take two 1.0 2.0 2.0alpha 1.0_branch accepted/2.0/20130305.190443 accepted/2.0alpha-wayland/20121108.021153 accepted/2.0alpha/20121108.025308 accepted/trunk/20121009.232513 accepted/trunk/20121012.014517 submit/2.0/20130305.193220 submit/2.0alpha-wayland/20121108.021211 submit/2.0alpha/20121108.021203 submit/trunk/20121009.234317 submit/trunk/20121012.005900
authorGraydon, Tracy <tracy.graydon@intel.com>
Tue, 9 Oct 2012 23:43:07 +0000 (16:43 -0700)
committerGraydon, Tracy <tracy.graydon@intel.com>
Tue, 9 Oct 2012 23:43:07 +0000 (16:43 -0700)
290 files changed:
ChangeLog
Makefile.am
Makefile.in
NEWS
aclocal.m4
build-aux/config.guess [deleted file]
build-aux/config.sub [deleted file]
build-aux/depcomp [deleted file]
build-aux/install-sh [deleted file]
build-aux/ltmain.sh [deleted file]
build-aux/missing [deleted file]
config.h.in
configure
configure.ac
ltmain.sh [changed mode: 0755->0644]
m4/libtool.m4 [deleted file]
m4/ltoptions.m4 [deleted file]
m4/ltsugar.m4 [deleted file]
m4/ltversion.m4 [deleted file]
m4/lt~obsolete.m4 [deleted file]
man/Makefile.in
man/intel.man
packaging/0001-Don-t-config-fail-if-no-dri1-support.patch [new file with mode: 0644]
packaging/xorg-x11-drv-intel.spec
src/Makefile.am
src/Makefile.in
src/brw_defines.h
src/brw_structs.h
src/common.h
src/compat-api.h [new file with mode: 0644]
src/i830_render.c
src/i915_render.c
src/i915_video.c
src/i965_3d.c [new file with mode: 0644]
src/i965_reg.h
src/i965_render.c
src/i965_video.c
src/intel.h
src/intel_batchbuffer.c
src/intel_batchbuffer.h
src/intel_display.c
src/intel_dri.c
src/intel_driver.c
src/intel_driver.h
src/intel_glamor.c [new file with mode: 0644]
src/intel_glamor.h [new file with mode: 0644]
src/intel_hwmc.c
src/intel_list.h [new file with mode: 0644]
src/intel_memory.c
src/intel_module.c
src/intel_options.c [new file with mode: 0644]
src/intel_options.h [new file with mode: 0644]
src/intel_shadow.c [deleted file]
src/intel_uxa.c
src/intel_video.c
src/legacy/Makefile.in
src/legacy/i810/Makefile.am
src/legacy/i810/Makefile.in
src/legacy/i810/i810.h
src/legacy/i810/i810_accel.c
src/legacy/i810/i810_common.h
src/legacy/i810/i810_cursor.c
src/legacy/i810/i810_dga.c
src/legacy/i810/i810_dri.c
src/legacy/i810/i810_driver.c
src/legacy/i810/i810_hwmc.c
src/legacy/i810/i810_io.c [deleted file]
src/legacy/i810/i810_video.c
src/legacy/i810/i810_xaa.c [new file with mode: 0644]
src/legacy/i810/xvmc/I810XvMC.c
src/legacy/i810/xvmc/Makefile.in
src/legacy/legacy.h
src/render_program/Makefile.am
src/render_program/Makefile.in
src/render_program/exa_sf.g5a [new file with mode: 0644]
src/render_program/exa_sf.g5b [new file with mode: 0644]
src/render_program/exa_sf_mask.g5a [new file with mode: 0644]
src/render_program/exa_sf_mask.g5b [new file with mode: 0644]
src/render_program/exa_wm_affine.g6i [new file with mode: 0644]
src/render_program/exa_wm_ca.g5a [new file with mode: 0644]
src/render_program/exa_wm_ca.g5b [new file with mode: 0644]
src/render_program/exa_wm_ca_srcalpha.g5a [new file with mode: 0644]
src/render_program/exa_wm_ca_srcalpha.g5b [new file with mode: 0644]
src/render_program/exa_wm_mask_affine.g5a [new file with mode: 0644]
src/render_program/exa_wm_mask_affine.g5b [new file with mode: 0644]
src/render_program/exa_wm_mask_affine.g6a
src/render_program/exa_wm_mask_affine.g7a [new file with mode: 0644]
src/render_program/exa_wm_mask_affine.g7b [new file with mode: 0644]
src/render_program/exa_wm_mask_projective.g5a [new file with mode: 0644]
src/render_program/exa_wm_mask_projective.g5b [new file with mode: 0644]
src/render_program/exa_wm_mask_projective.g7a [new file with mode: 0644]
src/render_program/exa_wm_mask_projective.g7b [new file with mode: 0644]
src/render_program/exa_wm_mask_sample_a.g5a [new file with mode: 0644]
src/render_program/exa_wm_mask_sample_a.g5b [new file with mode: 0644]
src/render_program/exa_wm_mask_sample_a.g7a [new file with mode: 0644]
src/render_program/exa_wm_mask_sample_a.g7b [new file with mode: 0644]
src/render_program/exa_wm_mask_sample_argb.g5a [new file with mode: 0644]
src/render_program/exa_wm_mask_sample_argb.g5b [new file with mode: 0644]
src/render_program/exa_wm_mask_sample_argb.g7a [new file with mode: 0644]
src/render_program/exa_wm_mask_sample_argb.g7b [new file with mode: 0644]
src/render_program/exa_wm_noca.g5a [new file with mode: 0644]
src/render_program/exa_wm_noca.g5b [new file with mode: 0644]
src/render_program/exa_wm_sample_planar.g4i [new file with mode: 0644]
src/render_program/exa_wm_src_affine.g5a [new file with mode: 0644]
src/render_program/exa_wm_src_affine.g5b [new file with mode: 0644]
src/render_program/exa_wm_src_affine.g6a
src/render_program/exa_wm_src_affine.g7a [new file with mode: 0644]
src/render_program/exa_wm_src_affine.g7b [new file with mode: 0644]
src/render_program/exa_wm_src_projective.g5a [new file with mode: 0644]
src/render_program/exa_wm_src_projective.g5b [new file with mode: 0644]
src/render_program/exa_wm_src_projective.g7a [new file with mode: 0644]
src/render_program/exa_wm_src_projective.g7b [new file with mode: 0644]
src/render_program/exa_wm_src_sample_a.g5a [new file with mode: 0644]
src/render_program/exa_wm_src_sample_a.g5b [new file with mode: 0644]
src/render_program/exa_wm_src_sample_a.g7a [new file with mode: 0644]
src/render_program/exa_wm_src_sample_a.g7b [new file with mode: 0644]
src/render_program/exa_wm_src_sample_argb.g4a
src/render_program/exa_wm_src_sample_argb.g4i [new file with mode: 0644]
src/render_program/exa_wm_src_sample_argb.g5a [new file with mode: 0644]
src/render_program/exa_wm_src_sample_argb.g5b [new file with mode: 0644]
src/render_program/exa_wm_src_sample_argb.g6a
src/render_program/exa_wm_src_sample_argb.g7a [new file with mode: 0644]
src/render_program/exa_wm_src_sample_argb.g7b [new file with mode: 0644]
src/render_program/exa_wm_src_sample_planar.g4a
src/render_program/exa_wm_src_sample_planar.g5a [new file with mode: 0644]
src/render_program/exa_wm_src_sample_planar.g5b [new file with mode: 0644]
src/render_program/exa_wm_src_sample_planar.g6a
src/render_program/exa_wm_src_sample_planar.g7a [new file with mode: 0644]
src/render_program/exa_wm_src_sample_planar.g7b [new file with mode: 0644]
src/render_program/exa_wm_write.g5a [new file with mode: 0644]
src/render_program/exa_wm_write.g5b [new file with mode: 0644]
src/render_program/exa_wm_write.g6a
src/render_program/exa_wm_write.g6i [new file with mode: 0644]
src/render_program/exa_wm_write.g7a [new file with mode: 0644]
src/render_program/exa_wm_write.g7b [new file with mode: 0644]
src/render_program/exa_wm_xy.g5a [new file with mode: 0644]
src/render_program/exa_wm_xy.g5b [new file with mode: 0644]
src/render_program/exa_wm_yuv_rgb.g5a [new file with mode: 0644]
src/render_program/exa_wm_yuv_rgb.g5b [new file with mode: 0644]
src/render_program/exa_wm_yuv_rgb.g7a [new file with mode: 0644]
src/render_program/exa_wm_yuv_rgb.g7b [new file with mode: 0644]
src/sna/Makefile.am [new file with mode: 0644]
src/sna/Makefile.in [new file with mode: 0644]
src/sna/README [new file with mode: 0644]
src/sna/blt.c [new file with mode: 0644]
src/sna/brw/Makefile.am [new file with mode: 0644]
src/sna/brw/Makefile.in [new file with mode: 0644]
src/sna/brw/brw.h [new file with mode: 0644]
src/sna/brw/brw_disasm.c [new file with mode: 0644]
src/sna/brw/brw_eu.c [new file with mode: 0644]
src/sna/brw/brw_eu.h [new file with mode: 0644]
src/sna/brw/brw_eu_emit.c [new file with mode: 0644]
src/sna/brw/brw_sf.c [new file with mode: 0644]
src/sna/brw/brw_test.c [new file with mode: 0644]
src/sna/brw/brw_test.h [new file with mode: 0644]
src/sna/brw/brw_test_gen4.c [new file with mode: 0644]
src/sna/brw/brw_test_gen5.c [new file with mode: 0644]
src/sna/brw/brw_test_gen6.c [new file with mode: 0644]
src/sna/brw/brw_test_gen7.c [new file with mode: 0644]
src/sna/brw/brw_wm.c [new file with mode: 0644]
src/sna/compiler.h [new file with mode: 0644]
src/sna/fb/Makefile.am [new file with mode: 0644]
src/sna/fb/Makefile.in [new file with mode: 0644]
src/sna/fb/README [new file with mode: 0644]
src/sna/fb/fb.h [new file with mode: 0644]
src/sna/fb/fbarc.c [new file with mode: 0644]
src/sna/fb/fbarcbits.h [new file with mode: 0644]
src/sna/fb/fbbitmap.c [new file with mode: 0644]
src/sna/fb/fbblt.c [new file with mode: 0644]
src/sna/fb/fbbltone.c [new file with mode: 0644]
src/sna/fb/fbclip.c [new file with mode: 0644]
src/sna/fb/fbclip.h [new file with mode: 0644]
src/sna/fb/fbcopy.c [new file with mode: 0644]
src/sna/fb/fbfill.c [new file with mode: 0644]
src/sna/fb/fbgc.c [new file with mode: 0644]
src/sna/fb/fbglyph.c [new file with mode: 0644]
src/sna/fb/fbglyphbits.h [new file with mode: 0644]
src/sna/fb/fbimage.c [new file with mode: 0644]
src/sna/fb/fbline.c [new file with mode: 0644]
src/sna/fb/fblinebits.h [new file with mode: 0644]
src/sna/fb/fbpict.c [new file with mode: 0644]
src/sna/fb/fbpict.h [new file with mode: 0644]
src/sna/fb/fbpoint.c [new file with mode: 0644]
src/sna/fb/fbpointbits.h [new file with mode: 0644]
src/sna/fb/fbpush.c [new file with mode: 0644]
src/sna/fb/fbrop.h [new file with mode: 0644]
src/sna/fb/fbseg.c [new file with mode: 0644]
src/sna/fb/fbsegbits.h [new file with mode: 0644]
src/sna/fb/fbspan.c [new file with mode: 0644]
src/sna/fb/fbstipple.c [new file with mode: 0644]
src/sna/fb/fbtile.c [new file with mode: 0644]
src/sna/fb/fbutil.c [new file with mode: 0644]
src/sna/fb/sfb.h [new file with mode: 0644]
src/sna/gen2_render.c [new file with mode: 0644]
src/sna/gen2_render.h [new file with mode: 0644]
src/sna/gen3_render.c [new file with mode: 0644]
src/sna/gen3_render.h [new file with mode: 0644]
src/sna/gen4_render.c [new file with mode: 0644]
src/sna/gen4_render.h [new file with mode: 0644]
src/sna/gen5_render.c [new file with mode: 0644]
src/sna/gen5_render.h [new file with mode: 0644]
src/sna/gen6_render.c [new file with mode: 0644]
src/sna/gen6_render.h [new file with mode: 0644]
src/sna/gen7_render.c [new file with mode: 0644]
src/sna/gen7_render.h [new file with mode: 0644]
src/sna/kgem.c [new file with mode: 0644]
src/sna/kgem.h [new file with mode: 0644]
src/sna/kgem_debug.c [new file with mode: 0644]
src/sna/kgem_debug.h [new file with mode: 0644]
src/sna/kgem_debug_gen2.c [new file with mode: 0644]
src/sna/kgem_debug_gen3.c [new file with mode: 0644]
src/sna/kgem_debug_gen4.c [new file with mode: 0644]
src/sna/kgem_debug_gen5.c [new file with mode: 0644]
src/sna/kgem_debug_gen6.c [new file with mode: 0644]
src/sna/kgem_debug_gen7.c [new file with mode: 0644]
src/sna/rop.h [new file with mode: 0644]
src/sna/sna.h [new file with mode: 0644]
src/sna/sna_accel.c [new file with mode: 0644]
src/sna/sna_blt.c [new file with mode: 0644]
src/sna/sna_composite.c [new file with mode: 0644]
src/sna/sna_damage.c [new file with mode: 0644]
src/sna/sna_damage.h [new file with mode: 0644]
src/sna/sna_display.c [new file with mode: 0644]
src/sna/sna_dri.c [new file with mode: 0644]
src/sna/sna_driver.c [new file with mode: 0644]
src/sna/sna_glyphs.c [new file with mode: 0644]
src/sna/sna_gradient.c [new file with mode: 0644]
src/sna/sna_io.c [new file with mode: 0644]
src/sna/sna_module.h [new file with mode: 0644]
src/sna/sna_reg.h [new file with mode: 0644]
src/sna/sna_render.c [new file with mode: 0644]
src/sna/sna_render.h [new file with mode: 0644]
src/sna/sna_render_inline.h [new file with mode: 0644]
src/sna/sna_stream.c [new file with mode: 0644]
src/sna/sna_tiling.c [new file with mode: 0644]
src/sna/sna_transform.c [new file with mode: 0644]
src/sna/sna_trapezoids.c [new file with mode: 0644]
src/sna/sna_video.c [new file with mode: 0644]
src/sna/sna_video.h [new file with mode: 0644]
src/sna/sna_video_hwmc.c [new file with mode: 0644]
src/sna/sna_video_hwmc.h [new file with mode: 0644]
src/sna/sna_video_overlay.c [new file with mode: 0644]
src/sna/sna_video_sprite.c [new file with mode: 0644]
src/sna/sna_video_textured.c [new file with mode: 0644]
src/xvmc/Makefile.in
src/xvmc/i965_xvmc.c
src/xvmc/intel_batchbuffer.h
src/xvmc/intel_xvmc.c
src/xvmc/shader/Makefile.in
src/xvmc/shader/mc/Makefile.in
src/xvmc/shader/vld/Makefile.in
src/xvmc/xvmc_vld.c
test/Makefile.am [new file with mode: 0644]
test/Makefile.in [new file with mode: 0644]
test/README [new file with mode: 0644]
test/basic-copyarea-size.c [new file with mode: 0644]
test/basic-copyarea.c [new file with mode: 0644]
test/basic-fillrect.c [new file with mode: 0644]
test/basic-lines.c [new file with mode: 0644]
test/basic-putimage.c [new file with mode: 0644]
test/basic-rectangle.c [new file with mode: 0644]
test/basic-stress.c [new file with mode: 0644]
test/basic-string.c [new file with mode: 0644]
test/dri2-swap.c [new file with mode: 0644]
test/dri2.c [new file with mode: 0644]
test/dri2.h [new file with mode: 0644]
test/mixed-stress.c [new file with mode: 0644]
test/render-composite-solid.c [new file with mode: 0644]
test/render-copy-alphaless.c [new file with mode: 0644]
test/render-copyarea-size.c [new file with mode: 0644]
test/render-copyarea.c [new file with mode: 0644]
test/render-fill-copy.c [new file with mode: 0644]
test/render-fill.c [new file with mode: 0644]
test/render-trapezoid-image.c [new file with mode: 0644]
test/render-trapezoid.c [new file with mode: 0644]
test/test.h [new file with mode: 0644]
test/test_display.c [new file with mode: 0644]
test/test_image.c [new file with mode: 0644]
test/test_log.c [new file with mode: 0644]
test/test_render.c [new file with mode: 0644]
uxa/Makefile.am
uxa/Makefile.in
uxa/uxa-accel.c
uxa/uxa-glamor.h [new file with mode: 0644]
uxa/uxa-glyphs.c
uxa/uxa-priv.h
uxa/uxa-render.c
uxa/uxa-unaccel.c
uxa/uxa.c
uxa/uxa.h

index ad435f1..9b1e41c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
+commit 16860d448f11ba405050bd1ff02dc63a4b26280c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Sep 29 10:40:51 2012 +0100
+
+    uxa: Only destroy the bufmgr if it exists
+    
+    Be wary in case the Screen is destroy before we initialise bufmgr.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 13f7a9e267fbefd3326569e89b840bef31d77996
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Sep 28 09:25:12 2012 +0100
+
+    sna: Restore LLC cache level after using a buffer for scanout (uncached)
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8bfd31e9bb13bcb7f12e4147bec0da87b8e87dde
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Sep 27 18:12:11 2012 +0100
+
+    sna/dri: Improve handling of flipping with no outputs
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit dddb6e4e63d5cc8b2a1f2ae3ff287922d30460b9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Sep 27 17:17:30 2012 +0100
+
+    sna: Attempt to restore the current mode if pipe is disabled on DPMS on
+    
+    If we attempt to power up the pipe through a DPMS request, but it was
+    previously disabled due to an error, first try re-enabling.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 88cfd23379950d1fe4e682519c48ef6e3091c2f3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Sep 27 16:16:39 2012 +0100
+
+    uxa: Update mode->fb_id after completing pageflips
+    
+    As intel_crtc_on() depends upon the current value for determining if the
+    pipe is active, we can only change the value afterwards.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 83990c649cbd3cb563d08f04e1c02232c44997aa
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Sep 27 14:58:26 2012 +0100
+
+    Remove the last couple of references to mibstore
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit cb0b72c4fbb7b1bc941522d8679fef856f2f8936
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Sep 27 14:53:46 2012 +0100
+
+    uxa: Fixup the last couple of commits after realising I didn't have uxa enabled
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit feef53005b57d6b4489a15f8d0db8245dcb0cfaa
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Sep 27 13:36:55 2012 +0100
+
+    uxa: Do not attempt to pageflip whilst not master
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5a45cbacb777e478d8fbda9223b0fb5c705d7249
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Sep 27 13:31:27 2012 +0100
+
+    uxa: Confirm the pipe is alive before flipping
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit edc5b7f741a4bb8e9a58b5eb2201fa9304f94ef7
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Sep 27 13:27:20 2012 +0100
+
+    uxa/dri: Confirm Drawable is still attached to an active pipe before flipping
+    
+    If we schedule a flip to happen on a far distant vblank, it is possible
+    for us to disable the pipes with a modeset, whilst maintaining the fb
+    size, or with a DPMS command. If the pipe is disabled and we still try
+    to flip, then we trigger an EINVAL error from the kernel.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit eb667378543f97d7c7e7767daddbd9b39e07c1f8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Sep 26 15:12:57 2012 +0100
+
+    sna: Typo in DBG
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 557ad78d02dfff3db9e7fc21f05230a8fe482f7c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Sep 26 15:02:17 2012 +0100
+
+    Kill mibstore pretend backwards compatibility
+    
+    Adam Jackson was kind enough to point out that mibstore had been a no-op
+    since xorg-1.4 and the earliest we claim to support is xorg-1.6.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 367f57faf2c422da026a25c099426dc750cf3759
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Sep 26 14:06:18 2012 +0100
+
+    sna/video: Force integer promotion to avoid u16 overflow for frame size
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 34772cb0e724a880a8c6db936c0bb5dd129398f2
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Sep 26 12:09:39 2012 +0100
+
+    sna/dri: Handle pending flips when drawable disappears.
+    
+    The async case needs special handling as the current front buffer may be
+    pending a flip onto the scanout which needs to be completed even if the
+    Drawable is destroyed.
+    
+    Fixes regression from commit ad877abdc70b842afd202b2f97892d97a0b8d151
+    Author: Chris Wilson <chris@chris-wilson.co.uk>
+    Date:   Sat Jul 7 17:48:52 2012 +0100
+    
+        sna/dri: Attach the chain of frame events to the Window, not pixmap
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit addfa653cf51fa45c7eae49be1fd722aaadf97d6
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Sep 26 08:59:18 2012 +0100
+
+    uxa: Prevent attempting to call intel_mode_fini() before PreInit runs
+    
+    In the Ubuntu xserver it is apparently possible for the Screen to be
+    deleted prior to being fully initialised. Make sure we don't crash in
+    that situation!
+    
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=55346
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b880d8e0a9a32acd50333f72d695268c4819c29e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Sep 25 16:59:20 2012 +0100
+
+    sna/gen5: Add WA reference
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 74f930fd80c3f97a1b6213e9e79e02f8f51c64b9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Sep 25 15:41:51 2012 +0100
+
+    sna: Make sure the batch is flushed before setting DPMS
+    
+    Just in case on the off-chance that the kernel modifies the pipe and we
+    had a pipe-dependent operation in the batch.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0a00c3765c3ba464bb4e9cde12e964c979421ed6
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Sep 25 13:50:33 2012 +0100
+
+    sna: Accommodate changes to the Damage extension not unwrapping the GC
+    
+    commit 4dc2a76740d921c824a4d8193f39dd373475f02a
+    Author: Adam Jackson <ajax@redhat.com>
+    Date:   Thu Sep 20 17:57:00 2012 -0400
+    
+        miext/damage: Only wrap into the GC ops chain if there's a listener (v3)
+    
+    leaves the GC->funcs still pointing to the damage layer as it calls into
+    the driver functions, so we need to be careful to restore the correct
+    function table after we manipulate the GC for fallbacks.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8f5a6d107bb30fa218ff3c1d07532ca834b82edc
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Sep 25 13:36:12 2012 +0100
+
+    Add miInitializeBackingStore() to compat-api.h
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit dee133a722fb137767a78b244a312620f52a51b1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Sep 25 13:22:40 2012 +0100
+
+    sna: Remove unused reference to mibstore.h, removed in future Xorg
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f0dbfc20aaa9b47329438ce42150770d4d7934c3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Sep 25 13:22:21 2012 +0100
+
+    sna/dri: Fixup a DBG statement not to print gibberish
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c6008068372709c73034163eddc902b47bf87d24
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Sep 23 21:42:31 2012 +0100
+
+    sna: Check against op->dst.bo rather than priv->cpu_bo for composite upload
+    
+    In this case, we may also be handling an unattached pixmap, so avoid the
+    deferences of the sna_pixmap unless we are sure it will exist.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5ed840881c26e90eb8e00521b6d77b0ea514de5e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Sep 23 20:29:21 2012 +0100
+
+    sna: Check that the CPU bo exists before declaring it is busy along upload
+    
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=55251
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a858afc66c1fa2eec65a7041e991f2266f82deca
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Sep 23 13:49:40 2012 +0100
+
+    Silence a couple of potential compiler warnings
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9326acc2917109f06dda809107c8fa5a2273c3d2
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Sep 23 13:40:04 2012 +0100
+
+    Allow compilation of a separate i810 driver
+    
+    Allow --enable-ums-only as a counter-option to --enable-kms-only in case
+    the distribution wishes to enable a non-root KMS driver but also offer
+    a separate UMS driver for i81x.
+    
+    On the second pass, use "--enable-ums-only --disable-uxa --disable-sna"
+    to get the trimmed down unaccelerated i810 support.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0afb7efe8c48b5fc839e2137e870bea0f5fb3c9c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Sep 23 09:41:59 2012 +0100
+
+    sna: Avoid overflows when translating the box16 extents during a copy
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0fc6e5820e4543d52bcf8d0285ca6f69b5213831
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Sep 23 09:32:49 2012 +0100
+
+    sna: Add missing protection against int16 overflow when copying
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c2ca1c5abca687adb08d6e137bc3b70bdecb083d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Sep 23 08:56:50 2012 +0100
+
+    Reorder INTEL_XVMC define so that we pick up Option "XvMC"
+    
+    Otherwise it will remain disabled.
+    
+    Reported-by: Giacomo Comes <comes@naic.edu>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 92dbedc6138b923aa473935013ecb0346280c4d3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Sep 22 08:56:49 2012 +0100
+
+    sna: Force the stall before trying to upload into a busy CPU bo
+    
+    Under the circumstances where we can not instead stream the write into
+    the GPU bo, we need to use the busy CPU bo.
+    
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=54978
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3e1be265cf950976b5929b14a9dad0664deaa2c1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Sep 21 17:37:58 2012 +0100
+
+    sna: Force an inplace upload if already wedged
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b8967aff382c1b6bef2335dea51c979a3f0800c7
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Sep 21 12:16:27 2012 +0100
+
+    sna: Do not query for the NULL edid property
+    
+    If the EDID blob id is set to 0, that means that it does not exist and
+    so we can safely skip it.
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=55193
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0be1d964713ca407f029278a8256d02d925dc9da
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Sep 11 21:48:24 2012 +0100
+
+    sna: Use inplace X tiling for LLC uploads
+    
+    Based on a suggestion by Chad Versace (taken from a patch for mesa).
+    
+    This allows for a faster upload of pixel data through a ShmImage, or for
+    complete replacement of a GPU bo.
+    
+    Using a modified version of x11perf to upload to a pixmap rather than
+    scanout on an IVB i7-3720qm:
+    
+    Before:
+    40000000 trep @   0.0007 msec (1410000.0/sec): ShmPutImage 10x10 square
+     4000000 trep @   0.0110 msec (  90700.0/sec): ShmPutImage 100x100 square
+      160000 trep @   0.1689 msec (   5920.0/sec): ShmPutImage 500x500 square
+    
+    After:
+    40000000 trep @   0.0007 msec (1450000.0/sec): ShmPutImage 10x10 square
+     6000000 trep @   0.0061 msec ( 164000.0/sec): ShmPutImage 100x100 square
+      400000 trep @   0.1126 msec (   8880.0/sec): ShmPutImage 500x500 square
+    
+    However, the real takeaway from this is that the overheads for
+    ShmPutImage are substantial, only hitting around 70% expected efficiency,
+    and overshadowed by PutImage, which for reference is
+    
+    60000000 trep @   0.0006 msec (1800000.0/sec): PutImage 10x10 square
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d853064e7eebc5719645c12605782f995131a6fe
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Sep 20 22:43:26 2012 +0100
+
+    sna/gen3+: Trim the target extents to the CompositeClip
+    
+    When computing the active region with of a composite operation with
+    unknown extents we try to simply use the whole Drawable. However, this
+    needs to be clipped otherwise it may trigger assertion failure with an
+    offscreen pixmap.
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=55164
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 853beff4306d5a168e310af82d0ddf9db319fdce
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Sep 19 08:30:59 2012 +0100
+
+    sna/dri:Add some DBG and assertions to validate names passed back to clients
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8c1e60a15431b193b57d94a27b8e8de7c5a7e683
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Sep 18 15:01:52 2012 +0100
+
+    sna: Add some asserts useful for tracking an xserver drawing bug
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit cd23ac69ffb670468b2993242ce0d596081bbca4
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Sep 18 13:39:33 2012 +0100
+
+    sna/gen7: Add some ring switching sanity checks
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 22c84d02ade83c39940d76fc616a9122e535606a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Sep 18 12:01:49 2012 +0100
+
+    sna: Remove special casing of drawing depth=1 glyphs
+    
+    It turns out that they were not so special after all, and the "fast
+    path" was missing the important handling such as validating the GC. As a
+    result we ended up trying to render the glyphs through a planemask of 0
+    and similar garbage resulting in corruption. An example given by Kaus
+    Dittrich was the use of rotated glyphs in gnuplot.
+    
+    Reported-by: Klaus Dittrich
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 71fa350325bb06a6141f89ef14431d96f0c4956a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Sep 17 13:40:24 2012 +0100
+
+    sna: Check that we do not keep a GPU bo around after flushing a ShmPixmap
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 88502b32d5d2b826fc08344392c98300341410e1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Sep 16 09:02:46 2012 +0100
+
+    2.20.8 release
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 395d738b5086f24659b56b4b3536bffaebad8a3e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Sep 15 21:18:35 2012 +0100
+
+    sna: Improve handling of probe failure during initialisation
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fe78904a45979d47bb092ce37d321854e2418344
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Sep 13 22:15:14 2012 +0100
+
+    Add basic support for ValleyView
+    
+    Bind to the ValleyView SDV for verifying the render routines.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3b9259f7cedc179617bc24b3912d2d8d75c5a824
+Author: Ian Stakenvicius <axs@gentoo.org>
+Date:   Fri Sep 14 21:04:42 2012 +0100
+
+    configure: Make udev dependency optional
+    
+    In order to support buildbots where the udev headers may exist on the
+    build system but not the target, we need explicit control over optional
+    dependencies.
+    
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=54942
+
+commit d995705fb01842652a79076cbecee4392f653bfe
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Sep 14 19:32:06 2012 +0100
+
+    sna: Only discard CPU damage if we completely overwrite its extents
+    
+    If we are performing a clipped copy, then we must be careful not to
+    completely discard the CPU damage as it may not be entirely replaced.
+    
+    Reported-by: Roman Jarosz <kedgedev@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=54937
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit deacab87e4ba7fe09f0f16568dc2848949f2707a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Sep 14 17:01:13 2012 +0100
+
+    sna/dri: flip->next_front.bo is owned by the DRI drawable not by the flip
+    
+    Be careful not to delete the reference we presume we hold as it is
+    borrowed from the DRI drawable.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5369408d596a0611d4f76333dac2e1c93e63e8b6
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Sep 14 16:12:00 2012 +0100
+
+    sna/dri: And the hunt for the use-after-free continues...
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8e9d64203428b344433ac8f86dc1f06d2c32529a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Sep 14 14:06:38 2012 +0100
+
+    sna: Fix typo for sna_render_picture_flatten()
+    
+    Pass it the correct value for the pixmap height, and not its 'y'
+    coordinate!
+    
+    Reported-by: Eugene Rosenzweig <ugn@outlook.com>
+    Bugzilla: https://bugs.gentoo.org/show_bug.cgi?id=434860
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6ee9969f0e99975a24e113af9591909d9023d8af
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Sep 14 13:04:50 2012 +0100
+
+    sna/dri: Update AsyncSwap for recent changes in tracking DRI drawables
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d2dbb991384f2b820a714eba262691ed97a6a22a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Sep 14 13:04:14 2012 +0100
+
+    sna/dri: Add a bunch of assertions for hunting a use-after-free
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d8756091474aeb44e5d8eed6b20b65c23b6574e7
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Sep 14 12:17:28 2012 +0100
+
+    sna/dri: Version bump for prototypical AsyncSwap
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0fc3d020f3086b5c6ecef1fed1aaedef7aa52b01
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Sep 14 09:49:00 2012 +0100
+
+    Skip adding unknown special modes
+    
+    In light of the discussion on how to add stereo modes it was revealed
+    that we would happily add modes with unknown and unhandled strange
+    flags. Adam Jackson mentioned that he has plans to fix that with some
+    upcoming work, but as a first step we can simply eradicate them whilst
+    pondering how to support the stereoscopic vision of the future.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 35d81d97b38d05f132a4823e57fff4012e966504
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Sep 13 22:32:47 2012 +0100
+
+    sna/gen7: Defensively program default GT values
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3fbdedbf9d509c5ca58ae0a01fe8e54dcc990cf8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Sep 13 22:10:08 2012 +0100
+
+    sna: Fix analysis of source extents for BLT composite
+    
+    After we have computed the source offset vector for the transformed
+    source bo, we need to use that with respect to the destination rectangle
+    to verify that the source sample is wholly within bounds.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6c7f998f7bda4f4f1286e079412d5d3a5b2eb073
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Sep 13 20:41:23 2012 +0100
+
+    sna: Fix BLT composite offset
+    
+    Reported-by: Jiri Slaby <jirislaby@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=54868
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2575cd0d236b4e1694e3185a487ebfd8bfe6499f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Sep 13 20:08:37 2012 +0100
+
+    sna: Avoid corrupting the CPU bo when compositing fallback data through BLT
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5781de2e5ab0d7e8e62965bda714789879555ed4
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Sep 13 19:53:29 2012 +0100
+
+    sna/gen3: Tidy NO_COMPOSITE debugging
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit dd1432b2c00c94ac75af4740b66b5cd1a573e261
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Sep 13 19:47:29 2012 +0100
+
+    sna: Do not attempt to change tiling if wedged
+    
+    The caller will just have to live with the current tiling, which should
+    be fine in most cases, in other cases the gpu is wedged...
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8c7dd2219fa777bf6354c4e0ef38a2f09fe09675
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Sep 13 17:14:23 2012 +0100
+
+    sna: Prefer to use indirect uploads for very small updates
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d87a56ed1789e0c5058b302bb930d7e952ff3e5e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Sep 13 09:57:30 2012 +0100
+
+    sna: Teach sna_replace__xor() how to tile large uploads
+    
+    This path is hit using eog+cairo-1.10 and a large image, e.g.
+    http://marsrovers.jpl.nasa.gov/gallery/press/opportunity/20120705a/PIA15689_Greeley_Pan_wDeck_L257F.jpg
+    
+    Reported-by: Michael Laß <bevan@bi-co.net>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=54808
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 58a96f0f684fe0d7d1a7890c630539ef8b065d1e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Sep 12 23:53:44 2012 +0100
+
+    sna: Also remove bogus assertion from sna_replace__xor()
+    
+    Like the assertion in sna_replace() this is now incorrect due to the
+    automatic flagging of large bo with flush.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6069e78238ca57e3433d528680fe04766a1e5307
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Sep 12 16:22:49 2012 +0100
+
+    sna: Keep a very small, short-lived cache of large buffers
+    
+    As we now regularly retire and so discard the temporary large buffers,
+    we find them in short supply and ourselves wasting lots of time creating
+    and destroying the transient buffers.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1e2a03ad19664e846ece4110e53d26babb5a2159
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Sep 12 16:15:22 2012 +0100
+
+    sna: Propagate busyness when creating the proxy
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e28f5a2537821dc170a7ef78bf33ecbd3c032da0
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Sep 12 15:21:27 2012 +0100
+
+    sna: Add some DBG as to why kgem_check_bo() flushes
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1af1dae1feefd6567017170bab241570fb528e5c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Sep 12 15:20:49 2012 +0100
+
+    sna: Ensure tiling upload buffers are trimmed to fit in the cache
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e5f137807c318588f546960668345eef34159e26
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Sep 12 14:11:43 2012 +0100
+
+    sna: Avoid fallbacks to shadow pixels if FORCE_GPU is in effect
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=54808
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0d17208a66a7e54d4106f8a4034d3a928e28bb62
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Sep 12 14:04:50 2012 +0100
+
+    sna: Avoid readback inplace if the target is unmappable
+    
+    We have to use the tiling indirect path, or else fail.
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=54808
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4b4abdaae94d164d5d0b2755907e76b9cbe0c988
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Sep 12 13:47:26 2012 +0100
+
+    sna: Flush after operating on large buffers
+    
+    As we know that such operations are likely to be slow and consume
+    precious GTT space, mark them as candidates for flushing.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 15911f533d6a7ef40e42ba5921fac7c62b290f8b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Sep 11 14:59:53 2012 +0100
+
+    prime: Reorder probe messages so that the driver prefix is correct
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit bc73acbd4da53bc50752c0413adcd0ce876e0a03
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Sep 10 18:55:04 2012 +0100
+
+    uxa: Error out after failing to become DRM master during PreInit
+    
+    As we set the card fd to -1 upon failure, the error here is
+    non-recoverable, so make sure it gets propagated and we abort loading
+    the intel ddx.
+    
+    Bugzilla: https://bugs.launchpad.net/ubuntu/+source/xserver-xorg-video-intel/+bug/962892
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b0d14071f7b60729c223af925935227393fbd3ee
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Sep 10 13:53:45 2012 +0100
+
+    sna: Workaround issue with global glyph privates and shared ZaphodHeads
+    
+    Under ZaphodHeads we end up with multple screens accessing the common
+    sna_glyph_key and so cause conflicting updates and erroneous references
+    into the screen-local texture atlases.
+    
+    Two approaches can be tried here. Transition to a screen-specific
+    private key introduced with xorg-1.13, or to move the glyph cache (and
+    the rest of the gpu state tracker) down into the device private rather
+    than screen private. This is neither of those, but a workaround to avoid
+    reusing the incorrect entries from shared screens.
+    
+    Reported-by: Stephen Liang <inteldriver@angrywalls.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=54707
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit cfa0c6162bbd2f6edab1301b6aed886af7e8ab38
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Sep 10 10:50:03 2012 +0100
+
+    sna: Fixup possible_crtcs for ZaphodHeads
+    
+    As the possible_crtcs is a bitmask of the available crtcs exposed to the
+    Xserver, we need to adjust it for the limited view given by Zaphod mode.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 95c71d1626dfbd97733e7e7e03fdde3af833446e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Sep 8 20:12:32 2012 +0100
+
+    NEWS: Fix version reference 'bugs since 2.20.6'!
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0659711dfa9c9fc52adeaba766049887d5b6f040
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Sep 8 20:01:32 2012 +0100
+
+    2.20.7 release
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2c8e48f8149499040342836491333402fd05b762
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Sep 7 23:00:47 2012 +0100
+
+    sna: Remember that LineDoubleDash involves updating the GC between segments
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ed7b8db24921dc0bb6ea59dacf35ea41a61d59bf
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Sep 7 22:12:17 2012 +0100
+
+    sna: Pass the hints down to the PolyPoint fallback
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6c9df48fa8f1ac93103ce771ae28f47faa321619
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Sep 7 22:05:19 2012 +0100
+
+    sna: Fix PolyPoint fallback through a complex clip
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7d76eb155ed78343abfa15b7c8af87fc3d4211e4
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Sep 7 18:06:25 2012 +0100
+
+    sna: First scan for a backlight associated with the device
+    
+    The goal is to find the right interface in a multi-GPU system.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2de7d2d8150d648815feb74a3ae2239b908b971e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Sep 7 16:56:33 2012 +0100
+
+    sna/prime: Fixup attaching the randr14 scanout pixmap
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 448808d8a4e78afa7fe90e318d6d7afdbff66190
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Sep 7 14:31:52 2012 +0100
+
+    prime: Allocate a GPU_SCREEN when not primary to fulfil the output sink role
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3dce661ef3df5558fe9c9d85324ab3395a37b7ea
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Sep 7 13:48:12 2012 +0100
+
+    sna: And remember to update the ScreenPixmap after resize
+    
+    Fixes the regression from the previous commit
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0c39c363d7235d03f27337c731c0ffe3369bf713
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Sep 7 13:07:52 2012 +0100
+
+    sna: Protect sna_crtc_resize() against early invocation with no RootWindow
+    
+    If the outputs are resized very early on, in CreateScreenResources, then
+    we will not yet have created a RootWindow and so trying to change its
+    pixmap is a futile effort.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d7879a5939cabcd8b804e19fc422d2022ab7e3a4
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Sep 7 12:18:08 2012 +0100
+
+    sna/dri: Fix the double-buffer pageflipping path
+    
+    Notably, we need to remember to exchange the front/back buffers after
+    flipping!
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2630c81937115602faa352fca369d89fbb926b33
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Sep 7 11:23:02 2012 +0100
+
+    sna/dri: Make sure we set the SCANOUT flag when creating bo for pageflips
+    
+    In case we should be creating an untiled framebuffer, we need to make
+    sure we honour the scanout alignment.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit aeef03520f1b2a4b8638ff1ed4fbf19c9b35e7c8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Sep 6 11:46:53 2012 +0100
+
+    sna/prime: Correct the pinning flag when importing the prime bo
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9bdf46d6c1a29b7b9e3d35e39a2e789334c0e1be
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Sep 6 11:38:08 2012 +0100
+
+    sna/prime: Distinguish forms of pinned pixmap
+    
+    So that we can allow prime to replace the backing bo of currently
+    exported pixmaps through DRI2.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 39c4be2b0be66ed83bf059d3007f4143325e340d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Sep 6 11:28:49 2012 +0100
+
+    uxa: Distinguish forms of pinning
+    
+    This allows us to replace the prime bo to meet sharing requirements, but
+    still maintain the integrity with other users.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 031fa1c1c1129e486a02ffb5b3b9071f03b60048
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Sep 6 11:08:23 2012 +0100
+
+    uxa/prime: Mark the pixmap as pinned once exported (similar to flink)
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e5d3f3818660cb875ce2ef4721c51bc95317b78d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Sep 6 10:54:57 2012 +0100
+
+    sna: Add is-pinned checks to changing the pitch on an existing bo
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f2affe403baea78b9c94e3d726d1b9d8a0004f35
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Sep 6 10:24:04 2012 +0100
+
+    sna: Apply the minimum 256 pitch to CREATE_USAGE_SHARED pixmaps as well
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fbe4080816191ee97347128444f56bcc34858481
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Sep 6 08:57:34 2012 +0100
+
+    prime: Align pitch of shared untiled buffers to 256 bytes
+    
+    In order for nvidia to handle the buffers we are currently generating,
+    they need to have a pitch alignment of 256 bytes. Make it so.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c5fb025267bf1019907dfcc60f0efef2691be436
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Sep 6 08:55:46 2012 +0100
+
+    sna: Correct assertions for adding damage that bypasses the region
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1f5d5a37e57e63fa6e5b336a4847ce4422b89044
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Sep 5 17:17:58 2012 +0100
+
+    Add PlatformProbe to handle sharing of device entities
+    
+    Reported-by: Nick Bowler <nbowler@draconx.ca>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=54561
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ddde40afc081f47a3b6b694aeb21682c240c9562
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Sep 5 16:48:01 2012 +0100
+
+    sna: Harden against initialisation failures
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=54561
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4627dc36fa56ab971cd90088bd29a597dd12dc02
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Sep 5 16:17:17 2012 +0100
+
+    Revert "sna: Flush the batch before a render operation if the GPU is idle"
+    
+    This reverts commit ad57ac07a273bf376b74884de47d8ee1e7129fb8.
+    
+    These checks end up being too frequent and not allowing us to batch
+    sufficient commands to offset the overhead of batch submission. Hmm.
+
+commit 886f3cef4101a674bb62656cf7f3046643cae4b1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Sep 5 15:27:21 2012 +0100
+
+    uxa: Fix cut'n'paste error in Option "Backlight"
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6211d0914e2ed1cdd4cc2e170ee16129fc9f0d73
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Sep 5 12:33:08 2012 +0100
+
+    uxa: Flush batch immediately after queuing a WAIT_FOR_EVENT
+    
+    We still encounter hangs with kernel-3.5 with the culprit being a wait
+    on a disabled pipe. As we thoroughly check before that the pipe is still
+    disabled and flush before a modeset, the only possibility that remains
+    is that DPMS is disabling the pipe before we submit. Close that race by
+    always submitting the batch immediately after a WAIT_FOR_EVENT.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6a1423547769c24d15f6475628981d14a76a4bb2
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Sep 5 12:15:52 2012 +0100
+
+    sna: Initialise the empty boxes field of the region before subtracting it
+    
+    Fixes regression from commit 38fb77af757318e5fb6f605b37306ce4585b11a5
+    Author: Chris Wilson <chris@chris-wilson.co.uk>
+    Date:   Wed Sep 5 08:23:34 2012 +0100
+    
+        sna: Don't upload ignored cpu damage
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit dff25e5ec4071a0404f82760e8deec3f99f4a0a9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Sep 5 11:05:28 2012 +0100
+
+    sna: Drop master after discarding framebuffers
+    
+    As Imre Deak pointed out in the previous patch, drmModeRmFB only works
+    when we hold the DRM master, therefore to prevent a leak of the
+    framebuffer across server reset we need to defer dropping master until
+    after we release our scanouts and modes.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 46981d01700c1159bfb6bc0aebc938ff1d447a0f
+Author: Imre Deak <imre.deak@intel.com>
+Date:   Fri Aug 31 14:31:51 2012 +0300
+
+    uxa: fix leakage of FB when closing the screen
+    
+    Calling drmModeRmFB is only allowed in DRM master mode. Since leaving
+    the VT also drops master mode we need to remove the FB before calling
+    I830LeaveVT.
+    
+    This is only a real leak in case of a server reset, otherwise the server
+    process will exit anyway and the kernel will clean up the FB.
+    
+    Signed-off-by: Imre Deak <imre.deak@intel.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 55cef974a5dad3fda1922648fa27bcf5bb32ea03
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Sep 5 09:38:47 2012 +0100
+
+    sna: Review validity of damage when discarding CPU bo
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 587499bbf55b7eb0e1848822a792d535a8a3db1b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Sep 5 10:56:18 2012 +0100
+
+    sna/video: Use the scanout flag and FB id for sprite framebuffers
+    
+    So that we can use the same teardown path as normal scanouts.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 913adacc5400f94bc754f22375447e6f90ccd510
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Sep 5 09:20:55 2012 +0100
+
+    sna/gen7: Always emit a stall when flushing the texture cache
+    
+    Reported-by: Reinhard Karcher <reinhard.karcher@gmx.net>
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=54488
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit bdfedb46bd5bb3b96543a3ff553abd8ed0774fad
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Sep 5 09:15:12 2012 +0100
+
+    sna: Use async upload only if the last render was not CPU
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 67b75ae6f66e2d8e97b0aaf70d66b6de30f9e67e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Sep 5 08:46:39 2012 +0100
+
+    sna: Tweak upload path to remove redundant code
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 38fb77af757318e5fb6f605b37306ce4585b11a5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Sep 5 08:23:34 2012 +0100
+
+    sna: Don't upload ignored cpu damage
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2eb32f711ddd65a55c3c21f813b41aca49635a22
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Sep 5 00:22:04 2012 +0100
+
+    sna: Add DBG control to disable CPU bo
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 19e170aa6fd3652cc2e983a291f82350dca27e52
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Sep 4 23:52:42 2012 +0100
+
+    sna: Fix comparison of memcpy overlap to include x-offsets
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7895416eabfc5bd361d0d0ff92c570e2f6af47e0
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Sep 4 20:30:53 2012 +0100
+
+    sna: Rearrange use_cpu() tests for composite ops to avoid syncing CPU bo
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ad57ac07a273bf376b74884de47d8ee1e7129fb8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Sep 4 20:06:49 2012 +0100
+
+    sna: Flush the batch before a render operation if the GPU is idle
+    
+    Experiment with pushing those first commands earlier.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6325d7e29a8bacede321362c20bf3acd33c48651
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Sep 4 14:51:54 2012 +0100
+
+    NEWS: fixup missing links to bugs referenced in 2.20.6 release notes
+    
+    Reported-by: Adam Jackson <ajax@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit bc309bad39035649ee377c1d5af9099491a8ea43
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Sep 4 14:22:15 2012 +0100
+
+    sna: And remember to flush the damage to the output slaves...
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 68d207588a177afa4e999260bfddb4d6dba1029b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Sep 4 13:20:21 2012 +0100
+
+    sna: Improve handling of output offloading
+    
+    In particular, don't forget to flush when we only have offload slaves
+    and no native pixmaps.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8cf7ac776b9b47dabd5ab141e5a5385c44d3f309
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Sep 4 13:55:34 2012 +0100
+
+    sna: Fix a typo in an error message
+    
+    s/achieve/retrieve/ otherwise it is nonsense.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit be83b98d299c74101357e7bf170b1451aec2e1f2
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Sep 4 11:23:58 2012 +0100
+
+    sna: Add some DBG to the prime paths
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d0684d55e3a62c231c92a68403cf100c9e18351b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Sep 4 11:05:43 2012 +0100
+
+    sna: Fixup CREATE_USAGE_SHARED
+    
+    The DRI2 code tries to create pixmaps with non-zero width/height,
+    whoops.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b6ced7a2267f9429ad38949dda39c843e2119e99
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Sep 4 10:05:46 2012 +0100
+
+    sna: Fix typo for detecting prime ioctls
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit df68723baae71498de95924c72d4f23fa7fc7fdf
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Sep 3 20:43:48 2012 +0100
+
+    sna: Port prime interfacing
+    
+    Preliminary prime support.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e3ad18036b4dca29744ecfa4694006f01dd3fd18
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Sep 3 20:53:30 2012 +0100
+
+    sna: Enable platform probing
+    
+    Completing commit 0768ac4d195214825137152893deb74a87fcd11e
+    Author: Dave Airlie <airlied@redhat.com>
+    Date:   Wed Jul 25 16:11:23 2012 +1000
+    
+        intel: add platform probing support.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3dc644b2a959fc559e1138b332ed42d7235de42f
+Author: Сковорода Никита Андреевич <chalkerx@gmail.com>
+Date:   Mon Sep 3 13:44:21 2012 +0400
+
+    uxa: Fix Backlight option support.
+    
+    Signed-off-by: Сковорода Никита Андреевич <chalkerx@gmail.com>
+
+commit a972affe0c78b23a119d5dd14bb4446c89122af1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Sep 2 17:43:33 2012 +0100
+
+    sna/gen6+: Redirect fills if the destination is too large for 3D
+    
+    Reported-by: Clemens Eisserer <linuxhippy@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=54134
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 18d26076c778c20eb589b638fc47fa847793f149
+Author: Dave Airlie <airlied@gmail.com>
+Date:   Tue Sep 4 07:19:12 2012 +1000
+
+    intel: fix return value for no pEnt
+    
+    Probably never gets hit but shuold return FALSE,
+    
+    pointed out on irc by Lekensteyn
+    
+    Signed-off-by: Dave Airlie <airlied@redhat.com>
+
+commit d14ff42f2a205542df2ef723c6151d18db2bea8b
+Author: Dave Airlie <airlied@redhat.com>
+Date:   Thu Jul 26 10:43:29 2012 +1000
+
+    intel: query kernel for caps to setup scrn capabilities.
+    
+    This queries the kernel for prime support before advertising
+    the capabilities.
+    
+    Signed-off-by: Dave Airlie <airlied@redhat.com>
+
+commit 6705d8237aca90964449e4dbee97b4f62b87c28b
+Author: Dave Airlie <airlied@redhat.com>
+Date:   Thu Jul 26 10:37:04 2012 +1000
+
+    intel: add pixmap tracking and scanout support. (v2)
+    
+    This adds support for pixmap tracking and scanout of
+    alternate pixmaps.
+    
+    v2: do dirty updates after uxa block handler, check if kernel
+    can flush vmap for us so we don't have to.
+    
+    Signed-off-by: Dave Airlie <airlied@redhat.com>
+
+commit 69827126abdfa289417b55fe7db8ae0535037185
+Author: Dave Airlie <airlied@redhat.com>
+Date:   Wed Jul 25 16:22:57 2012 +1000
+
+    intel/uxa: add pixmap sharing support.
+    
+    Signed-off-by: Dave Airlie <airlied@redhat.com>
+
+commit 0768ac4d195214825137152893deb74a87fcd11e
+Author: Dave Airlie <airlied@redhat.com>
+Date:   Wed Jul 25 16:11:23 2012 +1000
+
+    intel: add platform probing support.
+    
+    This allows the driver to be loaded by the platform loading code.
+    
+    Signed-off-by: Dave Airlie <airlied@redhat.com>
+
+commit 164ae7a4f9fd3e538f1b506031d297088fc0c659
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Sep 2 17:19:12 2012 +0100
+
+    man: Malformed "Backlight" section
+    
+    Reported-by: Matthew Monaco <dgbaley27@0x01b.net>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=54397
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 67b44104168650473a24e69056707e0b35f1713e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Sep 2 12:47:36 2012 +0100
+
+    sna: Cache the temporary upload buffer when copying boxes
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4b558281e04e4d4febfc361632a90f8a45080c49
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Sep 2 12:23:59 2012 +0100
+
+    sna: Don't retire when searching for a snoopable buffer without hw support
+    
+    If the hw/kernel doesn't support snoopable buffers, then it makes little
+    sense to search for one, and force a retire in the certainty of not
+    finding any.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d933f3a7965c9aa70f70477be3bfe94d5ded948b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Sep 2 10:29:49 2012 +0100
+
+    2.20.6 release
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 62e7e69d88f7e5c8b0f0931fe887ee0c3bddb43f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Sep 2 09:55:07 2012 +0100
+
+    sna: Tweak placement rules if we already have a CPU bo
+    
+    If we have a CPU bo, consider if it may be quicker to render to it then
+    create a GPU bo.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f837807cc257fbedd35fa6101dc0b4a57e5ad78d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Sep 1 10:36:09 2012 +0100
+
+    sna/dri: Remove busy-wait spin from vblank chaining of swapbuffers
+    
+    The issue being that, due to the delay, the chained swap would miss its
+    intended vblank and so cause an unwanted reduction in frame throughput
+    and increase output latency even further. Since both client and server
+    have other rate-limiting processes in place, we can forgo the stall here
+    and still keep the clients in check.
+    
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=54274
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b56e8c5105c858452ca4eabf15b298fc06dfd3c8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Sep 1 12:15:47 2012 +0100
+
+    sna: Nullify gpu_bo after free in case final release is deferred in destroy
+    
+    As we may defer the actual release of the pixmap until after completion
+    of the last shm operation, we need to make sure in that case we mark the
+    GPU bo as released to prevent a use-after-free.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c4d994014160d8c946af731196a908991c77d9f9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Sep 1 10:44:24 2012 +0100
+
+    sna/gen2+: Add the missing assertions in case the drawrect is invalid
+    
+    Only the later gen had these useful assertions, add them to the rest
+    just in case.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 25c1b478a957ceb0474e7121840b7eed1ba2e140
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Sep 1 09:49:34 2012 +0100
+
+    sna: Discard cached CPU upload early when clearing with a solid fill
+    
+    Otherwise we end up considering the GPU bo as a real target, causing
+    confusion and failed asserts.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 530b1d1516595cf14c5112d8833b870cd50eca46
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Aug 30 22:21:57 2012 +0100
+
+    sna/dri: Use common routine for testing busyness after flush
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 00d8c776b3607dbdab32c1126f91a7a38b8065f6
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Aug 30 21:47:17 2012 +0100
+
+    sna/dri: Hold a reference to the vsync blit
+    
+    Fixes regression from
+    
+    commit 96a921487ef00db03a12bec7b0821410d6b74c31
+    Author: Chris Wilson <chris@chris-wilson.co.uk>
+    Date:   Mon Aug 27 21:50:32 2012 +0100
+    
+        sna: Track outstanding requests per-ring
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b2a6c74c2159c9968c19400d61a11f4773724b4a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Aug 29 14:51:40 2012 +0100
+
+    sna: Remove inconsistent assertion
+    
+    As we now may not prefer to use the GPU even if all-damaged and clear,
+    asserting that if we choose to use the CPU if clear is now bogus.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit deaa1cac269be03f4ec44092f70349ff466d59de
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Aug 28 22:23:22 2012 +0100
+
+    sna: Align active upload buffers to the next page for reuse
+    
+    If we write to the same page as it already active on the GPU then
+    despite the invalidation performed at the beginning of each batch, we do
+    not seem to correctly sample the new data.
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=51422
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=52299
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9e0305a3928f253ded6c8e141a4dd42be3952eb9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Aug 28 20:49:20 2012 +0100
+
+    sna: Discard inplace flag if we create a CPU map for the upload buffer
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f3e122554e88da0351bfb9a7a722f0715553689b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Aug 28 21:27:04 2012 +0100
+
+    sna: Propagate the request to flush rather than directly submit the batch
+    
+    The subtly is that we need to reset the mode correctly after
+    submitting the batch which was not handled by kgem_flush(). If we fail
+    to set the appropriate mode then the next operation will be on a random
+    ring, which can prove fatal with SandyBridge+.
+    
+    Reported-by: Reinis Danne <reinis.danne@gmail.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b5c8efe4309248e62d94d80b37a70775284ae985
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Aug 28 08:33:00 2012 +0100
+
+    sna: Make sure we reset the domain tracking when exporting DRI bo
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 96a921487ef00db03a12bec7b0821410d6b74c31
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Aug 27 21:50:32 2012 +0100
+
+    sna: Track outstanding requests per-ring
+    
+    In order to properly track when the GPU is idle, we need to account for
+    the completion order that may differ on architectures like SandyBridge
+    with multiple mostly independent rings.
+    
+    Reported-by: Clemens Eisserer <linuxhippy@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=54127
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 26c731efc2048663b6a19a7ed7db0e94243ab30f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Aug 27 20:50:08 2012 +0100
+
+    sna: Ensure that we create a GTT mapping for the inplace upload buffer
+    
+    As the code will optimistically convert a request for a GTT mapping into
+    a CPU mapping if the object is still in the CPU domain, we need to
+    overrule that in this case where we explicitly want to write directly
+    into the GTT and furthermore keep the buffer around in an upload cache.
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=51422
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=52299
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2cbf88980ede50370b97f32e565dea33db16ac44
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Aug 27 20:07:17 2012 +0100
+
+    sna: Force the stall if using a busy ShmPixmap bo with PutImage
+    
+    As we will stall in the near future to serialise access with the
+    ShmPixmap, we may as well stall first and do a simple copy using the
+    CPU in this highly unlikely scenario.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 705103d77e6b80d796a4535cade96cb6e9ebece3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Aug 27 20:07:19 2012 +0100
+
+    sna: Add a modicum of DBG to kgem_is_idle()
+    
+    Print out the handle of the bo we just checked.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8218e5da2b177ca9cd0e2b1e7dbe114e5ef2ebf0
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Aug 27 19:36:03 2012 +0100
+
+    sna: Fix crash with broken DBG missing one of its arguments
+    
+    Reported-by: Clemens Eisserer <linuxhippy@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=54127
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 593f549b45fbb1528472feed51207d84901d142e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Aug 27 16:43:19 2012 +0100
+
+    sna: A little more DBG to try and identify ratelimiting ops
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 71ac12e9b6ed00c28993637aafd5186a2ba26256
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Aug 27 15:49:59 2012 +0100
+
+    sna: Assert that the bo is marked as 'flush' when exported to DRI clients
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit cf64c8ce758cfa5d3bcd1b7626ff94cce7a84636
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Aug 27 13:59:56 2012 +0100
+
+    sna: Upload PutImage inplace to a fresh GPU bo if the device doesn't snoop
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3c6758fc4a50ecfce9ed317fec669cc48addedcf
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Aug 27 11:58:05 2012 +0100
+
+    sna: Flush the batch if it references a ShmPixmap and the GPU is idle
+    
+    This helps minimise the stall when syncing with the GPU before sending
+    the next reply to the Client.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f21079bad6e8316baf5d0295d6e7a809041bce06
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Aug 27 11:25:28 2012 +0100
+
+    Revert "sna: Cleanup composite redirection after substituting the BLT"
+    
+    This reverts commit 5a5212117e7a73ce3fffb87c60a505a849e38c36.
+    
+    The clean up is in effect too early, as this is during preparation and
+    the actual work is already being correctly done at the end.
+
+commit 414e87255cdee6eb556703ddefd194af71b985ed
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Aug 26 19:47:31 2012 +0100
+
+    Add Option "Backlight" to override the probed backlight control interface
+    
+    The automatic selection may not correspond with the correct backlight
+    (such as in a multi-gpu, multi-panel device) or the user may simply
+    prefer another control interface. This allows them to override the
+    chosen interface using
+    
+      Option "Backlight" "my-backlight"
+    
+    to specify '/sys/class/backlight/my-backlight' as the interface to use
+    instead.
+    
+    Suggested-by: Alon Levy <alevy@redhat.com>
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=29273
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d4f7c58186849374cd929e20fa49ea2e93939a69
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Aug 26 17:01:55 2012 +0100
+
+    sna/gen5+: Use the common methods for choosing the render targets
+    
+    This should afford us much more flexibility in where we render.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3c88b5f693c29b990d69f96508b121ce97a7209e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Aug 25 11:49:30 2012 +0100
+
+    sna: Use a fast span emitter for mono trapezoids without damage or clipping
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8e10a5b348a37feadcf935ec7694e46cc0802bdf
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Aug 26 14:53:12 2012 +0100
+
+    sna/gen6+: Do not call sna_blt_composite() after prepping the composite op
+    
+    As sna_blt_composite() will overwrite parts of the composite op as it
+    checks whether or not it can execute that operation, it will lead to a
+    crash as the normal render path finds the op corrupt. (The BLT
+    conversion functions cater for the cases where we may wish to switch
+    pipelines after choosing src/dst bo.)
+    
+    Reported-by: rei4dan@gmail.com
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit cbbe7727e766a5ee8767673feb6c8cdec38a7051
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Aug 26 14:43:47 2012 +0100
+
+    sna/gen6+: Simplify prefer_blt_bo
+    
+    As we already check the tiling state, so all we need to then check is
+    that the pitch is within the BLT constraint.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0c15824a8143a288716d2eacf03252cc54eb9466
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Aug 26 14:29:41 2012 +0100
+
+    sna: Add some DBG to kgem_is_idle()
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d432983421286d343f7c487c12c7244b711f5a66
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Aug 26 13:43:35 2012 +0100
+
+    sna: Add some DBG to BLT composite substitute to show if redirection is used
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5a5212117e7a73ce3fffb87c60a505a849e38c36
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Aug 26 13:38:23 2012 +0100
+
+    sna: Cleanup composite redirection after substituting the BLT
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 335821d588460c253b2ba2c8616a7c46e5ad0150
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Aug 26 13:29:04 2012 +0100
+
+    sna/gen4+: Check for allocation failure for the clear solid bo
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b5c77a6aaf520e331e82409b2592911cb1bb3100
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Aug 26 12:48:18 2012 +0100
+
+    2.20.5 release
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 454cc8453af1852758c3396dbe303c13c5c1be27
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Aug 24 08:48:12 2012 +0100
+
+    sna: Submit the partial batch before throttling
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0e1e83ed4952f620e9422e58f955a5aea406e300
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Aug 24 00:59:31 2012 +0100
+
+    sna: Allow the batch to be flushed if the GPU is idle upon a context switch
+    
+    Submit early, submit often in order to keep the GPU busy. As always we
+    trade off CPU overhead versus concurrency.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5059db0697c5516f1538f7062937664baf7b1c2e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Aug 24 00:21:07 2012 +0100
+
+    sna: Correct a pair of DBG messages
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c5b46e411a2c738c5ae55bffb9b3d460249f5c24
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Aug 23 17:36:10 2012 +0100
+
+    sna: Tidy up users of __kgem_bo_is_busy()
+    
+    A lot of callsites had not been converted to the common function.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 82e91327d57e03d2117638165f298a50b946fcaa
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Aug 23 15:59:00 2012 +0100
+
+    sna: Use a temporary userptr mapping for a large upload into a busy target
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b286ffa6beccb8fe341c464a4fb9f2af98541263
+Author: Eric S. Raymond <esr@thyrsus.com>
+Date:   Thu Aug 23 12:42:18 2012 -0400
+
+    Fix seriously malformed list syntax on intel(4).
+    
+    Signed-off-by: Eric S. Raymond <esr@thyrsus.com>
+
+commit fc6b7f564df88ca773ae245b1b4e278b47dffd59
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Aug 23 15:13:14 2012 +0100
+
+    sna: Flush the batch if it contains any DRI pixmaps
+    
+    This fixes a regression from
+    
+    commit 02963f489b177d0085006753e91e240545933387
+    Author: Chris Wilson <chris@chris-wilson.co.uk>
+    Date:   Sun Aug 19 15:45:35 2012 +0100
+    
+        sna: Only submit the batch if flushing a DRI client bo
+    
+    which made the presumption that we called sna_add_flush_pixmap() for
+    every DRI pixmap that we used. However, that is only called for the
+    dirty pixmaps, any native exported pixmap only marks the batch as
+    requiring a flush. So in those cases we always need to submit the batch
+    if it contains an exported DRI pixmap.
+    
+    Reported-by: chr.ohm@gmx.net
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=53967
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fd38f45ec5421802b426867a050c978a2feec937
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Aug 23 12:11:48 2012 +0100
+
+    sna: Mark the CPU damage as needing flushing for DRI buffers
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ac6cb667546a82b865c959a1be32f52b2da7bf7d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Aug 22 12:00:49 2012 +0100
+
+    sna: Flush before adding any SHM pixmap into the batch
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 785c1046b94fd9ca6f22b2a6d73639408a411cea
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Aug 22 10:56:12 2012 +0100
+
+    sna: Only use the GPU for an active CPU bo unless forced
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8032f51859ce1928922edf6892f493a84d9c39f0
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Aug 22 10:40:53 2012 +0100
+
+    sna: If we cannot use the CPU bo along a render pathway, promote to GPU
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit cc967507bbf357e1d5ec3cd0f3c0c5ecfa8b867a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Aug 22 10:36:04 2012 +0100
+
+    sna: Convert to using IGNORE_CPU flag rather than complicating the CPU damage
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5aa59ce7c012eb309c4f5a362ccf531c065bd7ff
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Aug 22 10:10:33 2012 +0100
+
+    sna: Assert that the CPU bo is not used if the GPU is clear
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 273765033223024ff6a662195e0e4b96f8960463
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Aug 22 00:48:08 2012 +0100
+
+    sna: Make sure the opposite damage is destroyed after reducing to all
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 31e398c9dbd8539e6fd2cc7398e97ee1df2f7f23
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Aug 22 00:38:17 2012 +0100
+
+    sna: Discard a no-longer-used GPU bo after moving to the CPU domain
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8be15c37df9d9b34e0f21700673212bd19c772b2
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Aug 22 00:27:00 2012 +0100
+
+    sna: Balance CPU bo accounting for SHM pixmaps
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 262d57a5aaac46508d8e29860c7a567bcd5bc4d8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Aug 21 23:36:12 2012 +0100
+
+    sna: Display still resident memory in inactive/snoop caches under DEBUG_MEMORY
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 304581cc02adeb865a24edde934b5b9ceba68d96
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Aug 21 23:29:12 2012 +0100
+
+    sna: Add a DBG to log pixmap destruction
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 946d54238d90f5e31772f0df336ac9a5e7f2d62b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Aug 21 21:02:00 2012 +0100
+
+    sna: Fix the assertion for tracking proxies in the batch
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4ee2e227ddf61c87f08f55d4922d2562b563ca87
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Aug 21 00:28:40 2012 +0100
+
+    sna: Mark all levels of a proxy as dirty
+    
+    So that if we write to a surface through one view, we make sure that the
+    sample cache is invalidated for all future views.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit eee181e9d71273d94fe735805ed84e8f7b7b2180
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Aug 21 00:19:10 2012 +0100
+
+    sna/gen6+: Only mark the dst as dirty again if it already is in the batch
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c86df17c1455a53cb52f33a25c8c362e5331621e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Aug 20 22:54:06 2012 +0100
+
+    sna/gen3: Fix assertion to check the freshly allocated vertex bo
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6aabe90587f4916a01a1cd2bbc577a1e7fa20eca
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Aug 20 22:09:54 2012 +0100
+
+    sna: Allow target bo promotion to GPU even on old architectures
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1a4b6fea7b1516de35e6800efa5b85f8401a5b2a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Aug 20 22:08:23 2012 +0100
+
+    sna: Assign a unique id to snoopable CPU bo
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 892b1a1e431e8f27133825f8a27dde4955da0054
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Aug 20 22:07:05 2012 +0100
+
+    sna/gen3: Convert to sna_drawable_use_bo()
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3ca1bfb51ba522454433d58131e7dab7fcbe7e34
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Aug 20 21:28:47 2012 +0100
+
+    sna: Trim a parameter from kgem_bo_mark_dirty() and add some assertions
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 16f3d3a9ae145a3af51d2c0c42c6c585d676a863
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Aug 20 19:42:22 2012 +0100
+
+    sna: Keep a stash of the most recently allocated requests
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fb349ced91e15ecaa025321bd37d1fe3cfdd2f44
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Aug 20 17:35:44 2012 +0100
+
+    sna: A few more buffer cache management assertions
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ae6b3c7508d570af94f172d6a91d62d2987d654b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Aug 20 17:03:16 2012 +0100
+
+    Check that the module that indeed i915 before using custom ioctls
+    
+    Thanks to Adam Jackson for pointing me towards drmGetVersion() and
+    Julien Cristau for saying "Yuck!"
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3c611087e8ae09fc3fe4271f16d912ac8ae89f6b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Aug 20 16:09:25 2012 +0100
+
+    Only open the matching BusID and not the first named
+    
+    If you pass a name to drmOpen() it will attempt to open any device
+    corresponding to that name if it first fails to open the device
+    corresponding to the BusID. Obviously we want the failure from opening
+    the specified device in order to prevent wrongly opening the first found
+    device multiple times.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit dd6c67b32f726b6ad7f12f3b83f6d8c868ff4dc1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Aug 20 15:58:03 2012 +0100
+
+    sna: Add a couple of buffer cache management assertions
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 01ebdb4d7a8bb751167153554f9122d996e4ea91
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Aug 20 15:33:26 2012 +0100
+
+    sna: Remove confusing is_cpu()
+    
+    The only real user now has its own heuristics, so convert the remaining
+    users over to !is_gpu().
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 410316d20299b9ed3447d1d897f904af786ed097
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Aug 20 14:56:12 2012 +0100
+
+    sna: Refine decision making for maybe-inplace trapezoids
+    
+    In particular, we want to avoid preferentially taking the CPU paths
+    when it may force any migration (including clear).
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 91f1bf971f9cdc6498f513a5ddec1ad7a4e24b3d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Aug 20 15:27:27 2012 +0100
+
+    sna: Correct ordering of calls to memcpy for BLT cpu composite paths
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 027569bf83fc6d67dca7cfd65fdfa37ef6b47204
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Aug 20 12:55:20 2012 +0100
+
+    Missing includes for b5b76ad849b
+    
+    The warnings of implicit function declarations were lost amongst the
+    noise.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f1b259f627814c765ea93d8c839ee7533249974f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Aug 20 12:51:51 2012 +0100
+
+    sna: Add a modicum of DBG for PolyFillRect
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b5b76ad849bfda1e75192d1cb3c6c0fcc623bb91
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Aug 20 12:01:39 2012 +0100
+
+    Sanity check that the driver is an i915.ko GEM device before claiming it
+    
+    This fixes an issue with us claiming Poulsbo and friends even though we
+    do not speak their language.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 74f998136bac441d782faf779616af6f7bdcadad
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Aug 20 11:07:55 2012 +0100
+
+    sna: Avoid migrating the BLT composite src to the GPU if the dst is not
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a05643eb670e91ab102465df799301def88faaf9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Aug 20 10:46:14 2012 +0100
+
+    sna: Remove unneeded source bo unref after __sna_render_pixmap_bo()
+    
+    As __sna_render_pixmap_bo() deliberately does not reference its returned
+    bo, we need to avoid unreferencing it else we cause explosions later.
+    
+    Fixes regression from commit a13781d19defc97af6a279c11a85e33ef825020e
+    Author: Chris Wilson <chris@chris-wilson.co.uk>
+    Date:   Sun Aug 19 09:45:12 2012 +0100
+    
+        sna: Enable BLT composite functions to target CPU buffers
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c80db9bc2ef0a37a4abb78c9ef667c8b36ab6fba
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Aug 20 10:45:36 2012 +0100
+
+    sna: Flush the batch before preparing for a FlushCallback
+    
+    As we end up submitting and maybe synchronising upon a batch within
+    FlushCallback (or our client will) it is important that we start that
+    serialized batch as early as possible to minimise the impending stalls.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c39fe0253847f5a86e16b47ba420c8ba819c9110
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Aug 19 20:42:55 2012 +0100
+
+    sna: Do not use the GPU to migrate to the CPU whilst wedged!
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fe05268d70088c8cad5f4b5ef756e1ffe2069fca
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Aug 19 19:28:42 2012 +0100
+
+    sna: Experiment with flushing the batch prior to rendering to a ShmPixmap
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit bbd7a825810cc9772e6d613df449cb5ecb0be3f6
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Aug 19 19:28:20 2012 +0100
+
+    sna: Don't promote a ShmPixmap to GPU for a CopyArea
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7bf7a5ad1057f1aeb5b261da6dc501323c022287
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Aug 19 19:17:35 2012 +0100
+
+    sna/gen3: Tidy vbo discard
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d1b808fd72b477bde96f7c6737a993bd1a20baf2
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Aug 19 17:53:24 2012 +0100
+
+    sna: Tweak is_cpu/is_gpu heuristics
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c682c1a37692021cbd9bfc1e3f1ccf2b648c73f9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Aug 19 17:28:25 2012 +0100
+
+    sna: Discard GPU (and damage) after applying clear on migration to CPU
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit dc83ef49f9e8ff94ab77aa9d54fe29e32b9d7a3d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Aug 19 17:20:45 2012 +0100
+
+    sna/trapezoids: Accept more operators for maybe-inplace
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 47d948f5df0cd0e975cfe5183b6ce79cd3fd27ee
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Aug 19 17:09:21 2012 +0100
+
+    sna: Update maybe_inplace to recognise more types of handled pixel formats
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 02963f489b177d0085006753e91e240545933387
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Aug 19 15:45:35 2012 +0100
+
+    sna: Only submit the batch if flushing a DRI client bo
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 13d1a105159222518800d3c5ad5660725864ec6b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Aug 19 09:48:05 2012 +0100
+
+    sna: compare the correct trailing dword when skipping identical bitmap lines
+    
+    Fixes regression in 2.20.4 from
+    
+    commit 85192f00e345830541e3715e211b1f98154bbef4
+    Author: Chris Wilson <chris@chris-wilson.co.uk>
+    Date:   Wed Aug 8 12:11:50 2012 +0100
+    
+        sna: Ignore trailing bits when comparing lines inside the bitmap
+    
+    Reported-by: Edward Sheldrake <ejsheldrake@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=53699
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a13781d19defc97af6a279c11a85e33ef825020e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Aug 19 09:45:12 2012 +0100
+
+    sna: Enable BLT composite functions to target CPU buffers
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit be940856c74fbedd27997dd61e2a85959b321193
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Aug 18 21:23:03 2012 +0100
+
+    sna: Consider sample wraparound in each direction independently
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 110c7ef7f6c31929affa038918e6ce087bccddc6
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Aug 18 17:42:51 2012 +0100
+
+    sna/damage: Replace the damage with a larger box if subsumed
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 75a2fab766d8aed180ef795919e503db22c0e0fd
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Aug 18 17:28:08 2012 +0100
+
+    sna: Avoid forcing an upload for an unblittable bo unless on a fallback path
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 110d5519f3523b1e2c50db637cdc4c5bc44c960a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Aug 18 16:39:52 2012 +0100
+
+    sna: Reduce subtracted damage earlier
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8812e8b6e89e6432a6a768a0566ce4c153e9b256
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Aug 18 16:21:13 2012 +0100
+
+    sna: Reduce damage after a large composite operation
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e361627b90ea6bf2f9a8c46cf8debe562fdf4f09
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Aug 18 16:16:17 2012 +0100
+
+    sna/damage: Add some more sanity checks for creating empty regions
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 10f334872e9dd190e18c768219e60815acabe4d3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Aug 18 15:49:02 2012 +0100
+
+    sna: Add damage for the whole unaligned trapezoid not per component
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5ff6198c9346d84717bac28980329b048f4406e8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Aug 18 11:59:56 2012 +0100
+
+    2.20.4 release
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit bc77a466531fdbdd21e9354af567e5215a66edf9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Aug 18 11:09:23 2012 +0100
+
+    sna: Silence a couple of recent compiler warnings
+    
+    sna_accel.c: In function 'sna_poly_fill_rect_extents':
+    sna_accel.c:11438:11: warning: unused variable 'v' [-Wunused-variable]
+    
+    sna_blt.c: In function 'sna_blt_composite__convert':
+    sna_blt.c:1712:3: warning: format '%s' expects a matching 'char *' argument [-Wformat]
+    sna_blt.c:1738:3: warning: format '%x' expects argument of type 'unsigned int', but argument 4 has type 'CARD32' [-Wformat]
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d1da2c71461798bb027a260ff8480b71ebffde26
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Aug 16 21:15:54 2012 +0100
+
+    sna: Correct assertion for StoreColors
+    
+    Fixing the assertion reveals that it was bogus!
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 31ddaa0cfbde083aef42d9fdb5ed13bb4edc36c8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Aug 16 21:13:52 2012 +0100
+
+    sna: Fixup DBG after 7f5a9e3
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b8bc56c12c6fdc559354fbbf96b6e043a491aa8f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Aug 16 21:00:57 2012 +0100
+
+    uxa/gen3: Simply simple fill shader generation
+    
+    Suggested-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 182581edde356a21a0681de526f83884e1a0de5d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Aug 16 20:59:09 2012 +0100
+
+    uxa/glamor: Check for failed prepares
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c289b607d1526d8d3625fa84c093552a9f3ea168
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Aug 16 20:54:40 2012 +0100
+
+    uxa: Check for failed mmapping of the scanout
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 32ec8b979bc8cf7d8ce351ca752b806d42bc1c0f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Aug 16 20:53:08 2012 +0100
+
+    test/dri2: Discard error returns from _XReply
+    
+    This is only test code, so keep the static analyser quiet
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5675c36e0dca92b8d24235d82cd0e87f82fdc7b0
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Aug 16 20:44:32 2012 +0100
+
+    sna: Check for failure to pin the front buffer
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c9db2c74ab3b482489bec63b11df80bb35e21aca
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Aug 16 20:42:50 2012 +0100
+
+    sna/gen2: Add break rather than fallthrough
+    
+    The fall-through in this instance is irrelevant, and the static
+    analysers complain for not commenting on the fall-through. Silence the
+    analyser by removing the fall-through.
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e0abbc3ccafb51d6b2114e1c7d6dc2eda3a8c1f4
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Aug 16 20:40:17 2012 +0100
+
+    i810: Query PortPriv for the surface properties
+    
+    Avoid the NULL deferences.
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c09518f98d5c533860b084506d9ee2c819cca52f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Aug 16 20:32:53 2012 +0100
+
+    sna: Fix assignment inside assertion (should be an equality check)
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7d3e4328d4f4421178377933ca98fb80daa85c76
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Aug 16 20:32:11 2012 +0100
+
+    sna/glyphs: Fix potential leak of glyph extents (for many lists of many formats)
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9b00c82df78cb8820c0e32fbecc7c933eed81d52
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Aug 16 20:30:52 2012 +0100
+
+    sna: Remember alpha-fixup for BLT upload
+    
+    Still dubious whether this is truly beneficial...
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 94871944a0e1351273d6029df7bf0300f31a8571
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Aug 16 00:07:58 2012 +0100
+
+    sna: Avoid conflating tearfree and randr shadow modes
+    
+    For ordinary TearFree we do not want to adjust the crtc offsets.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1a389842347bab9d91240444e161589071eb9a47
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Aug 15 23:07:16 2012 +0100
+
+    sna: Avoid queuing a pageflip on a DPMS off pipe
+    
+    If the pipe is not running, attempting to queue a pageflip will result
+    in an error and us disabling the output in retaliation.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 615739556dd1cc4565eb1c47f93fe8abd697802f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Aug 15 20:10:52 2012 +0100
+
+    sna: Only continue to update the shadow buffer if the flips succeeded
+    
+    If the flip fail, we disable the crtc and may end up disabling the
+    output, removing the shadow (and old scanout bo) in the process.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2554d0d76e0fcae6e324938c28bb50deeb8814dc
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Aug 15 18:04:18 2012 +0100
+
+    sna: Submit the batch upon destroying a ShmPixmap
+    
+    The midlayer has already detached the pixmap from the segment (possibly
+    destroying that segment in the process, thanks midlayer!) so we need to
+    submit the batch asap before the segment disappears.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4e604d721be5a1c0f8eaf91e3a5cf8c01a609a69
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Aug 15 16:53:20 2012 +0100
+
+    sna: Flush shm pixmaps after upload
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7f5a9e30c953c174a4d6bc83e0b0a5e068cbda52
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Aug 15 09:34:24 2012 +0100
+
+    sna: Remove zero-size rectangles fro PolyFillRectangle
+    
+    Some applications like to waste precious bw by attempting to fill
+    zero-sized rectangles; remove them upfront rather than process them.
+    
+    Reported-by: Jiri Slaby <jirislaby@gmail.com>
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=47597
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0c882f4fa991ef379e416628eb41cd2178818ad1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Aug 14 16:02:38 2012 +0100
+
+    sna/gen2,3: Prevent dereferencing a NULL bo with solid render fills
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 48f436d3705059711097a222aac65f862b4a5cfd
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Aug 14 15:05:33 2012 +0100
+
+    sna: Defer the release of a busy SHM pixmap until the next flush callback
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9f07d1fc0181f22da36837337241f228626e0d88
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Aug 14 12:03:24 2012 +0100
+
+    sna: Enable use of shm pixmap for readback
+    
+    A little too overzealous in the degradation of writing to the CPU bo
+    if we need to read from a GPU bo.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9b016d2e466f342cc6649504fa48ab6a810c7e94
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Aug 12 21:36:30 2012 +0100
+
+    sna: do not bother attaching to a miniscule ShmPixmap
+    
+    If the pixmap is less than a page in size we are unlikely to recover the
+    cost of tracking it via the GPU.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2f4de90709264ad19a3e3f5f0f79f4bba78a760a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Aug 12 13:01:24 2012 +0100
+
+    uxa: Only emit a warning if we fail to tile the frontbuffer and the hw allows
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4d3cafc99ab49da6744046bc2004981144cb064d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Aug 12 13:02:43 2012 +0100
+
+    sna: Fix compilation without pixman glyphs
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit dc18eaa585c36c8e5f5b4ec405a976a835fd2ac3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Aug 12 10:34:10 2012 +0100
+
+    sna: Make the failure to create render caches non-fatal
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b580abdfa68108f3e63ee1f897b6ea83b9c47935
+Author: Dave Airlie <airlied@gmail.com>
+Date:   Sun Aug 12 20:52:12 2012 +1000
+
+    intel: fix video xvPipe range check
+    
+    Pointed out by Russell King on irc.
+    
+    Signed-off-by: Dave Airlie <airlied@redhat.com>
+
+commit 44f848f9b2f2a2dcd9087210ea46bc4fdb63c057
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Aug 11 19:44:15 2012 +0100
+
+    sna: Fix typo in computation of texel offsets for tiled 8x8 blts
+    
+    Reported-by: Clemens Eisserer <linuxhippy@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=53353
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b335d369bbcbfaef878795a5c8e72c2d40d3a536
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Aug 11 12:59:49 2012 +0100
+
+    sna: Discard the GPU bo after syncing to CPU bo for writing
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 029934662e0bad6cf47baf4d7202656dd3e0ba08
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Aug 11 10:47:44 2012 +0100
+
+    sna: Add a little DBG for promotion of CPU source bo
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f20f8556bfc8b4df6ba5050cca656a4ff0fdf18f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Aug 11 10:46:40 2012 +0100
+
+    sna: Treat ShmPixmap as ordinary
+    
+    In theory the code handles the automatic promotion and demotion of the
+    GPU buffers.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 16c751a06c503b85c5ab6588bae277af4348487d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Aug 11 10:44:08 2012 +0100
+
+    sna: Only mark userptr bo as snooped on non-LLC architectures
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 59359dba6496229eff7c60dd04536c5add69cec8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Aug 11 10:25:40 2012 +0100
+
+    sna: Mark SHM userptr bo as unreusable
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 64488010504a6e76008bb3b3c1e61caeb025913c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Aug 11 10:21:39 2012 +0100
+
+    sna/gen2-5: Substitute an equivalent BLT composite operation
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f464d508c870293699616626d64bd64f16051467
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Aug 11 10:10:32 2012 +0100
+
+    sna/gen6+: Try to use the BLT to avoid TLB misses
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e9c0e54e69a5ce93bb4e79d56da4a83fddf49c4e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Aug 11 08:58:14 2012 +0100
+
+    sna: Handle userptr failures more gracefully
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5d6d9231cd2003fda1c6f2dd3174014317a45704
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Aug 10 23:07:07 2012 +0100
+
+    sna: Reset BLT state after copy-boxes
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 50bfc172f1f89c023bb3a47418b845e31eba7126
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Aug 10 22:49:26 2012 +0100
+
+    sna: Improve a DBG statement
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b33f6754a99f6d11e423d6a03739fa2c04eeed88
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Aug 10 21:59:36 2012 +0100
+
+    sna: Add assertions to 8x8 tiled BLTs and reset BLT state afterwards
+    
+    Reported-by: Clemens Eisserer <linuxhippy@gmail.com>
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=53353
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ff54d4af39edcddd55f597c404ab6dd548a24aa9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Aug 10 21:41:38 2012 +0100
+
+    sna: Add a couple of debug options to control use of BLT patterns
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=53353
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 22306144030b5d37df6d46321555bced6e33c50c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Aug 8 19:45:09 2012 +0100
+
+    sna: Use the HAS_SEMAPHORES parameter when available
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 465ae1840a883c50d5a5aab7380b30527f00e17b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Aug 8 12:23:25 2012 +0100
+
+    sna: Use a compile time constant for determine the zeroth bit
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 85192f00e345830541e3715e211b1f98154bbef4
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Aug 8 12:11:50 2012 +0100
+
+    sna: Ignore trailing bits when comparing lines inside the bitmap
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=51422
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit edc1427f3dcddb73acdb5b5e03756ecb30cb3797
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Aug 8 10:53:40 2012 +0100
+
+    sna/gen5: Add DBG for context switching
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fec78ddc60b1f03097b334672546c2c7ef21ab4f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Aug 8 10:08:52 2012 +0100
+
+    sna: Add DBG option to disable discarding of glyph masks
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b0cd430082d219500729d20c4740440e58773892
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Aug 8 10:07:06 2012 +0100
+
+    sna/gen5: Fix use of uninitialised rgba value for DBG
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9ad923f95c59cdf42363f95c7dd52188c0987296
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Aug 8 09:59:50 2012 +0100
+
+    sna: Minor DBG for fallback glyphs and discarding the mask
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1a0590d133ea6991e0939d1f170f9c10df6856a0
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Aug 7 17:16:35 2012 +0100
+
+    sna: Check the composite extents against the clip
+    
+    When computing the composite extents (as opposed to the composite
+    region) also check if the resultant box overlaps the destination clip
+    region (we know it already fits into the extents). This helps in cases
+    with small roi against clipped drawables, such as drawing text onto
+    expose events.
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=51422
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5f5a10ef04a8c01b22da2284583851d84273dc2a
+Author: Paulo Zanoni <paulo.r.zanoni@intel.com>
+Date:   Mon Aug 6 18:48:09 2012 -0300
+
+    Add Haswell PCI IDs
+    
+    Signed-off-by: Paulo Zanoni <paulo.r.zanoni@intel.com>
+    Reviewed-by: Rodrigo Vivi <rodrigo.vivi@gmail.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d8f7f933bc2d30e529730521d5628c10df0361de
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Aug 5 17:18:54 2012 +0100
+
+    sna: Format markup to suppress compiler warning
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4d0a259988f67f5c569c5d8000c010a7b662efd3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Aug 4 15:54:19 2012 +0100
+
+    sna/gen6: Compile fix for DBG
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d917a276bff4e933590e78404526b929b6b3b497
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Aug 4 18:05:03 2012 +0100
+
+    sna/gen4: Restore the w/a flush for fill/copy as well
+    
+    So far, it looks like that the only one we can indeed drop is the
+    composite with mask.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d754bc3435889b5d19085588c9c888dc08f9522e
+Author: Cyril Brulebois <kibi@debian.org>
+Date:   Mon Nov 7 23:29:29 2011 +0100
+
+    Fix build failure when passing --with-builderstring.
+    
+    If --with-builderstring="foo" is passed to configure (and sna enabled):
+      CC     sna_driver.lo
+    src/sna/sna_driver.c: In function 'sna_init_scrn':
+    src/sna/sna_driver.c:1023:7: error: token ""foo"" is not valid in preprocessor expressions
+    
+    Fix the missing defined() around the BUILDER_DESCRIPTION variable.
+    
+    Signed-off-by: Cyril Brulebois <kibi@debian.org>
+
+commit 4bad76b4510d8cf4ccf3f64bcd13ebb80fae4d26
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Aug 4 14:28:41 2012 +0100
+
+    sna/dri: Don't force ring selection if we have semaphores
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fb7b584ec9d0ea96175ba3a621699378c6724940
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Aug 4 14:27:46 2012 +0100
+
+    sna/dri: Correct ring selection for a busy bo
+    
+    Confused the RENDER ring with the BLT, limiting swap performance.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 20e58077fe071fd03d44a97194aa163376dc46a4
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Aug 4 11:21:10 2012 +0100
+
+    sna/gen6: Reduce ring switching for overlapping copy boxes
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2345227663f443baa3c30bdf8b8c33827b7f4947
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Aug 4 11:12:12 2012 +0100
+
+    sna/gen7: Use a temporary to avoid switching rings for overlapping copies
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 61ec2999afd5dad22580e024421f13afe7c82f3a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Aug 4 10:33:05 2012 +0100
+
+    sna/gen4: Restore w/a flush for video
+    
+    One flush removal too many, keep those fingers crossed that the others
+    do not make an unwanted return.
+    
+    Reported-by: Roman Jarosz <kedgedev@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=53119
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5833ef173a01afb710acf10e806b83c5ca6efc09
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Aug 4 09:31:41 2012 +0100
+
+    2.20.3 release
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 036b90f099af21e60fb4c3684616daf1927f705e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Aug 3 21:41:59 2012 +0100
+
+    sna/gen7: Correct number of texture coordinates used for video
+    
+    Fixes regresion from
+    
+    commit 33c028f8be829caa4fdb9416ff177dc71f24b68e
+    Author: Chris Wilson <chris@chris-wilson.co.uk>
+    Date:   Wed Aug 1 01:17:50 2012 +0100
+    
+        sna/gen6+: Reduce floats-per-vertex for spans
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 05dcc5f1699ba90fc14c50882e8d4be89bc4a4f9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Aug 3 15:08:45 2012 +0100
+
+    Pass the chipset info through driverPrivate rather than a global pointer
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2b3f4ca33a00440a7005fef69099f8dbaddbbad1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Aug 3 14:27:51 2012 +0100
+
+    Unexport intel_chipsets
+    
+    Only used by the core module code, so make it static.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5ff749727d3590368806508ac0d0fa8efd1d1d51
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jul 25 22:21:29 2012 +0100
+
+    sna/gen7: Add constant variations and hookup a basic GT descriptor for Haswell
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit cd028cad3dc9b059a3d83b818d581f86e16ec317
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jul 26 13:17:11 2012 +0100
+
+    sna: Limit the batch size on all gen7 variants
+    
+    Seems the limit on the surface state size is common across the family
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4cd9ec9d404d934268952a1058afa07741b09efe
+Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
+Date:   Fri May 4 18:26:46 2012 +0200
+
+    uxa: fix 3DSTATE_PS to fill in number of samples for Haswell
+    
+    The sample mask value must match what is set for 3DSTATE_SAMPLE_MASK,
+    through gen6_upload_invariant_states().
+    
+    Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
+    Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
+
+commit 412668464cf9505629eac20001701af3402dc6e8
+Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
+Date:   Fri May 4 17:55:10 2012 +0200
+
+    uxa: set "Shader Channel Select" fields in surface state for Haswell
+    
+    For normal behaviour, each Shader Channel Select should be set to the
+    value indicating that same channel. i.e. Shader Channel Select Red is
+    set to SCS_RED, Shader Channel Select Green is set to SCS_GREEN, etc.
+    
+    Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
+    Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
+
+commit a47ba68996f117fabcb601d35bcc5f99cbcd6122
+Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
+Date:   Fri May 4 17:17:22 2012 +0200
+
+    uxa: fix max PS threads shift value for Haswell
+    
+    The maximum number of threads is now a 9-bit value. Thus, one more bit
+    towards LSB was re-used. i.e. bit position is now 23 instead of 24 on
+    Ivy Bridge.
+    
+    Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
+    Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
+
+commit ce4421e175ceb9259208c7c223af8d66282c3db3
+Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
+Date:   Fri May 4 17:09:19 2012 +0200
+
+    uxa: use at least 64 URB entries for Haswell
+    
+    Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
+    Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
+
+commit 8c880aa34c522b0d67cbb932771f00c947d00dec
+Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
+Date:   Fri May 4 17:43:19 2012 +0200
+
+    uxa: add IS_HSW() macro to distinguish Haswell from Ivybridge
+    
+    Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
+
+commit 0c0d1d956a8ba37d9e6f4a5e4f52018c8ce498e5
+Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
+Date:   Fri Aug 3 12:03:00 2012 +0100
+
+    Introduce a chipset identifier for Haswell (Ivybridge successor)
+    
+    Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
+
+commit 146959dd5ef28384a3db4fce4bf7840f2b3ec58c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Aug 1 23:43:15 2012 +0100
+
+    sna: Drop the clear flag as we discard the GPU damage
+    
+    Hopefully only to keep the sanity checks happy...
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7404e3085b2ee36fa24f77a02d156b4b1d2dff60
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Aug 1 23:37:35 2012 +0100
+
+    sna: Ensure we only mark a clear for a fill on the GPU bo
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ca46d1c7a18596ea9fe2b0577ccf1d110e3e42ac
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Aug 1 20:20:29 2012 +0100
+
+    sna/gen7: Prefer the BLT for self-copies
+    
+    Looking at the test results for a third time, gives the edge to the BLT
+    again.
+
+commit e4a3cd3d16447b5d83d1c8c63c342f1240935267
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Aug 1 17:37:33 2012 +0100
+
+    sna: Add validation of the clear flag to pixmap debugging
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit eaeda34bef711cc566f51dee092a19a3c4ac1a16
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Aug 1 16:23:05 2012 +0100
+
+    sna: Fix computation of st values for SIMD8 dispatch
+    
+    Fixes regression with enabling 8-pixels.
+    
+    Reported-by: Mehran Kholdi <semekh.dev@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=53044
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 55231eca818c82620c0146384b19b5d5659f6cd6
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Aug 1 16:22:23 2012 +0100
+
+    sna/gen6: Install a fallback 16-pixel shader
+    
+    In case the DBG options leave no shader compiled, make sure we always
+    supply one.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4e79c1fef064ce68914eb644edd7f588be3d7300
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Aug 1 15:58:43 2012 +0100
+
+    Revert "sna/gen7: Prefer the BLT for self-copies"
+    
+    This reverts commit 89e75dbcb6749bde7587ecc08abed276c255e7f9.
+    
+    Having removed the forced stall for a RENDER self-copy there is no
+    longer a need to encourage ring switching.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 85cef78a40c6a7a0254f8fba685f224eac6038e1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Aug 1 13:39:36 2012 +0100
+
+    sna/gen7: Simplify the force-stall detection
+    
+    After reducing the number of conditions where we think we need to force
+    the stall on the results, we can then simplify the code to detect
+    that remaining case.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9391a2c71f020541a2a62ae68eadd486216a38df
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Aug 1 12:50:32 2012 +0100
+
+    sna/gen7: Only force a stall for a dirty target if also used as a blend source
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0a4bb8663b9fa9b39d13bfb49aea30f2aaecce78
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Aug 1 11:19:27 2012 +0100
+
+    sna/gen4: Flush not required between fill vertices, only nomaskcomposite
+    
+    A small breakthrough... Still need to flush the primitive between state
+    changes though.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 33c028f8be829caa4fdb9416ff177dc71f24b68e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Aug 1 01:17:50 2012 +0100
+
+    sna/gen6+: Reduce floats-per-vertex for spans
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9b2873d3d97b6780d878bd9b821fba0302470f9f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Aug 1 00:01:15 2012 +0100
+
+    sna/gen4+: Implement an opacity shader
+    
+    Avoid the cumbersome lookup through the alpha gradient texture and
+    simply multiply the incoming opacity value. The next step will be to
+    reduce the number of floats required per vertex.
+    
+    Now that we have removed the primary user of the alpha solid cache, it
+    may be time to retire that as well.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fd3a1236051265fab700aad689a171de47d7338f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jul 31 10:20:51 2012 +0100
+
+    sna/gen6: Enable 8 pixel dispatch
+    
+    This gives a small performance increase when operating with rectangles,
+    which is reasonably frequent.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8922b804bc9ed27957c81f7cda4812ab4ecbd4de
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jul 31 10:20:51 2012 +0100
+
+    sna/gen7: Enable 8 pixel dispatch
+    
+    This gives a small performance increase when operating with rectangles,
+    which is reasonably frequent.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 492093d04b1486dd34aafe2f109a77ddeb836f18
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jul 31 18:39:17 2012 +0100
+
+    sna: Generate shaders for SNB+ 8-pixel dispatch
+    
+    Not ideal yet, sampling an alpha-only surface using SIMD8 only seems to
+    ever return 0...
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6a5ed88f9fab654c9c11c566b841d42150d26c5d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jul 30 17:08:20 2012 +0100
+
+    sna/gen4: Tidy debugging code
+    
+    Cluster the ifdefs together in the initialisation code.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 46ec9b0ed55d0fcade40f92206e59c02e402d870
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jul 31 17:41:34 2012 +0100
+
+    sna: Update DPMS mode on CRTC after forcing the outputs on
+    
+    If we forcibly update the outputs to be on, then the core will not issue
+    its on DPMS event and we miss out on updating the CRTC bookkeeping in
+    sna_crtc_dpms(). So we need to update the flag on the CRTC as we
+    manipulate the outputs during modesetting.
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=52142
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8f166d26b8a93592939068c5a8d160981c724cfd
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jul 31 11:58:24 2012 +0100
+
+    sna: Be more careful with damage reduction during CompositeRectangles
+    
+    We actually need to force DAMAGE_ALL in case we are promoting the GPU
+    pixmap.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e6cb5d93eaa01e7f4763f797bba341f3cc481d98
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jul 30 11:14:58 2012 +0100
+
+    sna: Avoid overlapping gpu/cpu damage with IGNORE_CPU
+    
+    We cannot simply ignore the presence of CPU damage with IGNORE_CPU but
+    must remember to discard it.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c9805ba98775bb1e969ff59c7044fe1a49673ca8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jul 29 18:19:37 2012 +0100
+
+    sna: Export sna_drawable_use_bo() to select target for FillRectangles
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 89e75dbcb6749bde7587ecc08abed276c255e7f9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jul 29 15:36:44 2012 +0100
+
+    sna/gen7: Prefer the BLT for self-copies
+    
+    If we are copying to ourselves, we have to regularly flush the render
+    cache at which point the RENDER pipeline is slower than the BLT
+    pipeline.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 33d6afda6cec124494f49b74152768da8a3fbdb5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jul 29 09:51:16 2012 +0100
+
+    sna/gen7: Compile basic kernels at runtime
+
+commit eba8d3b3e14a5a16cea6cb8a89f12d3feb8f3d99
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jul 29 09:51:16 2012 +0100
+
+    sna/gen6: Compile basic kernels at runtime
+
+commit 8515ec90405912b3d776defcd6e81b1b5f699f1e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jul 29 09:51:16 2012 +0100
+
+    sna/gen5: Compile basic kernels at runtime
+
+commit 00c08b1842c9493ca918a868202946b2e7150de0
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jul 29 09:51:16 2012 +0100
+
+    sna/gen4: Compile basic kernels at runtime
+
+commit 7c9dbc980b760e0053d83ca2d7cb147613285680
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jul 29 09:50:39 2012 +0100
+
+    sna: Assemble SF and WM kernels using brw
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8ebafa0493c0fa08ab9d80eeb1191b7560dc0863
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Sep 21 19:06:07 2011 +0100
+
+    sna: Add the brw assembler
+    
+    In order to construct programs on the fly to cater for the combinatorial
+    number of possible shaders, we need an assembler, whilst also taking the
+    opportunity to remove some of the inefficiencies and mistakes from the
+    current shaders.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ca9d9c02a260bf7930e04bf64e93cc051893c04e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 28 23:08:07 2012 +0100
+
+    sna: Prefer not to create a GPU bo without RENDER acceleration
+    
+    Unless that bo happens to be used on a render chain to the scanout.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit eefbe5b6038424566faf7333bb09764b050dd6b4
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jul 30 10:56:29 2012 +0100
+
+    sna: Debug option to test migration of inactive pixmaps
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d3499cacb59f19b5a3439a630ffbc3e105a27b75
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jul 29 23:00:15 2012 +0100
+
+    sna: Assert that we never attempt to submit a batch whilst wedged
+    
+    We should be asserting at the point that we insert the invalid operation
+    into the batch, but asserting upon submitting the batch is a useful
+    failsafe.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit cb4d789f98e6e05ec29e5242887018c7450ddf10
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jul 29 22:55:44 2012 +0100
+
+    sna: Disable the warning for a hung GPU is we manually set wedged
+    
+    Only warn about a hung GPU if we encounter an EIO during operation, but
+    don't warn if we set wedged during initialisation based on unsupported
+    hw or user request.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0fd680ff52f7ce0a101c617dfb8997c4e228e3ad
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jul 29 22:51:26 2012 +0100
+
+    Don't disable acceleration on 830/845g by default
+    
+    Run the risk of a GPU hang (it shouldn't endanger the entire machine
+    normally) and let the user elect to disable it through
+    
+      Option "NoAccel" "true"
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3d45f0affe263985f440e144203ed7cbb3803696
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 28 18:21:08 2012 +0100
+
+    sna: Honour the Option "DRI"
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=52624
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fb385745a2347f8966765567e78229d67ddc8d60
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jul 27 13:24:04 2012 +0100
+
+    sna/gen4: Move the common vertex_offset==0 check into the flush()
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 73ddd8b0decee444a57f10a11f05deebba686649
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jul 27 12:43:00 2012 +0100
+
+    sna/gen4: Further refinement to the GT allocation
+    
+    Still hunting for why gen4 fails utterly.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 717823a9f77cfedc50e03c5c31c1da44a396b561
+Author: Zhigang Gong <zhigang.gong@linux.intel.com>
+Date:   Fri Jul 27 18:12:26 2012 +0800
+
+    uxa/dri (glamor): Use exchange buffer in glamor fixup.
+    
+    The previous implementation is to create a new textured
+    pixmap based on the newly created pixmap's buffer object.
+    
+    This is not efficient, as we already created it when we
+    call CreatePixmap. We can just exchange the underlying
+    texture/image buffers by calling intel_glamor_exchange_buffers().
+    
+    And this commit seems also fix a weird rendering problem
+    when working with compiz/mutter.
+    
+    Signed-off-by: Zhigang Gong <zhigang.gong@linux.intel.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a8ee1406244d8b8399bf933d6b61bfd14374b5f9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jul 27 09:07:16 2012 +0100
+
+    2.20.2 release
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit bef73cd9279be3438e467981db39c67bc13104f5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jul 26 21:54:33 2012 +0100
+
+    sna/dri: Select the engine before emitting the wait
+    
+    So that if we have a flexible WAIT_FOR_EVENT that can go on either
+    pipeline, we can choose our preferred pipeline for DRI.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1ced4f1ddcf30b518e1760c7aa4a5ed4f934b9f5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jul 26 10:50:31 2012 +0100
+
+    Reduce maximum thread count for IVB GT1 to avoid spontaneous combustion
+    
+    Somewhere along the way it seems that IVB GT1 was reduced to only allow
+    a maximum of 48 threads, as revealed in the lastest bspecs.
+    
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=52473
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8f8f8759111f791ee99adfd87296443fb0e6acad
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jul 26 17:39:34 2012 +0100
+
+    sna/gen4: Tweak heuristics for render/blt usage
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c9dd1401615f0ed9492a0c0f547fb37150e013d1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jul 26 16:31:16 2012 +0100
+
+    sna/gen4: Bump thread counts
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7f3fdef98c1ab2fa27439c3be9810b7a934017ce
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jul 26 15:39:05 2012 +0100
+
+    sna/gen7: IVB requires a complete pipeline stall when changing blend modes
+    
+    Similar to how SandyBridge behaves, I had hoped that with IvyBridge they
+    would have made the pipelined operation actually pipelined, but alas.
+    
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=52473
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0938b3df8c25178c8ea0012e1ead1061d03a4e7c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jul 26 15:21:59 2012 +0100
+
+    sna/dri: Add an explanatory assertion
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c621183466aa55a5938027b702069e792df2272d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jul 26 15:18:56 2012 +0100
+
+    sna/dri: Tidy fallback/normal CopyRegion
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 52d2491a1bafb979d79bb970027c55788f199acb
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jul 26 15:19:14 2012 +0100
+
+    sna/video: Protect against attempting to use TexturedVideo whilst wedged
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8c0e3bbb0c301d0fa4652aa38edd84a9fd6b555e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jul 26 14:58:04 2012 +0100
+
+    sna: Force the damage on the DRI pixmap to be flushed to the GPU
+    
+    Otherwise nothing will happen if we consider ourselves wedged.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f50d7b03b5d0b81b24f0acb4ae555545bbdaa179
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jul 26 14:47:44 2012 +0100
+
+    sna: Only recommend not to create bo for a pixmap whilst wedged
+    
+    This allows us to continue to map a GPU bo and operate inplace if we are
+    force to create a GPU bo for a compositor.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 49403ddd1bd9a23e1b32a10e7d0757ae2897a579
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jul 26 14:44:14 2012 +0100
+
+    sna/dri: Mark a flush required for any new DRI already on exec/dirty lists
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit efe3c8ff48738f2a274e1d4514d32499fc4aadbc
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jul 26 14:43:33 2012 +0100
+
+    sna: Allow DRI to force allocation of a GPU bo and backing pixmap
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2069384f9f06d3ef9dbb0c3f2c64cac4b24e10fc
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jul 26 14:15:45 2012 +0100
+
+    sna/dri: Implement fallback handling for CopyRegion whilst wedged
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b18143de47e060b67a46d9c68590a2d35df9fca6
+Author: Paul Menzel <paulepanter@users.sourceforge.net>
+Date:   Thu Jul 26 12:51:57 2012 +0200
+
+    NEWS: Correct release version: s/2.12.0/2.20.0/
+    
+    Signed-off-by: Paul Menzel <paulepanter@users.sourceforge.net>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c262d02fb5defe9100df54cf83cc00e11e335745
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jul 26 01:12:11 2012 +0100
+
+    Limit PCI matching to VGA devices
+    
+    Fixes X -configure
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ad6355311b8b80777bc0fec95f6bf6cd1b4969d9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jul 26 01:02:53 2012 +0100
+
+    sna: Compile against xorg-1.10
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b6c7c490d76c683b7b5c89d20f902603b85bd3bc
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jul 26 00:48:59 2012 +0100
+
+    sna: Check for a NULL scanout after DPMS off with shadow enabled
+    
+    We may mark the scanout as detached when all outputs are turned off (for
+    example during rotation) and so in the subsequent block handler we need
+    to be careful in case we are handling a detached shadow.
+    
+    Reported-by: chr.ohm@gmx.net
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=52514
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f4acc01bb09f68edbad4c6cc7e04c271c92661c1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jul 25 22:43:32 2012 +0100
+
+    sna: Restore inplace upload for DRI compositors
+    
+    With a DRI compositor we have to flush the output after every request,
+    which leads to major inefficiencies. This can be mitigated slightly if
+    we know we will have to upload shortly, which we track using the pixmap
+    flush flag.
+    
+    In particular PutImage is meant to upload inplace to an active DRI
+    buffer, however this was accidentally dropped in
+    
+    commit a253c95ec63b2b075e66ae7380fed6a73469eba5
+    Author: Chris Wilson <chris@chris-wilson.co.uk>
+    Date:   Sun Jul 15 13:32:35 2012 +0100
+    
+        sna: Prefer uploads to be staged in snoopable bo
+    
+    Performace of putimage500 on ivb i7-3720qm:
+      bare:        4610
+      gnome-shell: 3000
+      patched:     3390
+    
+    Reported-by: Michael Larabel <Michael@phoronix.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5c969a05ef815b261e157fe8d1172aebfd7f5841
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jul 25 20:28:41 2012 +0100
+
+    sna/gen7: Move the PS thread count definition into the constant struct
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 901bb618215d65747eb0a8d481c77c1201f69362
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jul 25 20:13:15 2012 +0100
+
+    sna/gen7: Remove duplicated constants
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8c5077e4ed055a97bf9deda59c0e9a45e42317ca
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jul 25 16:59:11 2012 +0100
+
+    Assume all unknown chipsets are future gen
+    
+    I think the likelihood of a new product being launched based on a 8xx
+    design is remote enough not to worry about.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 954d9c6aca792098cb16a46b4ec8d5fc104b15a9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jul 25 15:41:29 2012 +0100
+
+    sna: Initialise single-shot tile offsets before use
+    
+    As noted by the compiler amidst all the noise.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 484b072072c8297a87940c9e32097923f0a77c8f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jul 25 12:22:47 2012 +0100
+
+    sna: Add 'gmux_backlight' to list of known devices for backwards compatability
+    
+    Reported-by: Austin Lund <austin.lund@gmail.com>
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=52423
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0ab6d7a50d37cf4454577cb8c333d4b8683aa054
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jul 25 12:20:36 2012 +0100
+
+    sna: Prefer platform backlight devices over firmware
+    
+    This is in contrast to libbacklight but closer to our original code as
+    we prefer a known custom backlight controller over the ACPI interfaces.
+    As only the ACPI interfaces are marked as firmware, and the custom
+    backlight controllers as platform, we therefore need to prefer platform
+    backlight devices.
+    
+    Reported-by: Austin Lund <austin.lund@gmail.com>
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=52423
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b6d82ab07661aba98963f239f9501b50c3910962
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jul 25 10:40:07 2012 +0100
+
+    sna: Reduce ping-pong for Composite with render disabled
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit de707b7dc853a3b315ead9789d5ca541412c99bc
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jul 25 09:05:46 2012 +0100
+
+    uxa: Add Apple's gmux to the list of known preferred backlights
+    
+    Reported-by: Austin Lund <austin.lund@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=52423
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3d254e4010d0753f433cfe62c6a7546b02482847
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jul 23 23:45:33 2012 +0100
+
+    sna: Use SETUP_BLT to reduce overheads for tiled BLT
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2ed44149eaa27b9632ec83a776f3ee67b0eec7b0
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jul 23 23:45:33 2012 +0100
+
+    sna: Use SETUP_BLT to reduce overheads for stippled BLT
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c1785aaca2c9347114d28f114ee59ef8206d829b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jul 23 23:00:25 2012 +0100
+
+    sna: Remove a surplus function
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 554fce8a65b2518cae032f1eadf58830559299c8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jul 23 22:59:16 2012 +0100
+
+    uxa: Pass the correct parameters to intel_detect_chipset()
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 40d90dfd8674c255a45b46bbdc09d497af5b3f50
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jul 23 21:55:46 2012 +0100
+
+    intel: Refactor the common chipset detection/override
+    
+    Reduce the duplicate messages for which type of chip we by
+    amalgamating the common code.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e3f6c48d18c316899c71b6fc34971039c6f9e5f8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jul 23 14:43:23 2012 +0100
+
+    sna: Refactor PutImage to avoid calling drawable_gc_flags() too early
+    
+    drawable_gc_flags() asserts that the gc has been moved to the CPU prior
+    to its calls so that it can read the reduced raster operation.
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1af26ea4228a9d7768b475b4f9164d2c7620d4fd
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jul 23 14:39:44 2012 +0100
+
+    sna: Flesh out tiled operations using the BLT
+    
+    Before enabling the RENDER pipeline for this operation, let's just see
+    what is required to fully use the BLT pipeline as well.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ac182a006732525a921a9c539e5ebfb537ad3b52
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jul 23 11:05:05 2012 +0100
+
+    sna: Hold a reference to the full stipple pattern for repeated tiles
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 83f683b47063eab8cfb5037d02133dd977c3fc25
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jul 22 23:20:23 2012 +0100
+
+    2.20.1 release
+    
+    A good brown paper bag bug release for SNA.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9402bdcc13f7e96dfe527ff4a3da8d13a7870a02
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jul 22 22:14:52 2012 +0100
+
+    sna/glyphs: Also discard the glyph mask for bitmaps with an opaque source
+    
+    Though I expect all such glyphs to be caught by the non-overlapping
+    checks...
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b315e0ebb75d8391ebef7ebe53741a5e33c968bb
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jul 22 20:07:38 2012 +0100
+
+    sna: Tweak the fallback hints for XYPixmap PutImage
+    
+    As the fallback uses a multiple-pass algorithm updating one plane at a
+    time, we wish to prepare the fallback surface for reads.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8acaf2693e176a92993a498683f121cfe0343fd4
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jul 22 12:28:34 2012 +0100
+
+    sna: Promote tiled operations to the GPU if the tile is already on the GPU
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7d4a3e371beea65bf66e54ae13789d6d5ca91f8b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jul 22 11:19:13 2012 +0100
+
+    sna: Use an upload buffer for large stipples
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 40e0cf32a25e43e16184b2af87a1e1abeb8e4052
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 21 19:43:23 2012 +0100
+
+    sna/dri: We fail at predicting the flip frame
+    
+    Simply report the values from the kernel, and transfer the blame...
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c6e316eeba3008b351f2cd63829154f4672c5417
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 21 18:18:32 2012 +0100
+
+    sna: Adjust hints to prefer rendering convex polygon with the GPU
+    
+    Keep the general polygons as only using the GPU if necessary, until the
+    cost of the routines is analysed.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f1e7248cb353d634f27d297059911168ce1a0762
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 21 16:08:31 2012 +0100
+
+    sna: Expand the heuristic for predicting when to use CPU bo for readback
+    
+    For tiny transfers, the cost of setting up the GPU operation outweighs
+    the actual savings through increased throughput. So we try to guess when
+    it will be preferrable to simply read from the GPU bo directly.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 06db69c2c7023f702f9773be90144fdf7a1159e4
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 21 15:28:10 2012 +0100
+
+    sna: Update assertion for cached io buffers
+    
+    As kgem_buffers may be reused and repurposed through the snoop cache it
+    is no longer true that only proxies will have the io flag set.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d715e1e01437049e167462281d51b5e214594361
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 21 15:04:31 2012 +0100
+
+    sna: Also discard the last-was-cpu flag when overwriting cpu damage
+    
+    We interpret a FillRect that erradicates the existing damage as a
+    clear-event and an opportunity to see if it is worth migrating the
+    render commands to the GPU. This is undermined if we leave the
+    'prefer-cpu' flag intact.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e95825d17ce65ad8173a5e6518a98969e236a4f8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 21 14:38:17 2012 +0100
+
+    sna: Enable snooping on the reused linear buffer
+    
+    This explains why suddenly I was seeing clflush again on a couple of
+    machines...
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c5e6b5874f334b9124a17f017c6eb175cf88f115
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 21 14:26:52 2012 +0100
+
+    sna: Fix the reversed not SHM assertion
+    
+    Should be double checking that we are not about to free a CPU bo pinned
+    to a SHM pixmap.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f36b656ab2bc16ec8849cadb0afb574bb742c3a3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 21 13:18:40 2012 +0100
+
+    sna: Avoid marking io/snoop buffers as unreusable unnecessarily
+    
+    As they are kept in special caches, we can reserve the unreusable flags
+    for exceptional buffers.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 37dfdb0e9e86effc3ca8b590c98aa2382e8f0cea
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 21 13:01:09 2012 +0100
+
+    sna: Correct assertion for __kgem_bo_size()
+    
+    Only proxies are measured in bytes not pages.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 83ad661bc73e9d0094b669c5203e25afc3937bb7
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 21 12:51:41 2012 +0100
+
+    sna: Change the vmap interface name to userptr
+    
+    This is in common with the other drivers and avoids the conflict with
+    'vmalloc/vmap' used by the kernel for allocation of contiguous virtual
+    mappings.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8dcccd308222bcf1b96f2ee15842b4558ea5f29e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 21 12:47:21 2012 +0100
+
+    sna: s/vmap/snoop/ since we use the flag more generically
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6acc9e6a6e1de2a11597c810e02f793774cef2dd
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 21 12:07:46 2012 +0100
+
+    sna: Fix role reversal of __kgem_bo_size() and kgem_bo_size()!
+    
+    Reported-by: Jiri Slaby <jirislaby@gmail.com>
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=47597
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 286b0e1a48cab85191dfbb112c8dd14aeaa70956
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jul 20 16:04:37 2012 +0100
+
+    sna: Refresh experimental userptr vmap support
+    
+    Bring the code uptodate with both kernel interface changes and internal
+    adjustments following the creation of CPU buffers with set-cacheing.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 93c794eb3f80bef64f1619986a7c950229dc7a47
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jul 20 20:34:53 2012 +0100
+
+    sna: Micro-optimise copying boxes with the blitter
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a0d95a9c2d3a27eafbe459e2aefe772c006e596f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jul 20 20:34:23 2012 +0100
+
+    sna: Only update a buffer when it becomes dirty
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c52d265b83b033fb2a275fcc9a8a8d146e3afdf6
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jul 20 19:38:38 2012 +0100
+
+    sna: Tweak CPU bo promotion rules for CopyArea
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f92a64dd9162731210b14368b6ee408356d7fefc
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jul 20 15:54:35 2012 +0100
+
+    sna: Only set the vmap flag after we make the bo snoopable
+    
+    Otherwise if we fail then we incorrectly add the handle to the vmap
+    cache.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8b4cf24f1403bf3d929cc0725de66b3d0e08ebaf
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jul 20 14:46:32 2012 +0100
+
+    sna: Also check whether the first upload box can use the BLT
+    
+    No point checking boxes 1..n if box 0 is the troublemaker!
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit df14b285be44f0c40a718bb8ae09a9558b1eb2c7
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jul 20 14:35:28 2012 +0100
+
+    sna/gen6: Prefer the more flexible render ring for large surfaces
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 578ff11c3753ede2c81afc47302991e3d3b316f2
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jul 20 14:24:06 2012 +0100
+
+    sna: Just use composite.box() when we only have one box
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fb7987fc0b51cf3b83dcf78bcefe65ec3af32ccf
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jul 20 13:12:27 2012 +0100
+
+    sna/dri: Cleanup ring selection for SNB+ CopyRegion
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3b56588fbaa2c4ccdfb2f2a8f5656d2cda9dacd7
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jul 20 10:19:25 2012 +0100
+
+    sna: Update WIP userptr example usage
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 473a1dfb683ed576d86b37aba36aaa0e379f4606
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jul 20 09:56:13 2012 +0100
+
+    sna: Rename kgem_partial_bo to kgem_buffer
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8e6e8a2fa8adda9ae9be8a88fbb14851e9d2df2e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jul 20 09:51:46 2012 +0100
+
+    sna: Allow the snoopable upload buffer to take pages from the CPU vma cache
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 979035bb9ce04db5fe30efa4f6daab0a40f6af57
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jul 19 20:06:28 2012 +0100
+
+    sna: Remove topmost unused 'flush' attribute
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b83011909aaf185f05fc2df743882c2410eff46d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jul 19 19:51:46 2012 +0100
+
+    sna: Replace 'sync' flag with equivalent 'flush'
+    
+    The only difference is in semantics. Currently 'sync' was only used on
+    CPU buffers for shared memory segments with 2D clients, and 'flush' on GPU
+    buffers shared with DRI clients.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 88bee3caeaacbbb1b4d789ea3db9a3802a62b59d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jul 19 19:40:34 2012 +0100
+
+    sna: Remove unused scanout-is-dirty? flag
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6f60f89588caa70e7d8ed53ba453bbe8c2094a95
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jul 19 16:58:34 2012 +0100
+
+    sna/gen6: Bump the WM thread count to 80
+    
+    Note that we should only do this when "WiZ Hashing" is disabled. So we
+    should be checking the GT_MODE register (bring on i915_read!) to be sure
+    that is safe to do so. However, it gives a big boost to performance of
+    render copies...  It also causes perf benchmarks to hit thermal limits
+    much quicker.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fc39d4b5cb105d269c5349e479daf112f5d93580
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jul 19 16:25:54 2012 +0100
+
+    sna/gen6: Add a simple DBG option to limit usage of either BLT/RENDER
+    
+    We can force the code to either select only BLT or RENDER operations -
+    for those that we have a choice for at least!
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 15d3eea7004822e5cbd48d676692e1b6a2b26d3e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jul 19 16:22:20 2012 +0100
+
+    sna: Handle mixed bo/buffers in assertions
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e4fce3b7801038e4f64d848a0995f4b441b4d2aa
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jul 19 10:50:09 2012 +0100
+
+    sna/gen4: Hookup composite spans
+    
+    Due to the unresolved flushing bug it is no faster (so only enable when
+    we definitely can't do the operation inplace), however it does eliminate
+    a chunk of CPU overhead.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5f138176bf15682324d2e8cfa9fac3e49604bf8f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jul 19 10:32:33 2012 +0100
+
+    sna: Tweak order of screen re-initialisation
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9bd0f8f3e7783d7a6bab707fc08ec96830cd5809
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jul 19 09:40:07 2012 +0100
+
+    i810: Correct the double negative and enable XAA when available
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d145d0e1459f578eea621e6944814642e5dd431f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jul 19 09:23:10 2012 +0100
+
+    i810: Handle initialisation without the XAA module present at runtime
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7a3b98e05b706548527e73b2008600391c601a62
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jul 19 08:42:05 2012 +0100
+
+    sna: Re-register the SHM funcs every server generation
+    
+    As the SHM layer hooks into the CloseScreen chain to free its privates,
+    we then need to call the registration function again on the next
+    generation to ensure that the private is reallocated before use.
+    
+    Reported-by: Pawel Sikora <pluto@agmk.net>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=52255
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4bcab83bbddf8a698aa83f5038f9ab019a404bd5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jul 18 22:19:45 2012 +0100
+
+    i810: DRI is not dependent upon XAA
+    
+    The blit routines is uses are independent of the XAA driver interface
+    and can be used separately.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 558c8251299b786cab1ac83dbd35f077224b5950
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jul 18 22:00:30 2012 +0100
+
+    sna/gen4+: Drop unsupported source formats
+    
+    Once again I've confused existence of the enum with the ability of the
+    sampler to read that format.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9f3b3098c9f870d303a9de2b9c0db119eff5a865
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jul 18 21:39:47 2012 +0100
+
+    sna/dri: Allow DRI2 to be loaded even if we are wedged
+    
+    Just because the GPU is spitting EIO at us does not necessarily imply
+    that a DRI client will also suffer. Spit out a warning for later bug
+    reporting and let them find out for themselves!
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 15b7191fd363e9e6083844a218e25419695d55f1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jul 18 12:59:41 2012 +0100
+
+    sna/gen6: Micro-optimise render copy emission
+    
+    Backport of the changes made for IVB.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4eea9ac0035dd72f3c637adc39eeaeda46472e9e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jul 18 12:59:41 2012 +0100
+
+    sna/gen7: Micro-optimise render copy emission
+    
+    The goal is bring the overhead down to that of using the blitter. Tricky
+    given the number of steps to using the 3D pipeline compared to the
+    BLT...
+    
+    A stretch goal would be to make IVB GPU bound for -copywinpix10!
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 267429bbb146449ee4d3b88fa8e23c5b1d53470a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jul 18 19:24:44 2012 +0100
+
+    sna: Enable runtime detection of set-cacheing ioctl
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c0b3674d042ff55d64ad1fd0d64926e1967be323
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jul 18 20:48:27 2012 +0100
+
+    sna/trapezoids: Only reduce bounded operators to a single pass
+    
+    Only for a few operators can we replace the opacity mask by
+    premultiplying into the source.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit bb0303677c38076db14dfbceec3636197a971e8c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jul 18 10:40:50 2012 +0100
+
+    sna/trapezoids: Use pixman from within the spans to reduce two-pass operations
+    
+    Reduce the two pass CompositeTrapezoids if we can perform the operation
+    inplace by calling pixman_image_composite from the span. This step
+    enables this for xrgb32.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit bee1a14618797b3d3a1c1a20eb72644fa907c048
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jul 18 09:38:32 2012 +0100
+
+    sna: Fix processing of the last fallback box
+    
+    The evil typo caused us to misalign the clip boxes and run over a
+    garbage array on 64-bit builds.
+    
+    Reported-by: Edward Sheldrake <ejsheldrake@gmail.com>
+    Reported-by: Clemens Eisserer <linuxhippy@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=52163
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 88cb1968b6dbf3edfa885da9503e91124af46007
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jul 18 09:38:03 2012 +0100
+
+    sna: Add more DBG for fallback processing
+    
+    Hunting the lost box...
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 36f2e46619598e9bca4fe1207aa2f157bfa1ecf4
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jul 18 00:45:54 2012 +0100
+
+    sna: Reuse the snoopable cache more frequently for upload buffers
+    
+    Now that we are keeping a small cache of snoopable buffers, experiment
+    with using them for uploads more frequently.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 73f07abbd2d78418e5a66262f293b5ed80b7ccb4
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jul 18 00:19:49 2012 +0100
+
+    sna: Maintain a short-lived cache of snoopable CPU bo for older gen
+    
+    Once again, we find that frequent buffer creation and manipulation of the
+    GTT is a painful experience leading to noticeable and frequent application
+    stalls. So mitigate the need for fresh pages by keeping a small stash of
+    recently freed and inactive bo.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 77520641a332a622c0b5378bd254ed5cb46a5f0a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jul 17 22:09:33 2012 +0100
+
+    i810: Replace XAAGet.*ROP() with local tables
+    
+    The XAAGetPatternROP() and XAAGetCopyROP() functions were removed along
+    with the rest of XAA so we need to implement those tables locally.
+    
+    Reported-by: Knut Petersen <Knut_Petersen@t-online.de>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit caef63e0268e59e439b030a9a338e81d5cf8e311
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jul 17 21:22:57 2012 +0100
+
+    i810: Split xaa routines from common acceleration methods
+    
+    Some of the routines in i810_accel.c are specific to XAA whilst others
+    are used elsewhere, for example in i810_dri.c. Therefore we have to be
+    selective over which ones we compile out without xaa.
+    
+    Reported-by: Knut Petersen <Knut_Petersen@t-online.de>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 53ff19f45a3cc4863845c23e8d3c2c2b95e03fd9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jul 17 19:40:16 2012 +0100
+
+    sna: Allow wedged CopyPlane to operate inplace on the destination
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d4fa4d5494db45b227c9ae7f7a90cd5dfd940027
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jul 17 19:29:32 2012 +0100
+
+    sna: Allow inplace copies for wedged CopyArea
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 217eeadf81a8cbb43e495e1e937acdd95c703377
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jul 17 19:35:06 2012 +0100
+
+    sna: Allow operation inplace to scanout whilst wedged
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 40ff29480a0dbf458adf1a1b0d3275ad1361530e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jul 17 18:38:49 2012 +0100
+
+    sna: Tweak fast blt path
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fce69c79c4840e7863d7c382da0d22be90a9f19a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jul 17 18:28:24 2012 +0100
+
+    sna: prefer fbBlt over pixman_blt
+    
+    It is currently much better optimised through memcpy.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c29f96d50839388377ad57c6366f9bc7ad8b9d0a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jul 17 13:02:51 2012 +0100
+
+    sna/gen7: Bump the number of pixel shader threads for IVB GT2
+    
+    Spotted-by: Kilarski, Bernard R" <bernard.r.kilarski@intel.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 799bae9e8ff53fb1b5c74f3278d530a58d66de9a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jul 17 17:07:10 2012 +0100
+
+    sna/dri: Do not allow an exchange to take place on invalid buffers
+    
+    If the SwapBuffers is called after we have resized a Window but before
+    the client has processed the Invalidate notification, then the
+    SwapBuffers will be referring to a pair of stale buffers. As the buffers
+    are no longer attached to the Pixmap, we can not simply exchange them.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 067aeaddb8047f01ae3a20b26ba0acf5ba2d035f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jul 17 15:33:19 2012 +0100
+
+    sna: Rebalance choice of GPU vs CPU bo
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7ebeea3f5c71959773478de44b08a967fe5acc8b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jul 17 15:10:43 2012 +0100
+
+    sna: Avoid the CPU bo readback for render paths
+    
+    As we exclude using the CPU bo if there is overlapping GPU damage, we
+    can forgo the call to keep the transfer the damage.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ed8c729ed02705fd03be1ab22a94b5aae13567c8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jul 17 11:21:30 2012 +0100
+
+    sna: Catch the short-circuit path for clearing clear on move-to-gpu as well
+    
+    I thought the short-circuit path was only taken when already clear, I
+    was wrong.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 359b9cc82de13b0ac89692896ac6104ff3be308b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jul 17 10:26:27 2012 +0100
+
+    sna: Limit the use of snoopable buffers to read/write uploads
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4f21dba6ee505217d63edd84611622e05aeb4593
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jul 17 09:26:46 2012 +0100
+
+    sna: Only drop the clear flag when writing to the GPU pixmap
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fbfbbee8288aba1e4754fd2dbc02e71f5e118cda
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jul 17 09:20:21 2012 +0100
+
+    sna: Fix glyph DBG to include clip extents and actual glyph origin
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f0ed0ca234a4bed986824845ff70e8554c0e579f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jul 17 08:35:20 2012 +0100
+
+    sna: Promote an undamaged pixmap to use the full GPU
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1f79e877fb6602bd0f9dd14ac9c3511f3b7044fb
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jul 16 21:18:24 2012 +0100
+
+    sna: Share the pixmap migration decision with the BLT composite routines
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d141a2d59007866c9eaad020c744be446e70c346
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jul 16 23:20:58 2012 +0100
+
+    sna: Disable snoopable bo for gen4
+    
+    Further inspection reveals that whilst it may not hang the GPU, the
+    results are not pleasant or complete.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 107feed2a4ca044313c70f83a62909187ff1f905
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jul 16 18:58:30 2012 +0100
+
+    sna: Disable snoopable uplaod buffers for gen4
+    
+    The sampler really does not like using snoopable buffers...
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 818c21165c746b7b410a6e6e23b1675d88db685d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jul 16 16:28:00 2012 +0100
+
+    sna: Fixup pixmap validation for sna_copy_area()
+    
+    Remember to offset the box by the drawable deltas in order to
+    compensate for compositing.
+    
+    Reported-by: Jiri Slaby <jirislaby@gmail.com>
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=52142
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 623d84bed7c47ac39348775ce35eec54196f6dac
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jul 16 16:07:37 2012 +0100
+
+    Wrap defines to avoid redefinition warnings
+    
+    Currently this only catches out ARRAY_SIZE, but wrap the other common
+    defines for consistency.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 907a2a7c97514d3f7610648ed87c7042a857f786
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jul 16 14:47:03 2012 +0100
+
+    sna/trapezoids: Fix inplace unaligned fills (on gen4)
+    
+    Reported-by: Sergio Callegari <sergio.callegari@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=52150
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6ce2f40249231f57cf464361ea5329cee1932ccf
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jul 16 14:46:39 2012 +0100
+
+    sna/trapezoids: Add some DBG to unaligned fills
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2721214868685123c973970a8ce0d93346ae0ee2
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jul 16 13:52:39 2012 +0100
+
+    sna: Move the disabling of CPU bo for gen4 to the render unit
+    
+    They appear to work fine with the BLT and only seem to cause issues when
+    used with the sammpler. So enable them for accelerated uploads and
+    downloads.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0777b146bf1a63c99e4d4af141e676a47b1f2dc9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jul 16 13:11:07 2012 +0100
+
+    sna: Use set-cache-level to allocate snoopable upload buffers
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 33443f7ee48fa54b6f4d09c93cddac0e32314b9c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jul 16 12:51:54 2012 +0100
+
+    sna: Add a couple of DBG options to control accelerated up/downloads
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 924060293826a1cc0d9d7bc26e913e46c6b2d054
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jul 16 12:03:47 2012 +0100
+
+    sna: Discard and recreate the CPU buffer when busy during move-to-cpu
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7024ef771ff170e61e788b5216c86b46e0f8ae6a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jul 16 12:15:54 2012 +0100
+
+    sna: Add a few DBG to show when CPU bos are being used for xfer
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c564414157e27417f0de1c0542dafd9b47e01eda
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jul 16 09:34:30 2012 +0100
+
+    sna: Disable the scanout flush when switch off via DPMS
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 536e7ab756d6821db79e4cd79a250af1c0f7d5a3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jul 16 12:16:26 2012 +0100
+
+    intel: Don't use stdbool without declaring it
+    
+    Reported-by: Fabio Pedretti <fabio.ped@libero.it>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0c32be15b06ad63c1fc1371de879f2d879080f6b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jul 5 19:26:48 2012 +0100
+
+    uxa: Remove Shadow hack
+    
+    This was an incomplete hack so deprecate in favour of Shadow-on-Steriods,
+    SNA.
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=47324
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6a18a0936eafc45ab920ab0eecf2fc2a601c41a7
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jul 15 20:26:00 2012 +0100
+
+    configure: version bump for 2.20.0 release
+    
+    The day SNA hits mainstream...
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6fa059330decd1437eef4928d732ec91fd4e17e7
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jul 15 14:04:48 2012 +0100
+
+    sna: Avoid creating a CPU bo for uploads if we already have a large GPU bo
+    
+    And vice-versa if already have a large CPU bo.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a253c95ec63b2b075e66ae7380fed6a73469eba5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jul 15 13:32:35 2012 +0100
+
+    sna: Prefer uploads to be staged in snoopable bo
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ef6d94a8444927941db108811e1a26357dc3f18e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jul 15 11:46:53 2012 +0100
+
+    sna: Simply reverse all the boxes if dx <= 0 and dy <= 0
+    
+    In this fairly common case, avoid both the double pass and use a simpler
+    algorithm as we can simply reverse the order of the boxes.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6601a943ff968ac39ba198351c50dc883cb4232e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jul 15 11:39:56 2012 +0100
+
+    sna: Keep track of the base pointer for the reordered boxes
+    
+    So that we avoid freeing an invalid pointer.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ef34d5cf415ad7459ab44b0ec2e70b14150735fc
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 14 23:25:17 2012 +0100
+
+    sna: Make sure we check for a busy CPU bo before declaring is-cpu
+    
+    Even if the pixmap is entirely damaged on the CPU, we still may be in
+    the process of transferring it and so cause an unwanted stall.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0e397e4a1dc23ed07089c967612d705584f3b376
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 14 21:35:23 2012 +0100
+
+    sna/glyphs: Perform the fallback mask reduce before moving the glyph pointers
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit db1ee13a53b0c1348b7566ee60ee1b7b384ef59a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 14 21:26:01 2012 +0100
+
+    sna/gen7: Check for gradient allocation failure within spans
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 86479e97460da798a3804cbb4ae39e62de881af1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 14 21:24:04 2012 +0100
+
+    sna/gen7: Uses EXTEND_PAD for its alpha-gradient with spans
+    
+    Fixes regression from 2b94f9a043.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f17037275c05198c3c3f456964fd42032f9085b6
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 14 20:11:17 2012 +0100
+
+    sna: Reorder overlapping boxes for CopyArea/Window
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 86e09d14bd00344d378b86a19ebb44f7d946926c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 14 17:51:31 2012 +0100
+
+    sna: Tidy sna_copy_boxes
+    
+    So there appears to be a bug hidden here. But only when we scroll
+    upwards in a GTK+ application. Hmm.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 924f596463555db27214fd8227218c2e21ecddc8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 14 19:03:08 2012 +0100
+
+    sna: Avoid BLT to snoopable bo on older gen
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 44e226b1d9fca8cb95b0864adf8708b03ee8472c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 14 18:36:29 2012 +0100
+
+    sna/glyphs: A repeat of the earlier typo for pixman glyphs
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 797ebf937fcfcc87502727c70e6b52f89fecc799
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 14 16:58:18 2012 +0100
+
+    sna/glyphs: Fix typo and render glyphs to the small mask
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2b94f9a043372ffede01339eea99377a71169fbc
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 14 16:38:21 2012 +0100
+
+    sna/gen7: Preselect sampler
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 50d61c38bdb720c17ba5bfcaf97032338e466d9b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 14 16:07:32 2012 +0100
+
+    sna/gen4: Fix typo introduced in checking dst format
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fc91b1f157f9e6e4097e662e2890574e530344ac
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 14 15:48:50 2012 +0100
+
+    sna/gen7: Only emit the render flushes between operations
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d30dc59651f156e9d4572141e2c54af89d007a37
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 14 15:42:19 2012 +0100
+
+    sna/gen7: Only fallback to BLT for a redirected target
+    
+    As we can always use a partial surface for the source.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9f05b0c03b1fdab474b436431c430028fca1937e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 14 15:03:32 2012 +0100
+
+    sna/gen4+: Fix up card/dest format confusion in previous commit
+    
+    That would have been much more successful had I not supplied the wrong
+    opaque formats to the sampler.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fffbc34e4621898eee9b80bf8b6b3699bcade52a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 14 14:54:27 2012 +0100
+
+    sna/gen4+: Translate to card format using a switch
+    
+    GCC produces faster code than a walk over the format tables.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 95fdd9af5c8a8360d02debc400e75869c36f05ca
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 14 13:05:27 2012 +0100
+
+    sna: Enable pixman_glyphs if available
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3f764ee4c50567cfb831495d42cb6c2bb94055ad
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 14 12:29:47 2012 +0100
+
+    sna/dri: Presume an unknown chipset will want i965_dri.so
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 39845280b5a9d0ed60c6a158c3d0df9fb8756d40
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 14 12:14:28 2012 +0100
+
+    sna: Allow BLT support on future unknown hardware
+    
+    Assume that if the kernel recognises the chipset and declares it has a
+    BLT, we can use it.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b260ca44b3aaba2c8cd25640ad7ac9ca6478b0f2
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 14 09:59:07 2012 +0100
+
+    Drop some unused includes
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f517bdb12b909ef9d0897166bdabc537551a065b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 14 08:56:21 2012 +0100
+
+    sna: Do not perform batch compaction on old kernels
+    
+    As they will reject the delta pointing outside of the target batch.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ce69a1e8686889f1eebb4cb3a39c41f473e58b93
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jul 13 23:25:02 2012 +0100
+
+    sna: Add some DBG for selecting glyph path
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b68b2d90915f7a97e43a39e3117927544886fba0
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jul 13 23:24:32 2012 +0100
+
+    sna: Add some DBG for short-circuiting choice of source bo
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ad4786b285074b5bd70b3ad0bea6ec1b77ad6740
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jul 13 22:24:51 2012 +0100
+
+    sna: Aim for consistency and use stdbool except for core X APIs
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a05c3547bba52288bae872ea672ffe2f4dab2ffa
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jul 13 15:06:15 2012 +0100
+
+    sna/gen4: Simplify comparing the pipeline-pointers against the previous
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ea9ec18505645dfec85ab96bbbbbc1793830c737
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jul 13 11:39:01 2012 +0100
+
+    sna: Split CloseScreen into two phases
+    
+    In order to get the ordering correct we need to free the xf86_cursors
+    before calling the miPointerCloseScreen. This requires us to insert a
+    hook at the top of the CloseScreen chain. However we still require the
+    final CloseScreen hook in order to do the fundamental clean up, hence
+    split the CloseScreen callback into two phases.
+    
+    Reported-by: Jiri Slaby <jirislaby@gmail.com>
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=47597
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0f03f7b4359fcbcde651bc1554ddff4fe10bc53b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jul 13 10:35:27 2012 +0100
+
+    sna: Only try to enable DRI2 if the module is available at runtime
+    
+    Blatantly cribbed from Michel Danzer's patch for ati...
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b5d6a57f12025aef9850c7d9baa6905f776be971
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jul 12 22:16:27 2012 +0100
+
+    Enable compilation of SNA by default
+    
+    But only if we meet the required versions of Xorg and leave UXA as the
+    default AccelMethod for the time being.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6c2975ab2943478b3a246b5fb231f9f3df2d8475
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jul 12 22:14:39 2012 +0100
+
+    Fix the reporting of whether SNA is configured
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fd15ce65ab8ce5cf571e37daa7db1ee245616cd4
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jul 12 20:32:14 2012 +0100
+
+    sna: Fix build without DRI2
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 22be9988b933f33fc5247a9abc3b00a7f2e4a202
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jul 12 19:49:34 2012 +0100
+
+    sna: Check for failure to initialize the sprite pointers
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 32e7f4ee64867779b2def6fcd882708d7b0e2cf5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jul 12 19:39:10 2012 +0100
+
+    sna/glyphs: Fix array allocation for list_extents
+    
+    Originally I intended to skip assigning the box on the last list.
+    However, loop simplicity failed and now we run the risk of writing
+    beyond the end of stack_extents, and overwriting the list_extents
+    pointer.
+    
+    Reported-by: Jiri Slaby <jirislaby@gmail.com>
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=47597
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0477b5fb6f040f3bad86bb314a24df1bcd660aed
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jul 12 19:37:02 2012 +0100
+
+    sna/glyphs: Apply mask reduction along fallback paths as well
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 16aaa51b5d326f44974489f5b29716c7ff5ab48e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jul 12 15:26:54 2012 +0100
+
+    sna: Rearrange the tests for dropping the glyph mask
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 600746f923b046187a66b60b5e5d2b187475730e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jul 12 14:16:31 2012 +0100
+
+    i810: Remove vestigial reference to xaa.h
+    
+    i810_hwmc.c can pull it in via i810.h like everybody else. As for
+    xaalocal.h, I have no idea what that is... Both appear to be cut'n'paste
+    includes.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1d9ab2e7101167075112a472ee82530dc0365183
+Author: Zhigang Gong <zhigang.gong@linux.intel.com>
+Date:   Thu Jul 12 18:47:50 2012 +0800
+
+    uxa/dri: Fix a buffer leak on pageflipping when enabling glamor.
+    
+    We need to put current front_buffer to back buffer thus we
+    don't need to create a new back buffer next time. This behaviou
+    should be the same with or without glamor. Previous code
+    incorrectly discard the previous front_buffer and cause a
+    big buffer leak problem.
+    
+    Signed-off-by: Zhigang Gong <zhigang.gong@linux.intel.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fa89e0614563cbe0cc45e6d7e7584cb333244c27
+Author: Zhigang Gong <zhigang.gong@linux.intel.com>
+Date:   Thu Jul 12 18:47:51 2012 +0800
+
+    uxa/glyphs: Bypass uxa glyphs operations if using glamor.
+    
+    glamor_glyphs will never fallback. We don't need to keep a
+    uxa glyphs cache picture here. Thus simply bypass the
+    corresponding operations.
+    
+    Signed-off-by: Zhigang Gong <zhigang.gong@linux.intel.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d25000e1f31e78aff2ab43adb12aec0aac36f56f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jul 11 22:37:25 2012 +0100
+
+    i810: Tidy configure detection for XAA/DGA
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 44a1528c15eec9b3f93651e779013137864d4d2b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jul 11 15:05:32 2012 +0100
+
+    sna: Remove unused cached partials list
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 94d489ae43a2c4d4d9ddc9ce30ff1a9142b77d4a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jul 11 14:25:20 2012 +0100
+
+    sna: Minor tweak to upload in place if the CPU bo is busy
+    
+    Since we have to pay the price of the stall anyway...
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b5db90aa52f10897ad2d7795df94c0e3d2878aea
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jul 11 12:52:24 2012 +0100
+
+    sna: Discard the mask for "non-overlapping" glyphs
+    
+    If we can acheive the same rasterisation results without the mask,
+    rendering the glyphs-to-dst is so much faster that it outweighs the cost
+    of checking for overlapping glyphs.
+    
+    The penalty is then for code that correctly declared that it required
+    a mask, who now have an extra ~10% overhead in the processing of their
+    glyphs.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 665c9cbdcf2c493cac29d316eaffa2abe197a183
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jul 10 19:01:12 2012 +0100
+
+    sna: Disable periodic scanout refresh if all outputs are disconnected
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 85fdc3143b157fd7ba3453efc86da8238d9de316
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jul 10 12:43:46 2012 +0100
+
+    sna: Avoid the expensive recomputation of the region when copying
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 747ed0ca28bb46fc45ff20acd1f82212fa2b46bd
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jul 10 17:05:20 2012 +0100
+
+    sna: Only promote to full GPU if we already have a GPU bo
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 232217eef8f99f5678d65bf9aa5b898ef6d3b3c6
+Author: Daniel Stone <daniel@fooishbar.org>
+Date:   Tue Jul 10 00:32:13 2012 +0100
+
+    i810: Make DGA optional
+    
+    Don't build DGA when it's not available, or when we don't want it.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 78dc0c04745ad4485b994f67833f4a155749f01d
+Author: Daniel Stone <daniel@fooishbar.org>
+Date:   Tue Jul 10 00:32:13 2012 +0100
+
+    i810: Make XAA optional
+    
+    Don't build XAA when it's not available, or when we don't want it.
+    
+    Signed-off-by: Daniel Stone <daniel@fooishbar.org>
+
+commit 45ab003a5860fd4290df24739d2520fddfe27a8f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jul 9 21:28:40 2012 +0100
+
+    sna: Check for overlapping glyphs within each list, then overlapping lists
+    
+    Spotted by Zhigang Gong is this optimisation to avoid the problem with
+    multiple lines passed in a single request (using multiple lists). As the
+    start of line will overlap with the previous line when we use the simple
+    bbox comparison, we always declare those runs as overlapping and so we
+    cannot substitute a glyph mask. However, we can reduce the problem to
+    only checking for overlapping glyphs within a list and then checking for
+    overlapping lists. Very, very clever.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8066bc33d78e78ce7c13833b08a7daaea2f3ed22
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jul 9 11:25:11 2012 +0100
+
+    sna: Fix reversal of inside logic for BitmapToRegion
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8a9a17cd092d156272e8953974119f527b2b77eb
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jul 9 11:12:12 2012 +0100
+
+    sna: Improve the check for assertions
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b11bc37684181390fc1400afb44054785104ca15
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jul 9 11:09:16 2012 +0100
+
+    sna: Simplify the DBG incarnation
+    
+    It was only ever used in conjunction with HAS_DEBUG_FULL. For debug
+    purposes it is as easy to redefine DBG locally. By simplifying the DBG
+    macro we can create it consistently and so reduce the number of compiler
+    warnings.
+    
+    Long term, this has to be dynamic. Sigh.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 21798a88676e91049917fafd3196dd4374b94226
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jul 9 09:23:20 2012 +0100
+
+    sna: Promote large operations to use the whole GPU
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1b6ad7a6ae6820c8f66d1c80613885ee84e7d316
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jul 9 08:54:11 2012 +0100
+
+    sna: Only consider large clears as candidates for GPU migration
+    
+    If we only operating on a small region of the pixmap and have require
+    damage migration in the past, we are likely to require migration again
+    at some point. So keep track of small damage areas.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d8a75538ea1d2a79d6282b0e2dfd73cfdea1a480
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jul 9 08:38:39 2012 +0100
+
+    sna: PadPixmap only writes to the out-of-bounds bits
+    
+    So we only need to delcare it as reading the source pixmap and not mark
+    it as damaged.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit eafb454edf188e7dada1ddf886d1e46f0151968d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jul 9 08:38:08 2012 +0100
+
+    sna: Rename conflicting symbols with uxa
+    
+    Reported-by: Christoph Reiter <reiter.christoph@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=51887
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0af29175a087cc2e509962f8828790c8f7232611
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jul 9 01:24:23 2012 +0100
+
+    sna: Just use a linear scan to find the terminating clip box
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2941a5fe15626730869a48a63bb088e8ae2c0549
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jul 9 00:20:57 2012 +0100
+
+    sna: Remove the consideration of CPU damage for overwriting FillRect
+    
+    We consideer a singular FillRect to be a sequence point in the rendering
+    commands, that is it is usually used to clear the background as the first
+    operation in a drawing sequence. So it is useful to ask if we can move
+    the sequence to the GPU at that point.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8be00b6d4767ffc09328d246d02ee75312ad5842
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jul 8 20:48:40 2012 +0100
+
+    sna: Substitute the reduce clip region for fallback ops
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0457935a70f6c1ae06f61f9ad0dd1bdc825465fa
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jul 8 20:38:03 2012 +0100
+
+    sna: Review placement hints for fallback operations
+    
+    Look for those operations that maybe better via the GTT and those that
+    are preferred to be in CPU cache. The wonders of multiple layers of
+    heuristics.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b7f0b0e7e3f66165b87c46f897de536cf74a9daf
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jul 8 19:59:34 2012 +0100
+
+    sna: Remove function for force-to-gpu
+    
+    This is now enitrely done in the core move-to-gpu as a special case.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit bb8770158c08394c2de79e0ca1c1b3112e17dd23
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jul 8 18:53:25 2012 +0100
+
+    sna: Apply the clear color when resizing the front buffer
+    
+    If the existing front buffer is clear, just apply the clear color to
+    then new buffer rather than copy the old one across.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8dd14855d75240501aa2d089bcdfa46e7badbf18
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jul 8 15:46:41 2012 +0100
+
+    sna/dri: Review stale comments
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3bb7a530e77a5c6e8bae0fb14c570feafe37c2bd
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 7 20:53:27 2012 +0100
+
+    sna/dri: Fix cross-chaining of pageflip vs vblank
+    
+    And double-check that the drawable is still flippable before completing
+    the delay exchange.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1454df8caa51fff9810a9b792d17aa82b247a4ae
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 7 19:59:50 2012 +0100
+
+    sna/dri: Use draw ref directly
+    
+    As we hook into the DestroyWindow notification, we can reliably use the
+    original Drawable reference and avoid the secondary object lookups.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9abb6c09bdb9831db5f0626eed70663a2dc39fc6
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 7 18:43:06 2012 +0100
+
+    sna/dri: Remove dead code for 'old_fb'
+    
+    The member still exists but is never set and is unused.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ad877abdc70b842afd202b2f97892d97a0b8d151
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 7 17:48:52 2012 +0100
+
+    sna/dri: Attach the chain of frame events to the Window, not pixmap
+    
+    So that we can have multiple clients swapping in separate windows
+    concurrently.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 81cd9aa80091b9bb08b50062f117d678a3bc7a91
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 7 16:12:49 2012 +0100
+
+    sna: Tweak start/stop of the deferred flush
+    
+    As we now emit work whenever we wakeup and find the GPU idle, we rarely
+    actually have pending work in the deferred flush queue, so try to avoid
+    installing a timer if we are not accumulating work.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6cb0c631e4eafc09f1677c73906de9108d735de4
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 7 15:10:18 2012 +0100
+
+    sna/dri: Clarify the message for one failure case
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9a314d18cef1e08b23f9dca861ad2ba396bb1080
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 7 14:56:05 2012 +0100
+
+    sna/dri: Add a couple of missing VG_CLEAR on vblanks
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 66a53c15cb5ee729fb43ea9713fd8538a3f982ad
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 7 14:46:08 2012 +0100
+
+    sna/dri: Couple the frame events into DestroyWindow
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 975a566bed72ddc79853b329307ed72a82df24b0
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 7 14:12:51 2012 +0100
+
+    sna/dri: Replace the DRI2 drawable type with a devPrivate
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0da1c98f660269806408af5fd08c1ab5e538082e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 7 12:15:28 2012 +0100
+
+    test: Add missing header for distcheck
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e3e58123d36924c760ab6f58a7155a040422e91d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jul 6 15:22:26 2012 +0100
+
+    sna: Fixup fb wrapper
+    
+    To accommodate changes in the Xserver and avoid breakage; would have been
+    much easier had the fb been exported in the first place.
+
+commit 5d2f88fd9972c62c87098ddc7fee7b6f0cea0fdb
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 7 10:07:51 2012 +0100
+
+    sna: Add a couple of DBG flags to control upload buffers
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 18b3090381ac0fb61df96a7c6b2f12aacf180ee8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 7 00:06:36 2012 +0100
+
+    sna: Fixup USE_INPLACE debug hint
+    
+    After we enabled inplace readback, we can just apply the INPLACE hint to
+    all fallbacks, but instead apply it to the automatic testing for a
+    potential inplace operation.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 24b59a8955eb15522ad334a541530aca937fcf07
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jul 6 14:16:36 2012 +0100
+
+    sna: Refactor a common function: is_clipped()
+    
+    Had I done this earlier, I would not have the bug in the open-coded
+    version. Le sigh.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 68b357454af705f1ed3a9599435a402f2611a180
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jul 6 10:58:06 2012 +0100
+
+    sna: Clear garbage from the new front buffer when resizing
+    
+    Avoid displaying a buffer filled with random junk when resizing (and
+    thereby creating a new) framebuffer.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5784e0f21dc91f33c99a507105a0695cc53d6574
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jul 6 09:42:37 2012 +0100
+
+    Allow matching against any device supported by drm/i915
+    
+    However we cannot enable acceleration if we do not recognise its
+    hardware layout or instruction set.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1ee10cc3b2aa0888753eeb25c7fde7296a3c92eb
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jul 6 00:01:58 2012 +0100
+
+    Make the detection of broken pre-production hardware verbose
+    
+    These SDV should have been returned to the manufacturer long ago and
+    replaced with real systems. So if they are still in use, add a gentle
+    reminder.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit cd2dd3016e0834d1636aa96511608022a4cdbcd1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jul 5 19:58:54 2012 +0100
+
+    sna: Fix clipping of glyphs-to-dst for partially obscurred windows
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0f086acb259d7732560c5d0d642308de028a4445
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jul 4 12:26:18 2012 +0100
+
+    sna: Fallback to attaching a shadow fb if we fail to setup the crtc
+    
+    As we've chosen to fix the kernel to handle CRTC offsets > 4096, drop
+    the automatic workaround. However, allow the user to force creation of
+    PerCrtcPixmaps for the purpose of debugging (and to workaround the bug
+    in older kernels) and to fallback to trying a shadow fb if the setcrtc
+    fails with the composite fb.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7e8060f837475c85cc061ba4a5388140cd227613
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jul 5 03:31:12 2012 +0100
+
+    sna: Do not force GPU allocation if CPU bo is already busy
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c32bb286dc9a489232030f6abe9076411fbcecfd
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jul 5 03:18:12 2012 +0100
+
+    sna: Make sure damage is flushed to the CPU bo before use
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d46cc00b3cd903bfaf37ad7d4a60676c4b346983
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jul 5 02:19:26 2012 +0100
+
+    sna/dri: Assert that our pixmaps sizes are invariant
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3c1f58fe45e8f4f18c45733f862ca1f290dde84d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jul 4 23:03:44 2012 +0100
+
+    sna: drop an unused ret var
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a69a47f94037698a360f8b8611f6f3e58a20ca87
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jul 4 22:15:45 2012 +0100
+
+    sna: Fix detection of EIO through throttle
+    
+    When using drmIoctl, one needs to check the errno for the actual error
+    code.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f2fdb0da83d6208c884ffde2bb30d0a67fc75217
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jul 4 21:43:22 2012 +0100
+
+    sna: Use throttle() to confirm a GPU hang
+    
+    This has two effects. The first is that we confirm that the EIO was
+    indeed a GPU hang and not some other form of I/O failure (for example
+    swapin). And the second is that it means we also print the warning to
+    look for an i915_error_state when we detect a GPU hang.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b8c2b34e39c7f2ee2597f8727b9b98c6aac93fb1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jul 4 19:53:27 2012 +0100
+
+    sna: Simplify timer execution
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 844ab84c64fde38db315787e16a9f7f674d0f88c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jul 4 17:58:27 2012 +0100
+
+    sna: Fix leak around ENOMEM error path in sna_copy_boxes
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 54ee41bf05e328ed2f2cd2a64c21afe3efe2556a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jul 4 17:40:58 2012 +0100
+
+    sna: Pass a hint to the backends when using copy_boxes for readback
+    
+    If we expect to only emit this set of copy_boxes() and then submit the
+    batch, we would prefer to use the BLT for its lower latency.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d36623aaebdc454bd281f34332edcad5d94f34c0
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jul 4 13:55:25 2012 +0100
+
+    sna/dri: Remove broken code for buffer xchg from AsyncSwap
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0bdb4d0d3693df007a6cfc9a75bb0deddd812d53
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jul 4 13:12:43 2012 +0100
+
+    sna/dri: Fixup blit fallback path to use xchg when possible
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit aeeed323f9081875a804ae19fb356bee2a61e7b0
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jul 4 11:52:27 2012 +0100
+
+    sna/dri: Select the appropriate copy engine based on the current src ring
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5026b6a147f411582af24ffd17c87a81da5eea0b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jul 4 09:39:59 2012 +0100
+
+    uxa: Install the drm_wakeup_handler for vblank events in !use_page_flipping
+    
+    Even if page-flipping itself is disabled, we still want to allow the
+    client to schedule wakeups for some future vblank which requires
+    listening to the kernel vblank notifications.
+    
+    Reported-by: Eric Anholt <eric@anholt.net>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=51699
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 79309dd55f20098e12ead5427c811f237d5592fa
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jul 3 22:27:39 2012 +0100
+
+    sna: check for failure to change cache level on the bo
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9e2ac8a413c05aafd1c69775c5b0fa5f1f37ac23
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jul 3 19:33:55 2012 +0100
+
+    sna: Use set-cache-level ioctl to create CPU bo
+    
+    As an alternative to vmap, we can use the kernel for all memory
+    management through bo, which is much preferred for its simplicity (i.e.
+    avoiding introducing even more vm complexity).
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f26163e916e21f6b64a19c147165f2f2c9c5466d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jul 3 18:51:46 2012 +0100
+
+    sna: Guess when the client is attempting to read back the whole pixmap
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c597e6cd4cb4406878eae07c04ad420d8185d99e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jul 3 13:26:33 2012 +0100
+
+    sna: Fix iterator typo
+    
+    Increment the iterator, not the end-stop.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2d087eadd9cd3aa2e2ccd73a568286d21702d29a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jul 3 11:54:02 2012 +0100
+
+    sna: Also prefer to use the dst GPU bo if CopyArea reduces to an inplace upload
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit dbe3a5ca1e6558bcee29d893aba8cc352220a36d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jul 3 11:48:15 2012 +0100
+
+    sna: Attempt to reduce all-damage on the CPU
+    
+    As we now treat CPU all-damaged as a special case for deciding when and
+    where to migrate, look out for that condition after adding damage.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3a41248195e8b327a5d970726450bd2077cdaf0f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jul 3 11:22:54 2012 +0100
+
+    sna: Operate on the original boxes for CopyArea
+    
+    Be consistent and avoid the confusion when mixing operations on the
+    region boxes and the original boxes.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e3bc91842bf186ec149c852f48993235ef7ad27f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jul 3 10:21:06 2012 +0100
+
+    sna: Allow booting on older kernels by disabling HW acceleration
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit affdebcb2d09cd8fdc5aadb2d8df3193587e4a06
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jul 2 18:50:26 2012 +0100
+
+    sna: And free the DIR after use
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e7b31b6d0a32f76db4a8aef64c77d4afe808fb6c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jul 2 14:01:36 2012 +0100
+
+    sna: Consolidate CopyArea with the aim of reducing migration ping-pong
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ce27a81ac508368d54f1237893a9b1214cf3e3d0
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jul 2 17:52:24 2012 +0100
+
+    sna: Clear cpu flag after deciding to use gpu bo
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2f1b7e8a23ac3086dda0025ecf09dd1feac94837
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jul 2 17:53:01 2012 +0100
+
+    sna: Check for non-existent /sys/class/backlight directory
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d12d50d107d403c3cf4dfe24bb63ce1006d0e025
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jul 2 14:09:21 2012 +0100
+
+    sna: Skip hidden and special entries inside /sys/class/backlight
+    
+    Just to avoid the warnings after fallback to comparing the d_name to
+    the list of known interfaces.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e80f9c4670a0e84521907b1baa059322784b1558
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jul 2 10:21:42 2012 +0100
+
+    sna: Prefer backlight iface based on /sys/class/backlight/*/type
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 61e16dc5673a1ac96b2ecee072cc3e80971be5d9
+Author: Tom Hughes <tom@compton.nu>
+Date:   Mon Jul 2 10:23:56 2012 +0100
+
+    Add asus-nb-wmi backlight control
+    
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=51593
+
+commit 543816011d05f0cf40b05ec58f87a5954397a224
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jul 1 18:36:55 2012 +0100
+
+    sna/gen7: Correct two minor misues of equivalent GEN6 constants
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 839fea7f779ca63c32817ee4ba695dfce3344980
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jul 1 18:23:38 2012 +0100
+
+    sna/gen6: Boost VS entries to maximum
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fbd114507d9bf2e2b1d1e52c5e42dc6cdbd8c9a0
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jul 1 14:03:31 2012 +0100
+
+    sna/dri: Assert that the replacement bo is large enough for the pixmap
+    
+    Just another paranoid sanity check.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 675cbd5fade91fd6a6bf533a31b0a211237af6e8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jul 1 12:39:13 2012 +0100
+
+    sna/trapezoids: Skip the division when converting coverage to floating point
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 182c3637cc5d3a6ce52127087aa2f19ca2b42719
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jul 1 13:23:44 2012 +0100
+
+    sna: If the pixmap is marked for flushing, prefer to use the GPU
+    
+    Again, to avoid the forced ping-pong as we upload the damage after
+    nearly every operation, simply prefer to use the GPU in such cases.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 35b1ac138002c206a6d6b866d49a0d73705dd3ac
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jul 1 10:53:07 2012 +0100
+
+    sna: After an operation on the CPU, prefer not to use the GPU
+    
+    A nasty habit of applications is to fill an area, only to read it back
+    with GetImage, render locally and replace with PutImage. This causes a
+    readback of an active bo everytime, so let's try to mitigate that by
+    preferring not to use the GPU after a forced readback.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e625c02e6266403fcd8a72ccce2c6c6291e2e5fc
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jun 30 09:34:21 2012 +0100
+
+    sna/damage: Early check for contains-box? if subtract and box outside region
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit abd7be1cee6f2f494a11cd9d2e7888c3043ffc02
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 29 15:32:10 2012 +0100
+
+    sna/dri: Prefer GPU rendering if no more CPU damage on a DRI bo
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 67b87e4f7cf6c3ab9cfccc9fe43a824bfe84f393
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 29 15:03:12 2012 +0100
+
+    sna/dri: Optimise clip reduction with copy-to-front to an unclipped Window
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit eae5e1275cd11703de2bca67dacd1d57129b561a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 29 13:12:52 2012 +0100
+
+    sna: Install the ModeSet handler as the base handler
+    
+    This way we can safely ignore it across server regen.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 15a0761cad862a5d73bbc2af81bc5267e66c307e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 29 12:22:55 2012 +0100
+
+    sna: Only consider the request list when deciding whether the GPU is busy
+    
+    Micro-optimisation to overhead extra checks and to make sure an
+    unflushed bo doesn't prevent us from submitting more work before
+    sleeping.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4061f05dd61a7200d91d30b9b4a2ab0c61306870
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 29 11:40:18 2012 +0100
+
+    sna/trapezoids: Write unaligned fallback boxes inplace
+    
+    As this is a pure write operation (though we will write the edge pixels
+    twice) we can perform this operation inplace and incur a slightly slower
+    trap creation at the benefit of avoiding the later copy.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 44e41536b7728c03a4899a97242960ae7ed35624
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 29 11:39:47 2012 +0100
+
+    sna/trapezoids: Render the partial left-edge of fallback unaligned boxes
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e6f9bfe1e20c4c76822d77598f4f1c7e10754929
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 29 11:06:33 2012 +0100
+
+    sna: Use currentTime rather than GetTimeInMillis()
+    
+    The overhead of reading the hpet() on every block handler (more or less)
+    is exorbitant, so trust that we update currentTime frequently enough to
+    be a good approximation - the side effect is that we will wakeup
+    slightly to earlier from using an old value for the current time.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c6c4f30e194eb3b8a2421134bb005f1542b3ef9f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 29 10:14:52 2012 +0100
+
+    sna: Add assertions to check that we do install the timers
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 87c8f5a47e3abb7ff887aab45b6389cf9b8d8008
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 29 09:33:09 2012 +0100
+
+    sna: Make the post-flip delay explictit
+    
+    As the kernel is inconsistent in enforcing this across generations,
+    handle the synchronisation of the pageflip explicity. Ultimately this
+    should be replaced with a tripple buffer mechanism.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 31caa43a21a68174386682fd558c911c7c03d76f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 28 17:05:46 2012 +0100
+
+    sna/gen5: Check harder for need_upload() fallbacks
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7c3eb1fda9e567a300a8138acdac9ec11e010b11
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 28 17:04:26 2012 +0100
+
+    sna: Correct inverted logic for checking xrgb drawables
+    
+    Reported-by: Christoph Reiter <reiter.christoph@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=51472
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c3e2c1332d8d5a3944df99cc11aa66c586add3e8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 28 12:34:36 2012 +0100
+
+    sna: Fix the application of the crtc offset for posting damage
+    
+    The damage boxes are in framebuffer (source) space, so we need to apply
+    the offset for the boxes in crtc (destination) space.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 47e6bfa4f40cf7efcfe7eee24d2512d737fd7e89
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 28 12:24:27 2012 +0100
+
+    sna: Force use of per-crtc scanout if the offset is too large
+    
+    On gen4+, the scanout offset into a tiled surface is specified through
+    the DSPTILEOFF register and limited to 12bits of precision. So if we
+    have a CRTC positioned in that nether-region, we need to allocate a
+    separate per-crtc pixmap for it and perform shadowing.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 93e77ee019248fe77483e83f2210d584bb5d1be2
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 28 12:02:32 2012 +0100
+
+    sna: Quieten kernel debug complaints when disabling crtc
+    
+    Even if we are obviously turning the crtc off, it still complains if the
+    number of connectors is non-zero. So make it so.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 85e4f48a87ddbc227af8f4af5ea46ae17902b111
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 28 11:44:45 2012 +0100
+
+    sna: Add a DBG to the periodic flush mechanism
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 87dd6408a5c29e4808283df78a981de0a3c0a79c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 28 10:53:59 2012 +0100
+
+    sna: Correct the reversal of the periodic flushing semantics
+    
+    Regression from 1e9319d (sna: extend RandR to support super sized
+    monitor configurations) which tried to take into account the need to
+    flush the shadow CRTC bo in addition to the normal scanout bo. In the
+    refactoring of the need_flush(), the double negative was missed.
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 05f486f64bc7ea4a8a71f5d792fa586ac0843414
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 28 10:42:21 2012 +0100
+
+    sna: Flush the per-crtc render caches for rotated scanouts
+    
+    We need to manually flush the render cache in order for results to be
+    visible on the scanout.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit db7979981032d5647069f213a063dcbf78e57890
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jun 27 09:36:58 2012 +0100
+
+    sna: s/width/height/ cut'n'paste typo
+    
+    Reported-by: Zdenek Kabelac <zdenek.kabelac@gmail.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fcbbe1664ae62ae275068cc040f385d2320d5213
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jun 27 09:30:44 2012 +0100
+
+    sna: Remove a trailing ';'
+    
+    The unwanted ';' caused is_cpu() to always return false if a GPU bo was
+    attached. Not necessary a bad thing, just misses the potential
+    optimisation where having chosen to prefer to use the CPU path we then
+    have to migrate to the GPU even though the bo is undamaged or idle.
+    
+    Spotted-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a072ab506569ecff5b4c57fa90f7a417db69f33b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jun 26 17:24:37 2012 +0100
+
+    test: Add client side copy to FakeFront for emulating CopyBuffer correctly
+    
+    The server manages FakeFront following a flip, but it the client
+    optimises a swap by replacing it with a CopyRegion, it is expected to
+    also update the FakeFront itself. Replicate that behaviour so that the
+    timings for the test case are consistent with mesa.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 96804c74f8f0d19fc1b9db467cf050f4934fe83b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jun 26 17:09:45 2012 +0100
+
+    test: FakeFront rules
+    
+    Oh my, I just once again rediscovered the copy on every flip due to the
+    requirement for keeping FakeFront uptodate for reads after a SwapBuffers.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f306cd557ef263ff5057e413c335cc75bc0f7895
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jun 26 14:59:37 2012 +0100
+
+    sna/dri: Hold a reference to the cached DRI2 buffer on the front buffer
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a87f2b9325bfad2bb3f93226706b6f9a09598945
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jun 24 13:48:38 2012 +0100
+
+    sna/gen4: Check for peculiar initial values for the surface offset
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8f4221a2520b7ed1f67b41185c2e4842e83e53ef
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jun 26 15:56:50 2012 +0100
+
+    test: Add a simple exercise for DRI2 swap paths
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a505015a254d6c6e24f0542bc141cde873dc6f34
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 25 22:50:47 2012 +0100
+
+    sna: Force DPMS to be on following a modeset
+    
+    Similarly to UXA, this papers over inconsistent behaviour in the kernel
+    in handling the DPMS upon a modeswitch.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b7a8c94cdb9cf42a31f8ce128d70e23458ba2042
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 25 20:49:59 2012 +0100
+
+    sna: remove the assert(0)s along error paths
+    
+    This were there as a debugging aide to see if we ever hit unreachable
+    code paths - mainly along corruption inducing GPU wedged recovery paths.
+    They are superfluous and just scare the reader.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 15c0ee445f603033c82f357fedfc7737d198d7b3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jun 24 19:28:03 2012 +0100
+
+    sna/gen5: Tweak thread allocations
+    
+    Bump the alloted number of threads to their max. Using more threads than
+    cores helps hide the stalls due to sampler fetch, math functions and urb
+    write. Specifying too many threads seems to not incur a performance
+    regression, suggesting that the hardware scheduler is sane enough not to
+    overpopulate the EU.
+    
+    A small but significant boost, peak x11perf -aa10text on an i3-330m is
+    raised from 1.93Mglyphs/s to 2.35Mglyphs/s.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fa10005ce31483827547b7f71eae066899f0026c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jun 23 17:28:00 2012 +0100
+
+    sna/dri: Perform an exchange for a composited windowed SwapBuffers
+    
+    If the front buffer is not attached to the scanout and has not been
+    reparented, we can simply exchange the underlying bo between the
+    front/back attachments and inform the compositor of the damage.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 53d735ddb16b0204662b8584aa22998ba53deec1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jun 23 10:16:44 2012 +0100
+
+    sna/dri: Queue windowed swaps
+    
+    Implement "tripple-buffering" for windowed SwapBuffers by allowing the
+    client to submit one extra frame before throttling. That is we emit the
+    vsync'ed blit and immediately unblock the client so that it renders to
+    the GPU (which is guaranteed to be executed after the blit so that its
+    Front/Back buffers are still correct) and requests another SwapBuffers.
+    The subsequent swapbuffers are appended to the vsync chain with the
+    blit/unblock then executed on the vblank following the original blit.
+    That is both the client and xserver render concurrently.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1e9319d5f56583be99f573f208cebb0ee3b5cc26
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 22 11:22:16 2012 +0100
+
+    sna: extend RandR to support super sized monitor configurations
+    
+    With the introduction of the third pipe on IvyBridge it is possible to
+    encounter situations where the combination of the three monitors exceed
+    the limits of the scanout engine and so prevent them being used at their
+    native resolutions. (It is conceivable to hit similar issues on earlier
+    generation, especially gen2/3.) One workaround, this patch, is to extend
+    the RandR shadow support to break the extended framebuffer into per-crtc
+    pixmaps.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e8b090902e788257610374deae659f01a91888f3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 22 22:01:37 2012 +0100
+
+    sna/gen3+: Remove stale assertions for cached vbo
+    
+    Following the previous commit, we reset the vbo when it becomes idle
+    rather than discard it. As such, the assertions to check that we are
+    discarding the vbo are now bogus.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 565297e6bd3457a150036af9c62fe0dc67b794ac
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 21 13:53:02 2012 +0100
+
+    sna/gen3+: Keep vbo cached
+    
+    Once we switch to using a vbo, keep it cached (resetting everytime it is
+    idle) until we expire our caches.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d806973e21cd46e605b3cd405323ae7a64c12798
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 21 12:57:13 2012 +0100
+
+    sna: Micro-optimise search_inactive_cache
+    
+    Discard the unneeded next parameter to drop a memory reference in a hot
+    path, and don't wait for a retirement if we are looking in a larger
+    bucket than suits.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d39fef0a7f3daf5c07686b44e4dea01c0f06c77a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 21 12:25:35 2012 +0100
+
+    sna: Tiles are only 128 bytes wide on gen2
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4f2dde1fa3b04b27bae8fc0bca9c824bd362d23b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 21 10:31:24 2012 +0100
+
+    sna/gen7: Eliminate the pipeline stall after a non-pipelined operation
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3ef05a8d0833203e265aff392f225a11a11c2d01
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 21 09:36:42 2012 +0100
+
+    sna/gen7: Do not emit a pipeline stall after a non-pipelined command
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4501e131e6b737cb8f2581c8b1f7ea9d29a8e912
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 21 16:38:32 2012 +0100
+
+    sna/gen7: prefer using RENDER copy
+    
+    Further testing and the balance of doubt swings in favour of using the
+    3D pipeline for copies.
+    
+    For small copies the BLT unit is faster,
+    2.14M/sec vs 1.71M/sec for comppixwin10
+    
+    And for large copies the RENDER pipeline is faster,
+    13000/sec vs 8000/sec for comppixwin500
+    
+    I think the implication is that we are not efficiently utilising the EU
+    for small primitives - i.e. something that we might be able to improve.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3da56c48b7820ec77d704c5a16670eb86a6f673f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jun 20 15:14:23 2012 +0100
+
+    sna/gen7: Prefer using BLT rather than redirect for copies
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b1f8386db6e9b3eea1bdbf8cde90f33792640ce8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jun 20 23:28:14 2012 +0100
+
+    sna/gen7: Emit a pipeline flush after every render operation
+    
+    For whatever reason, this produces a 30% improvement with the fish-demo
+    (500 -> 660 fps on i7-3730qm at 1024x768). However, it does cause about
+    a 5% regression in aa10text. We can appear to alleviate that by only
+    doing the flush when the composite op != PictOpSrc.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d02e6d81420a114c9622bbdaf90fc3ae5d4b15a7
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 21 16:10:02 2012 +0100
+
+    Encode the third pipe using the HIGH_CRTC shift for vblanks
+    
+    The original vblank interface only understood 2 pipes (primary and
+    secondary) and so selecting the third pipe (introduced with IvyBridge)
+    requires use of the HIGH_CRTC. Using the second pipe where we meant the
+    third pipe could result in some spurious timings when waiting on the
+    vblank.
+    
+    Reported-by: Adam Jackson <ajax@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f8b67be8d3b5d5cbe730ba5dba3edd2d30a99d9f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jun 20 12:39:19 2012 +0100
+
+    sna: Don't clear the needs_flush flag after emitting a flush on the busy bo
+    
+    We use that flag to check whether we need to check whether the bo is
+    still busy upon destruction, so only clear it if the bo is marked as
+    idle.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5419bbb483af595d7021e49debef7700c599217e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jun 20 11:21:52 2012 +0100
+
+    sna/gen7: Prefer BLT for copies
+    
+    It's faster for where the cost of the extra batches and ring switching
+    do not dominate...
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1c0bb8c4c93a43e2932429a9f6c23d91f1be2060
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jun 20 10:57:40 2012 +0100
+
+    sna/gen7: Keep using RENDER paths for large pixmaps
+    
+    As the 3D pipeline is quite versatile and we only need to force BLT if
+    we cannot extract the subregion.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b238f64e8a53883cfe7c568e37ef18bbee77996e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jun 20 10:46:59 2012 +0100
+
+    sna/gen[67]: Prefer to not force BLT paths for large pixmaps
+    
+    The sampler can in fact handler subregions of large pixmaps quite well,
+    and so we prefer to keep using the 3D pipeline so long as the operation
+    fits in. If not, then switch to the BLT in order to avoid the temporary
+    surface dance.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 38f06a351fdd35fa5c6136e9a25e034a812a94c2
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jun 19 22:22:12 2012 +0100
+
+    uxa: Fix second regression in glyph fallback from 64a4bc
+    
+    To complete my show of incompetence for the evening, not only do we have
+    to restore the original source when compositing the mask onto the
+    destination, we also need to restore the original dst (rather than
+    composite the mask onto the mask!).
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fda9faee755cb35906ca1179a568332ef2de35a5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jun 19 21:01:47 2012 +0100
+
+    uxa: Use the original src for fallback glyph compositing
+    
+    In 64a4bcb8cefff, I introduced a WHITE source for the purposes of
+    accumulating the glyph mask correctly. Unfortunately I neglected to
+    restore the original source picture for compositing the glyph mask on
+    the destination, resulting in a use-after-free and then corruption.
+    
+    Reported-by: Maarten Lankhorst <maarten.lankhorst@canonical.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8141e290b1ac7c4d1524bb389a84a8f375df4634
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jun 19 20:24:33 2012 +0100
+
+    sna: Explain why we ignore the busy status result during kgem_bo_flush()
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit eb1d07624e5aeb7b5db7ceb46975091e92185d63
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jun 19 16:00:13 2012 +0100
+
+    sna: Ensure extents is initialised if short-circuit use-cpu-bo
+    
+    As we may attempt to end up using the GPU bo is the CPU bo is busy, we
+    need to make sure we have initialised the damage extents first.
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9f216e159bd05ddd269eb8ddf3ca7a407c2901e2
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jun 19 15:57:31 2012 +0100
+
+    sna: Assert expected return values
+    
+    Keep the semantic analyser happy by consuming the expected return value
+    with an assert.
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2dc93b2a6c832ce8b972de90d09080e860dcd40f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jun 19 15:34:09 2012 +0100
+
+    sna: Check results from syscalls
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 06634604abf15fdd27dd007fcf81595da994146b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jun 19 15:28:43 2012 +0100
+
+    Initialise adaptors to 0 in case xf86XVListGenericAdaptors does not
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8bfea58dbc634cadc399d3132030c591e086880c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jun 19 15:26:18 2012 +0100
+
+    sna: Minor cleanups from sematic analyser in DBG
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0a43d425670b883b04565296c0510e7ba03ba6de
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jun 19 14:46:58 2012 +0100
+
+    uxa: Implement glyphs-to-dst to avoid fallbacks
+    
+    An earlier version was buggy and introduced corruption as it failed to
+    fallback gracefully with ComponentAlpha glpyhs. This is a much simpler
+    implementation that composites each glyph individually, leaving it to the
+    backend to optimise away state changes. It should still be many times
+    faster than incurring the fallback...
+    
+    Reported-by: Oleksandr Natalenko <pfactum@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=50508
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 64a4bcb8ceffff8e4ee448d8a467620596703509
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jun 19 13:42:12 2012 +0100
+
+    uxa: Use (white IN glyph) ADD mask to compose the glyph mask
+    
+    As pointed out by Soren Sandmann and Behdad Esfahbod, it is essential to
+    use white IN glyph when adding to the mask so that the channel expansion
+    is correctly performed when adding to an incompatible mask format.
+    
+    For example, loading alpha as the source results in the value 000a being
+    added to the rgba glyph mask (for mixed subpixel rendering with
+    grayscale glyphs), whereas the desired value is aaaa.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 99845dcb3ba862269b29aec782e2bcef31c0403e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jun 19 10:37:10 2012 +0100
+
+    Post Damage on the Screen Pixmap after a pageflip
+    
+    This issue was raised by Dave Airlie as he is trying to integrate
+    multiple GPUs into the xserver, and a particular setup has a slave
+    rendering device that copies the contents from the GPU over a
+    DisplayLink USB adaptor. As such the slave device is listening for
+    Damage on the Screen Pixmap and needs the update following pageflips.
+    Since we already are posting damage for all the SwapBuffers paths other
+    than pageflip, for consistency we should post damage along the pageflip
+    path as well.
+    
+    Reported-by: Dave Airlie <airlied@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4acf727941a37651f672db3774281a437940c540
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jun 19 10:20:54 2012 +0100
+
+    sna: Initialize the color value for fallback unaligned boxes
+    
+    Reported-by:Zdenek Kabelac <zkabelac@redhat.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=5047
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b0b2d3c9663c29e9844aef1608416ae40c194b55
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jun 19 00:41:35 2012 +0100
+
+    sna: Avoid copying unintialised data during source picture upload
+    
+    If we have never written to a pixmap, then there will be neither a GPU
+    or shadow pointer and we would attempt to copy a NULL pointer. In this
+    case as the user is expecting to copy unintialised data we are at
+    liberty to replace those undefined values with the clear color.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 38472fcc53c5dceb98b96458183e6729b8311a43
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jun 19 00:37:12 2012 +0100
+
+    sna: Double check that the source is busy before performing indirect reads
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8cdfb8c24c8b49c88451714d80293c66d63e8c01
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jun 19 00:36:41 2012 +0100
+
+    sna: Fix up the shadow pointer on the source when copying
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 17f3a83fdc8c0ef5c12fb4be34d86021c0c865e5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 18 23:48:16 2012 +0100
+
+    sna: Review sna_copy_boxes
+    
+    A couple of ordering issue and more assertions.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a9045699b9cd66d0b0d96bfc964458c96845f97f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 18 23:47:21 2012 +0100
+
+    sna: Reset region after transferring to cpu
+    
+    If we adjust the region for the pixmap offset, be sure that we reset it
+    before returning it back to the caller.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9f51311a7d95bf4bc23926b8e6bf8ee52afd180c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 18 23:45:50 2012 +0100
+
+    sna: Check if the busy is truly busy before commiting to an indirect upload
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 291b3c4367b455bfc5a772f8caaeee73f36d826a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 18 23:43:00 2012 +0100
+
+    sna: Align upload buffers to 128
+    
+    This seems to be a restriction (observed on 965gm at least) that we
+    have incoherent sampler cache if we write within 128 bytes of a busy
+    buffer. This is either due to a restriction on neighbouring cachelines
+    (like the earlier BLT limitations) or an effect of sampler prefetch.
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=50477
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 39e5c7491535999643c1761bb1602ad757ab486c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 18 21:58:27 2012 +0100
+
+    sna: Assert damage is valid after every addition
+    
+    Even more paranoia than just checking upon migration.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 92e1693e5fb3a1dd89fca5e5ecc660e2de78f9cd
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 18 21:26:58 2012 +0100
+
+    sna: Validate cpu/gpu damage never overlaps
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=50477
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d2312c8f958002e54ddcb834f37916f4b46ac291
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 18 21:29:29 2012 +0100
+
+    sna: Fixup tracking of vmap upload buffers
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 75e9eeca7e998b1ee3f8b0df780adae1b9e5b408
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 18 16:39:20 2012 +0100
+
+    sna: Remove overlapping CPU damage when operating inplace on the GPU
+    
+    Otherwise we gradually introduce garbage into the picture.
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=50477
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a936466dd41c4bb8b0956c4da5a5838f991b332a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 18 11:36:53 2012 +0100
+
+    sna: Prefer to attempt a Composite operation rather than use pixman composite
+    
+    As pixman composite performance is atrocious for anything other than
+    solids, prefer to upload the mask and attempt a composite operation on
+    the GPU unless we are forcing the fallback.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4b325d6e2b99ec3f63a7c5175f6f4746f6773550
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 18 11:24:55 2012 +0100
+
+    sna: Fix rendering of unaligned boxes through pixman
+    
+    Not only do we need to make sure the source is available to the CPU, we
+    need to actually check the right conditions for clipping the box.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit caef27492b5a70bd46a09cd5094b2c93e38e39ea
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jun 17 20:56:46 2012 +0100
+
+    sna: convert another instance of applying the clear to the CPU pixmap
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8695c4c77666cd07eab51efcbc7c4f11c85250fd
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jun 17 16:53:53 2012 +0100
+
+    sna: Fix the blt composite op with no-ops
+    
+    When returning early because the operation is a no-op, we still need to
+    fill in the function pointers to prevent a later NULL dereference.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7905ddae1dbc8805d0fadbd6d21c7a5df7e715fc
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jun 17 17:01:12 2012 +0100
+
+    sna: Further refine choice of placement when uploading source data.
+    
+    The goal is cheaply spot a simple copy operation that can be performed
+    on the CPU without having to load both parties onto the GPU.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5a675b61f27273f7ef344d4056dbba1f8cd97737
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jun 17 15:42:17 2012 +0100
+
+    sna: Correct typo forcing everything to be clear to 0!
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b55bf1abbe71281e3d9ebde1c4005d40902d5e7f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jun 17 14:14:44 2012 +0100
+
+    sna: Fix cut'n'paste errors in tiling debug
+    
+    Rename for different variables
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9756c60b4ad15281d025b9c27f19d19e8a630958
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jun 17 11:39:33 2012 +0100
+
+    sna/gen7: Enable non-rectilinear spans
+    
+    Seems we have enough GPU power to overcome the clumsy shaders. Just
+    imagine the possibilities when we have a true shader for spans...
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 41aff56a1f452e409c7a49512a1d2824b74f3838
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jun 17 10:50:31 2012 +0100
+
+    sna: Add tiling for spans
+    
+    Semmingly only advisable when already committed to using the GPU. This
+    first pass is still a little naive as it makes no attempt to avoid empty
+    tiles, nor aims to be efficient.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 222e6ff43ef683e82101fb360911fc01fbe00597
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jun 16 23:40:30 2012 +0100
+
+    sna: Read inplace for fallback copies
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 79d468925bb012806e097337e4e5930818c6ab46
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jun 16 17:54:21 2012 +0100
+
+    sna: Decrease latency for 1x1 GetImage by using an inplace mapping
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2c2a8d3780f1d8de3f13bee8e068fdaf608ff9e9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jun 16 23:19:49 2012 +0100
+
+    sna: Allow reads to be performed inplace
+    
+    If we can guess that we will only readback the data once, then we can
+    skip the copy into the shadow.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit bc6997f6f751d3ba352dfc20c6717ec12b8fac47
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jun 16 17:54:15 2012 +0100
+
+    sna: Cleanup damage processing after operating inplace
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 937ca8a5d8a0f70a0724db1519bb7b5fc0857425
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jun 16 17:53:58 2012 +0100
+
+    sna: Use memset for simple clears
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit de4572b0b52e2fcfcad04660ee2f81ee88d500a5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jun 16 13:40:26 2012 +0100
+
+    sna: Inspect CPU damaged state when deciding upon Composite placement
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b689cd924c500373e1e293dd9eb54a238e400381
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 15 16:25:51 2012 +0100
+
+    sna: Composite traps inplace if the CPU is already all-damaged
+    
+    One outcome is that inspecting the usage patterns afterwards indicated
+    that we were missing an opportunity to reduce unaligned boxes to an
+    inplace operation.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ae3c0963790cfb6f984ed4ad3ecbaae492775e1b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 15 16:25:51 2012 +0100
+
+    sna: Composite glyphs inplace if the CPU is already all-damaged
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit eaed58b2baf30eaea37be06cfc1d9d81059aba27
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jun 16 12:55:54 2012 +0100
+
+    sna: Tweak placement of operations
+    
+    Take in account busyness of the damaged GPU bo for considering placement
+    of the subsequent operations. In particular, note that is_cpu is only
+    used for when we feel like the following operation would be better on
+    the CPU and just want to confirm that doing so will not stall.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8eac098962891a5deb7c53d36c6dec57c7f2b972
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jun 17 09:51:12 2012 +0100
+
+    sna/gen3: Add another DBG for dropping vbo
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 515c8b19d638d4a811b159ef0dc7cf4059e30217
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 15 15:41:14 2012 +0100
+
+    sna: Prefer to operate inplace if already mapped of the GPU is wholly dirty
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d1713941e9db3e7a6d83466be1b253978fb4bf01
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 15 15:29:59 2012 +0100
+
+    sna: Tweaks for DBG missing glyphs through fallbacks
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2b23605efba009fb340ec10b37d54caae159b9b1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 15 15:28:31 2012 +0100
+
+    sna: Don't trim prepare for glyphs_via_mask
+    
+    If we pass the expected width/height without passing the per-glyph
+    offset into the preparation function, we make the erroneous mistake of
+    analysing the glyph cache only for the mask extents and so will miss
+    glyphs that we need to upload for the operation.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9f66b27114fcc457fa5cb2d5889e875384f89e75
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 15 13:47:33 2012 +0100
+
+    sna: Remove mark-as-cpu after gem_pread
+    
+    The kernel no longer moves the read bo into the CPU domain, so remove
+    the last vestiges of that tracking.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit bfd88d5429528b0162eafcc9496bfd1c708b60cd
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 15 11:21:29 2012 +0100
+
+    sna: Silence a few compiler warnings
+    
+    Nothing harmful, just noise.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b3659beec8c4126de5da4df5cb2cc077b7af6c0b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 15 11:08:18 2012 +0100
+
+    sna: Check for zero-sized damage regions after trimming Windows to their pixmaps
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 293a867ea55d3004f5be21b1d0ad765a89c28a5a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 14 23:02:10 2012 +0100
+
+    sna: Specialise the self-copy blitter to handle vertically overlapping copies
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3b76ab995bb70da5f76afead7c696cb7fd72b158
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 14 22:33:11 2012 +0100
+
+    sna: Add a little bit more DBG to migration IO paths
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 49543522e789a0a8213c164b37a18c0642e60ac4
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 14 20:25:21 2012 +0100
+
+    sna: Fix reversed assertion
+    
+    Darn the double negative! After adding damage we want to assert that
+    the region is not empty, not !not empty.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4e50467b4f50b522a07bedae7ff68b9c37362af8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 14 17:40:09 2012 +0100
+
+    uxa: Force the outputs to off for consistency with xf86DisableUnusedFunctions()
+    
+    Upon a VT switch, we set the desired modes and turn off the DPMS on any
+    unused output. Make this explicit so that we always maintain consistency
+    between the kernel and X's list of enabled CRTCs.
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=50772
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3a56a0b10eb3ab07efd28efdc79d0fd3a6fa20ff
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 14 19:26:42 2012 +0100
+
+    sna: Make the disable-unused after vt switch distinct from DPMS off
+    
+    So that we do not lose control over dpms on/off!
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b415ca05c2e1c4f09f85d8769d39e5369661ed3a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 14 17:06:19 2012 +0100
+
+    sna: Reset damage extents after reduction goes to zero
+    
+    If the reduction of the damage clears all of the boxes, we need to reset
+    the -infinite extents so that we continue to accumulate further damage.
+    
+    Reported-by: Zdenek Kabelac <zdenek.kabelac@gmail.com>
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=50744
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0df7c488640d3590d2a88dc353b72167b6644eaa
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 14 16:09:38 2012 +0100
+
+    sna: Supporting overlapping copies for fallback blits
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=50393
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d5b273b20b7d917d08af120815c28b1618d3342c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 14 15:35:24 2012 +0100
+
+    sna: Explicitly disable the CRTC so that xserver/kernel agree after VT switch
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=50772
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 221534abe2dc04fae8b8fc332104bca275d4863b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jun 13 22:48:43 2012 +0100
+
+    sna: Only reduce damage addition to a region operation if clean
+    
+    Some paths bypass operating upon the region as they do not have an
+    YX-banded set of boxes and so prefer to defer the costly construction of
+    the region till later. As a result, we have to be careful not to
+    overwrite any existing information if we do operate on the region after
+    setting the dirty boxes.
+    
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=50744
+    Reported-by: Zdenek Kabelac <zdenek.kabelac@gmail.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0db789e180b6b01fb8aff547879387058f52a0b9
+Author: Zdenek Kabelac <zkabelac@redhat.com>
+Date:   Wed Jun 13 14:26:37 2012 +0200
+
+    sna: Constification
+    
+    Adding preserving const modifiers to decrease amount of const warnings
+    
+    Signed-off-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 33998a7080aa7f50ba922c764c6a93fe951c5b64
+Author: Zdenek Kabelac <zkabelac@redhat.com>
+Date:   Wed Jun 13 14:26:36 2012 +0200
+
+    sna: Fix typo and compare y1 to y2
+    
+    It seems 'y1' was meant to be compared here
+    
+    Signed-off-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0ade32fbad4014efcc8aa8ed4cd0f8a39f9ab107
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jun 13 14:28:43 2012 +0100
+
+    sna: Fix operator preference around a | b & c | d
+    
+    Tell the compiler what we really mean is a | (b & (c | d))
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 20f3114ccd63052b4fd06ef1d87efaaabbbac7ac
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jun 13 14:27:10 2012 +0100
+
+    sna: Use long for simplicity when printing size_t values for debugging
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6f75b8da6a468188dd0c00015395424598b3f502
+Author: Zdenek Kabelac <zkabelac@redhat.com>
+Date:   Wed Jun 13 14:26:33 2012 +0200
+
+    sna: Valgrind updates
+    
+    Add some mising initialization for unknown ioctl
+    
+    Signed-off-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 70cf637ca47c9e67758e09c7e1d10eef51db1f98
+Author: Zdenek Kabelac <zkabelac@redhat.com>
+Date:   Wed Jun 13 14:26:32 2012 +0200
+
+    legacy/i810: Fix declaration to match definition
+    
+    Signed-off-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5fea2478cd5ab4156c182210d28c5e27e5f67403
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jun 13 14:10:01 2012 +0100
+
+    Lots of trivial semantic fixes
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e499f207c161d1b3cd75f065dc89021ff5f40b63
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jun 13 13:11:17 2012 +0100
+
+    sna: Fix memleak from sna_crtc_find_plane()
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 49da55da518348fc6b88e09d5132dd1b1d751304
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jun 13 11:20:41 2012 +0100
+
+    sna: Free the reversed glyph bits along with the font
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9f68c7fe6aa34ab17d82489fca5f63a3ce335444
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jun 13 11:15:42 2012 +0100
+
+    sna: Free clip rectangles after intersection with PolyRectangle extents
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ab3b7fe31b5a9d7924e959f21d29c4f7352ec8cb
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jun 13 10:35:14 2012 +0100
+
+    sna: Only reuse a write buffer if all external references have been dropped
+    
+    This avoids the unhappy situation of overwriting an upload buffer that
+    we intend to use for a fallback.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e8cb656dc4bab1489df9dfb4cb64704b2a9fa34b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jun 13 08:10:10 2012 +0100
+
+    sna: Free clip intersection with line extents after use
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 572745eb243a96819c8fa248f4ffdd703ed13b0f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jun 12 22:49:05 2012 +0100
+
+    sna/damage: Remove unused return value
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit aefc0417dde8b2137a787459a69d91c14902f22b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jun 12 22:47:41 2012 +0100
+
+    sna/damage: Simplify initialisation of damage extents
+    
+    Just use the already computed region->extents when adding the first box.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 78a96e812b912c5b25a02670f603f455f93e9d00
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jun 12 21:43:31 2012 +0100
+
+    sna: Refresh the damage self-tests
+    
+    They had bitrotted with the revamp and needed some massaging to update
+    to the new interfaces.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6138f7434a6fb014299a7e9a8392ef962c8cba30
+Author: Cyril Brulebois <kibi@debian.org>
+Date:   Tue Jun 12 21:19:14 2012 +0100
+
+    Fix up braindamage in previous commit.
+    
+    ickle: Fixing up my idiotic change, obviously too much birthday cake.
+
+commit 224d631a232d3536e0f1f2780bfbe1218ee7590f
+Author: Cyril Brulebois <kibi@debian.org>
+Date:   Tue Jun 12 21:14:53 2012 +0100
+
+    Avoid calling xf86nameCompare() with a NULL string
+    
+    Device sections without a Driver property would lead to a server
+    segfault because of a NULL pointer's being passed as the second
+    argument of xf86nameCompare().
+    
+    Debian bug #677206 <http://bugs.debian.org/677206>
+    
+    Signed-off-by: Cyril Brulebois <kibi@debian.org>
+
+commit 3b9b64c7c9b5b0bfaafb97c9a9fe5849bbb412da
+Author: Dave Airlie <airlied@gmail.com>
+Date:   Tue Jun 12 10:26:34 2012 +0100
+
+    uxa: do copy fb at startup.
+    
+    Copy the current framebuffer for smooth wayland->gdm handoff.
+    
+    This has been hanging around in Fedora for too long now, and we've
+    dropped the feature a few times, and yes I know the Simpsons did it^W^W^W
+    SNA does it.
+    
+    I've updated the code to have some of the better fixes from nouveau.
+    
+    I've no idea who wrote this code either, krh or ajax. [ickle: The
+    earliest version I've found had krh's fingerprints on it, though it may
+    still have been a joint effort.]
+    
+    Signed-off-by: Dave Airlie <airlied@redhat.com>
+    [ickle: improve error handling, only copy the fb during initial takeover]
+
+commit b6525702b9ffd21beb8ea6bb10a8ad5ce7f9de14
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jun 12 11:59:31 2012 +0100
+
+    sna: Hook up AdjustFrame()
+    
+    Looks to be unused by the core, just a solitary invocation in an obscure
+    extension it seems. However the implementation looks trivial so
+    incorporate it until it is finally removed, just in case.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7b281d1300127d65392aaadbbe2299fa9e1749a9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jun 12 10:37:04 2012 +0100
+
+    sna: Remove a pair of empty stub functions
+    
+    The export wrappers for the glyph cache constructor/destructor existed
+    in case there was a need to add more routines. Since that never
+    happened, remove the extra step of indirection.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 392e33a62d729c64c57699505220b4029e015470
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 11 09:51:41 2012 +0100
+
+    sna: Instrument memory/bo allocations for monitoring over time
+    
+    Hide it behind --enable-debug=memory to avoid incurring the cost for
+    everybody.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4e984b79cce038ba5026d8bdd93dec9b5a6ced8a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 11 09:02:03 2012 +0100
+
+    configure: Correct the help string for --with-default-accel
+    
+    Prior to finalizing the defaults I changed my mind and realised that the
+    default had to reflect the current behaviour of someone enabling SNA for
+    the first time, and not the previous behaviour of --enable-sna to
+    override UXA. This is so that distro's could offer an SNA enabled DDX
+    for the brave whilst not affecting their typical no-xorg.conf users.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7614a541886dd9eb5c9d441e2618785e9cc53a65
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jun 10 09:36:38 2012 +0100
+
+    configure: Harden --with-default-accel against simple mistakes
+    
+    If the user specifies no options, assume automatic selection. Then
+    double check we found a valid backend and so avoid later breaking the
+    build.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ea0209fbc12fca282bd8ef72223791bf163801ce
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 8 22:44:23 2012 +0100
+
+    sna: Remove option to disable vmap
+    
+    It works everywhere, so when it is finally enabled, let it be.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 18baa1428b1c4c0a49927d4c32db091db9e4e97b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 8 22:43:01 2012 +0100
+
+    Make the enum list of options consistent with the actual table.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit adc872a9654dc18d778323ca0721704878ad3851
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 8 06:44:20 2012 +0100
+
+    sna: Add DBG spew to flink()
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a62ad4e80722db187766c83a16fa84ec236cc5eb
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 7 23:37:59 2012 +0100
+
+    sna: Skip flushing the active queue if there is not a suitable bo pending
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 318982566bbc7145847bd03601087150eef7a8d8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 7 21:56:04 2012 +0100
+
+    sna/dri: Disable experimental code by default
+    
+    Since these require non-upstream patches to other components, we don't
+    want it enabled by default and randomly breaking builds.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ebf84b8e572b5cb1a509000d412dfa5be3d1aca3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 7 20:15:53 2012 +0100
+
+    sna/trapezoids: Micro-optimise cell allocation
+    
+    The pool is a fixed size so we can delete the generic code to handle
+    variable sizes.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0a25fc68c5cd82cad4b99b0f2357f430c8783c3f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 7 19:13:09 2012 +0100
+
+    sna: Actually create Y-tiled source pixmaps
+    
+    An inconsistency highlighted by 7c51cabaecac revealed that we had a
+    mismatch between the check in move_to_gpu() and how we created the
+    pixmap. This mismatch resulted in us creating and uploading tiled
+    pixmaps for single shot textures, and the increase aperture pressure was
+    causing a regression in firefox-fishbowl on pnv, for example.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c58d137d3eeb0e97bfd53e68404e04d9012b5697
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 7 11:18:27 2012 +0100
+
+    sna: Suppress DBG prints along potential SIGIO paths
+    
+    As ErrorF/fprintf is not re-entrant due to its mutex we can not use DBG
+    from code that could be called by a signal handler. X's SIGIO handler
+    attempts to move the cursor from within the handler (eek!) and so we
+    need to be careful not to take any locks, such in as the aforementioned
+    fprintf, along the cursor paths.
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=50744
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3f5b94f3d1625b06840c6441a0b175604ee3d2f9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jun 6 17:24:07 2012 +0100
+
+    sna: Check against integer overflows when computing cache size
+    
+    Even with a 1nm process, I doubt we will see 4+GiB cache sizes ;-)
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 902391bd798775e1a7a53503d4dd1756162f737f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jun 6 17:20:39 2012 +0100
+
+    uxa: Remove dead-code for SourcePictures
+    
+    All SourcePictures are now converted into Drawables, which had been
+    assumed by the driver backend. However, the code still existed to
+    attempt to pass procedural pictures onwards and so set pSrcPix to NULL
+    which was being flagged by the static analyser as a potential NULL
+    dereference.
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3d8a1f7176877975a31ad7a6548fa8309065f617
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jun 6 17:15:42 2012 +0100
+
+    sna/gen4+: Add missing "fall through" comments
+    
+    Reported-by: <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8ae4407c43e6a8d26784508f61b416138f908132
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jun 6 17:13:05 2012 +0100
+
+    sna: Silence static analyser complaining about potential NULL pointer
+    
+    Add an assert to prove that is not.
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 08010b23a3e2bc37d202251923fac814b18fa501
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jun 6 17:10:35 2012 +0100
+
+    uxa/dri: Silence static analyser for potential NULL intel_pixmap
+    
+    If the intel_pixmap was NULL we should have failed to create the DRI2
+    buffer, so we can safely assert here to keep the analyser quiet.
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 06b1b875ba13227ddaf7f28dbdcdaa3eb49f0857
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jun 6 17:05:13 2012 +0100
+
+    uxa/i915: check for failure to allocate temporary destination
+    
+    If the target drawable is too large for the render pipeline, we need to
+    create a temporary surface. This may fail, so abort if it does.
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c553dcae2dd714cac413ffc7c7779cd78c9a3e61
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jun 6 17:04:01 2012 +0100
+
+    sna: Silence a few unused function warnings
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 536033b4edb40db18210e5272eb8ce9703e5e364
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jun 6 16:02:47 2012 +0100
+
+    legacy/i810/dri: Check for malloc failure for BusIdString
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b2da80c1d1058dca5d3d85693918e53d9fa61dd3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jun 6 15:59:54 2012 +0100
+
+    sna: Add some missing 'fall through' comments
+    
+    Static analysers are dumb and presume readers are too.
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c433fb4521e2fb65a555489bd09ba6bb9448b72f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jun 6 15:17:30 2012 +0100
+
+    uxa/dri: Fix up typo from f2513cb0f
+    
+    s/true/FALSE/? Wrong.
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1675f441049d559d891fe378e437c12db21df9e7
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jun 6 12:55:13 2012 +0100
+
+    uxa/dri: Transfer reference of the new_back buffer to the flip_chain
+    
+    In order to prevent a leak of the bo when the chain is eventually
+    torn-down when the client exits.
+    
+    Reported-by: Andreas Lampersperger <lampersperger.andreas@heidenhain.de>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=50670
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 18726a4975ab2ddf85eaa6eb1602dcbe599217f7
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jun 6 10:58:49 2012 +0100
+
+    sna: Perform CopyArea directly onto a CPU bo if available
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 57d7d5de78bcf01d75d7a7de03fe50a2a9bd1b7e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jun 6 00:08:17 2012 +0100
+
+    sna: Use GPU for readback onto CPU bo
+    
+    Time to blt from GTT to LLC 16384 bytes:    125.000µs (snb)
+    Time to blt from GTT to LLC 16384 bytes:     71.000µs (ivb)
+    Time to blt from GTT to LLC 1048576 bytes: 1400.000µs (snb)
+    Time to blt from GTT to LLC 1048576 bytes:  938.000µs (ivb)
+    
+    Time to copy from GTT to LLC 16384 bytes:   118.000µs (snb)
+    Time to copy from GTT to LLC 16384 bytes:   134.000µs (ivb)
+    Time to copy from GTT to LLC 1048576 bytes:        6723.000µs (snb)
+    Time to copy from GTT to LLC 1048576 bytes:        7424.000µs (ivb)
+    
+    And conversely,
+    
+    Time to blt from LLC to GTT 16384 bytes:    10.000µs (snb)
+    Time to blt from LLC to GTT 16384 bytes:     8.000µs (ivb)
+    Time to blt from LLC to GTT 1048576 bytes: 217.000µs (snb)
+    Time to blt from LLC to GTT 1048576 bytes: 135.000µs (ivb)
+    
+    Time to copy from LLC to GTT 16384 bytes:    4.000µs (snb)
+    Time to copy from LLC to GTT 16384 bytes:    4.000µs (ivb)
+    Time to copy from LLC to GTT 1048576 bytes:        270.000µs (snb)
+    Time to copy from LLC to GTT 1048576 bytes:        179.500µs (ivb)
+    
+    It seems clear then that even with the extra synchronisation cost
+    copying from the GTT is much preferable with the GPU than using the
+    uncached reads by the CPU. Streaming write-combines from the CPU into
+    the GTT seem about as efficient as we can manage, so continue to use the
+    mapping unless busy.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f2513cb0fdb0d1214854fd4e4dcd477ba8583862
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jun 6 10:41:35 2012 +0100
+
+    uxa/dri: Do not use undeclared stdbool features
+    
+    The header isn't pulled in, so stop using the undefined values of
+    true/false.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1dafb4777f8378c87f34feae667582498220204c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jun 5 21:25:40 2012 +0100
+
+    sna/damage: Add some assertions to validate that each damage box is non-empty
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=50744
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c4eb5528a456b65c673f7c984d14a622ac67cdca
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jun 5 16:04:16 2012 +0100
+
+    uxa: Check for DPMS off before scheduling a WAIT_ON_EVENT
+    
+    Regression from commit 3f3bde4f0c72f6f31aae322bcdc20b95eade6631
+    Author: Chris Wilson <chris@chris-wilson.co.uk>
+    Date:   Thu May 24 11:58:46 2012 +0100
+    
+        uxa: Only consider an output valid if the kernel reports it attached
+    
+    When backporting from SNA, a key difference that UXA does not track DPMS
+    state in its enabled flag and that a DPMS off CRTC is still bound to the
+    fb. So we do need to rescan the outputs and check that we have a
+    connector enabled *and* the pipe is running prior to emitting a scanline
+    wait.
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=50668
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7c51cabaecac52348766c622e80ed14b9854e54d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jun 5 12:59:46 2012 +0100
+
+    sna: Try to create Y-tiled pixmaps for initial source bo
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a26c05cc8936cab28d83c6beeff906a910353338
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jun 5 12:48:33 2012 +0100
+
+    sna/gen2+: Tweak placement of operations for CPU-bound large pixmaps
+    
+    Try to avoid uncessary migration to the GPU of large pixmaps that are
+    wholly bound to the CPU.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a21bdbe3e312b40b936c5c68c84f5c1bc0f9fb88
+Author: Dave Airlie <airlied@redhat.com>
+Date:   Tue May 22 15:44:28 2012 +0100
+
+    sna: port to compat api
+    
+    This ports SNA to the new compat-api.
+    
+    Signed-off-by: Dave Airlie <airlied@redhat.com>
+
+commit 8f5001493e18b6b3b97ca5f0c923678a51975bd0
+Author: Dave Airlie <airlied@redhat.com>
+Date:   Tue May 22 15:35:01 2012 +0100
+
+    intel: port legacy and uxa to new API.
+    
+    This ports the legacy and uxa driver to the new server API.
+    
+    Signed-off-by: Dave Airlie <airlied@redhat.com>
+
+commit c9824827422f8ec4f46c9cba42d871c98dc54761
+Author: Dave Airlie <airlied@redhat.com>
+Date:   Tue Jun 5 10:38:21 2012 +0100
+
+    sna: drop using block/wakeup data.
+    
+    These went away in the new server API, and really if this
+    made any measurable difference, I'd be impressed.
+    
+    Signed-off-by: Dave Airlie <airlied@redhat.com>
+
+commit d9850a05003008d86d0b226bcd775aebdd43bccd
+Author: Dave Airlie <airlied@redhat.com>
+Date:   Tue Jun 5 10:04:48 2012 +0100
+
+    uxa: drop enable disable access hook
+    
+    This looks to be unused.
+    
+    Signed-off-by: Dave Airlie <airlied@redhat.com>
+
+commit 99df720216787c52d16a350dd25469e2dcea2c47
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jun 5 10:24:34 2012 +0100
+
+    sna: Add inline keyword in conjunction with attribute(always_inline)
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 47d7da5a986a9f133cd3dc8314ff243001586a36
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jun 5 10:18:40 2012 +0100
+
+    sna: Maintain the operation on the CPU if not completely replacing all-damaged
+    
+    We may as well continue the operation on the CPU if already bound to try to
+    reduce needless migrations (where the cost of the upload will outweigh
+    further use).
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 81f09347f2ab59cf0a3eaca7be83ded555655e93
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 4 16:45:05 2012 +0100
+
+    uxa/i965: Silence static analyser by asserting the bo exists for the video
+    
+    This is already checked at the beginning of PutImageTextured, so this
+    check upon the return value of intel_get_pixmap_bo() should only be
+    required to keep static analysers happy.
+    
+    Reported-by: Zdenek Kabelac <zdenek.kabelac@gmail.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1f43de322b400dcd64eb4545a978ad9b1c7de185
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 4 15:39:39 2012 +0100
+
+    sna: Exclude consideration of tiling flags from overwriting BLT commands
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ebb1c9d5f82e8822f7400ff11a887ab047a0d78e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 4 15:28:31 2012 +0100
+
+    sna: Make the bo-is-busy DBG more useful by saying which bo it is
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6dc5ddfe807b307ca10af971c4f84498b2fb82a2
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 4 13:49:35 2012 +0100
+
+    sna: Remove bogus check for color == 0
+    
+    This was written when the RGBA color value was being passed around and
+    not the pointer to the xRenderColor. As such, the NULL deref check
+    doesn't gain much and the check for rgba==0 irrelevant in this scenario.
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9b3937228c692598899fb39bfe448a9b457315db
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 4 13:47:58 2012 +0100
+
+    sna: Simplify selecting default tiling for framebuffers
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ff91fd4a2749f1ea8722189aaec938e51bce4222
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 4 12:41:05 2012 +0100
+
+    uxa: Check for failure from drmModeGetConnector()
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4712a4008aaff7b3c57a8dd0a5e639992c9b6d30
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 4 12:40:56 2012 +0100
+
+    shadow
+
+commit 63a55e9db97b647cbf7385403a0f30ee4d24dc3b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 4 12:36:11 2012 +0100
+
+    uxa/shadow: Free the buffer along the unexpected failure to attach to the pixmap
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c9bd4ed7d7d5c9ba6924e911652e03abc9267865
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 4 12:29:58 2012 +0100
+
+    legacy/i810: Silence a compiler warning for missing 'const'
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6f8b411b8a833cca6fce8888ce515db6413d57ca
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 4 12:21:27 2012 +0100
+
+    uxa: Preferred order for calloc is (count, size)
+    
+    And assert that the allocation succeeds for good measure. A great big
+    dollop of graceful failure is missing...
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 72a29aa74a1488269c2184300e573d060c49e232
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 4 12:21:27 2012 +0100
+
+    sna: Check that the buffer was allocated prior to caching it
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9bff89b1892cee90a80909255876240126b700b2
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 4 12:21:27 2012 +0100
+
+    legacy/i810: Be paranoid and guard against xf86GetPciInfoForEntity
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ed6004f7ad09329bd4097331aaff38edc83107b6
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 4 12:21:27 2012 +0100
+
+    uxa: Be paranoid and guard against xf86GetPciInfoForEntity
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit abb8d893742f4ba9567330da9706adda4e636e75
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 4 12:21:27 2012 +0100
+
+    sna: Be paranoid and guard against xf86GetPciInfoForEntity
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 782cd6eafa9917a5bdb181d66b7f4c05392950ba
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 4 12:20:17 2012 +0100
+
+    uxa: check for failure to allocate drmModeCrtc
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a99bf0125f8f166ff2d65449ecd376c99c3024b8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 4 12:15:51 2012 +0100
+
+    uxa/i965: Drop superfluous 'state' variable
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 15a00ba047fdb7d388a322f2e33894d20787af2f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 4 12:09:52 2012 +0100
+
+    sna/gen2: Remove double 'const'
+    
+    So constant, we const'ed it twice.
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 99129c369c16d9ff7588a0e59f9285cc339b7eb3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 4 12:08:11 2012 +0100
+
+    sna/gen4+: Use an explicit invalid value for alu
+    
+    Since the static analyser also doesn't like comparing a uint8_t against
+    ~0.
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fae9c054d47203b68a6c09647945d23074ea4df9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 4 12:04:30 2012 +0100
+
+    legacy/i810: Remove unused variable
+    
+    In order to reduce the volumes of output from static analysers.
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 880ec2c9a56d3de33c7fbbfa4c043082fbcf7a78
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 4 12:04:30 2012 +0100
+
+    legacy/i810: Reorder DRI teardown code to avoid potential NULL derefs
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7424ea7dd08e304baa4efa09e887b833737ac9f6
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 4 11:59:24 2012 +0100
+
+    uxa/dri: Free wait_info along DRI2WaitMSC error paths
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ebd6dea009479e612c67d78416b8680bb23dba94
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 4 11:56:11 2012 +0100
+
+    uxa/dri: Make sure is_glamor_pixmap is always initialised
+    
+    The code paths are too twisty to be sure otherwise.
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 33f0b4b96662d953052232b1c0477ced0c326a62
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 4 11:54:28 2012 +0100
+
+    legacy/i810: Free offscreen image info struct on failure
+    
+    Impossible with the current code, the server aborts on failure. However,
+    this looks to be the simple answer to keep static analysers quiet.
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d24340747389db971c04349d1ee517f195c2b28e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 4 11:53:26 2012 +0100
+
+    sna: Free clip boxes (if allocated) along error path
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1215abc5c30cc3e183bde59b1523c09b59c484e3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 4 11:49:15 2012 +0100
+
+    sna: Make the ignored return value explicit
+    
+    The return from __kgem_throttle_retire() is just a hint as to whether
+    any forward progress was made. In the case of the error path, though it
+    is a last ditch effort before aborting, so we do not really care whether
+    or not it succeeds, we must try again.
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e230b460515a043a1b7353d153e864754ca5e064
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 4 11:48:23 2012 +0100
+
+    ux/i965: create_sampler_state_bo() expects enums, so feed it the right types
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 072d7a8b42f04600c9d8054f3648642a1aaff57a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 4 11:40:01 2012 +0100
+
+    sna/debug: Assert the non-existence of the relocation handle at source
+    
+    This should help the static analyzer pinpoint the blame and make it
+    quieter.
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4a3c355e056339aed68b70470556633dea899b1b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 4 11:32:42 2012 +0100
+
+    sna: Silence a compiler warning for loss of 'const' qualifier
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 791029cc16bca36b8dec82297ff7e07a972c51ab
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jun 2 13:28:43 2012 +0100
+
+    sna/trapezoids: Implement trapezoidal opaque fills inplace
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1f78a934a423911e18d340f0585e31941f6e8663
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jun 2 13:27:52 2012 +0100
+
+    sna: Clear the counters prior to querying the property
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a1953f1d4abc6e158a5e3ca53d3207548842254c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jun 2 12:02:55 2012 +0100
+
+    sna: Prefer to use memset() for extremely large clears
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ce85cd1a36e31795a966ea8983c2d6f803a4eccd
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jun 2 11:46:06 2012 +0100
+
+    sna: Add some DBG to retreiving EDID
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e8eb273bd6153c232a9ffc558e3b7fd4beaab01b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jun 2 10:43:03 2012 +0100
+
+    sna/gen7: Add DBG for ring switching
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 722afa6bc910a2ccfbb0442872a878d1b6b78315
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jun 2 10:04:02 2012 +0100
+
+    sna: Remove some unused members from the KMS state tracking
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 26e7bb3f25f0c83d39ff505fa7e05bfcb976e39c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jun 2 09:16:51 2012 +0100
+
+    sna: Add a DBG message to indicate flushing for GPU idle
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 58fc03b8c36688e9fa7925aa82b83d36c9decb7e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jun 2 08:53:24 2012 +0100
+
+    sna: Prevent NULL deref with early termination and DBG enabled
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1be2afb81df887ed664ac31d0641da808cfb8888
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jun 2 08:04:02 2012 +0100
+
+    legacy/i810/video: Release memory after creating adaptors
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 261d086265fff6c9b28a67d2fcceed8f107d5cb0
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 1 23:22:31 2012 +0100
+
+    legacy/i810/dri: Propagate failure from allocating texture memory
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2ea12b56d42686f75deb33fc126d09acee7e2899
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 1 23:22:31 2012 +0100
+
+    legacy/i810: Fix memset(sizeof(*ptr)) rather than memset(sizeof(ptr))
+    
+    Clear the entire structure and not the first 4 bytes...
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d3e15d1460faad192781d74fdc2b5092e9c148ad
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jun 2 08:14:23 2012 +0100
+
+    uxa/i965: Make the unhandled allocation failures explicit
+    
+    Add assertions to the point of allocation and write failures.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 46fbb3d31bf73df4bd0259a146e9929f62a9c488
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 1 23:22:31 2012 +0100
+
+    uxa: NameForAtom may return NULL
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8451d5dd3c992bcfad9f71aa890b6b225884b978
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 1 23:22:31 2012 +0100
+
+    uxa: Use unsigned bitfields for single bits
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d66ca06865973833398560a04186e0067d9cb206
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 1 23:22:31 2012 +0100
+
+    uxa: Intialize is_glamor_pixmap
+    
+    It is not clear whether is_glamor_pixmap is always initialized prior to
+    use, so set it to a safe^W likely value.
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 25a17b2ca5e3945150151c4308761891c0e20bab
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 1 23:22:31 2012 +0100
+
+    uxa: Remove 'render_source_is_solid' dead code
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ba0eb230836fa5f94a2f50da5880fdd3b9dfd72e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 1 23:22:31 2012 +0100
+
+    uxa: Fix reallocation of XVAdaptors array
+    
+    Prevent the leak and remove some unsightly code in the process.
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit affb1f82c1401bac3f54654a342e3b16b8bd374b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jun 2 08:27:59 2012 +0100
+
+    sna/gradient: Reuse old gradient bo if allocation of new fails
+    
+    Prefer a stall to a crash.
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e51f984a4c15de42c5bee3aeacee553e2dd4eca0
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jun 2 08:23:35 2012 +0100
+
+    sna: Check gradient allocations during init
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2c5647a18e7856b604bce70270463fc128c2cfcd
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 1 23:22:31 2012 +0100
+
+    sna: NameForAtom may return NULL
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7867bff00caeff9e1fbe569ca3d37b94f704a4cd
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 1 23:22:31 2012 +0100
+
+    sna: Replace invalid signed value with unsigned ~0 for uint8_t
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ca72b372237287af0f4475801a9b64efca975832
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 1 23:22:31 2012 +0100
+
+    sna: Drop return value from 3D point transform
+    
+    And just fixup the computed coordinates in the face of an invalid
+    matrix.
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b83e2a79f2a082630e0d3147abec8d3599f3f4b4
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 1 17:17:49 2012 +0100
+
+    uxa: Static analysis warning fixes
+    
+    A smattering of bugs and confusing code.
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 67e8ac365c4b7dd9c4eb2abe46aecc8cc04d4278
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 1 17:20:51 2012 +0100
+
+    sna/gen3+: Guard against a kgem_bo_destroy(NULL)
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e91b27ae14a5366175a4fe9c87ee15a0a25b5a42
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 1 17:12:36 2012 +0100
+
+    sna: Fix potential deference of NULL cpu_bo inside assertion
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 048161e69612324d6c077ec487a2a64aaaa7c1f5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 1 17:09:21 2012 +0100
+
+    sna/trapezoids: Check for malloc failure
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2896aa7b46931d3b95567121ccb07844725ab45c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 1 17:08:01 2012 +0100
+
+    sna/io: Free the heap clip boxes on error paths
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1ef00ff720226c211444806d9fdf67ce2046685b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 1 17:05:55 2012 +0100
+
+    sna/dri: Fix typo, check for NULL after allocations to spot failure!
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit dc0fe44bebfdee63bcda4d185b85fe9e1cb16a71
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 1 16:54:41 2012 +0100
+
+    sna: Fix a smattering of static analysis warnings
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8eed569fb386a9af48a8beb28666d72c6678e48c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 1 13:02:50 2012 +0100
+
+    sna/trapezoids: Correct extents declaration for fallback
+    
+    Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 91419576eef562378cccf90968c4f0277139b03d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 1 12:09:19 2012 +0100
+
+    sna: Tiny DBG message tweak
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4bdecc5b07a184ba136129e75a7fef914ac3b8d2
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 1 11:06:04 2012 +0100
+
+    test: Add a very basic test to exercise BLT text drawing
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ea0f326d80f21f89c3cff3595a6e1afc42b52efd
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 1 09:04:23 2012 +0100
+
+    sna: Debug XDrawRectangle
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6a7efa991a705bdb5a3b9d5300d824a1ce8759af
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 1 08:47:20 2012 +0100
+
+    test: Exercise basic rectangle drawing code
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit bc4323558bebd53e474fbc5404e1c41ab16d02e6
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu May 31 21:19:26 2012 +0100
+
+    sna: Handle negative values when computing the stipple modulus
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit aca994e03e6e0e16f55841418b0061b175e91e5d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu May 31 21:17:24 2012 +0100
+
+    sna: Fill early break for clip process of spans
+    
+    When on the same Y-band as the span, as soon as the clip boxes are too
+    far to the right, we can stop searching for more intersections.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0fe150f898120ba9a00e1e6b9d66bec10d7e8a29
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu May 31 20:02:47 2012 +0100
+
+    sna: Fix computation of box for clipped stippled rectangles
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a65c3b7b45df46ba993af6755b2460aa80fde930
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu May 31 19:15:05 2012 +0100
+
+    sna: Add some more DBG for stippled blts
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b2cc64253217a90cf2ade9a8d6f1ed21b23fe875
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu May 31 19:45:56 2012 +0100
+
+    sna: And combine the two migrate to CPU clauses
+    
+    Just a small tidy up to remove a duplicated predicate.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit bd1dd4cf663ca230724dc6beb329b7eb270ea9d5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu May 31 17:57:56 2012 +0100
+
+    sna: If the CPU damage already contains the migration region, we are done
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a2d92ade3911e62f950c85b5650fb13da1279ced
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu May 31 17:49:01 2012 +0100
+
+    sna: Prevent readback of 1x1 if it lies inside CPU damage
+    
+    If the pixel exists only in the CPU damage, attempting to read it back
+    from the GPU only results in garbage.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a34a06c4ba36b21e386b1f6371a4bd3f03ff35a1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu May 31 20:14:38 2012 +0100
+
+    sna/glyphs: Clip the damage to the drawable for unclipped glyphs-to-dst
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit dcc7ba8ccf95db1c265bd5492f041f94ce368b7a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu May 31 17:48:40 2012 +0100
+
+    sna/composite: Add debugging modes to disable acceleration
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 984400b95a879c7c020de14545ac2e1d9e759e05
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu May 31 16:56:21 2012 +0100
+
+    sna/glyphs: Don't apply drawable offsets twice
+    
+    The offsets from image_from_pict() already include the drawable offset
+    so we need not apply them twice.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7bbd445c8cbeb7bcea2c56c4deb9bf6ccf6f2497
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu May 31 16:45:03 2012 +0100
+
+    sna/trapezoids: Apply the drawable offset for the CPU migration
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c5313620a2f66bc8daf211fc77a9c480a79ea271
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu May 31 15:06:16 2012 +0100
+
+    sna: Suppress flushes once we have cleared the kernel dirtiness
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0347c8abec9740d706d87dd2f719ac68f3d1c32e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu May 31 13:50:31 2012 +0100
+
+    sna/glyphs: Fix upconverting of glyphs via gpu
+    
+    When using the mask instead of the src for adding the glyphs we need to
+    pass the glyph coordinates through the mask coordinates rather than the
+    source.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 90ae4f853222ee33206134f4efdc4accfb2f2c38
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu May 31 14:17:40 2012 +0100
+
+    sna: Avoid mixing signed/unsigned int/int16 arithmetric
+    
+    Life becomes unpleasant with sign extension.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 660c89e9742bac5ce7cbd480e08b4667e37dee8c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu May 31 13:18:21 2012 +0100
+
+    sna: Use full 16-bit unsigned values for absolute differences
+    
+    Beware the overflow implicit in:
+      adx = x2 >= x1 ? x2 - x1 : x1 - x2;
+    when both x2 and x1 may be large signed 16-bit values
+    
+    Reported-by: Zdenek Kabelac <zdenek.kabelac@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=50532
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 035c2953751f58225bd6b1fcb4c1275ccb5526cb
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu May 31 09:29:40 2012 +0100
+
+    sna/glyphs: use add(WHITE, glyph, mask) for channel expansion
+    
+    If the glyph format does not match the mask format we can not simply add
+    the two together, but must first perform a channel expansion (or
+    contraction) by multiplying the glyph against a WHITE source.
+    
+    Normally the glyph and the mask are equivalent formats and so we hit the
+    fast path.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit cf5b3e2ebf4ee0330f5421b9377bb512a94ec284
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed May 30 14:44:59 2012 +0100
+
+    sna: Don't attempt to flush scanout if unattached
+    
+    This was lost in the midst of the OSTimer overhaul.
+    
+    Reported-by: Zdenek Kabelac <zdenek.kabelac@gmail.com>
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=50393
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3a64ba0895035f6567e9a15357396b06c0f2d6dd
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed May 30 13:51:07 2012 +0100
+
+    sna: Convert remaining drmCommands to drmIoctl
+    
+    This helps to silence valgrind
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 47e2db0ba8ae3fbcdf58cba26c58ec0932b4c90b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed May 30 10:37:22 2012 +0100
+
+    sna: Replace FREELIKE_BLOCK with MAKE_MEM_NOACCESS
+    
+    And similarly for MALLOCLIKE_BLOCK. The issue being that valgrind may
+    overwrite such blocks with alloc-fill and free-fill values, but when in
+    fact they are defined and still in use by the GPU. This can lead to the
+    GPU processing garbage, and GPU hangs.
+    
+    Reported-by: Zdenek Kabelac <zdenek.kabelac@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=50393
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 08a630dc5ef87e551865e558fe4fc45ea66457b4
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed May 30 08:50:44 2012 +0100
+
+    sna: Ensure we flush scanout even when otherwise idle.
+    
+    Reported-by: Zdenek Kabelac <zdenek.kabelac@gmail.com>
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=50477
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 10ca765ad346931087be146f3e6d1f4069c95f26
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed May 30 08:32:34 2012 +0100
+
+    Mark a few more options as being UXA specific
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 740368c4c6eb547adad247ff529d16e594d6459b
+Author: Nick Bowler <nbowler@draconx.ca>
+Date:   Mon May 28 18:28:28 2012 -0400
+
+    Include config.h in intel_options.c
+    
+    Commit 8a9a585341e2 ("Only create a single instance of the intel_options
+    array") moved the definition of intel_options into a separate .c file.
+    Several of the defined options are #ifdef'd based on the configuration,
+    but since config.h is never included, the macros being tested are never
+    defined.  Therefore, none of the configuration-specific options will
+    ever be available at runtime, even if they should be.
+    
+    Add an inclusion of config.h so that such configuration-specific options
+    work again.
+    
+    Signed-off-by: Nick Bowler <nbowler@draconx.ca>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e1b720c40cf511b4ed6d387891d715522d0d54b6
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed May 30 07:47:53 2012 +0100
+
+    sna/sprite: Restore another xf86drm.h
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e986b06162abf286b3f8f97b791fd66dcf8f9aec
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue May 29 22:21:05 2012 +0100
+
+    sna/overlay: Handle return from GETPARAM query correctly
+    
+    drmIoctl() returns 0 on success, not a positive value.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 68874e2d694cc68f5f051ba5fe4a79a71fdb2dbc
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue May 29 21:28:39 2012 +0100
+
+    sna: Fix chunking for large stipples
+    
+    Reported-and-tested-by: Matti Hamalainen <ccr@tnsp.org>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=49510
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 12af82581118470f59817f626d61df655950e243
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue May 29 21:45:32 2012 +0100
+
+    sna/overlay: Replace drmCommand with direct invocations of drmIoctl
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3a1b6e57fbbbb4c8e5ac9588537840f4ec176ae6
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue May 29 21:37:16 2012 +0100
+
+    sna/overlay: Restore one xf86drm.h include
+    
+    This was removed in haste, when it is required for drmIoctl and friends.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 264d1b1e1fb368f7845a8112bfa2ad2224acabd9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue May 29 13:03:56 2012 +0100
+
+    sna: Also check for a free exec slot for the upload buffers
+    
+    As we check before allocating the upload buffer, we can not be certain
+    that we will allocate an already attached bo or that we have a free exec
+    slot. So always check that we have an extra exec slot available - the
+    false positive rate is going to be negligible.
+    
+    Reported-by: Zdenek Kabelac <zdenek.kabelac@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=50457
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c7bcca9a3fb6c669d8b093e6399914693770b0b3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue May 29 12:49:12 2012 +0100
+
+    sna: Make finding DPMS property valgrind clean
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3c074797094dc7675bb6ae549630fdf061ab5258
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue May 29 12:45:20 2012 +0100
+
+    sna: Make GetEDID valgrind clean.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 560e50c0a5afa0824086557581ca6aa5696b44a2
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue May 29 12:36:31 2012 +0100
+
+    sna: Make GetEncoder() valgrind clean
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b4b6fa795201379694a03d537064dbca446cfdfd
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue May 29 11:32:28 2012 +0100
+
+    sna: Trim the set of includes
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9d1a9e666763a3e1270c8f000b1b37a6b926441f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon May 28 20:06:35 2012 +0100
+
+    sna: Bump experimental ioctl number for vmap
+    
+    Gazumped!
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 55e6f5f220401318529e81f7c96fe0af3b893a0c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon May 28 16:21:09 2012 +0100
+
+    sna: Use the local function for turning the cursor off prior to release
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 77dd429222922aa1ba7f283553e11e60e4d5c496
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon May 28 14:40:23 2012 +0100
+
+    sna/dri: Make WAIT_VBLANK valgrind clean
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8ebe84818ab70e662a9bb3f232b4664ff40ac375
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon May 28 14:27:46 2012 +0100
+
+    sna: Make sna_copy_fbcon() valgrind clean
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f37dae734ebac5c0ed2d6f50fc92bc107f4e4a33
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon May 28 14:20:54 2012 +0100
+
+    sna: Just use the CRTC id from the array
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b1f24a0eae4bb0081ff7469a2aee63a1f32140f7
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon May 28 14:16:03 2012 +0100
+
+    sna: Make sna_crtc_apply() valgrind clean
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0ebfcdbb80245f98c0c7ef9f090a2be6900fb457
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon May 28 14:10:04 2012 +0100
+
+    sna: Make AddFB valgrind clean
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 32ca3c7b65516b0bd48b0d0979b086ee1580167a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon May 28 14:02:11 2012 +0100
+
+    sna: Make sna_crtc_is_bound() valgrind clean
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7973f6751c9bf565dee4c89aa3e1badbcc45018f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon May 28 14:00:55 2012 +0100
+
+    sna: Add a little bit more verbosity to cursor routines for valgrind
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 19c463e52df919fc75de7e420fd3565f0e9a0576
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon May 28 12:54:35 2012 +0100
+
+    sna: Only wait if there is a suitable active buffer
+    
+    There is not point repeating the search after retiring if we know that
+    there is no outstanding suitable active buffer.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5b99c7cd340f782d3057d4257865c5feb96b71f0
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon May 28 10:55:49 2012 +0100
+
+    uxa/dri: Enable vblank scheduling even with pageflipping disabled
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 810357ad65d551ec5d35dbf228f1b62fe235801f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon May 28 10:12:38 2012 +0100
+
+    uxa/dri: Fix ordering of setting vs using swap members
+    
+    Trivial readibility fix, as the actual ordering is serialised through
+    there being only a single thread.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2b56a188ef2c48f82572eca2201a3a0ecf6b4f45
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon May 28 10:01:09 2012 +0100
+
+    Mark another couple of options as being UXA only.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b025f1a604dbbbd456a23f330ceed5f97ecdffcf
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon May 28 09:48:49 2012 +0100
+
+    sna/dri: Tweak vblank_mode=n swapbuffers to account for throttle delay
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 45148a714f1461fff898aeb393ad225f081b9bd5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon May 28 09:39:51 2012 +0100
+
+    sna/dri: Enable handling for Option "SwapBuffersWait"
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c709f2447dfc6dc36c50ff741d5d9bbdc7c03b58
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon May 28 08:17:21 2012 +0100
+
+    sna/dri: Requeue vblank throttling until the vsync'ed copy completes
+    
+    If the GPU is busy, then we may not actually schedule our copy for
+    several vblanks, resulting in us falsely reporting that the work
+    completed too early and allowing the client to continue scheduling more
+    work and racing ahead of the queued copies.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7e73fa02ed361a9c0c08f61d00421671bf10ce9f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon May 28 08:16:43 2012 +0100
+
+    sna: Add some debugging to show count of outstanding requests during retire
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 62b557065edc0555f2bf83b0eed9169329a2f2ba
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun May 27 16:52:51 2012 +0100
+
+    sna: Use magic upload buffers for video textures
+    
+    So that we may benefit from the caching of buffers and the automatic
+    selection  of the preferred upload method.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 35291d2db813f75fedcdca9920a40592acd3cca3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun May 27 16:54:29 2012 +0100
+
+    sna: Search the inactive bo cache for a mappable upload buffer
+    
+    See if we have a bo that we can cheaply map to an inplace upload, rather
+    than rely on an existing GTT map.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 36d53ff52b055b2b5fc03aff7b2cab83037d9f42
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun May 27 16:46:42 2012 +0100
+
+    sna: Validate all CRTCs after updating one
+    
+    Updating one CRTC may cause the kernel to turn off another, so be
+    paranoid and run the check in a loop after applying the CRTC set.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7fdd8bd6d2ba7bf113d4109e6bb6f750f909565f
+Author: Johannes Obermayr <johannesobermayr@gmx.de>
+Date:   Sat May 26 23:52:28 2012 +0200
+
+    glamor: Fix misspelled xf86GetOptValString and OPTION_ACCEL_METHOD introduced by commit e456291.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8ea4ba081de0206351394481f54dcbe6922a085b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat May 26 21:48:16 2012 +0100
+
+    sna: Fix typo for debug compilation
+    
+    s/ctrc/crtc/
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 317bf05196086eb5dedb6436c07f253f01c9bf63
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri May 25 14:34:16 2012 +0100
+
+    sna: Perform the selftest after probing
+    
+    We do no want to slow down the detection phase by performing our
+    self-tests, so only running those before initialising the driver.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a5fe863e3f1a6750edaffb518c4e768e9bc11521
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri May 25 14:28:56 2012 +0100
+
+    sna: Check the bus type before declaring probe success
+    
+    This should never fail, but still better to fail during detection rather
+    than pretend it works.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4094826aee76ef24dad13bc5a8a723bfe4a69162
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri May 25 08:55:13 2012 +0100
+
+    sna: Trust the crtc-is-bound determination after modeset and hotplug
+    
+    As these should be the only time that they change and we now have the
+    checks in place, we can drop the workaround of doing the check just
+    before emitting the wait.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8a9a585341e2dd43c649204fcf6d92a867671ba3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri May 25 08:50:33 2012 +0100
+
+    Only create a single instance of the intel_options array
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e45629135065d0cc73c285f8df35ab4e1d07c6dc
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu May 24 18:22:45 2012 +0100
+
+    Allow runtime switching of AccelMethod between uxa/sna and even glamor
+    
+    Section "Device"
+      Option "AccelMethod" "uxa/glamor/sna"
+    EndSection
+    
+    The appropriate backend must also be enabled at compile time for the
+    runtime option to be available (i.e. --enable-uxa (default) --enable-sna
+    --enable-glamor)
+    
+    Demanded-by: Adam Jackson <ajax@redhat.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=50290
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit df6ab02c3690eea8393ecc8c113e2f2891856cc6
+Author: Eugeni Dodonov <eugeni.dodonov@intel.com>
+Date:   Mon Oct 31 14:43:22 2011 -0200
+
+    Unify options handling between UXA and SNA
+    
+    Unifies available options for both UXA and SNA drivers, and
+    moves them into a common header file, intel_opts.h.
+    
+    Signed-off-by: Eugeni Dodonov <eugeni.dodonov@intel.com>
+
+commit ae2be7e25bda46551381c19a673b321b4382e1f9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu May 24 16:33:27 2012 +0100
+
+    sna/trapezoids: Correct rounding for downsampling onto sample grid
+    
+    Reported-by: S. Christian Collins <s_chriscollins@hotmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=49446
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0ab226e27e7920bdb9f7eb62c5174cd097ac7f7f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu May 24 12:51:46 2012 +0100
+
+    sna: Query CRTC states following a hotplug event
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3f3bde4f0c72f6f31aae322bcdc20b95eade6631
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu May 24 11:58:46 2012 +0100
+
+    uxa: Only consider an output valid if the kernel reports it attached
+    
+    Reported-by: Kyle Hill <kyle.hill@tacomafia.net>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=50078
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 11db66fedf96f158cbbac8011a8ba0b29a20ba3a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu May 24 11:07:19 2012 +0100
+
+    sna: Add some more DBG tracepoints around modesetting
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fb9da4cb9e12ca733c31879b8b37906f361a8c35
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed May 23 13:53:37 2012 +0100
+
+    sna: Only mark an unattached output as inactive
+    
+    So that a latter attempt to set the DesiredMode may succeed and we do
+    not modify the configuration without notifying clients.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5ae032e22b127c7c95753197e0914a8028a3b22e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed May 23 13:27:07 2012 +0100
+
+    sna: Suppress modesetting errors on return from VT switch
+    
+    If we presume that userspace will set the correct mode shortly
+    afterwards, we can ignore the failure of the automatic restore.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 34882a979d9817d33bd6a8ae73a9f7083556578c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed May 23 10:27:44 2012 +0100
+
+    sna: Keep checking retirement for flushing list
+    
+    Even after all outstanding requests have been completed we may still
+    have buffers on the flushing list that need to become idle.
+    Once such consequence would be to prevent the vblank flush from going
+    idle, causing spurious wakeups every vrefresh when otherwise idle.
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=50078
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 54fde5bf05d43f26e7f1893584af736a138d245f
+Author: Dave Airlie <airlied@redhat.com>
+Date:   Wed May 16 15:34:08 2012 +0100
+
+    intel: convert sna/uxa to using new glyph picture accessors.
+    
+    The compat-api.h takes care of old/new servers.
+    
+    Signed-off-by: Dave Airlie <airlied@redhat.com>
+
+commit 43a34186d13d29c671431832469ca5301751b3cf
+Author: Dave Airlie <airlied@redhat.com>
+Date:   Wed May 16 15:26:55 2012 +0100
+
+    intel: convert to new screen conversion APIs
+    
+    The compat header takes care of the old server vs new server.
+    
+    this commit was autogenerated from util/modular/x-driver-screen-scrn-conv.sh
+    
+    Signed-off-by: Dave Airlie <airlied@redhat.com>
+
+commit 9aabc04d76fa976abb4a74f4e9676c7556e88df3
+Author: Dave Airlie <airlied@redhat.com>
+Date:   Wed May 16 15:14:32 2012 +0100
+
+    intel: add compat header file for conversion fns
+    
+    Signed-off-by: Dave Airlie <airlied@redhat.com>
+
+commit c9ce6ae8a6fc7b1a91aef1e59640c39024d0426d
+Author: Dave Airlie <airlied@redhat.com>
+Date:   Wed May 23 08:33:20 2012 +0100
+
+    legacy/i810: rename pScreen->screen
+    
+    For consistency before moving to new APIs.
+    
+    This just changes the files where the API changes will touch.
+    
+    Signed-off-by: Dave Airlie <airlied@redhat.com>
+
+commit 70ee0f84f5b9c6c13a0338f8b2757e587c849c14
+Author: Dave Airlie <airlied@redhat.com>
+Date:   Wed May 23 08:31:52 2012 +0100
+
+    legacy/i810: rename pScrn->scrn
+    
+    This is need to make the compat api stuff easier to implement.
+    
+    Signed-off-by: Dave Airlie <airlied@redhat.com>
+
+commit 3410db008c6c20dc6590a89c05b40a0c6de6744a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue May 22 15:54:52 2012 +0100
+
+    sna/dri: Avoid confusion of attempting to exchange pixmaps for DPMS-off flips
+    
+    Not only do we confuse ourselves, but we end up confusing the damage
+    tracking on the root window whenever we update the Screen Pixmap. So for
+    the time being, don't.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 28c4fb0b70e098972af972d30a660d167a8973ad
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue May 22 09:49:53 2012 +0100
+
+    sna: Swallow disconnection event upon mode restoration
+    
+    So that we can VT switch back to X even though the output configuration
+    has now changed.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b17c44c8d234cb2c651e88c7892bcd5b33139c1c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue May 22 09:43:51 2012 +0100
+
+    sna: Remove incorrect assertion for mode restoration
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 49b7742999ee11b0c36754ea10bc5609ebe8c609
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue May 22 09:40:25 2012 +0100
+
+    sna: Force config restoration after VT switch
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 952e3dcba3a651d22d44dbb039ad97e111d9bc63
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon May 21 19:48:52 2012 +0100
+
+    sna: Only override active on DPMSModeOff
+    
+    Along the enable path we then only want to change the value if we
+    actually call sna_crtc_apply.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit afdaf184594bfe3633305969eb1166c28e1006bf
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon May 21 14:32:39 2012 +0100
+
+    sna: Add a log message for the change of CRTC mode
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9fb18462ec1428a486f998585e7b4caf4dd08f53
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon May 21 14:12:23 2012 +0100
+
+    sna: Confirm that the modeset takes
+    
+    If we attempt to change to a mode with a disabled connector the kernel
+    will silently switch off that connector (and crtc) and report that the
+    modeswitch is successful.
+    
+    Reported-by: Kyle Hill <kyle.hill@tacomafia.net>
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=50078
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit cd3b48854403ee63723ef570c1a7f9f8447e7105
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat May 19 12:56:45 2012 +0100
+
+    sna/gen7: Trim a dead assignment
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit cf79cd3e27b7077f67f202b16ed39eb1cc70ac65
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat May 19 12:44:11 2012 +0100
+
+    sna: Emit a new batch if we need to clip after PolyText without space
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f91dcc44dcc15850f82666b1bcdd27182400e7dc
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri May 18 20:09:41 2012 +0100
+
+    sna: Give the proxy a unique name
+    
+    So that if we cache the current destination bo (for example, gen3) then
+    a new proxy (or even just a new batchbuffer) will indeed cause the
+    destination buffer to be updated.
+    
+    Reported-and-tested-by: Clemens Eisserer <linuxhippy@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=48636
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ee073d613bba38f90951405d5ecddfcf3ac5e043
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri May 18 15:19:00 2012 +0100
+
+    sna/traps: Fix processing of full-steps
+    
+    A missing factor of Y-height caused the computation of coverage for the
+    spans to be completely wrong. This affects the vertical segments of
+    rounded rectangles, for instance.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8ba800c63906fb29d34f40b9437092a665bffb14
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu May 17 22:46:18 2012 +0100
+
+    sna: Don't consider uploading inplace if the dst bo is unmappable
+    
+    Handle (and take advantage of) the fallback at the high level rather
+    than masquerading an inplace write.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit dad24721a13ce3a357e8ddae3c2dea61045f6fc2
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu May 17 21:44:22 2012 +0100
+
+    Revert "sna: Always try to operate inplace if we an LLC gpu bo"
+    
+    This reverts commit 10b4a9bb5f46ab9d9c8b165084ce4174b54a8d39 as it
+    causes a regression for pixel data uploads to active buffers.
+
+commit 681c6e72412fff96b203a09be6ac8d393f3489a5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu May 17 19:43:02 2012 +0100
+
+    sna: Track flushing status of live bo
+    
+    Currently we only move a bo with an outstanding kernel flush onto the
+    flushing list if it is no longer in use. This leaves us potentially
+    stalling on a flush if we try then to write to the object believing it
+    to be retired and idle.
+    
+    Reported-by: Jiri Slaby <jirislaby@gmail.com>
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=47597
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d99502a33d5bdbad010b7a036c1aee989fe29947
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu May 17 17:56:43 2012 +0100
+
+    sna/glyphs: Pass the extents to the backend for preparing to composite glyphs
+    
+    This information should not be required, but it might come in handy, so
+    pass it along.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fb21c2df1a10d66f115a5978b0db508058fdc412
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu May 17 16:30:31 2012 +0100
+
+    sna/io: Assert that we do not replace a bo->flush object
+    
+    These should be pinned by the higher layers and so we should never be
+    attempting to replace them. If we do replace a bo->flush, then we will
+    end up miscounting outstanding flush bo.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 596c0a68709a93bb376647c1b566e9df4f23b35d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue May 15 18:53:39 2012 +0100
+
+    sna: Assign GCops after checking for fallback to pass sanity checks
+    
+    We assert that prior to installing the fallback GCops the current ops
+    are the default set. This is broken if we point GCops to our GPU ops,
+    but then fallback. So check for the fallback first.
+    
+    Reported-by: Jiri Slaby <jirislaby@gmail.com>
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=47597
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3c9759ef2ad755bbe720d4aa031ec67dbc3b7734
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon May 14 14:12:06 2012 +0100
+
+    sna/gen3: Fix pre-multiplication of opacity masks
+    
+    The return type for the multipliation was only 8-bits wide dating back
+    to the time when the function just computed a single channel and didn't
+    try to blend the output back into the argb pixel value. Inlining the
+    shift into the function means that we need the output to be 32-bits wide
+    instead.
+    
+    Reported-by: Jiri Slaby <jirislaby@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=49887
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 053bd5bf2425aed44e1c2bb981d98ee5171211a0
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon May 14 12:08:09 2012 +0100
+
+    sna: Use the correct storage for box_from_seg
+    
+    Fixes regression from 3aa98289e3a2 with clipped segments. As we clipped
+    the empty box rather than the segment, we never drew any outlines.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b654b8794db7b00666ce5c59535a9302932c483b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon May 14 11:36:15 2012 +0100
+
+    sna/trapezoids: Fix picture creation for fallback trapezoids
+    
+    Being a little lax in not updating the format after upconversion to
+    PICT_a8, meant we were trying to composite with a depth 1, 8 bpp a8
+    image and thoroughly confusing everybody when creating the upload
+    trapezoid mask.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 80567f61afe77a003e663b17c1fc6b6c3ed04042
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon May 14 10:40:38 2012 +0100
+
+    sna/trapezoids: Do not reduce SRC to a clear pixmap to unbounded
+    
+    As we instruct the migration code to drop the clear when copying from
+    the GPU to the CPU, we then need to emit the zeros during the span
+    writing.
+    
+    Fixes some occassional corruption behind complex clip masks.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 067e9375809ea6cfa0c0b5e2159b359535c3b362
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon May 14 10:00:00 2012 +0100
+
+    sna: Trim unused partial buffer uploads
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit effb0b9ec579624e38f0007cd7096e7da04048ca
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun May 13 19:29:44 2012 +0100
+
+    sna: Tweak usage of kgem_bo_can_map vs kgem_bo_mapped
+    
+    More often than not we only want to consider whether we can map the bo
+    and decide whether doing so is the better option. Whether the bo is
+    already mapped is not such an issue any more with the throttling.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 37aa1e1291127ff4d27407fac936af64d0e353a8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun May 13 16:59:30 2012 +0100
+
+    sna: Simplify partial buffer tracking
+    
+    As we only want to track partial buffers with asynchronous reuse,
+    exclude all overs from the active buffers list. Secondly, keep the list
+    in most-recently-used order rather than by size.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7048a71fb6ff5e7c37e21a794f7b42d9a1da3473
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun May 13 15:42:28 2012 +0100
+
+    sna: Flush batch if GPU is idle upon wakeup
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 12e340c4b8efa70f3305f489af30461b7c0e5edd
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun May 13 11:01:35 2012 +0100
+
+    sna: Optimise kgem_clear_dirty() by keeping dirty buffers at the front
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b0dfd8223adee87e28b391a019effa7bb3630533
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun May 13 08:33:23 2012 +0100
+
+    sna: Flush the batch before blocking if the GPU is idle
+    
+    If we have work pending for the GPU and we believe it is idle, just
+    submit the batch in order to improve GPU/CPU concurrency and reduce
+    latency.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6924fc525d6bc82901cfed769c176b44c0bce024
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri May 11 14:04:09 2012 +0100
+
+    sna: Fix off-by-one in computation of width for inplace trapezoids
+    
+    This lead to the dropping of the last pixel for small area trapezoids,
+    such as the right hand outline of buttons under ClearLooks.
+    
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=48320
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a58a543e84ed15c41f4fa7644be3ba7865d31b92
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu May 10 12:59:55 2012 +0100
+
+    sna: handle vmap creation failures gracefully
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9af651fdf93f6ccdbcb147cb16989f84c2d0ebdc
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu May 10 10:57:56 2012 +0100
+
+    sna: Include some DBG for segment drawing
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3aa98289e3a2f59633ac5f1a5f64db4ee55609d9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu May 10 10:31:03 2012 +0100
+
+    sna: Correct adjustment of LineCap for rectilinear segments
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ad69316ab1054c5e4b56c19b8eec87b9f86939e5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu May 10 10:03:49 2012 +0100
+
+    sna: Include a small amount of timer-slack to avoid very short sleeps
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 29d1d409b259ba0c85947ef5eef903ea527aa118
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu May 10 09:54:53 2012 +0100
+
+    sna: Avoid doubling the final step of poly lines
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a83d90ee61be44a2a36b56ad24bbc6544320448f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed May 9 20:34:52 2012 +0100
+
+    sna: Avoid randomly changing domains of active bo
+    
+    After attaching the bo to the scanout, mark it as retired in order to
+    update its domains so that the assertion during retirement later is
+    correct.
+    
+    Reported-by: Clemens Eisserer <linuxhippy@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=49526
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d5200510b8f2a0ccb2e0c45dfebc659f8360780c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed May 9 17:58:58 2012 +0100
+
+    sna: Respect the error terms when reversing the PolyLine DDA
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a3d37fb29f8dffb0e370ad95783994aaa7eccfaf
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue May 8 15:47:14 2012 +0100
+
+    sna: Force remapping for IO transfer
+    
+    Should fix regression from fcccc5528 (sna: Improve handling of inplace
+    IO for large transfers) whereby it was aborting the transfer it we need
+    to remap the buffer for the upload.
+    
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=49546
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2a9a93e4484e0c616724610f4c8019fcbaa7ad53
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue May 8 15:12:51 2012 +0100
+
+    sna: Only avoid ring switching for indirect uploads
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 613902b60e0f2ca2a916e68306a1a37bc236d00d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue May 8 14:17:46 2012 +0100
+
+    sna: Fix off-by-one in checking available execbuffer slots
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 663e387b35c314c4c2bee8137d6b70d27fa9f729
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue May 8 11:45:34 2012 +0100
+
+    sna: Only submit a batch to the scanout if it is not already busy
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit cd7a56b7313233190a4c4a735d4a141e99c9b688
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue May 8 08:53:41 2012 +0100
+
+    sna: Throttle independently of scanout updates
+    
+    As we are now throttling to relieve GTT pressure, it is a benefit to
+    consistently throttle before blocking.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2372176f73b7c945f56b7673eab5eccb86366416
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon May 7 12:57:35 2012 +0100
+
+    sna: Throttle execution when searching for inactive buffers
+    
+    If we have some active buffers that we may reuse and old outstanding
+    requests, throttling before retiring should prevent the CPU from running
+    away from the GPU and hogging the entire GTT and RAM.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4df228749729dd540b639368400fa20118cdf412
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon May 7 10:42:30 2012 +0100
+
+    sna: Rate-limit and shrink bo usage if we hit system resource limits
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ca4d2296e6e42e837627756790b262cae0fd3b6c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon May 7 10:23:19 2012 +0100
+
+    sna: Expand batch buffers
+    
+    As batch buffers are compacted to fit into the smallest bo, the only
+    cost is the larger static array allocation (and presumably cache
+    misses).
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9281b80644ce76ad9e0f3f8f812cbae97c10814a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon May 7 23:25:22 2012 +0100
+
+    sna/gen[345]: Clear used vertices when discarding unmappable vbo
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a6ee376e93517659391905e6c9018b3bb735135d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon May 7 10:24:21 2012 +0100
+
+    sna: Use the correct invocation of kgem_bo_destroy() for sanity-checks
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c89c7e9a04314e40cee5514a182a8364c4f99374
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon May 7 11:54:50 2012 +0100
+
+    sna: Update select timeout when installing a timer in the block handler
+    
+    The block handler is run after the timers are queried for their
+    expiration and so if we install a timer in the block hander, we must
+    set the timeout ourselves.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4ba366ead3a133136554579fe9a604da1fc1da68
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon May 7 08:55:35 2012 +0100
+
+    sna: Manually execute the timer as TimerForce does not run an inactive timer
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2c801c45dbad58d18f2673e17723825dda0c4e55
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun May 6 17:23:11 2012 +0100
+
+    sna: Replace timerfd with OsTimer
+    
+    As timerfd is linux-specific, and OsTimer an OS-agnostic abraction,
+    replace the former with the later. Arguably this has slightly better
+    performance characteristics in select-bound loops.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 74d2707de4a0f94d2143f1e9c60762e4167b1ea6
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun May 6 21:51:27 2012 +0100
+
+    sna: Remove short-circuiting for large font fallbacks
+    
+    Unlike the fallback for an unhandled depth, we need to ensure that the
+    pixmaps are mapped to the CPU before calling the fb routines.
+    
+    Reported-by: Toralf Förster <toralf.foerster@gmx.de>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=49558
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c5b6741d3729c6867702ab64a6c59cb8052c0ef3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun May 6 12:40:54 2012 +0100
+
+    sna/gen2+: Fix typo for computing redirected extents for render copy
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 771090f25db702d25ebbd3f2b44429cf0acfe8fd
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri May 4 20:56:37 2012 +0100
+
+    sna: Add a pair of asserts to track down a NULL pointer dereference
+    
+    Looks like the assumption for the location of the data is invalid,
+    allocation failure, perhaps?
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=47597
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d376a960df7a081a5d449f77b81ae13223b98929
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri May 4 10:09:46 2012 +0100
+
+    sna/dri: Only track a single pending flip across all pipes
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 450592f989efd0d3bc9ef2de245fce0a180e91a2
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri May 4 09:50:19 2012 +0100
+
+    sna: Cache the framebuffer id
+    
+    Also fixup a weakness of only tracking scanout with a single bit, as we
+    used to clear it forcibly after every flip.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 29d035279b2fe98d5ba9cf01125faea34d36fb76
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri May 4 09:11:31 2012 +0100
+
+    sna/dri: pageflip unref debugging
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 079b491ced2c9c3c73d938ef6025d040016ad3a7
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu May 3 23:52:17 2012 +0100
+
+    sna: Ensure drawables are clipped against the pixmap before migration
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1a5f8599b150064339d62a97c58026e62b49ff27
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu May 3 23:21:48 2012 +0100
+
+    sna: Compile fix for fresh assertion
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 61cac5c265279d45677262216a0ba56f548cd898
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu May 3 22:33:59 2012 +0100
+
+    sna: Maintain a reference to the chain of proxies
+    
+    Rather than attempt to flatten the chain to the last link, we may need
+    to hold a reference to the intermediate links in case of batch buffer
+    submission.
+    
+    Fixes http://tnsp.org/~ccr/intel-gfx/test.html
+    
+    Reported-by: Matti Hamalainen <ccr@tnsp.org>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=49436
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit dea5d429f7a52dfc945b17a57ef79744cc796b0e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu May 3 17:35:24 2012 +0100
+
+    sna: Remove extraneous SCANOUT flags
+    
+    These are now fixed by obeying a minimum alignment restriction.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 19fd24a4db994bb5c5ce4a73f06d9394a758ea91
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu May 3 17:35:10 2012 +0100
+
+    sna: Fix offset for combining damage
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1376c81dbf3b789e04e6804df1b1fd32bcb2bd1d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu May 3 17:34:28 2012 +0100
+
+    sna: Debug option to force particular upload/download paths
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f0d464d6b18855616fc43d9a25aa6853f86c8e2b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu May 3 16:17:35 2012 +0100
+
+    sna/dri: Balance flush counting
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d47e98dd64c0b9fe2979db42622c5ee8168e8b35
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu May 3 14:54:17 2012 +0100
+
+    sna: Minor glyph fallback fixes
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a1f08b8850616952fb0babe2275eb36b13a380ec
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu May 3 14:53:29 2012 +0100
+
+    sna: Don't discard GPU buffer if we only want to read back for the operation
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fcccc5528b8696fb4f9b3f9f528673b95d98a907
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu May 3 11:27:44 2012 +0100
+
+    sna: Improve handling of inplace IO for large transfers
+    
+    If the transfer is large enough to obliterate the caches, then it is
+    preferrable to do it inplace rather than upload a proxy texture and
+    queue a blit. This helps prevent an inconsistency where one layer
+    believes the operation should be done inplace only for the IO layer to
+    perform an indirect upload.
+    
+    Testing show no significant impact upon the cairo-traces, but it does
+    prevent x11perf -shmput from exploding.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 53568e8e49559094ce5b24b8709669f1f76fe2bf
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Apr 30 09:24:06 2012 +0100
+
+    sna/gen7: Fix debug printing of primitives
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 01c26a44fdce761781908be11102e7a6a3db523c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed May 2 21:09:27 2012 +0100
+
+    sna: Avoid reducing damage for synchronisation
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f4c34e9ab32f31669896b8f626195827a85af337
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed May 2 19:09:10 2012 +0100
+
+    sna: Bring back the minimum alignment for G33
+    
+    The underlying cause is still not fixed. It should be possible to use
+    the much laxer alignment for single-stream linear. Still no idea how I
+    fail to convince the GPU to drop the depth buffer.
+    
+    Reported-by: Matti Hamalainen <ccr@tnsp.org>
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=49391
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 10b4a9bb5f46ab9d9c8b165084ce4174b54a8d39
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed May 2 12:45:09 2012 +0100
+
+    sna: Always try to operate inplace if we an LLC gpu bo
+
+commit dd80fb00bf7acf37dc3b9125431a12b67d7e92d3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed May 2 11:31:42 2012 +0100
+
+    sna: Fallback for glyphs too large for XY_TEXT_IMMEDIATE
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7e09babb3e9e23882db30ee7d0c22c503962faa9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue May 1 12:37:45 2012 +0100
+
+    sna: Only attempt to reuse exported scanout buffers
+    
+    Yet more mesa w/a.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b4b32e7a0172a74372f800e9c74d639a23c5ff34
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue May 1 11:15:00 2012 +0100
+
+    sna: Fast-path unclipped glyphs
+    
+    Avoid the redundant computation of the glyph intersection with the
+    drawable bounding box.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ffdf9aca12adcfa1ec7ab7a1706873105a5f0d4a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Apr 29 21:59:52 2012 +0100
+
+    legacy/i810: hwmc additionally depends upon building DRI
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 444da84c47266bcbbdf5121507901de8eb36f11b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Apr 29 21:49:04 2012 +0100
+
+    configure: Version bump for 2.19.0 release
+
+commit a206a1eee1fb799d567d68db564d663cfc66f6cc
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Apr 28 01:54:43 2012 +0100
+
+    sna: Tune relocation array size
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4f1908c651ef9e2af33d8831466a605234978c46
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Apr 27 23:19:56 2012 +0100
+
+    sna: PolyPoint only uses the gc->fgPixel
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8453034c7dd893f1d4c32ee87724f3a13137595d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Apr 27 22:08:51 2012 +0100
+
+    sna/gen6: Allow ring switching at the start of a batch
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 93ad7793894787600c5074917c753fa7c6816134
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Apr 27 22:03:55 2012 +0100
+
+    sna: Tweak semaphores-enabled heuristic
+    
+    The kernel module now defaults to -1, confusing the test.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 986dbdda3bf8dcf208e55543d8a3393c4b53f10b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Apr 27 19:21:44 2012 +0100
+
+    sna: Tweak placement choice for high-overhead operations
+    
+    Some operations cost more to setup than to transfer data back and forth!
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit daac9a1d036d80ccce83438b49115a236a16bfb6
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Apr 27 16:50:28 2012 +0100
+
+    sna: Micro-optimise common case of checking a single fenced bo
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5967d76ca09a257ec9db66ea664158e1dfd083ba
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Apr 25 17:15:37 2012 +0100
+
+    sna: Fixup broken assertion
+    
+    It is valid for the cpu_bo to be NULL, as we may be choosing to free the
+    large shadow pixel buffer instead.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 860d3859b586939cd52e45b944cb6abd2a2ca71b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Apr 25 16:04:33 2012 +0100
+
+    sna/gen7: Add CS stall before changing WM binding table
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c219283460c0f2dfdb823e0cb139d05075c6afce
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Apr 25 15:04:01 2012 +0100
+
+    sna/gen7: Apply more recent improvements from SNB perf tuning
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a3371613c9bf577a69cdf811ca1bebaea46bbe95
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Apr 25 11:09:35 2012 +0100
+
+    sna: Do not automagically convert GTT mappings on untiled scanout to CPU
+    
+    The likelihood of an untiled mapping of the scanout is slim, except for
+    gen3 with large desktops, and there it should never be in the CPU
+    domain...
+    
+    The issue is that we may perform an operation "inplace", yet incoherent
+    with the display engine, and never flush the CPU cache, resulting in
+    render corruption. In theory at least!
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1abd92cd012ee46d44ed4873a5e750d56ae6668f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Apr 25 11:16:30 2012 +0100
+
+    sna: Clear the domain tracking after attaching the bo to scanout
+    
+    This is basically to make sure we don't continue treating it as CPU
+    coherent.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8c58c840b1ba579a5601804fc710c58e1e00213f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Apr 23 11:09:37 2012 +0100
+
+    sna/dri: Always clear the scanout when destroying dri2 buffers
+    
+    As we may end up holding onto and releasing the Screen pixmap last, we
+    may also be responsible for flushing the last reference to the scanout.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit caf9144271a10f90ea580c246b2df3f69a10b7a0
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Apr 20 17:15:37 2012 +0100
+
+    sna: Remove the assertions that the cached upload buffers are active
+    
+    These were added to track down some corruption, but the assertions
+    themselves are incorrect, just very rare. The upload buffer may
+    genuinely be cached if we abort the render operation after uploading the
+    source data, leaving the proxy not coupled to any request.
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=48400
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit aff3614efd5c12e658fa5723934e5bd50a83a316
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Apr 20 13:21:40 2012 +0100
+
+    sna: Always clear the mmapped domains when reusing  partial upload buffers
+    
+    As we need to make sure that we do invalidate the caches appropriately
+    on reuse. Mildly paranoid, but strictly required by the spec.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit cb6a3dc2edf3cd612f833bc9a4656166735ee856
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Apr 19 10:34:23 2012 +0100
+
+    sna: Discard proxy upload buffer if we choose to render to it
+    
+    Even if we try to avoid treating an upload buffer as a real GPU target,
+    we may still choose to migrate the buffer to the GPU in order to keep
+    other buffers on the GPU. In that case, we do want to create a real GPU
+    bo.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4cf74d409ca63c6a479c1ee2187908c04f3b830b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Apr 19 09:09:32 2012 +0100
+
+    sna: Don't consider upload proxies as being on the GPU for render targets
+    
+    The upload proxy is a fake buffer that we do not want to render to as
+    then the damage tracking become extremely confused and the buffer it
+    self is not optimised for persistent rendering. We assert that we do not
+    use it as a render target, and this patch adds the check so that we
+    avoid treating the proxy as a valid target when choosing the render
+    path.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fd81408b978c9b57c046ee43d2d32e1370e83a7d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Apr 18 11:39:43 2012 +0100
+
+    sna: Increase the render target alignment to 4 pixels on gen4+ as well
+    
+    Repoerted-and-tested-by: Toralf Förster <toralf.foerster@gmx.de
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=48865
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 11599e52b842b5db76798879b0fbb57762fe6002
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Apr 17 20:08:14 2012 +0100
+
+    sna/dri: Decouple the frame event info after attaching along error paths
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b817200371bfe16f44b879a793cf4a75ad17bc5c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Apr 17 17:54:58 2012 +0100
+
+    Don't issue a scanline wait while VT switched
+    
+    Be paranoid and check that we own the VT before emitting a scanline
+    wait. If we attempt to wait on a fb/pipe that we do not own, we may
+    issue an illegal command and cause a lockup.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit af4a6e8cb52ace594934446e6d8a7aaa1945a9b0
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Apr 16 20:57:03 2012 +0100
+
+    sna: Don't assert exported buffers are not busy
+    
+    As we do not fully control these buffers, we cannot truly say when they
+    are idle, we can only trust that the split between us and the compositor
+    doesn't lead to much corruption.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a16616209bb2dcb7aaa859b38e154f0a10faa82b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Apr 14 19:03:25 2012 +0100
+
+    uxa: Fix leak of glyph mask for unhandled glyph composition
+    
+    ==1401== 7,344 bytes in 34 blocks are possibly lost in loss record 570 of 587
+    ==1401==    at 0x4027034: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
+    ==1401==    by 0x8BE5150: drm_intel_gem_bo_alloc_internal (intel_bufmgr_gem.c:689)
+    ==1401==    by 0x899FC04: intel_uxa_create_pixmap (intel_uxa.c:1077)
+    ==1401==    by 0x89C2C41: uxa_glyphs (uxa-glyphs.c:254)
+    ==1401==    by 0x21F05E: damageGlyphs (damage.c:647)
+    ==1401==    by 0x218E06: ProcRenderCompositeGlyphs (render.c:1434)
+    ==1401==    by 0x15AA40: Dispatch (dispatch.c:439)
+    ==1401==    by 0x1499E9: main (main.c:287)
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ae145c21e9fd3a12164f8b4720d059f9c158249e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Apr 14 18:42:23 2012 +0100
+
+    sna: Avoid leaking the plane resources when determining sprite planes
+    
+    Fixes the tiny, one-off leak:
+    
+    ==1407== 8 bytes in 1 blocks are definitely lost in loss record 48 of 527
+    ==1407==    at 0x402894D: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
+    ==1407==    by 0x8580BE8: drmMalloc (xf86drm.c:147)
+    ==1407==    by 0x8583D54: drmAllocCpy (xf86drmMode.c:73)
+    ==1407==    by 0x8585265: drmModeGetPlaneResources (xf86drmMode.c:955)
+    ==1407==    by 0x8A1BCE9: sna_video_sprite_setup (sna_video_sprite.c:367)
+    ==1407==    by 0x8A1A0A3: sna_video_init (sna_video.c:523)
+    ==1407==    by 0x89FD4E0: sna_screen_init (sna_driver.c:935)
+    ==1407==    by 0x15AD80: AddScreen (dispatch.c:3909)
+    ==1407==    by 0x19A2DB: InitOutput (xf86Init.c:817)
+    ==1407==    by 0x14981C: main (main.c:204)
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 69a7737abeded6ee923643bd8a80a5a84e6a979c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Apr 14 12:06:51 2012 +0100
+
+    sna: Align texture subsurfaces to 2x2 texture samples
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1d2a46e0902d82b43a5e12af36521a6a7fd6ba39
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Apr 14 12:04:23 2012 +0100
+
+    sna: Align redirect subsurfaces to 2x2 or 4x4 render spans
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1ce2b65d622797000e0a4db7dc851d5b1da04f85
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Apr 14 11:59:31 2012 +0100
+
+    sna: Align render target sizes on gen2/3 to 4x4 render spans
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 89f2b09b1e5be9842747998ea4fe32a6f1ede4cc
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Apr 13 16:37:43 2012 +0100
+
+    sna: Avoid using TILING_Y for large objects on gen2/3
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=48636
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit eaadbce122059066353743f1653aa16e9d9b747f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Apr 13 15:12:36 2012 +0100
+
+    sna: Relax bogus assertion
+    
+    The bo may be considered unmappable due to being bound to outside the
+    mappable region, which we are attempting to rectify through mapping into
+    the GTT domain.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b478420740d05fa87ddbd92042b1f7f2d002f73e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Apr 13 15:07:13 2012 +0100
+
+    sna: Limit the buffer reuse for mappable uploads to only those with mmaps
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 90e2740e7e459c56205fa65bab1ae3dbfd5d3945
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Apr 13 13:51:57 2012 +0100
+
+    sna: Remove the conflicting assertion during GTT map
+    
+    Reported-by: Clemens Eisserer <linuxhippy@gmail.com>
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=48636
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9e6d55a8d63f10ca6a2b10e44d00c84b07724485
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Apr 13 09:56:39 2012 +0100
+
+    sna: Don't use miSpan code for wide-spans by default, too expensive
+    
+    Only use the fall-forward miSpans code when it prevents a readback.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9becfbbf89f2b170e50f705cabfc7bbf1dcf9846
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Apr 13 09:38:57 2012 +0100
+
+    sna: Draw dashed PolyLines twice, once for the fgPixel, once for the bgPixel
+    
+    As the fast paths only setup state upfront, we were missing the state
+    changes required between dash-on/off. Take advantage of that each pixel
+    is only drawn once to batch the state changes and run the
+    miZeroDashLines twice.
+    
+    A future task would be to use a custom line drawing routine...
+    
+    Fixes regression from ec1267df746512c2e262ef0bd9e9527bc5efe6f4.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e269ed5d4e1b9d758aeb9a85ed0fa631f0aff0b1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Apr 12 22:46:22 2012 +0100
+
+    sna: Restore CPU domain for vmapped buffers when reusing
+    
+    For a vmapped upload buffer, we need to notify the kernel (and thereby
+    the GPU) to invalidate the sampler and flush its caches when we reuse an
+    idle buffer.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d29b8650c40c673e6ddddaf52db9247e9836cba8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Apr 12 22:23:12 2012 +0100
+
+    sna: Revert use of mmap64()
+    
+    As this just causes mayhem on a 64-bit platform. Doomed if you, doomed
+    if you don't. :(
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a78b1d71a39ae29d5f85bd82c09202ebec3e6539
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Apr 12 15:37:25 2012 +0100
+
+    sna: Declare AC_SYS_LARGEFILE for mmap64
+    
+    In order to use the full 32-bits of mmap address space on small
+    platforms we need to use mmap64().
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 09deba927daa96be6230b1c3e1b425622512d8a2
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Apr 10 20:59:36 2012 +0100
+
+    sna: Check ioctl return from set-domain
+    
+    Let's not assume it succeeds and so avoid altering our bookkeeping along
+    failure paths.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0b12f1d8e4d0a4fafac9553f144535efc4ebe0be
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Apr 10 15:23:54 2012 +0100
+
+    sna: Fix shadowed variable
+    
+    sna_accel.c: In function 'sna_pixmap_move_area_to_gpu':
+    sna_accel.c:1751:12: warning: declaration of 'flags' shadows a parameter
+    [-Wshadow]
+    sna_accel.c:1731:72: warning: shadowed declaration is here [-Wshadow]
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 755a7107aed268d87c5cc0feb1ba388b0cb7fc59
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Apr 10 15:19:19 2012 +0100
+
+    sna: Fix typo and use the right pointer for kgem_bo_destroy
+    
+    Useless warnings in xorg headers ftl.
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=48400
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c8502e350cb18f6f5d821d237ffcee453f347eba
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Apr 10 14:43:28 2012 +0100
+
+    sna: Add missing alloc failure check for creating tile source
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9cc6f7ccc55cc11f47b3b7d626c9f5a7c1327d57
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Apr 10 12:06:56 2012 +0100
+
+    sna: Release the freed bo cache upon expire
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 102d11906a672140bac099e7bd1b35345d13a2fc
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Apr 9 22:54:51 2012 +0100
+
+    sna: Check for an inactive partial buffer to reuse after retiring requests
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e2fb2421d8f5c07925d1699673aa4b1dd6c6b22c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Apr 9 22:54:15 2012 +0100
+
+    sna: Release partial buffers during cache expiration
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 333fdcad8677675a4758223c1a980c90d970ee42
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Apr 9 22:53:31 2012 +0100
+
+    sna: Repeat expire whilst there remaining outstanding requests
+    
+    Do not allow the cache expiration to finish if we are still running
+    requests.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 778232e3d2fb5340a3092014801dc00a56c56d42
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Apr 10 11:14:50 2012 +0100
+
+    sna: Only move the bo into the read domain for readback
+    
+    And mark it as currently in no domain afterwards, so that if we reuse
+    it, it will be appropriately moved later.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit dd093eafb9b94b8e4cd8853d74078c3aa7e72f57
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Apr 9 14:09:42 2012 +0100
+
+    sna: Add assertions around proxy list handling
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=48400
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7f0bede3e7e3f92a637d1c886304b16afc0e34f2
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Apr 9 10:48:08 2012 +0100
+
+    sna/traps: Use a temporary variable for the write pointer
+    
+    To avoid accumulating the write offset for wide spans, we need to reset
+    the destination pointer between spans.
+    
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=48332
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2e4da00e3e03b873f5cad0cc5b1f6cc791852ca5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Apr 9 10:42:18 2012 +0100
+
+    sna/traps: Assert that the inplace row is contained before writing
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=48332
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0464e93a088a9e8bc29ad8b36b6e12c3dda32ec6
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Apr 8 17:16:03 2012 +0100
+
+    sna: Add some assertions for misuse of proxies
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=48400
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 479cb6ba71038fe44f66fb31fad90d0d454fea7a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Apr 8 14:25:49 2012 +0100
+
+    sna: Compress adjoining spans during FillSpans
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c5c01c13badeb7c2ead0c848b746d8d474277a77
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Apr 8 13:51:13 2012 +0100
+
+    sna: Remove the duplicated check for use-bo? in PolySegments
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f5deea4f60433ee2b0c2d02fba682fff8b7829e8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Apr 8 13:39:47 2012 +0100
+
+    sna: Correct partial-write flag for PolySegments fallback
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c3d7f4c1cf7d052163b7c4e74bb202c618f0eb76
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Apr 8 13:18:56 2012 +0100
+
+    sna/gen3: Reset accumulated constants for each composite
+    
+    In particular the glyph routines require the composite setup to
+    reinitialise state between glyph runs. This affects anything trying to
+    use glyphs without a mask with a gradient source, for example.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 701473d20485a0557b4fb36efcbfbb8656e2f619
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Apr 8 10:09:42 2012 +0100
+
+    sna: Release cached upload buffers when reusing a write buffer for readback
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=48400
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1ecf17b2507f95e1fefea15833fa9f57ec256a2e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Apr 7 10:01:01 2012 +0100
+
+    sna/gradient: Compute the absolute delta between color stops
+    
+    Otherwise we do not detect gradients that start from white!
+    
+    Reported-by: Clemens Eisserer <linuxhippy@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=48407
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4356fae72db3a33935b575edf95c84fbb48072a7
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Apr 6 21:10:50 2012 +0100
+
+    sna/video: Only wait upon the scanout pixmap
+    
+    Caught by the addition of the assertion.
+    
+    Reported-by: Jiri Slaby <jirislaby@gmail.com>
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=47597
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b790ba2ec9ead51227d85fc8630bc7505eb7d7b3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Apr 6 15:38:02 2012 +0100
+
+    sna: Correct the damage offset for redirected rendering
+    
+    Reported-by: Clemens Eisserer <linuxhippy@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=48385
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0b81bafb802bb86454739ed46cf45571bccef735
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Apr 6 15:14:45 2012 +0100
+
+    sna/glyphs: Prefer a temporary upload mask for large glyph masks
+    
+    If the required temporary mask is larger than the 3D pipeline can
+    handle, just render to a CPU buffer rather than redirect every glyph
+    composition.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 42a84613e34522af885b4b50d6c68ef77e81ffc3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Apr 6 14:27:15 2012 +0100
+
+    sna: Relase the upload cache when overwriting with PutImage
+    
+    Reported-by: Clemens Eisserer <linuxhippy@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=48359
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 999aa210ff87919945c673bdd34bae76ac097681
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Apr 6 09:24:36 2012 +0100
+
+    sna: Use a sentinel value to prevent accessing beyond the end of the y_buckets
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1ae6328c57eb496072f0d0e27440f5d0901633b0
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Apr 6 09:12:08 2012 +0100
+
+    sna: Remove redundant check from tor_inplace()
+    
+    We only execute full-steps for vertical edges so we do not need the
+    second check.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 51b9202d27db3d98c6d82ba224bd8eb218533dd9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Apr 4 11:13:27 2012 +0100
+
+    sna: Only engage the GPU detiler for multiple rows
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 98ad4c3cd8647ba3ec90fb45157773c8e85e886c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Apr 3 19:47:15 2012 +0100
+
+    sna/gen3: Don't force use of the render pipeline just for vmap
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0915d414f55a1bff4171981feb87bae212f29f23
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Apr 3 19:04:29 2012 +0100
+
+    sna/gen3: Fix pre-multiplication of mask value
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 04851e4210d2d71542359c14d4b68d0851b36326
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Apr 3 12:34:24 2012 +0100
+
+    sna/gen3: Convert the clear-color from picture->format to a8r8g8b8
+    
+    The shaders treat colours as an argb value, however the clear color is
+    stored in the pixmap's native format (a8, r5g6b5, x8r8g8b8 etc). So
+    before using the value of the clear color as a solid we need to convert
+    it into the a8r8g8b8 format.
+    
+    Reported-by: Clemens Eisserer <linuxhippy@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=48204
+    Reported-by: Paul Neumann <paul104x@yahoo.de>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=47308
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 87a672dafd9d6f47f31b77b406b7f0fb2b4030ac
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Apr 3 09:24:06 2012 +0100
+
+    sna: Apply CoordMode when computing point extents
+    
+    Reported-by: Patrick Truebe <eko-priv@gmx.net>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=48220
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0a0ee491ea18dc59748ff4419ae73bd1a369ae79
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Apr 3 09:23:49 2012 +0100
+
+    sna: Debugging flil spans and their clipping
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ec1267df746512c2e262ef0bd9e9527bc5efe6f4
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Apr 2 16:16:24 2012 +0100
+
+    sna: Use the solid spans fast paths for dashed zero-width lines as well
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2d1f3cb198f2fe9602356a334a076abf3c68a9c7
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Apr 2 13:51:37 2012 +0100
+
+    sna/gen4: Remove the accidental debugging hack from the last commit
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5c4dc9c5db7b2a5b936bdbc15536c5cf0f7f5f23
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Apr 2 13:40:22 2012 +0100
+
+    sna/gen3+: Fix sampling of borders around gradients
+    
+    Incurs a slight loss of precision for the internal gradient, but much
+    more preferable to the artefacts around the borders with RepeatNone.
+    
+    Reported-by: Clemens Eisserer <linuxhippy@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=45016
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0b2651dc04cef8f9692b2557684f044b4980700f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Apr 1 19:43:15 2012 +0100
+
+    sna: Apply composite offset to damage for spans fast paths
+    
+    Reported-by: Jiri Slaby <jirislaby@gmail.com>
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=47597
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4ea9ab9303d21a62683055b75eaed66c97a5f289
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Apr 1 16:36:16 2012 +0100
+
+    sna: Fix assertion to look at bbox of all boxes/points
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 932743bb333e35d5f6529a701137aad4d7490555
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Apr 1 09:54:43 2012 +0100
+
+    sna: Assert that drawing boxes are within bounds
+    
+    More sanity checks required.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit cc20c45aa0ca15720510668d6918bf3c99104626
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Mar 30 22:51:21 2012 +0100
+
+    sna: Minimise the risk of hotplug hangs by checking fb before vsync
+    
+    Everytime we issue a MI_WAIT_FOR_EVENT on a scan-line from userspace we
+    run the risk of that pipe being disable before we submit a batch. As the
+    pipe is then disabled or configured differently, we encounter an
+    indefinite wait and trigger a GPU hang.
+    
+    To minimise the risk of a hotplug event being detected and submitting a
+    vsynced batch prior to noticing the removal of the pipe, perform an
+    explicit query of the current CRTC and delete the wait if we spot that
+    our framebuffer is no longer attached. This is about as good as we can
+    achieve without extra help from the kernel.
+    
+    Reported-by: Francis Leblanc <Francis.Leblanc-Lebeau@verint.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=45413 (and others)
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 305734ebdf3d51c084cfbee8804b6c60b1f03a98
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Mar 30 21:27:29 2012 +0100
+
+    sna: Separate out scanline waiting for gen4
+    
+    So that we do not set a gen4 bit on gen2 and apply the old workaround of
+    trimming y2 instead.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6f2814db6f7b89e94e54b8d73c7e176ab7d1c469
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Mar 30 20:45:55 2012 +0100
+
+    sna/traps: Align the pointer+index
+    
+    It's the location of the pixels within the row that matter for
+    alignment!
+    
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=47418
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+    Tested-by: Magnus Kessler <Magnus.Kessler@gmx.net>
+
+commit ee075ced844350785685a0f93f88f1dc310bcc73
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Mar 30 19:09:30 2012 +0100
+
+    sna/traps: Align the pointer not the indices
+    
+    Magnus found that inplace_row was still crashing on his setup when it
+    tried to perform an 8-byte aligned write to an unaligned pointer. This
+    time it looks like the row pointer itself was not 8-byte aligned, so
+    instead of assuming that and fixing up the indices, ensure that the
+    (index+row) results in an 8-byte aligned value.
+    
+    Reported-by: Magnus Kessler <Magnus.Kessler@gmx.net>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=47418
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fde8a010b3d9406c2f65ee99978360a6ca54e006
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Mar 30 12:47:21 2012 +0100
+
+    uxa: Remove broken render glyphs-to-dst
+    
+    Reported-by: Vincent Untz <vuntz@gnome.org>
+    Reported-by: Robert Bradford <robert.bradford@intel.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=48045
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 451489b49916cf5a9d27844196f9656e590d9124
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Mar 30 10:21:26 2012 +0100
+
+    sna/gen7: Allow per-device specific maxima
+    
+    As the maximum thread count and urb size differs between different
+    incarnations of the GT units, be a little more flexible in programming
+    those maximums.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ea36f2c4a3fa9afa8184eeaf944af9924c080368
+Author: Eugeni Dodonov <eugeni.dodonov@intel.com>
+Date:   Thu Mar 29 21:08:29 2012 -0300
+
+    Add support for Ivy Bridge GT2 Server chipset
+    
+    Sometimes known as Bromlow.
+    
+    Signed-off-by: Eugeni Dodonov <eugeni.dodonov@intel.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6142232fa0feeb39412cda85ca727cc770eaa042
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Mar 28 18:59:26 2012 +0100
+
+    sna: Add video sprite support for ILK+
+    
+    Based on the work by Jesse Barnes.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ae8aa172a7330439a8e6dda41f5e33eb257a139b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Mar 28 22:07:10 2012 +0100
+
+    sna: Fix up 32-bit overflow for maximum object size calculation
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2e7b5f7eafbf452c781e50eba7dc8323260af59e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Mar 27 10:42:59 2012 +0100
+
+    sna/traps: Prefer to try mono spans on the GPU before trying inplace CPU
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 522b41b393b979fdccf1ad62194cde8129f98c8c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Mar 27 10:42:21 2012 +0100
+
+    sna/traps: Fix the width of the left-hand edge of an unaligned box
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 008ad39b72eb86dc2f89789427be269c148feaf4
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Mar 27 10:41:37 2012 +0100
+
+    sna/gen6: Reduce opaque solid OVER to SRC for render composite
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a9e9041934b2486e5661ba6c550e6670009f69f3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Mar 26 16:03:42 2012 +0100
+
+    sna: Remove bogus assertion of no references to in-flight upload buffers
+    
+    As we may hold a cached reference to an upload buffer whilst it is
+    in-flight, the assertion that there are no such references to a buffer
+    being reused is no longer true. Those cached references will be released
+    as soon as we retire the buffer during the readback and so we are free
+    to reuse such an upload buffer for immediate readback.
+    
+    Reported-by: Jiri Slaby <jirislaby@gmail.com>
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=47597
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 89091dd8a3fba6520a651e3e135c87546b81df9b
+Author: Paulo Zanoni <paulo.r.zanoni@intel.com>
+Date:   Tue Mar 20 11:53:21 2012 -0300
+
+    Avoid duplicated code with intel_output_create_ranged_atom
+    
+    Same change for intel_display.c and sna_display.c.
+    
+    Signed-off-by: Paulo Zanoni <paulo.r.zanoni@intel.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 62f9833298ea936eaefe973eca04b1dde858fbd8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Mar 25 21:25:15 2012 +0100
+
+    sna/gen2+: Approximate expensive gradients when using imprecise rendering
+    
+    If we lack the ability to use a shader to compute the gradients
+    per-pixel, we need to use pixman to render a fallback texture. We can
+    reduce the size of this texture and upsample to reduce the cost with
+    hopefully imperceptible loss of quality.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 25807f472d051163ed96556a409110fa405c24d1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Mar 23 14:56:06 2012 +0000
+
+    uxa: Remove hook for CompositeRectangles
+    
+    It was broken and not flushing damage correctly. With the
+    improvements made to the kernel, it is no longer a significant advantage
+    per se and not worth its additional complexity.
+    
+    Reported-by: Tilman Sauerbeck <tilman@code-monkey.de>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=32547
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4460c6d0d30cf20b76854d47fd9e3aecf1839f15
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Mar 23 11:05:55 2012 +0000
+
+    configure: Stop the debug build erroring out if it cannot find valgrind
+    
+    Another case where I passed an empty string believing that would be
+    sufficient to replace the error path...
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 168ecd96f23756e185af627f814f81b8a4c0c529
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Mar 22 23:47:56 2012 +0000
+
+    sna: Make the fallback debugging messages more consistent
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8693005b5427f256bcd7c2e7cfc48d56f5b8c5ea
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Mar 22 23:43:04 2012 +0000
+
+    sna: Update the target bo after changing from Y tiling
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 83f98d6e5c303e52c1e0fb95b6237ebf62a8edfe
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Mar 22 21:57:14 2012 +0000
+
+    sna: Correctly test for clear glyphs when searching for ones to skip
+    
+    With xterm, it is quite common for it to redraw itself by using lots of
+    spaces and so it is efficient for us if we ellide those clear glyphs and
+    only draw the backing boxes. However, we were only checking the first 8
+    pixels in each line because of a missing pointer increment.
+    
+    Fixes absent '=' characters when using a compositor and ImageText.
+    
+    Reported-by: Jiri Slaby <jirislaby@gmail.com
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=47735
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 86121a3af9a9fc9a2c76d7ac9f3ec17105d20d80
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Mar 22 11:21:43 2012 +0000
+
+    sna: Adjust the damage region for the composite offset
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=47597
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a6b48dd7f1eeb1a8e3841b8f3326c60b300ee9e9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Mar 22 09:22:52 2012 +0000
+
+    sna: Force fallbacks if the destination is unattached
+    
+    Since the removal of the ability to create a backing pixmap after the
+    creation of its parent, it no longer becomes practical to attempt
+    rendering with the GPU to unattached pixmaps. So having made the
+    decision never to render to that pixmap, perform the test explicitly
+    along the render paths.
+    
+    This fixes a segmentation fault introduced in 8a303f195 (sna: Remove
+    existing damage before overwriting with a composite op) which assumed
+    the existence of a backing pixmap along a render path.
+    
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=47700
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 52f39ae1697bef86471b7c5eef8553661f255b67
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Mar 21 13:31:03 2012 +0000
+
+    sna: Assert that the bo created is large enough
+    
+    Double check that the maximum access size computed from the bo
+    parameters is within the allocated size for the bo.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2f23c660f58e0db2107255f32a3503dae62fe304
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Mar 21 13:30:45 2012 +0000
+
+    sna: Assert that the tiled blt is correctly clipped
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e0cd13e2af3db237c171f8ca1c70ddc67b1fbce4
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Mar 21 09:06:10 2012 +0000
+
+    sna: Fallback to inplace upload if forced to tile the indirect replacement
+    
+    Reported-by: Clemens Eisserer <linuxhippy@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=47629
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1db1eced5462723811e535a53cb41b108fc6c5a3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Mar 20 22:57:50 2012 +0000
+
+    sna: Tidy an assertion when handling tiled copies
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 38b0cc24b45afd4ed57187fb066896bf1e467f45
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Mar 21 01:01:47 2012 +0000
+
+    sna: Remove the short-circuiting of move-to-cpu for read if no damage
+    
+    The danger now is that we may have either discarded the shadow pixels or
+    have replaced them with a GTT mapping, either way undesirable and so we
+    should reconstruct the shadow mapping.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f49a6b1fd7e23252b2a306f8bdb9baed5c1e8d4b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Mar 20 21:36:26 2012 +0000
+
+    sna: Decouple the private data after UnrealizeFont
+    
+    As the font is kept around and reused after UnrealizeFont, we need to
+    nullify the pointer to our private data in order to prevent the later
+    use-after-free.
+    
+    Reported-by: Peter Jordan
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1bdd6461de18a6812d5af0283f4222cbb80ca2f8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Mar 20 11:08:44 2012 +0000
+
+    sna/traps: Remove bogus assertion
+    
+    As we only enter that path for singular unbounded boxes, we are
+    guaranteed to fill the entire trapezoid extents and so do not need the
+    unbounded fixup the assertion was fretting about.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1c2932e9cb283942567c3dd2695d03b8045da27f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Mar 19 15:51:43 2012 +0000
+
+    uxa: Defer the call to EnterVT till after outputs are initialised
+    
+    We need to do this apparently or else we never perform the VT switch.
+    However, we can not do it too early, especially not before we have
+    finished intialising the outputs.
+    
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=47395
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 972e1108a5606399a679f97af0815ec9730ab5be
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Mar 19 14:38:28 2012 +0000
+
+    sna: Declare videoRam correctly on gen2 devices
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c0bab1df509d1f7fe36173715846c13b931e9be1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Mar 19 08:25:22 2012 +0000
+
+    sna/dri: Make the drawable as damaged for the off-screen immediate exchange
+    
+    In some cases off-screen is stil visible, for example under a rotation.
+    As such xrandr -o left; glxgears -fullscreen was broken.
+    
+    Reported-by: Phillip Haddad <phillip.haddad@gmail.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 17c19ea8e21e1b20eee446045573dfd94ce6f537
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Mar 18 13:23:26 2012 +0000
+
+    sna/traps: Remove separate edge->vertical flag
+    
+    Mark vertical edges with dy==0 to reduce structure size and reduce
+    memory load during edge walking.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 82023397cd05c05cfcb8939829a95e287d438875
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Mar 18 11:10:14 2012 +0000
+
+    sna/gen3: Improve clear-to-solid reduction
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7ce5f4a11389b2fe9f27a6f09c4848ac71424d5d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Mar 18 10:55:17 2012 +0000
+
+    sna/gen3: Do not force tiling for large pixmaps
+    
+    As the extraction routine is now smarter and can construction
+    subsurfaces without copying we do not need to force tiling.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 342dda3fe361c8be2f3af5af1516cdc6a5fdcaa9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Mar 18 10:55:06 2012 +0000
+
+    sna/gen3: Prevent copy-fallback if we cannot blit
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 28c089781fdf74a9bac2e138e65383748558fcc1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Mar 18 10:55:27 2012 +0000
+
+    sna: Fixup the cpu shadow mappings before uploading the box
+    
+    On the off-chance we arrive here with a pointer to the GTT mapping.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 79258fe560d08dd3dd22b4782360e1597e54948c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Mar 18 09:45:27 2012 +0000
+
+    sna/traps: Apply some more operator and unbounded reductions
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fe8866d6112c3e187d6682e9e4610325668427a0
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Mar 17 21:49:56 2012 +0000
+
+    sna/gen[345]: Convert CPU mappings to GTT for vertices on submit
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 97cd0c7da51024400e8900e46f51620a5f7ad402
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Mar 17 23:57:46 2012 +0000
+
+    sna/traps: Upon reducing an ADD to a SRC, we need to apply the pending clear
+    
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=47444
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e31d9dacafe060dc86de801114b475fdd0142eb6
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Mar 17 09:21:00 2012 +0000
+
+    sna/traps: Align indices for unrolled memset in row_inplace()
+    
+    The compiler presumes that the uint64_t write is naturally aligned and
+    so may emit code that crashes with an unaligned moved. To workaround
+    this, make sure the write is so aligned.
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=47418
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2b4e11923d9f683f43acf8053bcec1701df25c1f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Mar 17 00:05:47 2012 +0000
+
+    sna/traps: Tune inplace_end_subrows()
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d887f209f1210a294afc2c3883a97f7ac9f42bad
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Mar 16 17:19:11 2012 +0000
+
+    sna/dri: Mesa expects the 8-bit stencil buffer to have 2-bytes per pixel
+    
+    The seperate stencil buffer is full of lies, why worry about one more?
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 63c0d10faee3c7cca050505c2e81c416119e57e9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Mar 16 14:51:53 2012 +0000
+
+    sna/dri: Improve handling of non-front attachments for CopyRegion
+    
+    Confusion reigns between using the backing pixmap for the drawable for
+    the front buffer, and a fake pixmap for the auxiliary buffers.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 324a1dffdc7dd896224fab265bd6a9cf99d7587f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Mar 16 13:07:00 2012 +0000
+
+    sna/gen3: Micro-optimise solid span emission
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 47c47b85f6b7ef5cbc2192da9ef0cee91f6744ca
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Mar 16 12:59:13 2012 +0000
+
+    sna/traps: Micro-optimise span emission
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3a26437f195bf3e5d5913f5552a0b838cafb9b2c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Mar 16 12:37:25 2012 +0000
+
+    sna/traps: Tune nonzero_row
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit cb04cf9f4395c258987faead80de5c3a2c93082e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Mar 16 09:28:24 2012 +0000
+
+    sna/traps: Make the inline u8 arithmetic more robust
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d55bbdf42c75eb0fdb634e963ce81953583964b9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Mar 16 09:18:29 2012 +0000
+
+    sna/traps: Remove the old paths for mono inplace traps
+    
+    Dead code elimination.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fe4ad66aadcfa0c907ba6460a88c49e65225602c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Mar 15 21:33:00 2012 +0000
+
+    sna: Correct the order of screen private teardown
+    
+    So that we do not keep a stale references of the last cached pixmap
+    across server regeneration (or shutdown).
+    
+    Reported-by: Thierry Reding <thierry.reding@avionic-design.de>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=47357
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0a8218a535babb5969a58c3a7da0215912f6fef8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Mar 15 13:20:35 2012 +0000
+
+    sna: Prefer the CPU bo for uploads if last access was not through the shadow
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 77c9c03b102e6fac2279f0085034557bd68c5112
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Mar 15 13:18:43 2012 +0000
+
+    sna: Fixup the shadow pixmap pointer for move-to-gpu
+    
+    If we choose not to use the CPU bo for the upload (because we fear the
+    subsequent synchronisation cost), we need to fixup the shadow pointer
+    before dereferencing it.
+    
+    On the move-to-cpu side, the fixup is already performed as we will need
+    to access the shadow pixels for the subsequent drawing operation.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0e2fbb6a1c1ad6b0971d07a91a790b0b3236dad3
+Merge: 64ccc66 84d7a82
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Mar 15 12:43:47 2012 +0000
+
+    uxa: Merge 'remove complicated second level caching'
+    
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=47345
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 84d7a82122530a62ab9a2f4bba3044c23a0db9b0
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Mar 10 10:03:23 2012 +0000
+
+    uxa: Simplify allocation of backing pixmap
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1b1016624ad16cf5063e88a1d422e28865a9e87f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Mar 10 09:31:24 2012 +0000
+
+    uxa/i915: Remove broken CA pass, fallback to magic 2-pass composite helper
+    
+    The backend failed to handle all the corner cases, so remove the
+    complication.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 895a56a553e1386323a593063e5b7fbb7a410abe
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Mar 10 09:28:27 2012 +0000
+
+    uxa: Remove unused render_mask_solid members
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9c6f79440e8af9f264e3f6270384064dc1f44721
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Mar 10 09:27:36 2012 +0000
+
+    uxa: Remove unused tracking of the current render target
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 219467ac8bfab98bca82108b22eae8af3fc0bf36
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Mar 10 09:26:10 2012 +0000
+
+    uxa: Simplify flush tracking
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit bd8fafe0c48df7f138459f590a0e9e8d0c3267b7
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Mar 10 09:10:16 2012 +0000
+
+    uxa: Kill the complicated in-flight tracking
+    
+    Reference leak hunting.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 64ccc6698def517fc37e9ba3c41715626df0e3ca
+Author: Thierry Reding <thierry.reding@avionic-design.de>
+Date:   Thu Mar 15 13:10:20 2012 +0100
+
+    configure: Keep passed-in CFLAGS for DRI tests
+    
+    When the user passes extra CFLAGS and CPPFLAGS to the configure script,
+    they should be kept when performing subsequent checks with additional
+    flags. This is required to properly build in cross-compilation setups
+    where the user may pass in flags like --sysroot in order to pick up the
+    cross-built dependencies.
+    
+    Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
+
+commit c5c61ef378cad3c8259631138ea1e03eb02036af
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Mar 15 12:38:22 2012 +0000
+
+    sna/traps: dst IN WHITE does not reduce to SRC!
+    
+    I was getting too carried with my reductions. However, IN over a
+    clear surface is a no-op, though unlikely!
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fba49e1bb8e5b6b0e3ceace2dbddb5796ece954e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Mar 15 10:31:51 2012 +0000
+
+    sna/traps: Fix off-by-one for filling vertical segments in tor_inplace
+    
+    If the last solid portion was exactly 4-pixels wide, we would miss
+    filling in the mask.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 27f8f121b3d7433c6c3470b048428ca088acd2c9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Mar 14 23:43:20 2012 +0000
+
+    sna/damage: Handle a reduced damage rather than assert
+    
+    As we may reduce a damage to empty along the migration paths and not
+    detect that reduced damage till later, handle those scenarios rather
+    asserting.
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?42426
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit abd104600252f0ebd1eb77eb5419693e1c17deda
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Mar 14 23:08:31 2012 +0000
+
+    sna: Treat unmapped but CPU-mappable bo as available for mapping
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2c492c0064e23457bffdf4f9ab1a7c9f1be93a87
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Mar 14 23:05:58 2012 +0000
+
+    sna: Disable tiling for single row pixmaps (unless required for hw limits)
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6890592cd2b2d6f0d06c530f5e770fdc98577d4f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Mar 14 21:30:13 2012 +0000
+
+    sna/traps: Explicitly create an unattach pixmap for fallback
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=42426
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 23b5640a0f8d8a944275e574f4c72f2380f7ed7a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Mar 14 20:48:56 2012 +0000
+
+    sna: Avoid using kgem_bo_reference() internally
+    
+    So that we can keep the assertion to track the refcnt elsewhere.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 03731b4e37b0cbd3a1cb8c8ec08fddf0f670a918
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Mar 14 20:46:59 2012 +0000
+
+    sna: Ellide no-op image glyphs
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d0e05b4294b2f150a41dd95d52c2e6ee8479283d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Mar 14 20:19:30 2012 +0000
+
+    sna: Don't mark cached upload buffers for inactivity expiration
+    
+    As these do not follow the normal rules of damage tracking, we have to
+    be careful not to force migration.
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=42426
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 96ead26c4dddab637875c74a9afca6fd6662352b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Mar 14 19:56:42 2012 +0000
+
+    sna: Add a couple of asserts for inactive_partial reference counting
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6a4ac18e37521d54dc36b215cbd27c56d20b2922
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Mar 14 11:51:39 2012 +0000
+
+    sna/traps: Use a more direct fallback path for the CPU
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8580677ee6725144acf63f5cc2f8097376352d6e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Mar 14 11:46:18 2012 +0000
+
+    sna/traps: Rasterise using pixman inplace where appropriate
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8a303f195b53a78dcbb2b6c84e7e691bedc86d25
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Mar 14 11:26:03 2012 +0000
+
+    sna: Remove existing damage before overwriting with a composite op
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 63eeb98463a77adadc26d9de1e640b75eefebf1a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Mar 14 10:30:47 2012 +0000
+
+    sna/gen3: Look harder to see if we can indeed use the BLT for composite
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d23ee0380b61e0dfd3ed56b8b4a15fd0b7956491
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Mar 13 22:00:25 2012 +0000
+
+    sna: Reuse the cached upload as a source GPU bo
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=42426
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0acec1685328b1dd9dffa804a27a122fc6e4225a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Mar 13 21:29:57 2012 +0000
+
+    sna: Defer the release of the upload buffer cache till retirement
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 06b28d541bdf2607edc2eb476919b28e747885d8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Mar 13 20:01:53 2012 +0000
+
+    sna: Destroy the cached upload buffer if before copying into it
+    
+    As we discard the buffer after the next batch, we will lose the contents
+    of the pixmap. Instead discard the cache, and treat it as a normal
+    shadow again.
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=42426
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 015db20287ec90f81ddb7eb2e7ce23b90aacfb2b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Mar 13 16:29:41 2012 +0000
+
+    sna: Refactor source upload-to-gpu
+    
+    This was originally split between into functions for flexibility that
+    nothing used, so merge the duplicated code into a common function.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6dfe28f978b59ab2fc44cdd8ddf3743d6507588b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Mar 13 15:47:27 2012 +0000
+
+    sna/gen6: Remove the double application of the render offset
+    
+    Cut'n'paste error from an older generation.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c751242e245eb168b92616bdcea3421be4e420bc
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Mar 13 12:04:04 2012 +0000
+
+    sna: Only use the cpu bo for xfer between CPU and GPU if either is busy
+    
+    The synchronisation costs overwhelm any benefit from offloading the
+    copy, unless we are currently streaming the updates anyway.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c9668a772f15ab36d643a9b0616b309856146c89
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Mar 12 23:28:51 2012 +0000
+
+    sna: Reduce OVER with a clear pixmap to a BLT
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2ea58256f5ce6e1c0f48d366ff7a1fbf300600de
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Mar 12 23:05:17 2012 +0000
+
+    sna: Reuse the same upload buffer for the duration of the batch
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8b9abe2be1f54bd8e8593ed155cc4725ac97627a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Mar 12 21:09:19 2012 +0000
+
+    sna: Prefer to render very thin trapezoids inplace
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1e2d6ee31a21267ba27e4bebb883aaab08a12f30
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Mar 12 20:34:42 2012 +0000
+
+    sna: Always reset the source counter after rendering to with the CPU
+    
+    The goal is to avoid moving to the GPU too early for a frequently
+    modified CPU buffer.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7bde1f55a1075eefab0f083833508265fc0e91e7
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Mar 12 20:25:50 2012 +0000
+
+    sna: After move-to-gpu signals yes, force the GPU bo creation
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2ee7de1f1711d1058e5812c6aa0d94ecf9af7d8d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Mar 12 20:09:05 2012 +0000
+
+    sna/trapezoids: Reduce mono ADD/OVER against a clear background to a SRC
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 99c239e380b9f5134afc75bf55bf3f69e5113e38
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Mar 12 19:49:30 2012 +0000
+
+    sna: Treat backing pixmaps no differently from their forward facing cousins
+    
+    Another fix for the large buffers overhaul.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 28792be1f31190171644d911d7b5573186fe2df2
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Mar 12 19:45:35 2012 +0000
+
+    sna/display: Only flush pending output when installing a new scanout
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 278c329b9e2aa9a94bd0d0ee73939814ac514e3d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Mar 12 11:50:54 2012 +0000
+
+    sna/trapezoids: Further improve the clipping criteria for inplace traps
+    
+    Not only must we defend against the span starting too far to the right,
+    we must also defend against the span terminating too far to the left.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7ae45584327a10b05f7aee99bcb71e9d990a3e9b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Mar 12 10:49:46 2012 +0000
+
+    sna/trapezoids: Add paranoia to ensure that the span starts within the clip
+    
+    Reported-by: Clemens Eisserer <linuxhippy@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=47226
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8136bc5e113ae06c30def3c91b1615e5fab8af44
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Mar 11 19:45:55 2012 +0000
+
+    sna: Make the maximum BLT pitch assertions consistent
+    
+    The maximum permissibly BLT pitch value is 32767, so make the assertions
+    match...
+    
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=47206
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 989615493608525fc252e4e94ac7259cba0741f5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Mar 9 22:44:16 2012 +0000
+
+    sna: Feed fallback mono trapezoids through the mono rasteriser
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 552e4fbd2c25eb5ab0ae77e11f5f8ba2fdb29daa
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Mar 9 20:02:44 2012 +0000
+
+    sna/traps: Add a fast path for narrow masks
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 494edfaaacaae13adfa5e727c66a83cb2294d330
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Mar 9 12:19:33 2012 +0000
+
+    sna: Handle partial reads with a pending clear
+    
+    Skip the filling of the whole pixmap if we have a small read and we
+    know the GPU bo is clear. Also choose to operate inplace on the GPU bo
+    if we meet the usual criteria.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit bd62dc73dcdbab34aa5c83382e46c7315d554a1a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Mar 9 10:37:34 2012 +0000
+
+    sna/traps: Apply somes simple but common operator reduction for clipmasks
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c25a3f7f46010660f441070ab7b9d5d1bc39ed0d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Mar 9 09:43:46 2012 +0000
+
+    sna/dri: Only delivered a delayed flip if the drawable is still on the root
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 93846b468e778440549ef0cae171c7fe9678ed9a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Mar 9 09:43:24 2012 +0000
+
+    sna/traps: Remove some dead code
+    
+    This function was never used in this implementation, remove it.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 90c995736555ce14b08b69a42832d9774ba58304
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Mar 9 00:37:32 2012 +0000
+
+    sna: Emit a INFO when compiled with debugging enabled
+    
+    It is useful to know and to receive confirmation that you have
+    successfully compiled and executed the driver with debugging enabled.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2e194f33db0437ea2f25c22efdad9552aefcab2f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Mar 8 18:07:22 2012 +0000
+
+    sna/traps: Fix the initialisation of the error term for vertical mono edges
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 635c604b787625f93763001951f8bdf66482c682
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Mar 8 18:06:51 2012 +0000
+
+    sna/traps: Unroll insertion sort
+    
+    As the compiler cannot know the loop is bounded by a sentinel, manually
+    unroll it.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a087430ad99c06e79249d2cdd019cb8bf7f955d3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Mar 8 17:13:39 2012 +0000
+
+    sna/gen6: Replace the memset with explict initialisation
+    
+    The profiles told me to kill it...
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 61226cd41faf320f79ee4bd72dc77163079da853
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Mar 8 13:41:58 2012 +0000
+
+    sna: Fix handling of large glyphs following large and shared buffer work
+    
+    Part of the large buffer handling was to move the decision making about
+    whether to create GPU bo for a pixmap to creation time. The single
+    instance where we change our minds later is involving large glyphs which
+    we choose not to cache.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit aa7a2bd71275e069a2e4383a26355854b0b8044c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Mar 8 12:27:23 2012 +0000
+
+    sna: Fix reversed logic for CREATE_NO_RETIRE
+    
+    If the flag is set, we cannot retire, not the other way around!
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f8d520950edb5cec878999a09d3f7e6f8b15bf5e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Mar 8 12:13:36 2012 +0000
+
+    sna: Avoid NULL deference in DBG
+    
+    Only print out the details of the allocated CPU bo, if we actually
+    allocate it.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 33af42e6284f104ed3c4cdba4bf3b1c29322ce9c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Mar 8 12:10:24 2012 +0000
+
+    sna: Force the creation of a backing pixmap for scanout
+    
+    Ordinarily if the GPU is wedged, we just want to create a shadow buffer.
+    Except that we must ensure that we do allow a bo to be created for
+    attaching to the scanout.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6abfa4c5662e5294edc501953dbfa7aabf0b2f57
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Mar 8 11:59:02 2012 +0000
+
+    sna: Mark the pixmap for writing when creating the screen resources
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5c5ebd6a3ecf3bd83747003bc272a736b7c333c0
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Mar 8 11:13:34 2012 +0000
+
+    intel: Fix typo s/asert/assert/
+    
+    The joy of conditional compiles masked this compilation failure when
+    testing.
+    
+    Reported-by: Reinhard Karcher <reinhard.karcher@gmx.net>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f6474883d325cff443da9ceaa99ec734e6cdc1d6
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Mar 8 11:04:05 2012 +0000
+
+    sna/gen2+: Use the reduced operator from CompositeRectangles
+    
+    Do not attempt to further reduce the operator locally in each backend as
+    the reduction is already performed in the upper layer.
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=42606
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2ae3cd36ae98fa43716ef482e70364e7563cf1ea
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Mar 8 10:51:05 2012 +0000
+
+    sna: Tidy marking pixmap->clear for CompositeRectangles
+    
+    Reduce the two unsightly checks into one.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8b21659ef2f9cec799b8215a2e5481667bc744bf
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Mar 8 10:50:32 2012 +0000
+
+    sna: Add some assertions around pixmap creation for render operations
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7d74300647dd815ae5b4399f84ea339045d12563
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Mar 8 09:54:16 2012 +0000
+
+    sna: Discard unbound partial buffers
+    
+    Instead of keeping a virgin partial buffer around on its inactive list,
+    just transfer it to the global bo cache (in actuality destroy it since
+    it is just a kmalloc with no pages bound).
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9eb8ba4df2a99342dbb3569c043d84aa82506aba
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Mar 8 09:42:58 2012 +0000
+
+    sna: Preserve the offset alignment when trimming unused rows from partials
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8e6166a0e87a00248d0d4925953c923850f5b840
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Mar 8 02:09:25 2012 +0000
+
+    sna: Becareful not to reduce operators for superluminal colors
+    
+    wine-1.4 is such an example of a crazy application.
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=42606
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3f73cc706ff39cd4c10433791f12b5f829f62e6d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Mar 8 08:54:24 2012 +0000
+
+    sna/dri: Use a counter for the number of DRI drawables attached to a pixmap
+    
+    The root pixmap, for instance, may have unique DRI2Drawables for each
+    inferior window. We only want to clear the flush flag on the last
+    release, so we need to keep a count of how many DRI drawables remain
+    attached rather than a solitary flag.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 49a80ce1ff336fb2fa7d214bd3fddbce5a62b77a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Mar 7 15:52:41 2012 +0000
+
+    sna/gen2+: Prefer not to fallback if the source is busy
+    
+    As if we try to perform the operation with outstanding operations on the
+    source pixmaps, we will stall waiting for them to complete.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4899740f6f0f5b1a5b2b3490502ccdeb7b092877
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Mar 8 00:57:12 2012 +0000
+
+    sna: Do not reset partial buffers if they are not attached to the current batch
+    
+    As we may be holding on to them as an active mapping whilst they are
+    executing; reseting the used counter back to zero in this case can cause
+    corruption.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 72a7538d4e7bcf0bd7455d9e67d8751e17739e6c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Mar 7 15:45:21 2012 +0000
+
+    sna: Convolution filter fixes
+    
+    A couple of typos made the convolution filter explode rather than
+    convolve.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 34fe3cbb316c36c7022735cf9b03d8b655e04434
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Mar 7 17:49:01 2012 +0000
+
+    sna: Avoid recursive calls to kgem_retire_partials()
+    
+    Whilst iterating the partial list and uploading the buffers, we need to
+    avoid trigger a recursive call into retire should we attempt to shrink a
+    buffer. Such a recursive call will modify the list beneath us so that we
+    chase a stale pointer and wreak havoc with memory corruption.
+    
+    Reported-by: Clemens Eisserer <linuxhippy@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=47061
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 46c79e4d59ec4f90a1fa97b24a3e7058fdbfa6ba
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Mar 7 13:17:21 2012 +0000
+
+    sna: Restore checking for all-clipped-out for CompositeRectangles
+    
+    In the refactoring to avoid repeatedly applying the singular
+    pCompositeClip, the check for the all-clipped state was lost.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9944f1834a9c53091e4415f928f917e9247f17c5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Mar 7 10:47:42 2012 +0000
+
+    sna/gen2: Fix transformation of linear gradients
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit df25495eaab5bcd5baf86047a2dd0149eea00d1e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Mar 7 10:43:24 2012 +0000
+
+    sna/gen4: Hook in the poor-man's linear gradient
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 69d6a0387b8eec8396631714a0564b7e28d187ab
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Mar 7 10:43:24 2012 +0000
+
+    sna/gen5: Hook in the poor-man's linear gradient
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b0d3c4f661bace84b78b194eaeee7bfa009a32cf
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Mar 7 10:43:24 2012 +0000
+
+    sna/gen7: Hook in the poor-man's linear gradient
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit dcc364a7b190ce9cec2ff35aa22c10529f84e4c3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Mar 7 10:40:50 2012 +0000
+
+    sna/gen6: Add poor-man's linear implementation
+    
+    Still no JIT, in the meantime we can at least cache the gradient ramps.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 232972c0e5bd833c1d0b33432fa8092c601fd0e5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Mar 6 12:17:03 2012 +0000
+
+    sna: Remove the 2-step damage flush
+    
+    The idea was to reduce the number of unnecessary flushes by checking for
+    outgoing damage (could be refined further by inspecting the reply/event
+    callback for a XDamageNotifyEvent). However, it does not flush
+    sufficiently for the compositors' liking. As it doesn't appear to restore
+    performance to near uncomposited levels anyway, remove the complication.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit eb10ade0fc8e21cd01c0d8acba7891fd7f2aa222
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Mar 5 22:55:57 2012 +0000
+
+    sna: Defer the FlushCallback removal until after the next flush
+    
+    Try to reduce the amount of Add/Delete ping-pong, in particular around
+    the recreation of the DRI2 attachment to the scanout after pageflipping.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 60dacdb127599606db13ad111af8ce26c1141da5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Mar 5 22:46:20 2012 +0000
+
+    sna: Only install the flush callback for the duration of the foriegn buffer
+    
+    After we are no longer sharing the bo with foreign clients, we no longer
+    need to keep flushing before every X_Reply and so we can remove the
+    callbacks to remove the overhead of having to check every time.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b39d9f9166547effe066acfc3327dd88a019d273
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Mar 5 22:29:38 2012 +0000
+
+    sna: Check for flush at the start of every WriteToClient
+    
+    The goal is to simply avoid the flush before going to sleep when we have
+    no pending events. That is we only want to flush when we know there will
+    be at least on X_Reply sent to a Client. (Preferably, it would a Damage
+    reply!) We can safe assume that every WriteToClient marks the beginning
+    of a new reply added to the Client output queue and thus know that upon
+    the next flush event we will emitting a Reply and so need to submit our
+    batches.
+    
+    Second attempt to fix a438e4ac.
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f30b0beea4f5657a60eb5b286f41105298fa451a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Mar 4 22:23:39 2012 +0000
+
+    sna/trapezoids: Ellide empty cells
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b69c9dfae128ed69a397a066b8fbe62012742bf1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Mar 5 21:05:34 2012 +0000
+
+    sna/composite: Skip clipping the rectangle region against the singular clip
+    
+    As we will already have taken it into account when constructing the
+    region from the rectangles.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f4846168a60feca7437f0039612ba9986c5f8d77
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Mar 5 21:04:25 2012 +0000
+
+    sna: Flush dirty CPU damage before notifying the compositor
+    
+    Fixes regression from a438e4ac (sna: Revamp vmap support)
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d7600e4e7726bb8bd6c7256ad2baf195d4427c60
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Mar 4 19:12:29 2012 +0000
+
+    sna: Add some assertions to partial buffer list tracking
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3b5d556a93ac0afebf6c1dd02e0c92f6eb73f633
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Mar 4 15:48:33 2012 +0000
+
+    sna: Fix assertion for checking inactive shadow buffers
+    
+    We may have an ordinary malloc with no CPU bo attached so check before
+    dereferencing.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit aaed9e9722aa30a3d6dc9a3f07309655de65b6bd
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Mar 2 23:31:24 2012 +0000
+
+    sna: Encourage promotion of snooped CPU bo to real GPU bo
+    
+    This fixes the regression in performance of fishietank on gen2. As
+    the texture atlas is too large to be tiled, one might presume that it
+    has the same performance characteristics as the snooped linear CPU
+    buffer. It does not. Therefore if we attempt to reuse a vmap bo, promote
+    it to a full GPU bo. This hopefully gains the benefit of avoiding the
+    copy for single shot sources, but still gives us the benefit of avoiding
+    the clflushes.
+    
+    On the plus side, it does prove that gen2 handles snoopable memory from
+    both the blitter and the sampler!
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 599cd0e8ef3080fc735860bef4e47107c1c05f9a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Mar 2 20:18:32 2012 +0000
+
+    sna: Align allocations with partial buffers to 64 bytes.
+    
+    A magic number required for so many functions of the GPU. In this
+    particular case it is likely to be that the offset of a texture in the
+    GTT has to have a minimum alignment of 64 bytes.
+    
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=46415
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4918e309dfadaf14da6997468f08db03ac0a6327
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Mar 2 18:18:48 2012 +0000
+
+    sna: Silence an assertion failure during shutdown
+    
+    Clear the scanout flag on the front buffer during teardown to silence
+    the debugger.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f890fc25c6c2ca358323be5a0d636c3f2ab4b298
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Mar 2 18:11:56 2012 +0000
+
+    sna: And fix compilation for last commit
+    
+    I skipped a GCC warning about the implicit function declaration, which
+    of course results in a runtime silent death. Oops.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4f853acfeccb92885f154b03125d5716591a87bd
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Mar 2 17:36:50 2012 +0000
+
+    sna: Prevent backing pixmaps being created later
+    
+    We used to allow the backing pixmap to be created later in order to
+    accommodate ShmPixmaps and ShmPutImage. However, they are now correctly
+    handled upfront if we choose to accelerate those paths, and so all
+    choice over whether to attach to a pixmap are made during creation and
+    are invariant.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 866a61a2590f0c5ae6592a13d4e3de3e68f5e373
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Mar 2 16:06:59 2012 +0000
+
+    sna: Disable vmap on 965gm
+    
+    The sampler just dies if it encounters a snoopable page, for no apparent
+    reason. Whilst I encountered the bug on Crestline, disable it for the
+    rest of gen4 just to be safe.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1c653786895fc30be0e88455ce5f9caf9adc835d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Mar 2 14:34:23 2012 +0000
+
+    sna: Pass usage hint for creating linear buffers
+    
+    As we wish to immediate map the vertices buffers, it is beneficial to
+    search the linear cache for an existing mapping to reuse first.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 29ec36ff063472e0744af99aa81ed5ad8e291a36
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Mar 2 10:01:07 2012 +0000
+
+    sna: Only discard the inplace flag for LLC partial buffers
+    
+    KGEM_BUFFER_WRITE_INPLACE is WRITE | INPLACE and so the typo prevented
+    uploading of partial data through the pwrite paths.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f039ccf9587eb07528034c3247a6e700c87a5500
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Mar 2 09:47:10 2012 +0000
+
+    sna: Be careful not to discard the clear operation for move-region-to-cpu
+    
+    When moving only a region to the CPU and we detect a pending clear, we
+    transform the operation into a move whole pixmap. In such situations, we
+    only have a partial damage area and so need to or in MOVE_READ to
+    prevent the pending clear of the whole pixmap from being discarded.
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=46792
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 392593e61dac3ac65ee8e32de492c4439413ee85
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Mar 1 17:54:51 2012 +0000
+
+    sna/gen5: Help the compiler avoid an uncached read
+    
+    Debug builds are excruitatingly slow as the compiler doesn't store the
+    temporary in a register but uses an uncached readback instead. Maybe
+    this will help...
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9c0c04cac245db046ef17ff24c32e6ab93535f48
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Mar 1 14:52:39 2012 +0000
+
+    sna: Split storage of inactive partials
+    
+    As we now attempt to keep retain partial buffers after execution, we can
+    end up will lots of inactive buffers sitting on the partial buffer list.
+    In any one batch, we wish to minimise the number of buffers used, so
+    keep all the inactive buffers on a seperate list and only pull from them
+    as required.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a438e4ac9ba162e870fb22bc54024d35daa2121e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Feb 28 19:15:34 2012 +0000
+
+    sna: Revamp vmap support
+    
+    Dust off the kernel patches and update to reflect the changes made to
+    support LLC CPU bo, in particular to support the unsynchronized shadow
+    buffers.
+    
+    However, due to the forced synchronisation required for strict client
+    coherency we prefer not to use the vmap for shared pixmaps unless we are
+    already busy (i.e. sync afterwards rather than before in the hope that
+    we can squash a few operations into one). Being able to block the reply
+    to the client until the request is actually complete and so avoid the
+    sync remains a dream.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 272f5d9f8407d8084846b429c1722bddb3e861e9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Mar 1 11:10:03 2012 +0000
+
+    sna: Discard use of inplace GTT uploads on LLC architectures
+    
+    As the buffer is cache-coherent, we can read as well as write to any
+    partial buffer so the distinction is irrelevant.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 43b1a717bae047c7ebbf99e6fa4c03b7a67896b8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Feb 28 13:37:14 2012 +0000
+
+    sna: Sort the partial buffers after stealing a write buffer
+    
+    It will be decoupled and not used again, but this keeps the sanity
+    checks happy.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8198e5872c3771e2aefabe1e3e93afa94d2ea0ec
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Feb 28 10:42:19 2012 +0000
+
+    sna/gen3: Tweak glyph rendering fast paths
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3c4f29820bca336af2c997bafc7ef288b455813c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Feb 27 16:29:38 2012 +0000
+
+    uxa/gen3: Remove special casing of solid pictures
+    
+    Fixes use of alpha-groups and opacity masks in cairo.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8f3066f0c70654f04f4acadf140e3c5c8dda051d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Feb 27 13:58:58 2012 +0000
+
+    sna/gen2; Initialise channel.is-opaque for fills
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3640a0d4cb9e0f115fda9ea36212670f6ccafb22
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Feb 27 12:28:22 2012 +0000
+
+    Revert "meh"
+    
+    This reverts commit 4adb6967a84af8a04769c2d936a41f4a49ed1428.
+    
+    Oops, this debugging commit was not intended to be pushed along with the
+    bugfix. :(
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6fd8d74a6aedb6484e53e704d9f44e0bf83ae9ab
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Feb 27 12:06:50 2012 +0000
+
+    sna: Upload the ordinary partial buffers!
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4adb6967a84af8a04769c2d936a41f4a49ed1428
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Feb 27 11:36:35 2012 +0000
+
+    meh
+
+commit 4fbb0baff525115037f7e5a1689541880a6cdafb
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Feb 26 22:34:30 2012 +0000
+
+    sna: Avoid reusing mmapped partial write buffers for readback
+    
+    An artefact of retaining the mmapped partial buffers is that it
+    magnified the effect of stealing those for readback, causing extra
+    writes on non-llc platforms.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a3c398a6731874ba47e0a46bbd42bf9378e12ab8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Feb 25 10:59:14 2012 +0000
+
+    sna: Retain unfinished partial buffers between batches
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8d773b88f45594f45174dc6f1a264d968690ce84
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Feb 25 09:32:20 2012 +0000
+
+    sna/gen3+: Keep the vertex buffer resident between batches
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8cb773e7c809e1de23cd64d3db862d1f8e7e955a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Feb 25 11:07:16 2012 +0000
+
+    sna: Ensure we trigger a retire for search_linear_cache
+    
+    Bo used for batch buffers are handled differently and not tracked
+    through the active cache, so we failed to notice when we might be able
+    to run retire and recover a suitable buffer for reuse. So simply always
+    run retire when we might need to create a new linear buffer.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b1b4db8942e69d47aabfad3751165dc2252fa448
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Feb 25 00:43:30 2012 +0000
+
+    sna: Skip a tiled bo when searching the cache for a linear mmap
+    
+    If we change tiling on a bo, we are effectively discarding the cached
+    mmap so it is preferable to look for another.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 85e48d2e5eb029d8c17714cb5e7db39ea06a2455
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Feb 24 21:40:44 2012 +0000
+
+    legacy: Rename XF86DRI to HAVE_DRI1 to avoid conflicts with xorg-server.h
+    
+    We use the XF86DRI as a user configurable option to control whether to
+    build DRI support for i810, but it is also used internally within xorg
+    and there exists a public define in xorg-server.h which overrides our
+    configure option. So rename our define to HAVE_DRI1 to avoid the
+    conflict.
+    
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=46590
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 96db90e819a1990c2d139725e522055e92def959
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Feb 24 21:36:30 2012 +0000
+
+    legacy: Delete unused XF86DRI_DEVEL #define
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=46590
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b870a3e5cd922ce37050ece73e2469802dd21da2
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Feb 24 11:21:49 2012 +0000
+
+    configure, NEWS: Bump version to 2.18.0 for release
+    
+    Another quarter, a bit late as I was debugging a few regressions,
+    another release.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5b5cd6780ef7cae8f49d71d7c8532597291402d8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Feb 24 11:14:26 2012 +0000
+
+    uxa: Add a option to disable the bo cache
+    
+    If you are suffering from regular X crashes and rendering corruption
+    with a flood of ENOSPC or even EFILE reported in the Xorg.log, try
+    adding this snippet to your xorg.conf:
+    
+    Section "Driver"
+      Option "BufferCache" "False"
+    EndSection
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=39552
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f8ca50818cd4f82e0ad8eeb245e8ee838b083056
+Author: Gaetan Nadon <memsize@videotron.ca>
+Date:   Sat Feb 18 13:49:02 2012 -0500
+
+    Revert "Update autotools configuration"
+    
+    This reverts commit 9184af921bc2f332fcb6c9b47001414378eab8e2.
+    
+    All X.Org modules must be able to be configured with autoconf 2.60.
+    In addition, version 2.63 has GPL licensing issues which prevents
+    some vendor to release software based on it.
+    
+    The AM_SILENT_RULES are already handled by XORG_DEFAULT_OPTIONS.
+    
+    All X.Org modules must be able to be configured with libtool 1.5.
+    
+    AM_MAINTAINER_MODE default value is "enabled" already.
+    
+    We use the same autogen script for all x.org modules.
+    There are proposals for changes which should be reviewed and eventually
+    applied to all modules together.
+    
+    The lt*.m4 patterns are already included in the root .gitignore file.
+    This can be proposed as a change to all modules, but it invloves
+    changing the topvel .gitignore, the m4/.gitignore, the ACLOCAL_AMFLAGS
+    and the AC_CONFIG_MACRO_DIR together.
+    
+    For more information on project wide configuration guidelines,
+    consult http://www.x.org/wiki/ModularDevelopersGuide
+    and http://www.x.org/wiki/NewModuleGuidelines.
+    
+    Acked-by: Matthieu Herrb <matthieu.herrb@laas.fr>
+    Signed-off-by: Gaetan Nadon <memsize@videotron.ca>
+
+commit a647aff5124674b638ef52152a5c16c27466eed7
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Feb 23 12:04:09 2012 +0000
+
+    sna/gen3: Silence the compiler complaining with DBG enabled
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit cd3a618f583a546bafbe0c171a267774adc4d72b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Feb 23 10:40:57 2012 +0000
+
+    sna/gen4 Refactor get_rectangles() to re-emit state after a flush
+    
+    Condense the work performed by each caller into the callee.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6a3fa4d1b6849b666a9232b017ce82329494621b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Feb 23 10:40:57 2012 +0000
+
+    sna/gen7 Refactor get_rectangles() to re-emit state after a flush
+    
+    Condense the work performed by each caller into the callee.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fe914eaca4b9178ab3d14053a703772f93295895
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Feb 23 10:40:57 2012 +0000
+
+    sna/gen5 Refactor get_rectangles() to re-emit state after a flush
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4ecf882c838c1f044b4ed3add486b6579ea2c431
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Feb 23 10:40:57 2012 +0000
+
+    sna/gen6: Refactor get_rectangles() to re-emit state after a flush
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit dfa21713c27eb9135cb5e1745807324e49422fde
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Feb 23 10:29:38 2012 +0000
+
+    sna/gen3: Refactor get_rectangles() to emit composite state and retry
+    
+    As gen3 only uses the single state emission block, and uniformly calls
+    get_rectangles(), we can move that caller protocol into the callee.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a48e6e0db970ad07cd7452ba24c362d0c2fcf1bf
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Feb 23 10:17:34 2012 +0000
+
+    sna/gen3+: Force a batch flush when run out of CA vbo
+    
+    As we prematurely end the batch if we bail on extending the vbo for CA
+    glyphs, we need to force the flush.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 57c19b10db2b512c52a593fad98b5ac5db4f1497
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Feb 23 00:33:16 2012 +0000
+
+    sna: Use a CPU mapping if the bo is already in the CPU domain
+    
+    The heuristic of using the mapping only before the first use in an
+    execbuffer was suboptimal and broken by the change in bo initialisation.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 510767e213c2f44563f5c438ad1234113567be90
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Feb 22 18:33:09 2012 +0000
+
+    sna/gen4: Fix vertex flushing across batch flushing
+    
+    Due to the w/a for its buggy shaders, gen4 is significantly different
+    that backporting the simple patch from gen5 was prone to failure. We
+    need to check that the vertices have not already been flushed prior to
+    flushing again.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f6392048e3e761b35644268ef161045524cfa369
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Feb 22 17:00:38 2012 +0000
+
+    sna/blt: Avoid clobbering the composite state if we fail to setup the BLT
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4e86da64be947fe4b8b5f285d26d200827847a8c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Feb 22 14:36:35 2012 +0000
+
+    sna/gen3+: Flush the vertices during vertex-finish
+    
+    But only when finishing the vbo, which is the tricky part of the recent
+    CA glyph bugs.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 71512b2438e06b2bd256aff3657797152fbef38e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Feb 22 13:44:24 2012 +0000
+
+    sna: Clear the flush flag on release of scanout/dri
+    
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=46445
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 025d3d46dc28e967b4f42e5748d13c7fb3ad283b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Feb 22 13:17:01 2012 +0000
+
+    sna/trapezoids: Only the inplace PictOpIn is unbounded
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b02f866d67d60538368619849f2acda4c1706476
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Feb 22 09:15:25 2012 +0000
+
+    sna: Ensure we restore the shadow pixels before uploading CPU data
+    
+    Reported-by: Joe Nahmias <joe@nahmias.net>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=46425
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit be5df7b5ab487a1282c96dda92f3799e35cd19af
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Feb 21 23:27:33 2012 +0000
+
+    sna/gen5: Remove CA glyph workaround
+    
+    The root cause has been found and destroyed, so the w/a is now
+    redundant.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6038cede83e7f360428b4625d288411794f9d052
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Feb 21 21:26:29 2012 +0000
+
+    sna/gen3+: Re-emit composite state after flushing CA vertices
+    
+    Reported-by: Clemens Eisserer <linuxhippy@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=42891
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fe6602cbbc4eed1b88ac731a30b46cc970ea444f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Feb 21 21:26:29 2012 +0000
+
+    sna/gen3+: Only flush the vertices after checking for end-of-batch
+    
+    Or upon actually closing the vertex buffer.
+    
+    However, the underlying issue remains. That is we are failing to re-emit
+    the first-pass for CA text after flushing the vertex buffer (and so
+    emitting the second-pass for the flushed vertices).
+    
+    Reported-by: lemens Eisserer <linuxhippy@gmail.com>
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=42891
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 168c87a340119e65b1d7ccbbf59da820044ca936
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Feb 21 13:16:43 2012 +0000
+
+    sna: Clear the scanout flag after releasing the scanout pixmap
+    
+    In the future, this will be a good place to restore the cache level of
+    the bo as well.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d7415742a5f78958489216f450411603b1eff9a7
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Feb 21 16:33:26 2012 +0000
+
+    sna/dri: Queue a flush on the back DRI2 when enqueing a flip
+    
+    As we may wait upon the bo having finished rendering before we can
+    execute the flip, flushing the render cache as early as possible is
+    beneficial
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2715a455f7bfbecd7a6977184dc6180a09d06e1f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Feb 21 14:49:30 2012 +0000
+
+    uxa: Prevent laggy applications by throttling after rendering
+    
+    Before blocking and waiting for further input, we need to make sure that
+    we have not developed too large a queue of outstanding rendering. As we
+    rendering to the front-buffer with no natural throttling and allow X
+    clients to render as fast as they wish, it is entirely possible for a
+    large queue of outstanding rendering to develop. For such an example,
+    watch firefox rendering the fishietank demo and notice the delay that
+    can build up before the tooltips appear.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 26721893cb41cef66db7ef626881d1eba8a5bdea
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Feb 21 13:31:16 2012 +0000
+
+    sna: Mark the pixmap as active for the force-to-gpu short-circuit
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1541f1afca028453379083e564bc82debf0ba39a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Feb 21 13:17:35 2012 +0000
+
+    sna: Skip the CPU synchronization when marking a pixmap as inactive
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 74fd55a96bd6c63e9c49a4b7fee7ef91f6b00a2c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Feb 21 13:11:32 2012 +0000
+
+    sna/dri: Ensure that we reattach to the DRI2 front buffer after modeswitch
+    
+    If we change the Screen pixmap due to a change of mode, we lose the
+    flag that we've attached a DRI2 buffer to it. So the next time we try to
+    copy from/to it, reassert its DRI2 status.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d051793b9194060f5408503b1fac56958c6e58e4
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Feb 21 11:42:31 2012 +0000
+
+    sna/dri: Improve error handling of failing to create a DRI2 pixmap
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 580ae520cad749fb86a1bddd0fa2bcadfd60abb6
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Feb 21 10:55:46 2012 +0000
+
+    sna: Short-circuit repeated calls to force-to-gpu
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f2aafb98026b5c476b7f84aa2dc4c1f9ba2e573d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Feb 21 10:43:11 2012 +0000
+
+    uxa: Silence compiler warning for const arguments
+    
+    i965_video.c: In function 'gen6_create_cc_state':
+    i965_video.c:1374:12: warning: passing argument 4 of
+    'intel_bo_alloc_for_data' discards 'const' qualifier from pointer target
+    type [enabled by default]
+    
+    Repeated ad nauseam.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 507f72d6d44963cae5d8d4b9da68165f73c6fd36
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Feb 21 10:39:48 2012 +0000
+
+    uxa: Remove DPRINTF stubs
+    
+    It wasn't being used for anything non-trivial and was throwing compiler
+    warnings, so remove it.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c72a67390ea243bf43e2ee4efe237ab88a4615b7
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Feb 21 10:21:56 2012 +0000
+
+    sna/dri: Update for AsyncSwap interface changes
+    
+    We now need to return TRUE/FALSE depending on whether we need to
+    invalidate the drawable.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 27bc2acf0e6a0e5e071e0d187bdf71577e821af8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Feb 21 09:29:41 2012 +0000
+
+    sna: Fix use of RegionInit() for singular regions
+    
+    For a singular region, we want to use a value for nboxes of 0 not 1,
+    fortunately if you pass in a box, it ignores the value of nboxes.
+    RegionInit() is a most peculiar API!
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d98b41ce4323b43d2359349a04a4a56559e341a2
+Author: Zhigang Gong <zhigang.gong@linux.intel.com>
+Date:   Fri Feb 17 19:50:52 2012 +0800
+
+    uxa/glamor/dri: Should fixup the drawable pixmap.
+    
+    Two fixes in this commit, first we only need to check the
+    front left buffer, for other attachment we don't need to
+    check them. The second is, we should fixup the pixmap's
+    drawable not the original drawable.
+    
+    Signed-off-by: Zhigang Gong <zhigang.gong@linux.intel.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1e0d702c3a77f6db3dfd55b8cafc5fca4d778751
+Author: Zhigang Gong <zhigang.gong@linux.intel.com>
+Date:   Fri Feb 17 19:50:51 2012 +0800
+
+    uxa/glamor/dri: Enable the pageflip support on glamor.
+    
+    To support easy buffer exchange at glamor layer, glamor
+    added a new API glamor_egl_exchange_buffers() to exchange
+    two pixmaps' EGL image and fbos and textures without
+    recreating any of them. But this simple method's requirement
+    is that there are two pixmaps. A exceptional case is:
+    If we are using triple buffer when do page flipping, we
+    will have an extra back_buffer which doesn't have a pixmap
+    attached to it. Then each time we set that buffer to a
+    pixmap, we will have to call the create_egl_textured_pixmap
+    to create the corresponding EGL image and fbo and texture
+    for it. This is not efficient.
+    
+    To fix this issue, this commit introduces a new back_pixmap
+    to intel structure to hold the back buffer and corresponding
+    glamor resources. Then we will just need to do the light
+    weight buffer exchanging at both DDX and glamor layer.
+    
+    As the new back pixmap is similar to the screen pixmap
+    and need to be handled carefully when close screen. As the
+    glamor data structure is a per screen data, and will be
+    released at its close screen method. The glamor's close
+    screen method must cleanup the screen pixmap and back
+    pixmap's glamor resources. screen pixmap is easy to get,
+    but there is no good way to store the back pixmap.
+    
+    So the glamor add a new API glamor_egl_create_textured_screen_ext
+    function to pass the back pixmap's pointer to glamor layer.
+    
+    This commit make us depend on glamor commit: 4e58c4f.
+    And we increased the required glamor version from 0.3.0 to 0.3.1
+    
+    Signed-off-by: Zhigang Gong <zhigang.gong@linux.intel.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ce7a57994d662f340b9457a2750e4385e7d669cd
+Author: Zhigang Gong <zhigang.gong@linux.intel.com>
+Date:   Fri Feb 17 19:50:50 2012 +0800
+
+    uxa/dri: Refine the pageflip processing.
+    
+    Add a new element back_name to intel structure to track
+    the back bo's name then avoid flink every time.
+    And at function I830DRI2ExchangeBuffers, after finish
+    the BO exchange between info's front and back pixmap,
+    it set the new front bo to the screen pixmap. But the
+    screen pixmap should be the same as front's pixmap,
+    so this is a duplicate operation and can be removed.
+    
+    Signed-off-by: Zhigang Gong <zhigang.gong@linux.intel.com>
+
+commit 1a65e2b8a2ebfb4d736efb7631515babad75faf2
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Feb 21 08:09:52 2012 +0000
+
+    sna: Split up/down edge walking in order to handle endpoint clipping
+    
+    In order to prevent walking upwards off the top of the pixmap when
+    rendering a clipped vertical edge, we need to tweak the boundary
+    conditions for the vertical edge walker.
+    
+    Reported-by: Clemens Eisserer <linuxhippy@gmail.com>
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=46261
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7ea44997553ffdf57b346dc9d83742c511c9e5a4
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Feb 20 23:50:42 2012 +0000
+
+    sna: Restore the shadow pixels when reducing CPU damage to all
+    
+    Reported-by: Joe Nahmias <joe@nahmias.net>
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=46346
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit dbe0580e207ad85cb6a659f86c5746a7ecbcd036
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Feb 20 16:30:53 2012 +0000
+
+    sna: gen4+ suffer no penalty for changing tiling
+    
+    On gen4, the tiling/fence constraints are fairly lax, only requiring
+    page alignment of the object and its size, and so we can switch
+    tiling modes without incurring a GPU stall on active bo.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b68b76cf54a322e80685f1ec93538cd6c5813ea4
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Feb 20 13:38:11 2012 +0000
+
+    sna: Move sync'ing of CPU bo after allocation to first write
+    
+    The idea was that we could afford to allocate an active CPU bo for
+    copying to from using the GPU and later sync just before we need to
+    write to the shadow pixels. Having the sync inside the allocation
+    function potentially causes an unwanted stall.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit bbb6794a3b97b1fcf72c8712ab0ec591683b128b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Feb 20 12:25:31 2012 +0000
+
+    sna: Trim clipped lines to end within bounds
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=46261
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=45673
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 805bc3310cd0a13eab8e48e7615bdd42638cfa33
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Feb 20 12:09:19 2012 +0000
+
+    sna: When reversing line-drawing direction, use the clipped endpoint
+    
+    Make sure we take the clipping into account if we choose to reverse the
+    draw direction (to maintain left-to-right inside the box emission).
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=46261
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=45673
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7f0a4a5f7224003a0cd226137de5a068949a41b4
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Feb 20 09:52:37 2012 +0000
+
+    sna/dri: Ensure the domain tracking is reset when releasing bo used for swaps
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7d147c7462ba183f5316e7e8dafeca62add6f97c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Feb 19 17:50:56 2012 +0000
+
+    sna: Correct tile sizes for Y-tiling on i915g
+    
+    128-byte Y-tiling wasn't introduced until the 945.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 95391b7312147760d8da01fce68b8398aa8e4e2f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Feb 16 22:01:41 2012 +0000
+
+    sna/trapezoids: Presume that Precise mono rasterisation adheres to the spec
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=46156
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 52b11f63d7922032caef0f0a5979b080dbddcbfc
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Feb 16 11:22:23 2012 +0000
+
+    sna: Upconvert fallback trapezoids to a8
+    
+    Since the hardware only handles a8 without tricky emulation and pixman
+    insists on using a1 for sharp trapezoids we need to ensure that we
+    convert the a1 to a8 for our trapezoidal mask.
+    
+    More worryingly, this path should never be hit...
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=46156
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8050ced6204f5aca12e6c57f86308b6ad1b98209
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Feb 15 17:01:18 2012 +0000
+
+    sna/dri: Mark bo as reusable after completion of a flip-event
+    
+    After the flip chain is completed, any residual buffers are no longer in
+    use and so available for reuse.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fc046aabde76142fce130773d78d797d7d750ab7
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Feb 15 16:08:23 2012 +0000
+
+    sna/dri: Don't attempt to change tiling if it is a no-op
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 66cc9c69657ac2703f2c7fc3c2c50f06bf5daa99
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Feb 15 11:58:42 2012 +0000
+
+    Be paranoid about the definition of container_of
+    
+    Replace any existing definition with a correct version, since there are
+    broken container_of macros floating around the xorg includes.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c0376b7f7b083ab2e87edc36e56fd8eb99c3cd05
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Feb 13 00:48:15 2012 +0000
+
+    Add a missing macro for old xorg/list.h
+    
+    list_last_entry() needs to be defined if we are including the xorg
+    list.h as opposed to our standalone variant.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 87bed52180cd2abd80ef6b58384f9fd9c9968f7b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Feb 11 20:54:18 2012 +0000
+
+    Include a local copy of list.h
+    
+    In 1.11.903, the list.h was renamed to xorg-list.h with a corresponding
+    change to all structures. As we carried local fixes to list.h and
+    extended functionality, just create our own list.h with a bit of
+    handwaving to protect us for the brief existence of xorg/include/list.h.
+    
+    Reported-by: Armin K <krejzi@email.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=45938
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c64ebee5fdccf313cbd3c73850e02e6fa7dd2a65
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Feb 11 13:31:12 2012 +0000
+
+    sna/gen6: Prefer the render ring for copies
+    
+    Slower for fills, but on the current stack faster for copies, both large
+    and small. Hopefully, when we write some good shaders for SNB, we will
+    not only improve performance for copies but also make fills faster on
+    the render ring than the blt?
+    
+    As the BLT copy routine is GPU bound for copywinpix10, and the RENDER
+    copy routine is CPU bound and faster, I believe that we have reached the
+    potential of the BLT ring and not yet saturated the GPU using the render
+    copy.
+    
+    Note that we still do not casually switch rings, so the actual routine
+    chosen will still be selected by the preceeding operations, so is
+    unlikely to have any effect in practice during, for example, cairo-traces.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6a9b50177408c919ed5c6c2463f687476af2c698
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Feb 11 11:02:53 2012 +0000
+
+    sna/gen6: Suppress the CS stall for the first command in the batch
+    
+    The batch emission serves as a full stall, so we do not need to incur a
+    second before our first rendering.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit cbe8bed83f0b4097958c4541ad7809a05e6c6f43
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Feb 11 10:58:05 2012 +0000
+
+    sna/gen7: Mention the depth-stall required before changing VS state
+    
+    Because one day we may actually start using VS! Copied from the addition
+    of the w/a to Mesa by Kenneth Graunke.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6193f2f00fa7205f9d736340318c66d116dca53e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Feb 9 14:16:17 2012 +0000
+
+    sna: Fix retire after readback
+    
+    Upon reading, we encounter a serialisation point and so can retire all
+    requests. However, kgem_bo_retire() wasn't correctly detecting that
+    barrier and so we continued to using GPU detiling thinking the target
+    was still busy.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4d8369f8e60fd4f5a0ef49f3e9866ea5ecb21927
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Feb 8 13:15:46 2012 +0000
+
+    sna/gen2+: Force upload rather than perform source transformations on the CPU
+    
+    If both the source and destination is on the CPU, then the thinking was
+    it would be quicker to operate on those on the CPU rather than copy both
+    to the GPU and then perform the operation. This turns out to be a false
+    assumption if transformation is involved -- something to be reconsidered
+    if pixman should ever be improved.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8634d461bd9e5a3d3f75b0efc11db87b8d3e1245
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Feb 8 09:13:27 2012 +0000
+
+    sna: Limit max CPU bo size to prevent aperture thrashing on upload
+    
+    Copying between two objects that consume more than the available GATT
+    space is a painful experience due to the forced use of an intermediatory
+    and eviction on every batch. The tiled upload paths are in comparison
+    remarkably efficient, so favour their use when handling extremely large
+    buffers.
+    
+    This reverses the previous idea in that we now prefer large GPU bo
+    rather than large CPU bo, as the render pipeline is far more flexible
+    for handling those than the blitter is for handling the CPU bo (at least
+    for gen4+).
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5b16972d7850b2347efc084311d664e14263cba1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Feb 7 23:45:37 2012 +0000
+
+    sna: Check that we successfully retired an active linear buffer
+    
+    If we go to the trouble of running retire before searching, we may as
+    well check that we retired something before proceeding to check all the
+    inactive lists.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 207b4d4482a6af4a39472ec20ff04fa0c9322d73
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Feb 7 21:56:29 2012 +0000
+
+    sna: Relax must-be-blittable rules for gen4+
+    
+    The render pipeline is actually more flexible than the blitter for
+    dealing with large surfaces and so the BLT is no longer the limiting
+    factor on gen4+.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 13c960db9ef876ee99991d97dfc34fef184c0341
+Author: Zhigang Gong <zhigang.gong@linux.intel.com>
+Date:   Thu Feb 2 11:30:57 2012 +0800
+
+    uxa/glamor: Use a macro to specify module name.
+    
+    This depends upon glamor commit b5f8d, just after the 0.3.0 tag.
+    
+    Signed-off-by: Zhigang Gong <zhigang.gong@linux.intel.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 70092bfbc51ddc5a51c9cae21c6b2852c216a6fc
+Author: Zhigang Gong <zhigang.gong@linux.intel.com>
+Date:   Wed Feb 1 19:47:28 2012 +0800
+
+    uxa/glamor: Refine CloseScreen and InitScreen process.
+    
+    The previous version calls glamor_egl_close_screen and
+    glamor_egl_free_screen manually which is not align with
+    standard process. Now glamor change the way to follow
+    standard method:
+    
+    glamor layer and glamor egl layer both have their internal
+    CloseScreens. The correct sequence is after the I830CloseScreen
+    is registered, then register glamor_egl_close_screen and
+    the last one is glamor_close_screen. So we move out the
+    intel_glamor_init from the intel_uxa_init to I830ScreenInit
+    and just after the registration of I830CloseScreen.
+    
+    As the glamor interfaces changed, we need to check the
+    glamor version when load the glamor egl module to make
+    sure we are loading the right glamor module. If
+    failed, it will switch back to UXA path.
+    
+    This depends upon glamor commit 1bc8bf tagged with version 0.3.0.
+    
+    Signed-off-by: Zhigang Gong <zhigang.gong@linux.intel.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 798aad6c95a1a95fd587430dc7a6d59497a10ce1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Feb 7 20:16:48 2012 +0000
+
+    sna/gen[4-7]: Fix erroneous scale factor for partial large bo render copies
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ea6588726107f1ab0ef5a8f69d420b5bff819a76
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Feb 7 15:26:50 2012 +0000
+
+    sna: Apply offsets correctly for partial src/dst in large copy boxes
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 14c91e108464a305fb23b3313b842bfaeb9420fc
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Feb 7 15:25:48 2012 +0000
+
+    sna/tiling: Request Y-tiles if we know we cannot BLT to either the src or dst
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3131217e3ecbdf6cd40b044bd31e8228ff5c6bff
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Feb 7 14:35:59 2012 +0000
+
+    sna: Mark up the temporary allocations
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ec1ccb6bf6a984cbe3317e636d7ff73887348a46
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Feb 7 13:37:52 2012 +0000
+
+    sna: Set the damage for render->copy_boxes to NULL before use
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 58f634b792c6d109c5f2374a3e24d759e744abb4
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Feb 7 13:32:20 2012 +0000
+
+    sna: Handle tile alignment for untiled large bo more carefully
+    
+    We ended up trying to align the upper bound to zero as the integer
+    divsion of the tile width by pixel was zero.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit bf3518ea910a2a3c5b4500dcba7c829576fbfd47
+Author: Zhigang Gong <zhigang.gong@linux.intel.com>
+Date:   Tue Feb 7 09:40:54 2012 +0800
+
+    uxa/glamor/dri: Fix a typo bug when fixup glamor pixmap.
+    
+    Should modify the old pixmap's header not the new one which
+    was already destroyed.
+    
+    Signed-off-by: Zhigang Gong <zhigang.gong@linux.intel.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1467a4ba1a327877026cc76b3eabeb51d1415509
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Feb 6 20:41:53 2012 +0000
+
+    sna: Use the proper sna_picture_is_solid() test
+    
+    Rather than the specialised routines that assumed pDrawable was
+    non-NULL, which was no longer true after f30be6f743.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ef335a65a9d9f7eb96873201b546c25fd03d090c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Feb 6 20:37:54 2012 +0000
+
+    sna: Search all active buckets for a temporary allocation
+    
+    Reduce the need for creating a new object if we only need the allocation
+    for a single operation.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b7e3aaf773f05ce82405e135c0f99b40b3c2f434
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Feb 6 18:08:19 2012 +0000
+
+    sna: Use the clipped end-point for recomputing segment length after clipping
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=45673
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f30be6f74392f5687ffe8bc9dd2c6dc024ae06c8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Feb 6 15:59:21 2012 +0000
+
+    sna/gen2+: Exclude solids from being classed as requiring an upload
+    
+    We treat any pixmap that is not attached to either a CPU or GPU bo as
+    requiring the pixel data to be uploaded to the GPU before we can
+    composite. Normally this is true, except for the solid cache.
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=45672
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f009386de87acccadb1803567e4c494e5e80a2a9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Feb 6 09:50:03 2012 +0000
+
+    sna: If we have a CPU bo, do not assert we have shadow pixels
+    
+    When transferring damage to the GPU, on SNB it is not necessarily true
+    that we have a shadow pixmap, we may instead have drawn onto an unmapped
+    CPU bo and now simply need to copy from that bo onto the GPU. Move the
+    assertion onto the path where it truly matters.
+    
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=45672
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 22e452ebe01c32a08599411743cf18f9ad0545a7
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Feb 6 09:19:56 2012 +0000
+
+    sna: Disable use of xvmc for SNB+
+    
+    Not yet implemented, so don't bother setting it to fail.
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=44874
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a8ed1a02ada1f8d2f910dfefb150d26c840bf9ea
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Feb 4 20:13:07 2012 +0000
+
+    sna: Discard the redundant clear of the unbounded area if already clear
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b899a4b69696141ca8b897a7abf52649b09f7b3b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Feb 4 20:07:49 2012 +0000
+
+    sna: Always pass the clear colour for PictOpClear
+    
+    Having made that optimisation for Composite, and then made the
+    assumption that it is always true in the backends, we failed to clear
+    the unbounded area outside of a trapezoid since we passed in the
+    original colour and the operation was optimised as a continuation.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c107b90a44abb45c837ff8924939872be5b490eb
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Feb 4 16:33:34 2012 +0000
+
+    sna/gen6: Reduce PictOpClear to PictOpSrc (with blending disabled)
+    
+    The advantage of PictOpSrc is that it writes its results directly to
+    memory bypassing the blend unit.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4baa2806bc0f51e7576b769ca6750deb3821c4d3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Feb 4 12:06:22 2012 +0000
+
+    sna: Check if the damage reduces to all before performing the migration
+    
+    An assert exposed a situation where we had accumulated an unreduced
+    damage-all and so we were taking the slow path only to discover later
+    that it was a damage-all and that we had performed needless checks.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2653524dffc1fe0dbff7d74bfc9be535d9ececb1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Feb 3 20:06:43 2012 +0000
+
+    sna: Reduce the downsample tile size to accommodate alignment
+    
+    If we need to enlarge the sampled tile due to tiling alignments, the
+    resulting sample can become larger than we can accommodate through the 3D
+    pipeline, resulting in FAIL.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 93a0b10f163ee79b6a6a7ea46b0a33b622b1f86e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Feb 3 19:30:24 2012 +0000
+
+    sna: Apply redirection for the render copy into large pixmaps
+    
+    If the pixmap is larger than the pipeline, but the operation extents fit
+    within the pipeline, we may be able to create a proxy target to
+    transform the operation into one that fits within the constraints of the
+    render pipeline.
+    
+    This fixes the infinite recursion hit with partially displayed extremely
+    large images.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4774c6b8331831e0c9f3b24f5f6e1b6ea399f628
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Feb 2 15:23:03 2012 +0000
+
+    sna: Add a couple of sanity checks that the CPU drawable is on the CPU
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 418cd98db7c4a2886c9e310f3691eb6c77421dd7
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Feb 1 19:10:41 2012 +0000
+
+    sna/gen6: Ring switching outweighs the benefits for cairo-traces
+    
+    At the moment, the jury is still out on whether freely switching rings
+    for fills is a Good Idea. So make it easier to turn it on and off for
+    testing.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2d0e7c7ecd7371ac7b5fe3f382fc5d04792f7019
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Feb 1 14:52:56 2012 +0000
+
+    sna: Search again for a just-large-enough mapping for inplace uploads
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 55c7088f54655609fbb00106679a566b46ee8dba
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Feb 1 01:33:52 2012 +0000
+
+    sna: Add debugging code to verify damage extents of fallback paths
+    
+    After using the CPU, upload the damage and read back the pixels from the
+    GPU bo and verify that the two are equivalent.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c8fc2cde53ef7aa011ec7c47e7fc5486de0651f5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Feb 1 01:27:43 2012 +0000
+
+    sna: Fill extents for ImageGlyphs
+    
+    The spec says to fill the characters boxes, which is what the hardware
+    does. The implementation fills the extents instead. rxvt expects the
+    former, emacs the latter. Overdraw is a nuisance, but less than leaving
+    glyphs behind...
+    
+    Reported-by: walch.martin@web.de
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=45438
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 13508ab5ea136caca90c846ff1026c0c1acd2ad5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 31 22:38:46 2012 +0000
+
+    sna: PolyGlyph supports all of fill/tile/stipple rules
+    
+    The hw routines only directly supports solid fill so fallback for the
+    interesting cases. An alternative would be to investigate using the
+    miPolyGlyph routine to convert the weird fills into spans in order to
+    fallback. Sounds cheaper to fallback, so wait for an actual use case.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit df4e1059a4e09998334dde6aa1c8ccfe76e442c0
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 31 19:19:13 2012 +0000
+
+    sna/gen6: Prefer to do fills using the BLT
+    
+    Using the BLT is substantially faster than the current shaders for solid
+    fill. The downside is that it invokes more ring switching.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8b012de0a1af4ec97c3197af3f1efdcc67bc2118
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 31 20:29:58 2012 +0000
+
+    sna/gen5: Always prefer to emit solid fills using the BLT
+    
+    As the BLT is far, far faster than using a shader.
+    
+    Improves cairo-demos/chart from 6 to 13 fps.
+    
+    Reported-by: Michael Larabel <Michael@phoronix.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0a748fc49d60dc2bc9494f95c4934592b111831a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 31 10:51:02 2012 +0000
+
+    sna: Split the tiling limits between upload and copying
+    
+    The kernel has a bug that prevents pwriting buffers large than the
+    aperture. Whilst waiting for the fix, limit the upload where possible to
+    fit within that constraint.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9c1f8a768ca1f762c722f63bab2747e4ff1fd773
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 31 10:29:02 2012 +0000
+
+    sna: Avoid converting requested Y to X tiling for large pitches on gen4+
+    
+    The only strong requirement is that to utilize large pitches, the object
+    must be tiled. Having it as X tiling is a pure convenience to facilitate
+    use of the blitter. A DRI client may want to keep using Y tiling
+    instead.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e872c1011fc7b67683703fd891234f07dd7acd04
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 31 10:21:05 2012 +0000
+
+    sna/dri: We need to reduce tiling on older gen if we cannot fence
+    
+    Only apply the architectural limits to enable bo creation for DRI buffers.
+    
+    Reported-by: Alban Browaeys <prahal@yahoo.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=45414
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a4caf67d8da37d04f8915d96b10411ba7267937e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 31 00:35:42 2012 +0000
+
+    sna: Trim tile sizes to fit into bo cache
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3f7c1646c78d8854c88b214d3699e51839ba9711
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 31 00:09:42 2012 +0000
+
+    sna: Check that the intermediate IO buffer can also be used for blitting
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e504fab6c5354ae9d18ccefb10bd586fa49b924c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jan 30 23:49:18 2012 +0000
+
+    sna: Discard the cleared GPU buffer upon PutImage to the CPU buffer
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ed1c1a7468d78e99cb4f9a4a8b8a6b00c3257a75
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jan 30 13:43:59 2012 +0000
+
+    sna: Track large objects and limit prefer-gpu hint to small objects
+    
+    As the GATT is irrespective of actual RAM size, we need to be careful
+    not to be too generous when allocating GPU bo and their shadows. So
+    first of all we limit default render targets to those small enough to
+    fit comfortably in RAM alongside others, and secondly we try to only
+    keep a single copy of large objects in memory.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d53d93ffa6e133f46c39595294ecf8e2182b5a68
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jan 30 15:11:34 2012 +0000
+
+    sna: Update the partial buffer allocation size when reusing an old mapping
+    
+    Whilst the old mapping is guaranteed to be larger than the requested
+    allocation size, keep track of the actual size allows for better packing
+    of future buffers. And the code also performs a sanity check that the
+    buffer is the size we claim it to be...
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6f99555b6b64a0e1baad1853569f7bf521c327c3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jan 30 11:48:59 2012 +0000
+
+    sna: Allow the creation of render targets larger than the maximum bo cache
+    
+    Given that we now handle uploads to and from bo that are larger than the
+    aperture and that usage of such large bo is rare and so unlikely to
+    benefit from caching, allow them to be created as render targets and
+    destroy as soon as they become inactive.
+    
+    In principle, this finally enables GPU acceleration of ocitysmap on gen4+,
+    but due to the large cost of creating and destroying large bo it is
+    disabled on systems that require clflushing. It is, however, a
+    pre-requisite for exploiting the enhanced capabilities of IvyBridge.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c65ec096e79aa6bda7b2b3ef235e3fd9698b4da7
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jan 30 11:41:07 2012 +0000
+
+    sna: Decrease tiling step size in case we need to enlarge the box later
+    
+    We can juggle rendering into large bo on gen4 by redirecting the
+    rendering through a proxy that is tile aligned, and so the render target
+    may be slightly larger than the tiling step size. As that is then larger
+    than the maximum 3D pipeline, the trick fails and we need to resort to a
+    temporary render target with copies in and out. In this case, check that
+    the tile is aligned to the most pessimistic tiling width and reduce the
+    step size to accomodate the enlargement.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 95f3734dd69b82e007095a599cc21f4c63d6ec00
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jan 30 11:40:02 2012 +0000
+
+    sna: Allow creation of proxies to proxies
+    
+    Just update the offset of the new bo by the offset of the existing
+    proxy.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 488937edb67a60389380b405f8f8a548f51e64c7
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jan 30 11:38:36 2012 +0000
+
+    sna: Base prefer-gpu hint on default tiling choice
+    
+    As on gen4+, tiling increases the maximum usable pitch we can
+    accommodate wider pixmaps on the GPU.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ca252e5b51d7b2f5a7b2c2e0d8fdb024b08096db
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jan 29 19:36:55 2012 +0000
+
+    sna: Detect batch overflow and fallback rather an risk an ENOSPC
+    
+    Having noticed that eog was failing to perform a 8k x 8k copy with
+    compiz running on a 965gm, it was time the checks for batch overflow
+    were implemented.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3aee521bf236994628c4d103a2b8f391a4be2aa7
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jan 29 19:21:54 2012 +0000
+
+    sna: Add a tiled fallback for large BLT copies
+    
+    If we are attempting to copy between two large bo, larger than we can
+    fit into the aperture, break the copy into smaller steps and use an
+    intermediatory.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit df148c962108a7f3efead0b80ab4fe77f3f79c8b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jan 29 18:07:14 2012 +0000
+
+    sna: Limit the tile size for uploading into large pixmaps
+    
+    As we may have a constrained aperture, we need to be careful not to
+    exceed our resources limits when uploading the pixel data. (For example,
+    fitting two of the maximum bo into a single batch may fail due to
+    fragmentation of the GATT.) So be cautious and use more tiles to reduce
+    the size of each individual batch.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e1e67e8f394480eb4fef1238ccfd49cc36e4b6f2
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jan 29 15:43:42 2012 +0000
+
+    sna: Fix the "trivial" fix to improve error handling
+    
+    The logic was just backwards and we tried to upload a shadowless GPU
+    pixmap.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d3fb1e1e89ccf5cefe6add66de4f960ef07cac60
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jan 29 14:20:33 2012 +0000
+
+    sna: Handle GPU creation failure when uploading subtexture
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 518a99ea34b26aa094f29a4cc1ea5419f63a0e56
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jan 29 14:09:46 2012 +0000
+
+    sna: Always create a GPU bo for copying from an existent source GPU bo
+    
+    Make sure we prevent the readback of an active source GPU bo by always
+    prefering to do the copy on the GPU if the data is already resisent.
+    This fixes the second regression from e583af9cc, (sna: Experiment with
+    creating large objects as CPU bo).
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 624d9843abda9ca6bd1b004d70a6fdc082ba9653
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jan 29 13:55:20 2012 +0000
+
+    sna: Ignore map status and pick the first inactive bo for reuse
+    
+    This fixes the performance regression introduced with e583af9cca,
+    (sna: Experiment with creating large objects as CPU bo), as we ended up
+    creating fresh bo and incurring setup and thrashing overhead, when we
+    already had plenty cached.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5c6255ba2f12f04938fd586ca02562ee3cae05af
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jan 29 11:02:38 2012 +0000
+
+    sna: Determine whether to use a partial proxy based on the pitch
+    
+    On gen4+ devices the maximum render pitch is much larger than is simply
+    required for the maximum coordinates. This makes it possible to use
+    proxy textures as a subimage into the oversized texture without having
+    to blit into a temporary copy for virtually every single bo we use.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 65466f86263b3788b438fe021a12ade371190b01
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jan 28 01:54:47 2012 +0000
+
+    sna: Allow ridiculously large bo, up to half the total GATT
+    
+    Such large bo place extreme stress on the system, for example trying to
+    mmap a 1GiB into the CPU domain currently fails due to a kernel bug. :(
+    So if you can avoid the swap thrashing during the upload, the ddx can now
+    handle 16k x 16k images on gen4+ on the GPU. That is fine until you want
+    two such images...
+    
+    The real complication comes in uploading (and downloading) from such
+    large textures as they are too large for a single operation with
+    automatic detiling via either the BLT or the RENDER ring. We could do
+    manual tiling/switching or, as this patch does, tile the transfer in
+    chunks small enough to fit into either pipeline.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 03211f4b0b7e32b6d7dc28e60be72db204b8c8d4
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jan 27 23:18:05 2012 +0000
+
+    sna: Guard against the upload buffer growing past the maximum bo size
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2afd49a28429cdeb36583cfc31cc9b1742c1fb83
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jan 27 22:18:30 2012 +0000
+
+    sna: Limit inplace upload buffers to maximum mappable size
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=45323
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8f4bae01e39392faa8978090db4cbe28fa00b013
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jan 27 20:28:44 2012 +0000
+
+    sna/video: Ensure the video pixmap is on the GPU
+    
+    The presumption that the pixmap is the scanout and so will always be
+    pinned is false if there is a shadow or under a compositor. In those
+    cases, the pixmap may be idle and so the GPU bo reaped. This was
+    compounded by that the video path did not mark the pixmap as busy. So
+    whilst watching a video under xfce4 with compositing enabled (has to be
+    a non-GL compositor) the video would suddenly stall.
+    
+    Reported-by: Paul Neumann <paul104x@yahoo.de>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=45279
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d02bd80b2f9f8ee3840be5d8d6b8d389192c57f5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jan 27 20:12:49 2012 +0000
+
+    sna: Use a proxy rather than a temporary bo for too-tall but thin targets
+    
+    If the render target is thin enough to fit within the 3D pipeline, but is
+    too tall, we can fudge the address of the origin and coordinates to fit
+    within the constaints of the pipeline.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ea433995a37f0a9d1579f74029418f22a63a2bc0
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jan 27 19:34:39 2012 +0000
+
+    sna: Experiment with a partial source
+    
+    If the source is thin enough such that the pitch is within the sampler's
+    constraints and the sample size is small enough, just fudge the origin
+    of the bo such that it can be sampled.
+    
+    This avoids having to create a temporary bo and use the BLT to extract
+    it and helps, for example, firefox-asteroids which uses an 64x11200
+    texture atlas.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ad910949beb0c42e2d7b864f030b055ca40adacd
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jan 27 18:37:39 2012 +0000
+
+    sna: Mark diagonal lines as partial write
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b9c83e0b2c42f7657b1854a7cdcbc0407957c382
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jan 27 18:24:01 2012 +0000
+
+    sna/video: Add some DBG messages to track the error paths
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=45279
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 45d831c8b11d6f9f38c0cb9b5877541a971f2c67
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jan 27 15:45:17 2012 +0000
+
+    sna: Consolidate routines to choice destination bo
+    
+    Combine the two very similar routines that decided if we should render
+    into the GPU bo, CPU bo or shadow pixmap into a single function.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6402e7f1195f60f96dc269a701532c3270d8920f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jan 27 18:05:51 2012 +0000
+
+    sna: Ensure that we have a source bo for tiled fills
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6c5fb84f4de346b06e5a538e683c5a118f2579bc
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jan 27 14:08:57 2012 +0000
+
+    sna/glyphs: Check that we attached to the cache pixmaps upon creation
+    
+    If the hw is wedged, then the pixmap creation routines will return an
+    ordinary unattached pixmap. The code presumed that it would only return
+    a pixmap with an attached bo, and so would segfault as it chased the
+    invalid pointer after a GPU hang and the server was restarted.
+    Considering that we already checked that the GPU wasn't wedged before we
+    started, this is just mild paranoia, but on a run-once piece of code.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 86f1ae9164a94323c08e1dc6cb301e5bc1126b10
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jan 27 10:26:11 2012 +0000
+
+    sna/video: Add some more DBG breadcrumbs to the textured PutImage
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ce1cae7f4715fc8e14327c5b705d9f2cc45a3741
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jan 27 00:37:51 2012 +0000
+
+    sna/video: Simplify the gen2/915gm check
+    
+    And make the later check in put image match.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 541908524f9ee754db3bc45d2e1681d34479c1cc
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 26 23:14:14 2012 +0000
+
+    sna: Remove extraneous clipping from GetImage
+    
+    The spec says that they must wholly contained with the valid BorderClip
+    for a Window or within the Pixmap or else a BadMatch is thrown. Rely on
+    this behaviour and not perform the clipping ourselves.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7ff40b572ec5cd860d7c7ff23beca0388f37c31c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 26 22:55:04 2012 +0000
+
+    sna: Avoid fbBlt for the easy GetImage cases
+    
+    From (i5-2520m):
+      60000 trep @   0.6145 msec (  1630.0/sec): GetImage 500x500 square
+    To:
+      60000 trep @   0.4949 msec (  2020.0/sec): GetImage 500x500 square
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit adb1320bba15a3a3b4fa8e7d0fd0360fa696721d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 26 16:05:48 2012 +0000
+
+    sna/gen2+: Include being unattached in the list of source fallbacks
+    
+    If the source is not attached to a buffer (be it a GPU bo or a CPU bo),
+    a temporary upload buffer would be required and so it is not worth
+    forcing the target to the destination in that case (should the target
+    not be on the GPU already).
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b1f9415bf355e9fbd6fc3ce8fa1af59083ca2943
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 26 13:59:24 2012 +0000
+
+    sna: Allow gen4+ to use larger GPU bo
+    
+    As the blitter on gen4+ does not require fence registers, it is not
+    restricted to operating on large objects within the mappable aperture.
+    As we do not need to operate on such large GPU bo in place, we can relax
+    the restriction on the maximum bo size for gen4+ to allocate for use
+    with the GPU.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d35b6955dbb5d652d8685d2c1ea82c5e08de55ea
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 26 14:34:36 2012 +0000
+
+    sna: Prevent mapping through the GTT for large bo
+    
+    If the bo is larger than a quarter of the aperture, it is unlikely that
+    we will be able to evict enough contiguous space in the GATT to
+    accommodate that buffer. So don't attempt to map them and use the
+    indirect access instead.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7c81bcd0c425cc0f7ddf2ad8289bb739c8d44289
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 26 13:35:15 2012 +0000
+
+    sna: Add FORCE_FALLBACK debugging hook for PutImage
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 35c0ef586bf508c577642d772f18eae0b64cfd44
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 26 11:20:03 2012 +0000
+
+    sna/gen3: Use cpu bo if already in use
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b76a6da3fa0148ef32600dd9505e22b90de037df
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 26 10:47:01 2012 +0000
+
+    sna: Search the buckets above the desired size in the bo cache
+    
+    It is preferrable to reuse a slightly larger bo, than it is to create a
+    fresh one and map it into the aperture. So search the bucket above us as
+    well.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e2b8b1c145932e2254a705905c60f18c200cf2e8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 26 12:42:12 2012 +0000
+
+    sna: Apply any previous transformation when downsampling
+    
+    In order to handle rotations and fractional offsets produced by the act
+    of downsampling, we need to compute the full affine transformation and
+    apply it to the vertices rather than attempt to fudge it with an integer
+    offset.
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=45086
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 352828ee59164a9e81093d88dfdd45bc21f0c739
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 26 12:41:34 2012 +0000
+
+    sna: Tweak aperture thresholds for batch flushing
+    
+    In order to more easily accommodate operations on large source CPU bo.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit cff6a1a2e4648eb211a1789ae9f711e2f16e9d4d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 25 23:21:36 2012 +0000
+
+    sna: Use the cpu bo where possible as the source for texture extraction
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e583af9cca4ad2e5643317447c6b065d3ee7d11e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 25 23:04:50 2012 +0000
+
+    sna: Experiment with creating large objects as CPU bo
+    
+    Even on non-LLC systems if we can prevent the migration of such
+    objects, we can still benefit immensely from being able to map them into
+    the GTT as required.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 55569272f7d4232ef50f7b964dda82f85a190b99
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 25 20:13:27 2012 +0000
+
+    sna: Apply the same migration flags for the dst alphamap as for the dst pixmap
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4a132ddbf06e5ffc364c25002a1e46ad8bf0e45a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 25 20:12:55 2012 +0000
+
+    sna: Correct offset for moving drawable regions to the CPU
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 65164d90b7b17ec7eea1e24d4b02ec037b55b1ff
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 25 20:12:27 2012 +0000
+
+    sna/gen2+: Do not force use of GPU if the target is simply cleared
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 307f493d76580687a3cf56106bf296475f1f53e5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 25 20:11:21 2012 +0000
+
+    sna: Map freshly created, unbound bo through the CPU
+    
+    Take advantage that we know we will have to clflush the unbound bo
+    before use by the GPU and populate it inplace.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d785bb7df054a1f15d59db69b089deb743bbdb40
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 25 16:45:43 2012 +0000
+
+    sna: GetImage is allowed to read a window's border
+    
+    We need to adjust the clip to include the border pixels when migrating
+    damage from the backing pixmap. This also requires relaxing the
+    constraint that a read must be within the drawable.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 36425ba49ecbd87b1e3bf4340ca2496d8de24a7f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 25 12:49:24 2012 +0000
+
+    sna: Round up buffer allocations when downsampling
+    
+    The pathological case being nx1 or 1xm resulting in an illegal allocation
+    request of 0 bytes.
+    
+    One such example is
+      wolframalpha.com: x = (200 + x) / 100
+    which generates an approximately 8500x1 image and so needs downscaling
+    to fit in the render pipeline on all but IvyBridge. Bring on Ivy!
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a2e83c6dcba1e911f42a3004b3d0782049e243e2
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 25 11:22:38 2012 +0000
+
+    sna: Silence compiler warning for a potential uninitialised return on error
+    
+    sna_accel.c: In function 'sna_copy_plane':
+    sna_accel.c:5022:21: warning: 'ret' may be used uninitialized in this
+    function [-Wuninitialized]
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8d22a76506133e0f76424159c0944d29bdf39da9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 25 09:36:20 2012 +0000
+
+    sna: Run the miHandleExposures for no-op CopyPlane
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 338941eda3c7591a85b83000eafae0407d0d7cd0
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 25 02:42:25 2012 +0000
+
+    sna: Handle self-copies for CopyPlane
+    
+    Prepare the source first as this has the dual benefit of letting us
+    decide how best to proceed with the op (on the CPU or GPU) and prevents
+    modification of the damage after we have choosen our preferred path.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2e8b398ca383f5292adab8b351b8837dde3e131a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 25 01:42:56 2012 +0000
+
+    sna: Only shrink partial buffers that are being written to
+    
+    Ignore inactive and mmapped buffers.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b79252efaafe2ebc998d6cf6176a425dd897e66f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 25 01:36:27 2012 +0000
+
+    sna: Apply source clipping to sna_copy_plane()
+    
+    Ensure that the migration region is within bounds for both the source
+    and destination pixmaps.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 46252bc7bcc7e08e47d00cdc87d6c1ed93830fcc
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 25 01:31:34 2012 +0000
+
+    sna: Set the source clip for CopyArea fallback correctly
+    
+    The source window is (src->x, src->y)x(src->width, src->height) in
+    pixmap space. However, we then need to use this to clip against the
+    desination region, and so we need to translate from the source
+    coordinate to the destination coordinate.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ae6d3a311783d7e063de0347363331f14bd74d74
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 25 01:18:11 2012 +0000
+
+    sna: Print source and destination regions for CopyArea fallback for DBG
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit dd5e90adfc73870cebcb215ad9fb9b5aedd38673
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 25 01:17:49 2012 +0000
+
+    sna: Clip GetImage to drawable so that damage migration is within bounds
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b1fba5e8534da7fe253e21a3501854c04d82a108
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 25 01:16:34 2012 +0000
+
+    sna: Clear GPU damage first when moving a clear pixmap to the CPU
+    
+    This allows us to discard any busy GPU or CPU bo when we know we are
+    going to clear the shadow pixmap afterwards.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5ad95d66665802bce25e127ae0d06f3e0a9b0e62
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 24 22:11:20 2012 +0000
+
+    sna: Reduce number of reads required to inspect timers
+    
+    By using the information provided by select at wakeup.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit aae19cbc5d0ddcf247451d06e063b2550a7ff16f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 24 19:58:29 2012 +0000
+
+    sna: Only reset devPrivate.ptr if owned by the CPU bo when freeing
+    
+    If the pixmap is mapped to the GPU bo, we should continue to use the
+    current mapping rather than revoke it. Otherwise if we write to the GPU
+    bo inplace, thereby discarding the CPU bo, we set the pointer we are
+    about to copy to, to NULL.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5312ee90ad80eda1c6ff72fbef60f77f03094972
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 24 19:02:56 2012 +0000
+
+    sna: mark the pixmap as no longer clear after rendering video
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 69d3fc91f4a397f704b9971f97a905626e86eb3c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 24 18:51:32 2012 +0000
+
+    sna: Set up GC for general FillArc to FillSpans callback
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 855c45c65a69d34ad32a97a5fc54dd09d40d3e26
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 24 18:48:17 2012 +0000
+
+    sna: Enable clipping for mi FillSpans gpu callback
+    
+    The mi routines do not ensure that their output is suitably constrained
+    to the clip extents, so we must run it through the clipper.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c3fe42cde70a06a9a9a6190934df5cddb41d2f5f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 24 18:36:08 2012 +0000
+
+    sna: Don't attempt to create pixmaps for dpeths smaller than 8
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 22bab3cd7d0b2bcedfdd86f198d1ed9a21dd82aa
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 24 18:33:14 2012 +0000
+
+    sna: Handle malloc failures when downsampling
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4aef9e6f50cb96c57b7ba345a18e55c97d788192
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 24 17:23:43 2012 +0000
+
+    sna: Add more damage-is-contained asserts
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 16462e551d575bd5a370a8ac8b450ba72fea7d47
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 24 17:47:22 2012 +0000
+
+    sna: Install CPU handler for PolyLine for miPolySegment callback
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b8b49ae70b3aadf4423bd6830c446c040f87a2f1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 24 16:32:40 2012 +0000
+
+    sna: Mutate a temporary copy of the GC->ops so we don't alter new GCs
+    
+    In order to avoid using the wrong function for a scratch GC created
+    during the course of a MI function whilst we have a specialised GC in
+    use, we need to avoid modifying the original function table.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1a116a15a5d978a1edf413a439f6ef6d3205a7aa
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 24 16:53:21 2012 +0000
+
+    sna: Reduce the assertion that we would have hinted to operate inplace
+    
+    As the drawable_gc_flags() operate on lower level information than the
+    hint, it is able to spot more oportunities to reduce the READ flags and
+    so the assertion was overly optimistic.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3d1bba033bc29fdf498dc082f3542c520a5ed39a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 24 18:22:12 2012 +0000
+
+    sna/gen3: Apply damage to video pixmap
+    
+    Reported-by: Paul Neumann <paul104x@yahoo.de>
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=44504
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ff4b8a03a40f7eb1d71b96aebb5daa1d8df83d2a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 24 17:51:35 2012 +0000
+
+    sna: Use RepeatPad to avoid sampling the border color when downsampling
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=45086
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 09bddddaf94b848f417e1c9449cfe4b21d2554dd
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 24 15:50:02 2012 +0000
+
+    sna: handle negative modulus for tiled blits
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f3b11ebc28114062581c39089781114323946654
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 24 16:05:09 2012 +0000
+
+    sna: Add more assertions for copy errors
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b56971986d2d495aa38f015beb659fb12f0d433a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 24 17:23:59 2012 +0000
+
+    sna: Trim the clipped Segment to the right length
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 358a0861e642c26d925a69656039b4c95adba237
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 24 13:30:19 2012 +0000
+
+    sna: Do not discard CPU damage for a partial copy
+    
+    If we are copying a region that does not fill its extents (i.e. is not
+    singular) then we must be care not to discard the CPU damage that is not
+    overwritten by the copy.
+    
+    Fixes regression from 77ee92248582d65a03619d1bb1d93a74468eea00
+    (sna: Use full usage flags for moving the dst pixmap for a copy).
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 672c6ad8170572c0f2562d5a8381ab2d17fd1e1b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 24 12:56:59 2012 +0000
+
+    sna: Silence the compiler with a few DBG format warnings
+    
+    The size of the integers being printed changed causing warnings on 32/64
+    bit.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 238f3d9bc563950475ee823f844197cf15a909e2
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 24 12:19:38 2012 +0000
+
+    sna: A deferred attachment will never have a CPU bo
+    
+    So we can remove that check in sna_copy_boxes.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c353a8cfde838b070f3e71d3946f3b40d1d5113a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 24 10:52:27 2012 +0000
+
+    sna: Revise use of the inplace hint to favour small cacheable operations
+    
+    The goal of the heuristic is to reduce readbacks and damage tracking on
+    active GPU bo whilst simultaneously offering the best performance for
+    small operations which would prefer to be performed on the shadow rather
+    than in place.
+    
+    This restores ShmPutImage performance.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 29547421f392a9b589ba069cbfbba01dbe535d93
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 24 10:23:46 2012 +0000
+
+    sna: Use the reduced ROP from the fbGC to accurately determine readback
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ec794f7594ae5e2c223b7f7255ff8979d9fb06c1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jan 23 22:14:15 2012 +0000
+
+    sna: Track a proxy's dirty status upon itself rather than the target
+    
+    As proxy's are short-lived and are not used outside of the operation for
+    which they are created, dirtied or flushed, we can safely copy the dirty
+    status onto the proxy object itself.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2574a04c940e032fdcf1cd39a0950515e8652471
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jan 23 21:45:29 2012 +0000
+
+    sna: Split the active bo cache into per-tiling caches
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 566cbf1ef53b1f970289fcd5b3b389a74beb7e78
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jan 23 21:15:10 2012 +0000
+
+    sna: Abort search for a linear bo if we encounter a purged buffer
+    
+    Given the rarity of encountering a purged buffer versus the frequency of
+    scanning the list and the then likely result of allocation a new buffer,
+    simply abort the search on the first purged bo.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b8d3353624be51f2b618467c899a9ce3cbf3cbfe
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jan 23 19:13:22 2012 +0000
+
+    sna: Refactor tests for a solid gc to use the new function
+    
+    This way all paths can test to see if they might be able to reduce the
+    tiled fill or the opaque fill into a solid fill.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 78238b3a37c1c8a152bd3920e73aa6034c0f663f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jan 23 18:00:05 2012 +0000
+
+    sna: Prefer mi span filling functions to call through to the GPU
+    
+    Having removed the double analysis for the fast paths, at least, the
+    span filling code on the GPU is now faster than doing the same
+    operations in cache memory for the majority of cases. So allow the
+    driver to prefer to use those functions when it has a GPU bo.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c5c77d04d79666962fd7c2d86bc6e7aef716084b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jan 23 18:24:21 2012 +0000
+
+    sna: Reduce GC to solid if possible along general spans path
+    
+    Again, we should no longer be hitting this code if at all possible, but
+    for completeness...
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 03611f662db854dc3b14f32c0315bf45bc415bbf
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jan 23 19:59:06 2012 +0000
+
+    sna: Guard against being passed n==0 to FillSpans
+    
+    Apparently this does happen, notably by miFillPolyArc.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7ac13a4d5aca1627b3a5fc9e7261d5dfafba970b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 24 00:21:12 2012 +0000
+
+    sna: Provide a fast path for miZeroLine for PolySegment
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e7817a2206bd0b1cc4e4458686c328f7b41ea32c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jan 23 17:43:55 2012 +0000
+
+    sna: Override sna_fill_spans for PolySegment
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5b8db54d0fa9eab2610feed6947e917f2e400e1a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 24 00:21:12 2012 +0000
+
+    sna: Provide a fast path for miZeroLine for PolyLine
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 280a9165db5382b93ab449158106bdd5aa7b2329
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jan 23 17:43:55 2012 +0000
+
+    sna: Override sna_fill_spans for PolyLine
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 72fc3122b85fe1a1a16c7f7401c300089273fd88
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 24 01:27:08 2012 +0000
+
+    sna: Prefer to always use span generation for PolyArc
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 98879e3786b7f6241378a32a10f2d46eb01baf85
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jan 23 23:22:00 2012 +0000
+
+    sna: Specialise PolyPoint for callback from miZeroPolyArc
+    
+    miZeroPolyArc may use either FillSpans for PolyPoint to generate its
+    curves, so also provide custom point filling routines.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5b10cb4a5ce84bd677b0a67a17d8674defb19f31
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jan 23 17:02:46 2012 +0000
+
+    sna: Override sna_fill_spans for PolyArc
+    
+    This is the missing like that allows the GPU to outperform fbPolyArc.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6390a44a69d7f13a3ba16e8b48c640dc39dd227f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jan 23 15:57:53 2012 +0000
+
+    sna: Pass the reduce clip region to sna_fill_spans__cpu
+    
+    Since we compute it for the pixmap migration, we may as well use to
+    perform the clipping within FillSpans as well.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 40e3745debe9738362661c7d7f498f3489c28876
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jan 23 15:42:18 2012 +0000
+
+    sna: Wrap gc->ops->PolyFillArc
+    
+    The goal is to avoid the overhead of performing multiple region analysis
+    when calling sna_fill_spans by doing it once at the top level and then
+    choose the most appropriate drawing method.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 55c2211143b3be2827fd4e299c3c211f3bd7935b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jan 23 18:15:36 2012 +0000
+
+    sna: Use a streamlined sna_fill_spans for when we know we want to use the gpu
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b20ae331566e92f1a995f49fd0760f020db25035
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jan 23 19:49:18 2012 +0000
+
+    sna: Switch to using spans based on use_wide_spans()
+    
+    This just gives us a hook with which to conveniently enable or disable
+    the new code.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 41739ff9517ca158d9f7b7ac82e5bacef62a3d68
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jan 23 15:42:18 2012 +0000
+
+    sna: Wrap gc->ops->FillPolygon
+    
+    The goal is to avoid the overhead of performing multiple region analysis
+    when calling sna_fill_spans by doing it once at the top level and then
+    choose the most appropriate drawing method.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit aef56b194d4de9bd71ab71e3d93d81e1750262c5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jan 23 15:38:30 2012 +0000
+
+    sna: Mark GPU bo as busy when drawing to an all-damaged pixmap for core
+    
+    The fast path to decide whether to use the GPU bo for the core drawaing
+    operations forgot to update the active status of the pixmap. This
+    included forgetting to clear the is-cleared flag.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c67e6a05ff729c0ddb26775e1c8533be1144d85a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jan 23 11:40:13 2012 +0000
+
+    sna: Align the origin of downsampling subregion to an even pixel
+    
+    In order for us to produce stable downsampled images across multiple
+    frames, we need to sample the same pairs of pixels every time. This
+    requires us to align the origin of the sample region to an even pixel.
+    
+    Reported-by: Clemens Eisserer <linuxhippy@gmail.com>
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=45086
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9267da93969d1727cb95956c3f63643f0039c60d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jan 23 11:20:12 2012 +0000
+
+    sna: Apply composite offset to copy-clear GPU path
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 803f6558c665c16ba2d20415e778b5bd1d308c2f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jan 23 11:05:50 2012 +0000
+
+    sna: Only subtract the fillrect from the CPU damage if it covers the drawable
+    
+    The idea behind that optimisation is for the inactive pixmap to be
+    refreshed and allowed to be transfered back to the GPU when it is
+    entirely redrawn. As such performing the subtraction when it does not
+    completely remove it only incurs additional overhead.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 267493f39137704bd52df65b7605be30d2a062b2
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jan 23 10:54:13 2012 +0000
+
+    sna: Assert that the subtract operation does reduce an all-damaged
+    
+    Somewhere somewhen it appears that I am discarding the all-damaged flag
+    on the pointer. The only possibility I can see is for a no-op
+    subtraction, so put an assert there just in case the impossible is
+    happening.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2908fe2df7b8f870a55fc5856f94ea541a7c7b75
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jan 22 18:46:57 2012 +0000
+
+    sna: Remove assertion that all flushing list members are in the GPU domain
+    
+    This may not be true for external buffers that are put on the flushing
+    list because they have foreign requests pending.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a0bc17c0fa34c9f9243817d1674d1ff235dc99d6
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jan 22 18:27:34 2012 +0000
+
+    sna/gen6: stall before blending dirty pixels from the render cache
+    
+    Another restriction on the render pipeline, it turns out, is that before
+    the blend unit can read back the dst pixels in a subsequent primitive,
+    we must stall the pipeline for the completion of that earlier primitive.
+    
+    This is demonstrated by cacomposite.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5aa494305e90eed5df211427741a75380add8e96
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jan 22 16:10:39 2012 +0000
+
+    sna: Correct the offsets for performing partial downsampling on the GPU
+    
+    Reported-by: Clemens Eisserer <linuxhippy@gmail.com>
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=45086
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a7b24bb4342eefb2b23fa40d7c7216c38f2edc09
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jan 22 15:50:47 2012 +0000
+
+    sna: Correct image buffer size when uploading a downsampled image
+    
+    Reported-by: Clemens Eisserer <linuxhippy@gmail.com>
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=45086
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 238fc67aa945d5669eccd2a8fe8e98402b9a6223
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jan 22 16:04:13 2012 +0000
+
+    sna: Incude prefer-gpu hint in decision to upload CPU textures
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit aeaffb102190a8846c6341e72a4338b41639d679
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jan 22 15:52:41 2012 +0000
+
+    sna: Add some more DBG along the downsampling source extraction path
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 92badc9c9c2636284af8bc56b098d24ff222f167
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jan 22 12:41:31 2012 +0000
+
+    sna: Avoid a common readback after clearing
+    
+    It is surprisingly common for a pixmap to be created, cleared and then
+    used as an upload target or, even worse, as a source for a ShmGetImage.
+    In order to prevent this folly, we can trivially track when we clear an
+    entire pixmap and its GPU bo and avoid the readback in such cases.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 67a166d1247a1197fc851308c33c4970868f6a21
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jan 22 13:46:05 2012 +0000
+
+    sna: Pass inplace hint for sna_copy_boxes fallback
+    
+    In the unlikely event that this makes a difference, provide the hint as
+    to when we do not read back from the destination and so a streaming copy
+    would be preferable.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 77ee92248582d65a03619d1bb1d93a74468eea00
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jan 22 13:42:57 2012 +0000
+
+    sna: Use full usage flags for moving the dst pixmap for a copy
+    
+    Now that the migration code can decide for itself when to not move
+    damage, we can pass the hints to the code rather than perform the
+    optimisation in sna_copy_boxes.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit dd079dd1f64e7832c6343c24958aa9eeb2f58789
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jan 21 19:38:40 2012 +0000
+
+    sna: Check the blt composite op is within the source bounds
+    
+    If we attempt to read from a drawable that is partially off its backing
+    pixmap (such as a partially offscreen composite window) we need to fixup
+    the read from the out-of-bounds regions to return clear. Since we don't,
+    the easier answer is to just to switch to the render pipeline for such
+    an operation.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8a91c7d85740a5adc25d2a9b1972c367780ce714
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jan 21 01:18:17 2012 +0000
+
+    sna: Give kgem_create_buffer_2d a unique id
+    
+    The gen3, among others, backend uses the unique id of a buffer to track
+    the currently attached buffer and uses 0 as the invalid value. Linear
+    buffers as created by kgem_create_buffer_2d were not being assigned a
+    unique id causing mayhem when they were then being passed to the
+    backends as render targets and sources. In particular, gen3 did not
+    notice the switch in render target and did not emit commands to change
+    the GPU target nor attach the buffer to the batch, causing the
+    sna_read_boxes to fail and for us to trigger an assertion for an
+    uncomsumed read buffer.
+    
+    Reported-by: Clemens Eisserer <linuxhippy@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=42718
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d21e80433f2574fe96036ad1d563515406a1946f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jan 21 01:17:39 2012 +0000
+
+    sna/gen3: Add DBG markup for tracking target state
+    
+    In particular for when we switch to a new destination and mark it dirty.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 20006a9ae7f993f02c45ccbc1e414d74bfee3acd
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jan 20 22:17:44 2012 +0000
+
+    sna: Cleanup PolyText and ImageText fallback debugging
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3fbd7cafb4394e0641565dc794b82bef615b4aac
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jan 20 22:16:53 2012 +0000
+
+    sna: Copy the glyphs metrics before checking for an empty glyph
+    
+    The empty glyph still needs the correct advance, and copying it too late
+    left it as zero and so we were collapsing spaces in PolyText8 and
+    friends.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f0d8f5d377460bb7da82546e8304252312e97147
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jan 20 14:34:28 2012 +0000
+
+    sna/gen3: Set bo to NULL for render_fill_one
+    
+    It had to happen, I missed one! From fc9531fc2df.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0286ddbd67d3b2585ffa3deccb7eeb674cd7a3e0
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jan 20 11:33:05 2012 +0000
+
+    sna/gen6: Cleanup non-pipelined w/a
+    
+    Move the workaround CS stall into the emit drawrect which is the only
+    non-pipelined op we emit. This removes the split between deciding
+    whether we will emit a drawrect and actual emission.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a0c4024e32ccab70e7f7893896d30c80ad9f4240
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jan 20 09:42:18 2012 +0000
+
+    sna/gen6: Do not enable blending on video sources
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit bbbda4c408c2576927582097f7cd4f606b1761fa
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jan 20 09:40:04 2012 +0000
+
+    sna/gen6: Reduce the sampler stall if already stalling for drawrect
+    
+    If we are force to emit a stall for the non-pipelined workaround, we do
+    not then need to emit a stall for switching samplers.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e91601278a057f70df76b74539ff4f80d203bf00
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jan 20 01:37:29 2012 +0000
+
+    sna/gen6: Force a CS stall for changing samplers
+    
+    On closer inspection, we still need the workaround of forcing a pipeline
+    stall if we update the samplers.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fc9531fc2df12b896e6d9e8b3f0d7248e55bfcdd
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 19 21:15:35 2012 +0000
+
+    sna: Move the flush to the backends
+    
+    This allows us to implement backend specific workarounds and use the
+    more appropriate device specific flushing.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2e0a534a888c59b921fd4cad69b980c6eda72212
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 19 18:52:35 2012 +0000
+
+    sna/gen7: Forward port recent changes from gen6
+    
+    Fixes for resubmitting batches after running out of space for vertex
+    buffers and also a couple of trivial spans functions.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5caf806d42a1909ff3a7716d8bc592fa68a02377
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 19 17:33:25 2012 +0000
+
+    sna: BLT use dword pitch only for tiled surfaces
+    
+    The gen4+ spec is a little misleading as states that all BLT pitches for
+    the XY commands are in dwords. Apparently not, as the upload/download
+    functions were already demonstrating. This only became apparent when
+    accelerating core text routines to offscreen pixmaps, such as composited
+    windows.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit dbc75532d5f6a10e9fc7cfe3634d5a0db7304a99
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 19 14:36:32 2012 +0000
+
+    sna: Tweak move-to-cpu to ignore inplace hint if its already on the CPU
+    
+    If we test the area to be drawn against the existing CPU damage and find
+    it is already on the CPU, we may as well continue to utilize that
+    damaged region.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7ad4a0c9423ee7f4041173c428b07ac4af312fe1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 19 11:15:38 2012 +0000
+
+    sna: Only use the blitter to emit wide spans if we cannot stream the updates
+    
+    If either the region is busy on the gpu or if we need to read the
+    destination then we would incur penalties for trying to perform the
+    operation through the GTT. However, if we are simply streaming pixels to
+    an unbusy bo then we can do so inplace faster than computing the
+    corresponding GPU commands and uploading them.
+    
+    Note: currently it is universally slower to use the GPU here (the
+    computation of the spans is too slow). However that is only according to
+    micro-benchmarks, avoiding the readback is likely to be more efficient
+    in practice.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9db6b9fad808175184849f3030862ea115ef0708
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 19 11:54:14 2012 +0000
+
+    sna: Also check for the inplace hint when migrating the whole pixmap
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d3f7d5d614748306cc376d1929da2bbc14494a6e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 19 11:15:38 2012 +0000
+
+    sna: Only use the blitter to emit spans if we cannot stream the updates
+    
+    If either the region is busy on the gpu or if we need to read the
+    destination then we would incur penalties for trying to perform the
+    operation through the GTT. However, if we are simply streaming pixels to
+    an unbusy bo then we can do so inplace faster than computing the
+    corresponding GPU commands and uploading them.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ff2eb116ef85182eea9ed06daaa1e9a4f7bdbad3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 18 00:56:07 2012 +0000
+
+    sna: Micro-optimise line extents for zero line width
+    
+    Handling zero line widths is the common case, so avoid the extra work.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3c010745076204ed3b66e947c9eab6de84f670fe
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 19 09:46:52 2012 +0000
+
+    sna: filter out degenerate segments whilst drawing unclipped PolySegment
+    
+    The damage layer was detecting that we were asking it to accumulate a
+    degenerate box emanating from PolySegment, as the unclipped paths made
+    the fatal assumption that it would not need to filter out degenerate
+    boxes. However, a degenerate line becomes a point, does the same apply
+    to a degenerate segment?
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 35f81005f91d294e61bb4ced7cbddd1a76ccb324
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 19 00:41:08 2012 +0000
+
+    sna/damage: Always mark the damage as dirty when recording new boxes
+    
+    A few of the create_elts() routines missed marking the damage as dirty
+    so that if only part of the emebbed box was used (i.e. the damage
+    contained less than 8 rectangles that needed to included in the damage
+    region) then those were being ignored during migration and testing.
+    
+    Reported-by: Clemens Eisserer <linuxhippy@gmail.com>
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=44682
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 36e691ea900d7979950c19714e15c5887d3ea039
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 19 00:39:28 2012 +0000
+
+    sna: Demote MOVE_READ if the GC operation covers the clip
+    
+    If the write operation fills the entire clip, then we can demote and
+    possible avoid having to read back the clip from the GPU provided that
+    we do not need the destination data due to arithmetic operation or mask.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 17efdbc48c964d9d7b0af630c13a6ceb62fb1787
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 19 00:36:52 2012 +0000
+
+    sna: Clip damage area with source extents for fallback
+    
+    The damage tracking code asserts that it only handles clip regions.
+    However, sna_copy_area() was failing to ensure that its damage region
+    was being clipped by the source drawable, leading to out of bounds reads
+    during forced fallback.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fb07243c9a08b24e2dc03b86dc16d3cd72cbfcba
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 18 21:30:34 2012 +0000
+
+    sna: Fine grained fallback debugging for core drawing routines
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 05f9764a8860cbdd7ea2ce7f04c221ec8481e0bc
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 18 21:29:45 2012 +0000
+
+    sna/damage: Fast path singular regions
+    
+    Mainly for consistency, so that we treat it like the other damage
+    addition functions.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 96529e345d0718d253e4abfa0a02cd1f9f7c0406
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 18 21:05:40 2012 +0000
+
+    sna: Make sure we create a mappable GPU bo when streaming writes
+    
+    If we decide to do the CPU fallback inplace on the GPU bo through a WC
+    mapping (because it is a large write-only operation), make sure that
+    the new GPU bo we create is not active and so will not^W^W is less likely
+    to cause a stall when mapped.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit efce896e1dbab6177a773a7cf1c8eaf2dab0cdee
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 18 20:53:55 2012 +0000
+
+    sna: Check number of boxes to migrate during move-to-cpu
+    
+    When reducing the damage we may find that it is actually empty and so
+    sna_damage_get_boxes() returns 0, be prepared.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 334f3f70a8b4372cb089773ecded8339d2c7d984
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 18 20:09:26 2012 +0000
+
+    sna/gen3: Set the batch mode for emitting video state
+    
+    The lack of kgem_set_mode() here is causing some recently added
+    assertions to fail.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 76203b70708b8750f52348ea8b9135191e650ff7
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 18 18:36:43 2012 +0000
+
+    sna: Almagamate writes based on the total number of bytes written
+    
+    Cachelines will only be dirtied for the bytes accessed so a better
+    metric would based on the total number of pages brought into the TLB
+    and the total number of cachelines used. Base the decision on whether
+    to try and amalgamate the upload with others on the number of bytes
+    copied rather than the overall extents.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 470741e84c813a257897ee69f14500207a2674dc
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 18 18:35:59 2012 +0000
+
+    sna: Debug uploads
+    
+    All of the asserts and debug options that lead me to believe that the
+    tiling was completely screwy for some writes.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ab387a89cf64ace9f7d7fa52b7743e78b625f47d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 18 18:32:51 2012 +0000
+
+    sna: Update bo->tiling during search_linear_cache
+    
+    search_linear_cache() was updated to track the first good match whilst it
+    continued to search for a better match. This resulted in the first good
+    bo being modified and a record of those modifications lost, in
+    particular the change in tiling.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4b893ab0812452238305b29b1beea224219f641d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 18 16:34:17 2012 +0000
+
+    sna: Remove defunct debugging option
+    
+    FORCE_GPU_ONLY now has no effect except for marking the initial pixmap
+    as all-damaged on the GPU, and so not testing the paths for which it was
+    originally introduction.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 965586544a8559b6b6b98c20e14c1266e46bf20d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 18 16:11:50 2012 +0000
+
+    sna/gen6: Don't assume that a batch mode implies a non-empty batch
+    
+    Just in case we set a mode then fail to emit any dwords. Sounds
+    inefficient and woe betide the culprit when I find it...
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d2e05750360fb19575f3becd87816184615855bf
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 18 16:08:51 2012 +0000
+
+    sna: Fix some tracking of to-be-flushed dri pixmaps
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1ad5320fd40eaaf0bffcd209bf1eabd9a20e4bf8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 18 15:39:35 2012 +0000
+
+    sna: Add valgrind markup for tracking CPU mmaps
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f3da610eadd1f560812603ab1a72c2e173679689
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 18 12:59:48 2012 +0000
+
+    sna: Prevent switching rings with render disabled
+    
+    We fudge forced used of the BLT ring unless we install a render backend
+    and so we must also prevent the ring from being reset when the GPU is
+    idle. Therefore we make handing the ring status a backend function.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6d31cb2d943be456f4ebaa663275c6a939013d9e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 18 11:25:30 2012 +0000
+
+    sna: Restore use of shadow pixmaps by default without RENDER support
+    
+    If we do not have access to an accelerated render backend, only create
+    GPU buffers for the scanout and use an accelerated blitter for
+    upload/download and operating inplace on the scanout.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 15a150579c3907054e186c68382873efdbadca75
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 18 10:26:33 2012 +0000
+
+    intel: Trivially remove a piece of XAA dependency for shadow
+    
+    The wolves are gathering at the door baying for the removal of XAA from
+    Xorg.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 850495f956c811b1eb617d2e704e6bb7b5a86369
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 17 22:51:29 2012 +0000
+
+    sna: Fix increment of damage boxes after updating for rectangles
+    
+    Found by valgrind:
+    ==13639== Conditional jump or move depends on uninitialised value(s)
+    ==13639==    at 0x5520B1E: pixman_region_init_rects (in
+    /usr/lib/x86_64-linux-gnu/libpixman-1.so.0.24.0)
+    ==13639==    by 0x89E6ED7: __sna_damage_reduce (sna_damage.c:489)
+    ==13639==    by 0x89E7FEC: _sna_damage_contains_box (sna_damage.c:1161)
+    ==13639==    by 0x89CFCD9: sna_drawable_use_gpu_bo (sna_damage.h:175)
+    ==13639==    by 0x89D52DA: sna_poly_segment (sna_accel.c:6130)
+    ==13639==    by 0x21F87E: damagePolySegment (damage.c:1096)
+    ==13639==    by 0x1565A2: ProcPolySegment (dispatch.c:1771)
+    ==13639==    by 0x159FB0: Dispatch (dispatch.c:437)
+    ==13639==    by 0x1491D9: main (main.c:287)
+    ==13639==  Uninitialised value was created by a heap allocation
+    ==13639==    at 0x4028693: malloc (in
+    /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
+    ==13639==    by 0x89E6BFB: _sna_damage_create_boxes (sna_damage.c:205)
+    ==13639==    by 0x89E78F0: _sna_damage_add_rectangles (sna_damage.c:327)
+    ==13639==    by 0x89CD32D: sna_poly_fill_rect_blt.isra.65
+    (sna_damage.h:68)
+    ==13639==    by 0x89DE23F: sna_poly_fill_rect (sna_accel.c:8366)
+    ==13639==    by 0x21E9C8: damagePolyFillRect (damage.c:1309)
+    ==13639==    by 0x26DD3F: miPaintWindow (miexpose.c:674)
+    ==13639==    by 0x18370A: ChangeWindowAttributes (window.c:1553)
+    ==13639==    by 0x154500: ProcChangeWindowAttributes (dispatch.c:696)
+    ==13639==    by 0x159FB0: Dispatch (dispatch.c:437)
+    ==13639==    by 0x1491D9: main (main.c:287)
+    ==13639==
+    
+    Use 'count' everywhere for consistency.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4b5c9affd4968fd5b3d85551cf5a0b4d600a7892
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 17 20:23:26 2012 +0000
+
+    sna: Restore orginal shadow pointer before uploading CPU damage
+    
+    Detected by valgrind:
+    ==22012== Source and destination overlap in memcpy(0xd101000, 0xd101000,
+    783360)
+    ==22012==    at 0x402A180: memcpy (in
+    /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
+    ==22012==    by 0x89BD4ED: memcpy_blt (blt.c:209)
+    ==22012==    by 0x89F2921: sna_write_boxes (sna_io.c:364)
+    ==22012==    by 0x89CFABF: sna_pixmap_move_to_gpu (sna_accel.c:1900)
+    ==22012==    by 0x89F49B0: sna_render_pixmap_bo (sna_render.c:571)
+    ==22012==    by 0x8A268CE: gen5_composite_picture (gen5_render.c:1908)
+    ==22012==    by 0x8A29B8A: gen5_render_composite (gen5_render.c:2252)
+    ==22012==    by 0x89E6762: sna_composite (sna_composite.c:485)
+    ==22012==    by 0x21D3C3: damageComposite (damage.c:569)
+    ==22012==    by 0x215963: ProcRenderComposite (render.c:728)
+    ==22012==    by 0x159FB0: Dispatch (dispatch.c:437)
+    ==22012==    by 0x1491D9: main (main.c:287)
+    ==22012==
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit bbd6c8123635899e89911104bf84e1b7d11d66a1
+Author: Eugeni Dodonov <eugeni.dodonov@intel.com>
+Date:   Tue Jan 17 16:16:37 2012 -0200
+
+    sna: check for LLC support
+    
+    Instead of checking for CPU generation, use the libdrm-provided
+    I915_PARAM_HAS_LLC instead.
+    
+    v2: use a define check to verify if we have I915_PARAM_HAS_LLC.
+    
+    Signed-off-by: Eugeni Dodonov <eugeni.dodonov@intel.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e4efde920bcab980451e79df7d645d1814e5f78d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 17 13:44:12 2012 +0000
+
+    sna: Track whether damage is a complete representation of the dirt
+    
+    The previous commit undoes a premature optimisation that assumed that
+    the current damage captured all pixels written. However, it happens to
+    be a useful optimisation along that path (tracking upload of partial
+    images), so add the necessary booking that watches for when the union
+    of cpu and gpu damage is no longer the complete set of all pixels
+    written, that is if we either migrate from one pixmap to the other, the
+    undamaged region goes untracked. We also take advantage of whenever we
+    damage the whole pixel to restore knowledge that our tracking of all
+    pixels written is complete.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a9b705f9a7bbd37a0543ce5fbd4c60c912d1017d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 17 12:58:43 2012 +0000
+
+    sna: Mark GPU as all-damaged discarding the CPU bo to prevent stalls
+    
+    If we discard the CPU bo, we lose knowledge of whatever regions had been
+    initialised but no longer dirty on the GPU, but instead must assume that
+    the entirety of the GPU bo is dirty.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9d631e26d758eb4c2032a502604f07c5403b25ff
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 17 12:58:03 2012 +0000
+
+    sna: Mark the freshly allocated CPU bo as in the CPU domain
+    
+    As we immediately use it after creation, we need to inform GEM of the
+    domain transfer.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit dfbf02b8778719b86e0f5d78ee833a19436d43a0
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 17 10:55:29 2012 +0000
+
+    sna: Add some DBG breadcrumbs to put_image upload paths
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit da90afc32f19e9168cbaa4e0cdcd941d12f2c142
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 17 10:24:06 2012 +0000
+
+    sna: Add DBG breadcrumbs to gradient initialisation
+    
+    Put some markers into the debug log as those functions create many
+    proxies causing a lot of debug noise.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d14341cb22e37f52070cd92b707fec5e08038e96
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 17 00:31:43 2012 +0000
+
+    sna: Add a render ring detiling read path
+    
+    For SNB, in case you really, really want to use GPU detiling and not
+    incur the ring switch. Tweaking when to just mmap the target seems to
+    gain most anyway...
+    
+    The ulterior motive is that this provides fallback paths for avoiding
+    the use of TILING_Y with GTT mmaps which is broken on 855gm.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3620f9ca459f7bbbb01786c95b5583023b6d870c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 17 00:23:04 2012 +0000
+
+    sna: Cap pwrite buffer alignment to 64k
+    
+    We only want to create huge pwrite buffers when populating the inactive
+    cache for mmapped uploads. In the absence of using mmap for upload, be
+    more conservative with the alignment value so as not to simply waste
+    valuable aperture and memory.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b9f59b1099eeba3fb8b25693d4f37dd13267d8a3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 17 00:20:51 2012 +0000
+
+    sna: correct adjust of a stolen 2d read buffer
+    
+    If we steal a write buffer for creating a pixmap for read back, then we
+    need to be careful as we will have set the used amount to 0 and then try
+    to incorrectly decrease by the last row. Fortunately, we do not yet have
+    any code that attempts to create a 2d buffer for reading.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6fc4cdafeba4517b94202ff292f05fdd90e52b2e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jan 16 21:34:43 2012 +0000
+
+    sna: Correct assertion for a partial read buffer
+    
+    The batch may legitimately be submitted prior to the attachment of the
+    read buffer, if, for example, we need to switch rings. Therefore update
+    the assertion to only check that the bo remains in existence via either
+    a reference from the exec or from the user
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 377f5e16cd14bdf42e67b0c8f2e13b75526f3a85
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jan 16 15:51:33 2012 +0000
+
+    sna/gen[45]: clear the state tracker before setting the formats
+    
+    When backporting the patches from gen6, I didn't notice the memset that
+    came later, and this wasn't along the paths checked by rendercheck.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6387f2fb8a40f32cc4a3e4228983dcf0604ac4dc
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jan 16 14:12:36 2012 +0000
+
+    sna/gen[4567]: x1r5g5b5 is only a render target, not sampler
+    
+    Whilst we can render to and blend with an depth 15 target, we cannot use
+    it as a texture with the sampling engine.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8b2bb666662305ab88aad8198ad69b1c98407d75
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jan 16 13:35:05 2012 +0000
+
+    sna/gen6: Restore the non-pipelined op after every WM binding table update
+    
+    The hw wants it as demonstrated by the '>' in KDE's menus. Why is it
+    always KDE that demonstrates coherency problems...
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a11b22d172898ebfc657339a9ca56102ae92592f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jan 16 13:06:58 2012 +0000
+
+    sna/gen[23]: Remark the destination bo as dirty after flushing
+    
+    One of the side-effects of emitting the composite state is that it
+    tags the destination surface as dirty as a result of the *forthcoming*
+    operation. So emitting the flush after emitting the composite state
+    clears that tag, so we need to restore it for future coherency.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2f09363a6e2c77fb23bf0e4c12c4507521fa631b
+Author: Zhigang Gong <zhigang.gong@linux.intel.com>
+Date:   Thu Jan 12 15:30:15 2012 +0800
+
+    uxa/glamor: Create glamor pixmap by default.
+    
+    When creating native glamor pixmaps we will get much better performance
+    than using the textured-drm pixmap, this commit is to make that the
+    default behaviour when configured to use glamor. Another advantage
+    of this commit is that  we reduce the risk of encountering the
+    "incompatible region exists for this name" and the associated
+    render corruption. And since we now never intentionally allocate
+    a reusable pixmap we could just make all (intel_glamor) allocations
+    non-reusable without incurring too great an overhead.
+    
+    A side effect is that those glamor pixmaps do not have a
+    valid BO attached to them and thus it fails to get a DRI drawable. This
+    commit also fixes that problem by adjusting the fixup_shadow mechanism
+    to recreate a textured-drm pixmap from the native glamor pixmap. I tested
+    this with mutter, and it works fine.
+    
+    The performance gain to apply this patch is about 10% to 20% with
+    different workload.
+    
+    Signed-off-by: Zhigang Gong <zhigang.gong@linux.intel.com>
+    Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fd4c139a3959df90c7f078817fc6e2f3db715bf8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jan 16 00:32:12 2012 +0000
+
+    sna: On LLC systems quietly replace all linear mmappings using the CPU
+    
+    If the GPU and CPU caches are shared and coherent, we can use a cached
+    mapping for linear bo in the CPU domain with no penalty and so avoid the
+    penalty of using WC/UC mappings through the GTT (and any aperture
+    pressure). We presume that the bo for such mappings are indeed LLC
+    cached...
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c20a729d0a57fd5a782d9114535d9474f39a8950
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jan 15 22:19:22 2012 +0000
+
+    sna/gen6: Force a batch submission after allocation failure during composite
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 380a2fca3cce4c99c5026ab800f7885a1959b16d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jan 15 22:13:20 2012 +0000
+
+    sna: Optimise call to composite with single box
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9f89250de1dc134f54cb68012fa5eb996c61d57e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jan 15 21:54:13 2012 +0000
+
+    sna: Use the prefer-GPU hint for forcing allocation for core drawing
+    
+    Similar to the render paths and simpler than the current look up tiling
+    method.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8652bf7a196f53842db70f5c70aded31b470b0ab
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jan 15 19:04:01 2012 +0000
+
+    sna: Don't track an unmatching tiled bo when searching the linear cache
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit cc4b616990fa71e96d38512d8cdb4c3e2abb21c0
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jan 15 19:55:50 2012 +0000
+
+    sna/video: Increase the level of paranoia
+    
+    In how many different ways can we check that the scanout is allocated
+    before we start decoding video?
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7f480ba02c66fcc02bad483731c4c0cf6c746c0d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jan 15 18:45:06 2012 +0000
+
+    sna: Tidy search through active bo cache
+    
+    Perform the assertions upon cache consistency upfront, and tidy the
+    indentation.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6f7bc35d7f956f7c2507eabc874ead1a83c85ddb
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jan 15 18:14:24 2012 +0000
+
+    sna: Use indirect uploads rather than teardown existing CPU maps
+    
+    Allow the snoopable CPU mapping to be used inplace of the GTT map for
+    untiled bo.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 475fa67ed320f94df37ec86fe6c5dda886923751
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jan 15 17:30:00 2012 +0000
+
+    sna: Fast path move-area-to-cpu when the pixmap is already on the cpu
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 37ced44a53008debaf869ec9ef4ba2e5d6982e76
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jan 15 15:35:57 2012 +0000
+
+    sna: Be a little more lenient wrt damage migration if we have CPU bo
+    
+    The idea being that they facilitate copying to and from the CPU, but
+    also we want to avoid stalling on any pixels help by the CPU bo.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e3732a6f7f61a959521be9a668bba045591e633c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jan 15 11:06:59 2012 +0000
+
+    sna: Defer ring switching until after a period of idleness
+    
+    Similar to the desire to flush the next batch after an overflow, we do
+    not want to incur any lag in the midst of drawing, even if that lag is
+    mitigated by GPU semaphores.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5df7147b0934dadc63459c2c0f33e0663692425a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jan 15 10:28:00 2012 +0000
+
+    sna: Restore the kgem_create_map() symbol
+    
+    As the stub is exported to the driver even in the absence of vmapping.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit be53740c6f0bb182e3d88f0597f127732c839316
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jan 15 10:16:13 2012 +0000
+
+    sna: Various DBG typos
+    
+    Fix some mispellings inside the DBG messages
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 349e9a7b94199e759acaaccac3abf5e28f3c246f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jan 15 10:04:11 2012 +0000
+
+    sna: Prefer read-boxes inplace again
+    
+    Using the gpu to do the detiling just incurs extra latency and an extra
+    copy, so go back to using a fence and GTT mapping for the common path.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 09dc8b1b358aa33836d511b75f92e8d096bc7e59
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jan 14 23:21:29 2012 +0000
+
+    sna/gen7: Check reused source for validity
+    
+    Be sure the mask picture has a valid format even though it points to the
+    same pixels as the valid source. And also be wary if the source was
+    converted to a solid, but the mask is not.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d9871f01d8c4584c1f39eb09b51d5461863934e9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jan 14 23:21:29 2012 +0000
+
+    sna/gen6: Check reused source for validity
+    
+    Be sure the mask picture has a valid format even though it points to the
+    same pixels as the valid source. And also be wary if the source was
+    converted to a solid, but the mask is not.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1d6030322e2c3bae87a0173a32fb8d341dea560c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jan 14 23:21:29 2012 +0000
+
+    sna/gen5: Check reused source for validity
+    
+    Be sure the mask picture has a valid format even though it points to the
+    same pixels as the valid source. And also be wary if the source was
+    converted to a solid, but the mask is not.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0e4a24ef6c186909c99a501cb606994b5c10a813
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jan 14 23:21:29 2012 +0000
+
+    sna/gen4: Check reused source for validity
+    
+    Be sure the mask picture has a valid format even though it points to the
+    same pixels as the valid source. And also be wary if the source was
+    converted to a solid, but the mask is not.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ea299f2523d5adeca84274bb7003cde8ec743a44
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jan 14 23:21:29 2012 +0000
+
+    sna/gen3: Check reused source for validity
+    
+    Be sure the mask picture has a valid format even though it points to the
+    same pixels as the valid source. And also be wary if the source was
+    converted to a solid, but the mask is not.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 007da2f97894814eaded4d24e0481f950ca7bd00
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jan 14 23:21:29 2012 +0000
+
+    sna/gen2: Check reused source for validity
+    
+    Be sure the mask picture has a valid format even though it points to the
+    same pixels as the valid source. And also be wary if the source was
+    converted to a solid, but the mask is not.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1d55b42fbd77e85ab8930b78bb5a9e3bccbca49e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jan 14 23:44:23 2012 +0000
+
+    sna: Fix read back of partial mmapped buffers
+    
+    Do not move a GTT mapped buffer into the CPU domain, it causes untold
+    pain for no benefit!
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 046e945173397e5fee36a231303b68a6bc9d809d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jan 14 23:25:52 2012 +0000
+
+    sna: Discard read buffers after use
+    
+    Rather than pollute the cache with bo that are known not to be in the
+    GTT and are no longer useful, drop the bo after we read from it.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 421ee0bb53321e9fb2f17c850c51b80cc385bf57
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jan 15 00:46:47 2012 +0000
+
+    sna: Do not assume that the mappable aperture size is a power of two
+    
+    And instead derive a power-of-two alignment value for partial buffer
+    sizes from the mappable aperture size and use that during
+    kgem_create_buffer()
+    
+    Reported-by: Clemens Eisserer <linuxhippy@gmail.com>
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=44682
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5d5da35c9fab4e7154921861ecbb83befb8840e5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jan 14 18:28:24 2012 +0000
+
+    sna/gen[23]: Check for room in the batch before emitting pipeline flushes
+    
+    Use a single idiom and reuse the check built into the state emission,
+    for both spans/boxes paths.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f7e4799687d5010ea0b56aeb6fbbb2e854b1b363
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jan 14 16:53:38 2012 +0000
+
+    sna/gen6: Allow greater use of BLT
+    
+    Typically we will be bound to the RENDER ring as once engaged we try not
+    to switch. However, with semaphores enabled we may switch more freely
+    and there it is advantageous to use as much of the faster BLT as is
+    feasible.
+    
+    The most contentious point here is the choice of whether to use BLT for
+    copies by default. microbenchmarks (compwinwin) benefit from the
+    coallescing performed in the render batch, but the more complex traces
+    seem to prefer utilizing the blitter. The debate will continue...
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c1ce34d4509a3f3e963d82ac0569a21706892f8e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jan 14 15:08:18 2012 +0000
+
+    sna/gen6: Tidy markup for when using the BLT is truly preferrable
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b64751dbdb1b88b91ad97aaf995b4261876cf860
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jan 14 13:50:50 2012 +0000
+
+    sna: Be more lenient wrt switching rings if the kernel supports semaphores
+    
+    If the kernel uses GPU semaphores for its coherency mechanism between
+    rings rather than CPU waits, allow the ring to be chosen on the basis
+    of the subsequent operation following a submission of batch. (However,
+    since batches are likely to be submitted in the middle of a draw, then
+    the likelihood is for ddx to remain on one ring until forced to switch
+    for an operation or idle, which is the same situation as before and so
+    the difference is miniscule.)
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 295a22d2709b2442b5254968437f897dac22a0ec
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jan 14 14:12:25 2012 +0000
+
+    sna: Ensure that the batch mode is always declared before emitting dwords
+    
+    Initially, the batch->mode was only set upon an actual mode switch,
+    batch submission would not reset the mode. However, to facilitate fast
+    ring switching with semaphores, reseting the mode upon batch submission
+    is desired which means that if we submit the batch in the middle of an
+    operation we must redeclare its mode before continuing.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0d2a50772200d868d094f90dc1d30c1b4d7930ba
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jan 14 11:03:55 2012 +0000
+
+    sna/glyphs: Cache the glyph image on the fallback path as well
+    
+    The glyph cache grew to accommodate the fallback pixman image for mask
+    generation, and is equally applicable along the full fallback path.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f3e0ba4f65db2b85f89aa3868d153434bc41c811
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jan 14 10:17:27 2012 +0000
+
+    sna/gen5: Disable render glyphs_to_dst
+    
+    Processing more than a single rectangle using the CA path on ILK is
+    extremely hit-or-miss, often resulting in the absence of the second
+    primitive (ie. the glyphs are cleared but not added.) This is
+    reminiscent of the complete breakage of the BRW shaders, none of which
+    can handle more than a single rectangle.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fb92818ba4dc81ce62d58a87b5af6cb1e3a96708
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jan 14 01:48:11 2012 +0000
+
+    sna: Pass render operation to flush and avoid the implicit flush-on-batch-end
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a62429a1f79b8fa4a5ddaf61b2bc80fc8dbe576c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jan 13 19:00:01 2012 +0000
+
+    sna: Upload continuation vertices into mmapped buffers
+    
+    In the common case, we expect a very small number of vertices which will
+    fit into the batch along with the commands. However, in full flow we
+    overflow the on-stack buffer and likely several continuation buffers.
+    Streaming those straight into the GTT seems like a good idea, with the
+    usual caveats over aperture pressure. (Since these are linear we could
+    use snoopable bo for the architectures that support such for vertex
+    buffers and if we had kernel support.)
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 24df8ab9742f771cfeb6d30bd8a61a17a9e22ca7
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jan 13 16:15:21 2012 +0000
+
+    sna: Reverse the chronological sort order of inactive vma entries
+    
+    The goal is to reuse the most recently bound GTT mapping in the hope
+    that is still mappable at the time of reuse.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2f26bbe3dd55bfe26b6f93fc1f9e9813fc11f7c4
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jan 13 15:59:51 2012 +0000
+
+    sna: Remove the short-circuiting of all-damage in move_to_cpu
+    
+    To allow a replacement of the complete pixmap to be performed in place.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c81dba18e6a308d716a11b90da6e53ca7f5f8a02
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jan 13 14:21:13 2012 +0000
+
+    sna: Hint whether we prefer to use the GPU for a pixmap
+    
+    This includes the condition where the pixmap is too large, as well as
+    being too small, to be allocatable on the GPU. It is only a hint set
+    during creation, and may be overridden if required.
+    
+    This fixes the regression in ocitysmap which decided to render glyphs
+    into a GPU mask for a destination that does not fit into the aperture.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2bd942d55314426d7f429d7ccc0b62a622a79009
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jan 13 14:08:34 2012 +0000
+
+    sna/trapezoids: Quieten the debugging of the gory details of the rasteriser
+    
+    Hide the noise under another level of debugging so that hopefully the
+    reason why it chose a particular path become clear.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5dbcfc2ee3af64846298dbcb20db27c93b3d57f2
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jan 13 13:52:10 2012 +0000
+
+    sna: Be more lenient in not forcing to the GPU if the sources have CPU damage
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 20ff4a1d73cc10e1f53050b19b8799ccbb5c7d04
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jan 13 13:30:13 2012 +0000
+
+    sna: Use top_srcdir to detect .git rather than top_builddir
+    
+    For srcdir != builddir builds, we need to be searching the source tree
+    for the git id.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a4d5d725996b94e314ae7697c7a597ed2f60e8cd
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jan 13 10:41:44 2012 +0000
+
+    sna: Experiment with GTT mmapped upload buffers
+    
+    In a few places, we can stream the source into the GTT and so upload in
+    place through the WC mapping. Notably, in many other places we want to
+    rasterise on a partial in cacheable memory. So we need to notify the
+    backend of the intended usage for the buffer and when we think it is
+    appropriate we can allocate a GTT mapped pointer for zero-copy upload.
+    
+    The biggest improvement tends to be in the PutComposite style of
+    microbenchmark, yet throughput for trapezoid masks seems to suffer (e.g.
+    swfdec-giant-steps on i3 and gen2 in general). As expected, the culprit
+    of the regression is the aperture pressure causing eviction stalls, which
+    the pwrite paths sidesteps by doing a cached copy when there is no GTT
+    space. This could be alleviated with an is-mappable ioctl predicting when
+    use of the buffer would block and so falling back in those cases to
+    pwrite. However, I suspect that this will improve dispatch latency in
+    the common idle case for which I have no good metric.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 252f3818250ecf4776f20afa8111d7f1f6f29c18
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jan 13 11:30:32 2012 +0000
+
+    sna: Relinquish the GTT mmap on inactive buffers if moved out of the aperture
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9c73dd91e90810116c215060bac434c5e8174f5f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jan 14 17:00:01 2012 +0000
+
+    Include <xorgVersion.h> to repair build
+    
+    intel_module.c:41:48: error: missing binary operator before token "("
+
+commit b213f6e876f29cbcaccffeeb733726be4c91529e
+Author: Stefan Dirsch <sndirsch@suse.de>
+Date:   Sat Jan 14 05:43:33 2012 +0100
+
+    Make driver backwards compatible for server 1.6.x.
+    
+    Signed-off-by: Stefan Dirsch <sndirsch@suse.de>
+
+commit 94217a4dd908f1368dfdef90797ce74a081663fb
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jan 13 10:03:28 2012 +0000
+
+    sna: Decouple dirty pixmaps from list if we fail to upload them
+    
+    Rather than iterate endlessly trying to upload the same pixmap when
+    failing to flush dirty CPU damage, try again on the next flush.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 65ef369c733ab45945a7d5fe4b76fe5c7167b51b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jan 13 09:58:40 2012 +0000
+
+    sna: Decouple from CPU dirty list after removing all CPU damage
+    
+    In the paths where we discard CPU damage, we also need to remove it
+    from the dirty list so that we do not iterate over it during flush.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0845fcef9e664eb100b55ad1cc20743844deee58
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 12 23:45:03 2012 +0000
+
+    sna: Correct iteration counter for stippled blits
+    
+    ==7215== Invalid read of size 2
+    ==7215==    at 0x51A72F3: sna_poly_fill_rect_stippled_8x8_blt
+    (sna_accel.c:7340)
+    ==7215==    by 0x51A9CDF: sna_poly_fill_rect_stippled_blt
+    (sna_accel.c:8163)
+    ==7215==    by 0x51A3878: sna_poly_segment (sna_accel.c:6090)
+    ==7215==    by 0x216C02: damagePolySegment (damage.c:1096)
+    ==7215==    by 0x13F6E8: ProcPolySegment (dispatch.c:1771)
+    ==7215==    by 0x1436B4: Dispatch (dispatch.c:437)
+    ==7215==    by 0x131279: main (main.c:287)
+    ==7215==  Address 0x6f851e8 is 0 bytes after a block of size 32 alloc'd
+    ==7215==    at 0x4825DEC: malloc (vg_replace_malloc.c:261)
+    ==7215==    by 0x51A3558: sna_poly_segment (sna_accel.c:6049)
+    ==7215==    by 0x216C02: damagePolySegment (damage.c:1096)
+    ==7215==    by 0x13F6E8: ProcPolySegment (dispatch.c:1771)
+    ==7215==    by 0x1436B4: Dispatch (dispatch.c:437)
+    ==7215==    by 0x131279: main (main.c:287)
+    
+    An example being the stippled outline in gimp, the yellow marching ants,
+    would randomly walk over the entire image.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5c2c6474efd4dbc5a0fc9c68ef4e5b5e5cfee415
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 12 23:11:05 2012 +0000
+
+    sna/dri: Hook up a compile option to switch colour buffers to Y-tiling
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 59b79e5952fdc40f8c50f74a72a19363cb426140
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 12 21:05:39 2012 +0000
+
+    sna: Reorder composite-done to destroy mask bo before source bo
+    
+    Just in the unlikely event that we hit the delete-partial-upload path
+    which prefers destroying the last bo first.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 983b755313df8a0d256c59c32ec4106e35f237aa
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 12 21:05:16 2012 +0000
+
+    sna/damage: Fix union of extents with dirty damage but no region
+    
+    By failing to account for certain paths which would create a damage elt
+    without fully initialisating the damage region (only the damage extents),
+    we would later overwrite the damage extents with only the extents for
+    this operation (rather than the union of this operation with the current
+    damage). This fixes a regression from 098592ca5d,
+    (sna: Remove the independent tracking of elts from boxes).
+    
+    Include the associated damage migration debugging code of the callers.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8d2f1eefe142b65db7d8821ba0f80fdb0902b2d5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 12 21:08:41 2012 +0000
+
+    sna: Pass a hint that we may like to perform the fallback in place
+    
+    If we do not read back from the destination, we may prefer to utilize a
+    GTT mapping and perform the fallback inplace. For the rare event that we
+    wish to fallback and do not already have a shadow...
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 48ab72754d0069a3247c5fee8c353a6b593eaed9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 12 21:07:15 2012 +0000
+
+    sna: Use the GPU bo if it is all damaged
+    
+    By marking the scratch upload pixmap as damaged in both domains, we
+    confused the texture upload path and made it upload the pixmap a second
+    time. If either bo is all-damaged, use it!
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 20a4d7181983c7fed289844be49ccaf3f56965c6
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 12 21:05:51 2012 +0000
+
+    sna: Dump batch contents for debugging before modification
+    
+    We need to dump the batch contents before the maps are made by the
+    construction of the batch itself.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7932a2a259069bb7d19af8566f7b7704f6c2eade
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 12 14:06:22 2012 +0000
+
+    sna: Update for removal of backwards compatible miWideDash
+    
+    miWideDash() no longer calls miZeroLineDash() when called with
+    gc->lineWidth==0, we need to do so ourselves.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b7cefddd467bfd0c100219969712a0133475004c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 12 13:17:43 2012 +0000
+
+    sna: Re-enable min-alignment workaround on pre-SNB hw
+    
+    Confirmed as still being required for both gen3 and gen4. One day I will
+    get single-stream mode working, just not today apparently.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 978e1aeceab3c1a524f7d7a070fe04f37530c8d9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 12 11:38:56 2012 +0000
+
+    sna: Only shrink a partial buffer if it is no longer used.
+    
+    The condition on being able to shrink a buffer is more severe than just
+    whether we are reading from the buffer, but also we cannot swap the
+    handles if the existing handle remains exposed via a proxy.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d3169154d18600e0d41db5f833fad52970e17b55
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 12 11:36:05 2012 +0000
+
+    sna: Improve a DBG message
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2a22990968aebd53a7bfeaf19e58ee609b980e5f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 12 11:22:06 2012 +0000
+
+    sna: Prevent 60Hz wakeups if the client stops in mid-render
+    
+    Only continue to wake up if the scanout remains active.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1c0e9916caef6594511009c8cb79071ac0d82090
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 12 11:12:56 2012 +0000
+
+    sna: Align the partial buffer contents to cachelines
+    
+    To enable Daniel's faster pwrite paths. Only one step removed from using
+    whole page alignment...
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1e4080318f58fd51f37792eefd367e2e4c813ea3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 12 10:47:19 2012 +0000
+
+    sna: Replace the open-coded bubble sort of the partial list
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7290ced5791f9860b00901fa9a4545ab5a067fae
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 12 02:59:43 2012 +0000
+
+    sna/video: Fix for changes in damage api
+    
+    We can avoid both calls to modify the damage with one simple check.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 87e6dcb3b06c274ecba5de56d4e86fec73e46dbb
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 12 02:09:22 2012 +0000
+
+    sna: Don't call RegionIntersect for the trivial PutImage
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1bd6665093574372248a0743e5630e68aac653ed
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 12 01:37:08 2012 +0000
+
+    sna: Disable the min alignment workaround
+    
+    Allow all generations to use the minimum alignment of 4 bytes again as
+    it appears to be working for me... Or at least what remains broken seems
+    to be irrespective of this alignment.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 112b8959261712aaa82f92af0aca4b97fa7c7f03
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 12 01:38:18 2012 +0000
+
+    sna: Prevent shrinking a partial buffer stolen for a read
+    
+    If we reuse a partial buffer for a read, we cannot shrink it during
+    upload to the device as we do not track how many bytes we actually need
+    for the read operation.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b09ae4c20313fea7af11f77cd673039635d4dcc7
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 12 00:58:08 2012 +0000
+
+    sna: Don't drop expired partial bo immediately, wait until dispatch
+    
+    As the partial bo may be coupled into the execlist, we may as well hang
+    onto the memory to service the next partial buffer request until it
+    expires in the next dispatch.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a3c42565a8f557b2e7f7ff7bfa45b13b606f2968
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 11 16:39:45 2012 +0000
+
+    sna: Store damage-all in the low bit of the damage pointer
+    
+    Avoid the function call overhead by inspecting the low bit to see if it
+    is all-damaged already.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c64a9d0683e047a7eb041df78db746f6dd387b5e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 11 19:51:42 2012 +0000
+
+    sna: Choose a stride for the indirect replacement
+    
+    Don't blithely assume that the incoming bytes are appropriately aligned
+    for the destination buffer. Indeed we may be replacing the destination
+    bo with the shadow bytes out of another,larger, pixmap, in which case we
+    do need to create a stride that is appropriate for the upload an
+    perform the 2D copy.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b82851e74d5010ee08938ee42fa44c29fed633b1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 11 15:42:00 2012 +0000
+
+    sna: Mark upload pixmaps as being wholly GPU damaged
+    
+    So that subsequent code resists performing CPU operations with them
+    (after they have been populated.)
+    
+    Marking both sides as wholly damaged breaks the rules, but should work
+    out so long as we check whether we can perform the operation within the
+    target damage first.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2a5ab05f1690484c230e8f876a3f7aefb371af71
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 11 15:24:28 2012 +0000
+
+    sna: Use a minimum alignment of 64
+    
+    We should be able to reduce this by disabling dual-stream mode of the
+    GPU (which we want to achieve any way for 2D performance). Artefacts
+    in small uploads demonstrate that we fail to do.
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=44150
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e94807759eb6cfb10bd2d372fa71cc64a730bc7c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 11 12:13:18 2012 +0000
+
+    sna/gen6: Special case spans with no transform
+    
+    As the no transform is a special case of affine, we were attempting to
+    deference the NULL transform in order to determine if it was a simple
+    no-rotation matrix. As the operation is extremely simple, add a special
+    case vertex program to speed it up.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0a5313900ec9a7c499eb5051f3a5f078a9b0bbde
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 11 12:09:13 2012 +0000
+
+    sna: Explicitly retire the bo following a serialisation point
+    
+    This is to keep the sanity checks in order, but conceptually should be
+    useful as well.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2add5991a7d186d8271cb79ae4f62dad7b4ca243
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 11 11:33:19 2012 +0000
+
+    sna: Mark the bo as no longer in the GPU domain after clearing needs_flush
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fec70985719eec75b7fa799bddc3115fb329ab86
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 11 10:57:57 2012 +0000
+
+    sna: Add assertions to track requests
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a93c93be76f6d5d2b481971349aabd15f282c3e8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 11 00:05:20 2012 +0000
+
+    sna/gen6: Add a vertex program for a simple (affine, no rotation) spans
+    
+    I long for the day when this code is obsolete... Until then, this gives
+    a nice boost in the fishtank.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3cf5da1090ac777044912ec24619d349d1f6b521
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 10 23:32:29 2012 +0000
+
+    sna: Amalgamate small replacements into upload buffers
+    
+    Similar for the standard io paths, try to reuse an upload buffer for a
+    small replacement pixmap.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f0e3f6b5bebf7471d3e3e84bd9b2d8469eb64093
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 10 22:12:41 2012 +0000
+
+    sna: Check needs-flush status immediately upon destroy
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b4ae6dbaedd774f250b610b1e7323897c4abe23a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 10 21:25:28 2012 +0000
+
+    sna: Align the small upload buffers to 2 texels, and the pitch to dwords
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=44150
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 46f6c6917effbc43305367581cc1bbaa962c0251
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 10 20:34:09 2012 +0000
+
+    sna: A partial read buffer is allowed to be in the GPU domain
+    
+    As we can create the read buffer from an active cached bo, it may
+    already be in the GPU domain by the time we first finish it, so fix the
+    broken assertion.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3c26055639f789b211f7db982e65ec0b86b23d4a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 10 20:06:51 2012 +0000
+
+    sna: Shrink the partial upload buffers before compacting the batch
+    
+    So that the relocation entries point into the contiguous surface/batch
+    and can be trivially fixed up.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7b077a4d3d549cde79d5b876289203788294493c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 10 18:40:53 2012 +0000
+
+    sna: Make the check for a single fill-rectangle clearer before modifying damage
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ca2a07adc45273dc1abeb4b3ba7f88461aaf9c00
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 10 17:13:38 2012 +0000
+
+    sna: Release the stale GTT mapping after recreating the bo with new tiling
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8dd913fd3a093b54fc024fea2b31a3db2518db8d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 10 10:38:43 2012 +0000
+
+    sna: Add reminder about possible future tiling optimisations
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 21948578d0d87f38447ef1ae44fada406949bca8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 10 03:19:16 2012 +0000
+
+    sna: Disable the inline xRGB to ARGB upload conversion
+    
+    As we have to upload the dirty data anyway, setting the
+    alpha-channel to 0xff should be free. Not so for firefox-asteroids on
+    Atom at least.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 87f73b043426c47efa7670fb65bdcc7dfcf71fc3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 10 01:42:37 2012 +0000
+
+    sna/gen[23]: Tile render fill to oversized bo
+    
+    If we are forced to perform a render operation to a bo too large to fit
+    in the pipeline, copy to an intermediate and split the operation into
+    tiles rather than fallback.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2ccb31c5a4120efb940168c5e52154add01b0586
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 10 01:41:09 2012 +0000
+
+    sna: Shrink upoads buffers
+    
+    If we do not fill the whole upload buffer, we may be able to reuse a
+    smaller buffer that is currently bound in the GTT. Ideally, this will
+    keep our RSS trim.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 572cc76be5c78102166f2b3640640e21acdfa129
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 10 09:13:34 2012 +0000
+
+    sna: Destroy the counter damage after a reduction-to-all
+    
+    If, for instance, we reduce the GPU damage to all we know that there can
+    be no CPU damage even though it may still have a region with a list of
+    subtractions. Take advantage of this knowledge and cheaply discard that
+    damage without having to evaluate it.
+    
+    This should prevent a paranoid assertion that there is no cpu damage
+    when discarding the CPU bo for an active pixmap.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4a255e13164440b797e5ac11dcbf72f0827a3094
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 10 16:34:23 2012 +0000
+
+    sna: Replace the free-inactive-gpu-bo with the generic code
+    
+    The function was semantically equivalent to moving the pixmap to the CPU
+    for writing, so replace it with a call to the generic function.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c1d403266a611a68081690d19f6debb8e343095f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 10 00:41:05 2012 +0000
+
+    sna: Allow for xRGB uploads to replace their target bo
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 406776cd955c3c384d4a537300e21eebe4413666
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 10 00:25:14 2012 +0000
+
+    sna: Rearrange buffer allocation to prefer llc bo over vmaps
+    
+    If we can create snoopable bo, we prefer to use those as creating a vmap
+    forces a new bo creation increasing GTT pressure.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b76865fa3deff2f44a1158914a124b9c81d67eca
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jan 9 22:11:21 2012 +0000
+
+    sna/gen2: Try to avoid creating a bo for solid colours
+    
+    As we try to use the diffuse/specular and only resort to using a texture
+    operation for convenience in the rare case of a solid mask.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 981aae104a96b41db88cc381cc7592818f3e1298
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jan 9 22:02:40 2012 +0000
+
+    sna/gen2: Eliminate some switching between logic op and blend
+    
+    If the new mode can be done either using a logic op or with the blend
+    unit, prefer the currently enabled unit.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d65b7f9cf46a48e3bfb37c0b75df55aa1e7bff41
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jan 9 21:58:03 2012 +0000
+
+    sna/blt: Rearrange to reduce a out-of-bounds copy to a clear
+    
+    If we asked to use the BLT, try to avoid trigging a context switch for
+    a trivial case where we sample outside of a NONE source and so can
+    reduce the operation to a clear.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 09e54c553680cbc2f3b4319cdab0f3d1af1574a8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jan 9 14:04:41 2012 +0000
+
+    sna/gen2: Add poor-man's linear gradient support
+    
+    Convert the linear gradient to a texture ramp and compute the texture
+    coordinates in the standard manner.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6c70558ae7298db94724c931d88a730ef0151608
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jan 8 20:48:48 2012 +0000
+
+    sna: mark the cpu bo used for the upload buffer as in CPU domain
+    
+    For correctness we need to inform GEM of the change of domain for the
+    buffer so that it knows to invalidate any caches when it is next used by
+    the GPU.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9ec31af02922bb016d0dfba07bc60cdca35b36f8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jan 8 15:52:17 2012 +0000
+
+    sna/io: Combine small uploads into single writes
+    
+    For a small update, try and amalgamate the upload buffer.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4db1bb3fd81b51e74b7f3e90078627d9d96fbefe
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jan 8 14:20:40 2012 +0000
+
+    Removed deprecated xf86PciInfo.h includes
+    
+    The driver should and does provide its own PCI-IDs.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 54232d1a5da51d0f68fe099436bb0a1a2e249954
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jan 8 15:22:58 2012 +0000
+
+    sna: Add ricer stripes to memcpy_xor
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c037b4f542a7b21cbaecedec259da3589db10039
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jan 8 08:58:41 2012 +0000
+
+    sna: Tune cache size for cpu bo cache
+    
+    This helps SNB on cairo-traces that utilize lots of temporary uploads
+    (rasterised sources and masks for instance), but comes at a cost of
+    regressing others...
+    
+    In order to counter the regression from increasing the GTT cache size,
+    the CPU/GTT vma cache are split and accounted separately.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 26042b2660d87044e1920a1267d9984c00c9566a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jan 8 11:45:11 2012 +0000
+
+    sna: Bubble sort the partial buffer list back into order after trimming padding
+    
+    After reducing the used size in the partial buffer, we need to resort
+    the list to maintain the list in decreasing amount of available space.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3f7ea44bf19a03ee81b683885c9c2416092254a3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jan 8 02:27:28 2012 +0000
+
+    sna/gen[67]: Hook into the clear operation for glyph masks
+    
+    Allow SandyBridge to specialise its clear routine to reduce the number
+    of ring switches. It may be interesting to specialise the clear routines
+    even further and use the special render clear commands...
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 803ac5c6b992cb5448c67b11345b87a5d2b9c60d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jan 8 01:38:09 2012 +0000
+
+    sna/trapezoids: Don't risk stalling for inplace SRC trapezoids
+    
+    Optimistically we would replace the GPU damage with the new set of
+    trapezoids. However, if any partial damage remains then the next
+    operation which is often to composite another layer of trapezoids (for
+    complex clipmasks) using IN will then stall.
+    
+    This fixes a regression in firefox-fishbowl (and lesser regressions
+    throughout the cairo-traces).
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0229841c0d705138d6317a22ba80f4fa10d26acc
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jan 8 01:46:24 2012 +0000
+
+    sna: Do not upload an untiled GPU bo if we already have a CPU bo
+    
+    Continuing the tuning for sna_copy_boxes.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 42eb9b7c4b55b620d9652ad3a54c8ab0a76fd7c2
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jan 8 00:21:26 2012 +0000
+
+    sna: Trim usage of vmapping
+    
+    The first, and likely only, goal is to support SHMPixmap efficiently
+    (and without compromising SHMImage!) which we want to preserve as vmaps
+    and never create a GPU bo. For all other use cases, we will want to
+    create snoopable CPU bo ala the LLC buffers on SandyBridge.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e52f0204939924181480feec6d1511259169c8f1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jan 8 00:20:11 2012 +0000
+
+    sna: Do not move-to-gpu for sna_copy_boxes if we have a cpu bo
+    
+    We trade-off the extra copy in the hope that as we haven't used the GPU
+    bo before then, we won't need it again.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c05e90aa99c093431a74a94ceba27d7dce49d05b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jan 7 18:23:43 2012 +0000
+
+    sna: Missing chunks from last commit
+    
+    And update the check for reusing the blit!
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 292aebfcdc042b08d3a5a21f839e6aec1175359e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jan 7 18:09:47 2012 +0000
+
+    sna: Prevent reuse of scanlines after the buffer is destroyed
+    
+    Once the buffer is destroyed, it may be reallocated with a new pitch. We
+    could track handle and pitch, but it is easier to simply restart the
+    blit after the buffer is freed.
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=44277
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=44555
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d7d07d1df3ffc889ccc32c2ed44ce374e37f851d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jan 7 10:37:01 2012 +0000
+
+    sna: Pad upload buffers to ensure there are an even number of rows
+    
+    One restriction common to all generations is that samplers access pairs
+    of rows and so we need to pad the buffer to accommodate access to that
+    second row. Do so unconditionally along paths that may be used by the
+    render pipeline.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e2ad0f6272c776939499c6202fb60bdcc2e955fa
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jan 6 17:11:00 2012 +0000
+
+    sna/blt: Amalgamate many PolyFillRect of single boxes
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c085de905c30cb5bae6b339841badf1e105c6ee6
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jan 6 15:47:47 2012 +0000
+
+    sna: Also mark a bo created by force-to-gpu as being all-damaged
+    
+    Similar to the action taken into move-to-gpu so that we forgo the
+    overhead of damage tracking when the initial act of creation is on the
+    render paths.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9f1935bb4e894264053d94e53c99d5ad607700fb
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jan 6 15:26:11 2012 +0000
+
+    sna: Support performing alpha-fixup on the source
+    
+    By inlining the swizzling of the alpha-channel we can support BLT copies
+    from an alpha-less pixmap to an alpha-destination.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 141001df6c9c3485c500ed531a214c09b46c1d3b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jan 6 13:35:27 2012 +0000
+
+    sna: always skip active search when requested for find an inactive bo
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=44504
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit eac0d9652b2399f8c36ba0288db6fe347ed78dc9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jan 6 12:39:49 2012 +0000
+
+    sna: Optimise sna_poly_segment() for the frequent no-op case
+    
+    Strange as it may seem... But the principle of doing less work with
+    greater locality should help everywhere, just not as noticeable when
+    real work is performed.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a3699fff5ada85e4dea739aade25ebbb728e18f4
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jan 6 12:15:46 2012 +0000
+
+    sna: Only force a pipeline flush for a change of destination, not sources
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2fefee6015ed2df52c8513ae180ca83c01ff83c0
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jan 6 12:10:27 2012 +0000
+
+    sna/gen6: Reuse current no-blending setup for PictOpClear
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 800ca0b4d1194544fe2461f91cbdc632c4d3dd7a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jan 6 12:00:43 2012 +0000
+
+    sna/gen6: Tidy emission of CC state (blending)
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b9c9e9970cdb542173e3ed0da2bef614abedd3f7
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jan 6 11:38:31 2012 +0000
+
+    sna/trapezoids: Add debug markers for move-to-cpu
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2841c5fee79c42bca3e098ec620755d341b6888f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jan 6 11:32:54 2012 +0000
+
+    sna: fast path move-to-cpu of an all-damaged CPU bo
+    
+    When the bo is already completely damaged on the CPU, all we need to do
+    is to sync with the CPU bo.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 07f1724ba5759772043fc4c5d1163ddd640004c2
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jan 6 11:00:38 2012 +0000
+
+    sna: Pass the real destination pixmap to sna_write_boxes()
+    
+    Faking it for the render upload simply isn't good enough, since we need
+    the correct drawrect.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5c2e9a98715eeddd8dfdff9fe3871bde659484cc
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jan 6 02:26:39 2012 +0000
+
+    sna/trapezoids: Use a slightly faster miTrapezoidBounds()
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 75f61678249018c84872c61b4609ba9d3d0d73dc
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jan 6 01:38:42 2012 +0000
+
+    sna: Only need to remove the pixmap from the dirty CPU list when clearing damage
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 86cc2cd3343c16b12e35e2048c113481f49196cf
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jan 6 01:31:15 2012 +0000
+
+    sna: The condition for automatically using the GPU source is no CPU damage
+    
+    With no CPU damage to upload, we know that there is no reason not to use
+    the GPU bo.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 69c556c310da544ddb66c2441f5d06dca29fb9f3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jan 6 00:21:29 2012 +0000
+
+    sna: Rearrange use-cpu-bo to avoid reducing GPU damage
+    
+    If we spot that the region is wholly contained within the CPU damage
+    initially, we can conclude that is not in the GPU damage without
+    reduction.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 34c4dbe825a45315b05f0bd49539cbcf5de276f1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 5 23:18:37 2012 +0000
+
+    sna/gen6: Only force BLT if the src and dst overlaps for self-copy
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fc79af7a4abf1f0ceccacf23e8467ee2872eec09
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 5 23:06:17 2012 +0000
+
+    sna: Only force a batch continuation if the scanout is written to
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c16c16d2553aa9a8bf9b0b0b367715b59020a357
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 5 22:51:55 2012 +0000
+
+    sna/gen6: Enable reuse of source Picture
+    
+    Check if the source and mask are identical pictures and just copy the
+    source channel to the mask in that case.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f642b08870c6d7686368e053962075c153f76f86
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 5 22:26:09 2012 +0000
+
+    sna: Quickly handle the common case of using a CPU source pixmap
+    
+    For the common case (at least with llc bo) where we are immediately
+    using an uploaded image from its linear buffer, check upfront before
+    computing the sampled region for transfer to the GPU.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8a9baa59e9d0c0761b82f23734514f6847a9bcc1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 5 22:16:31 2012 +0000
+
+    sna: Quickly handle the common case of using a GPU source pixmap
+    
+    For the common case of glyphs, the pixmap is entirely on the GPU which
+    can be quickly tested before performing the more complex transformations
+    to determine how much pixel data we need to upload.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d4dad6e3723d70d78247f29f86079862af175266
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 5 21:39:24 2012 +0000
+
+    sna: Check that the GTT is no longer mapped before ensuring the shadow pointer
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 352f0a3ffb8ae8503bb2fab779ea84f4e6d76317
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 5 21:33:26 2012 +0000
+
+    sna: Only mark the pixmap as GTT mapped if the private owns the pixels
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3061382f98c0b284c250c1a36f7a4fee22046664
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 5 21:05:52 2012 +0000
+
+    sna: Make sure that we do not attach to SHM pixmaps in ignorance
+    
+    Without xserver support for notification of when scratch pixmaps are
+    reused, we simply cannot attach our privates to them lest we cause
+    corruption with SHM pixmaps.
+    
+    This is a recent regression back unto an old, old xserver issue.
+    
+    Reported-by: Paul Neumann <paul104x@yahoo.de>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=44503
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f7431726338e72d7a989e838f48aecdab15ab366
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 5 20:26:30 2012 +0000
+
+    sna: Add more debugging to use-gpu-bo
+    
+    To aide debugging in conjunction with compositors and their crazy
+    offsets.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 53c943b551b86402067ea96cd9fcca2848e84387
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 5 18:41:26 2012 +0000
+
+    sna: Check for usable pixmap before deference its private
+    
+    Beware the NULL pointer and early deference.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 307276d7da99ceb84c175e412452e5d86d615cf4
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 5 14:26:05 2012 +0000
+
+    sna: Enable using the render pipeline for uploads to Y-tiled pixmaps
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f9451aaa39e1d77b08d2201f5c4a44ab834f2237
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 5 14:22:21 2012 +0000
+
+    sna: Mark the upload as having acquired the GTT mapping
+    
+    In order for the entire PutImage to be performed inplace, we need to
+    maintain the tendency to keep doing inplace operations. This hint is
+    provided by tracking whether or not the last operation used the GTT
+    mapping. However, that hint was not being provided by zpixmap_blt.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ce93c00a33a395986ffc0d33aae85d2c23aabc5d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 5 14:20:55 2012 +0000
+
+    sna: Avoid operating inplace if we have pending CPU damage
+    
+    If the operation does not replace existing CPU damage, we are likely to
+    want to reuse the pixmap again on the CPU, so avoid mixing CPU/GPU
+    operations.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f5d02d90f3349f33341954fc55824d12a7829e6c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 5 12:56:21 2012 +0000
+
+    sna: Avoid switching rings for uploading data
+    
+    On systems that incur painful overhead for ring switches, it is usually
+    better to create a large buffer and perform a sparse copy on the same
+    ring than create a compact buffer and use the BLT.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a42111ff94911d5fad34e6dbac8aa4a11b2d8032
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 5 12:12:22 2012 +0000
+
+    sna/trapezoids: Try creating the trapezoids mask inplace if not using spans
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4c6ccbd46a1681c73382b79a0246f7d8cb097606
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 5 11:09:01 2012 +0000
+
+    sna: Throttle, throttle, throttle.
+    
+    This reverts 281425551bdab7eb38ae167a3205b14ae3599c49 as it was causing
+    insufferable lag in firefox.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit dbb495c3aeef34eab2aabfdfaafb81facdea4100
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 5 10:34:08 2012 +0000
+
+    sna: Attach to the pixmap for source counting when deferring uploads
+    
+    If we decide to defer the upload for this instance of the source pixmap,
+    mark it so. Then if we do use it again we will upload it to a GPU bo and
+    hopefully reuse those pixels.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 292097590ba0f81b7505aedb2a4fbd18021641a5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 5 10:31:15 2012 +0000
+
+    sna: Try doing a cheap is-contained check before reducing damage
+    
+    If the pixmap is entirely within the current CPU damage, we can forgo
+    reducing either the GPU or CPU damage when checking whether we need to
+    upload dirty pixels for a source texture.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5ddae8bf21067e7d2a031a6b9020c02ab977cfed
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 5 10:27:37 2012 +0000
+
+    sna: Check the composite-rectangles will be on the GPU before forcibly attaching
+    
+    If we think that the operation is better performed on the CPU, avoid the
+    overhead of manipulating our privates.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6ffd3605640bacaf0d744075622463aacf78d797
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 5 10:25:12 2012 +0000
+
+    sna: Deferred attachment to a pixmap needs to mark the pixmap as entirely dirty
+    
+    As demonstrated with oversized glyphs and a chain of catastrophy, when
+    attaching our private to a pixmap after creation we need to mark the
+    entire CPU pixmap as dirty as we never tracked exactly which bits were
+    dirtied.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a09ebe0b6cc66d08e52b57851d9b8a6a1f71df2b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 5 10:23:25 2012 +0000
+
+    sna: Immediately upload oversized glyphs
+    
+    Glyphs, even large ones, we suspect will be reused and so the deferred
+    upload is counterproductive. Upload them immediately and mark them as
+    special creatures for later debugging.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 797b27365dc09a3f84349a33cffbfdc67cba0baa
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 5 10:30:47 2012 +0000
+
+    sna: Don't perform a deferred attachment for vmapping if not supported
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 23e3959e1f603c3ba0bd4f01128290241cf93edf
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 5 04:00:32 2012 +0000
+
+    sna: Use the created cpu-bo for upload and download
+    
+    As we explicitly create CPU bo when wanted, we no longer desire to
+    spontaneously create vmaps for simply uploading to the GPU bo.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4530b87e445aea30ccbe751699963118ad5672d4
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jan 5 00:01:27 2012 +0000
+
+    sna: Fix assertion as we may want to create active bo with cpu mappings
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4119e68fb157fc612bce5e9c5669112ce35b4ca1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 4 19:35:30 2012 +0000
+
+    sna/damage: Fix reduction to copy the boxes correctly
+    
+    We need to be carefully to copy the boxes in a strict lifo order so as
+    to avoid overwritting the last boxes when reusing the array allocations.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 71b0924b586d9a60397e92e941e3d0cfa636ee61
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 4 19:34:41 2012 +0000
+
+    sna: Mark tiny CPU pixmaps as completely dirty
+    
+    Avoid the overhead of tracking damage on small pixmaps when using CPU
+    rasterisation; the extra cost of sending the whole pixmap compared to
+    the damage is negligble should it ever be required on the GPU.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fc14e63256a9b756c7c77ffe73f2f13784396c5a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 4 19:33:30 2012 +0000
+
+    sna: Only request page size allocations for the replacement buffer
+    
+    A precondition on bo creation is that the size must be page aligned.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 89739b711f42c3dbed7d3f4e6da0cdd61a5205ae
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 4 17:41:16 2012 +0000
+
+    sna: Expand small stipples into 8x8 patterns
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 878fbfe509da0a25dff8515d6d3b38ca3826466e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 4 16:56:55 2012 +0000
+
+    sna: Align tiled stipple uploads with the stipple pixmap correctly
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 28a222a66bb450c7f6d61aef16fe73332854c8ce
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 4 12:48:25 2012 +0000
+
+    sna: Always prefer to use cacheable operations after the GPU is wedged
+    
+    As rasterisation will be performed upon the CPU we need to avoid the
+    readbacks form uncached memory and so we should restrict ourselves to
+    only create further damage within the CPU pixmap.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 99ff83a3bebf1aa25c44a87f2c344307d20bc062
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 4 12:35:12 2012 +0000
+
+    sna: Prevent creation of bo purely for GTT mapping when wedged
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a7c35fa4c3155d10ad75ac33aefb03dafa010aba
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 4 12:33:09 2012 +0000
+
+    sna: Only allow mappable pixmaps to be mapped
+    
+    If we did not allocate the pixel data, such as for wedged pixmaps or
+    scratch buffers, then we cannot perform the pointer dance nor do we want
+    to create the GPU buffer.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2cbc97d28aae138566e49df05e16d274b533ea86
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 4 12:32:06 2012 +0000
+
+    sna: Force creation of ordinary pixmaps when wedged.
+    
+    If the pixmap was intended for scanout, then the GPU bo will be created
+    upon attachment to the fb.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f6cc73ba66f34d190b7c17421a62aa1256698431
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 4 12:56:31 2012 +0000
+
+    sna: The batch is counted in dwords, not bytes!
+    
+    Yikes, I choose the wrong units for the max_batch_size.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 227fbb90c4884bbc58c6c0cfff9663ec9ca54171
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 4 11:47:32 2012 +0000
+
+    sna: Carefully free the freed_pixmap upon exit
+    
+    As the contents of the pixmap are now rubbish, we need to manually
+    destroy it rather than pass it to the normal sna_pixmap_destroy()
+    routines.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0ed758cd2176ee4f34e03d05d05130d52d75e577
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 4 12:18:20 2012 +0000
+
+    sna: Limit batch to a single page on 865g
+    
+    Verified on real hw, this undocumented (at least in the bspec before me)
+    bug truly exists.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3449f1cbe184a618e662d2a662167f05362b82e5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 4 02:38:16 2012 +0000
+
+    sna: Guard against NULL damage deref
+    
+    The fast version of damage checking assumes that the damage has already
+    been determined to be non-NULL, so make sure it is.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 04a6260016fb5ebefc1056ed6acf5001ec535d5c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 4 01:14:19 2012 +0000
+
+    sna: Fix typo during partial list deletion
+    
+    And keep the asserts that lead to its discovery.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f1dc1eadd84097fc691e85c636535ceeeb601a18
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jan 4 00:09:30 2012 +0000
+
+    sna/gen3: Remove incorrect premultiplication of solid component-alpha mask
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8cb9b8d7d7a1eb62eb3b20e6a50d3f1c9bde40c1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 3 23:13:24 2012 +0000
+
+    sna: Discard mask and source for PictOpClear
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit feb75c55d6105a9ecc5f5ec7830276d1654918b9
+Author: Zhigang Gong <zhigang.gong@linux.intel.com>
+Date:   Sat Dec 31 21:18:15 2011 +0800
+
+    uxa/glamor: Route some missing drawing function to glamor
+    
+    We have to route all the drawing function to glamor first, when
+    glamor is enabled. This adds a few more functions that were previously
+    just falling back to swrast and passes them to glamor instead.
+    
+    Signed-off-by: Zhigang Gong <zhigang.gong@linux.intel.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f4ea732d7181d4ef7f97fb2585e87cdcaef99d46
+Author: Zhigang Gong <zhigang.gong@linux.intel.com>
+Date:   Tue Dec 27 17:09:17 2011 +0800
+
+    uxa/glamor: Let glamor do the GC validation
+    
+    If we are using GLAMOR, then a tile pixmap or stipple pixmap
+    may be pure glamor pixmap and thus UXA will not know how to
+    render to them, and we need to let glamor do the validation.
+    
+    Signed-off-by: Zhigang Gong <zhigang.gong@linux.intel.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e8aa9cedbfca09e22d46ec8882b9bebb3eb83022
+Author: Zhigang Gong <zhigang.gong@linux.intel.com>
+Date:   Tue Dec 27 17:09:16 2011 +0800
+
+    uxa/glamor: Remove extraneous flush
+    
+    When glamor is enabled, a pixmap will not be accessed by UXA's
+    accelerated functions. Only unaccelerated functions may access those
+    pixmaps, and before each unaccelerated rendering, it calls
+    uxa_prepare_access which will do a glFlush. Combined with a flush before
+    sending to DRI clients, we no longer need to flush after every
+    operation.
+    
+    Signed-off-by: Zhigang Gong <zhigang.gong@linux.intel.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4ca94ed91fab7a9de5eed1053b891e8420cdf43d
+Author: Zhigang Gong <zhigang.gong@linux.intel.com>
+Date:   Tue Dec 27 17:09:15 2011 +0800
+
+    uxa/glamor: Remove dead code.
+    
+    Signed-off-by: Zhigang Gong <zhigang.gong@linux.intel.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5576afc7d12ec0f028e416f4b4a076fc6d3c29d9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 3 16:48:52 2012 +0000
+
+    sna: Inline checks for over-sized buffers during pixmap creation
+    
+    Make the tests for acceptable GPU pixmaps explicit and upfront.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b2dc17678fa3a548be61e1055d4d321dbd6494c3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 3 15:50:21 2012 +0000
+
+    sna: Always search for an exact active match first from the bo-cache
+    
+    And accept second-best only if permitted by flags.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit caf41ae23d263c7baed6b23a80693690c4dfe563
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 3 15:11:13 2012 +0000
+
+    sna: Force tiling on medium pitches if not reduced for other reasons
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1b688ca0cfc1e623f896e60a6a6abf724d57efb4
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 3 14:18:05 2012 +0000
+
+    sna: Delete the last buffer if destroyed without being used on the GPU
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4a68e7277104d7dccbdc4739eb5651902b9ccc20
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 3 12:19:24 2012 +0000
+
+    sna/gen3: Prefer to use the blitter for solid fills
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 199e357dc693cfe232464e4faa82d9223a8325d6
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 3 12:16:48 2012 +0000
+
+    sna/trapezoids: Pass the sna pointer to the callees
+    
+    Avoid the repeated multiple indirect dereferences.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit bd7aa1754dcf9d58d7deb92d99da9b78c91a0eb2
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 3 12:46:40 2012 +0000
+
+    sna: Avoid unnecessary call overhead for read-only move-to-cpu
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 294c8791c435acf5933109fbcab85623a55b2c6c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 3 12:09:51 2012 +0000
+
+    sna: Use a cheaper no-reduction damage check for simply discarding further damage
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7ff42e9c83cdb17660a64901497704b38032af8c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 3 19:15:07 2012 +0000
+
+    sna/damage: Mark the box as packed so that the embedded_box is aligned correctly
+    
+    valgrind was complaining about an overlapping memcpy on a 64-bit
+    platform as gcc padded the sna_damage_box to 28 bytes...
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4652a20de5fee0d5d1a8baadc4a93b6a93525564
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jan 3 21:20:09 2012 +0000
+
+    sna/gen3: Check for a non-NULL bo before incrementing its ref in reuse_source()
+    
+    For gen3, we may reduce a source into a constant operator and so
+    dispense with keeping a bo. When duplicated into the mask channel, we
+    then need to be careful not to dereference the NULL pointer.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 777fcc9b11e8cbfe942aa6bf898749f552acb3cf
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jan 1 16:03:42 2012 +0000
+
+    sna: Prefer not to force the creation of gpu bo for pixmap uploads
+    
+    As this causes a significant regression when benchmarking firefox on SNB
+    with firefox-planet-gnome if we already have CPU buffers.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1a6c16a24cb74f82df9757c034c50f2cf141523f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jan 1 14:32:48 2012 +0000
+
+    sna: Keep a freelist of buffers
+    
+    As reallocation of bo is the most frequent cause of malloc/free.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f008a2a90c632d843f07846426f6d14af728c13b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jan 1 10:24:49 2012 +0000
+
+    sna: Tune blt routine
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b57c7248acc2ad6a51b7eac74449d155defc998f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jan 1 14:10:20 2012 +0000
+
+    sna: Delete some redundant code
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 83d16455b70e2f0348e51f95128d4fcae3736e7f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jan 1 13:58:44 2012 +0000
+
+    sna: Eliminate one union pass when reducing damage-add
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2f5b769e7144c7b85010429e6d8aebf9c9fc1628
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jan 1 10:00:37 2012 +0000
+
+    sna: Move some checks against programming errors to asserts
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 24bf59c43fbedd9d85c913ac3c7f0e752c232eb4
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Dec 31 18:57:57 2011 +0000
+
+    Revert "sna: Increase the minimum alignment constraint for g33"
+    
+    This reverts commit 2934e778f01cdf1307732b248b11a31c0e79e866. The actual
+    cause of the bug I was seeing on my PNV box turned out to be
+    a1f585a3d0a, so time to reinvestigate the alignment issues.
+
+commit 770a953ff03bb8328c3f29e274d225528840f30c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Dec 31 17:19:08 2011 +0000
+
+    uxa/video: Clear all state structures before uploading
+    
+    A regression from eb859f644633e left some of the state uninitialised
+    before uploading to the GPU leading to undefined behaviour.
+    
+    Reported-by: Alexey Shumitsky <alexey.shumitsky@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=44338
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=44252
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f1995c684d2e074ae04c9e42727e59cc77e16104
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Dec 31 15:57:32 2011 +0000
+
+    uxa: the video destination should be in the render write domain
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 511146d2e40e267f74e18c0dd06b65f5d6a69f5d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Dec 31 13:27:13 2011 +0000
+
+    sna: Implement inplace trapezoidal addition (for clipmasks)
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a1f585a3d0ae72e896684f62960a9ae96dc259f5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Dec 31 12:43:04 2011 +0000
+
+    sna: Update pixmap->devKind for GTT mappings
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 343de19ef98eea016601dbbe2d1f601dbff9de20
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Dec 31 11:19:44 2011 +0000
+
+    sna: Implement tiled uploads for small stipples larger than patterns
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fb15cf2294da20bfc375ae62443b822770850316
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Dec 31 10:24:58 2011 +0000
+
+    sna: Make sure the shadow pixmap is suitable for scanout
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 281425551bdab7eb38ae167a3205b14ae3599c49
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Dec 31 10:10:00 2011 +0000
+
+    sna: Tweak throttling to be run before going idle
+    
+    The goal is to avoid introducing extra latency in the middle of a
+    command sequence and to delay it until we have to wait for the clients.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2f5448f1329f344702e4e29b2509d7190677bbf0
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Dec 30 22:13:05 2011 +0000
+
+    sna: compare tiling against minimum width for relevancy
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e82b3d8069629ae5776e039d6ea1f3c901a3a094
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Dec 30 09:16:00 2011 +0000
+
+    sna: Defer the initial source upload if the GPU bo will be untiled
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 72624b0b5ba6549cb8d96f992d2656a28ec6078c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Dec 29 22:43:35 2011 +0000
+
+    sna: Remove redundant use-gpu-bo clause
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6dc9bbc0161f071bbaf5c7e379974158a5ad666f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Dec 29 22:43:44 2011 +0000
+
+    sna: Fix DBG for no intersection with damage
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0dc5c0651cb691fb8811cdf3075b3d322f9d37f8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Dec 29 13:49:23 2011 +0000
+
+    sna: Tune disarming of the scanout flush timer
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ccd895c61d9f409a36c70eaf02d7ab43cc6c03c2
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Dec 29 12:09:04 2011 +0000
+
+    sna: Allow uploading inplace to a freshly created GPU bo
+    
+    If the operation is favoured to be performed using a WC upload, presume
+    that we will use the uploaded pixmap on the GPU and so prefer to create
+    a GPU buffer to hold the fresh data.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f85a853455249fd782e907ce1d78d11f75362def
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Dec 29 11:59:57 2011 +0000
+
+    sna: Only update the damage region as necesary for contains-box
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f53936407bd68f3d36ab525b4e0531fad58098e3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Dec 29 11:59:37 2011 +0000
+
+    sna: Reset the source counter upon dirtying the shadow pixmap
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c9f7f10bc528ac783f4e89bdb36fc56ccdcd0088
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Dec 29 09:03:21 2011 +0000
+
+    sna: Be paranoid and check for errors from mmapping the bo
+    
+    Now that the error propagation is actually in place, we may as well use
+    it.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 98e053503aed292beb2006043e8508d59262c7c2
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Dec 29 08:50:53 2011 +0000
+
+    uxa: Depend upon DRI2 not DRI
+    
+    The symbols required for building intel_dri.c are checked during
+    configure under the DRI2 defines.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 58cee9d0def82d19f03c840325b6e84c20e77ace
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Dec 28 22:52:58 2011 +0000
+
+    sna/dri: Update set_bo() for change of bo ownership transfer during page-flip
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f9ee02be269d1658d3a8a5166e9bd2a49ab6dea0
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Dec 28 22:52:44 2011 +0000
+
+    sna: Fix debug message for read-boxes
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 698bd43e0f7a59bcce6601b0c96df85935e54bb3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Dec 28 21:45:12 2011 +0000
+
+    sna: Do not create glyph caches if the gpu is wedged
+    
+    As these will only be created in normal memory and never used.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 78425a15597079c0549de0fa1bbbdbebcf9eaf28
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Dec 28 15:26:14 2011 +0000
+
+    sna: Refactor common code for testing gpu busyness of a pixmap
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9105b7e03ab7e3602c7200ebdc44e89f873afe1f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Dec 28 13:46:18 2011 +0000
+
+    sna: Perform clip mask compositing inplace
+    
+    Avoid the extra composite-in pass for simple clipmask construction.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a5583165da0d2ae5eb1e5a2e11ee6e245d4b5aa4
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Dec 28 13:57:09 2011 +0000
+
+    uxa: Remove concept of global FB ownership made obsolete by GEM and KMS
+    
+    With the introduction of GEM, we can continue to submit batch buffers
+    irrespective of ownership of the console, so do so.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 337635ab97bbfc9b4455eadb63214783bb90bb2b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Dec 28 10:56:57 2011 +0000
+
+    sna: Add some more debugging to find the source of a read-boxes error
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3bf81241cbc97763e5f3cbc82772437ccbff5a6c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Dec 27 17:09:59 2011 +0000
+
+    sna: Skip zero-sized glyphs
+    
+    Similar to the empty glyphs make sure that we just advance by the
+    character width without drawing anything.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8fc21328a0bdf87fde35d68d2b27834011acde7b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Dec 27 15:26:46 2011 +0000
+
+    sna: Don't discard empty glyphs, just skip them
+    
+    A space is encoded as a 1x1 blank glyph, but we still need to advance by
+    its character width and so we cannot simply discard the glyph.
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=44091id=44091
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 726290ea2a54716d3d8fb998fe7d2ab252421de7
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Dec 27 13:16:34 2011 +0000
+
+    sna: Rearrange damage for tail-call optimisations
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 04396b6e5039c0cd1ac655a8a9afe88bb8a1ebde
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Dec 27 09:58:40 2011 +0000
+
+    sna: Don't force the creation of a GPU bo if it will be untiled
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 655a96cd5f12ff7fe593e7da5f34c7c92ef9b87d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Dec 26 14:37:37 2011 +0000
+
+    sna: Mark the glyph cache as being unpageable
+    
+    In order to prevent it falling foul of the inactive pixmap reaper, we
+    need to mark the pixmap as pinned.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2934e778f01cdf1307732b248b11a31c0e79e866
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Dec 26 11:30:39 2011 +0000
+
+    sna: Increase the minimum alignment constraint for g33
+    
+    Still not getting the single-stream mode that I am aiming for!
+    
+    Reported-by: Matti Hamalainen <ccr@tnsp.org>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=44150
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f7593a995a829978ce81397dde5c9ea6f9bb7681
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Dec 25 09:40:46 2011 +0000
+
+    sna: Move the is-mappable check into the callers of region_inplace()
+    
+    As they slightly differ in their requirements.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit aff32e3e08fce3c7b8dab3a25c96d69c409471fc
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Dec 25 00:36:33 2011 +0000
+
+    sna: Tweak damage not to reduce if it will not affect the outcome of reducing to all
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit be21a09fef0a3499153f2c123b65f1d5c872d437
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Dec 25 00:28:55 2011 +0000
+
+    sna: Only call move-to-gpu on scanout flush if we have cpu damage to move
+    
+    Reduce the number of redundant calls.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7b69dc88094ee2bb017364cd4356f3ae69cbc1f1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Dec 25 00:21:21 2011 +0000
+
+    sna: Inline the common portion of sna_get_pixel_from_rgba()
+    
+    The function overhead completely dominates for the common case.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b117f65520919f4ba36010cfe913a8c53166bf23
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Dec 24 21:03:01 2011 +0000
+
+    sna: Jump straight to the fallback copy routines if the dst is not attached
+    
+    Marginally simplify the convoluted logic for choosing the most
+    appropriate path and help prevent further errors.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 72217790ee2c080d618274456360b481d015e898
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Dec 24 19:14:09 2011 +0000
+
+    sna: Use shadow if the GPU is busy or not immediately mappable
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0be136c21f0373d1eb2259b83c598655f4eb841e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Dec 24 18:44:15 2011 +0000
+
+    sna: use indirect uploads if the bo was last known to be unmappable
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e764a52ee8f0c552e218b3110318be9ba06634ae
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Dec 24 15:17:06 2011 +0000
+
+    sna: Encourage large operations to be migrated to the GPU
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f9f8535db6a9e3affba9ba2c2a9314dfe12ab270
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Dec 24 21:01:39 2011 +0000
+
+    sna: Fix damage reduction by adding new boxes to the tail of the box list
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f8c91f229a9ca18fc58b0cabbea595d26627db8b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Dec 24 12:17:53 2011 +0000
+
+    sna: We can always compare the box to be subtracted against the dirty extents
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit cc21d3fa045209861564cf240a9a082e0bdb63f8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Dec 24 12:17:43 2011 +0000
+
+    sna/damage: Fix the is-contained test
+    
+    It was a non-overlapping test which is almost the reverse of what was
+    intended.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b86e4f59299f935d5a0ea8375da97e6fc57571f9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Dec 24 11:45:27 2011 +0000
+
+    sna: Check that the copy dst is attached before replacing damage
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3bcc9f08e1309725c18dfa5ca0e905bb88ebf4ea
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Dec 24 09:59:24 2011 +0000
+
+    sna: Create a GPU for a streaming write
+    
+    If we are about to do a write-only drawing operation that will exceed
+    our cache, allocate a GPU bo and perform the operation inplace.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit efc8d04fc114e9966e5ca00600f9663ecf03a5ca
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Dec 24 09:32:18 2011 +0000
+
+    sna: Promote an unattached pixmap to the GPU for inplace copies
+    
+    If we would prefer to perform the copy on the GPU and if the pixmap is
+    virgin, create a GPU bo for the operation.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8c0e7ff5ac996a5a5c0790966084d1c9e1b1f859
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Dec 24 09:19:18 2011 +0000
+
+    sna: Clear the CPU damage for other overwriting rectangular blits as well
+    
+    And make the accessing of the sna_pixmap safe -- it may not even exist!
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7f9ed3ca56466f319d9ec06aebb7055552fb1fe1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Dec 24 08:57:49 2011 +0000
+
+    sna: reset the pixmap on the initial clear after being swapped out
+    
+    Pixmaps are swapped out into the CPU after a period of inactivity. This
+    then prevents the core rendering routines from migrating the pixmap back
+    to the GPU until it gets used again on a Render path. However, we can
+    clear that CPU damage and enable migration before a number of key steps
+    in the expose process.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8c987b6ccfa83b99a316a7da49a6d7e30fcdf295
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Dec 24 09:09:58 2011 +0000
+
+    sna: Cheaply reduce damage when subtracting and removing the entire damage
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 098592ca5d79af2e4bdcd82ee598c4b2ba08df6b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Dec 24 02:49:24 2011 +0000
+
+    sna: Remove the independent tracking of elts from boxes
+    
+    Following the switch to a global mode for damage, the elts array became
+    redundant and all that is required is the list of boxes.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 73df0c7ab7c3a9edf0be2439c7e7ab07c0d75ecf
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Dec 24 02:48:18 2011 +0000
+
+    sna: Tune region upload inplace threshold
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ef66c5b5ad221211948ec795ade031591c3f0ac7
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Dec 24 00:15:33 2011 +0000
+
+    sna: Search the inactive VMA cache first for a linear mapping
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1cc07fa2d24b10ac95c7a84908290ec06539d447
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Dec 23 20:31:21 2011 +0000
+
+    sna: Avoid forced creation of GPU bo for tiny operations and dirty pixmaps
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e5bfea5826117bdd29664d83b3d478ff9db29ca3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Dec 23 20:30:58 2011 +0000
+
+    sna: Discard any GPU damage when overwriting with trapezoids
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 819dc93e52533afc9b9005db1472672c3d42229f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Dec 23 20:29:59 2011 +0000
+
+    sna/glyphs: Create GPU bo for large enough destination surfaces with glyphs
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9580ae8490a4119dac2fefe0085326db350209d7
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Dec 23 19:11:43 2011 +0000
+
+    sna: Pass usage-hint to move-to-gpu
+    
+    When simply creating a source GPU bo it is preferrable not to mark it as
+    all-damaged.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 98f15fc61361b7f1e01969f8d4237c13e93e3fb0
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Dec 23 17:25:42 2011 +0000
+
+    sna: Don't align pwrite to cachelines for doing discontiguous copies
+    
+    The batch compaction breaks the 1:1 mapping between the cpu buffer and
+    the bo, so we can no longer safely align the transfer to whole
+    cachelines.
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=44091
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3850f4ad48986691e1fb98038ae921deb6c25423
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Dec 23 12:42:02 2011 +0000
+
+    sna: Silence unsigned comparison against 0
+    
+    The good news is if this ever failed, the kernel is far too broken...
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d9ca113a83177562cde3537bf955164c6950cbd0
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Dec 23 10:06:58 2011 +0000
+
+    sna: Trim the unused pages from the batch between the last command and surface
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 013eda17e91ff421cd1ef70470e3575f1183fcbd
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Dec 23 10:40:58 2011 +0000
+
+    sna: Free the additional bindings on proxies
+
+commit 84d97bdba02b909369b54de21425ffc9f6ad581a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Dec 23 00:01:50 2011 +0000
+
+    sna/gen2+: Reuse source channel for mask where possible
+    
+    GTK+ has a clever trick for premultiplying its images by loading the
+    same pixel data into both the source and mask, and then performing the
+    composite. This causes us to upload the same pixel data twice!
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 281f620573917faef52d9226b12737ce1e2dffdc
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Dec 22 22:23:41 2011 +0000
+
+    sna: Age active wholly damaged GPU buffers more slowly
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f8575b8bd150ae11147fbf6b59171cbbb072dfec
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Dec 22 22:15:42 2011 +0000
+
+    sna: Cancel the immediate batch submit once handled in the block handler
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 609e1d9da282323ab7abc1baad4d3f24ac55588f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Dec 22 15:54:39 2011 +0000
+
+    sna: Bump the inactivity timeout
+    
+    With the goal of removing inactive pixmap froms the GPU after 5 minutes
+    of idleness.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 62602209e54c3568795122ee1c902c3b81985303
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Dec 22 14:20:20 2011 +0000
+
+    sna: discard damage-all even for width|height==0 operations
+    
+    Even if we don't know the extents of the render operation, if the entire
+    pixmap is damaged we can still reduce the damage tracking.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f68a99a55e1e63d7e76a13a7b77b4bb3f7802b9e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Dec 22 15:04:22 2011 +0000
+
+    sna: Mark fresh GPU only bo as being all damaged
+    
+    Presume that we will not fallback and so treat a GPU only bo (one that
+    is initially created on the GPU) as being all-damaged. This makes future
+    operations cheaper as the damage tracking overhead is much reduced, and
+    the cost of the first readback will mainly be in the synchronisation
+    overhead.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1f2cd536bc712843233de3f5c50802c388d63c72
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Dec 22 14:30:04 2011 +0000
+
+    sna: Reduce damage after complete solid fills
+    
+    RenderFillRectangles is often used to initially clear a pixmap after
+    creation by flooding it with a solid colour, as is PolyRect. We can
+    reduce further damage operations by checking for this condition.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7a6a2c5d4cc98da76c73152cb7eafcbdb0c088ec
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Dec 22 13:24:07 2011 +0000
+
+    sna: Setup the pixmap correctly in order to attach our private
+    
+    During creation of sna_pixmap we validate that we can use a GPU bo with
+    the target pixmap. This fails if we pass in a raw pixmap header, so
+    make sure the scratch pixmap is fully initialised first.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f621b3de841f6037d387ca1439a0abe12ef29811
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Dec 22 11:19:45 2011 +0000
+
+    sna: flatten source alphamaps
+    
+    Replace the source picture+alpha with a bo that contains the RGB
+    channels from source and A from the alpha map.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6c08eb4d6f8789e692ef018e007d1ae97a57c25f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Dec 22 11:42:39 2011 +0000
+
+    sna/gen2+: Prefer to use the CPU if we have a source alphamap and CPU pictures
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 354dc3c65b9cb86885b6927ee2b80cd2ee6a82ff
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Dec 21 21:35:06 2011 +0000
+
+    sna: Avoid fallbacks for convolutions by rendering the convolved texture
+    
+    If we have no shader support for generic convolutions, we currently
+    create the convolved texture using pixman. A multipass accumulation
+    algorithm can be implemented on top of CompositePicture, so try it!
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 34cfa15e522ba486d591d37f37d494e399f70354
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Dec 21 00:47:47 2011 +0000
+
+    sna: Drop suggested tiling parameter when creating bo
+    
+    The only place where we did anything other than use the default was when
+    creating a new bo for CopyArea. In that case, basing the choice on the
+    src GPU bo was not only wrong but a potential segfault.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4d348425592251f49fd31b9259651e8b05e92d1e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Dec 20 21:35:58 2011 +0000
+
+    sna: Intiialise pixmap size before use
+    
+    After 0c12f7cb0 we were setting the width/height of the pixmap *after*
+    trying to use them to determine if the pixmap could be created on the
+    GPU. Normally this would be corrected when we attempt to render, except
+    for the core drawing protocol.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e71058c9c81067cd72b1193242acbd85272ab73a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Dec 20 21:20:48 2011 +0000
+
+    sna: Always readback untiled bo in place
+    
+    We are going to gain no advantage from the kernel detiling the busy
+    buffer.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6690ff51ec939367051985172a00bf8ed65ac4e3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Dec 20 21:09:01 2011 +0000
+
+    sna: Treat all exported bo as potentially active
+    
+    Don't assume that a read/write will clear the active flag if the bo has
+    been exported to another DRI client.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 743084bbc4c411694190f60cf5161086ada6454f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Dec 20 20:42:08 2011 +0000
+
+    sna: Only upload tiny pixmaps on the second use
+    
+    Most small pixmaps appear to be single shot, so amalgamate them into one
+    buffer and trim our memory usage.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ca24ffe8b9acef034a5610376c73ebbdce87d41c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Dec 20 20:11:12 2011 +0000
+
+    sna: Improve a debug message
+    
+    Give the units when saying the pixmap is too small to bother tiling.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f837b9bcc7d384aeb37c2e9ebdac95571deaedc6
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Dec 20 20:06:25 2011 +0000
+
+    sna/render: If the pixmap already has a GPU bo, use it for the source
+    
+    The usage hint not to create a GPU bo is obviously superceded if we
+    already have a GPU bo.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit dfafe76a57655784c313bc2078d0b28a7ac2675b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Dec 20 18:39:20 2011 +0000
+
+    sna: Do not use Y-tiling for composite back pixmaps
+    
+    These are treated by the core drawing routines as replacements for the
+    front-buffer attached to Windows, and so expect the usual BLT
+    accelerations are available, for example overlapping blits to handle
+    scrolling. If we create these pixmaps with Y-tiling and then they are
+    pinned by the external compositor we are forced to perform a double copy
+    through the 3D pipeline as it does not handle overlapping blits and the
+    BLT does not handle Y-tiling.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0cda7b4fa82870d57fcd0036a3b734cc73e2bf28
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Dec 20 17:58:33 2011 +0000
+
+    sna: Implement extended fallback handling for src == dst copies
+    
+    Only marginally better than falling all the way back to using the CPU,
+    is to perform a double copy to workaround the overlapping copy.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d257a967396c517146cfb12bbec5cd28418752a3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Dec 20 12:53:42 2011 +0000
+
+    sna: Explicitly handle depth==1 scratch pixmaps
+    
+    Short-cut the determination of whether it can be tiled and accelerated
+    -- we know it can't! This is mainly to cleanup the debug logs.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0c12f7cb01e75de3bf9c2af8ac6d5b4152566457
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Dec 20 10:19:01 2011 +0000
+
+    sna: Tidy up some recent valgrind complaints with reuse of scratch pixmaps
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d3a4f5db149888239b78df1b9fcc5379b1603005
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Dec 20 12:12:39 2011 +0000
+
+    sna: Fixup the refcnt to avoid an assert
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ac52a1fcd11a3ab10e1843ed2d19f9cf818de4c1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Dec 20 02:20:48 2011 +0000
+
+    sna: Don't immediately check for region intersection after subtract
+    
+    In the READ==0 case we know that the region does not intersect damage
+    because we have just subtracted, and checking the intersection causes us
+    to immediately apply the subtraction operation defeating the
+    optimisation and forcing the expensive operation each time.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4071dca0ef8b2b1605f16bed5c42991885a35efd
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Dec 20 00:25:29 2011 +0000
+
+    sna: Don't mark mapping as synchronous by default
+    
+    Only those that point into scratch memory need to synchronized before
+    control is handed back to the client.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4c2a97e9d2b1073f0e4b3f7b6670939e1b1c5121
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Dec 19 23:10:45 2011 +0000
+
+    sna: Always pass the damage to sna_drawable_use_gpu_bo()
+    
+    As it now assumes that the damage is always writable.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 06a1792f91d3ae2ebb17e4ad55caec10c5407aa6
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Dec 19 21:04:02 2011 +0000
+
+    sna: Avoid the GPU readback with READ==0 move_to_cpu
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0b5fec3f80c8d2e4d3b504af5bb02fb76be6b3a6
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Dec 19 20:13:05 2011 +0000
+
+    sna: Drop the is-mapped flag after operating via the GPU
+    
+    Mark the end of a sequence of CPU operations and force the decision to
+    map again to be based on the current upload operation.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 351c8f16336e757b8a4d218b3afda0698781d143
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Dec 19 19:51:12 2011 +0000
+
+    sna: Discard all damage when replacing pixmap contents
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit addf66dda7cecaee8e58f53bb4e8d725dfdd2717
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Dec 19 18:37:08 2011 +0000
+
+    sna: Tweak the rendering priorities
+    
+    If the last operation was on the GPU, continue on the GPU if this
+    operation overlaps any GPU damage or does not overlap CPU damage.
+    Otherwise, if the last operation was on the CPU only switch to the GPU
+    if we do not overlap any CPU damage and overlap existing GPU damage.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9b6ade12346efa5b9cc095ad44c7d71880a19ab0
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Dec 19 17:21:26 2011 +0000
+
+    sna: Create a GPU bo for accelerated core drawing
+    
+    As we now can accelerate most of the common core drawing operations, we
+    can create GPU bo for accelerated drawing on first use without undue
+    fear of readbacks. This benefits Qt especially which heavily uses core
+    the drawing operations.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit eeb81dd6b4651c6b3e8676007d37480888726efa
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Dec 19 16:48:02 2011 +0000
+
+    sna: Remove the forced inplace upload
+    
+    Make the decision per-operation, with a tendency to remain mapped.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c3a8d77a2b6806a69de87fbaadea8612ef5f91dd
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Dec 19 16:51:29 2011 +0000
+
+    sna: Tune the inplace cross-over point to be half-cache size
+    
+    The theory being that we will also require cache space to copy from when
+    uploading into the shadow.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d53b1b28951fd7558e9913a2973c17983e0bcecf
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Dec 19 15:33:39 2011 +0000
+
+    configure: Bump the required pixman version
+    
+    UXA now also uses pixman_triangle_t in order for its fallback, so we
+    need to bump the required pixman version for UXA as well as SNA.
+    
+    Reported-by: Fabio Pedretti <fabio.ped@libero.it>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=43946
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1fa5721f064a8d1f34e4032b52f24597f4015313
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Dec 19 00:37:03 2011 +0000
+
+    sna: Reset the GTT mapping flag when freeing the shadow pointers
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7326d3098662688b8040c6e1261064caed1f5d06
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Dec 19 00:35:14 2011 +0000
+
+    sna: Restore CPU shadow after a GTT memory
+    
+    When mixing operations and switching between GTT and CPU mappings we
+    need to restore the original CPU shadow rather than accidentally
+    overwrite.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ae32aaf4b20dafef138dc9c28dbddbfe49f24b83
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Dec 19 00:34:12 2011 +0000
+
+    sna/gen[23]: We need to check the batch before doing an inline flush
+    
+    A missing check before emitting a dword into the batch opened up the
+    possibility of overflowing the batch and corrupting our state.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e32ad646762ccc7f22f938454e222d43abfb38ed
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Dec 18 23:42:07 2011 +0000
+
+    sna: Continue searching the linear lists for CPU mappings
+    
+    Prefer to reuse an available CPU mapping which are considered precious
+    and reaped if we keep too many unused entries availabled.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 15a769a66fa1afbcffc642ef980387cffefc6bef
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Dec 18 22:18:02 2011 +0000
+
+    sna: Distinguish between GTT and CPU maps when searching for VMA
+    
+    Similarly try to avoid borrowing any vma when all we intend to do is
+    pwrite.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d0ee695ef091671e2cc69b773f517030ebe961b2
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Dec 18 20:28:18 2011 +0000
+
+    sna: the active cache is not marked as purgeable, so skip checking it
+    
+    Otherwise we do a lot of list walking for no-ops.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8df9653135c6390ed699ba9f8cbf374b2cc84396
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Dec 18 19:53:14 2011 +0000
+
+    sna: clear the request list when reusing a flushing bo
+    
+    That the rq is NULL when on the flushing list is no longer true, but
+    now it points to the static request instead.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b51e3de66292e4b29483324e1dbfeb2495817351
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Dec 18 19:51:17 2011 +0000
+
+    sna: When freeing vma, first see if the kernel evicted any
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fed8d145c148bfa8a8a29f4088902377f9a10440
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Dec 18 19:26:38 2011 +0000
+
+    sna: Use a safe iterator whilst searching for inactive linear bo
+    
+    As we may free a purged bo whilst iterating, we need to keep the next bo
+    as a local member.
+    
+    Include the debugging that led to this find.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2a98dabcabf25067abcda60f233656e19e83493a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Dec 18 18:48:30 2011 +0000
+
+    sna: Purge all evicted bo
+    
+    After we find a single bo that has been evicted from our cache, the
+    kernel is likely to have evicted many more so check our caches for any
+    more bo to reap.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8ae105b2c7a06fc81757f06ec1aaa2447b53498a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Dec 18 18:20:11 2011 +0000
+
+    sna: Only retire for the VMA search if there are cached VMA
+    
+    If there are no VMA that might become inactive, there is no point
+    scanning the inactive lists if we are searching for VMA.
+    
+    This prevents the regression in firefox-fishbowl whilst maintaining most
+    of the improvement with PutComposite.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a0c0a3765ca348c74096fb157885da5b1258ee08
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Dec 18 16:59:15 2011 +0000
+
+    sna: Retire if the inactive vma list is empty
+    
+    Try to recycle vma by first trying to populate the inactive list before
+    scanning for a vma bo to harvest.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 34efb7314612cedcda4f866bc33f3ad5b6929ae2
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Dec 18 16:58:04 2011 +0000
+
+    sna: Hint likely usage of CPU bo
+    
+    If we are going to transfer GPU damage back to the CPU bo, then we can
+    reuse an active buffer and so improve the recycling.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 301896743867de0cbd22063c4bf2e1a8cf491656
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Dec 18 16:17:04 2011 +0000
+
+    sna: Only upload to the source GPU bo if we need tiling to avoid TLB misses
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b7f5d75aa54db7d0542b09f4b3081f7692ede602
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Dec 18 16:11:34 2011 +0000
+
+    Silence uxa-only compilation
+    
+    Kill the stray warning for the undeclared extern used by the module
+    loader.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a73cc4bf1e554806f403c6704d1cf98491f4d444
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Dec 18 14:54:12 2011 +0000
+
+    sna/gen5: Tidy checking against hardcoded maximum 3D size
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b43548af39f8773283b744e979ee575032183cdc
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Dec 18 12:11:01 2011 +0000
+
+    sna: Explicitly handle errors from madv
+    
+    In order to avoid conflating whether a bo was marked purgeable with its
+    retained state, we need to carefully handle the errors from madv.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 954cf5129d462f7f4ff5d4ff44b256e0f091667c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Dec 18 10:40:35 2011 +0000
+
+    sna/gen[67]: check for context switch after preparing source
+    
+    If we used the BLT to prepare the source, see if we can continue the
+    operation on the BLT.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 90a432431c8fc293db611289c3369669c2975706
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Dec 18 10:23:11 2011 +0000
+
+    sna/gen[23]: Try BLT if the source/target do no fit in the 3D pipeline
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit eeb9741981be528d1fba3021a30ab24084a5ce8c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Dec 18 10:04:08 2011 +0000
+
+    sna/gen3: Tidy checks against hardcoded maximum 3D pipeline size
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit dcfcf438a511ee43e5969d01e41b3040a08cac3a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Dec 18 09:58:08 2011 +0000
+
+    sna/gen2+: If we use the BLT to prepare the target, try using BLT for op
+    
+    If we incurred a context switch to the BLT in order to prepare the
+    target (uploading damage for instance), we should recheck whether we can
+    continue the operation on the BLT rather than force a switch back to
+    RENDER.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 507debe8015ee10734a0b8a6ddf4aa251b7dddc5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Dec 18 01:45:47 2011 +0000
+
+    sna/gen5: If we need to flush the composite op, check to see if we can blit
+    
+    If we need to halt the 3D engine in order to flush the pipeline for a
+    dirty source, we may as well re-evaluate whether we can use the BLT
+    instead.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit de530f89a36a80b652ed01001e6f0d4c8b1dc11a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Dec 18 01:41:03 2011 +0000
+
+    sna/gen5+: First try a blt composite if the source/dest are too large
+    
+    If we will need to extract either the source or the destination, we
+    should see if we can do the entire operation on the BLT.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7b88f87945f23b3f80ae44b2aa19f00dff1904c8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Dec 18 00:44:00 2011 +0000
+
+    sna: Upload images in place from CopyArea
+    
+    As for PutImage, if the damage will be immediately flushed out to the
+    GPU bo, we may as well do the write directly to the GPU bo and not
+    staged via the shadow.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1418e4f3156a17ff6c5cd0f653918160e30b7c0e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Dec 17 23:11:03 2011 +0000
+
+    sna: Tune the default pixmap upload paths
+    
+    One issue with the heuristic is that it is based on total pixmap size
+    whereas the goal is to pick the placement for the next series of
+    operations. The next step in refinement is to combine an overall
+    placement to avoid frequent migrations along with a per-operation
+    override.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 25c353503a25d20e7db5acdc63d83564804efdf4
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Dec 17 17:16:07 2011 +0000
+
+    sna: Simplify write domain tracking
+    
+    Replace the growing bitfield with an enum marking where it was last
+    used.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d20d167a753d8e4fe581950e1bc49f29e0ec9f1f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Dec 17 16:28:04 2011 +0000
+
+    sna: Upload to large pixmaps inplace
+    
+    When the pixmap is large, larger than L2 cache size, we are unlikely to
+    benefit from first copying the data to a shadow buffer -- as that shadow
+    buffer itself will mostly reside in main memory. In such circumstances
+    we may as perform the write to the GTT mapping of the GPU bo. As such,
+    it is a fragile heuristic that may require further tuning.
+    
+    Avoiding that extra copy gives a 30% boost to putimage500/shmput500 at
+    ~10% cost to putimage10/shmput10 on Atom (945gm/PineView), without any
+    noticeable impact upon cairo.
+    
+    Reported-by: Michael Larabel <Michael@phoronix.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit dd8fd6c90612ada39eb32b98adc5acc97e7902aa
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Dec 17 12:38:09 2011 +0000
+
+    sna: Search through the inactive VMA cache for potential upload bo
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8ef5d8c1955e2e2ee19c64730f600639ac42de55
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Dec 15 17:52:20 2011 +0000
+
+    sna: Map the upload buffer using an LLC bo
+    
+    In order to avoid having to perform a copy of the cacheable buffer into
+    GPU space, we can map a bo as cacheable and write directly to its
+    contents. This is only a win on systems that can avoid the clflush, and
+    also we have to go to greater measures to avoid unnecessary
+    serialisation upon that CPU bo. Sadly, we do not yet go to enough length
+    to avoid negatively impacting ShmPutImage, but that does not appear to
+    be a artefact of stalling upon a CPU buffer.
+    
+    Note, LLC is a SandyBridge feature enabled by default in kernel 3.1 and
+    later. In time, we should be able to expose similar support for
+    snoopable buffers for other generations.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6e47f283711d122d96384a1a82854c11644e6d68
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Dec 16 23:49:18 2011 +0000
+
+    sna/gen3: Enforce a minimum width of 2 elements for the render target
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2ff0826f94ca16e95cd662385f7091be750dec30
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Dec 16 23:33:25 2011 +0000
+
+    sna: Discard GPU damage first before choosing where to fill_boxes()
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 55520bab578865f878965aa362ec4933f4b26050
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Dec 16 23:22:38 2011 +0000
+
+    sna/gen3: Initialise missing value of need ca pass for fill_boxeS()
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e56d5081ea2da930bc82036ac7c4c78b433117ed
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Dec 16 23:18:02 2011 +0000
+
+    sna: Wrap I915_GEM_GET_PARAM with valgrind markup
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e0399ec1619fe4f87f0578791e697a7e2a8c86dc
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Dec 16 23:07:37 2011 +0000
+
+    sna: Suppress an overwritten XY_SRC_COPY
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1684ed6a5e8c26ecb48cc1a5025107466526fe94
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Dec 16 19:35:35 2011 +0000
+
+    sna: Clean up compiler warnings for shadowed variables
+    
+    No outright bug, just plenty of unwanted noise.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 300586b229ae941ac31850af00d120d8c441c583
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Dec 16 17:56:53 2011 +0000
+
+    sna/gen4+: disable the blend unit for PictOpSrc
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0de7604d8ecfc73ef9e92059340d00ce5cfcdd75
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Dec 16 17:40:01 2011 +0000
+
+    src/gen4+: Add support for depth 15 render copies/fills
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a8fe50ab6503d9cb63931771318dc3e84d002092
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Dec 17 11:15:36 2011 +0000
+
+    uxa: Explicitly check for libdrm_intel in configure
+    
+    And remove the excess dependencies from the common files.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3320b459d6fe90d1145e3874c840b95279fb16c8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Dec 17 12:08:24 2011 +0000
+
+    sna: Clean up caches stored upon the batch bo
+    
+    Until the advent of the VMA cache, we were safe to reap the batch bo by
+    hand. However, as we continue to add additional data to the bo, it is
+    wise to use the common free function.
+    
+    Reported-by: Clemens Eisserer <linuxhippy@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=43899
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e2c8bac972cf46982bf64bd786ecc001009081f0
+Author: Zhigang Gong <zhigang.gong@linux.intel.com>
+Date:   Fri Dec 16 15:11:16 2011 +0800
+
+    uxa/glamor: Fallback to new glamor pixmap if failed to create textured pixmap.
+    
+    If we failed to create textured pixmap from BO's handle, we
+    turn to create a new glamor pixmap by call glamor_create_pixmap
+    rather than fallback to in-memory pixmap. Have to introduce
+    a new wrapper function intel_glamor_create_pixmap.
+    
+    Signed-off-by: Zhigang Gong <zhigang.gong@linux.intel.com>
+
+commit 19c184b7e4f8de747ed6fb1f6f910238193cf2a1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Dec 15 18:18:19 2011 +0000
+
+    sna/gen3: Check for upload failure of video bo
+    
+    And propagate that failure back to the client.
+    
+    Reported-by: Paul Neumann <paul104x@yahoo.de>
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=43716
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e68a8748f3418179eb41e8d81ba1050b883b7e47
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Dec 15 09:44:20 2011 +0000
+
+    uxa: Move the region creation beyond the call into glamor
+    
+    So that we avoid leaking the region if hooking into glamor.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e3153a779ed220ad71958ce56be179d458794964
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Dec 15 09:30:28 2011 +0000
+
+    sna: cap the number of times we attempt to resubmit the batch upon EBUSY
+    
+    Just in case the kernel gets stuck in a loop and we fail to make any
+    progress at all.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1cc43dc97bd6438d7fc808cb5ee449889a966bdf
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Dec 15 00:00:56 2011 +0000
+
+    sna: More missing move-to-cpu allocation checks
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 12448b56060fb9c14da6b4ab02c95c7834fd3874
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Dec 15 00:01:37 2011 +0000
+
+    sna: silence warning for unused 'priv'
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit eb8e979b4de5d854f15ae4c86d3db29371b386c1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Dec 14 23:02:28 2011 +0000
+
+    uxa/glamor: Allocate a fbPixmap with storage for fallbacks
+    
+    When we try to create a glamor pixmap and fail we need to create a real
+    pixmap along with its pixel allocation, instead of detaching ourselves
+    and returning the fake pixmap header.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 232fa93a4bf1760e16e913e8fb4d5159c4be9295
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Dec 14 20:11:39 2011 +0000
+
+    uxa/glamor: Always notify glamor that the glyph has been unrealized
+    
+    The danger of the early return when UXA is not using glyphs is evident
+    in the eventual crash when glamor begins evicting and reusing its glyph
+    cache slots.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 95cceb5ae5503af0ac50a923fa47e134f0da8743
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Dec 14 19:27:53 2011 +0000
+
+    sna: Fix DBG crash whilst pruning inactive GPU buffers
+    
+    Don't attempt to dereference the NULL gpu_bo after having just freed it.
+    Here in lies the folly of trying to blindly silence the compiler.
+    
+    Instead we should heed the error return as it means that we didn't
+    decouple the pixmap from the inactive list and so we choose to place it
+    back on the active list to purge again in the near future.
+    
+    Reported-by: Paul Neumann <paul104x@yahoo.de
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=43716
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e7f4b7fd91a41cac77e5eb1cb4f185141b09a09e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Dec 14 18:21:22 2011 +0000
+
+    sna: Add some DBG() around Y-to-X fallbacks
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 32bb2c89b8cab92f16af32e7a084bfefa406661d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Dec 14 16:28:54 2011 +0000
+
+    sna: Check allocation of pixman_image_t
+    
+    And just fail to perform the copy, clearing the dst instead.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 37c525a11c0fab4e279e80ad24e5cf791239e005
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Dec 14 16:26:46 2011 +0000
+
+    sna: Skip glyphs if we fail to allocate pixel data for them
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6a8188bb4dd0eba58e29803566023ad5c3d4d58a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Dec 14 16:24:54 2011 +0000
+
+    sna: Close any handles after bo allocation failures
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 43a22743124a83310379122d509c35840b583b2e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Dec 14 13:26:05 2011 +0000
+
+    sna: Use the provided bo for blitting rather than assume priv->gpu_bo
+    
+    Reported-by: nkalkhof@web.de
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=43802
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 30f5ee11f8ec3688807bbaded92561e96f9a439b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Dec 14 12:30:40 2011 +0000
+
+    sna: Use a static request and synchronous rendering in case of malloc failure
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 23fb2cebbe1d4d7df7403a64635339efa08a4dfe
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Dec 14 12:34:03 2011 +0000
+
+    sna/blt: Add a missing allocation check upon the source CPU pixmap
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5b0f3ff9a83b7cc932e96400999dc5e4a49369cb
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Dec 14 12:23:04 2011 +0000
+
+    sna/damage: Guard against malloc failures
+    
+    In the event of failure, we choose to loose track of the damage and
+    choose rendering corruption over crashing.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f8b9a2a5473efd0fefb3d2878e70c24c320245ca
+Author: Zhigang Gong <zhigang.gong@linux.intel.com>
+Date:   Tue Dec 13 21:46:14 2011 +0800
+
+    uxa/glamor: Enable the rest of the glamor rendering routines
+    
+    This commit hooks up all the remaining rendering routines to call into
+    glamor; the takeover is nearly complete! When tested with the latest
+    glamor master branch, it passes rendercheck.
+    
+    One thing need to be pointed out is the picture's handling.
+    Pictures support many different color formats, but glamor's
+    texture only support a few color formats. And the most common
+    scenario is that we create a pixmap with a color depth and
+    then attach it to a picture which has a specific color format
+    with the same color depth. But there is no way to change a
+    texture's internal format after the texture was allocated.
+    If you do that, the OpenGL will allocate a new texture. And
+    then the glamor side and UXA side will be inconsitent. So
+    for all the picture related operations, we can't fallback to
+    UXA path directly, even it is rather a straight forward
+    operation. So for the get_image, Addtraps.., we have to add
+    wrappers function for them to jump into glamor firstly.
+    
+    Signed-off-by: Zhigang Gong <zhigang.gong@linux.intel.com>
+    [ickle: prefer access; ok = glamor(); finish; if (!ok) goto fallback; return; ]
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d5456e40d9bebc9d6a121abdb124a90a2a8a6958
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Dec 14 10:41:33 2011 +0000
+
+    uxa/glamor: Silence a compiler warning for some unused code
+    
+    intel_glamor.c: In function 'intel_glamor_create_screen_image':
+    intel_glamor.c:192:12: warning: variable 'pixmap' set but not used
+    [-Wunused-but-set-variable]
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4f1a99a70e76ea5637c5ee8226b2e52a464f5948
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Dec 13 19:44:15 2011 +0000
+
+    sna: Protect against deferred malloc failures for pixel data
+    
+    As we now defer the allocation of pixel data until first use, it can
+    fail in the middle of a rendering routine. In order to prevent chasing
+    us passing a NULL pointer into the fallback routines, we need to propagate
+    the failure from the malloc and suppress the failure, discarding the
+    operation, which is less than ideal.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d2c6d950ed2c5882e7d501b6974e72be4d6da8a8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Dec 13 15:04:10 2011 +0000
+
+    sna: Mark upload buffers as unaccessible upon submission
+    
+    Use valgrind to catch use-after-finish bugs.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e39ea29bcc5d1d76dd5cb3db555516ef848647a5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Dec 13 13:18:56 2011 +0000
+
+    sna: Allow the debugger to map bo from the batch during kgem_submit()
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2fabb5068d36ce97242844066b5121fcf6d9c24e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Dec 13 13:15:51 2011 +0000
+
+    sna: Debug fixup for non-LLC systems
+    
+    The cpu bo is only allocated on LLC systems, so do avoid the NULL deref on
+    debugging for others.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e037379c8e57f8e42956863c10a4e2b18057a6d5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Dec 13 13:14:15 2011 +0000
+
+    sna: Fix a debugging assert
+    
+    The bo is allowed to be NULL, so defer the assert until after it is
+    known to be non-NULL.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5d5b2b8ee203ae2274fc7d13ed38d2945facca9e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Dec 13 11:30:05 2011 +0000
+
+    uxa: Cap the maximum number of VMA cached
+    
+    Since we can not keep an unlimited number of vma cached due to the hard
+    per-process limits on the number of mappings and recreating mappings is
+    slow due to excruciatingly slow GTT pagefaults, we need to compromise
+    and keep a small MRU cache of inactive mmaps.
+    
+    This uses the new API in libdrm-2.4.29 to specify the limit upon the VMA
+    cache maintained by libdrm.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1128825efb3179a5a5d951fa24db6b769ee41219
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Dec 13 11:20:25 2011 +0000
+
+    uxa: Wakeup 3s after the last rendering to reap the bo-cache
+    
+    libdrm expires its bo 2s after entry into the cache, but we need to free
+    a buffer to trigger the reaper. So schedule a timer event to trigger 3s
+    after the last rendering is submitted to free any resident bo during
+    long periods of idleness.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit db7c9e8561afcc1ca7ab16b3bf2d5b49938e26d9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Dec 13 10:05:25 2011 +0000
+
+    configure: Link the extra valgrind debugging to --enable-debug
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d02dc0fd84194b6acc607d17e4396dd1fdc681f8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Dec 13 01:18:59 2011 +0000
+
+    sna: Set the refcnt on the replacement bo
+    
+    The paranoia wasn't in vain.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7472db8c8c9994798ea36de1ce2f51725d8b387a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Dec 12 21:55:04 2011 +0000
+
+    sna: Double-check that the submitted buffers were not purged
+    
+    More paranoia is good for the soul.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0bbd6a08fe485c80bd5c9a1b7027618a03a26f84
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Dec 12 21:52:56 2011 +0000
+
+    sna/gen2: Tidy checking against too large pixmaps for the 3D pipeline
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b392474f3a052fefc410383725b64f0fdbe7788e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Dec 12 21:28:09 2011 +0000
+
+    sna: Force a suitable minimum stride for 3D temporaries
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3c22baaba97a89d24e507e3d832d53d764902040
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Dec 12 21:16:56 2011 +0000
+
+    sna/gen2: Check for unhandled pitches in the render pipeline
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f6a30df8dc75852d1f6daeabe4511b275594e52e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Dec 12 20:40:29 2011 +0000
+
+    sna: Enable memcpy uploads to SHM pixmaps
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3c163d105e964a1084d665500ef917254d8f2179
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Dec 12 16:26:13 2011 +0000
+
+    sna: Use the CPU bo as a render source if compatible and no GPU bo
+    
+    This is principally to catch the cases of compositing after a fresh
+    PutImage.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c481bec356b2e40e66a000dbaaf261bf7aae930d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Dec 12 14:10:57 2011 +0000
+
+    sna: Experiment with creating the CPU pixmap using an LLC BO
+    
+    A poor cousin to vmap is to instead allocate snooped bo and use a CPU
+    mapping for zero-copy uploads into GPU resident memory. For maximum
+    performance, we still need tiled GPU buffers so CPU bo are only useful
+    in situations where we are frequently migrating data.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6c9aa6f9cf8e59ca6aa1866b83690a1de8cfb757
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Dec 12 11:47:25 2011 +0000
+
+    sna: Defer allocation of memory for larger pixmap until first use
+    
+    In the happy scenario where the pixmap only resides upon the GPU we can
+    forgo the CPU allocation entirely. The goal is to reduce the number of
+    needless mmaps performed by the system memory allocator and reduce
+    overall memory consumption.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4b48d28f6e85f345730cb7242f2152ac115b267a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Dec 12 10:52:34 2011 +0000
+
+    sna: Fix a typo, end statements with semi-colons
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4d20798c7871ffe8581e2cf509b6aa2e40b3ae5f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Dec 12 10:10:16 2011 +0000
+
+    sna: We need to remap the gpu_only mmap prior to every use
+    
+    Since the VMA may be reaped at any time whilst the mapping is idle.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2682308c10c9622247409dee9c6bb6a862b73c3f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Dec 12 09:24:11 2011 +0000
+
+    sna: Remove bo transference for whole XCopyArea
+    
+    In benchmarking firefox this performs whose - it would appear the
+    sources are indeed used more often than not.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7703424222f8bd08450c1b109ea64c6b0ee901d8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Dec 12 00:15:10 2011 +0000
+
+    sna/gen6: Only use CPU bo for a render target if untiled
+    
+    For large render targets, we prefer to use tiled bo in order to avoid
+    severe performance degradation. However, if we don't have a GPU bo but
+    do have a CPU bo and the operation would be untiled, then simply use the
+    CPU bo.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a92a41ba3291a4304948ed1961d1242ca7d3981e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Dec 11 19:03:54 2011 +0000
+
+    sna/gen6: Tidy the usage of the max pipeline size
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e9e6d6f7c8af300716c64b041f96c09d58b3eaa2
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Dec 11 17:25:46 2011 +0000
+
+    sna/gen3: Move the video dst_bo to make the conditional clearer
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 118ef0781c5064aa0696af59a5dac67091b10046
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Dec 11 16:56:53 2011 +0000
+
+    sna/composite: Make the check for a no-op earlier and clearer
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2674ef864c93034d728ee11ee0b7ab96cd4cba57
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Dec 11 16:23:13 2011 +0000
+
+    sna: Enable hooking up of valgrind during debugging
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c83fd4e24de187700bc125037cd9ae311514213e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Dec 11 16:14:38 2011 +0000
+
+    sna: Add some more debug messages for VMA caching
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3ae7fb918a2ca47d3944521a1ae30143dcb14eeb
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Dec 11 13:52:42 2011 +0000
+
+    sna: Restrict pitch alignment on 945gm to 64 bytes
+    
+    In theory we should be able to disable dual-stream mode and so be
+    subject to much looser restrictions (such as the pitch need only be
+    dword aligned). However, achieving single-stream mode seems quite
+    difficult!
+    
+    Reported-by: Paul Neumann <paul104x@yahoo.de>
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=43706
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2f35d77cd07a4974051c922f4809ce44939b0556
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Dec 11 13:37:18 2011 +0000
+
+    sna: Update computation of untiled pitch to cater for CREATE_SCANOUT
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5a0139487f5a5caada56121395aa166fc9f08663
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Dec 11 12:34:40 2011 +0000
+
+    sna/gen3: Ensure that depth read/writes are disabled before first use
+    
+    Our goal is to achieve "single-stream" rendering where the entire
+    RenderCache is allocated to the colour buffer (rather than split between
+    colour and depth). In theory all that is required is for the pipeline
+    not to reference the depth buffer at all, however it is not made clear
+    when that evaluation is made.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a02bbd8700690c98c6cf3ae98dd7ee3da9887b0a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Dec 11 10:34:37 2011 +0000
+
+    sna: Only transfer the bo if the src/dst are of matching size
+    
+    If the src replaces the dst, it could just be a much larger pixmap!
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 43a99648635fa76e0d6d71acaeb6ba919d24eb26
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Dec 11 10:30:48 2011 +0000
+
+    sna: Only transfer unpinned buffers
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit eb859f644633ee716083d253a5b7ff95163380e5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Dec 11 01:34:05 2011 +0000
+
+    uxa/video: Correct the offset of the binding table in the surface buffer
+    
+    The binding table is intended to be after all the surface descriptions,
+    so make sure we write it with the appropriate offset into the buffer.
+    
+    Fixes regression from 699888a64 (uxa/video: Use the common bo
+    allocations and upload)
+    
+    Reported-by: Cyril Brulebois <kibi@debian.org>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=43704
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 051a18063df075536cb1ac0dc4dfc3c1306ab74e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Dec 10 22:45:25 2011 +0000
+
+    sna: Implement a VMA cache
+    
+    A VMA cache appears unavoidable thanks to compiz and an excrutiatingly
+    slow GTT pagefault, though it does look like it will be ineffectual
+    during everyday usage. Compiz (and presumably other compositing
+    managers) appears to be undoing all the pagefault minimisation as
+    demonstrated on gen5 with large XPutImage. It also appears the CPU to
+    memory bandwidth ratio plays a crucial role in determining whether
+    going straight to GTT or through the CPU cache is a win - so no trivial
+    heuristic.
+    
+    x11perf -putimage10 -putimage500 on i5-2467m:
+    Before:
+      bare:   1150,000   2,410
+      compiz:  438,000   2,670
+    After:
+      bare:   1190,000   2,730
+      compiz:  437,000   2,690
+    UXA:
+      bare:    658,000   2,670
+      compiz:  389,000   2,520
+    
+    On i3-330m
+    Before:
+      bare:    537,000   1,080
+      compiz:  263,000     398
+    After:
+      bare:    606,000   1,360
+      compiz:  203,000     985
+    UXA:
+      bare:    294,000   1,070
+      compiz:  197,000     821
+    
+    On pnv:
+    Before:
+      bare:    179,000   213
+      compiz:  106,000   123
+    After:
+      bare:    181,000   246
+      compiz:  103,000   197
+    UXA:
+      bare:    114,000   312
+      compiz:   75,700   191
+    
+    Reported-by: Michael Larabel <Michael@phoronix.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 735a15208dd600eefa3090f344186df9cac0462d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Dec 10 23:45:56 2011 +0000
+
+    sna/gen5: Remove a redundant format check
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c5584252c34b792313578cc31d56248d8990b571
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Dec 10 23:34:16 2011 +0000
+
+    sna: Remember to assign a new unique id for the replaced bo
+    
+    Missed from the previous patch.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9c764dc13be40fc14238a4c130f7d8b44dbdf7db
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Dec 10 22:38:57 2011 +0000
+
+    sna: Be more pessimistic with CPU sources
+    
+    Try to avoid a few more unnecessary context switches.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 358aaef6dbff0737f026046b0c9a2e21d8cfdf2a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Dec 10 22:38:33 2011 +0000
+
+    sna/dri: Prefer using the BLT for DRICopyRegion on pre-SNB
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c295ad8da91e39c8fffa540901097651df5d24b2
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Dec 10 22:37:31 2011 +0000
+
+    sna: Transfer the whole bo for a replacement XCopyArea
+    
+    If we are copying over the entire source onto the destination,just copy
+    across the GPU bo. This is often used for caching images as pixmaps.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ece7fc8afeb8eefcf0ad1a054f02e7fac8db6327
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Dec 10 21:04:08 2011 +0000
+
+    sna: Only use the 64-byte pitch alignment for scanout
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b3816cf3a99d23d0c3ab4cd716b24ea544a07283
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Dec 10 20:32:56 2011 +0000
+
+    sna: Remove assertions that external bo are not busy
+    
+    We have to be careful to assume bo via exposed are under our full
+    control, in particular not to assert their state. :(
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b5a6bc9e33a2797c926969e1f98b4a9a796248c5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Dec 10 13:14:45 2011 +0000
+
+    sna/gen[23]: Fixup render targets with pitches below hw minimum
+    
+    gen2/3 have a restriction that the 3D pipeline cannot render to a pixmap
+    with a pitch less than 8/16 respectively. Rather than mandating all
+    pixmaps to be created with a stride greater than 16, fixup the bo for
+    the rare occasions when it is necessary.
+    
+    Reported-by: Paul Neumann <paul104x@yahoo.de>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=43688
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c0dab7b1cf17fe751c86ad2b3fabce682eb50366
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Dec 10 12:46:46 2011 +0000
+
+    sna/trapezoids: Try to render traps onto a8 destinations in place
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c73b14cabb059075af0f1727847074a89941c9df
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Dec 10 11:41:18 2011 +0000
+
+    sna/trapezoids: First try the scan converter for fallbacks
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 22d9bc0bc1ccd869ebcc93f9a57efc8a85840cb8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Dec 9 23:48:11 2011 +0000
+
+    sna: Use a single definition for the inactive cache timeout
+    
+    And share it between the timer and the expiration function, just to
+    simplify the code.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit eb3e04d960cd749adf696ba15c501a17cd1a184e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Dec 9 23:36:56 2011 +0000
+
+    sna: Fallback to ordinary monotonic clock if coarse is not supported
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1c202cc0746541b541d0af22eab5c9798d229a69
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Dec 9 17:25:19 2011 +0000
+
+    sna: s/MONOTONICE/MONOTONIC/
+    
+    A late addition to be flexible for compiling on different systems
+    heralded its doom.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c51626ccb660c777da8d84bb425de0d590864448
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Dec 9 15:45:29 2011 +0000
+
+    sna: Use the coarse monotonic clock to coalesce wakeup events
+    
+    For the long interval events (such as expiring the caches), we do not
+    need precise timing and so can use a coarse timer to allow the system
+    to coalesce and reduce wakeup events.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c22197f25bc0419d9f2abfcc978df5ef439feb47
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Dec 9 15:12:03 2011 +0000
+
+    sna: Discard bo for idle private pixmaps
+    
+    If a pixmap lies around for a couple of minutes not being used, it is
+    unlikely to be used again in the near future. Reap the GPU buffers of
+    any of those idle pixmaps (copying to a more compact buffer in system
+    memory) in order to free up resources for use elsewhere. Any object
+    that is exposed via DRI is obviously exempt from this reaping.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 429a36f7481b9bfd5ed137642d2916d69a713557
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Dec 9 09:54:12 2011 +0000
+
+    uxa: Fix clip processing for uxa_fill_spans()
+    
+    Fixes regression from e0066e77e026b0dd0daa0c3765473c7d63aa6753
+    (uxa: Simplify Composite solid acceleration for spans by only clipping
+    once) [2.15.901]
+    
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=43649
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 699888a6410b0699c69a7f8a8d82dc4fde6fcc7f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Dec 8 16:55:20 2011 +0000
+
+    uxa/video: Use the common bo allocations and upload
+    
+    In order to avoid inconsistent usage of coherency domains and to avoid
+    completely unnecessary clflushing during video playback, use the same
+    buffer allocation and upload functions as the rest of the driver.
+    
+    Reported-by: Christophe Roland <roll68@gmail.com>
+    Bugzilla: http://bugs.debian.org/cgi-bin/bugreport.cgi?msg=60;bug=651316
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 706d3a97bd3049e60c08d121a3d4d81c03029a87
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Dec 8 18:05:14 2011 +0000
+
+    sna/trapezoids: Fix detection of rectilinearity after projection
+    
+    A typo confused left and right, rejecting true vertical edges, and worse
+    might have incurred false positives.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit bc081420a5d6d28c4e6fd5527a70caaa3a8361c4
+Author: Simon Que <sque@chromium.org>
+Date:   Wed Dec 7 16:20:41 2011 -0800
+
+    xf86-video-intel: change order of DPMS operations
+    
+    The operations when setting dpms on should be in the order opposite
+    of what's done when setting dpms off.
+    
+    This is because of potentially conflicting effects:
+    ~ drmModeConnectoSetProperty() enables/disables the backlight driver.
+    Some backlight drivers such as intel_backlight set the backlight to 0
+    when disabled and to max when enabled.
+    ~ intel_output_dpms_backlight() saves the backlight value when turning
+    DPMS off and restores it when turning DPMS on.
+    
+    Here's the current order of operations:
+    
+    xset dpms force off (backlight is nonzero)
+       drmModeConnectoSetProperty(DPMSModeOff)
+          kernel: disable backlight, backlight=0
+       intel_output_dpms_backlight(DPMSModeOff)
+          save backlight value (0) <-- it has been set to 0 by kernel
+          set backlight to 0
+    
+    xset dpms force on
+       drmModeConnectoSetProperty(DPMSModeOn)
+          kernel: enable backlight, backlight=max
+       intel_output_dpms_backlight(DPMSModeOn)
+          set backlight to saved value (0)
+    
+    The correct way to do this would be to reverse the operations during
+    xset dpms force off:
+       intel_output_dpms_backlight(DPMSModeOff)
+          save backlight value (nonzero)
+          set backlight to 0
+       drmModeConnectoSetProperty(DPMSModeOff)
+          kernel: enable backlight, backlight=0
+    
+    This restores the saved nonzero backlight value during the force on.
+    
+    Signed-off-by: Simon Que <sque@chromium.org>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 84aaf1537cbd29e163346d03debc39f4623c69eb
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Dec 8 12:36:08 2011 +0000
+
+    sna/gen7: Reduce dst readbacks for unsupported sources
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 440ac68ec074e82818713773f3e2cb5d363862aa
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Dec 8 12:35:54 2011 +0000
+
+    sna/gen6: Reduce dst readbacks for unsupported sources
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit bc68211d18356c4a0e011ac360665d600de9fa30
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Dec 8 12:35:39 2011 +0000
+
+    sna/gen5: Reduce dst readbacks for unsupported sources
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a5df7c28e458c2f2b173fe5d745f447087eb8c6f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Dec 8 12:35:22 2011 +0000
+
+    sna/gen4: Reduce dst readbacks for unsupported sources
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit cc8cab649c0a4788803d2c62f186142ec7152b89
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Dec 8 12:34:58 2011 +0000
+
+    sna/gen3: Reduce readbacks on dst for unsupported sources
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e5bc0c823b8fd46b3f851c5e9a4b4de39cda9a91
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Dec 8 12:34:34 2011 +0000
+
+    sna/gen2: Avoid readbacks for unsupported sources
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 874c722c86b06ac0aa10e6943d3faf76fcb751be
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Dec 8 12:07:28 2011 +0000
+
+    sna: Beware flushing partial buffers before they are written
+    
+    A partial buffer is considered finished upon the next batch submission,
+    so one needs to be careful that it is completely written to before such
+    an event is triggered. move-to-cpu is such a trigger as demonstrated by
+    the picture fixup routine for handling convolution filters.
+    
+    Reported-by: Victor Machado <machado.prx@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=43607
+    Signed-off-by: Chris Wilson <ickle@crestline.(none)>
+
+commit 6ccb114a7e685c69fb388ebd119393455b315c36
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Dec 7 21:09:31 2011 +0000
+
+    sna: Prefer to use our pixmap upload paths
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 101942d41df7efaa6103e31e738775fafdb63159
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Dec 5 10:11:04 2011 +0000
+
+    uxa: Unmap the buffer after swrast
+    
+    Otherwise we may exhaust the per-process vma limit and cause
+    applications to stop rendering and eventually crash the X server.
+    
+    Will only work in conjunction with a new libdrm (2.4.28) and commit
+      c549a77c (intel: Unmap buffers during drm_intel_gem_bo_unmap)
+    in particular.
+    
+    Reported-by: nobled@dreamwidth.org
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=43075
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=40066
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b424b10e771b1d3d041efdd2b77f576251364744
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Dec 4 13:01:10 2011 +0000
+
+    sna: use tight pitches for a8
+    
+    As we never use these with a depth nor attach them to scanout, we can
+    safely relax the multiple-of-64 byte pitch restriction. In the unlikely
+    event that we do need A8 surfaces with depthbuffers, this is broken...
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 46c7df803881fa0e733c0d0fdd37567ebdccd6ac
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Dec 3 18:02:00 2011 +0000
+
+    sna: Remove one redundant retire
+    
+    There is no need to retire immediately after a batch and no indication
+    that it will be useful.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b99c6b13ebba9521333b8dd5982ac37b6e244b54
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Dec 3 18:01:11 2011 +0000
+
+    sna: Pass the current value of the batch offset to the kernel relocator
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 735219cd59e6184a6622d3d429a704ca3f58b9cd
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Dec 2 10:42:00 2011 +0000
+
+    uxa: Ensure that we can fallback with all of (src, mask, dst) as GTT mappings
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f6c82c73b673ec3c9cce432fe38d5e0076234efd
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Dec 2 10:34:10 2011 +0000
+
+    uxa: Fix runtime linking of previous commit
+    
+    So much for relying on compiler warnings.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 85d3dc5910a2eea3a10b822e01443e11eaae9291
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Dec 2 10:22:51 2011 +0000
+
+    uxa: Reset size limits based on AGP size
+    
+    The basis for the constraints are what we can map into the aperture for
+    direct writing with the CPU, so use the size of the mappable region as
+    opposed to the size of the total GTT.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e55198746102afb7427f577bd5bfc76667438da9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Dec 1 13:49:03 2011 +0000
+
+    sna: Reuse the full size of an old handle for io
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c5632369cbd6473304c06e4230347abbe46513ec
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Dec 1 13:23:56 2011 +0000
+
+    sna: Move the preservation of the io handle into the common destroy path
+    
+    In order to capture and reuse all io buffers.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 95f4da647a4055545b09cae0834df0fa2127a458
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Nov 30 11:59:31 2011 +0000
+
+    sna: Align pwrite to transfer whole cachelines
+    
+    Daniel claims that this is will be faster, or will be once he has
+    completed rewriting pwrite!
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ecd6cca617ac29cf2b1b2a4d33fca19b84fea2a9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Nov 29 19:27:46 2011 +0000
+
+    sna/gen5: Handle cpu-bo for render targets
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d8f2e87473eae81e07922271b5f608fdceb4ae5e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Nov 29 10:59:48 2011 +0000
+
+    sna/render: Fix check for "migrate whole pixmap"
+    
+    The whole pixmap means the sample covers the full width and height, not
+    just either!
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 20e57914089d6959529ad222e04853f5ffcb364f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Nov 29 10:59:20 2011 +0000
+
+    sna: Fix assertion around flushing of mmap(PROT_READ)
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 56155c91afb5a0dcafe4dbc22ade3b7c0c977674
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Nov 29 10:27:18 2011 +0000
+
+    sna/gen6: Set the batch mode prior to checking limits and flushing
+    
+    If we change contexts, then we will submit the batch obsoleting the
+    earlier resource checks.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5b1e9e15738b9001346ab6e0166f861ce308008e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Nov 28 22:01:00 2011 +0000
+
+    sna: Always reduce tiling for thin pixmaps
+    
+    Benchmarking on the current code base, says this is now a win. A
+    reversal of older benchmarks, so expect further tuning.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit dacb301c05dd1686e788d6ed8101887c27968389
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Nov 28 18:59:10 2011 +0000
+
+    sna: Use the correct pitch when creating an untiled active buffer
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8657128fa7e758a2dde93340d6e58928d5f11255
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Nov 28 18:22:01 2011 +0000
+
+    sna: Pass the pixmap to sna_replace()
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4e38d22105da2bd97db005dc505e75dcd22291d3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Nov 28 18:21:19 2011 +0000
+
+    sna: Tidy kgem_choose_tiling()
+    
+    Reduce the calls to compute the surface size down to one.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 04f47e52da06cc20c2a266da92ba3f8e961433cb
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Nov 27 17:45:05 2011 +0000
+
+    sna: Don't try to guess when the kernel believes a buffer to be flushed
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d87c332653001db4413c7dd81116ee03830db491
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Nov 27 10:18:11 2011 +0000
+
+    sna: Eliminate empty glyphs during format conversion
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 413776c79ee7c55b3a48b1ed29af63f8cea39337
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Nov 27 10:17:40 2011 +0000
+
+    sna: Use 64-bit mov (when available) for bitmap glyphs
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 507f99eba2c72bc109c9267c698f3d5f9fb6f539
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Nov 26 17:57:57 2011 +0000
+
+    sna/gen6+: Only use BLT if the untiled bo will cause per-pixel TLB misses
+    
+    i.e. only force the BLT if using the sampler is going to be incredibly
+    slow.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f11e9f189111f53ace20381a0bd4f559ccd3605f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Nov 26 17:12:03 2011 +0000
+
+    sna: Only check for all-damaged CPU bo if we may discard the GPU bo
+    
+    The goal of the optimisation is to discard the GPU bo early, so we
+    can skip the extra damage reduction if there is no gpu bo.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ccee730e45d8c2490e578d0b85d9e76f3a44f76f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Nov 26 16:47:04 2011 +0000
+
+    sna: Discard the gpu-bo is the entire pixmap is written to by the CPU.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit df68b20a17e28c0898226f970315bc8e515e9f56
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Nov 26 16:45:22 2011 +0000
+
+    sna: Disabling tiling if the bo would be smaller than a page
+    
+    Once again experiment with untiled smalled buffers.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d88ad2e60ac3d9f5608db1653a7af789f7f1b446
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Nov 27 09:01:09 2011 +0000
+
+    sna: Round up stride to alignment for TLB miss checking
+    
+    We want to avoid the condition of reducing the tiling mode (when reusing
+    an active untiled buffer in preference to creating a new) for a wide buffer
+    when doing will force a TLB miss on each sample.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 16f5e224dcfd97012b38ee1af6c72dbe3c0f3304
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Nov 25 16:21:41 2011 +0000
+
+    sna: Avoid the double application of drawable offsets for tiled spans
+    
+    As we handle tiled spans indirectly, we need to avoid applying the
+    drawable offsets twice (once in the mi layer generating the spans, and
+    then once more in the tiled rect renderer).
+    
+    Reported-by: Ulrich Müller <ulm@gentoo.org>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=43245
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e06789871b5cdf0c5535d46622b8ec3f85eb4386
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Nov 25 15:24:29 2011 +0000
+
+    sna/gen5+: Prefer using the BLT when either src or dst is untiled
+    
+    The cost of the TLB miss on every sample far outweighs the impact of the
+    context (and ring) switch.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d0cce0da71fae275a0f1be33b2bebad9d41212c9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Nov 25 13:16:37 2011 +0000
+
+    sna/gen5: Use the same prefer_blt_fill() switch for fill-one
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7ad2d3b695115439f685a12d43ab240cf5e18ef7
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Nov 25 09:44:21 2011 +0000
+
+    sna/gen2: Wire up NO_COMPOSITE for debugging
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 394ad51c421f41e4bc6545fcee10b1757cb5f518
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Nov 24 17:35:36 2011 +0000
+
+    sna/video: Check for Xv presence in the server before initialising
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a2fab9560ec5dd6efc352917fe7626e59bed69e3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Nov 24 17:14:08 2011 +0000
+
+    sna: Downgrade Y-tiling if we must use the BLT
+    
+    There are many operations, usually the core drawing acceleration, where
+    the BLT is much more preferable than using the CPU. However, the BLT is
+    limited to only using X-tiling, so if we encounter a Y-tiled pixmap
+    target we need to recreate it as X-tiling before proceeding. Hopefully,
+    the pixmap is then kept around and rendered multiple times to amoritize
+    the cost of the copy.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e0a4492c8b51d6ae09cde0b895da6177284e95e0
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Nov 24 17:00:18 2011 +0000
+
+    sna: Use Y-tiling for source pixmaps
+    
+    Y-tiling is slightly faster with RENDER operations, so attempt to
+    allocate source-only pixmaps using this tiling mode. Actually using
+    Y-tiling is a delicate balance because it then prevents the use of the
+    BLT. For instance, enabling Y-tiling by default gives a 30% performance
+    improvement on the fish-demo (compositing benchmark) at 2560x1440 on
+    Ironlake but regresses tiger-demo by 2x (spans benchmark).
+    
+    So experiment with this compromise and allow for changing the default
+    tiling.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7e4a1b7ed25a881113e197acde62b07f26f2d6ef
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Nov 24 11:34:51 2011 +0000
+
+    src/sna/gen5: Replace the precompiled shaders
+    
+    Take advantage of a couple of new instructions introduced with Cantiga
+    to reduce the instruction count inside the shaders and improve
+    performance by around 10% in the fish-demo.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 67ea8808d7f0ce47733a66d8708dcfa0dbec14c1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Nov 24 11:45:38 2011 +0000
+
+    sna/gen5: Remove the unused SIP
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 499ed74e979d99bbe1670ad54875fba6055fce5d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Nov 24 11:02:01 2011 +0000
+
+    sna: Tweak cancellation of deferred flush
+    
+    The goal is to keep running until the tick after every stops,
+    irrespective of forced flushes.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 35239d207c38e1ae0cb843ed7a72621711cb001e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Nov 24 02:51:51 2011 +0000
+
+    sna: Always call retire following a mmap
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 11e0b456de93dae9f7ba4298d8a32b6b60edc503
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Nov 24 03:04:09 2011 +0000
+
+    sna/gen5: Use the BLT rather than flush when copying
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a44663af9335136cba59b12078c6717992283b62
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Nov 24 02:54:43 2011 +0000
+
+    sna/gen4,gen5: Fix typo and only emit a flush if the video source is dirty
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4a27dd287cdb85d80ceaf6b54e7de0c17e01c00d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Nov 21 12:56:32 2011 +0000
+
+    uxa: Make the glamor/uxa transition more verbose
+    
+    And so hopefully make it clearer. In the process we restore the flushing
+    behaviour for UXA back to before the glamor intervention.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b0d64a9567d9cb749568448e4ce090b187308028
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Nov 21 11:49:49 2011 +0000
+
+    sna: Correct end-point adjustment for stippling PolySegment
+    
+    Reported-by: Roman Jarosz <kedgedev@gmail.com>
+    Reported-by: da_fox@mad.scientist.com
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=43134
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a5353a7c1d1f02b887f61f543c8e4bd4e8bd104f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Nov 21 10:58:17 2011 +0000
+
+    sna/gen4: Use the special composite rect emission for fill_one()
+    
+    In order to workaround a bug in the shaders on gen4, we need to flush
+    the pipeline after every rectangle. The recently introduced fill-one
+    mechanism for gen4, missed this vital step triggering a random hang with
+    an otherwise sane batchbuffer (the missing flush is hard to spot!).
+    
+    Fixes regression from 86f99379ee5 (sna/gen4: Add fill-one).
+    
+    Reported-by: Albert Damen <albrt@gmx.net>
+    Reported-by: Fryderyk Dziarmagowski <fdziarmagowski@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=43083
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3b9479dc39d32fd97f80c1e5e0fac67d36ee5e40
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Nov 19 19:12:06 2011 +0000
+
+    sna: Micro-optimise sna_push_pixels_solid_blt()
+    
+    Unroll the byte reversal as we know the row length is word aligned.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 297f7680cfd73ab6eb099adca7aefe00e61c9e85
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Nov 19 16:11:42 2011 +0000
+
+    sna: Avoid the NULL damage deref
+    
+    Fixes x11perf -wdcircle100 -time 1 -repeat 1 -rop GXxor
+    
+    Reported-by: Fryderyk Dziarmagowski <fdziarmagowski@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=43084
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4a86ec5ddbaf119fd9a32ecd963f7238152d7d28
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Nov 19 00:33:28 2011 +0000
+
+    sna/gen7: Apply recent SNB tuning as applicable
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fe944d61d53c275a168da2e9515d1e42be81630b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Nov 19 00:02:17 2011 +0000
+
+    sna/gen7: Correct shifts for surface state
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 70042400fd95f613b9547d0a72d6288abcc2357d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Nov 18 23:41:33 2011 +0000
+
+    sna/gen7: minor tidy of redundant defines
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f938cd15990d1a851b9d92414545dda37f00c5db
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Nov 17 13:43:37 2011 +0000
+
+    glamor: Include glamor cflags and libs for atypical builds
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit eb6148a36a318eb0b4aad865c34b50fedf4b709e
+Author: Zhigang Gong <zhigang.gong@linux.intel.com>
+Date:   Wed Nov 16 15:04:37 2011 +0800
+
+    uxa/glamor: Turn on glamor for fill spans and rects
+    
+    This commit only enables two glamor functions for
+    uxa_fill_spans and uxa_poly_fill_rects.
+    
+    Signed-off-by: Zhigang Gong <zhigang.gong@linux.intel.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fbabe60f48006ee664c983082498a863e8beec71
+Author: Zhigang Gong <zhigang.gong@linux.intel.com>
+Date:   Wed Nov 16 15:04:36 2011 +0800
+
+    glamor: Initial commit to introduce glamor acceleration.
+    
+    Added one configuration option --enable-glamor to control
+    whether use glamor. Added one new file intel_glamor.c to
+    wrap glamor egl API for intel driver's usage.
+    This commit doesn't really change the driver's control path.
+    It just adds necessary files for glamor and change some
+    configuration.
+    
+    Reviewed-by: Eugeni Dodonov <eugeni.dodonov@intel.com>
+    Signed-off-by: Zhigang Gong <zhigang.gong@linux.intel.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c4c2eb1fae2518578a56a278afeaec66d544439d
+Author: Zhigang Gong <zhigang.gong@linux.intel.com>
+Date:   Wed Nov 16 15:04:37 2011 +0800
+
+    uxa/glamor: Introduce additional access modes to wrap glamor acceleration
+    
+    Integrate glamor acceleration into UXA framework. Add
+    necessary flushing at the following points:
+    
+    1. Flush UXA batch buffer before call into glamor.
+    2. Flush GL operations after return from a glamor function.
+    3. The point we need to flush UXA batch buffer, we also
+       need to flush GL operations, for example, in
+       intel_flush_callback and couple of places in intel_display.c.
+    
+    Signed-off-by: Zhigang Gong <zhigang.gong@linux.intel.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ac7df2919b92c9fe47c6745975e1848932f989e8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Nov 16 23:25:16 2011 +0000
+
+    Revert "Disable adding normal RTF modes for an eDP"
+    
+    This reverts commit 212fa9868767637e8f430485eeb522c99e63fd16.
+    
+    The underlying register programming for eDP is now believed to be fixed
+    as of linux-3.1.
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=38012
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=41070
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 24ece4a87e34c27115ffb55f91294bce2bdf1502
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Nov 16 23:14:25 2011 +0000
+
+    configure: Version bump for 2.17.0 release
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 14b3176962bd535933623d8ed77ba286b077d6f0
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Nov 16 23:13:44 2011 +0000
+
+    NEWS: Release notes for 2.17.0
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c259144e3fc52d078b0a78107c38f0f3d3a2bbc1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Nov 16 10:28:23 2011 +0000
+
+    sna: The block handler is passed an indirect pointer to the timeval
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit bfd2bb40274d1242001d295a4010211fd51b0fc3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Nov 15 10:38:09 2011 +0000
+
+    sna: Correct dependencies for DRI2
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3771387ad11b5842a83e58a4b373c2acdd827bd2
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Nov 15 10:32:34 2011 +0000
+
+    Compile out UXA if so desired
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit edbeab8c4edf9e0e89d85add485fe659795b6350
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Nov 15 10:17:06 2011 +0000
+
+    sna: Reduce and clarify dependencies
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 78d4e99fc916e6477edb01c6f24b69ad73adc552
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Nov 15 11:06:04 2011 +0000
+
+    sna: And keep unity happy
+    
+    Rewrite the DRI layer to avoid the various bugs and shortcomings of the
+    Xserver and interfacing with mesa.
+    
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=38732
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=39044
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit aac022cbb3342e7027301a3f8c9add8929edbad6
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Nov 14 19:49:29 2011 +0000
+
+    sna: Optimise single pixel transfers
+    
+    Surprisingly frequent.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5647e2981d81fd2b5cdb22d544f83d2d0f9445c9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Nov 14 14:11:56 2011 +0000
+
+    sna/damage: Always reduce damage for testing PIXMAN_REGION_OUT
+    
+    Reported-by: Clemens Eisserer <linuxhippy@gmail.com>
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=42414
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 405b015fe255c75f91b0f3fe93f06bd14faee5a1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Nov 14 14:05:10 2011 +0000
+
+    sna: Be explicit in all sna_damage_contains_box() tests
+    
+    Clarify the exact in/out/maybe expected result when testing.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5d23149647b1645057dbd89087691e873494f763
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Nov 14 13:53:37 2011 +0000
+
+    sna: Remove redundant 'can_fill_spans()'
+    
+    Spans are almost always accelerated now...
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ae9de984adb275e028e7fbcb8b74a3ce11920eed
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Nov 14 13:39:34 2011 +0000
+
+    sna: Convert non-FillSolid rectilinear lines to boxes
+    
+    And render using the tiled/stippled rect routines instead.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e861e816f53989ce3ab3ec89dd1d9a35155f999a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Nov 14 13:39:34 2011 +0000
+
+    sna: Convert non-FillSolid rectilinear segments to boxes
+    
+    And render using the tiled/stippled rect routines instead.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6fc2928f578ae1e278c968d5c778d99d56bd667a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Nov 14 13:05:00 2011 +0000
+
+    sna: tidy assignment of composite damage
+    
+    Make sure that the damage is always set, even if only to NULL, so that
+    we are safe if in future the operation state is not initially cleared.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 99338ebe61917a07611cbc81cfaf70c0ec905014
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Nov 14 12:04:49 2011 +0000
+
+    sna: Check whether damage can be reduced to all-damage on moving to GPU
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 00d1c539e4b69636bfc35c0c47a6f1db3a33e731
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Nov 14 11:19:42 2011 +0000
+
+    sna/damage: Add a little more verbosity to debugging
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 60c0fc101adbc457a7c1927602175f8079175e10
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Nov 14 11:12:47 2011 +0000
+
+    sna: Refactor some common code into the common destroy-gpu-bo function
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 571457e9a4b0941ec956ef98391e96fe90fb4abc
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Nov 14 10:31:21 2011 +0000
+
+    sna: Be more thorough discarding fences for large objects
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e33dfbe3c00e634328adc7319261e5501f4c7a7a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Nov 14 09:41:53 2011 +0000
+
+    sna/damage: Verify that all-damage covers the entire pixmap after reduction
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f033172d2f383c7e17362a10f56c4958fb9a3a6b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Nov 14 09:32:53 2011 +0000
+
+    sna: Fix debug compilation
+    
+    Reported-by: Clemens Eisserer <linuxhippy@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=42887
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0c405595fb8739b22569f81f400100b5dfa472cf
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Nov 14 09:27:49 2011 +0000
+
+    sna: Downgrade tiling in order to fit within fence constraints
+    
+    Fixes a later assert that the fenced size is valid for kgem_create_2d()
+    
+    Reported-by: Clemens Eisserer <linuxhippy@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=42888
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1baff9f8cf79fdb4a5649eabcc66cf73487c873e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Nov 14 08:44:35 2011 +0000
+
+    uxa/gen4+: Re-emit composite invariant after video
+    
+    Reported-by: Ben Hutchings <ben@decadent.org.uk>
+    Bugzilla: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=635953
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7ad3b377a394c9342c3ab2f003d48b7cb3c0891d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Nov 13 17:53:11 2011 +0000
+
+    sna/video: Use the right pointer for unmapping
+    
+    Don't just deference any old random pointer, use the one we actually
+    mapped in the first place!
+    
+    Reported-by: Matti Hamalainen <ccr@tnsp.org>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=42880
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8da8809d03734d92c3bcf478fe051077ce3caa29
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Nov 13 17:49:23 2011 +0000
+
+    sna/video: Simplify check for 915G[M] which is simply gen==30
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit cac335b979a95e31e201f9766d19d737361e09b2
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Nov 13 13:13:03 2011 +0000
+
+    sna/video: Constify a couple of attribute arrays
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e592eb93dbd7df177993986f01ba6f65c4e20d4a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Nov 13 11:16:45 2011 +0000
+
+    configure: Version bump for 2.16.902 snapshot
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 56707b97dc746f7b46dd6cf94ba6c1db85ed619c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Nov 13 11:16:12 2011 +0000
+
+    NEWS: Details for 2.16.902
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f0acc6c0f15875fd51f6df6c8f13d589f9149771
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Nov 13 09:39:47 2011 +0000
+
+    sna/composite: Attempt to reduce the damage is the operation is contained
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 87147b63e905c3566ac1c12e0712f068e90d5e2e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Nov 12 19:35:43 2011 +0000
+
+    sna/damage: Reduce the damage for evaluating sna_damage_is_all
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e8799cdea461df5102d421fda26fecceae79b929
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Nov 12 12:19:31 2011 +0000
+
+    sna: Be stricter and disallow allocation of large fenced objects
+    
+    When allocating objects, we need to check the size of the full fenced
+    regions against the mappable limits in order to be able to mmap the
+    object later.
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=42813
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0269ec5533ecf7bec0f01c682e085861a3d2ab00
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Nov 12 11:49:32 2011 +0000
+
+    sna: Handle incremental uploads from PutImage
+    
+    PutImage rarely uploads the entire image inside a single request,
+    instead breaking up into scanline segments to fit within the protocol
+    limits. A few optimisations are based on detecting when we can discard
+    the GPU bo for an all-dirty CPU pixmap, which are useful in this case so
+    check for an entirely dirty pixmap following an incremental PutImage.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ed68f1b00ae7c0fb3be1f0e758b3683f3c26675b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Nov 12 11:13:59 2011 +0000
+
+    sna/gen7: Fix PRIMITIVE command
+    
+    The topology is now an extra dword rather than an embedded field in the
+    command.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 991ffcb60a15f08ebb396d4d4ec86d5aff0ded31
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Nov 11 23:20:36 2011 +0000
+
+    sna: Reset the source counter if we completely dirty the CPU pixmap
+    
+    For a long lived pixmap which we are repeatedly using for upload and
+    copying to other pixmaps, we don't want to keep to maintain a GPU
+    buffer. So instead, reset the source counter if we discard the GPU bo
+    and treat the pixmap as purely CPU.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 403a4dd353eef67decfba965e40623e8137e1944
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Nov 11 14:59:03 2011 +0000
+
+    sna: Defer source migration for a solitary upload via CopyArea
+    
+    Try to avoid allocating a GPU pixmap for PutImage followed by CopyArea.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 11acfaa62362660ff303f3afe90d1afa36b9ce73
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Nov 11 14:46:33 2011 +0000
+
+    sna/glyph: Tweak the small mask threshold
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c6e6ae1829e06ee8fe8eb063f2433cce603c9f96
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Nov 11 14:22:38 2011 +0000
+
+    sna/glyphs: Cache the glyph pixman_image_t wrapper
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8f50950f467eb2440009a807081f3ba2c9db209b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Nov 10 15:58:36 2011 +0000
+
+    sna/gen7: Remove stray no-op from GEN7_3DSTATE_SBE
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6a8338fc08a1b7e5e2c6722baa87cff3915b6ef9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Nov 10 15:11:13 2011 +0000
+
+    sna: Begin debugging gen7
+    
+    This is the stub of the decoder, sufficient to give details of the ops
+    within the batch and to keep the debugger happy.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2309f19638f8b2c35eb60fb44fa988aa5aaab57f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Nov 10 11:57:21 2011 +0000
+
+    sna/dri: Apply the damage for fullscreen async blits
+    
+    Otherwise gnome-shell forgets to update. Eventually, I'll get the async
+    pageflipping bits merged into the Xserver and this path and its extra
+    bw wastage will be history! But still I'll be undermined by the
+    compositor, grrr.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e65c2c54f5efcec16e97085dbc41042007c39151
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Nov 10 11:37:46 2011 +0000
+
+    sna: Store the sna pointer on the pixmap for cheap lookups
+    
+    A large part of the function preamble overhead is the multi-indirection
+    lookup for retrieving the sna pointer. We can eliminate most of these by
+    storing a pointer on the Pixmap as well, which we often need to lookup
+    anyway.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit bddac63de2d26c6ad4ade2f0a038d756f7a41424
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Nov 10 10:55:13 2011 +0000
+
+    sna: Defer purging a target buffer
+    
+    This is to keep the sanity checks upon the caches happy by keeping a
+    potential flush out of the inactive cache.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9083f7edcb05b1deb7a77c9c5a8b54fe73176648
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Nov 10 10:51:32 2011 +0000
+
+    sna/gen3: Fixup some false asserts
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ea01f7681901e3181204d3117fc0a23655de631f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Nov 10 10:51:01 2011 +0000
+
+    configure: Force full-debug builds to disable compiler optimisations
+
+commit a72563464f53f24246379afcf1365206fae9aad3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Nov 10 00:55:55 2011 +0000
+
+    sna/gen3: Clear the video shader flag upon batch reset
+    
+    Fixes regression from 3252b46e1.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3252b46e115e6cc46abbcc4f502feeb9edc31ad6
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Nov 9 15:16:04 2011 +0000
+
+    sna/gen3: Pack video frames
+    
+    If you're going to benchmark, you may as well do so favourably.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8e926759528a12076bd7565672acd82a37aa3eb1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Nov 9 14:44:54 2011 +0000
+
+    sna/video: Pass texture video limits to the client
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit bca58ff6f02b20ccf88937df8e2688f18cabac80
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Nov 9 14:18:57 2011 +0000
+
+    sna: Clear kgem->busy when all requests have been processed
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8fdbd01c94c0f6f56247feed8f225901ba39e18e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Nov 9 13:14:04 2011 +0000
+
+    sna/video: Use the normal bo cache for texture video streams
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 436a78684507129ca1245e065ff68870eb27624b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Nov 9 12:48:27 2011 +0000
+
+    sna: Track purgeability separately from reusability
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2699c01a396b644a35a9acb969ab556454be3517
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Nov 9 12:27:52 2011 +0000
+
+    sna: Handle non-reusable bo more correctly during retire
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fcc89d26600a57317007035fa720915e8a2ade81
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Nov 9 12:25:43 2011 +0000
+
+    sna: Safety first; make all flinked bo unreusable
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f62b9f94f64f402e731463205635d386386e274e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Nov 9 10:15:11 2011 +0000
+
+    sna/video: Pass cropped source dimensions along with frame data
+    
+    So pack all the relevant details into the same structure.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5809b1ad934d6e19dbcf00f1b59e156761ec16b6
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Nov 9 09:41:53 2011 +0000
+
+    sna/video: Tidy up copy routines
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1cd06100185a37ee33209fb18362da89f9646e6b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Nov 8 17:37:44 2011 +0000
+
+    sna: Protect against NULL deference of damage after reduction
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4b100b099a4d5877c79989e8b3b4ffcd3aa2306f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Nov 8 16:30:22 2011 +0000
+
+    sna: Convert stippled spans to rects
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7b95f87b26675af3a1923fef824c45e087098d61
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Nov 8 16:18:58 2011 +0000
+
+    sna: Use the blitter for overlapping lines if the alu doesn't read dst
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9a8d3a9dfff8be65b4ab28312ec49dbca36019e0
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Nov 8 13:51:00 2011 +0000
+
+    sna: Avoid the penalty of only writing partial channels with glyphs
+    
+    Yes, writing 3 channels is slower than writing 4. But it's okay we
+    simply ignore the alpha value anyway.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 576c5169efd068c364fb7d266fbb6b1dd2ad3f4d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Nov 8 13:27:05 2011 +0000
+
+    sna: Tidy sna_copy_bitmap_blt
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 32bbeefb8563ae2ab3a105d0b1c9b55d9587b788
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Nov 8 13:17:20 2011 +0000
+
+    sna: Pack clipped stippled uploads
+    
+    This are even more likely to fit inside the immediate payload.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3620cd2d157f3d81ccb76bce2ab813bd1e058878
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Nov 8 11:25:14 2011 +0000
+
+    sna: Begin hooking up valgrind/memcheck
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit aeaadb16093f83c9b830958c5946d4d048ffd26b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Nov 8 11:03:19 2011 +0000
+
+    sna: Handle creation of large Screen pixmap when the GPU is wedged
+    
+    Reported-by: Clemens Eisserer <linuxhippy@gmail.com>
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=42606
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7577d6ea45794b83d2f84b175d453d8a460b0e9b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Nov 8 10:24:34 2011 +0000
+
+    sna: Add some error messages to explain why we failed to create the screen
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 33256af40b3ce2cf8a899ced1fcbf40e316772e4
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Nov 8 09:55:07 2011 +0000
+
+    sna: Fixes for DBG_NO_HW (i.e. simulated GPU hanges);
+    
+    A couple of the recent GPU paths were failing to check for !wedged.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5f0886dae29429f498fb10a12d5dc8de6bd798fc
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Nov 8 00:02:18 2011 +0000
+
+    sna/trapezoids: Use ints for the offsets to accommodate multiplication
+    
+    Although the original precison need only 16-bits to store the offsets,
+    after projecting on to the sample grid we need a few more bits of
+    precision and so need a larger integer type to avoid overflow and render
+    glitches.
+    
+    Reported-by: Clemens Eisserer <linuxhippy@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=42680
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 33351d5c3dd912534c54e64ccfc7adc4c6f6ecae
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Nov 7 22:57:44 2011 +0000
+
+    sna/glyphs: Bypass masks for single glyphs
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e4872225ace7e3b129292f5822aa75b84c52beff
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Nov 7 22:57:05 2011 +0000
+
+    sna/io: Minor tidy of setting command flags
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5ba8ba7421e36bcdf83e84423595326939dbe7cd
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Nov 7 22:55:10 2011 +0000
+
+    sna: Avoid overwriting an upload buffer during readback
+    
+    Reported-by: Clemens Eisserer <linuxhippy@gmail.com>
+    Buzilla: https://bugs.freedesktop.org/show_bug.cgi?id=42677
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8f7a8a80237db77452f02273bd8ade68dfba575f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Nov 7 20:08:25 2011 +0000
+
+    sna/composite: Minor fixes in operator and colour reduction
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b1234f3d3a27f326b8048e3d6b476021a26e9101
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Nov 7 20:07:37 2011 +0000
+
+    sna: Expand multiplies of two 16-bit values to a full 32-bit range
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit afdf931e61821985b31b339d1f346ddd7c4e9e3c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Nov 7 20:06:35 2011 +0000
+
+    sna: Add some more debugging in the hunt for overflows
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8f3c845782fdb2fa8bdf751bdd7dd83ca02c42ac
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Nov 7 20:05:41 2011 +0000
+
+    sna/blt: Small cleanups
+    
+    Whilst perusing for overflows, remove some redundant conditionals.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8e775cecccebe543d344721d45b2d43ee9f122b3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Nov 7 20:01:33 2011 +0000
+
+    sna/gen3: Fix false reduction of ComponentAlpha with white source
+    
+    The principle behind the opertator reduction of WHITE * maskca is valid,
+    except that we failed to account for the src/mask transposition when
+    emitting the vertices - garbage ensued.
+    
+    Given that we agressively reduce the shader required for WHITE * maskca,
+    it does not seem worthwhile to special case the primitive emitter as
+    well.
+    
+    Reported-by: Clemens Eisserer <linuxhippy@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=42676
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 65a440543b13e3e605a4a2d6209a460fbbe55736
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Nov 7 20:00:20 2011 +0000
+
+    sna: Fix 16-bit overflow of rowlength for memcpy
+    
+    Reported-by: Clemens Eisserer <linuxhippy@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=42619
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d4edbd480445bc6aadd2c9f17262bd4b3eefbca6
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Nov 7 11:16:06 2011 +0000
+
+    sna/glyph: Fallback if we fail to clear the scratch pixmap for the glyph mask
+    
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=42663
+    Reported-by: Clemens Eisserer <linuxhippy@gmail.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 05f3e96a69af7750d2d62cf5ba991b89f39bc88a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Nov 7 09:28:19 2011 +0000
+
+    test: Compile fix for make check
+    
+    Reported-by: Jeremy Huddleston <jeremyhu@apple.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit cd3d86037746f3a03c4004c1e3ba6e8281344745
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Nov 6 11:13:27 2011 +0000
+
+    sna: Beware unsigned promotion of int16_t to uint32_t
+    
+    Mmakes for an unhappy mempy!
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0b9408d972050cb02c1024926c406cd45508a158
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Nov 6 09:55:09 2011 +0000
+
+    sna: Self-intersection of wide PolyLine are only drawn once
+    
+    We need to process the union of the PolyLine command if lineWidth!=0 so
+    we cannot generally feed lineWidth==1 into our special case handler.
+    Proving the lines do not intersect is as difficult as finding the
+    intersections and thereby finding the union of the path - so there is no
+    advantage in adding a check whether a wide line could be special cased.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c76714c29d29687f941a9112e80223c817185d53
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Nov 6 09:43:47 2011 +0000
+
+    test: Add a basic line tester
+    
+    Starting with exercising drawing of a single segment.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c1e1e20fe7875262530a4d522e970985642c3f13
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Nov 5 20:59:17 2011 +0000
+
+    sna: Add the pixman version to the debug output
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e2165f0e6b0620e3d788546924a2174506fbbde5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Nov 5 19:46:13 2011 +0000
+
+    sna: For a 32k max window size, we need to handle up to 128k strides
+    
+    Reported-by: Clemens Eisserer <linuxhippy@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=42619
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c5d94b21d5c65dcae3e294412a8f20bad347a6d8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Nov 5 14:32:16 2011 +0000
+
+    sna: Extend the zero-line segments by one
+    
+    Fixes misrendering of the wine tabs
+    
+    Reported-by: Clemens Eisserer <linuxhippy@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=42606
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0cf29afda9b061455bc438a22bbbfb1d6db6528e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Nov 5 12:36:53 2011 +0000
+
+    sna/glyphs: Fix clip detection for small masks
+    
+    -ENOCOFFEE.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d21c30d0b8b08ec85c3b5d9a02a6969f7c8b9315
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Nov 5 11:56:17 2011 +0000
+
+    sna: Constrain GPU pixmaps to always fit within the blitter
+    
+    Otherwise we end up always doing expensive readbacks where we would
+    obviously prefer it if we simply used cached memory for the CPU
+    operation and then upload.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e309cea3ae5c22c58a918008a52e3d8d694c9ff2
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Nov 5 11:28:06 2011 +0000
+
+    sna: Do the supported PictOp check first
+    
+    There is no point even attempting a BLT operation if we know that it is
+    an unusual render operation.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ab3d6d878fa27515eb760107d963d522cc87cd77
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Nov 5 10:08:02 2011 +0000
+
+    sna: Render small glyph masks on the CPU
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c25cf434d81ac1b4da29c9c75ca1d7c28be71d04
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Nov 5 01:04:54 2011 +0000
+
+    sna/gen3: Initiailse the op for fill_boxes()
+    
+    After removing the memset(0), a couple of fields where left
+    uninitialised, causing potential rendering glitches.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 96e760ea7589cbe953bd0a6f2f41980a7f1c4795
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Nov 5 01:04:24 2011 +0000
+
+    sna: s/flush/vblank/ fixes for DBG()
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 676cb4e38dc381b2ef4fb092b66db80687aa5013
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Nov 4 23:30:09 2011 +0000
+
+    sna: Run the deferred flush at vrefresh
+    
+    This helps to reduce the perceived jerkiness of the redraw.
+    
+    Reported-by: Clemens Eisserer <linuxhippy@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=42413
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8052c3904a1ac0308846ac13534c4c76bb96d5dd
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Nov 4 21:14:23 2011 +0000
+
+    sna: Drain the delayed timer after forcing a flush
+    
+    The goal is to remove a spurious wakeup when we have no work outstanding
+    afterwards and so would end up prematurely disabling the timer.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 112c61f6557c2337d5f1b25eb71d0dc9ada6ec89
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Nov 4 21:13:55 2011 +0000
+
+    sna: Convert GXcopy with -1 to GXset
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 573b23c6b618af808d3236395bbf4f4993b406e5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Nov 4 15:57:24 2011 +0000
+
+    sna: Add some asserts to detect buffer overflow.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4ba55c3d110ba51400a72da7d4f4c62efcea1335
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Nov 4 15:55:15 2011 +0000
+
+    sna/gen5: Prefer using the BLT for many solid fills
+    
+    Even if it means incurring a context switch, the BLT unit is
+    significantly faster so long as we do enough fills. And there is the
+    catch ;-)
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 703cf8abdbcda783e2bb0ceb423909ee8ca98176
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Nov 4 15:24:57 2011 +0000
+
+    sna: Add earlier guards against to wedged to sna_glyph_blt
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fc415ec3d3e982d89d7a25db8d5fd18e0412a99b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Nov 4 13:53:17 2011 +0000
+
+    sna/gen5: Also experiment with lazy spans here
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 567cfa508f788b4dd5de9aafbe2f148bb6a8dbc6
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Nov 4 13:43:03 2011 +0000
+
+    sna/gen6: Enable spans interface for boxes
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 465515a1446fd05fdc4691522803c94515187b4c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Nov 4 13:40:13 2011 +0000
+
+    sna: Silly compile fix, escaped when testing uxa
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a26c5d44ccaa7e9ff931948032b073f0a550343a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Nov 4 12:36:40 2011 +0000
+
+    uxa: Ensure that alphaMaps are mapped into the CPU for fallbacks
+    
+    Reported-by: Hans-Peter Budek <peter.budek@gmx.de>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 34758895cdd93bd7671a78464e79b3891bca113d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Nov 4 11:57:09 2011 +0000
+
+    sna: Ensure operations on a ShmPixmap are synchronous with clients
+    
+    If we are rendering to or from a ShmPixmap, we need to be sure that the
+    operation is complete prior to sending an XSync response to client in
+    order to preserve mixed rendering coherency.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5525691eb024f2a04b486652c24e0e34176fdd5e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Nov 4 10:49:48 2011 +0000
+
+    sna/gen6: Poor man's spans layered on top of the exisiting composite
+    
+    Performance of this lazy interface looks inconclusive:
+    
+    Speedups
+    ========
+     xlib         swfdec-giant-steps  1063.56 -> 710.68:     1.50x speedup
+     xlib          firefox-asteroids  3612.55 -> 3012.58:    1.20x speedup
+     xlib       firefox-canvas-alpha  15837.62 -> 13442.98:  1.18x speedup
+     xlib                  ocitysmap  1106.35 -> 970.66:     1.14x speedup
+     xlib             firefox-canvas  33140.27) -> 30616.08: 1.08x speedup
+     xlib                    poppler  629.97 -> 585.95:      1.08x speedup
+     xlib          firefox-talos-gfx  2754.37 -> 2562.00:    1.08x speedup
+    Slowdowns
+    =========
+     xlib                       gvim  1363.16 -> 1439.64:    1.06x slowdown
+     xlib              midori-zoomed  758.48 -> 904.37:      1.19x slowdown
+     xlib           firefox-fishbowl  22068.29 -> 26547.84:  1.20x slowdown
+     xlib       firefox-planet-gnome  2995.96 -> 4231.44:    1.41x slowdown
+    
+    It remains off and a curiosity for the time being.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5dba7028cd5024282b601c41ddfc9081eaa1d189
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Nov 4 11:24:03 2011 +0000
+
+    sna: Make sure the alpha map is accessible by the CPU on fallbacks
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 70c9e70f35af21de2b5b56d72f2a9e7fe9ed49d6
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Nov 4 10:19:21 2011 +0000
+
+    sna: Don't reuse partial vmapped bo
+    
+    A fun use after free.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7e8c9a5b8b1625fdfe885740c36da3f4c1373ee6
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Nov 2 14:02:56 2011 +0000
+
+    sna: Submit the batch on the next blockhander if operation overflows
+    
+    If an operation overflows from one batch into another, we submit the
+    complete batch and begin a new. That new batch will not be submitted
+    unless it is filled or on the next delayed flush update. This can cause
+    a flicker as a large operation is broken up, such as performing a
+    CopyArea through a Clipmask. So if we submit a full batch during a flush
+    interval, immediately flush any partial batch at the next blockhandler.
+    
+    This stops rude Santa flashing Rudolf in xsnow!
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5b21838471651a59d3e425c05a389c3f9196e21d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Nov 3 22:51:24 2011 +0000
+
+    sna: Compute the correct extents for the PolyRectangle
+    
+    Otherwise we may leave one behind...
+    
+    A regression from the introduction of sna_poly_rectangles:
+    40af32a0e9ed971a1f2c2a45266f32016bda7ed3 (sna: Execute blits directly
+    for PolyRectangle)
+    
+    Reported-by: Matti Hamalainen <ccr@tnsp.org>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=42568
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2174f840158aa9cfa370ade38be28f8dc8e4b526
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Nov 3 20:41:31 2011 +0000
+
+    uxa: Remove caching of surface binding location
+    
+    If the pixmap were to be used multiple times within a batch with
+    mulitple formats, the cache would only return the initial location with
+    the incorrect format and so cause rendering glitches. For instance, GTK+
+    uses the same pixmap as an xrgb source and as an argb mask in order to
+    premultiply and composite in a single pass. Rather than introduce an
+    overly complication caching (handle, format) mechanism, kiss and remove
+    the invalid implementation.
+    
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=40926
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a1b40a20bbba4b70990a8983a2916d3d5850d828
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Nov 3 19:27:23 2011 +0000
+
+    sna: Support binding of a bo for multiple formats
+    
+    Applications may use the same pixmap with multiple formats within the
+    same operation. For instance, you can premultiply and composite a normal
+    pixmap in this manner.  However, as we reused the sampler binding
+    locations of the source (without an alpha channel) for the mask, we
+    failed to read and multiply by the alpha channel causing it to remain
+    black instead of transparent.
+    
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=40926
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 31c5eb8e906bf8e59743372edb2d703b50cd311e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Nov 3 17:07:48 2011 +0000
+
+    sna: Clean up the fallback code for glyphs
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fa0fefd638d148d48760c95fe05520cddd96e5a4
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Nov 3 15:33:25 2011 +0000
+
+    sna: Restore the lowlevel glyph routines for the sake of Damage
+    
+    Damage bypasses the Text interface, preventing the backend from hooking
+    into the font and storing private glyph representations, and calls
+    directly into the Glyph routines. So to prevent a segfault we have to
+    restore them.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1677b273af67e2b690bd21a1b43a7d9f9d5a70c1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Nov 3 14:31:53 2011 +0000
+
+    sna: Skip encoding zero sized glyphs
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 239cfb99f9697392d7c25328093e6662ad04bdc9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Nov 3 14:25:54 2011 +0000
+
+    sna: Unroll the quadword upload of the glyph data
+    
+    We know that the length is nicely aligned and so can avoid a relatively
+    expensive call into memcpy.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e2542bad88573e590ef4cbeed6b5884166b56adb
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Nov 3 14:17:05 2011 +0000
+
+    sna: Add the missing returns to prevent fbImageGlyphBlt fallbacks
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit bc032c9be1bab7477fbf4b2a64fb7aca6d75ac18
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Nov 3 11:47:18 2011 +0000
+
+    sna: Coalesce reduction of cpu damage
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c92671b33ef30a8eb723eb366692ae3a5878b8f9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Nov 3 11:47:18 2011 +0000
+
+    sna: Coalesce reduction of gpu damage
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3b4a508eb022e9ade5929d3ebc97e0f9216a80b1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Nov 3 00:32:29 2011 +0000
+
+    sna: Translate glyphs into MSBFirst upon initial load
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8a259e34d3295af3be864e4fae96e6c3a9a632c7
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Nov 3 01:05:52 2011 +0000
+
+    sna: gc->miTranslate is always 1
+    
+    So we can perform some constant folding and eliminate dead code.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8f68f9e5f8341e20c4e1e46044f79806a44ecd03
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Nov 3 00:59:46 2011 +0000
+
+    sna: Trimming is redundant given that we always have a CompositeClip
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f4bdd84b846e6e778b7c496e7ed0d51e77310f36
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Nov 3 00:48:10 2011 +0000
+
+    sna: Simplify the uncommon check for gpu-only damage by using damage-all
+    
+    The use of a gpu-only scratch bo is uncommon with the core acceleration
+    routines, and we can eliminate the check for not incrementing the damage
+    by allocating a damage-all and using the common optimisation of
+    reduce_damage().
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 353fa4218cd904857fe95ef140e7f38aefe07578
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Nov 2 22:53:51 2011 +0000
+
+    sna: Don't call into retire unless there are outstanding requests
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6fdd0f254d2e58d425d6d23023e9db3d2924c6be
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Nov 2 22:23:16 2011 +0000
+
+    sna: Use an integer value for the sentinel
+    
+    clang complains otherwise.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1073c78f6cebfd6380b53dd891b7a72e50f398d6
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Nov 2 22:14:40 2011 +0000
+
+    sna: Pack small 1-bpp uploads into immediate buffers
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 73b2ef5a7de8d733fa1821e5010480ede305e25e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Nov 2 22:02:51 2011 +0000
+
+    sna: gc->pCompositeClip always exists after validate
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6fd0754e9c81164ca0fdcf96ba2bfb419568187f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Nov 2 18:03:07 2011 +0000
+
+    sna: defer calling fbValidateGC until we fallback
+    
+    A secondary effect is that this prevents needless migration of the
+    tiling pixmap which we want to optimistically keep on the GPU.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6f8875e216194474e818ba6e743e7c22b817f96e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Nov 2 15:41:40 2011 +0000
+
+    sna: Wait an extra interval before switching off periodic updates
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit def6b5e733e623333abf596bbdbabf8dd0ac8b00
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Nov 2 14:35:45 2011 +0000
+
+    sna: Only execute the accel block handler if we are about to block
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 088b875affb8655010bc678ca4a3e87703c92daf
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Nov 2 13:11:04 2011 +0000
+
+    sna: Use the packed 8x8 stipple for non-repeating small rectangles
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0c373db73d1d2b7cf844653307c60a3891a3cc10
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Nov 2 12:43:55 2011 +0000
+
+    sna: Fix the 8x8 stippled pattern origin
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9cdf8be55029f30b47cfc39ddd2754d40602cf2c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Nov 2 12:17:31 2011 +0000
+
+    sna: Add clipped stippled upload support
+    
+    For xsnow!
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6553c9e1cbfcecf781ba106de99f9e70c6d373ba
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Nov 2 10:03:45 2011 +0000
+
+    sna: Quieten a fewer compiler sign compare warnings
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 42e2036cda6b76f2b64e28a81bdaa661e4cbffa5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Nov 1 20:56:48 2011 +0000
+
+    sna: Use bo for scratch pixmaps allocated by the dix/mi routines
+    
+    Now that we have the rudiments of accelerated deep-plane copies, we can
+    begin to benefit from using BO for the core dix/mi routines like
+    ShmPutImage.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 45cc952994e169590ac4300f4ccf54810377f7f2
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Nov 1 20:20:35 2011 +0000
+
+    sna: Fix debugging assertions for Composite
+    
+    When comparing drawable clip extents against pixmap boundaries we need
+    to include the pixmap screen offset on a Composited desktop.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ebc9f3966d28343aebeba6886500abf511631785
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Nov 1 19:47:51 2011 +0000
+
+    sna: Accelerate deep-plane copy
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e0fd07bc251296784bf70f02877765171a053cc6
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Nov 1 17:02:17 2011 +0000
+
+    sna: Accelerate XYPixmap upload when using GXcopy
+    
+    Mostly for the lols.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 22c43efe6b9b5f669593aa9f3af6ee437426c5d2
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Nov 1 13:43:23 2011 +0000
+
+    sna: Implement 8x8 stippled rect fills
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c58b7643e9b86599a41ede516a778bd9869adc8e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Nov 1 10:13:20 2011 +0000
+
+    sna: Accelerate 1bpp uploads
+    
+    These still get used (see Wine and Swing) by applications which like to
+    do "crisp" 1-bit rendering on the client side and then put onto the
+    scanout. So avoid the readbacks, and push them through the BLT instead. It
+    turns out to be faster than using fb too, bonus!
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8939ddbc27efedbb3e446dd26425a6bed39577f2
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Oct 31 17:45:02 2011 +0000
+
+    sna: Improve rendering of thin segments
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 98b830a975e04685455b244a8414a293857cbd00
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Oct 31 17:41:27 2011 +0000
+
+    sna: Improve rendering of thin lines
+    
+    Reported-by: Clemens Eisserer <linuxhippy@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=42443
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6a5834ae560ef3b05c42b58ee0654316a66eaed0
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Oct 31 16:28:59 2011 +0000
+
+    sna/gen3: Fix invalid assert
+    
+    SHADER_CONSTANT is expected here, the other IMMEDIATES however should
+    have already been handled.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e12375d05bfb32933897b62829d82c6f1aa81d70
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Oct 31 14:24:19 2011 +0000
+
+    sna: Fix a few minor cut'n'paste errors
+    
+    Use the constant value [last_box-box] where applicable.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 20a4f533958991557a3b05af00f2856657579d68
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Oct 31 14:14:40 2011 +0000
+
+    sna: Apply the GPU damage for clipped PolyFillRectangles
+    
+    Reported-by: Clemens Eisserer <linuxhippy@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=42425
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7172f28c2b36aaa8c3a74ae4a7f699d3d4af10eb
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Oct 31 12:53:35 2011 +0000
+
+    sna: Fix placement of clipped wide PolyRectangle
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 59535d0e1c587cfe9249ab1baf9acf8470b49b8b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Oct 31 12:10:52 2011 +0000
+
+    sna: Set the flush interval based on output vrefresh
+    
+    Rather than a blank 25Hz, use twice the vblank interval to hopefully
+    avoid bad values.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9a2e59bfba6748325918f895b3e58351c7eb4baa
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Oct 31 11:56:53 2011 +0000
+
+    sna: Fix reversal of zero/wide for PolyRectangle
+    
+    Reported-by: Clemens Eisserer <linuxhippy@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=42414
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b1287e49347e0fff67f43d157fa87758d5cbe588
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Oct 31 11:27:36 2011 +0000
+
+    sna/video: Fix copy region for cropped video
+    
+    Reported-by: Clemens Eisserer <linuxhippy@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=42412
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b4ab412cb3eb8d37a33f5eeae5c613090ad2df0f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Oct 31 10:37:43 2011 +0000
+
+    sna/blt: Optimise fill with GXcopy and pixel==0 to a GXclear
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 088728ad26c7efc2d65b97ff22d526c65a0fa442
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Oct 31 10:04:35 2011 +0000
+
+    sna/blt: Don't idiotically override alu for pixel==0 and track alu
+    
+    Another classic and utterly stupid mistake. At least I was consistent in
+    my error.
+    
+    Reported-by: Clemens Eisserer <linuxhippy@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=42414
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9c399c74adc5e5bc7d425382a74d84315d2cef02
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Oct 31 09:20:54 2011 +0000
+
+    sna: Add an option to disable the delayed flush
+    
+    Section "Device"
+      Option "DelayedFlush" "False"
+    EndSection
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c8860ce26eaa8f9e876af2354d61c35338076ac8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Oct 30 23:25:48 2011 +0000
+
+    sna: Report whether anything was retired to the inactive list
+    
+    So that we can skip a fresh search of the inactive list if nothing
+    changed.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a7adcc8e47ba550e7c36a6543a6e0d99040c7354
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Oct 30 21:19:35 2011 +0000
+
+    sna: Stash the last scratch pixmap
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c8d4f5d32af94f712cc81ff495b19907261759ea
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Oct 30 21:21:25 2011 +0000
+
+    sna: Correct PolyRectangle verticals to be the end-point not the length
+    
+    Fixes an off-by-one in the drawing of the rectangles caused by a
+    too-literal translation of the rectangles into boxes.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5c45622b889ba66b6476241601e1458d219c45ba
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Oct 30 17:49:19 2011 +0000
+
+    uxa/glyphs: Fallback rather than fail to render with a non-solid Source
+    
+    Reported-by: Uli Schlachter <psychon@znc.in>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=31819
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e6eb803cb44b01e300fb4b08304227a430912beb
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Oct 30 17:44:26 2011 +0000
+
+    sna: Loop over all clip rects for glyph blt rather than fallback
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1eefb75c91fb769551b485f1b2c6b59023c69906
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Oct 30 17:17:36 2011 +0000
+
+    sna: Don't mess with NDEBUG
+    
+    This is set in configure and redefining it later inside the C files just
+    leads to trouble and broken compilation.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7237374a03d1e0c2e6c0b2d0eb42afc8df25df0d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Oct 30 16:46:10 2011 +0000
+
+    configure: Bump version to 2.16.901
+
+commit 0a78a75e75225d89e465804c482a667840a2c8de
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Oct 30 16:45:46 2011 +0000
+
+    NEWS: Add release notes for 2.16.901
+
+commit c7552cb819ae8c90975193c159236e0070628dd9
+Author: Daniel Vetter <daniel.vetter@ffwll.ch>
+Date:   Sun Oct 30 16:35:14 2011 +0100
+
+    i810: kill mmio vga access helpers
+    
+    Signed-Off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
+
+commit e8b8adeab3b2e69a8684217271604a5f658f617d
+Author: Daniel Vetter <daniel.vetter@ffwll.ch>
+Date:   Sun Oct 30 16:34:05 2011 +0100
+
+    i810: use vgahw functions instead of roll-your-own
+    
+    Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
+
+commit 4aeea489ed3189d7ebcae4199153c1ae736ebf68
+Author: Daniel Vetter <daniel.vetter@ffwll.ch>
+Date:   Sun Oct 30 16:07:45 2011 +0100
+
+    i810: rip out PIO access functions
+    
+    All the io done at init time is already converted to libpciaccess
+    
+    Signed-Off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
+
+commit e735636194671e221eca3e86b9bd06fd0d4b6c5a
+Author: Daniel Vetter <daniel.vetter@ffwll.ch>
+Date:   Sun Oct 30 15:51:49 2011 +0100
+
+    i810: kill dead i830 defines
+    
+    Signed-Off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
+
+commit bb840ee09fa620648065884306fbe3e0da37ad77
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Oct 30 16:13:04 2011 +0000
+
+    sna: Convert PolyRectangles to use Box32
+    
+    For the same overflow protection.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit af52e234a78bbde964a93ef8cce21f41a5c959f3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Oct 30 15:34:34 2011 +0000
+
+    sna: Fix compilation
+    
+    Remember to drink coffee and compile "obvious" fixes before pushing.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 23b314729c43101e515e2625db2a2401c72c2596
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Oct 30 15:24:21 2011 +0000
+
+    sna: Rewrite box32_add_rect() to enable int32_t promotion
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 427622aca31b7463eb2dcd52e352dc8997e84baa
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Oct 30 12:02:42 2011 +0000
+
+    sna: Push overflow detection to the end of extents
+    
+    Removes a couple of conditionals from the middle of the hotpath and on
+    Intel we are not realising the benefit of only utilising 16-bit values.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2d3aba8518ae790325c6123dacc3ce73b6e91cbd
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Oct 30 11:22:26 2011 +0000
+
+    Revert "sna: Don't flush the render caches if in the process of writing again"
+    
+    This reverts commit 15266e1b9500f6b348661c60d1982bde911f2d0e.
+    
+    KDE relies upon the ability to render into a sampler and then render
+    upon itself. Not the first sign of madness...
+    
+    Will have to find another way of winning back the compwinwin
+    performance.
+
+commit d4062705178856cffc83030fa40f758e9d884566
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Oct 30 10:40:32 2011 +0000
+
+    sna/composite: Fix incorrect operator reduction for RenderFillRectangles
+    
+    As exemplified by KDE (using Kate) on gen3, it would attempt to render a
+    large set of boxes using OVER and a transparent colour. As gen3 copied
+    across some of the BLT assumptions, it was incorrectly reducing that to
+    a CLEAR and thus rendering incorrectly.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit da3f8656744f7c801608c7c89a859c0f7dc9e6e0
+Author: Jeremy Huddleston <jeremyhu@apple.com>
+Date:   Sat Oct 29 20:15:11 2011 -0700
+
+    Use malloc/calloc/realloc/free directly
+    
+    Signed-off-by: Jeremy Huddleston <jeremyhu@apple.com>
+
+commit 17ba07a7befc7f442ae1c917a087ac026516d886
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Oct 29 20:03:37 2011 +0100
+
+    sna/gen3: Set the src flags for fill
+    
+    A regression from c2040fb8e62076d87f7a5b407505ee3f3482945e (sna: Remove
+    the memset(0) of the fill op) left the flags for the source channel
+    uninitalised leaving the shader construction undefined and causing
+    visual glitches.
+    
+    Reported-by: Paul Neumann <paul104x@yahoo.de>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=42367
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4835fe5b2e19ac456773565399f334845f7442c0
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Oct 29 18:56:29 2011 +0100
+
+    sna/genX: Improve reduction of Render operator to BLT alu
+    
+    This appeared to introduce a visual gitch into the xfce4 selection box
+    on gen6 at least.
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=42367
+    Reported-by: Paul Neumann <paul104x@yahoo.de>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 33383fde55609fb4bd372d2d41a6254799499225
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Oct 29 12:53:15 2011 +0100
+
+    sna: Tweak PolyRectangle blitting
+    
+    A box of height/width 1 and lineWidth 0 can also be drawn with a single
+    box as the far edge is contiguous with far side of the near edge.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 64a57c8dbec81f6420ff032985237eb16cebfb87
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Oct 29 11:01:51 2011 +0100
+
+    sna: Further clipping bugs
+    
+    Make sure the line is clipped to the current clip box and discard if the
+    clip is reduced to nothing.
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=42361
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 719626ef7918d5cd69d13f983b8b615aefe215d6
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Oct 29 10:26:08 2011 +0100
+
+    sna: Increment clip box when short-circuiting the iteration
+    
+    Reported-by: nkalkhof@web.de
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 32a9e0352a1e28509580d84bfc5377d8fae913c4
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Oct 28 23:14:24 2011 +0100
+
+    sna: Retire and search inactive again before creating new buffer
+    
+    Attempt to retire an active buffer into the inactive cache before giving
+    up and creating a new buffer.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 15266e1b9500f6b348661c60d1982bde911f2d0e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Oct 28 18:00:56 2011 +0100
+
+    sna: Don't flush the render caches if in the process of writing again
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d3c7ee921172d4898ebdc6e944812a02426008e9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Oct 28 16:44:16 2011 +0100
+
+    sna: Faster unclipped rectilinear segments
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3cd909cfe9e7d7e97a1d51513a049e312fd9ddae
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Oct 28 15:48:49 2011 +0100
+
+    sna: Call miZeroArcLine where appropriate for GPU paths
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9921c98df070032e082570f0663f6d3ad0cccd56
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Oct 28 14:09:11 2011 +0100
+
+    sna: Faster unclipped PolyFillRect
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c1718f96f520874c1fb2af0eb975c7f548762d34
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Oct 28 14:01:24 2011 +0100
+
+    sna: Faster unclipped PolyPoint
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a4762ed891a50238abddf6c762a053db5c34b87f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Oct 28 13:39:17 2011 +0100
+
+    sna: Call directly into tiled rects for tiled spans.
+    
+    As we already know the extents and that this is a candidate for
+    GPU-acceleration, we can skip over those steps and emit the tiled rects.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a02069df2ddc259d65ad468834f7968d283b713f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Oct 28 11:30:37 2011 +0100
+
+    sna: Faster unclipped spans
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 48eff1676c4066c8b8e069fd579a1b6fc2329960
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Oct 27 23:30:06 2011 +0100
+
+    sna/gen2: Reset BLT registers across 2D/3D context switches
+    
+    It appears the hardware trashes the BLT registers after a 3D context
+    switch, so we need to reload.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f006fac72a733e047b9468704e9c9206f62f96f5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Oct 27 21:50:25 2011 +0100
+
+    sna: Fast path typically unclipped tiled rects
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d6f543011bf3d03b9298b5ceeddfc1fc20fc534b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Oct 27 20:16:35 2011 +0100
+
+    sna: Use private identifier for internal scratch pixmaps
+    
+    This was meant to be a part of the previous commit.
+    
+    These are the scratch pixmaps for which we truly do want to allocate
+    GPU-only.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 14a065a267523f9a31be07daaab19b67e9f02290
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Oct 27 18:07:53 2011 +0100
+
+    sna: Create scratch pixmap on the CPU
+    
+    Contrary to earlier belief, the only usage of
+    CREATE_PIXMAP_USAGE_SCRATCH in the dix/mi are either along paths unused
+    by us or more importantly for operations which are detrimental to create
+    GPU-only buffers. So create CPU pixmaps instead.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5d52d5009375618bb703909fa0fad04e6d54a2ba
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Oct 27 17:06:51 2011 +0100
+
+    sna: Tweak zero line spans to include missing last segment
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 72e00096351137bd7eb0ae91474657a597836252
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Oct 27 16:36:39 2011 +0100
+
+    sna: Fix advance through clip boxes for fill->boxes
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c7bd89fb54686c14b687c007e42c34c23423b0fd
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Oct 27 16:23:35 2011 +0100
+
+    sna: Fix PolyPoint not to always send 512 boxes
+    
+    Just emit the remaining boxes!
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit cfd5b7f6ce80af911bfc8b71bba776ea814e307a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Oct 27 15:28:11 2011 +0100
+
+    sna: Use fill->boxes to pack PolyFillRectangle
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8d304f47e35be344550f389158eac3d4c21d9440
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Oct 27 14:43:46 2011 +0100
+
+    sna: Use fill->boxes for rectilinear blits
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5d51ff0cf901b808c3cd5aea761d51e6d15b73bf
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Oct 27 13:57:59 2011 +0100
+
+    sna: Clip PolyLines to the current clip box
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 990043f6b8cf8e580aad2e52f8d236a6aec838b5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Oct 27 12:33:55 2011 +0100
+
+    sna: Handle singular clip regions for PolyRectangles
+    
+    Otherwise X will crash!
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 991582f6678581e3d92c0497e10ecee67536efc2
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Oct 27 09:27:41 2011 +0100
+
+    sna/io: Update batch mode after submitting partial requests
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 91745de113340c8a281e8cb724b4a7e0b7a0711a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Oct 27 09:17:50 2011 +0100
+
+    sna: Further improve use of fill->boxes for PolyRectangle
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ffe1bdea82c07a2738743855dfa83494531b41aa
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Oct 26 18:37:29 2011 +0100
+
+    sna/blt: After submitting the batch, it will be empty
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b34e7454574f36796560955fb9d3d33ca00924d6
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Oct 26 18:11:25 2011 +0100
+
+    sna/blt: Convert Copy with color 0 into a Clear
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 389241aa6469b2e64a58cc0527e3310fdc69ffb7
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Oct 26 17:50:38 2011 +0100
+
+    sna: Suppress an overwritten fill
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit baf78fcddb87eba987163485ad8fd227fb244f29
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Oct 26 12:54:13 2011 +0100
+
+    sna/gen2: Cache the last solid colour for spans
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ff4715a36999a43cee20cf3474b4ae0af646342c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Oct 26 12:40:46 2011 +0100
+
+    sna/composite: Discard opaque masks
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0079579ebd548fc1b490a42928373507a93229bd
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Oct 26 11:49:53 2011 +0100
+
+    sna: Fix debug compilation, again.
+
+commit 5988422455ebb2a3b1cafadc1ff302c35a7a5039
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Oct 26 11:47:45 2011 +0100
+
+    sna: Handle degenerate copy area whilst wedged
+    
+    We want to return early to avoid handing the empty box as the lower code
+    makes the assumption that it has work to do.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3fc7cd2dc8e2b9c0d4143a9f6657f84050ae249a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Oct 23 20:59:50 2011 +0100
+
+    sna/blt: Rename the composite paths
+    
+    Whilst re-reading, I found the old naming scheme slightly muddled and
+    not nearly as descriptive as it should be. Hopefully this slight tweak
+    reads better in 6 months time.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 280325900bf3c17c3177f6e3f52236d6b452e0f3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Oct 23 20:58:48 2011 +0100
+
+    sna/blt: Share the common fill->boxes between blt and render paths
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 56f65e65204f1ecbad598419e525e69f6179f9c7
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Oct 23 20:40:21 2011 +0100
+
+    sna: Inline box_intersect()
+    
+    Most of this branchy function is spent in manipulating the stack for the
+    function call, so inline it.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f65e73f8a3a013e79b753d625f79994408e717f7
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Oct 23 19:55:40 2011 +0100
+
+    sna: Use fill->boxes to unroll FillSpans
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 94f9cd40dcdd444d3b5a5598deb0f3d04026df3a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Oct 23 19:11:35 2011 +0100
+
+    sna: Use fill->boxes to unroll PolyPoint
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5e08ca75a5eb852c09b9acf6004668bc63f1fe6c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Oct 23 17:53:54 2011 +0100
+
+    sna: Use the new fill->boxes for PolyRectangle
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit efdc7985e2f619ca94cf6ad77ead4f6867ceedc5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Oct 26 14:57:28 2011 +0100
+
+    self-copy-damage
+
+commit 0ed3426a810336b666604d34c10f996f318ebf82
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Oct 21 23:45:28 2011 +0100
+
+    sna: Convert diagonal zero-width lines into blits
+    
+    This is slower than falling back to swrast for x11perf (up to 4x slower
+    on SNB), it is still faster than doing that rasterisation through a
+    WC-mapping and much faster in ordinary usage due to avoiding the
+    readback hit.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c12371d9e7b3bbff7f318186a0933d6108db0bc8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Oct 21 22:28:56 2011 +0100
+
+    sna: Flatten the branching for fill-spans
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e7f19d85fead62df21eedc87409b5abacfec4a17
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Oct 21 22:15:09 2011 +0100
+
+    sna/blt: Upload the box using a single 64-bit instruction
+    
+    So long as we have 64-bit instructions of course!
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 40af32a0e9ed971a1f2c2a45266f32016bda7ed3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Oct 21 20:10:02 2011 +0100
+
+    sna: Execute blits directly for PolyRectangle
+    
+    By constructing the batch buffer directly for PolyRectangle, rather than
+    via miPolyRectangle->(PolyFillRectangle/PolyLine), we dramatically
+    reduce the CPU overhead and can saturate the GPU.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a18f559961135fa288dda3b94207abb0b6d4d302
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Oct 21 16:37:09 2011 +0100
+
+    sna: Fix debug compilation
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a3a075201c8e47cfad6ec296b7baf549deb44cb3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Oct 21 15:30:52 2011 +0100
+
+    sna: Treat a bo marked as being last seen on the GPU as requiring a flush
+    
+    We are hitting this path upon retiring the old scanout buffer following
+    a page-flip. We want to treat this as being hot and available for reuse,
+    so mark it as such until the next retirement pass.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 999d13f32162ce11fe4042825b5b849073944ca8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Oct 21 12:43:02 2011 +0100
+
+    sna: Fast path unclipped points
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit eb80013f4ea50ad4f54b4d1d90c5e9da27e1c34c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Oct 21 11:49:55 2011 +0100
+
+    sna: Fast path for unclipped rectangles
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d6ae86a51cc49dbba579838edd24a94e8f68294c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Oct 21 03:06:20 2011 +0100
+
+    sna: Optimise reduce_damage() to handle all-damaged pixmaps
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5b945b85ee938688412df6adfea488766f4656af
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Oct 21 02:45:50 2011 +0100
+
+    sna: Fast-path unclipped fill spans
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e9a193e9803bb69fc4a7e712f33a36ba395b3c89
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Oct 21 02:20:22 2011 +0100
+
+    sna: Short-circuit GetWindowPixmap() to speed-up pixmap retrieval
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 662402e41e5c7976002a71a7f961ca97c771b1f3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Oct 21 02:11:19 2011 +0100
+
+    sna: Micro-optimise PolyLine blt
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c2040fb8e62076d87f7a5b407505ee3f3482945e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Oct 21 02:00:44 2011 +0100
+
+    sna: Remove the memset(0) of the fill op
+    
+    The backends are all expected to initialise the state required.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7e7759db4c1dbf8b782fab9b9ca95cfa1db6cf59
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Oct 21 01:41:56 2011 +0100
+
+    sna: Pass a BoxRec to the fill op
+    
+    For many of the core drawing routines, passing a BoxRec for the fill is
+    more convenient since they already have one generated by the clip
+    intersection.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 98bca2dbb9c33c548b1d9789ddb633ae0389c8f1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Oct 21 01:07:52 2011 +0100
+
+    sna: Check whether we can blt whilst determining the PolyLine extents
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 91f49549750aac99d38ae8f3a132c955a2c8d8f5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Oct 21 00:42:43 2011 +0100
+
+    sna: Speed-up blitting of unclipped lines
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 06d7574d7da047a6314be5af27f4ac47ccd5a350
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Oct 20 21:38:30 2011 +0100
+
+    sna/damage: Stash the last freed damage for quick reallocation
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1471ef82b595a207dc8873c45176ec31f277a43f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Oct 20 21:32:14 2011 +0100
+
+    sna/damage: Only track the mode globally
+    
+    As damage accumulation is handled modally, we do not need to track the
+    mode per elt and so attempt to simplify the code.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1229bf6a690e7f315ab22957da23481f58515ff9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Oct 20 17:37:41 2011 +0100
+
+    sna: Actually apply the composite offset for the self-copy
+    
+    I translated the region to copy by the composite pixmap offset, only
+    failed to use the translated region for the actual copy command (using
+    instead the original boxes). Fix that mistake by avoiding the temporary
+    region entirely and applying the translation inplace.
+    
+    We also have to be careful in the case of copying between two composited
+    windows that have different offsets into the same screen pixmap.
+    
+    This fixes the regression introduced with a3466c8b69af (sna/accel:
+    Implement a simpler path for CopyArea between the same pixmaps).
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3526d83e460ce6410f23f59d1315793ff9607253
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Oct 20 00:29:52 2011 +0100
+
+    sna/dri: Perform a little dance to restore the gpu status on release of the bo
+    
+    As the bo is outside of our control whilst it is under the influence of
+    an external renderer, we try to maintain it on the gpu so as to avoid
+    unnecessary ping-pong. But once it is wholly back under our control, we
+    want to stop paying the penalty for sharing it.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 50b980f12e02401cdd4bc21b970d92e7bd1e6459
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Oct 19 21:09:01 2011 +0100
+
+    sna: Reuse any partial write buffer for readback
+    
+    Take advantage of any available temporary buffer that we reuse for
+    readback knowing that it is the last operation in the batch.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 972989276dd3f84c1cedca0494d04f907875f8f3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Oct 19 20:41:14 2011 +0100
+
+    sna: Add some debug to discern the nature of the Cr fallback
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fc224e2f8c0200c114f8dbddfc4f5395a3ef0fad
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Oct 19 20:20:55 2011 +0100
+
+    sna: Clean up some debug messages for 64bit
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f4346e5d255f419ee6148f7d69f02560732dd4de
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Oct 19 19:26:19 2011 +0100
+
+    sna/blt: Use SCANLINE_BLT for multiple fill boxes
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d7fb98efdcc1bcc2cca6deb54b16d425b0350196
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Oct 19 17:52:56 2011 +0100
+
+    sna: The initial aperture check for a set of bo is unlikely to fail
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3c8e1c5c4cbe703781f2845926f76a9537a971ea
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Oct 19 16:35:08 2011 +0100
+
+    sna: Reset the ring flag upon idling
+    
+    We track the last ring used when active so as to avoid stalling between
+    batches. Once the GPU has retired all the pending requests, we can use
+    whichever ring is preferrable for the next operation without any danger
+    of stalling upon submission.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 594c5f86bb2e1cd0390b360c926ead58ba49979f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Oct 19 16:25:42 2011 +0100
+
+    sna: Don't rewrite the solid colour cache if it hasn't changed
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5515f75647bb148d9e720dcc4713a93b59ffbd49
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Oct 19 13:49:55 2011 +0100
+
+    sna: Enlarge the minimum pixmap size to migrate for Render
+    
+    This is to workaround a ping-pong issue involving small icons. The
+    horrible sequence of operations appears to use a tiled FillRect to copy
+    from the scanout onto to a temporary pixmap, which causes us to
+    readback from the scanout. We are destined to hit the fallback path there
+    anyway until we implement stippling...
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=41718
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 87ba33bc0bcaf3c5160edfc61cff3ba0d28d3fd8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Oct 19 13:09:19 2011 +0100
+
+    sna/damage: Avoid reducing the damage for simple tests
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 63aa84ef57ff1e55d2df6d680d6bbf88be0619a6
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Oct 19 13:08:50 2011 +0100
+
+    sna/gen6: Apply the unknown blitter death workaround
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 25f2d181946738d1ac2deb724eb48453c8692ed1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Oct 18 23:03:10 2011 +0100
+
+    sna: Compute region extents in place to eliminate redundant stack space
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1a43b2a46a67fdea215719c4446224c9d2e26a20
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Oct 18 17:52:56 2011 +0100
+
+    sna: Use the unlikely wedged() throughout
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7a9c76e1812d106fedf160c959e6e502998e4ce8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Oct 18 15:51:33 2011 +0100
+
+    sna: Micro-optimise fill-spans
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0b83abfb2bc3f65447205048ae0af1a94fa9ef15
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Oct 18 14:43:37 2011 +0100
+
+    sna/gen6: Don't modify composite arguments whilst checking for BLT
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ae7bd2bf70b42b8c12e5e5ae074891595827a1c0
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Oct 18 11:54:05 2011 +0100
+
+    sna/blt: Move the conditional out of the fill-many hotpath
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 86f99379ee55b157634174c4c8aad61a30b4f57f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Oct 18 11:35:12 2011 +0100
+
+    sna/gen4: Add fill-one
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 26c082dbd3f89b987168d321f72e78db8c5ddc2c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Oct 18 10:50:53 2011 +0100
+
+    sna/gen6: Precompute floats_per_rect
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c69a7989b3c9cedc961e29b1a569b174207964ae
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Oct 18 10:48:37 2011 +0100
+
+    sna/gen5: Add fill-one implementation
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 26a1918290b2d23de72a67805fe5e766da0c5309
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Oct 18 10:42:48 2011 +0100
+
+    sna/gen6: Try continuing with the BLT if the last batch was also BLT
+    
+    In the vain hope of reducing switching between rings and introducing
+    stalls between batches.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4b1398f26d4de44167096c6548ff7384c24d5e06
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Oct 18 00:29:18 2011 +0100
+
+    sna/gen6: Micro-optimise gen6_rectangle_begin
+    
+    We can only emit state between primitives, ergo we need only check for
+    state updates if we've finished the vbo or are starting a new operation.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b2d842df5e3198dab401fbd450d4af83d44917dd
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Oct 17 23:34:19 2011 +0100
+
+    sna/gen2: Precompute floats-per-rect
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 729f1ec7869167ff91fa969d06dbdfbf0e8b4126
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Oct 17 23:20:20 2011 +0100
+
+    sna/gen2: Prefer to use the BLT
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit adef3a56cde1210554dc8327baa37c36fc5f18e3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Oct 17 23:08:32 2011 +0100
+
+    sna/gen3: Prefer to use the BLT where possible for composite ops
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f40e6ab50b264ef7eb7750f72ab7418c0d3dc9c1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Oct 17 23:06:30 2011 +0100
+
+    sna/gen3: Prefer to use the BLT to clear the scratch glyph pixmaps
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 941e3504e049be8af50ca9df2d0aafe9eb477983
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Oct 17 19:51:33 2011 +0100
+
+    sna: Some more debug output for request/bo retirement
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1d82fe3e528578d11d2a258b586b67c807eb7cb4
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Oct 17 19:47:03 2011 +0100
+
+    sna: Only retire the flush handler if nothing was submitted within the period
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7758e333409409393c4c974adb2831a7b5b18fe4
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Oct 17 19:32:44 2011 +0100
+
+    sna/gen3: Use immediates for black/white solid sources
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 29ca1a3922cb0e6f3d7b71857a252e5de81941b5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Oct 17 17:16:16 2011 +0100
+
+    sna/gen3: More removal of memset(0)
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 88bc10878830dffefda6ed905c1f598d7a7d67ef
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Oct 16 20:05:49 2011 +0100
+
+    sna/gen5: Rearrange the BLT->RENDER workaround
+    
+    So that we can simply use the pending DRAWRECT as the non-pipelined
+    flush required following use of a BLT command.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 18aed47ba37ccfbcdd72ed251fc97222741c66a7
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Oct 17 16:41:14 2011 +0100
+
+    sna: Fast path common colour conversions
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a3466c8b69afeda95180fcdc97b56d31f7a1d1ad
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Oct 16 20:52:47 2011 +0100
+
+    sna/accel: Implement a simpler path for CopyArea between the same pixmaps
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8afa05191a9a337ce6e02b1064de2876f5635435
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Oct 17 00:55:51 2011 +0100
+
+    sna: Improve debug output for mi/fb fallbacks
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2b118658d5b9cfa56132f91238f2ea61fba8b357
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Oct 17 15:00:01 2011 +0100
+
+    sna/gen3: Remove memset(0) from fill_boxes
+    
+    And initialise only the state used for the operation.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f1bb4ebfd8991f2f9eb9c38b9259792c11e7c86a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Oct 17 14:22:58 2011 +0100
+
+    sna/damage: Clear damage->all when subtracting
+    
+    I missed clearing the all-damaged flag on the subtract fast paths,
+    causing us to disregard further GPU damage and losing track of render
+    coherency.
+    
+    Reported-by: Roman Jarosz <kedgedev@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=41769
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 46f97127c22ea42bc8fdae59d2a133e4b8b6c997
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Oct 16 21:40:15 2011 +0100
+
+    snb,ivb: Workaround unknown blitter death
+    
+    The first workaround was a performance killing MI_FLUSH_DW after every
+    op. This workaround appears to be a stable compromise instead, only
+    requiring a redundant command after every BLT command with little
+    impact on throughput.
+    
+    Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=27892
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=39524
+    Tested-by: Daniel Vetter <daniel.vetter@ffwll.ch>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 71bf291e563ec5224777b4907a5347a3fbfe64c5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Oct 17 12:53:19 2011 +0100
+
+    sna/gen3: Micro-optimise gen3_rectangle_begin()
+    
+    We only need to emit the vbo description either at the beginning of a
+    new op (when the state may have changed) or after finishing a full vbo.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a032feb2531439b9945d7ae1e0c2e3ab95a960e1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Oct 17 12:41:21 2011 +0100
+
+    sna/gen3: Store floats_per_rect alongside floats_per_vertex
+    
+    Moves a multiply out of the hot path.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2cbe79b85b46796d561105afa980e7a52f4f1889
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Oct 17 11:57:07 2011 +0100
+
+    sna/gen3: Improve reduction of render operator to blt
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 606e18bd360d904a8aed01aef43644fb4a51d929
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Oct 17 10:50:33 2011 +0100
+
+    configure: Add a check for pixman version
+    
+    As SNA requires a fairly recent release and calls directly into pixman.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 17acaf8e232a8bad9bc2c653a9fceb06f0f65f6b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Oct 17 00:55:51 2011 +0100
+
+    sna: Defer CPU fallback if fb calls into mi
+    
+    If the fb routine does not access the pixel data directly, but instead
+    calls into an mi routine, we can defer the readback and possibly avoid
+    it.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c348b69f66cbe1cafc88396523da9768e1006889
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Oct 16 18:23:33 2011 +0100
+
+    sna: Prefer to accelerate non-RENDER operations if already using the GPU
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6fdc9e3fd3f8defb7ad62de11f8cb069a10e5736
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Oct 16 17:57:55 2011 +0100
+
+    sna: Simplify busy tracking by trusting the bo->gpu flag
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 30dff81cd62b5fc5a28d5175a08c5a3ee09667bd
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Oct 16 17:41:34 2011 +0100
+
+    sna/accel: Upload source to GPU for !copy CopyAreas
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit eefa925e3d3e009b21ecc0b428d93a6c732bfa14
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Oct 16 17:39:06 2011 +0100
+
+    sna/accel: Fall-forward for handling a non-copy CopyArea to a dst gpu bo
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 01f41e624b31af88d433a25eaefce557e7ff3d62
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Oct 16 17:38:26 2011 +0100
+
+    sna/gen2: Eliminate redundant diffuse and rectlist emission
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d9e3dbffcb7e6cff35e10100d81544936813095a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Oct 16 12:48:23 2011 +0100
+
+    sna/gen2: Fix fill-one-box
+    
+    Lets only have one special gen2 value for the source channel pixel
+    colour and so remove the confusion and misrendering.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b89592b16e373da1fe259ad067f65ba95021dc49
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Oct 16 19:39:14 2011 +0100
+
+    sna/gen7: Add missing tail to 3DSTATE_SBE
+    
+    I was a few NULs short of the declared amount.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 33f17b996dd0fcbb8e07875770e11571380d6509
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Oct 14 12:01:34 2011 +0100
+
+    Remove a couple of trivial compile warnings for unused variables
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e5e27528ffeb74f404823c678e04e847cf2109aa
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Oct 14 11:51:44 2011 +0100
+
+    sna/blt: Add a pair of operator reductions for opaque fills
+    
+    Extend the coverage of the BLT for a couple more composite operations,
+    though they be relatively infrequent.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3f5289b29962c3e5d94deb30782a156292d20053
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Oct 14 11:31:46 2011 +0100
+
+    sna/trapezoids: Fallback if the composite operation is not supported
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3d79264ef8a8be225d9b13efd14f37a7478e6b1b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Oct 14 11:31:00 2011 +0100
+
+    sna/tiling: Hook up composite_box
+    
+    Now used for spans and so triggering death by NULL function pointer on
+    older chipsets.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f5f3135e3cc1f4740508773cfefca0954aed2fd3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Oct 14 10:40:39 2011 +0100
+
+    sna: Ensure that the scanout is flushed before we sleep
+    
+    So that we do not see any delayed rendering on i965+.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 020d84d2d09c71a8209dd774a0735a3c11cb148d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Oct 13 22:32:00 2011 +0100
+
+    sna/accel: Fix sense of nothing-to-do due to clipping
+    
+    A missing not due to a hasty conversion from an assert.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b7fd6906c41e328649b97e16c42848a39f6e48f8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Oct 13 17:46:48 2011 +0100
+
+    sna/accel: Actually apply the clip to the glyph extents
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=41718
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit eb5f86b78181b174664aaa9bc689db5421b7e7bd
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Oct 13 17:32:54 2011 +0100
+
+    sna/accel: Correctly offset the damage intersection for glyph runs
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a4766026ad0aa14283e35598d33f13d311cc029b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Oct 13 17:32:30 2011 +0100
+
+    sna/accel: Check for reloc overflow when adding a new glyph run
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b10850af4125b8dbc36d13fa83f1dcce13ac6684
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Oct 13 17:09:25 2011 +0100
+
+    sna/blt: Check for reloc overflow when initialising solid fills
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d5242565ef17cb4265177338df5b564b960e3692
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Oct 12 21:14:43 2011 +0100
+
+    sna/gen2: Trim some surplus state commands
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7c5020532335c07d9b0f6cecb0b004de4af6d273
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Oct 12 20:36:53 2011 +0100
+
+    Remove vestigial includes from DRI1
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b6b3bb9b5e56949cbd9189d9857ffa1ff46377fd
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Sep 20 19:41:03 2011 +0100
+
+    sna: compare against the right array of cache buckets
+    
+    Fortunately harmless today as there are the same number of
+    inactive/active buckets.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1f70095837a30d6a88b9e313d3583d38ea55221d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Oct 11 16:06:31 2011 +0100
+
+    sna: And free the clip after creation for PolySegments
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 92f4d978c8b1f5e9a6cf3affa15d90bfb3d4e7b9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Oct 11 15:52:13 2011 +0100
+
+    sna: More micro-optimisation of messing around with clip regions
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 57151f654752ed64716358ecb5e9217b59784da8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Oct 11 15:23:17 2011 +0100
+
+    sna: Micro-optimise checking for singular clip boxes
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 823a4272c50247482428a16cb08741bf87a302ea
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Oct 11 13:51:41 2011 +0100
+
+    sna/gen3: Avoid RENDER/BLT context switch for fill boxes
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 887361de173e082841453902089427447c5a158a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Oct 11 13:51:25 2011 +0100
+
+    sna: Enable single fill fast path for PolySegment
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 721cf30e9eeb0102c77f337332ad8259463b7fef
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Oct 11 13:28:45 2011 +0100
+
+    sna/accel: If the data is already on the GPU, use it for the source
+    
+    Fixes regression from 1ec6a0e2775 (sna: Move the source to the GPU
+    if it is reused).
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 15a4410cec111c3b3bd15ec33f29bc1f4cb709c1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Oct 11 13:28:30 2011 +0100
+
+    sna: use correct insertion point for sorting partials
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a9b53c48774078d404149e86267c39eb82234c3a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Oct 11 10:37:25 2011 +0100
+
+    sna: Mark the spans render functions as fastcall
+    
+    This reduces the amount of dancing required to call into the span
+    functions as we can pass the arguments in both the integer and floating
+    point registers.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 208fa8e6b88daf8446239a1a001a68ceb7d02e76
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Oct 11 10:08:42 2011 +0100
+
+    sna/trapezoid: Perform the NULL check for damage in the caller
+    
+    Save the function call overhead in the common case.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5050fead0ef81785a2a9be735852921463377e04
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Oct 11 09:59:13 2011 +0100
+
+    sna/gen3: avoid applying zero offset to common spans
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d0184b59095d5b8fab1a65ceba075d29189130d4
+Author: Daniel Vetter <daniel.vetter@ffwll.ch>
+Date:   Sun Oct 9 18:43:14 2011 +0200
+
+    snb: implement PIPE_CONTROL workaround
+    
+    Sandybdrige requires an elaborate dance to flush caches without
+    hanging the gpu. See public docs Vol2Part1 1.7.4.1 PIPE_CONTROL
+    or the corrensponding code in mesa/kernel.
+    
+    This (together with the corresponding patch for the kernel) seems to
+    fix the hangs in cairo-perf-traces I'm seeing on my snb machine.
+    
+    v2: Incorporate review from Chris Wilson. For paranoia keep all three
+    PIPE_CONTROL cmds in the same batchbuffer to avoid upsetting the gpu.
+    
+    Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
+
+commit 4a2e833ab17e4facf0f90166b82a5696a1deef91
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Oct 11 08:45:47 2011 +0100
+
+    sna/gen7: Add render support for fill one
+    
+    To prevent the RENDER to BLT transition and potential stall.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 41f525fab5a82c24adafc7e8c8409417d16a0e9a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Oct 11 00:22:11 2011 +0100
+
+    sna/gen6: Add render support for fill-one-box
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5b6575bdded4b24ec1c9515203f44798225c10b6
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Oct 10 16:39:02 2011 +0100
+
+    sna: Support a fast composite hook for solitary boxes
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c5414ec992d935e10156a2b513d5ec2dded2f689
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Oct 2 12:02:41 2011 +0100
+
+    sna: Use BLT operations to avoid fallbacks in core glyph rendering
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6b62b9d7c4301457a024f840383fb4515704ebdb
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Oct 4 19:30:06 2011 +0100
+
+    sna: Increase reserved space in batch to accommodate gen5 workaround
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6351d8eb823dbfffb4792af8592d1ce565211e23
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Oct 4 19:29:46 2011 +0100
+
+    sna/gen[23]: Fix compilation with debugging enabled
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1ec6a0e27753027a68beeaff0276ae65c658d468
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Oct 3 16:14:18 2011 +0100
+
+    sna: Move the source to the GPU if it is reused
+    
+    We attempt to skip upload a source pixmap to the GPU in the event it is
+    used only once (for example during image upload by firefox). However, if
+    we continue to use the CPU source pixmap then it obviously was worth
+    uploading to the GPU. So if we use the CPU pixmap a second time, do the
+    upload and then blit.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 413c9f7111c605a3842d4d0a85f8cf01470e5faa
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Oct 3 00:24:50 2011 +0100
+
+    sna/blt: Suppress repeated SETUP_BLT
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1067335305a6b8123217518085f70a77b7f0334f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Oct 3 00:11:55 2011 +0100
+
+    sna/blt: SETUP_BLT needs 9 dwords of batch space, not 3!
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d8c96a6a1d50cd3dd40fd4b78958c8f78337a2fb
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Oct 2 12:57:53 2011 +0100
+
+    sna/blt: Use SETUP_MONO to reduce the number of fill relocations
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4d227d43f0dfca1fa1822207d68539635aac37b3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Oct 2 12:03:21 2011 +0100
+
+    sna/accel: Correct syntax for constifying BoxPtr
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3dd80524160d6b6cf0fb668afcc766f2bc6f8383
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Oct 2 09:59:03 2011 +0100
+
+    sna/accel: Only throttle after flushing
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 04b8f0a5a16ff71c5e55e0281dbcaa32554703ec
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Oct 2 09:36:38 2011 +0100
+
+    sna/accel: Add a compile option to force flushing on every blockhandler
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 32cef71efe231692f7b24f66913a8ae57bc00aa8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Oct 2 08:55:55 2011 +0100
+
+    sna/accel: Add an compile option to disable use of spans
+    
+    Using spans has a tremendous effect (~100x) on x11perf, some good but
+    mostly bad. However, in reality operations are mixed and so preventing
+    migration on alternate opertaions is a win. In the x11perf slowdowns, it
+    appears to be CPU bound and so it seems like there should be plenty of
+    scope for recovering the lost performance.
+    
+    However, for the time being, just go back to the old fallbacks.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit dc1ec0dd1a5f66114ee4249309d3a283ad84d584
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Oct 1 20:11:47 2011 +0100
+
+    sna/accel: Only disable the flush migitration if nothing changed
+    
+    Previously we ignored updating the scanout in place, and so we were not
+    amoritizing the shadow cost of common core rendering operations.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c6acf1325833b8679ef09ab74f0cb0fd82a8cd92
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Oct 1 11:26:54 2011 +0100
+
+    sna/accel: Micro-optimise sna_fill_spans_blt
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8029765515399b130bee18db0a2830eb83f47a07
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Oct 1 11:19:49 2011 +0100
+
+    sna/accel: Don't attempt converting to spans if we will only fallback
+    
+    As the span code does not yet handle plane masks or stippling, it is
+    disadvantageous to convert to spans only to fallback.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit cd11bd69f4c1b961593886945946c7d7c9269900
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Oct 1 10:45:18 2011 +0100
+
+    sna/accel: Use miPolyArc to convert arcs into spans for gpu bo
+    
+    This is actually tricker than it looks since miPolyArc() sometimes uses
+    an intermediate bitmap which performs worse than the fbPolyArc() fallback.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d07256cc3360cf94d131d9a1b24d9f1c6a70ee04
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Oct 1 10:42:45 2011 +0100
+
+    sna/accel: Convert segments into spans similarly to PolyLine
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d09a229e32468c810f5056bfd0043f2fb68038d3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Oct 1 10:01:21 2011 +0100
+
+    sna/accel: Use the mi*Line routines to convert the line into spans for gpu bo
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e7a662b92e3012735f7a3d72d4f7860ca61a3810
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Oct 1 09:26:52 2011 +0100
+
+    sna: Sort partials by remaining space
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 13b9b5d8d6b6f6db59fe2418270ac93d9b74436c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Oct 1 09:23:41 2011 +0100
+
+    sna/io: Only mark the buffer as LAST if we know we will flush the IO
+    
+    Otherwise we can continue to batch up the data upload into larger
+    buffers.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7ecc6993b8c8205e5896ee87c14d6a76310c9aa7
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Sep 30 16:11:05 2011 +0100
+
+    sna/gen6: Fix offset of Scan-Line-Compare register
+    
+    Reported-by: Frank Mariak <fmariak@macrosystem.de>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d8fe941bc245e24c83c417ccff5c57e83baac3f7
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Sep 28 23:04:03 2011 +0100
+
+    sna: Check for request retires after every batch
+    
+    In the beginning, I did perform a retire after ever batch. Then I
+    decided that it was too much CPU overhead for too little gain. On
+    reflection, i.e. further benchmarking, we do see a performance
+    improvement for recycling active buffers faster.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e74a39b45446e2c43df5419efc4a2e0e73275c45
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Sep 28 14:47:33 2011 +0100
+
+    sna/gen7: Confusion reigns as trying to fix errors found by an outdated checker
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6395894ada6b9c14deb62814ccf55848eaa80527
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Sep 27 23:26:33 2011 +0100
+
+    sna/gen7: Fix up a couple instances of my inability to count
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a53538659d5e18cb5a7a7a7dbd460f35985183fd
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Sep 25 12:40:01 2011 +0100
+
+    sna/accel: Fix s/x/y/ typo in computing relative drawing coordinates
+    
+    Reported-by:Roman Jarosz <kedgedev@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=41165
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 960688d1684dd062c345aa8df1ff4f105015f467
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Sep 25 12:23:10 2011 +0100
+
+    sna/accel: Debug option to force CPU fallbacks
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4fd46b8bb7e7a104a0afa0e5dee92993e043ef57
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Sep 25 10:02:02 2011 +0100
+
+    sna/glyphs: Add glyphs directly onto a client temporary buffer
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5154e281ed66334a8ff6342236c1203a1e4ac5a3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Sep 25 09:56:16 2011 +0100
+
+    sna/glyph: Avoid useless attempt at GPU glyph rendering to a1 destinations
+    
+    The actual bug is a little involved as we don't damage the temporary
+    glyph mask correctly presuming that we only hit GPU paths. However,
+    should we fail to prepare the composite operation that paints the mask
+    on to the destination, things fail horribly.
+    
+    One particular example is that wine like to create its own temporary a1
+    buffer for the glyphs (which we render to via another temporary mask...)
+    which triggers the delayed fallback and then sw compositing with a random
+    buffer.
+    
+    Reported-by: Roman Jarosz <kedgedev@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=41165
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 46fedf0cf1a413381109c1de34619e84ad614b8a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Sep 25 09:38:43 2011 +0100
+
+    sna/kgem: Check all operation bo in a single amalgamation
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ccf6547a8f1b77ddf4e79bdefe2a0878c0e9b256
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Sep 24 23:16:57 2011 +0100
+
+    sna: Paranoid debug flush after every op (as well as before)
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 02337600345951c0ea629db11f0484403a260991
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Sep 24 23:03:52 2011 +0100
+
+    sna/gen5: Debug option to disable state caching
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit af4d3853ae8f834fbf2fc55fb2b397b3f7f17656
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Sep 24 19:26:46 2011 +0100
+
+    sna/glyphs: Convert all sub-8bpp masks to a8
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c79e90da71ae58cb3804f8abaf0541350e47eb14
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Sep 24 19:26:31 2011 +0100
+
+    sna: Add a debug option to disable caching
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6bbb88af096e054877409a54d0e0a4ccf5ee317e
+Author: Kenneth Graunke <kenneth@whitecape.org>
+Date:   Sat Sep 24 09:27:33 2011 +0100
+
+    Fix incorrect maximum PS thread count on IvyBridge
+    
+    I mistakenly set GEN7_PS_MAX_THREAD_SHIFT to 23; it's actually 24 on
+    Ivybridge.  Not only did this halve our thread count, it caused us to
+    write 1 into a bit 23, which is marked as MBZ (must be zero).
+    Furthermore, it made us write an even number into this field, which is
+    apparently not allowed.  Apparently we were just lucky it worked.
+    
+    Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7f7f95abbf57e6e71f6a30d917f97c2f2bd6cea9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Sep 23 11:38:18 2011 +0100
+
+    sna/accel: Use the PolyFillRect to handle tiled spans
+    
+    Would be preferrable to duplicate the tiling logic. Leave the task of
+    reimplementing XAA to another day!
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 964c96b181e6b55f4de6a4011a5beb6cc2cac33d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Sep 23 11:37:48 2011 +0100
+
+    sna/accel: Always subtract the enlarged region from the outstanding GPU damage
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c68856f34653ac3e7af900dfbba41a108ffe119e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Sep 23 11:35:50 2011 +0100
+
+    sna/accel: Only skip undamaging the GPU for reads
+    
+    Introduced with ac1b83240e5 (sna/accel: Simplify single pixel read-back)
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5913c90967091124e7c7b262782f0e99cf400eab
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Sep 22 17:13:20 2011 +0100
+
+    sna/accel: fix assert to include the offset of copy
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 31857068026138fe5edd8656381fc1ae59d3058b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Sep 22 17:12:53 2011 +0100
+
+    sna: move an assert
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 61764af13aa3c770d19d51c8ad198cab8a5866f1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Sep 22 12:59:32 2011 +0100
+
+    sna/dri: Bump DRI2INFOREC_VERSION
+    
+    An intervening dri2 patch landed in the sever.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 12070b8eb1e98cb158802fff3e59f906b1547877
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Sep 22 12:18:26 2011 +0100
+
+    sna/dri: Play with marking bo reusable
+    
+    Since we have no recycling of wc pages in the kernel, we try hard to
+    recycle buffers in userspace to avoid GTT thrashing. This requires
+    co-operation between DRI clients and X, which is sadly lacking and so we
+    need to discard any buffer given out to a client after it is finished.
+    We cheat slightly for page-flips and access to the scanout.
+    
+    A further compromise.
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=38732
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 902a0234191d77816259affe331339caaa9131d6
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Sep 19 20:34:15 2011 +0100
+
+    sna: Use pot buckets for active cache
+    
+    On x11perf one of the major hotspots is the search through the active
+    list for an object large enough to reuse as the target surface. We can
+    eliminate that overhead by keeping those active objects in pre-sorted
+    lists by size.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7bb2c5c4d55560f7901fd8036cab164460f81edc
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Sep 19 19:12:46 2011 +0100
+
+    sna: Move an assertion to the point of import
+    
+    All the guesswork is so that when we require an inactive bo, we do
+    actually get a buffer that is not currently on a GPU active list. For
+    some unresolved reason, this assertion was firing when putting the
+    buffer onto the inactive list - so just workaround the worrisome issue
+    by delaying the check until use.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 686a5ec52c9ae475fac22c36fff18814372def71
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Sep 19 18:14:05 2011 +0100
+
+    sna/trapezoids: Fix overflow during sorting of mono edge step
+    
+    We were tracking the 32bit value of the prev_x using only a 16bit
+    variable, and so failing to sort the edges after advancing to the next
+    scanline.
+    
+    Fixes cairo a1-clip-fill-rule.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0390105bc239bf2ac22189f39fccc9d98bae4992
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Sep 19 12:48:38 2011 +0100
+
+    sna: compile fixes for debugging
+    
+    Update the DBG messages to reflect changes in function parameters.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7f0cba3a255eb9e76d56201b26d15f2d49134b58
+Author: Paulo Zanoni <paulo.r.zanoni@intel.com>
+Date:   Fri Sep 16 18:56:00 2011 -0300
+
+    Remove useless assertion
+    
+    Removes 17 instances of:
+    warning: comparison of unsigned expression >= 0 is always true
+    
+    Signed-off-by: Paulo Zanoni <paulo.r.zanoni@intel.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2d9effca142b1d82cd1a7ad3b7d2a61c4567801b
+Author: Paulo Zanoni <paulo.r.zanoni@intel.com>
+Date:   Fri Sep 16 18:53:01 2011 -0300
+
+    Fix "always false" conditionals
+    
+    Enums are unsigned by default in gcc and we can't rely on any specific
+    signedess for the other compilers.
+    
+    i965_render.c: In function ‘i965_prepare_composite’:
+    i965_render.c:2018:2: warning: comparison of unsigned expression < 0 is always false
+    i965_render.c:2025:2: warning: comparison of unsigned expression < 0 is always false
+    i965_render.c:2050:3: warning: comparison of unsigned expression < 0 is always false
+    i965_render.c:2057:3: warning: comparison of unsigned expression < 0 is always false
+    
+    Signed-off-by: Paulo Zanoni <paulo.r.zanoni@intel.com>
+    [ickle: take advantage and rename the enum values]
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7bcd1d2b75d280cecfc23877bb13426a28c07a1f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Sep 17 21:38:46 2011 +0100
+
+    sna: perform a warnings reduction pass
+    
+    Didn't spot anything that might have led to a genuine bug, but this
+    should help improve the signal-to-noise ratio of warnings in the future.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a5b5b4ebb14cab19258dd1cbc12721aaa9df226d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Sep 17 00:28:30 2011 +0100
+
+    sna: Apply the screen offset for direct upload of a composited pixmap
+    
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=38733
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit daeb9291e22d94cd2f81b3b56418f0f879531da5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Sep 17 00:27:55 2011 +0100
+
+    sna/trapezoids: Ensure we do not overrun the vertical edges for mono
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 481df2618af3c10877db0610c4cadf6fc509e72f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Sep 17 00:27:32 2011 +0100
+
+    sna: Add debug option to force allocaiton of gpu-only pixmaps
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 52f93c95465151d16f588d648a58b1f979e946a3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Sep 16 23:24:16 2011 +0100
+
+    sna/glyphs: Disable the glyph cache for debugging
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c8a144d6f84a00a26785fd518cb890ad77edd45f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Sep 16 22:56:36 2011 +0100
+
+    sna/glyphs: Correct offset of fallback-via-mask glyphs
+    
+    Under a compositing manager where we have fun values for both
+    drawable->x/y and pixmap->screen.x/y, we were not drawing either the
+    glyphs into the mask correctly and then failed to composite the mask in
+    the right position on top of the pixmap.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1eea2c4e60af535ac6500b1b62367f9f63f2a784
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Sep 16 20:35:03 2011 +0100
+
+    sna: Can't free bo from the active list
+    
+    As the active bo is still referenced in the request list, we can not
+    simply free it but need to wait for it to be purged on expiration.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d743c456db11bd3c0d21948dc3a2eb4b33e46342
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Sep 16 20:34:33 2011 +0100
+
+    sna: Debug option to disable tiling
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8c35df4493c910ef62c66a411c14e5be3b26bcf0
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Sep 16 20:33:57 2011 +0100
+
+    sna: Remove bad assert
+    
+    The caller intentionally violates this assert, so it is useless.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 72ca1fdf2fea80ff4cf003bb025424d15d8bac58
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Sep 15 17:52:45 2011 +0100
+
+    configure: Introduce --with-builderstring
+    
+    Julien Cristau disliked my broadcasting of the git tree used to build
+    his distribution package as it bore little relevance to his users. As it
+    is only useful for people installing their own drivers (as a means of
+    sanity checking that they are running the right driver), we introduce
+    the --with-builderstring idiom borrowed from the xserver. This allows
+    the builder to override the use of `git describe` and either leave it
+    blank or to fill it with something useful for their own purposes.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 544a4167c156eac7b630f90ddef30a6f00829835
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Sep 14 18:39:37 2011 +0100
+
+    sna/trapezoids: Amalgamate adjacent mono spans
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3565c48c4bb77c836d817de75d098791dbb529d3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Sep 14 17:45:41 2011 +0100
+
+    sna: Yet another s/x/y/ typo
+    
+    Every time I do a transformation into pixmap space I like to include one
+    of these copy'n'paste errors.
+    
+    Reported-by: Paul Neumann <paul104x@yahoo.de>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=40850
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4d4aca21fd32a367d78dfaf1c23b4faeabe36428
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Sep 14 13:06:26 2011 +0100
+
+    sna: assert that the memcpy upload path points to valid regions
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 83961051789e418f6022096b1ed2302cb2f05e5b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Sep 13 18:37:01 2011 +0100
+
+    sna/gen3: Reset the shader after playing video
+    
+    Another piece of state we zap without marking as dirty when playing
+    video.
+    
+    Reported-by: Paul Neumann <paul104x@yahoo.de>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=40842
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 34c03f22158d8fc1ec2fc56cb5e87f74e42d9a8f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Sep 13 17:24:14 2011 +0100
+
+    sna: Clear the list of buffers upon server regen
+    
+    Or else we may try to clear the new framebuffer with an invalid batch,
+    because it will reuse the same bo as last time and that bo may still
+    think it is part of the old batch.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 831cdb837189e92aee80030dec553f28e53ba0bc
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Sep 13 17:09:38 2011 +0100
+
+    sna/debug: Assert that BLT commands on gen2/3 are properly fenced
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a9242a77f0952d029be57d75615dd107af660de1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Sep 13 16:20:40 2011 +0100
+
+    sna: Add a couple of debug statements for why we may not flush the scanout
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0056bfd11e9930c1bcad6c186cd80fbab3694a8d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Sep 13 14:44:48 2011 +0100
+
+    video: Stop advertising unsupported Xv attributes
+    
+    We have yet to implement a yuv-shader that applies
+    contrast/brightness/saturation and so should not advertise such
+    features, potentially allowing the client to fallback and perform the
+    adjustments itself.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 84a7c11a8134dfd040d2f90bb1e0670aa2c89962
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Sep 13 14:42:33 2011 +0100
+
+    sna/video: Stop advertising unsupported Xv attributes
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a0d533ea8d098dbbd86af166de9c07ce67050c35
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Sep 13 12:23:10 2011 +0100
+
+    sna/trapezoids: Implement a mono-rasteriser to skip opacity spans
+    
+    For mono-rasteriser we can simply emit the composite spans without
+    requiring an opacity shader.
+    
+    For single trapezoids, it will be more interesting to emit triangles
+    directly. However, we still need to compute the union of many
+    trapezoids, and this builds upon existing code.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 343b99d2a85c520c81d1408534b2531fcbedfaae
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Sep 13 11:39:39 2011 +0100
+
+    sna: Reuse the smallest bo that fits the request
+    
+    When scanning the active list, pick the smallest that we can reuse.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 90071454d24e7230d00c49f5a897296298fc1f22
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Sep 13 11:37:17 2011 +0100
+
+    sna: Don't clear the kernel-needs-flush flag if we emit a MI_FLUSH
+    
+    We need to mirror the kernel active lists in order to predict when it
+    will stall upon an access to a bo, and so we cannot clear the
+    needs_flush for our own MI_FLUSH.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2deafe2d95d07b574f5a92471f7d7f13aebc790f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Sep 13 11:34:43 2011 +0100
+
+    sna/accel: Use correct enum for requesting a write-buffer
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 544b1a678d5bf49559d8422750866685c36cb152
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Sep 13 11:34:25 2011 +0100
+
+    sna/gen5: Fix debug compilation
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6b1ed58d63e9ac80d7d028fa3036633436154816
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Sep 12 19:07:25 2011 +0100
+
+    sna/gen5: Avoid bitfields for simple assignments
+
+commit 03a7fc16f9ef00ca5591655337621ec67bc37cba
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Sep 12 12:20:24 2011 +0100
+
+    sna: Avoid the call overhead for the trivial clip case
+    
+    Profile guided micro-optimisation. /o\
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2540c877d4811b318e1c2cd707745e5b06c9fa4b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Sep 12 11:54:46 2011 +0100
+
+    sna/gen6: Prefer RENDER for copies as it compacts better
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f2a617dcc5fbeaf503db4777f0ec7b3d862085b9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Sep 12 11:54:02 2011 +0100
+
+    sna: Use single precision for computing the texcoord scale factor
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c2e19987c333de31b258a3af37a2ed1f63ef949a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Sep 12 10:37:24 2011 +0100
+
+    sna: Provide a direct lookup cache of alpha values
+    
+    To reflect recent changes in cairo.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 04c5a3df02f6f40a904ff4edb927ae6ff0ce6408
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Sep 12 09:20:58 2011 +0100
+
+    sna: Fix compilation without timerfd()
+    
+    Based on the patch by Konstantin Belousov.
+    
+    Reported-by: Konstantin Belousov <konstantin.belousov@zoral.com.ua>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ae887c9d1cb2a06c515e054b36464bcf65440f9f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Sep 11 13:59:08 2011 +0100
+
+    sna/trapezoids: Prevent a memleak if feed lots of degenerate boxes
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 72fafdfd374eb165e703b791c70592c47e5772fc
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Sep 9 23:15:58 2011 +0100
+
+    gitignore: add git_version.h
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ac4d4cdbc1336c86a16a2ec3da2ef6e9842c1079
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Sep 9 23:12:59 2011 +0100
+
+    sna: Mark the bo as reusable after extracting the handle from the buffer
+    
+    The whole purpose for that little dance was so that we could reuse the
+    bo. However, we left it marked as non-reusable in order for us not to
+    tie up memory with too many buffers and so defeated the purpose of
+    trying to place it into the inactive cache.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b3429cf12d6e3e8dd89372f8f70c64205d835b0c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Sep 9 18:09:55 2011 +0100
+
+    sna/gen3: Use a clear pattern for ill-defined radial gradients
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b6837c21b459a99cb51b0d41906d82604e515dc0
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Sep 9 14:57:09 2011 +0100
+
+    sna/gen5: Prefer BLT for solids
+    
+    And Ironlake also fails to live up to the promise that its GPU is fast
+    enough to run simple programs at memory rates.
+    
+    x11perf -trap300 5x fold improvement. No obvious improvement elsewhere
+    yet.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 27e42b4e1216099f4a6aa7fddeb1e83b87124b6e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Sep 9 14:06:53 2011 +0100
+
+    sna: Prefer memcpy_blt over fbBlt
+    
+    We know we have compatible formats since we have a gpu_bo attached to
+    the pixmap, so we can use the simpler direct memcpy rather than calling
+    fbPutZImage/fbBlt.
+    
+    On my i3-330m, this improves putimage500 from 730 to 1100 ops/s.
+    
+    Reported-by: Michael Larabel <Michael@phoronix.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2e1bf7e1b44db16d0c322f17535fc6a6fa07353b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Sep 9 12:36:32 2011 +0100
+
+    sna: Record git-tree used for compilation
+    
+    Hopefully, I have all the dependencies correct for auto-updating and
+    should continue to work with tarballs...
+    
+    The next step is to perhaps include it in the usual version number,
+    perhaps as patch level?
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f73cd955e760064f57f414dce5f39e43022e4ea6
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Sep 9 11:37:32 2011 +0100
+
+    sna/trapezoids: Hook up Imprecise AddTraps in lieu of spans
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit adde6eab5d0e532633c864830f8edfa63b36ef4e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Sep 8 23:35:33 2011 +0100
+
+    sna/trapezoids: Fast upload path for gpu busy bo
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e9ca05331db9849fba39fbd0583db7052fc80a31
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Sep 8 22:54:22 2011 +0100
+
+    sna/traps: Use the trapezoid path for AddTraps
+    
+    Usually this will be to CPU-only pixmap, but just on the off-chance that
+    we are stalling for a GPU pixmap just the faster path developed for
+    Trapezoids.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit afdb8aa89a88c62ccd5e26a3ed9adb70fec310a8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Sep 7 20:10:02 2011 +0100
+
+    sna/gen3: Do not assume video updates are always vsync'ed
+    
+    In case the video is running async, then there may be subsequent
+    instructions within the batch and so we do need to mark the clobbered
+    state as dirty when setting up the video frame.
+    
+    Reported-by: Paul Neumann <paul104x@yahoo.de>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=40693
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6aee152cb8444bf63c0009a75c6537e9886b6070
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Sep 4 12:57:17 2011 +0100
+
+    sna/gen2: Flush the batch when we run out of vertex space
+    
+    Unlike the later gen, we do not yet use a separate vertex buffer and so
+    when can no longer fit a rectangle (and its CA ghost) we must flush the
+    batch. Due to the duplication required for the CA pass, the normal
+    checks to see whether we had sufficient space to add the new command
+    were passing as they failed to take into account the need to submit the
+    whole primitive again.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 48bfe4e6ded746f32080b83079235a7576f50d7a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Sep 4 12:46:32 2011 +0100
+
+    sna/gen2: Improve batch decoder.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2cda0aaf397de1a0ca049508c6fa76f2dd4e61e8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Sep 3 14:46:57 2011 +0100
+
+    sna/trapezoids: Check for alignment after projection
+    
+    If after projection onto the Imprecise fast sample grid, the trapezoid
+    becomes a pixel-aligned box, treat it as such and send it down the fast
+    paths.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit db0fb368c135d4fef4ae993df67ed4610a80fd52
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Sep 2 13:13:38 2011 +0100
+
+    sna: Add missing implementation for Triangles
+    
+    Feed both into spans and as a mask fallback.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 695e7115efab96c4467dc926be07dc2609011720
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Sep 1 15:50:29 2011 +0100
+
+    sna/trapezoids: Edges may lie out of bounds
+    
+    We cannot assume that the edge lies completely within the target, so we
+    must make sure that the initial prev_x is truly less than any possible
+    value whilst sorting intersections.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9a563ea03b6ad87d41bc091c5819e6c462100450
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Aug 31 23:29:00 2011 +0100
+
+    sna: Use the shadow buffer for PutImage
+    
+    This is optimising for the x11perf putimage benchmark, but nevertheless,
+    uploading the PutImage directly into the uncached scanout is between
+    2-20x slower than making a temporary copy in the shaodw buffer and
+    doing a deferred update. Most of the overhead is in the kernel, and
+    should be addressed there (rather than worked around) and a portion is
+    due to the overdraw in the benchmark (which is not likely to be
+    realistic, but then again neither should PutImage be!).
+    
+    The argument for uploading inplace when possible is that given that the
+    buffer already exists on the GPU implies that is likely to be used again
+    in future by the GPU and so we will be uploading it at some point.
+    Deferring that upload incurs an extra copy. The putimage benchmark does
+    not actually use the pixel data and so that extra cost is not being
+    measured.
+    
+    Reported-by: Michael Larabel <Michael@phoronix.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 32fc0c896e0dfd06617c12beda1ccacedf69fb4a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Aug 31 23:21:54 2011 +0100
+
+    sna/gen6: Prefer the BLT ring, except for copies on behalf of DRI
+    
+    As demonstrated by the all-important trap300, using the BLT is 2x faster
+    than the RENDER ring for the simple case of solid fills. (Though note
+    that performing the relocations costs 3x as much CPU for 2x GPU
+    performance.) One case that may regress from this change is copywinpix
+    which should benefit from the batching in the RENDER commands, and might
+    warrant revisiting in the future (with realistic and synthetic
+    benchmarks in hand!)
+    
+    However, due to the forced stall when switching rings, we still want to
+    perform RENDER copies on behalf of DRI clients and before page-flips.
+    
+    Checking against cairo-perf-trace indicated no major impact -- I had
+    worried that setting the BLT flag for some clears might have had a
+    knock-on effect causing too many operations that could be pipelined on
+    the RENDER ring to be sent to the BLT ring instead.
+    
+    Reported-by: Michael Larabel <Michael@phoronix.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5586dd729b153e37f942a285d328a07f3fe7ae16
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Aug 31 09:25:48 2011 +0100
+
+    sna/trapezoids: Refactor to project the trapezoid only once
+    
+    And doing so means that we can go back to using the common validity
+    check.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3507437cdba62c28772822cce8c4b656448546db
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Aug 30 22:13:24 2011 +0100
+
+    sna/trapezoids: Reject invalid traps after projecting onto the sample grid
+    
+    If either of the edges are degenerate on the sample grid, then the trap
+    has zero height and must be skipped. (Otherwise if just one edge becomes
+    degenerate than the polygon becomes unbalanced and the rasteriser will
+    implode.)
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 150a0612d545b7fd77bf393efdef1cc92ed91e61
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Aug 30 19:45:22 2011 +0100
+
+    sna/trapezoids: Allocate sufficient space for a8 mask for mono traps
+    
+    Oops, a silly cut'n'paste from caused us to allocate an A1 pixmap for
+    mono traps instead of the A8 pixmap that we tried to write to; mayhem
+    ensued.
+    
+    Reported-by: Eugeni Dodonov <eugeni.dodonov@intel.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit aafe03d3d1cfd5cbdf345cd51436de268ac27b6f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Aug 29 16:47:48 2011 +0100
+
+    sna: Retain the GTT space used for an upload buffer
+    
+    In order to retain the GTT space without keeping hold of the memory used
+    for the upload buffer, we have to create a new bo and copy the relevant
+    details across.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 28c8c5ca14c5b4eab7e2dc58c87050c1019037bb
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Aug 29 16:27:35 2011 +0100
+
+    sna: Free the buffers immediately upon release
+    
+    They do not appear to have been leaked per-se, but we end up
+    accumulating the unused buffers. A more complicated solution would be to
+    reallocate the handle for retained buffers so that the GTT region can be
+    reused.
+    
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=39184
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4f2fc00944272243af343a8b99f6eb8e0dfda006
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Aug 29 15:14:41 2011 +0100
+
+    sna: Cleanup up the cache upon close
+    
+    To help with leak-chasing under valgrind.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0ac4b974b90a5614d1114d5e211cb4b986a89454
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Aug 29 10:46:46 2011 +0100
+
+    sna/video: Defend against PutImage to a broken screen
+    
+    Similar to the previous commit, check that the Screen Pixmap is bound to
+    a bo before proceeding.
+    
+    [Note that in this case, the absence of the bo would have been picked
+    up much later after doing all of the setup...]
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0a74cd77a3f462d5d2707bf1f35663279bcb9be5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Aug 29 10:41:26 2011 +0100
+
+    video: check that the pixmap exists before use
+    
+    Now, the pixmap being used is meant to the Screen pixmap and by rights
+    that has to exists in a GPU buffer! Evidence contrary to the above
+    exists and so we had better check that we have a bo before using...
+    
+    Reported-by: Toralf Förster <toralf.foerster@gmx.de>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=40439
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8216c92d5c49d4b8de5c16b615bca0acece49a70
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Aug 28 22:32:09 2011 +0100
+
+    sna/trapezoids: Use the tor scan converter to compute the low precision mask
+    
+    Take of the advantage of the faster mask computation available using the
+    imprecise tor scan converter for chipsets non yet supporting spans.
+    In doing so, limit the ability to full step only for vertical only rows
+    as the small sample grid reduces the benefits of the computationally
+    more expensive full-step.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit aeee6db798e9ded746b399bc08716cff0bd16ef8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Aug 27 11:43:48 2011 +0100
+
+    sna/trapezoids: Reduce imprecise sampling to 4x4
+    
+    Note this also revealed a subtle bug in the handling of degenerate
+    trapezoids after shrinking to the raster grid.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ac1b83240e5d4dc5d5bacad3ed49446143cc5589
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Aug 27 11:42:19 2011 +0100
+
+    sna/accel: Simplify single pixel read-back
+    
+    The single pixel case is usually assocated with synchronisation of perf
+    clients and so we do not want to incur extra complication along that
+    path. Also the cost of tracking a single pixel of non-damage outweighs
+    its benefit.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 786a770f528a0daee2971494352672cb89f48384
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Aug 25 19:52:13 2011 +0100
+
+    sna/video: Flush the video state at the end of the operation
+    
+    Or in the case where a second command is received prior to the batch
+    being flushed, the vertex data is not flushed and leads to the a
+    miscompution of the number of vertices emitted.
+    
+    Reported-by: Elias Probst <mail@eliasprobst.eu>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=40332
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit bd98001a49be061f0f2cb008b515f5505c8a63a4
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Aug 25 14:49:30 2011 +0100
+
+    sna: Clear structures across server reset
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0865acb3ad03239ffdf8cbf3c9fc204b6c97121b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Aug 25 12:47:27 2011 +0100
+
+    sna/dri2: Add some debug around the use of the Resource database
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 98b67457caea583de50bff1b11a3c5a2bd694e26
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Aug 25 12:45:43 2011 +0100
+
+    sna/display: Destroy shadow data
+    
+    Under certain circumstances the shadow can be destroy after being
+    allocated but before being created. The pixmap is a NULL pointer at that
+    time, but we know that its value should be data, so just use the data
+    pointer instead.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b9ae4e7e71527f1cf2b6dd6890420da22a22fad9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Aug 24 21:38:28 2011 +0100
+
+    sna/gen3: reset blend state after applying CA pass
+    
+    Otherwise we use the stale value when rendering CA glyphs directly to
+    the front-buffer and subsequent rendering have a tendency to become
+    invisible. (Rendering via a temporary glyph mask has a fortunate
+    side-effect of reseting sufficient state to force the re-emission of the
+    blend state.)
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ef52f6c8c3421a31552d5965c40b4d9cf68f6a5c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Aug 24 11:04:28 2011 +0100
+
+    sna/render: allow CLAMP_TO_EDGE for outside samples of extract regions as well
+    
+    When clipping the sample region to the edge of the texture we can also
+    allow the GPU to use CLAMP_TO_EDGE (as well as CLAMP_TO_BORDER) to
+    emulate the RepeatPad mode of the parent texture. (Only the
+    RepeatNormal, RepeatReflect need special treatment with regard to tiling
+    that is not yet handled.)
+    
+    This fixes the recent performance regression due to a slight change in
+    the fish benchmark that caused it to sample outside of the texture atlas
+    for one of its little fish.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d330f3751e484d28293fc593a20375a31b068bc7
+Author: Stefan Dirsch <sndirsch@suse.de>
+Date:   Fri Jul 22 12:21:01 2011 +0200
+
+    Fix array size calculation for intel_pci_probe().
+
+commit ccddff087df0c567c28416941b175be81190a1d3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Aug 8 00:42:21 2011 +0100
+
+    sna/trapezoids: Speedup tor rasteriser
+    
+    Faster sorts for the win.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit bfbe36cfea76337689dd8a101ec03469f6d3553d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Aug 11 01:08:49 2011 +0100
+
+    sna/gradient: Use a high-precision ramp for a color step rather than fallback
+    
+    Slightly less precise, but the difference should not be observable in
+    practice...
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0e61e235bf7a926fd4e5b1f5a05b72dce4c450f3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jul 13 22:55:31 2011 +0100
+
+    sna/damage: Take advantage of marking all-damaged
+    
+    Return early from adding new damage regions if we know that we have
+    already marked it as all-damaged.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3a81bb6bafdbd37802dab96b8f05173ec6701d7f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Aug 9 09:42:40 2011 +0100
+
+    NEWS: 2.16.0 release
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f4bbbd1dfe59031f864c7d2bbf7bb0252a3aa6a7
+Author: Edward Sheldrake <ejsheldrake@gmail.com>
+Date:   Mon Aug 1 14:46:08 2011 +0100
+
+    Fix man page formatting
+    
+    Two option sections were not starting at the beginning of a new line.
+
+commit 63518c42234001ec96f638af5732c09079a3d682
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Aug 1 13:36:28 2011 +0100
+
+    dri: Build fix for xserver-1.7.7
+    
+    Back in the olden days before the introduction of dixRegisterPrivate().
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7976f5144d42a03ccd027908252a600db2631054
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 30 09:21:36 2011 +0100
+
+    NEWS: 2.15.901 snapshot
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2cfb703bbe7ec043d443452f4fa94f06b1ff7266
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 30 09:23:22 2011 +0100
+
+    Fix typos for distcheck
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6f919264da69ed8bce6f2573629d89962a670783
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 30 09:00:06 2011 +0100
+
+    sna: Mark the stencil as untiled
+    
+    In reality, Mesa will be treating it as W-tiling, only we have no way of
+    communicating that requirement to the kernel (as not only does the
+    kernel not understand W-tiling, but also the GTT is incapable of fencing
+    a W-tiled region.).
+    
+    Ported from Chad Versace's 3e55f3e88.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 326a84e832c43cc200a32e091b4e60b8b6a4a7c8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jul 22 11:10:26 2011 +0100
+
+    sna: Port IVB acceleration code (Xrender + Xv)
+    
+    Based on the superlative work by Kenneth Graunke and Xiang, Haihao.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 10790921570fea21d6b2bcc07a0204ef315c9182
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 30 08:46:19 2011 +0100
+
+    sna: Include the pixmap size in the debug info for moving to cpu
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5691c8cdec2a5264b8552f096b4a34b97afe4ae5
+Author: Kenneth Graunke <kenneth@whitecape.org>
+Date:   Thu Jul 14 10:14:53 2011 -0700
+
+    render: Enable RENDER acceleration on Ivybridge.
+    
+    Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
+    Acked-by: Eric Anholt <eric@anholt.net>
+    Acked-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0d92612b2a2782f80196a08eb9a17af906169f18
+Author: Kenneth Graunke <kenneth@whitecape.org>
+Date:   Thu Jul 14 00:30:09 2011 -0700
+
+    render: Update pixel shader state for Ivybridge.
+    
+    Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
+    Acked-by: Eric Anholt <eric@anholt.net>
+    Acked-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7460ee73d1fd22e6b02ce125f11ac38efff743ce
+Author: Kenneth Graunke <kenneth@whitecape.org>
+Date:   Thu Jul 14 00:16:54 2011 -0700
+
+    render: Use Ivybridge variants for 3D pipeline setup.
+    
+    Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
+    Acked-by: Eric Anholt <eric@anholt.net>
+    Acked-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e3a09608716c1dee2554e8fc26d6f77aeec684bd
+Author: Kenneth Graunke <kenneth@whitecape.org>
+Date:   Thu Jul 14 00:04:31 2011 -0700
+
+    render: Refactor to use newly shared pipeline setup code in i965_3d.c.
+    
+    Slightly generalize the shared SF and CC code to accomodate both.
+    
+    Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
+    Acked-by: Eric Anholt <eric@anholt.net>
+    Acked-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 682a690bfeeabae710b1392282163eab35b58eed
+Author: Kenneth Graunke <kenneth@whitecape.org>
+Date:   Wed Jul 13 22:52:52 2011 -0700
+
+    Xv: Refactor out pipeline setup functions for future reuse in render.
+    
+    While we're at it, make the functions simply take an intel_screen_private
+    pointer directly instead of having to fetch it from ScrnInfoPtr.
+    
+    Also coalesce some gen6/gen7 functions that were 98% identical.
+    
+    Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
+    Acked-by: Eric Anholt <eric@anholt.net>
+    Acked-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 54b3222658a285d26b7800bdc5f8343c918a804e
+Author: Kenneth Graunke <kenneth@whitecape.org>
+Date:   Wed Jul 13 22:27:37 2011 -0700
+
+    render: Update 3DPRIMITIVE for Ivybridge.
+    
+    Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
+    Acked-by: Eric Anholt <eric@anholt.net>
+    Acked-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4e491a1f6d7a15009904cb79e2c0b13cf2d9d6ec
+Author: Kenneth Graunke <kenneth@whitecape.org>
+Date:   Wed Jul 13 22:19:21 2011 -0700
+
+    render: Set Address Modify Enable in 3DSTATE_VERTEX_BUFFERS on Gen7.
+    
+    Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
+    Acked-by: Eric Anholt <eric@anholt.net>
+    Acked-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2787cd66f0d2907110f774392370537df63a96fa
+Author: Kenneth Graunke <kenneth@whitecape.org>
+Date:   Wed Jul 13 22:10:17 2011 -0700
+
+    render: Update SAMPLER_STATE for Ivybridge.
+    
+    Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
+    Acked-by: Eric Anholt <eric@anholt.net>
+    Acked-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1a7e541d0d33727953fa69f1e29fa4eda665a0d9
+Author: Kenneth Graunke <kenneth@whitecape.org>
+Date:   Wed Jul 13 21:53:27 2011 -0700
+
+    render: Update SURFACE_STATE for Ivybridge.
+    
+    Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
+    Acked-by: Eric Anholt <eric@anholt.net>
+    Acked-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 07cc488bcf3f7653cd54928e3cedb1f4f102c5e0
+Author: Kenneth Graunke <kenneth@whitecape.org>
+Date:   Sat Jul 9 01:36:52 2011 -0700
+
+    render: New Ivybridge assembly programs for render acceleration.
+    
+    These are exactly the same as the ones for Sandybridge, but with message
+    registers translated (hopefully) in the same way as Haihao's new
+    programs (m1 == g65).
+    
+    Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
+    Acked-by: Eric Anholt <eric@anholt.net>
+    Acked-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1b9e82b4b59dd50c1b057f58d71d5c04dcc648a7
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jul 26 08:29:36 2011 +0100
+
+    sna: Revert enabling scan-line wait on SNB
+    
+    Hanging the machine does indeed prevent video tearing. Just not quite
+    what the user expected...
+    
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=39497
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6dbbb74bde034f5f00aee0396ccd1e03a6625fbd
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 16 14:05:54 2011 +0100
+
+    sna: Enable gen6 scan-line waiting
+    
+    The code was ready and waiting, just forgot to turn it on.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3e55f3e88b40471706d5cd45c4df4010f8675c75
+Author: Chad Versace <chad@chad-versace.us>
+Date:   Mon Jul 18 00:38:00 2011 -0700
+
+    dri: Do not tile stencil buffer
+    
+    Until now, the stencil buffer was allocated as a Y tiled buffer, because
+    in several locations the PRM states that it is. However, it is actually
+    W tiled. From the PRM, 2011 Sandy Bridge, Volume 1, Part 2, Section
+    4.5.2.1 W-Major Format:
+        W-Major Tile Format is used for separate stencil.
+    
+    The GTT is incapable of W fencing, so we allocate the stencil buffer with
+    I915_TILING_NONE and decode the tile's layout in software.
+    
+    This commit mutually depends on the mesa commit:
+        intel: Fix stencil buffer to be W tiled
+        Author: Chad Versace <chad@chad-versace.us>
+        Date:   Mon Jul 18 00:37:45 2011 -0700
+    
+    Signed-off-by: Chad Versace <chad@chad-versace.us>
+    Reviewed-by: Ian Romanick <ian.romanick@intel.com>
+    Acked-by: Kenneth Graunke <kenneth@whitecape.org>
+
+commit 212fa9868767637e8f430485eeb522c99e63fd16
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jul 13 21:11:14 2011 +0100
+
+    Disable adding normal RTF modes for an eDP
+    
+    This is causing a hard hang with 2.6.39+, we don't know why so play safe
+    and disable for the time being.
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=38012
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7a695c9f6b919eba8785d62094526762ba2a0449
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jul 13 10:57:13 2011 +0100
+
+    sna: Fast-path single span boxes
+    
+    These are very common when compositing unclipped trapezoids, and the
+    majority of the overhead is in handling the arbitrary number of boxes
+    and misses out on the constant folding the compiler can do if it is
+    known we have just one box.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0190964906ad878d469d6021c10cde4e7f5799c3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jul 13 10:26:44 2011 +0100
+
+    sna/damage: Avoid testing against a completey damaged region
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b929717c89352d4b47dc2b9ce58e26fbbf327201
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jul 13 09:49:09 2011 +0100
+
+    sna/gen3: Tune emit_spans_primitive_constant
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fbdbfaf38d4da5204750d91cf5a3f43307a6ac33
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jul 13 17:38:41 2011 +0100
+
+    sna/glyphs: Discard GLYPH_PICTURE hint if the glyph doesn't fit into the cache
+    
+    If the glyph is too big to fit into the cache, than ideally we do want
+    to keep an associated GPU bo around for future use. As it is too large
+    to fit into the cache, it of reasonable size and there is little wastage
+    in allocating indiviual GPU bo for each oversized glyph.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 12f52530db1727e2f835e55dc922e5efaf4d3a16
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jul 13 17:38:22 2011 +0100
+
+    sna: Add some extra debugging to the texture upload fallback paths
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a861094c23b5f0df7b889bcc03904e32c4c2c6be
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jul 12 20:17:00 2011 +0100
+
+    sna/dri: Fix a couple of typos
+    
+    Somehow these were lost in the rebasing.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c221d0356db57c10f5d29ca17fdf592724b35385
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jul 12 15:39:42 2011 +0100
+
+    sna/dri: Remove the unused id/type members for Resource tracking
+    
+    ...and reduce it to a simple list.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 644b1a903301531e1fb59f27952c15e87888c4c6
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jul 12 11:50:24 2011 +0100
+
+    dri: Always initialise resource members of DRI2FrameEvent
+    
+    As we now attempt to always decouple the lists upon freeing the frame
+    event, we need to initialise them along all code paths.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 32f42358140ee812984149ae52b0df3dfd1778c3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jul 11 20:29:53 2011 +0100
+
+    sna/dri: Add some simple debugging
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a46598220ebf5d4e629e1e0a7baf47ce144ed2c8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jul 11 14:40:30 2011 +0100
+
+    sna/dri: Refactor common code for assigning a pixmap to the DRI2 buffer
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7538be3315b8683b05e8f6b22023baadcc0bc4da
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jul 11 10:50:36 2011 +0100
+
+    dri: Enable triple-bufferred pageflips
+    
+    By popular demand.
+    
+    Triple-buffering trade-offs output latency versus jitter. By having a
+    pre-rendered frame ready to swap in following a pageflip, we avoid the
+    scenario where the latency between receiving the flip complete signal
+    from the kernel, waking up the vsynced application, it render the new
+    frame and then for the server to process the swap request is greater
+    than the frame interval, causing us to miss the vblank. The result is
+    that application can become frame-locked to 30fps. Instead, we report to
+    the application that the first frame swap is immediately completed,
+    supply a new back buffer (or else the rendering would be blocked on
+    waiting for the front-buffer to be swapped away from the scanout) and
+    let them proceed to render the second frame. The second frame is added
+    to the swap queue, and the client throttled to vrefresh. (If the client
+    missed the vblank, the swap queue is empty and the client is immediately
+    woken again, whilst the pageflip is pending.)
+    
+    Note, for practical reasons this only applies to page-flipping, for
+    example, calls to glXSwapBuffer() on fullscreen applications.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2608a367acba7247e50754c3daeed09ba2e97d05
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jul 11 16:28:15 2011 +0100
+
+    dri: Prevent abuse of the Resource database
+    
+    The Resource database is only designed to store a single value for a
+    particular type associated with an XID. Due to the asynchronous nature
+    of the vblank/flip requests, we would often associate multiple frame
+    events with a particular drawable/client. Upon freeing the resource, we
+    would not necessarily decouple the right value, leaving a stale pointer
+    behind. Later when the client disappeared, we would write through that
+    stale pointer upsetting valgrind and causing memory corruption. MDK.
+    
+    Instead, we need to implement an extra layer for tracking multiple
+    frames within a single Resource.
+    
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=37700
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ab1000821ae881a301fb0e1f2210493ec383e681
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 9 19:44:26 2011 +0100
+
+    dri: Remove the shadow copy of attachment
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9f22ea7ca440c788f8104647356393c96c62d155
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 9 14:54:33 2011 +0100
+
+    sna: Clamp results for computing BoxRec coords from xRectangle
+    
+    As the width/height in the rectangle is specified as uint16_t, the
+    result may be larger than is storagable in the int16_t of the box. Of
+    course it would take a really inane client to do attempt to draw
+    something much larger than the largest possible surface... Is it strange
+    that first example I've found to do so is a Java application?
+    
+    Reported-by: Nicolas Kalkhof <nkalkhof@web.de>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f4c5dc88171435aa04a5d99372913120cdafe92b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 9 14:17:24 2011 +0100
+
+    sna/accel: Fix fallback for depth=1 copy
+    
+    A little carelessness with passing down the offsets caused us to
+    incorrectly copy depth=1 bitmaps, as exemplified by gkrellm.
+    
+    Reported-by: Nicolas Kalkhof <nkalkhof@web.de>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 649ebcef0938c7cde4f3172a639d39488454999a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jul 8 17:44:58 2011 +0100
+
+    sna: A buffer only needs a flush if it remains dirty at the end of the batch
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 625e37b317e4d237bdc9f80d7ab86b5d2badddc7
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jul 8 18:58:32 2011 +0100
+
+    sna/gen3: So we also need to ensure stippling is cleared...
+    
+    My theory that we used nothing that invoked polygon stippling proved
+    baseless.
+    
+    Fixes regression from 3b5971bd2359383cb8326702d80e03bc15d34c69
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1e2cae0ab339e477929e429f8ff31b11fcaf2cbf
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jul 8 09:54:43 2011 +0100
+
+    sna/gen3: Restore disabling the use of stencil/fog in the invariant
+    
+    One cleanup too far causing spurious results after rebooting. We also
+    need to ensure that the writemask is fully enabled (ie not disabled)
+    as well.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ec3dd64e739c4c2bbd8141de5275fe8a90f24a57
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jul 8 00:17:27 2011 +0100
+
+    sna/dri: Enable chaining of page-flips
+    
+    Trade off extra frames of latency for extra frames of anti-jitter
+    buffering and loss of completion information; compiz users rejoice.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a32694b0f07e35c22dd83bcfb828196d5d86628e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jul 7 23:11:39 2011 +0100
+
+    sna/dri: Remove redundant NULL check in reference
+    
+    The buffer has already been dereferenced by this point...
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d180c5f5f781f4fa7f747dd7bb8073a20771cd79
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jul 6 20:19:00 2011 +0100
+
+    sna: Take advantage of the needs_flush tracking on the front buffer
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0be47f459ba576ed3f93367de18732fb2367357a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jul 6 13:02:53 2011 +0100
+
+    sna: Check against an execbuffer reference before discarding partials
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f6573fe7577e00a1d2706dbc39179ab658c021d2
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jul 6 12:44:08 2011 +0100
+
+    sna: Compute aligned tiled heights for gen2 correctly
+    
+    We were underestimating the height of X-tiled surfaces (and less
+    harmfully overestimating the height of Y-tiled surfaces.)
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d6afd66461ebcdc2e8dcd94b3f46f374d8acf469
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jul 5 23:12:59 2011 +0100
+
+    sna: Reset unused partial buffers
+    
+    Whilst searching for available space on the active partial buffer list,
+    if we discover an unreferenced one, reset its used counter to zero.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6e7a0c86419bf6c928837f592784333c25d8b27b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jul 5 23:05:37 2011 +0100
+
+    sna: Discard unused partial buffers
+    
+    If we allocate a partial buffer and then fallback for the operation, the
+    buffer would remain on the partial list waiting for another user.
+    Discard any unused partials at the next batch submission or expiration
+    point.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3b5971bd2359383cb8326702d80e03bc15d34c69
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jul 5 22:20:28 2011 +0100
+
+    sna/gen2: Restore invariant ENABLES
+    
+    One deletion too many, unnoticed until the next reboot. Besides the
+    failure to disable logic op and enable colour buffer blending which
+    causes a hang if you subsequently try to enable both, you also need
+    to request texture caching...
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5fa3e73f2c03bcadb87c1760f76f853c22fdba18
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jul 5 21:38:08 2011 +0100
+
+    sna/gen[23]: Do as the comments suggest and prefer the BLT
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f749ed618e21b56a36a2feb9b4333ec797ec2ae5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jul 5 21:37:02 2011 +0100
+
+    sna: Reduce tiling if pitch is less than a tile_width/height only on pre-G33
+    
+    (Note this only applies to 2D pixmaps.)
+    
+    The rationale, borne out by experimentation with cairo-perf-trace, is
+    that on the pre-G33 devices we always need a fence region region
+    for tiled surfaces, i.e. at least .5/1MiB in size, and that combined
+    with the smaller GTT on those devices, we loose the benefit of tiling to
+    the excessive GTT thrashing.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b9de6a98d33db660ffad3f186c2b0ab2aea71ac0
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jul 5 17:48:11 2011 +0100
+
+    sna: Remove unused aperture_size member
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fd3bc2af471a3f9a73064cb28818fdd3485cffc7
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jul 4 16:31:20 2011 +0100
+
+    sna: Clamp object size to the min of 1/4 of the whole GTT or 1/2 the mappable
+    
+    ... for those pesky early devices whose GTT was no larger than the AGP
+    aperture.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d294e41a6a49ddaa6f8d7d5cda266168095fe1f5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jul 4 13:45:06 2011 +0100
+
+    sna: Update flush/retirement lists after a implicit flush for mmap
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3e53b0f3a365c031bfef8d087bcee0ae1c2d2988
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jul 4 13:44:28 2011 +0100
+
+    sna: Enable relaxed-fencing for gen2 devices
+    
+    (Just as dependent upon non-buggy kernels as gen3...)
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 33ddaf54299979e98b196d479f1b2060d9551cc5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jul 4 13:43:48 2011 +0100
+
+    sna: Fix gen2 tiled surface sizes
+    
+    Actually use the gen2 path for gen2 devices!
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9eceddf69f78fc79c02ca75ed10b000beeff2033
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jul 4 13:42:58 2011 +0100
+
+    sna/gen2: fix batch buffer acounting
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3f80f7edb8c511b94e66159cd59ba9362c3f69a2
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 2 23:16:04 2011 +0100
+
+    sna: Manually set to the GTT domain for mmap
+    
+    ...since the kernel no longer does strict coherency.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f91ee24b2dabb48288d6e81dcdd82191f158e312
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 2 23:05:04 2011 +0100
+
+    sna: Trim number of downsample passes
+    
+    If we can fit the entire width or the entire height into the pipeline
+    when downsampling, do so.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6db93720a73f59a9857a3c5ab260fab8b957813e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 2 23:04:14 2011 +0100
+
+    sna: Don't change tiling modes on replace
+    
+    This was trying to workaround a kernel bug, and instead causes a
+    performance cliff for textures that *need* to be tiled.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 430c905ef306ece8a4cb19091711a9feae74b00b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 2 18:24:40 2011 +0100
+
+    sna: Force tiled modes for large pitches
+    
+    If the surface is so big that the 2x2 texel sampling will cause a TLB
+    miss everytime, i.e. the row pitch exceeeds 4096, then we need to
+    encourage tiling to prevent attrocious performance.
+    
+    For example, try downscaling a 2560x1600 background image on a gen3
+    device using I915_TILING_NONE...
+    
+    Using slideshow-demo /usr/share/backgrounds/cosmos/whirlpool.jpg, on a
+    PineView netbook, fps goes from under 4 to over 40.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ae567b783e5af53f17f49dbf58b9be17fcb53737
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 2 00:11:21 2011 +0100
+
+    sna: Finer-grained debugging for trapezoids
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 98f2e3855d70c02b05e2721a70ebce0c17e44283
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jul 2 09:53:11 2011 +0100
+
+    sna/video: Downgrade severity of "overlay not found" message
+    
+    We don't need to warn the user that their hardware does not support the
+    video overlay plane (but Jesse is working on it!), but merely inform
+    them that its presence is lacking.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 01c258718e981f4da949a4e48595a0660d55d66e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jul 1 23:17:54 2011 +0100
+
+    sna/gen2: Add missing stub debug files
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5c8a108d2c99f542372efb1734c96ddd2af6bc76
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jul 1 21:24:43 2011 +0100
+
+    sna/gen2: Recompute blend pipeline for component-alpha pass
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 121511d3bd63da5eca28edf971aae3d062aed46e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jul 1 16:54:28 2011 +0100
+
+    sna/gen2: Pack solid sources into the default diffuse component
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a303f85c163979276ff13e00b7c56f55b5fd1d07
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jul 1 16:27:11 2011 +0100
+
+    sna/gen2: Remove unused state from invariant setup
+    
+    ... and also some state that gets clobbered when we install the
+    composite pipelines.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 120c98ac10435c8e848a8337c1f544f81a05cd3a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jul 1 14:55:44 2011 +0100
+
+    sna: Downsample sources 2x too large to fit in the 3D pipeline
+    
+    This is quite trivial to hit given the 2k limits on gen2/gen3. We
+    compromise on image quality by pre-downscaling the source by a fixed
+    factor to make it fit into the pipeline in preference to performing the
+    entire operation on the CPU.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f6c8c3bb6fd75bca6c7704b7d5869a5d44ce3832
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jul 1 11:17:32 2011 +0100
+
+    sna/gen2: Use specular component for solid spans
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit de14e3c8595f9e315dc3ce23ad15b04e118499f4
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jul 1 09:58:27 2011 +0100
+
+    sna/gen2: Add missing render fallbacks for blt ops
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ecbf6bbd27b1205dcf76cfe34ae2a7a3f5ec195a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jul 1 08:50:58 2011 +0100
+
+    sna/gen2: Implement composite-spans
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c89b37d7b43c9e588097b7fadcba3bc13a03f8bc
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 30 17:53:49 2011 +0100
+
+    sna: Mappable aperture is region 0 on gen2
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c0434ab49035bf278dad6f5f84a541ea58536fb4
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 30 16:31:28 2011 +0100
+
+    sna: Distinguish 830/845 vs 855/865 using the generation id
+    
+    Remove the PCI ID device checks by using the simpler check on the
+    generation id for errata pertaining to 830/845.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 18d08e49d270b7a05f14a309759c9315e5ab9679
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jun 28 20:25:46 2011 +0100
+
+    uxa/glyphs: Fallback instead of crashing on large strings
+    
+    Not ideal, but being slow is a major improvement over losing data.
+    
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=36860
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 95866bd6bdaeb612732fd43ec1b93e088763086e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 27 21:07:22 2011 +0100
+
+    sna/video: Use EXTEND_PAD to avoid mixing in the border color
+    
+    ...which is 0 and appears green around an unaligned YUV-video.
+    
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=38723
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 7446b39f04306ae2ffccdfe8dd6c8bda64a27043
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 27 15:26:49 2011 +0100
+
+    sna: Disable XVideo using the TexturedAdapter if the GPU is wedged
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 44cd6ebf43aa5b7f23c03629a11cdf83b6e96e3a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jun 26 18:41:20 2011 +0100
+
+    sna: Typo in debug assertion.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5cd7f5b59857f221bd3aa9965b43b938ff7824ed
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jun 26 18:36:05 2011 +0100
+
+    sna/dri: Mark the GPU bo as damaged upon a page-flip
+    
+    ...so that CPU pixmap is correctly invalidated for the next readback.
+    For instance, if you were to take a screenshot on a composited destkop.
+    
+    Reported-by: Sitosfe Wheeler <sitsofe@yahoo.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c4f7959266571f14c43c0f0cea69134bb8556875
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jun 26 14:09:11 2011 +0100
+
+    sna: Only create bo up to half the size of the mappable aperture
+    
+    As we use GTT mappings if writing directly into the tiled buffer and the
+    available aperture is reported by the kernel as the total GTT and not
+    limited to the fenceable/mappable region, we need to manually probe this
+    value and ensure that our creation and fenced routines observe this
+    distinct limit.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 130350111720a0e4ae825bb9d21a8c481cd2b548
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jun 25 23:21:20 2011 +0100
+
+    sna/dri: Reorganise schedule_swap to not confuse immediate and wait paths
+    
+    Eeek, the wait-for-target-msc was using the immediate swap path, meaning
+    that for copy-swaps the copy was submitting immediately but the client
+    throttled waiting upon the target vblank. What is actually intended is
+    for the presentation to be delayed until the target_msc.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b460b9645451af84136c5daebbc00c7545de67f4
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jun 25 16:34:15 2011 +0100
+
+    sna/dri: Fix composited copy-swaps
+    
+    The secret is not to cheat and render directly to the front buffer, but
+    remember to mark the Window as damaged.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 28fffbd1d07890c8b4d697369159f6a30f267675
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jun 25 16:33:31 2011 +0100
+
+    sna/display: Protect against drmModeGetCrtc returning NULL
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2c73b4651a04390668c3ed2aa10699663e44fd8a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jun 25 16:32:30 2011 +0100
+
+    sna/gen4+: Use the drawable rectangle offset for copy boxes
+    
+    Saves a little bit of work whilst emitting the rectangles.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3833ff967766b0b99f1d636c6453de1783a90586
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jun 25 14:02:50 2011 +0100
+
+    sna: Correct typo in computing damage of PolyPoint
+    
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=38614
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 471115a9806162bf0cafe27947f49d94fdd63d87
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 24 13:32:45 2011 +0100
+
+    sna: Also allow BLT copies to discard the alpha channel
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c3b1a0d7046a83b6daec03e5a562116e3adf3c71
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 24 12:19:09 2011 +0100
+
+    sna/dri: Copy to real front upon swap
+    
+    The front-buffer of a DRI2 drawable, may not in fact be pointing to the
+    scanout pixmap. So override the destination for swapbuffers to update
+    the scanout.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 669378cd8db8af89d12f1b95a07fc1ead0b1569c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 24 11:53:17 2011 +0100
+
+    sna: Wrap the fbcon in a scratch pixmap for render-copy across depth changes
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 33b2ea0392fe944b210ef744398aa22989bfdf33
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 24 11:43:07 2011 +0100
+
+    sna: Avoid using the BLT to copy between mismatching depths
+    
+    We either conflated bpp (which fails given a mixture of depth-24 and
+    depth-30 pixmaps) or neglected to check at all.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 28f6dc24d3c50aa399dd098a9ba6a18a95837800
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 24 11:24:59 2011 +0100
+
+    sna: Support depth-30 and some more logging to show the depth
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 312460ea69792594fe9acca8591ead55baea7d99
+Author: Xiang, Haihao <haihao.xiang@intel.com>
+Date:   Thu Jun 23 00:20:03 2011 +0800
+
+    Xv: set up pipeline for Xv on Ivybridge
+    
+    The configuration is same as that on Sandybridge, but
+    many state commands are changed
+    
+    Signed-off-by: Xiang, Haihao <haihao.xiang@intel.com>
+
+commit 90a0800588f83d78254136b94bca656c4c24215d
+Author: Xiang, Haihao <haihao.xiang@intel.com>
+Date:   Tue Jun 21 14:14:38 2011 +0800
+
+    Xv: upload new shaders to GEM objects for Xv on Ivybridge
+    
+    Signed-off-by: Xiang, Haihao <haihao.xiang@intel.com>
+
+commit 00614f712b243a7724cf919f94d204a123d2789a
+Author: Xiang, Haihao <haihao.xiang@intel.com>
+Date:   Thu Jun 23 00:09:21 2011 +0800
+
+    Xv: update SURFACE_STATE & SAMPLER_STATE for Xv on Ivybridge
+    
+    SURFACE_STATE & SAMPLER_STATE are changed since Ivybridge
+    
+    Signed-off-by: Xiang, Haihao <haihao.xiang@intel.com>
+
+commit 70f884772a3adc5dbf56572499c5fb2e080aa84a
+Author: Xiang, Haihao <haihao.xiang@intel.com>
+Date:   Thu Jun 23 00:02:38 2011 +0800
+
+    Xv: New shaders for Xv on Ivybridge
+    
+    Redefine some M4 macros, also update the check for
+    intel-gen4asm to support Ivybridge
+    
+    Signed-off-by: Xiang, Haihao <haihao.xiang@intel.com>
+
+commit 3cf423bd3a9483181e59ee87376a9487fa1f923d
+Author: Xiang, Haihao <haihao.xiang@intel.com>
+Date:   Wed Jun 22 23:33:08 2011 +0800
+
+    Xv: separate fragments from M4 macros
+    
+    It is to prepare for Xv on Ivybridge. The difference from Sandybridge
+    is that all message payload must be in GRF registers instead of MRF registers
+    on Ivybridge. We will only redefine some M4 macros for Ivybridge
+    
+    Signed-off-by: Xiang, Haihao <haihao.xiang@intel.com>
+
+commit 58d7a89b93ba4022f45465e479d2799b8903137a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 24 00:35:30 2011 +0100
+
+    sna: Don't render to invalid surfaces
+    
+    Fixes a regression from d0362a. In bypassing the is_wedged checked, we
+    also ended up bypassing the checks that we could indeed render to the
+    target bo. With the result that we were creating GPU buffers for SHM
+    surfaces, something that requires Xserver fixes before we can actually
+    enable...
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3c1d5bc35e02dfd8234c029dcab5661e1656ca8e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 24 00:34:11 2011 +0100
+
+    sna: Clip the fbcon to the frontbuffer
+    
+    ...both to correct the placement of the fbcon into the smaller scanout and
+    to ensure that we correctly clip the boxes to be copied.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e3b4c10f239f69e5282bde1d3b0c3685b24cf0aa
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 23 20:54:28 2011 +0100
+
+    sna: Relent and workaround the lack of O_NONBLOCK on /dev/dri/card0
+    
+    So in order not to block server shutdown, check that the fd is readable
+    before attempting to read from it.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 33d3077266942b23c5bc05ef4a9a6cebe357272a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 23 15:53:45 2011 +0100
+
+    sna: Debug compile fix, and some extra comments
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 03e6aee8fd2cc7486fbd2ec55a537c712786486b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 23 15:51:59 2011 +0100
+
+    sna: For an unbounded op, we need to convert the whole surface
+    
+    Otherwise if we fail to check, then we create a 0x0 surface to sample
+    with the operation -- net result is that we end up using a clear source
+    instead of the desired mask.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 356ded1308e8fe5f8dbec217b219228a991356d5
+Author: Adam Jackson <ajax@redhat.com>
+Date:   Wed Jun 22 17:17:15 2011 -0400
+
+    Don't include xf86Priv.h
+    
+    I'd like it to not be in the SDK anymore, and we're not using anything
+    from it.
+    
+    Signed-off-by: Adam Jackson <ajax@redhat.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8fb98e22a63a4354b049ace7870abb6406541c28
+Author: Jian Zhao <jian.j.zhao@intel.com>
+Date:   Wed Jun 22 08:54:59 2011 +0800
+
+    configure: Define required_xorg_xserver_version later so it can make successfully.
+
+commit ea71133da78632d4cfee5b0b4c96e8dddd6cdf44
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jun 21 12:28:13 2011 +0100
+
+    sna/video: Use pwrite for upload of unclipped, unrotated frames
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2f6afb5b1f02cc448da1b342627108ceddda4f0d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 20 17:29:17 2011 +0100
+
+    sna: Only reduce gpu damage after migration
+    
+    Otherwise we end up doing work for no reason, ala the regression in
+    grads-heat-map. However, it is important that the damage is reduced at
+    some point or else it may grow unbounded. Hopefully normal usage will
+    never hit the pathologocial case...
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 88d840b53d64e67cfee14cc4cef8da46d716c401
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 20 15:22:57 2011 +0100
+
+    sna/gen4: Check for sufficient batch space before emitting pipelined pointers
+    
+    For the broken shader workaround, we need to reset the pipeline state
+    before every blt as the state is changed by the magic CA pass. So we
+    need to check that we actually have sufficient space to emit the
+    pipelined pointers before doing so.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 84bd6e51199bf8b49e6f6e0c29a1d71c89f6996f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 20 15:22:00 2011 +0100
+
+    sna/gen4: Correct the number of dwods required to emit the ca pass
+    
+    We need 7 for pipelined pointers, 6 for the primitive and 1 for the
+    flush.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 22255335e428cb1f349fe4198d36e0ab3fe06948
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 20 13:51:12 2011 +0100
+
+    sna: Don't perform a GPU copy of the scanout if it is wedged.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e2684498a4905b4ac157a1c752c1c4f75301e7ad
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 20 13:50:43 2011 +0100
+
+    sna: Add some debugging asserts for handling wedged GPUs
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d0362a20bb3ead2fab9401b63209f917bdd72d55
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jun 19 19:33:01 2011 +0100
+
+    sna: Bypass the gpu-is-wedged? check for forced bo creation
+    
+    In order to attach a scanout (and use swrast) on a wedged GPU, we need to
+    bypass the safety checks for normal pixmap creation.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 585667c2f9f88554ed89ff21ae38600f761d964c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jun 18 15:52:22 2011 +0100
+
+    sna: Bump the required xserver version to 1.10
+    
+    SNA requires some pending bug fixes to the xserver so it makes little
+    sense to conditionalise the code and deliberately cause broken
+    behaviour.
+    
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=3843
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit de0286ed9f7814f903d56e488c7a4b3eb0ca56b0
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 17 09:40:53 2011 +0100
+
+    sna/display: After copying the fbcon, tell the server that we have a background
+    
+    ... so that the core knows to skip the clear.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f3869d60cc3bc349d1efba642baa011378f1c09b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 17 09:37:15 2011 +0100
+
+    sna/display: Apply damage for the fbcon copy
+    
+    ... so that any immediate shadow usage will read back the fbcon
+    contents.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 39f0b0ae17d00402971bb62555d3807bdf39ee93
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 16 23:49:06 2011 +0100
+
+    sna: Copy the fbcon contents onto the front buffer upon X startup
+    
+    This patch has been carried by the distributions every since they
+    started doing graphical boot splashes. Time to integrate it and give it
+    some TLC.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 37ba33f502af0878f6cb75f890c9fe288d0f7e41
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 17 07:03:25 2011 +0100
+
+    sna: Fix kgem_create_from_name error paths and to mark the bo as non-reusable
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 665bc1735748f266fad5255f82c40edc59ef98e5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 17 07:00:54 2011 +0100
+
+    sna/display: Remove the caching of the drmModeCrtc
+    
+    We only use it for the id. Everything else stored on it, like the
+    buffer_id, is not permanent and we need to query the current status as
+    required.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ad6235cfb11a5dfdd27106ac45106aaacba73bde
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 16 19:02:36 2011 +0100
+
+    sna/accel: convert BOX_ADD_RECT to an inline function
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a86f43988c4ded10cc3b1b964668300c9aa3af59
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 16 19:00:09 2011 +0100
+
+    sna/accel: convert BOX_ADD_PT to an inline function
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit f67a26590aadac8b9b9870ae3b03d23eb7eda1a2
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 16 18:58:38 2011 +0100
+
+    sna/accel: convert TRIM_AND_TRANSLATE_BOX to an inline function
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit df1b117dedfdda425fbc3e4ee394169902df4716
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 16 18:57:38 2011 +0100
+
+    sna/accel: convert TRANSLATE_BOX to an inline function
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 76ff3c715cf6059316d08217e7e7783ca0388393
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 16 18:56:24 2011 +0100
+
+    sna/accel: convert TRIM_BOX to an inline
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e4a66368e71df288323fce66b27237f1d9f93c3a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 16 18:55:03 2011 +0100
+
+    sna/accel: convert CLIP_BOX to an inline function
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d7b51cc5d6e624a72b2f2fb92b4488e49a1c749c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 16 18:52:56 2011 +0100
+
+    sna/accel: convert BOX_EMPTY macro to an inline function
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1c3c08e80f08adb12a03277a60c4a56115281743
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 16 18:37:43 2011 +0100
+
+    sna: Fix the typo in BOX_EMPTY
+    
+    BOX_EMPTY(&box) surprisingly compiles and generates interesting code that
+    evaluates to if (0). Oops.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 17bf0019b6962c06c87a08e4b41799481eaccd26
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 16 14:26:06 2011 +0100
+
+    sna: Only retire requests after IO if the bo was active
+    
+    We only want to process retirements if we know we caused a stall waiting
+    for the GPU to release the bo before performing IO.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b707f18d17564653a2b45adf46a4e8eafcc6ab2c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 16 14:16:06 2011 +0100
+
+    sna: Purge the bo cache only if we detect aperture thrashing
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 855ced5a4eb67e287001ae22cb6489639c548cfa
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 16 13:24:14 2011 +0100
+
+    uxa: Remove the attempt to use the 3D pipeline for core rendering
+    
+    The attempt was still ridden with bugs, such as
+    
+    http://bugs.freedesktop.org/show_bug.cgi?id=28768
+    http://bugs.freedesktop.org/show_bug.cgi?id=28798
+    http://bugs.freedesktop.org/show_bug.cgi?id=28908
+    http://bugs.freedesktop.org/show_bug.cgi?id=29401
+    
+    A fresh approach was taken with SNA, but in the mean time before that
+    can be enabled downstream, restore correct behaviour.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit dd4ad11e0d432f3a8eff4574a241c16f8463278d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 16 12:53:22 2011 +0100
+
+    sna: compile fix.
+    
+    A pox on all those who write trivial patches, attempt to compile on a
+    system not having dri2proto and just assume that all is good.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2ff36af7e1841a82fd43a9317d07b3229a309df5
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 16 11:23:16 2011 +0100
+
+    sna/accel: Prevent initialising a region with an invalid box
+    
+    pixman complains if you attempt to use a region created with an invalid
+    box, so don't do that.
+    
+    Reported-by: Reinhard Karcher <reinhard.karcher@gmx.net>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3c02110052ecf69d43577ed8537a8850227da560
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 16 10:30:58 2011 +0100
+
+    sna/dri: Add some comments to explain the choice of flags upon the bo
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 881f961a1c78e554e566ef624d6edcf28fee8fdf
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jun 15 19:11:05 2011 +0100
+
+    sna: Clear the gpu flag once is not busy and no flush is pending
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a1ee4b930846d4ba9274028c08800b882fc926f1
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jun 14 23:46:15 2011 +0100
+
+    sna/dri: And fix the blit swap paths
+    
+    Following on the recent successes with the pageflip paths.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2f675cf402a6d158448a9300779829a10ca991fd
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jun 14 08:13:58 2011 +0100
+
+    sna: Split zaphod across the crtcs
+    
+    Since we have no global resource allocator for zaphod mode, that's what
+    RandR-1.4 solves, we have to further constrain zaphod mode to only use
+    one crtc per screen. This also means that you must match the output
+    restrictions within the Screen definitions, noting that the crtc pipe id
+    corresponds with the screen number.
+    
+    Reportede-by: Phillp Haddad <phillip.haddad@gmail.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 49f265915a4bca52724c345f04cddfeaca972655
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jun 14 07:59:50 2011 +0100
+
+    sna: Compile fix for debugging enabled
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 12b8a62652e219de255fdd8b3c801c23274130e9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 13 20:51:56 2011 +0100
+
+    test: Exclude the long running stress tests from make distcheck
+    
+    tinderbox complains when it is left running for days on end...
+    
+    Reported-by: Jeremy Huddleston <jeremyhu@apple.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4173ca344bb7d3fb7c03ebdce0e31aa82dba1192
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 13 22:31:55 2011 +0100
+
+    sna: Invalidate the mode if the front pixmap was swapped whilst blanked
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2158534421f26bcd1eca9ad74ab7a30f27e47a75
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 13 15:27:23 2011 +0100
+
+    sna/dri: Accurately track front and pending front for async flips
+    
+    By not tracking the front buffer correctly, i.e. performing the exchange
+    on every swap, GL_FRONT was no longer pointing at the updated buffer and
+    neither was the root pixmap. So both X and GL would read the wrong
+    buffer was the flip was pending.
+    
+    The other issue was that we would feed the old front buffer back to the
+    application as a future back buffer (due to buffer caching) and so the
+    kernel would duly insert a WAIT_EVENT for the pending flip to complete
+    before allowing rendering to affect it.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2facaa910798c0e7adb34345e6d6913849b7d8a3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 13 11:46:04 2011 +0100
+
+    sna/dri: Complete the pending async flip even after DrawableGone
+    
+    If the client exits before the async page-flip completes then we still
+    need to decrement the pending flip count in order to correctly flip the
+    scanout next time.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 86888723901030c5cb9da16cbb03508d4b13332f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jun 12 22:38:01 2011 +0100
+
+    sna: Just do a pointer exchange when flipping with no scanout
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b881d1b16a8beec024ac18eca8308418e34cb05d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jun 12 20:13:26 2011 +0100
+
+    sna: Check that the scanout is still attached before waiting for scanline
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit bb08e73c557c379ef131225ffea5aa729ca781d6
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jun 12 20:07:20 2011 +0100
+
+    sna: Prevent tracking scratch pixmaps on older xservers
+    
+    Before the xserver is patched to send notification of release of the
+    scratch pixmaps, we cannot associated GPU resources with them. In
+    practice, the only advantage for doing so is for SHM pixmaps...
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ff262aca9c46b7616c59d8e8f04d33a5bbc6e324
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jun 11 10:15:14 2011 +0100
+
+    sna/dri: Fix tripple-buffering for vblank_mode=0
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b199bc2b415fd0f06e456e0b1f44dd25ba8dbe02
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jun 11 09:57:46 2011 +0100
+
+    sna/dri: Skip querying current msc for immediate swaps
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 5f4dbcc8bde3690668bde739ac61178037612475
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jun 11 09:06:50 2011 +0100
+
+    sna/dri: Queue page-flips immediately for next vblank
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 00e8b4bec6dc5bb46e6f073af9c1fa34f4a2c2c9
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jun 11 09:00:16 2011 +0100
+
+    sna/dri: For offscreen, swaps just exchange the buffers
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e9397b28eff5be4cd5e8a2ceca80333424f24391
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jun 11 08:54:04 2011 +0100
+
+    sna: Process dri wakeups first
+    
+    The goal is to minimise the latency in receiving the event from the
+    kernel and acting upon it.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit bcad5b21fef4573f3144608364cf5b1ea6d241e3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 10 21:27:38 2011 +0100
+
+    sna: Unbreak configure after last commit
+    
+    I went a step too far... I still need some define in order to switch
+    between uxa/sna at compile time.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d0d65940b4f4d4993eccb8c66ec7e8b633b331da
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 10 19:51:12 2011 +0100
+
+    sna: Remove the ability to disable chipset specific code
+    
+    This was a fun little, but pointless, exercise.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6f035e80b98e478ff4c59427e50e57ecd710da62
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 10 18:41:56 2011 +0100
+
+    sna/dri: Keep reference on swap buffers until the end of the pageflip
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit cf6c7901825bb831443615ef21555c5843184bdb
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 10 17:49:13 2011 +0100
+
+    sna: Use the ScreenPixmap->serialNumber as a generation count
+    
+    DRI2 presumes that the pixmap->serialNumber can be used as unique id.
+    If it changes revokes *all* the buffers, it presumes a new pixmap has
+    been attached to the window, for example after a reconfiguration event
+    (resizing of a window, or a mode switch). However, as we updated the
+    root pixmap upon a pageflip, we were triggering revocations everytime,
+    causing further revocations and massive aperture thrashing.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 3f19270d6795738b58d9ce1721896b3067b38c9f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 10 15:29:57 2011 +0100
+
+    sna/dri: Actually restrict pageflipping to properly aligned fs windows
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9e9c628708ae838e5df3df89331243f84b297e8e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 10 15:17:18 2011 +0100
+
+    sna/dri: Create pixmap suitable for the framebuffer for fullscreen buffers
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b22de0b01453884d5018e7e0faef439421fa63a0
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 10 13:30:54 2011 +0100
+
+    sna/blt: Suppress overwriting boxes through fill_boxes()
+    
+    As the introduction of the unrolled fill_boxes() was bypassing the
+    effective optimisation in fill_one().
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ebeebc2044610e6e31d9cef746c768d2e435f32c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 10 13:07:13 2011 +0100
+
+    sna: Use temporary for storing the current crtc box when computing best crtc
+    
+    ... as the caller may be reusing an input parameter for the result.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b3949d0d7424242703c9e60e2e33908499aa6a43
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 10 12:45:24 2011 +0100
+
+    sna/kgem: remove erroneous assert during submit
+    
+    This was only valid for gen6+ with the multiple rings.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 33abb68da2c49081f28898f93cc4e14702b40d70
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 10 12:44:56 2011 +0100
+
+    sna/kgem: remove redundant clears upon initialisation
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit cfde920a2e449efaa387850173e46f87d928023b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 10 11:27:04 2011 +0100
+
+    sna: Remember to decouple the fb on closing
+    
+    ... so that we actually attach a new one after regen!
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit b6192ce95af8aa8be6d9a68a500393f2a73c2f4c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 10 11:05:41 2011 +0100
+
+    sna/gen4: Tweak calculation of required batch space for CA
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c9b89fc87f1d43a715cd9c5915bfed957175986d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 10 10:53:29 2011 +0100
+
+    sna: Drain the event queues before CloseScreen
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ea560e25dfcce3750339b477a1a3c05f504cf91e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 10 10:44:27 2011 +0100
+
+    sna: Workaround the random free of the ScreenPixmap in fbCloseScreen
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1f364c6d241e8971e8fc1447871c718240e4563e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 10 10:03:01 2011 +0100
+
+    sna: Reset the kgem state on server regen
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 95ae39a93467655b2107b82bd7970f732c8de066
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 10 09:57:22 2011 +0100
+
+    sna: Add some debug statements to the core DDX interface
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0594724dc4e9e459240b8b290ddf42ed711be22b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 10 08:18:07 2011 +0100
+
+    sna/gen4: Restore normal state after CA pass and FLUSH_EVERY_VERTEX
+    
+    By working around the broken shaders, we emitted the CA rectangle in the
+    middle of a sequence of glyphs and left the state setup for CA. So we
+    need to reset the pipeline state at the start of every composite blt.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 2dff681efe1b89ffe59e5d33979c6e059b72a786
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 10 08:23:19 2011 +0100
+
+    sna/blt: Remove a couple of unused members from its op-state
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fbbd1c9dde3b2fafd8aaebb88daf3c546d86e5a4
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 10 08:22:00 2011 +0100
+
+    sna/glyphs: Fix glyphs to dst fallback path
+
+commit 3f46c34d534e389f541b5c7987b78981c556d868
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Jun 10 08:20:12 2011 +0100
+
+    sna/composite: Tweak setup for the minimal composite extents
+    
+    Clip the operation extents before passing to the backend to setup the
+    operation, so that we only need to upload the minimum amount of data
+    necessary, or avoid tiling etc.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a34caf1e3ded03dca53bbea3432dcd45101460fd
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 9 20:45:18 2011 +0100
+
+    sna/gradient: Check solid busy status not current domain
+    
+    We can write into the bo if it has no outstanding requests, whereas we
+    were checking to see it was last on the gpu instead.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1638a0a6c0b335dd31def93a9199f7407ae51170
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 9 16:00:30 2011 +0100
+
+    sna/dri: Add a comment to warn about a potential race between DRI clients
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4b54c89fbddc7aa72e5f2c5eded44e84bce70b77
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 9 15:53:11 2011 +0100
+
+    sna: Place the pixmap on the DRI dirty list after damaging the shadow copy
+    
+    In order that we remember to flush the contents back to the GPU
+    before we wake up the DRI clients, we need to add those dirty
+    pixmaps to the flushing list. I caught the obvious place, the
+    central move-to-cpu, but I missed a couple of paths were we
+    optimise the copy onto the shadow.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 190a6786563aadd69f63bb7b509f3edf712e81ef
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 9 15:13:17 2011 +0100
+
+    sna: Periodically reduce the gpu damage (after migrating any cpu damage)
+    
+    This will prevent the gpu damage list from growing unbounded.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 38d084ee6241527193ba08c6600b6734e1833118
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 9 14:53:34 2011 +0100
+
+    sna: Move !kgem->wedged check down into kgem_can_create_2d
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d1a3bb1467429310f5d17bf6afbf2eeb043ae64d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 9 14:51:49 2011 +0100
+
+    sna: Prefer inactive buffers when creating a bo for a dirty pixmap
+    
+    As we will immediately attempt to replace it with an inactive when
+    moving the data to the GPU, short-circuit that replacement.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8ee53cc7449de7df294f49d089ff1d6b2e944323
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 9 13:05:19 2011 +0100
+
+    sna: Debugging compile fix
+    
+    Still not enough coffee this morning.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6f59d7d19053fed4e9d6402a5f03bc8a62cb56af
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 9 12:59:59 2011 +0100
+
+    sna: Use --enable-debug=full to enable extremely verbose debugging
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 021209d5d3add8b28143611cfad4c5481a2945a3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 9 10:27:12 2011 +0100
+
+    sna: Remove the stubs from sna_render.c
+    
+    These only existed to work around an include order problem, when kgem
+    was intended to be entirely separable from sna. Moving the function
+    pointer into kgem simplifies matters.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 6141b1aea159759e7e9dcf2561deb9d8c02bd0a2
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 9 10:06:08 2011 +0100
+
+    sna: Warn after detecting a hung GPU
+    
+    ...and include the instructional error message from uxa.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 1786d2ee03a190ebe242ac7b58bed7cc31d66b16
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 9 09:48:57 2011 +0100
+
+    sna/accel: Add debug messages for falling back due to a wedged GPU
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4d509d501b09f565fea232947e6f53d54a08749f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 9 01:03:16 2011 +0100
+
+    sna: Tweak retiring old bo
+    
+    As we check for retirement everytime we wakeup, it is seldom useful to
+    check again until we know we have invoked an operation that may block.
+    But when we do check, we do not want to scan the entire active list
+    looking for flushing candidates, so track those on a separate list.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 17be5e2eb41b2ada94954b87c855961003c2fc7c
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Jun 9 00:38:29 2011 +0100
+
+    sna: Reduce the frequency of the timer interrupts
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d0b09f10242e09adfddbbe6ee1ea39dbf5d1b32d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jun 8 20:34:57 2011 +0100
+
+    sna: Make the device fd non-blocking
+    
+    So that we can simply query it from each of the Zaphod instances without
+    blocking. Requires a fixed kernel...
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 67ed14c5369cfd967f90e5a3e6053c95a48dd16e
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jun 8 19:42:02 2011 +0100
+
+    sna/dri: Set bo=NULL to actually detect unknown dri attachment points.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 68755bc5ff830dc5ed6a34b18a1217b7d1003ce4
+Author: Chad Versace <chad@chad-versace.us>
+Date:   Wed Jun 8 18:34:02 2011 +0100
+
+    sna/dri: Add support for DRI2BufferStencil and DRI2BufferHiz
+    
+    Based on Chad's commits 2662db5b and 3daba7e6:
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0030c3aab6172cdb83ca8f1b7b07c7db5915990d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jun 8 18:31:12 2011 +0100
+
+    sna/dri: Drop support for old dri2 versions with incompatible ABI
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 715d466ad44e82b740f5454c41db944863420596
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Wed Jun 8 13:32:59 2011 +0100
+
+    sna/dri: valgrindify
+    
+    Lots of scary warnings found by valgrind.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a62db5b050dee10246c02c72385358acb5e72b56
+Author: Chad Versace <chad@chad-versace.us>
+Date:   Mon May 23 14:23:54 2011 -0700
+
+    dri: Add support for DRI2BufferStencil and DRI2BufferHiz
+    
+    And bump configure.ac to require dri2proto >= 2.6, because
+    DRI2BufferStencil and DRI2BufferHiz were introduced in that version.
+    
+    When a client requests DRI2BufferHiz or DRI2BufferStencil,
+    I830DRI2CreateBuffer() now returns a Y-tiled buffer. The stencil buffer is
+    handled as a special case due its quirky pitch requirements.
+    
+    CC: Eric Anholt <eric@anholt.net>
+    CC: Ian Romanick <idr@freedesktop.org>
+    CC: Kristian Høgsberg <krh@bitplanet.net
+    Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
+    Signed-off-by: Chad Versace <chad@chad-versace.us>
+
+commit 263daba7e6afb37bd471fdc8dd8e4458da0a45ff
+Author: Chad Versace <chad@chad-versace.us>
+Date:   Sun Jun 5 19:48:19 2011 -0700
+
+    dri: Do not create DRI2 buffers for unrecognized DRI2 buffer tokens
+    
+    Before this commit, if a client were to request an unrecognized DRI2
+    buffer, such as DRI2BufferStencil, then I830DRI2CreateBuffer() allocated
+    and returned an X-tiled buffer by accident. The problem was that
+    unrecognized tokens were caught by the default case of a switch statement.
+    
+    Now, when given unrecognized DRI2 tokens, I830DRI2CreateBuffers() returns
+    null.
+    
+    This shouldn't break older Mesa versions, because they never query (via
+    DRI2GetBuffersWithFormat) for the drawable's DRI2BufferStencil.
+    
+    CC: Eric Anholt <eric@anholt.net>
+    CC: Ian Romanick <idr@freedesktop.org>
+    CC: Kenneth Graunke <kenneth@whitecape.org>
+    CC: Kristian Høgsberg <krh@bitplanet.net
+    Signed-off-by: Chad Versace <chad@chad-versace.us>
+
+commit 038f29c259c1463c0bff12f5f8f0b228c02e45b3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jun 7 19:16:01 2011 +0100
+
+    sna/blt: Flush batch before overwrite surface data
+    
+    A left-over from before the surface was embedded into the tail of the
+    batch, we were only checking for room against the total size of the
+    batch buffer. So under the wrong set of circumstances we ended up
+    overwriting surface data with batch and triggering a GPU hang on gen4+.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 265d94e0aa46b30a3198893544dd3619cc9145de
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jun 7 14:23:51 2011 +0100
+
+    sna: Add zaphod support
+    
+    Zaphod support is a rudimentary method for creating an Xserver with
+    multiple screens from a single device. The Device is instantiated, with
+    a duplication of its resources, as many as required up to a maximum of
+    the number of its outputs, and each instance is attached to a Screen
+    and added to the ServerLayout. A Device can be bound to a selection of
+    outputs using a comma separated list of RandR names.
+    
+    Note: in general, this is not the preferred solution! And will be
+    superseded by per-crtc-pixmaps in RandR-1.4.
+    
+    For example, the following xorg.conf fragment creates an XServer with
+    two screens, one attached to the LVDS panel on the laptop, and the other
+    to any external output:
+    
+    Section "Device"
+       Identifier "Intel0"
+       Driver     "intel"
+       BusID      "PCI:0:2:0"
+       Option     "ZaphodHeads" "LVDS1"
+       Screen     0
+    EndSection
+    
+    Section "Device"
+       Identifier "Intel1"
+       Driver     "intel"
+       BusID      "PCI:0:2:0"
+       Option     "ZaphodHeads" "DVI1,VGA1"
+       Screen     1
+    EndSection
+    
+    Section "Screen"
+       Identifier "Screen0"
+       Device     "Intel0"
+    EndSection
+    
+    Section "Screen"
+       Identifier "Screen1"
+       Device     "Intel1"
+    EndSection
+    
+    Section "ServerLayout"
+       Identifier "default"
+       Screen     "Screen0"
+       Screen     "Screen1"
+    EndSection
+    
+    Based on a patch by Ben Skegs <bskeggs@redhat.com>
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit ad5ead8257b7dda84a886461873d87831d43e663
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jun 7 11:06:52 2011 +0100
+
+    sna/gen2: Support covered xrgb sources on 830/845
+    
+    830/845 cannot directly sample from an x8r8g8b8 source, but if we know
+    that we are only sampling from within the confines of the source then we
+    force the alpha channel to one. (Outside of the source we require the
+    sampler to return a==0.)
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 790f90a277ff2a6fbb615b8cd3c06faa0d549c41
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jun 7 08:18:30 2011 +0100
+
+    sna/gen6: Initialise a couple more composite op members for copy_boxes
+    
+    Valgrind detected that I missed initialised a couple of fields for
+    use with the generic state emission paths:
+    
+    ==28683== Conditional jump or move depends on uninitialised value(s)
+    ==28683==    at 0x83BE646: gen6_get_blend (gen6_render.c:251)
+    ==28683==    by 0x83BF769: gen6_emit_state (gen6_render.c:818)
+    ==28683==    by 0x83C38ED: gen6_emit_copy_state (gen6_render.c:2280)
+    ==28683==    by 0x83C3C89: gen6_render_copy_boxes (gen6_render.c:2356)
+    ==28683== Conditional jump or move depends on uninitialised value(s)
+    ==28683==    at 0x83C15C3: gen6_rectangle_begin (gen6_render.c:1458)
+    ==28683==    by 0x83C177D: gen6_get_rectangles (gen6_render.c:1502)
+    ==28683==    by 0x83C3D16: gen6_render_copy_boxes (gen6_render.c:2363)
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4e443cbef589e016d085e8023677f47c1f01a858
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Jun 7 00:24:17 2011 +0100
+
+    sna: Add some more debug commentary to render picture source migration
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 367298c5109b47fa4961a60fa3cb454c800f02c3
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 6 23:21:09 2011 +0100
+
+    sna: Subtract the Solid RenderFillRectangles from CPU damage
+    
+    ... and so avoid having to move it the GPU, as seen in the wild. It
+    looks like I will actually need to handle mixed Render/Core operations
+    on the frontbuffer.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 62e4266b4dc9b5c3d165aca980738fa777a0f259
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 6 16:20:38 2011 +0100
+
+    sna/gen5: Only emit the non-pipelined op after BLT commands
+    
+    We were always terminating the batch with the non-pipelined op, and not
+    just at the end of a BLT sequence.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 8f97157d2e807d6c9acb521ec59757f419e6518b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 6 10:21:17 2011 +0100
+
+    sna/gen2: Replicate alpha for non-CA masks
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c8a2fa3a2e3f22e12f363e8ea060c70585156190
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 6 08:43:34 2011 +0100
+
+    sna/gen2: Correct command length for CA LOAD_IMMEDIATE_STATE_1
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a89fc7181b6ccec8ccca2cd4ccab4f180f663656
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 6 08:39:17 2011 +0100
+
+    sna/gen2: Only emit the mask texcoord if there is a mask
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 4fb7784e1e1b2b999c0c2420583e9c48eb1127ac
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 6 08:27:17 2011 +0100
+
+    sna/gen3: Non-affine texcoords require space for 4 floats not 3.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit d9344ab8d04fe4795a3a532c5c0e85dc11ecf968
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 6 08:25:53 2011 +0100
+
+    sna/gen2: Set op->floats_per_vertex
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 741c1101f17bfa379a15178e4760211737fa18cf
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 6 08:22:45 2011 +0100
+
+    sna/gen2: Enable selection of gen2 only
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit c76ec69660bf40de052159f60c16de8fd87341a8
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Mon Jun 6 08:02:09 2011 +0100
+
+    sna/gen2: The inline primitive takes a length, not a vertex count
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 91424d49373d8117e71441fa3221bd1801171692
+Author: Eric Anholt <eric@anholt.net>
+Date:   Tue May 31 23:29:43 2011 -0700
+
+    uxa: Simplify uxa_poly_fill_rect by only clipping once.
+    
+    Reviewed-by: Keith Packard <keithp@keithp.com>
+
+commit e0066e77e026b0dd0daa0c3765473c7d63aa6753
+Author: Eric Anholt <eric@anholt.net>
+Date:   Tue May 31 23:17:16 2011 -0700
+
+    uxa: Simplify Composite solid acceleration for spans by only clipping once.
+    
+    Unlike the previous commit removing this style of code, the code in
+    this one was originally wrong, and would fail to clip in the second
+    pass of clipping when y was > pbox->y2.
+    
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=37233
+    Reviewed-by: Keith Packard <keithp@keithp.com>
+
+commit ace324e4aa27effdd621156eec03f3f87b610732
+Author: Eric Anholt <eric@anholt.net>
+Date:   Tue May 31 23:13:18 2011 -0700
+
+    uxa: Simplify BLT solid acceleration for spans filling by only clipping once.
+    
+    We were clipping each span against the bounds of the clip, throwing
+    out the span early if it was all clipped, and then walked the clip box
+    clipping against each of the cliprects.  We would expect spans to
+    typically be clipped against one box, and not thrown out, so we were
+    not saving any work there.  For multiple cliprects, we were adding
+    work.  Only for many spans clipped entirely out of a complicated clip
+    region would it have saved work, and it clearly didn't save bugs as
+    evidenced by the many fix attempts here.
+    
+    Reviewed-by: Keith Packard <keithp@keithp.com>
+
+commit bdb396a44bf64f823a44aafee19b5ec692f1bf5f
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jun 5 19:41:25 2011 +0100
+
+    sna: PutImage: Copy straight to GTT if the bo is idle
+    
+    This saves a copy in the typical PutImage to frontbuffer favoured by
+    flash. And we also happen to fix a bug if we should be requested to
+    PutImage outside of the clip region...
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 407257570fea1c6456fda47c9fab36c39f169c2b
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jun 5 15:33:27 2011 +0100
+
+    sna/gen6: Flush the pipeline before effecting a change of blend modes
+    
+    ... also make sure that we flush if we change the blend mode for the CA pass.
+    
+    Reported-by: Ivan Bulatovic <combuster@archlinux.us>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=37946
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 73167711226f430cc9ef4c27f267655d0edf4622
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jun 5 14:56:32 2011 +0100
+
+    sna: 915gm does not have 128-byte Y-tiling
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0260c4ce32fa4d7ae8c6ee79d5488b0114e96251
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Jun 5 14:39:34 2011 +0100
+
+    sna: Fallback if presented with mask under NO_COMPOSITE
+    
+    Just making sure that the debug paths actually work...
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fcbe2d9ee79c936cad3ee86836286dcb280f0047
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat Jun 4 18:11:54 2011 +0100
+
+    sna/gen4: Flush every vertex for the magic CA pass
+    
+    gen4 dies hard if it has two rectangles in the pipeline, and despite the
+    stringent and crippling efforts to prevent us from efficiently using the
+    GPU, I missed a flush before submitting the CA rectangle.
+    
+    Reported-and-tested-by: Fryderyk Dziarmagowski <fdziarmagowski@gmail.com>
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=28768
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit bcef98af561939aa48d9236b2dfa2c5626adf4cb
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Fri Apr 8 07:17:14 2011 +0100
+
+    sna: Introduce a new acceleration model.
+    
+    The premise is that switching between rings (i.e. the BLT and
+    RENDER rings) on SandyBridge imposes a large latency overhead whilst
+    rendering. The cause is that in order to switch rings, we need to split
+    the batch earlier than is desired and to add serialisation between the
+    rings. Both of which incur large overhead.
+    
+    By switching to using a pure 3D blit engine (ok, not so pure as the BLT
+    engine still has uses for the core drawing model which can not be easily
+    represented without a combinatorial explosion of shaders) we can take
+    advantage of additional efficiencies, such as relative relocations, that
+    have been incorporated into recent hardware advances. However, even
+    older hardware performs better from avoiding the implicit context
+    switches and from the batching efficiency of the 3D pipeline...
+    
+    But this is X, and PolyGlyphBlt still exists and remains in use. So for
+    the operations that are not worth accelerating in hardware, we introduce a
+    shadow buffer mechanism through out and reintroduce pixmap migration.
+    Doing this efficiently is the cornerstone of ensuring that we do exploit
+    the increased potential of recent hardware for running old applications and
+    environments (i.e. so that the latest and greatest chip is actually faster
+    than gen2!)
+    
+    For the curious, sna is SandyBridge's New Acceleration. If you are
+    running older chipsets and welcome the performance increase offered by
+    this patch, then you may choose to call it Snazzy instead.
+    
+    Speedups
+    ========
+     gen3           firefox-fishtank  1203584.56 (1203842.75 0.01%) -> 85561.71 (125146.44 14.87%): 14.07x speedup
+     gen5             grads-heat-map  3385.42 (3489.73 1.44%) -> 350.29 (350.75 0.18%):  9.66x speedup
+     gen3          xfce4-terminal-a1  4179.02 (4180.09 0.06%) -> 503.90 (531.88 4.48%):  8.29x speedup
+     gen4             grads-heat-map  2458.66 (2826.34 4.64%) -> 348.82 (349.20 0.29%):  7.05x speedup
+     gen3             grads-heat-map  1443.33 (1445.32 0.09%) -> 298.55 (298.76 0.05%):  4.83x speedup
+     gen3             swfdec-youtube  3836.14 (3894.14 0.95%) -> 889.84 (979.56 5.99%):  4.31x speedup
+     gen6             grads-heat-map  742.11 (744.44 0.15%) -> 172.51 (172.93 0.20%):  4.30x speedup
+     gen3          firefox-talos-svg  71740.44 (72370.13 0.59%) -> 21959.29 (21995.09 0.68%):  3.27x speedup
+     gen5                       gvim  8045.51 (8071.47 0.17%) -> 2589.38 (3246.78 10.74%):  3.11x speedup
+     gen6                    poppler  3800.78 (3817.92 0.24%) -> 1227.36 (1230.12 0.30%):  3.10x speedup
+     gen6         gnome-terminal-vim  9106.84 (9111.56 0.03%) -> 3459.49 (3478.52 0.25%):  2.63x speedup
+     gen5              midori-zoomed  9564.53 (9586.58 0.17%) -> 3677.73 (3837.02 2.02%):  2.60x speedup
+     gen5         gnome-terminal-vim  38167.25 (38215.82 0.08%) -> 14901.09 (14902.28 0.01%):  2.56x speedup
+     gen5                    poppler  13575.66 (13605.04 0.16%) -> 5554.27 (5555.84 0.01%):  2.44x speedup
+     gen5         swfdec-giant-steps  8941.61 (8988.72 0.52%) -> 3851.98 (3871.01 0.93%):  2.32x speedup
+     gen5          xfce4-terminal-a1  18956.60 (18986.90 0.07%) -> 8362.75 (8365.70 0.01%):  2.27x speedup
+     gen5           firefox-fishtank  88750.31 (88858.23 0.14%) -> 39164.57 (39835.54 0.80%):  2.27x speedup
+     gen3              midori-zoomed  2392.13 (2397.82 0.14%) -> 1109.96 (1303.10 30.35%):  2.16x speedup
+     gen6                       gvim  2510.34 (2513.34 0.20%) -> 1200.76 (1204.30 0.22%):  2.09x speedup
+     gen5       firefox-planet-gnome  40478.16 (40565.68 0.09%) -> 19606.22 (19648.79 0.16%):  2.06x speedup
+     gen5       gnome-system-monitor  10344.47 (10385.62 0.29%) -> 5136.69 (5256.85 1.15%):  2.01x speedup
+     gen3                    poppler  2595.23 (2603.10 0.17%) -> 1297.56 (1302.42 0.61%):  2.00x speedup
+     gen6          firefox-talos-gfx  7184.03 (7194.97 0.13%) -> 3806.31 (3811.66 0.06%):  1.89x speedup
+     gen5                  evolution  8739.25 (8766.12 0.27%) -> 4817.54 (5050.96 1.54%):  1.81x speedup
+     gen3                  evolution  1684.06 (1696.88 0.35%) -> 1004.99 (1008.55 0.85%):  1.68x speedup
+     gen3         gnome-terminal-vim  4285.13 (4287.68 0.04%) -> 2715.97 (3202.17 13.52%):  1.58x speedup
+     gen5             swfdec-youtube  5843.94 (5951.07 0.91%) -> 3810.86 (3826.04 1.32%):  1.53x speedup
+     gen4                    poppler  7496.72 (7558.83 0.58%) -> 5125.08 (5247.65 1.44%):  1.46x speedup
+     gen4         gnome-terminal-vim  21126.24 (21292.08 0.85%) -> 14590.25 (15066.33 1.80%):  1.45x speedup
+     gen5          firefox-talos-svg  99873.69 (100300.95 0.37%) -> 70745.66 (70818.86 0.05%):  1.41x speedup
+     gen4       firefox-planet-gnome  28205.10 (28304.45 0.27%) -> 19996.11 (20081.44 0.56%):  1.41x speedup
+     gen5          firefox-talos-gfx  93070.85 (93194.72 0.10%) -> 67687.93 (70374.37 1.30%):  1.37x speedup
+     gen4                  evolution  6696.25 (6854.14 0.85%) -> 4958.62 (5027.73 0.85%):  1.35x speedup
+     gen3         swfdec-giant-steps  2538.03 (2539.30 0.04%) -> 1895.71 (2050.62 62.43%):  1.34x speedup
+     gen4                       gvim  4356.18 (4422.78 0.70%) -> 3276.31 (3281.69 0.13%):  1.33x speedup
+     gen6                  evolution  1242.13 (1245.44 0.72%) -> 953.76 (954.54 0.07%):  1.30x speedup
+     gen6       firefox-planet-gnome  4554.23 (4560.69 0.08%) -> 3758.76 (3768.97 0.28%):  1.21x speedup
+     gen3          firefox-talos-gfx  6264.13 (6284.65 0.30%) -> 5261.56 (5370.87 1.28%):  1.19x speedup
+     gen4              midori-zoomed  4771.13 (4809.90 0.73%) -> 4037.03 (4118.93 0.85%):  1.18x speedup
+     gen6         swfdec-giant-steps  1557.06 (1560.13 0.12%) -> 1336.34 (1341.29 0.32%):  1.17x speedup
+     gen4          firefox-talos-gfx  80767.28 (80986.31 0.17%) -> 69629.08 (69721.71 0.06%):  1.16x speedup
+     gen6              midori-zoomed  1463.70 (1463.76 0.08%) -> 1331.45 (1336.56 0.22%):  1.10x speedup
+    Slowdowns
+    =========
+     gen6          xfce4-terminal-a1  2030.25 (2036.23 0.25%) -> 2144.60 (2240.31 4.29%):  1.06x slowdown
+     gen4             swfdec-youtube  3580.00 (3597.23 3.92%) -> 3826.90 (3862.24 0.91%):  1.07x slowdown
+     gen4          firefox-talos-svg  66112.25 (66256.51 0.11%) -> 71433.40 (71584.31 0.14%):  1.08x slowdown
+     gen4       gnome-system-monitor  5691.60 (5724.03 0.56%) -> 6707.56 (6747.83 0.33%):  1.18x slowdown
+     gen3                  ocitysmap  3494.05 (3502.44 0.20%) -> 4321.99 (4524.42 2.78%):  1.24x slowdown
+     gen4                  ocitysmap  3628.42 (3641.66 9.37%) -> 5177.16 (5828.74 8.38%):  1.43x slowdown
+     gen5                  ocitysmap  4027.77 (4068.11 0.80%) -> 5748.26 (6282.25 7.38%):  1.43x slowdown
+     gen6                  ocitysmap  1401.61 (1402.24 0.40%) -> 2365.74 (2379.14 4.12%):  1.69x slowdown
+    
+    [Note the performance regression for ocitysmap comes from that we now
+    attempt to support rendering to and (more importantly) from large
+    surfaces. By enabling such operations is the only way to one day be
+    faster than purely using the CPU, in the meantime we suffer regression
+    due to the increased migration and aperture thrashing. The other couple
+    of regressions will be eliminated with improved span and shader support,
+    now that the framework for such is in place.]
+    
+    The performance increase for Cairo completely overlooks the other
+    critical aspects of the architecture:
+    
+    World of Padman:
+    gen3 (800x600):   57.5 ->  96.2
+    gen4 (800x600):   47.8 ->  74.6
+    gen6 (1366x768): 100.4 -> 140.3 [F15]
+                     144.3 -> 146.4 [drm-intel-next]
+    
+    x11perf (gen6);
+    aa10text:     3.47 -> 14.3 Mglyphs/s [unthrottled!]
+    copywinwin10: 1.66 -> 1.99 Mops/s
+    copywinpix10: 2.28 -> 2.98 Mops/s
+    
+    And we do not have a good measure for how much improvement the reworking
+    of the fallback paths give, except that xterm is now over 4x faster...
+    
+    PS: This depends upon the Xorg patchset "Remove the cacheing of the last
+    scratch PixmapRec" for correct invalidations of scratch Pixmaps (used by
+    the dix to implement SHM operations, used by chromium and gtk+ pixbufs.
+    
+    PPS: ./configure --enable-sna
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 340cfb7f5271fd1df4c8948e5c9336f5b69a6e6c
+Author: Diego Elio Pettenò <flameeyes@gmail.com>
+Date:   Sun May 15 02:17:32 2011 +0200
+
+    build: do not use AC_CHECK_FILE to find the header files.
+    
+    Using AC_CHECK_FILE will cause cross-builds to fail picking the right file;
+    instead use compile/preprocessor checks properly, and check for
+    xf86driproto earlier.
+    
+    Reviewed-by: Rémi Cardona <remi@gentoo.org>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 9d6e02a135efdea1d169d1938359ab2b553e941c
+Author: Adam Jackson <ajax@redhat.com>
+Date:   Tue May 10 15:27:45 2011 -0400
+
+    Remove the memory of Option "AccelMethod"
+    
+    Signed-off-by: Adam Jackson <ajax@redhat.com>
+    Reviewed-by: Eric Anholt <eric@anholt.net>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 895a46e8ff70195c1a4bdccbeb652e330376f64a
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue May 10 20:38:25 2011 +0100
+
+    dri: Flush the batch after a DRI swap/copy event
+    
+    To minimise lag in those every so critical games, we want to ensure that
+    the copy happens as soon as it is received, so we need to flush the
+    batch after processing a swap event and before we go to sleep.
+    
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=37068
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0b4ca9313cc7eb4845cf7f4e87c869c0c6d6ff0d
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue May 10 20:36:10 2011 +0100
+
+    video: Flush the batch on the next blockhandler after queuing
+    
+    In order to avoid video lag and jerky playback we need to ensure that
+    any queued video is flushed before we go to sleep.
+    
+    Fixes regression from 6f104189bb.
+    
+    Reported-and-tested-by: Edward Sheldrake <ejsheldrake@gmail.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=37068
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit bb8bf2a28bcb5e838bf4bb7e80ce220d28540719
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue May 10 14:35:02 2011 +0100
+
+    Correct chipset detection for Q33, Q35, B43_G1
+    
+    Everytime we update these tables we trip over this bit of marketing
+    genius.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit fd1ebd44fb72e7bdf57d00f8941cd6110a529cac
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue May 10 07:30:58 2011 +0100
+
+    module: Adopt IVB's more detailed naming convention for SNB
+    
+    This should fix the seven-fold repetition of "SandyBridge" in the list
+    of supported chipsets during start-up... And be more useful in bug
+    reports!
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit e9811bb777dfc51af19836175645400489f7d991
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue May 10 07:28:23 2011 +0100
+
+    Whitespacing cleanup for intel_module.c
+    
+    Bring intel_module.c into line with the kernel whitespacing rules abided
+    by everywhere else in the tree.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 79e59fb2a047b1e733a7b0dee608db3311391725
+Author: Eric Anholt <eric@anholt.net>
+Date:   Fri May 6 12:40:12 2011 -0700
+
+    Add support for Ivybridge chipset.
+    
+    This gets display and 2D blit acceleration up and running.  No Render
+    acceleration is provided yet.
+
+commit 792738adfc5164d30358f045875dfc9b199a46da
+Author: Eric Anholt <eric@anholt.net>
+Date:   Fri May 6 13:14:25 2011 -0700
+
+    Remove the static list of PciChipset and construct it from SymTabRec instead.
+    
+    This is one less place the new hardware enabler has to spam the
+    chipset in.  The PciChipset is just a match structure from PciId to
+    the SymTabRec entry token, and our SymTabRec entry tokens are just the
+    PciId, so it's trivial to construct.
+    
+    Acked-by: Kenneth Graunke <kenneth@whitecape.org>
+
+commit 583e80dfa12d6c73fc677c81cb605a07b2768979
+Author: Eric Anholt <eric@anholt.net>
+Date:   Fri May 6 13:00:53 2011 -0700
+
+    Use the existing deviceID -> name mapping in SymTabRec instead of duping it.
+    
+    We need to have this array anyway for the xf86 interfaces, apparently,
+    so just store the name in one location.  This drops the i852/i855
+    subdevice distinction in the name printed, but I haven't seen us ever
+    care about that.
+    
+    Acked-by: Kenneth Graunke <kenneth@whitecape.org>
+
+commit adf7bbd3a8758de6cdecbace42e399dd27188497
+Author: Eric Anholt <eric@anholt.net>
+Date:   Fri May 6 12:56:53 2011 -0700
+
+    Store the chipset info struct in the PCI match struct, instead of a switch().
+    
+    Acked-by: Kenneth Graunke <kenneth@whitecape.org>
+
+commit 3145530feed879082bcfab11ffc8e7fd0911c920
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sat May 7 19:51:04 2011 +0100
+
+    Ensure that the partial batch is flushed upon the blockhandler
+    
+    Currently, we require that a batch containing a dirty bo be submitted
+    before we mark the device as requiring a flush. So if we never submit a
+    batch between block handlers, we can end up sleeping without ever
+    flushing either the partial batch or the rendering to the scanout.
+    
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=36776
+    Tested-by: Vasily Khoruzhick <anarsoul@gmail.com>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 67e5a74e997f199327f9115c7ba867df3c49da8d
+Author: Paul Menzel <paulepanter@users.sourceforge.net>
+Date:   Fri Apr 22 15:09:12 2011 +0200
+
+    NEWS: fix typo (s/2.14/2.15/) to match corresponding release
+    
+    Signed-off-by: Paul Menzel <paulepanter@users.sourceforge.net>
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 0944e2d5749f5122cd9802c4a2421106fa829ea4
+Author: Jesse Barnes <jbarnes@virtuousgeek.org>
+Date:   Wed Apr 20 11:39:55 2011 -0700
+
+    Add basic 30 bit depth support
+    
+    Still need to handle video and gamma correction, but this gets the
+    display up and running at 30 bit depth if the kernel and display support
+    it.
+    
+    Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
+
+commit 1d102cc6ed21d1c4afa47800eecd24b9d663f689
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Tue Apr 12 13:48:38 2011 +0100
+
+    Use SwapbuffersWait config option to control waiting on fullscreen swaps
+    
+    As fullscreen swaps were going via a different path to the swapping of
+    ordinary windows, we were no longer honouring the xorg.conf option to
+    disable swapbuffer waiting.
+    
+    This changes the code to only use pageflipping if the Option
+    "SwapbuffersWait" is set to "TRUE" (default).
+    
+    Jesse's comment was that this should be superseded by actually
+    supporting asynchronous page flips. As we are missing kernel and dix level
+    support for that, in the meantime honour the config option.
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+    Cc: Jesse Barnes <jbarnes@virtuousgeek.org>
+    Cc: Kristian Høgsberg <krh@bitplanet.net>
+
+commit c9fb69cb2502917dfb2828c90802de7766072899
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Apr 17 10:42:05 2011 +0100
+
+    i965/video: We need 150 dwords of space for video state emission
+    
+    (Actually around 131, with additional 10% just for safety.)
+    
+    Reported-by: Modestas Vainius <geromanas@mailas.com>
+    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=36319
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit a51cd83d25f2f9f2107219d5671194f931601244
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Sun Apr 17 10:36:26 2011 +0100
+
+    intel: Beware the unsigned promotion when checking for batch overflows
+    
+    Reported-by: Modestas Vainius <geromanas@mailas.com>
+    References: https://bugs.freedesktop.org/show_bug.cgi?id=36319
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
+commit 030aa3d13643a0acb7126fa1fa6c5a8eac134639
+Author: Chris Wilson <chris@chris-wilson.co.uk>
+Date:   Thu Apr 14 10:25:21 2011 +0100
+
+    NEWS: typo.
+    
+    Spotted too late...
+    
+    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
+
 commit 0e425b30e12b11dbf51eea1d3366e3372f8b93af
 Author: Chris Wilson <chris@chris-wilson.co.uk>
 Date:   Thu Apr 14 10:16:03 2011 +0100
index 83948ab..b3d37b2 100644 (file)
 #  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.
 
-ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
 
-SUBDIRS = uxa src man
+SUBDIRS = man
+
+if UXA
+SUBDIRS += uxa
+endif
+
+SUBDIRS += src
 MAINTAINERCLEANFILES = ChangeLog INSTALL
 
+if HAVE_X11
+SUBDIRS += test
+endif
+
 .PHONY: ChangeLog INSTALL
 
 INSTALL:
index dec3d37..a9ae289 100644 (file)
@@ -1,9 +1,9 @@
-# Makefile.in generated by automake 1.11.1 from Makefile.am.
+# Makefile.in generated by automake 1.11.6 from Makefile.am.
 # @configure_input@
 
 # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-# 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
-# Inc.
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
+# Foundation, Inc.
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
 #  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.
 VPATH = @srcdir@
+am__make_dryrun = \
+  { \
+    am__dry=no; \
+    case $$MAKEFLAGS in \
+      *\\[\ \  ]*) \
+        echo 'am--echo: ; @echo "AM"  OK' | $(MAKE) -f - 2>/dev/null \
+          | grep '^AM OK$$' >/dev/null || am__dry=yes;; \
+      *) \
+        for am__flg in $$MAKEFLAGS; do \
+          case $$am__flg in \
+            *=*|--*) ;; \
+            *n*) am__dry=yes; break;; \
+          esac; \
+        done;; \
+    esac; \
+    test $$am__dry = yes; \
+  }
 pkgdatadir = $(datadir)/@PACKAGE@
 pkgincludedir = $(includedir)/@PACKAGE@
 pkglibdir = $(libdir)/@PACKAGE@
@@ -53,19 +70,16 @@ PRE_UNINSTALL = :
 POST_UNINSTALL = :
 build_triplet = @build@
 host_triplet = @host@
+@UXA_TRUE@am__append_1 = uxa
+@HAVE_X11_TRUE@am__append_2 = test
 subdir = .
 DIST_COMMON = README $(am__configure_deps) $(srcdir)/Makefile.am \
        $(srcdir)/Makefile.in $(srcdir)/config.h.in \
        $(top_srcdir)/configure AUTHORS COPYING ChangeLog INSTALL NEWS \
-       build-aux/config.guess build-aux/config.sub build-aux/depcomp \
-       build-aux/install-sh build-aux/ltmain.sh build-aux/missing \
        compile config.guess config.sub depcomp install-sh ltmain.sh \
        missing
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
-       $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
-       $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
-       $(top_srcdir)/configure.ac
+am__aclocal_m4_deps = $(top_srcdir)/configure.ac
 am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
        $(ACLOCAL_M4)
 am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \
@@ -74,11 +88,11 @@ mkinstalldirs = $(install_sh) -d
 CONFIG_HEADER = config.h
 CONFIG_CLEAN_FILES =
 CONFIG_CLEAN_VPATH_FILES =
-AM_V_GEN = $(am__v_GEN_$(V))
-am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY))
+AM_V_GEN = $(am__v_GEN_@AM_V@)
+am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
 am__v_GEN_0 = @echo "  GEN   " $@;
-AM_V_at = $(am__v_at_$(V))
-am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY))
+AM_V_at = $(am__v_at_@AM_V@)
+am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
 am__v_at_0 = @
 SOURCES =
 DIST_SOURCES =
@@ -89,6 +103,11 @@ RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \
        install-pdf-recursive install-ps-recursive install-recursive \
        installcheck-recursive installdirs-recursive pdf-recursive \
        ps-recursive uninstall-recursive
+am__can_run_installinfo = \
+  case $$AM_UPDATE_INFO_DIR in \
+    n|no|NO) false;; \
+    *) (install-info --version) >/dev/null 2>&1;; \
+  esac
 RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive        \
   distclean-recursive maintainer-clean-recursive
 AM_RECURSIVE_TARGETS = $(RECURSIVE_TARGETS:-recursive=) \
@@ -96,14 +115,16 @@ AM_RECURSIVE_TARGETS = $(RECURSIVE_TARGETS:-recursive=) \
        distdir dist dist-all distcheck
 ETAGS = etags
 CTAGS = ctags
-DIST_SUBDIRS = $(SUBDIRS)
+DIST_SUBDIRS = man uxa src test
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
 distdir = $(PACKAGE)-$(VERSION)
 top_distdir = $(distdir)
 am__remove_distdir = \
-  { test ! -d "$(distdir)" \
-    || { find "$(distdir)" -type d ! -perm -200 -exec chmod u+w {} ';' \
-         && rm -fr "$(distdir)"; }; }
+  if test -d "$(distdir)"; then \
+    find "$(distdir)" -type d ! -perm -200 -exec chmod u+w {} ';' \
+      && rm -rf "$(distdir)" \
+      || { sleep 5 && rm -rf "$(distdir)"; }; \
+  else :; fi
 am__relativize = \
   dir0=`pwd`; \
   sed_first='s,^\([^/]*\)/.*$$,\1,'; \
@@ -132,6 +153,8 @@ am__relativize = \
 DIST_ARCHIVES = $(distdir).tar.gz $(distdir).tar.bz2
 GZIP_ENV = --best
 distuninstallcheck_listfiles = find . -type f -print
+am__distuninstallcheck_listfiles = $(distuninstallcheck_listfiles) \
+  | sed 's|^\./|$(prefix)/|' | grep -v '$(infodir)/dir$$'
 distcleancheck_listfiles = find . -type f -print
 ACLOCAL = @ACLOCAL@
 ADMIN_MAN_DIR = @ADMIN_MAN_DIR@
@@ -145,6 +168,7 @@ AUTOCONF = @AUTOCONF@
 AUTOHEADER = @AUTOHEADER@
 AUTOMAKE = @AUTOMAKE@
 AWK = @AWK@
+BASE_CFLAGS = @BASE_CFLAGS@
 CC = @CC@
 CCDEPMODE = @CCDEPMODE@
 CFLAGS = @CFLAGS@
@@ -155,11 +179,16 @@ CWARNFLAGS = @CWARNFLAGS@
 CYGPATH_W = @CYGPATH_W@
 DEFS = @DEFS@
 DEPDIR = @DEPDIR@
+DLLTOOL = @DLLTOOL@
+DRI2_CFLAGS = @DRI2_CFLAGS@
+DRI2_LIBS = @DRI2_LIBS@
 DRIVER_MAN_DIR = @DRIVER_MAN_DIR@
 DRIVER_MAN_SUFFIX = @DRIVER_MAN_SUFFIX@
 DRIVER_NAME = @DRIVER_NAME@
 DRI_CFLAGS = @DRI_CFLAGS@
 DRI_LIBS = @DRI_LIBS@
+DRMINTEL_CFLAGS = @DRMINTEL_CFLAGS@
+DRMINTEL_LIBS = @DRMINTEL_LIBS@
 DRM_CFLAGS = @DRM_CFLAGS@
 DRM_LIBS = @DRM_LIBS@
 DSYMUTIL = @DSYMUTIL@
@@ -183,6 +212,10 @@ INSTALL_SCRIPT = @INSTALL_SCRIPT@
 INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
 LD = @LD@
 LDFLAGS = @LDFLAGS@
+LIBGLAMOR_CFLAGS = @LIBGLAMOR_CFLAGS@
+LIBGLAMOR_EGL_CFLAGS = @LIBGLAMOR_EGL_CFLAGS@
+LIBGLAMOR_EGL_LIBS = @LIBGLAMOR_EGL_LIBS@
+LIBGLAMOR_LIBS = @LIBGLAMOR_LIBS@
 LIBOBJS = @LIBOBJS@
 LIBS = @LIBS@
 LIBTOOL = @LIBTOOL@
@@ -193,6 +226,7 @@ LN_S = @LN_S@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MANIFEST_TOOL = @MANIFEST_TOOL@
 MAN_SUBSTS = @MAN_SUBSTS@
 MISC_MAN_DIR = @MISC_MAN_DIR@
 MISC_MAN_SUFFIX = @MISC_MAN_SUFFIX@
@@ -220,10 +254,15 @@ RANLIB = @RANLIB@
 SED = @SED@
 SET_MAKE = @SET_MAKE@
 SHELL = @SHELL@
+STRICT_CFLAGS = @STRICT_CFLAGS@
 STRIP = @STRIP@
 UDEV_CFLAGS = @UDEV_CFLAGS@
 UDEV_LIBS = @UDEV_LIBS@
+VALGRIND_CFLAGS = @VALGRIND_CFLAGS@
+VALGRIND_LIBS = @VALGRIND_LIBS@
 VERSION = @VERSION@
+X11_CFLAGS = @X11_CFLAGS@
+X11_LIBS = @X11_LIBS@
 XORG_CFLAGS = @XORG_CFLAGS@
 XORG_LIBS = @XORG_LIBS@
 XORG_MAN_PAGE = @XORG_MAN_PAGE@
@@ -233,6 +272,7 @@ abs_builddir = @abs_builddir@
 abs_srcdir = @abs_srcdir@
 abs_top_builddir = @abs_top_builddir@
 abs_top_srcdir = @abs_top_srcdir@
+ac_ct_AR = @ac_ct_AR@
 ac_ct_CC = @ac_ct_CC@
 ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
 am__include = @am__include@
@@ -265,7 +305,6 @@ libdir = @libdir@
 libexecdir = @libexecdir@
 localedir = @localedir@
 localstatedir = @localstatedir@
-lt_ECHO = @lt_ECHO@
 mandir = @mandir@
 mkdir_p = @mkdir_p@
 moduledir = @moduledir@
@@ -282,14 +321,13 @@ target_alias = @target_alias@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
-ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
-SUBDIRS = uxa src man
+SUBDIRS = man $(am__append_1) src $(am__append_2)
 MAINTAINERCLEANFILES = ChangeLog INSTALL
 all: config.h
        $(MAKE) $(AM_MAKEFLAGS) all-recursive
 
 .SUFFIXES:
-am--refresh:
+am--refresh: Makefile
        @:
 $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am  $(am__configure_deps)
        @for dep in $?; do \
@@ -325,10 +363,8 @@ $(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
 $(am__aclocal_m4_deps):
 
 config.h: stamp-h1
-       @if test ! -f $@; then \
-         rm -f stamp-h1; \
-         $(MAKE) $(AM_MAKEFLAGS) stamp-h1; \
-       else :; fi
+       @if test ! -f $@; then rm -f stamp-h1; else :; fi
+       @if test ! -f $@; then $(MAKE) $(AM_MAKEFLAGS) stamp-h1; else :; fi
 
 stamp-h1: $(srcdir)/config.h.in $(top_builddir)/config.status
        @rm -f stamp-h1
@@ -519,13 +555,10 @@ distdir: $(DISTFILES)
        done
        @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
          if test "$$subdir" = .; then :; else \
-           test -d "$(distdir)/$$subdir" \
-           || $(MKDIR_P) "$(distdir)/$$subdir" \
-           || exit 1; \
-         fi; \
-       done
-       @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
-         if test "$$subdir" = .; then :; else \
+           $(am__make_dryrun) \
+             || test -d "$(distdir)/$$subdir" \
+             || $(MKDIR_P) "$(distdir)/$$subdir" \
+             || exit 1; \
            dir1=$$subdir; dir2="$(distdir)/$$subdir"; \
            $(am__relativize); \
            new_distdir=$$reldir; \
@@ -559,7 +592,11 @@ dist-gzip: distdir
        tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz
        $(am__remove_distdir)
 dist-bzip2: distdir
-       tardir=$(distdir) && $(am__tar) | bzip2 -9 -c >$(distdir).tar.bz2
+       tardir=$(distdir) && $(am__tar) | BZIP2=$${BZIP2--9} bzip2 -c >$(distdir).tar.bz2
+       $(am__remove_distdir)
+
+dist-lzip: distdir
+       tardir=$(distdir) && $(am__tar) | lzip -c $${LZIP_OPT--9} >$(distdir).tar.lz
        $(am__remove_distdir)
 
 dist-lzma: distdir
@@ -567,7 +604,7 @@ dist-lzma: distdir
        $(am__remove_distdir)
 
 dist-xz: distdir
-       tardir=$(distdir) && $(am__tar) | xz -c >$(distdir).tar.xz
+       tardir=$(distdir) && $(am__tar) | XZ_OPT=$${XZ_OPT--e} xz -c >$(distdir).tar.xz
        $(am__remove_distdir)
 
 dist-tarZ: distdir
@@ -585,7 +622,7 @@ dist-zip: distdir
 
 dist dist-all: distdir
        tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz
-       tardir=$(distdir) && $(am__tar) | bzip2 -9 -c >$(distdir).tar.bz2
+       tardir=$(distdir) && $(am__tar) | BZIP2=$${BZIP2--9} bzip2 -c >$(distdir).tar.bz2
        $(am__remove_distdir)
 
 # This target untars the dist file and tries a VPATH configuration.  Then
@@ -599,6 +636,8 @@ distcheck: dist
          bzip2 -dc $(distdir).tar.bz2 | $(am__untar) ;;\
        *.tar.lzma*) \
          lzma -dc $(distdir).tar.lzma | $(am__untar) ;;\
+       *.tar.lz*) \
+         lzip -dc $(distdir).tar.lz | $(am__untar) ;;\
        *.tar.xz*) \
          xz -dc $(distdir).tar.xz | $(am__untar) ;;\
        *.tar.Z*) \
@@ -608,7 +647,7 @@ distcheck: dist
        *.zip*) \
          unzip $(distdir).zip ;;\
        esac
-       chmod -R a-w $(distdir); chmod a+w $(distdir)
+       chmod -R a-w $(distdir); chmod u+w $(distdir)
        mkdir $(distdir)/_build
        mkdir $(distdir)/_inst
        chmod a-w $(distdir)
@@ -618,6 +657,7 @@ distcheck: dist
          && am__cwd=`pwd` \
          && $(am__cd) $(distdir)/_build \
          && ../configure --srcdir=.. --prefix="$$dc_install_base" \
+           $(AM_DISTCHECK_CONFIGURE_FLAGS) \
            $(DISTCHECK_CONFIGURE_FLAGS) \
          && $(MAKE) $(AM_MAKEFLAGS) \
          && $(MAKE) $(AM_MAKEFLAGS) dvi \
@@ -646,8 +686,16 @@ distcheck: dist
          list='$(DIST_ARCHIVES)'; for i in $$list; do echo $$i; done) | \
          sed -e 1h -e 1s/./=/g -e 1p -e 1x -e '$$p' -e '$$x'
 distuninstallcheck:
-       @$(am__cd) '$(distuninstallcheck_dir)' \
-       && test `$(distuninstallcheck_listfiles) | wc -l` -le 1 \
+       @test -n '$(distuninstallcheck_dir)' || { \
+         echo 'ERROR: trying to run $@ with an empty' \
+              '$$(distuninstallcheck_dir)' >&2; \
+         exit 1; \
+       }; \
+       $(am__cd) '$(distuninstallcheck_dir)' || { \
+         echo 'ERROR: cannot chdir into $(distuninstallcheck_dir)' >&2; \
+         exit 1; \
+       }; \
+       test `$(am__distuninstallcheck_listfiles) | wc -l` -eq 0 \
           || { echo "ERROR: files left after uninstall:" ; \
                if test -n "$(DESTDIR)"; then \
                  echo "  (check DESTDIR support)"; \
@@ -678,10 +726,15 @@ install-am: all-am
 
 installcheck: installcheck-recursive
 install-strip:
-       $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
-         install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
-         `test -z '$(STRIP)' || \
-           echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+       if test -z '$(STRIP)'; then \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+             install; \
+       else \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+           "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+       fi
 mostlyclean-generic:
 
 clean-generic:
@@ -770,18 +823,19 @@ uninstall-am:
 .PHONY: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) CTAGS GTAGS \
        all all-am am--refresh check check-am clean clean-generic \
        clean-libtool ctags ctags-recursive dist dist-all dist-bzip2 \
-       dist-gzip dist-hook dist-lzma dist-shar dist-tarZ dist-xz \
-       dist-zip distcheck distclean distclean-generic distclean-hdr \
-       distclean-libtool distclean-tags distcleancheck distdir \
-       distuninstallcheck dvi dvi-am html html-am info info-am \
-       install install-am install-data install-data-am install-dvi \
-       install-dvi-am install-exec install-exec-am install-html \
-       install-html-am install-info install-info-am install-man \
-       install-pdf install-pdf-am install-ps install-ps-am \
-       install-strip installcheck installcheck-am installdirs \
-       installdirs-am maintainer-clean maintainer-clean-generic \
-       mostlyclean mostlyclean-generic mostlyclean-libtool pdf pdf-am \
-       ps ps-am tags tags-recursive uninstall uninstall-am
+       dist-gzip dist-hook dist-lzip dist-lzma dist-shar dist-tarZ \
+       dist-xz dist-zip distcheck distclean distclean-generic \
+       distclean-hdr distclean-libtool distclean-tags distcleancheck \
+       distdir distuninstallcheck dvi dvi-am html html-am info \
+       info-am install install-am install-data install-data-am \
+       install-dvi install-dvi-am install-exec install-exec-am \
+       install-html install-html-am install-info install-info-am \
+       install-man install-pdf install-pdf-am install-ps \
+       install-ps-am install-strip installcheck installcheck-am \
+       installdirs installdirs-am maintainer-clean \
+       maintainer-clean-generic mostlyclean mostlyclean-generic \
+       mostlyclean-libtool pdf pdf-am ps ps-am tags tags-recursive \
+       uninstall uninstall-am
 
 
 .PHONY: ChangeLog INSTALL
diff --git a/NEWS b/NEWS
index ea92bcf..7419e5e 100644 (file)
--- a/NEWS
+++ b/NEWS
+Release 2.20.9 (2012-09-29)
+===========================
+And so it came to pass that a critical bug was uncovered in UXA. The
+kernel does not like to pageflip when the pipe is off, yet due to the
+delayed nature of a pageflip and the relaxed checking performed by UXA,
+we could request a pageflip after turning off the display (DPMS). The
+kernel rejected that pageflip and the error handling path failed to
+restore sanity, and when the screen came back it was stuck on the image
+seen before it went to sleep. (Note that there are also some related
+kernel bugs, but this update should prevent the most conspicious of the
+freezes.)
+
+In other news:
+
+  * Prepare for xorg-1.4, the api is being tweaked again.
+
+  * Handle early FreeScreen in UXA.
+    https://bugs.freedesktop.org/show_bug.cgi?id=55346
+
+  * Reenable XvMC support
+
+  * Do not replace the GPU bo when uploading into the shadow/CPU copy
+    https://bugs.freedesktop.org/show_bug.cgi?id=54978
+
+  * Fix use of an uninitialised GC when drawing glyphs to a depth=1 pixmap
+    
+
+Release 2.20.8 (2012-09-16)
+===========================
+Another new small feature, another new release. And a few more bugs
+fixed as well! But what is this new feature, do I hear you ask? Why, it
+is nothing less than enabling the ValleyView SDV! The lucky person to
+have their hands on one will now be able to enjoy X in full TechniColor.
+
+For the rest of us, a few more bugs were fixed with interesting
+combinations of software and rendering patterns.
+
+ * Add an extra layer of defence against trying to use a non-GEM device
+   with UXA. This should already be taken care of with the new probe,
+   but the extra sanity check already existed in the code but was doing
+   nothing.
+   https://bugs.launchpad.net/ubuntu/+source/xserver-xorg-video-intel/+bug/962892
+
+ * Fix computation of valid CRTCs bitmask for ZaphodHead
+   Some systems can only handle certain outputs on certain pipes
+   (Screens), and this information was not being propagated through to X
+   and randr correctly, breaking valid configurations and not detecting
+   invalid configurations correctly.
+
+ * Disable global glyph caching with ZaphodHeads.
+   The glyph privates need to be Screen private, but at the moment are
+   global leading to conflicts and invalid rendering with multiple heads.
+   https://bugs.freedesktop.org/show_bug.cgi?id=54707
+
+ * Prevent direct read back of unmappable buffers
+   https://bugs.freedesktop.org/show_bug.cgi?id=54808
+
+ * Tile large uploads whilst replacing the alpha channel
+   https://bugs.freedesktop.org/show_bug.cgi?id=54808
+
+ * Correct the source offset when converting a RENDER composite
+   operation into a BLT composite operation.
+   https://bugs.freedesktop.org/show_bug.cgi?id=54868
+
+ * Correct a minor typo in flattening alphamaps which caused the
+   replacement pixmap to often end up with a height of zero.
+   https://bugs.gentoo.org/show_bug.cgi?id=434860
+
+ * Don't discard the CPU damage if only part of is being replaced.
+   This is most evident when combining software renders like Opera with
+   accelerated rendering.
+   https://bugs.freedesktop.org/show_bug.cgi?id=54937
+
+Release 2.20.7 (2012-09-08)
+===========================
+Continuing the flurry of releases, this week saw the release of
+xorg-1.13 bringing with it the first steps towards hotpluggable gpu
+support and the ability to offload DRI rendering onto other GPUs. In
+light of that advance, this release includes the support code by Dave
+Airlie to integrate PRIME into xf86-video-intel and make those new
+features available.
+
+Aside from landing PRIME, a few other bugs were fixed since 2.20.6:
+
+ * Fix framebuffer leak on server regeneration
+
+ * Fix texture cache flushing on IvyBridge and Kwin with plastique
+   https://bugs.freedesktop.org/show_bug.cgi?id=54488
+
+ * Redirect large solid fills on SandyBridge+. By large I mean greater
+   than 8192 or 16384 pixels on SandyBridge and IvyBridge respectively.
+   https://bugs.freedesktop.org/show_bug.cgi?id=54134
+
+ * Fix up backlight option handling in the manpage and uxa.
+   https://bugs.freedesktop.org/show_bug.cgi?id=54397
+
+ * Unbreak ZaphodHeads.
+   https://bugs.freedesktop.org/show_bug.cgi?id=52438
+
+Release 2.20.6 (2012-09-02)
+===========================
+A serious bug that caused a crash on SandyBridge and IvyBridge when
+mixing CPU and GPU operations on the same buffer, and an annoyance from
+bad scheduling of windowed swapbuffer updates causing low framerates and
+jitter. Plus the usual smattering of assertion fixes and a long standing
+issue with incoherent page access to a streaming buffer.
+
+ * Low frame rates in Blobby Valley when "fullscreen"
+   https://bugs.freedesktop.org/show_bug.cgi?id=54274
+
+ * Incoherent concurrent access with the CPU and GPU
+   https://bugs.freedesktop.org/show_bug.cgi?id=51422
+   https://bugs.freedesktop.org/show_bug.cgi?id=52299
+
+ * Add Option "Backlight" to override automatic selection of the
+   backlight interface.
+
+ * Avoid overwriting the composite operation info when testing if we
+   can transfer the operation to the BLT.
+
+Release 2.20.5 (2012-08-26)
+===========================
+Another silly bug found, another small bugfix release. The goal was for
+the driver to bind to all Intel devices supported by the kernel.
+Unfortunately we were too successful and started claiming Pouslbo,
+Medfield and Cedarview devices which are still encumbered by propietary
+IP and not supported by this driver.
+
+Bugs fixed since 2.20.4:
+
+ * Only bind to Intel devices using the i915 kernel module
+
+ * Regression in the bitmap-to-region code, e.g. icewm window buttons
+   https://bugs.freedesktop.org/show_bug.cgi?id=53699
+
+Release 2.20.4 (2012-08-18)
+===========================
+Continuing the small bugfix releases, the only real feature is initial
+enabling for Haswell for the purpose of rendering verification and
+validation - by no means is it complete!
+
+Bugs fixed since 2.20.3:
+
+  * Some potential errors along failure paths found by a static analyser
+  with the help of Zdenek Kablac.
+
+  * Eliminate zero-sized rectangles from PolyFillRectangles as the code
+  assumes that they did not exist and so caused corruption.
+
+  * Remove the UXA warning for failing to tile the front buffer if it is
+  disallowed by hardware, and so expected.
+
+  * Fix the validation of the XV pipe parameter.
+
+  * Fix 8x8 tiled pattern fills
+  https://bugs.freedesktop.org/show_bug.cgi?id=53353
+
+  * Fix compile failure when using --with-builderstring
+
+  * Restore w/a flush for gen4 fill/copy/video, fortunately rare
+  operations as at least for fill/copy we prefer to use the BLT.
+  https://bugs.freedesktop.org/show_bug.cgi?id=53119
+
+  * Restore preferred use of the RENDER ring for SNB+ DRI copies.
+
+Release 2.20.3 (2012-08-04)
+===========================
+Just a minor bugfix for gen4 chipsets (965gm, gm45 and friends) that
+crept into 2.20.2. As an added bonus, the pessimistic workaround for a
+GPU hang on gen4 has been relaxed and the shaders have been overhauled
+which should pave the way to eliminating the last of the uncommon CPU
+operations, along with immediately realising a small perforamnce
+improvement.
+
+Bugs fixed since 2.20.2:
+
+ * Update DPMS bookkeeping after modeset
+   https://bugs.freedesktop.org/show_bug.cgi?id=52142
+
+ * Avoid overlapping gpu/cpu damage after ignoring cpu damage in the
+   consideration of placement for the operation.
+
+ * Enable acceleration by default on 830gm/845g. The GMCH on this pair
+   of chipsets is notoriously incoherent, so the GPU is almost certainly
+   going to hang at some point, though unlikely to hang the system and
+   should automatically disable acceleration (and thence behave
+   identically as if the acceleration was disabled from the start).
+   Option "NoAccel" can be used to disable all 2D acceleration and
+   Option "DRI" can be used to disable all 3D acceleration.
+   https://bugs.freedesktop.org/show_bug.cgi?id=52624
+
+ * Fix vertex bookkeeping for gen4 that was causing corruption in the
+   command stream.
+
+Release 2.20.2 (2012-07-27)
+===========================
+For the last 9 months, since 2.16.901, we have been shipping a driver that
+does not work on IvyBridge GT1 systems (HD2500 graphics); we were telling
+the GPU to use an invalid number of threads for the pixel shader and this
+in turned caused the GPU to hang.
+
+Also fixed since the last release just a few days ago:
+
+* Support for the gmux backlight controller on Apple laptops
+  https://bugs.freedesktop.org/show_bug.cgi?id=52423
+
+* Fix X -configure not to list this driver as matching any Intel device,
+  just the VGA class devices will do!
+
+* A crash in SNA when repeatedly switching xrandr rotations
+
+* Corruption in SNA observed in kwin on IvyBridge
+  https://bugs.freedesktop.org/show_bug.cgi?id=52473
+
+Release 2.20.1 (2012-07-22)
+===========================
+A week in, grab the brown paper bags, for it is time to reveal a couple
+of critical bugs that spoilt the 2.20.0 release.
+
+Firstly we have the restoration of DRI for i810. I am sure that the
+solitary user will be overjoyed in a couple of years when a new xserver
+is forced upon him. That enjoyment will be short-lived when as no actual
+acceleration remains, not even shadow, for the chipset.
+
+Perhaps a little more wildly felt, I hope!, will be that the SNA
+fallbacks were broken on 64-bit machines if they required clipping. One
+little misplaced cast of a pointer, and the screen is filled with
+corruption.
+
+Among the other tweaks this week:
+
+* A bug affecting gen4 handling of trapezoids was fixed, and CPU
+  overhead reduced.
+  https://bugs.freedesktop.org/show_bug.cgi?id=52158
+
+* A fix for a bug causing corruption of a DRI2 unredirected client
+  window that was resized whilst under a compositor.
+
+* Support for snoopable buffers on non-LLC architectures, coming to
+  a future kernel. The aim to accelerate transfers between the CPU
+  and the GPU, in particular to dramatically improve readback
+  performance, and to further minimise clflushes.
+
+* Improvement to the composite performance on GT2 SandyBridge and
+  IvyBridge devices, in particular the render copy is significantly
+  improved.
+
+* Improved handling for when acceleration is disabled, including
+  permitting DRI2 to remain supported even if the X server believes
+  the GPU wedged.
+
+* Shadow support was dropped from UXA as it was neither complete nor
+  correct, use SNA instead.
+
+Release 2.20.0 (2012-07-15)
+===========================
+First the big news, a new acceleration method that aims to be faster and
+consume far less CPU than UXA is now available for selection at runtime.
+This snazzy new architecture can be selected through use of
+  Option "AccelMethod" "sna"
+in your xorg.conf. Whilst it has been under development for some time, it
+has not yet had the same degree of widespread testing of UXA, so tread
+lightly. Try it and if you spot anything that can be improved, please do
+report a bug.
+
+Otherwise we have the usual smattering of bug fixes for UXA:
+
+ * Use a white source whilst adding glyphs to the glyph mask
+   (This fixes blank glyphs if using a font that mixes ARGB and A glyphs.)
+
+ * Avoid fallbacks for glyph-to-dst in e.g. gnome-terminal
+   https://bugs.freedesktop.org/show_bug.cgi?id=50508
+
+ * Force unused outputs off when VT switching
+   https://bugs.freedesktop.org/show_bug.cgi?id=50772
+
+ * Copy the fbcon across to the Screen pixmap at startup.
+   (This patch has been kicking around in the distributions for years.)
+
+ * Many missed malloc failures checks and forgotten frees found by a static
+   analyzer. Thanks Zdenek Kabelac!
+
+ * Leak of the back buffer when terminating an application after pageflipping
+   https://bugs.freedesktop.org/show_bug.cgi?id=50670
+
+ * Double check that the pipe is on before emitting a WAIT_ON_EVENT.
+   In conjunction with an uptodate kernel, this should eliminate any
+   hangs when changing resolutions or adding/removing displays.
+   https://bugs.freedesktop.org/show_bug.cgi?id=50668
+
+ * Update to new Xorg APIs. Future proofing for the next generation of
+   hotplug Xorg display servers.
+
+Many thanks to everyone who has reported a bug and otherwise helped to
+improve the driver.
+
+Release 2.19.0 (2012-04-29)
+===========================
+More stability fixes for UXA and support for another variant of IvyBridge.
+Given the severity of the stability fixes, I strongly recommend everybody
+to upgrade to 2.19.0.
+
+* Prevent waiting on scanlines whilst not in control of the VT and therefore
+  whilst referencing foreign CRTC configurations.
+
+* Pixmap (and bo leak) during fallback glyph composition
+
+* Remove broken acceleration for rendering glyphs directly upon the
+  destination pixmap, exposed by cairo-1.12.0 (and coincidentally fix
+  another Pixmap leak upon fallback handling).
+
+* Add support for Ivy Bridge GT2 Server chipset [PCI id 0x016a]
+
+* Remove broken damage flushing with CompositeRectangles
+  https://bugs.freedesktop.org/show_bug.cgi?id=32547
+
+* Fix crash upon server start with multiple monitors
+  https://bugs.freedesktop.org/show_bug.cgi?id=47395
+
+* Fix composition issues resulting from overly aggressive Pixmap reuse
+  https://bugs.freedesktop.org/show_bug.cgi?id=47345
+
+Release 2.18.0 (2012-02-24)
+===========================
+Time passes, a few more bugs have crept out of the woodwork that are a
+compelling reason to update.
+
+Bugs fixed in this release (compared to 2.17.0)
+-----------------------------------------------
+
+* Limit maximum object size so that all of the source, mask and
+  destination can be mapped into the aperture simultaneously by basing the
+  limit on the mappable aperture size rather than the size of the total
+  GATT.
+
+* Incorrect clipping of polygons
+  https://bugs.freedesktop.org/show_bug.cgi?id=43649
+  Regression from 2.15.901
+
+* Limit number of VMA cached to avoid hitting the per-process VMA limit
+  There still is a residual bug in that we seem to have so many objects
+  floating around in the first place and that still leads to exhaustion
+  of system limits.
+  https://bugs.freedesktop.org/show_bug.cgi?id=43075
+  https://bugs.freedesktop.org/show_bug.cgi?id=40066
+
+* Latency in processing user-input during continuous rendering
+
+Release 2.17.0 (2011-11-16)
+==============================
+A few months have passed, and we have accumulated a surprising number of
+bug fixes. Oops! We would strongly encourage everyone to upgrade.
+
+Bugs fixed in this snapshot (compared to 2.16.902)
+--------------------------------------------------
+
+* Video clobbering composite batch state
+  http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=635953
+
+Snapshot 2.16.902 (2011-11-13)
+==============================
+This is the second release candidate in preparation for the upcoming
+2.17.0 release. We will appreciate any feedback we can get from
+testing of this snapshot, and thanks to everyone who tested and reported
+upon issues in the last snapshot.
+
+A very old bug demonstrating that nobody has ever used alpha maps, and a
+couple of more recent mistakes were found.
+
+Bugs fixed in this snapshot (compared to 2.16.901)
+--------------------------------------------------
+
+ * Incorrect reuse of surface bindings within a batch for multiple formats
+   https://bugs.freedesktop.org/show_bug.cgi?id=40926
+
+ * Nothing was rendered for text with procedural sources
+   https://bugs.freedesktop.org/show_bug.cgi?id=31819
+
+ * Handle fallbacks involving alpha maps
+
+Snapshot 2.16.901 (2011-10-30)
+==============================
+This is the first release candidate in preparation for the upcoming
+2.17.0 release. We will appreciate any feedback we can get from
+testing of this snapshot.
+
+The basis of this release are to push out a couple of critical stability
+fixes for SandyBridge and IvyBridge. There is very little else to see
+here. Those 200+ other commits do not exist...
+
+Bugs fixed in this snapshot (compared to 2.16.0)
+--------------------------------------------------
+
+ * Workaround blitter hang on SandyBridge and IvyBridge
+   https://bugzilla.kernel.org/show_bug.cgi?id=27892
+   https://bugs.freedesktop.org/show_bug.cgi
+
+ * Workaround pipe control issues on SandyBridge
+
+ * Use correct maximum PS thread count on IvyBridge
+
+ * Protect against failed pixmap allocation for XV
+   https://bugs.freedesktop.org/show_bug.cgi?id=40439
+
+Release 2.16.0 (2011-08-09)
+==============================
+A new quarter, a new release! The key feature of this release, looking past
+the bug fixes, is the enabling of IvyBridge acceleration. We have also fixed
+many bugs and graphical glitches and would encourage everyone to upgrade.
+
+Bugs fixed in this snapshot (compared to 2.15.901)
+--------------------------------------------------
+
+* Build fix for xserver-1.7.7
+
+Snapshot 2.15.901 (2011-07-30)
+==============================
+This is the first release candidate in preparation for the upcoming
+2.16.0 release. We will appreciate any feedback we can get from
+testing of this snapshot.
+
+The highlight of this snapshot is the full enabling of IvyBridge with
+acceleration for Render and Xv, along with handling of the shared render
+buffer allocations required for Mesa. Also of note is that deep-color
+support is enabled (for all chipsets), which allows you to drive your
+30-bit monitor at its native colour depth.
+
+Bugs fixed in this snapshot (compared to 2.15.0)
+--------------------------------------------------
+
+* Misuse of the Resource database causing crashes after DRI clients close
+  https://bugs.freedesktop.org/show_bug.cgi?id=37700
+
+* Crash on large strings
+  https://bugs.freedesktop.org/show_bug.cgi?id=36860
+
+* Incorrect rendering for some core drawing operations
+  http://bugs.freedesktop.org/show_bug.cgi?id=28768
+  http://bugs.freedesktop.org/show_bug.cgi?id=28798
+  http://bugs.freedesktop.org/show_bug.cgi?id=28908
+  http://bugs.freedesktop.org/show_bug.cgi?id=29401
+
+* Crash in Xv due to insufficient checks on batch space
+  https://bugs.freedesktop.org/show_bug.cgi?id=36319
+
 Release 2.15.0 (2011-04-14)
 ==============================
 We are pleased to announce this major release of the xf86-video-intel
 driver, roughly on schedule at 3 months since 2.14.0. With the many bug
-fixes in this release, we encourage everyone to upgrade to 2.14.
+fixes in this release, we encourage everyone to upgrade to 2.15.
 
-The priority for this quarter has been simply to unexciting and stabilise
+The priority for this quarter has been simply to be unexciting and stabilise
 the driver further, seeking to capitalise upon the improvements elsewhere
 in the stack.
 
index 92525c7..fa97284 100644 (file)
@@ -1,7 +1,8 @@
-# generated automatically by aclocal 1.11.1 -*- Autoconf -*-
+# generated automatically by aclocal 1.11.6 -*- Autoconf -*-
 
 # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
-# 2005, 2006, 2007, 2008, 2009  Free Software Foundation, Inc.
+# 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation,
+# Inc.
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
 
 m4_ifndef([AC_AUTOCONF_VERSION],
   [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
-m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.67],,
-[m4_warning([this file was generated for autoconf 2.67.
+m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.69],,
+[m4_warning([this file was generated for autoconf 2.69.
 You have another version of autoconf.  It may work, but is not guaranteed to.
 If you have problems, you may need to regenerate the build system entirely.
 To do so, use the procedure documented by the package, typically `autoreconf'.])])
 
+# libtool.m4 - Configure libtool for the host system. -*-Autoconf-*-
+#
+#   Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005,
+#                 2006, 2007, 2008, 2009, 2010, 2011 Free Software
+#                 Foundation, Inc.
+#   Written by Gordon Matzigkeit, 1996
+#
+# This file is free software; the Free Software Foundation gives
+# unlimited permission to copy and/or distribute it, with or without
+# modifications, as long as this notice is preserved.
+
+m4_define([_LT_COPYING], [dnl
+#   Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005,
+#                 2006, 2007, 2008, 2009, 2010, 2011 Free Software
+#                 Foundation, Inc.
+#   Written by Gordon Matzigkeit, 1996
+#
+#   This file is part of GNU Libtool.
+#
+# GNU Libtool is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of
+# the License, or (at your option) any later version.
+#
+# As a special exception to the GNU General Public License,
+# if you distribute this file as part of a program or library that
+# is built using GNU Libtool, you may include this file under the
+# same distribution terms that you use for the rest of that program.
+#
+# GNU Libtool is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Libtool; see the file COPYING.  If not, a copy
+# can be downloaded from http://www.gnu.org/licenses/gpl.html, or
+# obtained by writing to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+])
+
+# serial 57 LT_INIT
+
+
+# LT_PREREQ(VERSION)
+# ------------------
+# Complain and exit if this libtool version is less that VERSION.
+m4_defun([LT_PREREQ],
+[m4_if(m4_version_compare(m4_defn([LT_PACKAGE_VERSION]), [$1]), -1,
+       [m4_default([$3],
+                  [m4_fatal([Libtool version $1 or higher is required],
+                            63)])],
+       [$2])])
+
+
+# _LT_CHECK_BUILDDIR
+# ------------------
+# Complain if the absolute build directory name contains unusual characters
+m4_defun([_LT_CHECK_BUILDDIR],
+[case `pwd` in
+  *\ * | *\    *)
+    AC_MSG_WARN([Libtool does not cope well with whitespace in `pwd`]) ;;
+esac
+])
+
+
+# LT_INIT([OPTIONS])
+# ------------------
+AC_DEFUN([LT_INIT],
+[AC_PREREQ([2.58])dnl We use AC_INCLUDES_DEFAULT
+AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT])dnl
+AC_BEFORE([$0], [LT_LANG])dnl
+AC_BEFORE([$0], [LT_OUTPUT])dnl
+AC_BEFORE([$0], [LTDL_INIT])dnl
+m4_require([_LT_CHECK_BUILDDIR])dnl
+
+dnl Autoconf doesn't catch unexpanded LT_ macros by default:
+m4_pattern_forbid([^_?LT_[A-Z_]+$])dnl
+m4_pattern_allow([^(_LT_EOF|LT_DLGLOBAL|LT_DLLAZY_OR_NOW|LT_MULTI_MODULE)$])dnl
+dnl aclocal doesn't pull ltoptions.m4, ltsugar.m4, or ltversion.m4
+dnl unless we require an AC_DEFUNed macro:
+AC_REQUIRE([LTOPTIONS_VERSION])dnl
+AC_REQUIRE([LTSUGAR_VERSION])dnl
+AC_REQUIRE([LTVERSION_VERSION])dnl
+AC_REQUIRE([LTOBSOLETE_VERSION])dnl
+m4_require([_LT_PROG_LTMAIN])dnl
+
+_LT_SHELL_INIT([SHELL=${CONFIG_SHELL-/bin/sh}])
+
+dnl Parse OPTIONS
+_LT_SET_OPTIONS([$0], [$1])
+
+# This can be used to rebuild libtool when needed
+LIBTOOL_DEPS="$ltmain"
+
+# Always use our own libtool.
+LIBTOOL='$(SHELL) $(top_builddir)/libtool'
+AC_SUBST(LIBTOOL)dnl
+
+_LT_SETUP
+
+# Only expand once:
+m4_define([LT_INIT])
+])# LT_INIT
+
+# Old names:
+AU_ALIAS([AC_PROG_LIBTOOL], [LT_INIT])
+AU_ALIAS([AM_PROG_LIBTOOL], [LT_INIT])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_PROG_LIBTOOL], [])
+dnl AC_DEFUN([AM_PROG_LIBTOOL], [])
+
+
+# _LT_CC_BASENAME(CC)
+# -------------------
+# Calculate cc_basename.  Skip known compiler wrappers and cross-prefix.
+m4_defun([_LT_CC_BASENAME],
+[for cc_temp in $1""; do
+  case $cc_temp in
+    compile | *[[\\/]]compile | ccache | *[[\\/]]ccache ) ;;
+    distcc | *[[\\/]]distcc | purify | *[[\\/]]purify ) ;;
+    \-*) ;;
+    *) break;;
+  esac
+done
+cc_basename=`$ECHO "$cc_temp" | $SED "s%.*/%%; s%^$host_alias-%%"`
+])
+
+
+# _LT_FILEUTILS_DEFAULTS
+# ----------------------
+# It is okay to use these file commands and assume they have been set
+# sensibly after `m4_require([_LT_FILEUTILS_DEFAULTS])'.
+m4_defun([_LT_FILEUTILS_DEFAULTS],
+[: ${CP="cp -f"}
+: ${MV="mv -f"}
+: ${RM="rm -f"}
+])# _LT_FILEUTILS_DEFAULTS
+
+
+# _LT_SETUP
+# ---------
+m4_defun([_LT_SETUP],
+[AC_REQUIRE([AC_CANONICAL_HOST])dnl
+AC_REQUIRE([AC_CANONICAL_BUILD])dnl
+AC_REQUIRE([_LT_PREPARE_SED_QUOTE_VARS])dnl
+AC_REQUIRE([_LT_PROG_ECHO_BACKSLASH])dnl
+
+_LT_DECL([], [PATH_SEPARATOR], [1], [The PATH separator for the build system])dnl
+dnl
+_LT_DECL([], [host_alias], [0], [The host system])dnl
+_LT_DECL([], [host], [0])dnl
+_LT_DECL([], [host_os], [0])dnl
+dnl
+_LT_DECL([], [build_alias], [0], [The build system])dnl
+_LT_DECL([], [build], [0])dnl
+_LT_DECL([], [build_os], [0])dnl
+dnl
+AC_REQUIRE([AC_PROG_CC])dnl
+AC_REQUIRE([LT_PATH_LD])dnl
+AC_REQUIRE([LT_PATH_NM])dnl
+dnl
+AC_REQUIRE([AC_PROG_LN_S])dnl
+test -z "$LN_S" && LN_S="ln -s"
+_LT_DECL([], [LN_S], [1], [Whether we need soft or hard links])dnl
+dnl
+AC_REQUIRE([LT_CMD_MAX_LEN])dnl
+_LT_DECL([objext], [ac_objext], [0], [Object file suffix (normally "o")])dnl
+_LT_DECL([], [exeext], [0], [Executable file suffix (normally "")])dnl
+dnl
+m4_require([_LT_FILEUTILS_DEFAULTS])dnl
+m4_require([_LT_CHECK_SHELL_FEATURES])dnl
+m4_require([_LT_PATH_CONVERSION_FUNCTIONS])dnl
+m4_require([_LT_CMD_RELOAD])dnl
+m4_require([_LT_CHECK_MAGIC_METHOD])dnl
+m4_require([_LT_CHECK_SHAREDLIB_FROM_LINKLIB])dnl
+m4_require([_LT_CMD_OLD_ARCHIVE])dnl
+m4_require([_LT_CMD_GLOBAL_SYMBOLS])dnl
+m4_require([_LT_WITH_SYSROOT])dnl
+
+_LT_CONFIG_LIBTOOL_INIT([
+# See if we are running on zsh, and set the options which allow our
+# commands through without removal of \ escapes INIT.
+if test -n "\${ZSH_VERSION+set}" ; then
+   setopt NO_GLOB_SUBST
+fi
+])
+if test -n "${ZSH_VERSION+set}" ; then
+   setopt NO_GLOB_SUBST
+fi
+
+_LT_CHECK_OBJDIR
+
+m4_require([_LT_TAG_COMPILER])dnl
+
+case $host_os in
+aix3*)
+  # AIX sometimes has problems with the GCC collect2 program.  For some
+  # reason, if we set the COLLECT_NAMES environment variable, the problems
+  # vanish in a puff of smoke.
+  if test "X${COLLECT_NAMES+set}" != Xset; then
+    COLLECT_NAMES=
+    export COLLECT_NAMES
+  fi
+  ;;
+esac
+
+# Global variables:
+ofile=libtool
+can_build_shared=yes
+
+# All known linkers require a `.a' archive for static linking (except MSVC,
+# which needs '.lib').
+libext=a
+
+with_gnu_ld="$lt_cv_prog_gnu_ld"
+
+old_CC="$CC"
+old_CFLAGS="$CFLAGS"
+
+# Set sane defaults for various variables
+test -z "$CC" && CC=cc
+test -z "$LTCC" && LTCC=$CC
+test -z "$LTCFLAGS" && LTCFLAGS=$CFLAGS
+test -z "$LD" && LD=ld
+test -z "$ac_objext" && ac_objext=o
+
+_LT_CC_BASENAME([$compiler])
+
+# Only perform the check for file, if the check method requires it
+test -z "$MAGIC_CMD" && MAGIC_CMD=file
+case $deplibs_check_method in
+file_magic*)
+  if test "$file_magic_cmd" = '$MAGIC_CMD'; then
+    _LT_PATH_MAGIC
+  fi
+  ;;
+esac
+
+# Use C for the default configuration in the libtool script
+LT_SUPPORTED_TAG([CC])
+_LT_LANG_C_CONFIG
+_LT_LANG_DEFAULT_CONFIG
+_LT_CONFIG_COMMANDS
+])# _LT_SETUP
+
+
+# _LT_PREPARE_SED_QUOTE_VARS
+# --------------------------
+# Define a few sed substitution that help us do robust quoting.
+m4_defun([_LT_PREPARE_SED_QUOTE_VARS],
+[# Backslashify metacharacters that are still active within
+# double-quoted strings.
+sed_quote_subst='s/\([["`$\\]]\)/\\\1/g'
+
+# Same as above, but do not quote variable references.
+double_quote_subst='s/\([["`\\]]\)/\\\1/g'
+
+# Sed substitution to delay expansion of an escaped shell variable in a
+# double_quote_subst'ed string.
+delay_variable_subst='s/\\\\\\\\\\\$/\\\\\\$/g'
+
+# Sed substitution to delay expansion of an escaped single quote.
+delay_single_quote_subst='s/'\''/'\'\\\\\\\'\''/g'
+
+# Sed substitution to avoid accidental globbing in evaled expressions
+no_glob_subst='s/\*/\\\*/g'
+])
+
+# _LT_PROG_LTMAIN
+# ---------------
+# Note that this code is called both from `configure', and `config.status'
+# now that we use AC_CONFIG_COMMANDS to generate libtool.  Notably,
+# `config.status' has no value for ac_aux_dir unless we are using Automake,
+# so we pass a copy along to make sure it has a sensible value anyway.
+m4_defun([_LT_PROG_LTMAIN],
+[m4_ifdef([AC_REQUIRE_AUX_FILE], [AC_REQUIRE_AUX_FILE([ltmain.sh])])dnl
+_LT_CONFIG_LIBTOOL_INIT([ac_aux_dir='$ac_aux_dir'])
+ltmain="$ac_aux_dir/ltmain.sh"
+])# _LT_PROG_LTMAIN
+
+
+
+# So that we can recreate a full libtool script including additional
+# tags, we accumulate the chunks of code to send to AC_CONFIG_COMMANDS
+# in macros and then make a single call at the end using the `libtool'
+# label.
+
+
+# _LT_CONFIG_LIBTOOL_INIT([INIT-COMMANDS])
+# ----------------------------------------
+# Register INIT-COMMANDS to be passed to AC_CONFIG_COMMANDS later.
+m4_define([_LT_CONFIG_LIBTOOL_INIT],
+[m4_ifval([$1],
+          [m4_append([_LT_OUTPUT_LIBTOOL_INIT],
+                     [$1
+])])])
+
+# Initialize.
+m4_define([_LT_OUTPUT_LIBTOOL_INIT])
+
+
+# _LT_CONFIG_LIBTOOL([COMMANDS])
+# ------------------------------
+# Register COMMANDS to be passed to AC_CONFIG_COMMANDS later.
+m4_define([_LT_CONFIG_LIBTOOL],
+[m4_ifval([$1],
+          [m4_append([_LT_OUTPUT_LIBTOOL_COMMANDS],
+                     [$1
+])])])
+
+# Initialize.
+m4_define([_LT_OUTPUT_LIBTOOL_COMMANDS])
+
+
+# _LT_CONFIG_SAVE_COMMANDS([COMMANDS], [INIT_COMMANDS])
+# -----------------------------------------------------
+m4_defun([_LT_CONFIG_SAVE_COMMANDS],
+[_LT_CONFIG_LIBTOOL([$1])
+_LT_CONFIG_LIBTOOL_INIT([$2])
+])
+
+
+# _LT_FORMAT_COMMENT([COMMENT])
+# -----------------------------
+# Add leading comment marks to the start of each line, and a trailing
+# full-stop to the whole comment if one is not present already.
+m4_define([_LT_FORMAT_COMMENT],
+[m4_ifval([$1], [
+m4_bpatsubst([m4_bpatsubst([$1], [^ *], [# ])],
+              [['`$\]], [\\\&])]m4_bmatch([$1], [[!?.]$], [], [.])
+)])
+
+
+
+
+
+# _LT_DECL([CONFIGNAME], VARNAME, VALUE, [DESCRIPTION], [IS-TAGGED?])
+# -------------------------------------------------------------------
+# CONFIGNAME is the name given to the value in the libtool script.
+# VARNAME is the (base) name used in the configure script.
+# VALUE may be 0, 1 or 2 for a computed quote escaped value based on
+# VARNAME.  Any other value will be used directly.
+m4_define([_LT_DECL],
+[lt_if_append_uniq([lt_decl_varnames], [$2], [, ],
+    [lt_dict_add_subkey([lt_decl_dict], [$2], [libtool_name],
+       [m4_ifval([$1], [$1], [$2])])
+    lt_dict_add_subkey([lt_decl_dict], [$2], [value], [$3])
+    m4_ifval([$4],
+       [lt_dict_add_subkey([lt_decl_dict], [$2], [description], [$4])])
+    lt_dict_add_subkey([lt_decl_dict], [$2],
+       [tagged?], [m4_ifval([$5], [yes], [no])])])
+])
+
+
+# _LT_TAGDECL([CONFIGNAME], VARNAME, VALUE, [DESCRIPTION])
+# --------------------------------------------------------
+m4_define([_LT_TAGDECL], [_LT_DECL([$1], [$2], [$3], [$4], [yes])])
+
+
+# lt_decl_tag_varnames([SEPARATOR], [VARNAME1...])
+# ------------------------------------------------
+m4_define([lt_decl_tag_varnames],
+[_lt_decl_filter([tagged?], [yes], $@)])
+
+
+# _lt_decl_filter(SUBKEY, VALUE, [SEPARATOR], [VARNAME1..])
+# ---------------------------------------------------------
+m4_define([_lt_decl_filter],
+[m4_case([$#],
+  [0], [m4_fatal([$0: too few arguments: $#])],
+  [1], [m4_fatal([$0: too few arguments: $#: $1])],
+  [2], [lt_dict_filter([lt_decl_dict], [$1], [$2], [], lt_decl_varnames)],
+  [3], [lt_dict_filter([lt_decl_dict], [$1], [$2], [$3], lt_decl_varnames)],
+  [lt_dict_filter([lt_decl_dict], $@)])[]dnl
+])
+
+
+# lt_decl_quote_varnames([SEPARATOR], [VARNAME1...])
+# --------------------------------------------------
+m4_define([lt_decl_quote_varnames],
+[_lt_decl_filter([value], [1], $@)])
+
+
+# lt_decl_dquote_varnames([SEPARATOR], [VARNAME1...])
+# ---------------------------------------------------
+m4_define([lt_decl_dquote_varnames],
+[_lt_decl_filter([value], [2], $@)])
+
+
+# lt_decl_varnames_tagged([SEPARATOR], [VARNAME1...])
+# ---------------------------------------------------
+m4_define([lt_decl_varnames_tagged],
+[m4_assert([$# <= 2])dnl
+_$0(m4_quote(m4_default([$1], [[, ]])),
+    m4_ifval([$2], [[$2]], [m4_dquote(lt_decl_tag_varnames)]),
+    m4_split(m4_normalize(m4_quote(_LT_TAGS)), [ ]))])
+m4_define([_lt_decl_varnames_tagged],
+[m4_ifval([$3], [lt_combine([$1], [$2], [_], $3)])])
+
+
+# lt_decl_all_varnames([SEPARATOR], [VARNAME1...])
+# ------------------------------------------------
+m4_define([lt_decl_all_varnames],
+[_$0(m4_quote(m4_default([$1], [[, ]])),
+     m4_if([$2], [],
+          m4_quote(lt_decl_varnames),
+       m4_quote(m4_shift($@))))[]dnl
+])
+m4_define([_lt_decl_all_varnames],
+[lt_join($@, lt_decl_varnames_tagged([$1],
+                       lt_decl_tag_varnames([[, ]], m4_shift($@))))dnl
+])
+
+
+# _LT_CONFIG_STATUS_DECLARE([VARNAME])
+# ------------------------------------
+# Quote a variable value, and forward it to `config.status' so that its
+# declaration there will have the same value as in `configure'.  VARNAME
+# must have a single quote delimited value for this to work.
+m4_define([_LT_CONFIG_STATUS_DECLARE],
+[$1='`$ECHO "$][$1" | $SED "$delay_single_quote_subst"`'])
+
+
+# _LT_CONFIG_STATUS_DECLARATIONS
+# ------------------------------
+# We delimit libtool config variables with single quotes, so when
+# we write them to config.status, we have to be sure to quote all
+# embedded single quotes properly.  In configure, this macro expands
+# each variable declared with _LT_DECL (and _LT_TAGDECL) into:
+#
+#    <var>='`$ECHO "$<var>" | $SED "$delay_single_quote_subst"`'
+m4_defun([_LT_CONFIG_STATUS_DECLARATIONS],
+[m4_foreach([_lt_var], m4_quote(lt_decl_all_varnames),
+    [m4_n([_LT_CONFIG_STATUS_DECLARE(_lt_var)])])])
+
+
+# _LT_LIBTOOL_TAGS
+# ----------------
+# Output comment and list of tags supported by the script
+m4_defun([_LT_LIBTOOL_TAGS],
+[_LT_FORMAT_COMMENT([The names of the tagged configurations supported by this script])dnl
+available_tags="_LT_TAGS"dnl
+])
+
+
+# _LT_LIBTOOL_DECLARE(VARNAME, [TAG])
+# -----------------------------------
+# Extract the dictionary values for VARNAME (optionally with TAG) and
+# expand to a commented shell variable setting:
+#
+#    # Some comment about what VAR is for.
+#    visible_name=$lt_internal_name
+m4_define([_LT_LIBTOOL_DECLARE],
+[_LT_FORMAT_COMMENT(m4_quote(lt_dict_fetch([lt_decl_dict], [$1],
+                                          [description])))[]dnl
+m4_pushdef([_libtool_name],
+    m4_quote(lt_dict_fetch([lt_decl_dict], [$1], [libtool_name])))[]dnl
+m4_case(m4_quote(lt_dict_fetch([lt_decl_dict], [$1], [value])),
+    [0], [_libtool_name=[$]$1],
+    [1], [_libtool_name=$lt_[]$1],
+    [2], [_libtool_name=$lt_[]$1],
+    [_libtool_name=lt_dict_fetch([lt_decl_dict], [$1], [value])])[]dnl
+m4_ifval([$2], [_$2])[]m4_popdef([_libtool_name])[]dnl
+])
+
+
+# _LT_LIBTOOL_CONFIG_VARS
+# -----------------------
+# Produce commented declarations of non-tagged libtool config variables
+# suitable for insertion in the LIBTOOL CONFIG section of the `libtool'
+# script.  Tagged libtool config variables (even for the LIBTOOL CONFIG
+# section) are produced by _LT_LIBTOOL_TAG_VARS.
+m4_defun([_LT_LIBTOOL_CONFIG_VARS],
+[m4_foreach([_lt_var],
+    m4_quote(_lt_decl_filter([tagged?], [no], [], lt_decl_varnames)),
+    [m4_n([_LT_LIBTOOL_DECLARE(_lt_var)])])])
+
+
+# _LT_LIBTOOL_TAG_VARS(TAG)
+# -------------------------
+m4_define([_LT_LIBTOOL_TAG_VARS],
+[m4_foreach([_lt_var], m4_quote(lt_decl_tag_varnames),
+    [m4_n([_LT_LIBTOOL_DECLARE(_lt_var, [$1])])])])
+
+
+# _LT_TAGVAR(VARNAME, [TAGNAME])
+# ------------------------------
+m4_define([_LT_TAGVAR], [m4_ifval([$2], [$1_$2], [$1])])
+
+
+# _LT_CONFIG_COMMANDS
+# -------------------
+# Send accumulated output to $CONFIG_STATUS.  Thanks to the lists of
+# variables for single and double quote escaping we saved from calls
+# to _LT_DECL, we can put quote escaped variables declarations
+# into `config.status', and then the shell code to quote escape them in
+# for loops in `config.status'.  Finally, any additional code accumulated
+# from calls to _LT_CONFIG_LIBTOOL_INIT is expanded.
+m4_defun([_LT_CONFIG_COMMANDS],
+[AC_PROVIDE_IFELSE([LT_OUTPUT],
+       dnl If the libtool generation code has been placed in $CONFIG_LT,
+       dnl instead of duplicating it all over again into config.status,
+       dnl then we will have config.status run $CONFIG_LT later, so it
+       dnl needs to know what name is stored there:
+        [AC_CONFIG_COMMANDS([libtool],
+            [$SHELL $CONFIG_LT || AS_EXIT(1)], [CONFIG_LT='$CONFIG_LT'])],
+    dnl If the libtool generation code is destined for config.status,
+    dnl expand the accumulated commands and init code now:
+    [AC_CONFIG_COMMANDS([libtool],
+        [_LT_OUTPUT_LIBTOOL_COMMANDS], [_LT_OUTPUT_LIBTOOL_COMMANDS_INIT])])
+])#_LT_CONFIG_COMMANDS
+
+
+# Initialize.
+m4_define([_LT_OUTPUT_LIBTOOL_COMMANDS_INIT],
+[
+
+# The HP-UX ksh and POSIX shell print the target directory to stdout
+# if CDPATH is set.
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+
+sed_quote_subst='$sed_quote_subst'
+double_quote_subst='$double_quote_subst'
+delay_variable_subst='$delay_variable_subst'
+_LT_CONFIG_STATUS_DECLARATIONS
+LTCC='$LTCC'
+LTCFLAGS='$LTCFLAGS'
+compiler='$compiler_DEFAULT'
+
+# A function that is used when there is no print builtin or printf.
+func_fallback_echo ()
+{
+  eval 'cat <<_LTECHO_EOF
+\$[]1
+_LTECHO_EOF'
+}
+
+# Quote evaled strings.
+for var in lt_decl_all_varnames([[ \
+]], lt_decl_quote_varnames); do
+    case \`eval \\\\\$ECHO \\\\""\\\\\$\$var"\\\\"\` in
+    *[[\\\\\\\`\\"\\\$]]*)
+      eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"\\\$\$var\\" | \\\$SED \\"\\\$sed_quote_subst\\"\\\`\\\\\\""
+      ;;
+    *)
+      eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\""
+      ;;
+    esac
+done
+
+# Double-quote double-evaled strings.
+for var in lt_decl_all_varnames([[ \
+]], lt_decl_dquote_varnames); do
+    case \`eval \\\\\$ECHO \\\\""\\\\\$\$var"\\\\"\` in
+    *[[\\\\\\\`\\"\\\$]]*)
+      eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"\\\$\$var\\" | \\\$SED -e \\"\\\$double_quote_subst\\" -e \\"\\\$sed_quote_subst\\" -e \\"\\\$delay_variable_subst\\"\\\`\\\\\\""
+      ;;
+    *)
+      eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\""
+      ;;
+    esac
+done
+
+_LT_OUTPUT_LIBTOOL_INIT
+])
+
+# _LT_GENERATED_FILE_INIT(FILE, [COMMENT])
+# ------------------------------------
+# Generate a child script FILE with all initialization necessary to
+# reuse the environment learned by the parent script, and make the
+# file executable.  If COMMENT is supplied, it is inserted after the
+# `#!' sequence but before initialization text begins.  After this
+# macro, additional text can be appended to FILE to form the body of
+# the child script.  The macro ends with non-zero status if the
+# file could not be fully written (such as if the disk is full).
+m4_ifdef([AS_INIT_GENERATED],
+[m4_defun([_LT_GENERATED_FILE_INIT],[AS_INIT_GENERATED($@)])],
+[m4_defun([_LT_GENERATED_FILE_INIT],
+[m4_require([AS_PREPARE])]dnl
+[m4_pushdef([AS_MESSAGE_LOG_FD])]dnl
+[lt_write_fail=0
+cat >$1 <<_ASEOF || lt_write_fail=1
+#! $SHELL
+# Generated by $as_me.
+$2
+SHELL=\${CONFIG_SHELL-$SHELL}
+export SHELL
+_ASEOF
+cat >>$1 <<\_ASEOF || lt_write_fail=1
+AS_SHELL_SANITIZE
+_AS_PREPARE
+exec AS_MESSAGE_FD>&1
+_ASEOF
+test $lt_write_fail = 0 && chmod +x $1[]dnl
+m4_popdef([AS_MESSAGE_LOG_FD])])])# _LT_GENERATED_FILE_INIT
+
+# LT_OUTPUT
+# ---------
+# This macro allows early generation of the libtool script (before
+# AC_OUTPUT is called), incase it is used in configure for compilation
+# tests.
+AC_DEFUN([LT_OUTPUT],
+[: ${CONFIG_LT=./config.lt}
+AC_MSG_NOTICE([creating $CONFIG_LT])
+_LT_GENERATED_FILE_INIT(["$CONFIG_LT"],
+[# Run this file to recreate a libtool stub with the current configuration.])
+
+cat >>"$CONFIG_LT" <<\_LTEOF
+lt_cl_silent=false
+exec AS_MESSAGE_LOG_FD>>config.log
+{
+  echo
+  AS_BOX([Running $as_me.])
+} >&AS_MESSAGE_LOG_FD
+
+lt_cl_help="\
+\`$as_me' creates a local libtool stub from the current configuration,
+for use in further configure time tests before the real libtool is
+generated.
+
+Usage: $[0] [[OPTIONS]]
+
+  -h, --help      print this help, then exit
+  -V, --version   print version number, then exit
+  -q, --quiet     do not print progress messages
+  -d, --debug     don't remove temporary files
+
+Report bugs to <bug-libtool@gnu.org>."
+
+lt_cl_version="\
+m4_ifset([AC_PACKAGE_NAME], [AC_PACKAGE_NAME ])config.lt[]dnl
+m4_ifset([AC_PACKAGE_VERSION], [ AC_PACKAGE_VERSION])
+configured by $[0], generated by m4_PACKAGE_STRING.
+
+Copyright (C) 2011 Free Software Foundation, Inc.
+This config.lt script is free software; the Free Software Foundation
+gives unlimited permision to copy, distribute and modify it."
+
+while test $[#] != 0
+do
+  case $[1] in
+    --version | --v* | -V )
+      echo "$lt_cl_version"; exit 0 ;;
+    --help | --h* | -h )
+      echo "$lt_cl_help"; exit 0 ;;
+    --debug | --d* | -d )
+      debug=: ;;
+    --quiet | --q* | --silent | --s* | -q )
+      lt_cl_silent=: ;;
+
+    -*) AC_MSG_ERROR([unrecognized option: $[1]
+Try \`$[0] --help' for more information.]) ;;
+
+    *) AC_MSG_ERROR([unrecognized argument: $[1]
+Try \`$[0] --help' for more information.]) ;;
+  esac
+  shift
+done
+
+if $lt_cl_silent; then
+  exec AS_MESSAGE_FD>/dev/null
+fi
+_LTEOF
+
+cat >>"$CONFIG_LT" <<_LTEOF
+_LT_OUTPUT_LIBTOOL_COMMANDS_INIT
+_LTEOF
+
+cat >>"$CONFIG_LT" <<\_LTEOF
+AC_MSG_NOTICE([creating $ofile])
+_LT_OUTPUT_LIBTOOL_COMMANDS
+AS_EXIT(0)
+_LTEOF
+chmod +x "$CONFIG_LT"
+
+# configure is writing to config.log, but config.lt does its own redirection,
+# appending to config.log, which fails on DOS, as config.log is still kept
+# open by configure.  Here we exec the FD to /dev/null, effectively closing
+# config.log, so it can be properly (re)opened and appended to by config.lt.
+lt_cl_success=:
+test "$silent" = yes &&
+  lt_config_lt_args="$lt_config_lt_args --quiet"
+exec AS_MESSAGE_LOG_FD>/dev/null
+$SHELL "$CONFIG_LT" $lt_config_lt_args || lt_cl_success=false
+exec AS_MESSAGE_LOG_FD>>config.log
+$lt_cl_success || AS_EXIT(1)
+])# LT_OUTPUT
+
+
+# _LT_CONFIG(TAG)
+# ---------------
+# If TAG is the built-in tag, create an initial libtool script with a
+# default configuration from the untagged config vars.  Otherwise add code
+# to config.status for appending the configuration named by TAG from the
+# matching tagged config vars.
+m4_defun([_LT_CONFIG],
+[m4_require([_LT_FILEUTILS_DEFAULTS])dnl
+_LT_CONFIG_SAVE_COMMANDS([
+  m4_define([_LT_TAG], m4_if([$1], [], [C], [$1]))dnl
+  m4_if(_LT_TAG, [C], [
+    # See if we are running on zsh, and set the options which allow our
+    # commands through without removal of \ escapes.
+    if test -n "${ZSH_VERSION+set}" ; then
+      setopt NO_GLOB_SUBST
+    fi
+
+    cfgfile="${ofile}T"
+    trap "$RM \"$cfgfile\"; exit 1" 1 2 15
+    $RM "$cfgfile"
+
+    cat <<_LT_EOF >> "$cfgfile"
+#! $SHELL
+
+# `$ECHO "$ofile" | sed 's%^.*/%%'` - Provide generalized library-building support services.
+# Generated automatically by $as_me ($PACKAGE$TIMESTAMP) $VERSION
+# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`:
+# NOTE: Changes made to this file will be lost: look at ltmain.sh.
+#
+_LT_COPYING
+_LT_LIBTOOL_TAGS
+
+# ### BEGIN LIBTOOL CONFIG
+_LT_LIBTOOL_CONFIG_VARS
+_LT_LIBTOOL_TAG_VARS
+# ### END LIBTOOL CONFIG
+
+_LT_EOF
+
+  case $host_os in
+  aix3*)
+    cat <<\_LT_EOF >> "$cfgfile"
+# AIX sometimes has problems with the GCC collect2 program.  For some
+# reason, if we set the COLLECT_NAMES environment variable, the problems
+# vanish in a puff of smoke.
+if test "X${COLLECT_NAMES+set}" != Xset; then
+  COLLECT_NAMES=
+  export COLLECT_NAMES
+fi
+_LT_EOF
+    ;;
+  esac
+
+  _LT_PROG_LTMAIN
+
+  # We use sed instead of cat because bash on DJGPP gets confused if
+  # if finds mixed CR/LF and LF-only lines.  Since sed operates in
+  # text mode, it properly converts lines to CR/LF.  This bash problem
+  # is reportedly fixed, but why not run on old versions too?
+  sed '$q' "$ltmain" >> "$cfgfile" \
+     || (rm -f "$cfgfile"; exit 1)
+
+  _LT_PROG_REPLACE_SHELLFNS
+
+   mv -f "$cfgfile" "$ofile" ||
+    (rm -f "$ofile" && cp "$cfgfile" "$ofile" && rm -f "$cfgfile")
+  chmod +x "$ofile"
+],
+[cat <<_LT_EOF >> "$ofile"
+
+dnl Unfortunately we have to use $1 here, since _LT_TAG is not expanded
+dnl in a comment (ie after a #).
+# ### BEGIN LIBTOOL TAG CONFIG: $1
+_LT_LIBTOOL_TAG_VARS(_LT_TAG)
+# ### END LIBTOOL TAG CONFIG: $1
+_LT_EOF
+])dnl /m4_if
+],
+[m4_if([$1], [], [
+    PACKAGE='$PACKAGE'
+    VERSION='$VERSION'
+    TIMESTAMP='$TIMESTAMP'
+    RM='$RM'
+    ofile='$ofile'], [])
+])dnl /_LT_CONFIG_SAVE_COMMANDS
+])# _LT_CONFIG
+
+
+# LT_SUPPORTED_TAG(TAG)
+# ---------------------
+# Trace this macro to discover what tags are supported by the libtool
+# --tag option, using:
+#    autoconf --trace 'LT_SUPPORTED_TAG:$1'
+AC_DEFUN([LT_SUPPORTED_TAG], [])
+
+
+# C support is built-in for now
+m4_define([_LT_LANG_C_enabled], [])
+m4_define([_LT_TAGS], [])
+
+
+# LT_LANG(LANG)
+# -------------
+# Enable libtool support for the given language if not already enabled.
+AC_DEFUN([LT_LANG],
+[AC_BEFORE([$0], [LT_OUTPUT])dnl
+m4_case([$1],
+  [C],                 [_LT_LANG(C)],
+  [C++],               [_LT_LANG(CXX)],
+  [Go],                        [_LT_LANG(GO)],
+  [Java],              [_LT_LANG(GCJ)],
+  [Fortran 77],                [_LT_LANG(F77)],
+  [Fortran],           [_LT_LANG(FC)],
+  [Windows Resource],  [_LT_LANG(RC)],
+  [m4_ifdef([_LT_LANG_]$1[_CONFIG],
+    [_LT_LANG($1)],
+    [m4_fatal([$0: unsupported language: "$1"])])])dnl
+])# LT_LANG
+
+
+# _LT_LANG(LANGNAME)
+# ------------------
+m4_defun([_LT_LANG],
+[m4_ifdef([_LT_LANG_]$1[_enabled], [],
+  [LT_SUPPORTED_TAG([$1])dnl
+  m4_append([_LT_TAGS], [$1 ])dnl
+  m4_define([_LT_LANG_]$1[_enabled], [])dnl
+  _LT_LANG_$1_CONFIG($1)])dnl
+])# _LT_LANG
+
+
+m4_ifndef([AC_PROG_GO], [
+# NOTE: This macro has been submitted for inclusion into   #
+#  GNU Autoconf as AC_PROG_GO.  When it is available in    #
+#  a released version of Autoconf we should remove this    #
+#  macro and use it instead.                               #
+m4_defun([AC_PROG_GO],
+[AC_LANG_PUSH(Go)dnl
+AC_ARG_VAR([GOC],     [Go compiler command])dnl
+AC_ARG_VAR([GOFLAGS], [Go compiler flags])dnl
+_AC_ARG_VAR_LDFLAGS()dnl
+AC_CHECK_TOOL(GOC, gccgo)
+if test -z "$GOC"; then
+  if test -n "$ac_tool_prefix"; then
+    AC_CHECK_PROG(GOC, [${ac_tool_prefix}gccgo], [${ac_tool_prefix}gccgo])
+  fi
+fi
+if test -z "$GOC"; then
+  AC_CHECK_PROG(GOC, gccgo, gccgo, false)
+fi
+])#m4_defun
+])#m4_ifndef
+
+
+# _LT_LANG_DEFAULT_CONFIG
+# -----------------------
+m4_defun([_LT_LANG_DEFAULT_CONFIG],
+[AC_PROVIDE_IFELSE([AC_PROG_CXX],
+  [LT_LANG(CXX)],
+  [m4_define([AC_PROG_CXX], defn([AC_PROG_CXX])[LT_LANG(CXX)])])
+
+AC_PROVIDE_IFELSE([AC_PROG_F77],
+  [LT_LANG(F77)],
+  [m4_define([AC_PROG_F77], defn([AC_PROG_F77])[LT_LANG(F77)])])
+
+AC_PROVIDE_IFELSE([AC_PROG_FC],
+  [LT_LANG(FC)],
+  [m4_define([AC_PROG_FC], defn([AC_PROG_FC])[LT_LANG(FC)])])
+
+dnl The call to [A][M_PROG_GCJ] is quoted like that to stop aclocal
+dnl pulling things in needlessly.
+AC_PROVIDE_IFELSE([AC_PROG_GCJ],
+  [LT_LANG(GCJ)],
+  [AC_PROVIDE_IFELSE([A][M_PROG_GCJ],
+    [LT_LANG(GCJ)],
+    [AC_PROVIDE_IFELSE([LT_PROG_GCJ],
+      [LT_LANG(GCJ)],
+      [m4_ifdef([AC_PROG_GCJ],
+       [m4_define([AC_PROG_GCJ], defn([AC_PROG_GCJ])[LT_LANG(GCJ)])])
+       m4_ifdef([A][M_PROG_GCJ],
+       [m4_define([A][M_PROG_GCJ], defn([A][M_PROG_GCJ])[LT_LANG(GCJ)])])
+       m4_ifdef([LT_PROG_GCJ],
+       [m4_define([LT_PROG_GCJ], defn([LT_PROG_GCJ])[LT_LANG(GCJ)])])])])])
+
+AC_PROVIDE_IFELSE([AC_PROG_GO],
+  [LT_LANG(GO)],
+  [m4_define([AC_PROG_GO], defn([AC_PROG_GO])[LT_LANG(GO)])])
+
+AC_PROVIDE_IFELSE([LT_PROG_RC],
+  [LT_LANG(RC)],
+  [m4_define([LT_PROG_RC], defn([LT_PROG_RC])[LT_LANG(RC)])])
+])# _LT_LANG_DEFAULT_CONFIG
+
+# Obsolete macros:
+AU_DEFUN([AC_LIBTOOL_CXX], [LT_LANG(C++)])
+AU_DEFUN([AC_LIBTOOL_F77], [LT_LANG(Fortran 77)])
+AU_DEFUN([AC_LIBTOOL_FC], [LT_LANG(Fortran)])
+AU_DEFUN([AC_LIBTOOL_GCJ], [LT_LANG(Java)])
+AU_DEFUN([AC_LIBTOOL_RC], [LT_LANG(Windows Resource)])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_LIBTOOL_CXX], [])
+dnl AC_DEFUN([AC_LIBTOOL_F77], [])
+dnl AC_DEFUN([AC_LIBTOOL_FC], [])
+dnl AC_DEFUN([AC_LIBTOOL_GCJ], [])
+dnl AC_DEFUN([AC_LIBTOOL_RC], [])
+
+
+# _LT_TAG_COMPILER
+# ----------------
+m4_defun([_LT_TAG_COMPILER],
+[AC_REQUIRE([AC_PROG_CC])dnl
+
+_LT_DECL([LTCC], [CC], [1], [A C compiler])dnl
+_LT_DECL([LTCFLAGS], [CFLAGS], [1], [LTCC compiler flags])dnl
+_LT_TAGDECL([CC], [compiler], [1], [A language specific compiler])dnl
+_LT_TAGDECL([with_gcc], [GCC], [0], [Is the compiler the GNU compiler?])dnl
+
+# If no C compiler was specified, use CC.
+LTCC=${LTCC-"$CC"}
+
+# If no C compiler flags were specified, use CFLAGS.
+LTCFLAGS=${LTCFLAGS-"$CFLAGS"}
+
+# Allow CC to be a program name with arguments.
+compiler=$CC
+])# _LT_TAG_COMPILER
+
+
+# _LT_COMPILER_BOILERPLATE
+# ------------------------
+# Check for compiler boilerplate output or warnings with
+# the simple compiler test code.
+m4_defun([_LT_COMPILER_BOILERPLATE],
+[m4_require([_LT_DECL_SED])dnl
+ac_outfile=conftest.$ac_objext
+echo "$lt_simple_compile_test_code" >conftest.$ac_ext
+eval "$ac_compile" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err
+_lt_compiler_boilerplate=`cat conftest.err`
+$RM conftest*
+])# _LT_COMPILER_BOILERPLATE
+
+
+# _LT_LINKER_BOILERPLATE
+# ----------------------
+# Check for linker boilerplate output or warnings with
+# the simple link test code.
+m4_defun([_LT_LINKER_BOILERPLATE],
+[m4_require([_LT_DECL_SED])dnl
+ac_outfile=conftest.$ac_objext
+echo "$lt_simple_link_test_code" >conftest.$ac_ext
+eval "$ac_link" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err
+_lt_linker_boilerplate=`cat conftest.err`
+$RM -r conftest*
+])# _LT_LINKER_BOILERPLATE
+
+# _LT_REQUIRED_DARWIN_CHECKS
+# -------------------------
+m4_defun_once([_LT_REQUIRED_DARWIN_CHECKS],[
+  case $host_os in
+    rhapsody* | darwin*)
+    AC_CHECK_TOOL([DSYMUTIL], [dsymutil], [:])
+    AC_CHECK_TOOL([NMEDIT], [nmedit], [:])
+    AC_CHECK_TOOL([LIPO], [lipo], [:])
+    AC_CHECK_TOOL([OTOOL], [otool], [:])
+    AC_CHECK_TOOL([OTOOL64], [otool64], [:])
+    _LT_DECL([], [DSYMUTIL], [1],
+      [Tool to manipulate archived DWARF debug symbol files on Mac OS X])
+    _LT_DECL([], [NMEDIT], [1],
+      [Tool to change global to local symbols on Mac OS X])
+    _LT_DECL([], [LIPO], [1],
+      [Tool to manipulate fat objects and archives on Mac OS X])
+    _LT_DECL([], [OTOOL], [1],
+      [ldd/readelf like tool for Mach-O binaries on Mac OS X])
+    _LT_DECL([], [OTOOL64], [1],
+      [ldd/readelf like tool for 64 bit Mach-O binaries on Mac OS X 10.4])
+
+    AC_CACHE_CHECK([for -single_module linker flag],[lt_cv_apple_cc_single_mod],
+      [lt_cv_apple_cc_single_mod=no
+      if test -z "${LT_MULTI_MODULE}"; then
+       # By default we will add the -single_module flag. You can override
+       # by either setting the environment variable LT_MULTI_MODULE
+       # non-empty at configure time, or by adding -multi_module to the
+       # link flags.
+       rm -rf libconftest.dylib*
+       echo "int foo(void){return 1;}" > conftest.c
+       echo "$LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \
+-dynamiclib -Wl,-single_module conftest.c" >&AS_MESSAGE_LOG_FD
+       $LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \
+         -dynamiclib -Wl,-single_module conftest.c 2>conftest.err
+        _lt_result=$?
+       # If there is a non-empty error log, and "single_module"
+       # appears in it, assume the flag caused a linker warning
+        if test -s conftest.err && $GREP single_module conftest.err; then
+         cat conftest.err >&AS_MESSAGE_LOG_FD
+       # Otherwise, if the output was created with a 0 exit code from
+       # the compiler, it worked.
+       elif test -f libconftest.dylib && test $_lt_result -eq 0; then
+         lt_cv_apple_cc_single_mod=yes
+       else
+         cat conftest.err >&AS_MESSAGE_LOG_FD
+       fi
+       rm -rf libconftest.dylib*
+       rm -f conftest.*
+      fi])
+
+    AC_CACHE_CHECK([for -exported_symbols_list linker flag],
+      [lt_cv_ld_exported_symbols_list],
+      [lt_cv_ld_exported_symbols_list=no
+      save_LDFLAGS=$LDFLAGS
+      echo "_main" > conftest.sym
+      LDFLAGS="$LDFLAGS -Wl,-exported_symbols_list,conftest.sym"
+      AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])],
+       [lt_cv_ld_exported_symbols_list=yes],
+       [lt_cv_ld_exported_symbols_list=no])
+       LDFLAGS="$save_LDFLAGS"
+    ])
+
+    AC_CACHE_CHECK([for -force_load linker flag],[lt_cv_ld_force_load],
+      [lt_cv_ld_force_load=no
+      cat > conftest.c << _LT_EOF
+int forced_loaded() { return 2;}
+_LT_EOF
+      echo "$LTCC $LTCFLAGS -c -o conftest.o conftest.c" >&AS_MESSAGE_LOG_FD
+      $LTCC $LTCFLAGS -c -o conftest.o conftest.c 2>&AS_MESSAGE_LOG_FD
+      echo "$AR cru libconftest.a conftest.o" >&AS_MESSAGE_LOG_FD
+      $AR cru libconftest.a conftest.o 2>&AS_MESSAGE_LOG_FD
+      echo "$RANLIB libconftest.a" >&AS_MESSAGE_LOG_FD
+      $RANLIB libconftest.a 2>&AS_MESSAGE_LOG_FD
+      cat > conftest.c << _LT_EOF
+int main() { return 0;}
+_LT_EOF
+      echo "$LTCC $LTCFLAGS $LDFLAGS -o conftest conftest.c -Wl,-force_load,./libconftest.a" >&AS_MESSAGE_LOG_FD
+      $LTCC $LTCFLAGS $LDFLAGS -o conftest conftest.c -Wl,-force_load,./libconftest.a 2>conftest.err
+      _lt_result=$?
+      if test -s conftest.err && $GREP force_load conftest.err; then
+       cat conftest.err >&AS_MESSAGE_LOG_FD
+      elif test -f conftest && test $_lt_result -eq 0 && $GREP forced_load conftest >/dev/null 2>&1 ; then
+       lt_cv_ld_force_load=yes
+      else
+       cat conftest.err >&AS_MESSAGE_LOG_FD
+      fi
+        rm -f conftest.err libconftest.a conftest conftest.c
+        rm -rf conftest.dSYM
+    ])
+    case $host_os in
+    rhapsody* | darwin1.[[012]])
+      _lt_dar_allow_undefined='${wl}-undefined ${wl}suppress' ;;
+    darwin1.*)
+      _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;;
+    darwin*) # darwin 5.x on
+      # if running on 10.5 or later, the deployment target defaults
+      # to the OS version, if on x86, and 10.4, the deployment
+      # target defaults to 10.4. Don't you love it?
+      case ${MACOSX_DEPLOYMENT_TARGET-10.0},$host in
+       10.0,*86*-darwin8*|10.0,*-darwin[[91]]*)
+         _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;;
+       10.[[012]]*)
+         _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;;
+       10.*)
+         _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;;
+      esac
+    ;;
+  esac
+    if test "$lt_cv_apple_cc_single_mod" = "yes"; then
+      _lt_dar_single_mod='$single_module'
+    fi
+    if test "$lt_cv_ld_exported_symbols_list" = "yes"; then
+      _lt_dar_export_syms=' ${wl}-exported_symbols_list,$output_objdir/${libname}-symbols.expsym'
+    else
+      _lt_dar_export_syms='~$NMEDIT -s $output_objdir/${libname}-symbols.expsym ${lib}'
+    fi
+    if test "$DSYMUTIL" != ":" && test "$lt_cv_ld_force_load" = "no"; then
+      _lt_dsymutil='~$DSYMUTIL $lib || :'
+    else
+      _lt_dsymutil=
+    fi
+    ;;
+  esac
+])
+
+
+# _LT_DARWIN_LINKER_FEATURES([TAG])
+# ---------------------------------
+# Checks for linker and compiler features on darwin
+m4_defun([_LT_DARWIN_LINKER_FEATURES],
+[
+  m4_require([_LT_REQUIRED_DARWIN_CHECKS])
+  _LT_TAGVAR(archive_cmds_need_lc, $1)=no
+  _LT_TAGVAR(hardcode_direct, $1)=no
+  _LT_TAGVAR(hardcode_automatic, $1)=yes
+  _LT_TAGVAR(hardcode_shlibpath_var, $1)=unsupported
+  if test "$lt_cv_ld_force_load" = "yes"; then
+    _LT_TAGVAR(whole_archive_flag_spec, $1)='`for conv in $convenience\"\"; do test  -n \"$conv\" && new_convenience=\"$new_convenience ${wl}-force_load,$conv\"; done; func_echo_all \"$new_convenience\"`'
+    m4_case([$1], [F77], [_LT_TAGVAR(compiler_needs_object, $1)=yes],
+                  [FC],  [_LT_TAGVAR(compiler_needs_object, $1)=yes])
+  else
+    _LT_TAGVAR(whole_archive_flag_spec, $1)=''
+  fi
+  _LT_TAGVAR(link_all_deplibs, $1)=yes
+  _LT_TAGVAR(allow_undefined_flag, $1)="$_lt_dar_allow_undefined"
+  case $cc_basename in
+     ifort*) _lt_dar_can_shared=yes ;;
+     *) _lt_dar_can_shared=$GCC ;;
+  esac
+  if test "$_lt_dar_can_shared" = "yes"; then
+    output_verbose_link_cmd=func_echo_all
+    _LT_TAGVAR(archive_cmds, $1)="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}"
+    _LT_TAGVAR(module_cmds, $1)="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}"
+    _LT_TAGVAR(archive_expsym_cmds, $1)="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}"
+    _LT_TAGVAR(module_expsym_cmds, $1)="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}"
+    m4_if([$1], [CXX],
+[   if test "$lt_cv_apple_cc_single_mod" != "yes"; then
+      _LT_TAGVAR(archive_cmds, $1)="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}"
+      _LT_TAGVAR(archive_expsym_cmds, $1)="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dar_export_syms}${_lt_dsymutil}"
+    fi
+],[])
+  else
+  _LT_TAGVAR(ld_shlibs, $1)=no
+  fi
+])
+
+# _LT_SYS_MODULE_PATH_AIX([TAGNAME])
+# ----------------------------------
+# Links a minimal program and checks the executable
+# for the system default hardcoded library path. In most cases,
+# this is /usr/lib:/lib, but when the MPI compilers are used
+# the location of the communication and MPI libs are included too.
+# If we don't find anything, use the default library path according
+# to the aix ld manual.
+# Store the results from the different compilers for each TAGNAME.
+# Allow to override them for all tags through lt_cv_aix_libpath.
+m4_defun([_LT_SYS_MODULE_PATH_AIX],
+[m4_require([_LT_DECL_SED])dnl
+if test "${lt_cv_aix_libpath+set}" = set; then
+  aix_libpath=$lt_cv_aix_libpath
+else
+  AC_CACHE_VAL([_LT_TAGVAR([lt_cv_aix_libpath_], [$1])],
+  [AC_LINK_IFELSE([AC_LANG_PROGRAM],[
+  lt_aix_libpath_sed='[
+      /Import File Strings/,/^$/ {
+         /^0/ {
+             s/^0  *\([^ ]*\) *$/\1/
+             p
+         }
+      }]'
+  _LT_TAGVAR([lt_cv_aix_libpath_], [$1])=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
+  # Check for a 64-bit object if we didn't find anything.
+  if test -z "$_LT_TAGVAR([lt_cv_aix_libpath_], [$1])"; then
+    _LT_TAGVAR([lt_cv_aix_libpath_], [$1])=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
+  fi],[])
+  if test -z "$_LT_TAGVAR([lt_cv_aix_libpath_], [$1])"; then
+    _LT_TAGVAR([lt_cv_aix_libpath_], [$1])="/usr/lib:/lib"
+  fi
+  ])
+  aix_libpath=$_LT_TAGVAR([lt_cv_aix_libpath_], [$1])
+fi
+])# _LT_SYS_MODULE_PATH_AIX
+
+
+# _LT_SHELL_INIT(ARG)
+# -------------------
+m4_define([_LT_SHELL_INIT],
+[m4_divert_text([M4SH-INIT], [$1
+])])# _LT_SHELL_INIT
+
+
+
+# _LT_PROG_ECHO_BACKSLASH
+# -----------------------
+# Find how we can fake an echo command that does not interpret backslash.
+# In particular, with Autoconf 2.60 or later we add some code to the start
+# of the generated configure script which will find a shell with a builtin
+# printf (which we can use as an echo command).
+m4_defun([_LT_PROG_ECHO_BACKSLASH],
+[ECHO='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'
+ECHO=$ECHO$ECHO$ECHO$ECHO$ECHO
+ECHO=$ECHO$ECHO$ECHO$ECHO$ECHO$ECHO
+
+AC_MSG_CHECKING([how to print strings])
+# Test print first, because it will be a builtin if present.
+if test "X`( print -r -- -n ) 2>/dev/null`" = X-n && \
+   test "X`print -r -- $ECHO 2>/dev/null`" = "X$ECHO"; then
+  ECHO='print -r --'
+elif test "X`printf %s $ECHO 2>/dev/null`" = "X$ECHO"; then
+  ECHO='printf %s\n'
+else
+  # Use this function as a fallback that always works.
+  func_fallback_echo ()
+  {
+    eval 'cat <<_LTECHO_EOF
+$[]1
+_LTECHO_EOF'
+  }
+  ECHO='func_fallback_echo'
+fi
+
+# func_echo_all arg...
+# Invoke $ECHO with all args, space-separated.
+func_echo_all ()
+{
+    $ECHO "$*" 
+}
+
+case "$ECHO" in
+  printf*) AC_MSG_RESULT([printf]) ;;
+  print*) AC_MSG_RESULT([print -r]) ;;
+  *) AC_MSG_RESULT([cat]) ;;
+esac
+
+m4_ifdef([_AS_DETECT_SUGGESTED],
+[_AS_DETECT_SUGGESTED([
+  test -n "${ZSH_VERSION+set}${BASH_VERSION+set}" || (
+    ECHO='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'
+    ECHO=$ECHO$ECHO$ECHO$ECHO$ECHO
+    ECHO=$ECHO$ECHO$ECHO$ECHO$ECHO$ECHO
+    PATH=/empty FPATH=/empty; export PATH FPATH
+    test "X`printf %s $ECHO`" = "X$ECHO" \
+      || test "X`print -r -- $ECHO`" = "X$ECHO" )])])
+
+_LT_DECL([], [SHELL], [1], [Shell to use when invoking shell scripts])
+_LT_DECL([], [ECHO], [1], [An echo program that protects backslashes])
+])# _LT_PROG_ECHO_BACKSLASH
+
+
+# _LT_WITH_SYSROOT
+# ----------------
+AC_DEFUN([_LT_WITH_SYSROOT],
+[AC_MSG_CHECKING([for sysroot])
+AC_ARG_WITH([sysroot],
+[  --with-sysroot[=DIR] Search for dependent libraries within DIR
+                        (or the compiler's sysroot if not specified).],
+[], [with_sysroot=no])
+
+dnl lt_sysroot will always be passed unquoted.  We quote it here
+dnl in case the user passed a directory name.
+lt_sysroot=
+case ${with_sysroot} in #(
+ yes)
+   if test "$GCC" = yes; then
+     lt_sysroot=`$CC --print-sysroot 2>/dev/null`
+   fi
+   ;; #(
+ /*)
+   lt_sysroot=`echo "$with_sysroot" | sed -e "$sed_quote_subst"`
+   ;; #(
+ no|'')
+   ;; #(
+ *)
+   AC_MSG_RESULT([${with_sysroot}])
+   AC_MSG_ERROR([The sysroot must be an absolute path.])
+   ;;
+esac
+
+ AC_MSG_RESULT([${lt_sysroot:-no}])
+_LT_DECL([], [lt_sysroot], [0], [The root where to search for ]dnl
+[dependent libraries, and in which our libraries should be installed.])])
+
+# _LT_ENABLE_LOCK
+# ---------------
+m4_defun([_LT_ENABLE_LOCK],
+[AC_ARG_ENABLE([libtool-lock],
+  [AS_HELP_STRING([--disable-libtool-lock],
+    [avoid locking (might break parallel builds)])])
+test "x$enable_libtool_lock" != xno && enable_libtool_lock=yes
+
+# Some flags need to be propagated to the compiler or linker for good
+# libtool support.
+case $host in
+ia64-*-hpux*)
+  # Find out which ABI we are using.
+  echo 'int i;' > conftest.$ac_ext
+  if AC_TRY_EVAL(ac_compile); then
+    case `/usr/bin/file conftest.$ac_objext` in
+      *ELF-32*)
+       HPUX_IA64_MODE="32"
+       ;;
+      *ELF-64*)
+       HPUX_IA64_MODE="64"
+       ;;
+    esac
+  fi
+  rm -rf conftest*
+  ;;
+*-*-irix6*)
+  # Find out which ABI we are using.
+  echo '[#]line '$LINENO' "configure"' > conftest.$ac_ext
+  if AC_TRY_EVAL(ac_compile); then
+    if test "$lt_cv_prog_gnu_ld" = yes; then
+      case `/usr/bin/file conftest.$ac_objext` in
+       *32-bit*)
+         LD="${LD-ld} -melf32bsmip"
+         ;;
+       *N32*)
+         LD="${LD-ld} -melf32bmipn32"
+         ;;
+       *64-bit*)
+         LD="${LD-ld} -melf64bmip"
+       ;;
+      esac
+    else
+      case `/usr/bin/file conftest.$ac_objext` in
+       *32-bit*)
+         LD="${LD-ld} -32"
+         ;;
+       *N32*)
+         LD="${LD-ld} -n32"
+         ;;
+       *64-bit*)
+         LD="${LD-ld} -64"
+         ;;
+      esac
+    fi
+  fi
+  rm -rf conftest*
+  ;;
+
+x86_64-*kfreebsd*-gnu|x86_64-*linux*|ppc*-*linux*|powerpc*-*linux*| \
+s390*-*linux*|s390*-*tpf*|sparc*-*linux*)
+  # Find out which ABI we are using.
+  echo 'int i;' > conftest.$ac_ext
+  if AC_TRY_EVAL(ac_compile); then
+    case `/usr/bin/file conftest.o` in
+      *32-bit*)
+       case $host in
+         x86_64-*kfreebsd*-gnu)
+           LD="${LD-ld} -m elf_i386_fbsd"
+           ;;
+         x86_64-*linux*)
+           LD="${LD-ld} -m elf_i386"
+           ;;
+         ppc64-*linux*|powerpc64-*linux*)
+           LD="${LD-ld} -m elf32ppclinux"
+           ;;
+         s390x-*linux*)
+           LD="${LD-ld} -m elf_s390"
+           ;;
+         sparc64-*linux*)
+           LD="${LD-ld} -m elf32_sparc"
+           ;;
+       esac
+       ;;
+      *64-bit*)
+       case $host in
+         x86_64-*kfreebsd*-gnu)
+           LD="${LD-ld} -m elf_x86_64_fbsd"
+           ;;
+         x86_64-*linux*)
+           LD="${LD-ld} -m elf_x86_64"
+           ;;
+         ppc*-*linux*|powerpc*-*linux*)
+           LD="${LD-ld} -m elf64ppc"
+           ;;
+         s390*-*linux*|s390*-*tpf*)
+           LD="${LD-ld} -m elf64_s390"
+           ;;
+         sparc*-*linux*)
+           LD="${LD-ld} -m elf64_sparc"
+           ;;
+       esac
+       ;;
+    esac
+  fi
+  rm -rf conftest*
+  ;;
+
+*-*-sco3.2v5*)
+  # On SCO OpenServer 5, we need -belf to get full-featured binaries.
+  SAVE_CFLAGS="$CFLAGS"
+  CFLAGS="$CFLAGS -belf"
+  AC_CACHE_CHECK([whether the C compiler needs -belf], lt_cv_cc_needs_belf,
+    [AC_LANG_PUSH(C)
+     AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],[[]])],[lt_cv_cc_needs_belf=yes],[lt_cv_cc_needs_belf=no])
+     AC_LANG_POP])
+  if test x"$lt_cv_cc_needs_belf" != x"yes"; then
+    # this is probably gcc 2.8.0, egcs 1.0 or newer; no need for -belf
+    CFLAGS="$SAVE_CFLAGS"
+  fi
+  ;;
+*-*solaris*)
+  # Find out which ABI we are using.
+  echo 'int i;' > conftest.$ac_ext
+  if AC_TRY_EVAL(ac_compile); then
+    case `/usr/bin/file conftest.o` in
+    *64-bit*)
+      case $lt_cv_prog_gnu_ld in
+      yes*)
+        case $host in
+        i?86-*-solaris*)
+          LD="${LD-ld} -m elf_x86_64"
+          ;;
+        sparc*-*-solaris*)
+          LD="${LD-ld} -m elf64_sparc"
+          ;;
+        esac
+        # GNU ld 2.21 introduced _sol2 emulations.  Use them if available.
+        if ${LD-ld} -V | grep _sol2 >/dev/null 2>&1; then
+          LD="${LD-ld}_sol2"
+        fi
+        ;;
+      *)
+       if ${LD-ld} -64 -r -o conftest2.o conftest.o >/dev/null 2>&1; then
+         LD="${LD-ld} -64"
+       fi
+       ;;
+      esac
+      ;;
+    esac
+  fi
+  rm -rf conftest*
+  ;;
+esac
+
+need_locks="$enable_libtool_lock"
+])# _LT_ENABLE_LOCK
+
+
+# _LT_PROG_AR
+# -----------
+m4_defun([_LT_PROG_AR],
+[AC_CHECK_TOOLS(AR, [ar], false)
+: ${AR=ar}
+: ${AR_FLAGS=cru}
+_LT_DECL([], [AR], [1], [The archiver])
+_LT_DECL([], [AR_FLAGS], [1], [Flags to create an archive])
+
+AC_CACHE_CHECK([for archiver @FILE support], [lt_cv_ar_at_file],
+  [lt_cv_ar_at_file=no
+   AC_COMPILE_IFELSE([AC_LANG_PROGRAM],
+     [echo conftest.$ac_objext > conftest.lst
+      lt_ar_try='$AR $AR_FLAGS libconftest.a @conftest.lst >&AS_MESSAGE_LOG_FD'
+      AC_TRY_EVAL([lt_ar_try])
+      if test "$ac_status" -eq 0; then
+       # Ensure the archiver fails upon bogus file names.
+       rm -f conftest.$ac_objext libconftest.a
+       AC_TRY_EVAL([lt_ar_try])
+       if test "$ac_status" -ne 0; then
+          lt_cv_ar_at_file=@
+        fi
+      fi
+      rm -f conftest.* libconftest.a
+     ])
+  ])
+
+if test "x$lt_cv_ar_at_file" = xno; then
+  archiver_list_spec=
+else
+  archiver_list_spec=$lt_cv_ar_at_file
+fi
+_LT_DECL([], [archiver_list_spec], [1],
+  [How to feed a file listing to the archiver])
+])# _LT_PROG_AR
+
+
+# _LT_CMD_OLD_ARCHIVE
+# -------------------
+m4_defun([_LT_CMD_OLD_ARCHIVE],
+[_LT_PROG_AR
+
+AC_CHECK_TOOL(STRIP, strip, :)
+test -z "$STRIP" && STRIP=:
+_LT_DECL([], [STRIP], [1], [A symbol stripping program])
+
+AC_CHECK_TOOL(RANLIB, ranlib, :)
+test -z "$RANLIB" && RANLIB=:
+_LT_DECL([], [RANLIB], [1],
+    [Commands used to install an old-style archive])
+
+# Determine commands to create old-style static archives.
+old_archive_cmds='$AR $AR_FLAGS $oldlib$oldobjs'
+old_postinstall_cmds='chmod 644 $oldlib'
+old_postuninstall_cmds=
+
+if test -n "$RANLIB"; then
+  case $host_os in
+  openbsd*)
+    old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB -t \$tool_oldlib"
+    ;;
+  *)
+    old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB \$tool_oldlib"
+    ;;
+  esac
+  old_archive_cmds="$old_archive_cmds~\$RANLIB \$tool_oldlib"
+fi
+
+case $host_os in
+  darwin*)
+    lock_old_archive_extraction=yes ;;
+  *)
+    lock_old_archive_extraction=no ;;
+esac
+_LT_DECL([], [old_postinstall_cmds], [2])
+_LT_DECL([], [old_postuninstall_cmds], [2])
+_LT_TAGDECL([], [old_archive_cmds], [2],
+    [Commands used to build an old-style archive])
+_LT_DECL([], [lock_old_archive_extraction], [0],
+    [Whether to use a lock for old archive extraction])
+])# _LT_CMD_OLD_ARCHIVE
+
+
+# _LT_COMPILER_OPTION(MESSAGE, VARIABLE-NAME, FLAGS,
+#              [OUTPUT-FILE], [ACTION-SUCCESS], [ACTION-FAILURE])
+# ----------------------------------------------------------------
+# Check whether the given compiler option works
+AC_DEFUN([_LT_COMPILER_OPTION],
+[m4_require([_LT_FILEUTILS_DEFAULTS])dnl
+m4_require([_LT_DECL_SED])dnl
+AC_CACHE_CHECK([$1], [$2],
+  [$2=no
+   m4_if([$4], , [ac_outfile=conftest.$ac_objext], [ac_outfile=$4])
+   echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+   lt_compiler_flag="$3"
+   # Insert the option either (1) after the last *FLAGS variable, or
+   # (2) before a word containing "conftest.", or (3) at the end.
+   # Note that $ac_compile itself does not contain backslashes and begins
+   # with a dollar sign (not a hyphen), so the echo should work correctly.
+   # The option is referenced via a variable to avoid confusing sed.
+   lt_compile=`echo "$ac_compile" | $SED \
+   -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
+   -e 's: [[^ ]]*conftest\.: $lt_compiler_flag&:; t' \
+   -e 's:$: $lt_compiler_flag:'`
+   (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&AS_MESSAGE_LOG_FD)
+   (eval "$lt_compile" 2>conftest.err)
+   ac_status=$?
+   cat conftest.err >&AS_MESSAGE_LOG_FD
+   echo "$as_me:$LINENO: \$? = $ac_status" >&AS_MESSAGE_LOG_FD
+   if (exit $ac_status) && test -s "$ac_outfile"; then
+     # The compiler can only warn and ignore the option if not recognized
+     # So say no if there are warnings other than the usual output.
+     $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' >conftest.exp
+     $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
+     if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then
+       $2=yes
+     fi
+   fi
+   $RM conftest*
+])
+
+if test x"[$]$2" = xyes; then
+    m4_if([$5], , :, [$5])
+else
+    m4_if([$6], , :, [$6])
+fi
+])# _LT_COMPILER_OPTION
+
+# Old name:
+AU_ALIAS([AC_LIBTOOL_COMPILER_OPTION], [_LT_COMPILER_OPTION])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_LIBTOOL_COMPILER_OPTION], [])
+
+
+# _LT_LINKER_OPTION(MESSAGE, VARIABLE-NAME, FLAGS,
+#                  [ACTION-SUCCESS], [ACTION-FAILURE])
+# ----------------------------------------------------
+# Check whether the given linker option works
+AC_DEFUN([_LT_LINKER_OPTION],
+[m4_require([_LT_FILEUTILS_DEFAULTS])dnl
+m4_require([_LT_DECL_SED])dnl
+AC_CACHE_CHECK([$1], [$2],
+  [$2=no
+   save_LDFLAGS="$LDFLAGS"
+   LDFLAGS="$LDFLAGS $3"
+   echo "$lt_simple_link_test_code" > conftest.$ac_ext
+   if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then
+     # The linker can only warn and ignore the option if not recognized
+     # So say no if there are warnings
+     if test -s conftest.err; then
+       # Append any errors to the config.log.
+       cat conftest.err 1>&AS_MESSAGE_LOG_FD
+       $ECHO "$_lt_linker_boilerplate" | $SED '/^$/d' > conftest.exp
+       $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
+       if diff conftest.exp conftest.er2 >/dev/null; then
+         $2=yes
+       fi
+     else
+       $2=yes
+     fi
+   fi
+   $RM -r conftest*
+   LDFLAGS="$save_LDFLAGS"
+])
+
+if test x"[$]$2" = xyes; then
+    m4_if([$4], , :, [$4])
+else
+    m4_if([$5], , :, [$5])
+fi
+])# _LT_LINKER_OPTION
+
+# Old name:
+AU_ALIAS([AC_LIBTOOL_LINKER_OPTION], [_LT_LINKER_OPTION])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_LIBTOOL_LINKER_OPTION], [])
+
+
+# LT_CMD_MAX_LEN
+#---------------
+AC_DEFUN([LT_CMD_MAX_LEN],
+[AC_REQUIRE([AC_CANONICAL_HOST])dnl
+# find the maximum length of command line arguments
+AC_MSG_CHECKING([the maximum length of command line arguments])
+AC_CACHE_VAL([lt_cv_sys_max_cmd_len], [dnl
+  i=0
+  teststring="ABCD"
+
+  case $build_os in
+  msdosdjgpp*)
+    # On DJGPP, this test can blow up pretty badly due to problems in libc
+    # (any single argument exceeding 2000 bytes causes a buffer overrun
+    # during glob expansion).  Even if it were fixed, the result of this
+    # check would be larger than it should be.
+    lt_cv_sys_max_cmd_len=12288;    # 12K is about right
+    ;;
+
+  gnu*)
+    # Under GNU Hurd, this test is not required because there is
+    # no limit to the length of command line arguments.
+    # Libtool will interpret -1 as no limit whatsoever
+    lt_cv_sys_max_cmd_len=-1;
+    ;;
+
+  cygwin* | mingw* | cegcc*)
+    # On Win9x/ME, this test blows up -- it succeeds, but takes
+    # about 5 minutes as the teststring grows exponentially.
+    # Worse, since 9x/ME are not pre-emptively multitasking,
+    # you end up with a "frozen" computer, even though with patience
+    # the test eventually succeeds (with a max line length of 256k).
+    # Instead, let's just punt: use the minimum linelength reported by
+    # all of the supported platforms: 8192 (on NT/2K/XP).
+    lt_cv_sys_max_cmd_len=8192;
+    ;;
+
+  mint*)
+    # On MiNT this can take a long time and run out of memory.
+    lt_cv_sys_max_cmd_len=8192;
+    ;;
+
+  amigaos*)
+    # On AmigaOS with pdksh, this test takes hours, literally.
+    # So we just punt and use a minimum line length of 8192.
+    lt_cv_sys_max_cmd_len=8192;
+    ;;
+
+  netbsd* | freebsd* | openbsd* | darwin* | dragonfly*)
+    # This has been around since 386BSD, at least.  Likely further.
+    if test -x /sbin/sysctl; then
+      lt_cv_sys_max_cmd_len=`/sbin/sysctl -n kern.argmax`
+    elif test -x /usr/sbin/sysctl; then
+      lt_cv_sys_max_cmd_len=`/usr/sbin/sysctl -n kern.argmax`
+    else
+      lt_cv_sys_max_cmd_len=65536      # usable default for all BSDs
+    fi
+    # And add a safety zone
+    lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4`
+    lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3`
+    ;;
+
+  interix*)
+    # We know the value 262144 and hardcode it with a safety zone (like BSD)
+    lt_cv_sys_max_cmd_len=196608
+    ;;
+
+  os2*)
+    # The test takes a long time on OS/2.
+    lt_cv_sys_max_cmd_len=8192
+    ;;
+
+  osf*)
+    # Dr. Hans Ekkehard Plesser reports seeing a kernel panic running configure
+    # due to this test when exec_disable_arg_limit is 1 on Tru64. It is not
+    # nice to cause kernel panics so lets avoid the loop below.
+    # First set a reasonable default.
+    lt_cv_sys_max_cmd_len=16384
+    #
+    if test -x /sbin/sysconfig; then
+      case `/sbin/sysconfig -q proc exec_disable_arg_limit` in
+        *1*) lt_cv_sys_max_cmd_len=-1 ;;
+      esac
+    fi
+    ;;
+  sco3.2v5*)
+    lt_cv_sys_max_cmd_len=102400
+    ;;
+  sysv5* | sco5v6* | sysv4.2uw2*)
+    kargmax=`grep ARG_MAX /etc/conf/cf.d/stune 2>/dev/null`
+    if test -n "$kargmax"; then
+      lt_cv_sys_max_cmd_len=`echo $kargmax | sed 's/.*[[        ]]//'`
+    else
+      lt_cv_sys_max_cmd_len=32768
+    fi
+    ;;
+  *)
+    lt_cv_sys_max_cmd_len=`(getconf ARG_MAX) 2> /dev/null`
+    if test -n "$lt_cv_sys_max_cmd_len"; then
+      lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4`
+      lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3`
+    else
+      # Make teststring a little bigger before we do anything with it.
+      # a 1K string should be a reasonable start.
+      for i in 1 2 3 4 5 6 7 8 ; do
+        teststring=$teststring$teststring
+      done
+      SHELL=${SHELL-${CONFIG_SHELL-/bin/sh}}
+      # If test is not a shell built-in, we'll probably end up computing a
+      # maximum length that is only half of the actual maximum length, but
+      # we can't tell.
+      while { test "X"`env echo "$teststring$teststring" 2>/dev/null` \
+                = "X$teststring$teststring"; } >/dev/null 2>&1 &&
+             test $i != 17 # 1/2 MB should be enough
+      do
+        i=`expr $i + 1`
+        teststring=$teststring$teststring
+      done
+      # Only check the string length outside the loop.
+      lt_cv_sys_max_cmd_len=`expr "X$teststring" : ".*" 2>&1`
+      teststring=
+      # Add a significant safety factor because C++ compilers can tack on
+      # massive amounts of additional arguments before passing them to the
+      # linker.  It appears as though 1/2 is a usable value.
+      lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 2`
+    fi
+    ;;
+  esac
+])
+if test -n $lt_cv_sys_max_cmd_len ; then
+  AC_MSG_RESULT($lt_cv_sys_max_cmd_len)
+else
+  AC_MSG_RESULT(none)
+fi
+max_cmd_len=$lt_cv_sys_max_cmd_len
+_LT_DECL([], [max_cmd_len], [0],
+    [What is the maximum length of a command?])
+])# LT_CMD_MAX_LEN
+
+# Old name:
+AU_ALIAS([AC_LIBTOOL_SYS_MAX_CMD_LEN], [LT_CMD_MAX_LEN])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_LIBTOOL_SYS_MAX_CMD_LEN], [])
+
+
+# _LT_HEADER_DLFCN
+# ----------------
+m4_defun([_LT_HEADER_DLFCN],
+[AC_CHECK_HEADERS([dlfcn.h], [], [], [AC_INCLUDES_DEFAULT])dnl
+])# _LT_HEADER_DLFCN
+
+
+# _LT_TRY_DLOPEN_SELF (ACTION-IF-TRUE, ACTION-IF-TRUE-W-USCORE,
+#                      ACTION-IF-FALSE, ACTION-IF-CROSS-COMPILING)
+# ----------------------------------------------------------------
+m4_defun([_LT_TRY_DLOPEN_SELF],
+[m4_require([_LT_HEADER_DLFCN])dnl
+if test "$cross_compiling" = yes; then :
+  [$4]
+else
+  lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+  lt_status=$lt_dlunknown
+  cat > conftest.$ac_ext <<_LT_EOF
+[#line $LINENO "configure"
+#include "confdefs.h"
+
+#if HAVE_DLFCN_H
+#include <dlfcn.h>
+#endif
+
+#include <stdio.h>
+
+#ifdef RTLD_GLOBAL
+#  define LT_DLGLOBAL          RTLD_GLOBAL
+#else
+#  ifdef DL_GLOBAL
+#    define LT_DLGLOBAL                DL_GLOBAL
+#  else
+#    define LT_DLGLOBAL                0
+#  endif
+#endif
+
+/* We may have to define LT_DLLAZY_OR_NOW in the command line if we
+   find out it does not work in some platform. */
+#ifndef LT_DLLAZY_OR_NOW
+#  ifdef RTLD_LAZY
+#    define LT_DLLAZY_OR_NOW           RTLD_LAZY
+#  else
+#    ifdef DL_LAZY
+#      define LT_DLLAZY_OR_NOW         DL_LAZY
+#    else
+#      ifdef RTLD_NOW
+#        define LT_DLLAZY_OR_NOW       RTLD_NOW
+#      else
+#        ifdef DL_NOW
+#          define LT_DLLAZY_OR_NOW     DL_NOW
+#        else
+#          define LT_DLLAZY_OR_NOW     0
+#        endif
+#      endif
+#    endif
+#  endif
+#endif
+
+/* When -fvisbility=hidden is used, assume the code has been annotated
+   correspondingly for the symbols needed.  */
+#if defined(__GNUC__) && (((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)) || (__GNUC__ > 3))
+int fnord () __attribute__((visibility("default")));
+#endif
+
+int fnord () { return 42; }
+int main ()
+{
+  void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW);
+  int status = $lt_dlunknown;
+
+  if (self)
+    {
+      if (dlsym (self,"fnord"))       status = $lt_dlno_uscore;
+      else
+        {
+         if (dlsym( self,"_fnord"))  status = $lt_dlneed_uscore;
+          else puts (dlerror ());
+       }
+      /* dlclose (self); */
+    }
+  else
+    puts (dlerror ());
+
+  return status;
+}]
+_LT_EOF
+  if AC_TRY_EVAL(ac_link) && test -s conftest${ac_exeext} 2>/dev/null; then
+    (./conftest; exit; ) >&AS_MESSAGE_LOG_FD 2>/dev/null
+    lt_status=$?
+    case x$lt_status in
+      x$lt_dlno_uscore) $1 ;;
+      x$lt_dlneed_uscore) $2 ;;
+      x$lt_dlunknown|x*) $3 ;;
+    esac
+  else :
+    # compilation failed
+    $3
+  fi
+fi
+rm -fr conftest*
+])# _LT_TRY_DLOPEN_SELF
+
+
+# LT_SYS_DLOPEN_SELF
+# ------------------
+AC_DEFUN([LT_SYS_DLOPEN_SELF],
+[m4_require([_LT_HEADER_DLFCN])dnl
+if test "x$enable_dlopen" != xyes; then
+  enable_dlopen=unknown
+  enable_dlopen_self=unknown
+  enable_dlopen_self_static=unknown
+else
+  lt_cv_dlopen=no
+  lt_cv_dlopen_libs=
+
+  case $host_os in
+  beos*)
+    lt_cv_dlopen="load_add_on"
+    lt_cv_dlopen_libs=
+    lt_cv_dlopen_self=yes
+    ;;
+
+  mingw* | pw32* | cegcc*)
+    lt_cv_dlopen="LoadLibrary"
+    lt_cv_dlopen_libs=
+    ;;
+
+  cygwin*)
+    lt_cv_dlopen="dlopen"
+    lt_cv_dlopen_libs=
+    ;;
+
+  darwin*)
+  # if libdl is installed we need to link against it
+    AC_CHECK_LIB([dl], [dlopen],
+               [lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl"],[
+    lt_cv_dlopen="dyld"
+    lt_cv_dlopen_libs=
+    lt_cv_dlopen_self=yes
+    ])
+    ;;
+
+  *)
+    AC_CHECK_FUNC([shl_load],
+         [lt_cv_dlopen="shl_load"],
+      [AC_CHECK_LIB([dld], [shl_load],
+           [lt_cv_dlopen="shl_load" lt_cv_dlopen_libs="-ldld"],
+       [AC_CHECK_FUNC([dlopen],
+             [lt_cv_dlopen="dlopen"],
+         [AC_CHECK_LIB([dl], [dlopen],
+               [lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl"],
+           [AC_CHECK_LIB([svld], [dlopen],
+                 [lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-lsvld"],
+             [AC_CHECK_LIB([dld], [dld_link],
+                   [lt_cv_dlopen="dld_link" lt_cv_dlopen_libs="-ldld"])
+             ])
+           ])
+         ])
+       ])
+      ])
+    ;;
+  esac
+
+  if test "x$lt_cv_dlopen" != xno; then
+    enable_dlopen=yes
+  else
+    enable_dlopen=no
+  fi
+
+  case $lt_cv_dlopen in
+  dlopen)
+    save_CPPFLAGS="$CPPFLAGS"
+    test "x$ac_cv_header_dlfcn_h" = xyes && CPPFLAGS="$CPPFLAGS -DHAVE_DLFCN_H"
+
+    save_LDFLAGS="$LDFLAGS"
+    wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $export_dynamic_flag_spec\"
+
+    save_LIBS="$LIBS"
+    LIBS="$lt_cv_dlopen_libs $LIBS"
+
+    AC_CACHE_CHECK([whether a program can dlopen itself],
+         lt_cv_dlopen_self, [dnl
+         _LT_TRY_DLOPEN_SELF(
+           lt_cv_dlopen_self=yes, lt_cv_dlopen_self=yes,
+           lt_cv_dlopen_self=no, lt_cv_dlopen_self=cross)
+    ])
+
+    if test "x$lt_cv_dlopen_self" = xyes; then
+      wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $lt_prog_compiler_static\"
+      AC_CACHE_CHECK([whether a statically linked program can dlopen itself],
+         lt_cv_dlopen_self_static, [dnl
+         _LT_TRY_DLOPEN_SELF(
+           lt_cv_dlopen_self_static=yes, lt_cv_dlopen_self_static=yes,
+           lt_cv_dlopen_self_static=no,  lt_cv_dlopen_self_static=cross)
+      ])
+    fi
+
+    CPPFLAGS="$save_CPPFLAGS"
+    LDFLAGS="$save_LDFLAGS"
+    LIBS="$save_LIBS"
+    ;;
+  esac
+
+  case $lt_cv_dlopen_self in
+  yes|no) enable_dlopen_self=$lt_cv_dlopen_self ;;
+  *) enable_dlopen_self=unknown ;;
+  esac
+
+  case $lt_cv_dlopen_self_static in
+  yes|no) enable_dlopen_self_static=$lt_cv_dlopen_self_static ;;
+  *) enable_dlopen_self_static=unknown ;;
+  esac
+fi
+_LT_DECL([dlopen_support], [enable_dlopen], [0],
+        [Whether dlopen is supported])
+_LT_DECL([dlopen_self], [enable_dlopen_self], [0],
+        [Whether dlopen of programs is supported])
+_LT_DECL([dlopen_self_static], [enable_dlopen_self_static], [0],
+        [Whether dlopen of statically linked programs is supported])
+])# LT_SYS_DLOPEN_SELF
+
+# Old name:
+AU_ALIAS([AC_LIBTOOL_DLOPEN_SELF], [LT_SYS_DLOPEN_SELF])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_LIBTOOL_DLOPEN_SELF], [])
+
+
+# _LT_COMPILER_C_O([TAGNAME])
+# ---------------------------
+# Check to see if options -c and -o are simultaneously supported by compiler.
+# This macro does not hard code the compiler like AC_PROG_CC_C_O.
+m4_defun([_LT_COMPILER_C_O],
+[m4_require([_LT_DECL_SED])dnl
+m4_require([_LT_FILEUTILS_DEFAULTS])dnl
+m4_require([_LT_TAG_COMPILER])dnl
+AC_CACHE_CHECK([if $compiler supports -c -o file.$ac_objext],
+  [_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)],
+  [_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)=no
+   $RM -r conftest 2>/dev/null
+   mkdir conftest
+   cd conftest
+   mkdir out
+   echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+
+   lt_compiler_flag="-o out/conftest2.$ac_objext"
+   # Insert the option either (1) after the last *FLAGS variable, or
+   # (2) before a word containing "conftest.", or (3) at the end.
+   # Note that $ac_compile itself does not contain backslashes and begins
+   # with a dollar sign (not a hyphen), so the echo should work correctly.
+   lt_compile=`echo "$ac_compile" | $SED \
+   -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
+   -e 's: [[^ ]]*conftest\.: $lt_compiler_flag&:; t' \
+   -e 's:$: $lt_compiler_flag:'`
+   (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&AS_MESSAGE_LOG_FD)
+   (eval "$lt_compile" 2>out/conftest.err)
+   ac_status=$?
+   cat out/conftest.err >&AS_MESSAGE_LOG_FD
+   echo "$as_me:$LINENO: \$? = $ac_status" >&AS_MESSAGE_LOG_FD
+   if (exit $ac_status) && test -s out/conftest2.$ac_objext
+   then
+     # The compiler can only warn and ignore the option if not recognized
+     # So say no if there are warnings
+     $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' > out/conftest.exp
+     $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2
+     if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then
+       _LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)=yes
+     fi
+   fi
+   chmod u+w . 2>&AS_MESSAGE_LOG_FD
+   $RM conftest*
+   # SGI C++ compiler will create directory out/ii_files/ for
+   # template instantiation
+   test -d out/ii_files && $RM out/ii_files/* && rmdir out/ii_files
+   $RM out/* && rmdir out
+   cd ..
+   $RM -r conftest
+   $RM conftest*
+])
+_LT_TAGDECL([compiler_c_o], [lt_cv_prog_compiler_c_o], [1],
+       [Does compiler simultaneously support -c and -o options?])
+])# _LT_COMPILER_C_O
+
+
+# _LT_COMPILER_FILE_LOCKS([TAGNAME])
+# ----------------------------------
+# Check to see if we can do hard links to lock some files if needed
+m4_defun([_LT_COMPILER_FILE_LOCKS],
+[m4_require([_LT_ENABLE_LOCK])dnl
+m4_require([_LT_FILEUTILS_DEFAULTS])dnl
+_LT_COMPILER_C_O([$1])
+
+hard_links="nottested"
+if test "$_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)" = no && test "$need_locks" != no; then
+  # do not overwrite the value of need_locks provided by the user
+  AC_MSG_CHECKING([if we can lock with hard links])
+  hard_links=yes
+  $RM conftest*
+  ln conftest.a conftest.b 2>/dev/null && hard_links=no
+  touch conftest.a
+  ln conftest.a conftest.b 2>&5 || hard_links=no
+  ln conftest.a conftest.b 2>/dev/null && hard_links=no
+  AC_MSG_RESULT([$hard_links])
+  if test "$hard_links" = no; then
+    AC_MSG_WARN([`$CC' does not support `-c -o', so `make -j' may be unsafe])
+    need_locks=warn
+  fi
+else
+  need_locks=no
+fi
+_LT_DECL([], [need_locks], [1], [Must we lock files when doing compilation?])
+])# _LT_COMPILER_FILE_LOCKS
+
+
+# _LT_CHECK_OBJDIR
+# ----------------
+m4_defun([_LT_CHECK_OBJDIR],
+[AC_CACHE_CHECK([for objdir], [lt_cv_objdir],
+[rm -f .libs 2>/dev/null
+mkdir .libs 2>/dev/null
+if test -d .libs; then
+  lt_cv_objdir=.libs
+else
+  # MS-DOS does not allow filenames that begin with a dot.
+  lt_cv_objdir=_libs
+fi
+rmdir .libs 2>/dev/null])
+objdir=$lt_cv_objdir
+_LT_DECL([], [objdir], [0],
+         [The name of the directory that contains temporary libtool files])dnl
+m4_pattern_allow([LT_OBJDIR])dnl
+AC_DEFINE_UNQUOTED(LT_OBJDIR, "$lt_cv_objdir/",
+  [Define to the sub-directory in which libtool stores uninstalled libraries.])
+])# _LT_CHECK_OBJDIR
+
+
+# _LT_LINKER_HARDCODE_LIBPATH([TAGNAME])
+# --------------------------------------
+# Check hardcoding attributes.
+m4_defun([_LT_LINKER_HARDCODE_LIBPATH],
+[AC_MSG_CHECKING([how to hardcode library paths into programs])
+_LT_TAGVAR(hardcode_action, $1)=
+if test -n "$_LT_TAGVAR(hardcode_libdir_flag_spec, $1)" ||
+   test -n "$_LT_TAGVAR(runpath_var, $1)" ||
+   test "X$_LT_TAGVAR(hardcode_automatic, $1)" = "Xyes" ; then
+
+  # We can hardcode non-existent directories.
+  if test "$_LT_TAGVAR(hardcode_direct, $1)" != no &&
+     # If the only mechanism to avoid hardcoding is shlibpath_var, we
+     # have to relink, otherwise we might link with an installed library
+     # when we should be linking with a yet-to-be-installed one
+     ## test "$_LT_TAGVAR(hardcode_shlibpath_var, $1)" != no &&
+     test "$_LT_TAGVAR(hardcode_minus_L, $1)" != no; then
+    # Linking always hardcodes the temporary library directory.
+    _LT_TAGVAR(hardcode_action, $1)=relink
+  else
+    # We can link without hardcoding, and we can hardcode nonexisting dirs.
+    _LT_TAGVAR(hardcode_action, $1)=immediate
+  fi
+else
+  # We cannot hardcode anything, or else we can only hardcode existing
+  # directories.
+  _LT_TAGVAR(hardcode_action, $1)=unsupported
+fi
+AC_MSG_RESULT([$_LT_TAGVAR(hardcode_action, $1)])
+
+if test "$_LT_TAGVAR(hardcode_action, $1)" = relink ||
+   test "$_LT_TAGVAR(inherit_rpath, $1)" = yes; then
+  # Fast installation is not supported
+  enable_fast_install=no
+elif test "$shlibpath_overrides_runpath" = yes ||
+     test "$enable_shared" = no; then
+  # Fast installation is not necessary
+  enable_fast_install=needless
+fi
+_LT_TAGDECL([], [hardcode_action], [0],
+    [How to hardcode a shared library path into an executable])
+])# _LT_LINKER_HARDCODE_LIBPATH
+
+
+# _LT_CMD_STRIPLIB
+# ----------------
+m4_defun([_LT_CMD_STRIPLIB],
+[m4_require([_LT_DECL_EGREP])
+striplib=
+old_striplib=
+AC_MSG_CHECKING([whether stripping libraries is possible])
+if test -n "$STRIP" && $STRIP -V 2>&1 | $GREP "GNU strip" >/dev/null; then
+  test -z "$old_striplib" && old_striplib="$STRIP --strip-debug"
+  test -z "$striplib" && striplib="$STRIP --strip-unneeded"
+  AC_MSG_RESULT([yes])
+else
+# FIXME - insert some real tests, host_os isn't really good enough
+  case $host_os in
+  darwin*)
+    if test -n "$STRIP" ; then
+      striplib="$STRIP -x"
+      old_striplib="$STRIP -S"
+      AC_MSG_RESULT([yes])
+    else
+      AC_MSG_RESULT([no])
+    fi
+    ;;
+  *)
+    AC_MSG_RESULT([no])
+    ;;
+  esac
+fi
+_LT_DECL([], [old_striplib], [1], [Commands to strip libraries])
+_LT_DECL([], [striplib], [1])
+])# _LT_CMD_STRIPLIB
+
+
+# _LT_SYS_DYNAMIC_LINKER([TAG])
+# -----------------------------
+# PORTME Fill in your ld.so characteristics
+m4_defun([_LT_SYS_DYNAMIC_LINKER],
+[AC_REQUIRE([AC_CANONICAL_HOST])dnl
+m4_require([_LT_DECL_EGREP])dnl
+m4_require([_LT_FILEUTILS_DEFAULTS])dnl
+m4_require([_LT_DECL_OBJDUMP])dnl
+m4_require([_LT_DECL_SED])dnl
+m4_require([_LT_CHECK_SHELL_FEATURES])dnl
+AC_MSG_CHECKING([dynamic linker characteristics])
+m4_if([$1],
+       [], [
+if test "$GCC" = yes; then
+  case $host_os in
+    darwin*) lt_awk_arg="/^libraries:/,/LR/" ;;
+    *) lt_awk_arg="/^libraries:/" ;;
+  esac
+  case $host_os in
+    mingw* | cegcc*) lt_sed_strip_eq="s,=\([[A-Za-z]]:\),\1,g" ;;
+    *) lt_sed_strip_eq="s,=/,/,g" ;;
+  esac
+  lt_search_path_spec=`$CC -print-search-dirs | awk $lt_awk_arg | $SED -e "s/^libraries://" -e $lt_sed_strip_eq`
+  case $lt_search_path_spec in
+  *\;*)
+    # if the path contains ";" then we assume it to be the separator
+    # otherwise default to the standard path separator (i.e. ":") - it is
+    # assumed that no part of a normal pathname contains ";" but that should
+    # okay in the real world where ";" in dirpaths is itself problematic.
+    lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED 's/;/ /g'`
+    ;;
+  *)
+    lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED "s/$PATH_SEPARATOR/ /g"`
+    ;;
+  esac
+  # Ok, now we have the path, separated by spaces, we can step through it
+  # and add multilib dir if necessary.
+  lt_tmp_lt_search_path_spec=
+  lt_multi_os_dir=`$CC $CPPFLAGS $CFLAGS $LDFLAGS -print-multi-os-directory 2>/dev/null`
+  for lt_sys_path in $lt_search_path_spec; do
+    if test -d "$lt_sys_path/$lt_multi_os_dir"; then
+      lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path/$lt_multi_os_dir"
+    else
+      test -d "$lt_sys_path" && \
+       lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path"
+    fi
+  done
+  lt_search_path_spec=`$ECHO "$lt_tmp_lt_search_path_spec" | awk '
+BEGIN {RS=" "; FS="/|\n";} {
+  lt_foo="";
+  lt_count=0;
+  for (lt_i = NF; lt_i > 0; lt_i--) {
+    if ($lt_i != "" && $lt_i != ".") {
+      if ($lt_i == "..") {
+        lt_count++;
+      } else {
+        if (lt_count == 0) {
+          lt_foo="/" $lt_i lt_foo;
+        } else {
+          lt_count--;
+        }
+      }
+    }
+  }
+  if (lt_foo != "") { lt_freq[[lt_foo]]++; }
+  if (lt_freq[[lt_foo]] == 1) { print lt_foo; }
+}'`
+  # AWK program above erroneously prepends '/' to C:/dos/paths
+  # for these hosts.
+  case $host_os in
+    mingw* | cegcc*) lt_search_path_spec=`$ECHO "$lt_search_path_spec" |\
+      $SED 's,/\([[A-Za-z]]:\),\1,g'` ;;
+  esac
+  sys_lib_search_path_spec=`$ECHO "$lt_search_path_spec" | $lt_NL2SP`
+else
+  sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib"
+fi])
+library_names_spec=
+libname_spec='lib$name'
+soname_spec=
+shrext_cmds=".so"
+postinstall_cmds=
+postuninstall_cmds=
+finish_cmds=
+finish_eval=
+shlibpath_var=
+shlibpath_overrides_runpath=unknown
+version_type=none
+dynamic_linker="$host_os ld.so"
+sys_lib_dlsearch_path_spec="/lib /usr/lib"
+need_lib_prefix=unknown
+hardcode_into_libs=no
+
+# when you set need_version to no, make sure it does not cause -set_version
+# flags to be left without arguments
+need_version=unknown
+
+case $host_os in
+aix3*)
+  version_type=linux # correct to gnu/linux during the next big refactor
+  library_names_spec='${libname}${release}${shared_ext}$versuffix $libname.a'
+  shlibpath_var=LIBPATH
+
+  # AIX 3 has no versioning support, so we append a major version to the name.
+  soname_spec='${libname}${release}${shared_ext}$major'
+  ;;
+
+aix[[4-9]]*)
+  version_type=linux # correct to gnu/linux during the next big refactor
+  need_lib_prefix=no
+  need_version=no
+  hardcode_into_libs=yes
+  if test "$host_cpu" = ia64; then
+    # AIX 5 supports IA64
+    library_names_spec='${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext}$versuffix $libname${shared_ext}'
+    shlibpath_var=LD_LIBRARY_PATH
+  else
+    # With GCC up to 2.95.x, collect2 would create an import file
+    # for dependence libraries.  The import file would start with
+    # the line `#! .'.  This would cause the generated library to
+    # depend on `.', always an invalid library.  This was fixed in
+    # development snapshots of GCC prior to 3.0.
+    case $host_os in
+      aix4 | aix4.[[01]] | aix4.[[01]].*)
+      if { echo '#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97)'
+          echo ' yes '
+          echo '#endif'; } | ${CC} -E - | $GREP yes > /dev/null; then
+       :
+      else
+       can_build_shared=no
+      fi
+      ;;
+    esac
+    # AIX (on Power*) has no versioning support, so currently we can not hardcode correct
+    # soname into executable. Probably we can add versioning support to
+    # collect2, so additional links can be useful in future.
+    if test "$aix_use_runtimelinking" = yes; then
+      # If using run time linking (on AIX 4.2 or later) use lib<name>.so
+      # instead of lib<name>.a to let people know that these are not
+      # typical AIX shared libraries.
+      library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    else
+      # We preserve .a as extension for shared libraries through AIX4.2
+      # and later when we are not doing run time linking.
+      library_names_spec='${libname}${release}.a $libname.a'
+      soname_spec='${libname}${release}${shared_ext}$major'
+    fi
+    shlibpath_var=LIBPATH
+  fi
+  ;;
+
+amigaos*)
+  case $host_cpu in
+  powerpc)
+    # Since July 2007 AmigaOS4 officially supports .so libraries.
+    # When compiling the executable, add -use-dynld -Lsobjs: to the compileline.
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    ;;
+  m68k)
+    library_names_spec='$libname.ixlibrary $libname.a'
+    # Create ${libname}_ixlibrary.a entries in /sys/libs.
+    finish_eval='for lib in `ls $libdir/*.ixlibrary 2>/dev/null`; do libname=`func_echo_all "$lib" | $SED '\''s%^.*/\([[^/]]*\)\.ixlibrary$%\1%'\''`; test $RM /sys/libs/${libname}_ixlibrary.a; $show "cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a"; cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a || exit 1; done'
+    ;;
+  esac
+  ;;
+
+beos*)
+  library_names_spec='${libname}${shared_ext}'
+  dynamic_linker="$host_os ld.so"
+  shlibpath_var=LIBRARY_PATH
+  ;;
+
+bsdi[[45]]*)
+  version_type=linux # correct to gnu/linux during the next big refactor
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  finish_cmds='PATH="\$PATH:/sbin" ldconfig $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  sys_lib_search_path_spec="/shlib /usr/lib /usr/X11/lib /usr/contrib/lib /lib /usr/local/lib"
+  sys_lib_dlsearch_path_spec="/shlib /usr/lib /usr/local/lib"
+  # the default ld.so.conf also contains /usr/contrib/lib and
+  # /usr/X11R6/lib (/usr/X11 is a link to /usr/X11R6), but let us allow
+  # libtool to hard-code these into programs
+  ;;
+
+cygwin* | mingw* | pw32* | cegcc*)
+  version_type=windows
+  shrext_cmds=".dll"
+  need_version=no
+  need_lib_prefix=no
+
+  case $GCC,$cc_basename in
+  yes,*)
+    # gcc
+    library_names_spec='$libname.dll.a'
+    # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      test -d \$dldir || mkdir -p \$dldir~
+      $install_prog $dir/$dlname \$dldir/$dlname~
+      chmod a+x \$dldir/$dlname~
+      if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
+        eval '\''$striplib \$dldir/$dlname'\'' || exit \$?;
+      fi'
+    postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
+      dlpath=$dir/\$dldll~
+       $RM \$dlpath'
+    shlibpath_overrides_runpath=yes
+
+    case $host_os in
+    cygwin*)
+      # Cygwin DLLs use 'cyg' prefix rather than 'lib'
+      soname_spec='`echo ${libname} | sed -e 's/^lib/cyg/'``echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}'
+m4_if([$1], [],[
+      sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/lib/w32api"])
+      ;;
+    mingw* | cegcc*)
+      # MinGW DLLs use traditional 'lib' prefix
+      soname_spec='${libname}`echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}'
+      ;;
+    pw32*)
+      # pw32 DLLs use 'pw' prefix rather than 'lib'
+      library_names_spec='`echo ${libname} | sed -e 's/^lib/pw/'``echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}'
+      ;;
+    esac
+    dynamic_linker='Win32 ld.exe'
+    ;;
+
+  *,cl*)
+    # Native MSVC
+    libname_spec='$name'
+    soname_spec='${libname}`echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}'
+    library_names_spec='${libname}.dll.lib'
+
+    case $build_os in
+    mingw*)
+      sys_lib_search_path_spec=
+      lt_save_ifs=$IFS
+      IFS=';'
+      for lt_path in $LIB
+      do
+        IFS=$lt_save_ifs
+        # Let DOS variable expansion print the short 8.3 style file name.
+        lt_path=`cd "$lt_path" 2>/dev/null && cmd //C "for %i in (".") do @echo %~si"`
+        sys_lib_search_path_spec="$sys_lib_search_path_spec $lt_path"
+      done
+      IFS=$lt_save_ifs
+      # Convert to MSYS style.
+      sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | sed -e 's|\\\\|/|g' -e 's| \\([[a-zA-Z]]\\):| /\\1|g' -e 's|^ ||'`
+      ;;
+    cygwin*)
+      # Convert to unix form, then to dos form, then back to unix form
+      # but this time dos style (no spaces!) so that the unix form looks
+      # like /cygdrive/c/PROGRA~1:/cygdr...
+      sys_lib_search_path_spec=`cygpath --path --unix "$LIB"`
+      sys_lib_search_path_spec=`cygpath --path --dos "$sys_lib_search_path_spec" 2>/dev/null`
+      sys_lib_search_path_spec=`cygpath --path --unix "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"`
+      ;;
+    *)
+      sys_lib_search_path_spec="$LIB"
+      if $ECHO "$sys_lib_search_path_spec" | [$GREP ';[c-zC-Z]:/' >/dev/null]; then
+        # It is most probably a Windows format PATH.
+        sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'`
+      else
+        sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"`
+      fi
+      # FIXME: find the short name or the path components, as spaces are
+      # common. (e.g. "Program Files" -> "PROGRA~1")
+      ;;
+    esac
+
+    # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      test -d \$dldir || mkdir -p \$dldir~
+      $install_prog $dir/$dlname \$dldir/$dlname'
+    postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
+      dlpath=$dir/\$dldll~
+       $RM \$dlpath'
+    shlibpath_overrides_runpath=yes
+    dynamic_linker='Win32 link.exe'
+    ;;
+
+  *)
+    # Assume MSVC wrapper
+    library_names_spec='${libname}`echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext} $libname.lib'
+    dynamic_linker='Win32 ld.exe'
+    ;;
+  esac
+  # FIXME: first we should search . and the directory the executable is in
+  shlibpath_var=PATH
+  ;;
+
+darwin* | rhapsody*)
+  dynamic_linker="$host_os dyld"
+  version_type=darwin
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${major}$shared_ext ${libname}$shared_ext'
+  soname_spec='${libname}${release}${major}$shared_ext'
+  shlibpath_overrides_runpath=yes
+  shlibpath_var=DYLD_LIBRARY_PATH
+  shrext_cmds='`test .$module = .yes && echo .so || echo .dylib`'
+m4_if([$1], [],[
+  sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/local/lib"])
+  sys_lib_dlsearch_path_spec='/usr/local/lib /lib /usr/lib'
+  ;;
+
+dgux*)
+  version_type=linux # correct to gnu/linux during the next big refactor
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname$shared_ext'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  ;;
+
+freebsd* | dragonfly*)
+  # DragonFly does not have aout.  When/if they implement a new
+  # versioning mechanism, adjust this.
+  if test -x /usr/bin/objformat; then
+    objformat=`/usr/bin/objformat`
+  else
+    case $host_os in
+    freebsd[[23]].*) objformat=aout ;;
+    *) objformat=elf ;;
+    esac
+  fi
+  version_type=freebsd-$objformat
+  case $version_type in
+    freebsd-elf*)
+      library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}'
+      need_version=no
+      need_lib_prefix=no
+      ;;
+    freebsd-*)
+      library_names_spec='${libname}${release}${shared_ext}$versuffix $libname${shared_ext}$versuffix'
+      need_version=yes
+      ;;
+  esac
+  shlibpath_var=LD_LIBRARY_PATH
+  case $host_os in
+  freebsd2.*)
+    shlibpath_overrides_runpath=yes
+    ;;
+  freebsd3.[[01]]* | freebsdelf3.[[01]]*)
+    shlibpath_overrides_runpath=yes
+    hardcode_into_libs=yes
+    ;;
+  freebsd3.[[2-9]]* | freebsdelf3.[[2-9]]* | \
+  freebsd4.[[0-5]] | freebsdelf4.[[0-5]] | freebsd4.1.1 | freebsdelf4.1.1)
+    shlibpath_overrides_runpath=no
+    hardcode_into_libs=yes
+    ;;
+  *) # from 4.6 on, and DragonFly
+    shlibpath_overrides_runpath=yes
+    hardcode_into_libs=yes
+    ;;
+  esac
+  ;;
+
+haiku*)
+  version_type=linux # correct to gnu/linux during the next big refactor
+  need_lib_prefix=no
+  need_version=no
+  dynamic_linker="$host_os runtime_loader"
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}${major} ${libname}${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  sys_lib_dlsearch_path_spec='/boot/home/config/lib /boot/common/lib /boot/system/lib'
+  hardcode_into_libs=yes
+  ;;
+
+hpux9* | hpux10* | hpux11*)
+  # Give a soname corresponding to the major version so that dld.sl refuses to
+  # link against other versions.
+  version_type=sunos
+  need_lib_prefix=no
+  need_version=no
+  case $host_cpu in
+  ia64*)
+    shrext_cmds='.so'
+    hardcode_into_libs=yes
+    dynamic_linker="$host_os dld.so"
+    shlibpath_var=LD_LIBRARY_PATH
+    shlibpath_overrides_runpath=yes # Unless +noenvvar is specified.
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    if test "X$HPUX_IA64_MODE" = X32; then
+      sys_lib_search_path_spec="/usr/lib/hpux32 /usr/local/lib/hpux32 /usr/local/lib"
+    else
+      sys_lib_search_path_spec="/usr/lib/hpux64 /usr/local/lib/hpux64"
+    fi
+    sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec
+    ;;
+  hppa*64*)
+    shrext_cmds='.sl'
+    hardcode_into_libs=yes
+    dynamic_linker="$host_os dld.sl"
+    shlibpath_var=LD_LIBRARY_PATH # How should we handle SHLIB_PATH
+    shlibpath_overrides_runpath=yes # Unless +noenvvar is specified.
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    sys_lib_search_path_spec="/usr/lib/pa20_64 /usr/ccs/lib/pa20_64"
+    sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec
+    ;;
+  *)
+    shrext_cmds='.sl'
+    dynamic_linker="$host_os dld.sl"
+    shlibpath_var=SHLIB_PATH
+    shlibpath_overrides_runpath=no # +s is required to enable SHLIB_PATH
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    ;;
+  esac
+  # HP-UX runs *really* slowly unless shared libraries are mode 555, ...
+  postinstall_cmds='chmod 555 $lib'
+  # or fails outright, so override atomically:
+  install_override_mode=555
+  ;;
+
+interix[[3-9]]*)
+  version_type=linux # correct to gnu/linux during the next big refactor
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  dynamic_linker='Interix 3.x ld.so.1 (PE, like ELF)'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  hardcode_into_libs=yes
+  ;;
+
+irix5* | irix6* | nonstopux*)
+  case $host_os in
+    nonstopux*) version_type=nonstopux ;;
+    *)
+       if test "$lt_cv_prog_gnu_ld" = yes; then
+               version_type=linux # correct to gnu/linux during the next big refactor
+       else
+               version_type=irix
+       fi ;;
+  esac
+  need_lib_prefix=no
+  need_version=no
+  soname_spec='${libname}${release}${shared_ext}$major'
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext} $libname${shared_ext}'
+  case $host_os in
+  irix5* | nonstopux*)
+    libsuff= shlibsuff=
+    ;;
+  *)
+    case $LD in # libtool.m4 will add one of these switches to LD
+    *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ")
+      libsuff= shlibsuff= libmagic=32-bit;;
+    *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ")
+      libsuff=32 shlibsuff=N32 libmagic=N32;;
+    *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ")
+      libsuff=64 shlibsuff=64 libmagic=64-bit;;
+    *) libsuff= shlibsuff= libmagic=never-match;;
+    esac
+    ;;
+  esac
+  shlibpath_var=LD_LIBRARY${shlibsuff}_PATH
+  shlibpath_overrides_runpath=no
+  sys_lib_search_path_spec="/usr/lib${libsuff} /lib${libsuff} /usr/local/lib${libsuff}"
+  sys_lib_dlsearch_path_spec="/usr/lib${libsuff} /lib${libsuff}"
+  hardcode_into_libs=yes
+  ;;
+
+# No shared lib support for Linux oldld, aout, or coff.
+linux*oldld* | linux*aout* | linux*coff*)
+  dynamic_linker=no
+  ;;
+
+# This must be glibc/ELF.
+linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*)
+  version_type=linux # correct to gnu/linux during the next big refactor
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  finish_cmds='PATH="\$PATH:/sbin" ldconfig -n $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+
+  # Some binutils ld are patched to set DT_RUNPATH
+  AC_CACHE_VAL([lt_cv_shlibpath_overrides_runpath],
+    [lt_cv_shlibpath_overrides_runpath=no
+    save_LDFLAGS=$LDFLAGS
+    save_libdir=$libdir
+    eval "libdir=/foo; wl=\"$_LT_TAGVAR(lt_prog_compiler_wl, $1)\"; \
+        LDFLAGS=\"\$LDFLAGS $_LT_TAGVAR(hardcode_libdir_flag_spec, $1)\""
+    AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])],
+      [AS_IF([ ($OBJDUMP -p conftest$ac_exeext) 2>/dev/null | grep "RUNPATH.*$libdir" >/dev/null],
+        [lt_cv_shlibpath_overrides_runpath=yes])])
+    LDFLAGS=$save_LDFLAGS
+    libdir=$save_libdir
+    ])
+  shlibpath_overrides_runpath=$lt_cv_shlibpath_overrides_runpath
+
+  # This implies no fast_install, which is unacceptable.
+  # Some rework will be needed to allow for fast_install
+  # before this can be enabled.
+  hardcode_into_libs=yes
+
+  # Append ld.so.conf contents to the search path
+  if test -f /etc/ld.so.conf; then
+    lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \[$]2)); skip = 1; } { if (!skip) print \[$]0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[  ]*hwcap[        ]/d;s/[:,      ]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;s/"//g;/^$/d' | tr '\n' ' '`
+    sys_lib_dlsearch_path_spec="/lib /usr/lib $lt_ld_extra"
+  fi
+
+  # We used to test for /lib/ld.so.1 and disable shared libraries on
+  # powerpc, because MkLinux only supported shared libraries with the
+  # GNU dynamic linker.  Since this was broken with cross compilers,
+  # most powerpc-linux boxes support dynamic linking these days and
+  # people can always --disable-shared, the test was removed, and we
+  # assume the GNU/Linux dynamic linker is in use.
+  dynamic_linker='GNU/Linux ld.so'
+  ;;
+
+netbsdelf*-gnu)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  hardcode_into_libs=yes
+  dynamic_linker='NetBSD ld.elf_so'
+  ;;
+
+netbsd*)
+  version_type=sunos
+  need_lib_prefix=no
+  need_version=no
+  if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
+    finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir'
+    dynamic_linker='NetBSD (a.out) ld.so'
+  else
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    dynamic_linker='NetBSD ld.elf_so'
+  fi
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  hardcode_into_libs=yes
+  ;;
+
+newsos6)
+  version_type=linux # correct to gnu/linux during the next big refactor
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  ;;
+
+*nto* | *qnx*)
+  version_type=qnx
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  hardcode_into_libs=yes
+  dynamic_linker='ldqnx.so'
+  ;;
+
+openbsd*)
+  version_type=sunos
+  sys_lib_dlsearch_path_spec="/usr/lib"
+  need_lib_prefix=no
+  # Some older versions of OpenBSD (3.3 at least) *do* need versioned libs.
+  case $host_os in
+    openbsd3.3 | openbsd3.3.*) need_version=yes ;;
+    *)                         need_version=no  ;;
+  esac
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
+  finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
+    case $host_os in
+      openbsd2.[[89]] | openbsd2.[[89]].*)
+       shlibpath_overrides_runpath=no
+       ;;
+      *)
+       shlibpath_overrides_runpath=yes
+       ;;
+      esac
+  else
+    shlibpath_overrides_runpath=yes
+  fi
+  ;;
+
+os2*)
+  libname_spec='$name'
+  shrext_cmds=".dll"
+  need_lib_prefix=no
+  library_names_spec='$libname${shared_ext} $libname.a'
+  dynamic_linker='OS/2 ld.exe'
+  shlibpath_var=LIBPATH
+  ;;
+
+osf3* | osf4* | osf5*)
+  version_type=osf
+  need_lib_prefix=no
+  need_version=no
+  soname_spec='${libname}${release}${shared_ext}$major'
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  shlibpath_var=LD_LIBRARY_PATH
+  sys_lib_search_path_spec="/usr/shlib /usr/ccs/lib /usr/lib/cmplrs/cc /usr/lib /usr/local/lib /var/shlib"
+  sys_lib_dlsearch_path_spec="$sys_lib_search_path_spec"
+  ;;
+
+rdos*)
+  dynamic_linker=no
+  ;;
+
+solaris*)
+  version_type=linux # correct to gnu/linux during the next big refactor
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  hardcode_into_libs=yes
+  # ldd complains unless libraries are executable
+  postinstall_cmds='chmod +x $lib'
+  ;;
+
+sunos4*)
+  version_type=sunos
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
+  finish_cmds='PATH="\$PATH:/usr/etc" ldconfig $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  if test "$with_gnu_ld" = yes; then
+    need_lib_prefix=no
+  fi
+  need_version=yes
+  ;;
+
+sysv4 | sysv4.3*)
+  version_type=linux # correct to gnu/linux during the next big refactor
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  case $host_vendor in
+    sni)
+      shlibpath_overrides_runpath=no
+      need_lib_prefix=no
+      runpath_var=LD_RUN_PATH
+      ;;
+    siemens)
+      need_lib_prefix=no
+      ;;
+    motorola)
+      need_lib_prefix=no
+      need_version=no
+      shlibpath_overrides_runpath=no
+      sys_lib_search_path_spec='/lib /usr/lib /usr/ccs/lib'
+      ;;
+  esac
+  ;;
+
+sysv4*MP*)
+  if test -d /usr/nec ;then
+    version_type=linux # correct to gnu/linux during the next big refactor
+    library_names_spec='$libname${shared_ext}.$versuffix $libname${shared_ext}.$major $libname${shared_ext}'
+    soname_spec='$libname${shared_ext}.$major'
+    shlibpath_var=LD_LIBRARY_PATH
+  fi
+  ;;
+
+sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*)
+  version_type=freebsd-elf
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  hardcode_into_libs=yes
+  if test "$with_gnu_ld" = yes; then
+    sys_lib_search_path_spec='/usr/local/lib /usr/gnu/lib /usr/ccs/lib /usr/lib /lib'
+  else
+    sys_lib_search_path_spec='/usr/ccs/lib /usr/lib'
+    case $host_os in
+      sco3.2v5*)
+        sys_lib_search_path_spec="$sys_lib_search_path_spec /lib"
+       ;;
+    esac
+  fi
+  sys_lib_dlsearch_path_spec='/usr/lib'
+  ;;
+
+tpf*)
+  # TPF is a cross-target only.  Preferred cross-host = GNU/Linux.
+  version_type=linux # correct to gnu/linux during the next big refactor
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  hardcode_into_libs=yes
+  ;;
+
+uts4*)
+  version_type=linux # correct to gnu/linux during the next big refactor
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  ;;
+
+*)
+  dynamic_linker=no
+  ;;
+esac
+AC_MSG_RESULT([$dynamic_linker])
+test "$dynamic_linker" = no && can_build_shared=no
+
+variables_saved_for_relink="PATH $shlibpath_var $runpath_var"
+if test "$GCC" = yes; then
+  variables_saved_for_relink="$variables_saved_for_relink GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH"
+fi
+
+if test "${lt_cv_sys_lib_search_path_spec+set}" = set; then
+  sys_lib_search_path_spec="$lt_cv_sys_lib_search_path_spec"
+fi
+if test "${lt_cv_sys_lib_dlsearch_path_spec+set}" = set; then
+  sys_lib_dlsearch_path_spec="$lt_cv_sys_lib_dlsearch_path_spec"
+fi
+
+_LT_DECL([], [variables_saved_for_relink], [1],
+    [Variables whose values should be saved in libtool wrapper scripts and
+    restored at link time])
+_LT_DECL([], [need_lib_prefix], [0],
+    [Do we need the "lib" prefix for modules?])
+_LT_DECL([], [need_version], [0], [Do we need a version for libraries?])
+_LT_DECL([], [version_type], [0], [Library versioning type])
+_LT_DECL([], [runpath_var], [0],  [Shared library runtime path variable])
+_LT_DECL([], [shlibpath_var], [0],[Shared library path variable])
+_LT_DECL([], [shlibpath_overrides_runpath], [0],
+    [Is shlibpath searched before the hard-coded library search path?])
+_LT_DECL([], [libname_spec], [1], [Format of library name prefix])
+_LT_DECL([], [library_names_spec], [1],
+    [[List of archive names.  First name is the real one, the rest are links.
+    The last name is the one that the linker finds with -lNAME]])
+_LT_DECL([], [soname_spec], [1],
+    [[The coded name of the library, if different from the real name]])
+_LT_DECL([], [install_override_mode], [1],
+    [Permission mode override for installation of shared libraries])
+_LT_DECL([], [postinstall_cmds], [2],
+    [Command to use after installation of a shared archive])
+_LT_DECL([], [postuninstall_cmds], [2],
+    [Command to use after uninstallation of a shared archive])
+_LT_DECL([], [finish_cmds], [2],
+    [Commands used to finish a libtool library installation in a directory])
+_LT_DECL([], [finish_eval], [1],
+    [[As "finish_cmds", except a single script fragment to be evaled but
+    not shown]])
+_LT_DECL([], [hardcode_into_libs], [0],
+    [Whether we should hardcode library paths into libraries])
+_LT_DECL([], [sys_lib_search_path_spec], [2],
+    [Compile-time system search path for libraries])
+_LT_DECL([], [sys_lib_dlsearch_path_spec], [2],
+    [Run-time system search path for libraries])
+])# _LT_SYS_DYNAMIC_LINKER
+
+
+# _LT_PATH_TOOL_PREFIX(TOOL)
+# --------------------------
+# find a file program which can recognize shared library
+AC_DEFUN([_LT_PATH_TOOL_PREFIX],
+[m4_require([_LT_DECL_EGREP])dnl
+AC_MSG_CHECKING([for $1])
+AC_CACHE_VAL(lt_cv_path_MAGIC_CMD,
+[case $MAGIC_CMD in
+[[\\/*] |  ?:[\\/]*])
+  lt_cv_path_MAGIC_CMD="$MAGIC_CMD" # Let the user override the test with a path.
+  ;;
+*)
+  lt_save_MAGIC_CMD="$MAGIC_CMD"
+  lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
+dnl $ac_dummy forces splitting on constant user-supplied paths.
+dnl POSIX.2 word splitting is done only on the output of word expansions,
+dnl not every word.  This closes a longstanding sh security hole.
+  ac_dummy="m4_if([$2], , $PATH, [$2])"
+  for ac_dir in $ac_dummy; do
+    IFS="$lt_save_ifs"
+    test -z "$ac_dir" && ac_dir=.
+    if test -f $ac_dir/$1; then
+      lt_cv_path_MAGIC_CMD="$ac_dir/$1"
+      if test -n "$file_magic_test_file"; then
+       case $deplibs_check_method in
+       "file_magic "*)
+         file_magic_regex=`expr "$deplibs_check_method" : "file_magic \(.*\)"`
+         MAGIC_CMD="$lt_cv_path_MAGIC_CMD"
+         if eval $file_magic_cmd \$file_magic_test_file 2> /dev/null |
+           $EGREP "$file_magic_regex" > /dev/null; then
+           :
+         else
+           cat <<_LT_EOF 1>&2
+
+*** Warning: the command libtool uses to detect shared libraries,
+*** $file_magic_cmd, produces output that libtool cannot recognize.
+*** The result is that libtool may fail to recognize shared libraries
+*** as such.  This will affect the creation of libtool libraries that
+*** depend on shared libraries, but programs linked with such libtool
+*** libraries will work regardless of this problem.  Nevertheless, you
+*** may want to report the problem to your system manager and/or to
+*** bug-libtool@gnu.org
+
+_LT_EOF
+         fi ;;
+       esac
+      fi
+      break
+    fi
+  done
+  IFS="$lt_save_ifs"
+  MAGIC_CMD="$lt_save_MAGIC_CMD"
+  ;;
+esac])
+MAGIC_CMD="$lt_cv_path_MAGIC_CMD"
+if test -n "$MAGIC_CMD"; then
+  AC_MSG_RESULT($MAGIC_CMD)
+else
+  AC_MSG_RESULT(no)
+fi
+_LT_DECL([], [MAGIC_CMD], [0],
+        [Used to examine libraries when file_magic_cmd begins with "file"])dnl
+])# _LT_PATH_TOOL_PREFIX
+
+# Old name:
+AU_ALIAS([AC_PATH_TOOL_PREFIX], [_LT_PATH_TOOL_PREFIX])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_PATH_TOOL_PREFIX], [])
+
+
+# _LT_PATH_MAGIC
+# --------------
+# find a file program which can recognize a shared library
+m4_defun([_LT_PATH_MAGIC],
+[_LT_PATH_TOOL_PREFIX(${ac_tool_prefix}file, /usr/bin$PATH_SEPARATOR$PATH)
+if test -z "$lt_cv_path_MAGIC_CMD"; then
+  if test -n "$ac_tool_prefix"; then
+    _LT_PATH_TOOL_PREFIX(file, /usr/bin$PATH_SEPARATOR$PATH)
+  else
+    MAGIC_CMD=:
+  fi
+fi
+])# _LT_PATH_MAGIC
+
+
+# LT_PATH_LD
+# ----------
+# find the pathname to the GNU or non-GNU linker
+AC_DEFUN([LT_PATH_LD],
+[AC_REQUIRE([AC_PROG_CC])dnl
+AC_REQUIRE([AC_CANONICAL_HOST])dnl
+AC_REQUIRE([AC_CANONICAL_BUILD])dnl
+m4_require([_LT_DECL_SED])dnl
+m4_require([_LT_DECL_EGREP])dnl
+m4_require([_LT_PROG_ECHO_BACKSLASH])dnl
+
+AC_ARG_WITH([gnu-ld],
+    [AS_HELP_STRING([--with-gnu-ld],
+       [assume the C compiler uses GNU ld @<:@default=no@:>@])],
+    [test "$withval" = no || with_gnu_ld=yes],
+    [with_gnu_ld=no])dnl
+
+ac_prog=ld
+if test "$GCC" = yes; then
+  # Check if gcc -print-prog-name=ld gives a path.
+  AC_MSG_CHECKING([for ld used by $CC])
+  case $host in
+  *-*-mingw*)
+    # gcc leaves a trailing carriage return which upsets mingw
+    ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;;
+  *)
+    ac_prog=`($CC -print-prog-name=ld) 2>&5` ;;
+  esac
+  case $ac_prog in
+    # Accept absolute paths.
+    [[\\/]]* | ?:[[\\/]]*)
+      re_direlt='/[[^/]][[^/]]*/\.\./'
+      # Canonicalize the pathname of ld
+      ac_prog=`$ECHO "$ac_prog"| $SED 's%\\\\%/%g'`
+      while $ECHO "$ac_prog" | $GREP "$re_direlt" > /dev/null 2>&1; do
+       ac_prog=`$ECHO $ac_prog| $SED "s%$re_direlt%/%"`
+      done
+      test -z "$LD" && LD="$ac_prog"
+      ;;
+  "")
+    # If it fails, then pretend we aren't using GCC.
+    ac_prog=ld
+    ;;
+  *)
+    # If it is relative, then search for the first ld in PATH.
+    with_gnu_ld=unknown
+    ;;
+  esac
+elif test "$with_gnu_ld" = yes; then
+  AC_MSG_CHECKING([for GNU ld])
+else
+  AC_MSG_CHECKING([for non-GNU ld])
+fi
+AC_CACHE_VAL(lt_cv_path_LD,
+[if test -z "$LD"; then
+  lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
+  for ac_dir in $PATH; do
+    IFS="$lt_save_ifs"
+    test -z "$ac_dir" && ac_dir=.
+    if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then
+      lt_cv_path_LD="$ac_dir/$ac_prog"
+      # Check to see if the program is GNU ld.  I'd rather use --version,
+      # but apparently some variants of GNU ld only accept -v.
+      # Break only if it was the GNU/non-GNU ld that we prefer.
+      case `"$lt_cv_path_LD" -v 2>&1 </dev/null` in
+      *GNU* | *'with BFD'*)
+       test "$with_gnu_ld" != no && break
+       ;;
+      *)
+       test "$with_gnu_ld" != yes && break
+       ;;
+      esac
+    fi
+  done
+  IFS="$lt_save_ifs"
+else
+  lt_cv_path_LD="$LD" # Let the user override the test with a path.
+fi])
+LD="$lt_cv_path_LD"
+if test -n "$LD"; then
+  AC_MSG_RESULT($LD)
+else
+  AC_MSG_RESULT(no)
+fi
+test -z "$LD" && AC_MSG_ERROR([no acceptable ld found in \$PATH])
+_LT_PATH_LD_GNU
+AC_SUBST([LD])
+
+_LT_TAGDECL([], [LD], [1], [The linker used to build libraries])
+])# LT_PATH_LD
+
+# Old names:
+AU_ALIAS([AM_PROG_LD], [LT_PATH_LD])
+AU_ALIAS([AC_PROG_LD], [LT_PATH_LD])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AM_PROG_LD], [])
+dnl AC_DEFUN([AC_PROG_LD], [])
+
+
+# _LT_PATH_LD_GNU
+#- --------------
+m4_defun([_LT_PATH_LD_GNU],
+[AC_CACHE_CHECK([if the linker ($LD) is GNU ld], lt_cv_prog_gnu_ld,
+[# I'd rather use --version here, but apparently some GNU lds only accept -v.
+case `$LD -v 2>&1 </dev/null` in
+*GNU* | *'with BFD'*)
+  lt_cv_prog_gnu_ld=yes
+  ;;
+*)
+  lt_cv_prog_gnu_ld=no
+  ;;
+esac])
+with_gnu_ld=$lt_cv_prog_gnu_ld
+])# _LT_PATH_LD_GNU
+
+
+# _LT_CMD_RELOAD
+# --------------
+# find reload flag for linker
+#   -- PORTME Some linkers may need a different reload flag.
+m4_defun([_LT_CMD_RELOAD],
+[AC_CACHE_CHECK([for $LD option to reload object files],
+  lt_cv_ld_reload_flag,
+  [lt_cv_ld_reload_flag='-r'])
+reload_flag=$lt_cv_ld_reload_flag
+case $reload_flag in
+"" | " "*) ;;
+*) reload_flag=" $reload_flag" ;;
+esac
+reload_cmds='$LD$reload_flag -o $output$reload_objs'
+case $host_os in
+  cygwin* | mingw* | pw32* | cegcc*)
+    if test "$GCC" != yes; then
+      reload_cmds=false
+    fi
+    ;;
+  darwin*)
+    if test "$GCC" = yes; then
+      reload_cmds='$LTCC $LTCFLAGS -nostdlib ${wl}-r -o $output$reload_objs'
+    else
+      reload_cmds='$LD$reload_flag -o $output$reload_objs'
+    fi
+    ;;
+esac
+_LT_TAGDECL([], [reload_flag], [1], [How to create reloadable object files])dnl
+_LT_TAGDECL([], [reload_cmds], [2])dnl
+])# _LT_CMD_RELOAD
+
+
+# _LT_CHECK_MAGIC_METHOD
+# ----------------------
+# how to check for library dependencies
+#  -- PORTME fill in with the dynamic library characteristics
+m4_defun([_LT_CHECK_MAGIC_METHOD],
+[m4_require([_LT_DECL_EGREP])
+m4_require([_LT_DECL_OBJDUMP])
+AC_CACHE_CHECK([how to recognize dependent libraries],
+lt_cv_deplibs_check_method,
+[lt_cv_file_magic_cmd='$MAGIC_CMD'
+lt_cv_file_magic_test_file=
+lt_cv_deplibs_check_method='unknown'
+# Need to set the preceding variable on all platforms that support
+# interlibrary dependencies.
+# 'none' -- dependencies not supported.
+# `unknown' -- same as none, but documents that we really don't know.
+# 'pass_all' -- all dependencies passed with no checks.
+# 'test_compile' -- check by making test program.
+# 'file_magic [[regex]]' -- check by looking for files in library path
+# which responds to the $file_magic_cmd with a given extended regex.
+# If you have `file' or equivalent on your system and you're not sure
+# whether `pass_all' will *always* work, you probably want this one.
+
+case $host_os in
+aix[[4-9]]*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+beos*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+bsdi[[45]]*)
+  lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (shared object|dynamic lib)'
+  lt_cv_file_magic_cmd='/usr/bin/file -L'
+  lt_cv_file_magic_test_file=/shlib/libc.so
+  ;;
+
+cygwin*)
+  # func_win32_libid is a shell function defined in ltmain.sh
+  lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL'
+  lt_cv_file_magic_cmd='func_win32_libid'
+  ;;
+
+mingw* | pw32*)
+  # Base MSYS/MinGW do not provide the 'file' command needed by
+  # func_win32_libid shell function, so use a weaker test based on 'objdump',
+  # unless we find 'file', for example because we are cross-compiling.
+  # func_win32_libid assumes BSD nm, so disallow it if using MS dumpbin.
+  if ( test "$lt_cv_nm_interface" = "BSD nm" && file / ) >/dev/null 2>&1; then
+    lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL'
+    lt_cv_file_magic_cmd='func_win32_libid'
+  else
+    # Keep this pattern in sync with the one in func_win32_libid.
+    lt_cv_deplibs_check_method='file_magic file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)'
+    lt_cv_file_magic_cmd='$OBJDUMP -f'
+  fi
+  ;;
+
+cegcc*)
+  # use the weaker test based on 'objdump'. See mingw*.
+  lt_cv_deplibs_check_method='file_magic file format pe-arm-.*little(.*architecture: arm)?'
+  lt_cv_file_magic_cmd='$OBJDUMP -f'
+  ;;
+
+darwin* | rhapsody*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+freebsd* | dragonfly*)
+  if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then
+    case $host_cpu in
+    i*86 )
+      # Not sure whether the presence of OpenBSD here was a mistake.
+      # Let's accept both of them until this is cleared up.
+      lt_cv_deplibs_check_method='file_magic (FreeBSD|OpenBSD|DragonFly)/i[[3-9]]86 (compact )?demand paged shared library'
+      lt_cv_file_magic_cmd=/usr/bin/file
+      lt_cv_file_magic_test_file=`echo /usr/lib/libc.so.*`
+      ;;
+    esac
+  else
+    lt_cv_deplibs_check_method=pass_all
+  fi
+  ;;
+
+haiku*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+hpux10.20* | hpux11*)
+  lt_cv_file_magic_cmd=/usr/bin/file
+  case $host_cpu in
+  ia64*)
+    lt_cv_deplibs_check_method='file_magic (s[[0-9]][[0-9]][[0-9]]|ELF-[[0-9]][[0-9]]) shared object file - IA64'
+    lt_cv_file_magic_test_file=/usr/lib/hpux32/libc.so
+    ;;
+  hppa*64*)
+    [lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF[ -][0-9][0-9])(-bit)?( [LM]SB)? shared object( file)?[, -]* PA-RISC [0-9]\.[0-9]']
+    lt_cv_file_magic_test_file=/usr/lib/pa20_64/libc.sl
+    ;;
+  *)
+    lt_cv_deplibs_check_method='file_magic (s[[0-9]][[0-9]][[0-9]]|PA-RISC[[0-9]]\.[[0-9]]) shared library'
+    lt_cv_file_magic_test_file=/usr/lib/libc.sl
+    ;;
+  esac
+  ;;
+
+interix[[3-9]]*)
+  # PIC code is broken on Interix 3.x, that's why |\.a not |_pic\.a here
+  lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so|\.a)$'
+  ;;
+
+irix5* | irix6* | nonstopux*)
+  case $LD in
+  *-32|*"-32 ") libmagic=32-bit;;
+  *-n32|*"-n32 ") libmagic=N32;;
+  *-64|*"-64 ") libmagic=64-bit;;
+  *) libmagic=never-match;;
+  esac
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+# This must be glibc/ELF.
+linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+netbsd* | netbsdelf*-gnu)
+  if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then
+    lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$'
+  else
+    lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so|_pic\.a)$'
+  fi
+  ;;
+
+newos6*)
+  lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (executable|dynamic lib)'
+  lt_cv_file_magic_cmd=/usr/bin/file
+  lt_cv_file_magic_test_file=/usr/lib/libnls.so
+  ;;
+
+*nto* | *qnx*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+openbsd*)
+  if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
+    lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|\.so|_pic\.a)$'
+  else
+    lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$'
+  fi
+  ;;
+
+osf3* | osf4* | osf5*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+rdos*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+solaris*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+sysv4 | sysv4.3*)
+  case $host_vendor in
+  motorola)
+    lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (shared object|dynamic lib) M[[0-9]][[0-9]]* Version [[0-9]]'
+    lt_cv_file_magic_test_file=`echo /usr/lib/libc.so*`
+    ;;
+  ncr)
+    lt_cv_deplibs_check_method=pass_all
+    ;;
+  sequent)
+    lt_cv_file_magic_cmd='/bin/file'
+    lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[LM]]SB (shared object|dynamic lib )'
+    ;;
+  sni)
+    lt_cv_file_magic_cmd='/bin/file'
+    lt_cv_deplibs_check_method="file_magic ELF [[0-9]][[0-9]]*-bit [[LM]]SB dynamic lib"
+    lt_cv_file_magic_test_file=/lib/libc.so
+    ;;
+  siemens)
+    lt_cv_deplibs_check_method=pass_all
+    ;;
+  pc)
+    lt_cv_deplibs_check_method=pass_all
+    ;;
+  esac
+  ;;
+
+tpf*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+esac
+])
+
+file_magic_glob=
+want_nocaseglob=no
+if test "$build" = "$host"; then
+  case $host_os in
+  mingw* | pw32*)
+    if ( shopt | grep nocaseglob ) >/dev/null 2>&1; then
+      want_nocaseglob=yes
+    else
+      file_magic_glob=`echo aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ | $SED -e "s/\(..\)/s\/[[\1]]\/[[\1]]\/g;/g"`
+    fi
+    ;;
+  esac
+fi
+
+file_magic_cmd=$lt_cv_file_magic_cmd
+deplibs_check_method=$lt_cv_deplibs_check_method
+test -z "$deplibs_check_method" && deplibs_check_method=unknown
+
+_LT_DECL([], [deplibs_check_method], [1],
+    [Method to check whether dependent libraries are shared objects])
+_LT_DECL([], [file_magic_cmd], [1],
+    [Command to use when deplibs_check_method = "file_magic"])
+_LT_DECL([], [file_magic_glob], [1],
+    [How to find potential files when deplibs_check_method = "file_magic"])
+_LT_DECL([], [want_nocaseglob], [1],
+    [Find potential files using nocaseglob when deplibs_check_method = "file_magic"])
+])# _LT_CHECK_MAGIC_METHOD
+
+
+# LT_PATH_NM
+# ----------
+# find the pathname to a BSD- or MS-compatible name lister
+AC_DEFUN([LT_PATH_NM],
+[AC_REQUIRE([AC_PROG_CC])dnl
+AC_CACHE_CHECK([for BSD- or MS-compatible name lister (nm)], lt_cv_path_NM,
+[if test -n "$NM"; then
+  # Let the user override the test.
+  lt_cv_path_NM="$NM"
+else
+  lt_nm_to_check="${ac_tool_prefix}nm"
+  if test -n "$ac_tool_prefix" && test "$build" = "$host"; then
+    lt_nm_to_check="$lt_nm_to_check nm"
+  fi
+  for lt_tmp_nm in $lt_nm_to_check; do
+    lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
+    for ac_dir in $PATH /usr/ccs/bin/elf /usr/ccs/bin /usr/ucb /bin; do
+      IFS="$lt_save_ifs"
+      test -z "$ac_dir" && ac_dir=.
+      tmp_nm="$ac_dir/$lt_tmp_nm"
+      if test -f "$tmp_nm" || test -f "$tmp_nm$ac_exeext" ; then
+       # Check to see if the nm accepts a BSD-compat flag.
+       # Adding the `sed 1q' prevents false positives on HP-UX, which says:
+       #   nm: unknown option "B" ignored
+       # Tru64's nm complains that /dev/null is an invalid object file
+       case `"$tmp_nm" -B /dev/null 2>&1 | sed '1q'` in
+       */dev/null* | *'Invalid file or object type'*)
+         lt_cv_path_NM="$tmp_nm -B"
+         break
+         ;;
+       *)
+         case `"$tmp_nm" -p /dev/null 2>&1 | sed '1q'` in
+         */dev/null*)
+           lt_cv_path_NM="$tmp_nm -p"
+           break
+           ;;
+         *)
+           lt_cv_path_NM=${lt_cv_path_NM="$tmp_nm"} # keep the first match, but
+           continue # so that we can try to find one that supports BSD flags
+           ;;
+         esac
+         ;;
+       esac
+      fi
+    done
+    IFS="$lt_save_ifs"
+  done
+  : ${lt_cv_path_NM=no}
+fi])
+if test "$lt_cv_path_NM" != "no"; then
+  NM="$lt_cv_path_NM"
+else
+  # Didn't find any BSD compatible name lister, look for dumpbin.
+  if test -n "$DUMPBIN"; then :
+    # Let the user override the test.
+  else
+    AC_CHECK_TOOLS(DUMPBIN, [dumpbin "link -dump"], :)
+    case `$DUMPBIN -symbols /dev/null 2>&1 | sed '1q'` in
+    *COFF*)
+      DUMPBIN="$DUMPBIN -symbols"
+      ;;
+    *)
+      DUMPBIN=:
+      ;;
+    esac
+  fi
+  AC_SUBST([DUMPBIN])
+  if test "$DUMPBIN" != ":"; then
+    NM="$DUMPBIN"
+  fi
+fi
+test -z "$NM" && NM=nm
+AC_SUBST([NM])
+_LT_DECL([], [NM], [1], [A BSD- or MS-compatible name lister])dnl
+
+AC_CACHE_CHECK([the name lister ($NM) interface], [lt_cv_nm_interface],
+  [lt_cv_nm_interface="BSD nm"
+  echo "int some_variable = 0;" > conftest.$ac_ext
+  (eval echo "\"\$as_me:$LINENO: $ac_compile\"" >&AS_MESSAGE_LOG_FD)
+  (eval "$ac_compile" 2>conftest.err)
+  cat conftest.err >&AS_MESSAGE_LOG_FD
+  (eval echo "\"\$as_me:$LINENO: $NM \\\"conftest.$ac_objext\\\"\"" >&AS_MESSAGE_LOG_FD)
+  (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out)
+  cat conftest.err >&AS_MESSAGE_LOG_FD
+  (eval echo "\"\$as_me:$LINENO: output\"" >&AS_MESSAGE_LOG_FD)
+  cat conftest.out >&AS_MESSAGE_LOG_FD
+  if $GREP 'External.*some_variable' conftest.out > /dev/null; then
+    lt_cv_nm_interface="MS dumpbin"
+  fi
+  rm -f conftest*])
+])# LT_PATH_NM
+
+# Old names:
+AU_ALIAS([AM_PROG_NM], [LT_PATH_NM])
+AU_ALIAS([AC_PROG_NM], [LT_PATH_NM])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AM_PROG_NM], [])
+dnl AC_DEFUN([AC_PROG_NM], [])
+
+# _LT_CHECK_SHAREDLIB_FROM_LINKLIB
+# --------------------------------
+# how to determine the name of the shared library
+# associated with a specific link library.
+#  -- PORTME fill in with the dynamic library characteristics
+m4_defun([_LT_CHECK_SHAREDLIB_FROM_LINKLIB],
+[m4_require([_LT_DECL_EGREP])
+m4_require([_LT_DECL_OBJDUMP])
+m4_require([_LT_DECL_DLLTOOL])
+AC_CACHE_CHECK([how to associate runtime and link libraries],
+lt_cv_sharedlib_from_linklib_cmd,
+[lt_cv_sharedlib_from_linklib_cmd='unknown'
+
+case $host_os in
+cygwin* | mingw* | pw32* | cegcc*)
+  # two different shell functions defined in ltmain.sh
+  # decide which to use based on capabilities of $DLLTOOL
+  case `$DLLTOOL --help 2>&1` in
+  *--identify-strict*)
+    lt_cv_sharedlib_from_linklib_cmd=func_cygming_dll_for_implib
+    ;;
+  *)
+    lt_cv_sharedlib_from_linklib_cmd=func_cygming_dll_for_implib_fallback
+    ;;
+  esac
+  ;;
+*)
+  # fallback: assume linklib IS sharedlib
+  lt_cv_sharedlib_from_linklib_cmd="$ECHO"
+  ;;
+esac
+])
+sharedlib_from_linklib_cmd=$lt_cv_sharedlib_from_linklib_cmd
+test -z "$sharedlib_from_linklib_cmd" && sharedlib_from_linklib_cmd=$ECHO
+
+_LT_DECL([], [sharedlib_from_linklib_cmd], [1],
+    [Command to associate shared and link libraries])
+])# _LT_CHECK_SHAREDLIB_FROM_LINKLIB
+
+
+# _LT_PATH_MANIFEST_TOOL
+# ----------------------
+# locate the manifest tool
+m4_defun([_LT_PATH_MANIFEST_TOOL],
+[AC_CHECK_TOOL(MANIFEST_TOOL, mt, :)
+test -z "$MANIFEST_TOOL" && MANIFEST_TOOL=mt
+AC_CACHE_CHECK([if $MANIFEST_TOOL is a manifest tool], [lt_cv_path_mainfest_tool],
+  [lt_cv_path_mainfest_tool=no
+  echo "$as_me:$LINENO: $MANIFEST_TOOL '-?'" >&AS_MESSAGE_LOG_FD
+  $MANIFEST_TOOL '-?' 2>conftest.err > conftest.out
+  cat conftest.err >&AS_MESSAGE_LOG_FD
+  if $GREP 'Manifest Tool' conftest.out > /dev/null; then
+    lt_cv_path_mainfest_tool=yes
+  fi
+  rm -f conftest*])
+if test "x$lt_cv_path_mainfest_tool" != xyes; then
+  MANIFEST_TOOL=:
+fi
+_LT_DECL([], [MANIFEST_TOOL], [1], [Manifest tool])dnl
+])# _LT_PATH_MANIFEST_TOOL
+
+
+# LT_LIB_M
+# --------
+# check for math library
+AC_DEFUN([LT_LIB_M],
+[AC_REQUIRE([AC_CANONICAL_HOST])dnl
+LIBM=
+case $host in
+*-*-beos* | *-*-cegcc* | *-*-cygwin* | *-*-haiku* | *-*-pw32* | *-*-darwin*)
+  # These system don't have libm, or don't need it
+  ;;
+*-ncr-sysv4.3*)
+  AC_CHECK_LIB(mw, _mwvalidcheckl, LIBM="-lmw")
+  AC_CHECK_LIB(m, cos, LIBM="$LIBM -lm")
+  ;;
+*)
+  AC_CHECK_LIB(m, cos, LIBM="-lm")
+  ;;
+esac
+AC_SUBST([LIBM])
+])# LT_LIB_M
+
+# Old name:
+AU_ALIAS([AC_CHECK_LIBM], [LT_LIB_M])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_CHECK_LIBM], [])
+
+
+# _LT_COMPILER_NO_RTTI([TAGNAME])
+# -------------------------------
+m4_defun([_LT_COMPILER_NO_RTTI],
+[m4_require([_LT_TAG_COMPILER])dnl
+
+_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=
+
+if test "$GCC" = yes; then
+  case $cc_basename in
+  nvcc*)
+    _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=' -Xcompiler -fno-builtin' ;;
+  *)
+    _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=' -fno-builtin' ;;
+  esac
+
+  _LT_COMPILER_OPTION([if $compiler supports -fno-rtti -fno-exceptions],
+    lt_cv_prog_compiler_rtti_exceptions,
+    [-fno-rtti -fno-exceptions], [],
+    [_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)="$_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1) -fno-rtti -fno-exceptions"])
+fi
+_LT_TAGDECL([no_builtin_flag], [lt_prog_compiler_no_builtin_flag], [1],
+       [Compiler flag to turn off builtin functions])
+])# _LT_COMPILER_NO_RTTI
+
+
+# _LT_CMD_GLOBAL_SYMBOLS
+# ----------------------
+m4_defun([_LT_CMD_GLOBAL_SYMBOLS],
+[AC_REQUIRE([AC_CANONICAL_HOST])dnl
+AC_REQUIRE([AC_PROG_CC])dnl
+AC_REQUIRE([AC_PROG_AWK])dnl
+AC_REQUIRE([LT_PATH_NM])dnl
+AC_REQUIRE([LT_PATH_LD])dnl
+m4_require([_LT_DECL_SED])dnl
+m4_require([_LT_DECL_EGREP])dnl
+m4_require([_LT_TAG_COMPILER])dnl
+
+# Check for command to grab the raw symbol name followed by C symbol from nm.
+AC_MSG_CHECKING([command to parse $NM output from $compiler object])
+AC_CACHE_VAL([lt_cv_sys_global_symbol_pipe],
+[
+# These are sane defaults that work on at least a few old systems.
+# [They come from Ultrix.  What could be older than Ultrix?!! ;)]
+
+# Character class describing NM global symbol codes.
+symcode='[[BCDEGRST]]'
+
+# Regexp to match symbols that can be accessed directly from C.
+sympat='\([[_A-Za-z]][[_A-Za-z0-9]]*\)'
+
+# Define system-specific variables.
+case $host_os in
+aix*)
+  symcode='[[BCDT]]'
+  ;;
+cygwin* | mingw* | pw32* | cegcc*)
+  symcode='[[ABCDGISTW]]'
+  ;;
+hpux*)
+  if test "$host_cpu" = ia64; then
+    symcode='[[ABCDEGRST]]'
+  fi
+  ;;
+irix* | nonstopux*)
+  symcode='[[BCDEGRST]]'
+  ;;
+osf*)
+  symcode='[[BCDEGQRST]]'
+  ;;
+solaris*)
+  symcode='[[BDRT]]'
+  ;;
+sco3.2v5*)
+  symcode='[[DT]]'
+  ;;
+sysv4.2uw2*)
+  symcode='[[DT]]'
+  ;;
+sysv5* | sco5v6* | unixware* | OpenUNIX*)
+  symcode='[[ABDT]]'
+  ;;
+sysv4)
+  symcode='[[DFNSTU]]'
+  ;;
+esac
+
+# If we're using GNU nm, then use its standard symbol codes.
+case `$NM -V 2>&1` in
+*GNU* | *'with BFD'*)
+  symcode='[[ABCDGIRSTW]]' ;;
+esac
+
+# Transform an extracted symbol line into a proper C declaration.
+# Some systems (esp. on ia64) link data and code symbols differently,
+# so use this general approach.
+lt_cv_sys_global_symbol_to_cdecl="sed -n -e 's/^T .* \(.*\)$/extern int \1();/p' -e 's/^$symcode* .* \(.*\)$/extern char \1;/p'"
+
+# Transform an extracted symbol line into symbol name and symbol address
+lt_cv_sys_global_symbol_to_c_name_address="sed -n -e 's/^: \([[^ ]]*\)[[ ]]*$/  {\\\"\1\\\", (void *) 0},/p' -e 's/^$symcode* \([[^ ]]*\) \([[^ ]]*\)$/  {\"\2\", (void *) \&\2},/p'"
+lt_cv_sys_global_symbol_to_c_name_address_lib_prefix="sed -n -e 's/^: \([[^ ]]*\)[[ ]]*$/  {\\\"\1\\\", (void *) 0},/p' -e 's/^$symcode* \([[^ ]]*\) \(lib[[^ ]]*\)$/  {\"\2\", (void *) \&\2},/p' -e 's/^$symcode* \([[^ ]]*\) \([[^ ]]*\)$/  {\"lib\2\", (void *) \&\2},/p'"
+
+# Handle CRLF in mingw tool chain
+opt_cr=
+case $build_os in
+mingw*)
+  opt_cr=`$ECHO 'x\{0,1\}' | tr x '\015'` # option cr in regexp
+  ;;
+esac
+
+# Try without a prefix underscore, then with it.
+for ac_symprfx in "" "_"; do
+
+  # Transform symcode, sympat, and symprfx into a raw symbol and a C symbol.
+  symxfrm="\\1 $ac_symprfx\\2 \\2"
+
+  # Write the raw and C identifiers.
+  if test "$lt_cv_nm_interface" = "MS dumpbin"; then
+    # Fake it for dumpbin and say T for any non-static function
+    # and D for any global variable.
+    # Also find C++ and __fastcall symbols from MSVC++,
+    # which start with @ or ?.
+    lt_cv_sys_global_symbol_pipe="$AWK ['"\
+"     {last_section=section; section=\$ 3};"\
+"     /^COFF SYMBOL TABLE/{for(i in hide) delete hide[i]};"\
+"     /Section length .*#relocs.*(pick any)/{hide[last_section]=1};"\
+"     \$ 0!~/External *\|/{next};"\
+"     / 0+ UNDEF /{next}; / UNDEF \([^|]\)*()/{next};"\
+"     {if(hide[section]) next};"\
+"     {f=0}; \$ 0~/\(\).*\|/{f=1}; {printf f ? \"T \" : \"D \"};"\
+"     {split(\$ 0, a, /\||\r/); split(a[2], s)};"\
+"     s[1]~/^[@?]/{print s[1], s[1]; next};"\
+"     s[1]~prfx {split(s[1],t,\"@\"); print t[1], substr(t[1],length(prfx))}"\
+"     ' prfx=^$ac_symprfx]"
+  else
+    lt_cv_sys_global_symbol_pipe="sed -n -e 's/^.*[[    ]]\($symcode$symcode*\)[[       ]][[    ]]*$ac_symprfx$sympat$opt_cr$/$symxfrm/p'"
+  fi
+  lt_cv_sys_global_symbol_pipe="$lt_cv_sys_global_symbol_pipe | sed '/ __gnu_lto/d'"
+
+  # Check to see that the pipe works correctly.
+  pipe_works=no
+
+  rm -f conftest*
+  cat > conftest.$ac_ext <<_LT_EOF
+#ifdef __cplusplus
+extern "C" {
+#endif
+char nm_test_var;
+void nm_test_func(void);
+void nm_test_func(void){}
+#ifdef __cplusplus
+}
+#endif
+int main(){nm_test_var='a';nm_test_func();return(0);}
+_LT_EOF
+
+  if AC_TRY_EVAL(ac_compile); then
+    # Now try to grab the symbols.
+    nlist=conftest.nm
+    if AC_TRY_EVAL(NM conftest.$ac_objext \| "$lt_cv_sys_global_symbol_pipe" \> $nlist) && test -s "$nlist"; then
+      # Try sorting and uniquifying the output.
+      if sort "$nlist" | uniq > "$nlist"T; then
+       mv -f "$nlist"T "$nlist"
+      else
+       rm -f "$nlist"T
+      fi
+
+      # Make sure that we snagged all the symbols we need.
+      if $GREP ' nm_test_var$' "$nlist" >/dev/null; then
+       if $GREP ' nm_test_func$' "$nlist" >/dev/null; then
+         cat <<_LT_EOF > conftest.$ac_ext
+/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests.  */
+#if defined(_WIN32) || defined(__CYGWIN__) || defined(_WIN32_WCE)
+/* DATA imports from DLLs on WIN32 con't be const, because runtime
+   relocations are performed -- see ld's documentation on pseudo-relocs.  */
+# define LT@&t@_DLSYM_CONST
+#elif defined(__osf__)
+/* This system does not cope well with relocations in const data.  */
+# define LT@&t@_DLSYM_CONST
+#else
+# define LT@&t@_DLSYM_CONST const
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+_LT_EOF
+         # Now generate the symbol file.
+         eval "$lt_cv_sys_global_symbol_to_cdecl"' < "$nlist" | $GREP -v main >> conftest.$ac_ext'
+
+         cat <<_LT_EOF >> conftest.$ac_ext
+
+/* The mapping between symbol names and symbols.  */
+LT@&t@_DLSYM_CONST struct {
+  const char *name;
+  void       *address;
+}
+lt__PROGRAM__LTX_preloaded_symbols[[]] =
+{
+  { "@PROGRAM@", (void *) 0 },
+_LT_EOF
+         $SED "s/^$symcode$symcode* \(.*\) \(.*\)$/  {\"\2\", (void *) \&\2},/" < "$nlist" | $GREP -v main >> conftest.$ac_ext
+         cat <<\_LT_EOF >> conftest.$ac_ext
+  {0, (void *) 0}
+};
+
+/* This works around a problem in FreeBSD linker */
+#ifdef FREEBSD_WORKAROUND
+static const void *lt_preloaded_setup() {
+  return lt__PROGRAM__LTX_preloaded_symbols;
+}
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+_LT_EOF
+         # Now try linking the two files.
+         mv conftest.$ac_objext conftstm.$ac_objext
+         lt_globsym_save_LIBS=$LIBS
+         lt_globsym_save_CFLAGS=$CFLAGS
+         LIBS="conftstm.$ac_objext"
+         CFLAGS="$CFLAGS$_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)"
+         if AC_TRY_EVAL(ac_link) && test -s conftest${ac_exeext}; then
+           pipe_works=yes
+         fi
+         LIBS=$lt_globsym_save_LIBS
+         CFLAGS=$lt_globsym_save_CFLAGS
+       else
+         echo "cannot find nm_test_func in $nlist" >&AS_MESSAGE_LOG_FD
+       fi
+      else
+       echo "cannot find nm_test_var in $nlist" >&AS_MESSAGE_LOG_FD
+      fi
+    else
+      echo "cannot run $lt_cv_sys_global_symbol_pipe" >&AS_MESSAGE_LOG_FD
+    fi
+  else
+    echo "$progname: failed program was:" >&AS_MESSAGE_LOG_FD
+    cat conftest.$ac_ext >&5
+  fi
+  rm -rf conftest* conftst*
+
+  # Do not use the global_symbol_pipe unless it works.
+  if test "$pipe_works" = yes; then
+    break
+  else
+    lt_cv_sys_global_symbol_pipe=
+  fi
+done
+])
+if test -z "$lt_cv_sys_global_symbol_pipe"; then
+  lt_cv_sys_global_symbol_to_cdecl=
+fi
+if test -z "$lt_cv_sys_global_symbol_pipe$lt_cv_sys_global_symbol_to_cdecl"; then
+  AC_MSG_RESULT(failed)
+else
+  AC_MSG_RESULT(ok)
+fi
+
+# Response file support.
+if test "$lt_cv_nm_interface" = "MS dumpbin"; then
+  nm_file_list_spec='@'
+elif $NM --help 2>/dev/null | grep '[[@]]FILE' >/dev/null; then
+  nm_file_list_spec='@'
+fi
+
+_LT_DECL([global_symbol_pipe], [lt_cv_sys_global_symbol_pipe], [1],
+    [Take the output of nm and produce a listing of raw symbols and C names])
+_LT_DECL([global_symbol_to_cdecl], [lt_cv_sys_global_symbol_to_cdecl], [1],
+    [Transform the output of nm in a proper C declaration])
+_LT_DECL([global_symbol_to_c_name_address],
+    [lt_cv_sys_global_symbol_to_c_name_address], [1],
+    [Transform the output of nm in a C name address pair])
+_LT_DECL([global_symbol_to_c_name_address_lib_prefix],
+    [lt_cv_sys_global_symbol_to_c_name_address_lib_prefix], [1],
+    [Transform the output of nm in a C name address pair when lib prefix is needed])
+_LT_DECL([], [nm_file_list_spec], [1],
+    [Specify filename containing input files for $NM])
+]) # _LT_CMD_GLOBAL_SYMBOLS
+
+
+# _LT_COMPILER_PIC([TAGNAME])
+# ---------------------------
+m4_defun([_LT_COMPILER_PIC],
+[m4_require([_LT_TAG_COMPILER])dnl
+_LT_TAGVAR(lt_prog_compiler_wl, $1)=
+_LT_TAGVAR(lt_prog_compiler_pic, $1)=
+_LT_TAGVAR(lt_prog_compiler_static, $1)=
+
+m4_if([$1], [CXX], [
+  # C++ specific cases for pic, static, wl, etc.
+  if test "$GXX" = yes; then
+    _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+    _LT_TAGVAR(lt_prog_compiler_static, $1)='-static'
+
+    case $host_os in
+    aix*)
+      # All AIX code is PIC.
+      if test "$host_cpu" = ia64; then
+       # AIX 5 now supports IA64 processor
+       _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      fi
+      ;;
+
+    amigaos*)
+      case $host_cpu in
+      powerpc)
+            # see comment about AmigaOS4 .so support
+            _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+        ;;
+      m68k)
+            # FIXME: we need at least 68020 code to build shared libraries, but
+            # adding the `-m68020' flag to GCC prevents building anything better,
+            # like `-m68040'.
+            _LT_TAGVAR(lt_prog_compiler_pic, $1)='-m68020 -resident32 -malways-restore-a4'
+        ;;
+      esac
+      ;;
+
+    beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*)
+      # PIC is the default for these OSes.
+      ;;
+    mingw* | cygwin* | os2* | pw32* | cegcc*)
+      # This hack is so that the source file can tell whether it is being
+      # built for inclusion in a dll (and should export symbols for example).
+      # Although the cygwin gcc ignores -fPIC, still need this for old-style
+      # (--disable-auto-import) libraries
+      m4_if([$1], [GCJ], [],
+       [_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT'])
+      ;;
+    darwin* | rhapsody*)
+      # PIC is the default on this platform
+      # Common symbols not allowed in MH_DYLIB files
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fno-common'
+      ;;
+    *djgpp*)
+      # DJGPP does not support shared libraries at all
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)=
+      ;;
+    haiku*)
+      # PIC is the default for Haiku.
+      # The "-static" flag exists, but is broken.
+      _LT_TAGVAR(lt_prog_compiler_static, $1)=
+      ;;
+    interix[[3-9]]*)
+      # Interix 3.x gcc -fpic/-fPIC options generate broken code.
+      # Instead, we relocate shared libraries at runtime.
+      ;;
+    sysv4*MP*)
+      if test -d /usr/nec; then
+       _LT_TAGVAR(lt_prog_compiler_pic, $1)=-Kconform_pic
+      fi
+      ;;
+    hpux*)
+      # PIC is the default for 64-bit PA HP-UX, but not for 32-bit
+      # PA HP-UX.  On IA64 HP-UX, PIC is the default but the pic flag
+      # sets the default TLS model and affects inlining.
+      case $host_cpu in
+      hppa*64*)
+       ;;
+      *)
+       _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+       ;;
+      esac
+      ;;
+    *qnx* | *nto*)
+      # QNX uses GNU C++, but need to define -shared option too, otherwise
+      # it will coredump.
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared'
+      ;;
+    *)
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+      ;;
+    esac
+  else
+    case $host_os in
+      aix[[4-9]]*)
+       # All AIX code is PIC.
+       if test "$host_cpu" = ia64; then
+         # AIX 5 now supports IA64 processor
+         _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+       else
+         _LT_TAGVAR(lt_prog_compiler_static, $1)='-bnso -bI:/lib/syscalls.exp'
+       fi
+       ;;
+      chorus*)
+       case $cc_basename in
+       cxch68*)
+         # Green Hills C++ Compiler
+         # _LT_TAGVAR(lt_prog_compiler_static, $1)="--no_auto_instantiation -u __main -u __premain -u _abort -r $COOL_DIR/lib/libOrb.a $MVME_DIR/lib/CC/libC.a $MVME_DIR/lib/classix/libcx.s.a"
+         ;;
+       esac
+       ;;
+      mingw* | cygwin* | os2* | pw32* | cegcc*)
+       # This hack is so that the source file can tell whether it is being
+       # built for inclusion in a dll (and should export symbols for example).
+       m4_if([$1], [GCJ], [],
+         [_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT'])
+       ;;
+      dgux*)
+       case $cc_basename in
+         ec++*)
+           _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+           ;;
+         ghcx*)
+           # Green Hills C++ Compiler
+           _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic'
+           ;;
+         *)
+           ;;
+       esac
+       ;;
+      freebsd* | dragonfly*)
+       # FreeBSD uses GNU C++
+       ;;
+      hpux9* | hpux10* | hpux11*)
+       case $cc_basename in
+         CC*)
+           _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+           _LT_TAGVAR(lt_prog_compiler_static, $1)='${wl}-a ${wl}archive'
+           if test "$host_cpu" != ia64; then
+             _LT_TAGVAR(lt_prog_compiler_pic, $1)='+Z'
+           fi
+           ;;
+         aCC*)
+           _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+           _LT_TAGVAR(lt_prog_compiler_static, $1)='${wl}-a ${wl}archive'
+           case $host_cpu in
+           hppa*64*|ia64*)
+             # +Z the default
+             ;;
+           *)
+             _LT_TAGVAR(lt_prog_compiler_pic, $1)='+Z'
+             ;;
+           esac
+           ;;
+         *)
+           ;;
+       esac
+       ;;
+      interix*)
+       # This is c89, which is MS Visual C++ (no shared libs)
+       # Anyone wants to do a port?
+       ;;
+      irix5* | irix6* | nonstopux*)
+       case $cc_basename in
+         CC*)
+           _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+           _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
+           # CC pic flag -KPIC is the default.
+           ;;
+         *)
+           ;;
+       esac
+       ;;
+      linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*)
+       case $cc_basename in
+         KCC*)
+           # KAI C++ Compiler
+           _LT_TAGVAR(lt_prog_compiler_wl, $1)='--backend -Wl,'
+           _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+           ;;
+         ecpc* )
+           # old Intel C++ for x86_64 which still supported -KPIC.
+           _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+           _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+           _LT_TAGVAR(lt_prog_compiler_static, $1)='-static'
+           ;;
+         icpc* )
+           # Intel C++, used to be incompatible with GCC.
+           # ICC 10 doesn't accept -KPIC any more.
+           _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+           _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+           _LT_TAGVAR(lt_prog_compiler_static, $1)='-static'
+           ;;
+         pgCC* | pgcpp*)
+           # Portland Group C++ compiler
+           _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+           _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fpic'
+           _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+           ;;
+         cxx*)
+           # Compaq C++
+           # Make sure the PIC flag is empty.  It appears that all Alpha
+           # Linux and Compaq Tru64 Unix objects are PIC.
+           _LT_TAGVAR(lt_prog_compiler_pic, $1)=
+           _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
+           ;;
+         xlc* | xlC* | bgxl[[cC]]* | mpixl[[cC]]*)
+           # IBM XL 8.0, 9.0 on PPC and BlueGene
+           _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+           _LT_TAGVAR(lt_prog_compiler_pic, $1)='-qpic'
+           _LT_TAGVAR(lt_prog_compiler_static, $1)='-qstaticlink'
+           ;;
+         *)
+           case `$CC -V 2>&1 | sed 5q` in
+           *Sun\ C*)
+             # Sun C++ 5.9
+             _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+             _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+             _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld '
+             ;;
+           esac
+           ;;
+       esac
+       ;;
+      lynxos*)
+       ;;
+      m88k*)
+       ;;
+      mvs*)
+       case $cc_basename in
+         cxx*)
+           _LT_TAGVAR(lt_prog_compiler_pic, $1)='-W c,exportall'
+           ;;
+         *)
+           ;;
+       esac
+       ;;
+      netbsd* | netbsdelf*-gnu)
+       ;;
+      *qnx* | *nto*)
+        # QNX uses GNU C++, but need to define -shared option too, otherwise
+        # it will coredump.
+        _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared'
+        ;;
+      osf3* | osf4* | osf5*)
+       case $cc_basename in
+         KCC*)
+           _LT_TAGVAR(lt_prog_compiler_wl, $1)='--backend -Wl,'
+           ;;
+         RCC*)
+           # Rational C++ 2.4.1
+           _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic'
+           ;;
+         cxx*)
+           # Digital/Compaq C++
+           _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+           # Make sure the PIC flag is empty.  It appears that all Alpha
+           # Linux and Compaq Tru64 Unix objects are PIC.
+           _LT_TAGVAR(lt_prog_compiler_pic, $1)=
+           _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
+           ;;
+         *)
+           ;;
+       esac
+       ;;
+      psos*)
+       ;;
+      solaris*)
+       case $cc_basename in
+         CC* | sunCC*)
+           # Sun C++ 4.2, 5.x and Centerline C++
+           _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+           _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+           _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld '
+           ;;
+         gcx*)
+           # Green Hills C++ Compiler
+           _LT_TAGVAR(lt_prog_compiler_pic, $1)='-PIC'
+           ;;
+         *)
+           ;;
+       esac
+       ;;
+      sunos4*)
+       case $cc_basename in
+         CC*)
+           # Sun C++ 4.x
+           _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic'
+           _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+           ;;
+         lcc*)
+           # Lucid
+           _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic'
+           ;;
+         *)
+           ;;
+       esac
+       ;;
+      sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*)
+       case $cc_basename in
+         CC*)
+           _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+           _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+           _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+           ;;
+       esac
+       ;;
+      tandem*)
+       case $cc_basename in
+         NCC*)
+           # NonStop-UX NCC 3.20
+           _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+           ;;
+         *)
+           ;;
+       esac
+       ;;
+      vxworks*)
+       ;;
+      *)
+       _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no
+       ;;
+    esac
+  fi
+],
+[
+  if test "$GCC" = yes; then
+    _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+    _LT_TAGVAR(lt_prog_compiler_static, $1)='-static'
+
+    case $host_os in
+      aix*)
+      # All AIX code is PIC.
+      if test "$host_cpu" = ia64; then
+       # AIX 5 now supports IA64 processor
+       _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      fi
+      ;;
+
+    amigaos*)
+      case $host_cpu in
+      powerpc)
+            # see comment about AmigaOS4 .so support
+            _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+        ;;
+      m68k)
+            # FIXME: we need at least 68020 code to build shared libraries, but
+            # adding the `-m68020' flag to GCC prevents building anything better,
+            # like `-m68040'.
+            _LT_TAGVAR(lt_prog_compiler_pic, $1)='-m68020 -resident32 -malways-restore-a4'
+        ;;
+      esac
+      ;;
+
+    beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*)
+      # PIC is the default for these OSes.
+      ;;
+
+    mingw* | cygwin* | pw32* | os2* | cegcc*)
+      # This hack is so that the source file can tell whether it is being
+      # built for inclusion in a dll (and should export symbols for example).
+      # Although the cygwin gcc ignores -fPIC, still need this for old-style
+      # (--disable-auto-import) libraries
+      m4_if([$1], [GCJ], [],
+       [_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT'])
+      ;;
+
+    darwin* | rhapsody*)
+      # PIC is the default on this platform
+      # Common symbols not allowed in MH_DYLIB files
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fno-common'
+      ;;
+
+    haiku*)
+      # PIC is the default for Haiku.
+      # The "-static" flag exists, but is broken.
+      _LT_TAGVAR(lt_prog_compiler_static, $1)=
+      ;;
+
+    hpux*)
+      # PIC is the default for 64-bit PA HP-UX, but not for 32-bit
+      # PA HP-UX.  On IA64 HP-UX, PIC is the default but the pic flag
+      # sets the default TLS model and affects inlining.
+      case $host_cpu in
+      hppa*64*)
+       # +Z the default
+       ;;
+      *)
+       _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+       ;;
+      esac
+      ;;
+
+    interix[[3-9]]*)
+      # Interix 3.x gcc -fpic/-fPIC options generate broken code.
+      # Instead, we relocate shared libraries at runtime.
+      ;;
+
+    msdosdjgpp*)
+      # Just because we use GCC doesn't mean we suddenly get shared libraries
+      # on systems that don't support them.
+      _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no
+      enable_shared=no
+      ;;
+
+    *nto* | *qnx*)
+      # QNX uses GNU C++, but need to define -shared option too, otherwise
+      # it will coredump.
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared'
+      ;;
+
+    sysv4*MP*)
+      if test -d /usr/nec; then
+       _LT_TAGVAR(lt_prog_compiler_pic, $1)=-Kconform_pic
+      fi
+      ;;
+
+    *)
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+      ;;
+    esac
+
+    case $cc_basename in
+    nvcc*) # Cuda Compiler Driver 2.2
+      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Xlinker '
+      if test -n "$_LT_TAGVAR(lt_prog_compiler_pic, $1)"; then
+        _LT_TAGVAR(lt_prog_compiler_pic, $1)="-Xcompiler $_LT_TAGVAR(lt_prog_compiler_pic, $1)"
+      fi
+      ;;
+    esac
+  else
+    # PORTME Check for flag to pass linker flags through the system compiler.
+    case $host_os in
+    aix*)
+      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+      if test "$host_cpu" = ia64; then
+       # AIX 5 now supports IA64 processor
+       _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      else
+       _LT_TAGVAR(lt_prog_compiler_static, $1)='-bnso -bI:/lib/syscalls.exp'
+      fi
+      ;;
+
+    mingw* | cygwin* | pw32* | os2* | cegcc*)
+      # This hack is so that the source file can tell whether it is being
+      # built for inclusion in a dll (and should export symbols for example).
+      m4_if([$1], [GCJ], [],
+       [_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT'])
+      ;;
+
+    hpux9* | hpux10* | hpux11*)
+      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+      # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but
+      # not for PA HP-UX.
+      case $host_cpu in
+      hppa*64*|ia64*)
+       # +Z the default
+       ;;
+      *)
+       _LT_TAGVAR(lt_prog_compiler_pic, $1)='+Z'
+       ;;
+      esac
+      # Is there a better lt_prog_compiler_static that works with the bundled CC?
+      _LT_TAGVAR(lt_prog_compiler_static, $1)='${wl}-a ${wl}archive'
+      ;;
+
+    irix5* | irix6* | nonstopux*)
+      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+      # PIC (with -KPIC) is the default.
+      _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
+      ;;
+
+    linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*)
+      case $cc_basename in
+      # old Intel for x86_64 which still supported -KPIC.
+      ecc*)
+       _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+       _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+       _LT_TAGVAR(lt_prog_compiler_static, $1)='-static'
+        ;;
+      # icc used to be incompatible with GCC.
+      # ICC 10 doesn't accept -KPIC any more.
+      icc* | ifort*)
+       _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+       _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+       _LT_TAGVAR(lt_prog_compiler_static, $1)='-static'
+        ;;
+      # Lahey Fortran 8.1.
+      lf95*)
+       _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+       _LT_TAGVAR(lt_prog_compiler_pic, $1)='--shared'
+       _LT_TAGVAR(lt_prog_compiler_static, $1)='--static'
+       ;;
+      nagfor*)
+       # NAG Fortran compiler
+       _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,-Wl,,'
+       _LT_TAGVAR(lt_prog_compiler_pic, $1)='-PIC'
+       _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+       ;;
+      pgcc* | pgf77* | pgf90* | pgf95* | pgfortran*)
+        # Portland Group compilers (*not* the Pentium gcc compiler,
+       # which looks to be a dead project)
+       _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+       _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fpic'
+       _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+        ;;
+      ccc*)
+        _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+        # All Alpha code is PIC.
+        _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
+        ;;
+      xl* | bgxl* | bgf* | mpixl*)
+       # IBM XL C 8.0/Fortran 10.1, 11.1 on PPC and BlueGene
+       _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+       _LT_TAGVAR(lt_prog_compiler_pic, $1)='-qpic'
+       _LT_TAGVAR(lt_prog_compiler_static, $1)='-qstaticlink'
+       ;;
+      *)
+       case `$CC -V 2>&1 | sed 5q` in
+       *Sun\ Ceres\ Fortran* | *Sun*Fortran*\ [[1-7]].* | *Sun*Fortran*\ 8.[[0-3]]*)
+         # Sun Fortran 8.3 passes all unrecognized flags to the linker
+         _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+         _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+         _LT_TAGVAR(lt_prog_compiler_wl, $1)=''
+         ;;
+       *Sun\ F* | *Sun*Fortran*)
+         _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+         _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+         _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld '
+         ;;
+       *Sun\ C*)
+         # Sun C 5.9
+         _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+         _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+         _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+         ;;
+        *Intel*\ [[CF]]*Compiler*)
+         _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+         _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
+         _LT_TAGVAR(lt_prog_compiler_static, $1)='-static'
+         ;;
+       *Portland\ Group*)
+         _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+         _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fpic'
+         _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+         ;;
+       esac
+       ;;
+      esac
+      ;;
+
+    newsos6)
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+      _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      ;;
+
+    *nto* | *qnx*)
+      # QNX uses GNU C++, but need to define -shared option too, otherwise
+      # it will coredump.
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared'
+      ;;
+
+    osf3* | osf4* | osf5*)
+      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+      # All OSF/1 code is PIC.
+      _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
+      ;;
+
+    rdos*)
+      _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
+      ;;
+
+    solaris*)
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+      _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      case $cc_basename in
+      f77* | f90* | f95* | sunf77* | sunf90* | sunf95*)
+       _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ';;
+      *)
+       _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,';;
+      esac
+      ;;
+
+    sunos4*)
+      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld '
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-PIC'
+      _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      ;;
+
+    sysv4 | sysv4.2uw2* | sysv4.3*)
+      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+      _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      ;;
+
+    sysv4*MP*)
+      if test -d /usr/nec ;then
+       _LT_TAGVAR(lt_prog_compiler_pic, $1)='-Kconform_pic'
+       _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      fi
+      ;;
+
+    sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*)
+      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
+      _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      ;;
+
+    unicos*)
+      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
+      _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no
+      ;;
+
+    uts4*)
+      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic'
+      _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      ;;
+
+    *)
+      _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no
+      ;;
+    esac
+  fi
+])
+case $host_os in
+  # For platforms which do not support PIC, -DPIC is meaningless:
+  *djgpp*)
+    _LT_TAGVAR(lt_prog_compiler_pic, $1)=
+    ;;
+  *)
+    _LT_TAGVAR(lt_prog_compiler_pic, $1)="$_LT_TAGVAR(lt_prog_compiler_pic, $1)@&t@m4_if([$1],[],[ -DPIC],[m4_if([$1],[CXX],[ -DPIC],[])])"
+    ;;
+esac
+
+AC_CACHE_CHECK([for $compiler option to produce PIC],
+  [_LT_TAGVAR(lt_cv_prog_compiler_pic, $1)],
+  [_LT_TAGVAR(lt_cv_prog_compiler_pic, $1)=$_LT_TAGVAR(lt_prog_compiler_pic, $1)])
+_LT_TAGVAR(lt_prog_compiler_pic, $1)=$_LT_TAGVAR(lt_cv_prog_compiler_pic, $1)
+
+#
+# Check to make sure the PIC flag actually works.
+#
+if test -n "$_LT_TAGVAR(lt_prog_compiler_pic, $1)"; then
+  _LT_COMPILER_OPTION([if $compiler PIC flag $_LT_TAGVAR(lt_prog_compiler_pic, $1) works],
+    [_LT_TAGVAR(lt_cv_prog_compiler_pic_works, $1)],
+    [$_LT_TAGVAR(lt_prog_compiler_pic, $1)@&t@m4_if([$1],[],[ -DPIC],[m4_if([$1],[CXX],[ -DPIC],[])])], [],
+    [case $_LT_TAGVAR(lt_prog_compiler_pic, $1) in
+     "" | " "*) ;;
+     *) _LT_TAGVAR(lt_prog_compiler_pic, $1)=" $_LT_TAGVAR(lt_prog_compiler_pic, $1)" ;;
+     esac],
+    [_LT_TAGVAR(lt_prog_compiler_pic, $1)=
+     _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no])
+fi
+_LT_TAGDECL([pic_flag], [lt_prog_compiler_pic], [1],
+       [Additional compiler flags for building library objects])
+
+_LT_TAGDECL([wl], [lt_prog_compiler_wl], [1],
+       [How to pass a linker flag through the compiler])
+#
+# Check to make sure the static flag actually works.
+#
+wl=$_LT_TAGVAR(lt_prog_compiler_wl, $1) eval lt_tmp_static_flag=\"$_LT_TAGVAR(lt_prog_compiler_static, $1)\"
+_LT_LINKER_OPTION([if $compiler static flag $lt_tmp_static_flag works],
+  _LT_TAGVAR(lt_cv_prog_compiler_static_works, $1),
+  $lt_tmp_static_flag,
+  [],
+  [_LT_TAGVAR(lt_prog_compiler_static, $1)=])
+_LT_TAGDECL([link_static_flag], [lt_prog_compiler_static], [1],
+       [Compiler flag to prevent dynamic linking])
+])# _LT_COMPILER_PIC
+
+
+# _LT_LINKER_SHLIBS([TAGNAME])
+# ----------------------------
+# See if the linker supports building shared libraries.
+m4_defun([_LT_LINKER_SHLIBS],
+[AC_REQUIRE([LT_PATH_LD])dnl
+AC_REQUIRE([LT_PATH_NM])dnl
+m4_require([_LT_PATH_MANIFEST_TOOL])dnl
+m4_require([_LT_FILEUTILS_DEFAULTS])dnl
+m4_require([_LT_DECL_EGREP])dnl
+m4_require([_LT_DECL_SED])dnl
+m4_require([_LT_CMD_GLOBAL_SYMBOLS])dnl
+m4_require([_LT_TAG_COMPILER])dnl
+AC_MSG_CHECKING([whether the $compiler linker ($LD) supports shared libraries])
+m4_if([$1], [CXX], [
+  _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols'
+  _LT_TAGVAR(exclude_expsyms, $1)=['_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*']
+  case $host_os in
+  aix[[4-9]]*)
+    # If we're using GNU nm, then we don't want the "-C" option.
+    # -C means demangle to AIX nm, but means don't demangle with GNU nm
+    # Also, AIX nm treats weak defined symbols like other global defined
+    # symbols, whereas GNU nm marks them as "W".
+    if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then
+      _LT_TAGVAR(export_symbols_cmds, $1)='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W")) && ([substr](\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols'
+    else
+      _LT_TAGVAR(export_symbols_cmds, $1)='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && ([substr](\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols'
+    fi
+    ;;
+  pw32*)
+    _LT_TAGVAR(export_symbols_cmds, $1)="$ltdll_cmds"
+    ;;
+  cygwin* | mingw* | cegcc*)
+    case $cc_basename in
+    cl*)
+      _LT_TAGVAR(exclude_expsyms, $1)='_NULL_IMPORT_DESCRIPTOR|_IMPORT_DESCRIPTOR_.*'
+      ;;
+    *)
+      _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]][[ ]]/s/.*[[ ]]\([[^ ]]*\)/\1 DATA/;s/^.*[[ ]]__nm__\([[^ ]]*\)[[ ]][[^ ]]*/\1 DATA/;/^I[[ ]]/d;/^[[AITW]][[ ]]/s/.* //'\'' | sort | uniq > $export_symbols'
+      _LT_TAGVAR(exclude_expsyms, $1)=['[_]+GLOBAL_OFFSET_TABLE_|[_]+GLOBAL__[FID]_.*|[_]+head_[A-Za-z0-9_]+_dll|[A-Za-z0-9_]+_dll_iname']
+      ;;
+    esac
+    ;;
+  linux* | k*bsd*-gnu | gnu*)
+    _LT_TAGVAR(link_all_deplibs, $1)=no
+    ;;
+  *)
+    _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols'
+    ;;
+  esac
+], [
+  runpath_var=
+  _LT_TAGVAR(allow_undefined_flag, $1)=
+  _LT_TAGVAR(always_export_symbols, $1)=no
+  _LT_TAGVAR(archive_cmds, $1)=
+  _LT_TAGVAR(archive_expsym_cmds, $1)=
+  _LT_TAGVAR(compiler_needs_object, $1)=no
+  _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no
+  _LT_TAGVAR(export_dynamic_flag_spec, $1)=
+  _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols'
+  _LT_TAGVAR(hardcode_automatic, $1)=no
+  _LT_TAGVAR(hardcode_direct, $1)=no
+  _LT_TAGVAR(hardcode_direct_absolute, $1)=no
+  _LT_TAGVAR(hardcode_libdir_flag_spec, $1)=
+  _LT_TAGVAR(hardcode_libdir_separator, $1)=
+  _LT_TAGVAR(hardcode_minus_L, $1)=no
+  _LT_TAGVAR(hardcode_shlibpath_var, $1)=unsupported
+  _LT_TAGVAR(inherit_rpath, $1)=no
+  _LT_TAGVAR(link_all_deplibs, $1)=unknown
+  _LT_TAGVAR(module_cmds, $1)=
+  _LT_TAGVAR(module_expsym_cmds, $1)=
+  _LT_TAGVAR(old_archive_from_new_cmds, $1)=
+  _LT_TAGVAR(old_archive_from_expsyms_cmds, $1)=
+  _LT_TAGVAR(thread_safe_flag_spec, $1)=
+  _LT_TAGVAR(whole_archive_flag_spec, $1)=
+  # include_expsyms should be a list of space-separated symbols to be *always*
+  # included in the symbol list
+  _LT_TAGVAR(include_expsyms, $1)=
+  # exclude_expsyms can be an extended regexp of symbols to exclude
+  # it will be wrapped by ` (' and `)$', so one must not match beginning or
+  # end of line.  Example: `a|bc|.*d.*' will exclude the symbols `a' and `bc',
+  # as well as any symbol that contains `d'.
+  _LT_TAGVAR(exclude_expsyms, $1)=['_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*']
+  # Although _GLOBAL_OFFSET_TABLE_ is a valid symbol C name, most a.out
+  # platforms (ab)use it in PIC code, but their linkers get confused if
+  # the symbol is explicitly referenced.  Since portable code cannot
+  # rely on this symbol name, it's probably fine to never include it in
+  # preloaded symbol tables.
+  # Exclude shared library initialization/finalization symbols.
+dnl Note also adjust exclude_expsyms for C++ above.
+  extract_expsyms_cmds=
+
+  case $host_os in
+  cygwin* | mingw* | pw32* | cegcc*)
+    # FIXME: the MSVC++ port hasn't been tested in a loooong time
+    # When not using gcc, we currently assume that we are using
+    # Microsoft Visual C++.
+    if test "$GCC" != yes; then
+      with_gnu_ld=no
+    fi
+    ;;
+  interix*)
+    # we just hope/assume this is gcc and not c89 (= MSVC++)
+    with_gnu_ld=yes
+    ;;
+  openbsd*)
+    with_gnu_ld=no
+    ;;
+  linux* | k*bsd*-gnu | gnu*)
+    _LT_TAGVAR(link_all_deplibs, $1)=no
+    ;;
+  esac
+
+  _LT_TAGVAR(ld_shlibs, $1)=yes
+
+  # On some targets, GNU ld is compatible enough with the native linker
+  # that we're better off using the native interface for both.
+  lt_use_gnu_ld_interface=no
+  if test "$with_gnu_ld" = yes; then
+    case $host_os in
+      aix*)
+       # The AIX port of GNU ld has always aspired to compatibility
+       # with the native linker.  However, as the warning in the GNU ld
+       # block says, versions before 2.19.5* couldn't really create working
+       # shared libraries, regardless of the interface used.
+       case `$LD -v 2>&1` in
+         *\ \(GNU\ Binutils\)\ 2.19.5*) ;;
+         *\ \(GNU\ Binutils\)\ 2.[[2-9]]*) ;;
+         *\ \(GNU\ Binutils\)\ [[3-9]]*) ;;
+         *)
+           lt_use_gnu_ld_interface=yes
+           ;;
+       esac
+       ;;
+      *)
+       lt_use_gnu_ld_interface=yes
+       ;;
+    esac
+  fi
+
+  if test "$lt_use_gnu_ld_interface" = yes; then
+    # If archive_cmds runs LD, not CC, wlarc should be empty
+    wlarc='${wl}'
+
+    # Set some defaults for GNU ld with shared library support. These
+    # are reset later if shared libraries are not supported. Putting them
+    # here allows them to be overridden if necessary.
+    runpath_var=LD_RUN_PATH
+    _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+    _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
+    # ancient GNU ld didn't support --whole-archive et. al.
+    if $LD --help 2>&1 | $GREP 'no-whole-archive' > /dev/null; then
+      _LT_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive'
+    else
+      _LT_TAGVAR(whole_archive_flag_spec, $1)=
+    fi
+    supports_anon_versioning=no
+    case `$LD -v 2>&1` in
+      *GNU\ gold*) supports_anon_versioning=yes ;;
+      *\ [[01]].* | *\ 2.[[0-9]].* | *\ 2.10.*) ;; # catch versions < 2.11
+      *\ 2.11.93.0.2\ *) supports_anon_versioning=yes ;; # RH7.3 ...
+      *\ 2.11.92.0.12\ *) supports_anon_versioning=yes ;; # Mandrake 8.2 ...
+      *\ 2.11.*) ;; # other 2.11 versions
+      *) supports_anon_versioning=yes ;;
+    esac
+
+    # See if GNU ld supports shared libraries.
+    case $host_os in
+    aix[[3-9]]*)
+      # On AIX/PPC, the GNU linker is very broken
+      if test "$host_cpu" != ia64; then
+       _LT_TAGVAR(ld_shlibs, $1)=no
+       cat <<_LT_EOF 1>&2
+
+*** Warning: the GNU linker, at least up to release 2.19, is reported
+*** to be unable to reliably create shared libraries on AIX.
+*** Therefore, libtool is disabling shared libraries support.  If you
+*** really care for shared libraries, you may want to install binutils
+*** 2.20 or above, or modify your PATH so that a non-GNU linker is found.
+*** You will then need to restart the configuration process.
+
+_LT_EOF
+      fi
+      ;;
+
+    amigaos*)
+      case $host_cpu in
+      powerpc)
+            # see comment about AmigaOS4 .so support
+            _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+            _LT_TAGVAR(archive_expsym_cmds, $1)=''
+        ;;
+      m68k)
+            _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)'
+            _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+            _LT_TAGVAR(hardcode_minus_L, $1)=yes
+        ;;
+      esac
+      ;;
+
+    beos*)
+      if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
+       _LT_TAGVAR(allow_undefined_flag, $1)=unsupported
+       # Joseph Beckenbach <jrb3@best.com> says some releases of gcc
+       # support --undefined.  This deserves some investigation.  FIXME
+       _LT_TAGVAR(archive_cmds, $1)='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+      else
+       _LT_TAGVAR(ld_shlibs, $1)=no
+      fi
+      ;;
+
+    cygwin* | mingw* | pw32* | cegcc*)
+      # _LT_TAGVAR(hardcode_libdir_flag_spec, $1) is actually meaningless,
+      # as there is no search path for DLLs.
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+      _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-all-symbols'
+      _LT_TAGVAR(allow_undefined_flag, $1)=unsupported
+      _LT_TAGVAR(always_export_symbols, $1)=no
+      _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes
+      _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]][[ ]]/s/.*[[ ]]\([[^ ]]*\)/\1 DATA/;s/^.*[[ ]]__nm__\([[^ ]]*\)[[ ]][[^ ]]*/\1 DATA/;/^I[[ ]]/d;/^[[AITW]][[ ]]/s/.* //'\'' | sort | uniq > $export_symbols'
+      _LT_TAGVAR(exclude_expsyms, $1)=['[_]+GLOBAL_OFFSET_TABLE_|[_]+GLOBAL__[FID]_.*|[_]+head_[A-Za-z0-9_]+_dll|[A-Za-z0-9_]+_dll_iname']
+
+      if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then
+        _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib'
+       # If the export-symbols file already is a .def file (1st line
+       # is EXPORTS), use it as is; otherwise, prepend...
+       _LT_TAGVAR(archive_expsym_cmds, $1)='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then
+         cp $export_symbols $output_objdir/$soname.def;
+       else
+         echo EXPORTS > $output_objdir/$soname.def;
+         cat $export_symbols >> $output_objdir/$soname.def;
+       fi~
+       $CC -shared $output_objdir/$soname.def $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib'
+      else
+       _LT_TAGVAR(ld_shlibs, $1)=no
+      fi
+      ;;
+
+    haiku*)
+      _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+      _LT_TAGVAR(link_all_deplibs, $1)=yes
+      ;;
+
+    interix[[3-9]]*)
+      _LT_TAGVAR(hardcode_direct, $1)=no
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
+      _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+      # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc.
+      # Instead, shared libraries are loaded at an image base (0x10000000 by
+      # default) and relocated if they conflict, which is a slow very memory
+      # consuming and fragmenting process.  To avoid this, we pick a random,
+      # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link
+      # time.  Moving up from 0x10000000 also allows more sbrk(2) space.
+      _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
+      _LT_TAGVAR(archive_expsym_cmds, $1)='sed "s,^,_," $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--retain-symbols-file,$output_objdir/$soname.expsym ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
+      ;;
+
+    gnu* | linux* | tpf* | k*bsd*-gnu | kopensolaris*-gnu)
+      tmp_diet=no
+      if test "$host_os" = linux-dietlibc; then
+       case $cc_basename in
+         diet\ *) tmp_diet=yes;;       # linux-dietlibc with static linking (!diet-dyn)
+       esac
+      fi
+      if $LD --help 2>&1 | $EGREP ': supported targets:.* elf' > /dev/null \
+        && test "$tmp_diet" = no
+      then
+       tmp_addflag=' $pic_flag'
+       tmp_sharedflag='-shared'
+       case $cc_basename,$host_cpu in
+        pgcc*)                         # Portland Group C compiler
+         _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`for conv in $convenience\"\"; do test  -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` ${wl}--no-whole-archive'
+         tmp_addflag=' $pic_flag'
+         ;;
+       pgf77* | pgf90* | pgf95* | pgfortran*)
+                                       # Portland Group f77 and f90 compilers
+         _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`for conv in $convenience\"\"; do test  -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` ${wl}--no-whole-archive'
+         tmp_addflag=' $pic_flag -Mnomain' ;;
+       ecc*,ia64* | icc*,ia64*)        # Intel C compiler on ia64
+         tmp_addflag=' -i_dynamic' ;;
+       efc*,ia64* | ifort*,ia64*)      # Intel Fortran compiler on ia64
+         tmp_addflag=' -i_dynamic -nofor_main' ;;
+       ifc* | ifort*)                  # Intel Fortran compiler
+         tmp_addflag=' -nofor_main' ;;
+       lf95*)                          # Lahey Fortran 8.1
+         _LT_TAGVAR(whole_archive_flag_spec, $1)=
+         tmp_sharedflag='--shared' ;;
+       xl[[cC]]* | bgxl[[cC]]* | mpixl[[cC]]*) # IBM XL C 8.0 on PPC (deal with xlf below)
+         tmp_sharedflag='-qmkshrobj'
+         tmp_addflag= ;;
+       nvcc*)  # Cuda Compiler Driver 2.2
+         _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`for conv in $convenience\"\"; do test  -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` ${wl}--no-whole-archive'
+         _LT_TAGVAR(compiler_needs_object, $1)=yes
+         ;;
+       esac
+       case `$CC -V 2>&1 | sed 5q` in
+       *Sun\ C*)                       # Sun C 5.9
+         _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` ${wl}--no-whole-archive'
+         _LT_TAGVAR(compiler_needs_object, $1)=yes
+         tmp_sharedflag='-G' ;;
+       *Sun\ F*)                       # Sun Fortran 8.3
+         tmp_sharedflag='-G' ;;
+       esac
+       _LT_TAGVAR(archive_cmds, $1)='$CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+
+        if test "x$supports_anon_versioning" = xyes; then
+          _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~
+           cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~
+           echo "local: *; };" >> $output_objdir/$libname.ver~
+           $CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-version-script ${wl}$output_objdir/$libname.ver -o $lib'
+        fi
+
+       case $cc_basename in
+       xlf* | bgf* | bgxlf* | mpixlf*)
+         # IBM XL Fortran 10.1 on PPC cannot create shared libs itself
+         _LT_TAGVAR(whole_archive_flag_spec, $1)='--whole-archive$convenience --no-whole-archive'
+         _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+         _LT_TAGVAR(archive_cmds, $1)='$LD -shared $libobjs $deplibs $linker_flags -soname $soname -o $lib'
+         if test "x$supports_anon_versioning" = xyes; then
+           _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~
+             cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~
+             echo "local: *; };" >> $output_objdir/$libname.ver~
+             $LD -shared $libobjs $deplibs $linker_flags -soname $soname -version-script $output_objdir/$libname.ver -o $lib'
+         fi
+         ;;
+       esac
+      else
+        _LT_TAGVAR(ld_shlibs, $1)=no
+      fi
+      ;;
+
+    netbsd* | netbsdelf*-gnu)
+      if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
+       _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib'
+       wlarc=
+      else
+       _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+       _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+      fi
+      ;;
+
+    solaris*)
+      if $LD -v 2>&1 | $GREP 'BFD 2\.8' > /dev/null; then
+       _LT_TAGVAR(ld_shlibs, $1)=no
+       cat <<_LT_EOF 1>&2
+
+*** Warning: The releases 2.8.* of the GNU linker cannot reliably
+*** create shared libraries on Solaris systems.  Therefore, libtool
+*** is disabling shared libraries support.  We urge you to upgrade GNU
+*** binutils to release 2.9.1 or newer.  Another option is to modify
+*** your PATH or compiler configuration so that the native linker is
+*** used, and then restart.
+
+_LT_EOF
+      elif $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
+       _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+       _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+      else
+       _LT_TAGVAR(ld_shlibs, $1)=no
+      fi
+      ;;
+
+    sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX*)
+      case `$LD -v 2>&1` in
+        *\ [[01]].* | *\ 2.[[0-9]].* | *\ 2.1[[0-5]].*)
+       _LT_TAGVAR(ld_shlibs, $1)=no
+       cat <<_LT_EOF 1>&2
+
+*** Warning: Releases of the GNU linker prior to 2.16.91.0.3 can not
+*** reliably create shared libraries on SCO systems.  Therefore, libtool
+*** is disabling shared libraries support.  We urge you to upgrade GNU
+*** binutils to release 2.16.91.0.3 or newer.  Another option is to modify
+*** your PATH or compiler configuration so that the native linker is
+*** used, and then restart.
+
+_LT_EOF
+       ;;
+       *)
+         # For security reasons, it is highly recommended that you always
+         # use absolute paths for naming shared libraries, and exclude the
+         # DT_RUNPATH tag from executables and libraries.  But doing so
+         # requires that you compile everything twice, which is a pain.
+         if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
+           _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+           _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+           _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+         else
+           _LT_TAGVAR(ld_shlibs, $1)=no
+         fi
+       ;;
+      esac
+      ;;
+
+    sunos4*)
+      _LT_TAGVAR(archive_cmds, $1)='$LD -assert pure-text -Bshareable -o $lib $libobjs $deplibs $linker_flags'
+      wlarc=
+      _LT_TAGVAR(hardcode_direct, $1)=yes
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    *)
+      if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
+       _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+       _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+      else
+       _LT_TAGVAR(ld_shlibs, $1)=no
+      fi
+      ;;
+    esac
+
+    if test "$_LT_TAGVAR(ld_shlibs, $1)" = no; then
+      runpath_var=
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)=
+      _LT_TAGVAR(export_dynamic_flag_spec, $1)=
+      _LT_TAGVAR(whole_archive_flag_spec, $1)=
+    fi
+  else
+    # PORTME fill in a description of your system's linker (not GNU ld)
+    case $host_os in
+    aix3*)
+      _LT_TAGVAR(allow_undefined_flag, $1)=unsupported
+      _LT_TAGVAR(always_export_symbols, $1)=yes
+      _LT_TAGVAR(archive_expsym_cmds, $1)='$LD -o $output_objdir/$soname $libobjs $deplibs $linker_flags -bE:$export_symbols -T512 -H512 -bM:SRE~$AR $AR_FLAGS $lib $output_objdir/$soname'
+      # Note: this linker hardcodes the directories in LIBPATH if there
+      # are no directories specified by -L.
+      _LT_TAGVAR(hardcode_minus_L, $1)=yes
+      if test "$GCC" = yes && test -z "$lt_prog_compiler_static"; then
+       # Neither direct hardcoding nor static linking is supported with a
+       # broken collect2.
+       _LT_TAGVAR(hardcode_direct, $1)=unsupported
+      fi
+      ;;
+
+    aix[[4-9]]*)
+      if test "$host_cpu" = ia64; then
+       # On IA64, the linker does run time linking by default, so we don't
+       # have to do anything special.
+       aix_use_runtimelinking=no
+       exp_sym_flag='-Bexport'
+       no_entry_flag=""
+      else
+       # If we're using GNU nm, then we don't want the "-C" option.
+       # -C means demangle to AIX nm, but means don't demangle with GNU nm
+       # Also, AIX nm treats weak defined symbols like other global
+       # defined symbols, whereas GNU nm marks them as "W".
+       if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then
+         _LT_TAGVAR(export_symbols_cmds, $1)='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W")) && ([substr](\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols'
+       else
+         _LT_TAGVAR(export_symbols_cmds, $1)='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && ([substr](\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols'
+       fi
+       aix_use_runtimelinking=no
+
+       # Test if we are trying to use run time linking or normal
+       # AIX style linking. If -brtl is somewhere in LDFLAGS, we
+       # need to do runtime linking.
+       case $host_os in aix4.[[23]]|aix4.[[23]].*|aix[[5-9]]*)
+         for ld_flag in $LDFLAGS; do
+         if (test $ld_flag = "-brtl" || test $ld_flag = "-Wl,-brtl"); then
+           aix_use_runtimelinking=yes
+           break
+         fi
+         done
+         ;;
+       esac
+
+       exp_sym_flag='-bexport'
+       no_entry_flag='-bnoentry'
+      fi
+
+      # When large executables or shared objects are built, AIX ld can
+      # have problems creating the table of contents.  If linking a library
+      # or program results in "error TOC overflow" add -mminimal-toc to
+      # CXXFLAGS/CFLAGS for g++/gcc.  In the cases where that is not
+      # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS.
+
+      _LT_TAGVAR(archive_cmds, $1)=''
+      _LT_TAGVAR(hardcode_direct, $1)=yes
+      _LT_TAGVAR(hardcode_direct_absolute, $1)=yes
+      _LT_TAGVAR(hardcode_libdir_separator, $1)=':'
+      _LT_TAGVAR(link_all_deplibs, $1)=yes
+      _LT_TAGVAR(file_list_spec, $1)='${wl}-f,'
+
+      if test "$GCC" = yes; then
+       case $host_os in aix4.[[012]]|aix4.[[012]].*)
+       # We only want to do this on AIX 4.2 and lower, the check
+       # below for broken collect2 doesn't work under 4.3+
+         collect2name=`${CC} -print-prog-name=collect2`
+         if test -f "$collect2name" &&
+          strings "$collect2name" | $GREP resolve_lib_name >/dev/null
+         then
+         # We have reworked collect2
+         :
+         else
+         # We have old collect2
+         _LT_TAGVAR(hardcode_direct, $1)=unsupported
+         # It fails to find uninstalled libraries when the uninstalled
+         # path is not listed in the libpath.  Setting hardcode_minus_L
+         # to unsupported forces relinking
+         _LT_TAGVAR(hardcode_minus_L, $1)=yes
+         _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+         _LT_TAGVAR(hardcode_libdir_separator, $1)=
+         fi
+         ;;
+       esac
+       shared_flag='-shared'
+       if test "$aix_use_runtimelinking" = yes; then
+         shared_flag="$shared_flag "'${wl}-G'
+       fi
+       _LT_TAGVAR(link_all_deplibs, $1)=no
+      else
+       # not using gcc
+       if test "$host_cpu" = ia64; then
+       # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release
+       # chokes on -Wl,-G. The following line is correct:
+         shared_flag='-G'
+       else
+         if test "$aix_use_runtimelinking" = yes; then
+           shared_flag='${wl}-G'
+         else
+           shared_flag='${wl}-bM:SRE'
+         fi
+       fi
+      fi
+
+      _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-bexpall'
+      # It seems that -bexpall does not export symbols beginning with
+      # underscore (_), so it is better to generate a list of symbols to export.
+      _LT_TAGVAR(always_export_symbols, $1)=yes
+      if test "$aix_use_runtimelinking" = yes; then
+       # Warning - without using the other runtime loading flags (-brtl),
+       # -berok will link without error, but may produce a broken library.
+       _LT_TAGVAR(allow_undefined_flag, $1)='-berok'
+        # Determine the default libpath from the value encoded in an
+        # empty executable.
+        _LT_SYS_MODULE_PATH_AIX([$1])
+        _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath"
+        _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags `if test "x${allow_undefined_flag}" != "x"; then func_echo_all "${wl}${allow_undefined_flag}"; else :; fi` '"\${wl}$exp_sym_flag:\$export_symbols $shared_flag"
+      else
+       if test "$host_cpu" = ia64; then
+         _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $libdir:/usr/lib:/lib'
+         _LT_TAGVAR(allow_undefined_flag, $1)="-z nodefs"
+         _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$exp_sym_flag:\$export_symbols"
+       else
+        # Determine the default libpath from the value encoded in an
+        # empty executable.
+        _LT_SYS_MODULE_PATH_AIX([$1])
+        _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath"
+         # Warning - without using the other run time loading flags,
+         # -berok will link without error, but may produce a broken library.
+         _LT_TAGVAR(no_undefined_flag, $1)=' ${wl}-bernotok'
+         _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-berok'
+         if test "$with_gnu_ld" = yes; then
+           # We only use this code for GNU lds that support --whole-archive.
+           _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive$convenience ${wl}--no-whole-archive'
+         else
+           # Exported symbols can be pulled into shared objects from archives
+           _LT_TAGVAR(whole_archive_flag_spec, $1)='$convenience'
+         fi
+         _LT_TAGVAR(archive_cmds_need_lc, $1)=yes
+         # This is similar to how AIX traditionally builds its shared libraries.
+         _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs ${wl}-bnoentry $compiler_flags ${wl}-bE:$export_symbols${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname'
+       fi
+      fi
+      ;;
+
+    amigaos*)
+      case $host_cpu in
+      powerpc)
+            # see comment about AmigaOS4 .so support
+            _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+            _LT_TAGVAR(archive_expsym_cmds, $1)=''
+        ;;
+      m68k)
+            _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)'
+            _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+            _LT_TAGVAR(hardcode_minus_L, $1)=yes
+        ;;
+      esac
+      ;;
+
+    bsdi[[45]]*)
+      _LT_TAGVAR(export_dynamic_flag_spec, $1)=-rdynamic
+      ;;
+
+    cygwin* | mingw* | pw32* | cegcc*)
+      # When not using gcc, we currently assume that we are using
+      # Microsoft Visual C++.
+      # hardcode_libdir_flag_spec is actually meaningless, as there is
+      # no search path for DLLs.
+      case $cc_basename in
+      cl*)
+       # Native MSVC
+       _LT_TAGVAR(hardcode_libdir_flag_spec, $1)=' '
+       _LT_TAGVAR(allow_undefined_flag, $1)=unsupported
+       _LT_TAGVAR(always_export_symbols, $1)=yes
+       _LT_TAGVAR(file_list_spec, $1)='@'
+       # Tell ltmain to make .lib files, not .a files.
+       libext=lib
+       # Tell ltmain to make .dll files, not .so files.
+       shrext_cmds=".dll"
+       # FIXME: Setting linknames here is a bad hack.
+       _LT_TAGVAR(archive_cmds, $1)='$CC -o $output_objdir/$soname $libobjs $compiler_flags $deplibs -Wl,-dll~linknames='
+       _LT_TAGVAR(archive_expsym_cmds, $1)='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then
+           sed -n -e 's/\\\\\\\(.*\\\\\\\)/-link\\\ -EXPORT:\\\\\\\1/' -e '1\\\!p' < $export_symbols > $output_objdir/$soname.exp;
+         else
+           sed -e 's/\\\\\\\(.*\\\\\\\)/-link\\\ -EXPORT:\\\\\\\1/' < $export_symbols > $output_objdir/$soname.exp;
+         fi~
+         $CC -o $tool_output_objdir$soname $libobjs $compiler_flags $deplibs "@$tool_output_objdir$soname.exp" -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~
+         linknames='
+       # The linker will not automatically build a static lib if we build a DLL.
+       # _LT_TAGVAR(old_archive_from_new_cmds, $1)='true'
+       _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes
+       _LT_TAGVAR(exclude_expsyms, $1)='_NULL_IMPORT_DESCRIPTOR|_IMPORT_DESCRIPTOR_.*'
+       _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]][[ ]]/s/.*[[ ]]\([[^ ]]*\)/\1,DATA/'\'' | $SED -e '\''/^[[AITW]][[ ]]/s/.*[[ ]]//'\'' | sort | uniq > $export_symbols'
+       # Don't use ranlib
+       _LT_TAGVAR(old_postinstall_cmds, $1)='chmod 644 $oldlib'
+       _LT_TAGVAR(postlink_cmds, $1)='lt_outputfile="@OUTPUT@"~
+         lt_tool_outputfile="@TOOL_OUTPUT@"~
+         case $lt_outputfile in
+           *.exe|*.EXE) ;;
+           *)
+             lt_outputfile="$lt_outputfile.exe"
+             lt_tool_outputfile="$lt_tool_outputfile.exe"
+             ;;
+         esac~
+         if test "$MANIFEST_TOOL" != ":" && test -f "$lt_outputfile.manifest"; then
+           $MANIFEST_TOOL -manifest "$lt_tool_outputfile.manifest" -outputresource:"$lt_tool_outputfile" || exit 1;
+           $RM "$lt_outputfile.manifest";
+         fi'
+       ;;
+      *)
+       # Assume MSVC wrapper
+       _LT_TAGVAR(hardcode_libdir_flag_spec, $1)=' '
+       _LT_TAGVAR(allow_undefined_flag, $1)=unsupported
+       # Tell ltmain to make .lib files, not .a files.
+       libext=lib
+       # Tell ltmain to make .dll files, not .so files.
+       shrext_cmds=".dll"
+       # FIXME: Setting linknames here is a bad hack.
+       _LT_TAGVAR(archive_cmds, $1)='$CC -o $lib $libobjs $compiler_flags `func_echo_all "$deplibs" | $SED '\''s/ -lc$//'\''` -link -dll~linknames='
+       # The linker will automatically build a .lib file if we build a DLL.
+       _LT_TAGVAR(old_archive_from_new_cmds, $1)='true'
+       # FIXME: Should let the user specify the lib program.
+       _LT_TAGVAR(old_archive_cmds, $1)='lib -OUT:$oldlib$oldobjs$old_deplibs'
+       _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes
+       ;;
+      esac
+      ;;
+
+    darwin* | rhapsody*)
+      _LT_DARWIN_LINKER_FEATURES($1)
+      ;;
+
+    dgux*)
+      _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    # FreeBSD 2.2.[012] allows us to include c++rt0.o to get C++ constructor
+    # support.  Future versions do this automatically, but an explicit c++rt0.o
+    # does not break anything, and helps significantly (at the cost of a little
+    # extra space).
+    freebsd2.2*)
+      _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags /usr/lib/c++rt0.o'
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
+      _LT_TAGVAR(hardcode_direct, $1)=yes
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    # Unfortunately, older versions of FreeBSD 2 do not have this feature.
+    freebsd2.*)
+      _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'
+      _LT_TAGVAR(hardcode_direct, $1)=yes
+      _LT_TAGVAR(hardcode_minus_L, $1)=yes
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    # FreeBSD 3 and greater uses gcc -shared to do shared libraries.
+    freebsd* | dragonfly*)
+      _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags'
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
+      _LT_TAGVAR(hardcode_direct, $1)=yes
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    hpux9*)
+      if test "$GCC" = yes; then
+       _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$CC -shared $pic_flag ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $libobjs $deplibs $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
+      else
+       _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$LD -b +b $install_libdir -o $output_objdir/$soname $libobjs $deplibs $linker_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
+      fi
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir'
+      _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+      _LT_TAGVAR(hardcode_direct, $1)=yes
+
+      # hardcode_minus_L: Not really in the search PATH,
+      # but as the default location of the library.
+      _LT_TAGVAR(hardcode_minus_L, $1)=yes
+      _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+      ;;
+
+    hpux10*)
+      if test "$GCC" = yes && test "$with_gnu_ld" = no; then
+       _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'
+      else
+       _LT_TAGVAR(archive_cmds, $1)='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags'
+      fi
+      if test "$with_gnu_ld" = no; then
+       _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir'
+       _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+       _LT_TAGVAR(hardcode_direct, $1)=yes
+       _LT_TAGVAR(hardcode_direct_absolute, $1)=yes
+       _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+       # hardcode_minus_L: Not really in the search PATH,
+       # but as the default location of the library.
+       _LT_TAGVAR(hardcode_minus_L, $1)=yes
+      fi
+      ;;
+
+    hpux11*)
+      if test "$GCC" = yes && test "$with_gnu_ld" = no; then
+       case $host_cpu in
+       hppa*64*)
+         _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
+         ;;
+       ia64*)
+         _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags'
+         ;;
+       *)
+         _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'
+         ;;
+       esac
+      else
+       case $host_cpu in
+       hppa*64*)
+         _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
+         ;;
+       ia64*)
+         _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags'
+         ;;
+       *)
+       m4_if($1, [], [
+         # Older versions of the 11.00 compiler do not understand -b yet
+         # (HP92453-01 A.11.01.20 doesn't, HP92453-01 B.11.X.35175-35176.GP does)
+         _LT_LINKER_OPTION([if $CC understands -b],
+           _LT_TAGVAR(lt_cv_prog_compiler__b, $1), [-b],
+           [_LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'],
+           [_LT_TAGVAR(archive_cmds, $1)='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags'])],
+         [_LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'])
+         ;;
+       esac
+      fi
+      if test "$with_gnu_ld" = no; then
+       _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir'
+       _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+
+       case $host_cpu in
+       hppa*64*|ia64*)
+         _LT_TAGVAR(hardcode_direct, $1)=no
+         _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+         ;;
+       *)
+         _LT_TAGVAR(hardcode_direct, $1)=yes
+         _LT_TAGVAR(hardcode_direct_absolute, $1)=yes
+         _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+
+         # hardcode_minus_L: Not really in the search PATH,
+         # but as the default location of the library.
+         _LT_TAGVAR(hardcode_minus_L, $1)=yes
+         ;;
+       esac
+      fi
+      ;;
+
+    irix5* | irix6* | nonstopux*)
+      if test "$GCC" = yes; then
+       _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && func_echo_all "${wl}-set_version ${wl}$verstring"` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+       # Try to use the -exported_symbol ld option, if it does not
+       # work, assume that -exports_file does not work either and
+       # implicitly export all symbols.
+       # This should be the same for all languages, so no per-tag cache variable.
+       AC_CACHE_CHECK([whether the $host_os linker accepts -exported_symbol],
+         [lt_cv_irix_exported_symbol],
+         [save_LDFLAGS="$LDFLAGS"
+          LDFLAGS="$LDFLAGS -shared ${wl}-exported_symbol ${wl}foo ${wl}-update_registry ${wl}/dev/null"
+          AC_LINK_IFELSE(
+            [AC_LANG_SOURCE(
+               [AC_LANG_CASE([C], [[int foo (void) { return 0; }]],
+                             [C++], [[int foo (void) { return 0; }]],
+                             [Fortran 77], [[
+      subroutine foo
+      end]],
+                             [Fortran], [[
+      subroutine foo
+      end]])])],
+             [lt_cv_irix_exported_symbol=yes],
+             [lt_cv_irix_exported_symbol=no])
+           LDFLAGS="$save_LDFLAGS"])
+       if test "$lt_cv_irix_exported_symbol" = yes; then
+          _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && func_echo_all "${wl}-set_version ${wl}$verstring"` ${wl}-update_registry ${wl}${output_objdir}/so_locations ${wl}-exports_file ${wl}$export_symbols -o $lib'
+       fi
+      else
+       _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry ${output_objdir}/so_locations -o $lib'
+       _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry ${output_objdir}/so_locations -exports_file $export_symbols -o $lib'
+      fi
+      _LT_TAGVAR(archive_cmds_need_lc, $1)='no'
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+      _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+      _LT_TAGVAR(inherit_rpath, $1)=yes
+      _LT_TAGVAR(link_all_deplibs, $1)=yes
+      ;;
+
+    netbsd* | netbsdelf*-gnu)
+      if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
+       _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'  # a.out
+      else
+       _LT_TAGVAR(archive_cmds, $1)='$LD -shared -o $lib $libobjs $deplibs $linker_flags'      # ELF
+      fi
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
+      _LT_TAGVAR(hardcode_direct, $1)=yes
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    newsos6)
+      _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      _LT_TAGVAR(hardcode_direct, $1)=yes
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+      _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    *nto* | *qnx*)
+      ;;
+
+    openbsd*)
+      if test -f /usr/libexec/ld.so; then
+       _LT_TAGVAR(hardcode_direct, $1)=yes
+       _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+       _LT_TAGVAR(hardcode_direct_absolute, $1)=yes
+       if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
+         _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags'
+         _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-retain-symbols-file,$export_symbols'
+         _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
+         _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+       else
+         case $host_os in
+          openbsd[[01]].* | openbsd2.[[0-7]] | openbsd2.[[0-7]].*)
+            _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'
+            _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
+            ;;
+          *)
+            _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags'
+            _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
+            ;;
+         esac
+       fi
+      else
+       _LT_TAGVAR(ld_shlibs, $1)=no
+      fi
+      ;;
+
+    os2*)
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+      _LT_TAGVAR(hardcode_minus_L, $1)=yes
+      _LT_TAGVAR(allow_undefined_flag, $1)=unsupported
+      _LT_TAGVAR(archive_cmds, $1)='$ECHO "LIBRARY $libname INITINSTANCE" > $output_objdir/$libname.def~$ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~echo DATA >> $output_objdir/$libname.def~echo " SINGLE NONSHARED" >> $output_objdir/$libname.def~echo EXPORTS >> $output_objdir/$libname.def~emxexp $libobjs >> $output_objdir/$libname.def~$CC -Zdll -Zcrtdll -o $lib $libobjs $deplibs $compiler_flags $output_objdir/$libname.def'
+      _LT_TAGVAR(old_archive_from_new_cmds, $1)='emximp -o $output_objdir/$libname.a $output_objdir/$libname.def'
+      ;;
+
+    osf3*)
+      if test "$GCC" = yes; then
+       _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*'
+       _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && func_echo_all "${wl}-set_version ${wl}$verstring"` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+      else
+       _LT_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*'
+       _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry ${output_objdir}/so_locations -o $lib'
+      fi
+      _LT_TAGVAR(archive_cmds_need_lc, $1)='no'
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+      _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+      ;;
+
+    osf4* | osf5*)     # as osf3* with the addition of -msym flag
+      if test "$GCC" = yes; then
+       _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*'
+       _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $pic_flag $libobjs $deplibs $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && func_echo_all "${wl}-set_version ${wl}$verstring"` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+       _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+      else
+       _LT_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*'
+       _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags -msym -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry ${output_objdir}/so_locations -o $lib'
+       _LT_TAGVAR(archive_expsym_cmds, $1)='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done; printf "%s\\n" "-hidden">> $lib.exp~
+       $CC -shared${allow_undefined_flag} ${wl}-input ${wl}$lib.exp $compiler_flags $libobjs $deplibs -soname $soname `test -n "$verstring" && $ECHO "-set_version $verstring"` -update_registry ${output_objdir}/so_locations -o $lib~$RM $lib.exp'
+
+       # Both c and cxx compiler support -rpath directly
+       _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir'
+      fi
+      _LT_TAGVAR(archive_cmds_need_lc, $1)='no'
+      _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+      ;;
+
+    solaris*)
+      _LT_TAGVAR(no_undefined_flag, $1)=' -z defs'
+      if test "$GCC" = yes; then
+       wlarc='${wl}'
+       _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag ${wl}-z ${wl}text ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
+       _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
+         $CC -shared $pic_flag ${wl}-z ${wl}text ${wl}-M ${wl}$lib.exp ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp'
+      else
+       case `$CC -V 2>&1` in
+       *"Compilers 5.0"*)
+         wlarc=''
+         _LT_TAGVAR(archive_cmds, $1)='$LD -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $linker_flags'
+         _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
+         $LD -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $linker_flags~$RM $lib.exp'
+         ;;
+       *)
+         wlarc='${wl}'
+         _LT_TAGVAR(archive_cmds, $1)='$CC -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $compiler_flags'
+         _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
+         $CC -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp'
+         ;;
+       esac
+      fi
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      case $host_os in
+      solaris2.[[0-5]] | solaris2.[[0-5]].*) ;;
+      *)
+       # The compiler driver will combine and reorder linker options,
+       # but understands `-z linker_flag'.  GCC discards it without `$wl',
+       # but is careful enough not to reorder.
+       # Supported since Solaris 2.6 (maybe 2.5.1?)
+       if test "$GCC" = yes; then
+         _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}-z ${wl}allextract$convenience ${wl}-z ${wl}defaultextract'
+       else
+         _LT_TAGVAR(whole_archive_flag_spec, $1)='-z allextract$convenience -z defaultextract'
+       fi
+       ;;
+      esac
+      _LT_TAGVAR(link_all_deplibs, $1)=yes
+      ;;
+
+    sunos4*)
+      if test "x$host_vendor" = xsequent; then
+       # Use $CC to link under sequent, because it throws in some extra .o
+       # files that make .init and .fini sections work.
+       _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h $soname -o $lib $libobjs $deplibs $compiler_flags'
+      else
+       _LT_TAGVAR(archive_cmds, $1)='$LD -assert pure-text -Bstatic -o $lib $libobjs $deplibs $linker_flags'
+      fi
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+      _LT_TAGVAR(hardcode_direct, $1)=yes
+      _LT_TAGVAR(hardcode_minus_L, $1)=yes
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    sysv4)
+      case $host_vendor in
+       sni)
+         _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+         _LT_TAGVAR(hardcode_direct, $1)=yes # is this really true???
+       ;;
+       siemens)
+         ## LD is ld it makes a PLAMLIB
+         ## CC just makes a GrossModule.
+         _LT_TAGVAR(archive_cmds, $1)='$LD -G -o $lib $libobjs $deplibs $linker_flags'
+         _LT_TAGVAR(reload_cmds, $1)='$CC -r -o $output$reload_objs'
+         _LT_TAGVAR(hardcode_direct, $1)=no
+        ;;
+       motorola)
+         _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+         _LT_TAGVAR(hardcode_direct, $1)=no #Motorola manual says yes, but my tests say they lie
+       ;;
+      esac
+      runpath_var='LD_RUN_PATH'
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    sysv4.3*)
+      _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      _LT_TAGVAR(export_dynamic_flag_spec, $1)='-Bexport'
+      ;;
+
+    sysv4*MP*)
+      if test -d /usr/nec; then
+       _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+       _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+       runpath_var=LD_RUN_PATH
+       hardcode_runpath_var=yes
+       _LT_TAGVAR(ld_shlibs, $1)=yes
+      fi
+      ;;
+
+    sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[[01]].[[10]]* | unixware7* | sco3.2v5.0.[[024]]*)
+      _LT_TAGVAR(no_undefined_flag, $1)='${wl}-z,text'
+      _LT_TAGVAR(archive_cmds_need_lc, $1)=no
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      runpath_var='LD_RUN_PATH'
+
+      if test "$GCC" = yes; then
+       _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+       _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+      else
+       _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+       _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+      fi
+      ;;
+
+    sysv5* | sco3.2v5* | sco5v6*)
+      # Note: We can NOT use -z defs as we might desire, because we do not
+      # link with -lc, and that would cause any symbols used from libc to
+      # always be unresolved, which means just about no library would
+      # ever link correctly.  If we're not using GNU ld we use -z text
+      # though, which does catch some bad symbols but isn't as heavy-handed
+      # as -z defs.
+      _LT_TAGVAR(no_undefined_flag, $1)='${wl}-z,text'
+      _LT_TAGVAR(allow_undefined_flag, $1)='${wl}-z,nodefs'
+      _LT_TAGVAR(archive_cmds_need_lc, $1)=no
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R,$libdir'
+      _LT_TAGVAR(hardcode_libdir_separator, $1)=':'
+      _LT_TAGVAR(link_all_deplibs, $1)=yes
+      _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-Bexport'
+      runpath_var='LD_RUN_PATH'
+
+      if test "$GCC" = yes; then
+       _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+       _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+      else
+       _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+       _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+      fi
+      ;;
+
+    uts4*)
+      _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      ;;
+
+    *)
+      _LT_TAGVAR(ld_shlibs, $1)=no
+      ;;
+    esac
+
+    if test x$host_vendor = xsni; then
+      case $host in
+      sysv4 | sysv4.2uw2* | sysv4.3* | sysv5*)
+       _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-Blargedynsym'
+       ;;
+      esac
+    fi
+  fi
+])
+AC_MSG_RESULT([$_LT_TAGVAR(ld_shlibs, $1)])
+test "$_LT_TAGVAR(ld_shlibs, $1)" = no && can_build_shared=no
+
+_LT_TAGVAR(with_gnu_ld, $1)=$with_gnu_ld
+
+_LT_DECL([], [libext], [0], [Old archive suffix (normally "a")])dnl
+_LT_DECL([], [shrext_cmds], [1], [Shared library suffix (normally ".so")])dnl
+_LT_DECL([], [extract_expsyms_cmds], [2],
+    [The commands to extract the exported symbol list from a shared archive])
+
+#
+# Do we need to explicitly link libc?
+#
+case "x$_LT_TAGVAR(archive_cmds_need_lc, $1)" in
+x|xyes)
+  # Assume -lc should be added
+  _LT_TAGVAR(archive_cmds_need_lc, $1)=yes
+
+  if test "$enable_shared" = yes && test "$GCC" = yes; then
+    case $_LT_TAGVAR(archive_cmds, $1) in
+    *'~'*)
+      # FIXME: we may have to deal with multi-command sequences.
+      ;;
+    '$CC '*)
+      # Test whether the compiler implicitly links with -lc since on some
+      # systems, -lgcc has to come before -lc. If gcc already passes -lc
+      # to ld, don't add -lc before -lgcc.
+      AC_CACHE_CHECK([whether -lc should be explicitly linked in],
+       [lt_cv_]_LT_TAGVAR(archive_cmds_need_lc, $1),
+       [$RM conftest*
+       echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+
+       if AC_TRY_EVAL(ac_compile) 2>conftest.err; then
+         soname=conftest
+         lib=conftest
+         libobjs=conftest.$ac_objext
+         deplibs=
+         wl=$_LT_TAGVAR(lt_prog_compiler_wl, $1)
+         pic_flag=$_LT_TAGVAR(lt_prog_compiler_pic, $1)
+         compiler_flags=-v
+         linker_flags=-v
+         verstring=
+         output_objdir=.
+         libname=conftest
+         lt_save_allow_undefined_flag=$_LT_TAGVAR(allow_undefined_flag, $1)
+         _LT_TAGVAR(allow_undefined_flag, $1)=
+         if AC_TRY_EVAL(_LT_TAGVAR(archive_cmds, $1) 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1)
+         then
+           lt_cv_[]_LT_TAGVAR(archive_cmds_need_lc, $1)=no
+         else
+           lt_cv_[]_LT_TAGVAR(archive_cmds_need_lc, $1)=yes
+         fi
+         _LT_TAGVAR(allow_undefined_flag, $1)=$lt_save_allow_undefined_flag
+       else
+         cat conftest.err 1>&5
+       fi
+       $RM conftest*
+       ])
+      _LT_TAGVAR(archive_cmds_need_lc, $1)=$lt_cv_[]_LT_TAGVAR(archive_cmds_need_lc, $1)
+      ;;
+    esac
+  fi
+  ;;
+esac
+
+_LT_TAGDECL([build_libtool_need_lc], [archive_cmds_need_lc], [0],
+    [Whether or not to add -lc for building shared libraries])
+_LT_TAGDECL([allow_libtool_libs_with_static_runtimes],
+    [enable_shared_with_static_runtimes], [0],
+    [Whether or not to disallow shared libs when runtime libs are static])
+_LT_TAGDECL([], [export_dynamic_flag_spec], [1],
+    [Compiler flag to allow reflexive dlopens])
+_LT_TAGDECL([], [whole_archive_flag_spec], [1],
+    [Compiler flag to generate shared objects directly from archives])
+_LT_TAGDECL([], [compiler_needs_object], [1],
+    [Whether the compiler copes with passing no objects directly])
+_LT_TAGDECL([], [old_archive_from_new_cmds], [2],
+    [Create an old-style archive from a shared archive])
+_LT_TAGDECL([], [old_archive_from_expsyms_cmds], [2],
+    [Create a temporary old-style archive to link instead of a shared archive])
+_LT_TAGDECL([], [archive_cmds], [2], [Commands used to build a shared archive])
+_LT_TAGDECL([], [archive_expsym_cmds], [2])
+_LT_TAGDECL([], [module_cmds], [2],
+    [Commands used to build a loadable module if different from building
+    a shared archive.])
+_LT_TAGDECL([], [module_expsym_cmds], [2])
+_LT_TAGDECL([], [with_gnu_ld], [1],
+    [Whether we are building with GNU ld or not])
+_LT_TAGDECL([], [allow_undefined_flag], [1],
+    [Flag that allows shared libraries with undefined symbols to be built])
+_LT_TAGDECL([], [no_undefined_flag], [1],
+    [Flag that enforces no undefined symbols])
+_LT_TAGDECL([], [hardcode_libdir_flag_spec], [1],
+    [Flag to hardcode $libdir into a binary during linking.
+    This must work even if $libdir does not exist])
+_LT_TAGDECL([], [hardcode_libdir_separator], [1],
+    [Whether we need a single "-rpath" flag with a separated argument])
+_LT_TAGDECL([], [hardcode_direct], [0],
+    [Set to "yes" if using DIR/libNAME${shared_ext} during linking hardcodes
+    DIR into the resulting binary])
+_LT_TAGDECL([], [hardcode_direct_absolute], [0],
+    [Set to "yes" if using DIR/libNAME${shared_ext} during linking hardcodes
+    DIR into the resulting binary and the resulting library dependency is
+    "absolute", i.e impossible to change by setting ${shlibpath_var} if the
+    library is relocated])
+_LT_TAGDECL([], [hardcode_minus_L], [0],
+    [Set to "yes" if using the -LDIR flag during linking hardcodes DIR
+    into the resulting binary])
+_LT_TAGDECL([], [hardcode_shlibpath_var], [0],
+    [Set to "yes" if using SHLIBPATH_VAR=DIR during linking hardcodes DIR
+    into the resulting binary])
+_LT_TAGDECL([], [hardcode_automatic], [0],
+    [Set to "yes" if building a shared library automatically hardcodes DIR
+    into the library and all subsequent libraries and executables linked
+    against it])
+_LT_TAGDECL([], [inherit_rpath], [0],
+    [Set to yes if linker adds runtime paths of dependent libraries
+    to runtime path list])
+_LT_TAGDECL([], [link_all_deplibs], [0],
+    [Whether libtool must link a program against all its dependency libraries])
+_LT_TAGDECL([], [always_export_symbols], [0],
+    [Set to "yes" if exported symbols are required])
+_LT_TAGDECL([], [export_symbols_cmds], [2],
+    [The commands to list exported symbols])
+_LT_TAGDECL([], [exclude_expsyms], [1],
+    [Symbols that should not be listed in the preloaded symbols])
+_LT_TAGDECL([], [include_expsyms], [1],
+    [Symbols that must always be exported])
+_LT_TAGDECL([], [prelink_cmds], [2],
+    [Commands necessary for linking programs (against libraries) with templates])
+_LT_TAGDECL([], [postlink_cmds], [2],
+    [Commands necessary for finishing linking programs])
+_LT_TAGDECL([], [file_list_spec], [1],
+    [Specify filename containing input files])
+dnl FIXME: Not yet implemented
+dnl _LT_TAGDECL([], [thread_safe_flag_spec], [1],
+dnl    [Compiler flag to generate thread safe objects])
+])# _LT_LINKER_SHLIBS
+
+
+# _LT_LANG_C_CONFIG([TAG])
+# ------------------------
+# Ensure that the configuration variables for a C compiler are suitably
+# defined.  These variables are subsequently used by _LT_CONFIG to write
+# the compiler configuration to `libtool'.
+m4_defun([_LT_LANG_C_CONFIG],
+[m4_require([_LT_DECL_EGREP])dnl
+lt_save_CC="$CC"
+AC_LANG_PUSH(C)
+
+# Source file extension for C test sources.
+ac_ext=c
+
+# Object file extension for compiled C test sources.
+objext=o
+_LT_TAGVAR(objext, $1)=$objext
+
+# Code to be used in simple compile tests
+lt_simple_compile_test_code="int some_variable = 0;"
+
+# Code to be used in simple link tests
+lt_simple_link_test_code='int main(){return(0);}'
+
+_LT_TAG_COMPILER
+# Save the default compiler, since it gets overwritten when the other
+# tags are being tested, and _LT_TAGVAR(compiler, []) is a NOP.
+compiler_DEFAULT=$CC
+
+# save warnings/boilerplate of simple test code
+_LT_COMPILER_BOILERPLATE
+_LT_LINKER_BOILERPLATE
+
+if test -n "$compiler"; then
+  _LT_COMPILER_NO_RTTI($1)
+  _LT_COMPILER_PIC($1)
+  _LT_COMPILER_C_O($1)
+  _LT_COMPILER_FILE_LOCKS($1)
+  _LT_LINKER_SHLIBS($1)
+  _LT_SYS_DYNAMIC_LINKER($1)
+  _LT_LINKER_HARDCODE_LIBPATH($1)
+  LT_SYS_DLOPEN_SELF
+  _LT_CMD_STRIPLIB
+
+  # Report which library types will actually be built
+  AC_MSG_CHECKING([if libtool supports shared libraries])
+  AC_MSG_RESULT([$can_build_shared])
+
+  AC_MSG_CHECKING([whether to build shared libraries])
+  test "$can_build_shared" = "no" && enable_shared=no
+
+  # On AIX, shared libraries and static libraries use the same namespace, and
+  # are all built from PIC.
+  case $host_os in
+  aix3*)
+    test "$enable_shared" = yes && enable_static=no
+    if test -n "$RANLIB"; then
+      archive_cmds="$archive_cmds~\$RANLIB \$lib"
+      postinstall_cmds='$RANLIB $lib'
+    fi
+    ;;
+
+  aix[[4-9]]*)
+    if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then
+      test "$enable_shared" = yes && enable_static=no
+    fi
+    ;;
+  esac
+  AC_MSG_RESULT([$enable_shared])
+
+  AC_MSG_CHECKING([whether to build static libraries])
+  # Make sure either enable_shared or enable_static is yes.
+  test "$enable_shared" = yes || enable_static=yes
+  AC_MSG_RESULT([$enable_static])
+
+  _LT_CONFIG($1)
+fi
+AC_LANG_POP
+CC="$lt_save_CC"
+])# _LT_LANG_C_CONFIG
+
+
+# _LT_LANG_CXX_CONFIG([TAG])
+# --------------------------
+# Ensure that the configuration variables for a C++ compiler are suitably
+# defined.  These variables are subsequently used by _LT_CONFIG to write
+# the compiler configuration to `libtool'.
+m4_defun([_LT_LANG_CXX_CONFIG],
+[m4_require([_LT_FILEUTILS_DEFAULTS])dnl
+m4_require([_LT_DECL_EGREP])dnl
+m4_require([_LT_PATH_MANIFEST_TOOL])dnl
+if test -n "$CXX" && ( test "X$CXX" != "Xno" &&
+    ( (test "X$CXX" = "Xg++" && `g++ -v >/dev/null 2>&1` ) ||
+    (test "X$CXX" != "Xg++"))) ; then
+  AC_PROG_CXXCPP
+else
+  _lt_caught_CXX_error=yes
+fi
+
+AC_LANG_PUSH(C++)
+_LT_TAGVAR(archive_cmds_need_lc, $1)=no
+_LT_TAGVAR(allow_undefined_flag, $1)=
+_LT_TAGVAR(always_export_symbols, $1)=no
+_LT_TAGVAR(archive_expsym_cmds, $1)=
+_LT_TAGVAR(compiler_needs_object, $1)=no
+_LT_TAGVAR(export_dynamic_flag_spec, $1)=
+_LT_TAGVAR(hardcode_direct, $1)=no
+_LT_TAGVAR(hardcode_direct_absolute, $1)=no
+_LT_TAGVAR(hardcode_libdir_flag_spec, $1)=
+_LT_TAGVAR(hardcode_libdir_separator, $1)=
+_LT_TAGVAR(hardcode_minus_L, $1)=no
+_LT_TAGVAR(hardcode_shlibpath_var, $1)=unsupported
+_LT_TAGVAR(hardcode_automatic, $1)=no
+_LT_TAGVAR(inherit_rpath, $1)=no
+_LT_TAGVAR(module_cmds, $1)=
+_LT_TAGVAR(module_expsym_cmds, $1)=
+_LT_TAGVAR(link_all_deplibs, $1)=unknown
+_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds
+_LT_TAGVAR(reload_flag, $1)=$reload_flag
+_LT_TAGVAR(reload_cmds, $1)=$reload_cmds
+_LT_TAGVAR(no_undefined_flag, $1)=
+_LT_TAGVAR(whole_archive_flag_spec, $1)=
+_LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no
+
+# Source file extension for C++ test sources.
+ac_ext=cpp
+
+# Object file extension for compiled C++ test sources.
+objext=o
+_LT_TAGVAR(objext, $1)=$objext
+
+# No sense in running all these tests if we already determined that
+# the CXX compiler isn't working.  Some variables (like enable_shared)
+# are currently assumed to apply to all compilers on this platform,
+# and will be corrupted by setting them based on a non-working compiler.
+if test "$_lt_caught_CXX_error" != yes; then
+  # Code to be used in simple compile tests
+  lt_simple_compile_test_code="int some_variable = 0;"
+
+  # Code to be used in simple link tests
+  lt_simple_link_test_code='int main(int, char *[[]]) { return(0); }'
+
+  # ltmain only uses $CC for tagged configurations so make sure $CC is set.
+  _LT_TAG_COMPILER
+
+  # save warnings/boilerplate of simple test code
+  _LT_COMPILER_BOILERPLATE
+  _LT_LINKER_BOILERPLATE
+
+  # Allow CC to be a program name with arguments.
+  lt_save_CC=$CC
+  lt_save_CFLAGS=$CFLAGS
+  lt_save_LD=$LD
+  lt_save_GCC=$GCC
+  GCC=$GXX
+  lt_save_with_gnu_ld=$with_gnu_ld
+  lt_save_path_LD=$lt_cv_path_LD
+  if test -n "${lt_cv_prog_gnu_ldcxx+set}"; then
+    lt_cv_prog_gnu_ld=$lt_cv_prog_gnu_ldcxx
+  else
+    $as_unset lt_cv_prog_gnu_ld
+  fi
+  if test -n "${lt_cv_path_LDCXX+set}"; then
+    lt_cv_path_LD=$lt_cv_path_LDCXX
+  else
+    $as_unset lt_cv_path_LD
+  fi
+  test -z "${LDCXX+set}" || LD=$LDCXX
+  CC=${CXX-"c++"}
+  CFLAGS=$CXXFLAGS
+  compiler=$CC
+  _LT_TAGVAR(compiler, $1)=$CC
+  _LT_CC_BASENAME([$compiler])
+
+  if test -n "$compiler"; then
+    # We don't want -fno-exception when compiling C++ code, so set the
+    # no_builtin_flag separately
+    if test "$GXX" = yes; then
+      _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=' -fno-builtin'
+    else
+      _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=
+    fi
+
+    if test "$GXX" = yes; then
+      # Set up default GNU C++ configuration
+
+      LT_PATH_LD
+
+      # Check if GNU C++ uses GNU ld as the underlying linker, since the
+      # archiving commands below assume that GNU ld is being used.
+      if test "$with_gnu_ld" = yes; then
+        _LT_TAGVAR(archive_cmds, $1)='$CC $pic_flag -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib'
+        _LT_TAGVAR(archive_expsym_cmds, $1)='$CC $pic_flag -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+
+        _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+        _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
+
+        # If archive_cmds runs LD, not CC, wlarc should be empty
+        # XXX I think wlarc can be eliminated in ltcf-cxx, but I need to
+        #     investigate it a little bit more. (MM)
+        wlarc='${wl}'
+
+        # ancient GNU ld didn't support --whole-archive et. al.
+        if eval "`$CC -print-prog-name=ld` --help 2>&1" |
+         $GREP 'no-whole-archive' > /dev/null; then
+          _LT_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive'
+        else
+          _LT_TAGVAR(whole_archive_flag_spec, $1)=
+        fi
+      else
+        with_gnu_ld=no
+        wlarc=
+
+        # A generic and very simple default shared library creation
+        # command for GNU C++ for the case where it uses the native
+        # linker, instead of GNU ld.  If possible, this setting should
+        # overridden to take advantage of the native linker features on
+        # the platform it is being used on.
+        _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib'
+      fi
+
+      # Commands to make compiler produce verbose output that lists
+      # what "hidden" libraries, object files and flags are used when
+      # linking a shared library.
+      output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"'
+
+    else
+      GXX=no
+      with_gnu_ld=no
+      wlarc=
+    fi
+
+    # PORTME: fill in a description of your system's C++ link characteristics
+    AC_MSG_CHECKING([whether the $compiler linker ($LD) supports shared libraries])
+    _LT_TAGVAR(ld_shlibs, $1)=yes
+    case $host_os in
+      aix3*)
+        # FIXME: insert proper C++ library support
+        _LT_TAGVAR(ld_shlibs, $1)=no
+        ;;
+      aix[[4-9]]*)
+        if test "$host_cpu" = ia64; then
+          # On IA64, the linker does run time linking by default, so we don't
+          # have to do anything special.
+          aix_use_runtimelinking=no
+          exp_sym_flag='-Bexport'
+          no_entry_flag=""
+        else
+          aix_use_runtimelinking=no
+
+          # Test if we are trying to use run time linking or normal
+          # AIX style linking. If -brtl is somewhere in LDFLAGS, we
+          # need to do runtime linking.
+          case $host_os in aix4.[[23]]|aix4.[[23]].*|aix[[5-9]]*)
+           for ld_flag in $LDFLAGS; do
+             case $ld_flag in
+             *-brtl*)
+               aix_use_runtimelinking=yes
+               break
+               ;;
+             esac
+           done
+           ;;
+          esac
+
+          exp_sym_flag='-bexport'
+          no_entry_flag='-bnoentry'
+        fi
+
+        # When large executables or shared objects are built, AIX ld can
+        # have problems creating the table of contents.  If linking a library
+        # or program results in "error TOC overflow" add -mminimal-toc to
+        # CXXFLAGS/CFLAGS for g++/gcc.  In the cases where that is not
+        # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS.
+
+        _LT_TAGVAR(archive_cmds, $1)=''
+        _LT_TAGVAR(hardcode_direct, $1)=yes
+        _LT_TAGVAR(hardcode_direct_absolute, $1)=yes
+        _LT_TAGVAR(hardcode_libdir_separator, $1)=':'
+        _LT_TAGVAR(link_all_deplibs, $1)=yes
+        _LT_TAGVAR(file_list_spec, $1)='${wl}-f,'
+
+        if test "$GXX" = yes; then
+          case $host_os in aix4.[[012]]|aix4.[[012]].*)
+          # We only want to do this on AIX 4.2 and lower, the check
+          # below for broken collect2 doesn't work under 4.3+
+         collect2name=`${CC} -print-prog-name=collect2`
+         if test -f "$collect2name" &&
+            strings "$collect2name" | $GREP resolve_lib_name >/dev/null
+         then
+           # We have reworked collect2
+           :
+         else
+           # We have old collect2
+           _LT_TAGVAR(hardcode_direct, $1)=unsupported
+           # It fails to find uninstalled libraries when the uninstalled
+           # path is not listed in the libpath.  Setting hardcode_minus_L
+           # to unsupported forces relinking
+           _LT_TAGVAR(hardcode_minus_L, $1)=yes
+           _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+           _LT_TAGVAR(hardcode_libdir_separator, $1)=
+         fi
+          esac
+          shared_flag='-shared'
+         if test "$aix_use_runtimelinking" = yes; then
+           shared_flag="$shared_flag "'${wl}-G'
+         fi
+        else
+          # not using gcc
+          if test "$host_cpu" = ia64; then
+         # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release
+         # chokes on -Wl,-G. The following line is correct:
+         shared_flag='-G'
+          else
+           if test "$aix_use_runtimelinking" = yes; then
+             shared_flag='${wl}-G'
+           else
+             shared_flag='${wl}-bM:SRE'
+           fi
+          fi
+        fi
+
+        _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-bexpall'
+        # It seems that -bexpall does not export symbols beginning with
+        # underscore (_), so it is better to generate a list of symbols to
+       # export.
+        _LT_TAGVAR(always_export_symbols, $1)=yes
+        if test "$aix_use_runtimelinking" = yes; then
+          # Warning - without using the other runtime loading flags (-brtl),
+          # -berok will link without error, but may produce a broken library.
+          _LT_TAGVAR(allow_undefined_flag, $1)='-berok'
+          # Determine the default libpath from the value encoded in an empty
+          # executable.
+          _LT_SYS_MODULE_PATH_AIX([$1])
+          _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath"
+
+          _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags `if test "x${allow_undefined_flag}" != "x"; then func_echo_all "${wl}${allow_undefined_flag}"; else :; fi` '"\${wl}$exp_sym_flag:\$export_symbols $shared_flag"
+        else
+          if test "$host_cpu" = ia64; then
+           _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $libdir:/usr/lib:/lib'
+           _LT_TAGVAR(allow_undefined_flag, $1)="-z nodefs"
+           _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$exp_sym_flag:\$export_symbols"
+          else
+           # Determine the default libpath from the value encoded in an
+           # empty executable.
+           _LT_SYS_MODULE_PATH_AIX([$1])
+           _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath"
+           # Warning - without using the other run time loading flags,
+           # -berok will link without error, but may produce a broken library.
+           _LT_TAGVAR(no_undefined_flag, $1)=' ${wl}-bernotok'
+           _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-berok'
+           if test "$with_gnu_ld" = yes; then
+             # We only use this code for GNU lds that support --whole-archive.
+             _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive$convenience ${wl}--no-whole-archive'
+           else
+             # Exported symbols can be pulled into shared objects from archives
+             _LT_TAGVAR(whole_archive_flag_spec, $1)='$convenience'
+           fi
+           _LT_TAGVAR(archive_cmds_need_lc, $1)=yes
+           # This is similar to how AIX traditionally builds its shared
+           # libraries.
+           _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs ${wl}-bnoentry $compiler_flags ${wl}-bE:$export_symbols${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname'
+          fi
+        fi
+        ;;
+
+      beos*)
+       if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
+         _LT_TAGVAR(allow_undefined_flag, $1)=unsupported
+         # Joseph Beckenbach <jrb3@best.com> says some releases of gcc
+         # support --undefined.  This deserves some investigation.  FIXME
+         _LT_TAGVAR(archive_cmds, $1)='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+       else
+         _LT_TAGVAR(ld_shlibs, $1)=no
+       fi
+       ;;
+
+      chorus*)
+        case $cc_basename in
+          *)
+         # FIXME: insert proper C++ library support
+         _LT_TAGVAR(ld_shlibs, $1)=no
+         ;;
+        esac
+        ;;
+
+      cygwin* | mingw* | pw32* | cegcc*)
+       case $GXX,$cc_basename in
+       ,cl* | no,cl*)
+         # Native MSVC
+         # hardcode_libdir_flag_spec is actually meaningless, as there is
+         # no search path for DLLs.
+         _LT_TAGVAR(hardcode_libdir_flag_spec, $1)=' '
+         _LT_TAGVAR(allow_undefined_flag, $1)=unsupported
+         _LT_TAGVAR(always_export_symbols, $1)=yes
+         _LT_TAGVAR(file_list_spec, $1)='@'
+         # Tell ltmain to make .lib files, not .a files.
+         libext=lib
+         # Tell ltmain to make .dll files, not .so files.
+         shrext_cmds=".dll"
+         # FIXME: Setting linknames here is a bad hack.
+         _LT_TAGVAR(archive_cmds, $1)='$CC -o $output_objdir/$soname $libobjs $compiler_flags $deplibs -Wl,-dll~linknames='
+         _LT_TAGVAR(archive_expsym_cmds, $1)='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then
+             $SED -n -e 's/\\\\\\\(.*\\\\\\\)/-link\\\ -EXPORT:\\\\\\\1/' -e '1\\\!p' < $export_symbols > $output_objdir/$soname.exp;
+           else
+             $SED -e 's/\\\\\\\(.*\\\\\\\)/-link\\\ -EXPORT:\\\\\\\1/' < $export_symbols > $output_objdir/$soname.exp;
+           fi~
+           $CC -o $tool_output_objdir$soname $libobjs $compiler_flags $deplibs "@$tool_output_objdir$soname.exp" -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~
+           linknames='
+         # The linker will not automatically build a static lib if we build a DLL.
+         # _LT_TAGVAR(old_archive_from_new_cmds, $1)='true'
+         _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes
+         # Don't use ranlib
+         _LT_TAGVAR(old_postinstall_cmds, $1)='chmod 644 $oldlib'
+         _LT_TAGVAR(postlink_cmds, $1)='lt_outputfile="@OUTPUT@"~
+           lt_tool_outputfile="@TOOL_OUTPUT@"~
+           case $lt_outputfile in
+             *.exe|*.EXE) ;;
+             *)
+               lt_outputfile="$lt_outputfile.exe"
+               lt_tool_outputfile="$lt_tool_outputfile.exe"
+               ;;
+           esac~
+           func_to_tool_file "$lt_outputfile"~
+           if test "$MANIFEST_TOOL" != ":" && test -f "$lt_outputfile.manifest"; then
+             $MANIFEST_TOOL -manifest "$lt_tool_outputfile.manifest" -outputresource:"$lt_tool_outputfile" || exit 1;
+             $RM "$lt_outputfile.manifest";
+           fi'
+         ;;
+       *)
+         # g++
+         # _LT_TAGVAR(hardcode_libdir_flag_spec, $1) is actually meaningless,
+         # as there is no search path for DLLs.
+         _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
+         _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-all-symbols'
+         _LT_TAGVAR(allow_undefined_flag, $1)=unsupported
+         _LT_TAGVAR(always_export_symbols, $1)=no
+         _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes
+
+         if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then
+           _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib'
+           # If the export-symbols file already is a .def file (1st line
+           # is EXPORTS), use it as is; otherwise, prepend...
+           _LT_TAGVAR(archive_expsym_cmds, $1)='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then
+             cp $export_symbols $output_objdir/$soname.def;
+           else
+             echo EXPORTS > $output_objdir/$soname.def;
+             cat $export_symbols >> $output_objdir/$soname.def;
+           fi~
+           $CC -shared -nostdlib $output_objdir/$soname.def $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib'
+         else
+           _LT_TAGVAR(ld_shlibs, $1)=no
+         fi
+         ;;
+       esac
+       ;;
+      darwin* | rhapsody*)
+        _LT_DARWIN_LINKER_FEATURES($1)
+       ;;
+
+      dgux*)
+        case $cc_basename in
+          ec++*)
+           # FIXME: insert proper C++ library support
+           _LT_TAGVAR(ld_shlibs, $1)=no
+           ;;
+          ghcx*)
+           # Green Hills C++ Compiler
+           # FIXME: insert proper C++ library support
+           _LT_TAGVAR(ld_shlibs, $1)=no
+           ;;
+          *)
+           # FIXME: insert proper C++ library support
+           _LT_TAGVAR(ld_shlibs, $1)=no
+           ;;
+        esac
+        ;;
+
+      freebsd2.*)
+        # C++ shared libraries reported to be fairly broken before
+       # switch to ELF
+        _LT_TAGVAR(ld_shlibs, $1)=no
+        ;;
+
+      freebsd-elf*)
+        _LT_TAGVAR(archive_cmds_need_lc, $1)=no
+        ;;
+
+      freebsd* | dragonfly*)
+        # FreeBSD 3 and later use GNU C++ and GNU ld with standard ELF
+        # conventions
+        _LT_TAGVAR(ld_shlibs, $1)=yes
+        ;;
+
+      haiku*)
+        _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+        _LT_TAGVAR(link_all_deplibs, $1)=yes
+        ;;
+
+      hpux9*)
+        _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir'
+        _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+        _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+        _LT_TAGVAR(hardcode_direct, $1)=yes
+        _LT_TAGVAR(hardcode_minus_L, $1)=yes # Not in the search PATH,
+                                            # but as the default
+                                            # location of the library.
+
+        case $cc_basename in
+          CC*)
+            # FIXME: insert proper C++ library support
+            _LT_TAGVAR(ld_shlibs, $1)=no
+            ;;
+          aCC*)
+            _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$CC -b ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
+            # Commands to make compiler produce verbose output that lists
+            # what "hidden" libraries, object files and flags are used when
+            # linking a shared library.
+            #
+            # There doesn't appear to be a way to prevent this compiler from
+            # explicitly linking system object files so we need to strip them
+            # from the output so that they don't get included in the library
+            # dependencies.
+            output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $EGREP "\-L"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"'
+            ;;
+          *)
+            if test "$GXX" = yes; then
+              _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$CC -shared -nostdlib $pic_flag ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
+            else
+              # FIXME: insert proper C++ library support
+              _LT_TAGVAR(ld_shlibs, $1)=no
+            fi
+            ;;
+        esac
+        ;;
+
+      hpux10*|hpux11*)
+        if test $with_gnu_ld = no; then
+         _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir'
+         _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+
+          case $host_cpu in
+            hppa*64*|ia64*)
+              ;;
+            *)
+             _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+              ;;
+          esac
+        fi
+        case $host_cpu in
+          hppa*64*|ia64*)
+            _LT_TAGVAR(hardcode_direct, $1)=no
+            _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+            ;;
+          *)
+            _LT_TAGVAR(hardcode_direct, $1)=yes
+            _LT_TAGVAR(hardcode_direct_absolute, $1)=yes
+            _LT_TAGVAR(hardcode_minus_L, $1)=yes # Not in the search PATH,
+                                                # but as the default
+                                                # location of the library.
+            ;;
+        esac
+
+        case $cc_basename in
+          CC*)
+           # FIXME: insert proper C++ library support
+           _LT_TAGVAR(ld_shlibs, $1)=no
+           ;;
+          aCC*)
+           case $host_cpu in
+             hppa*64*)
+               _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+               ;;
+             ia64*)
+               _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+               ;;
+             *)
+               _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+               ;;
+           esac
+           # Commands to make compiler produce verbose output that lists
+           # what "hidden" libraries, object files and flags are used when
+           # linking a shared library.
+           #
+           # There doesn't appear to be a way to prevent this compiler from
+           # explicitly linking system object files so we need to strip them
+           # from the output so that they don't get included in the library
+           # dependencies.
+           output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $GREP "\-L"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"'
+           ;;
+          *)
+           if test "$GXX" = yes; then
+             if test $with_gnu_ld = no; then
+               case $host_cpu in
+                 hppa*64*)
+                   _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib -fPIC ${wl}+h ${wl}$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+                   ;;
+                 ia64*)
+                   _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $pic_flag ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+                   ;;
+                 *)
+                   _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $pic_flag ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+                   ;;
+               esac
+             fi
+           else
+             # FIXME: insert proper C++ library support
+             _LT_TAGVAR(ld_shlibs, $1)=no
+           fi
+           ;;
+        esac
+        ;;
+
+      interix[[3-9]]*)
+       _LT_TAGVAR(hardcode_direct, $1)=no
+       _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+       _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
+       _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+       # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc.
+       # Instead, shared libraries are loaded at an image base (0x10000000 by
+       # default) and relocated if they conflict, which is a slow very memory
+       # consuming and fragmenting process.  To avoid this, we pick a random,
+       # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link
+       # time.  Moving up from 0x10000000 also allows more sbrk(2) space.
+       _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
+       _LT_TAGVAR(archive_expsym_cmds, $1)='sed "s,^,_," $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--retain-symbols-file,$output_objdir/$soname.expsym ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
+       ;;
+      irix5* | irix6*)
+        case $cc_basename in
+          CC*)
+           # SGI C++
+           _LT_TAGVAR(archive_cmds, $1)='$CC -shared -all -multigot $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry ${output_objdir}/so_locations -o $lib'
+
+           # Archives containing C++ object files must be created using
+           # "CC -ar", where "CC" is the IRIX C++ compiler.  This is
+           # necessary to make sure instantiated templates are included
+           # in the archive.
+           _LT_TAGVAR(old_archive_cmds, $1)='$CC -ar -WR,-u -o $oldlib $oldobjs'
+           ;;
+          *)
+           if test "$GXX" = yes; then
+             if test "$with_gnu_ld" = no; then
+               _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && func_echo_all "${wl}-set_version ${wl}$verstring"` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+             else
+               _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && func_echo_all "${wl}-set_version ${wl}$verstring"` -o $lib'
+             fi
+           fi
+           _LT_TAGVAR(link_all_deplibs, $1)=yes
+           ;;
+        esac
+        _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+        _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+        _LT_TAGVAR(inherit_rpath, $1)=yes
+        ;;
+
+      linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*)
+        case $cc_basename in
+          KCC*)
+           # Kuck and Associates, Inc. (KAI) C++ Compiler
+
+           # KCC will only create a shared library if the output file
+           # ends with ".so" (or ".sl" for HP-UX), so rename the library
+           # to its proper name (with version) after linking.
+           _LT_TAGVAR(archive_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib'
+           _LT_TAGVAR(archive_expsym_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib ${wl}-retain-symbols-file,$export_symbols; mv \$templib $lib'
+           # Commands to make compiler produce verbose output that lists
+           # what "hidden" libraries, object files and flags are used when
+           # linking a shared library.
+           #
+           # There doesn't appear to be a way to prevent this compiler from
+           # explicitly linking system object files so we need to strip them
+           # from the output so that they don't get included in the library
+           # dependencies.
+           output_verbose_link_cmd='templist=`$CC $CFLAGS -v conftest.$objext -o libconftest$shared_ext 2>&1 | $GREP "ld"`; rm -f libconftest$shared_ext; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"'
+
+           _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
+           _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
+
+           # Archives containing C++ object files must be created using
+           # "CC -Bstatic", where "CC" is the KAI C++ compiler.
+           _LT_TAGVAR(old_archive_cmds, $1)='$CC -Bstatic -o $oldlib $oldobjs'
+           ;;
+         icpc* | ecpc* )
+           # Intel C++
+           with_gnu_ld=yes
+           # version 8.0 and above of icpc choke on multiply defined symbols
+           # if we add $predep_objects and $postdep_objects, however 7.1 and
+           # earlier do not add the objects themselves.
+           case `$CC -V 2>&1` in
+             *"Version 7."*)
+               _LT_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib'
+               _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+               ;;
+             *)  # Version 8.0 or newer
+               tmp_idyn=
+               case $host_cpu in
+                 ia64*) tmp_idyn=' -i_dynamic';;
+               esac
+               _LT_TAGVAR(archive_cmds, $1)='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+               _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+               ;;
+           esac
+           _LT_TAGVAR(archive_cmds_need_lc, $1)=no
+           _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
+           _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
+           _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive$convenience ${wl}--no-whole-archive'
+           ;;
+          pgCC* | pgcpp*)
+            # Portland Group C++ compiler
+           case `$CC -V` in
+           *pgCC\ [[1-5]].* | *pgcpp\ [[1-5]].*)
+             _LT_TAGVAR(prelink_cmds, $1)='tpldir=Template.dir~
+               rm -rf $tpldir~
+               $CC --prelink_objects --instantiation_dir $tpldir $objs $libobjs $compile_deplibs~
+               compile_command="$compile_command `find $tpldir -name \*.o | sort | $NL2SP`"'
+             _LT_TAGVAR(old_archive_cmds, $1)='tpldir=Template.dir~
+               rm -rf $tpldir~
+               $CC --prelink_objects --instantiation_dir $tpldir $oldobjs$old_deplibs~
+               $AR $AR_FLAGS $oldlib$oldobjs$old_deplibs `find $tpldir -name \*.o | sort | $NL2SP`~
+               $RANLIB $oldlib'
+             _LT_TAGVAR(archive_cmds, $1)='tpldir=Template.dir~
+               rm -rf $tpldir~
+               $CC --prelink_objects --instantiation_dir $tpldir $predep_objects $libobjs $deplibs $convenience $postdep_objects~
+               $CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | sort | $NL2SP` $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname -o $lib'
+             _LT_TAGVAR(archive_expsym_cmds, $1)='tpldir=Template.dir~
+               rm -rf $tpldir~
+               $CC --prelink_objects --instantiation_dir $tpldir $predep_objects $libobjs $deplibs $convenience $postdep_objects~
+               $CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | sort | $NL2SP` $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname ${wl}-retain-symbols-file ${wl}$export_symbols -o $lib'
+             ;;
+           *) # Version 6 and above use weak symbols
+             _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname -o $lib'
+             _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname ${wl}-retain-symbols-file ${wl}$export_symbols -o $lib'
+             ;;
+           esac
+
+           _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}--rpath ${wl}$libdir'
+           _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
+           _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`for conv in $convenience\"\"; do test  -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` ${wl}--no-whole-archive'
+            ;;
+         cxx*)
+           # Compaq C++
+           _LT_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib'
+           _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname  -o $lib ${wl}-retain-symbols-file $wl$export_symbols'
+
+           runpath_var=LD_RUN_PATH
+           _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir'
+           _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+
+           # Commands to make compiler produce verbose output that lists
+           # what "hidden" libraries, object files and flags are used when
+           # linking a shared library.
+           #
+           # There doesn't appear to be a way to prevent this compiler from
+           # explicitly linking system object files so we need to strip them
+           # from the output so that they don't get included in the library
+           # dependencies.
+           output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "ld"`; templist=`func_echo_all "$templist" | $SED "s/\(^.*ld.*\)\( .*ld .*$\)/\1/"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "X$list" | $Xsed'
+           ;;
+         xl* | mpixl* | bgxl*)
+           # IBM XL 8.0 on PPC, with GNU ld
+           _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+           _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
+           _LT_TAGVAR(archive_cmds, $1)='$CC -qmkshrobj $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+           if test "x$supports_anon_versioning" = xyes; then
+             _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~
+               cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~
+               echo "local: *; };" >> $output_objdir/$libname.ver~
+               $CC -qmkshrobj $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-version-script ${wl}$output_objdir/$libname.ver -o $lib'
+           fi
+           ;;
+         *)
+           case `$CC -V 2>&1 | sed 5q` in
+           *Sun\ C*)
+             # Sun C++ 5.9
+             _LT_TAGVAR(no_undefined_flag, $1)=' -zdefs'
+             _LT_TAGVAR(archive_cmds, $1)='$CC -G${allow_undefined_flag} -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+             _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G${allow_undefined_flag} -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-retain-symbols-file ${wl}$export_symbols'
+             _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
+             _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` ${wl}--no-whole-archive'
+             _LT_TAGVAR(compiler_needs_object, $1)=yes
+
+             # Not sure whether something based on
+             # $CC $CFLAGS -v conftest.$objext -o libconftest$shared_ext 2>&1
+             # would be better.
+             output_verbose_link_cmd='func_echo_all'
+
+             # Archives containing C++ object files must be created using
+             # "CC -xar", where "CC" is the Sun C++ compiler.  This is
+             # necessary to make sure instantiated templates are included
+             # in the archive.
+             _LT_TAGVAR(old_archive_cmds, $1)='$CC -xar -o $oldlib $oldobjs'
+             ;;
+           esac
+           ;;
+       esac
+       ;;
+
+      lynxos*)
+        # FIXME: insert proper C++ library support
+       _LT_TAGVAR(ld_shlibs, $1)=no
+       ;;
+
+      m88k*)
+        # FIXME: insert proper C++ library support
+        _LT_TAGVAR(ld_shlibs, $1)=no
+       ;;
+
+      mvs*)
+        case $cc_basename in
+          cxx*)
+           # FIXME: insert proper C++ library support
+           _LT_TAGVAR(ld_shlibs, $1)=no
+           ;;
+         *)
+           # FIXME: insert proper C++ library support
+           _LT_TAGVAR(ld_shlibs, $1)=no
+           ;;
+       esac
+       ;;
+
+      netbsd*)
+        if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
+         _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable  -o $lib $predep_objects $libobjs $deplibs $postdep_objects $linker_flags'
+         wlarc=
+         _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
+         _LT_TAGVAR(hardcode_direct, $1)=yes
+         _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+       fi
+       # Workaround some broken pre-1.5 toolchains
+       output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP conftest.$objext | $SED -e "s:-lgcc -lc -lgcc::"'
+       ;;
+
+      *nto* | *qnx*)
+        _LT_TAGVAR(ld_shlibs, $1)=yes
+       ;;
+
+      openbsd2*)
+        # C++ shared libraries are fairly broken
+       _LT_TAGVAR(ld_shlibs, $1)=no
+       ;;
+
+      openbsd*)
+       if test -f /usr/libexec/ld.so; then
+         _LT_TAGVAR(hardcode_direct, $1)=yes
+         _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+         _LT_TAGVAR(hardcode_direct_absolute, $1)=yes
+         _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib'
+         _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
+         if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
+           _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-retain-symbols-file,$export_symbols -o $lib'
+           _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
+           _LT_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive'
+         fi
+         output_verbose_link_cmd=func_echo_all
+       else
+         _LT_TAGVAR(ld_shlibs, $1)=no
+       fi
+       ;;
+
+      osf3* | osf4* | osf5*)
+        case $cc_basename in
+          KCC*)
+           # Kuck and Associates, Inc. (KAI) C++ Compiler
+
+           # KCC will only create a shared library if the output file
+           # ends with ".so" (or ".sl" for HP-UX), so rename the library
+           # to its proper name (with version) after linking.
+           _LT_TAGVAR(archive_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo "$lib" | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib'
+
+           _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
+           _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+
+           # Archives containing C++ object files must be created using
+           # the KAI C++ compiler.
+           case $host in
+             osf3*) _LT_TAGVAR(old_archive_cmds, $1)='$CC -Bstatic -o $oldlib $oldobjs' ;;
+             *) _LT_TAGVAR(old_archive_cmds, $1)='$CC -o $oldlib $oldobjs' ;;
+           esac
+           ;;
+          RCC*)
+           # Rational C++ 2.4.1
+           # FIXME: insert proper C++ library support
+           _LT_TAGVAR(ld_shlibs, $1)=no
+           ;;
+          cxx*)
+           case $host in
+             osf3*)
+               _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*'
+               _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $soname `test -n "$verstring" && func_echo_all "${wl}-set_version $verstring"` -update_registry ${output_objdir}/so_locations -o $lib'
+               _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+               ;;
+             *)
+               _LT_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*'
+               _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry ${output_objdir}/so_locations -o $lib'
+               _LT_TAGVAR(archive_expsym_cmds, $1)='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done~
+                 echo "-hidden">> $lib.exp~
+                 $CC -shared$allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname ${wl}-input ${wl}$lib.exp  `test -n "$verstring" && $ECHO "-set_version $verstring"` -update_registry ${output_objdir}/so_locations -o $lib~
+                 $RM $lib.exp'
+               _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir'
+               ;;
+           esac
+
+           _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+
+           # Commands to make compiler produce verbose output that lists
+           # what "hidden" libraries, object files and flags are used when
+           # linking a shared library.
+           #
+           # There doesn't appear to be a way to prevent this compiler from
+           # explicitly linking system object files so we need to strip them
+           # from the output so that they don't get included in the library
+           # dependencies.
+           output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "ld" | $GREP -v "ld:"`; templist=`func_echo_all "$templist" | $SED "s/\(^.*ld.*\)\( .*ld.*$\)/\1/"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"'
+           ;;
+         *)
+           if test "$GXX" = yes && test "$with_gnu_ld" = no; then
+             _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*'
+             case $host in
+               osf3*)
+                 _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib ${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && func_echo_all "${wl}-set_version ${wl}$verstring"` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+                 ;;
+               *)
+                 _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -nostdlib ${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && func_echo_all "${wl}-set_version ${wl}$verstring"` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+                 ;;
+             esac
+
+             _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
+             _LT_TAGVAR(hardcode_libdir_separator, $1)=:
+
+             # Commands to make compiler produce verbose output that lists
+             # what "hidden" libraries, object files and flags are used when
+             # linking a shared library.
+             output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"'
+
+           else
+             # FIXME: insert proper C++ library support
+             _LT_TAGVAR(ld_shlibs, $1)=no
+           fi
+           ;;
+        esac
+        ;;
+
+      psos*)
+        # FIXME: insert proper C++ library support
+        _LT_TAGVAR(ld_shlibs, $1)=no
+        ;;
+
+      sunos4*)
+        case $cc_basename in
+          CC*)
+           # Sun C++ 4.x
+           # FIXME: insert proper C++ library support
+           _LT_TAGVAR(ld_shlibs, $1)=no
+           ;;
+          lcc*)
+           # Lucid
+           # FIXME: insert proper C++ library support
+           _LT_TAGVAR(ld_shlibs, $1)=no
+           ;;
+          *)
+           # FIXME: insert proper C++ library support
+           _LT_TAGVAR(ld_shlibs, $1)=no
+           ;;
+        esac
+        ;;
+
+      solaris*)
+        case $cc_basename in
+          CC* | sunCC*)
+           # Sun C++ 4.2, 5.x and Centerline C++
+            _LT_TAGVAR(archive_cmds_need_lc,$1)=yes
+           _LT_TAGVAR(no_undefined_flag, $1)=' -zdefs'
+           _LT_TAGVAR(archive_cmds, $1)='$CC -G${allow_undefined_flag}  -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
+           _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
+             $CC -G${allow_undefined_flag} ${wl}-M ${wl}$lib.exp -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp'
+
+           _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
+           _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+           case $host_os in
+             solaris2.[[0-5]] | solaris2.[[0-5]].*) ;;
+             *)
+               # The compiler driver will combine and reorder linker options,
+               # but understands `-z linker_flag'.
+               # Supported since Solaris 2.6 (maybe 2.5.1?)
+               _LT_TAGVAR(whole_archive_flag_spec, $1)='-z allextract$convenience -z defaultextract'
+               ;;
+           esac
+           _LT_TAGVAR(link_all_deplibs, $1)=yes
+
+           output_verbose_link_cmd='func_echo_all'
+
+           # Archives containing C++ object files must be created using
+           # "CC -xar", where "CC" is the Sun C++ compiler.  This is
+           # necessary to make sure instantiated templates are included
+           # in the archive.
+           _LT_TAGVAR(old_archive_cmds, $1)='$CC -xar -o $oldlib $oldobjs'
+           ;;
+          gcx*)
+           # Green Hills C++ Compiler
+           _LT_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib'
+
+           # The C++ compiler must be used to create the archive.
+           _LT_TAGVAR(old_archive_cmds, $1)='$CC $LDFLAGS -archive -o $oldlib $oldobjs'
+           ;;
+          *)
+           # GNU C++ compiler with Solaris linker
+           if test "$GXX" = yes && test "$with_gnu_ld" = no; then
+             _LT_TAGVAR(no_undefined_flag, $1)=' ${wl}-z ${wl}defs'
+             if $CC --version | $GREP -v '^2\.7' > /dev/null; then
+               _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -nostdlib $LDFLAGS $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib'
+               _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
+                 $CC -shared $pic_flag -nostdlib ${wl}-M $wl$lib.exp -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp'
+
+               # Commands to make compiler produce verbose output that lists
+               # what "hidden" libraries, object files and flags are used when
+               # linking a shared library.
+               output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"'
+             else
+               # g++ 2.7 appears to require `-G' NOT `-shared' on this
+               # platform.
+               _LT_TAGVAR(archive_cmds, $1)='$CC -G -nostdlib $LDFLAGS $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib'
+               _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
+                 $CC -G -nostdlib ${wl}-M $wl$lib.exp -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp'
+
+               # Commands to make compiler produce verbose output that lists
+               # what "hidden" libraries, object files and flags are used when
+               # linking a shared library.
+               output_verbose_link_cmd='$CC -G $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"'
+             fi
+
+             _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $wl$libdir'
+             case $host_os in
+               solaris2.[[0-5]] | solaris2.[[0-5]].*) ;;
+               *)
+                 _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}-z ${wl}allextract$convenience ${wl}-z ${wl}defaultextract'
+                 ;;
+             esac
+           fi
+           ;;
+        esac
+        ;;
+
+    sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[[01]].[[10]]* | unixware7* | sco3.2v5.0.[[024]]*)
+      _LT_TAGVAR(no_undefined_flag, $1)='${wl}-z,text'
+      _LT_TAGVAR(archive_cmds_need_lc, $1)=no
+      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+      runpath_var='LD_RUN_PATH'
+
+      case $cc_basename in
+        CC*)
+         _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+         _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+         ;;
+       *)
+         _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+         _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+         ;;
+      esac
+      ;;
+
+      sysv5* | sco3.2v5* | sco5v6*)
+       # Note: We can NOT use -z defs as we might desire, because we do not
+       # link with -lc, and that would cause any symbols used from libc to
+       # always be unresolved, which means just about no library would
+       # ever link correctly.  If we're not using GNU ld we use -z text
+       # though, which does catch some bad symbols but isn't as heavy-handed
+       # as -z defs.
+       _LT_TAGVAR(no_undefined_flag, $1)='${wl}-z,text'
+       _LT_TAGVAR(allow_undefined_flag, $1)='${wl}-z,nodefs'
+       _LT_TAGVAR(archive_cmds_need_lc, $1)=no
+       _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
+       _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R,$libdir'
+       _LT_TAGVAR(hardcode_libdir_separator, $1)=':'
+       _LT_TAGVAR(link_all_deplibs, $1)=yes
+       _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-Bexport'
+       runpath_var='LD_RUN_PATH'
+
+       case $cc_basename in
+          CC*)
+           _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+           _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+           _LT_TAGVAR(old_archive_cmds, $1)='$CC -Tprelink_objects $oldobjs~
+             '"$_LT_TAGVAR(old_archive_cmds, $1)"
+           _LT_TAGVAR(reload_cmds, $1)='$CC -Tprelink_objects $reload_objs~
+             '"$_LT_TAGVAR(reload_cmds, $1)"
+           ;;
+         *)
+           _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+           _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+           ;;
+       esac
+      ;;
+
+      tandem*)
+        case $cc_basename in
+          NCC*)
+           # NonStop-UX NCC 3.20
+           # FIXME: insert proper C++ library support
+           _LT_TAGVAR(ld_shlibs, $1)=no
+           ;;
+          *)
+           # FIXME: insert proper C++ library support
+           _LT_TAGVAR(ld_shlibs, $1)=no
+           ;;
+        esac
+        ;;
+
+      vxworks*)
+        # FIXME: insert proper C++ library support
+        _LT_TAGVAR(ld_shlibs, $1)=no
+        ;;
+
+      *)
+        # FIXME: insert proper C++ library support
+        _LT_TAGVAR(ld_shlibs, $1)=no
+        ;;
+    esac
+
+    AC_MSG_RESULT([$_LT_TAGVAR(ld_shlibs, $1)])
+    test "$_LT_TAGVAR(ld_shlibs, $1)" = no && can_build_shared=no
+
+    _LT_TAGVAR(GCC, $1)="$GXX"
+    _LT_TAGVAR(LD, $1)="$LD"
+
+    ## CAVEAT EMPTOR:
+    ## There is no encapsulation within the following macros, do not change
+    ## the running order or otherwise move them around unless you know exactly
+    ## what you are doing...
+    _LT_SYS_HIDDEN_LIBDEPS($1)
+    _LT_COMPILER_PIC($1)
+    _LT_COMPILER_C_O($1)
+    _LT_COMPILER_FILE_LOCKS($1)
+    _LT_LINKER_SHLIBS($1)
+    _LT_SYS_DYNAMIC_LINKER($1)
+    _LT_LINKER_HARDCODE_LIBPATH($1)
+
+    _LT_CONFIG($1)
+  fi # test -n "$compiler"
+
+  CC=$lt_save_CC
+  CFLAGS=$lt_save_CFLAGS
+  LDCXX=$LD
+  LD=$lt_save_LD
+  GCC=$lt_save_GCC
+  with_gnu_ld=$lt_save_with_gnu_ld
+  lt_cv_path_LDCXX=$lt_cv_path_LD
+  lt_cv_path_LD=$lt_save_path_LD
+  lt_cv_prog_gnu_ldcxx=$lt_cv_prog_gnu_ld
+  lt_cv_prog_gnu_ld=$lt_save_with_gnu_ld
+fi # test "$_lt_caught_CXX_error" != yes
+
+AC_LANG_POP
+])# _LT_LANG_CXX_CONFIG
+
+
+# _LT_FUNC_STRIPNAME_CNF
+# ----------------------
+# func_stripname_cnf prefix suffix name
+# strip PREFIX and SUFFIX off of NAME.
+# PREFIX and SUFFIX must not contain globbing or regex special
+# characters, hashes, percent signs, but SUFFIX may contain a leading
+# dot (in which case that matches only a dot).
+#
+# This function is identical to the (non-XSI) version of func_stripname,
+# except this one can be used by m4 code that may be executed by configure,
+# rather than the libtool script.
+m4_defun([_LT_FUNC_STRIPNAME_CNF],[dnl
+AC_REQUIRE([_LT_DECL_SED])
+AC_REQUIRE([_LT_PROG_ECHO_BACKSLASH])
+func_stripname_cnf ()
+{
+  case ${2} in
+  .*) func_stripname_result=`$ECHO "${3}" | $SED "s%^${1}%%; s%\\\\${2}\$%%"`;;
+  *)  func_stripname_result=`$ECHO "${3}" | $SED "s%^${1}%%; s%${2}\$%%"`;;
+  esac
+} # func_stripname_cnf
+])# _LT_FUNC_STRIPNAME_CNF
+
+# _LT_SYS_HIDDEN_LIBDEPS([TAGNAME])
+# ---------------------------------
+# Figure out "hidden" library dependencies from verbose
+# compiler output when linking a shared library.
+# Parse the compiler output and extract the necessary
+# objects, libraries and library flags.
+m4_defun([_LT_SYS_HIDDEN_LIBDEPS],
+[m4_require([_LT_FILEUTILS_DEFAULTS])dnl
+AC_REQUIRE([_LT_FUNC_STRIPNAME_CNF])dnl
+# Dependencies to place before and after the object being linked:
+_LT_TAGVAR(predep_objects, $1)=
+_LT_TAGVAR(postdep_objects, $1)=
+_LT_TAGVAR(predeps, $1)=
+_LT_TAGVAR(postdeps, $1)=
+_LT_TAGVAR(compiler_lib_search_path, $1)=
+
+dnl we can't use the lt_simple_compile_test_code here,
+dnl because it contains code intended for an executable,
+dnl not a library.  It's possible we should let each
+dnl tag define a new lt_????_link_test_code variable,
+dnl but it's only used here...
+m4_if([$1], [], [cat > conftest.$ac_ext <<_LT_EOF
+int a;
+void foo (void) { a = 0; }
+_LT_EOF
+], [$1], [CXX], [cat > conftest.$ac_ext <<_LT_EOF
+class Foo
+{
+public:
+  Foo (void) { a = 0; }
+private:
+  int a;
+};
+_LT_EOF
+], [$1], [F77], [cat > conftest.$ac_ext <<_LT_EOF
+      subroutine foo
+      implicit none
+      integer*4 a
+      a=0
+      return
+      end
+_LT_EOF
+], [$1], [FC], [cat > conftest.$ac_ext <<_LT_EOF
+      subroutine foo
+      implicit none
+      integer a
+      a=0
+      return
+      end
+_LT_EOF
+], [$1], [GCJ], [cat > conftest.$ac_ext <<_LT_EOF
+public class foo {
+  private int a;
+  public void bar (void) {
+    a = 0;
+  }
+};
+_LT_EOF
+], [$1], [GO], [cat > conftest.$ac_ext <<_LT_EOF
+package foo
+func foo() {
+}
+_LT_EOF
+])
+
+_lt_libdeps_save_CFLAGS=$CFLAGS
+case "$CC $CFLAGS " in #(
+*\ -flto*\ *) CFLAGS="$CFLAGS -fno-lto" ;;
+*\ -fwhopr*\ *) CFLAGS="$CFLAGS -fno-whopr" ;;
+*\ -fuse-linker-plugin*\ *) CFLAGS="$CFLAGS -fno-use-linker-plugin" ;;
+esac
+
+dnl Parse the compiler output and extract the necessary
+dnl objects, libraries and library flags.
+if AC_TRY_EVAL(ac_compile); then
+  # Parse the compiler output and extract the necessary
+  # objects, libraries and library flags.
+
+  # Sentinel used to keep track of whether or not we are before
+  # the conftest object file.
+  pre_test_object_deps_done=no
+
+  for p in `eval "$output_verbose_link_cmd"`; do
+    case ${prev}${p} in
+
+    -L* | -R* | -l*)
+       # Some compilers place space between "-{L,R}" and the path.
+       # Remove the space.
+       if test $p = "-L" ||
+          test $p = "-R"; then
+        prev=$p
+        continue
+       fi
+
+       # Expand the sysroot to ease extracting the directories later.
+       if test -z "$prev"; then
+         case $p in
+         -L*) func_stripname_cnf '-L' '' "$p"; prev=-L; p=$func_stripname_result ;;
+         -R*) func_stripname_cnf '-R' '' "$p"; prev=-R; p=$func_stripname_result ;;
+         -l*) func_stripname_cnf '-l' '' "$p"; prev=-l; p=$func_stripname_result ;;
+         esac
+       fi
+       case $p in
+       =*) func_stripname_cnf '=' '' "$p"; p=$lt_sysroot$func_stripname_result ;;
+       esac
+       if test "$pre_test_object_deps_done" = no; then
+        case ${prev} in
+        -L | -R)
+          # Internal compiler library paths should come after those
+          # provided the user.  The postdeps already come after the
+          # user supplied libs so there is no need to process them.
+          if test -z "$_LT_TAGVAR(compiler_lib_search_path, $1)"; then
+            _LT_TAGVAR(compiler_lib_search_path, $1)="${prev}${p}"
+          else
+            _LT_TAGVAR(compiler_lib_search_path, $1)="${_LT_TAGVAR(compiler_lib_search_path, $1)} ${prev}${p}"
+          fi
+          ;;
+        # The "-l" case would never come before the object being
+        # linked, so don't bother handling this case.
+        esac
+       else
+        if test -z "$_LT_TAGVAR(postdeps, $1)"; then
+          _LT_TAGVAR(postdeps, $1)="${prev}${p}"
+        else
+          _LT_TAGVAR(postdeps, $1)="${_LT_TAGVAR(postdeps, $1)} ${prev}${p}"
+        fi
+       fi
+       prev=
+       ;;
+
+    *.lto.$objext) ;; # Ignore GCC LTO objects
+    *.$objext)
+       # This assumes that the test object file only shows up
+       # once in the compiler output.
+       if test "$p" = "conftest.$objext"; then
+        pre_test_object_deps_done=yes
+        continue
+       fi
+
+       if test "$pre_test_object_deps_done" = no; then
+        if test -z "$_LT_TAGVAR(predep_objects, $1)"; then
+          _LT_TAGVAR(predep_objects, $1)="$p"
+        else
+          _LT_TAGVAR(predep_objects, $1)="$_LT_TAGVAR(predep_objects, $1) $p"
+        fi
+       else
+        if test -z "$_LT_TAGVAR(postdep_objects, $1)"; then
+          _LT_TAGVAR(postdep_objects, $1)="$p"
+        else
+          _LT_TAGVAR(postdep_objects, $1)="$_LT_TAGVAR(postdep_objects, $1) $p"
+        fi
+       fi
+       ;;
+
+    *) ;; # Ignore the rest.
+
+    esac
+  done
+
+  # Clean up.
+  rm -f a.out a.exe
+else
+  echo "libtool.m4: error: problem compiling $1 test program"
+fi
+
+$RM -f confest.$objext
+CFLAGS=$_lt_libdeps_save_CFLAGS
+
+# PORTME: override above test on systems where it is broken
+m4_if([$1], [CXX],
+[case $host_os in
+interix[[3-9]]*)
+  # Interix 3.5 installs completely hosed .la files for C++, so rather than
+  # hack all around it, let's just trust "g++" to DTRT.
+  _LT_TAGVAR(predep_objects,$1)=
+  _LT_TAGVAR(postdep_objects,$1)=
+  _LT_TAGVAR(postdeps,$1)=
+  ;;
+
+linux*)
+  case `$CC -V 2>&1 | sed 5q` in
+  *Sun\ C*)
+    # Sun C++ 5.9
+
+    # The more standards-conforming stlport4 library is
+    # incompatible with the Cstd library. Avoid specifying
+    # it if it's in CXXFLAGS. Ignore libCrun as
+    # -library=stlport4 depends on it.
+    case " $CXX $CXXFLAGS " in
+    *" -library=stlport4 "*)
+      solaris_use_stlport4=yes
+      ;;
+    esac
+
+    if test "$solaris_use_stlport4" != yes; then
+      _LT_TAGVAR(postdeps,$1)='-library=Cstd -library=Crun'
+    fi
+    ;;
+  esac
+  ;;
+
+solaris*)
+  case $cc_basename in
+  CC* | sunCC*)
+    # The more standards-conforming stlport4 library is
+    # incompatible with the Cstd library. Avoid specifying
+    # it if it's in CXXFLAGS. Ignore libCrun as
+    # -library=stlport4 depends on it.
+    case " $CXX $CXXFLAGS " in
+    *" -library=stlport4 "*)
+      solaris_use_stlport4=yes
+      ;;
+    esac
+
+    # Adding this requires a known-good setup of shared libraries for
+    # Sun compiler versions before 5.6, else PIC objects from an old
+    # archive will be linked into the output, leading to subtle bugs.
+    if test "$solaris_use_stlport4" != yes; then
+      _LT_TAGVAR(postdeps,$1)='-library=Cstd -library=Crun'
+    fi
+    ;;
+  esac
+  ;;
+esac
+])
+
+case " $_LT_TAGVAR(postdeps, $1) " in
+*" -lc "*) _LT_TAGVAR(archive_cmds_need_lc, $1)=no ;;
+esac
+ _LT_TAGVAR(compiler_lib_search_dirs, $1)=
+if test -n "${_LT_TAGVAR(compiler_lib_search_path, $1)}"; then
+ _LT_TAGVAR(compiler_lib_search_dirs, $1)=`echo " ${_LT_TAGVAR(compiler_lib_search_path, $1)}" | ${SED} -e 's! -L! !g' -e 's!^ !!'`
+fi
+_LT_TAGDECL([], [compiler_lib_search_dirs], [1],
+    [The directories searched by this compiler when creating a shared library])
+_LT_TAGDECL([], [predep_objects], [1],
+    [Dependencies to place before and after the objects being linked to
+    create a shared library])
+_LT_TAGDECL([], [postdep_objects], [1])
+_LT_TAGDECL([], [predeps], [1])
+_LT_TAGDECL([], [postdeps], [1])
+_LT_TAGDECL([], [compiler_lib_search_path], [1],
+    [The library search path used internally by the compiler when linking
+    a shared library])
+])# _LT_SYS_HIDDEN_LIBDEPS
+
+
+# _LT_LANG_F77_CONFIG([TAG])
+# --------------------------
+# Ensure that the configuration variables for a Fortran 77 compiler are
+# suitably defined.  These variables are subsequently used by _LT_CONFIG
+# to write the compiler configuration to `libtool'.
+m4_defun([_LT_LANG_F77_CONFIG],
+[AC_LANG_PUSH(Fortran 77)
+if test -z "$F77" || test "X$F77" = "Xno"; then
+  _lt_disable_F77=yes
+fi
+
+_LT_TAGVAR(archive_cmds_need_lc, $1)=no
+_LT_TAGVAR(allow_undefined_flag, $1)=
+_LT_TAGVAR(always_export_symbols, $1)=no
+_LT_TAGVAR(archive_expsym_cmds, $1)=
+_LT_TAGVAR(export_dynamic_flag_spec, $1)=
+_LT_TAGVAR(hardcode_direct, $1)=no
+_LT_TAGVAR(hardcode_direct_absolute, $1)=no
+_LT_TAGVAR(hardcode_libdir_flag_spec, $1)=
+_LT_TAGVAR(hardcode_libdir_separator, $1)=
+_LT_TAGVAR(hardcode_minus_L, $1)=no
+_LT_TAGVAR(hardcode_automatic, $1)=no
+_LT_TAGVAR(inherit_rpath, $1)=no
+_LT_TAGVAR(module_cmds, $1)=
+_LT_TAGVAR(module_expsym_cmds, $1)=
+_LT_TAGVAR(link_all_deplibs, $1)=unknown
+_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds
+_LT_TAGVAR(reload_flag, $1)=$reload_flag
+_LT_TAGVAR(reload_cmds, $1)=$reload_cmds
+_LT_TAGVAR(no_undefined_flag, $1)=
+_LT_TAGVAR(whole_archive_flag_spec, $1)=
+_LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no
+
+# Source file extension for f77 test sources.
+ac_ext=f
+
+# Object file extension for compiled f77 test sources.
+objext=o
+_LT_TAGVAR(objext, $1)=$objext
+
+# No sense in running all these tests if we already determined that
+# the F77 compiler isn't working.  Some variables (like enable_shared)
+# are currently assumed to apply to all compilers on this platform,
+# and will be corrupted by setting them based on a non-working compiler.
+if test "$_lt_disable_F77" != yes; then
+  # Code to be used in simple compile tests
+  lt_simple_compile_test_code="\
+      subroutine t
+      return
+      end
+"
+
+  # Code to be used in simple link tests
+  lt_simple_link_test_code="\
+      program t
+      end
+"
+
+  # ltmain only uses $CC for tagged configurations so make sure $CC is set.
+  _LT_TAG_COMPILER
+
+  # save warnings/boilerplate of simple test code
+  _LT_COMPILER_BOILERPLATE
+  _LT_LINKER_BOILERPLATE
+
+  # Allow CC to be a program name with arguments.
+  lt_save_CC="$CC"
+  lt_save_GCC=$GCC
+  lt_save_CFLAGS=$CFLAGS
+  CC=${F77-"f77"}
+  CFLAGS=$FFLAGS
+  compiler=$CC
+  _LT_TAGVAR(compiler, $1)=$CC
+  _LT_CC_BASENAME([$compiler])
+  GCC=$G77
+  if test -n "$compiler"; then
+    AC_MSG_CHECKING([if libtool supports shared libraries])
+    AC_MSG_RESULT([$can_build_shared])
+
+    AC_MSG_CHECKING([whether to build shared libraries])
+    test "$can_build_shared" = "no" && enable_shared=no
+
+    # On AIX, shared libraries and static libraries use the same namespace, and
+    # are all built from PIC.
+    case $host_os in
+      aix3*)
+        test "$enable_shared" = yes && enable_static=no
+        if test -n "$RANLIB"; then
+          archive_cmds="$archive_cmds~\$RANLIB \$lib"
+          postinstall_cmds='$RANLIB $lib'
+        fi
+        ;;
+      aix[[4-9]]*)
+       if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then
+         test "$enable_shared" = yes && enable_static=no
+       fi
+        ;;
+    esac
+    AC_MSG_RESULT([$enable_shared])
+
+    AC_MSG_CHECKING([whether to build static libraries])
+    # Make sure either enable_shared or enable_static is yes.
+    test "$enable_shared" = yes || enable_static=yes
+    AC_MSG_RESULT([$enable_static])
+
+    _LT_TAGVAR(GCC, $1)="$G77"
+    _LT_TAGVAR(LD, $1)="$LD"
+
+    ## CAVEAT EMPTOR:
+    ## There is no encapsulation within the following macros, do not change
+    ## the running order or otherwise move them around unless you know exactly
+    ## what you are doing...
+    _LT_COMPILER_PIC($1)
+    _LT_COMPILER_C_O($1)
+    _LT_COMPILER_FILE_LOCKS($1)
+    _LT_LINKER_SHLIBS($1)
+    _LT_SYS_DYNAMIC_LINKER($1)
+    _LT_LINKER_HARDCODE_LIBPATH($1)
+
+    _LT_CONFIG($1)
+  fi # test -n "$compiler"
+
+  GCC=$lt_save_GCC
+  CC="$lt_save_CC"
+  CFLAGS="$lt_save_CFLAGS"
+fi # test "$_lt_disable_F77" != yes
+
+AC_LANG_POP
+])# _LT_LANG_F77_CONFIG
+
+
+# _LT_LANG_FC_CONFIG([TAG])
+# -------------------------
+# Ensure that the configuration variables for a Fortran compiler are
+# suitably defined.  These variables are subsequently used by _LT_CONFIG
+# to write the compiler configuration to `libtool'.
+m4_defun([_LT_LANG_FC_CONFIG],
+[AC_LANG_PUSH(Fortran)
+
+if test -z "$FC" || test "X$FC" = "Xno"; then
+  _lt_disable_FC=yes
+fi
+
+_LT_TAGVAR(archive_cmds_need_lc, $1)=no
+_LT_TAGVAR(allow_undefined_flag, $1)=
+_LT_TAGVAR(always_export_symbols, $1)=no
+_LT_TAGVAR(archive_expsym_cmds, $1)=
+_LT_TAGVAR(export_dynamic_flag_spec, $1)=
+_LT_TAGVAR(hardcode_direct, $1)=no
+_LT_TAGVAR(hardcode_direct_absolute, $1)=no
+_LT_TAGVAR(hardcode_libdir_flag_spec, $1)=
+_LT_TAGVAR(hardcode_libdir_separator, $1)=
+_LT_TAGVAR(hardcode_minus_L, $1)=no
+_LT_TAGVAR(hardcode_automatic, $1)=no
+_LT_TAGVAR(inherit_rpath, $1)=no
+_LT_TAGVAR(module_cmds, $1)=
+_LT_TAGVAR(module_expsym_cmds, $1)=
+_LT_TAGVAR(link_all_deplibs, $1)=unknown
+_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds
+_LT_TAGVAR(reload_flag, $1)=$reload_flag
+_LT_TAGVAR(reload_cmds, $1)=$reload_cmds
+_LT_TAGVAR(no_undefined_flag, $1)=
+_LT_TAGVAR(whole_archive_flag_spec, $1)=
+_LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no
+
+# Source file extension for fc test sources.
+ac_ext=${ac_fc_srcext-f}
+
+# Object file extension for compiled fc test sources.
+objext=o
+_LT_TAGVAR(objext, $1)=$objext
+
+# No sense in running all these tests if we already determined that
+# the FC compiler isn't working.  Some variables (like enable_shared)
+# are currently assumed to apply to all compilers on this platform,
+# and will be corrupted by setting them based on a non-working compiler.
+if test "$_lt_disable_FC" != yes; then
+  # Code to be used in simple compile tests
+  lt_simple_compile_test_code="\
+      subroutine t
+      return
+      end
+"
+
+  # Code to be used in simple link tests
+  lt_simple_link_test_code="\
+      program t
+      end
+"
+
+  # ltmain only uses $CC for tagged configurations so make sure $CC is set.
+  _LT_TAG_COMPILER
+
+  # save warnings/boilerplate of simple test code
+  _LT_COMPILER_BOILERPLATE
+  _LT_LINKER_BOILERPLATE
+
+  # Allow CC to be a program name with arguments.
+  lt_save_CC="$CC"
+  lt_save_GCC=$GCC
+  lt_save_CFLAGS=$CFLAGS
+  CC=${FC-"f95"}
+  CFLAGS=$FCFLAGS
+  compiler=$CC
+  GCC=$ac_cv_fc_compiler_gnu
+
+  _LT_TAGVAR(compiler, $1)=$CC
+  _LT_CC_BASENAME([$compiler])
+
+  if test -n "$compiler"; then
+    AC_MSG_CHECKING([if libtool supports shared libraries])
+    AC_MSG_RESULT([$can_build_shared])
+
+    AC_MSG_CHECKING([whether to build shared libraries])
+    test "$can_build_shared" = "no" && enable_shared=no
+
+    # On AIX, shared libraries and static libraries use the same namespace, and
+    # are all built from PIC.
+    case $host_os in
+      aix3*)
+        test "$enable_shared" = yes && enable_static=no
+        if test -n "$RANLIB"; then
+          archive_cmds="$archive_cmds~\$RANLIB \$lib"
+          postinstall_cmds='$RANLIB $lib'
+        fi
+        ;;
+      aix[[4-9]]*)
+       if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then
+         test "$enable_shared" = yes && enable_static=no
+       fi
+        ;;
+    esac
+    AC_MSG_RESULT([$enable_shared])
+
+    AC_MSG_CHECKING([whether to build static libraries])
+    # Make sure either enable_shared or enable_static is yes.
+    test "$enable_shared" = yes || enable_static=yes
+    AC_MSG_RESULT([$enable_static])
+
+    _LT_TAGVAR(GCC, $1)="$ac_cv_fc_compiler_gnu"
+    _LT_TAGVAR(LD, $1)="$LD"
+
+    ## CAVEAT EMPTOR:
+    ## There is no encapsulation within the following macros, do not change
+    ## the running order or otherwise move them around unless you know exactly
+    ## what you are doing...
+    _LT_SYS_HIDDEN_LIBDEPS($1)
+    _LT_COMPILER_PIC($1)
+    _LT_COMPILER_C_O($1)
+    _LT_COMPILER_FILE_LOCKS($1)
+    _LT_LINKER_SHLIBS($1)
+    _LT_SYS_DYNAMIC_LINKER($1)
+    _LT_LINKER_HARDCODE_LIBPATH($1)
+
+    _LT_CONFIG($1)
+  fi # test -n "$compiler"
+
+  GCC=$lt_save_GCC
+  CC=$lt_save_CC
+  CFLAGS=$lt_save_CFLAGS
+fi # test "$_lt_disable_FC" != yes
+
+AC_LANG_POP
+])# _LT_LANG_FC_CONFIG
+
+
+# _LT_LANG_GCJ_CONFIG([TAG])
+# --------------------------
+# Ensure that the configuration variables for the GNU Java Compiler compiler
+# are suitably defined.  These variables are subsequently used by _LT_CONFIG
+# to write the compiler configuration to `libtool'.
+m4_defun([_LT_LANG_GCJ_CONFIG],
+[AC_REQUIRE([LT_PROG_GCJ])dnl
+AC_LANG_SAVE
+
+# Source file extension for Java test sources.
+ac_ext=java
+
+# Object file extension for compiled Java test sources.
+objext=o
+_LT_TAGVAR(objext, $1)=$objext
+
+# Code to be used in simple compile tests
+lt_simple_compile_test_code="class foo {}"
+
+# Code to be used in simple link tests
+lt_simple_link_test_code='public class conftest { public static void main(String[[]] argv) {}; }'
+
+# ltmain only uses $CC for tagged configurations so make sure $CC is set.
+_LT_TAG_COMPILER
+
+# save warnings/boilerplate of simple test code
+_LT_COMPILER_BOILERPLATE
+_LT_LINKER_BOILERPLATE
+
+# Allow CC to be a program name with arguments.
+lt_save_CC=$CC
+lt_save_CFLAGS=$CFLAGS
+lt_save_GCC=$GCC
+GCC=yes
+CC=${GCJ-"gcj"}
+CFLAGS=$GCJFLAGS
+compiler=$CC
+_LT_TAGVAR(compiler, $1)=$CC
+_LT_TAGVAR(LD, $1)="$LD"
+_LT_CC_BASENAME([$compiler])
+
+# GCJ did not exist at the time GCC didn't implicitly link libc in.
+_LT_TAGVAR(archive_cmds_need_lc, $1)=no
+
+_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds
+_LT_TAGVAR(reload_flag, $1)=$reload_flag
+_LT_TAGVAR(reload_cmds, $1)=$reload_cmds
+
+if test -n "$compiler"; then
+  _LT_COMPILER_NO_RTTI($1)
+  _LT_COMPILER_PIC($1)
+  _LT_COMPILER_C_O($1)
+  _LT_COMPILER_FILE_LOCKS($1)
+  _LT_LINKER_SHLIBS($1)
+  _LT_LINKER_HARDCODE_LIBPATH($1)
+
+  _LT_CONFIG($1)
+fi
+
+AC_LANG_RESTORE
+
+GCC=$lt_save_GCC
+CC=$lt_save_CC
+CFLAGS=$lt_save_CFLAGS
+])# _LT_LANG_GCJ_CONFIG
+
+
+# _LT_LANG_GO_CONFIG([TAG])
+# --------------------------
+# Ensure that the configuration variables for the GNU Go compiler
+# are suitably defined.  These variables are subsequently used by _LT_CONFIG
+# to write the compiler configuration to `libtool'.
+m4_defun([_LT_LANG_GO_CONFIG],
+[AC_REQUIRE([LT_PROG_GO])dnl
+AC_LANG_SAVE
+
+# Source file extension for Go test sources.
+ac_ext=go
+
+# Object file extension for compiled Go test sources.
+objext=o
+_LT_TAGVAR(objext, $1)=$objext
+
+# Code to be used in simple compile tests
+lt_simple_compile_test_code="package main; func main() { }"
+
+# Code to be used in simple link tests
+lt_simple_link_test_code='package main; func main() { }'
+
+# ltmain only uses $CC for tagged configurations so make sure $CC is set.
+_LT_TAG_COMPILER
+
+# save warnings/boilerplate of simple test code
+_LT_COMPILER_BOILERPLATE
+_LT_LINKER_BOILERPLATE
+
+# Allow CC to be a program name with arguments.
+lt_save_CC=$CC
+lt_save_CFLAGS=$CFLAGS
+lt_save_GCC=$GCC
+GCC=yes
+CC=${GOC-"gccgo"}
+CFLAGS=$GOFLAGS
+compiler=$CC
+_LT_TAGVAR(compiler, $1)=$CC
+_LT_TAGVAR(LD, $1)="$LD"
+_LT_CC_BASENAME([$compiler])
+
+# Go did not exist at the time GCC didn't implicitly link libc in.
+_LT_TAGVAR(archive_cmds_need_lc, $1)=no
+
+_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds
+_LT_TAGVAR(reload_flag, $1)=$reload_flag
+_LT_TAGVAR(reload_cmds, $1)=$reload_cmds
+
+if test -n "$compiler"; then
+  _LT_COMPILER_NO_RTTI($1)
+  _LT_COMPILER_PIC($1)
+  _LT_COMPILER_C_O($1)
+  _LT_COMPILER_FILE_LOCKS($1)
+  _LT_LINKER_SHLIBS($1)
+  _LT_LINKER_HARDCODE_LIBPATH($1)
+
+  _LT_CONFIG($1)
+fi
+
+AC_LANG_RESTORE
+
+GCC=$lt_save_GCC
+CC=$lt_save_CC
+CFLAGS=$lt_save_CFLAGS
+])# _LT_LANG_GO_CONFIG
+
+
+# _LT_LANG_RC_CONFIG([TAG])
+# -------------------------
+# Ensure that the configuration variables for the Windows resource compiler
+# are suitably defined.  These variables are subsequently used by _LT_CONFIG
+# to write the compiler configuration to `libtool'.
+m4_defun([_LT_LANG_RC_CONFIG],
+[AC_REQUIRE([LT_PROG_RC])dnl
+AC_LANG_SAVE
+
+# Source file extension for RC test sources.
+ac_ext=rc
+
+# Object file extension for compiled RC test sources.
+objext=o
+_LT_TAGVAR(objext, $1)=$objext
+
+# Code to be used in simple compile tests
+lt_simple_compile_test_code='sample MENU { MENUITEM "&Soup", 100, CHECKED }'
+
+# Code to be used in simple link tests
+lt_simple_link_test_code="$lt_simple_compile_test_code"
+
+# ltmain only uses $CC for tagged configurations so make sure $CC is set.
+_LT_TAG_COMPILER
+
+# save warnings/boilerplate of simple test code
+_LT_COMPILER_BOILERPLATE
+_LT_LINKER_BOILERPLATE
+
+# Allow CC to be a program name with arguments.
+lt_save_CC="$CC"
+lt_save_CFLAGS=$CFLAGS
+lt_save_GCC=$GCC
+GCC=
+CC=${RC-"windres"}
+CFLAGS=
+compiler=$CC
+_LT_TAGVAR(compiler, $1)=$CC
+_LT_CC_BASENAME([$compiler])
+_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)=yes
+
+if test -n "$compiler"; then
+  :
+  _LT_CONFIG($1)
+fi
+
+GCC=$lt_save_GCC
+AC_LANG_RESTORE
+CC=$lt_save_CC
+CFLAGS=$lt_save_CFLAGS
+])# _LT_LANG_RC_CONFIG
+
+
+# LT_PROG_GCJ
+# -----------
+AC_DEFUN([LT_PROG_GCJ],
+[m4_ifdef([AC_PROG_GCJ], [AC_PROG_GCJ],
+  [m4_ifdef([A][M_PROG_GCJ], [A][M_PROG_GCJ],
+    [AC_CHECK_TOOL(GCJ, gcj,)
+      test "x${GCJFLAGS+set}" = xset || GCJFLAGS="-g -O2"
+      AC_SUBST(GCJFLAGS)])])[]dnl
+])
+
+# Old name:
+AU_ALIAS([LT_AC_PROG_GCJ], [LT_PROG_GCJ])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([LT_AC_PROG_GCJ], [])
+
+
+# LT_PROG_GO
+# ----------
+AC_DEFUN([LT_PROG_GO],
+[AC_CHECK_TOOL(GOC, gccgo,)
+])
+
+
+# LT_PROG_RC
+# ----------
+AC_DEFUN([LT_PROG_RC],
+[AC_CHECK_TOOL(RC, windres,)
+])
+
+# Old name:
+AU_ALIAS([LT_AC_PROG_RC], [LT_PROG_RC])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([LT_AC_PROG_RC], [])
+
+
+# _LT_DECL_EGREP
+# --------------
+# If we don't have a new enough Autoconf to choose the best grep
+# available, choose the one first in the user's PATH.
+m4_defun([_LT_DECL_EGREP],
+[AC_REQUIRE([AC_PROG_EGREP])dnl
+AC_REQUIRE([AC_PROG_FGREP])dnl
+test -z "$GREP" && GREP=grep
+_LT_DECL([], [GREP], [1], [A grep program that handles long lines])
+_LT_DECL([], [EGREP], [1], [An ERE matcher])
+_LT_DECL([], [FGREP], [1], [A literal string matcher])
+dnl Non-bleeding-edge autoconf doesn't subst GREP, so do it here too
+AC_SUBST([GREP])
+])
+
+
+# _LT_DECL_OBJDUMP
+# --------------
+# If we don't have a new enough Autoconf to choose the best objdump
+# available, choose the one first in the user's PATH.
+m4_defun([_LT_DECL_OBJDUMP],
+[AC_CHECK_TOOL(OBJDUMP, objdump, false)
+test -z "$OBJDUMP" && OBJDUMP=objdump
+_LT_DECL([], [OBJDUMP], [1], [An object symbol dumper])
+AC_SUBST([OBJDUMP])
+])
+
+# _LT_DECL_DLLTOOL
+# ----------------
+# Ensure DLLTOOL variable is set.
+m4_defun([_LT_DECL_DLLTOOL],
+[AC_CHECK_TOOL(DLLTOOL, dlltool, false)
+test -z "$DLLTOOL" && DLLTOOL=dlltool
+_LT_DECL([], [DLLTOOL], [1], [DLL creation program])
+AC_SUBST([DLLTOOL])
+])
+
+# _LT_DECL_SED
+# ------------
+# Check for a fully-functional sed program, that truncates
+# as few characters as possible.  Prefer GNU sed if found.
+m4_defun([_LT_DECL_SED],
+[AC_PROG_SED
+test -z "$SED" && SED=sed
+Xsed="$SED -e 1s/^X//"
+_LT_DECL([], [SED], [1], [A sed program that does not truncate output])
+_LT_DECL([], [Xsed], ["\$SED -e 1s/^X//"],
+    [Sed that helps us avoid accidentally triggering echo(1) options like -n])
+])# _LT_DECL_SED
+
+m4_ifndef([AC_PROG_SED], [
+# NOTE: This macro has been submitted for inclusion into   #
+#  GNU Autoconf as AC_PROG_SED.  When it is available in   #
+#  a released version of Autoconf we should remove this    #
+#  macro and use it instead.                               #
+
+m4_defun([AC_PROG_SED],
+[AC_MSG_CHECKING([for a sed that does not truncate output])
+AC_CACHE_VAL(lt_cv_path_SED,
+[# Loop through the user's path and test for sed and gsed.
+# Then use that list of sed's as ones to test for truncation.
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  for lt_ac_prog in sed gsed; do
+    for ac_exec_ext in '' $ac_executable_extensions; do
+      if $as_executable_p "$as_dir/$lt_ac_prog$ac_exec_ext"; then
+        lt_ac_sed_list="$lt_ac_sed_list $as_dir/$lt_ac_prog$ac_exec_ext"
+      fi
+    done
+  done
+done
+IFS=$as_save_IFS
+lt_ac_max=0
+lt_ac_count=0
+# Add /usr/xpg4/bin/sed as it is typically found on Solaris
+# along with /bin/sed that truncates output.
+for lt_ac_sed in $lt_ac_sed_list /usr/xpg4/bin/sed; do
+  test ! -f $lt_ac_sed && continue
+  cat /dev/null > conftest.in
+  lt_ac_count=0
+  echo $ECHO_N "0123456789$ECHO_C" >conftest.in
+  # Check for GNU sed and select it if it is found.
+  if "$lt_ac_sed" --version 2>&1 < /dev/null | grep 'GNU' > /dev/null; then
+    lt_cv_path_SED=$lt_ac_sed
+    break
+  fi
+  while true; do
+    cat conftest.in conftest.in >conftest.tmp
+    mv conftest.tmp conftest.in
+    cp conftest.in conftest.nl
+    echo >>conftest.nl
+    $lt_ac_sed -e 's/a$//' < conftest.nl >conftest.out || break
+    cmp -s conftest.out conftest.nl || break
+    # 10000 chars as input seems more than enough
+    test $lt_ac_count -gt 10 && break
+    lt_ac_count=`expr $lt_ac_count + 1`
+    if test $lt_ac_count -gt $lt_ac_max; then
+      lt_ac_max=$lt_ac_count
+      lt_cv_path_SED=$lt_ac_sed
+    fi
+  done
+done
+])
+SED=$lt_cv_path_SED
+AC_SUBST([SED])
+AC_MSG_RESULT([$SED])
+])#AC_PROG_SED
+])#m4_ifndef
+
+# Old name:
+AU_ALIAS([LT_AC_PROG_SED], [AC_PROG_SED])
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([LT_AC_PROG_SED], [])
+
+
+# _LT_CHECK_SHELL_FEATURES
+# ------------------------
+# Find out whether the shell is Bourne or XSI compatible,
+# or has some other useful features.
+m4_defun([_LT_CHECK_SHELL_FEATURES],
+[AC_MSG_CHECKING([whether the shell understands some XSI constructs])
+# Try some XSI features
+xsi_shell=no
+( _lt_dummy="a/b/c"
+  test "${_lt_dummy##*/},${_lt_dummy%/*},${_lt_dummy#??}"${_lt_dummy%"$_lt_dummy"}, \
+      = c,a/b,b/c, \
+    && eval 'test $(( 1 + 1 )) -eq 2 \
+    && test "${#_lt_dummy}" -eq 5' ) >/dev/null 2>&1 \
+  && xsi_shell=yes
+AC_MSG_RESULT([$xsi_shell])
+_LT_CONFIG_LIBTOOL_INIT([xsi_shell='$xsi_shell'])
+
+AC_MSG_CHECKING([whether the shell understands "+="])
+lt_shell_append=no
+( foo=bar; set foo baz; eval "$[1]+=\$[2]" && test "$foo" = barbaz ) \
+    >/dev/null 2>&1 \
+  && lt_shell_append=yes
+AC_MSG_RESULT([$lt_shell_append])
+_LT_CONFIG_LIBTOOL_INIT([lt_shell_append='$lt_shell_append'])
+
+if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then
+  lt_unset=unset
+else
+  lt_unset=false
+fi
+_LT_DECL([], [lt_unset], [0], [whether the shell understands "unset"])dnl
+
+# test EBCDIC or ASCII
+case `echo X|tr X '\101'` in
+ A) # ASCII based system
+    # \n is not interpreted correctly by Solaris 8 /usr/ucb/tr
+  lt_SP2NL='tr \040 \012'
+  lt_NL2SP='tr \015\012 \040\040'
+  ;;
+ *) # EBCDIC based system
+  lt_SP2NL='tr \100 \n'
+  lt_NL2SP='tr \r\n \100\100'
+  ;;
+esac
+_LT_DECL([SP2NL], [lt_SP2NL], [1], [turn spaces into newlines])dnl
+_LT_DECL([NL2SP], [lt_NL2SP], [1], [turn newlines into spaces])dnl
+])# _LT_CHECK_SHELL_FEATURES
+
+
+# _LT_PROG_FUNCTION_REPLACE (FUNCNAME, REPLACEMENT-BODY)
+# ------------------------------------------------------
+# In `$cfgfile', look for function FUNCNAME delimited by `^FUNCNAME ()$' and
+# '^} FUNCNAME ', and replace its body with REPLACEMENT-BODY.
+m4_defun([_LT_PROG_FUNCTION_REPLACE],
+[dnl {
+sed -e '/^$1 ()$/,/^} # $1 /c\
+$1 ()\
+{\
+m4_bpatsubsts([$2], [$], [\\], [^\([    ]\)], [\\\1])
+} # Extended-shell $1 implementation' "$cfgfile" > $cfgfile.tmp \
+  && mv -f "$cfgfile.tmp" "$cfgfile" \
+    || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp")
+test 0 -eq $? || _lt_function_replace_fail=:
+])
+
+
+# _LT_PROG_REPLACE_SHELLFNS
+# -------------------------
+# Replace existing portable implementations of several shell functions with
+# equivalent extended shell implementations where those features are available..
+m4_defun([_LT_PROG_REPLACE_SHELLFNS],
+[if test x"$xsi_shell" = xyes; then
+  _LT_PROG_FUNCTION_REPLACE([func_dirname], [dnl
+    case ${1} in
+      */*) func_dirname_result="${1%/*}${2}" ;;
+      *  ) func_dirname_result="${3}" ;;
+    esac])
+
+  _LT_PROG_FUNCTION_REPLACE([func_basename], [dnl
+    func_basename_result="${1##*/}"])
+
+  _LT_PROG_FUNCTION_REPLACE([func_dirname_and_basename], [dnl
+    case ${1} in
+      */*) func_dirname_result="${1%/*}${2}" ;;
+      *  ) func_dirname_result="${3}" ;;
+    esac
+    func_basename_result="${1##*/}"])
+
+  _LT_PROG_FUNCTION_REPLACE([func_stripname], [dnl
+    # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are
+    # positional parameters, so assign one to ordinary parameter first.
+    func_stripname_result=${3}
+    func_stripname_result=${func_stripname_result#"${1}"}
+    func_stripname_result=${func_stripname_result%"${2}"}])
+
+  _LT_PROG_FUNCTION_REPLACE([func_split_long_opt], [dnl
+    func_split_long_opt_name=${1%%=*}
+    func_split_long_opt_arg=${1#*=}])
+
+  _LT_PROG_FUNCTION_REPLACE([func_split_short_opt], [dnl
+    func_split_short_opt_arg=${1#??}
+    func_split_short_opt_name=${1%"$func_split_short_opt_arg"}])
+
+  _LT_PROG_FUNCTION_REPLACE([func_lo2o], [dnl
+    case ${1} in
+      *.lo) func_lo2o_result=${1%.lo}.${objext} ;;
+      *)    func_lo2o_result=${1} ;;
+    esac])
+
+  _LT_PROG_FUNCTION_REPLACE([func_xform], [    func_xform_result=${1%.*}.lo])
+
+  _LT_PROG_FUNCTION_REPLACE([func_arith], [    func_arith_result=$(( $[*] ))])
+
+  _LT_PROG_FUNCTION_REPLACE([func_len], [    func_len_result=${#1}])
+fi
+
+if test x"$lt_shell_append" = xyes; then
+  _LT_PROG_FUNCTION_REPLACE([func_append], [    eval "${1}+=\\${2}"])
+
+  _LT_PROG_FUNCTION_REPLACE([func_append_quoted], [dnl
+    func_quote_for_eval "${2}"
+dnl m4 expansion turns \\\\ into \\, and then the shell eval turns that into \
+    eval "${1}+=\\\\ \\$func_quote_for_eval_result"])
+
+  # Save a `func_append' function call where possible by direct use of '+='
+  sed -e 's%func_append \([[a-zA-Z_]]\{1,\}\) "%\1+="%g' $cfgfile > $cfgfile.tmp \
+    && mv -f "$cfgfile.tmp" "$cfgfile" \
+      || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp")
+  test 0 -eq $? || _lt_function_replace_fail=:
+else
+  # Save a `func_append' function call even when '+=' is not available
+  sed -e 's%func_append \([[a-zA-Z_]]\{1,\}\) "%\1="$\1%g' $cfgfile > $cfgfile.tmp \
+    && mv -f "$cfgfile.tmp" "$cfgfile" \
+      || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp")
+  test 0 -eq $? || _lt_function_replace_fail=:
+fi
+
+if test x"$_lt_function_replace_fail" = x":"; then
+  AC_MSG_WARN([Unable to substitute extended shell functions in $ofile])
+fi
+])
+
+# _LT_PATH_CONVERSION_FUNCTIONS
+# -----------------------------
+# Determine which file name conversion functions should be used by
+# func_to_host_file (and, implicitly, by func_to_host_path).  These are needed
+# for certain cross-compile configurations and native mingw.
+m4_defun([_LT_PATH_CONVERSION_FUNCTIONS],
+[AC_REQUIRE([AC_CANONICAL_HOST])dnl
+AC_REQUIRE([AC_CANONICAL_BUILD])dnl
+AC_MSG_CHECKING([how to convert $build file names to $host format])
+AC_CACHE_VAL(lt_cv_to_host_file_cmd,
+[case $host in
+  *-*-mingw* )
+    case $build in
+      *-*-mingw* ) # actually msys
+        lt_cv_to_host_file_cmd=func_convert_file_msys_to_w32
+        ;;
+      *-*-cygwin* )
+        lt_cv_to_host_file_cmd=func_convert_file_cygwin_to_w32
+        ;;
+      * ) # otherwise, assume *nix
+        lt_cv_to_host_file_cmd=func_convert_file_nix_to_w32
+        ;;
+    esac
+    ;;
+  *-*-cygwin* )
+    case $build in
+      *-*-mingw* ) # actually msys
+        lt_cv_to_host_file_cmd=func_convert_file_msys_to_cygwin
+        ;;
+      *-*-cygwin* )
+        lt_cv_to_host_file_cmd=func_convert_file_noop
+        ;;
+      * ) # otherwise, assume *nix
+        lt_cv_to_host_file_cmd=func_convert_file_nix_to_cygwin
+        ;;
+    esac
+    ;;
+  * ) # unhandled hosts (and "normal" native builds)
+    lt_cv_to_host_file_cmd=func_convert_file_noop
+    ;;
+esac
+])
+to_host_file_cmd=$lt_cv_to_host_file_cmd
+AC_MSG_RESULT([$lt_cv_to_host_file_cmd])
+_LT_DECL([to_host_file_cmd], [lt_cv_to_host_file_cmd],
+         [0], [convert $build file names to $host format])dnl
+
+AC_MSG_CHECKING([how to convert $build file names to toolchain format])
+AC_CACHE_VAL(lt_cv_to_tool_file_cmd,
+[#assume ordinary cross tools, or native build.
+lt_cv_to_tool_file_cmd=func_convert_file_noop
+case $host in
+  *-*-mingw* )
+    case $build in
+      *-*-mingw* ) # actually msys
+        lt_cv_to_tool_file_cmd=func_convert_file_msys_to_w32
+        ;;
+    esac
+    ;;
+esac
+])
+to_tool_file_cmd=$lt_cv_to_tool_file_cmd
+AC_MSG_RESULT([$lt_cv_to_tool_file_cmd])
+_LT_DECL([to_tool_file_cmd], [lt_cv_to_tool_file_cmd],
+         [0], [convert $build files to toolchain format])dnl
+])# _LT_PATH_CONVERSION_FUNCTIONS
+
+# Helper functions for option handling.                    -*- Autoconf -*-
+#
+#   Copyright (C) 2004, 2005, 2007, 2008, 2009 Free Software Foundation,
+#   Inc.
+#   Written by Gary V. Vaughan, 2004
+#
+# This file is free software; the Free Software Foundation gives
+# unlimited permission to copy and/or distribute it, with or without
+# modifications, as long as this notice is preserved.
+
+# serial 7 ltoptions.m4
+
+# This is to help aclocal find these macros, as it can't see m4_define.
+AC_DEFUN([LTOPTIONS_VERSION], [m4_if([1])])
+
+
+# _LT_MANGLE_OPTION(MACRO-NAME, OPTION-NAME)
+# ------------------------------------------
+m4_define([_LT_MANGLE_OPTION],
+[[_LT_OPTION_]m4_bpatsubst($1__$2, [[^a-zA-Z0-9_]], [_])])
+
+
+# _LT_SET_OPTION(MACRO-NAME, OPTION-NAME)
+# ---------------------------------------
+# Set option OPTION-NAME for macro MACRO-NAME, and if there is a
+# matching handler defined, dispatch to it.  Other OPTION-NAMEs are
+# saved as a flag.
+m4_define([_LT_SET_OPTION],
+[m4_define(_LT_MANGLE_OPTION([$1], [$2]))dnl
+m4_ifdef(_LT_MANGLE_DEFUN([$1], [$2]),
+        _LT_MANGLE_DEFUN([$1], [$2]),
+    [m4_warning([Unknown $1 option `$2'])])[]dnl
+])
+
+
+# _LT_IF_OPTION(MACRO-NAME, OPTION-NAME, IF-SET, [IF-NOT-SET])
+# ------------------------------------------------------------
+# Execute IF-SET if OPTION is set, IF-NOT-SET otherwise.
+m4_define([_LT_IF_OPTION],
+[m4_ifdef(_LT_MANGLE_OPTION([$1], [$2]), [$3], [$4])])
+
+
+# _LT_UNLESS_OPTIONS(MACRO-NAME, OPTION-LIST, IF-NOT-SET)
+# -------------------------------------------------------
+# Execute IF-NOT-SET unless all options in OPTION-LIST for MACRO-NAME
+# are set.
+m4_define([_LT_UNLESS_OPTIONS],
+[m4_foreach([_LT_Option], m4_split(m4_normalize([$2])),
+           [m4_ifdef(_LT_MANGLE_OPTION([$1], _LT_Option),
+                     [m4_define([$0_found])])])[]dnl
+m4_ifdef([$0_found], [m4_undefine([$0_found])], [$3
+])[]dnl
+])
+
+
+# _LT_SET_OPTIONS(MACRO-NAME, OPTION-LIST)
+# ----------------------------------------
+# OPTION-LIST is a space-separated list of Libtool options associated
+# with MACRO-NAME.  If any OPTION has a matching handler declared with
+# LT_OPTION_DEFINE, dispatch to that macro; otherwise complain about
+# the unknown option and exit.
+m4_defun([_LT_SET_OPTIONS],
+[# Set options
+m4_foreach([_LT_Option], m4_split(m4_normalize([$2])),
+    [_LT_SET_OPTION([$1], _LT_Option)])
+
+m4_if([$1],[LT_INIT],[
+  dnl
+  dnl Simply set some default values (i.e off) if boolean options were not
+  dnl specified:
+  _LT_UNLESS_OPTIONS([LT_INIT], [dlopen], [enable_dlopen=no
+  ])
+  _LT_UNLESS_OPTIONS([LT_INIT], [win32-dll], [enable_win32_dll=no
+  ])
+  dnl
+  dnl If no reference was made to various pairs of opposing options, then
+  dnl we run the default mode handler for the pair.  For example, if neither
+  dnl `shared' nor `disable-shared' was passed, we enable building of shared
+  dnl archives by default:
+  _LT_UNLESS_OPTIONS([LT_INIT], [shared disable-shared], [_LT_ENABLE_SHARED])
+  _LT_UNLESS_OPTIONS([LT_INIT], [static disable-static], [_LT_ENABLE_STATIC])
+  _LT_UNLESS_OPTIONS([LT_INIT], [pic-only no-pic], [_LT_WITH_PIC])
+  _LT_UNLESS_OPTIONS([LT_INIT], [fast-install disable-fast-install],
+                  [_LT_ENABLE_FAST_INSTALL])
+  ])
+])# _LT_SET_OPTIONS
+
+
+
+# _LT_MANGLE_DEFUN(MACRO-NAME, OPTION-NAME)
+# -----------------------------------------
+m4_define([_LT_MANGLE_DEFUN],
+[[_LT_OPTION_DEFUN_]m4_bpatsubst(m4_toupper([$1__$2]), [[^A-Z0-9_]], [_])])
+
+
+# LT_OPTION_DEFINE(MACRO-NAME, OPTION-NAME, CODE)
+# -----------------------------------------------
+m4_define([LT_OPTION_DEFINE],
+[m4_define(_LT_MANGLE_DEFUN([$1], [$2]), [$3])[]dnl
+])# LT_OPTION_DEFINE
+
+
+# dlopen
+# ------
+LT_OPTION_DEFINE([LT_INIT], [dlopen], [enable_dlopen=yes
+])
+
+AU_DEFUN([AC_LIBTOOL_DLOPEN],
+[_LT_SET_OPTION([LT_INIT], [dlopen])
+AC_DIAGNOSE([obsolete],
+[$0: Remove this warning and the call to _LT_SET_OPTION when you
+put the `dlopen' option into LT_INIT's first parameter.])
+])
+
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_LIBTOOL_DLOPEN], [])
+
+
+# win32-dll
+# ---------
+# Declare package support for building win32 dll's.
+LT_OPTION_DEFINE([LT_INIT], [win32-dll],
+[enable_win32_dll=yes
+
+case $host in
+*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-cegcc*)
+  AC_CHECK_TOOL(AS, as, false)
+  AC_CHECK_TOOL(DLLTOOL, dlltool, false)
+  AC_CHECK_TOOL(OBJDUMP, objdump, false)
+  ;;
+esac
+
+test -z "$AS" && AS=as
+_LT_DECL([], [AS],      [1], [Assembler program])dnl
+
+test -z "$DLLTOOL" && DLLTOOL=dlltool
+_LT_DECL([], [DLLTOOL], [1], [DLL creation program])dnl
+
+test -z "$OBJDUMP" && OBJDUMP=objdump
+_LT_DECL([], [OBJDUMP], [1], [Object dumper program])dnl
+])# win32-dll
+
+AU_DEFUN([AC_LIBTOOL_WIN32_DLL],
+[AC_REQUIRE([AC_CANONICAL_HOST])dnl
+_LT_SET_OPTION([LT_INIT], [win32-dll])
+AC_DIAGNOSE([obsolete],
+[$0: Remove this warning and the call to _LT_SET_OPTION when you
+put the `win32-dll' option into LT_INIT's first parameter.])
+])
+
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_LIBTOOL_WIN32_DLL], [])
+
+
+# _LT_ENABLE_SHARED([DEFAULT])
+# ----------------------------
+# implement the --enable-shared flag, and supports the `shared' and
+# `disable-shared' LT_INIT options.
+# DEFAULT is either `yes' or `no'.  If omitted, it defaults to `yes'.
+m4_define([_LT_ENABLE_SHARED],
+[m4_define([_LT_ENABLE_SHARED_DEFAULT], [m4_if($1, no, no, yes)])dnl
+AC_ARG_ENABLE([shared],
+    [AS_HELP_STRING([--enable-shared@<:@=PKGS@:>@],
+       [build shared libraries @<:@default=]_LT_ENABLE_SHARED_DEFAULT[@:>@])],
+    [p=${PACKAGE-default}
+    case $enableval in
+    yes) enable_shared=yes ;;
+    no) enable_shared=no ;;
+    *)
+      enable_shared=no
+      # Look at the argument we got.  We use all the common list separators.
+      lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
+      for pkg in $enableval; do
+       IFS="$lt_save_ifs"
+       if test "X$pkg" = "X$p"; then
+         enable_shared=yes
+       fi
+      done
+      IFS="$lt_save_ifs"
+      ;;
+    esac],
+    [enable_shared=]_LT_ENABLE_SHARED_DEFAULT)
+
+    _LT_DECL([build_libtool_libs], [enable_shared], [0],
+       [Whether or not to build shared libraries])
+])# _LT_ENABLE_SHARED
+
+LT_OPTION_DEFINE([LT_INIT], [shared], [_LT_ENABLE_SHARED([yes])])
+LT_OPTION_DEFINE([LT_INIT], [disable-shared], [_LT_ENABLE_SHARED([no])])
+
+# Old names:
+AC_DEFUN([AC_ENABLE_SHARED],
+[_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[shared])
+])
+
+AC_DEFUN([AC_DISABLE_SHARED],
+[_LT_SET_OPTION([LT_INIT], [disable-shared])
+])
+
+AU_DEFUN([AM_ENABLE_SHARED], [AC_ENABLE_SHARED($@)])
+AU_DEFUN([AM_DISABLE_SHARED], [AC_DISABLE_SHARED($@)])
+
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AM_ENABLE_SHARED], [])
+dnl AC_DEFUN([AM_DISABLE_SHARED], [])
+
+
+
+# _LT_ENABLE_STATIC([DEFAULT])
+# ----------------------------
+# implement the --enable-static flag, and support the `static' and
+# `disable-static' LT_INIT options.
+# DEFAULT is either `yes' or `no'.  If omitted, it defaults to `yes'.
+m4_define([_LT_ENABLE_STATIC],
+[m4_define([_LT_ENABLE_STATIC_DEFAULT], [m4_if($1, no, no, yes)])dnl
+AC_ARG_ENABLE([static],
+    [AS_HELP_STRING([--enable-static@<:@=PKGS@:>@],
+       [build static libraries @<:@default=]_LT_ENABLE_STATIC_DEFAULT[@:>@])],
+    [p=${PACKAGE-default}
+    case $enableval in
+    yes) enable_static=yes ;;
+    no) enable_static=no ;;
+    *)
+     enable_static=no
+      # Look at the argument we got.  We use all the common list separators.
+      lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
+      for pkg in $enableval; do
+       IFS="$lt_save_ifs"
+       if test "X$pkg" = "X$p"; then
+         enable_static=yes
+       fi
+      done
+      IFS="$lt_save_ifs"
+      ;;
+    esac],
+    [enable_static=]_LT_ENABLE_STATIC_DEFAULT)
+
+    _LT_DECL([build_old_libs], [enable_static], [0],
+       [Whether or not to build static libraries])
+])# _LT_ENABLE_STATIC
+
+LT_OPTION_DEFINE([LT_INIT], [static], [_LT_ENABLE_STATIC([yes])])
+LT_OPTION_DEFINE([LT_INIT], [disable-static], [_LT_ENABLE_STATIC([no])])
+
+# Old names:
+AC_DEFUN([AC_ENABLE_STATIC],
+[_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[static])
+])
+
+AC_DEFUN([AC_DISABLE_STATIC],
+[_LT_SET_OPTION([LT_INIT], [disable-static])
+])
+
+AU_DEFUN([AM_ENABLE_STATIC], [AC_ENABLE_STATIC($@)])
+AU_DEFUN([AM_DISABLE_STATIC], [AC_DISABLE_STATIC($@)])
+
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AM_ENABLE_STATIC], [])
+dnl AC_DEFUN([AM_DISABLE_STATIC], [])
+
+
+
+# _LT_ENABLE_FAST_INSTALL([DEFAULT])
+# ----------------------------------
+# implement the --enable-fast-install flag, and support the `fast-install'
+# and `disable-fast-install' LT_INIT options.
+# DEFAULT is either `yes' or `no'.  If omitted, it defaults to `yes'.
+m4_define([_LT_ENABLE_FAST_INSTALL],
+[m4_define([_LT_ENABLE_FAST_INSTALL_DEFAULT], [m4_if($1, no, no, yes)])dnl
+AC_ARG_ENABLE([fast-install],
+    [AS_HELP_STRING([--enable-fast-install@<:@=PKGS@:>@],
+    [optimize for fast installation @<:@default=]_LT_ENABLE_FAST_INSTALL_DEFAULT[@:>@])],
+    [p=${PACKAGE-default}
+    case $enableval in
+    yes) enable_fast_install=yes ;;
+    no) enable_fast_install=no ;;
+    *)
+      enable_fast_install=no
+      # Look at the argument we got.  We use all the common list separators.
+      lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
+      for pkg in $enableval; do
+       IFS="$lt_save_ifs"
+       if test "X$pkg" = "X$p"; then
+         enable_fast_install=yes
+       fi
+      done
+      IFS="$lt_save_ifs"
+      ;;
+    esac],
+    [enable_fast_install=]_LT_ENABLE_FAST_INSTALL_DEFAULT)
+
+_LT_DECL([fast_install], [enable_fast_install], [0],
+        [Whether or not to optimize for fast installation])dnl
+])# _LT_ENABLE_FAST_INSTALL
+
+LT_OPTION_DEFINE([LT_INIT], [fast-install], [_LT_ENABLE_FAST_INSTALL([yes])])
+LT_OPTION_DEFINE([LT_INIT], [disable-fast-install], [_LT_ENABLE_FAST_INSTALL([no])])
+
+# Old names:
+AU_DEFUN([AC_ENABLE_FAST_INSTALL],
+[_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[fast-install])
+AC_DIAGNOSE([obsolete],
+[$0: Remove this warning and the call to _LT_SET_OPTION when you put
+the `fast-install' option into LT_INIT's first parameter.])
+])
+
+AU_DEFUN([AC_DISABLE_FAST_INSTALL],
+[_LT_SET_OPTION([LT_INIT], [disable-fast-install])
+AC_DIAGNOSE([obsolete],
+[$0: Remove this warning and the call to _LT_SET_OPTION when you put
+the `disable-fast-install' option into LT_INIT's first parameter.])
+])
+
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_ENABLE_FAST_INSTALL], [])
+dnl AC_DEFUN([AM_DISABLE_FAST_INSTALL], [])
+
+
+# _LT_WITH_PIC([MODE])
+# --------------------
+# implement the --with-pic flag, and support the `pic-only' and `no-pic'
+# LT_INIT options.
+# MODE is either `yes' or `no'.  If omitted, it defaults to `both'.
+m4_define([_LT_WITH_PIC],
+[AC_ARG_WITH([pic],
+    [AS_HELP_STRING([--with-pic@<:@=PKGS@:>@],
+       [try to use only PIC/non-PIC objects @<:@default=use both@:>@])],
+    [lt_p=${PACKAGE-default}
+    case $withval in
+    yes|no) pic_mode=$withval ;;
+    *)
+      pic_mode=default
+      # Look at the argument we got.  We use all the common list separators.
+      lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
+      for lt_pkg in $withval; do
+       IFS="$lt_save_ifs"
+       if test "X$lt_pkg" = "X$lt_p"; then
+         pic_mode=yes
+       fi
+      done
+      IFS="$lt_save_ifs"
+      ;;
+    esac],
+    [pic_mode=default])
+
+test -z "$pic_mode" && pic_mode=m4_default([$1], [default])
+
+_LT_DECL([], [pic_mode], [0], [What type of objects to build])dnl
+])# _LT_WITH_PIC
+
+LT_OPTION_DEFINE([LT_INIT], [pic-only], [_LT_WITH_PIC([yes])])
+LT_OPTION_DEFINE([LT_INIT], [no-pic], [_LT_WITH_PIC([no])])
+
+# Old name:
+AU_DEFUN([AC_LIBTOOL_PICMODE],
+[_LT_SET_OPTION([LT_INIT], [pic-only])
+AC_DIAGNOSE([obsolete],
+[$0: Remove this warning and the call to _LT_SET_OPTION when you
+put the `pic-only' option into LT_INIT's first parameter.])
+])
+
+dnl aclocal-1.4 backwards compatibility:
+dnl AC_DEFUN([AC_LIBTOOL_PICMODE], [])
+
+
+m4_define([_LTDL_MODE], [])
+LT_OPTION_DEFINE([LTDL_INIT], [nonrecursive],
+                [m4_define([_LTDL_MODE], [nonrecursive])])
+LT_OPTION_DEFINE([LTDL_INIT], [recursive],
+                [m4_define([_LTDL_MODE], [recursive])])
+LT_OPTION_DEFINE([LTDL_INIT], [subproject],
+                [m4_define([_LTDL_MODE], [subproject])])
+
+m4_define([_LTDL_TYPE], [])
+LT_OPTION_DEFINE([LTDL_INIT], [installable],
+                [m4_define([_LTDL_TYPE], [installable])])
+LT_OPTION_DEFINE([LTDL_INIT], [convenience],
+                [m4_define([_LTDL_TYPE], [convenience])])
+
+# ltsugar.m4 -- libtool m4 base layer.                         -*-Autoconf-*-
+#
+# Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc.
+# Written by Gary V. Vaughan, 2004
+#
+# This file is free software; the Free Software Foundation gives
+# unlimited permission to copy and/or distribute it, with or without
+# modifications, as long as this notice is preserved.
+
+# serial 6 ltsugar.m4
+
+# This is to help aclocal find these macros, as it can't see m4_define.
+AC_DEFUN([LTSUGAR_VERSION], [m4_if([0.1])])
+
+
+# lt_join(SEP, ARG1, [ARG2...])
+# -----------------------------
+# Produce ARG1SEPARG2...SEPARGn, omitting [] arguments and their
+# associated separator.
+# Needed until we can rely on m4_join from Autoconf 2.62, since all earlier
+# versions in m4sugar had bugs.
+m4_define([lt_join],
+[m4_if([$#], [1], [],
+       [$#], [2], [[$2]],
+       [m4_if([$2], [], [], [[$2]_])$0([$1], m4_shift(m4_shift($@)))])])
+m4_define([_lt_join],
+[m4_if([$#$2], [2], [],
+       [m4_if([$2], [], [], [[$1$2]])$0([$1], m4_shift(m4_shift($@)))])])
+
+
+# lt_car(LIST)
+# lt_cdr(LIST)
+# ------------
+# Manipulate m4 lists.
+# These macros are necessary as long as will still need to support
+# Autoconf-2.59 which quotes differently.
+m4_define([lt_car], [[$1]])
+m4_define([lt_cdr],
+[m4_if([$#], 0, [m4_fatal([$0: cannot be called without arguments])],
+       [$#], 1, [],
+       [m4_dquote(m4_shift($@))])])
+m4_define([lt_unquote], $1)
+
+
+# lt_append(MACRO-NAME, STRING, [SEPARATOR])
+# ------------------------------------------
+# Redefine MACRO-NAME to hold its former content plus `SEPARATOR'`STRING'.
+# Note that neither SEPARATOR nor STRING are expanded; they are appended
+# to MACRO-NAME as is (leaving the expansion for when MACRO-NAME is invoked).
+# No SEPARATOR is output if MACRO-NAME was previously undefined (different
+# than defined and empty).
+#
+# This macro is needed until we can rely on Autoconf 2.62, since earlier
+# versions of m4sugar mistakenly expanded SEPARATOR but not STRING.
+m4_define([lt_append],
+[m4_define([$1],
+          m4_ifdef([$1], [m4_defn([$1])[$3]])[$2])])
+
+
+
+# lt_combine(SEP, PREFIX-LIST, INFIX, SUFFIX1, [SUFFIX2...])
+# ----------------------------------------------------------
+# Produce a SEP delimited list of all paired combinations of elements of
+# PREFIX-LIST with SUFFIX1 through SUFFIXn.  Each element of the list
+# has the form PREFIXmINFIXSUFFIXn.
+# Needed until we can rely on m4_combine added in Autoconf 2.62.
+m4_define([lt_combine],
+[m4_if(m4_eval([$# > 3]), [1],
+       [m4_pushdef([_Lt_sep], [m4_define([_Lt_sep], m4_defn([lt_car]))])]]dnl
+[[m4_foreach([_Lt_prefix], [$2],
+            [m4_foreach([_Lt_suffix],
+               ]m4_dquote(m4_dquote(m4_shift(m4_shift(m4_shift($@)))))[,
+       [_Lt_sep([$1])[]m4_defn([_Lt_prefix])[$3]m4_defn([_Lt_suffix])])])])])
+
+
+# lt_if_append_uniq(MACRO-NAME, VARNAME, [SEPARATOR], [UNIQ], [NOT-UNIQ])
+# -----------------------------------------------------------------------
+# Iff MACRO-NAME does not yet contain VARNAME, then append it (delimited
+# by SEPARATOR if supplied) and expand UNIQ, else NOT-UNIQ.
+m4_define([lt_if_append_uniq],
+[m4_ifdef([$1],
+         [m4_if(m4_index([$3]m4_defn([$1])[$3], [$3$2$3]), [-1],
+                [lt_append([$1], [$2], [$3])$4],
+                [$5])],
+         [lt_append([$1], [$2], [$3])$4])])
+
+
+# lt_dict_add(DICT, KEY, VALUE)
+# -----------------------------
+m4_define([lt_dict_add],
+[m4_define([$1($2)], [$3])])
+
+
+# lt_dict_add_subkey(DICT, KEY, SUBKEY, VALUE)
+# --------------------------------------------
+m4_define([lt_dict_add_subkey],
+[m4_define([$1($2:$3)], [$4])])
+
+
+# lt_dict_fetch(DICT, KEY, [SUBKEY])
+# ----------------------------------
+m4_define([lt_dict_fetch],
+[m4_ifval([$3],
+       m4_ifdef([$1($2:$3)], [m4_defn([$1($2:$3)])]),
+    m4_ifdef([$1($2)], [m4_defn([$1($2)])]))])
+
+
+# lt_if_dict_fetch(DICT, KEY, [SUBKEY], VALUE, IF-TRUE, [IF-FALSE])
+# -----------------------------------------------------------------
+m4_define([lt_if_dict_fetch],
+[m4_if(lt_dict_fetch([$1], [$2], [$3]), [$4],
+       [$5],
+    [$6])])
+
+
+# lt_dict_filter(DICT, [SUBKEY], VALUE, [SEPARATOR], KEY, [...])
+# --------------------------------------------------------------
+m4_define([lt_dict_filter],
+[m4_if([$5], [], [],
+  [lt_join(m4_quote(m4_default([$4], [[, ]])),
+           lt_unquote(m4_split(m4_normalize(m4_foreach(_Lt_key, lt_car([m4_shiftn(4, $@)]),
+                     [lt_if_dict_fetch([$1], _Lt_key, [$2], [$3], [_Lt_key ])])))))])[]dnl
+])
+
+# ltversion.m4 -- version numbers                      -*- Autoconf -*-
+#
+#   Copyright (C) 2004 Free Software Foundation, Inc.
+#   Written by Scott James Remnant, 2004
+#
+# This file is free software; the Free Software Foundation gives
+# unlimited permission to copy and/or distribute it, with or without
+# modifications, as long as this notice is preserved.
+
+# @configure_input@
+
+# serial 3337 ltversion.m4
+# This file is part of GNU Libtool
+
+m4_define([LT_PACKAGE_VERSION], [2.4.2])
+m4_define([LT_PACKAGE_REVISION], [1.3337])
+
+AC_DEFUN([LTVERSION_VERSION],
+[macro_version='2.4.2'
+macro_revision='1.3337'
+_LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?])
+_LT_DECL(, macro_revision, 0)
+])
+
+# lt~obsolete.m4 -- aclocal satisfying obsolete definitions.    -*-Autoconf-*-
+#
+#   Copyright (C) 2004, 2005, 2007, 2009 Free Software Foundation, Inc.
+#   Written by Scott James Remnant, 2004.
+#
+# This file is free software; the Free Software Foundation gives
+# unlimited permission to copy and/or distribute it, with or without
+# modifications, as long as this notice is preserved.
+
+# serial 5 lt~obsolete.m4
+
+# These exist entirely to fool aclocal when bootstrapping libtool.
+#
+# In the past libtool.m4 has provided macros via AC_DEFUN (or AU_DEFUN)
+# which have later been changed to m4_define as they aren't part of the
+# exported API, or moved to Autoconf or Automake where they belong.
+#
+# The trouble is, aclocal is a bit thick.  It'll see the old AC_DEFUN
+# in /usr/share/aclocal/libtool.m4 and remember it, then when it sees us
+# using a macro with the same name in our local m4/libtool.m4 it'll
+# pull the old libtool.m4 in (it doesn't see our shiny new m4_define
+# and doesn't know about Autoconf macros at all.)
+#
+# So we provide this file, which has a silly filename so it's always
+# included after everything else.  This provides aclocal with the
+# AC_DEFUNs it wants, but when m4 processes it, it doesn't do anything
+# because those macros already exist, or will be overwritten later.
+# We use AC_DEFUN over AU_DEFUN for compatibility with aclocal-1.6. 
+#
+# Anytime we withdraw an AC_DEFUN or AU_DEFUN, remember to add it here.
+# Yes, that means every name once taken will need to remain here until
+# we give up compatibility with versions before 1.7, at which point
+# we need to keep only those names which we still refer to.
+
+# This is to help aclocal find these macros, as it can't see m4_define.
+AC_DEFUN([LTOBSOLETE_VERSION], [m4_if([1])])
+
+m4_ifndef([AC_LIBTOOL_LINKER_OPTION],  [AC_DEFUN([AC_LIBTOOL_LINKER_OPTION])])
+m4_ifndef([AC_PROG_EGREP],             [AC_DEFUN([AC_PROG_EGREP])])
+m4_ifndef([_LT_AC_PROG_ECHO_BACKSLASH],        [AC_DEFUN([_LT_AC_PROG_ECHO_BACKSLASH])])
+m4_ifndef([_LT_AC_SHELL_INIT],         [AC_DEFUN([_LT_AC_SHELL_INIT])])
+m4_ifndef([_LT_AC_SYS_LIBPATH_AIX],    [AC_DEFUN([_LT_AC_SYS_LIBPATH_AIX])])
+m4_ifndef([_LT_PROG_LTMAIN],           [AC_DEFUN([_LT_PROG_LTMAIN])])
+m4_ifndef([_LT_AC_TAGVAR],             [AC_DEFUN([_LT_AC_TAGVAR])])
+m4_ifndef([AC_LTDL_ENABLE_INSTALL],    [AC_DEFUN([AC_LTDL_ENABLE_INSTALL])])
+m4_ifndef([AC_LTDL_PREOPEN],           [AC_DEFUN([AC_LTDL_PREOPEN])])
+m4_ifndef([_LT_AC_SYS_COMPILER],       [AC_DEFUN([_LT_AC_SYS_COMPILER])])
+m4_ifndef([_LT_AC_LOCK],               [AC_DEFUN([_LT_AC_LOCK])])
+m4_ifndef([AC_LIBTOOL_SYS_OLD_ARCHIVE],        [AC_DEFUN([AC_LIBTOOL_SYS_OLD_ARCHIVE])])
+m4_ifndef([_LT_AC_TRY_DLOPEN_SELF],    [AC_DEFUN([_LT_AC_TRY_DLOPEN_SELF])])
+m4_ifndef([AC_LIBTOOL_PROG_CC_C_O],    [AC_DEFUN([AC_LIBTOOL_PROG_CC_C_O])])
+m4_ifndef([AC_LIBTOOL_SYS_HARD_LINK_LOCKS], [AC_DEFUN([AC_LIBTOOL_SYS_HARD_LINK_LOCKS])])
+m4_ifndef([AC_LIBTOOL_OBJDIR],         [AC_DEFUN([AC_LIBTOOL_OBJDIR])])
+m4_ifndef([AC_LTDL_OBJDIR],            [AC_DEFUN([AC_LTDL_OBJDIR])])
+m4_ifndef([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH], [AC_DEFUN([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH])])
+m4_ifndef([AC_LIBTOOL_SYS_LIB_STRIP],  [AC_DEFUN([AC_LIBTOOL_SYS_LIB_STRIP])])
+m4_ifndef([AC_PATH_MAGIC],             [AC_DEFUN([AC_PATH_MAGIC])])
+m4_ifndef([AC_PROG_LD_GNU],            [AC_DEFUN([AC_PROG_LD_GNU])])
+m4_ifndef([AC_PROG_LD_RELOAD_FLAG],    [AC_DEFUN([AC_PROG_LD_RELOAD_FLAG])])
+m4_ifndef([AC_DEPLIBS_CHECK_METHOD],   [AC_DEFUN([AC_DEPLIBS_CHECK_METHOD])])
+m4_ifndef([AC_LIBTOOL_PROG_COMPILER_NO_RTTI], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_NO_RTTI])])
+m4_ifndef([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE], [AC_DEFUN([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE])])
+m4_ifndef([AC_LIBTOOL_PROG_COMPILER_PIC], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_PIC])])
+m4_ifndef([AC_LIBTOOL_PROG_LD_SHLIBS], [AC_DEFUN([AC_LIBTOOL_PROG_LD_SHLIBS])])
+m4_ifndef([AC_LIBTOOL_POSTDEP_PREDEP], [AC_DEFUN([AC_LIBTOOL_POSTDEP_PREDEP])])
+m4_ifndef([LT_AC_PROG_EGREP],          [AC_DEFUN([LT_AC_PROG_EGREP])])
+m4_ifndef([LT_AC_PROG_SED],            [AC_DEFUN([LT_AC_PROG_SED])])
+m4_ifndef([_LT_CC_BASENAME],           [AC_DEFUN([_LT_CC_BASENAME])])
+m4_ifndef([_LT_COMPILER_BOILERPLATE],  [AC_DEFUN([_LT_COMPILER_BOILERPLATE])])
+m4_ifndef([_LT_LINKER_BOILERPLATE],    [AC_DEFUN([_LT_LINKER_BOILERPLATE])])
+m4_ifndef([_AC_PROG_LIBTOOL],          [AC_DEFUN([_AC_PROG_LIBTOOL])])
+m4_ifndef([AC_LIBTOOL_SETUP],          [AC_DEFUN([AC_LIBTOOL_SETUP])])
+m4_ifndef([_LT_AC_CHECK_DLFCN],                [AC_DEFUN([_LT_AC_CHECK_DLFCN])])
+m4_ifndef([AC_LIBTOOL_SYS_DYNAMIC_LINKER],     [AC_DEFUN([AC_LIBTOOL_SYS_DYNAMIC_LINKER])])
+m4_ifndef([_LT_AC_TAGCONFIG],          [AC_DEFUN([_LT_AC_TAGCONFIG])])
+m4_ifndef([AC_DISABLE_FAST_INSTALL],   [AC_DEFUN([AC_DISABLE_FAST_INSTALL])])
+m4_ifndef([_LT_AC_LANG_CXX],           [AC_DEFUN([_LT_AC_LANG_CXX])])
+m4_ifndef([_LT_AC_LANG_F77],           [AC_DEFUN([_LT_AC_LANG_F77])])
+m4_ifndef([_LT_AC_LANG_GCJ],           [AC_DEFUN([_LT_AC_LANG_GCJ])])
+m4_ifndef([AC_LIBTOOL_LANG_C_CONFIG],  [AC_DEFUN([AC_LIBTOOL_LANG_C_CONFIG])])
+m4_ifndef([_LT_AC_LANG_C_CONFIG],      [AC_DEFUN([_LT_AC_LANG_C_CONFIG])])
+m4_ifndef([AC_LIBTOOL_LANG_CXX_CONFIG],        [AC_DEFUN([AC_LIBTOOL_LANG_CXX_CONFIG])])
+m4_ifndef([_LT_AC_LANG_CXX_CONFIG],    [AC_DEFUN([_LT_AC_LANG_CXX_CONFIG])])
+m4_ifndef([AC_LIBTOOL_LANG_F77_CONFIG],        [AC_DEFUN([AC_LIBTOOL_LANG_F77_CONFIG])])
+m4_ifndef([_LT_AC_LANG_F77_CONFIG],    [AC_DEFUN([_LT_AC_LANG_F77_CONFIG])])
+m4_ifndef([AC_LIBTOOL_LANG_GCJ_CONFIG],        [AC_DEFUN([AC_LIBTOOL_LANG_GCJ_CONFIG])])
+m4_ifndef([_LT_AC_LANG_GCJ_CONFIG],    [AC_DEFUN([_LT_AC_LANG_GCJ_CONFIG])])
+m4_ifndef([AC_LIBTOOL_LANG_RC_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_RC_CONFIG])])
+m4_ifndef([_LT_AC_LANG_RC_CONFIG],     [AC_DEFUN([_LT_AC_LANG_RC_CONFIG])])
+m4_ifndef([AC_LIBTOOL_CONFIG],         [AC_DEFUN([AC_LIBTOOL_CONFIG])])
+m4_ifndef([_LT_AC_FILE_LTDLL_C],       [AC_DEFUN([_LT_AC_FILE_LTDLL_C])])
+m4_ifndef([_LT_REQUIRED_DARWIN_CHECKS],        [AC_DEFUN([_LT_REQUIRED_DARWIN_CHECKS])])
+m4_ifndef([_LT_AC_PROG_CXXCPP],                [AC_DEFUN([_LT_AC_PROG_CXXCPP])])
+m4_ifndef([_LT_PREPARE_SED_QUOTE_VARS],        [AC_DEFUN([_LT_PREPARE_SED_QUOTE_VARS])])
+m4_ifndef([_LT_PROG_ECHO_BACKSLASH],   [AC_DEFUN([_LT_PROG_ECHO_BACKSLASH])])
+m4_ifndef([_LT_PROG_F77],              [AC_DEFUN([_LT_PROG_F77])])
+m4_ifndef([_LT_PROG_FC],               [AC_DEFUN([_LT_PROG_FC])])
+m4_ifndef([_LT_PROG_CXX],              [AC_DEFUN([_LT_PROG_CXX])])
+
 # pkg.m4 - Macros to locate and utilise pkg-config.            -*- Autoconf -*-
 # serial 1 (pkg-config-0.24)
 # 
@@ -47,7 +8636,8 @@ To do so, use the procedure documented by the package, typically `autoreconf'.])
 # ----------------------------------
 AC_DEFUN([PKG_PROG_PKG_CONFIG],
 [m4_pattern_forbid([^_?PKG_[A-Z_]+$])
-m4_pattern_allow([^PKG_CONFIG(_PATH)?$])
+m4_pattern_allow([^PKG_CONFIG(_(PATH|LIBDIR|SYSROOT_DIR|ALLOW_SYSTEM_(CFLAGS|LIBS)))?$])
+m4_pattern_allow([^PKG_CONFIG_(DISABLE_UNINSTALLED|TOP_BUILD_DIR|DEBUG_SPEW)$])
 AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility])
 AC_ARG_VAR([PKG_CONFIG_PATH], [directories to add to pkg-config's search path])
 AC_ARG_VAR([PKG_CONFIG_LIBDIR], [path overriding pkg-config's built-in search path])
@@ -93,7 +8683,8 @@ m4_define([_PKG_CONFIG],
     pkg_cv_[]$1="$$1"
  elif test -n "$PKG_CONFIG"; then
     PKG_CHECK_EXISTS([$3],
-                     [pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null`],
+                     [pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null`
+                     test "x$?" != "x0" && pkg_failed=yes ],
                     [pkg_failed=yes])
  else
     pkg_failed=untried
@@ -141,9 +8732,9 @@ if test $pkg_failed = yes; then
        AC_MSG_RESULT([no])
         _PKG_SHORT_ERRORS_SUPPORTED
         if test $_pkg_short_errors_supported = yes; then
-               $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "$2" 2>&1`
+               $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "$2" 2>&1`
         else 
-               $1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors "$2" 2>&1`
+               $1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "$2" 2>&1`
         fi
        # Put the nasty error message in config.log where it belongs
        echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD
@@ -216,7 +8807,7 @@ dnl DEALINGS IN THE SOFTWARE.
 # See the "minimum version" comment for each macro you use to see what 
 # version you require.
 m4_defun([XORG_MACROS_VERSION],[
-m4_define([vers_have], [1.12.0])
+m4_define([vers_have], [1.17])
 m4_define([maj_have], m4_substr(vers_have, 0, m4_index(vers_have, [.])))
 m4_define([maj_needed], m4_substr([$1], 0, m4_index([$1], [.])))
 m4_if(m4_cmp(maj_have, maj_needed), 0,,
@@ -243,7 +8834,7 @@ AC_PATH_PROGS(RAWCPP, [cpp], [${CPP}],
 # which is not the best choice for supporting other OS'es, but covers most
 # of the ones we need for now.
 AC_MSG_CHECKING([if $RAWCPP requires -undef])
-AC_LANG_CONFTEST([Does cpp redefine unix ?])
+AC_LANG_CONFTEST([AC_LANG_SOURCE([[Does cpp redefine unix ?]])])
 if test `${RAWCPP} < conftest.$ac_ext | grep -c 'unix'` -eq 1 ; then
        AC_MSG_RESULT([no])
 else
@@ -261,7 +8852,7 @@ fi
 rm -f conftest.$ac_ext
 
 AC_MSG_CHECKING([if $RAWCPP requires -traditional])
-AC_LANG_CONFTEST([Does cpp preserve   "whitespace"?])
+AC_LANG_CONFTEST([AC_LANG_SOURCE([[Does cpp preserve   "whitespace"?]])])
 if test `${RAWCPP} < conftest.$ac_ext | grep -c 'preserve   \"'` -eq 1 ; then
        AC_MSG_RESULT([no])
 else
@@ -636,6 +9227,8 @@ AM_CONDITIONAL([HAVE_XMLTO], [test "$have_xmlto" = yes])
 #
 AC_DEFUN([XORG_WITH_XSLTPROC],[
 AC_ARG_VAR([XSLTPROC], [Path to xsltproc command])
+# Preserves the interface, should it be implemented later
+m4_ifval([$1], [m4_warn([syntax], [Checking for xsltproc MIN-VERSION is not implemented])])
 m4_define([_defopt], m4_default([$2], [auto]))
 AC_ARG_WITH(xsltproc,
        AS_HELP_STRING([--with-xsltproc],
@@ -666,13 +9259,65 @@ else
    AC_MSG_ERROR([--with-xsltproc expects 'yes' or 'no'])
 fi
 
-# Checking for minimum version is not implemented
-# but we want to keep the interface consistent with other commands
-m4_ifval([$1],[AC_MSG_WARN(Checking for MIN-VERSION is not implemented.)])
-
 AM_CONDITIONAL([HAVE_XSLTPROC], [test "$have_xsltproc" = yes])
 ]) # XORG_WITH_XSLTPROC
 
+# XORG_WITH_PERL([MIN-VERSION], [DEFAULT])
+# ----------------------------------------
+# Minimum version: 1.15.0
+#
+# PERL (Practical Extraction and Report Language) is a language optimized for
+# scanning arbitrary text files, extracting information from those text files,
+# and printing reports based on that information.
+#
+# When DEFAULT is not specified, --with-perl assumes 'auto'.
+#
+# Interface to module:
+# HAVE_PERL: used in makefiles to conditionally scan text files
+# PERL:             returns the path of the perl program found
+#           returns the path set by the user in the environment
+# --with-perl: 'yes' user instructs the module to use perl
+#             'no' user instructs the module not to use perl
+# have_perl: returns yes if perl found in PATH or no
+#
+# If the user sets the value of PERL, AC_PATH_PROG skips testing the path.
+#
+AC_DEFUN([XORG_WITH_PERL],[
+AC_ARG_VAR([PERL], [Path to perl command])
+# Preserves the interface, should it be implemented later
+m4_ifval([$1], [m4_warn([syntax], [Checking for perl MIN-VERSION is not implemented])])
+m4_define([_defopt], m4_default([$2], [auto]))
+AC_ARG_WITH(perl,
+       AS_HELP_STRING([--with-perl],
+          [Use perl for extracting information from files (default: ]_defopt[)]),
+          [use_perl=$withval], [use_perl=]_defopt)
+m4_undefine([_defopt])
+
+if test "x$use_perl" = x"auto"; then
+   AC_PATH_PROG([PERL], [perl])
+   if test "x$PERL" = "x"; then
+        AC_MSG_WARN([perl not found - cannot extract information and report])
+       have_perl=no
+   else
+        have_perl=yes
+   fi
+elif test "x$use_perl" = x"yes" ; then
+   AC_PATH_PROG([PERL], [perl])
+   if test "x$PERL" = "x"; then
+        AC_MSG_ERROR([--with-perl=yes specified but perl not found in PATH])
+   fi
+   have_perl=yes
+elif test "x$use_perl" = x"no" ; then
+   if test "x$PERL" != "x"; then
+      AC_MSG_WARN([ignoring PERL environment variable since --with-perl=no was specified])
+   fi
+   have_perl=no
+else
+   AC_MSG_ERROR([--with-perl expects 'yes' or 'no'])
+fi
+
+AM_CONDITIONAL([HAVE_PERL], [test "$have_perl" = yes])
+]) # XORG_WITH_PERL
 
 # XORG_WITH_ASCIIDOC([MIN-VERSION], [DEFAULT])
 # ----------------
@@ -919,10 +9564,11 @@ AM_CONDITIONAL([HAVE_GROFF_MM], [test "$groff_mm_works" = yes])
 AM_CONDITIONAL([HAVE_GROFF_HTML], [test "$have_groff_html" = yes])
 ]) # XORG_WITH_GROFF
 
-# XORG_WITH_FOP([DEFAULT])
-# ----------------
+# XORG_WITH_FOP([MIN-VERSION], [DEFAULT])
+# ---------------------------------------
 # Minimum version: 1.6.0
 # Minimum version for optional DEFAULT argument: 1.11.0
+# Minimum version for optional MIN-VERSION argument: 1.15.0
 #
 # Documentation tools are not always available on all platforms and sometimes
 # not at the appropriate level. This macro enables a module to test for the
@@ -942,7 +9588,7 @@ AM_CONDITIONAL([HAVE_GROFF_HTML], [test "$have_groff_html" = yes])
 #
 AC_DEFUN([XORG_WITH_FOP],[
 AC_ARG_VAR([FOP], [Path to fop command])
-m4_define([_defopt], m4_default([$1], [auto]))
+m4_define([_defopt], m4_default([$2], [auto]))
 AC_ARG_WITH(fop,
        AS_HELP_STRING([--with-fop],
           [Use fop to regenerate documentation (default: ]_defopt[)]),
@@ -971,6 +9617,22 @@ elif test "x$use_fop" = x"no" ; then
 else
    AC_MSG_ERROR([--with-fop expects 'yes' or 'no'])
 fi
+
+# Test for a minimum version of fop, if provided.
+m4_ifval([$1],
+[if test "$have_fop" = yes; then
+    # scrape the fop version
+    AC_MSG_CHECKING([for fop minimum version])
+    fop_version=`$FOP -version 2>/dev/null | cut -d' ' -f3`
+    AC_MSG_RESULT([$fop_version])
+    AS_VERSION_COMPARE([$fop_version], [$1],
+        [if test "x$use_fop" = xauto; then
+            AC_MSG_WARN([fop version $fop_version found, but $1 needed])
+            have_fop=no
+        else
+            AC_MSG_ERROR([fop version $fop_version found, but $1 needed])
+        fi])
+fi])
 AM_CONDITIONAL([HAVE_FOP], [test "$have_fop" = yes])
 ]) # XORG_WITH_FOP
 
@@ -1130,6 +9792,288 @@ AC_MSG_CHECKING([whether to build functional specifications])
 AC_MSG_RESULT([$build_specs])
 ]) # XORG_ENABLE_SPECS
 
+# XORG_ENABLE_UNIT_TESTS (enable_unit_tests=auto)
+# ----------------------------------------------
+# Minimum version: 1.13.0
+#
+# This macro enables a builder to enable/disable unit testing
+# It makes no assumption about the test cases implementation
+# Test cases may or may not use Automake "Support for test suites"
+# They may or may not use the software utility library GLib
+#
+# When used in conjunction with XORG_WITH_GLIB, use both AM_CONDITIONAL
+# ENABLE_UNIT_TESTS and HAVE_GLIB. Not all unit tests may use glib.
+# The variable enable_unit_tests is used by other macros in this file.
+#
+# Interface to module:
+# ENABLE_UNIT_TESTS:   used in makefiles to conditionally build tests
+# enable_unit_tests:    used in configure.ac for additional configuration
+# --enable-unit-tests: 'yes' user instructs the module to build tests
+#                      'no' user instructs the module not to build tests
+# parm1:               specify the default value, yes or no.
+#
+AC_DEFUN([XORG_ENABLE_UNIT_TESTS],[
+AC_BEFORE([$0], [XORG_WITH_GLIB])
+AC_BEFORE([$0], [XORG_LD_WRAP])
+AC_REQUIRE([XORG_MEMORY_CHECK_FLAGS])
+m4_define([_defopt], m4_default([$1], [auto]))
+AC_ARG_ENABLE(unit-tests, AS_HELP_STRING([--enable-unit-tests],
+       [Enable building unit test cases (default: ]_defopt[)]),
+       [enable_unit_tests=$enableval], [enable_unit_tests=]_defopt)
+m4_undefine([_defopt])
+AM_CONDITIONAL(ENABLE_UNIT_TESTS, [test "x$enable_unit_tests" != xno])
+AC_MSG_CHECKING([whether to build unit test cases])
+AC_MSG_RESULT([$enable_unit_tests])
+]) # XORG_ENABLE_UNIT_TESTS
+
+# XORG_ENABLE_INTEGRATION_TESTS (enable_unit_tests=auto)
+# ------------------------------------------------------
+# Minimum version: 1.17.0
+#
+# This macro enables a builder to enable/disable integration testing
+# It makes no assumption about the test cases' implementation
+# Test cases may or may not use Automake "Support for test suites"
+#
+# Please see XORG_ENABLE_UNIT_TESTS for unit test support. Unit test support
+# usually requires less dependencies and may be built and run under less
+# stringent environments than integration tests.
+#
+# Interface to module:
+# ENABLE_INTEGRATION_TESTS:   used in makefiles to conditionally build tests
+# enable_integration_tests:   used in configure.ac for additional configuration
+# --enable-integration-tests: 'yes' user instructs the module to build tests
+#                             'no' user instructs the module not to build tests
+# parm1:                      specify the default value, yes or no.
+#
+AC_DEFUN([XORG_ENABLE_INTEGRATION_TESTS],[
+AC_REQUIRE([XORG_MEMORY_CHECK_FLAGS])
+m4_define([_defopt], m4_default([$1], [auto]))
+AC_ARG_ENABLE(integration-tests, AS_HELP_STRING([--enable-integration-tests],
+       [Enable building integration test cases (default: ]_defopt[)]),
+       [enable_integration_tests=$enableval],
+       [enable_integration_tests=]_defopt)
+m4_undefine([_defopt])
+AM_CONDITIONAL([ENABLE_INTEGRATION_TESTS],
+       [test "x$enable_integration_tests" != xno])
+AC_MSG_CHECKING([whether to build unit test cases])
+AC_MSG_RESULT([$enable_integration_tests])
+]) # XORG_ENABLE_INTEGRATION_TESTS
+
+# XORG_WITH_GLIB([MIN-VERSION], [DEFAULT])
+# ----------------------------------------
+# Minimum version: 1.13.0
+#
+# GLib is a library which provides advanced data structures and functions.
+# This macro enables a module to test for the presence of Glib.
+#
+# When used with ENABLE_UNIT_TESTS, it is assumed GLib is used for unit testing.
+# Otherwise the value of $enable_unit_tests is blank.
+#
+# Please see XORG_ENABLE_INTEGRATION_TESTS for integration test support. Unit
+# test support usually requires less dependencies and may be built and run under
+# less stringent environments than integration tests.
+#
+# Interface to module:
+# HAVE_GLIB: used in makefiles to conditionally build targets
+# with_glib: used in configure.ac to know if GLib has been found
+# --with-glib: 'yes' user instructs the module to use glib
+#              'no' user instructs the module not to use glib
+#
+AC_DEFUN([XORG_WITH_GLIB],[
+AC_REQUIRE([PKG_PROG_PKG_CONFIG])
+m4_define([_defopt], m4_default([$2], [auto]))
+AC_ARG_WITH(glib, AS_HELP_STRING([--with-glib],
+       [Use GLib library for unit testing (default: ]_defopt[)]),
+       [with_glib=$withval], [with_glib=]_defopt)
+m4_undefine([_defopt])
+
+have_glib=no
+# Do not probe GLib if user explicitly disabled unit testing
+if test "x$enable_unit_tests" != x"no"; then
+  # Do not probe GLib if user explicitly disabled it
+  if test "x$with_glib" != x"no"; then
+    m4_ifval(
+      [$1],
+      [PKG_CHECK_MODULES([GLIB], [glib-2.0 >= $1], [have_glib=yes], [have_glib=no])],
+      [PKG_CHECK_MODULES([GLIB], [glib-2.0], [have_glib=yes], [have_glib=no])]
+    )
+  fi
+fi
+
+# Not having GLib when unit testing has been explicitly requested is an error
+if test "x$enable_unit_tests" = x"yes"; then
+  if test "x$have_glib" = x"no"; then
+    AC_MSG_ERROR([--enable-unit-tests=yes specified but glib-2.0 not found])
+  fi
+fi
+
+# Having unit testing disabled when GLib has been explicitly requested is an error
+if test "x$enable_unit_tests" = x"no"; then
+  if test "x$with_glib" = x"yes"; then
+    AC_MSG_ERROR([--enable-unit-tests=yes specified but glib-2.0 not found])
+  fi
+fi
+
+# Not having GLib when it has been explicitly requested is an error
+if test "x$with_glib" = x"yes"; then
+  if test "x$have_glib" = x"no"; then
+    AC_MSG_ERROR([--with-glib=yes specified but glib-2.0 not found])
+  fi
+fi
+
+AM_CONDITIONAL([HAVE_GLIB], [test "$have_glib" = yes])
+]) # XORG_WITH_GLIB
+
+# XORG_LD_WRAP([required|optional])
+# ---------------------------------
+# Minimum version: 1.13.0
+#
+# Check if linker supports -wrap, passed via compiler flags
+#
+# When used with ENABLE_UNIT_TESTS, it is assumed -wrap is used for unit testing.
+# Otherwise the value of $enable_unit_tests is blank.
+#
+# Argument added in 1.16.0 - default is "required", to match existing behavior
+# of returning an error if enable_unit_tests is yes, and ld -wrap is not
+# available, an argument of "optional" allows use when some unit tests require
+# ld -wrap and others do not.
+#
+AC_DEFUN([XORG_LD_WRAP],[
+XORG_CHECK_LINKER_FLAGS([-Wl,-wrap,exit],[have_ld_wrap=yes],[have_ld_wrap=no],
+    [AC_LANG_PROGRAM([#include <stdlib.h>
+                      void __wrap_exit(int status) { return; }],
+                     [exit(0);])])
+# Not having ld wrap when unit testing has been explicitly requested is an error
+if test "x$enable_unit_tests" = x"yes" -a "x$1" != "xoptional"; then
+  if test "x$have_ld_wrap" = x"no"; then
+    AC_MSG_ERROR([--enable-unit-tests=yes specified but ld -wrap support is not available])
+  fi
+fi
+AM_CONDITIONAL([HAVE_LD_WRAP], [test "$have_ld_wrap" = yes])
+#
+]) # XORG_LD_WRAP
+
+# XORG_CHECK_LINKER_FLAGS
+# -----------------------
+# SYNOPSIS
+#
+#   XORG_CHECK_LINKER_FLAGS(FLAGS, [ACTION-SUCCESS], [ACTION-FAILURE], [PROGRAM-SOURCE])
+#
+# DESCRIPTION
+#
+#   Check whether the given linker FLAGS work with the current language's
+#   linker, or whether they give an error.
+#
+#   ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on
+#   success/failure.
+#
+#   PROGRAM-SOURCE is the program source to link with, if needed
+#
+#   NOTE: Based on AX_CHECK_COMPILER_FLAGS.
+#
+# LICENSE
+#
+#   Copyright (c) 2009 Mike Frysinger <vapier@gentoo.org>
+#   Copyright (c) 2009 Steven G. Johnson <stevenj@alum.mit.edu>
+#   Copyright (c) 2009 Matteo Frigo
+#
+#   This program is free software: you can redistribute it and/or modify it
+#   under the terms of the GNU General Public License as published by the
+#   Free Software Foundation, either version 3 of the License, or (at your
+#   option) any later version.
+#
+#   This program is distributed in the hope that it will be useful, but
+#   WITHOUT ANY WARRANTY; without even the implied warranty of
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+#   Public License for more details.
+#
+#   You should have received a copy of the GNU General Public License along
+#   with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+#   As a special exception, the respective Autoconf Macro's copyright owner
+#   gives unlimited permission to copy, distribute and modify the configure
+#   scripts that are the output of Autoconf when processing the Macro. You
+#   need not follow the terms of the GNU General Public License when using
+#   or distributing such scripts, even though portions of the text of the
+#   Macro appear in them. The GNU General Public License (GPL) does govern
+#   all other use of the material that constitutes the Autoconf Macro.
+#
+#   This special exception to the GPL applies to versions of the Autoconf
+#   Macro released by the Autoconf Archive. When you make and distribute a
+#   modified version of the Autoconf Macro, you may extend this special
+#   exception to the GPL to apply to your modified version as well.#
+AC_DEFUN([XORG_CHECK_LINKER_FLAGS],
+[AC_MSG_CHECKING([whether the linker accepts $1])
+dnl Some hackery here since AC_CACHE_VAL can't handle a non-literal varname:
+AS_LITERAL_IF([$1],
+  [AC_CACHE_VAL(AS_TR_SH(xorg_cv_linker_flags_[$1]), [
+      ax_save_FLAGS=$LDFLAGS
+      LDFLAGS="$1"
+      AC_LINK_IFELSE([m4_default([$4],[AC_LANG_PROGRAM()])],
+        AS_TR_SH(xorg_cv_linker_flags_[$1])=yes,
+        AS_TR_SH(xorg_cv_linker_flags_[$1])=no)
+      LDFLAGS=$ax_save_FLAGS])],
+  [ax_save_FLAGS=$LDFLAGS
+   LDFLAGS="$1"
+   AC_LINK_IFELSE([AC_LANG_PROGRAM()],
+     eval AS_TR_SH(xorg_cv_linker_flags_[$1])=yes,
+     eval AS_TR_SH(xorg_cv_linker_flags_[$1])=no)
+   LDFLAGS=$ax_save_FLAGS])
+eval xorg_check_linker_flags=$AS_TR_SH(xorg_cv_linker_flags_[$1])
+AC_MSG_RESULT($xorg_check_linker_flags)
+if test "x$xorg_check_linker_flags" = xyes; then
+       m4_default([$2], :)
+else
+       m4_default([$3], :)
+fi
+]) # XORG_CHECK_LINKER_FLAGS
+
+# XORG_MEMORY_CHECK_FLAGS
+# -----------------------
+# Minimum version: 1.16.0
+#
+# This macro attempts to find appropriate memory checking functionality
+# for various platforms which unit testing code may use to catch various
+# forms of memory allocation and access errors in testing.
+#
+# Interface to module:
+# XORG_MALLOC_DEBUG_ENV - environment variables to set to enable debugging
+#                         Usually added to TESTS_ENVIRONMENT in Makefile.am
+#
+# If the user sets the value of XORG_MALLOC_DEBUG_ENV, it is used verbatim.
+#
+AC_DEFUN([XORG_MEMORY_CHECK_FLAGS],[
+
+AC_REQUIRE([AC_CANONICAL_HOST])
+AC_ARG_VAR([XORG_MALLOC_DEBUG_ENV],
+           [Environment variables to enable memory checking in tests])
+
+# Check for different types of support on different platforms
+case $host_os in
+    solaris*)
+        AC_CHECK_LIB([umem], [umem_alloc],
+            [malloc_debug_env='LD_PRELOAD=libumem.so UMEM_DEBUG=default'])
+        ;;
+    *-gnu*) # GNU libc - Value is used as a single byte bit pattern,
+        # both directly and inverted, so should not be 0 or 255.
+        malloc_debug_env='MALLOC_PERTURB_=15'
+        ;;
+    darwin*)
+        malloc_debug_env='MallocPreScribble=1 MallocScribble=1 DYLD_INSERT_LIBRARIES=/usr/lib/libgmalloc.dylib'
+        ;;
+    *bsd*)
+        malloc_debug_env='MallocPreScribble=1 MallocScribble=1'
+        ;;
+esac
+
+# User supplied flags override default flags
+if test "x$XORG_MALLOC_DEBUG_ENV" != "x"; then
+    malloc_debug_env="$XORG_MALLOC_DEBUG_ENV"
+fi
+
+AC_SUBST([XORG_MALLOC_DEBUG_ENV],[$malloc_debug_env])
+]) # XORG_WITH_LINT
+
 # XORG_CHECK_MALLOC_ZERO
 # ----------------------
 # Minimum version: 1.0.0
@@ -1281,59 +10225,300 @@ AM_CONDITIONAL(MAKE_LINT_LIB, [test x$make_lint_lib != xno])
 
 ]) # XORG_LINT_LIBRARY
 
+# XORG_COMPILER_BRAND
+# -------------------
+# Minimum version: 1.14.0
+#
+# Checks for various brands of compilers and sets flags as appropriate:
+#   GNU gcc - relies on AC_PROG_CC (via AC_PROG_CC_C99) to set GCC to "yes"
+#   GNU g++ - relies on AC_PROG_CXX to set GXX to "yes"
+#   clang compiler - sets CLANGCC to "yes"
+#   Intel compiler - sets INTELCC to "yes"
+#   Sun/Oracle Solaris Studio cc - sets SUNCC to "yes"
+#
+AC_DEFUN([XORG_COMPILER_BRAND], [
+AC_LANG_CASE(
+       [C], [
+               AC_REQUIRE([AC_PROG_CC_C99])
+       ],
+       [C++], [
+               AC_REQUIRE([AC_PROG_CXX])
+       ]
+)
+AC_CHECK_DECL([__clang__], [CLANGCC="yes"], [CLANGCC="no"])
+AC_CHECK_DECL([__INTEL_COMPILER], [INTELCC="yes"], [INTELCC="no"])
+AC_CHECK_DECL([__SUNPRO_C], [SUNCC="yes"], [SUNCC="no"])
+]) # XORG_COMPILER_BRAND
+
+# XORG_TESTSET_CFLAG(<variable>, <flag>, [<alternative flag>, ...])
+# ---------------
+# Minimum version: 1.16.0
+#
+# Test if the compiler works when passed the given flag as a command line argument.
+# If it succeeds, the flag is appeneded to the given variable.  If not, it tries the
+# next flag in the list until there are no more options.
+#
+# Note that this does not guarantee that the compiler supports the flag as some
+# compilers will simply ignore arguments that they do not understand, but we do
+# attempt to weed out false positives by using -Werror=unknown-warning-option and
+# -Werror=unused-command-line-argument
+#
+AC_DEFUN([XORG_TESTSET_CFLAG], [
+m4_if([$#], 0, [m4_fatal([XORG_TESTSET_CFLAG was given with an unsupported number of arguments])])
+m4_if([$#], 1, [m4_fatal([XORG_TESTSET_CFLAG was given with an unsupported number of arguments])])
+
+AC_LANG_COMPILER_REQUIRE
+
+AC_LANG_CASE(
+       [C], [
+               AC_REQUIRE([AC_PROG_CC_C99])
+               define([PREFIX], [C])
+               define([CACHE_PREFIX], [cc])
+               define([COMPILER], [$CC])
+       ],
+       [C++], [
+               define([PREFIX], [CXX])
+               define([CACHE_PREFIX], [cxx])
+               define([COMPILER], [$CXX])
+       ]
+)
+
+[xorg_testset_save_]PREFIX[FLAGS]="$PREFIX[FLAGS]"
+
+if test "x$[xorg_testset_]CACHE_PREFIX[_unknown_warning_option]" = "x" ; then
+       PREFIX[FLAGS]="$PREFIX[FLAGS] -Werror=unknown-warning-option"
+       AC_CACHE_CHECK([if ]COMPILER[ supports -Werror=unknown-warning-option],
+                       [xorg_cv_]CACHE_PREFIX[_flag_unknown_warning_option],
+                       AC_COMPILE_IFELSE([AC_LANG_SOURCE([int i;])],
+                                         [xorg_cv_]CACHE_PREFIX[_flag_unknown_warning_option=yes],
+                                         [xorg_cv_]CACHE_PREFIX[_flag_unknown_warning_option=no]))
+       [xorg_testset_]CACHE_PREFIX[_unknown_warning_option]=$[xorg_cv_]CACHE_PREFIX[_flag_unknown_warning_option]
+       PREFIX[FLAGS]="$[xorg_testset_save_]PREFIX[FLAGS]"
+fi
+
+if test "x$[xorg_testset_]CACHE_PREFIX[_unused_command_line_argument]" = "x" ; then
+       if test "x$[xorg_testset_]CACHE_PREFIX[_unknown_warning_option]" = "xyes" ; then
+               PREFIX[FLAGS]="$PREFIX[FLAGS] -Werror=unknown-warning-option"
+       fi
+       PREFIX[FLAGS]="$PREFIX[FLAGS] -Werror=unused-command-line-argument"
+       AC_CACHE_CHECK([if ]COMPILER[ supports -Werror=unused-command-line-argument],
+                       [xorg_cv_]CACHE_PREFIX[_flag_unused_command_line_argument],
+                       AC_COMPILE_IFELSE([AC_LANG_SOURCE([int i;])],
+                                         [xorg_cv_]CACHE_PREFIX[_flag_unused_command_line_argument=yes],
+                                         [xorg_cv_]CACHE_PREFIX[_flag_unused_command_line_argument=no]))
+       [xorg_testset_]CACHE_PREFIX[_unused_command_line_argument]=$[xorg_cv_]CACHE_PREFIX[_flag_unused_command_line_argument]
+       PREFIX[FLAGS]="$[xorg_testset_save_]PREFIX[FLAGS]"
+fi
+
+found="no"
+m4_foreach([flag], m4_cdr($@), [
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       PREFIX[FLAGS]="$PREFIX[FLAGS] -Werror=unknown-warning-option"
+               fi
+
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       PREFIX[FLAGS]="$PREFIX[FLAGS] -Werror=unused-command-line-argument"
+               fi
+
+               PREFIX[FLAGS]="$PREFIX[FLAGS] ]flag["
+
+dnl Some hackery here since AC_CACHE_VAL can't handle a non-literal varname
+               AC_MSG_CHECKING([if ]COMPILER[ supports]flag[])
+               cacheid=AS_TR_SH([xorg_cv_]CACHE_PREFIX[_flag_]flag[])
+               AC_CACHE_VAL($cacheid,
+                            [AC_LINK_IFELSE([AC_LANG_PROGRAM([int i;])],
+                                            [eval $cacheid=yes],
+                                            [eval $cacheid=no])])
+
+               PREFIX[FLAGS]="$[xorg_testset_save_]PREFIX[FLAGS]"
+
+               eval supported=\$$cacheid
+               AC_MSG_RESULT([$supported])
+               if test "$supported" = "yes" ; then
+                       $1="$$1 ]flag["
+                       found="yes"
+               fi
+       fi
+])
+]) # XORG_TESTSET_CFLAG
+
+# XORG_COMPILER_FLAGS
+# ---------------
+# Minimum version: 1.16.0
+#
+# Defines BASE_CFLAGS or BASE_CXXFLAGS to contain a set of command line
+# arguments supported by the selected compiler which do NOT alter the generated
+# code.  These arguments will cause the compiler to print various warnings
+# during compilation AND turn a conservative set of warnings into errors.
+#
+# The set of flags supported by BASE_CFLAGS and BASE_CXXFLAGS will grow in
+# future versions of util-macros as options are added to new compilers.
+#
+AC_DEFUN([XORG_COMPILER_FLAGS], [
+AC_REQUIRE([XORG_COMPILER_BRAND])
+
+AC_ARG_ENABLE(selective-werror,
+              AS_HELP_STRING([--disable-selective-werror],
+                             [Turn off selective compiler errors. (default: enabled)]),
+              [SELECTIVE_WERROR=$enableval],
+              [SELECTIVE_WERROR=yes])
+
+AC_LANG_CASE(
+        [C], [
+                define([PREFIX], [C])
+        ],
+        [C++], [
+                define([PREFIX], [CXX])
+        ]
+)
+# -v is too short to test reliably with XORG_TESTSET_CFLAG
+if test "x$SUNCC" = "xyes"; then
+    [BASE_]PREFIX[FLAGS]="-v"
+else
+    [BASE_]PREFIX[FLAGS]=""
+fi
+
+# This chunk of warnings were those that existed in the legacy CWARNFLAGS
+XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wall])
+XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wpointer-arith])
+XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wmissing-declarations])
+XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wformat=2], [-Wformat])
+
+AC_LANG_CASE(
+       [C], [
+               XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wstrict-prototypes])
+               XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wmissing-prototypes])
+               XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wnested-externs])
+               XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wbad-function-cast])
+               XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wold-style-definition])
+               XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wdeclaration-after-statement])
+       ]
+)
+
+# This chunk adds additional warnings that could catch undesired effects.
+XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wunused])
+XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wuninitialized])
+XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wshadow])
+XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wcast-qual])
+XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wmissing-noreturn])
+XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wmissing-format-attribute])
+XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wredundant-decls])
+
+# These are currently disabled because they are noisy.  They will be enabled
+# in the future once the codebase is sufficiently modernized to silence
+# them.  For now, I don't want them to drown out the other warnings.
+# XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wlogical-op])
+# XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wparentheses])
+# XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wcast-align])
+
+# Turn some warnings into errors, so we don't accidently get successful builds
+# when there are problems that should be fixed.
+
+if test "x$SELECTIVE_WERROR" = "xyes" ; then
+XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=implicit], [-errwarn=E_NO_EXPLICIT_TYPE_GIVEN -errwarn=E_NO_IMPLICIT_DECL_ALLOWED])
+XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=nonnull])
+XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=init-self])
+XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=main])
+XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=missing-braces])
+XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=sequence-point])
+XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=return-type], [-errwarn=E_FUNC_HAS_NO_RETURN_STMT])
+XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=trigraphs])
+XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=array-bounds])
+XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=write-strings])
+XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=address])
+XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=int-to-pointer-cast], [-errwarn=E_BAD_PTR_INT_COMBINATION])
+XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Werror=pointer-to-int-cast]) # Also -errwarn=E_BAD_PTR_INT_COMBINATION
+else
+AC_MSG_WARN([You have chosen not to turn some select compiler warnings into errors.  This should not be necessary.  Please report why you needed to do so in a bug report at $PACKAGE_BUGREPORT])
+XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wimplicit])
+XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wnonnull])
+XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Winit-self])
+XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wmain])
+XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wmissing-braces])
+XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wsequence-point])
+XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wreturn-type])
+XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wtrigraphs])
+XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Warray-bounds])
+XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wwrite-strings])
+XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Waddress])
+XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wint-to-pointer-cast])
+XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wpointer-to-int-cast])
+fi
+
+AC_SUBST([BASE_]PREFIX[FLAGS])
+]) # XORG_COMPILER_FLAGS
+
 # XORG_CWARNFLAGS
 # ---------------
 # Minimum version: 1.2.0
+# Deprecated since: 1.16.0 (Use XORG_COMPILER_FLAGS instead)
 #
 # Defines CWARNFLAGS to enable C compiler warnings.
 #
+# This function is deprecated because it defines -fno-strict-aliasing
+# which alters the code generated by the compiler.  If -fno-strict-aliasing
+# is needed, then it should be added explicitly in the module when
+# it is updated to use BASE_CFLAGS.
+#
 AC_DEFUN([XORG_CWARNFLAGS], [
-AC_REQUIRE([AC_PROG_CC_C99])
-if  test "x$GCC" = xyes ; then
-    CWARNFLAGS="-Wall -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes \
--Wmissing-declarations -Wnested-externs -fno-strict-aliasing \
--Wbad-function-cast -Wformat=2"
-    case `$CC -dumpversion` in
-    3.4.* | 4.*)
-       CWARNFLAGS="$CWARNFLAGS -Wold-style-definition -Wdeclaration-after-statement"
-       ;;
-    esac
-else
-    AC_CHECK_DECL([__SUNPRO_C], [SUNCC="yes"], [SUNCC="no"])
-    if test "x$SUNCC" = "xyes"; then
-       CWARNFLAGS="-v"
-    fi
-fi
-AC_SUBST(CWARNFLAGS)
+AC_REQUIRE([XORG_COMPILER_FLAGS])
+AC_REQUIRE([XORG_COMPILER_BRAND])
+AC_LANG_CASE(
+       [C], [
+               CWARNFLAGS="$BASE_CFLAGS"
+               if  test "x$GCC" = xyes ; then
+                   CWARNFLAGS="$CWARNFLAGS -fno-strict-aliasing"
+               fi
+               AC_SUBST(CWARNFLAGS)
+       ]
+)
 ]) # XORG_CWARNFLAGS
 
 # XORG_STRICT_OPTION
 # -----------------------
 # Minimum version: 1.3.0
 #
-# Add configure option to enable strict compilation
+# Add configure option to enable strict compilation flags, such as treating
+# warnings as fatal errors.
+# If --enable-strict-compilation is passed to configure, adds strict flags to
+# $BASE_CFLAGS or $BASE_CXXFLAGS and the deprecated $CWARNFLAGS.
+#
+# Starting in 1.14.0 also exports $STRICT_CFLAGS for use in other tests or
+# when strict compilation is unconditionally desired.
 AC_DEFUN([XORG_STRICT_OPTION], [
-# If the module's configure.ac calls AC_PROG_CC later on, CC gets set to C89
-AC_REQUIRE([AC_PROG_CC_C99])
 AC_REQUIRE([XORG_CWARNFLAGS])
+AC_REQUIRE([XORG_COMPILER_FLAGS])
 
 AC_ARG_ENABLE(strict-compilation,
                          AS_HELP_STRING([--enable-strict-compilation],
                          [Enable all warnings from compiler and make them errors (default: disabled)]),
                          [STRICT_COMPILE=$enableval], [STRICT_COMPILE=no])
+
+AC_LANG_CASE(
+        [C], [
+                define([PREFIX], [C])
+        ],
+        [C++], [
+                define([PREFIX], [CXX])
+        ]
+)
+
+[STRICT_]PREFIX[FLAGS]=""
+XORG_TESTSET_CFLAG([[STRICT_]PREFIX[FLAGS]], [-pedantic])
+XORG_TESTSET_CFLAG([[STRICT_]PREFIX[FLAGS]], [-Werror], [-errwarn])
+
+# Earlier versions of gcc (eg: 4.2) support -Werror=attributes, but do not
+# activate it with -Werror, so we add it here explicitly.
+XORG_TESTSET_CFLAG([[STRICT_]PREFIX[FLAGS]], [-Werror=attributes])
+
 if test "x$STRICT_COMPILE" = "xyes"; then
-       AC_CHECK_DECL([__SUNPRO_C], [SUNCC="yes"], [SUNCC="no"])
-       AC_CHECK_DECL([__INTEL_COMPILER], [INTELCC="yes"], [INTELCC="no"])
-       if test "x$GCC" = xyes ; then
-               STRICT_CFLAGS="-pedantic -Werror"
-       elif test "x$SUNCC" = "xyes"; then
-               STRICT_CFLAGS="-errwarn"
-    elif test "x$INTELCC" = "xyes"; then
-               STRICT_CFLAGS="-Werror"
-       fi
+    [BASE_]PREFIX[FLAGS]="$[BASE_]PREFIX[FLAGS] $[STRICT_]PREFIX[FLAGS]"
+    AC_LANG_CASE([C], [CWARNFLAGS="$CWARNFLAGS $STRICT_CFLAGS"])
 fi
-CWARNFLAGS="$CWARNFLAGS $STRICT_CFLAGS"
-AC_SUBST([CWARNFLAGS])
+AC_SUBST([STRICT_]PREFIX[FLAGS])
+AC_SUBST([BASE_]PREFIX[FLAGS])
+AC_LANG_CASE([C], AC_SUBST([CWARNFLAGS]))
 ]) # XORG_STRICT_OPTION
 
 # XORG_DEFAULT_OPTIONS
@@ -1344,6 +10529,7 @@ AC_SUBST([CWARNFLAGS])
 #
 AC_DEFUN([XORG_DEFAULT_OPTIONS], [
 AC_REQUIRE([AC_PROG_INSTALL])
+XORG_COMPILER_FLAGS
 XORG_CWARNFLAGS
 XORG_STRICT_OPTION
 XORG_RELEASE_VERSION
@@ -1485,12 +10671,15 @@ AC_DEFUN([XORG_DRIVER_CHECK_EXT],[
        fi
 ])
 
-# Copyright (C) 2002, 2003, 2005, 2006, 2007, 2008  Free Software Foundation, Inc.
+# Copyright (C) 2002, 2003, 2005, 2006, 2007, 2008, 2011 Free Software
+# Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
 
+# serial 1
+
 # AM_AUTOMAKE_VERSION(VERSION)
 # ----------------------------
 # Automake X.Y traces this macro to ensure aclocal.m4 has been
@@ -1500,7 +10689,7 @@ AC_DEFUN([AM_AUTOMAKE_VERSION],
 [am__api_version='1.11'
 dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to
 dnl require some minimum version.  Point them to the right macro.
-m4_if([$1], [1.11.1], [],
+m4_if([$1], [1.11.6], [],
       [AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl
 ])
 
@@ -1516,19 +10705,21 @@ m4_define([_AM_AUTOCONF_VERSION], [])
 # Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced.
 # This function is AC_REQUIREd by AM_INIT_AUTOMAKE.
 AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION],
-[AM_AUTOMAKE_VERSION([1.11.1])dnl
+[AM_AUTOMAKE_VERSION([1.11.6])dnl
 m4_ifndef([AC_AUTOCONF_VERSION],
   [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
 _AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))])
 
 # AM_AUX_DIR_EXPAND                                         -*- Autoconf -*-
 
-# Copyright (C) 2001, 2003, 2005  Free Software Foundation, Inc.
+# Copyright (C) 2001, 2003, 2005, 2011 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
 
+# serial 1
+
 # For projects using AC_CONFIG_AUX_DIR([foo]), Autoconf sets
 # $ac_aux_dir to `$srcdir/foo'.  In other projects, it is set to
 # `$srcdir', `$srcdir/..', or `$srcdir/../..'.
@@ -1610,14 +10801,14 @@ AC_CONFIG_COMMANDS_PRE(
 Usually this means the macro was only invoked conditionally.]])
 fi])])
 
-# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2009
-# Free Software Foundation, Inc.
+# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2009,
+# 2010, 2011 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
 
-# serial 10
+# serial 12
 
 # There are a few dirty hacks below to avoid letting `AC_PROG_CC' be
 # written in clear, in which case automake, when reading aclocal.m4,
@@ -1657,6 +10848,7 @@ AC_CACHE_CHECK([dependency style of $depcc],
   # instance it was reported that on HP-UX the gcc test will end up
   # making a dummy file named `D' -- because `-MD' means `put the output
   # in D'.
+  rm -rf conftest.dir
   mkdir conftest.dir
   # Copy depcomp to subdir because otherwise we won't find it if we're
   # using a relative directory.
@@ -1721,7 +10913,7 @@ AC_CACHE_CHECK([dependency style of $depcc],
        break
       fi
       ;;
-    msvisualcpp | msvcmsys)
+    msvc7 | msvc7msys | msvisualcpp | msvcmsys)
       # This compiler won't grok `-c -o', but also, the minuso test has
       # not run yet.  These depmodes are late enough in the game, and
       # so weak that their functioning should not be impacted.
@@ -1786,10 +10978,13 @@ AC_DEFUN([AM_DEP_TRACK],
 if test "x$enable_dependency_tracking" != xno; then
   am_depcomp="$ac_aux_dir/depcomp"
   AMDEPBACKSLASH='\'
+  am__nodep='_no'
 fi
 AM_CONDITIONAL([AMDEP], [test "x$enable_dependency_tracking" != xno])
 AC_SUBST([AMDEPBACKSLASH])dnl
 _AM_SUBST_NOTMAKE([AMDEPBACKSLASH])dnl
+AC_SUBST([am__nodep])dnl
+_AM_SUBST_NOTMAKE([am__nodep])dnl
 ])
 
 # Generate code to set up dependency tracking.              -*- Autoconf -*-
@@ -2011,12 +11206,15 @@ for _am_header in $config_headers :; do
 done
 echo "timestamp for $_am_arg" >`AS_DIRNAME(["$_am_arg"])`/stamp-h[]$_am_stamp_count])
 
-# Copyright (C) 2001, 2003, 2005, 2008  Free Software Foundation, Inc.
+# Copyright (C) 2001, 2003, 2005, 2008, 2011 Free Software Foundation,
+# Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
 
+# serial 1
+
 # AM_PROG_INSTALL_SH
 # ------------------
 # Define $install_sh.
@@ -2056,8 +11254,8 @@ AC_SUBST([am__leading_dot])])
 # Add --enable-maintainer-mode option to configure.         -*- Autoconf -*-
 # From Jim Meyering
 
-# Copyright (C) 1996, 1998, 2000, 2001, 2002, 2003, 2004, 2005, 2008
-# Free Software Foundation, Inc.
+# Copyright (C) 1996, 1998, 2000, 2001, 2002, 2003, 2004, 2005, 2008,
+# 2011 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -2077,7 +11275,7 @@ AC_DEFUN([AM_MAINTAINER_MODE],
        [disable], [m4_define([am_maintainer_other], [enable])],
        [m4_define([am_maintainer_other], [enable])
         m4_warn([syntax], [unexpected argument to AM@&t@_MAINTAINER_MODE: $1])])
-AC_MSG_CHECKING([whether to am_maintainer_other maintainer-specific portions of Makefiles])
+AC_MSG_CHECKING([whether to enable maintainer-specific portions of Makefiles])
   dnl maintainer-mode's default is 'disable' unless 'enable' is passed
   AC_ARG_ENABLE([maintainer-mode],
 [  --][am_maintainer_other][-maintainer-mode  am_maintainer_other make rules and dependencies not useful
@@ -2188,12 +11386,15 @@ else
 fi
 ])
 
-# Copyright (C) 2003, 2004, 2005, 2006  Free Software Foundation, Inc.
+# Copyright (C) 2003, 2004, 2005, 2006, 2011 Free Software Foundation,
+# Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
 
+# serial 1
+
 # AM_PROG_MKDIR_P
 # ---------------
 # Check for `mkdir -p'.
@@ -2216,13 +11417,14 @@ esac
 
 # Helper functions for option handling.                     -*- Autoconf -*-
 
-# Copyright (C) 2001, 2002, 2003, 2005, 2008  Free Software Foundation, Inc.
+# Copyright (C) 2001, 2002, 2003, 2005, 2008, 2010 Free Software
+# Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
 
-# serial 4
+# serial 5
 
 # _AM_MANGLE_OPTION(NAME)
 # -----------------------
@@ -2230,13 +11432,13 @@ AC_DEFUN([_AM_MANGLE_OPTION],
 [[_AM_OPTION_]m4_bpatsubst($1, [[^a-zA-Z0-9_]], [_])])
 
 # _AM_SET_OPTION(NAME)
-# ------------------------------
+# --------------------
 # Set option NAME.  Presently that only means defining a flag for this option.
 AC_DEFUN([_AM_SET_OPTION],
 [m4_define(_AM_MANGLE_OPTION([$1]), 1)])
 
 # _AM_SET_OPTIONS(OPTIONS)
-# ----------------------------------
+# ------------------------
 # OPTIONS is a space-separated list of Automake options.
 AC_DEFUN([_AM_SET_OPTIONS],
 [m4_foreach_w([_AM_Option], [$1], [_AM_SET_OPTION(_AM_Option)])])
@@ -2312,13 +11514,13 @@ Check your system clock])
 fi
 AC_MSG_RESULT(yes)])
 
-# Copyright (C) 2009  Free Software Foundation, Inc.
+# Copyright (C) 2009, 2011  Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
 
-# serial 1
+# serial 2
 
 # AM_SILENT_RULES([DEFAULT])
 # --------------------------
@@ -2333,18 +11535,50 @@ yes) AM_DEFAULT_VERBOSITY=0;;
 no)  AM_DEFAULT_VERBOSITY=1;;
 *)   AM_DEFAULT_VERBOSITY=m4_if([$1], [yes], [0], [1]);;
 esac
+dnl
+dnl A few `make' implementations (e.g., NonStop OS and NextStep)
+dnl do not support nested variable expansions.
+dnl See automake bug#9928 and bug#10237.
+am_make=${MAKE-make}
+AC_CACHE_CHECK([whether $am_make supports nested variables],
+   [am_cv_make_support_nested_variables],
+   [if AS_ECHO([['TRUE=$(BAR$(V))
+BAR0=false
+BAR1=true
+V=1
+am__doit:
+       @$(TRUE)
+.PHONY: am__doit']]) | $am_make -f - >/dev/null 2>&1; then
+  am_cv_make_support_nested_variables=yes
+else
+  am_cv_make_support_nested_variables=no
+fi])
+if test $am_cv_make_support_nested_variables = yes; then
+  dnl Using `$V' instead of `$(V)' breaks IRIX make.
+  AM_V='$(V)'
+  AM_DEFAULT_V='$(AM_DEFAULT_VERBOSITY)'
+else
+  AM_V=$AM_DEFAULT_VERBOSITY
+  AM_DEFAULT_V=$AM_DEFAULT_VERBOSITY
+fi
+AC_SUBST([AM_V])dnl
+AM_SUBST_NOTMAKE([AM_V])dnl
+AC_SUBST([AM_DEFAULT_V])dnl
+AM_SUBST_NOTMAKE([AM_DEFAULT_V])dnl
 AC_SUBST([AM_DEFAULT_VERBOSITY])dnl
 AM_BACKSLASH='\'
 AC_SUBST([AM_BACKSLASH])dnl
 _AM_SUBST_NOTMAKE([AM_BACKSLASH])dnl
 ])
 
-# Copyright (C) 2001, 2003, 2005  Free Software Foundation, Inc.
+# Copyright (C) 2001, 2003, 2005, 2011 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
 
+# serial 1
+
 # AM_PROG_INSTALL_STRIP
 # ---------------------
 # One issue with vendor `install' (even GNU) is that you can't
 INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s"
 AC_SUBST([INSTALL_STRIP_PROGRAM])])
 
-# Copyright (C) 2006, 2008  Free Software Foundation, Inc.
+# Copyright (C) 2006, 2008, 2010 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
 
-# serial 2
+# serial 3
 
 # _AM_SUBST_NOTMAKE(VARIABLE)
 # ---------------------------
@@ -2382,13 +11616,13 @@ AC_SUBST([INSTALL_STRIP_PROGRAM])])
 AC_DEFUN([_AM_SUBST_NOTMAKE])
 
 # AM_SUBST_NOTMAKE(VARIABLE)
-# ---------------------------
+# --------------------------
 # Public sister of _AM_SUBST_NOTMAKE.
 AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)])
 
 # Check how to create a tarball.                            -*- Autoconf -*-
 
-# Copyright (C) 2004, 2005  Free Software Foundation, Inc.
+# Copyright (C) 2004, 2005, 2012 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -2410,10 +11644,11 @@ AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)])
 # a tarball read from stdin.
 #     $(am__untar) < result.tar
 AC_DEFUN([_AM_PROG_TAR],
-[# Always define AMTAR for backward compatibility.
-AM_MISSING_PROG([AMTAR], [tar])
+[# Always define AMTAR for backward compatibility.  Yes, it's still used
+# in the wild :-(  We should find a proper way to deprecate it ...
+AC_SUBST([AMTAR], ['$${TAR-tar}'])
 m4_if([$1], [v7],
-     [am__tar='${AMTAR} chof - "$$tardir"'; am__untar='${AMTAR} xf -'],
+     [am__tar='$${TAR-tar} chof - "$$tardir"' am__untar='$${TAR-tar} xf -'],
      [m4_case([$1], [ustar],, [pax],,
               [m4_fatal([Unknown tar format])])
 AC_MSG_CHECKING([how to create a $1 tar archive])
@@ -2482,8 +11717,3 @@ AC_SUBST([am__tar])
 AC_SUBST([am__untar])
 ]) # _AM_PROG_TAR
 
-m4_include([m4/libtool.m4])
-m4_include([m4/ltoptions.m4])
-m4_include([m4/ltsugar.m4])
-m4_include([m4/ltversion.m4])
-m4_include([m4/lt~obsolete.m4])
diff --git a/build-aux/config.guess b/build-aux/config.guess
deleted file mode 100755 (executable)
index c2246a4..0000000
+++ /dev/null
@@ -1,1502 +0,0 @@
-#! /bin/sh
-# Attempt to guess a canonical system name.
-#   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-#   2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
-#   Free Software Foundation, Inc.
-
-timestamp='2009-12-30'
-
-# This file is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
-# 02110-1301, USA.
-#
-# As a special exception to the GNU General Public License, if you
-# distribute this file as part of a program that contains a
-# configuration script generated by Autoconf, you may include it under
-# the same distribution terms that you use for the rest of that program.
-
-
-# Originally written by Per Bothner.  Please send patches (context
-# diff format) to <config-patches@gnu.org> and include a ChangeLog
-# entry.
-#
-# This script attempts to guess a canonical system name similar to
-# config.sub.  If it succeeds, it prints the system name on stdout, and
-# exits with 0.  Otherwise, it exits with 1.
-#
-# You can get the latest version of this script from:
-# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD
-
-me=`echo "$0" | sed -e 's,.*/,,'`
-
-usage="\
-Usage: $0 [OPTION]
-
-Output the configuration name of the system \`$me' is run on.
-
-Operation modes:
-  -h, --help         print this help, then exit
-  -t, --time-stamp   print date of last modification, then exit
-  -v, --version      print version number, then exit
-
-Report bugs and patches to <config-patches@gnu.org>."
-
-version="\
-GNU config.guess ($timestamp)
-
-Originally written by Per Bothner.
-Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free
-Software Foundation, Inc.
-
-This is free software; see the source for copying conditions.  There is NO
-warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
-
-help="
-Try \`$me --help' for more information."
-
-# Parse command line
-while test $# -gt 0 ; do
-  case $1 in
-    --time-stamp | --time* | -t )
-       echo "$timestamp" ; exit ;;
-    --version | -v )
-       echo "$version" ; exit ;;
-    --help | --h* | -h )
-       echo "$usage"; exit ;;
-    -- )     # Stop option processing
-       shift; break ;;
-    - )        # Use stdin as input.
-       break ;;
-    -* )
-       echo "$me: invalid option $1$help" >&2
-       exit 1 ;;
-    * )
-       break ;;
-  esac
-done
-
-if test $# != 0; then
-  echo "$me: too many arguments$help" >&2
-  exit 1
-fi
-
-trap 'exit 1' 1 2 15
-
-# CC_FOR_BUILD -- compiler used by this script. Note that the use of a
-# compiler to aid in system detection is discouraged as it requires
-# temporary files to be created and, as you can see below, it is a
-# headache to deal with in a portable fashion.
-
-# Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still
-# use `HOST_CC' if defined, but it is deprecated.
-
-# Portable tmp directory creation inspired by the Autoconf team.
-
-set_cc_for_build='
-trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ;
-trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ;
-: ${TMPDIR=/tmp} ;
- { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } ||
- { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } ||
- { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } ||
- { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ;
-dummy=$tmp/dummy ;
-tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ;
-case $CC_FOR_BUILD,$HOST_CC,$CC in
- ,,)    echo "int x;" > $dummy.c ;
-       for c in cc gcc c89 c99 ; do
-         if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then
-            CC_FOR_BUILD="$c"; break ;
-         fi ;
-       done ;
-       if test x"$CC_FOR_BUILD" = x ; then
-         CC_FOR_BUILD=no_compiler_found ;
-       fi
-       ;;
- ,,*)   CC_FOR_BUILD=$CC ;;
- ,*,*)  CC_FOR_BUILD=$HOST_CC ;;
-esac ; set_cc_for_build= ;'
-
-# This is needed to find uname on a Pyramid OSx when run in the BSD universe.
-# (ghazi@noc.rutgers.edu 1994-08-24)
-if (test -f /.attbin/uname) >/dev/null 2>&1 ; then
-       PATH=$PATH:/.attbin ; export PATH
-fi
-
-UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown
-UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown
-UNAME_SYSTEM=`(uname -s) 2>/dev/null`  || UNAME_SYSTEM=unknown
-UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown
-
-# Note: order is significant - the case branches are not exclusive.
-
-case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
-    *:NetBSD:*:*)
-       # NetBSD (nbsd) targets should (where applicable) match one or
-       # more of the tupples: *-*-netbsdelf*, *-*-netbsdaout*,
-       # *-*-netbsdecoff* and *-*-netbsd*.  For targets that recently
-       # switched to ELF, *-*-netbsd* would select the old
-       # object file format.  This provides both forward
-       # compatibility and a consistent mechanism for selecting the
-       # object file format.
-       #
-       # Note: NetBSD doesn't particularly care about the vendor
-       # portion of the name.  We always set it to "unknown".
-       sysctl="sysctl -n hw.machine_arch"
-       UNAME_MACHINE_ARCH=`(/sbin/$sysctl 2>/dev/null || \
-           /usr/sbin/$sysctl 2>/dev/null || echo unknown)`
-       case "${UNAME_MACHINE_ARCH}" in
-           armeb) machine=armeb-unknown ;;
-           arm*) machine=arm-unknown ;;
-           sh3el) machine=shl-unknown ;;
-           sh3eb) machine=sh-unknown ;;
-           sh5el) machine=sh5le-unknown ;;
-           *) machine=${UNAME_MACHINE_ARCH}-unknown ;;
-       esac
-       # The Operating System including object format, if it has switched
-       # to ELF recently, or will in the future.
-       case "${UNAME_MACHINE_ARCH}" in
-           arm*|i386|m68k|ns32k|sh3*|sparc|vax)
-               eval $set_cc_for_build
-               if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \
-                       | grep -q __ELF__
-               then
-                   # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout).
-                   # Return netbsd for either.  FIX?
-                   os=netbsd
-               else
-                   os=netbsdelf
-               fi
-               ;;
-           *)
-               os=netbsd
-               ;;
-       esac
-       # The OS release
-       # Debian GNU/NetBSD machines have a different userland, and
-       # thus, need a distinct triplet. However, they do not need
-       # kernel version information, so it can be replaced with a
-       # suitable tag, in the style of linux-gnu.
-       case "${UNAME_VERSION}" in
-           Debian*)
-               release='-gnu'
-               ;;
-           *)
-               release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'`
-               ;;
-       esac
-       # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM:
-       # contains redundant information, the shorter form:
-       # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used.
-       echo "${machine}-${os}${release}"
-       exit ;;
-    *:OpenBSD:*:*)
-       UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'`
-       echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE}
-       exit ;;
-    *:ekkoBSD:*:*)
-       echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE}
-       exit ;;
-    *:SolidBSD:*:*)
-       echo ${UNAME_MACHINE}-unknown-solidbsd${UNAME_RELEASE}
-       exit ;;
-    macppc:MirBSD:*:*)
-       echo powerpc-unknown-mirbsd${UNAME_RELEASE}
-       exit ;;
-    *:MirBSD:*:*)
-       echo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE}
-       exit ;;
-    alpha:OSF1:*:*)
-       case $UNAME_RELEASE in
-       *4.0)
-               UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'`
-               ;;
-       *5.*)
-               UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'`
-               ;;
-       esac
-       # According to Compaq, /usr/sbin/psrinfo has been available on
-       # OSF/1 and Tru64 systems produced since 1995.  I hope that
-       # covers most systems running today.  This code pipes the CPU
-       # types through head -n 1, so we only detect the type of CPU 0.
-       ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^  The alpha \(.*\) processor.*$/\1/p' | head -n 1`
-       case "$ALPHA_CPU_TYPE" in
-           "EV4 (21064)")
-               UNAME_MACHINE="alpha" ;;
-           "EV4.5 (21064)")
-               UNAME_MACHINE="alpha" ;;
-           "LCA4 (21066/21068)")
-               UNAME_MACHINE="alpha" ;;
-           "EV5 (21164)")
-               UNAME_MACHINE="alphaev5" ;;
-           "EV5.6 (21164A)")
-               UNAME_MACHINE="alphaev56" ;;
-           "EV5.6 (21164PC)")
-               UNAME_MACHINE="alphapca56" ;;
-           "EV5.7 (21164PC)")
-               UNAME_MACHINE="alphapca57" ;;
-           "EV6 (21264)")
-               UNAME_MACHINE="alphaev6" ;;
-           "EV6.7 (21264A)")
-               UNAME_MACHINE="alphaev67" ;;
-           "EV6.8CB (21264C)")
-               UNAME_MACHINE="alphaev68" ;;
-           "EV6.8AL (21264B)")
-               UNAME_MACHINE="alphaev68" ;;
-           "EV6.8CX (21264D)")
-               UNAME_MACHINE="alphaev68" ;;
-           "EV6.9A (21264/EV69A)")
-               UNAME_MACHINE="alphaev69" ;;
-           "EV7 (21364)")
-               UNAME_MACHINE="alphaev7" ;;
-           "EV7.9 (21364A)")
-               UNAME_MACHINE="alphaev79" ;;
-       esac
-       # A Pn.n version is a patched version.
-       # A Vn.n version is a released version.
-       # A Tn.n version is a released field test version.
-       # A Xn.n version is an unreleased experimental baselevel.
-       # 1.2 uses "1.2" for uname -r.
-       echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
-       exit ;;
-    Alpha\ *:Windows_NT*:*)
-       # How do we know it's Interix rather than the generic POSIX subsystem?
-       # Should we change UNAME_MACHINE based on the output of uname instead
-       # of the specific Alpha model?
-       echo alpha-pc-interix
-       exit ;;
-    21064:Windows_NT:50:3)
-       echo alpha-dec-winnt3.5
-       exit ;;
-    Amiga*:UNIX_System_V:4.0:*)
-       echo m68k-unknown-sysv4
-       exit ;;
-    *:[Aa]miga[Oo][Ss]:*:*)
-       echo ${UNAME_MACHINE}-unknown-amigaos
-       exit ;;
-    *:[Mm]orph[Oo][Ss]:*:*)
-       echo ${UNAME_MACHINE}-unknown-morphos
-       exit ;;
-    *:OS/390:*:*)
-       echo i370-ibm-openedition
-       exit ;;
-    *:z/VM:*:*)
-       echo s390-ibm-zvmoe
-       exit ;;
-    *:OS400:*:*)
-        echo powerpc-ibm-os400
-       exit ;;
-    arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*)
-       echo arm-acorn-riscix${UNAME_RELEASE}
-       exit ;;
-    arm:riscos:*:*|arm:RISCOS:*:*)
-       echo arm-unknown-riscos
-       exit ;;
-    SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*)
-       echo hppa1.1-hitachi-hiuxmpp
-       exit ;;
-    Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*)
-       # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE.
-       if test "`(/bin/universe) 2>/dev/null`" = att ; then
-               echo pyramid-pyramid-sysv3
-       else
-               echo pyramid-pyramid-bsd
-       fi
-       exit ;;
-    NILE*:*:*:dcosx)
-       echo pyramid-pyramid-svr4
-       exit ;;
-    DRS?6000:unix:4.0:6*)
-       echo sparc-icl-nx6
-       exit ;;
-    DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*)
-       case `/usr/bin/uname -p` in
-           sparc) echo sparc-icl-nx7; exit ;;
-       esac ;;
-    s390x:SunOS:*:*)
-       echo ${UNAME_MACHINE}-ibm-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
-       exit ;;
-    sun4H:SunOS:5.*:*)
-       echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
-       exit ;;
-    sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*)
-       echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
-       exit ;;
-    i86pc:AuroraUX:5.*:* | i86xen:AuroraUX:5.*:*)
-       echo i386-pc-auroraux${UNAME_RELEASE}
-       exit ;;
-    i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*)
-       eval $set_cc_for_build
-       SUN_ARCH="i386"
-       # If there is a compiler, see if it is configured for 64-bit objects.
-       # Note that the Sun cc does not turn __LP64__ into 1 like gcc does.
-       # This test works for both compilers.
-       if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then
-           if (echo '#ifdef __amd64'; echo IS_64BIT_ARCH; echo '#endif') | \
-               (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \
-               grep IS_64BIT_ARCH >/dev/null
-           then
-               SUN_ARCH="x86_64"
-           fi
-       fi
-       echo ${SUN_ARCH}-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
-       exit ;;
-    sun4*:SunOS:6*:*)
-       # According to config.sub, this is the proper way to canonicalize
-       # SunOS6.  Hard to guess exactly what SunOS6 will be like, but
-       # it's likely to be more like Solaris than SunOS4.
-       echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
-       exit ;;
-    sun4*:SunOS:*:*)
-       case "`/usr/bin/arch -k`" in
-           Series*|S4*)
-               UNAME_RELEASE=`uname -v`
-               ;;
-       esac
-       # Japanese Language versions have a version number like `4.1.3-JL'.
-       echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'`
-       exit ;;
-    sun3*:SunOS:*:*)
-       echo m68k-sun-sunos${UNAME_RELEASE}
-       exit ;;
-    sun*:*:4.2BSD:*)
-       UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null`
-       test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3
-       case "`/bin/arch`" in
-           sun3)
-               echo m68k-sun-sunos${UNAME_RELEASE}
-               ;;
-           sun4)
-               echo sparc-sun-sunos${UNAME_RELEASE}
-               ;;
-       esac
-       exit ;;
-    aushp:SunOS:*:*)
-       echo sparc-auspex-sunos${UNAME_RELEASE}
-       exit ;;
-    # The situation for MiNT is a little confusing.  The machine name
-    # can be virtually everything (everything which is not
-    # "atarist" or "atariste" at least should have a processor
-    # > m68000).  The system name ranges from "MiNT" over "FreeMiNT"
-    # to the lowercase version "mint" (or "freemint").  Finally
-    # the system name "TOS" denotes a system which is actually not
-    # MiNT.  But MiNT is downward compatible to TOS, so this should
-    # be no problem.
-    atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*)
-        echo m68k-atari-mint${UNAME_RELEASE}
-       exit ;;
-    atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*)
-       echo m68k-atari-mint${UNAME_RELEASE}
-        exit ;;
-    *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*)
-        echo m68k-atari-mint${UNAME_RELEASE}
-       exit ;;
-    milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*)
-        echo m68k-milan-mint${UNAME_RELEASE}
-        exit ;;
-    hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*)
-        echo m68k-hades-mint${UNAME_RELEASE}
-        exit ;;
-    *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*)
-        echo m68k-unknown-mint${UNAME_RELEASE}
-        exit ;;
-    m68k:machten:*:*)
-       echo m68k-apple-machten${UNAME_RELEASE}
-       exit ;;
-    powerpc:machten:*:*)
-       echo powerpc-apple-machten${UNAME_RELEASE}
-       exit ;;
-    RISC*:Mach:*:*)
-       echo mips-dec-mach_bsd4.3
-       exit ;;
-    RISC*:ULTRIX:*:*)
-       echo mips-dec-ultrix${UNAME_RELEASE}
-       exit ;;
-    VAX*:ULTRIX*:*:*)
-       echo vax-dec-ultrix${UNAME_RELEASE}
-       exit ;;
-    2020:CLIX:*:* | 2430:CLIX:*:*)
-       echo clipper-intergraph-clix${UNAME_RELEASE}
-       exit ;;
-    mips:*:*:UMIPS | mips:*:*:RISCos)
-       eval $set_cc_for_build
-       sed 's/^        //' << EOF >$dummy.c
-#ifdef __cplusplus
-#include <stdio.h>  /* for printf() prototype */
-       int main (int argc, char *argv[]) {
-#else
-       int main (argc, argv) int argc; char *argv[]; {
-#endif
-       #if defined (host_mips) && defined (MIPSEB)
-       #if defined (SYSTYPE_SYSV)
-         printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0);
-       #endif
-       #if defined (SYSTYPE_SVR4)
-         printf ("mips-mips-riscos%ssvr4\n", argv[1]); exit (0);
-       #endif
-       #if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD)
-         printf ("mips-mips-riscos%sbsd\n", argv[1]); exit (0);
-       #endif
-       #endif
-         exit (-1);
-       }
-EOF
-       $CC_FOR_BUILD -o $dummy $dummy.c &&
-         dummyarg=`echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` &&
-         SYSTEM_NAME=`$dummy $dummyarg` &&
-           { echo "$SYSTEM_NAME"; exit; }
-       echo mips-mips-riscos${UNAME_RELEASE}
-       exit ;;
-    Motorola:PowerMAX_OS:*:*)
-       echo powerpc-motorola-powermax
-       exit ;;
-    Motorola:*:4.3:PL8-*)
-       echo powerpc-harris-powermax
-       exit ;;
-    Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*)
-       echo powerpc-harris-powermax
-       exit ;;
-    Night_Hawk:Power_UNIX:*:*)
-       echo powerpc-harris-powerunix
-       exit ;;
-    m88k:CX/UX:7*:*)
-       echo m88k-harris-cxux7
-       exit ;;
-    m88k:*:4*:R4*)
-       echo m88k-motorola-sysv4
-       exit ;;
-    m88k:*:3*:R3*)
-       echo m88k-motorola-sysv3
-       exit ;;
-    AViiON:dgux:*:*)
-        # DG/UX returns AViiON for all architectures
-        UNAME_PROCESSOR=`/usr/bin/uname -p`
-       if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ]
-       then
-           if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \
-              [ ${TARGET_BINARY_INTERFACE}x = x ]
-           then
-               echo m88k-dg-dgux${UNAME_RELEASE}
-           else
-               echo m88k-dg-dguxbcs${UNAME_RELEASE}
-           fi
-       else
-           echo i586-dg-dgux${UNAME_RELEASE}
-       fi
-       exit ;;
-    M88*:DolphinOS:*:*)        # DolphinOS (SVR3)
-       echo m88k-dolphin-sysv3
-       exit ;;
-    M88*:*:R3*:*)
-       # Delta 88k system running SVR3
-       echo m88k-motorola-sysv3
-       exit ;;
-    XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3)
-       echo m88k-tektronix-sysv3
-       exit ;;
-    Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD)
-       echo m68k-tektronix-bsd
-       exit ;;
-    *:IRIX*:*:*)
-       echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'`
-       exit ;;
-    ????????:AIX?:[12].1:2)   # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX.
-       echo romp-ibm-aix     # uname -m gives an 8 hex-code CPU id
-       exit ;;               # Note that: echo "'`uname -s`'" gives 'AIX '
-    i*86:AIX:*:*)
-       echo i386-ibm-aix
-       exit ;;
-    ia64:AIX:*:*)
-       if [ -x /usr/bin/oslevel ] ; then
-               IBM_REV=`/usr/bin/oslevel`
-       else
-               IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE}
-       fi
-       echo ${UNAME_MACHINE}-ibm-aix${IBM_REV}
-       exit ;;
-    *:AIX:2:3)
-       if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then
-               eval $set_cc_for_build
-               sed 's/^                //' << EOF >$dummy.c
-               #include <sys/systemcfg.h>
-
-               main()
-                       {
-                       if (!__power_pc())
-                               exit(1);
-                       puts("powerpc-ibm-aix3.2.5");
-                       exit(0);
-                       }
-EOF
-               if $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy`
-               then
-                       echo "$SYSTEM_NAME"
-               else
-                       echo rs6000-ibm-aix3.2.5
-               fi
-       elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then
-               echo rs6000-ibm-aix3.2.4
-       else
-               echo rs6000-ibm-aix3.2
-       fi
-       exit ;;
-    *:AIX:*:[456])
-       IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'`
-       if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then
-               IBM_ARCH=rs6000
-       else
-               IBM_ARCH=powerpc
-       fi
-       if [ -x /usr/bin/oslevel ] ; then
-               IBM_REV=`/usr/bin/oslevel`
-       else
-               IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE}
-       fi
-       echo ${IBM_ARCH}-ibm-aix${IBM_REV}
-       exit ;;
-    *:AIX:*:*)
-       echo rs6000-ibm-aix
-       exit ;;
-    ibmrt:4.4BSD:*|romp-ibm:BSD:*)
-       echo romp-ibm-bsd4.4
-       exit ;;
-    ibmrt:*BSD:*|romp-ibm:BSD:*)            # covers RT/PC BSD and
-       echo romp-ibm-bsd${UNAME_RELEASE}   # 4.3 with uname added to
-       exit ;;                             # report: romp-ibm BSD 4.3
-    *:BOSX:*:*)
-       echo rs6000-bull-bosx
-       exit ;;
-    DPX/2?00:B.O.S.:*:*)
-       echo m68k-bull-sysv3
-       exit ;;
-    9000/[34]??:4.3bsd:1.*:*)
-       echo m68k-hp-bsd
-       exit ;;
-    hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*)
-       echo m68k-hp-bsd4.4
-       exit ;;
-    9000/[34678]??:HP-UX:*:*)
-       HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'`
-       case "${UNAME_MACHINE}" in
-           9000/31? )            HP_ARCH=m68000 ;;
-           9000/[34]?? )         HP_ARCH=m68k ;;
-           9000/[678][0-9][0-9])
-               if [ -x /usr/bin/getconf ]; then
-                   sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null`
-                    sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null`
-                    case "${sc_cpu_version}" in
-                      523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0
-                      528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1
-                      532)                      # CPU_PA_RISC2_0
-                        case "${sc_kernel_bits}" in
-                          32) HP_ARCH="hppa2.0n" ;;
-                          64) HP_ARCH="hppa2.0w" ;;
-                         '') HP_ARCH="hppa2.0" ;;   # HP-UX 10.20
-                        esac ;;
-                    esac
-               fi
-               if [ "${HP_ARCH}" = "" ]; then
-                   eval $set_cc_for_build
-                   sed 's/^              //' << EOF >$dummy.c
-
-              #define _HPUX_SOURCE
-              #include <stdlib.h>
-              #include <unistd.h>
-
-              int main ()
-              {
-              #if defined(_SC_KERNEL_BITS)
-                  long bits = sysconf(_SC_KERNEL_BITS);
-              #endif
-                  long cpu  = sysconf (_SC_CPU_VERSION);
-
-                  switch (cpu)
-               {
-               case CPU_PA_RISC1_0: puts ("hppa1.0"); break;
-               case CPU_PA_RISC1_1: puts ("hppa1.1"); break;
-               case CPU_PA_RISC2_0:
-              #if defined(_SC_KERNEL_BITS)
-                   switch (bits)
-                       {
-                       case 64: puts ("hppa2.0w"); break;
-                       case 32: puts ("hppa2.0n"); break;
-                       default: puts ("hppa2.0"); break;
-                       } break;
-              #else  /* !defined(_SC_KERNEL_BITS) */
-                   puts ("hppa2.0"); break;
-              #endif
-               default: puts ("hppa1.0"); break;
-               }
-                  exit (0);
-              }
-EOF
-                   (CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy`
-                   test -z "$HP_ARCH" && HP_ARCH=hppa
-               fi ;;
-       esac
-       if [ ${HP_ARCH} = "hppa2.0w" ]
-       then
-           eval $set_cc_for_build
-
-           # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating
-           # 32-bit code.  hppa64-hp-hpux* has the same kernel and a compiler
-           # generating 64-bit code.  GNU and HP use different nomenclature:
-           #
-           # $ CC_FOR_BUILD=cc ./config.guess
-           # => hppa2.0w-hp-hpux11.23
-           # $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess
-           # => hppa64-hp-hpux11.23
-
-           if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) |
-               grep -q __LP64__
-           then
-               HP_ARCH="hppa2.0w"
-           else
-               HP_ARCH="hppa64"
-           fi
-       fi
-       echo ${HP_ARCH}-hp-hpux${HPUX_REV}
-       exit ;;
-    ia64:HP-UX:*:*)
-       HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'`
-       echo ia64-hp-hpux${HPUX_REV}
-       exit ;;
-    3050*:HI-UX:*:*)
-       eval $set_cc_for_build
-       sed 's/^        //' << EOF >$dummy.c
-       #include <unistd.h>
-       int
-       main ()
-       {
-         long cpu = sysconf (_SC_CPU_VERSION);
-         /* The order matters, because CPU_IS_HP_MC68K erroneously returns
-            true for CPU_PA_RISC1_0.  CPU_IS_PA_RISC returns correct
-            results, however.  */
-         if (CPU_IS_PA_RISC (cpu))
-           {
-             switch (cpu)
-               {
-                 case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break;
-                 case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break;
-                 case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break;
-                 default: puts ("hppa-hitachi-hiuxwe2"); break;
-               }
-           }
-         else if (CPU_IS_HP_MC68K (cpu))
-           puts ("m68k-hitachi-hiuxwe2");
-         else puts ("unknown-hitachi-hiuxwe2");
-         exit (0);
-       }
-EOF
-       $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` &&
-               { echo "$SYSTEM_NAME"; exit; }
-       echo unknown-hitachi-hiuxwe2
-       exit ;;
-    9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* )
-       echo hppa1.1-hp-bsd
-       exit ;;
-    9000/8??:4.3bsd:*:*)
-       echo hppa1.0-hp-bsd
-       exit ;;
-    *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*)
-       echo hppa1.0-hp-mpeix
-       exit ;;
-    hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* )
-       echo hppa1.1-hp-osf
-       exit ;;
-    hp8??:OSF1:*:*)
-       echo hppa1.0-hp-osf
-       exit ;;
-    i*86:OSF1:*:*)
-       if [ -x /usr/sbin/sysversion ] ; then
-           echo ${UNAME_MACHINE}-unknown-osf1mk
-       else
-           echo ${UNAME_MACHINE}-unknown-osf1
-       fi
-       exit ;;
-    parisc*:Lites*:*:*)
-       echo hppa1.1-hp-lites
-       exit ;;
-    C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*)
-       echo c1-convex-bsd
-        exit ;;
-    C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*)
-       if getsysinfo -f scalar_acc
-       then echo c32-convex-bsd
-       else echo c2-convex-bsd
-       fi
-        exit ;;
-    C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*)
-       echo c34-convex-bsd
-        exit ;;
-    C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*)
-       echo c38-convex-bsd
-        exit ;;
-    C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*)
-       echo c4-convex-bsd
-        exit ;;
-    CRAY*Y-MP:*:*:*)
-       echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
-       exit ;;
-    CRAY*[A-Z]90:*:*:*)
-       echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \
-       | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \
-             -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \
-             -e 's/\.[^.]*$/.X/'
-       exit ;;
-    CRAY*TS:*:*:*)
-       echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
-       exit ;;
-    CRAY*T3E:*:*:*)
-       echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
-       exit ;;
-    CRAY*SV1:*:*:*)
-       echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
-       exit ;;
-    *:UNICOS/mp:*:*)
-       echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
-       exit ;;
-    F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*)
-       FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
-        FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
-        FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'`
-        echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
-        exit ;;
-    5000:UNIX_System_V:4.*:*)
-        FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
-        FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'`
-        echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
-       exit ;;
-    i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*)
-       echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE}
-       exit ;;
-    sparc*:BSD/OS:*:*)
-       echo sparc-unknown-bsdi${UNAME_RELEASE}
-       exit ;;
-    *:BSD/OS:*:*)
-       echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE}
-       exit ;;
-    *:FreeBSD:*:*)
-       case ${UNAME_MACHINE} in
-           pc98)
-               echo i386-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
-           amd64)
-               echo x86_64-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
-           *)
-               echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
-       esac
-       exit ;;
-    i*:CYGWIN*:*)
-       echo ${UNAME_MACHINE}-pc-cygwin
-       exit ;;
-    *:MINGW*:*)
-       echo ${UNAME_MACHINE}-pc-mingw32
-       exit ;;
-    i*:windows32*:*)
-       # uname -m includes "-pc" on this system.
-       echo ${UNAME_MACHINE}-mingw32
-       exit ;;
-    i*:PW*:*)
-       echo ${UNAME_MACHINE}-pc-pw32
-       exit ;;
-    *:Interix*:*)
-       case ${UNAME_MACHINE} in
-           x86)
-               echo i586-pc-interix${UNAME_RELEASE}
-               exit ;;
-           authenticamd | genuineintel | EM64T)
-               echo x86_64-unknown-interix${UNAME_RELEASE}
-               exit ;;
-           IA64)
-               echo ia64-unknown-interix${UNAME_RELEASE}
-               exit ;;
-       esac ;;
-    [345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*)
-       echo i${UNAME_MACHINE}-pc-mks
-       exit ;;
-    8664:Windows_NT:*)
-       echo x86_64-pc-mks
-       exit ;;
-    i*:Windows_NT*:* | Pentium*:Windows_NT*:*)
-       # How do we know it's Interix rather than the generic POSIX subsystem?
-       # It also conflicts with pre-2.0 versions of AT&T UWIN. Should we
-       # UNAME_MACHINE based on the output of uname instead of i386?
-       echo i586-pc-interix
-       exit ;;
-    i*:UWIN*:*)
-       echo ${UNAME_MACHINE}-pc-uwin
-       exit ;;
-    amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*)
-       echo x86_64-unknown-cygwin
-       exit ;;
-    p*:CYGWIN*:*)
-       echo powerpcle-unknown-cygwin
-       exit ;;
-    prep*:SunOS:5.*:*)
-       echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
-       exit ;;
-    *:GNU:*:*)
-       # the GNU system
-       echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'`
-       exit ;;
-    *:GNU/*:*:*)
-       # other systems with GNU libc and userland
-       echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-gnu
-       exit ;;
-    i*86:Minix:*:*)
-       echo ${UNAME_MACHINE}-pc-minix
-       exit ;;
-    alpha:Linux:*:*)
-       case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in
-         EV5)   UNAME_MACHINE=alphaev5 ;;
-         EV56)  UNAME_MACHINE=alphaev56 ;;
-         PCA56) UNAME_MACHINE=alphapca56 ;;
-         PCA57) UNAME_MACHINE=alphapca56 ;;
-         EV6)   UNAME_MACHINE=alphaev6 ;;
-         EV67)  UNAME_MACHINE=alphaev67 ;;
-         EV68*) UNAME_MACHINE=alphaev68 ;;
-        esac
-       objdump --private-headers /bin/sh | grep -q ld.so.1
-       if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi
-       echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC}
-       exit ;;
-    arm*:Linux:*:*)
-       eval $set_cc_for_build
-       if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \
-           | grep -q __ARM_EABI__
-       then
-           echo ${UNAME_MACHINE}-unknown-linux-gnu
-       else
-           echo ${UNAME_MACHINE}-unknown-linux-gnueabi
-       fi
-       exit ;;
-    avr32*:Linux:*:*)
-       echo ${UNAME_MACHINE}-unknown-linux-gnu
-       exit ;;
-    cris:Linux:*:*)
-       echo cris-axis-linux-gnu
-       exit ;;
-    crisv32:Linux:*:*)
-       echo crisv32-axis-linux-gnu
-       exit ;;
-    frv:Linux:*:*)
-       echo frv-unknown-linux-gnu
-       exit ;;
-    i*86:Linux:*:*)
-       LIBC=gnu
-       eval $set_cc_for_build
-       sed 's/^        //' << EOF >$dummy.c
-       #ifdef __dietlibc__
-       LIBC=dietlibc
-       #endif
-EOF
-       eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^LIBC'`
-       echo "${UNAME_MACHINE}-pc-linux-${LIBC}"
-       exit ;;
-    ia64:Linux:*:*)
-       echo ${UNAME_MACHINE}-unknown-linux-gnu
-       exit ;;
-    m32r*:Linux:*:*)
-       echo ${UNAME_MACHINE}-unknown-linux-gnu
-       exit ;;
-    m68*:Linux:*:*)
-       echo ${UNAME_MACHINE}-unknown-linux-gnu
-       exit ;;
-    mips:Linux:*:* | mips64:Linux:*:*)
-       eval $set_cc_for_build
-       sed 's/^        //' << EOF >$dummy.c
-       #undef CPU
-       #undef ${UNAME_MACHINE}
-       #undef ${UNAME_MACHINE}el
-       #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL)
-       CPU=${UNAME_MACHINE}el
-       #else
-       #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB)
-       CPU=${UNAME_MACHINE}
-       #else
-       CPU=
-       #endif
-       #endif
-EOF
-       eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^CPU'`
-       test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; }
-       ;;
-    or32:Linux:*:*)
-       echo or32-unknown-linux-gnu
-       exit ;;
-    padre:Linux:*:*)
-       echo sparc-unknown-linux-gnu
-       exit ;;
-    parisc64:Linux:*:* | hppa64:Linux:*:*)
-       echo hppa64-unknown-linux-gnu
-       exit ;;
-    parisc:Linux:*:* | hppa:Linux:*:*)
-       # Look for CPU level
-       case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in
-         PA7*) echo hppa1.1-unknown-linux-gnu ;;
-         PA8*) echo hppa2.0-unknown-linux-gnu ;;
-         *)    echo hppa-unknown-linux-gnu ;;
-       esac
-       exit ;;
-    ppc64:Linux:*:*)
-       echo powerpc64-unknown-linux-gnu
-       exit ;;
-    ppc:Linux:*:*)
-       echo powerpc-unknown-linux-gnu
-       exit ;;
-    s390:Linux:*:* | s390x:Linux:*:*)
-       echo ${UNAME_MACHINE}-ibm-linux
-       exit ;;
-    sh64*:Linux:*:*)
-       echo ${UNAME_MACHINE}-unknown-linux-gnu
-       exit ;;
-    sh*:Linux:*:*)
-       echo ${UNAME_MACHINE}-unknown-linux-gnu
-       exit ;;
-    sparc:Linux:*:* | sparc64:Linux:*:*)
-       echo ${UNAME_MACHINE}-unknown-linux-gnu
-       exit ;;
-    vax:Linux:*:*)
-       echo ${UNAME_MACHINE}-dec-linux-gnu
-       exit ;;
-    x86_64:Linux:*:*)
-       echo x86_64-unknown-linux-gnu
-       exit ;;
-    xtensa*:Linux:*:*)
-       echo ${UNAME_MACHINE}-unknown-linux-gnu
-       exit ;;
-    i*86:DYNIX/ptx:4*:*)
-       # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there.
-       # earlier versions are messed up and put the nodename in both
-       # sysname and nodename.
-       echo i386-sequent-sysv4
-       exit ;;
-    i*86:UNIX_SV:4.2MP:2.*)
-        # Unixware is an offshoot of SVR4, but it has its own version
-        # number series starting with 2...
-        # I am not positive that other SVR4 systems won't match this,
-       # I just have to hope.  -- rms.
-        # Use sysv4.2uw... so that sysv4* matches it.
-       echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION}
-       exit ;;
-    i*86:OS/2:*:*)
-       # If we were able to find `uname', then EMX Unix compatibility
-       # is probably installed.
-       echo ${UNAME_MACHINE}-pc-os2-emx
-       exit ;;
-    i*86:XTS-300:*:STOP)
-       echo ${UNAME_MACHINE}-unknown-stop
-       exit ;;
-    i*86:atheos:*:*)
-       echo ${UNAME_MACHINE}-unknown-atheos
-       exit ;;
-    i*86:syllable:*:*)
-       echo ${UNAME_MACHINE}-pc-syllable
-       exit ;;
-    i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.[02]*:*)
-       echo i386-unknown-lynxos${UNAME_RELEASE}
-       exit ;;
-    i*86:*DOS:*:*)
-       echo ${UNAME_MACHINE}-pc-msdosdjgpp
-       exit ;;
-    i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*)
-       UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'`
-       if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then
-               echo ${UNAME_MACHINE}-univel-sysv${UNAME_REL}
-       else
-               echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL}
-       fi
-       exit ;;
-    i*86:*:5:[678]*)
-       # UnixWare 7.x, OpenUNIX and OpenServer 6.
-       case `/bin/uname -X | grep "^Machine"` in
-           *486*)           UNAME_MACHINE=i486 ;;
-           *Pentium)        UNAME_MACHINE=i586 ;;
-           *Pent*|*Celeron) UNAME_MACHINE=i686 ;;
-       esac
-       echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION}
-       exit ;;
-    i*86:*:3.2:*)
-       if test -f /usr/options/cb.name; then
-               UNAME_REL=`sed -n 's/.*Version //p' </usr/options/cb.name`
-               echo ${UNAME_MACHINE}-pc-isc$UNAME_REL
-       elif /bin/uname -X 2>/dev/null >/dev/null ; then
-               UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')`
-               (/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486
-               (/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \
-                       && UNAME_MACHINE=i586
-               (/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \
-                       && UNAME_MACHINE=i686
-               (/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \
-                       && UNAME_MACHINE=i686
-               echo ${UNAME_MACHINE}-pc-sco$UNAME_REL
-       else
-               echo ${UNAME_MACHINE}-pc-sysv32
-       fi
-       exit ;;
-    pc:*:*:*)
-       # Left here for compatibility:
-        # uname -m prints for DJGPP always 'pc', but it prints nothing about
-        # the processor, so we play safe by assuming i586.
-       # Note: whatever this is, it MUST be the same as what config.sub
-       # prints for the "djgpp" host, or else GDB configury will decide that
-       # this is a cross-build.
-       echo i586-pc-msdosdjgpp
-        exit ;;
-    Intel:Mach:3*:*)
-       echo i386-pc-mach3
-       exit ;;
-    paragon:*:*:*)
-       echo i860-intel-osf1
-       exit ;;
-    i860:*:4.*:*) # i860-SVR4
-       if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then
-         echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4
-       else # Add other i860-SVR4 vendors below as they are discovered.
-         echo i860-unknown-sysv${UNAME_RELEASE}  # Unknown i860-SVR4
-       fi
-       exit ;;
-    mini*:CTIX:SYS*5:*)
-       # "miniframe"
-       echo m68010-convergent-sysv
-       exit ;;
-    mc68k:UNIX:SYSTEM5:3.51m)
-       echo m68k-convergent-sysv
-       exit ;;
-    M680?0:D-NIX:5.3:*)
-       echo m68k-diab-dnix
-       exit ;;
-    M68*:*:R3V[5678]*:*)
-       test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;;
-    3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0)
-       OS_REL=''
-       test -r /etc/.relid \
-       && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid`
-       /bin/uname -p 2>/dev/null | grep 86 >/dev/null \
-         && { echo i486-ncr-sysv4.3${OS_REL}; exit; }
-       /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \
-         && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;;
-    3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*)
-        /bin/uname -p 2>/dev/null | grep 86 >/dev/null \
-          && { echo i486-ncr-sysv4; exit; } ;;
-    NCR*:*:4.2:* | MPRAS*:*:4.2:*)
-       OS_REL='.3'
-       test -r /etc/.relid \
-           && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid`
-       /bin/uname -p 2>/dev/null | grep 86 >/dev/null \
-           && { echo i486-ncr-sysv4.3${OS_REL}; exit; }
-       /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \
-           && { echo i586-ncr-sysv4.3${OS_REL}; exit; }
-       /bin/uname -p 2>/dev/null | /bin/grep pteron >/dev/null \
-           && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;;
-    m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*)
-       echo m68k-unknown-lynxos${UNAME_RELEASE}
-       exit ;;
-    mc68030:UNIX_System_V:4.*:*)
-       echo m68k-atari-sysv4
-       exit ;;
-    TSUNAMI:LynxOS:2.*:*)
-       echo sparc-unknown-lynxos${UNAME_RELEASE}
-       exit ;;
-    rs6000:LynxOS:2.*:*)
-       echo rs6000-unknown-lynxos${UNAME_RELEASE}
-       exit ;;
-    PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.[02]*:*)
-       echo powerpc-unknown-lynxos${UNAME_RELEASE}
-       exit ;;
-    SM[BE]S:UNIX_SV:*:*)
-       echo mips-dde-sysv${UNAME_RELEASE}
-       exit ;;
-    RM*:ReliantUNIX-*:*:*)
-       echo mips-sni-sysv4
-       exit ;;
-    RM*:SINIX-*:*:*)
-       echo mips-sni-sysv4
-       exit ;;
-    *:SINIX-*:*:*)
-       if uname -p 2>/dev/null >/dev/null ; then
-               UNAME_MACHINE=`(uname -p) 2>/dev/null`
-               echo ${UNAME_MACHINE}-sni-sysv4
-       else
-               echo ns32k-sni-sysv
-       fi
-       exit ;;
-    PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort
-                      # says <Richard.M.Bartel@ccMail.Census.GOV>
-        echo i586-unisys-sysv4
-        exit ;;
-    *:UNIX_System_V:4*:FTX*)
-       # From Gerald Hewes <hewes@openmarket.com>.
-       # How about differentiating between stratus architectures? -djm
-       echo hppa1.1-stratus-sysv4
-       exit ;;
-    *:*:*:FTX*)
-       # From seanf@swdc.stratus.com.
-       echo i860-stratus-sysv4
-       exit ;;
-    i*86:VOS:*:*)
-       # From Paul.Green@stratus.com.
-       echo ${UNAME_MACHINE}-stratus-vos
-       exit ;;
-    *:VOS:*:*)
-       # From Paul.Green@stratus.com.
-       echo hppa1.1-stratus-vos
-       exit ;;
-    mc68*:A/UX:*:*)
-       echo m68k-apple-aux${UNAME_RELEASE}
-       exit ;;
-    news*:NEWS-OS:6*:*)
-       echo mips-sony-newsos6
-       exit ;;
-    R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*)
-       if [ -d /usr/nec ]; then
-               echo mips-nec-sysv${UNAME_RELEASE}
-       else
-               echo mips-unknown-sysv${UNAME_RELEASE}
-       fi
-        exit ;;
-    BeBox:BeOS:*:*)    # BeOS running on hardware made by Be, PPC only.
-       echo powerpc-be-beos
-       exit ;;
-    BeMac:BeOS:*:*)    # BeOS running on Mac or Mac clone, PPC only.
-       echo powerpc-apple-beos
-       exit ;;
-    BePC:BeOS:*:*)     # BeOS running on Intel PC compatible.
-       echo i586-pc-beos
-       exit ;;
-    BePC:Haiku:*:*)    # Haiku running on Intel PC compatible.
-       echo i586-pc-haiku
-       exit ;;
-    SX-4:SUPER-UX:*:*)
-       echo sx4-nec-superux${UNAME_RELEASE}
-       exit ;;
-    SX-5:SUPER-UX:*:*)
-       echo sx5-nec-superux${UNAME_RELEASE}
-       exit ;;
-    SX-6:SUPER-UX:*:*)
-       echo sx6-nec-superux${UNAME_RELEASE}
-       exit ;;
-    SX-7:SUPER-UX:*:*)
-       echo sx7-nec-superux${UNAME_RELEASE}
-       exit ;;
-    SX-8:SUPER-UX:*:*)
-       echo sx8-nec-superux${UNAME_RELEASE}
-       exit ;;
-    SX-8R:SUPER-UX:*:*)
-       echo sx8r-nec-superux${UNAME_RELEASE}
-       exit ;;
-    Power*:Rhapsody:*:*)
-       echo powerpc-apple-rhapsody${UNAME_RELEASE}
-       exit ;;
-    *:Rhapsody:*:*)
-       echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE}
-       exit ;;
-    *:Darwin:*:*)
-       UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown
-       case $UNAME_PROCESSOR in
-           i386)
-               eval $set_cc_for_build
-               if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then
-                 if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \
-                     (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \
-                     grep IS_64BIT_ARCH >/dev/null
-                 then
-                     UNAME_PROCESSOR="x86_64"
-                 fi
-               fi ;;
-           unknown) UNAME_PROCESSOR=powerpc ;;
-       esac
-       echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE}
-       exit ;;
-    *:procnto*:*:* | *:QNX:[0123456789]*:*)
-       UNAME_PROCESSOR=`uname -p`
-       if test "$UNAME_PROCESSOR" = "x86"; then
-               UNAME_PROCESSOR=i386
-               UNAME_MACHINE=pc
-       fi
-       echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE}
-       exit ;;
-    *:QNX:*:4*)
-       echo i386-pc-qnx
-       exit ;;
-    NSE-?:NONSTOP_KERNEL:*:*)
-       echo nse-tandem-nsk${UNAME_RELEASE}
-       exit ;;
-    NSR-?:NONSTOP_KERNEL:*:*)
-       echo nsr-tandem-nsk${UNAME_RELEASE}
-       exit ;;
-    *:NonStop-UX:*:*)
-       echo mips-compaq-nonstopux
-       exit ;;
-    BS2000:POSIX*:*:*)
-       echo bs2000-siemens-sysv
-       exit ;;
-    DS/*:UNIX_System_V:*:*)
-       echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE}
-       exit ;;
-    *:Plan9:*:*)
-       # "uname -m" is not consistent, so use $cputype instead. 386
-       # is converted to i386 for consistency with other x86
-       # operating systems.
-       if test "$cputype" = "386"; then
-           UNAME_MACHINE=i386
-       else
-           UNAME_MACHINE="$cputype"
-       fi
-       echo ${UNAME_MACHINE}-unknown-plan9
-       exit ;;
-    *:TOPS-10:*:*)
-       echo pdp10-unknown-tops10
-       exit ;;
-    *:TENEX:*:*)
-       echo pdp10-unknown-tenex
-       exit ;;
-    KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*)
-       echo pdp10-dec-tops20
-       exit ;;
-    XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*)
-       echo pdp10-xkl-tops20
-       exit ;;
-    *:TOPS-20:*:*)
-       echo pdp10-unknown-tops20
-       exit ;;
-    *:ITS:*:*)
-       echo pdp10-unknown-its
-       exit ;;
-    SEI:*:*:SEIUX)
-        echo mips-sei-seiux${UNAME_RELEASE}
-       exit ;;
-    *:DragonFly:*:*)
-       echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`
-       exit ;;
-    *:*VMS:*:*)
-       UNAME_MACHINE=`(uname -p) 2>/dev/null`
-       case "${UNAME_MACHINE}" in
-           A*) echo alpha-dec-vms ; exit ;;
-           I*) echo ia64-dec-vms ; exit ;;
-           V*) echo vax-dec-vms ; exit ;;
-       esac ;;
-    *:XENIX:*:SysV)
-       echo i386-pc-xenix
-       exit ;;
-    i*86:skyos:*:*)
-       echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE}` | sed -e 's/ .*$//'
-       exit ;;
-    i*86:rdos:*:*)
-       echo ${UNAME_MACHINE}-pc-rdos
-       exit ;;
-    i*86:AROS:*:*)
-       echo ${UNAME_MACHINE}-pc-aros
-       exit ;;
-esac
-
-#echo '(No uname command or uname output not recognized.)' 1>&2
-#echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2
-
-eval $set_cc_for_build
-cat >$dummy.c <<EOF
-#ifdef _SEQUENT_
-# include <sys/types.h>
-# include <sys/utsname.h>
-#endif
-main ()
-{
-#if defined (sony)
-#if defined (MIPSEB)
-  /* BFD wants "bsd" instead of "newsos".  Perhaps BFD should be changed,
-     I don't know....  */
-  printf ("mips-sony-bsd\n"); exit (0);
-#else
-#include <sys/param.h>
-  printf ("m68k-sony-newsos%s\n",
-#ifdef NEWSOS4
-          "4"
-#else
-         ""
-#endif
-         ); exit (0);
-#endif
-#endif
-
-#if defined (__arm) && defined (__acorn) && defined (__unix)
-  printf ("arm-acorn-riscix\n"); exit (0);
-#endif
-
-#if defined (hp300) && !defined (hpux)
-  printf ("m68k-hp-bsd\n"); exit (0);
-#endif
-
-#if defined (NeXT)
-#if !defined (__ARCHITECTURE__)
-#define __ARCHITECTURE__ "m68k"
-#endif
-  int version;
-  version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`;
-  if (version < 4)
-    printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version);
-  else
-    printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version);
-  exit (0);
-#endif
-
-#if defined (MULTIMAX) || defined (n16)
-#if defined (UMAXV)
-  printf ("ns32k-encore-sysv\n"); exit (0);
-#else
-#if defined (CMU)
-  printf ("ns32k-encore-mach\n"); exit (0);
-#else
-  printf ("ns32k-encore-bsd\n"); exit (0);
-#endif
-#endif
-#endif
-
-#if defined (__386BSD__)
-  printf ("i386-pc-bsd\n"); exit (0);
-#endif
-
-#if defined (sequent)
-#if defined (i386)
-  printf ("i386-sequent-dynix\n"); exit (0);
-#endif
-#if defined (ns32000)
-  printf ("ns32k-sequent-dynix\n"); exit (0);
-#endif
-#endif
-
-#if defined (_SEQUENT_)
-    struct utsname un;
-
-    uname(&un);
-
-    if (strncmp(un.version, "V2", 2) == 0) {
-       printf ("i386-sequent-ptx2\n"); exit (0);
-    }
-    if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */
-       printf ("i386-sequent-ptx1\n"); exit (0);
-    }
-    printf ("i386-sequent-ptx\n"); exit (0);
-
-#endif
-
-#if defined (vax)
-# if !defined (ultrix)
-#  include <sys/param.h>
-#  if defined (BSD)
-#   if BSD == 43
-      printf ("vax-dec-bsd4.3\n"); exit (0);
-#   else
-#    if BSD == 199006
-      printf ("vax-dec-bsd4.3reno\n"); exit (0);
-#    else
-      printf ("vax-dec-bsd\n"); exit (0);
-#    endif
-#   endif
-#  else
-    printf ("vax-dec-bsd\n"); exit (0);
-#  endif
-# else
-    printf ("vax-dec-ultrix\n"); exit (0);
-# endif
-#endif
-
-#if defined (alliant) && defined (i860)
-  printf ("i860-alliant-bsd\n"); exit (0);
-#endif
-
-  exit (1);
-}
-EOF
-
-$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && SYSTEM_NAME=`$dummy` &&
-       { echo "$SYSTEM_NAME"; exit; }
-
-# Apollos put the system type in the environment.
-
-test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit; }
-
-# Convex versions that predate uname can use getsysinfo(1)
-
-if [ -x /usr/convex/getsysinfo ]
-then
-    case `getsysinfo -f cpu_type` in
-    c1*)
-       echo c1-convex-bsd
-       exit ;;
-    c2*)
-       if getsysinfo -f scalar_acc
-       then echo c32-convex-bsd
-       else echo c2-convex-bsd
-       fi
-       exit ;;
-    c34*)
-       echo c34-convex-bsd
-       exit ;;
-    c38*)
-       echo c38-convex-bsd
-       exit ;;
-    c4*)
-       echo c4-convex-bsd
-       exit ;;
-    esac
-fi
-
-cat >&2 <<EOF
-$0: unable to guess system type
-
-This script, last modified $timestamp, has failed to recognize
-the operating system you are using. It is advised that you
-download the most up to date version of the config scripts from
-
-  http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD
-and
-  http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD
-
-If the version you run ($0) is already up to date, please
-send the following data and any information you think might be
-pertinent to <config-patches@gnu.org> in order to provide the needed
-information to handle your system.
-
-config.guess timestamp = $timestamp
-
-uname -m = `(uname -m) 2>/dev/null || echo unknown`
-uname -r = `(uname -r) 2>/dev/null || echo unknown`
-uname -s = `(uname -s) 2>/dev/null || echo unknown`
-uname -v = `(uname -v) 2>/dev/null || echo unknown`
-
-/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null`
-/bin/uname -X     = `(/bin/uname -X) 2>/dev/null`
-
-hostinfo               = `(hostinfo) 2>/dev/null`
-/bin/universe          = `(/bin/universe) 2>/dev/null`
-/usr/bin/arch -k       = `(/usr/bin/arch -k) 2>/dev/null`
-/bin/arch              = `(/bin/arch) 2>/dev/null`
-/usr/bin/oslevel       = `(/usr/bin/oslevel) 2>/dev/null`
-/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null`
-
-UNAME_MACHINE = ${UNAME_MACHINE}
-UNAME_RELEASE = ${UNAME_RELEASE}
-UNAME_SYSTEM  = ${UNAME_SYSTEM}
-UNAME_VERSION = ${UNAME_VERSION}
-EOF
-
-exit 1
-
-# Local variables:
-# eval: (add-hook 'write-file-hooks 'time-stamp)
-# time-stamp-start: "timestamp='"
-# time-stamp-format: "%:y-%02m-%02d"
-# time-stamp-end: "'"
-# End:
diff --git a/build-aux/config.sub b/build-aux/config.sub
deleted file mode 100755 (executable)
index c2d1257..0000000
+++ /dev/null
@@ -1,1714 +0,0 @@
-#! /bin/sh
-# Configuration validation subroutine script.
-#   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-#   2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
-#   Free Software Foundation, Inc.
-
-timestamp='2010-01-22'
-
-# This file is (in principle) common to ALL GNU software.
-# The presence of a machine in this file suggests that SOME GNU software
-# can handle that machine.  It does not imply ALL GNU software can.
-#
-# This file is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
-# 02110-1301, USA.
-#
-# As a special exception to the GNU General Public License, if you
-# distribute this file as part of a program that contains a
-# configuration script generated by Autoconf, you may include it under
-# the same distribution terms that you use for the rest of that program.
-
-
-# Please send patches to <config-patches@gnu.org>.  Submit a context
-# diff and a properly formatted GNU ChangeLog entry.
-#
-# Configuration subroutine to validate and canonicalize a configuration type.
-# Supply the specified configuration type as an argument.
-# If it is invalid, we print an error message on stderr and exit with code 1.
-# Otherwise, we print the canonical config type on stdout and succeed.
-
-# You can get the latest version of this script from:
-# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD
-
-# This file is supposed to be the same for all GNU packages
-# and recognize all the CPU types, system types and aliases
-# that are meaningful with *any* GNU software.
-# Each package is responsible for reporting which valid configurations
-# it does not support.  The user should be able to distinguish
-# a failure to support a valid configuration from a meaningless
-# configuration.
-
-# The goal of this file is to map all the various variations of a given
-# machine specification into a single specification in the form:
-#      CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM
-# or in some cases, the newer four-part form:
-#      CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM
-# It is wrong to echo any other type of specification.
-
-me=`echo "$0" | sed -e 's,.*/,,'`
-
-usage="\
-Usage: $0 [OPTION] CPU-MFR-OPSYS
-       $0 [OPTION] ALIAS
-
-Canonicalize a configuration name.
-
-Operation modes:
-  -h, --help         print this help, then exit
-  -t, --time-stamp   print date of last modification, then exit
-  -v, --version      print version number, then exit
-
-Report bugs and patches to <config-patches@gnu.org>."
-
-version="\
-GNU config.sub ($timestamp)
-
-Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free
-Software Foundation, Inc.
-
-This is free software; see the source for copying conditions.  There is NO
-warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
-
-help="
-Try \`$me --help' for more information."
-
-# Parse command line
-while test $# -gt 0 ; do
-  case $1 in
-    --time-stamp | --time* | -t )
-       echo "$timestamp" ; exit ;;
-    --version | -v )
-       echo "$version" ; exit ;;
-    --help | --h* | -h )
-       echo "$usage"; exit ;;
-    -- )     # Stop option processing
-       shift; break ;;
-    - )        # Use stdin as input.
-       break ;;
-    -* )
-       echo "$me: invalid option $1$help"
-       exit 1 ;;
-
-    *local*)
-       # First pass through any local machine types.
-       echo $1
-       exit ;;
-
-    * )
-       break ;;
-  esac
-done
-
-case $# in
- 0) echo "$me: missing argument$help" >&2
-    exit 1;;
- 1) ;;
- *) echo "$me: too many arguments$help" >&2
-    exit 1;;
-esac
-
-# Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any).
-# Here we must recognize all the valid KERNEL-OS combinations.
-maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'`
-case $maybe_os in
-  nto-qnx* | linux-gnu* | linux-dietlibc | linux-newlib* | linux-uclibc* | \
-  uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* | \
-  kopensolaris*-gnu* | \
-  storm-chaos* | os2-emx* | rtmk-nova*)
-    os=-$maybe_os
-    basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`
-    ;;
-  *)
-    basic_machine=`echo $1 | sed 's/-[^-]*$//'`
-    if [ $basic_machine != $1 ]
-    then os=`echo $1 | sed 's/.*-/-/'`
-    else os=; fi
-    ;;
-esac
-
-### Let's recognize common machines as not being operating systems so
-### that things like config.sub decstation-3100 work.  We also
-### recognize some manufacturers as not being operating systems, so we
-### can provide default operating systems below.
-case $os in
-       -sun*os*)
-               # Prevent following clause from handling this invalid input.
-               ;;
-       -dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \
-       -att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \
-       -unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \
-       -convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\
-       -c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \
-       -harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \
-       -apple | -axis | -knuth | -cray | -microblaze)
-               os=
-               basic_machine=$1
-               ;;
-        -bluegene*)
-               os=-cnk
-               ;;
-       -sim | -cisco | -oki | -wec | -winbond)
-               os=
-               basic_machine=$1
-               ;;
-       -scout)
-               ;;
-       -wrs)
-               os=-vxworks
-               basic_machine=$1
-               ;;
-       -chorusos*)
-               os=-chorusos
-               basic_machine=$1
-               ;;
-       -chorusrdb)
-               os=-chorusrdb
-               basic_machine=$1
-               ;;
-       -hiux*)
-               os=-hiuxwe2
-               ;;
-       -sco6)
-               os=-sco5v6
-               basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
-               ;;
-       -sco5)
-               os=-sco3.2v5
-               basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
-               ;;
-       -sco4)
-               os=-sco3.2v4
-               basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
-               ;;
-       -sco3.2.[4-9]*)
-               os=`echo $os | sed -e 's/sco3.2./sco3.2v/'`
-               basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
-               ;;
-       -sco3.2v[4-9]*)
-               # Don't forget version if it is 3.2v4 or newer.
-               basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
-               ;;
-       -sco5v6*)
-               # Don't forget version if it is 3.2v4 or newer.
-               basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
-               ;;
-       -sco*)
-               os=-sco3.2v2
-               basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
-               ;;
-       -udk*)
-               basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
-               ;;
-       -isc)
-               os=-isc2.2
-               basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
-               ;;
-       -clix*)
-               basic_machine=clipper-intergraph
-               ;;
-       -isc*)
-               basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
-               ;;
-       -lynx*)
-               os=-lynxos
-               ;;
-       -ptx*)
-               basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'`
-               ;;
-       -windowsnt*)
-               os=`echo $os | sed -e 's/windowsnt/winnt/'`
-               ;;
-       -psos*)
-               os=-psos
-               ;;
-       -mint | -mint[0-9]*)
-               basic_machine=m68k-atari
-               os=-mint
-               ;;
-esac
-
-# Decode aliases for certain CPU-COMPANY combinations.
-case $basic_machine in
-       # Recognize the basic CPU types without company name.
-       # Some are omitted here because they have special meanings below.
-       1750a | 580 \
-       | a29k \
-       | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \
-       | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \
-       | am33_2.0 \
-       | arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr | avr32 \
-       | bfin \
-       | c4x | clipper \
-       | d10v | d30v | dlx | dsp16xx \
-       | fido | fr30 | frv \
-       | h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \
-       | i370 | i860 | i960 | ia64 \
-       | ip2k | iq2000 \
-       | lm32 \
-       | m32c | m32r | m32rle | m68000 | m68k | m88k \
-       | maxq | mb | microblaze | mcore | mep | metag \
-       | mips | mipsbe | mipseb | mipsel | mipsle \
-       | mips16 \
-       | mips64 | mips64el \
-       | mips64octeon | mips64octeonel \
-       | mips64orion | mips64orionel \
-       | mips64r5900 | mips64r5900el \
-       | mips64vr | mips64vrel \
-       | mips64vr4100 | mips64vr4100el \
-       | mips64vr4300 | mips64vr4300el \
-       | mips64vr5000 | mips64vr5000el \
-       | mips64vr5900 | mips64vr5900el \
-       | mipsisa32 | mipsisa32el \
-       | mipsisa32r2 | mipsisa32r2el \
-       | mipsisa64 | mipsisa64el \
-       | mipsisa64r2 | mipsisa64r2el \
-       | mipsisa64sb1 | mipsisa64sb1el \
-       | mipsisa64sr71k | mipsisa64sr71kel \
-       | mipstx39 | mipstx39el \
-       | mn10200 | mn10300 \
-       | moxie \
-       | mt \
-       | msp430 \
-       | nios | nios2 \
-       | ns16k | ns32k \
-       | or32 \
-       | pdp10 | pdp11 | pj | pjl \
-       | powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \
-       | pyramid \
-       | rx \
-       | score \
-       | sh | sh[1234] | sh[24]a | sh[24]aeb | sh[23]e | sh[34]eb | sheb | shbe | shle | sh[1234]le | sh3ele \
-       | sh64 | sh64le \
-       | sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \
-       | sparcv8 | sparcv9 | sparcv9b | sparcv9v \
-       | spu | strongarm \
-       | tahoe | thumb | tic4x | tic80 | tron \
-       | ubicom32 \
-       | v850 | v850e \
-       | we32k \
-       | x86 | xc16x | xscale | xscalee[bl] | xstormy16 | xtensa \
-       | z8k | z80)
-               basic_machine=$basic_machine-unknown
-               ;;
-       m6811 | m68hc11 | m6812 | m68hc12 | picochip)
-               # Motorola 68HC11/12.
-               basic_machine=$basic_machine-unknown
-               os=-none
-               ;;
-       m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k)
-               ;;
-       ms1)
-               basic_machine=mt-unknown
-               ;;
-
-       # We use `pc' rather than `unknown'
-       # because (1) that's what they normally are, and
-       # (2) the word "unknown" tends to confuse beginning users.
-       i*86 | x86_64)
-         basic_machine=$basic_machine-pc
-         ;;
-       # Object if more than one company name word.
-       *-*-*)
-               echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2
-               exit 1
-               ;;
-       # Recognize the basic CPU types with company name.
-       580-* \
-       | a29k-* \
-       | alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \
-       | alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \
-       | alphapca5[67]-* | alpha64pca5[67]-* | arc-* \
-       | arm-*  | armbe-* | armle-* | armeb-* | armv*-* \
-       | avr-* | avr32-* \
-       | bfin-* | bs2000-* \
-       | c[123]* | c30-* | [cjt]90-* | c4x-* | c54x-* | c55x-* | c6x-* \
-       | clipper-* | craynv-* | cydra-* \
-       | d10v-* | d30v-* | dlx-* \
-       | elxsi-* \
-       | f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \
-       | h8300-* | h8500-* \
-       | hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \
-       | i*86-* | i860-* | i960-* | ia64-* \
-       | ip2k-* | iq2000-* \
-       | lm32-* \
-       | m32c-* | m32r-* | m32rle-* \
-       | m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \
-       | m88110-* | m88k-* | maxq-* | mcore-* | metag-* | microblaze-* \
-       | mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \
-       | mips16-* \
-       | mips64-* | mips64el-* \
-       | mips64octeon-* | mips64octeonel-* \
-       | mips64orion-* | mips64orionel-* \
-       | mips64r5900-* | mips64r5900el-* \
-       | mips64vr-* | mips64vrel-* \
-       | mips64vr4100-* | mips64vr4100el-* \
-       | mips64vr4300-* | mips64vr4300el-* \
-       | mips64vr5000-* | mips64vr5000el-* \
-       | mips64vr5900-* | mips64vr5900el-* \
-       | mipsisa32-* | mipsisa32el-* \
-       | mipsisa32r2-* | mipsisa32r2el-* \
-       | mipsisa64-* | mipsisa64el-* \
-       | mipsisa64r2-* | mipsisa64r2el-* \
-       | mipsisa64sb1-* | mipsisa64sb1el-* \
-       | mipsisa64sr71k-* | mipsisa64sr71kel-* \
-       | mipstx39-* | mipstx39el-* \
-       | mmix-* \
-       | mt-* \
-       | msp430-* \
-       | nios-* | nios2-* \
-       | none-* | np1-* | ns16k-* | ns32k-* \
-       | orion-* \
-       | pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \
-       | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \
-       | pyramid-* \
-       | romp-* | rs6000-* | rx-* \
-       | sh-* | sh[1234]-* | sh[24]a-* | sh[24]aeb-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \
-       | shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \
-       | sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \
-       | sparclite-* \
-       | sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | strongarm-* | sv1-* | sx?-* \
-       | tahoe-* | thumb-* \
-       | tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \
-       | tile-* | tilegx-* \
-       | tron-* \
-       | ubicom32-* \
-       | v850-* | v850e-* | vax-* \
-       | we32k-* \
-       | x86-* | x86_64-* | xc16x-* | xps100-* | xscale-* | xscalee[bl]-* \
-       | xstormy16-* | xtensa*-* \
-       | ymp-* \
-       | z8k-* | z80-*)
-               ;;
-       # Recognize the basic CPU types without company name, with glob match.
-       xtensa*)
-               basic_machine=$basic_machine-unknown
-               ;;
-       # Recognize the various machine names and aliases which stand
-       # for a CPU type and a company and sometimes even an OS.
-       386bsd)
-               basic_machine=i386-unknown
-               os=-bsd
-               ;;
-       3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc)
-               basic_machine=m68000-att
-               ;;
-       3b*)
-               basic_machine=we32k-att
-               ;;
-       a29khif)
-               basic_machine=a29k-amd
-               os=-udi
-               ;;
-       abacus)
-               basic_machine=abacus-unknown
-               ;;
-       adobe68k)
-               basic_machine=m68010-adobe
-               os=-scout
-               ;;
-       alliant | fx80)
-               basic_machine=fx80-alliant
-               ;;
-       altos | altos3068)
-               basic_machine=m68k-altos
-               ;;
-       am29k)
-               basic_machine=a29k-none
-               os=-bsd
-               ;;
-       amd64)
-               basic_machine=x86_64-pc
-               ;;
-       amd64-*)
-               basic_machine=x86_64-`echo $basic_machine | sed 's/^[^-]*-//'`
-               ;;
-       amdahl)
-               basic_machine=580-amdahl
-               os=-sysv
-               ;;
-       amiga | amiga-*)
-               basic_machine=m68k-unknown
-               ;;
-       amigaos | amigados)
-               basic_machine=m68k-unknown
-               os=-amigaos
-               ;;
-       amigaunix | amix)
-               basic_machine=m68k-unknown
-               os=-sysv4
-               ;;
-       apollo68)
-               basic_machine=m68k-apollo
-               os=-sysv
-               ;;
-       apollo68bsd)
-               basic_machine=m68k-apollo
-               os=-bsd
-               ;;
-       aros)
-               basic_machine=i386-pc
-               os=-aros
-               ;;
-       aux)
-               basic_machine=m68k-apple
-               os=-aux
-               ;;
-       balance)
-               basic_machine=ns32k-sequent
-               os=-dynix
-               ;;
-       blackfin)
-               basic_machine=bfin-unknown
-               os=-linux
-               ;;
-       blackfin-*)
-               basic_machine=bfin-`echo $basic_machine | sed 's/^[^-]*-//'`
-               os=-linux
-               ;;
-       bluegene*)
-               basic_machine=powerpc-ibm
-               os=-cnk
-               ;;
-       c90)
-               basic_machine=c90-cray
-               os=-unicos
-               ;;
-        cegcc)
-               basic_machine=arm-unknown
-               os=-cegcc
-               ;;
-       convex-c1)
-               basic_machine=c1-convex
-               os=-bsd
-               ;;
-       convex-c2)
-               basic_machine=c2-convex
-               os=-bsd
-               ;;
-       convex-c32)
-               basic_machine=c32-convex
-               os=-bsd
-               ;;
-       convex-c34)
-               basic_machine=c34-convex
-               os=-bsd
-               ;;
-       convex-c38)
-               basic_machine=c38-convex
-               os=-bsd
-               ;;
-       cray | j90)
-               basic_machine=j90-cray
-               os=-unicos
-               ;;
-       craynv)
-               basic_machine=craynv-cray
-               os=-unicosmp
-               ;;
-       cr16)
-               basic_machine=cr16-unknown
-               os=-elf
-               ;;
-       crds | unos)
-               basic_machine=m68k-crds
-               ;;
-       crisv32 | crisv32-* | etraxfs*)
-               basic_machine=crisv32-axis
-               ;;
-       cris | cris-* | etrax*)
-               basic_machine=cris-axis
-               ;;
-       crx)
-               basic_machine=crx-unknown
-               os=-elf
-               ;;
-       da30 | da30-*)
-               basic_machine=m68k-da30
-               ;;
-       decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn)
-               basic_machine=mips-dec
-               ;;
-       decsystem10* | dec10*)
-               basic_machine=pdp10-dec
-               os=-tops10
-               ;;
-       decsystem20* | dec20*)
-               basic_machine=pdp10-dec
-               os=-tops20
-               ;;
-       delta | 3300 | motorola-3300 | motorola-delta \
-             | 3300-motorola | delta-motorola)
-               basic_machine=m68k-motorola
-               ;;
-       delta88)
-               basic_machine=m88k-motorola
-               os=-sysv3
-               ;;
-       dicos)
-               basic_machine=i686-pc
-               os=-dicos
-               ;;
-       djgpp)
-               basic_machine=i586-pc
-               os=-msdosdjgpp
-               ;;
-       dpx20 | dpx20-*)
-               basic_machine=rs6000-bull
-               os=-bosx
-               ;;
-       dpx2* | dpx2*-bull)
-               basic_machine=m68k-bull
-               os=-sysv3
-               ;;
-       ebmon29k)
-               basic_machine=a29k-amd
-               os=-ebmon
-               ;;
-       elxsi)
-               basic_machine=elxsi-elxsi
-               os=-bsd
-               ;;
-       encore | umax | mmax)
-               basic_machine=ns32k-encore
-               ;;
-       es1800 | OSE68k | ose68k | ose | OSE)
-               basic_machine=m68k-ericsson
-               os=-ose
-               ;;
-       fx2800)
-               basic_machine=i860-alliant
-               ;;
-       genix)
-               basic_machine=ns32k-ns
-               ;;
-       gmicro)
-               basic_machine=tron-gmicro
-               os=-sysv
-               ;;
-       go32)
-               basic_machine=i386-pc
-               os=-go32
-               ;;
-       h3050r* | hiux*)
-               basic_machine=hppa1.1-hitachi
-               os=-hiuxwe2
-               ;;
-       h8300hms)
-               basic_machine=h8300-hitachi
-               os=-hms
-               ;;
-       h8300xray)
-               basic_machine=h8300-hitachi
-               os=-xray
-               ;;
-       h8500hms)
-               basic_machine=h8500-hitachi
-               os=-hms
-               ;;
-       harris)
-               basic_machine=m88k-harris
-               os=-sysv3
-               ;;
-       hp300-*)
-               basic_machine=m68k-hp
-               ;;
-       hp300bsd)
-               basic_machine=m68k-hp
-               os=-bsd
-               ;;
-       hp300hpux)
-               basic_machine=m68k-hp
-               os=-hpux
-               ;;
-       hp3k9[0-9][0-9] | hp9[0-9][0-9])
-               basic_machine=hppa1.0-hp
-               ;;
-       hp9k2[0-9][0-9] | hp9k31[0-9])
-               basic_machine=m68000-hp
-               ;;
-       hp9k3[2-9][0-9])
-               basic_machine=m68k-hp
-               ;;
-       hp9k6[0-9][0-9] | hp6[0-9][0-9])
-               basic_machine=hppa1.0-hp
-               ;;
-       hp9k7[0-79][0-9] | hp7[0-79][0-9])
-               basic_machine=hppa1.1-hp
-               ;;
-       hp9k78[0-9] | hp78[0-9])
-               # FIXME: really hppa2.0-hp
-               basic_machine=hppa1.1-hp
-               ;;
-       hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893)
-               # FIXME: really hppa2.0-hp
-               basic_machine=hppa1.1-hp
-               ;;
-       hp9k8[0-9][13679] | hp8[0-9][13679])
-               basic_machine=hppa1.1-hp
-               ;;
-       hp9k8[0-9][0-9] | hp8[0-9][0-9])
-               basic_machine=hppa1.0-hp
-               ;;
-       hppa-next)
-               os=-nextstep3
-               ;;
-       hppaosf)
-               basic_machine=hppa1.1-hp
-               os=-osf
-               ;;
-       hppro)
-               basic_machine=hppa1.1-hp
-               os=-proelf
-               ;;
-       i370-ibm* | ibm*)
-               basic_machine=i370-ibm
-               ;;
-# I'm not sure what "Sysv32" means.  Should this be sysv3.2?
-       i*86v32)
-               basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
-               os=-sysv32
-               ;;
-       i*86v4*)
-               basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
-               os=-sysv4
-               ;;
-       i*86v)
-               basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
-               os=-sysv
-               ;;
-       i*86sol2)
-               basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
-               os=-solaris2
-               ;;
-       i386mach)
-               basic_machine=i386-mach
-               os=-mach
-               ;;
-       i386-vsta | vsta)
-               basic_machine=i386-unknown
-               os=-vsta
-               ;;
-       iris | iris4d)
-               basic_machine=mips-sgi
-               case $os in
-                   -irix*)
-                       ;;
-                   *)
-                       os=-irix4
-                       ;;
-               esac
-               ;;
-       isi68 | isi)
-               basic_machine=m68k-isi
-               os=-sysv
-               ;;
-       m68knommu)
-               basic_machine=m68k-unknown
-               os=-linux
-               ;;
-       m68knommu-*)
-               basic_machine=m68k-`echo $basic_machine | sed 's/^[^-]*-//'`
-               os=-linux
-               ;;
-       m88k-omron*)
-               basic_machine=m88k-omron
-               ;;
-       magnum | m3230)
-               basic_machine=mips-mips
-               os=-sysv
-               ;;
-       merlin)
-               basic_machine=ns32k-utek
-               os=-sysv
-               ;;
-        microblaze)
-               basic_machine=microblaze-xilinx
-               ;;
-       mingw32)
-               basic_machine=i386-pc
-               os=-mingw32
-               ;;
-       mingw32ce)
-               basic_machine=arm-unknown
-               os=-mingw32ce
-               ;;
-       miniframe)
-               basic_machine=m68000-convergent
-               ;;
-       *mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*)
-               basic_machine=m68k-atari
-               os=-mint
-               ;;
-       mips3*-*)
-               basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`
-               ;;
-       mips3*)
-               basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown
-               ;;
-       monitor)
-               basic_machine=m68k-rom68k
-               os=-coff
-               ;;
-       morphos)
-               basic_machine=powerpc-unknown
-               os=-morphos
-               ;;
-       msdos)
-               basic_machine=i386-pc
-               os=-msdos
-               ;;
-       ms1-*)
-               basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'`
-               ;;
-       mvs)
-               basic_machine=i370-ibm
-               os=-mvs
-               ;;
-       ncr3000)
-               basic_machine=i486-ncr
-               os=-sysv4
-               ;;
-       netbsd386)
-               basic_machine=i386-unknown
-               os=-netbsd
-               ;;
-       netwinder)
-               basic_machine=armv4l-rebel
-               os=-linux
-               ;;
-       news | news700 | news800 | news900)
-               basic_machine=m68k-sony
-               os=-newsos
-               ;;
-       news1000)
-               basic_machine=m68030-sony
-               os=-newsos
-               ;;
-       news-3600 | risc-news)
-               basic_machine=mips-sony
-               os=-newsos
-               ;;
-       necv70)
-               basic_machine=v70-nec
-               os=-sysv
-               ;;
-       next | m*-next )
-               basic_machine=m68k-next
-               case $os in
-                   -nextstep* )
-                       ;;
-                   -ns2*)
-                     os=-nextstep2
-                       ;;
-                   *)
-                     os=-nextstep3
-                       ;;
-               esac
-               ;;
-       nh3000)
-               basic_machine=m68k-harris
-               os=-cxux
-               ;;
-       nh[45]000)
-               basic_machine=m88k-harris
-               os=-cxux
-               ;;
-       nindy960)
-               basic_machine=i960-intel
-               os=-nindy
-               ;;
-       mon960)
-               basic_machine=i960-intel
-               os=-mon960
-               ;;
-       nonstopux)
-               basic_machine=mips-compaq
-               os=-nonstopux
-               ;;
-       np1)
-               basic_machine=np1-gould
-               ;;
-       nsr-tandem)
-               basic_machine=nsr-tandem
-               ;;
-       op50n-* | op60c-*)
-               basic_machine=hppa1.1-oki
-               os=-proelf
-               ;;
-       openrisc | openrisc-*)
-               basic_machine=or32-unknown
-               ;;
-       os400)
-               basic_machine=powerpc-ibm
-               os=-os400
-               ;;
-       OSE68000 | ose68000)
-               basic_machine=m68000-ericsson
-               os=-ose
-               ;;
-       os68k)
-               basic_machine=m68k-none
-               os=-os68k
-               ;;
-       pa-hitachi)
-               basic_machine=hppa1.1-hitachi
-               os=-hiuxwe2
-               ;;
-       paragon)
-               basic_machine=i860-intel
-               os=-osf
-               ;;
-       parisc)
-               basic_machine=hppa-unknown
-               os=-linux
-               ;;
-       parisc-*)
-               basic_machine=hppa-`echo $basic_machine | sed 's/^[^-]*-//'`
-               os=-linux
-               ;;
-       pbd)
-               basic_machine=sparc-tti
-               ;;
-       pbb)
-               basic_machine=m68k-tti
-               ;;
-       pc532 | pc532-*)
-               basic_machine=ns32k-pc532
-               ;;
-       pc98)
-               basic_machine=i386-pc
-               ;;
-       pc98-*)
-               basic_machine=i386-`echo $basic_machine | sed 's/^[^-]*-//'`
-               ;;
-       pentium | p5 | k5 | k6 | nexgen | viac3)
-               basic_machine=i586-pc
-               ;;
-       pentiumpro | p6 | 6x86 | athlon | athlon_*)
-               basic_machine=i686-pc
-               ;;
-       pentiumii | pentium2 | pentiumiii | pentium3)
-               basic_machine=i686-pc
-               ;;
-       pentium4)
-               basic_machine=i786-pc
-               ;;
-       pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*)
-               basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'`
-               ;;
-       pentiumpro-* | p6-* | 6x86-* | athlon-*)
-               basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
-               ;;
-       pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*)
-               basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
-               ;;
-       pentium4-*)
-               basic_machine=i786-`echo $basic_machine | sed 's/^[^-]*-//'`
-               ;;
-       pn)
-               basic_machine=pn-gould
-               ;;
-       power)  basic_machine=power-ibm
-               ;;
-       ppc)    basic_machine=powerpc-unknown
-               ;;
-       ppc-*)  basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'`
-               ;;
-       ppcle | powerpclittle | ppc-le | powerpc-little)
-               basic_machine=powerpcle-unknown
-               ;;
-       ppcle-* | powerpclittle-*)
-               basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'`
-               ;;
-       ppc64)  basic_machine=powerpc64-unknown
-               ;;
-       ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'`
-               ;;
-       ppc64le | powerpc64little | ppc64-le | powerpc64-little)
-               basic_machine=powerpc64le-unknown
-               ;;
-       ppc64le-* | powerpc64little-*)
-               basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'`
-               ;;
-       ps2)
-               basic_machine=i386-ibm
-               ;;
-       pw32)
-               basic_machine=i586-unknown
-               os=-pw32
-               ;;
-       rdos)
-               basic_machine=i386-pc
-               os=-rdos
-               ;;
-       rom68k)
-               basic_machine=m68k-rom68k
-               os=-coff
-               ;;
-       rm[46]00)
-               basic_machine=mips-siemens
-               ;;
-       rtpc | rtpc-*)
-               basic_machine=romp-ibm
-               ;;
-       s390 | s390-*)
-               basic_machine=s390-ibm
-               ;;
-       s390x | s390x-*)
-               basic_machine=s390x-ibm
-               ;;
-       sa29200)
-               basic_machine=a29k-amd
-               os=-udi
-               ;;
-       sb1)
-               basic_machine=mipsisa64sb1-unknown
-               ;;
-       sb1el)
-               basic_machine=mipsisa64sb1el-unknown
-               ;;
-       sde)
-               basic_machine=mipsisa32-sde
-               os=-elf
-               ;;
-       sei)
-               basic_machine=mips-sei
-               os=-seiux
-               ;;
-       sequent)
-               basic_machine=i386-sequent
-               ;;
-       sh)
-               basic_machine=sh-hitachi
-               os=-hms
-               ;;
-       sh5el)
-               basic_machine=sh5le-unknown
-               ;;
-       sh64)
-               basic_machine=sh64-unknown
-               ;;
-       sparclite-wrs | simso-wrs)
-               basic_machine=sparclite-wrs
-               os=-vxworks
-               ;;
-       sps7)
-               basic_machine=m68k-bull
-               os=-sysv2
-               ;;
-       spur)
-               basic_machine=spur-unknown
-               ;;
-       st2000)
-               basic_machine=m68k-tandem
-               ;;
-       stratus)
-               basic_machine=i860-stratus
-               os=-sysv4
-               ;;
-       sun2)
-               basic_machine=m68000-sun
-               ;;
-       sun2os3)
-               basic_machine=m68000-sun
-               os=-sunos3
-               ;;
-       sun2os4)
-               basic_machine=m68000-sun
-               os=-sunos4
-               ;;
-       sun3os3)
-               basic_machine=m68k-sun
-               os=-sunos3
-               ;;
-       sun3os4)
-               basic_machine=m68k-sun
-               os=-sunos4
-               ;;
-       sun4os3)
-               basic_machine=sparc-sun
-               os=-sunos3
-               ;;
-       sun4os4)
-               basic_machine=sparc-sun
-               os=-sunos4
-               ;;
-       sun4sol2)
-               basic_machine=sparc-sun
-               os=-solaris2
-               ;;
-       sun3 | sun3-*)
-               basic_machine=m68k-sun
-               ;;
-       sun4)
-               basic_machine=sparc-sun
-               ;;
-       sun386 | sun386i | roadrunner)
-               basic_machine=i386-sun
-               ;;
-       sv1)
-               basic_machine=sv1-cray
-               os=-unicos
-               ;;
-       symmetry)
-               basic_machine=i386-sequent
-               os=-dynix
-               ;;
-       t3e)
-               basic_machine=alphaev5-cray
-               os=-unicos
-               ;;
-       t90)
-               basic_machine=t90-cray
-               os=-unicos
-               ;;
-       tic54x | c54x*)
-               basic_machine=tic54x-unknown
-               os=-coff
-               ;;
-       tic55x | c55x*)
-               basic_machine=tic55x-unknown
-               os=-coff
-               ;;
-       tic6x | c6x*)
-               basic_machine=tic6x-unknown
-               os=-coff
-               ;;
-        # This must be matched before tile*.
-        tilegx*)
-               basic_machine=tilegx-unknown
-               os=-linux-gnu
-               ;;
-       tile*)
-               basic_machine=tile-unknown
-               os=-linux-gnu
-               ;;
-       tx39)
-               basic_machine=mipstx39-unknown
-               ;;
-       tx39el)
-               basic_machine=mipstx39el-unknown
-               ;;
-       toad1)
-               basic_machine=pdp10-xkl
-               os=-tops20
-               ;;
-       tower | tower-32)
-               basic_machine=m68k-ncr
-               ;;
-       tpf)
-               basic_machine=s390x-ibm
-               os=-tpf
-               ;;
-       udi29k)
-               basic_machine=a29k-amd
-               os=-udi
-               ;;
-       ultra3)
-               basic_machine=a29k-nyu
-               os=-sym1
-               ;;
-       v810 | necv810)
-               basic_machine=v810-nec
-               os=-none
-               ;;
-       vaxv)
-               basic_machine=vax-dec
-               os=-sysv
-               ;;
-       vms)
-               basic_machine=vax-dec
-               os=-vms
-               ;;
-       vpp*|vx|vx-*)
-               basic_machine=f301-fujitsu
-               ;;
-       vxworks960)
-               basic_machine=i960-wrs
-               os=-vxworks
-               ;;
-       vxworks68)
-               basic_machine=m68k-wrs
-               os=-vxworks
-               ;;
-       vxworks29k)
-               basic_machine=a29k-wrs
-               os=-vxworks
-               ;;
-       w65*)
-               basic_machine=w65-wdc
-               os=-none
-               ;;
-       w89k-*)
-               basic_machine=hppa1.1-winbond
-               os=-proelf
-               ;;
-       xbox)
-               basic_machine=i686-pc
-               os=-mingw32
-               ;;
-       xps | xps100)
-               basic_machine=xps100-honeywell
-               ;;
-       ymp)
-               basic_machine=ymp-cray
-               os=-unicos
-               ;;
-       z8k-*-coff)
-               basic_machine=z8k-unknown
-               os=-sim
-               ;;
-       z80-*-coff)
-               basic_machine=z80-unknown
-               os=-sim
-               ;;
-       none)
-               basic_machine=none-none
-               os=-none
-               ;;
-
-# Here we handle the default manufacturer of certain CPU types.  It is in
-# some cases the only manufacturer, in others, it is the most popular.
-       w89k)
-               basic_machine=hppa1.1-winbond
-               ;;
-       op50n)
-               basic_machine=hppa1.1-oki
-               ;;
-       op60c)
-               basic_machine=hppa1.1-oki
-               ;;
-       romp)
-               basic_machine=romp-ibm
-               ;;
-       mmix)
-               basic_machine=mmix-knuth
-               ;;
-       rs6000)
-               basic_machine=rs6000-ibm
-               ;;
-       vax)
-               basic_machine=vax-dec
-               ;;
-       pdp10)
-               # there are many clones, so DEC is not a safe bet
-               basic_machine=pdp10-unknown
-               ;;
-       pdp11)
-               basic_machine=pdp11-dec
-               ;;
-       we32k)
-               basic_machine=we32k-att
-               ;;
-       sh[1234] | sh[24]a | sh[24]aeb | sh[34]eb | sh[1234]le | sh[23]ele)
-               basic_machine=sh-unknown
-               ;;
-       sparc | sparcv8 | sparcv9 | sparcv9b | sparcv9v)
-               basic_machine=sparc-sun
-               ;;
-       cydra)
-               basic_machine=cydra-cydrome
-               ;;
-       orion)
-               basic_machine=orion-highlevel
-               ;;
-       orion105)
-               basic_machine=clipper-highlevel
-               ;;
-       mac | mpw | mac-mpw)
-               basic_machine=m68k-apple
-               ;;
-       pmac | pmac-mpw)
-               basic_machine=powerpc-apple
-               ;;
-       *-unknown)
-               # Make sure to match an already-canonicalized machine name.
-               ;;
-       *)
-               echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2
-               exit 1
-               ;;
-esac
-
-# Here we canonicalize certain aliases for manufacturers.
-case $basic_machine in
-       *-digital*)
-               basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'`
-               ;;
-       *-commodore*)
-               basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'`
-               ;;
-       *)
-               ;;
-esac
-
-# Decode manufacturer-specific aliases for certain operating systems.
-
-if [ x"$os" != x"" ]
-then
-case $os in
-        # First match some system type aliases
-        # that might get confused with valid system types.
-       # -solaris* is a basic system type, with this one exception.
-        -auroraux)
-               os=-auroraux
-               ;;
-       -solaris1 | -solaris1.*)
-               os=`echo $os | sed -e 's|solaris1|sunos4|'`
-               ;;
-       -solaris)
-               os=-solaris2
-               ;;
-       -svr4*)
-               os=-sysv4
-               ;;
-       -unixware*)
-               os=-sysv4.2uw
-               ;;
-       -gnu/linux*)
-               os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'`
-               ;;
-       # First accept the basic system types.
-       # The portable systems comes first.
-       # Each alternative MUST END IN A *, to match a version number.
-       # -sysv* is not here because it comes later, after sysvr4.
-       -gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \
-             | -*vms* | -sco* | -esix* | -isc* | -aix* | -cnk* | -sunos | -sunos[34]*\
-             | -hpux* | -unos* | -osf* | -luna* | -dgux* | -auroraux* | -solaris* \
-             | -sym* | -kopensolaris* \
-             | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \
-             | -aos* | -aros* \
-             | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \
-             | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \
-             | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \
-             | -openbsd* | -solidbsd* \
-             | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \
-             | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \
-             | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \
-             | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
-             | -chorusos* | -chorusrdb* | -cegcc* \
-             | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
-             | -mingw32* | -linux-gnu* | -linux-newlib* | -linux-uclibc* \
-             | -uxpv* | -beos* | -mpeix* | -udk* \
-             | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \
-             | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \
-             | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \
-             | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \
-             | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \
-             | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \
-             | -skyos* | -haiku* | -rdos* | -toppers* | -drops* | -es*)
-       # Remember, each alternative MUST END IN *, to match a version number.
-               ;;
-       -qnx*)
-               case $basic_machine in
-                   x86-* | i*86-*)
-                       ;;
-                   *)
-                       os=-nto$os
-                       ;;
-               esac
-               ;;
-       -nto-qnx*)
-               ;;
-       -nto*)
-               os=`echo $os | sed -e 's|nto|nto-qnx|'`
-               ;;
-       -sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \
-             | -windows* | -osx | -abug | -netware* | -os9* | -beos* | -haiku* \
-             | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*)
-               ;;
-       -mac*)
-               os=`echo $os | sed -e 's|mac|macos|'`
-               ;;
-       -linux-dietlibc)
-               os=-linux-dietlibc
-               ;;
-       -linux*)
-               os=`echo $os | sed -e 's|linux|linux-gnu|'`
-               ;;
-       -sunos5*)
-               os=`echo $os | sed -e 's|sunos5|solaris2|'`
-               ;;
-       -sunos6*)
-               os=`echo $os | sed -e 's|sunos6|solaris3|'`
-               ;;
-       -opened*)
-               os=-openedition
-               ;;
-        -os400*)
-               os=-os400
-               ;;
-       -wince*)
-               os=-wince
-               ;;
-       -osfrose*)
-               os=-osfrose
-               ;;
-       -osf*)
-               os=-osf
-               ;;
-       -utek*)
-               os=-bsd
-               ;;
-       -dynix*)
-               os=-bsd
-               ;;
-       -acis*)
-               os=-aos
-               ;;
-       -atheos*)
-               os=-atheos
-               ;;
-       -syllable*)
-               os=-syllable
-               ;;
-       -386bsd)
-               os=-bsd
-               ;;
-       -ctix* | -uts*)
-               os=-sysv
-               ;;
-       -nova*)
-               os=-rtmk-nova
-               ;;
-       -ns2 )
-               os=-nextstep2
-               ;;
-       -nsk*)
-               os=-nsk
-               ;;
-       # Preserve the version number of sinix5.
-       -sinix5.*)
-               os=`echo $os | sed -e 's|sinix|sysv|'`
-               ;;
-       -sinix*)
-               os=-sysv4
-               ;;
-        -tpf*)
-               os=-tpf
-               ;;
-       -triton*)
-               os=-sysv3
-               ;;
-       -oss*)
-               os=-sysv3
-               ;;
-       -svr4)
-               os=-sysv4
-               ;;
-       -svr3)
-               os=-sysv3
-               ;;
-       -sysvr4)
-               os=-sysv4
-               ;;
-       # This must come after -sysvr4.
-       -sysv*)
-               ;;
-       -ose*)
-               os=-ose
-               ;;
-       -es1800*)
-               os=-ose
-               ;;
-       -xenix)
-               os=-xenix
-               ;;
-       -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
-               os=-mint
-               ;;
-       -aros*)
-               os=-aros
-               ;;
-       -kaos*)
-               os=-kaos
-               ;;
-       -zvmoe)
-               os=-zvmoe
-               ;;
-       -dicos*)
-               os=-dicos
-               ;;
-        -nacl*)
-               ;;
-       -none)
-               ;;
-       *)
-               # Get rid of the `-' at the beginning of $os.
-               os=`echo $os | sed 's/[^-]*-//'`
-               echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2
-               exit 1
-               ;;
-esac
-else
-
-# Here we handle the default operating systems that come with various machines.
-# The value should be what the vendor currently ships out the door with their
-# machine or put another way, the most popular os provided with the machine.
-
-# Note that if you're going to try to match "-MANUFACTURER" here (say,
-# "-sun"), then you have to tell the case statement up towards the top
-# that MANUFACTURER isn't an operating system.  Otherwise, code above
-# will signal an error saying that MANUFACTURER isn't an operating
-# system, and we'll never get to this point.
-
-case $basic_machine in
-        score-*)
-               os=-elf
-               ;;
-        spu-*)
-               os=-elf
-               ;;
-       *-acorn)
-               os=-riscix1.2
-               ;;
-       arm*-rebel)
-               os=-linux
-               ;;
-       arm*-semi)
-               os=-aout
-               ;;
-        c4x-* | tic4x-*)
-               os=-coff
-               ;;
-       # This must come before the *-dec entry.
-       pdp10-*)
-               os=-tops20
-               ;;
-       pdp11-*)
-               os=-none
-               ;;
-       *-dec | vax-*)
-               os=-ultrix4.2
-               ;;
-       m68*-apollo)
-               os=-domain
-               ;;
-       i386-sun)
-               os=-sunos4.0.2
-               ;;
-       m68000-sun)
-               os=-sunos3
-               # This also exists in the configure program, but was not the
-               # default.
-               # os=-sunos4
-               ;;
-       m68*-cisco)
-               os=-aout
-               ;;
-        mep-*)
-               os=-elf
-               ;;
-       mips*-cisco)
-               os=-elf
-               ;;
-       mips*-*)
-               os=-elf
-               ;;
-       or32-*)
-               os=-coff
-               ;;
-       *-tti)  # must be before sparc entry or we get the wrong os.
-               os=-sysv3
-               ;;
-       sparc-* | *-sun)
-               os=-sunos4.1.1
-               ;;
-       *-be)
-               os=-beos
-               ;;
-       *-haiku)
-               os=-haiku
-               ;;
-       *-ibm)
-               os=-aix
-               ;;
-       *-knuth)
-               os=-mmixware
-               ;;
-       *-wec)
-               os=-proelf
-               ;;
-       *-winbond)
-               os=-proelf
-               ;;
-       *-oki)
-               os=-proelf
-               ;;
-       *-hp)
-               os=-hpux
-               ;;
-       *-hitachi)
-               os=-hiux
-               ;;
-       i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent)
-               os=-sysv
-               ;;
-       *-cbm)
-               os=-amigaos
-               ;;
-       *-dg)
-               os=-dgux
-               ;;
-       *-dolphin)
-               os=-sysv3
-               ;;
-       m68k-ccur)
-               os=-rtu
-               ;;
-       m88k-omron*)
-               os=-luna
-               ;;
-       *-next )
-               os=-nextstep
-               ;;
-       *-sequent)
-               os=-ptx
-               ;;
-       *-crds)
-               os=-unos
-               ;;
-       *-ns)
-               os=-genix
-               ;;
-       i370-*)
-               os=-mvs
-               ;;
-       *-next)
-               os=-nextstep3
-               ;;
-       *-gould)
-               os=-sysv
-               ;;
-       *-highlevel)
-               os=-bsd
-               ;;
-       *-encore)
-               os=-bsd
-               ;;
-       *-sgi)
-               os=-irix
-               ;;
-       *-siemens)
-               os=-sysv4
-               ;;
-       *-masscomp)
-               os=-rtu
-               ;;
-       f30[01]-fujitsu | f700-fujitsu)
-               os=-uxpv
-               ;;
-       *-rom68k)
-               os=-coff
-               ;;
-       *-*bug)
-               os=-coff
-               ;;
-       *-apple)
-               os=-macos
-               ;;
-       *-atari*)
-               os=-mint
-               ;;
-       *)
-               os=-none
-               ;;
-esac
-fi
-
-# Here we handle the case where we know the os, and the CPU type, but not the
-# manufacturer.  We pick the logical manufacturer.
-vendor=unknown
-case $basic_machine in
-       *-unknown)
-               case $os in
-                       -riscix*)
-                               vendor=acorn
-                               ;;
-                       -sunos*)
-                               vendor=sun
-                               ;;
-                       -cnk*|-aix*)
-                               vendor=ibm
-                               ;;
-                       -beos*)
-                               vendor=be
-                               ;;
-                       -hpux*)
-                               vendor=hp
-                               ;;
-                       -mpeix*)
-                               vendor=hp
-                               ;;
-                       -hiux*)
-                               vendor=hitachi
-                               ;;
-                       -unos*)
-                               vendor=crds
-                               ;;
-                       -dgux*)
-                               vendor=dg
-                               ;;
-                       -luna*)
-                               vendor=omron
-                               ;;
-                       -genix*)
-                               vendor=ns
-                               ;;
-                       -mvs* | -opened*)
-                               vendor=ibm
-                               ;;
-                       -os400*)
-                               vendor=ibm
-                               ;;
-                       -ptx*)
-                               vendor=sequent
-                               ;;
-                       -tpf*)
-                               vendor=ibm
-                               ;;
-                       -vxsim* | -vxworks* | -windiss*)
-                               vendor=wrs
-                               ;;
-                       -aux*)
-                               vendor=apple
-                               ;;
-                       -hms*)
-                               vendor=hitachi
-                               ;;
-                       -mpw* | -macos*)
-                               vendor=apple
-                               ;;
-                       -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
-                               vendor=atari
-                               ;;
-                       -vos*)
-                               vendor=stratus
-                               ;;
-               esac
-               basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"`
-               ;;
-esac
-
-echo $basic_machine$os
-exit
-
-# Local variables:
-# eval: (add-hook 'write-file-hooks 'time-stamp)
-# time-stamp-start: "timestamp='"
-# time-stamp-format: "%:y-%02m-%02d"
-# time-stamp-end: "'"
-# End:
diff --git a/build-aux/depcomp b/build-aux/depcomp
deleted file mode 100755 (executable)
index df8eea7..0000000
+++ /dev/null
@@ -1,630 +0,0 @@
-#! /bin/sh
-# depcomp - compile a program generating dependencies as side-effects
-
-scriptversion=2009-04-28.21; # UTC
-
-# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2009 Free
-# Software Foundation, Inc.
-
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2, or (at your option)
-# any later version.
-
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-# As a special exception to the GNU General Public License, if you
-# distribute this file as part of a program that contains a
-# configuration script generated by Autoconf, you may include it under
-# the same distribution terms that you use for the rest of that program.
-
-# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
-
-case $1 in
-  '')
-     echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
-     exit 1;
-     ;;
-  -h | --h*)
-    cat <<\EOF
-Usage: depcomp [--help] [--version] PROGRAM [ARGS]
-
-Run PROGRAMS ARGS to compile a file, generating dependencies
-as side-effects.
-
-Environment variables:
-  depmode     Dependency tracking mode.
-  source      Source file read by `PROGRAMS ARGS'.
-  object      Object file output by `PROGRAMS ARGS'.
-  DEPDIR      directory where to store dependencies.
-  depfile     Dependency file to output.
-  tmpdepfile  Temporary file to use when outputing dependencies.
-  libtool     Whether libtool is used (yes/no).
-
-Report bugs to <bug-automake@gnu.org>.
-EOF
-    exit $?
-    ;;
-  -v | --v*)
-    echo "depcomp $scriptversion"
-    exit $?
-    ;;
-esac
-
-if test -z "$depmode" || test -z "$source" || test -z "$object"; then
-  echo "depcomp: Variables source, object and depmode must be set" 1>&2
-  exit 1
-fi
-
-# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
-depfile=${depfile-`echo "$object" |
-  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
-tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
-
-rm -f "$tmpdepfile"
-
-# Some modes work just like other modes, but use different flags.  We
-# parameterize here, but still list the modes in the big case below,
-# to make depend.m4 easier to write.  Note that we *cannot* use a case
-# here, because this file can only contain one case statement.
-if test "$depmode" = hp; then
-  # HP compiler uses -M and no extra arg.
-  gccflag=-M
-  depmode=gcc
-fi
-
-if test "$depmode" = dashXmstdout; then
-   # This is just like dashmstdout with a different argument.
-   dashmflag=-xM
-   depmode=dashmstdout
-fi
-
-cygpath_u="cygpath -u -f -"
-if test "$depmode" = msvcmsys; then
-   # This is just like msvisualcpp but w/o cygpath translation.
-   # Just convert the backslash-escaped backslashes to single forward
-   # slashes to satisfy depend.m4
-   cygpath_u="sed s,\\\\\\\\,/,g"
-   depmode=msvisualcpp
-fi
-
-case "$depmode" in
-gcc3)
-## gcc 3 implements dependency tracking that does exactly what
-## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
-## it if -MD -MP comes after the -MF stuff.  Hmm.
-## Unfortunately, FreeBSD c89 acceptance of flags depends upon
-## the command line argument order; so add the flags where they
-## appear in depend2.am.  Note that the slowdown incurred here
-## affects only configure: in makefiles, %FASTDEP% shortcuts this.
-  for arg
-  do
-    case $arg in
-    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
-    *)  set fnord "$@" "$arg" ;;
-    esac
-    shift # fnord
-    shift # $arg
-  done
-  "$@"
-  stat=$?
-  if test $stat -eq 0; then :
-  else
-    rm -f "$tmpdepfile"
-    exit $stat
-  fi
-  mv "$tmpdepfile" "$depfile"
-  ;;
-
-gcc)
-## There are various ways to get dependency output from gcc.  Here's
-## why we pick this rather obscure method:
-## - Don't want to use -MD because we'd like the dependencies to end
-##   up in a subdir.  Having to rename by hand is ugly.
-##   (We might end up doing this anyway to support other compilers.)
-## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
-##   -MM, not -M (despite what the docs say).
-## - Using -M directly means running the compiler twice (even worse
-##   than renaming).
-  if test -z "$gccflag"; then
-    gccflag=-MD,
-  fi
-  "$@" -Wp,"$gccflag$tmpdepfile"
-  stat=$?
-  if test $stat -eq 0; then :
-  else
-    rm -f "$tmpdepfile"
-    exit $stat
-  fi
-  rm -f "$depfile"
-  echo "$object : \\" > "$depfile"
-  alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
-## The second -e expression handles DOS-style file names with drive letters.
-  sed -e 's/^[^:]*: / /' \
-      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
-## This next piece of magic avoids the `deleted header file' problem.
-## The problem is that when a header file which appears in a .P file
-## is deleted, the dependency causes make to die (because there is
-## typically no way to rebuild the header).  We avoid this by adding
-## dummy dependencies for each header file.  Too bad gcc doesn't do
-## this for us directly.
-  tr ' ' '
-' < "$tmpdepfile" |
-## Some versions of gcc put a space before the `:'.  On the theory
-## that the space means something, we add a space to the output as
-## well.
-## Some versions of the HPUX 10.20 sed can't process this invocation
-## correctly.  Breaking it into two sed invocations is a workaround.
-    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
-  rm -f "$tmpdepfile"
-  ;;
-
-hp)
-  # This case exists only to let depend.m4 do its work.  It works by
-  # looking at the text of this script.  This case will never be run,
-  # since it is checked for above.
-  exit 1
-  ;;
-
-sgi)
-  if test "$libtool" = yes; then
-    "$@" "-Wp,-MDupdate,$tmpdepfile"
-  else
-    "$@" -MDupdate "$tmpdepfile"
-  fi
-  stat=$?
-  if test $stat -eq 0; then :
-  else
-    rm -f "$tmpdepfile"
-    exit $stat
-  fi
-  rm -f "$depfile"
-
-  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
-    echo "$object : \\" > "$depfile"
-
-    # Clip off the initial element (the dependent).  Don't try to be
-    # clever and replace this with sed code, as IRIX sed won't handle
-    # lines with more than a fixed number of characters (4096 in
-    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
-    # the IRIX cc adds comments like `#:fec' to the end of the
-    # dependency line.
-    tr ' ' '
-' < "$tmpdepfile" \
-    | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
-    tr '
-' ' ' >> "$depfile"
-    echo >> "$depfile"
-
-    # The second pass generates a dummy entry for each header file.
-    tr ' ' '
-' < "$tmpdepfile" \
-   | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
-   >> "$depfile"
-  else
-    # The sourcefile does not contain any dependencies, so just
-    # store a dummy comment line, to avoid errors with the Makefile
-    # "include basename.Plo" scheme.
-    echo "#dummy" > "$depfile"
-  fi
-  rm -f "$tmpdepfile"
-  ;;
-
-aix)
-  # The C for AIX Compiler uses -M and outputs the dependencies
-  # in a .u file.  In older versions, this file always lives in the
-  # current directory.  Also, the AIX compiler puts `$object:' at the
-  # start of each line; $object doesn't have directory information.
-  # Version 6 uses the directory in both cases.
-  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
-  test "x$dir" = "x$object" && dir=
-  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
-  if test "$libtool" = yes; then
-    tmpdepfile1=$dir$base.u
-    tmpdepfile2=$base.u
-    tmpdepfile3=$dir.libs/$base.u
-    "$@" -Wc,-M
-  else
-    tmpdepfile1=$dir$base.u
-    tmpdepfile2=$dir$base.u
-    tmpdepfile3=$dir$base.u
-    "$@" -M
-  fi
-  stat=$?
-
-  if test $stat -eq 0; then :
-  else
-    rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
-    exit $stat
-  fi
-
-  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
-  do
-    test -f "$tmpdepfile" && break
-  done
-  if test -f "$tmpdepfile"; then
-    # Each line is of the form `foo.o: dependent.h'.
-    # Do two passes, one to just change these to
-    # `$object: dependent.h' and one to simply `dependent.h:'.
-    sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
-    # That's a tab and a space in the [].
-    sed -e 's,^.*\.[a-z]*:[     ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
-  else
-    # The sourcefile does not contain any dependencies, so just
-    # store a dummy comment line, to avoid errors with the Makefile
-    # "include basename.Plo" scheme.
-    echo "#dummy" > "$depfile"
-  fi
-  rm -f "$tmpdepfile"
-  ;;
-
-icc)
-  # Intel's C compiler understands `-MD -MF file'.  However on
-  #    icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c
-  # ICC 7.0 will fill foo.d with something like
-  #    foo.o: sub/foo.c
-  #    foo.o: sub/foo.h
-  # which is wrong.  We want:
-  #    sub/foo.o: sub/foo.c
-  #    sub/foo.o: sub/foo.h
-  #    sub/foo.c:
-  #    sub/foo.h:
-  # ICC 7.1 will output
-  #    foo.o: sub/foo.c sub/foo.h
-  # and will wrap long lines using \ :
-  #    foo.o: sub/foo.c ... \
-  #     sub/foo.h ... \
-  #     ...
-
-  "$@" -MD -MF "$tmpdepfile"
-  stat=$?
-  if test $stat -eq 0; then :
-  else
-    rm -f "$tmpdepfile"
-    exit $stat
-  fi
-  rm -f "$depfile"
-  # Each line is of the form `foo.o: dependent.h',
-  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
-  # Do two passes, one to just change these to
-  # `$object: dependent.h' and one to simply `dependent.h:'.
-  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
-  # Some versions of the HPUX 10.20 sed can't process this invocation
-  # correctly.  Breaking it into two sed invocations is a workaround.
-  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
-    sed -e 's/$/ :/' >> "$depfile"
-  rm -f "$tmpdepfile"
-  ;;
-
-hp2)
-  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
-  # compilers, which have integrated preprocessors.  The correct option
-  # to use with these is +Maked; it writes dependencies to a file named
-  # 'foo.d', which lands next to the object file, wherever that
-  # happens to be.
-  # Much of this is similar to the tru64 case; see comments there.
-  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
-  test "x$dir" = "x$object" && dir=
-  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
-  if test "$libtool" = yes; then
-    tmpdepfile1=$dir$base.d
-    tmpdepfile2=$dir.libs/$base.d
-    "$@" -Wc,+Maked
-  else
-    tmpdepfile1=$dir$base.d
-    tmpdepfile2=$dir$base.d
-    "$@" +Maked
-  fi
-  stat=$?
-  if test $stat -eq 0; then :
-  else
-     rm -f "$tmpdepfile1" "$tmpdepfile2"
-     exit $stat
-  fi
-
-  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
-  do
-    test -f "$tmpdepfile" && break
-  done
-  if test -f "$tmpdepfile"; then
-    sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile"
-    # Add `dependent.h:' lines.
-    sed -ne '2,${
-              s/^ *//
-              s/ \\*$//
-              s/$/:/
-              p
-            }' "$tmpdepfile" >> "$depfile"
-  else
-    echo "#dummy" > "$depfile"
-  fi
-  rm -f "$tmpdepfile" "$tmpdepfile2"
-  ;;
-
-tru64)
-   # The Tru64 compiler uses -MD to generate dependencies as a side
-   # effect.  `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
-   # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
-   # dependencies in `foo.d' instead, so we check for that too.
-   # Subdirectories are respected.
-   dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
-   test "x$dir" = "x$object" && dir=
-   base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
-
-   if test "$libtool" = yes; then
-      # With Tru64 cc, shared objects can also be used to make a
-      # static library.  This mechanism is used in libtool 1.4 series to
-      # handle both shared and static libraries in a single compilation.
-      # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
-      #
-      # With libtool 1.5 this exception was removed, and libtool now
-      # generates 2 separate objects for the 2 libraries.  These two
-      # compilations output dependencies in $dir.libs/$base.o.d and
-      # in $dir$base.o.d.  We have to check for both files, because
-      # one of the two compilations can be disabled.  We should prefer
-      # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
-      # automatically cleaned when .libs/ is deleted, while ignoring
-      # the former would cause a distcleancheck panic.
-      tmpdepfile1=$dir.libs/$base.lo.d   # libtool 1.4
-      tmpdepfile2=$dir$base.o.d          # libtool 1.5
-      tmpdepfile3=$dir.libs/$base.o.d    # libtool 1.5
-      tmpdepfile4=$dir.libs/$base.d      # Compaq CCC V6.2-504
-      "$@" -Wc,-MD
-   else
-      tmpdepfile1=$dir$base.o.d
-      tmpdepfile2=$dir$base.d
-      tmpdepfile3=$dir$base.d
-      tmpdepfile4=$dir$base.d
-      "$@" -MD
-   fi
-
-   stat=$?
-   if test $stat -eq 0; then :
-   else
-      rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
-      exit $stat
-   fi
-
-   for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
-   do
-     test -f "$tmpdepfile" && break
-   done
-   if test -f "$tmpdepfile"; then
-      sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
-      # That's a tab and a space in the [].
-      sed -e 's,^.*\.[a-z]*:[   ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
-   else
-      echo "#dummy" > "$depfile"
-   fi
-   rm -f "$tmpdepfile"
-   ;;
-
-#nosideeffect)
-  # This comment above is used by automake to tell side-effect
-  # dependency tracking mechanisms from slower ones.
-
-dashmstdout)
-  # Important note: in order to support this mode, a compiler *must*
-  # always write the preprocessed file to stdout, regardless of -o.
-  "$@" || exit $?
-
-  # Remove the call to Libtool.
-  if test "$libtool" = yes; then
-    while test "X$1" != 'X--mode=compile'; do
-      shift
-    done
-    shift
-  fi
-
-  # Remove `-o $object'.
-  IFS=" "
-  for arg
-  do
-    case $arg in
-    -o)
-      shift
-      ;;
-    $object)
-      shift
-      ;;
-    *)
-      set fnord "$@" "$arg"
-      shift # fnord
-      shift # $arg
-      ;;
-    esac
-  done
-
-  test -z "$dashmflag" && dashmflag=-M
-  # Require at least two characters before searching for `:'
-  # in the target name.  This is to cope with DOS-style filenames:
-  # a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.
-  "$@" $dashmflag |
-    sed 's:^[  ]*[^: ][^:][^:]*\:[    ]*:'"$object"'\: :' > "$tmpdepfile"
-  rm -f "$depfile"
-  cat < "$tmpdepfile" > "$depfile"
-  tr ' ' '
-' < "$tmpdepfile" | \
-## Some versions of the HPUX 10.20 sed can't process this invocation
-## correctly.  Breaking it into two sed invocations is a workaround.
-    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
-  rm -f "$tmpdepfile"
-  ;;
-
-dashXmstdout)
-  # This case only exists to satisfy depend.m4.  It is never actually
-  # run, as this mode is specially recognized in the preamble.
-  exit 1
-  ;;
-
-makedepend)
-  "$@" || exit $?
-  # Remove any Libtool call
-  if test "$libtool" = yes; then
-    while test "X$1" != 'X--mode=compile'; do
-      shift
-    done
-    shift
-  fi
-  # X makedepend
-  shift
-  cleared=no eat=no
-  for arg
-  do
-    case $cleared in
-    no)
-      set ""; shift
-      cleared=yes ;;
-    esac
-    if test $eat = yes; then
-      eat=no
-      continue
-    fi
-    case "$arg" in
-    -D*|-I*)
-      set fnord "$@" "$arg"; shift ;;
-    # Strip any option that makedepend may not understand.  Remove
-    # the object too, otherwise makedepend will parse it as a source file.
-    -arch)
-      eat=yes ;;
-    -*|$object)
-      ;;
-    *)
-      set fnord "$@" "$arg"; shift ;;
-    esac
-  done
-  obj_suffix=`echo "$object" | sed 's/^.*\././'`
-  touch "$tmpdepfile"
-  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
-  rm -f "$depfile"
-  cat < "$tmpdepfile" > "$depfile"
-  sed '1,2d' "$tmpdepfile" | tr ' ' '
-' | \
-## Some versions of the HPUX 10.20 sed can't process this invocation
-## correctly.  Breaking it into two sed invocations is a workaround.
-    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
-  rm -f "$tmpdepfile" "$tmpdepfile".bak
-  ;;
-
-cpp)
-  # Important note: in order to support this mode, a compiler *must*
-  # always write the preprocessed file to stdout.
-  "$@" || exit $?
-
-  # Remove the call to Libtool.
-  if test "$libtool" = yes; then
-    while test "X$1" != 'X--mode=compile'; do
-      shift
-    done
-    shift
-  fi
-
-  # Remove `-o $object'.
-  IFS=" "
-  for arg
-  do
-    case $arg in
-    -o)
-      shift
-      ;;
-    $object)
-      shift
-      ;;
-    *)
-      set fnord "$@" "$arg"
-      shift # fnord
-      shift # $arg
-      ;;
-    esac
-  done
-
-  "$@" -E |
-    sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
-       -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
-    sed '$ s: \\$::' > "$tmpdepfile"
-  rm -f "$depfile"
-  echo "$object : \\" > "$depfile"
-  cat < "$tmpdepfile" >> "$depfile"
-  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
-  rm -f "$tmpdepfile"
-  ;;
-
-msvisualcpp)
-  # Important note: in order to support this mode, a compiler *must*
-  # always write the preprocessed file to stdout.
-  "$@" || exit $?
-
-  # Remove the call to Libtool.
-  if test "$libtool" = yes; then
-    while test "X$1" != 'X--mode=compile'; do
-      shift
-    done
-    shift
-  fi
-
-  IFS=" "
-  for arg
-  do
-    case "$arg" in
-    -o)
-      shift
-      ;;
-    $object)
-      shift
-      ;;
-    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
-       set fnord "$@"
-       shift
-       shift
-       ;;
-    *)
-       set fnord "$@" "$arg"
-       shift
-       shift
-       ;;
-    esac
-  done
-  "$@" -E 2>/dev/null |
-  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
-  rm -f "$depfile"
-  echo "$object : \\" > "$depfile"
-  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::     \1 \\:p' >> "$depfile"
-  echo "       " >> "$depfile"
-  sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
-  rm -f "$tmpdepfile"
-  ;;
-
-msvcmsys)
-  # This case exists only to let depend.m4 do its work.  It works by
-  # looking at the text of this script.  This case will never be run,
-  # since it is checked for above.
-  exit 1
-  ;;
-
-none)
-  exec "$@"
-  ;;
-
-*)
-  echo "Unknown depmode $depmode" 1>&2
-  exit 1
-  ;;
-esac
-
-exit 0
-
-# Local Variables:
-# mode: shell-script
-# sh-indentation: 2
-# eval: (add-hook 'write-file-hooks 'time-stamp)
-# time-stamp-start: "scriptversion="
-# time-stamp-format: "%:y-%02m-%02d.%02H"
-# time-stamp-time-zone: "UTC"
-# time-stamp-end: "; # UTC"
-# End:
diff --git a/build-aux/install-sh b/build-aux/install-sh
deleted file mode 100755 (executable)
index 6781b98..0000000
+++ /dev/null
@@ -1,520 +0,0 @@
-#!/bin/sh
-# install - install a program, script, or datafile
-
-scriptversion=2009-04-28.21; # UTC
-
-# This originates from X11R5 (mit/util/scripts/install.sh), which was
-# later released in X11R6 (xc/config/util/install.sh) with the
-# following copyright and license.
-#
-# Copyright (C) 1994 X Consortium
-#
-# 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
-# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
-# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
-# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-#
-# Except as contained in this notice, the name of the X Consortium shall not
-# be used in advertising or otherwise to promote the sale, use or other deal-
-# ings in this Software without prior written authorization from the X Consor-
-# tium.
-#
-#
-# FSF changes to this file are in the public domain.
-#
-# Calling this script install-sh is preferred over install.sh, to prevent
-# `make' implicit rules from creating a file called install from it
-# when there is no Makefile.
-#
-# This script is compatible with the BSD install script, but was written
-# from scratch.
-
-nl='
-'
-IFS=" ""       $nl"
-
-# set DOITPROG to echo to test this script
-
-# Don't use :- since 4.3BSD and earlier shells don't like it.
-doit=${DOITPROG-}
-if test -z "$doit"; then
-  doit_exec=exec
-else
-  doit_exec=$doit
-fi
-
-# Put in absolute file names if you don't have them in your path;
-# or use environment vars.
-
-chgrpprog=${CHGRPPROG-chgrp}
-chmodprog=${CHMODPROG-chmod}
-chownprog=${CHOWNPROG-chown}
-cmpprog=${CMPPROG-cmp}
-cpprog=${CPPROG-cp}
-mkdirprog=${MKDIRPROG-mkdir}
-mvprog=${MVPROG-mv}
-rmprog=${RMPROG-rm}
-stripprog=${STRIPPROG-strip}
-
-posix_glob='?'
-initialize_posix_glob='
-  test "$posix_glob" != "?" || {
-    if (set -f) 2>/dev/null; then
-      posix_glob=
-    else
-      posix_glob=:
-    fi
-  }
-'
-
-posix_mkdir=
-
-# Desired mode of installed file.
-mode=0755
-
-chgrpcmd=
-chmodcmd=$chmodprog
-chowncmd=
-mvcmd=$mvprog
-rmcmd="$rmprog -f"
-stripcmd=
-
-src=
-dst=
-dir_arg=
-dst_arg=
-
-copy_on_change=false
-no_target_directory=
-
-usage="\
-Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
-   or: $0 [OPTION]... SRCFILES... DIRECTORY
-   or: $0 [OPTION]... -t DIRECTORY SRCFILES...
-   or: $0 [OPTION]... -d DIRECTORIES...
-
-In the 1st form, copy SRCFILE to DSTFILE.
-In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
-In the 4th, create DIRECTORIES.
-
-Options:
-     --help     display this help and exit.
-     --version  display version info and exit.
-
-  -c            (ignored)
-  -C            install only if different (preserve the last data modification time)
-  -d            create directories instead of installing files.
-  -g GROUP      $chgrpprog installed files to GROUP.
-  -m MODE       $chmodprog installed files to MODE.
-  -o USER       $chownprog installed files to USER.
-  -s            $stripprog installed files.
-  -t DIRECTORY  install into DIRECTORY.
-  -T            report an error if DSTFILE is a directory.
-
-Environment variables override the default commands:
-  CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG
-  RMPROG STRIPPROG
-"
-
-while test $# -ne 0; do
-  case $1 in
-    -c) ;;
-
-    -C) copy_on_change=true;;
-
-    -d) dir_arg=true;;
-
-    -g) chgrpcmd="$chgrpprog $2"
-       shift;;
-
-    --help) echo "$usage"; exit $?;;
-
-    -m) mode=$2
-       case $mode in
-         *' '* | *'    '* | *'
-'*       | *'*'* | *'?'* | *'['*)
-           echo "$0: invalid mode: $mode" >&2
-           exit 1;;
-       esac
-       shift;;
-
-    -o) chowncmd="$chownprog $2"
-       shift;;
-
-    -s) stripcmd=$stripprog;;
-
-    -t) dst_arg=$2
-       shift;;
-
-    -T) no_target_directory=true;;
-
-    --version) echo "$0 $scriptversion"; exit $?;;
-
-    --)        shift
-       break;;
-
-    -*)        echo "$0: invalid option: $1" >&2
-       exit 1;;
-
-    *)  break;;
-  esac
-  shift
-done
-
-if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then
-  # When -d is used, all remaining arguments are directories to create.
-  # When -t is used, the destination is already specified.
-  # Otherwise, the last argument is the destination.  Remove it from $@.
-  for arg
-  do
-    if test -n "$dst_arg"; then
-      # $@ is not empty: it contains at least $arg.
-      set fnord "$@" "$dst_arg"
-      shift # fnord
-    fi
-    shift # arg
-    dst_arg=$arg
-  done
-fi
-
-if test $# -eq 0; then
-  if test -z "$dir_arg"; then
-    echo "$0: no input file specified." >&2
-    exit 1
-  fi
-  # It's OK to call `install-sh -d' without argument.
-  # This can happen when creating conditional directories.
-  exit 0
-fi
-
-if test -z "$dir_arg"; then
-  trap '(exit $?); exit' 1 2 13 15
-
-  # Set umask so as not to create temps with too-generous modes.
-  # However, 'strip' requires both read and write access to temps.
-  case $mode in
-    # Optimize common cases.
-    *644) cp_umask=133;;
-    *755) cp_umask=22;;
-
-    *[0-7])
-      if test -z "$stripcmd"; then
-       u_plus_rw=
-      else
-       u_plus_rw='% 200'
-      fi
-      cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;;
-    *)
-      if test -z "$stripcmd"; then
-       u_plus_rw=
-      else
-       u_plus_rw=,u+rw
-      fi
-      cp_umask=$mode$u_plus_rw;;
-  esac
-fi
-
-for src
-do
-  # Protect names starting with `-'.
-  case $src in
-    -*) src=./$src;;
-  esac
-
-  if test -n "$dir_arg"; then
-    dst=$src
-    dstdir=$dst
-    test -d "$dstdir"
-    dstdir_status=$?
-  else
-
-    # Waiting for this to be detected by the "$cpprog $src $dsttmp" command
-    # might cause directories to be created, which would be especially bad
-    # if $src (and thus $dsttmp) contains '*'.
-    if test ! -f "$src" && test ! -d "$src"; then
-      echo "$0: $src does not exist." >&2
-      exit 1
-    fi
-
-    if test -z "$dst_arg"; then
-      echo "$0: no destination specified." >&2
-      exit 1
-    fi
-
-    dst=$dst_arg
-    # Protect names starting with `-'.
-    case $dst in
-      -*) dst=./$dst;;
-    esac
-
-    # If destination is a directory, append the input filename; won't work
-    # if double slashes aren't ignored.
-    if test -d "$dst"; then
-      if test -n "$no_target_directory"; then
-       echo "$0: $dst_arg: Is a directory" >&2
-       exit 1
-      fi
-      dstdir=$dst
-      dst=$dstdir/`basename "$src"`
-      dstdir_status=0
-    else
-      # Prefer dirname, but fall back on a substitute if dirname fails.
-      dstdir=`
-       (dirname "$dst") 2>/dev/null ||
-       expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
-            X"$dst" : 'X\(//\)[^/]' \| \
-            X"$dst" : 'X\(//\)$' \| \
-            X"$dst" : 'X\(/\)' \| . 2>/dev/null ||
-       echo X"$dst" |
-           sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
-                  s//\1/
-                  q
-                }
-                /^X\(\/\/\)[^/].*/{
-                  s//\1/
-                  q
-                }
-                /^X\(\/\/\)$/{
-                  s//\1/
-                  q
-                }
-                /^X\(\/\).*/{
-                  s//\1/
-                  q
-                }
-                s/.*/./; q'
-      `
-
-      test -d "$dstdir"
-      dstdir_status=$?
-    fi
-  fi
-
-  obsolete_mkdir_used=false
-
-  if test $dstdir_status != 0; then
-    case $posix_mkdir in
-      '')
-       # Create intermediate dirs using mode 755 as modified by the umask.
-       # This is like FreeBSD 'install' as of 1997-10-28.
-       umask=`umask`
-       case $stripcmd.$umask in
-         # Optimize common cases.
-         *[2367][2367]) mkdir_umask=$umask;;
-         .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;;
-
-         *[0-7])
-           mkdir_umask=`expr $umask + 22 \
-             - $umask % 100 % 40 + $umask % 20 \
-             - $umask % 10 % 4 + $umask % 2
-           `;;
-         *) mkdir_umask=$umask,go-w;;
-       esac
-
-       # With -d, create the new directory with the user-specified mode.
-       # Otherwise, rely on $mkdir_umask.
-       if test -n "$dir_arg"; then
-         mkdir_mode=-m$mode
-       else
-         mkdir_mode=
-       fi
-
-       posix_mkdir=false
-       case $umask in
-         *[123567][0-7][0-7])
-           # POSIX mkdir -p sets u+wx bits regardless of umask, which
-           # is incompatible with FreeBSD 'install' when (umask & 300) != 0.
-           ;;
-         *)
-           tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
-           trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0
-
-           if (umask $mkdir_umask &&
-               exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1
-           then
-             if test -z "$dir_arg" || {
-                  # Check for POSIX incompatibilities with -m.
-                  # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
-                  # other-writeable bit of parent directory when it shouldn't.
-                  # FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
-                  ls_ld_tmpdir=`ls -ld "$tmpdir"`
-                  case $ls_ld_tmpdir in
-                    d????-?r-*) different_mode=700;;
-                    d????-?--*) different_mode=755;;
-                    *) false;;
-                  esac &&
-                  $mkdirprog -m$different_mode -p -- "$tmpdir" && {
-                    ls_ld_tmpdir_1=`ls -ld "$tmpdir"`
-                    test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
-                  }
-                }
-             then posix_mkdir=:
-             fi
-             rmdir "$tmpdir/d" "$tmpdir"
-           else
-             # Remove any dirs left behind by ancient mkdir implementations.
-             rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null
-           fi
-           trap '' 0;;
-       esac;;
-    esac
-
-    if
-      $posix_mkdir && (
-       umask $mkdir_umask &&
-       $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
-      )
-    then :
-    else
-
-      # The umask is ridiculous, or mkdir does not conform to POSIX,
-      # or it failed possibly due to a race condition.  Create the
-      # directory the slow way, step by step, checking for races as we go.
-
-      case $dstdir in
-       /*) prefix='/';;
-       -*) prefix='./';;
-       *)  prefix='';;
-      esac
-
-      eval "$initialize_posix_glob"
-
-      oIFS=$IFS
-      IFS=/
-      $posix_glob set -f
-      set fnord $dstdir
-      shift
-      $posix_glob set +f
-      IFS=$oIFS
-
-      prefixes=
-
-      for d
-      do
-       test -z "$d" && continue
-
-       prefix=$prefix$d
-       if test -d "$prefix"; then
-         prefixes=
-       else
-         if $posix_mkdir; then
-           (umask=$mkdir_umask &&
-            $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
-           # Don't fail if two instances are running concurrently.
-           test -d "$prefix" || exit 1
-         else
-           case $prefix in
-             *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
-             *) qprefix=$prefix;;
-           esac
-           prefixes="$prefixes '$qprefix'"
-         fi
-       fi
-       prefix=$prefix/
-      done
-
-      if test -n "$prefixes"; then
-       # Don't fail if two instances are running concurrently.
-       (umask $mkdir_umask &&
-        eval "\$doit_exec \$mkdirprog $prefixes") ||
-         test -d "$dstdir" || exit 1
-       obsolete_mkdir_used=true
-      fi
-    fi
-  fi
-
-  if test -n "$dir_arg"; then
-    { test -z "$chowncmd" || $doit $chowncmd "$dst"; } &&
-    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } &&
-    { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false ||
-      test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1
-  else
-
-    # Make a couple of temp file names in the proper directory.
-    dsttmp=$dstdir/_inst.$$_
-    rmtmp=$dstdir/_rm.$$_
-
-    # Trap to clean up those temp files at exit.
-    trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
-
-    # Copy the file name to the temp name.
-    (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") &&
-
-    # and set any options; do chmod last to preserve setuid bits.
-    #
-    # If any of these fail, we abort the whole thing.  If we want to
-    # ignore errors from any of these, just make sure not to ignore
-    # errors from the above "$doit $cpprog $src $dsttmp" command.
-    #
-    { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } &&
-    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } &&
-    { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } &&
-    { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } &&
-
-    # If -C, don't bother to copy if it wouldn't change the file.
-    if $copy_on_change &&
-       old=`LC_ALL=C ls -dlL "$dst"    2>/dev/null` &&
-       new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` &&
-
-       eval "$initialize_posix_glob" &&
-       $posix_glob set -f &&
-       set X $old && old=:$2:$4:$5:$6 &&
-       set X $new && new=:$2:$4:$5:$6 &&
-       $posix_glob set +f &&
-
-       test "$old" = "$new" &&
-       $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1
-    then
-      rm -f "$dsttmp"
-    else
-      # Rename the file to the real destination.
-      $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null ||
-
-      # The rename failed, perhaps because mv can't rename something else
-      # to itself, or perhaps because mv is so ancient that it does not
-      # support -f.
-      {
-       # Now remove or move aside any old file at destination location.
-       # We try this two ways since rm can't unlink itself on some
-       # systems and the destination file might be busy for other
-       # reasons.  In this case, the final cleanup might fail but the new
-       # file should still install successfully.
-       {
-         test ! -f "$dst" ||
-         $doit $rmcmd -f "$dst" 2>/dev/null ||
-         { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null &&
-           { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }
-         } ||
-         { echo "$0: cannot unlink or rename $dst" >&2
-           (exit 1); exit 1
-         }
-       } &&
-
-       # Now rename the file to the real destination.
-       $doit $mvcmd "$dsttmp" "$dst"
-      }
-    fi || exit 1
-
-    trap '' 0
-  fi
-done
-
-# Local variables:
-# eval: (add-hook 'write-file-hooks 'time-stamp)
-# time-stamp-start: "scriptversion="
-# time-stamp-format: "%:y-%02m-%02d.%02H"
-# time-stamp-time-zone: "UTC"
-# time-stamp-end: "; # UTC"
-# End:
diff --git a/build-aux/ltmain.sh b/build-aux/ltmain.sh
deleted file mode 100755 (executable)
index d88da2c..0000000
+++ /dev/null
@@ -1,8413 +0,0 @@
-# Generated from ltmain.m4sh.
-
-# ltmain.sh (GNU libtool) 2.2.6b
-# Written by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
-
-# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006, 2007 2008 Free Software Foundation, Inc.
-# This is free software; see the source for copying conditions.  There is NO
-# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-
-# GNU Libtool is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# As a special exception to the GNU General Public License,
-# if you distribute this file as part of a program or library that
-# is built using GNU Libtool, you may include this file under the
-# same distribution terms that you use for the rest of that program.
-#
-# GNU Libtool is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with GNU Libtool; see the file COPYING.  If not, a copy
-# can be downloaded from http://www.gnu.org/licenses/gpl.html,
-# or obtained by writing to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-
-# Usage: $progname [OPTION]... [MODE-ARG]...
-#
-# Provide generalized library-building support services.
-#
-#     --config             show all configuration variables
-#     --debug              enable verbose shell tracing
-# -n, --dry-run            display commands without modifying any files
-#     --features           display basic configuration information and exit
-#     --mode=MODE          use operation mode MODE
-#     --preserve-dup-deps  don't remove duplicate dependency libraries
-#     --quiet, --silent    don't print informational messages
-#     --tag=TAG            use configuration variables from tag TAG
-# -v, --verbose            print informational messages (default)
-#     --version            print version information
-# -h, --help               print short or long help message
-#
-# MODE must be one of the following:
-#
-#       clean              remove files from the build directory
-#       compile            compile a source file into a libtool object
-#       execute            automatically set library path, then run a program
-#       finish             complete the installation of libtool libraries
-#       install            install libraries or executables
-#       link               create a library or an executable
-#       uninstall          remove libraries from an installed directory
-#
-# MODE-ARGS vary depending on the MODE.
-# Try `$progname --help --mode=MODE' for a more detailed description of MODE.
-#
-# When reporting a bug, please describe a test case to reproduce it and
-# include the following information:
-#
-#       host-triplet:  $host
-#       shell:         $SHELL
-#       compiler:              $LTCC
-#       compiler flags:                $LTCFLAGS
-#       linker:                $LD (gnu? $with_gnu_ld)
-#       $progname:             (GNU libtool) 2.2.6b Debian-2.2.6b-2
-#       automake:              $automake_version
-#       autoconf:              $autoconf_version
-#
-# Report bugs to <bug-libtool@gnu.org>.
-
-PROGRAM=ltmain.sh
-PACKAGE=libtool
-VERSION="2.2.6b Debian-2.2.6b-2"
-TIMESTAMP=""
-package_revision=1.3017
-
-# Be Bourne compatible
-if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
-  emulate sh
-  NULLCMD=:
-  # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which
-  # is contrary to our usage.  Disable this feature.
-  alias -g '${1+"$@"}'='"$@"'
-  setopt NO_GLOB_SUBST
-else
-  case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac
-fi
-BIN_SH=xpg4; export BIN_SH # for Tru64
-DUALCASE=1; export DUALCASE # for MKS sh
-
-# NLS nuisances: We save the old values to restore during execute mode.
-# Only set LANG and LC_ALL to C if already set.
-# These must not be set unconditionally because not all systems understand
-# e.g. LANG=C (notably SCO).
-lt_user_locale=
-lt_safe_locale=
-for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
-do
-  eval "if test \"\${$lt_var+set}\" = set; then
-          save_$lt_var=\$$lt_var
-          $lt_var=C
-         export $lt_var
-         lt_user_locale=\"$lt_var=\\\$save_\$lt_var; \$lt_user_locale\"
-         lt_safe_locale=\"$lt_var=C; \$lt_safe_locale\"
-       fi"
-done
-
-$lt_unset CDPATH
-
-
-
-
-
-: ${CP="cp -f"}
-: ${ECHO="echo"}
-: ${EGREP="/bin/grep -E"}
-: ${FGREP="/bin/grep -F"}
-: ${GREP="/bin/grep"}
-: ${LN_S="ln -s"}
-: ${MAKE="make"}
-: ${MKDIR="mkdir"}
-: ${MV="mv -f"}
-: ${RM="rm -f"}
-: ${SED="/bin/sed"}
-: ${SHELL="${CONFIG_SHELL-/bin/sh}"}
-: ${Xsed="$SED -e 1s/^X//"}
-
-# Global variables:
-EXIT_SUCCESS=0
-EXIT_FAILURE=1
-EXIT_MISMATCH=63  # $? = 63 is used to indicate version mismatch to missing.
-EXIT_SKIP=77     # $? = 77 is used to indicate a skipped test to automake.
-
-exit_status=$EXIT_SUCCESS
-
-# Make sure IFS has a sensible default
-lt_nl='
-'
-IFS="  $lt_nl"
-
-dirname="s,/[^/]*$,,"
-basename="s,^.*/,,"
-
-# func_dirname_and_basename file append nondir_replacement
-# perform func_basename and func_dirname in a single function
-# call:
-#   dirname:  Compute the dirname of FILE.  If nonempty,
-#             add APPEND to the result, otherwise set result
-#             to NONDIR_REPLACEMENT.
-#             value returned in "$func_dirname_result"
-#   basename: Compute filename of FILE.
-#             value retuned in "$func_basename_result"
-# Implementation must be kept synchronized with func_dirname
-# and func_basename. For efficiency, we do not delegate to
-# those functions but instead duplicate the functionality here.
-func_dirname_and_basename ()
-{
-  # Extract subdirectory from the argument.
-  func_dirname_result=`$ECHO "X${1}" | $Xsed -e "$dirname"`
-  if test "X$func_dirname_result" = "X${1}"; then
-    func_dirname_result="${3}"
-  else
-    func_dirname_result="$func_dirname_result${2}"
-  fi
-  func_basename_result=`$ECHO "X${1}" | $Xsed -e "$basename"`
-}
-
-# Generated shell functions inserted here.
-
-# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
-# is ksh but when the shell is invoked as "sh" and the current value of
-# the _XPG environment variable is not equal to 1 (one), the special
-# positional parameter $0, within a function call, is the name of the
-# function.
-progpath="$0"
-
-# The name of this program:
-# In the unlikely event $progname began with a '-', it would play havoc with
-# func_echo (imagine progname=-n), so we prepend ./ in that case:
-func_dirname_and_basename "$progpath"
-progname=$func_basename_result
-case $progname in
-  -*) progname=./$progname ;;
-esac
-
-# Make sure we have an absolute path for reexecution:
-case $progpath in
-  [\\/]*|[A-Za-z]:\\*) ;;
-  *[\\/]*)
-     progdir=$func_dirname_result
-     progdir=`cd "$progdir" && pwd`
-     progpath="$progdir/$progname"
-     ;;
-  *)
-     save_IFS="$IFS"
-     IFS=:
-     for progdir in $PATH; do
-       IFS="$save_IFS"
-       test -x "$progdir/$progname" && break
-     done
-     IFS="$save_IFS"
-     test -n "$progdir" || progdir=`pwd`
-     progpath="$progdir/$progname"
-     ;;
-esac
-
-# Sed substitution that helps us do robust quoting.  It backslashifies
-# metacharacters that are still active within double-quoted strings.
-Xsed="${SED}"' -e 1s/^X//'
-sed_quote_subst='s/\([`"$\\]\)/\\\1/g'
-
-# Same as above, but do not quote variable references.
-double_quote_subst='s/\(["`\\]\)/\\\1/g'
-
-# Re-`\' parameter expansions in output of double_quote_subst that were
-# `\'-ed in input to the same.  If an odd number of `\' preceded a '$'
-# in input to double_quote_subst, that '$' was protected from expansion.
-# Since each input `\' is now two `\'s, look for any number of runs of
-# four `\'s followed by two `\'s and then a '$'.  `\' that '$'.
-bs='\\'
-bs2='\\\\'
-bs4='\\\\\\\\'
-dollar='\$'
-sed_double_backslash="\
-  s/$bs4/&\\
-/g
-  s/^$bs2$dollar/$bs&/
-  s/\\([^$bs]\\)$bs2$dollar/\\1$bs2$bs$dollar/g
-  s/\n//g"
-
-# Standard options:
-opt_dry_run=false
-opt_help=false
-opt_quiet=false
-opt_verbose=false
-opt_warning=:
-
-# func_echo arg...
-# Echo program name prefixed message, along with the current mode
-# name if it has been set yet.
-func_echo ()
-{
-    $ECHO "$progname${mode+: }$mode: $*"
-}
-
-# func_verbose arg...
-# Echo program name prefixed message in verbose mode only.
-func_verbose ()
-{
-    $opt_verbose && func_echo ${1+"$@"}
-
-    # A bug in bash halts the script if the last line of a function
-    # fails when set -e is in force, so we need another command to
-    # work around that:
-    :
-}
-
-# func_error arg...
-# Echo program name prefixed message to standard error.
-func_error ()
-{
-    $ECHO "$progname${mode+: }$mode: "${1+"$@"} 1>&2
-}
-
-# func_warning arg...
-# Echo program name prefixed warning message to standard error.
-func_warning ()
-{
-    $opt_warning && $ECHO "$progname${mode+: }$mode: warning: "${1+"$@"} 1>&2
-
-    # bash bug again:
-    :
-}
-
-# func_fatal_error arg...
-# Echo program name prefixed message to standard error, and exit.
-func_fatal_error ()
-{
-    func_error ${1+"$@"}
-    exit $EXIT_FAILURE
-}
-
-# func_fatal_help arg...
-# Echo program name prefixed message to standard error, followed by
-# a help hint, and exit.
-func_fatal_help ()
-{
-    func_error ${1+"$@"}
-    func_fatal_error "$help"
-}
-help="Try \`$progname --help' for more information."  ## default
-
-
-# func_grep expression filename
-# Check whether EXPRESSION matches any line of FILENAME, without output.
-func_grep ()
-{
-    $GREP "$1" "$2" >/dev/null 2>&1
-}
-
-
-# func_mkdir_p directory-path
-# Make sure the entire path to DIRECTORY-PATH is available.
-func_mkdir_p ()
-{
-    my_directory_path="$1"
-    my_dir_list=
-
-    if test -n "$my_directory_path" && test "$opt_dry_run" != ":"; then
-
-      # Protect directory names starting with `-'
-      case $my_directory_path in
-        -*) my_directory_path="./$my_directory_path" ;;
-      esac
-
-      # While some portion of DIR does not yet exist...
-      while test ! -d "$my_directory_path"; do
-        # ...make a list in topmost first order.  Use a colon delimited
-       # list incase some portion of path contains whitespace.
-        my_dir_list="$my_directory_path:$my_dir_list"
-
-        # If the last portion added has no slash in it, the list is done
-        case $my_directory_path in */*) ;; *) break ;; esac
-
-        # ...otherwise throw away the child directory and loop
-        my_directory_path=`$ECHO "X$my_directory_path" | $Xsed -e "$dirname"`
-      done
-      my_dir_list=`$ECHO "X$my_dir_list" | $Xsed -e 's,:*$,,'`
-
-      save_mkdir_p_IFS="$IFS"; IFS=':'
-      for my_dir in $my_dir_list; do
-       IFS="$save_mkdir_p_IFS"
-        # mkdir can fail with a `File exist' error if two processes
-        # try to create one of the directories concurrently.  Don't
-        # stop in that case!
-        $MKDIR "$my_dir" 2>/dev/null || :
-      done
-      IFS="$save_mkdir_p_IFS"
-
-      # Bail out if we (or some other process) failed to create a directory.
-      test -d "$my_directory_path" || \
-        func_fatal_error "Failed to create \`$1'"
-    fi
-}
-
-
-# func_mktempdir [string]
-# Make a temporary directory that won't clash with other running
-# libtool processes, and avoids race conditions if possible.  If
-# given, STRING is the basename for that directory.
-func_mktempdir ()
-{
-    my_template="${TMPDIR-/tmp}/${1-$progname}"
-
-    if test "$opt_dry_run" = ":"; then
-      # Return a directory name, but don't create it in dry-run mode
-      my_tmpdir="${my_template}-$$"
-    else
-
-      # If mktemp works, use that first and foremost
-      my_tmpdir=`mktemp -d "${my_template}-XXXXXXXX" 2>/dev/null`
-
-      if test ! -d "$my_tmpdir"; then
-        # Failing that, at least try and use $RANDOM to avoid a race
-        my_tmpdir="${my_template}-${RANDOM-0}$$"
-
-        save_mktempdir_umask=`umask`
-        umask 0077
-        $MKDIR "$my_tmpdir"
-        umask $save_mktempdir_umask
-      fi
-
-      # If we're not in dry-run mode, bomb out on failure
-      test -d "$my_tmpdir" || \
-        func_fatal_error "cannot create temporary directory \`$my_tmpdir'"
-    fi
-
-    $ECHO "X$my_tmpdir" | $Xsed
-}
-
-
-# func_quote_for_eval arg
-# Aesthetically quote ARG to be evaled later.
-# This function returns two values: FUNC_QUOTE_FOR_EVAL_RESULT
-# is double-quoted, suitable for a subsequent eval, whereas
-# FUNC_QUOTE_FOR_EVAL_UNQUOTED_RESULT has merely all characters
-# which are still active within double quotes backslashified.
-func_quote_for_eval ()
-{
-    case $1 in
-      *[\\\`\"\$]*)
-       func_quote_for_eval_unquoted_result=`$ECHO "X$1" | $Xsed -e "$sed_quote_subst"` ;;
-      *)
-        func_quote_for_eval_unquoted_result="$1" ;;
-    esac
-
-    case $func_quote_for_eval_unquoted_result in
-      # Double-quote args containing shell metacharacters to delay
-      # word splitting, command substitution and and variable
-      # expansion for a subsequent eval.
-      # Many Bourne shells cannot handle close brackets correctly
-      # in scan sets, so we specify it separately.
-      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \    ]*|*]*|"")
-        func_quote_for_eval_result="\"$func_quote_for_eval_unquoted_result\""
-        ;;
-      *)
-        func_quote_for_eval_result="$func_quote_for_eval_unquoted_result"
-    esac
-}
-
-
-# func_quote_for_expand arg
-# Aesthetically quote ARG to be evaled later; same as above,
-# but do not quote variable references.
-func_quote_for_expand ()
-{
-    case $1 in
-      *[\\\`\"]*)
-       my_arg=`$ECHO "X$1" | $Xsed \
-           -e "$double_quote_subst" -e "$sed_double_backslash"` ;;
-      *)
-        my_arg="$1" ;;
-    esac
-
-    case $my_arg in
-      # Double-quote args containing shell metacharacters to delay
-      # word splitting and command substitution for a subsequent eval.
-      # Many Bourne shells cannot handle close brackets correctly
-      # in scan sets, so we specify it separately.
-      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \    ]*|*]*|"")
-        my_arg="\"$my_arg\""
-        ;;
-    esac
-
-    func_quote_for_expand_result="$my_arg"
-}
-
-
-# func_show_eval cmd [fail_exp]
-# Unless opt_silent is true, then output CMD.  Then, if opt_dryrun is
-# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
-# is given, then evaluate it.
-func_show_eval ()
-{
-    my_cmd="$1"
-    my_fail_exp="${2-:}"
-
-    ${opt_silent-false} || {
-      func_quote_for_expand "$my_cmd"
-      eval "func_echo $func_quote_for_expand_result"
-    }
-
-    if ${opt_dry_run-false}; then :; else
-      eval "$my_cmd"
-      my_status=$?
-      if test "$my_status" -eq 0; then :; else
-       eval "(exit $my_status); $my_fail_exp"
-      fi
-    fi
-}
-
-
-# func_show_eval_locale cmd [fail_exp]
-# Unless opt_silent is true, then output CMD.  Then, if opt_dryrun is
-# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
-# is given, then evaluate it.  Use the saved locale for evaluation.
-func_show_eval_locale ()
-{
-    my_cmd="$1"
-    my_fail_exp="${2-:}"
-
-    ${opt_silent-false} || {
-      func_quote_for_expand "$my_cmd"
-      eval "func_echo $func_quote_for_expand_result"
-    }
-
-    if ${opt_dry_run-false}; then :; else
-      eval "$lt_user_locale
-           $my_cmd"
-      my_status=$?
-      eval "$lt_safe_locale"
-      if test "$my_status" -eq 0; then :; else
-       eval "(exit $my_status); $my_fail_exp"
-      fi
-    fi
-}
-
-
-
-
-
-# func_version
-# Echo version message to standard output and exit.
-func_version ()
-{
-    $SED -n '/^# '$PROGRAM' (GNU /,/# warranty; / {
-        s/^# //
-       s/^# *$//
-        s/\((C)\)[ 0-9,-]*\( [1-9][0-9]*\)/\1\2/
-        p
-     }' < "$progpath"
-     exit $?
-}
-
-# func_usage
-# Echo short help message to standard output and exit.
-func_usage ()
-{
-    $SED -n '/^# Usage:/,/# -h/ {
-        s/^# //
-       s/^# *$//
-       s/\$progname/'$progname'/
-       p
-    }' < "$progpath"
-    $ECHO
-    $ECHO "run \`$progname --help | more' for full usage"
-    exit $?
-}
-
-# func_help
-# Echo long help message to standard output and exit.
-func_help ()
-{
-    $SED -n '/^# Usage:/,/# Report bugs to/ {
-        s/^# //
-       s/^# *$//
-       s*\$progname*'$progname'*
-       s*\$host*'"$host"'*
-       s*\$SHELL*'"$SHELL"'*
-       s*\$LTCC*'"$LTCC"'*
-       s*\$LTCFLAGS*'"$LTCFLAGS"'*
-       s*\$LD*'"$LD"'*
-       s/\$with_gnu_ld/'"$with_gnu_ld"'/
-       s/\$automake_version/'"`(automake --version) 2>/dev/null |$SED 1q`"'/
-       s/\$autoconf_version/'"`(autoconf --version) 2>/dev/null |$SED 1q`"'/
-       p
-     }' < "$progpath"
-    exit $?
-}
-
-# func_missing_arg argname
-# Echo program name prefixed message to standard error and set global
-# exit_cmd.
-func_missing_arg ()
-{
-    func_error "missing argument for $1"
-    exit_cmd=exit
-}
-
-exit_cmd=:
-
-
-
-
-
-# Check that we have a working $ECHO.
-if test "X$1" = X--no-reexec; then
-  # Discard the --no-reexec flag, and continue.
-  shift
-elif test "X$1" = X--fallback-echo; then
-  # Avoid inline document here, it may be left over
-  :
-elif test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t'; then
-  # Yippee, $ECHO works!
-  :
-else
-  # Restart under the correct shell, and then maybe $ECHO will work.
-  exec $SHELL "$progpath" --no-reexec ${1+"$@"}
-fi
-
-if test "X$1" = X--fallback-echo; then
-  # used as fallback echo
-  shift
-  cat <<EOF
-$*
-EOF
-  exit $EXIT_SUCCESS
-fi
-
-magic="%%%MAGIC variable%%%"
-magic_exe="%%%MAGIC EXE variable%%%"
-
-# Global variables.
-# $mode is unset
-nonopt=
-execute_dlfiles=
-preserve_args=
-lo2o="s/\\.lo\$/.${objext}/"
-o2lo="s/\\.${objext}\$/.lo/"
-extracted_archives=
-extracted_serial=0
-
-opt_dry_run=false
-opt_duplicate_deps=false
-opt_silent=false
-opt_debug=:
-
-# If this variable is set in any of the actions, the command in it
-# will be execed at the end.  This prevents here-documents from being
-# left over by shells.
-exec_cmd=
-
-# func_fatal_configuration arg...
-# Echo program name prefixed message to standard error, followed by
-# a configuration failure hint, and exit.
-func_fatal_configuration ()
-{
-    func_error ${1+"$@"}
-    func_error "See the $PACKAGE documentation for more information."
-    func_fatal_error "Fatal configuration error."
-}
-
-
-# func_config
-# Display the configuration for all the tags in this script.
-func_config ()
-{
-    re_begincf='^# ### BEGIN LIBTOOL'
-    re_endcf='^# ### END LIBTOOL'
-
-    # Default configuration.
-    $SED "1,/$re_begincf CONFIG/d;/$re_endcf CONFIG/,\$d" < "$progpath"
-
-    # Now print the configurations for the tags.
-    for tagname in $taglist; do
-      $SED -n "/$re_begincf TAG CONFIG: $tagname\$/,/$re_endcf TAG CONFIG: $tagname\$/p" < "$progpath"
-    done
-
-    exit $?
-}
-
-# func_features
-# Display the features supported by this script.
-func_features ()
-{
-    $ECHO "host: $host"
-    if test "$build_libtool_libs" = yes; then
-      $ECHO "enable shared libraries"
-    else
-      $ECHO "disable shared libraries"
-    fi
-    if test "$build_old_libs" = yes; then
-      $ECHO "enable static libraries"
-    else
-      $ECHO "disable static libraries"
-    fi
-
-    exit $?
-}
-
-# func_enable_tag tagname
-# Verify that TAGNAME is valid, and either flag an error and exit, or
-# enable the TAGNAME tag.  We also add TAGNAME to the global $taglist
-# variable here.
-func_enable_tag ()
-{
-  # Global variable:
-  tagname="$1"
-
-  re_begincf="^# ### BEGIN LIBTOOL TAG CONFIG: $tagname\$"
-  re_endcf="^# ### END LIBTOOL TAG CONFIG: $tagname\$"
-  sed_extractcf="/$re_begincf/,/$re_endcf/p"
-
-  # Validate tagname.
-  case $tagname in
-    *[!-_A-Za-z0-9,/]*)
-      func_fatal_error "invalid tag name: $tagname"
-      ;;
-  esac
-
-  # Don't test for the "default" C tag, as we know it's
-  # there but not specially marked.
-  case $tagname in
-    CC) ;;
-    *)
-      if $GREP "$re_begincf" "$progpath" >/dev/null 2>&1; then
-       taglist="$taglist $tagname"
-
-       # Evaluate the configuration.  Be careful to quote the path
-       # and the sed script, to avoid splitting on whitespace, but
-       # also don't use non-portable quotes within backquotes within
-       # quotes we have to do it in 2 steps:
-       extractedcf=`$SED -n -e "$sed_extractcf" < "$progpath"`
-       eval "$extractedcf"
-      else
-       func_error "ignoring unknown tag $tagname"
-      fi
-      ;;
-  esac
-}
-
-# Parse options once, thoroughly.  This comes as soon as possible in
-# the script to make things like `libtool --version' happen quickly.
-{
-
-  # Shorthand for --mode=foo, only valid as the first argument
-  case $1 in
-  clean|clea|cle|cl)
-    shift; set dummy --mode clean ${1+"$@"}; shift
-    ;;
-  compile|compil|compi|comp|com|co|c)
-    shift; set dummy --mode compile ${1+"$@"}; shift
-    ;;
-  execute|execut|execu|exec|exe|ex|e)
-    shift; set dummy --mode execute ${1+"$@"}; shift
-    ;;
-  finish|finis|fini|fin|fi|f)
-    shift; set dummy --mode finish ${1+"$@"}; shift
-    ;;
-  install|instal|insta|inst|ins|in|i)
-    shift; set dummy --mode install ${1+"$@"}; shift
-    ;;
-  link|lin|li|l)
-    shift; set dummy --mode link ${1+"$@"}; shift
-    ;;
-  uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u)
-    shift; set dummy --mode uninstall ${1+"$@"}; shift
-    ;;
-  esac
-
-  # Parse non-mode specific arguments:
-  while test "$#" -gt 0; do
-    opt="$1"
-    shift
-
-    case $opt in
-      --config)                func_config                                     ;;
-
-      --debug)         preserve_args="$preserve_args $opt"
-                       func_echo "enabling shell trace mode"
-                       opt_debug='set -x'
-                       $opt_debug
-                       ;;
-
-      -dlopen)         test "$#" -eq 0 && func_missing_arg "$opt" && break
-                       execute_dlfiles="$execute_dlfiles $1"
-                       shift
-                       ;;
-
-      --dry-run | -n)  opt_dry_run=:                                   ;;
-      --features)       func_features                                  ;;
-      --finish)                mode="finish"                                   ;;
-
-      --mode)          test "$#" -eq 0 && func_missing_arg "$opt" && break
-                       case $1 in
-                         # Valid mode arguments:
-                         clean)        ;;
-                         compile)      ;;
-                         execute)      ;;
-                         finish)       ;;
-                         install)      ;;
-                         link)         ;;
-                         relink)       ;;
-                         uninstall)    ;;
-
-                         # Catch anything else as an error
-                         *) func_error "invalid argument for $opt"
-                            exit_cmd=exit
-                            break
-                            ;;
-                       esac
-
-                       mode="$1"
-                       shift
-                       ;;
-
-      --preserve-dup-deps)
-                       opt_duplicate_deps=:                            ;;
-
-      --quiet|--silent)        preserve_args="$preserve_args $opt"
-                       opt_silent=:
-                       ;;
-
-      --verbose| -v)   preserve_args="$preserve_args $opt"
-                       opt_silent=false
-                       ;;
-
-      --tag)           test "$#" -eq 0 && func_missing_arg "$opt" && break
-                       preserve_args="$preserve_args $opt $1"
-                       func_enable_tag "$1"    # tagname is set here
-                       shift
-                       ;;
-
-      # Separate optargs to long options:
-      -dlopen=*|--mode=*|--tag=*)
-                       func_opt_split "$opt"
-                       set dummy "$func_opt_split_opt" "$func_opt_split_arg" ${1+"$@"}
-                       shift
-                       ;;
-
-      -\?|-h)          func_usage                                      ;;
-      --help)          opt_help=:                                      ;;
-      --version)       func_version                                    ;;
-
-      -*)              func_fatal_help "unrecognized option \`$opt'"   ;;
-
-      *)               nonopt="$opt"
-                       break
-                       ;;
-    esac
-  done
-
-
-  case $host in
-    *cygwin* | *mingw* | *pw32* | *cegcc*)
-      # don't eliminate duplications in $postdeps and $predeps
-      opt_duplicate_compiler_generated_deps=:
-      ;;
-    *)
-      opt_duplicate_compiler_generated_deps=$opt_duplicate_deps
-      ;;
-  esac
-
-  # Having warned about all mis-specified options, bail out if
-  # anything was wrong.
-  $exit_cmd $EXIT_FAILURE
-}
-
-# func_check_version_match
-# Ensure that we are using m4 macros, and libtool script from the same
-# release of libtool.
-func_check_version_match ()
-{
-  if test "$package_revision" != "$macro_revision"; then
-    if test "$VERSION" != "$macro_version"; then
-      if test -z "$macro_version"; then
-        cat >&2 <<_LT_EOF
-$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
-$progname: definition of this LT_INIT comes from an older release.
-$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
-$progname: and run autoconf again.
-_LT_EOF
-      else
-        cat >&2 <<_LT_EOF
-$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
-$progname: definition of this LT_INIT comes from $PACKAGE $macro_version.
-$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
-$progname: and run autoconf again.
-_LT_EOF
-      fi
-    else
-      cat >&2 <<_LT_EOF
-$progname: Version mismatch error.  This is $PACKAGE $VERSION, revision $package_revision,
-$progname: but the definition of this LT_INIT comes from revision $macro_revision.
-$progname: You should recreate aclocal.m4 with macros from revision $package_revision
-$progname: of $PACKAGE $VERSION and run autoconf again.
-_LT_EOF
-    fi
-
-    exit $EXIT_MISMATCH
-  fi
-}
-
-
-## ----------- ##
-##    Main.    ##
-## ----------- ##
-
-$opt_help || {
-  # Sanity checks first:
-  func_check_version_match
-
-  if test "$build_libtool_libs" != yes && test "$build_old_libs" != yes; then
-    func_fatal_configuration "not configured to build any kind of library"
-  fi
-
-  test -z "$mode" && func_fatal_error "error: you must specify a MODE."
-
-
-  # Darwin sucks
-  eval std_shrext=\"$shrext_cmds\"
-
-
-  # Only execute mode is allowed to have -dlopen flags.
-  if test -n "$execute_dlfiles" && test "$mode" != execute; then
-    func_error "unrecognized option \`-dlopen'"
-    $ECHO "$help" 1>&2
-    exit $EXIT_FAILURE
-  fi
-
-  # Change the help message to a mode-specific one.
-  generic_help="$help"
-  help="Try \`$progname --help --mode=$mode' for more information."
-}
-
-
-# func_lalib_p file
-# True iff FILE is a libtool `.la' library or `.lo' object file.
-# This function is only a basic sanity check; it will hardly flush out
-# determined imposters.
-func_lalib_p ()
-{
-    test -f "$1" &&
-      $SED -e 4q "$1" 2>/dev/null \
-        | $GREP "^# Generated by .*$PACKAGE" > /dev/null 2>&1
-}
-
-# func_lalib_unsafe_p file
-# True iff FILE is a libtool `.la' library or `.lo' object file.
-# This function implements the same check as func_lalib_p without
-# resorting to external programs.  To this end, it redirects stdin and
-# closes it afterwards, without saving the original file descriptor.
-# As a safety measure, use it only where a negative result would be
-# fatal anyway.  Works if `file' does not exist.
-func_lalib_unsafe_p ()
-{
-    lalib_p=no
-    if test -f "$1" && test -r "$1" && exec 5<&0 <"$1"; then
-       for lalib_p_l in 1 2 3 4
-       do
-           read lalib_p_line
-           case "$lalib_p_line" in
-               \#\ Generated\ by\ *$PACKAGE* ) lalib_p=yes; break;;
-           esac
-       done
-       exec 0<&5 5<&-
-    fi
-    test "$lalib_p" = yes
-}
-
-# func_ltwrapper_script_p file
-# True iff FILE is a libtool wrapper script
-# This function is only a basic sanity check; it will hardly flush out
-# determined imposters.
-func_ltwrapper_script_p ()
-{
-    func_lalib_p "$1"
-}
-
-# func_ltwrapper_executable_p file
-# True iff FILE is a libtool wrapper executable
-# This function is only a basic sanity check; it will hardly flush out
-# determined imposters.
-func_ltwrapper_executable_p ()
-{
-    func_ltwrapper_exec_suffix=
-    case $1 in
-    *.exe) ;;
-    *) func_ltwrapper_exec_suffix=.exe ;;
-    esac
-    $GREP "$magic_exe" "$1$func_ltwrapper_exec_suffix" >/dev/null 2>&1
-}
-
-# func_ltwrapper_scriptname file
-# Assumes file is an ltwrapper_executable
-# uses $file to determine the appropriate filename for a
-# temporary ltwrapper_script.
-func_ltwrapper_scriptname ()
-{
-    func_ltwrapper_scriptname_result=""
-    if func_ltwrapper_executable_p "$1"; then
-       func_dirname_and_basename "$1" "" "."
-       func_stripname '' '.exe' "$func_basename_result"
-       func_ltwrapper_scriptname_result="$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper"
-    fi
-}
-
-# func_ltwrapper_p file
-# True iff FILE is a libtool wrapper script or wrapper executable
-# This function is only a basic sanity check; it will hardly flush out
-# determined imposters.
-func_ltwrapper_p ()
-{
-    func_ltwrapper_script_p "$1" || func_ltwrapper_executable_p "$1"
-}
-
-
-# func_execute_cmds commands fail_cmd
-# Execute tilde-delimited COMMANDS.
-# If FAIL_CMD is given, eval that upon failure.
-# FAIL_CMD may read-access the current command in variable CMD!
-func_execute_cmds ()
-{
-    $opt_debug
-    save_ifs=$IFS; IFS='~'
-    for cmd in $1; do
-      IFS=$save_ifs
-      eval cmd=\"$cmd\"
-      func_show_eval "$cmd" "${2-:}"
-    done
-    IFS=$save_ifs
-}
-
-
-# func_source file
-# Source FILE, adding directory component if necessary.
-# Note that it is not necessary on cygwin/mingw to append a dot to
-# FILE even if both FILE and FILE.exe exist: automatic-append-.exe
-# behavior happens only for exec(3), not for open(2)!  Also, sourcing
-# `FILE.' does not work on cygwin managed mounts.
-func_source ()
-{
-    $opt_debug
-    case $1 in
-    */* | *\\*)        . "$1" ;;
-    *)         . "./$1" ;;
-    esac
-}
-
-
-# func_infer_tag arg
-# Infer tagged configuration to use if any are available and
-# if one wasn't chosen via the "--tag" command line option.
-# Only attempt this if the compiler in the base compile
-# command doesn't match the default compiler.
-# arg is usually of the form 'gcc ...'
-func_infer_tag ()
-{
-    $opt_debug
-    if test -n "$available_tags" && test -z "$tagname"; then
-      CC_quoted=
-      for arg in $CC; do
-        func_quote_for_eval "$arg"
-       CC_quoted="$CC_quoted $func_quote_for_eval_result"
-      done
-      case $@ in
-      # Blanks in the command may have been stripped by the calling shell,
-      # but not from the CC environment variable when configure was run.
-      " $CC "* | "$CC "* | " `$ECHO $CC` "* | "`$ECHO $CC` "* | " $CC_quoted"* | "$CC_quoted "* | " `$ECHO $CC_quoted` "* | "`$ECHO $CC_quoted` "*) ;;
-      # Blanks at the start of $base_compile will cause this to fail
-      # if we don't check for them as well.
-      *)
-       for z in $available_tags; do
-         if $GREP "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then
-           # Evaluate the configuration.
-           eval "`${SED} -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`"
-           CC_quoted=
-           for arg in $CC; do
-             # Double-quote args containing other shell metacharacters.
-             func_quote_for_eval "$arg"
-             CC_quoted="$CC_quoted $func_quote_for_eval_result"
-           done
-           case "$@ " in
-             " $CC "* | "$CC "* | " `$ECHO $CC` "* | "`$ECHO $CC` "* | " $CC_quoted"* | "$CC_quoted "* | " `$ECHO $CC_quoted` "* | "`$ECHO $CC_quoted` "*)
-             # The compiler in the base compile command matches
-             # the one in the tagged configuration.
-             # Assume this is the tagged configuration we want.
-             tagname=$z
-             break
-             ;;
-           esac
-         fi
-       done
-       # If $tagname still isn't set, then no tagged configuration
-       # was found and let the user know that the "--tag" command
-       # line option must be used.
-       if test -z "$tagname"; then
-         func_echo "unable to infer tagged configuration"
-         func_fatal_error "specify a tag with \`--tag'"
-#      else
-#        func_verbose "using $tagname tagged configuration"
-       fi
-       ;;
-      esac
-    fi
-}
-
-
-
-# func_write_libtool_object output_name pic_name nonpic_name
-# Create a libtool object file (analogous to a ".la" file),
-# but don't create it if we're doing a dry run.
-func_write_libtool_object ()
-{
-    write_libobj=${1}
-    if test "$build_libtool_libs" = yes; then
-      write_lobj=\'${2}\'
-    else
-      write_lobj=none
-    fi
-
-    if test "$build_old_libs" = yes; then
-      write_oldobj=\'${3}\'
-    else
-      write_oldobj=none
-    fi
-
-    $opt_dry_run || {
-      cat >${write_libobj}T <<EOF
-# $write_libobj - a libtool object file
-# Generated by $PROGRAM (GNU $PACKAGE$TIMESTAMP) $VERSION
-#
-# Please DO NOT delete this file!
-# It is necessary for linking the library.
-
-# Name of the PIC object.
-pic_object=$write_lobj
-
-# Name of the non-PIC object
-non_pic_object=$write_oldobj
-
-EOF
-      $MV "${write_libobj}T" "${write_libobj}"
-    }
-}
-
-# func_mode_compile arg...
-func_mode_compile ()
-{
-    $opt_debug
-    # Get the compilation command and the source file.
-    base_compile=
-    srcfile="$nonopt"  #  always keep a non-empty value in "srcfile"
-    suppress_opt=yes
-    suppress_output=
-    arg_mode=normal
-    libobj=
-    later=
-    pie_flag=
-
-    for arg
-    do
-      case $arg_mode in
-      arg  )
-       # do not "continue".  Instead, add this to base_compile
-       lastarg="$arg"
-       arg_mode=normal
-       ;;
-
-      target )
-       libobj="$arg"
-       arg_mode=normal
-       continue
-       ;;
-
-      normal )
-       # Accept any command-line options.
-       case $arg in
-       -o)
-         test -n "$libobj" && \
-           func_fatal_error "you cannot specify \`-o' more than once"
-         arg_mode=target
-         continue
-         ;;
-
-       -pie | -fpie | -fPIE)
-          pie_flag="$pie_flag $arg"
-         continue
-         ;;
-
-       -shared | -static | -prefer-pic | -prefer-non-pic)
-         later="$later $arg"
-         continue
-         ;;
-
-       -no-suppress)
-         suppress_opt=no
-         continue
-         ;;
-
-       -Xcompiler)
-         arg_mode=arg  #  the next one goes into the "base_compile" arg list
-         continue      #  The current "srcfile" will either be retained or
-         ;;            #  replaced later.  I would guess that would be a bug.
-
-       -Wc,*)
-         func_stripname '-Wc,' '' "$arg"
-         args=$func_stripname_result
-         lastarg=
-         save_ifs="$IFS"; IFS=','
-         for arg in $args; do
-           IFS="$save_ifs"
-           func_quote_for_eval "$arg"
-           lastarg="$lastarg $func_quote_for_eval_result"
-         done
-         IFS="$save_ifs"
-         func_stripname ' ' '' "$lastarg"
-         lastarg=$func_stripname_result
-
-         # Add the arguments to base_compile.
-         base_compile="$base_compile $lastarg"
-         continue
-         ;;
-
-       *)
-         # Accept the current argument as the source file.
-         # The previous "srcfile" becomes the current argument.
-         #
-         lastarg="$srcfile"
-         srcfile="$arg"
-         ;;
-       esac  #  case $arg
-       ;;
-      esac    #  case $arg_mode
-
-      # Aesthetically quote the previous argument.
-      func_quote_for_eval "$lastarg"
-      base_compile="$base_compile $func_quote_for_eval_result"
-    done # for arg
-
-    case $arg_mode in
-    arg)
-      func_fatal_error "you must specify an argument for -Xcompile"
-      ;;
-    target)
-      func_fatal_error "you must specify a target with \`-o'"
-      ;;
-    *)
-      # Get the name of the library object.
-      test -z "$libobj" && {
-       func_basename "$srcfile"
-       libobj="$func_basename_result"
-      }
-      ;;
-    esac
-
-    # Recognize several different file suffixes.
-    # If the user specifies -o file.o, it is replaced with file.lo
-    case $libobj in
-    *.[cCFSifmso] | \
-    *.ada | *.adb | *.ads | *.asm | \
-    *.c++ | *.cc | *.ii | *.class | *.cpp | *.cxx | \
-    *.[fF][09]? | *.for | *.java | *.obj | *.sx)
-      func_xform "$libobj"
-      libobj=$func_xform_result
-      ;;
-    esac
-
-    case $libobj in
-    *.lo) func_lo2o "$libobj"; obj=$func_lo2o_result ;;
-    *)
-      func_fatal_error "cannot determine name of library object from \`$libobj'"
-      ;;
-    esac
-
-    func_infer_tag $base_compile
-
-    for arg in $later; do
-      case $arg in
-      -shared)
-       test "$build_libtool_libs" != yes && \
-         func_fatal_configuration "can not build a shared library"
-       build_old_libs=no
-       continue
-       ;;
-
-      -static)
-       build_libtool_libs=no
-       build_old_libs=yes
-       continue
-       ;;
-
-      -prefer-pic)
-       pic_mode=yes
-       continue
-       ;;
-
-      -prefer-non-pic)
-       pic_mode=no
-       continue
-       ;;
-      esac
-    done
-
-    func_quote_for_eval "$libobj"
-    test "X$libobj" != "X$func_quote_for_eval_result" \
-      && $ECHO "X$libobj" | $GREP '[]~#^*{};<>?"'"'"'   &()|`$[]' \
-      && func_warning "libobj name \`$libobj' may not contain shell special characters."
-    func_dirname_and_basename "$obj" "/" ""
-    objname="$func_basename_result"
-    xdir="$func_dirname_result"
-    lobj=${xdir}$objdir/$objname
-
-    test -z "$base_compile" && \
-      func_fatal_help "you must specify a compilation command"
-
-    # Delete any leftover library objects.
-    if test "$build_old_libs" = yes; then
-      removelist="$obj $lobj $libobj ${libobj}T"
-    else
-      removelist="$lobj $libobj ${libobj}T"
-    fi
-
-    # On Cygwin there's no "real" PIC flag so we must build both object types
-    case $host_os in
-    cygwin* | mingw* | pw32* | os2* | cegcc*)
-      pic_mode=default
-      ;;
-    esac
-    if test "$pic_mode" = no && test "$deplibs_check_method" != pass_all; then
-      # non-PIC code in shared libraries is not supported
-      pic_mode=default
-    fi
-
-    # Calculate the filename of the output object if compiler does
-    # not support -o with -c
-    if test "$compiler_c_o" = no; then
-      output_obj=`$ECHO "X$srcfile" | $Xsed -e 's%^.*/%%' -e 's%\.[^.]*$%%'`.${objext}
-      lockfile="$output_obj.lock"
-    else
-      output_obj=
-      need_locks=no
-      lockfile=
-    fi
-
-    # Lock this critical section if it is needed
-    # We use this script file to make the link, it avoids creating a new file
-    if test "$need_locks" = yes; then
-      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
-       func_echo "Waiting for $lockfile to be removed"
-       sleep 2
-      done
-    elif test "$need_locks" = warn; then
-      if test -f "$lockfile"; then
-       $ECHO "\
-*** ERROR, $lockfile exists and contains:
-`cat $lockfile 2>/dev/null`
-
-This indicates that another process is trying to use the same
-temporary object file, and libtool could not work around it because
-your compiler does not support \`-c' and \`-o' together.  If you
-repeat this compilation, it may succeed, by chance, but you had better
-avoid parallel builds (make -j) in this platform, or get a better
-compiler."
-
-       $opt_dry_run || $RM $removelist
-       exit $EXIT_FAILURE
-      fi
-      removelist="$removelist $output_obj"
-      $ECHO "$srcfile" > "$lockfile"
-    fi
-
-    $opt_dry_run || $RM $removelist
-    removelist="$removelist $lockfile"
-    trap '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' 1 2 15
-
-    if test -n "$fix_srcfile_path"; then
-      eval srcfile=\"$fix_srcfile_path\"
-    fi
-    func_quote_for_eval "$srcfile"
-    qsrcfile=$func_quote_for_eval_result
-
-    # Only build a PIC object if we are building libtool libraries.
-    if test "$build_libtool_libs" = yes; then
-      # Without this assignment, base_compile gets emptied.
-      fbsd_hideous_sh_bug=$base_compile
-
-      if test "$pic_mode" != no; then
-       command="$base_compile $qsrcfile $pic_flag"
-      else
-       # Don't build PIC code
-       command="$base_compile $qsrcfile"
-      fi
-
-      func_mkdir_p "$xdir$objdir"
-
-      if test -z "$output_obj"; then
-       # Place PIC objects in $objdir
-       command="$command -o $lobj"
-      fi
-
-      func_show_eval_locale "$command" \
-          'test -n "$output_obj" && $RM $removelist; exit $EXIT_FAILURE'
-
-      if test "$need_locks" = warn &&
-        test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
-       $ECHO "\
-*** ERROR, $lockfile contains:
-`cat $lockfile 2>/dev/null`
-
-but it should contain:
-$srcfile
-
-This indicates that another process is trying to use the same
-temporary object file, and libtool could not work around it because
-your compiler does not support \`-c' and \`-o' together.  If you
-repeat this compilation, it may succeed, by chance, but you had better
-avoid parallel builds (make -j) in this platform, or get a better
-compiler."
-
-       $opt_dry_run || $RM $removelist
-       exit $EXIT_FAILURE
-      fi
-
-      # Just move the object if needed, then go on to compile the next one
-      if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then
-       func_show_eval '$MV "$output_obj" "$lobj"' \
-         'error=$?; $opt_dry_run || $RM $removelist; exit $error'
-      fi
-
-      # Allow error messages only from the first compilation.
-      if test "$suppress_opt" = yes; then
-       suppress_output=' >/dev/null 2>&1'
-      fi
-    fi
-
-    # Only build a position-dependent object if we build old libraries.
-    if test "$build_old_libs" = yes; then
-      if test "$pic_mode" != yes; then
-       # Don't build PIC code
-       command="$base_compile $qsrcfile$pie_flag"
-      else
-       command="$base_compile $qsrcfile $pic_flag"
-      fi
-      if test "$compiler_c_o" = yes; then
-       command="$command -o $obj"
-      fi
-
-      # Suppress compiler output if we already did a PIC compilation.
-      command="$command$suppress_output"
-      func_show_eval_locale "$command" \
-        '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE'
-
-      if test "$need_locks" = warn &&
-        test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
-       $ECHO "\
-*** ERROR, $lockfile contains:
-`cat $lockfile 2>/dev/null`
-
-but it should contain:
-$srcfile
-
-This indicates that another process is trying to use the same
-temporary object file, and libtool could not work around it because
-your compiler does not support \`-c' and \`-o' together.  If you
-repeat this compilation, it may succeed, by chance, but you had better
-avoid parallel builds (make -j) in this platform, or get a better
-compiler."
-
-       $opt_dry_run || $RM $removelist
-       exit $EXIT_FAILURE
-      fi
-
-      # Just move the object if needed
-      if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then
-       func_show_eval '$MV "$output_obj" "$obj"' \
-         'error=$?; $opt_dry_run || $RM $removelist; exit $error'
-      fi
-    fi
-
-    $opt_dry_run || {
-      func_write_libtool_object "$libobj" "$objdir/$objname" "$objname"
-
-      # Unlock the critical section if it was locked
-      if test "$need_locks" != no; then
-       removelist=$lockfile
-        $RM "$lockfile"
-      fi
-    }
-
-    exit $EXIT_SUCCESS
-}
-
-$opt_help || {
-test "$mode" = compile && func_mode_compile ${1+"$@"}
-}
-
-func_mode_help ()
-{
-    # We need to display help for each of the modes.
-    case $mode in
-      "")
-        # Generic help is extracted from the usage comments
-        # at the start of this file.
-        func_help
-        ;;
-
-      clean)
-        $ECHO \
-"Usage: $progname [OPTION]... --mode=clean RM [RM-OPTION]... FILE...
-
-Remove files from the build directory.
-
-RM is the name of the program to use to delete files associated with each FILE
-(typically \`/bin/rm').  RM-OPTIONS are options (such as \`-f') to be passed
-to RM.
-
-If FILE is a libtool library, object or program, all the files associated
-with it are deleted. Otherwise, only FILE itself is deleted using RM."
-        ;;
-
-      compile)
-      $ECHO \
-"Usage: $progname [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE
-
-Compile a source file into a libtool library object.
-
-This mode accepts the following additional options:
-
-  -o OUTPUT-FILE    set the output file name to OUTPUT-FILE
-  -no-suppress      do not suppress compiler output for multiple passes
-  -prefer-pic       try to building PIC objects only
-  -prefer-non-pic   try to building non-PIC objects only
-  -shared           do not build a \`.o' file suitable for static linking
-  -static           only build a \`.o' file suitable for static linking
-
-COMPILE-COMMAND is a command to be used in creating a \`standard' object file
-from the given SOURCEFILE.
-
-The output file name is determined by removing the directory component from
-SOURCEFILE, then substituting the C source code suffix \`.c' with the
-library object suffix, \`.lo'."
-        ;;
-
-      execute)
-        $ECHO \
-"Usage: $progname [OPTION]... --mode=execute COMMAND [ARGS]...
-
-Automatically set library path, then run a program.
-
-This mode accepts the following additional options:
-
-  -dlopen FILE      add the directory containing FILE to the library path
-
-This mode sets the library path environment variable according to \`-dlopen'
-flags.
-
-If any of the ARGS are libtool executable wrappers, then they are translated
-into their corresponding uninstalled binary, and any of their required library
-directories are added to the library path.
-
-Then, COMMAND is executed, with ARGS as arguments."
-        ;;
-
-      finish)
-        $ECHO \
-"Usage: $progname [OPTION]... --mode=finish [LIBDIR]...
-
-Complete the installation of libtool libraries.
-
-Each LIBDIR is a directory that contains libtool libraries.
-
-The commands that this mode executes may require superuser privileges.  Use
-the \`--dry-run' option if you just want to see what would be executed."
-        ;;
-
-      install)
-        $ECHO \
-"Usage: $progname [OPTION]... --mode=install INSTALL-COMMAND...
-
-Install executables or libraries.
-
-INSTALL-COMMAND is the installation command.  The first component should be
-either the \`install' or \`cp' program.
-
-The following components of INSTALL-COMMAND are treated specially:
-
-  -inst-prefix PREFIX-DIR  Use PREFIX-DIR as a staging area for installation
-
-The rest of the components are interpreted as arguments to that command (only
-BSD-compatible install options are recognized)."
-        ;;
-
-      link)
-        $ECHO \
-"Usage: $progname [OPTION]... --mode=link LINK-COMMAND...
-
-Link object files or libraries together to form another library, or to
-create an executable program.
-
-LINK-COMMAND is a command using the C compiler that you would use to create
-a program from several object files.
-
-The following components of LINK-COMMAND are treated specially:
-
-  -all-static       do not do any dynamic linking at all
-  -avoid-version    do not add a version suffix if possible
-  -dlopen FILE      \`-dlpreopen' FILE if it cannot be dlopened at runtime
-  -dlpreopen FILE   link in FILE and add its symbols to lt_preloaded_symbols
-  -export-dynamic   allow symbols from OUTPUT-FILE to be resolved with dlsym(3)
-  -export-symbols SYMFILE
-                    try to export only the symbols listed in SYMFILE
-  -export-symbols-regex REGEX
-                    try to export only the symbols matching REGEX
-  -LLIBDIR          search LIBDIR for required installed libraries
-  -lNAME            OUTPUT-FILE requires the installed library libNAME
-  -module           build a library that can dlopened
-  -no-fast-install  disable the fast-install mode
-  -no-install       link a not-installable executable
-  -no-undefined     declare that a library does not refer to external symbols
-  -o OUTPUT-FILE    create OUTPUT-FILE from the specified objects
-  -objectlist FILE  Use a list of object files found in FILE to specify objects
-  -precious-files-regex REGEX
-                    don't remove output files matching REGEX
-  -release RELEASE  specify package release information
-  -rpath LIBDIR     the created library will eventually be installed in LIBDIR
-  -R[ ]LIBDIR       add LIBDIR to the runtime path of programs and libraries
-  -shared           only do dynamic linking of libtool libraries
-  -shrext SUFFIX    override the standard shared library file extension
-  -static           do not do any dynamic linking of uninstalled libtool libraries
-  -static-libtool-libs
-                    do not do any dynamic linking of libtool libraries
-  -version-info CURRENT[:REVISION[:AGE]]
-                    specify library version info [each variable defaults to 0]
-  -weak LIBNAME     declare that the target provides the LIBNAME interface
-
-All other options (arguments beginning with \`-') are ignored.
-
-Every other argument is treated as a filename.  Files ending in \`.la' are
-treated as uninstalled libtool libraries, other files are standard or library
-object files.
-
-If the OUTPUT-FILE ends in \`.la', then a libtool library is created,
-only library objects (\`.lo' files) may be specified, and \`-rpath' is
-required, except when creating a convenience library.
-
-If OUTPUT-FILE ends in \`.a' or \`.lib', then a standard library is created
-using \`ar' and \`ranlib', or on Windows using \`lib'.
-
-If OUTPUT-FILE ends in \`.lo' or \`.${objext}', then a reloadable object file
-is created, otherwise an executable program is created."
-        ;;
-
-      uninstall)
-        $ECHO \
-"Usage: $progname [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE...
-
-Remove libraries from an installation directory.
-
-RM is the name of the program to use to delete files associated with each FILE
-(typically \`/bin/rm').  RM-OPTIONS are options (such as \`-f') to be passed
-to RM.
-
-If FILE is a libtool library, all the files associated with it are deleted.
-Otherwise, only FILE itself is deleted using RM."
-        ;;
-
-      *)
-        func_fatal_help "invalid operation mode \`$mode'"
-        ;;
-    esac
-
-    $ECHO
-    $ECHO "Try \`$progname --help' for more information about other modes."
-
-    exit $?
-}
-
-  # Now that we've collected a possible --mode arg, show help if necessary
-  $opt_help && func_mode_help
-
-
-# func_mode_execute arg...
-func_mode_execute ()
-{
-    $opt_debug
-    # The first argument is the command name.
-    cmd="$nonopt"
-    test -z "$cmd" && \
-      func_fatal_help "you must specify a COMMAND"
-
-    # Handle -dlopen flags immediately.
-    for file in $execute_dlfiles; do
-      test -f "$file" \
-       || func_fatal_help "\`$file' is not a file"
-
-      dir=
-      case $file in
-      *.la)
-       # Check to see that this really is a libtool archive.
-       func_lalib_unsafe_p "$file" \
-         || func_fatal_help "\`$lib' is not a valid libtool archive"
-
-       # Read the libtool library.
-       dlname=
-       library_names=
-       func_source "$file"
-
-       # Skip this library if it cannot be dlopened.
-       if test -z "$dlname"; then
-         # Warn if it was a shared library.
-         test -n "$library_names" && \
-           func_warning "\`$file' was not linked with \`-export-dynamic'"
-         continue
-       fi
-
-       func_dirname "$file" "" "."
-       dir="$func_dirname_result"
-
-       if test -f "$dir/$objdir/$dlname"; then
-         dir="$dir/$objdir"
-       else
-         if test ! -f "$dir/$dlname"; then
-           func_fatal_error "cannot find \`$dlname' in \`$dir' or \`$dir/$objdir'"
-         fi
-       fi
-       ;;
-
-      *.lo)
-       # Just add the directory containing the .lo file.
-       func_dirname "$file" "" "."
-       dir="$func_dirname_result"
-       ;;
-
-      *)
-       func_warning "\`-dlopen' is ignored for non-libtool libraries and objects"
-       continue
-       ;;
-      esac
-
-      # Get the absolute pathname.
-      absdir=`cd "$dir" && pwd`
-      test -n "$absdir" && dir="$absdir"
-
-      # Now add the directory to shlibpath_var.
-      if eval "test -z \"\$$shlibpath_var\""; then
-       eval "$shlibpath_var=\"\$dir\""
-      else
-       eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\""
-      fi
-    done
-
-    # This variable tells wrapper scripts just to set shlibpath_var
-    # rather than running their programs.
-    libtool_execute_magic="$magic"
-
-    # Check if any of the arguments is a wrapper script.
-    args=
-    for file
-    do
-      case $file in
-      -*) ;;
-      *)
-       # Do a test to see if this is really a libtool program.
-       if func_ltwrapper_script_p "$file"; then
-         func_source "$file"
-         # Transform arg to wrapped name.
-         file="$progdir/$program"
-       elif func_ltwrapper_executable_p "$file"; then
-         func_ltwrapper_scriptname "$file"
-         func_source "$func_ltwrapper_scriptname_result"
-         # Transform arg to wrapped name.
-         file="$progdir/$program"
-       fi
-       ;;
-      esac
-      # Quote arguments (to preserve shell metacharacters).
-      func_quote_for_eval "$file"
-      args="$args $func_quote_for_eval_result"
-    done
-
-    if test "X$opt_dry_run" = Xfalse; then
-      if test -n "$shlibpath_var"; then
-       # Export the shlibpath_var.
-       eval "export $shlibpath_var"
-      fi
-
-      # Restore saved environment variables
-      for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
-      do
-       eval "if test \"\${save_$lt_var+set}\" = set; then
-                $lt_var=\$save_$lt_var; export $lt_var
-             else
-               $lt_unset $lt_var
-             fi"
-      done
-
-      # Now prepare to actually exec the command.
-      exec_cmd="\$cmd$args"
-    else
-      # Display what would be done.
-      if test -n "$shlibpath_var"; then
-       eval "\$ECHO \"\$shlibpath_var=\$$shlibpath_var\""
-       $ECHO "export $shlibpath_var"
-      fi
-      $ECHO "$cmd$args"
-      exit $EXIT_SUCCESS
-    fi
-}
-
-test "$mode" = execute && func_mode_execute ${1+"$@"}
-
-
-# func_mode_finish arg...
-func_mode_finish ()
-{
-    $opt_debug
-    libdirs="$nonopt"
-    admincmds=
-
-    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
-      for dir
-      do
-       libdirs="$libdirs $dir"
-      done
-
-      for libdir in $libdirs; do
-       if test -n "$finish_cmds"; then
-         # Do each command in the finish commands.
-         func_execute_cmds "$finish_cmds" 'admincmds="$admincmds
-'"$cmd"'"'
-       fi
-       if test -n "$finish_eval"; then
-         # Do the single finish_eval.
-         eval cmds=\"$finish_eval\"
-         $opt_dry_run || eval "$cmds" || admincmds="$admincmds
-       $cmds"
-       fi
-      done
-    fi
-
-    # Exit here if they wanted silent mode.
-    $opt_silent && exit $EXIT_SUCCESS
-
-    $ECHO "X----------------------------------------------------------------------" | $Xsed
-    $ECHO "Libraries have been installed in:"
-    for libdir in $libdirs; do
-      $ECHO "   $libdir"
-    done
-    $ECHO
-    $ECHO "If you ever happen to want to link against installed libraries"
-    $ECHO "in a given directory, LIBDIR, you must either use libtool, and"
-    $ECHO "specify the full pathname of the library, or use the \`-LLIBDIR'"
-    $ECHO "flag during linking and do at least one of the following:"
-    if test -n "$shlibpath_var"; then
-      $ECHO "   - add LIBDIR to the \`$shlibpath_var' environment variable"
-      $ECHO "     during execution"
-    fi
-    if test -n "$runpath_var"; then
-      $ECHO "   - add LIBDIR to the \`$runpath_var' environment variable"
-      $ECHO "     during linking"
-    fi
-    if test -n "$hardcode_libdir_flag_spec"; then
-      libdir=LIBDIR
-      eval flag=\"$hardcode_libdir_flag_spec\"
-
-      $ECHO "   - use the \`$flag' linker flag"
-    fi
-    if test -n "$admincmds"; then
-      $ECHO "   - have your system administrator run these commands:$admincmds"
-    fi
-    if test -f /etc/ld.so.conf; then
-      $ECHO "   - have your system administrator add LIBDIR to \`/etc/ld.so.conf'"
-    fi
-    $ECHO
-
-    $ECHO "See any operating system documentation about shared libraries for"
-    case $host in
-      solaris2.[6789]|solaris2.1[0-9])
-        $ECHO "more information, such as the ld(1), crle(1) and ld.so(8) manual"
-       $ECHO "pages."
-       ;;
-      *)
-        $ECHO "more information, such as the ld(1) and ld.so(8) manual pages."
-        ;;
-    esac
-    $ECHO "X----------------------------------------------------------------------" | $Xsed
-    exit $EXIT_SUCCESS
-}
-
-test "$mode" = finish && func_mode_finish ${1+"$@"}
-
-
-# func_mode_install arg...
-func_mode_install ()
-{
-    $opt_debug
-    # There may be an optional sh(1) argument at the beginning of
-    # install_prog (especially on Windows NT).
-    if test "$nonopt" = "$SHELL" || test "$nonopt" = /bin/sh ||
-       # Allow the use of GNU shtool's install command.
-       $ECHO "X$nonopt" | $GREP shtool >/dev/null; then
-      # Aesthetically quote it.
-      func_quote_for_eval "$nonopt"
-      install_prog="$func_quote_for_eval_result "
-      arg=$1
-      shift
-    else
-      install_prog=
-      arg=$nonopt
-    fi
-
-    # The real first argument should be the name of the installation program.
-    # Aesthetically quote it.
-    func_quote_for_eval "$arg"
-    install_prog="$install_prog$func_quote_for_eval_result"
-
-    # We need to accept at least all the BSD install flags.
-    dest=
-    files=
-    opts=
-    prev=
-    install_type=
-    isdir=no
-    stripme=
-    for arg
-    do
-      if test -n "$dest"; then
-       files="$files $dest"
-       dest=$arg
-       continue
-      fi
-
-      case $arg in
-      -d) isdir=yes ;;
-      -f)
-       case " $install_prog " in
-       *[\\\ /]cp\ *) ;;
-       *) prev=$arg ;;
-       esac
-       ;;
-      -g | -m | -o)
-       prev=$arg
-       ;;
-      -s)
-       stripme=" -s"
-       continue
-       ;;
-      -*)
-       ;;
-      *)
-       # If the previous option needed an argument, then skip it.
-       if test -n "$prev"; then
-         prev=
-       else
-         dest=$arg
-         continue
-       fi
-       ;;
-      esac
-
-      # Aesthetically quote the argument.
-      func_quote_for_eval "$arg"
-      install_prog="$install_prog $func_quote_for_eval_result"
-    done
-
-    test -z "$install_prog" && \
-      func_fatal_help "you must specify an install program"
-
-    test -n "$prev" && \
-      func_fatal_help "the \`$prev' option requires an argument"
-
-    if test -z "$files"; then
-      if test -z "$dest"; then
-       func_fatal_help "no file or destination specified"
-      else
-       func_fatal_help "you must specify a destination"
-      fi
-    fi
-
-    # Strip any trailing slash from the destination.
-    func_stripname '' '/' "$dest"
-    dest=$func_stripname_result
-
-    # Check to see that the destination is a directory.
-    test -d "$dest" && isdir=yes
-    if test "$isdir" = yes; then
-      destdir="$dest"
-      destname=
-    else
-      func_dirname_and_basename "$dest" "" "."
-      destdir="$func_dirname_result"
-      destname="$func_basename_result"
-
-      # Not a directory, so check to see that there is only one file specified.
-      set dummy $files; shift
-      test "$#" -gt 1 && \
-       func_fatal_help "\`$dest' is not a directory"
-    fi
-    case $destdir in
-    [\\/]* | [A-Za-z]:[\\/]*) ;;
-    *)
-      for file in $files; do
-       case $file in
-       *.lo) ;;
-       *)
-         func_fatal_help "\`$destdir' must be an absolute directory name"
-         ;;
-       esac
-      done
-      ;;
-    esac
-
-    # This variable tells wrapper scripts just to set variables rather
-    # than running their programs.
-    libtool_install_magic="$magic"
-
-    staticlibs=
-    future_libdirs=
-    current_libdirs=
-    for file in $files; do
-
-      # Do each installation.
-      case $file in
-      *.$libext)
-       # Do the static libraries later.
-       staticlibs="$staticlibs $file"
-       ;;
-
-      *.la)
-       # Check to see that this really is a libtool archive.
-       func_lalib_unsafe_p "$file" \
-         || func_fatal_help "\`$file' is not a valid libtool archive"
-
-       library_names=
-       old_library=
-       relink_command=
-       func_source "$file"
-
-       # Add the libdir to current_libdirs if it is the destination.
-       if test "X$destdir" = "X$libdir"; then
-         case "$current_libdirs " in
-         *" $libdir "*) ;;
-         *) current_libdirs="$current_libdirs $libdir" ;;
-         esac
-       else
-         # Note the libdir as a future libdir.
-         case "$future_libdirs " in
-         *" $libdir "*) ;;
-         *) future_libdirs="$future_libdirs $libdir" ;;
-         esac
-       fi
-
-       func_dirname "$file" "/" ""
-       dir="$func_dirname_result"
-       dir="$dir$objdir"
-
-       if test -n "$relink_command"; then
-         # Determine the prefix the user has applied to our future dir.
-         inst_prefix_dir=`$ECHO "X$destdir" | $Xsed -e "s%$libdir\$%%"`
-
-         # Don't allow the user to place us outside of our expected
-         # location b/c this prevents finding dependent libraries that
-         # are installed to the same prefix.
-         # At present, this check doesn't affect windows .dll's that
-         # are installed into $libdir/../bin (currently, that works fine)
-         # but it's something to keep an eye on.
-         test "$inst_prefix_dir" = "$destdir" && \
-           func_fatal_error "error: cannot install \`$file' to a directory not ending in $libdir"
-
-         if test -n "$inst_prefix_dir"; then
-           # Stick the inst_prefix_dir data into the link command.
-           relink_command=`$ECHO "X$relink_command" | $Xsed -e "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%"`
-         else
-           relink_command=`$ECHO "X$relink_command" | $Xsed -e "s%@inst_prefix_dir@%%"`
-         fi
-
-         func_warning "relinking \`$file'"
-         func_show_eval "$relink_command" \
-           'func_fatal_error "error: relink \`$file'\'' with the above command before installing it"'
-       fi
-
-       # See the names of the shared library.
-       set dummy $library_names; shift
-       if test -n "$1"; then
-         realname="$1"
-         shift
-
-         srcname="$realname"
-         test -n "$relink_command" && srcname="$realname"T
-
-         # Install the shared library and build the symlinks.
-         func_show_eval "$install_prog $dir/$srcname $destdir/$realname" \
-             'exit $?'
-         tstripme="$stripme"
-         case $host_os in
-         cygwin* | mingw* | pw32* | cegcc*)
-           case $realname in
-           *.dll.a)
-             tstripme=""
-             ;;
-           esac
-           ;;
-         esac
-         if test -n "$tstripme" && test -n "$striplib"; then
-           func_show_eval "$striplib $destdir/$realname" 'exit $?'
-         fi
-
-         if test "$#" -gt 0; then
-           # Delete the old symlinks, and create new ones.
-           # Try `ln -sf' first, because the `ln' binary might depend on
-           # the symlink we replace!  Solaris /bin/ln does not understand -f,
-           # so we also need to try rm && ln -s.
-           for linkname
-           do
-             test "$linkname" != "$realname" \
-               && func_show_eval "(cd $destdir && { $LN_S -f $realname $linkname || { $RM $linkname && $LN_S $realname $linkname; }; })"
-           done
-         fi
-
-         # Do each command in the postinstall commands.
-         lib="$destdir/$realname"
-         func_execute_cmds "$postinstall_cmds" 'exit $?'
-       fi
-
-       # Install the pseudo-library for information purposes.
-       func_basename "$file"
-       name="$func_basename_result"
-       instname="$dir/$name"i
-       func_show_eval "$install_prog $instname $destdir/$name" 'exit $?'
-
-       # Maybe install the static library, too.
-       test -n "$old_library" && staticlibs="$staticlibs $dir/$old_library"
-       ;;
-
-      *.lo)
-       # Install (i.e. copy) a libtool object.
-
-       # Figure out destination file name, if it wasn't already specified.
-       if test -n "$destname"; then
-         destfile="$destdir/$destname"
-       else
-         func_basename "$file"
-         destfile="$func_basename_result"
-         destfile="$destdir/$destfile"
-       fi
-
-       # Deduce the name of the destination old-style object file.
-       case $destfile in
-       *.lo)
-         func_lo2o "$destfile"
-         staticdest=$func_lo2o_result
-         ;;
-       *.$objext)
-         staticdest="$destfile"
-         destfile=
-         ;;
-       *)
-         func_fatal_help "cannot copy a libtool object to \`$destfile'"
-         ;;
-       esac
-
-       # Install the libtool object if requested.
-       test -n "$destfile" && \
-         func_show_eval "$install_prog $file $destfile" 'exit $?'
-
-       # Install the old object if enabled.
-       if test "$build_old_libs" = yes; then
-         # Deduce the name of the old-style object file.
-         func_lo2o "$file"
-         staticobj=$func_lo2o_result
-         func_show_eval "$install_prog \$staticobj \$staticdest" 'exit $?'
-       fi
-       exit $EXIT_SUCCESS
-       ;;
-
-      *)
-       # Figure out destination file name, if it wasn't already specified.
-       if test -n "$destname"; then
-         destfile="$destdir/$destname"
-       else
-         func_basename "$file"
-         destfile="$func_basename_result"
-         destfile="$destdir/$destfile"
-       fi
-
-       # If the file is missing, and there is a .exe on the end, strip it
-       # because it is most likely a libtool script we actually want to
-       # install
-       stripped_ext=""
-       case $file in
-         *.exe)
-           if test ! -f "$file"; then
-             func_stripname '' '.exe' "$file"
-             file=$func_stripname_result
-             stripped_ext=".exe"
-           fi
-           ;;
-       esac
-
-       # Do a test to see if this is really a libtool program.
-       case $host in
-       *cygwin* | *mingw*)
-           if func_ltwrapper_executable_p "$file"; then
-             func_ltwrapper_scriptname "$file"
-             wrapper=$func_ltwrapper_scriptname_result
-           else
-             func_stripname '' '.exe' "$file"
-             wrapper=$func_stripname_result
-           fi
-           ;;
-       *)
-           wrapper=$file
-           ;;
-       esac
-       if func_ltwrapper_script_p "$wrapper"; then
-         notinst_deplibs=
-         relink_command=
-
-         func_source "$wrapper"
-
-         # Check the variables that should have been set.
-         test -z "$generated_by_libtool_version" && \
-           func_fatal_error "invalid libtool wrapper script \`$wrapper'"
-
-         finalize=yes
-         for lib in $notinst_deplibs; do
-           # Check to see that each library is installed.
-           libdir=
-           if test -f "$lib"; then
-             func_source "$lib"
-           fi
-           libfile="$libdir/"`$ECHO "X$lib" | $Xsed -e 's%^.*/%%g'` ### testsuite: skip nested quoting test
-           if test -n "$libdir" && test ! -f "$libfile"; then
-             func_warning "\`$lib' has not been installed in \`$libdir'"
-             finalize=no
-           fi
-         done
-
-         relink_command=
-         func_source "$wrapper"
-
-         outputname=
-         if test "$fast_install" = no && test -n "$relink_command"; then
-           $opt_dry_run || {
-             if test "$finalize" = yes; then
-               tmpdir=`func_mktempdir`
-               func_basename "$file$stripped_ext"
-               file="$func_basename_result"
-               outputname="$tmpdir/$file"
-               # Replace the output file specification.
-               relink_command=`$ECHO "X$relink_command" | $Xsed -e 's%@OUTPUT@%'"$outputname"'%g'`
-
-               $opt_silent || {
-                 func_quote_for_expand "$relink_command"
-                 eval "func_echo $func_quote_for_expand_result"
-               }
-               if eval "$relink_command"; then :
-                 else
-                 func_error "error: relink \`$file' with the above command before installing it"
-                 $opt_dry_run || ${RM}r "$tmpdir"
-                 continue
-               fi
-               file="$outputname"
-             else
-               func_warning "cannot relink \`$file'"
-             fi
-           }
-         else
-           # Install the binary that we compiled earlier.
-           file=`$ECHO "X$file$stripped_ext" | $Xsed -e "s%\([^/]*\)$%$objdir/\1%"`
-         fi
-       fi
-
-       # remove .exe since cygwin /usr/bin/install will append another
-       # one anyway
-       case $install_prog,$host in
-       */usr/bin/install*,*cygwin*)
-         case $file:$destfile in
-         *.exe:*.exe)
-           # this is ok
-           ;;
-         *.exe:*)
-           destfile=$destfile.exe
-           ;;
-         *:*.exe)
-           func_stripname '' '.exe' "$destfile"
-           destfile=$func_stripname_result
-           ;;
-         esac
-         ;;
-       esac
-       func_show_eval "$install_prog\$stripme \$file \$destfile" 'exit $?'
-       $opt_dry_run || if test -n "$outputname"; then
-         ${RM}r "$tmpdir"
-       fi
-       ;;
-      esac
-    done
-
-    for file in $staticlibs; do
-      func_basename "$file"
-      name="$func_basename_result"
-
-      # Set up the ranlib parameters.
-      oldlib="$destdir/$name"
-
-      func_show_eval "$install_prog \$file \$oldlib" 'exit $?'
-
-      if test -n "$stripme" && test -n "$old_striplib"; then
-       func_show_eval "$old_striplib $oldlib" 'exit $?'
-      fi
-
-      # Do each command in the postinstall commands.
-      func_execute_cmds "$old_postinstall_cmds" 'exit $?'
-    done
-
-    test -n "$future_libdirs" && \
-      func_warning "remember to run \`$progname --finish$future_libdirs'"
-
-    if test -n "$current_libdirs"; then
-      # Maybe just do a dry run.
-      $opt_dry_run && current_libdirs=" -n$current_libdirs"
-      exec_cmd='$SHELL $progpath $preserve_args --finish$current_libdirs'
-    else
-      exit $EXIT_SUCCESS
-    fi
-}
-
-test "$mode" = install && func_mode_install ${1+"$@"}
-
-
-# func_generate_dlsyms outputname originator pic_p
-# Extract symbols from dlprefiles and create ${outputname}S.o with
-# a dlpreopen symbol table.
-func_generate_dlsyms ()
-{
-    $opt_debug
-    my_outputname="$1"
-    my_originator="$2"
-    my_pic_p="${3-no}"
-    my_prefix=`$ECHO "$my_originator" | sed 's%[^a-zA-Z0-9]%_%g'`
-    my_dlsyms=
-
-    if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then
-      if test -n "$NM" && test -n "$global_symbol_pipe"; then
-       my_dlsyms="${my_outputname}S.c"
-      else
-       func_error "not configured to extract global symbols from dlpreopened files"
-      fi
-    fi
-
-    if test -n "$my_dlsyms"; then
-      case $my_dlsyms in
-      "") ;;
-      *.c)
-       # Discover the nlist of each of the dlfiles.
-       nlist="$output_objdir/${my_outputname}.nm"
-
-       func_show_eval "$RM $nlist ${nlist}S ${nlist}T"
-
-       # Parse the name list into a source file.
-       func_verbose "creating $output_objdir/$my_dlsyms"
-
-       $opt_dry_run || $ECHO > "$output_objdir/$my_dlsyms" "\
-/* $my_dlsyms - symbol resolution table for \`$my_outputname' dlsym emulation. */
-/* Generated by $PROGRAM (GNU $PACKAGE$TIMESTAMP) $VERSION */
-
-#ifdef __cplusplus
-extern \"C\" {
-#endif
-
-/* External symbol declarations for the compiler. */\
-"
-
-       if test "$dlself" = yes; then
-         func_verbose "generating symbol list for \`$output'"
-
-         $opt_dry_run || echo ': @PROGRAM@ ' > "$nlist"
-
-         # Add our own program objects to the symbol list.
-         progfiles=`$ECHO "X$objs$old_deplibs" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP`
-         for progfile in $progfiles; do
-           func_verbose "extracting global C symbols from \`$progfile'"
-           $opt_dry_run || eval "$NM $progfile | $global_symbol_pipe >> '$nlist'"
-         done
-
-         if test -n "$exclude_expsyms"; then
-           $opt_dry_run || {
-             eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T'
-             eval '$MV "$nlist"T "$nlist"'
-           }
-         fi
-
-         if test -n "$export_symbols_regex"; then
-           $opt_dry_run || {
-             eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T'
-             eval '$MV "$nlist"T "$nlist"'
-           }
-         fi
-
-         # Prepare the list of exported symbols
-         if test -z "$export_symbols"; then
-           export_symbols="$output_objdir/$outputname.exp"
-           $opt_dry_run || {
-             $RM $export_symbols
-             eval "${SED} -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"'
-             case $host in
-             *cygwin* | *mingw* | *cegcc* )
-                eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
-                eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"'
-               ;;
-             esac
-           }
-         else
-           $opt_dry_run || {
-             eval "${SED} -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"'
-             eval '$GREP -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T'
-             eval '$MV "$nlist"T "$nlist"'
-             case $host in
-               *cygwin | *mingw* | *cegcc* )
-                 eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
-                 eval 'cat "$nlist" >> "$output_objdir/$outputname.def"'
-                 ;;
-             esac
-           }
-         fi
-       fi
-
-       for dlprefile in $dlprefiles; do
-         func_verbose "extracting global C symbols from \`$dlprefile'"
-         func_basename "$dlprefile"
-         name="$func_basename_result"
-         $opt_dry_run || {
-           eval '$ECHO ": $name " >> "$nlist"'
-           eval "$NM $dlprefile 2>/dev/null | $global_symbol_pipe >> '$nlist'"
-         }
-       done
-
-       $opt_dry_run || {
-         # Make sure we have at least an empty file.
-         test -f "$nlist" || : > "$nlist"
-
-         if test -n "$exclude_expsyms"; then
-           $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T
-           $MV "$nlist"T "$nlist"
-         fi
-
-         # Try sorting and uniquifying the output.
-         if $GREP -v "^: " < "$nlist" |
-             if sort -k 3 </dev/null >/dev/null 2>&1; then
-               sort -k 3
-             else
-               sort +2
-             fi |
-             uniq > "$nlist"S; then
-           :
-         else
-           $GREP -v "^: " < "$nlist" > "$nlist"S
-         fi
-
-         if test -f "$nlist"S; then
-           eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$my_dlsyms"'
-         else
-           $ECHO '/* NONE */' >> "$output_objdir/$my_dlsyms"
-         fi
-
-         $ECHO >> "$output_objdir/$my_dlsyms" "\
-
-/* The mapping between symbol names and symbols.  */
-typedef struct {
-  const char *name;
-  void *address;
-} lt_dlsymlist;
-"
-         case $host in
-         *cygwin* | *mingw* | *cegcc* )
-           $ECHO >> "$output_objdir/$my_dlsyms" "\
-/* DATA imports from DLLs on WIN32 con't be const, because
-   runtime relocations are performed -- see ld's documentation
-   on pseudo-relocs.  */"
-           lt_dlsym_const= ;;
-         *osf5*)
-           echo >> "$output_objdir/$my_dlsyms" "\
-/* This system does not cope well with relocations in const data */"
-           lt_dlsym_const= ;;
-         *)
-           lt_dlsym_const=const ;;
-         esac
-
-         $ECHO >> "$output_objdir/$my_dlsyms" "\
-extern $lt_dlsym_const lt_dlsymlist
-lt_${my_prefix}_LTX_preloaded_symbols[];
-$lt_dlsym_const lt_dlsymlist
-lt_${my_prefix}_LTX_preloaded_symbols[] =
-{\
-  { \"$my_originator\", (void *) 0 },"
-
-         case $need_lib_prefix in
-         no)
-           eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$my_dlsyms"
-           ;;
-         *)
-           eval "$global_symbol_to_c_name_address_lib_prefix" < "$nlist" >> "$output_objdir/$my_dlsyms"
-           ;;
-         esac
-         $ECHO >> "$output_objdir/$my_dlsyms" "\
-  {0, (void *) 0}
-};
-
-/* This works around a problem in FreeBSD linker */
-#ifdef FREEBSD_WORKAROUND
-static const void *lt_preloaded_setup() {
-  return lt_${my_prefix}_LTX_preloaded_symbols;
-}
-#endif
-
-#ifdef __cplusplus
-}
-#endif\
-"
-       } # !$opt_dry_run
-
-       pic_flag_for_symtable=
-       case "$compile_command " in
-       *" -static "*) ;;
-       *)
-         case $host in
-         # compiling the symbol table file with pic_flag works around
-         # a FreeBSD bug that causes programs to crash when -lm is
-         # linked before any other PIC object.  But we must not use
-         # pic_flag when linking with -static.  The problem exists in
-         # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1.
-         *-*-freebsd2*|*-*-freebsd3.0*|*-*-freebsdelf3.0*)
-           pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND" ;;
-         *-*-hpux*)
-           pic_flag_for_symtable=" $pic_flag"  ;;
-         *)
-           if test "X$my_pic_p" != Xno; then
-             pic_flag_for_symtable=" $pic_flag"
-           fi
-           ;;
-         esac
-         ;;
-       esac
-       symtab_cflags=
-       for arg in $LTCFLAGS; do
-         case $arg in
-         -pie | -fpie | -fPIE) ;;
-         *) symtab_cflags="$symtab_cflags $arg" ;;
-         esac
-       done
-
-       # Now compile the dynamic symbol file.
-       func_show_eval '(cd $output_objdir && $LTCC$symtab_cflags -c$no_builtin_flag$pic_flag_for_symtable "$my_dlsyms")' 'exit $?'
-
-       # Clean up the generated files.
-       func_show_eval '$RM "$output_objdir/$my_dlsyms" "$nlist" "${nlist}S" "${nlist}T"'
-
-       # Transform the symbol file into the correct name.
-       symfileobj="$output_objdir/${my_outputname}S.$objext"
-       case $host in
-       *cygwin* | *mingw* | *cegcc* )
-         if test -f "$output_objdir/$my_outputname.def"; then
-           compile_command=`$ECHO "X$compile_command" | $Xsed -e "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
-           finalize_command=`$ECHO "X$finalize_command" | $Xsed -e "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
-         else
-           compile_command=`$ECHO "X$compile_command" | $Xsed -e "s%@SYMFILE@%$symfileobj%"`
-           finalize_command=`$ECHO "X$finalize_command" | $Xsed -e "s%@SYMFILE@%$symfileobj%"`
-         fi
-         ;;
-       *)
-         compile_command=`$ECHO "X$compile_command" | $Xsed -e "s%@SYMFILE@%$symfileobj%"`
-         finalize_command=`$ECHO "X$finalize_command" | $Xsed -e "s%@SYMFILE@%$symfileobj%"`
-         ;;
-       esac
-       ;;
-      *)
-       func_fatal_error "unknown suffix for \`$my_dlsyms'"
-       ;;
-      esac
-    else
-      # We keep going just in case the user didn't refer to
-      # lt_preloaded_symbols.  The linker will fail if global_symbol_pipe
-      # really was required.
-
-      # Nullify the symbol file.
-      compile_command=`$ECHO "X$compile_command" | $Xsed -e "s% @SYMFILE@%%"`
-      finalize_command=`$ECHO "X$finalize_command" | $Xsed -e "s% @SYMFILE@%%"`
-    fi
-}
-
-# func_win32_libid arg
-# return the library type of file 'arg'
-#
-# Need a lot of goo to handle *both* DLLs and import libs
-# Has to be a shell function in order to 'eat' the argument
-# that is supplied when $file_magic_command is called.
-func_win32_libid ()
-{
-  $opt_debug
-  win32_libid_type="unknown"
-  win32_fileres=`file -L $1 2>/dev/null`
-  case $win32_fileres in
-  *ar\ archive\ import\ library*) # definitely import
-    win32_libid_type="x86 archive import"
-    ;;
-  *ar\ archive*) # could be an import, or static
-    if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null |
-       $EGREP 'file format pe-i386(.*architecture: i386)?' >/dev/null ; then
-      win32_nmres=`eval $NM -f posix -A $1 |
-       $SED -n -e '
-           1,100{
-               / I /{
-                   s,.*,import,
-                   p
-                   q
-               }
-           }'`
-      case $win32_nmres in
-      import*)  win32_libid_type="x86 archive import";;
-      *)        win32_libid_type="x86 archive static";;
-      esac
-    fi
-    ;;
-  *DLL*)
-    win32_libid_type="x86 DLL"
-    ;;
-  *executable*) # but shell scripts are "executable" too...
-    case $win32_fileres in
-    *MS\ Windows\ PE\ Intel*)
-      win32_libid_type="x86 DLL"
-      ;;
-    esac
-    ;;
-  esac
-  $ECHO "$win32_libid_type"
-}
-
-
-
-# func_extract_an_archive dir oldlib
-func_extract_an_archive ()
-{
-    $opt_debug
-    f_ex_an_ar_dir="$1"; shift
-    f_ex_an_ar_oldlib="$1"
-    func_show_eval "(cd \$f_ex_an_ar_dir && $AR x \"\$f_ex_an_ar_oldlib\")" 'exit $?'
-    if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then
-     :
-    else
-      func_fatal_error "object name conflicts in archive: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib"
-    fi
-}
-
-
-# func_extract_archives gentop oldlib ...
-func_extract_archives ()
-{
-    $opt_debug
-    my_gentop="$1"; shift
-    my_oldlibs=${1+"$@"}
-    my_oldobjs=""
-    my_xlib=""
-    my_xabs=""
-    my_xdir=""
-
-    for my_xlib in $my_oldlibs; do
-      # Extract the objects.
-      case $my_xlib in
-       [\\/]* | [A-Za-z]:[\\/]*) my_xabs="$my_xlib" ;;
-       *) my_xabs=`pwd`"/$my_xlib" ;;
-      esac
-      func_basename "$my_xlib"
-      my_xlib="$func_basename_result"
-      my_xlib_u=$my_xlib
-      while :; do
-        case " $extracted_archives " in
-       *" $my_xlib_u "*)
-         func_arith $extracted_serial + 1
-         extracted_serial=$func_arith_result
-         my_xlib_u=lt$extracted_serial-$my_xlib ;;
-       *) break ;;
-       esac
-      done
-      extracted_archives="$extracted_archives $my_xlib_u"
-      my_xdir="$my_gentop/$my_xlib_u"
-
-      func_mkdir_p "$my_xdir"
-
-      case $host in
-      *-darwin*)
-       func_verbose "Extracting $my_xabs"
-       # Do not bother doing anything if just a dry run
-       $opt_dry_run || {
-         darwin_orig_dir=`pwd`
-         cd $my_xdir || exit $?
-         darwin_archive=$my_xabs
-         darwin_curdir=`pwd`
-         darwin_base_archive=`basename "$darwin_archive"`
-         darwin_arches=`$LIPO -info "$darwin_archive" 2>/dev/null | $GREP Architectures 2>/dev/null || true`
-         if test -n "$darwin_arches"; then
-           darwin_arches=`$ECHO "$darwin_arches" | $SED -e 's/.*are://'`
-           darwin_arch=
-           func_verbose "$darwin_base_archive has multiple architectures $darwin_arches"
-           for darwin_arch in  $darwin_arches ; do
-             func_mkdir_p "unfat-$$/${darwin_base_archive}-${darwin_arch}"
-             $LIPO -thin $darwin_arch -output "unfat-$$/${darwin_base_archive}-${darwin_arch}/${darwin_base_archive}" "${darwin_archive}"
-             cd "unfat-$$/${darwin_base_archive}-${darwin_arch}"
-             func_extract_an_archive "`pwd`" "${darwin_base_archive}"
-             cd "$darwin_curdir"
-             $RM "unfat-$$/${darwin_base_archive}-${darwin_arch}/${darwin_base_archive}"
-           done # $darwin_arches
-            ## Okay now we've a bunch of thin objects, gotta fatten them up :)
-           darwin_filelist=`find unfat-$$ -type f -name \*.o -print -o -name \*.lo -print | $SED -e "$basename" | sort -u`
-           darwin_file=
-           darwin_files=
-           for darwin_file in $darwin_filelist; do
-             darwin_files=`find unfat-$$ -name $darwin_file -print | $NL2SP`
-             $LIPO -create -output "$darwin_file" $darwin_files
-           done # $darwin_filelist
-           $RM -rf unfat-$$
-           cd "$darwin_orig_dir"
-         else
-           cd $darwin_orig_dir
-           func_extract_an_archive "$my_xdir" "$my_xabs"
-         fi # $darwin_arches
-       } # !$opt_dry_run
-       ;;
-      *)
-        func_extract_an_archive "$my_xdir" "$my_xabs"
-       ;;
-      esac
-      my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | $NL2SP`
-    done
-
-    func_extract_archives_result="$my_oldobjs"
-}
-
-
-
-# func_emit_wrapper_part1 [arg=no]
-#
-# Emit the first part of a libtool wrapper script on stdout.
-# For more information, see the description associated with
-# func_emit_wrapper(), below.
-func_emit_wrapper_part1 ()
-{
-       func_emit_wrapper_part1_arg1=no
-       if test -n "$1" ; then
-         func_emit_wrapper_part1_arg1=$1
-       fi
-
-       $ECHO "\
-#! $SHELL
-
-# $output - temporary wrapper script for $objdir/$outputname
-# Generated by $PROGRAM (GNU $PACKAGE$TIMESTAMP) $VERSION
-#
-# The $output program cannot be directly executed until all the libtool
-# libraries that it depends on are installed.
-#
-# This wrapper script should never be moved out of the build directory.
-# If it is, it will not operate correctly.
-
-# Sed substitution that helps us do robust quoting.  It backslashifies
-# metacharacters that are still active within double-quoted strings.
-Xsed='${SED} -e 1s/^X//'
-sed_quote_subst='$sed_quote_subst'
-
-# Be Bourne compatible
-if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then
-  emulate sh
-  NULLCMD=:
-  # Zsh 3.x and 4.x performs word splitting on \${1+\"\$@\"}, which
-  # is contrary to our usage.  Disable this feature.
-  alias -g '\${1+\"\$@\"}'='\"\$@\"'
-  setopt NO_GLOB_SUBST
-else
-  case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac
-fi
-BIN_SH=xpg4; export BIN_SH # for Tru64
-DUALCASE=1; export DUALCASE # for MKS sh
-
-# The HP-UX ksh and POSIX shell print the target directory to stdout
-# if CDPATH is set.
-(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
-
-relink_command=\"$relink_command\"
-
-# This environment variable determines our operation mode.
-if test \"\$libtool_install_magic\" = \"$magic\"; then
-  # install mode needs the following variables:
-  generated_by_libtool_version='$macro_version'
-  notinst_deplibs='$notinst_deplibs'
-else
-  # When we are sourced in execute mode, \$file and \$ECHO are already set.
-  if test \"\$libtool_execute_magic\" != \"$magic\"; then
-    ECHO=\"$qecho\"
-    file=\"\$0\"
-    # Make sure echo works.
-    if test \"X\$1\" = X--no-reexec; then
-      # Discard the --no-reexec flag, and continue.
-      shift
-    elif test \"X\`{ \$ECHO '\t'; } 2>/dev/null\`\" = 'X\t'; then
-      # Yippee, \$ECHO works!
-      :
-    else
-      # Restart under the correct shell, and then maybe \$ECHO will work.
-      exec $SHELL \"\$0\" --no-reexec \${1+\"\$@\"}
-    fi
-  fi\
-"
-       $ECHO "\
-
-  # Find the directory that this script lives in.
-  thisdir=\`\$ECHO \"X\$file\" | \$Xsed -e 's%/[^/]*$%%'\`
-  test \"x\$thisdir\" = \"x\$file\" && thisdir=.
-
-  # Follow symbolic links until we get to the real thisdir.
-  file=\`ls -ld \"\$file\" | ${SED} -n 's/.*-> //p'\`
-  while test -n \"\$file\"; do
-    destdir=\`\$ECHO \"X\$file\" | \$Xsed -e 's%/[^/]*\$%%'\`
-
-    # If there was a directory component, then change thisdir.
-    if test \"x\$destdir\" != \"x\$file\"; then
-      case \"\$destdir\" in
-      [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;;
-      *) thisdir=\"\$thisdir/\$destdir\" ;;
-      esac
-    fi
-
-    file=\`\$ECHO \"X\$file\" | \$Xsed -e 's%^.*/%%'\`
-    file=\`ls -ld \"\$thisdir/\$file\" | ${SED} -n 's/.*-> //p'\`
-  done
-"
-}
-# end: func_emit_wrapper_part1
-
-# func_emit_wrapper_part2 [arg=no]
-#
-# Emit the second part of a libtool wrapper script on stdout.
-# For more information, see the description associated with
-# func_emit_wrapper(), below.
-func_emit_wrapper_part2 ()
-{
-       func_emit_wrapper_part2_arg1=no
-       if test -n "$1" ; then
-         func_emit_wrapper_part2_arg1=$1
-       fi
-
-       $ECHO "\
-
-  # Usually 'no', except on cygwin/mingw when embedded into
-  # the cwrapper.
-  WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_wrapper_part2_arg1
-  if test \"\$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR\" = \"yes\"; then
-    # special case for '.'
-    if test \"\$thisdir\" = \".\"; then
-      thisdir=\`pwd\`
-    fi
-    # remove .libs from thisdir
-    case \"\$thisdir\" in
-    *[\\\\/]$objdir ) thisdir=\`\$ECHO \"X\$thisdir\" | \$Xsed -e 's%[\\\\/][^\\\\/]*$%%'\` ;;
-    $objdir )   thisdir=. ;;
-    esac
-  fi
-
-  # Try to get the absolute directory name.
-  absdir=\`cd \"\$thisdir\" && pwd\`
-  test -n \"\$absdir\" && thisdir=\"\$absdir\"
-"
-
-       if test "$fast_install" = yes; then
-         $ECHO "\
-  program=lt-'$outputname'$exeext
-  progdir=\"\$thisdir/$objdir\"
-
-  if test ! -f \"\$progdir/\$program\" ||
-     { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | ${SED} 1q\`; \\
-       test \"X\$file\" != \"X\$progdir/\$program\"; }; then
-
-    file=\"\$\$-\$program\"
-
-    if test ! -d \"\$progdir\"; then
-      $MKDIR \"\$progdir\"
-    else
-      $RM \"\$progdir/\$file\"
-    fi"
-
-         $ECHO "\
-
-    # relink executable if necessary
-    if test -n \"\$relink_command\"; then
-      if relink_command_output=\`eval \$relink_command 2>&1\`; then :
-      else
-       $ECHO \"\$relink_command_output\" >&2
-       $RM \"\$progdir/\$file\"
-       exit 1
-      fi
-    fi
-
-    $MV \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null ||
-    { $RM \"\$progdir/\$program\";
-      $MV \"\$progdir/\$file\" \"\$progdir/\$program\"; }
-    $RM \"\$progdir/\$file\"
-  fi"
-       else
-         $ECHO "\
-  program='$outputname'
-  progdir=\"\$thisdir/$objdir\"
-"
-       fi
-
-       $ECHO "\
-
-  if test -f \"\$progdir/\$program\"; then"
-
-       # Export our shlibpath_var if we have one.
-       if test "$shlibpath_overrides_runpath" = yes && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
-         $ECHO "\
-    # Add our own library path to $shlibpath_var
-    $shlibpath_var=\"$temp_rpath\$$shlibpath_var\"
-
-    # Some systems cannot cope with colon-terminated $shlibpath_var
-    # The second colon is a workaround for a bug in BeOS R4 sed
-    $shlibpath_var=\`\$ECHO \"X\$$shlibpath_var\" | \$Xsed -e 's/::*\$//'\`
-
-    export $shlibpath_var
-"
-       fi
-
-       # fixup the dll searchpath if we need to.
-       if test -n "$dllsearchpath"; then
-         $ECHO "\
-    # Add the dll search path components to the executable PATH
-    PATH=$dllsearchpath:\$PATH
-"
-       fi
-
-       $ECHO "\
-    if test \"\$libtool_execute_magic\" != \"$magic\"; then
-      # Run the actual program with our arguments.
-"
-       case $host in
-       # Backslashes separate directories on plain windows
-       *-*-mingw | *-*-os2* | *-cegcc*)
-         $ECHO "\
-      exec \"\$progdir\\\\\$program\" \${1+\"\$@\"}
-"
-         ;;
-
-       *)
-         $ECHO "\
-      exec \"\$progdir/\$program\" \${1+\"\$@\"}
-"
-         ;;
-       esac
-       $ECHO "\
-      \$ECHO \"\$0: cannot exec \$program \$*\" 1>&2
-      exit 1
-    fi
-  else
-    # The program doesn't exist.
-    \$ECHO \"\$0: error: \\\`\$progdir/\$program' does not exist\" 1>&2
-    \$ECHO \"This script is just a wrapper for \$program.\" 1>&2
-    $ECHO \"See the $PACKAGE documentation for more information.\" 1>&2
-    exit 1
-  fi
-fi\
-"
-}
-# end: func_emit_wrapper_part2
-
-
-# func_emit_wrapper [arg=no]
-#
-# Emit a libtool wrapper script on stdout.
-# Don't directly open a file because we may want to
-# incorporate the script contents within a cygwin/mingw
-# wrapper executable.  Must ONLY be called from within
-# func_mode_link because it depends on a number of variables
-# set therein.
-#
-# ARG is the value that the WRAPPER_SCRIPT_BELONGS_IN_OBJDIR
-# variable will take.  If 'yes', then the emitted script
-# will assume that the directory in which it is stored is
-# the $objdir directory.  This is a cygwin/mingw-specific
-# behavior.
-func_emit_wrapper ()
-{
-       func_emit_wrapper_arg1=no
-       if test -n "$1" ; then
-         func_emit_wrapper_arg1=$1
-       fi
-
-       # split this up so that func_emit_cwrapperexe_src
-       # can call each part independently.
-       func_emit_wrapper_part1 "${func_emit_wrapper_arg1}"
-       func_emit_wrapper_part2 "${func_emit_wrapper_arg1}"
-}
-
-
-# func_to_host_path arg
-#
-# Convert paths to host format when used with build tools.
-# Intended for use with "native" mingw (where libtool itself
-# is running under the msys shell), or in the following cross-
-# build environments:
-#    $build          $host
-#    mingw (msys)    mingw  [e.g. native]
-#    cygwin          mingw
-#    *nix + wine     mingw
-# where wine is equipped with the `winepath' executable.
-# In the native mingw case, the (msys) shell automatically
-# converts paths for any non-msys applications it launches,
-# but that facility isn't available from inside the cwrapper.
-# Similar accommodations are necessary for $host mingw and
-# $build cygwin.  Calling this function does no harm for other
-# $host/$build combinations not listed above.
-#
-# ARG is the path (on $build) that should be converted to
-# the proper representation for $host. The result is stored
-# in $func_to_host_path_result.
-func_to_host_path ()
-{
-  func_to_host_path_result="$1"
-  if test -n "$1" ; then
-    case $host in
-      *mingw* )
-        lt_sed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
-        case $build in
-          *mingw* ) # actually, msys
-            # awkward: cmd appends spaces to result
-            lt_sed_strip_trailing_spaces="s/[ ]*\$//"
-            func_to_host_path_tmp1=`( cmd //c echo "$1" |\
-              $SED -e "$lt_sed_strip_trailing_spaces" ) 2>/dev/null || echo ""`
-            func_to_host_path_result=`echo "$func_to_host_path_tmp1" |\
-              $SED -e "$lt_sed_naive_backslashify"`
-            ;;
-          *cygwin* )
-            func_to_host_path_tmp1=`cygpath -w "$1"`
-            func_to_host_path_result=`echo "$func_to_host_path_tmp1" |\
-              $SED -e "$lt_sed_naive_backslashify"`
-            ;;
-          * )
-            # Unfortunately, winepath does not exit with a non-zero
-            # error code, so we are forced to check the contents of
-            # stdout. On the other hand, if the command is not
-            # found, the shell will set an exit code of 127 and print
-            # *an error message* to stdout. So we must check for both
-            # error code of zero AND non-empty stdout, which explains
-            # the odd construction:
-            func_to_host_path_tmp1=`winepath -w "$1" 2>/dev/null`
-            if test "$?" -eq 0 && test -n "${func_to_host_path_tmp1}"; then
-              func_to_host_path_result=`echo "$func_to_host_path_tmp1" |\
-                $SED -e "$lt_sed_naive_backslashify"`
-            else
-              # Allow warning below.
-              func_to_host_path_result=""
-            fi
-            ;;
-        esac
-        if test -z "$func_to_host_path_result" ; then
-          func_error "Could not determine host path corresponding to"
-          func_error "  '$1'"
-          func_error "Continuing, but uninstalled executables may not work."
-          # Fallback:
-          func_to_host_path_result="$1"
-        fi
-        ;;
-    esac
-  fi
-}
-# end: func_to_host_path
-
-# func_to_host_pathlist arg
-#
-# Convert pathlists to host format when used with build tools.
-# See func_to_host_path(), above. This function supports the
-# following $build/$host combinations (but does no harm for
-# combinations not listed here):
-#    $build          $host
-#    mingw (msys)    mingw  [e.g. native]
-#    cygwin          mingw
-#    *nix + wine     mingw
-#
-# Path separators are also converted from $build format to
-# $host format. If ARG begins or ends with a path separator
-# character, it is preserved (but converted to $host format)
-# on output.
-#
-# ARG is a pathlist (on $build) that should be converted to
-# the proper representation on $host. The result is stored
-# in $func_to_host_pathlist_result.
-func_to_host_pathlist ()
-{
-  func_to_host_pathlist_result="$1"
-  if test -n "$1" ; then
-    case $host in
-      *mingw* )
-        lt_sed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
-        # Remove leading and trailing path separator characters from
-        # ARG. msys behavior is inconsistent here, cygpath turns them
-        # into '.;' and ';.', and winepath ignores them completely.
-        func_to_host_pathlist_tmp2="$1"
-        # Once set for this call, this variable should not be
-        # reassigned. It is used in tha fallback case.
-        func_to_host_pathlist_tmp1=`echo "$func_to_host_pathlist_tmp2" |\
-          $SED -e 's|^:*||' -e 's|:*$||'`
-        case $build in
-          *mingw* ) # Actually, msys.
-            # Awkward: cmd appends spaces to result.
-            lt_sed_strip_trailing_spaces="s/[ ]*\$//"
-            func_to_host_pathlist_tmp2=`( cmd //c echo "$func_to_host_pathlist_tmp1" |\
-              $SED -e "$lt_sed_strip_trailing_spaces" ) 2>/dev/null || echo ""`
-            func_to_host_pathlist_result=`echo "$func_to_host_pathlist_tmp2" |\
-              $SED -e "$lt_sed_naive_backslashify"`
-            ;;
-          *cygwin* )
-            func_to_host_pathlist_tmp2=`cygpath -w -p "$func_to_host_pathlist_tmp1"`
-            func_to_host_pathlist_result=`echo "$func_to_host_pathlist_tmp2" |\
-              $SED -e "$lt_sed_naive_backslashify"`
-            ;;
-          * )
-            # unfortunately, winepath doesn't convert pathlists
-            func_to_host_pathlist_result=""
-            func_to_host_pathlist_oldIFS=$IFS
-            IFS=:
-            for func_to_host_pathlist_f in $func_to_host_pathlist_tmp1 ; do
-              IFS=$func_to_host_pathlist_oldIFS
-              if test -n "$func_to_host_pathlist_f" ; then
-                func_to_host_path "$func_to_host_pathlist_f"
-                if test -n "$func_to_host_path_result" ; then
-                  if test -z "$func_to_host_pathlist_result" ; then
-                    func_to_host_pathlist_result="$func_to_host_path_result"
-                  else
-                    func_to_host_pathlist_result="$func_to_host_pathlist_result;$func_to_host_path_result"
-                  fi
-                fi
-              fi
-              IFS=:
-            done
-            IFS=$func_to_host_pathlist_oldIFS
-            ;;
-        esac
-        if test -z "$func_to_host_pathlist_result" ; then
-          func_error "Could not determine the host path(s) corresponding to"
-          func_error "  '$1'"
-          func_error "Continuing, but uninstalled executables may not work."
-          # Fallback. This may break if $1 contains DOS-style drive
-          # specifications. The fix is not to complicate the expression
-          # below, but for the user to provide a working wine installation
-          # with winepath so that path translation in the cross-to-mingw
-          # case works properly.
-          lt_replace_pathsep_nix_to_dos="s|:|;|g"
-          func_to_host_pathlist_result=`echo "$func_to_host_pathlist_tmp1" |\
-            $SED -e "$lt_replace_pathsep_nix_to_dos"`
-        fi
-        # Now, add the leading and trailing path separators back
-        case "$1" in
-          :* ) func_to_host_pathlist_result=";$func_to_host_pathlist_result"
-            ;;
-        esac
-        case "$1" in
-          *: ) func_to_host_pathlist_result="$func_to_host_pathlist_result;"
-            ;;
-        esac
-        ;;
-    esac
-  fi
-}
-# end: func_to_host_pathlist
-
-# func_emit_cwrapperexe_src
-# emit the source code for a wrapper executable on stdout
-# Must ONLY be called from within func_mode_link because
-# it depends on a number of variable set therein.
-func_emit_cwrapperexe_src ()
-{
-       cat <<EOF
-
-/* $cwrappersource - temporary wrapper executable for $objdir/$outputname
-   Generated by $PROGRAM (GNU $PACKAGE$TIMESTAMP) $VERSION
-
-   The $output program cannot be directly executed until all the libtool
-   libraries that it depends on are installed.
-
-   This wrapper executable should never be moved out of the build directory.
-   If it is, it will not operate correctly.
-
-   Currently, it simply execs the wrapper *script* "$SHELL $output",
-   but could eventually absorb all of the scripts functionality and
-   exec $objdir/$outputname directly.
-*/
-EOF
-           cat <<"EOF"
-#include <stdio.h>
-#include <stdlib.h>
-#ifdef _MSC_VER
-# include <direct.h>
-# include <process.h>
-# include <io.h>
-# define setmode _setmode
-#else
-# include <unistd.h>
-# include <stdint.h>
-# ifdef __CYGWIN__
-#  include <io.h>
-#  define HAVE_SETENV
-#  ifdef __STRICT_ANSI__
-char *realpath (const char *, char *);
-int putenv (char *);
-int setenv (const char *, const char *, int);
-#  endif
-# endif
-#endif
-#include <malloc.h>
-#include <stdarg.h>
-#include <assert.h>
-#include <string.h>
-#include <ctype.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-
-#if defined(PATH_MAX)
-# define LT_PATHMAX PATH_MAX
-#elif defined(MAXPATHLEN)
-# define LT_PATHMAX MAXPATHLEN
-#else
-# define LT_PATHMAX 1024
-#endif
-
-#ifndef S_IXOTH
-# define S_IXOTH 0
-#endif
-#ifndef S_IXGRP
-# define S_IXGRP 0
-#endif
-
-#ifdef _MSC_VER
-# define S_IXUSR _S_IEXEC
-# define stat _stat
-# ifndef _INTPTR_T_DEFINED
-#  define intptr_t int
-# endif
-#endif
-
-#ifndef DIR_SEPARATOR
-# define DIR_SEPARATOR '/'
-# define PATH_SEPARATOR ':'
-#endif
-
-#if defined (_WIN32) || defined (__MSDOS__) || defined (__DJGPP__) || \
-  defined (__OS2__)
-# define HAVE_DOS_BASED_FILE_SYSTEM
-# define FOPEN_WB "wb"
-# ifndef DIR_SEPARATOR_2
-#  define DIR_SEPARATOR_2 '\\'
-# endif
-# ifndef PATH_SEPARATOR_2
-#  define PATH_SEPARATOR_2 ';'
-# endif
-#endif
-
-#ifndef DIR_SEPARATOR_2
-# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
-#else /* DIR_SEPARATOR_2 */
-# define IS_DIR_SEPARATOR(ch) \
-       (((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
-#endif /* DIR_SEPARATOR_2 */
-
-#ifndef PATH_SEPARATOR_2
-# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR)
-#else /* PATH_SEPARATOR_2 */
-# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2)
-#endif /* PATH_SEPARATOR_2 */
-
-#ifdef __CYGWIN__
-# define FOPEN_WB "wb"
-#endif
-
-#ifndef FOPEN_WB
-# define FOPEN_WB "w"
-#endif
-#ifndef _O_BINARY
-# define _O_BINARY 0
-#endif
-
-#define XMALLOC(type, num)      ((type *) xmalloc ((num) * sizeof(type)))
-#define XFREE(stale) do { \
-  if (stale) { free ((void *) stale); stale = 0; } \
-} while (0)
-
-#undef LTWRAPPER_DEBUGPRINTF
-#if defined DEBUGWRAPPER
-# define LTWRAPPER_DEBUGPRINTF(args) ltwrapper_debugprintf args
-static void
-ltwrapper_debugprintf (const char *fmt, ...)
-{
-    va_list args;
-    va_start (args, fmt);
-    (void) vfprintf (stderr, fmt, args);
-    va_end (args);
-}
-#else
-# define LTWRAPPER_DEBUGPRINTF(args)
-#endif
-
-const char *program_name = NULL;
-
-void *xmalloc (size_t num);
-char *xstrdup (const char *string);
-const char *base_name (const char *name);
-char *find_executable (const char *wrapper);
-char *chase_symlinks (const char *pathspec);
-int make_executable (const char *path);
-int check_executable (const char *path);
-char *strendzap (char *str, const char *pat);
-void lt_fatal (const char *message, ...);
-void lt_setenv (const char *name, const char *value);
-char *lt_extend_str (const char *orig_value, const char *add, int to_end);
-void lt_opt_process_env_set (const char *arg);
-void lt_opt_process_env_prepend (const char *arg);
-void lt_opt_process_env_append (const char *arg);
-int lt_split_name_value (const char *arg, char** name, char** value);
-void lt_update_exe_path (const char *name, const char *value);
-void lt_update_lib_path (const char *name, const char *value);
-
-static const char *script_text_part1 =
-EOF
-
-           func_emit_wrapper_part1 yes |
-               $SED -e 's/\([\\"]\)/\\\1/g' \
-                    -e 's/^/  "/' -e 's/$/\\n"/'
-           echo ";"
-           cat <<EOF
-
-static const char *script_text_part2 =
-EOF
-           func_emit_wrapper_part2 yes |
-               $SED -e 's/\([\\"]\)/\\\1/g' \
-                    -e 's/^/  "/' -e 's/$/\\n"/'
-           echo ";"
-
-           cat <<EOF
-const char * MAGIC_EXE = "$magic_exe";
-const char * LIB_PATH_VARNAME = "$shlibpath_var";
-EOF
-
-           if test "$shlibpath_overrides_runpath" = yes && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
-              func_to_host_pathlist "$temp_rpath"
-             cat <<EOF
-const char * LIB_PATH_VALUE   = "$func_to_host_pathlist_result";
-EOF
-           else
-             cat <<"EOF"
-const char * LIB_PATH_VALUE   = "";
-EOF
-           fi
-
-           if test -n "$dllsearchpath"; then
-              func_to_host_pathlist "$dllsearchpath:"
-             cat <<EOF
-const char * EXE_PATH_VARNAME = "PATH";
-const char * EXE_PATH_VALUE   = "$func_to_host_pathlist_result";
-EOF
-           else
-             cat <<"EOF"
-const char * EXE_PATH_VARNAME = "";
-const char * EXE_PATH_VALUE   = "";
-EOF
-           fi
-
-           if test "$fast_install" = yes; then
-             cat <<EOF
-const char * TARGET_PROGRAM_NAME = "lt-$outputname"; /* hopefully, no .exe */
-EOF
-           else
-             cat <<EOF
-const char * TARGET_PROGRAM_NAME = "$outputname"; /* hopefully, no .exe */
-EOF
-           fi
-
-
-           cat <<"EOF"
-
-#define LTWRAPPER_OPTION_PREFIX         "--lt-"
-#define LTWRAPPER_OPTION_PREFIX_LENGTH  5
-
-static const size_t opt_prefix_len         = LTWRAPPER_OPTION_PREFIX_LENGTH;
-static const char *ltwrapper_option_prefix = LTWRAPPER_OPTION_PREFIX;
-
-static const char *dumpscript_opt       = LTWRAPPER_OPTION_PREFIX "dump-script";
-
-static const size_t env_set_opt_len     = LTWRAPPER_OPTION_PREFIX_LENGTH + 7;
-static const char *env_set_opt          = LTWRAPPER_OPTION_PREFIX "env-set";
-  /* argument is putenv-style "foo=bar", value of foo is set to bar */
-
-static const size_t env_prepend_opt_len = LTWRAPPER_OPTION_PREFIX_LENGTH + 11;
-static const char *env_prepend_opt      = LTWRAPPER_OPTION_PREFIX "env-prepend";
-  /* argument is putenv-style "foo=bar", new value of foo is bar${foo} */
-
-static const size_t env_append_opt_len  = LTWRAPPER_OPTION_PREFIX_LENGTH + 10;
-static const char *env_append_opt       = LTWRAPPER_OPTION_PREFIX "env-append";
-  /* argument is putenv-style "foo=bar", new value of foo is ${foo}bar */
-
-int
-main (int argc, char *argv[])
-{
-  char **newargz;
-  int  newargc;
-  char *tmp_pathspec;
-  char *actual_cwrapper_path;
-  char *actual_cwrapper_name;
-  char *target_name;
-  char *lt_argv_zero;
-  intptr_t rval = 127;
-
-  int i;
-
-  program_name = (char *) xstrdup (base_name (argv[0]));
-  LTWRAPPER_DEBUGPRINTF (("(main) argv[0]      : %s\n", argv[0]));
-  LTWRAPPER_DEBUGPRINTF (("(main) program_name : %s\n", program_name));
-
-  /* very simple arg parsing; don't want to rely on getopt */
-  for (i = 1; i < argc; i++)
-    {
-      if (strcmp (argv[i], dumpscript_opt) == 0)
-       {
-EOF
-           case "$host" in
-             *mingw* | *cygwin* )
-               # make stdout use "unix" line endings
-               echo "          setmode(1,_O_BINARY);"
-               ;;
-             esac
-
-           cat <<"EOF"
-         printf ("%s", script_text_part1);
-         printf ("%s", script_text_part2);
-         return 0;
-       }
-    }
-
-  newargz = XMALLOC (char *, argc + 1);
-  tmp_pathspec = find_executable (argv[0]);
-  if (tmp_pathspec == NULL)
-    lt_fatal ("Couldn't find %s", argv[0]);
-  LTWRAPPER_DEBUGPRINTF (("(main) found exe (before symlink chase) at : %s\n",
-                         tmp_pathspec));
-
-  actual_cwrapper_path = chase_symlinks (tmp_pathspec);
-  LTWRAPPER_DEBUGPRINTF (("(main) found exe (after symlink chase) at : %s\n",
-                         actual_cwrapper_path));
-  XFREE (tmp_pathspec);
-
-  actual_cwrapper_name = xstrdup( base_name (actual_cwrapper_path));
-  strendzap (actual_cwrapper_path, actual_cwrapper_name);
-
-  /* wrapper name transforms */
-  strendzap (actual_cwrapper_name, ".exe");
-  tmp_pathspec = lt_extend_str (actual_cwrapper_name, ".exe", 1);
-  XFREE (actual_cwrapper_name);
-  actual_cwrapper_name = tmp_pathspec;
-  tmp_pathspec = 0;
-
-  /* target_name transforms -- use actual target program name; might have lt- prefix */
-  target_name = xstrdup (base_name (TARGET_PROGRAM_NAME));
-  strendzap (target_name, ".exe");
-  tmp_pathspec = lt_extend_str (target_name, ".exe", 1);
-  XFREE (target_name);
-  target_name = tmp_pathspec;
-  tmp_pathspec = 0;
-
-  LTWRAPPER_DEBUGPRINTF (("(main) libtool target name: %s\n",
-                         target_name));
-EOF
-
-           cat <<EOF
-  newargz[0] =
-    XMALLOC (char, (strlen (actual_cwrapper_path) +
-                   strlen ("$objdir") + 1 + strlen (actual_cwrapper_name) + 1));
-  strcpy (newargz[0], actual_cwrapper_path);
-  strcat (newargz[0], "$objdir");
-  strcat (newargz[0], "/");
-EOF
-
-           cat <<"EOF"
-  /* stop here, and copy so we don't have to do this twice */
-  tmp_pathspec = xstrdup (newargz[0]);
-
-  /* do NOT want the lt- prefix here, so use actual_cwrapper_name */
-  strcat (newargz[0], actual_cwrapper_name);
-
-  /* DO want the lt- prefix here if it exists, so use target_name */
-  lt_argv_zero = lt_extend_str (tmp_pathspec, target_name, 1);
-  XFREE (tmp_pathspec);
-  tmp_pathspec = NULL;
-EOF
-
-           case $host_os in
-             mingw*)
-           cat <<"EOF"
-  {
-    char* p;
-    while ((p = strchr (newargz[0], '\\')) != NULL)
-      {
-       *p = '/';
-      }
-    while ((p = strchr (lt_argv_zero, '\\')) != NULL)
-      {
-       *p = '/';
-      }
-  }
-EOF
-           ;;
-           esac
-
-           cat <<"EOF"
-  XFREE (target_name);
-  XFREE (actual_cwrapper_path);
-  XFREE (actual_cwrapper_name);
-
-  lt_setenv ("BIN_SH", "xpg4"); /* for Tru64 */
-  lt_setenv ("DUALCASE", "1");  /* for MSK sh */
-  lt_update_lib_path (LIB_PATH_VARNAME, LIB_PATH_VALUE);
-  lt_update_exe_path (EXE_PATH_VARNAME, EXE_PATH_VALUE);
-
-  newargc=0;
-  for (i = 1; i < argc; i++)
-    {
-      if (strncmp (argv[i], env_set_opt, env_set_opt_len) == 0)
-        {
-          if (argv[i][env_set_opt_len] == '=')
-            {
-              const char *p = argv[i] + env_set_opt_len + 1;
-              lt_opt_process_env_set (p);
-            }
-          else if (argv[i][env_set_opt_len] == '\0' && i + 1 < argc)
-            {
-              lt_opt_process_env_set (argv[++i]); /* don't copy */
-            }
-          else
-            lt_fatal ("%s missing required argument", env_set_opt);
-          continue;
-        }
-      if (strncmp (argv[i], env_prepend_opt, env_prepend_opt_len) == 0)
-        {
-          if (argv[i][env_prepend_opt_len] == '=')
-            {
-              const char *p = argv[i] + env_prepend_opt_len + 1;
-              lt_opt_process_env_prepend (p);
-            }
-          else if (argv[i][env_prepend_opt_len] == '\0' && i + 1 < argc)
-            {
-              lt_opt_process_env_prepend (argv[++i]); /* don't copy */
-            }
-          else
-            lt_fatal ("%s missing required argument", env_prepend_opt);
-          continue;
-        }
-      if (strncmp (argv[i], env_append_opt, env_append_opt_len) == 0)
-        {
-          if (argv[i][env_append_opt_len] == '=')
-            {
-              const char *p = argv[i] + env_append_opt_len + 1;
-              lt_opt_process_env_append (p);
-            }
-          else if (argv[i][env_append_opt_len] == '\0' && i + 1 < argc)
-            {
-              lt_opt_process_env_append (argv[++i]); /* don't copy */
-            }
-          else
-            lt_fatal ("%s missing required argument", env_append_opt);
-          continue;
-        }
-      if (strncmp (argv[i], ltwrapper_option_prefix, opt_prefix_len) == 0)
-        {
-          /* however, if there is an option in the LTWRAPPER_OPTION_PREFIX
-             namespace, but it is not one of the ones we know about and
-             have already dealt with, above (inluding dump-script), then
-             report an error. Otherwise, targets might begin to believe
-             they are allowed to use options in the LTWRAPPER_OPTION_PREFIX
-             namespace. The first time any user complains about this, we'll
-             need to make LTWRAPPER_OPTION_PREFIX a configure-time option
-             or a configure.ac-settable value.
-           */
-          lt_fatal ("Unrecognized option in %s namespace: '%s'",
-                    ltwrapper_option_prefix, argv[i]);
-        }
-      /* otherwise ... */
-      newargz[++newargc] = xstrdup (argv[i]);
-    }
-  newargz[++newargc] = NULL;
-
-  LTWRAPPER_DEBUGPRINTF     (("(main) lt_argv_zero : %s\n", (lt_argv_zero ? lt_argv_zero : "<NULL>")));
-  for (i = 0; i < newargc; i++)
-    {
-      LTWRAPPER_DEBUGPRINTF (("(main) newargz[%d]   : %s\n", i, (newargz[i] ? newargz[i] : "<NULL>")));
-    }
-
-EOF
-
-           case $host_os in
-             mingw*)
-               cat <<"EOF"
-  /* execv doesn't actually work on mingw as expected on unix */
-  rval = _spawnv (_P_WAIT, lt_argv_zero, (const char * const *) newargz);
-  if (rval == -1)
-    {
-      /* failed to start process */
-      LTWRAPPER_DEBUGPRINTF (("(main) failed to launch target \"%s\": errno = %d\n", lt_argv_zero, errno));
-      return 127;
-    }
-  return rval;
-EOF
-               ;;
-             *)
-               cat <<"EOF"
-  execv (lt_argv_zero, newargz);
-  return rval; /* =127, but avoids unused variable warning */
-EOF
-               ;;
-           esac
-
-           cat <<"EOF"
-}
-
-void *
-xmalloc (size_t num)
-{
-  void *p = (void *) malloc (num);
-  if (!p)
-    lt_fatal ("Memory exhausted");
-
-  return p;
-}
-
-char *
-xstrdup (const char *string)
-{
-  return string ? strcpy ((char *) xmalloc (strlen (string) + 1),
-                         string) : NULL;
-}
-
-const char *
-base_name (const char *name)
-{
-  const char *base;
-
-#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
-  /* Skip over the disk name in MSDOS pathnames. */
-  if (isalpha ((unsigned char) name[0]) && name[1] == ':')
-    name += 2;
-#endif
-
-  for (base = name; *name; name++)
-    if (IS_DIR_SEPARATOR (*name))
-      base = name + 1;
-  return base;
-}
-
-int
-check_executable (const char *path)
-{
-  struct stat st;
-
-  LTWRAPPER_DEBUGPRINTF (("(check_executable)  : %s\n",
-                         path ? (*path ? path : "EMPTY!") : "NULL!"));
-  if ((!path) || (!*path))
-    return 0;
-
-  if ((stat (path, &st) >= 0)
-      && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
-    return 1;
-  else
-    return 0;
-}
-
-int
-make_executable (const char *path)
-{
-  int rval = 0;
-  struct stat st;
-
-  LTWRAPPER_DEBUGPRINTF (("(make_executable)   : %s\n",
-                         path ? (*path ? path : "EMPTY!") : "NULL!"));
-  if ((!path) || (!*path))
-    return 0;
-
-  if (stat (path, &st) >= 0)
-    {
-      rval = chmod (path, st.st_mode | S_IXOTH | S_IXGRP | S_IXUSR);
-    }
-  return rval;
-}
-
-/* Searches for the full path of the wrapper.  Returns
-   newly allocated full path name if found, NULL otherwise
-   Does not chase symlinks, even on platforms that support them.
-*/
-char *
-find_executable (const char *wrapper)
-{
-  int has_slash = 0;
-  const char *p;
-  const char *p_next;
-  /* static buffer for getcwd */
-  char tmp[LT_PATHMAX + 1];
-  int tmp_len;
-  char *concat_name;
-
-  LTWRAPPER_DEBUGPRINTF (("(find_executable)   : %s\n",
-                         wrapper ? (*wrapper ? wrapper : "EMPTY!") : "NULL!"));
-
-  if ((wrapper == NULL) || (*wrapper == '\0'))
-    return NULL;
-
-  /* Absolute path? */
-#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
-  if (isalpha ((unsigned char) wrapper[0]) && wrapper[1] == ':')
-    {
-      concat_name = xstrdup (wrapper);
-      if (check_executable (concat_name))
-       return concat_name;
-      XFREE (concat_name);
-    }
-  else
-    {
-#endif
-      if (IS_DIR_SEPARATOR (wrapper[0]))
-       {
-         concat_name = xstrdup (wrapper);
-         if (check_executable (concat_name))
-           return concat_name;
-         XFREE (concat_name);
-       }
-#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
-    }
-#endif
-
-  for (p = wrapper; *p; p++)
-    if (*p == '/')
-      {
-       has_slash = 1;
-       break;
-      }
-  if (!has_slash)
-    {
-      /* no slashes; search PATH */
-      const char *path = getenv ("PATH");
-      if (path != NULL)
-       {
-         for (p = path; *p; p = p_next)
-           {
-             const char *q;
-             size_t p_len;
-             for (q = p; *q; q++)
-               if (IS_PATH_SEPARATOR (*q))
-                 break;
-             p_len = q - p;
-             p_next = (*q == '\0' ? q : q + 1);
-             if (p_len == 0)
-               {
-                 /* empty path: current directory */
-                 if (getcwd (tmp, LT_PATHMAX) == NULL)
-                   lt_fatal ("getcwd failed");
-                 tmp_len = strlen (tmp);
-                 concat_name =
-                   XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
-                 memcpy (concat_name, tmp, tmp_len);
-                 concat_name[tmp_len] = '/';
-                 strcpy (concat_name + tmp_len + 1, wrapper);
-               }
-             else
-               {
-                 concat_name =
-                   XMALLOC (char, p_len + 1 + strlen (wrapper) + 1);
-                 memcpy (concat_name, p, p_len);
-                 concat_name[p_len] = '/';
-                 strcpy (concat_name + p_len + 1, wrapper);
-               }
-             if (check_executable (concat_name))
-               return concat_name;
-             XFREE (concat_name);
-           }
-       }
-      /* not found in PATH; assume curdir */
-    }
-  /* Relative path | not found in path: prepend cwd */
-  if (getcwd (tmp, LT_PATHMAX) == NULL)
-    lt_fatal ("getcwd failed");
-  tmp_len = strlen (tmp);
-  concat_name = XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
-  memcpy (concat_name, tmp, tmp_len);
-  concat_name[tmp_len] = '/';
-  strcpy (concat_name + tmp_len + 1, wrapper);
-
-  if (check_executable (concat_name))
-    return concat_name;
-  XFREE (concat_name);
-  return NULL;
-}
-
-char *
-chase_symlinks (const char *pathspec)
-{
-#ifndef S_ISLNK
-  return xstrdup (pathspec);
-#else
-  char buf[LT_PATHMAX];
-  struct stat s;
-  char *tmp_pathspec = xstrdup (pathspec);
-  char *p;
-  int has_symlinks = 0;
-  while (strlen (tmp_pathspec) && !has_symlinks)
-    {
-      LTWRAPPER_DEBUGPRINTF (("checking path component for symlinks: %s\n",
-                             tmp_pathspec));
-      if (lstat (tmp_pathspec, &s) == 0)
-       {
-         if (S_ISLNK (s.st_mode) != 0)
-           {
-             has_symlinks = 1;
-             break;
-           }
-
-         /* search backwards for last DIR_SEPARATOR */
-         p = tmp_pathspec + strlen (tmp_pathspec) - 1;
-         while ((p > tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
-           p--;
-         if ((p == tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
-           {
-             /* no more DIR_SEPARATORS left */
-             break;
-           }
-         *p = '\0';
-       }
-      else
-       {
-         char *errstr = strerror (errno);
-         lt_fatal ("Error accessing file %s (%s)", tmp_pathspec, errstr);
-       }
-    }
-  XFREE (tmp_pathspec);
-
-  if (!has_symlinks)
-    {
-      return xstrdup (pathspec);
-    }
-
-  tmp_pathspec = realpath (pathspec, buf);
-  if (tmp_pathspec == 0)
-    {
-      lt_fatal ("Could not follow symlinks for %s", pathspec);
-    }
-  return xstrdup (tmp_pathspec);
-#endif
-}
-
-char *
-strendzap (char *str, const char *pat)
-{
-  size_t len, patlen;
-
-  assert (str != NULL);
-  assert (pat != NULL);
-
-  len = strlen (str);
-  patlen = strlen (pat);
-
-  if (patlen <= len)
-    {
-      str += len - patlen;
-      if (strcmp (str, pat) == 0)
-       *str = '\0';
-    }
-  return str;
-}
-
-static void
-lt_error_core (int exit_status, const char *mode,
-              const char *message, va_list ap)
-{
-  fprintf (stderr, "%s: %s: ", program_name, mode);
-  vfprintf (stderr, message, ap);
-  fprintf (stderr, ".\n");
-
-  if (exit_status >= 0)
-    exit (exit_status);
-}
-
-void
-lt_fatal (const char *message, ...)
-{
-  va_list ap;
-  va_start (ap, message);
-  lt_error_core (EXIT_FAILURE, "FATAL", message, ap);
-  va_end (ap);
-}
-
-void
-lt_setenv (const char *name, const char *value)
-{
-  LTWRAPPER_DEBUGPRINTF (("(lt_setenv) setting '%s' to '%s'\n",
-                          (name ? name : "<NULL>"),
-                          (value ? value : "<NULL>")));
-  {
-#ifdef HAVE_SETENV
-    /* always make a copy, for consistency with !HAVE_SETENV */
-    char *str = xstrdup (value);
-    setenv (name, str, 1);
-#else
-    int len = strlen (name) + 1 + strlen (value) + 1;
-    char *str = XMALLOC (char, len);
-    sprintf (str, "%s=%s", name, value);
-    if (putenv (str) != EXIT_SUCCESS)
-      {
-        XFREE (str);
-      }
-#endif
-  }
-}
-
-char *
-lt_extend_str (const char *orig_value, const char *add, int to_end)
-{
-  char *new_value;
-  if (orig_value && *orig_value)
-    {
-      int orig_value_len = strlen (orig_value);
-      int add_len = strlen (add);
-      new_value = XMALLOC (char, add_len + orig_value_len + 1);
-      if (to_end)
-        {
-          strcpy (new_value, orig_value);
-          strcpy (new_value + orig_value_len, add);
-        }
-      else
-        {
-          strcpy (new_value, add);
-          strcpy (new_value + add_len, orig_value);
-        }
-    }
-  else
-    {
-      new_value = xstrdup (add);
-    }
-  return new_value;
-}
-
-int
-lt_split_name_value (const char *arg, char** name, char** value)
-{
-  const char *p;
-  int len;
-  if (!arg || !*arg)
-    return 1;
-
-  p = strchr (arg, (int)'=');
-
-  if (!p)
-    return 1;
-
-  *value = xstrdup (++p);
-
-  len = strlen (arg) - strlen (*value);
-  *name = XMALLOC (char, len);
-  strncpy (*name, arg, len-1);
-  (*name)[len - 1] = '\0';
-
-  return 0;
-}
-
-void
-lt_opt_process_env_set (const char *arg)
-{
-  char *name = NULL;
-  char *value = NULL;
-
-  if (lt_split_name_value (arg, &name, &value) != 0)
-    {
-      XFREE (name);
-      XFREE (value);
-      lt_fatal ("bad argument for %s: '%s'", env_set_opt, arg);
-    }
-
-  lt_setenv (name, value);
-  XFREE (name);
-  XFREE (value);
-}
-
-void
-lt_opt_process_env_prepend (const char *arg)
-{
-  char *name = NULL;
-  char *value = NULL;
-  char *new_value = NULL;
-
-  if (lt_split_name_value (arg, &name, &value) != 0)
-    {
-      XFREE (name);
-      XFREE (value);
-      lt_fatal ("bad argument for %s: '%s'", env_prepend_opt, arg);
-    }
-
-  new_value = lt_extend_str (getenv (name), value, 0);
-  lt_setenv (name, new_value);
-  XFREE (new_value);
-  XFREE (name);
-  XFREE (value);
-}
-
-void
-lt_opt_process_env_append (const char *arg)
-{
-  char *name = NULL;
-  char *value = NULL;
-  char *new_value = NULL;
-
-  if (lt_split_name_value (arg, &name, &value) != 0)
-    {
-      XFREE (name);
-      XFREE (value);
-      lt_fatal ("bad argument for %s: '%s'", env_append_opt, arg);
-    }
-
-  new_value = lt_extend_str (getenv (name), value, 1);
-  lt_setenv (name, new_value);
-  XFREE (new_value);
-  XFREE (name);
-  XFREE (value);
-}
-
-void
-lt_update_exe_path (const char *name, const char *value)
-{
-  LTWRAPPER_DEBUGPRINTF (("(lt_update_exe_path) modifying '%s' by prepending '%s'\n",
-                          (name ? name : "<NULL>"),
-                          (value ? value : "<NULL>")));
-
-  if (name && *name && value && *value)
-    {
-      char *new_value = lt_extend_str (getenv (name), value, 0);
-      /* some systems can't cope with a ':'-terminated path #' */
-      int len = strlen (new_value);
-      while (((len = strlen (new_value)) > 0) && IS_PATH_SEPARATOR (new_value[len-1]))
-        {
-          new_value[len-1] = '\0';
-        }
-      lt_setenv (name, new_value);
-      XFREE (new_value);
-    }
-}
-
-void
-lt_update_lib_path (const char *name, const char *value)
-{
-  LTWRAPPER_DEBUGPRINTF (("(lt_update_lib_path) modifying '%s' by prepending '%s'\n",
-                          (name ? name : "<NULL>"),
-                          (value ? value : "<NULL>")));
-
-  if (name && *name && value && *value)
-    {
-      char *new_value = lt_extend_str (getenv (name), value, 0);
-      lt_setenv (name, new_value);
-      XFREE (new_value);
-    }
-}
-
-
-EOF
-}
-# end: func_emit_cwrapperexe_src
-
-# func_mode_link arg...
-func_mode_link ()
-{
-    $opt_debug
-    case $host in
-    *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
-      # It is impossible to link a dll without this setting, and
-      # we shouldn't force the makefile maintainer to figure out
-      # which system we are compiling for in order to pass an extra
-      # flag for every libtool invocation.
-      # allow_undefined=no
-
-      # FIXME: Unfortunately, there are problems with the above when trying
-      # to make a dll which has undefined symbols, in which case not
-      # even a static library is built.  For now, we need to specify
-      # -no-undefined on the libtool link line when we can be certain
-      # that all symbols are satisfied, otherwise we get a static library.
-      allow_undefined=yes
-      ;;
-    *)
-      allow_undefined=yes
-      ;;
-    esac
-    libtool_args=$nonopt
-    base_compile="$nonopt $@"
-    compile_command=$nonopt
-    finalize_command=$nonopt
-
-    compile_rpath=
-    finalize_rpath=
-    compile_shlibpath=
-    finalize_shlibpath=
-    convenience=
-    old_convenience=
-    deplibs=
-    old_deplibs=
-    compiler_flags=
-    linker_flags=
-    dllsearchpath=
-    lib_search_path=`pwd`
-    inst_prefix_dir=
-    new_inherited_linker_flags=
-
-    avoid_version=no
-    dlfiles=
-    dlprefiles=
-    dlself=no
-    export_dynamic=no
-    export_symbols=
-    export_symbols_regex=
-    generated=
-    libobjs=
-    ltlibs=
-    module=no
-    no_install=no
-    objs=
-    non_pic_objects=
-    precious_files_regex=
-    prefer_static_libs=no
-    preload=no
-    prev=
-    prevarg=
-    release=
-    rpath=
-    xrpath=
-    perm_rpath=
-    temp_rpath=
-    thread_safe=no
-    vinfo=
-    vinfo_number=no
-    weak_libs=
-    single_module="${wl}-single_module"
-    func_infer_tag $base_compile
-
-    # We need to know -static, to get the right output filenames.
-    for arg
-    do
-      case $arg in
-      -shared)
-       test "$build_libtool_libs" != yes && \
-         func_fatal_configuration "can not build a shared library"
-       build_old_libs=no
-       break
-       ;;
-      -all-static | -static | -static-libtool-libs)
-       case $arg in
-       -all-static)
-         if test "$build_libtool_libs" = yes && test -z "$link_static_flag"; then
-           func_warning "complete static linking is impossible in this configuration"
-         fi
-         if test -n "$link_static_flag"; then
-           dlopen_self=$dlopen_self_static
-         fi
-         prefer_static_libs=yes
-         ;;
-       -static)
-         if test -z "$pic_flag" && test -n "$link_static_flag"; then
-           dlopen_self=$dlopen_self_static
-         fi
-         prefer_static_libs=built
-         ;;
-       -static-libtool-libs)
-         if test -z "$pic_flag" && test -n "$link_static_flag"; then
-           dlopen_self=$dlopen_self_static
-         fi
-         prefer_static_libs=yes
-         ;;
-       esac
-       build_libtool_libs=no
-       build_old_libs=yes
-       break
-       ;;
-      esac
-    done
-
-    # See if our shared archives depend on static archives.
-    test -n "$old_archive_from_new_cmds" && build_old_libs=yes
-
-    # Go through the arguments, transforming them on the way.
-    while test "$#" -gt 0; do
-      arg="$1"
-      shift
-      func_quote_for_eval "$arg"
-      qarg=$func_quote_for_eval_unquoted_result
-      func_append libtool_args " $func_quote_for_eval_result"
-
-      # If the previous option needs an argument, assign it.
-      if test -n "$prev"; then
-       case $prev in
-       output)
-         func_append compile_command " @OUTPUT@"
-         func_append finalize_command " @OUTPUT@"
-         ;;
-       esac
-
-       case $prev in
-       dlfiles|dlprefiles)
-         if test "$preload" = no; then
-           # Add the symbol object into the linking commands.
-           func_append compile_command " @SYMFILE@"
-           func_append finalize_command " @SYMFILE@"
-           preload=yes
-         fi
-         case $arg in
-         *.la | *.lo) ;;  # We handle these cases below.
-         force)
-           if test "$dlself" = no; then
-             dlself=needless
-             export_dynamic=yes
-           fi
-           prev=
-           continue
-           ;;
-         self)
-           if test "$prev" = dlprefiles; then
-             dlself=yes
-           elif test "$prev" = dlfiles && test "$dlopen_self" != yes; then
-             dlself=yes
-           else
-             dlself=needless
-             export_dynamic=yes
-           fi
-           prev=
-           continue
-           ;;
-         *)
-           if test "$prev" = dlfiles; then
-             dlfiles="$dlfiles $arg"
-           else
-             dlprefiles="$dlprefiles $arg"
-           fi
-           prev=
-           continue
-           ;;
-         esac
-         ;;
-       expsyms)
-         export_symbols="$arg"
-         test -f "$arg" \
-           || func_fatal_error "symbol file \`$arg' does not exist"
-         prev=
-         continue
-         ;;
-       expsyms_regex)
-         export_symbols_regex="$arg"
-         prev=
-         continue
-         ;;
-       framework)
-         case $host in
-           *-*-darwin*)
-             case "$deplibs " in
-               *" $qarg.ltframework "*) ;;
-               *) deplibs="$deplibs $qarg.ltframework" # this is fixed later
-                  ;;
-             esac
-             ;;
-         esac
-         prev=
-         continue
-         ;;
-       inst_prefix)
-         inst_prefix_dir="$arg"
-         prev=
-         continue
-         ;;
-       objectlist)
-         if test -f "$arg"; then
-           save_arg=$arg
-           moreargs=
-           for fil in `cat "$save_arg"`
-           do
-#            moreargs="$moreargs $fil"
-             arg=$fil
-             # A libtool-controlled object.
-
-             # Check to see that this really is a libtool object.
-             if func_lalib_unsafe_p "$arg"; then
-               pic_object=
-               non_pic_object=
-
-               # Read the .lo file
-               func_source "$arg"
-
-               if test -z "$pic_object" ||
-                  test -z "$non_pic_object" ||
-                  test "$pic_object" = none &&
-                  test "$non_pic_object" = none; then
-                 func_fatal_error "cannot find name of object for \`$arg'"
-               fi
-
-               # Extract subdirectory from the argument.
-               func_dirname "$arg" "/" ""
-               xdir="$func_dirname_result"
-
-               if test "$pic_object" != none; then
-                 # Prepend the subdirectory the object is found in.
-                 pic_object="$xdir$pic_object"
-
-                 if test "$prev" = dlfiles; then
-                   if test "$build_libtool_libs" = yes && test "$dlopen_support" = yes; then
-                     dlfiles="$dlfiles $pic_object"
-                     prev=
-                     continue
-                   else
-                     # If libtool objects are unsupported, then we need to preload.
-                     prev=dlprefiles
-                   fi
-                 fi
-
-                 # CHECK ME:  I think I busted this.  -Ossama
-                 if test "$prev" = dlprefiles; then
-                   # Preload the old-style object.
-                   dlprefiles="$dlprefiles $pic_object"
-                   prev=
-                 fi
-
-                 # A PIC object.
-                 func_append libobjs " $pic_object"
-                 arg="$pic_object"
-               fi
-
-               # Non-PIC object.
-               if test "$non_pic_object" != none; then
-                 # Prepend the subdirectory the object is found in.
-                 non_pic_object="$xdir$non_pic_object"
-
-                 # A standard non-PIC object
-                 func_append non_pic_objects " $non_pic_object"
-                 if test -z "$pic_object" || test "$pic_object" = none ; then
-                   arg="$non_pic_object"
-                 fi
-               else
-                 # If the PIC object exists, use it instead.
-                 # $xdir was prepended to $pic_object above.
-                 non_pic_object="$pic_object"
-                 func_append non_pic_objects " $non_pic_object"
-               fi
-             else
-               # Only an error if not doing a dry-run.
-               if $opt_dry_run; then
-                 # Extract subdirectory from the argument.
-                 func_dirname "$arg" "/" ""
-                 xdir="$func_dirname_result"
-
-                 func_lo2o "$arg"
-                 pic_object=$xdir$objdir/$func_lo2o_result
-                 non_pic_object=$xdir$func_lo2o_result
-                 func_append libobjs " $pic_object"
-                 func_append non_pic_objects " $non_pic_object"
-               else
-                 func_fatal_error "\`$arg' is not a valid libtool object"
-               fi
-             fi
-           done
-         else
-           func_fatal_error "link input file \`$arg' does not exist"
-         fi
-         arg=$save_arg
-         prev=
-         continue
-         ;;
-       precious_regex)
-         precious_files_regex="$arg"
-         prev=
-         continue
-         ;;
-       release)
-         release="-$arg"
-         prev=
-         continue
-         ;;
-       rpath | xrpath)
-         # We need an absolute path.
-         case $arg in
-         [\\/]* | [A-Za-z]:[\\/]*) ;;
-         *)
-           func_fatal_error "only absolute run-paths are allowed"
-           ;;
-         esac
-         if test "$prev" = rpath; then
-           case "$rpath " in
-           *" $arg "*) ;;
-           *) rpath="$rpath $arg" ;;
-           esac
-         else
-           case "$xrpath " in
-           *" $arg "*) ;;
-           *) xrpath="$xrpath $arg" ;;
-           esac
-         fi
-         prev=
-         continue
-         ;;
-       shrext)
-         shrext_cmds="$arg"
-         prev=
-         continue
-         ;;
-       weak)
-         weak_libs="$weak_libs $arg"
-         prev=
-         continue
-         ;;
-       xcclinker)
-         linker_flags="$linker_flags $qarg"
-         compiler_flags="$compiler_flags $qarg"
-         prev=
-         func_append compile_command " $qarg"
-         func_append finalize_command " $qarg"
-         continue
-         ;;
-       xcompiler)
-         compiler_flags="$compiler_flags $qarg"
-         prev=
-         func_append compile_command " $qarg"
-         func_append finalize_command " $qarg"
-         continue
-         ;;
-       xlinker)
-         linker_flags="$linker_flags $qarg"
-         compiler_flags="$compiler_flags $wl$qarg"
-         prev=
-         func_append compile_command " $wl$qarg"
-         func_append finalize_command " $wl$qarg"
-         continue
-         ;;
-       *)
-         eval "$prev=\"\$arg\""
-         prev=
-         continue
-         ;;
-       esac
-      fi # test -n "$prev"
-
-      prevarg="$arg"
-
-      case $arg in
-      -all-static)
-       if test -n "$link_static_flag"; then
-         # See comment for -static flag below, for more details.
-         func_append compile_command " $link_static_flag"
-         func_append finalize_command " $link_static_flag"
-       fi
-       continue
-       ;;
-
-      -allow-undefined)
-       # FIXME: remove this flag sometime in the future.
-       func_fatal_error "\`-allow-undefined' must not be used because it is the default"
-       ;;
-
-      -avoid-version)
-       avoid_version=yes
-       continue
-       ;;
-
-      -dlopen)
-       prev=dlfiles
-       continue
-       ;;
-
-      -dlpreopen)
-       prev=dlprefiles
-       continue
-       ;;
-
-      -export-dynamic)
-       export_dynamic=yes
-       continue
-       ;;
-
-      -export-symbols | -export-symbols-regex)
-       if test -n "$export_symbols" || test -n "$export_symbols_regex"; then
-         func_fatal_error "more than one -exported-symbols argument is not allowed"
-       fi
-       if test "X$arg" = "X-export-symbols"; then
-         prev=expsyms
-       else
-         prev=expsyms_regex
-       fi
-       continue
-       ;;
-
-      -framework)
-       prev=framework
-       continue
-       ;;
-
-      -inst-prefix-dir)
-       prev=inst_prefix
-       continue
-       ;;
-
-      # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:*
-      # so, if we see these flags be careful not to treat them like -L
-      -L[A-Z][A-Z]*:*)
-       case $with_gcc/$host in
-       no/*-*-irix* | /*-*-irix*)
-         func_append compile_command " $arg"
-         func_append finalize_command " $arg"
-         ;;
-       esac
-       continue
-       ;;
-
-      -L*)
-       func_stripname '-L' '' "$arg"
-       dir=$func_stripname_result
-       if test -z "$dir"; then
-         if test "$#" -gt 0; then
-           func_fatal_error "require no space between \`-L' and \`$1'"
-         else
-           func_fatal_error "need path for \`-L' option"
-         fi
-       fi
-       # We need an absolute path.
-       case $dir in
-       [\\/]* | [A-Za-z]:[\\/]*) ;;
-       *)
-         absdir=`cd "$dir" && pwd`
-         test -z "$absdir" && \
-           func_fatal_error "cannot determine absolute directory name of \`$dir'"
-         dir="$absdir"
-         ;;
-       esac
-       case "$deplibs " in
-       *" -L$dir "*) ;;
-       *)
-         deplibs="$deplibs -L$dir"
-         lib_search_path="$lib_search_path $dir"
-         ;;
-       esac
-       case $host in
-       *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
-         testbindir=`$ECHO "X$dir" | $Xsed -e 's*/lib$*/bin*'`
-         case :$dllsearchpath: in
-         *":$dir:"*) ;;
-         ::) dllsearchpath=$dir;;
-         *) dllsearchpath="$dllsearchpath:$dir";;
-         esac
-         case :$dllsearchpath: in
-         *":$testbindir:"*) ;;
-         ::) dllsearchpath=$testbindir;;
-         *) dllsearchpath="$dllsearchpath:$testbindir";;
-         esac
-         ;;
-       esac
-       continue
-       ;;
-
-      -l*)
-       if test "X$arg" = "X-lc" || test "X$arg" = "X-lm"; then
-         case $host in
-         *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos* | *-cegcc*)
-           # These systems don't actually have a C or math library (as such)
-           continue
-           ;;
-         *-*-os2*)
-           # These systems don't actually have a C library (as such)
-           test "X$arg" = "X-lc" && continue
-           ;;
-         *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*)
-           # Do not include libc due to us having libc/libc_r.
-           test "X$arg" = "X-lc" && continue
-           ;;
-         *-*-rhapsody* | *-*-darwin1.[012])
-           # Rhapsody C and math libraries are in the System framework
-           deplibs="$deplibs System.ltframework"
-           continue
-           ;;
-         *-*-sco3.2v5* | *-*-sco5v6*)
-           # Causes problems with __ctype
-           test "X$arg" = "X-lc" && continue
-           ;;
-         *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
-           # Compiler inserts libc in the correct place for threads to work
-           test "X$arg" = "X-lc" && continue
-           ;;
-         esac
-       elif test "X$arg" = "X-lc_r"; then
-        case $host in
-        *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*)
-          # Do not include libc_r directly, use -pthread flag.
-          continue
-          ;;
-        esac
-       fi
-       deplibs="$deplibs $arg"
-       continue
-       ;;
-
-      -module)
-       module=yes
-       continue
-       ;;
-
-      # Tru64 UNIX uses -model [arg] to determine the layout of C++
-      # classes, name mangling, and exception handling.
-      # Darwin uses the -arch flag to determine output architecture.
-      -model|-arch|-isysroot)
-       compiler_flags="$compiler_flags $arg"
-       func_append compile_command " $arg"
-       func_append finalize_command " $arg"
-       prev=xcompiler
-       continue
-       ;;
-
-      -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe|-threads)
-       compiler_flags="$compiler_flags $arg"
-       func_append compile_command " $arg"
-       func_append finalize_command " $arg"
-       case "$new_inherited_linker_flags " in
-           *" $arg "*) ;;
-           * ) new_inherited_linker_flags="$new_inherited_linker_flags $arg" ;;
-       esac
-       continue
-       ;;
-
-      -multi_module)
-       single_module="${wl}-multi_module"
-       continue
-       ;;
-
-      -no-fast-install)
-       fast_install=no
-       continue
-       ;;
-
-      -no-install)
-       case $host in
-       *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*)
-         # The PATH hackery in wrapper scripts is required on Windows
-         # and Darwin in order for the loader to find any dlls it needs.
-         func_warning "\`-no-install' is ignored for $host"
-         func_warning "assuming \`-no-fast-install' instead"
-         fast_install=no
-         ;;
-       *) no_install=yes ;;
-       esac
-       continue
-       ;;
-
-      -no-undefined)
-       allow_undefined=no
-       continue
-       ;;
-
-      -objectlist)
-       prev=objectlist
-       continue
-       ;;
-
-      -o) prev=output ;;
-
-      -precious-files-regex)
-       prev=precious_regex
-       continue
-       ;;
-
-      -release)
-       prev=release
-       continue
-       ;;
-
-      -rpath)
-       prev=rpath
-       continue
-       ;;
-
-      -R)
-       prev=xrpath
-       continue
-       ;;
-
-      -R*)
-       func_stripname '-R' '' "$arg"
-       dir=$func_stripname_result
-       # We need an absolute path.
-       case $dir in
-       [\\/]* | [A-Za-z]:[\\/]*) ;;
-       *)
-         func_fatal_error "only absolute run-paths are allowed"
-         ;;
-       esac
-       case "$xrpath " in
-       *" $dir "*) ;;
-       *) xrpath="$xrpath $dir" ;;
-       esac
-       continue
-       ;;
-
-      -shared)
-       # The effects of -shared are defined in a previous loop.
-       continue
-       ;;
-
-      -shrext)
-       prev=shrext
-       continue
-       ;;
-
-      -static | -static-libtool-libs)
-       # The effects of -static are defined in a previous loop.
-       # We used to do the same as -all-static on platforms that
-       # didn't have a PIC flag, but the assumption that the effects
-       # would be equivalent was wrong.  It would break on at least
-       # Digital Unix and AIX.
-       continue
-       ;;
-
-      -thread-safe)
-       thread_safe=yes
-       continue
-       ;;
-
-      -version-info)
-       prev=vinfo
-       continue
-       ;;
-
-      -version-number)
-       prev=vinfo
-       vinfo_number=yes
-       continue
-       ;;
-
-      -weak)
-        prev=weak
-       continue
-       ;;
-
-      -Wc,*)
-       func_stripname '-Wc,' '' "$arg"
-       args=$func_stripname_result
-       arg=
-       save_ifs="$IFS"; IFS=','
-       for flag in $args; do
-         IFS="$save_ifs"
-          func_quote_for_eval "$flag"
-         arg="$arg $wl$func_quote_for_eval_result"
-         compiler_flags="$compiler_flags $func_quote_for_eval_result"
-       done
-       IFS="$save_ifs"
-       func_stripname ' ' '' "$arg"
-       arg=$func_stripname_result
-       ;;
-
-      -Wl,*)
-       func_stripname '-Wl,' '' "$arg"
-       args=$func_stripname_result
-       arg=
-       save_ifs="$IFS"; IFS=','
-       for flag in $args; do
-         IFS="$save_ifs"
-          func_quote_for_eval "$flag"
-         arg="$arg $wl$func_quote_for_eval_result"
-         compiler_flags="$compiler_flags $wl$func_quote_for_eval_result"
-         linker_flags="$linker_flags $func_quote_for_eval_result"
-       done
-       IFS="$save_ifs"
-       func_stripname ' ' '' "$arg"
-       arg=$func_stripname_result
-       ;;
-
-      -Xcompiler)
-       prev=xcompiler
-       continue
-       ;;
-
-      -Xlinker)
-       prev=xlinker
-       continue
-       ;;
-
-      -XCClinker)
-       prev=xcclinker
-       continue
-       ;;
-
-      # -msg_* for osf cc
-      -msg_*)
-       func_quote_for_eval "$arg"
-       arg="$func_quote_for_eval_result"
-       ;;
-
-      # -64, -mips[0-9] enable 64-bit mode on the SGI compiler
-      # -r[0-9][0-9]* specifies the processor on the SGI compiler
-      # -xarch=*, -xtarget=* enable 64-bit mode on the Sun compiler
-      # +DA*, +DD* enable 64-bit mode on the HP compiler
-      # -q* pass through compiler args for the IBM compiler
-      # -m*, -t[45]*, -txscale* pass through architecture-specific
-      # compiler args for GCC
-      # -F/path gives path to uninstalled frameworks, gcc on darwin
-      # -p, -pg, --coverage, -fprofile-* pass through profiling flag for GCC
-      # @file GCC response files
-      -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
-      -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*)
-        func_quote_for_eval "$arg"
-       arg="$func_quote_for_eval_result"
-        func_append compile_command " $arg"
-        func_append finalize_command " $arg"
-        compiler_flags="$compiler_flags $arg"
-        continue
-        ;;
-
-      # Some other compiler flag.
-      -* | +*)
-        func_quote_for_eval "$arg"
-       arg="$func_quote_for_eval_result"
-       ;;
-
-      *.$objext)
-       # A standard object.
-       objs="$objs $arg"
-       ;;
-
-      *.lo)
-       # A libtool-controlled object.
-
-       # Check to see that this really is a libtool object.
-       if func_lalib_unsafe_p "$arg"; then
-         pic_object=
-         non_pic_object=
-
-         # Read the .lo file
-         func_source "$arg"
-
-         if test -z "$pic_object" ||
-            test -z "$non_pic_object" ||
-            test "$pic_object" = none &&
-            test "$non_pic_object" = none; then
-           func_fatal_error "cannot find name of object for \`$arg'"
-         fi
-
-         # Extract subdirectory from the argument.
-         func_dirname "$arg" "/" ""
-         xdir="$func_dirname_result"
-
-         if test "$pic_object" != none; then
-           # Prepend the subdirectory the object is found in.
-           pic_object="$xdir$pic_object"
-
-           if test "$prev" = dlfiles; then
-             if test "$build_libtool_libs" = yes && test "$dlopen_support" = yes; then
-               dlfiles="$dlfiles $pic_object"
-               prev=
-               continue
-             else
-               # If libtool objects are unsupported, then we need to preload.
-               prev=dlprefiles
-             fi
-           fi
-
-           # CHECK ME:  I think I busted this.  -Ossama
-           if test "$prev" = dlprefiles; then
-             # Preload the old-style object.
-             dlprefiles="$dlprefiles $pic_object"
-             prev=
-           fi
-
-           # A PIC object.
-           func_append libobjs " $pic_object"
-           arg="$pic_object"
-         fi
-
-         # Non-PIC object.
-         if test "$non_pic_object" != none; then
-           # Prepend the subdirectory the object is found in.
-           non_pic_object="$xdir$non_pic_object"
-
-           # A standard non-PIC object
-           func_append non_pic_objects " $non_pic_object"
-           if test -z "$pic_object" || test "$pic_object" = none ; then
-             arg="$non_pic_object"
-           fi
-         else
-           # If the PIC object exists, use it instead.
-           # $xdir was prepended to $pic_object above.
-           non_pic_object="$pic_object"
-           func_append non_pic_objects " $non_pic_object"
-         fi
-       else
-         # Only an error if not doing a dry-run.
-         if $opt_dry_run; then
-           # Extract subdirectory from the argument.
-           func_dirname "$arg" "/" ""
-           xdir="$func_dirname_result"
-
-           func_lo2o "$arg"
-           pic_object=$xdir$objdir/$func_lo2o_result
-           non_pic_object=$xdir$func_lo2o_result
-           func_append libobjs " $pic_object"
-           func_append non_pic_objects " $non_pic_object"
-         else
-           func_fatal_error "\`$arg' is not a valid libtool object"
-         fi
-       fi
-       ;;
-
-      *.$libext)
-       # An archive.
-       deplibs="$deplibs $arg"
-       old_deplibs="$old_deplibs $arg"
-       continue
-       ;;
-
-      *.la)
-       # A libtool-controlled library.
-
-       if test "$prev" = dlfiles; then
-         # This library was specified with -dlopen.
-         dlfiles="$dlfiles $arg"
-         prev=
-       elif test "$prev" = dlprefiles; then
-         # The library was specified with -dlpreopen.
-         dlprefiles="$dlprefiles $arg"
-         prev=
-       else
-         deplibs="$deplibs $arg"
-       fi
-       continue
-       ;;
-
-      # Some other compiler argument.
-      *)
-       # Unknown arguments in both finalize_command and compile_command need
-       # to be aesthetically quoted because they are evaled later.
-       func_quote_for_eval "$arg"
-       arg="$func_quote_for_eval_result"
-       ;;
-      esac # arg
-
-      # Now actually substitute the argument into the commands.
-      if test -n "$arg"; then
-       func_append compile_command " $arg"
-       func_append finalize_command " $arg"
-      fi
-    done # argument parsing loop
-
-    test -n "$prev" && \
-      func_fatal_help "the \`$prevarg' option requires an argument"
-
-    if test "$export_dynamic" = yes && test -n "$export_dynamic_flag_spec"; then
-      eval arg=\"$export_dynamic_flag_spec\"
-      func_append compile_command " $arg"
-      func_append finalize_command " $arg"
-    fi
-
-    oldlibs=
-    # calculate the name of the file, without its directory
-    func_basename "$output"
-    outputname="$func_basename_result"
-    libobjs_save="$libobjs"
-
-    if test -n "$shlibpath_var"; then
-      # get the directories listed in $shlibpath_var
-      eval shlib_search_path=\`\$ECHO \"X\${$shlibpath_var}\" \| \$Xsed -e \'s/:/ /g\'\`
-    else
-      shlib_search_path=
-    fi
-    eval sys_lib_search_path=\"$sys_lib_search_path_spec\"
-    eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\"
-
-    func_dirname "$output" "/" ""
-    output_objdir="$func_dirname_result$objdir"
-    # Create the object directory.
-    func_mkdir_p "$output_objdir"
-
-    # Determine the type of output
-    case $output in
-    "")
-      func_fatal_help "you must specify an output file"
-      ;;
-    *.$libext) linkmode=oldlib ;;
-    *.lo | *.$objext) linkmode=obj ;;
-    *.la) linkmode=lib ;;
-    *) linkmode=prog ;; # Anything else should be a program.
-    esac
-
-    specialdeplibs=
-
-    libs=
-    # Find all interdependent deplibs by searching for libraries
-    # that are linked more than once (e.g. -la -lb -la)
-    for deplib in $deplibs; do
-      if $opt_duplicate_deps ; then
-       case "$libs " in
-       *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;;
-       esac
-      fi
-      libs="$libs $deplib"
-    done
-
-    if test "$linkmode" = lib; then
-      libs="$predeps $libs $compiler_lib_search_path $postdeps"
-
-      # Compute libraries that are listed more than once in $predeps
-      # $postdeps and mark them as special (i.e., whose duplicates are
-      # not to be eliminated).
-      pre_post_deps=
-      if $opt_duplicate_compiler_generated_deps; then
-       for pre_post_dep in $predeps $postdeps; do
-         case "$pre_post_deps " in
-         *" $pre_post_dep "*) specialdeplibs="$specialdeplibs $pre_post_deps" ;;
-         esac
-         pre_post_deps="$pre_post_deps $pre_post_dep"
-       done
-      fi
-      pre_post_deps=
-    fi
-
-    deplibs=
-    newdependency_libs=
-    newlib_search_path=
-    need_relink=no # whether we're linking any uninstalled libtool libraries
-    notinst_deplibs= # not-installed libtool libraries
-    notinst_path= # paths that contain not-installed libtool libraries
-
-    case $linkmode in
-    lib)
-       passes="conv dlpreopen link"
-       for file in $dlfiles $dlprefiles; do
-         case $file in
-         *.la) ;;
-         *)
-           func_fatal_help "libraries can \`-dlopen' only libtool libraries: $file"
-           ;;
-         esac
-       done
-       ;;
-    prog)
-       compile_deplibs=
-       finalize_deplibs=
-       alldeplibs=no
-       newdlfiles=
-       newdlprefiles=
-       passes="conv scan dlopen dlpreopen link"
-       ;;
-    *)  passes="conv"
-       ;;
-    esac
-
-    for pass in $passes; do
-      # The preopen pass in lib mode reverses $deplibs; put it back here
-      # so that -L comes before libs that need it for instance...
-      if test "$linkmode,$pass" = "lib,link"; then
-       ## FIXME: Find the place where the list is rebuilt in the wrong
-       ##        order, and fix it there properly
-        tmp_deplibs=
-       for deplib in $deplibs; do
-         tmp_deplibs="$deplib $tmp_deplibs"
-       done
-       deplibs="$tmp_deplibs"
-      fi
-
-      if test "$linkmode,$pass" = "lib,link" ||
-        test "$linkmode,$pass" = "prog,scan"; then
-       libs="$deplibs"
-       deplibs=
-      fi
-      if test "$linkmode" = prog; then
-       case $pass in
-       dlopen) libs="$dlfiles" ;;
-       dlpreopen) libs="$dlprefiles" ;;
-       link)
-         libs="$deplibs %DEPLIBS%"
-         test "X$link_all_deplibs" != Xno && libs="$libs $dependency_libs"
-         ;;
-       esac
-      fi
-      if test "$linkmode,$pass" = "lib,dlpreopen"; then
-       # Collect and forward deplibs of preopened libtool libs
-       for lib in $dlprefiles; do
-         # Ignore non-libtool-libs
-         dependency_libs=
-         case $lib in
-         *.la) func_source "$lib" ;;
-         esac
-
-         # Collect preopened libtool deplibs, except any this library
-         # has declared as weak libs
-         for deplib in $dependency_libs; do
-            deplib_base=`$ECHO "X$deplib" | $Xsed -e "$basename"`
-           case " $weak_libs " in
-           *" $deplib_base "*) ;;
-           *) deplibs="$deplibs $deplib" ;;
-           esac
-         done
-       done
-       libs="$dlprefiles"
-      fi
-      if test "$pass" = dlopen; then
-       # Collect dlpreopened libraries
-       save_deplibs="$deplibs"
-       deplibs=
-      fi
-
-      for deplib in $libs; do
-       lib=
-       found=no
-       case $deplib in
-       -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe|-threads)
-         if test "$linkmode,$pass" = "prog,link"; then
-           compile_deplibs="$deplib $compile_deplibs"
-           finalize_deplibs="$deplib $finalize_deplibs"
-         else
-           compiler_flags="$compiler_flags $deplib"
-           if test "$linkmode" = lib ; then
-               case "$new_inherited_linker_flags " in
-                   *" $deplib "*) ;;
-                   * ) new_inherited_linker_flags="$new_inherited_linker_flags $deplib" ;;
-               esac
-           fi
-         fi
-         continue
-         ;;
-       -l*)
-         if test "$linkmode" != lib && test "$linkmode" != prog; then
-           func_warning "\`-l' is ignored for archives/objects"
-           continue
-         fi
-         func_stripname '-l' '' "$deplib"
-         name=$func_stripname_result
-         if test "$linkmode" = lib; then
-           searchdirs="$newlib_search_path $lib_search_path $compiler_lib_search_dirs $sys_lib_search_path $shlib_search_path"
-         else
-           searchdirs="$newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path"
-         fi
-         for searchdir in $searchdirs; do
-           for search_ext in .la $std_shrext .so .a; do
-             # Search the libtool library
-             lib="$searchdir/lib${name}${search_ext}"
-             if test -f "$lib"; then
-               if test "$search_ext" = ".la"; then
-                 found=yes
-               else
-                 found=no
-               fi
-               break 2
-             fi
-           done
-         done
-         if test "$found" != yes; then
-           # deplib doesn't seem to be a libtool library
-           if test "$linkmode,$pass" = "prog,link"; then
-             compile_deplibs="$deplib $compile_deplibs"
-             finalize_deplibs="$deplib $finalize_deplibs"
-           else
-             deplibs="$deplib $deplibs"
-             test "$linkmode" = lib && newdependency_libs="$deplib $newdependency_libs"
-           fi
-           continue
-         else # deplib is a libtool library
-           # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib,
-           # We need to do some special things here, and not later.
-           if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then
-             case " $predeps $postdeps " in
-             *" $deplib "*)
-               if func_lalib_p "$lib"; then
-                 library_names=
-                 old_library=
-                 func_source "$lib"
-                 for l in $old_library $library_names; do
-                   ll="$l"
-                 done
-                 if test "X$ll" = "X$old_library" ; then # only static version available
-                   found=no
-                   func_dirname "$lib" "" "."
-                   ladir="$func_dirname_result"
-                   lib=$ladir/$old_library
-                   if test "$linkmode,$pass" = "prog,link"; then
-                     compile_deplibs="$deplib $compile_deplibs"
-                     finalize_deplibs="$deplib $finalize_deplibs"
-                   else
-                     deplibs="$deplib $deplibs"
-                     test "$linkmode" = lib && newdependency_libs="$deplib $newdependency_libs"
-                   fi
-                   continue
-                 fi
-               fi
-               ;;
-             *) ;;
-             esac
-           fi
-         fi
-         ;; # -l
-       *.ltframework)
-         if test "$linkmode,$pass" = "prog,link"; then
-           compile_deplibs="$deplib $compile_deplibs"
-           finalize_deplibs="$deplib $finalize_deplibs"
-         else
-           deplibs="$deplib $deplibs"
-           if test "$linkmode" = lib ; then
-               case "$new_inherited_linker_flags " in
-                   *" $deplib "*) ;;
-                   * ) new_inherited_linker_flags="$new_inherited_linker_flags $deplib" ;;
-               esac
-           fi
-         fi
-         continue
-         ;;
-       -L*)
-         case $linkmode in
-         lib)
-           deplibs="$deplib $deplibs"
-           test "$pass" = conv && continue
-           newdependency_libs="$deplib $newdependency_libs"
-           func_stripname '-L' '' "$deplib"
-           newlib_search_path="$newlib_search_path $func_stripname_result"
-           ;;
-         prog)
-           if test "$pass" = conv; then
-             deplibs="$deplib $deplibs"
-             continue
-           fi
-           if test "$pass" = scan; then
-             deplibs="$deplib $deplibs"
-           else
-             compile_deplibs="$deplib $compile_deplibs"
-             finalize_deplibs="$deplib $finalize_deplibs"
-           fi
-           func_stripname '-L' '' "$deplib"
-           newlib_search_path="$newlib_search_path $func_stripname_result"
-           ;;
-         *)
-           func_warning "\`-L' is ignored for archives/objects"
-           ;;
-         esac # linkmode
-         continue
-         ;; # -L
-       -R*)
-         if test "$pass" = link; then
-           func_stripname '-R' '' "$deplib"
-           dir=$func_stripname_result
-           # Make sure the xrpath contains only unique directories.
-           case "$xrpath " in
-           *" $dir "*) ;;
-           *) xrpath="$xrpath $dir" ;;
-           esac
-         fi
-         deplibs="$deplib $deplibs"
-         continue
-         ;;
-       *.la) lib="$deplib" ;;
-       *.$libext)
-         if test "$pass" = conv; then
-           deplibs="$deplib $deplibs"
-           continue
-         fi
-         case $linkmode in
-         lib)
-           # Linking convenience modules into shared libraries is allowed,
-           # but linking other static libraries is non-portable.
-           case " $dlpreconveniencelibs " in
-           *" $deplib "*) ;;
-           *)
-             valid_a_lib=no
-             case $deplibs_check_method in
-               match_pattern*)
-                 set dummy $deplibs_check_method; shift
-                 match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
-                 if eval "\$ECHO \"X$deplib\"" 2>/dev/null | $Xsed -e 10q \
-                   | $EGREP "$match_pattern_regex" > /dev/null; then
-                   valid_a_lib=yes
-                 fi
-               ;;
-               pass_all)
-                 valid_a_lib=yes
-               ;;
-             esac
-             if test "$valid_a_lib" != yes; then
-               $ECHO
-               $ECHO "*** Warning: Trying to link with static lib archive $deplib."
-               $ECHO "*** I have the capability to make that library automatically link in when"
-               $ECHO "*** you link to this library.  But I can only do this if you have a"
-               $ECHO "*** shared version of the library, which you do not appear to have"
-               $ECHO "*** because the file extensions .$libext of this argument makes me believe"
-               $ECHO "*** that it is just a static archive that I should not use here."
-             else
-               $ECHO
-               $ECHO "*** Warning: Linking the shared library $output against the"
-               $ECHO "*** static library $deplib is not portable!"
-               deplibs="$deplib $deplibs"
-             fi
-             ;;
-           esac
-           continue
-           ;;
-         prog)
-           if test "$pass" != link; then
-             deplibs="$deplib $deplibs"
-           else
-             compile_deplibs="$deplib $compile_deplibs"
-             finalize_deplibs="$deplib $finalize_deplibs"
-           fi
-           continue
-           ;;
-         esac # linkmode
-         ;; # *.$libext
-       *.lo | *.$objext)
-         if test "$pass" = conv; then
-           deplibs="$deplib $deplibs"
-         elif test "$linkmode" = prog; then
-           if test "$pass" = dlpreopen || test "$dlopen_support" != yes || test "$build_libtool_libs" = no; then
-             # If there is no dlopen support or we're linking statically,
-             # we need to preload.
-             newdlprefiles="$newdlprefiles $deplib"
-             compile_deplibs="$deplib $compile_deplibs"
-             finalize_deplibs="$deplib $finalize_deplibs"
-           else
-             newdlfiles="$newdlfiles $deplib"
-           fi
-         fi
-         continue
-         ;;
-       %DEPLIBS%)
-         alldeplibs=yes
-         continue
-         ;;
-       esac # case $deplib
-
-       if test "$found" = yes || test -f "$lib"; then :
-       else
-         func_fatal_error "cannot find the library \`$lib' or unhandled argument \`$deplib'"
-       fi
-
-       # Check to see that this really is a libtool archive.
-       func_lalib_unsafe_p "$lib" \
-         || func_fatal_error "\`$lib' is not a valid libtool archive"
-
-       func_dirname "$lib" "" "."
-       ladir="$func_dirname_result"
-
-       dlname=
-       dlopen=
-       dlpreopen=
-       libdir=
-       library_names=
-       old_library=
-       inherited_linker_flags=
-       # If the library was installed with an old release of libtool,
-       # it will not redefine variables installed, or shouldnotlink
-       installed=yes
-       shouldnotlink=no
-       avoidtemprpath=
-
-
-       # Read the .la file
-       func_source "$lib"
-
-       # Convert "-framework foo" to "foo.ltframework"
-       if test -n "$inherited_linker_flags"; then
-         tmp_inherited_linker_flags=`$ECHO "X$inherited_linker_flags" | $Xsed -e 's/-framework \([^ $]*\)/\1.ltframework/g'`
-         for tmp_inherited_linker_flag in $tmp_inherited_linker_flags; do
-           case " $new_inherited_linker_flags " in
-             *" $tmp_inherited_linker_flag "*) ;;
-             *) new_inherited_linker_flags="$new_inherited_linker_flags $tmp_inherited_linker_flag";;
-           esac
-         done
-       fi
-       dependency_libs=`$ECHO "X $dependency_libs" | $Xsed -e 's% \([^ $]*\).ltframework% -framework \1%g'`
-       if test "$linkmode,$pass" = "lib,link" ||
-          test "$linkmode,$pass" = "prog,scan" ||
-          { test "$linkmode" != prog && test "$linkmode" != lib; }; then
-         test -n "$dlopen" && dlfiles="$dlfiles $dlopen"
-         test -n "$dlpreopen" && dlprefiles="$dlprefiles $dlpreopen"
-       fi
-
-       if test "$pass" = conv; then
-         # Only check for convenience libraries
-         deplibs="$lib $deplibs"
-         if test -z "$libdir"; then
-           if test -z "$old_library"; then
-             func_fatal_error "cannot find name of link library for \`$lib'"
-           fi
-           # It is a libtool convenience library, so add in its objects.
-           convenience="$convenience $ladir/$objdir/$old_library"
-           old_convenience="$old_convenience $ladir/$objdir/$old_library"
-           tmp_libs=
-           for deplib in $dependency_libs; do
-             deplibs="$deplib $deplibs"
-             if $opt_duplicate_deps ; then
-               case "$tmp_libs " in
-               *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;;
-               esac
-             fi
-             tmp_libs="$tmp_libs $deplib"
-           done
-         elif test "$linkmode" != prog && test "$linkmode" != lib; then
-           func_fatal_error "\`$lib' is not a convenience library"
-         fi
-         continue
-       fi # $pass = conv
-
-
-       # Get the name of the library we link against.
-       linklib=
-       for l in $old_library $library_names; do
-         linklib="$l"
-       done
-       if test -z "$linklib"; then
-         func_fatal_error "cannot find name of link library for \`$lib'"
-       fi
-
-       # This library was specified with -dlopen.
-       if test "$pass" = dlopen; then
-         if test -z "$libdir"; then
-           func_fatal_error "cannot -dlopen a convenience library: \`$lib'"
-         fi
-         if test -z "$dlname" ||
-            test "$dlopen_support" != yes ||
-            test "$build_libtool_libs" = no; then
-           # If there is no dlname, no dlopen support or we're linking
-           # statically, we need to preload.  We also need to preload any
-           # dependent libraries so libltdl's deplib preloader doesn't
-           # bomb out in the load deplibs phase.
-           dlprefiles="$dlprefiles $lib $dependency_libs"
-         else
-           newdlfiles="$newdlfiles $lib"
-         fi
-         continue
-       fi # $pass = dlopen
-
-       # We need an absolute path.
-       case $ladir in
-       [\\/]* | [A-Za-z]:[\\/]*) abs_ladir="$ladir" ;;
-       *)
-         abs_ladir=`cd "$ladir" && pwd`
-         if test -z "$abs_ladir"; then
-           func_warning "cannot determine absolute directory name of \`$ladir'"
-           func_warning "passing it literally to the linker, although it might fail"
-           abs_ladir="$ladir"
-         fi
-         ;;
-       esac
-       func_basename "$lib"
-       laname="$func_basename_result"
-
-       # Find the relevant object directory and library name.
-       if test "X$installed" = Xyes; then
-         if test ! -f "$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then
-           func_warning "library \`$lib' was moved."
-           dir="$ladir"
-           absdir="$abs_ladir"
-           libdir="$abs_ladir"
-         else
-           dir="$libdir"
-           absdir="$libdir"
-         fi
-         test "X$hardcode_automatic" = Xyes && avoidtemprpath=yes
-       else
-         if test ! -f "$ladir/$objdir/$linklib" && test -f "$abs_ladir/$linklib"; then
-           dir="$ladir"
-           absdir="$abs_ladir"
-           # Remove this search path later
-           notinst_path="$notinst_path $abs_ladir"
-         else
-           dir="$ladir/$objdir"
-           absdir="$abs_ladir/$objdir"
-           # Remove this search path later
-           notinst_path="$notinst_path $abs_ladir"
-         fi
-       fi # $installed = yes
-       func_stripname 'lib' '.la' "$laname"
-       name=$func_stripname_result
-
-       # This library was specified with -dlpreopen.
-       if test "$pass" = dlpreopen; then
-         if test -z "$libdir" && test "$linkmode" = prog; then
-           func_fatal_error "only libraries may -dlpreopen a convenience library: \`$lib'"
-         fi
-         # Prefer using a static library (so that no silly _DYNAMIC symbols
-         # are required to link).
-         if test -n "$old_library"; then
-           newdlprefiles="$newdlprefiles $dir/$old_library"
-           # Keep a list of preopened convenience libraries to check
-           # that they are being used correctly in the link pass.
-           test -z "$libdir" && \
-               dlpreconveniencelibs="$dlpreconveniencelibs $dir/$old_library"
-         # Otherwise, use the dlname, so that lt_dlopen finds it.
-         elif test -n "$dlname"; then
-           newdlprefiles="$newdlprefiles $dir/$dlname"
-         else
-           newdlprefiles="$newdlprefiles $dir/$linklib"
-         fi
-       fi # $pass = dlpreopen
-
-       if test -z "$libdir"; then
-         # Link the convenience library
-         if test "$linkmode" = lib; then
-           deplibs="$dir/$old_library $deplibs"
-         elif test "$linkmode,$pass" = "prog,link"; then
-           compile_deplibs="$dir/$old_library $compile_deplibs"
-           finalize_deplibs="$dir/$old_library $finalize_deplibs"
-         else
-           deplibs="$lib $deplibs" # used for prog,scan pass
-         fi
-         continue
-       fi
-
-
-       if test "$linkmode" = prog && test "$pass" != link; then
-         newlib_search_path="$newlib_search_path $ladir"
-         deplibs="$lib $deplibs"
-
-         linkalldeplibs=no
-         if test "$link_all_deplibs" != no || test -z "$library_names" ||
-            test "$build_libtool_libs" = no; then
-           linkalldeplibs=yes
-         fi
-
-         tmp_libs=
-         for deplib in $dependency_libs; do
-           case $deplib in
-           -L*) func_stripname '-L' '' "$deplib"
-                newlib_search_path="$newlib_search_path $func_stripname_result"
-                ;;
-           esac
-           # Need to link against all dependency_libs?
-           if test "$linkalldeplibs" = yes; then
-             deplibs="$deplib $deplibs"
-           else
-             # Need to hardcode shared library paths
-             # or/and link against static libraries
-             newdependency_libs="$deplib $newdependency_libs"
-           fi
-           if $opt_duplicate_deps ; then
-             case "$tmp_libs " in
-             *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;;
-             esac
-           fi
-           tmp_libs="$tmp_libs $deplib"
-         done # for deplib
-         continue
-       fi # $linkmode = prog...
-
-       if test "$linkmode,$pass" = "prog,link"; then
-         if test -n "$library_names" &&
-            { { test "$prefer_static_libs" = no ||
-                test "$prefer_static_libs,$installed" = "built,yes"; } ||
-              test -z "$old_library"; }; then
-           # We need to hardcode the library path
-           if test -n "$shlibpath_var" && test -z "$avoidtemprpath" ; then
-             # Make sure the rpath contains only unique directories.
-             case "$temp_rpath:" in
-             *"$absdir:"*) ;;
-             *) temp_rpath="$temp_rpath$absdir:" ;;
-             esac
-           fi
-
-           # Hardcode the library path.
-           # Skip directories that are in the system default run-time
-           # search path.
-           case " $sys_lib_dlsearch_path " in
-           *" $absdir "*) ;;
-           *)
-             case "$compile_rpath " in
-             *" $absdir "*) ;;
-             *) compile_rpath="$compile_rpath $absdir"
-             esac
-             ;;
-           esac
-           case " $sys_lib_dlsearch_path " in
-           *" $libdir "*) ;;
-           *)
-             case "$finalize_rpath " in
-             *" $libdir "*) ;;
-             *) finalize_rpath="$finalize_rpath $libdir"
-             esac
-             ;;
-           esac
-         fi # $linkmode,$pass = prog,link...
-
-         if test "$alldeplibs" = yes &&
-            { test "$deplibs_check_method" = pass_all ||
-              { test "$build_libtool_libs" = yes &&
-                test -n "$library_names"; }; }; then
-           # We only need to search for static libraries
-           continue
-         fi
-       fi
-
-       link_static=no # Whether the deplib will be linked statically
-       use_static_libs=$prefer_static_libs
-       if test "$use_static_libs" = built && test "$installed" = yes; then
-         use_static_libs=no
-       fi
-       if test -n "$library_names" &&
-          { test "$use_static_libs" = no || test -z "$old_library"; }; then
-         case $host in
-         *cygwin* | *mingw* | *cegcc*)
-             # No point in relinking DLLs because paths are not encoded
-             notinst_deplibs="$notinst_deplibs $lib"
-             need_relink=no
-           ;;
-         *)
-           if test "$installed" = no; then
-             notinst_deplibs="$notinst_deplibs $lib"
-             need_relink=yes
-           fi
-           ;;
-         esac
-         # This is a shared library
-
-         # Warn about portability, can't link against -module's on some
-         # systems (darwin).  Don't bleat about dlopened modules though!
-         dlopenmodule=""
-         for dlpremoduletest in $dlprefiles; do
-           if test "X$dlpremoduletest" = "X$lib"; then
-             dlopenmodule="$dlpremoduletest"
-             break
-           fi
-         done
-         if test -z "$dlopenmodule" && test "$shouldnotlink" = yes && test "$pass" = link; then
-           $ECHO
-           if test "$linkmode" = prog; then
-             $ECHO "*** Warning: Linking the executable $output against the loadable module"
-           else
-             $ECHO "*** Warning: Linking the shared library $output against the loadable module"
-           fi
-           $ECHO "*** $linklib is not portable!"
-         fi
-         if test "$linkmode" = lib &&
-            test "$hardcode_into_libs" = yes; then
-           # Hardcode the library path.
-           # Skip directories that are in the system default run-time
-           # search path.
-           case " $sys_lib_dlsearch_path " in
-           *" $absdir "*) ;;
-           *)
-             case "$compile_rpath " in
-             *" $absdir "*) ;;
-             *) compile_rpath="$compile_rpath $absdir"
-             esac
-             ;;
-           esac
-           case " $sys_lib_dlsearch_path " in
-           *" $libdir "*) ;;
-           *)
-             case "$finalize_rpath " in
-             *" $libdir "*) ;;
-             *) finalize_rpath="$finalize_rpath $libdir"
-             esac
-             ;;
-           esac
-         fi
-
-         if test -n "$old_archive_from_expsyms_cmds"; then
-           # figure out the soname
-           set dummy $library_names
-           shift
-           realname="$1"
-           shift
-           libname=`eval "\\$ECHO \"$libname_spec\""`
-           # use dlname if we got it. it's perfectly good, no?
-           if test -n "$dlname"; then
-             soname="$dlname"
-           elif test -n "$soname_spec"; then
-             # bleh windows
-             case $host in
-             *cygwin* | mingw* | *cegcc*)
-               func_arith $current - $age
-               major=$func_arith_result
-               versuffix="-$major"
-               ;;
-             esac
-             eval soname=\"$soname_spec\"
-           else
-             soname="$realname"
-           fi
-
-           # Make a new name for the extract_expsyms_cmds to use
-           soroot="$soname"
-           func_basename "$soroot"
-           soname="$func_basename_result"
-           func_stripname 'lib' '.dll' "$soname"
-           newlib=libimp-$func_stripname_result.a
-
-           # If the library has no export list, then create one now
-           if test -f "$output_objdir/$soname-def"; then :
-           else
-             func_verbose "extracting exported symbol list from \`$soname'"
-             func_execute_cmds "$extract_expsyms_cmds" 'exit $?'
-           fi
-
-           # Create $newlib
-           if test -f "$output_objdir/$newlib"; then :; else
-             func_verbose "generating import library for \`$soname'"
-             func_execute_cmds "$old_archive_from_expsyms_cmds" 'exit $?'
-           fi
-           # make sure the library variables are pointing to the new library
-           dir=$output_objdir
-           linklib=$newlib
-         fi # test -n "$old_archive_from_expsyms_cmds"
-
-         if test "$linkmode" = prog || test "$mode" != relink; then
-           add_shlibpath=
-           add_dir=
-           add=
-           lib_linked=yes
-           case $hardcode_action in
-           immediate | unsupported)
-             if test "$hardcode_direct" = no; then
-               add="$dir/$linklib"
-               case $host in
-                 *-*-sco3.2v5.0.[024]*) add_dir="-L$dir" ;;
-                 *-*-sysv4*uw2*) add_dir="-L$dir" ;;
-                 *-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \
-                   *-*-unixware7*) add_dir="-L$dir" ;;
-                 *-*-darwin* )
-                   # if the lib is a (non-dlopened) module then we can not
-                   # link against it, someone is ignoring the earlier warnings
-                   if /usr/bin/file -L $add 2> /dev/null |
-                        $GREP ": [^:]* bundle" >/dev/null ; then
-                     if test "X$dlopenmodule" != "X$lib"; then
-                       $ECHO "*** Warning: lib $linklib is a module, not a shared library"
-                       if test -z "$old_library" ; then
-                         $ECHO
-                         $ECHO "*** And there doesn't seem to be a static archive available"
-                         $ECHO "*** The link will probably fail, sorry"
-                       else
-                         add="$dir/$old_library"
-                       fi
-                     elif test -n "$old_library"; then
-                       add="$dir/$old_library"
-                     fi
-                   fi
-               esac
-             elif test "$hardcode_minus_L" = no; then
-               case $host in
-               *-*-sunos*) add_shlibpath="$dir" ;;
-               esac
-               add_dir="-L$dir"
-               add="-l$name"
-             elif test "$hardcode_shlibpath_var" = no; then
-               add_shlibpath="$dir"
-               add="-l$name"
-             else
-               lib_linked=no
-             fi
-             ;;
-           relink)
-             if test "$hardcode_direct" = yes &&
-                test "$hardcode_direct_absolute" = no; then
-               add="$dir/$linklib"
-             elif test "$hardcode_minus_L" = yes; then
-               add_dir="-L$dir"
-               # Try looking first in the location we're being installed to.
-               if test -n "$inst_prefix_dir"; then
-                 case $libdir in
-                   [\\/]*)
-                     add_dir="$add_dir -L$inst_prefix_dir$libdir"
-                     ;;
-                 esac
-               fi
-               add="-l$name"
-             elif test "$hardcode_shlibpath_var" = yes; then
-               add_shlibpath="$dir"
-               add="-l$name"
-             else
-               lib_linked=no
-             fi
-             ;;
-           *) lib_linked=no ;;
-           esac
-
-           if test "$lib_linked" != yes; then
-             func_fatal_configuration "unsupported hardcode properties"
-           fi
-
-           if test -n "$add_shlibpath"; then
-             case :$compile_shlibpath: in
-             *":$add_shlibpath:"*) ;;
-             *) compile_shlibpath="$compile_shlibpath$add_shlibpath:" ;;
-             esac
-           fi
-           if test "$linkmode" = prog; then
-             test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs"
-             test -n "$add" && compile_deplibs="$add $compile_deplibs"
-           else
-             test -n "$add_dir" && deplibs="$add_dir $deplibs"
-             test -n "$add" && deplibs="$add $deplibs"
-             if test "$hardcode_direct" != yes &&
-                test "$hardcode_minus_L" != yes &&
-                test "$hardcode_shlibpath_var" = yes; then
-               case :$finalize_shlibpath: in
-               *":$libdir:"*) ;;
-               *) finalize_shlibpath="$finalize_shlibpath$libdir:" ;;
-               esac
-             fi
-           fi
-         fi
-
-         if test "$linkmode" = prog || test "$mode" = relink; then
-           add_shlibpath=
-           add_dir=
-           add=
-           # Finalize command for both is simple: just hardcode it.
-           if test "$hardcode_direct" = yes &&
-              test "$hardcode_direct_absolute" = no; then
-             add="$libdir/$linklib"
-           elif test "$hardcode_minus_L" = yes; then
-             add_dir="-L$libdir"
-             add="-l$name"
-           elif test "$hardcode_shlibpath_var" = yes; then
-             case :$finalize_shlibpath: in
-             *":$libdir:"*) ;;
-             *) finalize_shlibpath="$finalize_shlibpath$libdir:" ;;
-             esac
-             add="-l$name"
-           elif test "$hardcode_automatic" = yes; then
-             if test -n "$inst_prefix_dir" &&
-                test -f "$inst_prefix_dir$libdir/$linklib" ; then
-               add="$inst_prefix_dir$libdir/$linklib"
-             else
-               add="$libdir/$linklib"
-             fi
-           else
-             # We cannot seem to hardcode it, guess we'll fake it.
-             add_dir="-L$libdir"
-             # Try looking first in the location we're being installed to.
-             if test -n "$inst_prefix_dir"; then
-               case $libdir in
-                 [\\/]*)
-                   add_dir="$add_dir -L$inst_prefix_dir$libdir"
-                   ;;
-               esac
-             fi
-             add="-l$name"
-           fi
-
-           if test "$linkmode" = prog; then
-             test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs"
-             test -n "$add" && finalize_deplibs="$add $finalize_deplibs"
-           else
-             test -n "$add_dir" && deplibs="$add_dir $deplibs"
-             test -n "$add" && deplibs="$add $deplibs"
-           fi
-         fi
-       elif test "$linkmode" = prog; then
-         # Here we assume that one of hardcode_direct or hardcode_minus_L
-         # is not unsupported.  This is valid on all known static and
-         # shared platforms.
-         if test "$hardcode_direct" != unsupported; then
-           test -n "$old_library" && linklib="$old_library"
-           compile_deplibs="$dir/$linklib $compile_deplibs"
-           finalize_deplibs="$dir/$linklib $finalize_deplibs"
-         else
-           compile_deplibs="-l$name -L$dir $compile_deplibs"
-           finalize_deplibs="-l$name -L$dir $finalize_deplibs"
-         fi
-       elif test "$build_libtool_libs" = yes; then
-         # Not a shared library
-         if test "$deplibs_check_method" != pass_all; then
-           # We're trying link a shared library against a static one
-           # but the system doesn't support it.
-
-           # Just print a warning and add the library to dependency_libs so
-           # that the program can be linked against the static library.
-           $ECHO
-           $ECHO "*** Warning: This system can not link to static lib archive $lib."
-           $ECHO "*** I have the capability to make that library automatically link in when"
-           $ECHO "*** you link to this library.  But I can only do this if you have a"
-           $ECHO "*** shared version of the library, which you do not appear to have."
-           if test "$module" = yes; then
-             $ECHO "*** But as you try to build a module library, libtool will still create "
-             $ECHO "*** a static module, that should work as long as the dlopening application"
-             $ECHO "*** is linked with the -dlopen flag to resolve symbols at runtime."
-             if test -z "$global_symbol_pipe"; then
-               $ECHO
-               $ECHO "*** However, this would only work if libtool was able to extract symbol"
-               $ECHO "*** lists from a program, using \`nm' or equivalent, but libtool could"
-               $ECHO "*** not find such a program.  So, this module is probably useless."
-               $ECHO "*** \`nm' from GNU binutils and a full rebuild may help."
-             fi
-             if test "$build_old_libs" = no; then
-               build_libtool_libs=module
-               build_old_libs=yes
-             else
-               build_libtool_libs=no
-             fi
-           fi
-         else
-           deplibs="$dir/$old_library $deplibs"
-           link_static=yes
-         fi
-       fi # link shared/static library?
-
-       if test "$linkmode" = lib; then
-         if test -n "$dependency_libs" &&
-            { test "$hardcode_into_libs" != yes ||
-              test "$build_old_libs" = yes ||
-              test "$link_static" = yes; }; then
-           # Extract -R from dependency_libs
-           temp_deplibs=
-           for libdir in $dependency_libs; do
-             case $libdir in
-             -R*) func_stripname '-R' '' "$libdir"
-                  temp_xrpath=$func_stripname_result
-                  case " $xrpath " in
-                  *" $temp_xrpath "*) ;;
-                  *) xrpath="$xrpath $temp_xrpath";;
-                  esac;;
-             *) temp_deplibs="$temp_deplibs $libdir";;
-             esac
-           done
-           dependency_libs="$temp_deplibs"
-         fi
-
-         newlib_search_path="$newlib_search_path $absdir"
-         # Link against this library
-         test "$link_static" = no && newdependency_libs="$abs_ladir/$laname $newdependency_libs"
-         # ... and its dependency_libs
-         tmp_libs=
-         for deplib in $dependency_libs; do
-           newdependency_libs="$deplib $newdependency_libs"
-           if $opt_duplicate_deps ; then
-             case "$tmp_libs " in
-             *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;;
-             esac
-           fi
-           tmp_libs="$tmp_libs $deplib"
-         done
-
-         if test "$link_all_deplibs" != no; then
-           # Add the search paths of all dependency libraries
-           for deplib in $dependency_libs; do
-             path=
-             case $deplib in
-             -L*) path="$deplib" ;;
-             *.la)
-               func_dirname "$deplib" "" "."
-               dir="$func_dirname_result"
-               # We need an absolute path.
-               case $dir in
-               [\\/]* | [A-Za-z]:[\\/]*) absdir="$dir" ;;
-               *)
-                 absdir=`cd "$dir" && pwd`
-                 if test -z "$absdir"; then
-                   func_warning "cannot determine absolute directory name of \`$dir'"
-                   absdir="$dir"
-                 fi
-                 ;;
-               esac
-               if $GREP "^installed=no" $deplib > /dev/null; then
-               case $host in
-               *-*-darwin*)
-                 depdepl=
-                 eval deplibrary_names=`${SED} -n -e 's/^library_names=\(.*\)$/\1/p' $deplib`
-                 if test -n "$deplibrary_names" ; then
-                   for tmp in $deplibrary_names ; do
-                     depdepl=$tmp
-                   done
-                   if test -f "$absdir/$objdir/$depdepl" ; then
-                     depdepl="$absdir/$objdir/$depdepl"
-                     darwin_install_name=`${OTOOL} -L $depdepl | awk '{if (NR == 2) {print $1;exit}}'`
-                      if test -z "$darwin_install_name"; then
-                          darwin_install_name=`${OTOOL64} -L $depdepl  | awk '{if (NR == 2) {print $1;exit}}'`
-                      fi
-                     compiler_flags="$compiler_flags ${wl}-dylib_file ${wl}${darwin_install_name}:${depdepl}"
-                     linker_flags="$linker_flags -dylib_file ${darwin_install_name}:${depdepl}"
-                     path=
-                   fi
-                 fi
-                 ;;
-               *)
-                 path="-L$absdir/$objdir"
-                 ;;
-               esac
-               else
-                 eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $deplib`
-                 test -z "$libdir" && \
-                   func_fatal_error "\`$deplib' is not a valid libtool archive"
-                 test "$absdir" != "$libdir" && \
-                   func_warning "\`$deplib' seems to be moved"
-
-                 path="-L$absdir"
-               fi
-               ;;
-             esac
-             case " $deplibs " in
-             *" $path "*) ;;
-             *) deplibs="$path $deplibs" ;;
-             esac
-           done
-         fi # link_all_deplibs != no
-       fi # linkmode = lib
-      done # for deplib in $libs
-      if test "$pass" = link; then
-       if test "$linkmode" = "prog"; then
-         compile_deplibs="$new_inherited_linker_flags $compile_deplibs"
-         finalize_deplibs="$new_inherited_linker_flags $finalize_deplibs"
-       else
-         compiler_flags="$compiler_flags "`$ECHO "X $new_inherited_linker_flags" | $Xsed -e 's% \([^ $]*\).ltframework% -framework \1%g'`
-       fi
-      fi
-      dependency_libs="$newdependency_libs"
-      if test "$pass" = dlpreopen; then
-       # Link the dlpreopened libraries before other libraries
-       for deplib in $save_deplibs; do
-         deplibs="$deplib $deplibs"
-       done
-      fi
-      if test "$pass" != dlopen; then
-       if test "$pass" != conv; then
-         # Make sure lib_search_path contains only unique directories.
-         lib_search_path=
-         for dir in $newlib_search_path; do
-           case "$lib_search_path " in
-           *" $dir "*) ;;
-           *) lib_search_path="$lib_search_path $dir" ;;
-           esac
-         done
-         newlib_search_path=
-       fi
-
-       if test "$linkmode,$pass" != "prog,link"; then
-         vars="deplibs"
-       else
-         vars="compile_deplibs finalize_deplibs"
-       fi
-       for var in $vars dependency_libs; do
-         # Add libraries to $var in reverse order
-         eval tmp_libs=\"\$$var\"
-         new_libs=
-         for deplib in $tmp_libs; do
-           # FIXME: Pedantically, this is the right thing to do, so
-           #        that some nasty dependency loop isn't accidentally
-           #        broken:
-           #new_libs="$deplib $new_libs"
-           # Pragmatically, this seems to cause very few problems in
-           # practice:
-           case $deplib in
-           -L*) new_libs="$deplib $new_libs" ;;
-           -R*) ;;
-           *)
-             # And here is the reason: when a library appears more
-             # than once as an explicit dependence of a library, or
-             # is implicitly linked in more than once by the
-             # compiler, it is considered special, and multiple
-             # occurrences thereof are not removed.  Compare this
-             # with having the same library being listed as a
-             # dependency of multiple other libraries: in this case,
-             # we know (pedantically, we assume) the library does not
-             # need to be listed more than once, so we keep only the
-             # last copy.  This is not always right, but it is rare
-             # enough that we require users that really mean to play
-             # such unportable linking tricks to link the library
-             # using -Wl,-lname, so that libtool does not consider it
-             # for duplicate removal.
-             case " $specialdeplibs " in
-             *" $deplib "*) new_libs="$deplib $new_libs" ;;
-             *)
-               case " $new_libs " in
-               *" $deplib "*) ;;
-               *) new_libs="$deplib $new_libs" ;;
-               esac
-               ;;
-             esac
-             ;;
-           esac
-         done
-         tmp_libs=
-         for deplib in $new_libs; do
-           case $deplib in
-           -L*)
-             case " $tmp_libs " in
-             *" $deplib "*) ;;
-             *) tmp_libs="$tmp_libs $deplib" ;;
-             esac
-             ;;
-           *) tmp_libs="$tmp_libs $deplib" ;;
-           esac
-         done
-         eval $var=\"$tmp_libs\"
-       done # for var
-      fi
-      # Last step: remove runtime libs from dependency_libs
-      # (they stay in deplibs)
-      tmp_libs=
-      for i in $dependency_libs ; do
-       case " $predeps $postdeps $compiler_lib_search_path " in
-       *" $i "*)
-         i=""
-         ;;
-       esac
-       if test -n "$i" ; then
-         tmp_libs="$tmp_libs $i"
-       fi
-      done
-      dependency_libs=$tmp_libs
-    done # for pass
-    if test "$linkmode" = prog; then
-      dlfiles="$newdlfiles"
-    fi
-    if test "$linkmode" = prog || test "$linkmode" = lib; then
-      dlprefiles="$newdlprefiles"
-    fi
-
-    case $linkmode in
-    oldlib)
-      if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then
-       func_warning "\`-dlopen' is ignored for archives"
-      fi
-
-      case " $deplibs" in
-      *\ -l* | *\ -L*)
-       func_warning "\`-l' and \`-L' are ignored for archives" ;;
-      esac
-
-      test -n "$rpath" && \
-       func_warning "\`-rpath' is ignored for archives"
-
-      test -n "$xrpath" && \
-       func_warning "\`-R' is ignored for archives"
-
-      test -n "$vinfo" && \
-       func_warning "\`-version-info/-version-number' is ignored for archives"
-
-      test -n "$release" && \
-       func_warning "\`-release' is ignored for archives"
-
-      test -n "$export_symbols$export_symbols_regex" && \
-       func_warning "\`-export-symbols' is ignored for archives"
-
-      # Now set the variables for building old libraries.
-      build_libtool_libs=no
-      oldlibs="$output"
-      objs="$objs$old_deplibs"
-      ;;
-
-    lib)
-      # Make sure we only generate libraries of the form `libNAME.la'.
-      case $outputname in
-      lib*)
-       func_stripname 'lib' '.la' "$outputname"
-       name=$func_stripname_result
-       eval shared_ext=\"$shrext_cmds\"
-       eval libname=\"$libname_spec\"
-       ;;
-      *)
-       test "$module" = no && \
-         func_fatal_help "libtool library \`$output' must begin with \`lib'"
-
-       if test "$need_lib_prefix" != no; then
-         # Add the "lib" prefix for modules if required
-         func_stripname '' '.la' "$outputname"
-         name=$func_stripname_result
-         eval shared_ext=\"$shrext_cmds\"
-         eval libname=\"$libname_spec\"
-       else
-         func_stripname '' '.la' "$outputname"
-         libname=$func_stripname_result
-       fi
-       ;;
-      esac
-
-      if test -n "$objs"; then
-       if test "$deplibs_check_method" != pass_all; then
-         func_fatal_error "cannot build libtool library \`$output' from non-libtool objects on this host:$objs"
-       else
-         $ECHO
-         $ECHO "*** Warning: Linking the shared library $output against the non-libtool"
-         $ECHO "*** objects $objs is not portable!"
-         libobjs="$libobjs $objs"
-       fi
-      fi
-
-      test "$dlself" != no && \
-       func_warning "\`-dlopen self' is ignored for libtool libraries"
-
-      set dummy $rpath
-      shift
-      test "$#" -gt 1 && \
-       func_warning "ignoring multiple \`-rpath's for a libtool library"
-
-      install_libdir="$1"
-
-      oldlibs=
-      if test -z "$rpath"; then
-       if test "$build_libtool_libs" = yes; then
-         # Building a libtool convenience library.
-         # Some compilers have problems with a `.al' extension so
-         # convenience libraries should have the same extension an
-         # archive normally would.
-         oldlibs="$output_objdir/$libname.$libext $oldlibs"
-         build_libtool_libs=convenience
-         build_old_libs=yes
-       fi
-
-       test -n "$vinfo" && \
-         func_warning "\`-version-info/-version-number' is ignored for convenience libraries"
-
-       test -n "$release" && \
-         func_warning "\`-release' is ignored for convenience libraries"
-      else
-
-       # Parse the version information argument.
-       save_ifs="$IFS"; IFS=':'
-       set dummy $vinfo 0 0 0
-       shift
-       IFS="$save_ifs"
-
-       test -n "$7" && \
-         func_fatal_help "too many parameters to \`-version-info'"
-
-       # convert absolute version numbers to libtool ages
-       # this retains compatibility with .la files and attempts
-       # to make the code below a bit more comprehensible
-
-       case $vinfo_number in
-       yes)
-         number_major="$1"
-         number_minor="$2"
-         number_revision="$3"
-         #
-         # There are really only two kinds -- those that
-         # use the current revision as the major version
-         # and those that subtract age and use age as
-         # a minor version.  But, then there is irix
-         # which has an extra 1 added just for fun
-         #
-         case $version_type in
-         darwin|linux|osf|windows|none)
-           func_arith $number_major + $number_minor
-           current=$func_arith_result
-           age="$number_minor"
-           revision="$number_revision"
-           ;;
-         freebsd-aout|freebsd-elf|sunos)
-           current="$number_major"
-           revision="$number_minor"
-           age="0"
-           ;;
-         irix|nonstopux)
-           func_arith $number_major + $number_minor
-           current=$func_arith_result
-           age="$number_minor"
-           revision="$number_minor"
-           lt_irix_increment=no
-           ;;
-         *)
-           func_fatal_configuration "$modename: unknown library version type \`$version_type'"
-           ;;
-         esac
-         ;;
-       no)
-         current="$1"
-         revision="$2"
-         age="$3"
-         ;;
-       esac
-
-       # Check that each of the things are valid numbers.
-       case $current in
-       0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;;
-       *)
-         func_error "CURRENT \`$current' must be a nonnegative integer"
-         func_fatal_error "\`$vinfo' is not valid version information"
-         ;;
-       esac
-
-       case $revision in
-       0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;;
-       *)
-         func_error "REVISION \`$revision' must be a nonnegative integer"
-         func_fatal_error "\`$vinfo' is not valid version information"
-         ;;
-       esac
-
-       case $age in
-       0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;;
-       *)
-         func_error "AGE \`$age' must be a nonnegative integer"
-         func_fatal_error "\`$vinfo' is not valid version information"
-         ;;
-       esac
-
-       if test "$age" -gt "$current"; then
-         func_error "AGE \`$age' is greater than the current interface number \`$current'"
-         func_fatal_error "\`$vinfo' is not valid version information"
-       fi
-
-       # Calculate the version variables.
-       major=
-       versuffix=
-       verstring=
-       case $version_type in
-       none) ;;
-
-       darwin)
-         # Like Linux, but with the current version available in
-         # verstring for coding it into the library header
-         func_arith $current - $age
-         major=.$func_arith_result
-         versuffix="$major.$age.$revision"
-         # Darwin ld doesn't like 0 for these options...
-         func_arith $current + 1
-         minor_current=$func_arith_result
-         xlcverstring="${wl}-compatibility_version ${wl}$minor_current ${wl}-current_version ${wl}$minor_current.$revision"
-         verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
-         ;;
-
-       freebsd-aout)
-         major=".$current"
-         versuffix=".$current.$revision";
-         ;;
-
-       freebsd-elf)
-         major=".$current"
-         versuffix=".$current"
-         ;;
-
-       irix | nonstopux)
-         if test "X$lt_irix_increment" = "Xno"; then
-           func_arith $current - $age
-         else
-           func_arith $current - $age + 1
-         fi
-         major=$func_arith_result
-
-         case $version_type in
-           nonstopux) verstring_prefix=nonstopux ;;
-           *)         verstring_prefix=sgi ;;
-         esac
-         verstring="$verstring_prefix$major.$revision"
-
-         # Add in all the interfaces that we are compatible with.
-         loop=$revision
-         while test "$loop" -ne 0; do
-           func_arith $revision - $loop
-           iface=$func_arith_result
-           func_arith $loop - 1
-           loop=$func_arith_result
-           verstring="$verstring_prefix$major.$iface:$verstring"
-         done
-
-         # Before this point, $major must not contain `.'.
-         major=.$major
-         versuffix="$major.$revision"
-         ;;
-
-       linux)
-         func_arith $current - $age
-         major=.$func_arith_result
-         versuffix="$major.$age.$revision"
-         ;;
-
-       osf)
-         func_arith $current - $age
-         major=.$func_arith_result
-         versuffix=".$current.$age.$revision"
-         verstring="$current.$age.$revision"
-
-         # Add in all the interfaces that we are compatible with.
-         loop=$age
-         while test "$loop" -ne 0; do
-           func_arith $current - $loop
-           iface=$func_arith_result
-           func_arith $loop - 1
-           loop=$func_arith_result
-           verstring="$verstring:${iface}.0"
-         done
-
-         # Make executables depend on our current version.
-         verstring="$verstring:${current}.0"
-         ;;
-
-       qnx)
-         major=".$current"
-         versuffix=".$current"
-         ;;
-
-       sunos)
-         major=".$current"
-         versuffix=".$current.$revision"
-         ;;
-
-       windows)
-         # Use '-' rather than '.', since we only want one
-         # extension on DOS 8.3 filesystems.
-         func_arith $current - $age
-         major=$func_arith_result
-         versuffix="-$major"
-         ;;
-
-       *)
-         func_fatal_configuration "unknown library version type \`$version_type'"
-         ;;
-       esac
-
-       # Clear the version info if we defaulted, and they specified a release.
-       if test -z "$vinfo" && test -n "$release"; then
-         major=
-         case $version_type in
-         darwin)
-           # we can't check for "0.0" in archive_cmds due to quoting
-           # problems, so we reset it completely
-           verstring=
-           ;;
-         *)
-           verstring="0.0"
-           ;;
-         esac
-         if test "$need_version" = no; then
-           versuffix=
-         else
-           versuffix=".0.0"
-         fi
-       fi
-
-       # Remove version info from name if versioning should be avoided
-       if test "$avoid_version" = yes && test "$need_version" = no; then
-         major=
-         versuffix=
-         verstring=""
-       fi
-
-       # Check to see if the archive will have undefined symbols.
-       if test "$allow_undefined" = yes; then
-         if test "$allow_undefined_flag" = unsupported; then
-           func_warning "undefined symbols not allowed in $host shared libraries"
-           build_libtool_libs=no
-           build_old_libs=yes
-         fi
-       else
-         # Don't allow undefined symbols.
-         allow_undefined_flag="$no_undefined_flag"
-       fi
-
-      fi
-
-      func_generate_dlsyms "$libname" "$libname" "yes"
-      libobjs="$libobjs $symfileobj"
-      test "X$libobjs" = "X " && libobjs=
-
-      if test "$mode" != relink; then
-       # Remove our outputs, but don't remove object files since they
-       # may have been created when compiling PIC objects.
-       removelist=
-       tempremovelist=`$ECHO "$output_objdir/*"`
-       for p in $tempremovelist; do
-         case $p in
-           *.$objext | *.gcno)
-              ;;
-           $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/${libname}${release}.*)
-              if test "X$precious_files_regex" != "X"; then
-                if $ECHO "$p" | $EGREP -e "$precious_files_regex" >/dev/null 2>&1
-                then
-                  continue
-                fi
-              fi
-              removelist="$removelist $p"
-              ;;
-           *) ;;
-         esac
-       done
-       test -n "$removelist" && \
-         func_show_eval "${RM}r \$removelist"
-      fi
-
-      # Now set the variables for building old libraries.
-      if test "$build_old_libs" = yes && test "$build_libtool_libs" != convenience ; then
-       oldlibs="$oldlibs $output_objdir/$libname.$libext"
-
-       # Transform .lo files to .o files.
-       oldobjs="$objs "`$ECHO "X$libobjs" | $SP2NL | $Xsed -e '/\.'${libext}'$/d' -e "$lo2o" | $NL2SP`
-      fi
-
-      # Eliminate all temporary directories.
-      #for path in $notinst_path; do
-      #        lib_search_path=`$ECHO "X$lib_search_path " | $Xsed -e "s% $path % %g"`
-      #        deplibs=`$ECHO "X$deplibs " | $Xsed -e "s% -L$path % %g"`
-      #        dependency_libs=`$ECHO "X$dependency_libs " | $Xsed -e "s% -L$path % %g"`
-      #done
-
-      if test -n "$xrpath"; then
-       # If the user specified any rpath flags, then add them.
-       temp_xrpath=
-       for libdir in $xrpath; do
-         temp_xrpath="$temp_xrpath -R$libdir"
-         case "$finalize_rpath " in
-         *" $libdir "*) ;;
-         *) finalize_rpath="$finalize_rpath $libdir" ;;
-         esac
-       done
-       if test "$hardcode_into_libs" != yes || test "$build_old_libs" = yes; then
-         dependency_libs="$temp_xrpath $dependency_libs"
-       fi
-      fi
-
-      # Make sure dlfiles contains only unique files that won't be dlpreopened
-      old_dlfiles="$dlfiles"
-      dlfiles=
-      for lib in $old_dlfiles; do
-       case " $dlprefiles $dlfiles " in
-       *" $lib "*) ;;
-       *) dlfiles="$dlfiles $lib" ;;
-       esac
-      done
-
-      # Make sure dlprefiles contains only unique files
-      old_dlprefiles="$dlprefiles"
-      dlprefiles=
-      for lib in $old_dlprefiles; do
-       case "$dlprefiles " in
-       *" $lib "*) ;;
-       *) dlprefiles="$dlprefiles $lib" ;;
-       esac
-      done
-
-      if test "$build_libtool_libs" = yes; then
-       if test -n "$rpath"; then
-         case $host in
-         *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc*)
-           # these systems don't actually have a c library (as such)!
-           ;;
-         *-*-rhapsody* | *-*-darwin1.[012])
-           # Rhapsody C library is in the System framework
-           deplibs="$deplibs System.ltframework"
-           ;;
-         *-*-netbsd*)
-           # Don't link with libc until the a.out ld.so is fixed.
-           ;;
-         *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*)
-           # Do not include libc due to us having libc/libc_r.
-           ;;
-         *-*-sco3.2v5* | *-*-sco5v6*)
-           # Causes problems with __ctype
-           ;;
-         *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
-           # Compiler inserts libc in the correct place for threads to work
-           ;;
-         *)
-           # Add libc to deplibs on all other systems if necessary.
-           if test "$build_libtool_need_lc" = "yes"; then
-             deplibs="$deplibs -lc"
-           fi
-           ;;
-         esac
-       fi
-
-       # Transform deplibs into only deplibs that can be linked in shared.
-       name_save=$name
-       libname_save=$libname
-       release_save=$release
-       versuffix_save=$versuffix
-       major_save=$major
-       # I'm not sure if I'm treating the release correctly.  I think
-       # release should show up in the -l (ie -lgmp5) so we don't want to
-       # add it in twice.  Is that correct?
-       release=""
-       versuffix=""
-       major=""
-       newdeplibs=
-       droppeddeps=no
-       case $deplibs_check_method in
-       pass_all)
-         # Don't check for shared/static.  Everything works.
-         # This might be a little naive.  We might want to check
-         # whether the library exists or not.  But this is on
-         # osf3 & osf4 and I'm not really sure... Just
-         # implementing what was already the behavior.
-         newdeplibs=$deplibs
-         ;;
-       test_compile)
-         # This code stresses the "libraries are programs" paradigm to its
-         # limits. Maybe even breaks it.  We compile a program, linking it
-         # against the deplibs as a proxy for the library.  Then we can check
-         # whether they linked in statically or dynamically with ldd.
-         $opt_dry_run || $RM conftest.c
-         cat > conftest.c <<EOF
-         int main() { return 0; }
-EOF
-         $opt_dry_run || $RM conftest
-         if $LTCC $LTCFLAGS -o conftest conftest.c $deplibs; then
-           ldd_output=`ldd conftest`
-           for i in $deplibs; do
-             case $i in
-             -l*)
-               func_stripname -l '' "$i"
-               name=$func_stripname_result
-               if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then
-                 case " $predeps $postdeps " in
-                 *" $i "*)
-                   newdeplibs="$newdeplibs $i"
-                   i=""
-                   ;;
-                 esac
-               fi
-               if test -n "$i" ; then
-                 libname=`eval "\\$ECHO \"$libname_spec\""`
-                 deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
-                 set dummy $deplib_matches; shift
-                 deplib_match=$1
-                 if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0 ; then
-                   newdeplibs="$newdeplibs $i"
-                 else
-                   droppeddeps=yes
-                   $ECHO
-                   $ECHO "*** Warning: dynamic linker does not accept needed library $i."
-                   $ECHO "*** I have the capability to make that library automatically link in when"
-                   $ECHO "*** you link to this library.  But I can only do this if you have a"
-                   $ECHO "*** shared version of the library, which I believe you do not have"
-                   $ECHO "*** because a test_compile did reveal that the linker did not use it for"
-                   $ECHO "*** its dynamic dependency list that programs get resolved with at runtime."
-                 fi
-               fi
-               ;;
-             *)
-               newdeplibs="$newdeplibs $i"
-               ;;
-             esac
-           done
-         else
-           # Error occurred in the first compile.  Let's try to salvage
-           # the situation: Compile a separate program for each library.
-           for i in $deplibs; do
-             case $i in
-             -l*)
-               func_stripname -l '' "$i"
-               name=$func_stripname_result
-               $opt_dry_run || $RM conftest
-               if $LTCC $LTCFLAGS -o conftest conftest.c $i; then
-                 ldd_output=`ldd conftest`
-                 if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then
-                   case " $predeps $postdeps " in
-                   *" $i "*)
-                     newdeplibs="$newdeplibs $i"
-                     i=""
-                     ;;
-                   esac
-                 fi
-                 if test -n "$i" ; then
-                   libname=`eval "\\$ECHO \"$libname_spec\""`
-                   deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
-                   set dummy $deplib_matches; shift
-                   deplib_match=$1
-                   if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0 ; then
-                     newdeplibs="$newdeplibs $i"
-                   else
-                     droppeddeps=yes
-                     $ECHO
-                     $ECHO "*** Warning: dynamic linker does not accept needed library $i."
-                     $ECHO "*** I have the capability to make that library automatically link in when"
-                     $ECHO "*** you link to this library.  But I can only do this if you have a"
-                     $ECHO "*** shared version of the library, which you do not appear to have"
-                     $ECHO "*** because a test_compile did reveal that the linker did not use this one"
-                     $ECHO "*** as a dynamic dependency that programs can get resolved with at runtime."
-                   fi
-                 fi
-               else
-                 droppeddeps=yes
-                 $ECHO
-                 $ECHO "*** Warning!  Library $i is needed by this library but I was not able to"
-                 $ECHO "*** make it link in!  You will probably need to install it or some"
-                 $ECHO "*** library that it depends on before this library will be fully"
-                 $ECHO "*** functional.  Installing it before continuing would be even better."
-               fi
-               ;;
-             *)
-               newdeplibs="$newdeplibs $i"
-               ;;
-             esac
-           done
-         fi
-         ;;
-       file_magic*)
-         set dummy $deplibs_check_method; shift
-         file_magic_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
-         for a_deplib in $deplibs; do
-           case $a_deplib in
-           -l*)
-             func_stripname -l '' "$a_deplib"
-             name=$func_stripname_result
-             if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then
-               case " $predeps $postdeps " in
-               *" $a_deplib "*)
-                 newdeplibs="$newdeplibs $a_deplib"
-                 a_deplib=""
-                 ;;
-               esac
-             fi
-             if test -n "$a_deplib" ; then
-               libname=`eval "\\$ECHO \"$libname_spec\""`
-               for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
-                 potential_libs=`ls $i/$libname[.-]* 2>/dev/null`
-                 for potent_lib in $potential_libs; do
-                     # Follow soft links.
-                     if ls -lLd "$potent_lib" 2>/dev/null |
-                        $GREP " -> " >/dev/null; then
-                       continue
-                     fi
-                     # The statement above tries to avoid entering an
-                     # endless loop below, in case of cyclic links.
-                     # We might still enter an endless loop, since a link
-                     # loop can be closed while we follow links,
-                     # but so what?
-                     potlib="$potent_lib"
-                     while test -h "$potlib" 2>/dev/null; do
-                       potliblink=`ls -ld $potlib | ${SED} 's/.* -> //'`
-                       case $potliblink in
-                       [\\/]* | [A-Za-z]:[\\/]*) potlib="$potliblink";;
-                       *) potlib=`$ECHO "X$potlib" | $Xsed -e 's,[^/]*$,,'`"$potliblink";;
-                       esac
-                     done
-                     if eval $file_magic_cmd \"\$potlib\" 2>/dev/null |
-                        $SED -e 10q |
-                        $EGREP "$file_magic_regex" > /dev/null; then
-                       newdeplibs="$newdeplibs $a_deplib"
-                       a_deplib=""
-                       break 2
-                     fi
-                 done
-               done
-             fi
-             if test -n "$a_deplib" ; then
-               droppeddeps=yes
-               $ECHO
-               $ECHO "*** Warning: linker path does not have real file for library $a_deplib."
-               $ECHO "*** I have the capability to make that library automatically link in when"
-               $ECHO "*** you link to this library.  But I can only do this if you have a"
-               $ECHO "*** shared version of the library, which you do not appear to have"
-               $ECHO "*** because I did check the linker path looking for a file starting"
-               if test -z "$potlib" ; then
-                 $ECHO "*** with $libname but no candidates were found. (...for file magic test)"
-               else
-                 $ECHO "*** with $libname and none of the candidates passed a file format test"
-                 $ECHO "*** using a file magic. Last file checked: $potlib"
-               fi
-             fi
-             ;;
-           *)
-             # Add a -L argument.
-             newdeplibs="$newdeplibs $a_deplib"
-             ;;
-           esac
-         done # Gone through all deplibs.
-         ;;
-       match_pattern*)
-         set dummy $deplibs_check_method; shift
-         match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
-         for a_deplib in $deplibs; do
-           case $a_deplib in
-           -l*)
-             func_stripname -l '' "$a_deplib"
-             name=$func_stripname_result
-             if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then
-               case " $predeps $postdeps " in
-               *" $a_deplib "*)
-                 newdeplibs="$newdeplibs $a_deplib"
-                 a_deplib=""
-                 ;;
-               esac
-             fi
-             if test -n "$a_deplib" ; then
-               libname=`eval "\\$ECHO \"$libname_spec\""`
-               for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
-                 potential_libs=`ls $i/$libname[.-]* 2>/dev/null`
-                 for potent_lib in $potential_libs; do
-                   potlib="$potent_lib" # see symlink-check above in file_magic test
-                   if eval "\$ECHO \"X$potent_lib\"" 2>/dev/null | $Xsed -e 10q | \
-                      $EGREP "$match_pattern_regex" > /dev/null; then
-                     newdeplibs="$newdeplibs $a_deplib"
-                     a_deplib=""
-                     break 2
-                   fi
-                 done
-               done
-             fi
-             if test -n "$a_deplib" ; then
-               droppeddeps=yes
-               $ECHO
-               $ECHO "*** Warning: linker path does not have real file for library $a_deplib."
-               $ECHO "*** I have the capability to make that library automatically link in when"
-               $ECHO "*** you link to this library.  But I can only do this if you have a"
-               $ECHO "*** shared version of the library, which you do not appear to have"
-               $ECHO "*** because I did check the linker path looking for a file starting"
-               if test -z "$potlib" ; then
-                 $ECHO "*** with $libname but no candidates were found. (...for regex pattern test)"
-               else
-                 $ECHO "*** with $libname and none of the candidates passed a file format test"
-                 $ECHO "*** using a regex pattern. Last file checked: $potlib"
-               fi
-             fi
-             ;;
-           *)
-             # Add a -L argument.
-             newdeplibs="$newdeplibs $a_deplib"
-             ;;
-           esac
-         done # Gone through all deplibs.
-         ;;
-       none | unknown | *)
-         newdeplibs=""
-         tmp_deplibs=`$ECHO "X $deplibs" | $Xsed \
-             -e 's/ -lc$//' -e 's/ -[LR][^ ]*//g'`
-         if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then
-           for i in $predeps $postdeps ; do
-             # can't use Xsed below, because $i might contain '/'
-             tmp_deplibs=`$ECHO "X $tmp_deplibs" | $Xsed -e "s,$i,,"`
-           done
-         fi
-         if $ECHO "X $tmp_deplibs" | $Xsed -e 's/[      ]//g' |
-            $GREP . >/dev/null; then
-           $ECHO
-           if test "X$deplibs_check_method" = "Xnone"; then
-             $ECHO "*** Warning: inter-library dependencies are not supported in this platform."
-           else
-             $ECHO "*** Warning: inter-library dependencies are not known to be supported."
-           fi
-           $ECHO "*** All declared inter-library dependencies are being dropped."
-           droppeddeps=yes
-         fi
-         ;;
-       esac
-       versuffix=$versuffix_save
-       major=$major_save
-       release=$release_save
-       libname=$libname_save
-       name=$name_save
-
-       case $host in
-       *-*-rhapsody* | *-*-darwin1.[012])
-         # On Rhapsody replace the C library with the System framework
-         newdeplibs=`$ECHO "X $newdeplibs" | $Xsed -e 's/ -lc / System.ltframework /'`
-         ;;
-       esac
-
-       if test "$droppeddeps" = yes; then
-         if test "$module" = yes; then
-           $ECHO
-           $ECHO "*** Warning: libtool could not satisfy all declared inter-library"
-           $ECHO "*** dependencies of module $libname.  Therefore, libtool will create"
-           $ECHO "*** a static module, that should work as long as the dlopening"
-           $ECHO "*** application is linked with the -dlopen flag."
-           if test -z "$global_symbol_pipe"; then
-             $ECHO
-             $ECHO "*** However, this would only work if libtool was able to extract symbol"
-             $ECHO "*** lists from a program, using \`nm' or equivalent, but libtool could"
-             $ECHO "*** not find such a program.  So, this module is probably useless."
-             $ECHO "*** \`nm' from GNU binutils and a full rebuild may help."
-           fi
-           if test "$build_old_libs" = no; then
-             oldlibs="$output_objdir/$libname.$libext"
-             build_libtool_libs=module
-             build_old_libs=yes
-           else
-             build_libtool_libs=no
-           fi
-         else
-           $ECHO "*** The inter-library dependencies that have been dropped here will be"
-           $ECHO "*** automatically added whenever a program is linked with this library"
-           $ECHO "*** or is declared to -dlopen it."
-
-           if test "$allow_undefined" = no; then
-             $ECHO
-             $ECHO "*** Since this library must not contain undefined symbols,"
-             $ECHO "*** because either the platform does not support them or"
-             $ECHO "*** it was explicitly requested with -no-undefined,"
-             $ECHO "*** libtool will only create a static version of it."
-             if test "$build_old_libs" = no; then
-               oldlibs="$output_objdir/$libname.$libext"
-               build_libtool_libs=module
-               build_old_libs=yes
-             else
-               build_libtool_libs=no
-             fi
-           fi
-         fi
-       fi
-       # Done checking deplibs!
-       deplibs=$newdeplibs
-      fi
-      # Time to change all our "foo.ltframework" stuff back to "-framework foo"
-      case $host in
-       *-*-darwin*)
-         newdeplibs=`$ECHO "X $newdeplibs" | $Xsed -e 's% \([^ $]*\).ltframework% -framework \1%g'`
-         new_inherited_linker_flags=`$ECHO "X $new_inherited_linker_flags" | $Xsed -e 's% \([^ $]*\).ltframework% -framework \1%g'`
-         deplibs=`$ECHO "X $deplibs" | $Xsed -e 's% \([^ $]*\).ltframework% -framework \1%g'`
-         ;;
-      esac
-
-      # move library search paths that coincide with paths to not yet
-      # installed libraries to the beginning of the library search list
-      new_libs=
-      for path in $notinst_path; do
-       case " $new_libs " in
-       *" -L$path/$objdir "*) ;;
-       *)
-         case " $deplibs " in
-         *" -L$path/$objdir "*)
-           new_libs="$new_libs -L$path/$objdir" ;;
-         esac
-         ;;
-       esac
-      done
-      for deplib in $deplibs; do
-       case $deplib in
-       -L*)
-         case " $new_libs " in
-         *" $deplib "*) ;;
-         *) new_libs="$new_libs $deplib" ;;
-         esac
-         ;;
-       *) new_libs="$new_libs $deplib" ;;
-       esac
-      done
-      deplibs="$new_libs"
-
-      # All the library-specific variables (install_libdir is set above).
-      library_names=
-      old_library=
-      dlname=
-
-      # Test again, we may have decided not to build it any more
-      if test "$build_libtool_libs" = yes; then
-       if test "$hardcode_into_libs" = yes; then
-         # Hardcode the library paths
-         hardcode_libdirs=
-         dep_rpath=
-         rpath="$finalize_rpath"
-         test "$mode" != relink && rpath="$compile_rpath$rpath"
-         for libdir in $rpath; do
-           if test -n "$hardcode_libdir_flag_spec"; then
-             if test -n "$hardcode_libdir_separator"; then
-               if test -z "$hardcode_libdirs"; then
-                 hardcode_libdirs="$libdir"
-               else
-                 # Just accumulate the unique libdirs.
-                 case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
-                 *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
-                   ;;
-                 *)
-                   hardcode_libdirs="$hardcode_libdirs$hardcode_libdir_separator$libdir"
-                   ;;
-                 esac
-               fi
-             else
-               eval flag=\"$hardcode_libdir_flag_spec\"
-               dep_rpath="$dep_rpath $flag"
-             fi
-           elif test -n "$runpath_var"; then
-             case "$perm_rpath " in
-             *" $libdir "*) ;;
-             *) perm_rpath="$perm_rpath $libdir" ;;
-             esac
-           fi
-         done
-         # Substitute the hardcoded libdirs into the rpath.
-         if test -n "$hardcode_libdir_separator" &&
-            test -n "$hardcode_libdirs"; then
-           libdir="$hardcode_libdirs"
-           if test -n "$hardcode_libdir_flag_spec_ld"; then
-             eval dep_rpath=\"$hardcode_libdir_flag_spec_ld\"
-           else
-             eval dep_rpath=\"$hardcode_libdir_flag_spec\"
-           fi
-         fi
-         if test -n "$runpath_var" && test -n "$perm_rpath"; then
-           # We should set the runpath_var.
-           rpath=
-           for dir in $perm_rpath; do
-             rpath="$rpath$dir:"
-           done
-           eval "$runpath_var='$rpath\$$runpath_var'; export $runpath_var"
-         fi
-         test -n "$dep_rpath" && deplibs="$dep_rpath $deplibs"
-       fi
-
-       shlibpath="$finalize_shlibpath"
-       test "$mode" != relink && shlibpath="$compile_shlibpath$shlibpath"
-       if test -n "$shlibpath"; then
-         eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export $shlibpath_var"
-       fi
-
-       # Get the real and link names of the library.
-       eval shared_ext=\"$shrext_cmds\"
-       eval library_names=\"$library_names_spec\"
-       set dummy $library_names
-       shift
-       realname="$1"
-       shift
-
-       if test -n "$soname_spec"; then
-         eval soname=\"$soname_spec\"
-       else
-         soname="$realname"
-       fi
-       if test -z "$dlname"; then
-         dlname=$soname
-       fi
-
-       lib="$output_objdir/$realname"
-       linknames=
-       for link
-       do
-         linknames="$linknames $link"
-       done
-
-       # Use standard objects if they are pic
-       test -z "$pic_flag" && libobjs=`$ECHO "X$libobjs" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP`
-       test "X$libobjs" = "X " && libobjs=
-
-       delfiles=
-       if test -n "$export_symbols" && test -n "$include_expsyms"; then
-         $opt_dry_run || cp "$export_symbols" "$output_objdir/$libname.uexp"
-         export_symbols="$output_objdir/$libname.uexp"
-         delfiles="$delfiles $export_symbols"
-       fi
-
-       orig_export_symbols=
-       case $host_os in
-       cygwin* | mingw* | cegcc*)
-         if test -n "$export_symbols" && test -z "$export_symbols_regex"; then
-           # exporting using user supplied symfile
-           if test "x`$SED 1q $export_symbols`" != xEXPORTS; then
-             # and it's NOT already a .def file. Must figure out
-             # which of the given symbols are data symbols and tag
-             # them as such. So, trigger use of export_symbols_cmds.
-             # export_symbols gets reassigned inside the "prepare
-             # the list of exported symbols" if statement, so the
-             # include_expsyms logic still works.
-             orig_export_symbols="$export_symbols"
-             export_symbols=
-             always_export_symbols=yes
-           fi
-         fi
-         ;;
-       esac
-
-       # Prepare the list of exported symbols
-       if test -z "$export_symbols"; then
-         if test "$always_export_symbols" = yes || test -n "$export_symbols_regex"; then
-           func_verbose "generating symbol list for \`$libname.la'"
-           export_symbols="$output_objdir/$libname.exp"
-           $opt_dry_run || $RM $export_symbols
-           cmds=$export_symbols_cmds
-           save_ifs="$IFS"; IFS='~'
-           for cmd in $cmds; do
-             IFS="$save_ifs"
-             eval cmd=\"$cmd\"
-             func_len " $cmd"
-             len=$func_len_result
-             if test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
-               func_show_eval "$cmd" 'exit $?'
-               skipped_export=false
-             else
-               # The command line is too long to execute in one step.
-               func_verbose "using reloadable object file for export list..."
-               skipped_export=:
-               # Break out early, otherwise skipped_export may be
-               # set to false by a later but shorter cmd.
-               break
-             fi
-           done
-           IFS="$save_ifs"
-           if test -n "$export_symbols_regex" && test "X$skipped_export" != "X:"; then
-             func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
-             func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
-           fi
-         fi
-       fi
-
-       if test -n "$export_symbols" && test -n "$include_expsyms"; then
-         tmp_export_symbols="$export_symbols"
-         test -n "$orig_export_symbols" && tmp_export_symbols="$orig_export_symbols"
-         $opt_dry_run || eval '$ECHO "X$include_expsyms" | $Xsed | $SP2NL >> "$tmp_export_symbols"'
-       fi
-
-       if test "X$skipped_export" != "X:" && test -n "$orig_export_symbols"; then
-         # The given exports_symbols file has to be filtered, so filter it.
-         func_verbose "filter symbol list for \`$libname.la' to tag DATA exports"
-         # FIXME: $output_objdir/$libname.filter potentially contains lots of
-         # 's' commands which not all seds can handle. GNU sed should be fine
-         # though. Also, the filter scales superlinearly with the number of
-         # global variables. join(1) would be nice here, but unfortunately
-         # isn't a blessed tool.
-         $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
-         delfiles="$delfiles $export_symbols $output_objdir/$libname.filter"
-         export_symbols=$output_objdir/$libname.def
-         $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
-       fi
-
-       tmp_deplibs=
-       for test_deplib in $deplibs; do
-         case " $convenience " in
-         *" $test_deplib "*) ;;
-         *)
-           tmp_deplibs="$tmp_deplibs $test_deplib"
-           ;;
-         esac
-       done
-       deplibs="$tmp_deplibs"
-
-       if test -n "$convenience"; then
-         if test -n "$whole_archive_flag_spec" &&
-           test "$compiler_needs_object" = yes &&
-           test -z "$libobjs"; then
-           # extract the archives, so we have objects to list.
-           # TODO: could optimize this to just extract one archive.
-           whole_archive_flag_spec=
-         fi
-         if test -n "$whole_archive_flag_spec"; then
-           save_libobjs=$libobjs
-           eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
-           test "X$libobjs" = "X " && libobjs=
-         else
-           gentop="$output_objdir/${outputname}x"
-           generated="$generated $gentop"
-
-           func_extract_archives $gentop $convenience
-           libobjs="$libobjs $func_extract_archives_result"
-           test "X$libobjs" = "X " && libobjs=
-         fi
-       fi
-
-       if test "$thread_safe" = yes && test -n "$thread_safe_flag_spec"; then
-         eval flag=\"$thread_safe_flag_spec\"
-         linker_flags="$linker_flags $flag"
-       fi
-
-       # Make a backup of the uninstalled library when relinking
-       if test "$mode" = relink; then
-         $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}U && $MV $realname ${realname}U)' || exit $?
-       fi
-
-       # Do each of the archive commands.
-       if test "$module" = yes && test -n "$module_cmds" ; then
-         if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
-           eval test_cmds=\"$module_expsym_cmds\"
-           cmds=$module_expsym_cmds
-         else
-           eval test_cmds=\"$module_cmds\"
-           cmds=$module_cmds
-         fi
-       else
-         if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
-           eval test_cmds=\"$archive_expsym_cmds\"
-           cmds=$archive_expsym_cmds
-         else
-           eval test_cmds=\"$archive_cmds\"
-           cmds=$archive_cmds
-         fi
-       fi
-
-       if test "X$skipped_export" != "X:" &&
-          func_len " $test_cmds" &&
-          len=$func_len_result &&
-          test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
-         :
-       else
-         # The command line is too long to link in one step, link piecewise
-         # or, if using GNU ld and skipped_export is not :, use a linker
-         # script.
-
-         # Save the value of $output and $libobjs because we want to
-         # use them later.  If we have whole_archive_flag_spec, we
-         # want to use save_libobjs as it was before
-         # whole_archive_flag_spec was expanded, because we can't
-         # assume the linker understands whole_archive_flag_spec.
-         # This may have to be revisited, in case too many
-         # convenience libraries get linked in and end up exceeding
-         # the spec.
-         if test -z "$convenience" || test -z "$whole_archive_flag_spec"; then
-           save_libobjs=$libobjs
-         fi
-         save_output=$output
-         output_la=`$ECHO "X$output" | $Xsed -e "$basename"`
-
-         # Clear the reloadable object creation command queue and
-         # initialize k to one.
-         test_cmds=
-         concat_cmds=
-         objlist=
-         last_robj=
-         k=1
-
-         if test -n "$save_libobjs" && test "X$skipped_export" != "X:" && test "$with_gnu_ld" = yes; then
-           output=${output_objdir}/${output_la}.lnkscript
-           func_verbose "creating GNU ld script: $output"
-           $ECHO 'INPUT (' > $output
-           for obj in $save_libobjs
-           do
-             $ECHO "$obj" >> $output
-           done
-           $ECHO ')' >> $output
-           delfiles="$delfiles $output"
-         elif test -n "$save_libobjs" && test "X$skipped_export" != "X:" && test "X$file_list_spec" != X; then
-           output=${output_objdir}/${output_la}.lnk
-           func_verbose "creating linker input file list: $output"
-           : > $output
-           set x $save_libobjs
-           shift
-           firstobj=
-           if test "$compiler_needs_object" = yes; then
-             firstobj="$1 "
-             shift
-           fi
-           for obj
-           do
-             $ECHO "$obj" >> $output
-           done
-           delfiles="$delfiles $output"
-           output=$firstobj\"$file_list_spec$output\"
-         else
-           if test -n "$save_libobjs"; then
-             func_verbose "creating reloadable object files..."
-             output=$output_objdir/$output_la-${k}.$objext
-             eval test_cmds=\"$reload_cmds\"
-             func_len " $test_cmds"
-             len0=$func_len_result
-             len=$len0
-
-             # Loop over the list of objects to be linked.
-             for obj in $save_libobjs
-             do
-               func_len " $obj"
-               func_arith $len + $func_len_result
-               len=$func_arith_result
-               if test "X$objlist" = X ||
-                  test "$len" -lt "$max_cmd_len"; then
-                 func_append objlist " $obj"
-               else
-                 # The command $test_cmds is almost too long, add a
-                 # command to the queue.
-                 if test "$k" -eq 1 ; then
-                   # The first file doesn't have a previous command to add.
-                   eval concat_cmds=\"$reload_cmds $objlist $last_robj\"
-                 else
-                   # All subsequent reloadable object files will link in
-                   # the last one created.
-                   eval concat_cmds=\"\$concat_cmds~$reload_cmds $objlist $last_robj~\$RM $last_robj\"
-                 fi
-                 last_robj=$output_objdir/$output_la-${k}.$objext
-                 func_arith $k + 1
-                 k=$func_arith_result
-                 output=$output_objdir/$output_la-${k}.$objext
-                 objlist=$obj
-                 func_len " $last_robj"
-                 func_arith $len0 + $func_len_result
-                 len=$func_arith_result
-               fi
-             done
-             # Handle the remaining objects by creating one last
-             # reloadable object file.  All subsequent reloadable object
-             # files will link in the last one created.
-             test -z "$concat_cmds" || concat_cmds=$concat_cmds~
-             eval concat_cmds=\"\${concat_cmds}$reload_cmds $objlist $last_robj\"
-             if test -n "$last_robj"; then
-               eval concat_cmds=\"\${concat_cmds}~\$RM $last_robj\"
-             fi
-             delfiles="$delfiles $output"
-
-           else
-             output=
-           fi
-
-           if ${skipped_export-false}; then
-             func_verbose "generating symbol list for \`$libname.la'"
-             export_symbols="$output_objdir/$libname.exp"
-             $opt_dry_run || $RM $export_symbols
-             libobjs=$output
-             # Append the command to create the export file.
-             test -z "$concat_cmds" || concat_cmds=$concat_cmds~
-             eval concat_cmds=\"\$concat_cmds$export_symbols_cmds\"
-             if test -n "$last_robj"; then
-               eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
-             fi
-           fi
-
-           test -n "$save_libobjs" &&
-             func_verbose "creating a temporary reloadable object file: $output"
-
-           # Loop through the commands generated above and execute them.
-           save_ifs="$IFS"; IFS='~'
-           for cmd in $concat_cmds; do
-             IFS="$save_ifs"
-             $opt_silent || {
-                 func_quote_for_expand "$cmd"
-                 eval "func_echo $func_quote_for_expand_result"
-             }
-             $opt_dry_run || eval "$cmd" || {
-               lt_exit=$?
-
-               # Restore the uninstalled library and exit
-               if test "$mode" = relink; then
-                 ( cd "$output_objdir" && \
-                   $RM "${realname}T" && \
-                   $MV "${realname}U" "$realname" )
-               fi
-
-               exit $lt_exit
-             }
-           done
-           IFS="$save_ifs"
-
-           if test -n "$export_symbols_regex" && ${skipped_export-false}; then
-             func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
-             func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
-           fi
-         fi
-
-          if ${skipped_export-false}; then
-           if test -n "$export_symbols" && test -n "$include_expsyms"; then
-             tmp_export_symbols="$export_symbols"
-             test -n "$orig_export_symbols" && tmp_export_symbols="$orig_export_symbols"
-             $opt_dry_run || eval '$ECHO "X$include_expsyms" | $Xsed | $SP2NL >> "$tmp_export_symbols"'
-           fi
-
-           if test -n "$orig_export_symbols"; then
-             # The given exports_symbols file has to be filtered, so filter it.
-             func_verbose "filter symbol list for \`$libname.la' to tag DATA exports"
-             # FIXME: $output_objdir/$libname.filter potentially contains lots of
-             # 's' commands which not all seds can handle. GNU sed should be fine
-             # though. Also, the filter scales superlinearly with the number of
-             # global variables. join(1) would be nice here, but unfortunately
-             # isn't a blessed tool.
-             $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
-             delfiles="$delfiles $export_symbols $output_objdir/$libname.filter"
-             export_symbols=$output_objdir/$libname.def
-             $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
-           fi
-         fi
-
-         libobjs=$output
-         # Restore the value of output.
-         output=$save_output
-
-         if test -n "$convenience" && test -n "$whole_archive_flag_spec"; then
-           eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
-           test "X$libobjs" = "X " && libobjs=
-         fi
-         # Expand the library linking commands again to reset the
-         # value of $libobjs for piecewise linking.
-
-         # Do each of the archive commands.
-         if test "$module" = yes && test -n "$module_cmds" ; then
-           if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
-             cmds=$module_expsym_cmds
-           else
-             cmds=$module_cmds
-           fi
-         else
-           if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
-             cmds=$archive_expsym_cmds
-           else
-             cmds=$archive_cmds
-           fi
-         fi
-       fi
-
-       if test -n "$delfiles"; then
-         # Append the command to remove temporary files to $cmds.
-         eval cmds=\"\$cmds~\$RM $delfiles\"
-       fi
-
-       # Add any objects from preloaded convenience libraries
-       if test -n "$dlprefiles"; then
-         gentop="$output_objdir/${outputname}x"
-         generated="$generated $gentop"
-
-         func_extract_archives $gentop $dlprefiles
-         libobjs="$libobjs $func_extract_archives_result"
-         test "X$libobjs" = "X " && libobjs=
-       fi
-
-       save_ifs="$IFS"; IFS='~'
-       for cmd in $cmds; do
-         IFS="$save_ifs"
-         eval cmd=\"$cmd\"
-         $opt_silent || {
-           func_quote_for_expand "$cmd"
-           eval "func_echo $func_quote_for_expand_result"
-         }
-         $opt_dry_run || eval "$cmd" || {
-           lt_exit=$?
-
-           # Restore the uninstalled library and exit
-           if test "$mode" = relink; then
-             ( cd "$output_objdir" && \
-               $RM "${realname}T" && \
-               $MV "${realname}U" "$realname" )
-           fi
-
-           exit $lt_exit
-         }
-       done
-       IFS="$save_ifs"
-
-       # Restore the uninstalled library and exit
-       if test "$mode" = relink; then
-         $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}T && $MV $realname ${realname}T && $MV ${realname}U $realname)' || exit $?
-
-         if test -n "$convenience"; then
-           if test -z "$whole_archive_flag_spec"; then
-             func_show_eval '${RM}r "$gentop"'
-           fi
-         fi
-
-         exit $EXIT_SUCCESS
-       fi
-
-       # Create links to the real library.
-       for linkname in $linknames; do
-         if test "$realname" != "$linkname"; then
-           func_show_eval '(cd "$output_objdir" && $RM "$linkname" && $LN_S "$realname" "$linkname")' 'exit $?'
-         fi
-       done
-
-       # If -module or -export-dynamic was specified, set the dlname.
-       if test "$module" = yes || test "$export_dynamic" = yes; then
-         # On all known operating systems, these are identical.
-         dlname="$soname"
-       fi
-      fi
-      ;;
-
-    obj)
-      if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then
-       func_warning "\`-dlopen' is ignored for objects"
-      fi
-
-      case " $deplibs" in
-      *\ -l* | *\ -L*)
-       func_warning "\`-l' and \`-L' are ignored for objects" ;;
-      esac
-
-      test -n "$rpath" && \
-       func_warning "\`-rpath' is ignored for objects"
-
-      test -n "$xrpath" && \
-       func_warning "\`-R' is ignored for objects"
-
-      test -n "$vinfo" && \
-       func_warning "\`-version-info' is ignored for objects"
-
-      test -n "$release" && \
-       func_warning "\`-release' is ignored for objects"
-
-      case $output in
-      *.lo)
-       test -n "$objs$old_deplibs" && \
-         func_fatal_error "cannot build library object \`$output' from non-libtool objects"
-
-       libobj=$output
-       func_lo2o "$libobj"
-       obj=$func_lo2o_result
-       ;;
-      *)
-       libobj=
-       obj="$output"
-       ;;
-      esac
-
-      # Delete the old objects.
-      $opt_dry_run || $RM $obj $libobj
-
-      # Objects from convenience libraries.  This assumes
-      # single-version convenience libraries.  Whenever we create
-      # different ones for PIC/non-PIC, this we'll have to duplicate
-      # the extraction.
-      reload_conv_objs=
-      gentop=
-      # reload_cmds runs $LD directly, so let us get rid of
-      # -Wl from whole_archive_flag_spec and hope we can get by with
-      # turning comma into space..
-      wl=
-
-      if test -n "$convenience"; then
-       if test -n "$whole_archive_flag_spec"; then
-         eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\"
-         reload_conv_objs=$reload_objs\ `$ECHO "X$tmp_whole_archive_flags" | $Xsed -e 's|,| |g'`
-       else
-         gentop="$output_objdir/${obj}x"
-         generated="$generated $gentop"
-
-         func_extract_archives $gentop $convenience
-         reload_conv_objs="$reload_objs $func_extract_archives_result"
-       fi
-      fi
-
-      # Create the old-style object.
-      reload_objs="$objs$old_deplibs "`$ECHO "X$libobjs" | $SP2NL | $Xsed -e '/\.'${libext}$'/d' -e '/\.lib$/d' -e "$lo2o" | $NL2SP`" $reload_conv_objs" ### testsuite: skip nested quoting test
-
-      output="$obj"
-      func_execute_cmds "$reload_cmds" 'exit $?'
-
-      # Exit if we aren't doing a library object file.
-      if test -z "$libobj"; then
-       if test -n "$gentop"; then
-         func_show_eval '${RM}r "$gentop"'
-       fi
-
-       exit $EXIT_SUCCESS
-      fi
-
-      if test "$build_libtool_libs" != yes; then
-       if test -n "$gentop"; then
-         func_show_eval '${RM}r "$gentop"'
-       fi
-
-       # Create an invalid libtool object if no PIC, so that we don't
-       # accidentally link it into a program.
-       # $show "echo timestamp > $libobj"
-       # $opt_dry_run || eval "echo timestamp > $libobj" || exit $?
-       exit $EXIT_SUCCESS
-      fi
-
-      if test -n "$pic_flag" || test "$pic_mode" != default; then
-       # Only do commands if we really have different PIC objects.
-       reload_objs="$libobjs $reload_conv_objs"
-       output="$libobj"
-       func_execute_cmds "$reload_cmds" 'exit $?'
-      fi
-
-      if test -n "$gentop"; then
-       func_show_eval '${RM}r "$gentop"'
-      fi
-
-      exit $EXIT_SUCCESS
-      ;;
-
-    prog)
-      case $host in
-       *cygwin*) func_stripname '' '.exe' "$output"
-                 output=$func_stripname_result.exe;;
-      esac
-      test -n "$vinfo" && \
-       func_warning "\`-version-info' is ignored for programs"
-
-      test -n "$release" && \
-       func_warning "\`-release' is ignored for programs"
-
-      test "$preload" = yes \
-        && test "$dlopen_support" = unknown \
-       && test "$dlopen_self" = unknown \
-       && test "$dlopen_self_static" = unknown && \
-         func_warning "\`LT_INIT([dlopen])' not used. Assuming no dlopen support."
-
-      case $host in
-      *-*-rhapsody* | *-*-darwin1.[012])
-       # On Rhapsody replace the C library is the System framework
-       compile_deplibs=`$ECHO "X $compile_deplibs" | $Xsed -e 's/ -lc / System.ltframework /'`
-       finalize_deplibs=`$ECHO "X $finalize_deplibs" | $Xsed -e 's/ -lc / System.ltframework /'`
-       ;;
-      esac
-
-      case $host in
-      *-*-darwin*)
-       # Don't allow lazy linking, it breaks C++ global constructors
-       # But is supposedly fixed on 10.4 or later (yay!).
-       if test "$tagname" = CXX ; then
-         case ${MACOSX_DEPLOYMENT_TARGET-10.0} in
-           10.[0123])
-             compile_command="$compile_command ${wl}-bind_at_load"
-             finalize_command="$finalize_command ${wl}-bind_at_load"
-           ;;
-         esac
-       fi
-       # Time to change all our "foo.ltframework" stuff back to "-framework foo"
-       compile_deplibs=`$ECHO "X $compile_deplibs" | $Xsed -e 's% \([^ $]*\).ltframework% -framework \1%g'`
-       finalize_deplibs=`$ECHO "X $finalize_deplibs" | $Xsed -e 's% \([^ $]*\).ltframework% -framework \1%g'`
-       ;;
-      esac
-
-
-      # move library search paths that coincide with paths to not yet
-      # installed libraries to the beginning of the library search list
-      new_libs=
-      for path in $notinst_path; do
-       case " $new_libs " in
-       *" -L$path/$objdir "*) ;;
-       *)
-         case " $compile_deplibs " in
-         *" -L$path/$objdir "*)
-           new_libs="$new_libs -L$path/$objdir" ;;
-         esac
-         ;;
-       esac
-      done
-      for deplib in $compile_deplibs; do
-       case $deplib in
-       -L*)
-         case " $new_libs " in
-         *" $deplib "*) ;;
-         *) new_libs="$new_libs $deplib" ;;
-         esac
-         ;;
-       *) new_libs="$new_libs $deplib" ;;
-       esac
-      done
-      compile_deplibs="$new_libs"
-
-
-      compile_command="$compile_command $compile_deplibs"
-      finalize_command="$finalize_command $finalize_deplibs"
-
-      if test -n "$rpath$xrpath"; then
-       # If the user specified any rpath flags, then add them.
-       for libdir in $rpath $xrpath; do
-         # This is the magic to use -rpath.
-         case "$finalize_rpath " in
-         *" $libdir "*) ;;
-         *) finalize_rpath="$finalize_rpath $libdir" ;;
-         esac
-       done
-      fi
-
-      # Now hardcode the library paths
-      rpath=
-      hardcode_libdirs=
-      for libdir in $compile_rpath $finalize_rpath; do
-       if test -n "$hardcode_libdir_flag_spec"; then
-         if test -n "$hardcode_libdir_separator"; then
-           if test -z "$hardcode_libdirs"; then
-             hardcode_libdirs="$libdir"
-           else
-             # Just accumulate the unique libdirs.
-             case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
-             *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
-               ;;
-             *)
-               hardcode_libdirs="$hardcode_libdirs$hardcode_libdir_separator$libdir"
-               ;;
-             esac
-           fi
-         else
-           eval flag=\"$hardcode_libdir_flag_spec\"
-           rpath="$rpath $flag"
-         fi
-       elif test -n "$runpath_var"; then
-         case "$perm_rpath " in
-         *" $libdir "*) ;;
-         *) perm_rpath="$perm_rpath $libdir" ;;
-         esac
-       fi
-       case $host in
-       *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
-         testbindir=`${ECHO} "$libdir" | ${SED} -e 's*/lib$*/bin*'`
-         case :$dllsearchpath: in
-         *":$libdir:"*) ;;
-         ::) dllsearchpath=$libdir;;
-         *) dllsearchpath="$dllsearchpath:$libdir";;
-         esac
-         case :$dllsearchpath: in
-         *":$testbindir:"*) ;;
-         ::) dllsearchpath=$testbindir;;
-         *) dllsearchpath="$dllsearchpath:$testbindir";;
-         esac
-         ;;
-       esac
-      done
-      # Substitute the hardcoded libdirs into the rpath.
-      if test -n "$hardcode_libdir_separator" &&
-        test -n "$hardcode_libdirs"; then
-       libdir="$hardcode_libdirs"
-       eval rpath=\" $hardcode_libdir_flag_spec\"
-      fi
-      compile_rpath="$rpath"
-
-      rpath=
-      hardcode_libdirs=
-      for libdir in $finalize_rpath; do
-       if test -n "$hardcode_libdir_flag_spec"; then
-         if test -n "$hardcode_libdir_separator"; then
-           if test -z "$hardcode_libdirs"; then
-             hardcode_libdirs="$libdir"
-           else
-             # Just accumulate the unique libdirs.
-             case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
-             *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
-               ;;
-             *)
-               hardcode_libdirs="$hardcode_libdirs$hardcode_libdir_separator$libdir"
-               ;;
-             esac
-           fi
-         else
-           eval flag=\"$hardcode_libdir_flag_spec\"
-           rpath="$rpath $flag"
-         fi
-       elif test -n "$runpath_var"; then
-         case "$finalize_perm_rpath " in
-         *" $libdir "*) ;;
-         *) finalize_perm_rpath="$finalize_perm_rpath $libdir" ;;
-         esac
-       fi
-      done
-      # Substitute the hardcoded libdirs into the rpath.
-      if test -n "$hardcode_libdir_separator" &&
-        test -n "$hardcode_libdirs"; then
-       libdir="$hardcode_libdirs"
-       eval rpath=\" $hardcode_libdir_flag_spec\"
-      fi
-      finalize_rpath="$rpath"
-
-      if test -n "$libobjs" && test "$build_old_libs" = yes; then
-       # Transform all the library objects into standard objects.
-       compile_command=`$ECHO "X$compile_command" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP`
-       finalize_command=`$ECHO "X$finalize_command" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP`
-      fi
-
-      func_generate_dlsyms "$outputname" "@PROGRAM@" "no"
-
-      # template prelinking step
-      if test -n "$prelink_cmds"; then
-       func_execute_cmds "$prelink_cmds" 'exit $?'
-      fi
-
-      wrappers_required=yes
-      case $host in
-      *cygwin* | *mingw* )
-        if test "$build_libtool_libs" != yes; then
-          wrappers_required=no
-        fi
-        ;;
-      *cegcc)
-        # Disable wrappers for cegcc, we are cross compiling anyway.
-        wrappers_required=no
-        ;;
-      *)
-        if test "$need_relink" = no || test "$build_libtool_libs" != yes; then
-          wrappers_required=no
-        fi
-        ;;
-      esac
-      if test "$wrappers_required" = no; then
-       # Replace the output file specification.
-       compile_command=`$ECHO "X$compile_command" | $Xsed -e 's%@OUTPUT@%'"$output"'%g'`
-       link_command="$compile_command$compile_rpath"
-
-       # We have no uninstalled library dependencies, so finalize right now.
-       exit_status=0
-       func_show_eval "$link_command" 'exit_status=$?'
-
-       # Delete the generated files.
-       if test -f "$output_objdir/${outputname}S.${objext}"; then
-         func_show_eval '$RM "$output_objdir/${outputname}S.${objext}"'
-       fi
-
-       exit $exit_status
-      fi
-
-      if test -n "$compile_shlibpath$finalize_shlibpath"; then
-       compile_command="$shlibpath_var=\"$compile_shlibpath$finalize_shlibpath\$$shlibpath_var\" $compile_command"
-      fi
-      if test -n "$finalize_shlibpath"; then
-       finalize_command="$shlibpath_var=\"$finalize_shlibpath\$$shlibpath_var\" $finalize_command"
-      fi
-
-      compile_var=
-      finalize_var=
-      if test -n "$runpath_var"; then
-       if test -n "$perm_rpath"; then
-         # We should set the runpath_var.
-         rpath=
-         for dir in $perm_rpath; do
-           rpath="$rpath$dir:"
-         done
-         compile_var="$runpath_var=\"$rpath\$$runpath_var\" "
-       fi
-       if test -n "$finalize_perm_rpath"; then
-         # We should set the runpath_var.
-         rpath=
-         for dir in $finalize_perm_rpath; do
-           rpath="$rpath$dir:"
-         done
-         finalize_var="$runpath_var=\"$rpath\$$runpath_var\" "
-       fi
-      fi
-
-      if test "$no_install" = yes; then
-       # We don't need to create a wrapper script.
-       link_command="$compile_var$compile_command$compile_rpath"
-       # Replace the output file specification.
-       link_command=`$ECHO "X$link_command" | $Xsed -e 's%@OUTPUT@%'"$output"'%g'`
-       # Delete the old output file.
-       $opt_dry_run || $RM $output
-       # Link the executable and exit
-       func_show_eval "$link_command" 'exit $?'
-       exit $EXIT_SUCCESS
-      fi
-
-      if test "$hardcode_action" = relink; then
-       # Fast installation is not supported
-       link_command="$compile_var$compile_command$compile_rpath"
-       relink_command="$finalize_var$finalize_command$finalize_rpath"
-
-       func_warning "this platform does not like uninstalled shared libraries"
-       func_warning "\`$output' will be relinked during installation"
-      else
-       if test "$fast_install" != no; then
-         link_command="$finalize_var$compile_command$finalize_rpath"
-         if test "$fast_install" = yes; then
-           relink_command=`$ECHO "X$compile_var$compile_command$compile_rpath" | $Xsed -e 's%@OUTPUT@%\$progdir/\$file%g'`
-         else
-           # fast_install is set to needless
-           relink_command=
-         fi
-       else
-         link_command="$compile_var$compile_command$compile_rpath"
-         relink_command="$finalize_var$finalize_command$finalize_rpath"
-       fi
-      fi
-
-      # Replace the output file specification.
-      link_command=`$ECHO "X$link_command" | $Xsed -e 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'`
-
-      # Delete the old output files.
-      $opt_dry_run || $RM $output $output_objdir/$outputname $output_objdir/lt-$outputname
-
-      func_show_eval "$link_command" 'exit $?'
-
-      # Now create the wrapper script.
-      func_verbose "creating $output"
-
-      # Quote the relink command for shipping.
-      if test -n "$relink_command"; then
-       # Preserve any variables that may affect compiler behavior
-       for var in $variables_saved_for_relink; do
-         if eval test -z \"\${$var+set}\"; then
-           relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
-         elif eval var_value=\$$var; test -z "$var_value"; then
-           relink_command="$var=; export $var; $relink_command"
-         else
-           func_quote_for_eval "$var_value"
-           relink_command="$var=$func_quote_for_eval_result; export $var; $relink_command"
-         fi
-       done
-       relink_command="(cd `pwd`; $relink_command)"
-       relink_command=`$ECHO "X$relink_command" | $Xsed -e "$sed_quote_subst"`
-      fi
-
-      # Quote $ECHO for shipping.
-      if test "X$ECHO" = "X$SHELL $progpath --fallback-echo"; then
-       case $progpath in
-       [\\/]* | [A-Za-z]:[\\/]*) qecho="$SHELL $progpath --fallback-echo";;
-       *) qecho="$SHELL `pwd`/$progpath --fallback-echo";;
-       esac
-       qecho=`$ECHO "X$qecho" | $Xsed -e "$sed_quote_subst"`
-      else
-       qecho=`$ECHO "X$ECHO" | $Xsed -e "$sed_quote_subst"`
-      fi
-
-      # Only actually do things if not in dry run mode.
-      $opt_dry_run || {
-       # win32 will think the script is a binary if it has
-       # a .exe suffix, so we strip it off here.
-       case $output in
-         *.exe) func_stripname '' '.exe' "$output"
-                output=$func_stripname_result ;;
-       esac
-       # test for cygwin because mv fails w/o .exe extensions
-       case $host in
-         *cygwin*)
-           exeext=.exe
-           func_stripname '' '.exe' "$outputname"
-           outputname=$func_stripname_result ;;
-         *) exeext= ;;
-       esac
-       case $host in
-         *cygwin* | *mingw* )
-           func_dirname_and_basename "$output" "" "."
-           output_name=$func_basename_result
-           output_path=$func_dirname_result
-           cwrappersource="$output_path/$objdir/lt-$output_name.c"
-           cwrapper="$output_path/$output_name.exe"
-           $RM $cwrappersource $cwrapper
-           trap "$RM $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15
-
-           func_emit_cwrapperexe_src > $cwrappersource
-
-           # The wrapper executable is built using the $host compiler,
-           # because it contains $host paths and files. If cross-
-           # compiling, it, like the target executable, must be
-           # executed on the $host or under an emulation environment.
-           $opt_dry_run || {
-             $LTCC $LTCFLAGS -o $cwrapper $cwrappersource
-             $STRIP $cwrapper
-           }
-
-           # Now, create the wrapper script for func_source use:
-           func_ltwrapper_scriptname $cwrapper
-           $RM $func_ltwrapper_scriptname_result
-           trap "$RM $func_ltwrapper_scriptname_result; exit $EXIT_FAILURE" 1 2 15
-           $opt_dry_run || {
-             # note: this script will not be executed, so do not chmod.
-             if test "x$build" = "x$host" ; then
-               $cwrapper --lt-dump-script > $func_ltwrapper_scriptname_result
-             else
-               func_emit_wrapper no > $func_ltwrapper_scriptname_result
-             fi
-           }
-         ;;
-         * )
-           $RM $output
-           trap "$RM $output; exit $EXIT_FAILURE" 1 2 15
-
-           func_emit_wrapper no > $output
-           chmod +x $output
-         ;;
-       esac
-      }
-      exit $EXIT_SUCCESS
-      ;;
-    esac
-
-    # See if we need to build an old-fashioned archive.
-    for oldlib in $oldlibs; do
-
-      if test "$build_libtool_libs" = convenience; then
-       oldobjs="$libobjs_save $symfileobj"
-       addlibs="$convenience"
-       build_libtool_libs=no
-      else
-       if test "$build_libtool_libs" = module; then
-         oldobjs="$libobjs_save"
-         build_libtool_libs=no
-       else
-         oldobjs="$old_deplibs $non_pic_objects"
-         if test "$preload" = yes && test -f "$symfileobj"; then
-           oldobjs="$oldobjs $symfileobj"
-         fi
-       fi
-       addlibs="$old_convenience"
-      fi
-
-      if test -n "$addlibs"; then
-       gentop="$output_objdir/${outputname}x"
-       generated="$generated $gentop"
-
-       func_extract_archives $gentop $addlibs
-       oldobjs="$oldobjs $func_extract_archives_result"
-      fi
-
-      # Do each command in the archive commands.
-      if test -n "$old_archive_from_new_cmds" && test "$build_libtool_libs" = yes; then
-       cmds=$old_archive_from_new_cmds
-      else
-
-       # Add any objects from preloaded convenience libraries
-       if test -n "$dlprefiles"; then
-         gentop="$output_objdir/${outputname}x"
-         generated="$generated $gentop"
-
-         func_extract_archives $gentop $dlprefiles
-         oldobjs="$oldobjs $func_extract_archives_result"
-       fi
-
-       # POSIX demands no paths to be encoded in archives.  We have
-       # to avoid creating archives with duplicate basenames if we
-       # might have to extract them afterwards, e.g., when creating a
-       # static archive out of a convenience library, or when linking
-       # the entirety of a libtool archive into another (currently
-       # not supported by libtool).
-       if (for obj in $oldobjs
-           do
-             func_basename "$obj"
-             $ECHO "$func_basename_result"
-           done | sort | sort -uc >/dev/null 2>&1); then
-         :
-       else
-         $ECHO "copying selected object files to avoid basename conflicts..."
-         gentop="$output_objdir/${outputname}x"
-         generated="$generated $gentop"
-         func_mkdir_p "$gentop"
-         save_oldobjs=$oldobjs
-         oldobjs=
-         counter=1
-         for obj in $save_oldobjs
-         do
-           func_basename "$obj"
-           objbase="$func_basename_result"
-           case " $oldobjs " in
-           " ") oldobjs=$obj ;;
-           *[\ /]"$objbase "*)
-             while :; do
-               # Make sure we don't pick an alternate name that also
-               # overlaps.
-               newobj=lt$counter-$objbase
-               func_arith $counter + 1
-               counter=$func_arith_result
-               case " $oldobjs " in
-               *[\ /]"$newobj "*) ;;
-               *) if test ! -f "$gentop/$newobj"; then break; fi ;;
-               esac
-             done
-             func_show_eval "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj"
-             oldobjs="$oldobjs $gentop/$newobj"
-             ;;
-           *) oldobjs="$oldobjs $obj" ;;
-           esac
-         done
-       fi
-       eval cmds=\"$old_archive_cmds\"
-
-       func_len " $cmds"
-       len=$func_len_result
-       if test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
-         cmds=$old_archive_cmds
-       else
-         # the command line is too long to link in one step, link in parts
-         func_verbose "using piecewise archive linking..."
-         save_RANLIB=$RANLIB
-         RANLIB=:
-         objlist=
-         concat_cmds=
-         save_oldobjs=$oldobjs
-         oldobjs=
-         # Is there a better way of finding the last object in the list?
-         for obj in $save_oldobjs
-         do
-           last_oldobj=$obj
-         done
-         eval test_cmds=\"$old_archive_cmds\"
-         func_len " $test_cmds"
-         len0=$func_len_result
-         len=$len0
-         for obj in $save_oldobjs
-         do
-           func_len " $obj"
-           func_arith $len + $func_len_result
-           len=$func_arith_result
-           func_append objlist " $obj"
-           if test "$len" -lt "$max_cmd_len"; then
-             :
-           else
-             # the above command should be used before it gets too long
-             oldobjs=$objlist
-             if test "$obj" = "$last_oldobj" ; then
-               RANLIB=$save_RANLIB
-             fi
-             test -z "$concat_cmds" || concat_cmds=$concat_cmds~
-             eval concat_cmds=\"\${concat_cmds}$old_archive_cmds\"
-             objlist=
-             len=$len0
-           fi
-         done
-         RANLIB=$save_RANLIB
-         oldobjs=$objlist
-         if test "X$oldobjs" = "X" ; then
-           eval cmds=\"\$concat_cmds\"
-         else
-           eval cmds=\"\$concat_cmds~\$old_archive_cmds\"
-         fi
-       fi
-      fi
-      func_execute_cmds "$cmds" 'exit $?'
-    done
-
-    test -n "$generated" && \
-      func_show_eval "${RM}r$generated"
-
-    # Now create the libtool archive.
-    case $output in
-    *.la)
-      old_library=
-      test "$build_old_libs" = yes && old_library="$libname.$libext"
-      func_verbose "creating $output"
-
-      # Preserve any variables that may affect compiler behavior
-      for var in $variables_saved_for_relink; do
-       if eval test -z \"\${$var+set}\"; then
-         relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
-       elif eval var_value=\$$var; test -z "$var_value"; then
-         relink_command="$var=; export $var; $relink_command"
-       else
-         func_quote_for_eval "$var_value"
-         relink_command="$var=$func_quote_for_eval_result; export $var; $relink_command"
-       fi
-      done
-      # Quote the link command for shipping.
-      relink_command="(cd `pwd`; $SHELL $progpath $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)"
-      relink_command=`$ECHO "X$relink_command" | $Xsed -e "$sed_quote_subst"`
-      if test "$hardcode_automatic" = yes ; then
-       relink_command=
-      fi
-
-      # Only create the output if not a dry run.
-      $opt_dry_run || {
-       for installed in no yes; do
-         if test "$installed" = yes; then
-           if test -z "$install_libdir"; then
-             break
-           fi
-           output="$output_objdir/$outputname"i
-           # Replace all uninstalled libtool libraries with the installed ones
-           newdependency_libs=
-           for deplib in $dependency_libs; do
-             case $deplib in
-             *.la)
-               func_basename "$deplib"
-               name="$func_basename_result"
-               eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $deplib`
-               test -z "$libdir" && \
-                 func_fatal_error "\`$deplib' is not a valid libtool archive"
-               newdependency_libs="$newdependency_libs $libdir/$name"
-               ;;
-             *) newdependency_libs="$newdependency_libs $deplib" ;;
-             esac
-           done
-           dependency_libs="$newdependency_libs"
-           newdlfiles=
-
-           for lib in $dlfiles; do
-             case $lib in
-             *.la)
-               func_basename "$lib"
-               name="$func_basename_result"
-               eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
-               test -z "$libdir" && \
-                 func_fatal_error "\`$lib' is not a valid libtool archive"
-               newdlfiles="$newdlfiles $libdir/$name"
-               ;;
-             *) newdlfiles="$newdlfiles $lib" ;;
-             esac
-           done
-           dlfiles="$newdlfiles"
-           newdlprefiles=
-           for lib in $dlprefiles; do
-             case $lib in
-             *.la)
-               # Only pass preopened files to the pseudo-archive (for
-               # eventual linking with the app. that links it) if we
-               # didn't already link the preopened objects directly into
-               # the library:
-               func_basename "$lib"
-               name="$func_basename_result"
-               eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
-               test -z "$libdir" && \
-                 func_fatal_error "\`$lib' is not a valid libtool archive"
-               newdlprefiles="$newdlprefiles $libdir/$name"
-               ;;
-             esac
-           done
-           dlprefiles="$newdlprefiles"
-         else
-           newdlfiles=
-           for lib in $dlfiles; do
-             case $lib in
-               [\\/]* | [A-Za-z]:[\\/]*) abs="$lib" ;;
-               *) abs=`pwd`"/$lib" ;;
-             esac
-             newdlfiles="$newdlfiles $abs"
-           done
-           dlfiles="$newdlfiles"
-           newdlprefiles=
-           for lib in $dlprefiles; do
-             case $lib in
-               [\\/]* | [A-Za-z]:[\\/]*) abs="$lib" ;;
-               *) abs=`pwd`"/$lib" ;;
-             esac
-             newdlprefiles="$newdlprefiles $abs"
-           done
-           dlprefiles="$newdlprefiles"
-         fi
-         $RM $output
-         # place dlname in correct position for cygwin
-         tdlname=$dlname
-         case $host,$output,$installed,$module,$dlname in
-           *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll) tdlname=../bin/$dlname ;;
-         esac
-         $ECHO > $output "\
-# $outputname - a libtool library file
-# Generated by $PROGRAM (GNU $PACKAGE$TIMESTAMP) $VERSION
-#
-# Please DO NOT delete this file!
-# It is necessary for linking the library.
-
-# The name that we can dlopen(3).
-dlname='$tdlname'
-
-# Names of this library.
-library_names='$library_names'
-
-# The name of the static archive.
-old_library='$old_library'
-
-# Linker flags that can not go in dependency_libs.
-inherited_linker_flags='$new_inherited_linker_flags'
-
-# Libraries that this one depends upon.
-dependency_libs='$dependency_libs'
-
-# Names of additional weak libraries provided by this library
-weak_library_names='$weak_libs'
-
-# Version information for $libname.
-current=$current
-age=$age
-revision=$revision
-
-# Is this an already installed library?
-installed=$installed
-
-# Should we warn about portability when linking against -modules?
-shouldnotlink=$module
-
-# Files to dlopen/dlpreopen
-dlopen='$dlfiles'
-dlpreopen='$dlprefiles'
-
-# Directory that this library needs to be installed in:
-libdir='$install_libdir'"
-         if test "$installed" = no && test "$need_relink" = yes; then
-           $ECHO >> $output "\
-relink_command=\"$relink_command\""
-         fi
-       done
-      }
-
-      # Do a symbolic link so that the libtool archive can be found in
-      # LD_LIBRARY_PATH before the program is installed.
-      func_show_eval '( cd "$output_objdir" && $RM "$outputname" && $LN_S "../$outputname" "$outputname" )' 'exit $?'
-      ;;
-    esac
-    exit $EXIT_SUCCESS
-}
-
-{ test "$mode" = link || test "$mode" = relink; } &&
-    func_mode_link ${1+"$@"}
-
-
-# func_mode_uninstall arg...
-func_mode_uninstall ()
-{
-    $opt_debug
-    RM="$nonopt"
-    files=
-    rmforce=
-    exit_status=0
-
-    # This variable tells wrapper scripts just to set variables rather
-    # than running their programs.
-    libtool_install_magic="$magic"
-
-    for arg
-    do
-      case $arg in
-      -f) RM="$RM $arg"; rmforce=yes ;;
-      -*) RM="$RM $arg" ;;
-      *) files="$files $arg" ;;
-      esac
-    done
-
-    test -z "$RM" && \
-      func_fatal_help "you must specify an RM program"
-
-    rmdirs=
-
-    origobjdir="$objdir"
-    for file in $files; do
-      func_dirname "$file" "" "."
-      dir="$func_dirname_result"
-      if test "X$dir" = X.; then
-       objdir="$origobjdir"
-      else
-       objdir="$dir/$origobjdir"
-      fi
-      func_basename "$file"
-      name="$func_basename_result"
-      test "$mode" = uninstall && objdir="$dir"
-
-      # Remember objdir for removal later, being careful to avoid duplicates
-      if test "$mode" = clean; then
-       case " $rmdirs " in
-         *" $objdir "*) ;;
-         *) rmdirs="$rmdirs $objdir" ;;
-       esac
-      fi
-
-      # Don't error if the file doesn't exist and rm -f was used.
-      if { test -L "$file"; } >/dev/null 2>&1 ||
-        { test -h "$file"; } >/dev/null 2>&1 ||
-        test -f "$file"; then
-       :
-      elif test -d "$file"; then
-       exit_status=1
-       continue
-      elif test "$rmforce" = yes; then
-       continue
-      fi
-
-      rmfiles="$file"
-
-      case $name in
-      *.la)
-       # Possibly a libtool archive, so verify it.
-       if func_lalib_p "$file"; then
-         func_source $dir/$name
-
-         # Delete the libtool libraries and symlinks.
-         for n in $library_names; do
-           rmfiles="$rmfiles $objdir/$n"
-         done
-         test -n "$old_library" && rmfiles="$rmfiles $objdir/$old_library"
-
-         case "$mode" in
-         clean)
-           case "  $library_names " in
-           # "  " in the beginning catches empty $dlname
-           *" $dlname "*) ;;
-           *) rmfiles="$rmfiles $objdir/$dlname" ;;
-           esac
-           test -n "$libdir" && rmfiles="$rmfiles $objdir/$name $objdir/${name}i"
-           ;;
-         uninstall)
-           if test -n "$library_names"; then
-             # Do each command in the postuninstall commands.
-             func_execute_cmds "$postuninstall_cmds" 'test "$rmforce" = yes || exit_status=1'
-           fi
-
-           if test -n "$old_library"; then
-             # Do each command in the old_postuninstall commands.
-             func_execute_cmds "$old_postuninstall_cmds" 'test "$rmforce" = yes || exit_status=1'
-           fi
-           # FIXME: should reinstall the best remaining shared library.
-           ;;
-         esac
-       fi
-       ;;
-
-      *.lo)
-       # Possibly a libtool object, so verify it.
-       if func_lalib_p "$file"; then
-
-         # Read the .lo file
-         func_source $dir/$name
-
-         # Add PIC object to the list of files to remove.
-         if test -n "$pic_object" &&
-            test "$pic_object" != none; then
-           rmfiles="$rmfiles $dir/$pic_object"
-         fi
-
-         # Add non-PIC object to the list of files to remove.
-         if test -n "$non_pic_object" &&
-            test "$non_pic_object" != none; then
-           rmfiles="$rmfiles $dir/$non_pic_object"
-         fi
-       fi
-       ;;
-
-      *)
-       if test "$mode" = clean ; then
-         noexename=$name
-         case $file in
-         *.exe)
-           func_stripname '' '.exe' "$file"
-           file=$func_stripname_result
-           func_stripname '' '.exe' "$name"
-           noexename=$func_stripname_result
-           # $file with .exe has already been added to rmfiles,
-           # add $file without .exe
-           rmfiles="$rmfiles $file"
-           ;;
-         esac
-         # Do a test to see if this is a libtool program.
-         if func_ltwrapper_p "$file"; then
-           if func_ltwrapper_executable_p "$file"; then
-             func_ltwrapper_scriptname "$file"
-             relink_command=
-             func_source $func_ltwrapper_scriptname_result
-             rmfiles="$rmfiles $func_ltwrapper_scriptname_result"
-           else
-             relink_command=
-             func_source $dir/$noexename
-           fi
-
-           # note $name still contains .exe if it was in $file originally
-           # as does the version of $file that was added into $rmfiles
-           rmfiles="$rmfiles $objdir/$name $objdir/${name}S.${objext}"
-           if test "$fast_install" = yes && test -n "$relink_command"; then
-             rmfiles="$rmfiles $objdir/lt-$name"
-           fi
-           if test "X$noexename" != "X$name" ; then
-             rmfiles="$rmfiles $objdir/lt-${noexename}.c"
-           fi
-         fi
-       fi
-       ;;
-      esac
-      func_show_eval "$RM $rmfiles" 'exit_status=1'
-    done
-    objdir="$origobjdir"
-
-    # Try to remove the ${objdir}s in the directories where we deleted files
-    for dir in $rmdirs; do
-      if test -d "$dir"; then
-       func_show_eval "rmdir $dir >/dev/null 2>&1"
-      fi
-    done
-
-    exit $exit_status
-}
-
-{ test "$mode" = uninstall || test "$mode" = clean; } &&
-    func_mode_uninstall ${1+"$@"}
-
-test -z "$mode" && {
-  help="$generic_help"
-  func_fatal_help "you must specify a MODE"
-}
-
-test -z "$exec_cmd" && \
-  func_fatal_help "invalid operation mode \`$mode'"
-
-if test -n "$exec_cmd"; then
-  eval exec "$exec_cmd"
-  exit $EXIT_FAILURE
-fi
-
-exit $exit_status
-
-
-# The TAGs below are defined such that we never get into a situation
-# in which we disable both kinds of libraries.  Given conflicting
-# choices, we go for a static library, that is the most portable,
-# since we can't tell whether shared libraries were disabled because
-# the user asked for that or because the platform doesn't support
-# them.  This is particularly important on AIX, because we don't
-# support having both static and shared libraries enabled at the same
-# time on that platform, so we default to a shared-only configuration.
-# If a disable-shared tag is given, we'll fallback to a static-only
-# configuration.  But we'll never go from static-only to shared-only.
-
-# ### BEGIN LIBTOOL TAG CONFIG: disable-shared
-build_libtool_libs=no
-build_old_libs=yes
-# ### END LIBTOOL TAG CONFIG: disable-shared
-
-# ### BEGIN LIBTOOL TAG CONFIG: disable-static
-build_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac`
-# ### END LIBTOOL TAG CONFIG: disable-static
-
-# Local Variables:
-# mode:shell-script
-# sh-indentation:2
-# End:
-# vi:sw=2
-
diff --git a/build-aux/missing b/build-aux/missing
deleted file mode 100755 (executable)
index 28055d2..0000000
+++ /dev/null
@@ -1,376 +0,0 @@
-#! /bin/sh
-# Common stub for a few missing GNU programs while installing.
-
-scriptversion=2009-04-28.21; # UTC
-
-# Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003, 2004, 2005, 2006,
-# 2008, 2009 Free Software Foundation, Inc.
-# Originally by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
-
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2, or (at your option)
-# any later version.
-
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-# As a special exception to the GNU General Public License, if you
-# distribute this file as part of a program that contains a
-# configuration script generated by Autoconf, you may include it under
-# the same distribution terms that you use for the rest of that program.
-
-if test $# -eq 0; then
-  echo 1>&2 "Try \`$0 --help' for more information"
-  exit 1
-fi
-
-run=:
-sed_output='s/.* --output[ =]\([^ ]*\).*/\1/p'
-sed_minuso='s/.* -o \([^ ]*\).*/\1/p'
-
-# In the cases where this matters, `missing' is being run in the
-# srcdir already.
-if test -f configure.ac; then
-  configure_ac=configure.ac
-else
-  configure_ac=configure.in
-fi
-
-msg="missing on your system"
-
-case $1 in
---run)
-  # Try to run requested program, and just exit if it succeeds.
-  run=
-  shift
-  "$@" && exit 0
-  # Exit code 63 means version mismatch.  This often happens
-  # when the user try to use an ancient version of a tool on
-  # a file that requires a minimum version.  In this case we
-  # we should proceed has if the program had been absent, or
-  # if --run hadn't been passed.
-  if test $? = 63; then
-    run=:
-    msg="probably too old"
-  fi
-  ;;
-
-  -h|--h|--he|--hel|--help)
-    echo "\
-$0 [OPTION]... PROGRAM [ARGUMENT]...
-
-Handle \`PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an
-error status if there is no known handling for PROGRAM.
-
-Options:
-  -h, --help      display this help and exit
-  -v, --version   output version information and exit
-  --run           try to run the given command, and emulate it if it fails
-
-Supported PROGRAM values:
-  aclocal      touch file \`aclocal.m4'
-  autoconf     touch file \`configure'
-  autoheader   touch file \`config.h.in'
-  autom4te     touch the output file, or create a stub one
-  automake     touch all \`Makefile.in' files
-  bison        create \`y.tab.[ch]', if possible, from existing .[ch]
-  flex         create \`lex.yy.c', if possible, from existing .c
-  help2man     touch the output file
-  lex          create \`lex.yy.c', if possible, from existing .c
-  makeinfo     touch the output file
-  tar          try tar, gnutar, gtar, then tar without non-portable flags
-  yacc         create \`y.tab.[ch]', if possible, from existing .[ch]
-
-Version suffixes to PROGRAM as well as the prefixes \`gnu-', \`gnu', and
-\`g' are ignored when checking the name.
-
-Send bug reports to <bug-automake@gnu.org>."
-    exit $?
-    ;;
-
-  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
-    echo "missing $scriptversion (GNU Automake)"
-    exit $?
-    ;;
-
-  -*)
-    echo 1>&2 "$0: Unknown \`$1' option"
-    echo 1>&2 "Try \`$0 --help' for more information"
-    exit 1
-    ;;
-
-esac
-
-# normalize program name to check for.
-program=`echo "$1" | sed '
-  s/^gnu-//; t
-  s/^gnu//; t
-  s/^g//; t'`
-
-# Now exit if we have it, but it failed.  Also exit now if we
-# don't have it and --version was passed (most likely to detect
-# the program).  This is about non-GNU programs, so use $1 not
-# $program.
-case $1 in
-  lex*|yacc*)
-    # Not GNU programs, they don't have --version.
-    ;;
-
-  tar*)
-    if test -n "$run"; then
-       echo 1>&2 "ERROR: \`tar' requires --run"
-       exit 1
-    elif test "x$2" = "x--version" || test "x$2" = "x--help"; then
-       exit 1
-    fi
-    ;;
-
-  *)
-    if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
-       # We have it, but it failed.
-       exit 1
-    elif test "x$2" = "x--version" || test "x$2" = "x--help"; then
-       # Could not run --version or --help.  This is probably someone
-       # running `$TOOL --version' or `$TOOL --help' to check whether
-       # $TOOL exists and not knowing $TOOL uses missing.
-       exit 1
-    fi
-    ;;
-esac
-
-# If it does not exist, or fails to run (possibly an outdated version),
-# try to emulate it.
-case $program in
-  aclocal*)
-    echo 1>&2 "\
-WARNING: \`$1' is $msg.  You should only need it if
-         you modified \`acinclude.m4' or \`${configure_ac}'.  You might want
-         to install the \`Automake' and \`Perl' packages.  Grab them from
-         any GNU archive site."
-    touch aclocal.m4
-    ;;
-
-  autoconf*)
-    echo 1>&2 "\
-WARNING: \`$1' is $msg.  You should only need it if
-         you modified \`${configure_ac}'.  You might want to install the
-         \`Autoconf' and \`GNU m4' packages.  Grab them from any GNU
-         archive site."
-    touch configure
-    ;;
-
-  autoheader*)
-    echo 1>&2 "\
-WARNING: \`$1' is $msg.  You should only need it if
-         you modified \`acconfig.h' or \`${configure_ac}'.  You might want
-         to install the \`Autoconf' and \`GNU m4' packages.  Grab them
-         from any GNU archive site."
-    files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' ${configure_ac}`
-    test -z "$files" && files="config.h"
-    touch_files=
-    for f in $files; do
-      case $f in
-      *:*) touch_files="$touch_files "`echo "$f" |
-                                      sed -e 's/^[^:]*://' -e 's/:.*//'`;;
-      *) touch_files="$touch_files $f.in";;
-      esac
-    done
-    touch $touch_files
-    ;;
-
-  automake*)
-    echo 1>&2 "\
-WARNING: \`$1' is $msg.  You should only need it if
-         you modified \`Makefile.am', \`acinclude.m4' or \`${configure_ac}'.
-         You might want to install the \`Automake' and \`Perl' packages.
-         Grab them from any GNU archive site."
-    find . -type f -name Makefile.am -print |
-          sed 's/\.am$/.in/' |
-          while read f; do touch "$f"; done
-    ;;
-
-  autom4te*)
-    echo 1>&2 "\
-WARNING: \`$1' is needed, but is $msg.
-         You might have modified some files without having the
-         proper tools for further handling them.
-         You can get \`$1' as part of \`Autoconf' from any GNU
-         archive site."
-
-    file=`echo "$*" | sed -n "$sed_output"`
-    test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
-    if test -f "$file"; then
-       touch $file
-    else
-       test -z "$file" || exec >$file
-       echo "#! /bin/sh"
-       echo "# Created by GNU Automake missing as a replacement of"
-       echo "#  $ $@"
-       echo "exit 0"
-       chmod +x $file
-       exit 1
-    fi
-    ;;
-
-  bison*|yacc*)
-    echo 1>&2 "\
-WARNING: \`$1' $msg.  You should only need it if
-         you modified a \`.y' file.  You may need the \`Bison' package
-         in order for those modifications to take effect.  You can get
-         \`Bison' from any GNU archive site."
-    rm -f y.tab.c y.tab.h
-    if test $# -ne 1; then
-        eval LASTARG="\${$#}"
-       case $LASTARG in
-       *.y)
-           SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'`
-           if test -f "$SRCFILE"; then
-                cp "$SRCFILE" y.tab.c
-           fi
-           SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'`
-           if test -f "$SRCFILE"; then
-                cp "$SRCFILE" y.tab.h
-           fi
-         ;;
-       esac
-    fi
-    if test ! -f y.tab.h; then
-       echo >y.tab.h
-    fi
-    if test ! -f y.tab.c; then
-       echo 'main() { return 0; }' >y.tab.c
-    fi
-    ;;
-
-  lex*|flex*)
-    echo 1>&2 "\
-WARNING: \`$1' is $msg.  You should only need it if
-         you modified a \`.l' file.  You may need the \`Flex' package
-         in order for those modifications to take effect.  You can get
-         \`Flex' from any GNU archive site."
-    rm -f lex.yy.c
-    if test $# -ne 1; then
-        eval LASTARG="\${$#}"
-       case $LASTARG in
-       *.l)
-           SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'`
-           if test -f "$SRCFILE"; then
-                cp "$SRCFILE" lex.yy.c
-           fi
-         ;;
-       esac
-    fi
-    if test ! -f lex.yy.c; then
-       echo 'main() { return 0; }' >lex.yy.c
-    fi
-    ;;
-
-  help2man*)
-    echo 1>&2 "\
-WARNING: \`$1' is $msg.  You should only need it if
-        you modified a dependency of a manual page.  You may need the
-        \`Help2man' package in order for those modifications to take
-        effect.  You can get \`Help2man' from any GNU archive site."
-
-    file=`echo "$*" | sed -n "$sed_output"`
-    test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
-    if test -f "$file"; then
-       touch $file
-    else
-       test -z "$file" || exec >$file
-       echo ".ab help2man is required to generate this page"
-       exit $?
-    fi
-    ;;
-
-  makeinfo*)
-    echo 1>&2 "\
-WARNING: \`$1' is $msg.  You should only need it if
-         you modified a \`.texi' or \`.texinfo' file, or any other file
-         indirectly affecting the aspect of the manual.  The spurious
-         call might also be the consequence of using a buggy \`make' (AIX,
-         DU, IRIX).  You might want to install the \`Texinfo' package or
-         the \`GNU make' package.  Grab either from any GNU archive site."
-    # The file to touch is that specified with -o ...
-    file=`echo "$*" | sed -n "$sed_output"`
-    test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
-    if test -z "$file"; then
-      # ... or it is the one specified with @setfilename ...
-      infile=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'`
-      file=`sed -n '
-       /^@setfilename/{
-         s/.* \([^ ]*\) *$/\1/
-         p
-         q
-       }' $infile`
-      # ... or it is derived from the source name (dir/f.texi becomes f.info)
-      test -z "$file" && file=`echo "$infile" | sed 's,.*/,,;s,.[^.]*$,,'`.info
-    fi
-    # If the file does not exist, the user really needs makeinfo;
-    # let's fail without touching anything.
-    test -f $file || exit 1
-    touch $file
-    ;;
-
-  tar*)
-    shift
-
-    # We have already tried tar in the generic part.
-    # Look for gnutar/gtar before invocation to avoid ugly error
-    # messages.
-    if (gnutar --version > /dev/null 2>&1); then
-       gnutar "$@" && exit 0
-    fi
-    if (gtar --version > /dev/null 2>&1); then
-       gtar "$@" && exit 0
-    fi
-    firstarg="$1"
-    if shift; then
-       case $firstarg in
-       *o*)
-           firstarg=`echo "$firstarg" | sed s/o//`
-           tar "$firstarg" "$@" && exit 0
-           ;;
-       esac
-       case $firstarg in
-       *h*)
-           firstarg=`echo "$firstarg" | sed s/h//`
-           tar "$firstarg" "$@" && exit 0
-           ;;
-       esac
-    fi
-
-    echo 1>&2 "\
-WARNING: I can't seem to be able to run \`tar' with the given arguments.
-         You may want to install GNU tar or Free paxutils, or check the
-         command line arguments."
-    exit 1
-    ;;
-
-  *)
-    echo 1>&2 "\
-WARNING: \`$1' is needed, and is $msg.
-         You might have modified some files without having the
-         proper tools for further handling them.  Check the \`README' file,
-         it often tells you about the needed prerequisites for installing
-         this package.  You may also peek at any GNU archive site, in case
-         some other package would contain this missing \`$1' program."
-    exit 1
-    ;;
-esac
-
-exit 0
-
-# Local variables:
-# eval: (add-hook 'write-file-hooks 'time-stamp)
-# time-stamp-start: "scriptversion="
-# time-stamp-format: "%:y-%02m-%02d.%02H"
-# time-stamp-time-zone: "UTC"
-# time-stamp-end: "; # UTC"
-# End:
index c5cbb34..b02108a 100644 (file)
@@ -2,18 +2,57 @@
 
 #include "xorg-server.h"
 
+/* Builder description */
+#undef BUILDER_DESCRIPTION
+
+/* Enable memory debugging */
+#undef DEBUG_MEMORY
+
+/* Enable pixmap debugging */
+#undef DEBUG_PIXMAP
+
+/* Default acceleration method */
+#undef DEFAULT_ACCEL_METHOD
+
 /* Enable XvMC support */
 #undef ENABLE_XVMC
 
+/* Enable all debugging */
+#undef HAS_DEBUG_FULL
+
+/* Enable pixman glyph cache */
+#undef HAS_PIXMAN_GLYPHS
+
+/* Define to 1 if you have the <dgaproc.h> header file. */
+#undef HAVE_DGAPROC_H
+
 /* Define to 1 if you have the <dlfcn.h> header file. */
 #undef HAVE_DLFCN_H
 
+/* Are we in a git checkout? */
+#undef HAVE_DOT_GIT
+
+/* Enable DRI driver support */
+#undef HAVE_DRI1
+
+/* Define to 1 if you have the <dri2.h> header file. */
+#undef HAVE_DRI2_H
+
+/* Define to 1 if you have the <dristruct.h> header file. */
+#undef HAVE_DRISTRUCT_H
+
+/* Define to 1 if you have the <dri.h> header file. */
+#undef HAVE_DRI_H
+
 /* Define to 1 if you have the <inttypes.h> header file. */
 #undef HAVE_INTTYPES_H
 
 /* Define to 1 if you have the <memory.h> header file. */
 #undef HAVE_MEMORY_H
 
+/* Define to 1 if you have the <sarea.h> header file. */
+#undef HAVE_SAREA_H
+
 /* Define to 1 if you have the <stdint.h> header file. */
 #undef HAVE_STDINT_H
 
@@ -29,6 +68,9 @@
 /* Define to 1 if you have the <sys/stat.h> header file. */
 #undef HAVE_SYS_STAT_H
 
+/* Define to 1 if you have the <sys/sysinfo.h> header file. */
+#undef HAVE_SYS_SYSINFO_H
+
 /* Define to 1 if you have the <sys/types.h> header file. */
 #undef HAVE_SYS_TYPES_H
 
 /* Define to 1 if you have the <unistd.h> header file. */
 #undef HAVE_UNISTD_H
 
+/* Use valgrind intrinsics to suppress false warnings */
+#undef HAVE_VALGRIND
+
+/* Define to 1 if you have the <xaa.h> header file. */
+#undef HAVE_XAA_H
+
 /* Assume KMS support */
 #undef KMS_ONLY
 
 /* Define to 1 if you have the ANSI C header files. */
 #undef STDC_HEADERS
 
+/* Assume only UMS (no KMS) support */
+#undef UMS_ONLY
+
+/* Assume asynchronous swap support */
+#undef USE_ASYNC_SWAP
+
+/* Use automagic builder description */
+#undef USE_GIT_DESCRIBE
+
+/* Enable glamor acceleration */
+#undef USE_GLAMOR
+
+/* Enable SNA support */
+#undef USE_SNA
+
+/* Assume USERPTR support */
+#undef USE_USERPTR
+
+/* Enable UXA support */
+#undef USE_UXA
+
 /* Version number of package */
 #undef VERSION
 
-/* Enable DRI driver support */
-#undef XF86DRI
+/* Enable large inode numbers on Mac OS X 10.5.  */
+#ifndef _DARWIN_USE_64_BIT_INODE
+# define _DARWIN_USE_64_BIT_INODE 1
+#endif
+
+/* Number of bits in a file offset, on hosts where this is settable. */
+#undef _FILE_OFFSET_BITS
 
-/* Enable developmental DRI driver support */
-#undef XF86DRI_DEVEL
+/* Define for large files, on AIX-style hosts. */
+#undef _LARGE_FILES
index 2a143c8..e1fec96 100755 (executable)
--- a/configure
+++ b/configure
@@ -1,13 +1,11 @@
 #! /bin/sh
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.67 for xf86-video-intel 2.15.0.
+# Generated by GNU Autoconf 2.69 for xf86-video-intel 2.20.9.
 #
 # Report bugs to <https://bugs.freedesktop.org/enter_bug.cgi?product=xorg>.
 #
 #
-# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
-# 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software
-# Foundation, Inc.
+# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
 #
 #
 # This configure script is free software; the Free Software Foundation
@@ -91,6 +89,7 @@ fi
 IFS=" ""       $as_nl"
 
 # Find who we are.  Look in the path if we contain no directory separator.
+as_myself=
 case $0 in #((
   *[\\/]* ) as_myself=$0 ;;
   *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
@@ -135,6 +134,31 @@ export LANGUAGE
 # CDPATH.
 (unset CDPATH) >/dev/null 2>&1 && unset CDPATH
 
+# Use a proper internal environment variable to ensure we don't fall
+  # into an infinite loop, continuously re-executing ourselves.
+  if test x"${_as_can_reexec}" != xno && test "x$CONFIG_SHELL" != x; then
+    _as_can_reexec=no; export _as_can_reexec;
+    # We cannot yet assume a decent shell, so we have to provide a
+# neutralization value for shells without unset; and this also
+# works around shells that cannot unset nonexistent variables.
+# Preserve -v and -x to the replacement shell.
+BASH_ENV=/dev/null
+ENV=/dev/null
+(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV
+case $- in # ((((
+  *v*x* | *x*v* ) as_opts=-vx ;;
+  *v* ) as_opts=-v ;;
+  *x* ) as_opts=-x ;;
+  * ) as_opts= ;;
+esac
+exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"}
+# Admittedly, this is quite paranoid, since all the known shells bail
+# out after a failed `exec'.
+$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2
+as_fn_exit 255
+  fi
+  # We don't want this to propagate to other subprocesses.
+          { _as_can_reexec=; unset _as_can_reexec;}
 if test "x$CONFIG_SHELL" = x; then
   as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then :
   emulate sh
@@ -168,12 +192,21 @@ if ( set x; as_fn_ret_success y && test x = \"\$1\" ); then :
 else
   exitcode=1; echo positional parameters were not saved.
 fi
-test x\$exitcode = x0 || exit 1"
+test x\$exitcode = x0 || exit 1
+test -x / || exit 1"
   as_suggested="  as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO
   as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO
   eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" &&
   test \"x\`expr \$as_lineno_1'\$as_run' + 1\`\" = \"x\$as_lineno_2'\$as_run'\"' || exit 1
-test \$(( 1 + 1 )) = 2 || exit 1"
+test \$(( 1 + 1 )) = 2 || exit 1
+
+  test -n \"\${ZSH_VERSION+set}\${BASH_VERSION+set}\" || (
+    ECHO='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'
+    ECHO=\$ECHO\$ECHO\$ECHO\$ECHO\$ECHO
+    ECHO=\$ECHO\$ECHO\$ECHO\$ECHO\$ECHO\$ECHO
+    PATH=/empty FPATH=/empty; export PATH FPATH
+    test \"X\`printf %s \$ECHO\`\" = \"X\$ECHO\" \\
+      || test \"X\`print -r -- \$ECHO\`\" = \"X\$ECHO\" ) || exit 1"
   if (eval "$as_required") 2>/dev/null; then :
   as_have_required=yes
 else
@@ -213,14 +246,25 @@ IFS=$as_save_IFS
 
 
       if test "x$CONFIG_SHELL" != x; then :
-  # We cannot yet assume a decent shell, so we have to provide a
-       # neutralization value for shells without unset; and this also
-       # works around shells that cannot unset nonexistent variables.
-       BASH_ENV=/dev/null
-       ENV=/dev/null
-       (unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV
-       export CONFIG_SHELL
-       exec "$CONFIG_SHELL" "$as_myself" ${1+"$@"}
+  export CONFIG_SHELL
+             # We cannot yet assume a decent shell, so we have to provide a
+# neutralization value for shells without unset; and this also
+# works around shells that cannot unset nonexistent variables.
+# Preserve -v and -x to the replacement shell.
+BASH_ENV=/dev/null
+ENV=/dev/null
+(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV
+case $- in # ((((
+  *v*x* | *x*v* ) as_opts=-vx ;;
+  *v* ) as_opts=-v ;;
+  *x* ) as_opts=-x ;;
+  * ) as_opts= ;;
+esac
+exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"}
+# Admittedly, this is quite paranoid, since all the known shells bail
+# out after a failed `exec'.
+$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2
+exit 255
 fi
 
     if test x$as_have_required = xno; then :
@@ -324,6 +368,14 @@ $as_echo X"$as_dir" |
 
 
 } # as_fn_mkdir_p
+
+# as_fn_executable_p FILE
+# -----------------------
+# Test if FILE is an executable regular file.
+as_fn_executable_p ()
+{
+  test -f "$1" && test -x "$1"
+} # as_fn_executable_p
 # as_fn_append VAR VALUE
 # ----------------------
 # Append the text in VALUE to the end of the definition contained in VAR. Take
@@ -445,6 +497,10 @@ as_cr_alnum=$as_cr_Letters$as_cr_digits
   chmod +x "$as_me.lineno" ||
     { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; }
 
+  # If we had to re-execute with $CONFIG_SHELL, we're ensured to have
+  # already done that, so ensure we don't try to do so again and fall
+  # in an infinite loop.  This has already happened in practice.
+  _as_can_reexec=no; export _as_can_reexec
   # Don't try to exec as it changes $[0], causing all sort of problems
   # (the dirname of $[0] is not the place where we might find the
   # original and so on.  Autoconf is especially sensitive to this).
@@ -479,16 +535,16 @@ if (echo >conf$$.file) 2>/dev/null; then
     # ... but there are two gotchas:
     # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.
     # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.
-    # In both cases, we have to default to `cp -p'.
+    # In both cases, we have to default to `cp -pR'.
     ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||
-      as_ln_s='cp -p'
+      as_ln_s='cp -pR'
   elif ln conf$$.file conf$$ 2>/dev/null; then
     as_ln_s=ln
   else
-    as_ln_s='cp -p'
+    as_ln_s='cp -pR'
   fi
 else
-  as_ln_s='cp -p'
+  as_ln_s='cp -pR'
 fi
 rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file
 rmdir conf$$.dir 2>/dev/null
@@ -500,28 +556,8 @@ else
   as_mkdir_p=false
 fi
 
-if test -x / >/dev/null 2>&1; then
-  as_test_x='test -x'
-else
-  if ls -dL / >/dev/null 2>&1; then
-    as_ls_L_option=L
-  else
-    as_ls_L_option=
-  fi
-  as_test_x='
-    eval sh -c '\''
-      if test -d "$1"; then
-       test -d "$1/.";
-      else
-       case $1 in #(
-       -*)set "./$1";;
-       esac;
-       case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #((
-       ???[sx]*):;;*)false;;esac;fi
-    '\'' sh
-  '
-fi
-as_executable_p=$as_test_x
+as_test_x='test -x'
+as_executable_p=as_fn_executable_p
 
 # Sed expression to map a string onto a valid CPP name.
 as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
@@ -529,155 +565,8 @@ as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
 # Sed expression to map a string onto a valid variable name.
 as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'"
 
-
-
-# Check that we are running under the correct shell.
 SHELL=${CONFIG_SHELL-/bin/sh}
 
-case X$lt_ECHO in
-X*--fallback-echo)
-  # Remove one level of quotation (which was required for Make).
-  ECHO=`echo "$lt_ECHO" | sed 's,\\\\\$\\$0,'$0','`
-  ;;
-esac
-
-ECHO=${lt_ECHO-echo}
-if test "X$1" = X--no-reexec; then
-  # Discard the --no-reexec flag, and continue.
-  shift
-elif test "X$1" = X--fallback-echo; then
-  # Avoid inline document here, it may be left over
-  :
-elif test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t' ; then
-  # Yippee, $ECHO works!
-  :
-else
-  # Restart under the correct shell.
-  exec $SHELL "$0" --no-reexec ${1+"$@"}
-fi
-
-if test "X$1" = X--fallback-echo; then
-  # used as fallback echo
-  shift
-  cat <<_LT_EOF
-$*
-_LT_EOF
-  exit 0
-fi
-
-# The HP-UX ksh and POSIX shell print the target directory to stdout
-# if CDPATH is set.
-(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
-
-if test -z "$lt_ECHO"; then
-  if test "X${echo_test_string+set}" != Xset; then
-    # find a string as large as possible, as long as the shell can cope with it
-    for cmd in 'sed 50q "$0"' 'sed 20q "$0"' 'sed 10q "$0"' 'sed 2q "$0"' 'echo test'; do
-      # expected sizes: less than 2Kb, 1Kb, 512 bytes, 16 bytes, ...
-      if { echo_test_string=`eval $cmd`; } 2>/dev/null &&
-        { test "X$echo_test_string" = "X$echo_test_string"; } 2>/dev/null
-      then
-        break
-      fi
-    done
-  fi
-
-  if test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t' &&
-     echo_testing_string=`{ $ECHO "$echo_test_string"; } 2>/dev/null` &&
-     test "X$echo_testing_string" = "X$echo_test_string"; then
-    :
-  else
-    # The Solaris, AIX, and Digital Unix default echo programs unquote
-    # backslashes.  This makes it impossible to quote backslashes using
-    #   echo "$something" | sed 's/\\/\\\\/g'
-    #
-    # So, first we look for a working echo in the user's PATH.
-
-    lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
-    for dir in $PATH /usr/ucb; do
-      IFS="$lt_save_ifs"
-      if (test -f $dir/echo || test -f $dir/echo$ac_exeext) &&
-         test "X`($dir/echo '\t') 2>/dev/null`" = 'X\t' &&
-         echo_testing_string=`($dir/echo "$echo_test_string") 2>/dev/null` &&
-         test "X$echo_testing_string" = "X$echo_test_string"; then
-        ECHO="$dir/echo"
-        break
-      fi
-    done
-    IFS="$lt_save_ifs"
-
-    if test "X$ECHO" = Xecho; then
-      # We didn't find a better echo, so look for alternatives.
-      if test "X`{ print -r '\t'; } 2>/dev/null`" = 'X\t' &&
-         echo_testing_string=`{ print -r "$echo_test_string"; } 2>/dev/null` &&
-         test "X$echo_testing_string" = "X$echo_test_string"; then
-        # This shell has a builtin print -r that does the trick.
-        ECHO='print -r'
-      elif { test -f /bin/ksh || test -f /bin/ksh$ac_exeext; } &&
-          test "X$CONFIG_SHELL" != X/bin/ksh; then
-        # If we have ksh, try running configure again with it.
-        ORIGINAL_CONFIG_SHELL=${CONFIG_SHELL-/bin/sh}
-        export ORIGINAL_CONFIG_SHELL
-        CONFIG_SHELL=/bin/ksh
-        export CONFIG_SHELL
-        exec $CONFIG_SHELL "$0" --no-reexec ${1+"$@"}
-      else
-        # Try using printf.
-        ECHO='printf %s\n'
-        if test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t' &&
-          echo_testing_string=`{ $ECHO "$echo_test_string"; } 2>/dev/null` &&
-          test "X$echo_testing_string" = "X$echo_test_string"; then
-         # Cool, printf works
-         :
-        elif echo_testing_string=`($ORIGINAL_CONFIG_SHELL "$0" --fallback-echo '\t') 2>/dev/null` &&
-            test "X$echo_testing_string" = 'X\t' &&
-            echo_testing_string=`($ORIGINAL_CONFIG_SHELL "$0" --fallback-echo "$echo_test_string") 2>/dev/null` &&
-            test "X$echo_testing_string" = "X$echo_test_string"; then
-         CONFIG_SHELL=$ORIGINAL_CONFIG_SHELL
-         export CONFIG_SHELL
-         SHELL="$CONFIG_SHELL"
-         export SHELL
-         ECHO="$CONFIG_SHELL $0 --fallback-echo"
-        elif echo_testing_string=`($CONFIG_SHELL "$0" --fallback-echo '\t') 2>/dev/null` &&
-            test "X$echo_testing_string" = 'X\t' &&
-            echo_testing_string=`($CONFIG_SHELL "$0" --fallback-echo "$echo_test_string") 2>/dev/null` &&
-            test "X$echo_testing_string" = "X$echo_test_string"; then
-         ECHO="$CONFIG_SHELL $0 --fallback-echo"
-        else
-         # maybe with a smaller string...
-         prev=:
-
-         for cmd in 'echo test' 'sed 2q "$0"' 'sed 10q "$0"' 'sed 20q "$0"' 'sed 50q "$0"'; do
-           if { test "X$echo_test_string" = "X`eval $cmd`"; } 2>/dev/null
-           then
-             break
-           fi
-           prev="$cmd"
-         done
-
-         if test "$prev" != 'sed 50q "$0"'; then
-           echo_test_string=`eval $prev`
-           export echo_test_string
-           exec ${ORIGINAL_CONFIG_SHELL-${CONFIG_SHELL-/bin/sh}} "$0" ${1+"$@"}
-         else
-           # Oops.  We lost completely, so just stick with echo.
-           ECHO=echo
-         fi
-        fi
-      fi
-    fi
-  fi
-fi
-
-# Copy echo and quote the copy suitably for passing to libtool from
-# the Makefile, instead of quoting the original, which is used later.
-lt_ECHO=$ECHO
-if test "X$lt_ECHO" = "X$CONFIG_SHELL $0 --fallback-echo"; then
-   lt_ECHO="$CONFIG_SHELL \\\$\$0 --fallback-echo"
-fi
-
-
-
 
 test -n "$DJDIR" || exec 7<&0 </dev/null
 exec 6>&1
@@ -702,8 +591,8 @@ MAKEFLAGS=
 # Identity of this package.
 PACKAGE_NAME='xf86-video-intel'
 PACKAGE_TARNAME='xf86-video-intel'
-PACKAGE_VERSION='2.15.0'
-PACKAGE_STRING='xf86-video-intel 2.15.0'
+PACKAGE_VERSION='2.20.9'
+PACKAGE_STRING='xf86-video-intel 2.20.9'
 PACKAGE_BUGREPORT='https://bugs.freedesktop.org/enter_bug.cgi?product=xorg'
 PACKAGE_URL=''
 
@@ -750,36 +639,76 @@ LTLIBOBJS
 LIBOBJS
 moduledir
 DRIVER_NAME
+VALGRIND_LIBS
+VALGRIND_CFLAGS
+FULL_DEBUG_FALSE
+FULL_DEBUG_TRUE
+DEBUG_FALSE
+DEBUG_TRUE
+UMS_ONLY_FALSE
+UMS_ONLY_TRUE
 KMS_ONLY_FALSE
 KMS_ONLY_TRUE
 XVMC_FALSE
 XVMC_TRUE
 XVMCLIB_LIBS
 XVMCLIB_CFLAGS
-DRI_LIBS
-DRI_CFLAGS
+DRI2_FALSE
+DRI2_TRUE
 DRI_FALSE
 DRI_TRUE
 PCIACCESS_LIBS
 PCIACCESS_CFLAGS
+DRI2_LIBS
+DRI2_CFLAGS
+DRI_LIBS
+DRI_CFLAGS
 DRM_LIBS
 DRM_CFLAGS
+USE_ASYNC_SWAP_FALSE
+USE_ASYNC_SWAP_TRUE
+USE_USERPTR_FALSE
+USE_USERPTR_TRUE
+DGA_FALSE
+DGA_TRUE
+XAA_FALSE
+XAA_TRUE
 XORG_LIBS
 XORG_CFLAGS
+LIBGLAMOR_EGL_LIBS
+LIBGLAMOR_EGL_CFLAGS
+LIBGLAMOR_LIBS
+LIBGLAMOR_CFLAGS
+GLAMOR_FALSE
+GLAMOR_TRUE
+DRMINTEL_LIBS
+DRMINTEL_CFLAGS
+UXA_FALSE
+UXA_TRUE
+SNA_FALSE
+SNA_TRUE
+HAVE_X11_FALSE
+HAVE_X11_TRUE
+X11_LIBS
+X11_CFLAGS
 UDEV_LIBS
 UDEV_CFLAGS
 HAVE_GEN4ASM_FALSE
 HAVE_GEN4ASM_TRUE
 GEN4ASM_LIBS
 GEN4ASM_CFLAGS
+HAVE_DOT_GIT_FALSE
+HAVE_DOT_GIT_TRUE
 OTOOL64
 OTOOL
 LIPO
 NMEDIT
 DSYMUTIL
-lt_ECHO
+MANIFEST_TOOL
 RANLIB
+ac_ct_AR
 AR
+DLLTOOL
 OBJDUMP
 LN_S
 NM
@@ -788,6 +717,10 @@ DUMPBIN
 LD
 FGREP
 LIBTOOL
+AM_BACKSLASH
+AM_DEFAULT_VERBOSITY
+AM_DEFAULT_V
+AM_V
 MAN_SUBSTS
 XORG_MAN_PAGE
 ADMIN_MAN_DIR
@@ -816,13 +749,16 @@ PKG_CONFIG_LIBDIR
 PKG_CONFIG_PATH
 PKG_CONFIG
 CHANGELOG_CMD
+STRICT_CFLAGS
 CWARNFLAGS
+BASE_CFLAGS
 EGREP
 GREP
 CPP
 am__fastdepCC_FALSE
 am__fastdepCC_TRUE
 CCDEPMODE
+am__nodep
 AMDEPBACKSLASH
 AMDEP_FALSE
 AMDEP_TRUE
@@ -836,8 +772,6 @@ CPPFLAGS
 LDFLAGS
 CFLAGS
 CC
-AM_BACKSLASH
-AM_DEFAULT_VERBOSITY
 MAINT
 MAINTAINER_MODE_FALSE
 MAINTAINER_MODE_TRUE
@@ -906,19 +840,33 @@ ac_subst_files=''
 ac_user_opts='
 enable_option_checking
 enable_maintainer_mode
-enable_silent_rules
 enable_dependency_tracking
+enable_selective_werror
 enable_strict_compilation
+enable_silent_rules
 enable_static
 enable_shared
 with_pic
 enable_fast_install
 with_gnu_ld
+with_sysroot
 enable_libtool_lock
+enable_largefile
+with_builderstring
+enable_udev
 with_xorg_module_dir
 enable_dri
 enable_xvmc
 enable_kms_only
+enable_ums_only
+enable_sna
+enable_uxa
+enable_glamor
+enable_xaa
+enable_dga
+with_default_accel
+enable_userptr
+enable_async_swap
 enable_debug
 '
       ac_precious_vars='build_alias
@@ -937,16 +885,28 @@ GEN4ASM_CFLAGS
 GEN4ASM_LIBS
 UDEV_CFLAGS
 UDEV_LIBS
+X11_CFLAGS
+X11_LIBS
+DRMINTEL_CFLAGS
+DRMINTEL_LIBS
+LIBGLAMOR_CFLAGS
+LIBGLAMOR_LIBS
+LIBGLAMOR_EGL_CFLAGS
+LIBGLAMOR_EGL_LIBS
 XORG_CFLAGS
 XORG_LIBS
 DRM_CFLAGS
 DRM_LIBS
-PCIACCESS_CFLAGS
-PCIACCESS_LIBS
 DRI_CFLAGS
 DRI_LIBS
+DRI2_CFLAGS
+DRI2_LIBS
+PCIACCESS_CFLAGS
+PCIACCESS_LIBS
 XVMCLIB_CFLAGS
-XVMCLIB_LIBS'
+XVMCLIB_LIBS
+VALGRIND_CFLAGS
+VALGRIND_LIBS'
 
 
 # Initialize some variables set by options.
@@ -1351,7 +1311,7 @@ Try \`$0 --help' for more information"
     $as_echo "$as_me: WARNING: you should use --build, --host, --target" >&2
     expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null &&
       $as_echo "$as_me: WARNING: invalid host type: $ac_option" >&2
-    : ${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}
+    : "${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}"
     ;;
 
   esac
@@ -1402,8 +1362,6 @@ target=$target_alias
 if test "x$host_alias" != x; then
   if test "x$build_alias" = x; then
     cross_compiling=maybe
-    $as_echo "$as_me: WARNING: if you wanted to set the --build type, don't use --host.
-    If a cross compiler is detected then cross compile mode will be used" >&2
   elif test "x$build_alias" != "x$host_alias"; then
     cross_compiling=yes
   fi
@@ -1489,7 +1447,7 @@ if test "$ac_init_help" = "long"; then
   # Omit some internal or obsolete options to make the list less imposing.
   # This message is too long to be a string in the A/UX 3.1 sh.
   cat <<_ACEOF
-\`configure' configures xf86-video-intel 2.15.0 to adapt to many kinds of systems.
+\`configure' configures xf86-video-intel 2.20.9 to adapt to many kinds of systems.
 
 Usage: $0 [OPTION]... [VAR=VALUE]...
 
@@ -1560,7 +1518,7 @@ fi
 
 if test -n "$ac_init_help"; then
   case $ac_init_help in
-     short | recursive ) echo "Configuration of xf86-video-intel 2.15.0:";;
+     short | recursive ) echo "Configuration of xf86-video-intel 2.20.9:";;
    esac
   cat <<\_ACEOF
 
@@ -1568,34 +1526,61 @@ Optional Features:
   --disable-option-checking  ignore unrecognized --enable/--with options
   --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
   --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
-  --disable-maintainer-mode  disable make rules and dependencies not useful
+  --enable-maintainer-mode  enable make rules and dependencies not useful
                          (and sometimes confusing) to the casual installer
-  --enable-silent-rules          less verbose build output (undo: `make V=1')
-  --disable-silent-rules         verbose build output (undo: `make V=0')
   --disable-dependency-tracking  speeds up one-time build
   --enable-dependency-tracking   do not reject slow dependency extractors
+  --disable-selective-werror
+                          Turn off selective compiler errors. (default:
+                          enabled)
   --enable-strict-compilation
                           Enable all warnings from compiler and make them
                           errors (default: disabled)
+  --enable-silent-rules          less verbose build output (undo: `make V=1')
+  --disable-silent-rules         verbose build output (undo: `make V=0')
   --enable-static[=PKGS]  build static libraries [default=no]
   --enable-shared[=PKGS]  build shared libraries [default=yes]
   --enable-fast-install[=PKGS]
                           optimize for fast installation [default=yes]
   --disable-libtool-lock  avoid locking (might break parallel builds)
+  --disable-largefile     omit support for large files
+  --disable-udev          Disable udev-based monitor hotplug detection
+                          [default=auto]
   --disable-dri           Disable DRI support [[default=auto]]
   --disable-xvmc          Disable XvMC support [[default=yes]]
   --enable-kms-only       Assume KMS support [[default=no]]
-  --enable-debug          Enables internal debugging [[default=yes]]
+  --enable-ums-only       Assume only UMS (no KMS) support [[default=no]]
+  --enable-sna            Enable SandyBridge's New Acceleration (SNA)
+                          [default=auto]
+  --enable-uxa            Enable Unified Acceleration Architecture (UXA)
+                          [default=yes]
+  --enable-glamor         Enable glamor, a new GL-based acceleration
+                          [default=no]
+  --enable-xaa            Enable legacy X Acceleration Architecture (XAA)
+                          [default=auto]
+  --enable-dga            Enable legacy Direct Graphics Access (DGA)
+                          [default=auto]
+  --enable-userptr        Enable use of userptr (experimental) [default=no]
+  --enable-async-swap     Enable use of asynchronous swaps (experimental)
+                          [default=no]
+  --enable-debug          Enables internal debugging [default=no]
 
 Optional Packages:
   --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
   --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
-  --with-pic              try to use only PIC/non-PIC objects [default=use
+  --with-pic[=PKGS]       try to use only PIC/non-PIC objects [default=use
                           both]
   --with-gnu-ld           assume the C compiler uses GNU ld [default=no]
+  --with-sysroot=DIR Search for dependent libraries within DIR
+                        (or the compiler's sysroot if not specified).
+  --with-builderstring=BUILDERSTRING
+                          Additional builder string (default: use git
+                          describe)
   --with-xorg-module-dir=DIR
                           Default xorg module directory
                           [[default=$libdir/xorg/modules]]
+  --with-default-accel    Select the default acceleration method [default=uxa
+                          if enabled, otherwise sna]
 
 Some influential environment variables:
   CC          C compiler command
@@ -1617,20 +1602,40 @@ Some influential environment variables:
               linker flags for GEN4ASM, overriding pkg-config
   UDEV_CFLAGS C compiler flags for UDEV, overriding pkg-config
   UDEV_LIBS   linker flags for UDEV, overriding pkg-config
+  X11_CFLAGS  C compiler flags for X11, overriding pkg-config
+  X11_LIBS    linker flags for X11, overriding pkg-config
+  DRMINTEL_CFLAGS
+              C compiler flags for DRMINTEL, overriding pkg-config
+  DRMINTEL_LIBS
+              linker flags for DRMINTEL, overriding pkg-config
+  LIBGLAMOR_CFLAGS
+              C compiler flags for LIBGLAMOR, overriding pkg-config
+  LIBGLAMOR_LIBS
+              linker flags for LIBGLAMOR, overriding pkg-config
+  LIBGLAMOR_EGL_CFLAGS
+              C compiler flags for LIBGLAMOR_EGL, overriding pkg-config
+  LIBGLAMOR_EGL_LIBS
+              linker flags for LIBGLAMOR_EGL, overriding pkg-config
   XORG_CFLAGS C compiler flags for XORG, overriding pkg-config
   XORG_LIBS   linker flags for XORG, overriding pkg-config
   DRM_CFLAGS  C compiler flags for DRM, overriding pkg-config
   DRM_LIBS    linker flags for DRM, overriding pkg-config
+  DRI_CFLAGS  C compiler flags for DRI, overriding pkg-config
+  DRI_LIBS    linker flags for DRI, overriding pkg-config
+  DRI2_CFLAGS C compiler flags for DRI2, overriding pkg-config
+  DRI2_LIBS   linker flags for DRI2, overriding pkg-config
   PCIACCESS_CFLAGS
               C compiler flags for PCIACCESS, overriding pkg-config
   PCIACCESS_LIBS
               linker flags for PCIACCESS, overriding pkg-config
-  DRI_CFLAGS  C compiler flags for DRI, overriding pkg-config
-  DRI_LIBS    linker flags for DRI, overriding pkg-config
   XVMCLIB_CFLAGS
               C compiler flags for XVMCLIB, overriding pkg-config
   XVMCLIB_LIBS
               linker flags for XVMCLIB, overriding pkg-config
+  VALGRIND_CFLAGS
+              C compiler flags for VALGRIND, overriding pkg-config
+  VALGRIND_LIBS
+              linker flags for VALGRIND, overriding pkg-config
 
 Use these variables to override the choices made by `configure' or to help
 it to find libraries and programs with nonstandard names/locations.
@@ -1698,10 +1703,10 @@ fi
 test -n "$ac_init_help" && exit $ac_status
 if $ac_init_version; then
   cat <<\_ACEOF
-xf86-video-intel configure 2.15.0
-generated by GNU Autoconf 2.67
+xf86-video-intel configure 2.20.9
+generated by GNU Autoconf 2.69
 
-Copyright (C) 2010 Free Software Foundation, Inc.
+Copyright (C) 2012 Free Software Foundation, Inc.
 This configure script is free software; the Free Software Foundation
 gives unlimited permission to copy, distribute and modify it.
 _ACEOF
@@ -1745,7 +1750,7 @@ sed 's/^/| /' conftest.$ac_ext >&5
 
        ac_retval=1
 fi
-  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
+  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
   as_fn_set_status $ac_retval
 
 } # ac_fn_c_try_compile
@@ -1761,7 +1766,7 @@ ac_fn_c_check_decl ()
   as_decl_use=`echo $2|sed -e 's/(/((/' -e 's/)/) 0&/' -e 's/,/) 0& (/g'`
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $as_decl_name is declared" >&5
 $as_echo_n "checking whether $as_decl_name is declared... " >&6; }
-if eval "test \"\${$3+set}\"" = set; then :
+if eval \${$3+:} false; then :
   $as_echo_n "(cached) " >&6
 else
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
@@ -1792,7 +1797,7 @@ fi
 eval ac_res=\$$3
               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
 $as_echo "$ac_res" >&6; }
-  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
+  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
 
 } # ac_fn_c_check_decl
 
@@ -1828,7 +1833,7 @@ sed 's/^/| /' conftest.$ac_ext >&5
 
     ac_retval=1
 fi
-  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
+  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
   as_fn_set_status $ac_retval
 
 } # ac_fn_c_try_cpp
@@ -1870,7 +1875,7 @@ sed 's/^/| /' conftest.$ac_ext >&5
        ac_retval=$ac_status
 fi
   rm -rf conftest.dSYM conftest_ipa8_conftest.oo
-  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
+  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
   as_fn_set_status $ac_retval
 
 } # ac_fn_c_try_run
@@ -1884,7 +1889,7 @@ ac_fn_c_check_header_compile ()
   as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
 $as_echo_n "checking for $2... " >&6; }
-if eval "test \"\${$3+set}\"" = set; then :
+if eval \${$3+:} false; then :
   $as_echo_n "(cached) " >&6
 else
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
@@ -1902,7 +1907,7 @@ fi
 eval ac_res=\$$3
               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
 $as_echo "$ac_res" >&6; }
-  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
+  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
 
 } # ac_fn_c_check_header_compile
 
@@ -1933,7 +1938,7 @@ $as_echo "$ac_try_echo"; } >&5
         test ! -s conftest.err
        } && test -s conftest$ac_exeext && {
         test "$cross_compiling" = yes ||
-        $as_test_x conftest$ac_exeext
+        test -x conftest$ac_exeext
        }; then :
   ac_retval=0
 else
@@ -1947,7 +1952,7 @@ fi
   # interfere with the next link command; also delete a directory that is
   # left behind by Apple's compiler.  We do this before executing the actions.
   rm -rf conftest.dSYM conftest_ipa8_conftest.oo
-  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
+  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
   as_fn_set_status $ac_retval
 
 } # ac_fn_c_try_link
@@ -1960,7 +1965,7 @@ ac_fn_c_check_func ()
   as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
 $as_echo_n "checking for $2... " >&6; }
-if eval "test \"\${$3+set}\"" = set; then :
+if eval \${$3+:} false; then :
   $as_echo_n "(cached) " >&6
 else
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 eval ac_res=\$$3
               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
 $as_echo "$ac_res" >&6; }
-  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
+  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
 
 } # ac_fn_c_check_func
+
+# ac_fn_c_check_header_mongrel LINENO HEADER VAR INCLUDES
+# -------------------------------------------------------
+# Tests whether HEADER exists, giving a warning if it cannot be compiled using
+# the include files in INCLUDES and setting the cache variable VAR
+# accordingly.
+ac_fn_c_check_header_mongrel ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  if eval \${$3+:} false; then :
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
+$as_echo_n "checking for $2... " >&6; }
+if eval \${$3+:} false; then :
+  $as_echo_n "(cached) " >&6
+fi
+eval ac_res=\$$3
+              { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+else
+  # Is the header compilable?
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 usability" >&5
+$as_echo_n "checking $2 usability... " >&6; }
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$4
+#include <$2>
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_header_compiler=yes
+else
+  ac_header_compiler=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_compiler" >&5
+$as_echo "$ac_header_compiler" >&6; }
+
+# Is the header present?
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 presence" >&5
+$as_echo_n "checking $2 presence... " >&6; }
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <$2>
+_ACEOF
+if ac_fn_c_try_cpp "$LINENO"; then :
+  ac_header_preproc=yes
+else
+  ac_header_preproc=no
+fi
+rm -f conftest.err conftest.i conftest.$ac_ext
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_preproc" >&5
+$as_echo "$ac_header_preproc" >&6; }
+
+# So?  What about this header?
+case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in #((
+  yes:no: )
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&5
+$as_echo "$as_me: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5
+$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;}
+    ;;
+  no:yes:* )
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: present but cannot be compiled" >&5
+$as_echo "$as_me: WARNING: $2: present but cannot be compiled" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2:     check for missing prerequisite headers?" >&5
+$as_echo "$as_me: WARNING: $2:     check for missing prerequisite headers?" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: see the Autoconf documentation" >&5
+$as_echo "$as_me: WARNING: $2: see the Autoconf documentation" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2:     section \"Present But Cannot Be Compiled\"" >&5
+$as_echo "$as_me: WARNING: $2:     section \"Present But Cannot Be Compiled\"" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5
+$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;}
+( $as_echo "## ---------------------------------------------------------------------- ##
+## Report this to https://bugs.freedesktop.org/enter_bug.cgi?product=xorg ##
+## ---------------------------------------------------------------------- ##"
+     ) | sed "s/^/$as_me: WARNING:     /" >&2
+    ;;
+esac
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
+$as_echo_n "checking for $2... " >&6; }
+if eval \${$3+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  eval "$3=\$ac_header_compiler"
+fi
+eval ac_res=\$$3
+              { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+fi
+  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+
+} # ac_fn_c_check_header_mongrel
 cat >config.log <<_ACEOF
 This file contains any messages produced by compilers while
 running configure, to aid debugging if configure makes a mistake.
 
-It was created by xf86-video-intel $as_me 2.15.0, which was
-generated by GNU Autoconf 2.67.  Invocation command line was
+It was created by xf86-video-intel $as_me 2.20.9, which was
+generated by GNU Autoconf 2.69.  Invocation command line was
 
   $ $0 $@
 
@@ -2281,7 +2377,7 @@ $as_echo "$as_me: loading site script $ac_site_file" >&6;}
       || { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
 as_fn_error $? "failed to load site script $ac_site_file
-See \`config.log' for more details" "$LINENO" 5 ; }
+See \`config.log' for more details" "$LINENO" 5; }
   fi
 done
 
@@ -2374,7 +2470,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
 ac_config_headers="$ac_config_headers config.h"
 
 ac_aux_dir=
-for ac_dir in build-aux "$srcdir"/build-aux; do
+for ac_dir in . "$srcdir"/.; do
   if test -f "$ac_dir/install-sh"; then
     ac_aux_dir=$ac_dir
     ac_install_sh="$ac_aux_dir/install-sh -c"
@@ -2390,7 +2486,7 @@ for ac_dir in build-aux "$srcdir"/build-aux; do
   fi
 done
 if test -z "$ac_aux_dir"; then
-  as_fn_error $? "cannot find install-sh, install.sh, or shtool in build-aux \"$srcdir\"/build-aux" "$LINENO" 5
+  as_fn_error $? "cannot find install-sh, install.sh, or shtool in . \"$srcdir\"/." "$LINENO" 5
 fi
 
 # These three variables are undocumented and unsupported,
@@ -2403,7 +2499,6 @@ ac_configure="$SHELL $ac_aux_dir/configure"  # Please don't use this var.
 
 
 
-
 # Initialize Automake
 am__api_version='1.11'
 
@@ -2424,7 +2519,7 @@ am__api_version='1.11'
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for a BSD-compatible install" >&5
 $as_echo_n "checking for a BSD-compatible install... " >&6; }
 if test -z "$INSTALL"; then
-if test "${ac_cv_path_install+set}" = set; then :
+if ${ac_cv_path_install+:} false; then :
   $as_echo_n "(cached) " >&6
 else
   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
@@ -2444,7 +2539,7 @@ case $as_dir/ in #((
     # by default.
     for ac_prog in ginstall scoinst install; do
       for ac_exec_ext in '' $ac_executable_extensions; do
-       if { test -f "$as_dir/$ac_prog$ac_exec_ext" && $as_test_x "$as_dir/$ac_prog$ac_exec_ext"; }; then
+       if as_fn_executable_p "$as_dir/$ac_prog$ac_exec_ext"; then
          if test $ac_prog = install &&
            grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then
            # AIX install.  It has an incompatible calling convention.
@@ -2511,11 +2606,11 @@ am_lf='
 '
 case `pwd` in
   *[\\\"\#\$\&\'\`$am_lf]*)
-    as_fn_error $? "unsafe absolute working directory name" "$LINENO" 5 ;;
+    as_fn_error $? "unsafe absolute working directory name" "$LINENO" 5;;
 esac
 case $srcdir in
   *[\\\"\#\$\&\'\`$am_lf\ \    ]*)
-    as_fn_error $? "unsafe srcdir value: \`$srcdir'" "$LINENO" 5 ;;
+    as_fn_error $? "unsafe srcdir value: \`$srcdir'" "$LINENO" 5;;
 esac
 
 # Do `set' in a subshell so we don't clobber the current shell's
@@ -2601,7 +2696,7 @@ if test "$cross_compiling" != no; then
 set dummy ${ac_tool_prefix}strip; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if test "${ac_cv_prog_STRIP+set}" = set; then :
+if ${ac_cv_prog_STRIP+:} false; then :
   $as_echo_n "(cached) " >&6
 else
   if test -n "$STRIP"; then
@@ -2613,7 +2708,7 @@ do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
     ac_cv_prog_STRIP="${ac_tool_prefix}strip"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
@@ -2641,7 +2736,7 @@ if test -z "$ac_cv_prog_STRIP"; then
 set dummy strip; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if test "${ac_cv_prog_ac_ct_STRIP+set}" = set; then :
+if ${ac_cv_prog_ac_ct_STRIP+:} false; then :
   $as_echo_n "(cached) " >&6
 else
   if test -n "$ac_ct_STRIP"; then
@@ -2653,7 +2748,7 @@ do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
     ac_cv_prog_ac_ct_STRIP="strip"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
@@ -2694,7 +2789,7 @@ INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s"
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for a thread-safe mkdir -p" >&5
 $as_echo_n "checking for a thread-safe mkdir -p... " >&6; }
 if test -z "$MKDIR_P"; then
-  if test "${ac_cv_path_mkdir+set}" = set; then :
+  if ${ac_cv_path_mkdir+:} false; then :
   $as_echo_n "(cached) " >&6
 else
   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
@@ -2704,7 +2799,7 @@ do
   test -z "$as_dir" && as_dir=.
     for ac_prog in mkdir gmkdir; do
         for ac_exec_ext in '' $ac_executable_extensions; do
-          { test -f "$as_dir/$ac_prog$ac_exec_ext" && $as_test_x "$as_dir/$ac_prog$ac_exec_ext"; } || continue
+          as_fn_executable_p "$as_dir/$ac_prog$ac_exec_ext" || continue
           case `"$as_dir/$ac_prog$ac_exec_ext" --version 2>&1` in #(
             'mkdir (GNU coreutils) '* | \
             'mkdir (coreutils) '* | \
@@ -2745,7 +2840,7 @@ do
 set dummy $ac_prog; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if test "${ac_cv_prog_AWK+set}" = set; then :
+if ${ac_cv_prog_AWK+:} false; then :
   $as_echo_n "(cached) " >&6
 else
   if test -n "$AWK"; then
@@ -2757,7 +2852,7 @@ do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
     ac_cv_prog_AWK="$ac_prog"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
@@ -2785,7 +2880,7 @@ done
 $as_echo_n "checking whether ${MAKE-make} sets \$(MAKE)... " >&6; }
 set x ${MAKE-make}
 ac_make=`$as_echo "$2" | sed 's/+/p/g; s/[^a-zA-Z0-9_]/_/g'`
-if eval "test \"\${ac_cv_prog_make_${ac_make}_set+set}\"" = set; then :
+if eval \${ac_cv_prog_make_${ac_make}_set+:} false; then :
   $as_echo_n "(cached) " >&6
 else
   cat >conftest.make <<\_ACEOF
@@ -2843,7 +2938,7 @@ fi
 
 # Define the identity of the package.
  PACKAGE='xf86-video-intel'
- VERSION='2.15.0'
+ VERSION='2.20.9'
 
 
 cat >>confdefs.h <<_ACEOF
@@ -2873,24 +2968,24 @@ MAKEINFO=${MAKEINFO-"${am_missing_run}makeinfo"}
 
 # We need awk for the "check" target.  The system "awk" is bad on
 # some platforms.
-# Always define AMTAR for backward compatibility.
+# Always define AMTAR for backward compatibility.  Yes, it's still used
+# in the wild :-(  We should find a proper way to deprecate it ...
+AMTAR='$${TAR-tar}'
 
-AMTAR=${AMTAR-"${am_missing_run}tar"}
+am__tar='$${TAR-tar} chof - "$$tardir"' am__untar='$${TAR-tar} xf -'
 
-am__tar='${AMTAR} chof - "$$tardir"'; am__untar='${AMTAR} xf -'
 
 
 
 
 
-
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to disable maintainer-specific portions of Makefiles" >&5
-$as_echo_n "checking whether to disable maintainer-specific portions of Makefiles... " >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable maintainer-specific portions of Makefiles" >&5
+$as_echo_n "checking whether to enable maintainer-specific portions of Makefiles... " >&6; }
     # Check whether --enable-maintainer-mode was given.
 if test "${enable_maintainer_mode+set}" = set; then :
   enableval=$enable_maintainer_mode; USE_MAINTAINER_MODE=$enableval
 else
-  USE_MAINTAINER_MODE=yes
+  USE_MAINTAINER_MODE=no
 fi
 
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: $USE_MAINTAINER_MODE" >&5
@@ -2907,22 +3002,6 @@ fi
 
 
 
-# Support silent build rules, requires at least automake-1.11. Disable
-# by either passing --disable-silent-rules to configure or passing V=1
-# to make
-# Check whether --enable-silent-rules was given.
-if test "${enable_silent_rules+set}" = set; then :
-  enableval=$enable_silent_rules;
-fi
-
-case $enable_silent_rules in
-yes) AM_DEFAULT_VERBOSITY=0;;
-no)  AM_DEFAULT_VERBOSITY=1;;
-*)   AM_DEFAULT_VERBOSITY=0;;
-esac
-AM_BACKSLASH='\'
-
-
 # Require X.Org macros 1.8 or later for MAN_SUBSTS set by XORG_MANPAGE_SECTIONS
 
 
@@ -2988,6 +3067,7 @@ fi
 if test "x$enable_dependency_tracking" != xno; then
   am_depcomp="$ac_aux_dir/depcomp"
   AMDEPBACKSLASH='\'
+  am__nodep='_no'
 fi
  if test "x$enable_dependency_tracking" != xno; then
   AMDEP_TRUE=
@@ -3008,7 +3088,7 @@ if test -n "$ac_tool_prefix"; then
 set dummy ${ac_tool_prefix}gcc; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if test "${ac_cv_prog_CC+set}" = set; then :
+if ${ac_cv_prog_CC+:} false; then :
   $as_echo_n "(cached) " >&6
 else
   if test -n "$CC"; then
@@ -3020,7 +3100,7 @@ do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
     ac_cv_prog_CC="${ac_tool_prefix}gcc"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
@@ -3048,7 +3128,7 @@ if test -z "$ac_cv_prog_CC"; then
 set dummy gcc; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if test "${ac_cv_prog_ac_ct_CC+set}" = set; then :
+if ${ac_cv_prog_ac_ct_CC+:} false; then :
   $as_echo_n "(cached) " >&6
 else
   if test -n "$ac_ct_CC"; then
@@ -3060,7 +3140,7 @@ do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
     ac_cv_prog_ac_ct_CC="gcc"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
@@ -3101,7 +3181,7 @@ if test -z "$CC"; then
 set dummy ${ac_tool_prefix}cc; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if test "${ac_cv_prog_CC+set}" = set; then :
+if ${ac_cv_prog_CC+:} false; then :
   $as_echo_n "(cached) " >&6
 else
   if test -n "$CC"; then
@@ -3113,7 +3193,7 @@ do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
     ac_cv_prog_CC="${ac_tool_prefix}cc"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
@@ -3141,7 +3221,7 @@ if test -z "$CC"; then
 set dummy cc; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if test "${ac_cv_prog_CC+set}" = set; then :
+if ${ac_cv_prog_CC+:} false; then :
   $as_echo_n "(cached) " >&6
 else
   if test -n "$CC"; then
@@ -3154,7 +3234,7 @@ do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
     if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then
        ac_prog_rejected=yes
        continue
@@ -3200,7 +3280,7 @@ if test -z "$CC"; then
 set dummy $ac_tool_prefix$ac_prog; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if test "${ac_cv_prog_CC+set}" = set; then :
+if ${ac_cv_prog_CC+:} false; then :
   $as_echo_n "(cached) " >&6
 else
   if test -n "$CC"; then
@@ -3212,7 +3292,7 @@ do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
     ac_cv_prog_CC="$ac_tool_prefix$ac_prog"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
@@ -3244,7 +3324,7 @@ do
 set dummy $ac_prog; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if test "${ac_cv_prog_ac_ct_CC+set}" = set; then :
+if ${ac_cv_prog_ac_ct_CC+:} false; then :
   $as_echo_n "(cached) " >&6
 else
   if test -n "$ac_ct_CC"; then
@@ -3256,7 +3336,7 @@ do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
     ac_cv_prog_ac_ct_CC="$ac_prog"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
@@ -3299,7 +3379,7 @@ fi
 test -z "$CC" && { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
 as_fn_error $? "no acceptable C compiler found in \$PATH
-See \`config.log' for more details" "$LINENO" 5 ; }
+See \`config.log' for more details" "$LINENO" 5; }
 
 # Provide some information about the compiler.
 $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5
@@ -3414,7 +3494,7 @@ sed 's/^/| /' conftest.$ac_ext >&5
 { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
 as_fn_error 77 "C compiler cannot create executables
-See \`config.log' for more details" "$LINENO" 5 ; }
+See \`config.log' for more details" "$LINENO" 5; }
 else
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
 $as_echo "yes" >&6; }
@@ -3457,7 +3537,7 @@ else
   { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
 as_fn_error $? "cannot compute suffix of executables: cannot compile and link
-See \`config.log' for more details" "$LINENO" 5 ; }
+See \`config.log' for more details" "$LINENO" 5; }
 fi
 rm -f conftest conftest$ac_cv_exeext
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5
@@ -3516,7 +3596,7 @@ $as_echo "$ac_try_echo"; } >&5
 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
 as_fn_error $? "cannot run C compiled programs.
 If you meant to cross compile, use \`--host'.
-See \`config.log' for more details" "$LINENO" 5 ; }
+See \`config.log' for more details" "$LINENO" 5; }
     fi
   fi
 fi
@@ -3527,7 +3607,7 @@ rm -f conftest.$ac_ext conftest$ac_cv_exeext conftest.out
 ac_clean_files=$ac_clean_files_save
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5
 $as_echo_n "checking for suffix of object files... " >&6; }
-if test "${ac_cv_objext+set}" = set; then :
+if ${ac_cv_objext+:} false; then :
   $as_echo_n "(cached) " >&6
 else
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
@@ -3568,7 +3648,7 @@ sed 's/^/| /' conftest.$ac_ext >&5
 { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
 as_fn_error $? "cannot compute suffix of object files: cannot compile
-See \`config.log' for more details" "$LINENO" 5 ; }
+See \`config.log' for more details" "$LINENO" 5; }
 fi
 rm -f conftest.$ac_cv_objext conftest.$ac_ext
 fi
@@ -3578,7 +3658,7 @@ OBJEXT=$ac_cv_objext
 ac_objext=$OBJEXT
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C compiler" >&5
 $as_echo_n "checking whether we are using the GNU C compiler... " >&6; }
-if test "${ac_cv_c_compiler_gnu+set}" = set; then :
+if ${ac_cv_c_compiler_gnu+:} false; then :
   $as_echo_n "(cached) " >&6
 else
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
@@ -3615,7 +3695,7 @@ ac_test_CFLAGS=${CFLAGS+set}
 ac_save_CFLAGS=$CFLAGS
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5
 $as_echo_n "checking whether $CC accepts -g... " >&6; }
-if test "${ac_cv_prog_cc_g+set}" = set; then :
+if ${ac_cv_prog_cc_g+:} false; then :
   $as_echo_n "(cached) " >&6
 else
   ac_save_c_werror_flag=$ac_c_werror_flag
@@ -3693,7 +3773,7 @@ else
 fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C89" >&5
 $as_echo_n "checking for $CC option to accept ISO C89... " >&6; }
-if test "${ac_cv_prog_cc_c89+set}" = set; then :
+if ${ac_cv_prog_cc_c89+:} false; then :
   $as_echo_n "(cached) " >&6
 else
   ac_cv_prog_cc_c89=no
@@ -3702,8 +3782,7 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 #include <stdarg.h>
 #include <stdio.h>
-#include <sys/types.h>
-#include <sys/stat.h>
+struct stat;
 /* Most of the following tests are stolen from RCS 5.7's src/conf.sh.  */
 struct buf { int x; };
 FILE * (*rcsopen) (struct buf *, struct stat *, int);
@@ -3792,7 +3871,7 @@ depcc="$CC"   am_compiler_list=
 
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking dependency style of $depcc" >&5
 $as_echo_n "checking dependency style of $depcc... " >&6; }
-if test "${am_cv_CC_dependencies_compiler_type+set}" = set; then :
+if ${am_cv_CC_dependencies_compiler_type+:} false; then :
   $as_echo_n "(cached) " >&6
 else
   if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then
@@ -3801,6 +3880,7 @@ else
   # instance it was reported that on HP-UX the gcc test will end up
   # making a dummy file named `D' -- because `-MD' means `put the output
   # in D'.
+  rm -rf conftest.dir
   mkdir conftest.dir
   # Copy depcomp to subdir because otherwise we won't find it if we're
   # using a relative directory.
@@ -3860,7 +3940,7 @@ else
        break
       fi
       ;;
-    msvisualcpp | msvcmsys)
+    msvc7 | msvc7msys | msvisualcpp | msvcmsys)
       # This compiler won't grok `-c -o', but also, the minuso test has
       # not run yet.  These depmodes are late enough in the game, and
       # so weak that their functioning should not be impacted.
@@ -3917,7 +3997,7 @@ fi
 
    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C99" >&5
 $as_echo_n "checking for $CC option to accept ISO C99... " >&6; }
-if test "${ac_cv_prog_cc_c99+set}" = set; then :
+if ${ac_cv_prog_cc_c99+:} false; then :
   $as_echo_n "(cached) " >&6
 else
   ac_cv_prog_cc_c99=no
@@ -4061,7 +4141,7 @@ main ()
   return 0;
 }
 _ACEOF
-for ac_arg in '' -std=gnu99 -std=c99 -c99 -AC99 -xc99=all -qlanglvl=extc99
+for ac_arg in '' -std=gnu99 -std=c99 -c99 -AC99 -D_STDC_C99= -qlanglvl=extc99
 do
   CC="$ac_save_CC $ac_arg"
   if ac_fn_c_try_compile "$LINENO"; then :
@@ -4105,7 +4185,7 @@ if test -n "$CPP" && test -d "$CPP"; then
   CPP=
 fi
 if test -z "$CPP"; then
-  if test "${ac_cv_prog_CPP+set}" = set; then :
+  if ${ac_cv_prog_CPP+:} false; then :
   $as_echo_n "(cached) " >&6
 else
       # Double quotes because CPP needs to be expanded
@@ -4221,7 +4301,7 @@ else
   { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
 as_fn_error $? "C preprocessor \"$CPP\" fails sanity check
-See \`config.log' for more details" "$LINENO" 5 ; }
+See \`config.log' for more details" "$LINENO" 5; }
 fi
 
 ac_ext=c
@@ -4233,7 +4313,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
 
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5
 $as_echo_n "checking for grep that handles long lines and -e... " >&6; }
-if test "${ac_cv_path_GREP+set}" = set; then :
+if ${ac_cv_path_GREP+:} false; then :
   $as_echo_n "(cached) " >&6
 else
   if test -z "$GREP"; then
@@ -4247,7 +4327,7 @@ do
     for ac_prog in grep ggrep; do
     for ac_exec_ext in '' $ac_executable_extensions; do
       ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext"
-      { test -f "$ac_path_GREP" && $as_test_x "$ac_path_GREP"; } || continue
+      as_fn_executable_p "$ac_path_GREP" || continue
 # Check for GNU ac_path_GREP and select it if it is found.
   # Check for GNU $ac_path_GREP
 case `"$ac_path_GREP" --version 2>&1` in
@@ -4296,7 +4376,7 @@ $as_echo "$ac_cv_path_GREP" >&6; }
 
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for egrep" >&5
 $as_echo_n "checking for egrep... " >&6; }
-if test "${ac_cv_path_EGREP+set}" = set; then :
+if ${ac_cv_path_EGREP+:} false; then :
   $as_echo_n "(cached) " >&6
 else
   if echo a | $GREP -E '(a|b)' >/dev/null 2>&1
@@ -4313,7 +4393,7 @@ do
     for ac_prog in egrep; do
     for ac_exec_ext in '' $ac_executable_extensions; do
       ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext"
-      { test -f "$ac_path_EGREP" && $as_test_x "$ac_path_EGREP"; } || continue
+      as_fn_executable_p "$ac_path_EGREP" || continue
 # Check for GNU ac_path_EGREP and select it if it is found.
   # Check for GNU $ac_path_EGREP
 case `"$ac_path_EGREP" --version 2>&1` in
@@ -4363,7 +4443,7 @@ $as_echo "$ac_cv_path_EGREP" >&6; }
 
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5
 $as_echo_n "checking for ANSI C header files... " >&6; }
-if test "${ac_cv_header_stdc+set}" = set; then :
+if ${ac_cv_header_stdc+:} false; then :
   $as_echo_n "(cached) " >&6
 else
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
@@ -4494,6 +4574,33 @@ done
 
 
 
+ac_fn_c_check_decl "$LINENO" "__clang__" "ac_cv_have_decl___clang__" "$ac_includes_default"
+if test "x$ac_cv_have_decl___clang__" = xyes; then :
+  CLANGCC="yes"
+else
+  CLANGCC="no"
+fi
+
+ac_fn_c_check_decl "$LINENO" "__INTEL_COMPILER" "ac_cv_have_decl___INTEL_COMPILER" "$ac_includes_default"
+if test "x$ac_cv_have_decl___INTEL_COMPILER" = xyes; then :
+  INTELCC="yes"
+else
+  INTELCC="no"
+fi
+
+ac_fn_c_check_decl "$LINENO" "__SUNPRO_C" "ac_cv_have_decl___SUNPRO_C" "$ac_includes_default"
+if test "x$ac_cv_have_decl___SUNPRO_C" = xyes; then :
+  SUNCC="yes"
+else
+  SUNCC="no"
+fi
+
+
+
+
+
+
+
 
 
 if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
@@ -4502,7 +4609,7 @@ if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
 set dummy ${ac_tool_prefix}pkg-config; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if test "${ac_cv_path_PKG_CONFIG+set}" = set; then :
+if ${ac_cv_path_PKG_CONFIG+:} false; then :
   $as_echo_n "(cached) " >&6
 else
   case $PKG_CONFIG in
@@ -4516,7 +4623,7 @@ do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
     ac_cv_path_PKG_CONFIG="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
@@ -4545,7 +4652,7 @@ if test -z "$ac_cv_path_PKG_CONFIG"; then
 set dummy pkg-config; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if test "${ac_cv_path_ac_pt_PKG_CONFIG+set}" = set; then :
+if ${ac_cv_path_ac_pt_PKG_CONFIG+:} false; then :
   $as_echo_n "(cached) " >&6
 else
   case $ac_pt_PKG_CONFIG in
@@ -4559,7 +4666,7 @@ do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
     ac_cv_path_ac_pt_PKG_CONFIG="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
@@ -4615,7 +4722,7 @@ $SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 ||
 
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking build system type" >&5
 $as_echo_n "checking build system type... " >&6; }
-if test "${ac_cv_build+set}" = set; then :
+if ${ac_cv_build+:} false; then :
   $as_echo_n "(cached) " >&6
 else
   ac_build_alias=$build_alias
@@ -4631,7 +4738,7 @@ fi
 $as_echo "$ac_cv_build" >&6; }
 case $ac_cv_build in
 *-*-*) ;;
-*) as_fn_error $? "invalid value of canonical build" "$LINENO" 5 ;;
+*) as_fn_error $? "invalid value of canonical build" "$LINENO" 5;;
 esac
 build=$ac_cv_build
 ac_save_IFS=$IFS; IFS='-'
@@ -4649,7 +4756,7 @@ case $build_os in *\ *) build_os=`echo "$build_os" | sed 's/ /-/g'`;; esac
 
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking host system type" >&5
 $as_echo_n "checking host system type... " >&6; }
-if test "${ac_cv_host+set}" = set; then :
+if ${ac_cv_host+:} false; then :
   $as_echo_n "(cached) " >&6
 else
   if test "x$host_alias" = x; then
@@ -4664,7 +4771,7 @@ fi
 $as_echo "$ac_cv_host" >&6; }
 case $ac_cv_host in
 *-*-*) ;;
-*) as_fn_error $? "invalid value of canonical host" "$LINENO" 5 ;;
+*) as_fn_error $? "invalid value of canonical host" "$LINENO" 5;;
 esac
 host=$ac_cv_host
 ac_save_IFS=$IFS; IFS='-'
@@ -4682,7 +4789,7 @@ case $host_os in *\ *) host_os=`echo "$host_os" | sed 's/ /-/g'`;; esac
 
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for a sed that does not truncate output" >&5
 $as_echo_n "checking for a sed that does not truncate output... " >&6; }
-if test "${ac_cv_path_SED+set}" = set; then :
+if ${ac_cv_path_SED+:} false; then :
   $as_echo_n "(cached) " >&6
 else
             ac_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
@@ -4702,7 +4809,7 @@ do
     for ac_prog in sed gsed; do
     for ac_exec_ext in '' $ac_executable_extensions; do
       ac_path_SED="$as_dir/$ac_prog$ac_exec_ext"
-      { test -f "$ac_path_SED" && $as_test_x "$ac_path_SED"; } || continue
+      as_fn_executable_p "$ac_path_SED" || continue
 # Check for GNU ac_path_SED and select it if it is found.
   # Check for GNU $ac_path_SED
 case `"$ac_path_SED" --version 2>&1` in
@@ -4753,165 +4860,145 @@ $as_echo "$ac_cv_path_SED" >&6; }
 
 
 
-if  test "x$GCC" = xyes ; then
-    CWARNFLAGS="-Wall -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes \
--Wmissing-declarations -Wnested-externs -fno-strict-aliasing \
--Wbad-function-cast -Wformat=2"
-    case `$CC -dumpversion` in
-    3.4.* | 4.*)
-       CWARNFLAGS="$CWARNFLAGS -Wold-style-definition -Wdeclaration-after-statement"
-       ;;
-    esac
-else
-    ac_fn_c_check_decl "$LINENO" "__SUNPRO_C" "ac_cv_have_decl___SUNPRO_C" "$ac_includes_default"
-if test "x$ac_cv_have_decl___SUNPRO_C" = x""yes; then :
-  SUNCC="yes"
-else
-  SUNCC="no"
-fi
 
-    if test "x$SUNCC" = "xyes"; then
-       CWARNFLAGS="-v"
-    fi
+# Check whether --enable-selective-werror was given.
+if test "${enable_selective_werror+set}" = set; then :
+  enableval=$enable_selective_werror; SELECTIVE_WERROR=$enableval
+else
+  SELECTIVE_WERROR=yes
 fi
 
 
 
-# If the module's configure.ac calls AC_PROG_CC later on, CC gets set to C89
-
-
-
-# Check whether --enable-strict-compilation was given.
-if test "${enable_strict_compilation+set}" = set; then :
-  enableval=$enable_strict_compilation; STRICT_COMPILE=$enableval
-else
-  STRICT_COMPILE=no
-fi
 
-if test "x$STRICT_COMPILE" = "xyes"; then
-       ac_fn_c_check_decl "$LINENO" "__SUNPRO_C" "ac_cv_have_decl___SUNPRO_C" "$ac_includes_default"
-if test "x$ac_cv_have_decl___SUNPRO_C" = x""yes; then :
-  SUNCC="yes"
-else
-  SUNCC="no"
-fi
 
-       ac_fn_c_check_decl "$LINENO" "__INTEL_COMPILER" "ac_cv_have_decl___INTEL_COMPILER" "$ac_includes_default"
-if test "x$ac_cv_have_decl___INTEL_COMPILER" = x""yes; then :
-  INTELCC="yes"
+# -v is too short to test reliably with XORG_TESTSET_CFLAG
+if test "x$SUNCC" = "xyes"; then
+    BASE_CFLAGS="-v"
 else
-  INTELCC="no"
+    BASE_CFLAGS=""
 fi
 
-       if test "x$GCC" = xyes ; then
-               STRICT_CFLAGS="-pedantic -Werror"
-       elif test "x$SUNCC" = "xyes"; then
-               STRICT_CFLAGS="-errwarn"
-    elif test "x$INTELCC" = "xyes"; then
-               STRICT_CFLAGS="-Werror"
-       fi
-fi
-CWARNFLAGS="$CWARNFLAGS $STRICT_CFLAGS"
+# This chunk of warnings were those that existed in the legacy CWARNFLAGS
 
 
 
 
-cat >>confdefs.h <<_ACEOF
-#define PACKAGE_VERSION_MAJOR `echo $PACKAGE_VERSION | cut -d . -f 1`
-_ACEOF
 
-       PVM=`echo $PACKAGE_VERSION | cut -d . -f 2 | cut -d - -f 1`
-       if test "x$PVM" = "x"; then
-               PVM="0"
-       fi
 
-cat >>confdefs.h <<_ACEOF
-#define PACKAGE_VERSION_MINOR $PVM
-_ACEOF
 
-       PVP=`echo $PACKAGE_VERSION | cut -d . -f 3 | cut -d - -f 1`
-       if test "x$PVP" = "x"; then
-               PVP="0"
-       fi
 
-cat >>confdefs.h <<_ACEOF
-#define PACKAGE_VERSION_PATCHLEVEL $PVP
-_ACEOF
 
 
 
-CHANGELOG_CMD="(GIT_DIR=\$(top_srcdir)/.git git log > \$(top_srcdir)/.changelog.tmp && \
-mv \$(top_srcdir)/.changelog.tmp \$(top_srcdir)/ChangeLog) \
-|| (rm -f \$(top_srcdir)/.changelog.tmp; touch \$(top_srcdir)/ChangeLog; \
-echo 'git directory not found: installing possibly empty changelog.' >&2)"
 
 
+xorg_testset_save_CFLAGS="$CFLAGS"
 
+if test "x$xorg_testset_cc_unknown_warning_option" = "x" ; then
+       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unknown-warning-option" >&5
+$as_echo_n "checking if $CC supports -Werror=unknown-warning-option... " >&6; }
+if ${xorg_cv_cc_flag_unknown_warning_option+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unknown_warning_option=yes
+else
+  xorg_cv_cc_flag_unknown_warning_option=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unknown_warning_option" >&5
+$as_echo "$xorg_cv_cc_flag_unknown_warning_option" >&6; }
+       xorg_testset_cc_unknown_warning_option=$xorg_cv_cc_flag_unknown_warning_option
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
 
-macros_datadir=`$PKG_CONFIG --print-errors --variable=pkgdatadir xorg-macros`
-INSTALL_CMD="(cp -f "$macros_datadir/INSTALL" \$(top_srcdir)/.INSTALL.tmp && \
-mv \$(top_srcdir)/.INSTALL.tmp \$(top_srcdir)/INSTALL) \
-|| (rm -f \$(top_srcdir)/.INSTALL.tmp; touch \$(top_srcdir)/INSTALL; \
-echo 'util-macros \"pkgdatadir\" from xorg-macros.pc not found: installing possibly empty INSTALL.' >&2)"
+if test "x$xorg_testset_cc_unused_command_line_argument" = "x" ; then
+       if test "x$xorg_testset_cc_unknown_warning_option" = "xyes" ; then
+               CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       fi
+       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unused-command-line-argument" >&5
+$as_echo_n "checking if $CC supports -Werror=unused-command-line-argument... " >&6; }
+if ${xorg_cv_cc_flag_unused_command_line_argument+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unused_command_line_argument=yes
+else
+  xorg_cv_cc_flag_unused_command_line_argument=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unused_command_line_argument" >&5
+$as_echo "$xorg_cv_cc_flag_unused_command_line_argument" >&6; }
+       xorg_testset_cc_unused_command_line_argument=$xorg_cv_cc_flag_unused_command_line_argument
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
 
+found="no"
 
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
 
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
 
+               CFLAGS="$CFLAGS -Wall"
 
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-Wall" >&5
+$as_echo_n "checking if $CC supports-Wall... " >&6; }
+               cacheid=xorg_cv_cc_flag__Wall
+               if eval \${$cacheid+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+int
+main ()
+{
 
-if test x$APP_MAN_SUFFIX = x    ; then
-    APP_MAN_SUFFIX=1
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval $cacheid=yes
+else
+  eval $cacheid=no
 fi
-if test x$APP_MAN_DIR = x    ; then
-    APP_MAN_DIR='$(mandir)/man$(APP_MAN_SUFFIX)'
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
 fi
 
-if test x$LIB_MAN_SUFFIX = x    ; then
-    LIB_MAN_SUFFIX=3
-fi
-if test x$LIB_MAN_DIR = x    ; then
-    LIB_MAN_DIR='$(mandir)/man$(LIB_MAN_SUFFIX)'
-fi
 
-if test x$FILE_MAN_SUFFIX = x    ; then
-    case $host_os in
-       solaris*)       FILE_MAN_SUFFIX=4  ;;
-       *)              FILE_MAN_SUFFIX=5  ;;
-    esac
-fi
-if test x$FILE_MAN_DIR = x    ; then
-    FILE_MAN_DIR='$(mandir)/man$(FILE_MAN_SUFFIX)'
-fi
+               CFLAGS="$xorg_testset_save_CFLAGS"
+
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       BASE_CFLAGS="$BASE_CFLAGS -Wall"
+                       found="yes"
+               fi
+       fi
 
-if test x$MISC_MAN_SUFFIX = x    ; then
-    case $host_os in
-       solaris*)       MISC_MAN_SUFFIX=5  ;;
-       *)              MISC_MAN_SUFFIX=7  ;;
-    esac
-fi
-if test x$MISC_MAN_DIR = x    ; then
-    MISC_MAN_DIR='$(mandir)/man$(MISC_MAN_SUFFIX)'
-fi
 
-if test x$DRIVER_MAN_SUFFIX = x    ; then
-    case $host_os in
-       solaris*)       DRIVER_MAN_SUFFIX=7  ;;
-       *)              DRIVER_MAN_SUFFIX=4  ;;
-    esac
-fi
-if test x$DRIVER_MAN_DIR = x    ; then
-    DRIVER_MAN_DIR='$(mandir)/man$(DRIVER_MAN_SUFFIX)'
-fi
 
-if test x$ADMIN_MAN_SUFFIX = x    ; then
-    case $host_os in
-       solaris*)       ADMIN_MAN_SUFFIX=1m ;;
-       *)              ADMIN_MAN_SUFFIX=8  ;;
-    esac
-fi
-if test x$ADMIN_MAN_DIR = x    ; then
-    ADMIN_MAN_DIR='$(mandir)/man$(ADMIN_MAN_SUFFIX)'
-fi
 
 
 
 
 
 
+xorg_testset_save_CFLAGS="$CFLAGS"
+
+if test "x$xorg_testset_cc_unknown_warning_option" = "x" ; then
+       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unknown-warning-option" >&5
+$as_echo_n "checking if $CC supports -Werror=unknown-warning-option... " >&6; }
+if ${xorg_cv_cc_flag_unknown_warning_option+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unknown_warning_option=yes
+else
+  xorg_cv_cc_flag_unknown_warning_option=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unknown_warning_option" >&5
+$as_echo "$xorg_cv_cc_flag_unknown_warning_option" >&6; }
+       xorg_testset_cc_unknown_warning_option=$xorg_cv_cc_flag_unknown_warning_option
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
 
+if test "x$xorg_testset_cc_unused_command_line_argument" = "x" ; then
+       if test "x$xorg_testset_cc_unknown_warning_option" = "xyes" ; then
+               CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       fi
+       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unused-command-line-argument" >&5
+$as_echo_n "checking if $CC supports -Werror=unused-command-line-argument... " >&6; }
+if ${xorg_cv_cc_flag_unused_command_line_argument+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unused_command_line_argument=yes
+else
+  xorg_cv_cc_flag_unused_command_line_argument=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unused_command_line_argument" >&5
+$as_echo "$xorg_cv_cc_flag_unused_command_line_argument" >&6; }
+       xorg_testset_cc_unused_command_line_argument=$xorg_cv_cc_flag_unused_command_line_argument
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
 
+found="no"
 
-XORG_MAN_PAGE="X Version 11"
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
 
-MAN_SUBSTS="\
-       -e 's|__vendorversion__|\"\$(PACKAGE_STRING)\" \"\$(XORG_MAN_PAGE)\"|' \
-       -e 's|__xorgversion__|\"\$(PACKAGE_STRING)\" \"\$(XORG_MAN_PAGE)\"|' \
-       -e 's|__xservername__|Xorg|g' \
-       -e 's|__xconfigfile__|xorg.conf|g' \
-       -e 's|__projectroot__|\$(prefix)|g' \
-       -e 's|__apploaddir__|\$(appdefaultdir)|g' \
-       -e 's|__appmansuffix__|\$(APP_MAN_SUFFIX)|g' \
-       -e 's|__drivermansuffix__|\$(DRIVER_MAN_SUFFIX)|g' \
-       -e 's|__adminmansuffix__|\$(ADMIN_MAN_SUFFIX)|g' \
-       -e 's|__libmansuffix__|\$(LIB_MAN_SUFFIX)|g' \
-       -e 's|__miscmansuffix__|\$(MISC_MAN_SUFFIX)|g' \
-       -e 's|__filemansuffix__|\$(FILE_MAN_SUFFIX)|g'"
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
 
+               CFLAGS="$CFLAGS -Wpointer-arith"
 
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-Wpointer-arith" >&5
+$as_echo_n "checking if $CC supports-Wpointer-arith... " >&6; }
+               cacheid=xorg_cv_cc_flag__Wpointer_arith
+               if eval \${$cacheid+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+int
+main ()
+{
 
-# Check whether --enable-silent-rules was given.
-if test "${enable_silent_rules+set}" = set; then :
-  enableval=$enable_silent_rules;
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval $cacheid=yes
+else
+  eval $cacheid=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
 fi
 
-case $enable_silent_rules in
-yes) AM_DEFAULT_VERBOSITY=0;;
-no)  AM_DEFAULT_VERBOSITY=1;;
-*)   AM_DEFAULT_VERBOSITY=0;;
-esac
-AM_BACKSLASH='\'
 
+               CFLAGS="$xorg_testset_save_CFLAGS"
+
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       BASE_CFLAGS="$BASE_CFLAGS -Wpointer-arith"
+                       found="yes"
+               fi
+       fi
 
 
-# Require X.Org server macros (i.e. XORG_DRIVER_CHECK_EXT) to check for required modules
 
 
-# Initialize libtool
 
-case `pwd` in
-  *\ * | *\    *)
-    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Libtool does not cope well with whitespace in \`pwd\`" >&5
-$as_echo "$as_me: WARNING: Libtool does not cope well with whitespace in \`pwd\`" >&2;} ;;
-esac
 
 
 
-macro_version='2.2.6b'
-macro_revision='1.3017'
 
 
 
@@ -4981,87 +5129,109 @@ macro_revision='1.3017'
 
 
 
+xorg_testset_save_CFLAGS="$CFLAGS"
 
+if test "x$xorg_testset_cc_unknown_warning_option" = "x" ; then
+       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unknown-warning-option" >&5
+$as_echo_n "checking if $CC supports -Werror=unknown-warning-option... " >&6; }
+if ${xorg_cv_cc_flag_unknown_warning_option+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unknown_warning_option=yes
+else
+  xorg_cv_cc_flag_unknown_warning_option=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unknown_warning_option" >&5
+$as_echo "$xorg_cv_cc_flag_unknown_warning_option" >&6; }
+       xorg_testset_cc_unknown_warning_option=$xorg_cv_cc_flag_unknown_warning_option
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
 
+if test "x$xorg_testset_cc_unused_command_line_argument" = "x" ; then
+       if test "x$xorg_testset_cc_unknown_warning_option" = "xyes" ; then
+               CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       fi
+       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unused-command-line-argument" >&5
+$as_echo_n "checking if $CC supports -Werror=unused-command-line-argument... " >&6; }
+if ${xorg_cv_cc_flag_unused_command_line_argument+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unused_command_line_argument=yes
+else
+  xorg_cv_cc_flag_unused_command_line_argument=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unused_command_line_argument" >&5
+$as_echo "$xorg_cv_cc_flag_unused_command_line_argument" >&6; }
+       xorg_testset_cc_unused_command_line_argument=$xorg_cv_cc_flag_unused_command_line_argument
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
 
+found="no"
 
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
 
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
 
-ltmain="$ac_aux_dir/ltmain.sh"
+               CFLAGS="$CFLAGS -Wmissing-declarations"
 
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a sed that does not truncate output" >&5
-$as_echo_n "checking for a sed that does not truncate output... " >&6; }
-if test "${ac_cv_path_SED+set}" = set; then :
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-Wmissing-declarations" >&5
+$as_echo_n "checking if $CC supports-Wmissing-declarations... " >&6; }
+               cacheid=xorg_cv_cc_flag__Wmissing_declarations
+               if eval \${$cacheid+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-            ac_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
-     for ac_i in 1 2 3 4 5 6 7; do
-       ac_script="$ac_script$as_nl$ac_script"
-     done
-     echo "$ac_script" 2>/dev/null | sed 99q >conftest.sed
-     { ac_script=; unset ac_script;}
-     if test -z "$SED"; then
-  ac_path_SED_found=false
-  # Loop through the user's path and test for each of PROGNAME-LIST
-  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-    for ac_prog in sed gsed; do
-    for ac_exec_ext in '' $ac_executable_extensions; do
-      ac_path_SED="$as_dir/$ac_prog$ac_exec_ext"
-      { test -f "$ac_path_SED" && $as_test_x "$ac_path_SED"; } || continue
-# Check for GNU ac_path_SED and select it if it is found.
-  # Check for GNU $ac_path_SED
-case `"$ac_path_SED" --version 2>&1` in
-*GNU*)
-  ac_cv_path_SED="$ac_path_SED" ac_path_SED_found=:;;
-*)
-  ac_count=0
-  $as_echo_n 0123456789 >"conftest.in"
-  while :
-  do
-    cat "conftest.in" "conftest.in" >"conftest.tmp"
-    mv "conftest.tmp" "conftest.in"
-    cp "conftest.in" "conftest.nl"
-    $as_echo '' >> "conftest.nl"
-    "$ac_path_SED" -f conftest.sed < "conftest.nl" >"conftest.out" 2>/dev/null || break
-    diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
-    as_fn_arith $ac_count + 1 && ac_count=$as_val
-    if test $ac_count -gt ${ac_path_SED_max-0}; then
-      # Best one so far, save it but keep looking for a better one
-      ac_cv_path_SED="$ac_path_SED"
-      ac_path_SED_max=$ac_count
-    fi
-    # 10*(2^10) chars as input seems more than enough
-    test $ac_count -gt 10 && break
-  done
-  rm -f conftest.in conftest.tmp conftest.nl conftest.out;;
-esac
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+int
+main ()
+{
 
-      $ac_path_SED_found && break 3
-    done
-  done
-  done
-IFS=$as_save_IFS
-  if test -z "$ac_cv_path_SED"; then
-    as_fn_error $? "no acceptable sed could be found in \$PATH" "$LINENO" 5
-  fi
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval $cacheid=yes
 else
-  ac_cv_path_SED=$SED
+  eval $cacheid=no
 fi
-
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_SED" >&5
-$as_echo "$ac_cv_path_SED" >&6; }
- SED="$ac_cv_path_SED"
-  rm -f conftest.sed
 
-test -z "$SED" && SED=sed
-Xsed="$SED -e 1s/^X//"
 
+               CFLAGS="$xorg_testset_save_CFLAGS"
 
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       BASE_CFLAGS="$BASE_CFLAGS -Wmissing-declarations"
+                       found="yes"
+               fi
+       fi
 
 
 
@@ -5071,83 +5241,164 @@ Xsed="$SED -e 1s/^X//"
 
 
 
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for fgrep" >&5
-$as_echo_n "checking for fgrep... " >&6; }
-if test "${ac_cv_path_FGREP+set}" = set; then :
+
+
+
+
+
+
+xorg_testset_save_CFLAGS="$CFLAGS"
+
+if test "x$xorg_testset_cc_unknown_warning_option" = "x" ; then
+       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unknown-warning-option" >&5
+$as_echo_n "checking if $CC supports -Werror=unknown-warning-option... " >&6; }
+if ${xorg_cv_cc_flag_unknown_warning_option+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  if echo 'ab*c' | $GREP -F 'ab*c' >/dev/null 2>&1
-   then ac_cv_path_FGREP="$GREP -F"
-   else
-     if test -z "$FGREP"; then
-  ac_path_FGREP_found=false
-  # Loop through the user's path and test for each of PROGNAME-LIST
-  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-    for ac_prog in fgrep; do
-    for ac_exec_ext in '' $ac_executable_extensions; do
-      ac_path_FGREP="$as_dir/$ac_prog$ac_exec_ext"
-      { test -f "$ac_path_FGREP" && $as_test_x "$ac_path_FGREP"; } || continue
-# Check for GNU ac_path_FGREP and select it if it is found.
-  # Check for GNU $ac_path_FGREP
-case `"$ac_path_FGREP" --version 2>&1` in
-*GNU*)
-  ac_cv_path_FGREP="$ac_path_FGREP" ac_path_FGREP_found=:;;
-*)
-  ac_count=0
-  $as_echo_n 0123456789 >"conftest.in"
-  while :
-  do
-    cat "conftest.in" "conftest.in" >"conftest.tmp"
-    mv "conftest.tmp" "conftest.in"
-    cp "conftest.in" "conftest.nl"
-    $as_echo 'FGREP' >> "conftest.nl"
-    "$ac_path_FGREP" FGREP < "conftest.nl" >"conftest.out" 2>/dev/null || break
-    diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
-    as_fn_arith $ac_count + 1 && ac_count=$as_val
-    if test $ac_count -gt ${ac_path_FGREP_max-0}; then
-      # Best one so far, save it but keep looking for a better one
-      ac_cv_path_FGREP="$ac_path_FGREP"
-      ac_path_FGREP_max=$ac_count
-    fi
-    # 10*(2^10) chars as input seems more than enough
-    test $ac_count -gt 10 && break
-  done
-  rm -f conftest.in conftest.tmp conftest.nl conftest.out;;
-esac
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unknown_warning_option=yes
+else
+  xorg_cv_cc_flag_unknown_warning_option=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unknown_warning_option" >&5
+$as_echo "$xorg_cv_cc_flag_unknown_warning_option" >&6; }
+       xorg_testset_cc_unknown_warning_option=$xorg_cv_cc_flag_unknown_warning_option
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
 
-      $ac_path_FGREP_found && break 3
-    done
-  done
-  done
-IFS=$as_save_IFS
-  if test -z "$ac_cv_path_FGREP"; then
-    as_fn_error $? "no acceptable fgrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5
-  fi
+if test "x$xorg_testset_cc_unused_command_line_argument" = "x" ; then
+       if test "x$xorg_testset_cc_unknown_warning_option" = "xyes" ; then
+               CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       fi
+       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unused-command-line-argument" >&5
+$as_echo_n "checking if $CC supports -Werror=unused-command-line-argument... " >&6; }
+if ${xorg_cv_cc_flag_unused_command_line_argument+:} false; then :
+  $as_echo_n "(cached) " >&6
 else
-  ac_cv_path_FGREP=$FGREP
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unused_command_line_argument=yes
+else
+  xorg_cv_cc_flag_unused_command_line_argument=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unused_command_line_argument" >&5
+$as_echo "$xorg_cv_cc_flag_unused_command_line_argument" >&6; }
+       xorg_testset_cc_unused_command_line_argument=$xorg_cv_cc_flag_unused_command_line_argument
+       CFLAGS="$xorg_testset_save_CFLAGS"
 fi
 
-   fi
+found="no"
+
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
+
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
+
+               CFLAGS="$CFLAGS -Wformat=2"
+
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-Wformat=2" >&5
+$as_echo_n "checking if $CC supports-Wformat=2... " >&6; }
+               cacheid=xorg_cv_cc_flag__Wformat_2
+               if eval \${$cacheid+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval $cacheid=yes
+else
+  eval $cacheid=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_FGREP" >&5
-$as_echo "$ac_cv_path_FGREP" >&6; }
- FGREP="$ac_cv_path_FGREP"
 
 
-test -z "$GREP" && GREP=grep
+               CFLAGS="$xorg_testset_save_CFLAGS"
 
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       BASE_CFLAGS="$BASE_CFLAGS -Wformat=2"
+                       found="yes"
+               fi
+       fi
 
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
 
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
 
+               CFLAGS="$CFLAGS -Wformat"
 
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-Wformat" >&5
+$as_echo_n "checking if $CC supports-Wformat... " >&6; }
+               cacheid=xorg_cv_cc_flag__Wformat
+               if eval \${$cacheid+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+int
+main ()
+{
 
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval $cacheid=yes
+else
+  eval $cacheid=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+fi
 
 
+               CFLAGS="$xorg_testset_save_CFLAGS"
 
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       BASE_CFLAGS="$BASE_CFLAGS -Wformat"
+                       found="yes"
+               fi
+       fi
 
 
 
@@ -5158,110 +5409,116 @@ test -z "$GREP" && GREP=grep
 
 
 
-# Check whether --with-gnu-ld was given.
-if test "${with_gnu_ld+set}" = set; then :
-  withval=$with_gnu_ld; test "$withval" = no || with_gnu_ld=yes
-else
-  with_gnu_ld=no
-fi
 
-ac_prog=ld
-if test "$GCC" = yes; then
-  # Check if gcc -print-prog-name=ld gives a path.
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ld used by $CC" >&5
-$as_echo_n "checking for ld used by $CC... " >&6; }
-  case $host in
-  *-*-mingw*)
-    # gcc leaves a trailing carriage return which upsets mingw
-    ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;;
-  *)
-    ac_prog=`($CC -print-prog-name=ld) 2>&5` ;;
-  esac
-  case $ac_prog in
-    # Accept absolute paths.
-    [\\/]* | ?:[\\/]*)
-      re_direlt='/[^/][^/]*/\.\./'
-      # Canonicalize the pathname of ld
-      ac_prog=`$ECHO "$ac_prog"| $SED 's%\\\\%/%g'`
-      while $ECHO "$ac_prog" | $GREP "$re_direlt" > /dev/null 2>&1; do
-       ac_prog=`$ECHO $ac_prog| $SED "s%$re_direlt%/%"`
-      done
-      test -z "$LD" && LD="$ac_prog"
-      ;;
-  "")
-    # If it fails, then pretend we aren't using GCC.
-    ac_prog=ld
-    ;;
-  *)
-    # If it is relative, then search for the first ld in PATH.
-    with_gnu_ld=unknown
-    ;;
-  esac
-elif test "$with_gnu_ld" = yes; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GNU ld" >&5
-$as_echo_n "checking for GNU ld... " >&6; }
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for non-GNU ld" >&5
-$as_echo_n "checking for non-GNU ld... " >&6; }
-fi
-if test "${lt_cv_path_LD+set}" = set; then :
+
+
+
+
+
+
+xorg_testset_save_CFLAGS="$CFLAGS"
+
+if test "x$xorg_testset_cc_unknown_warning_option" = "x" ; then
+       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unknown-warning-option" >&5
+$as_echo_n "checking if $CC supports -Werror=unknown-warning-option... " >&6; }
+if ${xorg_cv_cc_flag_unknown_warning_option+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  if test -z "$LD"; then
-  lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
-  for ac_dir in $PATH; do
-    IFS="$lt_save_ifs"
-    test -z "$ac_dir" && ac_dir=.
-    if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then
-      lt_cv_path_LD="$ac_dir/$ac_prog"
-      # Check to see if the program is GNU ld.  I'd rather use --version,
-      # but apparently some variants of GNU ld only accept -v.
-      # Break only if it was the GNU/non-GNU ld that we prefer.
-      case `"$lt_cv_path_LD" -v 2>&1 </dev/null` in
-      *GNU* | *'with BFD'*)
-       test "$with_gnu_ld" != no && break
-       ;;
-      *)
-       test "$with_gnu_ld" != yes && break
-       ;;
-      esac
-    fi
-  done
-  IFS="$lt_save_ifs"
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unknown_warning_option=yes
 else
-  lt_cv_path_LD="$LD" # Let the user override the test with a path.
+  xorg_cv_cc_flag_unknown_warning_option=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unknown_warning_option" >&5
+$as_echo "$xorg_cv_cc_flag_unknown_warning_option" >&6; }
+       xorg_testset_cc_unknown_warning_option=$xorg_cv_cc_flag_unknown_warning_option
+       CFLAGS="$xorg_testset_save_CFLAGS"
 fi
 
-LD="$lt_cv_path_LD"
-if test -n "$LD"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LD" >&5
-$as_echo "$LD" >&6; }
+if test "x$xorg_testset_cc_unused_command_line_argument" = "x" ; then
+       if test "x$xorg_testset_cc_unknown_warning_option" = "xyes" ; then
+               CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       fi
+       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unused-command-line-argument" >&5
+$as_echo_n "checking if $CC supports -Werror=unused-command-line-argument... " >&6; }
+if ${xorg_cv_cc_flag_unused_command_line_argument+:} false; then :
+  $as_echo_n "(cached) " >&6
 else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unused_command_line_argument=yes
+else
+  xorg_cv_cc_flag_unused_command_line_argument=no
 fi
-test -z "$LD" && as_fn_error $? "no acceptable ld found in \$PATH" "$LINENO" 5
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if the linker ($LD) is GNU ld" >&5
-$as_echo_n "checking if the linker ($LD) is GNU ld... " >&6; }
-if test "${lt_cv_prog_gnu_ld+set}" = set; then :
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unused_command_line_argument" >&5
+$as_echo "$xorg_cv_cc_flag_unused_command_line_argument" >&6; }
+       xorg_testset_cc_unused_command_line_argument=$xorg_cv_cc_flag_unused_command_line_argument
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
+
+found="no"
+
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
+
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
+
+               CFLAGS="$CFLAGS -Wstrict-prototypes"
+
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-Wstrict-prototypes" >&5
+$as_echo_n "checking if $CC supports-Wstrict-prototypes... " >&6; }
+               cacheid=xorg_cv_cc_flag__Wstrict_prototypes
+               if eval \${$cacheid+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  # I'd rather use --version here, but apparently some GNU lds only accept -v.
-case `$LD -v 2>&1 </dev/null` in
-*GNU* | *'with BFD'*)
-  lt_cv_prog_gnu_ld=yes
-  ;;
-*)
-  lt_cv_prog_gnu_ld=no
-  ;;
-esac
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval $cacheid=yes
+else
+  eval $cacheid=no
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_gnu_ld" >&5
-$as_echo "$lt_cv_prog_gnu_ld" >&6; }
-with_gnu_ld=$lt_cv_prog_gnu_ld
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+fi
+
 
+               CFLAGS="$xorg_testset_save_CFLAGS"
 
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       BASE_CFLAGS="$BASE_CFLAGS -Wstrict-prototypes"
+                       found="yes"
+               fi
+       fi
 
 
 
@@ -5269,424 +5526,358 @@ with_gnu_ld=$lt_cv_prog_gnu_ld
 
 
 
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for BSD- or MS-compatible name lister (nm)" >&5
-$as_echo_n "checking for BSD- or MS-compatible name lister (nm)... " >&6; }
-if test "${lt_cv_path_NM+set}" = set; then :
+
+
+
+
+
+
+
+
+xorg_testset_save_CFLAGS="$CFLAGS"
+
+if test "x$xorg_testset_cc_unknown_warning_option" = "x" ; then
+       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unknown-warning-option" >&5
+$as_echo_n "checking if $CC supports -Werror=unknown-warning-option... " >&6; }
+if ${xorg_cv_cc_flag_unknown_warning_option+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  if test -n "$NM"; then
-  # Let the user override the test.
-  lt_cv_path_NM="$NM"
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unknown_warning_option=yes
 else
-  lt_nm_to_check="${ac_tool_prefix}nm"
-  if test -n "$ac_tool_prefix" && test "$build" = "$host"; then
-    lt_nm_to_check="$lt_nm_to_check nm"
-  fi
-  for lt_tmp_nm in $lt_nm_to_check; do
-    lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
-    for ac_dir in $PATH /usr/ccs/bin/elf /usr/ccs/bin /usr/ucb /bin; do
-      IFS="$lt_save_ifs"
-      test -z "$ac_dir" && ac_dir=.
-      tmp_nm="$ac_dir/$lt_tmp_nm"
-      if test -f "$tmp_nm" || test -f "$tmp_nm$ac_exeext" ; then
-       # Check to see if the nm accepts a BSD-compat flag.
-       # Adding the `sed 1q' prevents false positives on HP-UX, which says:
-       #   nm: unknown option "B" ignored
-       # Tru64's nm complains that /dev/null is an invalid object file
-       case `"$tmp_nm" -B /dev/null 2>&1 | sed '1q'` in
-       */dev/null* | *'Invalid file or object type'*)
-         lt_cv_path_NM="$tmp_nm -B"
-         break
-         ;;
-       *)
-         case `"$tmp_nm" -p /dev/null 2>&1 | sed '1q'` in
-         */dev/null*)
-           lt_cv_path_NM="$tmp_nm -p"
-           break
-           ;;
-         *)
-           lt_cv_path_NM=${lt_cv_path_NM="$tmp_nm"} # keep the first match, but
-           continue # so that we can try to find one that supports BSD flags
-           ;;
-         esac
-         ;;
-       esac
-      fi
-    done
-    IFS="$lt_save_ifs"
-  done
-  : ${lt_cv_path_NM=no}
+  xorg_cv_cc_flag_unknown_warning_option=no
 fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_path_NM" >&5
-$as_echo "$lt_cv_path_NM" >&6; }
-if test "$lt_cv_path_NM" != "no"; then
-  NM="$lt_cv_path_NM"
-else
-  # Didn't find any BSD compatible name lister, look for dumpbin.
-  if test -n "$ac_tool_prefix"; then
-  for ac_prog in "dumpbin -symbols" "link -dump -symbols"
-  do
-    # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
-set dummy $ac_tool_prefix$ac_prog; ac_word=$2
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
-$as_echo_n "checking for $ac_word... " >&6; }
-if test "${ac_cv_prog_DUMPBIN+set}" = set; then :
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unknown_warning_option" >&5
+$as_echo "$xorg_cv_cc_flag_unknown_warning_option" >&6; }
+       xorg_testset_cc_unknown_warning_option=$xorg_cv_cc_flag_unknown_warning_option
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
+
+if test "x$xorg_testset_cc_unused_command_line_argument" = "x" ; then
+       if test "x$xorg_testset_cc_unknown_warning_option" = "xyes" ; then
+               CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       fi
+       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unused-command-line-argument" >&5
+$as_echo_n "checking if $CC supports -Werror=unused-command-line-argument... " >&6; }
+if ${xorg_cv_cc_flag_unused_command_line_argument+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  if test -n "$DUMPBIN"; then
-  ac_cv_prog_DUMPBIN="$DUMPBIN" # Let the user override the test.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unused_command_line_argument=yes
 else
-as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_prog_DUMPBIN="$ac_tool_prefix$ac_prog"
-    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
-    break 2
-  fi
-done
-  done
-IFS=$as_save_IFS
-
+  xorg_cv_cc_flag_unused_command_line_argument=no
 fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 fi
-DUMPBIN=$ac_cv_prog_DUMPBIN
-if test -n "$DUMPBIN"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DUMPBIN" >&5
-$as_echo "$DUMPBIN" >&6; }
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unused_command_line_argument" >&5
+$as_echo "$xorg_cv_cc_flag_unused_command_line_argument" >&6; }
+       xorg_testset_cc_unused_command_line_argument=$xorg_cv_cc_flag_unused_command_line_argument
+       CFLAGS="$xorg_testset_save_CFLAGS"
 fi
 
+found="no"
 
-    test -n "$DUMPBIN" && break
-  done
-fi
-if test -z "$DUMPBIN"; then
-  ac_ct_DUMPBIN=$DUMPBIN
-  for ac_prog in "dumpbin -symbols" "link -dump -symbols"
-do
-  # Extract the first word of "$ac_prog", so it can be a program name with args.
-set dummy $ac_prog; ac_word=$2
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
-$as_echo_n "checking for $ac_word... " >&6; }
-if test "${ac_cv_prog_ac_ct_DUMPBIN+set}" = set; then :
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
+
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
+
+               CFLAGS="$CFLAGS -Wmissing-prototypes"
+
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-Wmissing-prototypes" >&5
+$as_echo_n "checking if $CC supports-Wmissing-prototypes... " >&6; }
+               cacheid=xorg_cv_cc_flag__Wmissing_prototypes
+               if eval \${$cacheid+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  if test -n "$ac_ct_DUMPBIN"; then
-  ac_cv_prog_ac_ct_DUMPBIN="$ac_ct_DUMPBIN" # Let the user override the test.
-else
-as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_prog_ac_ct_DUMPBIN="$ac_prog"
-    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
-    break 2
-  fi
-done
-  done
-IFS=$as_save_IFS
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+int
+main ()
+{
 
-fi
-fi
-ac_ct_DUMPBIN=$ac_cv_prog_ac_ct_DUMPBIN
-if test -n "$ac_ct_DUMPBIN"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DUMPBIN" >&5
-$as_echo "$ac_ct_DUMPBIN" >&6; }
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval $cacheid=yes
 else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
+  eval $cacheid=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
 fi
 
 
-  test -n "$ac_ct_DUMPBIN" && break
-done
+               CFLAGS="$xorg_testset_save_CFLAGS"
 
-  if test "x$ac_ct_DUMPBIN" = x; then
-    DUMPBIN=":"
-  else
-    case $cross_compiling:$ac_tool_warned in
-yes:)
-{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
-$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
-ac_tool_warned=yes ;;
-esac
-    DUMPBIN=$ac_ct_DUMPBIN
-  fi
-fi
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       BASE_CFLAGS="$BASE_CFLAGS -Wmissing-prototypes"
+                       found="yes"
+               fi
+       fi
 
 
-  if test "$DUMPBIN" != ":"; then
-    NM="$DUMPBIN"
-  fi
-fi
-test -z "$NM" && NM=nm
 
 
 
 
 
 
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking the name lister ($NM) interface" >&5
-$as_echo_n "checking the name lister ($NM) interface... " >&6; }
-if test "${lt_cv_nm_interface+set}" = set; then :
+
+
+
+
+
+
+
+xorg_testset_save_CFLAGS="$CFLAGS"
+
+if test "x$xorg_testset_cc_unknown_warning_option" = "x" ; then
+       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unknown-warning-option" >&5
+$as_echo_n "checking if $CC supports -Werror=unknown-warning-option... " >&6; }
+if ${xorg_cv_cc_flag_unknown_warning_option+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  lt_cv_nm_interface="BSD nm"
-  echo "int some_variable = 0;" > conftest.$ac_ext
-  (eval echo "\"\$as_me:5446: $ac_compile\"" >&5)
-  (eval "$ac_compile" 2>conftest.err)
-  cat conftest.err >&5
-  (eval echo "\"\$as_me:5449: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
-  (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out)
-  cat conftest.err >&5
-  (eval echo "\"\$as_me:5452: output\"" >&5)
-  cat conftest.out >&5
-  if $GREP 'External.*some_variable' conftest.out > /dev/null; then
-    lt_cv_nm_interface="MS dumpbin"
-  fi
-  rm -f conftest*
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unknown_warning_option=yes
+else
+  xorg_cv_cc_flag_unknown_warning_option=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unknown_warning_option" >&5
+$as_echo "$xorg_cv_cc_flag_unknown_warning_option" >&6; }
+       xorg_testset_cc_unknown_warning_option=$xorg_cv_cc_flag_unknown_warning_option
+       CFLAGS="$xorg_testset_save_CFLAGS"
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_nm_interface" >&5
-$as_echo "$lt_cv_nm_interface" >&6; }
 
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ln -s works" >&5
-$as_echo_n "checking whether ln -s works... " >&6; }
-LN_S=$as_ln_s
-if test "$LN_S" = "ln -s"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
-$as_echo "yes" >&6; }
+if test "x$xorg_testset_cc_unused_command_line_argument" = "x" ; then
+       if test "x$xorg_testset_cc_unknown_warning_option" = "xyes" ; then
+               CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       fi
+       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unused-command-line-argument" >&5
+$as_echo_n "checking if $CC supports -Werror=unused-command-line-argument... " >&6; }
+if ${xorg_cv_cc_flag_unused_command_line_argument+:} false; then :
+  $as_echo_n "(cached) " >&6
 else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no, using $LN_S" >&5
-$as_echo "no, using $LN_S" >&6; }
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unused_command_line_argument=yes
+else
+  xorg_cv_cc_flag_unused_command_line_argument=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unused_command_line_argument" >&5
+$as_echo "$xorg_cv_cc_flag_unused_command_line_argument" >&6; }
+       xorg_testset_cc_unused_command_line_argument=$xorg_cv_cc_flag_unused_command_line_argument
+       CFLAGS="$xorg_testset_save_CFLAGS"
 fi
 
-# find the maximum length of command line arguments
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking the maximum length of command line arguments" >&5
-$as_echo_n "checking the maximum length of command line arguments... " >&6; }
-if test "${lt_cv_sys_max_cmd_len+set}" = set; then :
+found="no"
+
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
+
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
+
+               CFLAGS="$CFLAGS -Wnested-externs"
+
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-Wnested-externs" >&5
+$as_echo_n "checking if $CC supports-Wnested-externs... " >&6; }
+               cacheid=xorg_cv_cc_flag__Wnested_externs
+               if eval \${$cacheid+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-    i=0
-  teststring="ABCD"
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+int
+main ()
+{
 
-  case $build_os in
-  msdosdjgpp*)
-    # On DJGPP, this test can blow up pretty badly due to problems in libc
-    # (any single argument exceeding 2000 bytes causes a buffer overrun
-    # during glob expansion).  Even if it were fixed, the result of this
-    # check would be larger than it should be.
-    lt_cv_sys_max_cmd_len=12288;    # 12K is about right
-    ;;
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval $cacheid=yes
+else
+  eval $cacheid=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+fi
 
-  gnu*)
-    # Under GNU Hurd, this test is not required because there is
-    # no limit to the length of command line arguments.
-    # Libtool will interpret -1 as no limit whatsoever
-    lt_cv_sys_max_cmd_len=-1;
-    ;;
 
-  cygwin* | mingw* | cegcc*)
-    # On Win9x/ME, this test blows up -- it succeeds, but takes
-    # about 5 minutes as the teststring grows exponentially.
-    # Worse, since 9x/ME are not pre-emptively multitasking,
-    # you end up with a "frozen" computer, even though with patience
-    # the test eventually succeeds (with a max line length of 256k).
-    # Instead, let's just punt: use the minimum linelength reported by
-    # all of the supported platforms: 8192 (on NT/2K/XP).
-    lt_cv_sys_max_cmd_len=8192;
-    ;;
+               CFLAGS="$xorg_testset_save_CFLAGS"
 
-  amigaos*)
-    # On AmigaOS with pdksh, this test takes hours, literally.
-    # So we just punt and use a minimum line length of 8192.
-    lt_cv_sys_max_cmd_len=8192;
-    ;;
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       BASE_CFLAGS="$BASE_CFLAGS -Wnested-externs"
+                       found="yes"
+               fi
+       fi
 
-  netbsd* | freebsd* | openbsd* | darwin* | dragonfly*)
-    # This has been around since 386BSD, at least.  Likely further.
-    if test -x /sbin/sysctl; then
-      lt_cv_sys_max_cmd_len=`/sbin/sysctl -n kern.argmax`
-    elif test -x /usr/sbin/sysctl; then
-      lt_cv_sys_max_cmd_len=`/usr/sbin/sysctl -n kern.argmax`
-    else
-      lt_cv_sys_max_cmd_len=65536      # usable default for all BSDs
-    fi
-    # And add a safety zone
-    lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4`
-    lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3`
-    ;;
 
-  interix*)
-    # We know the value 262144 and hardcode it with a safety zone (like BSD)
-    lt_cv_sys_max_cmd_len=196608
-    ;;
 
-  osf*)
-    # Dr. Hans Ekkehard Plesser reports seeing a kernel panic running configure
-    # due to this test when exec_disable_arg_limit is 1 on Tru64. It is not
-    # nice to cause kernel panics so lets avoid the loop below.
-    # First set a reasonable default.
-    lt_cv_sys_max_cmd_len=16384
-    #
-    if test -x /sbin/sysconfig; then
-      case `/sbin/sysconfig -q proc exec_disable_arg_limit` in
-        *1*) lt_cv_sys_max_cmd_len=-1 ;;
-      esac
-    fi
-    ;;
-  sco3.2v5*)
-    lt_cv_sys_max_cmd_len=102400
-    ;;
-  sysv5* | sco5v6* | sysv4.2uw2*)
-    kargmax=`grep ARG_MAX /etc/conf/cf.d/stune 2>/dev/null`
-    if test -n "$kargmax"; then
-      lt_cv_sys_max_cmd_len=`echo $kargmax | sed 's/.*[         ]//'`
-    else
-      lt_cv_sys_max_cmd_len=32768
-    fi
-    ;;
-  *)
-    lt_cv_sys_max_cmd_len=`(getconf ARG_MAX) 2> /dev/null`
-    if test -n "$lt_cv_sys_max_cmd_len"; then
-      lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4`
-      lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3`
-    else
-      # Make teststring a little bigger before we do anything with it.
-      # a 1K string should be a reasonable start.
-      for i in 1 2 3 4 5 6 7 8 ; do
-        teststring=$teststring$teststring
-      done
-      SHELL=${SHELL-${CONFIG_SHELL-/bin/sh}}
-      # If test is not a shell built-in, we'll probably end up computing a
-      # maximum length that is only half of the actual maximum length, but
-      # we can't tell.
-      while { test "X"`$SHELL $0 --fallback-echo "X$teststring$teststring" 2>/dev/null` \
-                = "XX$teststring$teststring"; } >/dev/null 2>&1 &&
-             test $i != 17 # 1/2 MB should be enough
-      do
-        i=`expr $i + 1`
-        teststring=$teststring$teststring
-      done
-      # Only check the string length outside the loop.
-      lt_cv_sys_max_cmd_len=`expr "X$teststring" : ".*" 2>&1`
-      teststring=
-      # Add a significant safety factor because C++ compilers can tack on
-      # massive amounts of additional arguments before passing them to the
-      # linker.  It appears as though 1/2 is a usable value.
-      lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 2`
-    fi
-    ;;
-  esac
 
-fi
 
-if test -n $lt_cv_sys_max_cmd_len ; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_sys_max_cmd_len" >&5
-$as_echo "$lt_cv_sys_max_cmd_len" >&6; }
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: none" >&5
-$as_echo "none" >&6; }
-fi
-max_cmd_len=$lt_cv_sys_max_cmd_len
 
 
 
 
 
 
-: ${CP="cp -f"}
-: ${MV="mv -f"}
-: ${RM="rm -f"}
 
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the shell understands some XSI constructs" >&5
-$as_echo_n "checking whether the shell understands some XSI constructs... " >&6; }
-# Try some XSI features
-xsi_shell=no
-( _lt_dummy="a/b/c"
-  test "${_lt_dummy##*/},${_lt_dummy%/*},"${_lt_dummy%"$_lt_dummy"}, \
-      = c,a/b,, \
-    && eval 'test $(( 1 + 1 )) -eq 2 \
-    && test "${#_lt_dummy}" -eq 5' ) >/dev/null 2>&1 \
-  && xsi_shell=yes
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xsi_shell" >&5
-$as_echo "$xsi_shell" >&6; }
 
 
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the shell understands \"+=\"" >&5
-$as_echo_n "checking whether the shell understands \"+=\"... " >&6; }
-lt_shell_append=no
-( foo=bar; set foo baz; eval "$1+=\$2" && test "$foo" = barbaz ) \
-    >/dev/null 2>&1 \
-  && lt_shell_append=yes
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_shell_append" >&5
-$as_echo "$lt_shell_append" >&6; }
 
+xorg_testset_save_CFLAGS="$CFLAGS"
 
-if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then
-  lt_unset=unset
+if test "x$xorg_testset_cc_unknown_warning_option" = "x" ; then
+       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unknown-warning-option" >&5
+$as_echo_n "checking if $CC supports -Werror=unknown-warning-option... " >&6; }
+if ${xorg_cv_cc_flag_unknown_warning_option+:} false; then :
+  $as_echo_n "(cached) " >&6
 else
-  lt_unset=false
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unknown_warning_option=yes
+else
+  xorg_cv_cc_flag_unknown_warning_option=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unknown_warning_option" >&5
+$as_echo "$xorg_cv_cc_flag_unknown_warning_option" >&6; }
+       xorg_testset_cc_unknown_warning_option=$xorg_cv_cc_flag_unknown_warning_option
+       CFLAGS="$xorg_testset_save_CFLAGS"
 fi
 
+if test "x$xorg_testset_cc_unused_command_line_argument" = "x" ; then
+       if test "x$xorg_testset_cc_unknown_warning_option" = "xyes" ; then
+               CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       fi
+       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unused-command-line-argument" >&5
+$as_echo_n "checking if $CC supports -Werror=unused-command-line-argument... " >&6; }
+if ${xorg_cv_cc_flag_unused_command_line_argument+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unused_command_line_argument=yes
+else
+  xorg_cv_cc_flag_unused_command_line_argument=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unused_command_line_argument" >&5
+$as_echo "$xorg_cv_cc_flag_unused_command_line_argument" >&6; }
+       xorg_testset_cc_unused_command_line_argument=$xorg_cv_cc_flag_unused_command_line_argument
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
 
+found="no"
 
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
 
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
 
-# test EBCDIC or ASCII
-case `echo X|tr X '\101'` in
- A) # ASCII based system
-    # \n is not interpreted correctly by Solaris 8 /usr/ucb/tr
-  lt_SP2NL='tr \040 \012'
-  lt_NL2SP='tr \015\012 \040\040'
-  ;;
- *) # EBCDIC based system
-  lt_SP2NL='tr \100 \n'
-  lt_NL2SP='tr \r\n \100\100'
-  ;;
-esac
+               CFLAGS="$CFLAGS -Wbad-function-cast"
+
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-Wbad-function-cast" >&5
+$as_echo_n "checking if $CC supports-Wbad-function-cast... " >&6; }
+               cacheid=xorg_cv_cc_flag__Wbad_function_cast
+               if eval \${$cacheid+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+int
+main ()
+{
 
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval $cacheid=yes
+else
+  eval $cacheid=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+fi
 
 
+               CFLAGS="$xorg_testset_save_CFLAGS"
 
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       BASE_CFLAGS="$BASE_CFLAGS -Wbad-function-cast"
+                       found="yes"
+               fi
+       fi
 
 
 
 
 
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $LD option to reload object files" >&5
-$as_echo_n "checking for $LD option to reload object files... " >&6; }
-if test "${lt_cv_ld_reload_flag+set}" = set; then :
-  $as_echo_n "(cached) " >&6
-else
-  lt_cv_ld_reload_flag='-r'
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_reload_flag" >&5
-$as_echo "$lt_cv_ld_reload_flag" >&6; }
-reload_flag=$lt_cv_ld_reload_flag
-case $reload_flag in
-"" | " "*) ;;
-*) reload_flag=" $reload_flag" ;;
-esac
-reload_cmds='$LD$reload_flag -o $output$reload_objs'
-case $host_os in
-  darwin*)
-    if test "$GCC" = yes; then
-      reload_cmds='$LTCC $LTCFLAGS -nostdlib ${wl}-r -o $output$reload_objs'
-    else
-      reload_cmds='$LD$reload_flag -o $output$reload_objs'
-    fi
-    ;;
-esac
 
 
 
@@ -5696,417 +5887,350 @@ esac
 
 
 
-if test -n "$ac_tool_prefix"; then
-  # Extract the first word of "${ac_tool_prefix}objdump", so it can be a program name with args.
-set dummy ${ac_tool_prefix}objdump; ac_word=$2
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
-$as_echo_n "checking for $ac_word... " >&6; }
-if test "${ac_cv_prog_OBJDUMP+set}" = set; then :
+
+xorg_testset_save_CFLAGS="$CFLAGS"
+
+if test "x$xorg_testset_cc_unknown_warning_option" = "x" ; then
+       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unknown-warning-option" >&5
+$as_echo_n "checking if $CC supports -Werror=unknown-warning-option... " >&6; }
+if ${xorg_cv_cc_flag_unknown_warning_option+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  if test -n "$OBJDUMP"; then
-  ac_cv_prog_OBJDUMP="$OBJDUMP" # Let the user override the test.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unknown_warning_option=yes
 else
-as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_prog_OBJDUMP="${ac_tool_prefix}objdump"
-    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
-    break 2
-  fi
-done
-  done
-IFS=$as_save_IFS
-
+  xorg_cv_cc_flag_unknown_warning_option=no
 fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 fi
-OBJDUMP=$ac_cv_prog_OBJDUMP
-if test -n "$OBJDUMP"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OBJDUMP" >&5
-$as_echo "$OBJDUMP" >&6; }
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unknown_warning_option" >&5
+$as_echo "$xorg_cv_cc_flag_unknown_warning_option" >&6; }
+       xorg_testset_cc_unknown_warning_option=$xorg_cv_cc_flag_unknown_warning_option
+       CFLAGS="$xorg_testset_save_CFLAGS"
 fi
 
-
-fi
-if test -z "$ac_cv_prog_OBJDUMP"; then
-  ac_ct_OBJDUMP=$OBJDUMP
-  # Extract the first word of "objdump", so it can be a program name with args.
-set dummy objdump; ac_word=$2
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
-$as_echo_n "checking for $ac_word... " >&6; }
-if test "${ac_cv_prog_ac_ct_OBJDUMP+set}" = set; then :
+if test "x$xorg_testset_cc_unused_command_line_argument" = "x" ; then
+       if test "x$xorg_testset_cc_unknown_warning_option" = "xyes" ; then
+               CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       fi
+       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unused-command-line-argument" >&5
+$as_echo_n "checking if $CC supports -Werror=unused-command-line-argument... " >&6; }
+if ${xorg_cv_cc_flag_unused_command_line_argument+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  if test -n "$ac_ct_OBJDUMP"; then
-  ac_cv_prog_ac_ct_OBJDUMP="$ac_ct_OBJDUMP" # Let the user override the test.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unused_command_line_argument=yes
 else
-as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_prog_ac_ct_OBJDUMP="objdump"
-    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
-    break 2
-  fi
-done
-  done
-IFS=$as_save_IFS
-
-fi
+  xorg_cv_cc_flag_unused_command_line_argument=no
 fi
-ac_ct_OBJDUMP=$ac_cv_prog_ac_ct_OBJDUMP
-if test -n "$ac_ct_OBJDUMP"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OBJDUMP" >&5
-$as_echo "$ac_ct_OBJDUMP" >&6; }
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 fi
-
-  if test "x$ac_ct_OBJDUMP" = x; then
-    OBJDUMP="false"
-  else
-    case $cross_compiling:$ac_tool_warned in
-yes:)
-{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
-$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
-ac_tool_warned=yes ;;
-esac
-    OBJDUMP=$ac_ct_OBJDUMP
-  fi
-else
-  OBJDUMP="$ac_cv_prog_OBJDUMP"
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unused_command_line_argument" >&5
+$as_echo "$xorg_cv_cc_flag_unused_command_line_argument" >&6; }
+       xorg_testset_cc_unused_command_line_argument=$xorg_cv_cc_flag_unused_command_line_argument
+       CFLAGS="$xorg_testset_save_CFLAGS"
 fi
 
-test -z "$OBJDUMP" && OBJDUMP=objdump
-
-
-
+found="no"
 
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
 
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
 
+               CFLAGS="$CFLAGS -Wold-style-definition"
 
-
-
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to recognize dependent libraries" >&5
-$as_echo_n "checking how to recognize dependent libraries... " >&6; }
-if test "${lt_cv_deplibs_check_method+set}" = set; then :
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-Wold-style-definition" >&5
+$as_echo_n "checking if $CC supports-Wold-style-definition... " >&6; }
+               cacheid=xorg_cv_cc_flag__Wold_style_definition
+               if eval \${$cacheid+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  lt_cv_file_magic_cmd='$MAGIC_CMD'
-lt_cv_file_magic_test_file=
-lt_cv_deplibs_check_method='unknown'
-# Need to set the preceding variable on all platforms that support
-# interlibrary dependencies.
-# 'none' -- dependencies not supported.
-# `unknown' -- same as none, but documents that we really don't know.
-# 'pass_all' -- all dependencies passed with no checks.
-# 'test_compile' -- check by making test program.
-# 'file_magic [[regex]]' -- check by looking for files in library path
-# which responds to the $file_magic_cmd with a given extended regex.
-# If you have `file' or equivalent on your system and you're not sure
-# whether `pass_all' will *always* work, you probably want this one.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+int
+main ()
+{
 
-case $host_os in
-aix[4-9]*)
-  lt_cv_deplibs_check_method=pass_all
-  ;;
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval $cacheid=yes
+else
+  eval $cacheid=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+fi
 
-beos*)
-  lt_cv_deplibs_check_method=pass_all
-  ;;
 
-bsdi[45]*)
-  lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [ML]SB (shared object|dynamic lib)'
-  lt_cv_file_magic_cmd='/usr/bin/file -L'
-  lt_cv_file_magic_test_file=/shlib/libc.so
-  ;;
+               CFLAGS="$xorg_testset_save_CFLAGS"
 
-cygwin*)
-  # func_win32_libid is a shell function defined in ltmain.sh
-  lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL'
-  lt_cv_file_magic_cmd='func_win32_libid'
-  ;;
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       BASE_CFLAGS="$BASE_CFLAGS -Wold-style-definition"
+                       found="yes"
+               fi
+       fi
 
-mingw* | pw32*)
-  # Base MSYS/MinGW do not provide the 'file' command needed by
-  # func_win32_libid shell function, so use a weaker test based on 'objdump',
-  # unless we find 'file', for example because we are cross-compiling.
-  if ( file / ) >/dev/null 2>&1; then
-    lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL'
-    lt_cv_file_magic_cmd='func_win32_libid'
-  else
-    lt_cv_deplibs_check_method='file_magic file format pei*-i386(.*architecture: i386)?'
-    lt_cv_file_magic_cmd='$OBJDUMP -f'
-  fi
-  ;;
 
-cegcc)
-  # use the weaker test based on 'objdump'. See mingw*.
-  lt_cv_deplibs_check_method='file_magic file format pe-arm-.*little(.*architecture: arm)?'
-  lt_cv_file_magic_cmd='$OBJDUMP -f'
-  ;;
 
-darwin* | rhapsody*)
-  lt_cv_deplibs_check_method=pass_all
-  ;;
 
-freebsd* | dragonfly*)
-  if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then
-    case $host_cpu in
-    i*86 )
-      # Not sure whether the presence of OpenBSD here was a mistake.
-      # Let's accept both of them until this is cleared up.
-      lt_cv_deplibs_check_method='file_magic (FreeBSD|OpenBSD|DragonFly)/i[3-9]86 (compact )?demand paged shared library'
-      lt_cv_file_magic_cmd=/usr/bin/file
-      lt_cv_file_magic_test_file=`echo /usr/lib/libc.so.*`
-      ;;
-    esac
-  else
-    lt_cv_deplibs_check_method=pass_all
-  fi
-  ;;
 
-gnu*)
-  lt_cv_deplibs_check_method=pass_all
-  ;;
 
-hpux10.20* | hpux11*)
-  lt_cv_file_magic_cmd=/usr/bin/file
-  case $host_cpu in
-  ia64*)
-    lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF-[0-9][0-9]) shared object file - IA64'
-    lt_cv_file_magic_test_file=/usr/lib/hpux32/libc.so
-    ;;
-  hppa*64*)
-    lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF-[0-9][0-9]) shared object file - PA-RISC [0-9].[0-9]'
-    lt_cv_file_magic_test_file=/usr/lib/pa20_64/libc.sl
-    ;;
-  *)
-    lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|PA-RISC[0-9].[0-9]) shared library'
-    lt_cv_file_magic_test_file=/usr/lib/libc.sl
-    ;;
-  esac
-  ;;
 
-interix[3-9]*)
-  # PIC code is broken on Interix 3.x, that's why |\.a not |_pic\.a here
-  lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so|\.a)$'
-  ;;
 
-irix5* | irix6* | nonstopux*)
-  case $LD in
-  *-32|*"-32 ") libmagic=32-bit;;
-  *-n32|*"-n32 ") libmagic=N32;;
-  *-64|*"-64 ") libmagic=64-bit;;
-  *) libmagic=never-match;;
-  esac
-  lt_cv_deplibs_check_method=pass_all
-  ;;
 
-# This must be Linux ELF.
-linux* | k*bsd*-gnu | kopensolaris*-gnu)
-  lt_cv_deplibs_check_method=pass_all
-  ;;
 
-netbsd* | netbsdelf*-gnu)
-  if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then
-    lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so\.[0-9]+\.[0-9]+|_pic\.a)$'
-  else
-    lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so|_pic\.a)$'
-  fi
-  ;;
 
-newos6*)
-  lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [ML]SB (executable|dynamic lib)'
-  lt_cv_file_magic_cmd=/usr/bin/file
-  lt_cv_file_magic_test_file=/usr/lib/libnls.so
-  ;;
 
-*nto* | *qnx*)
-  lt_cv_deplibs_check_method=pass_all
-  ;;
 
-openbsd*)
-  if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
-    lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so\.[0-9]+\.[0-9]+|\.so|_pic\.a)$'
-  else
-    lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so\.[0-9]+\.[0-9]+|_pic\.a)$'
-  fi
-  ;;
 
-osf3* | osf4* | osf5*)
-  lt_cv_deplibs_check_method=pass_all
-  ;;
 
-rdos*)
-  lt_cv_deplibs_check_method=pass_all
-  ;;
+xorg_testset_save_CFLAGS="$CFLAGS"
 
-solaris*)
-  lt_cv_deplibs_check_method=pass_all
-  ;;
+if test "x$xorg_testset_cc_unknown_warning_option" = "x" ; then
+       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unknown-warning-option" >&5
+$as_echo_n "checking if $CC supports -Werror=unknown-warning-option... " >&6; }
+if ${xorg_cv_cc_flag_unknown_warning_option+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unknown_warning_option=yes
+else
+  xorg_cv_cc_flag_unknown_warning_option=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unknown_warning_option" >&5
+$as_echo "$xorg_cv_cc_flag_unknown_warning_option" >&6; }
+       xorg_testset_cc_unknown_warning_option=$xorg_cv_cc_flag_unknown_warning_option
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
 
-sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*)
-  lt_cv_deplibs_check_method=pass_all
-  ;;
+if test "x$xorg_testset_cc_unused_command_line_argument" = "x" ; then
+       if test "x$xorg_testset_cc_unknown_warning_option" = "xyes" ; then
+               CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       fi
+       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unused-command-line-argument" >&5
+$as_echo_n "checking if $CC supports -Werror=unused-command-line-argument... " >&6; }
+if ${xorg_cv_cc_flag_unused_command_line_argument+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unused_command_line_argument=yes
+else
+  xorg_cv_cc_flag_unused_command_line_argument=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unused_command_line_argument" >&5
+$as_echo "$xorg_cv_cc_flag_unused_command_line_argument" >&6; }
+       xorg_testset_cc_unused_command_line_argument=$xorg_cv_cc_flag_unused_command_line_argument
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
 
-sysv4 | sysv4.3*)
-  case $host_vendor in
-  motorola)
-    lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [ML]SB (shared object|dynamic lib) M[0-9][0-9]* Version [0-9]'
-    lt_cv_file_magic_test_file=`echo /usr/lib/libc.so*`
-    ;;
-  ncr)
-    lt_cv_deplibs_check_method=pass_all
-    ;;
-  sequent)
-    lt_cv_file_magic_cmd='/bin/file'
-    lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [LM]SB (shared object|dynamic lib )'
-    ;;
-  sni)
-    lt_cv_file_magic_cmd='/bin/file'
-    lt_cv_deplibs_check_method="file_magic ELF [0-9][0-9]*-bit [LM]SB dynamic lib"
-    lt_cv_file_magic_test_file=/lib/libc.so
-    ;;
-  siemens)
-    lt_cv_deplibs_check_method=pass_all
-    ;;
-  pc)
-    lt_cv_deplibs_check_method=pass_all
-    ;;
-  esac
-  ;;
+found="no"
 
-tpf*)
-  lt_cv_deplibs_check_method=pass_all
-  ;;
-esac
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
+
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
+
+               CFLAGS="$CFLAGS -Wdeclaration-after-statement"
+
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-Wdeclaration-after-statement" >&5
+$as_echo_n "checking if $CC supports-Wdeclaration-after-statement... " >&6; }
+               cacheid=xorg_cv_cc_flag__Wdeclaration_after_statement
+               if eval \${$cacheid+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+int
+main ()
+{
 
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval $cacheid=yes
+else
+  eval $cacheid=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_deplibs_check_method" >&5
-$as_echo "$lt_cv_deplibs_check_method" >&6; }
-file_magic_cmd=$lt_cv_file_magic_cmd
-deplibs_check_method=$lt_cv_deplibs_check_method
-test -z "$deplibs_check_method" && deplibs_check_method=unknown
 
 
+               CFLAGS="$xorg_testset_save_CFLAGS"
 
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       BASE_CFLAGS="$BASE_CFLAGS -Wdeclaration-after-statement"
+                       found="yes"
+               fi
+       fi
 
 
 
 
 
+# This chunk adds additional warnings that could catch undesired effects.
 
 
 
 
-if test -n "$ac_tool_prefix"; then
-  # Extract the first word of "${ac_tool_prefix}ar", so it can be a program name with args.
-set dummy ${ac_tool_prefix}ar; ac_word=$2
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
-$as_echo_n "checking for $ac_word... " >&6; }
-if test "${ac_cv_prog_AR+set}" = set; then :
-  $as_echo_n "(cached) " >&6
-else
-  if test -n "$AR"; then
-  ac_cv_prog_AR="$AR" # Let the user override the test.
-else
-as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_prog_AR="${ac_tool_prefix}ar"
-    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
-    break 2
-  fi
-done
-  done
-IFS=$as_save_IFS
 
-fi
-fi
-AR=$ac_cv_prog_AR
-if test -n "$AR"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AR" >&5
-$as_echo "$AR" >&6; }
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-fi
 
 
-fi
-if test -z "$ac_cv_prog_AR"; then
-  ac_ct_AR=$AR
-  # Extract the first word of "ar", so it can be a program name with args.
-set dummy ar; ac_word=$2
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
-$as_echo_n "checking for $ac_word... " >&6; }
-if test "${ac_cv_prog_ac_ct_AR+set}" = set; then :
+
+
+
+
+
+
+xorg_testset_save_CFLAGS="$CFLAGS"
+
+if test "x$xorg_testset_cc_unknown_warning_option" = "x" ; then
+       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unknown-warning-option" >&5
+$as_echo_n "checking if $CC supports -Werror=unknown-warning-option... " >&6; }
+if ${xorg_cv_cc_flag_unknown_warning_option+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  if test -n "$ac_ct_AR"; then
-  ac_cv_prog_ac_ct_AR="$ac_ct_AR" # Let the user override the test.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unknown_warning_option=yes
 else
-as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_prog_ac_ct_AR="ar"
-    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
-    break 2
-  fi
-done
-  done
-IFS=$as_save_IFS
-
+  xorg_cv_cc_flag_unknown_warning_option=no
 fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 fi
-ac_ct_AR=$ac_cv_prog_ac_ct_AR
-if test -n "$ac_ct_AR"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_AR" >&5
-$as_echo "$ac_ct_AR" >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unknown_warning_option" >&5
+$as_echo "$xorg_cv_cc_flag_unknown_warning_option" >&6; }
+       xorg_testset_cc_unknown_warning_option=$xorg_cv_cc_flag_unknown_warning_option
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
+
+if test "x$xorg_testset_cc_unused_command_line_argument" = "x" ; then
+       if test "x$xorg_testset_cc_unknown_warning_option" = "xyes" ; then
+               CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       fi
+       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unused-command-line-argument" >&5
+$as_echo_n "checking if $CC supports -Werror=unused-command-line-argument... " >&6; }
+if ${xorg_cv_cc_flag_unused_command_line_argument+:} false; then :
+  $as_echo_n "(cached) " >&6
 else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unused_command_line_argument=yes
+else
+  xorg_cv_cc_flag_unused_command_line_argument=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unused_command_line_argument" >&5
+$as_echo "$xorg_cv_cc_flag_unused_command_line_argument" >&6; }
+       xorg_testset_cc_unused_command_line_argument=$xorg_cv_cc_flag_unused_command_line_argument
+       CFLAGS="$xorg_testset_save_CFLAGS"
 fi
 
-  if test "x$ac_ct_AR" = x; then
-    AR="false"
-  else
-    case $cross_compiling:$ac_tool_warned in
-yes:)
-{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
-$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
-ac_tool_warned=yes ;;
-esac
-    AR=$ac_ct_AR
-  fi
+found="no"
+
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
+
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
+
+               CFLAGS="$CFLAGS -Wunused"
+
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-Wunused" >&5
+$as_echo_n "checking if $CC supports-Wunused... " >&6; }
+               cacheid=xorg_cv_cc_flag__Wunused
+               if eval \${$cacheid+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval $cacheid=yes
 else
-  AR="$ac_cv_prog_AR"
+  eval $cacheid=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
 fi
 
-test -z "$AR" && AR=ar
-test -z "$AR_FLAGS" && AR_FLAGS=cru
 
+               CFLAGS="$xorg_testset_save_CFLAGS"
 
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       BASE_CFLAGS="$BASE_CFLAGS -Wunused"
+                       found="yes"
+               fi
+       fi
 
 
 
@@ -6116,220 +6240,238 @@ test -z "$AR_FLAGS" && AR_FLAGS=cru
 
 
 
-if test -n "$ac_tool_prefix"; then
-  # Extract the first word of "${ac_tool_prefix}strip", so it can be a program name with args.
-set dummy ${ac_tool_prefix}strip; ac_word=$2
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
-$as_echo_n "checking for $ac_word... " >&6; }
-if test "${ac_cv_prog_STRIP+set}" = set; then :
+
+
+
+
+
+
+xorg_testset_save_CFLAGS="$CFLAGS"
+
+if test "x$xorg_testset_cc_unknown_warning_option" = "x" ; then
+       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unknown-warning-option" >&5
+$as_echo_n "checking if $CC supports -Werror=unknown-warning-option... " >&6; }
+if ${xorg_cv_cc_flag_unknown_warning_option+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  if test -n "$STRIP"; then
-  ac_cv_prog_STRIP="$STRIP" # Let the user override the test.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unknown_warning_option=yes
 else
-as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_prog_STRIP="${ac_tool_prefix}strip"
-    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
-    break 2
-  fi
-done
-  done
-IFS=$as_save_IFS
-
+  xorg_cv_cc_flag_unknown_warning_option=no
 fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 fi
-STRIP=$ac_cv_prog_STRIP
-if test -n "$STRIP"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $STRIP" >&5
-$as_echo "$STRIP" >&6; }
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unknown_warning_option" >&5
+$as_echo "$xorg_cv_cc_flag_unknown_warning_option" >&6; }
+       xorg_testset_cc_unknown_warning_option=$xorg_cv_cc_flag_unknown_warning_option
+       CFLAGS="$xorg_testset_save_CFLAGS"
 fi
 
-
-fi
-if test -z "$ac_cv_prog_STRIP"; then
-  ac_ct_STRIP=$STRIP
-  # Extract the first word of "strip", so it can be a program name with args.
-set dummy strip; ac_word=$2
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
-$as_echo_n "checking for $ac_word... " >&6; }
-if test "${ac_cv_prog_ac_ct_STRIP+set}" = set; then :
+if test "x$xorg_testset_cc_unused_command_line_argument" = "x" ; then
+       if test "x$xorg_testset_cc_unknown_warning_option" = "xyes" ; then
+               CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       fi
+       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unused-command-line-argument" >&5
+$as_echo_n "checking if $CC supports -Werror=unused-command-line-argument... " >&6; }
+if ${xorg_cv_cc_flag_unused_command_line_argument+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  if test -n "$ac_ct_STRIP"; then
-  ac_cv_prog_ac_ct_STRIP="$ac_ct_STRIP" # Let the user override the test.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unused_command_line_argument=yes
 else
-as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_prog_ac_ct_STRIP="strip"
-    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
-    break 2
-  fi
-done
-  done
-IFS=$as_save_IFS
-
+  xorg_cv_cc_flag_unused_command_line_argument=no
 fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 fi
-ac_ct_STRIP=$ac_cv_prog_ac_ct_STRIP
-if test -n "$ac_ct_STRIP"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_STRIP" >&5
-$as_echo "$ac_ct_STRIP" >&6; }
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unused_command_line_argument" >&5
+$as_echo "$xorg_cv_cc_flag_unused_command_line_argument" >&6; }
+       xorg_testset_cc_unused_command_line_argument=$xorg_cv_cc_flag_unused_command_line_argument
+       CFLAGS="$xorg_testset_save_CFLAGS"
 fi
 
-  if test "x$ac_ct_STRIP" = x; then
-    STRIP=":"
-  else
-    case $cross_compiling:$ac_tool_warned in
-yes:)
-{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
-$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
-ac_tool_warned=yes ;;
-esac
-    STRIP=$ac_ct_STRIP
-  fi
+found="no"
+
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
+
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
+
+               CFLAGS="$CFLAGS -Wuninitialized"
+
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-Wuninitialized" >&5
+$as_echo_n "checking if $CC supports-Wuninitialized... " >&6; }
+               cacheid=xorg_cv_cc_flag__Wuninitialized
+               if eval \${$cacheid+:} false; then :
+  $as_echo_n "(cached) " >&6
 else
-  STRIP="$ac_cv_prog_STRIP"
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval $cacheid=yes
+else
+  eval $cacheid=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
 fi
 
-test -z "$STRIP" && STRIP=:
 
+               CFLAGS="$xorg_testset_save_CFLAGS"
+
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       BASE_CFLAGS="$BASE_CFLAGS -Wuninitialized"
+                       found="yes"
+               fi
+       fi
 
 
 
 
 
-if test -n "$ac_tool_prefix"; then
-  # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args.
-set dummy ${ac_tool_prefix}ranlib; ac_word=$2
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
-$as_echo_n "checking for $ac_word... " >&6; }
-if test "${ac_cv_prog_RANLIB+set}" = set; then :
+
+
+
+
+
+
+
+
+
+
+xorg_testset_save_CFLAGS="$CFLAGS"
+
+if test "x$xorg_testset_cc_unknown_warning_option" = "x" ; then
+       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unknown-warning-option" >&5
+$as_echo_n "checking if $CC supports -Werror=unknown-warning-option... " >&6; }
+if ${xorg_cv_cc_flag_unknown_warning_option+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  if test -n "$RANLIB"; then
-  ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unknown_warning_option=yes
 else
-as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib"
-    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
-    break 2
-  fi
-done
-  done
-IFS=$as_save_IFS
-
+  xorg_cv_cc_flag_unknown_warning_option=no
 fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 fi
-RANLIB=$ac_cv_prog_RANLIB
-if test -n "$RANLIB"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $RANLIB" >&5
-$as_echo "$RANLIB" >&6; }
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unknown_warning_option" >&5
+$as_echo "$xorg_cv_cc_flag_unknown_warning_option" >&6; }
+       xorg_testset_cc_unknown_warning_option=$xorg_cv_cc_flag_unknown_warning_option
+       CFLAGS="$xorg_testset_save_CFLAGS"
 fi
 
-
-fi
-if test -z "$ac_cv_prog_RANLIB"; then
-  ac_ct_RANLIB=$RANLIB
-  # Extract the first word of "ranlib", so it can be a program name with args.
-set dummy ranlib; ac_word=$2
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
-$as_echo_n "checking for $ac_word... " >&6; }
-if test "${ac_cv_prog_ac_ct_RANLIB+set}" = set; then :
+if test "x$xorg_testset_cc_unused_command_line_argument" = "x" ; then
+       if test "x$xorg_testset_cc_unknown_warning_option" = "xyes" ; then
+               CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       fi
+       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unused-command-line-argument" >&5
+$as_echo_n "checking if $CC supports -Werror=unused-command-line-argument... " >&6; }
+if ${xorg_cv_cc_flag_unused_command_line_argument+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  if test -n "$ac_ct_RANLIB"; then
-  ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unused_command_line_argument=yes
 else
-as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_prog_ac_ct_RANLIB="ranlib"
-    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
-    break 2
-  fi
-done
-  done
-IFS=$as_save_IFS
-
+  xorg_cv_cc_flag_unused_command_line_argument=no
 fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 fi
-ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB
-if test -n "$ac_ct_RANLIB"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_RANLIB" >&5
-$as_echo "$ac_ct_RANLIB" >&6; }
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unused_command_line_argument" >&5
+$as_echo "$xorg_cv_cc_flag_unused_command_line_argument" >&6; }
+       xorg_testset_cc_unused_command_line_argument=$xorg_cv_cc_flag_unused_command_line_argument
+       CFLAGS="$xorg_testset_save_CFLAGS"
 fi
 
-  if test "x$ac_ct_RANLIB" = x; then
-    RANLIB=":"
-  else
-    case $cross_compiling:$ac_tool_warned in
-yes:)
-{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
-$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
-ac_tool_warned=yes ;;
-esac
-    RANLIB=$ac_ct_RANLIB
-  fi
+found="no"
+
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
+
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
+
+               CFLAGS="$CFLAGS -Wshadow"
+
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-Wshadow" >&5
+$as_echo_n "checking if $CC supports-Wshadow... " >&6; }
+               cacheid=xorg_cv_cc_flag__Wshadow
+               if eval \${$cacheid+:} false; then :
+  $as_echo_n "(cached) " >&6
 else
-  RANLIB="$ac_cv_prog_RANLIB"
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval $cacheid=yes
+else
+  eval $cacheid=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
 fi
 
-test -z "$RANLIB" && RANLIB=:
 
+               CFLAGS="$xorg_testset_save_CFLAGS"
 
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       BASE_CFLAGS="$BASE_CFLAGS -Wshadow"
+                       found="yes"
+               fi
+       fi
 
 
 
 
-# Determine commands to create old-style static archives.
-old_archive_cmds='$AR $AR_FLAGS $oldlib$oldobjs'
-old_postinstall_cmds='chmod 644 $oldlib'
-old_postuninstall_cmds=
 
-if test -n "$RANLIB"; then
-  case $host_os in
-  openbsd*)
-    old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB -t \$oldlib"
-    ;;
-  *)
-    old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB \$oldlib"
-    ;;
-  esac
-  old_archive_cmds="$old_archive_cmds~\$RANLIB \$oldlib"
-fi
 
 
 
 
 
 
+xorg_testset_save_CFLAGS="$CFLAGS"
 
+if test "x$xorg_testset_cc_unknown_warning_option" = "x" ; then
+       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unknown-warning-option" >&5
+$as_echo_n "checking if $CC supports -Werror=unknown-warning-option... " >&6; }
+if ${xorg_cv_cc_flag_unknown_warning_option+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unknown_warning_option=yes
+else
+  xorg_cv_cc_flag_unknown_warning_option=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unknown_warning_option" >&5
+$as_echo "$xorg_cv_cc_flag_unknown_warning_option" >&6; }
+       xorg_testset_cc_unknown_warning_option=$xorg_cv_cc_flag_unknown_warning_option
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
 
+if test "x$xorg_testset_cc_unused_command_line_argument" = "x" ; then
+       if test "x$xorg_testset_cc_unknown_warning_option" = "xyes" ; then
+               CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       fi
+       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unused-command-line-argument" >&5
+$as_echo_n "checking if $CC supports -Werror=unused-command-line-argument... " >&6; }
+if ${xorg_cv_cc_flag_unused_command_line_argument+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unused_command_line_argument=yes
+else
+  xorg_cv_cc_flag_unused_command_line_argument=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unused_command_line_argument" >&5
+$as_echo "$xorg_cv_cc_flag_unused_command_line_argument" >&6; }
+       xorg_testset_cc_unused_command_line_argument=$xorg_cv_cc_flag_unused_command_line_argument
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
 
+found="no"
 
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
 
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
 
+               CFLAGS="$CFLAGS -Wcast-qual"
 
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-Wcast-qual" >&5
+$as_echo_n "checking if $CC supports-Wcast-qual... " >&6; }
+               cacheid=xorg_cv_cc_flag__Wcast_qual
+               if eval \${$cacheid+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+int
+main ()
+{
 
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval $cacheid=yes
+else
+  eval $cacheid=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+fi
 
 
+               CFLAGS="$xorg_testset_save_CFLAGS"
 
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       BASE_CFLAGS="$BASE_CFLAGS -Wcast-qual"
+                       found="yes"
+               fi
+       fi
 
 
 
 
 
 
-# If no C compiler was specified, use CC.
-LTCC=${LTCC-"$CC"}
 
-# If no C compiler flags were specified, use CFLAGS.
-LTCFLAGS=${LTCFLAGS-"$CFLAGS"}
 
-# Allow CC to be a program name with arguments.
-compiler=$CC
+xorg_testset_save_CFLAGS="$CFLAGS"
 
+if test "x$xorg_testset_cc_unknown_warning_option" = "x" ; then
+       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unknown-warning-option" >&5
+$as_echo_n "checking if $CC supports -Werror=unknown-warning-option... " >&6; }
+if ${xorg_cv_cc_flag_unknown_warning_option+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unknown_warning_option=yes
+else
+  xorg_cv_cc_flag_unknown_warning_option=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unknown_warning_option" >&5
+$as_echo "$xorg_cv_cc_flag_unknown_warning_option" >&6; }
+       xorg_testset_cc_unknown_warning_option=$xorg_cv_cc_flag_unknown_warning_option
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
 
-# Check for command to grab the raw symbol name followed by C symbol from nm.
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking command to parse $NM output from $compiler object" >&5
-$as_echo_n "checking command to parse $NM output from $compiler object... " >&6; }
-if test "${lt_cv_sys_global_symbol_pipe+set}" = set; then :
+if test "x$xorg_testset_cc_unused_command_line_argument" = "x" ; then
+       if test "x$xorg_testset_cc_unknown_warning_option" = "xyes" ; then
+               CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       fi
+       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unused-command-line-argument" >&5
+$as_echo_n "checking if $CC supports -Werror=unused-command-line-argument... " >&6; }
+if ${xorg_cv_cc_flag_unused_command_line_argument+:} false; then :
   $as_echo_n "(cached) " >&6
 else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unused_command_line_argument=yes
+else
+  xorg_cv_cc_flag_unused_command_line_argument=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unused_command_line_argument" >&5
+$as_echo "$xorg_cv_cc_flag_unused_command_line_argument" >&6; }
+       xorg_testset_cc_unused_command_line_argument=$xorg_cv_cc_flag_unused_command_line_argument
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
 
-# These are sane defaults that work on at least a few old systems.
-# [They come from Ultrix.  What could be older than Ultrix?!! ;)]
+found="no"
 
-# Character class describing NM global symbol codes.
-symcode='[BCDEGRST]'
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
 
-# Regexp to match symbols that can be accessed directly from C.
-sympat='\([_A-Za-z][_A-Za-z0-9]*\)'
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
 
-# Define system-specific variables.
-case $host_os in
-aix*)
-  symcode='[BCDT]'
-  ;;
-cygwin* | mingw* | pw32* | cegcc*)
-  symcode='[ABCDGISTW]'
-  ;;
-hpux*)
-  if test "$host_cpu" = ia64; then
-    symcode='[ABCDEGRST]'
-  fi
-  ;;
-irix* | nonstopux*)
-  symcode='[BCDEGRST]'
-  ;;
-osf*)
-  symcode='[BCDEGQRST]'
-  ;;
-solaris*)
-  symcode='[BDRT]'
-  ;;
-sco3.2v5*)
-  symcode='[DT]'
-  ;;
-sysv4.2uw2*)
-  symcode='[DT]'
-  ;;
-sysv5* | sco5v6* | unixware* | OpenUNIX*)
-  symcode='[ABDT]'
-  ;;
-sysv4)
-  symcode='[DFNSTU]'
-  ;;
-esac
+               CFLAGS="$CFLAGS -Wmissing-noreturn"
 
-# If we're using GNU nm, then use its standard symbol codes.
-case `$NM -V 2>&1` in
-*GNU* | *'with BFD'*)
-  symcode='[ABCDGIRSTW]' ;;
-esac
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-Wmissing-noreturn" >&5
+$as_echo_n "checking if $CC supports-Wmissing-noreturn... " >&6; }
+               cacheid=xorg_cv_cc_flag__Wmissing_noreturn
+               if eval \${$cacheid+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+int
+main ()
+{
 
-# Transform an extracted symbol line into a proper C declaration.
-# Some systems (esp. on ia64) link data and code symbols differently,
-# so use this general approach.
-lt_cv_sys_global_symbol_to_cdecl="sed -n -e 's/^T .* \(.*\)$/extern int \1();/p' -e 's/^$symcode* .* \(.*\)$/extern char \1;/p'"
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval $cacheid=yes
+else
+  eval $cacheid=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+fi
 
-# Transform an extracted symbol line into symbol name and symbol address
-lt_cv_sys_global_symbol_to_c_name_address="sed -n -e 's/^: \([^ ]*\) $/  {\\\"\1\\\", (void *) 0},/p' -e 's/^$symcode* \([^ ]*\) \([^ ]*\)$/  {\"\2\", (void *) \&\2},/p'"
-lt_cv_sys_global_symbol_to_c_name_address_lib_prefix="sed -n -e 's/^: \([^ ]*\) $/  {\\\"\1\\\", (void *) 0},/p' -e 's/^$symcode* \([^ ]*\) \(lib[^ ]*\)$/  {\"\2\", (void *) \&\2},/p' -e 's/^$symcode* \([^ ]*\) \([^ ]*\)$/  {\"lib\2\", (void *) \&\2},/p'"
 
-# Handle CRLF in mingw tool chain
-opt_cr=
-case $build_os in
-mingw*)
-  opt_cr=`$ECHO 'x\{0,1\}' | tr x '\015'` # option cr in regexp
-  ;;
-esac
+               CFLAGS="$xorg_testset_save_CFLAGS"
 
-# Try without a prefix underscore, then with it.
-for ac_symprfx in "" "_"; do
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       BASE_CFLAGS="$BASE_CFLAGS -Wmissing-noreturn"
+                       found="yes"
+               fi
+       fi
 
-  # Transform symcode, sympat, and symprfx into a raw symbol and a C symbol.
-  symxfrm="\\1 $ac_symprfx\\2 \\2"
 
-  # Write the raw and C identifiers.
-  if test "$lt_cv_nm_interface" = "MS dumpbin"; then
-    # Fake it for dumpbin and say T for any non-static function
-    # and D for any global variable.
-    # Also find C++ and __fastcall symbols from MSVC++,
-    # which start with @ or ?.
-    lt_cv_sys_global_symbol_pipe="$AWK '"\
-"     {last_section=section; section=\$ 3};"\
-"     /Section length .*#relocs.*(pick any)/{hide[last_section]=1};"\
-"     \$ 0!~/External *\|/{next};"\
-"     / 0+ UNDEF /{next}; / UNDEF \([^|]\)*()/{next};"\
-"     {if(hide[section]) next};"\
-"     {f=0}; \$ 0~/\(\).*\|/{f=1}; {printf f ? \"T \" : \"D \"};"\
-"     {split(\$ 0, a, /\||\r/); split(a[2], s)};"\
-"     s[1]~/^[@?]/{print s[1], s[1]; next};"\
-"     s[1]~prfx {split(s[1],t,\"@\"); print t[1], substr(t[1],length(prfx))}"\
-"     ' prfx=^$ac_symprfx"
-  else
-    lt_cv_sys_global_symbol_pipe="sed -n -e 's/^.*[     ]\($symcode$symcode*\)[         ][      ]*$ac_symprfx$sympat$opt_cr$/$symxfrm/p'"
-  fi
 
-  # Check to see that the pipe works correctly.
-  pipe_works=no
 
-  rm -f conftest*
-  cat > conftest.$ac_ext <<_LT_EOF
-#ifdef __cplusplus
-extern "C" {
-#endif
-char nm_test_var;
-void nm_test_func(void);
-void nm_test_func(void){}
-#ifdef __cplusplus
-}
-#endif
-int main(){nm_test_var='a';nm_test_func();return(0);}
-_LT_EOF
 
-  if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5
-  (eval $ac_compile) 2>&5
-  ac_status=$?
-  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
-  test $ac_status = 0; }; then
-    # Now try to grab the symbols.
-    nlist=conftest.nm
-    if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$NM conftest.$ac_objext \| $lt_cv_sys_global_symbol_pipe \> $nlist\""; } >&5
-  (eval $NM conftest.$ac_objext \| $lt_cv_sys_global_symbol_pipe \> $nlist) 2>&5
-  ac_status=$?
-  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
-  test $ac_status = 0; } && test -s "$nlist"; then
-      # Try sorting and uniquifying the output.
-      if sort "$nlist" | uniq > "$nlist"T; then
-       mv -f "$nlist"T "$nlist"
-      else
-       rm -f "$nlist"T
-      fi
 
-      # Make sure that we snagged all the symbols we need.
-      if $GREP ' nm_test_var$' "$nlist" >/dev/null; then
-       if $GREP ' nm_test_func$' "$nlist" >/dev/null; then
-         cat <<_LT_EOF > conftest.$ac_ext
-#ifdef __cplusplus
-extern "C" {
-#endif
 
-_LT_EOF
-         # Now generate the symbol file.
-         eval "$lt_cv_sys_global_symbol_to_cdecl"' < "$nlist" | $GREP -v main >> conftest.$ac_ext'
 
-         cat <<_LT_EOF >> conftest.$ac_ext
 
-/* The mapping between symbol names and symbols.  */
-const struct {
-  const char *name;
-  void       *address;
-}
-lt__PROGRAM__LTX_preloaded_symbols[] =
+
+
+
+
+
+
+xorg_testset_save_CFLAGS="$CFLAGS"
+
+if test "x$xorg_testset_cc_unknown_warning_option" = "x" ; then
+       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unknown-warning-option" >&5
+$as_echo_n "checking if $CC supports -Werror=unknown-warning-option... " >&6; }
+if ${xorg_cv_cc_flag_unknown_warning_option+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unknown_warning_option=yes
+else
+  xorg_cv_cc_flag_unknown_warning_option=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unknown_warning_option" >&5
+$as_echo "$xorg_cv_cc_flag_unknown_warning_option" >&6; }
+       xorg_testset_cc_unknown_warning_option=$xorg_cv_cc_flag_unknown_warning_option
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
+
+if test "x$xorg_testset_cc_unused_command_line_argument" = "x" ; then
+       if test "x$xorg_testset_cc_unknown_warning_option" = "xyes" ; then
+               CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       fi
+       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unused-command-line-argument" >&5
+$as_echo_n "checking if $CC supports -Werror=unused-command-line-argument... " >&6; }
+if ${xorg_cv_cc_flag_unused_command_line_argument+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unused_command_line_argument=yes
+else
+  xorg_cv_cc_flag_unused_command_line_argument=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unused_command_line_argument" >&5
+$as_echo "$xorg_cv_cc_flag_unused_command_line_argument" >&6; }
+       xorg_testset_cc_unused_command_line_argument=$xorg_cv_cc_flag_unused_command_line_argument
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
+
+found="no"
+
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
+
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
+
+               CFLAGS="$CFLAGS -Wmissing-format-attribute"
+
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-Wmissing-format-attribute" >&5
+$as_echo_n "checking if $CC supports-Wmissing-format-attribute... " >&6; }
+               cacheid=xorg_cv_cc_flag__Wmissing_format_attribute
+               if eval \${$cacheid+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+int
+main ()
 {
-  { "@PROGRAM@", (void *) 0 },
-_LT_EOF
-         $SED "s/^$symcode$symcode* \(.*\) \(.*\)$/  {\"\2\", (void *) \&\2},/" < "$nlist" | $GREP -v main >> conftest.$ac_ext
-         cat <<\_LT_EOF >> conftest.$ac_ext
-  {0, (void *) 0}
-};
 
-/* This works around a problem in FreeBSD linker */
-#ifdef FREEBSD_WORKAROUND
-static const void *lt_preloaded_setup() {
-  return lt__PROGRAM__LTX_preloaded_symbols;
+  ;
+  return 0;
 }
-#endif
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval $cacheid=yes
+else
+  eval $cacheid=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+fi
 
-#ifdef __cplusplus
-}
-#endif
-_LT_EOF
-         # Now try linking the two files.
-         mv conftest.$ac_objext conftstm.$ac_objext
-         lt_save_LIBS="$LIBS"
-         lt_save_CFLAGS="$CFLAGS"
-         LIBS="conftstm.$ac_objext"
-         CFLAGS="$CFLAGS$lt_prog_compiler_no_builtin_flag"
-         if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_link\""; } >&5
-  (eval $ac_link) 2>&5
-  ac_status=$?
-  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
-  test $ac_status = 0; } && test -s conftest${ac_exeext}; then
-           pipe_works=yes
-         fi
-         LIBS="$lt_save_LIBS"
-         CFLAGS="$lt_save_CFLAGS"
-       else
-         echo "cannot find nm_test_func in $nlist" >&5
+
+               CFLAGS="$xorg_testset_save_CFLAGS"
+
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       BASE_CFLAGS="$BASE_CFLAGS -Wmissing-format-attribute"
+                       found="yes"
+               fi
        fi
-      else
-       echo "cannot find nm_test_var in $nlist" >&5
-      fi
-    else
-      echo "cannot run $lt_cv_sys_global_symbol_pipe" >&5
-    fi
-  else
-    echo "$progname: failed program was:" >&5
-    cat conftest.$ac_ext >&5
-  fi
-  rm -rf conftest* conftst*
 
-  # Do not use the global_symbol_pipe unless it works.
-  if test "$pipe_works" = yes; then
-    break
-  else
-    lt_cv_sys_global_symbol_pipe=
-  fi
-done
 
+
+
+
+
+
+
+
+
+
+
+
+
+
+xorg_testset_save_CFLAGS="$CFLAGS"
+
+if test "x$xorg_testset_cc_unknown_warning_option" = "x" ; then
+       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unknown-warning-option" >&5
+$as_echo_n "checking if $CC supports -Werror=unknown-warning-option... " >&6; }
+if ${xorg_cv_cc_flag_unknown_warning_option+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unknown_warning_option=yes
+else
+  xorg_cv_cc_flag_unknown_warning_option=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unknown_warning_option" >&5
+$as_echo "$xorg_cv_cc_flag_unknown_warning_option" >&6; }
+       xorg_testset_cc_unknown_warning_option=$xorg_cv_cc_flag_unknown_warning_option
+       CFLAGS="$xorg_testset_save_CFLAGS"
 fi
 
-if test -z "$lt_cv_sys_global_symbol_pipe"; then
-  lt_cv_sys_global_symbol_to_cdecl=
+if test "x$xorg_testset_cc_unused_command_line_argument" = "x" ; then
+       if test "x$xorg_testset_cc_unknown_warning_option" = "xyes" ; then
+               CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       fi
+       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unused-command-line-argument" >&5
+$as_echo_n "checking if $CC supports -Werror=unused-command-line-argument... " >&6; }
+if ${xorg_cv_cc_flag_unused_command_line_argument+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unused_command_line_argument=yes
+else
+  xorg_cv_cc_flag_unused_command_line_argument=no
 fi
-if test -z "$lt_cv_sys_global_symbol_pipe$lt_cv_sys_global_symbol_to_cdecl"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: failed" >&5
-$as_echo "failed" >&6; }
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unused_command_line_argument" >&5
+$as_echo "$xorg_cv_cc_flag_unused_command_line_argument" >&6; }
+       xorg_testset_cc_unused_command_line_argument=$xorg_cv_cc_flag_unused_command_line_argument
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
+
+found="no"
+
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
+
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
+
+               CFLAGS="$CFLAGS -Wredundant-decls"
+
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-Wredundant-decls" >&5
+$as_echo_n "checking if $CC supports-Wredundant-decls... " >&6; }
+               cacheid=xorg_cv_cc_flag__Wredundant_decls
+               if eval \${$cacheid+:} false; then :
+  $as_echo_n "(cached) " >&6
 else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: ok" >&5
-$as_echo "ok" >&6; }
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval $cacheid=yes
+else
+  eval $cacheid=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
 fi
 
 
+               CFLAGS="$xorg_testset_save_CFLAGS"
 
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       BASE_CFLAGS="$BASE_CFLAGS -Wredundant-decls"
+                       found="yes"
+               fi
+       fi
 
 
 
+# These are currently disabled because they are noisy.  They will be enabled
+# in the future once the codebase is sufficiently modernized to silence
+# them.  For now, I don't want them to drown out the other warnings.
+# XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wlogical-op])
+# XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wparentheses])
+# XORG_TESTSET_CFLAG([[BASE_]PREFIX[FLAGS]], [-Wcast-align])
 
+# Turn some warnings into errors, so we don't accidently get successful builds
+# when there are problems that should be fixed.
 
+if test "x$SELECTIVE_WERROR" = "xyes" ; then
 
 
 
 
 
 
+xorg_testset_save_CFLAGS="$CFLAGS"
 
-# Check whether --enable-libtool-lock was given.
-if test "${enable_libtool_lock+set}" = set; then :
-  enableval=$enable_libtool_lock;
+if test "x$xorg_testset_cc_unknown_warning_option" = "x" ; then
+       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unknown-warning-option" >&5
+$as_echo_n "checking if $CC supports -Werror=unknown-warning-option... " >&6; }
+if ${xorg_cv_cc_flag_unknown_warning_option+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unknown_warning_option=yes
+else
+  xorg_cv_cc_flag_unknown_warning_option=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unknown_warning_option" >&5
+$as_echo "$xorg_cv_cc_flag_unknown_warning_option" >&6; }
+       xorg_testset_cc_unknown_warning_option=$xorg_cv_cc_flag_unknown_warning_option
+       CFLAGS="$xorg_testset_save_CFLAGS"
 fi
 
-test "x$enable_libtool_lock" != xno && enable_libtool_lock=yes
+if test "x$xorg_testset_cc_unused_command_line_argument" = "x" ; then
+       if test "x$xorg_testset_cc_unknown_warning_option" = "xyes" ; then
+               CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       fi
+       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unused-command-line-argument" >&5
+$as_echo_n "checking if $CC supports -Werror=unused-command-line-argument... " >&6; }
+if ${xorg_cv_cc_flag_unused_command_line_argument+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unused_command_line_argument=yes
+else
+  xorg_cv_cc_flag_unused_command_line_argument=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unused_command_line_argument" >&5
+$as_echo "$xorg_cv_cc_flag_unused_command_line_argument" >&6; }
+       xorg_testset_cc_unused_command_line_argument=$xorg_cv_cc_flag_unused_command_line_argument
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
 
-# Some flags need to be propagated to the compiler or linker for good
-# libtool support.
-case $host in
-ia64-*-hpux*)
-  # Find out which ABI we are using.
-  echo 'int i;' > conftest.$ac_ext
-  if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5
-  (eval $ac_compile) 2>&5
-  ac_status=$?
-  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
-  test $ac_status = 0; }; then
-    case `/usr/bin/file conftest.$ac_objext` in
-      *ELF-32*)
-       HPUX_IA64_MODE="32"
-       ;;
-      *ELF-64*)
-       HPUX_IA64_MODE="64"
-       ;;
-    esac
-  fi
-  rm -rf conftest*
-  ;;
-*-*-irix6*)
-  # Find out which ABI we are using.
-  echo '#line 6657 "configure"' > conftest.$ac_ext
-  if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5
-  (eval $ac_compile) 2>&5
-  ac_status=$?
-  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
-  test $ac_status = 0; }; then
-    if test "$lt_cv_prog_gnu_ld" = yes; then
-      case `/usr/bin/file conftest.$ac_objext` in
-       *32-bit*)
-         LD="${LD-ld} -melf32bsmip"
-         ;;
-       *N32*)
-         LD="${LD-ld} -melf32bmipn32"
-         ;;
-       *64-bit*)
-         LD="${LD-ld} -melf64bmip"
-       ;;
-      esac
-    else
-      case `/usr/bin/file conftest.$ac_objext` in
-       *32-bit*)
-         LD="${LD-ld} -32"
-         ;;
-       *N32*)
-         LD="${LD-ld} -n32"
-         ;;
-       *64-bit*)
-         LD="${LD-ld} -64"
-         ;;
-      esac
-    fi
-  fi
-  rm -rf conftest*
-  ;;
+found="no"
 
-x86_64-*kfreebsd*-gnu|x86_64-*linux*|ppc*-*linux*|powerpc*-*linux*| \
-s390*-*linux*|s390*-*tpf*|sparc*-*linux*)
-  # Find out which ABI we are using.
-  echo 'int i;' > conftest.$ac_ext
-  if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5
-  (eval $ac_compile) 2>&5
-  ac_status=$?
-  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
-  test $ac_status = 0; }; then
-    case `/usr/bin/file conftest.o` in
-      *32-bit*)
-       case $host in
-         x86_64-*kfreebsd*-gnu)
-           LD="${LD-ld} -m elf_i386_fbsd"
-           ;;
-         x86_64-*linux*)
-           LD="${LD-ld} -m elf_i386"
-           ;;
-         ppc64-*linux*|powerpc64-*linux*)
-           LD="${LD-ld} -m elf32ppclinux"
-           ;;
-         s390x-*linux*)
-           LD="${LD-ld} -m elf_s390"
-           ;;
-         sparc64-*linux*)
-           LD="${LD-ld} -m elf32_sparc"
-           ;;
-       esac
-       ;;
-      *64-bit*)
-       case $host in
-         x86_64-*kfreebsd*-gnu)
-           LD="${LD-ld} -m elf_x86_64_fbsd"
-           ;;
-         x86_64-*linux*)
-           LD="${LD-ld} -m elf_x86_64"
-           ;;
-         ppc*-*linux*|powerpc*-*linux*)
-           LD="${LD-ld} -m elf64ppc"
-           ;;
-         s390*-*linux*|s390*-*tpf*)
-           LD="${LD-ld} -m elf64_s390"
-           ;;
-         sparc*-*linux*)
-           LD="${LD-ld} -m elf64_sparc"
-           ;;
-       esac
-       ;;
-    esac
-  fi
-  rm -rf conftest*
-  ;;
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
 
-*-*-sco3.2v5*)
-  # On SCO OpenServer 5, we need -belf to get full-featured binaries.
-  SAVE_CFLAGS="$CFLAGS"
-  CFLAGS="$CFLAGS -belf"
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler needs -belf" >&5
-$as_echo_n "checking whether the C compiler needs -belf... " >&6; }
-if test "${lt_cv_cc_needs_belf+set}" = set; then :
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
+
+               CFLAGS="$CFLAGS -Werror=implicit"
+
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-Werror=implicit" >&5
+$as_echo_n "checking if $CC supports-Werror=implicit... " >&6; }
+               cacheid=xorg_cv_cc_flag__Werror_implicit
+               if eval \${$cacheid+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  ac_ext=c
-ac_cpp='$CPP $CPPFLAGS'
-ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
-ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
-ac_compiler_gnu=$ac_cv_c_compiler_gnu
-
-     cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
-
+int i;
 int
 main ()
 {
@@ -6769,518 +7050,546 @@ main ()
 }
 _ACEOF
 if ac_fn_c_try_link "$LINENO"; then :
-  lt_cv_cc_needs_belf=yes
+  eval $cacheid=yes
 else
-  lt_cv_cc_needs_belf=no
+  eval $cacheid=no
 fi
 rm -f core conftest.err conftest.$ac_objext \
     conftest$ac_exeext conftest.$ac_ext
-     ac_ext=c
-ac_cpp='$CPP $CPPFLAGS'
-ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
-ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
-ac_compiler_gnu=$ac_cv_c_compiler_gnu
-
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_cc_needs_belf" >&5
-$as_echo "$lt_cv_cc_needs_belf" >&6; }
-  if test x"$lt_cv_cc_needs_belf" != x"yes"; then
-    # this is probably gcc 2.8.0, egcs 1.0 or newer; no need for -belf
-    CFLAGS="$SAVE_CFLAGS"
-  fi
-  ;;
-sparc*-*solaris*)
-  # Find out which ABI we are using.
-  echo 'int i;' > conftest.$ac_ext
-  if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5
-  (eval $ac_compile) 2>&5
-  ac_status=$?
-  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
-  test $ac_status = 0; }; then
-    case `/usr/bin/file conftest.o` in
-    *64-bit*)
-      case $lt_cv_prog_gnu_ld in
-      yes*) LD="${LD-ld} -m elf64_sparc" ;;
-      *)
-       if ${LD-ld} -64 -r -o conftest2.o conftest.o >/dev/null 2>&1; then
-         LD="${LD-ld} -64"
+
+
+               CFLAGS="$xorg_testset_save_CFLAGS"
+
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       BASE_CFLAGS="$BASE_CFLAGS -Werror=implicit"
+                       found="yes"
+               fi
        fi
-       ;;
-      esac
-      ;;
-    esac
-  fi
-  rm -rf conftest*
-  ;;
-esac
 
-need_locks="$enable_libtool_lock"
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
 
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
 
-  case $host_os in
-    rhapsody* | darwin*)
-    if test -n "$ac_tool_prefix"; then
-  # Extract the first word of "${ac_tool_prefix}dsymutil", so it can be a program name with args.
-set dummy ${ac_tool_prefix}dsymutil; ac_word=$2
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
-$as_echo_n "checking for $ac_word... " >&6; }
-if test "${ac_cv_prog_DSYMUTIL+set}" = set; then :
+               CFLAGS="$CFLAGS -errwarn=E_NO_EXPLICIT_TYPE_GIVEN -errwarn=E_NO_IMPLICIT_DECL_ALLOWED"
+
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-errwarn=E_NO_EXPLICIT_TYPE_GIVEN -errwarn=E_NO_IMPLICIT_DECL_ALLOWED" >&5
+$as_echo_n "checking if $CC supports-errwarn=E_NO_EXPLICIT_TYPE_GIVEN -errwarn=E_NO_IMPLICIT_DECL_ALLOWED... " >&6; }
+               cacheid=xorg_cv_cc_flag__errwarn_E_NO_EXPLICIT_TYPE_GIVEN__errwarn_E_NO_IMPLICIT_DECL_ALLOWED
+               if eval \${$cacheid+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  if test -n "$DSYMUTIL"; then
-  ac_cv_prog_DSYMUTIL="$DSYMUTIL" # Let the user override the test.
-else
-as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_prog_DSYMUTIL="${ac_tool_prefix}dsymutil"
-    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
-    break 2
-  fi
-done
-  done
-IFS=$as_save_IFS
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+int
+main ()
+{
 
-fi
-fi
-DSYMUTIL=$ac_cv_prog_DSYMUTIL
-if test -n "$DSYMUTIL"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DSYMUTIL" >&5
-$as_echo "$DSYMUTIL" >&6; }
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval $cacheid=yes
 else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
+  eval $cacheid=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
 fi
 
 
-fi
-if test -z "$ac_cv_prog_DSYMUTIL"; then
-  ac_ct_DSYMUTIL=$DSYMUTIL
-  # Extract the first word of "dsymutil", so it can be a program name with args.
-set dummy dsymutil; ac_word=$2
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
-$as_echo_n "checking for $ac_word... " >&6; }
-if test "${ac_cv_prog_ac_ct_DSYMUTIL+set}" = set; then :
+               CFLAGS="$xorg_testset_save_CFLAGS"
+
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       BASE_CFLAGS="$BASE_CFLAGS -errwarn=E_NO_EXPLICIT_TYPE_GIVEN -errwarn=E_NO_IMPLICIT_DECL_ALLOWED"
+                       found="yes"
+               fi
+       fi
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+xorg_testset_save_CFLAGS="$CFLAGS"
+
+if test "x$xorg_testset_cc_unknown_warning_option" = "x" ; then
+       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unknown-warning-option" >&5
+$as_echo_n "checking if $CC supports -Werror=unknown-warning-option... " >&6; }
+if ${xorg_cv_cc_flag_unknown_warning_option+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  if test -n "$ac_ct_DSYMUTIL"; then
-  ac_cv_prog_ac_ct_DSYMUTIL="$ac_ct_DSYMUTIL" # Let the user override the test.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unknown_warning_option=yes
 else
-as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_prog_ac_ct_DSYMUTIL="dsymutil"
-    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
-    break 2
-  fi
-done
-  done
-IFS=$as_save_IFS
-
+  xorg_cv_cc_flag_unknown_warning_option=no
 fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 fi
-ac_ct_DSYMUTIL=$ac_cv_prog_ac_ct_DSYMUTIL
-if test -n "$ac_ct_DSYMUTIL"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DSYMUTIL" >&5
-$as_echo "$ac_ct_DSYMUTIL" >&6; }
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unknown_warning_option" >&5
+$as_echo "$xorg_cv_cc_flag_unknown_warning_option" >&6; }
+       xorg_testset_cc_unknown_warning_option=$xorg_cv_cc_flag_unknown_warning_option
+       CFLAGS="$xorg_testset_save_CFLAGS"
 fi
 
-  if test "x$ac_ct_DSYMUTIL" = x; then
-    DSYMUTIL=":"
-  else
-    case $cross_compiling:$ac_tool_warned in
-yes:)
-{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
-$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
-ac_tool_warned=yes ;;
-esac
-    DSYMUTIL=$ac_ct_DSYMUTIL
-  fi
+if test "x$xorg_testset_cc_unused_command_line_argument" = "x" ; then
+       if test "x$xorg_testset_cc_unknown_warning_option" = "xyes" ; then
+               CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       fi
+       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unused-command-line-argument" >&5
+$as_echo_n "checking if $CC supports -Werror=unused-command-line-argument... " >&6; }
+if ${xorg_cv_cc_flag_unused_command_line_argument+:} false; then :
+  $as_echo_n "(cached) " >&6
 else
-  DSYMUTIL="$ac_cv_prog_DSYMUTIL"
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unused_command_line_argument=yes
+else
+  xorg_cv_cc_flag_unused_command_line_argument=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unused_command_line_argument" >&5
+$as_echo "$xorg_cv_cc_flag_unused_command_line_argument" >&6; }
+       xorg_testset_cc_unused_command_line_argument=$xorg_cv_cc_flag_unused_command_line_argument
+       CFLAGS="$xorg_testset_save_CFLAGS"
 fi
 
-    if test -n "$ac_tool_prefix"; then
-  # Extract the first word of "${ac_tool_prefix}nmedit", so it can be a program name with args.
-set dummy ${ac_tool_prefix}nmedit; ac_word=$2
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
-$as_echo_n "checking for $ac_word... " >&6; }
-if test "${ac_cv_prog_NMEDIT+set}" = set; then :
+found="no"
+
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
+
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
+
+               CFLAGS="$CFLAGS -Werror=nonnull"
+
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-Werror=nonnull" >&5
+$as_echo_n "checking if $CC supports-Werror=nonnull... " >&6; }
+               cacheid=xorg_cv_cc_flag__Werror_nonnull
+               if eval \${$cacheid+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  if test -n "$NMEDIT"; then
-  ac_cv_prog_NMEDIT="$NMEDIT" # Let the user override the test.
-else
-as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_prog_NMEDIT="${ac_tool_prefix}nmedit"
-    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
-    break 2
-  fi
-done
-  done
-IFS=$as_save_IFS
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+int
+main ()
+{
 
-fi
-fi
-NMEDIT=$ac_cv_prog_NMEDIT
-if test -n "$NMEDIT"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $NMEDIT" >&5
-$as_echo "$NMEDIT" >&6; }
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval $cacheid=yes
 else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
+  eval $cacheid=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
 fi
 
 
-fi
-if test -z "$ac_cv_prog_NMEDIT"; then
-  ac_ct_NMEDIT=$NMEDIT
-  # Extract the first word of "nmedit", so it can be a program name with args.
-set dummy nmedit; ac_word=$2
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
-$as_echo_n "checking for $ac_word... " >&6; }
-if test "${ac_cv_prog_ac_ct_NMEDIT+set}" = set; then :
+               CFLAGS="$xorg_testset_save_CFLAGS"
+
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       BASE_CFLAGS="$BASE_CFLAGS -Werror=nonnull"
+                       found="yes"
+               fi
+       fi
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+xorg_testset_save_CFLAGS="$CFLAGS"
+
+if test "x$xorg_testset_cc_unknown_warning_option" = "x" ; then
+       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unknown-warning-option" >&5
+$as_echo_n "checking if $CC supports -Werror=unknown-warning-option... " >&6; }
+if ${xorg_cv_cc_flag_unknown_warning_option+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  if test -n "$ac_ct_NMEDIT"; then
-  ac_cv_prog_ac_ct_NMEDIT="$ac_ct_NMEDIT" # Let the user override the test.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unknown_warning_option=yes
 else
-as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_prog_ac_ct_NMEDIT="nmedit"
-    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
-    break 2
-  fi
-done
-  done
-IFS=$as_save_IFS
-
+  xorg_cv_cc_flag_unknown_warning_option=no
 fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 fi
-ac_ct_NMEDIT=$ac_cv_prog_ac_ct_NMEDIT
-if test -n "$ac_ct_NMEDIT"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_NMEDIT" >&5
-$as_echo "$ac_ct_NMEDIT" >&6; }
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unknown_warning_option" >&5
+$as_echo "$xorg_cv_cc_flag_unknown_warning_option" >&6; }
+       xorg_testset_cc_unknown_warning_option=$xorg_cv_cc_flag_unknown_warning_option
+       CFLAGS="$xorg_testset_save_CFLAGS"
 fi
 
-  if test "x$ac_ct_NMEDIT" = x; then
-    NMEDIT=":"
-  else
-    case $cross_compiling:$ac_tool_warned in
-yes:)
-{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
-$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
-ac_tool_warned=yes ;;
-esac
-    NMEDIT=$ac_ct_NMEDIT
-  fi
+if test "x$xorg_testset_cc_unused_command_line_argument" = "x" ; then
+       if test "x$xorg_testset_cc_unknown_warning_option" = "xyes" ; then
+               CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       fi
+       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unused-command-line-argument" >&5
+$as_echo_n "checking if $CC supports -Werror=unused-command-line-argument... " >&6; }
+if ${xorg_cv_cc_flag_unused_command_line_argument+:} false; then :
+  $as_echo_n "(cached) " >&6
 else
-  NMEDIT="$ac_cv_prog_NMEDIT"
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unused_command_line_argument=yes
+else
+  xorg_cv_cc_flag_unused_command_line_argument=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unused_command_line_argument" >&5
+$as_echo "$xorg_cv_cc_flag_unused_command_line_argument" >&6; }
+       xorg_testset_cc_unused_command_line_argument=$xorg_cv_cc_flag_unused_command_line_argument
+       CFLAGS="$xorg_testset_save_CFLAGS"
 fi
 
-    if test -n "$ac_tool_prefix"; then
-  # Extract the first word of "${ac_tool_prefix}lipo", so it can be a program name with args.
-set dummy ${ac_tool_prefix}lipo; ac_word=$2
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
-$as_echo_n "checking for $ac_word... " >&6; }
-if test "${ac_cv_prog_LIPO+set}" = set; then :
+found="no"
+
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
+
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
+
+               CFLAGS="$CFLAGS -Werror=init-self"
+
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-Werror=init-self" >&5
+$as_echo_n "checking if $CC supports-Werror=init-self... " >&6; }
+               cacheid=xorg_cv_cc_flag__Werror_init_self
+               if eval \${$cacheid+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  if test -n "$LIPO"; then
-  ac_cv_prog_LIPO="$LIPO" # Let the user override the test.
-else
-as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_prog_LIPO="${ac_tool_prefix}lipo"
-    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
-    break 2
-  fi
-done
-  done
-IFS=$as_save_IFS
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+int
+main ()
+{
 
-fi
-fi
-LIPO=$ac_cv_prog_LIPO
-if test -n "$LIPO"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LIPO" >&5
-$as_echo "$LIPO" >&6; }
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval $cacheid=yes
 else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
+  eval $cacheid=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
 fi
 
 
-fi
-if test -z "$ac_cv_prog_LIPO"; then
-  ac_ct_LIPO=$LIPO
-  # Extract the first word of "lipo", so it can be a program name with args.
-set dummy lipo; ac_word=$2
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
-$as_echo_n "checking for $ac_word... " >&6; }
-if test "${ac_cv_prog_ac_ct_LIPO+set}" = set; then :
+               CFLAGS="$xorg_testset_save_CFLAGS"
+
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       BASE_CFLAGS="$BASE_CFLAGS -Werror=init-self"
+                       found="yes"
+               fi
+       fi
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+xorg_testset_save_CFLAGS="$CFLAGS"
+
+if test "x$xorg_testset_cc_unknown_warning_option" = "x" ; then
+       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unknown-warning-option" >&5
+$as_echo_n "checking if $CC supports -Werror=unknown-warning-option... " >&6; }
+if ${xorg_cv_cc_flag_unknown_warning_option+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  if test -n "$ac_ct_LIPO"; then
-  ac_cv_prog_ac_ct_LIPO="$ac_ct_LIPO" # Let the user override the test.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unknown_warning_option=yes
 else
-as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_prog_ac_ct_LIPO="lipo"
-    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
-    break 2
-  fi
-done
-  done
-IFS=$as_save_IFS
-
+  xorg_cv_cc_flag_unknown_warning_option=no
 fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 fi
-ac_ct_LIPO=$ac_cv_prog_ac_ct_LIPO
-if test -n "$ac_ct_LIPO"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_LIPO" >&5
-$as_echo "$ac_ct_LIPO" >&6; }
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unknown_warning_option" >&5
+$as_echo "$xorg_cv_cc_flag_unknown_warning_option" >&6; }
+       xorg_testset_cc_unknown_warning_option=$xorg_cv_cc_flag_unknown_warning_option
+       CFLAGS="$xorg_testset_save_CFLAGS"
 fi
 
-  if test "x$ac_ct_LIPO" = x; then
-    LIPO=":"
-  else
-    case $cross_compiling:$ac_tool_warned in
-yes:)
-{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
-$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
-ac_tool_warned=yes ;;
-esac
-    LIPO=$ac_ct_LIPO
-  fi
+if test "x$xorg_testset_cc_unused_command_line_argument" = "x" ; then
+       if test "x$xorg_testset_cc_unknown_warning_option" = "xyes" ; then
+               CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       fi
+       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unused-command-line-argument" >&5
+$as_echo_n "checking if $CC supports -Werror=unused-command-line-argument... " >&6; }
+if ${xorg_cv_cc_flag_unused_command_line_argument+:} false; then :
+  $as_echo_n "(cached) " >&6
 else
-  LIPO="$ac_cv_prog_LIPO"
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unused_command_line_argument=yes
+else
+  xorg_cv_cc_flag_unused_command_line_argument=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unused_command_line_argument" >&5
+$as_echo "$xorg_cv_cc_flag_unused_command_line_argument" >&6; }
+       xorg_testset_cc_unused_command_line_argument=$xorg_cv_cc_flag_unused_command_line_argument
+       CFLAGS="$xorg_testset_save_CFLAGS"
 fi
 
-    if test -n "$ac_tool_prefix"; then
-  # Extract the first word of "${ac_tool_prefix}otool", so it can be a program name with args.
-set dummy ${ac_tool_prefix}otool; ac_word=$2
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
-$as_echo_n "checking for $ac_word... " >&6; }
-if test "${ac_cv_prog_OTOOL+set}" = set; then :
+found="no"
+
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
+
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
+
+               CFLAGS="$CFLAGS -Werror=main"
+
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-Werror=main" >&5
+$as_echo_n "checking if $CC supports-Werror=main... " >&6; }
+               cacheid=xorg_cv_cc_flag__Werror_main
+               if eval \${$cacheid+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  if test -n "$OTOOL"; then
-  ac_cv_prog_OTOOL="$OTOOL" # Let the user override the test.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval $cacheid=yes
 else
-as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_prog_OTOOL="${ac_tool_prefix}otool"
-    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
-    break 2
-  fi
-done
-  done
-IFS=$as_save_IFS
-
-fi
+  eval $cacheid=no
 fi
-OTOOL=$ac_cv_prog_OTOOL
-if test -n "$OTOOL"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OTOOL" >&5
-$as_echo "$OTOOL" >&6; }
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
 fi
 
 
-fi
-if test -z "$ac_cv_prog_OTOOL"; then
-  ac_ct_OTOOL=$OTOOL
-  # Extract the first word of "otool", so it can be a program name with args.
-set dummy otool; ac_word=$2
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
-$as_echo_n "checking for $ac_word... " >&6; }
-if test "${ac_cv_prog_ac_ct_OTOOL+set}" = set; then :
+               CFLAGS="$xorg_testset_save_CFLAGS"
+
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       BASE_CFLAGS="$BASE_CFLAGS -Werror=main"
+                       found="yes"
+               fi
+       fi
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+xorg_testset_save_CFLAGS="$CFLAGS"
+
+if test "x$xorg_testset_cc_unknown_warning_option" = "x" ; then
+       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unknown-warning-option" >&5
+$as_echo_n "checking if $CC supports -Werror=unknown-warning-option... " >&6; }
+if ${xorg_cv_cc_flag_unknown_warning_option+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  if test -n "$ac_ct_OTOOL"; then
-  ac_cv_prog_ac_ct_OTOOL="$ac_ct_OTOOL" # Let the user override the test.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unknown_warning_option=yes
 else
-as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_prog_ac_ct_OTOOL="otool"
-    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
-    break 2
-  fi
-done
-  done
-IFS=$as_save_IFS
-
+  xorg_cv_cc_flag_unknown_warning_option=no
 fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 fi
-ac_ct_OTOOL=$ac_cv_prog_ac_ct_OTOOL
-if test -n "$ac_ct_OTOOL"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OTOOL" >&5
-$as_echo "$ac_ct_OTOOL" >&6; }
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-fi
-
-  if test "x$ac_ct_OTOOL" = x; then
-    OTOOL=":"
-  else
-    case $cross_compiling:$ac_tool_warned in
-yes:)
-{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
-$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
-ac_tool_warned=yes ;;
-esac
-    OTOOL=$ac_ct_OTOOL
-  fi
-else
-  OTOOL="$ac_cv_prog_OTOOL"
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unknown_warning_option" >&5
+$as_echo "$xorg_cv_cc_flag_unknown_warning_option" >&6; }
+       xorg_testset_cc_unknown_warning_option=$xorg_cv_cc_flag_unknown_warning_option
+       CFLAGS="$xorg_testset_save_CFLAGS"
 fi
 
-    if test -n "$ac_tool_prefix"; then
-  # Extract the first word of "${ac_tool_prefix}otool64", so it can be a program name with args.
-set dummy ${ac_tool_prefix}otool64; ac_word=$2
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
-$as_echo_n "checking for $ac_word... " >&6; }
-if test "${ac_cv_prog_OTOOL64+set}" = set; then :
+if test "x$xorg_testset_cc_unused_command_line_argument" = "x" ; then
+       if test "x$xorg_testset_cc_unknown_warning_option" = "xyes" ; then
+               CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       fi
+       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unused-command-line-argument" >&5
+$as_echo_n "checking if $CC supports -Werror=unused-command-line-argument... " >&6; }
+if ${xorg_cv_cc_flag_unused_command_line_argument+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  if test -n "$OTOOL64"; then
-  ac_cv_prog_OTOOL64="$OTOOL64" # Let the user override the test.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unused_command_line_argument=yes
 else
-as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_prog_OTOOL64="${ac_tool_prefix}otool64"
-    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
-    break 2
-  fi
-done
-  done
-IFS=$as_save_IFS
-
+  xorg_cv_cc_flag_unused_command_line_argument=no
 fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 fi
-OTOOL64=$ac_cv_prog_OTOOL64
-if test -n "$OTOOL64"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OTOOL64" >&5
-$as_echo "$OTOOL64" >&6; }
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unused_command_line_argument" >&5
+$as_echo "$xorg_cv_cc_flag_unused_command_line_argument" >&6; }
+       xorg_testset_cc_unused_command_line_argument=$xorg_cv_cc_flag_unused_command_line_argument
+       CFLAGS="$xorg_testset_save_CFLAGS"
 fi
 
+found="no"
 
-fi
-if test -z "$ac_cv_prog_OTOOL64"; then
-  ac_ct_OTOOL64=$OTOOL64
-  # Extract the first word of "otool64", so it can be a program name with args.
-set dummy otool64; ac_word=$2
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
-$as_echo_n "checking for $ac_word... " >&6; }
-if test "${ac_cv_prog_ac_ct_OTOOL64+set}" = set; then :
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
+
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
+
+               CFLAGS="$CFLAGS -Werror=missing-braces"
+
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-Werror=missing-braces" >&5
+$as_echo_n "checking if $CC supports-Werror=missing-braces... " >&6; }
+               cacheid=xorg_cv_cc_flag__Werror_missing_braces
+               if eval \${$cacheid+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  if test -n "$ac_ct_OTOOL64"; then
-  ac_cv_prog_ac_ct_OTOOL64="$ac_ct_OTOOL64" # Let the user override the test.
-else
-as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_prog_ac_ct_OTOOL64="otool64"
-    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
-    break 2
-  fi
-done
-  done
-IFS=$as_save_IFS
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+int
+main ()
+{
 
-fi
-fi
-ac_ct_OTOOL64=$ac_cv_prog_ac_ct_OTOOL64
-if test -n "$ac_ct_OTOOL64"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OTOOL64" >&5
-$as_echo "$ac_ct_OTOOL64" >&6; }
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval $cacheid=yes
 else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
+  eval $cacheid=no
 fi
-
-  if test "x$ac_ct_OTOOL64" = x; then
-    OTOOL64=":"
-  else
-    case $cross_compiling:$ac_tool_warned in
-yes:)
-{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
-$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
-ac_tool_warned=yes ;;
-esac
-    OTOOL64=$ac_ct_OTOOL64
-  fi
-else
-  OTOOL64="$ac_cv_prog_OTOOL64"
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
 fi
 
 
+               CFLAGS="$xorg_testset_save_CFLAGS"
 
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       BASE_CFLAGS="$BASE_CFLAGS -Werror=missing-braces"
+                       found="yes"
+               fi
+       fi
 
 
 
@@ -7296,56 +7605,81 @@ fi
 
 
 
+xorg_testset_save_CFLAGS="$CFLAGS"
 
+if test "x$xorg_testset_cc_unknown_warning_option" = "x" ; then
+       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unknown-warning-option" >&5
+$as_echo_n "checking if $CC supports -Werror=unknown-warning-option... " >&6; }
+if ${xorg_cv_cc_flag_unknown_warning_option+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unknown_warning_option=yes
+else
+  xorg_cv_cc_flag_unknown_warning_option=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unknown_warning_option" >&5
+$as_echo "$xorg_cv_cc_flag_unknown_warning_option" >&6; }
+       xorg_testset_cc_unknown_warning_option=$xorg_cv_cc_flag_unknown_warning_option
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
 
+if test "x$xorg_testset_cc_unused_command_line_argument" = "x" ; then
+       if test "x$xorg_testset_cc_unknown_warning_option" = "xyes" ; then
+               CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       fi
+       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unused-command-line-argument" >&5
+$as_echo_n "checking if $CC supports -Werror=unused-command-line-argument... " >&6; }
+if ${xorg_cv_cc_flag_unused_command_line_argument+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unused_command_line_argument=yes
+else
+  xorg_cv_cc_flag_unused_command_line_argument=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unused_command_line_argument" >&5
+$as_echo "$xorg_cv_cc_flag_unused_command_line_argument" >&6; }
+       xorg_testset_cc_unused_command_line_argument=$xorg_cv_cc_flag_unused_command_line_argument
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
 
+found="no"
 
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
 
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
 
+               CFLAGS="$CFLAGS -Werror=sequence-point"
 
-
-
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -single_module linker flag" >&5
-$as_echo_n "checking for -single_module linker flag... " >&6; }
-if test "${lt_cv_apple_cc_single_mod+set}" = set; then :
-  $as_echo_n "(cached) " >&6
-else
-  lt_cv_apple_cc_single_mod=no
-      if test -z "${LT_MULTI_MODULE}"; then
-       # By default we will add the -single_module flag. You can override
-       # by either setting the environment variable LT_MULTI_MODULE
-       # non-empty at configure time, or by adding -multi_module to the
-       # link flags.
-       rm -rf libconftest.dylib*
-       echo "int foo(void){return 1;}" > conftest.c
-       echo "$LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \
--dynamiclib -Wl,-single_module conftest.c" >&5
-       $LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \
-         -dynamiclib -Wl,-single_module conftest.c 2>conftest.err
-        _lt_result=$?
-       if test -f libconftest.dylib && test ! -s conftest.err && test $_lt_result = 0; then
-         lt_cv_apple_cc_single_mod=yes
-       else
-         cat conftest.err >&5
-       fi
-       rm -rf libconftest.dylib*
-       rm -f conftest.*
-      fi
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_apple_cc_single_mod" >&5
-$as_echo "$lt_cv_apple_cc_single_mod" >&6; }
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -exported_symbols_list linker flag" >&5
-$as_echo_n "checking for -exported_symbols_list linker flag... " >&6; }
-if test "${lt_cv_ld_exported_symbols_list+set}" = set; then :
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-Werror=sequence-point" >&5
+$as_echo_n "checking if $CC supports-Werror=sequence-point... " >&6; }
+               cacheid=xorg_cv_cc_flag__Werror_sequence_point
+               if eval \${$cacheid+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  lt_cv_ld_exported_symbols_list=no
-      save_LDFLAGS=$LDFLAGS
-      echo "_main" > conftest.sym
-      LDFLAGS="$LDFLAGS -Wl,-exported_symbols_list,conftest.sym"
-      cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
-
+int i;
 int
 main ()
 {
@@ -7355,90 +7689,28 @@ main ()
 }
 _ACEOF
 if ac_fn_c_try_link "$LINENO"; then :
-  lt_cv_ld_exported_symbols_list=yes
+  eval $cacheid=yes
 else
-  lt_cv_ld_exported_symbols_list=no
+  eval $cacheid=no
 fi
 rm -f core conftest.err conftest.$ac_objext \
     conftest$ac_exeext conftest.$ac_ext
-       LDFLAGS="$save_LDFLAGS"
-
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_exported_symbols_list" >&5
-$as_echo "$lt_cv_ld_exported_symbols_list" >&6; }
-    case $host_os in
-    rhapsody* | darwin1.[012])
-      _lt_dar_allow_undefined='${wl}-undefined ${wl}suppress' ;;
-    darwin1.*)
-      _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;;
-    darwin*) # darwin 5.x on
-      # if running on 10.5 or later, the deployment target defaults
-      # to the OS version, if on x86, and 10.4, the deployment
-      # target defaults to 10.4. Don't you love it?
-      case ${MACOSX_DEPLOYMENT_TARGET-10.0},$host in
-       10.0,*86*-darwin8*|10.0,*-darwin[91]*)
-         _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;;
-       10.[012]*)
-         _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;;
-       10.*)
-         _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;;
-      esac
-    ;;
-  esac
-    if test "$lt_cv_apple_cc_single_mod" = "yes"; then
-      _lt_dar_single_mod='$single_module'
-    fi
-    if test "$lt_cv_ld_exported_symbols_list" = "yes"; then
-      _lt_dar_export_syms=' ${wl}-exported_symbols_list,$output_objdir/${libname}-symbols.expsym'
-    else
-      _lt_dar_export_syms='~$NMEDIT -s $output_objdir/${libname}-symbols.expsym ${lib}'
-    fi
-    if test "$DSYMUTIL" != ":"; then
-      _lt_dsymutil='~$DSYMUTIL $lib || :'
-    else
-      _lt_dsymutil=
-    fi
-    ;;
-  esac
 
-for ac_header in dlfcn.h
-do :
-  ac_fn_c_check_header_compile "$LINENO" "dlfcn.h" "ac_cv_header_dlfcn_h" "$ac_includes_default
-"
-if test "x$ac_cv_header_dlfcn_h" = x""yes; then :
-  cat >>confdefs.h <<_ACEOF
-#define HAVE_DLFCN_H 1
-_ACEOF
 
-fi
+               CFLAGS="$xorg_testset_save_CFLAGS"
 
-done
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       BASE_CFLAGS="$BASE_CFLAGS -Werror=sequence-point"
+                       found="yes"
+               fi
+       fi
 
 
 
-# Set options
-# Check whether --enable-static was given.
-if test "${enable_static+set}" = set; then :
-  enableval=$enable_static; p=${PACKAGE-default}
-    case $enableval in
-    yes) enable_static=yes ;;
-    no) enable_static=no ;;
-    *)
-     enable_static=no
-      # Look at the argument we got.  We use all the common list separators.
-      lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
-      for pkg in $enableval; do
-       IFS="$lt_save_ifs"
-       if test "X$pkg" = "X$p"; then
-         enable_static=yes
-       fi
-      done
-      IFS="$lt_save_ifs"
-      ;;
-    esac
-else
-  enable_static=no
-fi
 
 
 
 
 
 
-        enable_dlopen=no
 
 
-  enable_win32_dll=no
+xorg_testset_save_CFLAGS="$CFLAGS"
 
+if test "x$xorg_testset_cc_unknown_warning_option" = "x" ; then
+       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unknown-warning-option" >&5
+$as_echo_n "checking if $CC supports -Werror=unknown-warning-option... " >&6; }
+if ${xorg_cv_cc_flag_unknown_warning_option+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unknown_warning_option=yes
+else
+  xorg_cv_cc_flag_unknown_warning_option=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unknown_warning_option" >&5
+$as_echo "$xorg_cv_cc_flag_unknown_warning_option" >&6; }
+       xorg_testset_cc_unknown_warning_option=$xorg_cv_cc_flag_unknown_warning_option
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
 
-            # Check whether --enable-shared was given.
-if test "${enable_shared+set}" = set; then :
-  enableval=$enable_shared; p=${PACKAGE-default}
-    case $enableval in
-    yes) enable_shared=yes ;;
-    no) enable_shared=no ;;
-    *)
-      enable_shared=no
-      # Look at the argument we got.  We use all the common list separators.
-      lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
-      for pkg in $enableval; do
-       IFS="$lt_save_ifs"
-       if test "X$pkg" = "X$p"; then
-         enable_shared=yes
+if test "x$xorg_testset_cc_unused_command_line_argument" = "x" ; then
+       if test "x$xorg_testset_cc_unknown_warning_option" = "xyes" ; then
+               CFLAGS="$CFLAGS -Werror=unknown-warning-option"
        fi
-      done
-      IFS="$lt_save_ifs"
-      ;;
-    esac
+       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unused-command-line-argument" >&5
+$as_echo_n "checking if $CC supports -Werror=unused-command-line-argument... " >&6; }
+if ${xorg_cv_cc_flag_unused_command_line_argument+:} false; then :
+  $as_echo_n "(cached) " >&6
 else
-  enable_shared=yes
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unused_command_line_argument=yes
+else
+  xorg_cv_cc_flag_unused_command_line_argument=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unused_command_line_argument" >&5
+$as_echo "$xorg_cv_cc_flag_unused_command_line_argument" >&6; }
+       xorg_testset_cc_unused_command_line_argument=$xorg_cv_cc_flag_unused_command_line_argument
+       CFLAGS="$xorg_testset_save_CFLAGS"
 fi
 
+found="no"
 
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
 
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
 
+               CFLAGS="$CFLAGS -Werror=return-type"
 
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-Werror=return-type" >&5
+$as_echo_n "checking if $CC supports-Werror=return-type... " >&6; }
+               cacheid=xorg_cv_cc_flag__Werror_return_type
+               if eval \${$cacheid+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+int
+main ()
+{
 
-
-
-
-
-
-# Check whether --with-pic was given.
-if test "${with_pic+set}" = set; then :
-  withval=$with_pic; pic_mode="$withval"
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval $cacheid=yes
 else
-  pic_mode=default
+  eval $cacheid=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
 fi
 
 
-test -z "$pic_mode" && pic_mode=default
-
+               CFLAGS="$xorg_testset_save_CFLAGS"
 
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       BASE_CFLAGS="$BASE_CFLAGS -Werror=return-type"
+                       found="yes"
+               fi
+       fi
 
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
 
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
 
+               CFLAGS="$CFLAGS -errwarn=E_FUNC_HAS_NO_RETURN_STMT"
 
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-errwarn=E_FUNC_HAS_NO_RETURN_STMT" >&5
+$as_echo_n "checking if $CC supports-errwarn=E_FUNC_HAS_NO_RETURN_STMT... " >&6; }
+               cacheid=xorg_cv_cc_flag__errwarn_E_FUNC_HAS_NO_RETURN_STMT
+               if eval \${$cacheid+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+int
+main ()
+{
 
-  # Check whether --enable-fast-install was given.
-if test "${enable_fast_install+set}" = set; then :
-  enableval=$enable_fast_install; p=${PACKAGE-default}
-    case $enableval in
-    yes) enable_fast_install=yes ;;
-    no) enable_fast_install=no ;;
-    *)
-      enable_fast_install=no
-      # Look at the argument we got.  We use all the common list separators.
-      lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
-      for pkg in $enableval; do
-       IFS="$lt_save_ifs"
-       if test "X$pkg" = "X$p"; then
-         enable_fast_install=yes
-       fi
-      done
-      IFS="$lt_save_ifs"
-      ;;
-    esac
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval $cacheid=yes
 else
-  enable_fast_install=yes
+  eval $cacheid=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
 fi
 
 
+               CFLAGS="$xorg_testset_save_CFLAGS"
 
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       BASE_CFLAGS="$BASE_CFLAGS -errwarn=E_FUNC_HAS_NO_RETURN_STMT"
+                       found="yes"
+               fi
+       fi
 
 
 
@@ -7537,17 +7883,6 @@ fi
 
 
 
-# This can be used to rebuild libtool when needed
-LIBTOOL_DEPS="$ltmain"
-
-# Always use our own libtool.
-LIBTOOL='$(SHELL) $(top_builddir)/libtool'
-
-
-
-
-
-
 
 
 
@@ -7555,19 +7890,110 @@ LIBTOOL='$(SHELL) $(top_builddir)/libtool'
 
 
 
+xorg_testset_save_CFLAGS="$CFLAGS"
 
+if test "x$xorg_testset_cc_unknown_warning_option" = "x" ; then
+       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unknown-warning-option" >&5
+$as_echo_n "checking if $CC supports -Werror=unknown-warning-option... " >&6; }
+if ${xorg_cv_cc_flag_unknown_warning_option+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unknown_warning_option=yes
+else
+  xorg_cv_cc_flag_unknown_warning_option=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unknown_warning_option" >&5
+$as_echo "$xorg_cv_cc_flag_unknown_warning_option" >&6; }
+       xorg_testset_cc_unknown_warning_option=$xorg_cv_cc_flag_unknown_warning_option
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
 
+if test "x$xorg_testset_cc_unused_command_line_argument" = "x" ; then
+       if test "x$xorg_testset_cc_unknown_warning_option" = "xyes" ; then
+               CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       fi
+       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unused-command-line-argument" >&5
+$as_echo_n "checking if $CC supports -Werror=unused-command-line-argument... " >&6; }
+if ${xorg_cv_cc_flag_unused_command_line_argument+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unused_command_line_argument=yes
+else
+  xorg_cv_cc_flag_unused_command_line_argument=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unused_command_line_argument" >&5
+$as_echo "$xorg_cv_cc_flag_unused_command_line_argument" >&6; }
+       xorg_testset_cc_unused_command_line_argument=$xorg_cv_cc_flag_unused_command_line_argument
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
 
+found="no"
 
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
 
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
 
+               CFLAGS="$CFLAGS -Werror=trigraphs"
 
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-Werror=trigraphs" >&5
+$as_echo_n "checking if $CC supports-Werror=trigraphs... " >&6; }
+               cacheid=xorg_cv_cc_flag__Werror_trigraphs
+               if eval \${$cacheid+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+int
+main ()
+{
 
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval $cacheid=yes
+else
+  eval $cacheid=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+fi
 
 
+               CFLAGS="$xorg_testset_save_CFLAGS"
 
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       BASE_CFLAGS="$BASE_CFLAGS -Werror=trigraphs"
+                       found="yes"
+               fi
+       fi
 
-test -z "$LN_S" && LN_S="ln -s"
 
 
 
@@ -7582,45 +8008,109 @@ test -z "$LN_S" && LN_S="ln -s"
 
 
 
-if test -n "${ZSH_VERSION+set}" ; then
-   setopt NO_GLOB_SUBST
-fi
+xorg_testset_save_CFLAGS="$CFLAGS"
 
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for objdir" >&5
-$as_echo_n "checking for objdir... " >&6; }
-if test "${lt_cv_objdir+set}" = set; then :
+if test "x$xorg_testset_cc_unknown_warning_option" = "x" ; then
+       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unknown-warning-option" >&5
+$as_echo_n "checking if $CC supports -Werror=unknown-warning-option... " >&6; }
+if ${xorg_cv_cc_flag_unknown_warning_option+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  rm -f .libs 2>/dev/null
-mkdir .libs 2>/dev/null
-if test -d .libs; then
-  lt_cv_objdir=.libs
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unknown_warning_option=yes
 else
-  # MS-DOS does not allow filenames that begin with a dot.
-  lt_cv_objdir=_libs
+  xorg_cv_cc_flag_unknown_warning_option=no
 fi
-rmdir .libs 2>/dev/null
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unknown_warning_option" >&5
+$as_echo "$xorg_cv_cc_flag_unknown_warning_option" >&6; }
+       xorg_testset_cc_unknown_warning_option=$xorg_cv_cc_flag_unknown_warning_option
+       CFLAGS="$xorg_testset_save_CFLAGS"
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_objdir" >&5
-$as_echo "$lt_cv_objdir" >&6; }
-objdir=$lt_cv_objdir
-
-
-
-
 
-cat >>confdefs.h <<_ACEOF
-#define LT_OBJDIR "$lt_cv_objdir/"
+if test "x$xorg_testset_cc_unused_command_line_argument" = "x" ; then
+       if test "x$xorg_testset_cc_unknown_warning_option" = "xyes" ; then
+               CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       fi
+       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unused-command-line-argument" >&5
+$as_echo_n "checking if $CC supports -Werror=unused-command-line-argument... " >&6; }
+if ${xorg_cv_cc_flag_unused_command_line_argument+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
 _ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unused_command_line_argument=yes
+else
+  xorg_cv_cc_flag_unused_command_line_argument=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unused_command_line_argument" >&5
+$as_echo "$xorg_cv_cc_flag_unused_command_line_argument" >&6; }
+       xorg_testset_cc_unused_command_line_argument=$xorg_cv_cc_flag_unused_command_line_argument
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
 
+found="no"
 
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
 
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
 
+               CFLAGS="$CFLAGS -Werror=array-bounds"
 
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-Werror=array-bounds" >&5
+$as_echo_n "checking if $CC supports-Werror=array-bounds... " >&6; }
+               cacheid=xorg_cv_cc_flag__Werror_array_bounds
+               if eval \${$cacheid+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+int
+main ()
+{
 
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval $cacheid=yes
+else
+  eval $cacheid=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+fi
 
 
+               CFLAGS="$xorg_testset_save_CFLAGS"
 
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       BASE_CFLAGS="$BASE_CFLAGS -Werror=array-bounds"
+                       found="yes"
+               fi
+       fi
 
 
 
@@ -7629,229 +8119,118 @@ _ACEOF
 
 
 
-case $host_os in
-aix3*)
-  # AIX sometimes has problems with the GCC collect2 program.  For some
-  # reason, if we set the COLLECT_NAMES environment variable, the problems
-  # vanish in a puff of smoke.
-  if test "X${COLLECT_NAMES+set}" != Xset; then
-    COLLECT_NAMES=
-    export COLLECT_NAMES
-  fi
-  ;;
-esac
-
-# Sed substitution that helps us do robust quoting.  It backslashifies
-# metacharacters that are still active within double-quoted strings.
-sed_quote_subst='s/\(["`$\\]\)/\\\1/g'
-
-# Same as above, but do not quote variable references.
-double_quote_subst='s/\(["`\\]\)/\\\1/g'
-
-# Sed substitution to delay expansion of an escaped shell variable in a
-# double_quote_subst'ed string.
-delay_variable_subst='s/\\\\\\\\\\\$/\\\\\\$/g'
-
-# Sed substitution to delay expansion of an escaped single quote.
-delay_single_quote_subst='s/'\''/'\'\\\\\\\'\''/g'
-
-# Sed substitution to avoid accidental globbing in evaled expressions
-no_glob_subst='s/\*/\\\*/g'
 
-# Global variables:
-ofile=libtool
-can_build_shared=yes
 
-# All known linkers require a `.a' archive for static linking (except MSVC,
-# which needs '.lib').
-libext=a
 
-with_gnu_ld="$lt_cv_prog_gnu_ld"
 
-old_CC="$CC"
-old_CFLAGS="$CFLAGS"
 
-# Set sane defaults for various variables
-test -z "$CC" && CC=cc
-test -z "$LTCC" && LTCC=$CC
-test -z "$LTCFLAGS" && LTCFLAGS=$CFLAGS
-test -z "$LD" && LD=ld
-test -z "$ac_objext" && ac_objext=o
 
-for cc_temp in $compiler""; do
-  case $cc_temp in
-    compile | *[\\/]compile | ccache | *[\\/]ccache ) ;;
-    distcc | *[\\/]distcc | purify | *[\\/]purify ) ;;
-    \-*) ;;
-    *) break;;
-  esac
-done
-cc_basename=`$ECHO "X$cc_temp" | $Xsed -e 's%.*/%%' -e "s%^$host_alias-%%"`
 
+xorg_testset_save_CFLAGS="$CFLAGS"
 
-# Only perform the check for file, if the check method requires it
-test -z "$MAGIC_CMD" && MAGIC_CMD=file
-case $deplibs_check_method in
-file_magic*)
-  if test "$file_magic_cmd" = '$MAGIC_CMD'; then
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ${ac_tool_prefix}file" >&5
-$as_echo_n "checking for ${ac_tool_prefix}file... " >&6; }
-if test "${lt_cv_path_MAGIC_CMD+set}" = set; then :
+if test "x$xorg_testset_cc_unknown_warning_option" = "x" ; then
+       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unknown-warning-option" >&5
+$as_echo_n "checking if $CC supports -Werror=unknown-warning-option... " >&6; }
+if ${xorg_cv_cc_flag_unknown_warning_option+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $MAGIC_CMD in
-[\\/*] |  ?:[\\/]*)
-  lt_cv_path_MAGIC_CMD="$MAGIC_CMD" # Let the user override the test with a path.
-  ;;
-*)
-  lt_save_MAGIC_CMD="$MAGIC_CMD"
-  lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
-  ac_dummy="/usr/bin$PATH_SEPARATOR$PATH"
-  for ac_dir in $ac_dummy; do
-    IFS="$lt_save_ifs"
-    test -z "$ac_dir" && ac_dir=.
-    if test -f $ac_dir/${ac_tool_prefix}file; then
-      lt_cv_path_MAGIC_CMD="$ac_dir/${ac_tool_prefix}file"
-      if test -n "$file_magic_test_file"; then
-       case $deplibs_check_method in
-       "file_magic "*)
-         file_magic_regex=`expr "$deplibs_check_method" : "file_magic \(.*\)"`
-         MAGIC_CMD="$lt_cv_path_MAGIC_CMD"
-         if eval $file_magic_cmd \$file_magic_test_file 2> /dev/null |
-           $EGREP "$file_magic_regex" > /dev/null; then
-           :
-         else
-           cat <<_LT_EOF 1>&2
-
-*** Warning: the command libtool uses to detect shared libraries,
-*** $file_magic_cmd, produces output that libtool cannot recognize.
-*** The result is that libtool may fail to recognize shared libraries
-*** as such.  This will affect the creation of libtool libraries that
-*** depend on shared libraries, but programs linked with such libtool
-*** libraries will work regardless of this problem.  Nevertheless, you
-*** may want to report the problem to your system manager and/or to
-*** bug-libtool@gnu.org
-
-_LT_EOF
-         fi ;;
-       esac
-      fi
-      break
-    fi
-  done
-  IFS="$lt_save_ifs"
-  MAGIC_CMD="$lt_save_MAGIC_CMD"
-  ;;
-esac
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unknown_warning_option=yes
+else
+  xorg_cv_cc_flag_unknown_warning_option=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unknown_warning_option" >&5
+$as_echo "$xorg_cv_cc_flag_unknown_warning_option" >&6; }
+       xorg_testset_cc_unknown_warning_option=$xorg_cv_cc_flag_unknown_warning_option
+       CFLAGS="$xorg_testset_save_CFLAGS"
 fi
 
-MAGIC_CMD="$lt_cv_path_MAGIC_CMD"
-if test -n "$MAGIC_CMD"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MAGIC_CMD" >&5
-$as_echo "$MAGIC_CMD" >&6; }
+if test "x$xorg_testset_cc_unused_command_line_argument" = "x" ; then
+       if test "x$xorg_testset_cc_unknown_warning_option" = "xyes" ; then
+               CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       fi
+       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unused-command-line-argument" >&5
+$as_echo_n "checking if $CC supports -Werror=unused-command-line-argument... " >&6; }
+if ${xorg_cv_cc_flag_unused_command_line_argument+:} false; then :
+  $as_echo_n "(cached) " >&6
 else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unused_command_line_argument=yes
+else
+  xorg_cv_cc_flag_unused_command_line_argument=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unused_command_line_argument" >&5
+$as_echo "$xorg_cv_cc_flag_unused_command_line_argument" >&6; }
+       xorg_testset_cc_unused_command_line_argument=$xorg_cv_cc_flag_unused_command_line_argument
+       CFLAGS="$xorg_testset_save_CFLAGS"
 fi
 
+found="no"
 
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
 
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
 
+               CFLAGS="$CFLAGS -Werror=write-strings"
 
-if test -z "$lt_cv_path_MAGIC_CMD"; then
-  if test -n "$ac_tool_prefix"; then
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for file" >&5
-$as_echo_n "checking for file... " >&6; }
-if test "${lt_cv_path_MAGIC_CMD+set}" = set; then :
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-Werror=write-strings" >&5
+$as_echo_n "checking if $CC supports-Werror=write-strings... " >&6; }
+               cacheid=xorg_cv_cc_flag__Werror_write_strings
+               if eval \${$cacheid+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $MAGIC_CMD in
-[\\/*] |  ?:[\\/]*)
-  lt_cv_path_MAGIC_CMD="$MAGIC_CMD" # Let the user override the test with a path.
-  ;;
-*)
-  lt_save_MAGIC_CMD="$MAGIC_CMD"
-  lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
-  ac_dummy="/usr/bin$PATH_SEPARATOR$PATH"
-  for ac_dir in $ac_dummy; do
-    IFS="$lt_save_ifs"
-    test -z "$ac_dir" && ac_dir=.
-    if test -f $ac_dir/file; then
-      lt_cv_path_MAGIC_CMD="$ac_dir/file"
-      if test -n "$file_magic_test_file"; then
-       case $deplibs_check_method in
-       "file_magic "*)
-         file_magic_regex=`expr "$deplibs_check_method" : "file_magic \(.*\)"`
-         MAGIC_CMD="$lt_cv_path_MAGIC_CMD"
-         if eval $file_magic_cmd \$file_magic_test_file 2> /dev/null |
-           $EGREP "$file_magic_regex" > /dev/null; then
-           :
-         else
-           cat <<_LT_EOF 1>&2
-
-*** Warning: the command libtool uses to detect shared libraries,
-*** $file_magic_cmd, produces output that libtool cannot recognize.
-*** The result is that libtool may fail to recognize shared libraries
-*** as such.  This will affect the creation of libtool libraries that
-*** depend on shared libraries, but programs linked with such libtool
-*** libraries will work regardless of this problem.  Nevertheless, you
-*** may want to report the problem to your system manager and/or to
-*** bug-libtool@gnu.org
-
-_LT_EOF
-         fi ;;
-       esac
-      fi
-      break
-    fi
-  done
-  IFS="$lt_save_ifs"
-  MAGIC_CMD="$lt_save_MAGIC_CMD"
-  ;;
-esac
-fi
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+int
+main ()
+{
 
-MAGIC_CMD="$lt_cv_path_MAGIC_CMD"
-if test -n "$MAGIC_CMD"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MAGIC_CMD" >&5
-$as_echo "$MAGIC_CMD" >&6; }
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval $cacheid=yes
 else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
+  eval $cacheid=no
 fi
-
-
-  else
-    MAGIC_CMD=:
-  fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
 fi
 
-  fi
-  ;;
-esac
-
-# Use C for the default configuration in the libtool script
-
-lt_save_CC="$CC"
-ac_ext=c
-ac_cpp='$CPP $CPPFLAGS'
-ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
-ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
-ac_compiler_gnu=$ac_cv_c_compiler_gnu
-
 
-# Source file extension for C test sources.
-ac_ext=c
+               CFLAGS="$xorg_testset_save_CFLAGS"
 
-# Object file extension for compiled C test sources.
-objext=o
-objext=$objext
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       BASE_CFLAGS="$BASE_CFLAGS -Werror=write-strings"
+                       found="yes"
+               fi
+       fi
 
-# Code to be used in simple compile tests
-lt_simple_compile_test_code="int some_variable = 0;"
 
-# Code to be used in simple link tests
-lt_simple_link_test_code='int main(){return(0);}'
 
 
 
@@ -7859,478 +8238,409 @@ lt_simple_link_test_code='int main(){return(0);}'
 
 
 
-# If no C compiler was specified, use CC.
-LTCC=${LTCC-"$CC"}
 
-# If no C compiler flags were specified, use CFLAGS.
-LTCFLAGS=${LTCFLAGS-"$CFLAGS"}
 
-# Allow CC to be a program name with arguments.
-compiler=$CC
 
-# Save the default compiler, since it gets overwritten when the other
-# tags are being tested, and _LT_TAGVAR(compiler, []) is a NOP.
-compiler_DEFAULT=$CC
 
-# save warnings/boilerplate of simple test code
-ac_outfile=conftest.$ac_objext
-echo "$lt_simple_compile_test_code" >conftest.$ac_ext
-eval "$ac_compile" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err
-_lt_compiler_boilerplate=`cat conftest.err`
-$RM conftest*
 
-ac_outfile=conftest.$ac_objext
-echo "$lt_simple_link_test_code" >conftest.$ac_ext
-eval "$ac_link" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err
-_lt_linker_boilerplate=`cat conftest.err`
-$RM -r conftest*
 
+xorg_testset_save_CFLAGS="$CFLAGS"
 
-## CAVEAT EMPTOR:
-## There is no encapsulation within the following macros, do not change
-## the running order or otherwise move them around unless you know exactly
-## what you are doing...
-if test -n "$compiler"; then
+if test "x$xorg_testset_cc_unknown_warning_option" = "x" ; then
+       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unknown-warning-option" >&5
+$as_echo_n "checking if $CC supports -Werror=unknown-warning-option... " >&6; }
+if ${xorg_cv_cc_flag_unknown_warning_option+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unknown_warning_option=yes
+else
+  xorg_cv_cc_flag_unknown_warning_option=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unknown_warning_option" >&5
+$as_echo "$xorg_cv_cc_flag_unknown_warning_option" >&6; }
+       xorg_testset_cc_unknown_warning_option=$xorg_cv_cc_flag_unknown_warning_option
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
 
-lt_prog_compiler_no_builtin_flag=
+if test "x$xorg_testset_cc_unused_command_line_argument" = "x" ; then
+       if test "x$xorg_testset_cc_unknown_warning_option" = "xyes" ; then
+               CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       fi
+       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unused-command-line-argument" >&5
+$as_echo_n "checking if $CC supports -Werror=unused-command-line-argument... " >&6; }
+if ${xorg_cv_cc_flag_unused_command_line_argument+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unused_command_line_argument=yes
+else
+  xorg_cv_cc_flag_unused_command_line_argument=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unused_command_line_argument" >&5
+$as_echo "$xorg_cv_cc_flag_unused_command_line_argument" >&6; }
+       xorg_testset_cc_unused_command_line_argument=$xorg_cv_cc_flag_unused_command_line_argument
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
 
-if test "$GCC" = yes; then
-  lt_prog_compiler_no_builtin_flag=' -fno-builtin'
+found="no"
 
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -fno-rtti -fno-exceptions" >&5
-$as_echo_n "checking if $compiler supports -fno-rtti -fno-exceptions... " >&6; }
-if test "${lt_cv_prog_compiler_rtti_exceptions+set}" = set; then :
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
+
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
+
+               CFLAGS="$CFLAGS -Werror=address"
+
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-Werror=address" >&5
+$as_echo_n "checking if $CC supports-Werror=address... " >&6; }
+               cacheid=xorg_cv_cc_flag__Werror_address
+               if eval \${$cacheid+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  lt_cv_prog_compiler_rtti_exceptions=no
-   ac_outfile=conftest.$ac_objext
-   echo "$lt_simple_compile_test_code" > conftest.$ac_ext
-   lt_compiler_flag="-fno-rtti -fno-exceptions"
-   # Insert the option either (1) after the last *FLAGS variable, or
-   # (2) before a word containing "conftest.", or (3) at the end.
-   # Note that $ac_compile itself does not contain backslashes and begins
-   # with a dollar sign (not a hyphen), so the echo should work correctly.
-   # The option is referenced via a variable to avoid confusing sed.
-   lt_compile=`echo "$ac_compile" | $SED \
-   -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-   -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-   -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:7918: $lt_compile\"" >&5)
-   (eval "$lt_compile" 2>conftest.err)
-   ac_status=$?
-   cat conftest.err >&5
-   echo "$as_me:7922: \$? = $ac_status" >&5
-   if (exit $ac_status) && test -s "$ac_outfile"; then
-     # The compiler can only warn and ignore the option if not recognized
-     # So say no if there are warnings other than the usual output.
-     $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' >conftest.exp
-     $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
-     if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then
-       lt_cv_prog_compiler_rtti_exceptions=yes
-     fi
-   fi
-   $RM conftest*
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+int
+main ()
+{
 
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval $cacheid=yes
+else
+  eval $cacheid=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_rtti_exceptions" >&5
-$as_echo "$lt_cv_prog_compiler_rtti_exceptions" >&6; }
 
-if test x"$lt_cv_prog_compiler_rtti_exceptions" = xyes; then
-    lt_prog_compiler_no_builtin_flag="$lt_prog_compiler_no_builtin_flag -fno-rtti -fno-exceptions"
+
+               CFLAGS="$xorg_testset_save_CFLAGS"
+
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       BASE_CFLAGS="$BASE_CFLAGS -Werror=address"
+                       found="yes"
+               fi
+       fi
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+xorg_testset_save_CFLAGS="$CFLAGS"
+
+if test "x$xorg_testset_cc_unknown_warning_option" = "x" ; then
+       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unknown-warning-option" >&5
+$as_echo_n "checking if $CC supports -Werror=unknown-warning-option... " >&6; }
+if ${xorg_cv_cc_flag_unknown_warning_option+:} false; then :
+  $as_echo_n "(cached) " >&6
 else
-    :
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unknown_warning_option=yes
+else
+  xorg_cv_cc_flag_unknown_warning_option=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unknown_warning_option" >&5
+$as_echo "$xorg_cv_cc_flag_unknown_warning_option" >&6; }
+       xorg_testset_cc_unknown_warning_option=$xorg_cv_cc_flag_unknown_warning_option
+       CFLAGS="$xorg_testset_save_CFLAGS"
 fi
 
+if test "x$xorg_testset_cc_unused_command_line_argument" = "x" ; then
+       if test "x$xorg_testset_cc_unknown_warning_option" = "xyes" ; then
+               CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       fi
+       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unused-command-line-argument" >&5
+$as_echo_n "checking if $CC supports -Werror=unused-command-line-argument... " >&6; }
+if ${xorg_cv_cc_flag_unused_command_line_argument+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unused_command_line_argument=yes
+else
+  xorg_cv_cc_flag_unused_command_line_argument=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unused_command_line_argument" >&5
+$as_echo "$xorg_cv_cc_flag_unused_command_line_argument" >&6; }
+       xorg_testset_cc_unused_command_line_argument=$xorg_cv_cc_flag_unused_command_line_argument
+       CFLAGS="$xorg_testset_save_CFLAGS"
 fi
 
+found="no"
 
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
 
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
 
+               CFLAGS="$CFLAGS -Werror=int-to-pointer-cast"
 
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-Werror=int-to-pointer-cast" >&5
+$as_echo_n "checking if $CC supports-Werror=int-to-pointer-cast... " >&6; }
+               cacheid=xorg_cv_cc_flag__Werror_int_to_pointer_cast
+               if eval \${$cacheid+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+int
+main ()
+{
 
-  lt_prog_compiler_wl=
-lt_prog_compiler_pic=
-lt_prog_compiler_static=
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval $cacheid=yes
+else
+  eval $cacheid=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+fi
 
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $compiler option to produce PIC" >&5
-$as_echo_n "checking for $compiler option to produce PIC... " >&6; }
 
-  if test "$GCC" = yes; then
-    lt_prog_compiler_wl='-Wl,'
-    lt_prog_compiler_static='-static'
+               CFLAGS="$xorg_testset_save_CFLAGS"
 
-    case $host_os in
-      aix*)
-      # All AIX code is PIC.
-      if test "$host_cpu" = ia64; then
-       # AIX 5 now supports IA64 processor
-       lt_prog_compiler_static='-Bstatic'
-      fi
-      ;;
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       BASE_CFLAGS="$BASE_CFLAGS -Werror=int-to-pointer-cast"
+                       found="yes"
+               fi
+       fi
 
-    amigaos*)
-      case $host_cpu in
-      powerpc)
-            # see comment about AmigaOS4 .so support
-            lt_prog_compiler_pic='-fPIC'
-        ;;
-      m68k)
-            # FIXME: we need at least 68020 code to build shared libraries, but
-            # adding the `-m68020' flag to GCC prevents building anything better,
-            # like `-m68040'.
-            lt_prog_compiler_pic='-m68020 -resident32 -malways-restore-a4'
-        ;;
-      esac
-      ;;
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
 
-    beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*)
-      # PIC is the default for these OSes.
-      ;;
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
 
-    mingw* | cygwin* | pw32* | os2* | cegcc*)
-      # This hack is so that the source file can tell whether it is being
-      # built for inclusion in a dll (and should export symbols for example).
-      # Although the cygwin gcc ignores -fPIC, still need this for old-style
-      # (--disable-auto-import) libraries
-      lt_prog_compiler_pic='-DDLL_EXPORT'
-      ;;
+               CFLAGS="$CFLAGS -errwarn=E_BAD_PTR_INT_COMBINATION"
 
-    darwin* | rhapsody*)
-      # PIC is the default on this platform
-      # Common symbols not allowed in MH_DYLIB files
-      lt_prog_compiler_pic='-fno-common'
-      ;;
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-errwarn=E_BAD_PTR_INT_COMBINATION" >&5
+$as_echo_n "checking if $CC supports-errwarn=E_BAD_PTR_INT_COMBINATION... " >&6; }
+               cacheid=xorg_cv_cc_flag__errwarn_E_BAD_PTR_INT_COMBINATION
+               if eval \${$cacheid+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+int
+main ()
+{
 
-    hpux*)
-      # PIC is the default for 64-bit PA HP-UX, but not for 32-bit
-      # PA HP-UX.  On IA64 HP-UX, PIC is the default but the pic flag
-      # sets the default TLS model and affects inlining.
-      case $host_cpu in
-      hppa*64*)
-       # +Z the default
-       ;;
-      *)
-       lt_prog_compiler_pic='-fPIC'
-       ;;
-      esac
-      ;;
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval $cacheid=yes
+else
+  eval $cacheid=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+fi
 
-    interix[3-9]*)
-      # Interix 3.x gcc -fpic/-fPIC options generate broken code.
-      # Instead, we relocate shared libraries at runtime.
-      ;;
 
-    msdosdjgpp*)
-      # Just because we use GCC doesn't mean we suddenly get shared libraries
-      # on systems that don't support them.
-      lt_prog_compiler_can_build_shared=no
-      enable_shared=no
-      ;;
+               CFLAGS="$xorg_testset_save_CFLAGS"
 
-    *nto* | *qnx*)
-      # QNX uses GNU C++, but need to define -shared option too, otherwise
-      # it will coredump.
-      lt_prog_compiler_pic='-fPIC -shared'
-      ;;
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       BASE_CFLAGS="$BASE_CFLAGS -errwarn=E_BAD_PTR_INT_COMBINATION"
+                       found="yes"
+               fi
+       fi
 
-    sysv4*MP*)
-      if test -d /usr/nec; then
-       lt_prog_compiler_pic=-Kconform_pic
-      fi
-      ;;
 
-    *)
-      lt_prog_compiler_pic='-fPIC'
-      ;;
-    esac
-  else
-    # PORTME Check for flag to pass linker flags through the system compiler.
-    case $host_os in
-    aix*)
-      lt_prog_compiler_wl='-Wl,'
-      if test "$host_cpu" = ia64; then
-       # AIX 5 now supports IA64 processor
-       lt_prog_compiler_static='-Bstatic'
-      else
-       lt_prog_compiler_static='-bnso -bI:/lib/syscalls.exp'
-      fi
-      ;;
 
-    mingw* | cygwin* | pw32* | os2* | cegcc*)
-      # This hack is so that the source file can tell whether it is being
-      # built for inclusion in a dll (and should export symbols for example).
-      lt_prog_compiler_pic='-DDLL_EXPORT'
-      ;;
 
-    hpux9* | hpux10* | hpux11*)
-      lt_prog_compiler_wl='-Wl,'
-      # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but
-      # not for PA HP-UX.
-      case $host_cpu in
-      hppa*64*|ia64*)
-       # +Z the default
-       ;;
-      *)
-       lt_prog_compiler_pic='+Z'
-       ;;
-      esac
-      # Is there a better lt_prog_compiler_static that works with the bundled CC?
-      lt_prog_compiler_static='${wl}-a ${wl}archive'
-      ;;
-
-    irix5* | irix6* | nonstopux*)
-      lt_prog_compiler_wl='-Wl,'
-      # PIC (with -KPIC) is the default.
-      lt_prog_compiler_static='-non_shared'
-      ;;
-
-    linux* | k*bsd*-gnu | kopensolaris*-gnu)
-      case $cc_basename in
-      # old Intel for x86_64 which still supported -KPIC.
-      ecc*)
-       lt_prog_compiler_wl='-Wl,'
-       lt_prog_compiler_pic='-KPIC'
-       lt_prog_compiler_static='-static'
-        ;;
-      # icc used to be incompatible with GCC.
-      # ICC 10 doesn't accept -KPIC any more.
-      icc* | ifort*)
-       lt_prog_compiler_wl='-Wl,'
-       lt_prog_compiler_pic='-fPIC'
-       lt_prog_compiler_static='-static'
-        ;;
-      # Lahey Fortran 8.1.
-      lf95*)
-       lt_prog_compiler_wl='-Wl,'
-       lt_prog_compiler_pic='--shared'
-       lt_prog_compiler_static='--static'
-       ;;
-      pgcc* | pgf77* | pgf90* | pgf95*)
-        # Portland Group compilers (*not* the Pentium gcc compiler,
-       # which looks to be a dead project)
-       lt_prog_compiler_wl='-Wl,'
-       lt_prog_compiler_pic='-fpic'
-       lt_prog_compiler_static='-Bstatic'
-        ;;
-      ccc*)
-        lt_prog_compiler_wl='-Wl,'
-        # All Alpha code is PIC.
-        lt_prog_compiler_static='-non_shared'
-        ;;
-      xl*)
-       # IBM XL C 8.0/Fortran 10.1 on PPC
-       lt_prog_compiler_wl='-Wl,'
-       lt_prog_compiler_pic='-qpic'
-       lt_prog_compiler_static='-qstaticlink'
-       ;;
-      *)
-       case `$CC -V 2>&1 | sed 5q` in
-       *Sun\ C*)
-         # Sun C 5.9
-         lt_prog_compiler_pic='-KPIC'
-         lt_prog_compiler_static='-Bstatic'
-         lt_prog_compiler_wl='-Wl,'
-         ;;
-       *Sun\ F*)
-         # Sun Fortran 8.3 passes all unrecognized flags to the linker
-         lt_prog_compiler_pic='-KPIC'
-         lt_prog_compiler_static='-Bstatic'
-         lt_prog_compiler_wl=''
-         ;;
-       esac
-       ;;
-      esac
-      ;;
-
-    newsos6)
-      lt_prog_compiler_pic='-KPIC'
-      lt_prog_compiler_static='-Bstatic'
-      ;;
 
-    *nto* | *qnx*)
-      # QNX uses GNU C++, but need to define -shared option too, otherwise
-      # it will coredump.
-      lt_prog_compiler_pic='-fPIC -shared'
-      ;;
 
-    osf3* | osf4* | osf5*)
-      lt_prog_compiler_wl='-Wl,'
-      # All OSF/1 code is PIC.
-      lt_prog_compiler_static='-non_shared'
-      ;;
 
-    rdos*)
-      lt_prog_compiler_static='-non_shared'
-      ;;
 
-    solaris*)
-      lt_prog_compiler_pic='-KPIC'
-      lt_prog_compiler_static='-Bstatic'
-      case $cc_basename in
-      f77* | f90* | f95*)
-       lt_prog_compiler_wl='-Qoption ld ';;
-      *)
-       lt_prog_compiler_wl='-Wl,';;
-      esac
-      ;;
 
-    sunos4*)
-      lt_prog_compiler_wl='-Qoption ld '
-      lt_prog_compiler_pic='-PIC'
-      lt_prog_compiler_static='-Bstatic'
-      ;;
 
-    sysv4 | sysv4.2uw2* | sysv4.3*)
-      lt_prog_compiler_wl='-Wl,'
-      lt_prog_compiler_pic='-KPIC'
-      lt_prog_compiler_static='-Bstatic'
-      ;;
 
-    sysv4*MP*)
-      if test -d /usr/nec ;then
-       lt_prog_compiler_pic='-Kconform_pic'
-       lt_prog_compiler_static='-Bstatic'
-      fi
-      ;;
 
-    sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*)
-      lt_prog_compiler_wl='-Wl,'
-      lt_prog_compiler_pic='-KPIC'
-      lt_prog_compiler_static='-Bstatic'
-      ;;
 
-    unicos*)
-      lt_prog_compiler_wl='-Wl,'
-      lt_prog_compiler_can_build_shared=no
-      ;;
 
-    uts4*)
-      lt_prog_compiler_pic='-pic'
-      lt_prog_compiler_static='-Bstatic'
-      ;;
 
-    *)
-      lt_prog_compiler_can_build_shared=no
-      ;;
-    esac
-  fi
+xorg_testset_save_CFLAGS="$CFLAGS"
 
-case $host_os in
-  # For platforms which do not support PIC, -DPIC is meaningless:
-  *djgpp*)
-    lt_prog_compiler_pic=
-    ;;
-  *)
-    lt_prog_compiler_pic="$lt_prog_compiler_pic -DPIC"
-    ;;
-esac
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_prog_compiler_pic" >&5
-$as_echo "$lt_prog_compiler_pic" >&6; }
+if test "x$xorg_testset_cc_unknown_warning_option" = "x" ; then
+       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unknown-warning-option" >&5
+$as_echo_n "checking if $CC supports -Werror=unknown-warning-option... " >&6; }
+if ${xorg_cv_cc_flag_unknown_warning_option+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unknown_warning_option=yes
+else
+  xorg_cv_cc_flag_unknown_warning_option=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unknown_warning_option" >&5
+$as_echo "$xorg_cv_cc_flag_unknown_warning_option" >&6; }
+       xorg_testset_cc_unknown_warning_option=$xorg_cv_cc_flag_unknown_warning_option
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
 
+if test "x$xorg_testset_cc_unused_command_line_argument" = "x" ; then
+       if test "x$xorg_testset_cc_unknown_warning_option" = "xyes" ; then
+               CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       fi
+       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unused-command-line-argument" >&5
+$as_echo_n "checking if $CC supports -Werror=unused-command-line-argument... " >&6; }
+if ${xorg_cv_cc_flag_unused_command_line_argument+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unused_command_line_argument=yes
+else
+  xorg_cv_cc_flag_unused_command_line_argument=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unused_command_line_argument" >&5
+$as_echo "$xorg_cv_cc_flag_unused_command_line_argument" >&6; }
+       xorg_testset_cc_unused_command_line_argument=$xorg_cv_cc_flag_unused_command_line_argument
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
 
+found="no"
 
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
 
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
 
+               CFLAGS="$CFLAGS -Werror=pointer-to-int-cast"
 
-#
-# Check to make sure the PIC flag actually works.
-#
-if test -n "$lt_prog_compiler_pic"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler PIC flag $lt_prog_compiler_pic works" >&5
-$as_echo_n "checking if $compiler PIC flag $lt_prog_compiler_pic works... " >&6; }
-if test "${lt_cv_prog_compiler_pic_works+set}" = set; then :
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-Werror=pointer-to-int-cast" >&5
+$as_echo_n "checking if $CC supports-Werror=pointer-to-int-cast... " >&6; }
+               cacheid=xorg_cv_cc_flag__Werror_pointer_to_int_cast
+               if eval \${$cacheid+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  lt_cv_prog_compiler_pic_works=no
-   ac_outfile=conftest.$ac_objext
-   echo "$lt_simple_compile_test_code" > conftest.$ac_ext
-   lt_compiler_flag="$lt_prog_compiler_pic -DPIC"
-   # Insert the option either (1) after the last *FLAGS variable, or
-   # (2) before a word containing "conftest.", or (3) at the end.
-   # Note that $ac_compile itself does not contain backslashes and begins
-   # with a dollar sign (not a hyphen), so the echo should work correctly.
-   # The option is referenced via a variable to avoid confusing sed.
-   lt_compile=`echo "$ac_compile" | $SED \
-   -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-   -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-   -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:8257: $lt_compile\"" >&5)
-   (eval "$lt_compile" 2>conftest.err)
-   ac_status=$?
-   cat conftest.err >&5
-   echo "$as_me:8261: \$? = $ac_status" >&5
-   if (exit $ac_status) && test -s "$ac_outfile"; then
-     # The compiler can only warn and ignore the option if not recognized
-     # So say no if there are warnings other than the usual output.
-     $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' >conftest.exp
-     $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
-     if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then
-       lt_cv_prog_compiler_pic_works=yes
-     fi
-   fi
-   $RM conftest*
-
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_pic_works" >&5
-$as_echo "$lt_cv_prog_compiler_pic_works" >&6; }
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+int
+main ()
+{
 
-if test x"$lt_cv_prog_compiler_pic_works" = xyes; then
-    case $lt_prog_compiler_pic in
-     "" | " "*) ;;
-     *) lt_prog_compiler_pic=" $lt_prog_compiler_pic" ;;
-     esac
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval $cacheid=yes
 else
-    lt_prog_compiler_pic=
-     lt_prog_compiler_can_build_shared=no
+  eval $cacheid=no
 fi
-
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
 fi
 
 
+               CFLAGS="$xorg_testset_save_CFLAGS"
 
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       BASE_CFLAGS="$BASE_CFLAGS -Werror=pointer-to-int-cast"
+                       found="yes"
+               fi
+       fi
 
+ # Also -errwarn=E_BAD_PTR_INT_COMBINATION
+else
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: You have chosen not to turn some select compiler warnings into errors.  This should not be necessary.  Please report why you needed to do so in a bug report at $PACKAGE_BUGREPORT" >&5
+$as_echo "$as_me: WARNING: You have chosen not to turn some select compiler warnings into errors.  This should not be necessary.  Please report why you needed to do so in a bug report at $PACKAGE_BUGREPORT" >&2;}
 
 
-#
-# Check to make sure the static flag actually works.
-#
-wl=$lt_prog_compiler_wl eval lt_tmp_static_flag=\"$lt_prog_compiler_static\"
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler static flag $lt_tmp_static_flag works" >&5
-$as_echo_n "checking if $compiler static flag $lt_tmp_static_flag works... " >&6; }
-if test "${lt_cv_prog_compiler_static_works+set}" = set; then :
-  $as_echo_n "(cached) " >&6
-else
-  lt_cv_prog_compiler_static_works=no
-   save_LDFLAGS="$LDFLAGS"
-   LDFLAGS="$LDFLAGS $lt_tmp_static_flag"
-   echo "$lt_simple_link_test_code" > conftest.$ac_ext
-   if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then
-     # The linker can only warn and ignore the option if not recognized
-     # So say no if there are warnings
-     if test -s conftest.err; then
-       # Append any errors to the config.log.
-       cat conftest.err 1>&5
-       $ECHO "X$_lt_linker_boilerplate" | $Xsed -e '/^$/d' > conftest.exp
-       $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
-       if diff conftest.exp conftest.er2 >/dev/null; then
-         lt_cv_prog_compiler_static_works=yes
-       fi
-     else
-       lt_cv_prog_compiler_static_works=yes
-     fi
-   fi
-   $RM -r conftest*
-   LDFLAGS="$save_LDFLAGS"
 
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_static_works" >&5
-$as_echo "$lt_cv_prog_compiler_static_works" >&6; }
 
-if test x"$lt_cv_prog_compiler_static_works" = xyes; then
-    :
-else
-    lt_prog_compiler_static=
-fi
 
 
 
 
 
 
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5
-$as_echo_n "checking if $compiler supports -c -o file.$ac_objext... " >&6; }
-if test "${lt_cv_prog_compiler_c_o+set}" = set; then :
-  $as_echo_n "(cached) " >&6
-else
-  lt_cv_prog_compiler_c_o=no
-   $RM -r conftest 2>/dev/null
-   mkdir conftest
-   cd conftest
-   mkdir out
-   echo "$lt_simple_compile_test_code" > conftest.$ac_ext
 
-   lt_compiler_flag="-o out/conftest2.$ac_objext"
-   # Insert the option either (1) after the last *FLAGS variable, or
-   # (2) before a word containing "conftest.", or (3) at the end.
-   # Note that $ac_compile itself does not contain backslashes and begins
-   # with a dollar sign (not a hyphen), so the echo should work correctly.
-   lt_compile=`echo "$ac_compile" | $SED \
-   -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-   -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-   -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:8362: $lt_compile\"" >&5)
-   (eval "$lt_compile" 2>out/conftest.err)
-   ac_status=$?
-   cat out/conftest.err >&5
-   echo "$as_me:8366: \$? = $ac_status" >&5
-   if (exit $ac_status) && test -s out/conftest2.$ac_objext
-   then
-     # The compiler can only warn and ignore the option if not recognized
-     # So say no if there are warnings
-     $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' > out/conftest.exp
-     $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2
-     if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then
-       lt_cv_prog_compiler_c_o=yes
-     fi
-   fi
-   chmod u+w . 2>&5
-   $RM conftest*
-   # SGI C++ compiler will create directory out/ii_files/ for
-   # template instantiation
-   test -d out/ii_files && $RM out/ii_files/* && rmdir out/ii_files
-   $RM out/* && rmdir out
-   cd ..
-   $RM -r conftest
-   $RM conftest*
 
+xorg_testset_save_CFLAGS="$CFLAGS"
+
+if test "x$xorg_testset_cc_unknown_warning_option" = "x" ; then
+       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unknown-warning-option" >&5
+$as_echo_n "checking if $CC supports -Werror=unknown-warning-option... " >&6; }
+if ${xorg_cv_cc_flag_unknown_warning_option+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unknown_warning_option=yes
+else
+  xorg_cv_cc_flag_unknown_warning_option=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unknown_warning_option" >&5
+$as_echo "$xorg_cv_cc_flag_unknown_warning_option" >&6; }
+       xorg_testset_cc_unknown_warning_option=$xorg_cv_cc_flag_unknown_warning_option
+       CFLAGS="$xorg_testset_save_CFLAGS"
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o" >&5
-$as_echo "$lt_cv_prog_compiler_c_o" >&6; }
 
+if test "x$xorg_testset_cc_unused_command_line_argument" = "x" ; then
+       if test "x$xorg_testset_cc_unknown_warning_option" = "xyes" ; then
+               CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       fi
+       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unused-command-line-argument" >&5
+$as_echo_n "checking if $CC supports -Werror=unused-command-line-argument... " >&6; }
+if ${xorg_cv_cc_flag_unused_command_line_argument+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unused_command_line_argument=yes
+else
+  xorg_cv_cc_flag_unused_command_line_argument=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unused_command_line_argument" >&5
+$as_echo "$xorg_cv_cc_flag_unused_command_line_argument" >&6; }
+       xorg_testset_cc_unused_command_line_argument=$xorg_cv_cc_flag_unused_command_line_argument
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
 
+found="no"
 
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
 
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
 
+               CFLAGS="$CFLAGS -Wimplicit"
 
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5
-$as_echo_n "checking if $compiler supports -c -o file.$ac_objext... " >&6; }
-if test "${lt_cv_prog_compiler_c_o+set}" = set; then :
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-Wimplicit" >&5
+$as_echo_n "checking if $CC supports-Wimplicit... " >&6; }
+               cacheid=xorg_cv_cc_flag__Wimplicit
+               if eval \${$cacheid+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  lt_cv_prog_compiler_c_o=no
-   $RM -r conftest 2>/dev/null
-   mkdir conftest
-   cd conftest
-   mkdir out
-   echo "$lt_simple_compile_test_code" > conftest.$ac_ext
-
-   lt_compiler_flag="-o out/conftest2.$ac_objext"
-   # Insert the option either (1) after the last *FLAGS variable, or
-   # (2) before a word containing "conftest.", or (3) at the end.
-   # Note that $ac_compile itself does not contain backslashes and begins
-   # with a dollar sign (not a hyphen), so the echo should work correctly.
-   lt_compile=`echo "$ac_compile" | $SED \
-   -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-   -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-   -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:8417: $lt_compile\"" >&5)
-   (eval "$lt_compile" 2>out/conftest.err)
-   ac_status=$?
-   cat out/conftest.err >&5
-   echo "$as_me:8421: \$? = $ac_status" >&5
-   if (exit $ac_status) && test -s out/conftest2.$ac_objext
-   then
-     # The compiler can only warn and ignore the option if not recognized
-     # So say no if there are warnings
-     $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' > out/conftest.exp
-     $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2
-     if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then
-       lt_cv_prog_compiler_c_o=yes
-     fi
-   fi
-   chmod u+w . 2>&5
-   $RM conftest*
-   # SGI C++ compiler will create directory out/ii_files/ for
-   # template instantiation
-   test -d out/ii_files && $RM out/ii_files/* && rmdir out/ii_files
-   $RM out/* && rmdir out
-   cd ..
-   $RM -r conftest
-   $RM conftest*
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+int
+main ()
+{
 
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval $cacheid=yes
+else
+  eval $cacheid=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o" >&5
-$as_echo "$lt_cv_prog_compiler_c_o" >&6; }
 
 
+               CFLAGS="$xorg_testset_save_CFLAGS"
 
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       BASE_CFLAGS="$BASE_CFLAGS -Wimplicit"
+                       found="yes"
+               fi
+       fi
 
-hard_links="nottested"
-if test "$lt_cv_prog_compiler_c_o" = no && test "$need_locks" != no; then
-  # do not overwrite the value of need_locks provided by the user
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking if we can lock with hard links" >&5
-$as_echo_n "checking if we can lock with hard links... " >&6; }
-  hard_links=yes
-  $RM conftest*
-  ln conftest.a conftest.b 2>/dev/null && hard_links=no
-  touch conftest.a
-  ln conftest.a conftest.b 2>&5 || hard_links=no
-  ln conftest.a conftest.b 2>/dev/null && hard_links=no
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $hard_links" >&5
-$as_echo "$hard_links" >&6; }
-  if test "$hard_links" = no; then
-    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: \`$CC' does not support \`-c -o', so \`make -j' may be unsafe" >&5
-$as_echo "$as_me: WARNING: \`$CC' does not support \`-c -o', so \`make -j' may be unsafe" >&2;}
-    need_locks=warn
-  fi
-else
-  need_locks=no
-fi
 
 
 
 
 
 
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the $compiler linker ($LD) supports shared libraries" >&5
-$as_echo_n "checking whether the $compiler linker ($LD) supports shared libraries... " >&6; }
 
-  runpath_var=
-  allow_undefined_flag=
-  always_export_symbols=no
-  archive_cmds=
-  archive_expsym_cmds=
-  compiler_needs_object=no
-  enable_shared_with_static_runtimes=no
-  export_dynamic_flag_spec=
-  export_symbols_cmds='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols'
-  hardcode_automatic=no
-  hardcode_direct=no
-  hardcode_direct_absolute=no
-  hardcode_libdir_flag_spec=
-  hardcode_libdir_flag_spec_ld=
-  hardcode_libdir_separator=
-  hardcode_minus_L=no
-  hardcode_shlibpath_var=unsupported
-  inherit_rpath=no
-  link_all_deplibs=unknown
-  module_cmds=
-  module_expsym_cmds=
-  old_archive_from_new_cmds=
-  old_archive_from_expsyms_cmds=
-  thread_safe_flag_spec=
-  whole_archive_flag_spec=
-  # include_expsyms should be a list of space-separated symbols to be *always*
-  # included in the symbol list
-  include_expsyms=
-  # exclude_expsyms can be an extended regexp of symbols to exclude
-  # it will be wrapped by ` (' and `)$', so one must not match beginning or
-  # end of line.  Example: `a|bc|.*d.*' will exclude the symbols `a' and `bc',
-  # as well as any symbol that contains `d'.
-  exclude_expsyms='_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*'
-  # Although _GLOBAL_OFFSET_TABLE_ is a valid symbol C name, most a.out
-  # platforms (ab)use it in PIC code, but their linkers get confused if
-  # the symbol is explicitly referenced.  Since portable code cannot
-  # rely on this symbol name, it's probably fine to never include it in
-  # preloaded symbol tables.
-  # Exclude shared library initialization/finalization symbols.
-  extract_expsyms_cmds=
 
-  case $host_os in
-  cygwin* | mingw* | pw32* | cegcc*)
-    # FIXME: the MSVC++ port hasn't been tested in a loooong time
-    # When not using gcc, we currently assume that we are using
-    # Microsoft Visual C++.
-    if test "$GCC" != yes; then
-      with_gnu_ld=no
-    fi
-    ;;
-  interix*)
-    # we just hope/assume this is gcc and not c89 (= MSVC++)
-    with_gnu_ld=yes
-    ;;
-  openbsd*)
-    with_gnu_ld=no
-    ;;
-  linux* | k*bsd*-gnu)
-    link_all_deplibs=no
-    ;;
-  esac
 
-  ld_shlibs=yes
-  if test "$with_gnu_ld" = yes; then
-    # If archive_cmds runs LD, not CC, wlarc should be empty
-    wlarc='${wl}'
 
-    # Set some defaults for GNU ld with shared library support. These
-    # are reset later if shared libraries are not supported. Putting them
-    # here allows them to be overridden if necessary.
-    runpath_var=LD_RUN_PATH
-    hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
-    export_dynamic_flag_spec='${wl}--export-dynamic'
-    # ancient GNU ld didn't support --whole-archive et. al.
-    if $LD --help 2>&1 | $GREP 'no-whole-archive' > /dev/null; then
-      whole_archive_flag_spec="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive'
-    else
-      whole_archive_flag_spec=
-    fi
-    supports_anon_versioning=no
-    case `$LD -v 2>&1` in
-      *GNU\ gold*) supports_anon_versioning=yes ;;
-      *\ [01].* | *\ 2.[0-9].* | *\ 2.10.*) ;; # catch versions < 2.11
-      *\ 2.11.93.0.2\ *) supports_anon_versioning=yes ;; # RH7.3 ...
-      *\ 2.11.92.0.12\ *) supports_anon_versioning=yes ;; # Mandrake 8.2 ...
-      *\ 2.11.*) ;; # other 2.11 versions
-      *) supports_anon_versioning=yes ;;
-    esac
 
-    # See if GNU ld supports shared libraries.
-    case $host_os in
-    aix[3-9]*)
-      # On AIX/PPC, the GNU linker is very broken
-      if test "$host_cpu" != ia64; then
-       ld_shlibs=no
-       cat <<_LT_EOF 1>&2
 
-*** Warning: the GNU linker, at least up to release 2.9.1, is reported
-*** to be unable to reliably create shared libraries on AIX.
-*** Therefore, libtool is disabling shared libraries support.  If you
-*** really care for shared libraries, you may want to modify your PATH
-*** so that a non-GNU linker is found, and then restart.
 
-_LT_EOF
-      fi
-      ;;
 
-    amigaos*)
-      case $host_cpu in
-      powerpc)
-            # see comment about AmigaOS4 .so support
-            archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
-            archive_expsym_cmds=''
-        ;;
-      m68k)
-            archive_cmds='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)'
-            hardcode_libdir_flag_spec='-L$libdir'
-            hardcode_minus_L=yes
-        ;;
-      esac
-      ;;
+xorg_testset_save_CFLAGS="$CFLAGS"
 
-    beos*)
-      if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
-       allow_undefined_flag=unsupported
-       # Joseph Beckenbach <jrb3@best.com> says some releases of gcc
-       # support --undefined.  This deserves some investigation.  FIXME
-       archive_cmds='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
-      else
-       ld_shlibs=no
-      fi
-      ;;
+if test "x$xorg_testset_cc_unknown_warning_option" = "x" ; then
+       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unknown-warning-option" >&5
+$as_echo_n "checking if $CC supports -Werror=unknown-warning-option... " >&6; }
+if ${xorg_cv_cc_flag_unknown_warning_option+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unknown_warning_option=yes
+else
+  xorg_cv_cc_flag_unknown_warning_option=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unknown_warning_option" >&5
+$as_echo "$xorg_cv_cc_flag_unknown_warning_option" >&6; }
+       xorg_testset_cc_unknown_warning_option=$xorg_cv_cc_flag_unknown_warning_option
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
 
-    cygwin* | mingw* | pw32* | cegcc*)
-      # _LT_TAGVAR(hardcode_libdir_flag_spec, ) is actually meaningless,
-      # as there is no search path for DLLs.
-      hardcode_libdir_flag_spec='-L$libdir'
-      allow_undefined_flag=unsupported
-      always_export_symbols=no
-      enable_shared_with_static_runtimes=yes
-      export_symbols_cmds='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[BCDGRS][ ]/s/.*[ ]\([^ ]*\)/\1 DATA/'\'' | $SED -e '\''/^[AITW][ ]/s/.*[ ]//'\'' | sort | uniq > $export_symbols'
+if test "x$xorg_testset_cc_unused_command_line_argument" = "x" ; then
+       if test "x$xorg_testset_cc_unknown_warning_option" = "xyes" ; then
+               CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       fi
+       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unused-command-line-argument" >&5
+$as_echo_n "checking if $CC supports -Werror=unused-command-line-argument... " >&6; }
+if ${xorg_cv_cc_flag_unused_command_line_argument+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unused_command_line_argument=yes
+else
+  xorg_cv_cc_flag_unused_command_line_argument=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unused_command_line_argument" >&5
+$as_echo "$xorg_cv_cc_flag_unused_command_line_argument" >&6; }
+       xorg_testset_cc_unused_command_line_argument=$xorg_cv_cc_flag_unused_command_line_argument
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
 
-      if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then
-        archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib'
-       # If the export-symbols file already is a .def file (1st line
-       # is EXPORTS), use it as is; otherwise, prepend...
-       archive_expsym_cmds='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then
-         cp $export_symbols $output_objdir/$soname.def;
-       else
-         echo EXPORTS > $output_objdir/$soname.def;
-         cat $export_symbols >> $output_objdir/$soname.def;
-       fi~
-       $CC -shared $output_objdir/$soname.def $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib'
-      else
-       ld_shlibs=no
-      fi
-      ;;
+found="no"
 
-    interix[3-9]*)
-      hardcode_direct=no
-      hardcode_shlibpath_var=no
-      hardcode_libdir_flag_spec='${wl}-rpath,$libdir'
-      export_dynamic_flag_spec='${wl}-E'
-      # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc.
-      # Instead, shared libraries are loaded at an image base (0x10000000 by
-      # default) and relocated if they conflict, which is a slow very memory
-      # consuming and fragmenting process.  To avoid this, we pick a random,
-      # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link
-      # time.  Moving up from 0x10000000 also allows more sbrk(2) space.
-      archive_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
-      archive_expsym_cmds='sed "s,^,_," $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--retain-symbols-file,$output_objdir/$soname.expsym ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
-      ;;
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
 
-    gnu* | linux* | tpf* | k*bsd*-gnu | kopensolaris*-gnu)
-      tmp_diet=no
-      if test "$host_os" = linux-dietlibc; then
-       case $cc_basename in
-         diet\ *) tmp_diet=yes;;       # linux-dietlibc with static linking (!diet-dyn)
-       esac
-      fi
-      if $LD --help 2>&1 | $EGREP ': supported targets:.* elf' > /dev/null \
-        && test "$tmp_diet" = no
-      then
-       tmp_addflag=
-       tmp_sharedflag='-shared'
-       case $cc_basename,$host_cpu in
-        pgcc*)                         # Portland Group C compiler
-         whole_archive_flag_spec='${wl}--whole-archive`for conv in $convenience\"\"; do test  -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive'
-         tmp_addflag=' $pic_flag'
-         ;;
-       pgf77* | pgf90* | pgf95*)       # Portland Group f77 and f90 compilers
-         whole_archive_flag_spec='${wl}--whole-archive`for conv in $convenience\"\"; do test  -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive'
-         tmp_addflag=' $pic_flag -Mnomain' ;;
-       ecc*,ia64* | icc*,ia64*)        # Intel C compiler on ia64
-         tmp_addflag=' -i_dynamic' ;;
-       efc*,ia64* | ifort*,ia64*)      # Intel Fortran compiler on ia64
-         tmp_addflag=' -i_dynamic -nofor_main' ;;
-       ifc* | ifort*)                  # Intel Fortran compiler
-         tmp_addflag=' -nofor_main' ;;
-       lf95*)                          # Lahey Fortran 8.1
-         whole_archive_flag_spec=
-         tmp_sharedflag='--shared' ;;
-       xl[cC]*)                        # IBM XL C 8.0 on PPC (deal with xlf below)
-         tmp_sharedflag='-qmkshrobj'
-         tmp_addflag= ;;
-       esac
-       case `$CC -V 2>&1 | sed 5q` in
-       *Sun\ C*)                       # Sun C 5.9
-         whole_archive_flag_spec='${wl}--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive'
-         compiler_needs_object=yes
-         tmp_sharedflag='-G' ;;
-       *Sun\ F*)                       # Sun Fortran 8.3
-         tmp_sharedflag='-G' ;;
-       esac
-       archive_cmds='$CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
 
-        if test "x$supports_anon_versioning" = xyes; then
-          archive_expsym_cmds='echo "{ global:" > $output_objdir/$libname.ver~
-           cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~
-           echo "local: *; };" >> $output_objdir/$libname.ver~
-           $CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-version-script ${wl}$output_objdir/$libname.ver -o $lib'
-        fi
+               CFLAGS="$CFLAGS -Wnonnull"
 
-       case $cc_basename in
-       xlf*)
-         # IBM XL Fortran 10.1 on PPC cannot create shared libs itself
-         whole_archive_flag_spec='--whole-archive$convenience --no-whole-archive'
-         hardcode_libdir_flag_spec=
-         hardcode_libdir_flag_spec_ld='-rpath $libdir'
-         archive_cmds='$LD -shared $libobjs $deplibs $compiler_flags -soname $soname -o $lib'
-         if test "x$supports_anon_versioning" = xyes; then
-           archive_expsym_cmds='echo "{ global:" > $output_objdir/$libname.ver~
-             cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~
-             echo "local: *; };" >> $output_objdir/$libname.ver~
-             $LD -shared $libobjs $deplibs $compiler_flags -soname $soname -version-script $output_objdir/$libname.ver -o $lib'
-         fi
-         ;;
-       esac
-      else
-        ld_shlibs=no
-      fi
-      ;;
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-Wnonnull" >&5
+$as_echo_n "checking if $CC supports-Wnonnull... " >&6; }
+               cacheid=xorg_cv_cc_flag__Wnonnull
+               if eval \${$cacheid+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+int
+main ()
+{
 
-    netbsd* | netbsdelf*-gnu)
-      if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
-       archive_cmds='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib'
-       wlarc=
-      else
-       archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
-       archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
-      fi
-      ;;
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval $cacheid=yes
+else
+  eval $cacheid=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+fi
 
-    solaris*)
-      if $LD -v 2>&1 | $GREP 'BFD 2\.8' > /dev/null; then
-       ld_shlibs=no
-       cat <<_LT_EOF 1>&2
 
-*** Warning: The releases 2.8.* of the GNU linker cannot reliably
-*** create shared libraries on Solaris systems.  Therefore, libtool
-*** is disabling shared libraries support.  We urge you to upgrade GNU
-*** binutils to release 2.9.1 or newer.  Another option is to modify
-*** your PATH or compiler configuration so that the native linker is
-*** used, and then restart.
+               CFLAGS="$xorg_testset_save_CFLAGS"
 
-_LT_EOF
-      elif $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
-       archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
-       archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
-      else
-       ld_shlibs=no
-      fi
-      ;;
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       BASE_CFLAGS="$BASE_CFLAGS -Wnonnull"
+                       found="yes"
+               fi
+       fi
 
-    sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX*)
-      case `$LD -v 2>&1` in
-        *\ [01].* | *\ 2.[0-9].* | *\ 2.1[0-5].*)
-       ld_shlibs=no
-       cat <<_LT_EOF 1>&2
 
-*** Warning: Releases of the GNU linker prior to 2.16.91.0.3 can not
-*** reliably create shared libraries on SCO systems.  Therefore, libtool
-*** is disabling shared libraries support.  We urge you to upgrade GNU
-*** binutils to release 2.16.91.0.3 or newer.  Another option is to modify
-*** your PATH or compiler configuration so that the native linker is
-*** used, and then restart.
 
-_LT_EOF
-       ;;
-       *)
-         # For security reasons, it is highly recommended that you always
-         # use absolute paths for naming shared libraries, and exclude the
-         # DT_RUNPATH tag from executables and libraries.  But doing so
-         # requires that you compile everything twice, which is a pain.
-         if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
-           hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
-           archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
-           archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
-         else
-           ld_shlibs=no
-         fi
-       ;;
-      esac
-      ;;
 
-    sunos4*)
-      archive_cmds='$LD -assert pure-text -Bshareable -o $lib $libobjs $deplibs $linker_flags'
-      wlarc=
-      hardcode_direct=yes
-      hardcode_shlibpath_var=no
-      ;;
 
-    *)
-      if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
-       archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
-       archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
-      else
-       ld_shlibs=no
-      fi
-      ;;
-    esac
 
-    if test "$ld_shlibs" = no; then
-      runpath_var=
-      hardcode_libdir_flag_spec=
-      export_dynamic_flag_spec=
-      whole_archive_flag_spec=
-    fi
-  else
-    # PORTME fill in a description of your system's linker (not GNU ld)
-    case $host_os in
-    aix3*)
-      allow_undefined_flag=unsupported
-      always_export_symbols=yes
-      archive_expsym_cmds='$LD -o $output_objdir/$soname $libobjs $deplibs $linker_flags -bE:$export_symbols -T512 -H512 -bM:SRE~$AR $AR_FLAGS $lib $output_objdir/$soname'
-      # Note: this linker hardcodes the directories in LIBPATH if there
-      # are no directories specified by -L.
-      hardcode_minus_L=yes
-      if test "$GCC" = yes && test -z "$lt_prog_compiler_static"; then
-       # Neither direct hardcoding nor static linking is supported with a
-       # broken collect2.
-       hardcode_direct=unsupported
-      fi
-      ;;
 
-    aix[4-9]*)
-      if test "$host_cpu" = ia64; then
-       # On IA64, the linker does run time linking by default, so we don't
-       # have to do anything special.
-       aix_use_runtimelinking=no
-       exp_sym_flag='-Bexport'
-       no_entry_flag=""
-      else
-       # If we're using GNU nm, then we don't want the "-C" option.
-       # -C means demangle to AIX nm, but means don't demangle with GNU nm
-       if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then
-         export_symbols_cmds='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && (substr(\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols'
-       else
-         export_symbols_cmds='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && (substr(\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols'
-       fi
-       aix_use_runtimelinking=no
 
-       # Test if we are trying to use run time linking or normal
-       # AIX style linking. If -brtl is somewhere in LDFLAGS, we
-       # need to do runtime linking.
-       case $host_os in aix4.[23]|aix4.[23].*|aix[5-9]*)
-         for ld_flag in $LDFLAGS; do
-         if (test $ld_flag = "-brtl" || test $ld_flag = "-Wl,-brtl"); then
-           aix_use_runtimelinking=yes
-           break
-         fi
-         done
-         ;;
-       esac
 
-       exp_sym_flag='-bexport'
-       no_entry_flag='-bnoentry'
-      fi
 
-      # When large executables or shared objects are built, AIX ld can
-      # have problems creating the table of contents.  If linking a library
-      # or program results in "error TOC overflow" add -mminimal-toc to
-      # CXXFLAGS/CFLAGS for g++/gcc.  In the cases where that is not
-      # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS.
 
-      archive_cmds=''
-      hardcode_direct=yes
-      hardcode_direct_absolute=yes
-      hardcode_libdir_separator=':'
-      link_all_deplibs=yes
-      file_list_spec='${wl}-f,'
 
-      if test "$GCC" = yes; then
-       case $host_os in aix4.[012]|aix4.[012].*)
-       # We only want to do this on AIX 4.2 and lower, the check
-       # below for broken collect2 doesn't work under 4.3+
-         collect2name=`${CC} -print-prog-name=collect2`
-         if test -f "$collect2name" &&
-          strings "$collect2name" | $GREP resolve_lib_name >/dev/null
-         then
-         # We have reworked collect2
-         :
-         else
-         # We have old collect2
-         hardcode_direct=unsupported
-         # It fails to find uninstalled libraries when the uninstalled
-         # path is not listed in the libpath.  Setting hardcode_minus_L
-         # to unsupported forces relinking
-         hardcode_minus_L=yes
-         hardcode_libdir_flag_spec='-L$libdir'
-         hardcode_libdir_separator=
-         fi
-         ;;
-       esac
-       shared_flag='-shared'
-       if test "$aix_use_runtimelinking" = yes; then
-         shared_flag="$shared_flag "'${wl}-G'
-       fi
-       link_all_deplibs=no
-      else
-       # not using gcc
-       if test "$host_cpu" = ia64; then
-       # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release
-       # chokes on -Wl,-G. The following line is correct:
-         shared_flag='-G'
-       else
-         if test "$aix_use_runtimelinking" = yes; then
-           shared_flag='${wl}-G'
-         else
-           shared_flag='${wl}-bM:SRE'
-         fi
-       fi
-      fi
 
-      export_dynamic_flag_spec='${wl}-bexpall'
-      # It seems that -bexpall does not export symbols beginning with
-      # underscore (_), so it is better to generate a list of symbols to export.
-      always_export_symbols=yes
-      if test "$aix_use_runtimelinking" = yes; then
-       # Warning - without using the other runtime loading flags (-brtl),
-       # -berok will link without error, but may produce a broken library.
-       allow_undefined_flag='-berok'
-        # Determine the default libpath from the value encoded in an
-        # empty executable.
-        cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+
+
+xorg_testset_save_CFLAGS="$CFLAGS"
+
+if test "x$xorg_testset_cc_unknown_warning_option" = "x" ; then
+       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unknown-warning-option" >&5
+$as_echo_n "checking if $CC supports -Werror=unknown-warning-option... " >&6; }
+if ${xorg_cv_cc_flag_unknown_warning_option+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unknown_warning_option=yes
+else
+  xorg_cv_cc_flag_unknown_warning_option=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unknown_warning_option" >&5
+$as_echo "$xorg_cv_cc_flag_unknown_warning_option" >&6; }
+       xorg_testset_cc_unknown_warning_option=$xorg_cv_cc_flag_unknown_warning_option
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
+
+if test "x$xorg_testset_cc_unused_command_line_argument" = "x" ; then
+       if test "x$xorg_testset_cc_unknown_warning_option" = "xyes" ; then
+               CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       fi
+       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unused-command-line-argument" >&5
+$as_echo_n "checking if $CC supports -Werror=unused-command-line-argument... " >&6; }
+if ${xorg_cv_cc_flag_unused_command_line_argument+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unused_command_line_argument=yes
+else
+  xorg_cv_cc_flag_unused_command_line_argument=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unused_command_line_argument" >&5
+$as_echo "$xorg_cv_cc_flag_unused_command_line_argument" >&6; }
+       xorg_testset_cc_unused_command_line_argument=$xorg_cv_cc_flag_unused_command_line_argument
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
+
+found="no"
+
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
+
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
 
+               CFLAGS="$CFLAGS -Winit-self"
+
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-Winit-self" >&5
+$as_echo_n "checking if $CC supports-Winit-self... " >&6; }
+               cacheid=xorg_cv_cc_flag__Winit_self
+               if eval \${$cacheid+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
 int
 main ()
 {
@@ -8932,37 +8970,115 @@ main ()
 }
 _ACEOF
 if ac_fn_c_try_link "$LINENO"; then :
-
-lt_aix_libpath_sed='
-    /Import File Strings/,/^$/ {
-       /^0/ {
-           s/^0  *\(.*\)$/\1/
-           p
-       }
-    }'
-aix_libpath=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
-# Check for a 64-bit object if we didn't find anything.
-if test -z "$aix_libpath"; then
-  aix_libpath=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
-fi
+  eval $cacheid=yes
+else
+  eval $cacheid=no
 fi
 rm -f core conftest.err conftest.$ac_objext \
     conftest$ac_exeext conftest.$ac_ext
-if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi
+fi
 
-        hardcode_libdir_flag_spec='${wl}-blibpath:$libdir:'"$aix_libpath"
-        archive_expsym_cmds='$CC -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags `if test "x${allow_undefined_flag}" != "x"; then $ECHO "X${wl}${allow_undefined_flag}" | $Xsed; else :; fi` '"\${wl}$exp_sym_flag:\$export_symbols $shared_flag"
-      else
-       if test "$host_cpu" = ia64; then
-         hardcode_libdir_flag_spec='${wl}-R $libdir:/usr/lib:/lib'
-         allow_undefined_flag="-z nodefs"
-         archive_expsym_cmds="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$exp_sym_flag:\$export_symbols"
-       else
-        # Determine the default libpath from the value encoded in an
-        # empty executable.
-        cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+
+               CFLAGS="$xorg_testset_save_CFLAGS"
+
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       BASE_CFLAGS="$BASE_CFLAGS -Winit-self"
+                       found="yes"
+               fi
+       fi
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+xorg_testset_save_CFLAGS="$CFLAGS"
+
+if test "x$xorg_testset_cc_unknown_warning_option" = "x" ; then
+       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unknown-warning-option" >&5
+$as_echo_n "checking if $CC supports -Werror=unknown-warning-option... " >&6; }
+if ${xorg_cv_cc_flag_unknown_warning_option+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unknown_warning_option=yes
+else
+  xorg_cv_cc_flag_unknown_warning_option=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unknown_warning_option" >&5
+$as_echo "$xorg_cv_cc_flag_unknown_warning_option" >&6; }
+       xorg_testset_cc_unknown_warning_option=$xorg_cv_cc_flag_unknown_warning_option
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
+
+if test "x$xorg_testset_cc_unused_command_line_argument" = "x" ; then
+       if test "x$xorg_testset_cc_unknown_warning_option" = "xyes" ; then
+               CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       fi
+       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unused-command-line-argument" >&5
+$as_echo_n "checking if $CC supports -Werror=unused-command-line-argument... " >&6; }
+if ${xorg_cv_cc_flag_unused_command_line_argument+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unused_command_line_argument=yes
+else
+  xorg_cv_cc_flag_unused_command_line_argument=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unused_command_line_argument" >&5
+$as_echo "$xorg_cv_cc_flag_unused_command_line_argument" >&6; }
+       xorg_testset_cc_unused_command_line_argument=$xorg_cv_cc_flag_unused_command_line_argument
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
+
+found="no"
+
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
 
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
+
+               CFLAGS="$CFLAGS -Wmain"
+
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-Wmain" >&5
+$as_echo_n "checking if $CC supports-Wmain... " >&6; }
+               cacheid=xorg_cv_cc_flag__Wmain
+               if eval \${$cacheid+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
 int
 main ()
 {
@@ -8972,503 +9088,151 @@ main ()
 }
 _ACEOF
 if ac_fn_c_try_link "$LINENO"; then :
-
-lt_aix_libpath_sed='
-    /Import File Strings/,/^$/ {
-       /^0/ {
-           s/^0  *\(.*\)$/\1/
-           p
-       }
-    }'
-aix_libpath=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
-# Check for a 64-bit object if we didn't find anything.
-if test -z "$aix_libpath"; then
-  aix_libpath=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
-fi
+  eval $cacheid=yes
+else
+  eval $cacheid=no
 fi
 rm -f core conftest.err conftest.$ac_objext \
     conftest$ac_exeext conftest.$ac_ext
-if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi
+fi
 
-        hardcode_libdir_flag_spec='${wl}-blibpath:$libdir:'"$aix_libpath"
-         # Warning - without using the other run time loading flags,
-         # -berok will link without error, but may produce a broken library.
-         no_undefined_flag=' ${wl}-bernotok'
-         allow_undefined_flag=' ${wl}-berok'
-         # Exported symbols can be pulled into shared objects from archives
-         whole_archive_flag_spec='$convenience'
-         archive_cmds_need_lc=yes
-         # This is similar to how AIX traditionally builds its shared libraries.
-         archive_expsym_cmds="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs ${wl}-bnoentry $compiler_flags ${wl}-bE:$export_symbols${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname'
+
+               CFLAGS="$xorg_testset_save_CFLAGS"
+
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       BASE_CFLAGS="$BASE_CFLAGS -Wmain"
+                       found="yes"
+               fi
        fi
-      fi
-      ;;
 
-    amigaos*)
-      case $host_cpu in
-      powerpc)
-            # see comment about AmigaOS4 .so support
-            archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
-            archive_expsym_cmds=''
-        ;;
-      m68k)
-            archive_cmds='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)'
-            hardcode_libdir_flag_spec='-L$libdir'
-            hardcode_minus_L=yes
-        ;;
-      esac
-      ;;
 
-    bsdi[45]*)
-      export_dynamic_flag_spec=-rdynamic
-      ;;
 
-    cygwin* | mingw* | pw32* | cegcc*)
-      # When not using gcc, we currently assume that we are using
-      # Microsoft Visual C++.
-      # hardcode_libdir_flag_spec is actually meaningless, as there is
-      # no search path for DLLs.
-      hardcode_libdir_flag_spec=' '
-      allow_undefined_flag=unsupported
-      # Tell ltmain to make .lib files, not .a files.
-      libext=lib
-      # Tell ltmain to make .dll files, not .so files.
-      shrext_cmds=".dll"
-      # FIXME: Setting linknames here is a bad hack.
-      archive_cmds='$CC -o $lib $libobjs $compiler_flags `$ECHO "X$deplibs" | $Xsed -e '\''s/ -lc$//'\''` -link -dll~linknames='
-      # The linker will automatically build a .lib file if we build a DLL.
-      old_archive_from_new_cmds='true'
-      # FIXME: Should let the user specify the lib program.
-      old_archive_cmds='lib -OUT:$oldlib$oldobjs$old_deplibs'
-      fix_srcfile_path='`cygpath -w "$srcfile"`'
-      enable_shared_with_static_runtimes=yes
-      ;;
 
-    darwin* | rhapsody*)
 
 
-  archive_cmds_need_lc=no
-  hardcode_direct=no
-  hardcode_automatic=yes
-  hardcode_shlibpath_var=unsupported
-  whole_archive_flag_spec=''
-  link_all_deplibs=yes
-  allow_undefined_flag="$_lt_dar_allow_undefined"
-  case $cc_basename in
-     ifort*) _lt_dar_can_shared=yes ;;
-     *) _lt_dar_can_shared=$GCC ;;
-  esac
-  if test "$_lt_dar_can_shared" = "yes"; then
-    output_verbose_link_cmd=echo
-    archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}"
-    module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}"
-    archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}"
-    module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}"
 
-  else
-  ld_shlibs=no
-  fi
 
-      ;;
 
-    dgux*)
-      archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
-      hardcode_libdir_flag_spec='-L$libdir'
-      hardcode_shlibpath_var=no
-      ;;
 
-    freebsd1*)
-      ld_shlibs=no
-      ;;
 
-    # FreeBSD 2.2.[012] allows us to include c++rt0.o to get C++ constructor
-    # support.  Future versions do this automatically, but an explicit c++rt0.o
-    # does not break anything, and helps significantly (at the cost of a little
-    # extra space).
-    freebsd2.2*)
-      archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags /usr/lib/c++rt0.o'
-      hardcode_libdir_flag_spec='-R$libdir'
-      hardcode_direct=yes
-      hardcode_shlibpath_var=no
-      ;;
 
-    # Unfortunately, older versions of FreeBSD 2 do not have this feature.
-    freebsd2*)
-      archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'
-      hardcode_direct=yes
-      hardcode_minus_L=yes
-      hardcode_shlibpath_var=no
-      ;;
 
-    # FreeBSD 3 and greater uses gcc -shared to do shared libraries.
-    freebsd* | dragonfly*)
-      archive_cmds='$CC -shared -o $lib $libobjs $deplibs $compiler_flags'
-      hardcode_libdir_flag_spec='-R$libdir'
-      hardcode_direct=yes
-      hardcode_shlibpath_var=no
-      ;;
 
-    hpux9*)
-      if test "$GCC" = yes; then
-       archive_cmds='$RM $output_objdir/$soname~$CC -shared -fPIC ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $libobjs $deplibs $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
-      else
-       archive_cmds='$RM $output_objdir/$soname~$LD -b +b $install_libdir -o $output_objdir/$soname $libobjs $deplibs $linker_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
-      fi
-      hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir'
-      hardcode_libdir_separator=:
-      hardcode_direct=yes
 
-      # hardcode_minus_L: Not really in the search PATH,
-      # but as the default location of the library.
-      hardcode_minus_L=yes
-      export_dynamic_flag_spec='${wl}-E'
-      ;;
+xorg_testset_save_CFLAGS="$CFLAGS"
 
-    hpux10*)
-      if test "$GCC" = yes -a "$with_gnu_ld" = no; then
-       archive_cmds='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'
-      else
-       archive_cmds='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags'
-      fi
-      if test "$with_gnu_ld" = no; then
-       hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir'
-       hardcode_libdir_flag_spec_ld='+b $libdir'
-       hardcode_libdir_separator=:
-       hardcode_direct=yes
-       hardcode_direct_absolute=yes
-       export_dynamic_flag_spec='${wl}-E'
-       # hardcode_minus_L: Not really in the search PATH,
-       # but as the default location of the library.
-       hardcode_minus_L=yes
-      fi
-      ;;
+if test "x$xorg_testset_cc_unknown_warning_option" = "x" ; then
+       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unknown-warning-option" >&5
+$as_echo_n "checking if $CC supports -Werror=unknown-warning-option... " >&6; }
+if ${xorg_cv_cc_flag_unknown_warning_option+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unknown_warning_option=yes
+else
+  xorg_cv_cc_flag_unknown_warning_option=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unknown_warning_option" >&5
+$as_echo "$xorg_cv_cc_flag_unknown_warning_option" >&6; }
+       xorg_testset_cc_unknown_warning_option=$xorg_cv_cc_flag_unknown_warning_option
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
 
-    hpux11*)
-      if test "$GCC" = yes -a "$with_gnu_ld" = no; then
-       case $host_cpu in
-       hppa*64*)
-         archive_cmds='$CC -shared ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
-         ;;
-       ia64*)
-         archive_cmds='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags'
-         ;;
-       *)
-         archive_cmds='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'
-         ;;
-       esac
-      else
-       case $host_cpu in
-       hppa*64*)
-         archive_cmds='$CC -b ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
-         ;;
-       ia64*)
-         archive_cmds='$CC -b ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags'
-         ;;
-       *)
-         archive_cmds='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'
-         ;;
-       esac
-      fi
-      if test "$with_gnu_ld" = no; then
-       hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir'
-       hardcode_libdir_separator=:
+if test "x$xorg_testset_cc_unused_command_line_argument" = "x" ; then
+       if test "x$xorg_testset_cc_unknown_warning_option" = "xyes" ; then
+               CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       fi
+       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unused-command-line-argument" >&5
+$as_echo_n "checking if $CC supports -Werror=unused-command-line-argument... " >&6; }
+if ${xorg_cv_cc_flag_unused_command_line_argument+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unused_command_line_argument=yes
+else
+  xorg_cv_cc_flag_unused_command_line_argument=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unused_command_line_argument" >&5
+$as_echo "$xorg_cv_cc_flag_unused_command_line_argument" >&6; }
+       xorg_testset_cc_unused_command_line_argument=$xorg_cv_cc_flag_unused_command_line_argument
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
 
-       case $host_cpu in
-       hppa*64*|ia64*)
-         hardcode_direct=no
-         hardcode_shlibpath_var=no
-         ;;
-       *)
-         hardcode_direct=yes
-         hardcode_direct_absolute=yes
-         export_dynamic_flag_spec='${wl}-E'
+found="no"
 
-         # hardcode_minus_L: Not really in the search PATH,
-         # but as the default location of the library.
-         hardcode_minus_L=yes
-         ;;
-       esac
-      fi
-      ;;
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
 
-    irix5* | irix6* | nonstopux*)
-      if test "$GCC" = yes; then
-       archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
-       # Try to use the -exported_symbol ld option, if it does not
-       # work, assume that -exports_file does not work either and
-       # implicitly export all symbols.
-        save_LDFLAGS="$LDFLAGS"
-        LDFLAGS="$LDFLAGS -shared ${wl}-exported_symbol ${wl}foo ${wl}-update_registry ${wl}/dev/null"
-        cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
+
+               CFLAGS="$CFLAGS -Wmissing-braces"
+
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-Wmissing-braces" >&5
+$as_echo_n "checking if $CC supports-Wmissing-braces... " >&6; }
+               cacheid=xorg_cv_cc_flag__Wmissing_braces
+               if eval \${$cacheid+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
-int foo(void) {}
+int i;
+int
+main ()
+{
+
+  ;
+  return 0;
+}
 _ACEOF
 if ac_fn_c_try_link "$LINENO"; then :
-  archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations ${wl}-exports_file ${wl}$export_symbols -o $lib'
-
+  eval $cacheid=yes
+else
+  eval $cacheid=no
 fi
 rm -f core conftest.err conftest.$ac_objext \
     conftest$ac_exeext conftest.$ac_ext
-        LDFLAGS="$save_LDFLAGS"
-      else
-       archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib'
-       archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -exports_file $export_symbols -o $lib'
-      fi
-      archive_cmds_need_lc='no'
-      hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
-      hardcode_libdir_separator=:
-      inherit_rpath=yes
-      link_all_deplibs=yes
-      ;;
-
-    netbsd* | netbsdelf*-gnu)
-      if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
-       archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'  # a.out
-      else
-       archive_cmds='$LD -shared -o $lib $libobjs $deplibs $linker_flags'      # ELF
-      fi
-      hardcode_libdir_flag_spec='-R$libdir'
-      hardcode_direct=yes
-      hardcode_shlibpath_var=no
-      ;;
+fi
 
-    newsos6)
-      archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
-      hardcode_direct=yes
-      hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
-      hardcode_libdir_separator=:
-      hardcode_shlibpath_var=no
-      ;;
 
-    *nto* | *qnx*)
-      ;;
+               CFLAGS="$xorg_testset_save_CFLAGS"
 
-    openbsd*)
-      if test -f /usr/libexec/ld.so; then
-       hardcode_direct=yes
-       hardcode_shlibpath_var=no
-       hardcode_direct_absolute=yes
-       if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
-         archive_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags'
-         archive_expsym_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-retain-symbols-file,$export_symbols'
-         hardcode_libdir_flag_spec='${wl}-rpath,$libdir'
-         export_dynamic_flag_spec='${wl}-E'
-       else
-         case $host_os in
-          openbsd[01].* | openbsd2.[0-7] | openbsd2.[0-7].*)
-            archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'
-            hardcode_libdir_flag_spec='-R$libdir'
-            ;;
-          *)
-            archive_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags'
-            hardcode_libdir_flag_spec='${wl}-rpath,$libdir'
-            ;;
-         esac
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       BASE_CFLAGS="$BASE_CFLAGS -Wmissing-braces"
+                       found="yes"
+               fi
        fi
-      else
-       ld_shlibs=no
-      fi
-      ;;
 
-    os2*)
-      hardcode_libdir_flag_spec='-L$libdir'
-      hardcode_minus_L=yes
-      allow_undefined_flag=unsupported
-      archive_cmds='$ECHO "LIBRARY $libname INITINSTANCE" > $output_objdir/$libname.def~$ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~$ECHO DATA >> $output_objdir/$libname.def~$ECHO " SINGLE NONSHARED" >> $output_objdir/$libname.def~$ECHO EXPORTS >> $output_objdir/$libname.def~emxexp $libobjs >> $output_objdir/$libname.def~$CC -Zdll -Zcrtdll -o $lib $libobjs $deplibs $compiler_flags $output_objdir/$libname.def'
-      old_archive_from_new_cmds='emximp -o $output_objdir/$libname.a $output_objdir/$libname.def'
-      ;;
 
-    osf3*)
-      if test "$GCC" = yes; then
-       allow_undefined_flag=' ${wl}-expect_unresolved ${wl}\*'
-       archive_cmds='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
-      else
-       allow_undefined_flag=' -expect_unresolved \*'
-       archive_cmds='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib'
-      fi
-      archive_cmds_need_lc='no'
-      hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
-      hardcode_libdir_separator=:
-      ;;
 
-    osf4* | osf5*)     # as osf3* with the addition of -msym flag
-      if test "$GCC" = yes; then
-       allow_undefined_flag=' ${wl}-expect_unresolved ${wl}\*'
-       archive_cmds='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
-       hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
-      else
-       allow_undefined_flag=' -expect_unresolved \*'
-       archive_cmds='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags -msym -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib'
-       archive_expsym_cmds='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done; printf "%s\\n" "-hidden">> $lib.exp~
-       $CC -shared${allow_undefined_flag} ${wl}-input ${wl}$lib.exp $compiler_flags $libobjs $deplibs -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib~$RM $lib.exp'
 
-       # Both c and cxx compiler support -rpath directly
-       hardcode_libdir_flag_spec='-rpath $libdir'
-      fi
-      archive_cmds_need_lc='no'
-      hardcode_libdir_separator=:
-      ;;
 
-    solaris*)
-      no_undefined_flag=' -z defs'
-      if test "$GCC" = yes; then
-       wlarc='${wl}'
-       archive_cmds='$CC -shared ${wl}-z ${wl}text ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
-       archive_expsym_cmds='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
-         $CC -shared ${wl}-z ${wl}text ${wl}-M ${wl}$lib.exp ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp'
-      else
-       case `$CC -V 2>&1` in
-       *"Compilers 5.0"*)
-         wlarc=''
-         archive_cmds='$LD -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $linker_flags'
-         archive_expsym_cmds='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
-         $LD -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $linker_flags~$RM $lib.exp'
-         ;;
-       *)
-         wlarc='${wl}'
-         archive_cmds='$CC -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $compiler_flags'
-         archive_expsym_cmds='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
-         $CC -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp'
-         ;;
-       esac
-      fi
-      hardcode_libdir_flag_spec='-R$libdir'
-      hardcode_shlibpath_var=no
-      case $host_os in
-      solaris2.[0-5] | solaris2.[0-5].*) ;;
-      *)
-       # The compiler driver will combine and reorder linker options,
-       # but understands `-z linker_flag'.  GCC discards it without `$wl',
-       # but is careful enough not to reorder.
-       # Supported since Solaris 2.6 (maybe 2.5.1?)
-       if test "$GCC" = yes; then
-         whole_archive_flag_spec='${wl}-z ${wl}allextract$convenience ${wl}-z ${wl}defaultextract'
-       else
-         whole_archive_flag_spec='-z allextract$convenience -z defaultextract'
-       fi
-       ;;
-      esac
-      link_all_deplibs=yes
-      ;;
 
-    sunos4*)
-      if test "x$host_vendor" = xsequent; then
-       # Use $CC to link under sequent, because it throws in some extra .o
-       # files that make .init and .fini sections work.
-       archive_cmds='$CC -G ${wl}-h $soname -o $lib $libobjs $deplibs $compiler_flags'
-      else
-       archive_cmds='$LD -assert pure-text -Bstatic -o $lib $libobjs $deplibs $linker_flags'
-      fi
-      hardcode_libdir_flag_spec='-L$libdir'
-      hardcode_direct=yes
-      hardcode_minus_L=yes
-      hardcode_shlibpath_var=no
-      ;;
 
-    sysv4)
-      case $host_vendor in
-       sni)
-         archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
-         hardcode_direct=yes # is this really true???
-       ;;
-       siemens)
-         ## LD is ld it makes a PLAMLIB
-         ## CC just makes a GrossModule.
-         archive_cmds='$LD -G -o $lib $libobjs $deplibs $linker_flags'
-         reload_cmds='$CC -r -o $output$reload_objs'
-         hardcode_direct=no
-        ;;
-       motorola)
-         archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
-         hardcode_direct=no #Motorola manual says yes, but my tests say they lie
-       ;;
-      esac
-      runpath_var='LD_RUN_PATH'
-      hardcode_shlibpath_var=no
-      ;;
-
-    sysv4.3*)
-      archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
-      hardcode_shlibpath_var=no
-      export_dynamic_flag_spec='-Bexport'
-      ;;
-
-    sysv4*MP*)
-      if test -d /usr/nec; then
-       archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
-       hardcode_shlibpath_var=no
-       runpath_var=LD_RUN_PATH
-       hardcode_runpath_var=yes
-       ld_shlibs=yes
-      fi
-      ;;
-
-    sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[01].[10]* | unixware7* | sco3.2v5.0.[024]*)
-      no_undefined_flag='${wl}-z,text'
-      archive_cmds_need_lc=no
-      hardcode_shlibpath_var=no
-      runpath_var='LD_RUN_PATH'
-
-      if test "$GCC" = yes; then
-       archive_cmds='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
-       archive_expsym_cmds='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
-      else
-       archive_cmds='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
-       archive_expsym_cmds='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
-      fi
-      ;;
-
-    sysv5* | sco3.2v5* | sco5v6*)
-      # Note: We can NOT use -z defs as we might desire, because we do not
-      # link with -lc, and that would cause any symbols used from libc to
-      # always be unresolved, which means just about no library would
-      # ever link correctly.  If we're not using GNU ld we use -z text
-      # though, which does catch some bad symbols but isn't as heavy-handed
-      # as -z defs.
-      no_undefined_flag='${wl}-z,text'
-      allow_undefined_flag='${wl}-z,nodefs'
-      archive_cmds_need_lc=no
-      hardcode_shlibpath_var=no
-      hardcode_libdir_flag_spec='${wl}-R,$libdir'
-      hardcode_libdir_separator=':'
-      link_all_deplibs=yes
-      export_dynamic_flag_spec='${wl}-Bexport'
-      runpath_var='LD_RUN_PATH'
-
-      if test "$GCC" = yes; then
-       archive_cmds='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
-       archive_expsym_cmds='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
-      else
-       archive_cmds='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
-       archive_expsym_cmds='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
-      fi
-      ;;
-
-    uts4*)
-      archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
-      hardcode_libdir_flag_spec='-L$libdir'
-      hardcode_shlibpath_var=no
-      ;;
-
-    *)
-      ld_shlibs=no
-      ;;
-    esac
-
-    if test x$host_vendor = xsni; then
-      case $host in
-      sysv4 | sysv4.2uw2* | sysv4.3* | sysv5*)
-       export_dynamic_flag_spec='${wl}-Blargedynsym'
-       ;;
-      esac
-    fi
-  fi
-
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ld_shlibs" >&5
-$as_echo "$ld_shlibs" >&6; }
-test "$ld_shlibs" = no && can_build_shared=no
 
-with_gnu_ld=$with_gnu_ld
 
 
 
@@ -9476,77 +9240,109 @@ with_gnu_ld=$with_gnu_ld
 
 
 
+xorg_testset_save_CFLAGS="$CFLAGS"
 
+if test "x$xorg_testset_cc_unknown_warning_option" = "x" ; then
+       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unknown-warning-option" >&5
+$as_echo_n "checking if $CC supports -Werror=unknown-warning-option... " >&6; }
+if ${xorg_cv_cc_flag_unknown_warning_option+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unknown_warning_option=yes
+else
+  xorg_cv_cc_flag_unknown_warning_option=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unknown_warning_option" >&5
+$as_echo "$xorg_cv_cc_flag_unknown_warning_option" >&6; }
+       xorg_testset_cc_unknown_warning_option=$xorg_cv_cc_flag_unknown_warning_option
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
 
+if test "x$xorg_testset_cc_unused_command_line_argument" = "x" ; then
+       if test "x$xorg_testset_cc_unknown_warning_option" = "xyes" ; then
+               CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       fi
+       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unused-command-line-argument" >&5
+$as_echo_n "checking if $CC supports -Werror=unused-command-line-argument... " >&6; }
+if ${xorg_cv_cc_flag_unused_command_line_argument+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unused_command_line_argument=yes
+else
+  xorg_cv_cc_flag_unused_command_line_argument=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unused_command_line_argument" >&5
+$as_echo "$xorg_cv_cc_flag_unused_command_line_argument" >&6; }
+       xorg_testset_cc_unused_command_line_argument=$xorg_cv_cc_flag_unused_command_line_argument
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
 
+found="no"
 
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
 
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
 
+               CFLAGS="$CFLAGS -Wsequence-point"
 
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-Wsequence-point" >&5
+$as_echo_n "checking if $CC supports-Wsequence-point... " >&6; }
+               cacheid=xorg_cv_cc_flag__Wsequence_point
+               if eval \${$cacheid+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+int
+main ()
+{
 
-#
-# Do we need to explicitly link libc?
-#
-case "x$archive_cmds_need_lc" in
-x|xyes)
-  # Assume -lc should be added
-  archive_cmds_need_lc=yes
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval $cacheid=yes
+else
+  eval $cacheid=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+fi
 
-  if test "$enable_shared" = yes && test "$GCC" = yes; then
-    case $archive_cmds in
-    *'~'*)
-      # FIXME: we may have to deal with multi-command sequences.
-      ;;
-    '$CC '*)
-      # Test whether the compiler implicitly links with -lc since on some
-      # systems, -lgcc has to come before -lc. If gcc already passes -lc
-      # to ld, don't add -lc before -lgcc.
-      { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -lc should be explicitly linked in" >&5
-$as_echo_n "checking whether -lc should be explicitly linked in... " >&6; }
-      $RM conftest*
-      echo "$lt_simple_compile_test_code" > conftest.$ac_ext
 
-      if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5
-  (eval $ac_compile) 2>&5
-  ac_status=$?
-  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
-  test $ac_status = 0; } 2>conftest.err; then
-        soname=conftest
-        lib=conftest
-        libobjs=conftest.$ac_objext
-        deplibs=
-        wl=$lt_prog_compiler_wl
-       pic_flag=$lt_prog_compiler_pic
-        compiler_flags=-v
-        linker_flags=-v
-        verstring=
-        output_objdir=.
-        libname=conftest
-        lt_save_allow_undefined_flag=$allow_undefined_flag
-        allow_undefined_flag=
-        if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$archive_cmds 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1\""; } >&5
-  (eval $archive_cmds 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1) 2>&5
-  ac_status=$?
-  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
-  test $ac_status = 0; }
-        then
-         archive_cmds_need_lc=no
-        else
-         archive_cmds_need_lc=yes
-        fi
-        allow_undefined_flag=$lt_save_allow_undefined_flag
-      else
-        cat conftest.err 1>&5
-      fi
-      $RM conftest*
-      { $as_echo "$as_me:${as_lineno-$LINENO}: result: $archive_cmds_need_lc" >&5
-$as_echo "$archive_cmds_need_lc" >&6; }
-      ;;
-    esac
-  fi
-  ;;
-esac
+               CFLAGS="$xorg_testset_save_CFLAGS"
 
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       BASE_CFLAGS="$BASE_CFLAGS -Wsequence-point"
+                       found="yes"
+               fi
+       fi
 
 
 
@@ -9562,17 +9358,109 @@ esac
 
 
 
+xorg_testset_save_CFLAGS="$CFLAGS"
 
+if test "x$xorg_testset_cc_unknown_warning_option" = "x" ; then
+       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unknown-warning-option" >&5
+$as_echo_n "checking if $CC supports -Werror=unknown-warning-option... " >&6; }
+if ${xorg_cv_cc_flag_unknown_warning_option+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unknown_warning_option=yes
+else
+  xorg_cv_cc_flag_unknown_warning_option=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unknown_warning_option" >&5
+$as_echo "$xorg_cv_cc_flag_unknown_warning_option" >&6; }
+       xorg_testset_cc_unknown_warning_option=$xorg_cv_cc_flag_unknown_warning_option
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
 
+if test "x$xorg_testset_cc_unused_command_line_argument" = "x" ; then
+       if test "x$xorg_testset_cc_unknown_warning_option" = "xyes" ; then
+               CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       fi
+       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unused-command-line-argument" >&5
+$as_echo_n "checking if $CC supports -Werror=unused-command-line-argument... " >&6; }
+if ${xorg_cv_cc_flag_unused_command_line_argument+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unused_command_line_argument=yes
+else
+  xorg_cv_cc_flag_unused_command_line_argument=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unused_command_line_argument" >&5
+$as_echo "$xorg_cv_cc_flag_unused_command_line_argument" >&6; }
+       xorg_testset_cc_unused_command_line_argument=$xorg_cv_cc_flag_unused_command_line_argument
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
 
+found="no"
 
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
 
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
 
+               CFLAGS="$CFLAGS -Wreturn-type"
 
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-Wreturn-type" >&5
+$as_echo_n "checking if $CC supports-Wreturn-type... " >&6; }
+               cacheid=xorg_cv_cc_flag__Wreturn_type
+               if eval \${$cacheid+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+int
+main ()
+{
 
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval $cacheid=yes
+else
+  eval $cacheid=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+fi
 
 
+               CFLAGS="$xorg_testset_save_CFLAGS"
 
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       BASE_CFLAGS="$BASE_CFLAGS -Wreturn-type"
+                       found="yes"
+               fi
+       fi
 
 
 
@@ -9588,17 +9476,109 @@ esac
 
 
 
+xorg_testset_save_CFLAGS="$CFLAGS"
 
+if test "x$xorg_testset_cc_unknown_warning_option" = "x" ; then
+       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unknown-warning-option" >&5
+$as_echo_n "checking if $CC supports -Werror=unknown-warning-option... " >&6; }
+if ${xorg_cv_cc_flag_unknown_warning_option+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unknown_warning_option=yes
+else
+  xorg_cv_cc_flag_unknown_warning_option=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unknown_warning_option" >&5
+$as_echo "$xorg_cv_cc_flag_unknown_warning_option" >&6; }
+       xorg_testset_cc_unknown_warning_option=$xorg_cv_cc_flag_unknown_warning_option
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
 
+if test "x$xorg_testset_cc_unused_command_line_argument" = "x" ; then
+       if test "x$xorg_testset_cc_unknown_warning_option" = "xyes" ; then
+               CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       fi
+       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unused-command-line-argument" >&5
+$as_echo_n "checking if $CC supports -Werror=unused-command-line-argument... " >&6; }
+if ${xorg_cv_cc_flag_unused_command_line_argument+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unused_command_line_argument=yes
+else
+  xorg_cv_cc_flag_unused_command_line_argument=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unused_command_line_argument" >&5
+$as_echo "$xorg_cv_cc_flag_unused_command_line_argument" >&6; }
+       xorg_testset_cc_unused_command_line_argument=$xorg_cv_cc_flag_unused_command_line_argument
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
 
+found="no"
 
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
 
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
 
+               CFLAGS="$CFLAGS -Wtrigraphs"
 
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-Wtrigraphs" >&5
+$as_echo_n "checking if $CC supports-Wtrigraphs... " >&6; }
+               cacheid=xorg_cv_cc_flag__Wtrigraphs
+               if eval \${$cacheid+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+int
+main ()
+{
 
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval $cacheid=yes
+else
+  eval $cacheid=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+fi
 
 
+               CFLAGS="$xorg_testset_save_CFLAGS"
 
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       BASE_CFLAGS="$BASE_CFLAGS -Wtrigraphs"
+                       found="yes"
+               fi
+       fi
 
 
 
@@ -9614,17 +9594,109 @@ esac
 
 
 
+xorg_testset_save_CFLAGS="$CFLAGS"
 
+if test "x$xorg_testset_cc_unknown_warning_option" = "x" ; then
+       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unknown-warning-option" >&5
+$as_echo_n "checking if $CC supports -Werror=unknown-warning-option... " >&6; }
+if ${xorg_cv_cc_flag_unknown_warning_option+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unknown_warning_option=yes
+else
+  xorg_cv_cc_flag_unknown_warning_option=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unknown_warning_option" >&5
+$as_echo "$xorg_cv_cc_flag_unknown_warning_option" >&6; }
+       xorg_testset_cc_unknown_warning_option=$xorg_cv_cc_flag_unknown_warning_option
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
 
+if test "x$xorg_testset_cc_unused_command_line_argument" = "x" ; then
+       if test "x$xorg_testset_cc_unknown_warning_option" = "xyes" ; then
+               CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       fi
+       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unused-command-line-argument" >&5
+$as_echo_n "checking if $CC supports -Werror=unused-command-line-argument... " >&6; }
+if ${xorg_cv_cc_flag_unused_command_line_argument+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unused_command_line_argument=yes
+else
+  xorg_cv_cc_flag_unused_command_line_argument=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unused_command_line_argument" >&5
+$as_echo "$xorg_cv_cc_flag_unused_command_line_argument" >&6; }
+       xorg_testset_cc_unused_command_line_argument=$xorg_cv_cc_flag_unused_command_line_argument
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
 
+found="no"
 
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
 
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
 
+               CFLAGS="$CFLAGS -Warray-bounds"
 
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-Warray-bounds" >&5
+$as_echo_n "checking if $CC supports-Warray-bounds... " >&6; }
+               cacheid=xorg_cv_cc_flag__Warray_bounds
+               if eval \${$cacheid+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+int
+main ()
+{
 
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval $cacheid=yes
+else
+  eval $cacheid=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+fi
 
 
+               CFLAGS="$xorg_testset_save_CFLAGS"
 
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       BASE_CFLAGS="$BASE_CFLAGS -Warray-bounds"
+                       found="yes"
+               fi
+       fi
 
 
 
@@ -9640,17 +9712,109 @@ esac
 
 
 
+xorg_testset_save_CFLAGS="$CFLAGS"
 
+if test "x$xorg_testset_cc_unknown_warning_option" = "x" ; then
+       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unknown-warning-option" >&5
+$as_echo_n "checking if $CC supports -Werror=unknown-warning-option... " >&6; }
+if ${xorg_cv_cc_flag_unknown_warning_option+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unknown_warning_option=yes
+else
+  xorg_cv_cc_flag_unknown_warning_option=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unknown_warning_option" >&5
+$as_echo "$xorg_cv_cc_flag_unknown_warning_option" >&6; }
+       xorg_testset_cc_unknown_warning_option=$xorg_cv_cc_flag_unknown_warning_option
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
 
+if test "x$xorg_testset_cc_unused_command_line_argument" = "x" ; then
+       if test "x$xorg_testset_cc_unknown_warning_option" = "xyes" ; then
+               CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       fi
+       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unused-command-line-argument" >&5
+$as_echo_n "checking if $CC supports -Werror=unused-command-line-argument... " >&6; }
+if ${xorg_cv_cc_flag_unused_command_line_argument+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unused_command_line_argument=yes
+else
+  xorg_cv_cc_flag_unused_command_line_argument=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unused_command_line_argument" >&5
+$as_echo "$xorg_cv_cc_flag_unused_command_line_argument" >&6; }
+       xorg_testset_cc_unused_command_line_argument=$xorg_cv_cc_flag_unused_command_line_argument
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
 
+found="no"
 
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
 
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
 
+               CFLAGS="$CFLAGS -Wwrite-strings"
 
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-Wwrite-strings" >&5
+$as_echo_n "checking if $CC supports-Wwrite-strings... " >&6; }
+               cacheid=xorg_cv_cc_flag__Wwrite_strings
+               if eval \${$cacheid+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+int
+main ()
+{
 
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval $cacheid=yes
+else
+  eval $cacheid=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+fi
 
 
+               CFLAGS="$xorg_testset_save_CFLAGS"
 
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       BASE_CFLAGS="$BASE_CFLAGS -Wwrite-strings"
+                       found="yes"
+               fi
+       fi
 
 
 
@@ -9666,17 +9830,109 @@ esac
 
 
 
+xorg_testset_save_CFLAGS="$CFLAGS"
 
+if test "x$xorg_testset_cc_unknown_warning_option" = "x" ; then
+       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unknown-warning-option" >&5
+$as_echo_n "checking if $CC supports -Werror=unknown-warning-option... " >&6; }
+if ${xorg_cv_cc_flag_unknown_warning_option+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unknown_warning_option=yes
+else
+  xorg_cv_cc_flag_unknown_warning_option=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unknown_warning_option" >&5
+$as_echo "$xorg_cv_cc_flag_unknown_warning_option" >&6; }
+       xorg_testset_cc_unknown_warning_option=$xorg_cv_cc_flag_unknown_warning_option
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
 
+if test "x$xorg_testset_cc_unused_command_line_argument" = "x" ; then
+       if test "x$xorg_testset_cc_unknown_warning_option" = "xyes" ; then
+               CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       fi
+       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unused-command-line-argument" >&5
+$as_echo_n "checking if $CC supports -Werror=unused-command-line-argument... " >&6; }
+if ${xorg_cv_cc_flag_unused_command_line_argument+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unused_command_line_argument=yes
+else
+  xorg_cv_cc_flag_unused_command_line_argument=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unused_command_line_argument" >&5
+$as_echo "$xorg_cv_cc_flag_unused_command_line_argument" >&6; }
+       xorg_testset_cc_unused_command_line_argument=$xorg_cv_cc_flag_unused_command_line_argument
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
 
+found="no"
 
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
 
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
 
+               CFLAGS="$CFLAGS -Waddress"
 
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-Waddress" >&5
+$as_echo_n "checking if $CC supports-Waddress... " >&6; }
+               cacheid=xorg_cv_cc_flag__Waddress
+               if eval \${$cacheid+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+int
+main ()
+{
 
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval $cacheid=yes
+else
+  eval $cacheid=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+fi
 
 
+               CFLAGS="$xorg_testset_save_CFLAGS"
 
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       BASE_CFLAGS="$BASE_CFLAGS -Waddress"
+                       found="yes"
+               fi
+       fi
 
 
 
@@ -9692,442 +9948,199 @@ esac
 
 
 
+xorg_testset_save_CFLAGS="$CFLAGS"
 
+if test "x$xorg_testset_cc_unknown_warning_option" = "x" ; then
+       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unknown-warning-option" >&5
+$as_echo_n "checking if $CC supports -Werror=unknown-warning-option... " >&6; }
+if ${xorg_cv_cc_flag_unknown_warning_option+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unknown_warning_option=yes
+else
+  xorg_cv_cc_flag_unknown_warning_option=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unknown_warning_option" >&5
+$as_echo "$xorg_cv_cc_flag_unknown_warning_option" >&6; }
+       xorg_testset_cc_unknown_warning_option=$xorg_cv_cc_flag_unknown_warning_option
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
 
+if test "x$xorg_testset_cc_unused_command_line_argument" = "x" ; then
+       if test "x$xorg_testset_cc_unknown_warning_option" = "xyes" ; then
+               CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       fi
+       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unused-command-line-argument" >&5
+$as_echo_n "checking if $CC supports -Werror=unused-command-line-argument... " >&6; }
+if ${xorg_cv_cc_flag_unused_command_line_argument+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unused_command_line_argument=yes
+else
+  xorg_cv_cc_flag_unused_command_line_argument=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unused_command_line_argument" >&5
+$as_echo "$xorg_cv_cc_flag_unused_command_line_argument" >&6; }
+       xorg_testset_cc_unused_command_line_argument=$xorg_cv_cc_flag_unused_command_line_argument
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
 
+found="no"
 
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
 
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
 
+               CFLAGS="$CFLAGS -Wint-to-pointer-cast"
 
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-Wint-to-pointer-cast" >&5
+$as_echo_n "checking if $CC supports-Wint-to-pointer-cast... " >&6; }
+               cacheid=xorg_cv_cc_flag__Wint_to_pointer_cast
+               if eval \${$cacheid+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+int
+main ()
+{
 
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval $cacheid=yes
+else
+  eval $cacheid=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+fi
 
 
+               CFLAGS="$xorg_testset_save_CFLAGS"
 
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking dynamic linker characteristics" >&5
-$as_echo_n "checking dynamic linker characteristics... " >&6; }
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       BASE_CFLAGS="$BASE_CFLAGS -Wint-to-pointer-cast"
+                       found="yes"
+               fi
+       fi
 
-if test "$GCC" = yes; then
-  case $host_os in
-    darwin*) lt_awk_arg="/^libraries:/,/LR/" ;;
-    *) lt_awk_arg="/^libraries:/" ;;
-  esac
-  lt_search_path_spec=`$CC -print-search-dirs | awk $lt_awk_arg | $SED -e "s/^libraries://" -e "s,=/,/,g"`
-  if $ECHO "$lt_search_path_spec" | $GREP ';' >/dev/null ; then
-    # if the path contains ";" then we assume it to be the separator
-    # otherwise default to the standard path separator (i.e. ":") - it is
-    # assumed that no part of a normal pathname contains ";" but that should
-    # okay in the real world where ";" in dirpaths is itself problematic.
-    lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED -e 's/;/ /g'`
-  else
-    lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED  -e "s/$PATH_SEPARATOR/ /g"`
-  fi
-  # Ok, now we have the path, separated by spaces, we can step through it
-  # and add multilib dir if necessary.
-  lt_tmp_lt_search_path_spec=
-  lt_multi_os_dir=`$CC $CPPFLAGS $CFLAGS $LDFLAGS -print-multi-os-directory 2>/dev/null`
-  for lt_sys_path in $lt_search_path_spec; do
-    if test -d "$lt_sys_path/$lt_multi_os_dir"; then
-      lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path/$lt_multi_os_dir"
-    else
-      test -d "$lt_sys_path" && \
-       lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path"
-    fi
-  done
-  lt_search_path_spec=`$ECHO $lt_tmp_lt_search_path_spec | awk '
-BEGIN {RS=" "; FS="/|\n";} {
-  lt_foo="";
-  lt_count=0;
-  for (lt_i = NF; lt_i > 0; lt_i--) {
-    if ($lt_i != "" && $lt_i != ".") {
-      if ($lt_i == "..") {
-        lt_count++;
-      } else {
-        if (lt_count == 0) {
-          lt_foo="/" $lt_i lt_foo;
-        } else {
-          lt_count--;
-        }
-      }
-    }
-  }
-  if (lt_foo != "") { lt_freq[lt_foo]++; }
-  if (lt_freq[lt_foo] == 1) { print lt_foo; }
-}'`
-  sys_lib_search_path_spec=`$ECHO $lt_search_path_spec`
-else
-  sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib"
-fi
-library_names_spec=
-libname_spec='lib$name'
-soname_spec=
-shrext_cmds=".so"
-postinstall_cmds=
-postuninstall_cmds=
-finish_cmds=
-finish_eval=
-shlibpath_var=
-shlibpath_overrides_runpath=unknown
-version_type=none
-dynamic_linker="$host_os ld.so"
-sys_lib_dlsearch_path_spec="/lib /usr/lib"
-need_lib_prefix=unknown
-hardcode_into_libs=no
 
-# when you set need_version to no, make sure it does not cause -set_version
-# flags to be left without arguments
-need_version=unknown
 
-case $host_os in
-aix3*)
-  version_type=linux
-  library_names_spec='${libname}${release}${shared_ext}$versuffix $libname.a'
-  shlibpath_var=LIBPATH
 
-  # AIX 3 has no versioning support, so we append a major version to the name.
-  soname_spec='${libname}${release}${shared_ext}$major'
-  ;;
 
-aix[4-9]*)
-  version_type=linux
-  need_lib_prefix=no
-  need_version=no
-  hardcode_into_libs=yes
-  if test "$host_cpu" = ia64; then
-    # AIX 5 supports IA64
-    library_names_spec='${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext}$versuffix $libname${shared_ext}'
-    shlibpath_var=LD_LIBRARY_PATH
-  else
-    # With GCC up to 2.95.x, collect2 would create an import file
-    # for dependence libraries.  The import file would start with
-    # the line `#! .'.  This would cause the generated library to
-    # depend on `.', always an invalid library.  This was fixed in
-    # development snapshots of GCC prior to 3.0.
-    case $host_os in
-      aix4 | aix4.[01] | aix4.[01].*)
-      if { echo '#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97)'
-          echo ' yes '
-          echo '#endif'; } | ${CC} -E - | $GREP yes > /dev/null; then
-       :
-      else
-       can_build_shared=no
-      fi
-      ;;
-    esac
-    # AIX (on Power*) has no versioning support, so currently we can not hardcode correct
-    # soname into executable. Probably we can add versioning support to
-    # collect2, so additional links can be useful in future.
-    if test "$aix_use_runtimelinking" = yes; then
-      # If using run time linking (on AIX 4.2 or later) use lib<name>.so
-      # instead of lib<name>.a to let people know that these are not
-      # typical AIX shared libraries.
-      library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
-    else
-      # We preserve .a as extension for shared libraries through AIX4.2
-      # and later when we are not doing run time linking.
-      library_names_spec='${libname}${release}.a $libname.a'
-      soname_spec='${libname}${release}${shared_ext}$major'
-    fi
-    shlibpath_var=LIBPATH
-  fi
-  ;;
 
-amigaos*)
-  case $host_cpu in
-  powerpc)
-    # Since July 2007 AmigaOS4 officially supports .so libraries.
-    # When compiling the executable, add -use-dynld -Lsobjs: to the compileline.
-    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
-    ;;
-  m68k)
-    library_names_spec='$libname.ixlibrary $libname.a'
-    # Create ${libname}_ixlibrary.a entries in /sys/libs.
-    finish_eval='for lib in `ls $libdir/*.ixlibrary 2>/dev/null`; do libname=`$ECHO "X$lib" | $Xsed -e '\''s%^.*/\([^/]*\)\.ixlibrary$%\1%'\''`; test $RM /sys/libs/${libname}_ixlibrary.a; $show "cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a"; cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a || exit 1; done'
-    ;;
-  esac
-  ;;
 
-beos*)
-  library_names_spec='${libname}${shared_ext}'
-  dynamic_linker="$host_os ld.so"
-  shlibpath_var=LIBRARY_PATH
-  ;;
 
-bsdi[45]*)
-  version_type=linux
-  need_version=no
-  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
-  soname_spec='${libname}${release}${shared_ext}$major'
-  finish_cmds='PATH="\$PATH:/sbin" ldconfig $libdir'
-  shlibpath_var=LD_LIBRARY_PATH
-  sys_lib_search_path_spec="/shlib /usr/lib /usr/X11/lib /usr/contrib/lib /lib /usr/local/lib"
-  sys_lib_dlsearch_path_spec="/shlib /usr/lib /usr/local/lib"
-  # the default ld.so.conf also contains /usr/contrib/lib and
-  # /usr/X11R6/lib (/usr/X11 is a link to /usr/X11R6), but let us allow
-  # libtool to hard-code these into programs
-  ;;
 
-cygwin* | mingw* | pw32* | cegcc*)
-  version_type=windows
-  shrext_cmds=".dll"
-  need_version=no
-  need_lib_prefix=no
 
-  case $GCC,$host_os in
-  yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*)
-    library_names_spec='$libname.dll.a'
-    # DLL is installed to $(libdir)/../bin by postinstall_cmds
-    postinstall_cmds='base_file=`basename \${file}`~
-      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
-      dldir=$destdir/`dirname \$dlpath`~
-      test -d \$dldir || mkdir -p \$dldir~
-      $install_prog $dir/$dlname \$dldir/$dlname~
-      chmod a+x \$dldir/$dlname~
-      if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
-        eval '\''$striplib \$dldir/$dlname'\'' || exit \$?;
-      fi'
-    postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
-      dlpath=$dir/\$dldll~
-       $RM \$dlpath'
-    shlibpath_overrides_runpath=yes
 
-    case $host_os in
-    cygwin*)
-      # Cygwin DLLs use 'cyg' prefix rather than 'lib'
-      soname_spec='`echo ${libname} | sed -e 's/^lib/cyg/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
-      sys_lib_search_path_spec="/usr/lib /lib/w32api /lib /usr/local/lib"
-      ;;
-    mingw* | cegcc*)
-      # MinGW DLLs use traditional 'lib' prefix
-      soname_spec='${libname}`echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
-      sys_lib_search_path_spec=`$CC -print-search-dirs | $GREP "^libraries:" | $SED -e "s/^libraries://" -e "s,=/,/,g"`
-      if $ECHO "$sys_lib_search_path_spec" | $GREP ';[c-zC-Z]:/' >/dev/null; then
-        # It is most probably a Windows format PATH printed by
-        # mingw gcc, but we are running on Cygwin. Gcc prints its search
-        # path with ; separators, and with drive letters. We can handle the
-        # drive letters (cygwin fileutils understands them), so leave them,
-        # especially as we might pass files found there to a mingw objdump,
-        # which wouldn't understand a cygwinified path. Ahh.
-        sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'`
-      else
-        sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED  -e "s/$PATH_SEPARATOR/ /g"`
-      fi
-      ;;
-    pw32*)
-      # pw32 DLLs use 'pw' prefix rather than 'lib'
-      library_names_spec='`echo ${libname} | sed -e 's/^lib/pw/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
-      ;;
-    esac
-    ;;
 
-  *)
-    library_names_spec='${libname}`echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext} $libname.lib'
-    ;;
-  esac
-  dynamic_linker='Win32 ld.exe'
-  # FIXME: first we should search . and the directory the executable is in
-  shlibpath_var=PATH
-  ;;
 
-darwin* | rhapsody*)
-  dynamic_linker="$host_os dyld"
-  version_type=darwin
-  need_lib_prefix=no
-  need_version=no
-  library_names_spec='${libname}${release}${major}$shared_ext ${libname}$shared_ext'
-  soname_spec='${libname}${release}${major}$shared_ext'
-  shlibpath_overrides_runpath=yes
-  shlibpath_var=DYLD_LIBRARY_PATH
-  shrext_cmds='`test .$module = .yes && echo .so || echo .dylib`'
 
-  sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/local/lib"
-  sys_lib_dlsearch_path_spec='/usr/local/lib /lib /usr/lib'
-  ;;
 
-dgux*)
-  version_type=linux
-  need_lib_prefix=no
-  need_version=no
-  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname$shared_ext'
-  soname_spec='${libname}${release}${shared_ext}$major'
-  shlibpath_var=LD_LIBRARY_PATH
-  ;;
+xorg_testset_save_CFLAGS="$CFLAGS"
 
-freebsd1*)
-  dynamic_linker=no
-  ;;
+if test "x$xorg_testset_cc_unknown_warning_option" = "x" ; then
+       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unknown-warning-option" >&5
+$as_echo_n "checking if $CC supports -Werror=unknown-warning-option... " >&6; }
+if ${xorg_cv_cc_flag_unknown_warning_option+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unknown_warning_option=yes
+else
+  xorg_cv_cc_flag_unknown_warning_option=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unknown_warning_option" >&5
+$as_echo "$xorg_cv_cc_flag_unknown_warning_option" >&6; }
+       xorg_testset_cc_unknown_warning_option=$xorg_cv_cc_flag_unknown_warning_option
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
 
-freebsd* | dragonfly*)
-  # DragonFly does not have aout.  When/if they implement a new
-  # versioning mechanism, adjust this.
-  if test -x /usr/bin/objformat; then
-    objformat=`/usr/bin/objformat`
-  else
-    case $host_os in
-    freebsd[123]*) objformat=aout ;;
-    *) objformat=elf ;;
-    esac
-  fi
-  version_type=freebsd-$objformat
-  case $version_type in
-    freebsd-elf*)
-      library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}'
-      need_version=no
-      need_lib_prefix=no
-      ;;
-    freebsd-*)
-      library_names_spec='${libname}${release}${shared_ext}$versuffix $libname${shared_ext}$versuffix'
-      need_version=yes
-      ;;
-  esac
-  shlibpath_var=LD_LIBRARY_PATH
-  case $host_os in
-  freebsd2*)
-    shlibpath_overrides_runpath=yes
-    ;;
-  freebsd3.[01]* | freebsdelf3.[01]*)
-    shlibpath_overrides_runpath=yes
-    hardcode_into_libs=yes
-    ;;
-  freebsd3.[2-9]* | freebsdelf3.[2-9]* | \
-  freebsd4.[0-5] | freebsdelf4.[0-5] | freebsd4.1.1 | freebsdelf4.1.1)
-    shlibpath_overrides_runpath=no
-    hardcode_into_libs=yes
-    ;;
-  *) # from 4.6 on, and DragonFly
-    shlibpath_overrides_runpath=yes
-    hardcode_into_libs=yes
-    ;;
-  esac
-  ;;
+if test "x$xorg_testset_cc_unused_command_line_argument" = "x" ; then
+       if test "x$xorg_testset_cc_unknown_warning_option" = "xyes" ; then
+               CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       fi
+       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unused-command-line-argument" >&5
+$as_echo_n "checking if $CC supports -Werror=unused-command-line-argument... " >&6; }
+if ${xorg_cv_cc_flag_unused_command_line_argument+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unused_command_line_argument=yes
+else
+  xorg_cv_cc_flag_unused_command_line_argument=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unused_command_line_argument" >&5
+$as_echo "$xorg_cv_cc_flag_unused_command_line_argument" >&6; }
+       xorg_testset_cc_unused_command_line_argument=$xorg_cv_cc_flag_unused_command_line_argument
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
 
-gnu*)
-  version_type=linux
-  need_lib_prefix=no
-  need_version=no
-  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}${major} ${libname}${shared_ext}'
-  soname_spec='${libname}${release}${shared_ext}$major'
-  shlibpath_var=LD_LIBRARY_PATH
-  hardcode_into_libs=yes
-  ;;
+found="no"
 
-hpux9* | hpux10* | hpux11*)
-  # Give a soname corresponding to the major version so that dld.sl refuses to
-  # link against other versions.
-  version_type=sunos
-  need_lib_prefix=no
-  need_version=no
-  case $host_cpu in
-  ia64*)
-    shrext_cmds='.so'
-    hardcode_into_libs=yes
-    dynamic_linker="$host_os dld.so"
-    shlibpath_var=LD_LIBRARY_PATH
-    shlibpath_overrides_runpath=yes # Unless +noenvvar is specified.
-    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
-    soname_spec='${libname}${release}${shared_ext}$major'
-    if test "X$HPUX_IA64_MODE" = X32; then
-      sys_lib_search_path_spec="/usr/lib/hpux32 /usr/local/lib/hpux32 /usr/local/lib"
-    else
-      sys_lib_search_path_spec="/usr/lib/hpux64 /usr/local/lib/hpux64"
-    fi
-    sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec
-    ;;
-  hppa*64*)
-    shrext_cmds='.sl'
-    hardcode_into_libs=yes
-    dynamic_linker="$host_os dld.sl"
-    shlibpath_var=LD_LIBRARY_PATH # How should we handle SHLIB_PATH
-    shlibpath_overrides_runpath=yes # Unless +noenvvar is specified.
-    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
-    soname_spec='${libname}${release}${shared_ext}$major'
-    sys_lib_search_path_spec="/usr/lib/pa20_64 /usr/ccs/lib/pa20_64"
-    sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec
-    ;;
-  *)
-    shrext_cmds='.sl'
-    dynamic_linker="$host_os dld.sl"
-    shlibpath_var=SHLIB_PATH
-    shlibpath_overrides_runpath=no # +s is required to enable SHLIB_PATH
-    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
-    soname_spec='${libname}${release}${shared_ext}$major'
-    ;;
-  esac
-  # HP-UX runs *really* slowly unless shared libraries are mode 555.
-  postinstall_cmds='chmod 555 $lib'
-  ;;
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
 
-interix[3-9]*)
-  version_type=linux
-  need_lib_prefix=no
-  need_version=no
-  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
-  soname_spec='${libname}${release}${shared_ext}$major'
-  dynamic_linker='Interix 3.x ld.so.1 (PE, like ELF)'
-  shlibpath_var=LD_LIBRARY_PATH
-  shlibpath_overrides_runpath=no
-  hardcode_into_libs=yes
-  ;;
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
 
-irix5* | irix6* | nonstopux*)
-  case $host_os in
-    nonstopux*) version_type=nonstopux ;;
-    *)
-       if test "$lt_cv_prog_gnu_ld" = yes; then
-               version_type=linux
-       else
-               version_type=irix
-       fi ;;
-  esac
-  need_lib_prefix=no
-  need_version=no
-  soname_spec='${libname}${release}${shared_ext}$major'
-  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext} $libname${shared_ext}'
-  case $host_os in
-  irix5* | nonstopux*)
-    libsuff= shlibsuff=
-    ;;
-  *)
-    case $LD in # libtool.m4 will add one of these switches to LD
-    *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ")
-      libsuff= shlibsuff= libmagic=32-bit;;
-    *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ")
-      libsuff=32 shlibsuff=N32 libmagic=N32;;
-    *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ")
-      libsuff=64 shlibsuff=64 libmagic=64-bit;;
-    *) libsuff= shlibsuff= libmagic=never-match;;
-    esac
-    ;;
-  esac
-  shlibpath_var=LD_LIBRARY${shlibsuff}_PATH
-  shlibpath_overrides_runpath=no
-  sys_lib_search_path_spec="/usr/lib${libsuff} /lib${libsuff} /usr/local/lib${libsuff}"
-  sys_lib_dlsearch_path_spec="/usr/lib${libsuff} /lib${libsuff}"
-  hardcode_into_libs=yes
-  ;;
-
-# No shared lib support for Linux oldld, aout, or coff.
-linux*oldld* | linux*aout* | linux*coff*)
-  dynamic_linker=no
-  ;;
+               CFLAGS="$CFLAGS -Wpointer-to-int-cast"
 
-# This must be Linux ELF.
-linux* | k*bsd*-gnu | kopensolaris*-gnu)
-  version_type=linux
-  need_lib_prefix=no
-  need_version=no
-  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
-  soname_spec='${libname}${release}${shared_ext}$major'
-  finish_cmds='PATH="\$PATH:/sbin" ldconfig -n $libdir'
-  shlibpath_var=LD_LIBRARY_PATH
-  shlibpath_overrides_runpath=no
-  # Some binutils ld are patched to set DT_RUNPATH
-  save_LDFLAGS=$LDFLAGS
-  save_libdir=$libdir
-  eval "libdir=/foo; wl=\"$lt_prog_compiler_wl\"; \
-       LDFLAGS=\"\$LDFLAGS $hardcode_libdir_flag_spec\""
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-Wpointer-to-int-cast" >&5
+$as_echo_n "checking if $CC supports-Wpointer-to-int-cast... " >&6; }
+               cacheid=xorg_cv_cc_flag__Wpointer_to_int_cast
+               if eval \${$cacheid+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
-
+int i;
 int
 main ()
 {
@@ -10137,288 +10150,7633 @@ main ()
 }
 _ACEOF
 if ac_fn_c_try_link "$LINENO"; then :
-  if  ($OBJDUMP -p conftest$ac_exeext) 2>/dev/null | grep "RUNPATH.*$libdir" >/dev/null; then :
-  shlibpath_overrides_runpath=yes
-fi
+  eval $cacheid=yes
+else
+  eval $cacheid=no
 fi
 rm -f core conftest.err conftest.$ac_objext \
     conftest$ac_exeext conftest.$ac_ext
-  LDFLAGS=$save_LDFLAGS
-  libdir=$save_libdir
+fi
 
-  # This implies no fast_install, which is unacceptable.
-  # Some rework will be needed to allow for fast_install
-  # before this can be enabled.
-  hardcode_into_libs=yes
 
-  # Append ld.so.conf contents to the search path
-  if test -f /etc/ld.so.conf; then
-    lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \$2)); skip = 1; } { if (!skip) print \$0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[      ]*hwcap[        ]/d;s/[:,      ]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;/^$/d' | tr '\n' ' '`
-    sys_lib_dlsearch_path_spec="/lib /usr/lib $lt_ld_extra"
-  fi
+               CFLAGS="$xorg_testset_save_CFLAGS"
 
-  # We used to test for /lib/ld.so.1 and disable shared libraries on
-  # powerpc, because MkLinux only supported shared libraries with the
-  # GNU dynamic linker.  Since this was broken with cross compilers,
-  # most powerpc-linux boxes support dynamic linking these days and
-  # people can always --disable-shared, the test was removed, and we
-  # assume the GNU/Linux dynamic linker is in use.
-  dynamic_linker='GNU/Linux ld.so'
-  ;;
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       BASE_CFLAGS="$BASE_CFLAGS -Wpointer-to-int-cast"
+                       found="yes"
+               fi
+       fi
 
-netbsdelf*-gnu)
-  version_type=linux
-  need_lib_prefix=no
-  need_version=no
-  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
-  soname_spec='${libname}${release}${shared_ext}$major'
-  shlibpath_var=LD_LIBRARY_PATH
-  shlibpath_overrides_runpath=no
-  hardcode_into_libs=yes
-  dynamic_linker='NetBSD ld.elf_so'
-  ;;
 
-netbsd*)
-  version_type=sunos
-  need_lib_prefix=no
-  need_version=no
-  if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
-    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
-    finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir'
-    dynamic_linker='NetBSD (a.out) ld.so'
-  else
-    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
-    soname_spec='${libname}${release}${shared_ext}$major'
-    dynamic_linker='NetBSD ld.elf_so'
-  fi
-  shlibpath_var=LD_LIBRARY_PATH
-  shlibpath_overrides_runpath=yes
-  hardcode_into_libs=yes
-  ;;
+fi
 
-newsos6)
-  version_type=linux
-  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
-  shlibpath_var=LD_LIBRARY_PATH
-  shlibpath_overrides_runpath=yes
-  ;;
 
-*nto* | *qnx*)
-  version_type=qnx
-  need_lib_prefix=no
-  need_version=no
-  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
-  soname_spec='${libname}${release}${shared_ext}$major'
-  shlibpath_var=LD_LIBRARY_PATH
-  shlibpath_overrides_runpath=no
-  hardcode_into_libs=yes
-  dynamic_linker='ldqnx.so'
-  ;;
 
-openbsd*)
-  version_type=sunos
-  sys_lib_dlsearch_path_spec="/usr/lib"
-  need_lib_prefix=no
-  # Some older versions of OpenBSD (3.3 at least) *do* need versioned libs.
-  case $host_os in
-    openbsd3.3 | openbsd3.3.*) need_version=yes ;;
-    *)                         need_version=no  ;;
-  esac
-  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
-  finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir'
-  shlibpath_var=LD_LIBRARY_PATH
-  if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
-    case $host_os in
-      openbsd2.[89] | openbsd2.[89].*)
-       shlibpath_overrides_runpath=no
-       ;;
-      *)
-       shlibpath_overrides_runpath=yes
-       ;;
-      esac
-  else
-    shlibpath_overrides_runpath=yes
-  fi
-  ;;
 
-os2*)
-  libname_spec='$name'
-  shrext_cmds=".dll"
-  need_lib_prefix=no
-  library_names_spec='$libname${shared_ext} $libname.a'
-  dynamic_linker='OS/2 ld.exe'
-  shlibpath_var=LIBPATH
-  ;;
 
-osf3* | osf4* | osf5*)
-  version_type=osf
-  need_lib_prefix=no
-  need_version=no
-  soname_spec='${libname}${release}${shared_ext}$major'
-  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
-  shlibpath_var=LD_LIBRARY_PATH
-  sys_lib_search_path_spec="/usr/shlib /usr/ccs/lib /usr/lib/cmplrs/cc /usr/lib /usr/local/lib /var/shlib"
-  sys_lib_dlsearch_path_spec="$sys_lib_search_path_spec"
-  ;;
 
-rdos*)
-  dynamic_linker=no
-  ;;
 
-solaris*)
-  version_type=linux
-  need_lib_prefix=no
-  need_version=no
-  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
-  soname_spec='${libname}${release}${shared_ext}$major'
-  shlibpath_var=LD_LIBRARY_PATH
-  shlibpath_overrides_runpath=yes
-  hardcode_into_libs=yes
-  # ldd complains unless libraries are executable
-  postinstall_cmds='chmod +x $lib'
-  ;;
+               CWARNFLAGS="$BASE_CFLAGS"
+               if  test "x$GCC" = xyes ; then
+                   CWARNFLAGS="$CWARNFLAGS -fno-strict-aliasing"
+               fi
 
-sunos4*)
-  version_type=sunos
-  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
-  finish_cmds='PATH="\$PATH:/usr/etc" ldconfig $libdir'
-  shlibpath_var=LD_LIBRARY_PATH
-  shlibpath_overrides_runpath=yes
-  if test "$with_gnu_ld" = yes; then
-    need_lib_prefix=no
-  fi
-  need_version=yes
-  ;;
 
-sysv4 | sysv4.3*)
-  version_type=linux
-  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
-  soname_spec='${libname}${release}${shared_ext}$major'
-  shlibpath_var=LD_LIBRARY_PATH
-  case $host_vendor in
-    sni)
-      shlibpath_overrides_runpath=no
-      need_lib_prefix=no
-      runpath_var=LD_RUN_PATH
-      ;;
-    siemens)
-      need_lib_prefix=no
-      ;;
-    motorola)
-      need_lib_prefix=no
-      need_version=no
-      shlibpath_overrides_runpath=no
-      sys_lib_search_path_spec='/lib /usr/lib /usr/ccs/lib'
-      ;;
-  esac
-  ;;
 
-sysv4*MP*)
-  if test -d /usr/nec ;then
-    version_type=linux
-    library_names_spec='$libname${shared_ext}.$versuffix $libname${shared_ext}.$major $libname${shared_ext}'
-    soname_spec='$libname${shared_ext}.$major'
-    shlibpath_var=LD_LIBRARY_PATH
-  fi
-  ;;
 
-sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*)
-  version_type=freebsd-elf
-  need_lib_prefix=no
-  need_version=no
-  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}'
-  soname_spec='${libname}${release}${shared_ext}$major'
-  shlibpath_var=LD_LIBRARY_PATH
-  shlibpath_overrides_runpath=yes
-  hardcode_into_libs=yes
-  if test "$with_gnu_ld" = yes; then
-    sys_lib_search_path_spec='/usr/local/lib /usr/gnu/lib /usr/ccs/lib /usr/lib /lib'
-  else
-    sys_lib_search_path_spec='/usr/ccs/lib /usr/lib'
-    case $host_os in
-      sco3.2v5*)
-        sys_lib_search_path_spec="$sys_lib_search_path_spec /lib"
-       ;;
-    esac
-  fi
-  sys_lib_dlsearch_path_spec='/usr/lib'
-  ;;
 
-tpf*)
-  # TPF is a cross-target only.  Preferred cross-host = GNU/Linux.
-  version_type=linux
-  need_lib_prefix=no
-  need_version=no
-  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
-  shlibpath_var=LD_LIBRARY_PATH
-  shlibpath_overrides_runpath=no
-  hardcode_into_libs=yes
-  ;;
 
-uts4*)
-  version_type=linux
-  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
-  soname_spec='${libname}${release}${shared_ext}$major'
-  shlibpath_var=LD_LIBRARY_PATH
-  ;;
 
-*)
-  dynamic_linker=no
-  ;;
-esac
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $dynamic_linker" >&5
-$as_echo "$dynamic_linker" >&6; }
-test "$dynamic_linker" = no && can_build_shared=no
 
-variables_saved_for_relink="PATH $shlibpath_var $runpath_var"
-if test "$GCC" = yes; then
-  variables_saved_for_relink="$variables_saved_for_relink GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH"
+# Check whether --enable-strict-compilation was given.
+if test "${enable_strict_compilation+set}" = set; then :
+  enableval=$enable_strict_compilation; STRICT_COMPILE=$enableval
+else
+  STRICT_COMPILE=no
+fi
+
+
+
+
+
+
+STRICT_CFLAGS=""
+
+
+
+
+
+
+
+
+
+
+
+
+
+xorg_testset_save_CFLAGS="$CFLAGS"
+
+if test "x$xorg_testset_cc_unknown_warning_option" = "x" ; then
+       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unknown-warning-option" >&5
+$as_echo_n "checking if $CC supports -Werror=unknown-warning-option... " >&6; }
+if ${xorg_cv_cc_flag_unknown_warning_option+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unknown_warning_option=yes
+else
+  xorg_cv_cc_flag_unknown_warning_option=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unknown_warning_option" >&5
+$as_echo "$xorg_cv_cc_flag_unknown_warning_option" >&6; }
+       xorg_testset_cc_unknown_warning_option=$xorg_cv_cc_flag_unknown_warning_option
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
+
+if test "x$xorg_testset_cc_unused_command_line_argument" = "x" ; then
+       if test "x$xorg_testset_cc_unknown_warning_option" = "xyes" ; then
+               CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       fi
+       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unused-command-line-argument" >&5
+$as_echo_n "checking if $CC supports -Werror=unused-command-line-argument... " >&6; }
+if ${xorg_cv_cc_flag_unused_command_line_argument+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unused_command_line_argument=yes
+else
+  xorg_cv_cc_flag_unused_command_line_argument=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unused_command_line_argument" >&5
+$as_echo "$xorg_cv_cc_flag_unused_command_line_argument" >&6; }
+       xorg_testset_cc_unused_command_line_argument=$xorg_cv_cc_flag_unused_command_line_argument
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
+
+found="no"
+
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
+
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
+
+               CFLAGS="$CFLAGS -pedantic"
+
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-pedantic" >&5
+$as_echo_n "checking if $CC supports-pedantic... " >&6; }
+               cacheid=xorg_cv_cc_flag__pedantic
+               if eval \${$cacheid+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval $cacheid=yes
+else
+  eval $cacheid=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+fi
+
+
+               CFLAGS="$xorg_testset_save_CFLAGS"
+
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       STRICT_CFLAGS="$STRICT_CFLAGS -pedantic"
+                       found="yes"
+               fi
+       fi
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+xorg_testset_save_CFLAGS="$CFLAGS"
+
+if test "x$xorg_testset_cc_unknown_warning_option" = "x" ; then
+       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unknown-warning-option" >&5
+$as_echo_n "checking if $CC supports -Werror=unknown-warning-option... " >&6; }
+if ${xorg_cv_cc_flag_unknown_warning_option+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unknown_warning_option=yes
+else
+  xorg_cv_cc_flag_unknown_warning_option=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unknown_warning_option" >&5
+$as_echo "$xorg_cv_cc_flag_unknown_warning_option" >&6; }
+       xorg_testset_cc_unknown_warning_option=$xorg_cv_cc_flag_unknown_warning_option
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
+
+if test "x$xorg_testset_cc_unused_command_line_argument" = "x" ; then
+       if test "x$xorg_testset_cc_unknown_warning_option" = "xyes" ; then
+               CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       fi
+       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unused-command-line-argument" >&5
+$as_echo_n "checking if $CC supports -Werror=unused-command-line-argument... " >&6; }
+if ${xorg_cv_cc_flag_unused_command_line_argument+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unused_command_line_argument=yes
+else
+  xorg_cv_cc_flag_unused_command_line_argument=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unused_command_line_argument" >&5
+$as_echo "$xorg_cv_cc_flag_unused_command_line_argument" >&6; }
+       xorg_testset_cc_unused_command_line_argument=$xorg_cv_cc_flag_unused_command_line_argument
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
+
+found="no"
+
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
+
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
+
+               CFLAGS="$CFLAGS -Werror"
+
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-Werror" >&5
+$as_echo_n "checking if $CC supports-Werror... " >&6; }
+               cacheid=xorg_cv_cc_flag__Werror
+               if eval \${$cacheid+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval $cacheid=yes
+else
+  eval $cacheid=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+fi
+
+
+               CFLAGS="$xorg_testset_save_CFLAGS"
+
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       STRICT_CFLAGS="$STRICT_CFLAGS -Werror"
+                       found="yes"
+               fi
+       fi
+
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
+
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
+
+               CFLAGS="$CFLAGS -errwarn"
+
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-errwarn" >&5
+$as_echo_n "checking if $CC supports-errwarn... " >&6; }
+               cacheid=xorg_cv_cc_flag__errwarn
+               if eval \${$cacheid+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval $cacheid=yes
+else
+  eval $cacheid=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+fi
+
+
+               CFLAGS="$xorg_testset_save_CFLAGS"
+
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       STRICT_CFLAGS="$STRICT_CFLAGS -errwarn"
+                       found="yes"
+               fi
+       fi
+
+
+
+# Earlier versions of gcc (eg: 4.2) support -Werror=attributes, but do not
+# activate it with -Werror, so we add it here explicitly.
+
+
+
+
+
+
+
+
+
+
+
+
+
+xorg_testset_save_CFLAGS="$CFLAGS"
+
+if test "x$xorg_testset_cc_unknown_warning_option" = "x" ; then
+       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unknown-warning-option" >&5
+$as_echo_n "checking if $CC supports -Werror=unknown-warning-option... " >&6; }
+if ${xorg_cv_cc_flag_unknown_warning_option+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unknown_warning_option=yes
+else
+  xorg_cv_cc_flag_unknown_warning_option=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unknown_warning_option" >&5
+$as_echo "$xorg_cv_cc_flag_unknown_warning_option" >&6; }
+       xorg_testset_cc_unknown_warning_option=$xorg_cv_cc_flag_unknown_warning_option
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
+
+if test "x$xorg_testset_cc_unused_command_line_argument" = "x" ; then
+       if test "x$xorg_testset_cc_unknown_warning_option" = "xyes" ; then
+               CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+       fi
+       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -Werror=unused-command-line-argument" >&5
+$as_echo_n "checking if $CC supports -Werror=unused-command-line-argument... " >&6; }
+if ${xorg_cv_cc_flag_unused_command_line_argument+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  xorg_cv_cc_flag_unused_command_line_argument=yes
+else
+  xorg_cv_cc_flag_unused_command_line_argument=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xorg_cv_cc_flag_unused_command_line_argument" >&5
+$as_echo "$xorg_cv_cc_flag_unused_command_line_argument" >&6; }
+       xorg_testset_cc_unused_command_line_argument=$xorg_cv_cc_flag_unused_command_line_argument
+       CFLAGS="$xorg_testset_save_CFLAGS"
+fi
+
+found="no"
+
+       if test $found = "no" ; then
+               if test "x$xorg_testset_unknown_warning_option" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unknown-warning-option"
+               fi
+
+               if test "x$xorg_testset_unused_command_line_argument" = "xyes" ; then
+                       CFLAGS="$CFLAGS -Werror=unused-command-line-argument"
+               fi
+
+               CFLAGS="$CFLAGS -Werror=attributes"
+
+               { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports-Werror=attributes" >&5
+$as_echo_n "checking if $CC supports-Werror=attributes... " >&6; }
+               cacheid=xorg_cv_cc_flag__Werror_attributes
+               if eval \${$cacheid+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval $cacheid=yes
+else
+  eval $cacheid=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+fi
+
+
+               CFLAGS="$xorg_testset_save_CFLAGS"
+
+               eval supported=\$$cacheid
+               { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supported" >&5
+$as_echo "$supported" >&6; }
+               if test "$supported" = "yes" ; then
+                       STRICT_CFLAGS="$STRICT_CFLAGS -Werror=attributes"
+                       found="yes"
+               fi
+       fi
+
+
+
+if test "x$STRICT_COMPILE" = "xyes"; then
+    BASE_CFLAGS="$BASE_CFLAGS $STRICT_CFLAGS"
+    CWARNFLAGS="$CWARNFLAGS $STRICT_CFLAGS"
+fi
+
+
+
+
+
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_VERSION_MAJOR `echo $PACKAGE_VERSION | cut -d . -f 1`
+_ACEOF
+
+       PVM=`echo $PACKAGE_VERSION | cut -d . -f 2 | cut -d - -f 1`
+       if test "x$PVM" = "x"; then
+               PVM="0"
+       fi
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_VERSION_MINOR $PVM
+_ACEOF
+
+       PVP=`echo $PACKAGE_VERSION | cut -d . -f 3 | cut -d - -f 1`
+       if test "x$PVP" = "x"; then
+               PVP="0"
+       fi
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_VERSION_PATCHLEVEL $PVP
+_ACEOF
+
+
+
+CHANGELOG_CMD="(GIT_DIR=\$(top_srcdir)/.git git log > \$(top_srcdir)/.changelog.tmp && \
+mv \$(top_srcdir)/.changelog.tmp \$(top_srcdir)/ChangeLog) \
+|| (rm -f \$(top_srcdir)/.changelog.tmp; touch \$(top_srcdir)/ChangeLog; \
+echo 'git directory not found: installing possibly empty changelog.' >&2)"
+
+
+
+
+macros_datadir=`$PKG_CONFIG --print-errors --variable=pkgdatadir xorg-macros`
+INSTALL_CMD="(cp -f "$macros_datadir/INSTALL" \$(top_srcdir)/.INSTALL.tmp && \
+mv \$(top_srcdir)/.INSTALL.tmp \$(top_srcdir)/INSTALL) \
+|| (rm -f \$(top_srcdir)/.INSTALL.tmp; touch \$(top_srcdir)/INSTALL; \
+echo 'util-macros \"pkgdatadir\" from xorg-macros.pc not found: installing possibly empty INSTALL.' >&2)"
+
+
+
+
+
+
+if test x$APP_MAN_SUFFIX = x    ; then
+    APP_MAN_SUFFIX=1
+fi
+if test x$APP_MAN_DIR = x    ; then
+    APP_MAN_DIR='$(mandir)/man$(APP_MAN_SUFFIX)'
+fi
+
+if test x$LIB_MAN_SUFFIX = x    ; then
+    LIB_MAN_SUFFIX=3
+fi
+if test x$LIB_MAN_DIR = x    ; then
+    LIB_MAN_DIR='$(mandir)/man$(LIB_MAN_SUFFIX)'
+fi
+
+if test x$FILE_MAN_SUFFIX = x    ; then
+    case $host_os in
+       solaris*)       FILE_MAN_SUFFIX=4  ;;
+       *)              FILE_MAN_SUFFIX=5  ;;
+    esac
+fi
+if test x$FILE_MAN_DIR = x    ; then
+    FILE_MAN_DIR='$(mandir)/man$(FILE_MAN_SUFFIX)'
+fi
+
+if test x$MISC_MAN_SUFFIX = x    ; then
+    case $host_os in
+       solaris*)       MISC_MAN_SUFFIX=5  ;;
+       *)              MISC_MAN_SUFFIX=7  ;;
+    esac
+fi
+if test x$MISC_MAN_DIR = x    ; then
+    MISC_MAN_DIR='$(mandir)/man$(MISC_MAN_SUFFIX)'
+fi
+
+if test x$DRIVER_MAN_SUFFIX = x    ; then
+    case $host_os in
+       solaris*)       DRIVER_MAN_SUFFIX=7  ;;
+       *)              DRIVER_MAN_SUFFIX=4  ;;
+    esac
+fi
+if test x$DRIVER_MAN_DIR = x    ; then
+    DRIVER_MAN_DIR='$(mandir)/man$(DRIVER_MAN_SUFFIX)'
+fi
+
+if test x$ADMIN_MAN_SUFFIX = x    ; then
+    case $host_os in
+       solaris*)       ADMIN_MAN_SUFFIX=1m ;;
+       *)              ADMIN_MAN_SUFFIX=8  ;;
+    esac
+fi
+if test x$ADMIN_MAN_DIR = x    ; then
+    ADMIN_MAN_DIR='$(mandir)/man$(ADMIN_MAN_SUFFIX)'
+fi
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+XORG_MAN_PAGE="X Version 11"
+
+MAN_SUBSTS="\
+       -e 's|__vendorversion__|\"\$(PACKAGE_STRING)\" \"\$(XORG_MAN_PAGE)\"|' \
+       -e 's|__xorgversion__|\"\$(PACKAGE_STRING)\" \"\$(XORG_MAN_PAGE)\"|' \
+       -e 's|__xservername__|Xorg|g' \
+       -e 's|__xconfigfile__|xorg.conf|g' \
+       -e 's|__projectroot__|\$(prefix)|g' \
+       -e 's|__apploaddir__|\$(appdefaultdir)|g' \
+       -e 's|__appmansuffix__|\$(APP_MAN_SUFFIX)|g' \
+       -e 's|__drivermansuffix__|\$(DRIVER_MAN_SUFFIX)|g' \
+       -e 's|__adminmansuffix__|\$(ADMIN_MAN_SUFFIX)|g' \
+       -e 's|__libmansuffix__|\$(LIB_MAN_SUFFIX)|g' \
+       -e 's|__miscmansuffix__|\$(MISC_MAN_SUFFIX)|g' \
+       -e 's|__filemansuffix__|\$(FILE_MAN_SUFFIX)|g'"
+
+
+
+# Check whether --enable-silent-rules was given.
+if test "${enable_silent_rules+set}" = set; then :
+  enableval=$enable_silent_rules;
+fi
+
+case $enable_silent_rules in
+yes) AM_DEFAULT_VERBOSITY=0;;
+no)  AM_DEFAULT_VERBOSITY=1;;
+*)   AM_DEFAULT_VERBOSITY=0;;
+esac
+am_make=${MAKE-make}
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $am_make supports nested variables" >&5
+$as_echo_n "checking whether $am_make supports nested variables... " >&6; }
+if ${am_cv_make_support_nested_variables+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if $as_echo 'TRUE=$(BAR$(V))
+BAR0=false
+BAR1=true
+V=1
+am__doit:
+       @$(TRUE)
+.PHONY: am__doit' | $am_make -f - >/dev/null 2>&1; then
+  am_cv_make_support_nested_variables=yes
+else
+  am_cv_make_support_nested_variables=no
+fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_make_support_nested_variables" >&5
+$as_echo "$am_cv_make_support_nested_variables" >&6; }
+if test $am_cv_make_support_nested_variables = yes; then
+    AM_V='$(V)'
+  AM_DEFAULT_V='$(AM_DEFAULT_VERBOSITY)'
+else
+  AM_V=$AM_DEFAULT_VERBOSITY
+  AM_DEFAULT_V=$AM_DEFAULT_VERBOSITY
+fi
+AM_BACKSLASH='\'
+
+
+
+# Require X.Org server macros (i.e. XORG_DRIVER_CHECK_EXT) to check for required modules
+
+
+# Initialize libtool
+# Check whether --enable-static was given.
+if test "${enable_static+set}" = set; then :
+  enableval=$enable_static; p=${PACKAGE-default}
+    case $enableval in
+    yes) enable_static=yes ;;
+    no) enable_static=no ;;
+    *)
+     enable_static=no
+      # Look at the argument we got.  We use all the common list separators.
+      lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
+      for pkg in $enableval; do
+       IFS="$lt_save_ifs"
+       if test "X$pkg" = "X$p"; then
+         enable_static=yes
+       fi
+      done
+      IFS="$lt_save_ifs"
+      ;;
+    esac
+else
+  enable_static=no
+fi
+
+
+
+
+
+
+
+
+
+case `pwd` in
+  *\ * | *\    *)
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Libtool does not cope well with whitespace in \`pwd\`" >&5
+$as_echo "$as_me: WARNING: Libtool does not cope well with whitespace in \`pwd\`" >&2;} ;;
+esac
+
+
+
+macro_version='2.4.2'
+macro_revision='1.3337'
+
+
+
+
+
+
+
+
+
+
+
+
+
+ltmain="$ac_aux_dir/ltmain.sh"
+
+# Backslashify metacharacters that are still active within
+# double-quoted strings.
+sed_quote_subst='s/\(["`$\\]\)/\\\1/g'
+
+# Same as above, but do not quote variable references.
+double_quote_subst='s/\(["`\\]\)/\\\1/g'
+
+# Sed substitution to delay expansion of an escaped shell variable in a
+# double_quote_subst'ed string.
+delay_variable_subst='s/\\\\\\\\\\\$/\\\\\\$/g'
+
+# Sed substitution to delay expansion of an escaped single quote.
+delay_single_quote_subst='s/'\''/'\'\\\\\\\'\''/g'
+
+# Sed substitution to avoid accidental globbing in evaled expressions
+no_glob_subst='s/\*/\\\*/g'
+
+ECHO='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'
+ECHO=$ECHO$ECHO$ECHO$ECHO$ECHO
+ECHO=$ECHO$ECHO$ECHO$ECHO$ECHO$ECHO
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to print strings" >&5
+$as_echo_n "checking how to print strings... " >&6; }
+# Test print first, because it will be a builtin if present.
+if test "X`( print -r -- -n ) 2>/dev/null`" = X-n && \
+   test "X`print -r -- $ECHO 2>/dev/null`" = "X$ECHO"; then
+  ECHO='print -r --'
+elif test "X`printf %s $ECHO 2>/dev/null`" = "X$ECHO"; then
+  ECHO='printf %s\n'
+else
+  # Use this function as a fallback that always works.
+  func_fallback_echo ()
+  {
+    eval 'cat <<_LTECHO_EOF
+$1
+_LTECHO_EOF'
+  }
+  ECHO='func_fallback_echo'
+fi
+
+# func_echo_all arg...
+# Invoke $ECHO with all args, space-separated.
+func_echo_all ()
+{
+    $ECHO ""
+}
+
+case "$ECHO" in
+  printf*) { $as_echo "$as_me:${as_lineno-$LINENO}: result: printf" >&5
+$as_echo "printf" >&6; } ;;
+  print*) { $as_echo "$as_me:${as_lineno-$LINENO}: result: print -r" >&5
+$as_echo "print -r" >&6; } ;;
+  *) { $as_echo "$as_me:${as_lineno-$LINENO}: result: cat" >&5
+$as_echo "cat" >&6; } ;;
+esac
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a sed that does not truncate output" >&5
+$as_echo_n "checking for a sed that does not truncate output... " >&6; }
+if ${ac_cv_path_SED+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+            ac_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
+     for ac_i in 1 2 3 4 5 6 7; do
+       ac_script="$ac_script$as_nl$ac_script"
+     done
+     echo "$ac_script" 2>/dev/null | sed 99q >conftest.sed
+     { ac_script=; unset ac_script;}
+     if test -z "$SED"; then
+  ac_path_SED_found=false
+  # Loop through the user's path and test for each of PROGNAME-LIST
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_prog in sed gsed; do
+    for ac_exec_ext in '' $ac_executable_extensions; do
+      ac_path_SED="$as_dir/$ac_prog$ac_exec_ext"
+      as_fn_executable_p "$ac_path_SED" || continue
+# Check for GNU ac_path_SED and select it if it is found.
+  # Check for GNU $ac_path_SED
+case `"$ac_path_SED" --version 2>&1` in
+*GNU*)
+  ac_cv_path_SED="$ac_path_SED" ac_path_SED_found=:;;
+*)
+  ac_count=0
+  $as_echo_n 0123456789 >"conftest.in"
+  while :
+  do
+    cat "conftest.in" "conftest.in" >"conftest.tmp"
+    mv "conftest.tmp" "conftest.in"
+    cp "conftest.in" "conftest.nl"
+    $as_echo '' >> "conftest.nl"
+    "$ac_path_SED" -f conftest.sed < "conftest.nl" >"conftest.out" 2>/dev/null || break
+    diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
+    as_fn_arith $ac_count + 1 && ac_count=$as_val
+    if test $ac_count -gt ${ac_path_SED_max-0}; then
+      # Best one so far, save it but keep looking for a better one
+      ac_cv_path_SED="$ac_path_SED"
+      ac_path_SED_max=$ac_count
+    fi
+    # 10*(2^10) chars as input seems more than enough
+    test $ac_count -gt 10 && break
+  done
+  rm -f conftest.in conftest.tmp conftest.nl conftest.out;;
+esac
+
+      $ac_path_SED_found && break 3
+    done
+  done
+  done
+IFS=$as_save_IFS
+  if test -z "$ac_cv_path_SED"; then
+    as_fn_error $? "no acceptable sed could be found in \$PATH" "$LINENO" 5
+  fi
+else
+  ac_cv_path_SED=$SED
+fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_SED" >&5
+$as_echo "$ac_cv_path_SED" >&6; }
+ SED="$ac_cv_path_SED"
+  rm -f conftest.sed
+
+test -z "$SED" && SED=sed
+Xsed="$SED -e 1s/^X//"
+
+
+
+
+
+
+
+
+
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for fgrep" >&5
+$as_echo_n "checking for fgrep... " >&6; }
+if ${ac_cv_path_FGREP+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if echo 'ab*c' | $GREP -F 'ab*c' >/dev/null 2>&1
+   then ac_cv_path_FGREP="$GREP -F"
+   else
+     if test -z "$FGREP"; then
+  ac_path_FGREP_found=false
+  # Loop through the user's path and test for each of PROGNAME-LIST
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_prog in fgrep; do
+    for ac_exec_ext in '' $ac_executable_extensions; do
+      ac_path_FGREP="$as_dir/$ac_prog$ac_exec_ext"
+      as_fn_executable_p "$ac_path_FGREP" || continue
+# Check for GNU ac_path_FGREP and select it if it is found.
+  # Check for GNU $ac_path_FGREP
+case `"$ac_path_FGREP" --version 2>&1` in
+*GNU*)
+  ac_cv_path_FGREP="$ac_path_FGREP" ac_path_FGREP_found=:;;
+*)
+  ac_count=0
+  $as_echo_n 0123456789 >"conftest.in"
+  while :
+  do
+    cat "conftest.in" "conftest.in" >"conftest.tmp"
+    mv "conftest.tmp" "conftest.in"
+    cp "conftest.in" "conftest.nl"
+    $as_echo 'FGREP' >> "conftest.nl"
+    "$ac_path_FGREP" FGREP < "conftest.nl" >"conftest.out" 2>/dev/null || break
+    diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
+    as_fn_arith $ac_count + 1 && ac_count=$as_val
+    if test $ac_count -gt ${ac_path_FGREP_max-0}; then
+      # Best one so far, save it but keep looking for a better one
+      ac_cv_path_FGREP="$ac_path_FGREP"
+      ac_path_FGREP_max=$ac_count
+    fi
+    # 10*(2^10) chars as input seems more than enough
+    test $ac_count -gt 10 && break
+  done
+  rm -f conftest.in conftest.tmp conftest.nl conftest.out;;
+esac
+
+      $ac_path_FGREP_found && break 3
+    done
+  done
+  done
+IFS=$as_save_IFS
+  if test -z "$ac_cv_path_FGREP"; then
+    as_fn_error $? "no acceptable fgrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5
+  fi
+else
+  ac_cv_path_FGREP=$FGREP
+fi
+
+   fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_FGREP" >&5
+$as_echo "$ac_cv_path_FGREP" >&6; }
+ FGREP="$ac_cv_path_FGREP"
+
+
+test -z "$GREP" && GREP=grep
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+# Check whether --with-gnu-ld was given.
+if test "${with_gnu_ld+set}" = set; then :
+  withval=$with_gnu_ld; test "$withval" = no || with_gnu_ld=yes
+else
+  with_gnu_ld=no
+fi
+
+ac_prog=ld
+if test "$GCC" = yes; then
+  # Check if gcc -print-prog-name=ld gives a path.
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ld used by $CC" >&5
+$as_echo_n "checking for ld used by $CC... " >&6; }
+  case $host in
+  *-*-mingw*)
+    # gcc leaves a trailing carriage return which upsets mingw
+    ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;;
+  *)
+    ac_prog=`($CC -print-prog-name=ld) 2>&5` ;;
+  esac
+  case $ac_prog in
+    # Accept absolute paths.
+    [\\/]* | ?:[\\/]*)
+      re_direlt='/[^/][^/]*/\.\./'
+      # Canonicalize the pathname of ld
+      ac_prog=`$ECHO "$ac_prog"| $SED 's%\\\\%/%g'`
+      while $ECHO "$ac_prog" | $GREP "$re_direlt" > /dev/null 2>&1; do
+       ac_prog=`$ECHO $ac_prog| $SED "s%$re_direlt%/%"`
+      done
+      test -z "$LD" && LD="$ac_prog"
+      ;;
+  "")
+    # If it fails, then pretend we aren't using GCC.
+    ac_prog=ld
+    ;;
+  *)
+    # If it is relative, then search for the first ld in PATH.
+    with_gnu_ld=unknown
+    ;;
+  esac
+elif test "$with_gnu_ld" = yes; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GNU ld" >&5
+$as_echo_n "checking for GNU ld... " >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for non-GNU ld" >&5
+$as_echo_n "checking for non-GNU ld... " >&6; }
+fi
+if ${lt_cv_path_LD+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -z "$LD"; then
+  lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
+  for ac_dir in $PATH; do
+    IFS="$lt_save_ifs"
+    test -z "$ac_dir" && ac_dir=.
+    if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then
+      lt_cv_path_LD="$ac_dir/$ac_prog"
+      # Check to see if the program is GNU ld.  I'd rather use --version,
+      # but apparently some variants of GNU ld only accept -v.
+      # Break only if it was the GNU/non-GNU ld that we prefer.
+      case `"$lt_cv_path_LD" -v 2>&1 </dev/null` in
+      *GNU* | *'with BFD'*)
+       test "$with_gnu_ld" != no && break
+       ;;
+      *)
+       test "$with_gnu_ld" != yes && break
+       ;;
+      esac
+    fi
+  done
+  IFS="$lt_save_ifs"
+else
+  lt_cv_path_LD="$LD" # Let the user override the test with a path.
+fi
+fi
+
+LD="$lt_cv_path_LD"
+if test -n "$LD"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LD" >&5
+$as_echo "$LD" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+test -z "$LD" && as_fn_error $? "no acceptable ld found in \$PATH" "$LINENO" 5
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if the linker ($LD) is GNU ld" >&5
+$as_echo_n "checking if the linker ($LD) is GNU ld... " >&6; }
+if ${lt_cv_prog_gnu_ld+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  # I'd rather use --version here, but apparently some GNU lds only accept -v.
+case `$LD -v 2>&1 </dev/null` in
+*GNU* | *'with BFD'*)
+  lt_cv_prog_gnu_ld=yes
+  ;;
+*)
+  lt_cv_prog_gnu_ld=no
+  ;;
+esac
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_gnu_ld" >&5
+$as_echo "$lt_cv_prog_gnu_ld" >&6; }
+with_gnu_ld=$lt_cv_prog_gnu_ld
+
+
+
+
+
+
+
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for BSD- or MS-compatible name lister (nm)" >&5
+$as_echo_n "checking for BSD- or MS-compatible name lister (nm)... " >&6; }
+if ${lt_cv_path_NM+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$NM"; then
+  # Let the user override the test.
+  lt_cv_path_NM="$NM"
+else
+  lt_nm_to_check="${ac_tool_prefix}nm"
+  if test -n "$ac_tool_prefix" && test "$build" = "$host"; then
+    lt_nm_to_check="$lt_nm_to_check nm"
+  fi
+  for lt_tmp_nm in $lt_nm_to_check; do
+    lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
+    for ac_dir in $PATH /usr/ccs/bin/elf /usr/ccs/bin /usr/ucb /bin; do
+      IFS="$lt_save_ifs"
+      test -z "$ac_dir" && ac_dir=.
+      tmp_nm="$ac_dir/$lt_tmp_nm"
+      if test -f "$tmp_nm" || test -f "$tmp_nm$ac_exeext" ; then
+       # Check to see if the nm accepts a BSD-compat flag.
+       # Adding the `sed 1q' prevents false positives on HP-UX, which says:
+       #   nm: unknown option "B" ignored
+       # Tru64's nm complains that /dev/null is an invalid object file
+       case `"$tmp_nm" -B /dev/null 2>&1 | sed '1q'` in
+       */dev/null* | *'Invalid file or object type'*)
+         lt_cv_path_NM="$tmp_nm -B"
+         break
+         ;;
+       *)
+         case `"$tmp_nm" -p /dev/null 2>&1 | sed '1q'` in
+         */dev/null*)
+           lt_cv_path_NM="$tmp_nm -p"
+           break
+           ;;
+         *)
+           lt_cv_path_NM=${lt_cv_path_NM="$tmp_nm"} # keep the first match, but
+           continue # so that we can try to find one that supports BSD flags
+           ;;
+         esac
+         ;;
+       esac
+      fi
+    done
+    IFS="$lt_save_ifs"
+  done
+  : ${lt_cv_path_NM=no}
+fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_path_NM" >&5
+$as_echo "$lt_cv_path_NM" >&6; }
+if test "$lt_cv_path_NM" != "no"; then
+  NM="$lt_cv_path_NM"
+else
+  # Didn't find any BSD compatible name lister, look for dumpbin.
+  if test -n "$DUMPBIN"; then :
+    # Let the user override the test.
+  else
+    if test -n "$ac_tool_prefix"; then
+  for ac_prog in dumpbin "link -dump"
+  do
+    # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
+set dummy $ac_tool_prefix$ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_DUMPBIN+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$DUMPBIN"; then
+  ac_cv_prog_DUMPBIN="$DUMPBIN" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_DUMPBIN="$ac_tool_prefix$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+DUMPBIN=$ac_cv_prog_DUMPBIN
+if test -n "$DUMPBIN"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DUMPBIN" >&5
+$as_echo "$DUMPBIN" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+    test -n "$DUMPBIN" && break
+  done
+fi
+if test -z "$DUMPBIN"; then
+  ac_ct_DUMPBIN=$DUMPBIN
+  for ac_prog in dumpbin "link -dump"
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_ac_ct_DUMPBIN+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_DUMPBIN"; then
+  ac_cv_prog_ac_ct_DUMPBIN="$ac_ct_DUMPBIN" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_DUMPBIN="$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_DUMPBIN=$ac_cv_prog_ac_ct_DUMPBIN
+if test -n "$ac_ct_DUMPBIN"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DUMPBIN" >&5
+$as_echo "$ac_ct_DUMPBIN" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$ac_ct_DUMPBIN" && break
+done
+
+  if test "x$ac_ct_DUMPBIN" = x; then
+    DUMPBIN=":"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    DUMPBIN=$ac_ct_DUMPBIN
+  fi
+fi
+
+    case `$DUMPBIN -symbols /dev/null 2>&1 | sed '1q'` in
+    *COFF*)
+      DUMPBIN="$DUMPBIN -symbols"
+      ;;
+    *)
+      DUMPBIN=:
+      ;;
+    esac
+  fi
+
+  if test "$DUMPBIN" != ":"; then
+    NM="$DUMPBIN"
+  fi
+fi
+test -z "$NM" && NM=nm
+
+
+
+
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking the name lister ($NM) interface" >&5
+$as_echo_n "checking the name lister ($NM) interface... " >&6; }
+if ${lt_cv_nm_interface+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_nm_interface="BSD nm"
+  echo "int some_variable = 0;" > conftest.$ac_ext
+  (eval echo "\"\$as_me:$LINENO: $ac_compile\"" >&5)
+  (eval "$ac_compile" 2>conftest.err)
+  cat conftest.err >&5
+  (eval echo "\"\$as_me:$LINENO: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
+  (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out)
+  cat conftest.err >&5
+  (eval echo "\"\$as_me:$LINENO: output\"" >&5)
+  cat conftest.out >&5
+  if $GREP 'External.*some_variable' conftest.out > /dev/null; then
+    lt_cv_nm_interface="MS dumpbin"
+  fi
+  rm -f conftest*
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_nm_interface" >&5
+$as_echo "$lt_cv_nm_interface" >&6; }
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ln -s works" >&5
+$as_echo_n "checking whether ln -s works... " >&6; }
+LN_S=$as_ln_s
+if test "$LN_S" = "ln -s"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no, using $LN_S" >&5
+$as_echo "no, using $LN_S" >&6; }
+fi
+
+# find the maximum length of command line arguments
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking the maximum length of command line arguments" >&5
+$as_echo_n "checking the maximum length of command line arguments... " >&6; }
+if ${lt_cv_sys_max_cmd_len+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+    i=0
+  teststring="ABCD"
+
+  case $build_os in
+  msdosdjgpp*)
+    # On DJGPP, this test can blow up pretty badly due to problems in libc
+    # (any single argument exceeding 2000 bytes causes a buffer overrun
+    # during glob expansion).  Even if it were fixed, the result of this
+    # check would be larger than it should be.
+    lt_cv_sys_max_cmd_len=12288;    # 12K is about right
+    ;;
+
+  gnu*)
+    # Under GNU Hurd, this test is not required because there is
+    # no limit to the length of command line arguments.
+    # Libtool will interpret -1 as no limit whatsoever
+    lt_cv_sys_max_cmd_len=-1;
+    ;;
+
+  cygwin* | mingw* | cegcc*)
+    # On Win9x/ME, this test blows up -- it succeeds, but takes
+    # about 5 minutes as the teststring grows exponentially.
+    # Worse, since 9x/ME are not pre-emptively multitasking,
+    # you end up with a "frozen" computer, even though with patience
+    # the test eventually succeeds (with a max line length of 256k).
+    # Instead, let's just punt: use the minimum linelength reported by
+    # all of the supported platforms: 8192 (on NT/2K/XP).
+    lt_cv_sys_max_cmd_len=8192;
+    ;;
+
+  mint*)
+    # On MiNT this can take a long time and run out of memory.
+    lt_cv_sys_max_cmd_len=8192;
+    ;;
+
+  amigaos*)
+    # On AmigaOS with pdksh, this test takes hours, literally.
+    # So we just punt and use a minimum line length of 8192.
+    lt_cv_sys_max_cmd_len=8192;
+    ;;
+
+  netbsd* | freebsd* | openbsd* | darwin* | dragonfly*)
+    # This has been around since 386BSD, at least.  Likely further.
+    if test -x /sbin/sysctl; then
+      lt_cv_sys_max_cmd_len=`/sbin/sysctl -n kern.argmax`
+    elif test -x /usr/sbin/sysctl; then
+      lt_cv_sys_max_cmd_len=`/usr/sbin/sysctl -n kern.argmax`
+    else
+      lt_cv_sys_max_cmd_len=65536      # usable default for all BSDs
+    fi
+    # And add a safety zone
+    lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4`
+    lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3`
+    ;;
+
+  interix*)
+    # We know the value 262144 and hardcode it with a safety zone (like BSD)
+    lt_cv_sys_max_cmd_len=196608
+    ;;
+
+  os2*)
+    # The test takes a long time on OS/2.
+    lt_cv_sys_max_cmd_len=8192
+    ;;
+
+  osf*)
+    # Dr. Hans Ekkehard Plesser reports seeing a kernel panic running configure
+    # due to this test when exec_disable_arg_limit is 1 on Tru64. It is not
+    # nice to cause kernel panics so lets avoid the loop below.
+    # First set a reasonable default.
+    lt_cv_sys_max_cmd_len=16384
+    #
+    if test -x /sbin/sysconfig; then
+      case `/sbin/sysconfig -q proc exec_disable_arg_limit` in
+        *1*) lt_cv_sys_max_cmd_len=-1 ;;
+      esac
+    fi
+    ;;
+  sco3.2v5*)
+    lt_cv_sys_max_cmd_len=102400
+    ;;
+  sysv5* | sco5v6* | sysv4.2uw2*)
+    kargmax=`grep ARG_MAX /etc/conf/cf.d/stune 2>/dev/null`
+    if test -n "$kargmax"; then
+      lt_cv_sys_max_cmd_len=`echo $kargmax | sed 's/.*[         ]//'`
+    else
+      lt_cv_sys_max_cmd_len=32768
+    fi
+    ;;
+  *)
+    lt_cv_sys_max_cmd_len=`(getconf ARG_MAX) 2> /dev/null`
+    if test -n "$lt_cv_sys_max_cmd_len"; then
+      lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4`
+      lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3`
+    else
+      # Make teststring a little bigger before we do anything with it.
+      # a 1K string should be a reasonable start.
+      for i in 1 2 3 4 5 6 7 8 ; do
+        teststring=$teststring$teststring
+      done
+      SHELL=${SHELL-${CONFIG_SHELL-/bin/sh}}
+      # If test is not a shell built-in, we'll probably end up computing a
+      # maximum length that is only half of the actual maximum length, but
+      # we can't tell.
+      while { test "X"`env echo "$teststring$teststring" 2>/dev/null` \
+                = "X$teststring$teststring"; } >/dev/null 2>&1 &&
+             test $i != 17 # 1/2 MB should be enough
+      do
+        i=`expr $i + 1`
+        teststring=$teststring$teststring
+      done
+      # Only check the string length outside the loop.
+      lt_cv_sys_max_cmd_len=`expr "X$teststring" : ".*" 2>&1`
+      teststring=
+      # Add a significant safety factor because C++ compilers can tack on
+      # massive amounts of additional arguments before passing them to the
+      # linker.  It appears as though 1/2 is a usable value.
+      lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 2`
+    fi
+    ;;
+  esac
+
+fi
+
+if test -n $lt_cv_sys_max_cmd_len ; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_sys_max_cmd_len" >&5
+$as_echo "$lt_cv_sys_max_cmd_len" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: none" >&5
+$as_echo "none" >&6; }
+fi
+max_cmd_len=$lt_cv_sys_max_cmd_len
+
+
+
+
+
+
+: ${CP="cp -f"}
+: ${MV="mv -f"}
+: ${RM="rm -f"}
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the shell understands some XSI constructs" >&5
+$as_echo_n "checking whether the shell understands some XSI constructs... " >&6; }
+# Try some XSI features
+xsi_shell=no
+( _lt_dummy="a/b/c"
+  test "${_lt_dummy##*/},${_lt_dummy%/*},${_lt_dummy#??}"${_lt_dummy%"$_lt_dummy"}, \
+      = c,a/b,b/c, \
+    && eval 'test $(( 1 + 1 )) -eq 2 \
+    && test "${#_lt_dummy}" -eq 5' ) >/dev/null 2>&1 \
+  && xsi_shell=yes
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $xsi_shell" >&5
+$as_echo "$xsi_shell" >&6; }
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the shell understands \"+=\"" >&5
+$as_echo_n "checking whether the shell understands \"+=\"... " >&6; }
+lt_shell_append=no
+( foo=bar; set foo baz; eval "$1+=\$2" && test "$foo" = barbaz ) \
+    >/dev/null 2>&1 \
+  && lt_shell_append=yes
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_shell_append" >&5
+$as_echo "$lt_shell_append" >&6; }
+
+
+if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then
+  lt_unset=unset
+else
+  lt_unset=false
+fi
+
+
+
+
+
+# test EBCDIC or ASCII
+case `echo X|tr X '\101'` in
+ A) # ASCII based system
+    # \n is not interpreted correctly by Solaris 8 /usr/ucb/tr
+  lt_SP2NL='tr \040 \012'
+  lt_NL2SP='tr \015\012 \040\040'
+  ;;
+ *) # EBCDIC based system
+  lt_SP2NL='tr \100 \n'
+  lt_NL2SP='tr \r\n \100\100'
+  ;;
+esac
+
+
+
+
+
+
+
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to convert $build file names to $host format" >&5
+$as_echo_n "checking how to convert $build file names to $host format... " >&6; }
+if ${lt_cv_to_host_file_cmd+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $host in
+  *-*-mingw* )
+    case $build in
+      *-*-mingw* ) # actually msys
+        lt_cv_to_host_file_cmd=func_convert_file_msys_to_w32
+        ;;
+      *-*-cygwin* )
+        lt_cv_to_host_file_cmd=func_convert_file_cygwin_to_w32
+        ;;
+      * ) # otherwise, assume *nix
+        lt_cv_to_host_file_cmd=func_convert_file_nix_to_w32
+        ;;
+    esac
+    ;;
+  *-*-cygwin* )
+    case $build in
+      *-*-mingw* ) # actually msys
+        lt_cv_to_host_file_cmd=func_convert_file_msys_to_cygwin
+        ;;
+      *-*-cygwin* )
+        lt_cv_to_host_file_cmd=func_convert_file_noop
+        ;;
+      * ) # otherwise, assume *nix
+        lt_cv_to_host_file_cmd=func_convert_file_nix_to_cygwin
+        ;;
+    esac
+    ;;
+  * ) # unhandled hosts (and "normal" native builds)
+    lt_cv_to_host_file_cmd=func_convert_file_noop
+    ;;
+esac
+
+fi
+
+to_host_file_cmd=$lt_cv_to_host_file_cmd
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_to_host_file_cmd" >&5
+$as_echo "$lt_cv_to_host_file_cmd" >&6; }
+
+
+
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to convert $build file names to toolchain format" >&5
+$as_echo_n "checking how to convert $build file names to toolchain format... " >&6; }
+if ${lt_cv_to_tool_file_cmd+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  #assume ordinary cross tools, or native build.
+lt_cv_to_tool_file_cmd=func_convert_file_noop
+case $host in
+  *-*-mingw* )
+    case $build in
+      *-*-mingw* ) # actually msys
+        lt_cv_to_tool_file_cmd=func_convert_file_msys_to_w32
+        ;;
+    esac
+    ;;
+esac
+
+fi
+
+to_tool_file_cmd=$lt_cv_to_tool_file_cmd
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_to_tool_file_cmd" >&5
+$as_echo "$lt_cv_to_tool_file_cmd" >&6; }
+
+
+
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $LD option to reload object files" >&5
+$as_echo_n "checking for $LD option to reload object files... " >&6; }
+if ${lt_cv_ld_reload_flag+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_ld_reload_flag='-r'
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_reload_flag" >&5
+$as_echo "$lt_cv_ld_reload_flag" >&6; }
+reload_flag=$lt_cv_ld_reload_flag
+case $reload_flag in
+"" | " "*) ;;
+*) reload_flag=" $reload_flag" ;;
+esac
+reload_cmds='$LD$reload_flag -o $output$reload_objs'
+case $host_os in
+  cygwin* | mingw* | pw32* | cegcc*)
+    if test "$GCC" != yes; then
+      reload_cmds=false
+    fi
+    ;;
+  darwin*)
+    if test "$GCC" = yes; then
+      reload_cmds='$LTCC $LTCFLAGS -nostdlib ${wl}-r -o $output$reload_objs'
+    else
+      reload_cmds='$LD$reload_flag -o $output$reload_objs'
+    fi
+    ;;
+esac
+
+
+
+
+
+
+
+
+
+if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}objdump", so it can be a program name with args.
+set dummy ${ac_tool_prefix}objdump; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_OBJDUMP+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$OBJDUMP"; then
+  ac_cv_prog_OBJDUMP="$OBJDUMP" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_OBJDUMP="${ac_tool_prefix}objdump"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+OBJDUMP=$ac_cv_prog_OBJDUMP
+if test -n "$OBJDUMP"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OBJDUMP" >&5
+$as_echo "$OBJDUMP" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_OBJDUMP"; then
+  ac_ct_OBJDUMP=$OBJDUMP
+  # Extract the first word of "objdump", so it can be a program name with args.
+set dummy objdump; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_ac_ct_OBJDUMP+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_OBJDUMP"; then
+  ac_cv_prog_ac_ct_OBJDUMP="$ac_ct_OBJDUMP" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_OBJDUMP="objdump"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_OBJDUMP=$ac_cv_prog_ac_ct_OBJDUMP
+if test -n "$ac_ct_OBJDUMP"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OBJDUMP" >&5
+$as_echo "$ac_ct_OBJDUMP" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_OBJDUMP" = x; then
+    OBJDUMP="false"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    OBJDUMP=$ac_ct_OBJDUMP
+  fi
+else
+  OBJDUMP="$ac_cv_prog_OBJDUMP"
+fi
+
+test -z "$OBJDUMP" && OBJDUMP=objdump
+
+
+
+
+
+
+
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to recognize dependent libraries" >&5
+$as_echo_n "checking how to recognize dependent libraries... " >&6; }
+if ${lt_cv_deplibs_check_method+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_file_magic_cmd='$MAGIC_CMD'
+lt_cv_file_magic_test_file=
+lt_cv_deplibs_check_method='unknown'
+# Need to set the preceding variable on all platforms that support
+# interlibrary dependencies.
+# 'none' -- dependencies not supported.
+# `unknown' -- same as none, but documents that we really don't know.
+# 'pass_all' -- all dependencies passed with no checks.
+# 'test_compile' -- check by making test program.
+# 'file_magic [[regex]]' -- check by looking for files in library path
+# which responds to the $file_magic_cmd with a given extended regex.
+# If you have `file' or equivalent on your system and you're not sure
+# whether `pass_all' will *always* work, you probably want this one.
+
+case $host_os in
+aix[4-9]*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+beos*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+bsdi[45]*)
+  lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [ML]SB (shared object|dynamic lib)'
+  lt_cv_file_magic_cmd='/usr/bin/file -L'
+  lt_cv_file_magic_test_file=/shlib/libc.so
+  ;;
+
+cygwin*)
+  # func_win32_libid is a shell function defined in ltmain.sh
+  lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL'
+  lt_cv_file_magic_cmd='func_win32_libid'
+  ;;
+
+mingw* | pw32*)
+  # Base MSYS/MinGW do not provide the 'file' command needed by
+  # func_win32_libid shell function, so use a weaker test based on 'objdump',
+  # unless we find 'file', for example because we are cross-compiling.
+  # func_win32_libid assumes BSD nm, so disallow it if using MS dumpbin.
+  if ( test "$lt_cv_nm_interface" = "BSD nm" && file / ) >/dev/null 2>&1; then
+    lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL'
+    lt_cv_file_magic_cmd='func_win32_libid'
+  else
+    # Keep this pattern in sync with the one in func_win32_libid.
+    lt_cv_deplibs_check_method='file_magic file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)'
+    lt_cv_file_magic_cmd='$OBJDUMP -f'
+  fi
+  ;;
+
+cegcc*)
+  # use the weaker test based on 'objdump'. See mingw*.
+  lt_cv_deplibs_check_method='file_magic file format pe-arm-.*little(.*architecture: arm)?'
+  lt_cv_file_magic_cmd='$OBJDUMP -f'
+  ;;
+
+darwin* | rhapsody*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+freebsd* | dragonfly*)
+  if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then
+    case $host_cpu in
+    i*86 )
+      # Not sure whether the presence of OpenBSD here was a mistake.
+      # Let's accept both of them until this is cleared up.
+      lt_cv_deplibs_check_method='file_magic (FreeBSD|OpenBSD|DragonFly)/i[3-9]86 (compact )?demand paged shared library'
+      lt_cv_file_magic_cmd=/usr/bin/file
+      lt_cv_file_magic_test_file=`echo /usr/lib/libc.so.*`
+      ;;
+    esac
+  else
+    lt_cv_deplibs_check_method=pass_all
+  fi
+  ;;
+
+haiku*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+hpux10.20* | hpux11*)
+  lt_cv_file_magic_cmd=/usr/bin/file
+  case $host_cpu in
+  ia64*)
+    lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF-[0-9][0-9]) shared object file - IA64'
+    lt_cv_file_magic_test_file=/usr/lib/hpux32/libc.so
+    ;;
+  hppa*64*)
+    lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF[ -][0-9][0-9])(-bit)?( [LM]SB)? shared object( file)?[, -]* PA-RISC [0-9]\.[0-9]'
+    lt_cv_file_magic_test_file=/usr/lib/pa20_64/libc.sl
+    ;;
+  *)
+    lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|PA-RISC[0-9]\.[0-9]) shared library'
+    lt_cv_file_magic_test_file=/usr/lib/libc.sl
+    ;;
+  esac
+  ;;
+
+interix[3-9]*)
+  # PIC code is broken on Interix 3.x, that's why |\.a not |_pic\.a here
+  lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so|\.a)$'
+  ;;
+
+irix5* | irix6* | nonstopux*)
+  case $LD in
+  *-32|*"-32 ") libmagic=32-bit;;
+  *-n32|*"-n32 ") libmagic=N32;;
+  *-64|*"-64 ") libmagic=64-bit;;
+  *) libmagic=never-match;;
+  esac
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+# This must be glibc/ELF.
+linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+netbsd* | netbsdelf*-gnu)
+  if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then
+    lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so\.[0-9]+\.[0-9]+|_pic\.a)$'
+  else
+    lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so|_pic\.a)$'
+  fi
+  ;;
+
+newos6*)
+  lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [ML]SB (executable|dynamic lib)'
+  lt_cv_file_magic_cmd=/usr/bin/file
+  lt_cv_file_magic_test_file=/usr/lib/libnls.so
+  ;;
+
+*nto* | *qnx*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+openbsd*)
+  if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
+    lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so\.[0-9]+\.[0-9]+|\.so|_pic\.a)$'
+  else
+    lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so\.[0-9]+\.[0-9]+|_pic\.a)$'
+  fi
+  ;;
+
+osf3* | osf4* | osf5*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+rdos*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+solaris*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+
+sysv4 | sysv4.3*)
+  case $host_vendor in
+  motorola)
+    lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [ML]SB (shared object|dynamic lib) M[0-9][0-9]* Version [0-9]'
+    lt_cv_file_magic_test_file=`echo /usr/lib/libc.so*`
+    ;;
+  ncr)
+    lt_cv_deplibs_check_method=pass_all
+    ;;
+  sequent)
+    lt_cv_file_magic_cmd='/bin/file'
+    lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [LM]SB (shared object|dynamic lib )'
+    ;;
+  sni)
+    lt_cv_file_magic_cmd='/bin/file'
+    lt_cv_deplibs_check_method="file_magic ELF [0-9][0-9]*-bit [LM]SB dynamic lib"
+    lt_cv_file_magic_test_file=/lib/libc.so
+    ;;
+  siemens)
+    lt_cv_deplibs_check_method=pass_all
+    ;;
+  pc)
+    lt_cv_deplibs_check_method=pass_all
+    ;;
+  esac
+  ;;
+
+tpf*)
+  lt_cv_deplibs_check_method=pass_all
+  ;;
+esac
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_deplibs_check_method" >&5
+$as_echo "$lt_cv_deplibs_check_method" >&6; }
+
+file_magic_glob=
+want_nocaseglob=no
+if test "$build" = "$host"; then
+  case $host_os in
+  mingw* | pw32*)
+    if ( shopt | grep nocaseglob ) >/dev/null 2>&1; then
+      want_nocaseglob=yes
+    else
+      file_magic_glob=`echo aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ | $SED -e "s/\(..\)/s\/[\1]\/[\1]\/g;/g"`
+    fi
+    ;;
+  esac
+fi
+
+file_magic_cmd=$lt_cv_file_magic_cmd
+deplibs_check_method=$lt_cv_deplibs_check_method
+test -z "$deplibs_check_method" && deplibs_check_method=unknown
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}dlltool", so it can be a program name with args.
+set dummy ${ac_tool_prefix}dlltool; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_DLLTOOL+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$DLLTOOL"; then
+  ac_cv_prog_DLLTOOL="$DLLTOOL" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_DLLTOOL="${ac_tool_prefix}dlltool"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+DLLTOOL=$ac_cv_prog_DLLTOOL
+if test -n "$DLLTOOL"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DLLTOOL" >&5
+$as_echo "$DLLTOOL" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_DLLTOOL"; then
+  ac_ct_DLLTOOL=$DLLTOOL
+  # Extract the first word of "dlltool", so it can be a program name with args.
+set dummy dlltool; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_ac_ct_DLLTOOL+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_DLLTOOL"; then
+  ac_cv_prog_ac_ct_DLLTOOL="$ac_ct_DLLTOOL" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_DLLTOOL="dlltool"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_DLLTOOL=$ac_cv_prog_ac_ct_DLLTOOL
+if test -n "$ac_ct_DLLTOOL"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DLLTOOL" >&5
+$as_echo "$ac_ct_DLLTOOL" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_DLLTOOL" = x; then
+    DLLTOOL="false"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    DLLTOOL=$ac_ct_DLLTOOL
+  fi
+else
+  DLLTOOL="$ac_cv_prog_DLLTOOL"
+fi
+
+test -z "$DLLTOOL" && DLLTOOL=dlltool
+
+
+
+
+
+
+
+
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to associate runtime and link libraries" >&5
+$as_echo_n "checking how to associate runtime and link libraries... " >&6; }
+if ${lt_cv_sharedlib_from_linklib_cmd+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_sharedlib_from_linklib_cmd='unknown'
+
+case $host_os in
+cygwin* | mingw* | pw32* | cegcc*)
+  # two different shell functions defined in ltmain.sh
+  # decide which to use based on capabilities of $DLLTOOL
+  case `$DLLTOOL --help 2>&1` in
+  *--identify-strict*)
+    lt_cv_sharedlib_from_linklib_cmd=func_cygming_dll_for_implib
+    ;;
+  *)
+    lt_cv_sharedlib_from_linklib_cmd=func_cygming_dll_for_implib_fallback
+    ;;
+  esac
+  ;;
+*)
+  # fallback: assume linklib IS sharedlib
+  lt_cv_sharedlib_from_linklib_cmd="$ECHO"
+  ;;
+esac
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_sharedlib_from_linklib_cmd" >&5
+$as_echo "$lt_cv_sharedlib_from_linklib_cmd" >&6; }
+sharedlib_from_linklib_cmd=$lt_cv_sharedlib_from_linklib_cmd
+test -z "$sharedlib_from_linklib_cmd" && sharedlib_from_linklib_cmd=$ECHO
+
+
+
+
+
+
+
+if test -n "$ac_tool_prefix"; then
+  for ac_prog in ar
+  do
+    # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
+set dummy $ac_tool_prefix$ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_AR+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$AR"; then
+  ac_cv_prog_AR="$AR" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_AR="$ac_tool_prefix$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+AR=$ac_cv_prog_AR
+if test -n "$AR"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AR" >&5
+$as_echo "$AR" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+    test -n "$AR" && break
+  done
+fi
+if test -z "$AR"; then
+  ac_ct_AR=$AR
+  for ac_prog in ar
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_ac_ct_AR+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_AR"; then
+  ac_cv_prog_ac_ct_AR="$ac_ct_AR" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_AR="$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_AR=$ac_cv_prog_ac_ct_AR
+if test -n "$ac_ct_AR"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_AR" >&5
+$as_echo "$ac_ct_AR" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$ac_ct_AR" && break
+done
+
+  if test "x$ac_ct_AR" = x; then
+    AR="false"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    AR=$ac_ct_AR
+  fi
+fi
+
+: ${AR=ar}
+: ${AR_FLAGS=cru}
+
+
+
+
+
+
+
+
+
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for archiver @FILE support" >&5
+$as_echo_n "checking for archiver @FILE support... " >&6; }
+if ${lt_cv_ar_at_file+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_ar_at_file=no
+   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  echo conftest.$ac_objext > conftest.lst
+      lt_ar_try='$AR $AR_FLAGS libconftest.a @conftest.lst >&5'
+      { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$lt_ar_try\""; } >&5
+  (eval $lt_ar_try) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }
+      if test "$ac_status" -eq 0; then
+       # Ensure the archiver fails upon bogus file names.
+       rm -f conftest.$ac_objext libconftest.a
+       { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$lt_ar_try\""; } >&5
+  (eval $lt_ar_try) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }
+       if test "$ac_status" -ne 0; then
+          lt_cv_ar_at_file=@
+        fi
+      fi
+      rm -f conftest.* libconftest.a
+
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ar_at_file" >&5
+$as_echo "$lt_cv_ar_at_file" >&6; }
+
+if test "x$lt_cv_ar_at_file" = xno; then
+  archiver_list_spec=
+else
+  archiver_list_spec=$lt_cv_ar_at_file
+fi
+
+
+
+
+
+
+
+if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}strip", so it can be a program name with args.
+set dummy ${ac_tool_prefix}strip; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_STRIP+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$STRIP"; then
+  ac_cv_prog_STRIP="$STRIP" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_STRIP="${ac_tool_prefix}strip"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+STRIP=$ac_cv_prog_STRIP
+if test -n "$STRIP"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $STRIP" >&5
+$as_echo "$STRIP" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_STRIP"; then
+  ac_ct_STRIP=$STRIP
+  # Extract the first word of "strip", so it can be a program name with args.
+set dummy strip; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_ac_ct_STRIP+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_STRIP"; then
+  ac_cv_prog_ac_ct_STRIP="$ac_ct_STRIP" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_STRIP="strip"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_STRIP=$ac_cv_prog_ac_ct_STRIP
+if test -n "$ac_ct_STRIP"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_STRIP" >&5
+$as_echo "$ac_ct_STRIP" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_STRIP" = x; then
+    STRIP=":"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    STRIP=$ac_ct_STRIP
+  fi
+else
+  STRIP="$ac_cv_prog_STRIP"
+fi
+
+test -z "$STRIP" && STRIP=:
+
+
+
+
+
+
+if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args.
+set dummy ${ac_tool_prefix}ranlib; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_RANLIB+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$RANLIB"; then
+  ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+RANLIB=$ac_cv_prog_RANLIB
+if test -n "$RANLIB"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $RANLIB" >&5
+$as_echo "$RANLIB" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_RANLIB"; then
+  ac_ct_RANLIB=$RANLIB
+  # Extract the first word of "ranlib", so it can be a program name with args.
+set dummy ranlib; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_ac_ct_RANLIB+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_RANLIB"; then
+  ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_RANLIB="ranlib"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB
+if test -n "$ac_ct_RANLIB"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_RANLIB" >&5
+$as_echo "$ac_ct_RANLIB" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_RANLIB" = x; then
+    RANLIB=":"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    RANLIB=$ac_ct_RANLIB
+  fi
+else
+  RANLIB="$ac_cv_prog_RANLIB"
+fi
+
+test -z "$RANLIB" && RANLIB=:
+
+
+
+
+
+
+# Determine commands to create old-style static archives.
+old_archive_cmds='$AR $AR_FLAGS $oldlib$oldobjs'
+old_postinstall_cmds='chmod 644 $oldlib'
+old_postuninstall_cmds=
+
+if test -n "$RANLIB"; then
+  case $host_os in
+  openbsd*)
+    old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB -t \$tool_oldlib"
+    ;;
+  *)
+    old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB \$tool_oldlib"
+    ;;
+  esac
+  old_archive_cmds="$old_archive_cmds~\$RANLIB \$tool_oldlib"
+fi
+
+case $host_os in
+  darwin*)
+    lock_old_archive_extraction=yes ;;
+  *)
+    lock_old_archive_extraction=no ;;
+esac
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+# If no C compiler was specified, use CC.
+LTCC=${LTCC-"$CC"}
+
+# If no C compiler flags were specified, use CFLAGS.
+LTCFLAGS=${LTCFLAGS-"$CFLAGS"}
+
+# Allow CC to be a program name with arguments.
+compiler=$CC
+
+
+# Check for command to grab the raw symbol name followed by C symbol from nm.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking command to parse $NM output from $compiler object" >&5
+$as_echo_n "checking command to parse $NM output from $compiler object... " >&6; }
+if ${lt_cv_sys_global_symbol_pipe+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+
+# These are sane defaults that work on at least a few old systems.
+# [They come from Ultrix.  What could be older than Ultrix?!! ;)]
+
+# Character class describing NM global symbol codes.
+symcode='[BCDEGRST]'
+
+# Regexp to match symbols that can be accessed directly from C.
+sympat='\([_A-Za-z][_A-Za-z0-9]*\)'
+
+# Define system-specific variables.
+case $host_os in
+aix*)
+  symcode='[BCDT]'
+  ;;
+cygwin* | mingw* | pw32* | cegcc*)
+  symcode='[ABCDGISTW]'
+  ;;
+hpux*)
+  if test "$host_cpu" = ia64; then
+    symcode='[ABCDEGRST]'
+  fi
+  ;;
+irix* | nonstopux*)
+  symcode='[BCDEGRST]'
+  ;;
+osf*)
+  symcode='[BCDEGQRST]'
+  ;;
+solaris*)
+  symcode='[BDRT]'
+  ;;
+sco3.2v5*)
+  symcode='[DT]'
+  ;;
+sysv4.2uw2*)
+  symcode='[DT]'
+  ;;
+sysv5* | sco5v6* | unixware* | OpenUNIX*)
+  symcode='[ABDT]'
+  ;;
+sysv4)
+  symcode='[DFNSTU]'
+  ;;
+esac
+
+# If we're using GNU nm, then use its standard symbol codes.
+case `$NM -V 2>&1` in
+*GNU* | *'with BFD'*)
+  symcode='[ABCDGIRSTW]' ;;
+esac
+
+# Transform an extracted symbol line into a proper C declaration.
+# Some systems (esp. on ia64) link data and code symbols differently,
+# so use this general approach.
+lt_cv_sys_global_symbol_to_cdecl="sed -n -e 's/^T .* \(.*\)$/extern int \1();/p' -e 's/^$symcode* .* \(.*\)$/extern char \1;/p'"
+
+# Transform an extracted symbol line into symbol name and symbol address
+lt_cv_sys_global_symbol_to_c_name_address="sed -n -e 's/^: \([^ ]*\)[ ]*$/  {\\\"\1\\\", (void *) 0},/p' -e 's/^$symcode* \([^ ]*\) \([^ ]*\)$/  {\"\2\", (void *) \&\2},/p'"
+lt_cv_sys_global_symbol_to_c_name_address_lib_prefix="sed -n -e 's/^: \([^ ]*\)[ ]*$/  {\\\"\1\\\", (void *) 0},/p' -e 's/^$symcode* \([^ ]*\) \(lib[^ ]*\)$/  {\"\2\", (void *) \&\2},/p' -e 's/^$symcode* \([^ ]*\) \([^ ]*\)$/  {\"lib\2\", (void *) \&\2},/p'"
+
+# Handle CRLF in mingw tool chain
+opt_cr=
+case $build_os in
+mingw*)
+  opt_cr=`$ECHO 'x\{0,1\}' | tr x '\015'` # option cr in regexp
+  ;;
+esac
+
+# Try without a prefix underscore, then with it.
+for ac_symprfx in "" "_"; do
+
+  # Transform symcode, sympat, and symprfx into a raw symbol and a C symbol.
+  symxfrm="\\1 $ac_symprfx\\2 \\2"
+
+  # Write the raw and C identifiers.
+  if test "$lt_cv_nm_interface" = "MS dumpbin"; then
+    # Fake it for dumpbin and say T for any non-static function
+    # and D for any global variable.
+    # Also find C++ and __fastcall symbols from MSVC++,
+    # which start with @ or ?.
+    lt_cv_sys_global_symbol_pipe="$AWK '"\
+"     {last_section=section; section=\$ 3};"\
+"     /^COFF SYMBOL TABLE/{for(i in hide) delete hide[i]};"\
+"     /Section length .*#relocs.*(pick any)/{hide[last_section]=1};"\
+"     \$ 0!~/External *\|/{next};"\
+"     / 0+ UNDEF /{next}; / UNDEF \([^|]\)*()/{next};"\
+"     {if(hide[section]) next};"\
+"     {f=0}; \$ 0~/\(\).*\|/{f=1}; {printf f ? \"T \" : \"D \"};"\
+"     {split(\$ 0, a, /\||\r/); split(a[2], s)};"\
+"     s[1]~/^[@?]/{print s[1], s[1]; next};"\
+"     s[1]~prfx {split(s[1],t,\"@\"); print t[1], substr(t[1],length(prfx))}"\
+"     ' prfx=^$ac_symprfx"
+  else
+    lt_cv_sys_global_symbol_pipe="sed -n -e 's/^.*[     ]\($symcode$symcode*\)[         ][      ]*$ac_symprfx$sympat$opt_cr$/$symxfrm/p'"
+  fi
+  lt_cv_sys_global_symbol_pipe="$lt_cv_sys_global_symbol_pipe | sed '/ __gnu_lto/d'"
+
+  # Check to see that the pipe works correctly.
+  pipe_works=no
+
+  rm -f conftest*
+  cat > conftest.$ac_ext <<_LT_EOF
+#ifdef __cplusplus
+extern "C" {
+#endif
+char nm_test_var;
+void nm_test_func(void);
+void nm_test_func(void){}
+#ifdef __cplusplus
+}
+#endif
+int main(){nm_test_var='a';nm_test_func();return(0);}
+_LT_EOF
+
+  if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+    # Now try to grab the symbols.
+    nlist=conftest.nm
+    if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$NM conftest.$ac_objext \| "$lt_cv_sys_global_symbol_pipe" \> $nlist\""; } >&5
+  (eval $NM conftest.$ac_objext \| "$lt_cv_sys_global_symbol_pipe" \> $nlist) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; } && test -s "$nlist"; then
+      # Try sorting and uniquifying the output.
+      if sort "$nlist" | uniq > "$nlist"T; then
+       mv -f "$nlist"T "$nlist"
+      else
+       rm -f "$nlist"T
+      fi
+
+      # Make sure that we snagged all the symbols we need.
+      if $GREP ' nm_test_var$' "$nlist" >/dev/null; then
+       if $GREP ' nm_test_func$' "$nlist" >/dev/null; then
+         cat <<_LT_EOF > conftest.$ac_ext
+/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests.  */
+#if defined(_WIN32) || defined(__CYGWIN__) || defined(_WIN32_WCE)
+/* DATA imports from DLLs on WIN32 con't be const, because runtime
+   relocations are performed -- see ld's documentation on pseudo-relocs.  */
+# define LT_DLSYM_CONST
+#elif defined(__osf__)
+/* This system does not cope well with relocations in const data.  */
+# define LT_DLSYM_CONST
+#else
+# define LT_DLSYM_CONST const
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+_LT_EOF
+         # Now generate the symbol file.
+         eval "$lt_cv_sys_global_symbol_to_cdecl"' < "$nlist" | $GREP -v main >> conftest.$ac_ext'
+
+         cat <<_LT_EOF >> conftest.$ac_ext
+
+/* The mapping between symbol names and symbols.  */
+LT_DLSYM_CONST struct {
+  const char *name;
+  void       *address;
+}
+lt__PROGRAM__LTX_preloaded_symbols[] =
+{
+  { "@PROGRAM@", (void *) 0 },
+_LT_EOF
+         $SED "s/^$symcode$symcode* \(.*\) \(.*\)$/  {\"\2\", (void *) \&\2},/" < "$nlist" | $GREP -v main >> conftest.$ac_ext
+         cat <<\_LT_EOF >> conftest.$ac_ext
+  {0, (void *) 0}
+};
+
+/* This works around a problem in FreeBSD linker */
+#ifdef FREEBSD_WORKAROUND
+static const void *lt_preloaded_setup() {
+  return lt__PROGRAM__LTX_preloaded_symbols;
+}
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+_LT_EOF
+         # Now try linking the two files.
+         mv conftest.$ac_objext conftstm.$ac_objext
+         lt_globsym_save_LIBS=$LIBS
+         lt_globsym_save_CFLAGS=$CFLAGS
+         LIBS="conftstm.$ac_objext"
+         CFLAGS="$CFLAGS$lt_prog_compiler_no_builtin_flag"
+         if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_link\""; } >&5
+  (eval $ac_link) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; } && test -s conftest${ac_exeext}; then
+           pipe_works=yes
+         fi
+         LIBS=$lt_globsym_save_LIBS
+         CFLAGS=$lt_globsym_save_CFLAGS
+       else
+         echo "cannot find nm_test_func in $nlist" >&5
+       fi
+      else
+       echo "cannot find nm_test_var in $nlist" >&5
+      fi
+    else
+      echo "cannot run $lt_cv_sys_global_symbol_pipe" >&5
+    fi
+  else
+    echo "$progname: failed program was:" >&5
+    cat conftest.$ac_ext >&5
+  fi
+  rm -rf conftest* conftst*
+
+  # Do not use the global_symbol_pipe unless it works.
+  if test "$pipe_works" = yes; then
+    break
+  else
+    lt_cv_sys_global_symbol_pipe=
+  fi
+done
+
+fi
+
+if test -z "$lt_cv_sys_global_symbol_pipe"; then
+  lt_cv_sys_global_symbol_to_cdecl=
+fi
+if test -z "$lt_cv_sys_global_symbol_pipe$lt_cv_sys_global_symbol_to_cdecl"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: failed" >&5
+$as_echo "failed" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: ok" >&5
+$as_echo "ok" >&6; }
+fi
+
+# Response file support.
+if test "$lt_cv_nm_interface" = "MS dumpbin"; then
+  nm_file_list_spec='@'
+elif $NM --help 2>/dev/null | grep '[@]FILE' >/dev/null; then
+  nm_file_list_spec='@'
+fi
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for sysroot" >&5
+$as_echo_n "checking for sysroot... " >&6; }
+
+# Check whether --with-sysroot was given.
+if test "${with_sysroot+set}" = set; then :
+  withval=$with_sysroot;
+else
+  with_sysroot=no
+fi
+
+
+lt_sysroot=
+case ${with_sysroot} in #(
+ yes)
+   if test "$GCC" = yes; then
+     lt_sysroot=`$CC --print-sysroot 2>/dev/null`
+   fi
+   ;; #(
+ /*)
+   lt_sysroot=`echo "$with_sysroot" | sed -e "$sed_quote_subst"`
+   ;; #(
+ no|'')
+   ;; #(
+ *)
+   { $as_echo "$as_me:${as_lineno-$LINENO}: result: ${with_sysroot}" >&5
+$as_echo "${with_sysroot}" >&6; }
+   as_fn_error $? "The sysroot must be an absolute path." "$LINENO" 5
+   ;;
+esac
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: ${lt_sysroot:-no}" >&5
+$as_echo "${lt_sysroot:-no}" >&6; }
+
+
+
+
+
+# Check whether --enable-libtool-lock was given.
+if test "${enable_libtool_lock+set}" = set; then :
+  enableval=$enable_libtool_lock;
+fi
+
+test "x$enable_libtool_lock" != xno && enable_libtool_lock=yes
+
+# Some flags need to be propagated to the compiler or linker for good
+# libtool support.
+case $host in
+ia64-*-hpux*)
+  # Find out which ABI we are using.
+  echo 'int i;' > conftest.$ac_ext
+  if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+    case `/usr/bin/file conftest.$ac_objext` in
+      *ELF-32*)
+       HPUX_IA64_MODE="32"
+       ;;
+      *ELF-64*)
+       HPUX_IA64_MODE="64"
+       ;;
+    esac
+  fi
+  rm -rf conftest*
+  ;;
+*-*-irix6*)
+  # Find out which ABI we are using.
+  echo '#line '$LINENO' "configure"' > conftest.$ac_ext
+  if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+    if test "$lt_cv_prog_gnu_ld" = yes; then
+      case `/usr/bin/file conftest.$ac_objext` in
+       *32-bit*)
+         LD="${LD-ld} -melf32bsmip"
+         ;;
+       *N32*)
+         LD="${LD-ld} -melf32bmipn32"
+         ;;
+       *64-bit*)
+         LD="${LD-ld} -melf64bmip"
+       ;;
+      esac
+    else
+      case `/usr/bin/file conftest.$ac_objext` in
+       *32-bit*)
+         LD="${LD-ld} -32"
+         ;;
+       *N32*)
+         LD="${LD-ld} -n32"
+         ;;
+       *64-bit*)
+         LD="${LD-ld} -64"
+         ;;
+      esac
+    fi
+  fi
+  rm -rf conftest*
+  ;;
+
+x86_64-*kfreebsd*-gnu|x86_64-*linux*|ppc*-*linux*|powerpc*-*linux*| \
+s390*-*linux*|s390*-*tpf*|sparc*-*linux*)
+  # Find out which ABI we are using.
+  echo 'int i;' > conftest.$ac_ext
+  if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+    case `/usr/bin/file conftest.o` in
+      *32-bit*)
+       case $host in
+         x86_64-*kfreebsd*-gnu)
+           LD="${LD-ld} -m elf_i386_fbsd"
+           ;;
+         x86_64-*linux*)
+           LD="${LD-ld} -m elf_i386"
+           ;;
+         ppc64-*linux*|powerpc64-*linux*)
+           LD="${LD-ld} -m elf32ppclinux"
+           ;;
+         s390x-*linux*)
+           LD="${LD-ld} -m elf_s390"
+           ;;
+         sparc64-*linux*)
+           LD="${LD-ld} -m elf32_sparc"
+           ;;
+       esac
+       ;;
+      *64-bit*)
+       case $host in
+         x86_64-*kfreebsd*-gnu)
+           LD="${LD-ld} -m elf_x86_64_fbsd"
+           ;;
+         x86_64-*linux*)
+           LD="${LD-ld} -m elf_x86_64"
+           ;;
+         ppc*-*linux*|powerpc*-*linux*)
+           LD="${LD-ld} -m elf64ppc"
+           ;;
+         s390*-*linux*|s390*-*tpf*)
+           LD="${LD-ld} -m elf64_s390"
+           ;;
+         sparc*-*linux*)
+           LD="${LD-ld} -m elf64_sparc"
+           ;;
+       esac
+       ;;
+    esac
+  fi
+  rm -rf conftest*
+  ;;
+
+*-*-sco3.2v5*)
+  # On SCO OpenServer 5, we need -belf to get full-featured binaries.
+  SAVE_CFLAGS="$CFLAGS"
+  CFLAGS="$CFLAGS -belf"
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler needs -belf" >&5
+$as_echo_n "checking whether the C compiler needs -belf... " >&6; }
+if ${lt_cv_cc_needs_belf+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+     cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  lt_cv_cc_needs_belf=yes
+else
+  lt_cv_cc_needs_belf=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+     ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_cc_needs_belf" >&5
+$as_echo "$lt_cv_cc_needs_belf" >&6; }
+  if test x"$lt_cv_cc_needs_belf" != x"yes"; then
+    # this is probably gcc 2.8.0, egcs 1.0 or newer; no need for -belf
+    CFLAGS="$SAVE_CFLAGS"
+  fi
+  ;;
+*-*solaris*)
+  # Find out which ABI we are using.
+  echo 'int i;' > conftest.$ac_ext
+  if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+    case `/usr/bin/file conftest.o` in
+    *64-bit*)
+      case $lt_cv_prog_gnu_ld in
+      yes*)
+        case $host in
+        i?86-*-solaris*)
+          LD="${LD-ld} -m elf_x86_64"
+          ;;
+        sparc*-*-solaris*)
+          LD="${LD-ld} -m elf64_sparc"
+          ;;
+        esac
+        # GNU ld 2.21 introduced _sol2 emulations.  Use them if available.
+        if ${LD-ld} -V | grep _sol2 >/dev/null 2>&1; then
+          LD="${LD-ld}_sol2"
+        fi
+        ;;
+      *)
+       if ${LD-ld} -64 -r -o conftest2.o conftest.o >/dev/null 2>&1; then
+         LD="${LD-ld} -64"
+       fi
+       ;;
+      esac
+      ;;
+    esac
+  fi
+  rm -rf conftest*
+  ;;
+esac
+
+need_locks="$enable_libtool_lock"
+
+if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}mt", so it can be a program name with args.
+set dummy ${ac_tool_prefix}mt; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_MANIFEST_TOOL+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$MANIFEST_TOOL"; then
+  ac_cv_prog_MANIFEST_TOOL="$MANIFEST_TOOL" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_MANIFEST_TOOL="${ac_tool_prefix}mt"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+MANIFEST_TOOL=$ac_cv_prog_MANIFEST_TOOL
+if test -n "$MANIFEST_TOOL"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MANIFEST_TOOL" >&5
+$as_echo "$MANIFEST_TOOL" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_MANIFEST_TOOL"; then
+  ac_ct_MANIFEST_TOOL=$MANIFEST_TOOL
+  # Extract the first word of "mt", so it can be a program name with args.
+set dummy mt; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_ac_ct_MANIFEST_TOOL+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_MANIFEST_TOOL"; then
+  ac_cv_prog_ac_ct_MANIFEST_TOOL="$ac_ct_MANIFEST_TOOL" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_MANIFEST_TOOL="mt"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_MANIFEST_TOOL=$ac_cv_prog_ac_ct_MANIFEST_TOOL
+if test -n "$ac_ct_MANIFEST_TOOL"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_MANIFEST_TOOL" >&5
+$as_echo "$ac_ct_MANIFEST_TOOL" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_MANIFEST_TOOL" = x; then
+    MANIFEST_TOOL=":"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    MANIFEST_TOOL=$ac_ct_MANIFEST_TOOL
+  fi
+else
+  MANIFEST_TOOL="$ac_cv_prog_MANIFEST_TOOL"
+fi
+
+test -z "$MANIFEST_TOOL" && MANIFEST_TOOL=mt
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if $MANIFEST_TOOL is a manifest tool" >&5
+$as_echo_n "checking if $MANIFEST_TOOL is a manifest tool... " >&6; }
+if ${lt_cv_path_mainfest_tool+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_path_mainfest_tool=no
+  echo "$as_me:$LINENO: $MANIFEST_TOOL '-?'" >&5
+  $MANIFEST_TOOL '-?' 2>conftest.err > conftest.out
+  cat conftest.err >&5
+  if $GREP 'Manifest Tool' conftest.out > /dev/null; then
+    lt_cv_path_mainfest_tool=yes
+  fi
+  rm -f conftest*
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_path_mainfest_tool" >&5
+$as_echo "$lt_cv_path_mainfest_tool" >&6; }
+if test "x$lt_cv_path_mainfest_tool" != xyes; then
+  MANIFEST_TOOL=:
+fi
+
+
+
+
+
+
+  case $host_os in
+    rhapsody* | darwin*)
+    if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}dsymutil", so it can be a program name with args.
+set dummy ${ac_tool_prefix}dsymutil; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_DSYMUTIL+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$DSYMUTIL"; then
+  ac_cv_prog_DSYMUTIL="$DSYMUTIL" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_DSYMUTIL="${ac_tool_prefix}dsymutil"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+DSYMUTIL=$ac_cv_prog_DSYMUTIL
+if test -n "$DSYMUTIL"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DSYMUTIL" >&5
+$as_echo "$DSYMUTIL" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_DSYMUTIL"; then
+  ac_ct_DSYMUTIL=$DSYMUTIL
+  # Extract the first word of "dsymutil", so it can be a program name with args.
+set dummy dsymutil; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_ac_ct_DSYMUTIL+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_DSYMUTIL"; then
+  ac_cv_prog_ac_ct_DSYMUTIL="$ac_ct_DSYMUTIL" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_DSYMUTIL="dsymutil"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_DSYMUTIL=$ac_cv_prog_ac_ct_DSYMUTIL
+if test -n "$ac_ct_DSYMUTIL"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DSYMUTIL" >&5
+$as_echo "$ac_ct_DSYMUTIL" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_DSYMUTIL" = x; then
+    DSYMUTIL=":"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    DSYMUTIL=$ac_ct_DSYMUTIL
+  fi
+else
+  DSYMUTIL="$ac_cv_prog_DSYMUTIL"
+fi
+
+    if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}nmedit", so it can be a program name with args.
+set dummy ${ac_tool_prefix}nmedit; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_NMEDIT+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$NMEDIT"; then
+  ac_cv_prog_NMEDIT="$NMEDIT" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_NMEDIT="${ac_tool_prefix}nmedit"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+NMEDIT=$ac_cv_prog_NMEDIT
+if test -n "$NMEDIT"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $NMEDIT" >&5
+$as_echo "$NMEDIT" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_NMEDIT"; then
+  ac_ct_NMEDIT=$NMEDIT
+  # Extract the first word of "nmedit", so it can be a program name with args.
+set dummy nmedit; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_ac_ct_NMEDIT+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_NMEDIT"; then
+  ac_cv_prog_ac_ct_NMEDIT="$ac_ct_NMEDIT" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_NMEDIT="nmedit"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_NMEDIT=$ac_cv_prog_ac_ct_NMEDIT
+if test -n "$ac_ct_NMEDIT"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_NMEDIT" >&5
+$as_echo "$ac_ct_NMEDIT" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_NMEDIT" = x; then
+    NMEDIT=":"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    NMEDIT=$ac_ct_NMEDIT
+  fi
+else
+  NMEDIT="$ac_cv_prog_NMEDIT"
+fi
+
+    if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}lipo", so it can be a program name with args.
+set dummy ${ac_tool_prefix}lipo; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_LIPO+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$LIPO"; then
+  ac_cv_prog_LIPO="$LIPO" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_LIPO="${ac_tool_prefix}lipo"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+LIPO=$ac_cv_prog_LIPO
+if test -n "$LIPO"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LIPO" >&5
+$as_echo "$LIPO" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_LIPO"; then
+  ac_ct_LIPO=$LIPO
+  # Extract the first word of "lipo", so it can be a program name with args.
+set dummy lipo; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_ac_ct_LIPO+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_LIPO"; then
+  ac_cv_prog_ac_ct_LIPO="$ac_ct_LIPO" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_LIPO="lipo"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_LIPO=$ac_cv_prog_ac_ct_LIPO
+if test -n "$ac_ct_LIPO"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_LIPO" >&5
+$as_echo "$ac_ct_LIPO" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_LIPO" = x; then
+    LIPO=":"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    LIPO=$ac_ct_LIPO
+  fi
+else
+  LIPO="$ac_cv_prog_LIPO"
+fi
+
+    if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}otool", so it can be a program name with args.
+set dummy ${ac_tool_prefix}otool; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_OTOOL+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$OTOOL"; then
+  ac_cv_prog_OTOOL="$OTOOL" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_OTOOL="${ac_tool_prefix}otool"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+OTOOL=$ac_cv_prog_OTOOL
+if test -n "$OTOOL"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OTOOL" >&5
+$as_echo "$OTOOL" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_OTOOL"; then
+  ac_ct_OTOOL=$OTOOL
+  # Extract the first word of "otool", so it can be a program name with args.
+set dummy otool; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_ac_ct_OTOOL+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_OTOOL"; then
+  ac_cv_prog_ac_ct_OTOOL="$ac_ct_OTOOL" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_OTOOL="otool"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_OTOOL=$ac_cv_prog_ac_ct_OTOOL
+if test -n "$ac_ct_OTOOL"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OTOOL" >&5
+$as_echo "$ac_ct_OTOOL" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_OTOOL" = x; then
+    OTOOL=":"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    OTOOL=$ac_ct_OTOOL
+  fi
+else
+  OTOOL="$ac_cv_prog_OTOOL"
+fi
+
+    if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}otool64", so it can be a program name with args.
+set dummy ${ac_tool_prefix}otool64; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_OTOOL64+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$OTOOL64"; then
+  ac_cv_prog_OTOOL64="$OTOOL64" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_OTOOL64="${ac_tool_prefix}otool64"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+OTOOL64=$ac_cv_prog_OTOOL64
+if test -n "$OTOOL64"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OTOOL64" >&5
+$as_echo "$OTOOL64" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_OTOOL64"; then
+  ac_ct_OTOOL64=$OTOOL64
+  # Extract the first word of "otool64", so it can be a program name with args.
+set dummy otool64; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_ac_ct_OTOOL64+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_OTOOL64"; then
+  ac_cv_prog_ac_ct_OTOOL64="$ac_ct_OTOOL64" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_OTOOL64="otool64"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_OTOOL64=$ac_cv_prog_ac_ct_OTOOL64
+if test -n "$ac_ct_OTOOL64"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OTOOL64" >&5
+$as_echo "$ac_ct_OTOOL64" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_OTOOL64" = x; then
+    OTOOL64=":"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    OTOOL64=$ac_ct_OTOOL64
+  fi
+else
+  OTOOL64="$ac_cv_prog_OTOOL64"
+fi
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -single_module linker flag" >&5
+$as_echo_n "checking for -single_module linker flag... " >&6; }
+if ${lt_cv_apple_cc_single_mod+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_apple_cc_single_mod=no
+      if test -z "${LT_MULTI_MODULE}"; then
+       # By default we will add the -single_module flag. You can override
+       # by either setting the environment variable LT_MULTI_MODULE
+       # non-empty at configure time, or by adding -multi_module to the
+       # link flags.
+       rm -rf libconftest.dylib*
+       echo "int foo(void){return 1;}" > conftest.c
+       echo "$LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \
+-dynamiclib -Wl,-single_module conftest.c" >&5
+       $LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \
+         -dynamiclib -Wl,-single_module conftest.c 2>conftest.err
+        _lt_result=$?
+       # If there is a non-empty error log, and "single_module"
+       # appears in it, assume the flag caused a linker warning
+        if test -s conftest.err && $GREP single_module conftest.err; then
+         cat conftest.err >&5
+       # Otherwise, if the output was created with a 0 exit code from
+       # the compiler, it worked.
+       elif test -f libconftest.dylib && test $_lt_result -eq 0; then
+         lt_cv_apple_cc_single_mod=yes
+       else
+         cat conftest.err >&5
+       fi
+       rm -rf libconftest.dylib*
+       rm -f conftest.*
+      fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_apple_cc_single_mod" >&5
+$as_echo "$lt_cv_apple_cc_single_mod" >&6; }
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -exported_symbols_list linker flag" >&5
+$as_echo_n "checking for -exported_symbols_list linker flag... " >&6; }
+if ${lt_cv_ld_exported_symbols_list+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_ld_exported_symbols_list=no
+      save_LDFLAGS=$LDFLAGS
+      echo "_main" > conftest.sym
+      LDFLAGS="$LDFLAGS -Wl,-exported_symbols_list,conftest.sym"
+      cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  lt_cv_ld_exported_symbols_list=yes
+else
+  lt_cv_ld_exported_symbols_list=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+       LDFLAGS="$save_LDFLAGS"
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_exported_symbols_list" >&5
+$as_echo "$lt_cv_ld_exported_symbols_list" >&6; }
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -force_load linker flag" >&5
+$as_echo_n "checking for -force_load linker flag... " >&6; }
+if ${lt_cv_ld_force_load+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_ld_force_load=no
+      cat > conftest.c << _LT_EOF
+int forced_loaded() { return 2;}
+_LT_EOF
+      echo "$LTCC $LTCFLAGS -c -o conftest.o conftest.c" >&5
+      $LTCC $LTCFLAGS -c -o conftest.o conftest.c 2>&5
+      echo "$AR cru libconftest.a conftest.o" >&5
+      $AR cru libconftest.a conftest.o 2>&5
+      echo "$RANLIB libconftest.a" >&5
+      $RANLIB libconftest.a 2>&5
+      cat > conftest.c << _LT_EOF
+int main() { return 0;}
+_LT_EOF
+      echo "$LTCC $LTCFLAGS $LDFLAGS -o conftest conftest.c -Wl,-force_load,./libconftest.a" >&5
+      $LTCC $LTCFLAGS $LDFLAGS -o conftest conftest.c -Wl,-force_load,./libconftest.a 2>conftest.err
+      _lt_result=$?
+      if test -s conftest.err && $GREP force_load conftest.err; then
+       cat conftest.err >&5
+      elif test -f conftest && test $_lt_result -eq 0 && $GREP forced_load conftest >/dev/null 2>&1 ; then
+       lt_cv_ld_force_load=yes
+      else
+       cat conftest.err >&5
+      fi
+        rm -f conftest.err libconftest.a conftest conftest.c
+        rm -rf conftest.dSYM
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_force_load" >&5
+$as_echo "$lt_cv_ld_force_load" >&6; }
+    case $host_os in
+    rhapsody* | darwin1.[012])
+      _lt_dar_allow_undefined='${wl}-undefined ${wl}suppress' ;;
+    darwin1.*)
+      _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;;
+    darwin*) # darwin 5.x on
+      # if running on 10.5 or later, the deployment target defaults
+      # to the OS version, if on x86, and 10.4, the deployment
+      # target defaults to 10.4. Don't you love it?
+      case ${MACOSX_DEPLOYMENT_TARGET-10.0},$host in
+       10.0,*86*-darwin8*|10.0,*-darwin[91]*)
+         _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;;
+       10.[012]*)
+         _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;;
+       10.*)
+         _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;;
+      esac
+    ;;
+  esac
+    if test "$lt_cv_apple_cc_single_mod" = "yes"; then
+      _lt_dar_single_mod='$single_module'
+    fi
+    if test "$lt_cv_ld_exported_symbols_list" = "yes"; then
+      _lt_dar_export_syms=' ${wl}-exported_symbols_list,$output_objdir/${libname}-symbols.expsym'
+    else
+      _lt_dar_export_syms='~$NMEDIT -s $output_objdir/${libname}-symbols.expsym ${lib}'
+    fi
+    if test "$DSYMUTIL" != ":" && test "$lt_cv_ld_force_load" = "no"; then
+      _lt_dsymutil='~$DSYMUTIL $lib || :'
+    else
+      _lt_dsymutil=
+    fi
+    ;;
+  esac
+
+for ac_header in dlfcn.h
+do :
+  ac_fn_c_check_header_compile "$LINENO" "dlfcn.h" "ac_cv_header_dlfcn_h" "$ac_includes_default
+"
+if test "x$ac_cv_header_dlfcn_h" = xyes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_DLFCN_H 1
+_ACEOF
+
+fi
+
+done
+
+
+
+
+
+# Set options
+
+
+
+        enable_dlopen=no
+
+
+  enable_win32_dll=no
+
+
+            # Check whether --enable-shared was given.
+if test "${enable_shared+set}" = set; then :
+  enableval=$enable_shared; p=${PACKAGE-default}
+    case $enableval in
+    yes) enable_shared=yes ;;
+    no) enable_shared=no ;;
+    *)
+      enable_shared=no
+      # Look at the argument we got.  We use all the common list separators.
+      lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
+      for pkg in $enableval; do
+       IFS="$lt_save_ifs"
+       if test "X$pkg" = "X$p"; then
+         enable_shared=yes
+       fi
+      done
+      IFS="$lt_save_ifs"
+      ;;
+    esac
+else
+  enable_shared=yes
+fi
+
+
+
+
+
+
+
+
+
+
+
+# Check whether --with-pic was given.
+if test "${with_pic+set}" = set; then :
+  withval=$with_pic; lt_p=${PACKAGE-default}
+    case $withval in
+    yes|no) pic_mode=$withval ;;
+    *)
+      pic_mode=default
+      # Look at the argument we got.  We use all the common list separators.
+      lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
+      for lt_pkg in $withval; do
+       IFS="$lt_save_ifs"
+       if test "X$lt_pkg" = "X$lt_p"; then
+         pic_mode=yes
+       fi
+      done
+      IFS="$lt_save_ifs"
+      ;;
+    esac
+else
+  pic_mode=default
+fi
+
+
+test -z "$pic_mode" && pic_mode=default
+
+
+
+
+
+
+
+  # Check whether --enable-fast-install was given.
+if test "${enable_fast_install+set}" = set; then :
+  enableval=$enable_fast_install; p=${PACKAGE-default}
+    case $enableval in
+    yes) enable_fast_install=yes ;;
+    no) enable_fast_install=no ;;
+    *)
+      enable_fast_install=no
+      # Look at the argument we got.  We use all the common list separators.
+      lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
+      for pkg in $enableval; do
+       IFS="$lt_save_ifs"
+       if test "X$pkg" = "X$p"; then
+         enable_fast_install=yes
+       fi
+      done
+      IFS="$lt_save_ifs"
+      ;;
+    esac
+else
+  enable_fast_install=yes
+fi
+
+
+
+
+
+
+
+
+
+
+
+# This can be used to rebuild libtool when needed
+LIBTOOL_DEPS="$ltmain"
+
+# Always use our own libtool.
+LIBTOOL='$(SHELL) $(top_builddir)/libtool'
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+test -z "$LN_S" && LN_S="ln -s"
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+if test -n "${ZSH_VERSION+set}" ; then
+   setopt NO_GLOB_SUBST
+fi
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for objdir" >&5
+$as_echo_n "checking for objdir... " >&6; }
+if ${lt_cv_objdir+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  rm -f .libs 2>/dev/null
+mkdir .libs 2>/dev/null
+if test -d .libs; then
+  lt_cv_objdir=.libs
+else
+  # MS-DOS does not allow filenames that begin with a dot.
+  lt_cv_objdir=_libs
+fi
+rmdir .libs 2>/dev/null
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_objdir" >&5
+$as_echo "$lt_cv_objdir" >&6; }
+objdir=$lt_cv_objdir
+
+
+
+
+
+cat >>confdefs.h <<_ACEOF
+#define LT_OBJDIR "$lt_cv_objdir/"
+_ACEOF
+
+
+
+
+case $host_os in
+aix3*)
+  # AIX sometimes has problems with the GCC collect2 program.  For some
+  # reason, if we set the COLLECT_NAMES environment variable, the problems
+  # vanish in a puff of smoke.
+  if test "X${COLLECT_NAMES+set}" != Xset; then
+    COLLECT_NAMES=
+    export COLLECT_NAMES
+  fi
+  ;;
+esac
+
+# Global variables:
+ofile=libtool
+can_build_shared=yes
+
+# All known linkers require a `.a' archive for static linking (except MSVC,
+# which needs '.lib').
+libext=a
+
+with_gnu_ld="$lt_cv_prog_gnu_ld"
+
+old_CC="$CC"
+old_CFLAGS="$CFLAGS"
+
+# Set sane defaults for various variables
+test -z "$CC" && CC=cc
+test -z "$LTCC" && LTCC=$CC
+test -z "$LTCFLAGS" && LTCFLAGS=$CFLAGS
+test -z "$LD" && LD=ld
+test -z "$ac_objext" && ac_objext=o
+
+for cc_temp in $compiler""; do
+  case $cc_temp in
+    compile | *[\\/]compile | ccache | *[\\/]ccache ) ;;
+    distcc | *[\\/]distcc | purify | *[\\/]purify ) ;;
+    \-*) ;;
+    *) break;;
+  esac
+done
+cc_basename=`$ECHO "$cc_temp" | $SED "s%.*/%%; s%^$host_alias-%%"`
+
+
+# Only perform the check for file, if the check method requires it
+test -z "$MAGIC_CMD" && MAGIC_CMD=file
+case $deplibs_check_method in
+file_magic*)
+  if test "$file_magic_cmd" = '$MAGIC_CMD'; then
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ${ac_tool_prefix}file" >&5
+$as_echo_n "checking for ${ac_tool_prefix}file... " >&6; }
+if ${lt_cv_path_MAGIC_CMD+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $MAGIC_CMD in
+[\\/*] |  ?:[\\/]*)
+  lt_cv_path_MAGIC_CMD="$MAGIC_CMD" # Let the user override the test with a path.
+  ;;
+*)
+  lt_save_MAGIC_CMD="$MAGIC_CMD"
+  lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
+  ac_dummy="/usr/bin$PATH_SEPARATOR$PATH"
+  for ac_dir in $ac_dummy; do
+    IFS="$lt_save_ifs"
+    test -z "$ac_dir" && ac_dir=.
+    if test -f $ac_dir/${ac_tool_prefix}file; then
+      lt_cv_path_MAGIC_CMD="$ac_dir/${ac_tool_prefix}file"
+      if test -n "$file_magic_test_file"; then
+       case $deplibs_check_method in
+       "file_magic "*)
+         file_magic_regex=`expr "$deplibs_check_method" : "file_magic \(.*\)"`
+         MAGIC_CMD="$lt_cv_path_MAGIC_CMD"
+         if eval $file_magic_cmd \$file_magic_test_file 2> /dev/null |
+           $EGREP "$file_magic_regex" > /dev/null; then
+           :
+         else
+           cat <<_LT_EOF 1>&2
+
+*** Warning: the command libtool uses to detect shared libraries,
+*** $file_magic_cmd, produces output that libtool cannot recognize.
+*** The result is that libtool may fail to recognize shared libraries
+*** as such.  This will affect the creation of libtool libraries that
+*** depend on shared libraries, but programs linked with such libtool
+*** libraries will work regardless of this problem.  Nevertheless, you
+*** may want to report the problem to your system manager and/or to
+*** bug-libtool@gnu.org
+
+_LT_EOF
+         fi ;;
+       esac
+      fi
+      break
+    fi
+  done
+  IFS="$lt_save_ifs"
+  MAGIC_CMD="$lt_save_MAGIC_CMD"
+  ;;
+esac
+fi
+
+MAGIC_CMD="$lt_cv_path_MAGIC_CMD"
+if test -n "$MAGIC_CMD"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MAGIC_CMD" >&5
+$as_echo "$MAGIC_CMD" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+
+
+
+if test -z "$lt_cv_path_MAGIC_CMD"; then
+  if test -n "$ac_tool_prefix"; then
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for file" >&5
+$as_echo_n "checking for file... " >&6; }
+if ${lt_cv_path_MAGIC_CMD+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $MAGIC_CMD in
+[\\/*] |  ?:[\\/]*)
+  lt_cv_path_MAGIC_CMD="$MAGIC_CMD" # Let the user override the test with a path.
+  ;;
+*)
+  lt_save_MAGIC_CMD="$MAGIC_CMD"
+  lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
+  ac_dummy="/usr/bin$PATH_SEPARATOR$PATH"
+  for ac_dir in $ac_dummy; do
+    IFS="$lt_save_ifs"
+    test -z "$ac_dir" && ac_dir=.
+    if test -f $ac_dir/file; then
+      lt_cv_path_MAGIC_CMD="$ac_dir/file"
+      if test -n "$file_magic_test_file"; then
+       case $deplibs_check_method in
+       "file_magic "*)
+         file_magic_regex=`expr "$deplibs_check_method" : "file_magic \(.*\)"`
+         MAGIC_CMD="$lt_cv_path_MAGIC_CMD"
+         if eval $file_magic_cmd \$file_magic_test_file 2> /dev/null |
+           $EGREP "$file_magic_regex" > /dev/null; then
+           :
+         else
+           cat <<_LT_EOF 1>&2
+
+*** Warning: the command libtool uses to detect shared libraries,
+*** $file_magic_cmd, produces output that libtool cannot recognize.
+*** The result is that libtool may fail to recognize shared libraries
+*** as such.  This will affect the creation of libtool libraries that
+*** depend on shared libraries, but programs linked with such libtool
+*** libraries will work regardless of this problem.  Nevertheless, you
+*** may want to report the problem to your system manager and/or to
+*** bug-libtool@gnu.org
+
+_LT_EOF
+         fi ;;
+       esac
+      fi
+      break
+    fi
+  done
+  IFS="$lt_save_ifs"
+  MAGIC_CMD="$lt_save_MAGIC_CMD"
+  ;;
+esac
+fi
+
+MAGIC_CMD="$lt_cv_path_MAGIC_CMD"
+if test -n "$MAGIC_CMD"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MAGIC_CMD" >&5
+$as_echo "$MAGIC_CMD" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  else
+    MAGIC_CMD=:
+  fi
+fi
+
+  fi
+  ;;
+esac
+
+# Use C for the default configuration in the libtool script
+
+lt_save_CC="$CC"
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+# Source file extension for C test sources.
+ac_ext=c
+
+# Object file extension for compiled C test sources.
+objext=o
+objext=$objext
+
+# Code to be used in simple compile tests
+lt_simple_compile_test_code="int some_variable = 0;"
+
+# Code to be used in simple link tests
+lt_simple_link_test_code='int main(){return(0);}'
+
+
+
+
+
+
+
+# If no C compiler was specified, use CC.
+LTCC=${LTCC-"$CC"}
+
+# If no C compiler flags were specified, use CFLAGS.
+LTCFLAGS=${LTCFLAGS-"$CFLAGS"}
+
+# Allow CC to be a program name with arguments.
+compiler=$CC
+
+# Save the default compiler, since it gets overwritten when the other
+# tags are being tested, and _LT_TAGVAR(compiler, []) is a NOP.
+compiler_DEFAULT=$CC
+
+# save warnings/boilerplate of simple test code
+ac_outfile=conftest.$ac_objext
+echo "$lt_simple_compile_test_code" >conftest.$ac_ext
+eval "$ac_compile" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err
+_lt_compiler_boilerplate=`cat conftest.err`
+$RM conftest*
+
+ac_outfile=conftest.$ac_objext
+echo "$lt_simple_link_test_code" >conftest.$ac_ext
+eval "$ac_link" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err
+_lt_linker_boilerplate=`cat conftest.err`
+$RM -r conftest*
+
+
+if test -n "$compiler"; then
+
+lt_prog_compiler_no_builtin_flag=
+
+if test "$GCC" = yes; then
+  case $cc_basename in
+  nvcc*)
+    lt_prog_compiler_no_builtin_flag=' -Xcompiler -fno-builtin' ;;
+  *)
+    lt_prog_compiler_no_builtin_flag=' -fno-builtin' ;;
+  esac
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -fno-rtti -fno-exceptions" >&5
+$as_echo_n "checking if $compiler supports -fno-rtti -fno-exceptions... " >&6; }
+if ${lt_cv_prog_compiler_rtti_exceptions+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_prog_compiler_rtti_exceptions=no
+   ac_outfile=conftest.$ac_objext
+   echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+   lt_compiler_flag="-fno-rtti -fno-exceptions"
+   # Insert the option either (1) after the last *FLAGS variable, or
+   # (2) before a word containing "conftest.", or (3) at the end.
+   # Note that $ac_compile itself does not contain backslashes and begins
+   # with a dollar sign (not a hyphen), so the echo should work correctly.
+   # The option is referenced via a variable to avoid confusing sed.
+   lt_compile=`echo "$ac_compile" | $SED \
+   -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
+   -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
+   -e 's:$: $lt_compiler_flag:'`
+   (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&5)
+   (eval "$lt_compile" 2>conftest.err)
+   ac_status=$?
+   cat conftest.err >&5
+   echo "$as_me:$LINENO: \$? = $ac_status" >&5
+   if (exit $ac_status) && test -s "$ac_outfile"; then
+     # The compiler can only warn and ignore the option if not recognized
+     # So say no if there are warnings other than the usual output.
+     $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' >conftest.exp
+     $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
+     if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then
+       lt_cv_prog_compiler_rtti_exceptions=yes
+     fi
+   fi
+   $RM conftest*
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_rtti_exceptions" >&5
+$as_echo "$lt_cv_prog_compiler_rtti_exceptions" >&6; }
+
+if test x"$lt_cv_prog_compiler_rtti_exceptions" = xyes; then
+    lt_prog_compiler_no_builtin_flag="$lt_prog_compiler_no_builtin_flag -fno-rtti -fno-exceptions"
+else
+    :
+fi
+
+fi
+
+
+
+
+
+
+  lt_prog_compiler_wl=
+lt_prog_compiler_pic=
+lt_prog_compiler_static=
+
+
+  if test "$GCC" = yes; then
+    lt_prog_compiler_wl='-Wl,'
+    lt_prog_compiler_static='-static'
+
+    case $host_os in
+      aix*)
+      # All AIX code is PIC.
+      if test "$host_cpu" = ia64; then
+       # AIX 5 now supports IA64 processor
+       lt_prog_compiler_static='-Bstatic'
+      fi
+      ;;
+
+    amigaos*)
+      case $host_cpu in
+      powerpc)
+            # see comment about AmigaOS4 .so support
+            lt_prog_compiler_pic='-fPIC'
+        ;;
+      m68k)
+            # FIXME: we need at least 68020 code to build shared libraries, but
+            # adding the `-m68020' flag to GCC prevents building anything better,
+            # like `-m68040'.
+            lt_prog_compiler_pic='-m68020 -resident32 -malways-restore-a4'
+        ;;
+      esac
+      ;;
+
+    beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*)
+      # PIC is the default for these OSes.
+      ;;
+
+    mingw* | cygwin* | pw32* | os2* | cegcc*)
+      # This hack is so that the source file can tell whether it is being
+      # built for inclusion in a dll (and should export symbols for example).
+      # Although the cygwin gcc ignores -fPIC, still need this for old-style
+      # (--disable-auto-import) libraries
+      lt_prog_compiler_pic='-DDLL_EXPORT'
+      ;;
+
+    darwin* | rhapsody*)
+      # PIC is the default on this platform
+      # Common symbols not allowed in MH_DYLIB files
+      lt_prog_compiler_pic='-fno-common'
+      ;;
+
+    haiku*)
+      # PIC is the default for Haiku.
+      # The "-static" flag exists, but is broken.
+      lt_prog_compiler_static=
+      ;;
+
+    hpux*)
+      # PIC is the default for 64-bit PA HP-UX, but not for 32-bit
+      # PA HP-UX.  On IA64 HP-UX, PIC is the default but the pic flag
+      # sets the default TLS model and affects inlining.
+      case $host_cpu in
+      hppa*64*)
+       # +Z the default
+       ;;
+      *)
+       lt_prog_compiler_pic='-fPIC'
+       ;;
+      esac
+      ;;
+
+    interix[3-9]*)
+      # Interix 3.x gcc -fpic/-fPIC options generate broken code.
+      # Instead, we relocate shared libraries at runtime.
+      ;;
+
+    msdosdjgpp*)
+      # Just because we use GCC doesn't mean we suddenly get shared libraries
+      # on systems that don't support them.
+      lt_prog_compiler_can_build_shared=no
+      enable_shared=no
+      ;;
+
+    *nto* | *qnx*)
+      # QNX uses GNU C++, but need to define -shared option too, otherwise
+      # it will coredump.
+      lt_prog_compiler_pic='-fPIC -shared'
+      ;;
+
+    sysv4*MP*)
+      if test -d /usr/nec; then
+       lt_prog_compiler_pic=-Kconform_pic
+      fi
+      ;;
+
+    *)
+      lt_prog_compiler_pic='-fPIC'
+      ;;
+    esac
+
+    case $cc_basename in
+    nvcc*) # Cuda Compiler Driver 2.2
+      lt_prog_compiler_wl='-Xlinker '
+      if test -n "$lt_prog_compiler_pic"; then
+        lt_prog_compiler_pic="-Xcompiler $lt_prog_compiler_pic"
+      fi
+      ;;
+    esac
+  else
+    # PORTME Check for flag to pass linker flags through the system compiler.
+    case $host_os in
+    aix*)
+      lt_prog_compiler_wl='-Wl,'
+      if test "$host_cpu" = ia64; then
+       # AIX 5 now supports IA64 processor
+       lt_prog_compiler_static='-Bstatic'
+      else
+       lt_prog_compiler_static='-bnso -bI:/lib/syscalls.exp'
+      fi
+      ;;
+
+    mingw* | cygwin* | pw32* | os2* | cegcc*)
+      # This hack is so that the source file can tell whether it is being
+      # built for inclusion in a dll (and should export symbols for example).
+      lt_prog_compiler_pic='-DDLL_EXPORT'
+      ;;
+
+    hpux9* | hpux10* | hpux11*)
+      lt_prog_compiler_wl='-Wl,'
+      # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but
+      # not for PA HP-UX.
+      case $host_cpu in
+      hppa*64*|ia64*)
+       # +Z the default
+       ;;
+      *)
+       lt_prog_compiler_pic='+Z'
+       ;;
+      esac
+      # Is there a better lt_prog_compiler_static that works with the bundled CC?
+      lt_prog_compiler_static='${wl}-a ${wl}archive'
+      ;;
+
+    irix5* | irix6* | nonstopux*)
+      lt_prog_compiler_wl='-Wl,'
+      # PIC (with -KPIC) is the default.
+      lt_prog_compiler_static='-non_shared'
+      ;;
+
+    linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*)
+      case $cc_basename in
+      # old Intel for x86_64 which still supported -KPIC.
+      ecc*)
+       lt_prog_compiler_wl='-Wl,'
+       lt_prog_compiler_pic='-KPIC'
+       lt_prog_compiler_static='-static'
+        ;;
+      # icc used to be incompatible with GCC.
+      # ICC 10 doesn't accept -KPIC any more.
+      icc* | ifort*)
+       lt_prog_compiler_wl='-Wl,'
+       lt_prog_compiler_pic='-fPIC'
+       lt_prog_compiler_static='-static'
+        ;;
+      # Lahey Fortran 8.1.
+      lf95*)
+       lt_prog_compiler_wl='-Wl,'
+       lt_prog_compiler_pic='--shared'
+       lt_prog_compiler_static='--static'
+       ;;
+      nagfor*)
+       # NAG Fortran compiler
+       lt_prog_compiler_wl='-Wl,-Wl,,'
+       lt_prog_compiler_pic='-PIC'
+       lt_prog_compiler_static='-Bstatic'
+       ;;
+      pgcc* | pgf77* | pgf90* | pgf95* | pgfortran*)
+        # Portland Group compilers (*not* the Pentium gcc compiler,
+       # which looks to be a dead project)
+       lt_prog_compiler_wl='-Wl,'
+       lt_prog_compiler_pic='-fpic'
+       lt_prog_compiler_static='-Bstatic'
+        ;;
+      ccc*)
+        lt_prog_compiler_wl='-Wl,'
+        # All Alpha code is PIC.
+        lt_prog_compiler_static='-non_shared'
+        ;;
+      xl* | bgxl* | bgf* | mpixl*)
+       # IBM XL C 8.0/Fortran 10.1, 11.1 on PPC and BlueGene
+       lt_prog_compiler_wl='-Wl,'
+       lt_prog_compiler_pic='-qpic'
+       lt_prog_compiler_static='-qstaticlink'
+       ;;
+      *)
+       case `$CC -V 2>&1 | sed 5q` in
+       *Sun\ Ceres\ Fortran* | *Sun*Fortran*\ [1-7].* | *Sun*Fortran*\ 8.[0-3]*)
+         # Sun Fortran 8.3 passes all unrecognized flags to the linker
+         lt_prog_compiler_pic='-KPIC'
+         lt_prog_compiler_static='-Bstatic'
+         lt_prog_compiler_wl=''
+         ;;
+       *Sun\ F* | *Sun*Fortran*)
+         lt_prog_compiler_pic='-KPIC'
+         lt_prog_compiler_static='-Bstatic'
+         lt_prog_compiler_wl='-Qoption ld '
+         ;;
+       *Sun\ C*)
+         # Sun C 5.9
+         lt_prog_compiler_pic='-KPIC'
+         lt_prog_compiler_static='-Bstatic'
+         lt_prog_compiler_wl='-Wl,'
+         ;;
+        *Intel*\ [CF]*Compiler*)
+         lt_prog_compiler_wl='-Wl,'
+         lt_prog_compiler_pic='-fPIC'
+         lt_prog_compiler_static='-static'
+         ;;
+       *Portland\ Group*)
+         lt_prog_compiler_wl='-Wl,'
+         lt_prog_compiler_pic='-fpic'
+         lt_prog_compiler_static='-Bstatic'
+         ;;
+       esac
+       ;;
+      esac
+      ;;
+
+    newsos6)
+      lt_prog_compiler_pic='-KPIC'
+      lt_prog_compiler_static='-Bstatic'
+      ;;
+
+    *nto* | *qnx*)
+      # QNX uses GNU C++, but need to define -shared option too, otherwise
+      # it will coredump.
+      lt_prog_compiler_pic='-fPIC -shared'
+      ;;
+
+    osf3* | osf4* | osf5*)
+      lt_prog_compiler_wl='-Wl,'
+      # All OSF/1 code is PIC.
+      lt_prog_compiler_static='-non_shared'
+      ;;
+
+    rdos*)
+      lt_prog_compiler_static='-non_shared'
+      ;;
+
+    solaris*)
+      lt_prog_compiler_pic='-KPIC'
+      lt_prog_compiler_static='-Bstatic'
+      case $cc_basename in
+      f77* | f90* | f95* | sunf77* | sunf90* | sunf95*)
+       lt_prog_compiler_wl='-Qoption ld ';;
+      *)
+       lt_prog_compiler_wl='-Wl,';;
+      esac
+      ;;
+
+    sunos4*)
+      lt_prog_compiler_wl='-Qoption ld '
+      lt_prog_compiler_pic='-PIC'
+      lt_prog_compiler_static='-Bstatic'
+      ;;
+
+    sysv4 | sysv4.2uw2* | sysv4.3*)
+      lt_prog_compiler_wl='-Wl,'
+      lt_prog_compiler_pic='-KPIC'
+      lt_prog_compiler_static='-Bstatic'
+      ;;
+
+    sysv4*MP*)
+      if test -d /usr/nec ;then
+       lt_prog_compiler_pic='-Kconform_pic'
+       lt_prog_compiler_static='-Bstatic'
+      fi
+      ;;
+
+    sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*)
+      lt_prog_compiler_wl='-Wl,'
+      lt_prog_compiler_pic='-KPIC'
+      lt_prog_compiler_static='-Bstatic'
+      ;;
+
+    unicos*)
+      lt_prog_compiler_wl='-Wl,'
+      lt_prog_compiler_can_build_shared=no
+      ;;
+
+    uts4*)
+      lt_prog_compiler_pic='-pic'
+      lt_prog_compiler_static='-Bstatic'
+      ;;
+
+    *)
+      lt_prog_compiler_can_build_shared=no
+      ;;
+    esac
+  fi
+
+case $host_os in
+  # For platforms which do not support PIC, -DPIC is meaningless:
+  *djgpp*)
+    lt_prog_compiler_pic=
+    ;;
+  *)
+    lt_prog_compiler_pic="$lt_prog_compiler_pic -DPIC"
+    ;;
+esac
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $compiler option to produce PIC" >&5
+$as_echo_n "checking for $compiler option to produce PIC... " >&6; }
+if ${lt_cv_prog_compiler_pic+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_prog_compiler_pic=$lt_prog_compiler_pic
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_pic" >&5
+$as_echo "$lt_cv_prog_compiler_pic" >&6; }
+lt_prog_compiler_pic=$lt_cv_prog_compiler_pic
+
+#
+# Check to make sure the PIC flag actually works.
+#
+if test -n "$lt_prog_compiler_pic"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler PIC flag $lt_prog_compiler_pic works" >&5
+$as_echo_n "checking if $compiler PIC flag $lt_prog_compiler_pic works... " >&6; }
+if ${lt_cv_prog_compiler_pic_works+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_prog_compiler_pic_works=no
+   ac_outfile=conftest.$ac_objext
+   echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+   lt_compiler_flag="$lt_prog_compiler_pic -DPIC"
+   # Insert the option either (1) after the last *FLAGS variable, or
+   # (2) before a word containing "conftest.", or (3) at the end.
+   # Note that $ac_compile itself does not contain backslashes and begins
+   # with a dollar sign (not a hyphen), so the echo should work correctly.
+   # The option is referenced via a variable to avoid confusing sed.
+   lt_compile=`echo "$ac_compile" | $SED \
+   -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
+   -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
+   -e 's:$: $lt_compiler_flag:'`
+   (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&5)
+   (eval "$lt_compile" 2>conftest.err)
+   ac_status=$?
+   cat conftest.err >&5
+   echo "$as_me:$LINENO: \$? = $ac_status" >&5
+   if (exit $ac_status) && test -s "$ac_outfile"; then
+     # The compiler can only warn and ignore the option if not recognized
+     # So say no if there are warnings other than the usual output.
+     $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' >conftest.exp
+     $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
+     if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then
+       lt_cv_prog_compiler_pic_works=yes
+     fi
+   fi
+   $RM conftest*
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_pic_works" >&5
+$as_echo "$lt_cv_prog_compiler_pic_works" >&6; }
+
+if test x"$lt_cv_prog_compiler_pic_works" = xyes; then
+    case $lt_prog_compiler_pic in
+     "" | " "*) ;;
+     *) lt_prog_compiler_pic=" $lt_prog_compiler_pic" ;;
+     esac
+else
+    lt_prog_compiler_pic=
+     lt_prog_compiler_can_build_shared=no
+fi
+
+fi
+
+
+
+
+
+
+
+
+
+
+
+#
+# Check to make sure the static flag actually works.
+#
+wl=$lt_prog_compiler_wl eval lt_tmp_static_flag=\"$lt_prog_compiler_static\"
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler static flag $lt_tmp_static_flag works" >&5
+$as_echo_n "checking if $compiler static flag $lt_tmp_static_flag works... " >&6; }
+if ${lt_cv_prog_compiler_static_works+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_prog_compiler_static_works=no
+   save_LDFLAGS="$LDFLAGS"
+   LDFLAGS="$LDFLAGS $lt_tmp_static_flag"
+   echo "$lt_simple_link_test_code" > conftest.$ac_ext
+   if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then
+     # The linker can only warn and ignore the option if not recognized
+     # So say no if there are warnings
+     if test -s conftest.err; then
+       # Append any errors to the config.log.
+       cat conftest.err 1>&5
+       $ECHO "$_lt_linker_boilerplate" | $SED '/^$/d' > conftest.exp
+       $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
+       if diff conftest.exp conftest.er2 >/dev/null; then
+         lt_cv_prog_compiler_static_works=yes
+       fi
+     else
+       lt_cv_prog_compiler_static_works=yes
+     fi
+   fi
+   $RM -r conftest*
+   LDFLAGS="$save_LDFLAGS"
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_static_works" >&5
+$as_echo "$lt_cv_prog_compiler_static_works" >&6; }
+
+if test x"$lt_cv_prog_compiler_static_works" = xyes; then
+    :
+else
+    lt_prog_compiler_static=
+fi
+
+
+
+
+
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5
+$as_echo_n "checking if $compiler supports -c -o file.$ac_objext... " >&6; }
+if ${lt_cv_prog_compiler_c_o+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_prog_compiler_c_o=no
+   $RM -r conftest 2>/dev/null
+   mkdir conftest
+   cd conftest
+   mkdir out
+   echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+
+   lt_compiler_flag="-o out/conftest2.$ac_objext"
+   # Insert the option either (1) after the last *FLAGS variable, or
+   # (2) before a word containing "conftest.", or (3) at the end.
+   # Note that $ac_compile itself does not contain backslashes and begins
+   # with a dollar sign (not a hyphen), so the echo should work correctly.
+   lt_compile=`echo "$ac_compile" | $SED \
+   -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
+   -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
+   -e 's:$: $lt_compiler_flag:'`
+   (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&5)
+   (eval "$lt_compile" 2>out/conftest.err)
+   ac_status=$?
+   cat out/conftest.err >&5
+   echo "$as_me:$LINENO: \$? = $ac_status" >&5
+   if (exit $ac_status) && test -s out/conftest2.$ac_objext
+   then
+     # The compiler can only warn and ignore the option if not recognized
+     # So say no if there are warnings
+     $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' > out/conftest.exp
+     $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2
+     if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then
+       lt_cv_prog_compiler_c_o=yes
+     fi
+   fi
+   chmod u+w . 2>&5
+   $RM conftest*
+   # SGI C++ compiler will create directory out/ii_files/ for
+   # template instantiation
+   test -d out/ii_files && $RM out/ii_files/* && rmdir out/ii_files
+   $RM out/* && rmdir out
+   cd ..
+   $RM -r conftest
+   $RM conftest*
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o" >&5
+$as_echo "$lt_cv_prog_compiler_c_o" >&6; }
+
+
+
+
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5
+$as_echo_n "checking if $compiler supports -c -o file.$ac_objext... " >&6; }
+if ${lt_cv_prog_compiler_c_o+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_prog_compiler_c_o=no
+   $RM -r conftest 2>/dev/null
+   mkdir conftest
+   cd conftest
+   mkdir out
+   echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+
+   lt_compiler_flag="-o out/conftest2.$ac_objext"
+   # Insert the option either (1) after the last *FLAGS variable, or
+   # (2) before a word containing "conftest.", or (3) at the end.
+   # Note that $ac_compile itself does not contain backslashes and begins
+   # with a dollar sign (not a hyphen), so the echo should work correctly.
+   lt_compile=`echo "$ac_compile" | $SED \
+   -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
+   -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
+   -e 's:$: $lt_compiler_flag:'`
+   (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&5)
+   (eval "$lt_compile" 2>out/conftest.err)
+   ac_status=$?
+   cat out/conftest.err >&5
+   echo "$as_me:$LINENO: \$? = $ac_status" >&5
+   if (exit $ac_status) && test -s out/conftest2.$ac_objext
+   then
+     # The compiler can only warn and ignore the option if not recognized
+     # So say no if there are warnings
+     $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' > out/conftest.exp
+     $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2
+     if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then
+       lt_cv_prog_compiler_c_o=yes
+     fi
+   fi
+   chmod u+w . 2>&5
+   $RM conftest*
+   # SGI C++ compiler will create directory out/ii_files/ for
+   # template instantiation
+   test -d out/ii_files && $RM out/ii_files/* && rmdir out/ii_files
+   $RM out/* && rmdir out
+   cd ..
+   $RM -r conftest
+   $RM conftest*
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o" >&5
+$as_echo "$lt_cv_prog_compiler_c_o" >&6; }
+
+
+
+
+hard_links="nottested"
+if test "$lt_cv_prog_compiler_c_o" = no && test "$need_locks" != no; then
+  # do not overwrite the value of need_locks provided by the user
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking if we can lock with hard links" >&5
+$as_echo_n "checking if we can lock with hard links... " >&6; }
+  hard_links=yes
+  $RM conftest*
+  ln conftest.a conftest.b 2>/dev/null && hard_links=no
+  touch conftest.a
+  ln conftest.a conftest.b 2>&5 || hard_links=no
+  ln conftest.a conftest.b 2>/dev/null && hard_links=no
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $hard_links" >&5
+$as_echo "$hard_links" >&6; }
+  if test "$hard_links" = no; then
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: \`$CC' does not support \`-c -o', so \`make -j' may be unsafe" >&5
+$as_echo "$as_me: WARNING: \`$CC' does not support \`-c -o', so \`make -j' may be unsafe" >&2;}
+    need_locks=warn
+  fi
+else
+  need_locks=no
+fi
+
+
+
+
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the $compiler linker ($LD) supports shared libraries" >&5
+$as_echo_n "checking whether the $compiler linker ($LD) supports shared libraries... " >&6; }
+
+  runpath_var=
+  allow_undefined_flag=
+  always_export_symbols=no
+  archive_cmds=
+  archive_expsym_cmds=
+  compiler_needs_object=no
+  enable_shared_with_static_runtimes=no
+  export_dynamic_flag_spec=
+  export_symbols_cmds='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols'
+  hardcode_automatic=no
+  hardcode_direct=no
+  hardcode_direct_absolute=no
+  hardcode_libdir_flag_spec=
+  hardcode_libdir_separator=
+  hardcode_minus_L=no
+  hardcode_shlibpath_var=unsupported
+  inherit_rpath=no
+  link_all_deplibs=unknown
+  module_cmds=
+  module_expsym_cmds=
+  old_archive_from_new_cmds=
+  old_archive_from_expsyms_cmds=
+  thread_safe_flag_spec=
+  whole_archive_flag_spec=
+  # include_expsyms should be a list of space-separated symbols to be *always*
+  # included in the symbol list
+  include_expsyms=
+  # exclude_expsyms can be an extended regexp of symbols to exclude
+  # it will be wrapped by ` (' and `)$', so one must not match beginning or
+  # end of line.  Example: `a|bc|.*d.*' will exclude the symbols `a' and `bc',
+  # as well as any symbol that contains `d'.
+  exclude_expsyms='_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*'
+  # Although _GLOBAL_OFFSET_TABLE_ is a valid symbol C name, most a.out
+  # platforms (ab)use it in PIC code, but their linkers get confused if
+  # the symbol is explicitly referenced.  Since portable code cannot
+  # rely on this symbol name, it's probably fine to never include it in
+  # preloaded symbol tables.
+  # Exclude shared library initialization/finalization symbols.
+  extract_expsyms_cmds=
+
+  case $host_os in
+  cygwin* | mingw* | pw32* | cegcc*)
+    # FIXME: the MSVC++ port hasn't been tested in a loooong time
+    # When not using gcc, we currently assume that we are using
+    # Microsoft Visual C++.
+    if test "$GCC" != yes; then
+      with_gnu_ld=no
+    fi
+    ;;
+  interix*)
+    # we just hope/assume this is gcc and not c89 (= MSVC++)
+    with_gnu_ld=yes
+    ;;
+  openbsd*)
+    with_gnu_ld=no
+    ;;
+  linux* | k*bsd*-gnu | gnu*)
+    link_all_deplibs=no
+    ;;
+  esac
+
+  ld_shlibs=yes
+
+  # On some targets, GNU ld is compatible enough with the native linker
+  # that we're better off using the native interface for both.
+  lt_use_gnu_ld_interface=no
+  if test "$with_gnu_ld" = yes; then
+    case $host_os in
+      aix*)
+       # The AIX port of GNU ld has always aspired to compatibility
+       # with the native linker.  However, as the warning in the GNU ld
+       # block says, versions before 2.19.5* couldn't really create working
+       # shared libraries, regardless of the interface used.
+       case `$LD -v 2>&1` in
+         *\ \(GNU\ Binutils\)\ 2.19.5*) ;;
+         *\ \(GNU\ Binutils\)\ 2.[2-9]*) ;;
+         *\ \(GNU\ Binutils\)\ [3-9]*) ;;
+         *)
+           lt_use_gnu_ld_interface=yes
+           ;;
+       esac
+       ;;
+      *)
+       lt_use_gnu_ld_interface=yes
+       ;;
+    esac
+  fi
+
+  if test "$lt_use_gnu_ld_interface" = yes; then
+    # If archive_cmds runs LD, not CC, wlarc should be empty
+    wlarc='${wl}'
+
+    # Set some defaults for GNU ld with shared library support. These
+    # are reset later if shared libraries are not supported. Putting them
+    # here allows them to be overridden if necessary.
+    runpath_var=LD_RUN_PATH
+    hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
+    export_dynamic_flag_spec='${wl}--export-dynamic'
+    # ancient GNU ld didn't support --whole-archive et. al.
+    if $LD --help 2>&1 | $GREP 'no-whole-archive' > /dev/null; then
+      whole_archive_flag_spec="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive'
+    else
+      whole_archive_flag_spec=
+    fi
+    supports_anon_versioning=no
+    case `$LD -v 2>&1` in
+      *GNU\ gold*) supports_anon_versioning=yes ;;
+      *\ [01].* | *\ 2.[0-9].* | *\ 2.10.*) ;; # catch versions < 2.11
+      *\ 2.11.93.0.2\ *) supports_anon_versioning=yes ;; # RH7.3 ...
+      *\ 2.11.92.0.12\ *) supports_anon_versioning=yes ;; # Mandrake 8.2 ...
+      *\ 2.11.*) ;; # other 2.11 versions
+      *) supports_anon_versioning=yes ;;
+    esac
+
+    # See if GNU ld supports shared libraries.
+    case $host_os in
+    aix[3-9]*)
+      # On AIX/PPC, the GNU linker is very broken
+      if test "$host_cpu" != ia64; then
+       ld_shlibs=no
+       cat <<_LT_EOF 1>&2
+
+*** Warning: the GNU linker, at least up to release 2.19, is reported
+*** to be unable to reliably create shared libraries on AIX.
+*** Therefore, libtool is disabling shared libraries support.  If you
+*** really care for shared libraries, you may want to install binutils
+*** 2.20 or above, or modify your PATH so that a non-GNU linker is found.
+*** You will then need to restart the configuration process.
+
+_LT_EOF
+      fi
+      ;;
+
+    amigaos*)
+      case $host_cpu in
+      powerpc)
+            # see comment about AmigaOS4 .so support
+            archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+            archive_expsym_cmds=''
+        ;;
+      m68k)
+            archive_cmds='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)'
+            hardcode_libdir_flag_spec='-L$libdir'
+            hardcode_minus_L=yes
+        ;;
+      esac
+      ;;
+
+    beos*)
+      if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
+       allow_undefined_flag=unsupported
+       # Joseph Beckenbach <jrb3@best.com> says some releases of gcc
+       # support --undefined.  This deserves some investigation.  FIXME
+       archive_cmds='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+      else
+       ld_shlibs=no
+      fi
+      ;;
+
+    cygwin* | mingw* | pw32* | cegcc*)
+      # _LT_TAGVAR(hardcode_libdir_flag_spec, ) is actually meaningless,
+      # as there is no search path for DLLs.
+      hardcode_libdir_flag_spec='-L$libdir'
+      export_dynamic_flag_spec='${wl}--export-all-symbols'
+      allow_undefined_flag=unsupported
+      always_export_symbols=no
+      enable_shared_with_static_runtimes=yes
+      export_symbols_cmds='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[BCDGRS][ ]/s/.*[ ]\([^ ]*\)/\1 DATA/;s/^.*[ ]__nm__\([^ ]*\)[ ][^ ]*/\1 DATA/;/^I[ ]/d;/^[AITW][ ]/s/.* //'\'' | sort | uniq > $export_symbols'
+      exclude_expsyms='[_]+GLOBAL_OFFSET_TABLE_|[_]+GLOBAL__[FID]_.*|[_]+head_[A-Za-z0-9_]+_dll|[A-Za-z0-9_]+_dll_iname'
+
+      if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then
+        archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib'
+       # If the export-symbols file already is a .def file (1st line
+       # is EXPORTS), use it as is; otherwise, prepend...
+       archive_expsym_cmds='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then
+         cp $export_symbols $output_objdir/$soname.def;
+       else
+         echo EXPORTS > $output_objdir/$soname.def;
+         cat $export_symbols >> $output_objdir/$soname.def;
+       fi~
+       $CC -shared $output_objdir/$soname.def $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib'
+      else
+       ld_shlibs=no
+      fi
+      ;;
+
+    haiku*)
+      archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+      link_all_deplibs=yes
+      ;;
+
+    interix[3-9]*)
+      hardcode_direct=no
+      hardcode_shlibpath_var=no
+      hardcode_libdir_flag_spec='${wl}-rpath,$libdir'
+      export_dynamic_flag_spec='${wl}-E'
+      # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc.
+      # Instead, shared libraries are loaded at an image base (0x10000000 by
+      # default) and relocated if they conflict, which is a slow very memory
+      # consuming and fragmenting process.  To avoid this, we pick a random,
+      # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link
+      # time.  Moving up from 0x10000000 also allows more sbrk(2) space.
+      archive_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
+      archive_expsym_cmds='sed "s,^,_," $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--retain-symbols-file,$output_objdir/$soname.expsym ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
+      ;;
+
+    gnu* | linux* | tpf* | k*bsd*-gnu | kopensolaris*-gnu)
+      tmp_diet=no
+      if test "$host_os" = linux-dietlibc; then
+       case $cc_basename in
+         diet\ *) tmp_diet=yes;;       # linux-dietlibc with static linking (!diet-dyn)
+       esac
+      fi
+      if $LD --help 2>&1 | $EGREP ': supported targets:.* elf' > /dev/null \
+        && test "$tmp_diet" = no
+      then
+       tmp_addflag=' $pic_flag'
+       tmp_sharedflag='-shared'
+       case $cc_basename,$host_cpu in
+        pgcc*)                         # Portland Group C compiler
+         whole_archive_flag_spec='${wl}--whole-archive`for conv in $convenience\"\"; do test  -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` ${wl}--no-whole-archive'
+         tmp_addflag=' $pic_flag'
+         ;;
+       pgf77* | pgf90* | pgf95* | pgfortran*)
+                                       # Portland Group f77 and f90 compilers
+         whole_archive_flag_spec='${wl}--whole-archive`for conv in $convenience\"\"; do test  -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` ${wl}--no-whole-archive'
+         tmp_addflag=' $pic_flag -Mnomain' ;;
+       ecc*,ia64* | icc*,ia64*)        # Intel C compiler on ia64
+         tmp_addflag=' -i_dynamic' ;;
+       efc*,ia64* | ifort*,ia64*)      # Intel Fortran compiler on ia64
+         tmp_addflag=' -i_dynamic -nofor_main' ;;
+       ifc* | ifort*)                  # Intel Fortran compiler
+         tmp_addflag=' -nofor_main' ;;
+       lf95*)                          # Lahey Fortran 8.1
+         whole_archive_flag_spec=
+         tmp_sharedflag='--shared' ;;
+       xl[cC]* | bgxl[cC]* | mpixl[cC]*) # IBM XL C 8.0 on PPC (deal with xlf below)
+         tmp_sharedflag='-qmkshrobj'
+         tmp_addflag= ;;
+       nvcc*)  # Cuda Compiler Driver 2.2
+         whole_archive_flag_spec='${wl}--whole-archive`for conv in $convenience\"\"; do test  -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` ${wl}--no-whole-archive'
+         compiler_needs_object=yes
+         ;;
+       esac
+       case `$CC -V 2>&1 | sed 5q` in
+       *Sun\ C*)                       # Sun C 5.9
+         whole_archive_flag_spec='${wl}--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` ${wl}--no-whole-archive'
+         compiler_needs_object=yes
+         tmp_sharedflag='-G' ;;
+       *Sun\ F*)                       # Sun Fortran 8.3
+         tmp_sharedflag='-G' ;;
+       esac
+       archive_cmds='$CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+
+        if test "x$supports_anon_versioning" = xyes; then
+          archive_expsym_cmds='echo "{ global:" > $output_objdir/$libname.ver~
+           cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~
+           echo "local: *; };" >> $output_objdir/$libname.ver~
+           $CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-version-script ${wl}$output_objdir/$libname.ver -o $lib'
+        fi
+
+       case $cc_basename in
+       xlf* | bgf* | bgxlf* | mpixlf*)
+         # IBM XL Fortran 10.1 on PPC cannot create shared libs itself
+         whole_archive_flag_spec='--whole-archive$convenience --no-whole-archive'
+         hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
+         archive_cmds='$LD -shared $libobjs $deplibs $linker_flags -soname $soname -o $lib'
+         if test "x$supports_anon_versioning" = xyes; then
+           archive_expsym_cmds='echo "{ global:" > $output_objdir/$libname.ver~
+             cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~
+             echo "local: *; };" >> $output_objdir/$libname.ver~
+             $LD -shared $libobjs $deplibs $linker_flags -soname $soname -version-script $output_objdir/$libname.ver -o $lib'
+         fi
+         ;;
+       esac
+      else
+        ld_shlibs=no
+      fi
+      ;;
+
+    netbsd* | netbsdelf*-gnu)
+      if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
+       archive_cmds='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib'
+       wlarc=
+      else
+       archive_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+       archive_expsym_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+      fi
+      ;;
+
+    solaris*)
+      if $LD -v 2>&1 | $GREP 'BFD 2\.8' > /dev/null; then
+       ld_shlibs=no
+       cat <<_LT_EOF 1>&2
+
+*** Warning: The releases 2.8.* of the GNU linker cannot reliably
+*** create shared libraries on Solaris systems.  Therefore, libtool
+*** is disabling shared libraries support.  We urge you to upgrade GNU
+*** binutils to release 2.9.1 or newer.  Another option is to modify
+*** your PATH or compiler configuration so that the native linker is
+*** used, and then restart.
+
+_LT_EOF
+      elif $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
+       archive_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+       archive_expsym_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+      else
+       ld_shlibs=no
+      fi
+      ;;
+
+    sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX*)
+      case `$LD -v 2>&1` in
+        *\ [01].* | *\ 2.[0-9].* | *\ 2.1[0-5].*)
+       ld_shlibs=no
+       cat <<_LT_EOF 1>&2
+
+*** Warning: Releases of the GNU linker prior to 2.16.91.0.3 can not
+*** reliably create shared libraries on SCO systems.  Therefore, libtool
+*** is disabling shared libraries support.  We urge you to upgrade GNU
+*** binutils to release 2.16.91.0.3 or newer.  Another option is to modify
+*** your PATH or compiler configuration so that the native linker is
+*** used, and then restart.
+
+_LT_EOF
+       ;;
+       *)
+         # For security reasons, it is highly recommended that you always
+         # use absolute paths for naming shared libraries, and exclude the
+         # DT_RUNPATH tag from executables and libraries.  But doing so
+         # requires that you compile everything twice, which is a pain.
+         if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
+           hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
+           archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+           archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+         else
+           ld_shlibs=no
+         fi
+       ;;
+      esac
+      ;;
+
+    sunos4*)
+      archive_cmds='$LD -assert pure-text -Bshareable -o $lib $libobjs $deplibs $linker_flags'
+      wlarc=
+      hardcode_direct=yes
+      hardcode_shlibpath_var=no
+      ;;
+
+    *)
+      if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
+       archive_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+       archive_expsym_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
+      else
+       ld_shlibs=no
+      fi
+      ;;
+    esac
+
+    if test "$ld_shlibs" = no; then
+      runpath_var=
+      hardcode_libdir_flag_spec=
+      export_dynamic_flag_spec=
+      whole_archive_flag_spec=
+    fi
+  else
+    # PORTME fill in a description of your system's linker (not GNU ld)
+    case $host_os in
+    aix3*)
+      allow_undefined_flag=unsupported
+      always_export_symbols=yes
+      archive_expsym_cmds='$LD -o $output_objdir/$soname $libobjs $deplibs $linker_flags -bE:$export_symbols -T512 -H512 -bM:SRE~$AR $AR_FLAGS $lib $output_objdir/$soname'
+      # Note: this linker hardcodes the directories in LIBPATH if there
+      # are no directories specified by -L.
+      hardcode_minus_L=yes
+      if test "$GCC" = yes && test -z "$lt_prog_compiler_static"; then
+       # Neither direct hardcoding nor static linking is supported with a
+       # broken collect2.
+       hardcode_direct=unsupported
+      fi
+      ;;
+
+    aix[4-9]*)
+      if test "$host_cpu" = ia64; then
+       # On IA64, the linker does run time linking by default, so we don't
+       # have to do anything special.
+       aix_use_runtimelinking=no
+       exp_sym_flag='-Bexport'
+       no_entry_flag=""
+      else
+       # If we're using GNU nm, then we don't want the "-C" option.
+       # -C means demangle to AIX nm, but means don't demangle with GNU nm
+       # Also, AIX nm treats weak defined symbols like other global
+       # defined symbols, whereas GNU nm marks them as "W".
+       if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then
+         export_symbols_cmds='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W")) && (substr(\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols'
+       else
+         export_symbols_cmds='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && (substr(\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols'
+       fi
+       aix_use_runtimelinking=no
+
+       # Test if we are trying to use run time linking or normal
+       # AIX style linking. If -brtl is somewhere in LDFLAGS, we
+       # need to do runtime linking.
+       case $host_os in aix4.[23]|aix4.[23].*|aix[5-9]*)
+         for ld_flag in $LDFLAGS; do
+         if (test $ld_flag = "-brtl" || test $ld_flag = "-Wl,-brtl"); then
+           aix_use_runtimelinking=yes
+           break
+         fi
+         done
+         ;;
+       esac
+
+       exp_sym_flag='-bexport'
+       no_entry_flag='-bnoentry'
+      fi
+
+      # When large executables or shared objects are built, AIX ld can
+      # have problems creating the table of contents.  If linking a library
+      # or program results in "error TOC overflow" add -mminimal-toc to
+      # CXXFLAGS/CFLAGS for g++/gcc.  In the cases where that is not
+      # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS.
+
+      archive_cmds=''
+      hardcode_direct=yes
+      hardcode_direct_absolute=yes
+      hardcode_libdir_separator=':'
+      link_all_deplibs=yes
+      file_list_spec='${wl}-f,'
+
+      if test "$GCC" = yes; then
+       case $host_os in aix4.[012]|aix4.[012].*)
+       # We only want to do this on AIX 4.2 and lower, the check
+       # below for broken collect2 doesn't work under 4.3+
+         collect2name=`${CC} -print-prog-name=collect2`
+         if test -f "$collect2name" &&
+          strings "$collect2name" | $GREP resolve_lib_name >/dev/null
+         then
+         # We have reworked collect2
+         :
+         else
+         # We have old collect2
+         hardcode_direct=unsupported
+         # It fails to find uninstalled libraries when the uninstalled
+         # path is not listed in the libpath.  Setting hardcode_minus_L
+         # to unsupported forces relinking
+         hardcode_minus_L=yes
+         hardcode_libdir_flag_spec='-L$libdir'
+         hardcode_libdir_separator=
+         fi
+         ;;
+       esac
+       shared_flag='-shared'
+       if test "$aix_use_runtimelinking" = yes; then
+         shared_flag="$shared_flag "'${wl}-G'
+       fi
+       link_all_deplibs=no
+      else
+       # not using gcc
+       if test "$host_cpu" = ia64; then
+       # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release
+       # chokes on -Wl,-G. The following line is correct:
+         shared_flag='-G'
+       else
+         if test "$aix_use_runtimelinking" = yes; then
+           shared_flag='${wl}-G'
+         else
+           shared_flag='${wl}-bM:SRE'
+         fi
+       fi
+      fi
+
+      export_dynamic_flag_spec='${wl}-bexpall'
+      # It seems that -bexpall does not export symbols beginning with
+      # underscore (_), so it is better to generate a list of symbols to export.
+      always_export_symbols=yes
+      if test "$aix_use_runtimelinking" = yes; then
+       # Warning - without using the other runtime loading flags (-brtl),
+       # -berok will link without error, but may produce a broken library.
+       allow_undefined_flag='-berok'
+        # Determine the default libpath from the value encoded in an
+        # empty executable.
+        if test "${lt_cv_aix_libpath+set}" = set; then
+  aix_libpath=$lt_cv_aix_libpath
+else
+  if ${lt_cv_aix_libpath_+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+
+  lt_aix_libpath_sed='
+      /Import File Strings/,/^$/ {
+         /^0/ {
+             s/^0  *\([^ ]*\) *$/\1/
+             p
+         }
+      }'
+  lt_cv_aix_libpath_=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
+  # Check for a 64-bit object if we didn't find anything.
+  if test -z "$lt_cv_aix_libpath_"; then
+    lt_cv_aix_libpath_=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
+  fi
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+  if test -z "$lt_cv_aix_libpath_"; then
+    lt_cv_aix_libpath_="/usr/lib:/lib"
+  fi
+
+fi
+
+  aix_libpath=$lt_cv_aix_libpath_
+fi
+
+        hardcode_libdir_flag_spec='${wl}-blibpath:$libdir:'"$aix_libpath"
+        archive_expsym_cmds='$CC -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags `if test "x${allow_undefined_flag}" != "x"; then func_echo_all "${wl}${allow_undefined_flag}"; else :; fi` '"\${wl}$exp_sym_flag:\$export_symbols $shared_flag"
+      else
+       if test "$host_cpu" = ia64; then
+         hardcode_libdir_flag_spec='${wl}-R $libdir:/usr/lib:/lib'
+         allow_undefined_flag="-z nodefs"
+         archive_expsym_cmds="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$exp_sym_flag:\$export_symbols"
+       else
+        # Determine the default libpath from the value encoded in an
+        # empty executable.
+        if test "${lt_cv_aix_libpath+set}" = set; then
+  aix_libpath=$lt_cv_aix_libpath
+else
+  if ${lt_cv_aix_libpath_+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+
+  lt_aix_libpath_sed='
+      /Import File Strings/,/^$/ {
+         /^0/ {
+             s/^0  *\([^ ]*\) *$/\1/
+             p
+         }
+      }'
+  lt_cv_aix_libpath_=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
+  # Check for a 64-bit object if we didn't find anything.
+  if test -z "$lt_cv_aix_libpath_"; then
+    lt_cv_aix_libpath_=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
+  fi
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+  if test -z "$lt_cv_aix_libpath_"; then
+    lt_cv_aix_libpath_="/usr/lib:/lib"
+  fi
+
+fi
+
+  aix_libpath=$lt_cv_aix_libpath_
+fi
+
+        hardcode_libdir_flag_spec='${wl}-blibpath:$libdir:'"$aix_libpath"
+         # Warning - without using the other run time loading flags,
+         # -berok will link without error, but may produce a broken library.
+         no_undefined_flag=' ${wl}-bernotok'
+         allow_undefined_flag=' ${wl}-berok'
+         if test "$with_gnu_ld" = yes; then
+           # We only use this code for GNU lds that support --whole-archive.
+           whole_archive_flag_spec='${wl}--whole-archive$convenience ${wl}--no-whole-archive'
+         else
+           # Exported symbols can be pulled into shared objects from archives
+           whole_archive_flag_spec='$convenience'
+         fi
+         archive_cmds_need_lc=yes
+         # This is similar to how AIX traditionally builds its shared libraries.
+         archive_expsym_cmds="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs ${wl}-bnoentry $compiler_flags ${wl}-bE:$export_symbols${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname'
+       fi
+      fi
+      ;;
+
+    amigaos*)
+      case $host_cpu in
+      powerpc)
+            # see comment about AmigaOS4 .so support
+            archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
+            archive_expsym_cmds=''
+        ;;
+      m68k)
+            archive_cmds='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)'
+            hardcode_libdir_flag_spec='-L$libdir'
+            hardcode_minus_L=yes
+        ;;
+      esac
+      ;;
+
+    bsdi[45]*)
+      export_dynamic_flag_spec=-rdynamic
+      ;;
+
+    cygwin* | mingw* | pw32* | cegcc*)
+      # When not using gcc, we currently assume that we are using
+      # Microsoft Visual C++.
+      # hardcode_libdir_flag_spec is actually meaningless, as there is
+      # no search path for DLLs.
+      case $cc_basename in
+      cl*)
+       # Native MSVC
+       hardcode_libdir_flag_spec=' '
+       allow_undefined_flag=unsupported
+       always_export_symbols=yes
+       file_list_spec='@'
+       # Tell ltmain to make .lib files, not .a files.
+       libext=lib
+       # Tell ltmain to make .dll files, not .so files.
+       shrext_cmds=".dll"
+       # FIXME: Setting linknames here is a bad hack.
+       archive_cmds='$CC -o $output_objdir/$soname $libobjs $compiler_flags $deplibs -Wl,-dll~linknames='
+       archive_expsym_cmds='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then
+           sed -n -e 's/\\\\\\\(.*\\\\\\\)/-link\\\ -EXPORT:\\\\\\\1/' -e '1\\\!p' < $export_symbols > $output_objdir/$soname.exp;
+         else
+           sed -e 's/\\\\\\\(.*\\\\\\\)/-link\\\ -EXPORT:\\\\\\\1/' < $export_symbols > $output_objdir/$soname.exp;
+         fi~
+         $CC -o $tool_output_objdir$soname $libobjs $compiler_flags $deplibs "@$tool_output_objdir$soname.exp" -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~
+         linknames='
+       # The linker will not automatically build a static lib if we build a DLL.
+       # _LT_TAGVAR(old_archive_from_new_cmds, )='true'
+       enable_shared_with_static_runtimes=yes
+       exclude_expsyms='_NULL_IMPORT_DESCRIPTOR|_IMPORT_DESCRIPTOR_.*'
+       export_symbols_cmds='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[BCDGRS][ ]/s/.*[ ]\([^ ]*\)/\1,DATA/'\'' | $SED -e '\''/^[AITW][ ]/s/.*[ ]//'\'' | sort | uniq > $export_symbols'
+       # Don't use ranlib
+       old_postinstall_cmds='chmod 644 $oldlib'
+       postlink_cmds='lt_outputfile="@OUTPUT@"~
+         lt_tool_outputfile="@TOOL_OUTPUT@"~
+         case $lt_outputfile in
+           *.exe|*.EXE) ;;
+           *)
+             lt_outputfile="$lt_outputfile.exe"
+             lt_tool_outputfile="$lt_tool_outputfile.exe"
+             ;;
+         esac~
+         if test "$MANIFEST_TOOL" != ":" && test -f "$lt_outputfile.manifest"; then
+           $MANIFEST_TOOL -manifest "$lt_tool_outputfile.manifest" -outputresource:"$lt_tool_outputfile" || exit 1;
+           $RM "$lt_outputfile.manifest";
+         fi'
+       ;;
+      *)
+       # Assume MSVC wrapper
+       hardcode_libdir_flag_spec=' '
+       allow_undefined_flag=unsupported
+       # Tell ltmain to make .lib files, not .a files.
+       libext=lib
+       # Tell ltmain to make .dll files, not .so files.
+       shrext_cmds=".dll"
+       # FIXME: Setting linknames here is a bad hack.
+       archive_cmds='$CC -o $lib $libobjs $compiler_flags `func_echo_all "$deplibs" | $SED '\''s/ -lc$//'\''` -link -dll~linknames='
+       # The linker will automatically build a .lib file if we build a DLL.
+       old_archive_from_new_cmds='true'
+       # FIXME: Should let the user specify the lib program.
+       old_archive_cmds='lib -OUT:$oldlib$oldobjs$old_deplibs'
+       enable_shared_with_static_runtimes=yes
+       ;;
+      esac
+      ;;
+
+    darwin* | rhapsody*)
+
+
+  archive_cmds_need_lc=no
+  hardcode_direct=no
+  hardcode_automatic=yes
+  hardcode_shlibpath_var=unsupported
+  if test "$lt_cv_ld_force_load" = "yes"; then
+    whole_archive_flag_spec='`for conv in $convenience\"\"; do test  -n \"$conv\" && new_convenience=\"$new_convenience ${wl}-force_load,$conv\"; done; func_echo_all \"$new_convenience\"`'
+
+  else
+    whole_archive_flag_spec=''
+  fi
+  link_all_deplibs=yes
+  allow_undefined_flag="$_lt_dar_allow_undefined"
+  case $cc_basename in
+     ifort*) _lt_dar_can_shared=yes ;;
+     *) _lt_dar_can_shared=$GCC ;;
+  esac
+  if test "$_lt_dar_can_shared" = "yes"; then
+    output_verbose_link_cmd=func_echo_all
+    archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}"
+    module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}"
+    archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}"
+    module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}"
+
+  else
+  ld_shlibs=no
+  fi
+
+      ;;
+
+    dgux*)
+      archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      hardcode_libdir_flag_spec='-L$libdir'
+      hardcode_shlibpath_var=no
+      ;;
+
+    # FreeBSD 2.2.[012] allows us to include c++rt0.o to get C++ constructor
+    # support.  Future versions do this automatically, but an explicit c++rt0.o
+    # does not break anything, and helps significantly (at the cost of a little
+    # extra space).
+    freebsd2.2*)
+      archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags /usr/lib/c++rt0.o'
+      hardcode_libdir_flag_spec='-R$libdir'
+      hardcode_direct=yes
+      hardcode_shlibpath_var=no
+      ;;
+
+    # Unfortunately, older versions of FreeBSD 2 do not have this feature.
+    freebsd2.*)
+      archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'
+      hardcode_direct=yes
+      hardcode_minus_L=yes
+      hardcode_shlibpath_var=no
+      ;;
+
+    # FreeBSD 3 and greater uses gcc -shared to do shared libraries.
+    freebsd* | dragonfly*)
+      archive_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags'
+      hardcode_libdir_flag_spec='-R$libdir'
+      hardcode_direct=yes
+      hardcode_shlibpath_var=no
+      ;;
+
+    hpux9*)
+      if test "$GCC" = yes; then
+       archive_cmds='$RM $output_objdir/$soname~$CC -shared $pic_flag ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $libobjs $deplibs $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
+      else
+       archive_cmds='$RM $output_objdir/$soname~$LD -b +b $install_libdir -o $output_objdir/$soname $libobjs $deplibs $linker_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
+      fi
+      hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir'
+      hardcode_libdir_separator=:
+      hardcode_direct=yes
+
+      # hardcode_minus_L: Not really in the search PATH,
+      # but as the default location of the library.
+      hardcode_minus_L=yes
+      export_dynamic_flag_spec='${wl}-E'
+      ;;
+
+    hpux10*)
+      if test "$GCC" = yes && test "$with_gnu_ld" = no; then
+       archive_cmds='$CC -shared $pic_flag ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'
+      else
+       archive_cmds='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags'
+      fi
+      if test "$with_gnu_ld" = no; then
+       hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir'
+       hardcode_libdir_separator=:
+       hardcode_direct=yes
+       hardcode_direct_absolute=yes
+       export_dynamic_flag_spec='${wl}-E'
+       # hardcode_minus_L: Not really in the search PATH,
+       # but as the default location of the library.
+       hardcode_minus_L=yes
+      fi
+      ;;
+
+    hpux11*)
+      if test "$GCC" = yes && test "$with_gnu_ld" = no; then
+       case $host_cpu in
+       hppa*64*)
+         archive_cmds='$CC -shared ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
+         ;;
+       ia64*)
+         archive_cmds='$CC -shared $pic_flag ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags'
+         ;;
+       *)
+         archive_cmds='$CC -shared $pic_flag ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'
+         ;;
+       esac
+      else
+       case $host_cpu in
+       hppa*64*)
+         archive_cmds='$CC -b ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
+         ;;
+       ia64*)
+         archive_cmds='$CC -b ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags'
+         ;;
+       *)
+
+         # Older versions of the 11.00 compiler do not understand -b yet
+         # (HP92453-01 A.11.01.20 doesn't, HP92453-01 B.11.X.35175-35176.GP does)
+         { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC understands -b" >&5
+$as_echo_n "checking if $CC understands -b... " >&6; }
+if ${lt_cv_prog_compiler__b+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_prog_compiler__b=no
+   save_LDFLAGS="$LDFLAGS"
+   LDFLAGS="$LDFLAGS -b"
+   echo "$lt_simple_link_test_code" > conftest.$ac_ext
+   if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then
+     # The linker can only warn and ignore the option if not recognized
+     # So say no if there are warnings
+     if test -s conftest.err; then
+       # Append any errors to the config.log.
+       cat conftest.err 1>&5
+       $ECHO "$_lt_linker_boilerplate" | $SED '/^$/d' > conftest.exp
+       $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
+       if diff conftest.exp conftest.er2 >/dev/null; then
+         lt_cv_prog_compiler__b=yes
+       fi
+     else
+       lt_cv_prog_compiler__b=yes
+     fi
+   fi
+   $RM -r conftest*
+   LDFLAGS="$save_LDFLAGS"
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler__b" >&5
+$as_echo "$lt_cv_prog_compiler__b" >&6; }
+
+if test x"$lt_cv_prog_compiler__b" = xyes; then
+    archive_cmds='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'
+else
+    archive_cmds='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags'
+fi
+
+         ;;
+       esac
+      fi
+      if test "$with_gnu_ld" = no; then
+       hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir'
+       hardcode_libdir_separator=:
+
+       case $host_cpu in
+       hppa*64*|ia64*)
+         hardcode_direct=no
+         hardcode_shlibpath_var=no
+         ;;
+       *)
+         hardcode_direct=yes
+         hardcode_direct_absolute=yes
+         export_dynamic_flag_spec='${wl}-E'
+
+         # hardcode_minus_L: Not really in the search PATH,
+         # but as the default location of the library.
+         hardcode_minus_L=yes
+         ;;
+       esac
+      fi
+      ;;
+
+    irix5* | irix6* | nonstopux*)
+      if test "$GCC" = yes; then
+       archive_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && func_echo_all "${wl}-set_version ${wl}$verstring"` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+       # Try to use the -exported_symbol ld option, if it does not
+       # work, assume that -exports_file does not work either and
+       # implicitly export all symbols.
+       # This should be the same for all languages, so no per-tag cache variable.
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the $host_os linker accepts -exported_symbol" >&5
+$as_echo_n "checking whether the $host_os linker accepts -exported_symbol... " >&6; }
+if ${lt_cv_irix_exported_symbol+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  save_LDFLAGS="$LDFLAGS"
+          LDFLAGS="$LDFLAGS -shared ${wl}-exported_symbol ${wl}foo ${wl}-update_registry ${wl}/dev/null"
+          cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int foo (void) { return 0; }
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  lt_cv_irix_exported_symbol=yes
+else
+  lt_cv_irix_exported_symbol=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+           LDFLAGS="$save_LDFLAGS"
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_irix_exported_symbol" >&5
+$as_echo "$lt_cv_irix_exported_symbol" >&6; }
+       if test "$lt_cv_irix_exported_symbol" = yes; then
+          archive_expsym_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && func_echo_all "${wl}-set_version ${wl}$verstring"` ${wl}-update_registry ${wl}${output_objdir}/so_locations ${wl}-exports_file ${wl}$export_symbols -o $lib'
+       fi
+      else
+       archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry ${output_objdir}/so_locations -o $lib'
+       archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry ${output_objdir}/so_locations -exports_file $export_symbols -o $lib'
+      fi
+      archive_cmds_need_lc='no'
+      hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
+      hardcode_libdir_separator=:
+      inherit_rpath=yes
+      link_all_deplibs=yes
+      ;;
+
+    netbsd* | netbsdelf*-gnu)
+      if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
+       archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'  # a.out
+      else
+       archive_cmds='$LD -shared -o $lib $libobjs $deplibs $linker_flags'      # ELF
+      fi
+      hardcode_libdir_flag_spec='-R$libdir'
+      hardcode_direct=yes
+      hardcode_shlibpath_var=no
+      ;;
+
+    newsos6)
+      archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      hardcode_direct=yes
+      hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
+      hardcode_libdir_separator=:
+      hardcode_shlibpath_var=no
+      ;;
+
+    *nto* | *qnx*)
+      ;;
+
+    openbsd*)
+      if test -f /usr/libexec/ld.so; then
+       hardcode_direct=yes
+       hardcode_shlibpath_var=no
+       hardcode_direct_absolute=yes
+       if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
+         archive_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags'
+         archive_expsym_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-retain-symbols-file,$export_symbols'
+         hardcode_libdir_flag_spec='${wl}-rpath,$libdir'
+         export_dynamic_flag_spec='${wl}-E'
+       else
+         case $host_os in
+          openbsd[01].* | openbsd2.[0-7] | openbsd2.[0-7].*)
+            archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'
+            hardcode_libdir_flag_spec='-R$libdir'
+            ;;
+          *)
+            archive_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags'
+            hardcode_libdir_flag_spec='${wl}-rpath,$libdir'
+            ;;
+         esac
+       fi
+      else
+       ld_shlibs=no
+      fi
+      ;;
+
+    os2*)
+      hardcode_libdir_flag_spec='-L$libdir'
+      hardcode_minus_L=yes
+      allow_undefined_flag=unsupported
+      archive_cmds='$ECHO "LIBRARY $libname INITINSTANCE" > $output_objdir/$libname.def~$ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~echo DATA >> $output_objdir/$libname.def~echo " SINGLE NONSHARED" >> $output_objdir/$libname.def~echo EXPORTS >> $output_objdir/$libname.def~emxexp $libobjs >> $output_objdir/$libname.def~$CC -Zdll -Zcrtdll -o $lib $libobjs $deplibs $compiler_flags $output_objdir/$libname.def'
+      old_archive_from_new_cmds='emximp -o $output_objdir/$libname.a $output_objdir/$libname.def'
+      ;;
+
+    osf3*)
+      if test "$GCC" = yes; then
+       allow_undefined_flag=' ${wl}-expect_unresolved ${wl}\*'
+       archive_cmds='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && func_echo_all "${wl}-set_version ${wl}$verstring"` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+      else
+       allow_undefined_flag=' -expect_unresolved \*'
+       archive_cmds='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry ${output_objdir}/so_locations -o $lib'
+      fi
+      archive_cmds_need_lc='no'
+      hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
+      hardcode_libdir_separator=:
+      ;;
+
+    osf4* | osf5*)     # as osf3* with the addition of -msym flag
+      if test "$GCC" = yes; then
+       allow_undefined_flag=' ${wl}-expect_unresolved ${wl}\*'
+       archive_cmds='$CC -shared${allow_undefined_flag} $pic_flag $libobjs $deplibs $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && func_echo_all "${wl}-set_version ${wl}$verstring"` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
+       hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
+      else
+       allow_undefined_flag=' -expect_unresolved \*'
+       archive_cmds='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags -msym -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry ${output_objdir}/so_locations -o $lib'
+       archive_expsym_cmds='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done; printf "%s\\n" "-hidden">> $lib.exp~
+       $CC -shared${allow_undefined_flag} ${wl}-input ${wl}$lib.exp $compiler_flags $libobjs $deplibs -soname $soname `test -n "$verstring" && $ECHO "-set_version $verstring"` -update_registry ${output_objdir}/so_locations -o $lib~$RM $lib.exp'
+
+       # Both c and cxx compiler support -rpath directly
+       hardcode_libdir_flag_spec='-rpath $libdir'
+      fi
+      archive_cmds_need_lc='no'
+      hardcode_libdir_separator=:
+      ;;
+
+    solaris*)
+      no_undefined_flag=' -z defs'
+      if test "$GCC" = yes; then
+       wlarc='${wl}'
+       archive_cmds='$CC -shared $pic_flag ${wl}-z ${wl}text ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
+       archive_expsym_cmds='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
+         $CC -shared $pic_flag ${wl}-z ${wl}text ${wl}-M ${wl}$lib.exp ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp'
+      else
+       case `$CC -V 2>&1` in
+       *"Compilers 5.0"*)
+         wlarc=''
+         archive_cmds='$LD -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $linker_flags'
+         archive_expsym_cmds='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
+         $LD -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $linker_flags~$RM $lib.exp'
+         ;;
+       *)
+         wlarc='${wl}'
+         archive_cmds='$CC -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $compiler_flags'
+         archive_expsym_cmds='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
+         $CC -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp'
+         ;;
+       esac
+      fi
+      hardcode_libdir_flag_spec='-R$libdir'
+      hardcode_shlibpath_var=no
+      case $host_os in
+      solaris2.[0-5] | solaris2.[0-5].*) ;;
+      *)
+       # The compiler driver will combine and reorder linker options,
+       # but understands `-z linker_flag'.  GCC discards it without `$wl',
+       # but is careful enough not to reorder.
+       # Supported since Solaris 2.6 (maybe 2.5.1?)
+       if test "$GCC" = yes; then
+         whole_archive_flag_spec='${wl}-z ${wl}allextract$convenience ${wl}-z ${wl}defaultextract'
+       else
+         whole_archive_flag_spec='-z allextract$convenience -z defaultextract'
+       fi
+       ;;
+      esac
+      link_all_deplibs=yes
+      ;;
+
+    sunos4*)
+      if test "x$host_vendor" = xsequent; then
+       # Use $CC to link under sequent, because it throws in some extra .o
+       # files that make .init and .fini sections work.
+       archive_cmds='$CC -G ${wl}-h $soname -o $lib $libobjs $deplibs $compiler_flags'
+      else
+       archive_cmds='$LD -assert pure-text -Bstatic -o $lib $libobjs $deplibs $linker_flags'
+      fi
+      hardcode_libdir_flag_spec='-L$libdir'
+      hardcode_direct=yes
+      hardcode_minus_L=yes
+      hardcode_shlibpath_var=no
+      ;;
+
+    sysv4)
+      case $host_vendor in
+       sni)
+         archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+         hardcode_direct=yes # is this really true???
+       ;;
+       siemens)
+         ## LD is ld it makes a PLAMLIB
+         ## CC just makes a GrossModule.
+         archive_cmds='$LD -G -o $lib $libobjs $deplibs $linker_flags'
+         reload_cmds='$CC -r -o $output$reload_objs'
+         hardcode_direct=no
+        ;;
+       motorola)
+         archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+         hardcode_direct=no #Motorola manual says yes, but my tests say they lie
+       ;;
+      esac
+      runpath_var='LD_RUN_PATH'
+      hardcode_shlibpath_var=no
+      ;;
+
+    sysv4.3*)
+      archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      hardcode_shlibpath_var=no
+      export_dynamic_flag_spec='-Bexport'
+      ;;
+
+    sysv4*MP*)
+      if test -d /usr/nec; then
+       archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+       hardcode_shlibpath_var=no
+       runpath_var=LD_RUN_PATH
+       hardcode_runpath_var=yes
+       ld_shlibs=yes
+      fi
+      ;;
+
+    sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[01].[10]* | unixware7* | sco3.2v5.0.[024]*)
+      no_undefined_flag='${wl}-z,text'
+      archive_cmds_need_lc=no
+      hardcode_shlibpath_var=no
+      runpath_var='LD_RUN_PATH'
+
+      if test "$GCC" = yes; then
+       archive_cmds='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+       archive_expsym_cmds='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+      else
+       archive_cmds='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+       archive_expsym_cmds='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+      fi
+      ;;
+
+    sysv5* | sco3.2v5* | sco5v6*)
+      # Note: We can NOT use -z defs as we might desire, because we do not
+      # link with -lc, and that would cause any symbols used from libc to
+      # always be unresolved, which means just about no library would
+      # ever link correctly.  If we're not using GNU ld we use -z text
+      # though, which does catch some bad symbols but isn't as heavy-handed
+      # as -z defs.
+      no_undefined_flag='${wl}-z,text'
+      allow_undefined_flag='${wl}-z,nodefs'
+      archive_cmds_need_lc=no
+      hardcode_shlibpath_var=no
+      hardcode_libdir_flag_spec='${wl}-R,$libdir'
+      hardcode_libdir_separator=':'
+      link_all_deplibs=yes
+      export_dynamic_flag_spec='${wl}-Bexport'
+      runpath_var='LD_RUN_PATH'
+
+      if test "$GCC" = yes; then
+       archive_cmds='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+       archive_expsym_cmds='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+      else
+       archive_cmds='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+       archive_expsym_cmds='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
+      fi
+      ;;
+
+    uts4*)
+      archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
+      hardcode_libdir_flag_spec='-L$libdir'
+      hardcode_shlibpath_var=no
+      ;;
+
+    *)
+      ld_shlibs=no
+      ;;
+    esac
+
+    if test x$host_vendor = xsni; then
+      case $host in
+      sysv4 | sysv4.2uw2* | sysv4.3* | sysv5*)
+       export_dynamic_flag_spec='${wl}-Blargedynsym'
+       ;;
+      esac
+    fi
+  fi
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ld_shlibs" >&5
+$as_echo "$ld_shlibs" >&6; }
+test "$ld_shlibs" = no && can_build_shared=no
+
+with_gnu_ld=$with_gnu_ld
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#
+# Do we need to explicitly link libc?
+#
+case "x$archive_cmds_need_lc" in
+x|xyes)
+  # Assume -lc should be added
+  archive_cmds_need_lc=yes
+
+  if test "$enable_shared" = yes && test "$GCC" = yes; then
+    case $archive_cmds in
+    *'~'*)
+      # FIXME: we may have to deal with multi-command sequences.
+      ;;
+    '$CC '*)
+      # Test whether the compiler implicitly links with -lc since on some
+      # systems, -lgcc has to come before -lc. If gcc already passes -lc
+      # to ld, don't add -lc before -lgcc.
+      { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -lc should be explicitly linked in" >&5
+$as_echo_n "checking whether -lc should be explicitly linked in... " >&6; }
+if ${lt_cv_archive_cmds_need_lc+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  $RM conftest*
+       echo "$lt_simple_compile_test_code" > conftest.$ac_ext
+
+       if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; } 2>conftest.err; then
+         soname=conftest
+         lib=conftest
+         libobjs=conftest.$ac_objext
+         deplibs=
+         wl=$lt_prog_compiler_wl
+         pic_flag=$lt_prog_compiler_pic
+         compiler_flags=-v
+         linker_flags=-v
+         verstring=
+         output_objdir=.
+         libname=conftest
+         lt_save_allow_undefined_flag=$allow_undefined_flag
+         allow_undefined_flag=
+         if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$archive_cmds 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1\""; } >&5
+  (eval $archive_cmds 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }
+         then
+           lt_cv_archive_cmds_need_lc=no
+         else
+           lt_cv_archive_cmds_need_lc=yes
+         fi
+         allow_undefined_flag=$lt_save_allow_undefined_flag
+       else
+         cat conftest.err 1>&5
+       fi
+       $RM conftest*
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_archive_cmds_need_lc" >&5
+$as_echo "$lt_cv_archive_cmds_need_lc" >&6; }
+      archive_cmds_need_lc=$lt_cv_archive_cmds_need_lc
+      ;;
+    esac
+  fi
+  ;;
+esac
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking dynamic linker characteristics" >&5
+$as_echo_n "checking dynamic linker characteristics... " >&6; }
+
+if test "$GCC" = yes; then
+  case $host_os in
+    darwin*) lt_awk_arg="/^libraries:/,/LR/" ;;
+    *) lt_awk_arg="/^libraries:/" ;;
+  esac
+  case $host_os in
+    mingw* | cegcc*) lt_sed_strip_eq="s,=\([A-Za-z]:\),\1,g" ;;
+    *) lt_sed_strip_eq="s,=/,/,g" ;;
+  esac
+  lt_search_path_spec=`$CC -print-search-dirs | awk $lt_awk_arg | $SED -e "s/^libraries://" -e $lt_sed_strip_eq`
+  case $lt_search_path_spec in
+  *\;*)
+    # if the path contains ";" then we assume it to be the separator
+    # otherwise default to the standard path separator (i.e. ":") - it is
+    # assumed that no part of a normal pathname contains ";" but that should
+    # okay in the real world where ";" in dirpaths is itself problematic.
+    lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED 's/;/ /g'`
+    ;;
+  *)
+    lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED "s/$PATH_SEPARATOR/ /g"`
+    ;;
+  esac
+  # Ok, now we have the path, separated by spaces, we can step through it
+  # and add multilib dir if necessary.
+  lt_tmp_lt_search_path_spec=
+  lt_multi_os_dir=`$CC $CPPFLAGS $CFLAGS $LDFLAGS -print-multi-os-directory 2>/dev/null`
+  for lt_sys_path in $lt_search_path_spec; do
+    if test -d "$lt_sys_path/$lt_multi_os_dir"; then
+      lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path/$lt_multi_os_dir"
+    else
+      test -d "$lt_sys_path" && \
+       lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path"
+    fi
+  done
+  lt_search_path_spec=`$ECHO "$lt_tmp_lt_search_path_spec" | awk '
+BEGIN {RS=" "; FS="/|\n";} {
+  lt_foo="";
+  lt_count=0;
+  for (lt_i = NF; lt_i > 0; lt_i--) {
+    if ($lt_i != "" && $lt_i != ".") {
+      if ($lt_i == "..") {
+        lt_count++;
+      } else {
+        if (lt_count == 0) {
+          lt_foo="/" $lt_i lt_foo;
+        } else {
+          lt_count--;
+        }
+      }
+    }
+  }
+  if (lt_foo != "") { lt_freq[lt_foo]++; }
+  if (lt_freq[lt_foo] == 1) { print lt_foo; }
+}'`
+  # AWK program above erroneously prepends '/' to C:/dos/paths
+  # for these hosts.
+  case $host_os in
+    mingw* | cegcc*) lt_search_path_spec=`$ECHO "$lt_search_path_spec" |\
+      $SED 's,/\([A-Za-z]:\),\1,g'` ;;
+  esac
+  sys_lib_search_path_spec=`$ECHO "$lt_search_path_spec" | $lt_NL2SP`
+else
+  sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib"
+fi
+library_names_spec=
+libname_spec='lib$name'
+soname_spec=
+shrext_cmds=".so"
+postinstall_cmds=
+postuninstall_cmds=
+finish_cmds=
+finish_eval=
+shlibpath_var=
+shlibpath_overrides_runpath=unknown
+version_type=none
+dynamic_linker="$host_os ld.so"
+sys_lib_dlsearch_path_spec="/lib /usr/lib"
+need_lib_prefix=unknown
+hardcode_into_libs=no
+
+# when you set need_version to no, make sure it does not cause -set_version
+# flags to be left without arguments
+need_version=unknown
+
+case $host_os in
+aix3*)
+  version_type=linux # correct to gnu/linux during the next big refactor
+  library_names_spec='${libname}${release}${shared_ext}$versuffix $libname.a'
+  shlibpath_var=LIBPATH
+
+  # AIX 3 has no versioning support, so we append a major version to the name.
+  soname_spec='${libname}${release}${shared_ext}$major'
+  ;;
+
+aix[4-9]*)
+  version_type=linux # correct to gnu/linux during the next big refactor
+  need_lib_prefix=no
+  need_version=no
+  hardcode_into_libs=yes
+  if test "$host_cpu" = ia64; then
+    # AIX 5 supports IA64
+    library_names_spec='${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext}$versuffix $libname${shared_ext}'
+    shlibpath_var=LD_LIBRARY_PATH
+  else
+    # With GCC up to 2.95.x, collect2 would create an import file
+    # for dependence libraries.  The import file would start with
+    # the line `#! .'.  This would cause the generated library to
+    # depend on `.', always an invalid library.  This was fixed in
+    # development snapshots of GCC prior to 3.0.
+    case $host_os in
+      aix4 | aix4.[01] | aix4.[01].*)
+      if { echo '#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97)'
+          echo ' yes '
+          echo '#endif'; } | ${CC} -E - | $GREP yes > /dev/null; then
+       :
+      else
+       can_build_shared=no
+      fi
+      ;;
+    esac
+    # AIX (on Power*) has no versioning support, so currently we can not hardcode correct
+    # soname into executable. Probably we can add versioning support to
+    # collect2, so additional links can be useful in future.
+    if test "$aix_use_runtimelinking" = yes; then
+      # If using run time linking (on AIX 4.2 or later) use lib<name>.so
+      # instead of lib<name>.a to let people know that these are not
+      # typical AIX shared libraries.
+      library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    else
+      # We preserve .a as extension for shared libraries through AIX4.2
+      # and later when we are not doing run time linking.
+      library_names_spec='${libname}${release}.a $libname.a'
+      soname_spec='${libname}${release}${shared_ext}$major'
+    fi
+    shlibpath_var=LIBPATH
+  fi
+  ;;
+
+amigaos*)
+  case $host_cpu in
+  powerpc)
+    # Since July 2007 AmigaOS4 officially supports .so libraries.
+    # When compiling the executable, add -use-dynld -Lsobjs: to the compileline.
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    ;;
+  m68k)
+    library_names_spec='$libname.ixlibrary $libname.a'
+    # Create ${libname}_ixlibrary.a entries in /sys/libs.
+    finish_eval='for lib in `ls $libdir/*.ixlibrary 2>/dev/null`; do libname=`func_echo_all "$lib" | $SED '\''s%^.*/\([^/]*\)\.ixlibrary$%\1%'\''`; test $RM /sys/libs/${libname}_ixlibrary.a; $show "cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a"; cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a || exit 1; done'
+    ;;
+  esac
+  ;;
+
+beos*)
+  library_names_spec='${libname}${shared_ext}'
+  dynamic_linker="$host_os ld.so"
+  shlibpath_var=LIBRARY_PATH
+  ;;
+
+bsdi[45]*)
+  version_type=linux # correct to gnu/linux during the next big refactor
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  finish_cmds='PATH="\$PATH:/sbin" ldconfig $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  sys_lib_search_path_spec="/shlib /usr/lib /usr/X11/lib /usr/contrib/lib /lib /usr/local/lib"
+  sys_lib_dlsearch_path_spec="/shlib /usr/lib /usr/local/lib"
+  # the default ld.so.conf also contains /usr/contrib/lib and
+  # /usr/X11R6/lib (/usr/X11 is a link to /usr/X11R6), but let us allow
+  # libtool to hard-code these into programs
+  ;;
+
+cygwin* | mingw* | pw32* | cegcc*)
+  version_type=windows
+  shrext_cmds=".dll"
+  need_version=no
+  need_lib_prefix=no
+
+  case $GCC,$cc_basename in
+  yes,*)
+    # gcc
+    library_names_spec='$libname.dll.a'
+    # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      test -d \$dldir || mkdir -p \$dldir~
+      $install_prog $dir/$dlname \$dldir/$dlname~
+      chmod a+x \$dldir/$dlname~
+      if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
+        eval '\''$striplib \$dldir/$dlname'\'' || exit \$?;
+      fi'
+    postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
+      dlpath=$dir/\$dldll~
+       $RM \$dlpath'
+    shlibpath_overrides_runpath=yes
+
+    case $host_os in
+    cygwin*)
+      # Cygwin DLLs use 'cyg' prefix rather than 'lib'
+      soname_spec='`echo ${libname} | sed -e 's/^lib/cyg/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
+
+      sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/lib/w32api"
+      ;;
+    mingw* | cegcc*)
+      # MinGW DLLs use traditional 'lib' prefix
+      soname_spec='${libname}`echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
+      ;;
+    pw32*)
+      # pw32 DLLs use 'pw' prefix rather than 'lib'
+      library_names_spec='`echo ${libname} | sed -e 's/^lib/pw/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
+      ;;
+    esac
+    dynamic_linker='Win32 ld.exe'
+    ;;
+
+  *,cl*)
+    # Native MSVC
+    libname_spec='$name'
+    soname_spec='${libname}`echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}'
+    library_names_spec='${libname}.dll.lib'
+
+    case $build_os in
+    mingw*)
+      sys_lib_search_path_spec=
+      lt_save_ifs=$IFS
+      IFS=';'
+      for lt_path in $LIB
+      do
+        IFS=$lt_save_ifs
+        # Let DOS variable expansion print the short 8.3 style file name.
+        lt_path=`cd "$lt_path" 2>/dev/null && cmd //C "for %i in (".") do @echo %~si"`
+        sys_lib_search_path_spec="$sys_lib_search_path_spec $lt_path"
+      done
+      IFS=$lt_save_ifs
+      # Convert to MSYS style.
+      sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | sed -e 's|\\\\|/|g' -e 's| \\([a-zA-Z]\\):| /\\1|g' -e 's|^ ||'`
+      ;;
+    cygwin*)
+      # Convert to unix form, then to dos form, then back to unix form
+      # but this time dos style (no spaces!) so that the unix form looks
+      # like /cygdrive/c/PROGRA~1:/cygdr...
+      sys_lib_search_path_spec=`cygpath --path --unix "$LIB"`
+      sys_lib_search_path_spec=`cygpath --path --dos "$sys_lib_search_path_spec" 2>/dev/null`
+      sys_lib_search_path_spec=`cygpath --path --unix "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"`
+      ;;
+    *)
+      sys_lib_search_path_spec="$LIB"
+      if $ECHO "$sys_lib_search_path_spec" | $GREP ';[c-zC-Z]:/' >/dev/null; then
+        # It is most probably a Windows format PATH.
+        sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'`
+      else
+        sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"`
+      fi
+      # FIXME: find the short name or the path components, as spaces are
+      # common. (e.g. "Program Files" -> "PROGRA~1")
+      ;;
+    esac
+
+    # DLL is installed to $(libdir)/../bin by postinstall_cmds
+    postinstall_cmds='base_file=`basename \${file}`~
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
+      dldir=$destdir/`dirname \$dlpath`~
+      test -d \$dldir || mkdir -p \$dldir~
+      $install_prog $dir/$dlname \$dldir/$dlname'
+    postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
+      dlpath=$dir/\$dldll~
+       $RM \$dlpath'
+    shlibpath_overrides_runpath=yes
+    dynamic_linker='Win32 link.exe'
+    ;;
+
+  *)
+    # Assume MSVC wrapper
+    library_names_spec='${libname}`echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext} $libname.lib'
+    dynamic_linker='Win32 ld.exe'
+    ;;
+  esac
+  # FIXME: first we should search . and the directory the executable is in
+  shlibpath_var=PATH
+  ;;
+
+darwin* | rhapsody*)
+  dynamic_linker="$host_os dyld"
+  version_type=darwin
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${major}$shared_ext ${libname}$shared_ext'
+  soname_spec='${libname}${release}${major}$shared_ext'
+  shlibpath_overrides_runpath=yes
+  shlibpath_var=DYLD_LIBRARY_PATH
+  shrext_cmds='`test .$module = .yes && echo .so || echo .dylib`'
+
+  sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/local/lib"
+  sys_lib_dlsearch_path_spec='/usr/local/lib /lib /usr/lib'
+  ;;
+
+dgux*)
+  version_type=linux # correct to gnu/linux during the next big refactor
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname$shared_ext'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  ;;
+
+freebsd* | dragonfly*)
+  # DragonFly does not have aout.  When/if they implement a new
+  # versioning mechanism, adjust this.
+  if test -x /usr/bin/objformat; then
+    objformat=`/usr/bin/objformat`
+  else
+    case $host_os in
+    freebsd[23].*) objformat=aout ;;
+    *) objformat=elf ;;
+    esac
+  fi
+  version_type=freebsd-$objformat
+  case $version_type in
+    freebsd-elf*)
+      library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}'
+      need_version=no
+      need_lib_prefix=no
+      ;;
+    freebsd-*)
+      library_names_spec='${libname}${release}${shared_ext}$versuffix $libname${shared_ext}$versuffix'
+      need_version=yes
+      ;;
+  esac
+  shlibpath_var=LD_LIBRARY_PATH
+  case $host_os in
+  freebsd2.*)
+    shlibpath_overrides_runpath=yes
+    ;;
+  freebsd3.[01]* | freebsdelf3.[01]*)
+    shlibpath_overrides_runpath=yes
+    hardcode_into_libs=yes
+    ;;
+  freebsd3.[2-9]* | freebsdelf3.[2-9]* | \
+  freebsd4.[0-5] | freebsdelf4.[0-5] | freebsd4.1.1 | freebsdelf4.1.1)
+    shlibpath_overrides_runpath=no
+    hardcode_into_libs=yes
+    ;;
+  *) # from 4.6 on, and DragonFly
+    shlibpath_overrides_runpath=yes
+    hardcode_into_libs=yes
+    ;;
+  esac
+  ;;
+
+haiku*)
+  version_type=linux # correct to gnu/linux during the next big refactor
+  need_lib_prefix=no
+  need_version=no
+  dynamic_linker="$host_os runtime_loader"
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}${major} ${libname}${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  sys_lib_dlsearch_path_spec='/boot/home/config/lib /boot/common/lib /boot/system/lib'
+  hardcode_into_libs=yes
+  ;;
+
+hpux9* | hpux10* | hpux11*)
+  # Give a soname corresponding to the major version so that dld.sl refuses to
+  # link against other versions.
+  version_type=sunos
+  need_lib_prefix=no
+  need_version=no
+  case $host_cpu in
+  ia64*)
+    shrext_cmds='.so'
+    hardcode_into_libs=yes
+    dynamic_linker="$host_os dld.so"
+    shlibpath_var=LD_LIBRARY_PATH
+    shlibpath_overrides_runpath=yes # Unless +noenvvar is specified.
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    if test "X$HPUX_IA64_MODE" = X32; then
+      sys_lib_search_path_spec="/usr/lib/hpux32 /usr/local/lib/hpux32 /usr/local/lib"
+    else
+      sys_lib_search_path_spec="/usr/lib/hpux64 /usr/local/lib/hpux64"
+    fi
+    sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec
+    ;;
+  hppa*64*)
+    shrext_cmds='.sl'
+    hardcode_into_libs=yes
+    dynamic_linker="$host_os dld.sl"
+    shlibpath_var=LD_LIBRARY_PATH # How should we handle SHLIB_PATH
+    shlibpath_overrides_runpath=yes # Unless +noenvvar is specified.
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    sys_lib_search_path_spec="/usr/lib/pa20_64 /usr/ccs/lib/pa20_64"
+    sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec
+    ;;
+  *)
+    shrext_cmds='.sl'
+    dynamic_linker="$host_os dld.sl"
+    shlibpath_var=SHLIB_PATH
+    shlibpath_overrides_runpath=no # +s is required to enable SHLIB_PATH
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    ;;
+  esac
+  # HP-UX runs *really* slowly unless shared libraries are mode 555, ...
+  postinstall_cmds='chmod 555 $lib'
+  # or fails outright, so override atomically:
+  install_override_mode=555
+  ;;
+
+interix[3-9]*)
+  version_type=linux # correct to gnu/linux during the next big refactor
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  dynamic_linker='Interix 3.x ld.so.1 (PE, like ELF)'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  hardcode_into_libs=yes
+  ;;
+
+irix5* | irix6* | nonstopux*)
+  case $host_os in
+    nonstopux*) version_type=nonstopux ;;
+    *)
+       if test "$lt_cv_prog_gnu_ld" = yes; then
+               version_type=linux # correct to gnu/linux during the next big refactor
+       else
+               version_type=irix
+       fi ;;
+  esac
+  need_lib_prefix=no
+  need_version=no
+  soname_spec='${libname}${release}${shared_ext}$major'
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext} $libname${shared_ext}'
+  case $host_os in
+  irix5* | nonstopux*)
+    libsuff= shlibsuff=
+    ;;
+  *)
+    case $LD in # libtool.m4 will add one of these switches to LD
+    *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ")
+      libsuff= shlibsuff= libmagic=32-bit;;
+    *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ")
+      libsuff=32 shlibsuff=N32 libmagic=N32;;
+    *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ")
+      libsuff=64 shlibsuff=64 libmagic=64-bit;;
+    *) libsuff= shlibsuff= libmagic=never-match;;
+    esac
+    ;;
+  esac
+  shlibpath_var=LD_LIBRARY${shlibsuff}_PATH
+  shlibpath_overrides_runpath=no
+  sys_lib_search_path_spec="/usr/lib${libsuff} /lib${libsuff} /usr/local/lib${libsuff}"
+  sys_lib_dlsearch_path_spec="/usr/lib${libsuff} /lib${libsuff}"
+  hardcode_into_libs=yes
+  ;;
+
+# No shared lib support for Linux oldld, aout, or coff.
+linux*oldld* | linux*aout* | linux*coff*)
+  dynamic_linker=no
+  ;;
+
+# This must be glibc/ELF.
+linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*)
+  version_type=linux # correct to gnu/linux during the next big refactor
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  finish_cmds='PATH="\$PATH:/sbin" ldconfig -n $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+
+  # Some binutils ld are patched to set DT_RUNPATH
+  if ${lt_cv_shlibpath_overrides_runpath+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  lt_cv_shlibpath_overrides_runpath=no
+    save_LDFLAGS=$LDFLAGS
+    save_libdir=$libdir
+    eval "libdir=/foo; wl=\"$lt_prog_compiler_wl\"; \
+        LDFLAGS=\"\$LDFLAGS $hardcode_libdir_flag_spec\""
+    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  if  ($OBJDUMP -p conftest$ac_exeext) 2>/dev/null | grep "RUNPATH.*$libdir" >/dev/null; then :
+  lt_cv_shlibpath_overrides_runpath=yes
+fi
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+    LDFLAGS=$save_LDFLAGS
+    libdir=$save_libdir
+
+fi
+
+  shlibpath_overrides_runpath=$lt_cv_shlibpath_overrides_runpath
+
+  # This implies no fast_install, which is unacceptable.
+  # Some rework will be needed to allow for fast_install
+  # before this can be enabled.
+  hardcode_into_libs=yes
+
+  # Append ld.so.conf contents to the search path
+  if test -f /etc/ld.so.conf; then
+    lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \$2)); skip = 1; } { if (!skip) print \$0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[      ]*hwcap[        ]/d;s/[:,      ]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;s/"//g;/^$/d' | tr '\n' ' '`
+    sys_lib_dlsearch_path_spec="/lib /usr/lib $lt_ld_extra"
+  fi
+
+  # We used to test for /lib/ld.so.1 and disable shared libraries on
+  # powerpc, because MkLinux only supported shared libraries with the
+  # GNU dynamic linker.  Since this was broken with cross compilers,
+  # most powerpc-linux boxes support dynamic linking these days and
+  # people can always --disable-shared, the test was removed, and we
+  # assume the GNU/Linux dynamic linker is in use.
+  dynamic_linker='GNU/Linux ld.so'
+  ;;
+
+netbsdelf*-gnu)
+  version_type=linux
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  hardcode_into_libs=yes
+  dynamic_linker='NetBSD ld.elf_so'
+  ;;
+
+netbsd*)
+  version_type=sunos
+  need_lib_prefix=no
+  need_version=no
+  if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
+    finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir'
+    dynamic_linker='NetBSD (a.out) ld.so'
+  else
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
+    soname_spec='${libname}${release}${shared_ext}$major'
+    dynamic_linker='NetBSD ld.elf_so'
+  fi
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  hardcode_into_libs=yes
+  ;;
+
+newsos6)
+  version_type=linux # correct to gnu/linux during the next big refactor
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  ;;
+
+*nto* | *qnx*)
+  version_type=qnx
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  hardcode_into_libs=yes
+  dynamic_linker='ldqnx.so'
+  ;;
+
+openbsd*)
+  version_type=sunos
+  sys_lib_dlsearch_path_spec="/usr/lib"
+  need_lib_prefix=no
+  # Some older versions of OpenBSD (3.3 at least) *do* need versioned libs.
+  case $host_os in
+    openbsd3.3 | openbsd3.3.*) need_version=yes ;;
+    *)                         need_version=no  ;;
+  esac
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
+  finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
+    case $host_os in
+      openbsd2.[89] | openbsd2.[89].*)
+       shlibpath_overrides_runpath=no
+       ;;
+      *)
+       shlibpath_overrides_runpath=yes
+       ;;
+      esac
+  else
+    shlibpath_overrides_runpath=yes
+  fi
+  ;;
+
+os2*)
+  libname_spec='$name'
+  shrext_cmds=".dll"
+  need_lib_prefix=no
+  library_names_spec='$libname${shared_ext} $libname.a'
+  dynamic_linker='OS/2 ld.exe'
+  shlibpath_var=LIBPATH
+  ;;
+
+osf3* | osf4* | osf5*)
+  version_type=osf
+  need_lib_prefix=no
+  need_version=no
+  soname_spec='${libname}${release}${shared_ext}$major'
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  shlibpath_var=LD_LIBRARY_PATH
+  sys_lib_search_path_spec="/usr/shlib /usr/ccs/lib /usr/lib/cmplrs/cc /usr/lib /usr/local/lib /var/shlib"
+  sys_lib_dlsearch_path_spec="$sys_lib_search_path_spec"
+  ;;
+
+rdos*)
+  dynamic_linker=no
+  ;;
+
+solaris*)
+  version_type=linux # correct to gnu/linux during the next big refactor
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  hardcode_into_libs=yes
+  # ldd complains unless libraries are executable
+  postinstall_cmds='chmod +x $lib'
+  ;;
+
+sunos4*)
+  version_type=sunos
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
+  finish_cmds='PATH="\$PATH:/usr/etc" ldconfig $libdir'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  if test "$with_gnu_ld" = yes; then
+    need_lib_prefix=no
+  fi
+  need_version=yes
+  ;;
+
+sysv4 | sysv4.3*)
+  version_type=linux # correct to gnu/linux during the next big refactor
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  case $host_vendor in
+    sni)
+      shlibpath_overrides_runpath=no
+      need_lib_prefix=no
+      runpath_var=LD_RUN_PATH
+      ;;
+    siemens)
+      need_lib_prefix=no
+      ;;
+    motorola)
+      need_lib_prefix=no
+      need_version=no
+      shlibpath_overrides_runpath=no
+      sys_lib_search_path_spec='/lib /usr/lib /usr/ccs/lib'
+      ;;
+  esac
+  ;;
+
+sysv4*MP*)
+  if test -d /usr/nec ;then
+    version_type=linux # correct to gnu/linux during the next big refactor
+    library_names_spec='$libname${shared_ext}.$versuffix $libname${shared_ext}.$major $libname${shared_ext}'
+    soname_spec='$libname${shared_ext}.$major'
+    shlibpath_var=LD_LIBRARY_PATH
+  fi
+  ;;
+
+sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*)
+  version_type=freebsd-elf
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=yes
+  hardcode_into_libs=yes
+  if test "$with_gnu_ld" = yes; then
+    sys_lib_search_path_spec='/usr/local/lib /usr/gnu/lib /usr/ccs/lib /usr/lib /lib'
+  else
+    sys_lib_search_path_spec='/usr/ccs/lib /usr/lib'
+    case $host_os in
+      sco3.2v5*)
+        sys_lib_search_path_spec="$sys_lib_search_path_spec /lib"
+       ;;
+    esac
+  fi
+  sys_lib_dlsearch_path_spec='/usr/lib'
+  ;;
+
+tpf*)
+  # TPF is a cross-target only.  Preferred cross-host = GNU/Linux.
+  version_type=linux # correct to gnu/linux during the next big refactor
+  need_lib_prefix=no
+  need_version=no
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  shlibpath_var=LD_LIBRARY_PATH
+  shlibpath_overrides_runpath=no
+  hardcode_into_libs=yes
+  ;;
+
+uts4*)
+  version_type=linux # correct to gnu/linux during the next big refactor
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
+  soname_spec='${libname}${release}${shared_ext}$major'
+  shlibpath_var=LD_LIBRARY_PATH
+  ;;
+
+*)
+  dynamic_linker=no
+  ;;
+esac
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $dynamic_linker" >&5
+$as_echo "$dynamic_linker" >&6; }
+test "$dynamic_linker" = no && can_build_shared=no
+
+variables_saved_for_relink="PATH $shlibpath_var $runpath_var"
+if test "$GCC" = yes; then
+  variables_saved_for_relink="$variables_saved_for_relink GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH"
+fi
+
+if test "${lt_cv_sys_lib_search_path_spec+set}" = set; then
+  sys_lib_search_path_spec="$lt_cv_sys_lib_search_path_spec"
+fi
+if test "${lt_cv_sys_lib_dlsearch_path_spec+set}" = set; then
+  sys_lib_dlsearch_path_spec="$lt_cv_sys_lib_dlsearch_path_spec"
+fi
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to hardcode library paths into programs" >&5
+$as_echo_n "checking how to hardcode library paths into programs... " >&6; }
+hardcode_action=
+if test -n "$hardcode_libdir_flag_spec" ||
+   test -n "$runpath_var" ||
+   test "X$hardcode_automatic" = "Xyes" ; then
+
+  # We can hardcode non-existent directories.
+  if test "$hardcode_direct" != no &&
+     # If the only mechanism to avoid hardcoding is shlibpath_var, we
+     # have to relink, otherwise we might link with an installed library
+     # when we should be linking with a yet-to-be-installed one
+     ## test "$_LT_TAGVAR(hardcode_shlibpath_var, )" != no &&
+     test "$hardcode_minus_L" != no; then
+    # Linking always hardcodes the temporary library directory.
+    hardcode_action=relink
+  else
+    # We can link without hardcoding, and we can hardcode nonexisting dirs.
+    hardcode_action=immediate
+  fi
+else
+  # We cannot hardcode anything, or else we can only hardcode existing
+  # directories.
+  hardcode_action=unsupported
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $hardcode_action" >&5
+$as_echo "$hardcode_action" >&6; }
+
+if test "$hardcode_action" = relink ||
+   test "$inherit_rpath" = yes; then
+  # Fast installation is not supported
+  enable_fast_install=no
+elif test "$shlibpath_overrides_runpath" = yes ||
+     test "$enable_shared" = no; then
+  # Fast installation is not necessary
+  enable_fast_install=needless
+fi
+
+
+
+
+
+
+  if test "x$enable_dlopen" != xyes; then
+  enable_dlopen=unknown
+  enable_dlopen_self=unknown
+  enable_dlopen_self_static=unknown
+else
+  lt_cv_dlopen=no
+  lt_cv_dlopen_libs=
+
+  case $host_os in
+  beos*)
+    lt_cv_dlopen="load_add_on"
+    lt_cv_dlopen_libs=
+    lt_cv_dlopen_self=yes
+    ;;
+
+  mingw* | pw32* | cegcc*)
+    lt_cv_dlopen="LoadLibrary"
+    lt_cv_dlopen_libs=
+    ;;
+
+  cygwin*)
+    lt_cv_dlopen="dlopen"
+    lt_cv_dlopen_libs=
+    ;;
+
+  darwin*)
+  # if libdl is installed we need to link against it
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5
+$as_echo_n "checking for dlopen in -ldl... " >&6; }
+if ${ac_cv_lib_dl_dlopen+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-ldl  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char dlopen ();
+int
+main ()
+{
+return dlopen ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_dl_dlopen=yes
+else
+  ac_cv_lib_dl_dlopen=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dl_dlopen" >&5
+$as_echo "$ac_cv_lib_dl_dlopen" >&6; }
+if test "x$ac_cv_lib_dl_dlopen" = xyes; then :
+  lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl"
+else
+
+    lt_cv_dlopen="dyld"
+    lt_cv_dlopen_libs=
+    lt_cv_dlopen_self=yes
+
+fi
+
+    ;;
+
+  *)
+    ac_fn_c_check_func "$LINENO" "shl_load" "ac_cv_func_shl_load"
+if test "x$ac_cv_func_shl_load" = xyes; then :
+  lt_cv_dlopen="shl_load"
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for shl_load in -ldld" >&5
+$as_echo_n "checking for shl_load in -ldld... " >&6; }
+if ${ac_cv_lib_dld_shl_load+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-ldld  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char shl_load ();
+int
+main ()
+{
+return shl_load ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_dld_shl_load=yes
+else
+  ac_cv_lib_dld_shl_load=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dld_shl_load" >&5
+$as_echo "$ac_cv_lib_dld_shl_load" >&6; }
+if test "x$ac_cv_lib_dld_shl_load" = xyes; then :
+  lt_cv_dlopen="shl_load" lt_cv_dlopen_libs="-ldld"
+else
+  ac_fn_c_check_func "$LINENO" "dlopen" "ac_cv_func_dlopen"
+if test "x$ac_cv_func_dlopen" = xyes; then :
+  lt_cv_dlopen="dlopen"
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5
+$as_echo_n "checking for dlopen in -ldl... " >&6; }
+if ${ac_cv_lib_dl_dlopen+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-ldl  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char dlopen ();
+int
+main ()
+{
+return dlopen ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_dl_dlopen=yes
+else
+  ac_cv_lib_dl_dlopen=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dl_dlopen" >&5
+$as_echo "$ac_cv_lib_dl_dlopen" >&6; }
+if test "x$ac_cv_lib_dl_dlopen" = xyes; then :
+  lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl"
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -lsvld" >&5
+$as_echo_n "checking for dlopen in -lsvld... " >&6; }
+if ${ac_cv_lib_svld_dlopen+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lsvld  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char dlopen ();
+int
+main ()
+{
+return dlopen ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_svld_dlopen=yes
+else
+  ac_cv_lib_svld_dlopen=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_svld_dlopen" >&5
+$as_echo "$ac_cv_lib_svld_dlopen" >&6; }
+if test "x$ac_cv_lib_svld_dlopen" = xyes; then :
+  lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-lsvld"
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dld_link in -ldld" >&5
+$as_echo_n "checking for dld_link in -ldld... " >&6; }
+if ${ac_cv_lib_dld_dld_link+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-ldld  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char dld_link ();
+int
+main ()
+{
+return dld_link ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_dld_dld_link=yes
+else
+  ac_cv_lib_dld_dld_link=no
 fi
-
-if test "${lt_cv_sys_lib_search_path_spec+set}" = set; then
-  sys_lib_search_path_spec="$lt_cv_sys_lib_search_path_spec"
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
 fi
-if test "${lt_cv_sys_lib_dlsearch_path_spec+set}" = set; then
-  sys_lib_dlsearch_path_spec="$lt_cv_sys_lib_dlsearch_path_spec"
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dld_dld_link" >&5
+$as_echo "$ac_cv_lib_dld_dld_link" >&6; }
+if test "x$ac_cv_lib_dld_dld_link" = xyes; then :
+  lt_cv_dlopen="dld_link" lt_cv_dlopen_libs="-ldld"
+fi
+
+
 fi
 
 
+fi
 
 
+fi
 
 
+fi
 
 
+fi
 
+    ;;
+  esac
 
+  if test "x$lt_cv_dlopen" != xno; then
+    enable_dlopen=yes
+  else
+    enable_dlopen=no
+  fi
 
+  case $lt_cv_dlopen in
+  dlopen)
+    save_CPPFLAGS="$CPPFLAGS"
+    test "x$ac_cv_header_dlfcn_h" = xyes && CPPFLAGS="$CPPFLAGS -DHAVE_DLFCN_H"
 
+    save_LDFLAGS="$LDFLAGS"
+    wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $export_dynamic_flag_spec\"
 
+    save_LIBS="$LIBS"
+    LIBS="$lt_cv_dlopen_libs $LIBS"
 
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether a program can dlopen itself" >&5
+$as_echo_n "checking whether a program can dlopen itself... " >&6; }
+if ${lt_cv_dlopen_self+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+         if test "$cross_compiling" = yes; then :
+  lt_cv_dlopen_self=cross
+else
+  lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+  lt_status=$lt_dlunknown
+  cat > conftest.$ac_ext <<_LT_EOF
+#line $LINENO "configure"
+#include "confdefs.h"
 
+#if HAVE_DLFCN_H
+#include <dlfcn.h>
+#endif
 
+#include <stdio.h>
 
+#ifdef RTLD_GLOBAL
+#  define LT_DLGLOBAL          RTLD_GLOBAL
+#else
+#  ifdef DL_GLOBAL
+#    define LT_DLGLOBAL                DL_GLOBAL
+#  else
+#    define LT_DLGLOBAL                0
+#  endif
+#endif
 
+/* We may have to define LT_DLLAZY_OR_NOW in the command line if we
+   find out it does not work in some platform. */
+#ifndef LT_DLLAZY_OR_NOW
+#  ifdef RTLD_LAZY
+#    define LT_DLLAZY_OR_NOW           RTLD_LAZY
+#  else
+#    ifdef DL_LAZY
+#      define LT_DLLAZY_OR_NOW         DL_LAZY
+#    else
+#      ifdef RTLD_NOW
+#        define LT_DLLAZY_OR_NOW       RTLD_NOW
+#      else
+#        ifdef DL_NOW
+#          define LT_DLLAZY_OR_NOW     DL_NOW
+#        else
+#          define LT_DLLAZY_OR_NOW     0
+#        endif
+#      endif
+#    endif
+#  endif
+#endif
 
+/* When -fvisbility=hidden is used, assume the code has been annotated
+   correspondingly for the symbols needed.  */
+#if defined(__GNUC__) && (((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)) || (__GNUC__ > 3))
+int fnord () __attribute__((visibility("default")));
+#endif
 
+int fnord () { return 42; }
+int main ()
+{
+  void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW);
+  int status = $lt_dlunknown;
 
+  if (self)
+    {
+      if (dlsym (self,"fnord"))       status = $lt_dlno_uscore;
+      else
+        {
+         if (dlsym( self,"_fnord"))  status = $lt_dlneed_uscore;
+          else puts (dlerror ());
+       }
+      /* dlclose (self); */
+    }
+  else
+    puts (dlerror ());
 
+  return status;
+}
+_LT_EOF
+  if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_link\""; } >&5
+  (eval $ac_link) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; } && test -s conftest${ac_exeext} 2>/dev/null; then
+    (./conftest; exit; ) >&5 2>/dev/null
+    lt_status=$?
+    case x$lt_status in
+      x$lt_dlno_uscore) lt_cv_dlopen_self=yes ;;
+      x$lt_dlneed_uscore) lt_cv_dlopen_self=yes ;;
+      x$lt_dlunknown|x*) lt_cv_dlopen_self=no ;;
+    esac
+  else :
+    # compilation failed
+    lt_cv_dlopen_self=no
+  fi
+fi
+rm -fr conftest*
 
 
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_dlopen_self" >&5
+$as_echo "$lt_cv_dlopen_self" >&6; }
 
+    if test "x$lt_cv_dlopen_self" = xyes; then
+      wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $lt_prog_compiler_static\"
+      { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether a statically linked program can dlopen itself" >&5
+$as_echo_n "checking whether a statically linked program can dlopen itself... " >&6; }
+if ${lt_cv_dlopen_self_static+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+         if test "$cross_compiling" = yes; then :
+  lt_cv_dlopen_self_static=cross
+else
+  lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+  lt_status=$lt_dlunknown
+  cat > conftest.$ac_ext <<_LT_EOF
+#line $LINENO "configure"
+#include "confdefs.h"
 
+#if HAVE_DLFCN_H
+#include <dlfcn.h>
+#endif
 
+#include <stdio.h>
 
+#ifdef RTLD_GLOBAL
+#  define LT_DLGLOBAL          RTLD_GLOBAL
+#else
+#  ifdef DL_GLOBAL
+#    define LT_DLGLOBAL                DL_GLOBAL
+#  else
+#    define LT_DLGLOBAL                0
+#  endif
+#endif
 
+/* We may have to define LT_DLLAZY_OR_NOW in the command line if we
+   find out it does not work in some platform. */
+#ifndef LT_DLLAZY_OR_NOW
+#  ifdef RTLD_LAZY
+#    define LT_DLLAZY_OR_NOW           RTLD_LAZY
+#  else
+#    ifdef DL_LAZY
+#      define LT_DLLAZY_OR_NOW         DL_LAZY
+#    else
+#      ifdef RTLD_NOW
+#        define LT_DLLAZY_OR_NOW       RTLD_NOW
+#      else
+#        ifdef DL_NOW
+#          define LT_DLLAZY_OR_NOW     DL_NOW
+#        else
+#          define LT_DLLAZY_OR_NOW     0
+#        endif
+#      endif
+#    endif
+#  endif
+#endif
 
+/* When -fvisbility=hidden is used, assume the code has been annotated
+   correspondingly for the symbols needed.  */
+#if defined(__GNUC__) && (((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)) || (__GNUC__ > 3))
+int fnord () __attribute__((visibility("default")));
+#endif
 
+int fnord () { return 42; }
+int main ()
+{
+  void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW);
+  int status = $lt_dlunknown;
 
+  if (self)
+    {
+      if (dlsym (self,"fnord"))       status = $lt_dlno_uscore;
+      else
+        {
+         if (dlsym( self,"_fnord"))  status = $lt_dlneed_uscore;
+          else puts (dlerror ());
+       }
+      /* dlclose (self); */
+    }
+  else
+    puts (dlerror ());
 
+  return status;
+}
+_LT_EOF
+  if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_link\""; } >&5
+  (eval $ac_link) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; } && test -s conftest${ac_exeext} 2>/dev/null; then
+    (./conftest; exit; ) >&5 2>/dev/null
+    lt_status=$?
+    case x$lt_status in
+      x$lt_dlno_uscore) lt_cv_dlopen_self_static=yes ;;
+      x$lt_dlneed_uscore) lt_cv_dlopen_self_static=yes ;;
+      x$lt_dlunknown|x*) lt_cv_dlopen_self_static=no ;;
+    esac
+  else :
+    # compilation failed
+    lt_cv_dlopen_self_static=no
+  fi
+fi
+rm -fr conftest*
 
 
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_dlopen_self_static" >&5
+$as_echo "$lt_cv_dlopen_self_static" >&6; }
+    fi
 
+    CPPFLAGS="$save_CPPFLAGS"
+    LDFLAGS="$save_LDFLAGS"
+    LIBS="$save_LIBS"
+    ;;
+  esac
 
+  case $lt_cv_dlopen_self in
+  yes|no) enable_dlopen_self=$lt_cv_dlopen_self ;;
+  *) enable_dlopen_self=unknown ;;
+  esac
 
+  case $lt_cv_dlopen_self_static in
+  yes|no) enable_dlopen_self_static=$lt_cv_dlopen_self_static ;;
+  *) enable_dlopen_self_static=unknown ;;
+  esac
+fi
 
 
 
 
 
 
+striplib=
+old_striplib=
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether stripping libraries is possible" >&5
+$as_echo_n "checking whether stripping libraries is possible... " >&6; }
+if test -n "$STRIP" && $STRIP -V 2>&1 | $GREP "GNU strip" >/dev/null; then
+  test -z "$old_striplib" && old_striplib="$STRIP --strip-debug"
+  test -z "$striplib" && striplib="$STRIP --strip-unneeded"
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+else
+# FIXME - insert some real tests, host_os isn't really good enough
+  case $host_os in
+  darwin*)
+    if test -n "$STRIP" ; then
+      striplib="$STRIP -x"
+      old_striplib="$STRIP -S"
+      { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+    else
+      { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+    fi
+    ;;
+  *)
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+    ;;
+  esac
+fi
 
 
 
 
 
 
+  # Report which library types will actually be built
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking if libtool supports shared libraries" >&5
+$as_echo_n "checking if libtool supports shared libraries... " >&6; }
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $can_build_shared" >&5
+$as_echo "$can_build_shared" >&6; }
 
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to build shared libraries" >&5
+$as_echo_n "checking whether to build shared libraries... " >&6; }
+  test "$can_build_shared" = "no" && enable_shared=no
 
+  # On AIX, shared libraries and static libraries use the same namespace, and
+  # are all built from PIC.
+  case $host_os in
+  aix3*)
+    test "$enable_shared" = yes && enable_static=no
+    if test -n "$RANLIB"; then
+      archive_cmds="$archive_cmds~\$RANLIB \$lib"
+      postinstall_cmds='$RANLIB $lib'
+    fi
+    ;;
 
+  aix[4-9]*)
+    if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then
+      test "$enable_shared" = yes && enable_static=no
+    fi
+    ;;
+  esac
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_shared" >&5
+$as_echo "$enable_shared" >&6; }
 
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to build static libraries" >&5
+$as_echo_n "checking whether to build static libraries... " >&6; }
+  # Make sure either enable_shared or enable_static is yes.
+  test "$enable_shared" = yes || enable_static=yes
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_static" >&5
+$as_echo "$enable_static" >&6; }
 
 
 
 
+fi
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
 
+CC="$lt_save_CC"
 
 
 
 
 
 
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to hardcode library paths into programs" >&5
-$as_echo_n "checking how to hardcode library paths into programs... " >&6; }
-hardcode_action=
-if test -n "$hardcode_libdir_flag_spec" ||
-   test -n "$runpath_var" ||
-   test "X$hardcode_automatic" = "Xyes" ; then
 
-  # We can hardcode non-existent directories.
-  if test "$hardcode_direct" != no &&
-     # If the only mechanism to avoid hardcoding is shlibpath_var, we
-     # have to relink, otherwise we might link with an installed library
-     # when we should be linking with a yet-to-be-installed one
-     ## test "$_LT_TAGVAR(hardcode_shlibpath_var, )" != no &&
-     test "$hardcode_minus_L" != no; then
-    # Linking always hardcodes the temporary library directory.
-    hardcode_action=relink
-  else
-    # We can link without hardcoding, and we can hardcode nonexisting dirs.
-    hardcode_action=immediate
-  fi
-else
-  # We cannot hardcode anything, or else we can only hardcode existing
-  # directories.
-  hardcode_action=unsupported
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $hardcode_action" >&5
-$as_echo "$hardcode_action" >&6; }
 
-if test "$hardcode_action" = relink ||
-   test "$inherit_rpath" = yes; then
-  # Fast installation is not supported
-  enable_fast_install=no
-elif test "$shlibpath_overrides_runpath" = yes ||
-     test "$enable_shared" = no; then
-  # Fast installation is not necessary
-  enable_fast_install=needless
-fi
 
 
+        ac_config_commands="$ac_config_commands libtool"
 
 
 
 
-  if test "x$enable_dlopen" != xyes; then
-  enable_dlopen=unknown
-  enable_dlopen_self=unknown
-  enable_dlopen_self_static=unknown
-else
-  lt_cv_dlopen=no
-  lt_cv_dlopen_libs=
+# Only expand once:
 
-  case $host_os in
-  beos*)
-    lt_cv_dlopen="load_add_on"
-    lt_cv_dlopen_libs=
-    lt_cv_dlopen_self=yes
-    ;;
 
-  mingw* | pw32* | cegcc*)
-    lt_cv_dlopen="LoadLibrary"
-    lt_cv_dlopen_libs=
-    ;;
+# Check whether --enable-largefile was given.
+if test "${enable_largefile+set}" = set; then :
+  enableval=$enable_largefile;
+fi
 
-  cygwin*)
-    lt_cv_dlopen="dlopen"
-    lt_cv_dlopen_libs=
-    ;;
+if test "$enable_largefile" != no; then
 
-  darwin*)
-  # if libdl is installed we need to link against it
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5
-$as_echo_n "checking for dlopen in -ldl... " >&6; }
-if test "${ac_cv_lib_dl_dlopen+set}" = set; then :
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for special C compiler options needed for large files" >&5
+$as_echo_n "checking for special C compiler options needed for large files... " >&6; }
+if ${ac_cv_sys_largefile_CC+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  ac_check_lib_save_LIBS=$LIBS
-LIBS="-ldl  $LIBS"
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+  ac_cv_sys_largefile_CC=no
+     if test "$GCC" != yes; then
+       ac_save_CC=$CC
+       while :; do
+        # IRIX 6.2 and later do not support large files by default,
+        # so use the C compiler's -n32 option if that helps.
+        cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
-
-/* Override any GCC internal prototype to avoid an error.
-   Use char because int might match the return type of a GCC
-   builtin and then its argument prototype would still apply.  */
-#ifdef __cplusplus
-extern "C"
-#endif
-char dlopen ();
+#include <sys/types.h>
+ /* Check that off_t can represent 2**63 - 1 correctly.
+    We can't simply define LARGE_OFF_T to be 9223372036854775807,
+    since some C++ compilers masquerading as C compilers
+    incorrectly reject 9223372036854775807.  */
+#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
+  int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
+                      && LARGE_OFF_T % 2147483647 == 1)
+                     ? 1 : -1];
 int
 main ()
 {
-return dlopen ();
+
   ;
   return 0;
 }
 _ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
-  ac_cv_lib_dl_dlopen=yes
-else
-  ac_cv_lib_dl_dlopen=no
+        if ac_fn_c_try_compile "$LINENO"; then :
+  break
 fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
-LIBS=$ac_check_lib_save_LIBS
+rm -f core conftest.err conftest.$ac_objext
+        CC="$CC -n32"
+        if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_sys_largefile_CC=' -n32'; break
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dl_dlopen" >&5
-$as_echo "$ac_cv_lib_dl_dlopen" >&6; }
-if test "x$ac_cv_lib_dl_dlopen" = x""yes; then :
-  lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl"
-else
-
-    lt_cv_dlopen="dyld"
-    lt_cv_dlopen_libs=
-    lt_cv_dlopen_self=yes
-
+rm -f core conftest.err conftest.$ac_objext
+        break
+       done
+       CC=$ac_save_CC
+       rm -f conftest.$ac_ext
+    fi
 fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sys_largefile_CC" >&5
+$as_echo "$ac_cv_sys_largefile_CC" >&6; }
+  if test "$ac_cv_sys_largefile_CC" != no; then
+    CC=$CC$ac_cv_sys_largefile_CC
+  fi
 
-    ;;
-
-  *)
-    ac_fn_c_check_func "$LINENO" "shl_load" "ac_cv_func_shl_load"
-if test "x$ac_cv_func_shl_load" = x""yes; then :
-  lt_cv_dlopen="shl_load"
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for shl_load in -ldld" >&5
-$as_echo_n "checking for shl_load in -ldld... " >&6; }
-if test "${ac_cv_lib_dld_shl_load+set}" = set; then :
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for _FILE_OFFSET_BITS value needed for large files" >&5
+$as_echo_n "checking for _FILE_OFFSET_BITS value needed for large files... " >&6; }
+if ${ac_cv_sys_file_offset_bits+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  ac_check_lib_save_LIBS=$LIBS
-LIBS="-ldld  $LIBS"
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+  while :; do
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
-
-/* Override any GCC internal prototype to avoid an error.
-   Use char because int might match the return type of a GCC
-   builtin and then its argument prototype would still apply.  */
-#ifdef __cplusplus
-extern "C"
-#endif
-char shl_load ();
+#include <sys/types.h>
+ /* Check that off_t can represent 2**63 - 1 correctly.
+    We can't simply define LARGE_OFF_T to be 9223372036854775807,
+    since some C++ compilers masquerading as C compilers
+    incorrectly reject 9223372036854775807.  */
+#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
+  int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
+                      && LARGE_OFF_T % 2147483647 == 1)
+                     ? 1 : -1];
 int
 main ()
 {
-return shl_load ();
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
-  ac_cv_lib_dld_shl_load=yes
-else
-  ac_cv_lib_dld_shl_load=no
-fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
-LIBS=$ac_check_lib_save_LIBS
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dld_shl_load" >&5
-$as_echo "$ac_cv_lib_dld_shl_load" >&6; }
-if test "x$ac_cv_lib_dld_shl_load" = x""yes; then :
-  lt_cv_dlopen="shl_load" lt_cv_dlopen_libs="-ldld"
-else
-  ac_fn_c_check_func "$LINENO" "dlopen" "ac_cv_func_dlopen"
-if test "x$ac_cv_func_dlopen" = x""yes; then :
-  lt_cv_dlopen="dlopen"
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5
-$as_echo_n "checking for dlopen in -ldl... " >&6; }
-if test "${ac_cv_lib_dl_dlopen+set}" = set; then :
-  $as_echo_n "(cached) " >&6
-else
-  ac_check_lib_save_LIBS=$LIBS
-LIBS="-ldl  $LIBS"
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
 
-/* Override any GCC internal prototype to avoid an error.
-   Use char because int might match the return type of a GCC
-   builtin and then its argument prototype would still apply.  */
-#ifdef __cplusplus
-extern "C"
-#endif
-char dlopen ();
-int
-main ()
-{
-return dlopen ();
   ;
   return 0;
 }
 _ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
-  ac_cv_lib_dl_dlopen=yes
-else
-  ac_cv_lib_dl_dlopen=no
-fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
-LIBS=$ac_check_lib_save_LIBS
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_sys_file_offset_bits=no; break
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dl_dlopen" >&5
-$as_echo "$ac_cv_lib_dl_dlopen" >&6; }
-if test "x$ac_cv_lib_dl_dlopen" = x""yes; then :
-  lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl"
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -lsvld" >&5
-$as_echo_n "checking for dlopen in -lsvld... " >&6; }
-if test "${ac_cv_lib_svld_dlopen+set}" = set; then :
-  $as_echo_n "(cached) " >&6
-else
-  ac_check_lib_save_LIBS=$LIBS
-LIBS="-lsvld  $LIBS"
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
-
-/* Override any GCC internal prototype to avoid an error.
-   Use char because int might match the return type of a GCC
-   builtin and then its argument prototype would still apply.  */
-#ifdef __cplusplus
-extern "C"
-#endif
-char dlopen ();
+#define _FILE_OFFSET_BITS 64
+#include <sys/types.h>
+ /* Check that off_t can represent 2**63 - 1 correctly.
+    We can't simply define LARGE_OFF_T to be 9223372036854775807,
+    since some C++ compilers masquerading as C compilers
+    incorrectly reject 9223372036854775807.  */
+#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
+  int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
+                      && LARGE_OFF_T % 2147483647 == 1)
+                     ? 1 : -1];
 int
 main ()
 {
-return dlopen ();
+
   ;
   return 0;
 }
 _ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
-  ac_cv_lib_svld_dlopen=yes
-else
-  ac_cv_lib_svld_dlopen=no
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_sys_file_offset_bits=64; break
 fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
-LIBS=$ac_check_lib_save_LIBS
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+  ac_cv_sys_file_offset_bits=unknown
+  break
+done
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_svld_dlopen" >&5
-$as_echo "$ac_cv_lib_svld_dlopen" >&6; }
-if test "x$ac_cv_lib_svld_dlopen" = x""yes; then :
-  lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-lsvld"
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dld_link in -ldld" >&5
-$as_echo_n "checking for dld_link in -ldld... " >&6; }
-if test "${ac_cv_lib_dld_dld_link+set}" = set; then :
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sys_file_offset_bits" >&5
+$as_echo "$ac_cv_sys_file_offset_bits" >&6; }
+case $ac_cv_sys_file_offset_bits in #(
+  no | unknown) ;;
+  *)
+cat >>confdefs.h <<_ACEOF
+#define _FILE_OFFSET_BITS $ac_cv_sys_file_offset_bits
+_ACEOF
+;;
+esac
+rm -rf conftest*
+  if test $ac_cv_sys_file_offset_bits = unknown; then
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for _LARGE_FILES value needed for large files" >&5
+$as_echo_n "checking for _LARGE_FILES value needed for large files... " >&6; }
+if ${ac_cv_sys_large_files+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  ac_check_lib_save_LIBS=$LIBS
-LIBS="-ldld  $LIBS"
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+  while :; do
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
-
-/* Override any GCC internal prototype to avoid an error.
-   Use char because int might match the return type of a GCC
-   builtin and then its argument prototype would still apply.  */
-#ifdef __cplusplus
-extern "C"
-#endif
-char dld_link ();
+#include <sys/types.h>
+ /* Check that off_t can represent 2**63 - 1 correctly.
+    We can't simply define LARGE_OFF_T to be 9223372036854775807,
+    since some C++ compilers masquerading as C compilers
+    incorrectly reject 9223372036854775807.  */
+#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
+  int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
+                      && LARGE_OFF_T % 2147483647 == 1)
+                     ? 1 : -1];
 int
 main ()
 {
-return dld_link ();
+
   ;
   return 0;
 }
 _ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
-  ac_cv_lib_dld_dld_link=yes
-else
-  ac_cv_lib_dld_dld_link=no
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_sys_large_files=no; break
 fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
-LIBS=$ac_check_lib_save_LIBS
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#define _LARGE_FILES 1
+#include <sys/types.h>
+ /* Check that off_t can represent 2**63 - 1 correctly.
+    We can't simply define LARGE_OFF_T to be 9223372036854775807,
+    since some C++ compilers masquerading as C compilers
+    incorrectly reject 9223372036854775807.  */
+#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
+  int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
+                      && LARGE_OFF_T % 2147483647 == 1)
+                     ? 1 : -1];
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_sys_large_files=1; break
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dld_dld_link" >&5
-$as_echo "$ac_cv_lib_dld_dld_link" >&6; }
-if test "x$ac_cv_lib_dld_dld_link" = x""yes; then :
-  lt_cv_dlopen="dld_link" lt_cv_dlopen_libs="-ldld"
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+  ac_cv_sys_large_files=unknown
+  break
+done
 fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sys_large_files" >&5
+$as_echo "$ac_cv_sys_large_files" >&6; }
+case $ac_cv_sys_large_files in #(
+  no | unknown) ;;
+  *)
+cat >>confdefs.h <<_ACEOF
+#define _LARGE_FILES $ac_cv_sys_large_files
+_ACEOF
+;;
+esac
+rm -rf conftest*
+  fi
 
 
 fi
 
 
-fi
+# Are we in a git checkout?
+dot_git=no
+if test -e .git; then
 
+$as_echo "#define HAVE_DOT_GIT 1" >>confdefs.h
 
+       dot_git=yes
+fi
+ if test x$dot_git = xyes; then
+  HAVE_DOT_GIT_TRUE=
+  HAVE_DOT_GIT_FALSE='#'
+else
+  HAVE_DOT_GIT_TRUE='#'
+  HAVE_DOT_GIT_FALSE=
 fi
 
 
+# If so, we include the git description in our logs for sanity checking.
+#
+# However, for people not running their own drivers this is just noise.
+# So we copy the xserver's builderstring idiom to allow for this to be
+# overridden and perhaps replaced with something more useful.
+
+# Check whether --with-builderstring was given.
+if test "${with_builderstring+set}" = set; then :
+  withval=$with_builderstring; BUILDERSTRING="$withval"
+else
+  BUILDERSTRING="x-magic-git-describe"
 fi
 
 
-fi
+if test "x$BUILDERSTRING" = xx-magic-git-describe -a x$dot_git = xyes; then
 
-    ;;
-  esac
+$as_echo "#define USE_GIT_DESCRIBE 1" >>confdefs.h
+
+else
+  if test "x$BUILDERSTRING" != x -a "x$BUILDERSTRING" != xno -a "x$BUILDERSTRING" != xx-magic-git-describe; then
+
+cat >>confdefs.h <<_ACEOF
+#define BUILDER_DESCRIPTION "$BUILDERSTRING"
+_ACEOF
 
-  if test "x$lt_cv_dlopen" != xno; then
-    enable_dlopen=yes
-  else
-    enable_dlopen=no
   fi
+fi
 
-  case $lt_cv_dlopen in
-  dlopen)
-    save_CPPFLAGS="$CPPFLAGS"
-    test "x$ac_cv_header_dlfcn_h" = xyes && CPPFLAGS="$CPPFLAGS -DHAVE_DLFCN_H"
 
-    save_LDFLAGS="$LDFLAGS"
-    wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $export_dynamic_flag_spec\"
 
-    save_LIBS="$LIBS"
-    LIBS="$lt_cv_dlopen_libs $LIBS"
+pkg_failed=no
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for GEN4ASM" >&5
+$as_echo_n "checking for GEN4ASM... " >&6; }
 
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether a program can dlopen itself" >&5
-$as_echo_n "checking whether a program can dlopen itself... " >&6; }
-if test "${lt_cv_dlopen_self+set}" = set; then :
-  $as_echo_n "(cached) " >&6
+if test -n "$GEN4ASM_CFLAGS"; then
+    pkg_cv_GEN4ASM_CFLAGS="$GEN4ASM_CFLAGS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"intel-gen4asm >= 1.2\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "intel-gen4asm >= 1.2") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_GEN4ASM_CFLAGS=`$PKG_CONFIG --cflags "intel-gen4asm >= 1.2" 2>/dev/null`
+                     test "x$?" != "x0" && pkg_failed=yes
 else
-         if test "$cross_compiling" = yes; then :
-  lt_cv_dlopen_self=cross
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+if test -n "$GEN4ASM_LIBS"; then
+    pkg_cv_GEN4ASM_LIBS="$GEN4ASM_LIBS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"intel-gen4asm >= 1.2\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "intel-gen4asm >= 1.2") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_GEN4ASM_LIBS=`$PKG_CONFIG --libs "intel-gen4asm >= 1.2" 2>/dev/null`
+                     test "x$?" != "x0" && pkg_failed=yes
 else
-  lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
-  lt_status=$lt_dlunknown
-  cat > conftest.$ac_ext <<_LT_EOF
-#line 10801 "configure"
-#include "confdefs.h"
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
 
-#if HAVE_DLFCN_H
-#include <dlfcn.h>
-#endif
 
-#include <stdio.h>
 
-#ifdef RTLD_GLOBAL
-#  define LT_DLGLOBAL          RTLD_GLOBAL
-#else
-#  ifdef DL_GLOBAL
-#    define LT_DLGLOBAL                DL_GLOBAL
-#  else
-#    define LT_DLGLOBAL                0
-#  endif
-#endif
+if test $pkg_failed = yes; then
+       { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
 
-/* We may have to define LT_DLLAZY_OR_NOW in the command line if we
-   find out it does not work in some platform. */
-#ifndef LT_DLLAZY_OR_NOW
-#  ifdef RTLD_LAZY
-#    define LT_DLLAZY_OR_NOW           RTLD_LAZY
-#  else
-#    ifdef DL_LAZY
-#      define LT_DLLAZY_OR_NOW         DL_LAZY
-#    else
-#      ifdef RTLD_NOW
-#        define LT_DLLAZY_OR_NOW       RTLD_NOW
-#      else
-#        ifdef DL_NOW
-#          define LT_DLLAZY_OR_NOW     DL_NOW
-#        else
-#          define LT_DLLAZY_OR_NOW     0
-#        endif
-#      endif
-#    endif
-#  endif
-#endif
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
+        _pkg_short_errors_supported=yes
+else
+        _pkg_short_errors_supported=no
+fi
+        if test $_pkg_short_errors_supported = yes; then
+               GEN4ASM_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "intel-gen4asm >= 1.2" 2>&1`
+        else
+               GEN4ASM_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "intel-gen4asm >= 1.2" 2>&1`
+        fi
+       # Put the nasty error message in config.log where it belongs
+       echo "$GEN4ASM_PKG_ERRORS" >&5
 
-void fnord() { int i=42;}
-int main ()
-{
-  void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW);
-  int status = $lt_dlunknown;
+       gen4asm=no
+elif test $pkg_failed = untried; then
+       { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+       gen4asm=no
+else
+       GEN4ASM_CFLAGS=$pkg_cv_GEN4ASM_CFLAGS
+       GEN4ASM_LIBS=$pkg_cv_GEN4ASM_LIBS
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+       gen4asm=yes
+fi
+ if test x$gen4asm = xyes; then
+  HAVE_GEN4ASM_TRUE=
+  HAVE_GEN4ASM_FALSE='#'
+else
+  HAVE_GEN4ASM_TRUE='#'
+  HAVE_GEN4ASM_FALSE=
+fi
 
-  if (self)
-    {
-      if (dlsym (self,"fnord"))       status = $lt_dlno_uscore;
-      else if (dlsym( self,"_fnord")) status = $lt_dlneed_uscore;
-      /* dlclose (self); */
-    }
-  else
-    puts (dlerror ());
 
-  return status;
-}
-_LT_EOF
-  if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_link\""; } >&5
-  (eval $ac_link) 2>&5
-  ac_status=$?
-  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
-  test $ac_status = 0; } && test -s conftest${ac_exeext} 2>/dev/null; then
-    (./conftest; exit; ) >&5 2>/dev/null
-    lt_status=$?
-    case x$lt_status in
-      x$lt_dlno_uscore) lt_cv_dlopen_self=yes ;;
-      x$lt_dlneed_uscore) lt_cv_dlopen_self=yes ;;
-      x$lt_dlunknown|x*) lt_cv_dlopen_self=no ;;
-    esac
-  else :
-    # compilation failed
-    lt_cv_dlopen_self=no
-  fi
+# Check whether --enable-udev was given.
+if test "${enable_udev+set}" = set; then :
+  enableval=$enable_udev; UDEV="$enableval"
+else
+  UDEV=auto
 fi
-rm -fr conftest*
 
 
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_dlopen_self" >&5
-$as_echo "$lt_cv_dlopen_self" >&6; }
+if test x$UDEV != "xno"; then
 
-    if test "x$lt_cv_dlopen_self" = xyes; then
-      wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $lt_prog_compiler_static\"
-      { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether a statically linked program can dlopen itself" >&5
-$as_echo_n "checking whether a statically linked program can dlopen itself... " >&6; }
-if test "${lt_cv_dlopen_self_static+set}" = set; then :
-  $as_echo_n "(cached) " >&6
+pkg_failed=no
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for UDEV" >&5
+$as_echo_n "checking for UDEV... " >&6; }
+
+if test -n "$UDEV_CFLAGS"; then
+    pkg_cv_UDEV_CFLAGS="$UDEV_CFLAGS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libudev\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "libudev") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_UDEV_CFLAGS=`$PKG_CONFIG --cflags "libudev" 2>/dev/null`
+                     test "x$?" != "x0" && pkg_failed=yes
 else
-         if test "$cross_compiling" = yes; then :
-  lt_cv_dlopen_self_static=cross
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+if test -n "$UDEV_LIBS"; then
+    pkg_cv_UDEV_LIBS="$UDEV_LIBS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libudev\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "libudev") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_UDEV_LIBS=`$PKG_CONFIG --libs "libudev" 2>/dev/null`
+                     test "x$?" != "x0" && pkg_failed=yes
 else
-  lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
-  lt_status=$lt_dlunknown
-  cat > conftest.$ac_ext <<_LT_EOF
-#line 10897 "configure"
-#include "confdefs.h"
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
 
-#if HAVE_DLFCN_H
-#include <dlfcn.h>
-#endif
 
-#include <stdio.h>
 
-#ifdef RTLD_GLOBAL
-#  define LT_DLGLOBAL          RTLD_GLOBAL
-#else
-#  ifdef DL_GLOBAL
-#    define LT_DLGLOBAL                DL_GLOBAL
-#  else
-#    define LT_DLGLOBAL                0
-#  endif
-#endif
+if test $pkg_failed = yes; then
+       { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
 
-/* We may have to define LT_DLLAZY_OR_NOW in the command line if we
-   find out it does not work in some platform. */
-#ifndef LT_DLLAZY_OR_NOW
-#  ifdef RTLD_LAZY
-#    define LT_DLLAZY_OR_NOW           RTLD_LAZY
-#  else
-#    ifdef DL_LAZY
-#      define LT_DLLAZY_OR_NOW         DL_LAZY
-#    else
-#      ifdef RTLD_NOW
-#        define LT_DLLAZY_OR_NOW       RTLD_NOW
-#      else
-#        ifdef DL_NOW
-#          define LT_DLLAZY_OR_NOW     DL_NOW
-#        else
-#          define LT_DLLAZY_OR_NOW     0
-#        endif
-#      endif
-#    endif
-#  endif
-#endif
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
+        _pkg_short_errors_supported=yes
+else
+        _pkg_short_errors_supported=no
+fi
+        if test $_pkg_short_errors_supported = yes; then
+               UDEV_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "libudev" 2>&1`
+        else
+               UDEV_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "libudev" 2>&1`
+        fi
+       # Put the nasty error message in config.log where it belongs
+       echo "$UDEV_PKG_ERRORS" >&5
 
-void fnord() { int i=42;}
-int main ()
-{
-  void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW);
-  int status = $lt_dlunknown;
+       udev=no
+elif test $pkg_failed = untried; then
+       { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+       udev=no
+else
+       UDEV_CFLAGS=$pkg_cv_UDEV_CFLAGS
+       UDEV_LIBS=$pkg_cv_UDEV_LIBS
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+       udev=yes
+fi
+       if test x$UDEV == xyes -a x$udev != xyes; then
+               as_fn_error $? "udev support requested but not found (libudev)" "$LINENO" 5
+       fi
+       if test x$udev = xyes; then
 
-  if (self)
-    {
-      if (dlsym (self,"fnord"))       status = $lt_dlno_uscore;
-      else if (dlsym( self,"_fnord")) status = $lt_dlneed_uscore;
-      /* dlclose (self); */
-    }
-  else
-    puts (dlerror ());
+$as_echo "#define HAVE_UDEV 1" >>confdefs.h
 
-  return status;
-}
-_LT_EOF
-  if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_link\""; } >&5
-  (eval $ac_link) 2>&5
+       fi
+fi
+
+
+pkg_failed=no
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for X11" >&5
+$as_echo_n "checking for X11... " >&6; }
+
+if test -n "$X11_CFLAGS"; then
+    pkg_cv_X11_CFLAGS="$X11_CFLAGS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"x11 xrender xext pixman-1\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "x11 xrender xext pixman-1") 2>&5
   ac_status=$?
   $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
-  test $ac_status = 0; } && test -s conftest${ac_exeext} 2>/dev/null; then
-    (./conftest; exit; ) >&5 2>/dev/null
-    lt_status=$?
-    case x$lt_status in
-      x$lt_dlno_uscore) lt_cv_dlopen_self_static=yes ;;
-      x$lt_dlneed_uscore) lt_cv_dlopen_self_static=yes ;;
-      x$lt_dlunknown|x*) lt_cv_dlopen_self_static=no ;;
-    esac
-  else :
-    # compilation failed
-    lt_cv_dlopen_self_static=no
-  fi
+  test $ac_status = 0; }; then
+  pkg_cv_X11_CFLAGS=`$PKG_CONFIG --cflags "x11 xrender xext pixman-1" 2>/dev/null`
+                     test "x$?" != "x0" && pkg_failed=yes
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+if test -n "$X11_LIBS"; then
+    pkg_cv_X11_LIBS="$X11_LIBS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"x11 xrender xext pixman-1\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "x11 xrender xext pixman-1") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_X11_LIBS=`$PKG_CONFIG --libs "x11 xrender xext pixman-1" 2>/dev/null`
+                     test "x$?" != "x0" && pkg_failed=yes
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
 fi
-rm -fr conftest*
 
 
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_dlopen_self_static" >&5
-$as_echo "$lt_cv_dlopen_self_static" >&6; }
-    fi
 
-    CPPFLAGS="$save_CPPFLAGS"
-    LDFLAGS="$save_LDFLAGS"
-    LIBS="$save_LIBS"
-    ;;
-  esac
+if test $pkg_failed = yes; then
+       { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
 
-  case $lt_cv_dlopen_self in
-  yes|no) enable_dlopen_self=$lt_cv_dlopen_self ;;
-  *) enable_dlopen_self=unknown ;;
-  esac
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
+        _pkg_short_errors_supported=yes
+else
+        _pkg_short_errors_supported=no
+fi
+        if test $_pkg_short_errors_supported = yes; then
+               X11_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "x11 xrender xext pixman-1" 2>&1`
+        else
+               X11_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "x11 xrender xext pixman-1" 2>&1`
+        fi
+       # Put the nasty error message in config.log where it belongs
+       echo "$X11_PKG_ERRORS" >&5
 
-  case $lt_cv_dlopen_self_static in
-  yes|no) enable_dlopen_self_static=$lt_cv_dlopen_self_static ;;
-  *) enable_dlopen_self_static=unknown ;;
-  esac
+       x11=no
+elif test $pkg_failed = untried; then
+       { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+       x11=no
+else
+       X11_CFLAGS=$pkg_cv_X11_CFLAGS
+       X11_LIBS=$pkg_cv_X11_LIBS
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+       x11=yes
+fi
+ if test x$x11 = xyes; then
+  HAVE_X11_TRUE=
+  HAVE_X11_FALSE='#'
+else
+  HAVE_X11_TRUE='#'
+  HAVE_X11_FALSE=
 fi
 
 
 
 
+# Define a configure option for an alternate module directory
+
+# Check whether --with-xorg-module-dir was given.
+if test "${with_xorg_module_dir+set}" = set; then :
+  withval=$with_xorg_module_dir; moduledir="$withval"
+else
+  moduledir="$libdir/xorg/modules"
+fi
 
 
+# Check whether --enable-dri was given.
+if test "${enable_dri+set}" = set; then :
+  enableval=$enable_dri;
+fi
 
 
+# Check whether --enable-xvmc was given.
+if test "${enable_xvmc+set}" = set; then :
+  enableval=$enable_xvmc; XVMC="$enableval"
+else
+  XVMC=yes
+fi
 
 
+# Check whether --enable-kms-only was given.
+if test "${enable_kms_only+set}" = set; then :
+  enableval=$enable_kms_only; KMS_ONLY="$enableval"
+else
+  KMS_ONLY=no
+fi
 
+# Check whether --enable-ums-only was given.
+if test "${enable_ums_only+set}" = set; then :
+  enableval=$enable_ums_only; UMS_ONLY="$enableval"
+else
+  UMS_ONLY=no
+fi
 
 
+required_xorg_xserver_version=1.6
+required_pixman_version=0.24
 
+if pkg-config --exists 'pixman-1 >= 0.27.1'; then
 
+$as_echo "#define HAS_PIXMAN_GLYPHS 1" >>confdefs.h
 
+fi
 
-striplib=
-old_striplib=
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether stripping libraries is possible" >&5
-$as_echo_n "checking whether stripping libraries is possible... " >&6; }
-if test -n "$STRIP" && $STRIP -V 2>&1 | $GREP "GNU strip" >/dev/null; then
-  test -z "$old_striplib" && old_striplib="$STRIP --strip-debug"
-  test -z "$striplib" && striplib="$STRIP --strip-unneeded"
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
-$as_echo "yes" >&6; }
+# Check whether --enable-sna was given.
+if test "${enable_sna+set}" = set; then :
+  enableval=$enable_sna; SNA="$enableval"
 else
-# FIXME - insert some real tests, host_os isn't really good enough
-  case $host_os in
-  darwin*)
-    if test -n "$STRIP" ; then
-      striplib="$STRIP -x"
-      old_striplib="$STRIP -S"
-      { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
-$as_echo "yes" >&6; }
-    else
-      { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-    fi
-    ;;
-  *)
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-    ;;
-  esac
+  SNA=auto
 fi
 
 
+for ac_header in sys/sysinfo.h
+do :
+  ac_fn_c_check_header_mongrel "$LINENO" "sys/sysinfo.h" "ac_cv_header_sys_sysinfo_h" "$ac_includes_default"
+if test "x$ac_cv_header_sys_sysinfo_h" = xyes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_SYS_SYSINFO_H 1
+_ACEOF
 
+else
+  SNA=no
+fi
 
+done
 
+if test "x$SNA" = "xauto" && pkg-config --exists "xorg-server >= 1.10"; then
+       SNA=yes
+fi
+if test "x$SNA" != "xno"; then
+       required_xorg_xserver_version=1.10
 
+$as_echo "#define USE_SNA 1" >>confdefs.h
 
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to include SNA support" >&5
+$as_echo_n "checking whether to include SNA support... " >&6; }
+ if test x$SNA != xno; then
+  SNA_TRUE=
+  SNA_FALSE='#'
+else
+  SNA_TRUE='#'
+  SNA_FALSE=
+fi
 
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $SNA" >&5
+$as_echo "$SNA" >&6; }
 
+# Check whether --enable-uxa was given.
+if test "${enable_uxa+set}" = set; then :
+  enableval=$enable_uxa; UXA="$enableval"
+else
+  UXA=yes
+fi
 
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to include UXA support" >&5
+$as_echo_n "checking whether to include UXA support... " >&6; }
+ if test x$UXA != xno; then
+  UXA_TRUE=
+  UXA_FALSE='#'
+else
+  UXA_TRUE='#'
+  UXA_FALSE=
+fi
 
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $UXA" >&5
+$as_echo "$UXA" >&6; }
+if test "x$UXA" != "xno"; then
 
-  # Report which library types will actually be built
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking if libtool supports shared libraries" >&5
-$as_echo_n "checking if libtool supports shared libraries... " >&6; }
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $can_build_shared" >&5
-$as_echo "$can_build_shared" >&6; }
+$as_echo "#define USE_UXA 1" >>confdefs.h
 
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to build shared libraries" >&5
-$as_echo_n "checking whether to build shared libraries... " >&6; }
-  test "$can_build_shared" = "no" && enable_shared=no
 
-  # On AIX, shared libraries and static libraries use the same namespace, and
-  # are all built from PIC.
-  case $host_os in
-  aix3*)
-    test "$enable_shared" = yes && enable_static=no
-    if test -n "$RANLIB"; then
-      archive_cmds="$archive_cmds~\$RANLIB \$lib"
-      postinstall_cmds='$RANLIB $lib'
-    fi
-    ;;
+pkg_failed=no
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for DRMINTEL" >&5
+$as_echo_n "checking for DRMINTEL... " >&6; }
+
+if test -n "$DRMINTEL_CFLAGS"; then
+    pkg_cv_DRMINTEL_CFLAGS="$DRMINTEL_CFLAGS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libdrm_intel >= 2.4.29\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "libdrm_intel >= 2.4.29") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_DRMINTEL_CFLAGS=`$PKG_CONFIG --cflags "libdrm_intel >= 2.4.29" 2>/dev/null`
+                     test "x$?" != "x0" && pkg_failed=yes
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+if test -n "$DRMINTEL_LIBS"; then
+    pkg_cv_DRMINTEL_LIBS="$DRMINTEL_LIBS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libdrm_intel >= 2.4.29\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "libdrm_intel >= 2.4.29") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_DRMINTEL_LIBS=`$PKG_CONFIG --libs "libdrm_intel >= 2.4.29" 2>/dev/null`
+                     test "x$?" != "x0" && pkg_failed=yes
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
 
-  aix[4-9]*)
-    if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then
-      test "$enable_shared" = yes && enable_static=no
-    fi
-    ;;
-  esac
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_shared" >&5
-$as_echo "$enable_shared" >&6; }
 
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to build static libraries" >&5
-$as_echo_n "checking whether to build static libraries... " >&6; }
-  # Make sure either enable_shared or enable_static is yes.
-  test "$enable_shared" = yes || enable_static=yes
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_static" >&5
-$as_echo "$enable_static" >&6; }
 
+if test $pkg_failed = yes; then
+       { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
 
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
+        _pkg_short_errors_supported=yes
+else
+        _pkg_short_errors_supported=no
+fi
+        if test $_pkg_short_errors_supported = yes; then
+               DRMINTEL_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "libdrm_intel >= 2.4.29" 2>&1`
+        else
+               DRMINTEL_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "libdrm_intel >= 2.4.29" 2>&1`
+        fi
+       # Put the nasty error message in config.log where it belongs
+       echo "$DRMINTEL_PKG_ERRORS" >&5
 
+       as_fn_error $? "Package requirements (libdrm_intel >= 2.4.29) were not met:
 
-fi
-ac_ext=c
-ac_cpp='$CPP $CPPFLAGS'
-ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
-ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
-ac_compiler_gnu=$ac_cv_c_compiler_gnu
+$DRMINTEL_PKG_ERRORS
 
-CC="$lt_save_CC"
+Consider adjusting the PKG_CONFIG_PATH environment variable if you
+installed software in a non-standard prefix.
 
+Alternatively, you may set the environment variables DRMINTEL_CFLAGS
+and DRMINTEL_LIBS to avoid the need to call pkg-config.
+See the pkg-config man page for more details." "$LINENO" 5
+elif test $pkg_failed = untried; then
+       { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+       { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "The pkg-config script could not be found or is too old.  Make sure it
+is in your PATH or set the PKG_CONFIG environment variable to the full
+path to pkg-config.
 
+Alternatively, you may set the environment variables DRMINTEL_CFLAGS
+and DRMINTEL_LIBS to avoid the need to call pkg-config.
+See the pkg-config man page for more details.
 
+To get pkg-config, see <http://pkg-config.freedesktop.org/>.
+See \`config.log' for more details" "$LINENO" 5; }
+else
+       DRMINTEL_CFLAGS=$pkg_cv_DRMINTEL_CFLAGS
+       DRMINTEL_LIBS=$pkg_cv_DRMINTEL_LIBS
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
 
+fi
+fi
 
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to include GLAMOR support" >&5
+$as_echo_n "checking whether to include GLAMOR support... " >&6; }
+# Check whether --enable-glamor was given.
+if test "${enable_glamor+set}" = set; then :
+  enableval=$enable_glamor; GLAMOR="$enableval"
+else
+  GLAMOR=no
+fi
 
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $GLAMOR" >&5
+$as_echo "$GLAMOR" >&6; }
+ if test x$GLAMOR != xno; then
+  GLAMOR_TRUE=
+  GLAMOR_FALSE='#'
+else
+  GLAMOR_TRUE='#'
+  GLAMOR_FALSE=
+fi
 
+if test "x$GLAMOR" != "xno"; then
 
+pkg_failed=no
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for LIBGLAMOR" >&5
+$as_echo_n "checking for LIBGLAMOR... " >&6; }
 
+if test -n "$LIBGLAMOR_CFLAGS"; then
+    pkg_cv_LIBGLAMOR_CFLAGS="$LIBGLAMOR_CFLAGS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"glamor >= 0.3.1\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "glamor >= 0.3.1") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_LIBGLAMOR_CFLAGS=`$PKG_CONFIG --cflags "glamor >= 0.3.1" 2>/dev/null`
+                     test "x$?" != "x0" && pkg_failed=yes
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+if test -n "$LIBGLAMOR_LIBS"; then
+    pkg_cv_LIBGLAMOR_LIBS="$LIBGLAMOR_LIBS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"glamor >= 0.3.1\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "glamor >= 0.3.1") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_LIBGLAMOR_LIBS=`$PKG_CONFIG --libs "glamor >= 0.3.1" 2>/dev/null`
+                     test "x$?" != "x0" && pkg_failed=yes
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
 
 
 
+if test $pkg_failed = yes; then
+       { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
 
-        ac_config_commands="$ac_config_commands libtool"
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
+        _pkg_short_errors_supported=yes
+else
+        _pkg_short_errors_supported=no
+fi
+        if test $_pkg_short_errors_supported = yes; then
+               LIBGLAMOR_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "glamor >= 0.3.1" 2>&1`
+        else
+               LIBGLAMOR_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "glamor >= 0.3.1" 2>&1`
+        fi
+       # Put the nasty error message in config.log where it belongs
+       echo "$LIBGLAMOR_PKG_ERRORS" >&5
 
+       as_fn_error $? "Package requirements (glamor >= 0.3.1) were not met:
 
+$LIBGLAMOR_PKG_ERRORS
 
+Consider adjusting the PKG_CONFIG_PATH environment variable if you
+installed software in a non-standard prefix.
 
-# Only expand once:
+Alternatively, you may set the environment variables LIBGLAMOR_CFLAGS
+and LIBGLAMOR_LIBS to avoid the need to call pkg-config.
+See the pkg-config man page for more details." "$LINENO" 5
+elif test $pkg_failed = untried; then
+       { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+       { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "The pkg-config script could not be found or is too old.  Make sure it
+is in your PATH or set the PKG_CONFIG environment variable to the full
+path to pkg-config.
 
+Alternatively, you may set the environment variables LIBGLAMOR_CFLAGS
+and LIBGLAMOR_LIBS to avoid the need to call pkg-config.
+See the pkg-config man page for more details.
 
+To get pkg-config, see <http://pkg-config.freedesktop.org/>.
+See \`config.log' for more details" "$LINENO" 5; }
+else
+       LIBGLAMOR_CFLAGS=$pkg_cv_LIBGLAMOR_CFLAGS
+       LIBGLAMOR_LIBS=$pkg_cv_LIBGLAMOR_LIBS
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
 
+fi
 
 pkg_failed=no
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for GEN4ASM" >&5
-$as_echo_n "checking for GEN4ASM... " >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for LIBGLAMOR_EGL" >&5
+$as_echo_n "checking for LIBGLAMOR_EGL... " >&6; }
 
-if test -n "$GEN4ASM_CFLAGS"; then
-    pkg_cv_GEN4ASM_CFLAGS="$GEN4ASM_CFLAGS"
+if test -n "$LIBGLAMOR_EGL_CFLAGS"; then
+    pkg_cv_LIBGLAMOR_EGL_CFLAGS="$LIBGLAMOR_EGL_CFLAGS"
  elif test -n "$PKG_CONFIG"; then
     if test -n "$PKG_CONFIG" && \
-    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"intel-gen4asm >= 1.1\""; } >&5
-  ($PKG_CONFIG --exists --print-errors "intel-gen4asm >= 1.1") 2>&5
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"glamor-egl\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "glamor-egl") 2>&5
   ac_status=$?
   $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
   test $ac_status = 0; }; then
-  pkg_cv_GEN4ASM_CFLAGS=`$PKG_CONFIG --cflags "intel-gen4asm >= 1.1" 2>/dev/null`
+  pkg_cv_LIBGLAMOR_EGL_CFLAGS=`$PKG_CONFIG --cflags "glamor-egl" 2>/dev/null`
+                     test "x$?" != "x0" && pkg_failed=yes
 else
   pkg_failed=yes
 fi
  else
     pkg_failed=untried
 fi
-if test -n "$GEN4ASM_LIBS"; then
-    pkg_cv_GEN4ASM_LIBS="$GEN4ASM_LIBS"
+if test -n "$LIBGLAMOR_EGL_LIBS"; then
+    pkg_cv_LIBGLAMOR_EGL_LIBS="$LIBGLAMOR_EGL_LIBS"
  elif test -n "$PKG_CONFIG"; then
     if test -n "$PKG_CONFIG" && \
-    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"intel-gen4asm >= 1.1\""; } >&5
-  ($PKG_CONFIG --exists --print-errors "intel-gen4asm >= 1.1") 2>&5
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"glamor-egl\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "glamor-egl") 2>&5
   ac_status=$?
   $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
   test $ac_status = 0; }; then
-  pkg_cv_GEN4ASM_LIBS=`$PKG_CONFIG --libs "intel-gen4asm >= 1.1" 2>/dev/null`
+  pkg_cv_LIBGLAMOR_EGL_LIBS=`$PKG_CONFIG --libs "glamor-egl" 2>/dev/null`
+                     test "x$?" != "x0" && pkg_failed=yes
 else
   pkg_failed=yes
 fi
@@ -11172,65 +18776,84 @@ else
         _pkg_short_errors_supported=no
 fi
         if test $_pkg_short_errors_supported = yes; then
-               GEN4ASM_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "intel-gen4asm >= 1.1" 2>&1`
+               LIBGLAMOR_EGL_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "glamor-egl" 2>&1`
         else
-               GEN4ASM_PKG_ERRORS=`$PKG_CONFIG --print-errors "intel-gen4asm >= 1.1" 2>&1`
+               LIBGLAMOR_EGL_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "glamor-egl" 2>&1`
         fi
        # Put the nasty error message in config.log where it belongs
-       echo "$GEN4ASM_PKG_ERRORS" >&5
+       echo "$LIBGLAMOR_EGL_PKG_ERRORS" >&5
 
-       gen4asm=no
+       as_fn_error $? "Package requirements (glamor-egl) were not met:
+
+$LIBGLAMOR_EGL_PKG_ERRORS
+
+Consider adjusting the PKG_CONFIG_PATH environment variable if you
+installed software in a non-standard prefix.
+
+Alternatively, you may set the environment variables LIBGLAMOR_EGL_CFLAGS
+and LIBGLAMOR_EGL_LIBS to avoid the need to call pkg-config.
+See the pkg-config man page for more details." "$LINENO" 5
 elif test $pkg_failed = untried; then
        { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
-       gen4asm=no
+       { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "The pkg-config script could not be found or is too old.  Make sure it
+is in your PATH or set the PKG_CONFIG environment variable to the full
+path to pkg-config.
+
+Alternatively, you may set the environment variables LIBGLAMOR_EGL_CFLAGS
+and LIBGLAMOR_EGL_LIBS to avoid the need to call pkg-config.
+See the pkg-config man page for more details.
+
+To get pkg-config, see <http://pkg-config.freedesktop.org/>.
+See \`config.log' for more details" "$LINENO" 5; }
 else
-       GEN4ASM_CFLAGS=$pkg_cv_GEN4ASM_CFLAGS
-       GEN4ASM_LIBS=$pkg_cv_GEN4ASM_LIBS
+       LIBGLAMOR_EGL_CFLAGS=$pkg_cv_LIBGLAMOR_EGL_CFLAGS
+       LIBGLAMOR_EGL_LIBS=$pkg_cv_LIBGLAMOR_EGL_LIBS
         { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
 $as_echo "yes" >&6; }
-       gen4asm=yes
+
 fi
- if test x$gen4asm = xyes; then
-  HAVE_GEN4ASM_TRUE=
-  HAVE_GEN4ASM_FALSE='#'
-else
-  HAVE_GEN4ASM_TRUE='#'
-  HAVE_GEN4ASM_FALSE=
+
+$as_echo "#define USE_GLAMOR 1" >>confdefs.h
+
 fi
 
 
 
 pkg_failed=no
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for UDEV" >&5
-$as_echo_n "checking for UDEV... " >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for XORG" >&5
+$as_echo_n "checking for XORG... " >&6; }
 
-if test -n "$UDEV_CFLAGS"; then
-    pkg_cv_UDEV_CFLAGS="$UDEV_CFLAGS"
+if test -n "$XORG_CFLAGS"; then
+    pkg_cv_XORG_CFLAGS="$XORG_CFLAGS"
  elif test -n "$PKG_CONFIG"; then
     if test -n "$PKG_CONFIG" && \
-    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libudev\""; } >&5
-  ($PKG_CONFIG --exists --print-errors "libudev") 2>&5
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"xorg-server >= \$required_xorg_xserver_version xproto fontsproto pixman-1 >= \$required_pixman_version \$REQUIRED_MODULES\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "xorg-server >= $required_xorg_xserver_version xproto fontsproto pixman-1 >= $required_pixman_version $REQUIRED_MODULES") 2>&5
   ac_status=$?
   $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
   test $ac_status = 0; }; then
-  pkg_cv_UDEV_CFLAGS=`$PKG_CONFIG --cflags "libudev" 2>/dev/null`
+  pkg_cv_XORG_CFLAGS=`$PKG_CONFIG --cflags "xorg-server >= $required_xorg_xserver_version xproto fontsproto pixman-1 >= $required_pixman_version $REQUIRED_MODULES" 2>/dev/null`
+                     test "x$?" != "x0" && pkg_failed=yes
 else
   pkg_failed=yes
 fi
  else
     pkg_failed=untried
 fi
-if test -n "$UDEV_LIBS"; then
-    pkg_cv_UDEV_LIBS="$UDEV_LIBS"
+if test -n "$XORG_LIBS"; then
+    pkg_cv_XORG_LIBS="$XORG_LIBS"
  elif test -n "$PKG_CONFIG"; then
     if test -n "$PKG_CONFIG" && \
-    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libudev\""; } >&5
-  ($PKG_CONFIG --exists --print-errors "libudev") 2>&5
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"xorg-server >= \$required_xorg_xserver_version xproto fontsproto pixman-1 >= \$required_pixman_version \$REQUIRED_MODULES\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "xorg-server >= $required_xorg_xserver_version xproto fontsproto pixman-1 >= $required_pixman_version $REQUIRED_MODULES") 2>&5
   ac_status=$?
   $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
   test $ac_status = 0; }; then
-  pkg_cv_UDEV_LIBS=`$PKG_CONFIG --libs "libudev" 2>/dev/null`
+  pkg_cv_XORG_LIBS=`$PKG_CONFIG --libs "xorg-server >= $required_xorg_xserver_version xproto fontsproto pixman-1 >= $required_pixman_version $REQUIRED_MODULES" 2>/dev/null`
+                     test "x$?" != "x0" && pkg_failed=yes
 else
   pkg_failed=yes
 fi
@@ -11250,75 +18873,231 @@ else
         _pkg_short_errors_supported=no
 fi
         if test $_pkg_short_errors_supported = yes; then
-               UDEV_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "libudev" 2>&1`
+               XORG_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "xorg-server >= $required_xorg_xserver_version xproto fontsproto pixman-1 >= $required_pixman_version $REQUIRED_MODULES" 2>&1`
         else
-               UDEV_PKG_ERRORS=`$PKG_CONFIG --print-errors "libudev" 2>&1`
+               XORG_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "xorg-server >= $required_xorg_xserver_version xproto fontsproto pixman-1 >= $required_pixman_version $REQUIRED_MODULES" 2>&1`
         fi
        # Put the nasty error message in config.log where it belongs
-       echo "$UDEV_PKG_ERRORS" >&5
+       echo "$XORG_PKG_ERRORS" >&5
 
-       udev=no
+       as_fn_error $? "Package requirements (xorg-server >= $required_xorg_xserver_version xproto fontsproto pixman-1 >= $required_pixman_version $REQUIRED_MODULES) were not met:
+
+$XORG_PKG_ERRORS
+
+Consider adjusting the PKG_CONFIG_PATH environment variable if you
+installed software in a non-standard prefix.
+
+Alternatively, you may set the environment variables XORG_CFLAGS
+and XORG_LIBS to avoid the need to call pkg-config.
+See the pkg-config man page for more details." "$LINENO" 5
 elif test $pkg_failed = untried; then
        { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
-       udev=no
+       { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "The pkg-config script could not be found or is too old.  Make sure it
+is in your PATH or set the PKG_CONFIG environment variable to the full
+path to pkg-config.
+
+Alternatively, you may set the environment variables XORG_CFLAGS
+and XORG_LIBS to avoid the need to call pkg-config.
+See the pkg-config man page for more details.
+
+To get pkg-config, see <http://pkg-config.freedesktop.org/>.
+See \`config.log' for more details" "$LINENO" 5; }
 else
-       UDEV_CFLAGS=$pkg_cv_UDEV_CFLAGS
-       UDEV_LIBS=$pkg_cv_UDEV_LIBS
+       XORG_CFLAGS=$pkg_cv_XORG_CFLAGS
+       XORG_LIBS=$pkg_cv_XORG_LIBS
         { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
 $as_echo "yes" >&6; }
-       udev=yes
+
 fi
-if test x"$udev" = xyes; then
 
-$as_echo "#define HAVE_UDEV 1" >>confdefs.h
+# Check whether --enable-xaa was given.
+if test "${enable_xaa+set}" = set; then :
+  enableval=$enable_xaa; XAA="$enableval"
+else
+  XAA=auto
+fi
 
+if test "x$XAA" != xno; then
+        save_CFLAGS=$CFLAGS
+        CFLAGS=$XORG_CFLAGS
+       for ac_header in xaa.h
+do :
+  ac_fn_c_check_header_mongrel "$LINENO" "xaa.h" "ac_cv_header_xaa_h" "$ac_includes_default"
+if test "x$ac_cv_header_xaa_h" = xyes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_XAA_H 1
+_ACEOF
+ XAA=yes
+else
+  XAA=no
 fi
 
+done
+
+        CFLAGS=$save_CFLAGS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to include XAA support" >&5
+$as_echo_n "checking whether to include XAA support... " >&6; }
+ if test "x$XAA" = xyes; then
+  XAA_TRUE=
+  XAA_FALSE='#'
+else
+  XAA_TRUE='#'
+  XAA_FALSE=
+fi
 
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $XAA" >&5
+$as_echo "$XAA" >&6; }
 
-# Define a configure option for an alternate module directory
+# Check whether --enable-dga was given.
+if test "${enable_dga+set}" = set; then :
+  enableval=$enable_dga; DGA="$enableval"
+else
+  DGA=auto
+fi
 
-# Check whether --with-xorg-module-dir was given.
-if test "${with_xorg_module_dir+set}" = set; then :
-  withval=$with_xorg_module_dir; moduledir="$withval"
+if test "x$DGA" != xno; then
+        save_CFLAGS=$CFLAGS
+        CFLAGS=$XORG_CFLAGS
+       for ac_header in dgaproc.h
+do :
+  ac_fn_c_check_header_compile "$LINENO" "dgaproc.h" "ac_cv_header_dgaproc_h" "#include <dixstruct.h>
+"
+if test "x$ac_cv_header_dgaproc_h" = xyes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_DGAPROC_H 1
+_ACEOF
+ DGA=yes
 else
-  moduledir="$libdir/xorg/modules"
+  DGA=no
+fi
+
+done
+
+        CFLAGS=$save_CFLAGS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to include DGA support" >&5
+$as_echo_n "checking whether to include DGA support... " >&6; }
+ if test "x$DGA" = xyes; then
+  DGA_TRUE=
+  DGA_FALSE='#'
+else
+  DGA_TRUE='#'
+  DGA_FALSE=
+fi
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $DGA" >&5
+$as_echo "$DGA" >&6; }
+
+
+# Check whether --with-default-accel was given.
+if test "${with_default_accel+set}" = set; then :
+  withval=$with_default_accel; accel="$withval"
+else
+  accel=auto
+fi
+
+if test "x$accel" = xyes; then
+       { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: No default acceleration specified, choosing automatic selection" >&5
+$as_echo "$as_me: WARNING: No default acceleration specified, choosing automatic selection" >&2;}
+       accel="auto"
+fi
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking which acceleration method to use by default" >&5
+$as_echo_n "checking which acceleration method to use by default... " >&6; }
+if test "x$accel" = xauto; then
+       if test "x$UXA" != "xno"; then
+               accel=uxa
+       else
+               if test "x$SNA" != "xno"; then
+                       accel=sna
+               fi
+       fi
+       if test "x$accel" = xauto -a "x$UMS_ONLY" != "xyes"; then
+               as_fn_error $? "No default acceleration option" "$LINENO" 5
+       fi
+fi
+
+have_accel=none
+if test "x$accel" = xsna; then
+       if test "x$SNA" != "xno"; then
+
+$as_echo "#define DEFAULT_ACCEL_METHOD SNA" >>confdefs.h
+
+               have_accel=yes
+       else
+               as_fn_error $? "SNA requested as default, but is not enabled" "$LINENO" 5
+       fi
+fi
+
+if test "x$accel" = xuxa; then
+       if test "x$UXA" != "xno"; then
+
+$as_echo "#define DEFAULT_ACCEL_METHOD UXA" >>confdefs.h
+
+               have_accel=yes
+       else
+               as_fn_error $? "UXA requested as default, but is not enabled" "$LINENO" 5
+       fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $accel" >&5
+$as_echo "$accel" >&6; }
+if test "x$accel" = xnone -a "x$UMS_ONLY" != "xyes"; then
+       as_fn_error $? "No default acceleration option" "$LINENO" 5
 fi
 
+# Check whether --enable-userptr was given.
+if test "${enable_userptr+set}" = set; then :
+  enableval=$enable_userptr; USERPTR="$enableval"
+else
+  USERPTR=no
+fi
 
-# Check whether --enable-dri was given.
-if test "${enable_dri+set}" = set; then :
-  enableval=$enable_dri; DRI="$enableval"
+ if test x$USERPTR = xyes; then
+  USE_USERPTR_TRUE=
+  USE_USERPTR_FALSE='#'
 else
-  DRI=auto
+  USE_USERPTR_TRUE='#'
+  USE_USERPTR_FALSE=
 fi
 
+if test "x$USERPTR" = xyes; then
+
+$as_echo "#define USE_USERPTR 1" >>confdefs.h
 
-# Check whether --enable-xvmc was given.
-if test "${enable_xvmc+set}" = set; then :
-  enableval=$enable_xvmc; XVMC="$enableval"
-else
-  XVMC=yes
 fi
 
+# Check whether --enable-async-swap was given.
+if test "${enable_async_swap+set}" = set; then :
+  enableval=$enable_async_swap; ASYNC_SWAP="$enableval"
+else
+  ASYNC_SWAP=no
+fi
 
-# Check whether --enable-kms-only was given.
-if test "${enable_kms_only+set}" = set; then :
-  enableval=$enable_kms_only; KMS_ONLY="$enableval"
+ if test x$ASYNC_SWAP = xyes; then
+  USE_ASYNC_SWAP_TRUE=
+  USE_ASYNC_SWAP_FALSE='#'
 else
-  KMS_ONLY=no
+  USE_ASYNC_SWAP_TRUE='#'
+  USE_ASYNC_SWAP_FALSE=
 fi
 
+if test "x$ASYNC_SWAP" = xyes; then
+
+$as_echo "#define USE_ASYNC_SWAP 1" >>confdefs.h
+
+fi
 
 # Check whether --enable-debug was given.
 if test "${enable_debug+set}" = set; then :
   enableval=$enable_debug; DEBUG="$enableval"
 else
-  DEBUG=yes
+  DEBUG=no
 fi
 
-
 # Store the list of server defined optional extensions in REQUIRED_MODULES
 
 
@@ -11464,35 +19243,37 @@ $as_echo "$_EXT_CHECK" >&6; }
 # Obtain compiler/linker options for the driver dependencies
 
 pkg_failed=no
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for XORG" >&5
-$as_echo_n "checking for XORG... " >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for DRM" >&5
+$as_echo_n "checking for DRM... " >&6; }
 
-if test -n "$XORG_CFLAGS"; then
-    pkg_cv_XORG_CFLAGS="$XORG_CFLAGS"
+if test -n "$DRM_CFLAGS"; then
+    pkg_cv_DRM_CFLAGS="$DRM_CFLAGS"
  elif test -n "$PKG_CONFIG"; then
     if test -n "$PKG_CONFIG" && \
-    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"xorg-server >= 1.6 xproto fontsproto \$REQUIRED_MODULES\""; } >&5
-  ($PKG_CONFIG --exists --print-errors "xorg-server >= 1.6 xproto fontsproto $REQUIRED_MODULES") 2>&5
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libdrm >= 2.4.24\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "libdrm >= 2.4.24") 2>&5
   ac_status=$?
   $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
   test $ac_status = 0; }; then
-  pkg_cv_XORG_CFLAGS=`$PKG_CONFIG --cflags "xorg-server >= 1.6 xproto fontsproto $REQUIRED_MODULES" 2>/dev/null`
+  pkg_cv_DRM_CFLAGS=`$PKG_CONFIG --cflags "libdrm >= 2.4.24" 2>/dev/null`
+                     test "x$?" != "x0" && pkg_failed=yes
 else
   pkg_failed=yes
 fi
  else
     pkg_failed=untried
 fi
-if test -n "$XORG_LIBS"; then
-    pkg_cv_XORG_LIBS="$XORG_LIBS"
+if test -n "$DRM_LIBS"; then
+    pkg_cv_DRM_LIBS="$DRM_LIBS"
  elif test -n "$PKG_CONFIG"; then
     if test -n "$PKG_CONFIG" && \
-    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"xorg-server >= 1.6 xproto fontsproto \$REQUIRED_MODULES\""; } >&5
-  ($PKG_CONFIG --exists --print-errors "xorg-server >= 1.6 xproto fontsproto $REQUIRED_MODULES") 2>&5
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libdrm >= 2.4.24\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "libdrm >= 2.4.24") 2>&5
   ac_status=$?
   $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
   test $ac_status = 0; }; then
-  pkg_cv_XORG_LIBS=`$PKG_CONFIG --libs "xorg-server >= 1.6 xproto fontsproto $REQUIRED_MODULES" 2>/dev/null`
+  pkg_cv_DRM_LIBS=`$PKG_CONFIG --libs "libdrm >= 2.4.24" 2>/dev/null`
+                     test "x$?" != "x0" && pkg_failed=yes
 else
   pkg_failed=yes
 fi
@@ -11512,22 +19293,22 @@ else
         _pkg_short_errors_supported=no
 fi
         if test $_pkg_short_errors_supported = yes; then
-               XORG_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "xorg-server >= 1.6 xproto fontsproto $REQUIRED_MODULES" 2>&1`
+               DRM_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "libdrm >= 2.4.24" 2>&1`
         else
-               XORG_PKG_ERRORS=`$PKG_CONFIG --print-errors "xorg-server >= 1.6 xproto fontsproto $REQUIRED_MODULES" 2>&1`
+               DRM_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "libdrm >= 2.4.24" 2>&1`
         fi
        # Put the nasty error message in config.log where it belongs
-       echo "$XORG_PKG_ERRORS" >&5
+       echo "$DRM_PKG_ERRORS" >&5
 
-       as_fn_error $? "Package requirements (xorg-server >= 1.6 xproto fontsproto $REQUIRED_MODULES) were not met:
+       as_fn_error $? "Package requirements (libdrm >= 2.4.24) were not met:
 
-$XORG_PKG_ERRORS
+$DRM_PKG_ERRORS
 
 Consider adjusting the PKG_CONFIG_PATH environment variable if you
 installed software in a non-standard prefix.
 
-Alternatively, you may set the environment variables XORG_CFLAGS
-and XORG_LIBS to avoid the need to call pkg-config.
+Alternatively, you may set the environment variables DRM_CFLAGS
+and DRM_LIBS to avoid the need to call pkg-config.
 See the pkg-config man page for more details." "$LINENO" 5
 elif test $pkg_failed = untried; then
        { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
@@ -11538,50 +19319,52 @@ as_fn_error $? "The pkg-config script could not be found or is too old.  Make su
 is in your PATH or set the PKG_CONFIG environment variable to the full
 path to pkg-config.
 
-Alternatively, you may set the environment variables XORG_CFLAGS
-and XORG_LIBS to avoid the need to call pkg-config.
+Alternatively, you may set the environment variables DRM_CFLAGS
+and DRM_LIBS to avoid the need to call pkg-config.
 See the pkg-config man page for more details.
 
 To get pkg-config, see <http://pkg-config.freedesktop.org/>.
-See \`config.log' for more details" "$LINENO" 5 ; }
+See \`config.log' for more details" "$LINENO" 5; }
 else
-       XORG_CFLAGS=$pkg_cv_XORG_CFLAGS
-       XORG_LIBS=$pkg_cv_XORG_LIBS
+       DRM_CFLAGS=$pkg_cv_DRM_CFLAGS
+       DRM_LIBS=$pkg_cv_DRM_LIBS
         { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
 $as_echo "yes" >&6; }
 
-fi
+fi # libdrm_intel is checked separately
 
 pkg_failed=no
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for DRM" >&5
-$as_echo_n "checking for DRM... " >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for DRI" >&5
+$as_echo_n "checking for DRI... " >&6; }
 
-if test -n "$DRM_CFLAGS"; then
-    pkg_cv_DRM_CFLAGS="$DRM_CFLAGS"
+if test -n "$DRI_CFLAGS"; then
+    pkg_cv_DRI_CFLAGS="$DRI_CFLAGS"
  elif test -n "$PKG_CONFIG"; then
     if test -n "$PKG_CONFIG" && \
-    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libdrm >= 2.4.23\""; } >&5
-  ($PKG_CONFIG --exists --print-errors "libdrm >= 2.4.23") 2>&5
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"xf86driproto\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "xf86driproto") 2>&5
   ac_status=$?
   $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
   test $ac_status = 0; }; then
-  pkg_cv_DRM_CFLAGS=`$PKG_CONFIG --cflags "libdrm >= 2.4.23" 2>/dev/null`
+  pkg_cv_DRI_CFLAGS=`$PKG_CONFIG --cflags "xf86driproto" 2>/dev/null`
+                     test "x$?" != "x0" && pkg_failed=yes
 else
   pkg_failed=yes
 fi
  else
     pkg_failed=untried
 fi
-if test -n "$DRM_LIBS"; then
-    pkg_cv_DRM_LIBS="$DRM_LIBS"
+if test -n "$DRI_LIBS"; then
+    pkg_cv_DRI_LIBS="$DRI_LIBS"
  elif test -n "$PKG_CONFIG"; then
     if test -n "$PKG_CONFIG" && \
-    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libdrm >= 2.4.23\""; } >&5
-  ($PKG_CONFIG --exists --print-errors "libdrm >= 2.4.23") 2>&5
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"xf86driproto\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "xf86driproto") 2>&5
   ac_status=$?
   $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
   test $ac_status = 0; }; then
-  pkg_cv_DRM_LIBS=`$PKG_CONFIG --libs "libdrm >= 2.4.23" 2>/dev/null`
+  pkg_cv_DRI_LIBS=`$PKG_CONFIG --libs "xf86driproto" 2>/dev/null`
+                     test "x$?" != "x0" && pkg_failed=yes
 else
   pkg_failed=yes
 fi
@@ -11601,76 +19384,58 @@ else
         _pkg_short_errors_supported=no
 fi
         if test $_pkg_short_errors_supported = yes; then
-               DRM_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "libdrm >= 2.4.23" 2>&1`
+               DRI_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "xf86driproto" 2>&1`
         else
-               DRM_PKG_ERRORS=`$PKG_CONFIG --print-errors "libdrm >= 2.4.23" 2>&1`
+               DRI_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "xf86driproto" 2>&1`
         fi
        # Put the nasty error message in config.log where it belongs
-       echo "$DRM_PKG_ERRORS" >&5
-
-       as_fn_error $? "Package requirements (libdrm >= 2.4.23) were not met:
-
-$DRM_PKG_ERRORS
-
-Consider adjusting the PKG_CONFIG_PATH environment variable if you
-installed software in a non-standard prefix.
+       echo "$DRI_PKG_ERRORS" >&5
 
-Alternatively, you may set the environment variables DRM_CFLAGS
-and DRM_LIBS to avoid the need to call pkg-config.
-See the pkg-config man page for more details." "$LINENO" 5
+       DRI=no
 elif test $pkg_failed = untried; then
        { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
-       { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
-$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error $? "The pkg-config script could not be found or is too old.  Make sure it
-is in your PATH or set the PKG_CONFIG environment variable to the full
-path to pkg-config.
-
-Alternatively, you may set the environment variables DRM_CFLAGS
-and DRM_LIBS to avoid the need to call pkg-config.
-See the pkg-config man page for more details.
-
-To get pkg-config, see <http://pkg-config.freedesktop.org/>.
-See \`config.log' for more details" "$LINENO" 5 ; }
+       DRI=no
 else
-       DRM_CFLAGS=$pkg_cv_DRM_CFLAGS
-       DRM_LIBS=$pkg_cv_DRM_LIBS
+       DRI_CFLAGS=$pkg_cv_DRI_CFLAGS
+       DRI_LIBS=$pkg_cv_DRI_LIBS
         { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
 $as_echo "yes" >&6; }
 
 fi
 
 pkg_failed=no
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for PCIACCESS" >&5
-$as_echo_n "checking for PCIACCESS... " >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for DRI2" >&5
+$as_echo_n "checking for DRI2... " >&6; }
 
-if test -n "$PCIACCESS_CFLAGS"; then
-    pkg_cv_PCIACCESS_CFLAGS="$PCIACCESS_CFLAGS"
+if test -n "$DRI2_CFLAGS"; then
+    pkg_cv_DRI2_CFLAGS="$DRI2_CFLAGS"
  elif test -n "$PKG_CONFIG"; then
     if test -n "$PKG_CONFIG" && \
-    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"pciaccess >= 0.10\""; } >&5
-  ($PKG_CONFIG --exists --print-errors "pciaccess >= 0.10") 2>&5
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"dri2proto >= 2.6\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "dri2proto >= 2.6") 2>&5
   ac_status=$?
   $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
   test $ac_status = 0; }; then
-  pkg_cv_PCIACCESS_CFLAGS=`$PKG_CONFIG --cflags "pciaccess >= 0.10" 2>/dev/null`
+  pkg_cv_DRI2_CFLAGS=`$PKG_CONFIG --cflags "dri2proto >= 2.6" 2>/dev/null`
+                     test "x$?" != "x0" && pkg_failed=yes
 else
   pkg_failed=yes
 fi
  else
     pkg_failed=untried
 fi
-if test -n "$PCIACCESS_LIBS"; then
-    pkg_cv_PCIACCESS_LIBS="$PCIACCESS_LIBS"
+if test -n "$DRI2_LIBS"; then
+    pkg_cv_DRI2_LIBS="$DRI2_LIBS"
  elif test -n "$PKG_CONFIG"; then
     if test -n "$PKG_CONFIG" && \
-    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"pciaccess >= 0.10\""; } >&5
-  ($PKG_CONFIG --exists --print-errors "pciaccess >= 0.10") 2>&5
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"dri2proto >= 2.6\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "dri2proto >= 2.6") 2>&5
   ac_status=$?
   $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
   test $ac_status = 0; }; then
-  pkg_cv_PCIACCESS_LIBS=`$PKG_CONFIG --libs "pciaccess >= 0.10" 2>/dev/null`
+  pkg_cv_DRI2_LIBS=`$PKG_CONFIG --libs "dri2proto >= 2.6" 2>/dev/null`
+                     test "x$?" != "x0" && pkg_failed=yes
 else
   pkg_failed=yes
 fi
@@ -11690,179 +19455,58 @@ else
         _pkg_short_errors_supported=no
 fi
         if test $_pkg_short_errors_supported = yes; then
-               PCIACCESS_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "pciaccess >= 0.10" 2>&1`
+               DRI2_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "dri2proto >= 2.6" 2>&1`
         else
-               PCIACCESS_PKG_ERRORS=`$PKG_CONFIG --print-errors "pciaccess >= 0.10" 2>&1`
+               DRI2_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "dri2proto >= 2.6" 2>&1`
         fi
        # Put the nasty error message in config.log where it belongs
-       echo "$PCIACCESS_PKG_ERRORS" >&5
+       echo "$DRI2_PKG_ERRORS" >&5
 
-       as_fn_error $? "Package requirements (pciaccess >= 0.10) were not met:
-
-$PCIACCESS_PKG_ERRORS
-
-Consider adjusting the PKG_CONFIG_PATH environment variable if you
-installed software in a non-standard prefix.
-
-Alternatively, you may set the environment variables PCIACCESS_CFLAGS
-and PCIACCESS_LIBS to avoid the need to call pkg-config.
-See the pkg-config man page for more details." "$LINENO" 5
+       DRI2=no
 elif test $pkg_failed = untried; then
        { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
-       { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
-$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error $? "The pkg-config script could not be found or is too old.  Make sure it
-is in your PATH or set the PKG_CONFIG environment variable to the full
-path to pkg-config.
-
-Alternatively, you may set the environment variables PCIACCESS_CFLAGS
-and PCIACCESS_LIBS to avoid the need to call pkg-config.
-See the pkg-config man page for more details.
-
-To get pkg-config, see <http://pkg-config.freedesktop.org/>.
-See \`config.log' for more details" "$LINENO" 5 ; }
+       DRI2=no
 else
-       PCIACCESS_CFLAGS=$pkg_cv_PCIACCESS_CFLAGS
-       PCIACCESS_LIBS=$pkg_cv_PCIACCESS_LIBS
+       DRI2_CFLAGS=$pkg_cv_DRI2_CFLAGS
+       DRI2_LIBS=$pkg_cv_DRI2_LIBS
         { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
 $as_echo "yes" >&6; }
 
 fi
 
-sdkdir=`$PKG_CONFIG --variable=sdkdir xorg-server`
-
-save_CFLAGS="$CFLAGS"
-CFLAGS="$XORG_CFLAGS $DRI_CFLAGS $DRM_CFLAGS"
-CPPFLAGS="$XORG_CFLAGS $DRI_CFLAGS $DRM_CFLAGS"
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to include DRI support" >&5
-$as_echo_n "checking whether to include DRI support... " >&6; }
-if test x$DRI != xno; then
-        as_ac_File=`$as_echo "ac_cv_file_${sdkdir}/dri.h" | $as_tr_sh`
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ${sdkdir}/dri.h" >&5
-$as_echo_n "checking for ${sdkdir}/dri.h... " >&6; }
-if eval "test \"\${$as_ac_File+set}\"" = set; then :
-  $as_echo_n "(cached) " >&6
-else
-  test "$cross_compiling" = yes &&
-  as_fn_error $? "cannot check for file existence when cross compiling" "$LINENO" 5
-if test -r "${sdkdir}/dri.h"; then
-  eval "$as_ac_File=yes"
-else
-  eval "$as_ac_File=no"
-fi
-fi
-eval ac_res=\$$as_ac_File
-              { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
-$as_echo "$ac_res" >&6; }
-if eval test \"x\$"$as_ac_File"\" = x"yes"; then :
-  have_dri_h="yes"
-else
-  have_dri_h="no"
-fi
-
-        as_ac_File=`$as_echo "ac_cv_file_${sdkdir}/sarea.h" | $as_tr_sh`
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ${sdkdir}/sarea.h" >&5
-$as_echo_n "checking for ${sdkdir}/sarea.h... " >&6; }
-if eval "test \"\${$as_ac_File+set}\"" = set; then :
-  $as_echo_n "(cached) " >&6
-else
-  test "$cross_compiling" = yes &&
-  as_fn_error $? "cannot check for file existence when cross compiling" "$LINENO" 5
-if test -r "${sdkdir}/sarea.h"; then
-  eval "$as_ac_File=yes"
-else
-  eval "$as_ac_File=no"
-fi
-fi
-eval ac_res=\$$as_ac_File
-              { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
-$as_echo "$ac_res" >&6; }
-if eval test \"x\$"$as_ac_File"\" = x"yes"; then :
-  have_sarea_h="yes"
-else
-  have_sarea_h="no"
-fi
-
-        as_ac_File=`$as_echo "ac_cv_file_${sdkdir}/dristruct.h" | $as_tr_sh`
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ${sdkdir}/dristruct.h" >&5
-$as_echo_n "checking for ${sdkdir}/dristruct.h... " >&6; }
-if eval "test \"\${$as_ac_File+set}\"" = set; then :
-  $as_echo_n "(cached) " >&6
-else
-  test "$cross_compiling" = yes &&
-  as_fn_error $? "cannot check for file existence when cross compiling" "$LINENO" 5
-if test -r "${sdkdir}/dristruct.h"; then
-  eval "$as_ac_File=yes"
-else
-  eval "$as_ac_File=no"
-fi
-fi
-eval ac_res=\$$as_ac_File
-              { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
-$as_echo "$ac_res" >&6; }
-if eval test \"x\$"$as_ac_File"\" = x"yes"; then :
-  have_dristruct_h="yes"
-else
-  have_dristruct_h="no"
-fi
-
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to include DRI support" >&5
-$as_echo_n "checking whether to include DRI support... " >&6; }
-if test x$DRI = xauto; then
-        if test "$have_dri_h" = yes -a \
-                "$have_sarea_h" = yes -a \
-                "$have_dristruct_h" = yes; then
-                DRI="yes"
-        else
-                DRI="no"
-        fi
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $DRI" >&5
-$as_echo "$DRI" >&6; }
-CFLAGS="$save_CFLAGS $DEBUGFLAGS"
-
- if test x$DRI = xyes; then
-  DRI_TRUE=
-  DRI_FALSE='#'
-else
-  DRI_TRUE='#'
-  DRI_FALSE=
-fi
-
-if test "$DRI" = yes; then
-
 pkg_failed=no
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for DRI" >&5
-$as_echo_n "checking for DRI... " >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for PCIACCESS" >&5
+$as_echo_n "checking for PCIACCESS... " >&6; }
 
-if test -n "$DRI_CFLAGS"; then
-    pkg_cv_DRI_CFLAGS="$DRI_CFLAGS"
+if test -n "$PCIACCESS_CFLAGS"; then
+    pkg_cv_PCIACCESS_CFLAGS="$PCIACCESS_CFLAGS"
  elif test -n "$PKG_CONFIG"; then
     if test -n "$PKG_CONFIG" && \
-    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"xf86driproto\""; } >&5
-  ($PKG_CONFIG --exists --print-errors "xf86driproto") 2>&5
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"pciaccess >= 0.10\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "pciaccess >= 0.10") 2>&5
   ac_status=$?
   $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
   test $ac_status = 0; }; then
-  pkg_cv_DRI_CFLAGS=`$PKG_CONFIG --cflags "xf86driproto" 2>/dev/null`
+  pkg_cv_PCIACCESS_CFLAGS=`$PKG_CONFIG --cflags "pciaccess >= 0.10" 2>/dev/null`
+                     test "x$?" != "x0" && pkg_failed=yes
 else
   pkg_failed=yes
 fi
  else
     pkg_failed=untried
 fi
-if test -n "$DRI_LIBS"; then
-    pkg_cv_DRI_LIBS="$DRI_LIBS"
+if test -n "$PCIACCESS_LIBS"; then
+    pkg_cv_PCIACCESS_LIBS="$PCIACCESS_LIBS"
  elif test -n "$PKG_CONFIG"; then
     if test -n "$PKG_CONFIG" && \
-    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"xf86driproto\""; } >&5
-  ($PKG_CONFIG --exists --print-errors "xf86driproto") 2>&5
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"pciaccess >= 0.10\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "pciaccess >= 0.10") 2>&5
   ac_status=$?
   $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
   test $ac_status = 0; }; then
-  pkg_cv_DRI_LIBS=`$PKG_CONFIG --libs "xf86driproto" 2>/dev/null`
+  pkg_cv_PCIACCESS_LIBS=`$PKG_CONFIG --libs "pciaccess >= 0.10" 2>/dev/null`
+                     test "x$?" != "x0" && pkg_failed=yes
 else
   pkg_failed=yes
 fi
@@ -11882,22 +19526,22 @@ else
         _pkg_short_errors_supported=no
 fi
         if test $_pkg_short_errors_supported = yes; then
-               DRI_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "xf86driproto" 2>&1`
+               PCIACCESS_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "pciaccess >= 0.10" 2>&1`
         else
-               DRI_PKG_ERRORS=`$PKG_CONFIG --print-errors "xf86driproto" 2>&1`
+               PCIACCESS_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "pciaccess >= 0.10" 2>&1`
         fi
        # Put the nasty error message in config.log where it belongs
-       echo "$DRI_PKG_ERRORS" >&5
+       echo "$PCIACCESS_PKG_ERRORS" >&5
 
-       as_fn_error $? "Package requirements (xf86driproto) were not met:
+       as_fn_error $? "Package requirements (pciaccess >= 0.10) were not met:
 
-$DRI_PKG_ERRORS
+$PCIACCESS_PKG_ERRORS
 
 Consider adjusting the PKG_CONFIG_PATH environment variable if you
 installed software in a non-standard prefix.
 
-Alternatively, you may set the environment variables DRI_CFLAGS
-and DRI_LIBS to avoid the need to call pkg-config.
+Alternatively, you may set the environment variables PCIACCESS_CFLAGS
+and PCIACCESS_LIBS to avoid the need to call pkg-config.
 See the pkg-config man page for more details." "$LINENO" 5
 elif test $pkg_failed = untried; then
        { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
@@ -11908,27 +19552,118 @@ as_fn_error $? "The pkg-config script could not be found or is too old.  Make su
 is in your PATH or set the PKG_CONFIG environment variable to the full
 path to pkg-config.
 
-Alternatively, you may set the environment variables DRI_CFLAGS
-and DRI_LIBS to avoid the need to call pkg-config.
+Alternatively, you may set the environment variables PCIACCESS_CFLAGS
+and PCIACCESS_LIBS to avoid the need to call pkg-config.
 See the pkg-config man page for more details.
 
 To get pkg-config, see <http://pkg-config.freedesktop.org/>.
-See \`config.log' for more details" "$LINENO" 5 ; }
+See \`config.log' for more details" "$LINENO" 5; }
 else
-       DRI_CFLAGS=$pkg_cv_DRI_CFLAGS
-       DRI_LIBS=$pkg_cv_DRI_LIBS
+       PCIACCESS_CFLAGS=$pkg_cv_PCIACCESS_CFLAGS
+       PCIACCESS_LIBS=$pkg_cv_PCIACCESS_LIBS
         { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
 $as_echo "yes" >&6; }
 
 fi
 
-$as_echo "#define XF86DRI 1" >>confdefs.h
+sdkdir=`$PKG_CONFIG --variable=sdkdir xorg-server`
+
+if test "x$enable_dri" != "xno"; then
+        save_CFLAGS="$CFLAGS"
+        save_CPPFLAGS="$CPPFLAGS"
+        CFLAGS="$CFLAGS $XORG_CFLAGS $DRI_CFLAGS $DRM_CFLAGS"
+        CPPFLAGS="$CPPFLAGS $XORG_CFLAGS $DRI_CFLAGS $DRM_CFLAGS"
+        for ac_header in dri.h sarea.h dristruct.h
+do :
+  as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
+ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "/* for dri.h */
+                 #include <xf86str.h>
+                 /* for dristruct.h */
+                 #include <xorg-server.h>
+                 #ifdef HAVE_DRI_H
+                 # include <dri.h>
+                 #endif
+                 #ifdef HAVE_SAREA_H
+                 # include <sarea.h>
+                 #endif
+
+"
+if eval test \"x\$"$as_ac_Header"\" = x"yes"; then :
+  cat >>confdefs.h <<_ACEOF
+#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1
+_ACEOF
+
+else
+  DRI=no
+fi
+
+done
+
+        CFLAGS="$save_CFLAGS $DEBUGFLAGS"
+        CPPFLAGS="$save_CPPFLAGS"
+else
+        DRI=no
+fi
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to include DRI support" >&5
+$as_echo_n "checking whether to include DRI support... " >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: ${DRI-yes}" >&5
+$as_echo "${DRI-yes}" >&6; }
+
+ if test x$DRI != xno; then
+  DRI_TRUE=
+  DRI_FALSE='#'
+else
+  DRI_TRUE='#'
+  DRI_FALSE=
+fi
+
+if test "x$DRI" != "xno"; then
+
+$as_echo "#define HAVE_DRI1 1" >>confdefs.h
+
+else
+        DRI_CFLAGS=""
+        DRI_LIBS=""
+
+        if test "x$enable_dri" = "xyes"; then
+                as_fn_error $? "DRI requested but prerequisites not found" "$LINENO" 5
+        fi
+fi
 
+if test "x$DRI2" != "xno"; then
+       save_CFLAGS=$CFLAGS
+       CFLAGS="$XORG_CFLAGS $DRM_CFLAGS $DRI_CFLAGS $DRI2_CFLAGS"
+       for ac_header in dri2.h
+do :
+  ac_fn_c_check_header_compile "$LINENO" "dri2.h" "ac_cv_header_dri2_h" "#include <dixstruct.h>
+"
+if test "x$ac_cv_header_dri2_h" = xyes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_DRI2_H 1
+_ACEOF
+ DRI2=yes
+else
+  DRI2=no
+fi
 
-$as_echo "#define XF86DRI_DEVEL 1" >>confdefs.h
+done
 
+       CFLAGS=$save_CFLAGS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to include DRI2 support" >&5
+$as_echo_n "checking whether to include DRI2 support... " >&6; }
+ if test "x$DRI2" = xyes; then
+  DRI2_TRUE=
+  DRI2_FALSE='#'
+else
+  DRI2_TRUE='#'
+  DRI2_FALSE=
 fi
 
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $DRI2" >&5
+$as_echo "$DRI2" >&6; }
+
 if test "$XVMC" = yes; then
 
 pkg_failed=no
@@ -11945,6 +19680,7 @@ if test -n "$XVMCLIB_CFLAGS"; then
   $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
   test $ac_status = 0; }; then
   pkg_cv_XVMCLIB_CFLAGS=`$PKG_CONFIG --cflags "xvmc xext xfixes dri2proto x11-xcb xcb-dri2 xcb-aux" 2>/dev/null`
+                     test "x$?" != "x0" && pkg_failed=yes
 else
   pkg_failed=yes
 fi
@@ -11961,6 +19697,7 @@ if test -n "$XVMCLIB_LIBS"; then
   $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
   test $ac_status = 0; }; then
   pkg_cv_XVMCLIB_LIBS=`$PKG_CONFIG --libs "xvmc xext xfixes dri2proto x11-xcb xcb-dri2 xcb-aux" 2>/dev/null`
+                     test "x$?" != "x0" && pkg_failed=yes
 else
   pkg_failed=yes
 fi
@@ -11980,9 +19717,9 @@ else
         _pkg_short_errors_supported=no
 fi
         if test $_pkg_short_errors_supported = yes; then
-               XVMCLIB_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "xvmc xext xfixes dri2proto x11-xcb xcb-dri2 xcb-aux" 2>&1`
+               XVMCLIB_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "xvmc xext xfixes dri2proto x11-xcb xcb-dri2 xcb-aux" 2>&1`
         else
-               XVMCLIB_PKG_ERRORS=`$PKG_CONFIG --print-errors "xvmc xext xfixes dri2proto x11-xcb xcb-dri2 xcb-aux" 2>&1`
+               XVMCLIB_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "xvmc xext xfixes dri2proto x11-xcb xcb-dri2 xcb-aux" 2>&1`
         fi
        # Put the nasty error message in config.log where it belongs
        echo "$XVMCLIB_PKG_ERRORS" >&5
@@ -12031,18 +19768,147 @@ if test "x$KMS_ONLY" = xyes; then
 $as_echo "#define KMS_ONLY 1" >>confdefs.h
 
 fi
+ if test x$UMS_ONLY = xyes; then
+  UMS_ONLY_TRUE=
+  UMS_ONLY_FALSE='#'
+else
+  UMS_ONLY_TRUE='#'
+  UMS_ONLY_FALSE=
+fi
+
+if test "x$UMS_ONLY" = xyes; then
+
+$as_echo "#define UMS_ONLY 1" >>confdefs.h
+
+fi
+
+ if test x$DEBUG != xno; then
+  DEBUG_TRUE=
+  DEBUG_FALSE='#'
+else
+  DEBUG_TRUE='#'
+  DEBUG_FALSE=
+fi
+
+ if test x$FULL_DEBUG == xfull; then
+  FULL_DEBUG_TRUE=
+  FULL_DEBUG_FALSE='#'
+else
+  FULL_DEBUG_TRUE='#'
+  FULL_DEBUG_FALSE=
+fi
 
 if test "x$DEBUG" = xno; then
 
 $as_echo "#define NDEBUG 1" >>confdefs.h
 
 fi
+if test "x$DEBUG" != xno; then
+
+pkg_failed=no
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for VALGRIND" >&5
+$as_echo_n "checking for VALGRIND... " >&6; }
+
+if test -n "$VALGRIND_CFLAGS"; then
+    pkg_cv_VALGRIND_CFLAGS="$VALGRIND_CFLAGS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"valgrind\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "valgrind") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_VALGRIND_CFLAGS=`$PKG_CONFIG --cflags "valgrind" 2>/dev/null`
+                     test "x$?" != "x0" && pkg_failed=yes
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+if test -n "$VALGRIND_LIBS"; then
+    pkg_cv_VALGRIND_LIBS="$VALGRIND_LIBS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"valgrind\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "valgrind") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_VALGRIND_LIBS=`$PKG_CONFIG --libs "valgrind" 2>/dev/null`
+                     test "x$?" != "x0" && pkg_failed=yes
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+
+
+
+if test $pkg_failed = yes; then
+       { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
+        _pkg_short_errors_supported=yes
+else
+        _pkg_short_errors_supported=no
+fi
+        if test $_pkg_short_errors_supported = yes; then
+               VALGRIND_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "valgrind" 2>&1`
+        else
+               VALGRIND_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "valgrind" 2>&1`
+        fi
+       # Put the nasty error message in config.log where it belongs
+       echo "$VALGRIND_PKG_ERRORS" >&5
+
+       have_valgrind=no
+elif test $pkg_failed = untried; then
+       { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+       have_valgrind=no
+else
+       VALGRIND_CFLAGS=$pkg_cv_VALGRIND_CFLAGS
+       VALGRIND_LIBS=$pkg_cv_VALGRIND_LIBS
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+       have_valgrind=yes
+fi
+       if test x$have_valgrind = xyes; then
+
+$as_echo "#define HAVE_VALGRIND 1" >>confdefs.h
+
+       fi
+fi
+if test "x$DEBUG" = xmemory; then
+
+$as_echo "#define DEBUG_MEMORY 1" >>confdefs.h
+
+fi
+if test "x$DEBUG" = xpixmap; then
+
+$as_echo "#define DEBUG_PIXMAP 1" >>confdefs.h
+
+fi
+if test "x$DEBUG" = xfull; then
+
+$as_echo "#define DEBUG_MEMORY 1" >>confdefs.h
+
+
+$as_echo "#define DEBUG_PIXMAP 1" >>confdefs.h
+
+
+$as_echo "#define HAS_DEBUG_FULL 1" >>confdefs.h
+
+        CFLAGS="$CFLAGS -O0 -ggdb3"
+fi
 
 DRIVER_NAME=intel
 
 
 
-ac_config_files="$ac_config_files Makefile uxa/Makefile src/Makefile src/xvmc/Makefile src/xvmc/shader/Makefile src/xvmc/shader/mc/Makefile src/xvmc/shader/vld/Makefile src/legacy/Makefile src/legacy/i810/Makefile src/legacy/i810/xvmc/Makefile man/Makefile src/render_program/Makefile"
+ac_config_files="$ac_config_files Makefile uxa/Makefile src/Makefile src/xvmc/Makefile src/xvmc/shader/Makefile src/xvmc/shader/mc/Makefile src/xvmc/shader/vld/Makefile src/legacy/Makefile src/legacy/i810/Makefile src/legacy/i810/xvmc/Makefile src/sna/Makefile src/sna/brw/Makefile src/sna/fb/Makefile man/Makefile src/render_program/Makefile test/Makefile"
 
 cat >confcache <<\_ACEOF
 # This file is a shell script that caches the results of configure
@@ -12108,10 +19974,21 @@ $as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;;
      :end' >>confcache
 if diff "$cache_file" confcache >/dev/null 2>&1; then :; else
   if test -w "$cache_file"; then
-    test "x$cache_file" != "x/dev/null" &&
+    if test "x$cache_file" != "x/dev/null"; then
       { $as_echo "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5
 $as_echo "$as_me: updating cache $cache_file" >&6;}
-    cat confcache >$cache_file
+      if test ! -f "$cache_file" || test -h "$cache_file"; then
+       cat confcache >"$cache_file"
+      else
+        case $cache_file in #(
+        */* | ?:*)
+         mv -f confcache "$cache_file"$$ &&
+         mv -f "$cache_file"$$ "$cache_file" ;; #(
+        *)
+         mv -f confcache "$cache_file" ;;
+       esac
+      fi
+    fi
   else
     { $as_echo "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5
 $as_echo "$as_me: not updating unwritable cache $cache_file" >&6;}
@@ -12162,14 +20039,54 @@ if test -z "${am__fastdepCC_TRUE}" && test -z "${am__fastdepCC_FALSE}"; then
   as_fn_error $? "conditional \"am__fastdepCC\" was never defined.
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
 fi
+if test -z "${HAVE_DOT_GIT_TRUE}" && test -z "${HAVE_DOT_GIT_FALSE}"; then
+  as_fn_error $? "conditional \"HAVE_DOT_GIT\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
 if test -z "${HAVE_GEN4ASM_TRUE}" && test -z "${HAVE_GEN4ASM_FALSE}"; then
   as_fn_error $? "conditional \"HAVE_GEN4ASM\" was never defined.
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
 fi
+if test -z "${HAVE_X11_TRUE}" && test -z "${HAVE_X11_FALSE}"; then
+  as_fn_error $? "conditional \"HAVE_X11\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${SNA_TRUE}" && test -z "${SNA_FALSE}"; then
+  as_fn_error $? "conditional \"SNA\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${UXA_TRUE}" && test -z "${UXA_FALSE}"; then
+  as_fn_error $? "conditional \"UXA\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${GLAMOR_TRUE}" && test -z "${GLAMOR_FALSE}"; then
+  as_fn_error $? "conditional \"GLAMOR\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${XAA_TRUE}" && test -z "${XAA_FALSE}"; then
+  as_fn_error $? "conditional \"XAA\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${DGA_TRUE}" && test -z "${DGA_FALSE}"; then
+  as_fn_error $? "conditional \"DGA\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${USE_USERPTR_TRUE}" && test -z "${USE_USERPTR_FALSE}"; then
+  as_fn_error $? "conditional \"USE_USERPTR\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${USE_ASYNC_SWAP_TRUE}" && test -z "${USE_ASYNC_SWAP_FALSE}"; then
+  as_fn_error $? "conditional \"USE_ASYNC_SWAP\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
 if test -z "${DRI_TRUE}" && test -z "${DRI_FALSE}"; then
   as_fn_error $? "conditional \"DRI\" was never defined.
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
 fi
+if test -z "${DRI2_TRUE}" && test -z "${DRI2_FALSE}"; then
+  as_fn_error $? "conditional \"DRI2\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
 if test -z "${XVMC_TRUE}" && test -z "${XVMC_FALSE}"; then
   as_fn_error $? "conditional \"XVMC\" was never defined.
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
@@ -12178,8 +20095,20 @@ if test -z "${KMS_ONLY_TRUE}" && test -z "${KMS_ONLY_FALSE}"; then
   as_fn_error $? "conditional \"KMS_ONLY\" was never defined.
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
 fi
+if test -z "${UMS_ONLY_TRUE}" && test -z "${UMS_ONLY_FALSE}"; then
+  as_fn_error $? "conditional \"UMS_ONLY\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${DEBUG_TRUE}" && test -z "${DEBUG_FALSE}"; then
+  as_fn_error $? "conditional \"DEBUG\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${FULL_DEBUG_TRUE}" && test -z "${FULL_DEBUG_FALSE}"; then
+  as_fn_error $? "conditional \"FULL_DEBUG\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
 
-: ${CONFIG_STATUS=./config.status}
+: "${CONFIG_STATUS=./config.status}"
 ac_write_fail=0
 ac_clean_files_save=$ac_clean_files
 ac_clean_files="$ac_clean_files $CONFIG_STATUS"
@@ -12280,6 +20209,7 @@ fi
 IFS=" ""       $as_nl"
 
 # Find who we are.  Look in the path if we contain no directory separator.
+as_myself=
 case $0 in #((
   *[\\/]* ) as_myself=$0 ;;
   *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
@@ -12475,16 +20405,16 @@ if (echo >conf$$.file) 2>/dev/null; then
     # ... but there are two gotchas:
     # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.
     # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.
-    # In both cases, we have to default to `cp -p'.
+    # In both cases, we have to default to `cp -pR'.
     ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||
-      as_ln_s='cp -p'
+      as_ln_s='cp -pR'
   elif ln conf$$.file conf$$ 2>/dev/null; then
     as_ln_s=ln
   else
-    as_ln_s='cp -p'
+    as_ln_s='cp -pR'
   fi
 else
-  as_ln_s='cp -p'
+  as_ln_s='cp -pR'
 fi
 rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file
 rmdir conf$$.dir 2>/dev/null
@@ -12544,28 +20474,16 @@ else
   as_mkdir_p=false
 fi
 
-if test -x / >/dev/null 2>&1; then
-  as_test_x='test -x'
-else
-  if ls -dL / >/dev/null 2>&1; then
-    as_ls_L_option=L
-  else
-    as_ls_L_option=
-  fi
-  as_test_x='
-    eval sh -c '\''
-      if test -d "$1"; then
-       test -d "$1/.";
-      else
-       case $1 in #(
-       -*)set "./$1";;
-       esac;
-       case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #((
-       ???[sx]*):;;*)false;;esac;fi
-    '\'' sh
-  '
-fi
-as_executable_p=$as_test_x
+
+# as_fn_executable_p FILE
+# -----------------------
+# Test if FILE is an executable regular file.
+as_fn_executable_p ()
+{
+  test -f "$1" && test -x "$1"
+} # as_fn_executable_p
+as_test_x='test -x'
+as_executable_p=as_fn_executable_p
 
 # Sed expression to map a string onto a valid CPP name.
 as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
@@ -12586,8 +20504,8 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
 # report actual input values of CONFIG_FILES etc. instead of their
 # values after options handling.
 ac_log="
-This file was extended by xf86-video-intel $as_me 2.15.0, which was
-generated by GNU Autoconf 2.67.  Invocation command line was
+This file was extended by xf86-video-intel $as_me 2.20.9, which was
+generated by GNU Autoconf 2.69.  Invocation command line was
 
   CONFIG_FILES    = $CONFIG_FILES
   CONFIG_HEADERS  = $CONFIG_HEADERS
@@ -12652,11 +20570,11 @@ _ACEOF
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
 ac_cs_version="\\
-xf86-video-intel config.status 2.15.0
-configured by $0, generated by GNU Autoconf 2.67,
+xf86-video-intel config.status 2.20.9
+configured by $0, generated by GNU Autoconf 2.69,
   with options \\"\$ac_cs_config\\"
 
-Copyright (C) 2010 Free Software Foundation, Inc.
+Copyright (C) 2012 Free Software Foundation, Inc.
 This config.status script is free software; the Free Software Foundation
 gives unlimited permission to copy, distribute and modify it."
 
@@ -12747,7 +20665,7 @@ fi
 _ACEOF
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 if \$ac_cs_recheck; then
-  set X '$SHELL' '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion
+  set X $SHELL '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion
   shift
   \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6
   CONFIG_SHELL='$SHELL'
@@ -12781,131 +20699,154 @@ AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir"
 sed_quote_subst='$sed_quote_subst'
 double_quote_subst='$double_quote_subst'
 delay_variable_subst='$delay_variable_subst'
-macro_version='`$ECHO "X$macro_version" | $Xsed -e "$delay_single_quote_subst"`'
-macro_revision='`$ECHO "X$macro_revision" | $Xsed -e "$delay_single_quote_subst"`'
-enable_static='`$ECHO "X$enable_static" | $Xsed -e "$delay_single_quote_subst"`'
-enable_shared='`$ECHO "X$enable_shared" | $Xsed -e "$delay_single_quote_subst"`'
-pic_mode='`$ECHO "X$pic_mode" | $Xsed -e "$delay_single_quote_subst"`'
-enable_fast_install='`$ECHO "X$enable_fast_install" | $Xsed -e "$delay_single_quote_subst"`'
-host_alias='`$ECHO "X$host_alias" | $Xsed -e "$delay_single_quote_subst"`'
-host='`$ECHO "X$host" | $Xsed -e "$delay_single_quote_subst"`'
-host_os='`$ECHO "X$host_os" | $Xsed -e "$delay_single_quote_subst"`'
-build_alias='`$ECHO "X$build_alias" | $Xsed -e "$delay_single_quote_subst"`'
-build='`$ECHO "X$build" | $Xsed -e "$delay_single_quote_subst"`'
-build_os='`$ECHO "X$build_os" | $Xsed -e "$delay_single_quote_subst"`'
-SED='`$ECHO "X$SED" | $Xsed -e "$delay_single_quote_subst"`'
-Xsed='`$ECHO "X$Xsed" | $Xsed -e "$delay_single_quote_subst"`'
-GREP='`$ECHO "X$GREP" | $Xsed -e "$delay_single_quote_subst"`'
-EGREP='`$ECHO "X$EGREP" | $Xsed -e "$delay_single_quote_subst"`'
-FGREP='`$ECHO "X$FGREP" | $Xsed -e "$delay_single_quote_subst"`'
-LD='`$ECHO "X$LD" | $Xsed -e "$delay_single_quote_subst"`'
-NM='`$ECHO "X$NM" | $Xsed -e "$delay_single_quote_subst"`'
-LN_S='`$ECHO "X$LN_S" | $Xsed -e "$delay_single_quote_subst"`'
-max_cmd_len='`$ECHO "X$max_cmd_len" | $Xsed -e "$delay_single_quote_subst"`'
-ac_objext='`$ECHO "X$ac_objext" | $Xsed -e "$delay_single_quote_subst"`'
-exeext='`$ECHO "X$exeext" | $Xsed -e "$delay_single_quote_subst"`'
-lt_unset='`$ECHO "X$lt_unset" | $Xsed -e "$delay_single_quote_subst"`'
-lt_SP2NL='`$ECHO "X$lt_SP2NL" | $Xsed -e "$delay_single_quote_subst"`'
-lt_NL2SP='`$ECHO "X$lt_NL2SP" | $Xsed -e "$delay_single_quote_subst"`'
-reload_flag='`$ECHO "X$reload_flag" | $Xsed -e "$delay_single_quote_subst"`'
-reload_cmds='`$ECHO "X$reload_cmds" | $Xsed -e "$delay_single_quote_subst"`'
-OBJDUMP='`$ECHO "X$OBJDUMP" | $Xsed -e "$delay_single_quote_subst"`'
-deplibs_check_method='`$ECHO "X$deplibs_check_method" | $Xsed -e "$delay_single_quote_subst"`'
-file_magic_cmd='`$ECHO "X$file_magic_cmd" | $Xsed -e "$delay_single_quote_subst"`'
-AR='`$ECHO "X$AR" | $Xsed -e "$delay_single_quote_subst"`'
-AR_FLAGS='`$ECHO "X$AR_FLAGS" | $Xsed -e "$delay_single_quote_subst"`'
-STRIP='`$ECHO "X$STRIP" | $Xsed -e "$delay_single_quote_subst"`'
-RANLIB='`$ECHO "X$RANLIB" | $Xsed -e "$delay_single_quote_subst"`'
-old_postinstall_cmds='`$ECHO "X$old_postinstall_cmds" | $Xsed -e "$delay_single_quote_subst"`'
-old_postuninstall_cmds='`$ECHO "X$old_postuninstall_cmds" | $Xsed -e "$delay_single_quote_subst"`'
-old_archive_cmds='`$ECHO "X$old_archive_cmds" | $Xsed -e "$delay_single_quote_subst"`'
-CC='`$ECHO "X$CC" | $Xsed -e "$delay_single_quote_subst"`'
-CFLAGS='`$ECHO "X$CFLAGS" | $Xsed -e "$delay_single_quote_subst"`'
-compiler='`$ECHO "X$compiler" | $Xsed -e "$delay_single_quote_subst"`'
-GCC='`$ECHO "X$GCC" | $Xsed -e "$delay_single_quote_subst"`'
-lt_cv_sys_global_symbol_pipe='`$ECHO "X$lt_cv_sys_global_symbol_pipe" | $Xsed -e "$delay_single_quote_subst"`'
-lt_cv_sys_global_symbol_to_cdecl='`$ECHO "X$lt_cv_sys_global_symbol_to_cdecl" | $Xsed -e "$delay_single_quote_subst"`'
-lt_cv_sys_global_symbol_to_c_name_address='`$ECHO "X$lt_cv_sys_global_symbol_to_c_name_address" | $Xsed -e "$delay_single_quote_subst"`'
-lt_cv_sys_global_symbol_to_c_name_address_lib_prefix='`$ECHO "X$lt_cv_sys_global_symbol_to_c_name_address_lib_prefix" | $Xsed -e "$delay_single_quote_subst"`'
-objdir='`$ECHO "X$objdir" | $Xsed -e "$delay_single_quote_subst"`'
-SHELL='`$ECHO "X$SHELL" | $Xsed -e "$delay_single_quote_subst"`'
-ECHO='`$ECHO "X$ECHO" | $Xsed -e "$delay_single_quote_subst"`'
-MAGIC_CMD='`$ECHO "X$MAGIC_CMD" | $Xsed -e "$delay_single_quote_subst"`'
-lt_prog_compiler_no_builtin_flag='`$ECHO "X$lt_prog_compiler_no_builtin_flag" | $Xsed -e "$delay_single_quote_subst"`'
-lt_prog_compiler_wl='`$ECHO "X$lt_prog_compiler_wl" | $Xsed -e "$delay_single_quote_subst"`'
-lt_prog_compiler_pic='`$ECHO "X$lt_prog_compiler_pic" | $Xsed -e "$delay_single_quote_subst"`'
-lt_prog_compiler_static='`$ECHO "X$lt_prog_compiler_static" | $Xsed -e "$delay_single_quote_subst"`'
-lt_cv_prog_compiler_c_o='`$ECHO "X$lt_cv_prog_compiler_c_o" | $Xsed -e "$delay_single_quote_subst"`'
-need_locks='`$ECHO "X$need_locks" | $Xsed -e "$delay_single_quote_subst"`'
-DSYMUTIL='`$ECHO "X$DSYMUTIL" | $Xsed -e "$delay_single_quote_subst"`'
-NMEDIT='`$ECHO "X$NMEDIT" | $Xsed -e "$delay_single_quote_subst"`'
-LIPO='`$ECHO "X$LIPO" | $Xsed -e "$delay_single_quote_subst"`'
-OTOOL='`$ECHO "X$OTOOL" | $Xsed -e "$delay_single_quote_subst"`'
-OTOOL64='`$ECHO "X$OTOOL64" | $Xsed -e "$delay_single_quote_subst"`'
-libext='`$ECHO "X$libext" | $Xsed -e "$delay_single_quote_subst"`'
-shrext_cmds='`$ECHO "X$shrext_cmds" | $Xsed -e "$delay_single_quote_subst"`'
-extract_expsyms_cmds='`$ECHO "X$extract_expsyms_cmds" | $Xsed -e "$delay_single_quote_subst"`'
-archive_cmds_need_lc='`$ECHO "X$archive_cmds_need_lc" | $Xsed -e "$delay_single_quote_subst"`'
-enable_shared_with_static_runtimes='`$ECHO "X$enable_shared_with_static_runtimes" | $Xsed -e "$delay_single_quote_subst"`'
-export_dynamic_flag_spec='`$ECHO "X$export_dynamic_flag_spec" | $Xsed -e "$delay_single_quote_subst"`'
-whole_archive_flag_spec='`$ECHO "X$whole_archive_flag_spec" | $Xsed -e "$delay_single_quote_subst"`'
-compiler_needs_object='`$ECHO "X$compiler_needs_object" | $Xsed -e "$delay_single_quote_subst"`'
-old_archive_from_new_cmds='`$ECHO "X$old_archive_from_new_cmds" | $Xsed -e "$delay_single_quote_subst"`'
-old_archive_from_expsyms_cmds='`$ECHO "X$old_archive_from_expsyms_cmds" | $Xsed -e "$delay_single_quote_subst"`'
-archive_cmds='`$ECHO "X$archive_cmds" | $Xsed -e "$delay_single_quote_subst"`'
-archive_expsym_cmds='`$ECHO "X$archive_expsym_cmds" | $Xsed -e "$delay_single_quote_subst"`'
-module_cmds='`$ECHO "X$module_cmds" | $Xsed -e "$delay_single_quote_subst"`'
-module_expsym_cmds='`$ECHO "X$module_expsym_cmds" | $Xsed -e "$delay_single_quote_subst"`'
-with_gnu_ld='`$ECHO "X$with_gnu_ld" | $Xsed -e "$delay_single_quote_subst"`'
-allow_undefined_flag='`$ECHO "X$allow_undefined_flag" | $Xsed -e "$delay_single_quote_subst"`'
-no_undefined_flag='`$ECHO "X$no_undefined_flag" | $Xsed -e "$delay_single_quote_subst"`'
-hardcode_libdir_flag_spec='`$ECHO "X$hardcode_libdir_flag_spec" | $Xsed -e "$delay_single_quote_subst"`'
-hardcode_libdir_flag_spec_ld='`$ECHO "X$hardcode_libdir_flag_spec_ld" | $Xsed -e "$delay_single_quote_subst"`'
-hardcode_libdir_separator='`$ECHO "X$hardcode_libdir_separator" | $Xsed -e "$delay_single_quote_subst"`'
-hardcode_direct='`$ECHO "X$hardcode_direct" | $Xsed -e "$delay_single_quote_subst"`'
-hardcode_direct_absolute='`$ECHO "X$hardcode_direct_absolute" | $Xsed -e "$delay_single_quote_subst"`'
-hardcode_minus_L='`$ECHO "X$hardcode_minus_L" | $Xsed -e "$delay_single_quote_subst"`'
-hardcode_shlibpath_var='`$ECHO "X$hardcode_shlibpath_var" | $Xsed -e "$delay_single_quote_subst"`'
-hardcode_automatic='`$ECHO "X$hardcode_automatic" | $Xsed -e "$delay_single_quote_subst"`'
-inherit_rpath='`$ECHO "X$inherit_rpath" | $Xsed -e "$delay_single_quote_subst"`'
-link_all_deplibs='`$ECHO "X$link_all_deplibs" | $Xsed -e "$delay_single_quote_subst"`'
-fix_srcfile_path='`$ECHO "X$fix_srcfile_path" | $Xsed -e "$delay_single_quote_subst"`'
-always_export_symbols='`$ECHO "X$always_export_symbols" | $Xsed -e "$delay_single_quote_subst"`'
-export_symbols_cmds='`$ECHO "X$export_symbols_cmds" | $Xsed -e "$delay_single_quote_subst"`'
-exclude_expsyms='`$ECHO "X$exclude_expsyms" | $Xsed -e "$delay_single_quote_subst"`'
-include_expsyms='`$ECHO "X$include_expsyms" | $Xsed -e "$delay_single_quote_subst"`'
-prelink_cmds='`$ECHO "X$prelink_cmds" | $Xsed -e "$delay_single_quote_subst"`'
-file_list_spec='`$ECHO "X$file_list_spec" | $Xsed -e "$delay_single_quote_subst"`'
-variables_saved_for_relink='`$ECHO "X$variables_saved_for_relink" | $Xsed -e "$delay_single_quote_subst"`'
-need_lib_prefix='`$ECHO "X$need_lib_prefix" | $Xsed -e "$delay_single_quote_subst"`'
-need_version='`$ECHO "X$need_version" | $Xsed -e "$delay_single_quote_subst"`'
-version_type='`$ECHO "X$version_type" | $Xsed -e "$delay_single_quote_subst"`'
-runpath_var='`$ECHO "X$runpath_var" | $Xsed -e "$delay_single_quote_subst"`'
-shlibpath_var='`$ECHO "X$shlibpath_var" | $Xsed -e "$delay_single_quote_subst"`'
-shlibpath_overrides_runpath='`$ECHO "X$shlibpath_overrides_runpath" | $Xsed -e "$delay_single_quote_subst"`'
-libname_spec='`$ECHO "X$libname_spec" | $Xsed -e "$delay_single_quote_subst"`'
-library_names_spec='`$ECHO "X$library_names_spec" | $Xsed -e "$delay_single_quote_subst"`'
-soname_spec='`$ECHO "X$soname_spec" | $Xsed -e "$delay_single_quote_subst"`'
-postinstall_cmds='`$ECHO "X$postinstall_cmds" | $Xsed -e "$delay_single_quote_subst"`'
-postuninstall_cmds='`$ECHO "X$postuninstall_cmds" | $Xsed -e "$delay_single_quote_subst"`'
-finish_cmds='`$ECHO "X$finish_cmds" | $Xsed -e "$delay_single_quote_subst"`'
-finish_eval='`$ECHO "X$finish_eval" | $Xsed -e "$delay_single_quote_subst"`'
-hardcode_into_libs='`$ECHO "X$hardcode_into_libs" | $Xsed -e "$delay_single_quote_subst"`'
-sys_lib_search_path_spec='`$ECHO "X$sys_lib_search_path_spec" | $Xsed -e "$delay_single_quote_subst"`'
-sys_lib_dlsearch_path_spec='`$ECHO "X$sys_lib_dlsearch_path_spec" | $Xsed -e "$delay_single_quote_subst"`'
-hardcode_action='`$ECHO "X$hardcode_action" | $Xsed -e "$delay_single_quote_subst"`'
-enable_dlopen='`$ECHO "X$enable_dlopen" | $Xsed -e "$delay_single_quote_subst"`'
-enable_dlopen_self='`$ECHO "X$enable_dlopen_self" | $Xsed -e "$delay_single_quote_subst"`'
-enable_dlopen_self_static='`$ECHO "X$enable_dlopen_self_static" | $Xsed -e "$delay_single_quote_subst"`'
-old_striplib='`$ECHO "X$old_striplib" | $Xsed -e "$delay_single_quote_subst"`'
-striplib='`$ECHO "X$striplib" | $Xsed -e "$delay_single_quote_subst"`'
+enable_static='`$ECHO "$enable_static" | $SED "$delay_single_quote_subst"`'
+macro_version='`$ECHO "$macro_version" | $SED "$delay_single_quote_subst"`'
+macro_revision='`$ECHO "$macro_revision" | $SED "$delay_single_quote_subst"`'
+enable_shared='`$ECHO "$enable_shared" | $SED "$delay_single_quote_subst"`'
+pic_mode='`$ECHO "$pic_mode" | $SED "$delay_single_quote_subst"`'
+enable_fast_install='`$ECHO "$enable_fast_install" | $SED "$delay_single_quote_subst"`'
+SHELL='`$ECHO "$SHELL" | $SED "$delay_single_quote_subst"`'
+ECHO='`$ECHO "$ECHO" | $SED "$delay_single_quote_subst"`'
+PATH_SEPARATOR='`$ECHO "$PATH_SEPARATOR" | $SED "$delay_single_quote_subst"`'
+host_alias='`$ECHO "$host_alias" | $SED "$delay_single_quote_subst"`'
+host='`$ECHO "$host" | $SED "$delay_single_quote_subst"`'
+host_os='`$ECHO "$host_os" | $SED "$delay_single_quote_subst"`'
+build_alias='`$ECHO "$build_alias" | $SED "$delay_single_quote_subst"`'
+build='`$ECHO "$build" | $SED "$delay_single_quote_subst"`'
+build_os='`$ECHO "$build_os" | $SED "$delay_single_quote_subst"`'
+SED='`$ECHO "$SED" | $SED "$delay_single_quote_subst"`'
+Xsed='`$ECHO "$Xsed" | $SED "$delay_single_quote_subst"`'
+GREP='`$ECHO "$GREP" | $SED "$delay_single_quote_subst"`'
+EGREP='`$ECHO "$EGREP" | $SED "$delay_single_quote_subst"`'
+FGREP='`$ECHO "$FGREP" | $SED "$delay_single_quote_subst"`'
+LD='`$ECHO "$LD" | $SED "$delay_single_quote_subst"`'
+NM='`$ECHO "$NM" | $SED "$delay_single_quote_subst"`'
+LN_S='`$ECHO "$LN_S" | $SED "$delay_single_quote_subst"`'
+max_cmd_len='`$ECHO "$max_cmd_len" | $SED "$delay_single_quote_subst"`'
+ac_objext='`$ECHO "$ac_objext" | $SED "$delay_single_quote_subst"`'
+exeext='`$ECHO "$exeext" | $SED "$delay_single_quote_subst"`'
+lt_unset='`$ECHO "$lt_unset" | $SED "$delay_single_quote_subst"`'
+lt_SP2NL='`$ECHO "$lt_SP2NL" | $SED "$delay_single_quote_subst"`'
+lt_NL2SP='`$ECHO "$lt_NL2SP" | $SED "$delay_single_quote_subst"`'
+lt_cv_to_host_file_cmd='`$ECHO "$lt_cv_to_host_file_cmd" | $SED "$delay_single_quote_subst"`'
+lt_cv_to_tool_file_cmd='`$ECHO "$lt_cv_to_tool_file_cmd" | $SED "$delay_single_quote_subst"`'
+reload_flag='`$ECHO "$reload_flag" | $SED "$delay_single_quote_subst"`'
+reload_cmds='`$ECHO "$reload_cmds" | $SED "$delay_single_quote_subst"`'
+OBJDUMP='`$ECHO "$OBJDUMP" | $SED "$delay_single_quote_subst"`'
+deplibs_check_method='`$ECHO "$deplibs_check_method" | $SED "$delay_single_quote_subst"`'
+file_magic_cmd='`$ECHO "$file_magic_cmd" | $SED "$delay_single_quote_subst"`'
+file_magic_glob='`$ECHO "$file_magic_glob" | $SED "$delay_single_quote_subst"`'
+want_nocaseglob='`$ECHO "$want_nocaseglob" | $SED "$delay_single_quote_subst"`'
+DLLTOOL='`$ECHO "$DLLTOOL" | $SED "$delay_single_quote_subst"`'
+sharedlib_from_linklib_cmd='`$ECHO "$sharedlib_from_linklib_cmd" | $SED "$delay_single_quote_subst"`'
+AR='`$ECHO "$AR" | $SED "$delay_single_quote_subst"`'
+AR_FLAGS='`$ECHO "$AR_FLAGS" | $SED "$delay_single_quote_subst"`'
+archiver_list_spec='`$ECHO "$archiver_list_spec" | $SED "$delay_single_quote_subst"`'
+STRIP='`$ECHO "$STRIP" | $SED "$delay_single_quote_subst"`'
+RANLIB='`$ECHO "$RANLIB" | $SED "$delay_single_quote_subst"`'
+old_postinstall_cmds='`$ECHO "$old_postinstall_cmds" | $SED "$delay_single_quote_subst"`'
+old_postuninstall_cmds='`$ECHO "$old_postuninstall_cmds" | $SED "$delay_single_quote_subst"`'
+old_archive_cmds='`$ECHO "$old_archive_cmds" | $SED "$delay_single_quote_subst"`'
+lock_old_archive_extraction='`$ECHO "$lock_old_archive_extraction" | $SED "$delay_single_quote_subst"`'
+CC='`$ECHO "$CC" | $SED "$delay_single_quote_subst"`'
+CFLAGS='`$ECHO "$CFLAGS" | $SED "$delay_single_quote_subst"`'
+compiler='`$ECHO "$compiler" | $SED "$delay_single_quote_subst"`'
+GCC='`$ECHO "$GCC" | $SED "$delay_single_quote_subst"`'
+lt_cv_sys_global_symbol_pipe='`$ECHO "$lt_cv_sys_global_symbol_pipe" | $SED "$delay_single_quote_subst"`'
+lt_cv_sys_global_symbol_to_cdecl='`$ECHO "$lt_cv_sys_global_symbol_to_cdecl" | $SED "$delay_single_quote_subst"`'
+lt_cv_sys_global_symbol_to_c_name_address='`$ECHO "$lt_cv_sys_global_symbol_to_c_name_address" | $SED "$delay_single_quote_subst"`'
+lt_cv_sys_global_symbol_to_c_name_address_lib_prefix='`$ECHO "$lt_cv_sys_global_symbol_to_c_name_address_lib_prefix" | $SED "$delay_single_quote_subst"`'
+nm_file_list_spec='`$ECHO "$nm_file_list_spec" | $SED "$delay_single_quote_subst"`'
+lt_sysroot='`$ECHO "$lt_sysroot" | $SED "$delay_single_quote_subst"`'
+objdir='`$ECHO "$objdir" | $SED "$delay_single_quote_subst"`'
+MAGIC_CMD='`$ECHO "$MAGIC_CMD" | $SED "$delay_single_quote_subst"`'
+lt_prog_compiler_no_builtin_flag='`$ECHO "$lt_prog_compiler_no_builtin_flag" | $SED "$delay_single_quote_subst"`'
+lt_prog_compiler_pic='`$ECHO "$lt_prog_compiler_pic" | $SED "$delay_single_quote_subst"`'
+lt_prog_compiler_wl='`$ECHO "$lt_prog_compiler_wl" | $SED "$delay_single_quote_subst"`'
+lt_prog_compiler_static='`$ECHO "$lt_prog_compiler_static" | $SED "$delay_single_quote_subst"`'
+lt_cv_prog_compiler_c_o='`$ECHO "$lt_cv_prog_compiler_c_o" | $SED "$delay_single_quote_subst"`'
+need_locks='`$ECHO "$need_locks" | $SED "$delay_single_quote_subst"`'
+MANIFEST_TOOL='`$ECHO "$MANIFEST_TOOL" | $SED "$delay_single_quote_subst"`'
+DSYMUTIL='`$ECHO "$DSYMUTIL" | $SED "$delay_single_quote_subst"`'
+NMEDIT='`$ECHO "$NMEDIT" | $SED "$delay_single_quote_subst"`'
+LIPO='`$ECHO "$LIPO" | $SED "$delay_single_quote_subst"`'
+OTOOL='`$ECHO "$OTOOL" | $SED "$delay_single_quote_subst"`'
+OTOOL64='`$ECHO "$OTOOL64" | $SED "$delay_single_quote_subst"`'
+libext='`$ECHO "$libext" | $SED "$delay_single_quote_subst"`'
+shrext_cmds='`$ECHO "$shrext_cmds" | $SED "$delay_single_quote_subst"`'
+extract_expsyms_cmds='`$ECHO "$extract_expsyms_cmds" | $SED "$delay_single_quote_subst"`'
+archive_cmds_need_lc='`$ECHO "$archive_cmds_need_lc" | $SED "$delay_single_quote_subst"`'
+enable_shared_with_static_runtimes='`$ECHO "$enable_shared_with_static_runtimes" | $SED "$delay_single_quote_subst"`'
+export_dynamic_flag_spec='`$ECHO "$export_dynamic_flag_spec" | $SED "$delay_single_quote_subst"`'
+whole_archive_flag_spec='`$ECHO "$whole_archive_flag_spec" | $SED "$delay_single_quote_subst"`'
+compiler_needs_object='`$ECHO "$compiler_needs_object" | $SED "$delay_single_quote_subst"`'
+old_archive_from_new_cmds='`$ECHO "$old_archive_from_new_cmds" | $SED "$delay_single_quote_subst"`'
+old_archive_from_expsyms_cmds='`$ECHO "$old_archive_from_expsyms_cmds" | $SED "$delay_single_quote_subst"`'
+archive_cmds='`$ECHO "$archive_cmds" | $SED "$delay_single_quote_subst"`'
+archive_expsym_cmds='`$ECHO "$archive_expsym_cmds" | $SED "$delay_single_quote_subst"`'
+module_cmds='`$ECHO "$module_cmds" | $SED "$delay_single_quote_subst"`'
+module_expsym_cmds='`$ECHO "$module_expsym_cmds" | $SED "$delay_single_quote_subst"`'
+with_gnu_ld='`$ECHO "$with_gnu_ld" | $SED "$delay_single_quote_subst"`'
+allow_undefined_flag='`$ECHO "$allow_undefined_flag" | $SED "$delay_single_quote_subst"`'
+no_undefined_flag='`$ECHO "$no_undefined_flag" | $SED "$delay_single_quote_subst"`'
+hardcode_libdir_flag_spec='`$ECHO "$hardcode_libdir_flag_spec" | $SED "$delay_single_quote_subst"`'
+hardcode_libdir_separator='`$ECHO "$hardcode_libdir_separator" | $SED "$delay_single_quote_subst"`'
+hardcode_direct='`$ECHO "$hardcode_direct" | $SED "$delay_single_quote_subst"`'
+hardcode_direct_absolute='`$ECHO "$hardcode_direct_absolute" | $SED "$delay_single_quote_subst"`'
+hardcode_minus_L='`$ECHO "$hardcode_minus_L" | $SED "$delay_single_quote_subst"`'
+hardcode_shlibpath_var='`$ECHO "$hardcode_shlibpath_var" | $SED "$delay_single_quote_subst"`'
+hardcode_automatic='`$ECHO "$hardcode_automatic" | $SED "$delay_single_quote_subst"`'
+inherit_rpath='`$ECHO "$inherit_rpath" | $SED "$delay_single_quote_subst"`'
+link_all_deplibs='`$ECHO "$link_all_deplibs" | $SED "$delay_single_quote_subst"`'
+always_export_symbols='`$ECHO "$always_export_symbols" | $SED "$delay_single_quote_subst"`'
+export_symbols_cmds='`$ECHO "$export_symbols_cmds" | $SED "$delay_single_quote_subst"`'
+exclude_expsyms='`$ECHO "$exclude_expsyms" | $SED "$delay_single_quote_subst"`'
+include_expsyms='`$ECHO "$include_expsyms" | $SED "$delay_single_quote_subst"`'
+prelink_cmds='`$ECHO "$prelink_cmds" | $SED "$delay_single_quote_subst"`'
+postlink_cmds='`$ECHO "$postlink_cmds" | $SED "$delay_single_quote_subst"`'
+file_list_spec='`$ECHO "$file_list_spec" | $SED "$delay_single_quote_subst"`'
+variables_saved_for_relink='`$ECHO "$variables_saved_for_relink" | $SED "$delay_single_quote_subst"`'
+need_lib_prefix='`$ECHO "$need_lib_prefix" | $SED "$delay_single_quote_subst"`'
+need_version='`$ECHO "$need_version" | $SED "$delay_single_quote_subst"`'
+version_type='`$ECHO "$version_type" | $SED "$delay_single_quote_subst"`'
+runpath_var='`$ECHO "$runpath_var" | $SED "$delay_single_quote_subst"`'
+shlibpath_var='`$ECHO "$shlibpath_var" | $SED "$delay_single_quote_subst"`'
+shlibpath_overrides_runpath='`$ECHO "$shlibpath_overrides_runpath" | $SED "$delay_single_quote_subst"`'
+libname_spec='`$ECHO "$libname_spec" | $SED "$delay_single_quote_subst"`'
+library_names_spec='`$ECHO "$library_names_spec" | $SED "$delay_single_quote_subst"`'
+soname_spec='`$ECHO "$soname_spec" | $SED "$delay_single_quote_subst"`'
+install_override_mode='`$ECHO "$install_override_mode" | $SED "$delay_single_quote_subst"`'
+postinstall_cmds='`$ECHO "$postinstall_cmds" | $SED "$delay_single_quote_subst"`'
+postuninstall_cmds='`$ECHO "$postuninstall_cmds" | $SED "$delay_single_quote_subst"`'
+finish_cmds='`$ECHO "$finish_cmds" | $SED "$delay_single_quote_subst"`'
+finish_eval='`$ECHO "$finish_eval" | $SED "$delay_single_quote_subst"`'
+hardcode_into_libs='`$ECHO "$hardcode_into_libs" | $SED "$delay_single_quote_subst"`'
+sys_lib_search_path_spec='`$ECHO "$sys_lib_search_path_spec" | $SED "$delay_single_quote_subst"`'
+sys_lib_dlsearch_path_spec='`$ECHO "$sys_lib_dlsearch_path_spec" | $SED "$delay_single_quote_subst"`'
+hardcode_action='`$ECHO "$hardcode_action" | $SED "$delay_single_quote_subst"`'
+enable_dlopen='`$ECHO "$enable_dlopen" | $SED "$delay_single_quote_subst"`'
+enable_dlopen_self='`$ECHO "$enable_dlopen_self" | $SED "$delay_single_quote_subst"`'
+enable_dlopen_self_static='`$ECHO "$enable_dlopen_self_static" | $SED "$delay_single_quote_subst"`'
+old_striplib='`$ECHO "$old_striplib" | $SED "$delay_single_quote_subst"`'
+striplib='`$ECHO "$striplib" | $SED "$delay_single_quote_subst"`'
 
 LTCC='$LTCC'
 LTCFLAGS='$LTCFLAGS'
 compiler='$compiler_DEFAULT'
 
+# A function that is used when there is no print builtin or printf.
+func_fallback_echo ()
+{
+  eval 'cat <<_LTECHO_EOF
+\$1
+_LTECHO_EOF'
+}
+
 # Quote evaled strings.
-for var in SED \
+for var in SHELL \
+ECHO \
+PATH_SEPARATOR \
+SED \
 GREP \
 EGREP \
 FGREP \
@@ -12918,8 +20859,13 @@ reload_flag \
 OBJDUMP \
 deplibs_check_method \
 file_magic_cmd \
+file_magic_glob \
+want_nocaseglob \
+DLLTOOL \
+sharedlib_from_linklib_cmd \
 AR \
 AR_FLAGS \
+archiver_list_spec \
 STRIP \
 RANLIB \
 CC \
@@ -12929,14 +20875,14 @@ lt_cv_sys_global_symbol_pipe \
 lt_cv_sys_global_symbol_to_cdecl \
 lt_cv_sys_global_symbol_to_c_name_address \
 lt_cv_sys_global_symbol_to_c_name_address_lib_prefix \
-SHELL \
-ECHO \
+nm_file_list_spec \
 lt_prog_compiler_no_builtin_flag \
-lt_prog_compiler_wl \
 lt_prog_compiler_pic \
+lt_prog_compiler_wl \
 lt_prog_compiler_static \
 lt_cv_prog_compiler_c_o \
 need_locks \
+MANIFEST_TOOL \
 DSYMUTIL \
 NMEDIT \
 LIPO \
@@ -12950,9 +20896,7 @@ with_gnu_ld \
 allow_undefined_flag \
 no_undefined_flag \
 hardcode_libdir_flag_spec \
-hardcode_libdir_flag_spec_ld \
 hardcode_libdir_separator \
-fix_srcfile_path \
 exclude_expsyms \
 include_expsyms \
 file_list_spec \
@@ -12960,12 +20904,13 @@ variables_saved_for_relink \
 libname_spec \
 library_names_spec \
 soname_spec \
+install_override_mode \
 finish_eval \
 old_striplib \
 striplib; do
-    case \`eval \\\\\$ECHO "X\\\\\$\$var"\` in
+    case \`eval \\\\\$ECHO \\\\""\\\\\$\$var"\\\\"\` in
     *[\\\\\\\`\\"\\\$]*)
-      eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"X\\\$\$var\\" | \\\$Xsed -e \\"\\\$sed_quote_subst\\"\\\`\\\\\\""
+      eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"\\\$\$var\\" | \\\$SED \\"\\\$sed_quote_subst\\"\\\`\\\\\\""
       ;;
     *)
       eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\""
@@ -12987,14 +20932,15 @@ module_cmds \
 module_expsym_cmds \
 export_symbols_cmds \
 prelink_cmds \
+postlink_cmds \
 postinstall_cmds \
 postuninstall_cmds \
 finish_cmds \
 sys_lib_search_path_spec \
 sys_lib_dlsearch_path_spec; do
-    case \`eval \\\\\$ECHO "X\\\\\$\$var"\` in
+    case \`eval \\\\\$ECHO \\\\""\\\\\$\$var"\\\\"\` in
     *[\\\\\\\`\\"\\\$]*)
-      eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"X\\\$\$var\\" | \\\$Xsed -e \\"\\\$double_quote_subst\\" -e \\"\\\$sed_quote_subst\\" -e \\"\\\$delay_variable_subst\\"\\\`\\\\\\""
+      eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"\\\$\$var\\" | \\\$SED -e \\"\\\$double_quote_subst\\" -e \\"\\\$sed_quote_subst\\" -e \\"\\\$delay_variable_subst\\"\\\`\\\\\\""
       ;;
     *)
       eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\""
@@ -13002,12 +20948,6 @@ sys_lib_dlsearch_path_spec; do
     esac
 done
 
-# Fix-up fallback echo if it was mangled by the above quoting rules.
-case \$lt_ECHO in
-*'\\\$0 --fallback-echo"')  lt_ECHO=\`\$ECHO "X\$lt_ECHO" | \$Xsed -e 's/\\\\\\\\\\\\\\\$0 --fallback-echo"\$/\$0 --fallback-echo"/'\`
-  ;;
-esac
-
 ac_aux_dir='$ac_aux_dir'
 xsi_shell='$xsi_shell'
 lt_shell_append='$lt_shell_append'
     "src/legacy/Makefile") CONFIG_FILES="$CONFIG_FILES src/legacy/Makefile" ;;
     "src/legacy/i810/Makefile") CONFIG_FILES="$CONFIG_FILES src/legacy/i810/Makefile" ;;
     "src/legacy/i810/xvmc/Makefile") CONFIG_FILES="$CONFIG_FILES src/legacy/i810/xvmc/Makefile" ;;
+    "src/sna/Makefile") CONFIG_FILES="$CONFIG_FILES src/sna/Makefile" ;;
+    "src/sna/brw/Makefile") CONFIG_FILES="$CONFIG_FILES src/sna/brw/Makefile" ;;
+    "src/sna/fb/Makefile") CONFIG_FILES="$CONFIG_FILES src/sna/fb/Makefile" ;;
     "man/Makefile") CONFIG_FILES="$CONFIG_FILES man/Makefile" ;;
     "src/render_program/Makefile") CONFIG_FILES="$CONFIG_FILES src/render_program/Makefile" ;;
+    "test/Makefile") CONFIG_FILES="$CONFIG_FILES test/Makefile" ;;
 
-  *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5 ;;
+  *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;;
   esac
 done
 
 # after its creation but before its name has been assigned to `$tmp'.
 $debug ||
 {
-  tmp=
+  tmp= ac_tmp=
   trap 'exit_status=$?
-  { test -z "$tmp" || test ! -d "$tmp" || rm -fr "$tmp"; } && exit $exit_status
+  : "${ac_tmp:=$tmp}"
+  { test ! -d "$ac_tmp" || rm -fr "$ac_tmp"; } && exit $exit_status
 ' 0
   trap 'as_fn_exit 1' 1 2 13 15
 }
@@ -13085,12 +21030,13 @@ $debug ||
 
 {
   tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` &&
-  test -n "$tmp" && test -d "$tmp"
+  test -d "$tmp"
 }  ||
 {
   tmp=./conf$$-$RANDOM
   (umask 077 && mkdir "$tmp")
 } || as_fn_error $? "cannot create a temporary directory in ." "$LINENO" 5
+ac_tmp=$tmp
 
 # Set up the scripts for CONFIG_FILES section.
 # No need to generate them if there are no CONFIG_FILES.
@@ -13112,7 +21058,7 @@ else
   ac_cs_awk_cr=$ac_cr
 fi
 
-echo 'BEGIN {' >"$tmp/subs1.awk" &&
+echo 'BEGIN {' >"$ac_tmp/subs1.awk" &&
 _ACEOF
 
 
@@ -13140,7 +21086,7 @@ done
 rm -f conf$$subs.sh
 
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
-cat >>"\$tmp/subs1.awk" <<\\_ACAWK &&
+cat >>"\$ac_tmp/subs1.awk" <<\\_ACAWK &&
 _ACEOF
 sed -n '
 h
@@ -13188,7 +21134,7 @@ t delim
 rm -f conf$$subs.awk
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 _ACAWK
-cat >>"\$tmp/subs1.awk" <<_ACAWK &&
+cat >>"\$ac_tmp/subs1.awk" <<_ACAWK &&
   for (key in S) S_is_set[key] = 1
   FS = "\a"
 
@@ -13220,7 +21166,7 @@ if sed "s/$ac_cr//" < /dev/null > /dev/null 2>&1; then
   sed "s/$ac_cr\$//; s/$ac_cr/$ac_cs_awk_cr/g"
 else
   cat
-fi < "$tmp/subs1.awk" > "$tmp/subs.awk" \
+fi < "$ac_tmp/subs1.awk" > "$ac_tmp/subs.awk" \
   || as_fn_error $? "could not setup config files machinery" "$LINENO" 5
 _ACEOF
 
@@ -13254,7 +21200,7 @@ fi # test -n "$CONFIG_FILES"
 # No need to generate them if there are no CONFIG_HEADERS.
 # This happens for instance with `./config.status Makefile'.
 if test -n "$CONFIG_HEADERS"; then
-cat >"$tmp/defines.awk" <<\_ACAWK ||
+cat >"$ac_tmp/defines.awk" <<\_ACAWK ||
 BEGIN {
 _ACEOF
 
@@ -13266,8 +21212,8 @@ _ACEOF
 # handling of long lines.
 ac_delim='%!_!# '
 for ac_last_try in false false :; do
-  ac_t=`sed -n "/$ac_delim/p" confdefs.h`
-  if test -z "$ac_t"; then
+  ac_tt=`sed -n "/$ac_delim/p" confdefs.h`
+  if test -z "$ac_tt"; then
     break
   elif $ac_last_try; then
     as_fn_error $? "could not make $CONFIG_HEADERS" "$LINENO" 5
@@ -13368,7 +21314,7 @@ do
   esac
   case $ac_mode$ac_tag in
   :[FHL]*:*);;
-  :L* | :C*:*) as_fn_error $? "invalid tag \`$ac_tag'" "$LINENO" 5 ;;
+  :L* | :C*:*) as_fn_error $? "invalid tag \`$ac_tag'" "$LINENO" 5;;
   :[FH]-) ac_tag=-:-;;
   :[FH]*) ac_tag=$ac_tag:$ac_tag.in;;
   esac
@@ -13387,7 +21333,7 @@ do
     for ac_f
     do
       case $ac_f in
-      -) ac_f="$tmp/stdin";;
+      -) ac_f="$ac_tmp/stdin";;
       *) # Look for the file first in the build tree, then in the source tree
         # (if the path is not absolute).  The absolute path cannot be DOS-style,
         # because $ac_f cannot contain `:'.
@@ -13396,7 +21342,7 @@ do
           [\\/$]*) false;;
           *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";;
           esac ||
-          as_fn_error 1 "cannot find input file: \`$ac_f'" "$LINENO" 5 ;;
+          as_fn_error 1 "cannot find input file: \`$ac_f'" "$LINENO" 5;;
       esac
       case $ac_f in *\'*) ac_f=`$as_echo "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac
       as_fn_append ac_file_inputs " '$ac_f'"
@@ -13422,8 +21368,8 @@ $as_echo "$as_me: creating $ac_file" >&6;}
     esac
 
     case $ac_tag in
-    *:-:* | *:-) cat >"$tmp/stdin" \
-      || as_fn_error $? "could not create $ac_file" "$LINENO" 5  ;;
+    *:-:* | *:-) cat >"$ac_tmp/stdin" \
+      || as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;;
     esac
     ;;
   esac
@@ -13559,21 +21505,22 @@ s&@INSTALL@&$ac_INSTALL&;t t
 s&@MKDIR_P@&$ac_MKDIR_P&;t t
 $ac_datarootdir_hack
 "
-eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$tmp/subs.awk" >$tmp/out \
-  || as_fn_error $? "could not create $ac_file" "$LINENO" 5
+eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$ac_tmp/subs.awk" \
+  >$ac_tmp/out || as_fn_error $? "could not create $ac_file" "$LINENO" 5
 
 test -z "$ac_datarootdir_hack$ac_datarootdir_seen" &&
-  { ac_out=`sed -n '/\${datarootdir}/p' "$tmp/out"`; test -n "$ac_out"; } &&
-  { ac_out=`sed -n '/^[         ]*datarootdir[  ]*:*=/p' "$tmp/out"`; test -z "$ac_out"; } &&
+  { ac_out=`sed -n '/\${datarootdir}/p' "$ac_tmp/out"`; test -n "$ac_out"; } &&
+  { ac_out=`sed -n '/^[         ]*datarootdir[  ]*:*=/p' \
+      "$ac_tmp/out"`; test -z "$ac_out"; } &&
   { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable \`datarootdir'
 which seems to be undefined.  Please make sure it is defined" >&5
 $as_echo "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir'
 which seems to be undefined.  Please make sure it is defined" >&2;}
 
-  rm -f "$tmp/stdin"
+  rm -f "$ac_tmp/stdin"
   case $ac_file in
-  -) cat "$tmp/out" && rm -f "$tmp/out";;
-  *) rm -f "$ac_file" && mv "$tmp/out" "$ac_file";;
+  -) cat "$ac_tmp/out" && rm -f "$ac_tmp/out";;
+  *) rm -f "$ac_file" && mv "$ac_tmp/out" "$ac_file";;
   esac \
   || as_fn_error $? "could not create $ac_file" "$LINENO" 5
  ;;
@@ -13584,20 +21531,20 @@ which seems to be undefined.  Please make sure it is defined" >&2;}
   if test x"$ac_file" != x-; then
     {
       $as_echo "/* $configure_input  */" \
-      && eval '$AWK -f "$tmp/defines.awk"' "$ac_file_inputs"
-    } >"$tmp/config.h" \
+      && eval '$AWK -f "$ac_tmp/defines.awk"' "$ac_file_inputs"
+    } >"$ac_tmp/config.h" \
       || as_fn_error $? "could not create $ac_file" "$LINENO" 5
-    if diff "$ac_file" "$tmp/config.h" >/dev/null 2>&1; then
+    if diff "$ac_file" "$ac_tmp/config.h" >/dev/null 2>&1; then
       { $as_echo "$as_me:${as_lineno-$LINENO}: $ac_file is unchanged" >&5
 $as_echo "$as_me: $ac_file is unchanged" >&6;}
     else
       rm -f "$ac_file"
-      mv "$tmp/config.h" "$ac_file" \
+      mv "$ac_tmp/config.h" "$ac_file" \
        || as_fn_error $? "could not create $ac_file" "$LINENO" 5
     fi
   else
     $as_echo "/* $configure_input  */" \
-      && eval '$AWK -f "$tmp/defines.awk"' "$ac_file_inputs" \
+      && eval '$AWK -f "$ac_tmp/defines.awk"' "$ac_file_inputs" \
       || as_fn_error $? "could not create -" "$LINENO" 5
   fi
 # Compute "$ac_file"'s index in $config_headers.
@@ -13759,7 +21706,8 @@ $as_echo X"$file" |
 # NOTE: Changes made to this file will be lost: look at ltmain.sh.
 #
 #   Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005,
-#                 2006, 2007, 2008 Free Software Foundation, Inc.
+#                 2006, 2007, 2008, 2009, 2010, 2011 Free Software
+#                 Foundation, Inc.
 #   Written by Gordon Matzigkeit, 1996
 #
 #   This file is part of GNU Libtool.
@@ -13791,13 +21739,13 @@ available_tags=""
 
 # ### BEGIN LIBTOOL CONFIG
 
+# Whether or not to build static libraries.
+build_old_libs=$enable_static
+
 # Which release of libtool.m4 was used?
 macro_version=$macro_version
 macro_revision=$macro_revision
 
-# Whether or not to build static libraries.
-build_old_libs=$enable_static
-
 # Whether or not to build shared libraries.
 build_libtool_libs=$enable_shared
 
@@ -13807,6 +21755,15 @@ pic_mode=$pic_mode
 # Whether or not to optimize for fast installation.
 fast_install=$enable_fast_install
 
+# Shell to use when invoking shell scripts.
+SHELL=$lt_SHELL
+
+# An echo program that protects backslashes.
+ECHO=$lt_ECHO
+
+# The PATH separator for the build system.
+PATH_SEPARATOR=$lt_PATH_SEPARATOR
+
 # The host system.
 host_alias=$host_alias
 host=$host
@@ -13856,9 +21813,11 @@ SP2NL=$lt_lt_SP2NL
 # turn newlines into spaces.
 NL2SP=$lt_lt_NL2SP
 
-# How to create reloadable object files.
-reload_flag=$lt_reload_flag
-reload_cmds=$lt_reload_cmds
+# convert \$build file names to \$host format.
+to_host_file_cmd=$lt_cv_to_host_file_cmd
+
+# convert \$build files to toolchain format.
+to_tool_file_cmd=$lt_cv_to_tool_file_cmd
 
 # An object symbol dumper.
 OBJDUMP=$lt_OBJDUMP
@@ -13866,13 +21825,30 @@ OBJDUMP=$lt_OBJDUMP
 # Method to check whether dependent libraries are shared objects.
 deplibs_check_method=$lt_deplibs_check_method
 
-# Command to use when deplibs_check_method == "file_magic".
+# Command to use when deplibs_check_method = "file_magic".
 file_magic_cmd=$lt_file_magic_cmd
 
+# How to find potential files when deplibs_check_method = "file_magic".
+file_magic_glob=$lt_file_magic_glob
+
+# Find potential files using nocaseglob when deplibs_check_method = "file_magic".
+want_nocaseglob=$lt_want_nocaseglob
+
+# DLL creation program.
+DLLTOOL=$lt_DLLTOOL
+
+# Command to associate shared and link libraries.
+sharedlib_from_linklib_cmd=$lt_sharedlib_from_linklib_cmd
+
 # The archiver.
 AR=$lt_AR
+
+# Flags to create an archive.
 AR_FLAGS=$lt_AR_FLAGS
 
+# How to feed a file listing to the archiver.
+archiver_list_spec=$lt_archiver_list_spec
+
 # A symbol stripping program.
 STRIP=$lt_STRIP
 
@@ -13881,6 +21857,9 @@ RANLIB=$lt_RANLIB
 old_postinstall_cmds=$lt_old_postinstall_cmds
 old_postuninstall_cmds=$lt_old_postuninstall_cmds
 
+# Whether to use a lock for old archive extraction.
+lock_old_archive_extraction=$lock_old_archive_extraction
+
 # A C compiler.
 LTCC=$lt_CC
 
@@ -13899,14 +21878,14 @@ global_symbol_to_c_name_address=$lt_lt_cv_sys_global_symbol_to_c_name_address
 # Transform the output of nm in a C name address pair when lib prefix is needed.
 global_symbol_to_c_name_address_lib_prefix=$lt_lt_cv_sys_global_symbol_to_c_name_address_lib_prefix
 
-# The name of the directory that contains temporary libtool files.
-objdir=$objdir
+# Specify filename containing input files for \$NM.
+nm_file_list_spec=$lt_nm_file_list_spec
 
-# Shell to use when invoking shell scripts.
-SHELL=$lt_SHELL
+# The root where to search for dependent libraries,and in which our libraries should be installed.
+lt_sysroot=$lt_sysroot
 
-# An echo program that does not interpret backslashes.
-ECHO=$lt_ECHO
+# The name of the directory that contains temporary libtool files.
+objdir=$objdir
 
 # Used to examine libraries when file_magic_cmd begins with "file".
 MAGIC_CMD=$MAGIC_CMD
@@ -13914,6 +21893,9 @@ MAGIC_CMD=$MAGIC_CMD
 # Must we lock files when doing compilation?
 need_locks=$lt_need_locks
 
+# Manifest tool.
+MANIFEST_TOOL=$lt_MANIFEST_TOOL
+
 # Tool to manipulate archived DWARF debug symbol files on Mac OS X.
 DSYMUTIL=$lt_DSYMUTIL
 
@@ -13970,6 +21952,9 @@ library_names_spec=$lt_library_names_spec
 # The coded name of the library, if different from the real name.
 soname_spec=$lt_soname_spec
 
+# Permission mode override for installation of shared libraries.
+install_override_mode=$lt_install_override_mode
+
 # Command to use after installation of a shared archive.
 postinstall_cmds=$lt_postinstall_cmds
 
@@ -14009,6 +21994,10 @@ striplib=$lt_striplib
 # The linker used to build libraries.
 LD=$lt_LD
 
+# How to create reloadable object files.
+reload_flag=$lt_reload_flag
+reload_cmds=$lt_reload_cmds
+
 # Commands used to build an old-style archive.
 old_archive_cmds=$lt_old_archive_cmds
 
@@ -14021,12 +22010,12 @@ with_gcc=$GCC
 # Compiler flag to turn off builtin functions.
 no_builtin_flag=$lt_lt_prog_compiler_no_builtin_flag
 
-# How to pass a linker flag through the compiler.
-wl=$lt_lt_prog_compiler_wl
-
 # Additional compiler flags for building library objects.
 pic_flag=$lt_lt_prog_compiler_pic
 
+# How to pass a linker flag through the compiler.
+wl=$lt_lt_prog_compiler_wl
+
 # Compiler flag to prevent dynamic linking.
 link_static_flag=$lt_lt_prog_compiler_static
 
@@ -14076,10 +22065,6 @@ no_undefined_flag=$lt_no_undefined_flag
 # This must work even if \$libdir does not exist
 hardcode_libdir_flag_spec=$lt_hardcode_libdir_flag_spec
 
-# If ld is used when linking, flag to hardcode \$libdir into a binary
-# during linking.  This must work even if \$libdir does not exist.
-hardcode_libdir_flag_spec_ld=$lt_hardcode_libdir_flag_spec_ld
-
 # Whether we need a single "-rpath" flag with a separated argument.
 hardcode_libdir_separator=$lt_hardcode_libdir_separator
 
@@ -14113,9 +22098,6 @@ inherit_rpath=$inherit_rpath
 # Whether libtool must link a program against all its dependency libraries.
 link_all_deplibs=$link_all_deplibs
 
-# Fix the shell variable \$srcfile for the compiler.
-fix_srcfile_path=$lt_fix_srcfile_path
-
 # Set to "yes" if exported symbols are required.
 always_export_symbols=$always_export_symbols
 
@@ -14131,6 +22113,9 @@ include_expsyms=$lt_include_expsyms
 # Commands necessary for linking programs (against libraries) with templates.
 prelink_cmds=$lt_prelink_cmds
 
+# Commands necessary for finishing linking programs.
+postlink_cmds=$lt_postlink_cmds
+
 # Specify filename containing input files.
 file_list_spec=$lt_file_list_spec
 
@@ -14163,212 +22148,169 @@ ltmain="$ac_aux_dir/ltmain.sh"
   # if finds mixed CR/LF and LF-only lines.  Since sed operates in
   # text mode, it properly converts lines to CR/LF.  This bash problem
   # is reportedly fixed, but why not run on old versions too?
-  sed '/^# Generated shell functions inserted here/q' "$ltmain" >> "$cfgfile" \
-    || (rm -f "$cfgfile"; exit 1)
-
-  case $xsi_shell in
-  yes)
-    cat << \_LT_EOF >> "$cfgfile"
-
-# func_dirname file append nondir_replacement
-# Compute the dirname of FILE.  If nonempty, add APPEND to the result,
-# otherwise set result to NONDIR_REPLACEMENT.
-func_dirname ()
-{
-  case ${1} in
-    */*) func_dirname_result="${1%/*}${2}" ;;
-    *  ) func_dirname_result="${3}" ;;
-  esac
-}
-
-# func_basename file
-func_basename ()
-{
-  func_basename_result="${1##*/}"
-}
-
-# func_dirname_and_basename file append nondir_replacement
-# perform func_basename and func_dirname in a single function
-# call:
-#   dirname:  Compute the dirname of FILE.  If nonempty,
-#             add APPEND to the result, otherwise set result
-#             to NONDIR_REPLACEMENT.
-#             value returned in "$func_dirname_result"
-#   basename: Compute filename of FILE.
-#             value retuned in "$func_basename_result"
-# Implementation must be kept synchronized with func_dirname
-# and func_basename. For efficiency, we do not delegate to
-# those functions but instead duplicate the functionality here.
-func_dirname_and_basename ()
-{
-  case ${1} in
-    */*) func_dirname_result="${1%/*}${2}" ;;
-    *  ) func_dirname_result="${3}" ;;
-  esac
-  func_basename_result="${1##*/}"
-}
-
-# func_stripname prefix suffix name
-# strip PREFIX and SUFFIX off of NAME.
-# PREFIX and SUFFIX must not contain globbing or regex special
-# characters, hashes, percent signs, but SUFFIX may contain a leading
-# dot (in which case that matches only a dot).
-func_stripname ()
-{
-  # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are
-  # positional parameters, so assign one to ordinary parameter first.
-  func_stripname_result=${3}
-  func_stripname_result=${func_stripname_result#"${1}"}
-  func_stripname_result=${func_stripname_result%"${2}"}
-}
-
-# func_opt_split
-func_opt_split ()
-{
-  func_opt_split_opt=${1%%=*}
-  func_opt_split_arg=${1#*=}
-}
-
-# func_lo2o object
-func_lo2o ()
-{
-  case ${1} in
-    *.lo) func_lo2o_result=${1%.lo}.${objext} ;;
-    *)    func_lo2o_result=${1} ;;
-  esac
-}
-
-# func_xform libobj-or-source
-func_xform ()
-{
-  func_xform_result=${1%.*}.lo
-}
-
-# func_arith arithmetic-term...
-func_arith ()
-{
-  func_arith_result=$(( $* ))
-}
-
-# func_len string
-# STRING may not start with a hyphen.
-func_len ()
-{
-  func_len_result=${#1}
-}
-
-_LT_EOF
-    ;;
-  *) # Bourne compatible functions.
-    cat << \_LT_EOF >> "$cfgfile"
-
-# func_dirname file append nondir_replacement
-# Compute the dirname of FILE.  If nonempty, add APPEND to the result,
-# otherwise set result to NONDIR_REPLACEMENT.
-func_dirname ()
-{
-  # Extract subdirectory from the argument.
-  func_dirname_result=`$ECHO "X${1}" | $Xsed -e "$dirname"`
-  if test "X$func_dirname_result" = "X${1}"; then
-    func_dirname_result="${3}"
-  else
-    func_dirname_result="$func_dirname_result${2}"
-  fi
-}
-
-# func_basename file
-func_basename ()
-{
-  func_basename_result=`$ECHO "X${1}" | $Xsed -e "$basename"`
-}
-
-
-# func_stripname prefix suffix name
-# strip PREFIX and SUFFIX off of NAME.
-# PREFIX and SUFFIX must not contain globbing or regex special
-# characters, hashes, percent signs, but SUFFIX may contain a leading
-# dot (in which case that matches only a dot).
-# func_strip_suffix prefix name
-func_stripname ()
-{
-  case ${2} in
-    .*) func_stripname_result=`$ECHO "X${3}" \
-           | $Xsed -e "s%^${1}%%" -e "s%\\\\${2}\$%%"`;;
-    *)  func_stripname_result=`$ECHO "X${3}" \
-           | $Xsed -e "s%^${1}%%" -e "s%${2}\$%%"`;;
-  esac
-}
-
-# sed scripts:
-my_sed_long_opt='1s/^\(-[^=]*\)=.*/\1/;q'
-my_sed_long_arg='1s/^-[^=]*=//'
-
-# func_opt_split
-func_opt_split ()
-{
-  func_opt_split_opt=`$ECHO "X${1}" | $Xsed -e "$my_sed_long_opt"`
-  func_opt_split_arg=`$ECHO "X${1}" | $Xsed -e "$my_sed_long_arg"`
-}
-
-# func_lo2o object
-func_lo2o ()
-{
-  func_lo2o_result=`$ECHO "X${1}" | $Xsed -e "$lo2o"`
-}
-
-# func_xform libobj-or-source
-func_xform ()
-{
-  func_xform_result=`$ECHO "X${1}" | $Xsed -e 's/\.[^.]*$/.lo/'`
-}
-
-# func_arith arithmetic-term...
-func_arith ()
-{
-  func_arith_result=`expr "$@"`
-}
-
-# func_len string
-# STRING may not start with a hyphen.
-func_len ()
-{
-  func_len_result=`expr "$1" : ".*" 2>/dev/null || echo $max_cmd_len`
-}
-
-_LT_EOF
-esac
-
-case $lt_shell_append in
-  yes)
-    cat << \_LT_EOF >> "$cfgfile"
-
-# func_append var value
-# Append VALUE to the end of shell variable VAR.
-func_append ()
-{
-  eval "$1+=\$2"
-}
-_LT_EOF
-    ;;
-  *)
-    cat << \_LT_EOF >> "$cfgfile"
-
-# func_append var value
-# Append VALUE to the end of shell variable VAR.
-func_append ()
-{
-  eval "$1=\$$1\$2"
-}
-
-_LT_EOF
-    ;;
-  esac
-
-
-  sed -n '/^# Generated shell functions inserted here/,$p' "$ltmain" >> "$cfgfile" \
-    || (rm -f "$cfgfile"; exit 1)
-
-  mv -f "$cfgfile" "$ofile" ||
+  sed '$q' "$ltmain" >> "$cfgfile" \
+     || (rm -f "$cfgfile"; exit 1)
+
+  if test x"$xsi_shell" = xyes; then
+  sed -e '/^func_dirname ()$/,/^} # func_dirname /c\
+func_dirname ()\
+{\
+\    case ${1} in\
+\      */*) func_dirname_result="${1%/*}${2}" ;;\
+\      *  ) func_dirname_result="${3}" ;;\
+\    esac\
+} # Extended-shell func_dirname implementation' "$cfgfile" > $cfgfile.tmp \
+  && mv -f "$cfgfile.tmp" "$cfgfile" \
+    || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp")
+test 0 -eq $? || _lt_function_replace_fail=:
+
+
+  sed -e '/^func_basename ()$/,/^} # func_basename /c\
+func_basename ()\
+{\
+\    func_basename_result="${1##*/}"\
+} # Extended-shell func_basename implementation' "$cfgfile" > $cfgfile.tmp \
+  && mv -f "$cfgfile.tmp" "$cfgfile" \
+    || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp")
+test 0 -eq $? || _lt_function_replace_fail=:
+
+
+  sed -e '/^func_dirname_and_basename ()$/,/^} # func_dirname_and_basename /c\
+func_dirname_and_basename ()\
+{\
+\    case ${1} in\
+\      */*) func_dirname_result="${1%/*}${2}" ;;\
+\      *  ) func_dirname_result="${3}" ;;\
+\    esac\
+\    func_basename_result="${1##*/}"\
+} # Extended-shell func_dirname_and_basename implementation' "$cfgfile" > $cfgfile.tmp \
+  && mv -f "$cfgfile.tmp" "$cfgfile" \
+    || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp")
+test 0 -eq $? || _lt_function_replace_fail=:
+
+
+  sed -e '/^func_stripname ()$/,/^} # func_stripname /c\
+func_stripname ()\
+{\
+\    # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are\
+\    # positional parameters, so assign one to ordinary parameter first.\
+\    func_stripname_result=${3}\
+\    func_stripname_result=${func_stripname_result#"${1}"}\
+\    func_stripname_result=${func_stripname_result%"${2}"}\
+} # Extended-shell func_stripname implementation' "$cfgfile" > $cfgfile.tmp \
+  && mv -f "$cfgfile.tmp" "$cfgfile" \
+    || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp")
+test 0 -eq $? || _lt_function_replace_fail=:
+
+
+  sed -e '/^func_split_long_opt ()$/,/^} # func_split_long_opt /c\
+func_split_long_opt ()\
+{\
+\    func_split_long_opt_name=${1%%=*}\
+\    func_split_long_opt_arg=${1#*=}\
+} # Extended-shell func_split_long_opt implementation' "$cfgfile" > $cfgfile.tmp \
+  && mv -f "$cfgfile.tmp" "$cfgfile" \
+    || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp")
+test 0 -eq $? || _lt_function_replace_fail=:
+
+
+  sed -e '/^func_split_short_opt ()$/,/^} # func_split_short_opt /c\
+func_split_short_opt ()\
+{\
+\    func_split_short_opt_arg=${1#??}\
+\    func_split_short_opt_name=${1%"$func_split_short_opt_arg"}\
+} # Extended-shell func_split_short_opt implementation' "$cfgfile" > $cfgfile.tmp \
+  && mv -f "$cfgfile.tmp" "$cfgfile" \
+    || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp")
+test 0 -eq $? || _lt_function_replace_fail=:
+
+
+  sed -e '/^func_lo2o ()$/,/^} # func_lo2o /c\
+func_lo2o ()\
+{\
+\    case ${1} in\
+\      *.lo) func_lo2o_result=${1%.lo}.${objext} ;;\
+\      *)    func_lo2o_result=${1} ;;\
+\    esac\
+} # Extended-shell func_lo2o implementation' "$cfgfile" > $cfgfile.tmp \
+  && mv -f "$cfgfile.tmp" "$cfgfile" \
+    || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp")
+test 0 -eq $? || _lt_function_replace_fail=:
+
+
+  sed -e '/^func_xform ()$/,/^} # func_xform /c\
+func_xform ()\
+{\
+    func_xform_result=${1%.*}.lo\
+} # Extended-shell func_xform implementation' "$cfgfile" > $cfgfile.tmp \
+  && mv -f "$cfgfile.tmp" "$cfgfile" \
+    || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp")
+test 0 -eq $? || _lt_function_replace_fail=:
+
+
+  sed -e '/^func_arith ()$/,/^} # func_arith /c\
+func_arith ()\
+{\
+    func_arith_result=$(( $* ))\
+} # Extended-shell func_arith implementation' "$cfgfile" > $cfgfile.tmp \
+  && mv -f "$cfgfile.tmp" "$cfgfile" \
+    || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp")
+test 0 -eq $? || _lt_function_replace_fail=:
+
+
+  sed -e '/^func_len ()$/,/^} # func_len /c\
+func_len ()\
+{\
+    func_len_result=${#1}\
+} # Extended-shell func_len implementation' "$cfgfile" > $cfgfile.tmp \
+  && mv -f "$cfgfile.tmp" "$cfgfile" \
+    || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp")
+test 0 -eq $? || _lt_function_replace_fail=:
+
+fi
+
+if test x"$lt_shell_append" = xyes; then
+  sed -e '/^func_append ()$/,/^} # func_append /c\
+func_append ()\
+{\
+    eval "${1}+=\\${2}"\
+} # Extended-shell func_append implementation' "$cfgfile" > $cfgfile.tmp \
+  && mv -f "$cfgfile.tmp" "$cfgfile" \
+    || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp")
+test 0 -eq $? || _lt_function_replace_fail=:
+
+
+  sed -e '/^func_append_quoted ()$/,/^} # func_append_quoted /c\
+func_append_quoted ()\
+{\
+\    func_quote_for_eval "${2}"\
+\    eval "${1}+=\\\\ \\$func_quote_for_eval_result"\
+} # Extended-shell func_append_quoted implementation' "$cfgfile" > $cfgfile.tmp \
+  && mv -f "$cfgfile.tmp" "$cfgfile" \
+    || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp")
+test 0 -eq $? || _lt_function_replace_fail=:
+
+
+  # Save a `func_append' function call where possible by direct use of '+='
+  sed -e 's%func_append \([a-zA-Z_]\{1,\}\) "%\1+="%g' $cfgfile > $cfgfile.tmp \
+    && mv -f "$cfgfile.tmp" "$cfgfile" \
+      || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp")
+  test 0 -eq $? || _lt_function_replace_fail=:
+else
+  # Save a `func_append' function call even when '+=' is not available
+  sed -e 's%func_append \([a-zA-Z_]\{1,\}\) "%\1="$\1%g' $cfgfile > $cfgfile.tmp \
+    && mv -f "$cfgfile.tmp" "$cfgfile" \
+      || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp")
+  test 0 -eq $? || _lt_function_replace_fail=:
+fi
+
+if test x"$_lt_function_replace_fail" = x":"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Unable to substitute extended shell functions in $ofile" >&5
+$as_echo "$as_me: WARNING: Unable to substitute extended shell functions in $ofile" >&2;}
+fi
+
+
+   mv -f "$cfgfile" "$ofile" ||
     (rm -f "$ofile" && cp "$cfgfile" "$ofile" && rm -f "$cfgfile")
   chmod +x "$ofile"
 
index fd5a3cf..c961d85 100644 (file)
 # Process this file with autoconf to produce a configure script
 
 # Initialize Autoconf
-AC_PREREQ([2.63])
+AC_PREREQ([2.60])
 AC_INIT([xf86-video-intel],
-        [2.15.0],
+        [2.20.9],
         [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg],
         [xf86-video-intel])
 AC_CONFIG_SRCDIR([Makefile.am])
 AC_CONFIG_HEADERS([config.h])
-AC_CONFIG_AUX_DIR([build-aux])
-AC_CONFIG_MACRO_DIR([m4])
+AC_CONFIG_AUX_DIR(.)
 
 # Initialize Automake
-AM_INIT_AUTOMAKE([1.10 foreign dist-bzip2])
-AM_MAINTAINER_MODE([enable])
-
-# Support silent build rules, requires at least automake-1.11. Disable
-# by either passing --disable-silent-rules to configure or passing V=1
-# to make
-m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
+AM_INIT_AUTOMAKE([foreign dist-bzip2])
+AM_MAINTAINER_MODE
 
 # Require X.Org macros 1.8 or later for MAN_SUBSTS set by XORG_MANPAGE_SECTIONS
 m4_ifndef([XORG_MACROS_VERSION],
@@ -56,17 +50,60 @@ m4_ifndef([XORG_DRIVER_CHECK_EXT],
   depending on your distribution, try package 'xserver-xorg-dev' or 'xorg-x11-server-devel'])])
 
 # Initialize libtool
-LT_PREREQ([2.2])
-LT_INIT([disable-static])
+AC_DISABLE_STATIC
+AC_PROG_LIBTOOL
+AC_SYS_LARGEFILE
+
+# Are we in a git checkout?
+dot_git=no
+if test -e .git; then
+       AC_DEFINE(HAVE_DOT_GIT, 1, [Are we in a git checkout?])
+       dot_git=yes
+fi
+AM_CONDITIONAL(HAVE_DOT_GIT, test x$dot_git = xyes)
+
+# If so, we include the git description in our logs for sanity checking.
+#
+# However, for people not running their own drivers this is just noise.
+# So we copy the xserver's builderstring idiom to allow for this to be
+# overridden and perhaps replaced with something more useful.
+AC_ARG_WITH(builderstring,
+           AS_HELP_STRING([--with-builderstring=BUILDERSTRING],
+                          [Additional builder string (default: use git describe)]),
+           [BUILDERSTRING="$withval"],
+           [BUILDERSTRING="x-magic-git-describe"])
+
+if test "x$BUILDERSTRING" = xx-magic-git-describe -a x$dot_git = xyes; then
+       AC_DEFINE(USE_GIT_DESCRIBE, 1, [Use automagic builder description])
+else
+  if test "x$BUILDERSTRING" != x -a "x$BUILDERSTRING" != xno -a "x$BUILDERSTRING" != xx-magic-git-describe; then
+         AC_DEFINE_UNQUOTED(BUILDER_DESCRIPTION, ["$BUILDERSTRING"], [Builder description])
+  fi
+fi
 
-PKG_CHECK_MODULES(GEN4ASM, [intel-gen4asm >= 1.1], [gen4asm=yes], [gen4asm=no])
+
+PKG_CHECK_MODULES(GEN4ASM, [intel-gen4asm >= 1.2], [gen4asm=yes], [gen4asm=no])
 AM_CONDITIONAL(HAVE_GEN4ASM, test x$gen4asm = xyes)
 
-PKG_CHECK_MODULES(UDEV, [libudev], [udev=yes], [udev=no])
-if test x"$udev" = xyes; then
-       AC_DEFINE(HAVE_UDEV,1,[Enable udev-based monitor hotplug detection])
+AC_ARG_ENABLE(udev,
+              AS_HELP_STRING([--disable-udev],
+                             [Disable udev-based monitor hotplug detection [default=auto]]),
+              [UDEV="$enableval"],
+              [UDEV=auto])
+
+if test x$UDEV != "xno"; then
+       PKG_CHECK_MODULES(UDEV, [libudev], [udev=yes], [udev=no])
+       if test x$UDEV == xyes -a x$udev != xyes; then
+               AC_MSG_ERROR([udev support requested but not found (libudev)])
+       fi
+       if test x$udev = xyes; then
+               AC_DEFINE(HAVE_UDEV,1,[Enable udev-based monitor hotplug detection])
+       fi
 fi
 
+PKG_CHECK_MODULES(X11, [x11 xrender xext pixman-1], [x11=yes], [x11=no])
+AM_CONDITIONAL(HAVE_X11, test x$x11 = xyes)
+
 AH_TOP([#include "xorg-server.h"])
 
 # Define a configure option for an alternate module directory
@@ -77,9 +114,7 @@ AC_ARG_WITH(xorg-module-dir,
             [moduledir="$libdir/xorg/modules"])
 
 AC_ARG_ENABLE(dri, AS_HELP_STRING([--disable-dri],
-                                  [Disable DRI support [[default=auto]]]),
-              [DRI="$enableval"],
-              [DRI=auto])
+                                  [Disable DRI support [[default=auto]]]))
 
 AC_ARG_ENABLE(xvmc, AS_HELP_STRING([--disable-xvmc],
                                   [Disable XvMC support [[default=yes]]]),
@@ -90,13 +125,168 @@ AC_ARG_ENABLE(kms-only, AS_HELP_STRING([--enable-kms-only],
                                   [Assume KMS support [[default=no]]]),
               [KMS_ONLY="$enableval"],
               [KMS_ONLY=no])
+AC_ARG_ENABLE(ums-only, AS_HELP_STRING([--enable-ums-only],
+                                  [Assume only UMS (no KMS) support [[default=no]]]),
+              [UMS_ONLY="$enableval"],
+              [UMS_ONLY=no])
+
+required_xorg_xserver_version=1.6
+required_pixman_version=0.24
+
+if pkg-config --exists 'pixman-1 >= 0.27.1'; then
+       AC_DEFINE([HAS_PIXMAN_GLYPHS], 1, [Enable pixman glyph cache])
+fi
+
+AC_ARG_ENABLE(sna,
+             AS_HELP_STRING([--enable-sna],
+                            [Enable SandyBridge's New Acceleration (SNA) [default=auto]]),
+             [SNA="$enableval"],
+             [SNA=auto])
+
+AC_CHECK_HEADERS([sys/sysinfo.h], , SNA=no)
+if test "x$SNA" = "xauto" && pkg-config --exists "xorg-server >= 1.10"; then
+       SNA=yes
+fi
+if test "x$SNA" != "xno"; then
+       required_xorg_xserver_version=1.10
+       AC_DEFINE(USE_SNA, 1, [Enable SNA support])
+fi
+AC_MSG_CHECKING([whether to include SNA support])
+AM_CONDITIONAL(SNA, test x$SNA != xno)
+AC_MSG_RESULT([$SNA])
+
+AC_ARG_ENABLE(uxa,
+             AS_HELP_STRING([--enable-uxa],
+                            [Enable Unified Acceleration Architecture (UXA) [default=yes]]),
+             [UXA="$enableval"],
+             [UXA=yes])
+AC_MSG_CHECKING([whether to include UXA support])
+AM_CONDITIONAL(UXA, test x$UXA != xno)
+AC_MSG_RESULT([$UXA])
+if test "x$UXA" != "xno"; then
+       AC_DEFINE(USE_UXA, 1, [Enable UXA support])
+       PKG_CHECK_MODULES(DRMINTEL, [libdrm_intel >= 2.4.29])
+fi
+
+AC_MSG_CHECKING([whether to include GLAMOR support])
+AC_ARG_ENABLE(glamor,
+             AS_HELP_STRING([--enable-glamor],
+                            [Enable glamor, a new GL-based acceleration [default=no]]),
+             [GLAMOR="$enableval"],
+             [GLAMOR=no])
+AC_MSG_RESULT([$GLAMOR])
+AM_CONDITIONAL(GLAMOR, test x$GLAMOR != xno)
+if test "x$GLAMOR" != "xno"; then
+       PKG_CHECK_MODULES(LIBGLAMOR, [glamor >= 0.3.1])
+       PKG_CHECK_MODULES(LIBGLAMOR_EGL, [glamor-egl])
+       AC_DEFINE(USE_GLAMOR, 1, [Enable glamor acceleration])
+fi
+
+
+PKG_CHECK_MODULES(XORG, [xorg-server >= $required_xorg_xserver_version xproto fontsproto pixman-1 >= $required_pixman_version $REQUIRED_MODULES])
+
+AC_ARG_ENABLE(xaa,
+             AS_HELP_STRING([--enable-xaa],
+                            [Enable legacy X Acceleration Architecture (XAA) [default=auto]]),
+             [XAA="$enableval"],
+             [XAA=auto])
+if test "x$XAA" != xno; then
+        save_CFLAGS=$CFLAGS
+        CFLAGS=$XORG_CFLAGS
+       AC_CHECK_HEADERS([xaa.h], XAA=yes, XAA=no)
+        CFLAGS=$save_CFLAGS
+fi
+AC_MSG_CHECKING([whether to include XAA support])
+AM_CONDITIONAL(XAA, test "x$XAA" = xyes)
+AC_MSG_RESULT([$XAA])
+
+AC_ARG_ENABLE(dga,
+             AS_HELP_STRING([--enable-dga],
+                            [Enable legacy Direct Graphics Access (DGA) [default=auto]]),
+             [DGA="$enableval"],
+             [DGA=auto])
+if test "x$DGA" != xno; then
+        save_CFLAGS=$CFLAGS
+        CFLAGS=$XORG_CFLAGS
+       AC_CHECK_HEADERS([dgaproc.h], DGA=yes, DGA=no, [#include <dixstruct.h>])
+        CFLAGS=$save_CFLAGS
+fi
+AC_MSG_CHECKING([whether to include DGA support])
+AM_CONDITIONAL(DGA, test "x$DGA" = xyes)
+AC_MSG_RESULT([$DGA])
+
+AC_ARG_WITH(default-accel,
+           AS_HELP_STRING([--with-default-accel],
+                          [Select the default acceleration method [default=uxa if enabled, otherwise sna]]),
+                          [accel="$withval"],
+                          [accel=auto])
+if test "x$accel" = xyes; then
+       AC_MSG_WARN([No default acceleration specified, choosing automatic selection])
+       accel="auto"
+fi
+
+AC_MSG_CHECKING([which acceleration method to use by default])
+if test "x$accel" = xauto; then
+       if test "x$UXA" != "xno"; then
+               accel=uxa
+       else
+               if test "x$SNA" != "xno"; then
+                       accel=sna
+               fi
+       fi
+       if test "x$accel" = xauto -a "x$UMS_ONLY" != "xyes"; then
+               AC_MSG_ERROR([No default acceleration option])
+       fi
+fi
+
+have_accel=none
+if test "x$accel" = xsna; then
+       if test "x$SNA" != "xno"; then
+               AC_DEFINE(DEFAULT_ACCEL_METHOD, SNA, [Default acceleration method])
+               have_accel=yes
+       else
+               AC_MSG_ERROR([SNA requested as default, but is not enabled])
+       fi
+fi
+
+if test "x$accel" = xuxa; then
+       if test "x$UXA" != "xno"; then
+               AC_DEFINE(DEFAULT_ACCEL_METHOD, UXA, [Default acceleration method])
+               have_accel=yes
+       else
+               AC_MSG_ERROR([UXA requested as default, but is not enabled])
+       fi
+fi
+AC_MSG_RESULT($accel)
+if test "x$accel" = xnone -a "x$UMS_ONLY" != "xyes"; then
+       AC_MSG_ERROR([No default acceleration option])
+fi
+
+AC_ARG_ENABLE(userptr,
+             AS_HELP_STRING([--enable-userptr],
+                            [Enable use of userptr (experimental) [default=no]]),
+             [USERPTR="$enableval"],
+             [USERPTR=no])
+AM_CONDITIONAL(USE_USERPTR, test x$USERPTR = xyes)
+if test "x$USERPTR" = xyes; then
+       AC_DEFINE(USE_USERPTR,1,[Assume USERPTR support])
+fi
+
+AC_ARG_ENABLE(async-swap,
+             AS_HELP_STRING([--enable-async-swap],
+                            [Enable use of asynchronous swaps (experimental) [default=no]]),
+             [ASYNC_SWAP="$enableval"],
+             [ASYNC_SWAP=no])
+AM_CONDITIONAL(USE_ASYNC_SWAP, test x$ASYNC_SWAP = xyes)
+if test "x$ASYNC_SWAP" = xyes; then
+       AC_DEFINE(USE_ASYNC_SWAP,1,[Assume asynchronous swap support])
+fi
 
 AC_ARG_ENABLE(debug,
              AS_HELP_STRING([--enable-debug],
-                            [Enables internal debugging [[default=yes]]]),
+                            [Enables internal debugging [default=no]]),
               [DEBUG="$enableval"],
-              [DEBUG=yes])
-
+              [DEBUG=no])
 # Store the list of server defined optional extensions in REQUIRED_MODULES
 XORG_DRIVER_CHECK_EXT(RANDR, randrproto)
 XORG_DRIVER_CHECK_EXT(RENDER, renderproto)
@@ -104,43 +294,60 @@ XORG_DRIVER_CHECK_EXT(XF86DRI, xextproto x11)
 XORG_DRIVER_CHECK_EXT(DPMSExtension, xextproto)
 
 # Obtain compiler/linker options for the driver dependencies
-PKG_CHECK_MODULES(XORG, [xorg-server >= 1.6 xproto fontsproto $REQUIRED_MODULES])
-PKG_CHECK_MODULES(DRM, [libdrm >= 2.4.23])
+PKG_CHECK_MODULES(DRM, [libdrm >= 2.4.24]) # libdrm_intel is checked separately
+PKG_CHECK_MODULES(DRI, [xf86driproto], , DRI=no)
+PKG_CHECK_MODULES(DRI2, [dri2proto >= 2.6],, DRI2=no)
 PKG_CHECK_MODULES(PCIACCESS, [pciaccess >= 0.10])
 
 sdkdir=`$PKG_CONFIG --variable=sdkdir xorg-server`
 
-save_CFLAGS="$CFLAGS"
-CFLAGS="$XORG_CFLAGS $DRI_CFLAGS $DRM_CFLAGS"
-CPPFLAGS="$XORG_CFLAGS $DRI_CFLAGS $DRM_CFLAGS"
-AC_MSG_CHECKING([whether to include DRI support])
-if test x$DRI != xno; then
-        AC_CHECK_FILE([${sdkdir}/dri.h],
-                      [have_dri_h="yes"], [have_dri_h="no"])
-        AC_CHECK_FILE([${sdkdir}/sarea.h],
-                      [have_sarea_h="yes"], [have_sarea_h="no"])
-        AC_CHECK_FILE([${sdkdir}/dristruct.h],
-                      [have_dristruct_h="yes"], [have_dristruct_h="no"])
+if test "x$enable_dri" != "xno"; then
+        save_CFLAGS="$CFLAGS"
+        save_CPPFLAGS="$CPPFLAGS"
+        CFLAGS="$CFLAGS $XORG_CFLAGS $DRI_CFLAGS $DRM_CFLAGS"
+        CPPFLAGS="$CPPFLAGS $XORG_CFLAGS $DRI_CFLAGS $DRM_CFLAGS"
+        AC_CHECK_HEADERS([dri.h sarea.h dristruct.h],, [DRI=no],
+                [/* for dri.h */
+                 #include <xf86str.h>
+                 /* for dristruct.h */
+                 #include <xorg-server.h>
+                 #ifdef HAVE_DRI_H
+                 # include <dri.h>
+                 #endif
+                 #ifdef HAVE_SAREA_H
+                 # include <sarea.h>
+                 #endif
+                ])
+        CFLAGS="$save_CFLAGS $DEBUGFLAGS"
+        CPPFLAGS="$save_CPPFLAGS"
+else
+        DRI=no
 fi
+
 AC_MSG_CHECKING([whether to include DRI support])
-if test x$DRI = xauto; then
-        if test "$have_dri_h" = yes -a \
-                "$have_sarea_h" = yes -a \
-                "$have_dristruct_h" = yes; then
-                DRI="yes"
-        else
-                DRI="no"
+AC_MSG_RESULT([${DRI-yes}])
+
+AM_CONDITIONAL(DRI, test x$DRI != xno)
+if test "x$DRI" != "xno"; then
+        AC_DEFINE(HAVE_DRI1,1,[Enable DRI driver support])
+else
+        DRI_CFLAGS=""
+        DRI_LIBS=""
+
+        if test "x$enable_dri" = "xyes"; then
+                AC_MSG_ERROR([DRI requested but prerequisites not found])
         fi
 fi
-AC_MSG_RESULT([$DRI])
-CFLAGS="$save_CFLAGS $DEBUGFLAGS"
 
-AM_CONDITIONAL(DRI, test x$DRI = xyes)
-if test "$DRI" = yes; then
-        PKG_CHECK_MODULES(DRI, [xf86driproto])
-        AC_DEFINE(XF86DRI,1,[Enable DRI driver support])
-        AC_DEFINE(XF86DRI_DEVEL,1,[Enable developmental DRI driver support])
+if test "x$DRI2" != "xno"; then
+       save_CFLAGS=$CFLAGS
+       CFLAGS="$XORG_CFLAGS $DRM_CFLAGS $DRI_CFLAGS $DRI2_CFLAGS"
+       AC_CHECK_HEADERS([dri2.h], DRI2=yes, DRI2=no, [#include <dixstruct.h>])
+       CFLAGS=$save_CFLAGS
 fi
+AC_MSG_CHECKING([whether to include DRI2 support])
+AM_CONDITIONAL(DRI2, test "x$DRI2" = xyes)
+AC_MSG_RESULT([$DRI2])
 
 if test "$XVMC" = yes; then
        PKG_CHECK_MODULES(XVMCLIB,
@@ -158,10 +365,34 @@ AM_CONDITIONAL(KMS_ONLY, test x$KMS_ONLY = xyes)
 if test "x$KMS_ONLY" = xyes; then
        AC_DEFINE(KMS_ONLY,1,[Assume KMS support])
 fi
+AM_CONDITIONAL(UMS_ONLY, test x$UMS_ONLY = xyes)
+if test "x$UMS_ONLY" = xyes; then
+       AC_DEFINE(UMS_ONLY,1,[Assume only UMS (no KMS) support])
+fi
 
+AM_CONDITIONAL(DEBUG, test x$DEBUG != xno)
+AM_CONDITIONAL(FULL_DEBUG, test x$FULL_DEBUG == xfull)
 if test "x$DEBUG" = xno; then
        AC_DEFINE(NDEBUG,1,[Disable internal debugging])
 fi
+if test "x$DEBUG" != xno; then
+       PKG_CHECK_MODULES(VALGRIND, [valgrind], have_valgrind=yes, have_valgrind=no)
+       if test x$have_valgrind = xyes; then
+               AC_DEFINE([HAVE_VALGRIND], 1, [Use valgrind intrinsics to suppress false warnings])
+       fi
+fi
+if test "x$DEBUG" = xmemory; then
+       AC_DEFINE(DEBUG_MEMORY,1,[Enable memory debugging])
+fi
+if test "x$DEBUG" = xpixmap; then
+       AC_DEFINE(DEBUG_PIXMAP,1,[Enable pixmap debugging])
+fi
+if test "x$DEBUG" = xfull; then
+       AC_DEFINE(DEBUG_MEMORY,1,[Enable memory debugging])
+       AC_DEFINE(DEBUG_PIXMAP,1,[Enable pixmap debugging])
+       AC_DEFINE(HAS_DEBUG_FULL,1,[Enable all debugging])
+        CFLAGS="$CFLAGS -O0 -ggdb3"
+fi
 
 DRIVER_NAME=intel
 AC_SUBST([DRIVER_NAME])
@@ -178,7 +409,11 @@ AC_CONFIG_FILES([
                 src/legacy/Makefile
                 src/legacy/i810/Makefile
                 src/legacy/i810/xvmc/Makefile
+                src/sna/Makefile
+                src/sna/brw/Makefile
+                src/sna/fb/Makefile
                 man/Makefile
                 src/render_program/Makefile
+               test/Makefile
 ])
 AC_OUTPUT
old mode 100755 (executable)
new mode 100644 (file)
index d88da2c..c7d06c3
--- a/ltmain.sh
+++ b/ltmain.sh
@@ -1,9 +1,9 @@
-# Generated from ltmain.m4sh.
 
-# ltmain.sh (GNU libtool) 2.2.6b
+# libtool (GNU libtool) 2.4.2
 # Written by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
 
-# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006, 2007 2008 Free Software Foundation, Inc.
+# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006,
+# 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
 # This is free software; see the source for copying conditions.  There is NO
 # warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
 #
 # Provide generalized library-building support services.
 #
-#     --config             show all configuration variables
-#     --debug              enable verbose shell tracing
-# -n, --dry-run            display commands without modifying any files
-#     --features           display basic configuration information and exit
-#     --mode=MODE          use operation mode MODE
-#     --preserve-dup-deps  don't remove duplicate dependency libraries
-#     --quiet, --silent    don't print informational messages
-#     --tag=TAG            use configuration variables from tag TAG
-# -v, --verbose            print informational messages (default)
-#     --version            print version information
-# -h, --help               print short or long help message
+#       --config             show all configuration variables
+#       --debug              enable verbose shell tracing
+#   -n, --dry-run            display commands without modifying any files
+#       --features           display basic configuration information and exit
+#       --mode=MODE          use operation mode MODE
+#       --preserve-dup-deps  don't remove duplicate dependency libraries
+#       --quiet, --silent    don't print informational messages
+#       --no-quiet, --no-silent
+#                            print informational messages (default)
+#       --no-warn            don't display warning messages
+#       --tag=TAG            use configuration variables from tag TAG
+#   -v, --verbose            print more informational messages than default
+#       --no-verbose         don't print the extra informational messages
+#       --version            print version information
+#   -h, --help, --help-all   print short, long, or detailed help message
 #
 # MODE must be one of the following:
 #
-#       clean              remove files from the build directory
-#       compile            compile a source file into a libtool object
-#       execute            automatically set library path, then run a program
-#       finish             complete the installation of libtool libraries
-#       install            install libraries or executables
-#       link               create a library or an executable
-#       uninstall          remove libraries from an installed directory
+#         clean              remove files from the build directory
+#         compile            compile a source file into a libtool object
+#         execute            automatically set library path, then run a program
+#         finish             complete the installation of libtool libraries
+#         install            install libraries or executables
+#         link               create a library or an executable
+#         uninstall          remove libraries from an installed directory
 #
-# MODE-ARGS vary depending on the MODE.
+# MODE-ARGS vary depending on the MODE.  When passed as first option,
+# `--mode=MODE' may be abbreviated as `MODE' or a unique abbreviation of that.
 # Try `$progname --help --mode=MODE' for a more detailed description of MODE.
 #
 # When reporting a bug, please describe a test case to reproduce it and
 # include the following information:
 #
-#       host-triplet:  $host
-#       shell:         $SHELL
-#       compiler:              $LTCC
-#       compiler flags:                $LTCFLAGS
-#       linker:                $LD (gnu? $with_gnu_ld)
-#       $progname:             (GNU libtool) 2.2.6b Debian-2.2.6b-2
-#       automake:              $automake_version
-#       autoconf:              $autoconf_version
+#         host-triplet:        $host
+#         shell:               $SHELL
+#         compiler:            $LTCC
+#         compiler flags:              $LTCFLAGS
+#         linker:              $LD (gnu? $with_gnu_ld)
+#         $progname:   (GNU libtool) 2.4.2 Debian-2.4.2-1
+#         automake:    $automake_version
+#         autoconf:    $autoconf_version
 #
 # Report bugs to <bug-libtool@gnu.org>.
+# GNU libtool home page: <http://www.gnu.org/software/libtool/>.
+# General help using GNU software: <http://www.gnu.org/gethelp/>.
 
-PROGRAM=ltmain.sh
+PROGRAM=libtool
 PACKAGE=libtool
-VERSION="2.2.6b Debian-2.2.6b-2"
+VERSION="2.4.2 Debian-2.4.2-1"
 TIMESTAMP=""
-package_revision=1.3017
+package_revision=1.3337
 
 # Be Bourne compatible
 if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
@@ -91,10 +98,15 @@ fi
 BIN_SH=xpg4; export BIN_SH # for Tru64
 DUALCASE=1; export DUALCASE # for MKS sh
 
+# A function that is used when there is no print builtin or printf.
+func_fallback_echo ()
+{
+  eval 'cat <<_LTECHO_EOF
+$1
+_LTECHO_EOF'
+}
+
 # NLS nuisances: We save the old values to restore during execute mode.
-# Only set LANG and LC_ALL to C if already set.
-# These must not be set unconditionally because not all systems understand
-# e.g. LANG=C (notably SCO).
 lt_user_locale=
 lt_safe_locale=
 for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
@@ -107,24 +119,28 @@ do
          lt_safe_locale=\"$lt_var=C; \$lt_safe_locale\"
        fi"
 done
+LC_ALL=C
+LANGUAGE=C
+export LANGUAGE LC_ALL
 
 $lt_unset CDPATH
 
 
+# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
+# is ksh but when the shell is invoked as "sh" and the current value of
+# the _XPG environment variable is not equal to 1 (one), the special
+# positional parameter $0, within a function call, is the name of the
+# function.
+progpath="$0"
 
 
 
 : ${CP="cp -f"}
-: ${ECHO="echo"}
-: ${EGREP="/bin/grep -E"}
-: ${FGREP="/bin/grep -F"}
-: ${GREP="/bin/grep"}
-: ${LN_S="ln -s"}
+test "${ECHO+set}" = set || ECHO=${as_echo-'printf %s\n'}
 : ${MAKE="make"}
 : ${MKDIR="mkdir"}
 : ${MV="mv -f"}
 : ${RM="rm -f"}
-: ${SED="/bin/sed"}
 : ${SHELL="${CONFIG_SHELL-/bin/sh}"}
 : ${Xsed="$SED -e 1s/^X//"}
 
@@ -144,6 +160,27 @@ IFS="      $lt_nl"
 dirname="s,/[^/]*$,,"
 basename="s,^.*/,,"
 
+# func_dirname file append nondir_replacement
+# Compute the dirname of FILE.  If nonempty, add APPEND to the result,
+# otherwise set result to NONDIR_REPLACEMENT.
+func_dirname ()
+{
+    func_dirname_result=`$ECHO "${1}" | $SED "$dirname"`
+    if test "X$func_dirname_result" = "X${1}"; then
+      func_dirname_result="${3}"
+    else
+      func_dirname_result="$func_dirname_result${2}"
+    fi
+} # func_dirname may be replaced by extended shell implementation
+
+
+# func_basename file
+func_basename ()
+{
+    func_basename_result=`$ECHO "${1}" | $SED "$basename"`
+} # func_basename may be replaced by extended shell implementation
+
+
 # func_dirname_and_basename file append nondir_replacement
 # perform func_basename and func_dirname in a single function
 # call:
@@ -158,33 +195,183 @@ basename="s,^.*/,,"
 # those functions but instead duplicate the functionality here.
 func_dirname_and_basename ()
 {
-  # Extract subdirectory from the argument.
-  func_dirname_result=`$ECHO "X${1}" | $Xsed -e "$dirname"`
-  if test "X$func_dirname_result" = "X${1}"; then
-    func_dirname_result="${3}"
-  else
-    func_dirname_result="$func_dirname_result${2}"
-  fi
-  func_basename_result=`$ECHO "X${1}" | $Xsed -e "$basename"`
+    # Extract subdirectory from the argument.
+    func_dirname_result=`$ECHO "${1}" | $SED -e "$dirname"`
+    if test "X$func_dirname_result" = "X${1}"; then
+      func_dirname_result="${3}"
+    else
+      func_dirname_result="$func_dirname_result${2}"
+    fi
+    func_basename_result=`$ECHO "${1}" | $SED -e "$basename"`
+} # func_dirname_and_basename may be replaced by extended shell implementation
+
+
+# func_stripname prefix suffix name
+# strip PREFIX and SUFFIX off of NAME.
+# PREFIX and SUFFIX must not contain globbing or regex special
+# characters, hashes, percent signs, but SUFFIX may contain a leading
+# dot (in which case that matches only a dot).
+# func_strip_suffix prefix name
+func_stripname ()
+{
+    case ${2} in
+      .*) func_stripname_result=`$ECHO "${3}" | $SED "s%^${1}%%; s%\\\\${2}\$%%"`;;
+      *)  func_stripname_result=`$ECHO "${3}" | $SED "s%^${1}%%; s%${2}\$%%"`;;
+    esac
+} # func_stripname may be replaced by extended shell implementation
+
+
+# These SED scripts presuppose an absolute path with a trailing slash.
+pathcar='s,^/\([^/]*\).*$,\1,'
+pathcdr='s,^/[^/]*,,'
+removedotparts=':dotsl
+               s@/\./@/@g
+               t dotsl
+               s,/\.$,/,'
+collapseslashes='s@/\{1,\}@/@g'
+finalslash='s,/*$,/,'
+
+# func_normal_abspath PATH
+# Remove doubled-up and trailing slashes, "." path components,
+# and cancel out any ".." path components in PATH after making
+# it an absolute path.
+#             value returned in "$func_normal_abspath_result"
+func_normal_abspath ()
+{
+  # Start from root dir and reassemble the path.
+  func_normal_abspath_result=
+  func_normal_abspath_tpath=$1
+  func_normal_abspath_altnamespace=
+  case $func_normal_abspath_tpath in
+    "")
+      # Empty path, that just means $cwd.
+      func_stripname '' '/' "`pwd`"
+      func_normal_abspath_result=$func_stripname_result
+      return
+    ;;
+    # The next three entries are used to spot a run of precisely
+    # two leading slashes without using negated character classes;
+    # we take advantage of case's first-match behaviour.
+    ///*)
+      # Unusual form of absolute path, do nothing.
+    ;;
+    //*)
+      # Not necessarily an ordinary path; POSIX reserves leading '//'
+      # and for example Cygwin uses it to access remote file shares
+      # over CIFS/SMB, so we conserve a leading double slash if found.
+      func_normal_abspath_altnamespace=/
+    ;;
+    /*)
+      # Absolute path, do nothing.
+    ;;
+    *)
+      # Relative path, prepend $cwd.
+      func_normal_abspath_tpath=`pwd`/$func_normal_abspath_tpath
+    ;;
+  esac
+  # Cancel out all the simple stuff to save iterations.  We also want
+  # the path to end with a slash for ease of parsing, so make sure
+  # there is one (and only one) here.
+  func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
+        -e "$removedotparts" -e "$collapseslashes" -e "$finalslash"`
+  while :; do
+    # Processed it all yet?
+    if test "$func_normal_abspath_tpath" = / ; then
+      # If we ascended to the root using ".." the result may be empty now.
+      if test -z "$func_normal_abspath_result" ; then
+        func_normal_abspath_result=/
+      fi
+      break
+    fi
+    func_normal_abspath_tcomponent=`$ECHO "$func_normal_abspath_tpath" | $SED \
+        -e "$pathcar"`
+    func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
+        -e "$pathcdr"`
+    # Figure out what to do with it
+    case $func_normal_abspath_tcomponent in
+      "")
+        # Trailing empty path component, ignore it.
+      ;;
+      ..)
+        # Parent dir; strip last assembled component from result.
+        func_dirname "$func_normal_abspath_result"
+        func_normal_abspath_result=$func_dirname_result
+      ;;
+      *)
+        # Actual path component, append it.
+        func_normal_abspath_result=$func_normal_abspath_result/$func_normal_abspath_tcomponent
+      ;;
+    esac
+  done
+  # Restore leading double-slash if one was found on entry.
+  func_normal_abspath_result=$func_normal_abspath_altnamespace$func_normal_abspath_result
 }
 
-# Generated shell functions inserted here.
+# func_relative_path SRCDIR DSTDIR
+# generates a relative path from SRCDIR to DSTDIR, with a trailing
+# slash if non-empty, suitable for immediately appending a filename
+# without needing to append a separator.
+#             value returned in "$func_relative_path_result"
+func_relative_path ()
+{
+  func_relative_path_result=
+  func_normal_abspath "$1"
+  func_relative_path_tlibdir=$func_normal_abspath_result
+  func_normal_abspath "$2"
+  func_relative_path_tbindir=$func_normal_abspath_result
+
+  # Ascend the tree starting from libdir
+  while :; do
+    # check if we have found a prefix of bindir
+    case $func_relative_path_tbindir in
+      $func_relative_path_tlibdir)
+        # found an exact match
+        func_relative_path_tcancelled=
+        break
+        ;;
+      $func_relative_path_tlibdir*)
+        # found a matching prefix
+        func_stripname "$func_relative_path_tlibdir" '' "$func_relative_path_tbindir"
+        func_relative_path_tcancelled=$func_stripname_result
+        if test -z "$func_relative_path_result"; then
+          func_relative_path_result=.
+        fi
+        break
+        ;;
+      *)
+        func_dirname $func_relative_path_tlibdir
+        func_relative_path_tlibdir=${func_dirname_result}
+        if test "x$func_relative_path_tlibdir" = x ; then
+          # Have to descend all the way to the root!
+          func_relative_path_result=../$func_relative_path_result
+          func_relative_path_tcancelled=$func_relative_path_tbindir
+          break
+        fi
+        func_relative_path_result=../$func_relative_path_result
+        ;;
+    esac
+  done
 
-# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
-# is ksh but when the shell is invoked as "sh" and the current value of
-# the _XPG environment variable is not equal to 1 (one), the special
-# positional parameter $0, within a function call, is the name of the
-# function.
-progpath="$0"
+  # Now calculate path; take care to avoid doubling-up slashes.
+  func_stripname '' '/' "$func_relative_path_result"
+  func_relative_path_result=$func_stripname_result
+  func_stripname '/' '/' "$func_relative_path_tcancelled"
+  if test "x$func_stripname_result" != x ; then
+    func_relative_path_result=${func_relative_path_result}/${func_stripname_result}
+  fi
+
+  # Normalisation. If bindir is libdir, return empty string,
+  # else relative path ending with a slash; either way, target
+  # file name can be directly appended.
+  if test ! -z "$func_relative_path_result"; then
+    func_stripname './' '' "$func_relative_path_result/"
+    func_relative_path_result=$func_stripname_result
+  fi
+}
 
 # The name of this program:
-# In the unlikely event $progname began with a '-', it would play havoc with
-# func_echo (imagine progname=-n), so we prepend ./ in that case:
 func_dirname_and_basename "$progpath"
 progname=$func_basename_result
-case $progname in
-  -*) progname=./$progname ;;
-esac
 
 # Make sure we have an absolute path for reexecution:
 case $progpath in
@@ -196,7 +383,7 @@ case $progpath in
      ;;
   *)
      save_IFS="$IFS"
-     IFS=:
+     IFS=${PATH_SEPARATOR-:}
      for progdir in $PATH; do
        IFS="$save_IFS"
        test -x "$progdir/$progname" && break
@@ -215,6 +402,15 @@ sed_quote_subst='s/\([`"$\\]\)/\\\1/g'
 # Same as above, but do not quote variable references.
 double_quote_subst='s/\(["`\\]\)/\\\1/g'
 
+# Sed substitution that turns a string into a regex matching for the
+# string literally.
+sed_make_literal_regex='s,[].[^$\\*\/],\\&,g'
+
+# Sed substitution that converts a w32 file name or path
+# which contains forward slashes, into one that contains
+# (escaped) backslashes.  A very naive implementation.
+lt_sed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
+
 # Re-`\' parameter expansions in output of double_quote_subst that were
 # `\'-ed in input to the same.  If an odd number of `\' preceded a '$'
 # in input to double_quote_subst, that '$' was protected from expansion.
@@ -243,7 +439,7 @@ opt_warning=:
 # name if it has been set yet.
 func_echo ()
 {
-    $ECHO "$progname${mode+: }$mode: $*"
+    $ECHO "$progname: ${opt_mode+$opt_mode: }$*"
 }
 
 # func_verbose arg...
@@ -258,18 +454,25 @@ func_verbose ()
     :
 }
 
+# func_echo_all arg...
+# Invoke $ECHO with all args, space-separated.
+func_echo_all ()
+{
+    $ECHO "$*"
+}
+
 # func_error arg...
 # Echo program name prefixed message to standard error.
 func_error ()
 {
-    $ECHO "$progname${mode+: }$mode: "${1+"$@"} 1>&2
+    $ECHO "$progname: ${opt_mode+$opt_mode: }"${1+"$@"} 1>&2
 }
 
 # func_warning arg...
 # Echo program name prefixed warning message to standard error.
 func_warning ()
 {
-    $opt_warning && $ECHO "$progname${mode+: }$mode: warning: "${1+"$@"} 1>&2
+    $opt_warning && $ECHO "$progname: ${opt_mode+$opt_mode: }warning: "${1+"$@"} 1>&2
 
     # bash bug again:
     :
@@ -326,9 +529,9 @@ func_mkdir_p ()
         case $my_directory_path in */*) ;; *) break ;; esac
 
         # ...otherwise throw away the child directory and loop
-        my_directory_path=`$ECHO "X$my_directory_path" | $Xsed -e "$dirname"`
+        my_directory_path=`$ECHO "$my_directory_path" | $SED -e "$dirname"`
       done
-      my_dir_list=`$ECHO "X$my_dir_list" | $Xsed -e 's,:*$,,'`
+      my_dir_list=`$ECHO "$my_dir_list" | $SED 's,:*$,,'`
 
       save_mkdir_p_IFS="$IFS"; IFS=':'
       for my_dir in $my_dir_list; do
@@ -378,7 +581,7 @@ func_mktempdir ()
         func_fatal_error "cannot create temporary directory \`$my_tmpdir'"
     fi
 
-    $ECHO "X$my_tmpdir" | $Xsed
+    $ECHO "$my_tmpdir"
 }
 
 
@@ -392,7 +595,7 @@ func_quote_for_eval ()
 {
     case $1 in
       *[\\\`\"\$]*)
-       func_quote_for_eval_unquoted_result=`$ECHO "X$1" | $Xsed -e "$sed_quote_subst"` ;;
+       func_quote_for_eval_unquoted_result=`$ECHO "$1" | $SED "$sed_quote_subst"` ;;
       *)
         func_quote_for_eval_unquoted_result="$1" ;;
     esac
@@ -419,7 +622,7 @@ func_quote_for_expand ()
 {
     case $1 in
       *[\\\`\"]*)
-       my_arg=`$ECHO "X$1" | $Xsed \
+       my_arg=`$ECHO "$1" | $SED \
            -e "$double_quote_subst" -e "$sed_double_backslash"` ;;
       *)
         my_arg="$1" ;;
@@ -488,15 +691,39 @@ func_show_eval_locale ()
     fi
 }
 
-
-
+# func_tr_sh
+# Turn $1 into a string suitable for a shell variable name.
+# Result is stored in $func_tr_sh_result.  All characters
+# not in the set a-zA-Z0-9_ are replaced with '_'. Further,
+# if $1 begins with a digit, a '_' is prepended as well.
+func_tr_sh ()
+{
+  case $1 in
+  [0-9]* | *[!a-zA-Z0-9_]*)
+    func_tr_sh_result=`$ECHO "$1" | $SED 's/^\([0-9]\)/_\1/; s/[^a-zA-Z0-9_]/_/g'`
+    ;;
+  * )
+    func_tr_sh_result=$1
+    ;;
+  esac
+}
 
 
 # func_version
 # Echo version message to standard output and exit.
 func_version ()
 {
-    $SED -n '/^# '$PROGRAM' (GNU /,/# warranty; / {
+    $opt_debug
+
+    $SED -n '/(C)/!b go
+       :more
+       /\./!{
+         N
+         s/\n# / /
+         b more
+       }
+       :go
+       /^# '$PROGRAM' (GNU /,/# warranty; / {
         s/^# //
        s/^# *$//
         s/\((C)\)[ 0-9,-]*\( [1-9][0-9]*\)/\1\2/
@@ -509,22 +736,28 @@ func_version ()
 # Echo short help message to standard output and exit.
 func_usage ()
 {
-    $SED -n '/^# Usage:/,/# -h/ {
+    $opt_debug
+
+    $SED -n '/^# Usage:/,/^#  *.*--help/ {
         s/^# //
        s/^# *$//
        s/\$progname/'$progname'/
        p
     }' < "$progpath"
-    $ECHO
+    echo
     $ECHO "run \`$progname --help | more' for full usage"
     exit $?
 }
 
-# func_help
-# Echo long help message to standard output and exit.
+# func_help [NOEXIT]
+# Echo long help message to standard output and exit,
+# unless 'noexit' is passed as argument.
 func_help ()
 {
+    $opt_debug
+
     $SED -n '/^# Usage:/,/# Report bugs to/ {
+       :print
         s/^# //
        s/^# *$//
        s*\$progname*'$progname'*
@@ -534,11 +767,18 @@ func_help ()
        s*\$LTCFLAGS*'"$LTCFLAGS"'*
        s*\$LD*'"$LD"'*
        s/\$with_gnu_ld/'"$with_gnu_ld"'/
-       s/\$automake_version/'"`(automake --version) 2>/dev/null |$SED 1q`"'/
-       s/\$autoconf_version/'"`(autoconf --version) 2>/dev/null |$SED 1q`"'/
+       s/\$automake_version/'"`(${AUTOMAKE-automake} --version) 2>/dev/null |$SED 1q`"'/
+       s/\$autoconf_version/'"`(${AUTOCONF-autoconf} --version) 2>/dev/null |$SED 1q`"'/
        p
-     }' < "$progpath"
-    exit $?
+       d
+     }
+     /^# .* home page:/b print
+     /^# General help using/b print
+     ' < "$progpath"
+    ret=$?
+    if test -z "$1"; then
+      exit $ret
+    fi
 }
 
 # func_missing_arg argname
@@ -546,63 +786,106 @@ func_help ()
 # exit_cmd.
 func_missing_arg ()
 {
-    func_error "missing argument for $1"
+    $opt_debug
+
+    func_error "missing argument for $1."
     exit_cmd=exit
 }
 
-exit_cmd=:
 
+# func_split_short_opt shortopt
+# Set func_split_short_opt_name and func_split_short_opt_arg shell
+# variables after splitting SHORTOPT after the 2nd character.
+func_split_short_opt ()
+{
+    my_sed_short_opt='1s/^\(..\).*$/\1/;q'
+    my_sed_short_rest='1s/^..\(.*\)$/\1/;q'
 
+    func_split_short_opt_name=`$ECHO "$1" | $SED "$my_sed_short_opt"`
+    func_split_short_opt_arg=`$ECHO "$1" | $SED "$my_sed_short_rest"`
+} # func_split_short_opt may be replaced by extended shell implementation
+
+
+# func_split_long_opt longopt
+# Set func_split_long_opt_name and func_split_long_opt_arg shell
+# variables after splitting LONGOPT at the `=' sign.
+func_split_long_opt ()
+{
+    my_sed_long_opt='1s/^\(--[^=]*\)=.*/\1/;q'
+    my_sed_long_arg='1s/^--[^=]*=//'
+
+    func_split_long_opt_name=`$ECHO "$1" | $SED "$my_sed_long_opt"`
+    func_split_long_opt_arg=`$ECHO "$1" | $SED "$my_sed_long_arg"`
+} # func_split_long_opt may be replaced by extended shell implementation
+
+exit_cmd=:
 
 
 
-# Check that we have a working $ECHO.
-if test "X$1" = X--no-reexec; then
-  # Discard the --no-reexec flag, and continue.
-  shift
-elif test "X$1" = X--fallback-echo; then
-  # Avoid inline document here, it may be left over
-  :
-elif test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t'; then
-  # Yippee, $ECHO works!
-  :
-else
-  # Restart under the correct shell, and then maybe $ECHO will work.
-  exec $SHELL "$progpath" --no-reexec ${1+"$@"}
-fi
 
-if test "X$1" = X--fallback-echo; then
-  # used as fallback echo
-  shift
-  cat <<EOF
-$*
-EOF
-  exit $EXIT_SUCCESS
-fi
 
 magic="%%%MAGIC variable%%%"
 magic_exe="%%%MAGIC EXE variable%%%"
 
 # Global variables.
-# $mode is unset
 nonopt=
-execute_dlfiles=
 preserve_args=
 lo2o="s/\\.lo\$/.${objext}/"
 o2lo="s/\\.${objext}\$/.lo/"
 extracted_archives=
 extracted_serial=0
 
-opt_dry_run=false
-opt_duplicate_deps=false
-opt_silent=false
-opt_debug=:
-
 # If this variable is set in any of the actions, the command in it
 # will be execed at the end.  This prevents here-documents from being
 # left over by shells.
 exec_cmd=
 
+# func_append var value
+# Append VALUE to the end of shell variable VAR.
+func_append ()
+{
+    eval "${1}=\$${1}\${2}"
+} # func_append may be replaced by extended shell implementation
+
+# func_append_quoted var value
+# Quote VALUE and append to the end of shell variable VAR, separated
+# by a space.
+func_append_quoted ()
+{
+    func_quote_for_eval "${2}"
+    eval "${1}=\$${1}\\ \$func_quote_for_eval_result"
+} # func_append_quoted may be replaced by extended shell implementation
+
+
+# func_arith arithmetic-term...
+func_arith ()
+{
+    func_arith_result=`expr "${@}"`
+} # func_arith may be replaced by extended shell implementation
+
+
+# func_len string
+# STRING may not start with a hyphen.
+func_len ()
+{
+    func_len_result=`expr "${1}" : ".*" 2>/dev/null || echo $max_cmd_len`
+} # func_len may be replaced by extended shell implementation
+
+
+# func_lo2o object
+func_lo2o ()
+{
+    func_lo2o_result=`$ECHO "${1}" | $SED "$lo2o"`
+} # func_lo2o may be replaced by extended shell implementation
+
+
+# func_xform libobj-or-source
+func_xform ()
+{
+    func_xform_result=`$ECHO "${1}" | $SED 's/\.[^.]*$/.lo/'`
+} # func_xform may be replaced by extended shell implementation
+
+
 # func_fatal_configuration arg...
 # Echo program name prefixed message to standard error, followed by
 # a configuration failure hint, and exit.
@@ -636,16 +919,16 @@ func_config ()
 # Display the features supported by this script.
 func_features ()
 {
-    $ECHO "host: $host"
+    echo "host: $host"
     if test "$build_libtool_libs" = yes; then
-      $ECHO "enable shared libraries"
+      echo "enable shared libraries"
     else
-      $ECHO "disable shared libraries"
+      echo "disable shared libraries"
     fi
     if test "$build_old_libs" = yes; then
-      $ECHO "enable static libraries"
+      echo "enable static libraries"
     else
-      $ECHO "disable static libraries"
+      echo "disable static libraries"
     fi
 
     exit $?
@@ -692,117 +975,209 @@ func_enable_tag ()
   esac
 }
 
-# Parse options once, thoroughly.  This comes as soon as possible in
-# the script to make things like `libtool --version' happen quickly.
+# func_check_version_match
+# Ensure that we are using m4 macros, and libtool script from the same
+# release of libtool.
+func_check_version_match ()
 {
+  if test "$package_revision" != "$macro_revision"; then
+    if test "$VERSION" != "$macro_version"; then
+      if test -z "$macro_version"; then
+        cat >&2 <<_LT_EOF
+$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
+$progname: definition of this LT_INIT comes from an older release.
+$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
+$progname: and run autoconf again.
+_LT_EOF
+      else
+        cat >&2 <<_LT_EOF
+$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
+$progname: definition of this LT_INIT comes from $PACKAGE $macro_version.
+$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
+$progname: and run autoconf again.
+_LT_EOF
+      fi
+    else
+      cat >&2 <<_LT_EOF
+$progname: Version mismatch error.  This is $PACKAGE $VERSION, revision $package_revision,
+$progname: but the definition of this LT_INIT comes from revision $macro_revision.
+$progname: You should recreate aclocal.m4 with macros from revision $package_revision
+$progname: of $PACKAGE $VERSION and run autoconf again.
+_LT_EOF
+    fi
+
+    exit $EXIT_MISMATCH
+  fi
+}
+
+
+# Shorthand for --mode=foo, only valid as the first argument
+case $1 in
+clean|clea|cle|cl)
+  shift; set dummy --mode clean ${1+"$@"}; shift
+  ;;
+compile|compil|compi|comp|com|co|c)
+  shift; set dummy --mode compile ${1+"$@"}; shift
+  ;;
+execute|execut|execu|exec|exe|ex|e)
+  shift; set dummy --mode execute ${1+"$@"}; shift
+  ;;
+finish|finis|fini|fin|fi|f)
+  shift; set dummy --mode finish ${1+"$@"}; shift
+  ;;
+install|instal|insta|inst|ins|in|i)
+  shift; set dummy --mode install ${1+"$@"}; shift
+  ;;
+link|lin|li|l)
+  shift; set dummy --mode link ${1+"$@"}; shift
+  ;;
+uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u)
+  shift; set dummy --mode uninstall ${1+"$@"}; shift
+  ;;
+esac
+
+
+
+# Option defaults:
+opt_debug=:
+opt_dry_run=false
+opt_config=false
+opt_preserve_dup_deps=false
+opt_features=false
+opt_finish=false
+opt_help=false
+opt_help_all=false
+opt_silent=:
+opt_warning=:
+opt_verbose=:
+opt_silent=false
+opt_verbose=false
 
-  # Shorthand for --mode=foo, only valid as the first argument
-  case $1 in
-  clean|clea|cle|cl)
-    shift; set dummy --mode clean ${1+"$@"}; shift
-    ;;
-  compile|compil|compi|comp|com|co|c)
-    shift; set dummy --mode compile ${1+"$@"}; shift
-    ;;
-  execute|execut|execu|exec|exe|ex|e)
-    shift; set dummy --mode execute ${1+"$@"}; shift
-    ;;
-  finish|finis|fini|fin|fi|f)
-    shift; set dummy --mode finish ${1+"$@"}; shift
-    ;;
-  install|instal|insta|inst|ins|in|i)
-    shift; set dummy --mode install ${1+"$@"}; shift
-    ;;
-  link|lin|li|l)
-    shift; set dummy --mode link ${1+"$@"}; shift
-    ;;
-  uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u)
-    shift; set dummy --mode uninstall ${1+"$@"}; shift
-    ;;
-  esac
 
-  # Parse non-mode specific arguments:
-  while test "$#" -gt 0; do
+# Parse options once, thoroughly.  This comes as soon as possible in the
+# script to make things like `--version' happen as quickly as we can.
+{
+  # this just eases exit handling
+  while test $# -gt 0; do
     opt="$1"
     shift
-
     case $opt in
-      --config)                func_config                                     ;;
-
-      --debug)         preserve_args="$preserve_args $opt"
+      --debug|-x)      opt_debug='set -x'
                        func_echo "enabling shell trace mode"
-                       opt_debug='set -x'
                        $opt_debug
                        ;;
-
-      -dlopen)         test "$#" -eq 0 && func_missing_arg "$opt" && break
-                       execute_dlfiles="$execute_dlfiles $1"
-                       shift
+      --dry-run|--dryrun|-n)
+                       opt_dry_run=:
                        ;;
-
-      --dry-run | -n)  opt_dry_run=:                                   ;;
-      --features)       func_features                                  ;;
-      --finish)                mode="finish"                                   ;;
-
-      --mode)          test "$#" -eq 0 && func_missing_arg "$opt" && break
-                       case $1 in
-                         # Valid mode arguments:
-                         clean)        ;;
-                         compile)      ;;
-                         execute)      ;;
-                         finish)       ;;
-                         install)      ;;
-                         link)         ;;
-                         relink)       ;;
-                         uninstall)    ;;
-
-                         # Catch anything else as an error
-                         *) func_error "invalid argument for $opt"
-                            exit_cmd=exit
-                            break
-                            ;;
-                       esac
-
-                       mode="$1"
+      --config)
+                       opt_config=:
+func_config
+                       ;;
+      --dlopen|-dlopen)
+                       optarg="$1"
+                       opt_dlopen="${opt_dlopen+$opt_dlopen
+}$optarg"
                        shift
                        ;;
-
       --preserve-dup-deps)
-                       opt_duplicate_deps=:                            ;;
-
-      --quiet|--silent)        preserve_args="$preserve_args $opt"
-                       opt_silent=:
+                       opt_preserve_dup_deps=:
                        ;;
-
-      --verbose| -v)   preserve_args="$preserve_args $opt"
+      --features)
+                       opt_features=:
+func_features
+                       ;;
+      --finish)
+                       opt_finish=:
+set dummy --mode finish ${1+"$@"}; shift
+                       ;;
+      --help)
+                       opt_help=:
+                       ;;
+      --help-all)
+                       opt_help_all=:
+opt_help=': help-all'
+                       ;;
+      --mode)
+                       test $# = 0 && func_missing_arg $opt && break
+                       optarg="$1"
+                       opt_mode="$optarg"
+case $optarg in
+  # Valid mode arguments:
+  clean|compile|execute|finish|install|link|relink|uninstall) ;;
+
+  # Catch anything else as an error
+  *) func_error "invalid argument for $opt"
+     exit_cmd=exit
+     break
+     ;;
+esac
+                       shift
+                       ;;
+      --no-silent|--no-quiet)
                        opt_silent=false
+func_append preserve_args " $opt"
                        ;;
-
-      --tag)           test "$#" -eq 0 && func_missing_arg "$opt" && break
-                       preserve_args="$preserve_args $opt $1"
-                       func_enable_tag "$1"    # tagname is set here
+      --no-warning|--no-warn)
+                       opt_warning=false
+func_append preserve_args " $opt"
+                       ;;
+      --no-verbose)
+                       opt_verbose=false
+func_append preserve_args " $opt"
+                       ;;
+      --silent|--quiet)
+                       opt_silent=:
+func_append preserve_args " $opt"
+        opt_verbose=false
+                       ;;
+      --verbose|-v)
+                       opt_verbose=:
+func_append preserve_args " $opt"
+opt_silent=false
+                       ;;
+      --tag)
+                       test $# = 0 && func_missing_arg $opt && break
+                       optarg="$1"
+                       opt_tag="$optarg"
+func_append preserve_args " $opt $optarg"
+func_enable_tag "$optarg"
                        shift
                        ;;
 
+      -\?|-h)          func_usage                              ;;
+      --help)          func_help                               ;;
+      --version)       func_version                            ;;
+
       # Separate optargs to long options:
-      -dlopen=*|--mode=*|--tag=*)
-                       func_opt_split "$opt"
-                       set dummy "$func_opt_split_opt" "$func_opt_split_arg" ${1+"$@"}
+      --*=*)
+                       func_split_long_opt "$opt"
+                       set dummy "$func_split_long_opt_name" "$func_split_long_opt_arg" ${1+"$@"}
                        shift
                        ;;
 
-      -\?|-h)          func_usage                                      ;;
-      --help)          opt_help=:                                      ;;
-      --version)       func_version                                    ;;
-
-      -*)              func_fatal_help "unrecognized option \`$opt'"   ;;
-
-      *)               nonopt="$opt"
-                       break
+      # Separate non-argument short options:
+      -\?*|-h*|-n*|-v*)
+                       func_split_short_opt "$opt"
+                       set dummy "$func_split_short_opt_name" "-$func_split_short_opt_arg" ${1+"$@"}
+                       shift
                        ;;
+
+      --)              break                                   ;;
+      -*)              func_fatal_help "unrecognized option \`$opt'" ;;
+      *)               set dummy "$opt" ${1+"$@"};     shift; break  ;;
     esac
   done
 
+  # Validate options:
+
+  # save first non-option argument
+  if test "$#" -gt 0; then
+    nonopt="$opt"
+    shift
+  fi
+
+  # preserve --debug
+  test "$opt_debug" = : || func_append preserve_args " --debug"
 
   case $host in
     *cygwin* | *mingw* | *pw32* | *cegcc*)
@@ -810,82 +1185,44 @@ func_enable_tag ()
       opt_duplicate_compiler_generated_deps=:
       ;;
     *)
-      opt_duplicate_compiler_generated_deps=$opt_duplicate_deps
+      opt_duplicate_compiler_generated_deps=$opt_preserve_dup_deps
       ;;
   esac
 
-  # Having warned about all mis-specified options, bail out if
-  # anything was wrong.
-  $exit_cmd $EXIT_FAILURE
-}
+  $opt_help || {
+    # Sanity checks first:
+    func_check_version_match
 
-# func_check_version_match
-# Ensure that we are using m4 macros, and libtool script from the same
-# release of libtool.
-func_check_version_match ()
-{
-  if test "$package_revision" != "$macro_revision"; then
-    if test "$VERSION" != "$macro_version"; then
-      if test -z "$macro_version"; then
-        cat >&2 <<_LT_EOF
-$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
-$progname: definition of this LT_INIT comes from an older release.
-$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
-$progname: and run autoconf again.
-_LT_EOF
-      else
-        cat >&2 <<_LT_EOF
-$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
-$progname: definition of this LT_INIT comes from $PACKAGE $macro_version.
-$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
-$progname: and run autoconf again.
-_LT_EOF
-      fi
-    else
-      cat >&2 <<_LT_EOF
-$progname: Version mismatch error.  This is $PACKAGE $VERSION, revision $package_revision,
-$progname: but the definition of this LT_INIT comes from revision $macro_revision.
-$progname: You should recreate aclocal.m4 with macros from revision $package_revision
-$progname: of $PACKAGE $VERSION and run autoconf again.
-_LT_EOF
+    if test "$build_libtool_libs" != yes && test "$build_old_libs" != yes; then
+      func_fatal_configuration "not configured to build any kind of library"
     fi
 
-    exit $EXIT_MISMATCH
-  fi
-}
-
-
-## ----------- ##
-##    Main.    ##
-## ----------- ##
-
-$opt_help || {
-  # Sanity checks first:
-  func_check_version_match
+    # Darwin sucks
+    eval std_shrext=\"$shrext_cmds\"
 
-  if test "$build_libtool_libs" != yes && test "$build_old_libs" != yes; then
-    func_fatal_configuration "not configured to build any kind of library"
-  fi
+    # Only execute mode is allowed to have -dlopen flags.
+    if test -n "$opt_dlopen" && test "$opt_mode" != execute; then
+      func_error "unrecognized option \`-dlopen'"
+      $ECHO "$help" 1>&2
+      exit $EXIT_FAILURE
+    fi
 
-  test -z "$mode" && func_fatal_error "error: you must specify a MODE."
+    # Change the help message to a mode-specific one.
+    generic_help="$help"
+    help="Try \`$progname --help --mode=$opt_mode' for more information."
+  }
 
 
-  # Darwin sucks
-  eval std_shrext=\"$shrext_cmds\"
+  # Bail if the options were screwed
+  $exit_cmd $EXIT_FAILURE
+}
 
 
-  # Only execute mode is allowed to have -dlopen flags.
-  if test -n "$execute_dlfiles" && test "$mode" != execute; then
-    func_error "unrecognized option \`-dlopen'"
-    $ECHO "$help" 1>&2
-    exit $EXIT_FAILURE
-  fi
 
-  # Change the help message to a mode-specific one.
-  generic_help="$help"
-  help="Try \`$progname --help --mode=$mode' for more information."
-}
 
+## ----------- ##
+##    Main.    ##
+## ----------- ##
 
 # func_lalib_p file
 # True iff FILE is a libtool `.la' library or `.lo' object file.
@@ -950,12 +1287,9 @@ func_ltwrapper_executable_p ()
 # temporary ltwrapper_script.
 func_ltwrapper_scriptname ()
 {
-    func_ltwrapper_scriptname_result=""
-    if func_ltwrapper_executable_p "$1"; then
-       func_dirname_and_basename "$1" "" "."
-       func_stripname '' '.exe' "$func_basename_result"
-       func_ltwrapper_scriptname_result="$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper"
-    fi
+    func_dirname_and_basename "$1" "" "."
+    func_stripname '' '.exe' "$func_basename_result"
+    func_ltwrapper_scriptname_result="$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper"
 }
 
 # func_ltwrapper_p file
@@ -1001,6 +1335,37 @@ func_source ()
 }
 
 
+# func_resolve_sysroot PATH
+# Replace a leading = in PATH with a sysroot.  Store the result into
+# func_resolve_sysroot_result
+func_resolve_sysroot ()
+{
+  func_resolve_sysroot_result=$1
+  case $func_resolve_sysroot_result in
+  =*)
+    func_stripname '=' '' "$func_resolve_sysroot_result"
+    func_resolve_sysroot_result=$lt_sysroot$func_stripname_result
+    ;;
+  esac
+}
+
+# func_replace_sysroot PATH
+# If PATH begins with the sysroot, replace it with = and
+# store the result into func_replace_sysroot_result.
+func_replace_sysroot ()
+{
+  case "$lt_sysroot:$1" in
+  ?*:"$lt_sysroot"*)
+    func_stripname "$lt_sysroot" '' "$1"
+    func_replace_sysroot_result="=$func_stripname_result"
+    ;;
+  *)
+    # Including no sysroot.
+    func_replace_sysroot_result=$1
+    ;;
+  esac
+}
+
 # func_infer_tag arg
 # Infer tagged configuration to use if any are available and
 # if one wasn't chosen via the "--tag" command line option.
@@ -1013,13 +1378,15 @@ func_infer_tag ()
     if test -n "$available_tags" && test -z "$tagname"; then
       CC_quoted=
       for arg in $CC; do
-        func_quote_for_eval "$arg"
-       CC_quoted="$CC_quoted $func_quote_for_eval_result"
+       func_append_quoted CC_quoted "$arg"
       done
+      CC_expanded=`func_echo_all $CC`
+      CC_quoted_expanded=`func_echo_all $CC_quoted`
       case $@ in
       # Blanks in the command may have been stripped by the calling shell,
       # but not from the CC environment variable when configure was run.
-      " $CC "* | "$CC "* | " `$ECHO $CC` "* | "`$ECHO $CC` "* | " $CC_quoted"* | "$CC_quoted "* | " `$ECHO $CC_quoted` "* | "`$ECHO $CC_quoted` "*) ;;
+      " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
+      " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*) ;;
       # Blanks at the start of $base_compile will cause this to fail
       # if we don't check for them as well.
       *)
@@ -1030,11 +1397,13 @@ func_infer_tag ()
            CC_quoted=
            for arg in $CC; do
              # Double-quote args containing other shell metacharacters.
-             func_quote_for_eval "$arg"
-             CC_quoted="$CC_quoted $func_quote_for_eval_result"
+             func_append_quoted CC_quoted "$arg"
            done
+           CC_expanded=`func_echo_all $CC`
+           CC_quoted_expanded=`func_echo_all $CC_quoted`
            case "$@ " in
-             " $CC "* | "$CC "* | " `$ECHO $CC` "* | "`$ECHO $CC` "* | " $CC_quoted"* | "$CC_quoted "* | " `$ECHO $CC_quoted` "* | "`$ECHO $CC_quoted` "*)
+           " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
+           " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*)
              # The compiler in the base compile command matches
              # the one in the tagged configuration.
              # Assume this is the tagged configuration we want.
@@ -1097,6 +1466,486 @@ EOF
     }
 }
 
+
+##################################################
+# FILE NAME AND PATH CONVERSION HELPER FUNCTIONS #
+##################################################
+
+# func_convert_core_file_wine_to_w32 ARG
+# Helper function used by file name conversion functions when $build is *nix,
+# and $host is mingw, cygwin, or some other w32 environment. Relies on a
+# correctly configured wine environment available, with the winepath program
+# in $build's $PATH.
+#
+# ARG is the $build file name to be converted to w32 format.
+# Result is available in $func_convert_core_file_wine_to_w32_result, and will
+# be empty on error (or when ARG is empty)
+func_convert_core_file_wine_to_w32 ()
+{
+  $opt_debug
+  func_convert_core_file_wine_to_w32_result="$1"
+  if test -n "$1"; then
+    # Unfortunately, winepath does not exit with a non-zero error code, so we
+    # are forced to check the contents of stdout. On the other hand, if the
+    # command is not found, the shell will set an exit code of 127 and print
+    # *an error message* to stdout. So we must check for both error code of
+    # zero AND non-empty stdout, which explains the odd construction:
+    func_convert_core_file_wine_to_w32_tmp=`winepath -w "$1" 2>/dev/null`
+    if test "$?" -eq 0 && test -n "${func_convert_core_file_wine_to_w32_tmp}"; then
+      func_convert_core_file_wine_to_w32_result=`$ECHO "$func_convert_core_file_wine_to_w32_tmp" |
+        $SED -e "$lt_sed_naive_backslashify"`
+    else
+      func_convert_core_file_wine_to_w32_result=
+    fi
+  fi
+}
+# end: func_convert_core_file_wine_to_w32
+
+
+# func_convert_core_path_wine_to_w32 ARG
+# Helper function used by path conversion functions when $build is *nix, and
+# $host is mingw, cygwin, or some other w32 environment. Relies on a correctly
+# configured wine environment available, with the winepath program in $build's
+# $PATH. Assumes ARG has no leading or trailing path separator characters.
+#
+# ARG is path to be converted from $build format to win32.
+# Result is available in $func_convert_core_path_wine_to_w32_result.
+# Unconvertible file (directory) names in ARG are skipped; if no directory names
+# are convertible, then the result may be empty.
+func_convert_core_path_wine_to_w32 ()
+{
+  $opt_debug
+  # unfortunately, winepath doesn't convert paths, only file names
+  func_convert_core_path_wine_to_w32_result=""
+  if test -n "$1"; then
+    oldIFS=$IFS
+    IFS=:
+    for func_convert_core_path_wine_to_w32_f in $1; do
+      IFS=$oldIFS
+      func_convert_core_file_wine_to_w32 "$func_convert_core_path_wine_to_w32_f"
+      if test -n "$func_convert_core_file_wine_to_w32_result" ; then
+        if test -z "$func_convert_core_path_wine_to_w32_result"; then
+          func_convert_core_path_wine_to_w32_result="$func_convert_core_file_wine_to_w32_result"
+        else
+          func_append func_convert_core_path_wine_to_w32_result ";$func_convert_core_file_wine_to_w32_result"
+        fi
+      fi
+    done
+    IFS=$oldIFS
+  fi
+}
+# end: func_convert_core_path_wine_to_w32
+
+
+# func_cygpath ARGS...
+# Wrapper around calling the cygpath program via LT_CYGPATH. This is used when
+# when (1) $build is *nix and Cygwin is hosted via a wine environment; or (2)
+# $build is MSYS and $host is Cygwin, or (3) $build is Cygwin. In case (1) or
+# (2), returns the Cygwin file name or path in func_cygpath_result (input
+# file name or path is assumed to be in w32 format, as previously converted
+# from $build's *nix or MSYS format). In case (3), returns the w32 file name
+# or path in func_cygpath_result (input file name or path is assumed to be in
+# Cygwin format). Returns an empty string on error.
+#
+# ARGS are passed to cygpath, with the last one being the file name or path to
+# be converted.
+#
+# Specify the absolute *nix (or w32) name to cygpath in the LT_CYGPATH
+# environment variable; do not put it in $PATH.
+func_cygpath ()
+{
+  $opt_debug
+  if test -n "$LT_CYGPATH" && test -f "$LT_CYGPATH"; then
+    func_cygpath_result=`$LT_CYGPATH "$@" 2>/dev/null`
+    if test "$?" -ne 0; then
+      # on failure, ensure result is empty
+      func_cygpath_result=
+    fi
+  else
+    func_cygpath_result=
+    func_error "LT_CYGPATH is empty or specifies non-existent file: \`$LT_CYGPATH'"
+  fi
+}
+#end: func_cygpath
+
+
+# func_convert_core_msys_to_w32 ARG
+# Convert file name or path ARG from MSYS format to w32 format.  Return
+# result in func_convert_core_msys_to_w32_result.
+func_convert_core_msys_to_w32 ()
+{
+  $opt_debug
+  # awkward: cmd appends spaces to result
+  func_convert_core_msys_to_w32_result=`( cmd //c echo "$1" ) 2>/dev/null |
+    $SED -e 's/[ ]*$//' -e "$lt_sed_naive_backslashify"`
+}
+#end: func_convert_core_msys_to_w32
+
+
+# func_convert_file_check ARG1 ARG2
+# Verify that ARG1 (a file name in $build format) was converted to $host
+# format in ARG2. Otherwise, emit an error message, but continue (resetting
+# func_to_host_file_result to ARG1).
+func_convert_file_check ()
+{
+  $opt_debug
+  if test -z "$2" && test -n "$1" ; then
+    func_error "Could not determine host file name corresponding to"
+    func_error "  \`$1'"
+    func_error "Continuing, but uninstalled executables may not work."
+    # Fallback:
+    func_to_host_file_result="$1"
+  fi
+}
+# end func_convert_file_check
+
+
+# func_convert_path_check FROM_PATHSEP TO_PATHSEP FROM_PATH TO_PATH
+# Verify that FROM_PATH (a path in $build format) was converted to $host
+# format in TO_PATH. Otherwise, emit an error message, but continue, resetting
+# func_to_host_file_result to a simplistic fallback value (see below).
+func_convert_path_check ()
+{
+  $opt_debug
+  if test -z "$4" && test -n "$3"; then
+    func_error "Could not determine the host path corresponding to"
+    func_error "  \`$3'"
+    func_error "Continuing, but uninstalled executables may not work."
+    # Fallback.  This is a deliberately simplistic "conversion" and
+    # should not be "improved".  See libtool.info.
+    if test "x$1" != "x$2"; then
+      lt_replace_pathsep_chars="s|$1|$2|g"
+      func_to_host_path_result=`echo "$3" |
+        $SED -e "$lt_replace_pathsep_chars"`
+    else
+      func_to_host_path_result="$3"
+    fi
+  fi
+}
+# end func_convert_path_check
+
+
+# func_convert_path_front_back_pathsep FRONTPAT BACKPAT REPL ORIG
+# Modifies func_to_host_path_result by prepending REPL if ORIG matches FRONTPAT
+# and appending REPL if ORIG matches BACKPAT.
+func_convert_path_front_back_pathsep ()
+{
+  $opt_debug
+  case $4 in
+  $1 ) func_to_host_path_result="$3$func_to_host_path_result"
+    ;;
+  esac
+  case $4 in
+  $2 ) func_append func_to_host_path_result "$3"
+    ;;
+  esac
+}
+# end func_convert_path_front_back_pathsep
+
+
+##################################################
+# $build to $host FILE NAME CONVERSION FUNCTIONS #
+##################################################
+# invoked via `$to_host_file_cmd ARG'
+#
+# In each case, ARG is the path to be converted from $build to $host format.
+# Result will be available in $func_to_host_file_result.
+
+
+# func_to_host_file ARG
+# Converts the file name ARG from $build format to $host format. Return result
+# in func_to_host_file_result.
+func_to_host_file ()
+{
+  $opt_debug
+  $to_host_file_cmd "$1"
+}
+# end func_to_host_file
+
+
+# func_to_tool_file ARG LAZY
+# converts the file name ARG from $build format to toolchain format. Return
+# result in func_to_tool_file_result.  If the conversion in use is listed
+# in (the comma separated) LAZY, no conversion takes place.
+func_to_tool_file ()
+{
+  $opt_debug
+  case ,$2, in
+    *,"$to_tool_file_cmd",*)
+      func_to_tool_file_result=$1
+      ;;
+    *)
+      $to_tool_file_cmd "$1"
+      func_to_tool_file_result=$func_to_host_file_result
+      ;;
+  esac
+}
+# end func_to_tool_file
+
+
+# func_convert_file_noop ARG
+# Copy ARG to func_to_host_file_result.
+func_convert_file_noop ()
+{
+  func_to_host_file_result="$1"
+}
+# end func_convert_file_noop
+
+
+# func_convert_file_msys_to_w32 ARG
+# Convert file name ARG from (mingw) MSYS to (mingw) w32 format; automatic
+# conversion to w32 is not available inside the cwrapper.  Returns result in
+# func_to_host_file_result.
+func_convert_file_msys_to_w32 ()
+{
+  $opt_debug
+  func_to_host_file_result="$1"
+  if test -n "$1"; then
+    func_convert_core_msys_to_w32 "$1"
+    func_to_host_file_result="$func_convert_core_msys_to_w32_result"
+  fi
+  func_convert_file_check "$1" "$func_to_host_file_result"
+}
+# end func_convert_file_msys_to_w32
+
+
+# func_convert_file_cygwin_to_w32 ARG
+# Convert file name ARG from Cygwin to w32 format.  Returns result in
+# func_to_host_file_result.
+func_convert_file_cygwin_to_w32 ()
+{
+  $opt_debug
+  func_to_host_file_result="$1"
+  if test -n "$1"; then
+    # because $build is cygwin, we call "the" cygpath in $PATH; no need to use
+    # LT_CYGPATH in this case.
+    func_to_host_file_result=`cygpath -m "$1"`
+  fi
+  func_convert_file_check "$1" "$func_to_host_file_result"
+}
+# end func_convert_file_cygwin_to_w32
+
+
+# func_convert_file_nix_to_w32 ARG
+# Convert file name ARG from *nix to w32 format.  Requires a wine environment
+# and a working winepath. Returns result in func_to_host_file_result.
+func_convert_file_nix_to_w32 ()
+{
+  $opt_debug
+  func_to_host_file_result="$1"
+  if test -n "$1"; then
+    func_convert_core_file_wine_to_w32 "$1"
+    func_to_host_file_result="$func_convert_core_file_wine_to_w32_result"
+  fi
+  func_convert_file_check "$1" "$func_to_host_file_result"
+}
+# end func_convert_file_nix_to_w32
+
+
+# func_convert_file_msys_to_cygwin ARG
+# Convert file name ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
+# Returns result in func_to_host_file_result.
+func_convert_file_msys_to_cygwin ()
+{
+  $opt_debug
+  func_to_host_file_result="$1"
+  if test -n "$1"; then
+    func_convert_core_msys_to_w32 "$1"
+    func_cygpath -u "$func_convert_core_msys_to_w32_result"
+    func_to_host_file_result="$func_cygpath_result"
+  fi
+  func_convert_file_check "$1" "$func_to_host_file_result"
+}
+# end func_convert_file_msys_to_cygwin
+
+
+# func_convert_file_nix_to_cygwin ARG
+# Convert file name ARG from *nix to Cygwin format.  Requires Cygwin installed
+# in a wine environment, working winepath, and LT_CYGPATH set.  Returns result
+# in func_to_host_file_result.
+func_convert_file_nix_to_cygwin ()
+{
+  $opt_debug
+  func_to_host_file_result="$1"
+  if test -n "$1"; then
+    # convert from *nix to w32, then use cygpath to convert from w32 to cygwin.
+    func_convert_core_file_wine_to_w32 "$1"
+    func_cygpath -u "$func_convert_core_file_wine_to_w32_result"
+    func_to_host_file_result="$func_cygpath_result"
+  fi
+  func_convert_file_check "$1" "$func_to_host_file_result"
+}
+# end func_convert_file_nix_to_cygwin
+
+
+#############################################
+# $build to $host PATH CONVERSION FUNCTIONS #
+#############################################
+# invoked via `$to_host_path_cmd ARG'
+#
+# In each case, ARG is the path to be converted from $build to $host format.
+# The result will be available in $func_to_host_path_result.
+#
+# Path separators are also converted from $build format to $host format.  If
+# ARG begins or ends with a path separator character, it is preserved (but
+# converted to $host format) on output.
+#
+# All path conversion functions are named using the following convention:
+#   file name conversion function    : func_convert_file_X_to_Y ()
+#   path conversion function         : func_convert_path_X_to_Y ()
+# where, for any given $build/$host combination the 'X_to_Y' value is the
+# same.  If conversion functions are added for new $build/$host combinations,
+# the two new functions must follow this pattern, or func_init_to_host_path_cmd
+# will break.
+
+
+# func_init_to_host_path_cmd
+# Ensures that function "pointer" variable $to_host_path_cmd is set to the
+# appropriate value, based on the value of $to_host_file_cmd.
+to_host_path_cmd=
+func_init_to_host_path_cmd ()
+{
+  $opt_debug
+  if test -z "$to_host_path_cmd"; then
+    func_stripname 'func_convert_file_' '' "$to_host_file_cmd"
+    to_host_path_cmd="func_convert_path_${func_stripname_result}"
+  fi
+}
+
+
+# func_to_host_path ARG
+# Converts the path ARG from $build format to $host format. Return result
+# in func_to_host_path_result.
+func_to_host_path ()
+{
+  $opt_debug
+  func_init_to_host_path_cmd
+  $to_host_path_cmd "$1"
+}
+# end func_to_host_path
+
+
+# func_convert_path_noop ARG
+# Copy ARG to func_to_host_path_result.
+func_convert_path_noop ()
+{
+  func_to_host_path_result="$1"
+}
+# end func_convert_path_noop
+
+
+# func_convert_path_msys_to_w32 ARG
+# Convert path ARG from (mingw) MSYS to (mingw) w32 format; automatic
+# conversion to w32 is not available inside the cwrapper.  Returns result in
+# func_to_host_path_result.
+func_convert_path_msys_to_w32 ()
+{
+  $opt_debug
+  func_to_host_path_result="$1"
+  if test -n "$1"; then
+    # Remove leading and trailing path separator characters from ARG.  MSYS
+    # behavior is inconsistent here; cygpath turns them into '.;' and ';.';
+    # and winepath ignores them completely.
+    func_stripname : : "$1"
+    func_to_host_path_tmp1=$func_stripname_result
+    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
+    func_to_host_path_result="$func_convert_core_msys_to_w32_result"
+    func_convert_path_check : ";" \
+      "$func_to_host_path_tmp1" "$func_to_host_path_result"
+    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
+  fi
+}
+# end func_convert_path_msys_to_w32
+
+
+# func_convert_path_cygwin_to_w32 ARG
+# Convert path ARG from Cygwin to w32 format.  Returns result in
+# func_to_host_file_result.
+func_convert_path_cygwin_to_w32 ()
+{
+  $opt_debug
+  func_to_host_path_result="$1"
+  if test -n "$1"; then
+    # See func_convert_path_msys_to_w32:
+    func_stripname : : "$1"
+    func_to_host_path_tmp1=$func_stripname_result
+    func_to_host_path_result=`cygpath -m -p "$func_to_host_path_tmp1"`
+    func_convert_path_check : ";" \
+      "$func_to_host_path_tmp1" "$func_to_host_path_result"
+    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
+  fi
+}
+# end func_convert_path_cygwin_to_w32
+
+
+# func_convert_path_nix_to_w32 ARG
+# Convert path ARG from *nix to w32 format.  Requires a wine environment and
+# a working winepath.  Returns result in func_to_host_file_result.
+func_convert_path_nix_to_w32 ()
+{
+  $opt_debug
+  func_to_host_path_result="$1"
+  if test -n "$1"; then
+    # See func_convert_path_msys_to_w32:
+    func_stripname : : "$1"
+    func_to_host_path_tmp1=$func_stripname_result
+    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
+    func_to_host_path_result="$func_convert_core_path_wine_to_w32_result"
+    func_convert_path_check : ";" \
+      "$func_to_host_path_tmp1" "$func_to_host_path_result"
+    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
+  fi
+}
+# end func_convert_path_nix_to_w32
+
+
+# func_convert_path_msys_to_cygwin ARG
+# Convert path ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
+# Returns result in func_to_host_file_result.
+func_convert_path_msys_to_cygwin ()
+{
+  $opt_debug
+  func_to_host_path_result="$1"
+  if test -n "$1"; then
+    # See func_convert_path_msys_to_w32:
+    func_stripname : : "$1"
+    func_to_host_path_tmp1=$func_stripname_result
+    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
+    func_cygpath -u -p "$func_convert_core_msys_to_w32_result"
+    func_to_host_path_result="$func_cygpath_result"
+    func_convert_path_check : : \
+      "$func_to_host_path_tmp1" "$func_to_host_path_result"
+    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
+  fi
+}
+# end func_convert_path_msys_to_cygwin
+
+
+# func_convert_path_nix_to_cygwin ARG
+# Convert path ARG from *nix to Cygwin format.  Requires Cygwin installed in a
+# a wine environment, working winepath, and LT_CYGPATH set.  Returns result in
+# func_to_host_file_result.
+func_convert_path_nix_to_cygwin ()
+{
+  $opt_debug
+  func_to_host_path_result="$1"
+  if test -n "$1"; then
+    # Remove leading and trailing path separator characters from
+    # ARG. msys behavior is inconsistent here, cygpath turns them
+    # into '.;' and ';.', and winepath ignores them completely.
+    func_stripname : : "$1"
+    func_to_host_path_tmp1=$func_stripname_result
+    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
+    func_cygpath -u -p "$func_convert_core_path_wine_to_w32_result"
+    func_to_host_path_result="$func_cygpath_result"
+    func_convert_path_check : : \
+      "$func_to_host_path_tmp1" "$func_to_host_path_result"
+    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
+  fi
+}
+# end func_convert_path_nix_to_cygwin
+
+
 # func_mode_compile arg...
 func_mode_compile ()
 {
@@ -1137,12 +1986,12 @@ func_mode_compile ()
          ;;
 
        -pie | -fpie | -fPIE)
-          pie_flag="$pie_flag $arg"
+          func_append pie_flag " $arg"
          continue
          ;;
 
        -shared | -static | -prefer-pic | -prefer-non-pic)
-         later="$later $arg"
+         func_append later " $arg"
          continue
          ;;
 
@@ -1163,15 +2012,14 @@ func_mode_compile ()
          save_ifs="$IFS"; IFS=','
          for arg in $args; do
            IFS="$save_ifs"
-           func_quote_for_eval "$arg"
-           lastarg="$lastarg $func_quote_for_eval_result"
+           func_append_quoted lastarg "$arg"
          done
          IFS="$save_ifs"
          func_stripname ' ' '' "$lastarg"
          lastarg=$func_stripname_result
 
          # Add the arguments to base_compile.
-         base_compile="$base_compile $lastarg"
+         func_append base_compile " $lastarg"
          continue
          ;;
 
@@ -1187,8 +2035,7 @@ func_mode_compile ()
       esac    #  case $arg_mode
 
       # Aesthetically quote the previous argument.
-      func_quote_for_eval "$lastarg"
-      base_compile="$base_compile $func_quote_for_eval_result"
+      func_append_quoted base_compile "$lastarg"
     done # for arg
 
     case $arg_mode in
@@ -1213,7 +2060,7 @@ func_mode_compile ()
     *.[cCFSifmso] | \
     *.ada | *.adb | *.ads | *.asm | \
     *.c++ | *.cc | *.ii | *.class | *.cpp | *.cxx | \
-    *.[fF][09]? | *.for | *.java | *.obj | *.sx)
+    *.[fF][09]? | *.for | *.java | *.go | *.obj | *.sx | *.cu | *.cup)
       func_xform "$libobj"
       libobj=$func_xform_result
       ;;
@@ -1288,7 +2135,7 @@ func_mode_compile ()
     # Calculate the filename of the output object if compiler does
     # not support -o with -c
     if test "$compiler_c_o" = no; then
-      output_obj=`$ECHO "X$srcfile" | $Xsed -e 's%^.*/%%' -e 's%\.[^.]*$%%'`.${objext}
+      output_obj=`$ECHO "$srcfile" | $SED 's%^.*/%%; s%\.[^.]*$%%'`.${objext}
       lockfile="$output_obj.lock"
     else
       output_obj=
@@ -1319,17 +2166,16 @@ compiler."
        $opt_dry_run || $RM $removelist
        exit $EXIT_FAILURE
       fi
-      removelist="$removelist $output_obj"
+      func_append removelist " $output_obj"
       $ECHO "$srcfile" > "$lockfile"
     fi
 
     $opt_dry_run || $RM $removelist
-    removelist="$removelist $lockfile"
+    func_append removelist " $lockfile"
     trap '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' 1 2 15
 
-    if test -n "$fix_srcfile_path"; then
-      eval srcfile=\"$fix_srcfile_path\"
-    fi
+    func_to_tool_file "$srcfile" func_convert_file_msys_to_w32
+    srcfile=$func_to_tool_file_result
     func_quote_for_eval "$srcfile"
     qsrcfile=$func_quote_for_eval_result
 
@@ -1349,7 +2195,7 @@ compiler."
 
       if test -z "$output_obj"; then
        # Place PIC objects in $objdir
-       command="$command -o $lobj"
+       func_append command " -o $lobj"
       fi
 
       func_show_eval_locale "$command" \
@@ -1396,11 +2242,11 @@ compiler."
        command="$base_compile $qsrcfile $pic_flag"
       fi
       if test "$compiler_c_o" = yes; then
-       command="$command -o $obj"
+       func_append command " -o $obj"
       fi
 
       # Suppress compiler output if we already did a PIC compilation.
-      command="$command$suppress_output"
+      func_append command "$suppress_output"
       func_show_eval_locale "$command" \
         '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE'
 
@@ -1445,13 +2291,13 @@ compiler."
 }
 
 $opt_help || {
-test "$mode" = compile && func_mode_compile ${1+"$@"}
+  test "$opt_mode" = compile && func_mode_compile ${1+"$@"}
 }
 
 func_mode_help ()
 {
     # We need to display help for each of the modes.
-    case $mode in
+    case $opt_mode in
       "")
         # Generic help is extracted from the usage comments
         # at the start of this file.
@@ -1482,10 +2328,11 @@ This mode accepts the following additional options:
 
   -o OUTPUT-FILE    set the output file name to OUTPUT-FILE
   -no-suppress      do not suppress compiler output for multiple passes
-  -prefer-pic       try to building PIC objects only
-  -prefer-non-pic   try to building non-PIC objects only
+  -prefer-pic       try to build PIC objects only
+  -prefer-non-pic   try to build non-PIC objects only
   -shared           do not build a \`.o' file suitable for static linking
   -static           only build a \`.o' file suitable for static linking
+  -Wc,FLAG          pass FLAG directly to the compiler
 
 COMPILE-COMMAND is a command to be used in creating a \`standard' object file
 from the given SOURCEFILE.
@@ -1538,7 +2385,7 @@ either the \`install' or \`cp' program.
 
 The following components of INSTALL-COMMAND are treated specially:
 
-  -inst-prefix PREFIX-DIR  Use PREFIX-DIR as a staging area for installation
+  -inst-prefix-dir PREFIX-DIR  Use PREFIX-DIR as a staging area for installation
 
 The rest of the components are interpreted as arguments to that command (only
 BSD-compatible install options are recognized)."
@@ -1558,6 +2405,8 @@ The following components of LINK-COMMAND are treated specially:
 
   -all-static       do not do any dynamic linking at all
   -avoid-version    do not add a version suffix if possible
+  -bindir BINDIR    specify path to binaries directory (for systems where
+                    libraries must be found in the PATH setting at runtime)
   -dlopen FILE      \`-dlpreopen' FILE if it cannot be dlopened at runtime
   -dlpreopen FILE   link in FILE and add its symbols to lt_preloaded_symbols
   -export-dynamic   allow symbols from OUTPUT-FILE to be resolved with dlsym(3)
@@ -1586,6 +2435,11 @@ The following components of LINK-COMMAND are treated specially:
   -version-info CURRENT[:REVISION[:AGE]]
                     specify library version info [each variable defaults to 0]
   -weak LIBNAME     declare that the target provides the LIBNAME interface
+  -Wc,FLAG
+  -Xcompiler FLAG   pass linker-specific FLAG directly to the compiler
+  -Wl,FLAG
+  -Xlinker FLAG     pass linker-specific FLAG directly to the linker
+  -XCClinker FLAG   pass link-specific FLAG to the compiler driver (CC)
 
 All other options (arguments beginning with \`-') are ignored.
 
@@ -1619,18 +2473,44 @@ Otherwise, only FILE itself is deleted using RM."
         ;;
 
       *)
-        func_fatal_help "invalid operation mode \`$mode'"
+        func_fatal_help "invalid operation mode \`$opt_mode'"
         ;;
     esac
 
-    $ECHO
+    echo
     $ECHO "Try \`$progname --help' for more information about other modes."
-
-    exit $?
 }
 
-  # Now that we've collected a possible --mode arg, show help if necessary
-  $opt_help && func_mode_help
+# Now that we've collected a possible --mode arg, show help if necessary
+if $opt_help; then
+  if test "$opt_help" = :; then
+    func_mode_help
+  else
+    {
+      func_help noexit
+      for opt_mode in compile link execute install finish uninstall clean; do
+       func_mode_help
+      done
+    } | sed -n '1p; 2,$s/^Usage:/  or: /p'
+    {
+      func_help noexit
+      for opt_mode in compile link execute install finish uninstall clean; do
+       echo
+       func_mode_help
+      done
+    } |
+    sed '1d
+      /^When reporting/,/^Report/{
+       H
+       d
+      }
+      $x
+      /information about other modes/d
+      /more detailed .*MODE/d
+      s/^Usage:.*--mode=\([^ ]*\) .*/Description of \1 mode:/'
+  fi
+  exit $?
+fi
 
 
 # func_mode_execute arg...
@@ -1643,13 +2523,16 @@ func_mode_execute ()
       func_fatal_help "you must specify a COMMAND"
 
     # Handle -dlopen flags immediately.
-    for file in $execute_dlfiles; do
+    for file in $opt_dlopen; do
       test -f "$file" \
        || func_fatal_help "\`$file' is not a file"
 
       dir=
       case $file in
       *.la)
+       func_resolve_sysroot "$file"
+       file=$func_resolve_sysroot_result
+
        # Check to see that this really is a libtool archive.
        func_lalib_unsafe_p "$file" \
          || func_fatal_help "\`$lib' is not a valid libtool archive"
@@ -1671,7 +2554,7 @@ func_mode_execute ()
        dir="$func_dirname_result"
 
        if test -f "$dir/$objdir/$dlname"; then
-         dir="$dir/$objdir"
+         func_append dir "/$objdir"
        else
          if test ! -f "$dir/$dlname"; then
            func_fatal_error "cannot find \`$dlname' in \`$dir' or \`$dir/$objdir'"
@@ -1712,7 +2595,7 @@ func_mode_execute ()
     for file
     do
       case $file in
-      -*) ;;
+      -* | *.la | *.lo ) ;;
       *)
        # Do a test to see if this is really a libtool program.
        if func_ltwrapper_script_p "$file"; then
@@ -1728,8 +2611,7 @@ func_mode_execute ()
        ;;
       esac
       # Quote arguments (to preserve shell metacharacters).
-      func_quote_for_eval "$file"
-      args="$args $func_quote_for_eval_result"
+      func_append_quoted args "$file"
     done
 
     if test "X$opt_dry_run" = Xfalse; then
@@ -1754,29 +2636,66 @@ func_mode_execute ()
       # Display what would be done.
       if test -n "$shlibpath_var"; then
        eval "\$ECHO \"\$shlibpath_var=\$$shlibpath_var\""
-       $ECHO "export $shlibpath_var"
+       echo "export $shlibpath_var"
       fi
       $ECHO "$cmd$args"
       exit $EXIT_SUCCESS
     fi
 }
 
-test "$mode" = execute && func_mode_execute ${1+"$@"}
+test "$opt_mode" = execute && func_mode_execute ${1+"$@"}
 
 
 # func_mode_finish arg...
 func_mode_finish ()
 {
     $opt_debug
-    libdirs="$nonopt"
+    libs=
+    libdirs=
     admincmds=
 
-    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
-      for dir
-      do
-       libdirs="$libdirs $dir"
-      done
+    for opt in "$nonopt" ${1+"$@"}
+    do
+      if test -d "$opt"; then
+       func_append libdirs " $opt"
+
+      elif test -f "$opt"; then
+       if func_lalib_unsafe_p "$opt"; then
+         func_append libs " $opt"
+       else
+         func_warning "\`$opt' is not a valid libtool archive"
+       fi
+
+      else
+       func_fatal_error "invalid argument \`$opt'"
+      fi
+    done
+
+    if test -n "$libs"; then
+      if test -n "$lt_sysroot"; then
+        sysroot_regex=`$ECHO "$lt_sysroot" | $SED "$sed_make_literal_regex"`
+        sysroot_cmd="s/\([ ']\)$sysroot_regex/\1/g;"
+      else
+        sysroot_cmd=
+      fi
+
+      # Remove sysroot references
+      if $opt_dry_run; then
+        for lib in $libs; do
+          echo "removing references to $lt_sysroot and \`=' prefixes from $lib"
+        done
+      else
+        tmpdir=`func_mktempdir`
+        for lib in $libs; do
+         sed -e "${sysroot_cmd} s/\([ ']-[LR]\)=/\1/g; s/\([ ']\)=/\1/g" $lib \
+           > $tmpdir/tmp-la
+         mv -f $tmpdir/tmp-la $lib
+       done
+        ${RM}r "$tmpdir"
+      fi
+    fi
 
+    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
       for libdir in $libdirs; do
        if test -n "$finish_cmds"; then
          # Do each command in the finish commands.
@@ -1786,7 +2705,7 @@ func_mode_finish ()
        if test -n "$finish_eval"; then
          # Do the single finish_eval.
          eval cmds=\"$finish_eval\"
-         $opt_dry_run || eval "$cmds" || admincmds="$admincmds
+         $opt_dry_run || eval "$cmds" || func_append admincmds "
        $cmds"
        fi
       done
@@ -1795,53 +2714,55 @@ func_mode_finish ()
     # Exit here if they wanted silent mode.
     $opt_silent && exit $EXIT_SUCCESS
 
-    $ECHO "X----------------------------------------------------------------------" | $Xsed
-    $ECHO "Libraries have been installed in:"
-    for libdir in $libdirs; do
-      $ECHO "   $libdir"
-    done
-    $ECHO
-    $ECHO "If you ever happen to want to link against installed libraries"
-    $ECHO "in a given directory, LIBDIR, you must either use libtool, and"
-    $ECHO "specify the full pathname of the library, or use the \`-LLIBDIR'"
-    $ECHO "flag during linking and do at least one of the following:"
-    if test -n "$shlibpath_var"; then
-      $ECHO "   - add LIBDIR to the \`$shlibpath_var' environment variable"
-      $ECHO "     during execution"
-    fi
-    if test -n "$runpath_var"; then
-      $ECHO "   - add LIBDIR to the \`$runpath_var' environment variable"
-      $ECHO "     during linking"
-    fi
-    if test -n "$hardcode_libdir_flag_spec"; then
-      libdir=LIBDIR
-      eval flag=\"$hardcode_libdir_flag_spec\"
+    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
+      echo "----------------------------------------------------------------------"
+      echo "Libraries have been installed in:"
+      for libdir in $libdirs; do
+       $ECHO "   $libdir"
+      done
+      echo
+      echo "If you ever happen to want to link against installed libraries"
+      echo "in a given directory, LIBDIR, you must either use libtool, and"
+      echo "specify the full pathname of the library, or use the \`-LLIBDIR'"
+      echo "flag during linking and do at least one of the following:"
+      if test -n "$shlibpath_var"; then
+       echo "   - add LIBDIR to the \`$shlibpath_var' environment variable"
+       echo "     during execution"
+      fi
+      if test -n "$runpath_var"; then
+       echo "   - add LIBDIR to the \`$runpath_var' environment variable"
+       echo "     during linking"
+      fi
+      if test -n "$hardcode_libdir_flag_spec"; then
+       libdir=LIBDIR
+       eval flag=\"$hardcode_libdir_flag_spec\"
 
-      $ECHO "   - use the \`$flag' linker flag"
-    fi
-    if test -n "$admincmds"; then
-      $ECHO "   - have your system administrator run these commands:$admincmds"
-    fi
-    if test -f /etc/ld.so.conf; then
-      $ECHO "   - have your system administrator add LIBDIR to \`/etc/ld.so.conf'"
-    fi
-    $ECHO
+       $ECHO "   - use the \`$flag' linker flag"
+      fi
+      if test -n "$admincmds"; then
+       $ECHO "   - have your system administrator run these commands:$admincmds"
+      fi
+      if test -f /etc/ld.so.conf; then
+       echo "   - have your system administrator add LIBDIR to \`/etc/ld.so.conf'"
+      fi
+      echo
 
-    $ECHO "See any operating system documentation about shared libraries for"
-    case $host in
-      solaris2.[6789]|solaris2.1[0-9])
-        $ECHO "more information, such as the ld(1), crle(1) and ld.so(8) manual"
-       $ECHO "pages."
-       ;;
-      *)
-        $ECHO "more information, such as the ld(1) and ld.so(8) manual pages."
-        ;;
-    esac
-    $ECHO "X----------------------------------------------------------------------" | $Xsed
+      echo "See any operating system documentation about shared libraries for"
+      case $host in
+       solaris2.[6789]|solaris2.1[0-9])
+         echo "more information, such as the ld(1), crle(1) and ld.so(8) manual"
+         echo "pages."
+         ;;
+       *)
+         echo "more information, such as the ld(1) and ld.so(8) manual pages."
+         ;;
+      esac
+      echo "----------------------------------------------------------------------"
+    fi
     exit $EXIT_SUCCESS
 }
 
-test "$mode" = finish && func_mode_finish ${1+"$@"}
+test "$opt_mode" = finish && func_mode_finish ${1+"$@"}
 
 
 # func_mode_install arg...
@@ -1852,7 +2773,7 @@ func_mode_install ()
     # install_prog (especially on Windows NT).
     if test "$nonopt" = "$SHELL" || test "$nonopt" = /bin/sh ||
        # Allow the use of GNU shtool's install command.
-       $ECHO "X$nonopt" | $GREP shtool >/dev/null; then
+       case $nonopt in *shtool*) :;; *) false;; esac; then
       # Aesthetically quote it.
       func_quote_for_eval "$nonopt"
       install_prog="$func_quote_for_eval_result "
@@ -1866,7 +2787,12 @@ func_mode_install ()
     # The real first argument should be the name of the installation program.
     # Aesthetically quote it.
     func_quote_for_eval "$arg"
-    install_prog="$install_prog$func_quote_for_eval_result"
+    func_append install_prog "$func_quote_for_eval_result"
+    install_shared_prog=$install_prog
+    case " $install_prog " in
+      *[\\\ /]cp\ *) install_cp=: ;;
+      *) install_cp=false ;;
+    esac
 
     # We need to accept at least all the BSD install flags.
     dest=
@@ -1876,10 +2802,12 @@ func_mode_install ()
     install_type=
     isdir=no
     stripme=
+    no_mode=:
     for arg
     do
+      arg2=
       if test -n "$dest"; then
-       files="$files $dest"
+       func_append files " $dest"
        dest=$arg
        continue
       fi
@@ -1887,10 +2815,9 @@ func_mode_install ()
       case $arg in
       -d) isdir=yes ;;
       -f)
-       case " $install_prog " in
-       *[\\\ /]cp\ *) ;;
-       *) prev=$arg ;;
-       esac
+       if $install_cp; then :; else
+         prev=$arg
+       fi
        ;;
       -g | -m | -o)
        prev=$arg
@@ -1904,6 +2831,10 @@ func_mode_install ()
       *)
        # If the previous option needed an argument, then skip it.
        if test -n "$prev"; then
+         if test "x$prev" = x-m && test -n "$install_override_mode"; then
+           arg2=$install_override_mode
+           no_mode=false
+         fi
          prev=
        else
          dest=$arg
@@ -1914,7 +2845,11 @@ func_mode_install ()
 
       # Aesthetically quote the argument.
       func_quote_for_eval "$arg"
-      install_prog="$install_prog $func_quote_for_eval_result"
+      func_append install_prog " $func_quote_for_eval_result"
+      if test -n "$arg2"; then
+       func_quote_for_eval "$arg2"
+      fi
+      func_append install_shared_prog " $func_quote_for_eval_result"
     done
 
     test -z "$install_prog" && \
@@ -1923,6 +2858,13 @@ func_mode_install ()
     test -n "$prev" && \
       func_fatal_help "the \`$prev' option requires an argument"
 
+    if test -n "$install_override_mode" && $no_mode; then
+      if $install_cp; then :; else
+       func_quote_for_eval "$install_override_mode"
+       func_append install_shared_prog " -m $func_quote_for_eval_result"
+      fi
+    fi
+
     if test -z "$files"; then
       if test -z "$dest"; then
        func_fatal_help "no file or destination specified"
@@ -1977,10 +2919,13 @@ func_mode_install ()
       case $file in
       *.$libext)
        # Do the static libraries later.
-       staticlibs="$staticlibs $file"
+       func_append staticlibs " $file"
        ;;
 
       *.la)
+       func_resolve_sysroot "$file"
+       file=$func_resolve_sysroot_result
+
        # Check to see that this really is a libtool archive.
        func_lalib_unsafe_p "$file" \
          || func_fatal_help "\`$file' is not a valid libtool archive"
@@ -1994,23 +2939,23 @@ func_mode_install ()
        if test "X$destdir" = "X$libdir"; then
          case "$current_libdirs " in
          *" $libdir "*) ;;
-         *) current_libdirs="$current_libdirs $libdir" ;;
+         *) func_append current_libdirs " $libdir" ;;
          esac
        else
          # Note the libdir as a future libdir.
          case "$future_libdirs " in
          *" $libdir "*) ;;
-         *) future_libdirs="$future_libdirs $libdir" ;;
+         *) func_append future_libdirs " $libdir" ;;
          esac
        fi
 
        func_dirname "$file" "/" ""
        dir="$func_dirname_result"
-       dir="$dir$objdir"
+       func_append dir "$objdir"
 
        if test -n "$relink_command"; then
          # Determine the prefix the user has applied to our future dir.
-         inst_prefix_dir=`$ECHO "X$destdir" | $Xsed -e "s%$libdir\$%%"`
+         inst_prefix_dir=`$ECHO "$destdir" | $SED -e "s%$libdir\$%%"`
 
          # Don't allow the user to place us outside of our expected
          # location b/c this prevents finding dependent libraries that
@@ -2023,9 +2968,9 @@ func_mode_install ()
 
          if test -n "$inst_prefix_dir"; then
            # Stick the inst_prefix_dir data into the link command.
-           relink_command=`$ECHO "X$relink_command" | $Xsed -e "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%"`
+           relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%"`
          else
-           relink_command=`$ECHO "X$relink_command" | $Xsed -e "s%@inst_prefix_dir@%%"`
+           relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%%"`
          fi
 
          func_warning "relinking \`$file'"
@@ -2043,7 +2988,7 @@ func_mode_install ()
          test -n "$relink_command" && srcname="$realname"T
 
          # Install the shared library and build the symlinks.
-         func_show_eval "$install_prog $dir/$srcname $destdir/$realname" \
+         func_show_eval "$install_shared_prog $dir/$srcname $destdir/$realname" \
              'exit $?'
          tstripme="$stripme"
          case $host_os in
@@ -2083,7 +3028,7 @@ func_mode_install ()
        func_show_eval "$install_prog $instname $destdir/$name" 'exit $?'
 
        # Maybe install the static library, too.
-       test -n "$old_library" && staticlibs="$staticlibs $dir/$old_library"
+       test -n "$old_library" && func_append staticlibs " $dir/$old_library"
        ;;
 
       *.lo)
@@ -2183,7 +3128,7 @@ func_mode_install ()
            if test -f "$lib"; then
              func_source "$lib"
            fi
-           libfile="$libdir/"`$ECHO "X$lib" | $Xsed -e 's%^.*/%%g'` ### testsuite: skip nested quoting test
+           libfile="$libdir/"`$ECHO "$lib" | $SED 's%^.*/%%g'` ### testsuite: skip nested quoting test
            if test -n "$libdir" && test ! -f "$libfile"; then
              func_warning "\`$lib' has not been installed in \`$libdir'"
              finalize=no
@@ -2202,7 +3147,7 @@ func_mode_install ()
                file="$func_basename_result"
                outputname="$tmpdir/$file"
                # Replace the output file specification.
-               relink_command=`$ECHO "X$relink_command" | $Xsed -e 's%@OUTPUT@%'"$outputname"'%g'`
+               relink_command=`$ECHO "$relink_command" | $SED 's%@OUTPUT@%'"$outputname"'%g'`
 
                $opt_silent || {
                  func_quote_for_expand "$relink_command"
@@ -2221,7 +3166,7 @@ func_mode_install ()
            }
          else
            # Install the binary that we compiled earlier.
-           file=`$ECHO "X$file$stripped_ext" | $Xsed -e "s%\([^/]*\)$%$objdir/\1%"`
+           file=`$ECHO "$file$stripped_ext" | $SED "s%\([^/]*\)$%$objdir/\1%"`
          fi
        fi
 
@@ -2257,11 +3202,13 @@ func_mode_install ()
 
       # Set up the ranlib parameters.
       oldlib="$destdir/$name"
+      func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
+      tool_oldlib=$func_to_tool_file_result
 
       func_show_eval "$install_prog \$file \$oldlib" 'exit $?'
 
       if test -n "$stripme" && test -n "$old_striplib"; then
-       func_show_eval "$old_striplib $oldlib" 'exit $?'
+       func_show_eval "$old_striplib $tool_oldlib" 'exit $?'
       fi
 
       # Do each command in the postinstall commands.
@@ -2280,7 +3227,7 @@ func_mode_install ()
     fi
 }
 
-test "$mode" = install && func_mode_install ${1+"$@"}
+test "$opt_mode" = install && func_mode_install ${1+"$@"}
 
 
 # func_generate_dlsyms outputname originator pic_p
@@ -2323,6 +3270,22 @@ func_generate_dlsyms ()
 extern \"C\" {
 #endif
 
+#if defined(__GNUC__) && (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4)) || (__GNUC__ > 4))
+#pragma GCC diagnostic ignored \"-Wstrict-prototypes\"
+#endif
+
+/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests.  */
+#if defined(_WIN32) || defined(__CYGWIN__) || defined(_WIN32_WCE)
+/* DATA imports from DLLs on WIN32 con't be const, because runtime
+   relocations are performed -- see ld's documentation on pseudo-relocs.  */
+# define LT_DLSYM_CONST
+#elif defined(__osf__)
+/* This system does not cope well with relocations in const data.  */
+# define LT_DLSYM_CONST
+#else
+# define LT_DLSYM_CONST const
+#endif
+
 /* External symbol declarations for the compiler. */\
 "
 
@@ -2332,10 +3295,11 @@ extern \"C\" {
          $opt_dry_run || echo ': @PROGRAM@ ' > "$nlist"
 
          # Add our own program objects to the symbol list.
-         progfiles=`$ECHO "X$objs$old_deplibs" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP`
+         progfiles=`$ECHO "$objs$old_deplibs" | $SP2NL | $SED "$lo2o" | $NL2SP`
          for progfile in $progfiles; do
-           func_verbose "extracting global C symbols from \`$progfile'"
-           $opt_dry_run || eval "$NM $progfile | $global_symbol_pipe >> '$nlist'"
+           func_to_tool_file "$progfile" func_convert_file_msys_to_w32
+           func_verbose "extracting global C symbols from \`$func_to_tool_file_result'"
+           $opt_dry_run || eval "$NM $func_to_tool_file_result | $global_symbol_pipe >> '$nlist'"
          done
 
          if test -n "$exclude_expsyms"; then
@@ -2371,7 +3335,7 @@ extern \"C\" {
              eval '$GREP -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T'
              eval '$MV "$nlist"T "$nlist"'
              case $host in
-               *cygwin | *mingw* | *cegcc* )
+               *cygwin* | *mingw* | *cegcc* )
                  eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
                  eval 'cat "$nlist" >> "$output_objdir/$outputname.def"'
                  ;;
@@ -2384,10 +3348,52 @@ extern \"C\" {
          func_verbose "extracting global C symbols from \`$dlprefile'"
          func_basename "$dlprefile"
          name="$func_basename_result"
-         $opt_dry_run || {
-           eval '$ECHO ": $name " >> "$nlist"'
-           eval "$NM $dlprefile 2>/dev/null | $global_symbol_pipe >> '$nlist'"
-         }
+          case $host in
+           *cygwin* | *mingw* | *cegcc* )
+             # if an import library, we need to obtain dlname
+             if func_win32_import_lib_p "$dlprefile"; then
+               func_tr_sh "$dlprefile"
+               eval "curr_lafile=\$libfile_$func_tr_sh_result"
+               dlprefile_dlbasename=""
+               if test -n "$curr_lafile" && func_lalib_p "$curr_lafile"; then
+                 # Use subshell, to avoid clobbering current variable values
+                 dlprefile_dlname=`source "$curr_lafile" && echo "$dlname"`
+                 if test -n "$dlprefile_dlname" ; then
+                   func_basename "$dlprefile_dlname"
+                   dlprefile_dlbasename="$func_basename_result"
+                 else
+                   # no lafile. user explicitly requested -dlpreopen <import library>.
+                   $sharedlib_from_linklib_cmd "$dlprefile"
+                   dlprefile_dlbasename=$sharedlib_from_linklib_result
+                 fi
+               fi
+               $opt_dry_run || {
+                 if test -n "$dlprefile_dlbasename" ; then
+                   eval '$ECHO ": $dlprefile_dlbasename" >> "$nlist"'
+                 else
+                   func_warning "Could not compute DLL name from $name"
+                   eval '$ECHO ": $name " >> "$nlist"'
+                 fi
+                 func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
+                 eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe |
+                   $SED -e '/I __imp/d' -e 's/I __nm_/D /;s/_nm__//' >> '$nlist'"
+               }
+             else # not an import lib
+               $opt_dry_run || {
+                 eval '$ECHO ": $name " >> "$nlist"'
+                 func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
+                 eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
+               }
+             fi
+           ;;
+           *)
+             $opt_dry_run || {
+               eval '$ECHO ": $name " >> "$nlist"'
+               func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
+               eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
+             }
+           ;;
+          esac
        done
 
        $opt_dry_run || {
@@ -2415,36 +3421,19 @@ extern \"C\" {
          if test -f "$nlist"S; then
            eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$my_dlsyms"'
          else
-           $ECHO '/* NONE */' >> "$output_objdir/$my_dlsyms"
+           echo '/* NONE */' >> "$output_objdir/$my_dlsyms"
          fi
 
-         $ECHO >> "$output_objdir/$my_dlsyms" "\
+         echo >> "$output_objdir/$my_dlsyms" "\
 
 /* The mapping between symbol names and symbols.  */
 typedef struct {
   const char *name;
   void *address;
 } lt_dlsymlist;
-"
-         case $host in
-         *cygwin* | *mingw* | *cegcc* )
-           $ECHO >> "$output_objdir/$my_dlsyms" "\
-/* DATA imports from DLLs on WIN32 con't be const, because
-   runtime relocations are performed -- see ld's documentation
-   on pseudo-relocs.  */"
-           lt_dlsym_const= ;;
-         *osf5*)
-           echo >> "$output_objdir/$my_dlsyms" "\
-/* This system does not cope well with relocations in const data */"
-           lt_dlsym_const= ;;
-         *)
-           lt_dlsym_const=const ;;
-         esac
-
-         $ECHO >> "$output_objdir/$my_dlsyms" "\
-extern $lt_dlsym_const lt_dlsymlist
+extern LT_DLSYM_CONST lt_dlsymlist
 lt_${my_prefix}_LTX_preloaded_symbols[];
-$lt_dlsym_const lt_dlsymlist
+LT_DLSYM_CONST lt_dlsymlist
 lt_${my_prefix}_LTX_preloaded_symbols[] =
 {\
   { \"$my_originator\", (void *) 0 },"
@@ -2457,7 +3446,7 @@ lt_${my_prefix}_LTX_preloaded_symbols[] =
            eval "$global_symbol_to_c_name_address_lib_prefix" < "$nlist" >> "$output_objdir/$my_dlsyms"
            ;;
          esac
-         $ECHO >> "$output_objdir/$my_dlsyms" "\
+         echo >> "$output_objdir/$my_dlsyms" "\
   {0, (void *) 0}
 };
 
@@ -2484,7 +3473,7 @@ static const void *lt_preloaded_setup() {
          # linked before any other PIC object.  But we must not use
          # pic_flag when linking with -static.  The problem exists in
          # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1.
-         *-*-freebsd2*|*-*-freebsd3.0*|*-*-freebsdelf3.0*)
+         *-*-freebsd2.*|*-*-freebsd3.0*|*-*-freebsdelf3.0*)
            pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND" ;;
          *-*-hpux*)
            pic_flag_for_symtable=" $pic_flag"  ;;
@@ -2500,7 +3489,7 @@ static const void *lt_preloaded_setup() {
        for arg in $LTCFLAGS; do
          case $arg in
          -pie | -fpie | -fPIE) ;;
-         *) symtab_cflags="$symtab_cflags $arg" ;;
+         *) func_append symtab_cflags " $arg" ;;
          esac
        done
 
@@ -2515,16 +3504,16 @@ static const void *lt_preloaded_setup() {
        case $host in
        *cygwin* | *mingw* | *cegcc* )
          if test -f "$output_objdir/$my_outputname.def"; then
-           compile_command=`$ECHO "X$compile_command" | $Xsed -e "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
-           finalize_command=`$ECHO "X$finalize_command" | $Xsed -e "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
+           compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
+           finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
          else
-           compile_command=`$ECHO "X$compile_command" | $Xsed -e "s%@SYMFILE@%$symfileobj%"`
-           finalize_command=`$ECHO "X$finalize_command" | $Xsed -e "s%@SYMFILE@%$symfileobj%"`
+           compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
+           finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
          fi
          ;;
        *)
-         compile_command=`$ECHO "X$compile_command" | $Xsed -e "s%@SYMFILE@%$symfileobj%"`
-         finalize_command=`$ECHO "X$finalize_command" | $Xsed -e "s%@SYMFILE@%$symfileobj%"`
+         compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
+         finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
          ;;
        esac
        ;;
@@ -2538,8 +3527,8 @@ static const void *lt_preloaded_setup() {
       # really was required.
 
       # Nullify the symbol file.
-      compile_command=`$ECHO "X$compile_command" | $Xsed -e "s% @SYMFILE@%%"`
-      finalize_command=`$ECHO "X$finalize_command" | $Xsed -e "s% @SYMFILE@%%"`
+      compile_command=`$ECHO "$compile_command" | $SED "s% @SYMFILE@%%"`
+      finalize_command=`$ECHO "$finalize_command" | $SED "s% @SYMFILE@%%"`
     fi
 }
 
@@ -2549,6 +3538,7 @@ static const void *lt_preloaded_setup() {
 # Need a lot of goo to handle *both* DLLs and import libs
 # Has to be a shell function in order to 'eat' the argument
 # that is supplied when $file_magic_command is called.
+# Despite the name, also deal with 64 bit binaries.
 func_win32_libid ()
 {
   $opt_debug
@@ -2559,9 +3549,11 @@ func_win32_libid ()
     win32_libid_type="x86 archive import"
     ;;
   *ar\ archive*) # could be an import, or static
+    # Keep the egrep pattern in sync with the one in _LT_CHECK_MAGIC_METHOD.
     if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null |
-       $EGREP 'file format pe-i386(.*architecture: i386)?' >/dev/null ; then
-      win32_nmres=`eval $NM -f posix -A $1 |
+       $EGREP 'file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)' >/dev/null; then
+      func_to_tool_file "$1" func_convert_file_msys_to_w32
+      win32_nmres=`eval $NM -f posix -A \"$func_to_tool_file_result\" |
        $SED -n -e '
            1,100{
                / I /{
@@ -2590,6 +3582,131 @@ func_win32_libid ()
   $ECHO "$win32_libid_type"
 }
 
+# func_cygming_dll_for_implib ARG
+#
+# Platform-specific function to extract the
+# name of the DLL associated with the specified
+# import library ARG.
+# Invoked by eval'ing the libtool variable
+#    $sharedlib_from_linklib_cmd
+# Result is available in the variable
+#    $sharedlib_from_linklib_result
+func_cygming_dll_for_implib ()
+{
+  $opt_debug
+  sharedlib_from_linklib_result=`$DLLTOOL --identify-strict --identify "$1"`
+}
+
+# func_cygming_dll_for_implib_fallback_core SECTION_NAME LIBNAMEs
+#
+# The is the core of a fallback implementation of a
+# platform-specific function to extract the name of the
+# DLL associated with the specified import library LIBNAME.
+#
+# SECTION_NAME is either .idata$6 or .idata$7, depending
+# on the platform and compiler that created the implib.
+#
+# Echos the name of the DLL associated with the
+# specified import library.
+func_cygming_dll_for_implib_fallback_core ()
+{
+  $opt_debug
+  match_literal=`$ECHO "$1" | $SED "$sed_make_literal_regex"`
+  $OBJDUMP -s --section "$1" "$2" 2>/dev/null |
+    $SED '/^Contents of section '"$match_literal"':/{
+      # Place marker at beginning of archive member dllname section
+      s/.*/====MARK====/
+      p
+      d
+    }
+    # These lines can sometimes be longer than 43 characters, but
+    # are always uninteresting
+    /:[         ]*file format pe[i]\{,1\}-/d
+    /^In archive [^:]*:/d
+    # Ensure marker is printed
+    /^====MARK====/p
+    # Remove all lines with less than 43 characters
+    /^.\{43\}/!d
+    # From remaining lines, remove first 43 characters
+    s/^.\{43\}//' |
+    $SED -n '
+      # Join marker and all lines until next marker into a single line
+      /^====MARK====/ b para
+      H
+      $ b para
+      b
+      :para
+      x
+      s/\n//g
+      # Remove the marker
+      s/^====MARK====//
+      # Remove trailing dots and whitespace
+      s/[\. \t]*$//
+      # Print
+      /./p' |
+    # we now have a list, one entry per line, of the stringified
+    # contents of the appropriate section of all members of the
+    # archive which possess that section. Heuristic: eliminate
+    # all those which have a first or second character that is
+    # a '.' (that is, objdump's representation of an unprintable
+    # character.) This should work for all archives with less than
+    # 0x302f exports -- but will fail for DLLs whose name actually
+    # begins with a literal '.' or a single character followed by
+    # a '.'.
+    #
+    # Of those that remain, print the first one.
+    $SED -e '/^\./d;/^.\./d;q'
+}
+
+# func_cygming_gnu_implib_p ARG
+# This predicate returns with zero status (TRUE) if
+# ARG is a GNU/binutils-style import library. Returns
+# with nonzero status (FALSE) otherwise.
+func_cygming_gnu_implib_p ()
+{
+  $opt_debug
+  func_to_tool_file "$1" func_convert_file_msys_to_w32
+  func_cygming_gnu_implib_tmp=`$NM "$func_to_tool_file_result" | eval "$global_symbol_pipe" | $EGREP ' (_head_[A-Za-z0-9_]+_[ad]l*|[A-Za-z0-9_]+_[ad]l*_iname)$'`
+  test -n "$func_cygming_gnu_implib_tmp"
+}
+
+# func_cygming_ms_implib_p ARG
+# This predicate returns with zero status (TRUE) if
+# ARG is an MS-style import library. Returns
+# with nonzero status (FALSE) otherwise.
+func_cygming_ms_implib_p ()
+{
+  $opt_debug
+  func_to_tool_file "$1" func_convert_file_msys_to_w32
+  func_cygming_ms_implib_tmp=`$NM "$func_to_tool_file_result" | eval "$global_symbol_pipe" | $GREP '_NULL_IMPORT_DESCRIPTOR'`
+  test -n "$func_cygming_ms_implib_tmp"
+}
+
+# func_cygming_dll_for_implib_fallback ARG
+# Platform-specific function to extract the
+# name of the DLL associated with the specified
+# import library ARG.
+#
+# This fallback implementation is for use when $DLLTOOL
+# does not support the --identify-strict option.
+# Invoked by eval'ing the libtool variable
+#    $sharedlib_from_linklib_cmd
+# Result is available in the variable
+#    $sharedlib_from_linklib_result
+func_cygming_dll_for_implib_fallback ()
+{
+  $opt_debug
+  if func_cygming_gnu_implib_p "$1" ; then
+    # binutils import library
+    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$7' "$1"`
+  elif func_cygming_ms_implib_p "$1" ; then
+    # ms-generated import library
+    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$6' "$1"`
+  else
+    # unknown
+    sharedlib_from_linklib_result=""
+  fi
+}
 
 
 # func_extract_an_archive dir oldlib
@@ -2598,7 +3715,18 @@ func_extract_an_archive ()
     $opt_debug
     f_ex_an_ar_dir="$1"; shift
     f_ex_an_ar_oldlib="$1"
-    func_show_eval "(cd \$f_ex_an_ar_dir && $AR x \"\$f_ex_an_ar_oldlib\")" 'exit $?'
+    if test "$lock_old_archive_extraction" = yes; then
+      lockfile=$f_ex_an_ar_oldlib.lock
+      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
+       func_echo "Waiting for $lockfile to be removed"
+       sleep 2
+      done
+    fi
+    func_show_eval "(cd \$f_ex_an_ar_dir && $AR x \"\$f_ex_an_ar_oldlib\")" \
+                  'stat=$?; rm -f "$lockfile"; exit $stat'
+    if test "$lock_old_archive_extraction" = yes; then
+      $opt_dry_run || rm -f "$lockfile"
+    fi
     if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then
      :
     else
@@ -2669,7 +3797,7 @@ func_extract_archives ()
            darwin_file=
            darwin_files=
            for darwin_file in $darwin_filelist; do
-             darwin_files=`find unfat-$$ -name $darwin_file -print | $NL2SP`
+             darwin_files=`find unfat-$$ -name $darwin_file -print | sort | $NL2SP`
              $LIPO -create -output "$darwin_file" $darwin_files
            done # $darwin_filelist
            $RM -rf unfat-$$
@@ -2684,25 +3812,30 @@ func_extract_archives ()
         func_extract_an_archive "$my_xdir" "$my_xabs"
        ;;
       esac
-      my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | $NL2SP`
+      my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | sort | $NL2SP`
     done
 
     func_extract_archives_result="$my_oldobjs"
 }
 
 
-
-# func_emit_wrapper_part1 [arg=no]
+# func_emit_wrapper [arg=no]
+#
+# Emit a libtool wrapper script on stdout.
+# Don't directly open a file because we may want to
+# incorporate the script contents within a cygwin/mingw
+# wrapper executable.  Must ONLY be called from within
+# func_mode_link because it depends on a number of variables
+# set therein.
 #
-# Emit the first part of a libtool wrapper script on stdout.
-# For more information, see the description associated with
-# func_emit_wrapper(), below.
-func_emit_wrapper_part1 ()
+# ARG is the value that the WRAPPER_SCRIPT_BELONGS_IN_OBJDIR
+# variable will take.  If 'yes', then the emitted script
+# will assume that the directory in which it is stored is
+# the $objdir directory.  This is a cygwin/mingw-specific
+# behavior.
+func_emit_wrapper ()
 {
-       func_emit_wrapper_part1_arg1=no
-       if test -n "$1" ; then
-         func_emit_wrapper_part1_arg1=$1
-       fi
+       func_emit_wrapper_arg1=${1-no}
 
        $ECHO "\
 #! $SHELL
@@ -2718,7 +3851,6 @@ func_emit_wrapper_part1 ()
 
 # Sed substitution that helps us do robust quoting.  It backslashifies
 # metacharacters that are still active within double-quoted strings.
-Xsed='${SED} -e 1s/^X//'
 sed_quote_subst='$sed_quote_subst'
 
 # Be Bourne compatible
@@ -2749,31 +3881,135 @@ if test \"\$libtool_install_magic\" = \"$magic\"; then
 else
   # When we are sourced in execute mode, \$file and \$ECHO are already set.
   if test \"\$libtool_execute_magic\" != \"$magic\"; then
-    ECHO=\"$qecho\"
-    file=\"\$0\"
-    # Make sure echo works.
-    if test \"X\$1\" = X--no-reexec; then
-      # Discard the --no-reexec flag, and continue.
-      shift
-    elif test \"X\`{ \$ECHO '\t'; } 2>/dev/null\`\" = 'X\t'; then
-      # Yippee, \$ECHO works!
-      :
-    else
-      # Restart under the correct shell, and then maybe \$ECHO will work.
-      exec $SHELL \"\$0\" --no-reexec \${1+\"\$@\"}
-    fi
-  fi\
+    file=\"\$0\""
+
+    qECHO=`$ECHO "$ECHO" | $SED "$sed_quote_subst"`
+    $ECHO "\
+
+# A function that is used when there is no print builtin or printf.
+func_fallback_echo ()
+{
+  eval 'cat <<_LTECHO_EOF
+\$1
+_LTECHO_EOF'
+}
+    ECHO=\"$qECHO\"
+  fi
+
+# Very basic option parsing. These options are (a) specific to
+# the libtool wrapper, (b) are identical between the wrapper
+# /script/ and the wrapper /executable/ which is used only on
+# windows platforms, and (c) all begin with the string "--lt-"
+# (application programs are unlikely to have options which match
+# this pattern).
+#
+# There are only two supported options: --lt-debug and
+# --lt-dump-script. There is, deliberately, no --lt-help.
+#
+# The first argument to this parsing function should be the
+# script's $0 value, followed by "$@".
+lt_option_debug=
+func_parse_lt_options ()
+{
+  lt_script_arg0=\$0
+  shift
+  for lt_opt
+  do
+    case \"\$lt_opt\" in
+    --lt-debug) lt_option_debug=1 ;;
+    --lt-dump-script)
+        lt_dump_D=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%/[^/]*$%%'\`
+        test \"X\$lt_dump_D\" = \"X\$lt_script_arg0\" && lt_dump_D=.
+        lt_dump_F=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%^.*/%%'\`
+        cat \"\$lt_dump_D/\$lt_dump_F\"
+        exit 0
+      ;;
+    --lt-*)
+        \$ECHO \"Unrecognized --lt- option: '\$lt_opt'\" 1>&2
+        exit 1
+      ;;
+    esac
+  done
+
+  # Print the debug banner immediately:
+  if test -n \"\$lt_option_debug\"; then
+    echo \"${outputname}:${output}:\${LINENO}: libtool wrapper (GNU $PACKAGE$TIMESTAMP) $VERSION\" 1>&2
+  fi
+}
+
+# Used when --lt-debug. Prints its arguments to stdout
+# (redirection is the responsibility of the caller)
+func_lt_dump_args ()
+{
+  lt_dump_args_N=1;
+  for lt_arg
+  do
+    \$ECHO \"${outputname}:${output}:\${LINENO}: newargv[\$lt_dump_args_N]: \$lt_arg\"
+    lt_dump_args_N=\`expr \$lt_dump_args_N + 1\`
+  done
+}
+
+# Core function for launching the target application
+func_exec_program_core ()
+{
 "
-       $ECHO "\
+  case $host in
+  # Backslashes separate directories on plain windows
+  *-*-mingw | *-*-os2* | *-cegcc*)
+    $ECHO "\
+      if test -n \"\$lt_option_debug\"; then
+        \$ECHO \"${outputname}:${output}:\${LINENO}: newargv[0]: \$progdir\\\\\$program\" 1>&2
+        func_lt_dump_args \${1+\"\$@\"} 1>&2
+      fi
+      exec \"\$progdir\\\\\$program\" \${1+\"\$@\"}
+"
+    ;;
+
+  *)
+    $ECHO "\
+      if test -n \"\$lt_option_debug\"; then
+        \$ECHO \"${outputname}:${output}:\${LINENO}: newargv[0]: \$progdir/\$program\" 1>&2
+        func_lt_dump_args \${1+\"\$@\"} 1>&2
+      fi
+      exec \"\$progdir/\$program\" \${1+\"\$@\"}
+"
+    ;;
+  esac
+  $ECHO "\
+      \$ECHO \"\$0: cannot exec \$program \$*\" 1>&2
+      exit 1
+}
+
+# A function to encapsulate launching the target application
+# Strips options in the --lt-* namespace from \$@ and
+# launches target application with the remaining arguments.
+func_exec_program ()
+{
+  case \" \$* \" in
+  *\\ --lt-*)
+    for lt_wr_arg
+    do
+      case \$lt_wr_arg in
+      --lt-*) ;;
+      *) set x \"\$@\" \"\$lt_wr_arg\"; shift;;
+      esac
+      shift
+    done ;;
+  esac
+  func_exec_program_core \${1+\"\$@\"}
+}
+
+  # Parse options
+  func_parse_lt_options \"\$0\" \${1+\"\$@\"}
 
   # Find the directory that this script lives in.
-  thisdir=\`\$ECHO \"X\$file\" | \$Xsed -e 's%/[^/]*$%%'\`
+  thisdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*$%%'\`
   test \"x\$thisdir\" = \"x\$file\" && thisdir=.
 
   # Follow symbolic links until we get to the real thisdir.
-  file=\`ls -ld \"\$file\" | ${SED} -n 's/.*-> //p'\`
+  file=\`ls -ld \"\$file\" | $SED -n 's/.*-> //p'\`
   while test -n \"\$file\"; do
-    destdir=\`\$ECHO \"X\$file\" | \$Xsed -e 's%/[^/]*\$%%'\`
+    destdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*\$%%'\`
 
     # If there was a directory component, then change thisdir.
     if test \"x\$destdir\" != \"x\$file\"; then
@@ -2783,30 +4019,13 @@ else
       esac
     fi
 
-    file=\`\$ECHO \"X\$file\" | \$Xsed -e 's%^.*/%%'\`
-    file=\`ls -ld \"\$thisdir/\$file\" | ${SED} -n 's/.*-> //p'\`
+    file=\`\$ECHO \"\$file\" | $SED 's%^.*/%%'\`
+    file=\`ls -ld \"\$thisdir/\$file\" | $SED -n 's/.*-> //p'\`
   done
-"
-}
-# end: func_emit_wrapper_part1
-
-# func_emit_wrapper_part2 [arg=no]
-#
-# Emit the second part of a libtool wrapper script on stdout.
-# For more information, see the description associated with
-# func_emit_wrapper(), below.
-func_emit_wrapper_part2 ()
-{
-       func_emit_wrapper_part2_arg1=no
-       if test -n "$1" ; then
-         func_emit_wrapper_part2_arg1=$1
-       fi
-
-       $ECHO "\
 
   # Usually 'no', except on cygwin/mingw when embedded into
   # the cwrapper.
-  WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_wrapper_part2_arg1
+  WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_wrapper_arg1
   if test \"\$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR\" = \"yes\"; then
     # special case for '.'
     if test \"\$thisdir\" = \".\"; then
@@ -2814,7 +4033,7 @@ func_emit_wrapper_part2 ()
     fi
     # remove .libs from thisdir
     case \"\$thisdir\" in
-    *[\\\\/]$objdir ) thisdir=\`\$ECHO \"X\$thisdir\" | \$Xsed -e 's%[\\\\/][^\\\\/]*$%%'\` ;;
+    *[\\\\/]$objdir ) thisdir=\`\$ECHO \"\$thisdir\" | $SED 's%[\\\\/][^\\\\/]*$%%'\` ;;
     $objdir )   thisdir=. ;;
     esac
   fi
@@ -2869,6 +4088,18 @@ func_emit_wrapper_part2 ()
 
   if test -f \"\$progdir/\$program\"; then"
 
+       # fixup the dll searchpath if we need to.
+       #
+       # Fix the DLL searchpath if we need to.  Do this before prepending
+       # to shlibpath, because on Windows, both are PATH and uninstalled
+       # libraries must come first.
+       if test -n "$dllsearchpath"; then
+         $ECHO "\
+    # Add the dll search path components to the executable PATH
+    PATH=$dllsearchpath:\$PATH
+"
+       fi
+
        # Export our shlibpath_var if we have one.
        if test "$shlibpath_overrides_runpath" = yes && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
          $ECHO "\
@@ -2877,253 +4108,28 @@ func_emit_wrapper_part2 ()
 
     # Some systems cannot cope with colon-terminated $shlibpath_var
     # The second colon is a workaround for a bug in BeOS R4 sed
-    $shlibpath_var=\`\$ECHO \"X\$$shlibpath_var\" | \$Xsed -e 's/::*\$//'\`
+    $shlibpath_var=\`\$ECHO \"\$$shlibpath_var\" | $SED 's/::*\$//'\`
 
     export $shlibpath_var
 "
        fi
 
-       # fixup the dll searchpath if we need to.
-       if test -n "$dllsearchpath"; then
-         $ECHO "\
-    # Add the dll search path components to the executable PATH
-    PATH=$dllsearchpath:\$PATH
-"
-       fi
-
        $ECHO "\
     if test \"\$libtool_execute_magic\" != \"$magic\"; then
       # Run the actual program with our arguments.
-"
-       case $host in
-       # Backslashes separate directories on plain windows
-       *-*-mingw | *-*-os2* | *-cegcc*)
-         $ECHO "\
-      exec \"\$progdir\\\\\$program\" \${1+\"\$@\"}
-"
-         ;;
-
-       *)
-         $ECHO "\
-      exec \"\$progdir/\$program\" \${1+\"\$@\"}
-"
-         ;;
-       esac
-       $ECHO "\
-      \$ECHO \"\$0: cannot exec \$program \$*\" 1>&2
-      exit 1
+      func_exec_program \${1+\"\$@\"}
     fi
   else
     # The program doesn't exist.
     \$ECHO \"\$0: error: \\\`\$progdir/\$program' does not exist\" 1>&2
     \$ECHO \"This script is just a wrapper for \$program.\" 1>&2
-    $ECHO \"See the $PACKAGE documentation for more information.\" 1>&2
+    \$ECHO \"See the $PACKAGE documentation for more information.\" 1>&2
     exit 1
   fi
 fi\
 "
 }
-# end: func_emit_wrapper_part2
-
-
-# func_emit_wrapper [arg=no]
-#
-# Emit a libtool wrapper script on stdout.
-# Don't directly open a file because we may want to
-# incorporate the script contents within a cygwin/mingw
-# wrapper executable.  Must ONLY be called from within
-# func_mode_link because it depends on a number of variables
-# set therein.
-#
-# ARG is the value that the WRAPPER_SCRIPT_BELONGS_IN_OBJDIR
-# variable will take.  If 'yes', then the emitted script
-# will assume that the directory in which it is stored is
-# the $objdir directory.  This is a cygwin/mingw-specific
-# behavior.
-func_emit_wrapper ()
-{
-       func_emit_wrapper_arg1=no
-       if test -n "$1" ; then
-         func_emit_wrapper_arg1=$1
-       fi
-
-       # split this up so that func_emit_cwrapperexe_src
-       # can call each part independently.
-       func_emit_wrapper_part1 "${func_emit_wrapper_arg1}"
-       func_emit_wrapper_part2 "${func_emit_wrapper_arg1}"
-}
-
-
-# func_to_host_path arg
-#
-# Convert paths to host format when used with build tools.
-# Intended for use with "native" mingw (where libtool itself
-# is running under the msys shell), or in the following cross-
-# build environments:
-#    $build          $host
-#    mingw (msys)    mingw  [e.g. native]
-#    cygwin          mingw
-#    *nix + wine     mingw
-# where wine is equipped with the `winepath' executable.
-# In the native mingw case, the (msys) shell automatically
-# converts paths for any non-msys applications it launches,
-# but that facility isn't available from inside the cwrapper.
-# Similar accommodations are necessary for $host mingw and
-# $build cygwin.  Calling this function does no harm for other
-# $host/$build combinations not listed above.
-#
-# ARG is the path (on $build) that should be converted to
-# the proper representation for $host. The result is stored
-# in $func_to_host_path_result.
-func_to_host_path ()
-{
-  func_to_host_path_result="$1"
-  if test -n "$1" ; then
-    case $host in
-      *mingw* )
-        lt_sed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
-        case $build in
-          *mingw* ) # actually, msys
-            # awkward: cmd appends spaces to result
-            lt_sed_strip_trailing_spaces="s/[ ]*\$//"
-            func_to_host_path_tmp1=`( cmd //c echo "$1" |\
-              $SED -e "$lt_sed_strip_trailing_spaces" ) 2>/dev/null || echo ""`
-            func_to_host_path_result=`echo "$func_to_host_path_tmp1" |\
-              $SED -e "$lt_sed_naive_backslashify"`
-            ;;
-          *cygwin* )
-            func_to_host_path_tmp1=`cygpath -w "$1"`
-            func_to_host_path_result=`echo "$func_to_host_path_tmp1" |\
-              $SED -e "$lt_sed_naive_backslashify"`
-            ;;
-          * )
-            # Unfortunately, winepath does not exit with a non-zero
-            # error code, so we are forced to check the contents of
-            # stdout. On the other hand, if the command is not
-            # found, the shell will set an exit code of 127 and print
-            # *an error message* to stdout. So we must check for both
-            # error code of zero AND non-empty stdout, which explains
-            # the odd construction:
-            func_to_host_path_tmp1=`winepath -w "$1" 2>/dev/null`
-            if test "$?" -eq 0 && test -n "${func_to_host_path_tmp1}"; then
-              func_to_host_path_result=`echo "$func_to_host_path_tmp1" |\
-                $SED -e "$lt_sed_naive_backslashify"`
-            else
-              # Allow warning below.
-              func_to_host_path_result=""
-            fi
-            ;;
-        esac
-        if test -z "$func_to_host_path_result" ; then
-          func_error "Could not determine host path corresponding to"
-          func_error "  '$1'"
-          func_error "Continuing, but uninstalled executables may not work."
-          # Fallback:
-          func_to_host_path_result="$1"
-        fi
-        ;;
-    esac
-  fi
-}
-# end: func_to_host_path
 
-# func_to_host_pathlist arg
-#
-# Convert pathlists to host format when used with build tools.
-# See func_to_host_path(), above. This function supports the
-# following $build/$host combinations (but does no harm for
-# combinations not listed here):
-#    $build          $host
-#    mingw (msys)    mingw  [e.g. native]
-#    cygwin          mingw
-#    *nix + wine     mingw
-#
-# Path separators are also converted from $build format to
-# $host format. If ARG begins or ends with a path separator
-# character, it is preserved (but converted to $host format)
-# on output.
-#
-# ARG is a pathlist (on $build) that should be converted to
-# the proper representation on $host. The result is stored
-# in $func_to_host_pathlist_result.
-func_to_host_pathlist ()
-{
-  func_to_host_pathlist_result="$1"
-  if test -n "$1" ; then
-    case $host in
-      *mingw* )
-        lt_sed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
-        # Remove leading and trailing path separator characters from
-        # ARG. msys behavior is inconsistent here, cygpath turns them
-        # into '.;' and ';.', and winepath ignores them completely.
-        func_to_host_pathlist_tmp2="$1"
-        # Once set for this call, this variable should not be
-        # reassigned. It is used in tha fallback case.
-        func_to_host_pathlist_tmp1=`echo "$func_to_host_pathlist_tmp2" |\
-          $SED -e 's|^:*||' -e 's|:*$||'`
-        case $build in
-          *mingw* ) # Actually, msys.
-            # Awkward: cmd appends spaces to result.
-            lt_sed_strip_trailing_spaces="s/[ ]*\$//"
-            func_to_host_pathlist_tmp2=`( cmd //c echo "$func_to_host_pathlist_tmp1" |\
-              $SED -e "$lt_sed_strip_trailing_spaces" ) 2>/dev/null || echo ""`
-            func_to_host_pathlist_result=`echo "$func_to_host_pathlist_tmp2" |\
-              $SED -e "$lt_sed_naive_backslashify"`
-            ;;
-          *cygwin* )
-            func_to_host_pathlist_tmp2=`cygpath -w -p "$func_to_host_pathlist_tmp1"`
-            func_to_host_pathlist_result=`echo "$func_to_host_pathlist_tmp2" |\
-              $SED -e "$lt_sed_naive_backslashify"`
-            ;;
-          * )
-            # unfortunately, winepath doesn't convert pathlists
-            func_to_host_pathlist_result=""
-            func_to_host_pathlist_oldIFS=$IFS
-            IFS=:
-            for func_to_host_pathlist_f in $func_to_host_pathlist_tmp1 ; do
-              IFS=$func_to_host_pathlist_oldIFS
-              if test -n "$func_to_host_pathlist_f" ; then
-                func_to_host_path "$func_to_host_pathlist_f"
-                if test -n "$func_to_host_path_result" ; then
-                  if test -z "$func_to_host_pathlist_result" ; then
-                    func_to_host_pathlist_result="$func_to_host_path_result"
-                  else
-                    func_to_host_pathlist_result="$func_to_host_pathlist_result;$func_to_host_path_result"
-                  fi
-                fi
-              fi
-              IFS=:
-            done
-            IFS=$func_to_host_pathlist_oldIFS
-            ;;
-        esac
-        if test -z "$func_to_host_pathlist_result" ; then
-          func_error "Could not determine the host path(s) corresponding to"
-          func_error "  '$1'"
-          func_error "Continuing, but uninstalled executables may not work."
-          # Fallback. This may break if $1 contains DOS-style drive
-          # specifications. The fix is not to complicate the expression
-          # below, but for the user to provide a working wine installation
-          # with winepath so that path translation in the cross-to-mingw
-          # case works properly.
-          lt_replace_pathsep_nix_to_dos="s|:|;|g"
-          func_to_host_pathlist_result=`echo "$func_to_host_pathlist_tmp1" |\
-            $SED -e "$lt_replace_pathsep_nix_to_dos"`
-        fi
-        # Now, add the leading and trailing path separators back
-        case "$1" in
-          :* ) func_to_host_pathlist_result=";$func_to_host_pathlist_result"
-            ;;
-        esac
-        case "$1" in
-          *: ) func_to_host_pathlist_result="$func_to_host_pathlist_result;"
-            ;;
-        esac
-        ;;
-    esac
-  fi
-}
-# end: func_to_host_pathlist
 
 # func_emit_cwrapperexe_src
 # emit the source code for a wrapper executable on stdout
@@ -3141,31 +4147,23 @@ func_emit_cwrapperexe_src ()
 
    This wrapper executable should never be moved out of the build directory.
    If it is, it will not operate correctly.
-
-   Currently, it simply execs the wrapper *script* "$SHELL $output",
-   but could eventually absorb all of the scripts functionality and
-   exec $objdir/$outputname directly.
 */
 EOF
            cat <<"EOF"
+#ifdef _MSC_VER
+# define _CRT_SECURE_NO_DEPRECATE 1
+#endif
 #include <stdio.h>
 #include <stdlib.h>
 #ifdef _MSC_VER
 # include <direct.h>
 # include <process.h>
 # include <io.h>
-# define setmode _setmode
 #else
 # include <unistd.h>
 # include <stdint.h>
 # ifdef __CYGWIN__
 #  include <io.h>
-#  define HAVE_SETENV
-#  ifdef __STRICT_ANSI__
-char *realpath (const char *, char *);
-int putenv (char *);
-int setenv (const char *, const char *, int);
-#  endif
 # endif
 #endif
 #include <malloc.h>
@@ -3177,6 +4175,44 @@ int setenv (const char *, const char *, int);
 #include <fcntl.h>
 #include <sys/stat.h>
 
+/* declarations of non-ANSI functions */
+#if defined(__MINGW32__)
+# ifdef __STRICT_ANSI__
+int _putenv (const char *);
+# endif
+#elif defined(__CYGWIN__)
+# ifdef __STRICT_ANSI__
+char *realpath (const char *, char *);
+int putenv (char *);
+int setenv (const char *, const char *, int);
+# endif
+/* #elif defined (other platforms) ... */
+#endif
+
+/* portability defines, excluding path handling macros */
+#if defined(_MSC_VER)
+# define setmode _setmode
+# define stat    _stat
+# define chmod   _chmod
+# define getcwd  _getcwd
+# define putenv  _putenv
+# define S_IXUSR _S_IEXEC
+# ifndef _INTPTR_T_DEFINED
+#  define _INTPTR_T_DEFINED
+#  define intptr_t int
+# endif
+#elif defined(__MINGW32__)
+# define setmode _setmode
+# define stat    _stat
+# define chmod   _chmod
+# define getcwd  _getcwd
+# define putenv  _putenv
+#elif defined(__CYGWIN__)
+# define HAVE_SETENV
+# define FOPEN_WB "wb"
+/* #elif defined (other platforms) ... */
+#endif
+
 #if defined(PATH_MAX)
 # define LT_PATHMAX PATH_MAX
 #elif defined(MAXPATHLEN)
@@ -3192,14 +4228,7 @@ int setenv (const char *, const char *, int);
 # define S_IXGRP 0
 #endif
 
-#ifdef _MSC_VER
-# define S_IXUSR _S_IEXEC
-# define stat _stat
-# ifndef _INTPTR_T_DEFINED
-#  define intptr_t int
-# endif
-#endif
-
+/* path handling portability macros */
 #ifndef DIR_SEPARATOR
 # define DIR_SEPARATOR '/'
 # define PATH_SEPARATOR ':'
@@ -3230,10 +4259,6 @@ int setenv (const char *, const char *, int);
 # define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2)
 #endif /* PATH_SEPARATOR_2 */
 
-#ifdef __CYGWIN__
-# define FOPEN_WB "wb"
-#endif
-
 #ifndef FOPEN_WB
 # define FOPEN_WB "w"
 #endif
@@ -3246,22 +4271,13 @@ int setenv (const char *, const char *, int);
   if (stale) { free ((void *) stale); stale = 0; } \
 } while (0)
 
-#undef LTWRAPPER_DEBUGPRINTF
-#if defined DEBUGWRAPPER
-# define LTWRAPPER_DEBUGPRINTF(args) ltwrapper_debugprintf args
-static void
-ltwrapper_debugprintf (const char *fmt, ...)
-{
-    va_list args;
-    va_start (args, fmt);
-    (void) vfprintf (stderr, fmt, args);
-    va_end (args);
-}
+#if defined(LT_DEBUGWRAPPER)
+static int lt_debug = 1;
 #else
-# define LTWRAPPER_DEBUGPRINTF(args)
+static int lt_debug = 0;
 #endif
 
-const char *program_name = NULL;
+const char *program_name = "libtool-wrapper"; /* in case xstrdup fails */
 
 void *xmalloc (size_t num);
 char *xstrdup (const char *string);
@@ -3271,41 +4287,27 @@ char *chase_symlinks (const char *pathspec);
 int make_executable (const char *path);
 int check_executable (const char *path);
 char *strendzap (char *str, const char *pat);
-void lt_fatal (const char *message, ...);
+void lt_debugprintf (const char *file, int line, const char *fmt, ...);
+void lt_fatal (const char *file, int line, const char *message, ...);
+static const char *nonnull (const char *s);
+static const char *nonempty (const char *s);
 void lt_setenv (const char *name, const char *value);
 char *lt_extend_str (const char *orig_value, const char *add, int to_end);
-void lt_opt_process_env_set (const char *arg);
-void lt_opt_process_env_prepend (const char *arg);
-void lt_opt_process_env_append (const char *arg);
-int lt_split_name_value (const char *arg, char** name, char** value);
 void lt_update_exe_path (const char *name, const char *value);
 void lt_update_lib_path (const char *name, const char *value);
-
-static const char *script_text_part1 =
-EOF
-
-           func_emit_wrapper_part1 yes |
-               $SED -e 's/\([\\"]\)/\\\1/g' \
-                    -e 's/^/  "/' -e 's/$/\\n"/'
-           echo ";"
-           cat <<EOF
-
-static const char *script_text_part2 =
+char **prepare_spawn (char **argv);
+void lt_dump_script (FILE *f);
 EOF
-           func_emit_wrapper_part2 yes |
-               $SED -e 's/\([\\"]\)/\\\1/g' \
-                    -e 's/^/  "/' -e 's/$/\\n"/'
-           echo ";"
 
            cat <<EOF
-const char * MAGIC_EXE = "$magic_exe";
+volatile const char * MAGIC_EXE = "$magic_exe";
 const char * LIB_PATH_VARNAME = "$shlibpath_var";
 EOF
 
            if test "$shlibpath_overrides_runpath" = yes && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
-              func_to_host_pathlist "$temp_rpath"
+              func_to_host_path "$temp_rpath"
              cat <<EOF
-const char * LIB_PATH_VALUE   = "$func_to_host_pathlist_result";
+const char * LIB_PATH_VALUE   = "$func_to_host_path_result";
 EOF
            else
              cat <<"EOF"
@@ -3314,10 +4316,10 @@ EOF
            fi
 
            if test -n "$dllsearchpath"; then
-              func_to_host_pathlist "$dllsearchpath:"
+              func_to_host_path "$dllsearchpath:"
              cat <<EOF
 const char * EXE_PATH_VARNAME = "PATH";
-const char * EXE_PATH_VALUE   = "$func_to_host_pathlist_result";
+const char * EXE_PATH_VALUE   = "$func_to_host_path_result";
 EOF
            else
              cat <<"EOF"
@@ -3340,24 +4342,10 @@ EOF
            cat <<"EOF"
 
 #define LTWRAPPER_OPTION_PREFIX         "--lt-"
-#define LTWRAPPER_OPTION_PREFIX_LENGTH  5
 
-static const size_t opt_prefix_len         = LTWRAPPER_OPTION_PREFIX_LENGTH;
 static const char *ltwrapper_option_prefix = LTWRAPPER_OPTION_PREFIX;
-
 static const char *dumpscript_opt       = LTWRAPPER_OPTION_PREFIX "dump-script";
-
-static const size_t env_set_opt_len     = LTWRAPPER_OPTION_PREFIX_LENGTH + 7;
-static const char *env_set_opt          = LTWRAPPER_OPTION_PREFIX "env-set";
-  /* argument is putenv-style "foo=bar", value of foo is set to bar */
-
-static const size_t env_prepend_opt_len = LTWRAPPER_OPTION_PREFIX_LENGTH + 11;
-static const char *env_prepend_opt      = LTWRAPPER_OPTION_PREFIX "env-prepend";
-  /* argument is putenv-style "foo=bar", new value of foo is bar${foo} */
-
-static const size_t env_append_opt_len  = LTWRAPPER_OPTION_PREFIX_LENGTH + 10;
-static const char *env_append_opt       = LTWRAPPER_OPTION_PREFIX "env-append";
-  /* argument is putenv-style "foo=bar", new value of foo is ${foo}bar */
+static const char *debug_opt            = LTWRAPPER_OPTION_PREFIX "debug";
 
 int
 main (int argc, char *argv[])
@@ -3374,10 +4362,13 @@ main (int argc, char *argv[])
   int i;
 
   program_name = (char *) xstrdup (base_name (argv[0]));
-  LTWRAPPER_DEBUGPRINTF (("(main) argv[0]      : %s\n", argv[0]));
-  LTWRAPPER_DEBUGPRINTF (("(main) program_name : %s\n", program_name));
+  newargz = XMALLOC (char *, argc + 1);
 
-  /* very simple arg parsing; don't want to rely on getopt */
+  /* very simple arg parsing; don't want to rely on getopt
+   * also, copy all non cwrapper options to newargz, except
+   * argz[0], which is handled differently
+   */
+  newargc=0;
   for (i = 1; i < argc; i++)
     {
       if (strcmp (argv[i], dumpscript_opt) == 0)
@@ -3391,25 +4382,57 @@ EOF
              esac
 
            cat <<"EOF"
-         printf ("%s", script_text_part1);
-         printf ("%s", script_text_part2);
+         lt_dump_script (stdout);
          return 0;
        }
+      if (strcmp (argv[i], debug_opt) == 0)
+       {
+          lt_debug = 1;
+          continue;
+       }
+      if (strcmp (argv[i], ltwrapper_option_prefix) == 0)
+        {
+          /* however, if there is an option in the LTWRAPPER_OPTION_PREFIX
+             namespace, but it is not one of the ones we know about and
+             have already dealt with, above (inluding dump-script), then
+             report an error. Otherwise, targets might begin to believe
+             they are allowed to use options in the LTWRAPPER_OPTION_PREFIX
+             namespace. The first time any user complains about this, we'll
+             need to make LTWRAPPER_OPTION_PREFIX a configure-time option
+             or a configure.ac-settable value.
+           */
+          lt_fatal (__FILE__, __LINE__,
+                   "unrecognized %s option: '%s'",
+                    ltwrapper_option_prefix, argv[i]);
+        }
+      /* otherwise ... */
+      newargz[++newargc] = xstrdup (argv[i]);
     }
+  newargz[++newargc] = NULL;
+
+EOF
+           cat <<EOF
+  /* The GNU banner must be the first non-error debug message */
+  lt_debugprintf (__FILE__, __LINE__, "libtool wrapper (GNU $PACKAGE$TIMESTAMP) $VERSION\n");
+EOF
+           cat <<"EOF"
+  lt_debugprintf (__FILE__, __LINE__, "(main) argv[0]: %s\n", argv[0]);
+  lt_debugprintf (__FILE__, __LINE__, "(main) program_name: %s\n", program_name);
 
-  newargz = XMALLOC (char *, argc + 1);
   tmp_pathspec = find_executable (argv[0]);
   if (tmp_pathspec == NULL)
-    lt_fatal ("Couldn't find %s", argv[0]);
-  LTWRAPPER_DEBUGPRINTF (("(main) found exe (before symlink chase) at : %s\n",
-                         tmp_pathspec));
+    lt_fatal (__FILE__, __LINE__, "couldn't find %s", argv[0]);
+  lt_debugprintf (__FILE__, __LINE__,
+                  "(main) found exe (before symlink chase) at: %s\n",
+                 tmp_pathspec);
 
   actual_cwrapper_path = chase_symlinks (tmp_pathspec);
-  LTWRAPPER_DEBUGPRINTF (("(main) found exe (after symlink chase) at : %s\n",
-                         actual_cwrapper_path));
+  lt_debugprintf (__FILE__, __LINE__,
+                  "(main) found exe (after symlink chase) at: %s\n",
+                 actual_cwrapper_path);
   XFREE (tmp_pathspec);
 
-  actual_cwrapper_name = xstrdupbase_name (actual_cwrapper_path));
+  actual_cwrapper_name = xstrdup (base_name (actual_cwrapper_path));
   strendzap (actual_cwrapper_path, actual_cwrapper_name);
 
   /* wrapper name transforms */
@@ -3427,8 +4450,9 @@ EOF
   target_name = tmp_pathspec;
   tmp_pathspec = 0;
 
-  LTWRAPPER_DEBUGPRINTF (("(main) libtool target name: %s\n",
-                         target_name));
+  lt_debugprintf (__FILE__, __LINE__,
+                 "(main) libtool target name: %s\n",
+                 target_name);
 EOF
 
            cat <<EOF
@@ -3478,80 +4502,19 @@ EOF
 
   lt_setenv ("BIN_SH", "xpg4"); /* for Tru64 */
   lt_setenv ("DUALCASE", "1");  /* for MSK sh */
-  lt_update_lib_path (LIB_PATH_VARNAME, LIB_PATH_VALUE);
+  /* Update the DLL searchpath.  EXE_PATH_VALUE ($dllsearchpath) must
+     be prepended before (that is, appear after) LIB_PATH_VALUE ($temp_rpath)
+     because on Windows, both *_VARNAMEs are PATH but uninstalled
+     libraries must come first. */
   lt_update_exe_path (EXE_PATH_VARNAME, EXE_PATH_VALUE);
+  lt_update_lib_path (LIB_PATH_VARNAME, LIB_PATH_VALUE);
 
-  newargc=0;
-  for (i = 1; i < argc; i++)
-    {
-      if (strncmp (argv[i], env_set_opt, env_set_opt_len) == 0)
-        {
-          if (argv[i][env_set_opt_len] == '=')
-            {
-              const char *p = argv[i] + env_set_opt_len + 1;
-              lt_opt_process_env_set (p);
-            }
-          else if (argv[i][env_set_opt_len] == '\0' && i + 1 < argc)
-            {
-              lt_opt_process_env_set (argv[++i]); /* don't copy */
-            }
-          else
-            lt_fatal ("%s missing required argument", env_set_opt);
-          continue;
-        }
-      if (strncmp (argv[i], env_prepend_opt, env_prepend_opt_len) == 0)
-        {
-          if (argv[i][env_prepend_opt_len] == '=')
-            {
-              const char *p = argv[i] + env_prepend_opt_len + 1;
-              lt_opt_process_env_prepend (p);
-            }
-          else if (argv[i][env_prepend_opt_len] == '\0' && i + 1 < argc)
-            {
-              lt_opt_process_env_prepend (argv[++i]); /* don't copy */
-            }
-          else
-            lt_fatal ("%s missing required argument", env_prepend_opt);
-          continue;
-        }
-      if (strncmp (argv[i], env_append_opt, env_append_opt_len) == 0)
-        {
-          if (argv[i][env_append_opt_len] == '=')
-            {
-              const char *p = argv[i] + env_append_opt_len + 1;
-              lt_opt_process_env_append (p);
-            }
-          else if (argv[i][env_append_opt_len] == '\0' && i + 1 < argc)
-            {
-              lt_opt_process_env_append (argv[++i]); /* don't copy */
-            }
-          else
-            lt_fatal ("%s missing required argument", env_append_opt);
-          continue;
-        }
-      if (strncmp (argv[i], ltwrapper_option_prefix, opt_prefix_len) == 0)
-        {
-          /* however, if there is an option in the LTWRAPPER_OPTION_PREFIX
-             namespace, but it is not one of the ones we know about and
-             have already dealt with, above (inluding dump-script), then
-             report an error. Otherwise, targets might begin to believe
-             they are allowed to use options in the LTWRAPPER_OPTION_PREFIX
-             namespace. The first time any user complains about this, we'll
-             need to make LTWRAPPER_OPTION_PREFIX a configure-time option
-             or a configure.ac-settable value.
-           */
-          lt_fatal ("Unrecognized option in %s namespace: '%s'",
-                    ltwrapper_option_prefix, argv[i]);
-        }
-      /* otherwise ... */
-      newargz[++newargc] = xstrdup (argv[i]);
-    }
-  newargz[++newargc] = NULL;
-
-  LTWRAPPER_DEBUGPRINTF     (("(main) lt_argv_zero : %s\n", (lt_argv_zero ? lt_argv_zero : "<NULL>")));
+  lt_debugprintf (__FILE__, __LINE__, "(main) lt_argv_zero: %s\n",
+                 nonnull (lt_argv_zero));
   for (i = 0; i < newargc; i++)
     {
-      LTWRAPPER_DEBUGPRINTF (("(main) newargz[%d]   : %s\n", i, (newargz[i] ? newargz[i] : "<NULL>")));
+      lt_debugprintf (__FILE__, __LINE__, "(main) newargz[%d]: %s\n",
+                     i, nonnull (newargz[i]));
     }
 
 EOF
@@ -3560,11 +4523,14 @@ EOF
              mingw*)
                cat <<"EOF"
   /* execv doesn't actually work on mingw as expected on unix */
+  newargz = prepare_spawn (newargz);
   rval = _spawnv (_P_WAIT, lt_argv_zero, (const char * const *) newargz);
   if (rval == -1)
     {
       /* failed to start process */
-      LTWRAPPER_DEBUGPRINTF (("(main) failed to launch target \"%s\": errno = %d\n", lt_argv_zero, errno));
+      lt_debugprintf (__FILE__, __LINE__,
+                     "(main) failed to launch target \"%s\": %s\n",
+                     lt_argv_zero, nonnull (strerror (errno)));
       return 127;
     }
   return rval;
@@ -3586,7 +4552,7 @@ xmalloc (size_t num)
 {
   void *p = (void *) malloc (num);
   if (!p)
-    lt_fatal ("Memory exhausted");
+    lt_fatal (__FILE__, __LINE__, "memory exhausted");
 
   return p;
 }
@@ -3620,8 +4586,8 @@ check_executable (const char *path)
 {
   struct stat st;
 
-  LTWRAPPER_DEBUGPRINTF (("(check_executable)  : %s\n",
-                         path ? (*path ? path : "EMPTY!") : "NULL!"));
+  lt_debugprintf (__FILE__, __LINE__, "(check_executable): %s\n",
+                  nonempty (path));
   if ((!path) || (!*path))
     return 0;
 
@@ -3638,8 +4604,8 @@ make_executable (const char *path)
   int rval = 0;
   struct stat st;
 
-  LTWRAPPER_DEBUGPRINTF (("(make_executable)   : %s\n",
-                         path ? (*path ? path : "EMPTY!") : "NULL!"));
+  lt_debugprintf (__FILE__, __LINE__, "(make_executable): %s\n",
+                  nonempty (path));
   if ((!path) || (!*path))
     return 0;
 
@@ -3665,8 +4631,8 @@ find_executable (const char *wrapper)
   int tmp_len;
   char *concat_name;
 
-  LTWRAPPER_DEBUGPRINTF (("(find_executable)   : %s\n",
-                         wrapper ? (*wrapper ? wrapper : "EMPTY!") : "NULL!"));
+  lt_debugprintf (__FILE__, __LINE__, "(find_executable): %s\n",
+                  nonempty (wrapper));
 
   if ((wrapper == NULL) || (*wrapper == '\0'))
     return NULL;
@@ -3719,7 +4685,8 @@ find_executable (const char *wrapper)
                {
                  /* empty path: current directory */
                  if (getcwd (tmp, LT_PATHMAX) == NULL)
-                   lt_fatal ("getcwd failed");
+                   lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
+                              nonnull (strerror (errno)));
                  tmp_len = strlen (tmp);
                  concat_name =
                    XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
@@ -3744,7 +4711,8 @@ find_executable (const char *wrapper)
     }
   /* Relative path | not found in path: prepend cwd */
   if (getcwd (tmp, LT_PATHMAX) == NULL)
-    lt_fatal ("getcwd failed");
+    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
+              nonnull (strerror (errno)));
   tmp_len = strlen (tmp);
   concat_name = XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
   memcpy (concat_name, tmp, tmp_len);
@@ -3770,8 +4738,9 @@ chase_symlinks (const char *pathspec)
   int has_symlinks = 0;
   while (strlen (tmp_pathspec) && !has_symlinks)
     {
-      LTWRAPPER_DEBUGPRINTF (("checking path component for symlinks: %s\n",
-                             tmp_pathspec));
+      lt_debugprintf (__FILE__, __LINE__,
+                     "checking path component for symlinks: %s\n",
+                     tmp_pathspec);
       if (lstat (tmp_pathspec, &s) == 0)
        {
          if (S_ISLNK (s.st_mode) != 0)
@@ -3793,8 +4762,9 @@ chase_symlinks (const char *pathspec)
        }
       else
        {
-         char *errstr = strerror (errno);
-         lt_fatal ("Error accessing file %s (%s)", tmp_pathspec, errstr);
+         lt_fatal (__FILE__, __LINE__,
+                   "error accessing file \"%s\": %s",
+                   tmp_pathspec, nonnull (strerror (errno)));
        }
     }
   XFREE (tmp_pathspec);
@@ -3807,7 +4777,8 @@ chase_symlinks (const char *pathspec)
   tmp_pathspec = realpath (pathspec, buf);
   if (tmp_pathspec == 0)
     {
-      lt_fatal ("Could not follow symlinks for %s", pathspec);
+      lt_fatal (__FILE__, __LINE__,
+               "could not follow symlinks for %s", pathspec);
     }
   return xstrdup (tmp_pathspec);
 #endif
@@ -3833,11 +4804,25 @@ strendzap (char *str, const char *pat)
   return str;
 }
 
+void
+lt_debugprintf (const char *file, int line, const char *fmt, ...)
+{
+  va_list args;
+  if (lt_debug)
+    {
+      (void) fprintf (stderr, "%s:%s:%d: ", program_name, file, line);
+      va_start (args, fmt);
+      (void) vfprintf (stderr, fmt, args);
+      va_end (args);
+    }
+}
+
 static void
-lt_error_core (int exit_status, const char *mode,
+lt_error_core (int exit_status, const char *file,
+              int line, const char *mode,
               const char *message, va_list ap)
 {
-  fprintf (stderr, "%s: %s: ", program_name, mode);
+  fprintf (stderr, "%s:%s:%d: %s: ", program_name, file, line, mode);
   vfprintf (stderr, message, ap);
   fprintf (stderr, ".\n");
 
@@ -3846,20 +4831,32 @@ lt_error_core (int exit_status, const char *mode,
 }
 
 void
-lt_fatal (const char *message, ...)
+lt_fatal (const char *file, int line, const char *message, ...)
 {
   va_list ap;
   va_start (ap, message);
-  lt_error_core (EXIT_FAILURE, "FATAL", message, ap);
+  lt_error_core (EXIT_FAILURE, file, line, "FATAL", message, ap);
   va_end (ap);
 }
 
+static const char *
+nonnull (const char *s)
+{
+  return s ? s : "(null)";
+}
+
+static const char *
+nonempty (const char *s)
+{
+  return (s && !*s) ? "(empty)" : nonnull (s);
+}
+
 void
 lt_setenv (const char *name, const char *value)
 {
-  LTWRAPPER_DEBUGPRINTF (("(lt_setenv) setting '%s' to '%s'\n",
-                          (name ? name : "<NULL>"),
-                          (value ? value : "<NULL>")));
+  lt_debugprintf (__FILE__, __LINE__,
+                 "(lt_setenv) setting '%s' to '%s'\n",
+                  nonnull (name), nonnull (value));
   {
 #ifdef HAVE_SETENV
     /* always make a copy, for consistency with !HAVE_SETENV */
@@ -3904,95 +4901,12 @@ lt_extend_str (const char *orig_value, const char *add, int to_end)
   return new_value;
 }
 
-int
-lt_split_name_value (const char *arg, char** name, char** value)
-{
-  const char *p;
-  int len;
-  if (!arg || !*arg)
-    return 1;
-
-  p = strchr (arg, (int)'=');
-
-  if (!p)
-    return 1;
-
-  *value = xstrdup (++p);
-
-  len = strlen (arg) - strlen (*value);
-  *name = XMALLOC (char, len);
-  strncpy (*name, arg, len-1);
-  (*name)[len - 1] = '\0';
-
-  return 0;
-}
-
-void
-lt_opt_process_env_set (const char *arg)
-{
-  char *name = NULL;
-  char *value = NULL;
-
-  if (lt_split_name_value (arg, &name, &value) != 0)
-    {
-      XFREE (name);
-      XFREE (value);
-      lt_fatal ("bad argument for %s: '%s'", env_set_opt, arg);
-    }
-
-  lt_setenv (name, value);
-  XFREE (name);
-  XFREE (value);
-}
-
-void
-lt_opt_process_env_prepend (const char *arg)
-{
-  char *name = NULL;
-  char *value = NULL;
-  char *new_value = NULL;
-
-  if (lt_split_name_value (arg, &name, &value) != 0)
-    {
-      XFREE (name);
-      XFREE (value);
-      lt_fatal ("bad argument for %s: '%s'", env_prepend_opt, arg);
-    }
-
-  new_value = lt_extend_str (getenv (name), value, 0);
-  lt_setenv (name, new_value);
-  XFREE (new_value);
-  XFREE (name);
-  XFREE (value);
-}
-
-void
-lt_opt_process_env_append (const char *arg)
-{
-  char *name = NULL;
-  char *value = NULL;
-  char *new_value = NULL;
-
-  if (lt_split_name_value (arg, &name, &value) != 0)
-    {
-      XFREE (name);
-      XFREE (value);
-      lt_fatal ("bad argument for %s: '%s'", env_append_opt, arg);
-    }
-
-  new_value = lt_extend_str (getenv (name), value, 1);
-  lt_setenv (name, new_value);
-  XFREE (new_value);
-  XFREE (name);
-  XFREE (value);
-}
-
 void
 lt_update_exe_path (const char *name, const char *value)
 {
-  LTWRAPPER_DEBUGPRINTF (("(lt_update_exe_path) modifying '%s' by prepending '%s'\n",
-                          (name ? name : "<NULL>"),
-                          (value ? value : "<NULL>")));
+  lt_debugprintf (__FILE__, __LINE__,
+                 "(lt_update_exe_path) modifying '%s' by prepending '%s'\n",
+                  nonnull (name), nonnull (value));
 
   if (name && *name && value && *value)
     {
@@ -4011,9 +4925,9 @@ lt_update_exe_path (const char *name, const char *value)
 void
 lt_update_lib_path (const char *name, const char *value)
 {
-  LTWRAPPER_DEBUGPRINTF (("(lt_update_lib_path) modifying '%s' by prepending '%s'\n",
-                          (name ? name : "<NULL>"),
-                          (value ? value : "<NULL>")));
+  lt_debugprintf (__FILE__, __LINE__,
+                 "(lt_update_lib_path) modifying '%s' by prepending '%s'\n",
+                  nonnull (name), nonnull (value));
 
   if (name && *name && value && *value)
     {
@@ -4023,11 +4937,158 @@ lt_update_lib_path (const char *name, const char *value)
     }
 }
 
+EOF
+           case $host_os in
+             mingw*)
+               cat <<"EOF"
+
+/* Prepares an argument vector before calling spawn().
+   Note that spawn() does not by itself call the command interpreter
+     (getenv ("COMSPEC") != NULL ? getenv ("COMSPEC") :
+      ({ OSVERSIONINFO v; v.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+         GetVersionEx(&v);
+         v.dwPlatformId == VER_PLATFORM_WIN32_NT;
+      }) ? "cmd.exe" : "command.com").
+   Instead it simply concatenates the arguments, separated by ' ', and calls
+   CreateProcess().  We must quote the arguments since Win32 CreateProcess()
+   interprets characters like ' ', '\t', '\\', '"' (but not '<' and '>') in a
+   special way:
+   - Space and tab are interpreted as delimiters. They are not treated as
+     delimiters if they are surrounded by double quotes: "...".
+   - Unescaped double quotes are removed from the input. Their only effect is
+     that within double quotes, space and tab are treated like normal
+     characters.
+   - Backslashes not followed by double quotes are not special.
+   - But 2*n+1 backslashes followed by a double quote become
+     n backslashes followed by a double quote (n >= 0):
+       \" -> "
+       \\\" -> \"
+       \\\\\" -> \\"
+ */
+#define SHELL_SPECIAL_CHARS "\"\\ \001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037"
+#define SHELL_SPACE_CHARS " \001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037"
+char **
+prepare_spawn (char **argv)
+{
+  size_t argc;
+  char **new_argv;
+  size_t i;
+
+  /* Count number of arguments.  */
+  for (argc = 0; argv[argc] != NULL; argc++)
+    ;
+
+  /* Allocate new argument vector.  */
+  new_argv = XMALLOC (char *, argc + 1);
+
+  /* Put quoted arguments into the new argument vector.  */
+  for (i = 0; i < argc; i++)
+    {
+      const char *string = argv[i];
+
+      if (string[0] == '\0')
+       new_argv[i] = xstrdup ("\"\"");
+      else if (strpbrk (string, SHELL_SPECIAL_CHARS) != NULL)
+       {
+         int quote_around = (strpbrk (string, SHELL_SPACE_CHARS) != NULL);
+         size_t length;
+         unsigned int backslashes;
+         const char *s;
+         char *quoted_string;
+         char *p;
+
+         length = 0;
+         backslashes = 0;
+         if (quote_around)
+           length++;
+         for (s = string; *s != '\0'; s++)
+           {
+             char c = *s;
+             if (c == '"')
+               length += backslashes + 1;
+             length++;
+             if (c == '\\')
+               backslashes++;
+             else
+               backslashes = 0;
+           }
+         if (quote_around)
+           length += backslashes + 1;
+
+         quoted_string = XMALLOC (char, length + 1);
+
+         p = quoted_string;
+         backslashes = 0;
+         if (quote_around)
+           *p++ = '"';
+         for (s = string; *s != '\0'; s++)
+           {
+             char c = *s;
+             if (c == '"')
+               {
+                 unsigned int j;
+                 for (j = backslashes + 1; j > 0; j--)
+                   *p++ = '\\';
+               }
+             *p++ = c;
+             if (c == '\\')
+               backslashes++;
+             else
+               backslashes = 0;
+           }
+         if (quote_around)
+           {
+             unsigned int j;
+             for (j = backslashes; j > 0; j--)
+               *p++ = '\\';
+             *p++ = '"';
+           }
+         *p = '\0';
+
+         new_argv[i] = quoted_string;
+       }
+      else
+       new_argv[i] = (char *) string;
+    }
+  new_argv[argc] = NULL;
+
+  return new_argv;
+}
+EOF
+               ;;
+           esac
 
+            cat <<"EOF"
+void lt_dump_script (FILE* f)
+{
+EOF
+           func_emit_wrapper yes |
+             $SED -n -e '
+s/^\(.\{79\}\)\(..*\)/\1\
+\2/
+h
+s/\([\\"]\)/\\\1/g
+s/$/\\n/
+s/\([^\n]*\).*/  fputs ("\1", f);/p
+g
+D'
+            cat <<"EOF"
+}
 EOF
 }
 # end: func_emit_cwrapperexe_src
 
+# func_win32_import_lib_p ARG
+# True if ARG is an import lib, as indicated by $file_magic_cmd
+func_win32_import_lib_p ()
+{
+    $opt_debug
+    case `eval $file_magic_cmd \"\$1\" 2>/dev/null | $SED -e 10q` in
+    *import*) : ;;
+    *) false ;;
+    esac
+}
+
 # func_mode_link arg...
 func_mode_link ()
 {
@@ -4072,6 +5133,7 @@ func_mode_link ()
     new_inherited_linker_flags=
 
     avoid_version=no
+    bindir=
     dlfiles=
     dlprefiles=
     dlself=no
@@ -4164,6 +5226,11 @@ func_mode_link ()
        esac
 
        case $prev in
+       bindir)
+         bindir="$arg"
+         prev=
+         continue
+         ;;
        dlfiles|dlprefiles)
          if test "$preload" = no; then
            # Add the symbol object into the linking commands.
@@ -4195,9 +5262,9 @@ func_mode_link ()
            ;;
          *)
            if test "$prev" = dlfiles; then
-             dlfiles="$dlfiles $arg"
+             func_append dlfiles " $arg"
            else
-             dlprefiles="$dlprefiles $arg"
+             func_append dlprefiles " $arg"
            fi
            prev=
            continue
@@ -4221,7 +5288,7 @@ func_mode_link ()
            *-*-darwin*)
              case "$deplibs " in
                *" $qarg.ltframework "*) ;;
-               *) deplibs="$deplibs $qarg.ltframework" # this is fixed later
+               *) func_append deplibs " $qarg.ltframework" # this is fixed later
                   ;;
              esac
              ;;
@@ -4240,7 +5307,7 @@ func_mode_link ()
            moreargs=
            for fil in `cat "$save_arg"`
            do
-#            moreargs="$moreargs $fil"
+#            func_append moreargs " $fil"
              arg=$fil
              # A libtool-controlled object.
 
@@ -4269,7 +5336,7 @@ func_mode_link ()
 
                  if test "$prev" = dlfiles; then
                    if test "$build_libtool_libs" = yes && test "$dlopen_support" = yes; then
-                     dlfiles="$dlfiles $pic_object"
+                     func_append dlfiles " $pic_object"
                      prev=
                      continue
                    else
@@ -4281,7 +5348,7 @@ func_mode_link ()
                  # CHECK ME:  I think I busted this.  -Ossama
                  if test "$prev" = dlprefiles; then
                    # Preload the old-style object.
-                   dlprefiles="$dlprefiles $pic_object"
+                   func_append dlprefiles " $pic_object"
                    prev=
                  fi
 
@@ -4351,12 +5418,12 @@ func_mode_link ()
          if test "$prev" = rpath; then
            case "$rpath " in
            *" $arg "*) ;;
-           *) rpath="$rpath $arg" ;;
+           *) func_append rpath " $arg" ;;
            esac
          else
            case "$xrpath " in
            *" $arg "*) ;;
-           *) xrpath="$xrpath $arg" ;;
+           *) func_append xrpath " $arg" ;;
            esac
          fi
          prev=
@@ -4368,28 +5435,28 @@ func_mode_link ()
          continue
          ;;
        weak)
-         weak_libs="$weak_libs $arg"
+         func_append weak_libs " $arg"
          prev=
          continue
          ;;
        xcclinker)
-         linker_flags="$linker_flags $qarg"
-         compiler_flags="$compiler_flags $qarg"
+         func_append linker_flags " $qarg"
+         func_append compiler_flags " $qarg"
          prev=
          func_append compile_command " $qarg"
          func_append finalize_command " $qarg"
          continue
          ;;
        xcompiler)
-         compiler_flags="$compiler_flags $qarg"
+         func_append compiler_flags " $qarg"
          prev=
          func_append compile_command " $qarg"
          func_append finalize_command " $qarg"
          continue
          ;;
        xlinker)
-         linker_flags="$linker_flags $qarg"
-         compiler_flags="$compiler_flags $wl$qarg"
+         func_append linker_flags " $qarg"
+         func_append compiler_flags " $wl$qarg"
          prev=
          func_append compile_command " $wl$qarg"
          func_append finalize_command " $wl$qarg"
@@ -4425,6 +5492,11 @@ func_mode_link ()
        continue
        ;;
 
+      -bindir)
+       prev=bindir
+       continue
+       ;;
+
       -dlopen)
        prev=dlfiles
        continue
@@ -4475,15 +5547,16 @@ func_mode_link ()
        ;;
 
       -L*)
-       func_stripname '-L' '' "$arg"
-       dir=$func_stripname_result
-       if test -z "$dir"; then
+       func_stripname "-L" '' "$arg"
+       if test -z "$func_stripname_result"; then
          if test "$#" -gt 0; then
            func_fatal_error "require no space between \`-L' and \`$1'"
          else
            func_fatal_error "need path for \`-L' option"
          fi
        fi
+       func_resolve_sysroot "$func_stripname_result"
+       dir=$func_resolve_sysroot_result
        # We need an absolute path.
        case $dir in
        [\\/]* | [A-Za-z]:[\\/]*) ;;
@@ -4495,24 +5568,30 @@ func_mode_link ()
          ;;
        esac
        case "$deplibs " in
-       *" -L$dir "*) ;;
+       *" -L$dir "* | *" $arg "*)
+         # Will only happen for absolute or sysroot arguments
+         ;;
        *)
-         deplibs="$deplibs -L$dir"
-         lib_search_path="$lib_search_path $dir"
+         # Preserve sysroot, but never include relative directories
+         case $dir in
+           [\\/]* | [A-Za-z]:[\\/]* | =*) func_append deplibs " $arg" ;;
+           *) func_append deplibs " -L$dir" ;;
+         esac
+         func_append lib_search_path " $dir"
          ;;
        esac
        case $host in
        *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
-         testbindir=`$ECHO "X$dir" | $Xsed -e 's*/lib$*/bin*'`
+         testbindir=`$ECHO "$dir" | $SED 's*/lib$*/bin*'`
          case :$dllsearchpath: in
          *":$dir:"*) ;;
          ::) dllsearchpath=$dir;;
-         *) dllsearchpath="$dllsearchpath:$dir";;
+         *) func_append dllsearchpath ":$dir";;
          esac
          case :$dllsearchpath: in
          *":$testbindir:"*) ;;
          ::) dllsearchpath=$testbindir;;
-         *) dllsearchpath="$dllsearchpath:$testbindir";;
+         *) func_append dllsearchpath ":$testbindir";;
          esac
          ;;
        esac
@@ -4522,7 +5601,7 @@ func_mode_link ()
       -l*)
        if test "X$arg" = "X-lc" || test "X$arg" = "X-lm"; then
          case $host in
-         *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos* | *-cegcc*)
+         *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos* | *-cegcc* | *-*-haiku*)
            # These systems don't actually have a C or math library (as such)
            continue
            ;;
@@ -4536,7 +5615,7 @@ func_mode_link ()
            ;;
          *-*-rhapsody* | *-*-darwin1.[012])
            # Rhapsody C and math libraries are in the System framework
-           deplibs="$deplibs System.ltframework"
+           func_append deplibs " System.ltframework"
            continue
            ;;
          *-*-sco3.2v5* | *-*-sco5v6*)
@@ -4556,7 +5635,7 @@ func_mode_link ()
           ;;
         esac
        fi
-       deplibs="$deplibs $arg"
+       func_append deplibs " $arg"
        continue
        ;;
 
@@ -4568,21 +5647,22 @@ func_mode_link ()
       # Tru64 UNIX uses -model [arg] to determine the layout of C++
       # classes, name mangling, and exception handling.
       # Darwin uses the -arch flag to determine output architecture.
-      -model|-arch|-isysroot)
-       compiler_flags="$compiler_flags $arg"
+      -model|-arch|-isysroot|--sysroot)
+       func_append compiler_flags " $arg"
        func_append compile_command " $arg"
        func_append finalize_command " $arg"
        prev=xcompiler
        continue
        ;;
 
-      -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe|-threads)
-       compiler_flags="$compiler_flags $arg"
+      -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \
+      |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
+       func_append compiler_flags " $arg"
        func_append compile_command " $arg"
        func_append finalize_command " $arg"
        case "$new_inherited_linker_flags " in
            *" $arg "*) ;;
-           * ) new_inherited_linker_flags="$new_inherited_linker_flags $arg" ;;
+           * ) func_append new_inherited_linker_flags " $arg" ;;
        esac
        continue
        ;;
@@ -4649,13 +5729,17 @@ func_mode_link ()
        # We need an absolute path.
        case $dir in
        [\\/]* | [A-Za-z]:[\\/]*) ;;
+       =*)
+         func_stripname '=' '' "$dir"
+         dir=$lt_sysroot$func_stripname_result
+         ;;
        *)
          func_fatal_error "only absolute run-paths are allowed"
          ;;
        esac
        case "$xrpath " in
        *" $dir "*) ;;
-       *) xrpath="$xrpath $dir" ;;
+       *) func_append xrpath " $dir" ;;
        esac
        continue
        ;;
@@ -4708,8 +5792,8 @@ func_mode_link ()
        for flag in $args; do
          IFS="$save_ifs"
           func_quote_for_eval "$flag"
-         arg="$arg $wl$func_quote_for_eval_result"
-         compiler_flags="$compiler_flags $func_quote_for_eval_result"
+         func_append arg " $func_quote_for_eval_result"
+         func_append compiler_flags " $func_quote_for_eval_result"
        done
        IFS="$save_ifs"
        func_stripname ' ' '' "$arg"
@@ -4724,9 +5808,9 @@ func_mode_link ()
        for flag in $args; do
          IFS="$save_ifs"
           func_quote_for_eval "$flag"
-         arg="$arg $wl$func_quote_for_eval_result"
-         compiler_flags="$compiler_flags $wl$func_quote_for_eval_result"
-         linker_flags="$linker_flags $func_quote_for_eval_result"
+         func_append arg " $wl$func_quote_for_eval_result"
+         func_append compiler_flags " $wl$func_quote_for_eval_result"
+         func_append linker_flags " $func_quote_for_eval_result"
        done
        IFS="$save_ifs"
        func_stripname ' ' '' "$arg"
@@ -4754,23 +5838,27 @@ func_mode_link ()
        arg="$func_quote_for_eval_result"
        ;;
 
-      # -64, -mips[0-9] enable 64-bit mode on the SGI compiler
-      # -r[0-9][0-9]* specifies the processor on the SGI compiler
-      # -xarch=*, -xtarget=* enable 64-bit mode on the Sun compiler
-      # +DA*, +DD* enable 64-bit mode on the HP compiler
-      # -q* pass through compiler args for the IBM compiler
-      # -m*, -t[45]*, -txscale* pass through architecture-specific
-      # compiler args for GCC
-      # -F/path gives path to uninstalled frameworks, gcc on darwin
-      # -p, -pg, --coverage, -fprofile-* pass through profiling flag for GCC
-      # @file GCC response files
+      # Flags to be passed through unchanged, with rationale:
+      # -64, -mips[0-9]      enable 64-bit mode for the SGI compiler
+      # -r[0-9][0-9]*        specify processor for the SGI compiler
+      # -xarch=*, -xtarget=* enable 64-bit mode for the Sun compiler
+      # +DA*, +DD*           enable 64-bit mode for the HP compiler
+      # -q*                  compiler args for the IBM compiler
+      # -m*, -t[45]*, -txscale* architecture-specific flags for GCC
+      # -F/path              path to uninstalled frameworks, gcc on darwin
+      # -p, -pg, --coverage, -fprofile-*  profiling flags for GCC
+      # @file                GCC response files
+      # -tp=*                Portland pgcc target processor selection
+      # --sysroot=*          for sysroot support
+      # -O*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization
       -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
-      -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*)
+      -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \
+      -O*|-flto*|-fwhopr*|-fuse-linker-plugin)
         func_quote_for_eval "$arg"
        arg="$func_quote_for_eval_result"
         func_append compile_command " $arg"
         func_append finalize_command " $arg"
-        compiler_flags="$compiler_flags $arg"
+        func_append compiler_flags " $arg"
         continue
         ;;
 
@@ -4782,7 +5870,7 @@ func_mode_link ()
 
       *.$objext)
        # A standard object.
-       objs="$objs $arg"
+       func_append objs " $arg"
        ;;
 
       *.lo)
@@ -4813,7 +5901,7 @@ func_mode_link ()
 
            if test "$prev" = dlfiles; then
              if test "$build_libtool_libs" = yes && test "$dlopen_support" = yes; then
-               dlfiles="$dlfiles $pic_object"
+               func_append dlfiles " $pic_object"
                prev=
                continue
              else
@@ -4825,7 +5913,7 @@ func_mode_link ()
            # CHECK ME:  I think I busted this.  -Ossama
            if test "$prev" = dlprefiles; then
              # Preload the old-style object.
-             dlprefiles="$dlprefiles $pic_object"
+             func_append dlprefiles " $pic_object"
              prev=
            fi
 
@@ -4870,24 +5958,25 @@ func_mode_link ()
 
       *.$libext)
        # An archive.
-       deplibs="$deplibs $arg"
-       old_deplibs="$old_deplibs $arg"
+       func_append deplibs " $arg"
+       func_append old_deplibs " $arg"
        continue
        ;;
 
       *.la)
        # A libtool-controlled library.
 
+       func_resolve_sysroot "$arg"
        if test "$prev" = dlfiles; then
          # This library was specified with -dlopen.
-         dlfiles="$dlfiles $arg"
+         func_append dlfiles " $func_resolve_sysroot_result"
          prev=
        elif test "$prev" = dlprefiles; then
          # The library was specified with -dlpreopen.
-         dlprefiles="$dlprefiles $arg"
+         func_append dlprefiles " $func_resolve_sysroot_result"
          prev=
        else
-         deplibs="$deplibs $arg"
+         func_append deplibs " $func_resolve_sysroot_result"
        fi
        continue
        ;;
@@ -4925,7 +6014,7 @@ func_mode_link ()
 
     if test -n "$shlibpath_var"; then
       # get the directories listed in $shlibpath_var
-      eval shlib_search_path=\`\$ECHO \"X\${$shlibpath_var}\" \| \$Xsed -e \'s/:/ /g\'\`
+      eval shlib_search_path=\`\$ECHO \"\${$shlibpath_var}\" \| \$SED \'s/:/ /g\'\`
     else
       shlib_search_path=
     fi
@@ -4934,6 +6023,8 @@ func_mode_link ()
 
     func_dirname "$output" "/" ""
     output_objdir="$func_dirname_result$objdir"
+    func_to_tool_file "$output_objdir/"
+    tool_output_objdir=$func_to_tool_file_result
     # Create the object directory.
     func_mkdir_p "$output_objdir"
 
@@ -4954,12 +6045,12 @@ func_mode_link ()
     # Find all interdependent deplibs by searching for libraries
     # that are linked more than once (e.g. -la -lb -la)
     for deplib in $deplibs; do
-      if $opt_duplicate_deps ; then
+      if $opt_preserve_dup_deps ; then
        case "$libs " in
-       *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;;
+       *" $deplib "*) func_append specialdeplibs " $deplib" ;;
        esac
       fi
-      libs="$libs $deplib"
+      func_append libs " $deplib"
     done
 
     if test "$linkmode" = lib; then
@@ -4972,9 +6063,9 @@ func_mode_link ()
       if $opt_duplicate_compiler_generated_deps; then
        for pre_post_dep in $predeps $postdeps; do
          case "$pre_post_deps " in
-         *" $pre_post_dep "*) specialdeplibs="$specialdeplibs $pre_post_deps" ;;
+         *" $pre_post_dep "*) func_append specialdeplibs " $pre_post_deps" ;;
          esac
-         pre_post_deps="$pre_post_deps $pre_post_dep"
+         func_append pre_post_deps " $pre_post_dep"
        done
       fi
       pre_post_deps=
@@ -5044,17 +6135,19 @@ func_mode_link ()
        for lib in $dlprefiles; do
          # Ignore non-libtool-libs
          dependency_libs=
+         func_resolve_sysroot "$lib"
          case $lib in
-         *.la) func_source "$lib" ;;
+         *.la) func_source "$func_resolve_sysroot_result" ;;
          esac
 
          # Collect preopened libtool deplibs, except any this library
          # has declared as weak libs
          for deplib in $dependency_libs; do
-            deplib_base=`$ECHO "X$deplib" | $Xsed -e "$basename"`
+           func_basename "$deplib"
+            deplib_base=$func_basename_result
            case " $weak_libs " in
            *" $deplib_base "*) ;;
-           *) deplibs="$deplibs $deplib" ;;
+           *) func_append deplibs " $deplib" ;;
            esac
          done
        done
@@ -5070,16 +6163,17 @@ func_mode_link ()
        lib=
        found=no
        case $deplib in
-       -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe|-threads)
+       -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \
+        |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
          if test "$linkmode,$pass" = "prog,link"; then
            compile_deplibs="$deplib $compile_deplibs"
            finalize_deplibs="$deplib $finalize_deplibs"
          else
-           compiler_flags="$compiler_flags $deplib"
+           func_append compiler_flags " $deplib"
            if test "$linkmode" = lib ; then
                case "$new_inherited_linker_flags " in
                    *" $deplib "*) ;;
-                   * ) new_inherited_linker_flags="$new_inherited_linker_flags $deplib" ;;
+                   * ) func_append new_inherited_linker_flags " $deplib" ;;
                esac
            fi
          fi
@@ -5164,7 +6258,7 @@ func_mode_link ()
            if test "$linkmode" = lib ; then
                case "$new_inherited_linker_flags " in
                    *" $deplib "*) ;;
-                   * ) new_inherited_linker_flags="$new_inherited_linker_flags $deplib" ;;
+                   * ) func_append new_inherited_linker_flags " $deplib" ;;
                esac
            fi
          fi
@@ -5177,7 +6271,8 @@ func_mode_link ()
            test "$pass" = conv && continue
            newdependency_libs="$deplib $newdependency_libs"
            func_stripname '-L' '' "$deplib"
-           newlib_search_path="$newlib_search_path $func_stripname_result"
+           func_resolve_sysroot "$func_stripname_result"
+           func_append newlib_search_path " $func_resolve_sysroot_result"
            ;;
          prog)
            if test "$pass" = conv; then
@@ -5191,7 +6286,8 @@ func_mode_link ()
              finalize_deplibs="$deplib $finalize_deplibs"
            fi
            func_stripname '-L' '' "$deplib"
-           newlib_search_path="$newlib_search_path $func_stripname_result"
+           func_resolve_sysroot "$func_stripname_result"
+           func_append newlib_search_path " $func_resolve_sysroot_result"
            ;;
          *)
            func_warning "\`-L' is ignored for archives/objects"
@@ -5202,17 +6298,21 @@ func_mode_link ()
        -R*)
          if test "$pass" = link; then
            func_stripname '-R' '' "$deplib"
-           dir=$func_stripname_result
+           func_resolve_sysroot "$func_stripname_result"
+           dir=$func_resolve_sysroot_result
            # Make sure the xrpath contains only unique directories.
            case "$xrpath " in
            *" $dir "*) ;;
-           *) xrpath="$xrpath $dir" ;;
+           *) func_append xrpath " $dir" ;;
            esac
          fi
          deplibs="$deplib $deplibs"
          continue
          ;;
-       *.la) lib="$deplib" ;;
+       *.la)
+         func_resolve_sysroot "$deplib"
+         lib=$func_resolve_sysroot_result
+         ;;
        *.$libext)
          if test "$pass" = conv; then
            deplibs="$deplib $deplibs"
@@ -5230,7 +6330,7 @@ func_mode_link ()
                match_pattern*)
                  set dummy $deplibs_check_method; shift
                  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
-                 if eval "\$ECHO \"X$deplib\"" 2>/dev/null | $Xsed -e 10q \
+                 if eval "\$ECHO \"$deplib\"" 2>/dev/null | $SED 10q \
                    | $EGREP "$match_pattern_regex" > /dev/null; then
                    valid_a_lib=yes
                  fi
@@ -5240,15 +6340,15 @@ func_mode_link ()
                ;;
              esac
              if test "$valid_a_lib" != yes; then
-               $ECHO
+               echo
                $ECHO "*** Warning: Trying to link with static lib archive $deplib."
-               $ECHO "*** I have the capability to make that library automatically link in when"
-               $ECHO "*** you link to this library.  But I can only do this if you have a"
-               $ECHO "*** shared version of the library, which you do not appear to have"
-               $ECHO "*** because the file extensions .$libext of this argument makes me believe"
-               $ECHO "*** that it is just a static archive that I should not use here."
+               echo "*** I have the capability to make that library automatically link in when"
+               echo "*** you link to this library.  But I can only do this if you have a"
+               echo "*** shared version of the library, which you do not appear to have"
+               echo "*** because the file extensions .$libext of this argument makes me believe"
+               echo "*** that it is just a static archive that I should not use here."
              else
-               $ECHO
+               echo
                $ECHO "*** Warning: Linking the shared library $output against the"
                $ECHO "*** static library $deplib is not portable!"
                deplibs="$deplib $deplibs"
@@ -5275,11 +6375,11 @@ func_mode_link ()
            if test "$pass" = dlpreopen || test "$dlopen_support" != yes || test "$build_libtool_libs" = no; then
              # If there is no dlopen support or we're linking statically,
              # we need to preload.
-             newdlprefiles="$newdlprefiles $deplib"
+             func_append newdlprefiles " $deplib"
              compile_deplibs="$deplib $compile_deplibs"
              finalize_deplibs="$deplib $finalize_deplibs"
            else
-             newdlfiles="$newdlfiles $deplib"
+             func_append newdlfiles " $deplib"
            fi
          fi
          continue
@@ -5321,20 +6421,20 @@ func_mode_link ()
 
        # Convert "-framework foo" to "foo.ltframework"
        if test -n "$inherited_linker_flags"; then
-         tmp_inherited_linker_flags=`$ECHO "X$inherited_linker_flags" | $Xsed -e 's/-framework \([^ $]*\)/\1.ltframework/g'`
+         tmp_inherited_linker_flags=`$ECHO "$inherited_linker_flags" | $SED 's/-framework \([^ $]*\)/\1.ltframework/g'`
          for tmp_inherited_linker_flag in $tmp_inherited_linker_flags; do
            case " $new_inherited_linker_flags " in
              *" $tmp_inherited_linker_flag "*) ;;
-             *) new_inherited_linker_flags="$new_inherited_linker_flags $tmp_inherited_linker_flag";;
+             *) func_append new_inherited_linker_flags " $tmp_inherited_linker_flag";;
            esac
          done
        fi
-       dependency_libs=`$ECHO "X $dependency_libs" | $Xsed -e 's% \([^ $]*\).ltframework% -framework \1%g'`
+       dependency_libs=`$ECHO " $dependency_libs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
        if test "$linkmode,$pass" = "lib,link" ||
           test "$linkmode,$pass" = "prog,scan" ||
           { test "$linkmode" != prog && test "$linkmode" != lib; }; then
-         test -n "$dlopen" && dlfiles="$dlfiles $dlopen"
-         test -n "$dlpreopen" && dlprefiles="$dlprefiles $dlpreopen"
+         test -n "$dlopen" && func_append dlfiles " $dlopen"
+         test -n "$dlpreopen" && func_append dlprefiles " $dlpreopen"
        fi
 
        if test "$pass" = conv; then
@@ -5345,17 +6445,17 @@ func_mode_link ()
              func_fatal_error "cannot find name of link library for \`$lib'"
            fi
            # It is a libtool convenience library, so add in its objects.
-           convenience="$convenience $ladir/$objdir/$old_library"
-           old_convenience="$old_convenience $ladir/$objdir/$old_library"
+           func_append convenience " $ladir/$objdir/$old_library"
+           func_append old_convenience " $ladir/$objdir/$old_library"
            tmp_libs=
            for deplib in $dependency_libs; do
              deplibs="$deplib $deplibs"
-             if $opt_duplicate_deps ; then
+             if $opt_preserve_dup_deps ; then
                case "$tmp_libs " in
-               *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;;
+               *" $deplib "*) func_append specialdeplibs " $deplib" ;;
                esac
              fi
-             tmp_libs="$tmp_libs $deplib"
+             func_append tmp_libs " $deplib"
            done
          elif test "$linkmode" != prog && test "$linkmode" != lib; then
            func_fatal_error "\`$lib' is not a convenience library"
@@ -5366,9 +6466,15 @@ func_mode_link ()
 
        # Get the name of the library we link against.
        linklib=
-       for l in $old_library $library_names; do
-         linklib="$l"
-       done
+       if test -n "$old_library" &&
+          { test "$prefer_static_libs" = yes ||
+            test "$prefer_static_libs,$installed" = "built,no"; }; then
+         linklib=$old_library
+       else
+         for l in $old_library $library_names; do
+           linklib="$l"
+         done
+       fi
        if test -z "$linklib"; then
          func_fatal_error "cannot find name of link library for \`$lib'"
        fi
@@ -5385,9 +6491,9 @@ func_mode_link ()
            # statically, we need to preload.  We also need to preload any
            # dependent libraries so libltdl's deplib preloader doesn't
            # bomb out in the load deplibs phase.
-           dlprefiles="$dlprefiles $lib $dependency_libs"
+           func_append dlprefiles " $lib $dependency_libs"
          else
-           newdlfiles="$newdlfiles $lib"
+           func_append newdlfiles " $lib"
          fi
          continue
        fi # $pass = dlopen
@@ -5409,14 +6515,14 @@ func_mode_link ()
 
        # Find the relevant object directory and library name.
        if test "X$installed" = Xyes; then
-         if test ! -f "$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then
+         if test ! -f "$lt_sysroot$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then
            func_warning "library \`$lib' was moved."
            dir="$ladir"
            absdir="$abs_ladir"
            libdir="$abs_ladir"
          else
-           dir="$libdir"
-           absdir="$libdir"
+           dir="$lt_sysroot$libdir"
+           absdir="$lt_sysroot$libdir"
          fi
          test "X$hardcode_automatic" = Xyes && avoidtemprpath=yes
        else
@@ -5424,12 +6530,12 @@ func_mode_link ()
            dir="$ladir"
            absdir="$abs_ladir"
            # Remove this search path later
-           notinst_path="$notinst_path $abs_ladir"
+           func_append notinst_path " $abs_ladir"
          else
            dir="$ladir/$objdir"
            absdir="$abs_ladir/$objdir"
            # Remove this search path later
-           notinst_path="$notinst_path $abs_ladir"
+           func_append notinst_path " $abs_ladir"
          fi
        fi # $installed = yes
        func_stripname 'lib' '.la' "$laname"
@@ -5440,20 +6546,46 @@ func_mode_link ()
          if test -z "$libdir" && test "$linkmode" = prog; then
            func_fatal_error "only libraries may -dlpreopen a convenience library: \`$lib'"
          fi
-         # Prefer using a static library (so that no silly _DYNAMIC symbols
-         # are required to link).
-         if test -n "$old_library"; then
-           newdlprefiles="$newdlprefiles $dir/$old_library"
-           # Keep a list of preopened convenience libraries to check
-           # that they are being used correctly in the link pass.
-           test -z "$libdir" && \
-               dlpreconveniencelibs="$dlpreconveniencelibs $dir/$old_library"
-         # Otherwise, use the dlname, so that lt_dlopen finds it.
-         elif test -n "$dlname"; then
-           newdlprefiles="$newdlprefiles $dir/$dlname"
-         else
-           newdlprefiles="$newdlprefiles $dir/$linklib"
-         fi
+         case "$host" in
+           # special handling for platforms with PE-DLLs.
+           *cygwin* | *mingw* | *cegcc* )
+             # Linker will automatically link against shared library if both
+             # static and shared are present.  Therefore, ensure we extract
+             # symbols from the import library if a shared library is present
+             # (otherwise, the dlopen module name will be incorrect).  We do
+             # this by putting the import library name into $newdlprefiles.
+             # We recover the dlopen module name by 'saving' the la file
+             # name in a special purpose variable, and (later) extracting the
+             # dlname from the la file.
+             if test -n "$dlname"; then
+               func_tr_sh "$dir/$linklib"
+               eval "libfile_$func_tr_sh_result=\$abs_ladir/\$laname"
+               func_append newdlprefiles " $dir/$linklib"
+             else
+               func_append newdlprefiles " $dir/$old_library"
+               # Keep a list of preopened convenience libraries to check
+               # that they are being used correctly in the link pass.
+               test -z "$libdir" && \
+                 func_append dlpreconveniencelibs " $dir/$old_library"
+             fi
+           ;;
+           * )
+             # Prefer using a static library (so that no silly _DYNAMIC symbols
+             # are required to link).
+             if test -n "$old_library"; then
+               func_append newdlprefiles " $dir/$old_library"
+               # Keep a list of preopened convenience libraries to check
+               # that they are being used correctly in the link pass.
+               test -z "$libdir" && \
+                 func_append dlpreconveniencelibs " $dir/$old_library"
+             # Otherwise, use the dlname, so that lt_dlopen finds it.
+             elif test -n "$dlname"; then
+               func_append newdlprefiles " $dir/$dlname"
+             else
+               func_append newdlprefiles " $dir/$linklib"
+             fi
+           ;;
+         esac
        fi # $pass = dlpreopen
 
        if test -z "$libdir"; then
@@ -5471,7 +6603,7 @@ func_mode_link ()
 
 
        if test "$linkmode" = prog && test "$pass" != link; then
-         newlib_search_path="$newlib_search_path $ladir"
+         func_append newlib_search_path " $ladir"
          deplibs="$lib $deplibs"
 
          linkalldeplibs=no
@@ -5484,7 +6616,8 @@ func_mode_link ()
          for deplib in $dependency_libs; do
            case $deplib in
            -L*) func_stripname '-L' '' "$deplib"
-                newlib_search_path="$newlib_search_path $func_stripname_result"
+                func_resolve_sysroot "$func_stripname_result"
+                func_append newlib_search_path " $func_resolve_sysroot_result"
                 ;;
            esac
            # Need to link against all dependency_libs?
@@ -5495,12 +6628,12 @@ func_mode_link ()
              # or/and link against static libraries
              newdependency_libs="$deplib $newdependency_libs"
            fi
-           if $opt_duplicate_deps ; then
+           if $opt_preserve_dup_deps ; then
              case "$tmp_libs " in
-             *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;;
+             *" $deplib "*) func_append specialdeplibs " $deplib" ;;
              esac
            fi
-           tmp_libs="$tmp_libs $deplib"
+           func_append tmp_libs " $deplib"
          done # for deplib
          continue
        fi # $linkmode = prog...
@@ -5515,7 +6648,7 @@ func_mode_link ()
              # Make sure the rpath contains only unique directories.
              case "$temp_rpath:" in
              *"$absdir:"*) ;;
-             *) temp_rpath="$temp_rpath$absdir:" ;;
+             *) func_append temp_rpath "$absdir:" ;;
              esac
            fi
 
@@ -5527,7 +6660,7 @@ func_mode_link ()
            *)
              case "$compile_rpath " in
              *" $absdir "*) ;;
-             *) compile_rpath="$compile_rpath $absdir"
+             *) func_append compile_rpath " $absdir" ;;
              esac
              ;;
            esac
@@ -5536,7 +6669,7 @@ func_mode_link ()
            *)
              case "$finalize_rpath " in
              *" $libdir "*) ;;
-             *) finalize_rpath="$finalize_rpath $libdir"
+             *) func_append finalize_rpath " $libdir" ;;
              esac
              ;;
            esac
@@ -5561,12 +6694,12 @@ func_mode_link ()
          case $host in
          *cygwin* | *mingw* | *cegcc*)
              # No point in relinking DLLs because paths are not encoded
-             notinst_deplibs="$notinst_deplibs $lib"
+             func_append notinst_deplibs " $lib"
              need_relink=no
            ;;
          *)
            if test "$installed" = no; then
-             notinst_deplibs="$notinst_deplibs $lib"
+             func_append notinst_deplibs " $lib"
              need_relink=yes
            fi
            ;;
@@ -5583,7 +6716,7 @@ func_mode_link ()
            fi
          done
          if test -z "$dlopenmodule" && test "$shouldnotlink" = yes && test "$pass" = link; then
-           $ECHO
+           echo
            if test "$linkmode" = prog; then
              $ECHO "*** Warning: Linking the executable $output against the loadable module"
            else
@@ -5601,7 +6734,7 @@ func_mode_link ()
            *)
              case "$compile_rpath " in
              *" $absdir "*) ;;
-             *) compile_rpath="$compile_rpath $absdir"
+             *) func_append compile_rpath " $absdir" ;;
              esac
              ;;
            esac
@@ -5610,7 +6743,7 @@ func_mode_link ()
            *)
              case "$finalize_rpath " in
              *" $libdir "*) ;;
-             *) finalize_rpath="$finalize_rpath $libdir"
+             *) func_append finalize_rpath " $libdir" ;;
              esac
              ;;
            esac
@@ -5664,7 +6797,7 @@ func_mode_link ()
            linklib=$newlib
          fi # test -n "$old_archive_from_expsyms_cmds"
 
-         if test "$linkmode" = prog || test "$mode" != relink; then
+         if test "$linkmode" = prog || test "$opt_mode" != relink; then
            add_shlibpath=
            add_dir=
            add=
@@ -5686,9 +6819,9 @@ func_mode_link ()
                      if test "X$dlopenmodule" != "X$lib"; then
                        $ECHO "*** Warning: lib $linklib is a module, not a shared library"
                        if test -z "$old_library" ; then
-                         $ECHO
-                         $ECHO "*** And there doesn't seem to be a static archive available"
-                         $ECHO "*** The link will probably fail, sorry"
+                         echo
+                         echo "*** And there doesn't seem to be a static archive available"
+                         echo "*** The link will probably fail, sorry"
                        else
                          add="$dir/$old_library"
                        fi
@@ -5715,12 +6848,12 @@ func_mode_link ()
                 test "$hardcode_direct_absolute" = no; then
                add="$dir/$linklib"
              elif test "$hardcode_minus_L" = yes; then
-               add_dir="-L$dir"
+               add_dir="-L$absdir"
                # Try looking first in the location we're being installed to.
                if test -n "$inst_prefix_dir"; then
                  case $libdir in
                    [\\/]*)
-                     add_dir="$add_dir -L$inst_prefix_dir$libdir"
+                     func_append add_dir " -L$inst_prefix_dir$libdir"
                      ;;
                  esac
                fi
@@ -5742,7 +6875,7 @@ func_mode_link ()
            if test -n "$add_shlibpath"; then
              case :$compile_shlibpath: in
              *":$add_shlibpath:"*) ;;
-             *) compile_shlibpath="$compile_shlibpath$add_shlibpath:" ;;
+             *) func_append compile_shlibpath "$add_shlibpath:" ;;
              esac
            fi
            if test "$linkmode" = prog; then
@@ -5756,13 +6889,13 @@ func_mode_link ()
                 test "$hardcode_shlibpath_var" = yes; then
                case :$finalize_shlibpath: in
                *":$libdir:"*) ;;
-               *) finalize_shlibpath="$finalize_shlibpath$libdir:" ;;
+               *) func_append finalize_shlibpath "$libdir:" ;;
                esac
              fi
            fi
          fi
 
-         if test "$linkmode" = prog || test "$mode" = relink; then
+         if test "$linkmode" = prog || test "$opt_mode" = relink; then
            add_shlibpath=
            add_dir=
            add=
@@ -5776,7 +6909,7 @@ func_mode_link ()
            elif test "$hardcode_shlibpath_var" = yes; then
              case :$finalize_shlibpath: in
              *":$libdir:"*) ;;
-             *) finalize_shlibpath="$finalize_shlibpath$libdir:" ;;
+             *) func_append finalize_shlibpath "$libdir:" ;;
              esac
              add="-l$name"
            elif test "$hardcode_automatic" = yes; then
@@ -5793,7 +6926,7 @@ func_mode_link ()
              if test -n "$inst_prefix_dir"; then
                case $libdir in
                  [\\/]*)
-                   add_dir="$add_dir -L$inst_prefix_dir$libdir"
+                   func_append add_dir " -L$inst_prefix_dir$libdir"
                    ;;
                esac
              fi
@@ -5828,21 +6961,21 @@ func_mode_link ()
 
            # Just print a warning and add the library to dependency_libs so
            # that the program can be linked against the static library.
-           $ECHO
+           echo
            $ECHO "*** Warning: This system can not link to static lib archive $lib."
-           $ECHO "*** I have the capability to make that library automatically link in when"
-           $ECHO "*** you link to this library.  But I can only do this if you have a"
-           $ECHO "*** shared version of the library, which you do not appear to have."
+           echo "*** I have the capability to make that library automatically link in when"
+           echo "*** you link to this library.  But I can only do this if you have a"
+           echo "*** shared version of the library, which you do not appear to have."
            if test "$module" = yes; then
-             $ECHO "*** But as you try to build a module library, libtool will still create "
-             $ECHO "*** a static module, that should work as long as the dlopening application"
-             $ECHO "*** is linked with the -dlopen flag to resolve symbols at runtime."
+             echo "*** But as you try to build a module library, libtool will still create "
+             echo "*** a static module, that should work as long as the dlopening application"
+             echo "*** is linked with the -dlopen flag to resolve symbols at runtime."
              if test -z "$global_symbol_pipe"; then
-               $ECHO
-               $ECHO "*** However, this would only work if libtool was able to extract symbol"
-               $ECHO "*** lists from a program, using \`nm' or equivalent, but libtool could"
-               $ECHO "*** not find such a program.  So, this module is probably useless."
-               $ECHO "*** \`nm' from GNU binutils and a full rebuild may help."
+               echo
+               echo "*** However, this would only work if libtool was able to extract symbol"
+               echo "*** lists from a program, using \`nm' or equivalent, but libtool could"
+               echo "*** not find such a program.  So, this module is probably useless."
+               echo "*** \`nm' from GNU binutils and a full rebuild may help."
              fi
              if test "$build_old_libs" = no; then
                build_libtool_libs=module
@@ -5870,27 +7003,33 @@ func_mode_link ()
                   temp_xrpath=$func_stripname_result
                   case " $xrpath " in
                   *" $temp_xrpath "*) ;;
-                  *) xrpath="$xrpath $temp_xrpath";;
+                  *) func_append xrpath " $temp_xrpath";;
                   esac;;
-             *) temp_deplibs="$temp_deplibs $libdir";;
+             *) func_append temp_deplibs " $libdir";;
              esac
            done
            dependency_libs="$temp_deplibs"
          fi
 
-         newlib_search_path="$newlib_search_path $absdir"
+         func_append newlib_search_path " $absdir"
          # Link against this library
          test "$link_static" = no && newdependency_libs="$abs_ladir/$laname $newdependency_libs"
          # ... and its dependency_libs
          tmp_libs=
          for deplib in $dependency_libs; do
            newdependency_libs="$deplib $newdependency_libs"
-           if $opt_duplicate_deps ; then
+           case $deplib in
+              -L*) func_stripname '-L' '' "$deplib"
+                   func_resolve_sysroot "$func_stripname_result";;
+              *) func_resolve_sysroot "$deplib" ;;
+            esac
+           if $opt_preserve_dup_deps ; then
              case "$tmp_libs " in
-             *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;;
+             *" $func_resolve_sysroot_result "*)
+                func_append specialdeplibs " $func_resolve_sysroot_result" ;;
              esac
            fi
-           tmp_libs="$tmp_libs $deplib"
+           func_append tmp_libs " $func_resolve_sysroot_result"
          done
 
          if test "$link_all_deplibs" != no; then
@@ -5900,8 +7039,10 @@ func_mode_link ()
              case $deplib in
              -L*) path="$deplib" ;;
              *.la)
+               func_resolve_sysroot "$deplib"
+               deplib=$func_resolve_sysroot_result
                func_dirname "$deplib" "" "."
-               dir="$func_dirname_result"
+               dir=$func_dirname_result
                # We need an absolute path.
                case $dir in
                [\\/]* | [A-Za-z]:[\\/]*) absdir="$dir" ;;
@@ -5928,8 +7069,8 @@ func_mode_link ()
                       if test -z "$darwin_install_name"; then
                           darwin_install_name=`${OTOOL64} -L $depdepl  | awk '{if (NR == 2) {print $1;exit}}'`
                       fi
-                     compiler_flags="$compiler_flags ${wl}-dylib_file ${wl}${darwin_install_name}:${depdepl}"
-                     linker_flags="$linker_flags -dylib_file ${darwin_install_name}:${depdepl}"
+                     func_append compiler_flags " ${wl}-dylib_file ${wl}${darwin_install_name}:${depdepl}"
+                     func_append linker_flags " -dylib_file ${darwin_install_name}:${depdepl}"
                      path=
                    fi
                  fi
@@ -5962,7 +7103,7 @@ func_mode_link ()
          compile_deplibs="$new_inherited_linker_flags $compile_deplibs"
          finalize_deplibs="$new_inherited_linker_flags $finalize_deplibs"
        else
-         compiler_flags="$compiler_flags "`$ECHO "X $new_inherited_linker_flags" | $Xsed -e 's% \([^ $]*\).ltframework% -framework \1%g'`
+         compiler_flags="$compiler_flags "`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
        fi
       fi
       dependency_libs="$newdependency_libs"
@@ -5979,7 +7120,7 @@ func_mode_link ()
          for dir in $newlib_search_path; do
            case "$lib_search_path " in
            *" $dir "*) ;;
-           *) lib_search_path="$lib_search_path $dir" ;;
+           *) func_append lib_search_path " $dir" ;;
            esac
          done
          newlib_search_path=
@@ -6037,10 +7178,10 @@ func_mode_link ()
            -L*)
              case " $tmp_libs " in
              *" $deplib "*) ;;
-             *) tmp_libs="$tmp_libs $deplib" ;;
+             *) func_append tmp_libs " $deplib" ;;
              esac
              ;;
-           *) tmp_libs="$tmp_libs $deplib" ;;
+           *) func_append tmp_libs " $deplib" ;;
            esac
          done
          eval $var=\"$tmp_libs\"
@@ -6056,7 +7197,7 @@ func_mode_link ()
          ;;
        esac
        if test -n "$i" ; then
-         tmp_libs="$tmp_libs $i"
+         func_append tmp_libs " $i"
        fi
       done
       dependency_libs=$tmp_libs
@@ -6097,7 +7238,7 @@ func_mode_link ()
       # Now set the variables for building old libraries.
       build_libtool_libs=no
       oldlibs="$output"
-      objs="$objs$old_deplibs"
+      func_append objs "$old_deplibs"
       ;;
 
     lib)
@@ -6130,10 +7271,10 @@ func_mode_link ()
        if test "$deplibs_check_method" != pass_all; then
          func_fatal_error "cannot build libtool library \`$output' from non-libtool objects on this host:$objs"
        else
-         $ECHO
+         echo
          $ECHO "*** Warning: Linking the shared library $output against the non-libtool"
          $ECHO "*** objects $objs is not portable!"
-         libobjs="$libobjs $objs"
+         func_append libobjs " $objs"
        fi
       fi
 
@@ -6192,13 +7333,14 @@ func_mode_link ()
          # which has an extra 1 added just for fun
          #
          case $version_type in
+         # correct linux to gnu/linux during the next big refactor
          darwin|linux|osf|windows|none)
            func_arith $number_major + $number_minor
            current=$func_arith_result
            age="$number_minor"
            revision="$number_revision"
            ;;
-         freebsd-aout|freebsd-elf|sunos)
+         freebsd-aout|freebsd-elf|qnx|sunos)
            current="$number_major"
            revision="$number_minor"
            age="0"
@@ -6311,7 +7453,7 @@ func_mode_link ()
          versuffix="$major.$revision"
          ;;
 
-       linux)
+       linux) # correct to gnu/linux during the next big refactor
          func_arith $current - $age
          major=.$func_arith_result
          versuffix="$major.$age.$revision"
@@ -6334,7 +7476,7 @@ func_mode_link ()
          done
 
          # Make executables depend on our current version.
-         verstring="$verstring:${current}.0"
+         func_append verstring ":${current}.0"
          ;;
 
        qnx)
@@ -6402,10 +7544,10 @@ func_mode_link ()
       fi
 
       func_generate_dlsyms "$libname" "$libname" "yes"
-      libobjs="$libobjs $symfileobj"
+      func_append libobjs " $symfileobj"
       test "X$libobjs" = "X " && libobjs=
 
-      if test "$mode" != relink; then
+      if test "$opt_mode" != relink; then
        # Remove our outputs, but don't remove object files since they
        # may have been created when compiling PIC objects.
        removelist=
@@ -6421,7 +7563,7 @@ func_mode_link ()
                   continue
                 fi
               fi
-              removelist="$removelist $p"
+              func_append removelist " $p"
               ;;
            *) ;;
          esac
@@ -6432,27 +7574,28 @@ func_mode_link ()
 
       # Now set the variables for building old libraries.
       if test "$build_old_libs" = yes && test "$build_libtool_libs" != convenience ; then
-       oldlibs="$oldlibs $output_objdir/$libname.$libext"
+       func_append oldlibs " $output_objdir/$libname.$libext"
 
        # Transform .lo files to .o files.
-       oldobjs="$objs "`$ECHO "X$libobjs" | $SP2NL | $Xsed -e '/\.'${libext}'$/d' -e "$lo2o" | $NL2SP`
+       oldobjs="$objs "`$ECHO "$libobjs" | $SP2NL | $SED "/\.${libext}$/d; $lo2o" | $NL2SP`
       fi
 
       # Eliminate all temporary directories.
       #for path in $notinst_path; do
-      #        lib_search_path=`$ECHO "X$lib_search_path " | $Xsed -e "s% $path % %g"`
-      #        deplibs=`$ECHO "X$deplibs " | $Xsed -e "s% -L$path % %g"`
-      #        dependency_libs=`$ECHO "X$dependency_libs " | $Xsed -e "s% -L$path % %g"`
+      #        lib_search_path=`$ECHO "$lib_search_path " | $SED "s% $path % %g"`
+      #        deplibs=`$ECHO "$deplibs " | $SED "s% -L$path % %g"`
+      #        dependency_libs=`$ECHO "$dependency_libs " | $SED "s% -L$path % %g"`
       #done
 
       if test -n "$xrpath"; then
        # If the user specified any rpath flags, then add them.
        temp_xrpath=
        for libdir in $xrpath; do
-         temp_xrpath="$temp_xrpath -R$libdir"
+         func_replace_sysroot "$libdir"
+         func_append temp_xrpath " -R$func_replace_sysroot_result"
          case "$finalize_rpath " in
          *" $libdir "*) ;;
-         *) finalize_rpath="$finalize_rpath $libdir" ;;
+         *) func_append finalize_rpath " $libdir" ;;
          esac
        done
        if test "$hardcode_into_libs" != yes || test "$build_old_libs" = yes; then
@@ -6466,7 +7609,7 @@ func_mode_link ()
       for lib in $old_dlfiles; do
        case " $dlprefiles $dlfiles " in
        *" $lib "*) ;;
-       *) dlfiles="$dlfiles $lib" ;;
+       *) func_append dlfiles " $lib" ;;
        esac
       done
 
@@ -6476,19 +7619,19 @@ func_mode_link ()
       for lib in $old_dlprefiles; do
        case "$dlprefiles " in
        *" $lib "*) ;;
-       *) dlprefiles="$dlprefiles $lib" ;;
+       *) func_append dlprefiles " $lib" ;;
        esac
       done
 
       if test "$build_libtool_libs" = yes; then
        if test -n "$rpath"; then
          case $host in
-         *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc*)
+         *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc* | *-*-haiku*)
            # these systems don't actually have a c library (as such)!
            ;;
          *-*-rhapsody* | *-*-darwin1.[012])
            # Rhapsody C library is in the System framework
-           deplibs="$deplibs System.ltframework"
+           func_append deplibs " System.ltframework"
            ;;
          *-*-netbsd*)
            # Don't link with libc until the a.out ld.so is fixed.
@@ -6505,7 +7648,7 @@ func_mode_link ()
          *)
            # Add libc to deplibs on all other systems if necessary.
            if test "$build_libtool_need_lc" = "yes"; then
-             deplibs="$deplibs -lc"
+             func_append deplibs " -lc"
            fi
            ;;
          esac
@@ -6554,7 +7697,7 @@ EOF
                if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then
                  case " $predeps $postdeps " in
                  *" $i "*)
-                   newdeplibs="$newdeplibs $i"
+                   func_append newdeplibs " $i"
                    i=""
                    ;;
                  esac
@@ -6565,21 +7708,21 @@ EOF
                  set dummy $deplib_matches; shift
                  deplib_match=$1
                  if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0 ; then
-                   newdeplibs="$newdeplibs $i"
+                   func_append newdeplibs " $i"
                  else
                    droppeddeps=yes
-                   $ECHO
+                   echo
                    $ECHO "*** Warning: dynamic linker does not accept needed library $i."
-                   $ECHO "*** I have the capability to make that library automatically link in when"
-                   $ECHO "*** you link to this library.  But I can only do this if you have a"
-                   $ECHO "*** shared version of the library, which I believe you do not have"
-                   $ECHO "*** because a test_compile did reveal that the linker did not use it for"
-                   $ECHO "*** its dynamic dependency list that programs get resolved with at runtime."
+                   echo "*** I have the capability to make that library automatically link in when"
+                   echo "*** you link to this library.  But I can only do this if you have a"
+                   echo "*** shared version of the library, which I believe you do not have"
+                   echo "*** because a test_compile did reveal that the linker did not use it for"
+                   echo "*** its dynamic dependency list that programs get resolved with at runtime."
                  fi
                fi
                ;;
              *)
-               newdeplibs="$newdeplibs $i"
+               func_append newdeplibs " $i"
                ;;
              esac
            done
@@ -6597,7 +7740,7 @@ EOF
                  if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then
                    case " $predeps $postdeps " in
                    *" $i "*)
-                     newdeplibs="$newdeplibs $i"
+                     func_append newdeplibs " $i"
                      i=""
                      ;;
                    esac
@@ -6608,29 +7751,29 @@ EOF
                    set dummy $deplib_matches; shift
                    deplib_match=$1
                    if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0 ; then
-                     newdeplibs="$newdeplibs $i"
+                     func_append newdeplibs " $i"
                    else
                      droppeddeps=yes
-                     $ECHO
+                     echo
                      $ECHO "*** Warning: dynamic linker does not accept needed library $i."
-                     $ECHO "*** I have the capability to make that library automatically link in when"
-                     $ECHO "*** you link to this library.  But I can only do this if you have a"
-                     $ECHO "*** shared version of the library, which you do not appear to have"
-                     $ECHO "*** because a test_compile did reveal that the linker did not use this one"
-                     $ECHO "*** as a dynamic dependency that programs can get resolved with at runtime."
+                     echo "*** I have the capability to make that library automatically link in when"
+                     echo "*** you link to this library.  But I can only do this if you have a"
+                     echo "*** shared version of the library, which you do not appear to have"
+                     echo "*** because a test_compile did reveal that the linker did not use this one"
+                     echo "*** as a dynamic dependency that programs can get resolved with at runtime."
                    fi
                  fi
                else
                  droppeddeps=yes
-                 $ECHO
+                 echo
                  $ECHO "*** Warning!  Library $i is needed by this library but I was not able to"
-                 $ECHO "*** make it link in!  You will probably need to install it or some"
-                 $ECHO "*** library that it depends on before this library will be fully"
-                 $ECHO "*** functional.  Installing it before continuing would be even better."
+                 echo "*** make it link in!  You will probably need to install it or some"
+                 echo "*** library that it depends on before this library will be fully"
+                 echo "*** functional.  Installing it before continuing would be even better."
                fi
                ;;
              *)
-               newdeplibs="$newdeplibs $i"
+               func_append newdeplibs " $i"
                ;;
              esac
            done
@@ -6647,15 +7790,27 @@ EOF
              if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then
                case " $predeps $postdeps " in
                *" $a_deplib "*)
-                 newdeplibs="$newdeplibs $a_deplib"
+                 func_append newdeplibs " $a_deplib"
                  a_deplib=""
                  ;;
                esac
              fi
              if test -n "$a_deplib" ; then
                libname=`eval "\\$ECHO \"$libname_spec\""`
+               if test -n "$file_magic_glob"; then
+                 libnameglob=`func_echo_all "$libname" | $SED -e $file_magic_glob`
+               else
+                 libnameglob=$libname
+               fi
+               test "$want_nocaseglob" = yes && nocaseglob=`shopt -p nocaseglob`
                for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
-                 potential_libs=`ls $i/$libname[.-]* 2>/dev/null`
+                 if test "$want_nocaseglob" = yes; then
+                   shopt -s nocaseglob
+                   potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
+                   $nocaseglob
+                 else
+                   potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
+                 fi
                  for potent_lib in $potential_libs; do
                      # Follow soft links.
                      if ls -lLd "$potent_lib" 2>/dev/null |
@@ -6672,13 +7827,13 @@ EOF
                        potliblink=`ls -ld $potlib | ${SED} 's/.* -> //'`
                        case $potliblink in
                        [\\/]* | [A-Za-z]:[\\/]*) potlib="$potliblink";;
-                       *) potlib=`$ECHO "X$potlib" | $Xsed -e 's,[^/]*$,,'`"$potliblink";;
+                       *) potlib=`$ECHO "$potlib" | $SED 's,[^/]*$,,'`"$potliblink";;
                        esac
                      done
                      if eval $file_magic_cmd \"\$potlib\" 2>/dev/null |
                         $SED -e 10q |
                         $EGREP "$file_magic_regex" > /dev/null; then
-                       newdeplibs="$newdeplibs $a_deplib"
+                       func_append newdeplibs " $a_deplib"
                        a_deplib=""
                        break 2
                      fi
@@ -6687,12 +7842,12 @@ EOF
              fi
              if test -n "$a_deplib" ; then
                droppeddeps=yes
-               $ECHO
+               echo
                $ECHO "*** Warning: linker path does not have real file for library $a_deplib."
-               $ECHO "*** I have the capability to make that library automatically link in when"
-               $ECHO "*** you link to this library.  But I can only do this if you have a"
-               $ECHO "*** shared version of the library, which you do not appear to have"
-               $ECHO "*** because I did check the linker path looking for a file starting"
+               echo "*** I have the capability to make that library automatically link in when"
+               echo "*** you link to this library.  But I can only do this if you have a"
+               echo "*** shared version of the library, which you do not appear to have"
+               echo "*** because I did check the linker path looking for a file starting"
                if test -z "$potlib" ; then
                  $ECHO "*** with $libname but no candidates were found. (...for file magic test)"
                else
@@ -6703,7 +7858,7 @@ EOF
              ;;
            *)
              # Add a -L argument.
-             newdeplibs="$newdeplibs $a_deplib"
+             func_append newdeplibs " $a_deplib"
              ;;
            esac
          done # Gone through all deplibs.
@@ -6719,7 +7874,7 @@ EOF
              if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then
                case " $predeps $postdeps " in
                *" $a_deplib "*)
-                 newdeplibs="$newdeplibs $a_deplib"
+                 func_append newdeplibs " $a_deplib"
                  a_deplib=""
                  ;;
                esac
@@ -6730,9 +7885,9 @@ EOF
                  potential_libs=`ls $i/$libname[.-]* 2>/dev/null`
                  for potent_lib in $potential_libs; do
                    potlib="$potent_lib" # see symlink-check above in file_magic test
-                   if eval "\$ECHO \"X$potent_lib\"" 2>/dev/null | $Xsed -e 10q | \
+                   if eval "\$ECHO \"$potent_lib\"" 2>/dev/null | $SED 10q | \
                       $EGREP "$match_pattern_regex" > /dev/null; then
-                     newdeplibs="$newdeplibs $a_deplib"
+                     func_append newdeplibs " $a_deplib"
                      a_deplib=""
                      break 2
                    fi
@@ -6741,12 +7896,12 @@ EOF
              fi
              if test -n "$a_deplib" ; then
                droppeddeps=yes
-               $ECHO
+               echo
                $ECHO "*** Warning: linker path does not have real file for library $a_deplib."
-               $ECHO "*** I have the capability to make that library automatically link in when"
-               $ECHO "*** you link to this library.  But I can only do this if you have a"
-               $ECHO "*** shared version of the library, which you do not appear to have"
-               $ECHO "*** because I did check the linker path looking for a file starting"
+               echo "*** I have the capability to make that library automatically link in when"
+               echo "*** you link to this library.  But I can only do this if you have a"
+               echo "*** shared version of the library, which you do not appear to have"
+               echo "*** because I did check the linker path looking for a file starting"
                if test -z "$potlib" ; then
                  $ECHO "*** with $libname but no candidates were found. (...for regex pattern test)"
                else
@@ -6757,32 +7912,32 @@ EOF
              ;;
            *)
              # Add a -L argument.
-             newdeplibs="$newdeplibs $a_deplib"
+             func_append newdeplibs " $a_deplib"
              ;;
            esac
          done # Gone through all deplibs.
          ;;
        none | unknown | *)
          newdeplibs=""
-         tmp_deplibs=`$ECHO "X $deplibs" | $Xsed \
-             -e 's/ -lc$//' -e 's/ -[LR][^ ]*//g'`
+         tmp_deplibs=`$ECHO " $deplibs" | $SED 's/ -lc$//; s/ -[LR][^ ]*//g'`
          if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then
            for i in $predeps $postdeps ; do
              # can't use Xsed below, because $i might contain '/'
-             tmp_deplibs=`$ECHO "X $tmp_deplibs" | $Xsed -e "s,$i,,"`
+             tmp_deplibs=`$ECHO " $tmp_deplibs" | $SED "s,$i,,"`
            done
          fi
-         if $ECHO "X $tmp_deplibs" | $Xsed -e 's/[      ]//g' |
-            $GREP . >/dev/null; then
-           $ECHO
+         case $tmp_deplibs in
+         *[!\  \ ]*)
+           echo
            if test "X$deplibs_check_method" = "Xnone"; then
-             $ECHO "*** Warning: inter-library dependencies are not supported in this platform."
+             echo "*** Warning: inter-library dependencies are not supported in this platform."
            else
-             $ECHO "*** Warning: inter-library dependencies are not known to be supported."
+             echo "*** Warning: inter-library dependencies are not known to be supported."
            fi
-           $ECHO "*** All declared inter-library dependencies are being dropped."
+           echo "*** All declared inter-library dependencies are being dropped."
            droppeddeps=yes
-         fi
+           ;;
+         esac
          ;;
        esac
        versuffix=$versuffix_save
@@ -6794,23 +7949,23 @@ EOF
        case $host in
        *-*-rhapsody* | *-*-darwin1.[012])
          # On Rhapsody replace the C library with the System framework
-         newdeplibs=`$ECHO "X $newdeplibs" | $Xsed -e 's/ -lc / System.ltframework /'`
+         newdeplibs=`$ECHO " $newdeplibs" | $SED 's/ -lc / System.ltframework /'`
          ;;
        esac
 
        if test "$droppeddeps" = yes; then
          if test "$module" = yes; then
-           $ECHO
-           $ECHO "*** Warning: libtool could not satisfy all declared inter-library"
+           echo
+           echo "*** Warning: libtool could not satisfy all declared inter-library"
            $ECHO "*** dependencies of module $libname.  Therefore, libtool will create"
-           $ECHO "*** a static module, that should work as long as the dlopening"
-           $ECHO "*** application is linked with the -dlopen flag."
+           echo "*** a static module, that should work as long as the dlopening"
+           echo "*** application is linked with the -dlopen flag."
            if test -z "$global_symbol_pipe"; then
-             $ECHO
-             $ECHO "*** However, this would only work if libtool was able to extract symbol"
-             $ECHO "*** lists from a program, using \`nm' or equivalent, but libtool could"
-             $ECHO "*** not find such a program.  So, this module is probably useless."
-             $ECHO "*** \`nm' from GNU binutils and a full rebuild may help."
+             echo
+             echo "*** However, this would only work if libtool was able to extract symbol"
+             echo "*** lists from a program, using \`nm' or equivalent, but libtool could"
+             echo "*** not find such a program.  So, this module is probably useless."
+             echo "*** \`nm' from GNU binutils and a full rebuild may help."
            fi
            if test "$build_old_libs" = no; then
              oldlibs="$output_objdir/$libname.$libext"
@@ -6820,16 +7975,16 @@ EOF
              build_libtool_libs=no
            fi
          else
-           $ECHO "*** The inter-library dependencies that have been dropped here will be"
-           $ECHO "*** automatically added whenever a program is linked with this library"
-           $ECHO "*** or is declared to -dlopen it."
+           echo "*** The inter-library dependencies that have been dropped here will be"
+           echo "*** automatically added whenever a program is linked with this library"
+           echo "*** or is declared to -dlopen it."
 
            if test "$allow_undefined" = no; then
-             $ECHO
-             $ECHO "*** Since this library must not contain undefined symbols,"
-             $ECHO "*** because either the platform does not support them or"
-             $ECHO "*** it was explicitly requested with -no-undefined,"
-             $ECHO "*** libtool will only create a static version of it."
+             echo
+             echo "*** Since this library must not contain undefined symbols,"
+             echo "*** because either the platform does not support them or"
+             echo "*** it was explicitly requested with -no-undefined,"
+             echo "*** libtool will only create a static version of it."
              if test "$build_old_libs" = no; then
                oldlibs="$output_objdir/$libname.$libext"
                build_libtool_libs=module
@@ -6846,9 +8001,9 @@ EOF
       # Time to change all our "foo.ltframework" stuff back to "-framework foo"
       case $host in
        *-*-darwin*)
-         newdeplibs=`$ECHO "X $newdeplibs" | $Xsed -e 's% \([^ $]*\).ltframework% -framework \1%g'`
-         new_inherited_linker_flags=`$ECHO "X $new_inherited_linker_flags" | $Xsed -e 's% \([^ $]*\).ltframework% -framework \1%g'`
-         deplibs=`$ECHO "X $deplibs" | $Xsed -e 's% \([^ $]*\).ltframework% -framework \1%g'`
+         newdeplibs=`$ECHO " $newdeplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
+         new_inherited_linker_flags=`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
+         deplibs=`$ECHO " $deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
          ;;
       esac
 
@@ -6861,7 +8016,7 @@ EOF
        *)
          case " $deplibs " in
          *" -L$path/$objdir "*)
-           new_libs="$new_libs -L$path/$objdir" ;;
+           func_append new_libs " -L$path/$objdir" ;;
          esac
          ;;
        esac
@@ -6871,10 +8026,10 @@ EOF
        -L*)
          case " $new_libs " in
          *" $deplib "*) ;;
-         *) new_libs="$new_libs $deplib" ;;
+         *) func_append new_libs " $deplib" ;;
          esac
          ;;
-       *) new_libs="$new_libs $deplib" ;;
+       *) func_append new_libs " $deplib" ;;
        esac
       done
       deplibs="$new_libs"
@@ -6886,15 +8041,22 @@ EOF
 
       # Test again, we may have decided not to build it any more
       if test "$build_libtool_libs" = yes; then
+       # Remove ${wl} instances when linking with ld.
+       # FIXME: should test the right _cmds variable.
+       case $archive_cmds in
+         *\$LD\ *) wl= ;;
+        esac
        if test "$hardcode_into_libs" = yes; then
          # Hardcode the library paths
          hardcode_libdirs=
          dep_rpath=
          rpath="$finalize_rpath"
-         test "$mode" != relink && rpath="$compile_rpath$rpath"
+         test "$opt_mode" != relink && rpath="$compile_rpath$rpath"
          for libdir in $rpath; do
            if test -n "$hardcode_libdir_flag_spec"; then
              if test -n "$hardcode_libdir_separator"; then
+               func_replace_sysroot "$libdir"
+               libdir=$func_replace_sysroot_result
                if test -z "$hardcode_libdirs"; then
                  hardcode_libdirs="$libdir"
                else
@@ -6903,18 +8065,18 @@ EOF
                  *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
                    ;;
                  *)
-                   hardcode_libdirs="$hardcode_libdirs$hardcode_libdir_separator$libdir"
+                   func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
                    ;;
                  esac
                fi
              else
                eval flag=\"$hardcode_libdir_flag_spec\"
-               dep_rpath="$dep_rpath $flag"
+               func_append dep_rpath " $flag"
              fi
            elif test -n "$runpath_var"; then
              case "$perm_rpath " in
              *" $libdir "*) ;;
-             *) perm_rpath="$perm_rpath $libdir" ;;
+             *) func_append perm_rpath " $libdir" ;;
              esac
            fi
          done
@@ -6922,17 +8084,13 @@ EOF
          if test -n "$hardcode_libdir_separator" &&
             test -n "$hardcode_libdirs"; then
            libdir="$hardcode_libdirs"
-           if test -n "$hardcode_libdir_flag_spec_ld"; then
-             eval dep_rpath=\"$hardcode_libdir_flag_spec_ld\"
-           else
-             eval dep_rpath=\"$hardcode_libdir_flag_spec\"
-           fi
+           eval "dep_rpath=\"$hardcode_libdir_flag_spec\""
          fi
          if test -n "$runpath_var" && test -n "$perm_rpath"; then
            # We should set the runpath_var.
            rpath=
            for dir in $perm_rpath; do
-             rpath="$rpath$dir:"
+             func_append rpath "$dir:"
            done
            eval "$runpath_var='$rpath\$$runpath_var'; export $runpath_var"
          fi
@@ -6940,7 +8098,7 @@ EOF
        fi
 
        shlibpath="$finalize_shlibpath"
-       test "$mode" != relink && shlibpath="$compile_shlibpath$shlibpath"
+       test "$opt_mode" != relink && shlibpath="$compile_shlibpath$shlibpath"
        if test -n "$shlibpath"; then
          eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export $shlibpath_var"
        fi
@@ -6966,18 +8124,18 @@ EOF
        linknames=
        for link
        do
-         linknames="$linknames $link"
+         func_append linknames " $link"
        done
 
        # Use standard objects if they are pic
-       test -z "$pic_flag" && libobjs=`$ECHO "X$libobjs" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP`
+       test -z "$pic_flag" && libobjs=`$ECHO "$libobjs" | $SP2NL | $SED "$lo2o" | $NL2SP`
        test "X$libobjs" = "X " && libobjs=
 
        delfiles=
        if test -n "$export_symbols" && test -n "$include_expsyms"; then
          $opt_dry_run || cp "$export_symbols" "$output_objdir/$libname.uexp"
          export_symbols="$output_objdir/$libname.uexp"
-         delfiles="$delfiles $export_symbols"
+         func_append delfiles " $export_symbols"
        fi
 
        orig_export_symbols=
@@ -7008,13 +8166,45 @@ EOF
            $opt_dry_run || $RM $export_symbols
            cmds=$export_symbols_cmds
            save_ifs="$IFS"; IFS='~'
-           for cmd in $cmds; do
+           for cmd1 in $cmds; do
              IFS="$save_ifs"
-             eval cmd=\"$cmd\"
-             func_len " $cmd"
-             len=$func_len_result
-             if test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
+             # Take the normal branch if the nm_file_list_spec branch
+             # doesn't work or if tool conversion is not needed.
+             case $nm_file_list_spec~$to_tool_file_cmd in
+               *~func_convert_file_noop | *~func_convert_file_msys_to_w32 | ~*)
+                 try_normal_branch=yes
+                 eval cmd=\"$cmd1\"
+                 func_len " $cmd"
+                 len=$func_len_result
+                 ;;
+               *)
+                 try_normal_branch=no
+                 ;;
+             esac
+             if test "$try_normal_branch" = yes \
+                && { test "$len" -lt "$max_cmd_len" \
+                     || test "$max_cmd_len" -le -1; }
+             then
+               func_show_eval "$cmd" 'exit $?'
+               skipped_export=false
+             elif test -n "$nm_file_list_spec"; then
+               func_basename "$output"
+               output_la=$func_basename_result
+               save_libobjs=$libobjs
+               save_output=$output
+               output=${output_objdir}/${output_la}.nm
+               func_to_tool_file "$output"
+               libobjs=$nm_file_list_spec$func_to_tool_file_result
+               func_append delfiles " $output"
+               func_verbose "creating $NM input file list: $output"
+               for obj in $save_libobjs; do
+                 func_to_tool_file "$obj"
+                 $ECHO "$func_to_tool_file_result"
+               done > "$output"
+               eval cmd=\"$cmd1\"
                func_show_eval "$cmd" 'exit $?'
+               output=$save_output
+               libobjs=$save_libobjs
                skipped_export=false
              else
                # The command line is too long to execute in one step.
@@ -7036,7 +8226,7 @@ EOF
        if test -n "$export_symbols" && test -n "$include_expsyms"; then
          tmp_export_symbols="$export_symbols"
          test -n "$orig_export_symbols" && tmp_export_symbols="$orig_export_symbols"
-         $opt_dry_run || eval '$ECHO "X$include_expsyms" | $Xsed | $SP2NL >> "$tmp_export_symbols"'
+         $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
        fi
 
        if test "X$skipped_export" != "X:" && test -n "$orig_export_symbols"; then
@@ -7048,7 +8238,7 @@ EOF
          # global variables. join(1) would be nice here, but unfortunately
          # isn't a blessed tool.
          $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
-         delfiles="$delfiles $export_symbols $output_objdir/$libname.filter"
+         func_append delfiles " $export_symbols $output_objdir/$libname.filter"
          export_symbols=$output_objdir/$libname.def
          $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
        fi
@@ -7058,7 +8248,7 @@ EOF
          case " $convenience " in
          *" $test_deplib "*) ;;
          *)
-           tmp_deplibs="$tmp_deplibs $test_deplib"
+           func_append tmp_deplibs " $test_deplib"
            ;;
          esac
        done
@@ -7078,21 +8268,21 @@ EOF
            test "X$libobjs" = "X " && libobjs=
          else
            gentop="$output_objdir/${outputname}x"
-           generated="$generated $gentop"
+           func_append generated " $gentop"
 
            func_extract_archives $gentop $convenience
-           libobjs="$libobjs $func_extract_archives_result"
+           func_append libobjs " $func_extract_archives_result"
            test "X$libobjs" = "X " && libobjs=
          fi
        fi
 
        if test "$thread_safe" = yes && test -n "$thread_safe_flag_spec"; then
          eval flag=\"$thread_safe_flag_spec\"
-         linker_flags="$linker_flags $flag"
+         func_append linker_flags " $flag"
        fi
 
        # Make a backup of the uninstalled library when relinking
-       if test "$mode" = relink; then
+       if test "$opt_mode" = relink; then
          $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}U && $MV $realname ${realname}U)' || exit $?
        fi
 
@@ -7137,7 +8327,8 @@ EOF
            save_libobjs=$libobjs
          fi
          save_output=$output
-         output_la=`$ECHO "X$output" | $Xsed -e "$basename"`
+         func_basename "$output"
+         output_la=$func_basename_result
 
          # Clear the reloadable object creation command queue and
          # initialize k to one.
@@ -7150,13 +8341,16 @@ EOF
          if test -n "$save_libobjs" && test "X$skipped_export" != "X:" && test "$with_gnu_ld" = yes; then
            output=${output_objdir}/${output_la}.lnkscript
            func_verbose "creating GNU ld script: $output"
-           $ECHO 'INPUT (' > $output
+           echo 'INPUT (' > $output
            for obj in $save_libobjs
            do
-             $ECHO "$obj" >> $output
+             func_to_tool_file "$obj"
+             $ECHO "$func_to_tool_file_result" >> $output
            done
-           $ECHO ')' >> $output
-           delfiles="$delfiles $output"
+           echo ')' >> $output
+           func_append delfiles " $output"
+           func_to_tool_file "$output"
+           output=$func_to_tool_file_result
          elif test -n "$save_libobjs" && test "X$skipped_export" != "X:" && test "X$file_list_spec" != X; then
            output=${output_objdir}/${output_la}.lnk
            func_verbose "creating linker input file list: $output"
@@ -7170,10 +8364,12 @@ EOF
            fi
            for obj
            do
-             $ECHO "$obj" >> $output
+             func_to_tool_file "$obj"
+             $ECHO "$func_to_tool_file_result" >> $output
            done
-           delfiles="$delfiles $output"
-           output=$firstobj\"$file_list_spec$output\"
+           func_append delfiles " $output"
+           func_to_tool_file "$output"
+           output=$firstobj\"$file_list_spec$func_to_tool_file_result\"
          else
            if test -n "$save_libobjs"; then
              func_verbose "creating reloadable object files..."
@@ -7197,17 +8393,19 @@ EOF
                  # command to the queue.
                  if test "$k" -eq 1 ; then
                    # The first file doesn't have a previous command to add.
-                   eval concat_cmds=\"$reload_cmds $objlist $last_robj\"
+                   reload_objs=$objlist
+                   eval concat_cmds=\"$reload_cmds\"
                  else
                    # All subsequent reloadable object files will link in
                    # the last one created.
-                   eval concat_cmds=\"\$concat_cmds~$reload_cmds $objlist $last_robj~\$RM $last_robj\"
+                   reload_objs="$objlist $last_robj"
+                   eval concat_cmds=\"\$concat_cmds~$reload_cmds~\$RM $last_robj\"
                  fi
                  last_robj=$output_objdir/$output_la-${k}.$objext
                  func_arith $k + 1
                  k=$func_arith_result
                  output=$output_objdir/$output_la-${k}.$objext
-                 objlist=$obj
+                 objlist=" $obj"
                  func_len " $last_robj"
                  func_arith $len0 + $func_len_result
                  len=$func_arith_result
@@ -7217,11 +8415,12 @@ EOF
              # reloadable object file.  All subsequent reloadable object
              # files will link in the last one created.
              test -z "$concat_cmds" || concat_cmds=$concat_cmds~
-             eval concat_cmds=\"\${concat_cmds}$reload_cmds $objlist $last_robj\"
+             reload_objs="$objlist $last_robj"
+             eval concat_cmds=\"\${concat_cmds}$reload_cmds\"
              if test -n "$last_robj"; then
                eval concat_cmds=\"\${concat_cmds}~\$RM $last_robj\"
              fi
-             delfiles="$delfiles $output"
+             func_append delfiles " $output"
 
            else
              output=
@@ -7255,7 +8454,7 @@ EOF
                lt_exit=$?
 
                # Restore the uninstalled library and exit
-               if test "$mode" = relink; then
+               if test "$opt_mode" = relink; then
                  ( cd "$output_objdir" && \
                    $RM "${realname}T" && \
                    $MV "${realname}U" "$realname" )
@@ -7276,7 +8475,7 @@ EOF
            if test -n "$export_symbols" && test -n "$include_expsyms"; then
              tmp_export_symbols="$export_symbols"
              test -n "$orig_export_symbols" && tmp_export_symbols="$orig_export_symbols"
-             $opt_dry_run || eval '$ECHO "X$include_expsyms" | $Xsed | $SP2NL >> "$tmp_export_symbols"'
+             $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
            fi
 
            if test -n "$orig_export_symbols"; then
@@ -7288,7 +8487,7 @@ EOF
              # global variables. join(1) would be nice here, but unfortunately
              # isn't a blessed tool.
              $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
-             delfiles="$delfiles $export_symbols $output_objdir/$libname.filter"
+             func_append delfiles " $export_symbols $output_objdir/$libname.filter"
              export_symbols=$output_objdir/$libname.def
              $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
            fi
@@ -7329,10 +8528,10 @@ EOF
        # Add any objects from preloaded convenience libraries
        if test -n "$dlprefiles"; then
          gentop="$output_objdir/${outputname}x"
-         generated="$generated $gentop"
+         func_append generated " $gentop"
 
          func_extract_archives $gentop $dlprefiles
-         libobjs="$libobjs $func_extract_archives_result"
+         func_append libobjs " $func_extract_archives_result"
          test "X$libobjs" = "X " && libobjs=
        fi
 
@@ -7348,7 +8547,7 @@ EOF
            lt_exit=$?
 
            # Restore the uninstalled library and exit
-           if test "$mode" = relink; then
+           if test "$opt_mode" = relink; then
              ( cd "$output_objdir" && \
                $RM "${realname}T" && \
                $MV "${realname}U" "$realname" )
@@ -7360,7 +8559,7 @@ EOF
        IFS="$save_ifs"
 
        # Restore the uninstalled library and exit
-       if test "$mode" = relink; then
+       if test "$opt_mode" = relink; then
          $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}T && $MV $realname ${realname}T && $MV ${realname}U $realname)' || exit $?
 
          if test -n "$convenience"; then
@@ -7441,18 +8640,21 @@ EOF
       if test -n "$convenience"; then
        if test -n "$whole_archive_flag_spec"; then
          eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\"
-         reload_conv_objs=$reload_objs\ `$ECHO "X$tmp_whole_archive_flags" | $Xsed -e 's|,| |g'`
+         reload_conv_objs=$reload_objs\ `$ECHO "$tmp_whole_archive_flags" | $SED 's|,| |g'`
        else
          gentop="$output_objdir/${obj}x"
-         generated="$generated $gentop"
+         func_append generated " $gentop"
 
          func_extract_archives $gentop $convenience
          reload_conv_objs="$reload_objs $func_extract_archives_result"
        fi
       fi
 
+      # If we're not building shared, we need to use non_pic_objs
+      test "$build_libtool_libs" != yes && libobjs="$non_pic_objects"
+
       # Create the old-style object.
-      reload_objs="$objs$old_deplibs "`$ECHO "X$libobjs" | $SP2NL | $Xsed -e '/\.'${libext}$'/d' -e '/\.lib$/d' -e "$lo2o" | $NL2SP`" $reload_conv_objs" ### testsuite: skip nested quoting test
+      reload_objs="$objs$old_deplibs "`$ECHO "$libobjs" | $SP2NL | $SED "/\.${libext}$/d; /\.lib$/d; $lo2o" | $NL2SP`" $reload_conv_objs" ### testsuite: skip nested quoting test
 
       output="$obj"
       func_execute_cmds "$reload_cmds" 'exit $?'
@@ -7512,8 +8714,8 @@ EOF
       case $host in
       *-*-rhapsody* | *-*-darwin1.[012])
        # On Rhapsody replace the C library is the System framework
-       compile_deplibs=`$ECHO "X $compile_deplibs" | $Xsed -e 's/ -lc / System.ltframework /'`
-       finalize_deplibs=`$ECHO "X $finalize_deplibs" | $Xsed -e 's/ -lc / System.ltframework /'`
+       compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's/ -lc / System.ltframework /'`
+       finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's/ -lc / System.ltframework /'`
        ;;
       esac
 
@@ -7524,14 +8726,14 @@ EOF
        if test "$tagname" = CXX ; then
          case ${MACOSX_DEPLOYMENT_TARGET-10.0} in
            10.[0123])
-             compile_command="$compile_command ${wl}-bind_at_load"
-             finalize_command="$finalize_command ${wl}-bind_at_load"
+             func_append compile_command " ${wl}-bind_at_load"
+             func_append finalize_command " ${wl}-bind_at_load"
            ;;
          esac
        fi
        # Time to change all our "foo.ltframework" stuff back to "-framework foo"
-       compile_deplibs=`$ECHO "X $compile_deplibs" | $Xsed -e 's% \([^ $]*\).ltframework% -framework \1%g'`
-       finalize_deplibs=`$ECHO "X $finalize_deplibs" | $Xsed -e 's% \([^ $]*\).ltframework% -framework \1%g'`
+       compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
+       finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
        ;;
       esac
 
@@ -7545,7 +8747,7 @@ EOF
        *)
          case " $compile_deplibs " in
          *" -L$path/$objdir "*)
-           new_libs="$new_libs -L$path/$objdir" ;;
+           func_append new_libs " -L$path/$objdir" ;;
          esac
          ;;
        esac
@@ -7555,17 +8757,17 @@ EOF
        -L*)
          case " $new_libs " in
          *" $deplib "*) ;;
-         *) new_libs="$new_libs $deplib" ;;
+         *) func_append new_libs " $deplib" ;;
          esac
          ;;
-       *) new_libs="$new_libs $deplib" ;;
+       *) func_append new_libs " $deplib" ;;
        esac
       done
       compile_deplibs="$new_libs"
 
 
-      compile_command="$compile_command $compile_deplibs"
-      finalize_command="$finalize_command $finalize_deplibs"
+      func_append compile_command " $compile_deplibs"
+      func_append finalize_command " $finalize_deplibs"
 
       if test -n "$rpath$xrpath"; then
        # If the user specified any rpath flags, then add them.
@@ -7573,7 +8775,7 @@ EOF
          # This is the magic to use -rpath.
          case "$finalize_rpath " in
          *" $libdir "*) ;;
-         *) finalize_rpath="$finalize_rpath $libdir" ;;
+         *) func_append finalize_rpath " $libdir" ;;
          esac
        done
       fi
@@ -7592,18 +8794,18 @@ EOF
              *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
                ;;
              *)
-               hardcode_libdirs="$hardcode_libdirs$hardcode_libdir_separator$libdir"
+               func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
                ;;
              esac
            fi
          else
            eval flag=\"$hardcode_libdir_flag_spec\"
-           rpath="$rpath $flag"
+           func_append rpath " $flag"
          fi
        elif test -n "$runpath_var"; then
          case "$perm_rpath " in
          *" $libdir "*) ;;
-         *) perm_rpath="$perm_rpath $libdir" ;;
+         *) func_append perm_rpath " $libdir" ;;
          esac
        fi
        case $host in
@@ -7612,12 +8814,12 @@ EOF
          case :$dllsearchpath: in
          *":$libdir:"*) ;;
          ::) dllsearchpath=$libdir;;
-         *) dllsearchpath="$dllsearchpath:$libdir";;
+         *) func_append dllsearchpath ":$libdir";;
          esac
          case :$dllsearchpath: in
          *":$testbindir:"*) ;;
          ::) dllsearchpath=$testbindir;;
-         *) dllsearchpath="$dllsearchpath:$testbindir";;
+         *) func_append dllsearchpath ":$testbindir";;
          esac
          ;;
        esac
@@ -7643,18 +8845,18 @@ EOF
              *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
                ;;
              *)
-               hardcode_libdirs="$hardcode_libdirs$hardcode_libdir_separator$libdir"
+               func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
                ;;
              esac
            fi
          else
            eval flag=\"$hardcode_libdir_flag_spec\"
-           rpath="$rpath $flag"
+           func_append rpath " $flag"
          fi
        elif test -n "$runpath_var"; then
          case "$finalize_perm_rpath " in
          *" $libdir "*) ;;
-         *) finalize_perm_rpath="$finalize_perm_rpath $libdir" ;;
+         *) func_append finalize_perm_rpath " $libdir" ;;
          esac
        fi
       done
@@ -7668,8 +8870,8 @@ EOF
 
       if test -n "$libobjs" && test "$build_old_libs" = yes; then
        # Transform all the library objects into standard objects.
-       compile_command=`$ECHO "X$compile_command" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP`
-       finalize_command=`$ECHO "X$finalize_command" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP`
+       compile_command=`$ECHO "$compile_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
+       finalize_command=`$ECHO "$finalize_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
       fi
 
       func_generate_dlsyms "$outputname" "@PROGRAM@" "no"
@@ -7681,15 +8883,15 @@ EOF
 
       wrappers_required=yes
       case $host in
+      *cegcc* | *mingw32ce*)
+        # Disable wrappers for cegcc and mingw32ce hosts, we are cross compiling anyway.
+        wrappers_required=no
+        ;;
       *cygwin* | *mingw* )
         if test "$build_libtool_libs" != yes; then
           wrappers_required=no
         fi
         ;;
-      *cegcc)
-        # Disable wrappers for cegcc, we are cross compiling anyway.
-        wrappers_required=no
-        ;;
       *)
         if test "$need_relink" = no || test "$build_libtool_libs" != yes; then
           wrappers_required=no
@@ -7698,13 +8900,19 @@ EOF
       esac
       if test "$wrappers_required" = no; then
        # Replace the output file specification.
-       compile_command=`$ECHO "X$compile_command" | $Xsed -e 's%@OUTPUT@%'"$output"'%g'`
+       compile_command=`$ECHO "$compile_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
        link_command="$compile_command$compile_rpath"
 
        # We have no uninstalled library dependencies, so finalize right now.
        exit_status=0
        func_show_eval "$link_command" 'exit_status=$?'
 
+       if test -n "$postlink_cmds"; then
+         func_to_tool_file "$output"
+         postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
+         func_execute_cmds "$postlink_cmds" 'exit $?'
+       fi
+
        # Delete the generated files.
        if test -f "$output_objdir/${outputname}S.${objext}"; then
          func_show_eval '$RM "$output_objdir/${outputname}S.${objext}"'
@@ -7727,7 +8935,7 @@ EOF
          # We should set the runpath_var.
          rpath=
          for dir in $perm_rpath; do
-           rpath="$rpath$dir:"
+           func_append rpath "$dir:"
          done
          compile_var="$runpath_var=\"$rpath\$$runpath_var\" "
        fi
@@ -7735,7 +8943,7 @@ EOF
          # We should set the runpath_var.
          rpath=
          for dir in $finalize_perm_rpath; do
-           rpath="$rpath$dir:"
+           func_append rpath "$dir:"
          done
          finalize_var="$runpath_var=\"$rpath\$$runpath_var\" "
        fi
@@ -7745,11 +8953,18 @@ EOF
        # We don't need to create a wrapper script.
        link_command="$compile_var$compile_command$compile_rpath"
        # Replace the output file specification.
-       link_command=`$ECHO "X$link_command" | $Xsed -e 's%@OUTPUT@%'"$output"'%g'`
+       link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
        # Delete the old output file.
        $opt_dry_run || $RM $output
        # Link the executable and exit
        func_show_eval "$link_command" 'exit $?'
+
+       if test -n "$postlink_cmds"; then
+         func_to_tool_file "$output"
+         postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
+         func_execute_cmds "$postlink_cmds" 'exit $?'
+       fi
+
        exit $EXIT_SUCCESS
       fi
 
@@ -7764,7 +8979,7 @@ EOF
        if test "$fast_install" != no; then
          link_command="$finalize_var$compile_command$finalize_rpath"
          if test "$fast_install" = yes; then
-           relink_command=`$ECHO "X$compile_var$compile_command$compile_rpath" | $Xsed -e 's%@OUTPUT@%\$progdir/\$file%g'`
+           relink_command=`$ECHO "$compile_var$compile_command$compile_rpath" | $SED 's%@OUTPUT@%\$progdir/\$file%g'`
          else
            # fast_install is set to needless
            relink_command=
@@ -7776,13 +8991,19 @@ EOF
       fi
 
       # Replace the output file specification.
-      link_command=`$ECHO "X$link_command" | $Xsed -e 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'`
+      link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'`
 
       # Delete the old output files.
       $opt_dry_run || $RM $output $output_objdir/$outputname $output_objdir/lt-$outputname
 
       func_show_eval "$link_command" 'exit $?'
 
+      if test -n "$postlink_cmds"; then
+       func_to_tool_file "$output_objdir/$outputname"
+       postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output_objdir/$outputname"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
+       func_execute_cmds "$postlink_cmds" 'exit $?'
+      fi
+
       # Now create the wrapper script.
       func_verbose "creating $output"
 
@@ -7800,18 +9021,7 @@ EOF
          fi
        done
        relink_command="(cd `pwd`; $relink_command)"
-       relink_command=`$ECHO "X$relink_command" | $Xsed -e "$sed_quote_subst"`
-      fi
-
-      # Quote $ECHO for shipping.
-      if test "X$ECHO" = "X$SHELL $progpath --fallback-echo"; then
-       case $progpath in
-       [\\/]* | [A-Za-z]:[\\/]*) qecho="$SHELL $progpath --fallback-echo";;
-       *) qecho="$SHELL `pwd`/$progpath --fallback-echo";;
-       esac
-       qecho=`$ECHO "X$qecho" | $Xsed -e "$sed_quote_subst"`
-      else
-       qecho=`$ECHO "X$ECHO" | $Xsed -e "$sed_quote_subst"`
+       relink_command=`$ECHO "$relink_command" | $SED "$sed_quote_subst"`
       fi
 
       # Only actually do things if not in dry run mode.
@@ -7891,7 +9101,7 @@ EOF
        else
          oldobjs="$old_deplibs $non_pic_objects"
          if test "$preload" = yes && test -f "$symfileobj"; then
-           oldobjs="$oldobjs $symfileobj"
+           func_append oldobjs " $symfileobj"
          fi
        fi
        addlibs="$old_convenience"
@@ -7899,10 +9109,10 @@ EOF
 
       if test -n "$addlibs"; then
        gentop="$output_objdir/${outputname}x"
-       generated="$generated $gentop"
+       func_append generated " $gentop"
 
        func_extract_archives $gentop $addlibs
-       oldobjs="$oldobjs $func_extract_archives_result"
+       func_append oldobjs " $func_extract_archives_result"
       fi
 
       # Do each command in the archive commands.
@@ -7913,10 +9123,10 @@ EOF
        # Add any objects from preloaded convenience libraries
        if test -n "$dlprefiles"; then
          gentop="$output_objdir/${outputname}x"
-         generated="$generated $gentop"
+         func_append generated " $gentop"
 
          func_extract_archives $gentop $dlprefiles
-         oldobjs="$oldobjs $func_extract_archives_result"
+         func_append oldobjs " $func_extract_archives_result"
        fi
 
        # POSIX demands no paths to be encoded in archives.  We have
@@ -7932,9 +9142,9 @@ EOF
            done | sort | sort -uc >/dev/null 2>&1); then
          :
        else
-         $ECHO "copying selected object files to avoid basename conflicts..."
+         echo "copying selected object files to avoid basename conflicts..."
          gentop="$output_objdir/${outputname}x"
-         generated="$generated $gentop"
+         func_append generated " $gentop"
          func_mkdir_p "$gentop"
          save_oldobjs=$oldobjs
          oldobjs=
@@ -7958,18 +9168,30 @@ EOF
                esac
              done
              func_show_eval "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj"
-             oldobjs="$oldobjs $gentop/$newobj"
+             func_append oldobjs " $gentop/$newobj"
              ;;
-           *) oldobjs="$oldobjs $obj" ;;
+           *) func_append oldobjs " $obj" ;;
            esac
          done
        fi
+       func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
+       tool_oldlib=$func_to_tool_file_result
        eval cmds=\"$old_archive_cmds\"
 
        func_len " $cmds"
        len=$func_len_result
        if test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
          cmds=$old_archive_cmds
+       elif test -n "$archiver_list_spec"; then
+         func_verbose "using command file archive linking..."
+         for obj in $oldobjs
+         do
+           func_to_tool_file "$obj"
+           $ECHO "$func_to_tool_file_result"
+         done > $output_objdir/$libname.libcmd
+         func_to_tool_file "$output_objdir/$libname.libcmd"
+         oldobjs=" $archiver_list_spec$func_to_tool_file_result"
+         cmds=$old_archive_cmds
        else
          # the command line is too long to link in one step, link in parts
          func_verbose "using piecewise archive linking..."
@@ -8043,7 +9265,7 @@ EOF
       done
       # Quote the link command for shipping.
       relink_command="(cd `pwd`; $SHELL $progpath $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)"
-      relink_command=`$ECHO "X$relink_command" | $Xsed -e "$sed_quote_subst"`
+      relink_command=`$ECHO "$relink_command" | $SED "$sed_quote_subst"`
       if test "$hardcode_automatic" = yes ; then
        relink_command=
       fi
@@ -8063,12 +9285,23 @@ EOF
              *.la)
                func_basename "$deplib"
                name="$func_basename_result"
-               eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $deplib`
+               func_resolve_sysroot "$deplib"
+               eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $func_resolve_sysroot_result`
                test -z "$libdir" && \
                  func_fatal_error "\`$deplib' is not a valid libtool archive"
-               newdependency_libs="$newdependency_libs $libdir/$name"
+               func_append newdependency_libs " ${lt_sysroot:+=}$libdir/$name"
+               ;;
+             -L*)
+               func_stripname -L '' "$deplib"
+               func_replace_sysroot "$func_stripname_result"
+               func_append newdependency_libs " -L$func_replace_sysroot_result"
                ;;
-             *) newdependency_libs="$newdependency_libs $deplib" ;;
+             -R*)
+               func_stripname -R '' "$deplib"
+               func_replace_sysroot "$func_stripname_result"
+               func_append newdependency_libs " -R$func_replace_sysroot_result"
+               ;;
+             *) func_append newdependency_libs " $deplib" ;;
              esac
            done
            dependency_libs="$newdependency_libs"
@@ -8082,9 +9315,9 @@ EOF
                eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
                test -z "$libdir" && \
                  func_fatal_error "\`$lib' is not a valid libtool archive"
-               newdlfiles="$newdlfiles $libdir/$name"
+               func_append newdlfiles " ${lt_sysroot:+=}$libdir/$name"
                ;;
-             *) newdlfiles="$newdlfiles $lib" ;;
+             *) func_append newdlfiles " $lib" ;;
              esac
            done
            dlfiles="$newdlfiles"
@@ -8101,7 +9334,7 @@ EOF
                eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
                test -z "$libdir" && \
                  func_fatal_error "\`$lib' is not a valid libtool archive"
-               newdlprefiles="$newdlprefiles $libdir/$name"
+               func_append newdlprefiles " ${lt_sysroot:+=}$libdir/$name"
                ;;
              esac
            done
@@ -8113,7 +9346,7 @@ EOF
                [\\/]* | [A-Za-z]:[\\/]*) abs="$lib" ;;
                *) abs=`pwd`"/$lib" ;;
              esac
-             newdlfiles="$newdlfiles $abs"
+             func_append newdlfiles " $abs"
            done
            dlfiles="$newdlfiles"
            newdlprefiles=
@@ -8122,15 +9355,33 @@ EOF
                [\\/]* | [A-Za-z]:[\\/]*) abs="$lib" ;;
                *) abs=`pwd`"/$lib" ;;
              esac
-             newdlprefiles="$newdlprefiles $abs"
+             func_append newdlprefiles " $abs"
            done
            dlprefiles="$newdlprefiles"
          fi
          $RM $output
          # place dlname in correct position for cygwin
+         # In fact, it would be nice if we could use this code for all target
+         # systems that can't hard-code library paths into their executables
+         # and that have no shared library path variable independent of PATH,
+         # but it turns out we can't easily determine that from inspecting
+         # libtool variables, so we have to hard-code the OSs to which it
+         # applies here; at the moment, that means platforms that use the PE
+         # object format with DLL files.  See the long comment at the top of
+         # tests/bindir.at for full details.
          tdlname=$dlname
          case $host,$output,$installed,$module,$dlname in
-           *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll) tdlname=../bin/$dlname ;;
+           *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll)
+             # If a -bindir argument was supplied, place the dll there.
+             if test "x$bindir" != x ;
+             then
+               func_relative_path "$install_libdir" "$bindir"
+               tdlname=$func_relative_path_result$dlname
+             else
+               # Otherwise fall back on heuristic.
+               tdlname=../bin/$dlname
+             fi
+             ;;
          esac
          $ECHO > $output "\
 # $outputname - a libtool library file
@@ -8189,7 +9440,7 @@ relink_command=\"$relink_command\""
     exit $EXIT_SUCCESS
 }
 
-{ test "$mode" = link || test "$mode" = relink; } &&
+{ test "$opt_mode" = link || test "$opt_mode" = relink; } &&
     func_mode_link ${1+"$@"}
 
 
@@ -8209,9 +9460,9 @@ func_mode_uninstall ()
     for arg
     do
       case $arg in
-      -f) RM="$RM $arg"; rmforce=yes ;;
-      -*) RM="$RM $arg" ;;
-      *) files="$files $arg" ;;
+      -f) func_append RM " $arg"; rmforce=yes ;;
+      -*) func_append RM " $arg" ;;
+      *) func_append files " $arg" ;;
       esac
     done
 
@@ -8220,24 +9471,23 @@ func_mode_uninstall ()
 
     rmdirs=
 
-    origobjdir="$objdir"
     for file in $files; do
       func_dirname "$file" "" "."
       dir="$func_dirname_result"
       if test "X$dir" = X.; then
-       objdir="$origobjdir"
+       odir="$objdir"
       else
-       objdir="$dir/$origobjdir"
+       odir="$dir/$objdir"
       fi
       func_basename "$file"
       name="$func_basename_result"
-      test "$mode" = uninstall && objdir="$dir"
+      test "$opt_mode" = uninstall && odir="$dir"
 
-      # Remember objdir for removal later, being careful to avoid duplicates
-      if test "$mode" = clean; then
+      # Remember odir for removal later, being careful to avoid duplicates
+      if test "$opt_mode" = clean; then
        case " $rmdirs " in
-         *" $objdir "*) ;;
-         *) rmdirs="$rmdirs $objdir" ;;
+         *" $odir "*) ;;
+         *) func_append rmdirs " $odir" ;;
        esac
       fi
 
@@ -8263,18 +9513,17 @@ func_mode_uninstall ()
 
          # Delete the libtool libraries and symlinks.
          for n in $library_names; do
-           rmfiles="$rmfiles $objdir/$n"
+           func_append rmfiles " $odir/$n"
          done
-         test -n "$old_library" && rmfiles="$rmfiles $objdir/$old_library"
+         test -n "$old_library" && func_append rmfiles " $odir/$old_library"
 
-         case "$mode" in
+         case "$opt_mode" in
          clean)
-           case "  $library_names " in
-           # "  " in the beginning catches empty $dlname
+           case " $library_names " in
            *" $dlname "*) ;;
-           *) rmfiles="$rmfiles $objdir/$dlname" ;;
+           *) test -n "$dlname" && func_append rmfiles " $odir/$dlname" ;;
            esac
-           test -n "$libdir" && rmfiles="$rmfiles $objdir/$name $objdir/${name}i"
+           test -n "$libdir" && func_append rmfiles " $odir/$name $odir/${name}i"
            ;;
          uninstall)
            if test -n "$library_names"; then
@@ -8302,19 +9551,19 @@ func_mode_uninstall ()
          # Add PIC object to the list of files to remove.
          if test -n "$pic_object" &&
             test "$pic_object" != none; then
-           rmfiles="$rmfiles $dir/$pic_object"
+           func_append rmfiles " $dir/$pic_object"
          fi
 
          # Add non-PIC object to the list of files to remove.
          if test -n "$non_pic_object" &&
             test "$non_pic_object" != none; then
-           rmfiles="$rmfiles $dir/$non_pic_object"
+           func_append rmfiles " $dir/$non_pic_object"
          fi
        fi
        ;;
 
       *)
-       if test "$mode" = clean ; then
+       if test "$opt_mode" = clean ; then
          noexename=$name
          case $file in
          *.exe)
@@ -8324,7 +9573,7 @@ func_mode_uninstall ()
            noexename=$func_stripname_result
            # $file with .exe has already been added to rmfiles,
            # add $file without .exe
-           rmfiles="$rmfiles $file"
+           func_append rmfiles " $file"
            ;;
          esac
          # Do a test to see if this is a libtool program.
@@ -8333,7 +9582,7 @@ func_mode_uninstall ()
              func_ltwrapper_scriptname "$file"
              relink_command=
              func_source $func_ltwrapper_scriptname_result
-             rmfiles="$rmfiles $func_ltwrapper_scriptname_result"
+             func_append rmfiles " $func_ltwrapper_scriptname_result"
            else
              relink_command=
              func_source $dir/$noexename
@@ -8341,12 +9590,12 @@ func_mode_uninstall ()
 
            # note $name still contains .exe if it was in $file originally
            # as does the version of $file that was added into $rmfiles
-           rmfiles="$rmfiles $objdir/$name $objdir/${name}S.${objext}"
+           func_append rmfiles " $odir/$name $odir/${name}S.${objext}"
            if test "$fast_install" = yes && test -n "$relink_command"; then
-             rmfiles="$rmfiles $objdir/lt-$name"
+             func_append rmfiles " $odir/lt-$name"
            fi
            if test "X$noexename" != "X$name" ; then
-             rmfiles="$rmfiles $objdir/lt-${noexename}.c"
+             func_append rmfiles " $odir/lt-${noexename}.c"
            fi
          fi
        fi
@@ -8354,7 +9603,6 @@ func_mode_uninstall ()
       esac
       func_show_eval "$RM $rmfiles" 'exit_status=1'
     done
-    objdir="$origobjdir"
 
     # Try to remove the ${objdir}s in the directories where we deleted files
     for dir in $rmdirs; do
@@ -8366,16 +9614,16 @@ func_mode_uninstall ()
     exit $exit_status
 }
 
-{ test "$mode" = uninstall || test "$mode" = clean; } &&
+{ test "$opt_mode" = uninstall || test "$opt_mode" = clean; } &&
     func_mode_uninstall ${1+"$@"}
 
-test -z "$mode" && {
+test -z "$opt_mode" && {
   help="$generic_help"
   func_fatal_help "you must specify a MODE"
 }
 
 test -z "$exec_cmd" && \
-  func_fatal_help "invalid operation mode \`$mode'"
+  func_fatal_help "invalid operation mode \`$opt_mode'"
 
 if test -n "$exec_cmd"; then
   eval exec "$exec_cmd"
diff --git a/m4/libtool.m4 b/m4/libtool.m4
deleted file mode 100644 (file)
index a3fee53..0000000
+++ /dev/null
@@ -1,7377 +0,0 @@
-# libtool.m4 - Configure libtool for the host system. -*-Autoconf-*-
-#
-#   Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005,
-#                 2006, 2007, 2008 Free Software Foundation, Inc.
-#   Written by Gordon Matzigkeit, 1996
-#
-# This file is free software; the Free Software Foundation gives
-# unlimited permission to copy and/or distribute it, with or without
-# modifications, as long as this notice is preserved.
-
-m4_define([_LT_COPYING], [dnl
-#   Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005,
-#                 2006, 2007, 2008 Free Software Foundation, Inc.
-#   Written by Gordon Matzigkeit, 1996
-#
-#   This file is part of GNU Libtool.
-#
-# GNU Libtool is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; either version 2 of
-# the License, or (at your option) any later version.
-#
-# As a special exception to the GNU General Public License,
-# if you distribute this file as part of a program or library that
-# is built using GNU Libtool, you may include this file under the
-# same distribution terms that you use for the rest of that program.
-#
-# GNU Libtool is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with GNU Libtool; see the file COPYING.  If not, a copy
-# can be downloaded from http://www.gnu.org/licenses/gpl.html, or
-# obtained by writing to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-])
-
-# serial 56 LT_INIT
-
-
-# LT_PREREQ(VERSION)
-# ------------------
-# Complain and exit if this libtool version is less that VERSION.
-m4_defun([LT_PREREQ],
-[m4_if(m4_version_compare(m4_defn([LT_PACKAGE_VERSION]), [$1]), -1,
-       [m4_default([$3],
-                  [m4_fatal([Libtool version $1 or higher is required],
-                            63)])],
-       [$2])])
-
-
-# _LT_CHECK_BUILDDIR
-# ------------------
-# Complain if the absolute build directory name contains unusual characters
-m4_defun([_LT_CHECK_BUILDDIR],
-[case `pwd` in
-  *\ * | *\    *)
-    AC_MSG_WARN([Libtool does not cope well with whitespace in `pwd`]) ;;
-esac
-])
-
-
-# LT_INIT([OPTIONS])
-# ------------------
-AC_DEFUN([LT_INIT],
-[AC_PREREQ([2.58])dnl We use AC_INCLUDES_DEFAULT
-AC_BEFORE([$0], [LT_LANG])dnl
-AC_BEFORE([$0], [LT_OUTPUT])dnl
-AC_BEFORE([$0], [LTDL_INIT])dnl
-m4_require([_LT_CHECK_BUILDDIR])dnl
-
-dnl Autoconf doesn't catch unexpanded LT_ macros by default:
-m4_pattern_forbid([^_?LT_[A-Z_]+$])dnl
-m4_pattern_allow([^(_LT_EOF|LT_DLGLOBAL|LT_DLLAZY_OR_NOW|LT_MULTI_MODULE)$])dnl
-dnl aclocal doesn't pull ltoptions.m4, ltsugar.m4, or ltversion.m4
-dnl unless we require an AC_DEFUNed macro:
-AC_REQUIRE([LTOPTIONS_VERSION])dnl
-AC_REQUIRE([LTSUGAR_VERSION])dnl
-AC_REQUIRE([LTVERSION_VERSION])dnl
-AC_REQUIRE([LTOBSOLETE_VERSION])dnl
-m4_require([_LT_PROG_LTMAIN])dnl
-
-dnl Parse OPTIONS
-_LT_SET_OPTIONS([$0], [$1])
-
-# This can be used to rebuild libtool when needed
-LIBTOOL_DEPS="$ltmain"
-
-# Always use our own libtool.
-LIBTOOL='$(SHELL) $(top_builddir)/libtool'
-AC_SUBST(LIBTOOL)dnl
-
-_LT_SETUP
-
-# Only expand once:
-m4_define([LT_INIT])
-])# LT_INIT
-
-# Old names:
-AU_ALIAS([AC_PROG_LIBTOOL], [LT_INIT])
-AU_ALIAS([AM_PROG_LIBTOOL], [LT_INIT])
-dnl aclocal-1.4 backwards compatibility:
-dnl AC_DEFUN([AC_PROG_LIBTOOL], [])
-dnl AC_DEFUN([AM_PROG_LIBTOOL], [])
-
-
-# _LT_CC_BASENAME(CC)
-# -------------------
-# Calculate cc_basename.  Skip known compiler wrappers and cross-prefix.
-m4_defun([_LT_CC_BASENAME],
-[for cc_temp in $1""; do
-  case $cc_temp in
-    compile | *[[\\/]]compile | ccache | *[[\\/]]ccache ) ;;
-    distcc | *[[\\/]]distcc | purify | *[[\\/]]purify ) ;;
-    \-*) ;;
-    *) break;;
-  esac
-done
-cc_basename=`$ECHO "X$cc_temp" | $Xsed -e 's%.*/%%' -e "s%^$host_alias-%%"`
-])
-
-
-# _LT_FILEUTILS_DEFAULTS
-# ----------------------
-# It is okay to use these file commands and assume they have been set
-# sensibly after `m4_require([_LT_FILEUTILS_DEFAULTS])'.
-m4_defun([_LT_FILEUTILS_DEFAULTS],
-[: ${CP="cp -f"}
-: ${MV="mv -f"}
-: ${RM="rm -f"}
-])# _LT_FILEUTILS_DEFAULTS
-
-
-# _LT_SETUP
-# ---------
-m4_defun([_LT_SETUP],
-[AC_REQUIRE([AC_CANONICAL_HOST])dnl
-AC_REQUIRE([AC_CANONICAL_BUILD])dnl
-_LT_DECL([], [host_alias], [0], [The host system])dnl
-_LT_DECL([], [host], [0])dnl
-_LT_DECL([], [host_os], [0])dnl
-dnl
-_LT_DECL([], [build_alias], [0], [The build system])dnl
-_LT_DECL([], [build], [0])dnl
-_LT_DECL([], [build_os], [0])dnl
-dnl
-AC_REQUIRE([AC_PROG_CC])dnl
-AC_REQUIRE([LT_PATH_LD])dnl
-AC_REQUIRE([LT_PATH_NM])dnl
-dnl
-AC_REQUIRE([AC_PROG_LN_S])dnl
-test -z "$LN_S" && LN_S="ln -s"
-_LT_DECL([], [LN_S], [1], [Whether we need soft or hard links])dnl
-dnl
-AC_REQUIRE([LT_CMD_MAX_LEN])dnl
-_LT_DECL([objext], [ac_objext], [0], [Object file suffix (normally "o")])dnl
-_LT_DECL([], [exeext], [0], [Executable file suffix (normally "")])dnl
-dnl
-m4_require([_LT_FILEUTILS_DEFAULTS])dnl
-m4_require([_LT_CHECK_SHELL_FEATURES])dnl
-m4_require([_LT_CMD_RELOAD])dnl
-m4_require([_LT_CHECK_MAGIC_METHOD])dnl
-m4_require([_LT_CMD_OLD_ARCHIVE])dnl
-m4_require([_LT_CMD_GLOBAL_SYMBOLS])dnl
-
-_LT_CONFIG_LIBTOOL_INIT([
-# See if we are running on zsh, and set the options which allow our
-# commands through without removal of \ escapes INIT.
-if test -n "\${ZSH_VERSION+set}" ; then
-   setopt NO_GLOB_SUBST
-fi
-])
-if test -n "${ZSH_VERSION+set}" ; then
-   setopt NO_GLOB_SUBST
-fi
-
-_LT_CHECK_OBJDIR
-
-m4_require([_LT_TAG_COMPILER])dnl
-_LT_PROG_ECHO_BACKSLASH
-
-case $host_os in
-aix3*)
-  # AIX sometimes has problems with the GCC collect2 program.  For some
-  # reason, if we set the COLLECT_NAMES environment variable, the problems
-  # vanish in a puff of smoke.
-  if test "X${COLLECT_NAMES+set}" != Xset; then
-    COLLECT_NAMES=
-    export COLLECT_NAMES
-  fi
-  ;;
-esac
-
-# Sed substitution that helps us do robust quoting.  It backslashifies
-# metacharacters that are still active within double-quoted strings.
-sed_quote_subst='s/\([["`$\\]]\)/\\\1/g'
-
-# Same as above, but do not quote variable references.
-double_quote_subst='s/\([["`\\]]\)/\\\1/g'
-
-# Sed substitution to delay expansion of an escaped shell variable in a
-# double_quote_subst'ed string.
-delay_variable_subst='s/\\\\\\\\\\\$/\\\\\\$/g'
-
-# Sed substitution to delay expansion of an escaped single quote.
-delay_single_quote_subst='s/'\''/'\'\\\\\\\'\''/g'
-
-# Sed substitution to avoid accidental globbing in evaled expressions
-no_glob_subst='s/\*/\\\*/g'
-
-# Global variables:
-ofile=libtool
-can_build_shared=yes
-
-# All known linkers require a `.a' archive for static linking (except MSVC,
-# which needs '.lib').
-libext=a
-
-with_gnu_ld="$lt_cv_prog_gnu_ld"
-
-old_CC="$CC"
-old_CFLAGS="$CFLAGS"
-
-# Set sane defaults for various variables
-test -z "$CC" && CC=cc
-test -z "$LTCC" && LTCC=$CC
-test -z "$LTCFLAGS" && LTCFLAGS=$CFLAGS
-test -z "$LD" && LD=ld
-test -z "$ac_objext" && ac_objext=o
-
-_LT_CC_BASENAME([$compiler])
-
-# Only perform the check for file, if the check method requires it
-test -z "$MAGIC_CMD" && MAGIC_CMD=file
-case $deplibs_check_method in
-file_magic*)
-  if test "$file_magic_cmd" = '$MAGIC_CMD'; then
-    _LT_PATH_MAGIC
-  fi
-  ;;
-esac
-
-# Use C for the default configuration in the libtool script
-LT_SUPPORTED_TAG([CC])
-_LT_LANG_C_CONFIG
-_LT_LANG_DEFAULT_CONFIG
-_LT_CONFIG_COMMANDS
-])# _LT_SETUP
-
-
-# _LT_PROG_LTMAIN
-# ---------------
-# Note that this code is called both from `configure', and `config.status'
-# now that we use AC_CONFIG_COMMANDS to generate libtool.  Notably,
-# `config.status' has no value for ac_aux_dir unless we are using Automake,
-# so we pass a copy along to make sure it has a sensible value anyway.
-m4_defun([_LT_PROG_LTMAIN],
-[m4_ifdef([AC_REQUIRE_AUX_FILE], [AC_REQUIRE_AUX_FILE([ltmain.sh])])dnl
-_LT_CONFIG_LIBTOOL_INIT([ac_aux_dir='$ac_aux_dir'])
-ltmain="$ac_aux_dir/ltmain.sh"
-])# _LT_PROG_LTMAIN
-
-
-## ------------------------------------- ##
-## Accumulate code for creating libtool. ##
-## ------------------------------------- ##
-
-# So that we can recreate a full libtool script including additional
-# tags, we accumulate the chunks of code to send to AC_CONFIG_COMMANDS
-# in macros and then make a single call at the end using the `libtool'
-# label.
-
-
-# _LT_CONFIG_LIBTOOL_INIT([INIT-COMMANDS])
-# ----------------------------------------
-# Register INIT-COMMANDS to be passed to AC_CONFIG_COMMANDS later.
-m4_define([_LT_CONFIG_LIBTOOL_INIT],
-[m4_ifval([$1],
-          [m4_append([_LT_OUTPUT_LIBTOOL_INIT],
-                     [$1
-])])])
-
-# Initialize.
-m4_define([_LT_OUTPUT_LIBTOOL_INIT])
-
-
-# _LT_CONFIG_LIBTOOL([COMMANDS])
-# ------------------------------
-# Register COMMANDS to be passed to AC_CONFIG_COMMANDS later.
-m4_define([_LT_CONFIG_LIBTOOL],
-[m4_ifval([$1],
-          [m4_append([_LT_OUTPUT_LIBTOOL_COMMANDS],
-                     [$1
-])])])
-
-# Initialize.
-m4_define([_LT_OUTPUT_LIBTOOL_COMMANDS])
-
-
-# _LT_CONFIG_SAVE_COMMANDS([COMMANDS], [INIT_COMMANDS])
-# -----------------------------------------------------
-m4_defun([_LT_CONFIG_SAVE_COMMANDS],
-[_LT_CONFIG_LIBTOOL([$1])
-_LT_CONFIG_LIBTOOL_INIT([$2])
-])
-
-
-# _LT_FORMAT_COMMENT([COMMENT])
-# -----------------------------
-# Add leading comment marks to the start of each line, and a trailing
-# full-stop to the whole comment if one is not present already.
-m4_define([_LT_FORMAT_COMMENT],
-[m4_ifval([$1], [
-m4_bpatsubst([m4_bpatsubst([$1], [^ *], [# ])],
-              [['`$\]], [\\\&])]m4_bmatch([$1], [[!?.]$], [], [.])
-)])
-
-
-
-## ------------------------ ##
-## FIXME: Eliminate VARNAME ##
-## ------------------------ ##
-
-
-# _LT_DECL([CONFIGNAME], VARNAME, VALUE, [DESCRIPTION], [IS-TAGGED?])
-# -------------------------------------------------------------------
-# CONFIGNAME is the name given to the value in the libtool script.
-# VARNAME is the (base) name used in the configure script.
-# VALUE may be 0, 1 or 2 for a computed quote escaped value based on
-# VARNAME.  Any other value will be used directly.
-m4_define([_LT_DECL],
-[lt_if_append_uniq([lt_decl_varnames], [$2], [, ],
-    [lt_dict_add_subkey([lt_decl_dict], [$2], [libtool_name],
-       [m4_ifval([$1], [$1], [$2])])
-    lt_dict_add_subkey([lt_decl_dict], [$2], [value], [$3])
-    m4_ifval([$4],
-       [lt_dict_add_subkey([lt_decl_dict], [$2], [description], [$4])])
-    lt_dict_add_subkey([lt_decl_dict], [$2],
-       [tagged?], [m4_ifval([$5], [yes], [no])])])
-])
-
-
-# _LT_TAGDECL([CONFIGNAME], VARNAME, VALUE, [DESCRIPTION])
-# --------------------------------------------------------
-m4_define([_LT_TAGDECL], [_LT_DECL([$1], [$2], [$3], [$4], [yes])])
-
-
-# lt_decl_tag_varnames([SEPARATOR], [VARNAME1...])
-# ------------------------------------------------
-m4_define([lt_decl_tag_varnames],
-[_lt_decl_filter([tagged?], [yes], $@)])
-
-
-# _lt_decl_filter(SUBKEY, VALUE, [SEPARATOR], [VARNAME1..])
-# ---------------------------------------------------------
-m4_define([_lt_decl_filter],
-[m4_case([$#],
-  [0], [m4_fatal([$0: too few arguments: $#])],
-  [1], [m4_fatal([$0: too few arguments: $#: $1])],
-  [2], [lt_dict_filter([lt_decl_dict], [$1], [$2], [], lt_decl_varnames)],
-  [3], [lt_dict_filter([lt_decl_dict], [$1], [$2], [$3], lt_decl_varnames)],
-  [lt_dict_filter([lt_decl_dict], $@)])[]dnl
-])
-
-
-# lt_decl_quote_varnames([SEPARATOR], [VARNAME1...])
-# --------------------------------------------------
-m4_define([lt_decl_quote_varnames],
-[_lt_decl_filter([value], [1], $@)])
-
-
-# lt_decl_dquote_varnames([SEPARATOR], [VARNAME1...])
-# ---------------------------------------------------
-m4_define([lt_decl_dquote_varnames],
-[_lt_decl_filter([value], [2], $@)])
-
-
-# lt_decl_varnames_tagged([SEPARATOR], [VARNAME1...])
-# ---------------------------------------------------
-m4_define([lt_decl_varnames_tagged],
-[m4_assert([$# <= 2])dnl
-_$0(m4_quote(m4_default([$1], [[, ]])),
-    m4_ifval([$2], [[$2]], [m4_dquote(lt_decl_tag_varnames)]),
-    m4_split(m4_normalize(m4_quote(_LT_TAGS)), [ ]))])
-m4_define([_lt_decl_varnames_tagged],
-[m4_ifval([$3], [lt_combine([$1], [$2], [_], $3)])])
-
-
-# lt_decl_all_varnames([SEPARATOR], [VARNAME1...])
-# ------------------------------------------------
-m4_define([lt_decl_all_varnames],
-[_$0(m4_quote(m4_default([$1], [[, ]])),
-     m4_if([$2], [],
-          m4_quote(lt_decl_varnames),
-       m4_quote(m4_shift($@))))[]dnl
-])
-m4_define([_lt_decl_all_varnames],
-[lt_join($@, lt_decl_varnames_tagged([$1],
-                       lt_decl_tag_varnames([[, ]], m4_shift($@))))dnl
-])
-
-
-# _LT_CONFIG_STATUS_DECLARE([VARNAME])
-# ------------------------------------
-# Quote a variable value, and forward it to `config.status' so that its
-# declaration there will have the same value as in `configure'.  VARNAME
-# must have a single quote delimited value for this to work.
-m4_define([_LT_CONFIG_STATUS_DECLARE],
-[$1='`$ECHO "X$][$1" | $Xsed -e "$delay_single_quote_subst"`'])
-
-
-# _LT_CONFIG_STATUS_DECLARATIONS
-# ------------------------------
-# We delimit libtool config variables with single quotes, so when
-# we write them to config.status, we have to be sure to quote all
-# embedded single quotes properly.  In configure, this macro expands
-# each variable declared with _LT_DECL (and _LT_TAGDECL) into:
-#
-#    <var>='`$ECHO "X$<var>" | $Xsed -e "$delay_single_quote_subst"`'
-m4_defun([_LT_CONFIG_STATUS_DECLARATIONS],
-[m4_foreach([_lt_var], m4_quote(lt_decl_all_varnames),
-    [m4_n([_LT_CONFIG_STATUS_DECLARE(_lt_var)])])])
-
-
-# _LT_LIBTOOL_TAGS
-# ----------------
-# Output comment and list of tags supported by the script
-m4_defun([_LT_LIBTOOL_TAGS],
-[_LT_FORMAT_COMMENT([The names of the tagged configurations supported by this script])dnl
-available_tags="_LT_TAGS"dnl
-])
-
-
-# _LT_LIBTOOL_DECLARE(VARNAME, [TAG])
-# -----------------------------------
-# Extract the dictionary values for VARNAME (optionally with TAG) and
-# expand to a commented shell variable setting:
-#
-#    # Some comment about what VAR is for.
-#    visible_name=$lt_internal_name
-m4_define([_LT_LIBTOOL_DECLARE],
-[_LT_FORMAT_COMMENT(m4_quote(lt_dict_fetch([lt_decl_dict], [$1],
-                                          [description])))[]dnl
-m4_pushdef([_libtool_name],
-    m4_quote(lt_dict_fetch([lt_decl_dict], [$1], [libtool_name])))[]dnl
-m4_case(m4_quote(lt_dict_fetch([lt_decl_dict], [$1], [value])),
-    [0], [_libtool_name=[$]$1],
-    [1], [_libtool_name=$lt_[]$1],
-    [2], [_libtool_name=$lt_[]$1],
-    [_libtool_name=lt_dict_fetch([lt_decl_dict], [$1], [value])])[]dnl
-m4_ifval([$2], [_$2])[]m4_popdef([_libtool_name])[]dnl
-])
-
-
-# _LT_LIBTOOL_CONFIG_VARS
-# -----------------------
-# Produce commented declarations of non-tagged libtool config variables
-# suitable for insertion in the LIBTOOL CONFIG section of the `libtool'
-# script.  Tagged libtool config variables (even for the LIBTOOL CONFIG
-# section) are produced by _LT_LIBTOOL_TAG_VARS.
-m4_defun([_LT_LIBTOOL_CONFIG_VARS],
-[m4_foreach([_lt_var],
-    m4_quote(_lt_decl_filter([tagged?], [no], [], lt_decl_varnames)),
-    [m4_n([_LT_LIBTOOL_DECLARE(_lt_var)])])])
-
-
-# _LT_LIBTOOL_TAG_VARS(TAG)
-# -------------------------
-m4_define([_LT_LIBTOOL_TAG_VARS],
-[m4_foreach([_lt_var], m4_quote(lt_decl_tag_varnames),
-    [m4_n([_LT_LIBTOOL_DECLARE(_lt_var, [$1])])])])
-
-
-# _LT_TAGVAR(VARNAME, [TAGNAME])
-# ------------------------------
-m4_define([_LT_TAGVAR], [m4_ifval([$2], [$1_$2], [$1])])
-
-
-# _LT_CONFIG_COMMANDS
-# -------------------
-# Send accumulated output to $CONFIG_STATUS.  Thanks to the lists of
-# variables for single and double quote escaping we saved from calls
-# to _LT_DECL, we can put quote escaped variables declarations
-# into `config.status', and then the shell code to quote escape them in
-# for loops in `config.status'.  Finally, any additional code accumulated
-# from calls to _LT_CONFIG_LIBTOOL_INIT is expanded.
-m4_defun([_LT_CONFIG_COMMANDS],
-[AC_PROVIDE_IFELSE([LT_OUTPUT],
-       dnl If the libtool generation code has been placed in $CONFIG_LT,
-       dnl instead of duplicating it all over again into config.status,
-       dnl then we will have config.status run $CONFIG_LT later, so it
-       dnl needs to know what name is stored there:
-        [AC_CONFIG_COMMANDS([libtool],
-            [$SHELL $CONFIG_LT || AS_EXIT(1)], [CONFIG_LT='$CONFIG_LT'])],
-    dnl If the libtool generation code is destined for config.status,
-    dnl expand the accumulated commands and init code now:
-    [AC_CONFIG_COMMANDS([libtool],
-        [_LT_OUTPUT_LIBTOOL_COMMANDS], [_LT_OUTPUT_LIBTOOL_COMMANDS_INIT])])
-])#_LT_CONFIG_COMMANDS
-
-
-# Initialize.
-m4_define([_LT_OUTPUT_LIBTOOL_COMMANDS_INIT],
-[
-
-# The HP-UX ksh and POSIX shell print the target directory to stdout
-# if CDPATH is set.
-(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
-
-sed_quote_subst='$sed_quote_subst'
-double_quote_subst='$double_quote_subst'
-delay_variable_subst='$delay_variable_subst'
-_LT_CONFIG_STATUS_DECLARATIONS
-LTCC='$LTCC'
-LTCFLAGS='$LTCFLAGS'
-compiler='$compiler_DEFAULT'
-
-# Quote evaled strings.
-for var in lt_decl_all_varnames([[ \
-]], lt_decl_quote_varnames); do
-    case \`eval \\\\\$ECHO "X\\\\\$\$var"\` in
-    *[[\\\\\\\`\\"\\\$]]*)
-      eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"X\\\$\$var\\" | \\\$Xsed -e \\"\\\$sed_quote_subst\\"\\\`\\\\\\""
-      ;;
-    *)
-      eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\""
-      ;;
-    esac
-done
-
-# Double-quote double-evaled strings.
-for var in lt_decl_all_varnames([[ \
-]], lt_decl_dquote_varnames); do
-    case \`eval \\\\\$ECHO "X\\\\\$\$var"\` in
-    *[[\\\\\\\`\\"\\\$]]*)
-      eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"X\\\$\$var\\" | \\\$Xsed -e \\"\\\$double_quote_subst\\" -e \\"\\\$sed_quote_subst\\" -e \\"\\\$delay_variable_subst\\"\\\`\\\\\\""
-      ;;
-    *)
-      eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\""
-      ;;
-    esac
-done
-
-# Fix-up fallback echo if it was mangled by the above quoting rules.
-case \$lt_ECHO in
-*'\\\[$]0 --fallback-echo"')dnl "
-  lt_ECHO=\`\$ECHO "X\$lt_ECHO" | \$Xsed -e 's/\\\\\\\\\\\\\\\[$]0 --fallback-echo"\[$]/\[$]0 --fallback-echo"/'\`
-  ;;
-esac
-
-_LT_OUTPUT_LIBTOOL_INIT
-])
-
-
-# LT_OUTPUT
-# ---------
-# This macro allows early generation of the libtool script (before
-# AC_OUTPUT is called), incase it is used in configure for compilation
-# tests.
-AC_DEFUN([LT_OUTPUT],
-[: ${CONFIG_LT=./config.lt}
-AC_MSG_NOTICE([creating $CONFIG_LT])
-cat >"$CONFIG_LT" <<_LTEOF
-#! $SHELL
-# Generated by $as_me.
-# Run this file to recreate a libtool stub with the current configuration.
-
-lt_cl_silent=false
-SHELL=\${CONFIG_SHELL-$SHELL}
-_LTEOF
-
-cat >>"$CONFIG_LT" <<\_LTEOF
-AS_SHELL_SANITIZE
-_AS_PREPARE
-
-exec AS_MESSAGE_FD>&1
-exec AS_MESSAGE_LOG_FD>>config.log
-{
-  echo
-  AS_BOX([Running $as_me.])
-} >&AS_MESSAGE_LOG_FD
-
-lt_cl_help="\
-\`$as_me' creates a local libtool stub from the current configuration,
-for use in further configure time tests before the real libtool is
-generated.
-
-Usage: $[0] [[OPTIONS]]
-
-  -h, --help      print this help, then exit
-  -V, --version   print version number, then exit
-  -q, --quiet     do not print progress messages
-  -d, --debug     don't remove temporary files
-
-Report bugs to <bug-libtool@gnu.org>."
-
-lt_cl_version="\
-m4_ifset([AC_PACKAGE_NAME], [AC_PACKAGE_NAME ])config.lt[]dnl
-m4_ifset([AC_PACKAGE_VERSION], [ AC_PACKAGE_VERSION])
-configured by $[0], generated by m4_PACKAGE_STRING.
-
-Copyright (C) 2008 Free Software Foundation, Inc.
-This config.lt script is free software; the Free Software Foundation
-gives unlimited permision to copy, distribute and modify it."
-
-while test $[#] != 0
-do
-  case $[1] in
-    --version | --v* | -V )
-      echo "$lt_cl_version"; exit 0 ;;
-    --help | --h* | -h )
-      echo "$lt_cl_help"; exit 0 ;;
-    --debug | --d* | -d )
-      debug=: ;;
-    --quiet | --q* | --silent | --s* | -q )
-      lt_cl_silent=: ;;
-
-    -*) AC_MSG_ERROR([unrecognized option: $[1]
-Try \`$[0] --help' for more information.]) ;;
-
-    *) AC_MSG_ERROR([unrecognized argument: $[1]
-Try \`$[0] --help' for more information.]) ;;
-  esac
-  shift
-done
-
-if $lt_cl_silent; then
-  exec AS_MESSAGE_FD>/dev/null
-fi
-_LTEOF
-
-cat >>"$CONFIG_LT" <<_LTEOF
-_LT_OUTPUT_LIBTOOL_COMMANDS_INIT
-_LTEOF
-
-cat >>"$CONFIG_LT" <<\_LTEOF
-AC_MSG_NOTICE([creating $ofile])
-_LT_OUTPUT_LIBTOOL_COMMANDS
-AS_EXIT(0)
-_LTEOF
-chmod +x "$CONFIG_LT"
-
-# configure is writing to config.log, but config.lt does its own redirection,
-# appending to config.log, which fails on DOS, as config.log is still kept
-# open by configure.  Here we exec the FD to /dev/null, effectively closing
-# config.log, so it can be properly (re)opened and appended to by config.lt.
-if test "$no_create" != yes; then
-  lt_cl_success=:
-  test "$silent" = yes &&
-    lt_config_lt_args="$lt_config_lt_args --quiet"
-  exec AS_MESSAGE_LOG_FD>/dev/null
-  $SHELL "$CONFIG_LT" $lt_config_lt_args || lt_cl_success=false
-  exec AS_MESSAGE_LOG_FD>>config.log
-  $lt_cl_success || AS_EXIT(1)
-fi
-])# LT_OUTPUT
-
-
-# _LT_CONFIG(TAG)
-# ---------------
-# If TAG is the built-in tag, create an initial libtool script with a
-# default configuration from the untagged config vars.  Otherwise add code
-# to config.status for appending the configuration named by TAG from the
-# matching tagged config vars.
-m4_defun([_LT_CONFIG],
-[m4_require([_LT_FILEUTILS_DEFAULTS])dnl
-_LT_CONFIG_SAVE_COMMANDS([
-  m4_define([_LT_TAG], m4_if([$1], [], [C], [$1]))dnl
-  m4_if(_LT_TAG, [C], [
-    # See if we are running on zsh, and set the options which allow our
-    # commands through without removal of \ escapes.
-    if test -n "${ZSH_VERSION+set}" ; then
-      setopt NO_GLOB_SUBST
-    fi
-
-    cfgfile="${ofile}T"
-    trap "$RM \"$cfgfile\"; exit 1" 1 2 15
-    $RM "$cfgfile"
-
-    cat <<_LT_EOF >> "$cfgfile"
-#! $SHELL
-
-# `$ECHO "$ofile" | sed 's%^.*/%%'` - Provide generalized library-building support services.
-# Generated automatically by $as_me ($PACKAGE$TIMESTAMP) $VERSION
-# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`:
-# NOTE: Changes made to this file will be lost: look at ltmain.sh.
-#
-_LT_COPYING
-_LT_LIBTOOL_TAGS
-
-# ### BEGIN LIBTOOL CONFIG
-_LT_LIBTOOL_CONFIG_VARS
-_LT_LIBTOOL_TAG_VARS
-# ### END LIBTOOL CONFIG
-
-_LT_EOF
-
-  case $host_os in
-  aix3*)
-    cat <<\_LT_EOF >> "$cfgfile"
-# AIX sometimes has problems with the GCC collect2 program.  For some
-# reason, if we set the COLLECT_NAMES environment variable, the problems
-# vanish in a puff of smoke.
-if test "X${COLLECT_NAMES+set}" != Xset; then
-  COLLECT_NAMES=
-  export COLLECT_NAMES
-fi
-_LT_EOF
-    ;;
-  esac
-
-  _LT_PROG_LTMAIN
-
-  # We use sed instead of cat because bash on DJGPP gets confused if
-  # if finds mixed CR/LF and LF-only lines.  Since sed operates in
-  # text mode, it properly converts lines to CR/LF.  This bash problem
-  # is reportedly fixed, but why not run on old versions too?
-  sed '/^# Generated shell functions inserted here/q' "$ltmain" >> "$cfgfile" \
-    || (rm -f "$cfgfile"; exit 1)
-
-  _LT_PROG_XSI_SHELLFNS
-
-  sed -n '/^# Generated shell functions inserted here/,$p' "$ltmain" >> "$cfgfile" \
-    || (rm -f "$cfgfile"; exit 1)
-
-  mv -f "$cfgfile" "$ofile" ||
-    (rm -f "$ofile" && cp "$cfgfile" "$ofile" && rm -f "$cfgfile")
-  chmod +x "$ofile"
-],
-[cat <<_LT_EOF >> "$ofile"
-
-dnl Unfortunately we have to use $1 here, since _LT_TAG is not expanded
-dnl in a comment (ie after a #).
-# ### BEGIN LIBTOOL TAG CONFIG: $1
-_LT_LIBTOOL_TAG_VARS(_LT_TAG)
-# ### END LIBTOOL TAG CONFIG: $1
-_LT_EOF
-])dnl /m4_if
-],
-[m4_if([$1], [], [
-    PACKAGE='$PACKAGE'
-    VERSION='$VERSION'
-    TIMESTAMP='$TIMESTAMP'
-    RM='$RM'
-    ofile='$ofile'], [])
-])dnl /_LT_CONFIG_SAVE_COMMANDS
-])# _LT_CONFIG
-
-
-# LT_SUPPORTED_TAG(TAG)
-# ---------------------
-# Trace this macro to discover what tags are supported by the libtool
-# --tag option, using:
-#    autoconf --trace 'LT_SUPPORTED_TAG:$1'
-AC_DEFUN([LT_SUPPORTED_TAG], [])
-
-
-# C support is built-in for now
-m4_define([_LT_LANG_C_enabled], [])
-m4_define([_LT_TAGS], [])
-
-
-# LT_LANG(LANG)
-# -------------
-# Enable libtool support for the given language if not already enabled.
-AC_DEFUN([LT_LANG],
-[AC_BEFORE([$0], [LT_OUTPUT])dnl
-m4_case([$1],
-  [C],                 [_LT_LANG(C)],
-  [C++],               [_LT_LANG(CXX)],
-  [Java],              [_LT_LANG(GCJ)],
-  [Fortran 77],                [_LT_LANG(F77)],
-  [Fortran],           [_LT_LANG(FC)],
-  [Windows Resource],  [_LT_LANG(RC)],
-  [m4_ifdef([_LT_LANG_]$1[_CONFIG],
-    [_LT_LANG($1)],
-    [m4_fatal([$0: unsupported language: "$1"])])])dnl
-])# LT_LANG
-
-
-# _LT_LANG(LANGNAME)
-# ------------------
-m4_defun([_LT_LANG],
-[m4_ifdef([_LT_LANG_]$1[_enabled], [],
-  [LT_SUPPORTED_TAG([$1])dnl
-  m4_append([_LT_TAGS], [$1 ])dnl
-  m4_define([_LT_LANG_]$1[_enabled], [])dnl
-  _LT_LANG_$1_CONFIG($1)])dnl
-])# _LT_LANG
-
-
-# _LT_LANG_DEFAULT_CONFIG
-# -----------------------
-m4_defun([_LT_LANG_DEFAULT_CONFIG],
-[AC_PROVIDE_IFELSE([AC_PROG_CXX],
-  [LT_LANG(CXX)],
-  [m4_define([AC_PROG_CXX], defn([AC_PROG_CXX])[LT_LANG(CXX)])])
-
-AC_PROVIDE_IFELSE([AC_PROG_F77],
-  [LT_LANG(F77)],
-  [m4_define([AC_PROG_F77], defn([AC_PROG_F77])[LT_LANG(F77)])])
-
-AC_PROVIDE_IFELSE([AC_PROG_FC],
-  [LT_LANG(FC)],
-  [m4_define([AC_PROG_FC], defn([AC_PROG_FC])[LT_LANG(FC)])])
-
-dnl The call to [A][M_PROG_GCJ] is quoted like that to stop aclocal
-dnl pulling things in needlessly.
-AC_PROVIDE_IFELSE([AC_PROG_GCJ],
-  [LT_LANG(GCJ)],
-  [AC_PROVIDE_IFELSE([A][M_PROG_GCJ],
-    [LT_LANG(GCJ)],
-    [AC_PROVIDE_IFELSE([LT_PROG_GCJ],
-      [LT_LANG(GCJ)],
-      [m4_ifdef([AC_PROG_GCJ],
-       [m4_define([AC_PROG_GCJ], defn([AC_PROG_GCJ])[LT_LANG(GCJ)])])
-       m4_ifdef([A][M_PROG_GCJ],
-       [m4_define([A][M_PROG_GCJ], defn([A][M_PROG_GCJ])[LT_LANG(GCJ)])])
-       m4_ifdef([LT_PROG_GCJ],
-       [m4_define([LT_PROG_GCJ], defn([LT_PROG_GCJ])[LT_LANG(GCJ)])])])])])
-
-AC_PROVIDE_IFELSE([LT_PROG_RC],
-  [LT_LANG(RC)],
-  [m4_define([LT_PROG_RC], defn([LT_PROG_RC])[LT_LANG(RC)])])
-])# _LT_LANG_DEFAULT_CONFIG
-
-# Obsolete macros:
-AU_DEFUN([AC_LIBTOOL_CXX], [LT_LANG(C++)])
-AU_DEFUN([AC_LIBTOOL_F77], [LT_LANG(Fortran 77)])
-AU_DEFUN([AC_LIBTOOL_FC], [LT_LANG(Fortran)])
-AU_DEFUN([AC_LIBTOOL_GCJ], [LT_LANG(Java)])
-dnl aclocal-1.4 backwards compatibility:
-dnl AC_DEFUN([AC_LIBTOOL_CXX], [])
-dnl AC_DEFUN([AC_LIBTOOL_F77], [])
-dnl AC_DEFUN([AC_LIBTOOL_FC], [])
-dnl AC_DEFUN([AC_LIBTOOL_GCJ], [])
-
-
-# _LT_TAG_COMPILER
-# ----------------
-m4_defun([_LT_TAG_COMPILER],
-[AC_REQUIRE([AC_PROG_CC])dnl
-
-_LT_DECL([LTCC], [CC], [1], [A C compiler])dnl
-_LT_DECL([LTCFLAGS], [CFLAGS], [1], [LTCC compiler flags])dnl
-_LT_TAGDECL([CC], [compiler], [1], [A language specific compiler])dnl
-_LT_TAGDECL([with_gcc], [GCC], [0], [Is the compiler the GNU compiler?])dnl
-
-# If no C compiler was specified, use CC.
-LTCC=${LTCC-"$CC"}
-
-# If no C compiler flags were specified, use CFLAGS.
-LTCFLAGS=${LTCFLAGS-"$CFLAGS"}
-
-# Allow CC to be a program name with arguments.
-compiler=$CC
-])# _LT_TAG_COMPILER
-
-
-# _LT_COMPILER_BOILERPLATE
-# ------------------------
-# Check for compiler boilerplate output or warnings with
-# the simple compiler test code.
-m4_defun([_LT_COMPILER_BOILERPLATE],
-[m4_require([_LT_DECL_SED])dnl
-ac_outfile=conftest.$ac_objext
-echo "$lt_simple_compile_test_code" >conftest.$ac_ext
-eval "$ac_compile" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err
-_lt_compiler_boilerplate=`cat conftest.err`
-$RM conftest*
-])# _LT_COMPILER_BOILERPLATE
-
-
-# _LT_LINKER_BOILERPLATE
-# ----------------------
-# Check for linker boilerplate output or warnings with
-# the simple link test code.
-m4_defun([_LT_LINKER_BOILERPLATE],
-[m4_require([_LT_DECL_SED])dnl
-ac_outfile=conftest.$ac_objext
-echo "$lt_simple_link_test_code" >conftest.$ac_ext
-eval "$ac_link" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err
-_lt_linker_boilerplate=`cat conftest.err`
-$RM -r conftest*
-])# _LT_LINKER_BOILERPLATE
-
-# _LT_REQUIRED_DARWIN_CHECKS
-# -------------------------
-m4_defun_once([_LT_REQUIRED_DARWIN_CHECKS],[
-  case $host_os in
-    rhapsody* | darwin*)
-    AC_CHECK_TOOL([DSYMUTIL], [dsymutil], [:])
-    AC_CHECK_TOOL([NMEDIT], [nmedit], [:])
-    AC_CHECK_TOOL([LIPO], [lipo], [:])
-    AC_CHECK_TOOL([OTOOL], [otool], [:])
-    AC_CHECK_TOOL([OTOOL64], [otool64], [:])
-    _LT_DECL([], [DSYMUTIL], [1],
-      [Tool to manipulate archived DWARF debug symbol files on Mac OS X])
-    _LT_DECL([], [NMEDIT], [1],
-      [Tool to change global to local symbols on Mac OS X])
-    _LT_DECL([], [LIPO], [1],
-      [Tool to manipulate fat objects and archives on Mac OS X])
-    _LT_DECL([], [OTOOL], [1],
-      [ldd/readelf like tool for Mach-O binaries on Mac OS X])
-    _LT_DECL([], [OTOOL64], [1],
-      [ldd/readelf like tool for 64 bit Mach-O binaries on Mac OS X 10.4])
-
-    AC_CACHE_CHECK([for -single_module linker flag],[lt_cv_apple_cc_single_mod],
-      [lt_cv_apple_cc_single_mod=no
-      if test -z "${LT_MULTI_MODULE}"; then
-       # By default we will add the -single_module flag. You can override
-       # by either setting the environment variable LT_MULTI_MODULE
-       # non-empty at configure time, or by adding -multi_module to the
-       # link flags.
-       rm -rf libconftest.dylib*
-       echo "int foo(void){return 1;}" > conftest.c
-       echo "$LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \
--dynamiclib -Wl,-single_module conftest.c" >&AS_MESSAGE_LOG_FD
-       $LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \
-         -dynamiclib -Wl,-single_module conftest.c 2>conftest.err
-        _lt_result=$?
-       if test -f libconftest.dylib && test ! -s conftest.err && test $_lt_result = 0; then
-         lt_cv_apple_cc_single_mod=yes
-       else
-         cat conftest.err >&AS_MESSAGE_LOG_FD
-       fi
-       rm -rf libconftest.dylib*
-       rm -f conftest.*
-      fi])
-    AC_CACHE_CHECK([for -exported_symbols_list linker flag],
-      [lt_cv_ld_exported_symbols_list],
-      [lt_cv_ld_exported_symbols_list=no
-      save_LDFLAGS=$LDFLAGS
-      echo "_main" > conftest.sym
-      LDFLAGS="$LDFLAGS -Wl,-exported_symbols_list,conftest.sym"
-      AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])],
-       [lt_cv_ld_exported_symbols_list=yes],
-       [lt_cv_ld_exported_symbols_list=no])
-       LDFLAGS="$save_LDFLAGS"
-    ])
-    case $host_os in
-    rhapsody* | darwin1.[[012]])
-      _lt_dar_allow_undefined='${wl}-undefined ${wl}suppress' ;;
-    darwin1.*)
-      _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;;
-    darwin*) # darwin 5.x on
-      # if running on 10.5 or later, the deployment target defaults
-      # to the OS version, if on x86, and 10.4, the deployment
-      # target defaults to 10.4. Don't you love it?
-      case ${MACOSX_DEPLOYMENT_TARGET-10.0},$host in
-       10.0,*86*-darwin8*|10.0,*-darwin[[91]]*)
-         _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;;
-       10.[[012]]*)
-         _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;;
-       10.*)
-         _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;;
-      esac
-    ;;
-  esac
-    if test "$lt_cv_apple_cc_single_mod" = "yes"; then
-      _lt_dar_single_mod='$single_module'
-    fi
-    if test "$lt_cv_ld_exported_symbols_list" = "yes"; then
-      _lt_dar_export_syms=' ${wl}-exported_symbols_list,$output_objdir/${libname}-symbols.expsym'
-    else
-      _lt_dar_export_syms='~$NMEDIT -s $output_objdir/${libname}-symbols.expsym ${lib}'
-    fi
-    if test "$DSYMUTIL" != ":"; then
-      _lt_dsymutil='~$DSYMUTIL $lib || :'
-    else
-      _lt_dsymutil=
-    fi
-    ;;
-  esac
-])
-
-
-# _LT_DARWIN_LINKER_FEATURES
-# --------------------------
-# Checks for linker and compiler features on darwin
-m4_defun([_LT_DARWIN_LINKER_FEATURES],
-[
-  m4_require([_LT_REQUIRED_DARWIN_CHECKS])
-  _LT_TAGVAR(archive_cmds_need_lc, $1)=no
-  _LT_TAGVAR(hardcode_direct, $1)=no
-  _LT_TAGVAR(hardcode_automatic, $1)=yes
-  _LT_TAGVAR(hardcode_shlibpath_var, $1)=unsupported
-  _LT_TAGVAR(whole_archive_flag_spec, $1)=''
-  _LT_TAGVAR(link_all_deplibs, $1)=yes
-  _LT_TAGVAR(allow_undefined_flag, $1)="$_lt_dar_allow_undefined"
-  case $cc_basename in
-     ifort*) _lt_dar_can_shared=yes ;;
-     *) _lt_dar_can_shared=$GCC ;;
-  esac
-  if test "$_lt_dar_can_shared" = "yes"; then
-    output_verbose_link_cmd=echo
-    _LT_TAGVAR(archive_cmds, $1)="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}"
-    _LT_TAGVAR(module_cmds, $1)="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}"
-    _LT_TAGVAR(archive_expsym_cmds, $1)="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}"
-    _LT_TAGVAR(module_expsym_cmds, $1)="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}"
-    m4_if([$1], [CXX],
-[   if test "$lt_cv_apple_cc_single_mod" != "yes"; then
-      _LT_TAGVAR(archive_cmds, $1)="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}"
-      _LT_TAGVAR(archive_expsym_cmds, $1)="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dar_export_syms}${_lt_dsymutil}"
-    fi
-],[])
-  else
-  _LT_TAGVAR(ld_shlibs, $1)=no
-  fi
-])
-
-# _LT_SYS_MODULE_PATH_AIX
-# -----------------------
-# Links a minimal program and checks the executable
-# for the system default hardcoded library path. In most cases,
-# this is /usr/lib:/lib, but when the MPI compilers are used
-# the location of the communication and MPI libs are included too.
-# If we don't find anything, use the default library path according
-# to the aix ld manual.
-m4_defun([_LT_SYS_MODULE_PATH_AIX],
-[m4_require([_LT_DECL_SED])dnl
-AC_LINK_IFELSE(AC_LANG_PROGRAM,[
-lt_aix_libpath_sed='
-    /Import File Strings/,/^$/ {
-       /^0/ {
-           s/^0  *\(.*\)$/\1/
-           p
-       }
-    }'
-aix_libpath=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
-# Check for a 64-bit object if we didn't find anything.
-if test -z "$aix_libpath"; then
-  aix_libpath=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
-fi],[])
-if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi
-])# _LT_SYS_MODULE_PATH_AIX
-
-
-# _LT_SHELL_INIT(ARG)
-# -------------------
-m4_define([_LT_SHELL_INIT],
-[ifdef([AC_DIVERSION_NOTICE],
-            [AC_DIVERT_PUSH(AC_DIVERSION_NOTICE)],
-        [AC_DIVERT_PUSH(NOTICE)])
-$1
-AC_DIVERT_POP
-])# _LT_SHELL_INIT
-
-
-# _LT_PROG_ECHO_BACKSLASH
-# -----------------------
-# Add some code to the start of the generated configure script which
-# will find an echo command which doesn't interpret backslashes.
-m4_defun([_LT_PROG_ECHO_BACKSLASH],
-[_LT_SHELL_INIT([
-# Check that we are running under the correct shell.
-SHELL=${CONFIG_SHELL-/bin/sh}
-
-case X$lt_ECHO in
-X*--fallback-echo)
-  # Remove one level of quotation (which was required for Make).
-  ECHO=`echo "$lt_ECHO" | sed 's,\\\\\[$]\\[$]0,'[$]0','`
-  ;;
-esac
-
-ECHO=${lt_ECHO-echo}
-if test "X[$]1" = X--no-reexec; then
-  # Discard the --no-reexec flag, and continue.
-  shift
-elif test "X[$]1" = X--fallback-echo; then
-  # Avoid inline document here, it may be left over
-  :
-elif test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t' ; then
-  # Yippee, $ECHO works!
-  :
-else
-  # Restart under the correct shell.
-  exec $SHELL "[$]0" --no-reexec ${1+"[$]@"}
-fi
-
-if test "X[$]1" = X--fallback-echo; then
-  # used as fallback echo
-  shift
-  cat <<_LT_EOF
-[$]*
-_LT_EOF
-  exit 0
-fi
-
-# The HP-UX ksh and POSIX shell print the target directory to stdout
-# if CDPATH is set.
-(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
-
-if test -z "$lt_ECHO"; then
-  if test "X${echo_test_string+set}" != Xset; then
-    # find a string as large as possible, as long as the shell can cope with it
-    for cmd in 'sed 50q "[$]0"' 'sed 20q "[$]0"' 'sed 10q "[$]0"' 'sed 2q "[$]0"' 'echo test'; do
-      # expected sizes: less than 2Kb, 1Kb, 512 bytes, 16 bytes, ...
-      if { echo_test_string=`eval $cmd`; } 2>/dev/null &&
-        { test "X$echo_test_string" = "X$echo_test_string"; } 2>/dev/null
-      then
-        break
-      fi
-    done
-  fi
-
-  if test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t' &&
-     echo_testing_string=`{ $ECHO "$echo_test_string"; } 2>/dev/null` &&
-     test "X$echo_testing_string" = "X$echo_test_string"; then
-    :
-  else
-    # The Solaris, AIX, and Digital Unix default echo programs unquote
-    # backslashes.  This makes it impossible to quote backslashes using
-    #   echo "$something" | sed 's/\\/\\\\/g'
-    #
-    # So, first we look for a working echo in the user's PATH.
-
-    lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
-    for dir in $PATH /usr/ucb; do
-      IFS="$lt_save_ifs"
-      if (test -f $dir/echo || test -f $dir/echo$ac_exeext) &&
-         test "X`($dir/echo '\t') 2>/dev/null`" = 'X\t' &&
-         echo_testing_string=`($dir/echo "$echo_test_string") 2>/dev/null` &&
-         test "X$echo_testing_string" = "X$echo_test_string"; then
-        ECHO="$dir/echo"
-        break
-      fi
-    done
-    IFS="$lt_save_ifs"
-
-    if test "X$ECHO" = Xecho; then
-      # We didn't find a better echo, so look for alternatives.
-      if test "X`{ print -r '\t'; } 2>/dev/null`" = 'X\t' &&
-         echo_testing_string=`{ print -r "$echo_test_string"; } 2>/dev/null` &&
-         test "X$echo_testing_string" = "X$echo_test_string"; then
-        # This shell has a builtin print -r that does the trick.
-        ECHO='print -r'
-      elif { test -f /bin/ksh || test -f /bin/ksh$ac_exeext; } &&
-          test "X$CONFIG_SHELL" != X/bin/ksh; then
-        # If we have ksh, try running configure again with it.
-        ORIGINAL_CONFIG_SHELL=${CONFIG_SHELL-/bin/sh}
-        export ORIGINAL_CONFIG_SHELL
-        CONFIG_SHELL=/bin/ksh
-        export CONFIG_SHELL
-        exec $CONFIG_SHELL "[$]0" --no-reexec ${1+"[$]@"}
-      else
-        # Try using printf.
-        ECHO='printf %s\n'
-        if test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t' &&
-          echo_testing_string=`{ $ECHO "$echo_test_string"; } 2>/dev/null` &&
-          test "X$echo_testing_string" = "X$echo_test_string"; then
-         # Cool, printf works
-         :
-        elif echo_testing_string=`($ORIGINAL_CONFIG_SHELL "[$]0" --fallback-echo '\t') 2>/dev/null` &&
-            test "X$echo_testing_string" = 'X\t' &&
-            echo_testing_string=`($ORIGINAL_CONFIG_SHELL "[$]0" --fallback-echo "$echo_test_string") 2>/dev/null` &&
-            test "X$echo_testing_string" = "X$echo_test_string"; then
-         CONFIG_SHELL=$ORIGINAL_CONFIG_SHELL
-         export CONFIG_SHELL
-         SHELL="$CONFIG_SHELL"
-         export SHELL
-         ECHO="$CONFIG_SHELL [$]0 --fallback-echo"
-        elif echo_testing_string=`($CONFIG_SHELL "[$]0" --fallback-echo '\t') 2>/dev/null` &&
-            test "X$echo_testing_string" = 'X\t' &&
-            echo_testing_string=`($CONFIG_SHELL "[$]0" --fallback-echo "$echo_test_string") 2>/dev/null` &&
-            test "X$echo_testing_string" = "X$echo_test_string"; then
-         ECHO="$CONFIG_SHELL [$]0 --fallback-echo"
-        else
-         # maybe with a smaller string...
-         prev=:
-
-         for cmd in 'echo test' 'sed 2q "[$]0"' 'sed 10q "[$]0"' 'sed 20q "[$]0"' 'sed 50q "[$]0"'; do
-           if { test "X$echo_test_string" = "X`eval $cmd`"; } 2>/dev/null
-           then
-             break
-           fi
-           prev="$cmd"
-         done
-
-         if test "$prev" != 'sed 50q "[$]0"'; then
-           echo_test_string=`eval $prev`
-           export echo_test_string
-           exec ${ORIGINAL_CONFIG_SHELL-${CONFIG_SHELL-/bin/sh}} "[$]0" ${1+"[$]@"}
-         else
-           # Oops.  We lost completely, so just stick with echo.
-           ECHO=echo
-         fi
-        fi
-      fi
-    fi
-  fi
-fi
-
-# Copy echo and quote the copy suitably for passing to libtool from
-# the Makefile, instead of quoting the original, which is used later.
-lt_ECHO=$ECHO
-if test "X$lt_ECHO" = "X$CONFIG_SHELL [$]0 --fallback-echo"; then
-   lt_ECHO="$CONFIG_SHELL \\\$\[$]0 --fallback-echo"
-fi
-
-AC_SUBST(lt_ECHO)
-])
-_LT_DECL([], [SHELL], [1], [Shell to use when invoking shell scripts])
-_LT_DECL([], [ECHO], [1],
-    [An echo program that does not interpret backslashes])
-])# _LT_PROG_ECHO_BACKSLASH
-
-
-# _LT_ENABLE_LOCK
-# ---------------
-m4_defun([_LT_ENABLE_LOCK],
-[AC_ARG_ENABLE([libtool-lock],
-  [AS_HELP_STRING([--disable-libtool-lock],
-    [avoid locking (might break parallel builds)])])
-test "x$enable_libtool_lock" != xno && enable_libtool_lock=yes
-
-# Some flags need to be propagated to the compiler or linker for good
-# libtool support.
-case $host in
-ia64-*-hpux*)
-  # Find out which ABI we are using.
-  echo 'int i;' > conftest.$ac_ext
-  if AC_TRY_EVAL(ac_compile); then
-    case `/usr/bin/file conftest.$ac_objext` in
-      *ELF-32*)
-       HPUX_IA64_MODE="32"
-       ;;
-      *ELF-64*)
-       HPUX_IA64_MODE="64"
-       ;;
-    esac
-  fi
-  rm -rf conftest*
-  ;;
-*-*-irix6*)
-  # Find out which ABI we are using.
-  echo '[#]line __oline__ "configure"' > conftest.$ac_ext
-  if AC_TRY_EVAL(ac_compile); then
-    if test "$lt_cv_prog_gnu_ld" = yes; then
-      case `/usr/bin/file conftest.$ac_objext` in
-       *32-bit*)
-         LD="${LD-ld} -melf32bsmip"
-         ;;
-       *N32*)
-         LD="${LD-ld} -melf32bmipn32"
-         ;;
-       *64-bit*)
-         LD="${LD-ld} -melf64bmip"
-       ;;
-      esac
-    else
-      case `/usr/bin/file conftest.$ac_objext` in
-       *32-bit*)
-         LD="${LD-ld} -32"
-         ;;
-       *N32*)
-         LD="${LD-ld} -n32"
-         ;;
-       *64-bit*)
-         LD="${LD-ld} -64"
-         ;;
-      esac
-    fi
-  fi
-  rm -rf conftest*
-  ;;
-
-x86_64-*kfreebsd*-gnu|x86_64-*linux*|ppc*-*linux*|powerpc*-*linux*| \
-s390*-*linux*|s390*-*tpf*|sparc*-*linux*)
-  # Find out which ABI we are using.
-  echo 'int i;' > conftest.$ac_ext
-  if AC_TRY_EVAL(ac_compile); then
-    case `/usr/bin/file conftest.o` in
-      *32-bit*)
-       case $host in
-         x86_64-*kfreebsd*-gnu)
-           LD="${LD-ld} -m elf_i386_fbsd"
-           ;;
-         x86_64-*linux*)
-           LD="${LD-ld} -m elf_i386"
-           ;;
-         ppc64-*linux*|powerpc64-*linux*)
-           LD="${LD-ld} -m elf32ppclinux"
-           ;;
-         s390x-*linux*)
-           LD="${LD-ld} -m elf_s390"
-           ;;
-         sparc64-*linux*)
-           LD="${LD-ld} -m elf32_sparc"
-           ;;
-       esac
-       ;;
-      *64-bit*)
-       case $host in
-         x86_64-*kfreebsd*-gnu)
-           LD="${LD-ld} -m elf_x86_64_fbsd"
-           ;;
-         x86_64-*linux*)
-           LD="${LD-ld} -m elf_x86_64"
-           ;;
-         ppc*-*linux*|powerpc*-*linux*)
-           LD="${LD-ld} -m elf64ppc"
-           ;;
-         s390*-*linux*|s390*-*tpf*)
-           LD="${LD-ld} -m elf64_s390"
-           ;;
-         sparc*-*linux*)
-           LD="${LD-ld} -m elf64_sparc"
-           ;;
-       esac
-       ;;
-    esac
-  fi
-  rm -rf conftest*
-  ;;
-
-*-*-sco3.2v5*)
-  # On SCO OpenServer 5, we need -belf to get full-featured binaries.
-  SAVE_CFLAGS="$CFLAGS"
-  CFLAGS="$CFLAGS -belf"
-  AC_CACHE_CHECK([whether the C compiler needs -belf], lt_cv_cc_needs_belf,
-    [AC_LANG_PUSH(C)
-     AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],[[]])],[lt_cv_cc_needs_belf=yes],[lt_cv_cc_needs_belf=no])
-     AC_LANG_POP])
-  if test x"$lt_cv_cc_needs_belf" != x"yes"; then
-    # this is probably gcc 2.8.0, egcs 1.0 or newer; no need for -belf
-    CFLAGS="$SAVE_CFLAGS"
-  fi
-  ;;
-sparc*-*solaris*)
-  # Find out which ABI we are using.
-  echo 'int i;' > conftest.$ac_ext
-  if AC_TRY_EVAL(ac_compile); then
-    case `/usr/bin/file conftest.o` in
-    *64-bit*)
-      case $lt_cv_prog_gnu_ld in
-      yes*) LD="${LD-ld} -m elf64_sparc" ;;
-      *)
-       if ${LD-ld} -64 -r -o conftest2.o conftest.o >/dev/null 2>&1; then
-         LD="${LD-ld} -64"
-       fi
-       ;;
-      esac
-      ;;
-    esac
-  fi
-  rm -rf conftest*
-  ;;
-esac
-
-need_locks="$enable_libtool_lock"
-])# _LT_ENABLE_LOCK
-
-
-# _LT_CMD_OLD_ARCHIVE
-# -------------------
-m4_defun([_LT_CMD_OLD_ARCHIVE],
-[AC_CHECK_TOOL(AR, ar, false)
-test -z "$AR" && AR=ar
-test -z "$AR_FLAGS" && AR_FLAGS=cru
-_LT_DECL([], [AR], [1], [The archiver])
-_LT_DECL([], [AR_FLAGS], [1])
-
-AC_CHECK_TOOL(STRIP, strip, :)
-test -z "$STRIP" && STRIP=:
-_LT_DECL([], [STRIP], [1], [A symbol stripping program])
-
-AC_CHECK_TOOL(RANLIB, ranlib, :)
-test -z "$RANLIB" && RANLIB=:
-_LT_DECL([], [RANLIB], [1],
-    [Commands used to install an old-style archive])
-
-# Determine commands to create old-style static archives.
-old_archive_cmds='$AR $AR_FLAGS $oldlib$oldobjs'
-old_postinstall_cmds='chmod 644 $oldlib'
-old_postuninstall_cmds=
-
-if test -n "$RANLIB"; then
-  case $host_os in
-  openbsd*)
-    old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB -t \$oldlib"
-    ;;
-  *)
-    old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB \$oldlib"
-    ;;
-  esac
-  old_archive_cmds="$old_archive_cmds~\$RANLIB \$oldlib"
-fi
-_LT_DECL([], [old_postinstall_cmds], [2])
-_LT_DECL([], [old_postuninstall_cmds], [2])
-_LT_TAGDECL([], [old_archive_cmds], [2],
-    [Commands used to build an old-style archive])
-])# _LT_CMD_OLD_ARCHIVE
-
-
-# _LT_COMPILER_OPTION(MESSAGE, VARIABLE-NAME, FLAGS,
-#              [OUTPUT-FILE], [ACTION-SUCCESS], [ACTION-FAILURE])
-# ----------------------------------------------------------------
-# Check whether the given compiler option works
-AC_DEFUN([_LT_COMPILER_OPTION],
-[m4_require([_LT_FILEUTILS_DEFAULTS])dnl
-m4_require([_LT_DECL_SED])dnl
-AC_CACHE_CHECK([$1], [$2],
-  [$2=no
-   m4_if([$4], , [ac_outfile=conftest.$ac_objext], [ac_outfile=$4])
-   echo "$lt_simple_compile_test_code" > conftest.$ac_ext
-   lt_compiler_flag="$3"
-   # Insert the option either (1) after the last *FLAGS variable, or
-   # (2) before a word containing "conftest.", or (3) at the end.
-   # Note that $ac_compile itself does not contain backslashes and begins
-   # with a dollar sign (not a hyphen), so the echo should work correctly.
-   # The option is referenced via a variable to avoid confusing sed.
-   lt_compile=`echo "$ac_compile" | $SED \
-   -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-   -e 's: [[^ ]]*conftest\.: $lt_compiler_flag&:; t' \
-   -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:__oline__: $lt_compile\"" >&AS_MESSAGE_LOG_FD)
-   (eval "$lt_compile" 2>conftest.err)
-   ac_status=$?
-   cat conftest.err >&AS_MESSAGE_LOG_FD
-   echo "$as_me:__oline__: \$? = $ac_status" >&AS_MESSAGE_LOG_FD
-   if (exit $ac_status) && test -s "$ac_outfile"; then
-     # The compiler can only warn and ignore the option if not recognized
-     # So say no if there are warnings other than the usual output.
-     $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' >conftest.exp
-     $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
-     if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then
-       $2=yes
-     fi
-   fi
-   $RM conftest*
-])
-
-if test x"[$]$2" = xyes; then
-    m4_if([$5], , :, [$5])
-else
-    m4_if([$6], , :, [$6])
-fi
-])# _LT_COMPILER_OPTION
-
-# Old name:
-AU_ALIAS([AC_LIBTOOL_COMPILER_OPTION], [_LT_COMPILER_OPTION])
-dnl aclocal-1.4 backwards compatibility:
-dnl AC_DEFUN([AC_LIBTOOL_COMPILER_OPTION], [])
-
-
-# _LT_LINKER_OPTION(MESSAGE, VARIABLE-NAME, FLAGS,
-#                  [ACTION-SUCCESS], [ACTION-FAILURE])
-# ----------------------------------------------------
-# Check whether the given linker option works
-AC_DEFUN([_LT_LINKER_OPTION],
-[m4_require([_LT_FILEUTILS_DEFAULTS])dnl
-m4_require([_LT_DECL_SED])dnl
-AC_CACHE_CHECK([$1], [$2],
-  [$2=no
-   save_LDFLAGS="$LDFLAGS"
-   LDFLAGS="$LDFLAGS $3"
-   echo "$lt_simple_link_test_code" > conftest.$ac_ext
-   if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then
-     # The linker can only warn and ignore the option if not recognized
-     # So say no if there are warnings
-     if test -s conftest.err; then
-       # Append any errors to the config.log.
-       cat conftest.err 1>&AS_MESSAGE_LOG_FD
-       $ECHO "X$_lt_linker_boilerplate" | $Xsed -e '/^$/d' > conftest.exp
-       $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
-       if diff conftest.exp conftest.er2 >/dev/null; then
-         $2=yes
-       fi
-     else
-       $2=yes
-     fi
-   fi
-   $RM -r conftest*
-   LDFLAGS="$save_LDFLAGS"
-])
-
-if test x"[$]$2" = xyes; then
-    m4_if([$4], , :, [$4])
-else
-    m4_if([$5], , :, [$5])
-fi
-])# _LT_LINKER_OPTION
-
-# Old name:
-AU_ALIAS([AC_LIBTOOL_LINKER_OPTION], [_LT_LINKER_OPTION])
-dnl aclocal-1.4 backwards compatibility:
-dnl AC_DEFUN([AC_LIBTOOL_LINKER_OPTION], [])
-
-
-# LT_CMD_MAX_LEN
-#---------------
-AC_DEFUN([LT_CMD_MAX_LEN],
-[AC_REQUIRE([AC_CANONICAL_HOST])dnl
-# find the maximum length of command line arguments
-AC_MSG_CHECKING([the maximum length of command line arguments])
-AC_CACHE_VAL([lt_cv_sys_max_cmd_len], [dnl
-  i=0
-  teststring="ABCD"
-
-  case $build_os in
-  msdosdjgpp*)
-    # On DJGPP, this test can blow up pretty badly due to problems in libc
-    # (any single argument exceeding 2000 bytes causes a buffer overrun
-    # during glob expansion).  Even if it were fixed, the result of this
-    # check would be larger than it should be.
-    lt_cv_sys_max_cmd_len=12288;    # 12K is about right
-    ;;
-
-  gnu*)
-    # Under GNU Hurd, this test is not required because there is
-    # no limit to the length of command line arguments.
-    # Libtool will interpret -1 as no limit whatsoever
-    lt_cv_sys_max_cmd_len=-1;
-    ;;
-
-  cygwin* | mingw* | cegcc*)
-    # On Win9x/ME, this test blows up -- it succeeds, but takes
-    # about 5 minutes as the teststring grows exponentially.
-    # Worse, since 9x/ME are not pre-emptively multitasking,
-    # you end up with a "frozen" computer, even though with patience
-    # the test eventually succeeds (with a max line length of 256k).
-    # Instead, let's just punt: use the minimum linelength reported by
-    # all of the supported platforms: 8192 (on NT/2K/XP).
-    lt_cv_sys_max_cmd_len=8192;
-    ;;
-
-  amigaos*)
-    # On AmigaOS with pdksh, this test takes hours, literally.
-    # So we just punt and use a minimum line length of 8192.
-    lt_cv_sys_max_cmd_len=8192;
-    ;;
-
-  netbsd* | freebsd* | openbsd* | darwin* | dragonfly*)
-    # This has been around since 386BSD, at least.  Likely further.
-    if test -x /sbin/sysctl; then
-      lt_cv_sys_max_cmd_len=`/sbin/sysctl -n kern.argmax`
-    elif test -x /usr/sbin/sysctl; then
-      lt_cv_sys_max_cmd_len=`/usr/sbin/sysctl -n kern.argmax`
-    else
-      lt_cv_sys_max_cmd_len=65536      # usable default for all BSDs
-    fi
-    # And add a safety zone
-    lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4`
-    lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3`
-    ;;
-
-  interix*)
-    # We know the value 262144 and hardcode it with a safety zone (like BSD)
-    lt_cv_sys_max_cmd_len=196608
-    ;;
-
-  osf*)
-    # Dr. Hans Ekkehard Plesser reports seeing a kernel panic running configure
-    # due to this test when exec_disable_arg_limit is 1 on Tru64. It is not
-    # nice to cause kernel panics so lets avoid the loop below.
-    # First set a reasonable default.
-    lt_cv_sys_max_cmd_len=16384
-    #
-    if test -x /sbin/sysconfig; then
-      case `/sbin/sysconfig -q proc exec_disable_arg_limit` in
-        *1*) lt_cv_sys_max_cmd_len=-1 ;;
-      esac
-    fi
-    ;;
-  sco3.2v5*)
-    lt_cv_sys_max_cmd_len=102400
-    ;;
-  sysv5* | sco5v6* | sysv4.2uw2*)
-    kargmax=`grep ARG_MAX /etc/conf/cf.d/stune 2>/dev/null`
-    if test -n "$kargmax"; then
-      lt_cv_sys_max_cmd_len=`echo $kargmax | sed 's/.*[[        ]]//'`
-    else
-      lt_cv_sys_max_cmd_len=32768
-    fi
-    ;;
-  *)
-    lt_cv_sys_max_cmd_len=`(getconf ARG_MAX) 2> /dev/null`
-    if test -n "$lt_cv_sys_max_cmd_len"; then
-      lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4`
-      lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3`
-    else
-      # Make teststring a little bigger before we do anything with it.
-      # a 1K string should be a reasonable start.
-      for i in 1 2 3 4 5 6 7 8 ; do
-        teststring=$teststring$teststring
-      done
-      SHELL=${SHELL-${CONFIG_SHELL-/bin/sh}}
-      # If test is not a shell built-in, we'll probably end up computing a
-      # maximum length that is only half of the actual maximum length, but
-      # we can't tell.
-      while { test "X"`$SHELL [$]0 --fallback-echo "X$teststring$teststring" 2>/dev/null` \
-                = "XX$teststring$teststring"; } >/dev/null 2>&1 &&
-             test $i != 17 # 1/2 MB should be enough
-      do
-        i=`expr $i + 1`
-        teststring=$teststring$teststring
-      done
-      # Only check the string length outside the loop.
-      lt_cv_sys_max_cmd_len=`expr "X$teststring" : ".*" 2>&1`
-      teststring=
-      # Add a significant safety factor because C++ compilers can tack on
-      # massive amounts of additional arguments before passing them to the
-      # linker.  It appears as though 1/2 is a usable value.
-      lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 2`
-    fi
-    ;;
-  esac
-])
-if test -n $lt_cv_sys_max_cmd_len ; then
-  AC_MSG_RESULT($lt_cv_sys_max_cmd_len)
-else
-  AC_MSG_RESULT(none)
-fi
-max_cmd_len=$lt_cv_sys_max_cmd_len
-_LT_DECL([], [max_cmd_len], [0],
-    [What is the maximum length of a command?])
-])# LT_CMD_MAX_LEN
-
-# Old name:
-AU_ALIAS([AC_LIBTOOL_SYS_MAX_CMD_LEN], [LT_CMD_MAX_LEN])
-dnl aclocal-1.4 backwards compatibility:
-dnl AC_DEFUN([AC_LIBTOOL_SYS_MAX_CMD_LEN], [])
-
-
-# _LT_HEADER_DLFCN
-# ----------------
-m4_defun([_LT_HEADER_DLFCN],
-[AC_CHECK_HEADERS([dlfcn.h], [], [], [AC_INCLUDES_DEFAULT])dnl
-])# _LT_HEADER_DLFCN
-
-
-# _LT_TRY_DLOPEN_SELF (ACTION-IF-TRUE, ACTION-IF-TRUE-W-USCORE,
-#                      ACTION-IF-FALSE, ACTION-IF-CROSS-COMPILING)
-# ----------------------------------------------------------------
-m4_defun([_LT_TRY_DLOPEN_SELF],
-[m4_require([_LT_HEADER_DLFCN])dnl
-if test "$cross_compiling" = yes; then :
-  [$4]
-else
-  lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
-  lt_status=$lt_dlunknown
-  cat > conftest.$ac_ext <<_LT_EOF
-[#line __oline__ "configure"
-#include "confdefs.h"
-
-#if HAVE_DLFCN_H
-#include <dlfcn.h>
-#endif
-
-#include <stdio.h>
-
-#ifdef RTLD_GLOBAL
-#  define LT_DLGLOBAL          RTLD_GLOBAL
-#else
-#  ifdef DL_GLOBAL
-#    define LT_DLGLOBAL                DL_GLOBAL
-#  else
-#    define LT_DLGLOBAL                0
-#  endif
-#endif
-
-/* We may have to define LT_DLLAZY_OR_NOW in the command line if we
-   find out it does not work in some platform. */
-#ifndef LT_DLLAZY_OR_NOW
-#  ifdef RTLD_LAZY
-#    define LT_DLLAZY_OR_NOW           RTLD_LAZY
-#  else
-#    ifdef DL_LAZY
-#      define LT_DLLAZY_OR_NOW         DL_LAZY
-#    else
-#      ifdef RTLD_NOW
-#        define LT_DLLAZY_OR_NOW       RTLD_NOW
-#      else
-#        ifdef DL_NOW
-#          define LT_DLLAZY_OR_NOW     DL_NOW
-#        else
-#          define LT_DLLAZY_OR_NOW     0
-#        endif
-#      endif
-#    endif
-#  endif
-#endif
-
-void fnord() { int i=42;}
-int main ()
-{
-  void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW);
-  int status = $lt_dlunknown;
-
-  if (self)
-    {
-      if (dlsym (self,"fnord"))       status = $lt_dlno_uscore;
-      else if (dlsym( self,"_fnord")) status = $lt_dlneed_uscore;
-      /* dlclose (self); */
-    }
-  else
-    puts (dlerror ());
-
-  return status;
-}]
-_LT_EOF
-  if AC_TRY_EVAL(ac_link) && test -s conftest${ac_exeext} 2>/dev/null; then
-    (./conftest; exit; ) >&AS_MESSAGE_LOG_FD 2>/dev/null
-    lt_status=$?
-    case x$lt_status in
-      x$lt_dlno_uscore) $1 ;;
-      x$lt_dlneed_uscore) $2 ;;
-      x$lt_dlunknown|x*) $3 ;;
-    esac
-  else :
-    # compilation failed
-    $3
-  fi
-fi
-rm -fr conftest*
-])# _LT_TRY_DLOPEN_SELF
-
-
-# LT_SYS_DLOPEN_SELF
-# ------------------
-AC_DEFUN([LT_SYS_DLOPEN_SELF],
-[m4_require([_LT_HEADER_DLFCN])dnl
-if test "x$enable_dlopen" != xyes; then
-  enable_dlopen=unknown
-  enable_dlopen_self=unknown
-  enable_dlopen_self_static=unknown
-else
-  lt_cv_dlopen=no
-  lt_cv_dlopen_libs=
-
-  case $host_os in
-  beos*)
-    lt_cv_dlopen="load_add_on"
-    lt_cv_dlopen_libs=
-    lt_cv_dlopen_self=yes
-    ;;
-
-  mingw* | pw32* | cegcc*)
-    lt_cv_dlopen="LoadLibrary"
-    lt_cv_dlopen_libs=
-    ;;
-
-  cygwin*)
-    lt_cv_dlopen="dlopen"
-    lt_cv_dlopen_libs=
-    ;;
-
-  darwin*)
-  # if libdl is installed we need to link against it
-    AC_CHECK_LIB([dl], [dlopen],
-               [lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl"],[
-    lt_cv_dlopen="dyld"
-    lt_cv_dlopen_libs=
-    lt_cv_dlopen_self=yes
-    ])
-    ;;
-
-  *)
-    AC_CHECK_FUNC([shl_load],
-         [lt_cv_dlopen="shl_load"],
-      [AC_CHECK_LIB([dld], [shl_load],
-           [lt_cv_dlopen="shl_load" lt_cv_dlopen_libs="-ldld"],
-       [AC_CHECK_FUNC([dlopen],
-             [lt_cv_dlopen="dlopen"],
-         [AC_CHECK_LIB([dl], [dlopen],
-               [lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl"],
-           [AC_CHECK_LIB([svld], [dlopen],
-                 [lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-lsvld"],
-             [AC_CHECK_LIB([dld], [dld_link],
-                   [lt_cv_dlopen="dld_link" lt_cv_dlopen_libs="-ldld"])
-             ])
-           ])
-         ])
-       ])
-      ])
-    ;;
-  esac
-
-  if test "x$lt_cv_dlopen" != xno; then
-    enable_dlopen=yes
-  else
-    enable_dlopen=no
-  fi
-
-  case $lt_cv_dlopen in
-  dlopen)
-    save_CPPFLAGS="$CPPFLAGS"
-    test "x$ac_cv_header_dlfcn_h" = xyes && CPPFLAGS="$CPPFLAGS -DHAVE_DLFCN_H"
-
-    save_LDFLAGS="$LDFLAGS"
-    wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $export_dynamic_flag_spec\"
-
-    save_LIBS="$LIBS"
-    LIBS="$lt_cv_dlopen_libs $LIBS"
-
-    AC_CACHE_CHECK([whether a program can dlopen itself],
-         lt_cv_dlopen_self, [dnl
-         _LT_TRY_DLOPEN_SELF(
-           lt_cv_dlopen_self=yes, lt_cv_dlopen_self=yes,
-           lt_cv_dlopen_self=no, lt_cv_dlopen_self=cross)
-    ])
-
-    if test "x$lt_cv_dlopen_self" = xyes; then
-      wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $lt_prog_compiler_static\"
-      AC_CACHE_CHECK([whether a statically linked program can dlopen itself],
-         lt_cv_dlopen_self_static, [dnl
-         _LT_TRY_DLOPEN_SELF(
-           lt_cv_dlopen_self_static=yes, lt_cv_dlopen_self_static=yes,
-           lt_cv_dlopen_self_static=no,  lt_cv_dlopen_self_static=cross)
-      ])
-    fi
-
-    CPPFLAGS="$save_CPPFLAGS"
-    LDFLAGS="$save_LDFLAGS"
-    LIBS="$save_LIBS"
-    ;;
-  esac
-
-  case $lt_cv_dlopen_self in
-  yes|no) enable_dlopen_self=$lt_cv_dlopen_self ;;
-  *) enable_dlopen_self=unknown ;;
-  esac
-
-  case $lt_cv_dlopen_self_static in
-  yes|no) enable_dlopen_self_static=$lt_cv_dlopen_self_static ;;
-  *) enable_dlopen_self_static=unknown ;;
-  esac
-fi
-_LT_DECL([dlopen_support], [enable_dlopen], [0],
-        [Whether dlopen is supported])
-_LT_DECL([dlopen_self], [enable_dlopen_self], [0],
-        [Whether dlopen of programs is supported])
-_LT_DECL([dlopen_self_static], [enable_dlopen_self_static], [0],
-        [Whether dlopen of statically linked programs is supported])
-])# LT_SYS_DLOPEN_SELF
-
-# Old name:
-AU_ALIAS([AC_LIBTOOL_DLOPEN_SELF], [LT_SYS_DLOPEN_SELF])
-dnl aclocal-1.4 backwards compatibility:
-dnl AC_DEFUN([AC_LIBTOOL_DLOPEN_SELF], [])
-
-
-# _LT_COMPILER_C_O([TAGNAME])
-# ---------------------------
-# Check to see if options -c and -o are simultaneously supported by compiler.
-# This macro does not hard code the compiler like AC_PROG_CC_C_O.
-m4_defun([_LT_COMPILER_C_O],
-[m4_require([_LT_DECL_SED])dnl
-m4_require([_LT_FILEUTILS_DEFAULTS])dnl
-m4_require([_LT_TAG_COMPILER])dnl
-AC_CACHE_CHECK([if $compiler supports -c -o file.$ac_objext],
-  [_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)],
-  [_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)=no
-   $RM -r conftest 2>/dev/null
-   mkdir conftest
-   cd conftest
-   mkdir out
-   echo "$lt_simple_compile_test_code" > conftest.$ac_ext
-
-   lt_compiler_flag="-o out/conftest2.$ac_objext"
-   # Insert the option either (1) after the last *FLAGS variable, or
-   # (2) before a word containing "conftest.", or (3) at the end.
-   # Note that $ac_compile itself does not contain backslashes and begins
-   # with a dollar sign (not a hyphen), so the echo should work correctly.
-   lt_compile=`echo "$ac_compile" | $SED \
-   -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-   -e 's: [[^ ]]*conftest\.: $lt_compiler_flag&:; t' \
-   -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:__oline__: $lt_compile\"" >&AS_MESSAGE_LOG_FD)
-   (eval "$lt_compile" 2>out/conftest.err)
-   ac_status=$?
-   cat out/conftest.err >&AS_MESSAGE_LOG_FD
-   echo "$as_me:__oline__: \$? = $ac_status" >&AS_MESSAGE_LOG_FD
-   if (exit $ac_status) && test -s out/conftest2.$ac_objext
-   then
-     # The compiler can only warn and ignore the option if not recognized
-     # So say no if there are warnings
-     $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' > out/conftest.exp
-     $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2
-     if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then
-       _LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)=yes
-     fi
-   fi
-   chmod u+w . 2>&AS_MESSAGE_LOG_FD
-   $RM conftest*
-   # SGI C++ compiler will create directory out/ii_files/ for
-   # template instantiation
-   test -d out/ii_files && $RM out/ii_files/* && rmdir out/ii_files
-   $RM out/* && rmdir out
-   cd ..
-   $RM -r conftest
-   $RM conftest*
-])
-_LT_TAGDECL([compiler_c_o], [lt_cv_prog_compiler_c_o], [1],
-       [Does compiler simultaneously support -c and -o options?])
-])# _LT_COMPILER_C_O
-
-
-# _LT_COMPILER_FILE_LOCKS([TAGNAME])
-# ----------------------------------
-# Check to see if we can do hard links to lock some files if needed
-m4_defun([_LT_COMPILER_FILE_LOCKS],
-[m4_require([_LT_ENABLE_LOCK])dnl
-m4_require([_LT_FILEUTILS_DEFAULTS])dnl
-_LT_COMPILER_C_O([$1])
-
-hard_links="nottested"
-if test "$_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)" = no && test "$need_locks" != no; then
-  # do not overwrite the value of need_locks provided by the user
-  AC_MSG_CHECKING([if we can lock with hard links])
-  hard_links=yes
-  $RM conftest*
-  ln conftest.a conftest.b 2>/dev/null && hard_links=no
-  touch conftest.a
-  ln conftest.a conftest.b 2>&5 || hard_links=no
-  ln conftest.a conftest.b 2>/dev/null && hard_links=no
-  AC_MSG_RESULT([$hard_links])
-  if test "$hard_links" = no; then
-    AC_MSG_WARN([`$CC' does not support `-c -o', so `make -j' may be unsafe])
-    need_locks=warn
-  fi
-else
-  need_locks=no
-fi
-_LT_DECL([], [need_locks], [1], [Must we lock files when doing compilation?])
-])# _LT_COMPILER_FILE_LOCKS
-
-
-# _LT_CHECK_OBJDIR
-# ----------------
-m4_defun([_LT_CHECK_OBJDIR],
-[AC_CACHE_CHECK([for objdir], [lt_cv_objdir],
-[rm -f .libs 2>/dev/null
-mkdir .libs 2>/dev/null
-if test -d .libs; then
-  lt_cv_objdir=.libs
-else
-  # MS-DOS does not allow filenames that begin with a dot.
-  lt_cv_objdir=_libs
-fi
-rmdir .libs 2>/dev/null])
-objdir=$lt_cv_objdir
-_LT_DECL([], [objdir], [0],
-         [The name of the directory that contains temporary libtool files])dnl
-m4_pattern_allow([LT_OBJDIR])dnl
-AC_DEFINE_UNQUOTED(LT_OBJDIR, "$lt_cv_objdir/",
-  [Define to the sub-directory in which libtool stores uninstalled libraries.])
-])# _LT_CHECK_OBJDIR
-
-
-# _LT_LINKER_HARDCODE_LIBPATH([TAGNAME])
-# --------------------------------------
-# Check hardcoding attributes.
-m4_defun([_LT_LINKER_HARDCODE_LIBPATH],
-[AC_MSG_CHECKING([how to hardcode library paths into programs])
-_LT_TAGVAR(hardcode_action, $1)=
-if test -n "$_LT_TAGVAR(hardcode_libdir_flag_spec, $1)" ||
-   test -n "$_LT_TAGVAR(runpath_var, $1)" ||
-   test "X$_LT_TAGVAR(hardcode_automatic, $1)" = "Xyes" ; then
-
-  # We can hardcode non-existent directories.
-  if test "$_LT_TAGVAR(hardcode_direct, $1)" != no &&
-     # If the only mechanism to avoid hardcoding is shlibpath_var, we
-     # have to relink, otherwise we might link with an installed library
-     # when we should be linking with a yet-to-be-installed one
-     ## test "$_LT_TAGVAR(hardcode_shlibpath_var, $1)" != no &&
-     test "$_LT_TAGVAR(hardcode_minus_L, $1)" != no; then
-    # Linking always hardcodes the temporary library directory.
-    _LT_TAGVAR(hardcode_action, $1)=relink
-  else
-    # We can link without hardcoding, and we can hardcode nonexisting dirs.
-    _LT_TAGVAR(hardcode_action, $1)=immediate
-  fi
-else
-  # We cannot hardcode anything, or else we can only hardcode existing
-  # directories.
-  _LT_TAGVAR(hardcode_action, $1)=unsupported
-fi
-AC_MSG_RESULT([$_LT_TAGVAR(hardcode_action, $1)])
-
-if test "$_LT_TAGVAR(hardcode_action, $1)" = relink ||
-   test "$_LT_TAGVAR(inherit_rpath, $1)" = yes; then
-  # Fast installation is not supported
-  enable_fast_install=no
-elif test "$shlibpath_overrides_runpath" = yes ||
-     test "$enable_shared" = no; then
-  # Fast installation is not necessary
-  enable_fast_install=needless
-fi
-_LT_TAGDECL([], [hardcode_action], [0],
-    [How to hardcode a shared library path into an executable])
-])# _LT_LINKER_HARDCODE_LIBPATH
-
-
-# _LT_CMD_STRIPLIB
-# ----------------
-m4_defun([_LT_CMD_STRIPLIB],
-[m4_require([_LT_DECL_EGREP])
-striplib=
-old_striplib=
-AC_MSG_CHECKING([whether stripping libraries is possible])
-if test -n "$STRIP" && $STRIP -V 2>&1 | $GREP "GNU strip" >/dev/null; then
-  test -z "$old_striplib" && old_striplib="$STRIP --strip-debug"
-  test -z "$striplib" && striplib="$STRIP --strip-unneeded"
-  AC_MSG_RESULT([yes])
-else
-# FIXME - insert some real tests, host_os isn't really good enough
-  case $host_os in
-  darwin*)
-    if test -n "$STRIP" ; then
-      striplib="$STRIP -x"
-      old_striplib="$STRIP -S"
-      AC_MSG_RESULT([yes])
-    else
-      AC_MSG_RESULT([no])
-    fi
-    ;;
-  *)
-    AC_MSG_RESULT([no])
-    ;;
-  esac
-fi
-_LT_DECL([], [old_striplib], [1], [Commands to strip libraries])
-_LT_DECL([], [striplib], [1])
-])# _LT_CMD_STRIPLIB
-
-
-# _LT_SYS_DYNAMIC_LINKER([TAG])
-# -----------------------------
-# PORTME Fill in your ld.so characteristics
-m4_defun([_LT_SYS_DYNAMIC_LINKER],
-[AC_REQUIRE([AC_CANONICAL_HOST])dnl
-m4_require([_LT_DECL_EGREP])dnl
-m4_require([_LT_FILEUTILS_DEFAULTS])dnl
-m4_require([_LT_DECL_OBJDUMP])dnl
-m4_require([_LT_DECL_SED])dnl
-AC_MSG_CHECKING([dynamic linker characteristics])
-m4_if([$1],
-       [], [
-if test "$GCC" = yes; then
-  case $host_os in
-    darwin*) lt_awk_arg="/^libraries:/,/LR/" ;;
-    *) lt_awk_arg="/^libraries:/" ;;
-  esac
-  lt_search_path_spec=`$CC -print-search-dirs | awk $lt_awk_arg | $SED -e "s/^libraries://" -e "s,=/,/,g"`
-  if $ECHO "$lt_search_path_spec" | $GREP ';' >/dev/null ; then
-    # if the path contains ";" then we assume it to be the separator
-    # otherwise default to the standard path separator (i.e. ":") - it is
-    # assumed that no part of a normal pathname contains ";" but that should
-    # okay in the real world where ";" in dirpaths is itself problematic.
-    lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED -e 's/;/ /g'`
-  else
-    lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED  -e "s/$PATH_SEPARATOR/ /g"`
-  fi
-  # Ok, now we have the path, separated by spaces, we can step through it
-  # and add multilib dir if necessary.
-  lt_tmp_lt_search_path_spec=
-  lt_multi_os_dir=`$CC $CPPFLAGS $CFLAGS $LDFLAGS -print-multi-os-directory 2>/dev/null`
-  for lt_sys_path in $lt_search_path_spec; do
-    if test -d "$lt_sys_path/$lt_multi_os_dir"; then
-      lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path/$lt_multi_os_dir"
-    else
-      test -d "$lt_sys_path" && \
-       lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path"
-    fi
-  done
-  lt_search_path_spec=`$ECHO $lt_tmp_lt_search_path_spec | awk '
-BEGIN {RS=" "; FS="/|\n";} {
-  lt_foo="";
-  lt_count=0;
-  for (lt_i = NF; lt_i > 0; lt_i--) {
-    if ($lt_i != "" && $lt_i != ".") {
-      if ($lt_i == "..") {
-        lt_count++;
-      } else {
-        if (lt_count == 0) {
-          lt_foo="/" $lt_i lt_foo;
-        } else {
-          lt_count--;
-        }
-      }
-    }
-  }
-  if (lt_foo != "") { lt_freq[[lt_foo]]++; }
-  if (lt_freq[[lt_foo]] == 1) { print lt_foo; }
-}'`
-  sys_lib_search_path_spec=`$ECHO $lt_search_path_spec`
-else
-  sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib"
-fi])
-library_names_spec=
-libname_spec='lib$name'
-soname_spec=
-shrext_cmds=".so"
-postinstall_cmds=
-postuninstall_cmds=
-finish_cmds=
-finish_eval=
-shlibpath_var=
-shlibpath_overrides_runpath=unknown
-version_type=none
-dynamic_linker="$host_os ld.so"
-sys_lib_dlsearch_path_spec="/lib /usr/lib"
-need_lib_prefix=unknown
-hardcode_into_libs=no
-
-# when you set need_version to no, make sure it does not cause -set_version
-# flags to be left without arguments
-need_version=unknown
-
-case $host_os in
-aix3*)
-  version_type=linux
-  library_names_spec='${libname}${release}${shared_ext}$versuffix $libname.a'
-  shlibpath_var=LIBPATH
-
-  # AIX 3 has no versioning support, so we append a major version to the name.
-  soname_spec='${libname}${release}${shared_ext}$major'
-  ;;
-
-aix[[4-9]]*)
-  version_type=linux
-  need_lib_prefix=no
-  need_version=no
-  hardcode_into_libs=yes
-  if test "$host_cpu" = ia64; then
-    # AIX 5 supports IA64
-    library_names_spec='${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext}$versuffix $libname${shared_ext}'
-    shlibpath_var=LD_LIBRARY_PATH
-  else
-    # With GCC up to 2.95.x, collect2 would create an import file
-    # for dependence libraries.  The import file would start with
-    # the line `#! .'.  This would cause the generated library to
-    # depend on `.', always an invalid library.  This was fixed in
-    # development snapshots of GCC prior to 3.0.
-    case $host_os in
-      aix4 | aix4.[[01]] | aix4.[[01]].*)
-      if { echo '#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97)'
-          echo ' yes '
-          echo '#endif'; } | ${CC} -E - | $GREP yes > /dev/null; then
-       :
-      else
-       can_build_shared=no
-      fi
-      ;;
-    esac
-    # AIX (on Power*) has no versioning support, so currently we can not hardcode correct
-    # soname into executable. Probably we can add versioning support to
-    # collect2, so additional links can be useful in future.
-    if test "$aix_use_runtimelinking" = yes; then
-      # If using run time linking (on AIX 4.2 or later) use lib<name>.so
-      # instead of lib<name>.a to let people know that these are not
-      # typical AIX shared libraries.
-      library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
-    else
-      # We preserve .a as extension for shared libraries through AIX4.2
-      # and later when we are not doing run time linking.
-      library_names_spec='${libname}${release}.a $libname.a'
-      soname_spec='${libname}${release}${shared_ext}$major'
-    fi
-    shlibpath_var=LIBPATH
-  fi
-  ;;
-
-amigaos*)
-  case $host_cpu in
-  powerpc)
-    # Since July 2007 AmigaOS4 officially supports .so libraries.
-    # When compiling the executable, add -use-dynld -Lsobjs: to the compileline.
-    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
-    ;;
-  m68k)
-    library_names_spec='$libname.ixlibrary $libname.a'
-    # Create ${libname}_ixlibrary.a entries in /sys/libs.
-    finish_eval='for lib in `ls $libdir/*.ixlibrary 2>/dev/null`; do libname=`$ECHO "X$lib" | $Xsed -e '\''s%^.*/\([[^/]]*\)\.ixlibrary$%\1%'\''`; test $RM /sys/libs/${libname}_ixlibrary.a; $show "cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a"; cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a || exit 1; done'
-    ;;
-  esac
-  ;;
-
-beos*)
-  library_names_spec='${libname}${shared_ext}'
-  dynamic_linker="$host_os ld.so"
-  shlibpath_var=LIBRARY_PATH
-  ;;
-
-bsdi[[45]]*)
-  version_type=linux
-  need_version=no
-  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
-  soname_spec='${libname}${release}${shared_ext}$major'
-  finish_cmds='PATH="\$PATH:/sbin" ldconfig $libdir'
-  shlibpath_var=LD_LIBRARY_PATH
-  sys_lib_search_path_spec="/shlib /usr/lib /usr/X11/lib /usr/contrib/lib /lib /usr/local/lib"
-  sys_lib_dlsearch_path_spec="/shlib /usr/lib /usr/local/lib"
-  # the default ld.so.conf also contains /usr/contrib/lib and
-  # /usr/X11R6/lib (/usr/X11 is a link to /usr/X11R6), but let us allow
-  # libtool to hard-code these into programs
-  ;;
-
-cygwin* | mingw* | pw32* | cegcc*)
-  version_type=windows
-  shrext_cmds=".dll"
-  need_version=no
-  need_lib_prefix=no
-
-  case $GCC,$host_os in
-  yes,cygwin* | yes,mingw* | yes,pw32* | yes,cegcc*)
-    library_names_spec='$libname.dll.a'
-    # DLL is installed to $(libdir)/../bin by postinstall_cmds
-    postinstall_cmds='base_file=`basename \${file}`~
-      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~
-      dldir=$destdir/`dirname \$dlpath`~
-      test -d \$dldir || mkdir -p \$dldir~
-      $install_prog $dir/$dlname \$dldir/$dlname~
-      chmod a+x \$dldir/$dlname~
-      if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then
-        eval '\''$striplib \$dldir/$dlname'\'' || exit \$?;
-      fi'
-    postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
-      dlpath=$dir/\$dldll~
-       $RM \$dlpath'
-    shlibpath_overrides_runpath=yes
-
-    case $host_os in
-    cygwin*)
-      # Cygwin DLLs use 'cyg' prefix rather than 'lib'
-      soname_spec='`echo ${libname} | sed -e 's/^lib/cyg/'``echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}'
-      sys_lib_search_path_spec="/usr/lib /lib/w32api /lib /usr/local/lib"
-      ;;
-    mingw* | cegcc*)
-      # MinGW DLLs use traditional 'lib' prefix
-      soname_spec='${libname}`echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}'
-      sys_lib_search_path_spec=`$CC -print-search-dirs | $GREP "^libraries:" | $SED -e "s/^libraries://" -e "s,=/,/,g"`
-      if $ECHO "$sys_lib_search_path_spec" | [$GREP ';[c-zC-Z]:/' >/dev/null]; then
-        # It is most probably a Windows format PATH printed by
-        # mingw gcc, but we are running on Cygwin. Gcc prints its search
-        # path with ; separators, and with drive letters. We can handle the
-        # drive letters (cygwin fileutils understands them), so leave them,
-        # especially as we might pass files found there to a mingw objdump,
-        # which wouldn't understand a cygwinified path. Ahh.
-        sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'`
-      else
-        sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED  -e "s/$PATH_SEPARATOR/ /g"`
-      fi
-      ;;
-    pw32*)
-      # pw32 DLLs use 'pw' prefix rather than 'lib'
-      library_names_spec='`echo ${libname} | sed -e 's/^lib/pw/'``echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}'
-      ;;
-    esac
-    ;;
-
-  *)
-    library_names_spec='${libname}`echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext} $libname.lib'
-    ;;
-  esac
-  dynamic_linker='Win32 ld.exe'
-  # FIXME: first we should search . and the directory the executable is in
-  shlibpath_var=PATH
-  ;;
-
-darwin* | rhapsody*)
-  dynamic_linker="$host_os dyld"
-  version_type=darwin
-  need_lib_prefix=no
-  need_version=no
-  library_names_spec='${libname}${release}${major}$shared_ext ${libname}$shared_ext'
-  soname_spec='${libname}${release}${major}$shared_ext'
-  shlibpath_overrides_runpath=yes
-  shlibpath_var=DYLD_LIBRARY_PATH
-  shrext_cmds='`test .$module = .yes && echo .so || echo .dylib`'
-m4_if([$1], [],[
-  sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/local/lib"])
-  sys_lib_dlsearch_path_spec='/usr/local/lib /lib /usr/lib'
-  ;;
-
-dgux*)
-  version_type=linux
-  need_lib_prefix=no
-  need_version=no
-  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname$shared_ext'
-  soname_spec='${libname}${release}${shared_ext}$major'
-  shlibpath_var=LD_LIBRARY_PATH
-  ;;
-
-freebsd1*)
-  dynamic_linker=no
-  ;;
-
-freebsd* | dragonfly*)
-  # DragonFly does not have aout.  When/if they implement a new
-  # versioning mechanism, adjust this.
-  if test -x /usr/bin/objformat; then
-    objformat=`/usr/bin/objformat`
-  else
-    case $host_os in
-    freebsd[[123]]*) objformat=aout ;;
-    *) objformat=elf ;;
-    esac
-  fi
-  version_type=freebsd-$objformat
-  case $version_type in
-    freebsd-elf*)
-      library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}'
-      need_version=no
-      need_lib_prefix=no
-      ;;
-    freebsd-*)
-      library_names_spec='${libname}${release}${shared_ext}$versuffix $libname${shared_ext}$versuffix'
-      need_version=yes
-      ;;
-  esac
-  shlibpath_var=LD_LIBRARY_PATH
-  case $host_os in
-  freebsd2*)
-    shlibpath_overrides_runpath=yes
-    ;;
-  freebsd3.[[01]]* | freebsdelf3.[[01]]*)
-    shlibpath_overrides_runpath=yes
-    hardcode_into_libs=yes
-    ;;
-  freebsd3.[[2-9]]* | freebsdelf3.[[2-9]]* | \
-  freebsd4.[[0-5]] | freebsdelf4.[[0-5]] | freebsd4.1.1 | freebsdelf4.1.1)
-    shlibpath_overrides_runpath=no
-    hardcode_into_libs=yes
-    ;;
-  *) # from 4.6 on, and DragonFly
-    shlibpath_overrides_runpath=yes
-    hardcode_into_libs=yes
-    ;;
-  esac
-  ;;
-
-gnu*)
-  version_type=linux
-  need_lib_prefix=no
-  need_version=no
-  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}${major} ${libname}${shared_ext}'
-  soname_spec='${libname}${release}${shared_ext}$major'
-  shlibpath_var=LD_LIBRARY_PATH
-  hardcode_into_libs=yes
-  ;;
-
-hpux9* | hpux10* | hpux11*)
-  # Give a soname corresponding to the major version so that dld.sl refuses to
-  # link against other versions.
-  version_type=sunos
-  need_lib_prefix=no
-  need_version=no
-  case $host_cpu in
-  ia64*)
-    shrext_cmds='.so'
-    hardcode_into_libs=yes
-    dynamic_linker="$host_os dld.so"
-    shlibpath_var=LD_LIBRARY_PATH
-    shlibpath_overrides_runpath=yes # Unless +noenvvar is specified.
-    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
-    soname_spec='${libname}${release}${shared_ext}$major'
-    if test "X$HPUX_IA64_MODE" = X32; then
-      sys_lib_search_path_spec="/usr/lib/hpux32 /usr/local/lib/hpux32 /usr/local/lib"
-    else
-      sys_lib_search_path_spec="/usr/lib/hpux64 /usr/local/lib/hpux64"
-    fi
-    sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec
-    ;;
-  hppa*64*)
-    shrext_cmds='.sl'
-    hardcode_into_libs=yes
-    dynamic_linker="$host_os dld.sl"
-    shlibpath_var=LD_LIBRARY_PATH # How should we handle SHLIB_PATH
-    shlibpath_overrides_runpath=yes # Unless +noenvvar is specified.
-    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
-    soname_spec='${libname}${release}${shared_ext}$major'
-    sys_lib_search_path_spec="/usr/lib/pa20_64 /usr/ccs/lib/pa20_64"
-    sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec
-    ;;
-  *)
-    shrext_cmds='.sl'
-    dynamic_linker="$host_os dld.sl"
-    shlibpath_var=SHLIB_PATH
-    shlibpath_overrides_runpath=no # +s is required to enable SHLIB_PATH
-    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
-    soname_spec='${libname}${release}${shared_ext}$major'
-    ;;
-  esac
-  # HP-UX runs *really* slowly unless shared libraries are mode 555.
-  postinstall_cmds='chmod 555 $lib'
-  ;;
-
-interix[[3-9]]*)
-  version_type=linux
-  need_lib_prefix=no
-  need_version=no
-  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
-  soname_spec='${libname}${release}${shared_ext}$major'
-  dynamic_linker='Interix 3.x ld.so.1 (PE, like ELF)'
-  shlibpath_var=LD_LIBRARY_PATH
-  shlibpath_overrides_runpath=no
-  hardcode_into_libs=yes
-  ;;
-
-irix5* | irix6* | nonstopux*)
-  case $host_os in
-    nonstopux*) version_type=nonstopux ;;
-    *)
-       if test "$lt_cv_prog_gnu_ld" = yes; then
-               version_type=linux
-       else
-               version_type=irix
-       fi ;;
-  esac
-  need_lib_prefix=no
-  need_version=no
-  soname_spec='${libname}${release}${shared_ext}$major'
-  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext} $libname${shared_ext}'
-  case $host_os in
-  irix5* | nonstopux*)
-    libsuff= shlibsuff=
-    ;;
-  *)
-    case $LD in # libtool.m4 will add one of these switches to LD
-    *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ")
-      libsuff= shlibsuff= libmagic=32-bit;;
-    *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ")
-      libsuff=32 shlibsuff=N32 libmagic=N32;;
-    *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ")
-      libsuff=64 shlibsuff=64 libmagic=64-bit;;
-    *) libsuff= shlibsuff= libmagic=never-match;;
-    esac
-    ;;
-  esac
-  shlibpath_var=LD_LIBRARY${shlibsuff}_PATH
-  shlibpath_overrides_runpath=no
-  sys_lib_search_path_spec="/usr/lib${libsuff} /lib${libsuff} /usr/local/lib${libsuff}"
-  sys_lib_dlsearch_path_spec="/usr/lib${libsuff} /lib${libsuff}"
-  hardcode_into_libs=yes
-  ;;
-
-# No shared lib support for Linux oldld, aout, or coff.
-linux*oldld* | linux*aout* | linux*coff*)
-  dynamic_linker=no
-  ;;
-
-# This must be Linux ELF.
-linux* | k*bsd*-gnu | kopensolaris*-gnu)
-  version_type=linux
-  need_lib_prefix=no
-  need_version=no
-  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
-  soname_spec='${libname}${release}${shared_ext}$major'
-  finish_cmds='PATH="\$PATH:/sbin" ldconfig -n $libdir'
-  shlibpath_var=LD_LIBRARY_PATH
-  shlibpath_overrides_runpath=no
-  # Some binutils ld are patched to set DT_RUNPATH
-  save_LDFLAGS=$LDFLAGS
-  save_libdir=$libdir
-  eval "libdir=/foo; wl=\"$_LT_TAGVAR(lt_prog_compiler_wl, $1)\"; \
-       LDFLAGS=\"\$LDFLAGS $_LT_TAGVAR(hardcode_libdir_flag_spec, $1)\""
-  AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])],
-    [AS_IF([ ($OBJDUMP -p conftest$ac_exeext) 2>/dev/null | grep "RUNPATH.*$libdir" >/dev/null],
-       [shlibpath_overrides_runpath=yes])])
-  LDFLAGS=$save_LDFLAGS
-  libdir=$save_libdir
-
-  # This implies no fast_install, which is unacceptable.
-  # Some rework will be needed to allow for fast_install
-  # before this can be enabled.
-  hardcode_into_libs=yes
-
-  # Append ld.so.conf contents to the search path
-  if test -f /etc/ld.so.conf; then
-    lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \[$]2)); skip = 1; } { if (!skip) print \[$]0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[  ]*hwcap[        ]/d;s/[:,      ]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;/^$/d' | tr '\n' ' '`
-    sys_lib_dlsearch_path_spec="/lib /usr/lib $lt_ld_extra"
-  fi
-
-  # We used to test for /lib/ld.so.1 and disable shared libraries on
-  # powerpc, because MkLinux only supported shared libraries with the
-  # GNU dynamic linker.  Since this was broken with cross compilers,
-  # most powerpc-linux boxes support dynamic linking these days and
-  # people can always --disable-shared, the test was removed, and we
-  # assume the GNU/Linux dynamic linker is in use.
-  dynamic_linker='GNU/Linux ld.so'
-  ;;
-
-netbsdelf*-gnu)
-  version_type=linux
-  need_lib_prefix=no
-  need_version=no
-  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
-  soname_spec='${libname}${release}${shared_ext}$major'
-  shlibpath_var=LD_LIBRARY_PATH
-  shlibpath_overrides_runpath=no
-  hardcode_into_libs=yes
-  dynamic_linker='NetBSD ld.elf_so'
-  ;;
-
-netbsd*)
-  version_type=sunos
-  need_lib_prefix=no
-  need_version=no
-  if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
-    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
-    finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir'
-    dynamic_linker='NetBSD (a.out) ld.so'
-  else
-    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
-    soname_spec='${libname}${release}${shared_ext}$major'
-    dynamic_linker='NetBSD ld.elf_so'
-  fi
-  shlibpath_var=LD_LIBRARY_PATH
-  shlibpath_overrides_runpath=yes
-  hardcode_into_libs=yes
-  ;;
-
-newsos6)
-  version_type=linux
-  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
-  shlibpath_var=LD_LIBRARY_PATH
-  shlibpath_overrides_runpath=yes
-  ;;
-
-*nto* | *qnx*)
-  version_type=qnx
-  need_lib_prefix=no
-  need_version=no
-  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
-  soname_spec='${libname}${release}${shared_ext}$major'
-  shlibpath_var=LD_LIBRARY_PATH
-  shlibpath_overrides_runpath=no
-  hardcode_into_libs=yes
-  dynamic_linker='ldqnx.so'
-  ;;
-
-openbsd*)
-  version_type=sunos
-  sys_lib_dlsearch_path_spec="/usr/lib"
-  need_lib_prefix=no
-  # Some older versions of OpenBSD (3.3 at least) *do* need versioned libs.
-  case $host_os in
-    openbsd3.3 | openbsd3.3.*) need_version=yes ;;
-    *)                         need_version=no  ;;
-  esac
-  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
-  finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir'
-  shlibpath_var=LD_LIBRARY_PATH
-  if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
-    case $host_os in
-      openbsd2.[[89]] | openbsd2.[[89]].*)
-       shlibpath_overrides_runpath=no
-       ;;
-      *)
-       shlibpath_overrides_runpath=yes
-       ;;
-      esac
-  else
-    shlibpath_overrides_runpath=yes
-  fi
-  ;;
-
-os2*)
-  libname_spec='$name'
-  shrext_cmds=".dll"
-  need_lib_prefix=no
-  library_names_spec='$libname${shared_ext} $libname.a'
-  dynamic_linker='OS/2 ld.exe'
-  shlibpath_var=LIBPATH
-  ;;
-
-osf3* | osf4* | osf5*)
-  version_type=osf
-  need_lib_prefix=no
-  need_version=no
-  soname_spec='${libname}${release}${shared_ext}$major'
-  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
-  shlibpath_var=LD_LIBRARY_PATH
-  sys_lib_search_path_spec="/usr/shlib /usr/ccs/lib /usr/lib/cmplrs/cc /usr/lib /usr/local/lib /var/shlib"
-  sys_lib_dlsearch_path_spec="$sys_lib_search_path_spec"
-  ;;
-
-rdos*)
-  dynamic_linker=no
-  ;;
-
-solaris*)
-  version_type=linux
-  need_lib_prefix=no
-  need_version=no
-  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
-  soname_spec='${libname}${release}${shared_ext}$major'
-  shlibpath_var=LD_LIBRARY_PATH
-  shlibpath_overrides_runpath=yes
-  hardcode_into_libs=yes
-  # ldd complains unless libraries are executable
-  postinstall_cmds='chmod +x $lib'
-  ;;
-
-sunos4*)
-  version_type=sunos
-  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
-  finish_cmds='PATH="\$PATH:/usr/etc" ldconfig $libdir'
-  shlibpath_var=LD_LIBRARY_PATH
-  shlibpath_overrides_runpath=yes
-  if test "$with_gnu_ld" = yes; then
-    need_lib_prefix=no
-  fi
-  need_version=yes
-  ;;
-
-sysv4 | sysv4.3*)
-  version_type=linux
-  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
-  soname_spec='${libname}${release}${shared_ext}$major'
-  shlibpath_var=LD_LIBRARY_PATH
-  case $host_vendor in
-    sni)
-      shlibpath_overrides_runpath=no
-      need_lib_prefix=no
-      runpath_var=LD_RUN_PATH
-      ;;
-    siemens)
-      need_lib_prefix=no
-      ;;
-    motorola)
-      need_lib_prefix=no
-      need_version=no
-      shlibpath_overrides_runpath=no
-      sys_lib_search_path_spec='/lib /usr/lib /usr/ccs/lib'
-      ;;
-  esac
-  ;;
-
-sysv4*MP*)
-  if test -d /usr/nec ;then
-    version_type=linux
-    library_names_spec='$libname${shared_ext}.$versuffix $libname${shared_ext}.$major $libname${shared_ext}'
-    soname_spec='$libname${shared_ext}.$major'
-    shlibpath_var=LD_LIBRARY_PATH
-  fi
-  ;;
-
-sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*)
-  version_type=freebsd-elf
-  need_lib_prefix=no
-  need_version=no
-  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}'
-  soname_spec='${libname}${release}${shared_ext}$major'
-  shlibpath_var=LD_LIBRARY_PATH
-  shlibpath_overrides_runpath=yes
-  hardcode_into_libs=yes
-  if test "$with_gnu_ld" = yes; then
-    sys_lib_search_path_spec='/usr/local/lib /usr/gnu/lib /usr/ccs/lib /usr/lib /lib'
-  else
-    sys_lib_search_path_spec='/usr/ccs/lib /usr/lib'
-    case $host_os in
-      sco3.2v5*)
-        sys_lib_search_path_spec="$sys_lib_search_path_spec /lib"
-       ;;
-    esac
-  fi
-  sys_lib_dlsearch_path_spec='/usr/lib'
-  ;;
-
-tpf*)
-  # TPF is a cross-target only.  Preferred cross-host = GNU/Linux.
-  version_type=linux
-  need_lib_prefix=no
-  need_version=no
-  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
-  shlibpath_var=LD_LIBRARY_PATH
-  shlibpath_overrides_runpath=no
-  hardcode_into_libs=yes
-  ;;
-
-uts4*)
-  version_type=linux
-  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
-  soname_spec='${libname}${release}${shared_ext}$major'
-  shlibpath_var=LD_LIBRARY_PATH
-  ;;
-
-*)
-  dynamic_linker=no
-  ;;
-esac
-AC_MSG_RESULT([$dynamic_linker])
-test "$dynamic_linker" = no && can_build_shared=no
-
-variables_saved_for_relink="PATH $shlibpath_var $runpath_var"
-if test "$GCC" = yes; then
-  variables_saved_for_relink="$variables_saved_for_relink GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH"
-fi
-
-if test "${lt_cv_sys_lib_search_path_spec+set}" = set; then
-  sys_lib_search_path_spec="$lt_cv_sys_lib_search_path_spec"
-fi
-if test "${lt_cv_sys_lib_dlsearch_path_spec+set}" = set; then
-  sys_lib_dlsearch_path_spec="$lt_cv_sys_lib_dlsearch_path_spec"
-fi
-
-_LT_DECL([], [variables_saved_for_relink], [1],
-    [Variables whose values should be saved in libtool wrapper scripts and
-    restored at link time])
-_LT_DECL([], [need_lib_prefix], [0],
-    [Do we need the "lib" prefix for modules?])
-_LT_DECL([], [need_version], [0], [Do we need a version for libraries?])
-_LT_DECL([], [version_type], [0], [Library versioning type])
-_LT_DECL([], [runpath_var], [0],  [Shared library runtime path variable])
-_LT_DECL([], [shlibpath_var], [0],[Shared library path variable])
-_LT_DECL([], [shlibpath_overrides_runpath], [0],
-    [Is shlibpath searched before the hard-coded library search path?])
-_LT_DECL([], [libname_spec], [1], [Format of library name prefix])
-_LT_DECL([], [library_names_spec], [1],
-    [[List of archive names.  First name is the real one, the rest are links.
-    The last name is the one that the linker finds with -lNAME]])
-_LT_DECL([], [soname_spec], [1],
-    [[The coded name of the library, if different from the real name]])
-_LT_DECL([], [postinstall_cmds], [2],
-    [Command to use after installation of a shared archive])
-_LT_DECL([], [postuninstall_cmds], [2],
-    [Command to use after uninstallation of a shared archive])
-_LT_DECL([], [finish_cmds], [2],
-    [Commands used to finish a libtool library installation in a directory])
-_LT_DECL([], [finish_eval], [1],
-    [[As "finish_cmds", except a single script fragment to be evaled but
-    not shown]])
-_LT_DECL([], [hardcode_into_libs], [0],
-    [Whether we should hardcode library paths into libraries])
-_LT_DECL([], [sys_lib_search_path_spec], [2],
-    [Compile-time system search path for libraries])
-_LT_DECL([], [sys_lib_dlsearch_path_spec], [2],
-    [Run-time system search path for libraries])
-])# _LT_SYS_DYNAMIC_LINKER
-
-
-# _LT_PATH_TOOL_PREFIX(TOOL)
-# --------------------------
-# find a file program which can recognize shared library
-AC_DEFUN([_LT_PATH_TOOL_PREFIX],
-[m4_require([_LT_DECL_EGREP])dnl
-AC_MSG_CHECKING([for $1])
-AC_CACHE_VAL(lt_cv_path_MAGIC_CMD,
-[case $MAGIC_CMD in
-[[\\/*] |  ?:[\\/]*])
-  lt_cv_path_MAGIC_CMD="$MAGIC_CMD" # Let the user override the test with a path.
-  ;;
-*)
-  lt_save_MAGIC_CMD="$MAGIC_CMD"
-  lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
-dnl $ac_dummy forces splitting on constant user-supplied paths.
-dnl POSIX.2 word splitting is done only on the output of word expansions,
-dnl not every word.  This closes a longstanding sh security hole.
-  ac_dummy="m4_if([$2], , $PATH, [$2])"
-  for ac_dir in $ac_dummy; do
-    IFS="$lt_save_ifs"
-    test -z "$ac_dir" && ac_dir=.
-    if test -f $ac_dir/$1; then
-      lt_cv_path_MAGIC_CMD="$ac_dir/$1"
-      if test -n "$file_magic_test_file"; then
-       case $deplibs_check_method in
-       "file_magic "*)
-         file_magic_regex=`expr "$deplibs_check_method" : "file_magic \(.*\)"`
-         MAGIC_CMD="$lt_cv_path_MAGIC_CMD"
-         if eval $file_magic_cmd \$file_magic_test_file 2> /dev/null |
-           $EGREP "$file_magic_regex" > /dev/null; then
-           :
-         else
-           cat <<_LT_EOF 1>&2
-
-*** Warning: the command libtool uses to detect shared libraries,
-*** $file_magic_cmd, produces output that libtool cannot recognize.
-*** The result is that libtool may fail to recognize shared libraries
-*** as such.  This will affect the creation of libtool libraries that
-*** depend on shared libraries, but programs linked with such libtool
-*** libraries will work regardless of this problem.  Nevertheless, you
-*** may want to report the problem to your system manager and/or to
-*** bug-libtool@gnu.org
-
-_LT_EOF
-         fi ;;
-       esac
-      fi
-      break
-    fi
-  done
-  IFS="$lt_save_ifs"
-  MAGIC_CMD="$lt_save_MAGIC_CMD"
-  ;;
-esac])
-MAGIC_CMD="$lt_cv_path_MAGIC_CMD"
-if test -n "$MAGIC_CMD"; then
-  AC_MSG_RESULT($MAGIC_CMD)
-else
-  AC_MSG_RESULT(no)
-fi
-_LT_DECL([], [MAGIC_CMD], [0],
-        [Used to examine libraries when file_magic_cmd begins with "file"])dnl
-])# _LT_PATH_TOOL_PREFIX
-
-# Old name:
-AU_ALIAS([AC_PATH_TOOL_PREFIX], [_LT_PATH_TOOL_PREFIX])
-dnl aclocal-1.4 backwards compatibility:
-dnl AC_DEFUN([AC_PATH_TOOL_PREFIX], [])
-
-
-# _LT_PATH_MAGIC
-# --------------
-# find a file program which can recognize a shared library
-m4_defun([_LT_PATH_MAGIC],
-[_LT_PATH_TOOL_PREFIX(${ac_tool_prefix}file, /usr/bin$PATH_SEPARATOR$PATH)
-if test -z "$lt_cv_path_MAGIC_CMD"; then
-  if test -n "$ac_tool_prefix"; then
-    _LT_PATH_TOOL_PREFIX(file, /usr/bin$PATH_SEPARATOR$PATH)
-  else
-    MAGIC_CMD=:
-  fi
-fi
-])# _LT_PATH_MAGIC
-
-
-# LT_PATH_LD
-# ----------
-# find the pathname to the GNU or non-GNU linker
-AC_DEFUN([LT_PATH_LD],
-[AC_REQUIRE([AC_PROG_CC])dnl
-AC_REQUIRE([AC_CANONICAL_HOST])dnl
-AC_REQUIRE([AC_CANONICAL_BUILD])dnl
-m4_require([_LT_DECL_SED])dnl
-m4_require([_LT_DECL_EGREP])dnl
-
-AC_ARG_WITH([gnu-ld],
-    [AS_HELP_STRING([--with-gnu-ld],
-       [assume the C compiler uses GNU ld @<:@default=no@:>@])],
-    [test "$withval" = no || with_gnu_ld=yes],
-    [with_gnu_ld=no])dnl
-
-ac_prog=ld
-if test "$GCC" = yes; then
-  # Check if gcc -print-prog-name=ld gives a path.
-  AC_MSG_CHECKING([for ld used by $CC])
-  case $host in
-  *-*-mingw*)
-    # gcc leaves a trailing carriage return which upsets mingw
-    ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;;
-  *)
-    ac_prog=`($CC -print-prog-name=ld) 2>&5` ;;
-  esac
-  case $ac_prog in
-    # Accept absolute paths.
-    [[\\/]]* | ?:[[\\/]]*)
-      re_direlt='/[[^/]][[^/]]*/\.\./'
-      # Canonicalize the pathname of ld
-      ac_prog=`$ECHO "$ac_prog"| $SED 's%\\\\%/%g'`
-      while $ECHO "$ac_prog" | $GREP "$re_direlt" > /dev/null 2>&1; do
-       ac_prog=`$ECHO $ac_prog| $SED "s%$re_direlt%/%"`
-      done
-      test -z "$LD" && LD="$ac_prog"
-      ;;
-  "")
-    # If it fails, then pretend we aren't using GCC.
-    ac_prog=ld
-    ;;
-  *)
-    # If it is relative, then search for the first ld in PATH.
-    with_gnu_ld=unknown
-    ;;
-  esac
-elif test "$with_gnu_ld" = yes; then
-  AC_MSG_CHECKING([for GNU ld])
-else
-  AC_MSG_CHECKING([for non-GNU ld])
-fi
-AC_CACHE_VAL(lt_cv_path_LD,
-[if test -z "$LD"; then
-  lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
-  for ac_dir in $PATH; do
-    IFS="$lt_save_ifs"
-    test -z "$ac_dir" && ac_dir=.
-    if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then
-      lt_cv_path_LD="$ac_dir/$ac_prog"
-      # Check to see if the program is GNU ld.  I'd rather use --version,
-      # but apparently some variants of GNU ld only accept -v.
-      # Break only if it was the GNU/non-GNU ld that we prefer.
-      case `"$lt_cv_path_LD" -v 2>&1 </dev/null` in
-      *GNU* | *'with BFD'*)
-       test "$with_gnu_ld" != no && break
-       ;;
-      *)
-       test "$with_gnu_ld" != yes && break
-       ;;
-      esac
-    fi
-  done
-  IFS="$lt_save_ifs"
-else
-  lt_cv_path_LD="$LD" # Let the user override the test with a path.
-fi])
-LD="$lt_cv_path_LD"
-if test -n "$LD"; then
-  AC_MSG_RESULT($LD)
-else
-  AC_MSG_RESULT(no)
-fi
-test -z "$LD" && AC_MSG_ERROR([no acceptable ld found in \$PATH])
-_LT_PATH_LD_GNU
-AC_SUBST([LD])
-
-_LT_TAGDECL([], [LD], [1], [The linker used to build libraries])
-])# LT_PATH_LD
-
-# Old names:
-AU_ALIAS([AM_PROG_LD], [LT_PATH_LD])
-AU_ALIAS([AC_PROG_LD], [LT_PATH_LD])
-dnl aclocal-1.4 backwards compatibility:
-dnl AC_DEFUN([AM_PROG_LD], [])
-dnl AC_DEFUN([AC_PROG_LD], [])
-
-
-# _LT_PATH_LD_GNU
-#- --------------
-m4_defun([_LT_PATH_LD_GNU],
-[AC_CACHE_CHECK([if the linker ($LD) is GNU ld], lt_cv_prog_gnu_ld,
-[# I'd rather use --version here, but apparently some GNU lds only accept -v.
-case `$LD -v 2>&1 </dev/null` in
-*GNU* | *'with BFD'*)
-  lt_cv_prog_gnu_ld=yes
-  ;;
-*)
-  lt_cv_prog_gnu_ld=no
-  ;;
-esac])
-with_gnu_ld=$lt_cv_prog_gnu_ld
-])# _LT_PATH_LD_GNU
-
-
-# _LT_CMD_RELOAD
-# --------------
-# find reload flag for linker
-#   -- PORTME Some linkers may need a different reload flag.
-m4_defun([_LT_CMD_RELOAD],
-[AC_CACHE_CHECK([for $LD option to reload object files],
-  lt_cv_ld_reload_flag,
-  [lt_cv_ld_reload_flag='-r'])
-reload_flag=$lt_cv_ld_reload_flag
-case $reload_flag in
-"" | " "*) ;;
-*) reload_flag=" $reload_flag" ;;
-esac
-reload_cmds='$LD$reload_flag -o $output$reload_objs'
-case $host_os in
-  darwin*)
-    if test "$GCC" = yes; then
-      reload_cmds='$LTCC $LTCFLAGS -nostdlib ${wl}-r -o $output$reload_objs'
-    else
-      reload_cmds='$LD$reload_flag -o $output$reload_objs'
-    fi
-    ;;
-esac
-_LT_DECL([], [reload_flag], [1], [How to create reloadable object files])dnl
-_LT_DECL([], [reload_cmds], [2])dnl
-])# _LT_CMD_RELOAD
-
-
-# _LT_CHECK_MAGIC_METHOD
-# ----------------------
-# how to check for library dependencies
-#  -- PORTME fill in with the dynamic library characteristics
-m4_defun([_LT_CHECK_MAGIC_METHOD],
-[m4_require([_LT_DECL_EGREP])
-m4_require([_LT_DECL_OBJDUMP])
-AC_CACHE_CHECK([how to recognize dependent libraries],
-lt_cv_deplibs_check_method,
-[lt_cv_file_magic_cmd='$MAGIC_CMD'
-lt_cv_file_magic_test_file=
-lt_cv_deplibs_check_method='unknown'
-# Need to set the preceding variable on all platforms that support
-# interlibrary dependencies.
-# 'none' -- dependencies not supported.
-# `unknown' -- same as none, but documents that we really don't know.
-# 'pass_all' -- all dependencies passed with no checks.
-# 'test_compile' -- check by making test program.
-# 'file_magic [[regex]]' -- check by looking for files in library path
-# which responds to the $file_magic_cmd with a given extended regex.
-# If you have `file' or equivalent on your system and you're not sure
-# whether `pass_all' will *always* work, you probably want this one.
-
-case $host_os in
-aix[[4-9]]*)
-  lt_cv_deplibs_check_method=pass_all
-  ;;
-
-beos*)
-  lt_cv_deplibs_check_method=pass_all
-  ;;
-
-bsdi[[45]]*)
-  lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (shared object|dynamic lib)'
-  lt_cv_file_magic_cmd='/usr/bin/file -L'
-  lt_cv_file_magic_test_file=/shlib/libc.so
-  ;;
-
-cygwin*)
-  # func_win32_libid is a shell function defined in ltmain.sh
-  lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL'
-  lt_cv_file_magic_cmd='func_win32_libid'
-  ;;
-
-mingw* | pw32*)
-  # Base MSYS/MinGW do not provide the 'file' command needed by
-  # func_win32_libid shell function, so use a weaker test based on 'objdump',
-  # unless we find 'file', for example because we are cross-compiling.
-  if ( file / ) >/dev/null 2>&1; then
-    lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL'
-    lt_cv_file_magic_cmd='func_win32_libid'
-  else
-    lt_cv_deplibs_check_method='file_magic file format pei*-i386(.*architecture: i386)?'
-    lt_cv_file_magic_cmd='$OBJDUMP -f'
-  fi
-  ;;
-
-cegcc)
-  # use the weaker test based on 'objdump'. See mingw*.
-  lt_cv_deplibs_check_method='file_magic file format pe-arm-.*little(.*architecture: arm)?'
-  lt_cv_file_magic_cmd='$OBJDUMP -f'
-  ;;
-
-darwin* | rhapsody*)
-  lt_cv_deplibs_check_method=pass_all
-  ;;
-
-freebsd* | dragonfly*)
-  if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then
-    case $host_cpu in
-    i*86 )
-      # Not sure whether the presence of OpenBSD here was a mistake.
-      # Let's accept both of them until this is cleared up.
-      lt_cv_deplibs_check_method='file_magic (FreeBSD|OpenBSD|DragonFly)/i[[3-9]]86 (compact )?demand paged shared library'
-      lt_cv_file_magic_cmd=/usr/bin/file
-      lt_cv_file_magic_test_file=`echo /usr/lib/libc.so.*`
-      ;;
-    esac
-  else
-    lt_cv_deplibs_check_method=pass_all
-  fi
-  ;;
-
-gnu*)
-  lt_cv_deplibs_check_method=pass_all
-  ;;
-
-hpux10.20* | hpux11*)
-  lt_cv_file_magic_cmd=/usr/bin/file
-  case $host_cpu in
-  ia64*)
-    lt_cv_deplibs_check_method='file_magic (s[[0-9]][[0-9]][[0-9]]|ELF-[[0-9]][[0-9]]) shared object file - IA64'
-    lt_cv_file_magic_test_file=/usr/lib/hpux32/libc.so
-    ;;
-  hppa*64*)
-    [lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF-[0-9][0-9]) shared object file - PA-RISC [0-9].[0-9]']
-    lt_cv_file_magic_test_file=/usr/lib/pa20_64/libc.sl
-    ;;
-  *)
-    lt_cv_deplibs_check_method='file_magic (s[[0-9]][[0-9]][[0-9]]|PA-RISC[[0-9]].[[0-9]]) shared library'
-    lt_cv_file_magic_test_file=/usr/lib/libc.sl
-    ;;
-  esac
-  ;;
-
-interix[[3-9]]*)
-  # PIC code is broken on Interix 3.x, that's why |\.a not |_pic\.a here
-  lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so|\.a)$'
-  ;;
-
-irix5* | irix6* | nonstopux*)
-  case $LD in
-  *-32|*"-32 ") libmagic=32-bit;;
-  *-n32|*"-n32 ") libmagic=N32;;
-  *-64|*"-64 ") libmagic=64-bit;;
-  *) libmagic=never-match;;
-  esac
-  lt_cv_deplibs_check_method=pass_all
-  ;;
-
-# This must be Linux ELF.
-linux* | k*bsd*-gnu | kopensolaris*-gnu)
-  lt_cv_deplibs_check_method=pass_all
-  ;;
-
-netbsd* | netbsdelf*-gnu)
-  if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then
-    lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$'
-  else
-    lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so|_pic\.a)$'
-  fi
-  ;;
-
-newos6*)
-  lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (executable|dynamic lib)'
-  lt_cv_file_magic_cmd=/usr/bin/file
-  lt_cv_file_magic_test_file=/usr/lib/libnls.so
-  ;;
-
-*nto* | *qnx*)
-  lt_cv_deplibs_check_method=pass_all
-  ;;
-
-openbsd*)
-  if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
-    lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|\.so|_pic\.a)$'
-  else
-    lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$'
-  fi
-  ;;
-
-osf3* | osf4* | osf5*)
-  lt_cv_deplibs_check_method=pass_all
-  ;;
-
-rdos*)
-  lt_cv_deplibs_check_method=pass_all
-  ;;
-
-solaris*)
-  lt_cv_deplibs_check_method=pass_all
-  ;;
-
-sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*)
-  lt_cv_deplibs_check_method=pass_all
-  ;;
-
-sysv4 | sysv4.3*)
-  case $host_vendor in
-  motorola)
-    lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (shared object|dynamic lib) M[[0-9]][[0-9]]* Version [[0-9]]'
-    lt_cv_file_magic_test_file=`echo /usr/lib/libc.so*`
-    ;;
-  ncr)
-    lt_cv_deplibs_check_method=pass_all
-    ;;
-  sequent)
-    lt_cv_file_magic_cmd='/bin/file'
-    lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[LM]]SB (shared object|dynamic lib )'
-    ;;
-  sni)
-    lt_cv_file_magic_cmd='/bin/file'
-    lt_cv_deplibs_check_method="file_magic ELF [[0-9]][[0-9]]*-bit [[LM]]SB dynamic lib"
-    lt_cv_file_magic_test_file=/lib/libc.so
-    ;;
-  siemens)
-    lt_cv_deplibs_check_method=pass_all
-    ;;
-  pc)
-    lt_cv_deplibs_check_method=pass_all
-    ;;
-  esac
-  ;;
-
-tpf*)
-  lt_cv_deplibs_check_method=pass_all
-  ;;
-esac
-])
-file_magic_cmd=$lt_cv_file_magic_cmd
-deplibs_check_method=$lt_cv_deplibs_check_method
-test -z "$deplibs_check_method" && deplibs_check_method=unknown
-
-_LT_DECL([], [deplibs_check_method], [1],
-    [Method to check whether dependent libraries are shared objects])
-_LT_DECL([], [file_magic_cmd], [1],
-    [Command to use when deplibs_check_method == "file_magic"])
-])# _LT_CHECK_MAGIC_METHOD
-
-
-# LT_PATH_NM
-# ----------
-# find the pathname to a BSD- or MS-compatible name lister
-AC_DEFUN([LT_PATH_NM],
-[AC_REQUIRE([AC_PROG_CC])dnl
-AC_CACHE_CHECK([for BSD- or MS-compatible name lister (nm)], lt_cv_path_NM,
-[if test -n "$NM"; then
-  # Let the user override the test.
-  lt_cv_path_NM="$NM"
-else
-  lt_nm_to_check="${ac_tool_prefix}nm"
-  if test -n "$ac_tool_prefix" && test "$build" = "$host"; then
-    lt_nm_to_check="$lt_nm_to_check nm"
-  fi
-  for lt_tmp_nm in $lt_nm_to_check; do
-    lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
-    for ac_dir in $PATH /usr/ccs/bin/elf /usr/ccs/bin /usr/ucb /bin; do
-      IFS="$lt_save_ifs"
-      test -z "$ac_dir" && ac_dir=.
-      tmp_nm="$ac_dir/$lt_tmp_nm"
-      if test -f "$tmp_nm" || test -f "$tmp_nm$ac_exeext" ; then
-       # Check to see if the nm accepts a BSD-compat flag.
-       # Adding the `sed 1q' prevents false positives on HP-UX, which says:
-       #   nm: unknown option "B" ignored
-       # Tru64's nm complains that /dev/null is an invalid object file
-       case `"$tmp_nm" -B /dev/null 2>&1 | sed '1q'` in
-       */dev/null* | *'Invalid file or object type'*)
-         lt_cv_path_NM="$tmp_nm -B"
-         break
-         ;;
-       *)
-         case `"$tmp_nm" -p /dev/null 2>&1 | sed '1q'` in
-         */dev/null*)
-           lt_cv_path_NM="$tmp_nm -p"
-           break
-           ;;
-         *)
-           lt_cv_path_NM=${lt_cv_path_NM="$tmp_nm"} # keep the first match, but
-           continue # so that we can try to find one that supports BSD flags
-           ;;
-         esac
-         ;;
-       esac
-      fi
-    done
-    IFS="$lt_save_ifs"
-  done
-  : ${lt_cv_path_NM=no}
-fi])
-if test "$lt_cv_path_NM" != "no"; then
-  NM="$lt_cv_path_NM"
-else
-  # Didn't find any BSD compatible name lister, look for dumpbin.
-  AC_CHECK_TOOLS(DUMPBIN, ["dumpbin -symbols" "link -dump -symbols"], :)
-  AC_SUBST([DUMPBIN])
-  if test "$DUMPBIN" != ":"; then
-    NM="$DUMPBIN"
-  fi
-fi
-test -z "$NM" && NM=nm
-AC_SUBST([NM])
-_LT_DECL([], [NM], [1], [A BSD- or MS-compatible name lister])dnl
-
-AC_CACHE_CHECK([the name lister ($NM) interface], [lt_cv_nm_interface],
-  [lt_cv_nm_interface="BSD nm"
-  echo "int some_variable = 0;" > conftest.$ac_ext
-  (eval echo "\"\$as_me:__oline__: $ac_compile\"" >&AS_MESSAGE_LOG_FD)
-  (eval "$ac_compile" 2>conftest.err)
-  cat conftest.err >&AS_MESSAGE_LOG_FD
-  (eval echo "\"\$as_me:__oline__: $NM \\\"conftest.$ac_objext\\\"\"" >&AS_MESSAGE_LOG_FD)
-  (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out)
-  cat conftest.err >&AS_MESSAGE_LOG_FD
-  (eval echo "\"\$as_me:__oline__: output\"" >&AS_MESSAGE_LOG_FD)
-  cat conftest.out >&AS_MESSAGE_LOG_FD
-  if $GREP 'External.*some_variable' conftest.out > /dev/null; then
-    lt_cv_nm_interface="MS dumpbin"
-  fi
-  rm -f conftest*])
-])# LT_PATH_NM
-
-# Old names:
-AU_ALIAS([AM_PROG_NM], [LT_PATH_NM])
-AU_ALIAS([AC_PROG_NM], [LT_PATH_NM])
-dnl aclocal-1.4 backwards compatibility:
-dnl AC_DEFUN([AM_PROG_NM], [])
-dnl AC_DEFUN([AC_PROG_NM], [])
-
-
-# LT_LIB_M
-# --------
-# check for math library
-AC_DEFUN([LT_LIB_M],
-[AC_REQUIRE([AC_CANONICAL_HOST])dnl
-LIBM=
-case $host in
-*-*-beos* | *-*-cygwin* | *-*-pw32* | *-*-darwin*)
-  # These system don't have libm, or don't need it
-  ;;
-*-ncr-sysv4.3*)
-  AC_CHECK_LIB(mw, _mwvalidcheckl, LIBM="-lmw")
-  AC_CHECK_LIB(m, cos, LIBM="$LIBM -lm")
-  ;;
-*)
-  AC_CHECK_LIB(m, cos, LIBM="-lm")
-  ;;
-esac
-AC_SUBST([LIBM])
-])# LT_LIB_M
-
-# Old name:
-AU_ALIAS([AC_CHECK_LIBM], [LT_LIB_M])
-dnl aclocal-1.4 backwards compatibility:
-dnl AC_DEFUN([AC_CHECK_LIBM], [])
-
-
-# _LT_COMPILER_NO_RTTI([TAGNAME])
-# -------------------------------
-m4_defun([_LT_COMPILER_NO_RTTI],
-[m4_require([_LT_TAG_COMPILER])dnl
-
-_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=
-
-if test "$GCC" = yes; then
-  _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=' -fno-builtin'
-
-  _LT_COMPILER_OPTION([if $compiler supports -fno-rtti -fno-exceptions],
-    lt_cv_prog_compiler_rtti_exceptions,
-    [-fno-rtti -fno-exceptions], [],
-    [_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)="$_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1) -fno-rtti -fno-exceptions"])
-fi
-_LT_TAGDECL([no_builtin_flag], [lt_prog_compiler_no_builtin_flag], [1],
-       [Compiler flag to turn off builtin functions])
-])# _LT_COMPILER_NO_RTTI
-
-
-# _LT_CMD_GLOBAL_SYMBOLS
-# ----------------------
-m4_defun([_LT_CMD_GLOBAL_SYMBOLS],
-[AC_REQUIRE([AC_CANONICAL_HOST])dnl
-AC_REQUIRE([AC_PROG_CC])dnl
-AC_REQUIRE([LT_PATH_NM])dnl
-AC_REQUIRE([LT_PATH_LD])dnl
-m4_require([_LT_DECL_SED])dnl
-m4_require([_LT_DECL_EGREP])dnl
-m4_require([_LT_TAG_COMPILER])dnl
-
-# Check for command to grab the raw symbol name followed by C symbol from nm.
-AC_MSG_CHECKING([command to parse $NM output from $compiler object])
-AC_CACHE_VAL([lt_cv_sys_global_symbol_pipe],
-[
-# These are sane defaults that work on at least a few old systems.
-# [They come from Ultrix.  What could be older than Ultrix?!! ;)]
-
-# Character class describing NM global symbol codes.
-symcode='[[BCDEGRST]]'
-
-# Regexp to match symbols that can be accessed directly from C.
-sympat='\([[_A-Za-z]][[_A-Za-z0-9]]*\)'
-
-# Define system-specific variables.
-case $host_os in
-aix*)
-  symcode='[[BCDT]]'
-  ;;
-cygwin* | mingw* | pw32* | cegcc*)
-  symcode='[[ABCDGISTW]]'
-  ;;
-hpux*)
-  if test "$host_cpu" = ia64; then
-    symcode='[[ABCDEGRST]]'
-  fi
-  ;;
-irix* | nonstopux*)
-  symcode='[[BCDEGRST]]'
-  ;;
-osf*)
-  symcode='[[BCDEGQRST]]'
-  ;;
-solaris*)
-  symcode='[[BDRT]]'
-  ;;
-sco3.2v5*)
-  symcode='[[DT]]'
-  ;;
-sysv4.2uw2*)
-  symcode='[[DT]]'
-  ;;
-sysv5* | sco5v6* | unixware* | OpenUNIX*)
-  symcode='[[ABDT]]'
-  ;;
-sysv4)
-  symcode='[[DFNSTU]]'
-  ;;
-esac
-
-# If we're using GNU nm, then use its standard symbol codes.
-case `$NM -V 2>&1` in
-*GNU* | *'with BFD'*)
-  symcode='[[ABCDGIRSTW]]' ;;
-esac
-
-# Transform an extracted symbol line into a proper C declaration.
-# Some systems (esp. on ia64) link data and code symbols differently,
-# so use this general approach.
-lt_cv_sys_global_symbol_to_cdecl="sed -n -e 's/^T .* \(.*\)$/extern int \1();/p' -e 's/^$symcode* .* \(.*\)$/extern char \1;/p'"
-
-# Transform an extracted symbol line into symbol name and symbol address
-lt_cv_sys_global_symbol_to_c_name_address="sed -n -e 's/^: \([[^ ]]*\) $/  {\\\"\1\\\", (void *) 0},/p' -e 's/^$symcode* \([[^ ]]*\) \([[^ ]]*\)$/  {\"\2\", (void *) \&\2},/p'"
-lt_cv_sys_global_symbol_to_c_name_address_lib_prefix="sed -n -e 's/^: \([[^ ]]*\) $/  {\\\"\1\\\", (void *) 0},/p' -e 's/^$symcode* \([[^ ]]*\) \(lib[[^ ]]*\)$/  {\"\2\", (void *) \&\2},/p' -e 's/^$symcode* \([[^ ]]*\) \([[^ ]]*\)$/  {\"lib\2\", (void *) \&\2},/p'"
-
-# Handle CRLF in mingw tool chain
-opt_cr=
-case $build_os in
-mingw*)
-  opt_cr=`$ECHO 'x\{0,1\}' | tr x '\015'` # option cr in regexp
-  ;;
-esac
-
-# Try without a prefix underscore, then with it.
-for ac_symprfx in "" "_"; do
-
-  # Transform symcode, sympat, and symprfx into a raw symbol and a C symbol.
-  symxfrm="\\1 $ac_symprfx\\2 \\2"
-
-  # Write the raw and C identifiers.
-  if test "$lt_cv_nm_interface" = "MS dumpbin"; then
-    # Fake it for dumpbin and say T for any non-static function
-    # and D for any global variable.
-    # Also find C++ and __fastcall symbols from MSVC++,
-    # which start with @ or ?.
-    lt_cv_sys_global_symbol_pipe="$AWK ['"\
-"     {last_section=section; section=\$ 3};"\
-"     /Section length .*#relocs.*(pick any)/{hide[last_section]=1};"\
-"     \$ 0!~/External *\|/{next};"\
-"     / 0+ UNDEF /{next}; / UNDEF \([^|]\)*()/{next};"\
-"     {if(hide[section]) next};"\
-"     {f=0}; \$ 0~/\(\).*\|/{f=1}; {printf f ? \"T \" : \"D \"};"\
-"     {split(\$ 0, a, /\||\r/); split(a[2], s)};"\
-"     s[1]~/^[@?]/{print s[1], s[1]; next};"\
-"     s[1]~prfx {split(s[1],t,\"@\"); print t[1], substr(t[1],length(prfx))}"\
-"     ' prfx=^$ac_symprfx]"
-  else
-    lt_cv_sys_global_symbol_pipe="sed -n -e 's/^.*[[    ]]\($symcode$symcode*\)[[       ]][[    ]]*$ac_symprfx$sympat$opt_cr$/$symxfrm/p'"
-  fi
-
-  # Check to see that the pipe works correctly.
-  pipe_works=no
-
-  rm -f conftest*
-  cat > conftest.$ac_ext <<_LT_EOF
-#ifdef __cplusplus
-extern "C" {
-#endif
-char nm_test_var;
-void nm_test_func(void);
-void nm_test_func(void){}
-#ifdef __cplusplus
-}
-#endif
-int main(){nm_test_var='a';nm_test_func();return(0);}
-_LT_EOF
-
-  if AC_TRY_EVAL(ac_compile); then
-    # Now try to grab the symbols.
-    nlist=conftest.nm
-    if AC_TRY_EVAL(NM conftest.$ac_objext \| $lt_cv_sys_global_symbol_pipe \> $nlist) && test -s "$nlist"; then
-      # Try sorting and uniquifying the output.
-      if sort "$nlist" | uniq > "$nlist"T; then
-       mv -f "$nlist"T "$nlist"
-      else
-       rm -f "$nlist"T
-      fi
-
-      # Make sure that we snagged all the symbols we need.
-      if $GREP ' nm_test_var$' "$nlist" >/dev/null; then
-       if $GREP ' nm_test_func$' "$nlist" >/dev/null; then
-         cat <<_LT_EOF > conftest.$ac_ext
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-_LT_EOF
-         # Now generate the symbol file.
-         eval "$lt_cv_sys_global_symbol_to_cdecl"' < "$nlist" | $GREP -v main >> conftest.$ac_ext'
-
-         cat <<_LT_EOF >> conftest.$ac_ext
-
-/* The mapping between symbol names and symbols.  */
-const struct {
-  const char *name;
-  void       *address;
-}
-lt__PROGRAM__LTX_preloaded_symbols[[]] =
-{
-  { "@PROGRAM@", (void *) 0 },
-_LT_EOF
-         $SED "s/^$symcode$symcode* \(.*\) \(.*\)$/  {\"\2\", (void *) \&\2},/" < "$nlist" | $GREP -v main >> conftest.$ac_ext
-         cat <<\_LT_EOF >> conftest.$ac_ext
-  {0, (void *) 0}
-};
-
-/* This works around a problem in FreeBSD linker */
-#ifdef FREEBSD_WORKAROUND
-static const void *lt_preloaded_setup() {
-  return lt__PROGRAM__LTX_preloaded_symbols;
-}
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-_LT_EOF
-         # Now try linking the two files.
-         mv conftest.$ac_objext conftstm.$ac_objext
-         lt_save_LIBS="$LIBS"
-         lt_save_CFLAGS="$CFLAGS"
-         LIBS="conftstm.$ac_objext"
-         CFLAGS="$CFLAGS$_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)"
-         if AC_TRY_EVAL(ac_link) && test -s conftest${ac_exeext}; then
-           pipe_works=yes
-         fi
-         LIBS="$lt_save_LIBS"
-         CFLAGS="$lt_save_CFLAGS"
-       else
-         echo "cannot find nm_test_func in $nlist" >&AS_MESSAGE_LOG_FD
-       fi
-      else
-       echo "cannot find nm_test_var in $nlist" >&AS_MESSAGE_LOG_FD
-      fi
-    else
-      echo "cannot run $lt_cv_sys_global_symbol_pipe" >&AS_MESSAGE_LOG_FD
-    fi
-  else
-    echo "$progname: failed program was:" >&AS_MESSAGE_LOG_FD
-    cat conftest.$ac_ext >&5
-  fi
-  rm -rf conftest* conftst*
-
-  # Do not use the global_symbol_pipe unless it works.
-  if test "$pipe_works" = yes; then
-    break
-  else
-    lt_cv_sys_global_symbol_pipe=
-  fi
-done
-])
-if test -z "$lt_cv_sys_global_symbol_pipe"; then
-  lt_cv_sys_global_symbol_to_cdecl=
-fi
-if test -z "$lt_cv_sys_global_symbol_pipe$lt_cv_sys_global_symbol_to_cdecl"; then
-  AC_MSG_RESULT(failed)
-else
-  AC_MSG_RESULT(ok)
-fi
-
-_LT_DECL([global_symbol_pipe], [lt_cv_sys_global_symbol_pipe], [1],
-    [Take the output of nm and produce a listing of raw symbols and C names])
-_LT_DECL([global_symbol_to_cdecl], [lt_cv_sys_global_symbol_to_cdecl], [1],
-    [Transform the output of nm in a proper C declaration])
-_LT_DECL([global_symbol_to_c_name_address],
-    [lt_cv_sys_global_symbol_to_c_name_address], [1],
-    [Transform the output of nm in a C name address pair])
-_LT_DECL([global_symbol_to_c_name_address_lib_prefix],
-    [lt_cv_sys_global_symbol_to_c_name_address_lib_prefix], [1],
-    [Transform the output of nm in a C name address pair when lib prefix is needed])
-]) # _LT_CMD_GLOBAL_SYMBOLS
-
-
-# _LT_COMPILER_PIC([TAGNAME])
-# ---------------------------
-m4_defun([_LT_COMPILER_PIC],
-[m4_require([_LT_TAG_COMPILER])dnl
-_LT_TAGVAR(lt_prog_compiler_wl, $1)=
-_LT_TAGVAR(lt_prog_compiler_pic, $1)=
-_LT_TAGVAR(lt_prog_compiler_static, $1)=
-
-AC_MSG_CHECKING([for $compiler option to produce PIC])
-m4_if([$1], [CXX], [
-  # C++ specific cases for pic, static, wl, etc.
-  if test "$GXX" = yes; then
-    _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
-    _LT_TAGVAR(lt_prog_compiler_static, $1)='-static'
-
-    case $host_os in
-    aix*)
-      # All AIX code is PIC.
-      if test "$host_cpu" = ia64; then
-       # AIX 5 now supports IA64 processor
-       _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
-      fi
-      ;;
-
-    amigaos*)
-      case $host_cpu in
-      powerpc)
-            # see comment about AmigaOS4 .so support
-            _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
-        ;;
-      m68k)
-            # FIXME: we need at least 68020 code to build shared libraries, but
-            # adding the `-m68020' flag to GCC prevents building anything better,
-            # like `-m68040'.
-            _LT_TAGVAR(lt_prog_compiler_pic, $1)='-m68020 -resident32 -malways-restore-a4'
-        ;;
-      esac
-      ;;
-
-    beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*)
-      # PIC is the default for these OSes.
-      ;;
-    mingw* | cygwin* | os2* | pw32* | cegcc*)
-      # This hack is so that the source file can tell whether it is being
-      # built for inclusion in a dll (and should export symbols for example).
-      # Although the cygwin gcc ignores -fPIC, still need this for old-style
-      # (--disable-auto-import) libraries
-      m4_if([$1], [GCJ], [],
-       [_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT'])
-      ;;
-    darwin* | rhapsody*)
-      # PIC is the default on this platform
-      # Common symbols not allowed in MH_DYLIB files
-      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fno-common'
-      ;;
-    *djgpp*)
-      # DJGPP does not support shared libraries at all
-      _LT_TAGVAR(lt_prog_compiler_pic, $1)=
-      ;;
-    interix[[3-9]]*)
-      # Interix 3.x gcc -fpic/-fPIC options generate broken code.
-      # Instead, we relocate shared libraries at runtime.
-      ;;
-    sysv4*MP*)
-      if test -d /usr/nec; then
-       _LT_TAGVAR(lt_prog_compiler_pic, $1)=-Kconform_pic
-      fi
-      ;;
-    hpux*)
-      # PIC is the default for 64-bit PA HP-UX, but not for 32-bit
-      # PA HP-UX.  On IA64 HP-UX, PIC is the default but the pic flag
-      # sets the default TLS model and affects inlining.
-      case $host_cpu in
-      hppa*64*)
-       ;;
-      *)
-       _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
-       ;;
-      esac
-      ;;
-    *qnx* | *nto*)
-      # QNX uses GNU C++, but need to define -shared option too, otherwise
-      # it will coredump.
-      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared'
-      ;;
-    *)
-      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
-      ;;
-    esac
-  else
-    case $host_os in
-      aix[[4-9]]*)
-       # All AIX code is PIC.
-       if test "$host_cpu" = ia64; then
-         # AIX 5 now supports IA64 processor
-         _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
-       else
-         _LT_TAGVAR(lt_prog_compiler_static, $1)='-bnso -bI:/lib/syscalls.exp'
-       fi
-       ;;
-      chorus*)
-       case $cc_basename in
-       cxch68*)
-         # Green Hills C++ Compiler
-         # _LT_TAGVAR(lt_prog_compiler_static, $1)="--no_auto_instantiation -u __main -u __premain -u _abort -r $COOL_DIR/lib/libOrb.a $MVME_DIR/lib/CC/libC.a $MVME_DIR/lib/classix/libcx.s.a"
-         ;;
-       esac
-       ;;
-      dgux*)
-       case $cc_basename in
-         ec++*)
-           _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
-           ;;
-         ghcx*)
-           # Green Hills C++ Compiler
-           _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic'
-           ;;
-         *)
-           ;;
-       esac
-       ;;
-      freebsd* | dragonfly*)
-       # FreeBSD uses GNU C++
-       ;;
-      hpux9* | hpux10* | hpux11*)
-       case $cc_basename in
-         CC*)
-           _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
-           _LT_TAGVAR(lt_prog_compiler_static, $1)='${wl}-a ${wl}archive'
-           if test "$host_cpu" != ia64; then
-             _LT_TAGVAR(lt_prog_compiler_pic, $1)='+Z'
-           fi
-           ;;
-         aCC*)
-           _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
-           _LT_TAGVAR(lt_prog_compiler_static, $1)='${wl}-a ${wl}archive'
-           case $host_cpu in
-           hppa*64*|ia64*)
-             # +Z the default
-             ;;
-           *)
-             _LT_TAGVAR(lt_prog_compiler_pic, $1)='+Z'
-             ;;
-           esac
-           ;;
-         *)
-           ;;
-       esac
-       ;;
-      interix*)
-       # This is c89, which is MS Visual C++ (no shared libs)
-       # Anyone wants to do a port?
-       ;;
-      irix5* | irix6* | nonstopux*)
-       case $cc_basename in
-         CC*)
-           _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
-           _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
-           # CC pic flag -KPIC is the default.
-           ;;
-         *)
-           ;;
-       esac
-       ;;
-      linux* | k*bsd*-gnu | kopensolaris*-gnu)
-       case $cc_basename in
-         KCC*)
-           # KAI C++ Compiler
-           _LT_TAGVAR(lt_prog_compiler_wl, $1)='--backend -Wl,'
-           _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
-           ;;
-         ecpc* )
-           # old Intel C++ for x86_64 which still supported -KPIC.
-           _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
-           _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
-           _LT_TAGVAR(lt_prog_compiler_static, $1)='-static'
-           ;;
-         icpc* )
-           # Intel C++, used to be incompatible with GCC.
-           # ICC 10 doesn't accept -KPIC any more.
-           _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
-           _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
-           _LT_TAGVAR(lt_prog_compiler_static, $1)='-static'
-           ;;
-         pgCC* | pgcpp*)
-           # Portland Group C++ compiler
-           _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
-           _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fpic'
-           _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
-           ;;
-         cxx*)
-           # Compaq C++
-           # Make sure the PIC flag is empty.  It appears that all Alpha
-           # Linux and Compaq Tru64 Unix objects are PIC.
-           _LT_TAGVAR(lt_prog_compiler_pic, $1)=
-           _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
-           ;;
-         xlc* | xlC*)
-           # IBM XL 8.0 on PPC
-           _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
-           _LT_TAGVAR(lt_prog_compiler_pic, $1)='-qpic'
-           _LT_TAGVAR(lt_prog_compiler_static, $1)='-qstaticlink'
-           ;;
-         *)
-           case `$CC -V 2>&1 | sed 5q` in
-           *Sun\ C*)
-             # Sun C++ 5.9
-             _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
-             _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
-             _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld '
-             ;;
-           esac
-           ;;
-       esac
-       ;;
-      lynxos*)
-       ;;
-      m88k*)
-       ;;
-      mvs*)
-       case $cc_basename in
-         cxx*)
-           _LT_TAGVAR(lt_prog_compiler_pic, $1)='-W c,exportall'
-           ;;
-         *)
-           ;;
-       esac
-       ;;
-      netbsd* | netbsdelf*-gnu)
-       ;;
-      *qnx* | *nto*)
-        # QNX uses GNU C++, but need to define -shared option too, otherwise
-        # it will coredump.
-        _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared'
-        ;;
-      osf3* | osf4* | osf5*)
-       case $cc_basename in
-         KCC*)
-           _LT_TAGVAR(lt_prog_compiler_wl, $1)='--backend -Wl,'
-           ;;
-         RCC*)
-           # Rational C++ 2.4.1
-           _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic'
-           ;;
-         cxx*)
-           # Digital/Compaq C++
-           _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
-           # Make sure the PIC flag is empty.  It appears that all Alpha
-           # Linux and Compaq Tru64 Unix objects are PIC.
-           _LT_TAGVAR(lt_prog_compiler_pic, $1)=
-           _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
-           ;;
-         *)
-           ;;
-       esac
-       ;;
-      psos*)
-       ;;
-      solaris*)
-       case $cc_basename in
-         CC*)
-           # Sun C++ 4.2, 5.x and Centerline C++
-           _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
-           _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
-           _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld '
-           ;;
-         gcx*)
-           # Green Hills C++ Compiler
-           _LT_TAGVAR(lt_prog_compiler_pic, $1)='-PIC'
-           ;;
-         *)
-           ;;
-       esac
-       ;;
-      sunos4*)
-       case $cc_basename in
-         CC*)
-           # Sun C++ 4.x
-           _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic'
-           _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
-           ;;
-         lcc*)
-           # Lucid
-           _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic'
-           ;;
-         *)
-           ;;
-       esac
-       ;;
-      sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*)
-       case $cc_basename in
-         CC*)
-           _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
-           _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
-           _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
-           ;;
-       esac
-       ;;
-      tandem*)
-       case $cc_basename in
-         NCC*)
-           # NonStop-UX NCC 3.20
-           _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
-           ;;
-         *)
-           ;;
-       esac
-       ;;
-      vxworks*)
-       ;;
-      *)
-       _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no
-       ;;
-    esac
-  fi
-],
-[
-  if test "$GCC" = yes; then
-    _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
-    _LT_TAGVAR(lt_prog_compiler_static, $1)='-static'
-
-    case $host_os in
-      aix*)
-      # All AIX code is PIC.
-      if test "$host_cpu" = ia64; then
-       # AIX 5 now supports IA64 processor
-       _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
-      fi
-      ;;
-
-    amigaos*)
-      case $host_cpu in
-      powerpc)
-            # see comment about AmigaOS4 .so support
-            _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
-        ;;
-      m68k)
-            # FIXME: we need at least 68020 code to build shared libraries, but
-            # adding the `-m68020' flag to GCC prevents building anything better,
-            # like `-m68040'.
-            _LT_TAGVAR(lt_prog_compiler_pic, $1)='-m68020 -resident32 -malways-restore-a4'
-        ;;
-      esac
-      ;;
-
-    beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*)
-      # PIC is the default for these OSes.
-      ;;
-
-    mingw* | cygwin* | pw32* | os2* | cegcc*)
-      # This hack is so that the source file can tell whether it is being
-      # built for inclusion in a dll (and should export symbols for example).
-      # Although the cygwin gcc ignores -fPIC, still need this for old-style
-      # (--disable-auto-import) libraries
-      m4_if([$1], [GCJ], [],
-       [_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT'])
-      ;;
-
-    darwin* | rhapsody*)
-      # PIC is the default on this platform
-      # Common symbols not allowed in MH_DYLIB files
-      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fno-common'
-      ;;
-
-    hpux*)
-      # PIC is the default for 64-bit PA HP-UX, but not for 32-bit
-      # PA HP-UX.  On IA64 HP-UX, PIC is the default but the pic flag
-      # sets the default TLS model and affects inlining.
-      case $host_cpu in
-      hppa*64*)
-       # +Z the default
-       ;;
-      *)
-       _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
-       ;;
-      esac
-      ;;
-
-    interix[[3-9]]*)
-      # Interix 3.x gcc -fpic/-fPIC options generate broken code.
-      # Instead, we relocate shared libraries at runtime.
-      ;;
-
-    msdosdjgpp*)
-      # Just because we use GCC doesn't mean we suddenly get shared libraries
-      # on systems that don't support them.
-      _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no
-      enable_shared=no
-      ;;
-
-    *nto* | *qnx*)
-      # QNX uses GNU C++, but need to define -shared option too, otherwise
-      # it will coredump.
-      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared'
-      ;;
-
-    sysv4*MP*)
-      if test -d /usr/nec; then
-       _LT_TAGVAR(lt_prog_compiler_pic, $1)=-Kconform_pic
-      fi
-      ;;
-
-    *)
-      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
-      ;;
-    esac
-  else
-    # PORTME Check for flag to pass linker flags through the system compiler.
-    case $host_os in
-    aix*)
-      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
-      if test "$host_cpu" = ia64; then
-       # AIX 5 now supports IA64 processor
-       _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
-      else
-       _LT_TAGVAR(lt_prog_compiler_static, $1)='-bnso -bI:/lib/syscalls.exp'
-      fi
-      ;;
-
-    mingw* | cygwin* | pw32* | os2* | cegcc*)
-      # This hack is so that the source file can tell whether it is being
-      # built for inclusion in a dll (and should export symbols for example).
-      m4_if([$1], [GCJ], [],
-       [_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT'])
-      ;;
-
-    hpux9* | hpux10* | hpux11*)
-      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
-      # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but
-      # not for PA HP-UX.
-      case $host_cpu in
-      hppa*64*|ia64*)
-       # +Z the default
-       ;;
-      *)
-       _LT_TAGVAR(lt_prog_compiler_pic, $1)='+Z'
-       ;;
-      esac
-      # Is there a better lt_prog_compiler_static that works with the bundled CC?
-      _LT_TAGVAR(lt_prog_compiler_static, $1)='${wl}-a ${wl}archive'
-      ;;
-
-    irix5* | irix6* | nonstopux*)
-      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
-      # PIC (with -KPIC) is the default.
-      _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
-      ;;
-
-    linux* | k*bsd*-gnu | kopensolaris*-gnu)
-      case $cc_basename in
-      # old Intel for x86_64 which still supported -KPIC.
-      ecc*)
-       _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
-       _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
-       _LT_TAGVAR(lt_prog_compiler_static, $1)='-static'
-        ;;
-      # icc used to be incompatible with GCC.
-      # ICC 10 doesn't accept -KPIC any more.
-      icc* | ifort*)
-       _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
-       _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
-       _LT_TAGVAR(lt_prog_compiler_static, $1)='-static'
-        ;;
-      # Lahey Fortran 8.1.
-      lf95*)
-       _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
-       _LT_TAGVAR(lt_prog_compiler_pic, $1)='--shared'
-       _LT_TAGVAR(lt_prog_compiler_static, $1)='--static'
-       ;;
-      pgcc* | pgf77* | pgf90* | pgf95*)
-        # Portland Group compilers (*not* the Pentium gcc compiler,
-       # which looks to be a dead project)
-       _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
-       _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fpic'
-       _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
-        ;;
-      ccc*)
-        _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
-        # All Alpha code is PIC.
-        _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
-        ;;
-      xl*)
-       # IBM XL C 8.0/Fortran 10.1 on PPC
-       _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
-       _LT_TAGVAR(lt_prog_compiler_pic, $1)='-qpic'
-       _LT_TAGVAR(lt_prog_compiler_static, $1)='-qstaticlink'
-       ;;
-      *)
-       case `$CC -V 2>&1 | sed 5q` in
-       *Sun\ C*)
-         # Sun C 5.9
-         _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
-         _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
-         _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
-         ;;
-       *Sun\ F*)
-         # Sun Fortran 8.3 passes all unrecognized flags to the linker
-         _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
-         _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
-         _LT_TAGVAR(lt_prog_compiler_wl, $1)=''
-         ;;
-       esac
-       ;;
-      esac
-      ;;
-
-    newsos6)
-      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
-      _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
-      ;;
-
-    *nto* | *qnx*)
-      # QNX uses GNU C++, but need to define -shared option too, otherwise
-      # it will coredump.
-      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared'
-      ;;
-
-    osf3* | osf4* | osf5*)
-      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
-      # All OSF/1 code is PIC.
-      _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
-      ;;
-
-    rdos*)
-      _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
-      ;;
-
-    solaris*)
-      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
-      _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
-      case $cc_basename in
-      f77* | f90* | f95*)
-       _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ';;
-      *)
-       _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,';;
-      esac
-      ;;
-
-    sunos4*)
-      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld '
-      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-PIC'
-      _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
-      ;;
-
-    sysv4 | sysv4.2uw2* | sysv4.3*)
-      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
-      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
-      _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
-      ;;
-
-    sysv4*MP*)
-      if test -d /usr/nec ;then
-       _LT_TAGVAR(lt_prog_compiler_pic, $1)='-Kconform_pic'
-       _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
-      fi
-      ;;
-
-    sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*)
-      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
-      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
-      _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
-      ;;
-
-    unicos*)
-      _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
-      _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no
-      ;;
-
-    uts4*)
-      _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic'
-      _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
-      ;;
-
-    *)
-      _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no
-      ;;
-    esac
-  fi
-])
-case $host_os in
-  # For platforms which do not support PIC, -DPIC is meaningless:
-  *djgpp*)
-    _LT_TAGVAR(lt_prog_compiler_pic, $1)=
-    ;;
-  *)
-    _LT_TAGVAR(lt_prog_compiler_pic, $1)="$_LT_TAGVAR(lt_prog_compiler_pic, $1)@&t@m4_if([$1],[],[ -DPIC],[m4_if([$1],[CXX],[ -DPIC],[])])"
-    ;;
-esac
-AC_MSG_RESULT([$_LT_TAGVAR(lt_prog_compiler_pic, $1)])
-_LT_TAGDECL([wl], [lt_prog_compiler_wl], [1],
-       [How to pass a linker flag through the compiler])
-
-#
-# Check to make sure the PIC flag actually works.
-#
-if test -n "$_LT_TAGVAR(lt_prog_compiler_pic, $1)"; then
-  _LT_COMPILER_OPTION([if $compiler PIC flag $_LT_TAGVAR(lt_prog_compiler_pic, $1) works],
-    [_LT_TAGVAR(lt_cv_prog_compiler_pic_works, $1)],
-    [$_LT_TAGVAR(lt_prog_compiler_pic, $1)@&t@m4_if([$1],[],[ -DPIC],[m4_if([$1],[CXX],[ -DPIC],[])])], [],
-    [case $_LT_TAGVAR(lt_prog_compiler_pic, $1) in
-     "" | " "*) ;;
-     *) _LT_TAGVAR(lt_prog_compiler_pic, $1)=" $_LT_TAGVAR(lt_prog_compiler_pic, $1)" ;;
-     esac],
-    [_LT_TAGVAR(lt_prog_compiler_pic, $1)=
-     _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no])
-fi
-_LT_TAGDECL([pic_flag], [lt_prog_compiler_pic], [1],
-       [Additional compiler flags for building library objects])
-
-#
-# Check to make sure the static flag actually works.
-#
-wl=$_LT_TAGVAR(lt_prog_compiler_wl, $1) eval lt_tmp_static_flag=\"$_LT_TAGVAR(lt_prog_compiler_static, $1)\"
-_LT_LINKER_OPTION([if $compiler static flag $lt_tmp_static_flag works],
-  _LT_TAGVAR(lt_cv_prog_compiler_static_works, $1),
-  $lt_tmp_static_flag,
-  [],
-  [_LT_TAGVAR(lt_prog_compiler_static, $1)=])
-_LT_TAGDECL([link_static_flag], [lt_prog_compiler_static], [1],
-       [Compiler flag to prevent dynamic linking])
-])# _LT_COMPILER_PIC
-
-
-# _LT_LINKER_SHLIBS([TAGNAME])
-# ----------------------------
-# See if the linker supports building shared libraries.
-m4_defun([_LT_LINKER_SHLIBS],
-[AC_REQUIRE([LT_PATH_LD])dnl
-AC_REQUIRE([LT_PATH_NM])dnl
-m4_require([_LT_FILEUTILS_DEFAULTS])dnl
-m4_require([_LT_DECL_EGREP])dnl
-m4_require([_LT_DECL_SED])dnl
-m4_require([_LT_CMD_GLOBAL_SYMBOLS])dnl
-m4_require([_LT_TAG_COMPILER])dnl
-AC_MSG_CHECKING([whether the $compiler linker ($LD) supports shared libraries])
-m4_if([$1], [CXX], [
-  _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols'
-  case $host_os in
-  aix[[4-9]]*)
-    # If we're using GNU nm, then we don't want the "-C" option.
-    # -C means demangle to AIX nm, but means don't demangle with GNU nm
-    if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then
-      _LT_TAGVAR(export_symbols_cmds, $1)='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && ([substr](\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols'
-    else
-      _LT_TAGVAR(export_symbols_cmds, $1)='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && ([substr](\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols'
-    fi
-    ;;
-  pw32*)
-    _LT_TAGVAR(export_symbols_cmds, $1)="$ltdll_cmds"
-  ;;
-  cygwin* | mingw* | cegcc*)
-    _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]][[ ]]/s/.*[[ ]]\([[^ ]]*\)/\1 DATA/;/^.*[[ ]]__nm__/s/^.*[[ ]]__nm__\([[^ ]]*\)[[ ]][[^ ]]*/\1 DATA/;/^I[[ ]]/d;/^[[AITW]][[ ]]/s/.* //'\'' | sort | uniq > $export_symbols'
-  ;;
-  linux* | k*bsd*-gnu)
-    _LT_TAGVAR(link_all_deplibs, $1)=no
-  ;;
-  *)
-    _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols'
-  ;;
-  esac
-  _LT_TAGVAR(exclude_expsyms, $1)=['_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*']
-], [
-  runpath_var=
-  _LT_TAGVAR(allow_undefined_flag, $1)=
-  _LT_TAGVAR(always_export_symbols, $1)=no
-  _LT_TAGVAR(archive_cmds, $1)=
-  _LT_TAGVAR(archive_expsym_cmds, $1)=
-  _LT_TAGVAR(compiler_needs_object, $1)=no
-  _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no
-  _LT_TAGVAR(export_dynamic_flag_spec, $1)=
-  _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols'
-  _LT_TAGVAR(hardcode_automatic, $1)=no
-  _LT_TAGVAR(hardcode_direct, $1)=no
-  _LT_TAGVAR(hardcode_direct_absolute, $1)=no
-  _LT_TAGVAR(hardcode_libdir_flag_spec, $1)=
-  _LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)=
-  _LT_TAGVAR(hardcode_libdir_separator, $1)=
-  _LT_TAGVAR(hardcode_minus_L, $1)=no
-  _LT_TAGVAR(hardcode_shlibpath_var, $1)=unsupported
-  _LT_TAGVAR(inherit_rpath, $1)=no
-  _LT_TAGVAR(link_all_deplibs, $1)=unknown
-  _LT_TAGVAR(module_cmds, $1)=
-  _LT_TAGVAR(module_expsym_cmds, $1)=
-  _LT_TAGVAR(old_archive_from_new_cmds, $1)=
-  _LT_TAGVAR(old_archive_from_expsyms_cmds, $1)=
-  _LT_TAGVAR(thread_safe_flag_spec, $1)=
-  _LT_TAGVAR(whole_archive_flag_spec, $1)=
-  # include_expsyms should be a list of space-separated symbols to be *always*
-  # included in the symbol list
-  _LT_TAGVAR(include_expsyms, $1)=
-  # exclude_expsyms can be an extended regexp of symbols to exclude
-  # it will be wrapped by ` (' and `)$', so one must not match beginning or
-  # end of line.  Example: `a|bc|.*d.*' will exclude the symbols `a' and `bc',
-  # as well as any symbol that contains `d'.
-  _LT_TAGVAR(exclude_expsyms, $1)=['_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*']
-  # Although _GLOBAL_OFFSET_TABLE_ is a valid symbol C name, most a.out
-  # platforms (ab)use it in PIC code, but their linkers get confused if
-  # the symbol is explicitly referenced.  Since portable code cannot
-  # rely on this symbol name, it's probably fine to never include it in
-  # preloaded symbol tables.
-  # Exclude shared library initialization/finalization symbols.
-dnl Note also adjust exclude_expsyms for C++ above.
-  extract_expsyms_cmds=
-
-  case $host_os in
-  cygwin* | mingw* | pw32* | cegcc*)
-    # FIXME: the MSVC++ port hasn't been tested in a loooong time
-    # When not using gcc, we currently assume that we are using
-    # Microsoft Visual C++.
-    if test "$GCC" != yes; then
-      with_gnu_ld=no
-    fi
-    ;;
-  interix*)
-    # we just hope/assume this is gcc and not c89 (= MSVC++)
-    with_gnu_ld=yes
-    ;;
-  openbsd*)
-    with_gnu_ld=no
-    ;;
-  linux* | k*bsd*-gnu)
-    _LT_TAGVAR(link_all_deplibs, $1)=no
-    ;;
-  esac
-
-  _LT_TAGVAR(ld_shlibs, $1)=yes
-  if test "$with_gnu_ld" = yes; then
-    # If archive_cmds runs LD, not CC, wlarc should be empty
-    wlarc='${wl}'
-
-    # Set some defaults for GNU ld with shared library support. These
-    # are reset later if shared libraries are not supported. Putting them
-    # here allows them to be overridden if necessary.
-    runpath_var=LD_RUN_PATH
-    _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
-    _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
-    # ancient GNU ld didn't support --whole-archive et. al.
-    if $LD --help 2>&1 | $GREP 'no-whole-archive' > /dev/null; then
-      _LT_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive'
-    else
-      _LT_TAGVAR(whole_archive_flag_spec, $1)=
-    fi
-    supports_anon_versioning=no
-    case `$LD -v 2>&1` in
-      *GNU\ gold*) supports_anon_versioning=yes ;;
-      *\ [[01]].* | *\ 2.[[0-9]].* | *\ 2.10.*) ;; # catch versions < 2.11
-      *\ 2.11.93.0.2\ *) supports_anon_versioning=yes ;; # RH7.3 ...
-      *\ 2.11.92.0.12\ *) supports_anon_versioning=yes ;; # Mandrake 8.2 ...
-      *\ 2.11.*) ;; # other 2.11 versions
-      *) supports_anon_versioning=yes ;;
-    esac
-
-    # See if GNU ld supports shared libraries.
-    case $host_os in
-    aix[[3-9]]*)
-      # On AIX/PPC, the GNU linker is very broken
-      if test "$host_cpu" != ia64; then
-       _LT_TAGVAR(ld_shlibs, $1)=no
-       cat <<_LT_EOF 1>&2
-
-*** Warning: the GNU linker, at least up to release 2.9.1, is reported
-*** to be unable to reliably create shared libraries on AIX.
-*** Therefore, libtool is disabling shared libraries support.  If you
-*** really care for shared libraries, you may want to modify your PATH
-*** so that a non-GNU linker is found, and then restart.
-
-_LT_EOF
-      fi
-      ;;
-
-    amigaos*)
-      case $host_cpu in
-      powerpc)
-            # see comment about AmigaOS4 .so support
-            _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
-            _LT_TAGVAR(archive_expsym_cmds, $1)=''
-        ;;
-      m68k)
-            _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)'
-            _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
-            _LT_TAGVAR(hardcode_minus_L, $1)=yes
-        ;;
-      esac
-      ;;
-
-    beos*)
-      if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
-       _LT_TAGVAR(allow_undefined_flag, $1)=unsupported
-       # Joseph Beckenbach <jrb3@best.com> says some releases of gcc
-       # support --undefined.  This deserves some investigation.  FIXME
-       _LT_TAGVAR(archive_cmds, $1)='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
-      else
-       _LT_TAGVAR(ld_shlibs, $1)=no
-      fi
-      ;;
-
-    cygwin* | mingw* | pw32* | cegcc*)
-      # _LT_TAGVAR(hardcode_libdir_flag_spec, $1) is actually meaningless,
-      # as there is no search path for DLLs.
-      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
-      _LT_TAGVAR(allow_undefined_flag, $1)=unsupported
-      _LT_TAGVAR(always_export_symbols, $1)=no
-      _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes
-      _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]][[ ]]/s/.*[[ ]]\([[^ ]]*\)/\1 DATA/'\'' | $SED -e '\''/^[[AITW]][[ ]]/s/.*[[ ]]//'\'' | sort | uniq > $export_symbols'
-
-      if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then
-        _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib'
-       # If the export-symbols file already is a .def file (1st line
-       # is EXPORTS), use it as is; otherwise, prepend...
-       _LT_TAGVAR(archive_expsym_cmds, $1)='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then
-         cp $export_symbols $output_objdir/$soname.def;
-       else
-         echo EXPORTS > $output_objdir/$soname.def;
-         cat $export_symbols >> $output_objdir/$soname.def;
-       fi~
-       $CC -shared $output_objdir/$soname.def $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib'
-      else
-       _LT_TAGVAR(ld_shlibs, $1)=no
-      fi
-      ;;
-
-    interix[[3-9]]*)
-      _LT_TAGVAR(hardcode_direct, $1)=no
-      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
-      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
-      _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
-      # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc.
-      # Instead, shared libraries are loaded at an image base (0x10000000 by
-      # default) and relocated if they conflict, which is a slow very memory
-      # consuming and fragmenting process.  To avoid this, we pick a random,
-      # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link
-      # time.  Moving up from 0x10000000 also allows more sbrk(2) space.
-      _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
-      _LT_TAGVAR(archive_expsym_cmds, $1)='sed "s,^,_," $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--retain-symbols-file,$output_objdir/$soname.expsym ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
-      ;;
-
-    gnu* | linux* | tpf* | k*bsd*-gnu | kopensolaris*-gnu)
-      tmp_diet=no
-      if test "$host_os" = linux-dietlibc; then
-       case $cc_basename in
-         diet\ *) tmp_diet=yes;;       # linux-dietlibc with static linking (!diet-dyn)
-       esac
-      fi
-      if $LD --help 2>&1 | $EGREP ': supported targets:.* elf' > /dev/null \
-        && test "$tmp_diet" = no
-      then
-       tmp_addflag=
-       tmp_sharedflag='-shared'
-       case $cc_basename,$host_cpu in
-        pgcc*)                         # Portland Group C compiler
-         _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`for conv in $convenience\"\"; do test  -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive'
-         tmp_addflag=' $pic_flag'
-         ;;
-       pgf77* | pgf90* | pgf95*)       # Portland Group f77 and f90 compilers
-         _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`for conv in $convenience\"\"; do test  -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive'
-         tmp_addflag=' $pic_flag -Mnomain' ;;
-       ecc*,ia64* | icc*,ia64*)        # Intel C compiler on ia64
-         tmp_addflag=' -i_dynamic' ;;
-       efc*,ia64* | ifort*,ia64*)      # Intel Fortran compiler on ia64
-         tmp_addflag=' -i_dynamic -nofor_main' ;;
-       ifc* | ifort*)                  # Intel Fortran compiler
-         tmp_addflag=' -nofor_main' ;;
-       lf95*)                          # Lahey Fortran 8.1
-         _LT_TAGVAR(whole_archive_flag_spec, $1)=
-         tmp_sharedflag='--shared' ;;
-       xl[[cC]]*)                      # IBM XL C 8.0 on PPC (deal with xlf below)
-         tmp_sharedflag='-qmkshrobj'
-         tmp_addflag= ;;
-       esac
-       case `$CC -V 2>&1 | sed 5q` in
-       *Sun\ C*)                       # Sun C 5.9
-         _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive'
-         _LT_TAGVAR(compiler_needs_object, $1)=yes
-         tmp_sharedflag='-G' ;;
-       *Sun\ F*)                       # Sun Fortran 8.3
-         tmp_sharedflag='-G' ;;
-       esac
-       _LT_TAGVAR(archive_cmds, $1)='$CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
-
-        if test "x$supports_anon_versioning" = xyes; then
-          _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~
-           cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~
-           echo "local: *; };" >> $output_objdir/$libname.ver~
-           $CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-version-script ${wl}$output_objdir/$libname.ver -o $lib'
-        fi
-
-       case $cc_basename in
-       xlf*)
-         # IBM XL Fortran 10.1 on PPC cannot create shared libs itself
-         _LT_TAGVAR(whole_archive_flag_spec, $1)='--whole-archive$convenience --no-whole-archive'
-         _LT_TAGVAR(hardcode_libdir_flag_spec, $1)=
-         _LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)='-rpath $libdir'
-         _LT_TAGVAR(archive_cmds, $1)='$LD -shared $libobjs $deplibs $compiler_flags -soname $soname -o $lib'
-         if test "x$supports_anon_versioning" = xyes; then
-           _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~
-             cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~
-             echo "local: *; };" >> $output_objdir/$libname.ver~
-             $LD -shared $libobjs $deplibs $compiler_flags -soname $soname -version-script $output_objdir/$libname.ver -o $lib'
-         fi
-         ;;
-       esac
-      else
-        _LT_TAGVAR(ld_shlibs, $1)=no
-      fi
-      ;;
-
-    netbsd* | netbsdelf*-gnu)
-      if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
-       _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib'
-       wlarc=
-      else
-       _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
-       _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
-      fi
-      ;;
-
-    solaris*)
-      if $LD -v 2>&1 | $GREP 'BFD 2\.8' > /dev/null; then
-       _LT_TAGVAR(ld_shlibs, $1)=no
-       cat <<_LT_EOF 1>&2
-
-*** Warning: The releases 2.8.* of the GNU linker cannot reliably
-*** create shared libraries on Solaris systems.  Therefore, libtool
-*** is disabling shared libraries support.  We urge you to upgrade GNU
-*** binutils to release 2.9.1 or newer.  Another option is to modify
-*** your PATH or compiler configuration so that the native linker is
-*** used, and then restart.
-
-_LT_EOF
-      elif $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
-       _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
-       _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
-      else
-       _LT_TAGVAR(ld_shlibs, $1)=no
-      fi
-      ;;
-
-    sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX*)
-      case `$LD -v 2>&1` in
-        *\ [[01]].* | *\ 2.[[0-9]].* | *\ 2.1[[0-5]].*)
-       _LT_TAGVAR(ld_shlibs, $1)=no
-       cat <<_LT_EOF 1>&2
-
-*** Warning: Releases of the GNU linker prior to 2.16.91.0.3 can not
-*** reliably create shared libraries on SCO systems.  Therefore, libtool
-*** is disabling shared libraries support.  We urge you to upgrade GNU
-*** binutils to release 2.16.91.0.3 or newer.  Another option is to modify
-*** your PATH or compiler configuration so that the native linker is
-*** used, and then restart.
-
-_LT_EOF
-       ;;
-       *)
-         # For security reasons, it is highly recommended that you always
-         # use absolute paths for naming shared libraries, and exclude the
-         # DT_RUNPATH tag from executables and libraries.  But doing so
-         # requires that you compile everything twice, which is a pain.
-         if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
-           _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
-           _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
-           _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
-         else
-           _LT_TAGVAR(ld_shlibs, $1)=no
-         fi
-       ;;
-      esac
-      ;;
-
-    sunos4*)
-      _LT_TAGVAR(archive_cmds, $1)='$LD -assert pure-text -Bshareable -o $lib $libobjs $deplibs $linker_flags'
-      wlarc=
-      _LT_TAGVAR(hardcode_direct, $1)=yes
-      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
-      ;;
-
-    *)
-      if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
-       _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
-       _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
-      else
-       _LT_TAGVAR(ld_shlibs, $1)=no
-      fi
-      ;;
-    esac
-
-    if test "$_LT_TAGVAR(ld_shlibs, $1)" = no; then
-      runpath_var=
-      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)=
-      _LT_TAGVAR(export_dynamic_flag_spec, $1)=
-      _LT_TAGVAR(whole_archive_flag_spec, $1)=
-    fi
-  else
-    # PORTME fill in a description of your system's linker (not GNU ld)
-    case $host_os in
-    aix3*)
-      _LT_TAGVAR(allow_undefined_flag, $1)=unsupported
-      _LT_TAGVAR(always_export_symbols, $1)=yes
-      _LT_TAGVAR(archive_expsym_cmds, $1)='$LD -o $output_objdir/$soname $libobjs $deplibs $linker_flags -bE:$export_symbols -T512 -H512 -bM:SRE~$AR $AR_FLAGS $lib $output_objdir/$soname'
-      # Note: this linker hardcodes the directories in LIBPATH if there
-      # are no directories specified by -L.
-      _LT_TAGVAR(hardcode_minus_L, $1)=yes
-      if test "$GCC" = yes && test -z "$lt_prog_compiler_static"; then
-       # Neither direct hardcoding nor static linking is supported with a
-       # broken collect2.
-       _LT_TAGVAR(hardcode_direct, $1)=unsupported
-      fi
-      ;;
-
-    aix[[4-9]]*)
-      if test "$host_cpu" = ia64; then
-       # On IA64, the linker does run time linking by default, so we don't
-       # have to do anything special.
-       aix_use_runtimelinking=no
-       exp_sym_flag='-Bexport'
-       no_entry_flag=""
-      else
-       # If we're using GNU nm, then we don't want the "-C" option.
-       # -C means demangle to AIX nm, but means don't demangle with GNU nm
-       if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then
-         _LT_TAGVAR(export_symbols_cmds, $1)='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && ([substr](\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols'
-       else
-         _LT_TAGVAR(export_symbols_cmds, $1)='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && ([substr](\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols'
-       fi
-       aix_use_runtimelinking=no
-
-       # Test if we are trying to use run time linking or normal
-       # AIX style linking. If -brtl is somewhere in LDFLAGS, we
-       # need to do runtime linking.
-       case $host_os in aix4.[[23]]|aix4.[[23]].*|aix[[5-9]]*)
-         for ld_flag in $LDFLAGS; do
-         if (test $ld_flag = "-brtl" || test $ld_flag = "-Wl,-brtl"); then
-           aix_use_runtimelinking=yes
-           break
-         fi
-         done
-         ;;
-       esac
-
-       exp_sym_flag='-bexport'
-       no_entry_flag='-bnoentry'
-      fi
-
-      # When large executables or shared objects are built, AIX ld can
-      # have problems creating the table of contents.  If linking a library
-      # or program results in "error TOC overflow" add -mminimal-toc to
-      # CXXFLAGS/CFLAGS for g++/gcc.  In the cases where that is not
-      # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS.
-
-      _LT_TAGVAR(archive_cmds, $1)=''
-      _LT_TAGVAR(hardcode_direct, $1)=yes
-      _LT_TAGVAR(hardcode_direct_absolute, $1)=yes
-      _LT_TAGVAR(hardcode_libdir_separator, $1)=':'
-      _LT_TAGVAR(link_all_deplibs, $1)=yes
-      _LT_TAGVAR(file_list_spec, $1)='${wl}-f,'
-
-      if test "$GCC" = yes; then
-       case $host_os in aix4.[[012]]|aix4.[[012]].*)
-       # We only want to do this on AIX 4.2 and lower, the check
-       # below for broken collect2 doesn't work under 4.3+
-         collect2name=`${CC} -print-prog-name=collect2`
-         if test -f "$collect2name" &&
-          strings "$collect2name" | $GREP resolve_lib_name >/dev/null
-         then
-         # We have reworked collect2
-         :
-         else
-         # We have old collect2
-         _LT_TAGVAR(hardcode_direct, $1)=unsupported
-         # It fails to find uninstalled libraries when the uninstalled
-         # path is not listed in the libpath.  Setting hardcode_minus_L
-         # to unsupported forces relinking
-         _LT_TAGVAR(hardcode_minus_L, $1)=yes
-         _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
-         _LT_TAGVAR(hardcode_libdir_separator, $1)=
-         fi
-         ;;
-       esac
-       shared_flag='-shared'
-       if test "$aix_use_runtimelinking" = yes; then
-         shared_flag="$shared_flag "'${wl}-G'
-       fi
-       _LT_TAGVAR(link_all_deplibs, $1)=no
-      else
-       # not using gcc
-       if test "$host_cpu" = ia64; then
-       # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release
-       # chokes on -Wl,-G. The following line is correct:
-         shared_flag='-G'
-       else
-         if test "$aix_use_runtimelinking" = yes; then
-           shared_flag='${wl}-G'
-         else
-           shared_flag='${wl}-bM:SRE'
-         fi
-       fi
-      fi
-
-      _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-bexpall'
-      # It seems that -bexpall does not export symbols beginning with
-      # underscore (_), so it is better to generate a list of symbols to export.
-      _LT_TAGVAR(always_export_symbols, $1)=yes
-      if test "$aix_use_runtimelinking" = yes; then
-       # Warning - without using the other runtime loading flags (-brtl),
-       # -berok will link without error, but may produce a broken library.
-       _LT_TAGVAR(allow_undefined_flag, $1)='-berok'
-        # Determine the default libpath from the value encoded in an
-        # empty executable.
-        _LT_SYS_MODULE_PATH_AIX
-        _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath"
-        _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags `if test "x${allow_undefined_flag}" != "x"; then $ECHO "X${wl}${allow_undefined_flag}" | $Xsed; else :; fi` '"\${wl}$exp_sym_flag:\$export_symbols $shared_flag"
-      else
-       if test "$host_cpu" = ia64; then
-         _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $libdir:/usr/lib:/lib'
-         _LT_TAGVAR(allow_undefined_flag, $1)="-z nodefs"
-         _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$exp_sym_flag:\$export_symbols"
-       else
-        # Determine the default libpath from the value encoded in an
-        # empty executable.
-        _LT_SYS_MODULE_PATH_AIX
-        _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath"
-         # Warning - without using the other run time loading flags,
-         # -berok will link without error, but may produce a broken library.
-         _LT_TAGVAR(no_undefined_flag, $1)=' ${wl}-bernotok'
-         _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-berok'
-         # Exported symbols can be pulled into shared objects from archives
-         _LT_TAGVAR(whole_archive_flag_spec, $1)='$convenience'
-         _LT_TAGVAR(archive_cmds_need_lc, $1)=yes
-         # This is similar to how AIX traditionally builds its shared libraries.
-         _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs ${wl}-bnoentry $compiler_flags ${wl}-bE:$export_symbols${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname'
-       fi
-      fi
-      ;;
-
-    amigaos*)
-      case $host_cpu in
-      powerpc)
-            # see comment about AmigaOS4 .so support
-            _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
-            _LT_TAGVAR(archive_expsym_cmds, $1)=''
-        ;;
-      m68k)
-            _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)'
-            _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
-            _LT_TAGVAR(hardcode_minus_L, $1)=yes
-        ;;
-      esac
-      ;;
-
-    bsdi[[45]]*)
-      _LT_TAGVAR(export_dynamic_flag_spec, $1)=-rdynamic
-      ;;
-
-    cygwin* | mingw* | pw32* | cegcc*)
-      # When not using gcc, we currently assume that we are using
-      # Microsoft Visual C++.
-      # hardcode_libdir_flag_spec is actually meaningless, as there is
-      # no search path for DLLs.
-      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)=' '
-      _LT_TAGVAR(allow_undefined_flag, $1)=unsupported
-      # Tell ltmain to make .lib files, not .a files.
-      libext=lib
-      # Tell ltmain to make .dll files, not .so files.
-      shrext_cmds=".dll"
-      # FIXME: Setting linknames here is a bad hack.
-      _LT_TAGVAR(archive_cmds, $1)='$CC -o $lib $libobjs $compiler_flags `$ECHO "X$deplibs" | $Xsed -e '\''s/ -lc$//'\''` -link -dll~linknames='
-      # The linker will automatically build a .lib file if we build a DLL.
-      _LT_TAGVAR(old_archive_from_new_cmds, $1)='true'
-      # FIXME: Should let the user specify the lib program.
-      _LT_TAGVAR(old_archive_cmds, $1)='lib -OUT:$oldlib$oldobjs$old_deplibs'
-      _LT_TAGVAR(fix_srcfile_path, $1)='`cygpath -w "$srcfile"`'
-      _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes
-      ;;
-
-    darwin* | rhapsody*)
-      _LT_DARWIN_LINKER_FEATURES($1)
-      ;;
-
-    dgux*)
-      _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
-      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
-      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
-      ;;
-
-    freebsd1*)
-      _LT_TAGVAR(ld_shlibs, $1)=no
-      ;;
-
-    # FreeBSD 2.2.[012] allows us to include c++rt0.o to get C++ constructor
-    # support.  Future versions do this automatically, but an explicit c++rt0.o
-    # does not break anything, and helps significantly (at the cost of a little
-    # extra space).
-    freebsd2.2*)
-      _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags /usr/lib/c++rt0.o'
-      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
-      _LT_TAGVAR(hardcode_direct, $1)=yes
-      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
-      ;;
-
-    # Unfortunately, older versions of FreeBSD 2 do not have this feature.
-    freebsd2*)
-      _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'
-      _LT_TAGVAR(hardcode_direct, $1)=yes
-      _LT_TAGVAR(hardcode_minus_L, $1)=yes
-      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
-      ;;
-
-    # FreeBSD 3 and greater uses gcc -shared to do shared libraries.
-    freebsd* | dragonfly*)
-      _LT_TAGVAR(archive_cmds, $1)='$CC -shared -o $lib $libobjs $deplibs $compiler_flags'
-      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
-      _LT_TAGVAR(hardcode_direct, $1)=yes
-      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
-      ;;
-
-    hpux9*)
-      if test "$GCC" = yes; then
-       _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$CC -shared -fPIC ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $libobjs $deplibs $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
-      else
-       _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$LD -b +b $install_libdir -o $output_objdir/$soname $libobjs $deplibs $linker_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
-      fi
-      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir'
-      _LT_TAGVAR(hardcode_libdir_separator, $1)=:
-      _LT_TAGVAR(hardcode_direct, $1)=yes
-
-      # hardcode_minus_L: Not really in the search PATH,
-      # but as the default location of the library.
-      _LT_TAGVAR(hardcode_minus_L, $1)=yes
-      _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
-      ;;
-
-    hpux10*)
-      if test "$GCC" = yes -a "$with_gnu_ld" = no; then
-       _LT_TAGVAR(archive_cmds, $1)='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'
-      else
-       _LT_TAGVAR(archive_cmds, $1)='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags'
-      fi
-      if test "$with_gnu_ld" = no; then
-       _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir'
-       _LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)='+b $libdir'
-       _LT_TAGVAR(hardcode_libdir_separator, $1)=:
-       _LT_TAGVAR(hardcode_direct, $1)=yes
-       _LT_TAGVAR(hardcode_direct_absolute, $1)=yes
-       _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
-       # hardcode_minus_L: Not really in the search PATH,
-       # but as the default location of the library.
-       _LT_TAGVAR(hardcode_minus_L, $1)=yes
-      fi
-      ;;
-
-    hpux11*)
-      if test "$GCC" = yes -a "$with_gnu_ld" = no; then
-       case $host_cpu in
-       hppa*64*)
-         _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
-         ;;
-       ia64*)
-         _LT_TAGVAR(archive_cmds, $1)='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags'
-         ;;
-       *)
-         _LT_TAGVAR(archive_cmds, $1)='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'
-         ;;
-       esac
-      else
-       case $host_cpu in
-       hppa*64*)
-         _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
-         ;;
-       ia64*)
-         _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags'
-         ;;
-       *)
-         _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'
-         ;;
-       esac
-      fi
-      if test "$with_gnu_ld" = no; then
-       _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir'
-       _LT_TAGVAR(hardcode_libdir_separator, $1)=:
-
-       case $host_cpu in
-       hppa*64*|ia64*)
-         _LT_TAGVAR(hardcode_direct, $1)=no
-         _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
-         ;;
-       *)
-         _LT_TAGVAR(hardcode_direct, $1)=yes
-         _LT_TAGVAR(hardcode_direct_absolute, $1)=yes
-         _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
-
-         # hardcode_minus_L: Not really in the search PATH,
-         # but as the default location of the library.
-         _LT_TAGVAR(hardcode_minus_L, $1)=yes
-         ;;
-       esac
-      fi
-      ;;
-
-    irix5* | irix6* | nonstopux*)
-      if test "$GCC" = yes; then
-       _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
-       # Try to use the -exported_symbol ld option, if it does not
-       # work, assume that -exports_file does not work either and
-       # implicitly export all symbols.
-        save_LDFLAGS="$LDFLAGS"
-        LDFLAGS="$LDFLAGS -shared ${wl}-exported_symbol ${wl}foo ${wl}-update_registry ${wl}/dev/null"
-        AC_LINK_IFELSE(int foo(void) {},
-          _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations ${wl}-exports_file ${wl}$export_symbols -o $lib'
-        )
-        LDFLAGS="$save_LDFLAGS"
-      else
-       _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib'
-       _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -exports_file $export_symbols -o $lib'
-      fi
-      _LT_TAGVAR(archive_cmds_need_lc, $1)='no'
-      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
-      _LT_TAGVAR(hardcode_libdir_separator, $1)=:
-      _LT_TAGVAR(inherit_rpath, $1)=yes
-      _LT_TAGVAR(link_all_deplibs, $1)=yes
-      ;;
-
-    netbsd* | netbsdelf*-gnu)
-      if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
-       _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'  # a.out
-      else
-       _LT_TAGVAR(archive_cmds, $1)='$LD -shared -o $lib $libobjs $deplibs $linker_flags'      # ELF
-      fi
-      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
-      _LT_TAGVAR(hardcode_direct, $1)=yes
-      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
-      ;;
-
-    newsos6)
-      _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
-      _LT_TAGVAR(hardcode_direct, $1)=yes
-      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
-      _LT_TAGVAR(hardcode_libdir_separator, $1)=:
-      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
-      ;;
-
-    *nto* | *qnx*)
-      ;;
-
-    openbsd*)
-      if test -f /usr/libexec/ld.so; then
-       _LT_TAGVAR(hardcode_direct, $1)=yes
-       _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
-       _LT_TAGVAR(hardcode_direct_absolute, $1)=yes
-       if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
-         _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags'
-         _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-retain-symbols-file,$export_symbols'
-         _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
-         _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
-       else
-         case $host_os in
-          openbsd[[01]].* | openbsd2.[[0-7]] | openbsd2.[[0-7]].*)
-            _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'
-            _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
-            ;;
-          *)
-            _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags'
-            _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
-            ;;
-         esac
-       fi
-      else
-       _LT_TAGVAR(ld_shlibs, $1)=no
-      fi
-      ;;
-
-    os2*)
-      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
-      _LT_TAGVAR(hardcode_minus_L, $1)=yes
-      _LT_TAGVAR(allow_undefined_flag, $1)=unsupported
-      _LT_TAGVAR(archive_cmds, $1)='$ECHO "LIBRARY $libname INITINSTANCE" > $output_objdir/$libname.def~$ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~$ECHO DATA >> $output_objdir/$libname.def~$ECHO " SINGLE NONSHARED" >> $output_objdir/$libname.def~$ECHO EXPORTS >> $output_objdir/$libname.def~emxexp $libobjs >> $output_objdir/$libname.def~$CC -Zdll -Zcrtdll -o $lib $libobjs $deplibs $compiler_flags $output_objdir/$libname.def'
-      _LT_TAGVAR(old_archive_from_new_cmds, $1)='emximp -o $output_objdir/$libname.a $output_objdir/$libname.def'
-      ;;
-
-    osf3*)
-      if test "$GCC" = yes; then
-       _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*'
-       _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
-      else
-       _LT_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*'
-       _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib'
-      fi
-      _LT_TAGVAR(archive_cmds_need_lc, $1)='no'
-      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
-      _LT_TAGVAR(hardcode_libdir_separator, $1)=:
-      ;;
-
-    osf4* | osf5*)     # as osf3* with the addition of -msym flag
-      if test "$GCC" = yes; then
-       _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*'
-       _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
-       _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
-      else
-       _LT_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*'
-       _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags -msym -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib'
-       _LT_TAGVAR(archive_expsym_cmds, $1)='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done; printf "%s\\n" "-hidden">> $lib.exp~
-       $CC -shared${allow_undefined_flag} ${wl}-input ${wl}$lib.exp $compiler_flags $libobjs $deplibs -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib~$RM $lib.exp'
-
-       # Both c and cxx compiler support -rpath directly
-       _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir'
-      fi
-      _LT_TAGVAR(archive_cmds_need_lc, $1)='no'
-      _LT_TAGVAR(hardcode_libdir_separator, $1)=:
-      ;;
-
-    solaris*)
-      _LT_TAGVAR(no_undefined_flag, $1)=' -z defs'
-      if test "$GCC" = yes; then
-       wlarc='${wl}'
-       _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-z ${wl}text ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
-       _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
-         $CC -shared ${wl}-z ${wl}text ${wl}-M ${wl}$lib.exp ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp'
-      else
-       case `$CC -V 2>&1` in
-       *"Compilers 5.0"*)
-         wlarc=''
-         _LT_TAGVAR(archive_cmds, $1)='$LD -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $linker_flags'
-         _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
-         $LD -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $linker_flags~$RM $lib.exp'
-         ;;
-       *)
-         wlarc='${wl}'
-         _LT_TAGVAR(archive_cmds, $1)='$CC -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $compiler_flags'
-         _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
-         $CC -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp'
-         ;;
-       esac
-      fi
-      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
-      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
-      case $host_os in
-      solaris2.[[0-5]] | solaris2.[[0-5]].*) ;;
-      *)
-       # The compiler driver will combine and reorder linker options,
-       # but understands `-z linker_flag'.  GCC discards it without `$wl',
-       # but is careful enough not to reorder.
-       # Supported since Solaris 2.6 (maybe 2.5.1?)
-       if test "$GCC" = yes; then
-         _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}-z ${wl}allextract$convenience ${wl}-z ${wl}defaultextract'
-       else
-         _LT_TAGVAR(whole_archive_flag_spec, $1)='-z allextract$convenience -z defaultextract'
-       fi
-       ;;
-      esac
-      _LT_TAGVAR(link_all_deplibs, $1)=yes
-      ;;
-
-    sunos4*)
-      if test "x$host_vendor" = xsequent; then
-       # Use $CC to link under sequent, because it throws in some extra .o
-       # files that make .init and .fini sections work.
-       _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h $soname -o $lib $libobjs $deplibs $compiler_flags'
-      else
-       _LT_TAGVAR(archive_cmds, $1)='$LD -assert pure-text -Bstatic -o $lib $libobjs $deplibs $linker_flags'
-      fi
-      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
-      _LT_TAGVAR(hardcode_direct, $1)=yes
-      _LT_TAGVAR(hardcode_minus_L, $1)=yes
-      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
-      ;;
-
-    sysv4)
-      case $host_vendor in
-       sni)
-         _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
-         _LT_TAGVAR(hardcode_direct, $1)=yes # is this really true???
-       ;;
-       siemens)
-         ## LD is ld it makes a PLAMLIB
-         ## CC just makes a GrossModule.
-         _LT_TAGVAR(archive_cmds, $1)='$LD -G -o $lib $libobjs $deplibs $linker_flags'
-         _LT_TAGVAR(reload_cmds, $1)='$CC -r -o $output$reload_objs'
-         _LT_TAGVAR(hardcode_direct, $1)=no
-        ;;
-       motorola)
-         _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
-         _LT_TAGVAR(hardcode_direct, $1)=no #Motorola manual says yes, but my tests say they lie
-       ;;
-      esac
-      runpath_var='LD_RUN_PATH'
-      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
-      ;;
-
-    sysv4.3*)
-      _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
-      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
-      _LT_TAGVAR(export_dynamic_flag_spec, $1)='-Bexport'
-      ;;
-
-    sysv4*MP*)
-      if test -d /usr/nec; then
-       _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
-       _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
-       runpath_var=LD_RUN_PATH
-       hardcode_runpath_var=yes
-       _LT_TAGVAR(ld_shlibs, $1)=yes
-      fi
-      ;;
-
-    sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[[01]].[[10]]* | unixware7* | sco3.2v5.0.[[024]]*)
-      _LT_TAGVAR(no_undefined_flag, $1)='${wl}-z,text'
-      _LT_TAGVAR(archive_cmds_need_lc, $1)=no
-      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
-      runpath_var='LD_RUN_PATH'
-
-      if test "$GCC" = yes; then
-       _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
-       _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
-      else
-       _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
-       _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
-      fi
-      ;;
-
-    sysv5* | sco3.2v5* | sco5v6*)
-      # Note: We can NOT use -z defs as we might desire, because we do not
-      # link with -lc, and that would cause any symbols used from libc to
-      # always be unresolved, which means just about no library would
-      # ever link correctly.  If we're not using GNU ld we use -z text
-      # though, which does catch some bad symbols but isn't as heavy-handed
-      # as -z defs.
-      _LT_TAGVAR(no_undefined_flag, $1)='${wl}-z,text'
-      _LT_TAGVAR(allow_undefined_flag, $1)='${wl}-z,nodefs'
-      _LT_TAGVAR(archive_cmds_need_lc, $1)=no
-      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
-      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R,$libdir'
-      _LT_TAGVAR(hardcode_libdir_separator, $1)=':'
-      _LT_TAGVAR(link_all_deplibs, $1)=yes
-      _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-Bexport'
-      runpath_var='LD_RUN_PATH'
-
-      if test "$GCC" = yes; then
-       _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
-       _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
-      else
-       _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
-       _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
-      fi
-      ;;
-
-    uts4*)
-      _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
-      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
-      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
-      ;;
-
-    *)
-      _LT_TAGVAR(ld_shlibs, $1)=no
-      ;;
-    esac
-
-    if test x$host_vendor = xsni; then
-      case $host in
-      sysv4 | sysv4.2uw2* | sysv4.3* | sysv5*)
-       _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-Blargedynsym'
-       ;;
-      esac
-    fi
-  fi
-])
-AC_MSG_RESULT([$_LT_TAGVAR(ld_shlibs, $1)])
-test "$_LT_TAGVAR(ld_shlibs, $1)" = no && can_build_shared=no
-
-_LT_TAGVAR(with_gnu_ld, $1)=$with_gnu_ld
-
-_LT_DECL([], [libext], [0], [Old archive suffix (normally "a")])dnl
-_LT_DECL([], [shrext_cmds], [1], [Shared library suffix (normally ".so")])dnl
-_LT_DECL([], [extract_expsyms_cmds], [2],
-    [The commands to extract the exported symbol list from a shared archive])
-
-#
-# Do we need to explicitly link libc?
-#
-case "x$_LT_TAGVAR(archive_cmds_need_lc, $1)" in
-x|xyes)
-  # Assume -lc should be added
-  _LT_TAGVAR(archive_cmds_need_lc, $1)=yes
-
-  if test "$enable_shared" = yes && test "$GCC" = yes; then
-    case $_LT_TAGVAR(archive_cmds, $1) in
-    *'~'*)
-      # FIXME: we may have to deal with multi-command sequences.
-      ;;
-    '$CC '*)
-      # Test whether the compiler implicitly links with -lc since on some
-      # systems, -lgcc has to come before -lc. If gcc already passes -lc
-      # to ld, don't add -lc before -lgcc.
-      AC_MSG_CHECKING([whether -lc should be explicitly linked in])
-      $RM conftest*
-      echo "$lt_simple_compile_test_code" > conftest.$ac_ext
-
-      if AC_TRY_EVAL(ac_compile) 2>conftest.err; then
-        soname=conftest
-        lib=conftest
-        libobjs=conftest.$ac_objext
-        deplibs=
-        wl=$_LT_TAGVAR(lt_prog_compiler_wl, $1)
-       pic_flag=$_LT_TAGVAR(lt_prog_compiler_pic, $1)
-        compiler_flags=-v
-        linker_flags=-v
-        verstring=
-        output_objdir=.
-        libname=conftest
-        lt_save_allow_undefined_flag=$_LT_TAGVAR(allow_undefined_flag, $1)
-        _LT_TAGVAR(allow_undefined_flag, $1)=
-        if AC_TRY_EVAL(_LT_TAGVAR(archive_cmds, $1) 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1)
-        then
-         _LT_TAGVAR(archive_cmds_need_lc, $1)=no
-        else
-         _LT_TAGVAR(archive_cmds_need_lc, $1)=yes
-        fi
-        _LT_TAGVAR(allow_undefined_flag, $1)=$lt_save_allow_undefined_flag
-      else
-        cat conftest.err 1>&5
-      fi
-      $RM conftest*
-      AC_MSG_RESULT([$_LT_TAGVAR(archive_cmds_need_lc, $1)])
-      ;;
-    esac
-  fi
-  ;;
-esac
-
-_LT_TAGDECL([build_libtool_need_lc], [archive_cmds_need_lc], [0],
-    [Whether or not to add -lc for building shared libraries])
-_LT_TAGDECL([allow_libtool_libs_with_static_runtimes],
-    [enable_shared_with_static_runtimes], [0],
-    [Whether or not to disallow shared libs when runtime libs are static])
-_LT_TAGDECL([], [export_dynamic_flag_spec], [1],
-    [Compiler flag to allow reflexive dlopens])
-_LT_TAGDECL([], [whole_archive_flag_spec], [1],
-    [Compiler flag to generate shared objects directly from archives])
-_LT_TAGDECL([], [compiler_needs_object], [1],
-    [Whether the compiler copes with passing no objects directly])
-_LT_TAGDECL([], [old_archive_from_new_cmds], [2],
-    [Create an old-style archive from a shared archive])
-_LT_TAGDECL([], [old_archive_from_expsyms_cmds], [2],
-    [Create a temporary old-style archive to link instead of a shared archive])
-_LT_TAGDECL([], [archive_cmds], [2], [Commands used to build a shared archive])
-_LT_TAGDECL([], [archive_expsym_cmds], [2])
-_LT_TAGDECL([], [module_cmds], [2],
-    [Commands used to build a loadable module if different from building
-    a shared archive.])
-_LT_TAGDECL([], [module_expsym_cmds], [2])
-_LT_TAGDECL([], [with_gnu_ld], [1],
-    [Whether we are building with GNU ld or not])
-_LT_TAGDECL([], [allow_undefined_flag], [1],
-    [Flag that allows shared libraries with undefined symbols to be built])
-_LT_TAGDECL([], [no_undefined_flag], [1],
-    [Flag that enforces no undefined symbols])
-_LT_TAGDECL([], [hardcode_libdir_flag_spec], [1],
-    [Flag to hardcode $libdir into a binary during linking.
-    This must work even if $libdir does not exist])
-_LT_TAGDECL([], [hardcode_libdir_flag_spec_ld], [1],
-    [[If ld is used when linking, flag to hardcode $libdir into a binary
-    during linking.  This must work even if $libdir does not exist]])
-_LT_TAGDECL([], [hardcode_libdir_separator], [1],
-    [Whether we need a single "-rpath" flag with a separated argument])
-_LT_TAGDECL([], [hardcode_direct], [0],
-    [Set to "yes" if using DIR/libNAME${shared_ext} during linking hardcodes
-    DIR into the resulting binary])
-_LT_TAGDECL([], [hardcode_direct_absolute], [0],
-    [Set to "yes" if using DIR/libNAME${shared_ext} during linking hardcodes
-    DIR into the resulting binary and the resulting library dependency is
-    "absolute", i.e impossible to change by setting ${shlibpath_var} if the
-    library is relocated])
-_LT_TAGDECL([], [hardcode_minus_L], [0],
-    [Set to "yes" if using the -LDIR flag during linking hardcodes DIR
-    into the resulting binary])
-_LT_TAGDECL([], [hardcode_shlibpath_var], [0],
-    [Set to "yes" if using SHLIBPATH_VAR=DIR during linking hardcodes DIR
-    into the resulting binary])
-_LT_TAGDECL([], [hardcode_automatic], [0],
-    [Set to "yes" if building a shared library automatically hardcodes DIR
-    into the library and all subsequent libraries and executables linked
-    against it])
-_LT_TAGDECL([], [inherit_rpath], [0],
-    [Set to yes if linker adds runtime paths of dependent libraries
-    to runtime path list])
-_LT_TAGDECL([], [link_all_deplibs], [0],
-    [Whether libtool must link a program against all its dependency libraries])
-_LT_TAGDECL([], [fix_srcfile_path], [1],
-    [Fix the shell variable $srcfile for the compiler])
-_LT_TAGDECL([], [always_export_symbols], [0],
-    [Set to "yes" if exported symbols are required])
-_LT_TAGDECL([], [export_symbols_cmds], [2],
-    [The commands to list exported symbols])
-_LT_TAGDECL([], [exclude_expsyms], [1],
-    [Symbols that should not be listed in the preloaded symbols])
-_LT_TAGDECL([], [include_expsyms], [1],
-    [Symbols that must always be exported])
-_LT_TAGDECL([], [prelink_cmds], [2],
-    [Commands necessary for linking programs (against libraries) with templates])
-_LT_TAGDECL([], [file_list_spec], [1],
-    [Specify filename containing input files])
-dnl FIXME: Not yet implemented
-dnl _LT_TAGDECL([], [thread_safe_flag_spec], [1],
-dnl    [Compiler flag to generate thread safe objects])
-])# _LT_LINKER_SHLIBS
-
-
-# _LT_LANG_C_CONFIG([TAG])
-# ------------------------
-# Ensure that the configuration variables for a C compiler are suitably
-# defined.  These variables are subsequently used by _LT_CONFIG to write
-# the compiler configuration to `libtool'.
-m4_defun([_LT_LANG_C_CONFIG],
-[m4_require([_LT_DECL_EGREP])dnl
-lt_save_CC="$CC"
-AC_LANG_PUSH(C)
-
-# Source file extension for C test sources.
-ac_ext=c
-
-# Object file extension for compiled C test sources.
-objext=o
-_LT_TAGVAR(objext, $1)=$objext
-
-# Code to be used in simple compile tests
-lt_simple_compile_test_code="int some_variable = 0;"
-
-# Code to be used in simple link tests
-lt_simple_link_test_code='int main(){return(0);}'
-
-_LT_TAG_COMPILER
-# Save the default compiler, since it gets overwritten when the other
-# tags are being tested, and _LT_TAGVAR(compiler, []) is a NOP.
-compiler_DEFAULT=$CC
-
-# save warnings/boilerplate of simple test code
-_LT_COMPILER_BOILERPLATE
-_LT_LINKER_BOILERPLATE
-
-## CAVEAT EMPTOR:
-## There is no encapsulation within the following macros, do not change
-## the running order or otherwise move them around unless you know exactly
-## what you are doing...
-if test -n "$compiler"; then
-  _LT_COMPILER_NO_RTTI($1)
-  _LT_COMPILER_PIC($1)
-  _LT_COMPILER_C_O($1)
-  _LT_COMPILER_FILE_LOCKS($1)
-  _LT_LINKER_SHLIBS($1)
-  _LT_SYS_DYNAMIC_LINKER($1)
-  _LT_LINKER_HARDCODE_LIBPATH($1)
-  LT_SYS_DLOPEN_SELF
-  _LT_CMD_STRIPLIB
-
-  # Report which library types will actually be built
-  AC_MSG_CHECKING([if libtool supports shared libraries])
-  AC_MSG_RESULT([$can_build_shared])
-
-  AC_MSG_CHECKING([whether to build shared libraries])
-  test "$can_build_shared" = "no" && enable_shared=no
-
-  # On AIX, shared libraries and static libraries use the same namespace, and
-  # are all built from PIC.
-  case $host_os in
-  aix3*)
-    test "$enable_shared" = yes && enable_static=no
-    if test -n "$RANLIB"; then
-      archive_cmds="$archive_cmds~\$RANLIB \$lib"
-      postinstall_cmds='$RANLIB $lib'
-    fi
-    ;;
-
-  aix[[4-9]]*)
-    if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then
-      test "$enable_shared" = yes && enable_static=no
-    fi
-    ;;
-  esac
-  AC_MSG_RESULT([$enable_shared])
-
-  AC_MSG_CHECKING([whether to build static libraries])
-  # Make sure either enable_shared or enable_static is yes.
-  test "$enable_shared" = yes || enable_static=yes
-  AC_MSG_RESULT([$enable_static])
-
-  _LT_CONFIG($1)
-fi
-AC_LANG_POP
-CC="$lt_save_CC"
-])# _LT_LANG_C_CONFIG
-
-
-# _LT_PROG_CXX
-# ------------
-# Since AC_PROG_CXX is broken, in that it returns g++ if there is no c++
-# compiler, we have our own version here.
-m4_defun([_LT_PROG_CXX],
-[
-pushdef([AC_MSG_ERROR], [_lt_caught_CXX_error=yes])
-AC_PROG_CXX
-if test -n "$CXX" && ( test "X$CXX" != "Xno" &&
-    ( (test "X$CXX" = "Xg++" && `g++ -v >/dev/null 2>&1` ) ||
-    (test "X$CXX" != "Xg++"))) ; then
-  AC_PROG_CXXCPP
-else
-  _lt_caught_CXX_error=yes
-fi
-popdef([AC_MSG_ERROR])
-])# _LT_PROG_CXX
-
-dnl aclocal-1.4 backwards compatibility:
-dnl AC_DEFUN([_LT_PROG_CXX], [])
-
-
-# _LT_LANG_CXX_CONFIG([TAG])
-# --------------------------
-# Ensure that the configuration variables for a C++ compiler are suitably
-# defined.  These variables are subsequently used by _LT_CONFIG to write
-# the compiler configuration to `libtool'.
-m4_defun([_LT_LANG_CXX_CONFIG],
-[AC_REQUIRE([_LT_PROG_CXX])dnl
-m4_require([_LT_FILEUTILS_DEFAULTS])dnl
-m4_require([_LT_DECL_EGREP])dnl
-
-AC_LANG_PUSH(C++)
-_LT_TAGVAR(archive_cmds_need_lc, $1)=no
-_LT_TAGVAR(allow_undefined_flag, $1)=
-_LT_TAGVAR(always_export_symbols, $1)=no
-_LT_TAGVAR(archive_expsym_cmds, $1)=
-_LT_TAGVAR(compiler_needs_object, $1)=no
-_LT_TAGVAR(export_dynamic_flag_spec, $1)=
-_LT_TAGVAR(hardcode_direct, $1)=no
-_LT_TAGVAR(hardcode_direct_absolute, $1)=no
-_LT_TAGVAR(hardcode_libdir_flag_spec, $1)=
-_LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)=
-_LT_TAGVAR(hardcode_libdir_separator, $1)=
-_LT_TAGVAR(hardcode_minus_L, $1)=no
-_LT_TAGVAR(hardcode_shlibpath_var, $1)=unsupported
-_LT_TAGVAR(hardcode_automatic, $1)=no
-_LT_TAGVAR(inherit_rpath, $1)=no
-_LT_TAGVAR(module_cmds, $1)=
-_LT_TAGVAR(module_expsym_cmds, $1)=
-_LT_TAGVAR(link_all_deplibs, $1)=unknown
-_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds
-_LT_TAGVAR(no_undefined_flag, $1)=
-_LT_TAGVAR(whole_archive_flag_spec, $1)=
-_LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no
-
-# Source file extension for C++ test sources.
-ac_ext=cpp
-
-# Object file extension for compiled C++ test sources.
-objext=o
-_LT_TAGVAR(objext, $1)=$objext
-
-# No sense in running all these tests if we already determined that
-# the CXX compiler isn't working.  Some variables (like enable_shared)
-# are currently assumed to apply to all compilers on this platform,
-# and will be corrupted by setting them based on a non-working compiler.
-if test "$_lt_caught_CXX_error" != yes; then
-  # Code to be used in simple compile tests
-  lt_simple_compile_test_code="int some_variable = 0;"
-
-  # Code to be used in simple link tests
-  lt_simple_link_test_code='int main(int, char *[[]]) { return(0); }'
-
-  # ltmain only uses $CC for tagged configurations so make sure $CC is set.
-  _LT_TAG_COMPILER
-
-  # save warnings/boilerplate of simple test code
-  _LT_COMPILER_BOILERPLATE
-  _LT_LINKER_BOILERPLATE
-
-  # Allow CC to be a program name with arguments.
-  lt_save_CC=$CC
-  lt_save_LD=$LD
-  lt_save_GCC=$GCC
-  GCC=$GXX
-  lt_save_with_gnu_ld=$with_gnu_ld
-  lt_save_path_LD=$lt_cv_path_LD
-  if test -n "${lt_cv_prog_gnu_ldcxx+set}"; then
-    lt_cv_prog_gnu_ld=$lt_cv_prog_gnu_ldcxx
-  else
-    $as_unset lt_cv_prog_gnu_ld
-  fi
-  if test -n "${lt_cv_path_LDCXX+set}"; then
-    lt_cv_path_LD=$lt_cv_path_LDCXX
-  else
-    $as_unset lt_cv_path_LD
-  fi
-  test -z "${LDCXX+set}" || LD=$LDCXX
-  CC=${CXX-"c++"}
-  compiler=$CC
-  _LT_TAGVAR(compiler, $1)=$CC
-  _LT_CC_BASENAME([$compiler])
-
-  if test -n "$compiler"; then
-    # We don't want -fno-exception when compiling C++ code, so set the
-    # no_builtin_flag separately
-    if test "$GXX" = yes; then
-      _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=' -fno-builtin'
-    else
-      _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=
-    fi
-
-    if test "$GXX" = yes; then
-      # Set up default GNU C++ configuration
-
-      LT_PATH_LD
-
-      # Check if GNU C++ uses GNU ld as the underlying linker, since the
-      # archiving commands below assume that GNU ld is being used.
-      if test "$with_gnu_ld" = yes; then
-        _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib'
-        _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
-
-        _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
-        _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
-
-        # If archive_cmds runs LD, not CC, wlarc should be empty
-        # XXX I think wlarc can be eliminated in ltcf-cxx, but I need to
-        #     investigate it a little bit more. (MM)
-        wlarc='${wl}'
-
-        # ancient GNU ld didn't support --whole-archive et. al.
-        if eval "`$CC -print-prog-name=ld` --help 2>&1" |
-         $GREP 'no-whole-archive' > /dev/null; then
-          _LT_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive'
-        else
-          _LT_TAGVAR(whole_archive_flag_spec, $1)=
-        fi
-      else
-        with_gnu_ld=no
-        wlarc=
-
-        # A generic and very simple default shared library creation
-        # command for GNU C++ for the case where it uses the native
-        # linker, instead of GNU ld.  If possible, this setting should
-        # overridden to take advantage of the native linker features on
-        # the platform it is being used on.
-        _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib'
-      fi
-
-      # Commands to make compiler produce verbose output that lists
-      # what "hidden" libraries, object files and flags are used when
-      # linking a shared library.
-      output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "\-L"'
-
-    else
-      GXX=no
-      with_gnu_ld=no
-      wlarc=
-    fi
-
-    # PORTME: fill in a description of your system's C++ link characteristics
-    AC_MSG_CHECKING([whether the $compiler linker ($LD) supports shared libraries])
-    _LT_TAGVAR(ld_shlibs, $1)=yes
-    case $host_os in
-      aix3*)
-        # FIXME: insert proper C++ library support
-        _LT_TAGVAR(ld_shlibs, $1)=no
-        ;;
-      aix[[4-9]]*)
-        if test "$host_cpu" = ia64; then
-          # On IA64, the linker does run time linking by default, so we don't
-          # have to do anything special.
-          aix_use_runtimelinking=no
-          exp_sym_flag='-Bexport'
-          no_entry_flag=""
-        else
-          aix_use_runtimelinking=no
-
-          # Test if we are trying to use run time linking or normal
-          # AIX style linking. If -brtl is somewhere in LDFLAGS, we
-          # need to do runtime linking.
-          case $host_os in aix4.[[23]]|aix4.[[23]].*|aix[[5-9]]*)
-           for ld_flag in $LDFLAGS; do
-             case $ld_flag in
-             *-brtl*)
-               aix_use_runtimelinking=yes
-               break
-               ;;
-             esac
-           done
-           ;;
-          esac
-
-          exp_sym_flag='-bexport'
-          no_entry_flag='-bnoentry'
-        fi
-
-        # When large executables or shared objects are built, AIX ld can
-        # have problems creating the table of contents.  If linking a library
-        # or program results in "error TOC overflow" add -mminimal-toc to
-        # CXXFLAGS/CFLAGS for g++/gcc.  In the cases where that is not
-        # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS.
-
-        _LT_TAGVAR(archive_cmds, $1)=''
-        _LT_TAGVAR(hardcode_direct, $1)=yes
-        _LT_TAGVAR(hardcode_direct_absolute, $1)=yes
-        _LT_TAGVAR(hardcode_libdir_separator, $1)=':'
-        _LT_TAGVAR(link_all_deplibs, $1)=yes
-        _LT_TAGVAR(file_list_spec, $1)='${wl}-f,'
-
-        if test "$GXX" = yes; then
-          case $host_os in aix4.[[012]]|aix4.[[012]].*)
-          # We only want to do this on AIX 4.2 and lower, the check
-          # below for broken collect2 doesn't work under 4.3+
-         collect2name=`${CC} -print-prog-name=collect2`
-         if test -f "$collect2name" &&
-            strings "$collect2name" | $GREP resolve_lib_name >/dev/null
-         then
-           # We have reworked collect2
-           :
-         else
-           # We have old collect2
-           _LT_TAGVAR(hardcode_direct, $1)=unsupported
-           # It fails to find uninstalled libraries when the uninstalled
-           # path is not listed in the libpath.  Setting hardcode_minus_L
-           # to unsupported forces relinking
-           _LT_TAGVAR(hardcode_minus_L, $1)=yes
-           _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
-           _LT_TAGVAR(hardcode_libdir_separator, $1)=
-         fi
-          esac
-          shared_flag='-shared'
-         if test "$aix_use_runtimelinking" = yes; then
-           shared_flag="$shared_flag "'${wl}-G'
-         fi
-        else
-          # not using gcc
-          if test "$host_cpu" = ia64; then
-         # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release
-         # chokes on -Wl,-G. The following line is correct:
-         shared_flag='-G'
-          else
-           if test "$aix_use_runtimelinking" = yes; then
-             shared_flag='${wl}-G'
-           else
-             shared_flag='${wl}-bM:SRE'
-           fi
-          fi
-        fi
-
-        _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-bexpall'
-        # It seems that -bexpall does not export symbols beginning with
-        # underscore (_), so it is better to generate a list of symbols to
-       # export.
-        _LT_TAGVAR(always_export_symbols, $1)=yes
-        if test "$aix_use_runtimelinking" = yes; then
-          # Warning - without using the other runtime loading flags (-brtl),
-          # -berok will link without error, but may produce a broken library.
-          _LT_TAGVAR(allow_undefined_flag, $1)='-berok'
-          # Determine the default libpath from the value encoded in an empty
-          # executable.
-          _LT_SYS_MODULE_PATH_AIX
-          _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath"
-
-          _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags `if test "x${allow_undefined_flag}" != "x"; then $ECHO "X${wl}${allow_undefined_flag}" | $Xsed; else :; fi` '"\${wl}$exp_sym_flag:\$export_symbols $shared_flag"
-        else
-          if test "$host_cpu" = ia64; then
-           _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $libdir:/usr/lib:/lib'
-           _LT_TAGVAR(allow_undefined_flag, $1)="-z nodefs"
-           _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$exp_sym_flag:\$export_symbols"
-          else
-           # Determine the default libpath from the value encoded in an
-           # empty executable.
-           _LT_SYS_MODULE_PATH_AIX
-           _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath"
-           # Warning - without using the other run time loading flags,
-           # -berok will link without error, but may produce a broken library.
-           _LT_TAGVAR(no_undefined_flag, $1)=' ${wl}-bernotok'
-           _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-berok'
-           # Exported symbols can be pulled into shared objects from archives
-           _LT_TAGVAR(whole_archive_flag_spec, $1)='$convenience'
-           _LT_TAGVAR(archive_cmds_need_lc, $1)=yes
-           # This is similar to how AIX traditionally builds its shared
-           # libraries.
-           _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs ${wl}-bnoentry $compiler_flags ${wl}-bE:$export_symbols${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname'
-          fi
-        fi
-        ;;
-
-      beos*)
-       if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then
-         _LT_TAGVAR(allow_undefined_flag, $1)=unsupported
-         # Joseph Beckenbach <jrb3@best.com> says some releases of gcc
-         # support --undefined.  This deserves some investigation.  FIXME
-         _LT_TAGVAR(archive_cmds, $1)='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
-       else
-         _LT_TAGVAR(ld_shlibs, $1)=no
-       fi
-       ;;
-
-      chorus*)
-        case $cc_basename in
-          *)
-         # FIXME: insert proper C++ library support
-         _LT_TAGVAR(ld_shlibs, $1)=no
-         ;;
-        esac
-        ;;
-
-      cygwin* | mingw* | pw32* | cegcc*)
-        # _LT_TAGVAR(hardcode_libdir_flag_spec, $1) is actually meaningless,
-        # as there is no search path for DLLs.
-        _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
-        _LT_TAGVAR(allow_undefined_flag, $1)=unsupported
-        _LT_TAGVAR(always_export_symbols, $1)=no
-        _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes
-
-        if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then
-          _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib'
-          # If the export-symbols file already is a .def file (1st line
-          # is EXPORTS), use it as is; otherwise, prepend...
-          _LT_TAGVAR(archive_expsym_cmds, $1)='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then
-           cp $export_symbols $output_objdir/$soname.def;
-          else
-           echo EXPORTS > $output_objdir/$soname.def;
-           cat $export_symbols >> $output_objdir/$soname.def;
-          fi~
-          $CC -shared -nostdlib $output_objdir/$soname.def $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib'
-        else
-          _LT_TAGVAR(ld_shlibs, $1)=no
-        fi
-        ;;
-      darwin* | rhapsody*)
-        _LT_DARWIN_LINKER_FEATURES($1)
-       ;;
-
-      dgux*)
-        case $cc_basename in
-          ec++*)
-           # FIXME: insert proper C++ library support
-           _LT_TAGVAR(ld_shlibs, $1)=no
-           ;;
-          ghcx*)
-           # Green Hills C++ Compiler
-           # FIXME: insert proper C++ library support
-           _LT_TAGVAR(ld_shlibs, $1)=no
-           ;;
-          *)
-           # FIXME: insert proper C++ library support
-           _LT_TAGVAR(ld_shlibs, $1)=no
-           ;;
-        esac
-        ;;
-
-      freebsd[[12]]*)
-        # C++ shared libraries reported to be fairly broken before
-       # switch to ELF
-        _LT_TAGVAR(ld_shlibs, $1)=no
-        ;;
-
-      freebsd-elf*)
-        _LT_TAGVAR(archive_cmds_need_lc, $1)=no
-        ;;
-
-      freebsd* | dragonfly*)
-        # FreeBSD 3 and later use GNU C++ and GNU ld with standard ELF
-        # conventions
-        _LT_TAGVAR(ld_shlibs, $1)=yes
-        ;;
-
-      gnu*)
-        ;;
-
-      hpux9*)
-        _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir'
-        _LT_TAGVAR(hardcode_libdir_separator, $1)=:
-        _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
-        _LT_TAGVAR(hardcode_direct, $1)=yes
-        _LT_TAGVAR(hardcode_minus_L, $1)=yes # Not in the search PATH,
-                                            # but as the default
-                                            # location of the library.
-
-        case $cc_basename in
-          CC*)
-            # FIXME: insert proper C++ library support
-            _LT_TAGVAR(ld_shlibs, $1)=no
-            ;;
-          aCC*)
-            _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$CC -b ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
-            # Commands to make compiler produce verbose output that lists
-            # what "hidden" libraries, object files and flags are used when
-            # linking a shared library.
-            #
-            # There doesn't appear to be a way to prevent this compiler from
-            # explicitly linking system object files so we need to strip them
-            # from the output so that they don't get included in the library
-            # dependencies.
-            output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $EGREP "\-L"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; $ECHO "X$list" | $Xsed'
-            ;;
-          *)
-            if test "$GXX" = yes; then
-              _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$CC -shared -nostdlib -fPIC ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
-            else
-              # FIXME: insert proper C++ library support
-              _LT_TAGVAR(ld_shlibs, $1)=no
-            fi
-            ;;
-        esac
-        ;;
-
-      hpux10*|hpux11*)
-        if test $with_gnu_ld = no; then
-         _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir'
-         _LT_TAGVAR(hardcode_libdir_separator, $1)=:
-
-          case $host_cpu in
-            hppa*64*|ia64*)
-              ;;
-            *)
-             _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
-              ;;
-          esac
-        fi
-        case $host_cpu in
-          hppa*64*|ia64*)
-            _LT_TAGVAR(hardcode_direct, $1)=no
-            _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
-            ;;
-          *)
-            _LT_TAGVAR(hardcode_direct, $1)=yes
-            _LT_TAGVAR(hardcode_direct_absolute, $1)=yes
-            _LT_TAGVAR(hardcode_minus_L, $1)=yes # Not in the search PATH,
-                                                # but as the default
-                                                # location of the library.
-            ;;
-        esac
-
-        case $cc_basename in
-          CC*)
-           # FIXME: insert proper C++ library support
-           _LT_TAGVAR(ld_shlibs, $1)=no
-           ;;
-          aCC*)
-           case $host_cpu in
-             hppa*64*)
-               _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
-               ;;
-             ia64*)
-               _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
-               ;;
-             *)
-               _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
-               ;;
-           esac
-           # Commands to make compiler produce verbose output that lists
-           # what "hidden" libraries, object files and flags are used when
-           # linking a shared library.
-           #
-           # There doesn't appear to be a way to prevent this compiler from
-           # explicitly linking system object files so we need to strip them
-           # from the output so that they don't get included in the library
-           # dependencies.
-           output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $GREP "\-L"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; $ECHO "X$list" | $Xsed'
-           ;;
-          *)
-           if test "$GXX" = yes; then
-             if test $with_gnu_ld = no; then
-               case $host_cpu in
-                 hppa*64*)
-                   _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib -fPIC ${wl}+h ${wl}$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
-                   ;;
-                 ia64*)
-                   _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib -fPIC ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
-                   ;;
-                 *)
-                   _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
-                   ;;
-               esac
-             fi
-           else
-             # FIXME: insert proper C++ library support
-             _LT_TAGVAR(ld_shlibs, $1)=no
-           fi
-           ;;
-        esac
-        ;;
-
-      interix[[3-9]]*)
-       _LT_TAGVAR(hardcode_direct, $1)=no
-       _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
-       _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
-       _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
-       # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc.
-       # Instead, shared libraries are loaded at an image base (0x10000000 by
-       # default) and relocated if they conflict, which is a slow very memory
-       # consuming and fragmenting process.  To avoid this, we pick a random,
-       # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link
-       # time.  Moving up from 0x10000000 also allows more sbrk(2) space.
-       _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
-       _LT_TAGVAR(archive_expsym_cmds, $1)='sed "s,^,_," $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--retain-symbols-file,$output_objdir/$soname.expsym ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
-       ;;
-      irix5* | irix6*)
-        case $cc_basename in
-          CC*)
-           # SGI C++
-           _LT_TAGVAR(archive_cmds, $1)='$CC -shared -all -multigot $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib'
-
-           # Archives containing C++ object files must be created using
-           # "CC -ar", where "CC" is the IRIX C++ compiler.  This is
-           # necessary to make sure instantiated templates are included
-           # in the archive.
-           _LT_TAGVAR(old_archive_cmds, $1)='$CC -ar -WR,-u -o $oldlib $oldobjs'
-           ;;
-          *)
-           if test "$GXX" = yes; then
-             if test "$with_gnu_ld" = no; then
-               _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
-             else
-               _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` -o $lib'
-             fi
-           fi
-           _LT_TAGVAR(link_all_deplibs, $1)=yes
-           ;;
-        esac
-        _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
-        _LT_TAGVAR(hardcode_libdir_separator, $1)=:
-        _LT_TAGVAR(inherit_rpath, $1)=yes
-        ;;
-
-      linux* | k*bsd*-gnu | kopensolaris*-gnu)
-        case $cc_basename in
-          KCC*)
-           # Kuck and Associates, Inc. (KAI) C++ Compiler
-
-           # KCC will only create a shared library if the output file
-           # ends with ".so" (or ".sl" for HP-UX), so rename the library
-           # to its proper name (with version) after linking.
-           _LT_TAGVAR(archive_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib'
-           _LT_TAGVAR(archive_expsym_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib ${wl}-retain-symbols-file,$export_symbols; mv \$templib $lib'
-           # Commands to make compiler produce verbose output that lists
-           # what "hidden" libraries, object files and flags are used when
-           # linking a shared library.
-           #
-           # There doesn't appear to be a way to prevent this compiler from
-           # explicitly linking system object files so we need to strip them
-           # from the output so that they don't get included in the library
-           # dependencies.
-           output_verbose_link_cmd='templist=`$CC $CFLAGS -v conftest.$objext -o libconftest$shared_ext 2>&1 | $GREP "ld"`; rm -f libconftest$shared_ext; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; $ECHO "X$list" | $Xsed'
-
-           _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
-           _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
-
-           # Archives containing C++ object files must be created using
-           # "CC -Bstatic", where "CC" is the KAI C++ compiler.
-           _LT_TAGVAR(old_archive_cmds, $1)='$CC -Bstatic -o $oldlib $oldobjs'
-           ;;
-         icpc* | ecpc* )
-           # Intel C++
-           with_gnu_ld=yes
-           # version 8.0 and above of icpc choke on multiply defined symbols
-           # if we add $predep_objects and $postdep_objects, however 7.1 and
-           # earlier do not add the objects themselves.
-           case `$CC -V 2>&1` in
-             *"Version 7."*)
-               _LT_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib'
-               _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
-               ;;
-             *)  # Version 8.0 or newer
-               tmp_idyn=
-               case $host_cpu in
-                 ia64*) tmp_idyn=' -i_dynamic';;
-               esac
-               _LT_TAGVAR(archive_cmds, $1)='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
-               _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
-               ;;
-           esac
-           _LT_TAGVAR(archive_cmds_need_lc, $1)=no
-           _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
-           _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
-           _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive$convenience ${wl}--no-whole-archive'
-           ;;
-          pgCC* | pgcpp*)
-            # Portland Group C++ compiler
-           case `$CC -V` in
-           *pgCC\ [[1-5]]* | *pgcpp\ [[1-5]]*)
-             _LT_TAGVAR(prelink_cmds, $1)='tpldir=Template.dir~
-               rm -rf $tpldir~
-               $CC --prelink_objects --instantiation_dir $tpldir $objs $libobjs $compile_deplibs~
-               compile_command="$compile_command `find $tpldir -name \*.o | $NL2SP`"'
-             _LT_TAGVAR(old_archive_cmds, $1)='tpldir=Template.dir~
-               rm -rf $tpldir~
-               $CC --prelink_objects --instantiation_dir $tpldir $oldobjs$old_deplibs~
-               $AR $AR_FLAGS $oldlib$oldobjs$old_deplibs `find $tpldir -name \*.o | $NL2SP`~
-               $RANLIB $oldlib'
-             _LT_TAGVAR(archive_cmds, $1)='tpldir=Template.dir~
-               rm -rf $tpldir~
-               $CC --prelink_objects --instantiation_dir $tpldir $predep_objects $libobjs $deplibs $convenience $postdep_objects~
-               $CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | $NL2SP` $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname -o $lib'
-             _LT_TAGVAR(archive_expsym_cmds, $1)='tpldir=Template.dir~
-               rm -rf $tpldir~
-               $CC --prelink_objects --instantiation_dir $tpldir $predep_objects $libobjs $deplibs $convenience $postdep_objects~
-               $CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | $NL2SP` $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname ${wl}-retain-symbols-file ${wl}$export_symbols -o $lib'
-             ;;
-           *) # Version 6 will use weak symbols
-             _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname -o $lib'
-             _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname ${wl}-retain-symbols-file ${wl}$export_symbols -o $lib'
-             ;;
-           esac
-
-           _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}--rpath ${wl}$libdir'
-           _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
-           _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`for conv in $convenience\"\"; do test  -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive'
-            ;;
-         cxx*)
-           # Compaq C++
-           _LT_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib'
-           _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname  -o $lib ${wl}-retain-symbols-file $wl$export_symbols'
-
-           runpath_var=LD_RUN_PATH
-           _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir'
-           _LT_TAGVAR(hardcode_libdir_separator, $1)=:
-
-           # Commands to make compiler produce verbose output that lists
-           # what "hidden" libraries, object files and flags are used when
-           # linking a shared library.
-           #
-           # There doesn't appear to be a way to prevent this compiler from
-           # explicitly linking system object files so we need to strip them
-           # from the output so that they don't get included in the library
-           # dependencies.
-           output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "ld"`; templist=`$ECHO "X$templist" | $Xsed -e "s/\(^.*ld.*\)\( .*ld .*$\)/\1/"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; $ECHO "X$list" | $Xsed'
-           ;;
-         xl*)
-           # IBM XL 8.0 on PPC, with GNU ld
-           _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
-           _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
-           _LT_TAGVAR(archive_cmds, $1)='$CC -qmkshrobj $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
-           if test "x$supports_anon_versioning" = xyes; then
-             _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~
-               cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~
-               echo "local: *; };" >> $output_objdir/$libname.ver~
-               $CC -qmkshrobj $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-version-script ${wl}$output_objdir/$libname.ver -o $lib'
-           fi
-           ;;
-         *)
-           case `$CC -V 2>&1 | sed 5q` in
-           *Sun\ C*)
-             # Sun C++ 5.9
-             _LT_TAGVAR(no_undefined_flag, $1)=' -zdefs'
-             _LT_TAGVAR(archive_cmds, $1)='$CC -G${allow_undefined_flag} -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
-             _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G${allow_undefined_flag} -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-retain-symbols-file ${wl}$export_symbols'
-             _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
-             _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; $ECHO \"$new_convenience\"` ${wl}--no-whole-archive'
-             _LT_TAGVAR(compiler_needs_object, $1)=yes
-
-             # Not sure whether something based on
-             # $CC $CFLAGS -v conftest.$objext -o libconftest$shared_ext 2>&1
-             # would be better.
-             output_verbose_link_cmd='echo'
-
-             # Archives containing C++ object files must be created using
-             # "CC -xar", where "CC" is the Sun C++ compiler.  This is
-             # necessary to make sure instantiated templates are included
-             # in the archive.
-             _LT_TAGVAR(old_archive_cmds, $1)='$CC -xar -o $oldlib $oldobjs'
-             ;;
-           esac
-           ;;
-       esac
-       ;;
-
-      lynxos*)
-        # FIXME: insert proper C++ library support
-       _LT_TAGVAR(ld_shlibs, $1)=no
-       ;;
-
-      m88k*)
-        # FIXME: insert proper C++ library support
-        _LT_TAGVAR(ld_shlibs, $1)=no
-       ;;
-
-      mvs*)
-        case $cc_basename in
-          cxx*)
-           # FIXME: insert proper C++ library support
-           _LT_TAGVAR(ld_shlibs, $1)=no
-           ;;
-         *)
-           # FIXME: insert proper C++ library support
-           _LT_TAGVAR(ld_shlibs, $1)=no
-           ;;
-       esac
-       ;;
-
-      netbsd*)
-        if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then
-         _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable  -o $lib $predep_objects $libobjs $deplibs $postdep_objects $linker_flags'
-         wlarc=
-         _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
-         _LT_TAGVAR(hardcode_direct, $1)=yes
-         _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
-       fi
-       # Workaround some broken pre-1.5 toolchains
-       output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP conftest.$objext | $SED -e "s:-lgcc -lc -lgcc::"'
-       ;;
-
-      *nto* | *qnx*)
-        _LT_TAGVAR(ld_shlibs, $1)=yes
-       ;;
-
-      openbsd2*)
-        # C++ shared libraries are fairly broken
-       _LT_TAGVAR(ld_shlibs, $1)=no
-       ;;
-
-      openbsd*)
-       if test -f /usr/libexec/ld.so; then
-         _LT_TAGVAR(hardcode_direct, $1)=yes
-         _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
-         _LT_TAGVAR(hardcode_direct_absolute, $1)=yes
-         _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib'
-         _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
-         if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
-           _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-retain-symbols-file,$export_symbols -o $lib'
-           _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
-           _LT_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive'
-         fi
-         output_verbose_link_cmd=echo
-       else
-         _LT_TAGVAR(ld_shlibs, $1)=no
-       fi
-       ;;
-
-      osf3* | osf4* | osf5*)
-        case $cc_basename in
-          KCC*)
-           # Kuck and Associates, Inc. (KAI) C++ Compiler
-
-           # KCC will only create a shared library if the output file
-           # ends with ".so" (or ".sl" for HP-UX), so rename the library
-           # to its proper name (with version) after linking.
-           _LT_TAGVAR(archive_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo "$lib" | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib'
-
-           _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
-           _LT_TAGVAR(hardcode_libdir_separator, $1)=:
-
-           # Archives containing C++ object files must be created using
-           # the KAI C++ compiler.
-           case $host in
-             osf3*) _LT_TAGVAR(old_archive_cmds, $1)='$CC -Bstatic -o $oldlib $oldobjs' ;;
-             *) _LT_TAGVAR(old_archive_cmds, $1)='$CC -o $oldlib $oldobjs' ;;
-           esac
-           ;;
-          RCC*)
-           # Rational C++ 2.4.1
-           # FIXME: insert proper C++ library support
-           _LT_TAGVAR(ld_shlibs, $1)=no
-           ;;
-          cxx*)
-           case $host in
-             osf3*)
-               _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*'
-               _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $soname `test -n "$verstring" && $ECHO "X${wl}-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib'
-               _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
-               ;;
-             *)
-               _LT_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*'
-               _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib'
-               _LT_TAGVAR(archive_expsym_cmds, $1)='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done~
-                 echo "-hidden">> $lib.exp~
-                 $CC -shared$allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname ${wl}-input ${wl}$lib.exp  `test -n "$verstring" && $ECHO "X-set_version $verstring" | $Xsed` -update_registry ${output_objdir}/so_locations -o $lib~
-                 $RM $lib.exp'
-               _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir'
-               ;;
-           esac
-
-           _LT_TAGVAR(hardcode_libdir_separator, $1)=:
-
-           # Commands to make compiler produce verbose output that lists
-           # what "hidden" libraries, object files and flags are used when
-           # linking a shared library.
-           #
-           # There doesn't appear to be a way to prevent this compiler from
-           # explicitly linking system object files so we need to strip them
-           # from the output so that they don't get included in the library
-           # dependencies.
-           output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "ld" | $GREP -v "ld:"`; templist=`$ECHO "X$templist" | $Xsed -e "s/\(^.*ld.*\)\( .*ld.*$\)/\1/"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; $ECHO "X$list" | $Xsed'
-           ;;
-         *)
-           if test "$GXX" = yes && test "$with_gnu_ld" = no; then
-             _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*'
-             case $host in
-               osf3*)
-                 _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib ${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "X${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
-                 ;;
-               *)
-                 _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib ${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && $ECHO "${wl}-set_version ${wl}$verstring" | $Xsed` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
-                 ;;
-             esac
-
-             _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
-             _LT_TAGVAR(hardcode_libdir_separator, $1)=:
-
-             # Commands to make compiler produce verbose output that lists
-             # what "hidden" libraries, object files and flags are used when
-             # linking a shared library.
-             output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "\-L"'
-
-           else
-             # FIXME: insert proper C++ library support
-             _LT_TAGVAR(ld_shlibs, $1)=no
-           fi
-           ;;
-        esac
-        ;;
-
-      psos*)
-        # FIXME: insert proper C++ library support
-        _LT_TAGVAR(ld_shlibs, $1)=no
-        ;;
-
-      sunos4*)
-        case $cc_basename in
-          CC*)
-           # Sun C++ 4.x
-           # FIXME: insert proper C++ library support
-           _LT_TAGVAR(ld_shlibs, $1)=no
-           ;;
-          lcc*)
-           # Lucid
-           # FIXME: insert proper C++ library support
-           _LT_TAGVAR(ld_shlibs, $1)=no
-           ;;
-          *)
-           # FIXME: insert proper C++ library support
-           _LT_TAGVAR(ld_shlibs, $1)=no
-           ;;
-        esac
-        ;;
-
-      solaris*)
-        case $cc_basename in
-          CC*)
-           # Sun C++ 4.2, 5.x and Centerline C++
-            _LT_TAGVAR(archive_cmds_need_lc,$1)=yes
-           _LT_TAGVAR(no_undefined_flag, $1)=' -zdefs'
-           _LT_TAGVAR(archive_cmds, $1)='$CC -G${allow_undefined_flag}  -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
-           _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
-             $CC -G${allow_undefined_flag} ${wl}-M ${wl}$lib.exp -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp'
-
-           _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
-           _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
-           case $host_os in
-             solaris2.[[0-5]] | solaris2.[[0-5]].*) ;;
-             *)
-               # The compiler driver will combine and reorder linker options,
-               # but understands `-z linker_flag'.
-               # Supported since Solaris 2.6 (maybe 2.5.1?)
-               _LT_TAGVAR(whole_archive_flag_spec, $1)='-z allextract$convenience -z defaultextract'
-               ;;
-           esac
-           _LT_TAGVAR(link_all_deplibs, $1)=yes
-
-           output_verbose_link_cmd='echo'
-
-           # Archives containing C++ object files must be created using
-           # "CC -xar", where "CC" is the Sun C++ compiler.  This is
-           # necessary to make sure instantiated templates are included
-           # in the archive.
-           _LT_TAGVAR(old_archive_cmds, $1)='$CC -xar -o $oldlib $oldobjs'
-           ;;
-          gcx*)
-           # Green Hills C++ Compiler
-           _LT_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib'
-
-           # The C++ compiler must be used to create the archive.
-           _LT_TAGVAR(old_archive_cmds, $1)='$CC $LDFLAGS -archive -o $oldlib $oldobjs'
-           ;;
-          *)
-           # GNU C++ compiler with Solaris linker
-           if test "$GXX" = yes && test "$with_gnu_ld" = no; then
-             _LT_TAGVAR(no_undefined_flag, $1)=' ${wl}-z ${wl}defs'
-             if $CC --version | $GREP -v '^2\.7' > /dev/null; then
-               _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $LDFLAGS $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib'
-               _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
-                 $CC -shared -nostdlib ${wl}-M $wl$lib.exp -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp'
-
-               # Commands to make compiler produce verbose output that lists
-               # what "hidden" libraries, object files and flags are used when
-               # linking a shared library.
-               output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "\-L"'
-             else
-               # g++ 2.7 appears to require `-G' NOT `-shared' on this
-               # platform.
-               _LT_TAGVAR(archive_cmds, $1)='$CC -G -nostdlib $LDFLAGS $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib'
-               _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~
-                 $CC -G -nostdlib ${wl}-M $wl$lib.exp -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp'
-
-               # Commands to make compiler produce verbose output that lists
-               # what "hidden" libraries, object files and flags are used when
-               # linking a shared library.
-               output_verbose_link_cmd='$CC -G $CFLAGS -v conftest.$objext 2>&1 | $GREP "\-L"'
-             fi
-
-             _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $wl$libdir'
-             case $host_os in
-               solaris2.[[0-5]] | solaris2.[[0-5]].*) ;;
-               *)
-                 _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}-z ${wl}allextract$convenience ${wl}-z ${wl}defaultextract'
-                 ;;
-             esac
-           fi
-           ;;
-        esac
-        ;;
-
-    sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[[01]].[[10]]* | unixware7* | sco3.2v5.0.[[024]]*)
-      _LT_TAGVAR(no_undefined_flag, $1)='${wl}-z,text'
-      _LT_TAGVAR(archive_cmds_need_lc, $1)=no
-      _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
-      runpath_var='LD_RUN_PATH'
-
-      case $cc_basename in
-        CC*)
-         _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
-         _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
-         ;;
-       *)
-         _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
-         _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
-         ;;
-      esac
-      ;;
-
-      sysv5* | sco3.2v5* | sco5v6*)
-       # Note: We can NOT use -z defs as we might desire, because we do not
-       # link with -lc, and that would cause any symbols used from libc to
-       # always be unresolved, which means just about no library would
-       # ever link correctly.  If we're not using GNU ld we use -z text
-       # though, which does catch some bad symbols but isn't as heavy-handed
-       # as -z defs.
-       _LT_TAGVAR(no_undefined_flag, $1)='${wl}-z,text'
-       _LT_TAGVAR(allow_undefined_flag, $1)='${wl}-z,nodefs'
-       _LT_TAGVAR(archive_cmds_need_lc, $1)=no
-       _LT_TAGVAR(hardcode_shlibpath_var, $1)=no
-       _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R,$libdir'
-       _LT_TAGVAR(hardcode_libdir_separator, $1)=':'
-       _LT_TAGVAR(link_all_deplibs, $1)=yes
-       _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-Bexport'
-       runpath_var='LD_RUN_PATH'
-
-       case $cc_basename in
-          CC*)
-           _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
-           _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
-           ;;
-         *)
-           _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
-           _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
-           ;;
-       esac
-      ;;
-
-      tandem*)
-        case $cc_basename in
-          NCC*)
-           # NonStop-UX NCC 3.20
-           # FIXME: insert proper C++ library support
-           _LT_TAGVAR(ld_shlibs, $1)=no
-           ;;
-          *)
-           # FIXME: insert proper C++ library support
-           _LT_TAGVAR(ld_shlibs, $1)=no
-           ;;
-        esac
-        ;;
-
-      vxworks*)
-        # FIXME: insert proper C++ library support
-        _LT_TAGVAR(ld_shlibs, $1)=no
-        ;;
-
-      *)
-        # FIXME: insert proper C++ library support
-        _LT_TAGVAR(ld_shlibs, $1)=no
-        ;;
-    esac
-
-    AC_MSG_RESULT([$_LT_TAGVAR(ld_shlibs, $1)])
-    test "$_LT_TAGVAR(ld_shlibs, $1)" = no && can_build_shared=no
-
-    _LT_TAGVAR(GCC, $1)="$GXX"
-    _LT_TAGVAR(LD, $1)="$LD"
-
-    ## CAVEAT EMPTOR:
-    ## There is no encapsulation within the following macros, do not change
-    ## the running order or otherwise move them around unless you know exactly
-    ## what you are doing...
-    _LT_SYS_HIDDEN_LIBDEPS($1)
-    _LT_COMPILER_PIC($1)
-    _LT_COMPILER_C_O($1)
-    _LT_COMPILER_FILE_LOCKS($1)
-    _LT_LINKER_SHLIBS($1)
-    _LT_SYS_DYNAMIC_LINKER($1)
-    _LT_LINKER_HARDCODE_LIBPATH($1)
-
-    _LT_CONFIG($1)
-  fi # test -n "$compiler"
-
-  CC=$lt_save_CC
-  LDCXX=$LD
-  LD=$lt_save_LD
-  GCC=$lt_save_GCC
-  with_gnu_ld=$lt_save_with_gnu_ld
-  lt_cv_path_LDCXX=$lt_cv_path_LD
-  lt_cv_path_LD=$lt_save_path_LD
-  lt_cv_prog_gnu_ldcxx=$lt_cv_prog_gnu_ld
-  lt_cv_prog_gnu_ld=$lt_save_with_gnu_ld
-fi # test "$_lt_caught_CXX_error" != yes
-
-AC_LANG_POP
-])# _LT_LANG_CXX_CONFIG
-
-
-# _LT_SYS_HIDDEN_LIBDEPS([TAGNAME])
-# ---------------------------------
-# Figure out "hidden" library dependencies from verbose
-# compiler output when linking a shared library.
-# Parse the compiler output and extract the necessary
-# objects, libraries and library flags.
-m4_defun([_LT_SYS_HIDDEN_LIBDEPS],
-[m4_require([_LT_FILEUTILS_DEFAULTS])dnl
-# Dependencies to place before and after the object being linked:
-_LT_TAGVAR(predep_objects, $1)=
-_LT_TAGVAR(postdep_objects, $1)=
-_LT_TAGVAR(predeps, $1)=
-_LT_TAGVAR(postdeps, $1)=
-_LT_TAGVAR(compiler_lib_search_path, $1)=
-
-dnl we can't use the lt_simple_compile_test_code here,
-dnl because it contains code intended for an executable,
-dnl not a library.  It's possible we should let each
-dnl tag define a new lt_????_link_test_code variable,
-dnl but it's only used here...
-m4_if([$1], [], [cat > conftest.$ac_ext <<_LT_EOF
-int a;
-void foo (void) { a = 0; }
-_LT_EOF
-], [$1], [CXX], [cat > conftest.$ac_ext <<_LT_EOF
-class Foo
-{
-public:
-  Foo (void) { a = 0; }
-private:
-  int a;
-};
-_LT_EOF
-], [$1], [F77], [cat > conftest.$ac_ext <<_LT_EOF
-      subroutine foo
-      implicit none
-      integer*4 a
-      a=0
-      return
-      end
-_LT_EOF
-], [$1], [FC], [cat > conftest.$ac_ext <<_LT_EOF
-      subroutine foo
-      implicit none
-      integer a
-      a=0
-      return
-      end
-_LT_EOF
-], [$1], [GCJ], [cat > conftest.$ac_ext <<_LT_EOF
-public class foo {
-  private int a;
-  public void bar (void) {
-    a = 0;
-  }
-};
-_LT_EOF
-])
-dnl Parse the compiler output and extract the necessary
-dnl objects, libraries and library flags.
-if AC_TRY_EVAL(ac_compile); then
-  # Parse the compiler output and extract the necessary
-  # objects, libraries and library flags.
-
-  # Sentinel used to keep track of whether or not we are before
-  # the conftest object file.
-  pre_test_object_deps_done=no
-
-  for p in `eval "$output_verbose_link_cmd"`; do
-    case $p in
-
-    -L* | -R* | -l*)
-       # Some compilers place space between "-{L,R}" and the path.
-       # Remove the space.
-       if test $p = "-L" ||
-          test $p = "-R"; then
-        prev=$p
-        continue
-       else
-        prev=
-       fi
-
-       if test "$pre_test_object_deps_done" = no; then
-        case $p in
-        -L* | -R*)
-          # Internal compiler library paths should come after those
-          # provided the user.  The postdeps already come after the
-          # user supplied libs so there is no need to process them.
-          if test -z "$_LT_TAGVAR(compiler_lib_search_path, $1)"; then
-            _LT_TAGVAR(compiler_lib_search_path, $1)="${prev}${p}"
-          else
-            _LT_TAGVAR(compiler_lib_search_path, $1)="${_LT_TAGVAR(compiler_lib_search_path, $1)} ${prev}${p}"
-          fi
-          ;;
-        # The "-l" case would never come before the object being
-        # linked, so don't bother handling this case.
-        esac
-       else
-        if test -z "$_LT_TAGVAR(postdeps, $1)"; then
-          _LT_TAGVAR(postdeps, $1)="${prev}${p}"
-        else
-          _LT_TAGVAR(postdeps, $1)="${_LT_TAGVAR(postdeps, $1)} ${prev}${p}"
-        fi
-       fi
-       ;;
-
-    *.$objext)
-       # This assumes that the test object file only shows up
-       # once in the compiler output.
-       if test "$p" = "conftest.$objext"; then
-        pre_test_object_deps_done=yes
-        continue
-       fi
-
-       if test "$pre_test_object_deps_done" = no; then
-        if test -z "$_LT_TAGVAR(predep_objects, $1)"; then
-          _LT_TAGVAR(predep_objects, $1)="$p"
-        else
-          _LT_TAGVAR(predep_objects, $1)="$_LT_TAGVAR(predep_objects, $1) $p"
-        fi
-       else
-        if test -z "$_LT_TAGVAR(postdep_objects, $1)"; then
-          _LT_TAGVAR(postdep_objects, $1)="$p"
-        else
-          _LT_TAGVAR(postdep_objects, $1)="$_LT_TAGVAR(postdep_objects, $1) $p"
-        fi
-       fi
-       ;;
-
-    *) ;; # Ignore the rest.
-
-    esac
-  done
-
-  # Clean up.
-  rm -f a.out a.exe
-else
-  echo "libtool.m4: error: problem compiling $1 test program"
-fi
-
-$RM -f confest.$objext
-
-# PORTME: override above test on systems where it is broken
-m4_if([$1], [CXX],
-[case $host_os in
-interix[[3-9]]*)
-  # Interix 3.5 installs completely hosed .la files for C++, so rather than
-  # hack all around it, let's just trust "g++" to DTRT.
-  _LT_TAGVAR(predep_objects,$1)=
-  _LT_TAGVAR(postdep_objects,$1)=
-  _LT_TAGVAR(postdeps,$1)=
-  ;;
-
-linux*)
-  case `$CC -V 2>&1 | sed 5q` in
-  *Sun\ C*)
-    # Sun C++ 5.9
-
-    # The more standards-conforming stlport4 library is
-    # incompatible with the Cstd library. Avoid specifying
-    # it if it's in CXXFLAGS. Ignore libCrun as
-    # -library=stlport4 depends on it.
-    case " $CXX $CXXFLAGS " in
-    *" -library=stlport4 "*)
-      solaris_use_stlport4=yes
-      ;;
-    esac
-
-    if test "$solaris_use_stlport4" != yes; then
-      _LT_TAGVAR(postdeps,$1)='-library=Cstd -library=Crun'
-    fi
-    ;;
-  esac
-  ;;
-
-solaris*)
-  case $cc_basename in
-  CC*)
-    # The more standards-conforming stlport4 library is
-    # incompatible with the Cstd library. Avoid specifying
-    # it if it's in CXXFLAGS. Ignore libCrun as
-    # -library=stlport4 depends on it.
-    case " $CXX $CXXFLAGS " in
-    *" -library=stlport4 "*)
-      solaris_use_stlport4=yes
-      ;;
-    esac
-
-    # Adding this requires a known-good setup of shared libraries for
-    # Sun compiler versions before 5.6, else PIC objects from an old
-    # archive will be linked into the output, leading to subtle bugs.
-    if test "$solaris_use_stlport4" != yes; then
-      _LT_TAGVAR(postdeps,$1)='-library=Cstd -library=Crun'
-    fi
-    ;;
-  esac
-  ;;
-esac
-])
-
-case " $_LT_TAGVAR(postdeps, $1) " in
-*" -lc "*) _LT_TAGVAR(archive_cmds_need_lc, $1)=no ;;
-esac
- _LT_TAGVAR(compiler_lib_search_dirs, $1)=
-if test -n "${_LT_TAGVAR(compiler_lib_search_path, $1)}"; then
- _LT_TAGVAR(compiler_lib_search_dirs, $1)=`echo " ${_LT_TAGVAR(compiler_lib_search_path, $1)}" | ${SED} -e 's! -L! !g' -e 's!^ !!'`
-fi
-_LT_TAGDECL([], [compiler_lib_search_dirs], [1],
-    [The directories searched by this compiler when creating a shared library])
-_LT_TAGDECL([], [predep_objects], [1],
-    [Dependencies to place before and after the objects being linked to
-    create a shared library])
-_LT_TAGDECL([], [postdep_objects], [1])
-_LT_TAGDECL([], [predeps], [1])
-_LT_TAGDECL([], [postdeps], [1])
-_LT_TAGDECL([], [compiler_lib_search_path], [1],
-    [The library search path used internally by the compiler when linking
-    a shared library])
-])# _LT_SYS_HIDDEN_LIBDEPS
-
-
-# _LT_PROG_F77
-# ------------
-# Since AC_PROG_F77 is broken, in that it returns the empty string
-# if there is no fortran compiler, we have our own version here.
-m4_defun([_LT_PROG_F77],
-[
-pushdef([AC_MSG_ERROR], [_lt_disable_F77=yes])
-AC_PROG_F77
-if test -z "$F77" || test "X$F77" = "Xno"; then
-  _lt_disable_F77=yes
-fi
-popdef([AC_MSG_ERROR])
-])# _LT_PROG_F77
-
-dnl aclocal-1.4 backwards compatibility:
-dnl AC_DEFUN([_LT_PROG_F77], [])
-
-
-# _LT_LANG_F77_CONFIG([TAG])
-# --------------------------
-# Ensure that the configuration variables for a Fortran 77 compiler are
-# suitably defined.  These variables are subsequently used by _LT_CONFIG
-# to write the compiler configuration to `libtool'.
-m4_defun([_LT_LANG_F77_CONFIG],
-[AC_REQUIRE([_LT_PROG_F77])dnl
-AC_LANG_PUSH(Fortran 77)
-
-_LT_TAGVAR(archive_cmds_need_lc, $1)=no
-_LT_TAGVAR(allow_undefined_flag, $1)=
-_LT_TAGVAR(always_export_symbols, $1)=no
-_LT_TAGVAR(archive_expsym_cmds, $1)=
-_LT_TAGVAR(export_dynamic_flag_spec, $1)=
-_LT_TAGVAR(hardcode_direct, $1)=no
-_LT_TAGVAR(hardcode_direct_absolute, $1)=no
-_LT_TAGVAR(hardcode_libdir_flag_spec, $1)=
-_LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)=
-_LT_TAGVAR(hardcode_libdir_separator, $1)=
-_LT_TAGVAR(hardcode_minus_L, $1)=no
-_LT_TAGVAR(hardcode_automatic, $1)=no
-_LT_TAGVAR(inherit_rpath, $1)=no
-_LT_TAGVAR(module_cmds, $1)=
-_LT_TAGVAR(module_expsym_cmds, $1)=
-_LT_TAGVAR(link_all_deplibs, $1)=unknown
-_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds
-_LT_TAGVAR(no_undefined_flag, $1)=
-_LT_TAGVAR(whole_archive_flag_spec, $1)=
-_LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no
-
-# Source file extension for f77 test sources.
-ac_ext=f
-
-# Object file extension for compiled f77 test sources.
-objext=o
-_LT_TAGVAR(objext, $1)=$objext
-
-# No sense in running all these tests if we already determined that
-# the F77 compiler isn't working.  Some variables (like enable_shared)
-# are currently assumed to apply to all compilers on this platform,
-# and will be corrupted by setting them based on a non-working compiler.
-if test "$_lt_disable_F77" != yes; then
-  # Code to be used in simple compile tests
-  lt_simple_compile_test_code="\
-      subroutine t
-      return
-      end
-"
-
-  # Code to be used in simple link tests
-  lt_simple_link_test_code="\
-      program t
-      end
-"
-
-  # ltmain only uses $CC for tagged configurations so make sure $CC is set.
-  _LT_TAG_COMPILER
-
-  # save warnings/boilerplate of simple test code
-  _LT_COMPILER_BOILERPLATE
-  _LT_LINKER_BOILERPLATE
-
-  # Allow CC to be a program name with arguments.
-  lt_save_CC="$CC"
-  lt_save_GCC=$GCC
-  CC=${F77-"f77"}
-  compiler=$CC
-  _LT_TAGVAR(compiler, $1)=$CC
-  _LT_CC_BASENAME([$compiler])
-  GCC=$G77
-  if test -n "$compiler"; then
-    AC_MSG_CHECKING([if libtool supports shared libraries])
-    AC_MSG_RESULT([$can_build_shared])
-
-    AC_MSG_CHECKING([whether to build shared libraries])
-    test "$can_build_shared" = "no" && enable_shared=no
-
-    # On AIX, shared libraries and static libraries use the same namespace, and
-    # are all built from PIC.
-    case $host_os in
-      aix3*)
-        test "$enable_shared" = yes && enable_static=no
-        if test -n "$RANLIB"; then
-          archive_cmds="$archive_cmds~\$RANLIB \$lib"
-          postinstall_cmds='$RANLIB $lib'
-        fi
-        ;;
-      aix[[4-9]]*)
-       if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then
-         test "$enable_shared" = yes && enable_static=no
-       fi
-        ;;
-    esac
-    AC_MSG_RESULT([$enable_shared])
-
-    AC_MSG_CHECKING([whether to build static libraries])
-    # Make sure either enable_shared or enable_static is yes.
-    test "$enable_shared" = yes || enable_static=yes
-    AC_MSG_RESULT([$enable_static])
-
-    _LT_TAGVAR(GCC, $1)="$G77"
-    _LT_TAGVAR(LD, $1)="$LD"
-
-    ## CAVEAT EMPTOR:
-    ## There is no encapsulation within the following macros, do not change
-    ## the running order or otherwise move them around unless you know exactly
-    ## what you are doing...
-    _LT_COMPILER_PIC($1)
-    _LT_COMPILER_C_O($1)
-    _LT_COMPILER_FILE_LOCKS($1)
-    _LT_LINKER_SHLIBS($1)
-    _LT_SYS_DYNAMIC_LINKER($1)
-    _LT_LINKER_HARDCODE_LIBPATH($1)
-
-    _LT_CONFIG($1)
-  fi # test -n "$compiler"
-
-  GCC=$lt_save_GCC
-  CC="$lt_save_CC"
-fi # test "$_lt_disable_F77" != yes
-
-AC_LANG_POP
-])# _LT_LANG_F77_CONFIG
-
-
-# _LT_PROG_FC
-# -----------
-# Since AC_PROG_FC is broken, in that it returns the empty string
-# if there is no fortran compiler, we have our own version here.
-m4_defun([_LT_PROG_FC],
-[
-pushdef([AC_MSG_ERROR], [_lt_disable_FC=yes])
-AC_PROG_FC
-if test -z "$FC" || test "X$FC" = "Xno"; then
-  _lt_disable_FC=yes
-fi
-popdef([AC_MSG_ERROR])
-])# _LT_PROG_FC
-
-dnl aclocal-1.4 backwards compatibility:
-dnl AC_DEFUN([_LT_PROG_FC], [])
-
-
-# _LT_LANG_FC_CONFIG([TAG])
-# -------------------------
-# Ensure that the configuration variables for a Fortran compiler are
-# suitably defined.  These variables are subsequently used by _LT_CONFIG
-# to write the compiler configuration to `libtool'.
-m4_defun([_LT_LANG_FC_CONFIG],
-[AC_REQUIRE([_LT_PROG_FC])dnl
-AC_LANG_PUSH(Fortran)
-
-_LT_TAGVAR(archive_cmds_need_lc, $1)=no
-_LT_TAGVAR(allow_undefined_flag, $1)=
-_LT_TAGVAR(always_export_symbols, $1)=no
-_LT_TAGVAR(archive_expsym_cmds, $1)=
-_LT_TAGVAR(export_dynamic_flag_spec, $1)=
-_LT_TAGVAR(hardcode_direct, $1)=no
-_LT_TAGVAR(hardcode_direct_absolute, $1)=no
-_LT_TAGVAR(hardcode_libdir_flag_spec, $1)=
-_LT_TAGVAR(hardcode_libdir_flag_spec_ld, $1)=
-_LT_TAGVAR(hardcode_libdir_separator, $1)=
-_LT_TAGVAR(hardcode_minus_L, $1)=no
-_LT_TAGVAR(hardcode_automatic, $1)=no
-_LT_TAGVAR(inherit_rpath, $1)=no
-_LT_TAGVAR(module_cmds, $1)=
-_LT_TAGVAR(module_expsym_cmds, $1)=
-_LT_TAGVAR(link_all_deplibs, $1)=unknown
-_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds
-_LT_TAGVAR(no_undefined_flag, $1)=
-_LT_TAGVAR(whole_archive_flag_spec, $1)=
-_LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no
-
-# Source file extension for fc test sources.
-ac_ext=${ac_fc_srcext-f}
-
-# Object file extension for compiled fc test sources.
-objext=o
-_LT_TAGVAR(objext, $1)=$objext
-
-# No sense in running all these tests if we already determined that
-# the FC compiler isn't working.  Some variables (like enable_shared)
-# are currently assumed to apply to all compilers on this platform,
-# and will be corrupted by setting them based on a non-working compiler.
-if test "$_lt_disable_FC" != yes; then
-  # Code to be used in simple compile tests
-  lt_simple_compile_test_code="\
-      subroutine t
-      return
-      end
-"
-
-  # Code to be used in simple link tests
-  lt_simple_link_test_code="\
-      program t
-      end
-"
-
-  # ltmain only uses $CC for tagged configurations so make sure $CC is set.
-  _LT_TAG_COMPILER
-
-  # save warnings/boilerplate of simple test code
-  _LT_COMPILER_BOILERPLATE
-  _LT_LINKER_BOILERPLATE
-
-  # Allow CC to be a program name with arguments.
-  lt_save_CC="$CC"
-  lt_save_GCC=$GCC
-  CC=${FC-"f95"}
-  compiler=$CC
-  GCC=$ac_cv_fc_compiler_gnu
-
-  _LT_TAGVAR(compiler, $1)=$CC
-  _LT_CC_BASENAME([$compiler])
-
-  if test -n "$compiler"; then
-    AC_MSG_CHECKING([if libtool supports shared libraries])
-    AC_MSG_RESULT([$can_build_shared])
-
-    AC_MSG_CHECKING([whether to build shared libraries])
-    test "$can_build_shared" = "no" && enable_shared=no
-
-    # On AIX, shared libraries and static libraries use the same namespace, and
-    # are all built from PIC.
-    case $host_os in
-      aix3*)
-        test "$enable_shared" = yes && enable_static=no
-        if test -n "$RANLIB"; then
-          archive_cmds="$archive_cmds~\$RANLIB \$lib"
-          postinstall_cmds='$RANLIB $lib'
-        fi
-        ;;
-      aix[[4-9]]*)
-       if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then
-         test "$enable_shared" = yes && enable_static=no
-       fi
-        ;;
-    esac
-    AC_MSG_RESULT([$enable_shared])
-
-    AC_MSG_CHECKING([whether to build static libraries])
-    # Make sure either enable_shared or enable_static is yes.
-    test "$enable_shared" = yes || enable_static=yes
-    AC_MSG_RESULT([$enable_static])
-
-    _LT_TAGVAR(GCC, $1)="$ac_cv_fc_compiler_gnu"
-    _LT_TAGVAR(LD, $1)="$LD"
-
-    ## CAVEAT EMPTOR:
-    ## There is no encapsulation within the following macros, do not change
-    ## the running order or otherwise move them around unless you know exactly
-    ## what you are doing...
-    _LT_SYS_HIDDEN_LIBDEPS($1)
-    _LT_COMPILER_PIC($1)
-    _LT_COMPILER_C_O($1)
-    _LT_COMPILER_FILE_LOCKS($1)
-    _LT_LINKER_SHLIBS($1)
-    _LT_SYS_DYNAMIC_LINKER($1)
-    _LT_LINKER_HARDCODE_LIBPATH($1)
-
-    _LT_CONFIG($1)
-  fi # test -n "$compiler"
-
-  GCC=$lt_save_GCC
-  CC="$lt_save_CC"
-fi # test "$_lt_disable_FC" != yes
-
-AC_LANG_POP
-])# _LT_LANG_FC_CONFIG
-
-
-# _LT_LANG_GCJ_CONFIG([TAG])
-# --------------------------
-# Ensure that the configuration variables for the GNU Java Compiler compiler
-# are suitably defined.  These variables are subsequently used by _LT_CONFIG
-# to write the compiler configuration to `libtool'.
-m4_defun([_LT_LANG_GCJ_CONFIG],
-[AC_REQUIRE([LT_PROG_GCJ])dnl
-AC_LANG_SAVE
-
-# Source file extension for Java test sources.
-ac_ext=java
-
-# Object file extension for compiled Java test sources.
-objext=o
-_LT_TAGVAR(objext, $1)=$objext
-
-# Code to be used in simple compile tests
-lt_simple_compile_test_code="class foo {}"
-
-# Code to be used in simple link tests
-lt_simple_link_test_code='public class conftest { public static void main(String[[]] argv) {}; }'
-
-# ltmain only uses $CC for tagged configurations so make sure $CC is set.
-_LT_TAG_COMPILER
-
-# save warnings/boilerplate of simple test code
-_LT_COMPILER_BOILERPLATE
-_LT_LINKER_BOILERPLATE
-
-# Allow CC to be a program name with arguments.
-lt_save_CC="$CC"
-lt_save_GCC=$GCC
-GCC=yes
-CC=${GCJ-"gcj"}
-compiler=$CC
-_LT_TAGVAR(compiler, $1)=$CC
-_LT_TAGVAR(LD, $1)="$LD"
-_LT_CC_BASENAME([$compiler])
-
-# GCJ did not exist at the time GCC didn't implicitly link libc in.
-_LT_TAGVAR(archive_cmds_need_lc, $1)=no
-
-_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds
-
-## CAVEAT EMPTOR:
-## There is no encapsulation within the following macros, do not change
-## the running order or otherwise move them around unless you know exactly
-## what you are doing...
-if test -n "$compiler"; then
-  _LT_COMPILER_NO_RTTI($1)
-  _LT_COMPILER_PIC($1)
-  _LT_COMPILER_C_O($1)
-  _LT_COMPILER_FILE_LOCKS($1)
-  _LT_LINKER_SHLIBS($1)
-  _LT_LINKER_HARDCODE_LIBPATH($1)
-
-  _LT_CONFIG($1)
-fi
-
-AC_LANG_RESTORE
-
-GCC=$lt_save_GCC
-CC="$lt_save_CC"
-])# _LT_LANG_GCJ_CONFIG
-
-
-# _LT_LANG_RC_CONFIG([TAG])
-# -------------------------
-# Ensure that the configuration variables for the Windows resource compiler
-# are suitably defined.  These variables are subsequently used by _LT_CONFIG
-# to write the compiler configuration to `libtool'.
-m4_defun([_LT_LANG_RC_CONFIG],
-[AC_REQUIRE([LT_PROG_RC])dnl
-AC_LANG_SAVE
-
-# Source file extension for RC test sources.
-ac_ext=rc
-
-# Object file extension for compiled RC test sources.
-objext=o
-_LT_TAGVAR(objext, $1)=$objext
-
-# Code to be used in simple compile tests
-lt_simple_compile_test_code='sample MENU { MENUITEM "&Soup", 100, CHECKED }'
-
-# Code to be used in simple link tests
-lt_simple_link_test_code="$lt_simple_compile_test_code"
-
-# ltmain only uses $CC for tagged configurations so make sure $CC is set.
-_LT_TAG_COMPILER
-
-# save warnings/boilerplate of simple test code
-_LT_COMPILER_BOILERPLATE
-_LT_LINKER_BOILERPLATE
-
-# Allow CC to be a program name with arguments.
-lt_save_CC="$CC"
-lt_save_GCC=$GCC
-GCC=
-CC=${RC-"windres"}
-compiler=$CC
-_LT_TAGVAR(compiler, $1)=$CC
-_LT_CC_BASENAME([$compiler])
-_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)=yes
-
-if test -n "$compiler"; then
-  :
-  _LT_CONFIG($1)
-fi
-
-GCC=$lt_save_GCC
-AC_LANG_RESTORE
-CC="$lt_save_CC"
-])# _LT_LANG_RC_CONFIG
-
-
-# LT_PROG_GCJ
-# -----------
-AC_DEFUN([LT_PROG_GCJ],
-[m4_ifdef([AC_PROG_GCJ], [AC_PROG_GCJ],
-  [m4_ifdef([A][M_PROG_GCJ], [A][M_PROG_GCJ],
-    [AC_CHECK_TOOL(GCJ, gcj,)
-      test "x${GCJFLAGS+set}" = xset || GCJFLAGS="-g -O2"
-      AC_SUBST(GCJFLAGS)])])[]dnl
-])
-
-# Old name:
-AU_ALIAS([LT_AC_PROG_GCJ], [LT_PROG_GCJ])
-dnl aclocal-1.4 backwards compatibility:
-dnl AC_DEFUN([LT_AC_PROG_GCJ], [])
-
-
-# LT_PROG_RC
-# ----------
-AC_DEFUN([LT_PROG_RC],
-[AC_CHECK_TOOL(RC, windres,)
-])
-
-# Old name:
-AU_ALIAS([LT_AC_PROG_RC], [LT_PROG_RC])
-dnl aclocal-1.4 backwards compatibility:
-dnl AC_DEFUN([LT_AC_PROG_RC], [])
-
-
-# _LT_DECL_EGREP
-# --------------
-# If we don't have a new enough Autoconf to choose the best grep
-# available, choose the one first in the user's PATH.
-m4_defun([_LT_DECL_EGREP],
-[AC_REQUIRE([AC_PROG_EGREP])dnl
-AC_REQUIRE([AC_PROG_FGREP])dnl
-test -z "$GREP" && GREP=grep
-_LT_DECL([], [GREP], [1], [A grep program that handles long lines])
-_LT_DECL([], [EGREP], [1], [An ERE matcher])
-_LT_DECL([], [FGREP], [1], [A literal string matcher])
-dnl Non-bleeding-edge autoconf doesn't subst GREP, so do it here too
-AC_SUBST([GREP])
-])
-
-
-# _LT_DECL_OBJDUMP
-# --------------
-# If we don't have a new enough Autoconf to choose the best objdump
-# available, choose the one first in the user's PATH.
-m4_defun([_LT_DECL_OBJDUMP],
-[AC_CHECK_TOOL(OBJDUMP, objdump, false)
-test -z "$OBJDUMP" && OBJDUMP=objdump
-_LT_DECL([], [OBJDUMP], [1], [An object symbol dumper])
-AC_SUBST([OBJDUMP])
-])
-
-
-# _LT_DECL_SED
-# ------------
-# Check for a fully-functional sed program, that truncates
-# as few characters as possible.  Prefer GNU sed if found.
-m4_defun([_LT_DECL_SED],
-[AC_PROG_SED
-test -z "$SED" && SED=sed
-Xsed="$SED -e 1s/^X//"
-_LT_DECL([], [SED], [1], [A sed program that does not truncate output])
-_LT_DECL([], [Xsed], ["\$SED -e 1s/^X//"],
-    [Sed that helps us avoid accidentally triggering echo(1) options like -n])
-])# _LT_DECL_SED
-
-m4_ifndef([AC_PROG_SED], [
-############################################################
-# NOTE: This macro has been submitted for inclusion into   #
-#  GNU Autoconf as AC_PROG_SED.  When it is available in   #
-#  a released version of Autoconf we should remove this    #
-#  macro and use it instead.                               #
-############################################################
-
-m4_defun([AC_PROG_SED],
-[AC_MSG_CHECKING([for a sed that does not truncate output])
-AC_CACHE_VAL(lt_cv_path_SED,
-[# Loop through the user's path and test for sed and gsed.
-# Then use that list of sed's as ones to test for truncation.
-as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
-  IFS=$as_save_IFS
-  test -z "$as_dir" && as_dir=.
-  for lt_ac_prog in sed gsed; do
-    for ac_exec_ext in '' $ac_executable_extensions; do
-      if $as_executable_p "$as_dir/$lt_ac_prog$ac_exec_ext"; then
-        lt_ac_sed_list="$lt_ac_sed_list $as_dir/$lt_ac_prog$ac_exec_ext"
-      fi
-    done
-  done
-done
-IFS=$as_save_IFS
-lt_ac_max=0
-lt_ac_count=0
-# Add /usr/xpg4/bin/sed as it is typically found on Solaris
-# along with /bin/sed that truncates output.
-for lt_ac_sed in $lt_ac_sed_list /usr/xpg4/bin/sed; do
-  test ! -f $lt_ac_sed && continue
-  cat /dev/null > conftest.in
-  lt_ac_count=0
-  echo $ECHO_N "0123456789$ECHO_C" >conftest.in
-  # Check for GNU sed and select it if it is found.
-  if "$lt_ac_sed" --version 2>&1 < /dev/null | grep 'GNU' > /dev/null; then
-    lt_cv_path_SED=$lt_ac_sed
-    break
-  fi
-  while true; do
-    cat conftest.in conftest.in >conftest.tmp
-    mv conftest.tmp conftest.in
-    cp conftest.in conftest.nl
-    echo >>conftest.nl
-    $lt_ac_sed -e 's/a$//' < conftest.nl >conftest.out || break
-    cmp -s conftest.out conftest.nl || break
-    # 10000 chars as input seems more than enough
-    test $lt_ac_count -gt 10 && break
-    lt_ac_count=`expr $lt_ac_count + 1`
-    if test $lt_ac_count -gt $lt_ac_max; then
-      lt_ac_max=$lt_ac_count
-      lt_cv_path_SED=$lt_ac_sed
-    fi
-  done
-done
-])
-SED=$lt_cv_path_SED
-AC_SUBST([SED])
-AC_MSG_RESULT([$SED])
-])#AC_PROG_SED
-])#m4_ifndef
-
-# Old name:
-AU_ALIAS([LT_AC_PROG_SED], [AC_PROG_SED])
-dnl aclocal-1.4 backwards compatibility:
-dnl AC_DEFUN([LT_AC_PROG_SED], [])
-
-
-# _LT_CHECK_SHELL_FEATURES
-# ------------------------
-# Find out whether the shell is Bourne or XSI compatible,
-# or has some other useful features.
-m4_defun([_LT_CHECK_SHELL_FEATURES],
-[AC_MSG_CHECKING([whether the shell understands some XSI constructs])
-# Try some XSI features
-xsi_shell=no
-( _lt_dummy="a/b/c"
-  test "${_lt_dummy##*/},${_lt_dummy%/*},"${_lt_dummy%"$_lt_dummy"}, \
-      = c,a/b,, \
-    && eval 'test $(( 1 + 1 )) -eq 2 \
-    && test "${#_lt_dummy}" -eq 5' ) >/dev/null 2>&1 \
-  && xsi_shell=yes
-AC_MSG_RESULT([$xsi_shell])
-_LT_CONFIG_LIBTOOL_INIT([xsi_shell='$xsi_shell'])
-
-AC_MSG_CHECKING([whether the shell understands "+="])
-lt_shell_append=no
-( foo=bar; set foo baz; eval "$[1]+=\$[2]" && test "$foo" = barbaz ) \
-    >/dev/null 2>&1 \
-  && lt_shell_append=yes
-AC_MSG_RESULT([$lt_shell_append])
-_LT_CONFIG_LIBTOOL_INIT([lt_shell_append='$lt_shell_append'])
-
-if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then
-  lt_unset=unset
-else
-  lt_unset=false
-fi
-_LT_DECL([], [lt_unset], [0], [whether the shell understands "unset"])dnl
-
-# test EBCDIC or ASCII
-case `echo X|tr X '\101'` in
- A) # ASCII based system
-    # \n is not interpreted correctly by Solaris 8 /usr/ucb/tr
-  lt_SP2NL='tr \040 \012'
-  lt_NL2SP='tr \015\012 \040\040'
-  ;;
- *) # EBCDIC based system
-  lt_SP2NL='tr \100 \n'
-  lt_NL2SP='tr \r\n \100\100'
-  ;;
-esac
-_LT_DECL([SP2NL], [lt_SP2NL], [1], [turn spaces into newlines])dnl
-_LT_DECL([NL2SP], [lt_NL2SP], [1], [turn newlines into spaces])dnl
-])# _LT_CHECK_SHELL_FEATURES
-
-
-# _LT_PROG_XSI_SHELLFNS
-# ---------------------
-# Bourne and XSI compatible variants of some useful shell functions.
-m4_defun([_LT_PROG_XSI_SHELLFNS],
-[case $xsi_shell in
-  yes)
-    cat << \_LT_EOF >> "$cfgfile"
-
-# func_dirname file append nondir_replacement
-# Compute the dirname of FILE.  If nonempty, add APPEND to the result,
-# otherwise set result to NONDIR_REPLACEMENT.
-func_dirname ()
-{
-  case ${1} in
-    */*) func_dirname_result="${1%/*}${2}" ;;
-    *  ) func_dirname_result="${3}" ;;
-  esac
-}
-
-# func_basename file
-func_basename ()
-{
-  func_basename_result="${1##*/}"
-}
-
-# func_dirname_and_basename file append nondir_replacement
-# perform func_basename and func_dirname in a single function
-# call:
-#   dirname:  Compute the dirname of FILE.  If nonempty,
-#             add APPEND to the result, otherwise set result
-#             to NONDIR_REPLACEMENT.
-#             value returned in "$func_dirname_result"
-#   basename: Compute filename of FILE.
-#             value retuned in "$func_basename_result"
-# Implementation must be kept synchronized with func_dirname
-# and func_basename. For efficiency, we do not delegate to
-# those functions but instead duplicate the functionality here.
-func_dirname_and_basename ()
-{
-  case ${1} in
-    */*) func_dirname_result="${1%/*}${2}" ;;
-    *  ) func_dirname_result="${3}" ;;
-  esac
-  func_basename_result="${1##*/}"
-}
-
-# func_stripname prefix suffix name
-# strip PREFIX and SUFFIX off of NAME.
-# PREFIX and SUFFIX must not contain globbing or regex special
-# characters, hashes, percent signs, but SUFFIX may contain a leading
-# dot (in which case that matches only a dot).
-func_stripname ()
-{
-  # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are
-  # positional parameters, so assign one to ordinary parameter first.
-  func_stripname_result=${3}
-  func_stripname_result=${func_stripname_result#"${1}"}
-  func_stripname_result=${func_stripname_result%"${2}"}
-}
-
-# func_opt_split
-func_opt_split ()
-{
-  func_opt_split_opt=${1%%=*}
-  func_opt_split_arg=${1#*=}
-}
-
-# func_lo2o object
-func_lo2o ()
-{
-  case ${1} in
-    *.lo) func_lo2o_result=${1%.lo}.${objext} ;;
-    *)    func_lo2o_result=${1} ;;
-  esac
-}
-
-# func_xform libobj-or-source
-func_xform ()
-{
-  func_xform_result=${1%.*}.lo
-}
-
-# func_arith arithmetic-term...
-func_arith ()
-{
-  func_arith_result=$(( $[*] ))
-}
-
-# func_len string
-# STRING may not start with a hyphen.
-func_len ()
-{
-  func_len_result=${#1}
-}
-
-_LT_EOF
-    ;;
-  *) # Bourne compatible functions.
-    cat << \_LT_EOF >> "$cfgfile"
-
-# func_dirname file append nondir_replacement
-# Compute the dirname of FILE.  If nonempty, add APPEND to the result,
-# otherwise set result to NONDIR_REPLACEMENT.
-func_dirname ()
-{
-  # Extract subdirectory from the argument.
-  func_dirname_result=`$ECHO "X${1}" | $Xsed -e "$dirname"`
-  if test "X$func_dirname_result" = "X${1}"; then
-    func_dirname_result="${3}"
-  else
-    func_dirname_result="$func_dirname_result${2}"
-  fi
-}
-
-# func_basename file
-func_basename ()
-{
-  func_basename_result=`$ECHO "X${1}" | $Xsed -e "$basename"`
-}
-
-dnl func_dirname_and_basename
-dnl A portable version of this function is already defined in general.m4sh
-dnl so there is no need for it here.
-
-# func_stripname prefix suffix name
-# strip PREFIX and SUFFIX off of NAME.
-# PREFIX and SUFFIX must not contain globbing or regex special
-# characters, hashes, percent signs, but SUFFIX may contain a leading
-# dot (in which case that matches only a dot).
-# func_strip_suffix prefix name
-func_stripname ()
-{
-  case ${2} in
-    .*) func_stripname_result=`$ECHO "X${3}" \
-           | $Xsed -e "s%^${1}%%" -e "s%\\\\${2}\$%%"`;;
-    *)  func_stripname_result=`$ECHO "X${3}" \
-           | $Xsed -e "s%^${1}%%" -e "s%${2}\$%%"`;;
-  esac
-}
-
-# sed scripts:
-my_sed_long_opt='1s/^\(-[[^=]]*\)=.*/\1/;q'
-my_sed_long_arg='1s/^-[[^=]]*=//'
-
-# func_opt_split
-func_opt_split ()
-{
-  func_opt_split_opt=`$ECHO "X${1}" | $Xsed -e "$my_sed_long_opt"`
-  func_opt_split_arg=`$ECHO "X${1}" | $Xsed -e "$my_sed_long_arg"`
-}
-
-# func_lo2o object
-func_lo2o ()
-{
-  func_lo2o_result=`$ECHO "X${1}" | $Xsed -e "$lo2o"`
-}
-
-# func_xform libobj-or-source
-func_xform ()
-{
-  func_xform_result=`$ECHO "X${1}" | $Xsed -e 's/\.[[^.]]*$/.lo/'`
-}
-
-# func_arith arithmetic-term...
-func_arith ()
-{
-  func_arith_result=`expr "$[@]"`
-}
-
-# func_len string
-# STRING may not start with a hyphen.
-func_len ()
-{
-  func_len_result=`expr "$[1]" : ".*" 2>/dev/null || echo $max_cmd_len`
-}
-
-_LT_EOF
-esac
-
-case $lt_shell_append in
-  yes)
-    cat << \_LT_EOF >> "$cfgfile"
-
-# func_append var value
-# Append VALUE to the end of shell variable VAR.
-func_append ()
-{
-  eval "$[1]+=\$[2]"
-}
-_LT_EOF
-    ;;
-  *)
-    cat << \_LT_EOF >> "$cfgfile"
-
-# func_append var value
-# Append VALUE to the end of shell variable VAR.
-func_append ()
-{
-  eval "$[1]=\$$[1]\$[2]"
-}
-
-_LT_EOF
-    ;;
-  esac
-])
diff --git a/m4/ltoptions.m4 b/m4/ltoptions.m4
deleted file mode 100644 (file)
index 34151a3..0000000
+++ /dev/null
@@ -1,368 +0,0 @@
-# Helper functions for option handling.                    -*- Autoconf -*-
-#
-#   Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc.
-#   Written by Gary V. Vaughan, 2004
-#
-# This file is free software; the Free Software Foundation gives
-# unlimited permission to copy and/or distribute it, with or without
-# modifications, as long as this notice is preserved.
-
-# serial 6 ltoptions.m4
-
-# This is to help aclocal find these macros, as it can't see m4_define.
-AC_DEFUN([LTOPTIONS_VERSION], [m4_if([1])])
-
-
-# _LT_MANGLE_OPTION(MACRO-NAME, OPTION-NAME)
-# ------------------------------------------
-m4_define([_LT_MANGLE_OPTION],
-[[_LT_OPTION_]m4_bpatsubst($1__$2, [[^a-zA-Z0-9_]], [_])])
-
-
-# _LT_SET_OPTION(MACRO-NAME, OPTION-NAME)
-# ---------------------------------------
-# Set option OPTION-NAME for macro MACRO-NAME, and if there is a
-# matching handler defined, dispatch to it.  Other OPTION-NAMEs are
-# saved as a flag.
-m4_define([_LT_SET_OPTION],
-[m4_define(_LT_MANGLE_OPTION([$1], [$2]))dnl
-m4_ifdef(_LT_MANGLE_DEFUN([$1], [$2]),
-        _LT_MANGLE_DEFUN([$1], [$2]),
-    [m4_warning([Unknown $1 option `$2'])])[]dnl
-])
-
-
-# _LT_IF_OPTION(MACRO-NAME, OPTION-NAME, IF-SET, [IF-NOT-SET])
-# ------------------------------------------------------------
-# Execute IF-SET if OPTION is set, IF-NOT-SET otherwise.
-m4_define([_LT_IF_OPTION],
-[m4_ifdef(_LT_MANGLE_OPTION([$1], [$2]), [$3], [$4])])
-
-
-# _LT_UNLESS_OPTIONS(MACRO-NAME, OPTION-LIST, IF-NOT-SET)
-# -------------------------------------------------------
-# Execute IF-NOT-SET unless all options in OPTION-LIST for MACRO-NAME
-# are set.
-m4_define([_LT_UNLESS_OPTIONS],
-[m4_foreach([_LT_Option], m4_split(m4_normalize([$2])),
-           [m4_ifdef(_LT_MANGLE_OPTION([$1], _LT_Option),
-                     [m4_define([$0_found])])])[]dnl
-m4_ifdef([$0_found], [m4_undefine([$0_found])], [$3
-])[]dnl
-])
-
-
-# _LT_SET_OPTIONS(MACRO-NAME, OPTION-LIST)
-# ----------------------------------------
-# OPTION-LIST is a space-separated list of Libtool options associated
-# with MACRO-NAME.  If any OPTION has a matching handler declared with
-# LT_OPTION_DEFINE, dispatch to that macro; otherwise complain about
-# the unknown option and exit.
-m4_defun([_LT_SET_OPTIONS],
-[# Set options
-m4_foreach([_LT_Option], m4_split(m4_normalize([$2])),
-    [_LT_SET_OPTION([$1], _LT_Option)])
-
-m4_if([$1],[LT_INIT],[
-  dnl
-  dnl Simply set some default values (i.e off) if boolean options were not
-  dnl specified:
-  _LT_UNLESS_OPTIONS([LT_INIT], [dlopen], [enable_dlopen=no
-  ])
-  _LT_UNLESS_OPTIONS([LT_INIT], [win32-dll], [enable_win32_dll=no
-  ])
-  dnl
-  dnl If no reference was made to various pairs of opposing options, then
-  dnl we run the default mode handler for the pair.  For example, if neither
-  dnl `shared' nor `disable-shared' was passed, we enable building of shared
-  dnl archives by default:
-  _LT_UNLESS_OPTIONS([LT_INIT], [shared disable-shared], [_LT_ENABLE_SHARED])
-  _LT_UNLESS_OPTIONS([LT_INIT], [static disable-static], [_LT_ENABLE_STATIC])
-  _LT_UNLESS_OPTIONS([LT_INIT], [pic-only no-pic], [_LT_WITH_PIC])
-  _LT_UNLESS_OPTIONS([LT_INIT], [fast-install disable-fast-install],
-                  [_LT_ENABLE_FAST_INSTALL])
-  ])
-])# _LT_SET_OPTIONS
-
-
-## --------------------------------- ##
-## Macros to handle LT_INIT options. ##
-## --------------------------------- ##
-
-# _LT_MANGLE_DEFUN(MACRO-NAME, OPTION-NAME)
-# -----------------------------------------
-m4_define([_LT_MANGLE_DEFUN],
-[[_LT_OPTION_DEFUN_]m4_bpatsubst(m4_toupper([$1__$2]), [[^A-Z0-9_]], [_])])
-
-
-# LT_OPTION_DEFINE(MACRO-NAME, OPTION-NAME, CODE)
-# -----------------------------------------------
-m4_define([LT_OPTION_DEFINE],
-[m4_define(_LT_MANGLE_DEFUN([$1], [$2]), [$3])[]dnl
-])# LT_OPTION_DEFINE
-
-
-# dlopen
-# ------
-LT_OPTION_DEFINE([LT_INIT], [dlopen], [enable_dlopen=yes
-])
-
-AU_DEFUN([AC_LIBTOOL_DLOPEN],
-[_LT_SET_OPTION([LT_INIT], [dlopen])
-AC_DIAGNOSE([obsolete],
-[$0: Remove this warning and the call to _LT_SET_OPTION when you
-put the `dlopen' option into LT_INIT's first parameter.])
-])
-
-dnl aclocal-1.4 backwards compatibility:
-dnl AC_DEFUN([AC_LIBTOOL_DLOPEN], [])
-
-
-# win32-dll
-# ---------
-# Declare package support for building win32 dll's.
-LT_OPTION_DEFINE([LT_INIT], [win32-dll],
-[enable_win32_dll=yes
-
-case $host in
-*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-cegcc*)
-  AC_CHECK_TOOL(AS, as, false)
-  AC_CHECK_TOOL(DLLTOOL, dlltool, false)
-  AC_CHECK_TOOL(OBJDUMP, objdump, false)
-  ;;
-esac
-
-test -z "$AS" && AS=as
-_LT_DECL([], [AS],      [0], [Assembler program])dnl
-
-test -z "$DLLTOOL" && DLLTOOL=dlltool
-_LT_DECL([], [DLLTOOL], [0], [DLL creation program])dnl
-
-test -z "$OBJDUMP" && OBJDUMP=objdump
-_LT_DECL([], [OBJDUMP], [0], [Object dumper program])dnl
-])# win32-dll
-
-AU_DEFUN([AC_LIBTOOL_WIN32_DLL],
-[AC_REQUIRE([AC_CANONICAL_HOST])dnl
-_LT_SET_OPTION([LT_INIT], [win32-dll])
-AC_DIAGNOSE([obsolete],
-[$0: Remove this warning and the call to _LT_SET_OPTION when you
-put the `win32-dll' option into LT_INIT's first parameter.])
-])
-
-dnl aclocal-1.4 backwards compatibility:
-dnl AC_DEFUN([AC_LIBTOOL_WIN32_DLL], [])
-
-
-# _LT_ENABLE_SHARED([DEFAULT])
-# ----------------------------
-# implement the --enable-shared flag, and supports the `shared' and
-# `disable-shared' LT_INIT options.
-# DEFAULT is either `yes' or `no'.  If omitted, it defaults to `yes'.
-m4_define([_LT_ENABLE_SHARED],
-[m4_define([_LT_ENABLE_SHARED_DEFAULT], [m4_if($1, no, no, yes)])dnl
-AC_ARG_ENABLE([shared],
-    [AS_HELP_STRING([--enable-shared@<:@=PKGS@:>@],
-       [build shared libraries @<:@default=]_LT_ENABLE_SHARED_DEFAULT[@:>@])],
-    [p=${PACKAGE-default}
-    case $enableval in
-    yes) enable_shared=yes ;;
-    no) enable_shared=no ;;
-    *)
-      enable_shared=no
-      # Look at the argument we got.  We use all the common list separators.
-      lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
-      for pkg in $enableval; do
-       IFS="$lt_save_ifs"
-       if test "X$pkg" = "X$p"; then
-         enable_shared=yes
-       fi
-      done
-      IFS="$lt_save_ifs"
-      ;;
-    esac],
-    [enable_shared=]_LT_ENABLE_SHARED_DEFAULT)
-
-    _LT_DECL([build_libtool_libs], [enable_shared], [0],
-       [Whether or not to build shared libraries])
-])# _LT_ENABLE_SHARED
-
-LT_OPTION_DEFINE([LT_INIT], [shared], [_LT_ENABLE_SHARED([yes])])
-LT_OPTION_DEFINE([LT_INIT], [disable-shared], [_LT_ENABLE_SHARED([no])])
-
-# Old names:
-AC_DEFUN([AC_ENABLE_SHARED],
-[_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[shared])
-])
-
-AC_DEFUN([AC_DISABLE_SHARED],
-[_LT_SET_OPTION([LT_INIT], [disable-shared])
-])
-
-AU_DEFUN([AM_ENABLE_SHARED], [AC_ENABLE_SHARED($@)])
-AU_DEFUN([AM_DISABLE_SHARED], [AC_DISABLE_SHARED($@)])
-
-dnl aclocal-1.4 backwards compatibility:
-dnl AC_DEFUN([AM_ENABLE_SHARED], [])
-dnl AC_DEFUN([AM_DISABLE_SHARED], [])
-
-
-
-# _LT_ENABLE_STATIC([DEFAULT])
-# ----------------------------
-# implement the --enable-static flag, and support the `static' and
-# `disable-static' LT_INIT options.
-# DEFAULT is either `yes' or `no'.  If omitted, it defaults to `yes'.
-m4_define([_LT_ENABLE_STATIC],
-[m4_define([_LT_ENABLE_STATIC_DEFAULT], [m4_if($1, no, no, yes)])dnl
-AC_ARG_ENABLE([static],
-    [AS_HELP_STRING([--enable-static@<:@=PKGS@:>@],
-       [build static libraries @<:@default=]_LT_ENABLE_STATIC_DEFAULT[@:>@])],
-    [p=${PACKAGE-default}
-    case $enableval in
-    yes) enable_static=yes ;;
-    no) enable_static=no ;;
-    *)
-     enable_static=no
-      # Look at the argument we got.  We use all the common list separators.
-      lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
-      for pkg in $enableval; do
-       IFS="$lt_save_ifs"
-       if test "X$pkg" = "X$p"; then
-         enable_static=yes
-       fi
-      done
-      IFS="$lt_save_ifs"
-      ;;
-    esac],
-    [enable_static=]_LT_ENABLE_STATIC_DEFAULT)
-
-    _LT_DECL([build_old_libs], [enable_static], [0],
-       [Whether or not to build static libraries])
-])# _LT_ENABLE_STATIC
-
-LT_OPTION_DEFINE([LT_INIT], [static], [_LT_ENABLE_STATIC([yes])])
-LT_OPTION_DEFINE([LT_INIT], [disable-static], [_LT_ENABLE_STATIC([no])])
-
-# Old names:
-AC_DEFUN([AC_ENABLE_STATIC],
-[_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[static])
-])
-
-AC_DEFUN([AC_DISABLE_STATIC],
-[_LT_SET_OPTION([LT_INIT], [disable-static])
-])
-
-AU_DEFUN([AM_ENABLE_STATIC], [AC_ENABLE_STATIC($@)])
-AU_DEFUN([AM_DISABLE_STATIC], [AC_DISABLE_STATIC($@)])
-
-dnl aclocal-1.4 backwards compatibility:
-dnl AC_DEFUN([AM_ENABLE_STATIC], [])
-dnl AC_DEFUN([AM_DISABLE_STATIC], [])
-
-
-
-# _LT_ENABLE_FAST_INSTALL([DEFAULT])
-# ----------------------------------
-# implement the --enable-fast-install flag, and support the `fast-install'
-# and `disable-fast-install' LT_INIT options.
-# DEFAULT is either `yes' or `no'.  If omitted, it defaults to `yes'.
-m4_define([_LT_ENABLE_FAST_INSTALL],
-[m4_define([_LT_ENABLE_FAST_INSTALL_DEFAULT], [m4_if($1, no, no, yes)])dnl
-AC_ARG_ENABLE([fast-install],
-    [AS_HELP_STRING([--enable-fast-install@<:@=PKGS@:>@],
-    [optimize for fast installation @<:@default=]_LT_ENABLE_FAST_INSTALL_DEFAULT[@:>@])],
-    [p=${PACKAGE-default}
-    case $enableval in
-    yes) enable_fast_install=yes ;;
-    no) enable_fast_install=no ;;
-    *)
-      enable_fast_install=no
-      # Look at the argument we got.  We use all the common list separators.
-      lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
-      for pkg in $enableval; do
-       IFS="$lt_save_ifs"
-       if test "X$pkg" = "X$p"; then
-         enable_fast_install=yes
-       fi
-      done
-      IFS="$lt_save_ifs"
-      ;;
-    esac],
-    [enable_fast_install=]_LT_ENABLE_FAST_INSTALL_DEFAULT)
-
-_LT_DECL([fast_install], [enable_fast_install], [0],
-        [Whether or not to optimize for fast installation])dnl
-])# _LT_ENABLE_FAST_INSTALL
-
-LT_OPTION_DEFINE([LT_INIT], [fast-install], [_LT_ENABLE_FAST_INSTALL([yes])])
-LT_OPTION_DEFINE([LT_INIT], [disable-fast-install], [_LT_ENABLE_FAST_INSTALL([no])])
-
-# Old names:
-AU_DEFUN([AC_ENABLE_FAST_INSTALL],
-[_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[fast-install])
-AC_DIAGNOSE([obsolete],
-[$0: Remove this warning and the call to _LT_SET_OPTION when you put
-the `fast-install' option into LT_INIT's first parameter.])
-])
-
-AU_DEFUN([AC_DISABLE_FAST_INSTALL],
-[_LT_SET_OPTION([LT_INIT], [disable-fast-install])
-AC_DIAGNOSE([obsolete],
-[$0: Remove this warning and the call to _LT_SET_OPTION when you put
-the `disable-fast-install' option into LT_INIT's first parameter.])
-])
-
-dnl aclocal-1.4 backwards compatibility:
-dnl AC_DEFUN([AC_ENABLE_FAST_INSTALL], [])
-dnl AC_DEFUN([AM_DISABLE_FAST_INSTALL], [])
-
-
-# _LT_WITH_PIC([MODE])
-# --------------------
-# implement the --with-pic flag, and support the `pic-only' and `no-pic'
-# LT_INIT options.
-# MODE is either `yes' or `no'.  If omitted, it defaults to `both'.
-m4_define([_LT_WITH_PIC],
-[AC_ARG_WITH([pic],
-    [AS_HELP_STRING([--with-pic],
-       [try to use only PIC/non-PIC objects @<:@default=use both@:>@])],
-    [pic_mode="$withval"],
-    [pic_mode=default])
-
-test -z "$pic_mode" && pic_mode=m4_default([$1], [default])
-
-_LT_DECL([], [pic_mode], [0], [What type of objects to build])dnl
-])# _LT_WITH_PIC
-
-LT_OPTION_DEFINE([LT_INIT], [pic-only], [_LT_WITH_PIC([yes])])
-LT_OPTION_DEFINE([LT_INIT], [no-pic], [_LT_WITH_PIC([no])])
-
-# Old name:
-AU_DEFUN([AC_LIBTOOL_PICMODE],
-[_LT_SET_OPTION([LT_INIT], [pic-only])
-AC_DIAGNOSE([obsolete],
-[$0: Remove this warning and the call to _LT_SET_OPTION when you
-put the `pic-only' option into LT_INIT's first parameter.])
-])
-
-dnl aclocal-1.4 backwards compatibility:
-dnl AC_DEFUN([AC_LIBTOOL_PICMODE], [])
-
-## ----------------- ##
-## LTDL_INIT Options ##
-## ----------------- ##
-
-m4_define([_LTDL_MODE], [])
-LT_OPTION_DEFINE([LTDL_INIT], [nonrecursive],
-                [m4_define([_LTDL_MODE], [nonrecursive])])
-LT_OPTION_DEFINE([LTDL_INIT], [recursive],
-                [m4_define([_LTDL_MODE], [recursive])])
-LT_OPTION_DEFINE([LTDL_INIT], [subproject],
-                [m4_define([_LTDL_MODE], [subproject])])
-
-m4_define([_LTDL_TYPE], [])
-LT_OPTION_DEFINE([LTDL_INIT], [installable],
-                [m4_define([_LTDL_TYPE], [installable])])
-LT_OPTION_DEFINE([LTDL_INIT], [convenience],
-                [m4_define([_LTDL_TYPE], [convenience])])
diff --git a/m4/ltsugar.m4 b/m4/ltsugar.m4
deleted file mode 100644 (file)
index 9000a05..0000000
+++ /dev/null
@@ -1,123 +0,0 @@
-# ltsugar.m4 -- libtool m4 base layer.                         -*-Autoconf-*-
-#
-# Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc.
-# Written by Gary V. Vaughan, 2004
-#
-# This file is free software; the Free Software Foundation gives
-# unlimited permission to copy and/or distribute it, with or without
-# modifications, as long as this notice is preserved.
-
-# serial 6 ltsugar.m4
-
-# This is to help aclocal find these macros, as it can't see m4_define.
-AC_DEFUN([LTSUGAR_VERSION], [m4_if([0.1])])
-
-
-# lt_join(SEP, ARG1, [ARG2...])
-# -----------------------------
-# Produce ARG1SEPARG2...SEPARGn, omitting [] arguments and their
-# associated separator.
-# Needed until we can rely on m4_join from Autoconf 2.62, since all earlier
-# versions in m4sugar had bugs.
-m4_define([lt_join],
-[m4_if([$#], [1], [],
-       [$#], [2], [[$2]],
-       [m4_if([$2], [], [], [[$2]_])$0([$1], m4_shift(m4_shift($@)))])])
-m4_define([_lt_join],
-[m4_if([$#$2], [2], [],
-       [m4_if([$2], [], [], [[$1$2]])$0([$1], m4_shift(m4_shift($@)))])])
-
-
-# lt_car(LIST)
-# lt_cdr(LIST)
-# ------------
-# Manipulate m4 lists.
-# These macros are necessary as long as will still need to support
-# Autoconf-2.59 which quotes differently.
-m4_define([lt_car], [[$1]])
-m4_define([lt_cdr],
-[m4_if([$#], 0, [m4_fatal([$0: cannot be called without arguments])],
-       [$#], 1, [],
-       [m4_dquote(m4_shift($@))])])
-m4_define([lt_unquote], $1)
-
-
-# lt_append(MACRO-NAME, STRING, [SEPARATOR])
-# ------------------------------------------
-# Redefine MACRO-NAME to hold its former content plus `SEPARATOR'`STRING'.
-# Note that neither SEPARATOR nor STRING are expanded; they are appended
-# to MACRO-NAME as is (leaving the expansion for when MACRO-NAME is invoked).
-# No SEPARATOR is output if MACRO-NAME was previously undefined (different
-# than defined and empty).
-#
-# This macro is needed until we can rely on Autoconf 2.62, since earlier
-# versions of m4sugar mistakenly expanded SEPARATOR but not STRING.
-m4_define([lt_append],
-[m4_define([$1],
-          m4_ifdef([$1], [m4_defn([$1])[$3]])[$2])])
-
-
-
-# lt_combine(SEP, PREFIX-LIST, INFIX, SUFFIX1, [SUFFIX2...])
-# ----------------------------------------------------------
-# Produce a SEP delimited list of all paired combinations of elements of
-# PREFIX-LIST with SUFFIX1 through SUFFIXn.  Each element of the list
-# has the form PREFIXmINFIXSUFFIXn.
-# Needed until we can rely on m4_combine added in Autoconf 2.62.
-m4_define([lt_combine],
-[m4_if(m4_eval([$# > 3]), [1],
-       [m4_pushdef([_Lt_sep], [m4_define([_Lt_sep], m4_defn([lt_car]))])]]dnl
-[[m4_foreach([_Lt_prefix], [$2],
-            [m4_foreach([_Lt_suffix],
-               ]m4_dquote(m4_dquote(m4_shift(m4_shift(m4_shift($@)))))[,
-       [_Lt_sep([$1])[]m4_defn([_Lt_prefix])[$3]m4_defn([_Lt_suffix])])])])])
-
-
-# lt_if_append_uniq(MACRO-NAME, VARNAME, [SEPARATOR], [UNIQ], [NOT-UNIQ])
-# -----------------------------------------------------------------------
-# Iff MACRO-NAME does not yet contain VARNAME, then append it (delimited
-# by SEPARATOR if supplied) and expand UNIQ, else NOT-UNIQ.
-m4_define([lt_if_append_uniq],
-[m4_ifdef([$1],
-         [m4_if(m4_index([$3]m4_defn([$1])[$3], [$3$2$3]), [-1],
-                [lt_append([$1], [$2], [$3])$4],
-                [$5])],
-         [lt_append([$1], [$2], [$3])$4])])
-
-
-# lt_dict_add(DICT, KEY, VALUE)
-# -----------------------------
-m4_define([lt_dict_add],
-[m4_define([$1($2)], [$3])])
-
-
-# lt_dict_add_subkey(DICT, KEY, SUBKEY, VALUE)
-# --------------------------------------------
-m4_define([lt_dict_add_subkey],
-[m4_define([$1($2:$3)], [$4])])
-
-
-# lt_dict_fetch(DICT, KEY, [SUBKEY])
-# ----------------------------------
-m4_define([lt_dict_fetch],
-[m4_ifval([$3],
-       m4_ifdef([$1($2:$3)], [m4_defn([$1($2:$3)])]),
-    m4_ifdef([$1($2)], [m4_defn([$1($2)])]))])
-
-
-# lt_if_dict_fetch(DICT, KEY, [SUBKEY], VALUE, IF-TRUE, [IF-FALSE])
-# -----------------------------------------------------------------
-m4_define([lt_if_dict_fetch],
-[m4_if(lt_dict_fetch([$1], [$2], [$3]), [$4],
-       [$5],
-    [$6])])
-
-
-# lt_dict_filter(DICT, [SUBKEY], VALUE, [SEPARATOR], KEY, [...])
-# --------------------------------------------------------------
-m4_define([lt_dict_filter],
-[m4_if([$5], [], [],
-  [lt_join(m4_quote(m4_default([$4], [[, ]])),
-           lt_unquote(m4_split(m4_normalize(m4_foreach(_Lt_key, lt_car([m4_shiftn(4, $@)]),
-                     [lt_if_dict_fetch([$1], _Lt_key, [$2], [$3], [_Lt_key ])])))))])[]dnl
-])
diff --git a/m4/ltversion.m4 b/m4/ltversion.m4
deleted file mode 100644 (file)
index f3c5309..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-# ltversion.m4 -- version numbers                      -*- Autoconf -*-
-#
-#   Copyright (C) 2004 Free Software Foundation, Inc.
-#   Written by Scott James Remnant, 2004
-#
-# This file is free software; the Free Software Foundation gives
-# unlimited permission to copy and/or distribute it, with or without
-# modifications, as long as this notice is preserved.
-
-# Generated from ltversion.in.
-
-# serial 3017 ltversion.m4
-# This file is part of GNU Libtool
-
-m4_define([LT_PACKAGE_VERSION], [2.2.6b])
-m4_define([LT_PACKAGE_REVISION], [1.3017])
-
-AC_DEFUN([LTVERSION_VERSION],
-[macro_version='2.2.6b'
-macro_revision='1.3017'
-_LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?])
-_LT_DECL(, macro_revision, 0)
-])
diff --git a/m4/lt~obsolete.m4 b/m4/lt~obsolete.m4
deleted file mode 100644 (file)
index 637bb20..0000000
+++ /dev/null
@@ -1,92 +0,0 @@
-# lt~obsolete.m4 -- aclocal satisfying obsolete definitions.    -*-Autoconf-*-
-#
-#   Copyright (C) 2004, 2005, 2007 Free Software Foundation, Inc.
-#   Written by Scott James Remnant, 2004.
-#
-# This file is free software; the Free Software Foundation gives
-# unlimited permission to copy and/or distribute it, with or without
-# modifications, as long as this notice is preserved.
-
-# serial 4 lt~obsolete.m4
-
-# These exist entirely to fool aclocal when bootstrapping libtool.
-#
-# In the past libtool.m4 has provided macros via AC_DEFUN (or AU_DEFUN)
-# which have later been changed to m4_define as they aren't part of the
-# exported API, or moved to Autoconf or Automake where they belong.
-#
-# The trouble is, aclocal is a bit thick.  It'll see the old AC_DEFUN
-# in /usr/share/aclocal/libtool.m4 and remember it, then when it sees us
-# using a macro with the same name in our local m4/libtool.m4 it'll
-# pull the old libtool.m4 in (it doesn't see our shiny new m4_define
-# and doesn't know about Autoconf macros at all.)
-#
-# So we provide this file, which has a silly filename so it's always
-# included after everything else.  This provides aclocal with the
-# AC_DEFUNs it wants, but when m4 processes it, it doesn't do anything
-# because those macros already exist, or will be overwritten later.
-# We use AC_DEFUN over AU_DEFUN for compatibility with aclocal-1.6. 
-#
-# Anytime we withdraw an AC_DEFUN or AU_DEFUN, remember to add it here.
-# Yes, that means every name once taken will need to remain here until
-# we give up compatibility with versions before 1.7, at which point
-# we need to keep only those names which we still refer to.
-
-# This is to help aclocal find these macros, as it can't see m4_define.
-AC_DEFUN([LTOBSOLETE_VERSION], [m4_if([1])])
-
-m4_ifndef([AC_LIBTOOL_LINKER_OPTION],  [AC_DEFUN([AC_LIBTOOL_LINKER_OPTION])])
-m4_ifndef([AC_PROG_EGREP],             [AC_DEFUN([AC_PROG_EGREP])])
-m4_ifndef([_LT_AC_PROG_ECHO_BACKSLASH],        [AC_DEFUN([_LT_AC_PROG_ECHO_BACKSLASH])])
-m4_ifndef([_LT_AC_SHELL_INIT],         [AC_DEFUN([_LT_AC_SHELL_INIT])])
-m4_ifndef([_LT_AC_SYS_LIBPATH_AIX],    [AC_DEFUN([_LT_AC_SYS_LIBPATH_AIX])])
-m4_ifndef([_LT_PROG_LTMAIN],           [AC_DEFUN([_LT_PROG_LTMAIN])])
-m4_ifndef([_LT_AC_TAGVAR],             [AC_DEFUN([_LT_AC_TAGVAR])])
-m4_ifndef([AC_LTDL_ENABLE_INSTALL],    [AC_DEFUN([AC_LTDL_ENABLE_INSTALL])])
-m4_ifndef([AC_LTDL_PREOPEN],           [AC_DEFUN([AC_LTDL_PREOPEN])])
-m4_ifndef([_LT_AC_SYS_COMPILER],       [AC_DEFUN([_LT_AC_SYS_COMPILER])])
-m4_ifndef([_LT_AC_LOCK],               [AC_DEFUN([_LT_AC_LOCK])])
-m4_ifndef([AC_LIBTOOL_SYS_OLD_ARCHIVE],        [AC_DEFUN([AC_LIBTOOL_SYS_OLD_ARCHIVE])])
-m4_ifndef([_LT_AC_TRY_DLOPEN_SELF],    [AC_DEFUN([_LT_AC_TRY_DLOPEN_SELF])])
-m4_ifndef([AC_LIBTOOL_PROG_CC_C_O],    [AC_DEFUN([AC_LIBTOOL_PROG_CC_C_O])])
-m4_ifndef([AC_LIBTOOL_SYS_HARD_LINK_LOCKS], [AC_DEFUN([AC_LIBTOOL_SYS_HARD_LINK_LOCKS])])
-m4_ifndef([AC_LIBTOOL_OBJDIR],         [AC_DEFUN([AC_LIBTOOL_OBJDIR])])
-m4_ifndef([AC_LTDL_OBJDIR],            [AC_DEFUN([AC_LTDL_OBJDIR])])
-m4_ifndef([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH], [AC_DEFUN([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH])])
-m4_ifndef([AC_LIBTOOL_SYS_LIB_STRIP],  [AC_DEFUN([AC_LIBTOOL_SYS_LIB_STRIP])])
-m4_ifndef([AC_PATH_MAGIC],             [AC_DEFUN([AC_PATH_MAGIC])])
-m4_ifndef([AC_PROG_LD_GNU],            [AC_DEFUN([AC_PROG_LD_GNU])])
-m4_ifndef([AC_PROG_LD_RELOAD_FLAG],    [AC_DEFUN([AC_PROG_LD_RELOAD_FLAG])])
-m4_ifndef([AC_DEPLIBS_CHECK_METHOD],   [AC_DEFUN([AC_DEPLIBS_CHECK_METHOD])])
-m4_ifndef([AC_LIBTOOL_PROG_COMPILER_NO_RTTI], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_NO_RTTI])])
-m4_ifndef([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE], [AC_DEFUN([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE])])
-m4_ifndef([AC_LIBTOOL_PROG_COMPILER_PIC], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_PIC])])
-m4_ifndef([AC_LIBTOOL_PROG_LD_SHLIBS], [AC_DEFUN([AC_LIBTOOL_PROG_LD_SHLIBS])])
-m4_ifndef([AC_LIBTOOL_POSTDEP_PREDEP], [AC_DEFUN([AC_LIBTOOL_POSTDEP_PREDEP])])
-m4_ifndef([LT_AC_PROG_EGREP],          [AC_DEFUN([LT_AC_PROG_EGREP])])
-m4_ifndef([LT_AC_PROG_SED],            [AC_DEFUN([LT_AC_PROG_SED])])
-m4_ifndef([_LT_CC_BASENAME],           [AC_DEFUN([_LT_CC_BASENAME])])
-m4_ifndef([_LT_COMPILER_BOILERPLATE],  [AC_DEFUN([_LT_COMPILER_BOILERPLATE])])
-m4_ifndef([_LT_LINKER_BOILERPLATE],    [AC_DEFUN([_LT_LINKER_BOILERPLATE])])
-m4_ifndef([_AC_PROG_LIBTOOL],          [AC_DEFUN([_AC_PROG_LIBTOOL])])
-m4_ifndef([AC_LIBTOOL_SETUP],          [AC_DEFUN([AC_LIBTOOL_SETUP])])
-m4_ifndef([_LT_AC_CHECK_DLFCN],                [AC_DEFUN([_LT_AC_CHECK_DLFCN])])
-m4_ifndef([AC_LIBTOOL_SYS_DYNAMIC_LINKER],     [AC_DEFUN([AC_LIBTOOL_SYS_DYNAMIC_LINKER])])
-m4_ifndef([_LT_AC_TAGCONFIG],          [AC_DEFUN([_LT_AC_TAGCONFIG])])
-m4_ifndef([AC_DISABLE_FAST_INSTALL],   [AC_DEFUN([AC_DISABLE_FAST_INSTALL])])
-m4_ifndef([_LT_AC_LANG_CXX],           [AC_DEFUN([_LT_AC_LANG_CXX])])
-m4_ifndef([_LT_AC_LANG_F77],           [AC_DEFUN([_LT_AC_LANG_F77])])
-m4_ifndef([_LT_AC_LANG_GCJ],           [AC_DEFUN([_LT_AC_LANG_GCJ])])
-m4_ifndef([AC_LIBTOOL_RC],             [AC_DEFUN([AC_LIBTOOL_RC])])
-m4_ifndef([AC_LIBTOOL_LANG_C_CONFIG],  [AC_DEFUN([AC_LIBTOOL_LANG_C_CONFIG])])
-m4_ifndef([_LT_AC_LANG_C_CONFIG],      [AC_DEFUN([_LT_AC_LANG_C_CONFIG])])
-m4_ifndef([AC_LIBTOOL_LANG_CXX_CONFIG],        [AC_DEFUN([AC_LIBTOOL_LANG_CXX_CONFIG])])
-m4_ifndef([_LT_AC_LANG_CXX_CONFIG],    [AC_DEFUN([_LT_AC_LANG_CXX_CONFIG])])
-m4_ifndef([AC_LIBTOOL_LANG_F77_CONFIG],        [AC_DEFUN([AC_LIBTOOL_LANG_F77_CONFIG])])
-m4_ifndef([_LT_AC_LANG_F77_CONFIG],    [AC_DEFUN([_LT_AC_LANG_F77_CONFIG])])
-m4_ifndef([AC_LIBTOOL_LANG_GCJ_CONFIG],        [AC_DEFUN([AC_LIBTOOL_LANG_GCJ_CONFIG])])
-m4_ifndef([_LT_AC_LANG_GCJ_CONFIG],    [AC_DEFUN([_LT_AC_LANG_GCJ_CONFIG])])
-m4_ifndef([AC_LIBTOOL_LANG_RC_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_RC_CONFIG])])
-m4_ifndef([_LT_AC_LANG_RC_CONFIG],     [AC_DEFUN([_LT_AC_LANG_RC_CONFIG])])
-m4_ifndef([AC_LIBTOOL_CONFIG],         [AC_DEFUN([AC_LIBTOOL_CONFIG])])
-m4_ifndef([_LT_AC_FILE_LTDLL_C],       [AC_DEFUN([_LT_AC_FILE_LTDLL_C])])
index fc64b47..98f0bd4 100644 (file)
@@ -1,9 +1,9 @@
-# Makefile.in generated by automake 1.11.1 from Makefile.am.
+# Makefile.in generated by automake 1.11.6 from Makefile.am.
 # @configure_input@
 
 # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-# 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
-# Inc.
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
+# Foundation, Inc.
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
 # 
 
 VPATH = @srcdir@
+am__make_dryrun = \
+  { \
+    am__dry=no; \
+    case $$MAKEFLAGS in \
+      *\\[\ \  ]*) \
+        echo 'am--echo: ; @echo "AM"  OK' | $(MAKE) -f - 2>/dev/null \
+          | grep '^AM OK$$' >/dev/null || am__dry=yes;; \
+      *) \
+        for am__flg in $$MAKEFLAGS; do \
+          case $$am__flg in \
+            *=*|--*) ;; \
+            *n*) am__dry=yes; break;; \
+          esac; \
+        done;; \
+    esac; \
+    test $$am__dry = yes; \
+  }
 pkgdatadir = $(datadir)/@PACKAGE@
 pkgincludedir = $(includedir)/@PACKAGE@
 pkglibdir = $(libdir)/@PACKAGE@
@@ -60,24 +77,26 @@ host_triplet = @host@
 subdir = man
 DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
-       $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
-       $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
-       $(top_srcdir)/configure.ac
+am__aclocal_m4_deps = $(top_srcdir)/configure.ac
 am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
        $(ACLOCAL_M4)
 mkinstalldirs = $(install_sh) -d
 CONFIG_HEADER = $(top_builddir)/config.h
 CONFIG_CLEAN_FILES =
 CONFIG_CLEAN_VPATH_FILES =
-AM_V_GEN = $(am__v_GEN_$(V))
-am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY))
+AM_V_GEN = $(am__v_GEN_@AM_V@)
+am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
 am__v_GEN_0 = @echo "  GEN   " $@;
-AM_V_at = $(am__v_at_$(V))
-am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY))
+AM_V_at = $(am__v_at_@AM_V@)
+am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
 am__v_at_0 = @
 SOURCES =
 DIST_SOURCES =
+am__can_run_installinfo = \
+  case $$AM_UPDATE_INFO_DIR in \
+    n|no|NO) false;; \
+    *) (install-info --version) >/dev/null 2>&1;; \
+  esac
 am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
 am__vpath_adj = case $$p in \
     $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
@@ -99,6 +118,12 @@ am__nobase_list = $(am__nobase_strip_setup); \
 am__base_list = \
   sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
   sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
+am__uninstall_files_from_dir = { \
+  test -z "$$files" \
+    || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \
+    || { echo " ( cd '$$dir' && rm -f" $$files ")"; \
+         $(am__cd) "$$dir" && rm -f $$files; }; \
+  }
 am__installdirs = "$(DESTDIR)$(drivermandir)"
 DATA = $(driverman_DATA)
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
@@ -114,6 +139,7 @@ AUTOCONF = @AUTOCONF@
 AUTOHEADER = @AUTOHEADER@
 AUTOMAKE = @AUTOMAKE@
 AWK = @AWK@
+BASE_CFLAGS = @BASE_CFLAGS@
 CC = @CC@
 CCDEPMODE = @CCDEPMODE@
 CFLAGS = @CFLAGS@
@@ -124,11 +150,16 @@ CWARNFLAGS = @CWARNFLAGS@
 CYGPATH_W = @CYGPATH_W@
 DEFS = @DEFS@
 DEPDIR = @DEPDIR@
+DLLTOOL = @DLLTOOL@
+DRI2_CFLAGS = @DRI2_CFLAGS@
+DRI2_LIBS = @DRI2_LIBS@
 DRIVER_MAN_DIR = @DRIVER_MAN_DIR@
 DRIVER_MAN_SUFFIX = @DRIVER_MAN_SUFFIX@
 DRIVER_NAME = @DRIVER_NAME@
 DRI_CFLAGS = @DRI_CFLAGS@
 DRI_LIBS = @DRI_LIBS@
+DRMINTEL_CFLAGS = @DRMINTEL_CFLAGS@
+DRMINTEL_LIBS = @DRMINTEL_LIBS@
 DRM_CFLAGS = @DRM_CFLAGS@
 DRM_LIBS = @DRM_LIBS@
 DSYMUTIL = @DSYMUTIL@
@@ -152,6 +183,10 @@ INSTALL_SCRIPT = @INSTALL_SCRIPT@
 INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
 LD = @LD@
 LDFLAGS = @LDFLAGS@
+LIBGLAMOR_CFLAGS = @LIBGLAMOR_CFLAGS@
+LIBGLAMOR_EGL_CFLAGS = @LIBGLAMOR_EGL_CFLAGS@
+LIBGLAMOR_EGL_LIBS = @LIBGLAMOR_EGL_LIBS@
+LIBGLAMOR_LIBS = @LIBGLAMOR_LIBS@
 LIBOBJS = @LIBOBJS@
 LIBS = @LIBS@
 LIBTOOL = @LIBTOOL@
@@ -162,6 +197,7 @@ LN_S = @LN_S@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MANIFEST_TOOL = @MANIFEST_TOOL@
 MAN_SUBSTS = @MAN_SUBSTS@
 MISC_MAN_DIR = @MISC_MAN_DIR@
 MISC_MAN_SUFFIX = @MISC_MAN_SUFFIX@
@@ -189,10 +225,15 @@ RANLIB = @RANLIB@
 SED = @SED@
 SET_MAKE = @SET_MAKE@
 SHELL = @SHELL@
+STRICT_CFLAGS = @STRICT_CFLAGS@
 STRIP = @STRIP@
 UDEV_CFLAGS = @UDEV_CFLAGS@
 UDEV_LIBS = @UDEV_LIBS@
+VALGRIND_CFLAGS = @VALGRIND_CFLAGS@
+VALGRIND_LIBS = @VALGRIND_LIBS@
 VERSION = @VERSION@
+X11_CFLAGS = @X11_CFLAGS@
+X11_LIBS = @X11_LIBS@
 XORG_CFLAGS = @XORG_CFLAGS@
 XORG_LIBS = @XORG_LIBS@
 XORG_MAN_PAGE = @XORG_MAN_PAGE@
@@ -202,6 +243,7 @@ abs_builddir = @abs_builddir@
 abs_srcdir = @abs_srcdir@
 abs_top_builddir = @abs_top_builddir@
 abs_top_srcdir = @abs_top_srcdir@
+ac_ct_AR = @ac_ct_AR@
 ac_ct_CC = @ac_ct_CC@
 ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
 am__include = @am__include@
@@ -234,7 +276,6 @@ libdir = @libdir@
 libexecdir = @libexecdir@
 localedir = @localedir@
 localstatedir = @localstatedir@
-lt_ECHO = @lt_ECHO@
 mandir = @mandir@
 mkdir_p = @mkdir_p@
 moduledir = @moduledir@
@@ -300,8 +341,11 @@ clean-libtool:
        -rm -rf .libs _libs
 install-drivermanDATA: $(driverman_DATA)
        @$(NORMAL_INSTALL)
-       test -z "$(drivermandir)" || $(MKDIR_P) "$(DESTDIR)$(drivermandir)"
        @list='$(driverman_DATA)'; test -n "$(drivermandir)" || list=; \
+       if test -n "$$list"; then \
+         echo " $(MKDIR_P) '$(DESTDIR)$(drivermandir)'"; \
+         $(MKDIR_P) "$(DESTDIR)$(drivermandir)" || exit 1; \
+       fi; \
        for p in $$list; do \
          if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
          echo "$$d$$p"; \
@@ -315,9 +359,7 @@ uninstall-drivermanDATA:
        @$(NORMAL_UNINSTALL)
        @list='$(driverman_DATA)'; test -n "$(drivermandir)" || list=; \
        files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
-       test -n "$$files" || exit 0; \
-       echo " ( cd '$(DESTDIR)$(drivermandir)' && rm -f" $$files ")"; \
-       cd "$(DESTDIR)$(drivermandir)" && rm -f $$files
+       dir='$(DESTDIR)$(drivermandir)'; $(am__uninstall_files_from_dir)
 tags: TAGS
 TAGS:
 
@@ -372,10 +414,15 @@ install-am: all-am
 
 installcheck: installcheck-am
 install-strip:
-       $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
-         install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
-         `test -z '$(STRIP)' || \
-           echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+       if test -z '$(STRIP)'; then \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+             install; \
+       else \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+           "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+       fi
 mostlyclean-generic:
 
 clean-generic:
index 85e2b2e..0942dc1 100644 (file)
@@ -132,6 +132,14 @@ have options for selecting adaptors.
 .IP
 Default: Textured video adaptor is preferred.
 .TP
+.BI "Option \*qBacklight\*q \*q" string \*q
+Override the probed backlight control interface. Sometimes the automatically
+selected backlight interface may not correspond to the correct, or simply
+most useful, interface available on the system. This allows you to override
+that choice by specifying the entry under /sys/class/backlight to use.
+.IP
+Default: Automatic selection.
+.TP
 .BI "Option \*qFallbackDebug\*q \*q" boolean \*q
 Enable printing of debugging information on acceleration fallbacks to the
 server log.
@@ -156,19 +164,6 @@ i.e. perform synchronous rendering.
 .IP
 Default: Disabled
 .TP
-.BI "Option \*qShadow\*q \*q" boolean \*q
-This option controls the use of GPU acceleration and placement of auxiliary
-buffers in memory. Enabling the Shadow will disable all use of the GPU for
-RENDER acceleration and force software-fallbacks for all but updating the
-scan-out buffer. Hardware overlay is still supported so Xv will continue to
-playback videos using the GPU, but GL will be forced to use software
-rasterisation as well.  This is a last resort measure for systems with
-crippling bugs, such as early 8xx chipsets. It is still hoped that we will
-find a workaround to enable as much hardware acceleration on those
-architectures as is possible, but until then, using a shadow buffer should
-maintain system stability.
-.IP
-Default: Disabled
 .TP
 .BI "Option \*qSwapbuffersWait\*q \*q" boolean \*q
 This option controls the behavior of glXSwapBuffers and glXCopySubBufferMESA
@@ -180,6 +175,17 @@ the framerate of applications that render frames at less than refresh rate.
 .IP
 Default: enabled.
 .TP
+.BI "Option \*qTripleBuffer\*q \*q" boolean \*q
+This option enables the use of a third buffer for page-flipping. The third
+buffer allows applications to run at vrefresh rates even if they occasionally
+fail to swapbuffers on time. The effect of such missed swaps is the output
+jitters between 60fps and 30fps, and in the worst case appears frame-locked
+to 30fps. The disadvantage of triple buffering is that there is an extra
+frame of latency, due to the pre-rendered frame sitting in the swap queue,
+between input and any display update.
+.IP
+Default: enabled.
+.TP
 .BI "Option \*qTiling\*q \*q" boolean \*q
 This option controls whether memory buffers for Pixmaps are allocated in tiled mode.  In
 most cases (especially for complex rendering), tiling dramatically improves
@@ -210,11 +216,30 @@ User should provide absolute path to libIntelXvMC.so in XvMCConfig file.
 .IP
 Default: Disabled.
 .TP
+.BI "Option \*qThrottle\*q \*q" boolean \*q
+This option controls whether the driver periodically waits for pending
+drawing operations to complete. Throttling ensures that the GPU does not
+lag too far behind the CPU and thus noticeable delays in user responsible at
+the cost of throughput performance.
+.IP
+Default: enabled.
+.TP
 .BI "Option \*qHotPlug\*q \*q" boolean \*q
 This option controls whether the driver automatically notifies
 applications when monitors are connected or disconnected.
 .IP
 Default: enabled.
+.TP
+.BI "Option \*qZaphodHeads\*q \*q" string \*q
+.IP
+Specify the randr output(s) to use with zaphod mode for a particular driver
+instance.  If you this option you must use it with all instances of the
+driver
+.br
+For example:
+.B
+Option \*qZaphodHeads\*q \*qLVDS1,VGA1\*q
+will assign xrandr outputs LVDS1 and VGA0 to this instance of the driver.
 
 .SH OUTPUT CONFIGURATION
 On 830M and better chipsets, the driver supports runtime configuration of
@@ -240,80 +265,73 @@ VGA output port (typically exposed via an HD15 connector).
 .SS "LVDS"
 Low Voltage Differential Signalling output (typically a laptop LCD panel).  Available properties:
 
-.PP
-.B BACKLIGHT
-- current backlight level (adjustable)
-.TP 2
-By adjusting the BACKLIGHT property, the brightness on the LVDS output can be adjusted.  In some cases, this property may be unavailable (for example if your platform uses an external microcontroller to control the backlight).
-
-.PP
-.B scaling mode
-- control LCD panel scaling mode
-.TP 2
-When the currently selected display mode differs from the native panel resolution, various scaling options are available. These include
+.TP
+\fBBACKLIGHT\fB - current backlight level (adjustable)
+By adjusting the BACKLIGHT property, the brightness on the LVDS output
+can be adjusted.  In some cases, this property may be unavailable (for
+example if your platform uses an external microcontroller to control
+the backlight).
+.TP
+\fBscaling mode\fP - control LCD panel scaling mode
+When the currently selected display mode differs from the native panel
+resolution, various scaling options are available. These include
 .RS
-.PP
+.TP
 .B Center
-.TP 4
-Simply center the image on-screen without scaling. This is the only scaling mode that guarantees a one-to-one correspondence between native and displayed pixels, but some portions of the panel may be unused (so-called "letterboxing").
-.PP
+Simply center the image on-screen without scaling. This is the only
+scaling mode that guarantees a one-to-one correspondence between
+native and displayed pixels, but some portions of the panel may be
+unused (so-called "letterboxing").
+.TP
 .B Full aspect
-.TP 4
-Scale the image as much as possible while preserving aspect ratio. Pixels may not be displayed one-to-one (there may be some blurriness). Some portions of the panel may be unused if the aspect ratio of the selected mode does not match that of the panel.
-.PP
+Scale the image as much as possible while preserving aspect
+ratio. Pixels may not be displayed one-to-one (there may be some
+blurriness). Some portions of the panel may be unused if the aspect
+ratio of the selected mode does not match that of the panel.
+.TP
 .B Full
-.TP 4
-Scale the image to the panel size without regard to aspect ratio. This is the only mode which guarantees that every pixel of the panel will be used. But the displayed image may be distorted by stretching either horizontally or vertically, and pixels may not be displayed one-to-one (there may be some blurriness).
+Scale the image to the panel size without regard to aspect ratio. This
+is the only mode which guarantees that every pixel of the panel will
+be used. But the displayed image may be distorted by stretching either
+horizontally or vertically, and pixels may not be displayed one-to-one
+(there may be some blurriness).
 .RE
 
 The precise names of these options may differ depending on the kernel
-video driver, (but the functionality should be similar). See the output of
+video driver, (but the functionality should be similar). See the
+output of
 .B xrandr \-\-prop
 for a list of currently available scaling modes.
 .SS "TV"
 Integrated TV output.  Available properties include:
-
-.PP
-.B BOTTOM, RIGHT, TOP, LEFT
-- margins
-.TP 2
-Adjusting these properties allows you to control the placement of your TV output buffer on the screen. The options with the same name can also be set in xorg.conf with integer value.
-
-.PP
-.B BRIGHTNESS
-- TV brightness, range 0-255
-.TP 2
+.TP
+\fBBOTTOM, RIGHT, TOP, LEFT\fP - margins
+Adjusting these properties allows you to control the placement of your
+TV output buffer on the screen. The options with the same name can
+also be set in xorg.conf with integer value.
+.TP
+\fBBRIGHTNESS\fP - TV brightness, range 0-255
 Adjust TV brightness, default value is 128.
-
-.PP
-.B CONTRAST
-- TV contrast, range 0-255
-.TP 2
+.TP
+\fBCONTRAST\fP - TV contrast, range 0-255
 Adjust TV contrast, default value is 1.0 in chipset specific format.
-
-.PP
-.B SATURATION
-- TV saturation, range 0-255
-.TP 2
+.TP
+\fBSATURATION\fP - TV saturation, range 0-255
 Adjust TV saturation, default value is 1.0 in chipset specific format.
-
-.PP
-.B HUE
-- TV hue, range 0-255
-.TP 2
+.TP
+\fBHUE\fP - TV hue, range 0-255
 Adjust TV hue, default value is 0.
-
-.PP
-.B TV_FORMAT
-- output standard
-.TP 2
-This property allows you to control the output standard used on your TV output port.  You can select between NTSC-M, NTSC-443, NTSC-J, PAL-M, PAL-N, and PAL.
-
-.PP
-.B TV_Connector
-- connector type
-.TP 2
-This config option should be added to xorg.conf TV monitor's section, it allows you to force the TV output connector type, which bypass load detect and TV will always be taken as connected. You can select between S-Video, Composite and Component.
+.TP
+\fBTV_FORMAT\fP - output standard
+This property allows you to control the output standard used on your
+TV output port.  You can select between NTSC-M, NTSC-443, NTSC-J,
+PAL-M, PAL-N, and PAL.
+.TP
+\fBTV_Connector\fP - connector type
+This config option should be added to xorg.conf TV monitor's section,
+it allows you to force the TV output connector type, which bypass load
+detect and TV will always be taken as connected. You can select
+between S-Video, Composite and Component.
 
 .SS "TMDS-1"
 First DVI SDVO output
@@ -323,15 +341,15 @@ Second DVI SDVO output
 
 .SS "TMDS-1", "TMDS-2", "HDMI-1", "HDMI-2"
 DVI/HDMI outputs. Avaliable common properties include:
-.PP
-.B BROADCAST_RGB
-- method used to set RGB color range(full range 0-255, not full range 16-235)
-.TP 2
-Adjusting this propertie allows you to set RGB color range on each channel in order to match HDTV requirment(default 0 for full range). Setting 1 means RGB color range is 16-235, 0 means RGB color range is 0-255 on each channel.
+.TP
+\fBBROADCAST_RGB\fP - method used to set RGB color range
+Adjusting this property allows you to set RGB color range on each
+channel in order to match HDTV requirment(default 0 for full
+range). Setting 1 means RGB color range is 16-235, 0 means RGB color
+range is 0-255 on each channel.  (Full range is 0-255, not 16-235)
 
 .PP
 SDVO and DVO TV outputs are not supported by the driver at this time.
-
 .PP
 See __xconfigfile__(__filemansuffix__) for information on associating Monitor
 sections with these outputs for configuration.  Associating Monitor sections
diff --git a/packaging/0001-Don-t-config-fail-if-no-dri1-support.patch b/packaging/0001-Don-t-config-fail-if-no-dri1-support.patch
new file mode 100644 (file)
index 0000000..d4a2a17
--- /dev/null
@@ -0,0 +1,27 @@
+From 27f82af3f59e1303ec4f505ef88f96b4ad672ba1 Mon Sep 17 00:00:00 2001
+From: Li Peng <peng.li@intel.com>
+Date: Mon, 8 Oct 2012 18:56:53 +0800
+Subject: [PATCH] Don't config fail if no dri1 support
+
+---
+ configure.ac |    4 ----
+ 1 files changed, 0 insertions(+), 4 deletions(-)
+
+diff --git a/configure.ac b/configure.ac
+index c961d85..d332125 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -333,10 +333,6 @@ if test "x$DRI" != "xno"; then
+ else
+         DRI_CFLAGS=""
+         DRI_LIBS=""
+-
+-        if test "x$enable_dri" = "xyes"; then
+-                AC_MSG_ERROR([DRI requested but prerequisites not found])
+-        fi
+ fi
+ if test "x$DRI2" != "xno"; then
+-- 
+1.7.2.2
+
index fefa1ad..ae239ef 100644 (file)
@@ -1,6 +1,6 @@
 Name:       xorg-x11-drv-intel
 Summary:    Xorg X11 Intel video driver
-Version:    2.15.0
+Version:    2.20.9
 Release:    1
 Group:      System/X Hardware Support
 License:    MIT
@@ -8,13 +8,14 @@ URL:        http://www.x.org/
 Source0:    %{name}-%{version}.tar.bz2
 Source1001: packaging/xorg-x11-drv-intel.manifest 
 # >> gbp-patch-tags         # auto-added by gbp
-Patch0:     disable-page-flipping.patch
+Patch0:     0001-Don-t-config-fail-if-no-dri1-support.patch
 # << gbp-patch-tags         # auto-added by gbp
-Requires:   xorg-server
+Requires:   xorg-x11-server-Xorg
 Requires:   pciutils
 BuildRequires:  pkgconfig(xorg-server)
+BuildRequires:  pkgconfig(resourceproto)
 BuildRequires:  pkgconfig(libdrm)
-BuildRequires:  pkgconfig(xf86driproto)
+#BuildRequires:  pkgconfig(xf86driproto)
 BuildRequires:  pkgconfig(xvmc)
 BuildRequires:  pkgconfig(gl)
 BuildRequires:  pkgconfig(x11)
@@ -48,7 +49,7 @@ Xorg Intel video driver
 %build
 cp %{SOURCE1001} .
 CFLAGS="$CFLAGS -I/usr/include/X11"
-%configure --enable-dri \
+%reconfigure --enable-dri \
     --enable-kms-only
 
 make V=1 %{?jobs:-j%jobs}
index abb03c3..feed4ce 100644 (file)
@@ -26,30 +26,44 @@ SUBDIRS = xvmc render_program legacy
 # _ladir passes a dummy rpath to libtool so the thing will actually link
 # TODO: -nostdlib/-Bstatic/-lgcc platform magic, not installing the .a, etc.
 
-AM_CFLAGS = @CWARNFLAGS@ @XORG_CFLAGS@ @UDEV_CFLAGS@ @DRM_CFLAGS@ @DRI_CFLAGS@ \
-       @PCIACCESS_CFLAGS@ -I$(top_srcdir)/uxa -I$(top_srcdir)/src/render_program
+AM_CFLAGS = @CWARNFLAGS@ @XORG_CFLAGS@ @DRM_CFLAGS@ @PCIACCESS_CFLAGS@
 
 intel_drv_la_LTLIBRARIES = intel_drv.la
 intel_drv_la_LDFLAGS = -module -avoid-version
 intel_drv_ladir = @moduledir@/drivers
-intel_drv_la_LIBADD = @UDEV_LIBS@ -lm @DRM_LIBS@ -ldrm_intel ../uxa/libuxa.la legacy/liblegacy.la
-intel_drv_la_LIBADD += @PCIACCESS_LIBS@
+intel_drv_la_LIBADD = legacy/liblegacy.la @PCIACCESS_LIBS@
+
+if SNA
+SUBDIRS += sna
+intel_drv_la_LIBADD += sna/libsna.la
+endif
 
 NULL:=#
 
 intel_drv_la_SOURCES = \
+       intel_list.h \
+       intel_options.h \
+       intel_options.c \
+       intel_module.c \
+       compat-api.h \
+       $(NULL)
+
+if UXA
+AM_CFLAGS += @UDEV_CFLAGS@ @DRM_CFLAGS@ @DRMINTEL_CFLAGS@
+AM_CFLAGS += -I$(top_srcdir)/uxa -I$(top_srcdir)/src/render_program
+intel_drv_la_LIBADD += @UDEV_LIBS@ @DRMINTEL_LIBS@ @DRM_LIBS@ ../uxa/libuxa.la
+intel_drv_la_SOURCES += \
          brw_defines.h \
          brw_structs.h \
          common.h \
          intel.h \
-        intel_module.c \
          intel_batchbuffer.c \
          intel_batchbuffer.h \
         intel_display.c \
          intel_driver.c \
          intel_driver.h \
+        intel_glamor.h \
          intel_memory.c \
-        intel_shadow.c \
         intel_uxa.c \
          intel_video.c \
          intel_video.h \
@@ -62,11 +76,20 @@ intel_drv_la_SOURCES = \
         i915_render.c \
         i915_video.c \
         i965_reg.h \
+        i965_3d.c \
         i965_video.c \
         i965_render.c \
         $(NULL)
 
-if DRI
+if GLAMOR
+AM_CFLAGS += @LIBGLAMOR_CFLAGS@
+intel_drv_la_LIBADD += @LIBGLAMOR_LIBS@
+intel_drv_la_SOURCES += \
+        intel_glamor.c \
+        $(NULL)
+endif
+
+if DRI2
 intel_drv_la_SOURCES += \
        intel_dri.c \
        $(NULL)
@@ -81,3 +104,4 @@ intel_drv_la_SOURCES += \
        intel_hwmc.c \
        $(NULL)
 endif
+endif
index 76f5db7..529efea 100644 (file)
@@ -1,9 +1,9 @@
-# Makefile.in generated by automake 1.11.1 from Makefile.am.
+# Makefile.in generated by automake 1.11.6 from Makefile.am.
 # @configure_input@
 
 # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-# 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
-# Inc.
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
+# Foundation, Inc.
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
 #  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 VPATH = @srcdir@
+am__make_dryrun = \
+  { \
+    am__dry=no; \
+    case $$MAKEFLAGS in \
+      *\\[\ \  ]*) \
+        echo 'am--echo: ; @echo "AM"  OK' | $(MAKE) -f - 2>/dev/null \
+          | grep '^AM OK$$' >/dev/null || am__dry=yes;; \
+      *) \
+        for am__flg in $$MAKEFLAGS; do \
+          case $$am__flg in \
+            *=*|--*) ;; \
+            *n*) am__dry=yes; break;; \
+          esac; \
+        done;; \
+    esac; \
+    test $$am__dry = yes; \
+  }
 pkgdatadir = $(datadir)/@PACKAGE@
 pkgincludedir = $(includedir)/@PACKAGE@
 pkglibdir = $(libdir)/@PACKAGE@
@@ -54,26 +71,64 @@ PRE_UNINSTALL = :
 POST_UNINSTALL = :
 build_triplet = @build@
 host_triplet = @host@
-@DRI_TRUE@am__append_1 = \
-@DRI_TRUE@     intel_dri.c \
-@DRI_TRUE@     $(NULL)
-
-@DRI_TRUE@am__append_2 = \
-@DRI_TRUE@     $(DRI_LIBS) \
-@DRI_TRUE@     $(NULL)
-
-@XVMC_TRUE@am__append_3 = \
-@XVMC_TRUE@    intel_hwmc.h \
-@XVMC_TRUE@    intel_hwmc.c \
-@XVMC_TRUE@    $(NULL)
+@SNA_TRUE@am__append_1 = sna
+@SNA_TRUE@am__append_2 = sna/libsna.la
+@UXA_TRUE@am__append_3 = @UDEV_CFLAGS@ @DRM_CFLAGS@ @DRMINTEL_CFLAGS@ \
+@UXA_TRUE@     -I$(top_srcdir)/uxa \
+@UXA_TRUE@     -I$(top_srcdir)/src/render_program
+@UXA_TRUE@am__append_4 = @UDEV_LIBS@ @DRMINTEL_LIBS@ @DRM_LIBS@ ../uxa/libuxa.la
+@UXA_TRUE@am__append_5 = \
+@UXA_TRUE@         brw_defines.h \
+@UXA_TRUE@         brw_structs.h \
+@UXA_TRUE@         common.h \
+@UXA_TRUE@         intel.h \
+@UXA_TRUE@         intel_batchbuffer.c \
+@UXA_TRUE@         intel_batchbuffer.h \
+@UXA_TRUE@      intel_display.c \
+@UXA_TRUE@         intel_driver.c \
+@UXA_TRUE@         intel_driver.h \
+@UXA_TRUE@      intel_glamor.h \
+@UXA_TRUE@         intel_memory.c \
+@UXA_TRUE@      intel_uxa.c \
+@UXA_TRUE@         intel_video.c \
+@UXA_TRUE@         intel_video.h \
+@UXA_TRUE@      i830_3d.c \
+@UXA_TRUE@      i830_render.c \
+@UXA_TRUE@      i830_reg.h \
+@UXA_TRUE@      i915_3d.h \
+@UXA_TRUE@      i915_reg.h \
+@UXA_TRUE@      i915_3d.c \
+@UXA_TRUE@      i915_render.c \
+@UXA_TRUE@      i915_video.c \
+@UXA_TRUE@      i965_reg.h \
+@UXA_TRUE@      i965_3d.c \
+@UXA_TRUE@      i965_video.c \
+@UXA_TRUE@      i965_render.c \
+@UXA_TRUE@      $(NULL)
+
+@GLAMOR_TRUE@@UXA_TRUE@am__append_6 = @LIBGLAMOR_CFLAGS@
+@GLAMOR_TRUE@@UXA_TRUE@am__append_7 = @LIBGLAMOR_LIBS@
+@GLAMOR_TRUE@@UXA_TRUE@am__append_8 = \
+@GLAMOR_TRUE@@UXA_TRUE@         intel_glamor.c \
+@GLAMOR_TRUE@@UXA_TRUE@         $(NULL)
+
+@DRI2_TRUE@@UXA_TRUE@am__append_9 = \
+@DRI2_TRUE@@UXA_TRUE@  intel_dri.c \
+@DRI2_TRUE@@UXA_TRUE@  $(NULL)
+
+@DRI2_TRUE@@UXA_TRUE@am__append_10 = \
+@DRI2_TRUE@@UXA_TRUE@  $(DRI_LIBS) \
+@DRI2_TRUE@@UXA_TRUE@  $(NULL)
+
+@UXA_TRUE@@XVMC_TRUE@am__append_11 = \
+@UXA_TRUE@@XVMC_TRUE@  intel_hwmc.h \
+@UXA_TRUE@@XVMC_TRUE@  intel_hwmc.c \
+@UXA_TRUE@@XVMC_TRUE@  $(NULL)
 
 subdir = src
 DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
-       $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
-       $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
-       $(top_srcdir)/configure.ac
+am__aclocal_m4_deps = $(top_srcdir)/configure.ac
 am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
        $(ACLOCAL_M4)
 mkinstalldirs = $(install_sh) -d
@@ -101,38 +156,52 @@ am__nobase_list = $(am__nobase_strip_setup); \
 am__base_list = \
   sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
   sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
+am__uninstall_files_from_dir = { \
+  test -z "$$files" \
+    || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \
+    || { echo " ( cd '$$dir' && rm -f" $$files ")"; \
+         $(am__cd) "$$dir" && rm -f $$files; }; \
+  }
 am__installdirs = "$(DESTDIR)$(intel_drv_ladir)"
 LTLIBRARIES = $(intel_drv_la_LTLIBRARIES)
-am__DEPENDENCIES_1 =
-@DRI_TRUE@am__DEPENDENCIES_2 = $(am__DEPENDENCIES_1) \
-@DRI_TRUE@     $(am__DEPENDENCIES_1)
-intel_drv_la_DEPENDENCIES = ../uxa/libuxa.la legacy/liblegacy.la \
-       $(am__DEPENDENCIES_2)
-am__intel_drv_la_SOURCES_DIST = brw_defines.h brw_structs.h common.h \
-       intel.h intel_module.c intel_batchbuffer.c intel_batchbuffer.h \
-       intel_display.c intel_driver.c intel_driver.h intel_memory.c \
-       intel_shadow.c intel_uxa.c intel_video.c intel_video.h \
-       i830_3d.c i830_render.c i830_reg.h i915_3d.h i915_reg.h \
-       i915_3d.c i915_render.c i915_video.c i965_reg.h i965_video.c \
-       i965_render.c intel_dri.c intel_hwmc.h intel_hwmc.c
+@UXA_TRUE@am__DEPENDENCIES_1 = ../uxa/libuxa.la
+am__DEPENDENCIES_2 =
+@DRI2_TRUE@@UXA_TRUE@am__DEPENDENCIES_3 = $(am__DEPENDENCIES_2) \
+@DRI2_TRUE@@UXA_TRUE@  $(am__DEPENDENCIES_2)
+intel_drv_la_DEPENDENCIES = legacy/liblegacy.la $(am__append_2) \
+       $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2) \
+       $(am__DEPENDENCIES_3)
+am__intel_drv_la_SOURCES_DIST = intel_list.h intel_options.h \
+       intel_options.c intel_module.c compat-api.h brw_defines.h \
+       brw_structs.h common.h intel.h intel_batchbuffer.c \
+       intel_batchbuffer.h intel_display.c intel_driver.c \
+       intel_driver.h intel_glamor.h intel_memory.c intel_uxa.c \
+       intel_video.c intel_video.h i830_3d.c i830_render.c i830_reg.h \
+       i915_3d.h i915_reg.h i915_3d.c i915_render.c i915_video.c \
+       i965_reg.h i965_3d.c i965_video.c i965_render.c intel_glamor.c \
+       intel_dri.c intel_hwmc.h intel_hwmc.c
 am__objects_1 =
-@DRI_TRUE@am__objects_2 = intel_dri.lo $(am__objects_1)
-@XVMC_TRUE@am__objects_3 = intel_hwmc.lo $(am__objects_1)
-am_intel_drv_la_OBJECTS = intel_module.lo intel_batchbuffer.lo \
-       intel_display.lo intel_driver.lo intel_memory.lo \
-       intel_shadow.lo intel_uxa.lo intel_video.lo i830_3d.lo \
-       i830_render.lo i915_3d.lo i915_render.lo i915_video.lo \
-       i965_video.lo i965_render.lo $(am__objects_1) $(am__objects_2) \
-       $(am__objects_3)
+@UXA_TRUE@am__objects_2 = intel_batchbuffer.lo intel_display.lo \
+@UXA_TRUE@     intel_driver.lo intel_memory.lo intel_uxa.lo \
+@UXA_TRUE@     intel_video.lo i830_3d.lo i830_render.lo i915_3d.lo \
+@UXA_TRUE@     i915_render.lo i915_video.lo i965_3d.lo \
+@UXA_TRUE@     i965_video.lo i965_render.lo $(am__objects_1)
+@GLAMOR_TRUE@@UXA_TRUE@am__objects_3 = intel_glamor.lo \
+@GLAMOR_TRUE@@UXA_TRUE@        $(am__objects_1)
+@DRI2_TRUE@@UXA_TRUE@am__objects_4 = intel_dri.lo $(am__objects_1)
+@UXA_TRUE@@XVMC_TRUE@am__objects_5 = intel_hwmc.lo $(am__objects_1)
+am_intel_drv_la_OBJECTS = intel_options.lo intel_module.lo \
+       $(am__objects_1) $(am__objects_2) $(am__objects_3) \
+       $(am__objects_4) $(am__objects_5)
 intel_drv_la_OBJECTS = $(am_intel_drv_la_OBJECTS)
-AM_V_lt = $(am__v_lt_$(V))
-am__v_lt_ = $(am__v_lt_$(AM_DEFAULT_VERBOSITY))
+AM_V_lt = $(am__v_lt_@AM_V@)
+am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
 am__v_lt_0 = --silent
 intel_drv_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
        $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
        $(intel_drv_la_LDFLAGS) $(LDFLAGS) -o $@
 DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
-depcomp = $(SHELL) $(top_srcdir)/build-aux/depcomp
+depcomp = $(SHELL) $(top_srcdir)/depcomp
 am__depfiles_maybe = depfiles
 am__mv = mv -f
 COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
@@ -141,21 +210,21 @@ LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
        $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \
        $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
        $(AM_CFLAGS) $(CFLAGS)
-AM_V_CC = $(am__v_CC_$(V))
-am__v_CC_ = $(am__v_CC_$(AM_DEFAULT_VERBOSITY))
+AM_V_CC = $(am__v_CC_@AM_V@)
+am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@)
 am__v_CC_0 = @echo "  CC    " $@;
-AM_V_at = $(am__v_at_$(V))
-am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY))
+AM_V_at = $(am__v_at_@AM_V@)
+am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
 am__v_at_0 = @
 CCLD = $(CC)
 LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
        $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
        $(AM_LDFLAGS) $(LDFLAGS) -o $@
-AM_V_CCLD = $(am__v_CCLD_$(V))
-am__v_CCLD_ = $(am__v_CCLD_$(AM_DEFAULT_VERBOSITY))
+AM_V_CCLD = $(am__v_CCLD_@AM_V@)
+am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
 am__v_CCLD_0 = @echo "  CCLD  " $@;
-AM_V_GEN = $(am__v_GEN_$(V))
-am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY))
+AM_V_GEN = $(am__v_GEN_@AM_V@)
+am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
 am__v_GEN_0 = @echo "  GEN   " $@;
 SOURCES = $(intel_drv_la_SOURCES)
 DIST_SOURCES = $(am__intel_drv_la_SOURCES_DIST)
@@ -166,6 +235,11 @@ RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \
        install-pdf-recursive install-ps-recursive install-recursive \
        installcheck-recursive installdirs-recursive pdf-recursive \
        ps-recursive uninstall-recursive
+am__can_run_installinfo = \
+  case $$AM_UPDATE_INFO_DIR in \
+    n|no|NO) false;; \
+    *) (install-info --version) >/dev/null 2>&1;; \
+  esac
 RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive        \
   distclean-recursive maintainer-clean-recursive
 AM_RECURSIVE_TARGETS = $(RECURSIVE_TARGETS:-recursive=) \
@@ -173,7 +247,7 @@ AM_RECURSIVE_TARGETS = $(RECURSIVE_TARGETS:-recursive=) \
        distdir
 ETAGS = etags
 CTAGS = ctags
-DIST_SUBDIRS = $(SUBDIRS)
+DIST_SUBDIRS = xvmc render_program legacy sna
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
 am__relativize = \
   dir0=`pwd`; \
@@ -212,6 +286,7 @@ AUTOCONF = @AUTOCONF@
 AUTOHEADER = @AUTOHEADER@
 AUTOMAKE = @AUTOMAKE@
 AWK = @AWK@
+BASE_CFLAGS = @BASE_CFLAGS@
 CC = @CC@
 CCDEPMODE = @CCDEPMODE@
 CFLAGS = @CFLAGS@
@@ -222,11 +297,16 @@ CWARNFLAGS = @CWARNFLAGS@
 CYGPATH_W = @CYGPATH_W@
 DEFS = @DEFS@
 DEPDIR = @DEPDIR@
+DLLTOOL = @DLLTOOL@
+DRI2_CFLAGS = @DRI2_CFLAGS@
+DRI2_LIBS = @DRI2_LIBS@
 DRIVER_MAN_DIR = @DRIVER_MAN_DIR@
 DRIVER_MAN_SUFFIX = @DRIVER_MAN_SUFFIX@
 DRIVER_NAME = @DRIVER_NAME@
 DRI_CFLAGS = @DRI_CFLAGS@
 DRI_LIBS = @DRI_LIBS@
+DRMINTEL_CFLAGS = @DRMINTEL_CFLAGS@
+DRMINTEL_LIBS = @DRMINTEL_LIBS@
 DRM_CFLAGS = @DRM_CFLAGS@
 DRM_LIBS = @DRM_LIBS@
 DSYMUTIL = @DSYMUTIL@
@@ -250,6 +330,10 @@ INSTALL_SCRIPT = @INSTALL_SCRIPT@
 INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
 LD = @LD@
 LDFLAGS = @LDFLAGS@
+LIBGLAMOR_CFLAGS = @LIBGLAMOR_CFLAGS@
+LIBGLAMOR_EGL_CFLAGS = @LIBGLAMOR_EGL_CFLAGS@
+LIBGLAMOR_EGL_LIBS = @LIBGLAMOR_EGL_LIBS@
+LIBGLAMOR_LIBS = @LIBGLAMOR_LIBS@
 LIBOBJS = @LIBOBJS@
 LIBS = @LIBS@
 LIBTOOL = @LIBTOOL@
@@ -260,6 +344,7 @@ LN_S = @LN_S@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MANIFEST_TOOL = @MANIFEST_TOOL@
 MAN_SUBSTS = @MAN_SUBSTS@
 MISC_MAN_DIR = @MISC_MAN_DIR@
 MISC_MAN_SUFFIX = @MISC_MAN_SUFFIX@
@@ -287,10 +372,15 @@ RANLIB = @RANLIB@
 SED = @SED@
 SET_MAKE = @SET_MAKE@
 SHELL = @SHELL@
+STRICT_CFLAGS = @STRICT_CFLAGS@
 STRIP = @STRIP@
 UDEV_CFLAGS = @UDEV_CFLAGS@
 UDEV_LIBS = @UDEV_LIBS@
+VALGRIND_CFLAGS = @VALGRIND_CFLAGS@
+VALGRIND_LIBS = @VALGRIND_LIBS@
 VERSION = @VERSION@
+X11_CFLAGS = @X11_CFLAGS@
+X11_LIBS = @X11_LIBS@
 XORG_CFLAGS = @XORG_CFLAGS@
 XORG_LIBS = @XORG_LIBS@
 XORG_MAN_PAGE = @XORG_MAN_PAGE@
@@ -300,6 +390,7 @@ abs_builddir = @abs_builddir@
 abs_srcdir = @abs_srcdir@
 abs_top_builddir = @abs_top_builddir@
 abs_top_srcdir = @abs_top_srcdir@
+ac_ct_AR = @ac_ct_AR@
 ac_ct_CC = @ac_ct_CC@
 ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
 am__include = @am__include@
@@ -332,7 +423,6 @@ libdir = @libdir@
 libexecdir = @libexecdir@
 localedir = @localedir@
 localstatedir = @localstatedir@
-lt_ECHO = @lt_ECHO@
 mandir = @mandir@
 mkdir_p = @mkdir_p@
 moduledir = @moduledir@
@@ -349,30 +439,25 @@ target_alias = @target_alias@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
-SUBDIRS = xvmc render_program legacy
+SUBDIRS = xvmc render_program legacy $(am__append_1)
 
 # this is obnoxious:
 # -module lets us name the module exactly how we want
 # -avoid-version prevents gratuitous .0.0.0 version numbers on the end
 # _ladir passes a dummy rpath to libtool so the thing will actually link
 # TODO: -nostdlib/-Bstatic/-lgcc platform magic, not installing the .a, etc.
-AM_CFLAGS = @CWARNFLAGS@ @XORG_CFLAGS@ @UDEV_CFLAGS@ @DRM_CFLAGS@ @DRI_CFLAGS@ \
-       @PCIACCESS_CFLAGS@ -I$(top_srcdir)/uxa -I$(top_srcdir)/src/render_program
-
+AM_CFLAGS = @CWARNFLAGS@ @XORG_CFLAGS@ @DRM_CFLAGS@ @PCIACCESS_CFLAGS@ \
+       $(am__append_3) $(am__append_6)
 intel_drv_la_LTLIBRARIES = intel_drv.la
 intel_drv_la_LDFLAGS = -module -avoid-version
 intel_drv_ladir = @moduledir@/drivers
-intel_drv_la_LIBADD = @UDEV_LIBS@ -lm @DRM_LIBS@ -ldrm_intel \
-       ../uxa/libuxa.la legacy/liblegacy.la @PCIACCESS_LIBS@ \
-       $(am__append_2)
+intel_drv_la_LIBADD = legacy/liblegacy.la @PCIACCESS_LIBS@ \
+       $(am__append_2) $(am__append_4) $(am__append_7) \
+       $(am__append_10)
 NULL := #
-intel_drv_la_SOURCES = brw_defines.h brw_structs.h common.h intel.h \
-       intel_module.c intel_batchbuffer.c intel_batchbuffer.h \
-       intel_display.c intel_driver.c intel_driver.h intel_memory.c \
-       intel_shadow.c intel_uxa.c intel_video.c intel_video.h \
-       i830_3d.c i830_render.c i830_reg.h i915_3d.h i915_reg.h \
-       i915_3d.c i915_render.c i915_video.c i965_reg.h i965_video.c \
-       i965_render.c $(NULL) $(am__append_1) $(am__append_3)
+intel_drv_la_SOURCES = intel_list.h intel_options.h intel_options.c \
+       intel_module.c compat-api.h $(NULL) $(am__append_5) \
+       $(am__append_8) $(am__append_9) $(am__append_11)
 all: all-recursive
 
 .SUFFIXES:
@@ -409,7 +494,6 @@ $(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
 $(am__aclocal_m4_deps):
 install-intel_drv_laLTLIBRARIES: $(intel_drv_la_LTLIBRARIES)
        @$(NORMAL_INSTALL)
-       test -z "$(intel_drv_ladir)" || $(MKDIR_P) "$(DESTDIR)$(intel_drv_ladir)"
        @list='$(intel_drv_la_LTLIBRARIES)'; test -n "$(intel_drv_ladir)" || list=; \
        list2=; for p in $$list; do \
          if test -f $$p; then \
@@ -417,6 +501,8 @@ install-intel_drv_laLTLIBRARIES: $(intel_drv_la_LTLIBRARIES)
          else :; fi; \
        done; \
        test -z "$$list2" || { \
+         echo " $(MKDIR_P) '$(DESTDIR)$(intel_drv_ladir)'"; \
+         $(MKDIR_P) "$(DESTDIR)$(intel_drv_ladir)" || exit 1; \
          echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(intel_drv_ladir)'"; \
          $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(intel_drv_ladir)"; \
        }
@@ -438,7 +524,7 @@ clean-intel_drv_laLTLIBRARIES:
          echo "rm -f \"$${dir}/so_locations\""; \
          rm -f "$${dir}/so_locations"; \
        done
-intel_drv.la: $(intel_drv_la_OBJECTS) $(intel_drv_la_DEPENDENCIES) 
+intel_drv.la: $(intel_drv_la_OBJECTS) $(intel_drv_la_DEPENDENCIES) $(EXTRA_intel_drv_la_DEPENDENCIES) 
        $(AM_V_CCLD)$(intel_drv_la_LINK) -rpath $(intel_drv_ladir) $(intel_drv_la_OBJECTS) $(intel_drv_la_LIBADD) $(LIBS)
 
 mostlyclean-compile:
@@ -452,42 +538,41 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/i915_3d.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/i915_render.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/i915_video.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/i965_3d.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/i965_render.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/i965_video.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/intel_batchbuffer.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/intel_display.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/intel_dri.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/intel_driver.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/intel_glamor.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/intel_hwmc.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/intel_memory.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/intel_module.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/intel_shadow.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/intel_options.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/intel_uxa.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/intel_video.Plo@am__quote@
 
 .c.o:
 @am__fastdepCC_TRUE@   $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
 @am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
-@am__fastdepCC_FALSE@  $(AM_V_CC) @AM_BACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@  $(COMPILE) -c $<
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(COMPILE) -c $<
 
 .c.obj:
 @am__fastdepCC_TRUE@   $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
 @am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
-@am__fastdepCC_FALSE@  $(AM_V_CC) @AM_BACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@  $(COMPILE) -c `$(CYGPATH_W) '$<'`
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(COMPILE) -c `$(CYGPATH_W) '$<'`
 
 .c.lo:
 @am__fastdepCC_TRUE@   $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
 @am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
-@am__fastdepCC_FALSE@  $(AM_V_CC) @AM_BACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@  $(LTCOMPILE) -c -o $@ $<
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $<
 
 mostlyclean-libtool:
        -rm -f *.lo
@@ -662,13 +747,10 @@ distdir: $(DISTFILES)
        done
        @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
          if test "$$subdir" = .; then :; else \
-           test -d "$(distdir)/$$subdir" \
-           || $(MKDIR_P) "$(distdir)/$$subdir" \
-           || exit 1; \
-         fi; \
-       done
-       @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
-         if test "$$subdir" = .; then :; else \
+           $(am__make_dryrun) \
+             || test -d "$(distdir)/$$subdir" \
+             || $(MKDIR_P) "$(distdir)/$$subdir" \
+             || exit 1; \
            dir1=$$subdir; dir2="$(distdir)/$$subdir"; \
            $(am__relativize); \
            new_distdir=$$reldir; \
@@ -706,10 +788,15 @@ install-am: all-am
 
 installcheck: installcheck-recursive
 install-strip:
-       $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
-         install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
-         `test -z '$(STRIP)' || \
-           echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+       if test -z '$(STRIP)'; then \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+             install; \
+       else \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+           "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+       fi
 mostlyclean-generic:
 
 clean-generic:
index 0df2491..e580a8f 100644 (file)
 #define BRW_BORDER_COLOR_MODE_DEFAULT  0
 #define BRW_BORDER_COLOR_MODE_LEGACY   1
 
+#define HSW_SCS_ZERO                                   0
+#define HSW_SCS_ONE                                            1
+#define HSW_SCS_RED                                            4
+#define HSW_SCS_GREEN                                  5
+#define HSW_SCS_BLUE                                   6
+#define HSW_SCS_ALPHA                                  7
+
 #define BRW_TEXCOORDMODE_WRAP            0
 #define BRW_TEXCOORDMODE_MIRROR          1
 #define BRW_TEXCOORDMODE_CLAMP           2
index fa7b58b..20c2f85 100644 (file)
@@ -1592,4 +1592,132 @@ struct gen6_depth_stencil_state
        } ds2;
 };
 
+struct gen7_surface_state
+{
+       struct {
+               unsigned int cube_pos_z:1;
+               unsigned int cube_neg_z:1;
+               unsigned int cube_pos_y:1;
+               unsigned int cube_neg_y:1;
+               unsigned int cube_pos_x:1;
+               unsigned int cube_neg_x:1;
+               unsigned int pad2:2;
+               unsigned int render_cache_read_write:1;
+               unsigned int pad1:1;
+               unsigned int surface_array_spacing:1;
+               unsigned int vert_line_stride_ofs:1;
+               unsigned int vert_line_stride:1;
+               unsigned int tile_walk:1;
+               unsigned int tiled_surface:1;
+               unsigned int horizontal_alignment:1;
+               unsigned int vertical_alignment:2;
+               unsigned int surface_format:9;     /**< BRW_SURFACEFORMAT_x */
+               unsigned int pad0:1;
+               unsigned int is_array:1;
+               unsigned int surface_type:3;       /**< BRW_SURFACE_1D/2D/3D/CUBE */
+       } ss0;
+
+       struct {
+               unsigned int base_addr;
+       } ss1;
+
+       struct {
+               unsigned int width:14;
+               unsigned int pad1:2;
+               unsigned int height:14;
+               unsigned int pad0:2;
+       } ss2;
+
+       struct {
+               unsigned int pitch:18;
+               unsigned int pad:3;
+               unsigned int depth:11;
+       } ss3;
+
+       struct {
+               unsigned int multisample_position_palette_index:3;
+               unsigned int num_multisamples:3;
+               unsigned int multisampled_surface_storage_format:1;
+               unsigned int render_target_view_extent:11;
+               unsigned int min_array_elt:11;
+               unsigned int rotation:2;
+               unsigned int pad0:1;
+       } ss4;
+
+       struct {
+               unsigned int mip_count:4;
+               unsigned int min_lod:4;
+               unsigned int pad1:12;
+               unsigned int y_offset:4;
+               unsigned int pad0:1;
+               unsigned int x_offset:7;
+       } ss5;
+
+       struct {
+               unsigned int pad; /* Multisample Control Surface stuff */
+       } ss6;
+
+       struct {
+               unsigned int resource_min_lod:12;
+               unsigned int pad0:4;
+               unsigned int shader_chanel_select_a:3;
+               unsigned int shader_chanel_select_b:3;
+               unsigned int shader_chanel_select_g:3;
+               unsigned int shader_chanel_select_r:3;
+               unsigned int alpha_clear_color:1;
+               unsigned int blue_clear_color:1;
+               unsigned int green_clear_color:1;
+               unsigned int red_clear_color:1;
+       } ss7;
+};
+
+struct gen7_sampler_state
+{
+       struct
+       {
+               unsigned int aniso_algorithm:1;
+               unsigned int lod_bias:13;
+               unsigned int min_filter:3;
+               unsigned int mag_filter:3;
+               unsigned int mip_filter:2;
+               unsigned int base_level:5;
+               unsigned int pad1:1;
+               unsigned int lod_preclamp:1;
+               unsigned int default_color_mode:1;
+               unsigned int pad0:1;
+               unsigned int disable:1;
+       } ss0;
+
+       struct
+       {
+               unsigned int cube_control_mode:1;
+               unsigned int shadow_function:3;
+               unsigned int pad:4;
+               unsigned int max_lod:12;
+               unsigned int min_lod:12;
+       } ss1;
+
+       struct
+       {
+               unsigned int pad:5;
+               unsigned int default_color_pointer:27;
+       } ss2;
+
+       struct
+       {
+               unsigned int r_wrap_mode:3;
+               unsigned int t_wrap_mode:3;
+               unsigned int s_wrap_mode:3;
+               unsigned int pad:1;
+               unsigned int non_normalized_coord:1;
+               unsigned int trilinear_quality:2;
+               unsigned int address_round:6;
+               unsigned int max_aniso:3;
+               unsigned int chroma_key_mode:1;
+               unsigned int chroma_key_index:2;
+               unsigned int chroma_key_enable:1;
+               unsigned int pad0:6;
+       } ss3;
+};
+
 #endif
index 6f23cdd..86e5b11 100644 (file)
@@ -38,6 +38,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #ifndef _INTEL_COMMON_H_
 #define _INTEL_COMMON_H_
 
+#include <xf86.h>
+
 /* Provide substitutes for gcc's __FUNCTION__ on other compilers */
 #if !defined(__GNUC__) && !defined(__FUNCTION__)
 # if defined(__STDC__) && (__STDC_VERSION__>=199901L) /* C99 */
@@ -47,133 +49,13 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 # endif
 #endif
 
-
 #define PFX __FILE__,__LINE__,__FUNCTION__
 #define FUNCTION_NAME __FUNCTION__
 
-#ifdef I830DEBUG
-#define MARKER() ErrorF("\n### %s:%d: >>> %s <<< ###\n\n", \
-                        __FILE__, __LINE__,__FUNCTION__)
-#define DPRINTF I830DPRINTF
-#else /* #ifdef I830DEBUG */
-#define MARKER()
-#define DPRINTF I830DPRINTF_stub
-static inline void
-I830DPRINTF_stub(const char *filename, int line, const char *function,
-                const char *fmt, ...)
-{
-}
-#endif /* #ifdef I830DEBUG */
-
 #define KB(x) ((x) * 1024)
 #define MB(x) ((x) * KB(1024))
 
-/* Using usleep() makes things noticably slow. */
-#if 0
-#define DELAY(x) usleep(x)
-#else
-#define DELAY(x) do {;} while (0)
-#endif
-
-/* I830 hooks for the I810 driver setup/probe. */
-extern const OptionInfoRec *I830AvailableOptions(int chipid, int busid);
-extern void intel_init_scrn(ScrnInfoPtr scrn);
-
-/* Symbol lists shared by the i810 and i830 parts. */
-extern int I830EntityIndex;
-
-extern void I830DPRINTF_stub(const char *filename, int line,
-                            const char *function, const char *fmt, ...);
-
-#ifdef _I830_H_
-#define PrintErrorState i830_dump_error_state
-#define WaitRingFunc I830WaitLpRing
-#define RecPtr intel
-#else
-#define PrintErrorState I810PrintErrorState
-#define WaitRingFunc I810WaitLpRing
-#define RecPtr pI810
-#endif
-
-static inline void memset_volatile(volatile void *b, int c, size_t len)
-{
-    int i;
-    
-    for (i = 0; i < len; i++)
-       ((volatile char *)b)[i] = c;
-}
-
-static inline void memcpy_volatile(volatile void *dst, const void *src,
-                                  size_t len)
-{
-    int i;
-    
-    for (i = 0; i < len; i++)
-       ((volatile char *)dst)[i] = ((volatile char *)src)[i];
-}
-
-/* Memory mapped register access macros */
-#define INREG8(addr)        *(volatile uint8_t *)(RecPtr->MMIOBase + (addr))
-#define INREG16(addr)       *(volatile uint16_t *)(RecPtr->MMIOBase + (addr))
-#define INREG(addr)         *(volatile uint32_t *)(RecPtr->MMIOBase + (addr))
-#define INGTT(addr)         *(volatile uint32_t *)(RecPtr->GTTBase + (addr))
-#define POSTING_READ(addr)  (void)INREG(addr)
-
-#define OUTREG8(addr, val) do {                                                \
-   *(volatile uint8_t *)(RecPtr->MMIOBase  + (addr)) = (val);          \
-   if (I810_DEBUG&DEBUG_VERBOSE_OUTREG) {                              \
-      ErrorF("OUTREG8(0x%lx, 0x%lx) in %s\n", (unsigned long)(addr),   \
-               (unsigned long)(val), FUNCTION_NAME);                   \
-   }                                                                   \
-} while (0)
-
-#define OUTREG16(addr, val) do {                                       \
-   *(volatile uint16_t *)(RecPtr->MMIOBase + (addr)) = (val);          \
-   if (I810_DEBUG&DEBUG_VERBOSE_OUTREG) {                              \
-      ErrorF("OUTREG16(0x%lx, 0x%lx) in %s\n", (unsigned long)(addr),  \
-               (unsigned long)(val), FUNCTION_NAME);                   \
-   }                                                                   \
-} while (0)
-
-#define OUTREG(addr, val) do {                                         \
-   *(volatile uint32_t *)(RecPtr->MMIOBase + (addr)) = (val);          \
-   if (I810_DEBUG&DEBUG_VERBOSE_OUTREG) {                              \
-      ErrorF("OUTREG(0x%lx, 0x%lx) in %s\n", (unsigned long)(addr),    \
-               (unsigned long)(val), FUNCTION_NAME);                   \
-   }                                                                   \
-} while (0)
-
-
-#define DEBUG_VERBOSE_ACCEL  0x1
-#define DEBUG_VERBOSE_SYNC   0x2
-#define DEBUG_VERBOSE_VGA    0x4
-#define DEBUG_VERBOSE_RING   0x8
-#define DEBUG_VERBOSE_OUTREG 0x10
-#define DEBUG_VERBOSE_MEMORY 0x20
-#define DEBUG_VERBOSE_CURSOR 0x40
-#define DEBUG_ALWAYS_SYNC    0x80
-#define DEBUG_VERBOSE_DRI    0x100
-#define DEBUG_VERBOSE_BIOS   0x200
-
-/* Size of the mmio region.
- */
-#define I810_REG_SIZE 0x80000
-
-#define GTT_PAGE_SIZE                  KB(4)
-#define PRIMARY_RINGBUFFER_SIZE                KB(128)
-#define MIN_SCRATCH_BUFFER_SIZE                KB(16)
-#define MAX_SCRATCH_BUFFER_SIZE                KB(64)
-#define HWCURSOR_SIZE                  GTT_PAGE_SIZE
-#define HWCURSOR_SIZE_ARGB             GTT_PAGE_SIZE * 4
-
-/* Use a 64x64 HW cursor */
-#define I810_CURSOR_X                  64
-#define I810_CURSOR_Y                  I810_CURSOR_X
-
-#define PIPE_NAME(n)                   ('A' + (n))
-
-struct pci_device *
-intel_host_bridge (void);
+extern Bool intel_init_scrn(ScrnInfoPtr scrn);
 
 /**
  * Hints to CreatePixmap to tell the driver how the pixmap is going to be
diff --git a/src/compat-api.h b/src/compat-api.h
new file mode 100644 (file)
index 0000000..6b76572
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ * Copyright 2012 Red Hat, Inc.
+ *
+ * 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.
+ *
+ * Author: Dave Airlie <airlied@redhat.com>
+ */
+
+/* this file provides API compat between server post 1.13 and pre it,
+   it should be reused inside as many drivers as possible */
+#ifndef COMPAT_API_H
+#define COMPAT_API_H
+
+#ifndef GLYPH_HAS_GLYPH_PICTURE_ACCESSOR
+#define GetGlyphPicture(g, s) GlyphPicture((g))[(s)->myNum]
+#define SetGlyphPicture(g, s, p) GlyphPicture((g))[(s)->myNum] = p
+#endif
+
+#ifndef XF86_HAS_SCRN_CONV
+#define xf86ScreenToScrn(s) xf86Screens[(s)->myNum]
+#define xf86ScrnToScreen(s) screenInfo.screens[(s)->scrnIndex]
+#endif
+
+#ifndef XF86_SCRN_INTERFACE
+
+#define SCRN_ARG_TYPE int
+#define SCRN_INFO_PTR(arg1) ScrnInfoPtr scrn = xf86Screens[(arg1)]
+
+#define SCREEN_ARG_TYPE int
+#define SCREEN_PTR(arg1) ScreenPtr screen = screenInfo.screens[(arg1)]
+
+#define SCREEN_INIT_ARGS_DECL int scrnIndex, ScreenPtr screen, int argc, char **argv
+
+#define BLOCKHANDLER_ARGS_DECL int arg, pointer blockData, pointer timeout, pointer read_mask
+#define BLOCKHANDLER_ARGS arg, blockData, timeout, read_mask
+
+#define WAKEUPHANDLER_ARGS_DECL int arg, pointer wakeupData, unsigned long result, pointer read_mask
+#define WAKEUPHANDLER_ARGS arg, wakeupData, result, read_mask
+
+#define CLOSE_SCREEN_ARGS_DECL int scrnIndex, ScreenPtr screen
+#define CLOSE_SCREEN_ARGS scrnIndex, screen
+
+#define ADJUST_FRAME_ARGS_DECL int arg, int x, int y, int flags
+#define ADJUST_FRAME_ARGS(arg, x, y) (arg)->scrnIndex, x, y, 0
+
+#define SWITCH_MODE_ARGS_DECL int arg, DisplayModePtr mode, int flags
+#define SWITCH_MODE_ARGS(arg, m) (arg)->scrnIndex, m, 0
+
+#define FREE_SCREEN_ARGS_DECL int arg, int flags
+
+#define VT_FUNC_ARGS_DECL int arg, int flags
+#define VT_FUNC_ARGS(flags) scrn->scrnIndex, (flags)
+
+#define XF86_ENABLEDISABLEFB_ARG(x) ((x)->scrnIndex)
+
+#else
+#define SCRN_ARG_TYPE ScrnInfoPtr
+#define SCRN_INFO_PTR(arg1) ScrnInfoPtr scrn = (arg1)
+
+#define SCREEN_ARG_TYPE ScreenPtr
+#define SCREEN_PTR(arg1) ScreenPtr screen = (arg1)
+
+#define SCREEN_INIT_ARGS_DECL ScreenPtr screen, int argc, char **argv
+
+#define BLOCKHANDLER_ARGS_DECL ScreenPtr arg, pointer timeout, pointer read_mask
+#define BLOCKHANDLER_ARGS arg, timeout, read_mask
+
+#define WAKEUPHANDLER_ARGS_DECL ScreenPtr arg, unsigned long result, pointer read_mask
+#define WAKEUPHANDLER_ARGS arg, result, read_mask
+
+#define CLOSE_SCREEN_ARGS_DECL ScreenPtr screen
+#define CLOSE_SCREEN_ARGS screen
+
+#define ADJUST_FRAME_ARGS_DECL ScrnInfoPtr arg, int x, int y
+#define ADJUST_FRAME_ARGS(arg, x, y) arg, x, y
+
+#define SWITCH_MODE_ARGS_DECL ScrnInfoPtr arg, DisplayModePtr mode
+#define SWITCH_MODE_ARGS(arg, m) arg, m
+
+#define FREE_SCREEN_ARGS_DECL ScrnInfoPtr arg
+
+#define VT_FUNC_ARGS_DECL ScrnInfoPtr arg
+#define VT_FUNC_ARGS(flags) scrn
+
+#define XF86_ENABLEDISABLEFB_ARG(x) (x)
+
+#endif
+
+#endif
index 3f3d2ef..e169cc1 100644 (file)
@@ -164,7 +164,7 @@ static Bool i830_get_dest_format(PicturePtr dest_picture, uint32_t * dst_format)
                *dst_format = COLR_BUF_ARGB4444;
                break;
        default:
-               scrn = xf86Screens[dest_picture->pDrawable->pScreen->myNum];
+               scrn = xf86ScreenToScrn(dest_picture->pDrawable->pScreen);
                intel_debug_fallback(scrn, "Unsupported dest format 0x%x\n",
                                     (int)dest_picture->format);
                return FALSE;
@@ -245,7 +245,7 @@ static uint32_t i8xx_get_card_format(intel_screen_private *intel,
 static void i830_texture_setup(PicturePtr picture, PixmapPtr pixmap, int unit)
 {
 
-       ScrnInfoPtr scrn = xf86Screens[picture->pDrawable->pScreen->myNum];
+       ScrnInfoPtr scrn = xf86ScreenToScrn(picture->pDrawable->pScreen);
        intel_screen_private *intel = intel_get_screen_private(scrn);
        uint32_t format, tiling_bits, pitch, filter;
        uint32_t wrap_mode;
@@ -346,7 +346,7 @@ i830_check_composite(int op,
                     PicturePtr dest_picture,
                     int width, int height)
 {
-       ScrnInfoPtr scrn = xf86Screens[dest_picture->pDrawable->pScreen->myNum];
+       ScrnInfoPtr scrn = xf86ScreenToScrn(dest_picture->pDrawable->pScreen);
        uint32_t tmp1;
 
        /* Check for unsupported compositing operations. */
@@ -399,7 +399,7 @@ i830_check_composite_target(PixmapPtr pixmap)
 Bool
 i830_check_composite_texture(ScreenPtr screen, PicturePtr picture)
 {
-       ScrnInfoPtr scrn = xf86Screens[screen->myNum];
+       ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
        intel_screen_private *intel = intel_get_screen_private(scrn);
 
        if (picture->repeatType > RepeatReflect) {
@@ -446,7 +446,7 @@ i830_prepare_composite(int op, PicturePtr source_picture,
                       PicturePtr mask_picture, PicturePtr dest_picture,
                       PixmapPtr source, PixmapPtr mask, PixmapPtr dest)
 {
-       ScrnInfoPtr scrn = xf86Screens[dest_picture->pDrawable->pScreen->myNum];
+       ScrnInfoPtr scrn = xf86ScreenToScrn(dest_picture->pDrawable->pScreen);
        intel_screen_private *intel = intel_get_screen_private(scrn);
        drm_intel_bo *bo_table[] = {
                NULL,           /* batch_bo */
@@ -563,8 +563,7 @@ i830_prepare_composite(int op, PicturePtr source_picture,
                intel->s8_blendctl = blendctl;
        }
 
-       if(intel_pixmap_is_dirty(source) ||
-          (mask && intel_pixmap_is_dirty(mask)))
+       if (intel_pixmap_is_dirty(source) || intel_pixmap_is_dirty(mask))
                intel_batch_emit_flush(scrn);
 
        intel->needs_render_state_emit = TRUE;
@@ -666,7 +665,7 @@ i830_emit_composite_primitive(PixmapPtr dest,
                              int maskX, int maskY,
                              int dstX, int dstY, int w, int h)
 {
-       ScrnInfoPtr scrn = xf86Screens[dest->drawable.pScreen->myNum];
+       ScrnInfoPtr scrn = xf86ScreenToScrn(dest->drawable.pScreen);
        intel_screen_private *intel = intel_get_screen_private(scrn);
        Bool is_affine_src, is_affine_mask = TRUE;
        int per_vertex;
@@ -854,7 +853,7 @@ void
 i830_composite(PixmapPtr dest, int srcX, int srcY, int maskX, int maskY,
               int dstX, int dstY, int w, int h)
 {
-       ScrnInfoPtr scrn = xf86Screens[dest->drawable.pScreen->myNum];
+       ScrnInfoPtr scrn = xf86ScreenToScrn(dest->drawable.pScreen);
        intel_screen_private *intel = intel_get_screen_private(scrn);
 
        intel_batch_start_atomic(scrn, 58 +     /* invarient */
index 87d2336..6d3400e 100644 (file)
@@ -172,7 +172,7 @@ static Bool i915_get_dest_format(PicturePtr dest_picture, uint32_t * dst_format)
                *dst_format = COLR_BUF_ARGB4444;
                break;
        default:
-               scrn = xf86Screens[dest_picture->pDrawable->pScreen->myNum];
+               scrn = xf86ScreenToScrn(dest_picture->pDrawable->pScreen);
                intel_debug_fallback(scrn,
                                     "Unsupported dest format 0x%x\n",
                                     (int)dest_picture->format);
@@ -189,7 +189,7 @@ i915_check_composite(int op,
                     PicturePtr dest_picture,
                     int width, int height)
 {
-       ScrnInfoPtr scrn = xf86Screens[dest_picture->pDrawable->pScreen->myNum];
+       ScrnInfoPtr scrn = xf86ScreenToScrn(dest_picture->pDrawable->pScreen);
        uint32_t tmp1;
 
        /* Check for unsupported compositing operations. */
@@ -243,7 +243,7 @@ Bool
 i915_check_composite_texture(ScreenPtr screen, PicturePtr picture)
 {
        if (picture->repeatType > RepeatReflect) {
-               ScrnInfoPtr scrn = xf86Screens[screen->myNum];
+               ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
                intel_debug_fallback(scrn, "Unsupported picture repeat %d\n",
                             picture->repeatType);
                return FALSE;
@@ -251,17 +251,14 @@ i915_check_composite_texture(ScreenPtr screen, PicturePtr picture)
 
        if (picture->filter != PictFilterNearest &&
            picture->filter != PictFilterBilinear) {
-               ScrnInfoPtr scrn = xf86Screens[screen->myNum];
+               ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
                intel_debug_fallback(scrn, "Unsupported filter 0x%x\n",
                                     picture->filter);
                return FALSE;
        }
 
-       if (picture->pSourcePict) {
-               SourcePict *source = picture->pSourcePict;
-               if (source->type == SourcePictTypeSolidFill)
-                       return TRUE;
-       }
+       if (picture->pSourcePict)
+               return FALSE;
 
        if (picture->pDrawable) {
                int w, h, i;
@@ -269,7 +266,7 @@ i915_check_composite_texture(ScreenPtr screen, PicturePtr picture)
                w = picture->pDrawable->width;
                h = picture->pDrawable->height;
                if ((w > 2048) || (h > 2048)) {
-                       ScrnInfoPtr scrn = xf86Screens[screen->myNum];
+                       ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
                        intel_debug_fallback(scrn,
                                             "Picture w/h too large (%dx%d)\n",
                                             w, h);
@@ -284,7 +281,7 @@ i915_check_composite_texture(ScreenPtr screen, PicturePtr picture)
                }
                if (i == sizeof(i915_tex_formats) / sizeof(i915_tex_formats[0]))
                {
-                       ScrnInfoPtr scrn = xf86Screens[screen->myNum];
+                       ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
                        intel_debug_fallback(scrn, "Unsupported picture format "
                                             "0x%x\n",
                                             (int)picture->format);
@@ -299,7 +296,7 @@ i915_check_composite_texture(ScreenPtr screen, PicturePtr picture)
 
 static Bool i915_texture_setup(PicturePtr picture, PixmapPtr pixmap, int unit)
 {
-       ScrnInfoPtr scrn = xf86Screens[picture->pDrawable->pScreen->myNum];
+       ScrnInfoPtr scrn = xf86ScreenToScrn(picture->pDrawable->pScreen);
        intel_screen_private *intel = intel_get_screen_private(scrn);
        uint32_t format, pitch, filter;
        uint32_t wrap_mode, tiling_bits;
@@ -347,7 +344,6 @@ static Bool i915_texture_setup(PicturePtr picture, PixmapPtr pixmap, int unit)
                    (FILTER_LINEAR << SS2_MIN_FILTER_SHIFT);
                break;
        default:
-               filter = 0;
                intel_debug_fallback(scrn, "Bad filter 0x%x\n",
                                     picture->filter);
                return FALSE;
@@ -387,23 +383,6 @@ static Bool i915_texture_setup(PicturePtr picture, PixmapPtr pixmap, int unit)
 }
 
 static void
-i915_emit_composite_primitive_constant(intel_screen_private *intel,
-                                      int srcX, int srcY,
-                                      int maskX, int maskY,
-                                      int dstX, int dstY,
-                                      int w, int h)
-{
-       OUT_VERTEX(dstX + w);
-       OUT_VERTEX(dstY + h);
-
-       OUT_VERTEX(dstX);
-       OUT_VERTEX(dstY + h);
-
-       OUT_VERTEX(dstX);
-       OUT_VERTEX(dstY);
-}
-
-static void
 i915_emit_composite_primitive_identity_source(intel_screen_private *intel,
                                              int srcX, int srcY,
                                              int maskX, int maskY,
@@ -470,29 +449,6 @@ i915_emit_composite_primitive_affine_source(intel_screen_private *intel,
 }
 
 static void
-i915_emit_composite_primitive_constant_identity_mask(intel_screen_private *intel,
-                                                    int srcX, int srcY,
-                                                    int maskX, int maskY,
-                                                    int dstX, int dstY,
-                                                    int w, int h)
-{
-       OUT_VERTEX(dstX + w);
-       OUT_VERTEX(dstY + h);
-       OUT_VERTEX((maskX + w) * intel->scale_units[0][0]);
-       OUT_VERTEX((maskY + h) * intel->scale_units[0][1]);
-
-       OUT_VERTEX(dstX);
-       OUT_VERTEX(dstY + h);
-       OUT_VERTEX(maskX * intel->scale_units[0][0]);
-       OUT_VERTEX((maskY + h) * intel->scale_units[0][1]);
-
-       OUT_VERTEX(dstX);
-       OUT_VERTEX(dstY);
-       OUT_VERTEX(maskX * intel->scale_units[0][0]);
-       OUT_VERTEX(maskY * intel->scale_units[0][1]);
-}
-
-static void
 i915_emit_composite_primitive_identity_source_mask(intel_screen_private *intel,
                                                   int srcX, int srcY,
                                                   int maskX, int maskY,
@@ -529,70 +485,61 @@ i915_emit_composite_primitive(intel_screen_private *intel,
                              int w, int h)
 {
        Bool is_affine_src = TRUE, is_affine_mask = TRUE;
-       int per_vertex;
        int tex_unit = 0;
        int src_unit = -1, mask_unit = -1;
        float src_x[3], src_y[3], src_w[3], mask_x[3], mask_y[3], mask_w[3];
 
-       per_vertex = 2;         /* dest x/y */
-
-       if (! intel->render_source_is_solid) {
-               src_unit = tex_unit++;
-
-               is_affine_src = intel_transform_is_affine(intel->transform[src_unit]);
-               if (is_affine_src) {
-                       if (!intel_get_transformed_coordinates(srcX, srcY,
-                                                             intel->
-                                                             transform[src_unit],
-                                                             &src_x[0],
-                                                             &src_y[0]))
-                               return;
-
-                       if (!intel_get_transformed_coordinates(srcX, srcY + h,
-                                                             intel->
-                                                             transform[src_unit],
-                                                             &src_x[1],
-                                                             &src_y[1]))
-                               return;
-
-                       if (!intel_get_transformed_coordinates(srcX + w, srcY + h,
-                                                             intel->
-                                                             transform[src_unit],
-                                                             &src_x[2],
-                                                             &src_y[2]))
-                               return;
-
-                       per_vertex += 2;        /* src x/y */
-               } else {
-                       if (!intel_get_transformed_coordinates_3d(srcX, srcY,
-                                                                intel->
-                                                                transform[src_unit],
-                                                                &src_x[0],
-                                                                &src_y[0],
-                                                                &src_w[0]))
-                               return;
-
-                       if (!intel_get_transformed_coordinates_3d(srcX, srcY + h,
-                                                                intel->
-                                                                transform[src_unit],
-                                                                &src_x[1],
-                                                                &src_y[1],
-                                                                &src_w[1]))
-                               return;
-
-                       if (!intel_get_transformed_coordinates_3d(srcX + w, srcY + h,
-                                                                intel->
-                                                                transform[src_unit],
-                                                                &src_x[2],
-                                                                &src_y[2],
-                                                                &src_w[2]))
-                               return;
-
-                       per_vertex += 4;        /* src x/y/z/w */
-               }
-       }
-
-       if (intel->render_mask && ! intel->render_mask_is_solid) {
+       src_unit = tex_unit++;
+
+       is_affine_src = intel_transform_is_affine(intel->transform[src_unit]);
+       if (is_affine_src) {
+               if (!intel_get_transformed_coordinates(srcX, srcY,
+                                                     intel->
+                                                     transform[src_unit],
+                                                     &src_x[0],
+                                                     &src_y[0]))
+                       return;
+
+               if (!intel_get_transformed_coordinates(srcX, srcY + h,
+                                                     intel->
+                                                     transform[src_unit],
+                                                     &src_x[1],
+                                                     &src_y[1]))
+                       return;
+
+               if (!intel_get_transformed_coordinates(srcX + w, srcY + h,
+                                                     intel->
+                                                     transform[src_unit],
+                                                     &src_x[2],
+                                                     &src_y[2]))
+                       return;
+       } else {
+               if (!intel_get_transformed_coordinates_3d(srcX, srcY,
+                                                        intel->
+                                                        transform[src_unit],
+                                                        &src_x[0],
+                                                        &src_y[0],
+                                                        &src_w[0]))
+                       return;
+
+               if (!intel_get_transformed_coordinates_3d(srcX, srcY + h,
+                                                        intel->
+                                                        transform[src_unit],
+                                                        &src_x[1],
+                                                        &src_y[1],
+                                                        &src_w[1]))
+                       return;
+
+               if (!intel_get_transformed_coordinates_3d(srcX + w, srcY + h,
+                                                        intel->
+                                                        transform[src_unit],
+                                                        &src_x[2],
+                                                        &src_y[2],
+                                                        &src_w[2]))
+                       return;
+       }
+
+       if (intel->render_mask) {
                mask_unit = tex_unit++;
 
                is_affine_mask = intel_transform_is_affine(intel->transform[mask_unit]);
@@ -617,8 +564,6 @@ i915_emit_composite_primitive(intel_screen_private *intel,
                                                              &mask_x[2],
                                                              &mask_y[2]))
                                return;
-
-                       per_vertex += 2;        /* mask x/y */
                } else {
                        if (!intel_get_transformed_coordinates_3d(maskX, maskY,
                                                                 intel->
@@ -643,22 +588,18 @@ i915_emit_composite_primitive(intel_screen_private *intel,
                                                                 &mask_y[2],
                                                                 &mask_w[2]))
                                return;
-
-                       per_vertex += 4;        /* mask x/y/z/w */
                }
        }
 
        OUT_VERTEX(dstX + w);
        OUT_VERTEX(dstY + h);
-       if (! intel->render_source_is_solid) {
-           OUT_VERTEX(src_x[2] * intel->scale_units[src_unit][0]);
-           OUT_VERTEX(src_y[2] * intel->scale_units[src_unit][1]);
-           if (!is_affine_src) {
+       OUT_VERTEX(src_x[2] * intel->scale_units[src_unit][0]);
+       OUT_VERTEX(src_y[2] * intel->scale_units[src_unit][1]);
+       if (!is_affine_src) {
                OUT_VERTEX(0.0);
                OUT_VERTEX(src_w[2]);
-           }
        }
-       if (intel->render_mask && ! intel->render_mask_is_solid) {
+       if (intel->render_mask) {
                OUT_VERTEX(mask_x[2] * intel->scale_units[mask_unit][0]);
                OUT_VERTEX(mask_y[2] * intel->scale_units[mask_unit][1]);
                if (!is_affine_mask) {
@@ -669,15 +610,13 @@ i915_emit_composite_primitive(intel_screen_private *intel,
 
        OUT_VERTEX(dstX);
        OUT_VERTEX(dstY + h);
-       if (! intel->render_source_is_solid) {
-           OUT_VERTEX(src_x[1] * intel->scale_units[src_unit][0]);
-           OUT_VERTEX(src_y[1] * intel->scale_units[src_unit][1]);
-           if (!is_affine_src) {
+       OUT_VERTEX(src_x[1] * intel->scale_units[src_unit][0]);
+       OUT_VERTEX(src_y[1] * intel->scale_units[src_unit][1]);
+       if (!is_affine_src) {
                OUT_VERTEX(0.0);
                OUT_VERTEX(src_w[1]);
-           }
        }
-       if (intel->render_mask && ! intel->render_mask_is_solid) {
+       if (intel->render_mask) {
                OUT_VERTEX(mask_x[1] * intel->scale_units[mask_unit][0]);
                OUT_VERTEX(mask_y[1] * intel->scale_units[mask_unit][1]);
                if (!is_affine_mask) {
@@ -688,15 +627,13 @@ i915_emit_composite_primitive(intel_screen_private *intel,
 
        OUT_VERTEX(dstX);
        OUT_VERTEX(dstY);
-       if (! intel->render_source_is_solid) {
-           OUT_VERTEX(src_x[0] * intel->scale_units[src_unit][0]);
-           OUT_VERTEX(src_y[0] * intel->scale_units[src_unit][1]);
-           if (!is_affine_src) {
+       OUT_VERTEX(src_x[0] * intel->scale_units[src_unit][0]);
+       OUT_VERTEX(src_y[0] * intel->scale_units[src_unit][1]);
+       if (!is_affine_src) {
                OUT_VERTEX(0.0);
                OUT_VERTEX(src_w[0]);
-           }
        }
-       if (intel->render_mask && ! intel->render_mask_is_solid) {
+       if (intel->render_mask) {
                OUT_VERTEX(mask_x[0] * intel->scale_units[mask_unit][0]);
                OUT_VERTEX(mask_y[0] * intel->scale_units[mask_unit][1]);
                if (!is_affine_mask) {
@@ -711,12 +648,12 @@ i915_prepare_composite(int op, PicturePtr source_picture,
                       PicturePtr mask_picture, PicturePtr dest_picture,
                       PixmapPtr source, PixmapPtr mask, PixmapPtr dest)
 {
-       ScrnInfoPtr scrn = xf86Screens[dest_picture->pDrawable->pScreen->myNum];
+       ScrnInfoPtr scrn = xf86ScreenToScrn(dest_picture->pDrawable->pScreen);
        intel_screen_private *intel = intel_get_screen_private(scrn);
        drm_intel_bo *bo_table[] = {
                NULL,           /* batch_bo */
                intel_get_pixmap_bo(dest),
-               source ? intel_get_pixmap_bo(source) : NULL,
+               intel_get_pixmap_bo(source),
                mask ? intel_get_pixmap_bo(mask) : NULL,
        };
        int tex_unit = 0;
@@ -729,29 +666,11 @@ i915_prepare_composite(int op, PicturePtr source_picture,
        intel->render_dest_picture = dest_picture;
        intel->render_dest = dest;
 
-       intel->render_source_is_solid = FALSE;
-       if (source_picture->pSourcePict) {
-               SourcePict *source = source_picture->pSourcePict;
-               if (source->type == SourcePictTypeSolidFill) {
-                       intel->render_source_is_solid = TRUE;
-                       intel->render_source_solid = source->solidFill.color;
-               }
-       }
-       if (!intel->render_source_is_solid && !intel_check_pitch_3d(source))
+       if (!intel_check_pitch_3d(source))
                return FALSE;
 
-       intel->render_mask_is_solid = FALSE;
-       if (mask) {
-               if (mask_picture->pSourcePict) {
-                       SourcePict *source = mask_picture->pSourcePict;
-                       if (source->type == SourcePictTypeSolidFill) {
-                               intel->render_mask_is_solid = TRUE;
-                               intel->render_mask_solid = source->solidFill.color;
-                       }
-               }
-               if (!intel->render_mask_is_solid && !intel_check_pitch_3d(mask))
-                       return FALSE;
-       }
+       if (mask && !intel_check_pitch_3d(mask))
+               return FALSE;
 
        if (!intel_check_pitch_3d(dest))
                return FALSE;
@@ -763,7 +682,6 @@ i915_prepare_composite(int op, PicturePtr source_picture,
        if (!intel_get_aperture_space(scrn, bo_table, ARRAY_SIZE(bo_table)))
                return FALSE;
 
-       intel->needs_render_ca_pass = FALSE;
        if (mask_picture != NULL && mask_picture->componentAlpha &&
            PICT_FORMAT_RGB(mask_picture->format)) {
                /* Check if it's component alpha that relies on a source alpha
@@ -771,12 +689,8 @@ i915_prepare_composite(int op, PicturePtr source_picture,
                 * into the single source value that we get to blend with.
                 */
                if (i915_blend_op[op].src_alpha &&
-                   (i915_blend_op[op].src_blend != BLENDFACT_ZERO)) {
-                       if (op != PictOpOver)
-                               return FALSE;
-
-                       intel->needs_render_ca_pass = TRUE;
-               }
+                   (i915_blend_op[op].src_blend != BLENDFACT_ZERO))
+                       return FALSE;
        }
 
        intel->transform[0] = NULL;
@@ -787,57 +701,46 @@ i915_prepare_composite(int op, PicturePtr source_picture,
        intel->scale_units[1][1] = -1;
 
        floats_per_vertex = 2;          /* dest x/y */
-       if (! intel->render_source_is_solid) {
-               if (!i915_texture_setup(source_picture, source, tex_unit++)) {
-                       intel_debug_fallback(scrn, "fail to setup src texture\n");
-                       return FALSE;
-               }
-
-               if (intel_transform_is_affine(source_picture->transform))
-                       floats_per_vertex += 2; /* src x/y */
-               else
-                       floats_per_vertex += 4; /* src x/y/z/w */
+       if (!i915_texture_setup(source_picture, source, tex_unit++)) {
+               intel_debug_fallback(scrn, "fail to setup src texture\n");
+               return FALSE;
        }
 
-       if (mask != NULL) {
-               if (! intel->render_mask_is_solid) {
-                       if (!i915_texture_setup(mask_picture, mask, tex_unit++)) {
-                               intel_debug_fallback(scrn,
-                                               "fail to setup mask texture\n");
-                               return FALSE;
-                       }
+       if (intel_transform_is_affine(source_picture->transform))
+               floats_per_vertex += 2; /* src x/y */
+       else
+               floats_per_vertex += 4; /* src x/y/z/w */
 
-                       if (intel_transform_is_affine(mask_picture->transform))
-                               floats_per_vertex += 2; /* mask x/y */
-                       else
-                               floats_per_vertex += 4; /* mask x/y/z/w */
+       if (mask_picture != NULL) {
+               assert(mask != NULL);
+               if (!i915_texture_setup(mask_picture, mask, tex_unit++)) {
+                       intel_debug_fallback(scrn,
+                                            "fail to setup mask texture\n");
+                       return FALSE;
                }
+
+               if (intel_transform_is_affine(mask_picture->transform))
+                       floats_per_vertex += 2; /* mask x/y */
+               else
+                       floats_per_vertex += 4; /* mask x/y/z/w */
        }
 
        intel->i915_render_state.op = op;
 
-       /* BUF_INFO is an implicit flush */
-       if (dest != intel->render_current_dest)
-               intel_batch_do_flush(scrn);
-       else if((source && intel_pixmap_is_dirty(source)) ||
-               (mask && intel_pixmap_is_dirty(mask)))
+       if (intel_pixmap_is_dirty(source) || intel_pixmap_is_dirty(mask))
                intel_batch_emit_flush(scrn);
 
        intel->needs_render_state_emit = TRUE;
 
        intel->prim_emit = i915_emit_composite_primitive;
        if (!mask) {
-               if (intel->render_source_is_solid)
-                       intel->prim_emit = i915_emit_composite_primitive_constant;
-               else if (intel->transform[0] == NULL)
+               if (intel->transform[0] == NULL)
                        intel->prim_emit = i915_emit_composite_primitive_identity_source;
                else if (intel_transform_is_affine(intel->transform[0]))
                        intel->prim_emit = i915_emit_composite_primitive_affine_source;
        } else {
                if (intel->transform[0] == NULL) {
-                       if (intel->render_source_is_solid)
-                               intel->prim_emit = i915_emit_composite_primitive_constant_identity_mask;
-                       else if (intel->transform[1] == NULL)
+                       if (intel->transform[1] == NULL)
                                intel->prim_emit = i915_emit_composite_primitive_identity_source_mask;
                }
        }
@@ -856,76 +759,47 @@ i915_composite_emit_shader(intel_screen_private *intel, CARD8 op)
        PicturePtr mask_picture = intel->render_mask_picture;
        PixmapPtr mask = intel->render_mask;
        int src_reg, mask_reg;
-       Bool is_solid_src, is_solid_mask;
        Bool dest_is_alpha = PIXMAN_FORMAT_RGB(intel->render_dest_picture->format) == 0;
-       int tex_unit, t;
        FS_LOCALS();
 
-       is_solid_src = intel->render_source_is_solid;
-       is_solid_mask = intel->render_mask_is_solid;
-
        FS_BEGIN();
 
        /* Declare the registers necessary for our program.  */
-       t = 0;
-       if (is_solid_src) {
-               i915_fs_dcl(FS_T8);
-               src_reg = FS_T8;
-       } else {
-               i915_fs_dcl(FS_T0);
-               i915_fs_dcl(FS_S0);
-               t++;
-       }
+       i915_fs_dcl(FS_T0);
+       i915_fs_dcl(FS_S0);
        if (!mask) {
                /* No mask, so load directly to output color */
-               if (! is_solid_src) {
-                       if (dest_is_alpha)
-                               src_reg = FS_R0;
-                       else
-                               src_reg = FS_OC;
-
-                       if (intel_transform_is_affine(intel->transform[0]))
-                               i915_fs_texld(src_reg, FS_S0, FS_T0);
-                       else
-                               i915_fs_texldp(src_reg, FS_S0, FS_T0);
-               }
+               if (dest_is_alpha)
+                       src_reg = FS_R0;
+               else
+                       src_reg = FS_OC;
 
-               if (src_reg != FS_OC) {
-                       if (dest_is_alpha)
-                               i915_fs_mov(FS_OC, i915_fs_operand(src_reg, W, W, W, W));
-                       else
-                               i915_fs_mov(FS_OC, i915_fs_operand_reg(src_reg));
-               }
+               if (intel_transform_is_affine(intel->transform[0]))
+                       i915_fs_texld(src_reg, FS_S0, FS_T0);
+               else
+                       i915_fs_texldp(src_reg, FS_S0, FS_T0);
+
+               if (src_reg != FS_OC)
+                       i915_fs_mov(FS_OC, i915_fs_operand(src_reg, W, W, W, W));
        } else {
-               if (is_solid_mask) {
-                       i915_fs_dcl(FS_T9);
-                       mask_reg = FS_T9;
-               } else {
-                       i915_fs_dcl(FS_T0 + t);
-                       i915_fs_dcl(FS_S0 + t);
-               }
+               i915_fs_dcl(FS_T1);
+               i915_fs_dcl(FS_S1);
 
-               tex_unit = 0;
-               if (! is_solid_src) {
-                       /* Load the source_picture texel */
-                       if (intel_transform_is_affine(intel->transform[tex_unit]))
-                               i915_fs_texld(FS_R0, FS_S0, FS_T0);
-                       else
-                               i915_fs_texldp(FS_R0, FS_S0, FS_T0);
+               /* Load the source_picture texel */
+               if (intel_transform_is_affine(intel->transform[0]))
+                       i915_fs_texld(FS_R0, FS_S0, FS_T0);
+               else
+                       i915_fs_texldp(FS_R0, FS_S0, FS_T0);
 
-                       src_reg = FS_R0;
-                       tex_unit++;
-               }
+               src_reg = FS_R0;
 
-               if (! is_solid_mask) {
-                       /* Load the mask_picture texel */
-                       if (intel_transform_is_affine(intel->transform[tex_unit]))
-                               i915_fs_texld(FS_R1, FS_S0 + t, FS_T0 + t);
-                       else
-                               i915_fs_texldp(FS_R1, FS_S0 + t, FS_T0 + t);
+               /* Load the mask_picture texel */
+               if (intel_transform_is_affine(intel->transform[1]))
+                       i915_fs_texld(FS_R1, FS_S1, FS_T1);
+               else
+                       i915_fs_texldp(FS_R1, FS_S1, FS_T1);
 
-                       mask_reg = FS_R1;
-               }
+               mask_reg = FS_R1;
 
                if (dest_is_alpha) {
                        i915_fs_mul(FS_OC,
@@ -972,7 +846,6 @@ static void i915_emit_composite_setup(ScrnInfoPtr scrn)
        PicturePtr dest_picture = intel->render_dest_picture;
        PixmapPtr mask = intel->render_mask;
        PixmapPtr dest = intel->render_dest;
-       Bool is_solid_src, is_solid_mask;
        int tex_count, t;
 
        intel->needs_render_state_emit = FALSE;
@@ -980,12 +853,7 @@ static void i915_emit_composite_setup(ScrnInfoPtr scrn)
        IntelEmitInvarientState(scrn);
        intel->last_3d = LAST_3D_RENDER;
 
-       is_solid_src = intel->render_source_is_solid;
-       is_solid_mask = intel->render_mask_is_solid;
-
-       tex_count = 0;
-       tex_count += ! is_solid_src;
-       tex_count += mask && ! is_solid_mask;
+       tex_count = 1 + (mask != NULL);
 
        assert(intel->in_batch_atomic);
 
@@ -1007,24 +875,13 @@ static void i915_emit_composite_setup(ScrnInfoPtr scrn)
            }
        }
 
-       if (is_solid_src) {
-           OUT_BATCH (_3DSTATE_DFLT_DIFFUSE_CMD);
-           OUT_BATCH (intel->render_source_solid);
-       }
-       if (mask && is_solid_mask) {
-           OUT_BATCH (_3DSTATE_DFLT_SPEC_CMD);
-           OUT_BATCH (intel->render_mask_solid);
-       }
-
        /* BUF_INFO is an implicit flush, so avoid if the target has not changed.
         * XXX However for reasons unfathomed, correct rendering in KDE requires
         * at least a MI_FLUSH | INHIBIT_RENDER_CACHE_FLUSH here.
         */
-       if (1 || dest != intel->render_current_dest) {
+       if (1) {
                uint32_t tiling_bits;
 
-               intel_batch_do_flush(scrn);
-
                if (intel_pixmap_tiled(dest)) {
                        tiling_bits = BUF_3D_TILED_SURFACE;
                        if (intel_get_pixmap_private(dest)->tiling
@@ -1050,49 +907,36 @@ static void i915_emit_composite_setup(ScrnInfoPtr scrn)
                          DRAW_XMAX(dest->drawable.width - 1));
                /* yorig, xorig (relate to color buffer?) */
                OUT_BATCH(0x00000000);
-
-               intel->render_current_dest = dest;
        }
 
        {
                uint32_t ss2;
 
                ss2 = ~0;
-               t = 0;
-               if (! is_solid_src) {
-                   ss2 &= ~S2_TEXCOORD_FMT(t, TEXCOORDFMT_NOT_PRESENT);
-                   ss2 |= S2_TEXCOORD_FMT(t,
-                                          intel_transform_is_affine(intel->transform[t]) ?
+               ss2 &= ~S2_TEXCOORD_FMT(0, TEXCOORDFMT_NOT_PRESENT);
+               ss2 |= S2_TEXCOORD_FMT(0,
+                                      intel_transform_is_affine(intel->transform[0]) ?
+                                      TEXCOORDFMT_2D : TEXCOORDFMT_4D);
+               if (mask) {
+                   ss2 &= ~S2_TEXCOORD_FMT(1, TEXCOORDFMT_NOT_PRESENT);
+                   ss2 |= S2_TEXCOORD_FMT(1,
+                                          intel_transform_is_affine(intel->transform[1]) ?
                                           TEXCOORDFMT_2D : TEXCOORDFMT_4D);
-                   t++;
-               }
-               if (mask && ! is_solid_mask) {
-                   ss2 &= ~S2_TEXCOORD_FMT(t, TEXCOORDFMT_NOT_PRESENT);
-                   ss2 |= S2_TEXCOORD_FMT(t,
-                                          intel_transform_is_affine(intel->transform[t]) ?
-                                          TEXCOORDFMT_2D : TEXCOORDFMT_4D);
-                   t++;
                }
 
-               if (intel->needs_render_ca_pass) {
-                       OUT_BATCH(_3DSTATE_LOAD_STATE_IMMEDIATE_1 | I1_LOAD_S(2) | 0);
-                       OUT_BATCH(ss2);
-               } else {
-                       OUT_BATCH(_3DSTATE_LOAD_STATE_IMMEDIATE_1 | I1_LOAD_S(2) | I1_LOAD_S(6) | 1);
-                       OUT_BATCH(ss2);
-                       OUT_BATCH(i915_get_blend_cntl(op, mask_picture, dest_picture->format));
-               }
+               OUT_BATCH(_3DSTATE_LOAD_STATE_IMMEDIATE_1 | I1_LOAD_S(2) | I1_LOAD_S(6) | 1);
+               OUT_BATCH(ss2);
+               OUT_BATCH(i915_get_blend_cntl(op, mask_picture, dest_picture->format));
        }
 
-       if (! intel->needs_render_ca_pass)
-               i915_composite_emit_shader(intel, op);
+       i915_composite_emit_shader(intel, op);
 }
 
 void
 i915_composite(PixmapPtr dest, int srcX, int srcY, int maskX, int maskY,
               int dstX, int dstY, int w, int h)
 {
-       ScrnInfoPtr scrn = xf86Screens[dest->drawable.pScreen->myNum];
+       ScrnInfoPtr scrn = xf86ScreenToScrn(dest->drawable.pScreen);
        intel_screen_private *intel = intel_get_screen_private(scrn);
 
        /* 28 + 16 + 10 + 20 + 32 + 16 */
@@ -1130,14 +974,6 @@ i915_composite(PixmapPtr dest, int srcX, int srcY, int maskX, int maskY,
        }
 
        if (intel->prim_offset == 0) {
-               if (intel->needs_render_ca_pass) {
-                       OUT_BATCH(_3DSTATE_LOAD_STATE_IMMEDIATE_1 | I1_LOAD_S(6) | 0);
-                       OUT_BATCH(i915_get_blend_cntl(PictOpOutReverse,
-                                                     intel->render_mask_picture,
-                                                     intel->render_dest_picture->format));
-                       i915_composite_emit_shader(intel, PictOpOutReverse);
-               }
-
                intel->prim_offset = intel->batch_used;
                OUT_BATCH(PRIM3D_RECTLIST | PRIM3D_INDIRECT_SEQUENTIAL);
                OUT_BATCH(intel->vertex_index);
@@ -1162,16 +998,6 @@ i915_vertex_flush(intel_screen_private *intel)
        intel->batch_ptr[intel->prim_offset] |= intel->vertex_count;
        intel->prim_offset = 0;
 
-       if (intel->needs_render_ca_pass) {
-               OUT_BATCH(_3DSTATE_LOAD_STATE_IMMEDIATE_1 | I1_LOAD_S(6) | 0);
-               OUT_BATCH(i915_get_blend_cntl(PictOpAdd,
-                                             intel->render_mask_picture,
-                                             intel->render_dest_picture->format));
-               i915_composite_emit_shader(intel, PictOpAdd);
-               OUT_BATCH(PRIM3D_RECTLIST | PRIM3D_INDIRECT_SEQUENTIAL | intel->vertex_count);
-               OUT_BATCH(intel->vertex_index);
-       }
-
        intel->vertex_index += intel->vertex_count;
        intel->vertex_count = 0;
 }
@@ -1180,6 +1006,5 @@ void
 i915_batch_commit_notify(intel_screen_private *intel)
 {
        intel->needs_render_state_emit = TRUE;
-       intel->render_current_dest = NULL;
        intel->last_floats_per_vertex = 0;
 }
index d46c6d1..ae2e6bb 100644 (file)
@@ -33,6 +33,7 @@
 #include "xf86_OSproc.h"
 #include "xf86xv.h"
 #include "fourcc.h"
+#include "gcstruct.h"
 
 #include "intel.h"
 #include "intel_video.h"
@@ -73,6 +74,8 @@ I915DisplayVideoTextured(ScrnInfoPtr scrn,
                                              dstRegion->extents.y2 - dyo,
                                              pixmap->drawable.depth,
                                              CREATE_PIXMAP_USAGE_SCRATCH);
+               if (target == NULL)
+                       return;
 
                pix_xoff = -dxo;
                pix_yoff = -dyo;
diff --git a/src/i965_3d.c b/src/i965_3d.c
new file mode 100644 (file)
index 0000000..a18db12
--- /dev/null
@@ -0,0 +1,443 @@
+/*
+ * Copyright © 2011 Intel 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_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+
+#include "intel.h"
+#include "i965_reg.h"
+#include "brw_defines.h"
+#include "brw_structs.h"
+
+void
+gen6_upload_invariant_states(intel_screen_private *intel)
+{
+       Bool ivb = INTEL_INFO(intel)->gen >= 70;
+
+       OUT_BATCH(BRW_PIPE_CONTROL | (4 - 2));
+       OUT_BATCH(BRW_PIPE_CONTROL_IS_FLUSH |
+               BRW_PIPE_CONTROL_WC_FLUSH |
+               BRW_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
+               BRW_PIPE_CONTROL_NOWRITE);
+       OUT_BATCH(0); /* write address */
+       OUT_BATCH(0); /* write data */
+
+       OUT_BATCH(NEW_PIPELINE_SELECT | PIPELINE_SELECT_3D);
+
+       OUT_BATCH(GEN6_3DSTATE_MULTISAMPLE | ((ivb ? 4 : 3) - 2));
+       OUT_BATCH(GEN6_3DSTATE_MULTISAMPLE_PIXEL_LOCATION_CENTER |
+               GEN6_3DSTATE_MULTISAMPLE_NUMSAMPLES_1); /* 1 sample/pixel */
+       OUT_BATCH(0);
+       if (ivb)
+               OUT_BATCH(0);
+
+       OUT_BATCH(GEN6_3DSTATE_SAMPLE_MASK | (2 - 2));
+       OUT_BATCH(1);
+
+       /* Set system instruction pointer */
+       OUT_BATCH(BRW_STATE_SIP | 0);
+       OUT_BATCH(0);
+}
+
+void
+gen6_upload_viewport_state_pointers(intel_screen_private *intel,
+                                   drm_intel_bo *cc_vp_bo)
+{
+       OUT_BATCH(GEN6_3DSTATE_VIEWPORT_STATE_POINTERS |
+               GEN6_3DSTATE_VIEWPORT_STATE_MODIFY_CC |
+               (4 - 2));
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_RELOC(cc_vp_bo, I915_GEM_DOMAIN_INSTRUCTION, 0, 0);
+}
+
+void
+gen7_upload_viewport_state_pointers(intel_screen_private *intel,
+                                   drm_intel_bo *cc_vp_bo)
+{
+       OUT_BATCH(GEN7_3DSTATE_VIEWPORT_STATE_POINTERS_CC | (2 - 2));
+       OUT_RELOC(cc_vp_bo, I915_GEM_DOMAIN_INSTRUCTION, 0, 0);
+
+       OUT_BATCH(GEN7_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CL | (2 - 2));
+       OUT_BATCH(0);
+}
+
+void
+gen6_upload_urb(intel_screen_private *intel)
+{
+       OUT_BATCH(GEN6_3DSTATE_URB | (3 - 2));
+       OUT_BATCH(((1 - 1) << GEN6_3DSTATE_URB_VS_SIZE_SHIFT) |
+               (24 << GEN6_3DSTATE_URB_VS_ENTRIES_SHIFT)); /* at least 24 on GEN6 */
+       OUT_BATCH((0 << GEN6_3DSTATE_URB_GS_SIZE_SHIFT) |
+               (0 << GEN6_3DSTATE_URB_GS_ENTRIES_SHIFT)); /* no GS thread */
+}
+
+/*
+ * URB layout on GEN7
+ * ----------------------------------------
+ * | PS Push Constants (8KB) | VS entries |
+ * ----------------------------------------
+ */
+void
+gen7_upload_urb(intel_screen_private *intel)
+{
+       unsigned int num_urb_entries = 32;
+
+       if (IS_HSW(intel))
+               num_urb_entries = 64;
+
+       OUT_BATCH(GEN7_3DSTATE_PUSH_CONSTANT_ALLOC_PS | (2 - 2));
+       OUT_BATCH(8); /* in 1KBs */
+
+       OUT_BATCH(GEN7_3DSTATE_URB_VS | (2 - 2));
+       OUT_BATCH(
+               (num_urb_entries << GEN7_URB_ENTRY_NUMBER_SHIFT) |
+               (2 - 1) << GEN7_URB_ENTRY_SIZE_SHIFT |
+               (1 << GEN7_URB_STARTING_ADDRESS_SHIFT));
+
+       OUT_BATCH(GEN7_3DSTATE_URB_GS | (2 - 2));
+       OUT_BATCH((0 << GEN7_URB_ENTRY_SIZE_SHIFT) |
+               (1 << GEN7_URB_STARTING_ADDRESS_SHIFT));
+
+       OUT_BATCH(GEN7_3DSTATE_URB_HS | (2 - 2));
+       OUT_BATCH((0 << GEN7_URB_ENTRY_SIZE_SHIFT) |
+               (2 << GEN7_URB_STARTING_ADDRESS_SHIFT));
+
+       OUT_BATCH(GEN7_3DSTATE_URB_DS | (2 - 2));
+       OUT_BATCH((0 << GEN7_URB_ENTRY_SIZE_SHIFT) |
+               (2 << GEN7_URB_STARTING_ADDRESS_SHIFT));
+}
+
+void
+gen6_upload_cc_state_pointers(intel_screen_private *intel,
+                             drm_intel_bo *blend_bo,
+                             drm_intel_bo *cc_bo,
+                             drm_intel_bo *depth_stencil_bo,
+                             uint32_t blend_offset)
+{
+       OUT_BATCH(GEN6_3DSTATE_CC_STATE_POINTERS | (4 - 2));
+       if (blend_bo)
+               OUT_RELOC(blend_bo, I915_GEM_DOMAIN_INSTRUCTION, 0,
+                         blend_offset | 1);
+       else
+               OUT_BATCH(0);
+
+       if (depth_stencil_bo)
+               OUT_RELOC(depth_stencil_bo, I915_GEM_DOMAIN_INSTRUCTION, 0, 1);
+       else
+               OUT_BATCH(0);
+
+       if (cc_bo)
+               OUT_RELOC(cc_bo, I915_GEM_DOMAIN_INSTRUCTION, 0, 1);
+       else
+               OUT_BATCH(0);
+}
+
+void
+gen7_upload_cc_state_pointers(intel_screen_private *intel,
+                             drm_intel_bo *blend_bo,
+                             drm_intel_bo *cc_bo,
+                             drm_intel_bo *depth_stencil_bo,
+                             uint32_t blend_offset)
+{
+       OUT_BATCH(GEN7_3DSTATE_BLEND_STATE_POINTERS | (2 - 2));
+       if (blend_bo)
+               OUT_RELOC(blend_bo, I915_GEM_DOMAIN_INSTRUCTION, 0,
+                         blend_offset | 1);
+       else
+               OUT_BATCH(0);
+
+       OUT_BATCH(GEN6_3DSTATE_CC_STATE_POINTERS | (2 - 2));
+       if (cc_bo)
+               OUT_RELOC(cc_bo, I915_GEM_DOMAIN_INSTRUCTION, 0, 1);
+       else
+               OUT_BATCH(0);
+
+       OUT_BATCH(GEN7_3DSTATE_DEPTH_STENCIL_STATE_POINTERS | (2 - 2));
+       if (depth_stencil_bo)
+               OUT_RELOC(depth_stencil_bo, I915_GEM_DOMAIN_INSTRUCTION, 0, 1);
+       else
+               OUT_BATCH(0);
+}
+
+void
+gen6_upload_sampler_state_pointers(intel_screen_private *intel,
+                                  drm_intel_bo *sampler_bo)
+{
+       OUT_BATCH(GEN6_3DSTATE_SAMPLER_STATE_POINTERS |
+               GEN6_3DSTATE_SAMPLER_STATE_MODIFY_PS |
+               (4 - 2));
+       OUT_BATCH(0); /* VS */
+       OUT_BATCH(0); /* GS */
+       OUT_RELOC(sampler_bo, I915_GEM_DOMAIN_INSTRUCTION, 0, 0);
+}
+
+void
+gen7_upload_sampler_state_pointers(intel_screen_private *intel,
+                                  drm_intel_bo *sampler_bo)
+{
+       OUT_BATCH(GEN7_3DSTATE_SAMPLER_STATE_POINTERS_PS | (2 - 2));
+       OUT_RELOC(sampler_bo, I915_GEM_DOMAIN_INSTRUCTION, 0, 0);
+}
+
+void
+gen7_upload_bypass_states(intel_screen_private *intel)
+{
+       /* bypass GS */
+       OUT_BATCH(GEN6_3DSTATE_CONSTANT_GS | (7 - 2));
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+
+       OUT_BATCH(GEN6_3DSTATE_GS | (7 - 2));
+       OUT_BATCH(0); /* without GS kernel */
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0); /* pass-through */
+
+       OUT_BATCH(GEN7_3DSTATE_BINDING_TABLE_POINTERS_GS | (2 - 2));
+       OUT_BATCH(0);
+
+       /* disable HS */
+       OUT_BATCH(GEN7_3DSTATE_CONSTANT_HS | (7 - 2));
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+
+       OUT_BATCH(GEN7_3DSTATE_HS | (7 - 2));
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+
+       OUT_BATCH(GEN7_3DSTATE_BINDING_TABLE_POINTERS_HS | (2 - 2));
+       OUT_BATCH(0);
+
+       /* Disable TE */
+       OUT_BATCH(GEN7_3DSTATE_TE | (4 - 2));
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+
+       /* Disable DS */
+       OUT_BATCH(GEN7_3DSTATE_CONSTANT_DS | (7 - 2));
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+
+       OUT_BATCH(GEN7_3DSTATE_DS | (6 - 2));
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+
+       OUT_BATCH(GEN7_3DSTATE_BINDING_TABLE_POINTERS_DS | (2 - 2));
+       OUT_BATCH(0);
+
+       /* Disable STREAMOUT */
+       OUT_BATCH(GEN7_3DSTATE_STREAMOUT | (3 - 2));
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+}
+
+void
+gen6_upload_vs_state(intel_screen_private *intel)
+{
+       Bool ivb = INTEL_INFO(intel)->gen >= 70;
+       /* disable VS constant buffer */
+       OUT_BATCH(GEN6_3DSTATE_CONSTANT_VS | ((ivb ? 7 : 5) - 2));
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       if (ivb) {
+               OUT_BATCH(0);
+               OUT_BATCH(0);
+       }
+
+       OUT_BATCH(GEN6_3DSTATE_VS | (6 - 2));
+       OUT_BATCH(0); /* without VS kernel */
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0); /* pass-through */
+}
+
+void
+gen6_upload_gs_state(intel_screen_private *intel)
+{
+       /* disable GS constant buffer */
+       OUT_BATCH(GEN6_3DSTATE_CONSTANT_GS | (5 - 2));
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+
+       OUT_BATCH(GEN6_3DSTATE_GS | (7 - 2));
+       OUT_BATCH(0); /* without GS kernel */
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0); /* pass-through */
+}
+
+void
+gen6_upload_clip_state(intel_screen_private *intel)
+{
+       OUT_BATCH(GEN6_3DSTATE_CLIP | (4 - 2));
+       OUT_BATCH(0);
+       OUT_BATCH(0); /* pass-through */
+       OUT_BATCH(0);
+}
+
+void
+gen6_upload_sf_state(intel_screen_private *intel,
+                    int num_sf_outputs,
+                    int read_offset)
+{
+       OUT_BATCH(GEN6_3DSTATE_SF | (20 - 2));
+       OUT_BATCH((num_sf_outputs << GEN6_3DSTATE_SF_NUM_OUTPUTS_SHIFT) |
+               (1 << GEN6_3DSTATE_SF_URB_ENTRY_READ_LENGTH_SHIFT) |
+               (read_offset << GEN6_3DSTATE_SF_URB_ENTRY_READ_OFFSET_SHIFT));
+       OUT_BATCH(0);
+       OUT_BATCH(GEN6_3DSTATE_SF_CULL_NONE);
+       OUT_BATCH(2 << GEN6_3DSTATE_SF_TRIFAN_PROVOKE_SHIFT); /* DW4 */
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0); /* DW9 */
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0); /* DW14 */
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0); /* DW19 */
+}
+
+void
+gen7_upload_sf_state(intel_screen_private *intel,
+                    int num_sf_outputs,
+                    int read_offset)
+{
+       OUT_BATCH(GEN7_3DSTATE_SBE | (14 - 2));
+       OUT_BATCH((num_sf_outputs << GEN7_SBE_NUM_OUTPUTS_SHIFT) |
+               (1 << GEN7_SBE_URB_ENTRY_READ_LENGTH_SHIFT) |
+               (read_offset << GEN7_SBE_URB_ENTRY_READ_OFFSET_SHIFT));
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0); /* DW4 */
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0); /* DW9 */
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+
+       OUT_BATCH(GEN6_3DSTATE_SF | (7 - 2));
+       OUT_BATCH(0);
+       OUT_BATCH(GEN6_3DSTATE_SF_CULL_NONE);
+       OUT_BATCH(2 << GEN6_3DSTATE_SF_TRIFAN_PROVOKE_SHIFT);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+}
+
+void
+gen6_upload_binding_table(intel_screen_private *intel,
+                         uint32_t ps_binding_table_offset)
+{
+       /* Binding table pointers */
+       OUT_BATCH(BRW_3DSTATE_BINDING_TABLE_POINTERS |
+                 GEN6_3DSTATE_BINDING_TABLE_MODIFY_PS |
+                 (4 - 2));
+       OUT_BATCH(0); /* VS */
+       OUT_BATCH(0); /* GS */
+       /* Only the PS uses the binding table */
+       OUT_BATCH(ps_binding_table_offset);
+}
+
+void
+gen7_upload_binding_table(intel_screen_private *intel,
+                         uint32_t ps_binding_table_offset)
+{
+       OUT_BATCH(GEN7_3DSTATE_BINDING_TABLE_POINTERS_PS | (2 - 2));
+       OUT_BATCH(ps_binding_table_offset);
+}
+
+void
+gen6_upload_depth_buffer_state(intel_screen_private *intel)
+{
+       OUT_BATCH(BRW_3DSTATE_DEPTH_BUFFER | (7 - 2));
+       OUT_BATCH((BRW_SURFACE_NULL << BRW_3DSTATE_DEPTH_BUFFER_TYPE_SHIFT) |
+                 (BRW_DEPTHFORMAT_D32_FLOAT << BRW_3DSTATE_DEPTH_BUFFER_FORMAT_SHIFT));
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+
+       OUT_BATCH(BRW_3DSTATE_CLEAR_PARAMS | (2 - 2));
+       OUT_BATCH(0);
+}
+
+void
+gen7_upload_depth_buffer_state(intel_screen_private *intel)
+{
+       OUT_BATCH(GEN7_3DSTATE_DEPTH_BUFFER | (7 - 2));
+       OUT_BATCH((BRW_DEPTHFORMAT_D32_FLOAT << 18) | (BRW_SURFACE_NULL << 29));
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+
+       OUT_BATCH(GEN7_3DSTATE_CLEAR_PARAMS | (3 - 2));
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+}
index df41fba..4bb5e4d 100644 (file)
 # define GEN6_3DSTATE_MULTISAMPLE_NUMSAMPLES_4                 (2 << 1)
 # define GEN6_3DSTATE_MULTISAMPLE_NUMSAMPLES_8                 (3 << 1)
 
+/* on GEN7+ */
+/* _3DSTATE_VERTEX_BUFFERS on GEN7*/
+/* DW1 */
+#define GEN7_VB0_ADDRESS_MODIFYENABLE   (1 << 14)
+
+/* _3DPRIMITIVE on GEN7 */
+/* DW1 */
+# define GEN7_3DPRIM_VERTEXBUFFER_ACCESS_SEQUENTIAL     (0 << 8)
+# define GEN7_3DPRIM_VERTEXBUFFER_ACCESS_RANDOM         (1 << 8)
+
+/* 3DSTATE_WM on GEN7 */
+/* DW1 */
+# define GEN7_WM_STATISTICS_ENABLE                              (1 << 31)
+# define GEN7_WM_DEPTH_CLEAR                                    (1 << 30)
+# define GEN7_WM_DISPATCH_ENABLE                                (1 << 29)
+# define GEN6_WM_DEPTH_RESOLVE                                  (1 << 28)
+# define GEN7_WM_HIERARCHICAL_DEPTH_RESOLVE                     (1 << 27)
+# define GEN7_WM_KILL_ENABLE                                    (1 << 25)
+# define GEN7_WM_PSCDEPTH_OFF                                   (0 << 23)
+# define GEN7_WM_PSCDEPTH_ON                                    (1 << 23)
+# define GEN7_WM_PSCDEPTH_ON_GE                                 (2 << 23)
+# define GEN7_WM_PSCDEPTH_ON_LE                                 (3 << 23)
+# define GEN7_WM_USES_SOURCE_DEPTH                              (1 << 20)
+# define GEN7_WM_USES_SOURCE_W                                  (1 << 19)
+# define GEN7_WM_POSITION_ZW_PIXEL                              (0 << 17)
+# define GEN7_WM_POSITION_ZW_CENTROID                           (2 << 17)
+# define GEN7_WM_POSITION_ZW_SAMPLE                             (3 << 17)
+# define GEN7_WM_NONPERSPECTIVE_SAMPLE_BARYCENTRIC              (1 << 16)
+# define GEN7_WM_NONPERSPECTIVE_CENTROID_BARYCENTRIC            (1 << 15)
+# define GEN7_WM_NONPERSPECTIVE_PIXEL_BARYCENTRIC               (1 << 14)
+# define GEN7_WM_PERSPECTIVE_SAMPLE_BARYCENTRIC                 (1 << 13)
+# define GEN7_WM_PERSPECTIVE_CENTROID_BARYCENTRIC               (1 << 12)
+# define GEN7_WM_PERSPECTIVE_PIXEL_BARYCENTRIC                  (1 << 11)
+# define GEN7_WM_USES_INPUT_COVERAGE_MASK                       (1 << 10)
+# define GEN7_WM_LINE_END_CAP_AA_WIDTH_0_5                      (0 << 8)
+# define GEN7_WM_LINE_END_CAP_AA_WIDTH_1_0                      (1 << 8)
+# define GEN7_WM_LINE_END_CAP_AA_WIDTH_2_0                      (2 << 8)
+# define GEN7_WM_LINE_END_CAP_AA_WIDTH_4_0                      (3 << 8)
+# define GEN7_WM_LINE_AA_WIDTH_0_5                              (0 << 6)
+# define GEN7_WM_LINE_AA_WIDTH_1_0                              (1 << 6)
+# define GEN7_WM_LINE_AA_WIDTH_2_0                              (2 << 6)
+# define GEN7_WM_LINE_AA_WIDTH_4_0                              (3 << 6)
+# define GEN7_WM_POLYGON_STIPPLE_ENABLE                         (1 << 4)
+# define GEN7_WM_LINE_STIPPLE_ENABLE                            (1 << 3)
+# define GEN7_WM_POINT_RASTRULE_UPPER_RIGHT                     (1 << 2)
+# define GEN7_WM_MSRAST_OFF_PIXEL                               (0 << 0)
+# define GEN7_WM_MSRAST_OFF_PATTERN                             (1 << 0)
+# define GEN7_WM_MSRAST_ON_PIXEL                                (2 << 0)
+# define GEN7_WM_MSRAST_ON_PATTERN                              (3 << 0)
+/* DW2 */
+# define GEN7_WM_MSDISPMODE_PERPIXEL                            (1 << 31)
+
+#define GEN7_3DSTATE_CLEAR_PARAMS               BRW_3D(3, 0, 0x04)
+#define GEN7_3DSTATE_DEPTH_BUFFER               BRW_3D(3, 0, 0x05)
+
+#define GEN7_3DSTATE_CONSTANT_HS                BRW_3D(3, 0, 0x19)
+#define GEN7_3DSTATE_CONSTANT_DS                BRW_3D(3, 0, 0x1a)
+
+#define GEN7_3DSTATE_HS                         BRW_3D(3, 0, 0x1b)
+#define GEN7_3DSTATE_TE                         BRW_3D(3, 0, 0x1c)
+#define GEN7_3DSTATE_DS                         BRW_3D(3, 0, 0x1d)
+#define GEN7_3DSTATE_STREAMOUT                  BRW_3D(3, 0, 0x1e)
+#define GEN7_3DSTATE_SBE                        BRW_3D(3, 0, 0x1f)
+
+/* DW1 */
+# define GEN7_SBE_SWIZZLE_CONTROL_MODE          (1 << 28)
+# define GEN7_SBE_NUM_OUTPUTS_SHIFT             22
+# define GEN7_SBE_SWIZZLE_ENABLE                (1 << 21)
+# define GEN7_SBE_POINT_SPRITE_LOWERLEFT        (1 << 20)
+# define GEN7_SBE_URB_ENTRY_READ_LENGTH_SHIFT   11
+# define GEN7_SBE_URB_ENTRY_READ_OFFSET_SHIFT   4
+
+#define GEN7_3DSTATE_PS                                 BRW_3D(3, 0, 0x20)
+/* DW1: kernel pointer */
+/* DW2 */
+# define GEN7_PS_SPF_MODE                               (1 << 31)
+# define GEN7_PS_VECTOR_MASK_ENABLE                     (1 << 30)
+# define GEN7_PS_SAMPLER_COUNT_SHIFT                    27
+# define GEN7_PS_BINDING_TABLE_ENTRY_COUNT_SHIFT        18
+# define GEN7_PS_FLOATING_POINT_MODE_IEEE_754           (0 << 16)
+# define GEN7_PS_FLOATING_POINT_MODE_ALT                (1 << 16)
+/* DW3: scratch space */
+/* DW4 */
+# define GEN7_PS_MAX_THREADS_SHIFT_IVB                  24
+# define GEN7_PS_MAX_THREADS_SHIFT_HSW                  23
+# define GEN7_PS_SAMPLE_MASK_SHIFT_HSW                 12
+# define GEN7_PS_PUSH_CONSTANT_ENABLE                   (1 << 11)
+# define GEN7_PS_ATTRIBUTE_ENABLE                       (1 << 10)
+# define GEN7_PS_OMASK_TO_RENDER_TARGET                 (1 << 9)
+# define GEN7_PS_DUAL_SOURCE_BLEND_ENABLE               (1 << 7)
+# define GEN7_PS_POSOFFSET_NONE                         (0 << 3)
+# define GEN7_PS_POSOFFSET_CENTROID                     (2 << 3)
+# define GEN7_PS_POSOFFSET_SAMPLE                       (3 << 3)
+# define GEN7_PS_32_DISPATCH_ENABLE                     (1 << 2)
+# define GEN7_PS_16_DISPATCH_ENABLE                     (1 << 1)
+# define GEN7_PS_8_DISPATCH_ENABLE                      (1 << 0)
+/* DW5 */
+# define GEN7_PS_DISPATCH_START_GRF_SHIFT_0             16
+# define GEN7_PS_DISPATCH_START_GRF_SHIFT_1             8
+# define GEN7_PS_DISPATCH_START_GRF_SHIFT_2             0
+/* DW6: kernel 1 pointer */
+/* DW7: kernel 2 pointer */
+
+#define GEN7_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CL      BRW_3D(3, 0, 0x21)
+#define GEN7_3DSTATE_VIEWPORT_STATE_POINTERS_CC         BRW_3D(3, 0, 0x23)
+
+#define GEN7_3DSTATE_BLEND_STATE_POINTERS               BRW_3D(3, 0, 0x24)
+#define GEN7_3DSTATE_DEPTH_STENCIL_STATE_POINTERS       BRW_3D(3, 0, 0x25)
+
+#define GEN7_3DSTATE_BINDING_TABLE_POINTERS_VS          BRW_3D(3, 0, 0x26)
+#define GEN7_3DSTATE_BINDING_TABLE_POINTERS_HS          BRW_3D(3, 0, 0x27)
+#define GEN7_3DSTATE_BINDING_TABLE_POINTERS_DS          BRW_3D(3, 0, 0x28)
+#define GEN7_3DSTATE_BINDING_TABLE_POINTERS_GS          BRW_3D(3, 0, 0x29)
+#define GEN7_3DSTATE_BINDING_TABLE_POINTERS_PS          BRW_3D(3, 0, 0x2a)
+
+#define GEN7_3DSTATE_SAMPLER_STATE_POINTERS_VS          BRW_3D(3, 0, 0x2b)
+#define GEN7_3DSTATE_SAMPLER_STATE_POINTERS_GS          BRW_3D(3, 0, 0x2e)
+#define GEN7_3DSTATE_SAMPLER_STATE_POINTERS_PS          BRW_3D(3, 0, 0x2f)
+
+#define GEN7_3DSTATE_URB_VS                             BRW_3D(3, 0, 0x30)
+#define GEN7_3DSTATE_URB_HS                             BRW_3D(3, 0, 0x31)
+#define GEN7_3DSTATE_URB_DS                             BRW_3D(3, 0, 0x32)
+#define GEN7_3DSTATE_URB_GS                             BRW_3D(3, 0, 0x33)
+/* DW1 */
+# define GEN7_URB_ENTRY_NUMBER_SHIFT            0
+# define GEN7_URB_ENTRY_SIZE_SHIFT              16
+# define GEN7_URB_STARTING_ADDRESS_SHIFT        25
+
+#define GEN7_3DSTATE_PUSH_CONSTANT_ALLOC_VS             BRW_3D(3, 1, 0x12)
+#define GEN7_3DSTATE_PUSH_CONSTANT_ALLOC_PS             BRW_3D(3, 1, 0x16)
+/* DW1 */
+# define GEN7_PUSH_CONSTANT_BUFFER_OFFSET_SHIFT 16
+
+
 #define PIPELINE_SELECT_3D             0
 #define PIPELINE_SELECT_MEDIA          1
 
 #define BRW_CLIP_ENABLE                       1
 
 /* for BRW_PIPE_CONTROL */
+#define BRW_PIPE_CONTROL_CS_STALL      (1 << 20)
 #define BRW_PIPE_CONTROL_NOWRITE       (0 << 14)
 #define BRW_PIPE_CONTROL_WRITE_QWORD   (1 << 14)
 #define BRW_PIPE_CONTROL_WRITE_DEPTH   (2 << 14)
 #define BRW_PIPE_CONTROL_NOTIFY_ENABLE (1 << 8)
 #define BRW_PIPE_CONTROL_GLOBAL_GTT    (1 << 2)
 #define BRW_PIPE_CONTROL_LOCAL_PGTT    (0 << 2)
+#define BRW_PIPE_CONTROL_STALL_AT_SCOREBOARD    (1 << 1)
 #define BRW_PIPE_CONTROL_DEPTH_CACHE_FLUSH     (1 << 0)
 
 /* VERTEX_BUFFER_STATE Structure */
index bfcd3f2..42b1959 100644 (file)
@@ -181,7 +181,7 @@ i965_check_composite(int op,
                     PicturePtr dest_picture,
                     int width, int height)
 {
-       ScrnInfoPtr scrn = xf86Screens[dest_picture->pDrawable->pScreen->myNum];
+       ScrnInfoPtr scrn = xf86ScreenToScrn(dest_picture->pDrawable->pScreen);
 
        /* Check for unsupported compositing operations. */
        if (op >= sizeof(i965_blend_op) / sizeof(i965_blend_op[0])) {
@@ -219,7 +219,7 @@ Bool
 i965_check_composite_texture(ScreenPtr screen, PicturePtr picture)
 {
        if (picture->repeatType > RepeatReflect) {
-               ScrnInfoPtr scrn = xf86Screens[screen->myNum];
+               ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
                intel_debug_fallback(scrn,
                                     "extended repeat (%d) not supported\n",
                                     picture->repeatType);
@@ -228,7 +228,7 @@ i965_check_composite_texture(ScreenPtr screen, PicturePtr picture)
 
        if (picture->filter != PictFilterNearest &&
            picture->filter != PictFilterBilinear) {
-               ScrnInfoPtr scrn = xf86Screens[screen->myNum];
+               ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
                intel_debug_fallback(scrn, "Unsupported filter 0x%x\n",
                                     picture->filter);
                return FALSE;
@@ -240,7 +240,7 @@ i965_check_composite_texture(ScreenPtr screen, PicturePtr picture)
                w = picture->pDrawable->width;
                h = picture->pDrawable->height;
                if ((w > 8192) || (h > 8192)) {
-                       ScrnInfoPtr scrn = xf86Screens[screen->myNum];
+                       ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
                        intel_debug_fallback(scrn,
                                             "Picture w/h too large (%dx%d)\n",
                                             w, h);
@@ -255,7 +255,7 @@ i965_check_composite_texture(ScreenPtr screen, PicturePtr picture)
                }
                if (i == sizeof(i965_tex_formats) / sizeof(i965_tex_formats[0]))
                {
-                       ScrnInfoPtr scrn = xf86Screens[screen->myNum];
+                       ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
                        intel_debug_fallback(scrn,
                                             "Unsupported picture format "
                                             "0x%x\n",
@@ -534,18 +534,88 @@ static const uint32_t ps_kernel_masknoca_projective_static_gen6[][4] = {
 #include "exa_wm_write.g6b"
 };
 
+/* programs for GEN7 */
+static const uint32_t ps_kernel_nomask_affine_static_gen7[][4] = {
+#include "exa_wm_src_affine.g7b"
+#include "exa_wm_src_sample_argb.g7b"
+#include "exa_wm_write.g7b"
+};
+
+static const uint32_t ps_kernel_nomask_projective_static_gen7[][4] = {
+#include "exa_wm_src_projective.g7b"
+#include "exa_wm_src_sample_argb.g7b"
+#include "exa_wm_write.g7b"
+};
+
+static const uint32_t ps_kernel_maskca_affine_static_gen7[][4] = {
+#include "exa_wm_src_affine.g7b"
+#include "exa_wm_src_sample_argb.g7b"
+#include "exa_wm_mask_affine.g7b"
+#include "exa_wm_mask_sample_argb.g7b"
+#include "exa_wm_ca.g6b"
+#include "exa_wm_write.g7b"
+};
+
+static const uint32_t ps_kernel_maskca_projective_static_gen7[][4] = {
+#include "exa_wm_src_projective.g7b"
+#include "exa_wm_src_sample_argb.g7b"
+#include "exa_wm_mask_projective.g7b"
+#include "exa_wm_mask_sample_argb.g7b"
+#include "exa_wm_ca.g4b.gen5"
+#include "exa_wm_write.g7b"
+};
+
+static const uint32_t ps_kernel_maskca_srcalpha_affine_static_gen7[][4] = {
+#include "exa_wm_src_affine.g7b"
+#include "exa_wm_src_sample_a.g7b"
+#include "exa_wm_mask_affine.g7b"
+#include "exa_wm_mask_sample_argb.g7b"
+#include "exa_wm_ca_srcalpha.g6b"
+#include "exa_wm_write.g7b"
+};
+
+static const uint32_t ps_kernel_maskca_srcalpha_projective_static_gen7[][4] = {
+#include "exa_wm_src_projective.g7b"
+#include "exa_wm_src_sample_a.g7b"
+#include "exa_wm_mask_projective.g7b"
+#include "exa_wm_mask_sample_argb.g7b"
+#include "exa_wm_ca_srcalpha.g6b"
+#include "exa_wm_write.g7b"
+};
+
+static const uint32_t ps_kernel_masknoca_affine_static_gen7[][4] = {
+#include "exa_wm_src_affine.g7b"
+#include "exa_wm_src_sample_argb.g7b"
+#include "exa_wm_mask_affine.g7b"
+#include "exa_wm_mask_sample_a.g7b"
+#include "exa_wm_noca.g6b"
+#include "exa_wm_write.g7b"
+};
+
+static const uint32_t ps_kernel_masknoca_projective_static_gen7[][4] = {
+#include "exa_wm_src_projective.g7b"
+#include "exa_wm_src_sample_argb.g7b"
+#include "exa_wm_mask_projective.g7b"
+#include "exa_wm_mask_sample_a.g7b"
+#include "exa_wm_noca.g6b"
+#include "exa_wm_write.g7b"
+};
+
+
 typedef enum {
-       SAMPLER_STATE_FILTER_NEAREST,
-       SAMPLER_STATE_FILTER_BILINEAR,
-       FILTER_COUNT
+       SS_INVALID_FILTER = -1,
+       SS_FILTER_NEAREST,
+       SS_FILTER_BILINEAR,
+       FILTER_COUNT,
 } sampler_state_filter_t;
 
 typedef enum {
-       SAMPLER_STATE_EXTEND_NONE,
-       SAMPLER_STATE_EXTEND_REPEAT,
-       SAMPLER_STATE_EXTEND_PAD,
-       SAMPLER_STATE_EXTEND_REFLECT,
-       EXTEND_COUNT
+       SS_INVALID_EXTEND = -1,
+       SS_EXTEND_NONE,
+       SS_EXTEND_REPEAT,
+       SS_EXTEND_PAD,
+       SS_EXTEND_REFLECT,
+       EXTEND_COUNT,
 } sampler_state_extend_t;
 
 typedef enum {
@@ -625,6 +695,25 @@ static const struct wm_kernel_info wm_kernels_gen6[] = {
               ps_kernel_masknoca_projective_static_gen6, TRUE),
 };
 
+static const struct wm_kernel_info wm_kernels_gen7[] = {
+       KERNEL(WM_KERNEL_NOMASK_AFFINE,
+              ps_kernel_nomask_affine_static_gen7, FALSE),
+       KERNEL(WM_KERNEL_NOMASK_PROJECTIVE,
+              ps_kernel_nomask_projective_static_gen7, FALSE),
+       KERNEL(WM_KERNEL_MASKCA_AFFINE,
+              ps_kernel_maskca_affine_static_gen7, TRUE),
+       KERNEL(WM_KERNEL_MASKCA_PROJECTIVE,
+              ps_kernel_maskca_projective_static_gen7, TRUE),
+       KERNEL(WM_KERNEL_MASKCA_SRCALPHA_AFFINE,
+              ps_kernel_maskca_srcalpha_affine_static_gen7, TRUE),
+       KERNEL(WM_KERNEL_MASKCA_SRCALPHA_PROJECTIVE,
+              ps_kernel_maskca_srcalpha_projective_static_gen7, TRUE),
+       KERNEL(WM_KERNEL_MASKNOCA_AFFINE,
+              ps_kernel_masknoca_affine_static_gen7, TRUE),
+       KERNEL(WM_KERNEL_MASKNOCA_PROJECTIVE,
+              ps_kernel_masknoca_projective_static_gen7, TRUE),
+};
+
 #undef KERNEL
 
 typedef struct _brw_cc_unit_state_padded {
@@ -632,10 +721,10 @@ typedef struct _brw_cc_unit_state_padded {
        char pad[64 - sizeof(struct brw_cc_unit_state)];
 } brw_cc_unit_state_padded;
 
-typedef struct brw_surface_state_padded {
-       struct brw_surface_state state;
-       char pad[32 - sizeof(struct brw_surface_state)];
-} brw_surface_state_padded;
+#ifndef MAX
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
+#endif
+#define SURFACE_STATE_PADDED_SIZE ALIGN(MAX(sizeof(struct brw_surface_state), sizeof(struct gen7_surface_state)), 32)
 
 struct gen4_cc_unit_state {
        /* Index by [src_blend][dst_blend] */
@@ -689,13 +778,16 @@ static drm_intel_bo *gen4_create_sf_state(intel_screen_private *intel,
 {
        struct brw_sf_unit_state *sf_state;
        drm_intel_bo *sf_state_bo;
+       int ret;
 
        sf_state_bo = drm_intel_bo_alloc(intel->bufmgr, "gen4 SF state",
                                         sizeof(*sf_state), 4096);
-       drm_intel_bo_map(sf_state_bo, TRUE);
-       sf_state = sf_state_bo->virtual;
+       assert(sf_state_bo);
+
+       ret = drm_intel_bo_map(sf_state_bo, TRUE);
+       assert(ret == 0);
 
-       memset(sf_state, 0, sizeof(*sf_state));
+       sf_state = memset(sf_state_bo->virtual, 0, sizeof(*sf_state));
        sf_state->thread0.grf_reg_count = BRW_GRF_BLOCKS(SF_KERNEL_NUM_GRF);
        sf_state->thread0.kernel_start_pointer =
            intel_emit_reloc(sf_state_bo,
@@ -731,6 +823,7 @@ static drm_intel_bo *gen4_create_sf_state(intel_screen_private *intel,
        drm_intel_bo_unmap(sf_state_bo);
 
        return sf_state_bo;
+       (void)ret;
 }
 
 static drm_intel_bo *sampler_border_color_create(intel_screen_private *intel)
@@ -751,7 +844,7 @@ static drm_intel_bo *sampler_border_color_create(intel_screen_private *intel)
 }
 
 static void
-sampler_state_init(drm_intel_bo * sampler_state_bo,
+gen4_sampler_state_init(drm_intel_bo * sampler_state_bo,
                   struct brw_sampler_state *sampler_state,
                   sampler_state_filter_t filter,
                   sampler_state_extend_t extend,
@@ -773,11 +866,11 @@ sampler_state_init(drm_intel_bo * sampler_state_bo,
 
        switch (filter) {
        default:
-       case SAMPLER_STATE_FILTER_NEAREST:
+       case SS_FILTER_NEAREST:
                sampler_state->ss0.min_filter = BRW_MAPFILTER_NEAREST;
                sampler_state->ss0.mag_filter = BRW_MAPFILTER_NEAREST;
                break;
-       case SAMPLER_STATE_FILTER_BILINEAR:
+       case SS_FILTER_BILINEAR:
                sampler_state->ss0.min_filter = BRW_MAPFILTER_LINEAR;
                sampler_state->ss0.mag_filter = BRW_MAPFILTER_LINEAR;
                break;
@@ -785,22 +878,22 @@ sampler_state_init(drm_intel_bo * sampler_state_bo,
 
        switch (extend) {
        default:
-       case SAMPLER_STATE_EXTEND_NONE:
+       case SS_EXTEND_NONE:
                sampler_state->ss1.r_wrap_mode = BRW_TEXCOORDMODE_CLAMP_BORDER;
                sampler_state->ss1.s_wrap_mode = BRW_TEXCOORDMODE_CLAMP_BORDER;
                sampler_state->ss1.t_wrap_mode = BRW_TEXCOORDMODE_CLAMP_BORDER;
                break;
-       case SAMPLER_STATE_EXTEND_REPEAT:
+       case SS_EXTEND_REPEAT:
                sampler_state->ss1.r_wrap_mode = BRW_TEXCOORDMODE_WRAP;
                sampler_state->ss1.s_wrap_mode = BRW_TEXCOORDMODE_WRAP;
                sampler_state->ss1.t_wrap_mode = BRW_TEXCOORDMODE_WRAP;
                break;
-       case SAMPLER_STATE_EXTEND_PAD:
+       case SS_EXTEND_PAD:
                sampler_state->ss1.r_wrap_mode = BRW_TEXCOORDMODE_CLAMP;
                sampler_state->ss1.s_wrap_mode = BRW_TEXCOORDMODE_CLAMP;
                sampler_state->ss1.t_wrap_mode = BRW_TEXCOORDMODE_CLAMP;
                break;
-       case SAMPLER_STATE_EXTEND_REFLECT:
+       case SS_EXTEND_REFLECT:
                sampler_state->ss1.r_wrap_mode = BRW_TEXCOORDMODE_MIRROR;
                sampler_state->ss1.s_wrap_mode = BRW_TEXCOORDMODE_MIRROR;
                sampler_state->ss1.t_wrap_mode = BRW_TEXCOORDMODE_MIRROR;
@@ -816,6 +909,74 @@ sampler_state_init(drm_intel_bo * sampler_state_bo,
        sampler_state->ss3.chroma_key_enable = 0;       /* disable chromakey */
 }
 
+static void
+gen7_sampler_state_init(drm_intel_bo * sampler_state_bo,
+                  struct gen7_sampler_state *sampler_state,
+                  sampler_state_filter_t filter,
+                  sampler_state_extend_t extend,
+                  drm_intel_bo * border_color_bo)
+{
+       uint32_t sampler_state_offset;
+
+       sampler_state_offset = (char *)sampler_state -
+           (char *)sampler_state_bo->virtual;
+
+       /* PS kernel use this sampler */
+       memset(sampler_state, 0, sizeof(*sampler_state));
+
+       sampler_state->ss0.lod_preclamp = 1;    /* GL mode */
+
+       /* We use the legacy mode to get the semantics specified by
+        * the Render extension. */
+       sampler_state->ss0.default_color_mode = BRW_BORDER_COLOR_MODE_LEGACY;
+
+       switch (filter) {
+       default:
+       case SS_FILTER_NEAREST:
+               sampler_state->ss0.min_filter = BRW_MAPFILTER_NEAREST;
+               sampler_state->ss0.mag_filter = BRW_MAPFILTER_NEAREST;
+               break;
+       case SS_FILTER_BILINEAR:
+               sampler_state->ss0.min_filter = BRW_MAPFILTER_LINEAR;
+               sampler_state->ss0.mag_filter = BRW_MAPFILTER_LINEAR;
+               break;
+       }
+
+       switch (extend) {
+       default:
+       case SS_EXTEND_NONE:
+               sampler_state->ss3.r_wrap_mode = BRW_TEXCOORDMODE_CLAMP_BORDER;
+               sampler_state->ss3.s_wrap_mode = BRW_TEXCOORDMODE_CLAMP_BORDER;
+               sampler_state->ss3.t_wrap_mode = BRW_TEXCOORDMODE_CLAMP_BORDER;
+               break;
+       case SS_EXTEND_REPEAT:
+               sampler_state->ss3.r_wrap_mode = BRW_TEXCOORDMODE_WRAP;
+               sampler_state->ss3.s_wrap_mode = BRW_TEXCOORDMODE_WRAP;
+               sampler_state->ss3.t_wrap_mode = BRW_TEXCOORDMODE_WRAP;
+               break;
+       case SS_EXTEND_PAD:
+               sampler_state->ss3.r_wrap_mode = BRW_TEXCOORDMODE_CLAMP;
+               sampler_state->ss3.s_wrap_mode = BRW_TEXCOORDMODE_CLAMP;
+               sampler_state->ss3.t_wrap_mode = BRW_TEXCOORDMODE_CLAMP;
+               break;
+       case SS_EXTEND_REFLECT:
+               sampler_state->ss3.r_wrap_mode = BRW_TEXCOORDMODE_MIRROR;
+               sampler_state->ss3.s_wrap_mode = BRW_TEXCOORDMODE_MIRROR;
+               sampler_state->ss3.t_wrap_mode = BRW_TEXCOORDMODE_MIRROR;
+               break;
+       }
+
+       sampler_state->ss2.default_color_pointer =
+           intel_emit_reloc(sampler_state_bo, sampler_state_offset +
+                            offsetof(struct gen7_sampler_state, ss2),
+                            border_color_bo, 0,
+                            I915_GEM_DOMAIN_SAMPLER, 0) >> 5;
+
+       sampler_state->ss3.chroma_key_enable = 0;       /* disable chromakey */
+}
+
+
+
 static drm_intel_bo *gen4_create_sampler_state(intel_screen_private *intel,
                                               sampler_state_filter_t src_filter,
                                               sampler_state_extend_t src_extend,
@@ -825,25 +986,84 @@ static drm_intel_bo *gen4_create_sampler_state(intel_screen_private *intel,
 {
        drm_intel_bo *sampler_state_bo;
        struct brw_sampler_state *sampler_state;
+       int ret;
 
        sampler_state_bo =
            drm_intel_bo_alloc(intel->bufmgr, "gen4 sampler state",
                               sizeof(struct brw_sampler_state) * 2, 4096);
-       drm_intel_bo_map(sampler_state_bo, TRUE);
+       assert(sampler_state_bo);
+
+       ret = drm_intel_bo_map(sampler_state_bo, TRUE);
+       assert(ret == 0);
+
+       sampler_state = sampler_state_bo->virtual;
+
+       gen4_sampler_state_init(sampler_state_bo,
+                               &sampler_state[0],
+                               src_filter, src_extend, border_color_bo);
+       gen4_sampler_state_init(sampler_state_bo,
+                               &sampler_state[1],
+                               mask_filter, mask_extend, border_color_bo);
+
+       drm_intel_bo_unmap(sampler_state_bo);
+
+       return sampler_state_bo;
+       (void)ret;
+}
+
+static drm_intel_bo *
+gen7_create_sampler_state(intel_screen_private *intel,
+                         sampler_state_filter_t src_filter,
+                         sampler_state_extend_t src_extend,
+                         sampler_state_filter_t mask_filter,
+                         sampler_state_extend_t mask_extend,
+                         drm_intel_bo * border_color_bo)
+{
+       drm_intel_bo *sampler_state_bo;
+       struct gen7_sampler_state *sampler_state;
+       int ret;
+
+       sampler_state_bo =
+           drm_intel_bo_alloc(intel->bufmgr, "gen7 sampler state",
+                              sizeof(struct gen7_sampler_state) * 2, 4096);
+       assert(sampler_state_bo);
+
+       ret = drm_intel_bo_map(sampler_state_bo, TRUE);
+       assert(ret == 0);
+
        sampler_state = sampler_state_bo->virtual;
 
-       sampler_state_init(sampler_state_bo,
-                          &sampler_state[0],
-                          src_filter, src_extend, border_color_bo);
-       sampler_state_init(sampler_state_bo,
-                          &sampler_state[1],
-                          mask_filter, mask_extend, border_color_bo);
+       gen7_sampler_state_init(sampler_state_bo,
+                               &sampler_state[0],
+                               src_filter, src_extend, border_color_bo);
+       gen7_sampler_state_init(sampler_state_bo,
+                               &sampler_state[1],
+                               mask_filter, mask_extend, border_color_bo);
 
        drm_intel_bo_unmap(sampler_state_bo);
 
        return sampler_state_bo;
+       (void)ret;
 }
 
+static inline drm_intel_bo *
+i965_create_sampler_state(intel_screen_private *intel,
+                         sampler_state_filter_t src_filter,
+                         sampler_state_extend_t src_extend,
+                         sampler_state_filter_t mask_filter,
+                         sampler_state_extend_t mask_extend,
+                         drm_intel_bo * border_color_bo)
+{
+       if (INTEL_INFO(intel)->gen < 70)
+               return gen4_create_sampler_state(intel, src_filter, src_extend,
+                                                mask_filter, mask_extend,
+                                                border_color_bo);
+       return gen7_create_sampler_state(intel, src_filter, src_extend,
+                                        mask_filter, mask_extend,
+                                        border_color_bo);
+}
+
+
 static void
 cc_state_init(drm_intel_bo * cc_state_bo,
              uint32_t cc_state_offset,
@@ -892,13 +1112,16 @@ static drm_intel_bo *gen4_create_wm_state(intel_screen_private *intel,
 {
        struct brw_wm_unit_state *state;
        drm_intel_bo *wm_state_bo;
+       int ret;
 
        wm_state_bo = drm_intel_bo_alloc(intel->bufmgr, "gen4 WM state",
                                         sizeof(*state), 4096);
-       drm_intel_bo_map(wm_state_bo, TRUE);
-       state = wm_state_bo->virtual;
+       assert(wm_state_bo);
+
+       ret = drm_intel_bo_map(wm_state_bo, TRUE);
+       assert(ret == 0);
 
-       memset(state, 0, sizeof(*state));
+       state = memset(wm_state_bo->virtual, 0, sizeof(*state));
        state->thread0.grf_reg_count = BRW_GRF_BLOCKS(PS_KERNEL_NUM_GRF);
        state->thread0.kernel_start_pointer =
            intel_emit_reloc(wm_state_bo,
@@ -958,21 +1181,27 @@ static drm_intel_bo *gen4_create_wm_state(intel_screen_private *intel,
        drm_intel_bo_unmap(wm_state_bo);
 
        return wm_state_bo;
+       (void)ret;
 }
 
 static drm_intel_bo *gen4_create_cc_viewport(intel_screen_private *intel)
 {
        drm_intel_bo *bo;
        struct brw_cc_viewport vp;
+       int ret;
 
        vp.min_depth = -1.e35;
        vp.max_depth = 1.e35;
 
        bo = drm_intel_bo_alloc(intel->bufmgr, "gen4 render unit state",
                                sizeof(vp), 4096);
-       drm_intel_bo_subdata(bo, 0, sizeof(vp), &vp);
+       assert(bo);
+
+       ret = drm_intel_bo_subdata(bo, 0, sizeof(vp), &vp);
+       assert(ret == 0);
 
        return bo;
+       (void)ret;
 }
 
 static drm_intel_bo *gen4_create_vs_unit_state(intel_screen_private *intel)
@@ -1000,14 +1229,18 @@ static drm_intel_bo *gen4_create_vs_unit_state(intel_screen_private *intel)
 static drm_intel_bo *gen4_create_cc_unit_state(intel_screen_private *intel)
 {
        drm_intel_bo *cc_state_bo, *cc_vp_bo;
-       int i, j;
+       int i, j, ret;
 
        cc_vp_bo = gen4_create_cc_viewport(intel);
 
        cc_state_bo = drm_intel_bo_alloc(intel->bufmgr, "gen4 CC state",
                                         sizeof(struct gen4_cc_unit_state),
                                         4096);
-       drm_intel_bo_map(cc_state_bo, TRUE);
+       assert(cc_state_bo);
+
+       ret = drm_intel_bo_map(cc_state_bo, TRUE);
+       assert(ret == 0);
+
        for (i = 0; i < BRW_BLENDFACTOR_COUNT; i++) {
                for (j = 0; j < BRW_BLENDFACTOR_COUNT; j++) {
                        cc_state_init(cc_state_bo,
@@ -1021,6 +1254,7 @@ static drm_intel_bo *gen4_create_cc_unit_state(intel_screen_private *intel)
        drm_intel_bo_unreference(cc_vp_bo);
 
        return cc_state_bo;
+       (void)ret;
 }
 
 static uint32_t i965_get_card_format(PicturePtr picture)
@@ -1041,11 +1275,11 @@ static sampler_state_filter_t sampler_state_filter_from_picture(int filter)
 {
        switch (filter) {
        case PictFilterNearest:
-               return SAMPLER_STATE_FILTER_NEAREST;
+               return SS_FILTER_NEAREST;
        case PictFilterBilinear:
-               return SAMPLER_STATE_FILTER_BILINEAR;
+               return SS_FILTER_BILINEAR;
        default:
-               return -1;
+               return SS_INVALID_FILTER;
        }
 }
 
@@ -1053,15 +1287,15 @@ static sampler_state_extend_t sampler_state_extend_from_picture(int repeat_type)
 {
        switch (repeat_type) {
        case RepeatNone:
-               return SAMPLER_STATE_EXTEND_NONE;
+               return SS_EXTEND_NONE;
        case RepeatNormal:
-               return SAMPLER_STATE_EXTEND_REPEAT;
+               return SS_EXTEND_REPEAT;
        case RepeatPad:
-               return SAMPLER_STATE_EXTEND_PAD;
+               return SS_EXTEND_PAD;
        case RepeatReflect:
-               return SAMPLER_STATE_EXTEND_REFLECT;
+               return SS_EXTEND_REFLECT;
        default:
-               return -1;
+               return SS_INVALID_EXTEND;
        }
 }
 
@@ -1070,7 +1304,7 @@ static sampler_state_extend_t sampler_state_extend_from_picture(int repeat_type)
  * picture in the given surface state buffer.
  */
 static int
-i965_set_picture_surface_state(intel_screen_private *intel,
+gen4_set_picture_surface_state(intel_screen_private *intel,
                               PicturePtr picture, PixmapPtr pixmap,
                               Bool is_dst)
 {
@@ -1088,14 +1322,6 @@ i965_set_picture_surface_state(intel_screen_private *intel,
        }
        intel_batch_mark_pixmap_domains(intel, priv,
                                        read_domains, write_domain);
-       if (is_dst) {
-               if (priv->dst_bound)
-                       return priv->dst_bound;
-       } else {
-               if (priv->src_bound)
-                       return priv->src_bound;
-       }
-
        ss = (struct brw_surface_state *)
                (intel->surface_data + intel->surface_used);
 
@@ -1124,16 +1350,78 @@ i965_set_picture_surface_state(intel_screen_private *intel,
                          priv->bo);
 
        offset = intel->surface_used;
-       intel->surface_used += sizeof(struct brw_surface_state_padded);
+       intel->surface_used += SURFACE_STATE_PADDED_SIZE;
 
+       return offset;
+}
+
+static int
+gen7_set_picture_surface_state(intel_screen_private *intel,
+                              PicturePtr picture, PixmapPtr pixmap,
+                              Bool is_dst)
+{
+       struct intel_pixmap *priv = intel_get_pixmap_private(pixmap);
+       struct gen7_surface_state *ss;
+       uint32_t write_domain, read_domains;
+       int offset;
+
+       if (is_dst) {
+               write_domain = I915_GEM_DOMAIN_RENDER;
+               read_domains = I915_GEM_DOMAIN_RENDER;
+       } else {
+               write_domain = 0;
+               read_domains = I915_GEM_DOMAIN_SAMPLER;
+       }
+       intel_batch_mark_pixmap_domains(intel, priv,
+                                       read_domains, write_domain);
+       ss = (struct gen7_surface_state *)
+               (intel->surface_data + intel->surface_used);
+
+       memset(ss, 0, sizeof(*ss));
+       ss->ss0.surface_type = BRW_SURFACE_2D;
        if (is_dst)
-               priv->dst_bound = offset;
+               ss->ss0.surface_format = i965_get_dest_format(picture);
        else
-               priv->src_bound = offset;
+               ss->ss0.surface_format = i965_get_card_format(picture);
+
+       ss->ss0.tile_walk = 0;  /* Tiled X */
+       ss->ss0.tiled_surface = intel_pixmap_tiled(pixmap) ? 1 : 0;
+       ss->ss1.base_addr = priv->bo->offset;
+
+       ss->ss2.height = pixmap->drawable.height - 1;
+       ss->ss2.width = pixmap->drawable.width - 1;
+       ss->ss3.pitch = intel_pixmap_pitch(pixmap) - 1;
+
+       if (IS_HSW(intel)) {
+               ss->ss7.shader_chanel_select_r = HSW_SCS_RED;
+               ss->ss7.shader_chanel_select_g = HSW_SCS_GREEN;
+               ss->ss7.shader_chanel_select_b = HSW_SCS_BLUE;
+               ss->ss7.shader_chanel_select_a = HSW_SCS_ALPHA;
+       }
+
+       dri_bo_emit_reloc(intel->surface_bo,
+                         read_domains, write_domain,
+                         0,
+                         intel->surface_used +
+                         offsetof(struct gen7_surface_state, ss1),
+                         priv->bo);
+
+       offset = intel->surface_used;
+       intel->surface_used += SURFACE_STATE_PADDED_SIZE;
 
        return offset;
 }
 
+static inline int
+i965_set_picture_surface_state(intel_screen_private *intel,
+                              PicturePtr picture, PixmapPtr pixmap,
+                              Bool is_dst)
+{
+    if (INTEL_INFO(intel)->gen < 70)
+        return gen4_set_picture_surface_state(intel, picture, pixmap, is_dst);
+    return gen7_set_picture_surface_state(intel, picture, pixmap, is_dst);
+}
+
 static void gen4_composite_vertex_elements(struct intel_screen_private *intel)
 {
        struct gen4_render_state *render_state = intel->gen4_render_state;
@@ -1473,11 +1761,12 @@ static Bool i965_composite_check_aperture(intel_screen_private *intel)
 
 static void i965_surface_flush(struct intel_screen_private *intel)
 {
-       struct intel_pixmap *priv;
+       int ret;
 
-       drm_intel_bo_subdata(intel->surface_bo,
-                            0, intel->surface_used,
-                            intel->surface_data);
+       ret = drm_intel_bo_subdata(intel->surface_bo,
+                                  0, intel->surface_used,
+                                  intel->surface_data);
+       assert(ret == 0);
        intel->surface_used = 0;
 
        assert (intel->surface_reloc != 0);
@@ -1491,9 +1780,10 @@ static void i965_surface_flush(struct intel_screen_private *intel)
        intel->surface_bo =
                drm_intel_bo_alloc(intel->bufmgr, "surface data",
                                   sizeof(intel->surface_data), 4096);
+       assert(intel->surface_bo);
 
-       list_foreach_entry(priv, struct intel_pixmap, &intel->batch_pixmaps, batch)
-               priv->dst_bound = priv->src_bound = 0;
+       return;
+       (void)ret;
 }
 
 static void
@@ -1601,47 +1891,45 @@ i965_emit_composite_primitive(intel_screen_private *intel,
        float src_x[3], src_y[3], src_w[3], mask_x[3], mask_y[3], mask_w[3];
        Bool is_affine = intel->gen4_render_state->composite_op.is_affine;
 
-       if (! intel->render_source_is_solid) {
-               if (is_affine) {
-                       if (!intel_get_transformed_coordinates(srcX, srcY,
-                                                             intel->transform[0],
-                                                             &src_x[0],
-                                                             &src_y[0]))
-                               return;
-
-                       if (!intel_get_transformed_coordinates(srcX, srcY + h,
-                                                             intel->transform[0],
-                                                             &src_x[1],
-                                                             &src_y[1]))
-                               return;
-
-                       if (!intel_get_transformed_coordinates(srcX + w, srcY + h,
-                                                             intel->transform[0],
-                                                             &src_x[2],
-                                                             &src_y[2]))
-                               return;
-               } else {
-                       if (!intel_get_transformed_coordinates_3d(srcX, srcY,
-                                                                intel->transform[0],
-                                                                &src_x[0],
-                                                                &src_y[0],
-                                                                &src_w[0]))
-                               return;
-
-                       if (!intel_get_transformed_coordinates_3d(srcX, srcY + h,
-                                                                intel->transform[0],
-                                                                &src_x[1],
-                                                                &src_y[1],
-                                                                &src_w[1]))
-                               return;
-
-                       if (!intel_get_transformed_coordinates_3d(srcX + w, srcY + h,
-                                                                intel->transform[0],
-                                                                &src_x[2],
-                                                                &src_y[2],
-                                                                &src_w[2]))
-                               return;
-               }
+       if (is_affine) {
+               if (!intel_get_transformed_coordinates(srcX, srcY,
+                                                      intel->transform[0],
+                                                      &src_x[0],
+                                                      &src_y[0]))
+                       return;
+
+               if (!intel_get_transformed_coordinates(srcX, srcY + h,
+                                                      intel->transform[0],
+                                                      &src_x[1],
+                                                      &src_y[1]))
+                       return;
+
+               if (!intel_get_transformed_coordinates(srcX + w, srcY + h,
+                                                      intel->transform[0],
+                                                      &src_x[2],
+                                                      &src_y[2]))
+                       return;
+       } else {
+               if (!intel_get_transformed_coordinates_3d(srcX, srcY,
+                                                         intel->transform[0],
+                                                         &src_x[0],
+                                                         &src_y[0],
+                                                         &src_w[0]))
+                       return;
+
+               if (!intel_get_transformed_coordinates_3d(srcX, srcY + h,
+                                                         intel->transform[0],
+                                                         &src_x[1],
+                                                         &src_y[1],
+                                                         &src_w[1]))
+                       return;
+
+               if (!intel_get_transformed_coordinates_3d(srcX + w, srcY + h,
+                                                         intel->transform[0],
+                                                         &src_x[2],
+                                                         &src_y[2],
+                                                         &src_w[2]))
+                       return;
        }
 
        if (intel->render_mask) {
@@ -1732,21 +2020,21 @@ i965_prepare_composite(int op, PicturePtr source_picture,
                       PicturePtr mask_picture, PicturePtr dest_picture,
                       PixmapPtr source, PixmapPtr mask, PixmapPtr dest)
 {
-       ScrnInfoPtr scrn = xf86Screens[dest_picture->pDrawable->pScreen->myNum];
+       ScrnInfoPtr scrn = xf86ScreenToScrn(dest_picture->pDrawable->pScreen);
        intel_screen_private *intel = intel_get_screen_private(scrn);
        struct gen4_render_state *render_state = intel->gen4_render_state;
        gen4_composite_op *composite_op = &render_state->composite_op;
 
        composite_op->src_filter =
            sampler_state_filter_from_picture(source_picture->filter);
-       if (composite_op->src_filter < 0) {
+       if (composite_op->src_filter == SS_INVALID_FILTER) {
                intel_debug_fallback(scrn, "Bad src filter 0x%x\n",
                                     source_picture->filter);
                return FALSE;
        }
        composite_op->src_extend =
            sampler_state_extend_from_picture(source_picture->repeatType);
-       if (composite_op->src_extend < 0) {
+       if (composite_op->src_extend == SS_INVALID_EXTEND) {
                intel_debug_fallback(scrn, "Bad src repeat 0x%x\n",
                                     source_picture->repeatType);
                return FALSE;
@@ -1771,26 +2059,25 @@ i965_prepare_composite(int op, PicturePtr source_picture,
 
                composite_op->mask_filter =
                    sampler_state_filter_from_picture(mask_picture->filter);
-               if (composite_op->mask_filter < 0) {
+               if (composite_op->mask_filter == SS_INVALID_FILTER) {
                        intel_debug_fallback(scrn, "Bad mask filter 0x%x\n",
                                             mask_picture->filter);
                        return FALSE;
                }
                composite_op->mask_extend =
                    sampler_state_extend_from_picture(mask_picture->repeatType);
-               if (composite_op->mask_extend < 0) {
+               if (composite_op->mask_extend == SS_INVALID_EXTEND) {
                        intel_debug_fallback(scrn, "Bad mask repeat 0x%x\n",
                                             mask_picture->repeatType);
                        return FALSE;
                }
        } else {
-               composite_op->mask_filter = SAMPLER_STATE_FILTER_NEAREST;
-               composite_op->mask_extend = SAMPLER_STATE_EXTEND_NONE;
+               composite_op->mask_filter = SS_FILTER_NEAREST;
+               composite_op->mask_extend = SS_EXTEND_NONE;
        }
 
        /* Flush any pending writes prior to relocating the textures. */
-       if (intel_pixmap_is_dirty(source) ||
-           (mask && intel_pixmap_is_dirty(mask)))
+       if (intel_pixmap_is_dirty(source) || intel_pixmap_is_dirty(mask))
                intel_batch_emit_flush(scrn);
 
        composite_op->op = op;
@@ -1807,11 +2094,12 @@ i965_prepare_composite(int op, PicturePtr source_picture,
        intel->transform[0] = source_picture->transform;
        composite_op->is_affine = intel_transform_is_affine(intel->transform[0]);
 
-       if (!mask) {
+       if (mask_picture == NULL) {
                intel->transform[1] = NULL;
                intel->scale_units[1][0] = -1;
                intel->scale_units[1][1] = -1;
        } else {
+               assert(mask != NULL);
                intel->transform[1] = mask_picture->transform;
                intel->scale_units[1][0] = 1. / mask->drawable.width;
                intel->scale_units[1][1] = 1. / mask->drawable.height;
@@ -1877,7 +2165,7 @@ i965_prepare_composite(int op, PicturePtr source_picture,
        }
 
        if (sizeof(intel->surface_data) - intel->surface_used <
-           4 * sizeof(struct brw_surface_state_padded))
+           4 * SURFACE_STATE_PADDED_SIZE)
                i965_surface_flush(intel);
 
        intel->needs_render_state_emit = TRUE;
@@ -1888,10 +2176,14 @@ i965_prepare_composite(int op, PicturePtr source_picture,
 static void i965_select_vertex_buffer(struct intel_screen_private *intel)
 {
        int id = intel->gen4_render_state->composite_op.vertex_id;
+       int modifyenable = 0;
 
        if (intel->vertex_id & (1 << id))
                return;
 
+       if (INTEL_INFO(intel)->gen >= 70)
+               modifyenable = GEN7_VB0_ADDRESS_MODIFYENABLE;
+
        /* Set up the pointer to our (single) vertex buffer */
        OUT_BATCH(BRW_3DSTATE_VERTEX_BUFFERS | 3);
 
@@ -1901,6 +2193,7 @@ static void i965_select_vertex_buffer(struct intel_screen_private *intel)
        if (INTEL_INFO(intel)->gen >= 60) {
                OUT_BATCH((id << GEN6_VB0_BUFFER_INDEX_SHIFT) |
                          GEN6_VB0_VERTEXDATA |
+                         modifyenable |
                          (4*intel->floats_per_vertex << VB0_BUFFER_PITCH_SHIFT));
        } else {
                OUT_BATCH((id << VB0_BUFFER_INDEX_SHIFT) |
@@ -1923,11 +2216,11 @@ static void i965_bind_surfaces(struct intel_screen_private *intel)
 {
        uint32_t *binding_table;
 
-       assert(intel->surface_used + 4 * sizeof(struct brw_surface_state_padded) <= sizeof(intel->surface_data));
+       assert(intel->surface_used + 4 * SURFACE_STATE_PADDED_SIZE <= sizeof(intel->surface_data));
 
        binding_table = (uint32_t*) (intel->surface_data + intel->surface_used);
        intel->surface_table = intel->surface_used;
-       intel->surface_used += sizeof(struct brw_surface_state_padded);
+       intel->surface_used += SURFACE_STATE_PADDED_SIZE;
 
        binding_table[0] =
                i965_set_picture_surface_state(intel,
@@ -1952,7 +2245,7 @@ void
 i965_composite(PixmapPtr dest, int srcX, int srcY, int maskX, int maskY,
               int dstX, int dstY, int w, int h)
 {
-       ScrnInfoPtr scrn = xf86Screens[dest->drawable.pScreen->myNum];
+       ScrnInfoPtr scrn = xf86ScreenToScrn(dest->drawable.pScreen);
        intel_screen_private *intel = intel_get_screen_private(scrn);
 
        intel_batch_start_atomic(scrn, 200);
@@ -1978,11 +2271,17 @@ i965_composite(PixmapPtr dest, int srcX, int srcY, int maskX, int maskY,
        i965_select_vertex_buffer(intel);
 
        if (intel->vertex_offset == 0) {
-               OUT_BATCH(BRW_3DPRIMITIVE |
-                         BRW_3DPRIMITIVE_VERTEX_SEQUENTIAL |
-                         (_3DPRIM_RECTLIST << BRW_3DPRIMITIVE_TOPOLOGY_SHIFT) |
-                         (0 << 9) |
-                         4);
+               if (INTEL_INFO(intel)->gen >= 70) {
+                       OUT_BATCH(BRW_3DPRIMITIVE | (7 - 2));
+                       OUT_BATCH(BRW_3DPRIMITIVE_VERTEX_SEQUENTIAL |
+                                 _3DPRIM_RECTLIST);
+               } else {
+                       OUT_BATCH(BRW_3DPRIMITIVE |
+                                 BRW_3DPRIMITIVE_VERTEX_SEQUENTIAL |
+                                 (_3DPRIM_RECTLIST << BRW_3DPRIMITIVE_TOPOLOGY_SHIFT) |
+                                 (0 << 9) |
+                                 4);
+               }
                intel->vertex_offset = intel->batch_used;
                OUT_BATCH(0);   /* vertex count, to be filled in later */
                OUT_BATCH(intel->vertex_index);
@@ -2034,19 +2333,27 @@ void gen4_render_state_init(ScrnInfoPtr scrn)
        intel_screen_private *intel = intel_get_screen_private(scrn);
        struct gen4_render_state *render;
        const struct wm_kernel_info *wm_kernels;
-       int i, j, k, l, m;
+       sampler_state_filter_t src_filter;
+       sampler_state_extend_t src_extend;
+       sampler_state_filter_t mask_filter;
+       sampler_state_extend_t mask_extend;
        drm_intel_bo *sf_kernel_bo, *sf_kernel_mask_bo;
        drm_intel_bo *border_color_bo;
+       int m;
 
        intel->needs_3d_invariant = TRUE;
 
        intel->surface_bo =
                drm_intel_bo_alloc(intel->bufmgr, "surface data",
                                   sizeof(intel->surface_data), 4096);
+       assert(intel->surface_bo);
+
        intel->surface_used = 0;
 
-       if (intel->gen4_render_state == NULL)
-               intel->gen4_render_state = calloc(sizeof(*render), 1);
+       if (intel->gen4_render_state == NULL) {
+               intel->gen4_render_state = calloc(1, sizeof(*render));
+               assert(intel->gen4_render_state != NULL);
+       }
 
        if (INTEL_INFO(intel)->gen >= 60)
                return gen6_render_state_init(scrn);
@@ -2096,20 +2403,20 @@ void gen4_render_state_init(ScrnInfoPtr scrn)
         * kernel.
         */
        border_color_bo = sampler_border_color_create(intel);
-       for (i = 0; i < FILTER_COUNT; i++) {
-               for (j = 0; j < EXTEND_COUNT; j++) {
-                       for (k = 0; k < FILTER_COUNT; k++) {
-                               for (l = 0; l < EXTEND_COUNT; l++) {
+       for (src_filter = 0; src_filter < FILTER_COUNT; src_filter++) {
+               for (src_extend = 0; src_extend < EXTEND_COUNT; src_extend++) {
+                       for (mask_filter = 0; mask_filter < FILTER_COUNT; mask_filter++) {
+                               for (mask_extend = 0; mask_extend < EXTEND_COUNT; mask_extend++) {
                                        drm_intel_bo *sampler_state_bo;
 
                                        sampler_state_bo =
-                                           gen4_create_sampler_state(intel,
-                                                                     i, j,
-                                                                     k, l,
+                                           i965_create_sampler_state(intel,
+                                                                     src_filter, src_extend,
+                                                                     mask_filter, mask_extend,
                                                                      border_color_bo);
 
                                        for (m = 0; m < KERNEL_COUNT; m++) {
-                                               render->wm_state_bo[m][i][j][k][l] =
+                                               render->wm_state_bo[m][src_filter][src_extend][mask_filter][mask_extend] =
                                                        gen4_create_wm_state
                                                        (intel,
                                                         wm_kernels[m]. has_mask,
@@ -2179,14 +2486,18 @@ gen6_composite_create_cc_state(intel_screen_private *intel)
 {
        struct gen6_color_calc_state *state;
        drm_intel_bo *cc_bo;
+       int ret;
 
        cc_bo = drm_intel_bo_alloc(intel->bufmgr,
                                "gen6 CC state",
                                sizeof(*state),
                                4096);
-       drm_intel_bo_map(cc_bo, TRUE);
-       state = cc_bo->virtual;
-       memset(state, 0, sizeof(*state));
+       assert(cc_bo);
+
+       ret = drm_intel_bo_map(cc_bo, TRUE);
+       assert(ret == 0);
+
+       state = memset(cc_bo->virtual, 0, sizeof(*state));
        state->constant_r = 1.0;
        state->constant_g = 0.0;
        state->constant_b = 1.0;
@@ -2194,21 +2505,25 @@ gen6_composite_create_cc_state(intel_screen_private *intel)
        drm_intel_bo_unmap(cc_bo);
 
        return cc_bo;
+       (void)ret;
 }
 
 static drm_intel_bo *
 gen6_composite_create_blend_state(intel_screen_private *intel)
 {
        drm_intel_bo *blend_bo;
-       int src, dst;
+       int src, dst, ret;
 
        blend_bo = drm_intel_bo_alloc(intel->bufmgr,
                                "gen6 BLEND state",
                                BRW_BLENDFACTOR_COUNT * BRW_BLENDFACTOR_COUNT * GEN6_BLEND_STATE_PADDED_SIZE,
                                4096);
-       drm_intel_bo_map(blend_bo, TRUE);
-       memset(blend_bo->virtual, 0, blend_bo->size);
+       assert(blend_bo);
 
+       ret = drm_intel_bo_map(blend_bo, TRUE);
+       assert(ret == 0);
+
+       memset(blend_bo->virtual, 0, blend_bo->size);
        for (src = 0; src < BRW_BLENDFACTOR_COUNT; src++) {
                for (dst = 0; dst < BRW_BLENDFACTOR_COUNT; dst++) {
                        uint32_t blend_state_offset = (src * BRW_BLENDFACTOR_COUNT + dst) * GEN6_BLEND_STATE_PADDED_SIZE;
@@ -2227,42 +2542,31 @@ gen6_composite_create_blend_state(intel_screen_private *intel)
 
        drm_intel_bo_unmap(blend_bo);
        return blend_bo;
+       (void)ret;
 }
 
 static drm_intel_bo *
 gen6_composite_create_depth_stencil_state(intel_screen_private *intel)
 {
-       struct gen6_depth_stencil_state *state;
        drm_intel_bo *depth_stencil_bo;
+       int ret;
 
-       depth_stencil_bo = drm_intel_bo_alloc(intel->bufmgr,
-                                       "gen6 DEPTH_STENCIL state",
-                                       sizeof(*state),
-                                       4096);
-       drm_intel_bo_map(depth_stencil_bo, TRUE);
-       state = depth_stencil_bo->virtual;
-       memset(state, 0, sizeof(*state));
-       drm_intel_bo_unmap(depth_stencil_bo);
+       depth_stencil_bo =
+               drm_intel_bo_alloc(intel->bufmgr,
+                                  "gen6 DEPTH_STENCIL state",
+                                  sizeof(struct gen6_depth_stencil_state),
+                                  4096);
+       assert(depth_stencil_bo);
 
-       return depth_stencil_bo;
-}
-
-static void
-gen6_composite_invariant_states(intel_screen_private *intel)
-{
-       OUT_BATCH(NEW_PIPELINE_SELECT | PIPELINE_SELECT_3D);
-
-       OUT_BATCH(GEN6_3DSTATE_MULTISAMPLE | (3 - 2));
-       OUT_BATCH(GEN6_3DSTATE_MULTISAMPLE_PIXEL_LOCATION_CENTER |
-                 GEN6_3DSTATE_MULTISAMPLE_NUMSAMPLES_1); /* 1 sample/pixel */
-       OUT_BATCH(0);
+       ret = drm_intel_bo_map(depth_stencil_bo, TRUE);
+       assert(ret == 0);
 
-       OUT_BATCH(GEN6_3DSTATE_SAMPLE_MASK | (2 - 2));
-       OUT_BATCH(1);
+       memset(depth_stencil_bo->virtual, 0,
+              sizeof(struct gen6_depth_stencil_state));
+       drm_intel_bo_unmap(depth_stencil_bo);
 
-       /* Set system instruction pointer */
-       OUT_BATCH(BRW_STATE_SIP | 0);
-       OUT_BATCH(0);
+       return depth_stencil_bo;
+       (void)ret;
 }
 
 static void
@@ -2283,51 +2587,24 @@ gen6_composite_state_base_address(intel_screen_private *intel)
 }
 
 static void
-gen6_composite_viewport_state_pointers(intel_screen_private *intel,
-                                      drm_intel_bo *cc_vp_bo)
-{
-
-       OUT_BATCH(GEN6_3DSTATE_VIEWPORT_STATE_POINTERS |
-                 GEN6_3DSTATE_VIEWPORT_STATE_MODIFY_CC |
-                 (4 - 2));
-       OUT_BATCH(0);
-       OUT_BATCH(0);
-       OUT_RELOC(cc_vp_bo, I915_GEM_DOMAIN_INSTRUCTION, 0, 0);
-}
-
-static void
-gen6_composite_urb(intel_screen_private *intel)
-{
-       OUT_BATCH(GEN6_3DSTATE_URB | (3 - 2));
-       OUT_BATCH(((1 - 1) << GEN6_3DSTATE_URB_VS_SIZE_SHIFT) |
-                 (24 << GEN6_3DSTATE_URB_VS_ENTRIES_SHIFT)); /* at least 24 on GEN6 */
-       OUT_BATCH((0 << GEN6_3DSTATE_URB_GS_SIZE_SHIFT) |
-               (0 << GEN6_3DSTATE_URB_GS_ENTRIES_SHIFT)); /* no GS thread */
-}
-
-static void
 gen6_composite_cc_state_pointers(intel_screen_private *intel,
                                 uint32_t blend_offset)
 {
        struct gen4_render_state *render_state = intel->gen4_render_state;
+       drm_intel_bo *cc_bo = NULL;
+       drm_intel_bo *depth_stencil_bo = NULL;
 
        if (intel->gen6_render_state.blend == blend_offset)
                return;
 
-       OUT_BATCH(GEN6_3DSTATE_CC_STATE_POINTERS | (4 - 2));
-       OUT_RELOC(render_state->gen6_blend_bo,
-                 I915_GEM_DOMAIN_INSTRUCTION, 0,
-                 blend_offset | 1);
        if (intel->gen6_render_state.blend == -1) {
-               OUT_RELOC(render_state->gen6_depth_stencil_bo,
-                         I915_GEM_DOMAIN_INSTRUCTION, 0,
-                         1);
-               OUT_RELOC(render_state->cc_state_bo,
-                         I915_GEM_DOMAIN_INSTRUCTION, 0,
-                         1);
+               cc_bo = render_state->cc_state_bo;
+               depth_stencil_bo = render_state->gen6_depth_stencil_bo;
+       }
+       if (INTEL_INFO(intel)->gen >= 70) {
+               gen7_upload_cc_state_pointers(intel, render_state->gen6_blend_bo, cc_bo, depth_stencil_bo, blend_offset);
        } else {
-               OUT_BATCH(0);
-               OUT_BATCH(0);
+               gen6_upload_cc_state_pointers(intel, render_state->gen6_blend_bo, cc_bo, depth_stencil_bo, blend_offset);
        }
 
        intel->gen6_render_state.blend = blend_offset;
@@ -2342,69 +2619,26 @@ gen6_composite_sampler_state_pointers(intel_screen_private *intel,
 
        intel->gen6_render_state.samplers = bo;
 
-       OUT_BATCH(GEN6_3DSTATE_SAMPLER_STATE_POINTERS |
-                 GEN6_3DSTATE_SAMPLER_STATE_MODIFY_PS |
-                 (4 - 2));
-       OUT_BATCH(0); /* VS */
-       OUT_BATCH(0); /* GS */
-       OUT_RELOC(bo, I915_GEM_DOMAIN_INSTRUCTION, 0, 0);
-}
-
-static void
-gen6_composite_vs_state(intel_screen_private *intel)
-{
-       /* disable VS constant buffer */
-       OUT_BATCH(GEN6_3DSTATE_CONSTANT_VS | (5 - 2));
-       OUT_BATCH(0);
-       OUT_BATCH(0);
-       OUT_BATCH(0);
-       OUT_BATCH(0);
-
-       OUT_BATCH(GEN6_3DSTATE_VS | (6 - 2));
-       OUT_BATCH(0); /* without VS kernel */
-       OUT_BATCH(0);
-       OUT_BATCH(0);
-       OUT_BATCH(0);
-       OUT_BATCH(0); /* pass-through */
-}
-
-static void
-gen6_composite_gs_state(intel_screen_private *intel)
-{
-       /* disable GS constant buffer */
-       OUT_BATCH(GEN6_3DSTATE_CONSTANT_GS | (5 - 2));
-       OUT_BATCH(0);
-       OUT_BATCH(0);
-       OUT_BATCH(0);
-       OUT_BATCH(0);
-
-       OUT_BATCH(GEN6_3DSTATE_GS | (7 - 2));
-       OUT_BATCH(0); /* without GS kernel */
-       OUT_BATCH(0);
-       OUT_BATCH(0);
-       OUT_BATCH(0);
-       OUT_BATCH(0);
-       OUT_BATCH(0); /* pass-through */
+       if (INTEL_INFO(intel)->gen >= 70)
+               gen7_upload_sampler_state_pointers(intel, bo);
+       else
+               gen6_upload_sampler_state_pointers(intel, bo);
 }
 
 static void
 gen6_composite_wm_constants(intel_screen_private *intel)
 {
+       Bool ivb = INTEL_INFO(intel)->gen >= 70;
        /* disable WM constant buffer */
-       OUT_BATCH(GEN6_3DSTATE_CONSTANT_PS | (5 - 2));
+       OUT_BATCH(GEN6_3DSTATE_CONSTANT_PS | ((ivb ? 7 : 5) - 2));
        OUT_BATCH(0);
        OUT_BATCH(0);
        OUT_BATCH(0);
        OUT_BATCH(0);
-}
-
-static void
-gen6_composite_clip_state(intel_screen_private *intel)
-{
-       OUT_BATCH(GEN6_3DSTATE_CLIP | (4 - 2));
-       OUT_BATCH(0);
-       OUT_BATCH(0); /* pass-through */
-       OUT_BATCH(0);
+       if (ivb) {
+               OUT_BATCH(0);
+               OUT_BATCH(0);
+       }
 }
 
 static void
@@ -2418,28 +2652,10 @@ gen6_composite_sf_state(intel_screen_private *intel,
 
        intel->gen6_render_state.num_sf_outputs = num_sf_outputs;
 
-       OUT_BATCH(GEN6_3DSTATE_SF | (20 - 2));
-       OUT_BATCH((num_sf_outputs << GEN6_3DSTATE_SF_NUM_OUTPUTS_SHIFT) |
-                 (1 << GEN6_3DSTATE_SF_URB_ENTRY_READ_LENGTH_SHIFT) |
-                 (1 << GEN6_3DSTATE_SF_URB_ENTRY_READ_OFFSET_SHIFT));
-       OUT_BATCH(0);
-       OUT_BATCH(GEN6_3DSTATE_SF_CULL_NONE);
-       OUT_BATCH(2 << GEN6_3DSTATE_SF_TRIFAN_PROVOKE_SHIFT); /* DW4 */
-       OUT_BATCH(0);
-       OUT_BATCH(0);
-       OUT_BATCH(0);
-       OUT_BATCH(0);
-       OUT_BATCH(0); /* DW9 */
-       OUT_BATCH(0);
-       OUT_BATCH(0);
-       OUT_BATCH(0);
-       OUT_BATCH(0);
-       OUT_BATCH(0); /* DW14 */
-       OUT_BATCH(0);
-       OUT_BATCH(0);
-       OUT_BATCH(0);
-       OUT_BATCH(0);
-       OUT_BATCH(0); /* DW19 */
+       if (INTEL_INFO(intel)->gen >= 70)
+               gen7_upload_sf_state(intel, num_sf_outputs, 1);
+       else
+               gen6_upload_sf_state(intel, num_sf_outputs, 1);
 }
 
 static void
@@ -2473,34 +2689,43 @@ gen6_composite_wm_state(intel_screen_private *intel,
 }
 
 static void
-gen6_composite_binding_table_pointers(intel_screen_private *intel)
+gen7_composite_wm_state(intel_screen_private *intel,
+                       Bool has_mask,
+                       drm_intel_bo *bo)
 {
-       /* Binding table pointers */
-       OUT_BATCH(BRW_3DSTATE_BINDING_TABLE_POINTERS |
-                 GEN6_3DSTATE_BINDING_TABLE_MODIFY_PS |
-                 (4 - 2));
-       OUT_BATCH(0);           /* vs */
-       OUT_BATCH(0);           /* gs */
-       /* Only the PS uses the binding table */
-       OUT_BATCH(intel->surface_table);
-}
+       int num_surfaces = has_mask ? 3 : 2;
+       unsigned int max_threads_shift = GEN7_PS_MAX_THREADS_SHIFT_IVB;
+       unsigned int num_samples = 0;
 
-static void
-gen6_composite_depth_buffer_state(intel_screen_private *intel)
-{
-       OUT_BATCH(BRW_3DSTATE_DEPTH_BUFFER | (7 - 2));
-       OUT_BATCH((BRW_SURFACE_NULL << BRW_3DSTATE_DEPTH_BUFFER_TYPE_SHIFT) |
-                 (BRW_DEPTHFORMAT_D32_FLOAT << BRW_3DSTATE_DEPTH_BUFFER_FORMAT_SHIFT));
-       OUT_BATCH(0);
-       OUT_BATCH(0);
-       OUT_BATCH(0);
-       OUT_BATCH(0);
-       OUT_BATCH(0);
+       if (IS_HSW(intel)) {
+               max_threads_shift = GEN7_PS_MAX_THREADS_SHIFT_HSW;
+               num_samples = 1 << GEN7_PS_SAMPLE_MASK_SHIFT_HSW;
+       }
+
+       if (intel->gen6_render_state.kernel == bo)
+               return;
+
+       intel->gen6_render_state.kernel = bo;
 
-       OUT_BATCH(BRW_3DSTATE_CLEAR_PARAMS | (2 - 2));
+       OUT_BATCH(GEN6_3DSTATE_WM | (3 - 2));
+       OUT_BATCH(GEN7_WM_DISPATCH_ENABLE |
+                 GEN7_WM_PERSPECTIVE_PIXEL_BARYCENTRIC);
        OUT_BATCH(0);
+
+       OUT_BATCH(GEN7_3DSTATE_PS | (8 - 2));
+       OUT_RELOC(bo, I915_GEM_DOMAIN_INSTRUCTION, 0, 0);
+       OUT_BATCH((1 << GEN7_PS_SAMPLER_COUNT_SHIFT) |
+                 (num_surfaces << GEN7_PS_BINDING_TABLE_ENTRY_COUNT_SHIFT));
+       OUT_BATCH(0); /* scratch space base offset */
+       OUT_BATCH(((48 - 1) << max_threads_shift) | num_samples |
+                 GEN7_PS_ATTRIBUTE_ENABLE |
+                 GEN7_PS_16_DISPATCH_ENABLE);
+       OUT_BATCH((6 << GEN7_PS_DISPATCH_START_GRF_SHIFT_0));
+       OUT_BATCH(0); /* kernel 1 pointer */
+       OUT_BATCH(0); /* kernel 2 pointer */
 }
 
+
 static void
 gen6_composite_drawing_rectangle(intel_screen_private *intel,
                                 PixmapPtr dest)
@@ -2614,21 +2839,30 @@ gen6_emit_composite_state(struct intel_screen_private *intel)
        sampler_state_extend_t mask_extend = composite_op->mask_extend;
        Bool is_affine = composite_op->is_affine;
        Bool has_mask = intel->render_mask != NULL;
+       Bool ivb = INTEL_INFO(intel)->gen >= 70;
        uint32_t src, dst;
        drm_intel_bo *ps_sampler_state_bo = render->ps_sampler_state_bo[src_filter][src_extend][mask_filter][mask_extend];
 
        intel->needs_render_state_emit = FALSE;
        if (intel->needs_3d_invariant) {
-               gen6_composite_invariant_states(intel);
-               gen6_composite_viewport_state_pointers(intel,
-                                                      render->cc_vp_bo);
-               gen6_composite_urb(intel);
-
-               gen6_composite_vs_state(intel);
-               gen6_composite_gs_state(intel);
-               gen6_composite_clip_state(intel);
+               gen6_upload_invariant_states(intel);
+
+               if (ivb) {
+                       gen7_upload_viewport_state_pointers(intel, render->cc_vp_bo);
+                       gen7_upload_urb(intel);
+                       gen7_upload_bypass_states(intel);
+                       gen7_upload_depth_buffer_state(intel);
+               } else {
+                       gen6_upload_invariant_states(intel);
+                       gen6_upload_viewport_state_pointers(intel, render->cc_vp_bo);
+                       gen6_upload_urb(intel);
+
+                       gen6_upload_gs_state(intel);
+                       gen6_upload_depth_buffer_state(intel);
+               }
                gen6_composite_wm_constants(intel);
-               gen6_composite_depth_buffer_state(intel);
+               gen6_upload_vs_state(intel);
+               gen6_upload_clip_state(intel);
 
                intel->needs_3d_invariant = FALSE;
        }
@@ -2645,11 +2879,15 @@ gen6_emit_composite_state(struct intel_screen_private *intel)
                                        (src * BRW_BLENDFACTOR_COUNT + dst) * GEN6_BLEND_STATE_PADDED_SIZE);
        gen6_composite_sampler_state_pointers(intel, ps_sampler_state_bo);
        gen6_composite_sf_state(intel, has_mask);
-       gen6_composite_wm_state(intel,
-                               has_mask,
-                               render->wm_kernel_bo[composite_op->wm_kernel]);
-       gen6_composite_binding_table_pointers(intel);
-
+       if (ivb) {
+               gen7_composite_wm_state(intel, has_mask,
+                                       render->wm_kernel_bo[composite_op->wm_kernel]);
+               gen7_upload_binding_table(intel, intel->surface_table);
+       } else {
+               gen6_composite_wm_state(intel, has_mask,
+                                       render->wm_kernel_bo[composite_op->wm_kernel]);
+               gen6_upload_binding_table(intel, intel->surface_table);
+       }
        gen6_composite_drawing_rectangle(intel, intel->render_dest);
        gen6_composite_vertex_element_state(intel, has_mask, is_affine);
 }
@@ -2659,8 +2897,13 @@ gen6_render_state_init(ScrnInfoPtr scrn)
 {
        intel_screen_private *intel = intel_get_screen_private(scrn);
        struct gen4_render_state *render;
-       int i, j, k, l, m;
+       sampler_state_filter_t src_filter;
+       sampler_state_filter_t mask_filter;
+       sampler_state_extend_t src_extend;
+       sampler_state_extend_t mask_extend;
+       int m;
        drm_intel_bo *border_color_bo;
+       const struct wm_kernel_info *wm_kernels;
 
        render= intel->gen4_render_state;
        render->composite_op.vertex_id = -1;
@@ -2671,24 +2914,25 @@ gen6_render_state_init(ScrnInfoPtr scrn)
        intel->gen6_render_state.kernel = NULL;
        intel->gen6_render_state.drawrect = -1;
 
+       wm_kernels = IS_GEN7(intel) ? wm_kernels_gen7 : wm_kernels_gen6;
        for (m = 0; m < KERNEL_COUNT; m++) {
                render->wm_kernel_bo[m] =
                        intel_bo_alloc_for_data(intel,
-                                       wm_kernels_gen6[m].data,
-                                       wm_kernels_gen6[m].size,
-                                       "WM kernel gen6");
+                                       wm_kernels[m].data,
+                                       wm_kernels[m].size,
+                                       "WM kernel gen6/7");
        }
 
        border_color_bo = sampler_border_color_create(intel);
 
-       for (i = 0; i < FILTER_COUNT; i++) {
-               for (j = 0; j < EXTEND_COUNT; j++) {
-                       for (k = 0; k < FILTER_COUNT; k++) {
-                               for (l = 0; l < EXTEND_COUNT; l++) {
-                                       render->ps_sampler_state_bo[i][j][k][l] =
-                                               gen4_create_sampler_state(intel,
-                                                               i, j,
-                                                               k, l,
+       for (src_filter = 0; src_filter < FILTER_COUNT; src_filter++) {
+               for (src_extend = 0; src_extend < EXTEND_COUNT; src_extend++) {
+                       for (mask_filter = 0; mask_filter < FILTER_COUNT; mask_filter++) {
+                               for (mask_extend = 0; mask_extend < EXTEND_COUNT; mask_extend++) {
+                                       render->ps_sampler_state_bo[src_filter][src_extend][mask_filter][mask_extend] =
+                                               i965_create_sampler_state(intel,
+                                                                         src_filter, src_extend,
+                                                                         mask_filter, mask_extend,
                                                                border_color_bo);
                                }
                        }
index c757681..3276788 100644 (file)
@@ -149,6 +149,30 @@ static const uint32_t ps_kernel_planar_static_gen6[][4] = {
 #include "exa_wm_write.g6b"
 };
 
+/* programs for Ivybridge */
+static const uint32_t ps_kernel_packed_static_gen7[][4] = {
+#include "exa_wm_src_affine.g7b"
+#include "exa_wm_src_sample_argb.g7b"
+#include "exa_wm_yuv_rgb.g7b"
+#include "exa_wm_write.g7b"
+};
+
+static const uint32_t ps_kernel_planar_static_gen7[][4] = {
+#include "exa_wm_src_affine.g7b"
+#include "exa_wm_src_sample_planar.g7b"
+#include "exa_wm_yuv_rgb.g7b"
+#include "exa_wm_write.g7b"
+};
+
+#ifndef MAX2
+#define MAX2(a,b) ((a) > (b) ? (a) : (b))
+#endif
+
+#define SURFACE_STATE_PADDED_SIZE_I965  ALIGN(sizeof(struct brw_surface_state), 32)
+#define SURFACE_STATE_PADDED_SIZE_GEN7  ALIGN(sizeof(struct gen7_surface_state), 32)
+#define SURFACE_STATE_PADDED_SIZE       MAX2(SURFACE_STATE_PADDED_SIZE_I965, SURFACE_STATE_PADDED_SIZE_GEN7)
+#define SURFACE_STATE_OFFSET(index)     (SURFACE_STATE_PADDED_SIZE * index)
+
 static uint32_t float_to_uint(float f)
 {
        union {
@@ -356,73 +380,53 @@ static void i965_post_draw_debug(ScrnInfoPtr scrn)
 #define URB_CS_ENTRIES       0
 #define URB_CS_ENTRY_SIZE     0
 
-static int
-intel_alloc_and_map(intel_screen_private *intel, char *name, int size,
-                   drm_intel_bo ** bop, void *virtualp)
-{
-       drm_intel_bo *bo;
-
-       bo = drm_intel_bo_alloc(intel->bufmgr, name, size, 4096);
-       if (!bo)
-               return -1;
-       if (drm_intel_bo_map(bo, TRUE) != 0) {
-               drm_intel_bo_unreference(bo);
-               return -1;
-       }
-       *bop = bo;
-       *(void **)virtualp = bo->virtual;
-       memset(bo->virtual, 0, size);
-       return 0;
-}
-
 static void i965_create_dst_surface_state(ScrnInfoPtr scrn,
                                        PixmapPtr pixmap,
                                        drm_intel_bo *surf_bo,
                                        uint32_t offset)
 {
        intel_screen_private *intel = intel_get_screen_private(scrn);
-       struct brw_surface_state *dest_surf_state;
+       struct brw_surface_state dest_surf_state;
        drm_intel_bo *pixmap_bo = intel_get_pixmap_bo(pixmap);
+       assert(pixmap_bo != NULL);
 
-       if (drm_intel_bo_map(surf_bo, TRUE) != 0)
-               return;
-
-       dest_surf_state = (struct brw_surface_state *)((char *)surf_bo->virtual + offset);
-       memset(dest_surf_state, 0, sizeof(*dest_surf_state));
+       memset(&dest_surf_state, 0, sizeof(dest_surf_state));
 
-       dest_surf_state->ss0.surface_type = BRW_SURFACE_2D;
-       dest_surf_state->ss0.data_return_format =
+       dest_surf_state.ss0.surface_type = BRW_SURFACE_2D;
+       dest_surf_state.ss0.data_return_format =
            BRW_SURFACERETURNFORMAT_FLOAT32;
        if (intel->cpp == 2) {
-               dest_surf_state->ss0.surface_format =
+               dest_surf_state.ss0.surface_format =
                    BRW_SURFACEFORMAT_B5G6R5_UNORM;
        } else {
-               dest_surf_state->ss0.surface_format =
+               dest_surf_state.ss0.surface_format =
                    BRW_SURFACEFORMAT_B8G8R8A8_UNORM;
        }
-       dest_surf_state->ss0.writedisable_alpha = 0;
-       dest_surf_state->ss0.writedisable_red = 0;
-       dest_surf_state->ss0.writedisable_green = 0;
-       dest_surf_state->ss0.writedisable_blue = 0;
-       dest_surf_state->ss0.color_blend = 1;
-       dest_surf_state->ss0.vert_line_stride = 0;
-       dest_surf_state->ss0.vert_line_stride_ofs = 0;
-       dest_surf_state->ss0.mipmap_layout_mode = 0;
-       dest_surf_state->ss0.render_cache_read_mode = 0;
-
-       dest_surf_state->ss1.base_addr =
+       dest_surf_state.ss0.writedisable_alpha = 0;
+       dest_surf_state.ss0.writedisable_red = 0;
+       dest_surf_state.ss0.writedisable_green = 0;
+       dest_surf_state.ss0.writedisable_blue = 0;
+       dest_surf_state.ss0.color_blend = 1;
+       dest_surf_state.ss0.vert_line_stride = 0;
+       dest_surf_state.ss0.vert_line_stride_ofs = 0;
+       dest_surf_state.ss0.mipmap_layout_mode = 0;
+       dest_surf_state.ss0.render_cache_read_mode = 0;
+
+       dest_surf_state.ss1.base_addr =
            intel_emit_reloc(surf_bo, offset + offsetof(struct brw_surface_state, ss1),
-                            pixmap_bo, 0, I915_GEM_DOMAIN_SAMPLER, 0);
-
-       dest_surf_state->ss2.height = pixmap->drawable.height - 1;
-       dest_surf_state->ss2.width = pixmap->drawable.width - 1;
-       dest_surf_state->ss2.mip_count = 0;
-       dest_surf_state->ss2.render_target_rotation = 0;
-       dest_surf_state->ss3.pitch = intel_pixmap_pitch(pixmap) - 1;
-       dest_surf_state->ss3.tiled_surface = intel_pixmap_tiled(pixmap);
-       dest_surf_state->ss3.tile_walk = 0;     /* TileX */
-
-       drm_intel_bo_unmap(surf_bo);
+                            pixmap_bo, 0, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER);
+
+       dest_surf_state.ss2.height = pixmap->drawable.height - 1;
+       dest_surf_state.ss2.width = pixmap->drawable.width - 1;
+       dest_surf_state.ss2.mip_count = 0;
+       dest_surf_state.ss2.render_target_rotation = 0;
+       dest_surf_state.ss3.pitch = intel_pixmap_pitch(pixmap) - 1;
+       dest_surf_state.ss3.tiled_surface = intel_pixmap_tiled(pixmap);
+       dest_surf_state.ss3.tile_walk = 0;      /* TileX */
+
+       dri_bo_subdata(surf_bo,
+                      offset, sizeof(dest_surf_state),
+                      &dest_surf_state);
 }
 
 static void i965_create_src_surface_state(ScrnInfoPtr scrn,
@@ -435,106 +439,202 @@ static void i965_create_src_surface_state(ScrnInfoPtr scrn,
                                        drm_intel_bo *surface_bo,
                                        uint32_t offset)
 {
-       struct brw_surface_state *src_surf_state;
+       struct brw_surface_state src_surf_state;
 
-       if (drm_intel_bo_map(surface_bo, TRUE) != 0)
-               return;
-
-       src_surf_state = (struct brw_surface_state *)((char *)surface_bo->virtual + offset);
-       memset(src_surf_state, 0, sizeof(*src_surf_state));
+       memset(&src_surf_state, 0, sizeof(src_surf_state));
 
        /* Set up the source surface state buffer */
-       src_surf_state->ss0.surface_type = BRW_SURFACE_2D;
-       src_surf_state->ss0.surface_format = src_surf_format;
-       src_surf_state->ss0.writedisable_alpha = 0;
-       src_surf_state->ss0.writedisable_red = 0;
-       src_surf_state->ss0.writedisable_green = 0;
-       src_surf_state->ss0.writedisable_blue = 0;
-       src_surf_state->ss0.color_blend = 1;
-       src_surf_state->ss0.vert_line_stride = 0;
-       src_surf_state->ss0.vert_line_stride_ofs = 0;
-       src_surf_state->ss0.mipmap_layout_mode = 0;
-       src_surf_state->ss0.render_cache_read_mode = 0;
-
-       src_surf_state->ss2.width = src_width - 1;
-       src_surf_state->ss2.height = src_height - 1;
-       src_surf_state->ss2.mip_count = 0;
-       src_surf_state->ss2.render_target_rotation = 0;
-       src_surf_state->ss3.pitch = src_pitch - 1;
+       src_surf_state.ss0.surface_type = BRW_SURFACE_2D;
+       src_surf_state.ss0.surface_format = src_surf_format;
+       src_surf_state.ss0.writedisable_alpha = 0;
+       src_surf_state.ss0.writedisable_red = 0;
+       src_surf_state.ss0.writedisable_green = 0;
+       src_surf_state.ss0.writedisable_blue = 0;
+       src_surf_state.ss0.color_blend = 1;
+       src_surf_state.ss0.vert_line_stride = 0;
+       src_surf_state.ss0.vert_line_stride_ofs = 0;
+       src_surf_state.ss0.mipmap_layout_mode = 0;
+       src_surf_state.ss0.render_cache_read_mode = 0;
+
+       src_surf_state.ss2.width = src_width - 1;
+       src_surf_state.ss2.height = src_height - 1;
+       src_surf_state.ss2.mip_count = 0;
+       src_surf_state.ss2.render_target_rotation = 0;
+       src_surf_state.ss3.pitch = src_pitch - 1;
 
        if (src_bo) {
-               src_surf_state->ss1.base_addr =
+               src_surf_state.ss1.base_addr =
                    intel_emit_reloc(surface_bo,
                                     offset + offsetof(struct brw_surface_state, ss1),
                                     src_bo, src_offset,
                                     I915_GEM_DOMAIN_SAMPLER, 0);
        } else {
-               src_surf_state->ss1.base_addr = src_offset;
+               src_surf_state.ss1.base_addr = src_offset;
+       }
+
+       dri_bo_subdata(surface_bo,
+                      offset, sizeof(src_surf_state),
+                      &src_surf_state);
+}
+
+static void gen7_create_dst_surface_state(ScrnInfoPtr scrn,
+                                       PixmapPtr pixmap,
+                                       drm_intel_bo *surf_bo,
+                                       uint32_t offset)
+{
+       intel_screen_private *intel = intel_get_screen_private(scrn);
+       struct gen7_surface_state dest_surf_state;
+       drm_intel_bo *pixmap_bo = intel_get_pixmap_bo(pixmap);
+       assert(pixmap_bo != NULL);
+
+       memset(&dest_surf_state, 0, sizeof(dest_surf_state));
+
+       dest_surf_state.ss0.surface_type = BRW_SURFACE_2D;
+       dest_surf_state.ss0.tiled_surface = intel_pixmap_tiled(pixmap);
+       dest_surf_state.ss0.tile_walk = 0;      /* TileX */
+
+       if (intel->cpp == 2) {
+               dest_surf_state.ss0.surface_format = BRW_SURFACEFORMAT_B5G6R5_UNORM;
+       } else {
+               dest_surf_state.ss0.surface_format = BRW_SURFACEFORMAT_B8G8R8A8_UNORM;
+       }
+
+       dest_surf_state.ss1.base_addr =
+               intel_emit_reloc(surf_bo,
+                               offset + offsetof(struct gen7_surface_state, ss1),
+                               pixmap_bo, 0,
+                               I915_GEM_DOMAIN_SAMPLER, 0);
+
+       dest_surf_state.ss2.height = pixmap->drawable.height - 1;
+       dest_surf_state.ss2.width = pixmap->drawable.width - 1;
+
+       dest_surf_state.ss3.pitch = intel_pixmap_pitch(pixmap) - 1;
+
+       if (IS_HSW(intel)) {
+               dest_surf_state.ss7.shader_chanel_select_r = HSW_SCS_RED;
+               dest_surf_state.ss7.shader_chanel_select_g = HSW_SCS_GREEN;
+               dest_surf_state.ss7.shader_chanel_select_b = HSW_SCS_BLUE;
+               dest_surf_state.ss7.shader_chanel_select_a = HSW_SCS_ALPHA;
+       }
+
+       dri_bo_subdata(surf_bo,
+                      offset, sizeof(dest_surf_state),
+                      &dest_surf_state);
+}
+
+static void gen7_create_src_surface_state(ScrnInfoPtr scrn,
+                                       drm_intel_bo * src_bo,
+                                       uint32_t src_offset,
+                                       int src_width,
+                                       int src_height,
+                                       int src_pitch,
+                                       uint32_t src_surf_format,
+                                       drm_intel_bo *surface_bo,
+                                       uint32_t offset)
+{
+       intel_screen_private * const intel = intel_get_screen_private(scrn);
+       struct gen7_surface_state src_surf_state;
+
+       memset(&src_surf_state, 0, sizeof(src_surf_state));
+
+       src_surf_state.ss0.surface_type = BRW_SURFACE_2D;
+       src_surf_state.ss0.surface_format = src_surf_format;
+
+       if (src_bo) {
+               src_surf_state.ss1.base_addr =
+                       intel_emit_reloc(surface_bo,
+                                       offset + offsetof(struct gen7_surface_state, ss1),
+                                       src_bo, src_offset,
+                                       I915_GEM_DOMAIN_SAMPLER, 0);
+       } else {
+               src_surf_state.ss1.base_addr = src_offset;
        }
 
-       drm_intel_bo_unmap(surface_bo);
+       src_surf_state.ss2.width = src_width - 1;
+       src_surf_state.ss2.height = src_height - 1;
+
+       src_surf_state.ss3.pitch = src_pitch - 1;
+
+       if (IS_HSW(intel)) {
+               src_surf_state.ss7.shader_chanel_select_r = HSW_SCS_RED;
+               src_surf_state.ss7.shader_chanel_select_g = HSW_SCS_GREEN;
+               src_surf_state.ss7.shader_chanel_select_b = HSW_SCS_BLUE;
+               src_surf_state.ss7.shader_chanel_select_a = HSW_SCS_ALPHA;
+       }
+
+       dri_bo_subdata(surface_bo,
+                      offset, sizeof(src_surf_state),
+                      &src_surf_state);
 }
 
 static void i965_create_binding_table(ScrnInfoPtr scrn,
-                               drm_intel_bo *bind_bo,
-                               int n_surf)
+                                     drm_intel_bo *bind_bo,
+                                     int n_surf)
 {
-       uint32_t *binding_table;
+       uint32_t binding_table[n_surf];
        int i;
 
        /* Set up a binding table for our surfaces.  Only the PS will use it */
-       if (drm_intel_bo_map(bind_bo, TRUE) != 0)
-               return;
-
-       binding_table = (uint32_t*)((char *)bind_bo->virtual + n_surf * ALIGN(sizeof(struct brw_surface_state), 32));
-
        for (i = 0; i < n_surf; i++)
-               binding_table[i] = i * ALIGN(sizeof(struct brw_surface_state), 32);
+               binding_table[i] = i * SURFACE_STATE_PADDED_SIZE;
 
-       drm_intel_bo_unmap(bind_bo);
+       dri_bo_subdata(bind_bo,
+                      n_surf * SURFACE_STATE_PADDED_SIZE,
+                      sizeof(binding_table), binding_table);
 }
 
 static drm_intel_bo *i965_create_sampler_state(ScrnInfoPtr scrn)
 {
        intel_screen_private *intel = intel_get_screen_private(scrn);
-       drm_intel_bo *sampler_bo;
-       struct brw_sampler_state *sampler_state;
-
-       if (intel_alloc_and_map(intel, "textured video sampler state", 4096,
-                               &sampler_bo, &sampler_state) != 0)
-               return NULL;
-
-       sampler_state->ss0.min_filter = BRW_MAPFILTER_LINEAR;
-       sampler_state->ss0.mag_filter = BRW_MAPFILTER_LINEAR;
-       sampler_state->ss1.r_wrap_mode = BRW_TEXCOORDMODE_CLAMP;
-       sampler_state->ss1.s_wrap_mode = BRW_TEXCOORDMODE_CLAMP;
-       sampler_state->ss1.t_wrap_mode = BRW_TEXCOORDMODE_CLAMP;
+       struct brw_sampler_state sampler_state;
+
+       memset(&sampler_state, 0, sizeof(sampler_state));
+       sampler_state.ss0.min_filter = BRW_MAPFILTER_LINEAR;
+       sampler_state.ss0.mag_filter = BRW_MAPFILTER_LINEAR;
+       sampler_state.ss1.r_wrap_mode = BRW_TEXCOORDMODE_CLAMP;
+       sampler_state.ss1.s_wrap_mode = BRW_TEXCOORDMODE_CLAMP;
+       sampler_state.ss1.t_wrap_mode = BRW_TEXCOORDMODE_CLAMP;
+
+       return intel_bo_alloc_for_data(intel,
+                                      &sampler_state, sizeof(sampler_state),
+                                      "textured video sampler state");
+}
 
-       drm_intel_bo_unmap(sampler_bo);
-       return sampler_bo;
+static drm_intel_bo *gen7_create_sampler_state(ScrnInfoPtr scrn)
+{
+       intel_screen_private *intel = intel_get_screen_private(scrn);
+       struct gen7_sampler_state sampler_state;
+
+       memset(&sampler_state, 0, sizeof(sampler_state));
+       sampler_state.ss0.min_filter = BRW_MAPFILTER_LINEAR;
+       sampler_state.ss0.mag_filter = BRW_MAPFILTER_LINEAR;
+       sampler_state.ss3.r_wrap_mode = BRW_TEXCOORDMODE_CLAMP;
+       sampler_state.ss3.s_wrap_mode = BRW_TEXCOORDMODE_CLAMP;
+       sampler_state.ss3.t_wrap_mode = BRW_TEXCOORDMODE_CLAMP;
+
+       return intel_bo_alloc_for_data(intel,
+                                      &sampler_state, sizeof(sampler_state),
+                                      "textured video sampler state");
 }
 
 static drm_intel_bo *i965_create_vs_state(ScrnInfoPtr scrn)
 {
        intel_screen_private *intel = intel_get_screen_private(scrn);
-       drm_intel_bo *vs_bo;
-       struct brw_vs_unit_state *vs_state;
-
-       if (intel_alloc_and_map(intel, "textured video vs state", 4096,
-                               &vs_bo, &vs_state) != 0)
-               return NULL;
+       struct brw_vs_unit_state vs_state;
 
        /* Set up the vertex shader to be disabled (passthrough) */
+       memset(&vs_state, 0, sizeof(vs_state));
        if (IS_GEN5(intel))
-               vs_state->thread4.nr_urb_entries = URB_VS_ENTRIES >> 2;
+               vs_state.thread4.nr_urb_entries = URB_VS_ENTRIES >> 2;
        else
-               vs_state->thread4.nr_urb_entries = URB_VS_ENTRIES;
-       vs_state->thread4.urb_entry_allocation_size = URB_VS_ENTRY_SIZE - 1;
-       vs_state->vs6.vs_enable = 0;
-       vs_state->vs6.vert_cache_disable = 1;
-
-       drm_intel_bo_unmap(vs_bo);
-       return vs_bo;
+               vs_state.thread4.nr_urb_entries = URB_VS_ENTRIES;
+       vs_state.thread4.urb_entry_allocation_size = URB_VS_ENTRY_SIZE - 1;
+       vs_state.vs6.vs_enable = 0;
+       vs_state.vs6.vert_cache_disable = 1;
+
+       return intel_bo_alloc_for_data(intel,
+                                      &vs_state, sizeof(vs_state),
+                                      "textured video vs state");
 }
 
 static drm_intel_bo *i965_create_program(ScrnInfoPtr scrn,
@@ -542,37 +642,32 @@ static drm_intel_bo *i965_create_program(ScrnInfoPtr scrn,
                                         unsigned int program_size)
 {
        intel_screen_private *intel = intel_get_screen_private(scrn);
-       drm_intel_bo *prog_bo;
-
-       prog_bo = drm_intel_bo_alloc(intel->bufmgr, "textured video program",
-                                    program_size, 4096);
-       if (!prog_bo)
-               return NULL;
-
-       drm_intel_bo_subdata(prog_bo, 0, program_size, program);
-
-       return prog_bo;
+       return intel_bo_alloc_for_data(intel,
+                                      program, program_size,
+                                      "textured video program");
 }
 
 static drm_intel_bo *i965_create_sf_state(ScrnInfoPtr scrn)
 {
        intel_screen_private *intel = intel_get_screen_private(scrn);
        drm_intel_bo *sf_bo, *kernel_bo;
-       struct brw_sf_unit_state *sf_state;
+       struct brw_sf_unit_state sf_state;
 
        if (IS_GEN5(intel))
-               kernel_bo =
-                   i965_create_program(scrn, &sf_kernel_static_gen5[0][0],
-                                       sizeof(sf_kernel_static_gen5));
+               kernel_bo = i965_create_program(scrn,
+                                               &sf_kernel_static_gen5[0][0],
+                                               sizeof(sf_kernel_static_gen5));
        else
-               kernel_bo = i965_create_program(scrn, &sf_kernel_static[0][0],
+               kernel_bo = i965_create_program(scrn,
+                                               &sf_kernel_static[0][0],
                                                sizeof(sf_kernel_static));
-
        if (!kernel_bo)
                return NULL;
 
-       if (intel_alloc_and_map(intel, "textured video sf state", 4096,
-                               &sf_bo, &sf_state) != 0) {
+       sf_bo = drm_intel_bo_alloc(intel->bufmgr,
+                                  "textured video sf state", 4096,
+                                  sizeof(sf_state));
+       if (sf_bo == NULL) {
                drm_intel_bo_unreference(kernel_bo);
                return NULL;
        }
@@ -581,38 +676,39 @@ static drm_intel_bo *i965_create_sf_state(ScrnInfoPtr scrn)
         * calculate dA/dx and dA/dy.  Hand these interpolation coefficients
         * back to SF which then hands pixels off to WM.
         */
-       sf_state->thread0.grf_reg_count = BRW_GRF_BLOCKS(SF_KERNEL_NUM_GRF);
-       sf_state->thread0.kernel_start_pointer =
+       memset(&sf_state, 0, sizeof(sf_state));
+       sf_state.thread0.grf_reg_count = BRW_GRF_BLOCKS(SF_KERNEL_NUM_GRF);
+       sf_state.thread0.kernel_start_pointer =
            intel_emit_reloc(sf_bo, offsetof(struct brw_sf_unit_state, thread0),
-                            kernel_bo, sf_state->thread0.grf_reg_count << 1,
+                            kernel_bo, sf_state.thread0.grf_reg_count << 1,
                             I915_GEM_DOMAIN_INSTRUCTION, 0) >> 6;
-       sf_state->sf1.single_program_flow = 1;  /* XXX */
-       sf_state->sf1.binding_table_entry_count = 0;
-       sf_state->sf1.thread_priority = 0;
-       sf_state->sf1.floating_point_mode = 0;  /* Mesa does this */
-       sf_state->sf1.illegal_op_exception_enable = 1;
-       sf_state->sf1.mask_stack_exception_enable = 1;
-       sf_state->sf1.sw_exception_enable = 1;
-       sf_state->thread2.per_thread_scratch_space = 0;
+       sf_state.sf1.single_program_flow = 1;   /* XXX */
+       sf_state.sf1.binding_table_entry_count = 0;
+       sf_state.sf1.thread_priority = 0;
+       sf_state.sf1.floating_point_mode = 0;   /* Mesa does this */
+       sf_state.sf1.illegal_op_exception_enable = 1;
+       sf_state.sf1.mask_stack_exception_enable = 1;
+       sf_state.sf1.sw_exception_enable = 1;
+       sf_state.thread2.per_thread_scratch_space = 0;
        /* scratch space is not used in our kernel */
-       sf_state->thread2.scratch_space_base_pointer = 0;
-       sf_state->thread3.const_urb_entry_read_length = 0;      /* no const URBs */
-       sf_state->thread3.const_urb_entry_read_offset = 0;      /* no const URBs */
-       sf_state->thread3.urb_entry_read_length = 1;    /* 1 URB per vertex */
-       sf_state->thread3.urb_entry_read_offset = 0;
-       sf_state->thread3.dispatch_grf_start_reg = 3;
-       sf_state->thread4.max_threads = SF_MAX_THREADS - 1;
-       sf_state->thread4.urb_entry_allocation_size = URB_SF_ENTRY_SIZE - 1;
-       sf_state->thread4.nr_urb_entries = URB_SF_ENTRIES;
-       sf_state->thread4.stats_enable = 1;
-       sf_state->sf5.viewport_transform = FALSE;       /* skip viewport */
-       sf_state->sf6.cull_mode = BRW_CULLMODE_NONE;
-       sf_state->sf6.scissor = 0;
-       sf_state->sf7.trifan_pv = 2;
-       sf_state->sf6.dest_org_vbias = 0x8;
-       sf_state->sf6.dest_org_hbias = 0x8;
-
-       drm_intel_bo_unmap(sf_bo);
+       sf_state.thread2.scratch_space_base_pointer = 0;
+       sf_state.thread3.const_urb_entry_read_length = 0;       /* no const URBs */
+       sf_state.thread3.const_urb_entry_read_offset = 0;       /* no const URBs */
+       sf_state.thread3.urb_entry_read_length = 1;     /* 1 URB per vertex */
+       sf_state.thread3.urb_entry_read_offset = 0;
+       sf_state.thread3.dispatch_grf_start_reg = 3;
+       sf_state.thread4.max_threads = SF_MAX_THREADS - 1;
+       sf_state.thread4.urb_entry_allocation_size = URB_SF_ENTRY_SIZE - 1;
+       sf_state.thread4.nr_urb_entries = URB_SF_ENTRIES;
+       sf_state.thread4.stats_enable = 1;
+       sf_state.sf5.viewport_transform = FALSE;        /* skip viewport */
+       sf_state.sf6.cull_mode = BRW_CULLMODE_NONE;
+       sf_state.sf6.scissor = 0;
+       sf_state.sf7.trifan_pv = 2;
+       sf_state.sf6.dest_org_vbias = 0x8;
+       sf_state.sf6.dest_org_hbias = 0x8;
+
+       dri_bo_subdata(sf_bo, 0, sizeof(sf_state), &sf_state);
        return sf_bo;
 }
 
@@ -622,7 +718,7 @@ static drm_intel_bo *i965_create_wm_state(ScrnInfoPtr scrn,
 {
        intel_screen_private *intel = intel_get_screen_private(scrn);
        drm_intel_bo *wm_bo, *kernel_bo;
-       struct brw_wm_unit_state *wm_state;
+       struct brw_wm_unit_state wm_state;
 
        if (is_packed) {
                if (IS_GEN5(intel))
@@ -656,116 +752,115 @@ static drm_intel_bo *i965_create_wm_state(ScrnInfoPtr scrn,
        if (!kernel_bo)
                return NULL;
 
-       if (intel_alloc_and_map
-           (intel, "textured video wm state", sizeof(*wm_state), &wm_bo,
-            &wm_state)) {
+       wm_bo = drm_intel_bo_alloc(intel->bufmgr,
+                                  "textured video wm state",
+                                  sizeof(wm_state), 0);
+       if (wm_bo == NULL) {
                drm_intel_bo_unreference(kernel_bo);
                return NULL;
        }
 
-       wm_state->thread0.grf_reg_count = BRW_GRF_BLOCKS(PS_KERNEL_NUM_GRF);
-       wm_state->thread0.kernel_start_pointer =
+       memset(&wm_state, 0, sizeof(wm_state));
+       wm_state.thread0.grf_reg_count = BRW_GRF_BLOCKS(PS_KERNEL_NUM_GRF);
+       wm_state.thread0.kernel_start_pointer =
            intel_emit_reloc(wm_bo, offsetof(struct brw_wm_unit_state, thread0),
-                            kernel_bo, wm_state->thread0.grf_reg_count << 1,
+                            kernel_bo, wm_state.thread0.grf_reg_count << 1,
                             I915_GEM_DOMAIN_INSTRUCTION, 0) >> 6;
-       wm_state->thread1.single_program_flow = 1;      /* XXX */
+       wm_state.thread1.single_program_flow = 1;       /* XXX */
        if (is_packed)
-               wm_state->thread1.binding_table_entry_count = 2;
+               wm_state.thread1.binding_table_entry_count = 2;
        else
-               wm_state->thread1.binding_table_entry_count = 7;
+               wm_state.thread1.binding_table_entry_count = 7;
 
        /* binding table entry count is only used for prefetching, and it has to
         * be set 0 for Ironlake
         */
        if (IS_GEN5(intel))
-               wm_state->thread1.binding_table_entry_count = 0;
+               wm_state.thread1.binding_table_entry_count = 0;
 
        /* Though we never use the scratch space in our WM kernel, it has to be
         * set, and the minimum allocation is 1024 bytes.
         */
-       wm_state->thread2.scratch_space_base_pointer = 0;
-       wm_state->thread2.per_thread_scratch_space = 0; /* 1024 bytes */
-       wm_state->thread3.dispatch_grf_start_reg = 3;   /* XXX */
-       wm_state->thread3.const_urb_entry_read_length = 0;
-       wm_state->thread3.const_urb_entry_read_offset = 0;
-       wm_state->thread3.urb_entry_read_length = 1;    /* XXX */
-       wm_state->thread3.urb_entry_read_offset = 0;    /* XXX */
-       wm_state->wm4.stats_enable = 1;
-       wm_state->wm4.sampler_state_pointer =
+       wm_state.thread2.scratch_space_base_pointer = 0;
+       wm_state.thread2.per_thread_scratch_space = 0;  /* 1024 bytes */
+       wm_state.thread3.dispatch_grf_start_reg = 3;    /* XXX */
+       wm_state.thread3.const_urb_entry_read_length = 0;
+       wm_state.thread3.const_urb_entry_read_offset = 0;
+       wm_state.thread3.urb_entry_read_length = 1;     /* XXX */
+       wm_state.thread3.urb_entry_read_offset = 0;     /* XXX */
+       wm_state.wm4.stats_enable = 1;
+       wm_state.wm4.sampler_state_pointer =
            intel_emit_reloc(wm_bo, offsetof(struct brw_wm_unit_state, wm4),
                             sampler_bo, 0,
                             I915_GEM_DOMAIN_INSTRUCTION, 0) >> 5;
        if (IS_GEN5(intel))
-               wm_state->wm4.sampler_count = 0;
+               wm_state.wm4.sampler_count = 0;
        else
-               wm_state->wm4.sampler_count = 1;        /* 1-4 samplers used */
-       wm_state->wm5.max_threads = PS_MAX_THREADS - 1;
-       wm_state->wm5.thread_dispatch_enable = 1;
-       wm_state->wm5.enable_16_pix = 1;
-       wm_state->wm5.enable_8_pix = 0;
-       wm_state->wm5.early_depth_test = 1;
-
+               wm_state.wm4.sampler_count = 1; /* 1-4 samplers used */
+       wm_state.wm5.max_threads = PS_MAX_THREADS - 1;
+       wm_state.wm5.thread_dispatch_enable = 1;
+       wm_state.wm5.enable_16_pix = 1;
+       wm_state.wm5.enable_8_pix = 0;
+       wm_state.wm5.early_depth_test = 1;
+
+       dri_bo_subdata(wm_bo, 0, sizeof(wm_state), &wm_state);
        drm_intel_bo_unreference(kernel_bo);
-
-       drm_intel_bo_unmap(wm_bo);
        return wm_bo;
 }
 
 static drm_intel_bo *i965_create_cc_vp_state(ScrnInfoPtr scrn)
 {
        intel_screen_private *intel = intel_get_screen_private(scrn);
-       drm_intel_bo *cc_vp_bo;
-       struct brw_cc_viewport *cc_viewport;
-
-       if (intel_alloc_and_map(intel, "textured video cc viewport", 4096,
-                               &cc_vp_bo, &cc_viewport) != 0)
-               return NULL;
+       struct brw_cc_viewport cc_viewport;
 
-       cc_viewport->min_depth = -1.e35;
-       cc_viewport->max_depth = 1.e35;
+       memset(&cc_viewport, 0, sizeof(cc_viewport));
+       cc_viewport.min_depth = -1.e35;
+       cc_viewport.max_depth = 1.e35;
 
-       drm_intel_bo_unmap(cc_vp_bo);
-       return cc_vp_bo;
+       return intel_bo_alloc_for_data(intel,
+                                      &cc_viewport, sizeof(cc_viewport),
+                                      "textured video cc viewport");
 }
 
 static drm_intel_bo *i965_create_cc_state(ScrnInfoPtr scrn)
 {
        intel_screen_private *intel = intel_get_screen_private(scrn);
        drm_intel_bo *cc_bo, *cc_vp_bo;
-       struct brw_cc_unit_state *cc_state;
+       struct brw_cc_unit_state cc_state;
 
        cc_vp_bo = i965_create_cc_vp_state(scrn);
        if (!cc_vp_bo)
                return NULL;
 
-       if (intel_alloc_and_map
-           (intel, "textured video cc state", sizeof(*cc_state), &cc_bo,
-            &cc_state) != 0) {
+       cc_bo = drm_intel_bo_alloc(intel->bufmgr,
+                                  "textured video cc state",
+                                  sizeof(cc_state), 0);
+       if (cc_bo == NULL){
                drm_intel_bo_unreference(cc_vp_bo);
                return NULL;
        }
 
        /* Color calculator state */
-       memset(cc_state, 0, sizeof(*cc_state));
-       cc_state->cc0.stencil_enable = 0;       /* disable stencil */
-       cc_state->cc2.depth_test = 0;   /* disable depth test */
-       cc_state->cc2.logicop_enable = 1;       /* enable logic op */
-       cc_state->cc3.ia_blend_enable = 1;      /* blend alpha just like colors */
-       cc_state->cc3.blend_enable = 0; /* disable color blend */
-       cc_state->cc3.alpha_test = 0;   /* disable alpha test */
-       cc_state->cc4.cc_viewport_state_offset =
+       memset(&cc_state, 0, sizeof(cc_state));
+       cc_state.cc0.stencil_enable = 0;        /* disable stencil */
+       cc_state.cc2.depth_test = 0;    /* disable depth test */
+       cc_state.cc2.logicop_enable = 1;        /* enable logic op */
+       cc_state.cc3.ia_blend_enable = 1;       /* blend alpha just like colors */
+       cc_state.cc3.blend_enable = 0;  /* disable color blend */
+       cc_state.cc3.alpha_test = 0;    /* disable alpha test */
+       cc_state.cc4.cc_viewport_state_offset =
            intel_emit_reloc(cc_bo, offsetof(struct brw_cc_unit_state, cc4),
                             cc_vp_bo, 0, I915_GEM_DOMAIN_INSTRUCTION, 0) >> 5;
-       cc_state->cc5.dither_enable = 0;        /* disable dither */
-       cc_state->cc5.logicop_func = 0xc;       /* WHITE */
-       cc_state->cc5.statistics_enable = 1;
-       cc_state->cc5.ia_blend_function = BRW_BLENDFUNCTION_ADD;
-       cc_state->cc5.ia_src_blend_factor = BRW_BLENDFACTOR_ONE;
-       cc_state->cc5.ia_dest_blend_factor = BRW_BLENDFACTOR_ONE;
-
-       drm_intel_bo_unmap(cc_bo);
-
+       cc_state.cc5.dither_enable = 0; /* disable dither */
+       cc_state.cc5.logicop_func = 0xc;        /* WHITE */
+       cc_state.cc5.statistics_enable = 1;
+       cc_state.cc5.ia_blend_function = BRW_BLENDFUNCTION_ADD;
+       cc_state.cc5.ia_src_blend_factor = BRW_BLENDFACTOR_ONE;
+       cc_state.cc5.ia_dest_blend_factor = BRW_BLENDFACTOR_ONE;
+
+       dri_bo_subdata(cc_bo, 0, sizeof(cc_state), &cc_state);
        drm_intel_bo_unreference(cc_vp_bo);
+
        return cc_bo;
 }
 
@@ -782,6 +877,7 @@ i965_emit_video_setup(ScrnInfoPtr scrn, drm_intel_bo * surface_state_binding_tab
 
        IntelEmitInvarientState(scrn);
        intel->last_3d = LAST_3D_VIDEO;
+       intel->needs_3d_invariant = TRUE;
 
        urb_vs_start = 0;
        urb_vs_size = URB_VS_ENTRIES * URB_VS_ENTRY_SIZE;
@@ -863,7 +959,7 @@ i965_emit_video_setup(ScrnInfoPtr scrn, drm_intel_bo * surface_state_binding_tab
        OUT_BATCH(0);           /* clip */
        OUT_BATCH(0);           /* sf */
        /* Only the PS uses the binding table */
-       OUT_BATCH((n_src_surf + 1) * ALIGN(sizeof(struct brw_surface_state), 32));
+       OUT_BATCH((n_src_surf + 1) * SURFACE_STATE_PADDED_SIZE);
 
        /* Blend constant color (magenta is fun) */
        OUT_BATCH(BRW_3DSTATE_CONSTANT_COLOR | 3);
@@ -1056,7 +1152,7 @@ I965DisplayVideoTextured(ScrnInfoPtr scrn,
        surface_state_binding_table_bo = 
                drm_intel_bo_alloc(intel->bufmgr,
                                "surface state & binding table",
-                               (n_src_surf + 1) * (ALIGN(sizeof(struct brw_surface_state), 32) + sizeof(uint32_t)),
+                               (n_src_surf + 1) * (SURFACE_STATE_PADDED_SIZE + sizeof(uint32_t)),
                                4096);
 
        if (!surface_state_binding_table_bo)
@@ -1073,7 +1169,7 @@ I965DisplayVideoTextured(ScrnInfoPtr scrn,
                                        src_pitch[src_surf],
                                        src_surf_format,
                                        surface_state_binding_table_bo,
-                                       (src_surf + 1) * ALIGN(sizeof(struct brw_surface_state), 32));
+                                       (src_surf + 1) * SURFACE_STATE_PADDED_SIZE);
        }
 
        i965_create_binding_table(scrn, surface_state_binding_table_bo, n_src_surf + 1);
@@ -1158,8 +1254,7 @@ I965DisplayVideoTextured(ScrnInfoPtr scrn,
                int box_x2 = pbox->x2;
                int box_y2 = pbox->y2;
                int i;
-               drm_intel_bo *vb_bo;
-               float *vb;
+               float vb[12];
                drm_intel_bo *bo_table[] = {
                        NULL,   /* vb_bo */
                        intel->batch_bo,
@@ -1175,11 +1270,6 @@ I965DisplayVideoTextured(ScrnInfoPtr scrn,
 
                pbox++;
 
-               if (intel_alloc_and_map(intel, "textured video vb", 4096,
-                                       &vb_bo, &vb) != 0)
-                       break;
-               bo_table[0] = vb_bo;
-
                i = 0;
                vb[i++] = (box_x2 - dxo) * src_scale_x;
                vb[i++] = (box_y2 - dyo) * src_scale_y;
@@ -1196,7 +1286,9 @@ I965DisplayVideoTextured(ScrnInfoPtr scrn,
                vb[i++] = (float)box_x1 + pix_xoff;
                vb[i++] = (float)box_y1 + pix_yoff;
 
-               drm_intel_bo_unmap(vb_bo);
+               bo_table[0] = intel_bo_alloc_for_data(intel,
+                                                     vb, sizeof(vb),
+                                                     "textured video vbo");
 
                if (IS_GEN4(intel))
                        i965_pre_draw_debug(scrn);
@@ -1210,7 +1302,7 @@ I965DisplayVideoTextured(ScrnInfoPtr scrn,
                        intel_batch_submit(scrn);
                }
 
-               intel_batch_start_atomic(scrn, 100);
+               intel_batch_start_atomic(scrn, 150);
 
                i965_emit_video_setup(scrn, surface_state_binding_table_bo, n_src_surf, pixmap);
 
@@ -1219,9 +1311,9 @@ I965DisplayVideoTextured(ScrnInfoPtr scrn,
                /* four 32-bit floats per vertex */
                OUT_BATCH((0 << VB0_BUFFER_INDEX_SHIFT) |
                          VB0_VERTEXDATA | ((4 * 4) << VB0_BUFFER_PITCH_SHIFT));
-               OUT_RELOC(vb_bo, I915_GEM_DOMAIN_VERTEX, 0, 0);
+               OUT_RELOC(bo_table[0], I915_GEM_DOMAIN_VERTEX, 0, 0);
                if (IS_GEN5(intel))
-                       OUT_RELOC(vb_bo, I915_GEM_DOMAIN_VERTEX, 0,
+                       OUT_RELOC(bo_table[0], I915_GEM_DOMAIN_VERTEX, 0,
                                  i * 4);
                else
                        OUT_BATCH(3);   /* four corners to our rectangle */
@@ -1238,7 +1330,7 @@ I965DisplayVideoTextured(ScrnInfoPtr scrn,
 
                intel_batch_end_atomic(scrn);
 
-               drm_intel_bo_unreference(vb_bo);
+               drm_intel_bo_unreference(bo_table[0]);
 
                if (IS_GEN4(intel))
                        i965_post_draw_debug(scrn);
@@ -1286,86 +1378,84 @@ static drm_intel_bo *
 gen6_create_cc_state(ScrnInfoPtr scrn)
 {
        intel_screen_private *intel = intel_get_screen_private(scrn);
-       struct gen6_color_calc_state *cc_state;
-       drm_intel_bo *cc_bo;
-
-       if (intel_alloc_and_map(
-                       intel,
-                       "textured video cc state", 
-                       sizeof(*cc_state), 
-                       &cc_bo,
-                       &cc_state) != 0)
-               return NULL;
+       struct gen6_color_calc_state cc_state;
 
-       cc_state->constant_r = 1.0;
-       cc_state->constant_g = 0.0;
-       cc_state->constant_b = 1.0;
-       cc_state->constant_a = 1.0;
+       memset(&cc_state, 0, sizeof(cc_state));
+       cc_state.constant_r = 1.0;
+       cc_state.constant_g = 0.0;
+       cc_state.constant_b = 1.0;
+       cc_state.constant_a = 1.0;
 
-       drm_intel_bo_unmap(cc_bo);
-       return cc_bo;
+       return intel_bo_alloc_for_data(intel,
+                                      &cc_state, sizeof(cc_state),
+                                      "textured video cc state");
 }
 
 static drm_intel_bo *
 gen6_create_blend_state(ScrnInfoPtr scrn)
 {
        intel_screen_private *intel = intel_get_screen_private(scrn);
-       struct gen6_blend_state *blend_state;
-       drm_intel_bo *blend_bo;
-
-       if (intel_alloc_and_map(
-                       intel,
-                       "textured video blend state",
-                       sizeof(*blend_state),
-                       &blend_bo,
-                       &blend_state) != 0)
-               return NULL;
+       struct gen6_blend_state blend_state;
 
-       blend_state->blend1.logic_op_enable = 1;
-       blend_state->blend1.logic_op_func = 0xc;
+       memset(&blend_state, 0, sizeof(blend_state));
+       blend_state.blend1.logic_op_enable = 1;
+       blend_state.blend1.logic_op_func = 0xc;
+       blend_state.blend1.pre_blend_clamp_enable = 1;
 
-       drm_intel_bo_unmap(blend_bo);
-       return blend_bo;
+       return intel_bo_alloc_for_data(intel,
+                                      &blend_state, sizeof(blend_state),
+                                      "textured video blend state");
 }
 
 static drm_intel_bo *
 gen6_create_depth_stencil_state(ScrnInfoPtr scrn)
 {
        intel_screen_private *intel = intel_get_screen_private(scrn);
-       struct gen6_depth_stencil_state *depth_stencil_state;
-       drm_intel_bo *depth_stencil_bo;
-
-       if (intel_alloc_and_map(
-                       intel,
-                       "textured video blend state",
-                       sizeof(*depth_stencil_state),
-                       &depth_stencil_bo,
-                       &depth_stencil_state) != 0)
-               return NULL;
+       struct gen6_depth_stencil_state depth_stencil_state;
 
-       drm_intel_bo_unmap(depth_stencil_bo);
-       return depth_stencil_bo;
+       memset(&depth_stencil_state, 0, sizeof(depth_stencil_state));
+       return intel_bo_alloc_for_data(intel,
+                                      &depth_stencil_state,
+                                      sizeof(depth_stencil_state),
+                                      "textured video blend state");
 }
 
 static Bool
 gen6_create_vidoe_objects(ScrnInfoPtr scrn)
 {
        intel_screen_private *intel = intel_get_screen_private(scrn);
+       drm_intel_bo *(*create_sampler_state)(ScrnInfoPtr);
+       const uint32_t *packed_ps_kernel, *planar_ps_kernel;
+       unsigned int packed_ps_size, planar_ps_size;
+       
+       if (INTEL_INFO(intel)->gen >= 70) {
+               create_sampler_state = gen7_create_sampler_state;
+               packed_ps_kernel = &ps_kernel_packed_static_gen7[0][0];
+               packed_ps_size = sizeof(ps_kernel_packed_static_gen7);
+               planar_ps_kernel = &ps_kernel_planar_static_gen7[0][0];
+               planar_ps_size = sizeof(ps_kernel_planar_static_gen7);
+       } else {
+               create_sampler_state = i965_create_sampler_state;
+               packed_ps_kernel = &ps_kernel_packed_static_gen6[0][0];
+               packed_ps_size = sizeof(ps_kernel_packed_static_gen6);
+               planar_ps_kernel = &ps_kernel_planar_static_gen6[0][0];
+               planar_ps_size = sizeof(ps_kernel_planar_static_gen6);
+       }
 
        if (intel->video.gen4_sampler_bo == NULL)
-               intel->video.gen4_sampler_bo = i965_create_sampler_state(scrn);
+               intel->video.gen4_sampler_bo = create_sampler_state(scrn);
                
        if (intel->video.wm_prog_packed_bo == NULL)
                intel->video.wm_prog_packed_bo =
                        i965_create_program(scrn,
-                                       &ps_kernel_packed_static_gen6[0][0],
-                                       sizeof(ps_kernel_packed_static_gen6));
+                                       packed_ps_kernel,
+                                       packed_ps_size);
                
        if (intel->video.wm_prog_planar_bo == NULL)
                intel->video.wm_prog_planar_bo =
                        i965_create_program(scrn,
-                                       &ps_kernel_planar_static_gen6[0][0],
-                                       sizeof(ps_kernel_planar_static_gen6));
+                                       planar_ps_kernel,
+                                       planar_ps_size);
 
        if (intel->video.gen4_cc_vp_bo == NULL)
                intel->video.gen4_cc_vp_bo = i965_create_cc_vp_state(scrn);
@@ -1390,34 +1480,6 @@ gen6_create_vidoe_objects(ScrnInfoPtr scrn)
 }
 
 static void
-gen6_upload_invarient_states(ScrnInfoPtr scrn)
-{
-       intel_screen_private *intel = intel_get_screen_private(scrn);
-
-       OUT_BATCH(BRW_PIPE_CONTROL | (4 - 2));
-       OUT_BATCH(BRW_PIPE_CONTROL_IS_FLUSH |
-               BRW_PIPE_CONTROL_WC_FLUSH |
-               BRW_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
-               BRW_PIPE_CONTROL_NOWRITE);
-       OUT_BATCH(0); /* write address */
-       OUT_BATCH(0); /* write data */
-
-       OUT_BATCH(NEW_PIPELINE_SELECT | PIPELINE_SELECT_3D);
-
-       OUT_BATCH(GEN6_3DSTATE_MULTISAMPLE | (3 - 2));
-       OUT_BATCH(GEN6_3DSTATE_MULTISAMPLE_PIXEL_LOCATION_CENTER |
-               GEN6_3DSTATE_MULTISAMPLE_NUMSAMPLES_1); /* 1 sample/pixel */
-       OUT_BATCH(0);
-
-       OUT_BATCH(GEN6_3DSTATE_SAMPLE_MASK | (2 - 2));
-       OUT_BATCH(1);
-
-       /* Set system instruction pointer */
-       OUT_BATCH(BRW_STATE_SIP | 0);
-       OUT_BATCH(0);
-}
-
-static void
 gen6_upload_state_base_address(ScrnInfoPtr scrn, drm_intel_bo *surface_state_binding_table_bo)
 {
        intel_screen_private *intel = intel_get_screen_private(scrn);
@@ -1435,88 +1497,6 @@ gen6_upload_state_base_address(ScrnInfoPtr scrn, drm_intel_bo *surface_state_bin
 }
 
 static void
-gen6_upload_viewport_state_pointers(ScrnInfoPtr scrn)
-{
-       intel_screen_private *intel = intel_get_screen_private(scrn);
-
-       OUT_BATCH(GEN6_3DSTATE_VIEWPORT_STATE_POINTERS |
-               GEN6_3DSTATE_VIEWPORT_STATE_MODIFY_CC |
-               (4 - 2));
-       OUT_BATCH(0);
-       OUT_BATCH(0);
-       OUT_RELOC(intel->video.gen4_cc_vp_bo, I915_GEM_DOMAIN_INSTRUCTION, 0, 0);
-}
-
-static void
-gen6_upload_urb(ScrnInfoPtr scrn)
-{
-       intel_screen_private *intel = intel_get_screen_private(scrn);
-
-       OUT_BATCH(GEN6_3DSTATE_URB | (3 - 2));
-       OUT_BATCH(((1 - 1) << GEN6_3DSTATE_URB_VS_SIZE_SHIFT) |
-               (24 << GEN6_3DSTATE_URB_VS_ENTRIES_SHIFT)); /* at least 24 on GEN6 */
-       OUT_BATCH((0 << GEN6_3DSTATE_URB_GS_SIZE_SHIFT) |
-               (0 << GEN6_3DSTATE_URB_GS_ENTRIES_SHIFT)); /* no GS thread */
-}
-
-static void
-gen6_upload_cc_state_pointers(ScrnInfoPtr scrn)
-{
-       intel_screen_private *intel = intel_get_screen_private(scrn);
-
-       OUT_BATCH(GEN6_3DSTATE_CC_STATE_POINTERS | (4 - 2));
-       OUT_RELOC(intel->video.gen6_blend_bo, I915_GEM_DOMAIN_INSTRUCTION, 0, 1);
-       OUT_RELOC(intel->video.gen6_depth_stencil_bo, I915_GEM_DOMAIN_INSTRUCTION, 0, 1);
-       OUT_RELOC(intel->video.gen4_cc_bo, I915_GEM_DOMAIN_INSTRUCTION, 0, 1);
-}
-
-static void
-gen6_upload_sampler_state_pointers(ScrnInfoPtr scrn)
-{
-       intel_screen_private *intel = intel_get_screen_private(scrn);
-
-       OUT_BATCH(GEN6_3DSTATE_SAMPLER_STATE_POINTERS |
-               GEN6_3DSTATE_SAMPLER_STATE_MODIFY_PS |
-               (4 - 2));
-       OUT_BATCH(0); /* VS */
-       OUT_BATCH(0); /* GS */
-       OUT_RELOC(intel->video.gen4_sampler_bo, I915_GEM_DOMAIN_INSTRUCTION, 0, 0);
-}
-
-static void
-gen6_upload_binding_table(ScrnInfoPtr scrn, uint32_t ps_binding_table_offset)
-{
-       intel_screen_private *intel = intel_get_screen_private(scrn);
-
-       /* Binding table pointers */
-       OUT_BATCH(BRW_3DSTATE_BINDING_TABLE_POINTERS |
-               GEN6_3DSTATE_BINDING_TABLE_MODIFY_PS |
-               (4 - 2));
-       OUT_BATCH(0);           /* vs */
-       OUT_BATCH(0);           /* gs */
-       /* Only the PS uses the binding table */
-       OUT_BATCH(ps_binding_table_offset);
-}
-
-static void
-gen6_upload_depth_buffer_state(ScrnInfoPtr scrn)
-{
-       intel_screen_private *intel = intel_get_screen_private(scrn);
-
-       OUT_BATCH(BRW_3DSTATE_DEPTH_BUFFER | (7 - 2));
-       OUT_BATCH((BRW_SURFACE_NULL << BRW_3DSTATE_DEPTH_BUFFER_TYPE_SHIFT) |
-               (BRW_DEPTHFORMAT_D32_FLOAT << BRW_3DSTATE_DEPTH_BUFFER_FORMAT_SHIFT));
-       OUT_BATCH(0);
-       OUT_BATCH(0);
-       OUT_BATCH(0);
-       OUT_BATCH(0);
-       OUT_BATCH(0);
-
-       OUT_BATCH(BRW_3DSTATE_CLEAR_PARAMS | (2 - 2));
-       OUT_BATCH(0);
-}
-
-static void
 gen6_upload_drawing_rectangle(ScrnInfoPtr scrn, PixmapPtr pixmap)
 {
        intel_screen_private *intel = intel_get_screen_private(scrn);
@@ -1528,87 +1508,6 @@ gen6_upload_drawing_rectangle(ScrnInfoPtr scrn, PixmapPtr pixmap)
 }
 
 static void 
-gen6_upload_vs_state(ScrnInfoPtr scrn)
-{
-       intel_screen_private *intel = intel_get_screen_private(scrn);
-
-       /* disable VS constant buffer */
-       OUT_BATCH(GEN6_3DSTATE_CONSTANT_VS | (5 - 2));
-       OUT_BATCH(0);
-       OUT_BATCH(0);
-       OUT_BATCH(0);
-       OUT_BATCH(0);
-       
-       OUT_BATCH(GEN6_3DSTATE_VS | (6 - 2));
-       OUT_BATCH(0); /* without VS kernel */
-       OUT_BATCH(0);
-       OUT_BATCH(0);
-       OUT_BATCH(0);
-       OUT_BATCH(0); /* pass-through */
-}
-
-static void 
-gen6_upload_gs_state(ScrnInfoPtr scrn)
-{
-       intel_screen_private *intel = intel_get_screen_private(scrn);
-
-       /* disable GS constant buffer */
-       OUT_BATCH(GEN6_3DSTATE_CONSTANT_GS | (5 - 2));
-       OUT_BATCH(0);
-       OUT_BATCH(0);
-       OUT_BATCH(0);
-       OUT_BATCH(0);
-       
-       OUT_BATCH(GEN6_3DSTATE_GS | (7 - 2));
-       OUT_BATCH(0); /* without GS kernel */
-       OUT_BATCH(0);
-       OUT_BATCH(0);
-       OUT_BATCH(0);
-       OUT_BATCH(0);
-       OUT_BATCH(0); /* pass-through */
-}
-
-static void 
-gen6_upload_clip_state(ScrnInfoPtr scrn)
-{
-       intel_screen_private *intel = intel_get_screen_private(scrn);
-
-       OUT_BATCH(GEN6_3DSTATE_CLIP | (4 - 2));
-       OUT_BATCH(0);
-       OUT_BATCH(0); /* pass-through */
-       OUT_BATCH(0);
-}
-
-static void 
-gen6_upload_sf_state(ScrnInfoPtr scrn)
-{
-       intel_screen_private *intel = intel_get_screen_private(scrn);
-
-       OUT_BATCH(GEN6_3DSTATE_SF | (20 - 2));
-       OUT_BATCH((1 << GEN6_3DSTATE_SF_NUM_OUTPUTS_SHIFT) |
-               (1 << GEN6_3DSTATE_SF_URB_ENTRY_READ_LENGTH_SHIFT) |
-               (0 << GEN6_3DSTATE_SF_URB_ENTRY_READ_OFFSET_SHIFT));
-       OUT_BATCH(0);
-       OUT_BATCH(GEN6_3DSTATE_SF_CULL_NONE);
-       OUT_BATCH(2 << GEN6_3DSTATE_SF_TRIFAN_PROVOKE_SHIFT); /* DW4 */
-       OUT_BATCH(0);
-       OUT_BATCH(0);
-       OUT_BATCH(0);
-       OUT_BATCH(0);
-       OUT_BATCH(0); /* DW9 */
-       OUT_BATCH(0);
-       OUT_BATCH(0);
-       OUT_BATCH(0);
-       OUT_BATCH(0);
-       OUT_BATCH(0); /* DW14 */
-       OUT_BATCH(0);
-       OUT_BATCH(0);
-       OUT_BATCH(0);
-       OUT_BATCH(0);
-       OUT_BATCH(0); /* DW19 */
-}
-
-static void 
 gen6_upload_wm_state(ScrnInfoPtr scrn, Bool is_packed)
 {
        intel_screen_private *intel = intel_get_screen_private(scrn);
@@ -1672,30 +1571,186 @@ gen6_upload_vertex_element_state(ScrnInfoPtr scrn)
                (BRW_VFCOMPONENT_STORE_1_FLT << VE1_VFCOMPONENT_3_SHIFT));
 }
 
+static void 
+gen6_upload_vertex_buffer(ScrnInfoPtr scrn, drm_intel_bo *vertex_bo, uint32_t end_address_offset)
+{
+       intel_screen_private *intel = intel_get_screen_private(scrn);
+
+       /* Set up the pointer to our vertex buffer */
+       OUT_BATCH(BRW_3DSTATE_VERTEX_BUFFERS | (5 - 2));
+       /* four 32-bit floats per vertex */
+       OUT_BATCH((0 << GEN6_VB0_BUFFER_INDEX_SHIFT) |
+               GEN6_VB0_VERTEXDATA | 
+               ((4 * 4) << VB0_BUFFER_PITCH_SHIFT));
+       OUT_RELOC(vertex_bo, I915_GEM_DOMAIN_VERTEX, 0, 0);
+       OUT_RELOC(vertex_bo, I915_GEM_DOMAIN_VERTEX, 0, end_address_offset);
+       OUT_BATCH(0);   /* reserved */
+}
+
+static void
+gen6_upload_primitive(ScrnInfoPtr scrn)
+{
+       intel_screen_private *intel = intel_get_screen_private(scrn);
+
+       OUT_BATCH(BRW_3DPRIMITIVE | 
+               BRW_3DPRIMITIVE_VERTEX_SEQUENTIAL | 
+               (_3DPRIM_RECTLIST << BRW_3DPRIMITIVE_TOPOLOGY_SHIFT) | 
+               (0 << 9) | /* Internal Vertex Count */
+               (6 - 2));
+       OUT_BATCH(3);   /* vertex count per instance */
+       OUT_BATCH(0);   /* start vertex offset */
+       OUT_BATCH(1);   /* single instance */
+       OUT_BATCH(0);   /* start instance location */
+       OUT_BATCH(0);   /* index buffer offset, ignored */
+}
+
 static void
-gen6_emit_video_setup(ScrnInfoPtr scrn, drm_intel_bo *surface_state_binding_table_bo, int n_src_surf, PixmapPtr pixmap)
+gen6_emit_video_setup(ScrnInfoPtr scrn,
+               drm_intel_bo *surface_state_binding_table_bo, int n_src_surf,
+               PixmapPtr pixmap,
+               drm_intel_bo *vertex_bo, uint32_t end_address_offset)
 {
        intel_screen_private *intel = intel_get_screen_private(scrn);
 
        assert(n_src_surf == 1 || n_src_surf == 6);
        IntelEmitInvarientState(scrn);
        intel->last_3d = LAST_3D_VIDEO;
+       intel->needs_3d_invariant = TRUE;
 
-       gen6_upload_invarient_states(scrn);
+       gen6_upload_invariant_states(intel);
        gen6_upload_state_base_address(scrn, surface_state_binding_table_bo);
-       gen6_upload_viewport_state_pointers(scrn);
-       gen6_upload_urb(scrn);
-       gen6_upload_cc_state_pointers(scrn);
-       gen6_upload_sampler_state_pointers(scrn);
-       gen6_upload_vs_state(scrn);
-       gen6_upload_gs_state(scrn);
-       gen6_upload_clip_state(scrn);
-       gen6_upload_sf_state(scrn);
+       gen6_upload_viewport_state_pointers(intel, intel->video.gen4_cc_vp_bo);
+       gen6_upload_urb(intel);
+       gen6_upload_cc_state_pointers(intel, intel->video.gen6_blend_bo, intel->video.gen4_cc_bo, intel->video.gen6_depth_stencil_bo, 0);
+       gen6_upload_sampler_state_pointers(intel, intel->video.gen4_sampler_bo);
+       gen6_upload_vs_state(intel);
+       gen6_upload_gs_state(intel);
+       gen6_upload_clip_state(intel);
+       gen6_upload_sf_state(intel, 1, 0);
        gen6_upload_wm_state(scrn, n_src_surf == 1 ? TRUE : FALSE);
-       gen6_upload_binding_table(scrn, (n_src_surf + 1) * ALIGN(sizeof(struct brw_surface_state), 32));;
-       gen6_upload_depth_buffer_state(scrn);
+       gen6_upload_binding_table(intel, (n_src_surf + 1) * SURFACE_STATE_PADDED_SIZE);
+       gen6_upload_depth_buffer_state(intel);
+       gen6_upload_drawing_rectangle(scrn, pixmap);
+       gen6_upload_vertex_element_state(scrn);
+       gen6_upload_vertex_buffer(scrn, vertex_bo, end_address_offset);
+       gen6_upload_primitive(scrn);
+}
+
+static void 
+gen7_upload_wm_state(ScrnInfoPtr scrn, Bool is_packed)
+{
+       intel_screen_private *intel = intel_get_screen_private(scrn);
+       unsigned int max_threads_shift = GEN7_PS_MAX_THREADS_SHIFT_IVB;
+       unsigned int num_samples = 0;
+
+       if (IS_HSW(intel)) {
+               max_threads_shift = GEN7_PS_MAX_THREADS_SHIFT_HSW;
+               num_samples = 1 << GEN7_PS_SAMPLE_MASK_SHIFT_HSW;
+       }
+
+       /* disable WM constant buffer */
+       OUT_BATCH(GEN6_3DSTATE_CONSTANT_PS | (7 - 2));
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+
+       OUT_BATCH(GEN6_3DSTATE_WM | (3 - 2));
+       OUT_BATCH(GEN7_WM_DISPATCH_ENABLE |
+               GEN7_WM_PERSPECTIVE_PIXEL_BARYCENTRIC);
+       OUT_BATCH(0);
+
+       OUT_BATCH(GEN7_3DSTATE_PS | (8 - 2));
+
+       if (is_packed) {
+               OUT_RELOC(intel->video.wm_prog_packed_bo,
+                       I915_GEM_DOMAIN_INSTRUCTION, 0,
+                       0);
+               OUT_BATCH((1 << GEN7_PS_SAMPLER_COUNT_SHIFT) |
+                       (2 << GEN7_PS_BINDING_TABLE_ENTRY_COUNT_SHIFT));
+       } else {
+               OUT_RELOC(intel->video.wm_prog_planar_bo,
+                       I915_GEM_DOMAIN_INSTRUCTION, 0,
+                       0);
+               OUT_BATCH((1 << GEN7_PS_SAMPLER_COUNT_SHIFT) |
+                       (7 << GEN7_PS_BINDING_TABLE_ENTRY_COUNT_SHIFT));
+       }
+
+       OUT_BATCH(0); /* scratch space base offset */
+       OUT_BATCH(
+               ((48 - 1) << max_threads_shift) | num_samples |
+               GEN7_PS_ATTRIBUTE_ENABLE |
+               GEN7_PS_16_DISPATCH_ENABLE);
+       OUT_BATCH(
+               (6 << GEN7_PS_DISPATCH_START_GRF_SHIFT_0));
+       OUT_BATCH(0); /* kernel 1 pointer */
+       OUT_BATCH(0); /* kernel 2 pointer */
+}
+
+static void 
+gen7_upload_vertex_buffer(ScrnInfoPtr scrn, drm_intel_bo *vertex_bo, uint32_t end_address_offset)
+{
+       intel_screen_private *intel = intel_get_screen_private(scrn);
+
+       /* Set up the pointer to our vertex buffer */
+       OUT_BATCH(BRW_3DSTATE_VERTEX_BUFFERS | (5 - 2));
+       /* four 32-bit floats per vertex */
+       OUT_BATCH((0 << GEN6_VB0_BUFFER_INDEX_SHIFT) |
+               GEN6_VB0_VERTEXDATA | 
+               GEN7_VB0_ADDRESS_MODIFYENABLE |
+               ((4 * 4) << VB0_BUFFER_PITCH_SHIFT));
+       OUT_RELOC(vertex_bo, I915_GEM_DOMAIN_VERTEX, 0, 0);
+       OUT_RELOC(vertex_bo, I915_GEM_DOMAIN_VERTEX, 0, end_address_offset);
+       OUT_BATCH(0);   /* reserved */
+}
+
+static void
+gen7_upload_primitive(ScrnInfoPtr scrn)
+{
+       intel_screen_private *intel = intel_get_screen_private(scrn);
+
+       OUT_BATCH(BRW_3DPRIMITIVE | (7 - 2));
+       OUT_BATCH(_3DPRIM_RECTLIST |
+               GEN7_3DPRIM_VERTEXBUFFER_ACCESS_SEQUENTIAL);
+       OUT_BATCH(3); /* vertex count per instance */
+       OUT_BATCH(0); /* start vertex offset */
+       OUT_BATCH(1); /* single instance */
+       OUT_BATCH(0); /* start instance location */
+       OUT_BATCH(0);
+}
+
+static void
+gen7_emit_video_setup(ScrnInfoPtr scrn,
+               drm_intel_bo *surface_state_binding_table_bo, int n_src_surf,
+               PixmapPtr pixmap,
+               drm_intel_bo *vertex_bo, uint32_t end_address_offset)
+{
+       intel_screen_private *intel = intel_get_screen_private(scrn);
+
+       assert(n_src_surf == 1 || n_src_surf == 6);
+       IntelEmitInvarientState(scrn);
+       intel->last_3d = LAST_3D_VIDEO;
+       intel->needs_3d_invariant = TRUE;
+
+       gen6_upload_invariant_states(intel);
+       gen6_upload_state_base_address(scrn, surface_state_binding_table_bo);
+       gen7_upload_viewport_state_pointers(intel, intel->video.gen4_cc_vp_bo);
+       gen7_upload_urb(intel);
+       gen7_upload_cc_state_pointers(intel, intel->video.gen6_blend_bo, intel->video.gen4_cc_bo, intel->video.gen6_depth_stencil_bo, 0);
+       gen7_upload_sampler_state_pointers(intel, intel->video.gen4_sampler_bo);
+       gen7_upload_bypass_states(intel);
+       gen6_upload_vs_state(intel);
+       gen6_upload_clip_state(intel);
+       gen7_upload_sf_state(intel, 1, 0);
+       gen7_upload_wm_state(scrn, n_src_surf == 1 ? TRUE : FALSE);
+       gen7_upload_binding_table(intel, (n_src_surf + 1) * SURFACE_STATE_PADDED_SIZE);
+       gen7_upload_depth_buffer_state(intel);
        gen6_upload_drawing_rectangle(scrn, pixmap);
        gen6_upload_vertex_element_state(scrn);
+       gen7_upload_vertex_buffer(scrn, vertex_bo, end_address_offset);
+       gen7_upload_primitive(scrn);
 }
 
 void Gen6DisplayVideoTextured(ScrnInfoPtr scrn,
@@ -1718,6 +1773,29 @@ void Gen6DisplayVideoTextured(ScrnInfoPtr scrn,
        int src_height[6];
        int src_pitch[6];
        drm_intel_bo *surface_state_binding_table_bo;
+       void (*create_dst_surface_state)(ScrnInfoPtr,
+                                       PixmapPtr, 
+                                       drm_intel_bo *, 
+                                       uint32_t);
+       void (*create_src_surface_state)(ScrnInfoPtr,
+                                       drm_intel_bo *,
+                                       uint32_t, int, 
+                                       int, int, uint32_t, 
+                                       drm_intel_bo *, uint32_t);
+       void (*emit_video_setup)(ScrnInfoPtr,
+                               drm_intel_bo *, int,
+                               PixmapPtr,
+                               drm_intel_bo *, uint32_t);
+
+       if (INTEL_INFO(intel)->gen >= 70) {
+               create_dst_surface_state = gen7_create_dst_surface_state;
+               create_src_surface_state = gen7_create_src_surface_state;
+               emit_video_setup = gen7_emit_video_setup;
+       } else {
+               create_dst_surface_state = i965_create_dst_surface_state;
+               create_src_surface_state = i965_create_src_surface_state;
+               emit_video_setup = gen6_emit_video_setup;
+       }
 
        src_surf_base[0] = adaptor_priv->YBufOffset;
        src_surf_base[1] = adaptor_priv->YBufOffset;
@@ -1753,16 +1831,16 @@ void Gen6DisplayVideoTextured(ScrnInfoPtr scrn,
        surface_state_binding_table_bo = 
                drm_intel_bo_alloc(intel->bufmgr,
                                "surface state & binding table",
-                               (n_src_surf + 1) * (ALIGN(sizeof(struct brw_surface_state), 32) + sizeof(uint32_t)),
+                               (n_src_surf + 1) * (SURFACE_STATE_PADDED_SIZE + sizeof(uint32_t)),
                                4096);
 
        if (!surface_state_binding_table_bo)
                return;
                                
-       i965_create_dst_surface_state(scrn, pixmap, surface_state_binding_table_bo, 0);
+       create_dst_surface_state(scrn, pixmap, surface_state_binding_table_bo, 0);
 
        for (src_surf = 0; src_surf < n_src_surf; src_surf++) {
-               i965_create_src_surface_state(scrn,
+               create_src_surface_state(scrn,
                                        adaptor_priv->buf,
                                        src_surf_base[src_surf],
                                        src_width[src_surf],
@@ -1770,7 +1848,7 @@ void Gen6DisplayVideoTextured(ScrnInfoPtr scrn,
                                        src_pitch[src_surf],
                                        src_surf_format,
                                        surface_state_binding_table_bo,
-                                       (src_surf + 1) * ALIGN(sizeof(struct brw_surface_state), 32));
+                                       (src_surf + 1) * SURFACE_STATE_PADDED_SIZE);
        }
 
        i965_create_binding_table(scrn, surface_state_binding_table_bo, n_src_surf + 1);
@@ -1806,8 +1884,7 @@ void Gen6DisplayVideoTextured(ScrnInfoPtr scrn,
                int box_x2 = pbox->x2;
                int box_y2 = pbox->y2;
                int i;
-               drm_intel_bo *vb_bo;
-               float *vb;
+               float vb[12];
                drm_intel_bo *bo_table[] = {
                        NULL,   /* vb_bo */
                        intel->batch_bo,
@@ -1823,11 +1900,6 @@ void Gen6DisplayVideoTextured(ScrnInfoPtr scrn,
 
                pbox++;
 
-               if (intel_alloc_and_map(intel, "textured video vb", 4096,
-                                               &vb_bo, &vb) != 0)
-                       break;
-               bo_table[0] = vb_bo;
-
                i = 0;
                vb[i++] = (box_x2 - dxo) * src_scale_x;
                vb[i++] = (box_y2 - dyo) * src_scale_y;
@@ -1844,7 +1916,9 @@ void Gen6DisplayVideoTextured(ScrnInfoPtr scrn,
                vb[i++] = (float)box_x1 + pix_xoff;
                vb[i++] = (float)box_y1 + pix_yoff;
 
-               drm_intel_bo_unmap(vb_bo);
+               bo_table[0] = intel_bo_alloc_for_data(intel,
+                                                     vb, sizeof(vb),
+                                                     "video vbo");
 
                /* If this command won't fit in the current batch, flush.
                 * Assume that it does after being flushed.
@@ -1853,31 +1927,10 @@ void Gen6DisplayVideoTextured(ScrnInfoPtr scrn,
                        intel_batch_submit(scrn);
 
                intel_batch_start_atomic(scrn, 200);
-               gen6_emit_video_setup(scrn, surface_state_binding_table_bo, n_src_surf, pixmap);
-
-               /* Set up the pointer to our vertex buffer */
-               OUT_BATCH(BRW_3DSTATE_VERTEX_BUFFERS | (5 - 2));
-               /* four 32-bit floats per vertex */
-               OUT_BATCH((0 << GEN6_VB0_BUFFER_INDEX_SHIFT) |
-                       GEN6_VB0_VERTEXDATA | 
-                       ((4 * 4) << VB0_BUFFER_PITCH_SHIFT));
-               OUT_RELOC(vb_bo, I915_GEM_DOMAIN_VERTEX, 0, 0);
-               OUT_RELOC(vb_bo, I915_GEM_DOMAIN_VERTEX, 0, i * 4);
-               OUT_BATCH(0);   /* reserved */
-
-               OUT_BATCH(BRW_3DPRIMITIVE | 
-                       BRW_3DPRIMITIVE_VERTEX_SEQUENTIAL | 
-                       (_3DPRIM_RECTLIST << BRW_3DPRIMITIVE_TOPOLOGY_SHIFT) | 
-                       (0 << 9) | /* Internal Vertex Count */
-                       (6 - 2));
-               OUT_BATCH(3);   /* vertex count per instance */
-               OUT_BATCH(0);   /* start vertex offset */
-               OUT_BATCH(1);   /* single instance */
-               OUT_BATCH(0);   /* start instance location */
-               OUT_BATCH(0);   /* index buffer offset, ignored */
-
+               emit_video_setup(scrn, surface_state_binding_table_bo, n_src_surf, pixmap, bo_table[0], i * 4);
                intel_batch_end_atomic(scrn);
-               drm_intel_bo_unreference(vb_bo);
+
+               drm_intel_bo_unreference(bo_table[0]);
        }
 
        /* release reference once we're finished */
index 2b114c3..a5603fe 100644 (file)
@@ -53,138 +53,52 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 #include "xf86_OSproc.h"
 #include "compiler.h"
-#include "xf86PciInfo.h"
 #include "xf86Pci.h"
 #include "xf86Cursor.h"
 #include "xf86xv.h"
-#include "vgaHW.h"
 #include "xf86Crtc.h"
 #include "xf86RandR12.h"
 
 #include "xorg-server.h"
 #include <pciaccess.h>
 
-#include "xf86drm.h"
-#include "sarea.h"
 #define _XF86DRI_SERVER_
-#include "dri.h"
 #include "dri2.h"
 #include "intel_bufmgr.h"
 #include "i915_drm.h"
 
 #include "intel_driver.h"
+#include "intel_options.h"
+#include "intel_list.h"
+#include "compat-api.h"
 
 #if HAVE_UDEV
 #include <libudev.h>
 #endif
 
-#include "uxa.h"
-/* XXX
- * The X server gained an *almost* identical implementation in 1.9.
- *
- * Remove this duplicate code either in 2.16 (when we can depend upon 1.9)
- * or the drivers are merged back into the xserver tree, whichever happens
- * earlier.
- */
-
-#ifndef _LIST_H_
-/* classic doubly-link circular list */
-struct list {
-       struct list *next, *prev;
-};
-
-static void
-list_init(struct list *list)
-{
-       list->next = list->prev = list;
-}
-
-static inline void
-__list_add(struct list *entry,
-           struct list *prev,
-           struct list *next)
-{
-       next->prev = entry;
-       entry->next = next;
-       entry->prev = prev;
-       prev->next = entry;
-}
-
-static inline void
-list_add(struct list *entry, struct list *head)
-{
-       __list_add(entry, head, head->next);
-}
-
-static inline void
-__list_del(struct list *prev, struct list *next)
-{
-       next->prev = prev;
-       prev->next = next;
-}
-
-static inline void
-list_del(struct list *entry)
-{
-       __list_del(entry->prev, entry->next);
-       list_init(entry);
-}
-
-static inline Bool
-list_is_empty(struct list *head)
-{
-       return head->next == head;
-}
-#endif
-
-/* XXX work around a broken define in list.h currently [ickle 20100713] */
-#undef container_of
-
-#ifndef container_of
-#define container_of(ptr, type, member) \
-       ((type *)((char *)(ptr) - (char *) &((type *)0)->member))
-#endif
-
-#ifndef list_entry
-#define list_entry(ptr, type, member) \
-       container_of(ptr, type, member)
-#endif
-
-#ifndef list_first_entry
-#define list_first_entry(ptr, type, member) \
-       list_entry((ptr)->next, type, member)
-#endif
-
-#ifndef list_foreach
-#define list_foreach(pos, head)                        \
-       for (pos = (head)->next; pos != (head); pos = pos->next)
-#endif
-
-/* XXX list.h from xserver-1.9 uses a GCC-ism to avoid having to pass type */
-#ifndef list_foreach_entry
-#define list_foreach_entry(pos, type, head, member)            \
-       for (pos = list_entry((head)->next, type, member);\
-            &pos->member != (head);                                    \
-            pos = list_entry(pos->member.next, type, member))
-#endif
-
 /* remain compatible to xorg-server 1.6 */
 #ifndef MONITOR_EDID_COMPLETE_RAWDATA
 #define MONITOR_EDID_COMPLETE_RAWDATA EDID_COMPLETE_RAWDATA
 #endif
 
+#if XF86_CRTC_VERSION >= 5
+#define INTEL_PIXMAP_SHARING 1
+#endif
+
 struct intel_pixmap {
        dri_bo *bo;
 
-       struct list flush, batch, in_flight;
+       struct list batch;
 
-       uint16_t src_bound, dst_bound;
        uint16_t stride;
        uint8_t tiling;
        int8_t busy :2;
-       int8_t batch_write :1;
-       int8_t offscreen :1;
-       int8_t pinned :1;
+       uint8_t dirty :1;
+       uint8_t offscreen :1;
+       uint8_t pinned :3;
+#define PIN_SCANOUT 0x1
+#define PIN_DRI 0x2
+#define PIN_GLAMOR 0x4
 };
 
 #if HAS_DEVPRIVATEKEYREC
@@ -216,7 +130,7 @@ static inline void intel_set_pixmap_private(PixmapPtr pixmap, struct intel_pixma
 
 static inline Bool intel_pixmap_is_dirty(PixmapPtr pixmap)
 {
-       return !list_is_empty(&intel_get_pixmap_private(pixmap)->flush);
+       return pixmap && intel_get_pixmap_private(pixmap)->dirty;
 }
 
 static inline Bool intel_pixmap_tiled(PixmapPtr pixmap)
@@ -229,12 +143,6 @@ void intel_set_pixmap_bo(PixmapPtr pixmap, dri_bo * bo);
 
 #include "common.h"
 
-#ifdef XvMCExtension
-#ifdef ENABLE_XVMC
-#define INTEL_XVMC 1
-#endif
-#endif
-
 #define PITCH_NONE 0
 
 /** enumeration of 3d consumers so some can maintain invariant state. */
@@ -260,11 +168,10 @@ typedef struct intel_screen_private {
        unsigned int current_batch;
 
        void *modes;
-       drm_intel_bo *front_buffer;
+       drm_intel_bo *front_buffer, *back_buffer;
+       PixmapPtr back_pixmap;
+       unsigned int back_name;
        long front_pitch, front_tiling;
-       void *shadow_buffer;
-       int shadow_stride;
-       DamagePtr shadow_damage;
 
        dri_bufmgr *bufmgr;
 
@@ -281,8 +188,8 @@ typedef struct intel_screen_private {
        /** Ending batch_used that was verified by intel_start_batch_atomic() */
        int batch_atomic_limit;
        struct list batch_pixmaps;
-       struct list flush_pixmaps;
-       struct list in_flight;
+       drm_intel_bo *wa_scratch_bo;
+       OsTimerPtr cache_expire;
 
        /* For Xvideo */
        Bool use_overlay;
@@ -307,7 +214,7 @@ typedef struct intel_screen_private {
        int Chipset;
        EntityInfoPtr pEnt;
        struct pci_device *PciInfo;
-       struct intel_chipset chipset;
+       const struct intel_device_info *info;
 
        unsigned int BR[20];
 
@@ -319,7 +226,8 @@ typedef struct intel_screen_private {
        void (*batch_flush) (struct intel_screen_private *intel);
        void (*batch_commit_notify) (struct intel_screen_private *intel);
 
-       uxa_driver_t *uxa_driver;
+       struct _UxaDriver *uxa_driver;
+       int uxa_flags;
        Bool need_sync;
        int accel_pixmap_offset_alignment;
        int accel_max_x;
@@ -359,15 +267,9 @@ typedef struct intel_screen_private {
 
        PixmapPtr render_source, render_mask, render_dest;
        PicturePtr render_source_picture, render_mask_picture, render_dest_picture;
-       CARD32 render_source_solid;
-       CARD32 render_mask_solid;
-       PixmapPtr render_current_dest;
-       Bool render_source_is_solid;
-       Bool render_mask_is_solid;
        Bool needs_3d_invariant;
        Bool needs_render_state_emit;
        Bool needs_render_vertex_emit;
-       Bool needs_render_ca_pass;
 
        /* i830 render accel state */
        uint32_t render_dest_format;
@@ -423,11 +325,12 @@ typedef struct intel_screen_private {
        char *deviceName;
 
        Bool use_pageflipping;
+       Bool use_triple_buffer;
        Bool force_fallback;
-       Bool can_blt;
        Bool has_kernel_flush;
        Bool needs_flush;
-       Bool use_shadow;
+
+       struct _DRI2FrameEvent *pending_flip[2];
 
        /* Broken-out options. */
        OptionInfoPtr Options;
@@ -446,8 +349,13 @@ typedef struct intel_screen_private {
        struct udev_monitor *uevent_monitor;
        InputHandlerProc uevent_handler;
 #endif
+       Bool has_prime_vmap_flush;
 } intel_screen_private;
 
+#ifndef I915_PARAM_HAS_PRIME_VMAP_FLUSH
+#define I915_PARAM_HAS_PRIME_VMAP_FLUSH 21
+#endif
+
 enum {
        DEBUG_FLUSH_BATCHES = 0x1,
        DEBUG_FLUSH_CACHES = 0x2,
@@ -456,15 +364,18 @@ enum {
 
 extern Bool intel_mode_pre_init(ScrnInfoPtr pScrn, int fd, int cpp);
 extern void intel_mode_init(struct intel_screen_private *intel);
+extern void intel_mode_disable_unused_functions(ScrnInfoPtr scrn);
 extern void intel_mode_remove_fb(intel_screen_private *intel);
 extern void intel_mode_fini(intel_screen_private *intel);
 
 extern int intel_get_pipe_from_crtc_id(drm_intel_bufmgr *bufmgr, xf86CrtcPtr crtc);
 extern int intel_crtc_id(xf86CrtcPtr crtc);
 extern int intel_output_dpms_status(xf86OutputPtr output);
+extern void intel_copy_fb(ScrnInfoPtr scrn);
 
 enum DRI2FrameEventType {
        DRI2_SWAP,
+       DRI2_SWAP_CHAIN,
        DRI2_FLIP,
        DRI2_WAITMSC,
 };
@@ -475,17 +386,23 @@ typedef void (*DRI2SwapEventPtr)(ClientPtr client, void *data, int type,
 #endif
 
 typedef struct _DRI2FrameEvent {
+       struct intel_screen_private *intel;
+
        XID drawable_id;
-       XID client_id;  /* fake client ID to track client destruction */
        ClientPtr client;
        enum DRI2FrameEventType type;
        int frame;
+       int pipe;
+
+       struct list drawable_resource, client_resource;
 
        /* for swaps & flips only */
        DRI2SwapEventPtr event_complete;
        void *event_data;
        DRI2BufferPtr front;
        DRI2BufferPtr back;
+
+       struct _DRI2FrameEvent *chain;
 } DRI2FrameEventRec, *DRI2FrameEventPtr;
 
 extern Bool intel_do_pageflip(intel_screen_private *intel,
@@ -498,9 +415,17 @@ intel_get_screen_private(ScrnInfoPtr scrn)
        return (intel_screen_private *)(scrn->driverPrivate);
 }
 
+#ifndef ARRAY_SIZE
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
+#endif
+
+#ifndef ALIGN
 #define ALIGN(i,m)     (((i) + (m) - 1) & ~((m) - 1))
+#endif
+
+#ifndef MIN
 #define MIN(a,b)       ((a) < (b) ? (a) : (b))
+#endif
 
 static inline unsigned long intel_pixmap_pitch(PixmapPtr pixmap)
 {
@@ -535,7 +460,6 @@ int intel_crtc_to_pipe(xf86CrtcPtr crtc);
 unsigned long intel_get_fence_size(intel_screen_private *intel, unsigned long size);
 unsigned long intel_get_fence_pitch(intel_screen_private *intel, unsigned long pitch,
                                   uint32_t tiling_mode);
-void intel_set_gem_max_sizes(ScrnInfoPtr scrn);
 
 drm_intel_bo *intel_allocate_framebuffer(ScrnInfoPtr scrn,
                                        int w, int h, int cpp,
@@ -587,6 +511,37 @@ void i965_vertex_flush(intel_screen_private *intel);
 void i965_batch_flush(intel_screen_private *intel);
 void i965_batch_commit_notify(intel_screen_private *intel);
 
+/* i965_3d.c */
+void gen6_upload_invariant_states(intel_screen_private *intel);
+void gen6_upload_viewport_state_pointers(intel_screen_private *intel,
+                                        drm_intel_bo *cc_vp_bo);
+void gen7_upload_viewport_state_pointers(intel_screen_private *intel,
+                                        drm_intel_bo *cc_vp_bo);
+void gen6_upload_urb(intel_screen_private *intel);
+void gen7_upload_urb(intel_screen_private *intel);
+void gen6_upload_cc_state_pointers(intel_screen_private *intel,
+                                  drm_intel_bo *blend_bo, drm_intel_bo *cc_bo,
+                                  drm_intel_bo *depth_stencil_bo,
+                                  uint32_t blend_offset);
+void gen7_upload_cc_state_pointers(intel_screen_private *intel,
+                                  drm_intel_bo *blend_bo, drm_intel_bo *cc_bo,
+                                  drm_intel_bo *depth_stencil_bo,
+                                  uint32_t blend_offset);
+void gen6_upload_sampler_state_pointers(intel_screen_private *intel,
+                                       drm_intel_bo *sampler_bo);
+void gen7_upload_sampler_state_pointers(intel_screen_private *intel,
+                                       drm_intel_bo *sampler_bo);
+void gen7_upload_bypass_states(intel_screen_private *intel);
+void gen6_upload_gs_state(intel_screen_private *intel);
+void gen6_upload_vs_state(intel_screen_private *intel);
+void gen6_upload_clip_state(intel_screen_private *intel);
+void gen6_upload_sf_state(intel_screen_private *intel, int num_sf_outputs, int read_offset);
+void gen7_upload_sf_state(intel_screen_private *intel, int num_sf_outputs, int read_offset);
+void gen6_upload_binding_table(intel_screen_private *intel, uint32_t ps_binding_table_offset);
+void gen7_upload_binding_table(intel_screen_private *intel, uint32_t ps_binding_table_offset);
+void gen6_upload_depth_buffer_state(intel_screen_private *intel);
+void gen7_upload_depth_buffer_state(intel_screen_private *intel);
+
 Bool intel_transform_is_affine(PictTransformPtr t);
 Bool
 intel_get_transformed_coordinates(int x, int y, PictTransformPtr transform,
@@ -597,7 +552,7 @@ intel_get_transformed_coordinates_3d(int x, int y, PictTransformPtr transform,
                                    float *x_out, float *y_out, float *z_out);
 
 static inline void
-intel_debug_fallback(ScrnInfoPtr scrn, char *format, ...)
+intel_debug_fallback(ScrnInfoPtr scrn, const char *format, ...)
 {
        intel_screen_private *intel = intel_get_screen_private(scrn);
        va_list ap;
@@ -615,7 +570,7 @@ intel_check_pitch_2d(PixmapPtr pixmap)
 {
        uint32_t pitch = intel_pixmap_pitch(pixmap);
        if (pitch > KB(32)) {
-               ScrnInfoPtr scrn = xf86Screens[pixmap->drawable.pScreen->myNum];
+               ScrnInfoPtr scrn = xf86ScreenToScrn(pixmap->drawable.pScreen);
                intel_debug_fallback(scrn, "pitch exceeds 2d limit 32K\n");
                return FALSE;
        }
@@ -628,7 +583,7 @@ intel_check_pitch_3d(PixmapPtr pixmap)
 {
        uint32_t pitch = intel_pixmap_pitch(pixmap);
        if (pitch > KB(8)) {
-               ScrnInfoPtr scrn = xf86Screens[pixmap->drawable.pScreen->myNum];
+               ScrnInfoPtr scrn = xf86ScreenToScrn(pixmap->drawable.pScreen);
                intel_debug_fallback(scrn, "pitch exceeds 3d limit 8K\n");
                return FALSE;
        }
@@ -655,14 +610,19 @@ intel_emit_reloc(drm_intel_bo * bo, uint32_t offset,
 static inline drm_intel_bo *intel_bo_alloc_for_data(intel_screen_private *intel,
                                                    const void *data,
                                                    unsigned int size,
-                                                   char *name)
+                                                   const char *name)
 {
        drm_intel_bo *bo;
+       int ret;
 
        bo = drm_intel_bo_alloc(intel->bufmgr, name, size, 4096);
-       if (bo)
-               drm_intel_bo_subdata(bo, 0, size, data);
+       assert(bo);
+
+       ret = drm_intel_bo_subdata(bo, 0, size, data);
+       assert(ret == 0);
+
        return bo;
+       (void)ret;
 }
 
 void intel_debug_flush(ScrnInfoPtr scrn);
@@ -684,16 +644,16 @@ static inline Bool pixmap_is_scanout(PixmapPtr pixmap)
        return pixmap == screen->GetScreenPixmap(screen);
 }
 
-const OptionInfoRec *intel_uxa_available_options(int chipid, int busid);
-
 Bool intel_uxa_init(ScreenPtr pScreen);
 Bool intel_uxa_create_screen_resources(ScreenPtr pScreen);
 void intel_uxa_block_handler(intel_screen_private *intel);
 Bool intel_get_aperture_space(ScrnInfoPtr scrn, drm_intel_bo ** bo_table,
                              int num_bos);
 
-/* intel_shadow.c */
-void intel_shadow_blt(intel_screen_private *intel);
-void intel_shadow_create(struct intel_screen_private *intel);
+static inline Bool intel_pixmap_is_offscreen(PixmapPtr pixmap)
+{
+       struct intel_pixmap *priv = intel_get_pixmap_private(pixmap);
+       return priv && priv->offscreen;
+}
 
 #endif /* _I830_H_ */
index 289ed2b..46f22bc 100644 (file)
@@ -40,6 +40,8 @@
 #include "i915_drm.h"
 #include "i965_reg.h"
 
+#include "uxa.h"
+
 #define DUMP_BATCHBUFFERS NULL // "/tmp/i915-batchbuffers.dump"
 
 static void intel_end_vertex(intel_screen_private *intel)
@@ -112,29 +114,44 @@ void intel_batch_teardown(ScrnInfoPtr scrn)
 
        while (!list_is_empty(&intel->batch_pixmaps))
                list_del(intel->batch_pixmaps.next);
+}
 
-       while (!list_is_empty(&intel->flush_pixmaps))
-               list_del(intel->flush_pixmaps.next);
-
-       while (!list_is_empty(&intel->in_flight)) {
-               struct intel_pixmap *entry;
-
-               entry = list_first_entry(&intel->in_flight,
-                                        struct intel_pixmap,
-                                        in_flight);
+static void intel_batch_do_flush(ScrnInfoPtr scrn)
+{
+       intel_screen_private *intel = intel_get_screen_private(scrn);
+       struct intel_pixmap *priv;
 
-               dri_bo_unreference(entry->bo);
-               list_del(&entry->in_flight);
-               free(entry);
-       }
+       list_for_each_entry(priv, &intel->batch_pixmaps, batch)
+               priv->dirty = 0;
 }
 
-void intel_batch_do_flush(ScrnInfoPtr scrn)
+static void intel_emit_post_sync_nonzero_flush(ScrnInfoPtr scrn)
 {
        intel_screen_private *intel = intel_get_screen_private(scrn);
 
-       while (!list_is_empty(&intel->flush_pixmaps))
-               list_del(intel->flush_pixmaps.next);
+       /* keep this entire sequence of 3 PIPE_CONTROL cmds in one batch to
+        * avoid upsetting the gpu. */
+       BEGIN_BATCH(3*4);
+       OUT_BATCH(BRW_PIPE_CONTROL | (4 - 2));
+       OUT_BATCH(BRW_PIPE_CONTROL_CS_STALL |
+                 BRW_PIPE_CONTROL_STALL_AT_SCOREBOARD);
+       OUT_BATCH(0); /* address */
+       OUT_BATCH(0); /* write data */
+
+       OUT_BATCH(BRW_PIPE_CONTROL | (4 - 2));
+       OUT_BATCH(BRW_PIPE_CONTROL_WRITE_QWORD);
+       OUT_RELOC(intel->wa_scratch_bo,
+                 I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION, 0);
+       OUT_BATCH(0); /* write data */
+
+       /* now finally the _real flush */
+       OUT_BATCH(BRW_PIPE_CONTROL | (4 - 2));
+       OUT_BATCH(BRW_PIPE_CONTROL_WC_FLUSH |
+                 BRW_PIPE_CONTROL_TC_FLUSH |
+                 BRW_PIPE_CONTROL_NOWRITE);
+       OUT_BATCH(0); /* write address */
+       OUT_BATCH(0); /* write data */
+       ADVANCE_BATCH();
 }
 
 void intel_batch_emit_flush(ScrnInfoPtr scrn)
@@ -154,14 +171,19 @@ void intel_batch_emit_flush(ScrnInfoPtr scrn)
                        OUT_BATCH(0);
                        ADVANCE_BATCH();
                } else  {
-                       BEGIN_BATCH(4);
-                       OUT_BATCH(BRW_PIPE_CONTROL | (4 - 2));
-                       OUT_BATCH(BRW_PIPE_CONTROL_WC_FLUSH |
-                                 BRW_PIPE_CONTROL_TC_FLUSH |
-                                 BRW_PIPE_CONTROL_NOWRITE);
-                       OUT_BATCH(0); /* write address */
-                       OUT_BATCH(0); /* write data */
-                       ADVANCE_BATCH();
+                       if ((INTEL_INFO(intel)->gen == 60)) {
+                               /* HW-Workaround for Sandybdrige */
+                               intel_emit_post_sync_nonzero_flush(scrn);
+                       } else {
+                               BEGIN_BATCH(4);
+                               OUT_BATCH(BRW_PIPE_CONTROL | (4 - 2));
+                               OUT_BATCH(BRW_PIPE_CONTROL_WC_FLUSH |
+                                         BRW_PIPE_CONTROL_TC_FLUSH |
+                                         BRW_PIPE_CONTROL_NOWRITE);
+                               OUT_BATCH(0); /* write address */
+                               OUT_BATCH(0); /* write data */
+                               ADVANCE_BATCH();
+                       }
                }
        } else {
                flags = MI_WRITE_DIRTY_STATE | MI_INVALIDATE_MAP_CACHE;
@@ -175,13 +197,6 @@ void intel_batch_emit_flush(ScrnInfoPtr scrn)
        intel_batch_do_flush(scrn);
 }
 
-static Bool intel_batch_needs_flush(intel_screen_private *intel)
-{
-       ScreenPtr screen = intel->scrn->pScreen;
-       PixmapPtr pixmap = screen->GetScreenPixmap(screen);
-       return intel_get_pixmap_private(pixmap)->batch_write;
-}
-
 void intel_batch_submit(ScrnInfoPtr scrn)
 {
        intel_screen_private *intel = intel_get_screen_private(scrn);
@@ -218,7 +233,9 @@ void intel_batch_submit(ScrnInfoPtr scrn)
                ret = drm_intel_bo_mrb_exec(intel->batch_bo,
                                intel->batch_used*4,
                                NULL, 0, 0xffffffff,
-                               IS_GEN6(intel) ? intel->current_batch: I915_EXEC_DEFAULT);
+                               (HAS_BLT(intel) ?
+                                intel->current_batch:
+                                I915_EXEC_DEFAULT));
        }
 
        if (ret != 0) {
@@ -229,7 +246,7 @@ void intel_batch_submit(ScrnInfoPtr scrn)
                        if (!once) {
                                xf86DrvMsg(scrn->scrnIndex, X_ERROR, "Detected a hung GPU, disabling acceleration.\n");
                                xf86DrvMsg(scrn->scrnIndex, X_ERROR, "When reporting this, please include i915_error_state from debugfs and the full dmesg.\n");
-                               uxa_set_force_fallback(screenInfo.screens[scrn->scrnIndex], TRUE);
+                               uxa_set_force_fallback(xf86ScrnToScreen(scrn), TRUE);
                                intel->force_fallback = TRUE;
                                once = 1;
                        }
@@ -241,8 +258,6 @@ void intel_batch_submit(ScrnInfoPtr scrn)
                }
        }
 
-       intel->needs_flush |= intel_batch_needs_flush(intel);
-
        while (!list_is_empty(&intel->batch_pixmaps)) {
                struct intel_pixmap *entry;
 
@@ -251,25 +266,10 @@ void intel_batch_submit(ScrnInfoPtr scrn)
                                         batch);
 
                entry->busy = -1;
-               entry->batch_write = 0;
+               entry->dirty = 0;
                list_del(&entry->batch);
        }
 
-       while (!list_is_empty(&intel->flush_pixmaps))
-               list_del(intel->flush_pixmaps.next);
-
-       while (!list_is_empty(&intel->in_flight)) {
-               struct intel_pixmap *entry;
-
-               entry = list_first_entry(&intel->in_flight,
-                                        struct intel_pixmap,
-                                        in_flight);
-
-               dri_bo_unreference(entry->bo);
-               list_del(&entry->in_flight);
-               free(entry);
-       }
-
        if (intel->debug_flush & DEBUG_FLUSH_WAIT)
                drm_intel_bo_wait_rendering(intel->batch_bo);
 
index 605932a..b2bb390 100644 (file)
@@ -36,7 +36,6 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 void intel_batch_init(ScrnInfoPtr scrn);
 void intel_batch_teardown(ScrnInfoPtr scrn);
 void intel_batch_emit_flush(ScrnInfoPtr scrn);
-void intel_batch_do_flush(ScrnInfoPtr scrn);
 void intel_batch_submit(ScrnInfoPtr scrn);
 
 static inline int intel_batch_space(intel_screen_private *intel)
@@ -50,14 +49,14 @@ static inline int intel_vertex_space(intel_screen_private *intel)
 }
 
 static inline void
-intel_batch_require_space(ScrnInfoPtr scrn, intel_screen_private *intel, unsigned int sz)
+intel_batch_require_space(ScrnInfoPtr scrn, intel_screen_private *intel, int sz)
 {
        assert(sz < intel->batch_bo->size - 8);
        if (intel_batch_space(intel) < sz)
                intel_batch_submit(scrn);
 }
 
-static inline void intel_batch_start_atomic(ScrnInfoPtr scrn, unsigned int sz)
+static inline void intel_batch_start_atomic(ScrnInfoPtr scrn, int sz)
 {
        intel_screen_private *intel = intel_get_screen_private(scrn);
 
@@ -132,11 +131,11 @@ intel_batch_mark_pixmap_domains(intel_screen_private *intel,
 
        if (list_is_empty(&priv->batch))
                list_add(&priv->batch, &intel->batch_pixmaps);
-       if (write_domain && list_is_empty(&priv->flush))
-               list_add(&priv->flush, &intel->flush_pixmaps);
 
-       priv->batch_write |= write_domain != 0;
+       priv->dirty |= write_domain != 0;
        priv->busy = 1;
+
+       intel->needs_flush |= write_domain != 0;
 }
 
 static inline void
index b6592c4..b2a5904 100644 (file)
 #include <unistd.h>
 #include <errno.h>
 #include <poll.h>
+#include <sys/ioctl.h>
 
 #include "xorgVersion.h"
 
 #include "intel.h"
 #include "intel_bufmgr.h"
+#include "intel_options.h"
+#include "xf86drm.h"
 #include "xf86drmMode.h"
 #include "X11/Xatom.h"
+#include "X11/extensions/dpmsconst.h"
+#include "xf86DDC.h"
+#include "fb.h"
+#include "uxa.h"
+
+#include "intel_glamor.h"
+
+#define KNOWN_MODE_FLAGS ((1<<14)-1)
 
 struct intel_mode {
        int fd;
@@ -77,6 +88,8 @@ struct intel_crtc {
        uint32_t rotate_fb_id;
        xf86CrtcPtr crtc;
        struct list link;
+       PixmapPtr scanout_pixmap;
+       uint32_t scanout_fb_id;
 };
 
 struct intel_property {
@@ -119,7 +132,9 @@ intel_output_dpms_backlight(xf86OutputPtr output, int oldmode, int mode);
  * List of available kernel interfaces in priority order
  */
 static const char *backlight_interfaces[] = {
+       "gmux_backlight",
        "asus-laptop",
+       "asus-nb-wmi",
        "eeepc",
        "thinkpad_screen",
        "mbp_backlight",
@@ -242,19 +257,36 @@ static void
 intel_output_backlight_init(xf86OutputPtr output)
 {
        struct intel_output *intel_output = output->driver_private;
+       intel_screen_private *intel = intel_get_screen_private(output->scrn);
+       char path[BACKLIGHT_PATH_LEN];
+       struct stat buf;
+       char *str;
        int i;
 
-       for (i = 0; backlight_interfaces[i] != NULL; i++) {
-               char path[BACKLIGHT_PATH_LEN];
-               struct stat buf;
+       str = xf86GetOptValString(intel->Options, OPTION_BACKLIGHT);
+       if (str != NULL) {
+               sprintf(path, "%s/%s", BACKLIGHT_CLASS, str);
+               if (!stat(path, &buf)) {
+                       intel_output->backlight_iface = str;
+                       intel_output->backlight_max = intel_output_backlight_get_max(output);
+                       if (intel_output->backlight_max > 0) {
+                               xf86DrvMsg(output->scrn->scrnIndex, X_CONFIG,
+                                          "found backlight control interface %s\n", path);
+                               return;
+                       }
+               }
+               xf86DrvMsg(output->scrn->scrnIndex, X_ERROR,
+                          "unrecognised backlight control interface %s\n", str);
+       }
 
+       for (i = 0; backlight_interfaces[i] != NULL; i++) {
                sprintf(path, "%s/%s", BACKLIGHT_CLASS, backlight_interfaces[i]);
                if (!stat(path, &buf)) {
                        intel_output->backlight_iface = backlight_interfaces[i];
                        intel_output->backlight_max = intel_output_backlight_get_max(output);
                        if (intel_output->backlight_max > 0) {
                                intel_output->backlight_active_level = intel_output_backlight_get(output);
-                               xf86DrvMsg(output->scrn->scrnIndex, X_INFO,
+                               xf86DrvMsg(output->scrn->scrnIndex, X_PROBED,
                                           "found backlight control interface %s\n", path);
                                return;
                        }
@@ -286,7 +318,7 @@ mode_from_kmode(ScrnInfoPtr scrn,
        mode->VTotal = kmode->vtotal;
        mode->VScan = kmode->vscan;
 
-       mode->Flags = kmode->flags; //& FLAG_BITS;
+       mode->Flags = kmode->flags;
        mode->name = strdup(kmode->name);
 
        if (kmode->type & DRM_MODE_TYPE_DRIVER)
@@ -294,6 +326,9 @@ mode_from_kmode(ScrnInfoPtr scrn,
        if (kmode->type & DRM_MODE_TYPE_PREFERRED)
                mode->type |= M_T_PREFERRED;
 
+       if (mode->status == MODE_OK && kmode->flags & ~KNOWN_MODE_FLAGS)
+               mode->status = MODE_BAD; /* unknown flags => unhandled */
+
        xf86SetModeCrtc (mode, scrn->adjustFlags);
 }
 
@@ -317,16 +352,31 @@ mode_to_kmode(ScrnInfoPtr scrn,
        kmode->vtotal = mode->VTotal;
        kmode->vscan = mode->VScan;
 
-       kmode->flags = mode->Flags; //& FLAG_BITS;
+       kmode->flags = mode->Flags;
        if (mode->name)
                strncpy(kmode->name, mode->name, DRM_DISPLAY_MODE_LEN);
        kmode->name[DRM_DISPLAY_MODE_LEN-1] = 0;
 }
 
 static void
-intel_crtc_dpms(xf86CrtcPtr intel_crtc, int mode)
+intel_crtc_dpms(xf86CrtcPtr crtc, int mode)
 {
+}
 
+void
+intel_mode_disable_unused_functions(ScrnInfoPtr scrn)
+{
+       xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+       struct intel_mode *mode = intel_get_screen_private(scrn)->modes;
+       int i;
+
+       /* Force off for consistency between kernel and ddx */
+       for (i = 0; i < xf86_config->num_crtc; i++) {
+               xf86CrtcPtr crtc = xf86_config->crtc[i];
+               if (!crtc->enabled)
+                       drmModeSetCrtc(mode->fd, crtc_id(crtc->driver_private),
+                                      0, 0, 0, NULL, 0, NULL);
+       }
 }
 
 static Bool
@@ -358,13 +408,15 @@ intel_crtc_apply(xf86CrtcPtr crtc)
                output_count++;
        }
 
+       if (!intel_crtc->scanout_fb_id) {
 #if XORG_VERSION_CURRENT < XORG_VERSION_NUMERIC(1,5,99,0,0)
-       if (!xf86CrtcRotate(crtc, mode, rotation))
-               goto done;
+               if (!xf86CrtcRotate(crtc, mode, rotation))
+                       goto done;
 #else
-       if (!xf86CrtcRotate(crtc))
-               goto done;
+               if (!xf86CrtcRotate(crtc))
+                       goto done;
 #endif
+       }
 
 #if XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1,7,0,0,0)
        crtc->funcs->gamma_set(crtc, crtc->gamma_red, crtc->gamma_green,
@@ -378,6 +430,10 @@ intel_crtc_apply(xf86CrtcPtr crtc)
                fb_id = intel_crtc->rotate_fb_id;
                x = 0;
                y = 0;
+       } else if (intel_crtc->scanout_fb_id && intel_crtc->scanout_pixmap->drawable.width >= crtc->mode.HDisplay && intel_crtc->scanout_pixmap->drawable.height >= crtc->mode.VDisplay) {
+               fb_id = intel_crtc->scanout_fb_id;
+               x = 0;
+               y = 0;
        }
        ret = drmModeSetCrtc(mode->fd, crtc_id(intel_crtc),
                             fb_id, x, y, output_ids, output_count,
@@ -405,8 +461,6 @@ intel_crtc_apply(xf86CrtcPtr crtc)
                }
        }
 
-       intel_set_gem_max_sizes(scrn);
-
        if (scrn->pScreen)
                xf86_reload_cursors(scrn->pScreen);
 
@@ -451,6 +505,7 @@ intel_crtc_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
        crtc->y = y;
        crtc->rotation = rotation;
 
+       intel_glamor_flush(intel);
        intel_batch_submit(crtc->scrn);
 
        mode_to_kmode(crtc->scrn, &intel_crtc->kmode, mode);
@@ -611,7 +666,7 @@ intel_crtc_shadow_destroy(xf86CrtcPtr crtc, PixmapPtr rotate_pixmap, void *data)
                intel_crtc->rotate_bo = NULL;
        }
 
-       intel->shadow_present = intel->use_shadow;
+       intel->shadow_present = FALSE;
 }
 
 static void
@@ -642,6 +697,40 @@ intel_crtc_destroy(xf86CrtcPtr crtc)
        crtc->driver_private = NULL;
 }
 
+#ifdef INTEL_PIXMAP_SHARING
+static Bool
+intel_set_scanout_pixmap(xf86CrtcPtr crtc, PixmapPtr ppix)
+{
+       struct intel_crtc *intel_crtc = crtc->driver_private;
+       ScrnInfoPtr scrn = crtc->scrn;
+       intel_screen_private *intel = intel_get_screen_private(scrn);
+       dri_bo *bo;
+
+       if (ppix == intel_crtc->scanout_pixmap)
+               return TRUE;
+
+       if (!ppix) {
+               intel_crtc->scanout_pixmap = NULL;
+               if (intel_crtc->scanout_fb_id) {
+                       drmModeRmFB(intel->drmSubFD, intel_crtc->scanout_fb_id);
+                       intel_crtc->scanout_fb_id = 0;
+               }
+               return TRUE;
+       }
+
+       bo = intel_get_pixmap_bo(ppix);
+       if (intel->front_buffer) {
+               ErrorF("have front buffer\n");
+       }
+
+       intel_crtc->scanout_pixmap = ppix;
+       return drmModeAddFB(intel->drmSubFD, ppix->drawable.width,
+                          ppix->drawable.height, ppix->drawable.depth,
+                          ppix->drawable.bitsPerPixel, ppix->devKind,
+                          bo->handle, &intel_crtc->scanout_fb_id) == 0;
+}
+#endif
+
 static const xf86CrtcFuncsRec intel_crtc_funcs = {
        .dpms = intel_crtc_dpms,
        .set_mode_major = intel_crtc_set_mode_major,
@@ -655,6 +744,9 @@ static const xf86CrtcFuncsRec intel_crtc_funcs = {
        .shadow_destroy = intel_crtc_shadow_destroy,
        .gamma_set = intel_crtc_gamma_set,
        .destroy = intel_crtc_destroy,
+#ifdef INTEL_PIXMAP_SHARING
+       .set_scanout_pixmap = intel_set_scanout_pixmap,
+#endif
 };
 
 static void
@@ -676,6 +768,11 @@ intel_crtc_init(ScrnInfoPtr scrn, struct intel_mode *mode, int num)
 
        intel_crtc->mode_crtc = drmModeGetCrtc(mode->fd,
                                               mode->mode_res->crtcs[num]);
+       if (intel_crtc->mode_crtc == NULL) {
+               free(intel_crtc);
+               return;
+       }
+
        intel_crtc->mode = mode;
        crtc->driver_private = intel_crtc;
 
@@ -683,8 +780,7 @@ intel_crtc_init(ScrnInfoPtr scrn, struct intel_mode *mode, int num)
                                                           crtc_id(intel_crtc));
 
        intel_crtc->cursor = drm_intel_bo_alloc(intel->bufmgr, "ARGB cursor",
-                                               HWCURSOR_SIZE_ARGB,
-                                               GTT_PAGE_SIZE);
+                                               4*64*64, 4096);
 
        intel_crtc->crtc = crtc;
        list_add(&intel_crtc->link, &mode->crtcs);
@@ -694,7 +790,7 @@ static Bool
 is_panel(int type)
 {
        return (type == DRM_MODE_CONNECTOR_LVDS ||
-               type == DRM_MODE_CONNECTOR_eDP);
+               type == DRM_MODE_CONNECTOR_eDP);
 }
 
 static xf86OutputStatus
@@ -708,6 +804,12 @@ intel_output_detect(xf86OutputPtr output)
        drmModeFreeConnector(intel_output->mode_output);
        intel_output->mode_output =
                drmModeGetConnector(mode->fd, intel_output->output_id);
+       if (intel_output->mode_output == NULL) {
+               /* and hope we are safe everywhere else */
+               xf86DrvMsg(output->scrn->scrnIndex, X_ERROR,
+                          "drmModeGetConnector failed, reporting output disconnected\n");
+               return XF86OutputStatusDisconnected;
+       }
 
        switch (intel_output->mode_output->connection) {
        case DRM_MODE_CONNECTED:
@@ -941,13 +1043,19 @@ intel_output_dpms(xf86OutputPtr output, int dpms)
                        continue;
 
                if (!strcmp(props->name, "DPMS")) {
+                       /* Make sure to reverse the order between on and off. */
+                       if (dpms == DPMSModeOff)
+                               intel_output_dpms_backlight(output,
+                                                           intel_output->dpms_mode,
+                                                           dpms);
                        drmModeConnectorSetProperty(mode->fd,
                                                    intel_output->output_id,
                                                    props->prop_id,
                                                    dpms);
-                       intel_output_dpms_backlight(output,
-                                                     intel_output->dpms_mode,
-                                                     dpms);
+                       if (dpms != DPMSModeOff)
+                               intel_output_dpms_backlight(output,
+                                                           intel_output->dpms_mode,
+                                                           dpms);
                        intel_output->dpms_mode = dpms;
                        drmModeFreeProperty(props);
                        return;
@@ -982,6 +1090,33 @@ intel_property_ignore(drmModePropertyPtr prop)
        return FALSE;
 }
 
+static void
+intel_output_create_ranged_atom(xf86OutputPtr output, Atom *atom,
+                               const char *name, INT32 min, INT32 max,
+                               uint64_t value, Bool immutable)
+{
+       int err;
+       INT32 atom_range[2];
+
+       atom_range[0] = min;
+       atom_range[1] = max;
+
+       *atom = MakeAtom(name, strlen(name), TRUE);
+
+       err = RRConfigureOutputProperty(output->randr_output, *atom, FALSE,
+                                       TRUE, immutable, 2, atom_range);
+       if (err != 0)
+               xf86DrvMsg(output->scrn->scrnIndex, X_ERROR,
+                          "RRConfigureOutputProperty error, %d\n", err);
+
+       err = RRChangeOutputProperty(output->randr_output, *atom, XA_INTEGER,
+                                    32, PropModeReplace, 1, &value, FALSE,
+                                    TRUE);
+       if (err != 0)
+               xf86DrvMsg(output->scrn->scrnIndex, X_ERROR,
+                          "RRChangeOutputProperty error, %d\n", err);
+}
+
 #define BACKLIGHT_NAME             "Backlight"
 #define BACKLIGHT_DEPRECATED_NAME  "BACKLIGHT"
 static Atom backlight_atom, backlight_deprecated_atom;
@@ -1021,30 +1156,18 @@ intel_output_create_resources(xf86OutputPtr output)
                drmModePropertyPtr drmmode_prop = p->mode_prop;
 
                if (drmmode_prop->flags & DRM_MODE_PROP_RANGE) {
-                       INT32 range[2];
-
                        p->num_atoms = 1;
                        p->atoms = calloc(p->num_atoms, sizeof(Atom));
                        if (!p->atoms)
                                continue;
 
-                       p->atoms[0] = MakeAtom(drmmode_prop->name, strlen(drmmode_prop->name), TRUE);
-                       range[0] = drmmode_prop->values[0];
-                       range[1] = drmmode_prop->values[1];
-                       err = RRConfigureOutputProperty(output->randr_output, p->atoms[0],
-                                                       FALSE, TRUE,
-                                                       drmmode_prop->flags & DRM_MODE_PROP_IMMUTABLE ? TRUE : FALSE,
-                                                       2, range);
-                       if (err != 0) {
-                               xf86DrvMsg(output->scrn->scrnIndex, X_ERROR,
-                                          "RRConfigureOutputProperty error, %d\n", err);
-                       }
-                       err = RRChangeOutputProperty(output->randr_output, p->atoms[0],
-                                                    XA_INTEGER, 32, PropModeReplace, 1, &p->value, FALSE, TRUE);
-                       if (err != 0) {
-                               xf86DrvMsg(output->scrn->scrnIndex, X_ERROR,
-                                          "RRChangeOutputProperty error, %d\n", err);
-                       }
+                       intel_output_create_ranged_atom(output, &p->atoms[0],
+                                                       drmmode_prop->name,
+                                                       drmmode_prop->values[0],
+                                                       drmmode_prop->values[1],
+                                                       p->value,
+                                                       drmmode_prop->flags & DRM_MODE_PROP_IMMUTABLE ? TRUE : FALSE);
+
                } else if (drmmode_prop->flags & DRM_MODE_PROP_ENUM) {
                        p->num_atoms = drmmode_prop->count_enums + 1;
                        p->atoms = calloc(p->num_atoms, sizeof(Atom));
@@ -1080,50 +1203,21 @@ intel_output_create_resources(xf86OutputPtr output)
        }
 
        if (intel_output->backlight_iface) {
-               INT32 data, backlight_range[2];
-
                /* Set up the backlight property, which takes effect
                 * immediately and accepts values only within the
                 * backlight_range.
                 */
-               backlight_atom = MakeAtom(BACKLIGHT_NAME, sizeof(BACKLIGHT_NAME) - 1, TRUE);
-               backlight_deprecated_atom = MakeAtom(BACKLIGHT_DEPRECATED_NAME,
-                                                    sizeof(BACKLIGHT_DEPRECATED_NAME) - 1, TRUE);
-
-               backlight_range[0] = 0;
-               backlight_range[1] = intel_output->backlight_max;
-               err = RRConfigureOutputProperty(output->randr_output,
-                                               backlight_atom,
-                                               FALSE, TRUE, FALSE,
-                                               2, backlight_range);
-               if (err != 0) {
-                       xf86DrvMsg(output->scrn->scrnIndex, X_ERROR,
-                                  "RRConfigureOutputProperty error, %d\n", err);
-               }
-               err = RRConfigureOutputProperty(output->randr_output,
-                                               backlight_deprecated_atom,
-                                               FALSE, TRUE, FALSE,
-                                               2, backlight_range);
-               if (err != 0) {
-                       xf86DrvMsg(output->scrn->scrnIndex, X_ERROR,
-                                  "RRConfigureOutputProperty error, %d\n", err);
-               }
-               /* Set the current value of the backlight property */
-               data = intel_output->backlight_active_level;
-               err = RRChangeOutputProperty(output->randr_output, backlight_atom,
-                                            XA_INTEGER, 32, PropModeReplace, 1, &data,
-                                            FALSE, TRUE);
-               if (err != 0) {
-                       xf86DrvMsg(output->scrn->scrnIndex, X_ERROR,
-                                  "RRChangeOutputProperty error, %d\n", err);
-               }
-               err = RRChangeOutputProperty(output->randr_output, backlight_deprecated_atom,
-                                            XA_INTEGER, 32, PropModeReplace, 1, &data,
-                                            FALSE, TRUE);
-               if (err != 0) {
-                       xf86DrvMsg(output->scrn->scrnIndex, X_ERROR,
-                                  "RRChangeOutputProperty error, %d\n", err);
-               }
+               intel_output_create_ranged_atom(output, &backlight_atom,
+                                       BACKLIGHT_NAME, 0,
+                                       intel_output->backlight_max,
+                                       intel_output->backlight_active_level,
+                                       FALSE);
+               intel_output_create_ranged_atom(output,
+                                       &backlight_deprecated_atom,
+                                       BACKLIGHT_DEPRECATED_NAME, 0,
+                                       intel_output->backlight_max,
+                                       intel_output->backlight_active_level,
+                                       FALSE);
        }
 }
 
@@ -1180,6 +1274,8 @@ intel_output_set_property(xf86OutputPtr output, Atom property,
                                return FALSE;
                        memcpy(&atom, value->data, 4);
                        name = NameForAtom(atom);
+                       if (name == NULL)
+                               return FALSE;
 
                        /* search for matching name string, then set its value down */
                        for (j = 0; j < p->mode_prop->count_enums; j++) {
@@ -1359,10 +1455,12 @@ intel_xf86crtc_resize(ScrnInfoPtr scrn, int width, int height)
        int         i, old_width, old_height, old_pitch;
        unsigned long pitch;
        uint32_t tiling;
+       ScreenPtr screen;
 
        if (scrn->virtualX == width && scrn->virtualY == height)
                return TRUE;
 
+       intel_glamor_flush(intel);
        intel_batch_submit(scrn);
 
        old_width = scrn->virtualX;
@@ -1371,6 +1469,17 @@ intel_xf86crtc_resize(ScrnInfoPtr scrn, int width, int height)
        old_fb_id = mode->fb_id;
        old_front = intel->front_buffer;
 
+       if (intel->back_pixmap) {
+               screen = intel->back_pixmap->drawable.pScreen;
+               screen->DestroyPixmap(intel->back_pixmap);
+               intel->back_pixmap = NULL;
+       }
+
+       if (intel->back_buffer) {
+               drm_intel_bo_unreference(intel->back_buffer);
+               intel->back_buffer = NULL;
+       }
+
        intel->front_buffer = intel_allocate_framebuffer(scrn,
                                                         width, height,
                                                         intel->cpp,
@@ -1436,17 +1545,20 @@ intel_do_pageflip(intel_screen_private *intel,
        struct intel_mode *mode = crtc->mode;
        unsigned int pitch = scrn->displayWidth * intel->cpp;
        struct intel_pageflip *flip;
-       int i, old_fb_id;
+       uint32_t new_fb_id;
+       int i;
 
        /*
         * Create a new handle for the back buffer
         */
-       old_fb_id = mode->fb_id;
        if (drmModeAddFB(mode->fd, scrn->virtualX, scrn->virtualY,
                         scrn->depth, scrn->bitsPerPixel, pitch,
-                        new_front->handle, &mode->fb_id))
+                        new_front->handle, &new_fb_id))
                goto error_out;
 
+       intel_glamor_flush(intel);
+       intel_batch_submit(scrn);
+
        /*
         * Queue flips on all enabled CRTCs
         * Note that if/when we get per-CRTC buffers, we'll have to update this.
@@ -1461,7 +1573,7 @@ intel_do_pageflip(intel_screen_private *intel,
        mode->fe_tv_usec = 0;
 
        for (i = 0; i < config->num_crtc; i++) {
-               if (!config->crtc[i]->enabled)
+               if (!intel_crtc_on(config->crtc[i]))
                        continue;
 
                mode->flip_info = flip_info;
@@ -1484,7 +1596,7 @@ intel_do_pageflip(intel_screen_private *intel,
 
                if (drmModePageFlip(mode->fd,
                                    crtc_id(crtc),
-                                   mode->fb_id,
+                                   new_fb_id,
                                    DRM_MODE_PAGE_FLIP_EVENT, flip)) {
                        xf86DrvMsg(scrn->scrnIndex, X_WARNING,
                                   "flip queue failed: %s\n", strerror(errno));
@@ -1493,12 +1605,16 @@ intel_do_pageflip(intel_screen_private *intel,
                }
        }
 
-       mode->old_fb_id = old_fb_id;
+       mode->old_fb_id = mode->fb_id;
+       mode->fb_id = new_fb_id;
        return TRUE;
 
 error_undo:
-       drmModeRmFB(mode->fd, mode->fb_id);
-       mode->fb_id = old_fb_id;
+       drmModeRmFB(mode->fd, new_fb_id);
+       for (i = 0; i < config->num_crtc; i++) {
+               if (config->crtc[i]->enabled)
+                       intel_crtc_apply(config->crtc[i]);
+       }
 
 error_out:
        xf86DrvMsg(scrn->scrnIndex, X_WARNING, "Page flip failed: %s\n",
@@ -1600,21 +1716,25 @@ Bool intel_mode_pre_init(ScrnInfoPtr scrn, int fd, int cpp)
        for (i = 0; i < mode->mode_res->count_connectors; i++)
                intel_output_init(scrn, mode, i);
 
+#ifdef INTEL_PIXMAP_SHARING
+       xf86ProviderSetup(scrn, NULL, "Intel");
+#endif
+
        xf86InitialConfiguration(scrn, TRUE);
 
+       mode->event_context.version = DRM_EVENT_CONTEXT_VERSION;
+       mode->event_context.vblank_handler = intel_vblank_handler;
+       mode->event_context.page_flip_handler = intel_page_flip_handler;
+
        has_flipping = 0;
        gp.param = I915_PARAM_HAS_PAGEFLIPPING;
        gp.value = &has_flipping;
        (void)drmCommandWriteRead(intel->drmSubFD, DRM_I915_GETPARAM, &gp,
                                  sizeof(gp));
-       if (has_flipping) {
+       if (has_flipping && intel->swapbuffers_wait) {
                xf86DrvMsg(scrn->scrnIndex, X_INFO,
                           "Kernel page flipping support detected, enabling\n");
                intel->use_pageflipping = TRUE;
-
-               mode->event_context.version = DRM_EVENT_CONTEXT_VERSION;
-               mode->event_context.vblank_handler = intel_vblank_handler;
-               mode->event_context.page_flip_handler = intel_page_flip_handler;
        }
 
        intel->modes = mode;
@@ -1624,18 +1744,16 @@ Bool intel_mode_pre_init(ScrnInfoPtr scrn, int fd, int cpp)
 void
 intel_mode_init(struct intel_screen_private *intel)
 {
-       if (intel->use_pageflipping) {
-               struct intel_mode *mode = intel->modes;
+       struct intel_mode *mode = intel->modes;
 
-               /* We need to re-register the mode->fd for the synchronisation
-                * feedback on every server generation, so perform the
-                * registration within ScreenInit and not PreInit.
-                */
-               mode->flip_count = 0;
-               AddGeneralSocket(mode->fd);
-               RegisterBlockAndWakeupHandlers((BlockHandlerProcPtr)NoopDDA,
-                                              drm_wakeup_handler, mode);
-       }
+       /* We need to re-register the mode->fd for the synchronisation
+        * feedback on every server generation, so perform the
+        * registration within ScreenInit and not PreInit.
+        */
+       mode->flip_count = 0;
+       AddGeneralSocket(mode->fd);
+       RegisterBlockAndWakeupHandlers((BlockHandlerProcPtr)NoopDDA,
+                                      drm_wakeup_handler, mode);
 }
 
 void
@@ -1654,6 +1772,9 @@ intel_mode_fini(intel_screen_private *intel)
 {
        struct intel_mode *mode = intel->modes;
 
+       if (mode == NULL)
+               return;
+
        while(!list_is_empty(&mode->crtcs)) {
                xf86CrtcDestroy(list_first_entry(&mode->crtcs,
                                                 struct intel_crtc,
@@ -1687,3 +1808,165 @@ int intel_crtc_to_pipe(xf86CrtcPtr crtc)
        struct intel_crtc *intel_crtc = crtc->driver_private;
        return intel_crtc->pipe;
 }
+
+Bool intel_crtc_on(xf86CrtcPtr crtc)
+{
+       struct intel_crtc *intel_crtc = crtc->driver_private;
+       xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
+       drmModeCrtcPtr drm_crtc;
+       Bool ret;
+       int i;
+
+       if (!crtc->enabled)
+               return FALSE;
+
+       /* Kernel manages CRTC status based on output config */
+       ret = FALSE;
+       for (i = 0; i < xf86_config->num_output; i++) {
+               xf86OutputPtr output = xf86_config->output[i];
+               if (output->crtc == crtc &&
+                   intel_output_dpms_status(output) == DPMSModeOn) {
+                       ret = TRUE;
+                       break;
+               }
+       }
+       if (!ret)
+               return FALSE;
+
+       /* And finally check with the kernel that the fb is bound */
+       drm_crtc = drmModeGetCrtc(intel_crtc->mode->fd, crtc_id(intel_crtc));
+       if (drm_crtc == NULL)
+               return FALSE;
+
+       ret = (drm_crtc->mode_valid &&
+              intel_crtc->mode->fb_id == drm_crtc->buffer_id);
+       free(drm_crtc);
+
+       return ret;
+}
+
+static PixmapPtr
+intel_create_pixmap_for_bo(ScreenPtr pScreen, dri_bo *bo,
+                          int width, int height,
+                          int depth, int bpp,
+                          int pitch)
+{
+       PixmapPtr pixmap;
+
+       pixmap = pScreen->CreatePixmap(pScreen, 0, 0, depth, 0);
+       if (pixmap == NullPixmap)
+               return pixmap;
+
+       if (!pScreen->ModifyPixmapHeader(pixmap,
+                                        width, height,
+                                        depth, bpp,
+                                        pitch, NULL)) {
+               pScreen->DestroyPixmap(pixmap);
+               return NullPixmap;
+       }
+
+       intel_set_pixmap_bo(pixmap, bo);
+       return pixmap;
+}
+
+static PixmapPtr
+intel_create_pixmap_for_fbcon(ScrnInfoPtr scrn, int fbcon_id)
+{
+       ScreenPtr pScreen = xf86ScrnToScreen(scrn);
+       intel_screen_private *intel = intel_get_screen_private(scrn);
+       struct intel_mode *mode = intel->modes;
+       int fd = mode->fd;
+       drmModeFBPtr fbcon;
+       struct drm_gem_flink flink;
+       drm_intel_bo *bo;
+       PixmapPtr pixmap = NullPixmap;
+
+       fbcon = drmModeGetFB(fd, fbcon_id);
+       if (fbcon == NULL)
+               return NULL;
+
+       if (fbcon->depth != scrn->depth ||
+           fbcon->width != scrn->virtualX ||
+           fbcon->height != scrn->virtualY)
+               goto out_free_fb;
+
+       flink.handle = fbcon->handle;
+       if (ioctl(fd, DRM_IOCTL_GEM_FLINK, &flink) < 0) {
+               xf86DrvMsg(scrn->scrnIndex, X_ERROR,
+                          "Couldn't flink fbcon handle\n");
+               goto out_free_fb;
+       }
+
+       bo = drm_intel_bo_gem_create_from_name(intel->bufmgr,
+                                              "fbcon", flink.name);
+       if (bo == NULL) {
+               xf86DrvMsg(scrn->scrnIndex, X_ERROR,
+                          "Couldn't allocate bo for fbcon handle\n");
+               goto out_free_fb;
+       }
+
+       pixmap = intel_create_pixmap_for_bo(pScreen, bo,
+                                           fbcon->width, fbcon->height,
+                                           fbcon->depth, fbcon->bpp,
+                                           fbcon->pitch);
+       if (pixmap == NullPixmap)
+               xf86DrvMsg(scrn->scrnIndex, X_ERROR,
+                          "Couldn't allocate pixmap fbcon contents\n");
+       drm_intel_bo_unreference(bo);
+out_free_fb:
+       drmModeFreeFB(fbcon);
+
+       return pixmap;
+}
+
+void intel_copy_fb(ScrnInfoPtr scrn)
+{
+       xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+       ScreenPtr pScreen = xf86ScrnToScreen(scrn);
+       intel_screen_private *intel = intel_get_screen_private(scrn);
+       PixmapPtr src, dst;
+       unsigned int pitch = scrn->displayWidth * intel->cpp;
+       struct intel_crtc *intel_crtc;
+       int i, fbcon_id;
+
+       if (intel->force_fallback)
+               return;
+
+       fbcon_id = 0;
+       for (i = 0; i < xf86_config->num_crtc; i++) {
+               intel_crtc = xf86_config->crtc[i]->driver_private;
+               if (intel_crtc->mode_crtc->buffer_id)
+                       fbcon_id = intel_crtc->mode_crtc->buffer_id;
+       }
+       if (!fbcon_id)
+               return;
+
+       src = intel_create_pixmap_for_fbcon(scrn, fbcon_id);
+       if (src == NULL)
+               return;
+
+       /* We dont have a screen Pixmap yet */
+       dst = intel_create_pixmap_for_bo(pScreen, intel->front_buffer,
+                                        scrn->virtualX, scrn->virtualY,
+                                        scrn->depth, scrn->bitsPerPixel,
+                                        pitch);
+       if (dst == NullPixmap)
+               goto cleanup_src;
+
+       if (!intel->uxa_driver->prepare_copy(src, dst,
+                                            -1, -1,
+                                            GXcopy, FB_ALLONES))
+               goto cleanup_dst;
+
+       intel->uxa_driver->copy(dst,
+                               0, 0,
+                               0, 0,
+                               scrn->virtualX, scrn->virtualY);
+       intel->uxa_driver->done_copy(dst);
+       pScreen->canDoBGNoneRoot = TRUE;
+
+cleanup_dst:
+       (*pScreen->DestroyPixmap)(dst);
+cleanup_src:
+       (*pScreen->DestroyPixmap)(src);
+}
index a39b512..64cb567 100644 (file)
@@ -50,15 +50,13 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 #include "xf86.h"
 #include "xf86_OSproc.h"
-#include "xf86Priv.h"
 
-#include "xf86PciInfo.h"
 #include "xf86Pci.h"
+#include "xf86drm.h"
 
 #include "windowstr.h"
 #include "shadow.h"
-
-#include "xaarop.h"
+#include "fb.h"
 
 #include "intel.h"
 #include "i830_reg.h"
@@ -67,12 +65,20 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 #include "dri2.h"
 
+#include "intel_glamor.h"
+#include "uxa.h"
+
 typedef struct {
        int refcnt;
        PixmapPtr pixmap;
-       unsigned int attachment;
 } I830DRI2BufferPrivateRec, *I830DRI2BufferPrivatePtr;
 
+#if HAS_DEVPRIVATEKEYREC
+static DevPrivateKeyRec i830_client_key;
+#else
+static int i830_client_key;
+#endif
+
 static uint32_t pixmap_flink(PixmapPtr pixmap)
 {
        struct intel_pixmap *priv = intel_get_pixmap_private(pixmap);
@@ -84,77 +90,42 @@ static uint32_t pixmap_flink(PixmapPtr pixmap)
        if (dri_bo_flink(priv->bo, &name) != 0)
                return 0;
 
-       priv->pinned = 1;
+       priv->pinned |= PIN_DRI;
        return name;
 }
 
 static PixmapPtr get_front_buffer(DrawablePtr drawable)
 {
-       ScreenPtr screen = drawable->pScreen;
-       ScrnInfoPtr scrn = xf86Screens[screen->myNum];
-       intel_screen_private *intel = intel_get_screen_private(scrn);
        PixmapPtr pixmap;
 
        pixmap = get_drawable_pixmap(drawable);
-       if (!intel->use_shadow) {
-               pixmap->refcnt++;
-       } else if (pixmap_is_scanout(pixmap)) {
-               pixmap = fbCreatePixmap(screen, 0, 0, drawable->depth, 0);
-               if (pixmap) {
-                       screen->ModifyPixmapHeader(pixmap,
-                                                  drawable->width,
-                                                  drawable->height,
-                                                  0, 0,
-                                                  intel->front_pitch,
-                                                  intel->front_buffer->virtual);
-
-                       intel_set_pixmap_bo(pixmap, intel->front_buffer);
-                       intel_get_pixmap_private(pixmap)->offscreen = 0;
-                       if (WindowDrawable(drawable->type))
-                               screen->SetWindowPixmap((WindowPtr)drawable,
-                                                       pixmap);
-               }
-       } else if (intel_get_pixmap_bo(pixmap)) {
-               pixmap->refcnt++;
-       } else
-               pixmap = NULL;
+       if (!intel_get_pixmap_bo(pixmap))
+               return NULL;
+
+       pixmap->refcnt++;
        return pixmap;
 }
 
-static PixmapPtr fixup_shadow(DrawablePtr drawable, PixmapPtr pixmap)
+static PixmapPtr fixup_glamor(DrawablePtr drawable, PixmapPtr pixmap)
 {
        ScreenPtr screen = drawable->pScreen;
+       ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+       intel_screen_private *intel = intel_get_screen_private(scrn);
        PixmapPtr old = get_drawable_pixmap(drawable);
        struct intel_pixmap *priv = intel_get_pixmap_private(pixmap);
        GCPtr gc;
 
-       /* With an active shadow buffer, 2D pixmaps are created in
-        * system memory and GPU acceleration of 2D render operations
-        * is *disabled*. As DRI is still enabled, we create hardware
-        * buffers for the clients, and need to mix this with the
-        * 2D rendering. So we replace the system pixmap with a GTT
-        * mapping (with the kernel enforcing coherency between
-        * CPU and GPU) for 2D and provide the bo so that clients
-        * can write directly to it (or read from it in the case
-        * of TextureFromPixmap) using the GPU.
+       /* With a glamor pixmap, 2D pixmaps are created in texture
+        * and without a static BO attached to it. To support DRI,
+        * we need to create a new textured-drm pixmap and
+        * need to copy the original content to this new textured-drm
+        * pixmap, and then convert the old pixmap to a coherent
+        * textured-drm pixmap which has a valid BO attached to it
+        * and also has a valid texture, thus both glamor and DRI2
+        * can access it.
         *
-        * So for a compositor with a GL backend (i.e. compiz) we have
-        * smooth wobbly windows but incur the cost of uncached 2D rendering,
-        * however 3D applications (games and clutter) are still fully
-        * accelerated.
         */
 
-       if (drm_intel_gem_bo_map_gtt(priv->bo))
-               return pixmap;
-
-       screen->ModifyPixmapHeader(pixmap,
-                                  drawable->width,
-                                  drawable->height,
-                                  0, 0,
-                                  priv->stride,
-                                  priv->bo->virtual);
-       priv->offscreen = 0;
-
        /* Copy the current contents of the pixmap to the bo. */
        gc = GetScratchGC(drawable->depth, screen);
        if (gc) {
@@ -169,19 +140,21 @@ static PixmapPtr fixup_shadow(DrawablePtr drawable, PixmapPtr pixmap)
        }
 
        intel_set_pixmap_private(pixmap, NULL);
-       screen->DestroyPixmap(pixmap);
 
-       /* Redirect 2D rendering to the uncached GTT map of the bo */
+       /* Exchange the underlying texture/image. */
+       intel_glamor_exchange_buffers(intel, old, pixmap);
+       /* And redirect the pixmap to the new bo (for 3D). */
+       intel_set_pixmap_private(old, priv);
+       old->refcnt++;
+
        screen->ModifyPixmapHeader(old,
                                   drawable->width,
                                   drawable->height,
                                   0, 0,
                                   priv->stride,
-                                  priv->bo->virtual);
-
-       /* And redirect the pixmap to the new bo (for 3D). */
-       intel_set_pixmap_private(old, priv);
-       old->refcnt++;
+                                  NULL);
+       screen->DestroyPixmap(pixmap);
+       intel_get_screen_private(xf86ScreenToScrn(screen))->needs_flush = TRUE;
        return old;
 }
 
@@ -191,11 +164,12 @@ I830DRI2CreateBuffers(DrawablePtr drawable, unsigned int *attachments,
                      int count)
 {
        ScreenPtr screen = drawable->pScreen;
-       ScrnInfoPtr scrn = xf86Screens[screen->myNum];
+       ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
        intel_screen_private *intel = intel_get_screen_private(scrn);
        DRI2BufferPtr buffers;
        I830DRI2BufferPrivatePtr privates;
        PixmapPtr pixmap, pDepthPixmap;
+       Bool is_glamor_pixmap = FALSE;
        int i;
 
        buffers = calloc(count, sizeof *buffers);
@@ -212,10 +186,16 @@ I830DRI2CreateBuffers(DrawablePtr drawable, unsigned int *attachments,
                pixmap = NULL;
                if (attachments[i] == DRI2BufferFrontLeft) {
                        pixmap = get_front_buffer(drawable);
+
+                       if (pixmap == NULL) {
+                               drawable = &(get_drawable_pixmap(drawable)->drawable);
+                               is_glamor_pixmap = TRUE;
+                       }
                } else if (attachments[i] == DRI2BufferStencil && pDepthPixmap) {
                        pixmap = pDepthPixmap;
                        pixmap->refcnt++;
                }
+
                if (pixmap == NULL) {
                        unsigned int hint = INTEL_CREATE_PIXMAP_DRI2;
 
@@ -249,8 +229,8 @@ I830DRI2CreateBuffers(DrawablePtr drawable, unsigned int *attachments,
                                goto unwind;
                        }
 
-                       if (attachment == DRI2BufferFrontLeft)
-                               pixmap = fixup_shadow(drawable, pixmap);
+                       if (is_glamor_pixmap)
+                               pixmap = fixup_glamor(drawable, pixmap);
                }
 
                if (attachments[i] == DRI2BufferDepth)
@@ -263,7 +243,6 @@ I830DRI2CreateBuffers(DrawablePtr drawable, unsigned int *attachments,
                buffers[i].flags = 0;   /* not tiled */
                privates[i].refcnt = 1;
                privates[i].pixmap = pixmap;
-               privates[i].attachment = attachments[i];
 
                if ((buffers[i].name = pixmap_flink(pixmap)) == 0) {
                        /* failed to name buffer */
@@ -307,11 +286,12 @@ I830DRI2CreateBuffer(DrawablePtr drawable, unsigned int attachment,
                     unsigned int format)
 {
        ScreenPtr screen = drawable->pScreen;
-       ScrnInfoPtr scrn = xf86Screens[screen->myNum];
+       ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
        intel_screen_private *intel = intel_get_screen_private(scrn);
        DRI2Buffer2Ptr buffer;
        I830DRI2BufferPrivatePtr privates;
        PixmapPtr pixmap;
+       Bool is_glamor_pixmap = FALSE;
 
        buffer = calloc(1, sizeof *buffer);
        if (buffer == NULL)
@@ -323,30 +303,77 @@ I830DRI2CreateBuffer(DrawablePtr drawable, unsigned int attachment,
        }
 
        pixmap = NULL;
-       if (attachment == DRI2BufferFrontLeft)
+       if (attachment == DRI2BufferFrontLeft) {
                pixmap = get_front_buffer(drawable);
+
+               if (pixmap == NULL) {
+                       drawable = &(get_drawable_pixmap(drawable)->drawable);
+                       is_glamor_pixmap = TRUE;
+               }
+       }
+
        if (pixmap == NULL) {
                unsigned int hint = INTEL_CREATE_PIXMAP_DRI2;
+               int pixmap_width = drawable->width;
+               int pixmap_height = drawable->height;
+               int pixmap_cpp = (format != 0) ? format : drawable->depth;
 
                if (intel->tiling & INTEL_TILING_3D) {
                        switch (attachment) {
                        case DRI2BufferDepth:
                        case DRI2BufferDepthStencil:
+                       case DRI2BufferHiz:
                                if (SUPPORTS_YTILING(intel)) {
                                        hint |= INTEL_CREATE_PIXMAP_TILING_Y;
                                        break;
                                }
-                       default:
+                       case DRI2BufferAccum:
+                       case DRI2BufferBackLeft:
+                       case DRI2BufferBackRight:
+                       case DRI2BufferFakeFrontLeft:
+                       case DRI2BufferFakeFrontRight:
+                       case DRI2BufferFrontLeft:
+                       case DRI2BufferFrontRight:
                                hint |= INTEL_CREATE_PIXMAP_TILING_X;
                                break;
-                       }
+                       case DRI2BufferStencil:
+                               /*
+                                * The stencil buffer is W tiled. However, we
+                                * request from the kernel a non-tiled buffer
+                                * because the GTT is incapable of W fencing.
+                                */
+                               hint |= INTEL_CREATE_PIXMAP_TILING_NONE;
+                               break;
+                       default:
+                               free(privates);
+                               free(buffer);
+                               return NULL;
+                        }
+               }
+
+               /*
+                * The stencil buffer has quirky pitch requirements.  From Vol
+                * 2a, 11.5.6.2.1 3DSTATE_STENCIL_BUFFER, field "Surface
+                * Pitch":
+                *    The pitch must be set to 2x the value computed based on
+                *    width, as the stencil buffer is stored with two rows
+                *    interleaved.
+                * To accomplish this, we resort to the nasty hack of doubling
+                * the drm region's cpp and halving its height.
+                *
+                * If we neglect to double the pitch, then render corruption
+                * occurs.
+                */
+               if (attachment == DRI2BufferStencil) {
+                       pixmap_width = ALIGN(pixmap_width, 64);
+                       pixmap_height = ALIGN((pixmap_height + 1) / 2, 64);
+                       pixmap_cpp *= 2;
                }
 
                pixmap = screen->CreatePixmap(screen,
-                                             drawable->width,
-                                             drawable->height,
-                                             (format != 0) ? format :
-                                                             drawable->depth,
+                                             pixmap_width,
+                                             pixmap_height,
+                                             pixmap_cpp,
                                              hint);
                if (pixmap == NULL || intel_get_pixmap_bo(pixmap) == NULL) {
                        if (pixmap)
@@ -355,9 +382,8 @@ I830DRI2CreateBuffer(DrawablePtr drawable, unsigned int attachment,
                        free(buffer);
                        return NULL;
                }
-
-               if (attachment == DRI2BufferFrontLeft)
-                       pixmap = fixup_shadow(drawable, pixmap);
+               if (is_glamor_pixmap)
+                       pixmap = fixup_glamor(drawable, pixmap);
        }
 
        buffer->attachment = attachment;
@@ -368,7 +394,6 @@ I830DRI2CreateBuffer(DrawablePtr drawable, unsigned int attachment,
        buffer->flags = 0;      /* not tiled */
        privates->refcnt = 1;
        privates->pixmap = pixmap;
-       privates->attachment = attachment;
 
        if ((buffer->name = pixmap_flink(pixmap)) == 0) {
                /* failed to name buffer */
@@ -405,11 +430,11 @@ I830DRI2CopyRegion(DrawablePtr drawable, RegionPtr pRegion,
        I830DRI2BufferPrivatePtr srcPrivate = sourceBuffer->driverPrivate;
        I830DRI2BufferPrivatePtr dstPrivate = destBuffer->driverPrivate;
        ScreenPtr screen = drawable->pScreen;
-       ScrnInfoPtr scrn = xf86Screens[screen->myNum];
+       ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
        intel_screen_private *intel = intel_get_screen_private(scrn);
-       DrawablePtr src = (srcPrivate->attachment == DRI2BufferFrontLeft)
+       DrawablePtr src = (sourceBuffer->attachment == DRI2BufferFrontLeft)
                ? drawable : &srcPrivate->pixmap->drawable;
-       DrawablePtr dst = (dstPrivate->attachment == DRI2BufferFrontLeft)
+       DrawablePtr dst = (destBuffer->attachment == DRI2BufferFrontLeft)
                ? drawable : &dstPrivate->pixmap->drawable;
        RegionPtr pCopyClip;
        GCPtr gc;
@@ -424,12 +449,13 @@ I830DRI2CopyRegion(DrawablePtr drawable, RegionPtr pRegion,
        ValidateGC(dst, gc);
 
        /* Wait for the scanline to be outside the region to be copied */
-       if (pixmap_is_scanout(get_drawable_pixmap(dst)) &&
-           intel->swapbuffers_wait) {
+       if (scrn->vtSema &&
+           pixmap_is_scanout(get_drawable_pixmap(dst)) &&
+           intel->swapbuffers_wait && INTEL_INFO(intel)->gen < 60) {
                BoxPtr box;
                BoxRec crtcbox;
                int y1, y2;
-               int pipe = -1, event, load_scan_lines_pipe;
+               int event, load_scan_lines_pipe;
                xf86CrtcPtr crtc;
                Bool full_height = FALSE;
 
@@ -441,7 +467,7 @@ I830DRI2CopyRegion(DrawablePtr drawable, RegionPtr pRegion,
                 * buffer
                 */
                if (crtc != NULL && !crtc->rotatedData) {
-                       pipe = intel_crtc_to_pipe(crtc);
+                       int pipe = intel_crtc_to_pipe(crtc);
 
                        /*
                         * Make sure we don't wait for a scanline that will
@@ -508,39 +534,17 @@ I830DRI2CopyRegion(DrawablePtr drawable, RegionPtr pRegion,
         * that will happen before the client tries to render
         * again. */
 
-       /* Re-enable 2D acceleration... */
-       if (intel->use_shadow) {
-               struct intel_pixmap *src_pixmap, *dst_pixmap;
-
-               src_pixmap = intel_get_pixmap_private(get_drawable_pixmap(src));
-               if (src_pixmap) {
-                       src_pixmap->offscreen = 1;
-                       src_pixmap->busy = 1;
-               }
-
-               dst_pixmap = intel_get_pixmap_private(get_drawable_pixmap(dst));
-               if (dst_pixmap) {
-                       dst_pixmap->offscreen = 1;
-                       dst_pixmap->busy = 1;
-               }
-
-               gc->ops->CopyArea(src, dst, gc,
-                                 0, 0,
-                                 drawable->width, drawable->height,
-                                 0, 0);
+       gc->ops->CopyArea(src, dst, gc,
+                         0, 0,
+                         drawable->width, drawable->height,
+                         0, 0);
 
-               /* and restore 2D/3D coherency */
-               if (src_pixmap)
-                       src_pixmap->offscreen = 0;
-               if (dst_pixmap)
-                       dst_pixmap->offscreen = 0;
-       } else {
-               gc->ops->CopyArea(src, dst, gc,
-                                 0, 0,
-                                 drawable->width, drawable->height,
-                                 0, 0);
-       }
        FreeScratchGC(gc);
+
+       /* And make sure the WAIT_FOR_EVENT is queued before any
+        * modesetting/dpms operations on the pipe.
+        */
+       intel_batch_submit(scrn);
 }
 
 #if DRI2INFOREC_VERSION >= 4
@@ -557,7 +561,7 @@ static int
 I830DRI2DrawablePipe(DrawablePtr pDraw)
 {
        ScreenPtr pScreen = pDraw->pScreen;
-       ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+       ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
        BoxRec box, crtcbox;
        xf86CrtcPtr crtc;
        int pipe = -1;
@@ -578,22 +582,73 @@ I830DRI2DrawablePipe(DrawablePtr pDraw)
 
 static RESTYPE frame_event_client_type, frame_event_drawable_type;
 
+struct i830_dri2_resource {
+       XID id;
+       RESTYPE type;
+       struct list list;
+};
+
+static struct i830_dri2_resource *
+get_resource(XID id, RESTYPE type)
+{
+       struct i830_dri2_resource *resource;
+       void *ptr;
+
+       ptr = NULL;
+       dixLookupResourceByType(&ptr, id, type, NULL, DixWriteAccess);
+       if (ptr)
+               return ptr;
+
+       resource = malloc(sizeof(*resource));
+       if (resource == NULL)
+               return NULL;
+
+       if (!AddResource(id, type, resource)) {
+               free(resource);
+               return NULL;
+       }
+
+       resource->id = id;
+       resource->type = type;
+       list_init(&resource->list);
+       return resource;
+}
+
 static int
 i830_dri2_frame_event_client_gone(void *data, XID id)
 {
-       DRI2FrameEventPtr       frame_event = data;
+       struct i830_dri2_resource *resource = data;
+
+       while (!list_is_empty(&resource->list)) {
+               DRI2FrameEventPtr info =
+                       list_first_entry(&resource->list,
+                                        DRI2FrameEventRec,
+                                        client_resource);
+
+               list_del(&info->client_resource);
+               info->client = NULL;
+       }
+       free(resource);
 
-       frame_event->client = NULL;
-       frame_event->client_id = None;
        return Success;
 }
 
 static int
 i830_dri2_frame_event_drawable_gone(void *data, XID id)
 {
-       DRI2FrameEventPtr       frame_event = data;
+       struct i830_dri2_resource *resource = data;
+
+       while (!list_is_empty(&resource->list)) {
+               DRI2FrameEventPtr info =
+                       list_first_entry(&resource->list,
+                                        DRI2FrameEventRec,
+                                        drawable_resource);
+
+               list_del(&info->drawable_resource);
+               info->drawable_id = None;
+       }
+       free(resource);
 
-       frame_event->drawable_id = None;
        return Success;
 }
 
@@ -611,45 +666,98 @@ i830_dri2_register_frame_event_resource_types(void)
        return TRUE;
 }
 
+static XID
+get_client_id(ClientPtr client)
+{
+#if HAS_DIXREGISTERPRIVATEKEY
+       XID *ptr = dixGetPrivateAddr(&client->devPrivates, &i830_client_key);
+#else
+       XID *ptr = dixLookupPrivate(&client->devPrivates, &i830_client_key);
+#endif
+       if (*ptr == 0)
+               *ptr = FakeClientID(client->index);
+       return *ptr;
+}
+
 /*
  * Hook this frame event into the server resource
  * database so we can clean it up if the drawable or
  * client exits while the swap is pending
  */
 static Bool
-i830_dri2_add_frame_event(DRI2FrameEventPtr frame_event)
+i830_dri2_add_frame_event(DRI2FrameEventPtr info)
 {
-       frame_event->client_id = FakeClientID(frame_event->client->index);
+       struct i830_dri2_resource *resource;
 
-       if (!AddResource(frame_event->client_id, frame_event_client_type, frame_event))
+       resource = get_resource(get_client_id(info->client),
+                               frame_event_client_type);
+       if (resource == NULL)
                return FALSE;
 
-       if (!AddResource(frame_event->drawable_id, frame_event_drawable_type, frame_event)) {
-               FreeResourceByType(frame_event->client_id, frame_event_client_type, TRUE);
+       list_add(&info->client_resource, &resource->list);
+
+       resource = get_resource(info->drawable_id, frame_event_drawable_type);
+       if (resource == NULL) {
+               list_del(&info->client_resource);
                return FALSE;
        }
 
+       list_add(&info->drawable_resource, &resource->list);
+
        return TRUE;
 }
 
 static void
-i830_dri2_del_frame_event(DRI2FrameEventPtr frame_event)
+i830_dri2_del_frame_event(DrawablePtr drawable, DRI2FrameEventPtr info)
 {
-       if (frame_event->client_id)
-               FreeResourceByType(frame_event->client_id, frame_event_client_type, TRUE);
-       if (frame_event->drawable_id)
-               FreeResourceByType(frame_event->drawable_id, frame_event_drawable_type, TRUE);
+       list_del(&info->client_resource);
+       list_del(&info->drawable_resource);
+
+       if (info->front)
+               I830DRI2DestroyBuffer(drawable, info->front);
+       if (info->back)
+               I830DRI2DestroyBuffer(drawable, info->back);
+
+       free(info);
+}
+
+static struct intel_pixmap *
+intel_exchange_pixmap_buffers(struct intel_screen_private *intel, PixmapPtr front, PixmapPtr back)
+{
+       struct intel_pixmap *new_front, *new_back;
+
+       new_front = intel_get_pixmap_private(back);
+       new_back = intel_get_pixmap_private(front);
+       intel_set_pixmap_private(front, new_front);
+       intel_set_pixmap_private(back, new_back);
+       new_front->busy = 1;
+       new_back->busy = -1;
+
+       intel_glamor_exchange_buffers(intel, front, back);
+
+       /* Post damage on the new front buffer so that listeners, such
+        * as DisplayLink know take a copy and shove it over the USB.
+        */
+       {
+               RegionRec region;
+
+               region.extents.x1 = region.extents.y1 = 0;
+               region.extents.x2 = front->drawable.width;
+               region.extents.y2 = front->drawable.height;
+               region.data = NULL;
+               DamageRegionAppend(&front->drawable, &region);
+               DamageRegionProcessPending(&front->drawable);
+       }
+
+       return new_front;
 }
 
 static void
-I830DRI2ExchangeBuffers(DrawablePtr draw, DRI2BufferPtr front,
-                       DRI2BufferPtr back)
+I830DRI2ExchangeBuffers(struct intel_screen_private *intel, DRI2BufferPtr front, DRI2BufferPtr back)
 {
        I830DRI2BufferPrivatePtr front_priv, back_priv;
-       struct intel_pixmap *front_intel, *back_intel;
-       ScreenPtr screen;
-       intel_screen_private *intel;
        int tmp;
+       struct intel_pixmap *new_front;
 
        front_priv = front->driverPrivate;
        back_priv = back->driverPrivate;
@@ -660,23 +768,51 @@ I830DRI2ExchangeBuffers(DrawablePtr draw, DRI2BufferPtr front,
        back->name = tmp;
 
        /* Swap pixmap bos */
-       front_intel = intel_get_pixmap_private(front_priv->pixmap);
-       back_intel = intel_get_pixmap_private(back_priv->pixmap);
-       intel_set_pixmap_private(front_priv->pixmap, back_intel);
-       intel_set_pixmap_private(back_priv->pixmap, front_intel); /* should be screen */
-
-       /* Do we need to update the Screen? */
-       screen = draw->pScreen;
-       intel = intel_get_screen_private(xf86Screens[screen->myNum]);
-       if (front_intel->bo == intel->front_buffer) {
-           dri_bo_unreference (intel->front_buffer);
-           intel->front_buffer = back_intel->bo;
-           dri_bo_reference (intel->front_buffer);
-           intel_set_pixmap_private(screen->GetScreenPixmap(screen),
-                                    back_intel);
-           back_intel->busy = 1;
-           front_intel->busy = -1;
+       new_front = intel_exchange_pixmap_buffers(intel,
+                                                 front_priv->pixmap,
+                                                 back_priv->pixmap);
+       dri_bo_unreference (intel->front_buffer);
+       intel->front_buffer = new_front->bo;
+       dri_bo_reference (intel->front_buffer);
+}
+
+static PixmapPtr
+intel_glamor_create_back_pixmap(ScreenPtr screen,
+                               PixmapPtr front_pixmap,
+                               drm_intel_bo *back_bo)
+{
+       PixmapPtr back_pixmap;
+
+       back_pixmap = screen->CreatePixmap(screen,
+                                          0,
+                                          0,
+                                          front_pixmap->drawable.depth,
+                                          0);
+       if (back_pixmap == NULL)
+               return NULL;
+
+       screen->ModifyPixmapHeader(back_pixmap,
+                                  front_pixmap->drawable.width,
+                                  front_pixmap->drawable.height,
+                                  0, 0,
+                                  front_pixmap->devKind,
+                                  0);
+       intel_set_pixmap_bo(back_pixmap, back_bo);
+       if (!intel_glamor_create_textured_pixmap(back_pixmap)) {
+               ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+               xf86DrvMsg(scrn->scrnIndex, X_WARNING,
+                          "Failed to create textured back pixmap.\n");
+               screen->DestroyPixmap(back_pixmap);
+               return NULL;
        }
+       return back_pixmap;
+}
+
+static drm_intel_bo *get_pixmap_bo(I830DRI2BufferPrivatePtr priv)
+{
+       drm_intel_bo *bo = intel_get_pixmap_bo(priv->pixmap);
+       assert(bo != NULL); /* guaranteed by construction of the DRI2 buffer */
+       return bo;
 }
 
 /*
@@ -685,47 +821,111 @@ I830DRI2ExchangeBuffers(DrawablePtr draw, DRI2BufferPtr front,
  */
 static Bool
 I830DRI2ScheduleFlip(struct intel_screen_private *intel,
-                    ClientPtr client, DrawablePtr draw, DRI2BufferPtr front,
-                    DRI2BufferPtr back, DRI2SwapEventPtr func, void *data,
-                    unsigned int target_msc)
+                    DrawablePtr draw,
+                    DRI2FrameEventPtr info)
 {
-       I830DRI2BufferPrivatePtr back_priv;
-       DRI2FrameEventPtr flip_info;
-
-       /* Main crtc for this drawable shall finally deliver pageflip event. */
-       int ref_crtc_hw_id = I830DRI2DrawablePipe(draw);
-
-       flip_info = calloc(1, sizeof(DRI2FrameEventRec));
-       if (!flip_info)
-           return FALSE;
-
-       flip_info->drawable_id = draw->id;
-       flip_info->client = client;
-       flip_info->type = DRI2_SWAP;
-       flip_info->event_complete = func;
-       flip_info->event_data = data;
-       flip_info->frame = target_msc;
-
-       if (!i830_dri2_add_frame_event(flip_info)) {
-           free(flip_info);
-           return FALSE;
+       I830DRI2BufferPrivatePtr priv = info->back->driverPrivate;
+       drm_intel_bo *new_back, *old_back;
+       int tmp_name;
+
+       if (!intel->use_triple_buffer) {
+               info->type = DRI2_SWAP;
+               if (!intel_do_pageflip(intel,
+                                      get_pixmap_bo(priv),
+                                      info, info->pipe))
+                       return FALSE;
+
+               I830DRI2ExchangeBuffers(intel, info->front, info->back);
+               return TRUE;
        }
 
-       /* Page flip the full screen buffer */
-       back_priv = back->driverPrivate;
-       if (intel_do_pageflip(intel,
-                             intel_get_pixmap_bo(back_priv->pixmap),
-                             flip_info, ref_crtc_hw_id))
+       if (intel->pending_flip[info->pipe]) {
+               assert(intel->pending_flip[info->pipe]->chain == NULL);
+               intel->pending_flip[info->pipe]->chain = info;
                return TRUE;
+       }
+
+       if (intel->back_buffer == NULL) {
+               I830DRI2BufferPrivatePtr priv;
+               PixmapPtr front_pixmap, back_pixmap;
+               ScreenPtr screen;
+
+               new_back = drm_intel_bo_alloc(intel->bufmgr, "front buffer",
+                                             intel->front_buffer->size, 0);
+               if (new_back == NULL)
+                       return FALSE;
+
+               if (intel->front_tiling != I915_TILING_NONE) {
+                       uint32_t tiling = intel->front_tiling;
+                       drm_intel_bo_set_tiling(new_back, &tiling, intel->front_pitch);
+                       if (tiling != intel->front_tiling) {
+                               drm_intel_bo_unreference(new_back);
+                               return FALSE;
+                       }
+               }
+
+               drm_intel_bo_disable_reuse(new_back);
+               dri_bo_flink(new_back, &intel->back_name);
+
+               if ((intel->uxa_flags & UXA_USE_GLAMOR)) {
+                       screen = draw->pScreen;
+                       priv = info->front->driverPrivate;
+                       front_pixmap = priv->pixmap;
 
-       i830_dri2_del_frame_event(flip_info);
-       free(flip_info);
-       return FALSE;
+                       back_pixmap = intel_glamor_create_back_pixmap(screen,
+                                                                     front_pixmap,
+                                                                     new_back);
+                       if (back_pixmap == NULL) {
+                               drm_intel_bo_unreference(new_back);
+                               return FALSE;
+                       }
+                       intel->back_pixmap = back_pixmap;
+               }
+       } else {
+               new_back = intel->back_buffer;
+               intel->back_buffer = NULL;
+       }
+
+       old_back = get_pixmap_bo(priv);
+       if (!intel_do_pageflip(intel, old_back, info, info->pipe)) {
+               intel->back_buffer = new_back;
+               return FALSE;
+       }
+       info->type = DRI2_SWAP_CHAIN;
+       intel->pending_flip[info->pipe] = info;
+
+       priv = info->front->driverPrivate;
+
+       /* Exchange the current front-buffer with the fresh bo */
+
+       intel->back_buffer = intel->front_buffer;
+       drm_intel_bo_reference(intel->back_buffer);
+       if (!(intel->uxa_flags & UXA_USE_GLAMOR)) {
+               intel_set_pixmap_bo(priv->pixmap, new_back);
+               drm_intel_bo_unreference(new_back);
+       }
+       else
+               intel_exchange_pixmap_buffers(intel, priv->pixmap,
+                                             intel->back_pixmap);
+
+       tmp_name = info->front->name;
+       info->front->name = intel->back_name;
+       intel->back_name = tmp_name;
+
+       /* Then flip DRI2 pointers and update the screen pixmap */
+       I830DRI2ExchangeBuffers(intel, info->front, info->back);
+       DRI2SwapComplete(info->client, draw, 0, 0, 0,
+                        DRI2_EXCHANGE_COMPLETE,
+                        info->event_complete,
+                        info->event_data);
+       return TRUE;
 }
 
 static Bool
-can_exchange(DRI2BufferPtr front, DRI2BufferPtr back)
+can_exchange(DrawablePtr drawable, DRI2BufferPtr front, DRI2BufferPtr back)
 {
+       ScrnInfoPtr pScrn = xf86ScreenToScrn(drawable->pScreen);
+       struct intel_screen_private *intel = intel_get_screen_private(pScrn);
        I830DRI2BufferPrivatePtr front_priv = front->driverPrivate;
        I830DRI2BufferPrivatePtr back_priv = back->driverPrivate;
        PixmapPtr front_pixmap = front_priv->pixmap;
@@ -733,6 +933,21 @@ can_exchange(DRI2BufferPtr front, DRI2BufferPtr back)
        struct intel_pixmap *front_intel = intel_get_pixmap_private(front_pixmap);
        struct intel_pixmap *back_intel = intel_get_pixmap_private(back_pixmap);
 
+       if (!pScrn->vtSema)
+               return FALSE;
+
+       if (I830DRI2DrawablePipe(drawable) < 0)
+               return FALSE;
+
+       if (!DRI2CanFlip(drawable))
+               return FALSE;
+
+       if (intel->shadow_present)
+               return FALSE;
+
+       if (!intel->use_pageflipping)
+               return FALSE;
+
        if (front_pixmap->drawable.width != back_pixmap->drawable.width)
                return FALSE;
 
@@ -758,10 +973,8 @@ can_exchange(DRI2BufferPtr front, DRI2BufferPtr back)
 void I830DRI2FrameEventHandler(unsigned int frame, unsigned int tv_sec,
                               unsigned int tv_usec, DRI2FrameEventPtr swap_info)
 {
+       intel_screen_private *intel = swap_info->intel;
        DrawablePtr drawable;
-       ScreenPtr screen;
-       ScrnInfoPtr scrn;
-       intel_screen_private *intel;
        int status;
 
        if (!swap_info->drawable_id)
@@ -770,56 +983,33 @@ void I830DRI2FrameEventHandler(unsigned int frame, unsigned int tv_sec,
                status = dixLookupDrawable(&drawable, swap_info->drawable_id, serverClient,
                                           M_ANY, DixWriteAccess);
        if (status != Success) {
-               i830_dri2_del_frame_event(swap_info);
-               I830DRI2DestroyBuffer(NULL, swap_info->front);
-               I830DRI2DestroyBuffer(NULL, swap_info->back);
-               free(swap_info);
+               i830_dri2_del_frame_event(NULL, swap_info);
                return;
        }
 
-       screen = drawable->pScreen;
-       scrn = xf86Screens[screen->myNum];
-       intel = intel_get_screen_private(scrn);
 
        switch (swap_info->type) {
        case DRI2_FLIP:
                /* If we can still flip... */
-               if (DRI2CanFlip(drawable) && !intel->shadow_present &&
-                   intel->use_pageflipping &&
-                   can_exchange(swap_info->front, swap_info->back) &&
-                   I830DRI2ScheduleFlip(intel,
-                                        swap_info->client, drawable, swap_info->front,
-                                        swap_info->back, swap_info->event_complete,
-                                        swap_info->event_data, swap_info->frame)) {
-                       I830DRI2ExchangeBuffers(drawable,
-                                               swap_info->front, swap_info->back);
-                       break;
-               }
+               if (can_exchange(drawable, swap_info->front, swap_info->back) &&
+                   I830DRI2ScheduleFlip(intel, drawable, swap_info))
+                       return;
+
                /* else fall through to exchange/blit */
        case DRI2_SWAP: {
-               int swap_type;
-
-               if (DRI2CanExchange(drawable) && can_exchange(swap_info->front,
-                                                             swap_info->back)) {
-                       I830DRI2ExchangeBuffers(drawable,
-                                               swap_info->front, swap_info->back);
-                       swap_type = DRI2_EXCHANGE_COMPLETE;
-               } else {
-                       BoxRec      box;
-                       RegionRec           region;
-
-                       box.x1 = 0;
-                       box.y1 = 0;
-                       box.x2 = drawable->width;
-                       box.y2 = drawable->height;
-                       REGION_INIT(pScreen, &region, &box, 0);
-
-                       I830DRI2CopyRegion(drawable,
-                                          &region, swap_info->front, swap_info->back);
-                       swap_type = DRI2_BLIT_COMPLETE;
-               }
+               BoxRec box;
+               RegionRec region;
+
+               box.x1 = 0;
+               box.y1 = 0;
+               box.x2 = drawable->width;
+               box.y2 = drawable->height;
+               REGION_INIT(pScreen, &region, &box, 0);
+
+               I830DRI2CopyRegion(drawable,
+                                  &region, swap_info->front, swap_info->back);
                DRI2SwapComplete(swap_info->client, drawable, frame, tv_sec, tv_usec,
-                                swap_type,
+                                DRI2_BLIT_COMPLETE,
                                 swap_info->client ? swap_info->event_complete : NULL,
                                 swap_info->event_data);
                break;
@@ -830,43 +1020,34 @@ void I830DRI2FrameEventHandler(unsigned int frame, unsigned int tv_sec,
                                            frame, tv_sec, tv_usec);
                break;
        default:
-               xf86DrvMsg(scrn->scrnIndex, X_WARNING,
+               xf86DrvMsg(intel->scrn->scrnIndex, X_WARNING,
                           "%s: unknown vblank event received\n", __func__);
                /* Unknown type */
                break;
        }
 
-       i830_dri2_del_frame_event(swap_info);
-       I830DRI2DestroyBuffer(drawable, swap_info->front);
-       I830DRI2DestroyBuffer(drawable, swap_info->back);
-       free(swap_info);
+       i830_dri2_del_frame_event(drawable, swap_info);
 }
 
 void I830DRI2FlipEventHandler(unsigned int frame, unsigned int tv_sec,
                              unsigned int tv_usec, DRI2FrameEventPtr flip_info)
 {
+       struct intel_screen_private *intel = flip_info->intel;
        DrawablePtr drawable;
-       ScreenPtr screen;
-       ScrnInfoPtr scrn;
-       int status;
+       DRI2FrameEventPtr chain;
 
-       if (!flip_info->drawable_id)
-               status = BadDrawable;
-       else
-               status = dixLookupDrawable(&drawable, flip_info->drawable_id, serverClient,
-                                          M_ANY, DixWriteAccess);
-       if (status != Success) {
-               i830_dri2_del_frame_event(flip_info);
-               free(flip_info);
-               return;
-       }
+       drawable = NULL;
+       if (flip_info->drawable_id)
+               dixLookupDrawable(&drawable, flip_info->drawable_id, serverClient,
+                                 M_ANY, DixWriteAccess);
 
-       screen = drawable->pScreen;
-       scrn = xf86Screens[screen->myNum];
 
        /* We assume our flips arrive in order, so we don't check the frame */
        switch (flip_info->type) {
        case DRI2_SWAP:
+               if (!drawable)
+                       break;
+
                /* Check for too small vblank count of pageflip completion, taking wraparound
                 * into account. This usually means some defective kms pageflip completion,
                 * causing wrong (msc, ust) return values and possible visual corruption.
@@ -878,7 +1059,7 @@ void I830DRI2FlipEventHandler(unsigned int frame, unsigned int tv_sec,
                         * kernels, so make it quieter.
                         */
                        if (limit) {
-                               xf86DrvMsg(scrn->scrnIndex, X_WARNING,
+                               xf86DrvMsg(intel->scrn->scrnIndex, X_WARNING,
                                           "%s: Pageflip completion has impossible msc %d < target_msc %d\n",
                                           __func__, frame, flip_info->frame);
                                limit--;
@@ -891,16 +1072,62 @@ void I830DRI2FlipEventHandler(unsigned int frame, unsigned int tv_sec,
                DRI2SwapComplete(flip_info->client, drawable, frame, tv_sec, tv_usec,
                                 DRI2_FLIP_COMPLETE, flip_info->client ? flip_info->event_complete : NULL,
                                 flip_info->event_data);
-       break;
+               break;
+
+       case DRI2_SWAP_CHAIN:
+               assert(intel->pending_flip[flip_info->pipe] == flip_info);
+               intel->pending_flip[flip_info->pipe] = NULL;
+
+               chain = flip_info->chain;
+               if (chain) {
+                       DrawablePtr chain_drawable = NULL;
+                       if (chain->drawable_id)
+                                dixLookupDrawable(&chain_drawable,
+                                                  chain->drawable_id,
+                                                  serverClient,
+                                                  M_ANY, DixWriteAccess);
+                       if (chain_drawable == NULL) {
+                               i830_dri2_del_frame_event(chain_drawable, chain);
+                       } else if (!can_exchange(chain_drawable, chain->front, chain->back) ||
+                                  !I830DRI2ScheduleFlip(intel, chain_drawable, chain)) {
+                               BoxRec box;
+                               RegionRec region;
+
+                               box.x1 = 0;
+                               box.y1 = 0;
+                               box.x2 = chain_drawable->width;
+                               box.y2 = chain_drawable->height;
+                               REGION_INIT(pScreen, &region, &box, 0);
+
+                               I830DRI2CopyRegion(chain_drawable, &region,
+                                                  chain->front, chain->back);
+                               DRI2SwapComplete(chain->client, chain_drawable, frame, tv_sec, tv_usec,
+                                                DRI2_BLIT_COMPLETE,
+                                                chain->client ? chain->event_complete : NULL,
+                                                chain->event_data);
+                               i830_dri2_del_frame_event(chain_drawable, chain);
+                       }
+               }
+               break;
+
        default:
-               xf86DrvMsg(scrn->scrnIndex, X_WARNING,
+               xf86DrvMsg(intel->scrn->scrnIndex, X_WARNING,
                           "%s: unknown vblank event received\n", __func__);
                /* Unknown type */
                break;
        }
 
-       i830_dri2_del_frame_event(flip_info);
-       free(flip_info);
+       i830_dri2_del_frame_event(drawable, flip_info);
+}
+
+static uint32_t pipe_select(int pipe)
+{
+       if (pipe > 1)
+               return pipe << DRM_VBLANK_HIGH_CRTC_SHIFT;
+       else if (pipe > 0)
+               return DRM_VBLANK_SECONDARY;
+       else
+               return 0;
 }
 
 /*
@@ -929,7 +1156,7 @@ I830DRI2ScheduleSwap(ClientPtr client, DrawablePtr draw, DRI2BufferPtr front,
                     CARD64 remainder, DRI2SwapEventPtr func, void *data)
 {
        ScreenPtr screen = draw->pScreen;
-       ScrnInfoPtr scrn = xf86Screens[screen->myNum];
+       ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
        intel_screen_private *intel = intel_get_screen_private(scrn);
        drmVBlank vbl;
        int ret, pipe = I830DRI2DrawablePipe(draw), flip = 0;
@@ -953,12 +1180,14 @@ I830DRI2ScheduleSwap(ClientPtr client, DrawablePtr draw, DRI2BufferPtr front,
        if (!swap_info)
            goto blit_fallback;
 
+       swap_info->intel = intel;
        swap_info->drawable_id = draw->id;
        swap_info->client = client;
        swap_info->event_complete = func;
        swap_info->event_data = data;
        swap_info->front = front;
        swap_info->back = back;
+       swap_info->pipe = pipe;
 
        if (!i830_dri2_add_frame_event(swap_info)) {
            free(swap_info);
@@ -970,9 +1199,7 @@ I830DRI2ScheduleSwap(ClientPtr client, DrawablePtr draw, DRI2BufferPtr front,
        I830DRI2ReferenceBuffer(back);
 
        /* Get current count */
-       vbl.request.type = DRM_VBLANK_RELATIVE;
-       if (pipe > 0)
-               vbl.request.type |= DRM_VBLANK_SECONDARY;
+       vbl.request.type = DRM_VBLANK_RELATIVE | pipe_select(pipe);
        vbl.request.sequence = 0;
        ret = drmWaitVBlank(intel->drmSubFD, &vbl);
        if (ret) {
@@ -985,10 +1212,7 @@ I830DRI2ScheduleSwap(ClientPtr client, DrawablePtr draw, DRI2BufferPtr front,
        current_msc = vbl.reply.sequence;
 
        /* Flips need to be submitted one frame before */
-       if (intel->use_pageflipping &&
-           !intel->shadow_present &&
-           DRI2CanFlip(draw) &&
-           can_exchange(front, back)) {
+       if (can_exchange(draw, front, back)) {
            swap_type = DRI2_FLIP;
            flip = 1;
        }
@@ -1008,9 +1232,11 @@ I830DRI2ScheduleSwap(ClientPtr client, DrawablePtr draw, DRI2BufferPtr front,
         * the swap.
         */
        if (divisor == 0 || current_msc < *target_msc) {
-               vbl.request.type =  DRM_VBLANK_ABSOLUTE | DRM_VBLANK_EVENT;
-               if (pipe > 0)
-                       vbl.request.type |= DRM_VBLANK_SECONDARY;
+               if (flip && I830DRI2ScheduleFlip(intel, draw, swap_info))
+                       return TRUE;
+
+               vbl.request.type =
+                       DRM_VBLANK_ABSOLUTE | DRM_VBLANK_EVENT | pipe_select(pipe);
 
                /* If non-pageflipping, but blitting/exchanging, we need to use
                 * DRM_VBLANK_NEXTONMISS to avoid unreliable timestamping later
@@ -1018,8 +1244,6 @@ I830DRI2ScheduleSwap(ClientPtr client, DrawablePtr draw, DRI2BufferPtr front,
                 */
                if (flip == 0)
                        vbl.request.type |= DRM_VBLANK_NEXTONMISS;
-               if (pipe > 0)
-                       vbl.request.type |= DRM_VBLANK_SECONDARY;
 
                /* If target_msc already reached or passed, set it to
                 * current_msc to ensure we return a reasonable value back
@@ -1049,11 +1273,10 @@ I830DRI2ScheduleSwap(ClientPtr client, DrawablePtr draw, DRI2BufferPtr front,
         * and we need to queue an event that will satisfy the divisor/remainder
         * equation.
         */
-       vbl.request.type = DRM_VBLANK_ABSOLUTE | DRM_VBLANK_EVENT;
+       vbl.request.type =
+               DRM_VBLANK_ABSOLUTE | DRM_VBLANK_EVENT | pipe_select(pipe);
        if (flip == 0)
                vbl.request.type |= DRM_VBLANK_NEXTONMISS;
-       if (pipe > 0)
-               vbl.request.type |= DRM_VBLANK_SECONDARY;
 
        vbl.request.sequence = current_msc - (current_msc % divisor) +
                remainder;
@@ -1100,12 +1323,8 @@ blit_fallback:
        I830DRI2CopyRegion(draw, &region, front, back);
 
        DRI2SwapComplete(client, draw, 0, 0, 0, DRI2_BLIT_COMPLETE, func, data);
-       if (swap_info) {
-           i830_dri2_del_frame_event(swap_info);
-           I830DRI2DestroyBuffer(draw, swap_info->front);
-           I830DRI2DestroyBuffer(draw, swap_info->back);
-           free(swap_info);
-       }
+       if (swap_info)
+           i830_dri2_del_frame_event(draw, swap_info);
        *target_msc = 0; /* offscreen, so zero out target vblank count */
        return TRUE;
 }
@@ -1118,7 +1337,7 @@ static int
 I830DRI2GetMSC(DrawablePtr draw, CARD64 *ust, CARD64 *msc)
 {
        ScreenPtr screen = draw->pScreen;
-       ScrnInfoPtr scrn = xf86Screens[screen->myNum];
+       ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
        intel_screen_private *intel = intel_get_screen_private(scrn);
        drmVBlank vbl;
        int ret, pipe = I830DRI2DrawablePipe(draw);
@@ -1130,9 +1349,7 @@ I830DRI2GetMSC(DrawablePtr draw, CARD64 *ust, CARD64 *msc)
                return TRUE;
        }
 
-       vbl.request.type = DRM_VBLANK_RELATIVE;
-       if (pipe > 0)
-               vbl.request.type |= DRM_VBLANK_SECONDARY;
+       vbl.request.type = DRM_VBLANK_RELATIVE | pipe_select(pipe);
        vbl.request.sequence = 0;
 
        ret = drmWaitVBlank(intel->drmSubFD, &vbl);
@@ -1165,7 +1382,7 @@ I830DRI2ScheduleWaitMSC(ClientPtr client, DrawablePtr draw, CARD64 target_msc,
                        CARD64 divisor, CARD64 remainder)
 {
        ScreenPtr screen = draw->pScreen;
-       ScrnInfoPtr scrn = xf86Screens[screen->myNum];
+       ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
        intel_screen_private *intel = intel_get_screen_private(scrn);
        DRI2FrameEventPtr wait_info;
        drmVBlank vbl;
@@ -1186,14 +1403,19 @@ I830DRI2ScheduleWaitMSC(ClientPtr client, DrawablePtr draw, CARD64 target_msc,
        if (!wait_info)
                goto out_complete;
 
+       wait_info->intel = intel;
        wait_info->drawable_id = draw->id;
        wait_info->client = client;
        wait_info->type = DRI2_WAITMSC;
 
+       if (!i830_dri2_add_frame_event(wait_info)) {
+           free(wait_info);
+           wait_info = NULL;
+           goto out_complete;
+       }
+
        /* Get current count */
-       vbl.request.type = DRM_VBLANK_RELATIVE;
-       if (pipe > 0)
-               vbl.request.type |= DRM_VBLANK_SECONDARY;
+       vbl.request.type = DRM_VBLANK_RELATIVE | pipe_select(pipe);
        vbl.request.sequence = 0;
        ret = drmWaitVBlank(intel->drmSubFD, &vbl);
        if (ret) {
@@ -1205,7 +1427,7 @@ I830DRI2ScheduleWaitMSC(ClientPtr client, DrawablePtr draw, CARD64 target_msc,
                                   strerror(errno));
                        limit--;
                }
-               goto out_complete;
+               goto out_free;
        }
 
        current_msc = vbl.reply.sequence;
@@ -1224,9 +1446,8 @@ I830DRI2ScheduleWaitMSC(ClientPtr client, DrawablePtr draw, CARD64 target_msc,
                 */
                if (current_msc >= target_msc)
                        target_msc = current_msc;
-               vbl.request.type = DRM_VBLANK_ABSOLUTE | DRM_VBLANK_EVENT;
-               if (pipe > 0)
-                       vbl.request.type |= DRM_VBLANK_SECONDARY;
+               vbl.request.type =
+                       DRM_VBLANK_ABSOLUTE | DRM_VBLANK_EVENT | pipe_select(pipe);
                vbl.request.sequence = target_msc;
                vbl.request.signal = (unsigned long)wait_info;
                ret = drmWaitVBlank(intel->drmSubFD, &vbl);
@@ -1239,7 +1460,7 @@ I830DRI2ScheduleWaitMSC(ClientPtr client, DrawablePtr draw, CARD64 target_msc,
                                           strerror(errno));
                                limit--;
                        }
-                       goto out_complete;
+                       goto out_free;
                }
 
                wait_info->frame = vbl.reply.sequence;
@@ -1251,9 +1472,8 @@ I830DRI2ScheduleWaitMSC(ClientPtr client, DrawablePtr draw, CARD64 target_msc,
         * If we get here, target_msc has already passed or we don't have one,
         * so we queue an event that will satisfy the divisor/remainder equation.
         */
-       vbl.request.type = DRM_VBLANK_ABSOLUTE | DRM_VBLANK_EVENT;
-       if (pipe > 0)
-               vbl.request.type |= DRM_VBLANK_SECONDARY;
+       vbl.request.type =
+               DRM_VBLANK_ABSOLUTE | DRM_VBLANK_EVENT | pipe_select(pipe);
 
        vbl.request.sequence = current_msc - (current_msc % divisor) +
            remainder;
@@ -1278,7 +1498,7 @@ I830DRI2ScheduleWaitMSC(ClientPtr client, DrawablePtr draw, CARD64 target_msc,
                                   strerror(errno));
                        limit--;
                }
-               goto out_complete;
+               goto out_free;
        }
 
        wait_info->frame = vbl.reply.sequence;
@@ -1286,6 +1506,8 @@ I830DRI2ScheduleWaitMSC(ClientPtr client, DrawablePtr draw, CARD64 target_msc,
 
        return TRUE;
 
+out_free:
+       i830_dri2_del_frame_event(draw, wait_info);
 out_complete:
        DRI2WaitMSCComplete(client, draw, target_msc, 0, 0);
        return TRUE;
@@ -1296,7 +1518,7 @@ static int dri2_server_generation;
 
 Bool I830DRI2ScreenInit(ScreenPtr screen)
 {
-       ScrnInfoPtr scrn = xf86Screens[screen->myNum];
+       ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
        intel_screen_private *intel = intel_get_screen_private(scrn);
        DRI2InfoRec info;
        int dri2_major = 1;
@@ -1320,6 +1542,15 @@ Bool I830DRI2ScreenInit(ScreenPtr screen)
                return FALSE;
        }
 
+#if HAS_DIXREGISTERPRIVATEKEY
+       if (!dixRegisterPrivateKey(&i830_client_key, PRIVATE_CLIENT, sizeof(XID)))
+               return FALSE;
+#else
+       if (!dixRequestPrivate(&i830_client_key, sizeof(XID)))
+               return FALSE;
+#endif
+
+
 #if DRI2INFOREC_VERSION >= 4
        if (serverGeneration != dri2_server_generation) {
            dri2_server_generation = serverGeneration;
@@ -1356,15 +1587,13 @@ Bool I830DRI2ScreenInit(ScreenPtr screen)
 
        info.CopyRegion = I830DRI2CopyRegion;
 #if DRI2INFOREC_VERSION >= 4
-       if (intel->use_pageflipping) {
-           info.version = 4;
-           info.ScheduleSwap = I830DRI2ScheduleSwap;
-           info.GetMSC = I830DRI2GetMSC;
-           info.ScheduleWaitMSC = I830DRI2ScheduleWaitMSC;
-           info.numDrivers = 1;
-           info.driverNames = driverNames;
-           driverNames[0] = info.driverName;
-       }
+       info.version = 4;
+       info.ScheduleSwap = I830DRI2ScheduleSwap;
+       info.GetMSC = I830DRI2GetMSC;
+       info.ScheduleWaitMSC = I830DRI2ScheduleWaitMSC;
+       info.numDrivers = 1;
+       info.driverNames = driverNames;
+       driverNames[0] = info.driverName;
 #endif
 
        return DRI2ScreenInit(screen, &info);
@@ -1372,7 +1601,7 @@ Bool I830DRI2ScreenInit(ScreenPtr screen)
 
 void I830DRI2CloseScreen(ScreenPtr screen)
 {
-       ScrnInfoPtr scrn = xf86Screens[screen->myNum];
+       ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
        intel_screen_private *intel = intel_get_screen_private(scrn);
 
        DRI2CloseScreen(screen);
index e867351..65a5008 100644 (file)
@@ -47,15 +47,14 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 #include "xf86.h"
 #include "xf86_OSproc.h"
-#include "xf86Priv.h"
 #include "xf86cmap.h"
+#include "xf86drm.h"
 #include "compiler.h"
-#include "mibstore.h"
-#include "vgaHW.h"
 #include "mipointer.h"
 #include "micmap.h"
 #include "shadowfb.h"
 #include <X11/extensions/randr.h>
+#include <X11/extensions/dpmsconst.h>
 #include "fb.h"
 #include "miscstruct.h"
 #include "dixstruct.h"
@@ -71,92 +70,23 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
 #endif
 
 #include "legacy/legacy.h"
+#include "uxa.h"
 
 #include <sys/ioctl.h>
 #include "i915_drm.h"
 #include <xf86drmMode.h>
 
-/* *INDENT-OFF* */
-/*
- * Note: "ColorKey" is provided for compatibility with the i810 driver.
- * However, the correct option name is "VideoKey".  "ColorKey" usually
- * refers to the tranparency key for 8+24 overlays, not for video overlays.
- */
+#include "intel_glamor.h"
+#include "intel_options.h"
 
-typedef enum {
-   OPTION_ACCELMETHOD,
-   OPTION_DRI,
-   OPTION_VIDEO_KEY,
-   OPTION_COLOR_KEY,
-   OPTION_FALLBACKDEBUG,
-   OPTION_TILING_FB,
-   OPTION_TILING_2D,
-   OPTION_SHADOW,
-   OPTION_SWAPBUFFERS_WAIT,
-#ifdef INTEL_XVMC
-   OPTION_XVMC,
-#endif
-   OPTION_PREFER_OVERLAY,
-   OPTION_DEBUG_FLUSH_BATCHES,
-   OPTION_DEBUG_FLUSH_CACHES,
-   OPTION_DEBUG_WAIT,
-   OPTION_HOTPLUG,
-   OPTION_RELAXED_FENCING,
-} I830Opts;
-
-static OptionInfoRec I830Options[] = {
-   {OPTION_ACCELMETHOD,        "AccelMethod",  OPTV_ANYSTR,    {0},    FALSE},
-   {OPTION_DRI,                "DRI",          OPTV_BOOLEAN,   {0},    TRUE},
-   {OPTION_COLOR_KEY,  "ColorKey",     OPTV_INTEGER,   {0},    FALSE},
-   {OPTION_VIDEO_KEY,  "VideoKey",     OPTV_INTEGER,   {0},    FALSE},
-   {OPTION_FALLBACKDEBUG, "FallbackDebug", OPTV_BOOLEAN, {0},  FALSE},
-   {OPTION_TILING_2D,  "Tiling",       OPTV_BOOLEAN,   {0},    TRUE},
-   {OPTION_TILING_FB,  "LinearFramebuffer",    OPTV_BOOLEAN,   {0},    FALSE},
-   {OPTION_SHADOW,     "Shadow",       OPTV_BOOLEAN,   {0},    FALSE},
-   {OPTION_SWAPBUFFERS_WAIT, "SwapbuffersWait", OPTV_BOOLEAN,  {0},    TRUE},
-#ifdef INTEL_XVMC
-   {OPTION_XVMC,       "XvMC",         OPTV_BOOLEAN,   {0},    TRUE},
-#endif
-   {OPTION_PREFER_OVERLAY, "XvPreferOverlay", OPTV_BOOLEAN, {0}, FALSE},
-   {OPTION_DEBUG_FLUSH_BATCHES, "DebugFlushBatches", OPTV_BOOLEAN, {0}, FALSE},
-   {OPTION_DEBUG_FLUSH_CACHES, "DebugFlushCaches", OPTV_BOOLEAN, {0}, FALSE},
-   {OPTION_DEBUG_WAIT, "DebugWait", OPTV_BOOLEAN, {0}, FALSE},
-   {OPTION_HOTPLUG,    "HotPlug",      OPTV_BOOLEAN,   {0},    TRUE},
-   {OPTION_RELAXED_FENCING,    "RelaxedFencing",       OPTV_BOOLEAN,   {0},    TRUE},
-   {-1,                        NULL,           OPTV_NONE,      {0},    FALSE}
-};
-/* *INDENT-ON* */
-
-static void i830AdjustFrame(int scrnIndex, int x, int y, int flags);
-static Bool I830CloseScreen(int scrnIndex, ScreenPtr screen);
-static Bool I830EnterVT(int scrnIndex, int flags);
+static void i830AdjustFrame(ADJUST_FRAME_ARGS_DECL);
+static Bool I830CloseScreen(CLOSE_SCREEN_ARGS_DECL);
+static Bool I830EnterVT(VT_FUNC_ARGS_DECL);
 
 /* temporary */
 extern void xf86SetCursor(ScreenPtr screen, CursorPtr pCurs, int x, int y);
 
-#ifdef I830DEBUG
-void
-I830DPRINTF(const char *filename, int line, const char *function,
-           const char *fmt, ...)
-{
-       va_list ap;
-
-       ErrorF("\n##############################################\n"
-              "*** In function %s, on line %d, in file %s ***\n",
-              function, line, filename);
-       va_start(ap, fmt);
-       VErrorF(fmt, ap);
-       va_end(ap);
-       ErrorF("##############################################\n\n");
-}
-#endif /* #ifdef I830DEBUG */
-
 /* Export I830 options to i830 driver where necessary */
-const OptionInfoRec *intel_uxa_available_options(int chipid, int busid)
-{
-       return I830Options;
-}
-
 static void
 I830LoadPalette(ScrnInfoPtr scrn, int numColors, int *indices,
                LOCO * colors, VisualPtr pVisual)
@@ -166,8 +96,6 @@ I830LoadPalette(ScrnInfoPtr scrn, int numColors, int *indices,
        int p;
        uint16_t lut_r[256], lut_g[256], lut_b[256];
 
-       DPRINTF(PFX, "I830LoadPalette: numColors: %d\n", numColors);
-
        for (p = 0; p < xf86_config->num_crtc; p++) {
                xf86CrtcPtr crtc = xf86_config->crtc[p];
 
@@ -231,14 +159,18 @@ I830LoadPalette(ScrnInfoPtr scrn, int numColors, int *indices,
  */
 static Bool i830CreateScreenResources(ScreenPtr screen)
 {
-       ScrnInfoPtr scrn = xf86Screens[screen->myNum];
+       ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
        intel_screen_private *intel = intel_get_screen_private(scrn);
 
        screen->CreateScreenResources = intel->CreateScreenResources;
        if (!(*screen->CreateScreenResources) (screen))
                return FALSE;
 
-       return intel_uxa_create_screen_resources(screen);
+       if (!intel_uxa_create_screen_resources(screen))
+               return FALSE;
+
+       intel_copy_fb(scrn);
+       return TRUE;
 }
 
 static void PreInitCleanup(ScrnInfoPtr scrn)
@@ -253,37 +185,7 @@ static void PreInitCleanup(ScrnInfoPtr scrn)
 static void intel_check_chipset_option(ScrnInfoPtr scrn)
 {
        intel_screen_private *intel = intel_get_screen_private(scrn);
-       MessageType from = X_PROBED;
-
-       intel_detect_chipset(scrn,
-                            intel->PciInfo,
-                            &intel->chipset);
-
-       /* Set the Chipset and ChipRev, allowing config file entries to override. */
-       if (intel->pEnt->device->chipset && *intel->pEnt->device->chipset) {
-               scrn->chipset = intel->pEnt->device->chipset;
-               from = X_CONFIG;
-       } else if (intel->pEnt->device->chipID >= 0) {
-               scrn->chipset = (char *)xf86TokenToString(intel_chipsets,
-                                                          intel->pEnt->device->chipID);
-               from = X_CONFIG;
-               xf86DrvMsg(scrn->scrnIndex, X_CONFIG,
-                          "ChipID override: 0x%04X\n",
-                          intel->pEnt->device->chipID);
-               DEVICE_ID(intel->PciInfo) = intel->pEnt->device->chipID;
-       } else {
-               from = X_PROBED;
-               scrn->chipset = (char *)xf86TokenToString(intel_chipsets,
-                                                          DEVICE_ID(intel->PciInfo));
-       }
-
-       if (intel->pEnt->device->chipRev >= 0) {
-               xf86DrvMsg(scrn->scrnIndex, X_CONFIG, "ChipRev override: %d\n",
-                          intel->pEnt->device->chipRev);
-       }
-
-       xf86DrvMsg(scrn->scrnIndex, from, "Chipset: \"%s\"\n",
-                  (scrn->chipset != NULL) ? scrn->chipset : "Unknown i8xx");
+       intel_detect_chipset(scrn, intel->pEnt, intel->PciInfo);
 }
 
 static Bool I830GetEarlyOptions(ScrnInfoPtr scrn)
@@ -291,11 +193,9 @@ static Bool I830GetEarlyOptions(ScrnInfoPtr scrn)
        intel_screen_private *intel = intel_get_screen_private(scrn);
 
        /* Process the options */
-       xf86CollectOptions(scrn, NULL);
-       if (!(intel->Options = malloc(sizeof(I830Options))))
+       intel->Options = intel_options_get(scrn);
+       if (!intel->Options)
                return FALSE;
-       memcpy(intel->Options, I830Options, sizeof(I830Options));
-       xf86ProcessOptions(scrn->scrnIndex, scrn->options, intel->Options);
 
        intel->fallback_debug = xf86ReturnOptValBool(intel->Options,
                                                     OPTION_FALLBACKDEBUG,
@@ -328,10 +228,10 @@ static void intel_check_dri_option(ScrnInfoPtr scrn)
        if (!xf86ReturnOptValBool(intel->Options, OPTION_DRI, TRUE))
                intel->directRenderingType = DRI_DISABLED;
 
-       if (scrn->depth != 16 && scrn->depth != 24) {
+       if (scrn->depth != 16 && scrn->depth != 24 && scrn->depth != 30) {
                xf86DrvMsg(scrn->scrnIndex, X_CONFIG,
                           "DRI is disabled because it "
-                          "runs only at depths 16 and 24.\n");
+                          "runs only at depths 16, 24, and 30.\n");
                intel->directRenderingType = DRI_DISABLED;
        }
 }
@@ -348,7 +248,7 @@ static Bool intel_open_drm_master(ScrnInfoPtr scrn)
        snprintf(busid, sizeof(busid), "pci:%04x:%02x:%02x.%d",
                 dev->domain, dev->bus, dev->dev, dev->func);
 
-       intel->drmSubFD = drmOpen("i915", busid);
+       intel->drmSubFD = drmOpen(NULL, busid);
        if (intel->drmSubFD == -1) {
                xf86DrvMsg(scrn->scrnIndex, X_ERROR,
                           "[drm] Failed to open DRM device for %s: %s\n",
@@ -410,18 +310,28 @@ static int intel_init_bufmgr(intel_screen_private *intel)
        if (!intel->bufmgr)
                return FALSE;
 
-       drm_intel_bufmgr_gem_enable_reuse(intel->bufmgr);
+       if (xf86ReturnOptValBool(intel->Options, OPTION_BUFFER_CACHE, TRUE))
+               drm_intel_bufmgr_gem_enable_reuse(intel->bufmgr);
+       drm_intel_bufmgr_gem_set_vma_cache_size(intel->bufmgr, 512);
        drm_intel_bufmgr_gem_enable_fenced_relocs(intel->bufmgr);
 
        list_init(&intel->batch_pixmaps);
-       list_init(&intel->flush_pixmaps);
-       list_init(&intel->in_flight);
+
+       if ((INTEL_INFO(intel)->gen == 60)) {
+               intel->wa_scratch_bo =
+                       drm_intel_bo_alloc(intel->bufmgr, "wa scratch",
+                                          4096, 4096);
+       }
 
        return TRUE;
 }
 
 static void intel_bufmgr_fini(intel_screen_private *intel)
 {
+       if (intel->bufmgr == NULL)
+               return;
+
+       drm_intel_bo_unreference(intel->wa_scratch_bo);
        drm_intel_bufmgr_destroy(intel->bufmgr);
 }
 
@@ -477,23 +387,37 @@ static Bool has_relaxed_fencing(struct intel_screen_private *intel)
        return drm_has_boolean_param(intel, I915_PARAM_HAS_RELAXED_FENCING);
 }
 
+static Bool has_prime_vmap_flush(struct intel_screen_private *intel)
+{
+       return drm_has_boolean_param(intel, I915_PARAM_HAS_PRIME_VMAP_FLUSH);
+}
+
 static Bool can_accelerate_blt(struct intel_screen_private *intel)
 {
-       if (0 && (IS_I830(intel) || IS_845G(intel))) {
-               /* These pair of i8xx chipsets have a crippling erratum
-                * that prevents the use of a PTE entry by the BLT
-                * engine immediately following updating that
-                * entry in the GATT.
-                *
-                * As the BLT is fundamental to our 2D acceleration,
-                * and the workaround is lost in the midst of time,
-                * fallback.
-                *
-                * XXX disabled for release as causes regressions in GL.
-                */
+       if (INTEL_INFO(intel)->gen == -1)
+               return FALSE;
+
+       if (xf86ReturnOptValBool(intel->Options, OPTION_ACCEL_DISABLE, FALSE)) {
+               xf86DrvMsg(intel->scrn->scrnIndex, X_CONFIG,
+                          "Disabling hardware acceleration.\n");
                return FALSE;
        }
 
+       if (INTEL_INFO(intel)->gen == 60) {
+               struct pci_device *const device = intel->PciInfo;
+
+               /* Sandybridge rev07 locks up easily, even with the
+                * BLT ring workaround in place.
+                * Thus use shadowfb by default.
+                */
+               if (device->revision < 8) {
+                       xf86DrvMsg(intel->scrn->scrnIndex, X_WARNING,
+                                  "Disabling hardware acceleration on this pre-production hardware.\n");
+
+                       return FALSE;
+               }
+       }
+
        if (INTEL_INFO(intel)->gen >= 60) {
                drm_i915_getparam_t gp;
                int value;
@@ -507,18 +431,26 @@ static Bool can_accelerate_blt(struct intel_screen_private *intel)
                        return FALSE;
        }
 
-       if (INTEL_INFO(intel)->gen == 60) {
-               struct pci_device *const device = intel->PciInfo;
+       return TRUE;
+}
 
-               /* Sandybridge rev07 locks up easily, even with the
-                * BLT ring workaround in place.
-                * Thus use shadowfb by default.
-                */
-               if (device->revision < 8)
-                   return FALSE;
-       }
+static void intel_setup_capabilities(ScrnInfoPtr scrn)
+{
+#ifdef INTEL_PIXMAP_SHARING
+       intel_screen_private *intel = intel_get_screen_private(scrn);
+       uint64_t value;
+       int ret;
 
-       return TRUE;
+       scrn->capabilities = 0;
+
+       ret = drmGetCap(intel->drmSubFD, DRM_CAP_PRIME, &value);
+       if (ret == 0) {
+               if (value & DRM_PRIME_CAP_EXPORT)
+                       scrn->capabilities |= RR_Capability_SourceOutput | RR_Capability_SinkOffload;
+               if (value & DRM_PRIME_CAP_IMPORT)
+                       scrn->capabilities |= RR_Capability_SinkOutput;
+       }
+#endif
 }
 
 /**
@@ -546,31 +478,40 @@ static Bool I830PreInit(ScrnInfoPtr scrn, int flags)
                return FALSE;
 
        pEnt = xf86GetEntityInfo(scrn->entityList[0]);
+       if (pEnt == NULL)
+               return FALSE;
+
+       if (pEnt->location.type != BUS_PCI
+#ifdef XSERVER_PLATFORM_BUS
+           && pEnt->location.type != BUS_PLATFORM
+#endif
+               )
+               return FALSE;
 
        if (flags & PROBE_DETECT)
                return TRUE;
 
-       intel = intel_get_screen_private(scrn);
-       if (intel == NULL) {
-               intel = xnfcalloc(sizeof(intel_screen_private), 1);
+       if (((uintptr_t)scrn->driverPrivate) & 1) {
+               intel = xnfcalloc(sizeof(*intel), 1);
                if (intel == NULL)
                        return FALSE;
 
+               intel->info = (void *)((uintptr_t)scrn->driverPrivate & ~1);
                scrn->driverPrivate = intel;
        }
+       intel = intel_get_screen_private(scrn);
        intel->scrn = scrn;
        intel->pEnt = pEnt;
 
        scrn->displayWidth = 640;       /* default it */
 
-       if (intel->pEnt->location.type != BUS_PCI)
-               return FALSE;
-
        intel->PciInfo = xf86GetPciInfoForEntity(intel->pEnt->index);
 
-       if (!intel_open_drm_master(scrn))
+       if (!intel_open_drm_master(scrn)) {
                xf86DrvMsg(scrn->scrnIndex, X_ERROR,
                           "Failed to become DRM master.\n");
+               return FALSE;
+       }
 
        scrn->monitor = scrn->confScreen->monitor;
        scrn->progClock = TRUE;
@@ -586,6 +527,7 @@ static Bool I830PreInit(ScrnInfoPtr scrn, int flags)
        case 15:
        case 16:
        case 24:
+       case 30:
                break;
        default:
                xf86DrvMsg(scrn->scrnIndex, X_ERROR,
@@ -605,6 +547,7 @@ static Bool I830PreInit(ScrnInfoPtr scrn, int flags)
        if (!I830GetEarlyOptions(scrn))
                return FALSE;
 
+       intel_setup_capabilities(scrn);
        intel_check_chipset_option(scrn);
        intel_check_dri_option(scrn);
 
@@ -624,23 +567,14 @@ static Bool I830PreInit(ScrnInfoPtr scrn, int flags)
                intel->tiling &= ~INTEL_TILING_2D;
        if (xf86ReturnOptValBool(intel->Options, OPTION_TILING_FB, FALSE))
                intel->tiling &= ~INTEL_TILING_FB;
+       if (!can_accelerate_blt(intel)) {
+               intel->force_fallback = TRUE;
+               intel->tiling &= ~INTEL_TILING_FB;
+       }
 
-       intel->can_blt = can_accelerate_blt(intel);
        intel->has_kernel_flush = has_kernel_flush(intel);
-       intel->use_shadow = !intel->can_blt;
 
-       if (xf86IsOptionSet(intel->Options, OPTION_SHADOW)) {
-               intel->use_shadow =
-                       xf86ReturnOptValBool(intel->Options,
-                                            OPTION_SHADOW,
-                                            FALSE);
-       }
-
-       if (intel->use_shadow) {
-               xf86DrvMsg(scrn->scrnIndex, X_CONFIG,
-                          "Shadow buffer enabled,"
-                          " 2D GPU acceleration disabled.\n");
-       }
+       intel->has_prime_vmap_flush = has_prime_vmap_flush(intel);
 
        intel->has_relaxed_fencing =
                xf86ReturnOptValBool(intel->Options,
@@ -658,8 +592,15 @@ static Bool I830PreInit(ScrnInfoPtr scrn, int flags)
        intel->swapbuffers_wait = xf86ReturnOptValBool(intel->Options,
                                                       OPTION_SWAPBUFFERS_WAIT,
                                                       TRUE);
-       if (IS_GEN6(intel))
-               intel->swapbuffers_wait = FALSE;
+       xf86DrvMsg(scrn->scrnIndex, X_CONFIG, "Wait on SwapBuffers? %s\n",
+                  intel->swapbuffers_wait ? "enabled" : "disabled");
+
+       intel->use_triple_buffer =
+               xf86ReturnOptValBool(intel->Options,
+                                    OPTION_TRIPLE_BUFFER,
+                                    TRUE);
+       xf86DrvMsg(scrn->scrnIndex, X_CONFIG, "Triple buffering? %s\n",
+                  intel->use_triple_buffer ? "enabled" : "disabled");
 
        xf86DrvMsg(scrn->scrnIndex, X_CONFIG, "Framebuffer %s\n",
                   intel->tiling & INTEL_TILING_FB ? "tiled" : "linear");
@@ -698,6 +639,13 @@ static Bool I830PreInit(ScrnInfoPtr scrn, int flags)
                return FALSE;
        }
 
+       if (!intel_glamor_pre_init(scrn)) {
+               PreInitCleanup(scrn);
+               xf86DrvMsg(scrn->scrnIndex, X_ERROR,
+                       "Failed to pre init glamor display.\n");
+               return FALSE;
+       }
+
        /* Load the dri2 module if requested. */
        if (intel->directRenderingType != DRI_DISABLED)
                xf86LoadSubModule(scrn, "dri2");
@@ -728,22 +676,70 @@ void IntelEmitInvarientState(ScrnInfoPtr scrn)
                I915EmitInvarientState(scrn);
 }
 
+#ifdef INTEL_PIXMAP_SHARING
+static Bool
+redisplay_dirty(ScreenPtr screen, PixmapDirtyUpdatePtr dirty)
+{
+       ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+       intel_screen_private *intel = intel_get_screen_private(scrn);
+       RegionRec pixregion;
+       int was_blocked;
+
+       PixmapRegionInit(&pixregion, dirty->slave_dst->master_pixmap);
+
+       PixmapSyncDirtyHelper(dirty, &pixregion);
+       intel_batch_submit(scrn);
+       if (!intel->has_prime_vmap_flush) {
+               drm_intel_bo *bo = intel_get_pixmap_bo(dirty->slave_dst->master_pixmap);
+               was_blocked = xf86BlockSIGIO();
+               drm_intel_bo_map(bo, FALSE);
+               drm_intel_bo_unmap(bo);
+               xf86UnblockSIGIO(was_blocked);
+        }
+        DamageRegionAppend(&dirty->slave_dst->drawable, &pixregion);
+        RegionUninit(&pixregion);
+       return 0;
+}
+
+static void
+intel_dirty_update(ScreenPtr screen)
+{
+       RegionPtr region;
+       PixmapDirtyUpdatePtr ent;
+
+       if (xorg_list_is_empty(&screen->pixmap_dirty_list))
+           return;
+
+       ErrorF("list is not empty\n");
+       xorg_list_for_each_entry(ent, &screen->pixmap_dirty_list, ent) {
+               region = DamageRegion(ent->damage);
+               if (RegionNotEmpty(region)) {
+                       redisplay_dirty(screen, ent);
+                       DamageEmpty(ent->damage);
+               }
+       }
+}
+#endif
+
 static void
-I830BlockHandler(int i, pointer blockData, pointer pTimeout, pointer pReadmask)
+I830BlockHandler(BLOCKHANDLER_ARGS_DECL)
 {
-       ScreenPtr screen = screenInfo.screens[i];
-       ScrnInfoPtr scrn = xf86Screens[i];
+       SCREEN_PTR(arg);
+       ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
        intel_screen_private *intel = intel_get_screen_private(scrn);
 
        screen->BlockHandler = intel->BlockHandler;
 
-       (*screen->BlockHandler) (i, blockData, pTimeout, pReadmask);
+       (*screen->BlockHandler) (BLOCKHANDLER_ARGS);
 
        intel->BlockHandler = screen->BlockHandler;
        screen->BlockHandler = I830BlockHandler;
 
        intel_uxa_block_handler(intel);
        intel_video_block_handler(intel);
+#ifdef INTEL_PIXMAP_SHARING
+       intel_dirty_update(screen);
+#endif
 }
 
 static Bool
@@ -774,33 +770,15 @@ intel_init_initial_framebuffer(ScrnInfoPtr scrn)
        return TRUE;
 }
 
-Bool intel_crtc_on(xf86CrtcPtr crtc)
-{
-       ScrnInfoPtr scrn = crtc->scrn;
-       xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
-       int i;
-
-       if (!crtc->enabled)
-               return FALSE;
-
-       /* Kernel manages CRTC status based out output config */
-       for (i = 0; i < xf86_config->num_output; i++) {
-               xf86OutputPtr output = xf86_config->output[i];
-               if (output->crtc == crtc &&
-                   intel_output_dpms_status(output) == DPMSModeOn)
-                       return TRUE;
-       }
-
-       return FALSE;
-}
-
 static void
 intel_flush_callback(CallbackListPtr *list,
                     pointer user_data, pointer call_data)
 {
        ScrnInfoPtr scrn = user_data;
-       if (scrn->vtSema)
+       if (scrn->vtSema) {
                intel_batch_submit(scrn);
+               intel_glamor_flush(intel_get_screen_private(scrn));
+       }
 }
 
 #if HAVE_UDEV
@@ -819,7 +797,10 @@ I830HandleUEvents(int fd, void *closure)
                return;
 
        udev_devnum = udev_device_get_devnum(dev);
-       fstat(intel->drmSubFD, &s);
+       if (fstat(intel->drmSubFD, &s)) {
+               udev_device_unref(dev);
+               return;
+       }
        /*
         * Check to make sure this event is directed at our
         * device (by comparing dev_t values), then make
@@ -830,7 +811,7 @@ I830HandleUEvents(int fd, void *closure)
 
        if (memcmp(&s.st_rdev, &udev_devnum, sizeof (dev_t)) == 0 &&
                        hotplug && atoi(hotplug) == 1)
-               RRGetInfo(screenInfo.screens[scrn->scrnIndex], TRUE);
+               RRGetInfo(xf86ScrnToScreen(scrn), TRUE);
 
        udev_device_unref(dev);
 }
@@ -907,9 +888,9 @@ I830UeventFini(ScrnInfoPtr scrn)
 #endif /* HAVE_UDEV */
 
 static Bool
-I830ScreenInit(int scrnIndex, ScreenPtr screen, int argc, char **argv)
+I830ScreenInit(SCREEN_INIT_ARGS_DECL)
 {
-       ScrnInfoPtr scrn = xf86Screens[screen->myNum];
+       ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
        intel_screen_private *intel = intel_get_screen_private(scrn);
        VisualPtr visual;
 #ifdef INTEL_XVMC
@@ -951,9 +932,6 @@ I830ScreenInit(int scrnIndex, ScreenPtr screen, int argc, char **argv)
        if (!miSetPixmapDepths())
                return FALSE;
 
-       DPRINTF(PFX, "assert( if(!I830EnterVT(scrnIndex, 0)) )\n");
-
-       DPRINTF(PFX, "assert( if(!fbScreenInit(screen, ...) )\n");
        if (!fbScreenInit(screen, NULL,
                          scrn->virtualX, scrn->virtualY,
                          scrn->xDpi, scrn->yDpi,
@@ -985,13 +963,12 @@ I830ScreenInit(int scrnIndex, ScreenPtr screen, int argc, char **argv)
                return FALSE;
        }
 
-       miInitializeBackingStore(screen);
        xf86SetBackingStore(screen);
        xf86SetSilkenMouse(screen);
        miDCInitialize(screen, xf86GetPointerScreenFuncs());
 
        xf86DrvMsg(scrn->scrnIndex, X_INFO, "Initializing HW Cursor\n");
-       if (!xf86_cursors_init(screen, I810_CURSOR_X, I810_CURSOR_Y,
+       if (!xf86_cursors_init(screen, 64, 64,
                               (HARDWARE_CURSOR_TRUECOLOR_AT_8BPP |
                                HARDWARE_CURSOR_BIT_ORDER_MSBFIRST |
                                HARDWARE_CURSOR_INVERT_MASK |
@@ -1004,16 +981,14 @@ I830ScreenInit(int scrnIndex, ScreenPtr screen, int argc, char **argv)
                           "Hardware cursor initialization failed\n");
        }
 
-       /* Must force it before EnterVT, so we are in control of VT and
-        * later memory should be bound when allocating, e.g rotate_mem */
-       scrn->vtSema = TRUE;
-
-       if (!I830EnterVT(scrnIndex, 0))
-               return FALSE;
-
        intel->BlockHandler = screen->BlockHandler;
        screen->BlockHandler = I830BlockHandler;
 
+#ifdef INTEL_PIXMAP_SHARING
+       screen->StartPixmapTracking = PixmapStartDirtyTracking;
+       screen->StopPixmapTracking = PixmapStopDirtyTracking;
+#endif
+
        if (!AddCallback(&FlushCallback, intel_flush_callback, scrn))
                return FALSE;
 
@@ -1023,14 +998,13 @@ I830ScreenInit(int scrnIndex, ScreenPtr screen, int argc, char **argv)
        intel->CreateScreenResources = screen->CreateScreenResources;
        screen->CreateScreenResources = i830CreateScreenResources;
 
+       intel_glamor_init(screen);
        if (!xf86CrtcScreenInit(screen))
                return FALSE;
 
-       DPRINTF(PFX, "assert( if(!miCreateDefColormap(screen)) )\n");
        if (!miCreateDefColormap(screen))
                return FALSE;
 
-       DPRINTF(PFX, "assert( if(!xf86HandleColormaps(screen, ...)) )\n");
        if (!xf86HandleColormaps(screen, 256, 8, I830LoadPalette, NULL,
                                 CMAP_RELOAD_ON_MODE_SWITCH |
                                 CMAP_PALETTED_TRUECOLOR)) {
@@ -1084,16 +1058,20 @@ I830ScreenInit(int scrnIndex, ScreenPtr screen, int argc, char **argv)
        I830UeventInit(scrn);
 #endif
 
-       return TRUE;
+       /* Must force it before EnterVT, so we are in control of VT and
+        * later memory should be bound when allocating, e.g rotate_mem */
+       scrn->vtSema = TRUE;
+
+       return I830EnterVT(VT_FUNC_ARGS(0));
 }
 
-static void i830AdjustFrame(int scrnIndex, int x, int y, int flags)
+static void i830AdjustFrame(ADJUST_FRAME_ARGS_DECL)
 {
 }
 
-static void I830FreeScreen(int scrnIndex, int flags)
+static void I830FreeScreen(FREE_SCREEN_ARGS_DECL)
 {
-       ScrnInfoPtr scrn = xf86Screens[scrnIndex];
+       SCRN_INFO_PTR(arg);
        intel_screen_private *intel = intel_get_screen_private(scrn);
 
        if (intel) {
@@ -1104,19 +1082,14 @@ static void I830FreeScreen(int scrnIndex, int flags)
                free(intel);
                scrn->driverPrivate = NULL;
        }
-
-       if (xf86LoaderCheckSymbol("vgaHWFreeHWRec"))
-               vgaHWFreeHWRec(xf86Screens[scrnIndex]);
 }
 
-static void I830LeaveVT(int scrnIndex, int flags)
+static void I830LeaveVT(VT_FUNC_ARGS_DECL)
 {
-       ScrnInfoPtr scrn = xf86Screens[scrnIndex];
+       SCRN_INFO_PTR(arg);
        intel_screen_private *intel = intel_get_screen_private(scrn);
        int ret;
 
-       DPRINTF(PFX, "Leave VT\n");
-
        xf86RotateFreeShadow(scrn);
 
        xf86_hide_cursors(scrn);
@@ -1130,14 +1103,12 @@ static void I830LeaveVT(int scrnIndex, int flags)
 /*
  * This gets called when gaining control of the VT, and from ScreenInit().
  */
-static Bool I830EnterVT(int scrnIndex, int flags)
+static Bool I830EnterVT(VT_FUNC_ARGS_DECL)
 {
-       ScrnInfoPtr scrn = xf86Screens[scrnIndex];
+       SCRN_INFO_PTR(arg);
        intel_screen_private *intel = intel_get_screen_private(scrn);
        int ret;
 
-       DPRINTF(PFX, "Enter VT\n");
-
        ret = drmSetMaster(intel->drmSubFD);
        if (ret) {
                xf86DrvMsg(scrn->scrnIndex, X_WARNING,
@@ -1145,61 +1116,60 @@ static Bool I830EnterVT(int scrnIndex, int flags)
                           strerror(errno));
        }
 
-       intel_set_gem_max_sizes(scrn);
-
        if (!xf86SetDesiredModes(scrn))
                return FALSE;
 
+       intel_mode_disable_unused_functions(scrn);
        return TRUE;
 }
 
-static Bool I830SwitchMode(int scrnIndex, DisplayModePtr mode, int flags)
+static Bool I830SwitchMode(SWITCH_MODE_ARGS_DECL)
 {
-       ScrnInfoPtr scrn = xf86Screens[scrnIndex];
+       SCRN_INFO_PTR(arg);
 
        return xf86SetSingleMode(scrn, mode, RR_Rotate_0);
 }
 
-static Bool I830CloseScreen(int scrnIndex, ScreenPtr screen)
+static Bool I830CloseScreen(CLOSE_SCREEN_ARGS_DECL)
 {
-       ScrnInfoPtr scrn = xf86Screens[scrnIndex];
+       ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
        intel_screen_private *intel = intel_get_screen_private(scrn);
 
 #if HAVE_UDEV
        I830UeventFini(scrn);
 #endif
 
-       if (scrn->vtSema == TRUE) {
-               I830LeaveVT(scrnIndex, 0);
-       }
-
        DeleteCallback(&FlushCallback, intel_flush_callback, scrn);
 
+       intel_glamor_close_screen(screen);
+
+       TimerFree(intel->cache_expire);
+       intel->cache_expire = NULL;
+
        if (intel->uxa_driver) {
                uxa_driver_fini(screen);
                free(intel->uxa_driver);
                intel->uxa_driver = NULL;
        }
 
+       if (intel->back_pixmap) {
+               screen->DestroyPixmap(intel->back_pixmap);
+               intel->back_pixmap = NULL;
+       }
+
+       if (intel->back_buffer) {
+               drm_intel_bo_unreference(intel->back_buffer);
+               intel->back_buffer = NULL;
+       }
+
        if (intel->front_buffer) {
-               if (!intel->use_shadow)
-                       intel_set_pixmap_bo(screen->GetScreenPixmap(screen),
-                                           NULL);
                intel_mode_remove_fb(intel);
                drm_intel_bo_unreference(intel->front_buffer);
                intel->front_buffer = NULL;
        }
 
-       if (intel->shadow_buffer) {
-               free(intel->shadow_buffer);
-               intel->shadow_buffer = NULL;
-       }
-
-       if (intel->shadow_damage) {
-               DamageUnregister(&screen->GetScreenPixmap(screen)->drawable,
-                                intel->shadow_damage);
-               DamageDestroy(intel->shadow_damage);
-               intel->shadow_damage = NULL;
+       if (scrn->vtSema == TRUE) {
+               I830LeaveVT(VT_FUNC_ARGS(0));
        }
 
        intel_batch_teardown(scrn);
@@ -1212,7 +1182,7 @@ static Bool I830CloseScreen(int scrnIndex, ScreenPtr screen)
        i965_free_video(scrn);
 
        screen->CloseScreen = intel->CloseScreen;
-       (*screen->CloseScreen) (scrnIndex, screen);
+       (*screen->CloseScreen) (CLOSE_SCREEN_ARGS);
 
        if (intel->directRenderingOpen
            && intel->directRenderingType == DRI_DRI2) {
@@ -1220,18 +1190,19 @@ static Bool I830CloseScreen(int scrnIndex, ScreenPtr screen)
                I830DRI2CloseScreen(screen);
        }
 
-       xf86GARTCloseScreen(scrnIndex);
+       xf86GARTCloseScreen(scrn->scrnIndex);
 
        scrn->vtSema = FALSE;
        return TRUE;
 }
 
 static ModeStatus
-I830ValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, int flags)
+I830ValidMode(SCRN_ARG_TYPE arg, DisplayModePtr mode, Bool verbose, int flags)
 {
+       SCRN_INFO_PTR(arg);
        if (mode->Flags & V_INTERLACE) {
                if (verbose) {
-                       xf86DrvMsg(scrnIndex, X_PROBED,
+                       xf86DrvMsg(scrn->scrnIndex, X_PROBED,
                                   "Removing interlaced mode \"%s\"\n",
                                   mode->name);
                }
@@ -1252,14 +1223,11 @@ I830ValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, int flags)
  * DoApmEvent() in common/xf86PM.c, including if we want to see events other
  * than suspend/resume.
  */
-static Bool I830PMEvent(int scrnIndex, pmEvent event, Bool undo)
+static Bool I830PMEvent(SCRN_ARG_TYPE arg, pmEvent event, Bool undo)
 {
-       ScrnInfoPtr scrn = xf86Screens[scrnIndex];
+       SCRN_INFO_PTR(arg);
        intel_screen_private *intel = intel_get_screen_private(scrn);
 
-       DPRINTF(PFX, "Enter VT, event %d, undo: %s\n", event,
-               BOOLTOSTRING(undo));
-
        switch (event) {
        case XF86_APM_SYS_SUSPEND:
        case XF86_APM_CRITICAL_SUSPEND: /*do we want to delay a critical suspend? */
@@ -1267,12 +1235,12 @@ static Bool I830PMEvent(int scrnIndex, pmEvent event, Bool undo)
        case XF86_APM_SYS_STANDBY:
        case XF86_APM_USER_STANDBY:
                if (!undo && !intel->suspended) {
-                       scrn->LeaveVT(scrnIndex, 0);
+                       scrn->LeaveVT(VT_FUNC_ARGS(0));
                        intel->suspended = TRUE;
                        sleep(SUSPEND_SLEEP);
                } else if (undo && intel->suspended) {
                        sleep(RESUME_SLEEP);
-                       scrn->EnterVT(scrnIndex, 0);
+                       scrn->EnterVT(VT_FUNC_ARGS(0));
                        intel->suspended = FALSE;
                }
                break;
@@ -1281,7 +1249,7 @@ static Bool I830PMEvent(int scrnIndex, pmEvent event, Bool undo)
        case XF86_APM_CRITICAL_RESUME:
                if (intel->suspended) {
                        sleep(RESUME_SLEEP);
-                       scrn->EnterVT(scrnIndex, 0);
+                       scrn->EnterVT(VT_FUNC_ARGS(0));
                        intel->suspended = FALSE;
                        /*
                         * Turn the screen saver off when resuming.  This seems to be
@@ -1307,7 +1275,7 @@ static Bool I830PMEvent(int scrnIndex, pmEvent event, Bool undo)
        return TRUE;
 }
 
-void intel_init_scrn(ScrnInfoPtr scrn)
+Bool intel_init_scrn(ScrnInfoPtr scrn)
 {
        scrn->PreInit = I830PreInit;
        scrn->ScreenInit = I830ScreenInit;
@@ -1318,4 +1286,5 @@ void intel_init_scrn(ScrnInfoPtr scrn)
        scrn->FreeScreen = I830FreeScreen;
        scrn->ValidMode = I830ValidMode;
        scrn->PMEvent = I830PMEvent;
+       return TRUE;
 }
index 2e72177..b719062 100644 (file)
 #define PCI_CHIP_SANDYBRIDGE_M_GT2_PLUS        0x0126
 #define PCI_CHIP_SANDYBRIDGE_BRIDGE_S  0x0108  /* Server */
 #define PCI_CHIP_SANDYBRIDGE_S_GT      0x010A
+
+#define PCI_CHIP_IVYBRIDGE_M_GT1       0x0156
+#define PCI_CHIP_IVYBRIDGE_M_GT2       0x0166
+#define PCI_CHIP_IVYBRIDGE_D_GT1       0x0152
+#define PCI_CHIP_IVYBRIDGE_D_GT2       0x0162
+#define PCI_CHIP_IVYBRIDGE_S_GT1       0x015a
+#define PCI_CHIP_IVYBRIDGE_S_GT2       0x016a
+
+#define PCI_CHIP_HASWELL_D_GT1         0x0402
+#define PCI_CHIP_HASWELL_D_GT2         0x0412
+#define PCI_CHIP_HASWELL_D_GT2_PLUS    0x0422
+#define PCI_CHIP_HASWELL_M_GT1         0x0406
+#define PCI_CHIP_HASWELL_M_GT2         0x0416
+#define PCI_CHIP_HASWELL_M_GT2_PLUS    0x0426
+#define PCI_CHIP_HASWELL_S_GT1         0x040A
+#define PCI_CHIP_HASWELL_S_GT2         0x041A
+#define PCI_CHIP_HASWELL_S_GT2_PLUS    0x042A
+#define PCI_CHIP_HASWELL_SDV_D_GT1     0x0C02
+#define PCI_CHIP_HASWELL_SDV_D_GT2     0x0C12
+#define PCI_CHIP_HASWELL_SDV_D_GT2_PLUS        0x0C22
+#define PCI_CHIP_HASWELL_SDV_M_GT1     0x0C06
+#define PCI_CHIP_HASWELL_SDV_M_GT2     0x0C16
+#define PCI_CHIP_HASWELL_SDV_M_GT2_PLUS        0x0C26
+#define PCI_CHIP_HASWELL_SDV_S_GT1     0x0C0A
+#define PCI_CHIP_HASWELL_SDV_S_GT2     0x0C1A
+#define PCI_CHIP_HASWELL_SDV_S_GT2_PLUS        0x0C2A
+#define PCI_CHIP_HASWELL_ULT_D_GT1     0x0A02
+#define PCI_CHIP_HASWELL_ULT_D_GT2     0x0A12
+#define PCI_CHIP_HASWELL_ULT_D_GT2_PLUS        0x0A22
+#define PCI_CHIP_HASWELL_ULT_M_GT1     0x0A06
+#define PCI_CHIP_HASWELL_ULT_M_GT2     0x0A16
+#define PCI_CHIP_HASWELL_ULT_M_GT2_PLUS        0x0A26
+#define PCI_CHIP_HASWELL_ULT_S_GT1     0x0A0A
+#define PCI_CHIP_HASWELL_ULT_S_GT2     0x0A1A
+#define PCI_CHIP_HASWELL_ULT_S_GT2_PLUS        0x0A2A
+#define PCI_CHIP_HASWELL_CRW_D_GT1     0x0D12
+#define PCI_CHIP_HASWELL_CRW_D_GT2     0x0D22
+#define PCI_CHIP_HASWELL_CRW_D_GT2_PLUS        0x0D32
+#define PCI_CHIP_HASWELL_CRW_M_GT1     0x0D16
+#define PCI_CHIP_HASWELL_CRW_M_GT2     0x0D26
+#define PCI_CHIP_HASWELL_CRW_M_GT2_PLUS        0x0D36
+#define PCI_CHIP_HASWELL_CRW_S_GT1     0x0D1A
+#define PCI_CHIP_HASWELL_CRW_S_GT2     0x0D2A
+#define PCI_CHIP_HASWELL_CRW_S_GT2_PLUS        0x0D3A
+
+#define PCI_CHIP_VALLEYVIEW_PO         0x0f30
+
 #endif
 
 #define I85X_CAPID                     0x44
 #define SUBSYS_ID(p)      (p)->subdevice_id
 #define CHIP_REVISION(p)  (p)->revision
 
-#define INTEL_INFO(intel) ((intel)->chipset.info)
+#define INTEL_INFO(intel) ((intel)->info)
 #define IS_GENx(intel, X) (INTEL_INFO(intel)->gen >= 10*(X) && INTEL_INFO(intel)->gen < 10*((X)+1))
 #define IS_GEN1(intel) IS_GENx(intel, 1)
 #define IS_GEN2(intel) IS_GENx(intel, 2)
 #define IS_GEN4(intel) IS_GENx(intel, 4)
 #define IS_GEN5(intel) IS_GENx(intel, 5)
 #define IS_GEN6(intel) IS_GENx(intel, 6)
+#define IS_GEN7(intel) IS_GENx(intel, 7)
+#define IS_HSW(intel) (INTEL_INFO(intel)->gen == 75)
 
 /* Some chips have specific errata (or limits) that we need to workaround. */
 #define IS_I830(intel) (DEVICE_ID((intel)->PciInfo) == PCI_CHIP_I830_M)
 
 /* supports Y tiled surfaces (pre-965 Mesa isn't ready yet) */
 #define SUPPORTS_YTILING(pI810) (INTEL_INFO(intel)->gen >= 40)
+#define HAS_BLT(pI810) (INTEL_INFO(intel)->gen >= 60)
 
-extern SymTabRec *intel_chipsets;
-
-struct intel_chipset {
-    const char *name;
-    int variant;
-    const struct intel_device_info {
-           int gen;
-    } *info;
+struct intel_device_info {
+       int gen;
 };
 
 void intel_detect_chipset(ScrnInfoPtr scrn,
-                         struct pci_device *pci,
-                         struct intel_chipset *chipset);
+                         EntityInfoPtr ent,
+                         struct pci_device *pci);
+
 
 #endif /* INTEL_DRIVER_H */
diff --git a/src/intel_glamor.c b/src/intel_glamor.c
new file mode 100644 (file)
index 0000000..55eb2de
--- /dev/null
@@ -0,0 +1,247 @@
+/*
+ * Copyright © 2011 Intel 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.
+ *
+ * Authors:
+ *    Zhigang Gong <zhigang.gong@linux.intel.com>
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <xf86.h>
+#define GLAMOR_FOR_XORG  1
+#include <glamor.h>
+
+#include "intel.h"
+#include "i915_drm.h"
+#include "intel_glamor.h"
+#include "uxa.h"
+#include "intel_options.h"
+
+void
+intel_glamor_exchange_buffers(struct intel_screen_private *intel,
+                             PixmapPtr src,
+                             PixmapPtr dst)
+{
+       if (!(intel->uxa_flags & UXA_USE_GLAMOR))
+               return;
+       glamor_egl_exchange_buffers(src, dst);
+}
+
+Bool
+intel_glamor_create_screen_resources(ScreenPtr screen)
+{
+       ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+       intel_screen_private *intel = intel_get_screen_private(scrn);
+
+       if (!(intel->uxa_flags & UXA_USE_GLAMOR))
+               return TRUE;
+
+       if (!glamor_glyphs_init(screen))
+               return FALSE;
+
+       if (!glamor_egl_create_textured_screen_ext(screen,
+                                                  intel->front_buffer->handle,
+                                                  intel->front_pitch,
+                                                  &intel->back_pixmap))
+               return FALSE;
+
+       return TRUE;
+}
+
+Bool
+intel_glamor_pre_init(ScrnInfoPtr scrn)
+{
+       intel_screen_private *intel = intel_get_screen_private(scrn);
+       pointer glamor_module;
+       CARD32 version;
+
+       /* Load glamor module */
+       if ((glamor_module = xf86LoadSubModule(scrn, GLAMOR_EGL_MODULE_NAME))) {
+               version = xf86GetModuleVersion(glamor_module);
+               if (version < MODULE_VERSION_NUMERIC(0,3,1)) {
+                       xf86DrvMsg(scrn->scrnIndex, X_ERROR,
+                       "Incompatible glamor version, required >= 0.3.0.\n");
+               } else {
+                       if (glamor_egl_init(scrn, intel->drmSubFD)) {
+                               xf86DrvMsg(scrn->scrnIndex, X_INFO,
+                                          "glamor detected, initialising egl layer.\n");
+                               intel->uxa_flags = UXA_GLAMOR_EGL_INITIALIZED;
+                       } else
+                               xf86DrvMsg(scrn->scrnIndex, X_WARNING,
+                                          "glamor detected, failed to initialize egl.\n");
+               }
+       } else
+               xf86DrvMsg(scrn->scrnIndex, X_WARNING,
+                          "glamor not available\n");
+
+       return TRUE;
+}
+
+PixmapPtr
+intel_glamor_create_pixmap(ScreenPtr screen, int w, int h,
+                          int depth, unsigned int usage)
+{
+       ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+       intel_screen_private *intel = intel_get_screen_private(scrn);
+
+       if (intel->uxa_flags & UXA_USE_GLAMOR)
+               return glamor_create_pixmap(screen, w, h, depth, usage);
+       else
+               return NULL;
+}
+
+Bool
+intel_glamor_create_textured_pixmap(PixmapPtr pixmap)
+{
+       ScrnInfoPtr scrn = xf86ScreenToScrn(pixmap->drawable.pScreen);
+       intel_screen_private *intel = intel_get_screen_private(scrn);
+       struct intel_pixmap *priv;
+
+       if ((intel->uxa_flags & UXA_USE_GLAMOR) == 0)
+               return TRUE;
+
+       priv = intel_get_pixmap_private(pixmap);
+       if (glamor_egl_create_textured_pixmap(pixmap, priv->bo->handle,
+                                             priv->stride)) {
+               drm_intel_bo_disable_reuse(priv->bo);
+               priv->pinned |= PIN_GLAMOR;
+               return TRUE;
+       } else
+               return FALSE;
+}
+
+void
+intel_glamor_destroy_pixmap(PixmapPtr pixmap)
+{
+       ScrnInfoPtr scrn = xf86ScreenToScrn(pixmap->drawable.pScreen);
+       intel_screen_private * intel;
+
+       intel = intel_get_screen_private(scrn);
+       if (intel->uxa_flags & UXA_USE_GLAMOR)
+               glamor_egl_destroy_textured_pixmap(pixmap);
+}
+
+static void
+intel_glamor_need_flush(DrawablePtr pDrawable)
+{
+       ScrnInfoPtr scrn = xf86ScreenToScrn(pDrawable->pScreen);
+       intel_screen_private * intel;
+
+       intel = intel_get_screen_private(scrn);
+       intel->needs_flush = TRUE;
+}
+
+static void
+intel_glamor_finish_access(PixmapPtr pixmap, uxa_access_t access)
+{
+       switch(access) {
+       case UXA_ACCESS_RO:
+       case UXA_ACCESS_RW:
+       case UXA_GLAMOR_ACCESS_RO:
+               break;
+       case UXA_GLAMOR_ACCESS_RW:
+               intel_glamor_need_flush(&pixmap->drawable);
+               break;
+       default:
+               ErrorF("Invalid access mode %d\n", access);
+       }
+
+       return;
+}
+
+static Bool
+intel_glamor_enabled(intel_screen_private *intel)
+{
+       const char *s;
+
+       s = xf86GetOptValString(intel->Options, OPTION_ACCEL_METHOD);
+       if (s == NULL)
+               return FALSE;
+
+       return strcasecmp(s, "glamor") == 0;
+}
+
+Bool
+intel_glamor_init(ScreenPtr screen)
+{
+       ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+       intel_screen_private *intel = intel_get_screen_private(scrn);
+
+       if ((intel->uxa_flags & UXA_GLAMOR_EGL_INITIALIZED) == 0)
+               goto fail;
+
+       if (!intel_glamor_enabled(intel))
+               goto fail;
+
+       if (!glamor_init(screen, GLAMOR_INVERTED_Y_AXIS | GLAMOR_USE_EGL_SCREEN)) {
+               xf86DrvMsg(scrn->scrnIndex, X_ERROR,
+                          "Failed to initialize glamor.\n");
+               goto fail;
+       }
+
+       if (!glamor_egl_init_textured_pixmap(screen)) {
+               xf86DrvMsg(scrn->scrnIndex, X_ERROR,
+                          "Failed to initialize textured pixmap of screen for glamor.\n");
+               goto fail;
+       }
+
+       intel->uxa_driver->flags |= UXA_USE_GLAMOR;
+       intel->uxa_flags |= intel->uxa_driver->flags;
+
+       intel->uxa_driver->finish_access = intel_glamor_finish_access;
+
+       xf86DrvMsg(scrn->scrnIndex, X_INFO,
+                  "Use GLAMOR acceleration.\n");
+       return TRUE;
+
+  fail:
+       xf86DrvMsg(scrn->scrnIndex, X_INFO,
+                  "Use standard UXA acceleration.\n");
+       return FALSE;
+}
+
+void
+intel_glamor_flush(intel_screen_private * intel)
+{
+       ScreenPtr screen;
+
+       screen = xf86ScrnToScreen(intel->scrn);
+       if (intel->uxa_flags & UXA_USE_GLAMOR)
+               glamor_block_handler(screen);
+}
+
+Bool
+intel_glamor_close_screen(ScreenPtr screen)
+{
+       ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+       intel_screen_private *intel = intel_get_screen_private(scrn);
+
+       if (intel->uxa_flags & UXA_USE_GLAMOR)
+               intel->uxa_flags &= ~UXA_USE_GLAMOR;
+
+       return TRUE;
+}
diff --git a/src/intel_glamor.h b/src/intel_glamor.h
new file mode 100644 (file)
index 0000000..46692bc
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * Copyright © 2011 Intel 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.
+ *
+ * Authors:
+ *    Zhigang Gong <zhigang.gong@linux.intel.com>
+ *
+ */
+
+#ifndef INTEL_GLAMOR_H
+#define INTEL_GLAMOR_H
+
+#ifdef USE_GLAMOR
+
+Bool intel_glamor_pre_init(ScrnInfoPtr scrn);
+Bool intel_glamor_init(ScreenPtr screen);
+Bool intel_glamor_create_screen_resources(ScreenPtr screen);
+Bool intel_glamor_close_screen(ScreenPtr screen);
+void intel_glamor_free_screen(int scrnIndex, int flags);
+
+void intel_glamor_flush(intel_screen_private * intel);
+
+Bool intel_glamor_create_textured_pixmap(PixmapPtr pixmap);
+void intel_glamor_destroy_pixmap(PixmapPtr pixmap);
+PixmapPtr intel_glamor_create_pixmap(ScreenPtr screen, int w, int h,
+                                    int depth, unsigned int usage);
+void intel_glamor_exchange_buffers(struct intel_screen_private *intel, PixmapPtr src, PixmapPtr dst);
+#else
+
+static inline Bool intel_glamor_pre_init(ScrnInfoPtr scrn) { return TRUE; }
+static inline Bool intel_glamor_init(ScreenPtr screen) { return TRUE; }
+static inline Bool intel_glamor_create_screen_resources(ScreenPtr screen) { return TRUE; }
+static inline Bool intel_glamor_close_screen(ScreenPtr screen) { return TRUE; }
+static inline void intel_glamor_free_screen(int scrnIndex, int flags) { }
+
+static inline void intel_glamor_flush(intel_screen_private * intel) { }
+
+static inline Bool intel_glamor_create_textured_pixmap(PixmapPtr pixmap) { return TRUE; }
+static inline void intel_glamor_destroy_pixmap(PixmapPtr pixmap) { }
+
+static inline PixmapPtr intel_glamor_create_pixmap(ScreenPtr screen, int w, int h,
+                                                  int depth, unsigned int usage) { return NULL; }
+
+static inline void intel_glamor_exchange_buffers(struct intel_screen_private *intel, PixmapPtr src, PixmapPtr dst) {}
+#endif
+
+#endif /* INTEL_GLAMOR_H */
index d626725..af8bd81 100644 (file)
@@ -189,7 +189,7 @@ static XF86MCSurfaceInfoPtr surface_info_vld[] = {
 /* check chip type and load xvmc driver */
 Bool intel_xvmc_adaptor_init(ScreenPtr pScreen)
 {
-       ScrnInfoPtr scrn = xf86Screens[pScreen->myNum];
+       ScrnInfoPtr scrn = xf86ScreenToScrn(pScreen);
        intel_screen_private *intel = intel_get_screen_private(scrn);
        static XF86MCAdaptorRec *pAdapt;
        char *name;
diff --git a/src/intel_list.h b/src/intel_list.h
new file mode 100644 (file)
index 0000000..cfaa1ad
--- /dev/null
@@ -0,0 +1,407 @@
+/*
+ * Copyright © 2010-2012 Intel Corporation
+ * Copyright © 2010 Francisco Jerez <currojerez@riseup.net>
+ *
+ * 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 _INTEL_LIST_H_
+#define _INTEL_LIST_H_
+
+#include <xorgVersion.h>
+
+#if XORG_VERSION_CURRENT < XORG_VERSION_NUMERIC(1,9,0,0,0) || XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1,11,99,903,0)
+
+#include <stdbool.h>
+
+/**
+ * @file Classic doubly-link circular list implementation.
+ * For real usage examples of the linked list, see the file test/list.c
+ *
+ * Example:
+ * We need to keep a list of struct foo in the parent struct bar, i.e. what
+ * we want is something like this.
+ *
+ *     struct bar {
+ *          ...
+ *          struct foo *list_of_foos; -----> struct foo {}, struct foo {}, struct foo{}
+ *          ...
+ *     }
+ *
+ * We need one list head in bar and a list element in all list_of_foos (both are of
+ * data type 'struct list').
+ *
+ *     struct bar {
+ *          ...
+ *          struct list list_of_foos;
+ *          ...
+ *     }
+ *
+ *     struct foo {
+ *          ...
+ *          struct list entry;
+ *          ...
+ *     }
+ *
+ * Now we initialize the list head:
+ *
+ *     struct bar bar;
+ *     ...
+ *     list_init(&bar.list_of_foos);
+ *
+ * Then we create the first element and add it to this list:
+ *
+ *     struct foo *foo = malloc(...);
+ *     ....
+ *     list_add(&foo->entry, &bar.list_of_foos);
+ *
+ * Repeat the above for each element you want to add to the list. Deleting
+ * works with the element itself.
+ *      list_del(&foo->entry);
+ *      free(foo);
+ *
+ * Note: calling list_del(&bar.list_of_foos) will set bar.list_of_foos to an empty
+ * list again.
+ *
+ * Looping through the list requires a 'struct foo' as iterator and the
+ * name of the field the subnodes use.
+ *
+ * struct foo *iterator;
+ * list_for_each_entry(iterator, &bar.list_of_foos, entry) {
+ *      if (iterator->something == ...)
+ *             ...
+ * }
+ *
+ * Note: You must not call list_del() on the iterator if you continue the
+ * loop. You need to run the safe for-each loop instead:
+ *
+ * struct foo *iterator, *next;
+ * list_for_each_entry_safe(iterator, next, &bar.list_of_foos, entry) {
+ *      if (...)
+ *              list_del(&iterator->entry);
+ * }
+ *
+ */
+
+/**
+ * The linkage struct for list nodes. This struct must be part of your
+ * to-be-linked struct. struct list is required for both the head of the
+ * list and for each list node.
+ *
+ * Position and name of the struct list field is irrelevant.
+ * There are no requirements that elements of a list are of the same type.
+ * There are no requirements for a list head, any struct list can be a list
+ * head.
+ */
+struct list {
+    struct list *next, *prev;
+};
+
+/**
+ * Initialize the list as an empty list.
+ *
+ * Example:
+ * list_init(&bar->list_of_foos);
+ *
+ * @param The list to initialized.
+ */
+static void
+list_init(struct list *list)
+{
+    list->next = list->prev = list;
+}
+
+static inline void
+__list_add(struct list *entry,
+           struct list *prev,
+           struct list *next)
+{
+    next->prev = entry;
+    entry->next = next;
+    entry->prev = prev;
+    prev->next = entry;
+}
+
+/**
+ * Insert a new element after the given list head. The new element does not
+ * need to be initialised as empty list.
+ * The list changes from:
+ *      head → some element → ...
+ * to
+ *      head → new element → older element → ...
+ *
+ * Example:
+ * struct foo *newfoo = malloc(...);
+ * list_add(&newfoo->entry, &bar->list_of_foos);
+ *
+ * @param entry The new element to prepend to the list.
+ * @param head The existing list.
+ */
+static inline void
+list_add(struct list *entry, struct list *head)
+{
+    __list_add(entry, head, head->next);
+}
+
+static inline void
+list_add_tail(struct list *entry, struct list *head)
+{
+    __list_add(entry, head->prev, head);
+}
+
+static inline void list_replace(struct list *old,
+                               struct list *new)
+{
+       new->next = old->next;
+       new->next->prev = new;
+       new->prev = old->prev;
+       new->prev->next = new;
+}
+
+#define list_last_entry(ptr, type, member) \
+    list_entry((ptr)->prev, type, member)
+
+#define list_for_each(pos, head)                               \
+    for (pos = (head)->next; pos != (head); pos = pos->next)
+
+/**
+ * Append a new element to the end of the list given with this list head.
+ *
+ * The list changes from:
+ *      head → some element → ... → lastelement
+ * to
+ *      head → some element → ... → lastelement → new element
+ *
+ * Example:
+ * struct foo *newfoo = malloc(...);
+ * list_append(&newfoo->entry, &bar->list_of_foos);
+ *
+ * @param entry The new element to prepend to the list.
+ * @param head The existing list.
+ */
+static inline void
+list_append(struct list *entry, struct list *head)
+{
+    __list_add(entry, head->prev, head);
+}
+
+
+static inline void
+__list_del(struct list *prev, struct list *next)
+{
+       assert(next->prev == prev->next);
+       next->prev = prev;
+       prev->next = next;
+}
+
+static inline void
+_list_del(struct list *entry)
+{
+    assert(entry->prev->next == entry);
+    assert(entry->next->prev == entry);
+    __list_del(entry->prev, entry->next);
+}
+
+/**
+ * Remove the element from the list it is in. Using this function will reset
+ * the pointers to/from this element so it is removed from the list. It does
+ * NOT free the element itself or manipulate it otherwise.
+ *
+ * Using list_del on a pure list head (like in the example at the top of
+ * this file) will NOT remove the first element from
+ * the list but rather reset the list as empty list.
+ *
+ * Example:
+ * list_del(&foo->entry);
+ *
+ * @param entry The element to remove.
+ */
+static inline void
+list_del(struct list *entry)
+{
+    _list_del(entry);
+    list_init(entry);
+}
+
+static inline void list_move(struct list *list, struct list *head)
+{
+       if (list->prev != head) {
+               _list_del(list);
+               list_add(list, head);
+       }
+}
+
+static inline void list_move_tail(struct list *list, struct list *head)
+{
+       _list_del(list);
+       list_add_tail(list, head);
+}
+
+/**
+ * Check if the list is empty.
+ *
+ * Example:
+ * list_is_empty(&bar->list_of_foos);
+ *
+ * @return True if the list contains one or more elements or False otherwise.
+ */
+static inline bool
+list_is_empty(struct list *head)
+{
+    return head->next == head;
+}
+
+/**
+ * Alias of container_of
+ */
+#define list_entry(ptr, type, member) \
+    container_of(ptr, type, member)
+
+/**
+ * Retrieve the first list entry for the given list pointer.
+ *
+ * Example:
+ * struct foo *first;
+ * first = list_first_entry(&bar->list_of_foos, struct foo, list_of_foos);
+ *
+ * @param ptr The list head
+ * @param type Data type of the list element to retrieve
+ * @param member Member name of the struct list field in the list element.
+ * @return A pointer to the first list element.
+ */
+#define list_first_entry(ptr, type, member) \
+    list_entry((ptr)->next, type, member)
+
+/**
+ * Retrieve the last list entry for the given listpointer.
+ *
+ * Example:
+ * struct foo *first;
+ * first = list_last_entry(&bar->list_of_foos, struct foo, list_of_foos);
+ *
+ * @param ptr The list head
+ * @param type Data type of the list element to retrieve
+ * @param member Member name of the struct list field in the list element.
+ * @return A pointer to the last list element.
+ */
+#define list_last_entry(ptr, type, member) \
+    list_entry((ptr)->prev, type, member)
+
+#define __container_of(ptr, sample, member)                            \
+    (void *)((char *)(ptr)                                             \
+            - ((char *)&(sample)->member - (char *)(sample)))
+/**
+ * Loop through the list given by head and set pos to struct in the list.
+ *
+ * Example:
+ * struct foo *iterator;
+ * list_for_each_entry(iterator, &bar->list_of_foos, entry) {
+ *      [modify iterator]
+ * }
+ *
+ * This macro is not safe for node deletion. Use list_for_each_entry_safe
+ * instead.
+ *
+ * @param pos Iterator variable of the type of the list elements.
+ * @param head List head
+ * @param member Member name of the struct list in the list elements.
+ *
+ */
+#define list_for_each_entry(pos, head, member)                         \
+    for (pos = __container_of((head)->next, pos, member);              \
+        &pos->member != (head);                                        \
+        pos = __container_of(pos->member.next, pos, member))
+
+#define list_for_each_entry_reverse(pos, head, member)                         \
+    for (pos = __container_of((head)->prev, pos, member);              \
+        &pos->member != (head);                                        \
+        pos = __container_of(pos->member.prev, pos, member))
+
+/**
+ * Loop through the list, keeping a backup pointer to the element. This
+ * macro allows for the deletion of a list element while looping through the
+ * list.
+ *
+ * See list_for_each_entry for more details.
+ */
+#define list_for_each_entry_safe(pos, tmp, head, member)               \
+    for (pos = __container_of((head)->next, pos, member),              \
+        tmp = __container_of(pos->member.next, pos, member);           \
+        &pos->member != (head);                                        \
+        pos = tmp, tmp = __container_of(pos->member.next, tmp, member))
+
+#else
+
+#include <list.h>
+
+static inline void
+list_add_tail(struct list *entry, struct list *head)
+{
+    __list_add(entry, head->prev, head);
+}
+
+static inline void
+_list_del(struct list *entry)
+{
+    assert(entry->prev->next == entry);
+    assert(entry->next->prev == entry);
+    __list_del(entry->prev, entry->next);
+}
+
+static inline void list_replace(struct list *old,
+                               struct list *new)
+{
+       new->next = old->next;
+       new->next->prev = new;
+       new->prev = old->prev;
+       new->prev->next = new;
+}
+
+static inline void list_move(struct list *list, struct list *head)
+{
+       if (list->prev != head) {
+               _list_del(list);
+               list_add(list, head);
+       }
+}
+
+static inline void list_move_tail(struct list *list, struct list *head)
+{
+       _list_del(list);
+       list_add_tail(list, head);
+}
+
+#define list_last_entry(ptr, type, member) \
+    list_entry((ptr)->prev, type, member)
+
+#define list_for_each_entry_reverse(pos, head, member)                         \
+    for (pos = __container_of((head)->prev, pos, member);              \
+        &pos->member != (head);                                        \
+        pos = __container_of(pos->member.prev, pos, member))
+
+#endif
+
+#undef container_of
+#define container_of(ptr, type, member) \
+       ((type *)((char *)(ptr) - (char *) &((type *)0)->member))
+
+#endif /* _INTEL_LIST_H_ */
+
index 763a6ad..f08ebdd 100644 (file)
@@ -96,7 +96,7 @@ unsigned long intel_get_fence_size(intel_screen_private *intel, unsigned long si
 
        if (INTEL_INFO(intel)->gen >= 40 || intel->has_relaxed_fencing) {
                /* The 965 can have fences at any page boundary. */
-               return ALIGN(size, GTT_PAGE_SIZE);
+               return ALIGN(size, 4096);
        } else {
                /* Align the size to a power of two greater than the smallest fence
                 * size.
@@ -169,6 +169,39 @@ static inline int intel_pad_drawable_width(int width)
        return ALIGN(width, 64);
 }
 
+
+static size_t
+agp_aperture_size(struct pci_device *dev, int gen)
+{
+       return dev->regions[gen < 30 ? 0 : 2].size;
+}
+
+static void intel_set_gem_max_sizes(ScrnInfoPtr scrn)
+{
+       intel_screen_private *intel = intel_get_screen_private(scrn);
+       size_t agp_size = agp_aperture_size(intel->PciInfo,
+                                           INTEL_INFO(intel)->gen);
+
+       /* The chances of being able to mmap an object larger than
+        * agp_size/2 are slim. Moreover, we may be forced to fallback
+        * using a gtt mapping as both the source and a mask, as well
+        * as a destination and all need to fit into the aperture.
+        */
+       intel->max_gtt_map_size = agp_size / 4;
+
+       /* Let objects be tiled up to the size where only 4 would fit in
+        * the aperture, presuming best case alignment. Also if we
+        * cannot mmap it using the GTT we will be stuck. */
+       intel->max_tiling_size = intel->max_gtt_map_size;
+
+       /* Large BOs will tend to hit SW fallbacks frequently, and also will
+        * tend to fail to successfully map when doing SW fallbacks because we
+        * overcommit address space for BO access, or worse cause aperture
+        * thrashing.
+        */
+       intel->max_bo_size = intel->max_gtt_map_size;
+}
+
 /**
  * Allocates a framebuffer for a screen.
  *
@@ -231,10 +264,12 @@ retry:
                return NULL;
        }
 
-       if ((intel->tiling & INTEL_TILING_FB) && tiling_mode != I915_TILING_X) {
+       /* If we could have used tiling but failed, warn */
+       if (intel->tiling & INTEL_TILING_FB &&
+           tiling_mode != I915_TILING_X &&
+           intel_check_display_stride(scrn, pitch, I915_TILING_X))
                xf86DrvMsg(scrn->scrnIndex, X_WARNING,
                           "Failed to set tiling on frontbuffer.\n");
-       }
 
        xf86DrvMsg(scrn->scrnIndex, X_INFO,
                   "Allocated new frame buffer %dx%d stride %ld, %s\n",
@@ -249,56 +284,3 @@ retry:
 
        return front_buffer;
 }
-
-static void intel_set_max_bo_size(intel_screen_private *intel,
-                                const struct drm_i915_gem_get_aperture *aperture)
-{
-       if (aperture->aper_available_size)
-               /* Large BOs will tend to hit SW fallbacks frequently, and also will
-                * tend to fail to successfully map when doing SW fallbacks because we
-                * overcommit address space for BO access, or worse cause aperture
-                * thrashing.
-                */
-               intel->max_bo_size = aperture->aper_available_size / 2;
-       else
-               intel->max_bo_size = 64 * 1024 * 1024;
-}
-
-static void intel_set_max_gtt_map_size(intel_screen_private *intel,
-                                     const struct drm_i915_gem_get_aperture *aperture)
-{
-       if (aperture->aper_available_size)
-               /* Let objects up get bound up to the size where only 2 would fit in
-                * the aperture, but then leave slop to account for alignment like
-                * libdrm does.
-                */
-               intel->max_gtt_map_size =
-                       aperture->aper_available_size * 3 / 4 / 2;
-       else
-               intel->max_gtt_map_size = 16 * 1024 * 1024;
-}
-
-static void intel_set_max_tiling_size(intel_screen_private *intel,
-                                    const struct drm_i915_gem_get_aperture *aperture)
-{
-       if (aperture->aper_available_size)
-               /* Let objects be tiled up to the size where only 4 would fit in
-                * the aperture, presuming worst case alignment.
-                */
-               intel->max_tiling_size = aperture->aper_available_size / 4;
-       else
-               intel->max_tiling_size = 4 * 1024 * 1024;
-}
-
-void intel_set_gem_max_sizes(ScrnInfoPtr scrn)
-{
-       intel_screen_private *intel = intel_get_screen_private(scrn);
-       struct drm_i915_gem_get_aperture aperture;
-
-       aperture.aper_available_size = 0;
-       drmIoctl(intel->drmSubFD, DRM_IOCTL_I915_GEM_GET_APERTURE, &aperture);
-
-       intel_set_max_bo_size(intel, &aperture);
-       intel_set_max_gtt_map_size(intel, &aperture);
-       intel_set_max_tiling_size(intel, &aperture);
-}
index 8416544..e6ca964 100644 (file)
 #include "config.h"
 #endif
 
-#include "xf86.h"
-#include "xf86_OSproc.h"
-#include "xf86cmap.h"
+#include <unistd.h>
+#include <xf86_OSproc.h>
+#include <xf86Parser.h>
+#include <xf86drm.h>
+#include <xf86drmMode.h>
+#include <i915_drm.h>
+
+#include <xorgVersion.h>
+
+#if XORG_VERSION_CURRENT < XORG_VERSION_NUMERIC(1,6,99,0,0)
+#include <xf86Resources.h>
+#endif
 
 #include "common.h"
-#include "intel.h"
 #include "intel_driver.h"
+#include "intel_options.h"
 #include "legacy/legacy.h"
+#include "sna/sna_module.h"
 
-#include <xf86drmMode.h>
+#ifdef XSERVER_PLATFORM_BUS
+#include <xf86platformBus.h>
+#endif
+
+static const struct intel_device_info intel_generic_info = {
+       .gen = -1,
+};
 
 static const struct intel_device_info intel_i81x_info = {
        .gen = 10,
 };
 
-static const struct intel_device_info intel_i8xx_info = {
+static const struct intel_device_info intel_i830_info = {
+       .gen = 20,
+};
+static const struct intel_device_info intel_i845_info = {
        .gen = 20,
 };
+static const struct intel_device_info intel_i855_info = {
+       .gen = 21,
+};
+static const struct intel_device_info intel_i865_info = {
+       .gen = 22,
+};
 
 static const struct intel_device_info intel_i915_info = {
        .gen = 30,
 };
+static const struct intel_device_info intel_i945_info = {
+       .gen = 31,
+};
 
 static const struct intel_device_info intel_g33_info = {
        .gen = 33,
@@ -71,329 +99,254 @@ static const struct intel_device_info intel_sandybridge_info = {
        .gen = 60,
 };
 
+static const struct intel_device_info intel_ivybridge_info = {
+       .gen = 70,
+};
+
+static const struct intel_device_info intel_valleyview_info = {
+       .gen = 70,
+};
+
+static const struct intel_device_info intel_haswell_info = {
+       .gen = 75,
+};
+
 static const SymTabRec _intel_chipsets[] = {
-    {PCI_CHIP_I810,            "i810"},
-    {PCI_CHIP_I810_DC100,      "i810-dc100"},
-    {PCI_CHIP_I810_E,          "i810e"},
-    {PCI_CHIP_I815,            "i815"},
-    {PCI_CHIP_I830_M,          "i830M"},
-    {PCI_CHIP_845_G,           "845G"},
-    {PCI_CHIP_I854,            "854"},
-    {PCI_CHIP_I855_GM,         "852GM/855GM"},
-    {PCI_CHIP_I865_G,          "865G"},
-    {PCI_CHIP_I915_G,          "915G"},
-    {PCI_CHIP_E7221_G,         "E7221 (i915)"},
-    {PCI_CHIP_I915_GM,         "915GM"},
-    {PCI_CHIP_I945_G,          "945G"},
-    {PCI_CHIP_I945_GM,         "945GM"},
-    {PCI_CHIP_I945_GME,                "945GME"},
-    {PCI_CHIP_PINEVIEW_M,      "Pineview GM"},
-    {PCI_CHIP_PINEVIEW_G,      "Pineview G"},
-    {PCI_CHIP_I965_G,          "965G"},
-    {PCI_CHIP_G35_G,           "G35"},
-    {PCI_CHIP_I965_Q,          "965Q"},
-    {PCI_CHIP_I946_GZ,         "946GZ"},
-    {PCI_CHIP_I965_GM,         "965GM"},
-    {PCI_CHIP_I965_GME,                "965GME/GLE"},
-    {PCI_CHIP_G33_G,           "G33"},
-    {PCI_CHIP_Q35_G,           "Q35"},
-    {PCI_CHIP_Q33_G,           "Q33"},
-    {PCI_CHIP_GM45_GM,         "GM45"},
-    {PCI_CHIP_G45_E_G,         "4 Series"},
-    {PCI_CHIP_G45_G,           "G45/G43"},
-    {PCI_CHIP_Q45_G,           "Q45/Q43"},
-    {PCI_CHIP_G41_G,           "G41"},
-    {PCI_CHIP_B43_G,           "B43"},
-    {PCI_CHIP_B43_G1,          "B43"},
-    {PCI_CHIP_IRONLAKE_D_G,            "Clarkdale"},
-    {PCI_CHIP_IRONLAKE_M_G,            "Arrandale"},
-    {PCI_CHIP_SANDYBRIDGE_GT1, "Sandybridge" },
-    {PCI_CHIP_SANDYBRIDGE_GT2, "Sandybridge" },
-    {PCI_CHIP_SANDYBRIDGE_GT2_PLUS,    "Sandybridge" },
-    {PCI_CHIP_SANDYBRIDGE_M_GT1,       "Sandybridge" },
-    {PCI_CHIP_SANDYBRIDGE_M_GT2,       "Sandybridge" },
-    {PCI_CHIP_SANDYBRIDGE_M_GT2_PLUS,  "Sandybridge" },
-    {PCI_CHIP_SANDYBRIDGE_S_GT,        "Sandybridge" },
-    {-1,                               NULL}
+       {PCI_CHIP_I810,                         "i810"},
+       {PCI_CHIP_I810_DC100,                   "i810-dc100"},
+       {PCI_CHIP_I810_E,                       "i810e"},
+       {PCI_CHIP_I815,                         "i815"},
+       {PCI_CHIP_I830_M,                       "i830M"},
+       {PCI_CHIP_845_G,                        "845G"},
+       {PCI_CHIP_I854,                         "854"},
+       {PCI_CHIP_I855_GM,                      "852GM/855GM"},
+       {PCI_CHIP_I865_G,                       "865G"},
+       {PCI_CHIP_I915_G,                       "915G"},
+       {PCI_CHIP_E7221_G,                      "E7221 (i915)"},
+       {PCI_CHIP_I915_GM,                      "915GM"},
+       {PCI_CHIP_I945_G,                       "945G"},
+       {PCI_CHIP_I945_GM,                      "945GM"},
+       {PCI_CHIP_I945_GME,                     "945GME"},
+       {PCI_CHIP_PINEVIEW_M,                   "Pineview GM"},
+       {PCI_CHIP_PINEVIEW_G,                   "Pineview G"},
+       {PCI_CHIP_I965_G,                       "965G"},
+       {PCI_CHIP_G35_G,                        "G35"},
+       {PCI_CHIP_I965_Q,                       "965Q"},
+       {PCI_CHIP_I946_GZ,                      "946GZ"},
+       {PCI_CHIP_I965_GM,                      "965GM"},
+       {PCI_CHIP_I965_GME,                     "965GME/GLE"},
+       {PCI_CHIP_G33_G,                        "G33"},
+       {PCI_CHIP_Q35_G,                        "Q35"},
+       {PCI_CHIP_Q33_G,                        "Q33"},
+       {PCI_CHIP_GM45_GM,                      "GM45"},
+       {PCI_CHIP_G45_E_G,                      "4 Series"},
+       {PCI_CHIP_G45_G,                        "G45/G43"},
+       {PCI_CHIP_Q45_G,                        "Q45/Q43"},
+       {PCI_CHIP_G41_G,                        "G41"},
+       {PCI_CHIP_B43_G,                        "B43"},
+       {PCI_CHIP_B43_G1,                       "B43"},
+       {PCI_CHIP_IRONLAKE_D_G,                 "Clarkdale"},
+       {PCI_CHIP_IRONLAKE_M_G,                 "Arrandale"},
+       {PCI_CHIP_SANDYBRIDGE_GT1,              "Sandybridge Desktop (GT1)" },
+       {PCI_CHIP_SANDYBRIDGE_GT2,              "Sandybridge Desktop (GT2)" },
+       {PCI_CHIP_SANDYBRIDGE_GT2_PLUS,         "Sandybridge Desktop (GT2+)" },
+       {PCI_CHIP_SANDYBRIDGE_M_GT1,            "Sandybridge Mobile (GT1)" },
+       {PCI_CHIP_SANDYBRIDGE_M_GT2,            "Sandybridge Mobile (GT2)" },
+       {PCI_CHIP_SANDYBRIDGE_M_GT2_PLUS,       "Sandybridge Mobile (GT2+)" },
+       {PCI_CHIP_SANDYBRIDGE_S_GT,             "Sandybridge Server" },
+       {PCI_CHIP_IVYBRIDGE_M_GT1,              "Ivybridge Mobile (GT1)" },
+       {PCI_CHIP_IVYBRIDGE_M_GT2,              "Ivybridge Mobile (GT2)" },
+       {PCI_CHIP_IVYBRIDGE_D_GT1,              "Ivybridge Desktop (GT1)" },
+       {PCI_CHIP_IVYBRIDGE_D_GT2,              "Ivybridge Desktop (GT2)" },
+       {PCI_CHIP_IVYBRIDGE_S_GT1,              "Ivybridge Server" },
+       {PCI_CHIP_IVYBRIDGE_S_GT2,              "Ivybridge Server (GT2)" },
+       {PCI_CHIP_HASWELL_D_GT1,                "Haswell Desktop (GT1)" },
+       {PCI_CHIP_HASWELL_D_GT2,                "Haswell Desktop (GT2)" },
+       {PCI_CHIP_HASWELL_D_GT2_PLUS,           "Haswell Desktop (GT2+)" },
+       {PCI_CHIP_HASWELL_M_GT1,                "Haswell Mobile (GT1)" },
+       {PCI_CHIP_HASWELL_M_GT2,                "Haswell Mobile (GT2)" },
+       {PCI_CHIP_HASWELL_M_GT2_PLUS,           "Haswell Mobile (GT2+)" },
+       {PCI_CHIP_HASWELL_S_GT1,                "Haswell Server (GT1)" },
+       {PCI_CHIP_HASWELL_S_GT2,                "Haswell Server (GT2)" },
+       {PCI_CHIP_HASWELL_S_GT2_PLUS,           "Haswell Server (GT2+)" },
+       {PCI_CHIP_HASWELL_SDV_D_GT1,            "Haswell SDV Desktop (GT1)" },
+       {PCI_CHIP_HASWELL_SDV_D_GT2,            "Haswell SDV Desktop (GT2)" },
+       {PCI_CHIP_HASWELL_SDV_D_GT2_PLUS,       "Haswell SDV Desktop (GT2+)" },
+       {PCI_CHIP_HASWELL_SDV_M_GT1,            "Haswell SDV Mobile (GT1)" },
+       {PCI_CHIP_HASWELL_SDV_M_GT2,            "Haswell SDV Mobile (GT2)" },
+       {PCI_CHIP_HASWELL_SDV_M_GT2_PLUS,       "Haswell SDV Mobile (GT2+)" },
+       {PCI_CHIP_HASWELL_SDV_S_GT1,            "Haswell SDV Server (GT1)" },
+       {PCI_CHIP_HASWELL_SDV_S_GT2,            "Haswell SDV Server (GT2)" },
+       {PCI_CHIP_HASWELL_SDV_S_GT2_PLUS,       "Haswell SDV Server (GT2+)" },
+       {PCI_CHIP_HASWELL_ULT_D_GT1,            "Haswell ULT Desktop (GT1)" },
+       {PCI_CHIP_HASWELL_ULT_D_GT2,            "Haswell ULT Desktop (GT2)" },
+       {PCI_CHIP_HASWELL_ULT_D_GT2_PLUS,       "Haswell ULT Desktop (GT2+)" },
+       {PCI_CHIP_HASWELL_ULT_M_GT1,            "Haswell ULT Mobile (GT1)" },
+       {PCI_CHIP_HASWELL_ULT_M_GT2,            "Haswell ULT Mobile (GT2)" },
+       {PCI_CHIP_HASWELL_ULT_M_GT2_PLUS,       "Haswell ULT Mobile (GT2+)" },
+       {PCI_CHIP_HASWELL_ULT_S_GT1,            "Haswell ULT Server (GT1)" },
+       {PCI_CHIP_HASWELL_ULT_S_GT2,            "Haswell ULT Server (GT2)" },
+       {PCI_CHIP_HASWELL_ULT_S_GT2_PLUS,       "Haswell ULT Server (GT2+)" },
+       {PCI_CHIP_HASWELL_CRW_D_GT1,            "Haswell CRW Desktop (GT1)" },
+       {PCI_CHIP_HASWELL_CRW_D_GT2,            "Haswell CRW Desktop (GT2)" },
+       {PCI_CHIP_HASWELL_CRW_D_GT2_PLUS,       "Haswell CRW Desktop (GT2+)" },
+       {PCI_CHIP_HASWELL_CRW_M_GT1,            "Haswell CRW Mobile (GT1)" },
+       {PCI_CHIP_HASWELL_CRW_M_GT2,            "Haswell CRW Mobile (GT2)" },
+       {PCI_CHIP_HASWELL_CRW_M_GT2_PLUS,       "Haswell CRW Mobile (GT2+)" },
+       {PCI_CHIP_HASWELL_CRW_S_GT1,            "Haswell CRW Server (GT1)" },
+       {PCI_CHIP_HASWELL_CRW_S_GT2,            "Haswell CRW Server (GT2)" },
+       {PCI_CHIP_HASWELL_CRW_S_GT2_PLUS,       "Haswell CRW Server (GT2+)" },
+       {PCI_CHIP_VALLEYVIEW_PO,                "ValleyView PO board" },
+       {-1,                                    NULL}
 };
-SymTabRec *intel_chipsets = (SymTabRec *) _intel_chipsets;
+#define NUM_CHIPSETS (sizeof(_intel_chipsets) / sizeof(_intel_chipsets[0]))
+
+static SymTabRec *intel_chipsets = (SymTabRec *) _intel_chipsets;
 
 #define INTEL_DEVICE_MATCH(d,i) \
-{ 0x8086, (d), PCI_MATCH_ANY, PCI_MATCH_ANY, 0, 0, (i) }
+    { 0x8086, (d), PCI_MATCH_ANY, PCI_MATCH_ANY, 0x3 << 16, 0xff << 16, (intptr_t)(i) }
 
 static const struct pci_id_match intel_device_match[] = {
-    INTEL_DEVICE_MATCH (PCI_CHIP_I810, 0 ),
-    INTEL_DEVICE_MATCH (PCI_CHIP_I810_DC100, 0 ),
-    INTEL_DEVICE_MATCH (PCI_CHIP_I810_E, 0 ),
-    INTEL_DEVICE_MATCH (PCI_CHIP_I815, 0 ),
-    INTEL_DEVICE_MATCH (PCI_CHIP_I830_M, 0 ),
-    INTEL_DEVICE_MATCH (PCI_CHIP_845_G, 0 ),
-    INTEL_DEVICE_MATCH (PCI_CHIP_I854, 0 ),
-    INTEL_DEVICE_MATCH (PCI_CHIP_I855_GM, 0 ),
-    INTEL_DEVICE_MATCH (PCI_CHIP_I865_G, 0 ),
-    INTEL_DEVICE_MATCH (PCI_CHIP_I915_G, 0 ),
-    INTEL_DEVICE_MATCH (PCI_CHIP_E7221_G, 0 ),
-    INTEL_DEVICE_MATCH (PCI_CHIP_I915_GM, 0 ),
-    INTEL_DEVICE_MATCH (PCI_CHIP_I945_G, 0 ),
-    INTEL_DEVICE_MATCH (PCI_CHIP_I945_GM, 0 ),
-    INTEL_DEVICE_MATCH (PCI_CHIP_I945_GME, 0 ),
-    INTEL_DEVICE_MATCH (PCI_CHIP_PINEVIEW_M, 0 ),
-    INTEL_DEVICE_MATCH (PCI_CHIP_PINEVIEW_G, 0 ),
-    INTEL_DEVICE_MATCH (PCI_CHIP_I965_G, 0 ),
-    INTEL_DEVICE_MATCH (PCI_CHIP_G35_G, 0 ),
-    INTEL_DEVICE_MATCH (PCI_CHIP_I965_Q, 0 ),
-    INTEL_DEVICE_MATCH (PCI_CHIP_I946_GZ, 0 ),
-    INTEL_DEVICE_MATCH (PCI_CHIP_I965_GM, 0 ),
-    INTEL_DEVICE_MATCH (PCI_CHIP_I965_GME, 0 ),
-    INTEL_DEVICE_MATCH (PCI_CHIP_G33_G, 0 ),
-    INTEL_DEVICE_MATCH (PCI_CHIP_Q35_G, 0 ),
-    INTEL_DEVICE_MATCH (PCI_CHIP_Q33_G, 0 ),
-    INTEL_DEVICE_MATCH (PCI_CHIP_GM45_GM, 0 ),
-    INTEL_DEVICE_MATCH (PCI_CHIP_G45_E_G, 0 ),
-    INTEL_DEVICE_MATCH (PCI_CHIP_G45_G, 0 ),
-    INTEL_DEVICE_MATCH (PCI_CHIP_Q45_G, 0 ),
-    INTEL_DEVICE_MATCH (PCI_CHIP_G41_G, 0 ),
-    INTEL_DEVICE_MATCH (PCI_CHIP_B43_G, 0 ),
-    INTEL_DEVICE_MATCH (PCI_CHIP_IRONLAKE_D_G, 0 ),
-    INTEL_DEVICE_MATCH (PCI_CHIP_IRONLAKE_M_G, 0 ),
-    INTEL_DEVICE_MATCH (PCI_CHIP_SANDYBRIDGE_GT1, 0 ),
-    INTEL_DEVICE_MATCH (PCI_CHIP_SANDYBRIDGE_GT2, 0 ),
-    INTEL_DEVICE_MATCH (PCI_CHIP_SANDYBRIDGE_GT2_PLUS, 0 ),
-    INTEL_DEVICE_MATCH (PCI_CHIP_SANDYBRIDGE_M_GT1, 0 ),
-    INTEL_DEVICE_MATCH (PCI_CHIP_SANDYBRIDGE_M_GT2, 0 ),
-    INTEL_DEVICE_MATCH (PCI_CHIP_SANDYBRIDGE_M_GT2_PLUS, 0 ),
-    INTEL_DEVICE_MATCH (PCI_CHIP_SANDYBRIDGE_S_GT, 0 ),
-    { 0, 0, 0 },
-};
+#if !KMS_ONLY
+       INTEL_DEVICE_MATCH (PCI_CHIP_I810, &intel_i81x_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_I810_DC100, &intel_i81x_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_I810_E, &intel_i81x_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_I815, &intel_i81x_info ),
+#endif
+
+#if !UMS_ONLY
+       INTEL_DEVICE_MATCH (PCI_CHIP_I830_M, &intel_i830_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_845_G, &intel_i845_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_I854, &intel_i855_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_I855_GM, &intel_i855_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_I865_G, &intel_i865_info ),
+
+       INTEL_DEVICE_MATCH (PCI_CHIP_I915_G, &intel_i915_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_E7221_G, &intel_i915_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_I915_GM, &intel_i915_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_I945_G, &intel_i945_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_I945_GM, &intel_i945_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_I945_GME, &intel_i945_info ),
+
+       INTEL_DEVICE_MATCH (PCI_CHIP_PINEVIEW_M, &intel_g33_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_PINEVIEW_G, &intel_g33_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_G33_G, &intel_g33_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_Q33_G, &intel_g33_info ),
+       /* Another marketing win: Q35 is another g33 device not a gen4 part
+        * like its G35 brethren.
+        */
+       INTEL_DEVICE_MATCH (PCI_CHIP_Q35_G, &intel_g33_info ),
+
+       INTEL_DEVICE_MATCH (PCI_CHIP_I965_G, &intel_i965_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_G35_G, &intel_i965_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_I965_Q, &intel_i965_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_I946_GZ, &intel_i965_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_I965_GM, &intel_i965_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_I965_GME, &intel_i965_info ),
+
+       INTEL_DEVICE_MATCH (PCI_CHIP_GM45_GM, &intel_g4x_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_G45_E_G, &intel_g4x_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_G45_G, &intel_g4x_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_Q45_G, &intel_g4x_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_G41_G, &intel_g4x_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_B43_G, &intel_g4x_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_B43_G1, &intel_g4x_info ),
+
+       INTEL_DEVICE_MATCH (PCI_CHIP_IRONLAKE_D_G, &intel_ironlake_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_IRONLAKE_M_G, &intel_ironlake_info ),
+
+       INTEL_DEVICE_MATCH (PCI_CHIP_SANDYBRIDGE_GT1, &intel_sandybridge_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_SANDYBRIDGE_GT2, &intel_sandybridge_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_SANDYBRIDGE_GT2_PLUS, &intel_sandybridge_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_SANDYBRIDGE_M_GT1, &intel_sandybridge_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_SANDYBRIDGE_M_GT2, &intel_sandybridge_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_SANDYBRIDGE_M_GT2_PLUS, &intel_sandybridge_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_SANDYBRIDGE_S_GT, &intel_sandybridge_info ),
+
+       INTEL_DEVICE_MATCH (PCI_CHIP_IVYBRIDGE_M_GT1, &intel_ivybridge_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_IVYBRIDGE_M_GT2, &intel_ivybridge_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_IVYBRIDGE_D_GT1, &intel_ivybridge_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_IVYBRIDGE_D_GT2, &intel_ivybridge_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_IVYBRIDGE_S_GT1, &intel_ivybridge_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_IVYBRIDGE_S_GT2, &intel_ivybridge_info ),
+
+       INTEL_DEVICE_MATCH (PCI_CHIP_HASWELL_D_GT1, &intel_haswell_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_HASWELL_D_GT2, &intel_haswell_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_HASWELL_D_GT2_PLUS, &intel_haswell_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_HASWELL_M_GT1, &intel_haswell_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_HASWELL_M_GT2, &intel_haswell_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_HASWELL_M_GT2_PLUS, &intel_haswell_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_HASWELL_S_GT1, &intel_haswell_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_HASWELL_S_GT2, &intel_haswell_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_HASWELL_S_GT2_PLUS, &intel_haswell_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_HASWELL_SDV_D_GT1, &intel_haswell_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_HASWELL_SDV_D_GT2, &intel_haswell_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_HASWELL_SDV_D_GT2_PLUS, &intel_haswell_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_HASWELL_SDV_M_GT1, &intel_haswell_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_HASWELL_SDV_M_GT2, &intel_haswell_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_HASWELL_SDV_M_GT2_PLUS, &intel_haswell_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_HASWELL_SDV_S_GT1, &intel_haswell_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_HASWELL_SDV_S_GT2, &intel_haswell_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_HASWELL_SDV_S_GT2_PLUS, &intel_haswell_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_HASWELL_ULT_D_GT1, &intel_haswell_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_HASWELL_ULT_D_GT2, &intel_haswell_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_HASWELL_ULT_D_GT2_PLUS, &intel_haswell_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_HASWELL_ULT_M_GT1, &intel_haswell_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_HASWELL_ULT_M_GT2, &intel_haswell_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_HASWELL_ULT_M_GT2_PLUS, &intel_haswell_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_HASWELL_ULT_S_GT1, &intel_haswell_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_HASWELL_ULT_S_GT2, &intel_haswell_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_HASWELL_ULT_S_GT2_PLUS, &intel_haswell_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_HASWELL_CRW_D_GT1, &intel_haswell_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_HASWELL_CRW_D_GT2, &intel_haswell_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_HASWELL_CRW_D_GT2_PLUS, &intel_haswell_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_HASWELL_CRW_M_GT1, &intel_haswell_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_HASWELL_CRW_M_GT2, &intel_haswell_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_HASWELL_CRW_M_GT2_PLUS, &intel_haswell_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_HASWELL_CRW_S_GT1, &intel_haswell_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_HASWELL_CRW_S_GT2, &intel_haswell_info ),
+       INTEL_DEVICE_MATCH (PCI_CHIP_HASWELL_CRW_S_GT2_PLUS, &intel_haswell_info ),
+
+       INTEL_DEVICE_MATCH (PCI_CHIP_VALLEYVIEW_PO, &intel_valleyview_info ),
+
+       INTEL_DEVICE_MATCH (PCI_MATCH_ANY, &intel_generic_info ),
+#endif
 
-static PciChipsets intel_pci_chipsets[] = {
-    {PCI_CHIP_I810,            PCI_CHIP_I810,          NULL},
-    {PCI_CHIP_I810_DC100,      PCI_CHIP_I810_DC100,    NULL},
-    {PCI_CHIP_I810_E,          PCI_CHIP_I810_E,        NULL},
-    {PCI_CHIP_I815,            PCI_CHIP_I815,          NULL},
-    {PCI_CHIP_I830_M,          PCI_CHIP_I830_M,        NULL},
-    {PCI_CHIP_845_G,           PCI_CHIP_845_G,         NULL},
-    {PCI_CHIP_I854,            PCI_CHIP_I854,          NULL},
-    {PCI_CHIP_I855_GM,         PCI_CHIP_I855_GM,       NULL},
-    {PCI_CHIP_I865_G,          PCI_CHIP_I865_G,        NULL},
-    {PCI_CHIP_I915_G,          PCI_CHIP_I915_G,        NULL},
-    {PCI_CHIP_E7221_G,         PCI_CHIP_E7221_G,       NULL},
-    {PCI_CHIP_I915_GM,         PCI_CHIP_I915_GM,       NULL},
-    {PCI_CHIP_I945_G,          PCI_CHIP_I945_G,        NULL},
-    {PCI_CHIP_I945_GM,         PCI_CHIP_I945_GM,       NULL},
-    {PCI_CHIP_I945_GME,                PCI_CHIP_I945_GME,      NULL},
-    {PCI_CHIP_PINEVIEW_M,      PCI_CHIP_PINEVIEW_M,    NULL},
-    {PCI_CHIP_PINEVIEW_G,      PCI_CHIP_PINEVIEW_G,            NULL},
-    {PCI_CHIP_I965_G,          PCI_CHIP_I965_G,        NULL},
-    {PCI_CHIP_G35_G,           PCI_CHIP_G35_G,         NULL},
-    {PCI_CHIP_I965_Q,          PCI_CHIP_I965_Q,        NULL},
-    {PCI_CHIP_I946_GZ,         PCI_CHIP_I946_GZ,       NULL},
-    {PCI_CHIP_I965_GM,         PCI_CHIP_I965_GM,       NULL},
-    {PCI_CHIP_I965_GME,                PCI_CHIP_I965_GME,      NULL},
-    {PCI_CHIP_G33_G,           PCI_CHIP_G33_G,         NULL},
-    {PCI_CHIP_Q35_G,           PCI_CHIP_Q35_G,         NULL},
-    {PCI_CHIP_Q33_G,           PCI_CHIP_Q33_G,         NULL},
-    {PCI_CHIP_GM45_GM,         PCI_CHIP_GM45_GM,       NULL},
-    {PCI_CHIP_G45_E_G,         PCI_CHIP_G45_E_G,       NULL},
-    {PCI_CHIP_G45_G,           PCI_CHIP_G45_G,         NULL},
-    {PCI_CHIP_Q45_G,           PCI_CHIP_Q45_G,         NULL},
-    {PCI_CHIP_G41_G,           PCI_CHIP_G41_G,         NULL},
-    {PCI_CHIP_B43_G,           PCI_CHIP_B43_G,         NULL},
-    {PCI_CHIP_IRONLAKE_D_G,    PCI_CHIP_IRONLAKE_D_G,  NULL},
-    {PCI_CHIP_IRONLAKE_M_G,    PCI_CHIP_IRONLAKE_M_G,  NULL},
-    {PCI_CHIP_SANDYBRIDGE_GT1, PCI_CHIP_SANDYBRIDGE_GT1,       NULL},
-    {PCI_CHIP_SANDYBRIDGE_GT2, PCI_CHIP_SANDYBRIDGE_GT2,       NULL},
-    {PCI_CHIP_SANDYBRIDGE_GT2_PLUS,    PCI_CHIP_SANDYBRIDGE_GT2_PLUS,  NULL},
-    {PCI_CHIP_SANDYBRIDGE_M_GT1,       PCI_CHIP_SANDYBRIDGE_M_GT1,     NULL},
-    {PCI_CHIP_SANDYBRIDGE_M_GT2,       PCI_CHIP_SANDYBRIDGE_M_GT2,     NULL},
-    {PCI_CHIP_SANDYBRIDGE_M_GT2_PLUS,  PCI_CHIP_SANDYBRIDGE_M_GT2_PLUS, NULL},
-    {PCI_CHIP_SANDYBRIDGE_S_GT,                PCI_CHIP_SANDYBRIDGE_S_GT,      NULL},
-    {-1,                               -1, NULL }
+       { 0, 0, 0 },
 };
 
-void intel_detect_chipset(ScrnInfoPtr scrn,
-                         struct pci_device *pci,
-                         struct intel_chipset *chipset)
+void
+intel_detect_chipset(ScrnInfoPtr scrn,
+                    EntityInfoPtr ent,
+                    struct pci_device *pci)
 {
-    uint32_t capid;
-
-    switch (DEVICE_ID(pci)) {
-    case PCI_CHIP_I810:
-       chipset->name = "i810";
-       chipset->info = &intel_i81x_info;
-       break;
-    case PCI_CHIP_I810_DC100:
-       chipset->name = "i810-dc100";
-       chipset->info = &intel_i81x_info;
-       break;
-    case PCI_CHIP_I810_E:
-       chipset->name = "i810e";
-       chipset->info = &intel_i81x_info;
-       break;
-    case PCI_CHIP_I815:
-       chipset->name = "i815";
-       chipset->info = &intel_i81x_info;
-       break;
-    case PCI_CHIP_I830_M:
-       chipset->name = "830M";
-       chipset->info = &intel_i8xx_info;
-       break;
-    case PCI_CHIP_845_G:
-       chipset->name = "845G";
-       chipset->info = &intel_i8xx_info;
-       break;
-    case PCI_CHIP_I854:
-       chipset->name = "854";
-       chipset->info = &intel_i8xx_info;
-       break;
-    case PCI_CHIP_I855_GM:
-       /* Check capid register to find the chipset variant */
-       pci_device_cfg_read_u32(pci, &capid, I85X_CAPID);
-       chipset->variant =
-           (capid >> I85X_VARIANT_SHIFT) & I85X_VARIANT_MASK;
-       switch (chipset->variant) {
-       case I855_GM:
-           chipset->name = "855GM";
-           break;
-       case I855_GME:
-           chipset->name = "855GME";
-           break;
-       case I852_GM:
-           chipset->name = "852GM";
-           break;
-       case I852_GME:
-           chipset->name = "852GME";
-           break;
-       default:
-           xf86DrvMsg(scrn->scrnIndex, X_INFO,
-                      "Unknown 852GM/855GM variant: 0x%x)\n",
-                      chipset->variant);
-           chipset->name = "852GM/855GM (unknown variant)";
-           break;
+       MessageType from = X_PROBED;
+       const char *name = NULL;
+       int i;
+
+       if (ent->device->chipID >= 0) {
+               xf86DrvMsg(scrn->scrnIndex, from = X_CONFIG,
+                          "ChipID override: 0x%04X\n",
+                          ent->device->chipID);
+               DEVICE_ID(pci) = ent->device->chipID;
        }
-       chipset->info = &intel_i8xx_info;
-       break;
-    case PCI_CHIP_I865_G:
-       chipset->name = "865G";
-       chipset->info = &intel_i8xx_info;
-       break;
-    case PCI_CHIP_I915_G:
-       chipset->name = "915G";
-       chipset->info = &intel_i915_info;
-       break;
-    case PCI_CHIP_E7221_G:
-       chipset->name = "E7221 (i915)";
-       chipset->info = &intel_i915_info;
-       break;
-    case PCI_CHIP_I915_GM:
-       chipset->name = "915GM";
-       chipset->info = &intel_i915_info;
-       break;
-    case PCI_CHIP_I945_G:
-       chipset->name = "945G";
-       chipset->info = &intel_i915_info;
-       break;
-    case PCI_CHIP_I945_GM:
-       chipset->name = "945GM";
-       chipset->info = &intel_i915_info;
-       break;
-    case PCI_CHIP_I945_GME:
-       chipset->name = "945GME";
-       chipset->info = &intel_i915_info;
-       break;
-    case PCI_CHIP_PINEVIEW_M:
-       chipset->name = "Pineview GM";
-       chipset->info = &intel_g33_info;
-       break;
-    case PCI_CHIP_PINEVIEW_G:
-       chipset->name = "Pineview G";
-       chipset->info = &intel_g33_info;
-       break;
-    case PCI_CHIP_I965_G:
-       chipset->name = "965G";
-       chipset->info = &intel_i965_info;
-       break;
-    case PCI_CHIP_G35_G:
-       chipset->name = "G35";
-       chipset->info = &intel_i965_info;
-       break;
-    case PCI_CHIP_I965_Q:
-       chipset->name = "965Q";
-       chipset->info = &intel_i965_info;
-       break;
-    case PCI_CHIP_I946_GZ:
-       chipset->name = "946GZ";
-       chipset->info = &intel_i965_info;
-       break;
-    case PCI_CHIP_I965_GM:
-       chipset->name = "965GM";
-       chipset->info = &intel_i965_info;
-       break;
-    case PCI_CHIP_I965_GME:
-       chipset->name = "965GME/GLE";
-       chipset->info = &intel_i965_info;
-       break;
-    case PCI_CHIP_G33_G:
-       chipset->name = "G33";
-       chipset->info = &intel_g33_info;
-       break;
-    case PCI_CHIP_Q35_G:
-       chipset->name = "Q35";
-       chipset->info = &intel_g33_info;
-       break;
-    case PCI_CHIP_Q33_G:
-       chipset->name = "Q33";
-       chipset->info = &intel_g33_info;
-       break;
-    case PCI_CHIP_GM45_GM:
-       chipset->name = "GM45";
-       chipset->info = &intel_g4x_info;
-       break;
-    case PCI_CHIP_G45_E_G:
-       chipset->name = "4 Series";
-       chipset->info = &intel_g4x_info;
-       break;
-    case PCI_CHIP_G45_G:
-       chipset->name = "G45/G43";
-       chipset->info = &intel_g4x_info;
-       break;
-    case PCI_CHIP_Q45_G:
-       chipset->name = "Q45/Q43";
-       chipset->info = &intel_g4x_info;
-       break;
-    case PCI_CHIP_G41_G:
-       chipset->name = "G41";
-       chipset->info = &intel_g4x_info;
-       break;
-    case PCI_CHIP_B43_G:
-       chipset->name = "B43";
-       chipset->info = &intel_g4x_info;
-       break;
-    case PCI_CHIP_IRONLAKE_D_G:
-       chipset->name = "Clarkdale";
-       chipset->info = &intel_ironlake_info;
-       break;
-    case PCI_CHIP_IRONLAKE_M_G:
-       chipset->name = "Arrandale";
-       chipset->info = &intel_ironlake_info;
-       break;
-    case PCI_CHIP_SANDYBRIDGE_GT1:
-    case PCI_CHIP_SANDYBRIDGE_GT2:
-    case PCI_CHIP_SANDYBRIDGE_GT2_PLUS:
-    case PCI_CHIP_SANDYBRIDGE_M_GT1:
-    case PCI_CHIP_SANDYBRIDGE_M_GT2:
-    case PCI_CHIP_SANDYBRIDGE_M_GT2_PLUS:
-    case PCI_CHIP_SANDYBRIDGE_S_GT:
-       chipset->name = "Sandybridge";
-       chipset->info = &intel_sandybridge_info;
-       break;
-    default:
-       chipset->name = "unknown chipset";
-       break;
-    }
-
-    xf86DrvMsg(scrn->scrnIndex, X_INFO,
-              "Integrated Graphics Chipset: Intel(R) %s\n", chipset->name);
+
+       for (i = 0; intel_chipsets[i].name != NULL; i++) {
+               if (DEVICE_ID(pci) == intel_chipsets[i].token) {
+                       name = intel_chipsets[i].name;
+                       break;
+               }
+       }
+       if (name == NULL) {
+               xf86DrvMsg(scrn->scrnIndex, X_WARNING, "unknown chipset\n");
+               name = "unknown";
+       } else {
+               xf86DrvMsg(scrn->scrnIndex, from,
+                          "Integrated Graphics Chipset: Intel(R) %s\n",
+                          name);
+       }
+
+       scrn->chipset = name;
 }
 
 /*
@@ -404,36 +357,36 @@ void intel_detect_chipset(ScrnInfoPtr scrn,
  */
 static void intel_identify(int flags)
 {
-    xf86PrintChipsets(INTEL_NAME,
-                     "Driver for Intel Integrated Graphics Chipsets",
-                     intel_chipsets);
+       xf86PrintChipsets(INTEL_NAME,
+                         "Driver for Intel Integrated Graphics Chipsets",
+                         intel_chipsets);
 }
 
 static Bool intel_driver_func(ScrnInfoPtr pScrn,
                              xorgDriverFuncOp op,
                              pointer ptr)
 {
-    xorgHWFlags *flag;
+       xorgHWFlags *flag;
 
-    switch (op) {
-    case GET_REQUIRED_HW_INTERFACES:
-       flag = (CARD32*)ptr;
+       switch (op) {
+       case GET_REQUIRED_HW_INTERFACES:
+               flag = (CARD32*)ptr;
 #ifdef KMS_ONLY
-       (*flag) = 0;
+               (*flag) = 0;
 #else
-       (*flag) = HW_IO | HW_MMIO;
+               (*flag) = HW_IO | HW_MMIO;
 #endif
-       return TRUE;
-    default:
-       /* Unknown or deprecated function */
-       return FALSE;
-    }
+               return TRUE;
+       default:
+               /* Unknown or deprecated function */
+               return FALSE;
+       }
 }
 
 static Bool has_kernel_mode_setting(struct pci_device *dev)
 {
        char id[20];
-       int ret;
+       int ret, fd;
 
        snprintf(id, sizeof(id),
                 "pci:%04x:%02x:%02x.%d",
@@ -443,14 +396,75 @@ static Bool has_kernel_mode_setting(struct pci_device *dev)
        if (ret) {
                if (xf86LoadKernelModule("i915"))
                        ret = drmCheckModesettingSupported(id);
-       }
-       /* Be nice to the user and load fbcon too */
-       if (!ret)
+               if (ret)
+                       return FALSE;
+               /* Be nice to the user and load fbcon too */
                (void)xf86LoadKernelModule("fbcon");
+       }
+
+       /* Confirm that this is a i915.ko device with GEM/KMS enabled */
+       ret = FALSE;
+       fd = drmOpen(NULL, id);
+       if (fd != -1) {
+               drmVersionPtr version = drmGetVersion(fd);
+               if (version) {
+                       ret = strcmp ("i915", version->name) == 0;
+                       drmFreeVersion(version);
+               }
+               if (ret) {
+                       struct drm_i915_getparam gp;
+                       gp.param = I915_PARAM_HAS_GEM;
+                       gp.value = &ret;
+                       if (drmIoctl(fd, DRM_IOCTL_I915_GETPARAM, &gp))
+                               ret = FALSE;
+               }
+
+               close(fd);
+       }
 
-       return ret == 0;
+       return ret;
 }
 
+#if !UMS_ONLY
+extern XF86ConfigPtr xf86configptr;
+
+static XF86ConfDevicePtr
+_xf86findDriver(const char *ident, XF86ConfDevicePtr p)
+{
+       while (p) {
+               if (p->dev_driver && xf86nameCompare(ident, p->dev_driver) == 0)
+                       return p;
+
+               p = p->list.next;
+       }
+
+       return NULL;
+}
+
+static enum accel_method { UXA, SNA } get_accel_method(void)
+{
+       enum accel_method accel_method = DEFAULT_ACCEL_METHOD;
+       XF86ConfDevicePtr dev;
+
+       dev = _xf86findDriver("intel", xf86configptr->conf_device_lst);
+       if (dev && dev->dev_option_lst) {
+               const char *s;
+
+               s = xf86FindOptionValue(dev->dev_option_lst, "AccelMethod");
+               if (s ) {
+                       if (strcasecmp(s, "sna") == 0)
+                               accel_method = SNA;
+                       else if (strcasecmp(s, "uxa") == 0)
+                               accel_method = UXA;
+                       else if (strcasecmp(s, "glamor") == 0)
+                               accel_method = UXA;
+               }
+       }
+
+       return accel_method;
+}
+#endif
+
 /*
  * intel_pci_probe --
  *
@@ -458,104 +472,185 @@ static Bool has_kernel_mode_setting(struct pci_device *dev)
  * Setup the dispatch table for the rest of the driver functions.
  *
  */
-static Bool intel_pci_probe (DriverPtr         driver,
-                            int                entity_num,
-                            struct pci_device  *device,
-                            intptr_t           match_data)
+static Bool intel_pci_probe(DriverPtr          driver,
+                           int                 entity_num,
+                           struct pci_device   *device,
+                           intptr_t            match_data)
 {
-    ScrnInfoPtr scrn;
+       ScrnInfoPtr scrn;
+       PciChipsets intel_pci_chipsets[NUM_CHIPSETS];
+       unsigned i;
 
-    if (!has_kernel_mode_setting(device)) {
+       if (!has_kernel_mode_setting(device)) {
 #if KMS_ONLY
-           return FALSE;
+               return FALSE;
 #else
-           switch (DEVICE_ID(device)) {
-           case PCI_CHIP_I810:
-           case PCI_CHIP_I810_DC100:
-           case PCI_CHIP_I810_E:
-           case PCI_CHIP_I815:
-                   break;
-           default:
-                   return FALSE;
-           }
+               switch (DEVICE_ID(device)) {
+               case PCI_CHIP_I810:
+               case PCI_CHIP_I810_DC100:
+               case PCI_CHIP_I810_E:
+               case PCI_CHIP_I815:
+                       break;
+               default:
+                       return FALSE;
+               }
 #endif
-    }
+       }
+
+       for (i = 0; i < NUM_CHIPSETS; i++) {
+               intel_pci_chipsets[i].numChipset = intel_chipsets[i].token;
+               intel_pci_chipsets[i].PCIid = intel_chipsets[i].token;
+#if XORG_VERSION_CURRENT < XORG_VERSION_NUMERIC(1,6,99,0,0)
+               intel_pci_chipsets[i].resList = RES_SHARED_VGA;
+#else
+               intel_pci_chipsets[i].dummy = NULL;
+#endif
+       }
+
+       scrn = xf86ConfigPciEntity(NULL, 0, entity_num, intel_pci_chipsets,
+                                  NULL, NULL, NULL, NULL, NULL);
+       if (scrn == NULL)
+               return FALSE;
 
-    scrn = xf86ConfigPciEntity(NULL, 0, entity_num, intel_pci_chipsets,
-                              NULL, NULL, NULL, NULL, NULL);
-    if (scrn != NULL) {
        scrn->driverVersion = INTEL_VERSION;
        scrn->driverName = INTEL_DRIVER_NAME;
        scrn->name = INTEL_NAME;
+       scrn->driverPrivate = (void *)(match_data | 1);
        scrn->Probe = NULL;
 
-#if KMS_ONLY
-       intel_init_scrn(scrn);
-#else
+#if !KMS_ONLY
        switch (DEVICE_ID(device)) {
        case PCI_CHIP_I810:
        case PCI_CHIP_I810_DC100:
        case PCI_CHIP_I810_E:
        case PCI_CHIP_I815:
-           lg_i810_init(scrn);
-           break;
+               return lg_i810_init(scrn);
+       }
+#endif
 
-       default:
-           intel_init_scrn(scrn);
-           break;
+#if !UMS_ONLY
+       switch (get_accel_method()) {
+#if USE_SNA
+       case SNA: return sna_init_scrn(scrn, entity_num);
+#endif
+
+#if USE_UXA
+       case UXA: return intel_init_scrn(scrn);
+#endif
+
+       default: break;
        }
 #endif
-    }
-    return scrn != NULL;
+
+       return FALSE;
 }
 
+#ifdef XSERVER_PLATFORM_BUS
+static Bool
+intel_platform_probe(DriverPtr driver,
+                    int entity_num, int flags,
+                    struct xf86_platform_device *dev,
+                    intptr_t match_data)
+{
+       ScrnInfoPtr scrn = NULL;
+       char *path = xf86_get_platform_device_attrib(dev, ODEV_ATTRIB_PATH);
+       unsigned scrn_flags = 0;
+
+       if (!dev->pdev)
+               return FALSE;
+
+       /* Allow ourselves to act as a slaved output if not primary */
+       if (flags & PLATFORM_PROBE_GPU_SCREEN) {
+               flags &= ~PLATFORM_PROBE_GPU_SCREEN;
+               scrn_flags |= XF86_ALLOCATE_GPU_SCREEN;
+       }
+
+       /* if we get any flags we don't understand fail to probe for now */
+       if (flags)
+               return FALSE;
+
+       scrn = xf86AllocateScreen(driver, scrn_flags);
+       if (scrn == NULL)
+               return FALSE;
+
+       scrn->driverVersion = INTEL_VERSION;
+       scrn->driverName = INTEL_DRIVER_NAME;
+       scrn->name = INTEL_NAME;
+       scrn->driverPrivate = (void *)(match_data | 1);
+       scrn->Probe = NULL;
+
+       if (xf86IsEntitySharable(entity_num))
+               xf86SetEntityShared(entity_num);
+       xf86AddEntityToScreen(scrn, entity_num);
+
+       xf86DrvMsg(scrn->scrnIndex, X_INFO,
+                  "using device path '%s'\n", path ? path : "Default device");
+
+#if !UMS_ONLY
+       switch (get_accel_method()) {
+#if USE_SNA
+        case SNA: return sna_init_scrn(scrn, entity_num);
+#endif
+#if USE_UXA
+        case UXA: return intel_init_scrn(scrn);
+#endif
+
+       default: break;
+       }
+#endif
+
+       return FALSE;
+}
+#endif
+
 #ifdef XFree86LOADER
 
 static MODULESETUPPROTO(intel_setup);
 
 static XF86ModuleVersionInfo intel_version = {
-    "intel",
-    MODULEVENDORSTRING,
-    MODINFOSTRING1,
-    MODINFOSTRING2,
-    XORG_VERSION_CURRENT,
-    INTEL_VERSION_MAJOR, INTEL_VERSION_MINOR, INTEL_VERSION_PATCH,
-    ABI_CLASS_VIDEODRV,
-    ABI_VIDEODRV_VERSION,
-    MOD_CLASS_VIDEODRV,
-    {0, 0, 0, 0}
+       "intel",
+       MODULEVENDORSTRING,
+       MODINFOSTRING1,
+       MODINFOSTRING2,
+       XORG_VERSION_CURRENT,
+       INTEL_VERSION_MAJOR, INTEL_VERSION_MINOR, INTEL_VERSION_PATCH,
+       ABI_CLASS_VIDEODRV,
+       ABI_VIDEODRV_VERSION,
+       MOD_CLASS_VIDEODRV,
+       {0, 0, 0, 0}
 };
 
 static const OptionInfoRec *
 intel_available_options(int chipid, int busid)
 {
-#if KMS_ONLY
-       return intel_uxa_available_options(chipid, busid);
-#else
        switch (chipid) {
+#if !KMS_ONLY
        case PCI_CHIP_I810:
        case PCI_CHIP_I810_DC100:
        case PCI_CHIP_I810_E:
        case PCI_CHIP_I815:
                return lg_i810_available_options(chipid, busid);
+#endif
 
        default:
-               return intel_uxa_available_options(chipid, busid);
+               return intel_options;
        }
-#endif
 }
 
 static DriverRec intel = {
-    INTEL_VERSION,
-    INTEL_DRIVER_NAME,
-    intel_identify,
-    NULL,
-    intel_available_options,
-    NULL,
-    0,
-    intel_driver_func,
-    intel_device_match,
-    intel_pci_probe
+       INTEL_VERSION,
+       INTEL_DRIVER_NAME,
+       intel_identify,
+       NULL,
+       intel_available_options,
+       NULL,
+       0,
+       intel_driver_func,
+       intel_device_match,
+       intel_pci_probe,
+#ifdef XSERVER_PLATFORM_BUS
+       intel_platform_probe
+#endif
 };
 
 static pointer intel_setup(pointer module,
@@ -563,24 +658,24 @@ static pointer intel_setup(pointer module,
                           int *errmaj,
                           int *errmin)
 {
-    static Bool setupDone = 0;
-
-    /* This module should be loaded only once, but check to be sure.
-    */
-    if (!setupDone) {
-       setupDone = 1;
-       xf86AddDriver(&intel, module, HaveDriverFuncs);
-
-       /*
-        * The return value must be non-NULL on success even though there
-        * is no TearDownProc.
-        */
-       return (pointer) 1;
-    } else {
-       if (errmaj)
-           *errmaj = LDR_ONCEONLY;
-       return NULL;
-    }
+       static Bool setupDone = 0;
+
+       /* This module should be loaded only once, but check to be sure.
+       */
+       if (!setupDone) {
+               setupDone = 1;
+               xf86AddDriver(&intel, module, HaveDriverFuncs);
+
+               /*
+                * The return value must be non-NULL on success even though there
+                * is no TearDownProc.
+                */
+               return (pointer) 1;
+       } else {
+               if (errmaj)
+                       *errmaj = LDR_ONCEONLY;
+               return NULL;
+       }
 }
 
 _X_EXPORT XF86ModuleData intelModuleData = { &intel_version, intel_setup, NULL };
diff --git a/src/intel_options.c b/src/intel_options.c
new file mode 100644 (file)
index 0000000..dcab9e7
--- /dev/null
@@ -0,0 +1,53 @@
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "intel_options.h"
+
+const OptionInfoRec intel_options[] = {
+       {OPTION_ACCEL_DISABLE,  "NoAccel",      OPTV_BOOLEAN,   {0},    0},
+       {OPTION_ACCEL_METHOD,   "AccelMethod",  OPTV_STRING,    {0},    0},
+       {OPTION_BACKLIGHT,      "Backlight",    OPTV_STRING,    {0},    0},
+       {OPTION_DRI,            "DRI",          OPTV_BOOLEAN,   {0},    1},
+       {OPTION_COLOR_KEY,      "ColorKey",     OPTV_INTEGER,   {0},    0},
+       {OPTION_VIDEO_KEY,      "VideoKey",     OPTV_INTEGER,   {0},    0},
+       {OPTION_TILING_2D,      "Tiling",       OPTV_BOOLEAN,   {0},    1},
+       {OPTION_TILING_FB,      "LinearFramebuffer",    OPTV_BOOLEAN,   {0},    0},
+       {OPTION_SWAPBUFFERS_WAIT, "SwapbuffersWait", OPTV_BOOLEAN,      {0},    1},
+       {OPTION_PREFER_OVERLAY, "XvPreferOverlay", OPTV_BOOLEAN, {0}, 0},
+       {OPTION_HOTPLUG,        "HotPlug",      OPTV_BOOLEAN,   {0},    1},
+       {OPTION_RELAXED_FENCING,"RelaxedFencing",       OPTV_BOOLEAN,   {0},    1},
+#ifdef INTEL_XVMC
+       {OPTION_XVMC,   "XvMC",         OPTV_BOOLEAN,   {0},    1},
+#endif
+#ifdef USE_SNA
+       {OPTION_THROTTLE,       "Throttle",     OPTV_BOOLEAN,   {0},    1},
+       {OPTION_ZAPHOD,         "ZaphodHeads",  OPTV_STRING,    {0},    0},
+       {OPTION_DELAYED_FLUSH,  "DelayedFlush", OPTV_BOOLEAN,   {0},    1},
+       {OPTION_TEAR_FREE,      "TearFree",     OPTV_BOOLEAN,   {0},    0},
+       {OPTION_CRTC_PIXMAPS,   "PerCrtcPixmaps", OPTV_BOOLEAN, {0},    0},
+#endif
+#ifdef USE_UXA
+       {OPTION_FALLBACKDEBUG,  "FallbackDebug",OPTV_BOOLEAN,   {0},    0},
+       {OPTION_DEBUG_FLUSH_BATCHES, "DebugFlushBatches", OPTV_BOOLEAN, {0}, 0},
+       {OPTION_DEBUG_FLUSH_CACHES, "DebugFlushCaches", OPTV_BOOLEAN, {0}, 0},
+       {OPTION_DEBUG_WAIT, "DebugWait", OPTV_BOOLEAN, {0}, 0},
+       {OPTION_BUFFER_CACHE,   "BufferCache",  OPTV_BOOLEAN,   {0},    1},
+       {OPTION_TRIPLE_BUFFER,  "TripleBuffer", OPTV_BOOLEAN,   {0},    1},
+#endif
+       {-1,                    NULL,           OPTV_NONE,      {0},    0}
+};
+
+OptionInfoPtr intel_options_get(ScrnInfoPtr scrn)
+{
+       OptionInfoPtr options;
+
+       xf86CollectOptions(scrn, NULL);
+       if (!(options = malloc(sizeof(intel_options))))
+               return NULL;
+
+       memcpy(options, intel_options, sizeof(intel_options));
+       xf86ProcessOptions(scrn->scrnIndex, scrn->options, options);
+
+       return options;
+}
diff --git a/src/intel_options.h b/src/intel_options.h
new file mode 100644 (file)
index 0000000..3b5262a
--- /dev/null
@@ -0,0 +1,51 @@
+#ifndef INTEL_OPTIONS_H
+#define INTEL_OPTIONS_H
+
+#include <xf86.h>
+#include <xf86Opt.h>
+
+/*
+ * Note: "ColorKey" is provided for compatibility with the i810 driver.
+ * However, the correct option name is "VideoKey".  "ColorKey" usually
+ * refers to the tranparency key for 8+24 overlays, not for video overlays.
+ */
+
+enum intel_options {
+       OPTION_ACCEL_DISABLE,
+       OPTION_ACCEL_METHOD,
+       OPTION_BACKLIGHT,
+       OPTION_DRI,
+       OPTION_VIDEO_KEY,
+       OPTION_COLOR_KEY,
+       OPTION_TILING_2D,
+       OPTION_TILING_FB,
+       OPTION_SWAPBUFFERS_WAIT,
+       OPTION_PREFER_OVERLAY,
+       OPTION_HOTPLUG,
+       OPTION_RELAXED_FENCING,
+#if defined(XvMCExtension) && defined(ENABLE_XVMC)
+       OPTION_XVMC,
+#define INTEL_XVMC 1
+#endif
+#ifdef USE_SNA
+       OPTION_THROTTLE,
+       OPTION_ZAPHOD,
+       OPTION_DELAYED_FLUSH,
+       OPTION_TEAR_FREE,
+       OPTION_CRTC_PIXMAPS,
+#endif
+#ifdef USE_UXA
+       OPTION_FALLBACKDEBUG,
+       OPTION_DEBUG_FLUSH_BATCHES,
+       OPTION_DEBUG_FLUSH_CACHES,
+       OPTION_DEBUG_WAIT,
+       OPTION_BUFFER_CACHE,
+       OPTION_TRIPLE_BUFFER,
+#endif
+       NUM_OPTIONS,
+};
+
+extern const OptionInfoRec intel_options[];
+OptionInfoPtr intel_options_get(ScrnInfoPtr scrn);
+
+#endif /* INTEL_OPTIONS_H */
diff --git a/src/intel_shadow.c b/src/intel_shadow.c
deleted file mode 100644 (file)
index b86530a..0000000
+++ /dev/null
@@ -1,204 +0,0 @@
-/**************************************************************************
-
-Copyright 2010 Intel Corporation
-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, sub license, 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 NON-INFRINGEMENT.
-IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS 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_CONFIG_H
-#include "config.h"
-#endif
-
-#include "xf86.h"
-#include "xaarop.h"
-#include "intel.h"
-#include "i830_reg.h"
-
-static dri_bo *
-intel_shadow_create_bo(intel_screen_private *intel,
-                      int16_t x1, int16_t y1,
-                      int16_t x2, int16_t y2,
-                      int *pitch)
-{
-       int w = x2 - x1, h = y2 - y1;
-       int size = h * w * intel->cpp;
-       dri_bo *bo;
-
-       bo = drm_intel_bo_alloc(intel->bufmgr, "shadow", size, 0);
-       if (bo && drm_intel_gem_bo_map_gtt(bo) == 0) {
-               char *dst = bo->virtual;
-               char *src = intel->shadow_buffer;
-               int src_pitch = intel->shadow_stride;
-               int row_length = w * intel->cpp;
-               int num_rows = h;
-               src += y1 * src_pitch + x1 * intel->cpp;
-               do {
-                       memcpy (dst, src, row_length);
-                       src += src_pitch;
-                       dst += row_length;
-               } while (--num_rows);
-               drm_intel_gem_bo_unmap_gtt(bo);
-       }
-
-       *pitch = w * intel->cpp;
-       return bo;
-}
-
-static void intel_shadow_memcpy(intel_screen_private *intel)
-{
-       char *src_data, *dst_data;
-       unsigned int src_pitch, dst_pitch;
-       RegionPtr region;
-       BoxPtr box;
-       int n;
-
-       if (drm_intel_gem_bo_map_gtt(intel->front_buffer))
-               return;
-
-       src_data = intel->shadow_buffer;
-       dst_data = intel->front_buffer->virtual;
-
-       src_pitch = intel->shadow_stride;
-       dst_pitch = intel->front_pitch;
-
-       region = DamageRegion(intel->shadow_damage);
-       box = REGION_RECTS(region);
-       n = REGION_NUM_RECTS(region);
-       while (n--) {
-               char *src = src_data + box->y1*src_pitch + box->x1*intel->cpp;
-               char *dst = dst_data + box->y1*dst_pitch + box->x1*intel->cpp;
-               int len = (box->x2 - box->x1)*intel->cpp;
-               int row = box->y2 - box->y1;
-               while (row--) {
-                       memcpy(dst, src, len);
-                       src += src_pitch;
-                       dst += dst_pitch;
-               }
-               box++;
-       }
-}
-
-void intel_shadow_blt(intel_screen_private *intel)
-{
-       ScrnInfoPtr scrn = intel->scrn;
-       unsigned int dst_pitch;
-       uint32_t blt, br13;
-       RegionPtr region;
-       BoxPtr box;
-       int n;
-
-       /* Can we trust the BLT? Otherwise do an uncached mmecy. */
-       if (!intel->can_blt || IS_GEN2(intel)) {
-               intel_shadow_memcpy(intel);
-               return;
-       }
-
-       dst_pitch = intel->front_pitch;
-
-       blt = XY_SRC_COPY_BLT_CMD;
-       if (intel->cpp == 4)
-               blt |= (XY_SRC_COPY_BLT_WRITE_ALPHA |
-                               XY_SRC_COPY_BLT_WRITE_RGB);
-
-       if (INTEL_INFO(intel)->gen >= 40) {
-               if (intel->front_tiling) {
-                       dst_pitch >>= 2;
-                       blt |= XY_SRC_COPY_BLT_DST_TILED;
-               }
-       }
-
-       br13 = ROP_S << 16 | dst_pitch;
-       switch (intel->cpp) {
-               default:
-               case 4: br13 |= 1 << 25; /* RGB8888 */
-               case 2: br13 |= 1 << 24; /* RGB565 */
-               case 1: break;
-       }
-
-       region = DamageRegion(intel->shadow_damage);
-       box = REGION_RECTS(region);
-       n = REGION_NUM_RECTS(region);
-       while (n--) {
-               int pitch;
-               dri_bo *bo;
-
-               bo = intel_shadow_create_bo(intel,
-                                           box->x1, box->y1,
-                                           box->x2, box->y2,
-                                           &pitch);
-               if (bo == NULL)
-                       return;
-
-               BEGIN_BATCH_BLT(8);
-               OUT_BATCH(blt);
-               OUT_BATCH(br13);
-               OUT_BATCH(box->y1 << 16 | box->x1);
-               OUT_BATCH(box->y2 << 16 | box->x2);
-               OUT_RELOC_FENCED(intel->front_buffer,
-                               I915_GEM_DOMAIN_RENDER,
-                               I915_GEM_DOMAIN_RENDER,
-                               0);
-               OUT_BATCH(0);
-               OUT_BATCH(pitch);
-               OUT_RELOC(bo, I915_GEM_DOMAIN_RENDER, 0, 0);
-
-               ADVANCE_BATCH();
-
-               drm_intel_bo_unreference(bo);
-               box++;
-       }
-}
-
-void intel_shadow_create(struct intel_screen_private *intel)
-{
-       ScrnInfoPtr scrn = intel->scrn;
-       ScreenPtr screen = scrn->pScreen;
-       PixmapPtr pixmap;
-       int stride;
-       void *buffer;
-
-       pixmap = screen->GetScreenPixmap(screen);
-       stride = intel->cpp*scrn->virtualX;
-       buffer = malloc(stride * scrn->virtualY);
-       if (buffer &&
-           screen->ModifyPixmapHeader(pixmap,
-                                      scrn->virtualX, scrn->virtualY,
-                                      -1, -1,
-                                      stride, buffer)) {
-               free(intel->shadow_buffer);
-               intel->shadow_buffer = buffer;
-       } else
-               stride = intel->shadow_stride;
-
-       if (!intel->shadow_damage) {
-               intel->shadow_damage =
-                       DamageCreate(NULL, NULL,
-                                    DamageReportNone, TRUE,
-                                    screen, intel);
-               DamageRegister(&pixmap->drawable, intel->shadow_damage);
-               DamageSetReportAfterOp(intel->shadow_damage, TRUE);
-       }
-
-       scrn->displayWidth = stride / intel->cpp;
-       intel->shadow_stride = stride;
-}
index df3adcb..6d202c7 100644 (file)
@@ -31,14 +31,20 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "config.h"
 #endif
 
-#include "xf86.h"
-#include "xaarop.h"
+#include <xf86.h>
+#include <xf86drm.h>
+#include <xaarop.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+
 #include "intel.h"
+#include "intel_glamor.h"
+#include "uxa.h"
+
 #include "i830_reg.h"
 #include "i915_drm.h"
 #include "brw_defines.h"
-#include <string.h>
-#include <errno.h>
 
 static const int I830CopyROP[16] = {
        ROP_0,                  /* GXclear */
@@ -155,7 +161,7 @@ intel_uxa_pixmap_compute_size(PixmapPtr pixmap,
                              int *stride,
                              unsigned usage)
 {
-       ScrnInfoPtr scrn = xf86Screens[pixmap->drawable.pScreen->myNum];
+       ScrnInfoPtr scrn = xf86ScreenToScrn(pixmap->drawable.pScreen);
        intel_screen_private *intel = intel_get_screen_private(scrn);
        int pitch, size;
 
@@ -222,11 +228,14 @@ intel_uxa_pixmap_compute_size(PixmapPtr pixmap,
        }
 
        if (*tiling == I915_TILING_NONE) {
+               /* We only require a 64 byte alignment for scanouts, but
+                * a 256 byte alignment for sharing with PRIME.
+                */
+               *stride = ALIGN(pitch, 256);
                /* Round the height up so that the GPU's access to a 2x2 aligned
                 * subspan doesn't address an invalid page offset beyond the
                 * end of the GTT.
                 */
-               *stride = ALIGN(pitch, 64);
                size = *stride * ALIGN(h, 2);
        }
 
@@ -236,7 +245,7 @@ intel_uxa_pixmap_compute_size(PixmapPtr pixmap,
 static Bool
 intel_uxa_check_solid(DrawablePtr drawable, int alu, Pixel planemask)
 {
-       ScrnInfoPtr scrn = xf86Screens[drawable->pScreen->myNum];
+       ScrnInfoPtr scrn = xf86ScreenToScrn(drawable->pScreen);
 
        if (!UXA_PM_IS_SOLID(drawable, planemask)) {
                intel_debug_fallback(scrn, "planemask is not solid\n");
@@ -261,7 +270,7 @@ intel_uxa_check_solid(DrawablePtr drawable, int alu, Pixel planemask)
 static Bool
 intel_uxa_prepare_solid(PixmapPtr pixmap, int alu, Pixel planemask, Pixel fg)
 {
-       ScrnInfoPtr scrn = xf86Screens[pixmap->drawable.pScreen->myNum];
+       ScrnInfoPtr scrn = xf86ScreenToScrn(pixmap->drawable.pScreen);
        intel_screen_private *intel = intel_get_screen_private(scrn);
        drm_intel_bo *bo_table[] = {
                NULL,           /* batch_bo */
@@ -294,7 +303,7 @@ intel_uxa_prepare_solid(PixmapPtr pixmap, int alu, Pixel planemask, Pixel fg)
 
 static void intel_uxa_solid(PixmapPtr pixmap, int x1, int y1, int x2, int y2)
 {
-       ScrnInfoPtr scrn = xf86Screens[pixmap->drawable.pScreen->myNum];
+       ScrnInfoPtr scrn = xf86ScreenToScrn(pixmap->drawable.pScreen);
        intel_screen_private *intel = intel_get_screen_private(scrn);
        unsigned long pitch;
        uint32_t cmd;
@@ -340,13 +349,6 @@ static void intel_uxa_solid(PixmapPtr pixmap, int x1, int y1, int x2, int y2)
        }
 }
 
-static void intel_uxa_done_solid(PixmapPtr pixmap)
-{
-       ScrnInfoPtr scrn = xf86Screens[pixmap->drawable.pScreen->myNum];
-
-       intel_debug_flush(scrn);
-}
-
 /**
  * TODO:
  *   - support planemask using FULL_BLT_CMD?
@@ -355,7 +357,7 @@ static Bool
 intel_uxa_check_copy(PixmapPtr source, PixmapPtr dest,
                    int alu, Pixel planemask)
 {
-       ScrnInfoPtr scrn = xf86Screens[dest->drawable.pScreen->myNum];
+       ScrnInfoPtr scrn = xf86ScreenToScrn(dest->drawable.pScreen);
 
        if (!UXA_PM_IS_SOLID(&source->drawable, planemask)) {
                intel_debug_fallback(scrn, "planemask is not solid");
@@ -387,7 +389,7 @@ static Bool
 intel_uxa_prepare_copy(PixmapPtr source, PixmapPtr dest, int xdir,
                      int ydir, int alu, Pixel planemask)
 {
-       ScrnInfoPtr scrn = xf86Screens[dest->drawable.pScreen->myNum];
+       ScrnInfoPtr scrn = xf86ScreenToScrn(dest->drawable.pScreen);
        intel_screen_private *intel = intel_get_screen_private(scrn);
        drm_intel_bo *bo_table[] = {
                NULL,           /* batch_bo */
@@ -419,7 +421,7 @@ static void
 intel_uxa_copy(PixmapPtr dest, int src_x1, int src_y1, int dst_x1,
              int dst_y1, int w, int h)
 {
-       ScrnInfoPtr scrn = xf86Screens[dest->drawable.pScreen->myNum];
+       ScrnInfoPtr scrn = xf86ScreenToScrn(dest->drawable.pScreen);
        intel_screen_private *intel = intel_get_screen_private(scrn);
        uint32_t cmd;
        int dst_x2, dst_y2, src_x2, src_y2;
@@ -501,9 +503,19 @@ intel_uxa_copy(PixmapPtr dest, int src_x1, int src_y1, int dst_x1,
        }
 }
 
-static void intel_uxa_done_copy(PixmapPtr dest)
+static void intel_uxa_done(PixmapPtr pixmap)
 {
-       ScrnInfoPtr scrn = xf86Screens[dest->drawable.pScreen->myNum];
+       ScrnInfoPtr scrn = xf86ScreenToScrn(pixmap->drawable.pScreen);
+       intel_screen_private *intel = intel_get_screen_private(scrn);
+
+       if (IS_GEN6(intel) || IS_GEN7(intel)) {
+               /* workaround a random BLT hang */
+               BEGIN_BATCH_BLT(3);
+               OUT_BATCH(XY_SETUP_CLIP_BLT_CMD);
+               OUT_BATCH(0);
+               OUT_BATCH(0);
+               ADVANCE_BATCH();
+       }
 
        intel_debug_flush(scrn);
 }
@@ -515,7 +527,7 @@ static void intel_uxa_done_copy(PixmapPtr dest)
  */
 static void i830_done_composite(PixmapPtr dest)
 {
-       ScrnInfoPtr scrn = xf86Screens[dest->drawable.pScreen->myNum];
+       ScrnInfoPtr scrn = xf86ScreenToScrn(dest->drawable.pScreen);
        intel_screen_private *intel = intel_get_screen_private(scrn);
 
        if (intel->vertex_flush)
@@ -620,12 +632,9 @@ dri_bo *intel_get_pixmap_bo(PixmapPtr pixmap)
 
 void intel_set_pixmap_bo(PixmapPtr pixmap, dri_bo * bo)
 {
-       ScrnInfoPtr scrn = xf86Screens[pixmap->drawable.pScreen->myNum];
-       intel_screen_private *intel = intel_get_screen_private(scrn);
        struct intel_pixmap *priv;
 
        priv = intel_get_pixmap_private(pixmap);
-
        if (priv == NULL && bo == NULL)
            return;
 
@@ -633,20 +642,11 @@ void intel_set_pixmap_bo(PixmapPtr pixmap, dri_bo * bo)
                if (priv->bo == bo)
                        return;
 
-               priv->dst_bound = priv->src_bound = 0;
-               if (list_is_empty(&priv->batch)) {
-                       dri_bo_unreference(priv->bo);
-               } else if (!drm_intel_bo_is_reusable(priv->bo)) {
-                       dri_bo_unreference(priv->bo);
-                       list_del(&priv->batch);
-                       list_del(&priv->flush);
-               } else {
-                       list_add(&priv->in_flight, &intel->in_flight);
-                       priv = NULL;
-               }
+               dri_bo_unreference(priv->bo);
+               list_del(&priv->batch);
 
-               if (intel->render_current_dest == pixmap)
-                   intel->render_current_dest = NULL;
+               free(priv);
+               priv = NULL;
        }
 
        if (bo != NULL) {
@@ -654,14 +654,11 @@ void intel_set_pixmap_bo(PixmapPtr pixmap, dri_bo * bo)
                uint32_t swizzle_mode;
                int ret;
 
-               if (priv == NULL) {
-                       priv = calloc(1, sizeof (struct intel_pixmap));
-                       if (priv == NULL)
-                               goto BAIL;
+               priv = calloc(1, sizeof (struct intel_pixmap));
+               if (priv == NULL)
+                       goto BAIL;
 
-                       list_init(&priv->batch);
-                       list_init(&priv->flush);
-               }
+               list_init(&priv->batch);
 
                dri_bo_reference(bo);
                priv->bo = bo;
@@ -676,11 +673,6 @@ void intel_set_pixmap_bo(PixmapPtr pixmap, dri_bo * bo)
                priv->tiling = tiling;
                priv->busy = -1;
                priv->offscreen = 1;
-       } else {
-               if (priv != NULL) {
-                       free(priv);
-                       priv = NULL;
-               }
        }
 
   BAIL:
@@ -689,30 +681,38 @@ void intel_set_pixmap_bo(PixmapPtr pixmap, dri_bo * bo)
 
 static Bool intel_uxa_pixmap_is_offscreen(PixmapPtr pixmap)
 {
-       struct intel_pixmap *priv = intel_get_pixmap_private(pixmap);
-       return priv && priv->offscreen;
+       return intel_pixmap_is_offscreen(pixmap);
 }
 
 static Bool intel_uxa_prepare_access(PixmapPtr pixmap, uxa_access_t access)
 {
-       ScrnInfoPtr scrn = xf86Screens[pixmap->drawable.pScreen->myNum];
+       ScrnInfoPtr scrn = xf86ScreenToScrn(pixmap->drawable.pScreen);
        intel_screen_private *intel = intel_get_screen_private(scrn);
        struct intel_pixmap *priv = intel_get_pixmap_private(pixmap);
        dri_bo *bo = priv->bo;
        int ret;
 
-       if (!list_is_empty(&priv->batch) &&
-           (access == UXA_ACCESS_RW || priv->batch_write))
+       /* Transitioning to glamor acceleration, we need to flush all pending
+        * usage by UXA. */
+       if (access == UXA_GLAMOR_ACCESS_RW || access == UXA_GLAMOR_ACCESS_RO) {
+               if (!list_is_empty(&priv->batch))
+                       intel_batch_submit(scrn);
+               return TRUE;
+       }
+
+       /* When falling back to swrast, flush all pending operations */
+       intel_glamor_flush(intel);
+       if (access == UXA_ACCESS_RW || priv->dirty)
                intel_batch_submit(scrn);
 
-       if (priv->tiling || bo->size <= intel->max_gtt_map_size)
-               ret = drm_intel_gem_bo_map_gtt(bo);
-       else
-               ret = dri_bo_map(bo, access == UXA_ACCESS_RW);
+       assert(bo->size <= intel->max_gtt_map_size);
+       ret = drm_intel_gem_bo_map_gtt(bo);
        if (ret) {
                xf86DrvMsg(scrn->scrnIndex, X_WARNING,
-                          "%s: bo map failed: %s\n",
+                          "%s: bo map (use gtt? %d, access %d) failed: %s\n",
                           __FUNCTION__,
+                          priv->tiling || bo->size <= intel->max_gtt_map_size,
+                          access,
                           strerror(-ret));
                return FALSE;
        }
@@ -723,6 +723,21 @@ static Bool intel_uxa_prepare_access(PixmapPtr pixmap, uxa_access_t access)
        return TRUE;
 }
 
+static void intel_uxa_finish_access(PixmapPtr pixmap, uxa_access_t access)
+{
+       struct intel_pixmap *priv;
+
+       if (access == UXA_GLAMOR_ACCESS_RW || access == UXA_GLAMOR_ACCESS_RO)
+               return;
+
+       priv = intel_get_pixmap_private(pixmap);
+       if (priv == NULL)
+               return;
+
+       drm_intel_gem_bo_unmap_gtt(priv->bo);
+       pixmap->devPrivate.ptr = NULL;
+}
+
 static Bool intel_uxa_pixmap_put_image(PixmapPtr pixmap,
                                       char *src, int src_pitch,
                                       int x, int y, int w, int h)
@@ -776,7 +791,7 @@ static Bool intel_uxa_put_image(PixmapPtr pixmap,
                    w == pixmap->drawable.width &&
                    h == pixmap->drawable.height)
                {
-                       intel_screen_private *intel = intel_get_screen_private(xf86Screens[screen->myNum]);
+                       intel_screen_private *intel = intel_get_screen_private(xf86ScreenToScrn(screen));
                        uint32_t tiling = priv->tiling;
                        int size, stride;
                        dri_bo *bo;
@@ -921,7 +936,7 @@ static Bool intel_uxa_get_image(PixmapPtr pixmap,
 
                FreeScratchGC(gc);
 
-               intel_batch_submit(xf86Screens[screen->myNum]);
+               intel_batch_submit(xf86ScreenToScrn(screen));
 
                x = y = 0;
                pixmap = scratch;
@@ -935,6 +950,23 @@ static Bool intel_uxa_get_image(PixmapPtr pixmap,
        return ret;
 }
 
+static CARD32 intel_cache_expire(OsTimerPtr timer, CARD32 now, pointer data)
+{
+       intel_screen_private *intel = data;
+
+       /* We just want to create and destroy a bo as this causes libdrm
+        * to reap its caches. However, since we can't remove that buffer
+        * from the cache due to its own activity, we want to use something
+        * that we know we will reuse later. The most frequently reused buffer
+        * we have is the batchbuffer, and the best way to trigger its
+        * reallocation is to submit a flush.
+        */
+       intel_batch_emit_flush(intel->scrn);
+       intel_batch_submit(intel->scrn);
+
+       return 0;
+}
+
 static void intel_flush_rendering(intel_screen_private *intel)
 {
        if (intel->needs_flush == 0)
@@ -948,31 +980,42 @@ static void intel_flush_rendering(intel_screen_private *intel)
                intel_batch_submit(intel->scrn);
        }
 
+       intel->cache_expire = TimerSet(intel->cache_expire, 0, 3000,
+                                      intel_cache_expire, intel);
+
        intel->needs_flush = 0;
 }
 
-void intel_uxa_block_handler(intel_screen_private *intel)
+static void intel_throttle(intel_screen_private *intel)
 {
-       if (intel->shadow_damage &&
-           pixman_region_not_empty(DamageRegion(intel->shadow_damage))) {
-               intel_shadow_blt(intel);
-               DamageEmpty(intel->shadow_damage);
-       }
+       drmCommandNone(intel->drmSubFD, DRM_I915_GEM_THROTTLE);
+}
 
+void intel_uxa_block_handler(intel_screen_private *intel)
+{
        /* Emit a flush of the rendering cache, or on the 965
         * and beyond rendering results may not hit the
         * framebuffer until significantly later.
         */
+       intel_glamor_flush(intel);
        intel_flush_rendering(intel);
+       intel_throttle(intel);
 }
 
 static PixmapPtr
 intel_uxa_create_pixmap(ScreenPtr screen, int w, int h, int depth,
                        unsigned usage)
 {
-       ScrnInfoPtr scrn = xf86Screens[screen->myNum];
+       ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
        intel_screen_private *intel = intel_get_screen_private(scrn);
-       PixmapPtr pixmap;
+       struct intel_pixmap *priv;
+       PixmapPtr pixmap, new_pixmap = NULL;
+
+       if (!(usage & INTEL_CREATE_PIXMAP_DRI2)) {
+               pixmap = intel_glamor_create_pixmap(screen, w, h, depth, usage);
+               if (pixmap)
+                       return pixmap;
+       }
 
        if (w > 32767 || h > 32767)
                return NullPixmap;
@@ -980,16 +1023,14 @@ intel_uxa_create_pixmap(ScreenPtr screen, int w, int h, int depth,
        if (depth == 1 || intel->force_fallback)
                return fbCreatePixmap(screen, w, h, depth, usage);
 
-       if (intel->use_shadow && (usage & INTEL_CREATE_PIXMAP_DRI2) == 0)
-               return fbCreatePixmap(screen, w, h, depth, usage);
-
        if (usage == CREATE_PIXMAP_USAGE_GLYPH_PICTURE && w <= 32 && h <= 32)
                return fbCreatePixmap(screen, w, h, depth, usage);
 
        pixmap = fbCreatePixmap(screen, 0, 0, depth, usage);
+       if (pixmap == NullPixmap)
+               return pixmap;
 
        if (w && h) {
-               struct intel_pixmap *priv;
                unsigned int size, tiling;
                int stride;
 
@@ -1003,6 +1044,10 @@ intel_uxa_create_pixmap(ScreenPtr screen, int w, int h, int depth,
                if (usage == UXA_CREATE_PIXMAP_FOR_MAP || usage & INTEL_CREATE_PIXMAP_TILING_NONE)
                        tiling = I915_TILING_NONE;
 
+#ifdef CREATE_PIXMAP_USAGE_SHARED
+               if (usage == CREATE_PIXMAP_USAGE_SHARED)
+                       tiling = I915_TILING_NONE;
+#endif
                /* if tiling is off force to none */
                if (!intel->tiling)
                        tiling = I915_TILING_NONE;
@@ -1019,53 +1064,12 @@ intel_uxa_create_pixmap(ScreenPtr screen, int w, int h, int depth,
                 * frequently, and also will tend to fail to successfully map when doing
                 * SW fallbacks because we overcommit address space for BO access.
                 */
-               if (size > intel->max_bo_size || stride >= KB(32)) {
-                       fbDestroyPixmap(pixmap);
-                       return fbCreatePixmap(screen, w, h, depth, usage);
-               }
-
-               /* Perform a preliminary search for an in-flight bo */
-               if (usage != UXA_CREATE_PIXMAP_FOR_MAP) {
-                       int aligned_h;
-
-                       if (tiling == I915_TILING_X)
-                               aligned_h = ALIGN(h, 8);
-                       else if (tiling == I915_TILING_Y)
-                               aligned_h = ALIGN(h, 32);
-                       else
-                               aligned_h = ALIGN(h, 2);
-
-                       list_foreach_entry(priv, struct intel_pixmap,
-                                          &intel->in_flight,
-                                          in_flight) {
-                               if (priv->tiling != tiling)
-                                       continue;
-
-                               if (tiling == I915_TILING_NONE) {
-                                   if (priv->bo->size < size)
-                                           continue;
-
-                                       priv->stride = stride;
-                               } else {
-                                       if (priv->stride < stride ||
-                                           priv->bo->size < priv->stride * aligned_h)
-                                               continue;
-
-                                       stride = priv->stride;
-                               }
-
-                               list_del(&priv->in_flight);
-                               screen->ModifyPixmapHeader(pixmap, w, h, 0, 0, stride, NULL);
-                               intel_set_pixmap_private(pixmap, priv);
-                               return pixmap;
-                       }
-               }
+               if (size > intel->max_bo_size || stride >= KB(32))
+                       goto fallback_pixmap;
 
                priv = calloc(1, sizeof (struct intel_pixmap));
-               if (priv == NULL) {
-                       fbDestroyPixmap(pixmap);
-                       return NullPixmap;
-               }
+               if (priv == NULL)
+                       goto fallback_pixmap;
 
                if (usage == UXA_CREATE_PIXMAP_FOR_MAP) {
                        priv->busy = 0;
@@ -1077,11 +1081,8 @@ intel_uxa_create_pixmap(ScreenPtr screen, int w, int h, int depth,
                                                                 "pixmap",
                                                                 size, 0);
                }
-               if (!priv->bo) {
-                       free(priv);
-                       fbDestroyPixmap(pixmap);
-                       return NullPixmap;
-               }
+               if (!priv->bo)
+                       goto fallback_priv;
 
                if (tiling != I915_TILING_NONE)
                        drm_intel_bo_set_tiling(priv->bo, &tiling, stride);
@@ -1089,52 +1090,155 @@ intel_uxa_create_pixmap(ScreenPtr screen, int w, int h, int depth,
                priv->tiling = tiling;
                priv->offscreen = 1;
 
-               screen->ModifyPixmapHeader(pixmap, w, h, 0, 0, stride, NULL);
-
                list_init(&priv->batch);
-               list_init(&priv->flush);
                intel_set_pixmap_private(pixmap, priv);
+
+               screen->ModifyPixmapHeader(pixmap, w, h, 0, 0, stride, NULL);
+
+               if (!intel_glamor_create_textured_pixmap(pixmap))
+                       goto fallback_glamor;
        }
 
        return pixmap;
+
+fallback_glamor:
+       if (usage & INTEL_CREATE_PIXMAP_DRI2) {
+       /* XXX need further work to handle the DRI2 failure case.
+        * Glamor don't know how to handle a BO only pixmap. Put
+        * a warning indicator here.
+        */
+               xf86DrvMsg(scrn->scrnIndex, X_WARNING,
+                          "Failed to create textured DRI2 pixmap.");
+               return pixmap;
+       }
+       /* Create textured pixmap failed means glamor failed to
+        * create a texture from current BO for some reasons. We turn
+        * to create a new glamor pixmap and clean up current one.
+        * One thing need to be noted, this new pixmap doesn't
+        * has a priv and bo attached to it. It's glamor's responsbility
+        * to take care of it. Glamor will mark this new pixmap as a
+        * texture only pixmap and will never fallback to DDX layer
+        * afterwards.
+        */
+       new_pixmap = intel_glamor_create_pixmap(screen, w, h,
+                                               depth, usage);
+       dri_bo_unreference(priv->bo);
+fallback_priv:
+       free(priv);
+fallback_pixmap:
+       fbDestroyPixmap(pixmap);
+       if (new_pixmap)
+               return new_pixmap;
+       else
+               return fbCreatePixmap(screen, w, h, depth, usage);
 }
 
 static Bool intel_uxa_destroy_pixmap(PixmapPtr pixmap)
 {
-       if (pixmap->refcnt == 1)
+       if (pixmap->refcnt == 1) {
+               intel_glamor_destroy_pixmap(pixmap);
                intel_set_pixmap_bo(pixmap, NULL);
+       }
        fbDestroyPixmap(pixmap);
        return TRUE;
 }
 
 Bool intel_uxa_create_screen_resources(ScreenPtr screen)
 {
-       ScrnInfoPtr scrn = xf86Screens[screen->myNum];
+       ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+       PixmapPtr pixmap;
        intel_screen_private *intel = intel_get_screen_private(scrn);
        dri_bo *bo = intel->front_buffer;
 
        if (!uxa_resources_init(screen))
                return FALSE;
 
-       drm_intel_gem_bo_map_gtt(bo);
+       if (drm_intel_gem_bo_map_gtt(bo))
+               return FALSE;
 
-       if (intel->use_shadow) {
-               intel_shadow_create(intel);
-       } else {
-               PixmapPtr pixmap = screen->GetScreenPixmap(screen);
-               intel_set_pixmap_bo(pixmap, bo);
-               intel_get_pixmap_private(pixmap)->pinned = 1;
-               screen->ModifyPixmapHeader(pixmap,
-                                          scrn->virtualX,
-                                          scrn->virtualY,
-                                          -1, -1,
-                                          intel->front_pitch,
-                                          NULL);
-               scrn->displayWidth = intel->front_pitch / intel->cpp;
+       pixmap = screen->GetScreenPixmap(screen);
+       intel_set_pixmap_bo(pixmap, bo);
+       intel_get_pixmap_private(pixmap)->pinned |= PIN_SCANOUT;
+       screen->ModifyPixmapHeader(pixmap,
+                                  scrn->virtualX,
+                                  scrn->virtualY,
+                                  -1, -1,
+                                  intel->front_pitch,
+                                  NULL);
+       scrn->displayWidth = intel->front_pitch / intel->cpp;
+
+       if (!intel_glamor_create_screen_resources(screen))
+               return FALSE;
+
+       return TRUE;
+}
+
+#ifdef CREATE_PIXMAP_USAGE_SHARED
+static Bool
+intel_uxa_share_pixmap_backing(PixmapPtr ppix, ScreenPtr slave, void **fd_handle)
+{
+       ScrnInfoPtr scrn = xf86ScreenToScrn(ppix->drawable.pScreen);
+       intel_screen_private *intel = intel_get_screen_private(scrn);
+       struct intel_pixmap *priv = intel_get_pixmap_private(ppix);
+       unsigned int size, tiling, swizzle;
+       dri_bo *bo = intel_get_pixmap_bo(ppix), *newbo;
+       int stride;
+       int handle;
+
+       if (drm_intel_bo_references(intel->batch_bo, bo))
+               intel_batch_submit(intel->scrn);
+
+       drm_intel_bo_get_tiling(bo, &tiling, &swizzle);
+
+       if (tiling == I915_TILING_X) {
+               if (priv->pinned & ~PIN_DRI)
+                       return FALSE;
+
+               tiling = I915_TILING_NONE;
+
+               size = intel_uxa_pixmap_compute_size(ppix, ppix->drawable.width, ppix->drawable.height, &tiling, &stride, INTEL_CREATE_PIXMAP_DRI2);
+
+               newbo = drm_intel_bo_alloc_for_render(intel->bufmgr,
+                                                     "pixmap",
+                                                     size, 0);
+
+               if (tiling != I915_TILING_NONE)
+                       drm_intel_bo_set_tiling(newbo, &tiling, stride);
+               priv->stride = stride;
+               priv->tiling = tiling;
+               intel_set_pixmap_bo(ppix, newbo);
+
+               ppix->drawable.pScreen->ModifyPixmapHeader(ppix, ppix->drawable.width,
+                                          ppix->drawable.height, 0, 0,
+                                          stride, NULL);
+               bo = newbo;
        }
+       drm_intel_bo_get_tiling(bo, &tiling, &swizzle);
+       drm_intel_bo_gem_export_to_prime(bo, &handle);
+       priv->pinned |= PIN_DRI;
+
+       *fd_handle = (void *)(long)handle;
+       return TRUE;
+}
+
+static Bool
+intel_uxa_set_shared_pixmap_backing(PixmapPtr ppix, void *fd_handle)
+{
+       ScrnInfoPtr scrn = xf86ScreenToScrn(ppix->drawable.pScreen);
+       intel_screen_private *intel = intel_get_screen_private(scrn);
+       dri_bo *bo;
+       int ihandle = (int)(long)fd_handle;
+
+       /* force untiled for now */
+       bo = drm_intel_bo_gem_create_from_prime(intel->bufmgr, ihandle, 0);
+       if (!bo)
+               return FALSE;
 
+       intel_set_pixmap_bo(ppix, bo);
+       close(ihandle);
        return TRUE;
 }
+#endif
 
 static void
 intel_limits_init(intel_screen_private *intel)
@@ -1190,7 +1294,7 @@ intel_limits_init(intel_screen_private *intel)
 
 Bool intel_uxa_init(ScreenPtr screen)
 {
-       ScrnInfoPtr scrn = xf86Screens[screen->myNum];
+       ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
        intel_screen_private *intel = intel_get_screen_private(scrn);
 
 #if HAS_DIXREGISTERPRIVATEKEY
@@ -1211,7 +1315,6 @@ Bool intel_uxa_init(ScreenPtr screen)
        intel->uxa_driver->uxa_major = 1;
        intel->uxa_driver->uxa_minor = 0;
 
-       intel->render_current_dest = NULL;
        intel->prim_offset = 0;
        intel->vertex_count = 0;
        intel->vertex_offset = 0;
@@ -1226,13 +1329,13 @@ Bool intel_uxa_init(ScreenPtr screen)
        intel->uxa_driver->check_solid = intel_uxa_check_solid;
        intel->uxa_driver->prepare_solid = intel_uxa_prepare_solid;
        intel->uxa_driver->solid = intel_uxa_solid;
-       intel->uxa_driver->done_solid = intel_uxa_done_solid;
+       intel->uxa_driver->done_solid = intel_uxa_done;
 
        /* Copy */
        intel->uxa_driver->check_copy = intel_uxa_check_copy;
        intel->uxa_driver->prepare_copy = intel_uxa_prepare_copy;
        intel->uxa_driver->copy = intel_uxa_copy;
-       intel->uxa_driver->done_copy = intel_uxa_done_copy;
+       intel->uxa_driver->done_copy = intel_uxa_done;
 
        /* Composite */
        if (IS_GEN2(intel)) {
@@ -1280,11 +1383,17 @@ Bool intel_uxa_init(ScreenPtr screen)
        intel->uxa_driver->get_image = intel_uxa_get_image;
 
        intel->uxa_driver->prepare_access = intel_uxa_prepare_access;
+       intel->uxa_driver->finish_access = intel_uxa_finish_access;
        intel->uxa_driver->pixmap_is_offscreen = intel_uxa_pixmap_is_offscreen;
 
        screen->CreatePixmap = intel_uxa_create_pixmap;
        screen->DestroyPixmap = intel_uxa_destroy_pixmap;
 
+#ifdef CREATE_PIXMAP_USAGE_SHARED
+       screen->SharePixmapBacking = intel_uxa_share_pixmap_backing;
+       screen->SetSharedPixmapBacking = intel_uxa_set_shared_pixmap_backing;
+#endif
+
        if (!uxa_driver_init(screen, intel->uxa_driver)) {
                xf86DrvMsg(scrn->scrnIndex, X_ERROR,
                           "UXA initialization failed\n");
index 499614f..09782aa 100644 (file)
@@ -58,9 +58,9 @@
 #include "xf86.h"
 #include "xf86_OSproc.h"
 #include "compiler.h"
-#include "xf86PciInfo.h"
 #include "xf86Pci.h"
 #include "xf86fbman.h"
+#include "xf86drm.h"
 #include "regionstr.h"
 #include "randrstr.h"
 #include "windowstr.h"
@@ -149,13 +149,6 @@ static XF86AttributeRec Attributes[NUM_ATTRIBUTES] = {
        {XvSettable | XvGettable, -1, 1, "XV_PIPE"}
 };
 
-#define NUM_TEXTURED_ATTRIBUTES 3
-static XF86AttributeRec TexturedAttributes[NUM_TEXTURED_ATTRIBUTES] = {
-       {XvSettable | XvGettable, -128, 127, "XV_BRIGHTNESS"},
-       {XvSettable | XvGettable, 0, 255, "XV_CONTRAST"},
-       {XvSettable | XvGettable, -1, 1, "XV_SYNC_TO_VBLANK"},
-};
-
 #define GAMMA_ATTRIBUTES 6
 static XF86AttributeRec GammaAttributes[GAMMA_ATTRIBUTES] = {
        {XvSettable | XvGettable, 0, 0xffffff, "XV_GAMMA0"},
@@ -217,14 +210,13 @@ static Bool intel_has_overlay(intel_screen_private *intel)
        gp.value = &has_overlay;
        ret = drmCommandWriteRead(intel->drmSubFD, DRM_I915_GETPARAM, &gp, sizeof(gp));
 
-       return !! has_overlay;
+       return ret == 0 && !! has_overlay;
 }
 
-static void intel_overlay_update_attrs(intel_screen_private *intel)
+static Bool intel_overlay_update_attrs(intel_screen_private *intel)
 {
        intel_adaptor_private *adaptor_priv = intel_get_adaptor_private(intel);
        struct drm_intel_overlay_attrs attrs;
-       int ret;
 
        attrs.flags = I915_OVERLAY_UPDATE_ATTRS;
        attrs.brightness = adaptor_priv->brightness;
@@ -238,8 +230,8 @@ static void intel_overlay_update_attrs(intel_screen_private *intel)
        attrs.gamma4 = adaptor_priv->gamma4;
        attrs.gamma5 = adaptor_priv->gamma5;
 
-       ret = drmCommandWriteRead(intel->drmSubFD, DRM_I915_OVERLAY_ATTRS,
-                                 &attrs, sizeof(attrs));
+       return drmCommandWriteRead(intel->drmSubFD, DRM_I915_OVERLAY_ATTRS,
+                                  &attrs, sizeof(attrs)) == 0;
 }
 
 static void intel_overlay_off(intel_screen_private *intel)
@@ -251,6 +243,7 @@ static void intel_overlay_off(intel_screen_private *intel)
 
        ret = drmCommandWrite(intel->drmSubFD, DRM_I915_OVERLAY_PUT_IMAGE,
                              &request, sizeof(request));
+       (void) ret;
 }
 
 static Bool
@@ -334,23 +327,20 @@ intel_overlay_put_image(intel_screen_private *intel,
 
 void I830InitVideo(ScreenPtr screen)
 {
-       ScrnInfoPtr scrn = xf86Screens[screen->myNum];
+       ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
        intel_screen_private *intel = intel_get_screen_private(scrn);
-       XF86VideoAdaptorPtr *adaptors, *newAdaptors = NULL;
+       XF86VideoAdaptorPtr *adaptors = NULL, *newAdaptors = NULL;
        XF86VideoAdaptorPtr overlayAdaptor = NULL, texturedAdaptor = NULL;
-       int num_adaptors;
-
-       num_adaptors = xf86XVListGenericAdaptors(scrn, &adaptors);
+       int num_adaptors = xf86XVListGenericAdaptors(scrn, &adaptors);
        /* Give our adaptor list enough space for the overlay and/or texture video
         * adaptors.
         */
-       newAdaptors =
-           malloc((num_adaptors + 2) * sizeof(XF86VideoAdaptorPtr *));
-       if (newAdaptors == NULL)
+       newAdaptors = realloc(adaptors,
+                             (num_adaptors + 2) * sizeof(XF86VideoAdaptorPtr));
+       if (newAdaptors == NULL) {
+               free(adaptors);
                return;
-
-       memcpy(newAdaptors, adaptors,
-              num_adaptors * sizeof(XF86VideoAdaptorPtr));
+       }
        adaptors = newAdaptors;
 
        /* Add the adaptors supported by our hardware.  First, set up the atoms
@@ -363,8 +353,7 @@ void I830InitVideo(ScreenPtr screen)
         * supported hardware.
         */
        if (scrn->bitsPerPixel >= 16 &&
-           INTEL_INFO(intel)->gen >= 30 &&
-           !intel->use_shadow) {
+           INTEL_INFO(intel)->gen >= 30) {
                texturedAdaptor = I830SetupImageVideoTextured(screen);
                if (texturedAdaptor != NULL) {
                        xf86DrvMsg(scrn->scrnIndex, X_INFO,
@@ -414,7 +403,7 @@ void I830InitVideo(ScreenPtr screen)
 
 static XF86VideoAdaptorPtr I830SetupImageVideoOverlay(ScreenPtr screen)
 {
-       ScrnInfoPtr scrn = xf86Screens[screen->myNum];
+       ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
        intel_screen_private *intel = intel_get_screen_private(scrn);
        XF86VideoAdaptorPtr adapt;
        intel_adaptor_private *adaptor_priv;
@@ -459,7 +448,6 @@ static XF86VideoAdaptorPtr I830SetupImageVideoOverlay(ScreenPtr screen)
        if (INTEL_INFO(intel)->gen >= 30) {
                memcpy((char *)att, (char *)GammaAttributes,
                       sizeof(XF86AttributeRec) * GAMMA_ATTRIBUTES);
-               att += GAMMA_ATTRIBUTES;
        }
        adapt->nImages = NUM_IMAGES - XVMC_IMAGE;
 
@@ -523,29 +511,22 @@ static XF86VideoAdaptorPtr I830SetupImageVideoOverlay(ScreenPtr screen)
 
 static XF86VideoAdaptorPtr I830SetupImageVideoTextured(ScreenPtr screen)
 {
-       ScrnInfoPtr scrn = xf86Screens[screen->myNum];
+       ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
        intel_screen_private *intel = intel_get_screen_private(scrn);
        XF86VideoAdaptorPtr adapt;
-       XF86AttributePtr attrs;
        intel_adaptor_private *adaptor_privs;
        DevUnion *devUnions;
        int nports = 16, i;
-       int nAttributes;
 
        OVERLAY_DEBUG("I830SetupImageVideoOverlay\n");
 
-       nAttributes = NUM_TEXTURED_ATTRIBUTES;
-
        adapt = calloc(1, sizeof(XF86VideoAdaptorRec));
        adaptor_privs = calloc(nports, sizeof(intel_adaptor_private));
        devUnions = calloc(nports, sizeof(DevUnion));
-       attrs = calloc(nAttributes, sizeof(XF86AttributeRec));
-       if (adapt == NULL || adaptor_privs == NULL || devUnions == NULL ||
-           attrs == NULL) {
+       if (adapt == NULL || adaptor_privs == NULL || devUnions == NULL) {
                free(adapt);
                free(adaptor_privs);
                free(devUnions);
-               free(attrs);
                return NULL;
        }
 
@@ -559,10 +540,8 @@ static XF86VideoAdaptorPtr I830SetupImageVideoTextured(ScreenPtr screen)
        adapt->pFormats = Formats;
        adapt->nPorts = nports;
        adapt->pPortPrivates = devUnions;
-       adapt->nAttributes = nAttributes;
-       adapt->pAttributes = attrs;
-       memcpy(attrs, TexturedAttributes,
-              nAttributes * sizeof(XF86AttributeRec));
+       adapt->nAttributes = 0;
+       adapt->pAttributes = NULL;
        if (IS_I915G(intel) || IS_I915GM(intel))
                adapt->nImages = NUM_IMAGES - XVMC_IMAGE;
        else
@@ -696,7 +675,7 @@ I830SetPortAttributeOverlay(ScrnInfoPtr scrn,
                adaptor_priv->saturation = value;
        } else if (attribute == xvPipe) {
                xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
-               if ((value < -1) || (value > xf86_config->num_crtc))
+               if ((value < -1) || (value >= xf86_config->num_crtc))
                        return BadValue;
                if (value < 0)
                        adaptor_priv->desired_crtc = NULL;
@@ -729,7 +708,8 @@ I830SetPortAttributeOverlay(ScrnInfoPtr scrn,
                OVERLAY_DEBUG("GAMMA\n");
        }
 
-       intel_overlay_update_attrs(intel);
+       if (!intel_overlay_update_attrs(intel))
+               return BadValue;
 
        if (attribute == xvColorKey)
                REGION_EMPTY(scrn->pScreen, &adaptor_priv->clip);
@@ -1300,7 +1280,7 @@ intel_wait_for_scanline(ScrnInfoPtr scrn, PixmapPtr pixmap,
        int y1, y2;
 
        pipe = -1;
-       if (pixmap_is_scanout(pixmap))
+       if (scrn->vtSema && pixmap_is_scanout(pixmap))
                pipe = intel_crtc_to_pipe(crtc);
        if (pipe < 0)
                return;
@@ -1530,6 +1510,9 @@ I830PutImageTextured(ScrnInfoPtr scrn,
        xf86CrtcPtr crtc;
        int top, left, npixels, nlines;
 
+       if (!intel_pixmap_is_offscreen(pixmap))
+               return BadAlloc;
+
 #if 0
        ErrorF("I830PutImage: src: (%d,%d)(%d,%d), dst: (%d,%d)(%d,%d)\n"
               "width %d, height %d\n", src_x, src_y, src_w, src_h, drw_x,
@@ -1599,8 +1582,14 @@ I830PutImageTextured(ScrnInfoPtr scrn,
                                         pixmap);
        }
 
+       intel_get_screen_private(scrn)->needs_flush = TRUE;
        DamageDamageRegion(drawable, clipBoxes);
 
+       /* And make sure the WAIT_FOR_EVENT is queued before any
+        * modesetting/dpms operations on the pipe.
+        */
+       intel_batch_submit(scrn);
+
        return Success;
 }
 
index 7384eda..c7a343f 100644 (file)
@@ -1,9 +1,9 @@
-# Makefile.in generated by automake 1.11.1 from Makefile.am.
+# Makefile.in generated by automake 1.11.6 from Makefile.am.
 # @configure_input@
 
 # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-# 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
-# Inc.
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
+# Foundation, Inc.
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
 @SET_MAKE@
 
 VPATH = @srcdir@
+am__make_dryrun = \
+  { \
+    am__dry=no; \
+    case $$MAKEFLAGS in \
+      *\\[\ \  ]*) \
+        echo 'am--echo: ; @echo "AM"  OK' | $(MAKE) -f - 2>/dev/null \
+          | grep '^AM OK$$' >/dev/null || am__dry=yes;; \
+      *) \
+        for am__flg in $$MAKEFLAGS; do \
+          case $$am__flg in \
+            *=*|--*) ;; \
+            *n*) am__dry=yes; break;; \
+          esac; \
+        done;; \
+    esac; \
+    test $$am__dry = yes; \
+  }
 pkgdatadir = $(datadir)/@PACKAGE@
 pkgincludedir = $(includedir)/@PACKAGE@
 pkglibdir = $(libdir)/@PACKAGE@
@@ -43,10 +60,7 @@ host_triplet = @host@
 subdir = src/legacy
 DIST_COMMON = README $(srcdir)/Makefile.am $(srcdir)/Makefile.in
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
-       $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
-       $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
-       $(top_srcdir)/configure.ac
+am__aclocal_m4_deps = $(top_srcdir)/configure.ac
 am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
        $(ACLOCAL_M4)
 mkinstalldirs = $(install_sh) -d
@@ -61,8 +75,8 @@ liblegacy_la_DEPENDENCIES = $(am__DEPENDENCIES_2)
 am__objects_1 =
 am_liblegacy_la_OBJECTS = $(am__objects_1)
 liblegacy_la_OBJECTS = $(am_liblegacy_la_OBJECTS)
-AM_V_lt = $(am__v_lt_$(V))
-am__v_lt_ = $(am__v_lt_$(AM_DEFAULT_VERBOSITY))
+AM_V_lt = $(am__v_lt_@AM_V@)
+am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
 am__v_lt_0 = --silent
 DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
 COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
@@ -71,21 +85,21 @@ LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
        $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \
        $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
        $(AM_CFLAGS) $(CFLAGS)
-AM_V_CC = $(am__v_CC_$(V))
-am__v_CC_ = $(am__v_CC_$(AM_DEFAULT_VERBOSITY))
+AM_V_CC = $(am__v_CC_@AM_V@)
+am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@)
 am__v_CC_0 = @echo "  CC    " $@;
-AM_V_at = $(am__v_at_$(V))
-am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY))
+AM_V_at = $(am__v_at_@AM_V@)
+am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
 am__v_at_0 = @
 CCLD = $(CC)
 LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
        $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
        $(AM_LDFLAGS) $(LDFLAGS) -o $@
-AM_V_CCLD = $(am__v_CCLD_$(V))
-am__v_CCLD_ = $(am__v_CCLD_$(AM_DEFAULT_VERBOSITY))
+AM_V_CCLD = $(am__v_CCLD_@AM_V@)
+am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
 am__v_CCLD_0 = @echo "  CCLD  " $@;
-AM_V_GEN = $(am__v_GEN_$(V))
-am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY))
+AM_V_GEN = $(am__v_GEN_@AM_V@)
+am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
 am__v_GEN_0 = @echo "  GEN   " $@;
 SOURCES = $(liblegacy_la_SOURCES)
 DIST_SOURCES = $(liblegacy_la_SOURCES)
@@ -96,6 +110,11 @@ RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \
        install-pdf-recursive install-ps-recursive install-recursive \
        installcheck-recursive installdirs-recursive pdf-recursive \
        ps-recursive uninstall-recursive
+am__can_run_installinfo = \
+  case $$AM_UPDATE_INFO_DIR in \
+    n|no|NO) false;; \
+    *) (install-info --version) >/dev/null 2>&1;; \
+  esac
 RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive        \
   distclean-recursive maintainer-clean-recursive
 AM_RECURSIVE_TARGETS = $(RECURSIVE_TARGETS:-recursive=) \
@@ -142,6 +161,7 @@ AUTOCONF = @AUTOCONF@
 AUTOHEADER = @AUTOHEADER@
 AUTOMAKE = @AUTOMAKE@
 AWK = @AWK@
+BASE_CFLAGS = @BASE_CFLAGS@
 CC = @CC@
 CCDEPMODE = @CCDEPMODE@
 CFLAGS = @CFLAGS@
@@ -152,11 +172,16 @@ CWARNFLAGS = @CWARNFLAGS@
 CYGPATH_W = @CYGPATH_W@
 DEFS = @DEFS@
 DEPDIR = @DEPDIR@
+DLLTOOL = @DLLTOOL@
+DRI2_CFLAGS = @DRI2_CFLAGS@
+DRI2_LIBS = @DRI2_LIBS@
 DRIVER_MAN_DIR = @DRIVER_MAN_DIR@
 DRIVER_MAN_SUFFIX = @DRIVER_MAN_SUFFIX@
 DRIVER_NAME = @DRIVER_NAME@
 DRI_CFLAGS = @DRI_CFLAGS@
 DRI_LIBS = @DRI_LIBS@
+DRMINTEL_CFLAGS = @DRMINTEL_CFLAGS@
+DRMINTEL_LIBS = @DRMINTEL_LIBS@
 DRM_CFLAGS = @DRM_CFLAGS@
 DRM_LIBS = @DRM_LIBS@
 DSYMUTIL = @DSYMUTIL@
@@ -180,6 +205,10 @@ INSTALL_SCRIPT = @INSTALL_SCRIPT@
 INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
 LD = @LD@
 LDFLAGS = @LDFLAGS@
+LIBGLAMOR_CFLAGS = @LIBGLAMOR_CFLAGS@
+LIBGLAMOR_EGL_CFLAGS = @LIBGLAMOR_EGL_CFLAGS@
+LIBGLAMOR_EGL_LIBS = @LIBGLAMOR_EGL_LIBS@
+LIBGLAMOR_LIBS = @LIBGLAMOR_LIBS@
 LIBOBJS = @LIBOBJS@
 LIBS = @LIBS@
 LIBTOOL = @LIBTOOL@
@@ -190,6 +219,7 @@ LN_S = @LN_S@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MANIFEST_TOOL = @MANIFEST_TOOL@
 MAN_SUBSTS = @MAN_SUBSTS@
 MISC_MAN_DIR = @MISC_MAN_DIR@
 MISC_MAN_SUFFIX = @MISC_MAN_SUFFIX@
@@ -217,10 +247,15 @@ RANLIB = @RANLIB@
 SED = @SED@
 SET_MAKE = @SET_MAKE@
 SHELL = @SHELL@
+STRICT_CFLAGS = @STRICT_CFLAGS@
 STRIP = @STRIP@
 UDEV_CFLAGS = @UDEV_CFLAGS@
 UDEV_LIBS = @UDEV_LIBS@
+VALGRIND_CFLAGS = @VALGRIND_CFLAGS@
+VALGRIND_LIBS = @VALGRIND_LIBS@
 VERSION = @VERSION@
+X11_CFLAGS = @X11_CFLAGS@
+X11_LIBS = @X11_LIBS@
 XORG_CFLAGS = @XORG_CFLAGS@
 XORG_LIBS = @XORG_LIBS@
 XORG_MAN_PAGE = @XORG_MAN_PAGE@
@@ -230,6 +265,7 @@ abs_builddir = @abs_builddir@
 abs_srcdir = @abs_srcdir@
 abs_top_builddir = @abs_top_builddir@
 abs_top_srcdir = @abs_top_srcdir@
+ac_ct_AR = @ac_ct_AR@
 ac_ct_CC = @ac_ct_CC@
 ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
 am__include = @am__include@
@@ -262,7 +298,6 @@ libdir = @libdir@
 libexecdir = @libexecdir@
 localedir = @localedir@
 localstatedir = @localstatedir@
-lt_ECHO = @lt_ECHO@
 mandir = @mandir@
 mkdir_p = @mkdir_p@
 moduledir = @moduledir@
@@ -327,7 +362,7 @@ clean-noinstLTLIBRARIES:
          echo "rm -f \"$${dir}/so_locations\""; \
          rm -f "$${dir}/so_locations"; \
        done
-liblegacy.la: $(liblegacy_la_OBJECTS) $(liblegacy_la_DEPENDENCIES) 
+liblegacy.la: $(liblegacy_la_OBJECTS) $(liblegacy_la_DEPENDENCIES) $(EXTRA_liblegacy_la_DEPENDENCIES) 
        $(AM_V_CCLD)$(LINK)  $(liblegacy_la_OBJECTS) $(liblegacy_la_LIBADD) $(LIBS)
 
 mostlyclean-compile:
@@ -509,13 +544,10 @@ distdir: $(DISTFILES)
        done
        @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
          if test "$$subdir" = .; then :; else \
-           test -d "$(distdir)/$$subdir" \
-           || $(MKDIR_P) "$(distdir)/$$subdir" \
-           || exit 1; \
-         fi; \
-       done
-       @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
-         if test "$$subdir" = .; then :; else \
+           $(am__make_dryrun) \
+             || test -d "$(distdir)/$$subdir" \
+             || $(MKDIR_P) "$(distdir)/$$subdir" \
+             || exit 1; \
            dir1=$$subdir; dir2="$(distdir)/$$subdir"; \
            $(am__relativize); \
            new_distdir=$$reldir; \
@@ -550,10 +582,15 @@ install-am: all-am
 
 installcheck: installcheck-recursive
 install-strip:
-       $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
-         install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
-         `test -z '$(STRIP)' || \
-           echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+       if test -z '$(STRIP)'; then \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+             install; \
+       else \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+           "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+       fi
 mostlyclean-generic:
 
 clean-generic:
index 3676da6..51489b8 100644 (file)
@@ -11,25 +11,33 @@ liblegacy_i810_la_SOURCES = \
          i810_accel.c \
          i810_common.h \
          i810_cursor.c \
-         i810_dga.c \
          i810_driver.c \
          i810.h \
-         i810_io.c \
          i810_memory.c \
          i810_reg.h \
          i810_ring.h \
          i810_video.c \
          i810_wmark.c
 
+if XAA
+liblegacy_i810_la_SOURCES += \
+         i810_xaa.c
+endif
+
+if DGA
+liblegacy_i810_la_SOURCES += \
+         i810_dga.c
+endif
+
 if DRI
 liblegacy_i810_la_SOURCES +=\
          i810_dri.c \
          i810_dri.h \
         $(NULL)
-endif
 
 if XVMC
 liblegacy_i810_la_SOURCES += \
        i810_hwmc.c \
        $(NULL)
 endif
+endif
index 1c189a7..374bd90 100644 (file)
@@ -1,9 +1,9 @@
-# Makefile.in generated by automake 1.11.1 from Makefile.am.
+# Makefile.in generated by automake 1.11.6 from Makefile.am.
 # @configure_input@
 
 # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-# 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
-# Inc.
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
+# Foundation, Inc.
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
 @SET_MAKE@
 
 VPATH = @srcdir@
+am__make_dryrun = \
+  { \
+    am__dry=no; \
+    case $$MAKEFLAGS in \
+      *\\[\ \  ]*) \
+        echo 'am--echo: ; @echo "AM"  OK' | $(MAKE) -f - 2>/dev/null \
+          | grep '^AM OK$$' >/dev/null || am__dry=yes;; \
+      *) \
+        for am__flg in $$MAKEFLAGS; do \
+          case $$am__flg in \
+            *=*|--*) ;; \
+            *n*) am__dry=yes; break;; \
+          esac; \
+        done;; \
+    esac; \
+    test $$am__dry = yes; \
+  }
 pkgdatadir = $(datadir)/@PACKAGE@
 pkgincludedir = $(includedir)/@PACKAGE@
 pkglibdir = $(libdir)/@PACKAGE@
@@ -34,22 +51,25 @@ PRE_UNINSTALL = :
 POST_UNINSTALL = :
 build_triplet = @build@
 host_triplet = @host@
-@DRI_TRUE@am__append_1 = \
+@XAA_TRUE@am__append_1 = \
+@XAA_TRUE@         i810_xaa.c
+
+@DGA_TRUE@am__append_2 = \
+@DGA_TRUE@         i810_dga.c
+
+@DRI_TRUE@am__append_3 = \
 @DRI_TRUE@         i810_dri.c \
 @DRI_TRUE@         i810_dri.h \
 @DRI_TRUE@      $(NULL)
 
-@XVMC_TRUE@am__append_2 = \
-@XVMC_TRUE@    i810_hwmc.c \
-@XVMC_TRUE@    $(NULL)
+@DRI_TRUE@@XVMC_TRUE@am__append_4 = \
+@DRI_TRUE@@XVMC_TRUE@  i810_hwmc.c \
+@DRI_TRUE@@XVMC_TRUE@  $(NULL)
 
 subdir = src/legacy/i810
 DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
-       $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
-       $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
-       $(top_srcdir)/configure.ac
+am__aclocal_m4_deps = $(top_srcdir)/configure.ac
 am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
        $(ACLOCAL_M4)
 mkinstalldirs = $(install_sh) -d
@@ -59,20 +79,23 @@ CONFIG_CLEAN_VPATH_FILES =
 LTLIBRARIES = $(noinst_LTLIBRARIES)
 liblegacy_i810_la_LIBADD =
 am__liblegacy_i810_la_SOURCES_DIST = i810_accel.c i810_common.h \
-       i810_cursor.c i810_dga.c i810_driver.c i810.h i810_io.c \
-       i810_memory.c i810_reg.h i810_ring.h i810_video.c i810_wmark.c \
+       i810_cursor.c i810_driver.c i810.h i810_memory.c i810_reg.h \
+       i810_ring.h i810_video.c i810_wmark.c i810_xaa.c i810_dga.c \
        i810_dri.c i810_dri.h i810_hwmc.c
-@DRI_TRUE@am__objects_1 = i810_dri.lo
-@XVMC_TRUE@am__objects_2 = i810_hwmc.lo
+@XAA_TRUE@am__objects_1 = i810_xaa.lo
+@DGA_TRUE@am__objects_2 = i810_dga.lo
+@DRI_TRUE@am__objects_3 = i810_dri.lo
+@DRI_TRUE@@XVMC_TRUE@am__objects_4 = i810_hwmc.lo
 am_liblegacy_i810_la_OBJECTS = i810_accel.lo i810_cursor.lo \
-       i810_dga.lo i810_driver.lo i810_io.lo i810_memory.lo \
-       i810_video.lo i810_wmark.lo $(am__objects_1) $(am__objects_2)
+       i810_driver.lo i810_memory.lo i810_video.lo i810_wmark.lo \
+       $(am__objects_1) $(am__objects_2) $(am__objects_3) \
+       $(am__objects_4)
 liblegacy_i810_la_OBJECTS = $(am_liblegacy_i810_la_OBJECTS)
-AM_V_lt = $(am__v_lt_$(V))
-am__v_lt_ = $(am__v_lt_$(AM_DEFAULT_VERBOSITY))
+AM_V_lt = $(am__v_lt_@AM_V@)
+am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
 am__v_lt_0 = --silent
 DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
-depcomp = $(SHELL) $(top_srcdir)/build-aux/depcomp
+depcomp = $(SHELL) $(top_srcdir)/depcomp
 am__depfiles_maybe = depfiles
 am__mv = mv -f
 COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
@@ -81,21 +104,21 @@ LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
        $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \
        $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
        $(AM_CFLAGS) $(CFLAGS)
-AM_V_CC = $(am__v_CC_$(V))
-am__v_CC_ = $(am__v_CC_$(AM_DEFAULT_VERBOSITY))
+AM_V_CC = $(am__v_CC_@AM_V@)
+am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@)
 am__v_CC_0 = @echo "  CC    " $@;
-AM_V_at = $(am__v_at_$(V))
-am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY))
+AM_V_at = $(am__v_at_@AM_V@)
+am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
 am__v_at_0 = @
 CCLD = $(CC)
 LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
        $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
        $(AM_LDFLAGS) $(LDFLAGS) -o $@
-AM_V_CCLD = $(am__v_CCLD_$(V))
-am__v_CCLD_ = $(am__v_CCLD_$(AM_DEFAULT_VERBOSITY))
+AM_V_CCLD = $(am__v_CCLD_@AM_V@)
+am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
 am__v_CCLD_0 = @echo "  CCLD  " $@;
-AM_V_GEN = $(am__v_GEN_$(V))
-am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY))
+AM_V_GEN = $(am__v_GEN_@AM_V@)
+am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
 am__v_GEN_0 = @echo "  GEN   " $@;
 SOURCES = $(liblegacy_i810_la_SOURCES)
 DIST_SOURCES = $(am__liblegacy_i810_la_SOURCES_DIST)
@@ -106,6 +129,11 @@ RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \
        install-pdf-recursive install-ps-recursive install-recursive \
        installcheck-recursive installdirs-recursive pdf-recursive \
        ps-recursive uninstall-recursive
+am__can_run_installinfo = \
+  case $$AM_UPDATE_INFO_DIR in \
+    n|no|NO) false;; \
+    *) (install-info --version) >/dev/null 2>&1;; \
+  esac
 RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive        \
   distclean-recursive maintainer-clean-recursive
 AM_RECURSIVE_TARGETS = $(RECURSIVE_TARGETS:-recursive=) \
@@ -152,6 +180,7 @@ AUTOCONF = @AUTOCONF@
 AUTOHEADER = @AUTOHEADER@
 AUTOMAKE = @AUTOMAKE@
 AWK = @AWK@
+BASE_CFLAGS = @BASE_CFLAGS@
 CC = @CC@
 CCDEPMODE = @CCDEPMODE@
 CFLAGS = @CFLAGS@
@@ -162,11 +191,16 @@ CWARNFLAGS = @CWARNFLAGS@
 CYGPATH_W = @CYGPATH_W@
 DEFS = @DEFS@
 DEPDIR = @DEPDIR@
+DLLTOOL = @DLLTOOL@
+DRI2_CFLAGS = @DRI2_CFLAGS@
+DRI2_LIBS = @DRI2_LIBS@
 DRIVER_MAN_DIR = @DRIVER_MAN_DIR@
 DRIVER_MAN_SUFFIX = @DRIVER_MAN_SUFFIX@
 DRIVER_NAME = @DRIVER_NAME@
 DRI_CFLAGS = @DRI_CFLAGS@
 DRI_LIBS = @DRI_LIBS@
+DRMINTEL_CFLAGS = @DRMINTEL_CFLAGS@
+DRMINTEL_LIBS = @DRMINTEL_LIBS@
 DRM_CFLAGS = @DRM_CFLAGS@
 DRM_LIBS = @DRM_LIBS@
 DSYMUTIL = @DSYMUTIL@
@@ -190,6 +224,10 @@ INSTALL_SCRIPT = @INSTALL_SCRIPT@
 INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
 LD = @LD@
 LDFLAGS = @LDFLAGS@
+LIBGLAMOR_CFLAGS = @LIBGLAMOR_CFLAGS@
+LIBGLAMOR_EGL_CFLAGS = @LIBGLAMOR_EGL_CFLAGS@
+LIBGLAMOR_EGL_LIBS = @LIBGLAMOR_EGL_LIBS@
+LIBGLAMOR_LIBS = @LIBGLAMOR_LIBS@
 LIBOBJS = @LIBOBJS@
 LIBS = @LIBS@
 LIBTOOL = @LIBTOOL@
@@ -200,6 +238,7 @@ LN_S = @LN_S@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MANIFEST_TOOL = @MANIFEST_TOOL@
 MAN_SUBSTS = @MAN_SUBSTS@
 MISC_MAN_DIR = @MISC_MAN_DIR@
 MISC_MAN_SUFFIX = @MISC_MAN_SUFFIX@
@@ -227,10 +266,15 @@ RANLIB = @RANLIB@
 SED = @SED@
 SET_MAKE = @SET_MAKE@
 SHELL = @SHELL@
+STRICT_CFLAGS = @STRICT_CFLAGS@
 STRIP = @STRIP@
 UDEV_CFLAGS = @UDEV_CFLAGS@
 UDEV_LIBS = @UDEV_LIBS@
+VALGRIND_CFLAGS = @VALGRIND_CFLAGS@
+VALGRIND_LIBS = @VALGRIND_LIBS@
 VERSION = @VERSION@
+X11_CFLAGS = @X11_CFLAGS@
+X11_LIBS = @X11_LIBS@
 XORG_CFLAGS = @XORG_CFLAGS@
 XORG_LIBS = @XORG_LIBS@
 XORG_MAN_PAGE = @XORG_MAN_PAGE@
@@ -240,6 +284,7 @@ abs_builddir = @abs_builddir@
 abs_srcdir = @abs_srcdir@
 abs_top_builddir = @abs_top_builddir@
 abs_top_srcdir = @abs_top_srcdir@
+ac_ct_AR = @ac_ct_AR@
 ac_ct_CC = @ac_ct_CC@
 ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
 am__include = @am__include@
@@ -272,7 +317,6 @@ libdir = @libdir@
 libexecdir = @libexecdir@
 localedir = @localedir@
 localstatedir = @localstatedir@
-lt_ECHO = @lt_ECHO@
 mandir = @mandir@
 mkdir_p = @mkdir_p@
 moduledir = @moduledir@
@@ -297,9 +341,9 @@ AM_CFLAGS = @CWARNFLAGS@ @XORG_CFLAGS@ @DRM_CFLAGS@ @DRI_CFLAGS@ @PCIACCESS_CFLA
            $(NULL)
 
 liblegacy_i810_la_SOURCES = i810_accel.c i810_common.h i810_cursor.c \
-       i810_dga.c i810_driver.c i810.h i810_io.c i810_memory.c \
-       i810_reg.h i810_ring.h i810_video.c i810_wmark.c \
-       $(am__append_1) $(am__append_2)
+       i810_driver.c i810.h i810_memory.c i810_reg.h i810_ring.h \
+       i810_video.c i810_wmark.c $(am__append_1) $(am__append_2) \
+       $(am__append_3) $(am__append_4)
 all: all-recursive
 
 .SUFFIXES:
@@ -343,7 +387,7 @@ clean-noinstLTLIBRARIES:
          echo "rm -f \"$${dir}/so_locations\""; \
          rm -f "$${dir}/so_locations"; \
        done
-liblegacy-i810.la: $(liblegacy_i810_la_OBJECTS) $(liblegacy_i810_la_DEPENDENCIES) 
+liblegacy-i810.la: $(liblegacy_i810_la_OBJECTS) $(liblegacy_i810_la_DEPENDENCIES) $(EXTRA_liblegacy_i810_la_DEPENDENCIES) 
        $(AM_V_CCLD)$(LINK)  $(liblegacy_i810_la_OBJECTS) $(liblegacy_i810_la_LIBADD) $(LIBS)
 
 mostlyclean-compile:
@@ -358,34 +402,31 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/i810_dri.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/i810_driver.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/i810_hwmc.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/i810_io.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/i810_memory.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/i810_video.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/i810_wmark.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/i810_xaa.Plo@am__quote@
 
 .c.o:
 @am__fastdepCC_TRUE@   $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
 @am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
-@am__fastdepCC_FALSE@  $(AM_V_CC) @AM_BACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@  $(COMPILE) -c $<
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(COMPILE) -c $<
 
 .c.obj:
 @am__fastdepCC_TRUE@   $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
 @am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
-@am__fastdepCC_FALSE@  $(AM_V_CC) @AM_BACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@  $(COMPILE) -c `$(CYGPATH_W) '$<'`
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(COMPILE) -c `$(CYGPATH_W) '$<'`
 
 .c.lo:
 @am__fastdepCC_TRUE@   $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
 @am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
-@am__fastdepCC_FALSE@  $(AM_V_CC) @AM_BACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@  $(LTCOMPILE) -c -o $@ $<
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $<
 
 mostlyclean-libtool:
        -rm -f *.lo
@@ -560,13 +601,10 @@ distdir: $(DISTFILES)
        done
        @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
          if test "$$subdir" = .; then :; else \
-           test -d "$(distdir)/$$subdir" \
-           || $(MKDIR_P) "$(distdir)/$$subdir" \
-           || exit 1; \
-         fi; \
-       done
-       @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
-         if test "$$subdir" = .; then :; else \
+           $(am__make_dryrun) \
+             || test -d "$(distdir)/$$subdir" \
+             || $(MKDIR_P) "$(distdir)/$$subdir" \
+             || exit 1; \
            dir1=$$subdir; dir2="$(distdir)/$$subdir"; \
            $(am__relativize); \
            new_distdir=$$reldir; \
@@ -601,10 +639,15 @@ install-am: all-am
 
 installcheck: installcheck-recursive
 install-strip:
-       $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
-         install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
-         `test -z '$(STRIP)' || \
-           echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+       if test -z '$(STRIP)'; then \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+             install; \
+       else \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+           "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+       fi
 mostlyclean-generic:
 
 clean-generic:
index 6620695..de250ab 100644 (file)
@@ -40,10 +40,11 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 #include <stdint.h>
 #include "compiler.h"
-#include "xf86PciInfo.h"
 #include "xf86Pci.h"
 #include "i810_reg.h"
+#ifdef HAVE_XAA_H
 #include "xaa.h"
+#endif
 #include "xf86Cursor.h"
 #include "xf86xv.h"
 #include "vbe.h"
@@ -52,7 +53,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "xorg-server.h"
 #include <pciaccess.h>
 
-#ifdef XF86DRI
+#include "compat-api.h"
+#ifdef HAVE_DRI1
 #include "xf86drm.h"
 #include "sarea.h"
 #define _XF86DRI_SERVER_
@@ -74,14 +76,6 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 typedef struct _I810Rec *I810Ptr;
 
-typedef void (*I810WriteIndexedByteFunc)(I810Ptr pI810, IOADDRESS addr,
-                                        uint8_t index, uint8_t value);
-typedef uint8_t(*I810ReadIndexedByteFunc)(I810Ptr pI810, IOADDRESS addr,
-                                         uint8_t index);
-typedef void (*I810WriteByteFunc)(I810Ptr pI810, IOADDRESS addr,
-                                 uint8_t value);
-typedef uint8_t(*I810ReadByteFunc)(I810Ptr pI810, IOADDRESS addr);
-
 extern void I810SetTiledMemory(ScrnInfoPtr pScrn, int nr, unsigned start,
                               unsigned pitch, unsigned size);
 
@@ -178,7 +172,6 @@ typedef struct _I810Rec {
    int Chipset;
    unsigned long LinearAddr;
    unsigned long MMIOAddr;
-   IOADDRESS ioBase;
    EntityInfoPtr pEnt;
    struct pci_device *PciInfo;
 
@@ -211,20 +204,17 @@ typedef struct _I810Rec {
    I810RegRec SavedReg;
    I810RegRec ModeReg;
 
+#ifdef HAVE_XAA_H
    XAAInfoRecPtr AccelInfoRec;
+#endif
    xf86CursorInfoPtr CursorInfoRec;
    CloseScreenProcPtr CloseScreen;
    ScreenBlockHandlerProcPtr BlockHandler;
 
-   I810WriteIndexedByteFunc writeControl;
-   I810ReadIndexedByteFunc readControl;
-   I810WriteByteFunc writeStandard;
-   I810ReadByteFunc readStandard;
-
    Bool directRenderingDisabled;        /* DRI disabled in PreInit */
    Bool directRenderingEnabled;                /* false if XF86DRI not defined. */
 
-#ifdef XF86DRI
+#ifdef HAVE_DRI1
    int LockHeld;
    DRIInfoPtr pDRIInfo;
    int drmSubFD;
@@ -263,7 +253,7 @@ typedef struct _I810Rec {
 #define I810_SELECT_BACK       1
 #define I810_SELECT_DEPTH      2
 
-#ifdef XF86DRI
+#ifdef HAVE_DRI1
 extern Bool I810DRIScreenInit(ScreenPtr pScreen);
 extern void I810DRICloseScreen(ScreenPtr pScreen);
 extern Bool I810DRIFinishScreenInit(ScreenPtr pScreen);
@@ -277,7 +267,11 @@ extern Bool I810CleanupDma(ScrnInfoPtr pScrn);
 #define I810REGPTR(p) (&(I810PTR(p)->ModeReg))
 
 extern Bool I810CursorInit(ScreenPtr pScreen);
+#ifdef HAVE_XAA_H
 extern Bool I810AccelInit(ScreenPtr pScreen);
+#else
+static inline  Bool I810AccelInit(ScreenPtr pScreen) { return TRUE; }
+#endif
 extern void I810SetPIOAccess(I810Ptr pI810);
 extern void I810SetMMIOAccess(I810Ptr pI810);
 extern unsigned int I810CalcWatermark(ScrnInfoPtr pScrn, double freq,
@@ -301,8 +295,8 @@ extern Bool I810UnbindGARTMemory(ScrnInfoPtr pScrn);
 
 extern int I810CheckAvailableMemory(ScrnInfoPtr pScrn);
 
-extern Bool I810SwitchMode(int scrnIndex, DisplayModePtr mode, int flags);
-extern void I810AdjustFrame(int scrnIndex, int x, int y, int flags);
+extern Bool I810SwitchMode(SWITCH_MODE_ARGS_DECL);
+extern void I810AdjustFrame(ADJUST_FRAME_ARGS_DECL);
 
 extern void I810SetupForScreenToScreenCopy(ScrnInfoPtr pScrn, int xdir,
                                           int ydir, int rop,
@@ -320,7 +314,6 @@ extern void I810SelectBuffer(ScrnInfoPtr pScrn, int buffer);
 
 extern void I810RefreshRing(ScrnInfoPtr pScrn);
 extern void I810EmitFlush(ScrnInfoPtr pScrn);
-extern void I810EmitInvarientState(ScrnInfoPtr pScrn);
 
 extern Bool I810DGAInit(ScreenPtr pScreen);
 
@@ -329,4 +322,7 @@ extern void I810InitMC(ScreenPtr pScreen);
 
 extern const OptionInfoRec *I810AvailableOptions(int chipid, int busid);
 
+extern const int I810CopyROP[16];
+const int I810PatternROP[16];
+
 #endif /* _I810_H_ */
index 9aa3e42..aa2c4df 100644 (file)
@@ -40,136 +40,43 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "xaarop.h"
 #include "i810.h"
 
-static void I810SetupForMono8x8PatternFill(ScrnInfoPtr pScrn,
-                                          int pattx, int patty,
-                                          int fg, int bg, int rop,
-                                          unsigned int planemask);
-static void I810SubsequentMono8x8PatternFillRect(ScrnInfoPtr pScrn,
-                                                int pattx, int patty,
-                                                int x, int y, int w, int h);
-
-static void I810SetupForScanlineCPUToScreenColorExpandFill(ScrnInfoPtr pScrn,
-                                                          int fg, int bg,
-                                                          int rop,
-                                                          unsigned int mask);
-
-static void I810SubsequentScanlineCPUToScreenColorExpandFill(ScrnInfoPtr
-                                                            pScrn, int x,
-                                                            int y, int w,
-                                                            int h,
-                                                            int skipleft);
-
-static void I810SubsequentColorExpandScanline(ScrnInfoPtr pScrn, int bufno);
-
-/* The following function sets up the supported acceleration. Call it
- * from the FbInit() function in the SVGA driver, or before ScreenInit
- * in a monolithic server.
- */
-Bool
-I810AccelInit(ScreenPtr pScreen)
-{
-   XAAInfoRecPtr infoPtr;
-   ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-   I810Ptr pI810 = I810PTR(pScrn);
-
-   if (I810_DEBUG & DEBUG_VERBOSE_ACCEL)
-      ErrorF("I810AccelInit\n");
-
-   pI810->AccelInfoRec = infoPtr = XAACreateInfoRec();
-   if (!infoPtr)
-      return FALSE;
-
-   pI810->bufferOffset = 0;
-   infoPtr->Flags = LINEAR_FRAMEBUFFER | OFFSCREEN_PIXMAPS;
-   infoPtr->Flags |= PIXMAP_CACHE;
-
-   /* Sync
-    */
-   infoPtr->Sync = I810Sync;
-
-   /* Solid filled rectangles 
-    */
-   {
-      infoPtr->SolidFillFlags = NO_PLANEMASK;
-      infoPtr->SetupForSolidFill = I810SetupForSolidFill;
-      infoPtr->SubsequentSolidFillRect = I810SubsequentSolidFillRect;
-   }
-
-   /* Screen to screen copy 
-    *   - the transparency op hangs the blit engine, disable for now.
-    */
-   {
-      infoPtr->ScreenToScreenCopyFlags = (0
-                                         | NO_PLANEMASK
-                                         | NO_TRANSPARENCY | 0);
-
-      infoPtr->SetupForScreenToScreenCopy = I810SetupForScreenToScreenCopy;
-      infoPtr->SubsequentScreenToScreenCopy =
-           I810SubsequentScreenToScreenCopy;
-   }
-
-   /* 8x8 pattern fills 
-    */
-   {
-      infoPtr->SetupForMono8x8PatternFill = I810SetupForMono8x8PatternFill;
-      infoPtr->SubsequentMono8x8PatternFillRect =
-           I810SubsequentMono8x8PatternFillRect;
-
-      infoPtr->Mono8x8PatternFillFlags = (HARDWARE_PATTERN_PROGRAMMED_BITS |
-                                         HARDWARE_PATTERN_SCREEN_ORIGIN |
-                                         BIT_ORDER_IN_BYTE_MSBFIRST |
-                                         NO_PLANEMASK | 0);
-   }
-
-   /* 8x8 color fills - not considered useful for XAA.
-    */
-
-   /* Scanline color expansion - Use the same scheme as the 3.3 driver.  
-    *
-    */
-   if (pI810->Scratch.Size != 0) {
-      int i;
-      int width = ALIGN(pScrn->displayWidth, 32) / 8;
-      int nr_buffers = pI810->Scratch.Size / width;
-      unsigned char *ptr = pI810->FbBase + pI810->Scratch.Start;
-
-      pI810->NumScanlineColorExpandBuffers = nr_buffers;
-      pI810->ScanlineColorExpandBuffers = (unsigned char **)
-           xnfcalloc(nr_buffers, sizeof(unsigned char *));
-
-      for (i = 0; i < nr_buffers; i++, ptr += width)
-        pI810->ScanlineColorExpandBuffers[i] = ptr;
-
-      infoPtr->ScanlineCPUToScreenColorExpandFillFlags = (NO_PLANEMASK |
-                                                         ROP_NEEDS_SOURCE |
-                                                         BIT_ORDER_IN_BYTE_MSBFIRST
-                                                         | 0);
-
-      infoPtr->ScanlineColorExpandBuffers = (unsigned char **)
-           xnfcalloc(1, sizeof(unsigned char *));
-      infoPtr->NumScanlineColorExpandBuffers = 1;
-
-      infoPtr->ScanlineColorExpandBuffers[0] =
-           pI810->ScanlineColorExpandBuffers[0];
-      pI810->nextColorExpandBuf = 0;
-
-      infoPtr->SetupForScanlineCPUToScreenColorExpandFill =
-           I810SetupForScanlineCPUToScreenColorExpandFill;
-
-      infoPtr->SubsequentScanlineCPUToScreenColorExpandFill =
-           I810SubsequentScanlineCPUToScreenColorExpandFill;
-
-      infoPtr->SubsequentColorExpandScanline =
-           I810SubsequentColorExpandScanline;
-   }
-
-   /* Possible todo: Image writes w/ non-GXCOPY rop.
-    */
-
-   I810SelectBuffer(pScrn, I810_SELECT_FRONT);
-
-   return XAAInit(pScreen, infoPtr);
-}
+const int I810CopyROP[16] = {
+       ROP_0,                  /* GXclear */
+       ROP_DSa,                /* GXand */
+       ROP_SDna,               /* GXandReverse */
+       ROP_S,                  /* GXcopy */
+       ROP_DSna,               /* GXandInverted */
+       ROP_D,                  /* GXnoop */
+       ROP_DSx,                /* GXxor */
+       ROP_DSo,                /* GXor */
+       ROP_DSon,               /* GXnor */
+       ROP_DSxn,               /* GXequiv */
+       ROP_Dn,                 /* GXinvert */
+       ROP_SDno,               /* GXorReverse */
+       ROP_Sn,                 /* GXcopyInverted */
+       ROP_DSno,               /* GXorInverted */
+       ROP_DSan,               /* GXnand */
+       ROP_1                   /* GXset */
+};
+
+const int I810PatternROP[16] = {
+       ROP_0,
+       ROP_DPa,
+       ROP_PDna,
+       ROP_P,
+       ROP_DPna,
+       ROP_D,
+       ROP_DPx,
+       ROP_DPo,
+       ROP_DPon,
+       ROP_PDxn,
+       ROP_Dn,
+       ROP_PDno,
+       ROP_Pn,
+       ROP_DPno,
+       ROP_DPan,
+       ROP_1
+};
 
 int
 I810WaitLpRing(ScrnInfoPtr pScrn, int n, int timeout_millis)
@@ -213,13 +120,15 @@ I810WaitLpRing(ScrnInfoPtr pScrn, int n, int timeout_millis)
                start);
         I810PrintErrorState(pScrn);
         ErrorF("space: %d wanted %d\n", ring->space, n);
-#ifdef XF86DRI
+#ifdef HAVE_DRI1
         if (pI810->directRenderingEnabled) {
-           DRIUnlock(screenInfo.screens[pScrn->scrnIndex]);
-           DRICloseScreen(screenInfo.screens[pScrn->scrnIndex]);
+           DRIUnlock(xf86ScrnToScreen(pScrn));
+           DRICloseScreen(xf86ScrnToScreen(pScrn));
         }
 #endif
+#if HAVE_XAA_H
         pI810->AccelInfoRec = NULL;    /* Stops recursive behavior */
+#endif
         FatalError("lockup\n");
       }
 
@@ -245,7 +154,7 @@ I810Sync(ScrnInfoPtr pScrn)
    if (I810_DEBUG & (DEBUG_VERBOSE_ACCEL | DEBUG_VERBOSE_SYNC))
       ErrorF("I810Sync\n");
 
-#ifdef XF86DRI
+#ifdef HAVE_DRI1
    /* VT switching tries to do this.  
     */
    if (!pI810->LockHeld && pI810->directRenderingEnabled) {
@@ -282,7 +191,7 @@ I810SetupForSolidFill(ScrnInfoPtr pScrn, int color, int rop,
 
    /* Color blit, p166 */
    pI810->BR[13] = (BR13_SOLID_PATTERN |
-                   (XAAGetPatternROP(rop) << 16) |
+                   (I810PatternROP[rop] << 16) |
                    (pScrn->displayWidth * pI810->cpp));
    pI810->BR[16] = color;
 }
@@ -328,7 +237,7 @@ I810SetupForScreenToScreenCopy(ScrnInfoPtr pScrn, int xdir, int ydir, int rop,
    if (xdir == -1)
       pI810->BR[13] |= BR13_RIGHT_TO_LEFT;
 
-   pI810->BR[13] |= XAAGetCopyROP(rop) << 16;
+   pI810->BR[13] |= I810CopyROP[rop] << 16;
 
    pI810->BR[18] = 0;
 }
@@ -399,145 +308,6 @@ I810SubsequentScreenToScreenCopy(ScrnInfoPtr pScrn, int x1, int y1,
     }  while (1);
 }
 
-static void
-I810SetupForMono8x8PatternFill(ScrnInfoPtr pScrn, int pattx, int patty,
-                              int fg, int bg, int rop,
-                              unsigned int planemask)
-{
-   I810Ptr pI810 = I810PTR(pScrn);
-
-   if (I810_DEBUG & DEBUG_VERBOSE_ACCEL)
-      ErrorF("I810SetupFor8x8PatternColorExpand\n");
-
-   /* FULL_MONO_PAT_BLT, p176 */
-   pI810->BR[0] = (BR00_BITBLT_CLIENT | BR00_OP_MONO_PAT_BLT | 0x9);
-   pI810->BR[18] = bg;
-   pI810->BR[19] = fg;
-   pI810->BR[13] = (pScrn->displayWidth * pI810->cpp);
-   pI810->BR[13] |= XAAGetPatternROP(rop) << 16;
-   if (bg == -1)
-      pI810->BR[13] |= BR13_MONO_PATN_TRANS;
-}
-
-static void
-I810SubsequentMono8x8PatternFillRect(ScrnInfoPtr pScrn, int pattx, int patty,
-                                    int x, int y, int w, int h)
-{
-   I810Ptr pI810 = I810PTR(pScrn);
-   int addr =
-        pI810->bufferOffset + (y * pScrn->displayWidth + x) * pI810->cpp;
-
-   if (I810_DEBUG & DEBUG_VERBOSE_ACCEL)
-      ErrorF("I810Subsequent8x8PatternColorExpand\n");
-
-   {
-      BEGIN_LP_RING(12);
-      OUT_RING(pI810->BR[0] | ((y << 5) & BR00_PAT_VERT_ALIGN));
-      OUT_RING(pI810->BR[13]);
-      OUT_RING((h << 16) | (w * pI810->cpp));
-      OUT_RING(addr);
-      OUT_RING(pI810->BR[13] & 0xFFFF);        /* src pitch */
-      OUT_RING(addr);                  /* src addr */
-      OUT_RING(0);                     /* transparency color */
-      OUT_RING(pI810->BR[18]);         /* bg */
-      OUT_RING(pI810->BR[19]);         /* fg */
-      OUT_RING(pattx);                 /* pattern data */
-      OUT_RING(patty);
-      OUT_RING(0);
-      ADVANCE_LP_RING();
-   }
-}
-
-static void
-I810GetNextScanlineColorExpandBuffer(ScrnInfoPtr pScrn)
-{
-   I810Ptr pI810 = I810PTR(pScrn);
-   XAAInfoRecPtr infoPtr = pI810->AccelInfoRec;
-
-   if (pI810->nextColorExpandBuf == pI810->NumScanlineColorExpandBuffers)
-      I810Sync(pScrn);
-
-   infoPtr->ScanlineColorExpandBuffers[0] =
-        pI810->ScanlineColorExpandBuffers[pI810->nextColorExpandBuf];
-
-   if (I810_DEBUG & DEBUG_VERBOSE_ACCEL)
-      ErrorF("using color expand buffer %d\n", pI810->nextColorExpandBuf);
-
-   pI810->nextColorExpandBuf++;
-}
-
-static void
-I810SetupForScanlineCPUToScreenColorExpandFill(ScrnInfoPtr pScrn,
-                                              int fg, int bg, int rop,
-                                              unsigned int planemask)
-{
-   I810Ptr pI810 = I810PTR(pScrn);
-
-   if (I810_DEBUG & DEBUG_VERBOSE_ACCEL)
-      ErrorF("I810SetupForScanlineScreenToScreenColorExpand %d %d %x %x\n",
-            fg, bg, rop, planemask);
-
-   pI810->BR[13] = (pScrn->displayWidth * pI810->cpp);
-   pI810->BR[13] |= XAAGetCopyROP(rop) << 16;
-   pI810->BR[13] |= (1 << 27);
-   if (bg == -1)
-      pI810->BR[13] |= BR13_MONO_TRANSPCY;
-
-   pI810->BR[18] = bg;
-   pI810->BR[19] = fg;
-
-   I810GetNextScanlineColorExpandBuffer(pScrn);
-}
-
-static void
-I810SubsequentScanlineCPUToScreenColorExpandFill(ScrnInfoPtr pScrn,
-                                                int x, int y,
-                                                int w, int h, int skipleft)
-{
-   I810Ptr pI810 = I810PTR(pScrn);
-
-   if (I810_DEBUG & DEBUG_VERBOSE_ACCEL)
-      ErrorF("I810SubsequentScanlineCPUToScreenColorExpandFill "
-            "%d,%d %dx%x %d\n", x, y, w, h, skipleft);
-
-   pI810->BR[0] = BR00_BITBLT_CLIENT | BR00_OP_MONO_SRC_COPY_BLT | 0x06;
-   pI810->BR[9] = (pI810->bufferOffset +
-                  (y * pScrn->displayWidth + x) * pI810->cpp);
-   pI810->BR[14] = ((1 << 16) | (w * pI810->cpp));
-   pI810->BR[11] = ((w + 31) / 32) - 1;
-}
-
-static void
-I810SubsequentColorExpandScanline(ScrnInfoPtr pScrn, int bufno)
-{
-   I810Ptr pI810 = I810PTR(pScrn);
-
-   pI810->BR[12] = (pI810->AccelInfoRec->ScanlineColorExpandBuffers[0] -
-                   pI810->FbBase);
-
-   if (I810_DEBUG & DEBUG_VERBOSE_ACCEL)
-      ErrorF("I810SubsequentColorExpandScanline %d (addr %x)\n",
-            bufno, pI810->BR[12]);
-
-   {
-      BEGIN_LP_RING(8);
-      OUT_RING(pI810->BR[0]);
-      OUT_RING(pI810->BR[13]);
-      OUT_RING(pI810->BR[14]);
-      OUT_RING(pI810->BR[9]);
-      OUT_RING(pI810->BR[11]);
-      OUT_RING(pI810->BR[12]);         /* srcaddr */
-      OUT_RING(pI810->BR[18]);
-      OUT_RING(pI810->BR[19]);
-      ADVANCE_LP_RING();
-   }
-
-   /* Advance to next scanline.
-    */
-   pI810->BR[9] += pScrn->displayWidth * pI810->cpp;
-   I810GetNextScanlineColorExpandBuffer(pScrn);
-}
-
 void
 I810EmitFlush(ScrnInfoPtr pScrn)
 {
@@ -583,35 +353,8 @@ I810RefreshRing(ScrnInfoPtr pScrn)
    if (pI810->LpRing->space < 0)
       pI810->LpRing->space += pI810->LpRing->mem.Size;
 
+#if HAVE_XAA_H
    if (pI810->AccelInfoRec)
       pI810->AccelInfoRec->NeedToSync = TRUE;
+#endif
 }
-
-/* Emit on gaining VT?
- */
-void
-I810EmitInvarientState(ScrnInfoPtr pScrn)
-{
-   I810Ptr pI810 = I810PTR(pScrn);
-
-   BEGIN_LP_RING(10);
-
-   OUT_RING(INST_PARSER_CLIENT | INST_OP_FLUSH | INST_FLUSH_MAP_CACHE);
-   OUT_RING(GFX_CMD_CONTEXT_SEL | CS_UPDATE_USE | CS_USE_CTX0);
-   OUT_RING(INST_PARSER_CLIENT | INST_OP_FLUSH | INST_FLUSH_MAP_CACHE);
-   OUT_RING(0);
-
-   OUT_RING(GFX_OP_COLOR_CHROMA_KEY);
-   OUT_RING(CC1_UPDATE_KILL_WRITE |
-           CC1_DISABLE_KILL_WRITE |
-           CC1_UPDATE_COLOR_IDX |
-           CC1_UPDATE_CHROMA_LOW | CC1_UPDATE_CHROMA_HI | 0);
-   OUT_RING(0);
-   OUT_RING(0);
-
-/*     OUT_RING( CMD_OP_Z_BUFFER_INFO ); */
-/*     OUT_RING( pI810->DepthBuffer.Start | pI810->auxPitchBits); */
-
-   ADVANCE_LP_RING();
-}
-
index 14b2993..efa2a7d 100644 (file)
@@ -77,7 +77,7 @@ static inline void memcpy_volatile(volatile void *dst, const void *src,
     int i;
     
     for (i = 0; i < len; i++)
-       ((volatile char *)dst)[i] = ((volatile char *)src)[i];
+       ((volatile char *)dst)[i] = ((const volatile char *)src)[i];
 }
 
 /* Memory mapped register access macros */
index 898a136..580fe4b 100644 (file)
@@ -63,7 +63,7 @@ I810CursorInit(ScreenPtr pScreen)
    I810Ptr pI810;
    xf86CursorInfoPtr infoPtr;
 
-   pScrn = xf86Screens[pScreen->myNum];
+   pScrn = xf86ScreenToScrn(pScreen);
    pI810 = I810PTR(pScrn);
    pI810->CursorInfoRec = infoPtr = xf86CreateCursorInfoRec();
    if (!infoPtr)
@@ -101,7 +101,7 @@ I810CursorInit(ScreenPtr pScreen)
 
 static Bool I810UseHWCursorARGB (ScreenPtr pScreen, CursorPtr pCurs)
 {
-   ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+   ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
    I810Ptr pI810 = I810PTR(pScrn);
 
    if (!pI810->CursorARGBPhysical)
@@ -144,7 +144,7 @@ static void I810LoadCursorARGB (ScrnInfoPtr pScrn, CursorPtr pCurs)
 static Bool
 I810UseHWCursor(ScreenPtr pScreen, CursorPtr pCurs)
 {
-   ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+   ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
    I810Ptr pI810 = I810PTR(pScrn);
 
    if (!pI810->CursorPhysical)
@@ -239,26 +239,29 @@ I810SetCursorColors(ScrnInfoPtr pScrn, int bg, int fg)
 {
    int tmp;
    I810Ptr pI810 = I810PTR(pScrn);
+   vgaHWPtr hwp;
 
 #ifdef ARGB_CURSOR
    if (pI810->CursorIsARGB)
       return;
 #endif
 
+   hwp = VGAHWPTR(pScrn);
+
    tmp = INREG8(PIXPIPE_CONFIG_0);
    tmp |= EXTENDED_PALETTE;
    OUTREG8(PIXPIPE_CONFIG_0, tmp);
 
-   pI810->writeStandard(pI810, DACMASK, 0xFF);
-   pI810->writeStandard(pI810, DACWX, 0x04);
+   hwp->writeDacMask(hwp, 0xFF);
+   hwp->writeDacWriteAddr(hwp, 0x04);
 
-   pI810->writeStandard(pI810, DACDATA, (bg & 0x00FF0000) >> 16);
-   pI810->writeStandard(pI810, DACDATA, (bg & 0x0000FF00) >> 8);
-   pI810->writeStandard(pI810, DACDATA, (bg & 0x000000FF));
+   hwp->writeDacData(hwp, (bg & 0x00FF0000) >> 16);
+   hwp->writeDacData(hwp, (bg & 0x0000FF00) >> 8);
+   hwp->writeDacData(hwp, (bg & 0x000000FF));
 
-   pI810->writeStandard(pI810, DACDATA, (fg & 0x00FF0000) >> 16);
-   pI810->writeStandard(pI810, DACDATA, (fg & 0x0000FF00) >> 8);
-   pI810->writeStandard(pI810, DACDATA, (fg & 0x000000FF));
+   hwp->writeDacData(hwp, (fg & 0x00FF0000) >> 16);
+   hwp->writeDacData(hwp, (fg & 0x0000FF00) >> 8);
+   hwp->writeDacData(hwp, (fg & 0x000000FF));
 
    tmp = INREG8(PIXPIPE_CONFIG_0);
    tmp &= ~EXTENDED_PALETTE;
index d9ddda0..81e1767 100644 (file)
@@ -29,9 +29,6 @@
 #include "xf86.h"
 #include "xf86_OSproc.h"
 #include "xf86Pci.h"
-#include "xf86PciInfo.h"
-#include "xaa.h"
-#include "xaalocal.h"
 #include "i810.h"
 #include "i810_reg.h"
 #include "dgaproc.h"
 static Bool I810_OpenFramebuffer(ScrnInfoPtr, char **, unsigned char **,
                                 int *, int *, int *);
 static Bool I810_SetMode(ScrnInfoPtr, DGAModePtr);
-static void I810_Sync(ScrnInfoPtr);
 static int I810_GetViewport(ScrnInfoPtr);
 static void I810_SetViewport(ScrnInfoPtr, int, int, int);
+
+#ifdef HAVE_XAA_H
+static void I810_Sync(ScrnInfoPtr);
 static void I810_FillRect(ScrnInfoPtr, int, int, int, int, unsigned long);
 static void I810_BlitRect(ScrnInfoPtr, int, int, int, int, int, int);
+#endif
 
 #if 0
 static void I810_BlitTransRect(ScrnInfoPtr, int, int, int, int, int, int,
@@ -58,9 +58,15 @@ DGAFunctionRec I810DGAFuncs = {
    I810_SetMode,
    I810_SetViewport,
    I810_GetViewport,
+#ifdef HAVE_XAA_H
    I810_Sync,
    I810_FillRect,
    I810_BlitRect,
+#else
+   NULL,
+   NULL,
+   NULL,
+#endif
 #if 0
    I810_BlitTransRect
 #else
@@ -71,7 +77,7 @@ DGAFunctionRec I810DGAFuncs = {
 Bool
 I810DGAInit(ScreenPtr pScreen)
 {
-   ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+   ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
    I810Ptr pI810 = I810PTR(pScrn);
    DGAModePtr modes = NULL, newmodes = NULL, currentMode;
    DisplayModePtr pMode, firstMode;
@@ -149,8 +155,8 @@ I810_SetMode(ScrnInfoPtr pScrn, DGAModePtr pMode)
    if (!pMode) {                       /* restore the original mode */
       if (pI810->DGAactive) {
         pScrn->currentMode = I810SavedDGAModes[index];
-        pScrn->SwitchMode(index, pScrn->currentMode, 0);
-        pScrn->AdjustFrame(index, 0, 0, 0);
+        pScrn->SwitchMode(SWITCH_MODE_ARGS(pScrn, pScrn->currentMode));
+        pScrn->AdjustFrame(ADJUST_FRAME_ARGS(pScrn, 0, 0));
         pI810->DGAactive = FALSE;
       }
    } else {
@@ -158,8 +164,7 @@ I810_SetMode(ScrnInfoPtr pScrn, DGAModePtr pMode)
         I810SavedDGAModes[index] = pScrn->currentMode;
         pI810->DGAactive = TRUE;
       }
-
-      pScrn->SwitchMode(index, pMode->mode, 0);
+      pScrn->SwitchMode(SWITCH_MODE_ARGS(pScrn, pMode->mode));
    }
 
    return TRUE;
@@ -179,7 +184,7 @@ I810_SetViewport(ScrnInfoPtr pScrn, int x, int y, int flags)
    I810Ptr pI810 = I810PTR(pScrn);
    vgaHWPtr hwp = VGAHWPTR(pScrn);
 
-   pScrn->AdjustFrame(pScrn->pScreen->myNum, x, y, flags);
+   pScrn->AdjustFrame(ADJUST_FRAME_ARGS(pScrn, x, y));
 
    /* wait for retrace */
    while ((hwp->readST01(hwp) & 0x08)) ;
@@ -188,6 +193,7 @@ I810_SetViewport(ScrnInfoPtr pScrn, int x, int y, int flags)
    pI810->DGAViewportStatus = 0;
 }
 
+#ifdef HAVE_XAA_H
 static void
 I810_FillRect(ScrnInfoPtr pScrn,
              int x, int y, int w, int h, unsigned long color)
@@ -228,6 +234,7 @@ I810_BlitRect(ScrnInfoPtr pScrn,
       SET_SYNC_FLAG(pI810->AccelInfoRec);
    }
 }
+#endif
 
 #if 0
 static void
index 509c141..3bdb2ce 100644 (file)
@@ -9,9 +9,7 @@
 
 #include "xf86.h"
 #include "xf86_OSproc.h"
-#include "xf86Priv.h"
 
-#include "xf86PciInfo.h"
 #include "xf86Pci.h"
 
 #include "windowstr.h"
@@ -157,7 +155,7 @@ mylog2(unsigned int n)
 Bool
 I810DRIScreenInit(ScreenPtr pScreen)
 {
-   ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+   ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
    I810Ptr pI810 = I810PTR(pScrn);
    DRIInfoPtr pDRIInfo;
    I810DRIPtr pI810DRI;
@@ -242,10 +240,16 @@ I810DRIScreenInit(ScreenPtr pScreen)
       pDRIInfo->busIdString = DRICreatePCIBusID(pI810->PciInfo);
    } else {
       pDRIInfo->busIdString = malloc(64);
-      sprintf(pDRIInfo->busIdString, "PCI:%d:%d:%d",
-             ((pI810->PciInfo->domain << 8) | pI810->PciInfo->bus),
-             pI810->PciInfo->dev, pI810->PciInfo->func
-             );
+      if (pDRIInfo->busIdString)
+        sprintf(pDRIInfo->busIdString, "PCI:%d:%d:%d",
+                ((pI810->PciInfo->domain << 8) | pI810->PciInfo->bus),
+                pI810->PciInfo->dev, pI810->PciInfo->func
+               );
+   }
+   if (!pDRIInfo->busIdString) {
+      DRIDestroyInfoRec(pI810->pDRIInfo);
+      pI810->pDRIInfo = NULL;
+      return FALSE;
    }
    pDRIInfo->ddxDriverMajorVersion = I810_MAJOR_VERSION;
    pDRIInfo->ddxDriverMinorVersion = I810_MINOR_VERSION;
@@ -375,7 +379,7 @@ I810DRIScreenInit(ScreenPtr pScreen)
 
    pI810DRI->regsSize = I810_REG_SIZE;
    if (drmAddMap(pI810->drmSubFD, (drm_handle_t) pI810->MMIOAddr,
-                pI810DRI->regsSize, DRM_REGISTERS, 0, 
+                pI810DRI->regsSize, DRM_REGISTERS, 0,
                 (drmAddress) &pI810DRI->regs) < 0) {
       xf86DrvMsg(pScreen->myNum, X_ERROR, "[drm] drmAddMap(regs) failed\n");
       DRICloseScreen(pScreen);
@@ -417,7 +421,7 @@ I810DRIScreenInit(ScreenPtr pScreen)
     * under the DRI.
     */
 
-   drmAgpAlloc(pI810->drmSubFD, 4096 * 1024, 1, NULL, 
+   drmAgpAlloc(pI810->drmSubFD, 4096 * 1024, 1, NULL,
               (drmAddress) &dcacheHandle);
    pI810->dcacheHandle = dcacheHandle;
 
@@ -503,7 +507,7 @@ I810DRIScreenInit(ScreenPtr pScreen)
                 "[agp] GART: no dcache memory found\n");
    }
 
-   drmAgpAlloc(pI810->drmSubFD, back_size, 0, NULL, 
+   drmAgpAlloc(pI810->drmSubFD, back_size, 0, NULL,
               (drmAddress) &agpHandle);
    pI810->backHandle = agpHandle;
 
@@ -560,10 +564,10 @@ I810DRIScreenInit(ScreenPtr pScreen)
    /* Now allocate and bind the agp space.  This memory will include the
     * regular framebuffer as well as texture memory.
     */
-   drmAgpAlloc(pI810->drmSubFD, sysmem_size, 0, NULL, 
+   drmAgpAlloc(pI810->drmSubFD, sysmem_size, 0, NULL,
               (drmAddress)&agpHandle);
    pI810->sysmemHandle = agpHandle;
-   
+
    if (agpHandle != DRM_AGP_NO_HANDLE) {
       if (drmAgpBind(pI810->drmSubFD, agpHandle, 0) == 0) {
        xf86DrvMsg(pScrn->scrnIndex, X_INFO,
@@ -606,7 +610,7 @@ I810DRIScreenInit(ScreenPtr pScreen)
       }
       drmAgpAlloc(pI810->drmSubFD, pI810->MC.Size, 0, NULL,
                  (drmAddress) &agpHandle);
-      
+
       pI810->xvmcHandle = agpHandle;
 
       if (agpHandle != DRM_AGP_NO_HANDLE) {
@@ -630,7 +634,7 @@ I810DRIScreenInit(ScreenPtr pScreen)
    }
 
    drmAgpAlloc(pI810->drmSubFD, 4096, 2,
-              (unsigned long *)&pI810->CursorPhysical, 
+              (unsigned long *)&pI810->CursorPhysical,
               (drmAddress) &agpHandle);
 
    pI810->cursorHandle = agpHandle;
@@ -661,9 +665,7 @@ I810DRIScreenInit(ScreenPtr pScreen)
    pI810->cursorARGBHandle = agpHandle;
 
    if (agpHandle != DRM_AGP_NO_HANDLE) {
-       int r;
-
-      if ((r = drmAgpBind(pI810->drmSubFD, agpHandle, tom)) == 0) {
+      if (drmAgpBind(pI810->drmSubFD, agpHandle, tom) == 0) {
         xf86DrvMsg(pScrn->scrnIndex, X_INFO,
                    "[agp] GART: Allocated 16K for ARGB mouse cursor image\n");
         pI810->CursorARGBStart = tom;
@@ -785,7 +787,7 @@ I810DRIScreenInit(ScreenPtr pScreen)
    pI810DRI->agp_buf_size = pI810->BufferMem.Size;
 
    if (drmAddMap(pI810->drmSubFD, (drm_handle_t) pI810->LpRing->mem.Start,
-                pI810->LpRing->mem.Size, DRM_AGP, 0, 
+                pI810->LpRing->mem.Size, DRM_AGP, 0,
                 (drmAddress) &pI810->ring_map) < 0) {
       xf86DrvMsg(pScreen->myNum, X_ERROR,
                 "[drm] drmAddMap(ring_map) failed.  Disabling DRI.\n");
@@ -811,10 +813,15 @@ I810DRIScreenInit(ScreenPtr pScreen)
       return FALSE;
    }
 
-   I810AllocLow(&(pI810->TexMem), &(pI810->SysMem), pI810DRI->textureSize);
+   if (!I810AllocLow(&(pI810->TexMem), &(pI810->SysMem), pI810DRI->textureSize)) {
+      xf86DrvMsg(pScrn->scrnIndex, X_INFO,
+                "[agp] Texure memory allocation failed\n");
+      DRICloseScreen(pScreen);
+      return FALSE;
+   }
 
    if (drmAddMap(pI810->drmSubFD, (drm_handle_t) pI810->TexMem.Start,
-                pI810->TexMem.Size, DRM_AGP, 0, 
+                pI810->TexMem.Size, DRM_AGP, 0,
                 (drmAddress) &pI810DRI->textures) < 0) {
       xf86DrvMsg(pScreen->myNum, X_ERROR,
                 "[drm] drmAddMap(textures) failed.  Disabling DRI.\n");
@@ -893,32 +900,44 @@ I810DRIScreenInit(ScreenPtr pScreen)
 void
 I810DRICloseScreen(ScreenPtr pScreen)
 {
-   ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+   ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
    I810Ptr pI810 = I810PTR(pScrn);
-   I810DRIPtr pI810DRI = (I810DRIPtr) pI810->pDRIInfo->devPrivate;
 
-   if (pI810DRI->irq) {
-       drmCtlUninstHandler(pI810->drmSubFD);
-       pI810DRI->irq = 0;
-   }
+   if (pI810->pDRIInfo) {
+       I810DRIPtr pI810DRI = (I810DRIPtr) pI810->pDRIInfo->devPrivate;
 
-   I810CleanupDma(pScrn);
+       if (pI810DRI) {
+          if (pI810DRI->irq) {
+              drmCtlUninstHandler(pI810->drmSubFD);
+              pI810DRI->irq = 0;
+          }
+
+          free(pI810->pDRIInfo->devPrivate);
+          pI810->pDRIInfo->devPrivate = NULL;
+       }
+
+       I810CleanupDma(pScrn);
+
+       DRICloseScreen(pScreen);
+       DRIDestroyInfoRec(pI810->pDRIInfo);
+       pI810->pDRIInfo = NULL;
+   }
 
    if (pI810->dcacheHandle!=DRM_AGP_NO_HANDLE)
-      drmAgpFree(pI810->drmSubFD, pI810->dcacheHandle);
+       drmAgpFree(pI810->drmSubFD, pI810->dcacheHandle);
    if (pI810->backHandle!=DRM_AGP_NO_HANDLE)
-      drmAgpFree(pI810->drmSubFD, pI810->backHandle);
+       drmAgpFree(pI810->drmSubFD, pI810->backHandle);
    if (pI810->zHandle!=DRM_AGP_NO_HANDLE)
-      drmAgpFree(pI810->drmSubFD, pI810->zHandle);
+       drmAgpFree(pI810->drmSubFD, pI810->zHandle);
    if (pI810->cursorHandle!=DRM_AGP_NO_HANDLE)
-      drmAgpFree(pI810->drmSubFD, pI810->cursorHandle);
+       drmAgpFree(pI810->drmSubFD, pI810->cursorHandle);
    if (pI810->xvmcHandle!=DRM_AGP_NO_HANDLE)
-      drmAgpFree(pI810->drmSubFD, pI810->xvmcHandle);
+       drmAgpFree(pI810->drmSubFD, pI810->xvmcHandle);
    if (pI810->sysmemHandle!=DRM_AGP_NO_HANDLE)
-      drmAgpFree(pI810->drmSubFD, pI810->sysmemHandle);
+       drmAgpFree(pI810->drmSubFD, pI810->sysmemHandle);
 
    if (pI810->agpAcquired == TRUE)
-      drmAgpRelease(pI810->drmSubFD);
+       drmAgpRelease(pI810->drmSubFD);
 
    pI810->backHandle = DRM_AGP_NO_HANDLE;
    pI810->zHandle = DRM_AGP_NO_HANDLE;
@@ -927,17 +946,6 @@ I810DRICloseScreen(ScreenPtr pScreen)
    pI810->sysmemHandle = DRM_AGP_NO_HANDLE;
    pI810->agpAcquired = FALSE;
    pI810->dcacheHandle = DRM_AGP_NO_HANDLE;
-
-   DRICloseScreen(pScreen);
-
-   if (pI810->pDRIInfo) {
-      if (pI810->pDRIInfo->devPrivate) {
-        free(pI810->pDRIInfo->devPrivate);
-        pI810->pDRIInfo->devPrivate = NULL;
-      }
-      DRIDestroyInfoRec(pI810->pDRIInfo);
-      pI810->pDRIInfo = NULL;
-   }
 }
 
 static Bool
@@ -958,16 +966,16 @@ Bool
 I810DRIFinishScreenInit(ScreenPtr pScreen)
 {
    I810SAREARec *sPriv = (I810SAREARec *) DRIGetSAREAPrivate(pScreen);
-   ScrnInfoPtr        pScrn = xf86Screens[pScreen->myNum];
+   ScrnInfoPtr        pScrn = xf86ScreenToScrn(pScreen);
    I810Ptr info  = I810PTR(pScrn);
 
-   memset(sPriv, 0, sizeof(sPriv));
+   memset(sPriv, 0, sizeof(*sPriv));
 
    /* Have shadow run only while there is 3d active.
     */
    if (info->allowPageFlip && info->drmMinor >= 3) {
      ShadowFBInit( pScreen, I810DRIRefreshArea );
-   } 
+   }
    else
      info->allowPageFlip = 0;
    return DRIFinishScreenInit(pScreen);
@@ -978,7 +986,7 @@ I810DRISwapContext(ScreenPtr pScreen, DRISyncType syncType,
                   DRIContextType oldContextType, void *oldContext,
                   DRIContextType newContextType, void *newContext)
 {
-   ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+   ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
    I810Ptr pI810 = I810PTR(pScrn);
 
    if (syncType == DRI_3D_SYNC &&
@@ -1001,11 +1009,20 @@ I810DRISwapContext(ScreenPtr pScreen, DRISyncType syncType,
 }
 
 static void
+I810DRISetNeedSync(ScrnInfoPtr pScrn)
+{
+#ifdef HAVE_XAA_H
+   I810Ptr pI810 = I810PTR(pScrn);
+   if (pI810->AccelInfoRec)
+       pI810->AccelInfoRec->NeedToSync = TRUE;
+#endif
+}
+
+static void
 I810DRIInitBuffers(WindowPtr pWin, RegionPtr prgn, CARD32 index)
 {
    ScreenPtr pScreen = pWin->drawable.pScreen;
-   ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-   I810Ptr pI810 = I810PTR(pScrn);
+   ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
    BoxPtr pbox = REGION_RECTS(prgn);
    int nbox = REGION_NUM_RECTS(prgn);
 
@@ -1033,8 +1050,7 @@ I810DRIInitBuffers(WindowPtr pWin, RegionPtr prgn, CARD32 index)
    }
    I810SelectBuffer(pScrn, I810_SELECT_FRONT);
 
-   if (pI810->AccelInfoRec)
-       pI810->AccelInfoRec->NeedToSync = TRUE;
+   I810DRISetNeedSync(pScrn);
 }
 
 /* This routine is a modified form of XAADoBitBlt with the calls to
@@ -1049,8 +1065,7 @@ I810DRIMoveBuffers(WindowPtr pParent, DDXPointRec ptOldOrg,
                   RegionPtr prgnSrc, CARD32 index)
 {
    ScreenPtr pScreen = pParent->drawable.pScreen;
-   ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-   I810Ptr pI810 = I810PTR(pScrn);
+   ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
    BoxPtr pboxTmp, pboxNext, pboxBase;
    DDXPointPtr pptTmp, pptNew2 = NULL;
    int xdir, ydir;
@@ -1193,8 +1208,7 @@ I810DRIMoveBuffers(WindowPtr pParent, DDXPointRec ptOldOrg,
       free(pboxNew1);
    }
 
-   if (pI810->AccelInfoRec)
-       pI810->AccelInfoRec->NeedToSync = TRUE;
+   I810DRISetNeedSync(pScrn);
 }
 
 
@@ -1251,7 +1265,7 @@ static void I810DRIRefreshArea(ScrnInfoPtr pScrn, int num, BoxPtr pbox)
 
 static void I810EnablePageFlip(ScreenPtr pScreen)
 {
-    ScrnInfoPtr         pScrn      = xf86Screens[pScreen->myNum];
+    ScrnInfoPtr         pScrn      = xf86ScreenToScrn(pScreen);
     I810Ptr       pI810       = I810PTR(pScrn);
     I810SAREAPtr  pSAREAPriv = DRIGetSAREAPrivate(pScreen);
     int cpp=2;
@@ -1300,7 +1314,7 @@ static void I810DRITransitionMultiToSingle3d(ScreenPtr pScreen)
 
 static void I810DRITransitionTo3d(ScreenPtr pScreen)
 {
-    ScrnInfoPtr    pScrn = xf86Screens[pScreen->myNum];
+    ScrnInfoPtr    pScrn = xf86ScreenToScrn(pScreen);
     I810Ptr  pI810  = I810PTR(pScrn);
 
     I810EnablePageFlip(pScreen);
@@ -1309,7 +1323,7 @@ static void I810DRITransitionTo3d(ScreenPtr pScreen)
 
 static void I810DRITransitionTo2d(ScreenPtr pScreen)
 {
-    ScrnInfoPtr         pScrn      = xf86Screens[pScreen->myNum];
+    ScrnInfoPtr         pScrn      = xf86ScreenToScrn(pScreen);
     I810Ptr       pI810       = I810PTR(pScrn);
     I810SAREAPtr  pSAREAPriv = DRIGetSAREAPrivate(pScreen);
 
@@ -1410,5 +1424,7 @@ I810DRIEnter(ScrnInfoPtr pScrn)
                        pI810->CursorARGBStart) != 0)
            return FALSE;
    }
+
+   I810SelectBuffer(pScrn, I810_SELECT_FRONT);
    return TRUE;
 }
index 3637e25..9f684d2 100644 (file)
@@ -58,7 +58,6 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "xf86cmap.h"
 
 #include "compiler.h"
-#include "mibstore.h"
 #include "vgaHW.h"
 #include "mipointer.h"
 #include "micmap.h"
@@ -68,27 +67,27 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "xf86xv.h"
 #include <X11/extensions/Xv.h>
 #include "vbe.h"
+#include "xf86fbman.h"
 
 #include "i810.h"
 
-#ifdef XF86DRI
+#ifdef HAVE_DRI1
 #include "dri.h"
 #endif
 
 #include "../legacy.h"
 
 static Bool I810PreInit(ScrnInfoPtr pScrn, int flags);
-static Bool I810ScreenInit(int Index, ScreenPtr pScreen, int argc,
-                          char **argv);
-static Bool I810EnterVT(int scrnIndex, int flags);
-static void I810LeaveVT(int scrnIndex, int flags);
-static Bool I810CloseScreen(int scrnIndex, ScreenPtr pScreen);
+static Bool I810ScreenInit(SCREEN_INIT_ARGS_DECL);
+static Bool I810EnterVT(VT_FUNC_ARGS_DECL);
+static void I810LeaveVT(VT_FUNC_ARGS_DECL);
+static Bool I810CloseScreen(CLOSE_SCREEN_ARGS_DECL);
 static Bool I810SaveScreen(ScreenPtr pScreen, Bool unblank);
-static void I810FreeScreen(int scrnIndex, int flags);
+static void I810FreeScreen(FREE_SCREEN_ARGS_DECL);
 static void I810DisplayPowerManagementSet(ScrnInfoPtr pScrn,
                                          int PowerManagermentMode,
                                          int flags);
-static ModeStatus I810ValidMode(int scrnIndex, DisplayModePtr mode,
+static ModeStatus I810ValidMode(SCRN_ARG_TYPE arg, DisplayModePtr mode,
                                Bool verbose, int flags);
 
 typedef enum {
@@ -132,7 +131,7 @@ int I810_DEBUG = (0
       );
 #endif
 
-#ifdef XF86DRI
+#ifdef HAVE_DRI1
 static int i810_pitches[] = {
    512,
    1024,
@@ -142,8 +141,6 @@ static int i810_pitches[] = {
 };
 #endif
 
-int I830EntityIndex = -1;
-
 /*
  * I810GetRec and I810FreeRec --
  *
@@ -152,24 +149,24 @@ int I830EntityIndex = -1;
  *
  */
 static Bool
-I810GetRec(ScrnInfoPtr pScrn)
+I810GetRec(ScrnInfoPtr scrn)
 {
-   if (pScrn->driverPrivate)
+   if (((uintptr_t)scrn->driverPrivate & 1) == 0)
       return TRUE;
 
-   pScrn->driverPrivate = xnfcalloc(sizeof(I810Rec), 1);
+   scrn->driverPrivate = xnfcalloc(sizeof(I810Rec), 1);
    return TRUE;
 }
 
 static void
-I810FreeRec(ScrnInfoPtr pScrn)
+I810FreeRec(ScrnInfoPtr scrn)
 {
-   if (!pScrn)
+   if (!scrn)
       return;
-   if (!pScrn->driverPrivate)
+   if (!scrn->driverPrivate)
       return;
-   free(pScrn->driverPrivate);
-   pScrn->driverPrivate = NULL;
+   free(scrn->driverPrivate);
+   scrn->driverPrivate = NULL;
 }
 
 struct pci_device *
@@ -188,11 +185,11 @@ intel_host_bridge (void)
 }
 
 static void
-I810ProbeDDC(ScrnInfoPtr pScrn, int index)
+I810ProbeDDC(ScrnInfoPtr scrn, int index)
 {
    vbeInfoPtr pVbe;
 
-   if (xf86LoadSubModule(pScrn, "vbe")) {
+   if (xf86LoadSubModule(scrn, "vbe")) {
       pVbe = VBEInit(NULL, index);
       ConfiguredMonitor = vbeDoEDID(pVbe, NULL);
       vbeFree(pVbe);
@@ -200,24 +197,24 @@ I810ProbeDDC(ScrnInfoPtr pScrn, int index)
 }
 
 static xf86MonPtr
-I810DoDDC(ScrnInfoPtr pScrn, int index)
+I810DoDDC(ScrnInfoPtr scrn, int index)
 {
    vbeInfoPtr pVbe;
    xf86MonPtr MonInfo = NULL;
-   I810Ptr pI810 = I810PTR(pScrn);
+   I810Ptr pI810 = I810PTR(scrn);
 
    /* Honour Option "noDDC" */
    if (xf86ReturnOptValBool(pI810->Options, OPTION_NO_DDC, FALSE)) {
       return MonInfo;
    }
 
-   if (xf86LoadSubModule(pScrn, "vbe") && (pVbe = VBEInit(NULL, index))) {
+   if (xf86LoadSubModule(scrn, "vbe") && (pVbe = VBEInit(NULL, index))) {
       MonInfo = vbeDoEDID(pVbe, NULL);
       xf86PrintEDID(MonInfo);
-      xf86SetDDCproperties(pScrn, MonInfo);
+      xf86SetDDCproperties(scrn, MonInfo);
       vbeFree(pVbe);
    } else {
-      xf86DrvMsg(pScrn->scrnIndex, X_INFO,
+      xf86DrvMsg(scrn->scrnIndex, X_INFO,
                 "this driver cannot do DDC without VBE\n");
    }
 
@@ -232,9 +229,8 @@ I810DoDDC(ScrnInfoPtr pScrn, int index)
  *
  */
 static Bool
-I810PreInit(ScrnInfoPtr pScrn, int flags)
+I810PreInit(ScrnInfoPtr scrn, int flags)
 {
-   vgaHWPtr hwp;
    I810Ptr pI810;
    ClockRangePtr clockRanges;
    int i;
@@ -243,93 +239,90 @@ I810PreInit(ScrnInfoPtr pScrn, int flags)
    rgb defaultWeight = { 0, 0, 0 };
    int mem;
    Bool enable;
-   struct intel_chipset chipset;
 
-   if (pScrn->numEntities != 1)
+   if (scrn->numEntities != 1)
       return FALSE;
 
    /* Allocate driverPrivate */
-   if (!I810GetRec(pScrn))
+   if (!I810GetRec(scrn))
       return FALSE;
 
-   pI810 = I810PTR(pScrn);
+   pI810 = I810PTR(scrn);
 
-   pI810->pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
-   if (pI810->pEnt->location.type != BUS_PCI)
+   pI810->pEnt = xf86GetEntityInfo(scrn->entityList[0]);
+   if (pI810->pEnt == NULL || pI810->pEnt->location.type != BUS_PCI)
       return FALSE;
 
    if (flags & PROBE_DETECT) {
-      I810ProbeDDC(pScrn, pI810->pEnt->index);
+      I810ProbeDDC(scrn, pI810->pEnt->index);
       return TRUE;
    }
 
    /* The vgahw module should be loaded here when needed */
-   if (!xf86LoadSubModule(pScrn, "vgahw"))
+   if (!xf86LoadSubModule(scrn, "vgahw"))
       return FALSE;
 
    /* Allocate a vgaHWRec */
-   if (!vgaHWGetHWRec(pScrn))
+   if (!vgaHWGetHWRec(scrn))
       return FALSE;
-   hwp = VGAHWPTR(pScrn);
-   pI810->ioBase = hwp->PIOOffset;
 
    pI810->PciInfo = xf86GetPciInfoForEntity(pI810->pEnt->index);
 
-   /* Set pScrn->monitor */
-   pScrn->monitor = pScrn->confScreen->monitor;
+   /* Set scrn->monitor */
+   scrn->monitor = scrn->confScreen->monitor;
 
    flags24 = Support24bppFb | PreferConvert32to24 | SupportConvert32to24;
-   if (!xf86SetDepthBpp(pScrn, 16, 0, 16, flags24)) {
+   if (!xf86SetDepthBpp(scrn, 16, 0, 16, flags24)) {
       return FALSE;
    } else {
-      switch (pScrn->depth) {
+      switch (scrn->depth) {
       case 8:
       case 15:
       case 16:
       case 24:
         break;
       default:
-        xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+        xf86DrvMsg(scrn->scrnIndex, X_ERROR,
                    "Given depth (%d) is not supported by i810 driver\n",
-                   pScrn->depth);
+                   scrn->depth);
         return FALSE;
       }
    }
-   xf86PrintDepthBpp(pScrn);
+   xf86PrintDepthBpp(scrn);
 
-   switch (pScrn->bitsPerPixel) {
+   switch (scrn->bitsPerPixel) {
    case 8:
    case 16:
    case 24:
       break;
    default:
-      xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+      xf86DrvMsg(scrn->scrnIndex, X_ERROR,
                 "Given bpp (%d) is not supported by i810 driver\n",
-                pScrn->bitsPerPixel);
+                scrn->bitsPerPixel);
       return FALSE;
    }
 
-   if (!xf86SetWeight(pScrn, defaultWeight, defaultWeight))
+   if (!xf86SetWeight(scrn, defaultWeight, defaultWeight))
       return FALSE;
 
-   if (!xf86SetDefaultVisual(pScrn, -1))
+   if (!xf86SetDefaultVisual(scrn, -1))
       return FALSE;
 
    /* We use a programmable clock */
-   pScrn->progClock = TRUE;
+   scrn->progClock = TRUE;
 
-   pI810->cpp = pScrn->bitsPerPixel / 8;
+   pI810->cpp = scrn->bitsPerPixel / 8;
 
    /* Process the options */
-   xf86CollectOptions(pScrn, NULL);
+   xf86CollectOptions(scrn, NULL);
    if (!(pI810->Options = malloc(sizeof(I810Options))))
       return FALSE;
    memcpy(pI810->Options, I810Options, sizeof(I810Options));
-   xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, pI810->Options);
+   xf86ProcessOptions(scrn->scrnIndex, scrn->options, pI810->Options);
 
-   pScrn->rgbBits = 8;
+   scrn->rgbBits = 8;
    if (xf86ReturnOptValBool(pI810->Options, OPTION_DAC_6BIT, FALSE))
-      pScrn->rgbBits = 6;
+      scrn->rgbBits = 6;
 
    if (xf86ReturnOptValBool(pI810->Options, OPTION_SHOW_CACHE, FALSE))
      pI810->showCache = TRUE;
@@ -338,7 +331,7 @@ I810PreInit(ScrnInfoPtr pScrn, int flags)
 
    /* 6-BIT dac isn't reasonable for modes with > 8bpp */
    if (xf86ReturnOptValBool(pI810->Options, OPTION_DAC_6BIT, FALSE) &&
-       pScrn->bitsPerPixel > 8) {
+       scrn->bitsPerPixel > 8) {
       OptionInfoPtr ptr;
 
       ptr = xf86TokenToOptinfo(pI810->Options, OPTION_DAC_6BIT);
@@ -348,24 +341,16 @@ I810PreInit(ScrnInfoPtr pScrn, int flags)
    if (xf86ReturnOptValBool(pI810->Options, OPTION_NOACCEL, FALSE))
       pI810->noAccel = TRUE;
 
-   if (!pI810->noAccel) {
-      if (!xf86LoadSubModule(pScrn, "xaa")) {
-        I810FreeRec(pScrn);
-        return FALSE;
-      }
-   }
+   if (!pI810->noAccel && !xf86LoadSubModule(scrn, "xaa"))
+      pI810->noAccel = TRUE;
    
-#ifdef XF86DRI
+#ifdef HAVE_DRI1
    pI810->directRenderingDisabled =
      !xf86ReturnOptValBool(pI810->Options, OPTION_DRI, TRUE);
 
    if (!pI810->directRenderingDisabled) {
-     if (pI810->noAccel) {
-       xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "DRI is disabled because it "
-                 "needs 2D acceleration.\n");
-       pI810->directRenderingDisabled=TRUE;
-     } else if (pScrn->depth!=16) {
-       xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "DRI is disabled because it "
+     if (scrn->depth!=16) {
+       xf86DrvMsg(scrn->scrnIndex, X_WARNING, "DRI is disabled because it "
                  "runs only at 16-bit depth.\n");
        pI810->directRenderingDisabled=TRUE;
      }
@@ -376,52 +361,23 @@ I810PreInit(ScrnInfoPtr pScrn, int flags)
    /* after xf86ProcessOptions,
     * because it is controlled by options [no]vbe and [no]ddc
     */
-   I810DoDDC(pScrn, pI810->pEnt->index);
-
-   /* We have to use PIO to probe, because we haven't mapped yet */
-   I810SetPIOAccess(pI810);
-
-   intel_detect_chipset(pScrn, pI810->PciInfo, &chipset);
+   I810DoDDC(scrn, pI810->pEnt->index);
 
-   /*
-    * Set the Chipset and ChipRev, allowing config file entries to
-    * override.
-    */
-   if (pI810->pEnt->device->chipset && *pI810->pEnt->device->chipset) {
-      pScrn->chipset = pI810->pEnt->device->chipset;
-      from = X_CONFIG;
-   } else if (pI810->pEnt->device->chipID >= 0) {
-      pScrn->chipset = (char *)xf86TokenToString(intel_chipsets,
-                                                pI810->pEnt->device->chipID);
-      from = X_CONFIG;
-      xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "ChipID override: 0x%04X\n",
-                pI810->pEnt->device->chipID);
-   } else {
-      from = X_PROBED;
-      pScrn->chipset = (char *)xf86TokenToString(intel_chipsets,
-                                                DEVICE_ID(pI810->PciInfo));
-   }
-   if (pI810->pEnt->device->chipRev >= 0) {
-      xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "ChipRev override: %d\n",
-                pI810->pEnt->device->chipRev);
-   }
-
-   xf86DrvMsg(pScrn->scrnIndex, from, "Chipset: \"%s\"\n",
-             (pScrn->chipset != NULL) ? pScrn->chipset : "Unknown i810");
+   intel_detect_chipset(scrn, pI810->pEnt, pI810->PciInfo);
 
    pI810->LinearAddr = pI810->PciInfo->regions[0].base_addr;
-   xf86DrvMsg(pScrn->scrnIndex, from, "Linear framebuffer at 0x%lX\n",
+   xf86DrvMsg(scrn->scrnIndex, X_PROBED, "Linear framebuffer at 0x%lX\n",
              (unsigned long)pI810->LinearAddr);
 
    pI810->MMIOAddr = pI810->PciInfo->regions[1].base_addr;
-   xf86DrvMsg(pScrn->scrnIndex, from, "IO registers at addr 0x%lX\n",
+   xf86DrvMsg(scrn->scrnIndex, X_PROBED, "IO registers at addr 0x%lX\n",
              (unsigned long)pI810->MMIOAddr);
 
    /* AGP GART support is required.  Don't proceed any further if it isn't
     * present.
     */
    if (!xf86AgpGARTSupported()) {
-      xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+      xf86DrvMsg(scrn->scrnIndex, X_ERROR,
                 "AGP GART support is not available.  Make sure your kernel has\n"
                 "\tagpgart support or that the agpgart kernel module is loaded.\n");
       return FALSE;
@@ -448,40 +404,40 @@ I810PreInit(ScrnInfoPtr pScrn, int flags)
     *
     *  Changed to 8 Meg so we can have acceleration by default (Mark).
     */
-   mem = I810CheckAvailableMemory(pScrn);
+   mem = I810CheckAvailableMemory(scrn);
    if (pI810->directRenderingDisabled || mem < 131072)  /* < 128 MB */
-       pScrn->videoRam = 8192;
+       scrn->videoRam = 8192;
    else if (mem < 196608)
-       pScrn->videoRam = 16384;  /* < 192 MB */
+       scrn->videoRam = 16384;  /* < 192 MB */
    else
-       pScrn->videoRam = 24576;
+       scrn->videoRam = 24576;
    
    from = X_DEFAULT;
    
    if (pI810->pEnt->device->videoRam) {
-      pScrn->videoRam = pI810->pEnt->device->videoRam;
+      scrn->videoRam = pI810->pEnt->device->videoRam;
       from = X_CONFIG;
    }
 
-   if (mem > 0 && mem < pScrn->videoRam) {
-      xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "%dk of memory was requested,"
+   if (mem > 0 && mem < scrn->videoRam) {
+      xf86DrvMsg(scrn->scrnIndex, X_WARNING, "%dk of memory was requested,"
                 " but the\n\t maximum AGP memory available is %dk.\n",
-                pScrn->videoRam, mem);
+                scrn->videoRam, mem);
       from = X_PROBED;
       if (mem > (6 * 1024)) {
-        xf86DrvMsg(pScrn->scrnIndex, X_INFO,
+        xf86DrvMsg(scrn->scrnIndex, X_INFO,
                    "Reducing video memory to 4MB\n");
-        pScrn->videoRam = 4096;
+        scrn->videoRam = 4096;
       } else {
-        xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Less than 6MB of AGP memory"
+        xf86DrvMsg(scrn->scrnIndex, X_ERROR, "Less than 6MB of AGP memory"
                    " is available. Cannot proceed.\n");
-        I810FreeRec(pScrn);
+        I810FreeRec(scrn);
         return FALSE;
       }
    }
 
-   xf86DrvMsg(pScrn->scrnIndex, from,
-             "Will alloc AGP framebuffer: %d kByte\n", pScrn->videoRam);
+   xf86DrvMsg(scrn->scrnIndex, from,
+             "Will alloc AGP framebuffer: %d kByte\n", scrn->videoRam);
 
    /* Calculate Fixed Offsets depending on graphics aperture size */
    {
@@ -508,14 +464,14 @@ I810PreInit(ScrnInfoPtr pScrn, int flags)
    {
       Gamma zeros = { 0.0, 0.0, 0.0 };
 
-      if (!xf86SetGamma(pScrn, zeros)) {
+      if (!xf86SetGamma(scrn, zeros)) {
         return FALSE;
       }
    }
 
    pI810->MaxClock = 0;
    if (pI810->pEnt->device->dacSpeeds[0]) {
-      switch (pScrn->bitsPerPixel) {
+      switch (scrn->bitsPerPixel) {
       case 8:
         pI810->MaxClock = pI810->pEnt->device->dacSpeeds[DAC_BPP8];
         break;
@@ -532,7 +488,7 @@ I810PreInit(ScrnInfoPtr pScrn, int flags)
       if (!pI810->MaxClock)
         pI810->MaxClock = pI810->pEnt->device->dacSpeeds[0];
    } else {
-      switch (pScrn->bitsPerPixel) {
+      switch (scrn->bitsPerPixel) {
       case 8:
         pI810->MaxClock = 203000;
         break;
@@ -555,77 +511,77 @@ I810PreInit(ScrnInfoPtr pScrn, int flags)
    clockRanges->interlaceAllowed = TRUE;
    clockRanges->doubleScanAllowed = FALSE;
 
-   i = xf86ValidateModes(pScrn, pScrn->monitor->Modes,
-                        pScrn->display->modes, clockRanges,
-#ifndef XF86DRI
-                        0, 320, 1600, 64 * pScrn->bitsPerPixel,
+   i = xf86ValidateModes(scrn, scrn->monitor->Modes,
+                        scrn->display->modes, clockRanges,
+#ifndef HAVE_DRI1
+                        0, 320, 1600, 64 * scrn->bitsPerPixel,
 #else
-                        i810_pitches, 0, 0, 64 * pScrn->bitsPerPixel,
+                        i810_pitches, 0, 0, 64 * scrn->bitsPerPixel,
 #endif
                         200, 1200,
-                        pScrn->display->virtualX, pScrn->display->virtualY,
-                        pScrn->videoRam * 1024, LOOKUP_BEST_REFRESH);
+                        scrn->display->virtualX, scrn->display->virtualY,
+                        scrn->videoRam * 1024, LOOKUP_BEST_REFRESH);
 
    if (i == -1) {
-      I810FreeRec(pScrn);
+      I810FreeRec(scrn);
       return FALSE;
    }
 
-   xf86PruneDriverModes(pScrn);
+   xf86PruneDriverModes(scrn);
 
-   if (!i || !pScrn->modes) {
-      xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No valid modes found\n");
-      I810FreeRec(pScrn);
+   if (!i || !scrn->modes) {
+      xf86DrvMsg(scrn->scrnIndex, X_ERROR, "No valid modes found\n");
+      I810FreeRec(scrn);
       return FALSE;
    }
 
-   xf86SetCrtcForModes(pScrn, INTERLACE_HALVE_V);
+   xf86SetCrtcForModes(scrn, INTERLACE_HALVE_V);
 
-   pScrn->currentMode = pScrn->modes;
+   scrn->currentMode = scrn->modes;
 
-   xf86PrintModes(pScrn);
+   xf86PrintModes(scrn);
 
-   xf86SetDpi(pScrn, 0, 0);
+   xf86SetDpi(scrn, 0, 0);
 
-   if (!xf86LoadSubModule(pScrn, "fb")) {
-      I810FreeRec(pScrn);
+   if (!xf86LoadSubModule(scrn, "fb")) {
+      I810FreeRec(scrn);
       return FALSE;
    }
 
    if (!xf86ReturnOptValBool(pI810->Options, OPTION_SW_CURSOR, FALSE)) {
-      if (!xf86LoadSubModule(pScrn, "ramdac")) {
-        I810FreeRec(pScrn);
+      if (!xf86LoadSubModule(scrn, "ramdac")) {
+        I810FreeRec(scrn);
         return FALSE;
       }
    }
 
    if (xf86GetOptValInteger
        (pI810->Options, OPTION_COLOR_KEY, &(pI810->colorKey))) {
-      xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
+      xf86DrvMsg(scrn->scrnIndex, X_CONFIG,
                 "video overlay key set to 0x%x\n", pI810->colorKey);
    } else {
-      pI810->colorKey = (1 << pScrn->offset.red) |
-           (1 << pScrn->offset.green) |
-           (((pScrn->mask.blue >> pScrn->offset.blue) -
-             1) << pScrn->offset.blue);
+      pI810->colorKey = (1 << scrn->offset.red) |
+           (1 << scrn->offset.green) |
+           (((scrn->mask.blue >> scrn->offset.blue) -
+             1) << scrn->offset.blue);
    }
 
    pI810->allowPageFlip=FALSE;
    enable = xf86ReturnOptValBool(pI810->Options, OPTION_PAGEFLIP, FALSE);   
 
-#ifdef XF86DRI
+#ifdef HAVE_DRI1
    if (!pI810->directRenderingDisabled) {
      pI810->allowPageFlip = enable;
      if (pI810->allowPageFlip == TRUE)
      {
-       if (!xf86LoadSubModule(pScrn, "shadowfb")) {
+       if (!xf86LoadSubModule(scrn, "shadowfb")) {
         pI810->allowPageFlip = 0;
-        xf86DrvMsg(pScrn->scrnIndex, X_ERROR, 
+        xf86DrvMsg(scrn->scrnIndex, X_ERROR, 
                    "Couldn't load shadowfb module:\n");
        }
      }
      
-     xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "page flipping %s\n",
+     xf86DrvMsg(scrn->scrnIndex, X_CONFIG, "page flipping %s\n",
                enable ? "enabled" : "disabled");
      
    }
@@ -633,40 +589,38 @@ I810PreInit(ScrnInfoPtr pScrn, int flags)
 
    if (xf86GetOptValInteger(pI810->Options, OPTION_XVMC_SURFACES,
                            &(pI810->numSurfaces))) {
-      xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "%d XvMC Surfaces Requested.\n",
+      xf86DrvMsg(scrn->scrnIndex, X_CONFIG, "%d XvMC Surfaces Requested.\n",
                 pI810->numSurfaces);
       if (pI810->numSurfaces > 7) {
-        xf86DrvMsg(pScrn->scrnIndex, X_PROBED,
+        xf86DrvMsg(scrn->scrnIndex, X_PROBED,
                    "Using 7 XvMC Surfaces (Maximum Allowed).\n");
         pI810->numSurfaces = 7;
       }
       if (pI810->numSurfaces < 6) {
-        xf86DrvMsg(pScrn->scrnIndex, X_PROBED,
+        xf86DrvMsg(scrn->scrnIndex, X_PROBED,
                    "Using 6 XvMC Surfaces (Minimum Allowed).\n");
         pI810->numSurfaces = 6;
       }
    } else {
-      xf86DrvMsg(pScrn->scrnIndex, X_INFO,
+      xf86DrvMsg(scrn->scrnIndex, X_INFO,
                 "XvMC is Disabled: use XvMCSurfaces config option to enable.\n");
       pI810->numSurfaces = 0;
    }
 
-#ifdef XF86DRI
+#ifdef HAVE_DRI1
    /* Load the dri module if requested. */
    if (xf86ReturnOptValBool(pI810->Options, OPTION_DRI, FALSE)) {
-      xf86LoadSubModule(pScrn, "dri");
+      xf86LoadSubModule(scrn, "dri");
    }
 #endif
 
-   /*  We won't be using the VGA access after the probe */
-   I810SetMMIOAccess(pI810);
    return TRUE;
 }
 
 static Bool
-I810MapMMIO(ScrnInfoPtr pScrn)
+I810MapMMIO(ScrnInfoPtr scrn)
 {
-   I810Ptr pI810 = I810PTR(pScrn);
+   I810Ptr pI810 = I810PTR(scrn);
    struct pci_device *const device = pI810->PciInfo;
    int err;
 
@@ -677,7 +631,7 @@ I810MapMMIO(ScrnInfoPtr pScrn)
                               (void **) &pI810->MMIOBase);
    if (err) 
    {
-      xf86DrvMsg (pScrn->scrnIndex, X_ERROR,
+      xf86DrvMsg (scrn->scrnIndex, X_ERROR,
                  "Unable to map mmio BAR. %s (%d)\n",
                  strerror (err), err);
       return FALSE;
@@ -686,13 +640,13 @@ I810MapMMIO(ScrnInfoPtr pScrn)
 }
 
 static Bool
-I810MapMem(ScrnInfoPtr pScrn)
+I810MapMem(ScrnInfoPtr scrn)
 {
-   I810Ptr pI810 = I810PTR(pScrn);
+   I810Ptr pI810 = I810PTR(scrn);
    struct pci_device *const device = pI810->PciInfo;
    int err;
 
-   if (!I810MapMMIO(pScrn))
+   if (!I810MapMMIO(scrn))
       return FALSE;
 
    err = pci_device_map_range (device,
@@ -702,7 +656,7 @@ I810MapMem(ScrnInfoPtr pScrn)
                               (void **) &pI810->FbBase);
    if (err) 
    {
-      xf86DrvMsg (pScrn->scrnIndex, X_ERROR,
+      xf86DrvMsg (scrn->scrnIndex, X_ERROR,
                  "Unable to map frame buffer BAR. %s (%d)\n",
                  strerror (err), err);
       return FALSE;
@@ -714,31 +668,31 @@ I810MapMem(ScrnInfoPtr pScrn)
 }
 
 static void
-I810UnmapMMIO(ScrnInfoPtr pScrn)
+I810UnmapMMIO(ScrnInfoPtr scrn)
 {
-   I810Ptr pI810 = I810PTR(pScrn);
+   I810Ptr pI810 = I810PTR(scrn);
 
    pci_device_unmap_range (pI810->PciInfo, pI810->MMIOBase, I810_REG_SIZE);
    pI810->MMIOBase = NULL;
 }
 
 static Bool
-I810UnmapMem(ScrnInfoPtr pScrn)
+I810UnmapMem(ScrnInfoPtr scrn)
 {
-   I810Ptr pI810 = I810PTR(pScrn);
+   I810Ptr pI810 = I810PTR(scrn);
 
    pci_device_unmap_range (pI810->PciInfo, pI810->FbBase, pI810->FbMapSize);
    pI810->FbBase = NULL;
-   I810UnmapMMIO(pScrn);
+   I810UnmapMMIO(scrn);
    return TRUE;
 }
 
 /* Famous last words
  */
 void
-I810PrintErrorState(ScrnInfoPtr pScrn)
+I810PrintErrorState(ScrnInfoPtr scrn)
 {
-   I810Ptr pI810 = I810PTR(pScrn);
+   I810Ptr pI810 = I810PTR(scrn);
 
    ErrorF("pgetbl_ctl: 0x%lx pgetbl_err: 0x%lx\n",
          (unsigned long) INREG(PGETBL_CTL), (unsigned long) INREG(PGE_ERR));
@@ -772,31 +726,31 @@ I810PrintErrorState(ScrnInfoPtr pScrn)
  * mask out bits here - just read the registers.
  */
 static void
-DoSave(ScrnInfoPtr pScrn, vgaRegPtr vgaReg, I810RegPtr i810Reg,
+DoSave(ScrnInfoPtr scrn, vgaRegPtr vgaReg, I810RegPtr i810Reg,
        Bool saveFonts)
 {
    I810Ptr pI810;
    vgaHWPtr hwp;
    int i;
 
-   pI810 = I810PTR(pScrn);
-   hwp = VGAHWPTR(pScrn);
+   pI810 = I810PTR(scrn);
+   hwp = VGAHWPTR(scrn);
 
    /*
     * This function will handle creating the data structure and filling
     * in the generic VGA portion.
     */
    if (saveFonts)
-      vgaHWSave(pScrn, vgaReg, VGA_SR_MODE | VGA_SR_FONTS | VGA_SR_CMAP);
+      vgaHWSave(scrn, vgaReg, VGA_SR_MODE | VGA_SR_FONTS | VGA_SR_CMAP);
    else
-      vgaHWSave(pScrn, vgaReg, VGA_SR_MODE | VGA_SR_CMAP);
+      vgaHWSave(scrn, vgaReg, VGA_SR_MODE | VGA_SR_CMAP);
 
    /*
     * The port I/O code necessary to read in the extended registers
     * into the fields of the vgaI810Rec structure goes here.
     */
    i810Reg->IOControl = hwp->readCrtc(hwp, IO_CTNL);
-   i810Reg->AddressMapping = pI810->readControl(pI810, GRX, ADDRESS_MAPPING);
+   i810Reg->AddressMapping = hwp->readGr(hwp, ADDRESS_MAPPING);
    i810Reg->BitBLTControl = INREG8(BITBLT_CNTL);
    i810Reg->VideoClk2_M = INREG16(VCLK2_VCO_M);
    i810Reg->VideoClk2_N = INREG16(VCLK2_VCO_N);
@@ -827,21 +781,21 @@ DoSave(ScrnInfoPtr pScrn, vgaRegPtr vgaReg, I810RegPtr i810Reg,
 
    if ((i810Reg->LprbTail & TAIL_ADDR) != (i810Reg->LprbHead & HEAD_ADDR) &&
        i810Reg->LprbLen & RING_VALID) {
-      I810PrintErrorState(pScrn);
+      I810PrintErrorState(scrn);
       FatalError("Active ring not flushed\n");
    }
 }
 
 static void
-I810Save(ScrnInfoPtr pScrn)
+I810Save(ScrnInfoPtr scrn)
 {
    vgaHWPtr hwp;
    I810Ptr pI810;
    uint32_t temp;
 
-   hwp = VGAHWPTR(pScrn);
-   pI810 = I810PTR(pScrn);
-   DoSave(pScrn, &hwp->SavedReg, &pI810->SavedReg, TRUE);
+   hwp = VGAHWPTR(scrn);
+   pI810 = I810PTR(scrn);
+   DoSave(scrn, &hwp->SavedReg, &pI810->SavedReg, TRUE);
 
    temp = INREG(MEMMODE);
    temp |= 4;
@@ -913,7 +867,7 @@ i810PrintMode(vgaRegPtr vgaReg, I810RegPtr mode)
 }
 
 static void
-DoRestore(ScrnInfoPtr pScrn, vgaRegPtr vgaReg, I810RegPtr i810Reg,
+DoRestore(ScrnInfoPtr scrn, vgaRegPtr vgaReg, I810RegPtr i810Reg,
          Bool restoreFonts)
 {
    I810Ptr pI810;
@@ -922,15 +876,15 @@ DoRestore(ScrnInfoPtr pScrn, vgaRegPtr vgaReg, I810RegPtr i810Reg,
    unsigned int itemp;
    int i;
 
-   pI810 = I810PTR(pScrn);
-   hwp = VGAHWPTR(pScrn);
+   pI810 = I810PTR(scrn);
+   hwp = VGAHWPTR(scrn);
 
    if (I810_DEBUG & DEBUG_VERBOSE_VGA) {
       ErrorF("Setting mode in I810Restore:\n");
       i810PrintMode(vgaReg, i810Reg);
    }
 
-   vgaHWProtect(pScrn, TRUE);
+   vgaHWProtect(scrn, TRUE);
 
    usleep(50000);
 
@@ -974,9 +928,9 @@ DoRestore(ScrnInfoPtr pScrn, vgaRegPtr vgaReg, I810RegPtr i810Reg,
     *           restore clock-select bits.
     */
    if (restoreFonts)
-      vgaHWRestore(pScrn, vgaReg, VGA_SR_FONTS | VGA_SR_MODE | VGA_SR_CMAP);
+      vgaHWRestore(scrn, vgaReg, VGA_SR_FONTS | VGA_SR_MODE | VGA_SR_CMAP);
    else
-      vgaHWRestore(pScrn, vgaReg, VGA_SR_MODE | VGA_SR_CMAP);
+      vgaHWRestore(scrn, vgaReg, VGA_SR_MODE | VGA_SR_CMAP);
 
    hwp->writeCrtc(hwp, EXT_VERT_TOTAL, i810Reg->ExtVertTotal);
    hwp->writeCrtc(hwp, EXT_VERT_DISPLAY, i810Reg->ExtVertDispEnd);
@@ -991,17 +945,17 @@ DoRestore(ScrnInfoPtr pScrn, vgaRegPtr vgaReg, I810RegPtr i810Reg,
    temp |= i810Reg->InterlaceControl;
    hwp->writeCrtc(hwp, INTERLACE_CNTL, temp);
 
-   temp = pI810->readControl(pI810, GRX, ADDRESS_MAPPING);
+   temp = hwp->readGr(hwp, ADDRESS_MAPPING);
    temp &= 0xE0;                       /* Save reserved bits 7:5 */
    temp |= i810Reg->AddressMapping;
-   pI810->writeControl(pI810, GRX, ADDRESS_MAPPING, temp);
+   hwp->writeGr(hwp, ADDRESS_MAPPING, temp);
 
    /* Setting the OVRACT Register for video overlay */
    {
        uint32_t LCD_TV_Control = INREG(LCD_TV_C);
        uint32_t TV_HTotal = INREG(LCD_TV_HTOTAL);
        uint32_t ActiveStart, ActiveEnd;
-       
+
        if((LCD_TV_Control & LCD_TV_ENABLE)
          && !(LCD_TV_Control & LCD_TV_VGAMOD)
           && TV_HTotal) {
@@ -1014,7 +968,7 @@ DoRestore(ScrnInfoPtr pScrn, vgaRegPtr vgaReg, I810RegPtr i810Reg,
        OUTREG(LCD_TV_OVRACT,
              (ActiveEnd << 16) | ActiveStart);
    }
-   
+
    /* Turn on DRAM Refresh */
    temp = INREG8(DRAM_ROW_CNTL_HI);
    temp &= ~DRAM_REFRESH_RATE;
@@ -1089,13 +1043,13 @@ DoRestore(ScrnInfoPtr pScrn, vgaRegPtr vgaReg, I810RegPtr i810Reg,
    if (!(vgaReg->Attribute[0x10] & 0x1)) {
       usleep(50000);
       if (restoreFonts)
-        vgaHWRestore(pScrn, vgaReg,
+        vgaHWRestore(scrn, vgaReg,
                      VGA_SR_FONTS | VGA_SR_MODE | VGA_SR_CMAP);
       else
-        vgaHWRestore(pScrn, vgaReg, VGA_SR_MODE | VGA_SR_CMAP);
+        vgaHWRestore(scrn, vgaReg, VGA_SR_MODE | VGA_SR_CMAP);
    }
 
-   vgaHWProtect(pScrn, FALSE);
+   vgaHWProtect(scrn, FALSE);
 
    temp = hwp->readCrtc(hwp, IO_CTNL);
    temp &= ~(EXTENDED_ATTR_CNTL | EXTENDED_CRTC_CNTL);
@@ -1104,10 +1058,10 @@ DoRestore(ScrnInfoPtr pScrn, vgaRegPtr vgaReg, I810RegPtr i810Reg,
 }
 
 static void
-I810SetRingRegs(ScrnInfoPtr pScrn)
+I810SetRingRegs(ScrnInfoPtr scrn)
 {
    unsigned int itemp;
-   I810Ptr pI810 = I810PTR(pScrn);
+   I810Ptr pI810 = I810PTR(scrn);
 
    OUTREG(LP_RING + RING_TAIL, 0);
    OUTREG(LP_RING + RING_HEAD, 0);
@@ -1124,15 +1078,15 @@ I810SetRingRegs(ScrnInfoPtr pScrn)
 }
 
 static void
-I810Restore(ScrnInfoPtr pScrn)
+I810Restore(ScrnInfoPtr scrn)
 {
    vgaHWPtr hwp;
    I810Ptr pI810;
 
-   hwp = VGAHWPTR(pScrn);
-   pI810 = I810PTR(pScrn);
+   hwp = VGAHWPTR(scrn);
+   pI810 = I810PTR(scrn);
 
-   DoRestore(pScrn, &hwp->SavedReg, &pI810->SavedReg, TRUE);
+   DoRestore(scrn, &hwp->SavedReg, &pI810->SavedReg, TRUE);
 }
 
 /*
@@ -1149,9 +1103,9 @@ I810Restore(ScrnInfoPtr pScrn)
     (double)m / ((double)n * (1 << p)) * 4 * REF_FREQ
 
 static void
-I810CalcVCLK(ScrnInfoPtr pScrn, double freq)
+I810CalcVCLK(ScrnInfoPtr scrn, double freq)
 {
-   I810Ptr pI810 = I810PTR(pScrn);
+   I810Ptr pI810 = I810PTR(scrn);
    I810RegPtr i810Reg = &pI810->ModeReg;
    int m, n, p;
    double f_out;
@@ -1196,7 +1150,7 @@ I810CalcVCLK(ScrnInfoPtr pScrn, double freq)
    i810Reg->VideoClk2_N = (n_best - 2) & 0x3FF;
    i810Reg->VideoClk2_DivisorSel = (p_best << 4);
 
-   xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 3,
+   xf86DrvMsgVerb(scrn->scrnIndex, X_INFO, 3,
                  "Setting dot clock to %.1f MHz " "[ 0x%x 0x%x 0x%x ] "
                  "[ %d %d %d ]\n", CALC_VCLK(m_best, n_best, p_best),
                  i810Reg->VideoClk2_M, i810Reg->VideoClk2_N,
@@ -1204,36 +1158,36 @@ I810CalcVCLK(ScrnInfoPtr pScrn, double freq)
 }
 
 static Bool
-I810SetMode(ScrnInfoPtr pScrn, DisplayModePtr mode)
+I810SetMode(ScrnInfoPtr scrn, DisplayModePtr mode)
 {
-   I810Ptr pI810 = I810PTR(pScrn);
+   I810Ptr pI810 = I810PTR(scrn);
    I810RegPtr i810Reg = &pI810->ModeReg;
-   vgaRegPtr pVga = &VGAHWPTR(pScrn)->ModeReg;
+   vgaRegPtr pVga = &VGAHWPTR(scrn)->ModeReg;
    double dclk = mode->Clock / 1000.0;
 
-   switch (pScrn->bitsPerPixel) {
+   switch (scrn->bitsPerPixel) {
    case 8:
-      pVga->CRTC[0x13] = pScrn->displayWidth >> 3;
-      i810Reg->ExtOffset = pScrn->displayWidth >> 11;
+      pVga->CRTC[0x13] = scrn->displayWidth >> 3;
+      i810Reg->ExtOffset = scrn->displayWidth >> 11;
       i810Reg->PixelPipeCfg1 = DISPLAY_8BPP_MODE;
       i810Reg->BitBLTControl = COLEXP_8BPP;
       break;
    case 16:
-      if (pScrn->weight.green == 5) {
+      if (scrn->weight.green == 5) {
         i810Reg->PixelPipeCfg1 = DISPLAY_15BPP_MODE;
       } else {
         i810Reg->PixelPipeCfg1 = DISPLAY_16BPP_MODE;
       }
-      pVga->CRTC[0x13] = pScrn->displayWidth >> 2;
-      i810Reg->ExtOffset = pScrn->displayWidth >> 10;
+      pVga->CRTC[0x13] = scrn->displayWidth >> 2;
+      i810Reg->ExtOffset = scrn->displayWidth >> 10;
       i810Reg->BitBLTControl = COLEXP_16BPP;
 
       /* Enable Palette Programming for Direct Color visuals. -jens */
       i810Reg->PixelPipeCfg2 = DISPLAY_GAMMA_ENABLE;
       break;
    case 24:
-      pVga->CRTC[0x13] = (pScrn->displayWidth * 3) >> 3;
-      i810Reg->ExtOffset = (pScrn->displayWidth * 3) >> 11;
+      pVga->CRTC[0x13] = (scrn->displayWidth * 3) >> 3;
+      i810Reg->ExtOffset = (scrn->displayWidth * 3) >> 11;
 
       i810Reg->PixelPipeCfg1 = DISPLAY_24BPP_MODE;
       i810Reg->BitBLTControl = COLEXP_24BPP;
@@ -1318,13 +1272,13 @@ I810SetMode(ScrnInfoPtr pScrn, DisplayModePtr mode)
     * Calculate the VCLK that most closely matches the requested dot
     * clock.
     */
-   I810CalcVCLK(pScrn, dclk);
+   I810CalcVCLK(scrn, dclk);
 
    /* Since we program the clocks ourselves, always use VCLK2. */
    pVga->MiscOutReg |= 0x0C;
 
    /* Calculate the FIFO Watermark and Burst Length. */
-   i810Reg->LMI_FIFO_Watermark = I810CalcWatermark(pScrn, dclk, FALSE);
+   i810Reg->LMI_FIFO_Watermark = I810CalcWatermark(scrn, dclk, FALSE);
 
    /* Setup the ring buffer */
    i810Reg->LprbTail = 0;
@@ -1341,36 +1295,36 @@ I810SetMode(ScrnInfoPtr pScrn, DisplayModePtr mode)
 }
 
 static Bool
-I810ModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode)
+I810ModeInit(ScrnInfoPtr scrn, DisplayModePtr mode)
 {
    vgaHWPtr hwp;
    I810Ptr pI810;
 
-   hwp = VGAHWPTR(pScrn);
-   pI810 = I810PTR(pScrn);
+   hwp = VGAHWPTR(scrn);
+   pI810 = I810PTR(scrn);
 
    vgaHWUnlock(hwp);
 
-   if (!vgaHWInit(pScrn, mode))
+   if (!vgaHWInit(scrn, mode))
       return FALSE;
 
-   pScrn->vtSema = TRUE;
+   scrn->vtSema = TRUE;
 
-   if (!I810SetMode(pScrn, mode))
+   if (!I810SetMode(scrn, mode))
       return FALSE;
 
-#ifdef XF86DRI
+#ifdef HAVE_DRI1
    if (pI810->directRenderingEnabled) {
-      DRILock(screenInfo.screens[pScrn->scrnIndex], 0);
+      DRILock(xf86ScrnToScreen(scrn), 0);
       pI810->LockHeld = 1;
    }
 #endif
 
-   DoRestore(pScrn, &hwp->ModeReg, &pI810->ModeReg, FALSE);
+   DoRestore(scrn, &hwp->ModeReg, &pI810->ModeReg, FALSE);
 
-#ifdef XF86DRI
+#ifdef HAVE_DRI1
    if (pI810->directRenderingEnabled) {
-      DRIUnlock(screenInfo.screens[pScrn->scrnIndex]);
+      DRIUnlock(xf86ScrnToScreen(scrn));
       pI810->LockHeld = 0;
    }
 #endif
@@ -1379,14 +1333,14 @@ I810ModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode)
 }
 
 static void
-I810LoadPalette15(ScrnInfoPtr pScrn, int numColors, int *indices,
+I810LoadPalette15(ScrnInfoPtr scrn, int numColors, int *indices,
                  LOCO * colors, VisualPtr pVisual)
 {
    vgaHWPtr hwp;
    int i, j, index;
    unsigned char r, g, b;
 
-   hwp = VGAHWPTR(pScrn);
+   hwp = VGAHWPTR(scrn);
 
    for (i = 0; i < numColors; i++) {
       index = indices[i];
@@ -1403,14 +1357,14 @@ I810LoadPalette15(ScrnInfoPtr pScrn, int numColors, int *indices,
 }
 
 static void
-I810LoadPalette16(ScrnInfoPtr pScrn, int numColors, int *indices,
+I810LoadPalette16(ScrnInfoPtr scrn, int numColors, int *indices,
                  LOCO * colors, VisualPtr pVisual)
 {
    vgaHWPtr hwp;
    int i, index;
    unsigned char r, g, b;
 
-   hwp = VGAHWPTR(pScrn);
+   hwp = VGAHWPTR(scrn);
 
    /* Load all four entries in each of the 64 color ranges.  -jens */
    for (i = 0; i < numColors; i++) {
@@ -1467,14 +1421,14 @@ I810LoadPalette16(ScrnInfoPtr pScrn, int numColors, int *indices,
 }
 
 static void
-I810LoadPalette24(ScrnInfoPtr pScrn, int numColors, int *indices,
+I810LoadPalette24(ScrnInfoPtr scrn, int numColors, int *indices,
                  LOCO * colors, VisualPtr pVisual)
 {
    vgaHWPtr hwp;
    int i, index;
    unsigned char r, g, b;
 
-   hwp = VGAHWPTR(pScrn);
+   hwp = VGAHWPTR(scrn);
 
    for (i = 0; i < numColors; i++) {
       index = indices[i];
@@ -1489,9 +1443,9 @@ I810LoadPalette24(ScrnInfoPtr pScrn, int numColors, int *indices,
 }
 
 Bool
-I810AllocateFront(ScrnInfoPtr pScrn)
+I810AllocateFront(ScrnInfoPtr scrn)
 {
-   I810Ptr pI810 = I810PTR(pScrn);
+   I810Ptr pI810 = I810PTR(scrn);
    int cache_lines = -1;
 
    if (pI810->DoneFrontAlloc)
@@ -1500,16 +1454,16 @@ I810AllocateFront(ScrnInfoPtr pScrn)
    memset(&(pI810->FbMemBox), 0, sizeof(BoxRec));
    /* Alloc FrontBuffer/Ring/Accel memory */
    pI810->FbMemBox.x1 = 0;
-   pI810->FbMemBox.x2 = pScrn->displayWidth;
+   pI810->FbMemBox.x2 = scrn->displayWidth;
    pI810->FbMemBox.y1 = 0;
-   pI810->FbMemBox.y2 = pScrn->virtualY;
+   pI810->FbMemBox.y2 = scrn->virtualY;
 
    xf86GetOptValInteger(pI810->Options, OPTION_CACHE_LINES, &cache_lines);
 
    if (cache_lines < 0) {
       /* make sure there is enough for two DVD sized YUV buffers */
-      cache_lines = (pScrn->depth == 24) ? 256 : 384;
-      if (pScrn->displayWidth <= 1024)
+      cache_lines = (scrn->depth == 24) ? 256 : 384;
+      if (scrn->displayWidth <= 1024)
         cache_lines *= 2;
    }
    /* Make sure there's enough space for cache_lines.
@@ -1525,9 +1479,9 @@ I810AllocateFront(ScrnInfoPtr pScrn)
    {
       int maxCacheLines;
 
-      maxCacheLines = (pScrn->videoRam * 1024 /
-                      (pScrn->bitsPerPixel / 8) /
-                      pScrn->displayWidth) - pScrn->virtualY;
+      maxCacheLines = (scrn->videoRam * 1024 /
+                      (scrn->bitsPerPixel / 8) /
+                      scrn->displayWidth) - scrn->virtualY;
       if (maxCacheLines < 0)
         maxCacheLines = 0;
       if (cache_lines > maxCacheLines)
@@ -1535,7 +1489,7 @@ I810AllocateFront(ScrnInfoPtr pScrn)
    }
    pI810->FbMemBox.y2 += cache_lines;
 
-   xf86DrvMsg(pScrn->scrnIndex, X_INFO,
+   xf86DrvMsg(scrn->scrnIndex, X_INFO,
              "Adding %i scanlines for pixmap caching\n", cache_lines);
 
    /* Reserve room for the framebuffer and pixcache.  Put at the top
@@ -1546,7 +1500,7 @@ I810AllocateFront(ScrnInfoPtr pScrn)
    if (!I810AllocLow(&(pI810->FrontBuffer),
                     &(pI810->SysMem),
                     ALIGN((pI810->FbMemBox.x2 * pI810->FbMemBox.y2 * pI810->cpp), 4096))) {
-      xf86DrvMsg(pScrn->scrnIndex,
+      xf86DrvMsg(scrn->scrnIndex,
                 X_WARNING, "Framebuffer allocation failed\n");
       return FALSE;
    }
@@ -1559,16 +1513,16 @@ I810AllocateFront(ScrnInfoPtr pScrn)
       pI810->LpRing->tail = 0;
       pI810->LpRing->space = 0;
    } else {
-      xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+      xf86DrvMsg(scrn->scrnIndex, X_ERROR,
                 "Ring buffer allocation failed\n");
       return (FALSE);
    }
 
    if (I810AllocLow(&pI810->Scratch, &(pI810->SysMem), 64 * 1024) ||
        I810AllocLow(&pI810->Scratch, &(pI810->SysMem), 16 * 1024)) {
-      xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Allocated Scratch Memory\n");
+      xf86DrvMsg(scrn->scrnIndex, X_INFO, "Allocated Scratch Memory\n");
    } else {
-      xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+      xf86DrvMsg(scrn->scrnIndex, X_ERROR,
                 "Scratch memory allocation failed\n");
       return (FALSE);
    }
@@ -1578,29 +1532,29 @@ I810AllocateFront(ScrnInfoPtr pScrn)
 }
 
 static Bool
-I810ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
+I810ScreenInit(SCREEN_INIT_ARGS_DECL)
 {
-   ScrnInfoPtr pScrn;
+   ScrnInfoPtr scrn;
    vgaHWPtr hwp;
    I810Ptr pI810;
    VisualPtr visual;
 
-   pScrn = xf86Screens[pScreen->myNum];
-   pI810 = I810PTR(pScrn);
-   hwp = VGAHWPTR(pScrn);
+   scrn = xf86ScreenToScrn(screen);
+   pI810 = I810PTR(scrn);
+   hwp = VGAHWPTR(scrn);
 
    pI810->LpRing = calloc(sizeof(I810RingBuffer),1);
    if (!pI810->LpRing) {
-     xf86DrvMsg(pScrn->scrnIndex, X_ERROR, 
+     xf86DrvMsg(scrn->scrnIndex, X_ERROR,
                "Could not allocate lpring data structure.\n");
      return FALSE;
    }
-   
+
    miClearVisualTypes();
 
    /* Re-implemented Direct Color support, -jens */
-   if (!miSetVisualTypes(pScrn->depth, miGetDefaultVisualMask(pScrn->depth),
-                        pScrn->rgbBits, pScrn->defaultVisual))
+   if (!miSetVisualTypes(scrn->depth, miGetDefaultVisualMask(scrn->depth),
+                        scrn->rgbBits, scrn->defaultVisual))
       return FALSE;
 
    if (!miSetPixmapDepths())
@@ -1618,7 +1572,7 @@ I810ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     * memory.  Wonder if this is going to be a problem...
     */
 
-#ifdef XF86DRI
+#ifdef HAVE_DRI1
    /*
     * Setup DRI after visuals have been established, but before fbScreenInit
     * is called.   fbScreenInit will eventually call into the drivers
@@ -1629,178 +1583,176 @@ I810ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     * pI810->directRenderingEnabled based on it each generation.
     */
    pI810->directRenderingEnabled = !pI810->directRenderingDisabled;
-   
+
    if (pI810->directRenderingEnabled==TRUE)
-     pI810->directRenderingEnabled = I810DRIScreenInit(pScreen);
+     pI810->directRenderingEnabled = I810DRIScreenInit(screen);
 
 #else
    pI810->directRenderingEnabled = FALSE;
-   if (!I810AllocateGARTMemory(pScrn))
+   if (!I810AllocateGARTMemory(scrn))
       return FALSE;
-   if (!I810AllocateFront(pScrn))
+   if (!I810AllocateFront(scrn))
       return FALSE;
 #endif
 
-   if (!I810MapMem(pScrn))
+   if (!I810MapMem(scrn))
       return FALSE;
 
-   pScrn->memPhysBase = (unsigned long)pI810->LinearAddr;
-   pScrn->fbOffset = 0;
+   scrn->memPhysBase = (unsigned long)pI810->LinearAddr;
+   scrn->fbOffset = 0;
 
    vgaHWSetMmioFuncs(hwp, pI810->MMIOBase, 0);
    vgaHWGetIOBase(hwp);
-   if (!vgaHWMapMem(pScrn))
+   if (!vgaHWMapMem(scrn))
       return FALSE;
 
-   I810Save(pScrn);
-   if (!I810ModeInit(pScrn, pScrn->currentMode))
+   I810Save(scrn);
+   if (!I810ModeInit(scrn, scrn->currentMode))
       return FALSE;
 
-   I810SaveScreen(pScreen, FALSE);
-   I810AdjustFrame(scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
+   I810SaveScreen(screen, FALSE);
+   I810AdjustFrame(ADJUST_FRAME_ARGS(scrn, scrn->frameX0, scrn->frameY0));
 
-   if (!fbScreenInit(pScreen, pI810->FbBase + pScrn->fbOffset,
-                    pScrn->virtualX, pScrn->virtualY,
-                    pScrn->xDpi, pScrn->yDpi,
-                    pScrn->displayWidth, pScrn->bitsPerPixel))
+   if (!fbScreenInit(screen, pI810->FbBase + scrn->fbOffset,
+                    scrn->virtualX, scrn->virtualY,
+                    scrn->xDpi, scrn->yDpi,
+                    scrn->displayWidth, scrn->bitsPerPixel))
       return FALSE;
 
-   if (pScrn->bitsPerPixel > 8) {
+   if (scrn->bitsPerPixel > 8) {
       /* Fixup RGB ordering */
-      visual = pScreen->visuals + pScreen->numVisuals;
-      while (--visual >= pScreen->visuals) {
+      visual = screen->visuals + screen->numVisuals;
+      while (--visual >= screen->visuals) {
         if ((visual->class | DynamicClass) == DirectColor) {
-           visual->offsetRed = pScrn->offset.red;
-           visual->offsetGreen = pScrn->offset.green;
-           visual->offsetBlue = pScrn->offset.blue;
-           visual->redMask = pScrn->mask.red;
-           visual->greenMask = pScrn->mask.green;
-           visual->blueMask = pScrn->mask.blue;
+           visual->offsetRed = scrn->offset.red;
+           visual->offsetGreen = scrn->offset.green;
+           visual->offsetBlue = scrn->offset.blue;
+           visual->redMask = scrn->mask.red;
+           visual->greenMask = scrn->mask.green;
+           visual->blueMask = scrn->mask.blue;
         }
       }
    }
 
-   fbPictureInit(pScreen, NULL, 0);
+   fbPictureInit(screen, NULL, 0);
 
-   xf86SetBlackWhitePixels(pScreen);
+   xf86SetBlackWhitePixels(screen);
 
-#ifdef XF86DRI
+#ifdef HAVE_DRI1
    if (pI810->LpRing->mem.Start == 0 && pI810->directRenderingEnabled) {
       pI810->directRenderingEnabled = FALSE;
-      I810DRICloseScreen(pScreen);
+      I810DRICloseScreen(screen);
    }
 
    if (!pI810->directRenderingEnabled) {
       pI810->DoneFrontAlloc = FALSE;
-      if (!I810AllocateGARTMemory(pScrn))
+      if (!I810AllocateGARTMemory(scrn))
         return FALSE;
-      if (!I810AllocateFront(pScrn))
+      if (!I810AllocateFront(scrn))
         return FALSE;
    }
 #endif
 
-#ifdef XFreeXDGA
-   I810DGAInit(pScreen);
+#ifdef HAVE_DGAPROC_H
+   I810DGAInit(screen);
 #endif
 
-   if (!xf86InitFBManager(pScreen, &(pI810->FbMemBox))) {
-      xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+   if (!xf86InitFBManager(screen, &(pI810->FbMemBox))) {
+      xf86DrvMsg(scrn->scrnIndex, X_ERROR,
                 "Failed to init memory manager\n");
       return FALSE;
    }
 
-   if (!xf86ReturnOptValBool(pI810->Options, OPTION_NOACCEL, FALSE)) {
-      if (pI810->LpRing->mem.Size != 0) {
-        I810SetRingRegs(pScrn);
+   if (pI810->LpRing->mem.Size != 0) {
+      I810SetRingRegs(scrn);
 
-        if (!I810AccelInit(pScreen)) {
-           xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
-                      "Hardware acceleration initialization failed\n");
-        }  else /* PK added 16.02.2004 */
-            I810EmitFlush(pScrn);
+      if (!pI810->noAccel && !I810AccelInit(screen)) {
+        xf86DrvMsg(scrn->scrnIndex, X_ERROR,
+                   "Hardware acceleration initialization failed\n");
       }
+
+      I810EmitFlush(scrn);
    }
 
-   miInitializeBackingStore(pScreen);
-   xf86SetBackingStore(pScreen);
-   xf86SetSilkenMouse(pScreen);
+   xf86SetBackingStore(screen);
+   xf86SetSilkenMouse(screen);
 
-   miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
+   miDCInitialize(screen, xf86GetPointerScreenFuncs());
 
    if (!xf86ReturnOptValBool(pI810->Options, OPTION_SW_CURSOR, FALSE)) {
-      if (!I810CursorInit(pScreen)) {
-        xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+      if (!I810CursorInit(screen)) {
+        xf86DrvMsg(scrn->scrnIndex, X_ERROR,
                    "Hardware cursor initialization failed\n");
       }
    }
 
-   if (!miCreateDefColormap(pScreen))
+   if (!miCreateDefColormap(screen))
       return FALSE;
 
    /* Use driver specific palette load routines for Direct Color support. -jens */
-   if (pScrn->bitsPerPixel == 16) {
-      if (pScrn->depth == 15) {
-        if (!xf86HandleColormaps(pScreen, 256, 8, I810LoadPalette15, NULL,
+   if (scrn->bitsPerPixel == 16) {
+      if (scrn->depth == 15) {
+        if (!xf86HandleColormaps(screen, 256, 8, I810LoadPalette15, NULL,
                                  CMAP_PALETTED_TRUECOLOR |
                                  CMAP_RELOAD_ON_MODE_SWITCH))
            return FALSE;
       } else {
-        if (!xf86HandleColormaps(pScreen, 256, 8, I810LoadPalette16, NULL,
+        if (!xf86HandleColormaps(screen, 256, 8, I810LoadPalette16, NULL,
                                  CMAP_PALETTED_TRUECOLOR |
                                  CMAP_RELOAD_ON_MODE_SWITCH))
            return FALSE;
       }
    } else {
-      if (!xf86HandleColormaps(pScreen, 256, 8, I810LoadPalette24, NULL,
+      if (!xf86HandleColormaps(screen, 256, 8, I810LoadPalette24, NULL,
                               CMAP_PALETTED_TRUECOLOR |
                               CMAP_RELOAD_ON_MODE_SWITCH))
         return FALSE;
    }
 
-   xf86DPMSInit(pScreen, I810DisplayPowerManagementSet, 0);
+   xf86DPMSInit(screen, I810DisplayPowerManagementSet, 0);
 
-   I810InitVideo(pScreen);
+   I810InitVideo(screen);
 
-#ifdef XF86DRI
+#ifdef HAVE_DRI1
    if (pI810->directRenderingEnabled) {
       /* Now that mi, fb, drm and others have done their thing,
        * complete the DRI setup.
        */
-      pI810->directRenderingEnabled = I810DRIFinishScreenInit(pScreen);
+      pI810->directRenderingEnabled = I810DRIFinishScreenInit(screen);
    }
 #ifdef XvMCExtension
    if ((pI810->directRenderingEnabled) && (pI810->numSurfaces)) {
       /* Initialize the hardware motion compensation code */
-      I810InitMC(pScreen);
+      I810InitMC(screen);
    }
 #endif
 #endif
 
    if (pI810->directRenderingEnabled) {
-      xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Direct rendering enabled\n");
+      xf86DrvMsg(scrn->scrnIndex, X_INFO, "Direct rendering enabled\n");
    } else {
-      xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "Direct rendering disabled\n");
+      xf86DrvMsg(scrn->scrnIndex, X_WARNING, "Direct rendering disabled\n");
    }
 
-   pScreen->SaveScreen = I810SaveScreen;
-   pI810->CloseScreen = pScreen->CloseScreen;
-   pScreen->CloseScreen = I810CloseScreen;
+   screen->SaveScreen = I810SaveScreen;
+   pI810->CloseScreen = screen->CloseScreen;
+   screen->CloseScreen = I810CloseScreen;
 
    if (serverGeneration == 1)
-      xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);
+      xf86ShowUnusedOptions(scrn->scrnIndex, scrn->options);
 
    return TRUE;
 }
 
 Bool
-I810SwitchMode(int scrnIndex, DisplayModePtr mode, int flags)
+I810SwitchMode(SWITCH_MODE_ARGS_DECL)
 {
-   ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
+   SCRN_INFO_PTR(arg);
 #if 0
-   I810Ptr pI810 = I810PTR(pScrn);
+   I810Ptr pI810 = I810PTR(scrn);
 #endif
    if (I810_DEBUG & DEBUG_VERBOSE_CURSOR)
-      ErrorF("I810SwitchMode %p %x\n", (void *)mode, flags);
+      ErrorF("I810SwitchMode %p\n", (void *)mode);
 
 #if 0
 /* 
@@ -1811,7 +1763,7 @@ I810SwitchMode(int scrnIndex, DisplayModePtr mode, int flags)
  * If lockups on mode switch are still seen revisit this code. (EE)
  */
 
-# ifdef XF86DRI
+# ifdef HAVE_DRI1
    if (pI810->directRenderingEnabled) {
       if (I810_DEBUG & DEBUG_VERBOSE_DRI)
         ErrorF("calling dri lock\n");
@@ -1820,17 +1772,17 @@ I810SwitchMode(int scrnIndex, DisplayModePtr mode, int flags)
    }
 # endif
    if (pI810->AccelInfoRec != NULL) {
-      I810RefreshRing(pScrn);
-      I810Sync(pScrn);
+      I810RefreshRing(scrn);
+      I810Sync(scrn);
       pI810->AccelInfoRec->NeedToSync = FALSE;
    }
-   I810Restore(pScrn);
+   I810Restore(scrn);
 
-# ifdef XF86DRI
+# ifdef HAVE_DRI1
    if (pI810->directRenderingEnabled) {
-       if (!I810DRILeave(pScrn))
+       if (!I810DRILeave(scrn))
           return FALSE;
-       if (!I810DRIEnter(pScrn))
+       if (!I810DRIEnter(scrn))
           return FALSE;
 
        if (I810_DEBUG & DEBUG_VERBOSE_DRI)
@@ -1840,33 +1792,33 @@ I810SwitchMode(int scrnIndex, DisplayModePtr mode, int flags)
    }
 # endif
 #endif
-   return I810ModeInit(pScrn, mode);
+   return I810ModeInit(scrn, mode);
 }
 
 void
-I810AdjustFrame(int scrnIndex, int x, int y, int flags)
+I810AdjustFrame(ADJUST_FRAME_ARGS_DECL)
 {
-   ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
-   I810Ptr pI810 = I810PTR(pScrn);
-   vgaHWPtr hwp = VGAHWPTR(pScrn);
+   SCRN_INFO_PTR(arg);
+   I810Ptr pI810 = I810PTR(scrn);
+   vgaHWPtr hwp = VGAHWPTR(scrn);
    int Base;
 
 #if 1
    if (pI810->showCache) {
      int lastline = pI810->FbMapSize / 
-       ((pScrn->displayWidth * pScrn->bitsPerPixel) / 8);
-     lastline -= pScrn->currentMode->VDisplay;
+       ((scrn->displayWidth * scrn->bitsPerPixel) / 8);
+     lastline -= scrn->currentMode->VDisplay;
      if (y > 0)
-       y += pScrn->currentMode->VDisplay;
+       y += scrn->currentMode->VDisplay;
      if (y > lastline) y = lastline;
    }
 #endif
-   Base = (y * pScrn->displayWidth + x) >> 2;
+   Base = (y * scrn->displayWidth + x) >> 2;
 
    if (I810_DEBUG & DEBUG_VERBOSE_CURSOR)
-      ErrorF("I810AdjustFrame %d,%d %x\n", x, y, flags);
+      ErrorF("I810AdjustFrame %d,%d\n", x, y);
 
-   switch (pScrn->bitsPerPixel) {
+   switch (scrn->bitsPerPixel) {
    case 8:
       break;
    case 16:
@@ -1896,68 +1848,70 @@ I810AdjustFrame(int scrnIndex, int x, int y, int flags)
 /* These functions are usually called with the lock **not held**.
  */
 static Bool
-I810EnterVT(int scrnIndex, int flags)
+I810EnterVT(VT_FUNC_ARGS_DECL)
 {
-   ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
+   SCRN_INFO_PTR(arg);
 
-#ifdef XF86DRI
-   I810Ptr pI810 = I810PTR(pScrn);
+#ifdef HAVE_DRI1
+   I810Ptr pI810 = I810PTR(scrn);
 #endif
 
    if (I810_DEBUG & DEBUG_VERBOSE_DRI)
       ErrorF("\n\nENTER VT\n");
 
-   if (!I810BindGARTMemory(pScrn)) {
+   if (!I810BindGARTMemory(scrn)) {
       return FALSE;
    }
-#ifdef XF86DRI
-   if (!I810DRIEnter(pScrn)) {
+#ifdef HAVE_DRI1
+   if (!I810DRIEnter(scrn)) {
       return FALSE;
    }
    if (pI810->directRenderingEnabled) {
       if (I810_DEBUG & DEBUG_VERBOSE_DRI)
         ErrorF("calling dri unlock\n");
-      DRIUnlock(screenInfo.screens[scrnIndex]);
+      DRIUnlock(xf86ScrnToScreen(scrn));
       pI810->LockHeld = 0;
    }
 #endif
 
-   if (!I810ModeInit(pScrn, pScrn->currentMode))
+   if (!I810ModeInit(scrn, scrn->currentMode))
       return FALSE;
-   I810AdjustFrame(scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
+   I810AdjustFrame(ADJUST_FRAME_ARGS(scrn, scrn->frameX0, scrn->frameY0));
    return TRUE;
 }
 
 static void
-I810LeaveVT(int scrnIndex, int flags)
+I810LeaveVT(VT_FUNC_ARGS_DECL)
 {
-   ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
-   vgaHWPtr hwp = VGAHWPTR(pScrn);
-   I810Ptr pI810 = I810PTR(pScrn);
+   SCRN_INFO_PTR(arg);
+   vgaHWPtr hwp = VGAHWPTR(scrn);
+   I810Ptr pI810 = I810PTR(scrn);
 
    if (I810_DEBUG & DEBUG_VERBOSE_DRI)
       ErrorF("\n\n\nLeave VT\n");
 
-#ifdef XF86DRI
+#ifdef HAVE_DRI1
    if (pI810->directRenderingEnabled) {
       if (I810_DEBUG & DEBUG_VERBOSE_DRI)
         ErrorF("calling dri lock\n");
-      DRILock(screenInfo.screens[scrnIndex], 0);
+      DRILock(xf86ScrnToScreen(scrn), 0);
       pI810->LockHeld = 1;
    }
 #endif
 
+#ifdef HAVE_XAA_H
    if (pI810->AccelInfoRec != NULL) {
-      I810RefreshRing(pScrn);
-      I810Sync(pScrn);
+      I810RefreshRing(scrn);
+      I810Sync(scrn);
       pI810->AccelInfoRec->NeedToSync = FALSE;
    }
-   I810Restore(pScrn);
+#endif
+   I810Restore(scrn);
 
-   if (!I810UnbindGARTMemory(pScrn))
+   if (!I810UnbindGARTMemory(scrn))
       return;
-#ifdef XF86DRI
-   if (!I810DRILeave(pScrn))
+#ifdef HAVE_DRI1
+   if (!I810DRILeave(scrn))
       return;
 #endif
 
@@ -1965,49 +1919,55 @@ I810LeaveVT(int scrnIndex, int flags)
 }
 
 static Bool
-I810CloseScreen(int scrnIndex, ScreenPtr pScreen)
+I810CloseScreen(CLOSE_SCREEN_ARGS_DECL)
 {
-   ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
-   vgaHWPtr hwp = VGAHWPTR(pScrn);
-   I810Ptr pI810 = I810PTR(pScrn);
+   ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+   vgaHWPtr hwp = VGAHWPTR(scrn);
+   I810Ptr pI810 = I810PTR(scrn);
+#ifdef HAVE_XAA_H
    XAAInfoRecPtr infoPtr = pI810->AccelInfoRec;
+#endif
 
-   if (pScrn->vtSema == TRUE) {
+   if (scrn->vtSema == TRUE) {
+#ifdef HAVE_XAA_H
       if (pI810->AccelInfoRec != NULL) {
-        I810RefreshRing(pScrn);
-        I810Sync(pScrn);
+        I810RefreshRing(scrn);
+        I810Sync(scrn);
         pI810->AccelInfoRec->NeedToSync = FALSE;
       }
-      I810Restore(pScrn);
+#endif
+      I810Restore(scrn);
       vgaHWLock(hwp);
    }
-#ifdef XF86DRI
+#ifdef HAVE_DRI1
    if (pI810->directRenderingEnabled) {
-      I810DRICloseScreen(pScreen);
+      I810DRICloseScreen(screen);
       pI810->directRenderingEnabled = FALSE;
    }
 #endif
 
-   if (pScrn->vtSema == TRUE) {
-      I810UnbindGARTMemory(pScrn);
-      I810Restore(pScrn);
+   if (scrn->vtSema == TRUE) {
+      I810UnbindGARTMemory(scrn);
+      I810Restore(scrn);
       vgaHWLock(hwp);
    }
 
-   I810UnmapMem(pScrn);
-   vgaHWUnmapMem(pScrn);
+   I810UnmapMem(scrn);
+   vgaHWUnmapMem(scrn);
 
    if (pI810->ScanlineColorExpandBuffers) {
       free(pI810->ScanlineColorExpandBuffers);
       pI810->ScanlineColorExpandBuffers = NULL;
    }
 
+#ifdef HAVE_XAA_H
    if (infoPtr) {
       if (infoPtr->ScanlineColorExpandBuffers)
         free(infoPtr->ScanlineColorExpandBuffers);
       XAADestroyInfoRec(infoPtr);
       pI810->AccelInfoRec = NULL;
    }
+#endif
 
    if (pI810->CursorInfoRec) {
       xf86DestroyCursorInfoRec(pI810->CursorInfoRec);
@@ -2023,30 +1983,32 @@ I810CloseScreen(int scrnIndex, ScreenPtr pScreen)
    /* Need to actually close the gart fd, or the unbound memory will just sit
     * around.  Will prevent the Xserver from recycling.
     */
-   xf86GARTCloseScreen(scrnIndex);
+   xf86GARTCloseScreen(scrn->scrnIndex);
 
    free(pI810->LpRing);
    pI810->LpRing = NULL;
 
-   pScrn->vtSema = FALSE;
-   pScreen->CloseScreen = pI810->CloseScreen;
-   return (*pScreen->CloseScreen) (scrnIndex, pScreen);
+   scrn->vtSema = FALSE;
+   screen->CloseScreen = pI810->CloseScreen;
+   return (*screen->CloseScreen) (CLOSE_SCREEN_ARGS);
 }
 
 static void
-I810FreeScreen(int scrnIndex, int flags)
+I810FreeScreen(FREE_SCREEN_ARGS_DECL)
 {
-   I810FreeRec(xf86Screens[scrnIndex]);
+   SCRN_INFO_PTR(arg);
+   I810FreeRec(scrn);
    if (xf86LoaderCheckSymbol("vgaHWFreeHWRec"))
-      vgaHWFreeHWRec(xf86Screens[scrnIndex]);
+     vgaHWFreeHWRec(scrn);
 }
 
 static ModeStatus
-I810ValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, int flags)
+I810ValidMode(SCRN_ARG_TYPE arg, DisplayModePtr mode, Bool verbose, int flags)
 {
+   SCRN_INFO_PTR(arg);
    if (mode->Flags & V_INTERLACE) {
       if (verbose) {
-        xf86DrvMsg(scrnIndex, X_PROBED,
+        xf86DrvMsg(scrn->scrnIndex, X_PROBED,
                    "Removing interlaced mode \"%s\"\n", mode->name);
       }
       return MODE_BAD;
@@ -2055,20 +2017,21 @@ I810ValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, int flags)
 }
 
 static Bool
-I810SaveScreen(ScreenPtr pScreen, Bool unblack)
+I810SaveScreen(ScreenPtr screen, Bool unblack)
 {
-   return vgaHWSaveScreen(pScreen, unblack);
+   return vgaHWSaveScreen(screen, unblack);
 }
 
 static void
-I810DisplayPowerManagementSet(ScrnInfoPtr pScrn, int PowerManagementMode,
+I810DisplayPowerManagementSet(ScrnInfoPtr scrn, int PowerManagementMode,
                              int flags)
 {
    I810Ptr pI810;
    unsigned char SEQ01 = 0;
    int DPMSSyncSelect = 0;
+   vgaHWPtr hwp;
 
-   pI810 = I810PTR(pScrn);
+   pI810 = I810PTR(scrn);
    switch (PowerManagementMode) {
    case DPMSModeOn:
       /* Screen: On; HSync: On, VSync: On */
@@ -2092,9 +2055,11 @@ I810DisplayPowerManagementSet(ScrnInfoPtr pScrn, int PowerManagementMode,
       break;
    }
 
+   hwp = VGAHWPTR(scrn);
+
    /* Turn the screen on/off */
-   SEQ01 |= pI810->readControl(pI810, SRX, 0x01) & ~0x20;
-   pI810->writeControl(pI810, SRX, 0x01, SEQ01);
+   SEQ01 |= hwp->readSeq(hwp, 0x01) & ~0x20;
+   hwp->writeSeq(hwp, 0x01, SEQ01);
 
    /* Set the DPMS mode */
    OUTREG8(DPMS_SYNC_SELECT, DPMSSyncSelect);
@@ -2107,7 +2072,7 @@ lg_i810_available_options(int chipid, int busid)
 }
 
 
-void lg_i810_init(ScrnInfoPtr scrn)
+Bool lg_i810_init(ScrnInfoPtr scrn)
 {
     scrn->PreInit = I810PreInit;
     scrn->ScreenInit = I810ScreenInit;
@@ -2117,4 +2082,5 @@ void lg_i810_init(ScrnInfoPtr scrn)
     scrn->LeaveVT = I810LeaveVT;
     scrn->FreeScreen = I810FreeScreen;
     scrn->ValidMode = I810ValidMode;
+    return TRUE;
 }
index 724e1be..4d3bd1a 100644 (file)
@@ -42,7 +42,6 @@ THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "xf86.h"
 #include "xf86_OSproc.h"
 #include "compiler.h"
-#include "xf86PciInfo.h"
 #include "xf86Pci.h"
 #include "xf86fbman.h"
 #include "regionstr.h"
@@ -54,8 +53,6 @@ THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "xf86xvmc.h"
 #include <X11/extensions/Xv.h>
 #include <X11/extensions/XvMC.h>
-#include "xaa.h"
-#include "xaalocal.h"
 #include "dixstruct.h"
 #include "fourcc.h"
 
@@ -198,7 +195,7 @@ static XF86MCAdaptorPtr ppAdapt[1] =
  **************************************************************************/
 void I810InitMC(ScreenPtr pScreen)
 {
-  ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+  ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
   I810Ptr pI810 = I810PTR(pScrn);
   int i;
 
diff --git a/src/legacy/i810/i810_io.c b/src/legacy/i810/i810_io.c
deleted file mode 100644 (file)
index a6cf305..0000000
+++ /dev/null
@@ -1,133 +0,0 @@
-/**************************************************************************
-
-Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
-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, sub license, 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 NON-INFRINGEMENT.
-IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS 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_CONFIG_H
-#include "config.h"
-#endif
-
-/*
- * Authors:
- *   Daryll Strauss <daryll@precisioninsight.com>
- *
- */
-
-#include "xf86.h"
-#include "xf86_OSproc.h"
-#include "compiler.h"
-
-#ifdef BUILD_FOR_I830
-#include "i830.h"
-#define pI810 pI830
-#define I810Ptr I830Ptr
-#define I810WriteControlPIO I830WriteControlPIO
-#define I810ReadControlPIO I830ReadControlPIO
-#define I810WriteStandardPIO I830WriteStandardPIO
-#define I810ReadStandardPIO I830ReadStandardPIO
-#define I810SetPIOAccess I830SetPIOAccess
-#define I810WriteControlMMIO I830WriteControlMMIO
-#define I810ReadControlMMIO I830ReadControlMMIO
-#define I810WriteStandardMMIO I830WriteStandardMMIO
-#define I810ReadStandardMMIO I830ReadStandardMMIO
-#define I810SetMMIOAccess I830SetMMIOAccess
-#else
-#include "i810.h"
-#endif
-
-#define minb(p) *(volatile uint8_t *)(pI810->MMIOBase + (p))
-#define moutb(p,v) *(volatile uint8_t *)(pI810->MMIOBase + (p)) = (v)
-
-static void
-I810WriteControlPIO(I810Ptr pI810, IOADDRESS addr, uint8_t index, uint8_t val)
-{
-   addr += pI810->ioBase;
-   outb(addr, index);
-   outb(addr + 1, val);
-}
-
-static uint8_t
-I810ReadControlPIO(I810Ptr pI810, IOADDRESS addr, uint8_t index)
-{
-   addr += pI810->ioBase;
-   outb(addr, index);
-   return inb(addr + 1);
-}
-
-static void
-I810WriteStandardPIO(I810Ptr pI810, IOADDRESS addr, uint8_t val)
-{
-   outb(pI810->ioBase + addr, val);
-}
-
-static uint8_t
-I810ReadStandardPIO(I810Ptr pI810, IOADDRESS addr)
-{
-   return inb(pI810->ioBase + addr);
-}
-
-void
-I810SetPIOAccess(I810Ptr pI810)
-{
-   pI810->writeControl = I810WriteControlPIO;
-   pI810->readControl = I810ReadControlPIO;
-   pI810->writeStandard = I810WriteStandardPIO;
-   pI810->readStandard = I810ReadStandardPIO;
-}
-
-static void
-I810WriteControlMMIO(I810Ptr pI810, IOADDRESS addr, uint8_t index, uint8_t val)
-{
-   moutb(addr, index);
-   moutb(addr + 1, val);
-}
-
-static uint8_t
-I810ReadControlMMIO(I810Ptr pI810, IOADDRESS addr, uint8_t index)
-{
-   moutb(addr, index);
-   return minb(addr + 1);
-}
-
-static void
-I810WriteStandardMMIO(I810Ptr pI810, IOADDRESS addr, uint8_t val)
-{
-   moutb(addr, val);
-}
-
-static uint8_t
-I810ReadStandardMMIO(I810Ptr pI810, IOADDRESS addr)
-{
-   return minb(addr);
-}
-
-void
-I810SetMMIOAccess(I810Ptr pI810)
-{
-   pI810->writeControl = I810WriteControlMMIO;
-   pI810->readControl = I810ReadControlMMIO;
-   pI810->writeStandard = I810WriteStandardMMIO;
-   pI810->readStandard = I810ReadStandardMMIO;
-}
index 68dc471..bbaa3ce 100644 (file)
@@ -42,7 +42,6 @@ THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "xf86.h"
 #include "xf86_OSproc.h"
 #include "compiler.h"
-#include "xf86PciInfo.h"
 #include "xf86Pci.h"
 #include "xf86fbman.h"
 #include "regionstr.h"
@@ -50,8 +49,6 @@ THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "i810.h"
 #include "xf86xv.h"
 #include <X11/extensions/Xv.h>
-#include "xaa.h"
-#include "xaalocal.h"
 #include "dixstruct.h"
 #include "fourcc.h"
 
@@ -79,7 +76,7 @@ static int I810PutImage( ScrnInfoPtr,
 static int I810QueryImageAttributes(ScrnInfoPtr, 
        int, unsigned short *, unsigned short *,  int *, int *);
 
-static void I810BlockHandler(int, pointer, pointer, pointer);
+static void I810BlockHandler(BLOCKHANDLER_ARGS_DECL);
 
 #define MAKE_ATOM(a) MakeAtom(a, sizeof(a) - 1, TRUE)
 
@@ -153,43 +150,35 @@ static Atom xvBrightness, xvContrast, xvColorKey;
 #define RGB15ToColorKey(c) \
         (((c & 0x7c00) << 9) | ((c & 0x03E0) << 6) | ((c & 0x001F) << 3))
 
-void I810InitVideo(ScreenPtr pScreen)
+void I810InitVideo(ScreenPtr screen)
 {
-    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-    XF86VideoAdaptorPtr *adaptors, *newAdaptors = NULL;
-    XF86VideoAdaptorPtr newAdaptor = NULL;
-    int num_adaptors;
-       
-    if (pScrn->bitsPerPixel != 8) 
-    {
-       newAdaptor = I810SetupImageVideo(pScreen);
-       I810InitOffscreenImages(pScreen);
-    }
+    ScrnInfoPtr pScrn = xf86ScreenToScrn(screen);
+    XF86VideoAdaptorPtr *adaptors = NULL;
+    int num_adaptors = xf86XVListGenericAdaptors(pScrn, &adaptors);
+
+    if (pScrn->bitsPerPixel != 8) {
+       XF86VideoAdaptorPtr newAdaptor;
+
+       newAdaptor = I810SetupImageVideo(screen);
+       I810InitOffscreenImages(screen);
 
-    num_adaptors = xf86XVListGenericAdaptors(pScrn, &adaptors);
-
-    if(newAdaptor) {
-       if(!num_adaptors) {
-           num_adaptors = 1;
-           adaptors = &newAdaptor;
-       } else {
-           newAdaptors =  /* need to free this someplace */
-               malloc((num_adaptors + 1) * sizeof(XF86VideoAdaptorPtr*));
-           if(newAdaptors) {
-               memcpy(newAdaptors, adaptors, num_adaptors * 
-                                       sizeof(XF86VideoAdaptorPtr));
-               newAdaptors[num_adaptors] = newAdaptor;
+       if (newAdaptor) {
+           XF86VideoAdaptorPtr *newAdaptors;
+
+           newAdaptors =
+               realloc(adaptors,
+                       (num_adaptors + 1) * sizeof(XF86VideoAdaptorPtr));
+           if (newAdaptors != NULL) {
+               newAdaptors[num_adaptors++] = newAdaptor;
                adaptors = newAdaptors;
-               num_adaptors++;
            }
        }
     }
 
-    if(num_adaptors)
-        xf86XVScreenInit(pScreen, adaptors, num_adaptors);
+    if (num_adaptors)
+       xf86XVScreenInit(screen, adaptors, num_adaptors);
 
-    if(newAdaptors)
-       free(newAdaptors);
+    free(adaptors);
 }
 
 /* *INDENT-OFF* */
@@ -376,9 +365,9 @@ static void I810ResetVideo(ScrnInfoPtr pScrn)
 
 
 static XF86VideoAdaptorPtr 
-I810SetupImageVideo(ScreenPtr pScreen)
+I810SetupImageVideo(ScreenPtr screen)
 {
-    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+    ScrnInfoPtr pScrn = xf86ScreenToScrn(screen);
     I810Ptr pI810 = I810PTR(pScrn);
     XF86VideoAdaptorPtr adapt;
     I810PortPrivPtr pPriv;
@@ -424,12 +413,12 @@ I810SetupImageVideo(ScreenPtr pScreen)
     pPriv->currentBuf = 0;
 
     /* gotta uninit this someplace */
-    REGION_NULL(pScreen, &pPriv->clip);
+    REGION_NULL(screen, &pPriv->clip);
 
     pI810->adaptor = adapt;
 
-    pI810->BlockHandler = pScreen->BlockHandler;
-    pScreen->BlockHandler = I810BlockHandler;
+    pI810->BlockHandler = screen->BlockHandler;
+    screen->BlockHandler = I810BlockHandler;
 
     xvBrightness = MAKE_ATOM("XV_BRIGHTNESS");
     xvContrast   = MAKE_ATOM("XV_CONTRAST");
@@ -523,7 +512,7 @@ I810StopVideo(ScrnInfoPtr pScrn, pointer data, Bool shutdown)
 
   I810OverlayRegPtr overlay = (I810OverlayRegPtr) (pI810->FbBase + pI810->OverlayStart); 
 
-  REGION_EMPTY(pScrn->pScreen, &pPriv->clip);   
+  REGION_EMPTY(pScrn->screen, &pPriv->clip);   
 
   if(shutdown) {
      if(pPriv->videoStatus & CLIENT_VIDEO_ON) {
@@ -580,7 +569,7 @@ I810SetPortAttribute(
                  break;
        }
        OVERLAY_UPDATE(pI810->OverlayPhysical);
-       REGION_EMPTY(pScrn->pScreen, &pPriv->clip);   
+       REGION_EMPTY(pScrn->screen, &pPriv->clip);   
   } else return BadMatch;
 
   return Success;
@@ -929,7 +918,7 @@ I810AllocateMemory(
   FBLinearPtr linear,
   int size
 ){
-   ScreenPtr pScreen;
+   ScreenPtr screen;
    FBLinearPtr new_linear;
 
    if(linear) {
@@ -942,21 +931,21 @@ I810AllocateMemory(
        xf86FreeOffscreenLinear(linear);
    }
 
-   pScreen = screenInfo.screens[pScrn->scrnIndex];
+   screen = xf86ScrnToScreen(pScrn);
 
-   new_linear = xf86AllocateOffscreenLinear(pScreen, size, 4,
+   new_linear = xf86AllocateOffscreenLinear(screen, size, 4,
                                             NULL, NULL, NULL);
 
    if(!new_linear) {
         int max_size;
 
-        xf86QueryLargestOffscreenLinear(pScreen, &max_size, 4, 
+        xf86QueryLargestOffscreenLinear(screen, &max_size, 4, 
                                       PRIORITY_EXTREME);
 
         if(max_size < size) return NULL;
 
-        xf86PurgeUnlockedOffscreenAreas(pScreen);
-        new_linear = xf86AllocateOffscreenLinear(pScreen, size, 4, 
+        xf86PurgeUnlockedOffscreenAreas(screen);
+        new_linear = xf86AllocateOffscreenLinear(screen, size, 4, 
                                                  NULL, NULL, NULL);
    } 
 
@@ -996,7 +985,7 @@ I810PutImage(
     dstBox.y2 = drw_y + drw_h;
 
     I810ClipVideo(&dstBox, &x1, &x2, &y1, &y2, 
-                 REGION_EXTENTS(pScrn->pScreen, clipBoxes), width, height);
+                 REGION_EXTENTS(pScrn->screen, clipBoxes), width, height);
     
     if((x1 >= x2) || (y1 >= y2))
        return Success;
@@ -1082,8 +1071,8 @@ I810PutImage(
     }
 
     /* update cliplist */
-    if(!REGION_EQUAL(pScrn->pScreen, &pPriv->clip, clipBoxes)) {
-       REGION_COPY(pScrn->pScreen, &pPriv->clip, clipBoxes);
+    if(!REGION_EQUAL(pScrn->screen, &pPriv->clip, clipBoxes)) {
+       REGION_COPY(pScrn->screen, &pPriv->clip, clipBoxes);
        /* draw these */
        xf86XVFillKeyHelperDrawable(pDraw, pPriv->colorKey, clipBoxes);
     }
@@ -1146,23 +1135,19 @@ I810QueryImageAttributes(
 }
 
 static void
-I810BlockHandler (
-    int i,
-    pointer     blockData,
-    pointer     pTimeout,
-    pointer     pReadmask
-){
-    ScreenPtr   pScreen = screenInfo.screens[i];
-    ScrnInfoPtr pScrn = xf86Screens[i];
+I810BlockHandler (BLOCKHANDLER_ARGS_DECL)
+{
+    SCREEN_PTR(arg);
+    ScrnInfoPtr pScrn = xf86ScreenToScrn(screen);
     I810Ptr      pI810 = I810PTR(pScrn);
     I810PortPrivPtr pPriv = GET_PORT_PRIVATE(pScrn);
     I810OverlayRegPtr overlay = (I810OverlayRegPtr) (pI810->FbBase + pI810->OverlayStart); 
 
-    pScreen->BlockHandler = pI810->BlockHandler;
+    screen->BlockHandler = pI810->BlockHandler;
     
-    (*pScreen->BlockHandler) (i, blockData, pTimeout, pReadmask);
+    (*screen->BlockHandler) (BLOCKHANDLER_ARGS);
 
-    pScreen->BlockHandler = I810BlockHandler;
+    screen->BlockHandler = I810BlockHandler;
 
     if(pPriv->videoStatus & TIMER_MASK) {
        UpdateCurrentTime();
@@ -1298,7 +1283,7 @@ I810GetSurfaceAttribute(
     Atom attribute,
     INT32 *value
 ){
-    return I810GetPortAttribute(pScrn, attribute, value, NULL);
+    return I810GetPortAttribute(pScrn, attribute, value, GET_PORT_PRIVATE(pScrn));
 }
 
 static int
@@ -1307,7 +1292,7 @@ I810SetSurfaceAttribute(
     Atom attribute,
     INT32 value
 ){
-    return I810SetPortAttribute(pScrn, attribute, value, NULL);
+    return I810SetPortAttribute(pScrn, attribute, value, GET_PORT_PRIVATE(pScrn));
 }
 
 
@@ -1383,7 +1368,7 @@ I810DisplaySurface(
     pPriv->isOn = TRUE;
     /* we've prempted the XvImage stream so set its free timer */
     if(pI810Priv->videoStatus & CLIENT_VIDEO_ON) {
-      REGION_EMPTY(pScrn->pScreen, & pI810Priv->clip);   
+      REGION_EMPTY(pScrn->screen, & pI810Priv->clip);   
       UpdateCurrentTime();
       pI810Priv->videoStatus = FREE_TIMER;
       pI810Priv->freeTime = currentTime.milliseconds + FREE_DELAY;
@@ -1395,7 +1380,7 @@ I810DisplaySurface(
 
 
 static void 
-I810InitOffscreenImages(ScreenPtr pScreen)
+I810InitOffscreenImages(ScreenPtr screen)
 {
     XF86OffscreenImagePtr offscreenImages;
 
@@ -1418,6 +1403,7 @@ I810InitOffscreenImages(ScreenPtr pScreen)
     offscreenImages[0].num_attributes = 1;
     offscreenImages[0].attributes = Attributes;
 
-    xf86XVRegisterOffscreenImages(pScreen, offscreenImages, 1);
+    if (!xf86XVRegisterOffscreenImages(screen, offscreenImages, 1))
+           free(offscreenImages);
 }
 
diff --git a/src/legacy/i810/i810_xaa.c b/src/legacy/i810/i810_xaa.c
new file mode 100644 (file)
index 0000000..13f0dc2
--- /dev/null
@@ -0,0 +1,320 @@
+
+/**************************************************************************
+
+Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
+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, sub license, 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 NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS 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_CONFIG_H
+#include "config.h"
+#endif
+
+/*
+ * Authors:
+ *   Keith Whitwell <keith@tungstengraphics.com>
+ *
+ */
+
+#include "xf86.h"
+#include "xaarop.h"
+#include "i810.h"
+
+static void
+I810SetupForMono8x8PatternFill(ScrnInfoPtr pScrn, int pattx, int patty,
+                              int fg, int bg, int rop,
+                              unsigned int planemask)
+{
+   I810Ptr pI810 = I810PTR(pScrn);
+
+   if (I810_DEBUG & DEBUG_VERBOSE_ACCEL)
+      ErrorF("I810SetupFor8x8PatternColorExpand\n");
+
+   /* FULL_MONO_PAT_BLT, p176 */
+   pI810->BR[0] = (BR00_BITBLT_CLIENT | BR00_OP_MONO_PAT_BLT | 0x9);
+   pI810->BR[18] = bg;
+   pI810->BR[19] = fg;
+   pI810->BR[13] = (pScrn->displayWidth * pI810->cpp);
+   pI810->BR[13] |= I810PatternROP[rop] << 16;
+   if (bg == -1)
+      pI810->BR[13] |= BR13_MONO_PATN_TRANS;
+}
+
+static void
+I810SubsequentMono8x8PatternFillRect(ScrnInfoPtr pScrn, int pattx, int patty,
+                                    int x, int y, int w, int h)
+{
+   I810Ptr pI810 = I810PTR(pScrn);
+   int addr =
+        pI810->bufferOffset + (y * pScrn->displayWidth + x) * pI810->cpp;
+
+   if (I810_DEBUG & DEBUG_VERBOSE_ACCEL)
+      ErrorF("I810Subsequent8x8PatternColorExpand\n");
+
+   {
+      BEGIN_LP_RING(12);
+      OUT_RING(pI810->BR[0] | ((y << 5) & BR00_PAT_VERT_ALIGN));
+      OUT_RING(pI810->BR[13]);
+      OUT_RING((h << 16) | (w * pI810->cpp));
+      OUT_RING(addr);
+      OUT_RING(pI810->BR[13] & 0xFFFF);        /* src pitch */
+      OUT_RING(addr);                  /* src addr */
+      OUT_RING(0);                     /* transparency color */
+      OUT_RING(pI810->BR[18]);         /* bg */
+      OUT_RING(pI810->BR[19]);         /* fg */
+      OUT_RING(pattx);                 /* pattern data */
+      OUT_RING(patty);
+      OUT_RING(0);
+      ADVANCE_LP_RING();
+   }
+}
+
+static void
+I810GetNextScanlineColorExpandBuffer(ScrnInfoPtr pScrn)
+{
+   I810Ptr pI810 = I810PTR(pScrn);
+   XAAInfoRecPtr infoPtr = pI810->AccelInfoRec;
+
+   if (pI810->nextColorExpandBuf == pI810->NumScanlineColorExpandBuffers)
+      I810Sync(pScrn);
+
+   infoPtr->ScanlineColorExpandBuffers[0] =
+        pI810->ScanlineColorExpandBuffers[pI810->nextColorExpandBuf];
+
+   if (I810_DEBUG & DEBUG_VERBOSE_ACCEL)
+      ErrorF("using color expand buffer %d\n", pI810->nextColorExpandBuf);
+
+   pI810->nextColorExpandBuf++;
+}
+
+static void
+I810SetupForScanlineCPUToScreenColorExpandFill(ScrnInfoPtr pScrn,
+                                              int fg, int bg, int rop,
+                                              unsigned int planemask)
+{
+   I810Ptr pI810 = I810PTR(pScrn);
+
+   if (I810_DEBUG & DEBUG_VERBOSE_ACCEL)
+      ErrorF("I810SetupForScanlineScreenToScreenColorExpand %d %d %x %x\n",
+            fg, bg, rop, planemask);
+
+   pI810->BR[13] = (pScrn->displayWidth * pI810->cpp);
+   pI810->BR[13] |= I810CopyROP[rop] << 16;
+   pI810->BR[13] |= (1 << 27);
+   if (bg == -1)
+      pI810->BR[13] |= BR13_MONO_TRANSPCY;
+
+   pI810->BR[18] = bg;
+   pI810->BR[19] = fg;
+
+   I810GetNextScanlineColorExpandBuffer(pScrn);
+}
+
+static void
+I810SubsequentScanlineCPUToScreenColorExpandFill(ScrnInfoPtr pScrn,
+                                                int x, int y,
+                                                int w, int h, int skipleft)
+{
+   I810Ptr pI810 = I810PTR(pScrn);
+
+   if (I810_DEBUG & DEBUG_VERBOSE_ACCEL)
+      ErrorF("I810SubsequentScanlineCPUToScreenColorExpandFill "
+            "%d,%d %dx%x %d\n", x, y, w, h, skipleft);
+
+   pI810->BR[0] = BR00_BITBLT_CLIENT | BR00_OP_MONO_SRC_COPY_BLT | 0x06;
+   pI810->BR[9] = (pI810->bufferOffset +
+                  (y * pScrn->displayWidth + x) * pI810->cpp);
+   pI810->BR[14] = ((1 << 16) | (w * pI810->cpp));
+   pI810->BR[11] = ((w + 31) / 32) - 1;
+}
+
+static void
+I810SubsequentColorExpandScanline(ScrnInfoPtr pScrn, int bufno)
+{
+   I810Ptr pI810 = I810PTR(pScrn);
+
+   pI810->BR[12] = (pI810->AccelInfoRec->ScanlineColorExpandBuffers[0] -
+                   pI810->FbBase);
+
+   if (I810_DEBUG & DEBUG_VERBOSE_ACCEL)
+      ErrorF("I810SubsequentColorExpandScanline %d (addr %x)\n",
+            bufno, pI810->BR[12]);
+
+   {
+      BEGIN_LP_RING(8);
+      OUT_RING(pI810->BR[0]);
+      OUT_RING(pI810->BR[13]);
+      OUT_RING(pI810->BR[14]);
+      OUT_RING(pI810->BR[9]);
+      OUT_RING(pI810->BR[11]);
+      OUT_RING(pI810->BR[12]);         /* srcaddr */
+      OUT_RING(pI810->BR[18]);
+      OUT_RING(pI810->BR[19]);
+      ADVANCE_LP_RING();
+   }
+
+   /* Advance to next scanline.
+    */
+   pI810->BR[9] += pScrn->displayWidth * pI810->cpp;
+   I810GetNextScanlineColorExpandBuffer(pScrn);
+}
+
+/* Emit on gaining VT?
+ */
+#if 0
+static void
+I810EmitInvarientState(ScrnInfoPtr pScrn)
+{
+   I810Ptr pI810 = I810PTR(pScrn);
+
+   BEGIN_LP_RING(10);
+
+   OUT_RING(INST_PARSER_CLIENT | INST_OP_FLUSH | INST_FLUSH_MAP_CACHE);
+   OUT_RING(GFX_CMD_CONTEXT_SEL | CS_UPDATE_USE | CS_USE_CTX0);
+   OUT_RING(INST_PARSER_CLIENT | INST_OP_FLUSH | INST_FLUSH_MAP_CACHE);
+   OUT_RING(0);
+
+   OUT_RING(GFX_OP_COLOR_CHROMA_KEY);
+   OUT_RING(CC1_UPDATE_KILL_WRITE |
+           CC1_DISABLE_KILL_WRITE |
+           CC1_UPDATE_COLOR_IDX |
+           CC1_UPDATE_CHROMA_LOW | CC1_UPDATE_CHROMA_HI | 0);
+   OUT_RING(0);
+   OUT_RING(0);
+
+/*     OUT_RING( CMD_OP_Z_BUFFER_INFO ); */
+/*     OUT_RING( pI810->DepthBuffer.Start | pI810->auxPitchBits); */
+
+   ADVANCE_LP_RING();
+}
+#endif
+
+/* The following function sets up the supported acceleration. Call it
+ * from the FbInit() function in the SVGA driver, or before ScreenInit
+ * in a monolithic server.
+ */
+Bool
+I810AccelInit(ScreenPtr pScreen)
+{
+   XAAInfoRecPtr infoPtr;
+   ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
+   I810Ptr pI810 = I810PTR(pScrn);
+
+   if (I810_DEBUG & DEBUG_VERBOSE_ACCEL)
+      ErrorF("I810AccelInit\n");
+
+   pI810->AccelInfoRec = infoPtr = XAACreateInfoRec();
+   if (!infoPtr)
+      return FALSE;
+
+   pI810->bufferOffset = 0;
+   infoPtr->Flags = LINEAR_FRAMEBUFFER | OFFSCREEN_PIXMAPS;
+   infoPtr->Flags |= PIXMAP_CACHE;
+
+   /* Sync
+    */
+   infoPtr->Sync = I810Sync;
+
+   /* Solid filled rectangles
+    */
+   {
+      infoPtr->SolidFillFlags = NO_PLANEMASK;
+      infoPtr->SetupForSolidFill = I810SetupForSolidFill;
+      infoPtr->SubsequentSolidFillRect = I810SubsequentSolidFillRect;
+   }
+
+   /* Screen to screen copy
+    *   - the transparency op hangs the blit engine, disable for now.
+    */
+   {
+      infoPtr->ScreenToScreenCopyFlags = (0
+                                         | NO_PLANEMASK
+                                         | NO_TRANSPARENCY | 0);
+
+      infoPtr->SetupForScreenToScreenCopy = I810SetupForScreenToScreenCopy;
+      infoPtr->SubsequentScreenToScreenCopy =
+           I810SubsequentScreenToScreenCopy;
+   }
+
+   /* 8x8 pattern fills
+    */
+   {
+      infoPtr->SetupForMono8x8PatternFill = I810SetupForMono8x8PatternFill;
+      infoPtr->SubsequentMono8x8PatternFillRect =
+           I810SubsequentMono8x8PatternFillRect;
+
+      infoPtr->Mono8x8PatternFillFlags = (HARDWARE_PATTERN_PROGRAMMED_BITS |
+                                         HARDWARE_PATTERN_SCREEN_ORIGIN |
+                                         BIT_ORDER_IN_BYTE_MSBFIRST |
+                                         NO_PLANEMASK | 0);
+   }
+
+   /* 8x8 color fills - not considered useful for XAA.
+    */
+
+   /* Scanline color expansion - Use the same scheme as the 3.3 driver.
+    *
+    */
+   if (pI810->Scratch.Size != 0) {
+      int i;
+      int width = ALIGN(pScrn->displayWidth, 32) / 8;
+      int nr_buffers = pI810->Scratch.Size / width;
+      unsigned char *ptr = pI810->FbBase + pI810->Scratch.Start;
+
+      pI810->NumScanlineColorExpandBuffers = nr_buffers;
+      pI810->ScanlineColorExpandBuffers = (unsigned char **)
+           xnfcalloc(nr_buffers, sizeof(unsigned char *));
+
+      for (i = 0; i < nr_buffers; i++, ptr += width)
+        pI810->ScanlineColorExpandBuffers[i] = ptr;
+
+      infoPtr->ScanlineCPUToScreenColorExpandFillFlags = (NO_PLANEMASK |
+                                                         ROP_NEEDS_SOURCE |
+                                                         BIT_ORDER_IN_BYTE_MSBFIRST
+                                                         | 0);
+
+      infoPtr->ScanlineColorExpandBuffers = (unsigned char **)
+           xnfcalloc(1, sizeof(unsigned char *));
+      infoPtr->NumScanlineColorExpandBuffers = 1;
+
+      infoPtr->ScanlineColorExpandBuffers[0] =
+           pI810->ScanlineColorExpandBuffers[0];
+      pI810->nextColorExpandBuf = 0;
+
+      infoPtr->SetupForScanlineCPUToScreenColorExpandFill =
+           I810SetupForScanlineCPUToScreenColorExpandFill;
+
+      infoPtr->SubsequentScanlineCPUToScreenColorExpandFill =
+           I810SubsequentScanlineCPUToScreenColorExpandFill;
+
+      infoPtr->SubsequentColorExpandScanline =
+           I810SubsequentColorExpandScanline;
+   }
+
+   /* Possible todo: Image writes w/ non-GXCOPY rop.
+    */
+
+   I810SelectBuffer(pScrn, I810_SELECT_FRONT);
+
+   return XAAInit(pScreen, infoPtr);
+}
index 0754ff4..e6b63d3 100644 (file)
@@ -4323,7 +4323,7 @@ static XvAttribute I810_XVMC_ATTRIBUTES[] = {
 // Function: XvMCQueryAttributes
 // Description: An array of XvAttributes of size "number" is returned by
 //   this function. If there are no attributes, NULL is returned and number
-//   is set to 0. The array may be freed with xfree().
+//   is set to 0. The array may be freed with free().
 //
 // Arguments:
 //   display - Connection to the X server.
index 57f9685..d8aa4fb 100644 (file)
@@ -1,9 +1,9 @@
-# Makefile.in generated by automake 1.11.1 from Makefile.am.
+# Makefile.in generated by automake 1.11.6 from Makefile.am.
 # @configure_input@
 
 # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-# 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
-# Inc.
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
+# Foundation, Inc.
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
 @SET_MAKE@
 
 VPATH = @srcdir@
+am__make_dryrun = \
+  { \
+    am__dry=no; \
+    case $$MAKEFLAGS in \
+      *\\[\ \  ]*) \
+        echo 'am--echo: ; @echo "AM"  OK' | $(MAKE) -f - 2>/dev/null \
+          | grep '^AM OK$$' >/dev/null || am__dry=yes;; \
+      *) \
+        for am__flg in $$MAKEFLAGS; do \
+          case $$am__flg in \
+            *=*|--*) ;; \
+            *n*) am__dry=yes; break;; \
+          esac; \
+        done;; \
+    esac; \
+    test $$am__dry = yes; \
+  }
 pkgdatadir = $(datadir)/@PACKAGE@
 pkgincludedir = $(includedir)/@PACKAGE@
 pkglibdir = $(libdir)/@PACKAGE@
@@ -37,10 +54,7 @@ host_triplet = @host@
 subdir = src/legacy/i810/xvmc
 DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
-       $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
-       $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
-       $(top_srcdir)/configure.ac
+am__aclocal_m4_deps = $(top_srcdir)/configure.ac
 am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
        $(ACLOCAL_M4)
 mkinstalldirs = $(install_sh) -d
@@ -68,13 +82,19 @@ am__nobase_list = $(am__nobase_strip_setup); \
 am__base_list = \
   sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
   sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
+am__uninstall_files_from_dir = { \
+  test -z "$$files" \
+    || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \
+    || { echo " ( cd '$$dir' && rm -f" $$files ")"; \
+         $(am__cd) "$$dir" && rm -f $$files; }; \
+  }
 am__installdirs = "$(DESTDIR)$(libdir)"
 LTLIBRARIES = $(lib_LTLIBRARIES)
 libI810XvMC_la_DEPENDENCIES =
 am_libI810XvMC_la_OBJECTS = I810XvMC.lo
 libI810XvMC_la_OBJECTS = $(am_libI810XvMC_la_OBJECTS)
-AM_V_lt = $(am__v_lt_$(V))
-am__v_lt_ = $(am__v_lt_$(AM_DEFAULT_VERBOSITY))
+AM_V_lt = $(am__v_lt_@AM_V@)
+am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
 am__v_lt_0 = --silent
 libI810XvMC_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \
        $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \
@@ -82,7 +102,7 @@ libI810XvMC_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \
        $@
 @XVMC_TRUE@am_libI810XvMC_la_rpath = -rpath $(libdir)
 DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
-depcomp = $(SHELL) $(top_srcdir)/build-aux/depcomp
+depcomp = $(SHELL) $(top_srcdir)/depcomp
 am__depfiles_maybe = depfiles
 am__mv = mv -f
 COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
@@ -91,24 +111,29 @@ LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
        $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \
        $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
        $(AM_CFLAGS) $(CFLAGS)
-AM_V_CC = $(am__v_CC_$(V))
-am__v_CC_ = $(am__v_CC_$(AM_DEFAULT_VERBOSITY))
+AM_V_CC = $(am__v_CC_@AM_V@)
+am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@)
 am__v_CC_0 = @echo "  CC    " $@;
-AM_V_at = $(am__v_at_$(V))
-am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY))
+AM_V_at = $(am__v_at_@AM_V@)
+am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
 am__v_at_0 = @
 CCLD = $(CC)
 LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
        $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
        $(AM_LDFLAGS) $(LDFLAGS) -o $@
-AM_V_CCLD = $(am__v_CCLD_$(V))
-am__v_CCLD_ = $(am__v_CCLD_$(AM_DEFAULT_VERBOSITY))
+AM_V_CCLD = $(am__v_CCLD_@AM_V@)
+am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
 am__v_CCLD_0 = @echo "  CCLD  " $@;
-AM_V_GEN = $(am__v_GEN_$(V))
-am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY))
+AM_V_GEN = $(am__v_GEN_@AM_V@)
+am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
 am__v_GEN_0 = @echo "  GEN   " $@;
 SOURCES = $(libI810XvMC_la_SOURCES)
 DIST_SOURCES = $(libI810XvMC_la_SOURCES)
+am__can_run_installinfo = \
+  case $$AM_UPDATE_INFO_DIR in \
+    n|no|NO) false;; \
+    *) (install-info --version) >/dev/null 2>&1;; \
+  esac
 ETAGS = etags
 CTAGS = ctags
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
@@ -124,6 +149,7 @@ AUTOCONF = @AUTOCONF@
 AUTOHEADER = @AUTOHEADER@
 AUTOMAKE = @AUTOMAKE@
 AWK = @AWK@
+BASE_CFLAGS = @BASE_CFLAGS@
 CC = @CC@
 CCDEPMODE = @CCDEPMODE@
 CFLAGS = @CFLAGS@
@@ -134,11 +160,16 @@ CWARNFLAGS = @CWARNFLAGS@
 CYGPATH_W = @CYGPATH_W@
 DEFS = @DEFS@
 DEPDIR = @DEPDIR@
+DLLTOOL = @DLLTOOL@
+DRI2_CFLAGS = @DRI2_CFLAGS@
+DRI2_LIBS = @DRI2_LIBS@
 DRIVER_MAN_DIR = @DRIVER_MAN_DIR@
 DRIVER_MAN_SUFFIX = @DRIVER_MAN_SUFFIX@
 DRIVER_NAME = @DRIVER_NAME@
 DRI_CFLAGS = @DRI_CFLAGS@
 DRI_LIBS = @DRI_LIBS@
+DRMINTEL_CFLAGS = @DRMINTEL_CFLAGS@
+DRMINTEL_LIBS = @DRMINTEL_LIBS@
 DRM_CFLAGS = @DRM_CFLAGS@
 DRM_LIBS = @DRM_LIBS@
 DSYMUTIL = @DSYMUTIL@
@@ -162,6 +193,10 @@ INSTALL_SCRIPT = @INSTALL_SCRIPT@
 INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
 LD = @LD@
 LDFLAGS = @LDFLAGS@
+LIBGLAMOR_CFLAGS = @LIBGLAMOR_CFLAGS@
+LIBGLAMOR_EGL_CFLAGS = @LIBGLAMOR_EGL_CFLAGS@
+LIBGLAMOR_EGL_LIBS = @LIBGLAMOR_EGL_LIBS@
+LIBGLAMOR_LIBS = @LIBGLAMOR_LIBS@
 LIBOBJS = @LIBOBJS@
 LIBS = @LIBS@
 LIBTOOL = @LIBTOOL@
@@ -172,6 +207,7 @@ LN_S = @LN_S@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MANIFEST_TOOL = @MANIFEST_TOOL@
 MAN_SUBSTS = @MAN_SUBSTS@
 MISC_MAN_DIR = @MISC_MAN_DIR@
 MISC_MAN_SUFFIX = @MISC_MAN_SUFFIX@
@@ -199,10 +235,15 @@ RANLIB = @RANLIB@
 SED = @SED@
 SET_MAKE = @SET_MAKE@
 SHELL = @SHELL@
+STRICT_CFLAGS = @STRICT_CFLAGS@
 STRIP = @STRIP@
 UDEV_CFLAGS = @UDEV_CFLAGS@
 UDEV_LIBS = @UDEV_LIBS@
+VALGRIND_CFLAGS = @VALGRIND_CFLAGS@
+VALGRIND_LIBS = @VALGRIND_LIBS@
 VERSION = @VERSION@
+X11_CFLAGS = @X11_CFLAGS@
+X11_LIBS = @X11_LIBS@
 XORG_CFLAGS = @XORG_CFLAGS@
 XORG_LIBS = @XORG_LIBS@
 XORG_MAN_PAGE = @XORG_MAN_PAGE@
@@ -212,6 +253,7 @@ abs_builddir = @abs_builddir@
 abs_srcdir = @abs_srcdir@
 abs_top_builddir = @abs_top_builddir@
 abs_top_srcdir = @abs_top_srcdir@
+ac_ct_AR = @ac_ct_AR@
 ac_ct_CC = @ac_ct_CC@
 ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
 am__include = @am__include@
@@ -244,7 +286,6 @@ libdir = @libdir@
 libexecdir = @libexecdir@
 localedir = @localedir@
 localstatedir = @localstatedir@
-lt_ECHO = @lt_ECHO@
 mandir = @mandir@
 mkdir_p = @mkdir_p@
 moduledir = @moduledir@
@@ -304,7 +345,6 @@ $(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
 $(am__aclocal_m4_deps):
 install-libLTLIBRARIES: $(lib_LTLIBRARIES)
        @$(NORMAL_INSTALL)
-       test -z "$(libdir)" || $(MKDIR_P) "$(DESTDIR)$(libdir)"
        @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \
        list2=; for p in $$list; do \
          if test -f $$p; then \
@@ -312,6 +352,8 @@ install-libLTLIBRARIES: $(lib_LTLIBRARIES)
          else :; fi; \
        done; \
        test -z "$$list2" || { \
+         echo " $(MKDIR_P) '$(DESTDIR)$(libdir)'"; \
+         $(MKDIR_P) "$(DESTDIR)$(libdir)" || exit 1; \
          echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(libdir)'"; \
          $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(libdir)"; \
        }
@@ -333,7 +375,7 @@ clean-libLTLIBRARIES:
          echo "rm -f \"$${dir}/so_locations\""; \
          rm -f "$${dir}/so_locations"; \
        done
-libI810XvMC.la: $(libI810XvMC_la_OBJECTS) $(libI810XvMC_la_DEPENDENCIES) 
+libI810XvMC.la: $(libI810XvMC_la_OBJECTS) $(libI810XvMC_la_DEPENDENCIES) $(EXTRA_libI810XvMC_la_DEPENDENCIES) 
        $(AM_V_CCLD)$(libI810XvMC_la_LINK) $(am_libI810XvMC_la_rpath) $(libI810XvMC_la_OBJECTS) $(libI810XvMC_la_LIBADD) $(LIBS)
 
 mostlyclean-compile:
@@ -347,26 +389,23 @@ distclean-compile:
 .c.o:
 @am__fastdepCC_TRUE@   $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
 @am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
-@am__fastdepCC_FALSE@  $(AM_V_CC) @AM_BACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@  $(COMPILE) -c $<
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(COMPILE) -c $<
 
 .c.obj:
 @am__fastdepCC_TRUE@   $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
 @am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
-@am__fastdepCC_FALSE@  $(AM_V_CC) @AM_BACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@  $(COMPILE) -c `$(CYGPATH_W) '$<'`
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(COMPILE) -c `$(CYGPATH_W) '$<'`
 
 .c.lo:
 @am__fastdepCC_TRUE@   $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
 @am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
-@am__fastdepCC_FALSE@  $(AM_V_CC) @AM_BACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@  $(LTCOMPILE) -c -o $@ $<
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $<
 
 mostlyclean-libtool:
        -rm -f *.lo
@@ -473,10 +512,15 @@ install-am: all-am
 
 installcheck: installcheck-am
 install-strip:
-       $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
-         install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
-         `test -z '$(STRIP)' || \
-           echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+       if test -z '$(STRIP)'; then \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+             install; \
+       else \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+           "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+       fi
 mostlyclean-generic:
 
 clean-generic:
index 7bdd172..0ff3299 100644 (file)
@@ -1,3 +1,3 @@
 /* The old i810 (only) driver. */
 const OptionInfoRec *lg_i810_available_options(int chipid, int busid);
-void lg_i810_init(ScrnInfoPtr scrn);
+Bool lg_i810_init(ScrnInfoPtr scrn);
index 1a19437..1704036 100644 (file)
@@ -15,12 +15,16 @@ INTEL_G4A =                         \
        exa_wm_ca_srcalpha.g4a          \
        exa_wm_write.g4a                \
        exa_wm_yuv_rgb.g4a              \
-       exa_wm_xy.g4a
+       exa_wm_xy.g4a                   \
+       $(NULL)
 
 INTEL_G4I =                            \
        exa_wm.g4i                      \
        exa_wm_affine.g4i               \
-       exa_wm_projective.g4i
+       exa_wm_projective.g4i           \
+       exa_wm_sample_planar.g4i        \
+       exa_wm_src_sample_argb.g4i      \
+       $(NULL)
 
 INTEL_G4B =                            \
        exa_sf.g4b                      \
@@ -39,7 +43,8 @@ INTEL_G4B =                           \
        exa_wm_ca_srcalpha.g4b          \
        exa_wm_write.g4b                \
        exa_wm_yuv_rgb.g4b              \
-       exa_wm_xy.g4b
+       exa_wm_xy.g4b                   \
+       $(NULL)
 
 
 INTEL_G4B_GEN5 =                               \
@@ -59,7 +64,53 @@ INTEL_G4B_GEN5 =                             \
        exa_wm_ca_srcalpha.g4b.gen5             \
        exa_wm_write.g4b.gen5                   \
        exa_wm_yuv_rgb.g4b.gen5                 \
-       exa_wm_xy.g4b.gen5
+       exa_wm_xy.g4b.gen5                      \
+       $(NULL)
+
+INTEL_G5A =                            \
+       exa_sf.g5a                      \
+       exa_sf_mask.g5a                 \
+       exa_wm_src_affine.g5a           \
+       exa_wm_src_projective.g5a       \
+       exa_wm_src_sample_argb.g5a      \
+       exa_wm_src_sample_a.g5a         \
+       exa_wm_src_sample_planar.g5a    \
+       exa_wm_mask_affine.g5a          \
+       exa_wm_mask_projective.g5a      \
+       exa_wm_mask_sample_argb.g5a     \
+       exa_wm_mask_sample_a.g5a        \
+       exa_wm_noca.g5a                 \
+       exa_wm_ca.g5a                   \
+       exa_wm_ca_srcalpha.g5a          \
+       exa_wm_write.g5a                \
+       exa_wm_yuv_rgb.g5a              \
+       exa_wm_xy.g5a                   \
+       $(NULL)
+
+INTEL_G5B =                            \
+       exa_sf.g5b                      \
+       exa_sf_mask.g5b                 \
+       exa_wm_src_affine.g5b           \
+       exa_wm_src_projective.g5b       \
+       exa_wm_src_sample_argb.g5b      \
+       exa_wm_src_sample_a.g5b         \
+       exa_wm_src_sample_planar.g5b    \
+       exa_wm_mask_affine.g5b          \
+       exa_wm_mask_projective.g5b      \
+       exa_wm_mask_sample_argb.g5b     \
+       exa_wm_mask_sample_a.g5b        \
+       exa_wm_noca.g5b                 \
+       exa_wm_ca.g5b                   \
+       exa_wm_ca_srcalpha.g5b          \
+       exa_wm_write.g5b                \
+       exa_wm_yuv_rgb.g5b              \
+       exa_wm_xy.g5b                   \
+       $(NULL)
+
+INTEL_G6I =                            \
+       exa_wm_affine.g6i               \
+       exa_wm_write.g6i                \
+       $(NULL)
 
 INTEL_G6A =                            \
        exa_wm_src_affine.g6a           \
@@ -75,7 +126,8 @@ INTEL_G6A =                          \
        exa_wm_ca_srcalpha.g6a          \
        exa_wm_noca.g6a                 \
        exa_wm_write.g6a                \
-       exa_wm_yuv_rgb.g6a
+       exa_wm_yuv_rgb.g6a              \
+       $(NULL)
 
 INTEL_G6B =                            \
        exa_wm_src_affine.g6b           \
@@ -91,31 +143,75 @@ INTEL_G6B =                                \
        exa_wm_ca_srcalpha.g6b          \
        exa_wm_noca.g6b                 \
        exa_wm_write.g6b                \
-       exa_wm_yuv_rgb.g6b
+       exa_wm_yuv_rgb.g6b              \
+       $(NULL)
+
+INTEL_G7A =                            \
+       exa_wm_mask_affine.g7a          \
+       exa_wm_mask_projective.g7a      \
+       exa_wm_mask_sample_a.g7a        \
+       exa_wm_mask_sample_argb.g7a     \
+       exa_wm_src_affine.g7a           \
+       exa_wm_src_projective.g7a       \
+       exa_wm_src_sample_a.g7a         \
+       exa_wm_src_sample_argb.g7a      \
+       exa_wm_src_sample_planar.g7a    \
+       exa_wm_write.g7a                \
+       exa_wm_yuv_rgb.g7a              \
+       $(NULL)
+
+INTEL_G7B =                            \
+       exa_wm_mask_affine.g7b          \
+       exa_wm_mask_projective.g7b      \
+       exa_wm_mask_sample_a.g7b        \
+       exa_wm_mask_sample_argb.g7b     \
+       exa_wm_src_affine.g7b           \
+       exa_wm_src_projective.g7b       \
+       exa_wm_src_sample_a.g7b         \
+       exa_wm_src_sample_argb.g7b      \
+       exa_wm_src_sample_planar.g7b    \
+       exa_wm_write.g7b                \
+       exa_wm_yuv_rgb.g7b              \
+       $(NULL)
 
 EXTRA_DIST =           \
        $(INTEL_G4A)    \
        $(INTEL_G4I)    \
        $(INTEL_G4B)    \
        $(INTEL_G4B_GEN5)\
+       $(INTEL_G5A)    \
+       $(INTEL_G5B)    \
        $(INTEL_G6A)    \
-       $(INTEL_G6B)
+       $(INTEL_G6B)    \
+       $(INTEL_G6I)    \
+       $(INTEL_G7A)    \
+       $(INTEL_G7B)
 
 if HAVE_GEN4ASM
 
-SUFFIXES = .g4a .g4b .g6a .g6b
+SUFFIXES = .g4a .g4b .g5a .g5b .g6a .g6b .g7a .g7b
 .g4a.g4b:
        m4 -I$(srcdir) -s $< > $*.g4m && intel-gen4asm -o $@ $*.g4m && intel-gen4asm -g 5 -o $@.gen5 $*.g4m && rm $*.g4m
 
+.g5a.g5b:
+       m4 -I$(srcdir) -s $< > $*.g5m && intel-gen4asm -g 5 -o $@ $*.g5m && rm $*.g5m
+
 .g6a.g6b:
        m4 -I$(srcdir) -s $< > $*.g6m && intel-gen4asm -g 6 -o $@ $*.g6m && rm $*.g6m
 
+.g7a.g7b:
+       m4 -I$(srcdir) -s $< > $*.g7m && intel-gen4asm -g 7 -o $@ $*.g7m && rm $*.g7m
+
 $(INTEL_G4B): $(INTEL_G4I)
-$(INTEL_G6B): $(INTEL_G4I)
+$(INTEL_G5B): $(INTEL_G4I)
+$(INTEL_G6B): $(INTEL_G4I) $(INTEL_G6I)
+$(INTEL_G7B): $(INTEL_G4I) $(INTEL_G6I)
 
-BUILT_SOURCES= $(INTEL_G4B) $(INTEL_G6B)
+BUILT_SOURCES= $(INTEL_G4B) $(INTEL_G5B) $(INTEL_G6B) $(INTEL_G7B)
 
 clean-local:
        -rm -f $(INTEL_G4B) $(INTEL_G4B_GEN5)
+       -rm -f $(INTEL_G5B)
        -rm -f $(INTEL_G6B)
+       -rm -f $(INTEL_G7B)
 endif
index c96a02c..1e1dadd 100644 (file)
@@ -1,9 +1,9 @@
-# Makefile.in generated by automake 1.11.1 from Makefile.am.
+# Makefile.in generated by automake 1.11.6 from Makefile.am.
 # @configure_input@
 
 # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-# 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
-# Inc.
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
+# Foundation, Inc.
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
 
 @SET_MAKE@
 VPATH = @srcdir@
+am__make_dryrun = \
+  { \
+    am__dry=no; \
+    case $$MAKEFLAGS in \
+      *\\[\ \  ]*) \
+        echo 'am--echo: ; @echo "AM"  OK' | $(MAKE) -f - 2>/dev/null \
+          | grep '^AM OK$$' >/dev/null || am__dry=yes;; \
+      *) \
+        for am__flg in $$MAKEFLAGS; do \
+          case $$am__flg in \
+            *=*|--*) ;; \
+            *n*) am__dry=yes; break;; \
+          esac; \
+        done;; \
+    esac; \
+    test $$am__dry = yes; \
+  }
 pkgdatadir = $(datadir)/@PACKAGE@
 pkgincludedir = $(includedir)/@PACKAGE@
 pkglibdir = $(libdir)/@PACKAGE@
@@ -36,24 +53,26 @@ host_triplet = @host@
 subdir = src/render_program
 DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
-       $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
-       $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
-       $(top_srcdir)/configure.ac
+am__aclocal_m4_deps = $(top_srcdir)/configure.ac
 am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
        $(ACLOCAL_M4)
 mkinstalldirs = $(install_sh) -d
 CONFIG_HEADER = $(top_builddir)/config.h
 CONFIG_CLEAN_FILES =
 CONFIG_CLEAN_VPATH_FILES =
-AM_V_GEN = $(am__v_GEN_$(V))
-am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY))
+AM_V_GEN = $(am__v_GEN_@AM_V@)
+am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
 am__v_GEN_0 = @echo "  GEN   " $@;
-AM_V_at = $(am__v_at_$(V))
-am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY))
+AM_V_at = $(am__v_at_@AM_V@)
+am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
 am__v_at_0 = @
 SOURCES =
 DIST_SOURCES =
+am__can_run_installinfo = \
+  case $$AM_UPDATE_INFO_DIR in \
+    n|no|NO) false;; \
+    *) (install-info --version) >/dev/null 2>&1;; \
+  esac
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
 ACLOCAL = @ACLOCAL@
 ADMIN_MAN_DIR = @ADMIN_MAN_DIR@
@@ -67,6 +86,7 @@ AUTOCONF = @AUTOCONF@
 AUTOHEADER = @AUTOHEADER@
 AUTOMAKE = @AUTOMAKE@
 AWK = @AWK@
+BASE_CFLAGS = @BASE_CFLAGS@
 CC = @CC@
 CCDEPMODE = @CCDEPMODE@
 CFLAGS = @CFLAGS@
@@ -77,11 +97,16 @@ CWARNFLAGS = @CWARNFLAGS@
 CYGPATH_W = @CYGPATH_W@
 DEFS = @DEFS@
 DEPDIR = @DEPDIR@
+DLLTOOL = @DLLTOOL@
+DRI2_CFLAGS = @DRI2_CFLAGS@
+DRI2_LIBS = @DRI2_LIBS@
 DRIVER_MAN_DIR = @DRIVER_MAN_DIR@
 DRIVER_MAN_SUFFIX = @DRIVER_MAN_SUFFIX@
 DRIVER_NAME = @DRIVER_NAME@
 DRI_CFLAGS = @DRI_CFLAGS@
 DRI_LIBS = @DRI_LIBS@
+DRMINTEL_CFLAGS = @DRMINTEL_CFLAGS@
+DRMINTEL_LIBS = @DRMINTEL_LIBS@
 DRM_CFLAGS = @DRM_CFLAGS@
 DRM_LIBS = @DRM_LIBS@
 DSYMUTIL = @DSYMUTIL@
@@ -105,6 +130,10 @@ INSTALL_SCRIPT = @INSTALL_SCRIPT@
 INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
 LD = @LD@
 LDFLAGS = @LDFLAGS@
+LIBGLAMOR_CFLAGS = @LIBGLAMOR_CFLAGS@
+LIBGLAMOR_EGL_CFLAGS = @LIBGLAMOR_EGL_CFLAGS@
+LIBGLAMOR_EGL_LIBS = @LIBGLAMOR_EGL_LIBS@
+LIBGLAMOR_LIBS = @LIBGLAMOR_LIBS@
 LIBOBJS = @LIBOBJS@
 LIBS = @LIBS@
 LIBTOOL = @LIBTOOL@
@@ -115,6 +144,7 @@ LN_S = @LN_S@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MANIFEST_TOOL = @MANIFEST_TOOL@
 MAN_SUBSTS = @MAN_SUBSTS@
 MISC_MAN_DIR = @MISC_MAN_DIR@
 MISC_MAN_SUFFIX = @MISC_MAN_SUFFIX@
@@ -142,10 +172,15 @@ RANLIB = @RANLIB@
 SED = @SED@
 SET_MAKE = @SET_MAKE@
 SHELL = @SHELL@
+STRICT_CFLAGS = @STRICT_CFLAGS@
 STRIP = @STRIP@
 UDEV_CFLAGS = @UDEV_CFLAGS@
 UDEV_LIBS = @UDEV_LIBS@
+VALGRIND_CFLAGS = @VALGRIND_CFLAGS@
+VALGRIND_LIBS = @VALGRIND_LIBS@
 VERSION = @VERSION@
+X11_CFLAGS = @X11_CFLAGS@
+X11_LIBS = @X11_LIBS@
 XORG_CFLAGS = @XORG_CFLAGS@
 XORG_LIBS = @XORG_LIBS@
 XORG_MAN_PAGE = @XORG_MAN_PAGE@
@@ -155,6 +190,7 @@ abs_builddir = @abs_builddir@
 abs_srcdir = @abs_srcdir@
 abs_top_builddir = @abs_top_builddir@
 abs_top_srcdir = @abs_top_srcdir@
+ac_ct_AR = @ac_ct_AR@
 ac_ct_CC = @ac_ct_CC@
 ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
 am__include = @am__include@
@@ -187,7 +223,6 @@ libdir = @libdir@
 libexecdir = @libexecdir@
 localedir = @localedir@
 localstatedir = @localstatedir@
-lt_ECHO = @lt_ECHO@
 mandir = @mandir@
 mkdir_p = @mkdir_p@
 moduledir = @moduledir@
@@ -221,12 +256,16 @@ INTEL_G4A = \
        exa_wm_ca_srcalpha.g4a          \
        exa_wm_write.g4a                \
        exa_wm_yuv_rgb.g4a              \
-       exa_wm_xy.g4a
+       exa_wm_xy.g4a                   \
+       $(NULL)
 
 INTEL_G4I = \
        exa_wm.g4i                      \
        exa_wm_affine.g4i               \
-       exa_wm_projective.g4i
+       exa_wm_projective.g4i           \
+       exa_wm_sample_planar.g4i        \
+       exa_wm_src_sample_argb.g4i      \
+       $(NULL)
 
 INTEL_G4B = \
        exa_sf.g4b                      \
@@ -245,7 +284,8 @@ INTEL_G4B = \
        exa_wm_ca_srcalpha.g4b          \
        exa_wm_write.g4b                \
        exa_wm_yuv_rgb.g4b              \
-       exa_wm_xy.g4b
+       exa_wm_xy.g4b                   \
+       $(NULL)
 
 INTEL_G4B_GEN5 = \
        exa_sf.g4b.gen5                         \
@@ -264,7 +304,53 @@ INTEL_G4B_GEN5 = \
        exa_wm_ca_srcalpha.g4b.gen5             \
        exa_wm_write.g4b.gen5                   \
        exa_wm_yuv_rgb.g4b.gen5                 \
-       exa_wm_xy.g4b.gen5
+       exa_wm_xy.g4b.gen5                      \
+       $(NULL)
+
+INTEL_G5A = \
+       exa_sf.g5a                      \
+       exa_sf_mask.g5a                 \
+       exa_wm_src_affine.g5a           \
+       exa_wm_src_projective.g5a       \
+       exa_wm_src_sample_argb.g5a      \
+       exa_wm_src_sample_a.g5a         \
+       exa_wm_src_sample_planar.g5a    \
+       exa_wm_mask_affine.g5a          \
+       exa_wm_mask_projective.g5a      \
+       exa_wm_mask_sample_argb.g5a     \
+       exa_wm_mask_sample_a.g5a        \
+       exa_wm_noca.g5a                 \
+       exa_wm_ca.g5a                   \
+       exa_wm_ca_srcalpha.g5a          \
+       exa_wm_write.g5a                \
+       exa_wm_yuv_rgb.g5a              \
+       exa_wm_xy.g5a                   \
+       $(NULL)
+
+INTEL_G5B = \
+       exa_sf.g5b                      \
+       exa_sf_mask.g5b                 \
+       exa_wm_src_affine.g5b           \
+       exa_wm_src_projective.g5b       \
+       exa_wm_src_sample_argb.g5b      \
+       exa_wm_src_sample_a.g5b         \
+       exa_wm_src_sample_planar.g5b    \
+       exa_wm_mask_affine.g5b          \
+       exa_wm_mask_projective.g5b      \
+       exa_wm_mask_sample_argb.g5b     \
+       exa_wm_mask_sample_a.g5b        \
+       exa_wm_noca.g5b                 \
+       exa_wm_ca.g5b                   \
+       exa_wm_ca_srcalpha.g5b          \
+       exa_wm_write.g5b                \
+       exa_wm_yuv_rgb.g5b              \
+       exa_wm_xy.g5b                   \
+       $(NULL)
+
+INTEL_G6I = \
+       exa_wm_affine.g6i               \
+       exa_wm_write.g6i                \
+       $(NULL)
 
 INTEL_G6A = \
        exa_wm_src_affine.g6a           \
@@ -280,7 +366,8 @@ INTEL_G6A = \
        exa_wm_ca_srcalpha.g6a          \
        exa_wm_noca.g6a                 \
        exa_wm_write.g6a                \
-       exa_wm_yuv_rgb.g6a
+       exa_wm_yuv_rgb.g6a              \
+       $(NULL)
 
 INTEL_G6B = \
        exa_wm_src_affine.g6b           \
@@ -296,23 +383,57 @@ INTEL_G6B = \
        exa_wm_ca_srcalpha.g6b          \
        exa_wm_noca.g6b                 \
        exa_wm_write.g6b                \
-       exa_wm_yuv_rgb.g6b
+       exa_wm_yuv_rgb.g6b              \
+       $(NULL)
+
+INTEL_G7A = \
+       exa_wm_mask_affine.g7a          \
+       exa_wm_mask_projective.g7a      \
+       exa_wm_mask_sample_a.g7a        \
+       exa_wm_mask_sample_argb.g7a     \
+       exa_wm_src_affine.g7a           \
+       exa_wm_src_projective.g7a       \
+       exa_wm_src_sample_a.g7a         \
+       exa_wm_src_sample_argb.g7a      \
+       exa_wm_src_sample_planar.g7a    \
+       exa_wm_write.g7a                \
+       exa_wm_yuv_rgb.g7a              \
+       $(NULL)
+
+INTEL_G7B = \
+       exa_wm_mask_affine.g7b          \
+       exa_wm_mask_projective.g7b      \
+       exa_wm_mask_sample_a.g7b        \
+       exa_wm_mask_sample_argb.g7b     \
+       exa_wm_src_affine.g7b           \
+       exa_wm_src_projective.g7b       \
+       exa_wm_src_sample_a.g7b         \
+       exa_wm_src_sample_argb.g7b      \
+       exa_wm_src_sample_planar.g7b    \
+       exa_wm_write.g7b                \
+       exa_wm_yuv_rgb.g7b              \
+       $(NULL)
 
 EXTRA_DIST = \
        $(INTEL_G4A)    \
        $(INTEL_G4I)    \
        $(INTEL_G4B)    \
        $(INTEL_G4B_GEN5)\
+       $(INTEL_G5A)    \
+       $(INTEL_G5B)    \
        $(INTEL_G6A)    \
-       $(INTEL_G6B)
+       $(INTEL_G6B)    \
+       $(INTEL_G6I)    \
+       $(INTEL_G7A)    \
+       $(INTEL_G7B)
 
-@HAVE_GEN4ASM_TRUE@SUFFIXES = .g4a .g4b .g6a .g6b
-@HAVE_GEN4ASM_TRUE@BUILT_SOURCES = $(INTEL_G4B) $(INTEL_G6B)
+@HAVE_GEN4ASM_TRUE@SUFFIXES = .g4a .g4b .g5a .g5b .g6a .g6b .g7a .g7b
+@HAVE_GEN4ASM_TRUE@BUILT_SOURCES = $(INTEL_G4B) $(INTEL_G5B) $(INTEL_G6B) $(INTEL_G7B)
 all: $(BUILT_SOURCES)
        $(MAKE) $(AM_MAKEFLAGS) all-am
 
 .SUFFIXES:
-.SUFFIXES: .g4a .g4b .g6a .g6b
+.SUFFIXES: .g4a .g4b .g5a .g5b .g6a .g6b .g7a .g7b
 $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am  $(am__configure_deps)
        @for dep in $?; do \
          case '$(am__configure_deps)' in \
@@ -402,10 +523,15 @@ install-am: all-am
 
 installcheck: installcheck-am
 install-strip:
-       $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
-         install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
-         `test -z '$(STRIP)' || \
-           echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+       if test -z '$(STRIP)'; then \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+             install; \
+       else \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+           "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+       fi
 mostlyclean-generic:
 
 clean-generic:
@@ -502,15 +628,25 @@ uninstall-am:
 @HAVE_GEN4ASM_TRUE@.g4a.g4b:
 @HAVE_GEN4ASM_TRUE@    m4 -I$(srcdir) -s $< > $*.g4m && intel-gen4asm -o $@ $*.g4m && intel-gen4asm -g 5 -o $@.gen5 $*.g4m && rm $*.g4m
 
+@HAVE_GEN4ASM_TRUE@.g5a.g5b:
+@HAVE_GEN4ASM_TRUE@    m4 -I$(srcdir) -s $< > $*.g5m && intel-gen4asm -g 5 -o $@ $*.g5m && rm $*.g5m
+
 @HAVE_GEN4ASM_TRUE@.g6a.g6b:
 @HAVE_GEN4ASM_TRUE@    m4 -I$(srcdir) -s $< > $*.g6m && intel-gen4asm -g 6 -o $@ $*.g6m && rm $*.g6m
 
+@HAVE_GEN4ASM_TRUE@.g7a.g7b:
+@HAVE_GEN4ASM_TRUE@    m4 -I$(srcdir) -s $< > $*.g7m && intel-gen4asm -g 7 -o $@ $*.g7m && rm $*.g7m
+
 @HAVE_GEN4ASM_TRUE@$(INTEL_G4B): $(INTEL_G4I)
-@HAVE_GEN4ASM_TRUE@$(INTEL_G6B): $(INTEL_G4I)
+@HAVE_GEN4ASM_TRUE@$(INTEL_G5B): $(INTEL_G4I)
+@HAVE_GEN4ASM_TRUE@$(INTEL_G6B): $(INTEL_G4I) $(INTEL_G6I)
+@HAVE_GEN4ASM_TRUE@$(INTEL_G7B): $(INTEL_G4I) $(INTEL_G6I)
 
 @HAVE_GEN4ASM_TRUE@clean-local:
 @HAVE_GEN4ASM_TRUE@    -rm -f $(INTEL_G4B) $(INTEL_G4B_GEN5)
+@HAVE_GEN4ASM_TRUE@    -rm -f $(INTEL_G5B)
 @HAVE_GEN4ASM_TRUE@    -rm -f $(INTEL_G6B)
+@HAVE_GEN4ASM_TRUE@    -rm -f $(INTEL_G7B)
 
 # Tell versions [3.59,3.63) of GNU make to not export all variables.
 # Otherwise a system limit (for SysV at least) may be exceeded.
diff --git a/src/render_program/exa_sf.g5a b/src/render_program/exa_sf.g5a
new file mode 100644 (file)
index 0000000..a5dd0ee
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * Copyright © 2006 Intel 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.
+ *
+ * Authors:
+ *    Keith Packard <keithp@keithp.com>
+ *    Eric Anholt <eric@anholt.net>
+ *
+ */
+
+/*
+ * Inputs (note all sub-register addresses are bytes, not float indices)
+ *
+ * Note that the vertices will have been reordered:
+ *
+ * V0 is topmost (leftmost among topmost) (upper left)
+ * V1 is next clockwise (lower right)
+ * V2 is remaining (lower left)
+ *
+ *  V0 ...................... XX
+ *  |                          .
+ *  |                          .
+ *  |                          .
+ *  V2------------------------V1
+ *
+ *  G0     thread state -- just pass along
+ *
+ *  G1 and G2 are fixed by SF spec
+ *
+ *  G1.0    reserved
+ *  G1.4    Provoking vertex
+ *  G1.8    Determinant
+ *  G1.12   X1 - X0
+ *  G1.16   X2 - X0
+ *  G1.20   Y1 - Y0
+ *  G1.24   Y2 - Y0
+ *  G1.30   reserved
+ *
+ *  G2.0    Z0
+ *  G2.4    1/W0
+ *  G2.8    Z1
+ *  G2.12   1/W1
+ *  G2.16   Z2
+ *  G2.20   1/W2
+ *  G2.24   reserved
+ *  G2.30   reserved
+ *
+ *  G3 is V0 Vertex Attribute Data from URB (upper left)
+ *
+ *  G3.0    u0
+ *  G3.4    v0
+ *
+ *  G4 is V1 Vertex Attribute Data from URB (lower right)
+ *
+ *  G4.0    u1
+ *  G4.4    v1
+ *
+ *  G5 is V2 Vertex Attribute Data from URB (lower left)
+ *
+ */
+
+/* Compute inverses of the input deltas */
+send (4) 0 g6<1>F g1.12<4,4,1>F math inv mlen 1 rlen 1 { align1 };
+
+/* texture location at V0 */
+mov (4) m3<1>F g3<4,4,1>F { align1 };
+
+/* compute V1 - V2 (motion in X) for texture coordinates */
+add (4) g7<1>F g4<4,4,1>F -g5<4,4,1>F { align1 };
+
+/* multiply by 1/dx */
+mul (4) m1<1>F g7<4,4,1>F g6.0<0,1,0>F { align1 };
+
+/* Compute V2 - V0 (motion in Y) for texture coordinates */
+add (4) g7<1>F g5<4,4,1>F -g3<4,4,1>F { align1 };
+
+/* multiply by 1/dy */
+mul (4) m2<1>F g7<4,4,1>F g6.8<0,1,0>F {align1 };
+
+/* and we're done */
+send (8) 0 null g0<8,8,1>F urb 0 transpose used complete mlen 4 rlen 0 { align1 EOT };
diff --git a/src/render_program/exa_sf.g5b b/src/render_program/exa_sf.g5b
new file mode 100644 (file)
index 0000000..d1035ae
--- /dev/null
@@ -0,0 +1,7 @@
+   { 0x00400031, 0x20c01fbd, 0x1069002c, 0x02100001 },
+   { 0x00400001, 0x206003be, 0x00690060, 0x00000000 },
+   { 0x00400040, 0x20e077bd, 0x00690080, 0x006940a0 },
+   { 0x00400041, 0x202077be, 0x006900e0, 0x000000c0 },
+   { 0x00400040, 0x20e077bd, 0x006900a0, 0x00694060 },
+   { 0x00400041, 0x204077be, 0x006900e0, 0x000000c8 },
+   { 0x00600031, 0x20001fbc, 0x648d0000, 0x8808c800 },
diff --git a/src/render_program/exa_sf_mask.g5a b/src/render_program/exa_sf_mask.g5a
new file mode 100644 (file)
index 0000000..b4e984c
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * Copyright © 2006 Intel 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.
+ *
+ * Authors:
+ *    Keith Packard <keithp@keithp.com>
+ *    Eric Anholt <eric@anholt.net>
+ *    Wang Zhenyu <zhenyu.z.wang@intel.com>
+ */
+
+/*
+ * Inputs (note all sub-register addresses are bytes, not float indices)
+ *
+ * Note that the vertices will have been reordered:
+ *
+ * V0 is topmost (leftmost among topmost) (upper left)
+ * V1 is next clockwise (lower right)
+ * V2 is remaining (lower left)
+ *
+ *  V0 ...................... XX
+ *  |                          .
+ *  |                          .
+ *  |                          .
+ *  V2------------------------V1
+ *
+ *  G0     thread state -- just pass along
+ *
+ *  G1 and G2 are fixed by SF spec
+ *
+ *  G1.0    reserved
+ *  G1.4    Provoking vertex
+ *  G1.8    Determinant
+ *  G1.12   X1 - X0
+ *  G1.16   X2 - X0
+ *  G1.20   Y1 - Y0
+ *  G1.24   Y2 - Y0
+ *  G1.30   reserved
+ *
+ *  G2.0    Z0
+ *  G2.4    1/W0
+ *  G2.8    Z1
+ *  G2.12   1/W1
+ *  G2.16   Z2
+ *  G2.20   1/W2
+ *  G2.24   reserved
+ *  G2.30   reserved
+ *
+ *  G3 is V0 Vertex Attribute Data from URB (upper left)
+ *
+ *  G3.0    u0
+ *  G3.4    v0
+ *
+ *  G4 is V1 Vertex Attribute Data from URB (lower right)
+ *
+ *  G4.0    u1
+ *  G4.4    v1
+ *
+ *  G5 is V2 Vertex Attribute Data from URB (lower left)
+ *
+ */
+
+/* Compute inverses of the input deltas */
+send (4) 0 g6<1>F g1.12<4,4,1>F math inv mlen 1 rlen 1 { align1 };
+
+/* texture location at V0 */
+mov (8) m3<1>F g3<8,8,1>F { align1 };
+
+/* compute V1 - V2 (motion in X) for texture coordinates */
+add (8) g7<1>F g4<8,8,1>F -g5<8,8,1>F { align1 };
+
+/* multiply by 1/dx */
+mul (8) m1<1>F g7<8,8,1>F g6.0<0,1,0>F { align1 };
+
+/* Compute V2 - V0 (motion in Y) for texture coordinates */
+add (8) g7<1>F g5<8,8,1>F -g3<8,8,1>F { align1 };
+
+/* multiply by 1/dy */
+mul (8) m2<1>F g7<8,8,1>F g6.8<0,1,0>F {align1 };
+
+/* and we're done */
+send (8) 0 null g0<8,8,1>F urb 0 transpose used complete mlen 4 rlen 0 { align1 EOT };
diff --git a/src/render_program/exa_sf_mask.g5b b/src/render_program/exa_sf_mask.g5b
new file mode 100644 (file)
index 0000000..76a03f8
--- /dev/null
@@ -0,0 +1,7 @@
+   { 0x00400031, 0x20c01fbd, 0x1069002c, 0x02100001 },
+   { 0x00600001, 0x206003be, 0x008d0060, 0x00000000 },
+   { 0x00600040, 0x20e077bd, 0x008d0080, 0x008d40a0 },
+   { 0x00600041, 0x202077be, 0x008d00e0, 0x000000c0 },
+   { 0x00600040, 0x20e077bd, 0x008d00a0, 0x008d4060 },
+   { 0x00600041, 0x204077be, 0x008d00e0, 0x000000c8 },
+   { 0x00600031, 0x20001fbc, 0x648d0000, 0x8808c800 },
diff --git a/src/render_program/exa_wm_affine.g6i b/src/render_program/exa_wm_affine.g6i
new file mode 100644 (file)
index 0000000..9ac21d5
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright © 2010-2011 Intel 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.
+ *
+ */
+
+/*
+ * Fragment to compute src u/v values
+ */
+
+/* U */
+pln (8) ul<1>F a0_a_x bl { align1 }; /* pixel 0-7 */
+pln (8) uh<1>F a0_a_x bh { align1 }; /* pixel 8-15 */
+
+/* V */
+pln (8) vl<1>F a0_a_y bl { align1 }; /* pixel 0-7 */
+pln (8) vh<1>F a0_a_y bh { align1 }; /* pixel 8-15 */
diff --git a/src/render_program/exa_wm_ca.g5a b/src/render_program/exa_wm_ca.g5a
new file mode 100644 (file)
index 0000000..5d982b3
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright © 2006 Intel 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.
+ *
+ * Authors:
+ *    Wang Zhenyu <zhenyu.z.wang@intel.com>
+ *    Keith Packard <keithp@keithp.com>
+ */
+/*
+ * Composite src and mask together, no component alpha
+ */
+
+include(`exa_wm.g4i')
+
+/* mul mask rgba channels to src */
+mul (16)    src_sample_r_01<1>F        src_sample_r_01<8,8,1>F mask_sample_r_01<8,8,1>F { compr align1 };
+mul (16)    src_sample_g_01<1>F src_sample_g_01<8,8,1>F        mask_sample_g_01<8,8,1>F { compr align1 };
+mul (16)    src_sample_b_01<1>F src_sample_b_01<8,8,1>F        mask_sample_b_01<8,8,1>F { compr align1 };
+mul (16)    src_sample_a_01<1>F src_sample_a_01<8,8,1>F        mask_sample_a_01<8,8,1>F { compr align1 };
diff --git a/src/render_program/exa_wm_ca.g5b b/src/render_program/exa_wm_ca.g5b
new file mode 100644 (file)
index 0000000..372e8b2
--- /dev/null
@@ -0,0 +1,4 @@
+   { 0x00802041, 0x21c077bd, 0x008d01c0, 0x008d02c0 },
+   { 0x00802041, 0x220077bd, 0x008d0200, 0x008d0300 },
+   { 0x00802041, 0x224077bd, 0x008d0240, 0x008d0340 },
+   { 0x00802041, 0x228077bd, 0x008d0280, 0x008d0380 },
diff --git a/src/render_program/exa_wm_ca_srcalpha.g5a b/src/render_program/exa_wm_ca_srcalpha.g5a
new file mode 100644 (file)
index 0000000..d1f847f
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright © 2006 Intel 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.
+ *
+ * Authors:
+ *    Wang Zhenyu <zhenyu.z.wang@intel.com>
+ *    Keith Packard <keithp@keithp.com>
+ */
+/*
+ * Composite src and mask together, no component alpha
+ */
+
+include(`exa_wm.g4i')
+
+mul (16)    src_sample_r_01<1>F mask_sample_r_01<8,8,1>F src_sample_a_01<8,8,1>F { compr align1 };
+mul (16)    src_sample_g_01<1>F mask_sample_g_01<8,8,1>F src_sample_a_01<8,8,1>F { compr align1 };
+mul (16)    src_sample_b_01<1>F mask_sample_b_01<8,8,1>F src_sample_a_01<8,8,1>F { compr align1 };
+mul (16)    src_sample_a_01<1>F mask_sample_a_01<8,8,1>F src_sample_a_01<8,8,1>F { compr align1 };
diff --git a/src/render_program/exa_wm_ca_srcalpha.g5b b/src/render_program/exa_wm_ca_srcalpha.g5b
new file mode 100644 (file)
index 0000000..963d676
--- /dev/null
@@ -0,0 +1,4 @@
+   { 0x00802041, 0x21c077bd, 0x008d02c0, 0x008d0280 },
+   { 0x00802041, 0x220077bd, 0x008d0300, 0x008d0280 },
+   { 0x00802041, 0x224077bd, 0x008d0340, 0x008d0280 },
+   { 0x00802041, 0x228077bd, 0x008d0380, 0x008d0280 },
diff --git a/src/render_program/exa_wm_mask_affine.g5a b/src/render_program/exa_wm_mask_affine.g5a
new file mode 100644 (file)
index 0000000..d3f498e
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Copyright © 2010 Intel 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(`exa_wm.g4i')
+
+line (16) null mask_du_dx dst_x<8,8,1>F { compr align1 };
+mac (16) mask_u mask_du_dy dst_y<8,8,1>F { compr align1 };
+
+line (16) null mask_dv_dx dst_x<8,8,1>F { compr align1 };
+mac (16) mask_v mask_dv_dy dst_y<8,8,1>F { compr align1 };
diff --git a/src/render_program/exa_wm_mask_affine.g5b b/src/render_program/exa_wm_mask_affine.g5b
new file mode 100644 (file)
index 0000000..e265bee
--- /dev/null
@@ -0,0 +1,4 @@
+   { 0x00802059, 0x200077bc, 0x000000a0, 0x008d0100 },
+   { 0x00802048, 0x210077be, 0x000000a4, 0x008d0140 },
+   { 0x00802059, 0x200077bc, 0x000000b0, 0x008d0100 },
+   { 0x00802048, 0x214077be, 0x000000b4, 0x008d0140 },
index 2daf4e2..04ad2a2 100644 (file)
@@ -38,10 +38,4 @@ define(`bh',    `g4.0<8,8,1>F')
 define(`a0_a_x',`g8.0<0,1,0>F')
 define(`a0_a_y',`g8.16<0,1,0>F')
 
-/* U */
-pln (8) ul<1>F a0_a_x bl { align1 }; /* pixel 0-7 */
-pln (8) uh<1>F a0_a_x bh { align1 }; /* pixel 8-15 */
-
-/* V */
-pln (8) vl<1>F a0_a_y bl { align1 }; /* pixel 0-7 */
-pln (8) vh<1>F a0_a_y bh { align1 }; /* pixel 8-15 */
+include(`exa_wm_affine.g6i')
diff --git a/src/render_program/exa_wm_mask_affine.g7a b/src/render_program/exa_wm_mask_affine.g7a
new file mode 100644 (file)
index 0000000..4277080
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright © 2010 Intel 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.
+ *
+ */
+
+/*
+ * Fragment to compute src u/v values
+ */
+include(`exa_wm.g4i')
+
+define(`ul',    `g72')
+define(`uh',    `g73')
+define(`vl',    `g74')
+define(`vh',    `g75')
+
+define(`bl',    `g2.0<8,8,1>F')
+define(`bh',    `g4.0<8,8,1>F')
+
+define(`a0_a_x',`g8.0<0,1,0>F')
+define(`a0_a_y',`g8.16<0,1,0>F')
+
+include(`exa_wm_affine.g6i')
diff --git a/src/render_program/exa_wm_mask_affine.g7b b/src/render_program/exa_wm_mask_affine.g7b
new file mode 100644 (file)
index 0000000..8d72599
--- /dev/null
@@ -0,0 +1,4 @@
+   { 0x0060005a, 0x290077bd, 0x00000100, 0x008d0040 },
+   { 0x0060005a, 0x292077bd, 0x00000100, 0x008d0080 },
+   { 0x0060005a, 0x294077bd, 0x00000110, 0x008d0040 },
+   { 0x0060005a, 0x296077bd, 0x00000110, 0x008d0080 },
diff --git a/src/render_program/exa_wm_mask_projective.g5a b/src/render_program/exa_wm_mask_projective.g5a
new file mode 100644 (file)
index 0000000..9acaace
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Copyright © 2006 Intel 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.
+ *
+ * Authors:
+ *    Wang Zhenyu <zhenyu.z.wang@intel.com>
+ *    Keith Packard <keithp@keithp.com>
+ */
+
+include(`exa_wm.g4i')
+
+define(`du_dx',        `mask_du_dx')
+define(`du_dy',        `mask_du_dy')
+define(`uo',   `mask_uo')
+
+define(`dv_dx',        `mask_dv_dx')
+define(`dv_dy',        `mask_dv_dy')
+define(`vo',   `mask_vo')
+
+define(`dw_dx',        `mask_dw_dx')
+define(`dw_dy',        `mask_dw_dy')
+define(`wo',   `mask_wo')
+
+define(`u',    `mask_u')
+define(`v',    `mask_v')
+define(`w',    `mask_w')
+
+define(`u_0',  `mask_u_0')
+define(`v_0',  `mask_v_0')
+define(`u_1',  `mask_u_1')
+define(`v_1',  `mask_v_1')
+define(`w_0',  `mask_w_0')
+define(`w_1',  `mask_w_1')
+
+include(`exa_wm_projective.g4i')
diff --git a/src/render_program/exa_wm_mask_projective.g5b b/src/render_program/exa_wm_mask_projective.g5b
new file mode 100644 (file)
index 0000000..c357459
--- /dev/null
@@ -0,0 +1,16 @@
+   { 0x00802041, 0x23c077bd, 0x008d0100, 0x000000c0 },
+   { 0x00802041, 0x238077bd, 0x008d0140, 0x000000c4 },
+   { 0x00802040, 0x23c077bd, 0x008d03c0, 0x008d0380 },
+   { 0x00802040, 0x23c077bd, 0x008d03c0, 0x000000cc },
+   { 0x00600031, 0x21801fbd, 0x108d03c0, 0x02100001 },
+   { 0x00600031, 0x21a01fbd, 0x108d03e0, 0x02100001 },
+   { 0x00802041, 0x23c077bd, 0x008d0100, 0x000000a0 },
+   { 0x00802041, 0x238077bd, 0x008d0140, 0x000000a4 },
+   { 0x00802040, 0x23c077bd, 0x008d03c0, 0x008d0380 },
+   { 0x00802040, 0x23c077bd, 0x008d03c0, 0x000000ac },
+   { 0x00802041, 0x210077be, 0x008d03c0, 0x008d0180 },
+   { 0x00802041, 0x23c077bd, 0x008d0100, 0x000000b0 },
+   { 0x00802041, 0x238077bd, 0x008d0140, 0x000000b4 },
+   { 0x00802040, 0x23c077bd, 0x008d03c0, 0x008d0380 },
+   { 0x00802040, 0x23c077bd, 0x008d03c0, 0x000000bc },
+   { 0x00802041, 0x214077be, 0x008d03c0, 0x008d0180 },
diff --git a/src/render_program/exa_wm_mask_projective.g7a b/src/render_program/exa_wm_mask_projective.g7a
new file mode 100644 (file)
index 0000000..ba4158f
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright © 2010 Intel 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.
+ *
+ */
+
+/*
+ * Fragment to compute src u/v values
+ */
+include(`exa_wm.g4i')
+
+define(`u',     `g72')
+define(`ul',    `g72')
+define(`uh',    `g73')
+define(`v',     `g74')
+define(`vl',    `g74')
+define(`vh',    `g75')
+define(`w',     `mask_w')
+define(`wl',    `mask_w_0')
+define(`wh',    `mask_w_1')
+
+define(`bl',    `g2.0<8,8,1>F')
+define(`bh',    `g4.0<8,8,1>F')
+
+define(`a0_a_x',`g8.0<0,1,0>F')
+define(`a0_a_y',`g8.16<0,1,0>F')
+define(`a0_a_z',`g9.0<0,1,0>F')
+
+/* W */
+pln (8) temp_x_0<1>F a0_a_z bl { align1 }; /* pixel 0-7 */
+pln (8) temp_x_1<1>F a0_a_z bh { align1 }; /* pixel 8-15 */
+math (8) wl<1>F temp_x_0<8,8,1>F null inv { align1 };
+math (8) wh<1>F temp_x_1<8,8,1>F null inv { align1 };
+
+/* U */
+pln (8) temp_x_0<1>F a0_a_x bl { align1 }; /* pixel 0-7 */
+pln (8) temp_x_1<1>F a0_a_x bh { align1 }; /* pixel 8-15 */
+mul (8) ul<1>F temp_x_0<8,8,1>F wl<8,8,1>F { align1 };
+mul (8) uh<1>F temp_x_1<8,8,1>F wh<8,8,1>F { align1 };
+
+/* V */
+pln (8) temp_x_0<1>F a0_a_y bl { align1 }; /* pixel 0-7 */
+pln (8) temp_x_1<1>F a0_a_y bh { align1 }; /* pixel 8-15 */
+mul (8) vl<1>F temp_x_0<8,8,1>F wl<8,8,1>F { align1 };
+mul (8) vh<1>F temp_x_1<8,8,1>F wh<8,8,1>F { align1 };
diff --git a/src/render_program/exa_wm_mask_projective.g7b b/src/render_program/exa_wm_mask_projective.g7b
new file mode 100644 (file)
index 0000000..a2e9267
--- /dev/null
@@ -0,0 +1,12 @@
+   { 0x0060005a, 0x23c077bd, 0x00000120, 0x008d0040 },
+   { 0x0060005a, 0x23e077bd, 0x00000120, 0x008d0080 },
+   { 0x01600038, 0x218003bd, 0x008d03c0, 0x00000000 },
+   { 0x01600038, 0x21a003bd, 0x008d03e0, 0x00000000 },
+   { 0x0060005a, 0x23c077bd, 0x00000100, 0x008d0040 },
+   { 0x0060005a, 0x23e077bd, 0x00000100, 0x008d0080 },
+   { 0x00600041, 0x290077bd, 0x008d03c0, 0x008d0180 },
+   { 0x00600041, 0x292077bd, 0x008d03e0, 0x008d01a0 },
+   { 0x0060005a, 0x23c077bd, 0x00000110, 0x008d0040 },
+   { 0x0060005a, 0x23e077bd, 0x00000110, 0x008d0080 },
+   { 0x00600041, 0x294077bd, 0x008d03c0, 0x008d0180 },
+   { 0x00600041, 0x296077bd, 0x008d03e0, 0x008d01a0 },
diff --git a/src/render_program/exa_wm_mask_sample_a.g5a b/src/render_program/exa_wm_mask_sample_a.g5a
new file mode 100644 (file)
index 0000000..b1c75af
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright © 2006 Intel 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.
+ *
+ * Authors:
+ *    Wang Zhenyu <zhenyu.z.wang@intel.com>
+ *    Keith Packard <keithp@keithp.com>
+ */
+
+/* Sample the mask surface */
+
+include(`exa_wm.g4i')
+
+/* prepare sampler read back gX register, which would be written back to output */
+
+/* use simd16 sampler, param 0 is u, param 1 is v. */
+/* 'payload' loading, assuming tex coord start from g4 */
+
+/* load only alpha */
+mov (1) g0.8<1>UD      0x00007000UD { align1 mask_disable };
+mov (8) mask_msg<1>UD g0<8,8,1>UD { align1 }; /* copy to msg start reg*/
+
+/* mask_msg will be copied with g0, as it contains send desc */
+/* emit sampler 'send' cmd */
+send (16) mask_msg_ind         /* msg reg index */
+       mask_sample_a_01<1>UW   /* readback */
+       null
+       sampler (2,1,F)         /* sampler message description, (binding_table,sampler_index,datatype)
+                               /* here(src->dst) we should use src_sampler and src_surface */
+       mlen 5 rlen 2 { align1 };   /* required message len 5, readback len 8 */
+
diff --git a/src/render_program/exa_wm_mask_sample_a.g5b b/src/render_program/exa_wm_mask_sample_a.g5b
new file mode 100644 (file)
index 0000000..472c2bb
--- /dev/null
@@ -0,0 +1,3 @@
+   { 0x00000201, 0x20080061, 0x00000000, 0x00007000 },
+   { 0x00600001, 0x20e00022, 0x008d0000, 0x00000000 },
+   { 0x07800031, 0x23801c09, 0x20000000, 0x0a2a0102 },
diff --git a/src/render_program/exa_wm_mask_sample_a.g7a b/src/render_program/exa_wm_mask_sample_a.g7a
new file mode 100644 (file)
index 0000000..a0d38e1
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright © 2006 Intel 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.
+ *
+ * Authors:
+ *    Wang Zhenyu <zhenyu.z.wang@intel.com>
+ *    Keith Packard <keithp@keithp.com>
+ */
+
+/* Sample the mask surface */
+
+include(`exa_wm.g4i')
+
+/* prepare sampler read back gX register, which would be written back to output */
+
+/* use simd16 sampler, param 0 is u, param 1 is v. */
+/* 'payload' loading, assuming tex coord start from g4 */
+
+/* load only alpha */
+mov (1) g0.8<1>UD      0x00007000UD { align1 mask_disable };
+mov (8) g71<1>UD g0<8,8,1>UD { align1 }; /* copy to msg start reg*/
+
+/* g71 will be copied with g0, as it contains send desc */
+/* emit sampler 'send' cmd */
+send (16) 71           /* msg reg index */
+       mask_sample_a_01<1>UW   /* readback */
+       null
+       sampler (2,1,F)         /* sampler message description, (binding_table,sampler_index,datatype)
+                               /* here(src->dst) we should use src_sampler and src_surface */
+       mlen 5 rlen 2 { align1 };   /* required message len 5, readback len 8 */
+
diff --git a/src/render_program/exa_wm_mask_sample_a.g7b b/src/render_program/exa_wm_mask_sample_a.g7b
new file mode 100644 (file)
index 0000000..fa36a59
--- /dev/null
@@ -0,0 +1,3 @@
+   { 0x00000201, 0x20080061, 0x00000000, 0x00007000 },
+   { 0x00600001, 0x28e00021, 0x008d0000, 0x00000000 },
+   { 0x02800031, 0x23801ca9, 0x000008e0, 0x0a2c0102 },
diff --git a/src/render_program/exa_wm_mask_sample_argb.g5a b/src/render_program/exa_wm_mask_sample_argb.g5a
new file mode 100644 (file)
index 0000000..78bfc92
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright © 2006 Intel 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.
+ *
+ * Authors:
+ *    Wang Zhenyu <zhenyu.z.wang@intel.com>
+ *    Keith Packard <keithp@keithp.com>
+ */
+
+/* Sample the mask surface */
+
+include(`exa_wm.g4i')
+
+/* prepare sampler read back gX register, which would be written back to output */
+
+/* use simd16 sampler, param 0 is u, param 1 is v. */
+/* 'payload' loading, assuming tex coord start from g4 */
+
+/* load argb */
+mov (1) g0.8<1>UD      0x00000000UD { align1 mask_disable };
+mov (8) mask_msg<1>UD g0<8,8,1>UD { align1 }; /* copy to msg start reg*/
+
+/* mask_msg will be copied with g0, as it contains send desc */
+/* emit sampler 'send' cmd */
+send (16) mask_msg_ind         /* msg reg index */
+       mask_sample_base<1>UW   /* readback */
+       null
+       sampler (2,1,F)         /* sampler message description, (binding_table,sampler_index,datatype)
+                               /* here(src->dst) we should use src_sampler and src_surface */
+       mlen 5 rlen 8 { align1 };   /* required message len 5, readback len 8 */
+
diff --git a/src/render_program/exa_wm_mask_sample_argb.g5b b/src/render_program/exa_wm_mask_sample_argb.g5b
new file mode 100644 (file)
index 0000000..cb112d5
--- /dev/null
@@ -0,0 +1,3 @@
+   { 0x00000201, 0x20080061, 0x00000000, 0x00000000 },
+   { 0x00600001, 0x20e00022, 0x008d0000, 0x00000000 },
+   { 0x07800031, 0x22c01c09, 0x20000000, 0x0a8a0102 },
diff --git a/src/render_program/exa_wm_mask_sample_argb.g7a b/src/render_program/exa_wm_mask_sample_argb.g7a
new file mode 100644 (file)
index 0000000..984b622
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright © 2006 Intel 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.
+ *
+ * Authors:
+ *    Wang Zhenyu <zhenyu.z.wang@intel.com>
+ *    Keith Packard <keithp@keithp.com>
+ */
+
+/* Sample the mask surface */
+
+include(`exa_wm.g4i')
+
+/* prepare sampler read back gX register, which would be written back to output */
+
+/* use simd16 sampler, param 0 is u, param 1 is v. */
+/* 'payload' loading, assuming tex coord start from g4 */
+
+/* load argb */
+mov (1) g0.8<1>UD      0x00000000UD { align1 mask_disable };
+mov (8) g71<1>UD g0<8,8,1>UD { align1 }; /* copy to msg start reg*/
+
+/* g71 will be copied with g0, as it contains send desc */
+/* emit sampler 'send' cmd */
+send (16) 71           /* msg reg index */
+       mask_sample_base<1>UW   /* readback */
+       null
+       sampler (2,1,F)         /* sampler message description, (binding_table,sampler_index,datatype)
+                               /* here(src->dst) we should use src_sampler and src_surface */
+       mlen 5 rlen 8 { align1 };   /* required message len 5, readback len 8 */
+
diff --git a/src/render_program/exa_wm_mask_sample_argb.g7b b/src/render_program/exa_wm_mask_sample_argb.g7b
new file mode 100644 (file)
index 0000000..01edf7d
--- /dev/null
@@ -0,0 +1,3 @@
+   { 0x00000201, 0x20080061, 0x00000000, 0x00000000 },
+   { 0x00600001, 0x28e00021, 0x008d0000, 0x00000000 },
+   { 0x02800031, 0x22c01ca9, 0x000008e0, 0x0a8c0102 },
diff --git a/src/render_program/exa_wm_noca.g5a b/src/render_program/exa_wm_noca.g5a
new file mode 100644 (file)
index 0000000..d0d60fa
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright © 2006 Intel 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.
+ *
+ * Authors:
+ *    Wang Zhenyu <zhenyu.z.wang@intel.com>
+ *    Keith Packard <keithp@keithp.com>
+ */
+/*
+ * Composite src and mask together, no component alpha
+ */
+
+include(`exa_wm.g4i')
+/* mul mask's alpha channel to src */
+
+mul (16)    src_sample_r_01<1>F        src_sample_r_01<8,8,1>F mask_sample_a_01<8,8,1>F { compr align1 };
+mul (16)    src_sample_g_01<1>F src_sample_g_01<8,8,1>F        mask_sample_a_01<8,8,1>F { compr align1 };
+mul (16)    src_sample_b_01<1>F src_sample_b_01<8,8,1>F        mask_sample_a_01<8,8,1>F { compr align1 };
+mul (16)    src_sample_a_01<1>F src_sample_a_01<8,8,1>F        mask_sample_a_01<8,8,1>F { compr align1 };
diff --git a/src/render_program/exa_wm_noca.g5b b/src/render_program/exa_wm_noca.g5b
new file mode 100644 (file)
index 0000000..1506334
--- /dev/null
@@ -0,0 +1,4 @@
+   { 0x00802041, 0x21c077bd, 0x008d01c0, 0x008d0380 },
+   { 0x00802041, 0x220077bd, 0x008d0200, 0x008d0380 },
+   { 0x00802041, 0x224077bd, 0x008d0240, 0x008d0380 },
+   { 0x00802041, 0x228077bd, 0x008d0280, 0x008d0380 },
diff --git a/src/render_program/exa_wm_sample_planar.g4i b/src/render_program/exa_wm_sample_planar.g4i
new file mode 100644 (file)
index 0000000..5452420
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * Copyright © 2006 Intel 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.
+ *
+ * Authors:
+ *    Wang Zhenyu <zhenyu.z.wang@intel.com>
+ *    Keith Packard <keithp@keithp.com>
+ */
+
+/* Sample the src surface in planar format */
+
+/* prepare sampler read back gX register, which would be written back to output */
+
+/* use simd16 sampler, param 0 is u, param 1 is v. */
+/* 'payload' loading, assuming tex coord start from g4 */
+
+/* load r */
+mov (1) g0.8<1>UD      0x0000e000UD { align1 mask_disable };
+
+/* src_msg will be copied with g0, as it contains send desc */
+/* emit sampler 'send' cmd */
+
+/* sample Y */
+mov (8) src_msg<1>UD g0<8,8,1>UD { align1 }; /* copy to msg start reg*/
+send (16) src_msg_ind          /* msg reg index */
+       src_sample_g<1>UW       /* readback */
+       null
+       sampler (1,0,F)         /* sampler message description, (binding_table,sampler_index,datatype)
+                               /* here(src->dst) we should use src_sampler and src_surface */
+       mlen 5 rlen 2 { align1 };   /* required message len 5, readback len 8 */
+       
+/* sample U (Cr) */
+send (16) src_msg_ind          /* msg reg index */
+       src_sample_r<1>UW       /* readback */
+       null
+       sampler (3,0,F)         /* sampler message description, (binding_table,sampler_index,datatype)
+                               /* here(src->dst) we should use src_sampler and src_surface */
+       mlen 5 rlen 2 { align1 };   /* required message len 5, readback len 8 */
+       
+/* sample V (Cb) */
+send (16) src_msg_ind          /* msg reg index */
+       src_sample_b<1>UW       /* readback */
+       null
+       sampler (5,0,F)         /* sampler message description, (binding_table,sampler_index,datatype)
+                               /* here(src->dst) we should use src_sampler and src_surface */
+       mlen 5 rlen 2 { align1 };   /* required message len 5, readback len 8 */
diff --git a/src/render_program/exa_wm_src_affine.g5a b/src/render_program/exa_wm_src_affine.g5a
new file mode 100644 (file)
index 0000000..cf2b421
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Copyright © 2010 Intel 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(`exa_wm.g4i')
+
+line (16) null src_du_dx dst_x<8,8,1>F { compr align1 };
+mac (16) src_u src_du_dy dst_y<8,8,1>F { compr align1 };
+
+line (16) null src_dv_dx dst_x<8,8,1>F { compr align1 };
+mac (16) src_v src_dv_dy dst_y<8,8,1>F { compr align1 };
diff --git a/src/render_program/exa_wm_src_affine.g5b b/src/render_program/exa_wm_src_affine.g5b
new file mode 100644 (file)
index 0000000..f526adf
--- /dev/null
@@ -0,0 +1,4 @@
+   { 0x00802059, 0x200077bc, 0x00000060, 0x008d0100 },
+   { 0x00802048, 0x204077be, 0x00000064, 0x008d0140 },
+   { 0x00802059, 0x200077bc, 0x00000070, 0x008d0100 },
+   { 0x00802048, 0x208077be, 0x00000074, 0x008d0140 },
index 08195a4..38623bf 100644 (file)
@@ -38,10 +38,4 @@ define(`bh',    `g4.0<8,8,1>F')
 define(`a0_a_x',`g6.0<0,1,0>F')
 define(`a0_a_y',`g6.16<0,1,0>F')
 
-/* U */
-pln (8) ul<1>F a0_a_x bl { align1 }; /* pixel 0-7 */
-pln (8) uh<1>F a0_a_x bh { align1 }; /* pixel 8-15 */
-
-/* V */
-pln (8) vl<1>F a0_a_y bl { align1 }; /* pixel 0-7 */
-pln (8) vh<1>F a0_a_y bh { align1 }; /* pixel 8-15 */
+include(`exa_wm_affine.g6i')
diff --git a/src/render_program/exa_wm_src_affine.g7a b/src/render_program/exa_wm_src_affine.g7a
new file mode 100644 (file)
index 0000000..cf24b2f
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright © 2010 Intel 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.
+ *
+ */
+
+/*
+ * Fragment to compute src u/v values
+ */
+include(`exa_wm.g4i')
+
+define(`ul',    `g66')
+define(`uh',    `g67')
+define(`vl',    `g68')
+define(`vh',    `g69')
+
+define(`bl',    `g2.0<8,8,1>F')
+define(`bh',    `g4.0<8,8,1>F')
+
+define(`a0_a_x',`g6.0<0,1,0>F')
+define(`a0_a_y',`g6.16<0,1,0>F')
+
+include(`exa_wm_affine.g6i')
diff --git a/src/render_program/exa_wm_src_affine.g7b b/src/render_program/exa_wm_src_affine.g7b
new file mode 100644 (file)
index 0000000..f545fba
--- /dev/null
@@ -0,0 +1,4 @@
+   { 0x0060005a, 0x284077bd, 0x000000c0, 0x008d0040 },
+   { 0x0060005a, 0x286077bd, 0x000000c0, 0x008d0080 },
+   { 0x0060005a, 0x288077bd, 0x000000d0, 0x008d0040 },
+   { 0x0060005a, 0x28a077bd, 0x000000d0, 0x008d0080 },
diff --git a/src/render_program/exa_wm_src_projective.g5a b/src/render_program/exa_wm_src_projective.g5a
new file mode 100644 (file)
index 0000000..16c9cd5
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright © 2006 Intel 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.
+ *
+ * Authors:
+ *    Wang Zhenyu <zhenyu.z.wang@intel.com>
+ *    Keith Packard <keithp@keithp.com>
+ */
+
+
+include(`exa_wm.g4i')
+define(`du_dx',        `src_du_dx')
+define(`du_dy',        `src_du_dy')
+define(`uo',   `src_uo')
+define(`dv_dx',        `src_dv_dx')
+define(`dv_dy',        `src_dv_dy')
+define(`vo',   `src_vo')
+define(`dw_dx',        `src_dw_dx')
+define(`dw_dy',        `src_dw_dy')
+define(`wo',   `src_wo')
+define(`u',    `src_u')
+define(`v',    `src_v')
+define(`w',    `src_w')
+define(`u_0',  `src_u_0')
+define(`v_0',  `src_v_0')
+define(`u_1',  `src_u_1')
+define(`v_1',  `src_v_1')
+define(`w_0',  `src_w_0')
+define(`w_1',  `src_w_1')
+
+include(`exa_wm_projective.g4i')
diff --git a/src/render_program/exa_wm_src_projective.g5b b/src/render_program/exa_wm_src_projective.g5b
new file mode 100644 (file)
index 0000000..ae3db8c
--- /dev/null
@@ -0,0 +1,16 @@
+   { 0x00802041, 0x23c077bd, 0x008d0100, 0x00000080 },
+   { 0x00802041, 0x238077bd, 0x008d0140, 0x00000084 },
+   { 0x00802040, 0x23c077bd, 0x008d03c0, 0x008d0380 },
+   { 0x00802040, 0x23c077bd, 0x008d03c0, 0x0000008c },
+   { 0x00600031, 0x21801fbd, 0x108d03c0, 0x02100001 },
+   { 0x00600031, 0x21a01fbd, 0x108d03e0, 0x02100001 },
+   { 0x00802041, 0x23c077bd, 0x008d0100, 0x00000060 },
+   { 0x00802041, 0x238077bd, 0x008d0140, 0x00000064 },
+   { 0x00802040, 0x23c077bd, 0x008d03c0, 0x008d0380 },
+   { 0x00802040, 0x23c077bd, 0x008d03c0, 0x0000006c },
+   { 0x00802041, 0x204077be, 0x008d03c0, 0x008d0180 },
+   { 0x00802041, 0x23c077bd, 0x008d0100, 0x00000070 },
+   { 0x00802041, 0x238077bd, 0x008d0140, 0x00000074 },
+   { 0x00802040, 0x23c077bd, 0x008d03c0, 0x008d0380 },
+   { 0x00802040, 0x23c077bd, 0x008d03c0, 0x0000007c },
+   { 0x00802041, 0x208077be, 0x008d03c0, 0x008d0180 },
diff --git a/src/render_program/exa_wm_src_projective.g7a b/src/render_program/exa_wm_src_projective.g7a
new file mode 100644 (file)
index 0000000..9fd495c
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright © 2010 Intel 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.
+ *
+ */
+
+/*
+ * Fragment to compute src u/v values
+ */
+include(`exa_wm.g4i')
+
+define(`u',     `g66')
+define(`ul',    `g66')
+define(`uh',    `g67')
+define(`v',     `src_v')
+define(`vl',    `src_v')
+define(`vh',    `g69')
+define(`w',     `src_w')
+define(`wl',    `src_w_0')
+define(`wh',    `src_w_1')
+
+define(`bl',    `g2.0<8,8,1>F')
+define(`bh',    `g4.0<8,8,1>F')
+
+define(`a0_a_x',`g6.0<0,1,0>F')
+define(`a0_a_y',`g6.16<0,1,0>F')
+define(`a0_a_z',`g7.0<0,1,0>F')
+
+/* W */
+pln (8) temp_x_0<1>F a0_a_z bl { align1 }; /* pixel 0-7 */
+pln (8) temp_x_1<1>F a0_a_z bh { align1 }; /* pixel 8-15 */
+math (8) wl<1>F temp_x_0<8,8,1>F null inv { align1 };
+math (8) wh<1>F temp_x_1<8,8,1>F null inv { align1 };
+
+/* U */
+pln (8) temp_x_0<1>F a0_a_x bl { align1 }; /* pixel 0-7 */
+pln (8) temp_x_1<1>F a0_a_x bh { align1 }; /* pixel 8-15 */
+mul (8) ul<1>F temp_x_0<8,8,1>F wl<8,8,1>F { align1 };
+mul (8) uh<1>F temp_x_1<8,8,1>F wh<8,8,1>F { align1 };
+
+/* V */
+pln (8) temp_x_0<1>F a0_a_y bl { align1 }; /* pixel 0-7 */
+pln (8) temp_x_1<1>F a0_a_y bh { align1 }; /* pixel 8-15 */
+mul (8) vl<1>F temp_x_0<8,8,1>F wl<8,8,1>F { align1 };
+mul (8) vh<1>F temp_x_1<8,8,1>F wh<8,8,1>F { align1 };
diff --git a/src/render_program/exa_wm_src_projective.g7b b/src/render_program/exa_wm_src_projective.g7b
new file mode 100644 (file)
index 0000000..73727ff
--- /dev/null
@@ -0,0 +1,12 @@
+   { 0x0060005a, 0x23c077bd, 0x000000e0, 0x008d0040 },
+   { 0x0060005a, 0x23e077bd, 0x000000e0, 0x008d0080 },
+   { 0x01600038, 0x218003bd, 0x008d03c0, 0x00000000 },
+   { 0x01600038, 0x21a003bd, 0x008d03e0, 0x00000000 },
+   { 0x0060005a, 0x23c077bd, 0x000000c0, 0x008d0040 },
+   { 0x0060005a, 0x23e077bd, 0x000000c0, 0x008d0080 },
+   { 0x00600041, 0x284077bd, 0x008d03c0, 0x008d0180 },
+   { 0x00600041, 0x286077bd, 0x008d03e0, 0x008d01a0 },
+   { 0x0060005a, 0x23c077bd, 0x000000d0, 0x008d0040 },
+   { 0x0060005a, 0x23e077bd, 0x000000d0, 0x008d0080 },
+   { 0x00600041, 0x208077be, 0x008d03c0, 0x008d0180 },
+   { 0x00600041, 0x28a077bd, 0x008d03e0, 0x008d01a0 },
diff --git a/src/render_program/exa_wm_src_sample_a.g5a b/src/render_program/exa_wm_src_sample_a.g5a
new file mode 100644 (file)
index 0000000..667bfb3
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright © 2006 Intel 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.
+ *
+ * Authors:
+ *    Wang Zhenyu <zhenyu.z.wang@intel.com>
+ *    Keith Packard <keithp@keithp.com>
+ */
+
+/* Sample the src surface */
+
+include(`exa_wm.g4i')
+
+/* prepare sampler read back gX register, which would be written back to output */
+
+/* use simd16 sampler, param 0 is u, param 1 is v. */
+/* 'payload' loading, assuming tex coord start from g4 */
+
+/* load alpha */
+mov (1) g0.8<1>UD      0x00007000UD { align1 mask_disable };
+mov (8) src_msg<1>UD g0<8,8,1>UD { align1 }; /* copy to msg start reg*/
+
+/* src_msg will be copied with g0, as it contains send desc */
+/* emit sampler 'send' cmd */
+send (16) src_msg_ind          /* msg reg index */
+       src_sample_a_01<1>UW    /* readback */
+       null
+       sampler (1,0,F)         /* sampler message description, (binding_table,sampler_index,datatype)
+                               /* here(src->dst) we should use src_sampler and src_surface */
+       mlen 5 rlen 2 { align1 };   /* required message len 5, readback len 8 */
diff --git a/src/render_program/exa_wm_src_sample_a.g5b b/src/render_program/exa_wm_src_sample_a.g5b
new file mode 100644 (file)
index 0000000..0e4eebe
--- /dev/null
@@ -0,0 +1,3 @@
+   { 0x00000201, 0x20080061, 0x00000000, 0x00007000 },
+   { 0x00600001, 0x20200022, 0x008d0000, 0x00000000 },
+   { 0x01800031, 0x22801c09, 0x20000000, 0x0a2a0001 },
diff --git a/src/render_program/exa_wm_src_sample_a.g7a b/src/render_program/exa_wm_src_sample_a.g7a
new file mode 100644 (file)
index 0000000..d5d24fd
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright © 2006 Intel 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.
+ *
+ * Authors:
+ *    Wang Zhenyu <zhenyu.z.wang@intel.com>
+ *    Keith Packard <keithp@keithp.com>
+ */
+
+/* Sample the src surface */
+
+include(`exa_wm.g4i')
+
+/* prepare sampler read back gX register, which would be written back to output */
+
+/* use simd16 sampler, param 0 is u, param 1 is v. */
+/* 'payload' loading, assuming tex coord start from g4 */
+
+/* load alpha */
+mov (1) g0.8<1>UD      0x00007000UD { align1 mask_disable };
+mov (8) g65<1>UD g0<8,8,1>UD { align1 }; /* copy to msg start reg*/
+
+/* g65 will be copied with g0, as it contains send desc */
+/* emit sampler 'send' cmd */
+send (16) 65           /* msg reg index */
+       src_sample_a_01<1>UW    /* readback */
+       null
+       sampler (1,0,F)         /* sampler message description, (binding_table,sampler_index,datatype)
+                               /* here(src->dst) we should use src_sampler and src_surface */
+       mlen 5 rlen 2 { align1 };   /* required message len 5, readback len 8 */
diff --git a/src/render_program/exa_wm_src_sample_a.g7b b/src/render_program/exa_wm_src_sample_a.g7b
new file mode 100644 (file)
index 0000000..73912b7
--- /dev/null
@@ -0,0 +1,3 @@
+   { 0x00000201, 0x20080061, 0x00000000, 0x00007000 },
+   { 0x00600001, 0x28200021, 0x008d0000, 0x00000000 },
+   { 0x02800031, 0x22801ca9, 0x00000820, 0x0a2c0001 },
index 384fe26..02119e3 100644 (file)
 
 include(`exa_wm.g4i')
 
-/* prepare sampler read back gX register, which would be written back to output */
-
-/* use simd16 sampler, param 0 is u, param 1 is v. */
-/* 'payload' loading, assuming tex coord start from g4 */
-
-/* load argb */
-mov (1) g0.8<1>UD      0x00000000UD { align1 mask_disable };
-mov (8) src_msg<1>UD g0<8,8,1>UD { align1 }; /* copy to msg start reg*/
-
-/* src_msg will be copied with g0, as it contains send desc */
-/* emit sampler 'send' cmd */
-send (16) src_msg_ind          /* msg reg index */
-       src_sample_base<1>UW    /* readback */
-       null
-       sampler (1,0,F)         /* sampler message description, (binding_table,sampler_index,datatype)
-                               /* here(src->dst) we should use src_sampler and src_surface */
-       mlen 5 rlen 8 { align1 };   /* required message len 5, readback len 8 */
+include(`exa_wm_src_sample_argb.g4i')
diff --git a/src/render_program/exa_wm_src_sample_argb.g4i b/src/render_program/exa_wm_src_sample_argb.g4i
new file mode 100644 (file)
index 0000000..62d5afc
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright © 2006 Intel 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.
+ *
+ * Authors:
+ *    Wang Zhenyu <zhenyu.z.wang@intel.com>
+ *    Keith Packard <keithp@keithp.com>
+ */
+
+/* prepare sampler read back gX register, which would be written back to output */
+
+/* use simd16 sampler, param 0 is u, param 1 is v. */
+/* 'payload' loading, assuming tex coord start from g4 */
+
+/* load argb */
+mov (1) g0.8<1>UD      0x00000000UD { align1 mask_disable };
+mov (8) src_msg<1>UD g0<8,8,1>UD { align1 }; /* copy to msg start reg*/
+
+/* src_msg will be copied with g0, as it contains send desc */
+/* emit sampler 'send' cmd */
+send (16) src_msg_ind          /* msg reg index */
+       src_sample_base<1>UW    /* readback */
+       null
+       sampler (1,0,F)         /* sampler message description, (binding_table,sampler_index,datatype)
+                               /* here(src->dst) we should use src_sampler and src_surface */
+       mlen 5 rlen 8 { align1 };   /* required message len 5, readback len 8 */
diff --git a/src/render_program/exa_wm_src_sample_argb.g5a b/src/render_program/exa_wm_src_sample_argb.g5a
new file mode 100644 (file)
index 0000000..b598de6
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright © 2006 Intel 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.
+ *
+ * Authors:
+ *    Wang Zhenyu <zhenyu.z.wang@intel.com>
+ *    Keith Packard <keithp@keithp.com>
+ */
+
+/* Sample the src surface */
+
+include(`exa_wm.g4i')
+
+/* prepare sampler read back gX register, which would be written back to output */
+
+/* use simd16 sampler, param 0 is u, param 1 is v. */
+/* 'payload' loading, assuming tex coord start from g4 */
+
+/* load argb */
+mov (1) g0.8<1>UD      0x00000000UD { align1 mask_disable };
+
+/* src_msg will be copied with g0, as it contains send desc */
+send (16) src_msg_ind          /* msg reg index */
+       src_sample_base<1>UW    /* readback */
+       g0<8,8,1>UW
+       sampler (1,0,F)         /* sampler message description, (binding_table,sampler_index,datatype)
+                               /* here(src->dst) we should use src_sampler and src_surface */
+       mlen 5 rlen 8 { align1 };
diff --git a/src/render_program/exa_wm_src_sample_argb.g5b b/src/render_program/exa_wm_src_sample_argb.g5b
new file mode 100644 (file)
index 0000000..f8cb41e
--- /dev/null
@@ -0,0 +1,2 @@
+   { 0x00000201, 0x20080061, 0x00000000, 0x00000000 },
+   { 0x01800031, 0x21c01d29, 0x208d0000, 0x0a8a0001 },
index 384fe26..02119e3 100644 (file)
 
 include(`exa_wm.g4i')
 
-/* prepare sampler read back gX register, which would be written back to output */
-
-/* use simd16 sampler, param 0 is u, param 1 is v. */
-/* 'payload' loading, assuming tex coord start from g4 */
-
-/* load argb */
-mov (1) g0.8<1>UD      0x00000000UD { align1 mask_disable };
-mov (8) src_msg<1>UD g0<8,8,1>UD { align1 }; /* copy to msg start reg*/
-
-/* src_msg will be copied with g0, as it contains send desc */
-/* emit sampler 'send' cmd */
-send (16) src_msg_ind          /* msg reg index */
-       src_sample_base<1>UW    /* readback */
-       null
-       sampler (1,0,F)         /* sampler message description, (binding_table,sampler_index,datatype)
-                               /* here(src->dst) we should use src_sampler and src_surface */
-       mlen 5 rlen 8 { align1 };   /* required message len 5, readback len 8 */
+include(`exa_wm_src_sample_argb.g4i')
diff --git a/src/render_program/exa_wm_src_sample_argb.g7a b/src/render_program/exa_wm_src_sample_argb.g7a
new file mode 100644 (file)
index 0000000..69f5ebc
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright © 2006 Intel 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.
+ *
+ * Authors:
+ *    Wang Zhenyu <zhenyu.z.wang@intel.com>
+ *    Keith Packard <keithp@keithp.com>
+ */
+
+/* Sample the src surface */
+
+include(`exa_wm.g4i')
+
+undefine(`src_msg')
+undefine(`src_msg_ind')
+
+define(`src_msg',       `g65')
+define(`src_msg_ind',   `65')
+
+include(`exa_wm_src_sample_argb.g4i')
diff --git a/src/render_program/exa_wm_src_sample_argb.g7b b/src/render_program/exa_wm_src_sample_argb.g7b
new file mode 100644 (file)
index 0000000..a282cf8
--- /dev/null
@@ -0,0 +1,3 @@
+   { 0x00000201, 0x20080061, 0x00000000, 0x00000000 },
+   { 0x00600001, 0x28200021, 0x008d0000, 0x00000000 },
+   { 0x02800031, 0x21c01ca9, 0x00000820, 0x0a8c0001 },
index 5f5520b..59678f5 100644 (file)
 
 include(`exa_wm.g4i')
 
-/* prepare sampler read back gX register, which would be written back to output */
-
-/* use simd16 sampler, param 0 is u, param 1 is v. */
-/* 'payload' loading, assuming tex coord start from g4 */
-
-/* load r */
-mov (1) g0.8<1>UD      0x0000e000UD { align1 mask_disable };
-
-/* src_msg will be copied with g0, as it contains send desc */
-/* emit sampler 'send' cmd */
-
-/* sample Y */
-mov (8) src_msg<1>UD g0<8,8,1>UD { align1 }; /* copy to msg start reg*/
-send (16) src_msg_ind          /* msg reg index */
-       src_sample_g<1>UW       /* readback */
-       null
-       sampler (1,0,F)         /* sampler message description, (binding_table,sampler_index,datatype)
-                               /* here(src->dst) we should use src_sampler and src_surface */
-       mlen 5 rlen 2 { align1 };   /* required message len 5, readback len 8 */
-       
-/* sample U (Cr) */
-send (16) src_msg_ind          /* msg reg index */
-       src_sample_r<1>UW       /* readback */
-       null
-       sampler (3,0,F)         /* sampler message description, (binding_table,sampler_index,datatype)
-                               /* here(src->dst) we should use src_sampler and src_surface */
-       mlen 5 rlen 2 { align1 };   /* required message len 5, readback len 8 */
-       
-/* sample V (Cb) */
-send (16) src_msg_ind          /* msg reg index */
-       src_sample_b<1>UW       /* readback */
-       null
-       sampler (5,0,F)         /* sampler message description, (binding_table,sampler_index,datatype)
-                               /* here(src->dst) we should use src_sampler and src_surface */
-       mlen 5 rlen 2 { align1 };   /* required message len 5, readback len 8 */
+include(`exa_wm_sample_planar.g4i')
diff --git a/src/render_program/exa_wm_src_sample_planar.g5a b/src/render_program/exa_wm_src_sample_planar.g5a
new file mode 100644 (file)
index 0000000..59678f5
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright © 2006 Intel 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.
+ *
+ * Authors:
+ *    Wang Zhenyu <zhenyu.z.wang@intel.com>
+ *    Keith Packard <keithp@keithp.com>
+ */
+
+/* Sample the src surface in planar format */
+
+include(`exa_wm.g4i')
+
+include(`exa_wm_sample_planar.g4i')
diff --git a/src/render_program/exa_wm_src_sample_planar.g5b b/src/render_program/exa_wm_src_sample_planar.g5b
new file mode 100644 (file)
index 0000000..ce3670b
--- /dev/null
@@ -0,0 +1,5 @@
+   { 0x00000201, 0x20080061, 0x00000000, 0x0000e000 },
+   { 0x00600001, 0x20200022, 0x008d0000, 0x00000000 },
+   { 0x01800031, 0x22001c09, 0x20000000, 0x0a2a0001 },
+   { 0x01800031, 0x21c01c09, 0x20000000, 0x0a2a0003 },
+   { 0x01800031, 0x22401c09, 0x20000000, 0x0a2a0005 },
index 5f5520b..59678f5 100644 (file)
 
 include(`exa_wm.g4i')
 
-/* prepare sampler read back gX register, which would be written back to output */
-
-/* use simd16 sampler, param 0 is u, param 1 is v. */
-/* 'payload' loading, assuming tex coord start from g4 */
-
-/* load r */
-mov (1) g0.8<1>UD      0x0000e000UD { align1 mask_disable };
-
-/* src_msg will be copied with g0, as it contains send desc */
-/* emit sampler 'send' cmd */
-
-/* sample Y */
-mov (8) src_msg<1>UD g0<8,8,1>UD { align1 }; /* copy to msg start reg*/
-send (16) src_msg_ind          /* msg reg index */
-       src_sample_g<1>UW       /* readback */
-       null
-       sampler (1,0,F)         /* sampler message description, (binding_table,sampler_index,datatype)
-                               /* here(src->dst) we should use src_sampler and src_surface */
-       mlen 5 rlen 2 { align1 };   /* required message len 5, readback len 8 */
-       
-/* sample U (Cr) */
-send (16) src_msg_ind          /* msg reg index */
-       src_sample_r<1>UW       /* readback */
-       null
-       sampler (3,0,F)         /* sampler message description, (binding_table,sampler_index,datatype)
-                               /* here(src->dst) we should use src_sampler and src_surface */
-       mlen 5 rlen 2 { align1 };   /* required message len 5, readback len 8 */
-       
-/* sample V (Cb) */
-send (16) src_msg_ind          /* msg reg index */
-       src_sample_b<1>UW       /* readback */
-       null
-       sampler (5,0,F)         /* sampler message description, (binding_table,sampler_index,datatype)
-                               /* here(src->dst) we should use src_sampler and src_surface */
-       mlen 5 rlen 2 { align1 };   /* required message len 5, readback len 8 */
+include(`exa_wm_sample_planar.g4i')
diff --git a/src/render_program/exa_wm_src_sample_planar.g7a b/src/render_program/exa_wm_src_sample_planar.g7a
new file mode 100644 (file)
index 0000000..53b1211
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright © 2006 Intel 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.
+ *
+ * Authors:
+ *    Wang Zhenyu <zhenyu.z.wang@intel.com>
+ *    Keith Packard <keithp@keithp.com>
+ */
+
+/* Sample the src surface in planar format */
+
+include(`exa_wm.g4i')
+
+undefine(`src_msg')
+undefine(`src_msg_ind')
+
+define(`src_msg',       `g65')
+define(`src_msg_ind',   `65')
+
+include(`exa_wm_sample_planar.g4i')
diff --git a/src/render_program/exa_wm_src_sample_planar.g7b b/src/render_program/exa_wm_src_sample_planar.g7b
new file mode 100644 (file)
index 0000000..ddd6f36
--- /dev/null
@@ -0,0 +1,5 @@
+   { 0x00000201, 0x20080061, 0x00000000, 0x0000e000 },
+   { 0x00600001, 0x28200021, 0x008d0000, 0x00000000 },
+   { 0x02800031, 0x22001ca9, 0x00000820, 0x0a2c0001 },
+   { 0x02800031, 0x21c01ca9, 0x00000820, 0x0a2c0003 },
+   { 0x02800031, 0x22401ca9, 0x00000820, 0x0a2c0005 },
diff --git a/src/render_program/exa_wm_write.g5a b/src/render_program/exa_wm_write.g5a
new file mode 100644 (file)
index 0000000..c472a9b
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Copyright © 2006 Intel 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.
+ *
+ * Authors:
+ *    Wang Zhenyu <zhenyu.z.wang@intel.com>
+ *    Keith Packard <keithp@keithp.com>
+ */
+
+include(`exa_wm.g4i')
+
+/*
+ * Prepare data in m2-m5 for subspan(1,0), m6-m9 for subspan(3,2),
+ */
+
+mov (16) m130<1>F      src_sample_r_01<8,8,1>F { align1 compr };
+mov (16) m131<1>F      src_sample_g_01<8,8,1>F { align1 compr };
+mov (16) m132<1>F      src_sample_b_01<8,8,1>F { align1 compr };
+mov (16) m133<1>F      src_sample_a_01<8,8,1>F { align1 compr };
+
+/* m0, m1 are all direct passed by PS thread payload */
+mov (8) data_port_msg_1<1>F    g1<8,8,1>F              { mask_disable align1 };
+
+/* write */
+send (16) 
+       data_port_msg_0_ind 
+       acc0<1>UW
+       g0<8,8,1>UW 
+       write (
+              0,  /* binding_table */
+              8,  /* pixel scordboard clear, msg type simd16 single source */
+              4,  /* render target write */
+              0   /* no write commit message */
+       ) 
+       mlen 10
+       rlen 0
+       { align1 EOT };
diff --git a/src/render_program/exa_wm_write.g5b b/src/render_program/exa_wm_write.g5b
new file mode 100644 (file)
index 0000000..aff2ce0
--- /dev/null
@@ -0,0 +1,6 @@
+   { 0x00802001, 0x304003be, 0x008d01c0, 0x00000000 },
+   { 0x00802001, 0x306003be, 0x008d0200, 0x00000000 },
+   { 0x00802001, 0x308003be, 0x008d0240, 0x00000000 },
+   { 0x00802001, 0x30a003be, 0x008d0280, 0x00000000 },
+   { 0x00600201, 0x202003be, 0x008d0020, 0x00000000 },
+   { 0x00800031, 0x24001d28, 0x548d0000, 0x94084800 },
index c0f3cc1..ed976b5 100644 (file)
@@ -38,40 +38,4 @@ define(`slot_a_00',     `m8')
 define(`slot_a_01',     `m9')
 define(`data_port_msg_2_ind',  `2')
 
-mov (8) slot_r_00<1>F     src_sample_r_01<8,8,1>F { align1 };
-mov (8) slot_r_01<1>F     src_sample_r_23<8,8,1>F { align1 };
-
-mov (8) slot_g_00<1>F     src_sample_g_01<8,8,1>F { align1 };
-mov (8) slot_g_01<1>F     src_sample_g_23<8,8,1>F { align1 };
-
-mov (8) slot_b_00<1>F     src_sample_b_01<8,8,1>F { align1 };
-mov (8) slot_b_01<1>F     src_sample_b_23<8,8,1>F { align1 };
-
-mov (8) slot_a_00<1>F     src_sample_a_01<8,8,1>F { align1 };
-mov (8) slot_a_01<1>F     src_sample_a_23<8,8,1>F { align1 };
-
-/* write */
-send (16) 
-       data_port_msg_2_ind 
-       acc0<1>UW 
-       null
-       write (
-              0,  /* binding_table */
-              16,  /* pixel scordboard clear, msg type simd16 single source */
-              12,  /* render target write */
-              0,   /* no write commit message */
-              0  /* headerless render target write */
-       ) 
-       mlen 8
-       rlen 0
-       { align1 EOT };
-
-nop;
-nop;
-nop;
-nop;
-nop;
-nop;
-nop;
-nop;
-
+include(`exa_wm_write.g6i')
diff --git a/src/render_program/exa_wm_write.g6i b/src/render_program/exa_wm_write.g6i
new file mode 100644 (file)
index 0000000..7be1db2
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Copyright © 2010 Intel 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.
+ *
+ */
+
+mov (8) slot_r_00<1>F     src_sample_r_01<8,8,1>F { align1 };
+mov (8) slot_r_01<1>F     src_sample_r_23<8,8,1>F { align1 };
+
+mov (8) slot_g_00<1>F     src_sample_g_01<8,8,1>F { align1 };
+mov (8) slot_g_01<1>F     src_sample_g_23<8,8,1>F { align1 };
+
+mov (8) slot_b_00<1>F     src_sample_b_01<8,8,1>F { align1 };
+mov (8) slot_b_01<1>F     src_sample_b_23<8,8,1>F { align1 };
+
+mov (8) slot_a_00<1>F     src_sample_a_01<8,8,1>F { align1 };
+mov (8) slot_a_01<1>F     src_sample_a_23<8,8,1>F { align1 };
+
+/* write */
+send (16) 
+       data_port_msg_2_ind 
+       acc0<1>UW 
+       null
+       write (
+              0,  /* binding_table */
+              16,  /* pixel scordboard clear, msg type simd16 single source */
+              12,  /* render target write */
+              0,   /* no write commit message */
+              0  /* headerless render target write */
+       ) 
+       mlen 8
+       rlen 0
+       { align1 EOT };
+
+nop;
+nop;
+nop;
+nop;
+nop;
+nop;
+nop;
+nop;
+
diff --git a/src/render_program/exa_wm_write.g7a b/src/render_program/exa_wm_write.g7a
new file mode 100644 (file)
index 0000000..d21f9b4
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright © 2010 Intel 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(`exa_wm.g4i')
+
+/*
+ * Prepare data in g66-g67 for Red channel, g68-g69 for Green channel,
+ * g70-g71 for Blue and g72-g73 for Alpha channel
+ */
+define(`slot_r_00',     `g66')
+define(`slot_r_01',     `g67')
+define(`slot_g_00',     `g68')
+define(`slot_g_01',     `g69')
+define(`slot_b_00',     `g70')
+define(`slot_b_01',     `g71')
+define(`slot_a_00',     `g72')
+define(`slot_a_01',     `g73')
+define(`data_port_msg_2_ind',  `66')
+
+include(`exa_wm_write.g6i')
diff --git a/src/render_program/exa_wm_write.g7b b/src/render_program/exa_wm_write.g7b
new file mode 100644 (file)
index 0000000..f31af51
--- /dev/null
@@ -0,0 +1,17 @@
+   { 0x00600001, 0x284003bd, 0x008d01c0, 0x00000000 },
+   { 0x00600001, 0x286003bd, 0x008d01e0, 0x00000000 },
+   { 0x00600001, 0x288003bd, 0x008d0200, 0x00000000 },
+   { 0x00600001, 0x28a003bd, 0x008d0220, 0x00000000 },
+   { 0x00600001, 0x28c003bd, 0x008d0240, 0x00000000 },
+   { 0x00600001, 0x28e003bd, 0x008d0260, 0x00000000 },
+   { 0x00600001, 0x290003bd, 0x008d0280, 0x00000000 },
+   { 0x00600001, 0x292003bd, 0x008d02a0, 0x00000000 },
+   { 0x05800031, 0x24001ca8, 0x00000840, 0x90031000 },
+   { 0x0000007e, 0x00000000, 0x00000000, 0x00000000 },
+   { 0x0000007e, 0x00000000, 0x00000000, 0x00000000 },
+   { 0x0000007e, 0x00000000, 0x00000000, 0x00000000 },
+   { 0x0000007e, 0x00000000, 0x00000000, 0x00000000 },
+   { 0x0000007e, 0x00000000, 0x00000000, 0x00000000 },
+   { 0x0000007e, 0x00000000, 0x00000000, 0x00000000 },
+   { 0x0000007e, 0x00000000, 0x00000000, 0x00000000 },
+   { 0x0000007e, 0x00000000, 0x00000000, 0x00000000 },
diff --git a/src/render_program/exa_wm_xy.g5a b/src/render_program/exa_wm_xy.g5a
new file mode 100644 (file)
index 0000000..e99f5ac
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright © 2006 Intel 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.
+ *
+ * Authors:
+ *    Wang Zhenyu <zhenyu.z.wang@intel.com>
+ *    Keith Packard <keithp@keithp.com>
+ */
+/*
+ * Register assignments:
+ *
+ *  x              g6/g7
+ *  y              g8/g9
+ *
+ *  temp x         g10/g11
+ *  temp y         g12/g13
+ *
+ *  src w          g14/g15
+ *  src u          m1/m2
+ *  src v          m3/m4
+ */
+/* Fragment to compute per-pixel XY values */
+
+include(`exa_wm.g4i')
+    
+    /* Load X and Y coordinates and compute per-pixel coordinates */
+add (16)       temp_x_uw<1>UW  dst_x_uw                0x10101010V     { align1 };
+add (16)       temp_y_uw<1>UW  dst_y_uw                0x11001100V     { align1 };
+
+    /* subtract screen-space origin of vertex 0 */
+add (16)       dst_x<1>F       temp_x_uw<8,8,1>UW      -screen_x0      { compr align1 };
+add (16)       dst_y<1>F       temp_y_uw<8,8,1>UW      -screen_y0      { compr align1 };
diff --git a/src/render_program/exa_wm_xy.g5b b/src/render_program/exa_wm_xy.g5b
new file mode 100644 (file)
index 0000000..327fc29
--- /dev/null
@@ -0,0 +1,4 @@
+   { 0x00800040, 0x23c06d29, 0x00480028, 0x10101010 },
+   { 0x00800040, 0x23806d29, 0x0048002a, 0x11001100 },
+   { 0x00802040, 0x2100753d, 0x008d03c0, 0x00004020 },
+   { 0x00802040, 0x2140753d, 0x008d0380, 0x00004024 },
diff --git a/src/render_program/exa_wm_yuv_rgb.g5a b/src/render_program/exa_wm_yuv_rgb.g5a
new file mode 100644 (file)
index 0000000..4fb2576
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+ * Copyright © 2006 Intel 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.
+ *
+ * Authors:
+ *    Keith Packard <keithp@keithp.com>
+ *    Eric Anholt <eric@anholt.net>
+ *
+ */
+
+include(`exa_wm.g4i')
+
+define(`YCbCr_base',   `src_sample_base')
+
+define(`Cr',           `src_sample_r')
+define(`Cr_01',                `src_sample_r_01')
+define(`Cr_23',                `src_sample_r_23')
+
+define(`Y',            `src_sample_g')
+define(`Y_01',         `src_sample_g_01')
+define(`Y_23',         `src_sample_g_23')
+
+define(`Cb',           `src_sample_b')
+define(`Cb_01',                `src_sample_b_01')
+define(`Cb_23',                `src_sample_b_23')
+
+define(`Crn',          `mask_sample_r')
+define(`Crn_01',       `mask_sample_r_01')
+define(`Crn_23',       `mask_sample_r_23')
+
+define(`Yn',           `mask_sample_g')
+define(`Yn_01',                `mask_sample_g_01')
+define(`Yn_23',                `mask_sample_g_23')
+
+define(`Cbn',          `mask_sample_b')
+define(`Cbn_01',       `mask_sample_b_01')
+define(`Cbn_23',       `mask_sample_b_23')
+
+    /* color space conversion function:
+     * R = Clamp ( 1.164(Y-16/255) + 1.596(Cr-128/255), 0, 1)
+     * G = Clamp ( 1.164(Y-16/255) - 0.813(Cr-128/255) - 0.392(Cb-128/255), 0, 1)
+     * B = Clamp ( 1.164(Y-16/255) + 2.017(Cb-128/255), 0, 1)
+     */
+
+    /* Normalize Y, Cb and Cr:
+     *
+     * Yn = (Y - 16/255) * 1.164
+     * Crn = Cr - 128 / 255
+     * Cbn = Cb - 128 / 255
+     */
+add (16)    Yn<1>F             Y<8,8,1>F       -0.0627451F { compr align1 };
+mul (16)    Yn<1>F             Yn<8,8,1>F      1.164F      { compr align1 };
+
+add (16)    Crn<1>F            Cr<8,8,1>F      -0.501961F  { compr align1 };
+
+add (16)    Cbn<1>F            Cb<8,8,1>F      -0.501961F  { compr align1 };
+
+    /* 
+     * R = Y + Cr * 1.596
+     */
+mov (16)    acc0<1>F           Yn<8,8,1>F                  { compr align1 };
+mac.sat(16) src_sample_r<1>F   Crn<8,8,1>F     1.596F      { compr align1 };
+     
+    /*
+     * G = Crn * -0.813 + Cbn * -0.392 + Y
+     */
+mov (16)    acc0<1>F           Yn<8,8,1>F                  { compr align1 };
+mac (16)    acc0<1>F           Crn<8,8,1>F     -0.813F     { compr align1 };
+mac.sat(16) src_sample_g<1>F   Cbn<8,8,1>F     -0.392F     { compr align1 };
+
+    /*
+     * B = Cbn * 2.017 + Y
+     */
+mov (16)    acc0<1>F           Yn<8,8,1>F                  { compr align1 };
+mac.sat(16) src_sample_b<1>F   Cbn<8,8,1>F     2.017F      { compr align1 };
+
+    /*
+     * A = 1.0
+     */
+mov (16)    src_sample_a<1>F   1.0F                        { compr align1 };
diff --git a/src/render_program/exa_wm_yuv_rgb.g5b b/src/render_program/exa_wm_yuv_rgb.g5b
new file mode 100644 (file)
index 0000000..01f6e2b
--- /dev/null
@@ -0,0 +1,12 @@
+   { 0x00802040, 0x23007fbd, 0x008d0200, 0xbd808081 },
+   { 0x00802041, 0x23007fbd, 0x008d0300, 0x3f94fdf4 },
+   { 0x00802040, 0x22c07fbd, 0x008d01c0, 0xbf008084 },
+   { 0x00802040, 0x23407fbd, 0x008d0240, 0xbf008084 },
+   { 0x00802001, 0x240003bc, 0x008d0300, 0x00000000 },
+   { 0x80802048, 0x21c07fbd, 0x008d02c0, 0x3fcc49ba },
+   { 0x00802001, 0x240003bc, 0x008d0300, 0x00000000 },
+   { 0x00802048, 0x24007fbc, 0x008d02c0, 0xbf5020c5 },
+   { 0x80802048, 0x22007fbd, 0x008d0340, 0xbec8b439 },
+   { 0x00802001, 0x240003bc, 0x008d0300, 0x00000000 },
+   { 0x80802048, 0x22407fbd, 0x008d0340, 0x40011687 },
+   { 0x00802001, 0x228003fd, 0x00000000, 0x3f800000 },
diff --git a/src/render_program/exa_wm_yuv_rgb.g7a b/src/render_program/exa_wm_yuv_rgb.g7a
new file mode 100644 (file)
index 0000000..4fb2576
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+ * Copyright © 2006 Intel 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.
+ *
+ * Authors:
+ *    Keith Packard <keithp@keithp.com>
+ *    Eric Anholt <eric@anholt.net>
+ *
+ */
+
+include(`exa_wm.g4i')
+
+define(`YCbCr_base',   `src_sample_base')
+
+define(`Cr',           `src_sample_r')
+define(`Cr_01',                `src_sample_r_01')
+define(`Cr_23',                `src_sample_r_23')
+
+define(`Y',            `src_sample_g')
+define(`Y_01',         `src_sample_g_01')
+define(`Y_23',         `src_sample_g_23')
+
+define(`Cb',           `src_sample_b')
+define(`Cb_01',                `src_sample_b_01')
+define(`Cb_23',                `src_sample_b_23')
+
+define(`Crn',          `mask_sample_r')
+define(`Crn_01',       `mask_sample_r_01')
+define(`Crn_23',       `mask_sample_r_23')
+
+define(`Yn',           `mask_sample_g')
+define(`Yn_01',                `mask_sample_g_01')
+define(`Yn_23',                `mask_sample_g_23')
+
+define(`Cbn',          `mask_sample_b')
+define(`Cbn_01',       `mask_sample_b_01')
+define(`Cbn_23',       `mask_sample_b_23')
+
+    /* color space conversion function:
+     * R = Clamp ( 1.164(Y-16/255) + 1.596(Cr-128/255), 0, 1)
+     * G = Clamp ( 1.164(Y-16/255) - 0.813(Cr-128/255) - 0.392(Cb-128/255), 0, 1)
+     * B = Clamp ( 1.164(Y-16/255) + 2.017(Cb-128/255), 0, 1)
+     */
+
+    /* Normalize Y, Cb and Cr:
+     *
+     * Yn = (Y - 16/255) * 1.164
+     * Crn = Cr - 128 / 255
+     * Cbn = Cb - 128 / 255
+     */
+add (16)    Yn<1>F             Y<8,8,1>F       -0.0627451F { compr align1 };
+mul (16)    Yn<1>F             Yn<8,8,1>F      1.164F      { compr align1 };
+
+add (16)    Crn<1>F            Cr<8,8,1>F      -0.501961F  { compr align1 };
+
+add (16)    Cbn<1>F            Cb<8,8,1>F      -0.501961F  { compr align1 };
+
+    /* 
+     * R = Y + Cr * 1.596
+     */
+mov (16)    acc0<1>F           Yn<8,8,1>F                  { compr align1 };
+mac.sat(16) src_sample_r<1>F   Crn<8,8,1>F     1.596F      { compr align1 };
+     
+    /*
+     * G = Crn * -0.813 + Cbn * -0.392 + Y
+     */
+mov (16)    acc0<1>F           Yn<8,8,1>F                  { compr align1 };
+mac (16)    acc0<1>F           Crn<8,8,1>F     -0.813F     { compr align1 };
+mac.sat(16) src_sample_g<1>F   Cbn<8,8,1>F     -0.392F     { compr align1 };
+
+    /*
+     * B = Cbn * 2.017 + Y
+     */
+mov (16)    acc0<1>F           Yn<8,8,1>F                  { compr align1 };
+mac.sat(16) src_sample_b<1>F   Cbn<8,8,1>F     2.017F      { compr align1 };
+
+    /*
+     * A = 1.0
+     */
+mov (16)    src_sample_a<1>F   1.0F                        { compr align1 };
diff --git a/src/render_program/exa_wm_yuv_rgb.g7b b/src/render_program/exa_wm_yuv_rgb.g7b
new file mode 100644 (file)
index 0000000..01ec5e5
--- /dev/null
@@ -0,0 +1,12 @@
+   { 0x00800040, 0x23007fbd, 0x008d0200, 0xbd808081 },
+   { 0x00800041, 0x23007fbd, 0x008d0300, 0x3f94fdf4 },
+   { 0x00800040, 0x22c07fbd, 0x008d01c0, 0xbf008084 },
+   { 0x00800040, 0x23407fbd, 0x008d0240, 0xbf008084 },
+   { 0x00800001, 0x240003bc, 0x008d0300, 0x00000000 },
+   { 0x80800048, 0x21c07fbd, 0x008d02c0, 0x3fcc49ba },
+   { 0x00800001, 0x240003bc, 0x008d0300, 0x00000000 },
+   { 0x00800048, 0x24007fbc, 0x008d02c0, 0xbf5020c5 },
+   { 0x80800048, 0x22007fbd, 0x008d0340, 0xbec8b439 },
+   { 0x00800001, 0x240003bc, 0x008d0300, 0x00000000 },
+   { 0x80800048, 0x22407fbd, 0x008d0340, 0x40011687 },
+   { 0x00800001, 0x228003fd, 0x00000000, 0x3f800000 },
diff --git a/src/sna/Makefile.am b/src/sna/Makefile.am
new file mode 100644 (file)
index 0000000..306996b
--- /dev/null
@@ -0,0 +1,115 @@
+#  Copyright 2005 Adam Jackson.
+#
+#  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
+#  on the rights to use, copy, modify, merge, publish, distribute, sub
+#  license, 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 NON-INFRINGEMENT.  IN NO EVENT SHALL
+#  ADAM JACKSON 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.
+
+SUBDIRS = brw fb
+
+AM_CFLAGS = \
+       @CWARNFLAGS@ \
+       -I$(top_srcdir)/src \
+       -I$(top_srcdir)/src/render_program \
+       @XORG_CFLAGS@ \
+       @UDEV_CFLAGS@ \
+       @DRM_CFLAGS@ \
+       $(NULL)
+
+if DEBUG
+AM_CFLAGS += @VALGRIND_CFLAGS@
+endif
+
+noinst_LTLIBRARIES = libsna.la
+libsna_la_LIBADD = @UDEV_LIBS@ -lm @DRM_LIBS@ brw/libbrw.la fb/libfb.la
+
+libsna_la_SOURCES = \
+       blt.c \
+       compiler.h \
+       kgem.c \
+       kgem.h \
+       rop.h \
+       sna.h \
+       sna_accel.c \
+       sna_blt.c \
+       sna_composite.c \
+       sna_damage.c \
+       sna_damage.h \
+       sna_display.c \
+       sna_driver.c \
+       sna_glyphs.c \
+       sna_gradient.c \
+       sna_io.c \
+       sna_module.h \
+       sna_render.c \
+       sna_render.h \
+       sna_render_inline.h \
+       sna_reg.h \
+       sna_stream.c \
+       sna_trapezoids.c \
+       sna_tiling.c \
+       sna_transform.c \
+       sna_video.c \
+       sna_video.h \
+       sna_video_overlay.c \
+       sna_video_sprite.c \
+       sna_video_textured.c \
+       gen2_render.c \
+       gen2_render.h \
+       gen3_render.c \
+       gen3_render.h \
+       gen4_render.c \
+       gen4_render.h \
+       gen5_render.c \
+       gen5_render.h \
+       gen6_render.c \
+       gen6_render.h \
+       gen7_render.c \
+       gen7_render.h \
+       $(NULL)
+
+if DRI2
+AM_CFLAGS += @DRI_CFLAGS@
+libsna_la_SOURCES += sna_dri.c
+libsna_la_LIBADD += $(DRI_LIBS)
+endif
+
+if XVMC
+libsna_la_SOURCES += \
+       sna_video_hwmc.h \
+       sna_video_hwmc.c \
+       $(NULL)
+endif
+
+if FULL_DEBUG
+libsna_la_SOURCES += \
+       kgem_debug.c \
+       kgem_debug.h \
+       kgem_debug_gen2.c \
+       kgem_debug_gen3.c \
+       kgem_debug_gen4.c \
+       kgem_debug_gen5.c \
+       kgem_debug_gen6.c \
+       kgem_debug_gen7.c \
+       $(NULL)
+endif
+
+if HAVE_DOT_GIT
+git_version.h: $(top_srcdir)/.git/HEAD $(shell sed -e '/ref:/!d' -e 's#ref: *#$(top_srcdir)/.git/#' < $(top_srcdir)/.git/HEAD)
+       @echo "Recording git-tree used for compilation: `git describe`"
+       @V=`git describe`; echo "static const char git_version[] = \"$$V\";" > git_version.h
+sna_driver.c: git_version.h
+endif
diff --git a/src/sna/Makefile.in b/src/sna/Makefile.in
new file mode 100644 (file)
index 0000000..a8ec8ef
--- /dev/null
@@ -0,0 +1,835 @@
+# Makefile.in generated by automake 1.11.6 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
+# Foundation, Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+
+#  Copyright 2005 Adam Jackson.
+#
+#  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
+#  on the rights to use, copy, modify, merge, publish, distribute, sub
+#  license, 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 NON-INFRINGEMENT.  IN NO EVENT SHALL
+#  ADAM JACKSON 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.
+
+VPATH = @srcdir@
+am__make_dryrun = \
+  { \
+    am__dry=no; \
+    case $$MAKEFLAGS in \
+      *\\[\ \  ]*) \
+        echo 'am--echo: ; @echo "AM"  OK' | $(MAKE) -f - 2>/dev/null \
+          | grep '^AM OK$$' >/dev/null || am__dry=yes;; \
+      *) \
+        for am__flg in $$MAKEFLAGS; do \
+          case $$am__flg in \
+            *=*|--*) ;; \
+            *n*) am__dry=yes; break;; \
+          esac; \
+        done;; \
+    esac; \
+    test $$am__dry = yes; \
+  }
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+@DEBUG_TRUE@am__append_1 = @VALGRIND_CFLAGS@
+@DRI2_TRUE@am__append_2 = @DRI_CFLAGS@
+@DRI2_TRUE@am__append_3 = sna_dri.c
+@DRI2_TRUE@am__append_4 = $(DRI_LIBS)
+@XVMC_TRUE@am__append_5 = \
+@XVMC_TRUE@    sna_video_hwmc.h \
+@XVMC_TRUE@    sna_video_hwmc.c \
+@XVMC_TRUE@    $(NULL)
+
+@FULL_DEBUG_TRUE@am__append_6 = \
+@FULL_DEBUG_TRUE@      kgem_debug.c \
+@FULL_DEBUG_TRUE@      kgem_debug.h \
+@FULL_DEBUG_TRUE@      kgem_debug_gen2.c \
+@FULL_DEBUG_TRUE@      kgem_debug_gen3.c \
+@FULL_DEBUG_TRUE@      kgem_debug_gen4.c \
+@FULL_DEBUG_TRUE@      kgem_debug_gen5.c \
+@FULL_DEBUG_TRUE@      kgem_debug_gen6.c \
+@FULL_DEBUG_TRUE@      kgem_debug_gen7.c \
+@FULL_DEBUG_TRUE@      $(NULL)
+
+subdir = src/sna
+DIST_COMMON = README $(srcdir)/Makefile.am $(srcdir)/Makefile.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+       $(ACLOCAL_M4)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+LTLIBRARIES = $(noinst_LTLIBRARIES)
+am__DEPENDENCIES_1 =
+@DRI2_TRUE@am__DEPENDENCIES_2 = $(am__DEPENDENCIES_1)
+libsna_la_DEPENDENCIES = brw/libbrw.la fb/libfb.la \
+       $(am__DEPENDENCIES_2)
+am__libsna_la_SOURCES_DIST = blt.c compiler.h kgem.c kgem.h rop.h \
+       sna.h sna_accel.c sna_blt.c sna_composite.c sna_damage.c \
+       sna_damage.h sna_display.c sna_driver.c sna_glyphs.c \
+       sna_gradient.c sna_io.c sna_module.h sna_render.c sna_render.h \
+       sna_render_inline.h sna_reg.h sna_stream.c sna_trapezoids.c \
+       sna_tiling.c sna_transform.c sna_video.c sna_video.h \
+       sna_video_overlay.c sna_video_sprite.c sna_video_textured.c \
+       gen2_render.c gen2_render.h gen3_render.c gen3_render.h \
+       gen4_render.c gen4_render.h gen5_render.c gen5_render.h \
+       gen6_render.c gen6_render.h gen7_render.c gen7_render.h \
+       sna_dri.c sna_video_hwmc.h sna_video_hwmc.c kgem_debug.c \
+       kgem_debug.h kgem_debug_gen2.c kgem_debug_gen3.c \
+       kgem_debug_gen4.c kgem_debug_gen5.c kgem_debug_gen6.c \
+       kgem_debug_gen7.c
+@DRI2_TRUE@am__objects_1 = sna_dri.lo
+@XVMC_TRUE@am__objects_2 = sna_video_hwmc.lo
+@FULL_DEBUG_TRUE@am__objects_3 = kgem_debug.lo kgem_debug_gen2.lo \
+@FULL_DEBUG_TRUE@      kgem_debug_gen3.lo kgem_debug_gen4.lo \
+@FULL_DEBUG_TRUE@      kgem_debug_gen5.lo kgem_debug_gen6.lo \
+@FULL_DEBUG_TRUE@      kgem_debug_gen7.lo
+am_libsna_la_OBJECTS = blt.lo kgem.lo sna_accel.lo sna_blt.lo \
+       sna_composite.lo sna_damage.lo sna_display.lo sna_driver.lo \
+       sna_glyphs.lo sna_gradient.lo sna_io.lo sna_render.lo \
+       sna_stream.lo sna_trapezoids.lo sna_tiling.lo sna_transform.lo \
+       sna_video.lo sna_video_overlay.lo sna_video_sprite.lo \
+       sna_video_textured.lo gen2_render.lo gen3_render.lo \
+       gen4_render.lo gen5_render.lo gen6_render.lo gen7_render.lo \
+       $(am__objects_1) $(am__objects_2) $(am__objects_3)
+libsna_la_OBJECTS = $(am_libsna_la_OBJECTS)
+AM_V_lt = $(am__v_lt_@AM_V@)
+am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
+am__v_lt_0 = --silent
+DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
+depcomp = $(SHELL) $(top_srcdir)/depcomp
+am__depfiles_maybe = depfiles
+am__mv = mv -f
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+       $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+       $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \
+       $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
+       $(AM_CFLAGS) $(CFLAGS)
+AM_V_CC = $(am__v_CC_@AM_V@)
+am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@)
+am__v_CC_0 = @echo "  CC    " $@;
+AM_V_at = $(am__v_at_@AM_V@)
+am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
+am__v_at_0 = @
+CCLD = $(CC)
+LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+       $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+       $(AM_LDFLAGS) $(LDFLAGS) -o $@
+AM_V_CCLD = $(am__v_CCLD_@AM_V@)
+am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
+am__v_CCLD_0 = @echo "  CCLD  " $@;
+AM_V_GEN = $(am__v_GEN_@AM_V@)
+am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
+am__v_GEN_0 = @echo "  GEN   " $@;
+SOURCES = $(libsna_la_SOURCES)
+DIST_SOURCES = $(am__libsna_la_SOURCES_DIST)
+RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \
+       html-recursive info-recursive install-data-recursive \
+       install-dvi-recursive install-exec-recursive \
+       install-html-recursive install-info-recursive \
+       install-pdf-recursive install-ps-recursive install-recursive \
+       installcheck-recursive installdirs-recursive pdf-recursive \
+       ps-recursive uninstall-recursive
+am__can_run_installinfo = \
+  case $$AM_UPDATE_INFO_DIR in \
+    n|no|NO) false;; \
+    *) (install-info --version) >/dev/null 2>&1;; \
+  esac
+RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive        \
+  distclean-recursive maintainer-clean-recursive
+AM_RECURSIVE_TARGETS = $(RECURSIVE_TARGETS:-recursive=) \
+       $(RECURSIVE_CLEAN_TARGETS:-recursive=) tags TAGS ctags CTAGS \
+       distdir
+ETAGS = etags
+CTAGS = ctags
+DIST_SUBDIRS = $(SUBDIRS)
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+am__relativize = \
+  dir0=`pwd`; \
+  sed_first='s,^\([^/]*\)/.*$$,\1,'; \
+  sed_rest='s,^[^/]*/*,,'; \
+  sed_last='s,^.*/\([^/]*\)$$,\1,'; \
+  sed_butlast='s,/*[^/]*$$,,'; \
+  while test -n "$$dir1"; do \
+    first=`echo "$$dir1" | sed -e "$$sed_first"`; \
+    if test "$$first" != "."; then \
+      if test "$$first" = ".."; then \
+        dir2=`echo "$$dir0" | sed -e "$$sed_last"`/"$$dir2"; \
+        dir0=`echo "$$dir0" | sed -e "$$sed_butlast"`; \
+      else \
+        first2=`echo "$$dir2" | sed -e "$$sed_first"`; \
+        if test "$$first2" = "$$first"; then \
+          dir2=`echo "$$dir2" | sed -e "$$sed_rest"`; \
+        else \
+          dir2="../$$dir2"; \
+        fi; \
+        dir0="$$dir0"/"$$first"; \
+      fi; \
+    fi; \
+    dir1=`echo "$$dir1" | sed -e "$$sed_rest"`; \
+  done; \
+  reldir="$$dir2"
+ACLOCAL = @ACLOCAL@
+ADMIN_MAN_DIR = @ADMIN_MAN_DIR@
+ADMIN_MAN_SUFFIX = @ADMIN_MAN_SUFFIX@
+AMTAR = @AMTAR@
+AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
+APP_MAN_DIR = @APP_MAN_DIR@
+APP_MAN_SUFFIX = @APP_MAN_SUFFIX@
+AR = @AR@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+BASE_CFLAGS = @BASE_CFLAGS@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CHANGELOG_CMD = @CHANGELOG_CMD@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CWARNFLAGS = @CWARNFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DLLTOOL = @DLLTOOL@
+DRI2_CFLAGS = @DRI2_CFLAGS@
+DRI2_LIBS = @DRI2_LIBS@
+DRIVER_MAN_DIR = @DRIVER_MAN_DIR@
+DRIVER_MAN_SUFFIX = @DRIVER_MAN_SUFFIX@
+DRIVER_NAME = @DRIVER_NAME@
+DRI_CFLAGS = @DRI_CFLAGS@
+DRI_LIBS = @DRI_LIBS@
+DRMINTEL_CFLAGS = @DRMINTEL_CFLAGS@
+DRMINTEL_LIBS = @DRMINTEL_LIBS@
+DRM_CFLAGS = @DRM_CFLAGS@
+DRM_LIBS = @DRM_LIBS@
+DSYMUTIL = @DSYMUTIL@
+DUMPBIN = @DUMPBIN@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+FGREP = @FGREP@
+FILE_MAN_DIR = @FILE_MAN_DIR@
+FILE_MAN_SUFFIX = @FILE_MAN_SUFFIX@
+GEN4ASM_CFLAGS = @GEN4ASM_CFLAGS@
+GEN4ASM_LIBS = @GEN4ASM_LIBS@
+GREP = @GREP@
+INSTALL = @INSTALL@
+INSTALL_CMD = @INSTALL_CMD@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+LD = @LD@
+LDFLAGS = @LDFLAGS@
+LIBGLAMOR_CFLAGS = @LIBGLAMOR_CFLAGS@
+LIBGLAMOR_EGL_CFLAGS = @LIBGLAMOR_EGL_CFLAGS@
+LIBGLAMOR_EGL_LIBS = @LIBGLAMOR_EGL_LIBS@
+LIBGLAMOR_LIBS = @LIBGLAMOR_LIBS@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBTOOL = @LIBTOOL@
+LIB_MAN_DIR = @LIB_MAN_DIR@
+LIB_MAN_SUFFIX = @LIB_MAN_SUFFIX@
+LIPO = @LIPO@
+LN_S = @LN_S@
+LTLIBOBJS = @LTLIBOBJS@
+MAINT = @MAINT@
+MAKEINFO = @MAKEINFO@
+MANIFEST_TOOL = @MANIFEST_TOOL@
+MAN_SUBSTS = @MAN_SUBSTS@
+MISC_MAN_DIR = @MISC_MAN_DIR@
+MISC_MAN_SUFFIX = @MISC_MAN_SUFFIX@
+MKDIR_P = @MKDIR_P@
+NM = @NM@
+NMEDIT = @NMEDIT@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+OTOOL = @OTOOL@
+OTOOL64 = @OTOOL64@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_URL = @PACKAGE_URL@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PCIACCESS_CFLAGS = @PCIACCESS_CFLAGS@
+PCIACCESS_LIBS = @PCIACCESS_LIBS@
+PKG_CONFIG = @PKG_CONFIG@
+PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
+PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
+RANLIB = @RANLIB@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STRICT_CFLAGS = @STRICT_CFLAGS@
+STRIP = @STRIP@
+UDEV_CFLAGS = @UDEV_CFLAGS@
+UDEV_LIBS = @UDEV_LIBS@
+VALGRIND_CFLAGS = @VALGRIND_CFLAGS@
+VALGRIND_LIBS = @VALGRIND_LIBS@
+VERSION = @VERSION@
+X11_CFLAGS = @X11_CFLAGS@
+X11_LIBS = @X11_LIBS@
+XORG_CFLAGS = @XORG_CFLAGS@
+XORG_LIBS = @XORG_LIBS@
+XORG_MAN_PAGE = @XORG_MAN_PAGE@
+XVMCLIB_CFLAGS = @XVMCLIB_CFLAGS@
+XVMCLIB_LIBS = @XVMCLIB_LIBS@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_AR = @ac_ct_AR@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+moduledir = @moduledir@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+SUBDIRS = brw fb
+AM_CFLAGS = @CWARNFLAGS@ -I$(top_srcdir)/src \
+       -I$(top_srcdir)/src/render_program @XORG_CFLAGS@ @UDEV_CFLAGS@ \
+       @DRM_CFLAGS@ $(NULL) $(am__append_1) $(am__append_2)
+noinst_LTLIBRARIES = libsna.la
+libsna_la_LIBADD = @UDEV_LIBS@ -lm @DRM_LIBS@ brw/libbrw.la \
+       fb/libfb.la $(am__append_4)
+libsna_la_SOURCES = blt.c compiler.h kgem.c kgem.h rop.h sna.h \
+       sna_accel.c sna_blt.c sna_composite.c sna_damage.c \
+       sna_damage.h sna_display.c sna_driver.c sna_glyphs.c \
+       sna_gradient.c sna_io.c sna_module.h sna_render.c sna_render.h \
+       sna_render_inline.h sna_reg.h sna_stream.c sna_trapezoids.c \
+       sna_tiling.c sna_transform.c sna_video.c sna_video.h \
+       sna_video_overlay.c sna_video_sprite.c sna_video_textured.c \
+       gen2_render.c gen2_render.h gen3_render.c gen3_render.h \
+       gen4_render.c gen4_render.h gen5_render.c gen5_render.h \
+       gen6_render.c gen6_render.h gen7_render.c gen7_render.h \
+       $(NULL) $(am__append_3) $(am__append_5) $(am__append_6)
+all: all-recursive
+
+.SUFFIXES:
+.SUFFIXES: .c .lo .o .obj
+$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am  $(am__configure_deps)
+       @for dep in $?; do \
+         case '$(am__configure_deps)' in \
+           *$$dep*) \
+             ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+               && { if test -f $@; then exit 0; else break; fi; }; \
+             exit 1;; \
+         esac; \
+       done; \
+       echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/sna/Makefile'; \
+       $(am__cd) $(top_srcdir) && \
+         $(AUTOMAKE) --foreign src/sna/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+       @case '$?' in \
+         *config.status*) \
+           cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+         *) \
+           echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+           cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+       esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+       cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
+       cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
+       cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+
+clean-noinstLTLIBRARIES:
+       -test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES)
+       @list='$(noinst_LTLIBRARIES)'; for p in $$list; do \
+         dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \
+         test "$$dir" != "$$p" || dir=.; \
+         echo "rm -f \"$${dir}/so_locations\""; \
+         rm -f "$${dir}/so_locations"; \
+       done
+libsna.la: $(libsna_la_OBJECTS) $(libsna_la_DEPENDENCIES) $(EXTRA_libsna_la_DEPENDENCIES) 
+       $(AM_V_CCLD)$(LINK)  $(libsna_la_OBJECTS) $(libsna_la_LIBADD) $(LIBS)
+
+mostlyclean-compile:
+       -rm -f *.$(OBJEXT)
+
+distclean-compile:
+       -rm -f *.tab.c
+
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/blt.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gen2_render.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gen3_render.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gen4_render.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gen5_render.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gen6_render.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gen7_render.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/kgem.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/kgem_debug.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/kgem_debug_gen2.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/kgem_debug_gen3.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/kgem_debug_gen4.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/kgem_debug_gen5.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/kgem_debug_gen6.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/kgem_debug_gen7.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sna_accel.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sna_blt.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sna_composite.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sna_damage.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sna_display.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sna_dri.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sna_driver.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sna_glyphs.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sna_gradient.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sna_io.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sna_render.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sna_stream.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sna_tiling.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sna_transform.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sna_trapezoids.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sna_video.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sna_video_hwmc.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sna_video_overlay.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sna_video_sprite.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sna_video_textured.Plo@am__quote@
+
+.c.o:
+@am__fastdepCC_TRUE@   $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(COMPILE) -c $<
+
+.c.obj:
+@am__fastdepCC_TRUE@   $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+@am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(COMPILE) -c `$(CYGPATH_W) '$<'`
+
+.c.lo:
+@am__fastdepCC_TRUE@   $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $<
+
+mostlyclean-libtool:
+       -rm -f *.lo
+
+clean-libtool:
+       -rm -rf .libs _libs
+
+# This directory's subdirectories are mostly independent; you can cd
+# into them and run `make' without going through this Makefile.
+# To change the values of `make' variables: instead of editing Makefiles,
+# (1) if the variable is set in `config.status', edit `config.status'
+#     (which will cause the Makefiles to be regenerated when you run `make');
+# (2) otherwise, pass the desired values on the `make' command line.
+$(RECURSIVE_TARGETS):
+       @fail= failcom='exit 1'; \
+       for f in x $$MAKEFLAGS; do \
+         case $$f in \
+           *=* | --[!k]*);; \
+           *k*) failcom='fail=yes';; \
+         esac; \
+       done; \
+       dot_seen=no; \
+       target=`echo $@ | sed s/-recursive//`; \
+       list='$(SUBDIRS)'; for subdir in $$list; do \
+         echo "Making $$target in $$subdir"; \
+         if test "$$subdir" = "."; then \
+           dot_seen=yes; \
+           local_target="$$target-am"; \
+         else \
+           local_target="$$target"; \
+         fi; \
+         ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
+         || eval $$failcom; \
+       done; \
+       if test "$$dot_seen" = "no"; then \
+         $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \
+       fi; test -z "$$fail"
+
+$(RECURSIVE_CLEAN_TARGETS):
+       @fail= failcom='exit 1'; \
+       for f in x $$MAKEFLAGS; do \
+         case $$f in \
+           *=* | --[!k]*);; \
+           *k*) failcom='fail=yes';; \
+         esac; \
+       done; \
+       dot_seen=no; \
+       case "$@" in \
+         distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \
+         *) list='$(SUBDIRS)' ;; \
+       esac; \
+       rev=''; for subdir in $$list; do \
+         if test "$$subdir" = "."; then :; else \
+           rev="$$subdir $$rev"; \
+         fi; \
+       done; \
+       rev="$$rev ."; \
+       target=`echo $@ | sed s/-recursive//`; \
+       for subdir in $$rev; do \
+         echo "Making $$target in $$subdir"; \
+         if test "$$subdir" = "."; then \
+           local_target="$$target-am"; \
+         else \
+           local_target="$$target"; \
+         fi; \
+         ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
+         || eval $$failcom; \
+       done && test -z "$$fail"
+tags-recursive:
+       list='$(SUBDIRS)'; for subdir in $$list; do \
+         test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \
+       done
+ctags-recursive:
+       list='$(SUBDIRS)'; for subdir in $$list; do \
+         test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) ctags); \
+       done
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+       list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+       unique=`for i in $$list; do \
+           if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+         done | \
+         $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+             END { if (nonempty) { for (i in files) print i; }; }'`; \
+       mkid -fID $$unique
+tags: TAGS
+
+TAGS: tags-recursive $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+               $(TAGS_FILES) $(LISP)
+       set x; \
+       here=`pwd`; \
+       if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \
+         include_option=--etags-include; \
+         empty_fix=.; \
+       else \
+         include_option=--include; \
+         empty_fix=; \
+       fi; \
+       list='$(SUBDIRS)'; for subdir in $$list; do \
+         if test "$$subdir" = .; then :; else \
+           test ! -f $$subdir/TAGS || \
+             set "$$@" "$$include_option=$$here/$$subdir/TAGS"; \
+         fi; \
+       done; \
+       list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+       unique=`for i in $$list; do \
+           if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+         done | \
+         $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+             END { if (nonempty) { for (i in files) print i; }; }'`; \
+       shift; \
+       if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
+         test -n "$$unique" || unique=$$empty_fix; \
+         if test $$# -gt 0; then \
+           $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+             "$$@" $$unique; \
+         else \
+           $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+             $$unique; \
+         fi; \
+       fi
+ctags: CTAGS
+CTAGS: ctags-recursive $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+               $(TAGS_FILES) $(LISP)
+       list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+       unique=`for i in $$list; do \
+           if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+         done | \
+         $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+             END { if (nonempty) { for (i in files) print i; }; }'`; \
+       test -z "$(CTAGS_ARGS)$$unique" \
+         || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+            $$unique
+
+GTAGS:
+       here=`$(am__cd) $(top_builddir) && pwd` \
+         && $(am__cd) $(top_srcdir) \
+         && gtags -i $(GTAGS_ARGS) "$$here"
+
+distclean-tags:
+       -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+distdir: $(DISTFILES)
+       @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+       topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+       list='$(DISTFILES)'; \
+         dist_files=`for file in $$list; do echo $$file; done | \
+         sed -e "s|^$$srcdirstrip/||;t" \
+             -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+       case $$dist_files in \
+         */*) $(MKDIR_P) `echo "$$dist_files" | \
+                          sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+                          sort -u` ;; \
+       esac; \
+       for file in $$dist_files; do \
+         if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+         if test -d $$d/$$file; then \
+           dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+           if test -d "$(distdir)/$$file"; then \
+             find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+           fi; \
+           if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+             cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+             find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+           fi; \
+           cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+         else \
+           test -f "$(distdir)/$$file" \
+           || cp -p $$d/$$file "$(distdir)/$$file" \
+           || exit 1; \
+         fi; \
+       done
+       @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
+         if test "$$subdir" = .; then :; else \
+           $(am__make_dryrun) \
+             || test -d "$(distdir)/$$subdir" \
+             || $(MKDIR_P) "$(distdir)/$$subdir" \
+             || exit 1; \
+           dir1=$$subdir; dir2="$(distdir)/$$subdir"; \
+           $(am__relativize); \
+           new_distdir=$$reldir; \
+           dir1=$$subdir; dir2="$(top_distdir)"; \
+           $(am__relativize); \
+           new_top_distdir=$$reldir; \
+           echo " (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) top_distdir="$$new_top_distdir" distdir="$$new_distdir" \\"; \
+           echo "     am__remove_distdir=: am__skip_length_check=: am__skip_mode_fix=: distdir)"; \
+           ($(am__cd) $$subdir && \
+             $(MAKE) $(AM_MAKEFLAGS) \
+               top_distdir="$$new_top_distdir" \
+               distdir="$$new_distdir" \
+               am__remove_distdir=: \
+               am__skip_length_check=: \
+               am__skip_mode_fix=: \
+               distdir) \
+             || exit 1; \
+         fi; \
+       done
+check-am: all-am
+check: check-recursive
+all-am: Makefile $(LTLIBRARIES)
+installdirs: installdirs-recursive
+installdirs-am:
+install: install-recursive
+install-exec: install-exec-recursive
+install-data: install-data-recursive
+uninstall: uninstall-recursive
+
+install-am: all-am
+       @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-recursive
+install-strip:
+       if test -z '$(STRIP)'; then \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+             install; \
+       else \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+           "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+       fi
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+       -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+       -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+
+maintainer-clean-generic:
+       @echo "This command is intended for maintainers to use"
+       @echo "it deletes files that may require special tools to rebuild."
+clean: clean-recursive
+
+clean-am: clean-generic clean-libtool clean-noinstLTLIBRARIES \
+       mostlyclean-am
+
+distclean: distclean-recursive
+       -rm -rf ./$(DEPDIR)
+       -rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+       distclean-tags
+
+dvi: dvi-recursive
+
+dvi-am:
+
+html: html-recursive
+
+html-am:
+
+info: info-recursive
+
+info-am:
+
+install-data-am:
+
+install-dvi: install-dvi-recursive
+
+install-dvi-am:
+
+install-exec-am:
+
+install-html: install-html-recursive
+
+install-html-am:
+
+install-info: install-info-recursive
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-recursive
+
+install-pdf-am:
+
+install-ps: install-ps-recursive
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-recursive
+       -rm -rf ./$(DEPDIR)
+       -rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-recursive
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+       mostlyclean-libtool
+
+pdf: pdf-recursive
+
+pdf-am:
+
+ps: ps-recursive
+
+ps-am:
+
+uninstall-am:
+
+.MAKE: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) ctags-recursive \
+       install-am install-strip tags-recursive
+
+.PHONY: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) CTAGS GTAGS \
+       all all-am check check-am clean clean-generic clean-libtool \
+       clean-noinstLTLIBRARIES ctags ctags-recursive distclean \
+       distclean-compile distclean-generic distclean-libtool \
+       distclean-tags distdir dvi dvi-am html html-am info info-am \
+       install install-am install-data install-data-am install-dvi \
+       install-dvi-am install-exec install-exec-am install-html \
+       install-html-am install-info install-info-am install-man \
+       install-pdf install-pdf-am install-ps install-ps-am \
+       install-strip installcheck installcheck-am installdirs \
+       installdirs-am maintainer-clean maintainer-clean-generic \
+       mostlyclean mostlyclean-compile mostlyclean-generic \
+       mostlyclean-libtool pdf pdf-am ps ps-am tags tags-recursive \
+       uninstall uninstall-am
+
+
+@HAVE_DOT_GIT_TRUE@git_version.h: $(top_srcdir)/.git/HEAD $(shell sed -e '/ref:/!d' -e 's#ref: *#$(top_srcdir)/.git/#' < $(top_srcdir)/.git/HEAD)
+@HAVE_DOT_GIT_TRUE@    @echo "Recording git-tree used for compilation: `git describe`"
+@HAVE_DOT_GIT_TRUE@    @V=`git describe`; echo "static const char git_version[] = \"$$V\";" > git_version.h
+@HAVE_DOT_GIT_TRUE@sna_driver.c: git_version.h
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/src/sna/README b/src/sna/README
new file mode 100644 (file)
index 0000000..fd847de
--- /dev/null
@@ -0,0 +1,30 @@
+SandyBridge's New Acceleration
+------------------------------
+
+The guiding principle behind the design is to avoid GPU context switches.
+On SandyBridge (and beyond), these are especially pernicious because the
+RENDER and BLT engine are now on different rings and require
+synchronisation of the various execution units when switching contexts.
+They were not cheap on early generation, but with the increasing
+complexity of the GPU, avoiding such serialisations is important.
+
+Furthermore, we try very hard to avoid migrating between the CPU and GPU.
+Every pixmap (apart from temporary "scratch" surfaces which we intend to
+use on the GPU) is created in system memory. All operations are then done
+upon this shadow copy until we are forced to move it onto the GPU. Such
+migration can only be first triggered by: setting the pixmap as the
+scanout (we obviously need a GPU buffer here), using the pixmap as a DRI
+buffer (the client expects to perform hardware acceleration and we do not
+want to disappoint) and lastly using the pixmap as a RENDER target. This
+last is chosen because when we know we are going to perform hardware
+acceleration and will continue to do so without fallbacks, using the GPU
+is much, much faster than the CPU. The heuristic I chose therefore was
+that if the application uses RENDER, i.e. cairo, then it will only be
+using those paths and not intermixing core drawing operations and so
+unlikely to trigger a fallback.
+
+The complicating case is front-buffer rendering. So in order to accommodate
+using RENDER on an application whilst running xterm without a composite
+manager redirecting all the pixmaps to backing surfaces, we have to
+perform damage tracking to avoid excess migration of portions of the
+buffer.
diff --git a/src/sna/blt.c b/src/sna/blt.c
new file mode 100644 (file)
index 0000000..4735d14
--- /dev/null
@@ -0,0 +1,670 @@
+/*
+ * Copyright (c) 2011 Intel 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.
+ *
+ * Authors:
+ *    Chris Wilson <chris@chris-wilson.co.uk>
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "sna.h"
+
+#if __x86_64__
+#define USE_SSE2 1
+#endif
+
+#if USE_SSE2
+#include <xmmintrin.h>
+
+#if __x86_64__
+#define have_sse2() 1
+#else
+enum {
+       MMX = 0x1,
+       MMX_EXTENSIONS = 0x2,
+       SSE = 0x6,
+       SSE2 = 0x8,
+       CMOV = 0x10
+};
+
+#ifdef __GNUC__
+static unsigned int
+detect_cpu_features(void)
+{
+       unsigned int features;
+       unsigned int result = 0;
+
+       char vendor[13];
+       vendor[0] = 0;
+       vendor[12] = 0;
+
+       asm (
+            "pushf\n"
+            "pop %%eax\n"
+            "mov %%eax, %%ecx\n"
+            "xor $0x00200000, %%eax\n"
+            "push %%eax\n"
+            "popf\n"
+            "pushf\n"
+            "pop %%eax\n"
+            "mov $0x0, %%edx\n"
+            "xor %%ecx, %%eax\n"
+            "jz 1f\n"
+
+            "mov $0x00000000, %%eax\n"
+            "push %%ebx\n"
+            "cpuid\n"
+            "mov %%ebx, %%eax\n"
+            "pop %%ebx\n"
+            "mov %%eax, %1\n"
+            "mov %%edx, %2\n"
+            "mov %%ecx, %3\n"
+            "mov $0x00000001, %%eax\n"
+            "push %%ebx\n"
+            "cpuid\n"
+            "pop %%ebx\n"
+            "1:\n"
+            "mov %%edx, %0\n"
+            : "=r" (result), "=m" (vendor[0]), "=m" (vendor[4]), "=m" (vendor[8])
+            :: "%eax", "%ecx", "%edx");
+
+       features = 0;
+       if (result) {
+               /* result now contains the standard feature bits */
+               if (result & (1 << 15))
+                       features |= CMOV;
+               if (result & (1 << 23))
+                       features |= MMX;
+               if (result & (1 << 25))
+                       features |= SSE;
+               if (result & (1 << 26))
+                       features |= SSE2;
+       }
+       return features;
+}
+#else
+static unsigned int detect_cpu_features(void) { return 0; }
+#endif
+
+static bool have_sse2(void)
+{
+       static int sse2_present = -1;
+
+       if (sse2_present == -1)
+               sse2_present = detect_cpu_features() & SSE2;
+
+       return sse2_present;
+}
+#endif
+
+static inline __m128i
+xmm_create_mask_32(uint32_t mask)
+{
+       return _mm_set_epi32(mask, mask, mask, mask);
+}
+
+static inline __m128i
+xmm_load_128u(const __m128i *src)
+{
+       return _mm_loadu_si128(src);
+}
+
+static inline void
+xmm_save_128(__m128i *dst, __m128i data)
+{
+       _mm_store_si128(dst, data);
+}
+#endif
+
+void
+memcpy_blt(const void *src, void *dst, int bpp,
+          int32_t src_stride, int32_t dst_stride,
+          int16_t src_x, int16_t src_y,
+          int16_t dst_x, int16_t dst_y,
+          uint16_t width, uint16_t height)
+{
+       const uint8_t *src_bytes;
+       uint8_t *dst_bytes;
+       int byte_width;
+
+       assert(src);
+       assert(dst);
+       assert(width && height);
+       assert(bpp >= 8);
+       assert(width*bpp <= 8*src_stride);
+       assert(width*bpp <= 8*dst_stride);
+
+       DBG(("%s: src=(%d, %d), dst=(%d, %d), size=%dx%d, pitch=%d/%d\n",
+            __FUNCTION__, src_x, src_y, dst_x, dst_y, width, height, src_stride, dst_stride));
+
+       bpp /= 8;
+
+       src_bytes = (const uint8_t *)src + src_stride * src_y + src_x * bpp;
+       dst_bytes = (uint8_t *)dst + dst_stride * dst_y + dst_x * bpp;
+
+       byte_width = width * bpp;
+       if (byte_width == src_stride && byte_width == dst_stride) {
+               byte_width *= height;
+               height = 1;
+       }
+
+       switch (byte_width) {
+       case 1:
+               do {
+                       *dst_bytes = *src_bytes;
+                       src_bytes += src_stride;
+                       dst_bytes += dst_stride;
+               } while (--height);
+               break;
+
+       case 2:
+               do {
+                       *(uint16_t *)dst_bytes = *(const uint16_t *)src_bytes;
+                       src_bytes += src_stride;
+                       dst_bytes += dst_stride;
+               } while (--height);
+               break;
+
+       case 4:
+               do {
+                       *(uint32_t *)dst_bytes = *(const uint32_t *)src_bytes;
+                       src_bytes += src_stride;
+                       dst_bytes += dst_stride;
+               } while (--height);
+               break;
+
+       case 8:
+               do {
+                       *(uint64_t *)dst_bytes = *(const uint64_t *)src_bytes;
+                       src_bytes += src_stride;
+                       dst_bytes += dst_stride;
+               } while (--height);
+               break;
+
+       default:
+               do {
+                       memcpy(dst_bytes, src_bytes, byte_width);
+                       src_bytes += src_stride;
+                       dst_bytes += dst_stride;
+               } while (--height);
+               break;
+       }
+}
+
+void
+memcpy_to_tiled_x(const void *src, void *dst, int bpp, int swizzling,
+                 int32_t src_stride, int32_t dst_stride,
+                 int16_t src_x, int16_t src_y,
+                 int16_t dst_x, int16_t dst_y,
+                 uint16_t width, uint16_t height)
+{
+       const unsigned tile_width = 512;
+       const unsigned tile_height = 8;
+       const unsigned tile_size = 4096;
+
+       const unsigned cpp = bpp / 8;
+       const unsigned stride_tiles = dst_stride / tile_width;
+       const unsigned swizzle_pixels = (swizzling ? 64 : tile_width) / cpp;
+       const unsigned tile_pixels = ffs(tile_width / cpp) - 1;
+       const unsigned tile_mask = (1 << tile_pixels) - 1;
+
+       unsigned x, y;
+
+       DBG(("%s(bpp=%d, swizzling=%d): src=(%d, %d), dst=(%d, %d), size=%dx%d, pitch=%d/%d\n",
+            __FUNCTION__, bpp, swizzling, src_x, src_y, dst_x, dst_y, width, height, src_stride, dst_stride));
+
+       src = (const uint8_t *)src + src_y * src_stride + src_x * cpp;
+
+       for (y = 0; y < height; ++y) {
+               const uint32_t dy = y + dst_y;
+               const uint32_t tile_row =
+                       (dy / tile_height * stride_tiles * tile_size +
+                        (dy & (tile_height-1)) * tile_width);
+               const uint8_t *src_row = (const uint8_t *)src + src_stride * y;
+               uint32_t dx = dst_x, offset;
+
+               x = width * cpp;
+               if (dx & (swizzle_pixels - 1)) {
+                       const uint32_t swizzle_bound_pixels = ALIGN(dx + 1, swizzle_pixels);
+                       const uint32_t length = min(dst_x + width, swizzle_bound_pixels) - dx;
+                       offset = tile_row +
+                               (dx >> tile_pixels) * tile_size +
+                               (dx & tile_mask) * cpp;
+                       switch (swizzling) {
+                       case I915_BIT_6_SWIZZLE_NONE:
+                               break;
+                       case I915_BIT_6_SWIZZLE_9:
+                               offset ^= (offset >> 3) & 64;
+                               break;
+                       case I915_BIT_6_SWIZZLE_9_10:
+                               offset ^= ((offset ^ (offset >> 1)) >> 3) & 64;
+                               break;
+                       case I915_BIT_6_SWIZZLE_9_11:
+                               offset ^= ((offset ^ (offset >> 2)) >> 3) & 64;
+                               break;
+                       }
+
+                       memcpy((char *)dst + offset, src_row, length * cpp);
+
+                       src_row += length * cpp;
+                       x -= length * cpp;
+                       dx += length;
+               }
+               if (swizzling) {
+                       while (x >= 64) {
+                               offset = tile_row +
+                                       (dx >> tile_pixels) * tile_size +
+                                       (dx & tile_mask) * cpp;
+                               switch (swizzling) {
+                               case I915_BIT_6_SWIZZLE_9:
+                                       offset ^= (offset >> 3) & 64;
+                                       break;
+                               case I915_BIT_6_SWIZZLE_9_10:
+                                       offset ^= ((offset ^ (offset >> 1)) >> 3) & 64;
+                                       break;
+                               case I915_BIT_6_SWIZZLE_9_11:
+                                       offset ^= ((offset ^ (offset >> 2)) >> 3) & 64;
+                                       break;
+                               }
+
+                               memcpy((char *)dst + offset, src_row, 64);
+
+                               src_row += 64;
+                               x -= 64;
+                               dx += swizzle_pixels;
+                       }
+               } else {
+                       while (x >= 512) {
+                               assert((dx & tile_mask) == 0);
+                               offset = tile_row + (dx >> tile_pixels) * tile_size;
+
+                               memcpy((char *)dst + offset, src_row, 512);
+
+                               src_row += 512;
+                               x -= 512;
+                               dx += swizzle_pixels;
+                       }
+               }
+               if (x) {
+                       offset = tile_row +
+                               (dx >> tile_pixels) * tile_size +
+                               (dx & tile_mask) * cpp;
+                       switch (swizzling) {
+                       case I915_BIT_6_SWIZZLE_NONE:
+                               break;
+                       case I915_BIT_6_SWIZZLE_9:
+                               offset ^= (offset >> 3) & 64;
+                               break;
+                       case I915_BIT_6_SWIZZLE_9_10:
+                               offset ^= ((offset ^ (offset >> 1)) >> 3) & 64;
+                               break;
+                       case I915_BIT_6_SWIZZLE_9_11:
+                               offset ^= ((offset ^ (offset >> 2)) >> 3) & 64;
+                               break;
+                       }
+
+                       memcpy((char *)dst + offset, src_row, x);
+               }
+       }
+}
+
+void
+memmove_box(const void *src, void *dst,
+           int bpp, int32_t stride,
+           const BoxRec *box,
+           int dx, int dy)
+{
+       union {
+               uint8_t u8;
+               uint16_t u16;
+               uint32_t u32;
+               uint64_t u64;
+       } tmp;
+       const uint8_t *src_bytes;
+       uint8_t *dst_bytes;
+       int width, height;
+
+       assert(src);
+       assert(dst);
+       assert(bpp >= 8);
+       assert(box->x2 > box->x1);
+       assert(box->y2 > box->y1);
+
+       DBG(("%s: box=(%d, %d), (%d, %d), pitch=%d, bpp=%d, dx=%d, dy=%d\n",
+            __FUNCTION__,
+            box->x1, box->y1, box->x2, box->y2,
+            stride, bpp, dx, dy));
+
+       bpp /= 8;
+       width = box->y1 * stride + box->x1 * bpp;
+       src_bytes = (const uint8_t *)src + width;
+       dst_bytes = (uint8_t *)dst + width;
+
+       width = (box->x2 - box->x1) * bpp;
+       height = (box->y2 - box->y1);
+       assert(width <= 8*stride);
+       if (width == stride) {
+               width *= height;
+               height = 1;
+       }
+
+       if (dy >= 0) {
+               switch (width) {
+               case 1:
+                       do {
+                               *dst_bytes = tmp.u8 = *src_bytes;
+                               src_bytes += stride;
+                               dst_bytes += stride;
+                       } while (--height);
+                       break;
+
+               case 2:
+                       do {
+                               *(uint16_t *)dst_bytes = tmp.u16 = *(const uint16_t *)src_bytes;
+                               src_bytes += stride;
+                               dst_bytes += stride;
+                       } while (--height);
+                       break;
+
+               case 4:
+                       do {
+                               *(uint32_t *)dst_bytes = tmp.u32 = *(const uint32_t *)src_bytes;
+                               src_bytes += stride;
+                               dst_bytes += stride;
+                       } while (--height);
+                       break;
+
+               case 8:
+                       do {
+                               *(uint64_t *)dst_bytes = tmp.u64 = *(const uint64_t *)src_bytes;
+                               src_bytes += stride;
+                               dst_bytes += stride;
+                       } while (--height);
+                       break;
+
+               default:
+                       if (dst_bytes < src_bytes + width &&
+                           src_bytes < dst_bytes + width) {
+                               do {
+                                       memmove(dst_bytes, src_bytes, width);
+                                       src_bytes += stride;
+                                       dst_bytes += stride;
+                               } while (--height);
+                       } else {
+                               do {
+                                       memcpy(dst_bytes, src_bytes, width);
+                                       src_bytes += stride;
+                                       dst_bytes += stride;
+                               } while (--height);
+                       }
+                       break;
+               }
+       } else {
+               src_bytes += (height-1) * stride;
+               dst_bytes += (height-1) * stride;
+
+               switch (width) {
+               case 1:
+                       do {
+                               *dst_bytes = tmp.u8 = *src_bytes;
+                               src_bytes -= stride;
+                               dst_bytes -= stride;
+                       } while (--height);
+                       break;
+
+               case 2:
+                       do {
+                               *(uint16_t *)dst_bytes = tmp.u16 = *(const uint16_t *)src_bytes;
+                               src_bytes -= stride;
+                               dst_bytes -= stride;
+                       } while (--height);
+                       break;
+
+               case 4:
+                       do {
+                               *(uint32_t *)dst_bytes = tmp.u32 = *(const uint32_t *)src_bytes;
+                               src_bytes -= stride;
+                               dst_bytes -= stride;
+                       } while (--height);
+                       break;
+
+               case 8:
+                       do {
+                               *(uint64_t *)dst_bytes = tmp.u64 = *(const uint64_t *)src_bytes;
+                               src_bytes -= stride;
+                               dst_bytes -= stride;
+                       } while (--height);
+                       break;
+
+               default:
+                       if (dst_bytes < src_bytes + width &&
+                           src_bytes < dst_bytes + width) {
+                               do {
+                                       memmove(dst_bytes, src_bytes, width);
+                                       src_bytes -= stride;
+                                       dst_bytes -= stride;
+                               } while (--height);
+                       } else {
+                               do {
+                                       memcpy(dst_bytes, src_bytes, width);
+                                       src_bytes -= stride;
+                                       dst_bytes -= stride;
+                               } while (--height);
+                       }
+                       break;
+               }
+       }
+}
+
+void
+memcpy_xor(const void *src, void *dst, int bpp,
+          int32_t src_stride, int32_t dst_stride,
+          int16_t src_x, int16_t src_y,
+          int16_t dst_x, int16_t dst_y,
+          uint16_t width, uint16_t height,
+          uint32_t and, uint32_t or)
+{
+       const uint8_t *src_bytes;
+       uint8_t *dst_bytes;
+       int i;
+
+       assert(width && height);
+       assert(bpp >= 8);
+       assert(width*bpp <= 8*src_stride);
+       assert(width*bpp <= 8*dst_stride);
+
+       DBG(("%s: src=(%d, %d), dst=(%d, %d), size=%dx%d, pitch=%d/%d, bpp=%d, and=%x, xor=%x\n",
+            __FUNCTION__,
+            src_x, src_y, dst_x, dst_y,
+            width, height,
+            src_stride, dst_stride,
+            bpp, and, or));
+
+       bpp /= 8;
+       src_bytes = (const uint8_t *)src + src_stride * src_y + src_x * bpp;
+       dst_bytes = (uint8_t *)dst + dst_stride * dst_y + dst_x * bpp;
+
+       if (and == 0xffffffff) {
+               switch (bpp) {
+               case 1:
+                       if (width & 1) {
+                               do {
+                                       for (i = 0; i < width; i++)
+                                               dst_bytes[i] = src_bytes[i] | or;
+
+                                       src_bytes += src_stride;
+                                       dst_bytes += dst_stride;
+                               } while (--height);
+                               break;
+                       } else {
+                               width /= 2;
+                               or |= or << 8;
+                       }
+               case 2:
+                       if (width & 1) {
+                               do {
+                                       uint16_t *d = (uint16_t *)dst_bytes;
+                                       const uint16_t *s = (const uint16_t *)src_bytes;
+
+                                       for (i = 0; i < width; i++)
+                                               d[i] = s[i] | or;
+
+                                       src_bytes += src_stride;
+                                       dst_bytes += dst_stride;
+                               } while (--height);
+                               break;
+                       } else {
+                               width /= 2;
+                               or |= or << 16;
+                       }
+               case 4:
+#if USE_SSE2
+                       if (width * 4 == dst_stride && dst_stride == src_stride) {
+                               width *= height;
+                               height = 1;
+                       }
+
+                       if (have_sse2()) {
+                               do {
+                                       uint32_t *d = (uint32_t *)dst_bytes;
+                                       const uint32_t *s = (const uint32_t *)src_bytes;
+                                       __m128i mask = xmm_create_mask_32(or);
+
+                                       i = width;
+                                       while (i && (uintptr_t)d & 15) {
+                                               *d++ = *s++ | or;
+                                               i--;
+                                       }
+
+                                       while (i >= 16) {
+                                               __m128i xmm1, xmm2, xmm3, xmm4;
+
+                                               xmm1 = xmm_load_128u((__m128i*)s + 0);
+                                               xmm2 = xmm_load_128u((__m128i*)s + 1);
+                                               xmm3 = xmm_load_128u((__m128i*)s + 2);
+                                               xmm4 = xmm_load_128u((__m128i*)s + 3);
+
+                                               xmm_save_128((__m128i*)d + 0,
+                                                            _mm_or_si128(xmm1, mask));
+                                               xmm_save_128((__m128i*)d + 1,
+                                                            _mm_or_si128(xmm2, mask));
+                                               xmm_save_128((__m128i*)d + 2,
+                                                            _mm_or_si128(xmm3, mask));
+                                               xmm_save_128((__m128i*)d + 3,
+                                                            _mm_or_si128(xmm4, mask));
+
+                                               d += 16;
+                                               s += 16;
+                                               i -= 16;
+                                       }
+
+                                       if (i & 8) {
+                                               __m128i xmm1, xmm2;
+
+                                               xmm1 = xmm_load_128u((__m128i*)s + 0);
+                                               xmm2 = xmm_load_128u((__m128i*)s + 1);
+
+                                               xmm_save_128((__m128i*)d + 0,
+                                                            _mm_or_si128(xmm1, mask));
+                                               xmm_save_128((__m128i*)d + 1,
+                                                            _mm_or_si128(xmm2, mask));
+                                               d += 8;
+                                               s += 8;
+                                               i -= 8;
+                                       }
+
+                                       if (i & 4) {
+                                               xmm_save_128((__m128i*)d,
+                                                            _mm_or_si128(xmm_load_128u((__m128i*)s),
+                                                                         mask));
+
+                                               d += 4;
+                                               s += 4;
+                                               i -= 4;
+                                       }
+
+                                       while (i) {
+                                               *d++ = *s++ | or;
+                                               i--;
+                                       }
+
+                                       src_bytes += src_stride;
+                                       dst_bytes += dst_stride;
+                               } while (--height);
+                       } else
+#else
+                               do {
+                                       uint32_t *d = (uint32_t *)dst_bytes;
+                                       uint32_t *s = (uint32_t *)src_bytes;
+
+                                       for (i = 0; i < width; i++)
+                                               d[i] = s[i] | or;
+
+                                       src_bytes += src_stride;
+                                       dst_bytes += dst_stride;
+                               } while (--height);
+#endif
+                       break;
+               }
+       } else {
+               switch (bpp) {
+               case 1:
+                       do {
+                               for (i = 0; i < width; i++)
+                                       dst_bytes[i] = (src_bytes[i] & and) | or;
+
+                               src_bytes += src_stride;
+                               dst_bytes += dst_stride;
+                       } while (--height);
+                       break;
+
+               case 2:
+                       do {
+                               uint16_t *d = (uint16_t *)dst_bytes;
+                               uint16_t *s = (uint16_t *)src_bytes;
+
+                               for (i = 0; i < width; i++)
+                                       d[i] = (s[i] & and) | or;
+
+                               src_bytes += src_stride;
+                               dst_bytes += dst_stride;
+                       } while (--height);
+                       break;
+
+               case 4:
+                       do {
+                               uint32_t *d = (uint32_t *)dst_bytes;
+                               uint32_t *s = (uint32_t *)src_bytes;
+
+                               for (i = 0; i < width; i++)
+                                       d[i] = (s[i] & and) | or;
+
+                               src_bytes += src_stride;
+                               dst_bytes += dst_stride;
+                       } while (--height);
+                       break;
+               }
+       }
+}
diff --git a/src/sna/brw/Makefile.am b/src/sna/brw/Makefile.am
new file mode 100644 (file)
index 0000000..b3513cf
--- /dev/null
@@ -0,0 +1,59 @@
+
+#  Copyright 2005 Adam Jackson.
+#
+#  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
+#  on the rights to use, copy, modify, merge, publish, distribute, sub
+#  license, 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 NON-INFRINGEMENT.  IN NO EVENT SHALL
+#  ADAM JACKSON 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.
+
+noinst_LTLIBRARIES = libbrw.la
+noinst_PROGRAMS = brw_test
+
+AM_CFLAGS = \
+       @CWARNFLAGS@ \
+       -I$(top_srcdir)/src \
+       -I$(top_srcdir)/src/render_program \
+       @XORG_CFLAGS@ \
+       @UDEV_CFLAGS@ \
+       @DRM_CFLAGS@ \
+       $(NULL)
+
+if DEBUG
+AM_CFLAGS += @VALGRIND_CFLAGS@
+endif
+
+libbrw_la_SOURCES = \
+       brw.h \
+       brw_disasm.c \
+       brw_eu.h \
+       brw_eu.c \
+       brw_eu_emit.c \
+       brw_sf.c \
+       brw_wm.c \
+       $(NULL)
+
+brw_test_SOURCES = \
+       brw_test.c \
+       brw_test.h \
+       brw_test_gen4.c \
+       brw_test_gen5.c \
+       brw_test_gen6.c \
+       brw_test_gen7.c \
+       $(NULL)
+
+brw_test_LDADD = \
+       libbrw.la \
+       $(NULL)
diff --git a/src/sna/brw/Makefile.in b/src/sna/brw/Makefile.in
new file mode 100644 (file)
index 0000000..209eb87
--- /dev/null
@@ -0,0 +1,637 @@
+# Makefile.in generated by automake 1.11.6 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
+# Foundation, Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+
+#  Copyright 2005 Adam Jackson.
+#
+#  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
+#  on the rights to use, copy, modify, merge, publish, distribute, sub
+#  license, 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 NON-INFRINGEMENT.  IN NO EVENT SHALL
+#  ADAM JACKSON 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.
+
+
+VPATH = @srcdir@
+am__make_dryrun = \
+  { \
+    am__dry=no; \
+    case $$MAKEFLAGS in \
+      *\\[\ \  ]*) \
+        echo 'am--echo: ; @echo "AM"  OK' | $(MAKE) -f - 2>/dev/null \
+          | grep '^AM OK$$' >/dev/null || am__dry=yes;; \
+      *) \
+        for am__flg in $$MAKEFLAGS; do \
+          case $$am__flg in \
+            *=*|--*) ;; \
+            *n*) am__dry=yes; break;; \
+          esac; \
+        done;; \
+    esac; \
+    test $$am__dry = yes; \
+  }
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+noinst_PROGRAMS = brw_test$(EXEEXT)
+@DEBUG_TRUE@am__append_1 = @VALGRIND_CFLAGS@
+subdir = src/sna/brw
+DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+       $(ACLOCAL_M4)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+LTLIBRARIES = $(noinst_LTLIBRARIES)
+libbrw_la_LIBADD =
+am_libbrw_la_OBJECTS = brw_disasm.lo brw_eu.lo brw_eu_emit.lo \
+       brw_sf.lo brw_wm.lo
+libbrw_la_OBJECTS = $(am_libbrw_la_OBJECTS)
+AM_V_lt = $(am__v_lt_@AM_V@)
+am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
+am__v_lt_0 = --silent
+PROGRAMS = $(noinst_PROGRAMS)
+am_brw_test_OBJECTS = brw_test.$(OBJEXT) brw_test_gen4.$(OBJEXT) \
+       brw_test_gen5.$(OBJEXT) brw_test_gen6.$(OBJEXT) \
+       brw_test_gen7.$(OBJEXT)
+brw_test_OBJECTS = $(am_brw_test_OBJECTS)
+brw_test_DEPENDENCIES = libbrw.la
+DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
+depcomp = $(SHELL) $(top_srcdir)/depcomp
+am__depfiles_maybe = depfiles
+am__mv = mv -f
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+       $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+       $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \
+       $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
+       $(AM_CFLAGS) $(CFLAGS)
+AM_V_CC = $(am__v_CC_@AM_V@)
+am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@)
+am__v_CC_0 = @echo "  CC    " $@;
+AM_V_at = $(am__v_at_@AM_V@)
+am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
+am__v_at_0 = @
+CCLD = $(CC)
+LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+       $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+       $(AM_LDFLAGS) $(LDFLAGS) -o $@
+AM_V_CCLD = $(am__v_CCLD_@AM_V@)
+am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
+am__v_CCLD_0 = @echo "  CCLD  " $@;
+AM_V_GEN = $(am__v_GEN_@AM_V@)
+am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
+am__v_GEN_0 = @echo "  GEN   " $@;
+SOURCES = $(libbrw_la_SOURCES) $(brw_test_SOURCES)
+DIST_SOURCES = $(libbrw_la_SOURCES) $(brw_test_SOURCES)
+am__can_run_installinfo = \
+  case $$AM_UPDATE_INFO_DIR in \
+    n|no|NO) false;; \
+    *) (install-info --version) >/dev/null 2>&1;; \
+  esac
+ETAGS = etags
+CTAGS = ctags
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+ADMIN_MAN_DIR = @ADMIN_MAN_DIR@
+ADMIN_MAN_SUFFIX = @ADMIN_MAN_SUFFIX@
+AMTAR = @AMTAR@
+AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
+APP_MAN_DIR = @APP_MAN_DIR@
+APP_MAN_SUFFIX = @APP_MAN_SUFFIX@
+AR = @AR@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+BASE_CFLAGS = @BASE_CFLAGS@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CHANGELOG_CMD = @CHANGELOG_CMD@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CWARNFLAGS = @CWARNFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DLLTOOL = @DLLTOOL@
+DRI2_CFLAGS = @DRI2_CFLAGS@
+DRI2_LIBS = @DRI2_LIBS@
+DRIVER_MAN_DIR = @DRIVER_MAN_DIR@
+DRIVER_MAN_SUFFIX = @DRIVER_MAN_SUFFIX@
+DRIVER_NAME = @DRIVER_NAME@
+DRI_CFLAGS = @DRI_CFLAGS@
+DRI_LIBS = @DRI_LIBS@
+DRMINTEL_CFLAGS = @DRMINTEL_CFLAGS@
+DRMINTEL_LIBS = @DRMINTEL_LIBS@
+DRM_CFLAGS = @DRM_CFLAGS@
+DRM_LIBS = @DRM_LIBS@
+DSYMUTIL = @DSYMUTIL@
+DUMPBIN = @DUMPBIN@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+FGREP = @FGREP@
+FILE_MAN_DIR = @FILE_MAN_DIR@
+FILE_MAN_SUFFIX = @FILE_MAN_SUFFIX@
+GEN4ASM_CFLAGS = @GEN4ASM_CFLAGS@
+GEN4ASM_LIBS = @GEN4ASM_LIBS@
+GREP = @GREP@
+INSTALL = @INSTALL@
+INSTALL_CMD = @INSTALL_CMD@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+LD = @LD@
+LDFLAGS = @LDFLAGS@
+LIBGLAMOR_CFLAGS = @LIBGLAMOR_CFLAGS@
+LIBGLAMOR_EGL_CFLAGS = @LIBGLAMOR_EGL_CFLAGS@
+LIBGLAMOR_EGL_LIBS = @LIBGLAMOR_EGL_LIBS@
+LIBGLAMOR_LIBS = @LIBGLAMOR_LIBS@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBTOOL = @LIBTOOL@
+LIB_MAN_DIR = @LIB_MAN_DIR@
+LIB_MAN_SUFFIX = @LIB_MAN_SUFFIX@
+LIPO = @LIPO@
+LN_S = @LN_S@
+LTLIBOBJS = @LTLIBOBJS@
+MAINT = @MAINT@
+MAKEINFO = @MAKEINFO@
+MANIFEST_TOOL = @MANIFEST_TOOL@
+MAN_SUBSTS = @MAN_SUBSTS@
+MISC_MAN_DIR = @MISC_MAN_DIR@
+MISC_MAN_SUFFIX = @MISC_MAN_SUFFIX@
+MKDIR_P = @MKDIR_P@
+NM = @NM@
+NMEDIT = @NMEDIT@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+OTOOL = @OTOOL@
+OTOOL64 = @OTOOL64@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_URL = @PACKAGE_URL@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PCIACCESS_CFLAGS = @PCIACCESS_CFLAGS@
+PCIACCESS_LIBS = @PCIACCESS_LIBS@
+PKG_CONFIG = @PKG_CONFIG@
+PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
+PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
+RANLIB = @RANLIB@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STRICT_CFLAGS = @STRICT_CFLAGS@
+STRIP = @STRIP@
+UDEV_CFLAGS = @UDEV_CFLAGS@
+UDEV_LIBS = @UDEV_LIBS@
+VALGRIND_CFLAGS = @VALGRIND_CFLAGS@
+VALGRIND_LIBS = @VALGRIND_LIBS@
+VERSION = @VERSION@
+X11_CFLAGS = @X11_CFLAGS@
+X11_LIBS = @X11_LIBS@
+XORG_CFLAGS = @XORG_CFLAGS@
+XORG_LIBS = @XORG_LIBS@
+XORG_MAN_PAGE = @XORG_MAN_PAGE@
+XVMCLIB_CFLAGS = @XVMCLIB_CFLAGS@
+XVMCLIB_LIBS = @XVMCLIB_LIBS@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_AR = @ac_ct_AR@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+moduledir = @moduledir@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+noinst_LTLIBRARIES = libbrw.la
+AM_CFLAGS = @CWARNFLAGS@ -I$(top_srcdir)/src \
+       -I$(top_srcdir)/src/render_program @XORG_CFLAGS@ @UDEV_CFLAGS@ \
+       @DRM_CFLAGS@ $(NULL) $(am__append_1)
+libbrw_la_SOURCES = \
+       brw.h \
+       brw_disasm.c \
+       brw_eu.h \
+       brw_eu.c \
+       brw_eu_emit.c \
+       brw_sf.c \
+       brw_wm.c \
+       $(NULL)
+
+brw_test_SOURCES = \
+       brw_test.c \
+       brw_test.h \
+       brw_test_gen4.c \
+       brw_test_gen5.c \
+       brw_test_gen6.c \
+       brw_test_gen7.c \
+       $(NULL)
+
+brw_test_LDADD = \
+       libbrw.la \
+       $(NULL)
+
+all: all-am
+
+.SUFFIXES:
+.SUFFIXES: .c .lo .o .obj
+$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am  $(am__configure_deps)
+       @for dep in $?; do \
+         case '$(am__configure_deps)' in \
+           *$$dep*) \
+             ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+               && { if test -f $@; then exit 0; else break; fi; }; \
+             exit 1;; \
+         esac; \
+       done; \
+       echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/sna/brw/Makefile'; \
+       $(am__cd) $(top_srcdir) && \
+         $(AUTOMAKE) --foreign src/sna/brw/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+       @case '$?' in \
+         *config.status*) \
+           cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+         *) \
+           echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+           cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+       esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+       cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
+       cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
+       cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+
+clean-noinstLTLIBRARIES:
+       -test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES)
+       @list='$(noinst_LTLIBRARIES)'; for p in $$list; do \
+         dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \
+         test "$$dir" != "$$p" || dir=.; \
+         echo "rm -f \"$${dir}/so_locations\""; \
+         rm -f "$${dir}/so_locations"; \
+       done
+libbrw.la: $(libbrw_la_OBJECTS) $(libbrw_la_DEPENDENCIES) $(EXTRA_libbrw_la_DEPENDENCIES) 
+       $(AM_V_CCLD)$(LINK)  $(libbrw_la_OBJECTS) $(libbrw_la_LIBADD) $(LIBS)
+
+clean-noinstPROGRAMS:
+       @list='$(noinst_PROGRAMS)'; test -n "$$list" || exit 0; \
+       echo " rm -f" $$list; \
+       rm -f $$list || exit $$?; \
+       test -n "$(EXEEXT)" || exit 0; \
+       list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \
+       echo " rm -f" $$list; \
+       rm -f $$list
+brw_test$(EXEEXT): $(brw_test_OBJECTS) $(brw_test_DEPENDENCIES) $(EXTRA_brw_test_DEPENDENCIES) 
+       @rm -f brw_test$(EXEEXT)
+       $(AM_V_CCLD)$(LINK) $(brw_test_OBJECTS) $(brw_test_LDADD) $(LIBS)
+
+mostlyclean-compile:
+       -rm -f *.$(OBJEXT)
+
+distclean-compile:
+       -rm -f *.tab.c
+
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/brw_disasm.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/brw_eu.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/brw_eu_emit.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/brw_sf.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/brw_test.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/brw_test_gen4.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/brw_test_gen5.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/brw_test_gen6.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/brw_test_gen7.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/brw_wm.Plo@am__quote@
+
+.c.o:
+@am__fastdepCC_TRUE@   $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(COMPILE) -c $<
+
+.c.obj:
+@am__fastdepCC_TRUE@   $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+@am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(COMPILE) -c `$(CYGPATH_W) '$<'`
+
+.c.lo:
+@am__fastdepCC_TRUE@   $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $<
+
+mostlyclean-libtool:
+       -rm -f *.lo
+
+clean-libtool:
+       -rm -rf .libs _libs
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+       list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+       unique=`for i in $$list; do \
+           if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+         done | \
+         $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+             END { if (nonempty) { for (i in files) print i; }; }'`; \
+       mkid -fID $$unique
+tags: TAGS
+
+TAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+               $(TAGS_FILES) $(LISP)
+       set x; \
+       here=`pwd`; \
+       list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+       unique=`for i in $$list; do \
+           if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+         done | \
+         $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+             END { if (nonempty) { for (i in files) print i; }; }'`; \
+       shift; \
+       if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
+         test -n "$$unique" || unique=$$empty_fix; \
+         if test $$# -gt 0; then \
+           $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+             "$$@" $$unique; \
+         else \
+           $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+             $$unique; \
+         fi; \
+       fi
+ctags: CTAGS
+CTAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+               $(TAGS_FILES) $(LISP)
+       list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+       unique=`for i in $$list; do \
+           if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+         done | \
+         $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+             END { if (nonempty) { for (i in files) print i; }; }'`; \
+       test -z "$(CTAGS_ARGS)$$unique" \
+         || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+            $$unique
+
+GTAGS:
+       here=`$(am__cd) $(top_builddir) && pwd` \
+         && $(am__cd) $(top_srcdir) \
+         && gtags -i $(GTAGS_ARGS) "$$here"
+
+distclean-tags:
+       -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+distdir: $(DISTFILES)
+       @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+       topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+       list='$(DISTFILES)'; \
+         dist_files=`for file in $$list; do echo $$file; done | \
+         sed -e "s|^$$srcdirstrip/||;t" \
+             -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+       case $$dist_files in \
+         */*) $(MKDIR_P) `echo "$$dist_files" | \
+                          sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+                          sort -u` ;; \
+       esac; \
+       for file in $$dist_files; do \
+         if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+         if test -d $$d/$$file; then \
+           dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+           if test -d "$(distdir)/$$file"; then \
+             find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+           fi; \
+           if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+             cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+             find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+           fi; \
+           cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+         else \
+           test -f "$(distdir)/$$file" \
+           || cp -p $$d/$$file "$(distdir)/$$file" \
+           || exit 1; \
+         fi; \
+       done
+check-am: all-am
+check: check-am
+all-am: Makefile $(LTLIBRARIES) $(PROGRAMS)
+installdirs:
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+       @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+       if test -z '$(STRIP)'; then \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+             install; \
+       else \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+           "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+       fi
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+       -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+       -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+
+maintainer-clean-generic:
+       @echo "This command is intended for maintainers to use"
+       @echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-generic clean-libtool clean-noinstLTLIBRARIES \
+       clean-noinstPROGRAMS mostlyclean-am
+
+distclean: distclean-am
+       -rm -rf ./$(DEPDIR)
+       -rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+       distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+html-am:
+
+info: info-am
+
+info-am:
+
+install-data-am:
+
+install-dvi: install-dvi-am
+
+install-dvi-am:
+
+install-exec-am:
+
+install-html: install-html-am
+
+install-html-am:
+
+install-info: install-info-am
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-am
+
+install-pdf-am:
+
+install-ps: install-ps-am
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+       -rm -rf ./$(DEPDIR)
+       -rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+       mostlyclean-libtool
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am:
+
+.MAKE: install-am install-strip
+
+.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
+       clean-libtool clean-noinstLTLIBRARIES clean-noinstPROGRAMS \
+       ctags distclean distclean-compile distclean-generic \
+       distclean-libtool distclean-tags distdir dvi dvi-am html \
+       html-am info info-am install install-am install-data \
+       install-data-am install-dvi install-dvi-am install-exec \
+       install-exec-am install-html install-html-am install-info \
+       install-info-am install-man install-pdf install-pdf-am \
+       install-ps install-ps-am install-strip installcheck \
+       installcheck-am installdirs maintainer-clean \
+       maintainer-clean-generic mostlyclean mostlyclean-compile \
+       mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
+       tags uninstall uninstall-am
+
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/src/sna/brw/brw.h b/src/sna/brw/brw.h
new file mode 100644 (file)
index 0000000..e5fa72f
--- /dev/null
@@ -0,0 +1,17 @@
+#include "brw_eu.h"
+
+bool brw_sf_kernel__nomask(struct brw_compile *p);
+bool brw_sf_kernel__mask(struct brw_compile *p);
+
+bool brw_wm_kernel__affine(struct brw_compile *p, int dispatch_width);
+bool brw_wm_kernel__affine_mask(struct brw_compile *p, int dispatch_width);
+bool brw_wm_kernel__affine_mask_ca(struct brw_compile *p, int dispatch_width);
+bool brw_wm_kernel__affine_mask_sa(struct brw_compile *p, int dispatch_width);
+
+bool brw_wm_kernel__projective(struct brw_compile *p, int dispatch_width);
+bool brw_wm_kernel__projective_mask(struct brw_compile *p, int dispatch_width);
+bool brw_wm_kernel__projective_mask_ca(struct brw_compile *p, int dispatch_width);
+bool brw_wm_kernel__projective_mask_sa(struct brw_compile *p, int dispatch_width);
+
+bool brw_wm_kernel__affine_opacity(struct brw_compile *p, int dispatch_width);
+bool brw_wm_kernel__projective_opacity(struct brw_compile *p, int dispatch_width);
diff --git a/src/sna/brw/brw_disasm.c b/src/sna/brw/brw_disasm.c
new file mode 100644 (file)
index 0000000..e6da174
--- /dev/null
@@ -0,0 +1,1104 @@
+/*
+ * Copyright © 2008 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <getopt.h>
+#include <unistd.h>
+#include <stdarg.h>
+
+#include "brw_eu.h"
+
+static const struct {
+       const char *name;
+       int nsrc;
+       int ndst;
+} opcode[128] = {
+       [BRW_OPCODE_MOV] = { .name = "mov", .nsrc = 1, .ndst = 1 },
+       [BRW_OPCODE_FRC] = { .name = "frc", .nsrc = 1, .ndst = 1 },
+       [BRW_OPCODE_RNDU] = { .name = "rndu", .nsrc = 1, .ndst = 1 },
+       [BRW_OPCODE_RNDD] = { .name = "rndd", .nsrc = 1, .ndst = 1 },
+       [BRW_OPCODE_RNDE] = { .name = "rnde", .nsrc = 1, .ndst = 1 },
+       [BRW_OPCODE_RNDZ] = { .name = "rndz", .nsrc = 1, .ndst = 1 },
+       [BRW_OPCODE_NOT] = { .name = "not", .nsrc = 1, .ndst = 1 },
+       [BRW_OPCODE_LZD] = { .name = "lzd", .nsrc = 1, .ndst = 1 },
+
+       [BRW_OPCODE_MUL] = { .name = "mul", .nsrc = 2, .ndst = 1 },
+       [BRW_OPCODE_MAC] = { .name = "mac", .nsrc = 2, .ndst = 1 },
+       [BRW_OPCODE_MACH] = { .name = "mach", .nsrc = 2, .ndst = 1 },
+       [BRW_OPCODE_LINE] = { .name = "line", .nsrc = 2, .ndst = 1 },
+       [BRW_OPCODE_PLN] = { .name = "pln", .nsrc = 2, .ndst = 1 },
+       [BRW_OPCODE_SAD2] = { .name = "sad2", .nsrc = 2, .ndst = 1 },
+       [BRW_OPCODE_SADA2] = { .name = "sada2", .nsrc = 2, .ndst = 1 },
+       [BRW_OPCODE_DP4] = { .name = "dp4", .nsrc = 2, .ndst = 1 },
+       [BRW_OPCODE_DPH] = { .name = "dph", .nsrc = 2, .ndst = 1 },
+       [BRW_OPCODE_DP3] = { .name = "dp3", .nsrc = 2, .ndst = 1 },
+       [BRW_OPCODE_DP2] = { .name = "dp2", .nsrc = 2, .ndst = 1 },
+       [BRW_OPCODE_MATH] = { .name = "math", .nsrc = 2, .ndst = 1 },
+
+       [BRW_OPCODE_AVG] = { .name = "avg", .nsrc = 2, .ndst = 1 },
+       [BRW_OPCODE_ADD] = { .name = "add", .nsrc = 2, .ndst = 1 },
+       [BRW_OPCODE_SEL] = { .name = "sel", .nsrc = 2, .ndst = 1 },
+       [BRW_OPCODE_AND] = { .name = "and", .nsrc = 2, .ndst = 1 },
+       [BRW_OPCODE_OR] = { .name = "or", .nsrc = 2, .ndst = 1 },
+       [BRW_OPCODE_XOR] = { .name = "xor", .nsrc = 2, .ndst = 1 },
+       [BRW_OPCODE_SHR] = { .name = "shr", .nsrc = 2, .ndst = 1 },
+       [BRW_OPCODE_SHL] = { .name = "shl", .nsrc = 2, .ndst = 1 },
+       [BRW_OPCODE_ASR] = { .name = "asr", .nsrc = 2, .ndst = 1 },
+       [BRW_OPCODE_CMP] = { .name = "cmp", .nsrc = 2, .ndst = 1 },
+       [BRW_OPCODE_CMPN] = { .name = "cmpn", .nsrc = 2, .ndst = 1 },
+
+       [BRW_OPCODE_SEND] = { .name = "send", .nsrc = 1, .ndst = 1 },
+       [BRW_OPCODE_SENDC] = { .name = "sendc", .nsrc = 1, .ndst = 1 },
+       [BRW_OPCODE_NOP] = { .name = "nop", .nsrc = 0, .ndst = 0 },
+       [BRW_OPCODE_JMPI] = { .name = "jmpi", .nsrc = 1, .ndst = 0 },
+       [BRW_OPCODE_IF] = { .name = "if", .nsrc = 2, .ndst = 0 },
+       [BRW_OPCODE_IFF] = { .name = "iff", .nsrc = 2, .ndst = 1 },
+       [BRW_OPCODE_WHILE] = { .name = "while", .nsrc = 2, .ndst = 0 },
+       [BRW_OPCODE_ELSE] = { .name = "else", .nsrc = 2, .ndst = 0 },
+       [BRW_OPCODE_BREAK] = { .name = "break", .nsrc = 2, .ndst = 0 },
+       [BRW_OPCODE_CONTINUE] = { .name = "cont", .nsrc = 1, .ndst = 0 },
+       [BRW_OPCODE_HALT] = { .name = "halt", .nsrc = 1, .ndst = 0 },
+       [BRW_OPCODE_MSAVE] = { .name = "msave", .nsrc = 1, .ndst = 1 },
+       [BRW_OPCODE_PUSH] = { .name = "push", .nsrc = 1, .ndst = 1 },
+       [BRW_OPCODE_MRESTORE] = { .name = "mrest", .nsrc = 1, .ndst = 1 },
+       [BRW_OPCODE_POP] = { .name = "pop", .nsrc = 2, .ndst = 0 },
+       [BRW_OPCODE_WAIT] = { .name = "wait", .nsrc = 1, .ndst = 0 },
+       [BRW_OPCODE_DO] = { .name = "do", .nsrc = 0, .ndst = 0 },
+       [BRW_OPCODE_ENDIF] = { .name = "endif", .nsrc = 2, .ndst = 0 },
+};
+
+static const char *conditional_modifier[16] = {
+       [BRW_CONDITIONAL_NONE] = "",
+       [BRW_CONDITIONAL_Z] = ".e",
+       [BRW_CONDITIONAL_NZ] = ".ne",
+       [BRW_CONDITIONAL_G] = ".g",
+       [BRW_CONDITIONAL_GE] = ".ge",
+       [BRW_CONDITIONAL_L] = ".l",
+       [BRW_CONDITIONAL_LE] = ".le",
+       [BRW_CONDITIONAL_R] = ".r",
+       [BRW_CONDITIONAL_O] = ".o",
+       [BRW_CONDITIONAL_U] = ".u",
+};
+
+static const char *negate[2] = {
+       [0] = "",
+       [1] = "-",
+};
+
+static const char *_abs[2] = {
+       [0] = "",
+       [1] = "(abs)",
+};
+
+static const char *vert_stride[16] = {
+       [0] = "0",
+       [1] = "1",
+       [2] = "2",
+       [3] = "4",
+       [4] = "8",
+       [5] = "16",
+       [6] = "32",
+       [15] = "VxH",
+};
+
+static const char *width[8] = {
+       [0] = "1",
+       [1] = "2",
+       [2] = "4",
+       [3] = "8",
+       [4] = "16",
+};
+
+static const char *horiz_stride[4] = {
+       [0] = "0",
+       [1] = "1",
+       [2] = "2",
+       [3] = "4"
+};
+
+static const char *chan_sel[4] = {
+       [0] = "x",
+       [1] = "y",
+       [2] = "z",
+       [3] = "w",
+};
+
+#if 0
+static const char *dest_condmod[16] = {
+};
+
+static const char *imm_encoding[8] = {
+       [0] = "UD",
+       [1] = "D",
+       [2] = "UW",
+       [3] = "W",
+       [5] = "VF",
+       [6] = "V",
+       [7] = "F"
+};
+#endif
+
+static const char *debug_ctrl[2] = {
+       [0] = "",
+       [1] = ".breakpoint"
+};
+
+static const char *saturate[2] = {
+       [0] = "",
+       [1] = ".sat"
+};
+
+static const char *accwr[2] = {
+       [0] = "",
+       [1] = "AccWrEnable"
+};
+
+static const char *wectrl[2] = {
+       [0] = "WE_normal",
+       [1] = "WE_all"
+};
+
+static const char *exec_size[8] = {
+       [0] = "1",
+       [1] = "2",
+       [2] = "4",
+       [3] = "8",
+       [4] = "16",
+       [5] = "32"
+};
+
+static const char *pred_inv[2] = {
+       [0] = "+",
+       [1] = "-"
+};
+
+static const char *pred_ctrl_align16[16] = {
+       [1] = "",
+       [2] = ".x",
+       [3] = ".y",
+       [4] = ".z",
+       [5] = ".w",
+       [6] = ".any4h",
+       [7] = ".all4h",
+};
+
+static const char *pred_ctrl_align1[16] = {
+       [1] = "",
+       [2] = ".anyv",
+       [3] = ".allv",
+       [4] = ".any2h",
+       [5] = ".all2h",
+       [6] = ".any4h",
+       [7] = ".all4h",
+       [8] = ".any8h",
+       [9] = ".all8h",
+       [10] = ".any16h",
+       [11] = ".all16h",
+};
+
+static const char *thread_ctrl[4] = {
+       [0] = "",
+       [2] = "switch"
+};
+
+static const char *compr_ctrl[4] = {
+       [0] = "",
+       [1] = "sechalf",
+       [2] = "compr",
+       [3] = "compr4",
+};
+
+static const char *dep_ctrl[4] = {
+       [0] = "",
+       [1] = "NoDDClr",
+       [2] = "NoDDChk",
+       [3] = "NoDDClr,NoDDChk",
+};
+
+static const char *mask_ctrl[4] = {
+       [0] = "",
+       [1] = "nomask",
+};
+
+static const char *access_mode[2] = {
+       [0] = "align1",
+       [1] = "align16",
+};
+
+static const char *reg_encoding[8] = {
+       [0] = "UD",
+       [1] = "D",
+       [2] = "UW",
+       [3] = "W",
+       [4] = "UB",
+       [5] = "B",
+       [7] = "F"
+};
+
+static const int reg_type_size[8] = {
+       [0] = 4,
+       [1] = 4,
+       [2] = 2,
+       [3] = 2,
+       [4] = 1,
+       [5] = 1,
+       [7] = 4
+};
+
+static const char *reg_file[4] = {
+       [0] = "A",
+       [1] = "g",
+       [2] = "m",
+       [3] = "imm",
+};
+
+static const char *writemask[16] = {
+       [0x0] = ".",
+       [0x1] = ".x",
+       [0x2] = ".y",
+       [0x3] = ".xy",
+       [0x4] = ".z",
+       [0x5] = ".xz",
+       [0x6] = ".yz",
+       [0x7] = ".xyz",
+       [0x8] = ".w",
+       [0x9] = ".xw",
+       [0xa] = ".yw",
+       [0xb] = ".xyw",
+       [0xc] = ".zw",
+       [0xd] = ".xzw",
+       [0xe] = ".yzw",
+       [0xf] = "",
+};
+
+static const char *end_of_thread[2] = {
+       [0] = "",
+       [1] = "EOT"
+};
+
+static const char *target_function[16] = {
+       [BRW_SFID_NULL] = "null",
+       [BRW_SFID_MATH] = "math",
+       [BRW_SFID_SAMPLER] = "sampler",
+       [BRW_SFID_MESSAGE_GATEWAY] = "gateway",
+       [BRW_SFID_DATAPORT_READ] = "read",
+       [BRW_SFID_DATAPORT_WRITE] = "write",
+       [BRW_SFID_URB] = "urb",
+       [BRW_SFID_THREAD_SPAWNER] = "thread_spawner"
+};
+
+static const char *target_function_gen6[16] = {
+       [BRW_SFID_NULL] = "null",
+       [BRW_SFID_MATH] = "math",
+       [BRW_SFID_SAMPLER] = "sampler",
+       [BRW_SFID_MESSAGE_GATEWAY] = "gateway",
+       [BRW_SFID_URB] = "urb",
+       [BRW_SFID_THREAD_SPAWNER] = "thread_spawner",
+       [GEN6_SFID_DATAPORT_SAMPLER_CACHE] = "sampler",
+       [GEN6_SFID_DATAPORT_RENDER_CACHE] = "render",
+       [GEN6_SFID_DATAPORT_CONSTANT_CACHE] = "const",
+       [GEN7_SFID_DATAPORT_DATA_CACHE] = "data"
+};
+
+static const char *dp_rc_msg_type_gen6[16] = {
+       [BRW_DATAPORT_READ_MESSAGE_OWORD_BLOCK_READ] = "OWORD block read",
+       [GEN6_DATAPORT_READ_MESSAGE_RENDER_UNORM_READ] = "RT UNORM read",
+       [GEN6_DATAPORT_READ_MESSAGE_OWORD_DUAL_BLOCK_READ] = "OWORD dual block read",
+       [GEN6_DATAPORT_READ_MESSAGE_MEDIA_BLOCK_READ] = "media block read",
+       [GEN6_DATAPORT_READ_MESSAGE_OWORD_UNALIGN_BLOCK_READ] = "OWORD unaligned block read",
+       [GEN6_DATAPORT_READ_MESSAGE_DWORD_SCATTERED_READ] = "DWORD scattered read",
+       [GEN6_DATAPORT_WRITE_MESSAGE_DWORD_ATOMIC_WRITE] = "DWORD atomic write",
+       [GEN6_DATAPORT_WRITE_MESSAGE_OWORD_BLOCK_WRITE] = "OWORD block write",
+       [GEN6_DATAPORT_WRITE_MESSAGE_OWORD_DUAL_BLOCK_WRITE] = "OWORD dual block write",
+       [GEN6_DATAPORT_WRITE_MESSAGE_MEDIA_BLOCK_WRITE] = "media block write",
+       [GEN6_DATAPORT_WRITE_MESSAGE_DWORD_SCATTERED_WRITE] = "DWORD scattered write",
+       [GEN6_DATAPORT_WRITE_MESSAGE_RENDER_TARGET_WRITE] = "RT write",
+       [GEN6_DATAPORT_WRITE_MESSAGE_STREAMED_VB_WRITE] = "streamed VB write",
+       [GEN6_DATAPORT_WRITE_MESSAGE_RENDER_TARGET_UNORM_WRITE] = "RT UNORMc write",
+};
+
+static const char *math_function[16] = {
+       [BRW_MATH_FUNCTION_INV] = "inv",
+       [BRW_MATH_FUNCTION_LOG] = "log",
+       [BRW_MATH_FUNCTION_EXP] = "exp",
+       [BRW_MATH_FUNCTION_SQRT] = "sqrt",
+       [BRW_MATH_FUNCTION_RSQ] = "rsq",
+       [BRW_MATH_FUNCTION_SIN] = "sin",
+       [BRW_MATH_FUNCTION_COS] = "cos",
+       [BRW_MATH_FUNCTION_SINCOS] = "sincos",
+       [BRW_MATH_FUNCTION_TAN] = "tan",
+       [BRW_MATH_FUNCTION_POW] = "pow",
+       [BRW_MATH_FUNCTION_INT_DIV_QUOTIENT_AND_REMAINDER] = "intdivmod",
+       [BRW_MATH_FUNCTION_INT_DIV_QUOTIENT] = "intdiv",
+       [BRW_MATH_FUNCTION_INT_DIV_REMAINDER] = "intmod",
+};
+
+static const char *math_saturate[2] = {
+       [0] = "",
+       [1] = "sat"
+};
+
+static const char *math_signed[2] = {
+       [0] = "",
+       [1] = "signed"
+};
+
+static const char *math_scalar[2] = {
+       [0] = "",
+       [1] = "scalar"
+};
+
+static const char *math_precision[2] = {
+       [0] = "",
+       [1] = "partial_precision"
+};
+
+static const char *urb_opcode[2] = {
+       [0] = "urb_write",
+       [1] = "ff_sync",
+};
+
+static const char *urb_swizzle[4] = {
+       [BRW_URB_SWIZZLE_NONE] = "",
+       [BRW_URB_SWIZZLE_INTERLEAVE] = "interleave",
+       [BRW_URB_SWIZZLE_TRANSPOSE] = "transpose",
+};
+
+static const char *urb_allocate[2] = {
+       [0] = "",
+       [1] = "allocate"
+};
+
+static const char *urb_used[2] = {
+       [0] = "",
+       [1] = "used"
+};
+
+static const char *urb_complete[2] = {
+       [0] = "",
+       [1] = "complete"
+};
+
+static const char *sampler_target_format[4] = {
+       [0] = "F",
+       [2] = "UD",
+       [3] = "D"
+};
+
+static int column;
+
+static int string(FILE *file, const char *str)
+{
+       fputs(str, file);
+       column += strlen(str);
+       return 0;
+}
+
+#if defined(__GNUC__) && (__GNUC__ > 2)
+__attribute__((format(printf, 2, 3)))
+#endif
+static int format(FILE *f, const char *fmt, ...)
+{
+       char buf[1024];
+       va_list args;
+
+       va_start(args, fmt);
+       vsnprintf(buf, sizeof(buf) - 1, fmt, args);
+       va_end(args);
+
+       string(f, buf);
+       return 0;
+}
+
+static void newline(FILE *f)
+{
+       putc('\n', f);
+       column = 0;
+}
+
+static void pad(FILE *f, int c)
+{
+       do
+               string(f, " ");
+       while (column < c);
+}
+
+static void control(FILE *file, const char *name, const char *ctrl[], unsigned id, int *space)
+{
+       if (!ctrl[id]) {
+               fprintf(file, "*** invalid %s value %d ",
+                       name, id);
+               assert(0);
+       }
+       if (ctrl[id][0]) {
+               if (space && *space)
+                       string(file, " ");
+               string(file, ctrl[id]);
+               if (space)
+                       *space = 1;
+       }
+}
+
+static void print_opcode(FILE *file, int id)
+{
+       if (!opcode[id].name) {
+               format(file, "*** invalid opcode value %d ", id);
+               assert(0);
+       }
+       string(file, opcode[id].name);
+}
+
+static int reg(FILE *file, unsigned _reg_file, unsigned _reg_nr)
+{
+       /* Clear the Compr4 instruction compression bit. */
+       if (_reg_file == BRW_MESSAGE_REGISTER_FILE)
+               _reg_nr &= ~(1 << 7);
+
+       if (_reg_file == BRW_ARCHITECTURE_REGISTER_FILE) {
+               switch (_reg_nr & 0xf0) {
+               case BRW_ARF_NULL:
+                       string(file, "null");
+                       return -1;
+               case BRW_ARF_ADDRESS:
+                       format(file, "a%d", _reg_nr & 0x0f);
+                       break;
+               case BRW_ARF_ACCUMULATOR:
+                       format(file, "acc%d", _reg_nr & 0x0f);
+                       break;
+               case BRW_ARF_FLAG:
+                       format(file, "f%d", _reg_nr & 0x0f);
+                       break;
+               case BRW_ARF_MASK:
+                       format(file, "mask%d", _reg_nr & 0x0f);
+                       break;
+               case BRW_ARF_MASK_STACK:
+                       format(file, "msd%d", _reg_nr & 0x0f);
+                       break;
+               case BRW_ARF_STATE:
+                       format(file, "sr%d", _reg_nr & 0x0f);
+                       break;
+               case BRW_ARF_CONTROL:
+                       format(file, "cr%d", _reg_nr & 0x0f);
+                       break;
+               case BRW_ARF_NOTIFICATION_COUNT:
+                       format(file, "n%d", _reg_nr & 0x0f);
+                       break;
+               case BRW_ARF_IP:
+                       string(file, "ip");
+                       return -1;
+               default:
+                       format(file, "ARF%d", _reg_nr);
+                       break;
+               }
+       } else {
+               control(file, "src reg file", reg_file, _reg_file, NULL);
+               format(file, "%d", _reg_nr);
+       }
+       return 0;
+}
+
+static void dest(FILE *file, const struct brw_instruction *inst)
+{
+       if (inst->header.access_mode == BRW_ALIGN_1) {
+               if (inst->bits1.da1.dest_address_mode == BRW_ADDRESS_DIRECT) {
+                       if (reg(file, inst->bits1.da1.dest_reg_file, inst->bits1.da1.dest_reg_nr))
+                               return;
+
+                       if (inst->bits1.da1.dest_subreg_nr)
+                               format(file, ".%d", inst->bits1.da1.dest_subreg_nr /
+                                      reg_type_size[inst->bits1.da1.dest_reg_type]);
+                       format(file, "<%d>", inst->bits1.da1.dest_horiz_stride);
+                       control(file, "dest reg encoding", reg_encoding, inst->bits1.da1.dest_reg_type, NULL);
+               } else {
+                       string(file, "g[a0");
+                       if (inst->bits1.ia1.dest_subreg_nr)
+                               format(file, ".%d", inst->bits1.ia1.dest_subreg_nr /
+                                      reg_type_size[inst->bits1.ia1.dest_reg_type]);
+                       if (inst->bits1.ia1.dest_indirect_offset)
+                               format(file, " %d", inst->bits1.ia1.dest_indirect_offset);
+                       string(file, "]");
+                       format(file, "<%d>", inst->bits1.ia1.dest_horiz_stride);
+                       control(file, "dest reg encoding", reg_encoding, inst->bits1.ia1.dest_reg_type, NULL);
+               }
+       } else {
+               if (inst->bits1.da16.dest_address_mode == BRW_ADDRESS_DIRECT) {
+                       if (reg(file, inst->bits1.da16.dest_reg_file, inst->bits1.da16.dest_reg_nr))
+                               return;
+
+                       if (inst->bits1.da16.dest_subreg_nr)
+                               format(file, ".%d", inst->bits1.da16.dest_subreg_nr /
+                                      reg_type_size[inst->bits1.da16.dest_reg_type]);
+                       string(file, "<1>");
+                       control(file, "writemask", writemask, inst->bits1.da16.dest_writemask, NULL);
+                       control(file, "dest reg encoding", reg_encoding, inst->bits1.da16.dest_reg_type, NULL);
+               } else {
+                       string(file, "Indirect align16 address mode not supported");
+               }
+       }
+}
+
+static void src_align1_region(FILE *file,
+                             unsigned _vert_stride, unsigned _width, unsigned _horiz_stride)
+{
+       string(file, "<");
+       control(file, "vert stride", vert_stride, _vert_stride, NULL);
+       string(file, ",");
+       control(file, "width", width, _width, NULL);
+       string(file, ",");
+       control(file, "horiz_stride", horiz_stride, _horiz_stride, NULL);
+       string(file, ">");
+}
+
+static void src_da1(FILE *file, unsigned type, unsigned _reg_file,
+                   unsigned _vert_stride, unsigned _width, unsigned _horiz_stride,
+                   unsigned reg_num, unsigned sub_reg_num, unsigned __abs, unsigned _negate)
+{
+       control(file, "negate", negate, _negate, NULL);
+       control(file, "abs", _abs, __abs, NULL);
+
+       if (reg(file, _reg_file, reg_num))
+               return;
+
+       if (sub_reg_num)
+               format(file, ".%d", sub_reg_num / reg_type_size[type]); /* use formal style like spec */
+       src_align1_region(file, _vert_stride, _width, _horiz_stride);
+       control(file, "src reg encoding", reg_encoding, type, NULL);
+}
+
+static void src_ia1(FILE *file,
+                   unsigned type,
+                   unsigned _reg_file,
+                   int _addr_imm,
+                   unsigned _addr_subreg_nr,
+                   unsigned _negate,
+                   unsigned __abs,
+                   unsigned _addr_mode,
+                   unsigned _horiz_stride,
+                   unsigned _width,
+                   unsigned _vert_stride)
+{
+       control(file, "negate", negate, _negate, NULL);
+       control(file, "abs", _abs, __abs, NULL);
+
+       string(file, "g[a0");
+       if (_addr_subreg_nr)
+               format(file, ".%d", _addr_subreg_nr);
+       if (_addr_imm)
+               format(file, " %d", _addr_imm);
+       string(file, "]");
+       src_align1_region(file, _vert_stride, _width, _horiz_stride);
+       control(file, "src reg encoding", reg_encoding, type, NULL);
+}
+
+static void src_da16(FILE *file,
+                    unsigned _reg_type,
+                    unsigned _reg_file,
+                    unsigned _vert_stride,
+                    unsigned _reg_nr,
+                    unsigned _subreg_nr,
+                    unsigned __abs,
+                    unsigned _negate,
+                    unsigned swz_x,
+                    unsigned swz_y,
+                    unsigned swz_z,
+                    unsigned swz_w)
+{
+       control(file, "negate", negate, _negate, NULL);
+       control(file, "abs", _abs, __abs, NULL);
+
+       if (reg(file, _reg_file, _reg_nr))
+               return;
+
+       if (_subreg_nr)
+               /* bit4 for subreg number byte addressing. Make this same meaning as
+                  in da1 case, so output looks consistent. */
+               format(file, ".%d", 16 / reg_type_size[_reg_type]);
+       string(file, "<");
+       control(file, "vert stride", vert_stride, _vert_stride, NULL);
+       string(file, ",4,1>");
+       /*
+        * Three kinds of swizzle display:
+        *  identity - nothing printed
+        *  1->all       - print the single channel
+        *  1->1     - print the mapping
+        */
+       if (swz_x == BRW_CHANNEL_X &&
+           swz_y == BRW_CHANNEL_Y &&
+           swz_z == BRW_CHANNEL_Z &&
+           swz_w == BRW_CHANNEL_W)
+       {
+               ;
+       }
+       else if (swz_x == swz_y && swz_x == swz_z && swz_x == swz_w)
+       {
+               string(file, ".");
+               control(file, "channel select", chan_sel, swz_x, NULL);
+       }
+       else
+       {
+               string(file, ".");
+               control(file, "channel select", chan_sel, swz_x, NULL);
+               control(file, "channel select", chan_sel, swz_y, NULL);
+               control(file, "channel select", chan_sel, swz_z, NULL);
+               control(file, "channel select", chan_sel, swz_w, NULL);
+       }
+       control(file, "src da16 reg type", reg_encoding, _reg_type, NULL);
+}
+
+static void imm(FILE *file, unsigned type, const struct brw_instruction *inst)
+{
+       switch (type) {
+       case BRW_REGISTER_TYPE_UD:
+               format(file, "0x%08xUD", inst->bits3.ud);
+               break;
+       case BRW_REGISTER_TYPE_D:
+               format(file, "%dD", inst->bits3.d);
+               break;
+       case BRW_REGISTER_TYPE_UW:
+               format(file, "0x%04xUW", (uint16_t) inst->bits3.ud);
+               break;
+       case BRW_REGISTER_TYPE_W:
+               format(file, "%dW", (int16_t) inst->bits3.d);
+               break;
+       case BRW_REGISTER_TYPE_UB:
+               format(file, "0x%02xUB", (int8_t) inst->bits3.ud);
+               break;
+       case BRW_REGISTER_TYPE_VF:
+               format(file, "Vector Float");
+               break;
+       case BRW_REGISTER_TYPE_V:
+               format(file, "0x%08xV", inst->bits3.ud);
+               break;
+       case BRW_REGISTER_TYPE_F:
+               format(file, "%-gF", inst->bits3.f);
+       }
+}
+
+static void src0(FILE *file, const struct brw_instruction *inst)
+{
+       if (inst->bits1.da1.src0_reg_file == BRW_IMMEDIATE_VALUE)
+               imm(file, inst->bits1.da1.src0_reg_type, inst);
+       else if (inst->header.access_mode == BRW_ALIGN_1) {
+               if (inst->bits2.da1.src0_address_mode == BRW_ADDRESS_DIRECT) {
+                       src_da1(file,
+                               inst->bits1.da1.src0_reg_type,
+                               inst->bits1.da1.src0_reg_file,
+                               inst->bits2.da1.src0_vert_stride,
+                               inst->bits2.da1.src0_width,
+                               inst->bits2.da1.src0_horiz_stride,
+                               inst->bits2.da1.src0_reg_nr,
+                               inst->bits2.da1.src0_subreg_nr,
+                               inst->bits2.da1.src0_abs,
+                               inst->bits2.da1.src0_negate);
+               } else {
+                       src_ia1(file,
+                               inst->bits1.ia1.src0_reg_type,
+                               inst->bits1.ia1.src0_reg_file,
+                               inst->bits2.ia1.src0_indirect_offset,
+                               inst->bits2.ia1.src0_subreg_nr,
+                               inst->bits2.ia1.src0_negate,
+                               inst->bits2.ia1.src0_abs,
+                               inst->bits2.ia1.src0_address_mode,
+                               inst->bits2.ia1.src0_horiz_stride,
+                               inst->bits2.ia1.src0_width,
+                               inst->bits2.ia1.src0_vert_stride);
+               }
+       } else {
+               if (inst->bits2.da16.src0_address_mode == BRW_ADDRESS_DIRECT) {
+                       src_da16(file,
+                                inst->bits1.da16.src0_reg_type,
+                                inst->bits1.da16.src0_reg_file,
+                                inst->bits2.da16.src0_vert_stride,
+                                inst->bits2.da16.src0_reg_nr,
+                                inst->bits2.da16.src0_subreg_nr,
+                                inst->bits2.da16.src0_abs,
+                                inst->bits2.da16.src0_negate,
+                                inst->bits2.da16.src0_swz_x,
+                                inst->bits2.da16.src0_swz_y,
+                                inst->bits2.da16.src0_swz_z,
+                                inst->bits2.da16.src0_swz_w);
+               } else {
+                       string(file, "Indirect align16 address mode not supported");
+               }
+       }
+}
+
+static void src1(FILE *file, const struct brw_instruction *inst)
+{
+       if (inst->bits1.da1.src1_reg_file == BRW_IMMEDIATE_VALUE)
+               imm(file, inst->bits1.da1.src1_reg_type, inst);
+       else if (inst->header.access_mode == BRW_ALIGN_1) {
+               if (inst->bits3.da1.src1_address_mode == BRW_ADDRESS_DIRECT) {
+                       src_da1(file,
+                               inst->bits1.da1.src1_reg_type,
+                               inst->bits1.da1.src1_reg_file,
+                               inst->bits3.da1.src1_vert_stride,
+                               inst->bits3.da1.src1_width,
+                               inst->bits3.da1.src1_horiz_stride,
+                               inst->bits3.da1.src1_reg_nr,
+                               inst->bits3.da1.src1_subreg_nr,
+                               inst->bits3.da1.src1_abs,
+                               inst->bits3.da1.src1_negate);
+               } else {
+                       src_ia1(file,
+                               inst->bits1.ia1.src1_reg_type,
+                               inst->bits1.ia1.src1_reg_file,
+                               inst->bits3.ia1.src1_indirect_offset,
+                               inst->bits3.ia1.src1_subreg_nr,
+                               inst->bits3.ia1.src1_negate,
+                               inst->bits3.ia1.src1_abs,
+                               inst->bits3.ia1.src1_address_mode,
+                               inst->bits3.ia1.src1_horiz_stride,
+                               inst->bits3.ia1.src1_width,
+                               inst->bits3.ia1.src1_vert_stride);
+               }
+       } else {
+               if (inst->bits3.da16.src1_address_mode == BRW_ADDRESS_DIRECT) {
+                       src_da16(file,
+                                inst->bits1.da16.src1_reg_type,
+                                inst->bits1.da16.src1_reg_file,
+                                inst->bits3.da16.src1_vert_stride,
+                                inst->bits3.da16.src1_reg_nr,
+                                inst->bits3.da16.src1_subreg_nr,
+                                inst->bits3.da16.src1_abs,
+                                inst->bits3.da16.src1_negate,
+                                inst->bits3.da16.src1_swz_x,
+                                inst->bits3.da16.src1_swz_y,
+                                inst->bits3.da16.src1_swz_z,
+                                inst->bits3.da16.src1_swz_w);
+               } else {
+                       string(file, "Indirect align16 address mode not supported");
+               }
+       }
+}
+
+static const int esize[6] = {
+       [0] = 1,
+       [1] = 2,
+       [2] = 4,
+       [3] = 8,
+       [4] = 16,
+       [5] = 32,
+};
+
+static int qtr_ctrl(FILE *file, const struct brw_instruction *inst)
+{
+       int qtr_ctl = inst->header.compression_control;
+       int size = esize[inst->header.execution_size];
+
+       if (size == 8) {
+               switch (qtr_ctl) {
+               case 0:
+                       string(file, " 1Q");
+                       break;
+               case 1:
+                       string(file, " 2Q");
+                       break;
+               case 2:
+                       string(file, " 3Q");
+                       break;
+               case 3:
+                       string(file, " 4Q");
+                       break;
+               }
+       } else if (size == 16){
+               if (qtr_ctl < 2)
+                       string(file, " 1H");
+               else
+                       string(file, " 2H");
+       }
+       return 0;
+}
+
+void brw_disasm(FILE *file, const struct brw_instruction *inst, int gen)
+{
+       int space = 0;
+
+       format(file, "%08x %08x %08x %08x\n",
+              ((const uint32_t*)inst)[0],
+              ((const uint32_t*)inst)[1],
+              ((const uint32_t*)inst)[2],
+              ((const uint32_t*)inst)[3]);
+
+       if (inst->header.predicate_control) {
+               string(file, "(");
+               control(file, "predicate inverse", pred_inv, inst->header.predicate_inverse, NULL);
+               string(file, "f0");
+               if (inst->bits2.da1.flag_subreg_nr)
+                       format(file, ".%d", inst->bits2.da1.flag_subreg_nr);
+               if (inst->header.access_mode == BRW_ALIGN_1)
+                       control(file, "predicate control align1", pred_ctrl_align1,
+                               inst->header.predicate_control, NULL);
+               else
+                       control(file, "predicate control align16", pred_ctrl_align16,
+                               inst->header.predicate_control, NULL);
+               string(file, ") ");
+       }
+
+       print_opcode(file, inst->header.opcode);
+       control(file, "saturate", saturate, inst->header.saturate, NULL);
+       control(file, "debug control", debug_ctrl, inst->header.debug_control, NULL);
+
+       if (inst->header.opcode == BRW_OPCODE_MATH) {
+               string(file, " ");
+               control(file, "function", math_function,
+                       inst->header.destreg__conditionalmod, NULL);
+       } else if (inst->header.opcode != BRW_OPCODE_SEND &&
+                  inst->header.opcode != BRW_OPCODE_SENDC)
+               control(file, "conditional modifier", conditional_modifier,
+                       inst->header.destreg__conditionalmod, NULL);
+
+       if (inst->header.opcode != BRW_OPCODE_NOP) {
+               string(file, "(");
+               control(file, "execution size", exec_size, inst->header.execution_size, NULL);
+               string(file, ")");
+       }
+
+       if (inst->header.opcode == BRW_OPCODE_SEND && gen < 60)
+               format(file, " %d", inst->header.destreg__conditionalmod);
+
+       if (opcode[inst->header.opcode].ndst > 0) {
+               pad(file, 16);
+               dest(file, inst);
+       } else if (gen >= 60 && (inst->header.opcode == BRW_OPCODE_IF ||
+                                inst->header.opcode == BRW_OPCODE_ELSE ||
+                                inst->header.opcode == BRW_OPCODE_ENDIF ||
+                                inst->header.opcode == BRW_OPCODE_WHILE)) {
+               format(file, " %d", inst->bits1.branch_gen6.jump_count);
+       }
+
+       if (opcode[inst->header.opcode].nsrc > 0) {
+               pad(file, 32);
+               src0(file, inst);
+       }
+       if (opcode[inst->header.opcode].nsrc > 1) {
+               pad(file, 48);
+               src1(file, inst);
+       }
+
+       if (inst->header.opcode == BRW_OPCODE_SEND ||
+           inst->header.opcode == BRW_OPCODE_SENDC) {
+               enum brw_message_target target;
+
+               if (gen >= 60)
+                       target = inst->header.destreg__conditionalmod;
+               else if (gen >= 50)
+                       target = inst->bits2.send_gen5.sfid;
+               else
+                       target = inst->bits3.generic.msg_target;
+
+               newline (file);
+               pad (file, 16);
+               space = 0;
+
+               if (gen >= 60) {
+                       control (file, "target function", target_function_gen6,
+                                target, &space);
+               } else {
+                       control (file, "target function", target_function,
+                                target, &space);
+               }
+
+               switch (target) {
+               case BRW_SFID_MATH:
+                       control (file, "math function", math_function,
+                                inst->bits3.math.function, &space);
+                       control (file, "math saturate", math_saturate,
+                                inst->bits3.math.saturate, &space);
+                       control (file, "math signed", math_signed,
+                                inst->bits3.math.int_type, &space);
+                       control (file, "math scalar", math_scalar,
+                                inst->bits3.math.data_type, &space);
+                       control (file, "math precision", math_precision,
+                                inst->bits3.math.precision, &space);
+                       break;
+               case BRW_SFID_SAMPLER:
+                       if (gen >= 70) {
+                               format (file, " (%d, %d, %d, %d)",
+                                       inst->bits3.sampler_gen7.binding_table_index,
+                                       inst->bits3.sampler_gen7.sampler,
+                                       inst->bits3.sampler_gen7.msg_type,
+                                       inst->bits3.sampler_gen7.simd_mode);
+                       } else if (gen >= 50) {
+                               format (file, " (%d, %d, %d, %d)",
+                                       inst->bits3.sampler_gen5.binding_table_index,
+                                       inst->bits3.sampler_gen5.sampler,
+                                       inst->bits3.sampler_gen5.msg_type,
+                                       inst->bits3.sampler_gen5.simd_mode);
+                       } else if (gen >= 45) {
+                               format (file, " (%d, %d)",
+                                       inst->bits3.sampler_g4x.binding_table_index,
+                                       inst->bits3.sampler_g4x.sampler);
+                       } else {
+                               format (file, " (%d, %d, ",
+                                       inst->bits3.sampler.binding_table_index,
+                                       inst->bits3.sampler.sampler);
+                               control (file, "sampler target format",
+                                        sampler_target_format,
+                                        inst->bits3.sampler.return_format, NULL);
+                               string (file, ")");
+                       }
+                       break;
+               case BRW_SFID_DATAPORT_READ:
+                       if (gen >= 60) {
+                               format (file, " (%d, %d, %d, %d)",
+                                       inst->bits3.gen6_dp.binding_table_index,
+                                       inst->bits3.gen6_dp.msg_control,
+                                       inst->bits3.gen6_dp.msg_type,
+                                       inst->bits3.gen6_dp.send_commit_msg);
+                       } else if (gen >= 45) {
+                               format (file, " (%d, %d, %d)",
+                                       inst->bits3.dp_read_gen5.binding_table_index,
+                                       inst->bits3.dp_read_gen5.msg_control,
+                                       inst->bits3.dp_read_gen5.msg_type);
+                       } else {
+                               format (file, " (%d, %d, %d)",
+                                       inst->bits3.dp_read.binding_table_index,
+                                       inst->bits3.dp_read.msg_control,
+                                       inst->bits3.dp_read.msg_type);
+                       }
+                       break;
+
+               case BRW_SFID_DATAPORT_WRITE:
+                       if (gen >= 70) {
+                               format (file, " (");
+
+                               control (file, "DP rc message type",
+                                        dp_rc_msg_type_gen6,
+                                        inst->bits3.gen7_dp.msg_type, &space);
+
+                               format (file, ", %d, %d, %d)",
+                                       inst->bits3.gen7_dp.binding_table_index,
+                                       inst->bits3.gen7_dp.msg_control,
+                                       inst->bits3.gen7_dp.msg_type);
+                       } else if (gen >= 60) {
+                               format (file, " (");
+
+                               control (file, "DP rc message type",
+                                        dp_rc_msg_type_gen6,
+                                        inst->bits3.gen6_dp.msg_type, &space);
+
+                               format (file, ", %d, %d, %d, %d)",
+                                       inst->bits3.gen6_dp.binding_table_index,
+                                       inst->bits3.gen6_dp.msg_control,
+                                       inst->bits3.gen6_dp.msg_type,
+                                       inst->bits3.gen6_dp.send_commit_msg);
+                       } else {
+                               format (file, " (%d, %d, %d, %d)",
+                                       inst->bits3.dp_write.binding_table_index,
+                                       (inst->bits3.dp_write.last_render_target << 3) |
+                                       inst->bits3.dp_write.msg_control,
+                                       inst->bits3.dp_write.msg_type,
+                                       inst->bits3.dp_write.send_commit_msg);
+                       }
+                       break;
+
+               case BRW_SFID_URB:
+                       if (gen >= 50) {
+                               format (file, " %d", inst->bits3.urb_gen5.offset);
+                       } else {
+                               format (file, " %d", inst->bits3.urb.offset);
+                       }
+
+                       space = 1;
+                       if (gen >= 50) {
+                               control (file, "urb opcode", urb_opcode,
+                                        inst->bits3.urb_gen5.opcode, &space);
+                       }
+                       control (file, "urb swizzle", urb_swizzle,
+                                inst->bits3.urb.swizzle_control, &space);
+                       control (file, "urb allocate", urb_allocate,
+                                inst->bits3.urb.allocate, &space);
+                       control (file, "urb used", urb_used,
+                                inst->bits3.urb.used, &space);
+                       control (file, "urb complete", urb_complete,
+                                inst->bits3.urb.complete, &space);
+                       break;
+               case BRW_SFID_THREAD_SPAWNER:
+                       break;
+               case GEN7_SFID_DATAPORT_DATA_CACHE:
+                       format (file, " (%d, %d, %d)",
+                               inst->bits3.gen7_dp.binding_table_index,
+                               inst->bits3.gen7_dp.msg_control,
+                               inst->bits3.gen7_dp.msg_type);
+                       break;
+
+
+               default:
+                       format (file, "unsupported target %d", target);
+                       break;
+               }
+               if (space)
+                       string (file, " ");
+               if (gen >= 50) {
+                       format (file, "mlen %d",
+                               inst->bits3.generic_gen5.msg_length);
+                       format (file, " rlen %d",
+                               inst->bits3.generic_gen5.response_length);
+               } else {
+                       format (file, "mlen %d",
+                               inst->bits3.generic.msg_length);
+                       format (file, " rlen %d",
+                               inst->bits3.generic.response_length);
+               }
+       }
+       pad(file, 64);
+       if (inst->header.opcode != BRW_OPCODE_NOP) {
+               string(file, "{");
+               space = 1;
+               control(file, "access mode", access_mode, inst->header.access_mode, &space);
+               if (gen >= 60)
+                       control(file, "write enable control", wectrl, inst->header.mask_control, &space);
+               else
+                       control(file, "mask control", mask_ctrl, inst->header.mask_control, &space);
+               control(file, "dependency control", dep_ctrl, inst->header.dependency_control, &space);
+
+               if (gen >= 60)
+                       qtr_ctrl(file, inst);
+               else {
+                       if (inst->header.compression_control == BRW_COMPRESSION_COMPRESSED &&
+                           opcode[inst->header.opcode].ndst > 0 &&
+                           inst->bits1.da1.dest_reg_file == BRW_MESSAGE_REGISTER_FILE &&
+                           inst->bits1.da1.dest_reg_nr & (1 << 7)) {
+                               format(file, " compr4");
+                       } else {
+                               control(file, "compression control", compr_ctrl,
+                                       inst->header.compression_control, &space);
+                       }
+               }
+
+               control(file, "thread control", thread_ctrl, inst->header.thread_control, &space);
+               if (gen >= 60)
+                       control(file, "acc write control", accwr, inst->header.acc_wr_control, &space);
+               if (inst->header.opcode == BRW_OPCODE_SEND ||
+                   inst->header.opcode == BRW_OPCODE_SENDC)
+                       control(file, "end of thread", end_of_thread,
+                               inst->bits3.generic.end_of_thread, &space);
+               if (space)
+                       string(file, " ");
+               string(file, "}");
+       }
+       string(file, ";");
+       newline(file);
+}
diff --git a/src/sna/brw/brw_eu.c b/src/sna/brw/brw_eu.c
new file mode 100644 (file)
index 0000000..7c32ea1
--- /dev/null
@@ -0,0 +1,150 @@
+/*
+ Copyright (C) Intel Corp.  2006.  All Rights Reserved.
+ Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
+ develop this 3D driver.
+
+ 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 COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS 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.
+
+ **********************************************************************/
+ /*
+  * Authors:
+  *   Keith Whitwell <keith@tungstengraphics.com>
+  */
+
+#include "brw_eu.h"
+
+#include <string.h>
+#include <stdlib.h>
+
+/* Returns the corresponding conditional mod for swapping src0 and
+ * src1 in e.g. CMP.
+ */
+uint32_t
+brw_swap_cmod(uint32_t cmod)
+{
+       switch (cmod) {
+       case BRW_CONDITIONAL_Z:
+       case BRW_CONDITIONAL_NZ:
+               return cmod;
+       case BRW_CONDITIONAL_G:
+               return BRW_CONDITIONAL_LE;
+       case BRW_CONDITIONAL_GE:
+               return BRW_CONDITIONAL_L;
+       case BRW_CONDITIONAL_L:
+               return BRW_CONDITIONAL_GE;
+       case BRW_CONDITIONAL_LE:
+               return BRW_CONDITIONAL_G;
+       default:
+               return ~0;
+       }
+}
+
+/* How does predicate control work when execution_size != 8?  Do I
+ * need to test/set for 0xffff when execution_size is 16?
+ */
+void brw_set_predicate_control_flag_value( struct brw_compile *p, unsigned value )
+{
+       p->current->header.predicate_control = BRW_PREDICATE_NONE;
+
+       if (value != 0xff) {
+               if (value != p->flag_value) {
+                       brw_MOV(p, brw_flag_reg(), brw_imm_uw(value));
+                       p->flag_value = value;
+               }
+
+               p->current->header.predicate_control = BRW_PREDICATE_NORMAL;
+       }
+}
+
+void brw_set_compression_control(struct brw_compile *p,
+                                enum brw_compression compression_control)
+{
+       p->compressed = (compression_control == BRW_COMPRESSION_COMPRESSED);
+
+       if (p->gen >= 60) {
+               /* Since we don't use the 32-wide support in gen6, we translate
+                * the pre-gen6 compression control here.
+                */
+               switch (compression_control) {
+               case BRW_COMPRESSION_NONE:
+                       /* This is the "use the first set of bits of dmask/vmask/arf
+                        * according to execsize" option.
+                        */
+                       p->current->header.compression_control = GEN6_COMPRESSION_1Q;
+                       break;
+               case BRW_COMPRESSION_2NDHALF:
+                       /* For 8-wide, this is "use the second set of 8 bits." */
+                       p->current->header.compression_control = GEN6_COMPRESSION_2Q;
+                       break;
+               case BRW_COMPRESSION_COMPRESSED:
+                       /* For 16-wide instruction compression, use the first set of 16 bits
+                        * since we don't do 32-wide dispatch.
+                        */
+                       p->current->header.compression_control = GEN6_COMPRESSION_1H;
+                       break;
+               default:
+                       assert(!"not reached");
+                       p->current->header.compression_control = GEN6_COMPRESSION_1H;
+                       break;
+               }
+       } else {
+               p->current->header.compression_control = compression_control;
+       }
+}
+
+void brw_push_insn_state( struct brw_compile *p )
+{
+       assert(p->current != &p->stack[BRW_EU_MAX_INSN_STACK-1]);
+       memcpy(p->current+1, p->current, sizeof(struct brw_instruction));
+       p->compressed_stack[p->current - p->stack] = p->compressed;
+       p->current++;
+}
+
+void brw_pop_insn_state( struct brw_compile *p )
+{
+       assert(p->current != p->stack);
+       p->current--;
+       p->compressed = p->compressed_stack[p->current - p->stack];
+}
+
+void brw_compile_init(struct brw_compile *p, int gen, void *store)
+{
+       assert(gen);
+
+       p->gen = gen;
+       p->store = store;
+
+       p->nr_insn = 0;
+       p->current = p->stack;
+       p->compressed = false;
+       memset(p->current, 0, sizeof(p->current[0]));
+
+       /* Some defaults?
+       */
+       brw_set_mask_control(p, BRW_MASK_ENABLE); /* what does this do? */
+       brw_set_saturate(p, 0);
+       brw_set_compression_control(p, BRW_COMPRESSION_NONE);
+       brw_set_predicate_control_flag_value(p, 0xff);
+
+       p->if_stack_depth = 0;
+       p->if_stack_array_size = 0;
+       p->if_stack = NULL;
+}
diff --git a/src/sna/brw/brw_eu.h b/src/sna/brw/brw_eu.h
new file mode 100644 (file)
index 0000000..65e66d5
--- /dev/null
@@ -0,0 +1,2266 @@
+/*
+   Copyright (C) Intel Corp.  2006.  All Rights Reserved.
+   Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
+   develop this 3D driver.
+
+   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 COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS 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.
+
+ **********************************************************************/
+/*
+ * Authors:
+ *   Keith Whitwell <keith@tungstengraphics.com>
+ */
+
+
+#ifndef BRW_EU_H
+#define BRW_EU_H
+
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <assert.h>
+
+#define BRW_SWIZZLE4(a,b,c,d) (((a)<<0) | ((b)<<2) | ((c)<<4) | ((d)<<6))
+#define BRW_GET_SWZ(swz, idx) (((swz) >> ((idx)*2)) & 0x3)
+
+#define BRW_SWIZZLE_NOOP      BRW_SWIZZLE4(0,1,2,3)
+#define BRW_SWIZZLE_XYZW      BRW_SWIZZLE4(0,1,2,3)
+#define BRW_SWIZZLE_XXXX      BRW_SWIZZLE4(0,0,0,0)
+#define BRW_SWIZZLE_YYYY      BRW_SWIZZLE4(1,1,1,1)
+#define BRW_SWIZZLE_ZZZZ      BRW_SWIZZLE4(2,2,2,2)
+#define BRW_SWIZZLE_WWWW      BRW_SWIZZLE4(3,3,3,3)
+#define BRW_SWIZZLE_XYXY      BRW_SWIZZLE4(0,1,0,1)
+
+#define WRITEMASK_X 0x1
+#define WRITEMASK_Y 0x2
+#define WRITEMASK_Z 0x4
+#define WRITEMASK_W 0x8
+
+#define WRITEMASK_XY (WRITEMASK_X | WRITEMASK_Y)
+#define WRITEMASK_XYZ (WRITEMASK_X | WRITEMASK_Y | WRITEMASK_Z)
+#define WRITEMASK_XYZW (WRITEMASK_X | WRITEMASK_Y | WRITEMASK_Z | WRITEMASK_W)
+
+/** Number of general purpose registers (VS, WM, etc) */
+#define BRW_MAX_GRF 128
+
+/** Number of message register file registers */
+#define BRW_MAX_MRF 16
+
+
+#define BRW_ALIGN_1   0
+#define BRW_ALIGN_16  1
+
+#define BRW_ADDRESS_DIRECT                        0
+#define BRW_ADDRESS_REGISTER_INDIRECT_REGISTER    1
+
+#define BRW_CHANNEL_X     0
+#define BRW_CHANNEL_Y     1
+#define BRW_CHANNEL_Z     2
+#define BRW_CHANNEL_W     3
+
+enum brw_compression {
+       BRW_COMPRESSION_NONE,
+       BRW_COMPRESSION_2NDHALF,
+       BRW_COMPRESSION_COMPRESSED,
+};
+
+#define GEN6_COMPRESSION_1Q            0
+#define GEN6_COMPRESSION_2Q            1
+#define GEN6_COMPRESSION_3Q            2
+#define GEN6_COMPRESSION_4Q            3
+#define GEN6_COMPRESSION_1H            0
+#define GEN6_COMPRESSION_2H            2
+
+#define BRW_CONDITIONAL_NONE  0
+#define BRW_CONDITIONAL_Z     1
+#define BRW_CONDITIONAL_NZ    2
+#define BRW_CONDITIONAL_EQ    1        /* Z */
+#define BRW_CONDITIONAL_NEQ   2        /* NZ */
+#define BRW_CONDITIONAL_G     3
+#define BRW_CONDITIONAL_GE    4
+#define BRW_CONDITIONAL_L     5
+#define BRW_CONDITIONAL_LE    6
+#define BRW_CONDITIONAL_R     7
+#define BRW_CONDITIONAL_O     8
+#define BRW_CONDITIONAL_U     9
+
+#define BRW_DEBUG_NONE        0
+#define BRW_DEBUG_BREAKPOINT  1
+
+#define BRW_DEPENDENCY_NORMAL         0
+#define BRW_DEPENDENCY_NOTCLEARED     1
+#define BRW_DEPENDENCY_NOTCHECKED     2
+#define BRW_DEPENDENCY_DISABLE        3
+
+#define BRW_EXECUTE_1     0
+#define BRW_EXECUTE_2     1
+#define BRW_EXECUTE_4     2
+#define BRW_EXECUTE_8     3
+#define BRW_EXECUTE_16    4
+#define BRW_EXECUTE_32    5
+
+#define BRW_HORIZONTAL_STRIDE_0   0
+#define BRW_HORIZONTAL_STRIDE_1   1
+#define BRW_HORIZONTAL_STRIDE_2   2
+#define BRW_HORIZONTAL_STRIDE_4   3
+
+#define BRW_INSTRUCTION_NORMAL    0
+#define BRW_INSTRUCTION_SATURATE  1
+
+#define BRW_MASK_ENABLE   0
+#define BRW_MASK_DISABLE  1
+
+/** @{
+ *
+ * Gen6 has replaced "mask enable/disable" with WECtrl, which is
+ * effectively the same but much simpler to think about.  Now, there
+ * are two contributors ANDed together to whether channels are
+ * executed: The predication on the instruction, and the channel write
+ * enable.
+ */
+/**
+ * This is the default value.  It means that a channel's write enable is set
+ * if the per-channel IP is pointing at this instruction.
+ */
+#define BRW_WE_NORMAL          0
+/**
+ * This is used like BRW_MASK_DISABLE, and causes all channels to have
+ * their write enable set.  Note that predication still contributes to
+ * whether the channel actually gets written.
+ */
+#define BRW_WE_ALL             1
+/** @} */
+
+enum opcode {
+       /* These are the actual hardware opcodes. */
+       BRW_OPCODE_MOV =        1,
+       BRW_OPCODE_SEL =        2,
+       BRW_OPCODE_NOT =        4,
+       BRW_OPCODE_AND =        5,
+       BRW_OPCODE_OR = 6,
+       BRW_OPCODE_XOR =        7,
+       BRW_OPCODE_SHR =        8,
+       BRW_OPCODE_SHL =        9,
+       BRW_OPCODE_RSR =        10,
+       BRW_OPCODE_RSL =        11,
+       BRW_OPCODE_ASR =        12,
+       BRW_OPCODE_CMP =        16,
+       BRW_OPCODE_CMPN =       17,
+       BRW_OPCODE_JMPI =       32,
+       BRW_OPCODE_IF = 34,
+       BRW_OPCODE_IFF =        35,
+       BRW_OPCODE_ELSE =       36,
+       BRW_OPCODE_ENDIF =      37,
+       BRW_OPCODE_DO = 38,
+       BRW_OPCODE_WHILE =      39,
+       BRW_OPCODE_BREAK =      40,
+       BRW_OPCODE_CONTINUE = 41,
+       BRW_OPCODE_HALT =       42,
+       BRW_OPCODE_MSAVE =      44,
+       BRW_OPCODE_MRESTORE = 45,
+       BRW_OPCODE_PUSH =       46,
+       BRW_OPCODE_POP =        47,
+       BRW_OPCODE_WAIT =       48,
+       BRW_OPCODE_SEND =       49,
+       BRW_OPCODE_SENDC =      50,
+       BRW_OPCODE_MATH =       56,
+       BRW_OPCODE_ADD =        64,
+       BRW_OPCODE_MUL =        65,
+       BRW_OPCODE_AVG =        66,
+       BRW_OPCODE_FRC =        67,
+       BRW_OPCODE_RNDU =       68,
+       BRW_OPCODE_RNDD =       69,
+       BRW_OPCODE_RNDE =       70,
+       BRW_OPCODE_RNDZ =       71,
+       BRW_OPCODE_MAC =        72,
+       BRW_OPCODE_MACH =       73,
+       BRW_OPCODE_LZD =        74,
+       BRW_OPCODE_SAD2 =       80,
+       BRW_OPCODE_SADA2 =      81,
+       BRW_OPCODE_DP4 =        84,
+       BRW_OPCODE_DPH =        85,
+       BRW_OPCODE_DP3 =        86,
+       BRW_OPCODE_DP2 =        87,
+       BRW_OPCODE_DPA2 =       88,
+       BRW_OPCODE_LINE =       89,
+       BRW_OPCODE_PLN =        90,
+       BRW_OPCODE_NOP =        126,
+
+       /* These are compiler backend opcodes that get translated into other
+        * instructions.
+        */
+       FS_OPCODE_FB_WRITE = 128,
+       SHADER_OPCODE_RCP,
+       SHADER_OPCODE_RSQ,
+       SHADER_OPCODE_SQRT,
+       SHADER_OPCODE_EXP2,
+       SHADER_OPCODE_LOG2,
+       SHADER_OPCODE_POW,
+       SHADER_OPCODE_SIN,
+       SHADER_OPCODE_COS,
+       FS_OPCODE_DDX,
+       FS_OPCODE_DDY,
+       FS_OPCODE_PIXEL_X,
+       FS_OPCODE_PIXEL_Y,
+       FS_OPCODE_CINTERP,
+       FS_OPCODE_LINTERP,
+       FS_OPCODE_TEX,
+       FS_OPCODE_TXB,
+       FS_OPCODE_TXD,
+       FS_OPCODE_TXF,
+       FS_OPCODE_TXL,
+       FS_OPCODE_TXS,
+       FS_OPCODE_DISCARD,
+       FS_OPCODE_SPILL,
+       FS_OPCODE_UNSPILL,
+       FS_OPCODE_PULL_CONSTANT_LOAD,
+
+       VS_OPCODE_URB_WRITE,
+       VS_OPCODE_SCRATCH_READ,
+       VS_OPCODE_SCRATCH_WRITE,
+       VS_OPCODE_PULL_CONSTANT_LOAD,
+};
+
+#define BRW_PREDICATE_NONE             0
+#define BRW_PREDICATE_NORMAL           1
+#define BRW_PREDICATE_ALIGN1_ANYV             2
+#define BRW_PREDICATE_ALIGN1_ALLV             3
+#define BRW_PREDICATE_ALIGN1_ANY2H            4
+#define BRW_PREDICATE_ALIGN1_ALL2H            5
+#define BRW_PREDICATE_ALIGN1_ANY4H            6
+#define BRW_PREDICATE_ALIGN1_ALL4H            7
+#define BRW_PREDICATE_ALIGN1_ANY8H            8
+#define BRW_PREDICATE_ALIGN1_ALL8H            9
+#define BRW_PREDICATE_ALIGN1_ANY16H           10
+#define BRW_PREDICATE_ALIGN1_ALL16H           11
+#define BRW_PREDICATE_ALIGN16_REPLICATE_X     2
+#define BRW_PREDICATE_ALIGN16_REPLICATE_Y     3
+#define BRW_PREDICATE_ALIGN16_REPLICATE_Z     4
+#define BRW_PREDICATE_ALIGN16_REPLICATE_W     5
+#define BRW_PREDICATE_ALIGN16_ANY4H           6
+#define BRW_PREDICATE_ALIGN16_ALL4H           7
+
+#define BRW_ARCHITECTURE_REGISTER_FILE    0
+#define BRW_GENERAL_REGISTER_FILE         1
+#define BRW_MESSAGE_REGISTER_FILE         2
+#define BRW_IMMEDIATE_VALUE               3
+
+#define BRW_REGISTER_TYPE_UD  0
+#define BRW_REGISTER_TYPE_D   1
+#define BRW_REGISTER_TYPE_UW  2
+#define BRW_REGISTER_TYPE_W   3
+#define BRW_REGISTER_TYPE_UB  4
+#define BRW_REGISTER_TYPE_B   5
+#define BRW_REGISTER_TYPE_VF  5        /* packed float vector, immediates only? */
+#define BRW_REGISTER_TYPE_HF  6
+#define BRW_REGISTER_TYPE_V   6        /* packed int vector, immediates only, uword dest only */
+#define BRW_REGISTER_TYPE_F   7
+
+#define BRW_ARF_NULL                  0x00
+#define BRW_ARF_ADDRESS               0x10
+#define BRW_ARF_ACCUMULATOR           0x20
+#define BRW_ARF_FLAG                  0x30
+#define BRW_ARF_MASK                  0x40
+#define BRW_ARF_MASK_STACK            0x50
+#define BRW_ARF_MASK_STACK_DEPTH      0x60
+#define BRW_ARF_STATE                 0x70
+#define BRW_ARF_CONTROL               0x80
+#define BRW_ARF_NOTIFICATION_COUNT    0x90
+#define BRW_ARF_IP                    0xA0
+
+#define BRW_MRF_COMPR4                 (1 << 7)
+
+#define BRW_AMASK   0
+#define BRW_IMASK   1
+#define BRW_LMASK   2
+#define BRW_CMASK   3
+
+#define BRW_THREAD_NORMAL     0
+#define BRW_THREAD_ATOMIC     1
+#define BRW_THREAD_SWITCH     2
+
+#define BRW_VERTICAL_STRIDE_0                 0
+#define BRW_VERTICAL_STRIDE_1                 1
+#define BRW_VERTICAL_STRIDE_2                 2
+#define BRW_VERTICAL_STRIDE_4                 3
+#define BRW_VERTICAL_STRIDE_8                 4
+#define BRW_VERTICAL_STRIDE_16                5
+#define BRW_VERTICAL_STRIDE_32                6
+#define BRW_VERTICAL_STRIDE_64                7
+#define BRW_VERTICAL_STRIDE_128               8
+#define BRW_VERTICAL_STRIDE_256               9
+#define BRW_VERTICAL_STRIDE_ONE_DIMENSIONAL   0xF
+
+#define BRW_WIDTH_1       0
+#define BRW_WIDTH_2       1
+#define BRW_WIDTH_4       2
+#define BRW_WIDTH_8       3
+#define BRW_WIDTH_16      4
+
+#define BRW_STATELESS_BUFFER_BOUNDARY_1K      0
+#define BRW_STATELESS_BUFFER_BOUNDARY_2K      1
+#define BRW_STATELESS_BUFFER_BOUNDARY_4K      2
+#define BRW_STATELESS_BUFFER_BOUNDARY_8K      3
+#define BRW_STATELESS_BUFFER_BOUNDARY_16K     4
+#define BRW_STATELESS_BUFFER_BOUNDARY_32K     5
+#define BRW_STATELESS_BUFFER_BOUNDARY_64K     6
+#define BRW_STATELESS_BUFFER_BOUNDARY_128K    7
+#define BRW_STATELESS_BUFFER_BOUNDARY_256K    8
+#define BRW_STATELESS_BUFFER_BOUNDARY_512K    9
+#define BRW_STATELESS_BUFFER_BOUNDARY_1M      10
+#define BRW_STATELESS_BUFFER_BOUNDARY_2M      11
+
+#define BRW_POLYGON_FACING_FRONT      0
+#define BRW_POLYGON_FACING_BACK       1
+
+#define BRW_MESSAGE_TARGET_NULL               0
+#define BRW_MESSAGE_TARGET_MATH               1 /* reserved on GEN6 */
+#define BRW_MESSAGE_TARGET_SAMPLER            2
+#define BRW_MESSAGE_TARGET_GATEWAY            3
+#define BRW_MESSAGE_TARGET_DATAPORT_READ      4
+#define BRW_MESSAGE_TARGET_DATAPORT_WRITE     5
+#define BRW_MESSAGE_TARGET_URB                6
+#define BRW_MESSAGE_TARGET_THREAD_SPAWNER     7
+
+#define GEN6_MESSAGE_TARGET_DP_SAMPLER_CACHE  4
+#define GEN6_MESSAGE_TARGET_DP_RENDER_CACHE   5
+#define GEN6_MESSAGE_TARGET_DP_CONST_CACHE    9
+
+#define BRW_SAMPLER_RETURN_FORMAT_FLOAT32     0
+#define BRW_SAMPLER_RETURN_FORMAT_UINT32      2
+#define BRW_SAMPLER_RETURN_FORMAT_SINT32      3
+
+#define BRW_SAMPLER_MESSAGE_SAMPLE                   0
+#define BRW_SAMPLER_MESSAGE_SIMD8_SAMPLE              0
+#define BRW_SAMPLER_MESSAGE_SIMD16_SAMPLE             0
+#define BRW_SAMPLER_MESSAGE_SIMD16_SAMPLE_BIAS        0
+#define BRW_SAMPLER_MESSAGE_SIMD8_KILLPIX             1
+#define BRW_SAMPLER_MESSAGE_SIMD4X2_SAMPLE_LOD        1
+#define BRW_SAMPLER_MESSAGE_SIMD16_SAMPLE_LOD         1
+#define BRW_SAMPLER_MESSAGE_SIMD4X2_SAMPLE_GRADIENTS  2
+#define BRW_SAMPLER_MESSAGE_SIMD8_SAMPLE_GRADIENTS    2
+#define BRW_SAMPLER_MESSAGE_SIMD4X2_SAMPLE_COMPARE    0
+#define BRW_SAMPLER_MESSAGE_SIMD16_SAMPLE_COMPARE     2
+#define BRW_SAMPLER_MESSAGE_SIMD8_SAMPLE_BIAS_COMPARE 0
+#define BRW_SAMPLER_MESSAGE_SIMD8_SAMPLE_LOD_COMPARE  1
+#define BRW_SAMPLER_MESSAGE_SIMD4X2_RESINFO           2
+#define BRW_SAMPLER_MESSAGE_SIMD16_RESINFO            2
+#define BRW_SAMPLER_MESSAGE_SIMD4X2_LD                3
+#define BRW_SAMPLER_MESSAGE_SIMD8_LD                  3
+#define BRW_SAMPLER_MESSAGE_SIMD16_LD                 3
+
+#define GEN5_SAMPLER_MESSAGE_SAMPLE              0
+#define GEN5_SAMPLER_MESSAGE_SAMPLE_BIAS         1
+#define GEN5_SAMPLER_MESSAGE_SAMPLE_LOD          2
+#define GEN5_SAMPLER_MESSAGE_SAMPLE_COMPARE      3
+#define GEN5_SAMPLER_MESSAGE_SAMPLE_DERIVS       4
+#define GEN5_SAMPLER_MESSAGE_SAMPLE_BIAS_COMPARE 5
+#define GEN5_SAMPLER_MESSAGE_SAMPLE_LOD_COMPARE  6
+#define GEN5_SAMPLER_MESSAGE_SAMPLE_LD           7
+#define GEN5_SAMPLER_MESSAGE_SAMPLE_RESINFO      10
+
+/* for GEN5 only */
+#define BRW_SAMPLER_SIMD_MODE_SIMD4X2                   0
+#define BRW_SAMPLER_SIMD_MODE_SIMD8                     1
+#define BRW_SAMPLER_SIMD_MODE_SIMD16                    2
+#define BRW_SAMPLER_SIMD_MODE_SIMD32_64                 3
+
+#define BRW_DATAPORT_OWORD_BLOCK_1_OWORDLOW   0
+#define BRW_DATAPORT_OWORD_BLOCK_1_OWORDHIGH  1
+#define BRW_DATAPORT_OWORD_BLOCK_2_OWORDS     2
+#define BRW_DATAPORT_OWORD_BLOCK_4_OWORDS     3
+#define BRW_DATAPORT_OWORD_BLOCK_8_OWORDS     4
+
+#define BRW_DATAPORT_OWORD_DUAL_BLOCK_1OWORD     0
+#define BRW_DATAPORT_OWORD_DUAL_BLOCK_4OWORDS    2
+
+#define BRW_DATAPORT_DWORD_SCATTERED_BLOCK_8DWORDS   2
+#define BRW_DATAPORT_DWORD_SCATTERED_BLOCK_16DWORDS  3
+
+/* This one stays the same across generations. */
+#define BRW_DATAPORT_READ_MESSAGE_OWORD_BLOCK_READ          0
+/* GEN4 */
+#define BRW_DATAPORT_READ_MESSAGE_OWORD_DUAL_BLOCK_READ     1
+#define BRW_DATAPORT_READ_MESSAGE_MEDIA_BLOCK_READ          2
+#define BRW_DATAPORT_READ_MESSAGE_DWORD_SCATTERED_READ      3
+/* G45, GEN5 */
+#define G45_DATAPORT_READ_MESSAGE_RENDER_UNORM_READ        1
+#define G45_DATAPORT_READ_MESSAGE_OWORD_DUAL_BLOCK_READ     2
+#define G45_DATAPORT_READ_MESSAGE_AVC_LOOP_FILTER_READ     3
+#define G45_DATAPORT_READ_MESSAGE_MEDIA_BLOCK_READ          4
+#define G45_DATAPORT_READ_MESSAGE_DWORD_SCATTERED_READ      6
+/* GEN6 */
+#define GEN6_DATAPORT_READ_MESSAGE_RENDER_UNORM_READ       1
+#define GEN6_DATAPORT_READ_MESSAGE_OWORD_DUAL_BLOCK_READ     2
+#define GEN6_DATAPORT_READ_MESSAGE_MEDIA_BLOCK_READ          4
+#define GEN6_DATAPORT_READ_MESSAGE_OWORD_UNALIGN_BLOCK_READ  5
+#define GEN6_DATAPORT_READ_MESSAGE_DWORD_SCATTERED_READ      6
+
+#define BRW_DATAPORT_READ_TARGET_DATA_CACHE      0
+#define BRW_DATAPORT_READ_TARGET_RENDER_CACHE    1
+#define BRW_DATAPORT_READ_TARGET_SAMPLER_CACHE   2
+
+#define BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD16_SINGLE_SOURCE                0
+#define BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD16_SINGLE_SOURCE_REPLICATED     1
+#define BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD8_DUAL_SOURCE_SUBSPAN01         2
+#define BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD8_DUAL_SOURCE_SUBSPAN23         3
+#define BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD8_SINGLE_SOURCE_SUBSPAN01       4
+
+/**
+ * Message target: Shared Function ID for where to SEND a message.
+ *
+ * These are enumerated in the ISA reference under "send - Send Message".
+ * In particular, see the following tables:
+ * - G45 PRM, Volume 4, Table 14-15 "Message Descriptor Definition"
+ * - Sandybridge PRM, Volume 4 Part 2, Table 8-16 "Extended Message Descriptor"
+ * - BSpec, Volume 1a (GPU Overview) / Graphics Processing Engine (GPE) /
+ *   Overview / GPE Function IDs
+ */
+enum brw_message_target {
+   BRW_SFID_NULL                     = 0,
+   BRW_SFID_MATH                     = 1, /* Only valid on Gen4-5 */
+   BRW_SFID_SAMPLER                  = 2,
+   BRW_SFID_MESSAGE_GATEWAY          = 3,
+   BRW_SFID_DATAPORT_READ            = 4,
+   BRW_SFID_DATAPORT_WRITE           = 5,
+   BRW_SFID_URB                      = 6,
+   BRW_SFID_THREAD_SPAWNER           = 7,
+
+   GEN6_SFID_DATAPORT_SAMPLER_CACHE  = 4,
+   GEN6_SFID_DATAPORT_RENDER_CACHE   = 5,
+   GEN6_SFID_DATAPORT_CONSTANT_CACHE = 9,
+
+   GEN7_SFID_DATAPORT_DATA_CACHE     = 10,
+};
+
+#define GEN7_MESSAGE_TARGET_DP_DATA_CACHE     10
+
+#define BRW_DATAPORT_WRITE_MESSAGE_OWORD_BLOCK_WRITE                0
+#define BRW_DATAPORT_WRITE_MESSAGE_OWORD_DUAL_BLOCK_WRITE           1
+#define BRW_DATAPORT_WRITE_MESSAGE_MEDIA_BLOCK_WRITE                2
+#define BRW_DATAPORT_WRITE_MESSAGE_DWORD_SCATTERED_WRITE            3
+#define BRW_DATAPORT_WRITE_MESSAGE_RENDER_TARGET_WRITE              4
+#define BRW_DATAPORT_WRITE_MESSAGE_STREAMED_VERTEX_BUFFER_WRITE     5
+#define BRW_DATAPORT_WRITE_MESSAGE_FLUSH_RENDER_CACHE               7
+
+/* GEN6 */
+#define GEN6_DATAPORT_WRITE_MESSAGE_DWORD_ATOMIC_WRITE              7
+#define GEN6_DATAPORT_WRITE_MESSAGE_OWORD_BLOCK_WRITE               8
+#define GEN6_DATAPORT_WRITE_MESSAGE_OWORD_DUAL_BLOCK_WRITE          9
+#define GEN6_DATAPORT_WRITE_MESSAGE_MEDIA_BLOCK_WRITE               10
+#define GEN6_DATAPORT_WRITE_MESSAGE_DWORD_SCATTERED_WRITE           11
+#define GEN6_DATAPORT_WRITE_MESSAGE_RENDER_TARGET_WRITE             12
+#define GEN6_DATAPORT_WRITE_MESSAGE_STREAMED_VB_WRITE               13
+#define GEN6_DATAPORT_WRITE_MESSAGE_RENDER_TARGET_UNORM_WRITE       14
+
+#define BRW_MATH_FUNCTION_INV                              1
+#define BRW_MATH_FUNCTION_LOG                              2
+#define BRW_MATH_FUNCTION_EXP                              3
+#define BRW_MATH_FUNCTION_SQRT                             4
+#define BRW_MATH_FUNCTION_RSQ                              5
+#define BRW_MATH_FUNCTION_SIN                              6 /* was 7 */
+#define BRW_MATH_FUNCTION_COS                              7 /* was 8 */
+#define BRW_MATH_FUNCTION_SINCOS                           8 /* was 6 */
+#define BRW_MATH_FUNCTION_TAN                              9 /* gen4 */
+#define BRW_MATH_FUNCTION_FDIV                             9 /* gen6+ */
+#define BRW_MATH_FUNCTION_POW                              10
+#define BRW_MATH_FUNCTION_INT_DIV_QUOTIENT_AND_REMAINDER   11
+#define BRW_MATH_FUNCTION_INT_DIV_QUOTIENT                 12
+#define BRW_MATH_FUNCTION_INT_DIV_REMAINDER                13
+
+#define BRW_MATH_INTEGER_UNSIGNED     0
+#define BRW_MATH_INTEGER_SIGNED       1
+
+#define BRW_MATH_PRECISION_FULL        0
+#define BRW_MATH_PRECISION_PARTIAL     1
+
+#define BRW_MATH_SATURATE_NONE         0
+#define BRW_MATH_SATURATE_SATURATE     1
+
+#define BRW_MATH_DATA_VECTOR  0
+#define BRW_MATH_DATA_SCALAR  1
+
+#define BRW_URB_OPCODE_WRITE  0
+
+#define BRW_URB_SWIZZLE_NONE          0
+#define BRW_URB_SWIZZLE_INTERLEAVE    1
+#define BRW_URB_SWIZZLE_TRANSPOSE     2
+
+#define BRW_SCRATCH_SPACE_SIZE_1K     0
+#define BRW_SCRATCH_SPACE_SIZE_2K     1
+#define BRW_SCRATCH_SPACE_SIZE_4K     2
+#define BRW_SCRATCH_SPACE_SIZE_8K     3
+#define BRW_SCRATCH_SPACE_SIZE_16K    4
+#define BRW_SCRATCH_SPACE_SIZE_32K    5
+#define BRW_SCRATCH_SPACE_SIZE_64K    6
+#define BRW_SCRATCH_SPACE_SIZE_128K   7
+#define BRW_SCRATCH_SPACE_SIZE_256K   8
+#define BRW_SCRATCH_SPACE_SIZE_512K   9
+#define BRW_SCRATCH_SPACE_SIZE_1M     10
+#define BRW_SCRATCH_SPACE_SIZE_2M     11
+
+#define REG_SIZE (8*4)
+
+struct brw_instruction {
+       struct {
+               unsigned opcode:7;
+               unsigned pad:1;
+               unsigned access_mode:1;
+               unsigned mask_control:1;
+               unsigned dependency_control:2;
+               unsigned compression_control:2; /* gen6: quater control */
+               unsigned thread_control:2;
+               unsigned predicate_control:4;
+               unsigned predicate_inverse:1;
+               unsigned execution_size:3;
+               /**
+                * Conditional Modifier for most instructions.  On Gen6+, this is also
+                * used for the SEND instruction's Message Target/SFID.
+                */
+               unsigned destreg__conditionalmod:4;
+               unsigned acc_wr_control:1;
+               unsigned cmpt_control:1;
+               unsigned debug_control:1;
+               unsigned saturate:1;
+       } header;
+
+       union {
+               struct {
+                       unsigned dest_reg_file:2;
+                       unsigned dest_reg_type:3;
+                       unsigned src0_reg_file:2;
+                       unsigned src0_reg_type:3;
+                       unsigned src1_reg_file:2;
+                       unsigned src1_reg_type:3;
+                       unsigned pad:1;
+                       unsigned dest_subreg_nr:5;
+                       unsigned dest_reg_nr:8;
+                       unsigned dest_horiz_stride:2;
+                       unsigned dest_address_mode:1;
+               } da1;
+
+               struct {
+                       unsigned dest_reg_file:2;
+                       unsigned dest_reg_type:3;
+                       unsigned src0_reg_file:2;
+                       unsigned src0_reg_type:3;
+                       unsigned src1_reg_file:2;        /* 0x00000c00 */
+                       unsigned src1_reg_type:3;        /* 0x00007000 */
+                       unsigned pad:1;
+                       int dest_indirect_offset:10;    /* offset against the deref'd address reg */
+                       unsigned dest_subreg_nr:3; /* subnr for the address reg a0.x */
+                       unsigned dest_horiz_stride:2;
+                       unsigned dest_address_mode:1;
+               } ia1;
+
+               struct {
+                       unsigned dest_reg_file:2;
+                       unsigned dest_reg_type:3;
+                       unsigned src0_reg_file:2;
+                       unsigned src0_reg_type:3;
+                       unsigned src1_reg_file:2;
+                       unsigned src1_reg_type:3;
+                       unsigned pad:1;
+                       unsigned dest_writemask:4;
+                       unsigned dest_subreg_nr:1;
+                       unsigned dest_reg_nr:8;
+                       unsigned dest_horiz_stride:2;
+                       unsigned dest_address_mode:1;
+               } da16;
+
+               struct {
+                       unsigned dest_reg_file:2;
+                       unsigned dest_reg_type:3;
+                       unsigned src0_reg_file:2;
+                       unsigned src0_reg_type:3;
+                       unsigned pad0:6;
+                       unsigned dest_writemask:4;
+                       int dest_indirect_offset:6;
+                       unsigned dest_subreg_nr:3;
+                       unsigned dest_horiz_stride:2;
+                       unsigned dest_address_mode:1;
+               } ia16;
+
+               struct {
+                       unsigned dest_reg_file:2;
+                       unsigned dest_reg_type:3;
+                       unsigned src0_reg_file:2;
+                       unsigned src0_reg_type:3;
+                       unsigned src1_reg_file:2;
+                       unsigned src1_reg_type:3;
+                       unsigned pad:1;
+
+                       int jump_count:16;
+               } branch_gen6;
+
+               struct {
+                       unsigned dest_reg_file:1;
+                       unsigned flag_subreg_num:1;
+                       unsigned pad0:2;
+                       unsigned src0_abs:1;
+                       unsigned src0_negate:1;
+                       unsigned src1_abs:1;
+                       unsigned src1_negate:1;
+                       unsigned src2_abs:1;
+                       unsigned src2_negate:1;
+                       unsigned pad1:7;
+                       unsigned dest_writemask:4;
+                       unsigned dest_subreg_nr:3;
+                       unsigned dest_reg_nr:8;
+               } da3src;
+       } bits1;
+
+
+       union {
+               struct {
+                       unsigned src0_subreg_nr:5;
+                       unsigned src0_reg_nr:8;
+                       unsigned src0_abs:1;
+                       unsigned src0_negate:1;
+                       unsigned src0_address_mode:1;
+                       unsigned src0_horiz_stride:2;
+                       unsigned src0_width:3;
+                       unsigned src0_vert_stride:4;
+                       unsigned flag_subreg_nr:1;
+                       unsigned flag_reg_nr:1;
+                       unsigned pad:5;
+               } da1;
+
+               struct {
+                       int src0_indirect_offset:10;
+                       unsigned src0_subreg_nr:3;
+                       unsigned src0_abs:1;
+                       unsigned src0_negate:1;
+                       unsigned src0_address_mode:1;
+                       unsigned src0_horiz_stride:2;
+                       unsigned src0_width:3;
+                       unsigned src0_vert_stride:4;
+                       unsigned flag_subreg_nr:1;
+                       unsigned flag_reg_nr:1;
+                       unsigned pad:5;
+               } ia1;
+
+               struct {
+                       unsigned src0_swz_x:2;
+                       unsigned src0_swz_y:2;
+                       unsigned src0_subreg_nr:1;
+                       unsigned src0_reg_nr:8;
+                       unsigned src0_abs:1;
+                       unsigned src0_negate:1;
+                       unsigned src0_address_mode:1;
+                       unsigned src0_swz_z:2;
+                       unsigned src0_swz_w:2;
+                       unsigned pad0:1;
+                       unsigned src0_vert_stride:4;
+                       unsigned flag_subreg_nr:1;
+                       unsigned flag_reg_nr:1;
+                       unsigned pad1:5;
+               } da16;
+
+               struct {
+                       unsigned src0_swz_x:2;
+                       unsigned src0_swz_y:2;
+                       int src0_indirect_offset:6;
+                       unsigned src0_subreg_nr:3;
+                       unsigned src0_abs:1;
+                       unsigned src0_negate:1;
+                       unsigned src0_address_mode:1;
+                       unsigned src0_swz_z:2;
+                       unsigned src0_swz_w:2;
+                       unsigned pad0:1;
+                       unsigned src0_vert_stride:4;
+                       unsigned flag_subreg_nr:1;
+                       unsigned flag_reg_nr:1;
+                       unsigned pad1:5;
+               } ia16;
+
+               /* Extended Message Descriptor for Ironlake (Gen5) SEND instruction.
+                *
+                * Does not apply to Gen6+.  The SFID/message target moved to bits
+                * 27:24 of the header (destreg__conditionalmod); EOT is in bits3.
+                */
+               struct {
+                       unsigned pad:26;
+                       unsigned end_of_thread:1;
+                       unsigned pad1:1;
+                       unsigned sfid:4;
+               } send_gen5;  /* for Ironlake only */
+
+               struct {
+                       unsigned src0_rep_ctrl:1;
+                       unsigned src0_swizzle:8;
+                       unsigned src0_subreg_nr:3;
+                       unsigned src0_reg_nr:8;
+                       unsigned pad0:1;
+                       unsigned src1_rep_ctrl:1;
+                       unsigned src1_swizzle:8;
+                       unsigned src1_subreg_nr_low:2;
+               } da3src;
+       } bits2;
+
+       union {
+               struct {
+                       unsigned src1_subreg_nr:5;
+                       unsigned src1_reg_nr:8;
+                       unsigned src1_abs:1;
+                       unsigned src1_negate:1;
+                       unsigned src1_address_mode:1;
+                       unsigned src1_horiz_stride:2;
+                       unsigned src1_width:3;
+                       unsigned src1_vert_stride:4;
+                       unsigned pad0:7;
+               } da1;
+
+               struct {
+                       unsigned src1_swz_x:2;
+                       unsigned src1_swz_y:2;
+                       unsigned src1_subreg_nr:1;
+                       unsigned src1_reg_nr:8;
+                       unsigned src1_abs:1;
+                       unsigned src1_negate:1;
+                       unsigned src1_address_mode:1;
+                       unsigned src1_swz_z:2;
+                       unsigned src1_swz_w:2;
+                       unsigned pad1:1;
+                       unsigned src1_vert_stride:4;
+                       unsigned pad2:7;
+               } da16;
+
+               struct {
+                       int src1_indirect_offset:10;
+                       unsigned src1_subreg_nr:3;
+                       unsigned src1_abs:1;
+                       unsigned src1_negate:1;
+                       unsigned src1_address_mode:1;
+                       unsigned src1_horiz_stride:2;
+                       unsigned src1_width:3;
+                       unsigned src1_vert_stride:4;
+                       unsigned flag_subreg_nr:1;
+                       unsigned flag_reg_nr:1;
+                       unsigned pad1:5;
+               } ia1;
+
+               struct {
+                       unsigned src1_swz_x:2;
+                       unsigned src1_swz_y:2;
+                       int  src1_indirect_offset:6;
+                       unsigned src1_subreg_nr:3;
+                       unsigned src1_abs:1;
+                       unsigned src1_negate:1;
+                       unsigned pad0:1;
+                       unsigned src1_swz_z:2;
+                       unsigned src1_swz_w:2;
+                       unsigned pad1:1;
+                       unsigned src1_vert_stride:4;
+                       unsigned flag_subreg_nr:1;
+                       unsigned flag_reg_nr:1;
+                       unsigned pad2:5;
+               } ia16;
+
+               struct {
+                       int jump_count:16;      /* note: signed */
+                       unsigned pop_count:4;
+                       unsigned pad0:12;
+               } if_else;
+
+               /* This is also used for gen7 IF/ELSE instructions */
+               struct {
+                       /* Signed jump distance to the ip to jump to if all channels
+                        * are disabled after the break or continue.  It should point
+                        * to the end of the innermost control flow block, as that's
+                        * where some channel could get re-enabled.
+                        */
+                       int jip:16;
+
+                       /* Signed jump distance to the location to resume execution
+                        * of this channel if it's enabled for the break or continue.
+                        */
+                       int uip:16;
+               } break_cont;
+
+               /**
+                * \defgroup SEND instructions / Message Descriptors
+                *
+                * @{
+                */
+
+               /**
+                * Generic Message Descriptor for Gen4 SEND instructions.  The structs
+                * below expand function_control to something specific for their
+                * message.  Due to struct packing issues, they duplicate these bits.
+                *
+                * See the G45 PRM, Volume 4, Table 14-15.
+                */
+               struct {
+                       unsigned function_control:16;
+                       unsigned response_length:4;
+                       unsigned msg_length:4;
+                       unsigned msg_target:4;
+                       unsigned pad1:3;
+                       unsigned end_of_thread:1;
+               } generic;
+
+               /**
+                * Generic Message Descriptor for Gen5-7 SEND instructions.
+                *
+                * See the Sandybridge PRM, Volume 2 Part 2, Table 8-15.  (Sadly, most
+                * of the information on the SEND instruction is missing from the public
+                * Ironlake PRM.)
+                *
+                * The table claims that bit 31 is reserved/MBZ on Gen6+, but it lies.
+                * According to the SEND instruction description:
+                * "The MSb of the message description, the EOT field, always comes from
+                *  bit 127 of the instruction word"...which is bit 31 of this field.
+                */
+               struct {
+                       unsigned function_control:19;
+                       unsigned header_present:1;
+                       unsigned response_length:5;
+                       unsigned msg_length:4;
+                       unsigned pad1:2;
+                       unsigned end_of_thread:1;
+               } generic_gen5;
+
+               /** G45 PRM, Volume 4, Section 6.1.1.1 */
+               struct {
+                       unsigned function:4;
+                       unsigned int_type:1;
+                       unsigned precision:1;
+                       unsigned saturate:1;
+                       unsigned data_type:1;
+                       unsigned pad0:8;
+                       unsigned response_length:4;
+                       unsigned msg_length:4;
+                       unsigned msg_target:4;
+                       unsigned pad1:3;
+                       unsigned end_of_thread:1;
+               } math;
+
+               /** Ironlake PRM, Volume 4 Part 1, Section 6.1.1.1 */
+               struct {
+                       unsigned function:4;
+                       unsigned int_type:1;
+                       unsigned precision:1;
+                       unsigned saturate:1;
+                       unsigned data_type:1;
+                       unsigned snapshot:1;
+                       unsigned pad0:10;
+                       unsigned header_present:1;
+                       unsigned response_length:5;
+                       unsigned msg_length:4;
+                       unsigned pad1:2;
+                       unsigned end_of_thread:1;
+               } math_gen5;
+
+               /** G45 PRM, Volume 4, Section 4.8.1.1.1 [DevBW] and [DevCL] */
+               struct {
+                       unsigned binding_table_index:8;
+                       unsigned sampler:4;
+                       unsigned return_format:2;
+                       unsigned msg_type:2;
+                       unsigned response_length:4;
+                       unsigned msg_length:4;
+                       unsigned msg_target:4;
+                       unsigned pad1:3;
+                       unsigned end_of_thread:1;
+               } sampler;
+
+               /** G45 PRM, Volume 4, Section 4.8.1.1.2 [DevCTG] */
+               struct {
+                       unsigned binding_table_index:8;
+                       unsigned sampler:4;
+                       unsigned msg_type:4;
+                       unsigned response_length:4;
+                       unsigned msg_length:4;
+                       unsigned msg_target:4;
+                       unsigned pad1:3;
+                       unsigned end_of_thread:1;
+               } sampler_g4x;
+
+               /** Ironlake PRM, Volume 4 Part 1, Section 4.11.1.1.3 */
+               struct {
+                       unsigned binding_table_index:8;
+                       unsigned sampler:4;
+                       unsigned msg_type:4;
+                       unsigned simd_mode:2;
+                       unsigned pad0:1;
+                       unsigned header_present:1;
+                       unsigned response_length:5;
+                       unsigned msg_length:4;
+                       unsigned pad1:2;
+                       unsigned end_of_thread:1;
+               } sampler_gen5;
+
+               struct {
+                       unsigned binding_table_index:8;
+                       unsigned sampler:4;
+                       unsigned msg_type:5;
+                       unsigned simd_mode:2;
+                       unsigned header_present:1;
+                       unsigned response_length:5;
+                       unsigned msg_length:4;
+                       unsigned pad1:2;
+                       unsigned end_of_thread:1;
+               } sampler_gen7;
+
+               struct brw_urb_immediate {
+                       unsigned opcode:4;
+                       unsigned offset:6;
+                       unsigned swizzle_control:2;
+                       unsigned pad:1;
+                       unsigned allocate:1;
+                       unsigned used:1;
+                       unsigned complete:1;
+                       unsigned response_length:4;
+                       unsigned msg_length:4;
+                       unsigned msg_target:4;
+                       unsigned pad1:3;
+                       unsigned end_of_thread:1;
+               } urb;
+
+               struct {
+                       unsigned opcode:4;
+                       unsigned offset:6;
+                       unsigned swizzle_control:2;
+                       unsigned pad:1;
+                       unsigned allocate:1;
+                       unsigned used:1;
+                       unsigned complete:1;
+                       unsigned pad0:3;
+                       unsigned header_present:1;
+                       unsigned response_length:5;
+                       unsigned msg_length:4;
+                       unsigned pad1:2;
+                       unsigned end_of_thread:1;
+               } urb_gen5;
+
+               struct {
+                       unsigned opcode:3;
+                       unsigned offset:11;
+                       unsigned swizzle_control:1;
+                       unsigned complete:1;
+                       unsigned per_slot_offset:1;
+                       unsigned pad0:2;
+                       unsigned header_present:1;
+                       unsigned response_length:5;
+                       unsigned msg_length:4;
+                       unsigned pad1:2;
+                       unsigned end_of_thread:1;
+               } urb_gen7;
+
+               /** 965 PRM, Volume 4, Section 5.10.1.1: Message Descriptor */
+               struct {
+                       unsigned binding_table_index:8;
+                       unsigned msg_control:4;
+                       unsigned msg_type:2;
+                       unsigned target_cache:2;
+                       unsigned response_length:4;
+                       unsigned msg_length:4;
+                       unsigned msg_target:4;
+                       unsigned pad1:3;
+                       unsigned end_of_thread:1;
+               } dp_read;
+
+               /** G45 PRM, Volume 4, Section 5.10.1.1.2 */
+               struct {
+                       unsigned binding_table_index:8;
+                       unsigned msg_control:3;
+                       unsigned msg_type:3;
+                       unsigned target_cache:2;
+                       unsigned response_length:4;
+                       unsigned msg_length:4;
+                       unsigned msg_target:4;
+                       unsigned pad1:3;
+                       unsigned end_of_thread:1;
+               } dp_read_g4x;
+
+               /** Ironlake PRM, Volume 4 Part 1, Section 5.10.2.1.2. */
+               struct {
+                       unsigned binding_table_index:8;
+                       unsigned msg_control:3;
+                       unsigned msg_type:3;
+                       unsigned target_cache:2;
+                       unsigned pad0:3;
+                       unsigned header_present:1;
+                       unsigned response_length:5;
+                       unsigned msg_length:4;
+                       unsigned pad1:2;
+                       unsigned end_of_thread:1;
+               } dp_read_gen5;
+
+               /** G45 PRM, Volume 4, Section 5.10.1.1.2.  For both Gen4 and G45. */
+               struct {
+                       unsigned binding_table_index:8;
+                       unsigned msg_control:3;
+                       unsigned last_render_target:1;
+                       unsigned msg_type:3;
+                       unsigned send_commit_msg:1;
+                       unsigned response_length:4;
+                       unsigned msg_length:4;
+                       unsigned msg_target:4;
+                       unsigned pad1:3;
+                       unsigned end_of_thread:1;
+               } dp_write;
+
+               /** Ironlake PRM, Volume 4 Part 1, Section 5.10.2.1.2. */
+               struct {
+                       unsigned binding_table_index:8;
+                       unsigned msg_control:3;
+                       unsigned last_render_target:1;
+                       unsigned msg_type:3;
+                       unsigned send_commit_msg:1;
+                       unsigned pad0:3;
+                       unsigned header_present:1;
+                       unsigned response_length:5;
+                       unsigned msg_length:4;
+                       unsigned pad1:2;
+                       unsigned end_of_thread:1;
+               } dp_write_gen5;
+
+               /**
+                * Message for the Sandybridge Sampler Cache or Constant Cache Data Port.
+                *
+                * See the Sandybridge PRM, Volume 4 Part 1, Section 3.9.2.1.1.
+                **/
+               struct {
+                       unsigned binding_table_index:8;
+                       unsigned msg_control:5;
+                       unsigned msg_type:3;
+                       unsigned pad0:3;
+                       unsigned header_present:1;
+                       unsigned response_length:5;
+                       unsigned msg_length:4;
+                       unsigned pad1:2;
+                       unsigned end_of_thread:1;
+               } gen6_dp_sampler_const_cache;
+
+               /**
+                * Message for the Sandybridge Render Cache Data Port.
+                *
+                * Most fields are defined in the Sandybridge PRM, Volume 4 Part 1,
+                * Section 3.9.2.1.1: Message Descriptor.
+                *
+                * "Slot Group Select" and "Last Render Target" are part of the
+                * 5-bit message control for Render Target Write messages.  See
+                * Section 3.9.9.2.1 of the same volume.
+                */
+               struct {
+                       unsigned binding_table_index:8;
+                       unsigned msg_control:3;
+                       unsigned slot_group_select:1;
+                       unsigned last_render_target:1;
+                       unsigned msg_type:4;
+                       unsigned send_commit_msg:1;
+                       unsigned pad0:1;
+                       unsigned header_present:1;
+                       unsigned response_length:5;
+                       unsigned msg_length:4;
+                       unsigned pad1:2;
+                       unsigned end_of_thread:1;
+               } gen6_dp;
+
+               /**
+                * Message for any of the Gen7 Data Port caches.
+                *
+                * Most fields are defined in BSpec volume 5c.2 Data Port / Messages /
+                * Data Port Messages / Message Descriptor.  Once again, "Slot Group
+                * Select" and "Last Render Target" are part of the 6-bit message
+                * control for Render Target Writes.
+                */
+               struct {
+                       unsigned binding_table_index:8;
+                       unsigned msg_control:3;
+                       unsigned slot_group_select:1;
+                       unsigned last_render_target:1;
+                       unsigned msg_control_pad:1;
+                       unsigned msg_type:4;
+                       unsigned pad1:1;
+                       unsigned header_present:1;
+                       unsigned response_length:5;
+                       unsigned msg_length:4;
+                       unsigned pad2:2;
+                       unsigned end_of_thread:1;
+               } gen7_dp;
+               /** @} */
+
+               struct {
+                       unsigned src1_subreg_nr_high:1;
+                       unsigned src1_reg_nr:8;
+                       unsigned pad0:1;
+                       unsigned src2_rep_ctrl:1;
+                       unsigned src2_swizzle:8;
+                       unsigned src2_subreg_nr:3;
+                       unsigned src2_reg_nr:8;
+                       unsigned pad1:2;
+               } da3src;
+
+               int d;
+               unsigned ud;
+               float f;
+       } bits3;
+};
+
+
+/* These aren't hardware structs, just something useful for us to pass around:
+ *
+ * Align1 operation has a lot of control over input ranges.  Used in
+ * WM programs to implement shaders decomposed into "channel serial"
+ * or "structure of array" form:
+ */
+struct brw_reg {
+       unsigned type:4;
+       unsigned file:2;
+       unsigned nr:8;
+       unsigned subnr:5;               /* :1 in align16 */
+       unsigned negate:1;              /* source only */
+       unsigned abs:1;         /* source only */
+       unsigned vstride:4;             /* source only */
+       unsigned width:3;               /* src only, align1 only */
+       unsigned hstride:2;             /* align1 only */
+       unsigned address_mode:1;        /* relative addressing, hopefully! */
+       unsigned pad0:1;
+
+       union {
+               struct {
+                       unsigned swizzle:8;             /* src only, align16 only */
+                       unsigned writemask:4;           /* dest only, align16 only */
+                       int  indirect_offset:10;        /* relative addressing offset */
+                       unsigned pad1:10;               /* two dwords total */
+               } bits;
+
+               float f;
+               int   d;
+               unsigned ud;
+       } dw1;
+};
+
+struct brw_indirect {
+       unsigned addr_subnr:4;
+       int addr_offset:10;
+       unsigned pad:18;
+};
+
+#define BRW_EU_MAX_INSN_STACK 5
+#define BRW_EU_MAX_INSN 10000
+
+struct brw_compile {
+       struct brw_instruction *store;
+       unsigned nr_insn;
+
+       int gen;
+
+       /* Allow clients to push/pop instruction state:
+       */
+       struct brw_instruction stack[BRW_EU_MAX_INSN_STACK];
+       bool compressed_stack[BRW_EU_MAX_INSN_STACK];
+       struct brw_instruction *current;
+
+       unsigned flag_value;
+       bool single_program_flow;
+       bool compressed;
+
+       /* Control flow stacks:
+        * - if_stack contains IF and ELSE instructions which must be patched
+        *   (and popped) once the matching ENDIF instruction is encountered.
+        */
+       struct brw_instruction **if_stack;
+       int if_stack_depth;
+       int if_stack_array_size;
+};
+
+static inline int type_sz(unsigned type)
+{
+       switch (type) {
+       case BRW_REGISTER_TYPE_UD:
+       case BRW_REGISTER_TYPE_D:
+       case BRW_REGISTER_TYPE_F:
+               return 4;
+       case BRW_REGISTER_TYPE_HF:
+       case BRW_REGISTER_TYPE_UW:
+       case BRW_REGISTER_TYPE_W:
+               return 2;
+       case BRW_REGISTER_TYPE_UB:
+       case BRW_REGISTER_TYPE_B:
+               return 1;
+       default:
+               return 0;
+       }
+}
+
+/**
+ * Construct a brw_reg.
+ * \param file  one of the BRW_x_REGISTER_FILE values
+ * \param nr  register number/index
+ * \param subnr  register sub number
+ * \param type  one of BRW_REGISTER_TYPE_x
+ * \param vstride  one of BRW_VERTICAL_STRIDE_x
+ * \param width  one of BRW_WIDTH_x
+ * \param hstride  one of BRW_HORIZONTAL_STRIDE_x
+ * \param swizzle  one of BRW_SWIZZLE_x
+ * \param writemask  WRITEMASK_X/Y/Z/W bitfield
+ */
+static inline struct brw_reg brw_reg(unsigned file,
+                                    unsigned nr,
+                                    unsigned subnr,
+                                    unsigned type,
+                                    unsigned vstride,
+                                    unsigned width,
+                                    unsigned hstride,
+                                    unsigned swizzle,
+                                    unsigned writemask)
+{
+       struct brw_reg reg;
+       if (file == BRW_GENERAL_REGISTER_FILE)
+               assert(nr < BRW_MAX_GRF);
+       else if (file == BRW_MESSAGE_REGISTER_FILE)
+               assert((nr & ~(1 << 7)) < BRW_MAX_MRF);
+       else if (file == BRW_ARCHITECTURE_REGISTER_FILE)
+               assert(nr <= BRW_ARF_IP);
+
+       reg.type = type;
+       reg.file = file;
+       reg.nr = nr;
+       reg.subnr = subnr * type_sz(type);
+       reg.negate = 0;
+       reg.abs = 0;
+       reg.vstride = vstride;
+       reg.width = width;
+       reg.hstride = hstride;
+       reg.address_mode = BRW_ADDRESS_DIRECT;
+       reg.pad0 = 0;
+
+       /* Could do better: If the reg is r5.3<0;1,0>, we probably want to
+        * set swizzle and writemask to W, as the lower bits of subnr will
+        * be lost when converted to align16.  This is probably too much to
+        * keep track of as you'd want it adjusted by suboffset(), etc.
+        * Perhaps fix up when converting to align16?
+        */
+       reg.dw1.bits.swizzle = swizzle;
+       reg.dw1.bits.writemask = writemask;
+       reg.dw1.bits.indirect_offset = 0;
+       reg.dw1.bits.pad1 = 0;
+       return reg;
+}
+
+/** Construct float[16] register */
+static inline struct brw_reg brw_vec16_reg(unsigned file,
+                                          unsigned nr,
+                                          unsigned subnr)
+{
+       return brw_reg(file,
+                      nr,
+                      subnr,
+                      BRW_REGISTER_TYPE_F,
+                      BRW_VERTICAL_STRIDE_16,
+                      BRW_WIDTH_16,
+                      BRW_HORIZONTAL_STRIDE_1,
+                      BRW_SWIZZLE_XYZW,
+                      WRITEMASK_XYZW);
+}
+
+/** Construct float[8] register */
+static inline struct brw_reg brw_vec8_reg(unsigned file,
+                                         unsigned nr,
+                                         unsigned subnr)
+{
+       return brw_reg(file,
+                      nr,
+                      subnr,
+                      BRW_REGISTER_TYPE_F,
+                      BRW_VERTICAL_STRIDE_8,
+                      BRW_WIDTH_8,
+                      BRW_HORIZONTAL_STRIDE_1,
+                      BRW_SWIZZLE_XYZW,
+                      WRITEMASK_XYZW);
+}
+
+/** Construct float[4] register */
+static inline struct brw_reg brw_vec4_reg(unsigned file,
+                                         unsigned nr,
+                                         unsigned subnr)
+{
+       return brw_reg(file,
+                      nr,
+                      subnr,
+                      BRW_REGISTER_TYPE_F,
+                      BRW_VERTICAL_STRIDE_4,
+                      BRW_WIDTH_4,
+                      BRW_HORIZONTAL_STRIDE_1,
+                      BRW_SWIZZLE_XYZW,
+                      WRITEMASK_XYZW);
+}
+
+/** Construct float[2] register */
+static inline struct brw_reg brw_vec2_reg(unsigned file,
+                                         unsigned nr,
+                                         unsigned subnr)
+{
+       return brw_reg(file,
+                      nr,
+                      subnr,
+                      BRW_REGISTER_TYPE_F,
+                      BRW_VERTICAL_STRIDE_2,
+                      BRW_WIDTH_2,
+                      BRW_HORIZONTAL_STRIDE_1,
+                      BRW_SWIZZLE_XYXY,
+                      WRITEMASK_XY);
+}
+
+/** Construct float[1] register */
+static inline struct brw_reg brw_vec1_reg(unsigned file,
+                                         unsigned nr,
+                                         unsigned subnr)
+{
+       return brw_reg(file,
+                      nr,
+                      subnr,
+                      BRW_REGISTER_TYPE_F,
+                      BRW_VERTICAL_STRIDE_0,
+                      BRW_WIDTH_1,
+                      BRW_HORIZONTAL_STRIDE_0,
+                      BRW_SWIZZLE_XXXX,
+                      WRITEMASK_X);
+}
+
+
+static inline struct brw_reg __retype(struct brw_reg reg,
+                                     unsigned type)
+{
+       reg.type = type;
+       return reg;
+}
+
+static inline struct brw_reg __retype_d(struct brw_reg reg)
+{
+       return __retype(reg, BRW_REGISTER_TYPE_D);
+}
+
+static inline struct brw_reg __retype_ud(struct brw_reg reg)
+{
+       return __retype(reg, BRW_REGISTER_TYPE_UD);
+}
+
+static inline struct brw_reg __retype_uw(struct brw_reg reg)
+{
+       return __retype(reg, BRW_REGISTER_TYPE_UW);
+}
+
+static inline struct brw_reg __sechalf(struct brw_reg reg)
+{
+       if (reg.vstride)
+               reg.nr++;
+       return reg;
+}
+
+static inline struct brw_reg __suboffset(struct brw_reg reg,
+                                        unsigned delta)
+{
+       reg.subnr += delta * type_sz(reg.type);
+       return reg;
+}
+
+static inline struct brw_reg __offset(struct brw_reg reg,
+                                     unsigned delta)
+{
+       reg.nr += delta;
+       return reg;
+}
+
+static inline struct brw_reg byte_offset(struct brw_reg reg,
+                                        unsigned bytes)
+{
+       unsigned newoffset = reg.nr * REG_SIZE + reg.subnr + bytes;
+       reg.nr = newoffset / REG_SIZE;
+       reg.subnr = newoffset % REG_SIZE;
+       return reg;
+}
+
+
+/** Construct unsigned word[16] register */
+static inline struct brw_reg brw_uw16_reg(unsigned file,
+                                         unsigned nr,
+                                         unsigned subnr)
+{
+       return __suboffset(__retype(brw_vec16_reg(file, nr, 0), BRW_REGISTER_TYPE_UW), subnr);
+}
+
+/** Construct unsigned word[8] register */
+static inline struct brw_reg brw_uw8_reg(unsigned file,
+                                        unsigned nr,
+                                        unsigned subnr)
+{
+       return __suboffset(__retype(brw_vec8_reg(file, nr, 0), BRW_REGISTER_TYPE_UW), subnr);
+}
+
+/** Construct unsigned word[1] register */
+static inline struct brw_reg brw_uw1_reg(unsigned file,
+                                        unsigned nr,
+                                        unsigned subnr)
+{
+       return __suboffset(__retype(brw_vec1_reg(file, nr, 0), BRW_REGISTER_TYPE_UW), subnr);
+}
+
+static inline struct brw_reg brw_imm_reg(unsigned type)
+{
+       return brw_reg( BRW_IMMEDIATE_VALUE,
+                       0,
+                       0,
+                       type,
+                       BRW_VERTICAL_STRIDE_0,
+                       BRW_WIDTH_1,
+                       BRW_HORIZONTAL_STRIDE_0,
+                       0,
+                       0);
+}
+
+/** Construct float immediate register */
+static inline struct brw_reg brw_imm_f(float f)
+{
+       struct brw_reg imm = brw_imm_reg(BRW_REGISTER_TYPE_F);
+       imm.dw1.f = f;
+       return imm;
+}
+
+/** Construct integer immediate register */
+static inline struct brw_reg brw_imm_d(int d)
+{
+       struct brw_reg imm = brw_imm_reg(BRW_REGISTER_TYPE_D);
+       imm.dw1.d = d;
+       return imm;
+}
+
+/** Construct uint immediate register */
+static inline struct brw_reg brw_imm_ud(unsigned ud)
+{
+       struct brw_reg imm = brw_imm_reg(BRW_REGISTER_TYPE_UD);
+       imm.dw1.ud = ud;
+       return imm;
+}
+
+/** Construct ushort immediate register */
+static inline struct brw_reg brw_imm_uw(uint16_t uw)
+{
+       struct brw_reg imm = brw_imm_reg(BRW_REGISTER_TYPE_UW);
+       imm.dw1.ud = uw | (uw << 16);
+       return imm;
+}
+
+/** Construct short immediate register */
+static inline struct brw_reg brw_imm_w(int16_t w)
+{
+       struct brw_reg imm = brw_imm_reg(BRW_REGISTER_TYPE_W);
+       imm.dw1.d = w | (w << 16);
+       return imm;
+}
+
+/* brw_imm_b and brw_imm_ub aren't supported by hardware - the type
+ * numbers alias with _V and _VF below:
+ */
+
+/** Construct vector of eight signed half-byte values */
+static inline struct brw_reg brw_imm_v(unsigned v)
+{
+       struct brw_reg imm = brw_imm_reg(BRW_REGISTER_TYPE_V);
+       imm.vstride = BRW_VERTICAL_STRIDE_0;
+       imm.width = BRW_WIDTH_8;
+       imm.hstride = BRW_HORIZONTAL_STRIDE_1;
+       imm.dw1.ud = v;
+       return imm;
+}
+
+/** Construct vector of four 8-bit float values */
+static inline struct brw_reg brw_imm_vf(unsigned v)
+{
+       struct brw_reg imm = brw_imm_reg(BRW_REGISTER_TYPE_VF);
+       imm.vstride = BRW_VERTICAL_STRIDE_0;
+       imm.width = BRW_WIDTH_4;
+       imm.hstride = BRW_HORIZONTAL_STRIDE_1;
+       imm.dw1.ud = v;
+       return imm;
+}
+
+#define VF_ZERO 0x0
+#define VF_ONE  0x30
+#define VF_NEG  (1<<7)
+
+static inline struct brw_reg brw_imm_vf4(unsigned v0,
+                                        unsigned v1,
+                                        unsigned v2,
+                                        unsigned v3)
+{
+       struct brw_reg imm = brw_imm_reg(BRW_REGISTER_TYPE_VF);
+       imm.vstride = BRW_VERTICAL_STRIDE_0;
+       imm.width = BRW_WIDTH_4;
+       imm.hstride = BRW_HORIZONTAL_STRIDE_1;
+       imm.dw1.ud = ((v0 << 0) |
+                     (v1 << 8) |
+                     (v2 << 16) |
+                     (v3 << 24));
+       return imm;
+}
+
+static inline struct brw_reg brw_address(struct brw_reg reg)
+{
+       return brw_imm_uw(reg.nr * REG_SIZE + reg.subnr);
+}
+
+/** Construct float[1] general-purpose register */
+static inline struct brw_reg brw_vec1_grf(unsigned nr, unsigned subnr)
+{
+       return brw_vec1_reg(BRW_GENERAL_REGISTER_FILE, nr, subnr);
+}
+
+/** Construct float[2] general-purpose register */
+static inline struct brw_reg brw_vec2_grf(unsigned nr, unsigned subnr)
+{
+       return brw_vec2_reg(BRW_GENERAL_REGISTER_FILE, nr, subnr);
+}
+
+/** Construct float[4] general-purpose register */
+static inline struct brw_reg brw_vec4_grf(unsigned nr, unsigned subnr)
+{
+       return brw_vec4_reg(BRW_GENERAL_REGISTER_FILE, nr, subnr);
+}
+
+/** Construct float[8] general-purpose register */
+static inline struct brw_reg brw_vec8_grf(unsigned nr, unsigned subnr)
+{
+       return brw_vec8_reg(BRW_GENERAL_REGISTER_FILE, nr, subnr);
+}
+
+static inline struct brw_reg brw_uw8_grf(unsigned nr, unsigned subnr)
+{
+       return brw_uw8_reg(BRW_GENERAL_REGISTER_FILE, nr, subnr);
+}
+
+static inline struct brw_reg brw_uw16_grf(unsigned nr, unsigned subnr)
+{
+       return brw_uw16_reg(BRW_GENERAL_REGISTER_FILE, nr, subnr);
+}
+
+/** Construct null register (usually used for setting condition codes) */
+static inline struct brw_reg brw_null_reg(void)
+{
+       return brw_vec8_reg(BRW_ARCHITECTURE_REGISTER_FILE,
+                           BRW_ARF_NULL,
+                           0);
+}
+
+static inline struct brw_reg brw_address_reg(unsigned subnr)
+{
+       return brw_uw1_reg(BRW_ARCHITECTURE_REGISTER_FILE,
+                          BRW_ARF_ADDRESS,
+                          subnr);
+}
+
+/* If/else instructions break in align16 mode if writemask & swizzle
+ * aren't xyzw.  This goes against the convention for other scalar
+ * regs:
+ */
+static inline struct brw_reg brw_ip_reg(void)
+{
+       return brw_reg(BRW_ARCHITECTURE_REGISTER_FILE,
+                      BRW_ARF_IP,
+                      0,
+                      BRW_REGISTER_TYPE_UD,
+                      BRW_VERTICAL_STRIDE_4, /* ? */
+                      BRW_WIDTH_1,
+                      BRW_HORIZONTAL_STRIDE_0,
+                      BRW_SWIZZLE_XYZW, /* NOTE! */
+                      WRITEMASK_XYZW); /* NOTE! */
+}
+
+static inline struct brw_reg brw_acc_reg(void)
+{
+       return brw_vec8_reg(BRW_ARCHITECTURE_REGISTER_FILE,
+                           BRW_ARF_ACCUMULATOR,
+                           0);
+}
+
+static inline struct brw_reg brw_notification_1_reg(void)
+{
+       return brw_reg(BRW_ARCHITECTURE_REGISTER_FILE,
+                      BRW_ARF_NOTIFICATION_COUNT,
+                      1,
+                      BRW_REGISTER_TYPE_UD,
+                      BRW_VERTICAL_STRIDE_0,
+                      BRW_WIDTH_1,
+                      BRW_HORIZONTAL_STRIDE_0,
+                      BRW_SWIZZLE_XXXX,
+                      WRITEMASK_X);
+}
+
+static inline struct brw_reg brw_flag_reg(void)
+{
+       return brw_uw1_reg(BRW_ARCHITECTURE_REGISTER_FILE,
+                          BRW_ARF_FLAG,
+                          0);
+}
+
+static inline struct brw_reg brw_mask_reg(unsigned subnr)
+{
+       return brw_uw1_reg(BRW_ARCHITECTURE_REGISTER_FILE,
+                          BRW_ARF_MASK,
+                          subnr);
+}
+
+static inline struct brw_reg brw_message_reg(unsigned nr)
+{
+       assert((nr & ~(1 << 7)) < BRW_MAX_MRF);
+       return brw_vec8_reg(BRW_MESSAGE_REGISTER_FILE, nr, 0);
+}
+
+static inline struct brw_reg brw_message4_reg(unsigned nr,
+                                             int subnr)
+{
+       assert((nr & ~(1 << 7)) < BRW_MAX_MRF);
+       return brw_vec4_reg(BRW_MESSAGE_REGISTER_FILE, nr, subnr);
+}
+
+/* This is almost always called with a numeric constant argument, so
+ * make things easy to evaluate at compile time:
+ */
+static inline unsigned cvt(unsigned val)
+{
+       switch (val) {
+       case 0: return 0;
+       case 1: return 1;
+       case 2: return 2;
+       case 4: return 3;
+       case 8: return 4;
+       case 16: return 5;
+       case 32: return 6;
+       }
+       return 0;
+}
+
+static inline struct brw_reg __stride(struct brw_reg reg,
+                                   unsigned vstride,
+                                   unsigned width,
+                                   unsigned hstride)
+{
+       reg.vstride = cvt(vstride);
+       reg.width = cvt(width) - 1;
+       reg.hstride = cvt(hstride);
+       return reg;
+}
+
+static inline struct brw_reg vec16(struct brw_reg reg)
+{
+       return __stride(reg, 16,16,1);
+}
+
+static inline struct brw_reg vec8(struct brw_reg reg)
+{
+       return __stride(reg, 8,8,1);
+}
+
+static inline struct brw_reg vec4(struct brw_reg reg)
+{
+       return __stride(reg, 4,4,1);
+}
+
+static inline struct brw_reg vec2(struct brw_reg reg)
+{
+       return __stride(reg, 2,2,1);
+}
+
+static inline struct brw_reg vec1(struct brw_reg reg)
+{
+       return __stride(reg, 0,1,0);
+}
+
+static inline struct brw_reg get_element(struct brw_reg reg, unsigned elt)
+{
+       return vec1(__suboffset(reg, elt));
+}
+
+static inline struct brw_reg get_element_ud(struct brw_reg reg, unsigned elt)
+{
+       return vec1(__suboffset(__retype(reg, BRW_REGISTER_TYPE_UD), elt));
+}
+
+static inline struct brw_reg brw_swizzle(struct brw_reg reg,
+                                        unsigned x,
+                                        unsigned y,
+                                        unsigned z,
+                                        unsigned w)
+{
+       assert(reg.file != BRW_IMMEDIATE_VALUE);
+
+       reg.dw1.bits.swizzle = BRW_SWIZZLE4(BRW_GET_SWZ(reg.dw1.bits.swizzle, x),
+                                           BRW_GET_SWZ(reg.dw1.bits.swizzle, y),
+                                           BRW_GET_SWZ(reg.dw1.bits.swizzle, z),
+                                           BRW_GET_SWZ(reg.dw1.bits.swizzle, w));
+       return reg;
+}
+
+static inline struct brw_reg brw_swizzle1(struct brw_reg reg,
+                                         unsigned x)
+{
+       return brw_swizzle(reg, x, x, x, x);
+}
+
+static inline struct brw_reg brw_writemask(struct brw_reg reg,
+                                          unsigned mask)
+{
+       assert(reg.file != BRW_IMMEDIATE_VALUE);
+       reg.dw1.bits.writemask &= mask;
+       return reg;
+}
+
+static inline struct brw_reg brw_set_writemask(struct brw_reg reg,
+                                              unsigned mask)
+{
+       assert(reg.file != BRW_IMMEDIATE_VALUE);
+       reg.dw1.bits.writemask = mask;
+       return reg;
+}
+
+static inline struct brw_reg brw_negate(struct brw_reg reg)
+{
+       reg.negate ^= 1;
+       return reg;
+}
+
+static inline struct brw_reg brw_abs(struct brw_reg reg)
+{
+       reg.abs = 1;
+       return reg;
+}
+
+/***********************************************************************
+*/
+static inline struct brw_reg brw_vec4_indirect(unsigned subnr,
+                                              int offset)
+{
+       struct brw_reg reg =  brw_vec4_grf(0, 0);
+       reg.subnr = subnr;
+       reg.address_mode = BRW_ADDRESS_REGISTER_INDIRECT_REGISTER;
+       reg.dw1.bits.indirect_offset = offset;
+       return reg;
+}
+
+static inline struct brw_reg brw_vec1_indirect(unsigned subnr,
+                                              int offset)
+{
+       struct brw_reg reg =  brw_vec1_grf(0, 0);
+       reg.subnr = subnr;
+       reg.address_mode = BRW_ADDRESS_REGISTER_INDIRECT_REGISTER;
+       reg.dw1.bits.indirect_offset = offset;
+       return reg;
+}
+
+static inline struct brw_reg deref_4f(struct brw_indirect ptr, int offset)
+{
+       return brw_vec4_indirect(ptr.addr_subnr, ptr.addr_offset + offset);
+}
+
+static inline struct brw_reg deref_1f(struct brw_indirect ptr, int offset)
+{
+       return brw_vec1_indirect(ptr.addr_subnr, ptr.addr_offset + offset);
+}
+
+static inline struct brw_reg deref_4b(struct brw_indirect ptr, int offset)
+{
+       return __retype(deref_4f(ptr, offset), BRW_REGISTER_TYPE_B);
+}
+
+static inline struct brw_reg deref_1uw(struct brw_indirect ptr, int offset)
+{
+       return __retype(deref_1f(ptr, offset), BRW_REGISTER_TYPE_UW);
+}
+
+static inline struct brw_reg deref_1d(struct brw_indirect ptr, int offset)
+{
+       return __retype(deref_1f(ptr, offset), BRW_REGISTER_TYPE_D);
+}
+
+static inline struct brw_reg deref_1ud(struct brw_indirect ptr, int offset)
+{
+       return __retype(deref_1f(ptr, offset), BRW_REGISTER_TYPE_UD);
+}
+
+static inline struct brw_reg get_addr_reg(struct brw_indirect ptr)
+{
+       return brw_address_reg(ptr.addr_subnr);
+}
+
+static inline struct brw_indirect brw_indirect_offset(struct brw_indirect ptr, int offset)
+{
+       ptr.addr_offset += offset;
+       return ptr;
+}
+
+static inline struct brw_indirect brw_indirect(unsigned addr_subnr, int offset)
+{
+       struct brw_indirect ptr;
+       ptr.addr_subnr = addr_subnr;
+       ptr.addr_offset = offset;
+       ptr.pad = 0;
+       return ptr;
+}
+
+/** Do two brw_regs refer to the same register? */
+static inline bool brw_same_reg(struct brw_reg r1, struct brw_reg r2)
+{
+       return r1.file == r2.file && r1.nr == r2.nr;
+}
+
+static inline struct brw_instruction *current_insn( struct brw_compile *p)
+{
+       return &p->store[p->nr_insn];
+}
+
+static inline void brw_set_predicate_control( struct brw_compile *p, unsigned pc )
+{
+       p->current->header.predicate_control = pc;
+}
+
+static inline void brw_set_predicate_inverse(struct brw_compile *p, bool predicate_inverse)
+{
+       p->current->header.predicate_inverse = predicate_inverse;
+}
+
+static inline void brw_set_conditionalmod( struct brw_compile *p, unsigned conditional )
+{
+       p->current->header.destreg__conditionalmod = conditional;
+}
+
+static inline void brw_set_access_mode(struct brw_compile *p, unsigned access_mode)
+{
+       p->current->header.access_mode = access_mode;
+}
+
+static inline void brw_set_mask_control(struct brw_compile *p, unsigned value)
+{
+       p->current->header.mask_control = value;
+}
+
+static inline void brw_set_saturate(struct brw_compile *p, unsigned value)
+{
+       p->current->header.saturate = value;
+}
+
+static inline void brw_set_acc_write_control(struct brw_compile *p, unsigned value)
+{
+       if (p->gen >= 60)
+               p->current->header.acc_wr_control = value;
+}
+
+void brw_pop_insn_state(struct brw_compile *p);
+void brw_push_insn_state(struct brw_compile *p);
+void brw_set_compression_control(struct brw_compile *p, enum brw_compression control);
+void brw_set_predicate_control_flag_value( struct brw_compile *p, unsigned value );
+
+void brw_compile_init(struct brw_compile *p, int gen, void *store);
+
+void brw_set_dest(struct brw_compile *p, struct brw_instruction *insn,
+                 struct brw_reg dest);
+void brw_set_src0(struct brw_compile *p, struct brw_instruction *insn,
+                 struct brw_reg reg);
+void brw_set_src1(struct brw_compile *p,
+                 struct brw_instruction *insn,
+                 struct brw_reg reg);
+
+void gen6_resolve_implied_move(struct brw_compile *p,
+                              struct brw_reg *src,
+                              unsigned msg_reg_nr);
+
+static inline struct brw_instruction *
+brw_next_insn(struct brw_compile *p, unsigned opcode)
+{
+       struct brw_instruction *insn;
+
+       assert(p->nr_insn + 1 < BRW_EU_MAX_INSN);
+
+       insn = &p->store[p->nr_insn++];
+       *insn = *p->current;
+
+       if (p->current->header.destreg__conditionalmod) {
+               p->current->header.destreg__conditionalmod = 0;
+               p->current->header.predicate_control = BRW_PREDICATE_NORMAL;
+       }
+
+       insn->header.opcode = opcode;
+       return insn;
+}
+
+/* Helpers for regular instructions: */
+#define ALU1(OP)                                                       \
+static inline struct brw_instruction *brw_##OP(struct brw_compile *p,  \
+                                              struct brw_reg dest,     \
+                                              struct brw_reg src0)     \
+{                                                                      \
+   return brw_alu1(p, BRW_OPCODE_##OP, dest, src0);                    \
+}
+
+#define ALU2(OP)                                                       \
+static inline struct brw_instruction *brw_##OP(struct brw_compile *p,  \
+                                              struct brw_reg dest,     \
+                                              struct brw_reg src0,     \
+                                               struct brw_reg src1)    \
+{                                                                      \
+   return brw_alu2(p, BRW_OPCODE_##OP, dest, src0, src1);              \
+}
+
+/* Rounding operations (other than RNDD) require two instructions - the first
+ * stores a rounded value (possibly the wrong way) in the dest register, but
+ * also sets a per-channel "increment bit" in the flag register.  A predicated
+ * add of 1.0 fixes dest to contain the desired result.
+ *
+ * Sandybridge and later appear to round correctly without an ADD.
+ */
+#define ROUND(OP)                                                      \
+static inline void brw_##OP(struct brw_compile *p,                     \
+                           struct brw_reg dest,                        \
+                           struct brw_reg src)                         \
+{                                                                      \
+       struct brw_instruction *rnd, *add;                              \
+       rnd = brw_next_insn(p, BRW_OPCODE_##OP);                        \
+       brw_set_dest(p, rnd, dest);                                     \
+       brw_set_src0(p, rnd, src);                                      \
+       if (p->gen < 60) {                                              \
+               /* turn on round-increments */                          \
+               rnd->header.destreg__conditionalmod = BRW_CONDITIONAL_R; \
+               add = brw_ADD(p, dest, dest, brw_imm_f(1.0f));          \
+               add->header.predicate_control = BRW_PREDICATE_NORMAL;   \
+       }                                                               \
+}
+
+static inline struct brw_instruction *brw_alu1(struct brw_compile *p,
+                                              unsigned opcode,
+                                              struct brw_reg dest,
+                                              struct brw_reg src)
+{
+       struct brw_instruction *insn = brw_next_insn(p, opcode);
+       brw_set_dest(p, insn, dest);
+       brw_set_src0(p, insn, src);
+       return insn;
+}
+
+static inline struct brw_instruction *brw_alu2(struct brw_compile *p,
+                                              unsigned opcode,
+                                              struct brw_reg dest,
+                                              struct brw_reg src0,
+                                              struct brw_reg src1 )
+{
+       struct brw_instruction *insn = brw_next_insn(p, opcode);
+       brw_set_dest(p, insn, dest);
+       brw_set_src0(p, insn, src0);
+       brw_set_src1(p, insn, src1);
+       return insn;
+}
+
+static inline struct brw_instruction *brw_ADD(struct brw_compile *p,
+                                             struct brw_reg dest,
+                                             struct brw_reg src0,
+                                             struct brw_reg src1)
+{
+       /* 6.2.2: add */
+       if (src0.type == BRW_REGISTER_TYPE_F ||
+           (src0.file == BRW_IMMEDIATE_VALUE &&
+            src0.type == BRW_REGISTER_TYPE_VF)) {
+               assert(src1.type != BRW_REGISTER_TYPE_UD);
+               assert(src1.type != BRW_REGISTER_TYPE_D);
+       }
+
+       if (src1.type == BRW_REGISTER_TYPE_F ||
+           (src1.file == BRW_IMMEDIATE_VALUE &&
+            src1.type == BRW_REGISTER_TYPE_VF)) {
+               assert(src0.type != BRW_REGISTER_TYPE_UD);
+               assert(src0.type != BRW_REGISTER_TYPE_D);
+       }
+
+       return brw_alu2(p, BRW_OPCODE_ADD, dest, src0, src1);
+}
+
+static inline struct brw_instruction *brw_MUL(struct brw_compile *p,
+                                             struct brw_reg dest,
+                                             struct brw_reg src0,
+                                             struct brw_reg src1)
+{
+       /* 6.32.38: mul */
+       if (src0.type == BRW_REGISTER_TYPE_D ||
+           src0.type == BRW_REGISTER_TYPE_UD ||
+           src1.type == BRW_REGISTER_TYPE_D ||
+           src1.type == BRW_REGISTER_TYPE_UD) {
+               assert(dest.type != BRW_REGISTER_TYPE_F);
+       }
+
+       if (src0.type == BRW_REGISTER_TYPE_F ||
+           (src0.file == BRW_IMMEDIATE_VALUE &&
+            src0.type == BRW_REGISTER_TYPE_VF)) {
+               assert(src1.type != BRW_REGISTER_TYPE_UD);
+               assert(src1.type != BRW_REGISTER_TYPE_D);
+       }
+
+       if (src1.type == BRW_REGISTER_TYPE_F ||
+           (src1.file == BRW_IMMEDIATE_VALUE &&
+            src1.type == BRW_REGISTER_TYPE_VF)) {
+               assert(src0.type != BRW_REGISTER_TYPE_UD);
+               assert(src0.type != BRW_REGISTER_TYPE_D);
+       }
+
+       assert(src0.file != BRW_ARCHITECTURE_REGISTER_FILE ||
+              src0.nr != BRW_ARF_ACCUMULATOR);
+       assert(src1.file != BRW_ARCHITECTURE_REGISTER_FILE ||
+              src1.nr != BRW_ARF_ACCUMULATOR);
+
+       return brw_alu2(p, BRW_OPCODE_MUL, dest, src0, src1);
+}
+
+static inline struct brw_instruction *brw_JMPI(struct brw_compile *p,
+                                              struct brw_reg dest,
+                                              struct brw_reg src0,
+                                              struct brw_reg src1)
+{
+       struct brw_instruction *insn = brw_alu2(p, BRW_OPCODE_JMPI, dest, src0, src1);
+
+       insn->header.execution_size = 1;
+       insn->header.compression_control = BRW_COMPRESSION_NONE;
+       insn->header.mask_control = BRW_MASK_DISABLE;
+
+       p->current->header.predicate_control = BRW_PREDICATE_NONE;
+
+       return insn;
+}
+
+
+ALU1(MOV);
+ALU2(SEL);
+ALU1(NOT);
+ALU2(AND);
+ALU2(OR);
+ALU2(XOR);
+ALU2(SHR);
+ALU2(SHL);
+ALU2(RSR);
+ALU2(RSL);
+ALU2(ASR);
+ALU1(FRC);
+ALU1(RNDD);
+ALU2(MAC);
+ALU2(MACH);
+ALU1(LZD);
+ALU2(DP4);
+ALU2(DPH);
+ALU2(DP3);
+ALU2(DP2);
+ALU2(LINE);
+ALU2(PLN);
+
+ROUND(RNDZ);
+ROUND(RNDE);
+
+#undef ALU1
+#undef ALU2
+#undef ROUND
+
+/* Helpers for SEND instruction */
+void brw_set_dp_read_message(struct brw_compile *p,
+                            struct brw_instruction *insn,
+                            unsigned binding_table_index,
+                            unsigned msg_control,
+                            unsigned msg_type,
+                            unsigned target_cache,
+                            unsigned msg_length,
+                            unsigned response_length);
+
+void brw_set_dp_write_message(struct brw_compile *p,
+                             struct brw_instruction *insn,
+                             unsigned binding_table_index,
+                             unsigned msg_control,
+                             unsigned msg_type,
+                             unsigned msg_length,
+                             bool header_present,
+                             bool last_render_target,
+                             unsigned response_length,
+                             bool end_of_thread,
+                             bool send_commit_msg);
+
+void brw_urb_WRITE(struct brw_compile *p,
+                  struct brw_reg dest,
+                  unsigned msg_reg_nr,
+                  struct brw_reg src0,
+                  bool allocate,
+                  bool used,
+                  unsigned msg_length,
+                  unsigned response_length,
+                  bool eot,
+                  bool writes_complete,
+                  unsigned offset,
+                  unsigned swizzle);
+
+void brw_ff_sync(struct brw_compile *p,
+                struct brw_reg dest,
+                unsigned msg_reg_nr,
+                struct brw_reg src0,
+                bool allocate,
+                unsigned response_length,
+                bool eot);
+
+void brw_fb_WRITE(struct brw_compile *p,
+                 int dispatch_width,
+                  unsigned msg_reg_nr,
+                  struct brw_reg src0,
+                  unsigned msg_control,
+                  unsigned binding_table_index,
+                  unsigned msg_length,
+                  unsigned response_length,
+                  bool eot,
+                  bool header_present);
+
+void brw_SAMPLE(struct brw_compile *p,
+               struct brw_reg dest,
+               unsigned msg_reg_nr,
+               struct brw_reg src0,
+               unsigned binding_table_index,
+               unsigned sampler,
+               unsigned writemask,
+               unsigned msg_type,
+               unsigned response_length,
+               unsigned msg_length,
+               bool header_present,
+               unsigned simd_mode);
+
+void brw_math_16(struct brw_compile *p,
+                struct brw_reg dest,
+                unsigned function,
+                unsigned saturate,
+                unsigned msg_reg_nr,
+                struct brw_reg src,
+                unsigned precision);
+
+void brw_math(struct brw_compile *p,
+             struct brw_reg dest,
+             unsigned function,
+             unsigned saturate,
+             unsigned msg_reg_nr,
+             struct brw_reg src,
+             unsigned data_type,
+             unsigned precision);
+
+void brw_math2(struct brw_compile *p,
+              struct brw_reg dest,
+              unsigned function,
+              struct brw_reg src0,
+              struct brw_reg src1);
+
+void brw_oword_block_read(struct brw_compile *p,
+                         struct brw_reg dest,
+                         struct brw_reg mrf,
+                         uint32_t offset,
+                         uint32_t bind_table_index);
+
+void brw_oword_block_read_scratch(struct brw_compile *p,
+                                 struct brw_reg dest,
+                                 struct brw_reg mrf,
+                                 int num_regs,
+                                 unsigned offset);
+
+void brw_oword_block_write_scratch(struct brw_compile *p,
+                                  struct brw_reg mrf,
+                                  int num_regs,
+                                  unsigned offset);
+
+void brw_dword_scattered_read(struct brw_compile *p,
+                             struct brw_reg dest,
+                             struct brw_reg mrf,
+                             uint32_t bind_table_index);
+
+void brw_dp_READ_4_vs(struct brw_compile *p,
+                     struct brw_reg dest,
+                     unsigned location,
+                     unsigned bind_table_index);
+
+void brw_dp_READ_4_vs_relative(struct brw_compile *p,
+                              struct brw_reg dest,
+                              struct brw_reg addrReg,
+                              unsigned offset,
+                              unsigned bind_table_index);
+
+/* If/else/endif.  Works by manipulating the execution flags on each
+ * channel.
+ */
+struct brw_instruction *brw_IF(struct brw_compile *p,
+                              unsigned execute_size);
+struct brw_instruction *gen6_IF(struct brw_compile *p, uint32_t conditional,
+                               struct brw_reg src0, struct brw_reg src1);
+
+void brw_ELSE(struct brw_compile *p);
+void brw_ENDIF(struct brw_compile *p);
+
+/* DO/WHILE loops:
+*/
+struct brw_instruction *brw_DO(struct brw_compile *p,
+                              unsigned execute_size);
+
+struct brw_instruction *brw_WHILE(struct brw_compile *p,
+                                 struct brw_instruction *patch_insn);
+
+struct brw_instruction *brw_BREAK(struct brw_compile *p, int pop_count);
+struct brw_instruction *brw_CONT(struct brw_compile *p, int pop_count);
+struct brw_instruction *gen6_CONT(struct brw_compile *p,
+                                 struct brw_instruction *do_insn);
+/* Forward jumps:
+*/
+void brw_land_fwd_jump(struct brw_compile *p,
+                      struct brw_instruction *jmp_insn);
+
+void brw_NOP(struct brw_compile *p);
+
+void brw_WAIT(struct brw_compile *p);
+
+/* Special case: there is never a destination, execution size will be
+ * taken from src0:
+ */
+void brw_CMP(struct brw_compile *p,
+            struct brw_reg dest,
+            unsigned conditional,
+            struct brw_reg src0,
+            struct brw_reg src1);
+
+void brw_print_reg(struct brw_reg reg);
+
+static inline void brw_math_invert(struct brw_compile *p,
+                                  struct brw_reg dst,
+                                  struct brw_reg src)
+{
+       brw_math(p,
+                dst,
+                BRW_MATH_FUNCTION_INV,
+                BRW_MATH_SATURATE_NONE,
+                0,
+                src,
+                BRW_MATH_PRECISION_FULL,
+                BRW_MATH_DATA_VECTOR);
+}
+
+void brw_set_uip_jip(struct brw_compile *p);
+
+uint32_t brw_swap_cmod(uint32_t cmod);
+
+void brw_disasm(FILE *file,
+               const struct brw_instruction *inst,
+               int gen);
+
+#endif
diff --git a/src/sna/brw/brw_eu_emit.c b/src/sna/brw/brw_eu_emit.c
new file mode 100644 (file)
index 0000000..3f01ae7
--- /dev/null
@@ -0,0 +1,2002 @@
+/*
+   Copyright (C) Intel Corp.  2006.  All Rights Reserved.
+   Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
+   develop this 3D driver.
+
+   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 COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS 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.
+
+ **********************************************************************/
+/*
+ * Authors:
+ *   Keith Whitwell <keith@tungstengraphics.com>
+ */
+
+#include "brw_eu.h"
+
+#include <string.h>
+#include <stdlib.h>
+
+/***********************************************************************
+ * Internal helper for constructing instructions
+ */
+
+static void guess_execution_size(struct brw_compile *p,
+                                struct brw_instruction *insn,
+                                struct brw_reg reg)
+{
+       if (reg.width == BRW_WIDTH_8 && p->compressed)
+               insn->header.execution_size = BRW_EXECUTE_16;
+       else
+               insn->header.execution_size = reg.width;
+}
+
+
+/**
+ * Prior to Sandybridge, the SEND instruction accepted non-MRF source
+ * registers, implicitly moving the operand to a message register.
+ *
+ * On Sandybridge, this is no longer the case.  This function performs the
+ * explicit move; it should be called before emitting a SEND instruction.
+ */
+void
+gen6_resolve_implied_move(struct brw_compile *p,
+                         struct brw_reg *src,
+                         unsigned msg_reg_nr)
+{
+       if (p->gen < 60)
+               return;
+
+       if (src->file == BRW_MESSAGE_REGISTER_FILE)
+               return;
+
+       if (src->file != BRW_ARCHITECTURE_REGISTER_FILE || src->nr != BRW_ARF_NULL) {
+               brw_push_insn_state(p);
+               brw_set_mask_control(p, BRW_MASK_DISABLE);
+               brw_set_compression_control(p, BRW_COMPRESSION_NONE);
+               brw_MOV(p, __retype_ud(brw_message_reg(msg_reg_nr)), __retype_ud(*src));
+               brw_pop_insn_state(p);
+       }
+       *src = brw_message_reg(msg_reg_nr);
+}
+
+static void
+gen7_convert_mrf_to_grf(struct brw_compile *p, struct brw_reg *reg)
+{
+       /* From the BSpec / ISA Reference / send - [DevIVB+]:
+        * "The send with EOT should use register space R112-R127 for <src>. This is
+        *  to enable loading of a new thread into the same slot while the message
+        *  with EOT for current thread is pending dispatch."
+        *
+        * Since we're pretending to have 16 MRFs anyway, we may as well use the
+        * registers required for messages with EOT.
+        */
+       if (p->gen >= 70 && reg->file == BRW_MESSAGE_REGISTER_FILE) {
+               reg->file = BRW_GENERAL_REGISTER_FILE;
+               reg->nr += 111;
+       }
+}
+
+void
+brw_set_dest(struct brw_compile *p, struct brw_instruction *insn,
+            struct brw_reg dest)
+{
+       if (dest.file != BRW_ARCHITECTURE_REGISTER_FILE &&
+           dest.file != BRW_MESSAGE_REGISTER_FILE)
+               assert(dest.nr < 128);
+
+       gen7_convert_mrf_to_grf(p, &dest);
+
+       insn->bits1.da1.dest_reg_file = dest.file;
+       insn->bits1.da1.dest_reg_type = dest.type;
+       insn->bits1.da1.dest_address_mode = dest.address_mode;
+
+       if (dest.address_mode == BRW_ADDRESS_DIRECT) {
+               insn->bits1.da1.dest_reg_nr = dest.nr;
+
+               if (insn->header.access_mode == BRW_ALIGN_1) {
+                       insn->bits1.da1.dest_subreg_nr = dest.subnr;
+                       if (dest.hstride == BRW_HORIZONTAL_STRIDE_0)
+                               dest.hstride = BRW_HORIZONTAL_STRIDE_1;
+                       insn->bits1.da1.dest_horiz_stride = dest.hstride;
+               } else {
+                       insn->bits1.da16.dest_subreg_nr = dest.subnr / 16;
+                       insn->bits1.da16.dest_writemask = dest.dw1.bits.writemask;
+                       /* even ignored in da16, still need to set as '01' */
+                       insn->bits1.da16.dest_horiz_stride = 1;
+               }
+       } else {
+               insn->bits1.ia1.dest_subreg_nr = dest.subnr;
+
+               /* These are different sizes in align1 vs align16:
+               */
+               if (insn->header.access_mode == BRW_ALIGN_1) {
+                       insn->bits1.ia1.dest_indirect_offset = dest.dw1.bits.indirect_offset;
+                       if (dest.hstride == BRW_HORIZONTAL_STRIDE_0)
+                               dest.hstride = BRW_HORIZONTAL_STRIDE_1;
+                       insn->bits1.ia1.dest_horiz_stride = dest.hstride;
+               }
+               else {
+                       insn->bits1.ia16.dest_indirect_offset = dest.dw1.bits.indirect_offset;
+                       /* even ignored in da16, still need to set as '01' */
+                       insn->bits1.ia16.dest_horiz_stride = 1;
+               }
+       }
+
+       guess_execution_size(p, insn, dest);
+}
+
+static const int reg_type_size[8] = {
+       [0] = 4,
+       [1] = 4,
+       [2] = 2,
+       [3] = 2,
+       [4] = 1,
+       [5] = 1,
+       [7] = 4
+};
+
+static void
+validate_reg(struct brw_instruction *insn, struct brw_reg reg)
+{
+       int hstride_for_reg[] = {0, 1, 2, 4};
+       int vstride_for_reg[] = {0, 1, 2, 4, 8, 16, 32, 64, 128, 256};
+       int width_for_reg[] = {1, 2, 4, 8, 16};
+       int execsize_for_reg[] = {1, 2, 4, 8, 16};
+       int width, hstride, vstride, execsize;
+
+       if (reg.file == BRW_IMMEDIATE_VALUE) {
+               /* 3.3.6: Region Parameters.  Restriction: Immediate vectors
+                * mean the destination has to be 128-bit aligned and the
+                * destination horiz stride has to be a word.
+                */
+               if (reg.type == BRW_REGISTER_TYPE_V) {
+                       assert(hstride_for_reg[insn->bits1.da1.dest_horiz_stride] *
+                              reg_type_size[insn->bits1.da1.dest_reg_type] == 2);
+               }
+
+               return;
+       }
+
+       if (reg.file == BRW_ARCHITECTURE_REGISTER_FILE &&
+           reg.file == BRW_ARF_NULL)
+               return;
+
+       hstride = hstride_for_reg[reg.hstride];
+
+       if (reg.vstride == 0xf) {
+               vstride = -1;
+       } else {
+               vstride = vstride_for_reg[reg.vstride];
+       }
+
+       width = width_for_reg[reg.width];
+
+       execsize = execsize_for_reg[insn->header.execution_size];
+
+       /* Restrictions from 3.3.10: Register Region Restrictions. */
+       /* 3. */
+       assert(execsize >= width);
+
+       /* 4. */
+       if (execsize == width && hstride != 0) {
+               assert(vstride == -1 || vstride == width * hstride);
+       }
+
+       /* 5. */
+       if (execsize == width && hstride == 0) {
+               /* no restriction on vstride. */
+       }
+
+       /* 6. */
+       if (width == 1) {
+               assert(hstride == 0);
+       }
+
+       /* 7. */
+       if (execsize == 1 && width == 1) {
+               assert(hstride == 0);
+               assert(vstride == 0);
+       }
+
+       /* 8. */
+       if (vstride == 0 && hstride == 0) {
+               assert(width == 1);
+       }
+
+       /* 10. Check destination issues. */
+}
+
+void
+brw_set_src0(struct brw_compile *p, struct brw_instruction *insn,
+            struct brw_reg reg)
+{
+       if (reg.type != BRW_ARCHITECTURE_REGISTER_FILE)
+               assert(reg.nr < 128);
+
+       gen7_convert_mrf_to_grf(p, &reg);
+
+       validate_reg(insn, reg);
+
+       insn->bits1.da1.src0_reg_file = reg.file;
+       insn->bits1.da1.src0_reg_type = reg.type;
+       insn->bits2.da1.src0_abs = reg.abs;
+       insn->bits2.da1.src0_negate = reg.negate;
+       insn->bits2.da1.src0_address_mode = reg.address_mode;
+
+       if (reg.file == BRW_IMMEDIATE_VALUE) {
+               insn->bits3.ud = reg.dw1.ud;
+
+               /* Required to set some fields in src1 as well:
+               */
+               insn->bits1.da1.src1_reg_file = 0; /* arf */
+               insn->bits1.da1.src1_reg_type = reg.type;
+       } else {
+               if (reg.address_mode == BRW_ADDRESS_DIRECT) {
+                       if (insn->header.access_mode == BRW_ALIGN_1) {
+                               insn->bits2.da1.src0_subreg_nr = reg.subnr;
+                               insn->bits2.da1.src0_reg_nr = reg.nr;
+                       } else {
+                               insn->bits2.da16.src0_subreg_nr = reg.subnr / 16;
+                               insn->bits2.da16.src0_reg_nr = reg.nr;
+                       }
+               } else {
+                       insn->bits2.ia1.src0_subreg_nr = reg.subnr;
+
+                       if (insn->header.access_mode == BRW_ALIGN_1) {
+                               insn->bits2.ia1.src0_indirect_offset = reg.dw1.bits.indirect_offset;
+                       } else {
+                               insn->bits2.ia16.src0_subreg_nr = reg.dw1.bits.indirect_offset;
+                       }
+               }
+
+               if (insn->header.access_mode == BRW_ALIGN_1) {
+                       if (reg.width == BRW_WIDTH_1 &&
+                           insn->header.execution_size == BRW_EXECUTE_1) {
+                               insn->bits2.da1.src0_horiz_stride = BRW_HORIZONTAL_STRIDE_0;
+                               insn->bits2.da1.src0_width = BRW_WIDTH_1;
+                               insn->bits2.da1.src0_vert_stride = BRW_VERTICAL_STRIDE_0;
+                       } else {
+                               insn->bits2.da1.src0_horiz_stride = reg.hstride;
+                               insn->bits2.da1.src0_width = reg.width;
+                               insn->bits2.da1.src0_vert_stride = reg.vstride;
+                       }
+               } else {
+                       insn->bits2.da16.src0_swz_x = BRW_GET_SWZ(reg.dw1.bits.swizzle, BRW_CHANNEL_X);
+                       insn->bits2.da16.src0_swz_y = BRW_GET_SWZ(reg.dw1.bits.swizzle, BRW_CHANNEL_Y);
+                       insn->bits2.da16.src0_swz_z = BRW_GET_SWZ(reg.dw1.bits.swizzle, BRW_CHANNEL_Z);
+                       insn->bits2.da16.src0_swz_w = BRW_GET_SWZ(reg.dw1.bits.swizzle, BRW_CHANNEL_W);
+
+                       /* This is an oddity of the fact we're using the same
+                        * descriptions for registers in align_16 as align_1:
+                        */
+                       if (reg.vstride == BRW_VERTICAL_STRIDE_8)
+                               insn->bits2.da16.src0_vert_stride = BRW_VERTICAL_STRIDE_4;
+                       else
+                               insn->bits2.da16.src0_vert_stride = reg.vstride;
+               }
+       }
+}
+
+void brw_set_src1(struct brw_compile *p,
+                 struct brw_instruction *insn,
+                 struct brw_reg reg)
+{
+       assert(reg.file != BRW_MESSAGE_REGISTER_FILE);
+       assert(reg.nr < 128);
+
+       gen7_convert_mrf_to_grf(p, &reg);
+
+       validate_reg(insn, reg);
+
+       insn->bits1.da1.src1_reg_file = reg.file;
+       insn->bits1.da1.src1_reg_type = reg.type;
+       insn->bits3.da1.src1_abs = reg.abs;
+       insn->bits3.da1.src1_negate = reg.negate;
+
+       /* Only src1 can be immediate in two-argument instructions. */
+       assert(insn->bits1.da1.src0_reg_file != BRW_IMMEDIATE_VALUE);
+
+       if (reg.file == BRW_IMMEDIATE_VALUE) {
+               insn->bits3.ud = reg.dw1.ud;
+       } else {
+               /* This is a hardware restriction, which may or may not be lifted
+                * in the future:
+                */
+               assert (reg.address_mode == BRW_ADDRESS_DIRECT);
+               /* assert (reg.file == BRW_GENERAL_REGISTER_FILE); */
+
+               if (insn->header.access_mode == BRW_ALIGN_1) {
+                       insn->bits3.da1.src1_subreg_nr = reg.subnr;
+                       insn->bits3.da1.src1_reg_nr = reg.nr;
+               } else {
+                       insn->bits3.da16.src1_subreg_nr = reg.subnr / 16;
+                       insn->bits3.da16.src1_reg_nr = reg.nr;
+               }
+
+               if (insn->header.access_mode == BRW_ALIGN_1) {
+                       if (reg.width == BRW_WIDTH_1 &&
+                           insn->header.execution_size == BRW_EXECUTE_1) {
+                               insn->bits3.da1.src1_horiz_stride = BRW_HORIZONTAL_STRIDE_0;
+                               insn->bits3.da1.src1_width = BRW_WIDTH_1;
+                               insn->bits3.da1.src1_vert_stride = BRW_VERTICAL_STRIDE_0;
+                       } else {
+                               insn->bits3.da1.src1_horiz_stride = reg.hstride;
+                               insn->bits3.da1.src1_width = reg.width;
+                               insn->bits3.da1.src1_vert_stride = reg.vstride;
+                       }
+               } else {
+                       insn->bits3.da16.src1_swz_x = BRW_GET_SWZ(reg.dw1.bits.swizzle, BRW_CHANNEL_X);
+                       insn->bits3.da16.src1_swz_y = BRW_GET_SWZ(reg.dw1.bits.swizzle, BRW_CHANNEL_Y);
+                       insn->bits3.da16.src1_swz_z = BRW_GET_SWZ(reg.dw1.bits.swizzle, BRW_CHANNEL_Z);
+                       insn->bits3.da16.src1_swz_w = BRW_GET_SWZ(reg.dw1.bits.swizzle, BRW_CHANNEL_W);
+
+                       /* This is an oddity of the fact we're using the same
+                        * descriptions for registers in align_16 as align_1:
+                        */
+                       if (reg.vstride == BRW_VERTICAL_STRIDE_8)
+                               insn->bits3.da16.src1_vert_stride = BRW_VERTICAL_STRIDE_4;
+                       else
+                               insn->bits3.da16.src1_vert_stride = reg.vstride;
+               }
+       }
+}
+
+/**
+ * Set the Message Descriptor and Extended Message Descriptor fields
+ * for SEND messages.
+ *
+ * \note This zeroes out the Function Control bits, so it must be called
+ *       \b before filling out any message-specific data.  Callers can
+ *       choose not to fill in irrelevant bits; they will be zero.
+ */
+static void
+brw_set_message_descriptor(struct brw_compile *p,
+                          struct brw_instruction *inst,
+                          enum brw_message_target sfid,
+                          unsigned msg_length,
+                          unsigned response_length,
+                          bool header_present,
+                          bool end_of_thread)
+{
+       brw_set_src1(p, inst, brw_imm_d(0));
+
+       if (p->gen >= 50) {
+               inst->bits3.generic_gen5.header_present = header_present;
+               inst->bits3.generic_gen5.response_length = response_length;
+               inst->bits3.generic_gen5.msg_length = msg_length;
+               inst->bits3.generic_gen5.end_of_thread = end_of_thread;
+
+               if (p->gen >= 60) {
+                       /* On Gen6+ Message target/SFID goes in bits 27:24 of the header */
+                       inst->header.destreg__conditionalmod = sfid;
+               } else {
+                       /* Set Extended Message Descriptor (ex_desc) */
+                       inst->bits2.send_gen5.sfid = sfid;
+                       inst->bits2.send_gen5.end_of_thread = end_of_thread;
+               }
+       } else {
+               inst->bits3.generic.response_length = response_length;
+               inst->bits3.generic.msg_length = msg_length;
+               inst->bits3.generic.msg_target = sfid;
+               inst->bits3.generic.end_of_thread = end_of_thread;
+       }
+}
+
+
+static void brw_set_math_message(struct brw_compile *p,
+                                struct brw_instruction *insn,
+                                unsigned function,
+                                unsigned integer_type,
+                                bool low_precision,
+                                bool saturate,
+                                unsigned dataType)
+{
+       unsigned msg_length;
+       unsigned response_length;
+
+       /* Infer message length from the function */
+       switch (function) {
+       case BRW_MATH_FUNCTION_POW:
+       case BRW_MATH_FUNCTION_INT_DIV_QUOTIENT:
+       case BRW_MATH_FUNCTION_INT_DIV_REMAINDER:
+       case BRW_MATH_FUNCTION_INT_DIV_QUOTIENT_AND_REMAINDER:
+               msg_length = 2;
+               break;
+       default:
+               msg_length = 1;
+               break;
+       }
+
+       /* Infer response length from the function */
+       switch (function) {
+       case BRW_MATH_FUNCTION_SINCOS:
+       case BRW_MATH_FUNCTION_INT_DIV_QUOTIENT_AND_REMAINDER:
+               response_length = 2;
+               break;
+       default:
+               response_length = 1;
+               break;
+       }
+
+       brw_set_message_descriptor(p, insn, BRW_SFID_MATH,
+                                  msg_length, response_length,
+                                  false, false);
+       if (p->gen == 50) {
+               insn->bits3.math_gen5.function = function;
+               insn->bits3.math_gen5.int_type = integer_type;
+               insn->bits3.math_gen5.precision = low_precision;
+               insn->bits3.math_gen5.saturate = saturate;
+               insn->bits3.math_gen5.data_type = dataType;
+               insn->bits3.math_gen5.snapshot = 0;
+       } else {
+               insn->bits3.math.function = function;
+               insn->bits3.math.int_type = integer_type;
+               insn->bits3.math.precision = low_precision;
+               insn->bits3.math.saturate = saturate;
+               insn->bits3.math.data_type = dataType;
+       }
+}
+
+static void brw_set_ff_sync_message(struct brw_compile *p,
+                                   struct brw_instruction *insn,
+                                   bool allocate,
+                                   unsigned response_length,
+                                   bool end_of_thread)
+{
+       brw_set_message_descriptor(p, insn, BRW_SFID_URB,
+                                  1, response_length,
+                                  true, end_of_thread);
+       insn->bits3.urb_gen5.opcode = 1; /* FF_SYNC */
+       insn->bits3.urb_gen5.offset = 0; /* Not used by FF_SYNC */
+       insn->bits3.urb_gen5.swizzle_control = 0; /* Not used by FF_SYNC */
+       insn->bits3.urb_gen5.allocate = allocate;
+       insn->bits3.urb_gen5.used = 0; /* Not used by FF_SYNC */
+       insn->bits3.urb_gen5.complete = 0; /* Not used by FF_SYNC */
+}
+
+static void brw_set_urb_message(struct brw_compile *p,
+                               struct brw_instruction *insn,
+                               bool allocate,
+                               bool used,
+                               unsigned msg_length,
+                               unsigned response_length,
+                               bool end_of_thread,
+                               bool complete,
+                               unsigned offset,
+                               unsigned swizzle_control)
+{
+       brw_set_message_descriptor(p, insn, BRW_SFID_URB,
+                                  msg_length, response_length, true, end_of_thread);
+       if (p->gen >= 70) {
+               insn->bits3.urb_gen7.opcode = 0;        /* URB_WRITE_HWORD */
+               insn->bits3.urb_gen7.offset = offset;
+               assert(swizzle_control != BRW_URB_SWIZZLE_TRANSPOSE);
+               insn->bits3.urb_gen7.swizzle_control = swizzle_control;
+               /* per_slot_offset = 0 makes it ignore offsets in message header */
+               insn->bits3.urb_gen7.per_slot_offset = 0;
+               insn->bits3.urb_gen7.complete = complete;
+       } else if (p->gen >= 50) {
+               insn->bits3.urb_gen5.opcode = 0;        /* URB_WRITE */
+               insn->bits3.urb_gen5.offset = offset;
+               insn->bits3.urb_gen5.swizzle_control = swizzle_control;
+               insn->bits3.urb_gen5.allocate = allocate;
+               insn->bits3.urb_gen5.used = used;       /* ? */
+               insn->bits3.urb_gen5.complete = complete;
+       } else {
+               insn->bits3.urb.opcode = 0;     /* ? */
+               insn->bits3.urb.offset = offset;
+               insn->bits3.urb.swizzle_control = swizzle_control;
+               insn->bits3.urb.allocate = allocate;
+               insn->bits3.urb.used = used;    /* ? */
+               insn->bits3.urb.complete = complete;
+       }
+}
+
+void
+brw_set_dp_write_message(struct brw_compile *p,
+                        struct brw_instruction *insn,
+                        unsigned binding_table_index,
+                        unsigned msg_control,
+                        unsigned msg_type,
+                        unsigned msg_length,
+                        bool header_present,
+                        bool last_render_target,
+                        unsigned response_length,
+                        bool end_of_thread,
+                        bool send_commit_msg)
+{
+       unsigned sfid;
+
+       if (p->gen >= 70) {
+               /* Use the Render Cache for RT writes; otherwise use the Data Cache */
+               if (msg_type == GEN6_DATAPORT_WRITE_MESSAGE_RENDER_TARGET_WRITE)
+                       sfid = GEN6_SFID_DATAPORT_RENDER_CACHE;
+               else
+                       sfid = GEN7_SFID_DATAPORT_DATA_CACHE;
+       } else if (p->gen >= 60) {
+               /* Use the render cache for all write messages. */
+               sfid = GEN6_SFID_DATAPORT_RENDER_CACHE;
+       } else {
+               sfid = BRW_SFID_DATAPORT_WRITE;
+       }
+
+       brw_set_message_descriptor(p, insn, sfid,
+                                  msg_length, response_length,
+                                  header_present, end_of_thread);
+
+       if (p->gen >= 70) {
+               insn->bits3.gen7_dp.binding_table_index = binding_table_index;
+               insn->bits3.gen7_dp.msg_control = msg_control;
+               insn->bits3.gen7_dp.last_render_target = last_render_target;
+               insn->bits3.gen7_dp.msg_type = msg_type;
+       } else if (p->gen >= 60) {
+               insn->bits3.gen6_dp.binding_table_index = binding_table_index;
+               insn->bits3.gen6_dp.msg_control = msg_control;
+               insn->bits3.gen6_dp.last_render_target = last_render_target;
+               insn->bits3.gen6_dp.msg_type = msg_type;
+               insn->bits3.gen6_dp.send_commit_msg = send_commit_msg;
+       } else if (p->gen >= 50) {
+               insn->bits3.dp_write_gen5.binding_table_index = binding_table_index;
+               insn->bits3.dp_write_gen5.msg_control = msg_control;
+               insn->bits3.dp_write_gen5.last_render_target = last_render_target;
+               insn->bits3.dp_write_gen5.msg_type = msg_type;
+               insn->bits3.dp_write_gen5.send_commit_msg = send_commit_msg;
+       } else {
+               insn->bits3.dp_write.binding_table_index = binding_table_index;
+               insn->bits3.dp_write.msg_control = msg_control;
+               insn->bits3.dp_write.last_render_target = last_render_target;
+               insn->bits3.dp_write.msg_type = msg_type;
+               insn->bits3.dp_write.send_commit_msg = send_commit_msg;
+       }
+}
+
+void
+brw_set_dp_read_message(struct brw_compile *p,
+                       struct brw_instruction *insn,
+                       unsigned binding_table_index,
+                       unsigned msg_control,
+                       unsigned msg_type,
+                       unsigned target_cache,
+                       unsigned msg_length,
+                       unsigned response_length)
+{
+       unsigned sfid;
+
+       if (p->gen >= 70) {
+               sfid = GEN7_SFID_DATAPORT_DATA_CACHE;
+       } else if (p->gen >= 60) {
+               if (target_cache == BRW_DATAPORT_READ_TARGET_RENDER_CACHE)
+                       sfid = GEN6_SFID_DATAPORT_RENDER_CACHE;
+               else
+                       sfid = GEN6_SFID_DATAPORT_SAMPLER_CACHE;
+       } else {
+               sfid = BRW_SFID_DATAPORT_READ;
+       }
+
+       brw_set_message_descriptor(p, insn, sfid,
+                                  msg_length, response_length,
+                                  true, false);
+
+       if (p->gen >= 70) {
+               insn->bits3.gen7_dp.binding_table_index = binding_table_index;
+               insn->bits3.gen7_dp.msg_control = msg_control;
+               insn->bits3.gen7_dp.last_render_target = 0;
+               insn->bits3.gen7_dp.msg_type = msg_type;
+       } else if (p->gen >= 60) {
+               insn->bits3.gen6_dp.binding_table_index = binding_table_index;
+               insn->bits3.gen6_dp.msg_control = msg_control;
+               insn->bits3.gen6_dp.last_render_target = 0;
+               insn->bits3.gen6_dp.msg_type = msg_type;
+               insn->bits3.gen6_dp.send_commit_msg = 0;
+       } else if (p->gen >= 50) {
+               insn->bits3.dp_read_gen5.binding_table_index = binding_table_index;
+               insn->bits3.dp_read_gen5.msg_control = msg_control;
+               insn->bits3.dp_read_gen5.msg_type = msg_type;
+               insn->bits3.dp_read_gen5.target_cache = target_cache;
+       } else if (p->gen >= 45) {
+               insn->bits3.dp_read_g4x.binding_table_index = binding_table_index; /*0:7*/
+               insn->bits3.dp_read_g4x.msg_control = msg_control;  /*8:10*/
+               insn->bits3.dp_read_g4x.msg_type = msg_type;  /*11:13*/
+               insn->bits3.dp_read_g4x.target_cache = target_cache;  /*14:15*/
+       } else {
+               insn->bits3.dp_read.binding_table_index = binding_table_index; /*0:7*/
+               insn->bits3.dp_read.msg_control = msg_control;  /*8:11*/
+               insn->bits3.dp_read.msg_type = msg_type;  /*12:13*/
+               insn->bits3.dp_read.target_cache = target_cache;  /*14:15*/
+       }
+}
+
+static void brw_set_sampler_message(struct brw_compile *p,
+                                    struct brw_instruction *insn,
+                                    unsigned binding_table_index,
+                                    unsigned sampler,
+                                    unsigned msg_type,
+                                    unsigned response_length,
+                                    unsigned msg_length,
+                                    bool header_present,
+                                    unsigned simd_mode)
+{
+       brw_set_message_descriptor(p, insn, BRW_SFID_SAMPLER,
+                                  msg_length, response_length,
+                                  header_present, false);
+
+       if (p->gen >= 70) {
+               insn->bits3.sampler_gen7.binding_table_index = binding_table_index;
+               insn->bits3.sampler_gen7.sampler = sampler;
+               insn->bits3.sampler_gen7.msg_type = msg_type;
+               insn->bits3.sampler_gen7.simd_mode = simd_mode;
+       } else if (p->gen >= 50) {
+               insn->bits3.sampler_gen5.binding_table_index = binding_table_index;
+               insn->bits3.sampler_gen5.sampler = sampler;
+               insn->bits3.sampler_gen5.msg_type = msg_type;
+               insn->bits3.sampler_gen5.simd_mode = simd_mode;
+       } else if (p->gen >= 45) {
+               insn->bits3.sampler_g4x.binding_table_index = binding_table_index;
+               insn->bits3.sampler_g4x.sampler = sampler;
+               insn->bits3.sampler_g4x.msg_type = msg_type;
+       } else {
+               insn->bits3.sampler.binding_table_index = binding_table_index;
+               insn->bits3.sampler.sampler = sampler;
+               insn->bits3.sampler.msg_type = msg_type;
+               insn->bits3.sampler.return_format = BRW_SAMPLER_RETURN_FORMAT_FLOAT32;
+       }
+}
+
+
+void brw_NOP(struct brw_compile *p)
+{
+       struct brw_instruction *insn = brw_next_insn(p, BRW_OPCODE_NOP);
+       brw_set_dest(p, insn, __retype_ud(brw_vec4_grf(0,0)));
+       brw_set_src0(p, insn, __retype_ud(brw_vec4_grf(0,0)));
+       brw_set_src1(p, insn, brw_imm_ud(0x0));
+}
+
+/***********************************************************************
+ * Comparisons, if/else/endif
+ */
+
+static void
+push_if_stack(struct brw_compile *p, struct brw_instruction *inst)
+{
+       p->if_stack[p->if_stack_depth] = inst;
+
+       p->if_stack_depth++;
+       if (p->if_stack_array_size <= p->if_stack_depth) {
+               p->if_stack_array_size *= 2;
+               p->if_stack = realloc(p->if_stack, sizeof(struct brw_instruction *)*p->if_stack_array_size);
+       }
+}
+
+/* EU takes the value from the flag register and pushes it onto some
+ * sort of a stack (presumably merging with any flag value already on
+ * the stack).  Within an if block, the flags at the top of the stack
+ * control execution on each channel of the unit, eg. on each of the
+ * 16 pixel values in our wm programs.
+ *
+ * When the matching 'else' instruction is reached (presumably by
+ * countdown of the instruction count patched in by our ELSE/ENDIF
+ * functions), the relevent flags are inverted.
+ *
+ * When the matching 'endif' instruction is reached, the flags are
+ * popped off.  If the stack is now empty, normal execution resumes.
+ */
+struct brw_instruction *
+brw_IF(struct brw_compile *p, unsigned execute_size)
+{
+       struct brw_instruction *insn;
+
+       insn = brw_next_insn(p, BRW_OPCODE_IF);
+
+       /* Override the defaults for this instruction: */
+       if (p->gen < 60) {
+               brw_set_dest(p, insn, brw_ip_reg());
+               brw_set_src0(p, insn, brw_ip_reg());
+               brw_set_src1(p, insn, brw_imm_d(0x0));
+       } else if (p->gen < 70) {
+               brw_set_dest(p, insn, brw_imm_w(0));
+               insn->bits1.branch_gen6.jump_count = 0;
+               brw_set_src0(p, insn, __retype_d(brw_null_reg()));
+               brw_set_src1(p, insn, __retype_d(brw_null_reg()));
+       } else {
+               brw_set_dest(p, insn, __retype_d(brw_null_reg()));
+               brw_set_src0(p, insn, __retype_d(brw_null_reg()));
+               brw_set_src1(p, insn, brw_imm_ud(0));
+               insn->bits3.break_cont.jip = 0;
+               insn->bits3.break_cont.uip = 0;
+       }
+
+       insn->header.execution_size = execute_size;
+       insn->header.compression_control = BRW_COMPRESSION_NONE;
+       insn->header.predicate_control = BRW_PREDICATE_NORMAL;
+       insn->header.mask_control = BRW_MASK_ENABLE;
+       if (!p->single_program_flow)
+               insn->header.thread_control = BRW_THREAD_SWITCH;
+
+       p->current->header.predicate_control = BRW_PREDICATE_NONE;
+
+       push_if_stack(p, insn);
+       return insn;
+}
+
+/* This function is only used for gen6-style IF instructions with an
+ * embedded comparison (conditional modifier).  It is not used on gen7.
+ */
+struct brw_instruction *
+gen6_IF(struct brw_compile *p, uint32_t conditional,
+       struct brw_reg src0, struct brw_reg src1)
+{
+       struct brw_instruction *insn;
+
+       insn = brw_next_insn(p, BRW_OPCODE_IF);
+
+       brw_set_dest(p, insn, brw_imm_w(0));
+       if (p->compressed) {
+               insn->header.execution_size = BRW_EXECUTE_16;
+       } else {
+               insn->header.execution_size = BRW_EXECUTE_8;
+       }
+       insn->bits1.branch_gen6.jump_count = 0;
+       brw_set_src0(p, insn, src0);
+       brw_set_src1(p, insn, src1);
+
+       assert(insn->header.compression_control == BRW_COMPRESSION_NONE);
+       assert(insn->header.predicate_control == BRW_PREDICATE_NONE);
+       insn->header.destreg__conditionalmod = conditional;
+
+       if (!p->single_program_flow)
+               insn->header.thread_control = BRW_THREAD_SWITCH;
+
+       push_if_stack(p, insn);
+       return insn;
+}
+
+/**
+ * In single-program-flow (SPF) mode, convert IF and ELSE into ADDs.
+ */
+static void
+convert_IF_ELSE_to_ADD(struct brw_compile *p,
+                      struct brw_instruction *if_inst,
+                      struct brw_instruction *else_inst)
+{
+       /* The next instruction (where the ENDIF would be, if it existed) */
+       struct brw_instruction *next_inst = &p->store[p->nr_insn];
+
+       assert(p->single_program_flow);
+       assert(if_inst != NULL && if_inst->header.opcode == BRW_OPCODE_IF);
+       assert(else_inst == NULL || else_inst->header.opcode == BRW_OPCODE_ELSE);
+       assert(if_inst->header.execution_size == BRW_EXECUTE_1);
+
+       /* Convert IF to an ADD instruction that moves the instruction pointer
+        * to the first instruction of the ELSE block.  If there is no ELSE
+        * block, point to where ENDIF would be.  Reverse the predicate.
+        *
+        * There's no need to execute an ENDIF since we don't need to do any
+        * stack operations, and if we're currently executing, we just want to
+        * continue normally.
+        */
+       if_inst->header.opcode = BRW_OPCODE_ADD;
+       if_inst->header.predicate_inverse = 1;
+
+       if (else_inst != NULL) {
+               /* Convert ELSE to an ADD instruction that points where the ENDIF
+                * would be.
+                */
+               else_inst->header.opcode = BRW_OPCODE_ADD;
+
+               if_inst->bits3.ud = (else_inst - if_inst + 1) * 16;
+               else_inst->bits3.ud = (next_inst - else_inst) * 16;
+       } else {
+               if_inst->bits3.ud = (next_inst - if_inst) * 16;
+       }
+}
+
+/**
+ * Patch IF and ELSE instructions with appropriate jump targets.
+ */
+static void
+patch_IF_ELSE(struct brw_compile *p,
+             struct brw_instruction *if_inst,
+             struct brw_instruction *else_inst,
+             struct brw_instruction *endif_inst)
+{
+       unsigned br = 1;
+
+       assert(!p->single_program_flow);
+       assert(if_inst != NULL && if_inst->header.opcode == BRW_OPCODE_IF);
+       assert(endif_inst != NULL);
+       assert(else_inst == NULL || else_inst->header.opcode == BRW_OPCODE_ELSE);
+
+       /* Jump count is for 64bit data chunk each, so one 128bit instruction
+        * requires 2 chunks.
+        */
+       if (p->gen >= 50)
+               br = 2;
+
+       assert(endif_inst->header.opcode == BRW_OPCODE_ENDIF);
+       endif_inst->header.execution_size = if_inst->header.execution_size;
+
+       if (else_inst == NULL) {
+               /* Patch IF -> ENDIF */
+               if (p->gen < 60) {
+                       /* Turn it into an IFF, which means no mask stack operations for
+                        * all-false and jumping past the ENDIF.
+                        */
+                       if_inst->header.opcode = BRW_OPCODE_IFF;
+                       if_inst->bits3.if_else.jump_count = br * (endif_inst - if_inst + 1);
+                       if_inst->bits3.if_else.pop_count = 0;
+                       if_inst->bits3.if_else.pad0 = 0;
+               } else if (p->gen < 70) {
+                       /* As of gen6, there is no IFF and IF must point to the ENDIF. */
+                       if_inst->bits1.branch_gen6.jump_count = br * (endif_inst - if_inst);
+               } else {
+                       if_inst->bits3.break_cont.uip = br * (endif_inst - if_inst);
+                       if_inst->bits3.break_cont.jip = br * (endif_inst - if_inst);
+               }
+       } else {
+               else_inst->header.execution_size = if_inst->header.execution_size;
+
+               /* Patch IF -> ELSE */
+               if (p->gen < 60) {
+                       if_inst->bits3.if_else.jump_count = br * (else_inst - if_inst);
+                       if_inst->bits3.if_else.pop_count = 0;
+                       if_inst->bits3.if_else.pad0 = 0;
+               } else if (p->gen <= 70) {
+                       if_inst->bits1.branch_gen6.jump_count = br * (else_inst - if_inst + 1);
+               }
+
+               /* Patch ELSE -> ENDIF */
+               if (p->gen < 60) {
+                       /* BRW_OPCODE_ELSE pre-gen6 should point just past the
+                        * matching ENDIF.
+                        */
+                       else_inst->bits3.if_else.jump_count = br*(endif_inst - else_inst + 1);
+                       else_inst->bits3.if_else.pop_count = 1;
+                       else_inst->bits3.if_else.pad0 = 0;
+               } else if (p->gen < 70) {
+                       /* BRW_OPCODE_ELSE on gen6 should point to the matching ENDIF. */
+                       else_inst->bits1.branch_gen6.jump_count = br*(endif_inst - else_inst);
+               } else {
+                       /* The IF instruction's JIP should point just past the ELSE */
+                       if_inst->bits3.break_cont.jip = br * (else_inst - if_inst + 1);
+                       /* The IF instruction's UIP and ELSE's JIP should point to ENDIF */
+                       if_inst->bits3.break_cont.uip = br * (endif_inst - if_inst);
+                       else_inst->bits3.break_cont.jip = br * (endif_inst - else_inst);
+               }
+       }
+}
+
+void
+brw_ELSE(struct brw_compile *p)
+{
+       struct brw_instruction *insn;
+
+       insn = brw_next_insn(p, BRW_OPCODE_ELSE);
+
+       if (p->gen < 60) {
+               brw_set_dest(p, insn, brw_ip_reg());
+               brw_set_src0(p, insn, brw_ip_reg());
+               brw_set_src1(p, insn, brw_imm_d(0x0));
+       } else if (p->gen < 70) {
+               brw_set_dest(p, insn, brw_imm_w(0));
+               insn->bits1.branch_gen6.jump_count = 0;
+               brw_set_src0(p, insn, __retype_d(brw_null_reg()));
+               brw_set_src1(p, insn, __retype_d(brw_null_reg()));
+       } else {
+               brw_set_dest(p, insn, __retype_d(brw_null_reg()));
+               brw_set_src0(p, insn, __retype_d(brw_null_reg()));
+               brw_set_src1(p, insn, brw_imm_ud(0));
+               insn->bits3.break_cont.jip = 0;
+               insn->bits3.break_cont.uip = 0;
+       }
+
+       insn->header.compression_control = BRW_COMPRESSION_NONE;
+       insn->header.mask_control = BRW_MASK_ENABLE;
+       if (!p->single_program_flow)
+               insn->header.thread_control = BRW_THREAD_SWITCH;
+
+       push_if_stack(p, insn);
+}
+
+void
+brw_ENDIF(struct brw_compile *p)
+{
+       struct brw_instruction *insn;
+       struct brw_instruction *else_inst = NULL;
+       struct brw_instruction *if_inst = NULL;
+
+       /* Pop the IF and (optional) ELSE instructions from the stack */
+       p->if_stack_depth--;
+       if (p->if_stack[p->if_stack_depth]->header.opcode == BRW_OPCODE_ELSE) {
+               else_inst = p->if_stack[p->if_stack_depth];
+               p->if_stack_depth--;
+       }
+       if_inst = p->if_stack[p->if_stack_depth];
+
+       if (p->single_program_flow) {
+               /* ENDIF is useless; don't bother emitting it. */
+               convert_IF_ELSE_to_ADD(p, if_inst, else_inst);
+               return;
+       }
+
+       insn = brw_next_insn(p, BRW_OPCODE_ENDIF);
+
+       if (p->gen < 60) {
+               brw_set_dest(p, insn, __retype_ud(brw_vec4_grf(0,0)));
+               brw_set_src0(p, insn, __retype_ud(brw_vec4_grf(0,0)));
+               brw_set_src1(p, insn, brw_imm_d(0x0));
+       } else if (p->gen < 70) {
+               brw_set_dest(p, insn, brw_imm_w(0));
+               brw_set_src0(p, insn, __retype_d(brw_null_reg()));
+               brw_set_src1(p, insn, __retype_d(brw_null_reg()));
+       } else {
+               brw_set_dest(p, insn, __retype_d(brw_null_reg()));
+               brw_set_src0(p, insn, __retype_d(brw_null_reg()));
+               brw_set_src1(p, insn, brw_imm_ud(0));
+       }
+
+       insn->header.compression_control = BRW_COMPRESSION_NONE;
+       insn->header.mask_control = BRW_MASK_ENABLE;
+       insn->header.thread_control = BRW_THREAD_SWITCH;
+
+       /* Also pop item off the stack in the endif instruction: */
+       if (p->gen < 60) {
+               insn->bits3.if_else.jump_count = 0;
+               insn->bits3.if_else.pop_count = 1;
+               insn->bits3.if_else.pad0 = 0;
+       } else if (p->gen < 70) {
+               insn->bits1.branch_gen6.jump_count = 2;
+       } else {
+               insn->bits3.break_cont.jip = 2;
+       }
+       patch_IF_ELSE(p, if_inst, else_inst, insn);
+}
+
+struct brw_instruction *brw_BREAK(struct brw_compile *p, int pop_count)
+{
+       struct brw_instruction *insn;
+
+       insn = brw_next_insn(p, BRW_OPCODE_BREAK);
+       if (p->gen >= 60) {
+               brw_set_dest(p, insn, __retype_d(brw_null_reg()));
+               brw_set_src0(p, insn, __retype_d(brw_null_reg()));
+               brw_set_src1(p, insn, brw_imm_d(0x0));
+       } else {
+               brw_set_dest(p, insn, brw_ip_reg());
+               brw_set_src0(p, insn, brw_ip_reg());
+               brw_set_src1(p, insn, brw_imm_d(0x0));
+               insn->bits3.if_else.pad0 = 0;
+               insn->bits3.if_else.pop_count = pop_count;
+       }
+       insn->header.compression_control = BRW_COMPRESSION_NONE;
+       insn->header.execution_size = BRW_EXECUTE_8;
+
+       return insn;
+}
+
+struct brw_instruction *gen6_CONT(struct brw_compile *p,
+                                 struct brw_instruction *do_insn)
+{
+       struct brw_instruction *insn;
+
+       insn = brw_next_insn(p, BRW_OPCODE_CONTINUE);
+       brw_set_dest(p, insn, __retype_d(brw_null_reg()));
+       brw_set_src0(p, insn, __retype_d(brw_null_reg()));
+       brw_set_dest(p, insn, brw_ip_reg());
+       brw_set_src0(p, insn, brw_ip_reg());
+       brw_set_src1(p, insn, brw_imm_d(0x0));
+
+       insn->header.compression_control = BRW_COMPRESSION_NONE;
+       insn->header.execution_size = BRW_EXECUTE_8;
+       return insn;
+}
+
+struct brw_instruction *brw_CONT(struct brw_compile *p, int pop_count)
+{
+       struct brw_instruction *insn;
+       insn = brw_next_insn(p, BRW_OPCODE_CONTINUE);
+       brw_set_dest(p, insn, brw_ip_reg());
+       brw_set_src0(p, insn, brw_ip_reg());
+       brw_set_src1(p, insn, brw_imm_d(0x0));
+       insn->header.compression_control = BRW_COMPRESSION_NONE;
+       insn->header.execution_size = BRW_EXECUTE_8;
+       /* insn->header.mask_control = BRW_MASK_DISABLE; */
+       insn->bits3.if_else.pad0 = 0;
+       insn->bits3.if_else.pop_count = pop_count;
+       return insn;
+}
+
+/* DO/WHILE loop:
+ *
+ * The DO/WHILE is just an unterminated loop -- break or continue are
+ * used for control within the loop.  We have a few ways they can be
+ * done.
+ *
+ * For uniform control flow, the WHILE is just a jump, so ADD ip, ip,
+ * jip and no DO instruction.
+ *
+ * For non-uniform control flow pre-gen6, there's a DO instruction to
+ * push the mask, and a WHILE to jump back, and BREAK to get out and
+ * pop the mask.
+ *
+ * For gen6, there's no more mask stack, so no need for DO.  WHILE
+ * just points back to the first instruction of the loop.
+ */
+struct brw_instruction *brw_DO(struct brw_compile *p, unsigned execute_size)
+{
+       if (p->gen >= 60 || p->single_program_flow) {
+               return &p->store[p->nr_insn];
+       } else {
+               struct brw_instruction *insn = brw_next_insn(p, BRW_OPCODE_DO);
+
+               /* Override the defaults for this instruction:
+               */
+               brw_set_dest(p, insn, brw_null_reg());
+               brw_set_src0(p, insn, brw_null_reg());
+               brw_set_src1(p, insn, brw_null_reg());
+
+               insn->header.compression_control = BRW_COMPRESSION_NONE;
+               insn->header.execution_size = execute_size;
+               insn->header.predicate_control = BRW_PREDICATE_NONE;
+               /* insn->header.mask_control = BRW_MASK_ENABLE; */
+               /* insn->header.mask_control = BRW_MASK_DISABLE; */
+
+               return insn;
+       }
+}
+
+struct brw_instruction *brw_WHILE(struct brw_compile *p,
+                                  struct brw_instruction *do_insn)
+{
+       struct brw_instruction *insn;
+       unsigned br = 1;
+
+       if (p->gen >= 50)
+               br = 2;
+
+       if (p->gen >= 70) {
+               insn = brw_next_insn(p, BRW_OPCODE_WHILE);
+
+               brw_set_dest(p, insn, __retype_d(brw_null_reg()));
+               brw_set_src0(p, insn, __retype_d(brw_null_reg()));
+               brw_set_src1(p, insn, brw_imm_ud(0));
+               insn->bits3.break_cont.jip = br * (do_insn - insn);
+
+               insn->header.execution_size = BRW_EXECUTE_8;
+       } else if (p->gen >= 60) {
+               insn = brw_next_insn(p, BRW_OPCODE_WHILE);
+
+               brw_set_dest(p, insn, brw_imm_w(0));
+               insn->bits1.branch_gen6.jump_count = br * (do_insn - insn);
+               brw_set_src0(p, insn, __retype_d(brw_null_reg()));
+               brw_set_src1(p, insn, __retype_d(brw_null_reg()));
+
+               insn->header.execution_size = BRW_EXECUTE_8;
+       } else {
+               if (p->single_program_flow) {
+                       insn = brw_next_insn(p, BRW_OPCODE_ADD);
+
+                       brw_set_dest(p, insn, brw_ip_reg());
+                       brw_set_src0(p, insn, brw_ip_reg());
+                       brw_set_src1(p, insn, brw_imm_d((do_insn - insn) * 16));
+                       insn->header.execution_size = BRW_EXECUTE_1;
+               } else {
+                       insn = brw_next_insn(p, BRW_OPCODE_WHILE);
+
+                       assert(do_insn->header.opcode == BRW_OPCODE_DO);
+
+                       brw_set_dest(p, insn, brw_ip_reg());
+                       brw_set_src0(p, insn, brw_ip_reg());
+                       brw_set_src1(p, insn, brw_imm_d(0));
+
+                       insn->header.execution_size = do_insn->header.execution_size;
+                       insn->bits3.if_else.jump_count = br * (do_insn - insn + 1);
+                       insn->bits3.if_else.pop_count = 0;
+                       insn->bits3.if_else.pad0 = 0;
+               }
+       }
+       insn->header.compression_control = BRW_COMPRESSION_NONE;
+       p->current->header.predicate_control = BRW_PREDICATE_NONE;
+
+       return insn;
+}
+
+/* FORWARD JUMPS:
+ */
+void brw_land_fwd_jump(struct brw_compile *p,
+                      struct brw_instruction *jmp_insn)
+{
+       struct brw_instruction *landing = &p->store[p->nr_insn];
+       unsigned jmpi = 1;
+
+       if (p->gen >= 50)
+               jmpi = 2;
+
+       assert(jmp_insn->header.opcode == BRW_OPCODE_JMPI);
+       assert(jmp_insn->bits1.da1.src1_reg_file == BRW_IMMEDIATE_VALUE);
+
+       jmp_insn->bits3.ud = jmpi * ((landing - jmp_insn) - 1);
+}
+
+
+
+/* To integrate with the above, it makes sense that the comparison
+ * instruction should populate the flag register.  It might be simpler
+ * just to use the flag reg for most WM tasks?
+ */
+void brw_CMP(struct brw_compile *p,
+            struct brw_reg dest,
+            unsigned conditional,
+            struct brw_reg src0,
+            struct brw_reg src1)
+{
+       struct brw_instruction *insn = brw_next_insn(p, BRW_OPCODE_CMP);
+
+       insn->header.destreg__conditionalmod = conditional;
+       brw_set_dest(p, insn, dest);
+       brw_set_src0(p, insn, src0);
+       brw_set_src1(p, insn, src1);
+
+       /* Make it so that future instructions will use the computed flag
+        * value until brw_set_predicate_control_flag_value() is called
+        * again.  
+        */
+       if (dest.file == BRW_ARCHITECTURE_REGISTER_FILE &&
+           dest.nr == 0) {
+               p->current->header.predicate_control = BRW_PREDICATE_NORMAL;
+               p->flag_value = 0xff;
+       }
+}
+
+/* Issue 'wait' instruction for n1, host could program MMIO
+   to wake up thread. */
+void brw_WAIT(struct brw_compile *p)
+{
+       struct brw_instruction *insn = brw_next_insn(p, BRW_OPCODE_WAIT);
+       struct brw_reg src = brw_notification_1_reg();
+
+       brw_set_dest(p, insn, src);
+       brw_set_src0(p, insn, src);
+       brw_set_src1(p, insn, brw_null_reg());
+       insn->header.execution_size = 0; /* must */
+       insn->header.predicate_control = 0;
+       insn->header.compression_control = 0;
+}
+
+/***********************************************************************
+ * Helpers for the various SEND message types:
+ */
+
+/** Extended math function, float[8].
+ */
+void brw_math(struct brw_compile *p,
+             struct brw_reg dest,
+             unsigned function,
+             unsigned saturate,
+             unsigned msg_reg_nr,
+             struct brw_reg src,
+             unsigned data_type,
+             unsigned precision)
+{
+       if (p->gen >= 60) {
+               struct brw_instruction *insn = brw_next_insn(p, BRW_OPCODE_MATH);
+
+               assert(dest.file == BRW_GENERAL_REGISTER_FILE);
+               assert(src.file == BRW_GENERAL_REGISTER_FILE);
+
+               assert(dest.hstride == BRW_HORIZONTAL_STRIDE_1);
+               assert(src.hstride == BRW_HORIZONTAL_STRIDE_1);
+
+               /* Source modifiers are ignored for extended math instructions. */
+               assert(!src.negate);
+               assert(!src.abs);
+
+               if (function != BRW_MATH_FUNCTION_INT_DIV_QUOTIENT &&
+                   function != BRW_MATH_FUNCTION_INT_DIV_QUOTIENT_AND_REMAINDER) {
+                       assert(src.type == BRW_REGISTER_TYPE_F);
+               }
+
+               /* Math is the same ISA format as other opcodes, except that CondModifier
+                * becomes FC[3:0] and ThreadCtrl becomes FC[5:4].
+                */
+               insn->header.destreg__conditionalmod = function;
+               insn->header.saturate = saturate;
+
+               brw_set_dest(p, insn, dest);
+               brw_set_src0(p, insn, src);
+               brw_set_src1(p, insn, brw_null_reg());
+       } else {
+               struct brw_instruction *insn = brw_next_insn(p, BRW_OPCODE_SEND);
+               /* Example code doesn't set predicate_control for send
+                * instructions.
+                */
+               insn->header.predicate_control = 0;
+               insn->header.destreg__conditionalmod = msg_reg_nr;
+
+               brw_set_dest(p, insn, dest);
+               brw_set_src0(p, insn, src);
+               brw_set_math_message(p, insn, function,
+                                    src.type == BRW_REGISTER_TYPE_D,
+                                    precision,
+                                    saturate,
+                                    data_type);
+       }
+}
+
+/** Extended math function, float[8].
+ */
+void brw_math2(struct brw_compile *p,
+              struct brw_reg dest,
+              unsigned function,
+              struct brw_reg src0,
+              struct brw_reg src1)
+{
+       struct brw_instruction *insn = brw_next_insn(p, BRW_OPCODE_MATH);
+
+       assert(dest.file == BRW_GENERAL_REGISTER_FILE);
+       assert(src0.file == BRW_GENERAL_REGISTER_FILE);
+       assert(src1.file == BRW_GENERAL_REGISTER_FILE);
+
+       assert(dest.hstride == BRW_HORIZONTAL_STRIDE_1);
+       assert(src0.hstride == BRW_HORIZONTAL_STRIDE_1);
+       assert(src1.hstride == BRW_HORIZONTAL_STRIDE_1);
+
+       if (function != BRW_MATH_FUNCTION_INT_DIV_QUOTIENT &&
+           function != BRW_MATH_FUNCTION_INT_DIV_QUOTIENT_AND_REMAINDER) {
+               assert(src0.type == BRW_REGISTER_TYPE_F);
+               assert(src1.type == BRW_REGISTER_TYPE_F);
+       }
+
+       /* Source modifiers are ignored for extended math instructions. */
+       assert(!src0.negate);
+       assert(!src0.abs);
+       assert(!src1.negate);
+       assert(!src1.abs);
+
+       /* Math is the same ISA format as other opcodes, except that CondModifier
+        * becomes FC[3:0] and ThreadCtrl becomes FC[5:4].
+        */
+       insn->header.destreg__conditionalmod = function;
+
+       brw_set_dest(p, insn, dest);
+       brw_set_src0(p, insn, src0);
+       brw_set_src1(p, insn, src1);
+}
+
+/**
+ * Extended math function, float[16].
+ * Use 2 send instructions.
+ */
+void brw_math_16(struct brw_compile *p,
+                struct brw_reg dest,
+                unsigned function,
+                unsigned saturate,
+                unsigned msg_reg_nr,
+                struct brw_reg src,
+                unsigned precision)
+{
+       struct brw_instruction *insn;
+
+       if (p->gen >= 60) {
+               insn = brw_next_insn(p, BRW_OPCODE_MATH);
+
+               /* Math is the same ISA format as other opcodes, except that CondModifier
+                * becomes FC[3:0] and ThreadCtrl becomes FC[5:4].
+                */
+               insn->header.destreg__conditionalmod = function;
+               insn->header.saturate = saturate;
+
+               /* Source modifiers are ignored for extended math instructions. */
+               assert(!src.negate);
+               assert(!src.abs);
+
+               brw_set_dest(p, insn, dest);
+               brw_set_src0(p, insn, src);
+               brw_set_src1(p, insn, brw_null_reg());
+               return;
+       }
+
+       /* First instruction:
+       */
+       brw_push_insn_state(p);
+       brw_set_predicate_control_flag_value(p, 0xff);
+       brw_set_compression_control(p, BRW_COMPRESSION_NONE);
+
+       insn = brw_next_insn(p, BRW_OPCODE_SEND);
+       insn->header.destreg__conditionalmod = msg_reg_nr;
+
+       brw_set_dest(p, insn, dest);
+       brw_set_src0(p, insn, src);
+       brw_set_math_message(p, insn, function,
+                            BRW_MATH_INTEGER_UNSIGNED,
+                            precision,
+                            saturate,
+                            BRW_MATH_DATA_VECTOR);
+
+       /* Second instruction:
+       */
+       insn = brw_next_insn(p, BRW_OPCODE_SEND);
+       insn->header.compression_control = BRW_COMPRESSION_2NDHALF;
+       insn->header.destreg__conditionalmod = msg_reg_nr+1;
+
+       brw_set_dest(p, insn, __offset(dest,1));
+       brw_set_src0(p, insn, src);
+       brw_set_math_message(p, insn, function,
+                            BRW_MATH_INTEGER_UNSIGNED,
+                            precision,
+                            saturate,
+                            BRW_MATH_DATA_VECTOR);
+
+       brw_pop_insn_state(p);
+}
+
+/**
+ * Write a block of OWORDs (half a GRF each) from the scratch buffer,
+ * using a constant offset per channel.
+ *
+ * The offset must be aligned to oword size (16 bytes).  Used for
+ * register spilling.
+ */
+void brw_oword_block_write_scratch(struct brw_compile *p,
+                                  struct brw_reg mrf,
+                                  int num_regs,
+                                  unsigned offset)
+{
+       uint32_t msg_control, msg_type;
+       int mlen;
+
+       if (p->gen >= 60)
+               offset /= 16;
+
+       mrf = __retype_ud(mrf);
+
+       if (num_regs == 1) {
+               msg_control = BRW_DATAPORT_OWORD_BLOCK_2_OWORDS;
+               mlen = 2;
+       } else {
+               msg_control = BRW_DATAPORT_OWORD_BLOCK_4_OWORDS;
+               mlen = 3;
+       }
+
+       /* Set up the message header.  This is g0, with g0.2 filled with
+        * the offset.  We don't want to leave our offset around in g0 or
+        * it'll screw up texture samples, so set it up inside the message
+        * reg.
+        */
+       {
+               brw_push_insn_state(p);
+               brw_set_mask_control(p, BRW_MASK_DISABLE);
+               brw_set_compression_control(p, BRW_COMPRESSION_NONE);
+
+               brw_MOV(p, mrf, __retype_ud(brw_vec8_grf(0, 0)));
+
+               /* set message header global offset field (reg 0, element 2) */
+               brw_MOV(p,
+                       __retype_ud(brw_vec1_reg(BRW_MESSAGE_REGISTER_FILE, mrf.nr, 2)),
+                       brw_imm_ud(offset));
+
+               brw_pop_insn_state(p);
+       }
+
+       {
+               struct brw_reg dest;
+               struct brw_instruction *insn = brw_next_insn(p, BRW_OPCODE_SEND);
+               int send_commit_msg;
+               struct brw_reg src_header = __retype_uw(brw_vec8_grf(0, 0));
+
+               if (insn->header.compression_control != BRW_COMPRESSION_NONE) {
+                       insn->header.compression_control = BRW_COMPRESSION_NONE;
+                       src_header = vec16(src_header);
+               }
+               assert(insn->header.predicate_control == BRW_PREDICATE_NONE);
+               insn->header.destreg__conditionalmod = mrf.nr;
+
+               /* Until gen6, writes followed by reads from the same location
+                * are not guaranteed to be ordered unless write_commit is set.
+                * If set, then a no-op write is issued to the destination
+                * register to set a dependency, and a read from the destination
+                * can be used to ensure the ordering.
+                *
+                * For gen6, only writes between different threads need ordering
+                * protection.  Our use of DP writes is all about register
+                * spilling within a thread.
+                */
+               if (p->gen >= 60) {
+                       dest = __retype_uw(vec16(brw_null_reg()));
+                       send_commit_msg = 0;
+               } else {
+                       dest = src_header;
+                       send_commit_msg = 1;
+               }
+
+               brw_set_dest(p, insn, dest);
+               if (p->gen >= 60) {
+                       brw_set_src0(p, insn, mrf);
+               } else {
+                       brw_set_src0(p, insn, brw_null_reg());
+               }
+
+               if (p->gen >= 60)
+                       msg_type = GEN6_DATAPORT_WRITE_MESSAGE_OWORD_BLOCK_WRITE;
+               else
+                       msg_type = BRW_DATAPORT_WRITE_MESSAGE_OWORD_BLOCK_WRITE;
+
+               brw_set_dp_write_message(p,
+                                        insn,
+                                        255, /* binding table index (255=stateless) */
+                                        msg_control,
+                                        msg_type,
+                                        mlen,
+                                        true, /* header_present */
+                                        0, /* pixel scoreboard */
+                                        send_commit_msg, /* response_length */
+                                        0, /* eot */
+                                        send_commit_msg);
+       }
+}
+
+
+/**
+ * Read a block of owords (half a GRF each) from the scratch buffer
+ * using a constant index per channel.
+ *
+ * Offset must be aligned to oword size (16 bytes).  Used for register
+ * spilling.
+ */
+void
+brw_oword_block_read_scratch(struct brw_compile *p,
+                            struct brw_reg dest,
+                            struct brw_reg mrf,
+                            int num_regs,
+                            unsigned offset)
+{
+       uint32_t msg_control;
+       int rlen;
+
+       if (p->gen >= 60)
+               offset /= 16;
+
+       mrf = __retype_ud(mrf);
+       dest = __retype_uw(dest);
+
+       if (num_regs == 1) {
+               msg_control = BRW_DATAPORT_OWORD_BLOCK_2_OWORDS;
+               rlen = 1;
+       } else {
+               msg_control = BRW_DATAPORT_OWORD_BLOCK_4_OWORDS;
+               rlen = 2;
+       }
+
+       {
+               brw_push_insn_state(p);
+               brw_set_compression_control(p, BRW_COMPRESSION_NONE);
+               brw_set_mask_control(p, BRW_MASK_DISABLE);
+
+               brw_MOV(p, mrf, __retype_ud(brw_vec8_grf(0, 0)));
+
+               /* set message header global offset field (reg 0, element 2) */
+               brw_MOV(p,
+                       __retype_ud(brw_vec1_reg(BRW_MESSAGE_REGISTER_FILE, mrf.nr, 2)),
+                       brw_imm_ud(offset));
+
+               brw_pop_insn_state(p);
+       }
+
+       {
+               struct brw_instruction *insn = brw_next_insn(p, BRW_OPCODE_SEND);
+
+               assert(insn->header.predicate_control == 0);
+               insn->header.compression_control = BRW_COMPRESSION_NONE;
+               insn->header.destreg__conditionalmod = mrf.nr;
+
+               brw_set_dest(p, insn, dest); /* UW? */
+               if (p->gen >= 60) {
+                       brw_set_src0(p, insn, mrf);
+               } else {
+                       brw_set_src0(p, insn, brw_null_reg());
+               }
+
+               brw_set_dp_read_message(p,
+                                       insn,
+                                       255, /* binding table index (255=stateless) */
+                                       msg_control,
+                                       BRW_DATAPORT_READ_MESSAGE_OWORD_BLOCK_READ, /* msg_type */
+                                       BRW_DATAPORT_READ_TARGET_RENDER_CACHE,
+                                       1, /* msg_length */
+                                       rlen);
+       }
+}
+
+/**
+ * Read a float[4] vector from the data port Data Cache (const buffer).
+ * Location (in buffer) should be a multiple of 16.
+ * Used for fetching shader constants.
+ */
+void brw_oword_block_read(struct brw_compile *p,
+                         struct brw_reg dest,
+                         struct brw_reg mrf,
+                         uint32_t offset,
+                         uint32_t bind_table_index)
+{
+       struct brw_instruction *insn;
+
+       /* On newer hardware, offset is in units of owords. */
+       if (p->gen >= 60)
+               offset /= 16;
+
+       mrf = __retype_ud(mrf);
+
+       brw_push_insn_state(p);
+       brw_set_predicate_control(p, BRW_PREDICATE_NONE);
+       brw_set_compression_control(p, BRW_COMPRESSION_NONE);
+       brw_set_mask_control(p, BRW_MASK_DISABLE);
+
+       brw_MOV(p, mrf, __retype_ud(brw_vec8_grf(0, 0)));
+
+       /* set message header global offset field (reg 0, element 2) */
+       brw_MOV(p,
+               __retype_ud(brw_vec1_reg(BRW_MESSAGE_REGISTER_FILE, mrf.nr, 2)),
+               brw_imm_ud(offset));
+
+       insn = brw_next_insn(p, BRW_OPCODE_SEND);
+       insn->header.destreg__conditionalmod = mrf.nr;
+
+       /* cast dest to a uword[8] vector */
+       dest = __retype_uw(vec8(dest));
+
+       brw_set_dest(p, insn, dest);
+       if (p->gen >= 60) {
+               brw_set_src0(p, insn, mrf);
+       } else {
+               brw_set_src0(p, insn, brw_null_reg());
+       }
+
+       brw_set_dp_read_message(p,
+                               insn,
+                               bind_table_index,
+                               BRW_DATAPORT_OWORD_BLOCK_1_OWORDLOW,
+                               BRW_DATAPORT_READ_MESSAGE_OWORD_BLOCK_READ,
+                               BRW_DATAPORT_READ_TARGET_DATA_CACHE,
+                               1, /* msg_length */
+                               1); /* response_length (1 reg, 2 owords!) */
+
+       brw_pop_insn_state(p);
+}
+
+/**
+ * Read a set of dwords from the data port Data Cache (const buffer).
+ *
+ * Location (in buffer) appears as UD offsets in the register after
+ * the provided mrf header reg.
+ */
+void brw_dword_scattered_read(struct brw_compile *p,
+                             struct brw_reg dest,
+                             struct brw_reg mrf,
+                             uint32_t bind_table_index)
+{
+       struct brw_instruction *insn;
+
+       mrf = __retype_ud(mrf);
+
+       brw_push_insn_state(p);
+       brw_set_predicate_control(p, BRW_PREDICATE_NONE);
+       brw_set_compression_control(p, BRW_COMPRESSION_NONE);
+       brw_set_mask_control(p, BRW_MASK_DISABLE);
+       brw_MOV(p, mrf, __retype_ud(brw_vec8_grf(0, 0)));
+       brw_pop_insn_state(p);
+
+       insn = brw_next_insn(p, BRW_OPCODE_SEND);
+       insn->header.destreg__conditionalmod = mrf.nr;
+
+       /* cast dest to a uword[8] vector */
+       dest = __retype_uw(vec8(dest));
+
+       brw_set_dest(p, insn, dest);
+       brw_set_src0(p, insn, brw_null_reg());
+
+       brw_set_dp_read_message(p,
+                               insn,
+                               bind_table_index,
+                               BRW_DATAPORT_DWORD_SCATTERED_BLOCK_8DWORDS,
+                               BRW_DATAPORT_READ_MESSAGE_DWORD_SCATTERED_READ,
+                               BRW_DATAPORT_READ_TARGET_DATA_CACHE,
+                               2, /* msg_length */
+                               1); /* response_length */
+}
+
+/**
+ * Read float[4] constant(s) from VS constant buffer.
+ * For relative addressing, two float[4] constants will be read into 'dest'.
+ * Otherwise, one float[4] constant will be read into the lower half of 'dest'.
+ */
+void brw_dp_READ_4_vs(struct brw_compile *p,
+                      struct brw_reg dest,
+                      unsigned location,
+                      unsigned bind_table_index)
+{
+       struct brw_instruction *insn;
+       unsigned msg_reg_nr = 1;
+
+       if (p->gen >= 60)
+               location /= 16;
+
+       /* Setup MRF[1] with location/offset into const buffer */
+       brw_push_insn_state(p);
+       brw_set_access_mode(p, BRW_ALIGN_1);
+       brw_set_compression_control(p, BRW_COMPRESSION_NONE);
+       brw_set_mask_control(p, BRW_MASK_DISABLE);
+       brw_set_predicate_control(p, BRW_PREDICATE_NONE);
+       brw_MOV(p, __retype_ud(brw_vec1_reg(BRW_MESSAGE_REGISTER_FILE, msg_reg_nr, 2)),
+               brw_imm_ud(location));
+       brw_pop_insn_state(p);
+
+       insn = brw_next_insn(p, BRW_OPCODE_SEND);
+
+       insn->header.predicate_control = BRW_PREDICATE_NONE;
+       insn->header.compression_control = BRW_COMPRESSION_NONE;
+       insn->header.destreg__conditionalmod = msg_reg_nr;
+       insn->header.mask_control = BRW_MASK_DISABLE;
+
+       brw_set_dest(p, insn, dest);
+       if (p->gen >= 60) {
+               brw_set_src0(p, insn, brw_message_reg(msg_reg_nr));
+       } else {
+               brw_set_src0(p, insn, brw_null_reg());
+       }
+
+       brw_set_dp_read_message(p,
+                               insn,
+                               bind_table_index,
+                               0,
+                               BRW_DATAPORT_READ_MESSAGE_OWORD_BLOCK_READ, /* msg_type */
+                               BRW_DATAPORT_READ_TARGET_DATA_CACHE,
+                               1, /* msg_length */
+                               1); /* response_length (1 Oword) */
+}
+
+/**
+ * Read a float[4] constant per vertex from VS constant buffer, with
+ * relative addressing.
+ */
+void brw_dp_READ_4_vs_relative(struct brw_compile *p,
+                              struct brw_reg dest,
+                              struct brw_reg addr_reg,
+                              unsigned offset,
+                              unsigned bind_table_index)
+{
+       struct brw_reg src = brw_vec8_grf(0, 0);
+       struct brw_instruction *insn;
+       int msg_type;
+
+       /* Setup MRF[1] with offset into const buffer */
+       brw_push_insn_state(p);
+       brw_set_access_mode(p, BRW_ALIGN_1);
+       brw_set_compression_control(p, BRW_COMPRESSION_NONE);
+       brw_set_mask_control(p, BRW_MASK_DISABLE);
+       brw_set_predicate_control(p, BRW_PREDICATE_NONE);
+
+       /* M1.0 is block offset 0, M1.4 is block offset 1, all other
+        * fields ignored.
+        */
+       brw_ADD(p, __retype_d(brw_message_reg(1)),
+               addr_reg, brw_imm_d(offset));
+       brw_pop_insn_state(p);
+
+       gen6_resolve_implied_move(p, &src, 0);
+
+       insn = brw_next_insn(p, BRW_OPCODE_SEND);
+       insn->header.predicate_control = BRW_PREDICATE_NONE;
+       insn->header.compression_control = BRW_COMPRESSION_NONE;
+       insn->header.destreg__conditionalmod = 0;
+       insn->header.mask_control = BRW_MASK_DISABLE;
+
+       brw_set_dest(p, insn, dest);
+       brw_set_src0(p, insn, src);
+
+       if (p->gen >= 60)
+               msg_type = GEN6_DATAPORT_READ_MESSAGE_OWORD_DUAL_BLOCK_READ;
+       else if (p->gen >= 45)
+               msg_type = G45_DATAPORT_READ_MESSAGE_OWORD_DUAL_BLOCK_READ;
+       else
+               msg_type = BRW_DATAPORT_READ_MESSAGE_OWORD_DUAL_BLOCK_READ;
+
+       brw_set_dp_read_message(p,
+                               insn,
+                               bind_table_index,
+                               BRW_DATAPORT_OWORD_DUAL_BLOCK_1OWORD,
+                               msg_type,
+                               BRW_DATAPORT_READ_TARGET_DATA_CACHE,
+                               2, /* msg_length */
+                               1); /* response_length */
+}
+
+void brw_fb_WRITE(struct brw_compile *p,
+                 int dispatch_width,
+                  unsigned msg_reg_nr,
+                  struct brw_reg src0,
+                  unsigned msg_control,
+                  unsigned binding_table_index,
+                  unsigned msg_length,
+                  unsigned response_length,
+                  bool eot,
+                  bool header_present)
+{
+       struct brw_instruction *insn;
+       unsigned msg_type;
+       struct brw_reg dest;
+
+       if (dispatch_width == 16)
+               dest = __retype_uw(vec16(brw_null_reg()));
+       else
+               dest = __retype_uw(vec8(brw_null_reg()));
+
+       if (p->gen >= 60 && binding_table_index == 0) {
+               insn = brw_next_insn(p, BRW_OPCODE_SENDC);
+       } else {
+               insn = brw_next_insn(p, BRW_OPCODE_SEND);
+       }
+       /* The execution mask is ignored for render target writes. */
+       insn->header.predicate_control = 0;
+       insn->header.compression_control = BRW_COMPRESSION_NONE;
+
+       if (p->gen >= 60) {
+               /* headerless version, just submit color payload */
+               src0 = brw_message_reg(msg_reg_nr);
+
+               msg_type = GEN6_DATAPORT_WRITE_MESSAGE_RENDER_TARGET_WRITE;
+       } else {
+               insn->header.destreg__conditionalmod = msg_reg_nr;
+
+               msg_type = BRW_DATAPORT_WRITE_MESSAGE_RENDER_TARGET_WRITE;
+       }
+
+       brw_set_dest(p, insn, dest);
+       brw_set_src0(p, insn, src0);
+       brw_set_dp_write_message(p,
+                                insn,
+                                binding_table_index,
+                                msg_control,
+                                msg_type,
+                                msg_length,
+                                header_present,
+                                eot,
+                                response_length,
+                                eot,
+                                0 /* send_commit_msg */);
+}
+
+/**
+ * Texture sample instruction.
+ * Note: the msg_type plus msg_length values determine exactly what kind
+ * of sampling operation is performed.  See volume 4, page 161 of docs.
+ */
+void brw_SAMPLE(struct brw_compile *p,
+               struct brw_reg dest,
+               unsigned msg_reg_nr,
+               struct brw_reg src0,
+               unsigned binding_table_index,
+               unsigned sampler,
+               unsigned writemask,
+               unsigned msg_type,
+               unsigned response_length,
+               unsigned msg_length,
+               bool header_present,
+               unsigned simd_mode)
+{
+       assert(writemask);
+
+       if (p->gen < 50 || writemask != WRITEMASK_XYZW) {
+               struct brw_reg m1 = brw_message_reg(msg_reg_nr);
+
+               writemask = ~writemask & WRITEMASK_XYZW;
+
+               brw_push_insn_state(p);
+
+               brw_set_compression_control(p, BRW_COMPRESSION_NONE);
+               brw_set_mask_control(p, BRW_MASK_DISABLE);
+
+               brw_MOV(p, __retype_ud(m1), __retype_ud(brw_vec8_grf(0,0)));
+               brw_MOV(p, get_element_ud(m1, 2), brw_imm_ud(writemask << 12));
+
+               brw_pop_insn_state(p);
+
+               src0 = __retype_uw(brw_null_reg());
+       }
+
+       {
+               struct brw_instruction *insn;
+
+               gen6_resolve_implied_move(p, &src0, msg_reg_nr);
+
+               insn = brw_next_insn(p, BRW_OPCODE_SEND);
+               insn->header.predicate_control = 0; /* XXX */
+               insn->header.compression_control = BRW_COMPRESSION_NONE;
+               if (p->gen < 60)
+                       insn->header.destreg__conditionalmod = msg_reg_nr;
+
+               brw_set_dest(p, insn, dest);
+               brw_set_src0(p, insn, src0);
+               brw_set_sampler_message(p, insn,
+                                       binding_table_index,
+                                       sampler,
+                                       msg_type,
+                                       response_length,
+                                       msg_length,
+                                       header_present,
+                                       simd_mode);
+       }
+}
+
+/* All these variables are pretty confusing - we might be better off
+ * using bitmasks and macros for this, in the old style.  Or perhaps
+ * just having the caller instantiate the fields in dword3 itself.
+ */
+void brw_urb_WRITE(struct brw_compile *p,
+                  struct brw_reg dest,
+                  unsigned msg_reg_nr,
+                  struct brw_reg src0,
+                  bool allocate,
+                  bool used,
+                  unsigned msg_length,
+                  unsigned response_length,
+                  bool eot,
+                  bool writes_complete,
+                  unsigned offset,
+                  unsigned swizzle)
+{
+       struct brw_instruction *insn;
+
+       gen6_resolve_implied_move(p, &src0, msg_reg_nr);
+
+       if (p->gen >= 70) {
+               /* Enable Channel Masks in the URB_WRITE_HWORD message header */
+               brw_push_insn_state(p);
+               brw_set_access_mode(p, BRW_ALIGN_1);
+               brw_OR(p, __retype_ud(brw_vec1_reg(BRW_MESSAGE_REGISTER_FILE, msg_reg_nr, 5)),
+                      __retype_ud(brw_vec1_grf(0, 5)),
+                      brw_imm_ud(0xff00));
+               brw_pop_insn_state(p);
+       }
+
+       insn = brw_next_insn(p, BRW_OPCODE_SEND);
+
+       assert(msg_length < BRW_MAX_MRF);
+
+       brw_set_dest(p, insn, dest);
+       brw_set_src0(p, insn, src0);
+       brw_set_src1(p, insn, brw_imm_d(0));
+
+       if (p->gen <= 60)
+               insn->header.destreg__conditionalmod = msg_reg_nr;
+
+       brw_set_urb_message(p,
+                           insn,
+                           allocate,
+                           used,
+                           msg_length,
+                           response_length,
+                           eot,
+                           writes_complete,
+                           offset,
+                           swizzle);
+}
+
+static int
+brw_find_next_block_end(struct brw_compile *p, int start)
+{
+       int ip;
+
+       for (ip = start + 1; ip < p->nr_insn; ip++) {
+               struct brw_instruction *insn = &p->store[ip];
+
+               switch (insn->header.opcode) {
+               case BRW_OPCODE_ENDIF:
+               case BRW_OPCODE_ELSE:
+               case BRW_OPCODE_WHILE:
+                       return ip;
+               }
+       }
+       assert(!"not reached");
+       return start + 1;
+}
+
+/* There is no DO instruction on gen6, so to find the end of the loop
+ * we have to see if the loop is jumping back before our start
+ * instruction.
+ */
+static int
+brw_find_loop_end(struct brw_compile *p, int start)
+{
+       int ip;
+       int br = 2;
+
+       for (ip = start + 1; ip < p->nr_insn; ip++) {
+               struct brw_instruction *insn = &p->store[ip];
+
+               if (insn->header.opcode == BRW_OPCODE_WHILE) {
+                       int jip = p->gen <= 70 ? insn->bits1.branch_gen6.jump_count
+                               : insn->bits3.break_cont.jip;
+                       if (ip + jip / br <= start)
+                               return ip;
+               }
+       }
+       assert(!"not reached");
+       return start + 1;
+}
+
+/* After program generation, go back and update the UIP and JIP of
+ * BREAK and CONT instructions to their correct locations.
+ */
+void
+brw_set_uip_jip(struct brw_compile *p)
+{
+       int ip;
+       int br = 2;
+
+       if (p->gen <= 60)
+               return;
+
+       for (ip = 0; ip < p->nr_insn; ip++) {
+               struct brw_instruction *insn = &p->store[ip];
+
+               switch (insn->header.opcode) {
+               case BRW_OPCODE_BREAK:
+                       insn->bits3.break_cont.jip = br * (brw_find_next_block_end(p, ip) - ip);
+                       /* Gen7 UIP points to WHILE; Gen6 points just after it */
+                       insn->bits3.break_cont.uip =
+                               br * (brw_find_loop_end(p, ip) - ip + (p->gen <= 70 ? 1 : 0));
+                       break;
+               case BRW_OPCODE_CONTINUE:
+                       insn->bits3.break_cont.jip = br * (brw_find_next_block_end(p, ip) - ip);
+                       insn->bits3.break_cont.uip = br * (brw_find_loop_end(p, ip) - ip);
+
+                       assert(insn->bits3.break_cont.uip != 0);
+                       assert(insn->bits3.break_cont.jip != 0);
+                       break;
+               }
+       }
+}
+
+void brw_ff_sync(struct brw_compile *p,
+                  struct brw_reg dest,
+                  unsigned msg_reg_nr,
+                  struct brw_reg src0,
+                  bool allocate,
+                  unsigned response_length,
+                  bool eot)
+{
+       struct brw_instruction *insn;
+
+       gen6_resolve_implied_move(p, &src0, msg_reg_nr);
+
+       insn = brw_next_insn(p, BRW_OPCODE_SEND);
+       brw_set_dest(p, insn, dest);
+       brw_set_src0(p, insn, src0);
+       brw_set_src1(p, insn, brw_imm_d(0));
+
+       if (p->gen < 60)
+               insn->header.destreg__conditionalmod = msg_reg_nr;
+
+       brw_set_ff_sync_message(p,
+                               insn,
+                               allocate,
+                               response_length,
+                               eot);
+}
diff --git a/src/sna/brw/brw_sf.c b/src/sna/brw/brw_sf.c
new file mode 100644 (file)
index 0000000..6f82171
--- /dev/null
@@ -0,0 +1,54 @@
+#include "brw.h"
+
+bool brw_sf_kernel__nomask(struct brw_compile *p)
+{
+       struct brw_reg inv, v0, v1, v2, delta;
+
+       v0 = brw_vec4_grf(3, 0);
+       v1 = brw_vec4_grf(4, 0);
+       v2 = brw_vec4_grf(5, 0);
+       delta = brw_vec8_grf(7, 0);
+
+       inv = brw_vec4_grf(6, 0);
+       brw_math_invert(p, inv, brw_vec4_grf(1, 11));
+
+       brw_MOV(p, brw_message_reg(3), v0);
+
+       brw_ADD(p, delta, v1, brw_negate(v2));
+       brw_MUL(p, brw_message_reg(1), delta, brw_vec1_grf(6,0));
+
+       brw_ADD(p, delta, v2, brw_negate(v0));
+       brw_MUL(p, brw_message_reg(2), delta, brw_vec1_grf(6,2));
+
+       brw_urb_WRITE(p, brw_null_reg(), 0, brw_vec8_grf(0 ,0),
+                     false, true, 4, 0, true, true, 0,
+                     BRW_URB_SWIZZLE_TRANSPOSE);
+
+       return true;
+}
+
+bool brw_sf_kernel__mask(struct brw_compile *p)
+{
+       struct brw_reg inv, v0, v1, v2;
+
+       v0 = brw_vec8_grf(3, 0);
+       v1 = brw_vec8_grf(4, 0);
+       v2 = brw_vec8_grf(5, 0);
+
+       inv = brw_vec4_grf(6, 0);
+       brw_math_invert(p, inv, brw_vec4_grf(1, 11));
+
+       brw_MOV(p, brw_message_reg(3), v0);
+
+       brw_ADD(p, brw_vec8_grf(7, 0), v1, brw_negate(v2));
+       brw_MUL(p, brw_message_reg(1), brw_vec8_grf(7, 0), brw_vec1_grf(6,0));
+
+       brw_ADD(p, brw_vec8_grf(7, 0), v2, brw_negate(v0));
+       brw_MUL(p, brw_message_reg(2), brw_vec8_grf(7, 0), brw_vec1_grf(6,2));
+
+       brw_urb_WRITE(p, brw_null_reg(), 0, brw_vec8_grf(0 ,0),
+                     false, true, 4, 0, true, true, 0,
+                     BRW_URB_SWIZZLE_TRANSPOSE);
+
+       return true;
+}
diff --git a/src/sna/brw/brw_test.c b/src/sna/brw/brw_test.c
new file mode 100644 (file)
index 0000000..4f03858
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2011 Intel 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.
+ *
+ * Authors:
+ *    Chris Wilson <chris@chris-wilson.co.uk>
+ *
+ */
+
+#include "brw_test.h"
+#include <string.h>
+
+void brw_test_compare(const char *function, int gen,
+                     const struct brw_instruction *new, int num_new,
+                     const struct brw_instruction *old, int num_old)
+{
+       int n;
+
+       if (num_new != num_old ||
+           memcmp(new, old, num_new * sizeof(struct brw_instruction))) {
+               printf ("%s: new\n", function);
+               for (n = 0; n < num_new; n++)
+                       brw_disasm(stdout, &new[n], gen);
+
+               printf ("%s: old\n", function);
+               for (n = 0; n < num_old; n++)
+                       brw_disasm(stdout, &old[n], gen);
+               printf ("\n");
+       }
+}
+
+
+/* Check that we can recreate all the existing programs using the assembler */
+int main(int argc, char **argv)
+{
+       brw_test_gen4();
+       brw_test_gen5();
+       brw_test_gen6();
+       brw_test_gen7();
+
+       return 0;
+}
diff --git a/src/sna/brw/brw_test.h b/src/sna/brw/brw_test.h
new file mode 100644 (file)
index 0000000..41f4ca6
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2011 Intel 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.
+ *
+ * Authors:
+ *    Chris Wilson <chris@chris-wilson.co.uk>
+ *
+ */
+
+#ifndef BRW_TEST_H
+#define BRW_TEST_H
+
+#include "brw.h"
+
+#ifndef ARRAY_SIZE
+#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
+#endif
+
+void brw_test_compare(const char *function, int gen,
+                     const struct brw_instruction *new, int num_new,
+                     const struct brw_instruction *old, int num_old);
+
+void brw_test_gen4(void);
+void brw_test_gen5(void);
+void brw_test_gen6(void);
+void brw_test_gen7(void);
+
+#endif /* BRW_TEST_H */
diff --git a/src/sna/brw/brw_test_gen4.c b/src/sna/brw/brw_test_gen4.c
new file mode 100644 (file)
index 0000000..742c7c2
--- /dev/null
@@ -0,0 +1,199 @@
+/*
+ * Copyright (c) 2011 Intel 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.
+ *
+ * Authors:
+ *    Chris Wilson <chris@chris-wilson.co.uk>
+ *
+ */
+
+#include "brw_test.h"
+
+#include <string.h>
+
+static const uint32_t sf_kernel[][4] = {
+#include "exa_sf.g4b"
+};
+
+static const uint32_t sf_kernel_mask[][4] = {
+#include "exa_sf_mask.g4b"
+};
+
+static const uint32_t ps_kernel_nomask_affine[][4] = {
+#include "exa_wm_xy.g4b"
+#include "exa_wm_src_affine.g4b"
+#include "exa_wm_src_sample_argb.g4b"
+#include "exa_wm_write.g4b"
+};
+
+static const uint32_t ps_kernel_nomask_projective[][4] = {
+#include "exa_wm_xy.g4b"
+#include "exa_wm_src_projective.g4b"
+#include "exa_wm_src_sample_argb.g4b"
+#include "exa_wm_write.g4b"
+};
+
+static const uint32_t ps_kernel_maskca_affine[][4] = {
+#include "exa_wm_xy.g4b"
+#include "exa_wm_src_affine.g4b"
+#include "exa_wm_src_sample_argb.g4b"
+#include "exa_wm_mask_affine.g4b"
+#include "exa_wm_mask_sample_argb.g4b"
+#include "exa_wm_ca.g4b"
+#include "exa_wm_write.g4b"
+};
+
+static const uint32_t ps_kernel_maskca_projective[][4] = {
+#include "exa_wm_xy.g4b"
+#include "exa_wm_src_projective.g4b"
+#include "exa_wm_src_sample_argb.g4b"
+#include "exa_wm_mask_projective.g4b"
+#include "exa_wm_mask_sample_argb.g4b"
+#include "exa_wm_ca.g4b"
+#include "exa_wm_write.g4b"
+};
+
+static const uint32_t ps_kernel_maskca_srcalpha_affine[][4] = {
+#include "exa_wm_xy.g4b"
+#include "exa_wm_src_affine.g4b"
+#include "exa_wm_src_sample_a.g4b"
+#include "exa_wm_mask_affine.g4b"
+#include "exa_wm_mask_sample_argb.g4b"
+#include "exa_wm_ca_srcalpha.g4b"
+#include "exa_wm_write.g4b"
+};
+
+static const uint32_t ps_kernel_maskca_srcalpha_projective[][4] = {
+#include "exa_wm_xy.g4b"
+#include "exa_wm_src_projective.g4b"
+#include "exa_wm_src_sample_a.g4b"
+#include "exa_wm_mask_projective.g4b"
+#include "exa_wm_mask_sample_argb.g4b"
+#include "exa_wm_ca_srcalpha.g4b"
+#include "exa_wm_write.g4b"
+};
+
+static const uint32_t ps_kernel_masknoca_affine[][4] = {
+#include "exa_wm_xy.g4b"
+#include "exa_wm_src_affine.g4b"
+#include "exa_wm_src_sample_argb.g4b"
+#include "exa_wm_mask_affine.g4b"
+#include "exa_wm_mask_sample_a.g4b"
+#include "exa_wm_noca.g4b"
+#include "exa_wm_write.g4b"
+};
+
+static const uint32_t ps_kernel_masknoca_projective[][4] = {
+#include "exa_wm_xy.g4b"
+#include "exa_wm_src_projective.g4b"
+#include "exa_wm_src_sample_argb.g4b"
+#include "exa_wm_mask_projective.g4b"
+#include "exa_wm_mask_sample_a.g4b"
+#include "exa_wm_noca.g4b"
+#include "exa_wm_write.g4b"
+};
+
+static const uint32_t ps_kernel_packed_static[][4] = {
+#include "exa_wm_xy.g4b"
+#include "exa_wm_src_affine.g4b"
+#include "exa_wm_src_sample_argb.g4b"
+#include "exa_wm_yuv_rgb.g4b"
+#include "exa_wm_write.g4b"
+};
+
+static const uint32_t ps_kernel_planar_static[][4] = {
+#include "exa_wm_xy.g4b"
+#include "exa_wm_src_affine.g4b"
+#include "exa_wm_src_sample_planar.g4b"
+#include "exa_wm_yuv_rgb.g4b"
+#include "exa_wm_write.g4b"
+};
+
+#define compare(old) brw_test_compare(__FUNCTION__, p.gen, p.store, p.nr_insn, (struct brw_instruction *)old, ARRAY_SIZE(old)-8)
+
+static void gen4_sf__nomask(void)
+{
+       uint32_t store[128];
+       struct brw_compile p;
+
+       brw_compile_init(&p, 40, store);
+       brw_sf_kernel__nomask(&p);
+
+       compare(sf_kernel);
+}
+
+static void gen4_sf__mask(void)
+{
+       uint32_t store[128];
+       struct brw_compile p;
+
+       brw_compile_init(&p, 40, store);
+       brw_sf_kernel__mask(&p);
+
+       compare(sf_kernel_mask);
+}
+
+static void
+gen4_wm_kernel__affine_nomask(void)
+{
+       uint32_t store[128];
+       struct brw_compile p;
+
+       brw_compile_init(&p, 40, store);
+       brw_wm_kernel__affine(&p, 16);
+
+       compare(ps_kernel_nomask_affine);
+}
+
+static void
+gen4_wm_kernel__affine_mask_noca(void)
+{
+       uint32_t store[128];
+       struct brw_compile p;
+
+       brw_compile_init(&p, 40, store);
+       brw_wm_kernel__affine_mask(&p, 16);
+
+       compare(ps_kernel_masknoca_affine);
+}
+
+static void
+gen4_wm_kernel__projective_nomask(void)
+{
+       uint32_t store[128];
+       struct brw_compile p;
+
+       brw_compile_init(&p, 40, store);
+       brw_wm_kernel__projective(&p, 16);
+
+       compare(ps_kernel_nomask_projective);
+}
+
+void brw_test_gen4(void)
+{
+       gen4_sf__nomask();
+       gen4_sf__mask();
+
+       gen4_wm_kernel__affine_nomask();
+       gen4_wm_kernel__affine_mask_noca();
+
+       gen4_wm_kernel__projective_nomask();
+}
diff --git a/src/sna/brw/brw_test_gen5.c b/src/sna/brw/brw_test_gen5.c
new file mode 100644 (file)
index 0000000..62a999e
--- /dev/null
@@ -0,0 +1,208 @@
+/*
+ * Copyright (c) 2011 Intel 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.
+ *
+ * Authors:
+ *    Chris Wilson <chris@chris-wilson.co.uk>
+ *
+ */
+
+#include "brw_test.h"
+
+#include <string.h>
+
+static const uint32_t sf_kernel[][4] = {
+#include "exa_sf.g5b"
+};
+
+static const uint32_t sf_kernel_mask[][4] = {
+#include "exa_sf_mask.g5b"
+};
+
+static const uint32_t ps_kernel_nomask_affine[][4] = {
+#include "exa_wm_xy.g5b"
+#include "exa_wm_src_affine.g5b"
+#include "exa_wm_src_sample_argb.g5b"
+#include "exa_wm_write.g5b"
+};
+
+static const uint32_t ps_kernel_nomask_projective[][4] = {
+#include "exa_wm_xy.g5b"
+#include "exa_wm_src_projective.g5b"
+#include "exa_wm_src_sample_argb.g5b"
+#include "exa_wm_write.g5b"
+};
+
+static const uint32_t ps_kernel_maskca_affine[][4] = {
+#include "exa_wm_xy.g5b"
+#include "exa_wm_src_affine.g5b"
+#include "exa_wm_src_sample_argb.g5b"
+#include "exa_wm_mask_affine.g5b"
+#include "exa_wm_mask_sample_argb.g5b"
+#include "exa_wm_ca.g5b"
+#include "exa_wm_write.g5b"
+};
+
+static const uint32_t ps_kernel_maskca_projective[][4] = {
+#include "exa_wm_xy.g5b"
+#include "exa_wm_src_projective.g5b"
+#include "exa_wm_src_sample_argb.g5b"
+#include "exa_wm_mask_projective.g5b"
+#include "exa_wm_mask_sample_argb.g5b"
+#include "exa_wm_ca.g5b"
+#include "exa_wm_write.g5b"
+};
+
+static const uint32_t ps_kernel_maskca_srcalpha_affine[][4] = {
+#include "exa_wm_xy.g5b"
+#include "exa_wm_src_affine.g5b"
+#include "exa_wm_src_sample_a.g5b"
+#include "exa_wm_mask_affine.g5b"
+#include "exa_wm_mask_sample_argb.g5b"
+#include "exa_wm_ca_srcalpha.g5b"
+#include "exa_wm_write.g5b"
+};
+
+static const uint32_t ps_kernel_maskca_srcalpha_projective[][4] = {
+#include "exa_wm_xy.g5b"
+#include "exa_wm_src_projective.g5b"
+#include "exa_wm_src_sample_a.g5b"
+#include "exa_wm_mask_projective.g5b"
+#include "exa_wm_mask_sample_argb.g5b"
+#include "exa_wm_ca_srcalpha.g5b"
+#include "exa_wm_write.g5b"
+};
+
+static const uint32_t ps_kernel_masknoca_affine[][4] = {
+#include "exa_wm_xy.g5b"
+#include "exa_wm_src_affine.g5b"
+#include "exa_wm_src_sample_argb.g5b"
+#include "exa_wm_mask_affine.g5b"
+#include "exa_wm_mask_sample_a.g5b"
+#include "exa_wm_noca.g5b"
+#include "exa_wm_write.g5b"
+};
+
+static const uint32_t ps_kernel_masknoca_projective[][4] = {
+#include "exa_wm_xy.g5b"
+#include "exa_wm_src_projective.g5b"
+#include "exa_wm_src_sample_argb.g5b"
+#include "exa_wm_mask_projective.g5b"
+#include "exa_wm_mask_sample_a.g5b"
+#include "exa_wm_noca.g5b"
+#include "exa_wm_write.g5b"
+};
+
+static const uint32_t ps_kernel_packed_static[][4] = {
+#include "exa_wm_xy.g5b"
+#include "exa_wm_src_affine.g5b"
+#include "exa_wm_src_sample_argb.g5b"
+#include "exa_wm_yuv_rgb.g5b"
+#include "exa_wm_write.g5b"
+};
+
+static const uint32_t ps_kernel_planar_static[][4] = {
+#include "exa_wm_xy.g5b"
+#include "exa_wm_src_affine.g5b"
+#include "exa_wm_src_sample_planar.g5b"
+#include "exa_wm_yuv_rgb.g5b"
+#include "exa_wm_write.g5b"
+};
+
+#define compare(old) brw_test_compare(__FUNCTION__, p.gen, p.store, p.nr_insn, (struct brw_instruction *)old, ARRAY_SIZE(old))
+
+static void gen5_sf(void)
+{
+       uint32_t store[128];
+       struct brw_compile p;
+
+       brw_compile_init(&p, 50, store);
+       brw_sf_kernel__nomask(&p);
+
+       compare(sf_kernel);
+}
+
+static void gen5_sf_mask(void)
+{
+       uint32_t store[128];
+       struct brw_compile p;
+
+       brw_compile_init(&p, 50, store);
+       brw_sf_kernel__mask(&p);
+
+       compare(sf_kernel_mask);
+}
+
+static void gen5_wm_affine_nomask(void)
+{
+       uint32_t store[128];
+       struct brw_compile p;
+
+       brw_compile_init(&p, 50, store);
+       brw_wm_kernel__affine(&p, 16);
+
+       compare(ps_kernel_nomask_affine);
+}
+
+static void gen5_wm_affine_mask_noca(void)
+{
+       uint32_t store[128];
+       struct brw_compile p;
+
+       brw_compile_init(&p, 50, store);
+       brw_wm_kernel__affine_mask(&p, 16);
+
+       compare(ps_kernel_masknoca_affine);
+}
+
+static void gen5_wm_affine_mask_ca(void)
+{
+       uint32_t store[128];
+       struct brw_compile p;
+
+       brw_compile_init(&p, 50, store);
+       brw_wm_kernel__affine_mask_ca(&p, 16);
+
+       compare(ps_kernel_maskca_affine);
+}
+
+static void gen5_wm_projective_nomask(void)
+{
+       uint32_t store[128];
+       struct brw_compile p;
+
+       brw_compile_init(&p, 50, store);
+       brw_wm_kernel__projective(&p, 16);
+
+       compare(ps_kernel_nomask_projective);
+}
+
+void brw_test_gen5(void)
+{
+       gen5_sf();
+       gen5_sf_mask();
+
+       gen5_wm_affine_nomask();
+       gen5_wm_affine_mask_noca();
+       gen5_wm_affine_mask_ca();
+
+       gen5_wm_projective_nomask();
+}
diff --git a/src/sna/brw/brw_test_gen6.c b/src/sna/brw/brw_test_gen6.c
new file mode 100644 (file)
index 0000000..64bc2fb
--- /dev/null
@@ -0,0 +1,209 @@
+/*
+ * Copyright (c) 2011 Intel 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.
+ *
+ * Authors:
+ *    Chris Wilson <chris@chris-wilson.co.uk>
+ *
+ */
+
+#include "brw_test.h"
+
+#include <string.h>
+
+static const uint32_t ps_kernel_nomask_affine[][4] = {
+#include "exa_wm_src_affine.g6b"
+#include "exa_wm_src_sample_argb.g6b"
+#include "exa_wm_write.g6b"
+};
+
+static const uint32_t ps_kernel_nomask_projective[][4] = {
+#include "exa_wm_src_projective.g6b"
+#include "exa_wm_src_sample_argb.g6b"
+#include "exa_wm_write.g6b"
+};
+
+static const uint32_t ps_kernel_maskca_affine[][4] = {
+#include "exa_wm_src_affine.g6b"
+#include "exa_wm_src_sample_argb.g6b"
+#include "exa_wm_mask_affine.g6b"
+#include "exa_wm_mask_sample_argb.g6b"
+#include "exa_wm_ca.g6b"
+#include "exa_wm_write.g6b"
+};
+
+static const uint32_t ps_kernel_maskca_projective[][4] = {
+#include "exa_wm_src_projective.g6b"
+#include "exa_wm_src_sample_argb.g6b"
+#include "exa_wm_mask_projective.g6b"
+#include "exa_wm_mask_sample_argb.g6b"
+#include "exa_wm_ca.g6b"
+#include "exa_wm_write.g6b"
+};
+
+static const uint32_t ps_kernel_maskca_srcalpha_affine[][4] = {
+#include "exa_wm_src_affine.g6b"
+#include "exa_wm_src_sample_a.g6b"
+#include "exa_wm_mask_affine.g6b"
+#include "exa_wm_mask_sample_argb.g6b"
+#include "exa_wm_ca_srcalpha.g6b"
+#include "exa_wm_write.g6b"
+};
+
+static const uint32_t ps_kernel_maskca_srcalpha_projective[][4] = {
+#include "exa_wm_src_projective.g6b"
+#include "exa_wm_src_sample_a.g6b"
+#include "exa_wm_mask_projective.g6b"
+#include "exa_wm_mask_sample_argb.g6b"
+#include "exa_wm_ca_srcalpha.g6b"
+#include "exa_wm_write.g6b"
+};
+
+static const uint32_t ps_kernel_masknoca_affine[][4] = {
+#include "exa_wm_src_affine.g6b"
+#include "exa_wm_src_sample_argb.g6b"
+#include "exa_wm_mask_affine.g6b"
+#include "exa_wm_mask_sample_a.g6b"
+#include "exa_wm_noca.g6b"
+#include "exa_wm_write.g6b"
+};
+
+static const uint32_t ps_kernel_masknoca_projective[][4] = {
+#include "exa_wm_src_projective.g6b"
+#include "exa_wm_src_sample_argb.g6b"
+#include "exa_wm_mask_projective.g6b"
+#include "exa_wm_mask_sample_a.g6b"
+#include "exa_wm_noca.g6b"
+#include "exa_wm_write.g6b"
+};
+
+static const uint32_t ps_kernel_packed[][4] = {
+#include "exa_wm_src_affine.g6b"
+#include "exa_wm_src_sample_argb.g6b"
+#include "exa_wm_yuv_rgb.g6b"
+#include "exa_wm_write.g6b"
+};
+
+static const uint32_t ps_kernel_planar[][4] = {
+#include "exa_wm_src_affine.g6b"
+#include "exa_wm_src_sample_planar.g6b"
+#include "exa_wm_yuv_rgb.g6b"
+#include "exa_wm_write.g6b"
+};
+
+#define compare(old) brw_test_compare(__FUNCTION__, p.gen, p.store, p.nr_insn, (struct brw_instruction *)old, ARRAY_SIZE(old))
+
+#if 0
+static void wm_src_affine(struct brw_compile *p)
+{
+       brw_PLN(p, brw_message_reg(2), brw_vec1_grf(6,0), brw_vec8_grf(2,0));
+       brw_PLN(p, brw_message_reg(3), brw_vec1_grf(6,0), brw_vec8_grf(4,0));
+       brw_PLN(p, brw_message_reg(4), brw_vec1_grf(6,4), brw_vec8_grf(2,0));
+       brw_PLN(p, brw_message_reg(5), brw_vec1_grf(6,4), brw_vec8_grf(4,0));
+}
+
+static void wm_src_sample_argb(struct brw_compile *p)
+{
+       static const uint32_t fragment[][4] = {
+#include "exa_wm_src_affine.g6b"
+#include "exa_wm_src_sample_argb.g6b"
+#include "exa_wm_write.g6b"
+       };
+       int n;
+
+       brw_push_insn_state(p);
+       brw_set_mask_control(p, BRW_MASK_DISABLE);
+       brw_set_compression_control(p, BRW_COMPRESSION_NONE);
+       brw_MOV(p,
+               retype(brw_vec1_grf(0,2), BRW_REGISTER_TYPE_UD),
+               brw_imm_ud(0));
+       brw_pop_insn_state(p);
+
+       brw_SAMPLE(p,
+                  retype(vec16(brw_vec8_grf(14, 0)), BRW_REGISTER_TYPE_UW),
+                  1,
+                  retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UD),
+                  1, 0,
+                  WRITEMASK_XYZW,
+                  GEN5_SAMPLER_MESSAGE_SAMPLE,
+                  8,
+                  5,
+                  true,
+                  BRW_SAMPLER_SIMD_MODE_SIMD16);
+
+
+       for (n = 0; n < p->nr_insn; n++) {
+               brw_disasm(stdout, &p->store[n], 60);
+       }
+
+       printf("\n\n");
+       for (n = 0; n < ARRAY_SIZE(fragment); n++) {
+               brw_disasm(stdout,
+                          (const struct brw_instruction *)&fragment[n][0],
+                          60);
+       }
+}
+
+static void wm_write(struct brw_compile *p)
+{
+}
+#endif
+
+static void gen6_ps_nomask_affine(void)
+{
+       uint32_t store[1024];
+       struct brw_compile p;
+
+       brw_compile_init(&p, 60, store);
+       brw_wm_kernel__affine(&p, 16);
+
+       compare(ps_kernel_nomask_affine);
+}
+
+static void gen6_ps_mask_affine(void)
+{
+       uint32_t store[1024];
+       struct brw_compile p;
+
+       brw_compile_init(&p, 60, store);
+       brw_wm_kernel__affine_mask(&p, 16);
+
+       compare(ps_kernel_masknoca_affine);
+}
+
+static void gen6_ps_nomask_projective(void)
+{
+       uint32_t store[1024];
+       struct brw_compile p;
+
+       brw_compile_init(&p, 60, store);
+       brw_wm_kernel__projective(&p, 16);
+
+       compare(ps_kernel_nomask_projective);
+}
+
+void brw_test_gen6(void)
+{
+       gen6_ps_nomask_affine();
+       gen6_ps_mask_affine();
+
+       gen6_ps_nomask_projective();
+}
diff --git a/src/sna/brw/brw_test_gen7.c b/src/sna/brw/brw_test_gen7.c
new file mode 100644 (file)
index 0000000..085b25c
--- /dev/null
@@ -0,0 +1,191 @@
+/*
+ * Copyright (c) 2011 Intel 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.
+ *
+ * Authors:
+ *    Chris Wilson <chris@chris-wilson.co.uk>
+ *
+ */
+
+#include "brw_test.h"
+
+#include <string.h>
+
+static const uint32_t ps_kernel_nomask_affine[][4] = {
+#include "exa_wm_src_affine.g7b"
+#include "exa_wm_src_sample_argb.g7b"
+#include "exa_wm_write.g7b"
+};
+
+static const uint32_t ps_kernel_nomask_projective[][4] = {
+#include "exa_wm_src_projective.g7b"
+#include "exa_wm_src_sample_argb.g7b"
+#include "exa_wm_write.g7b"
+};
+
+static const uint32_t ps_kernel_maskca_affine[][4] = {
+#include "exa_wm_src_affine.g7b"
+#include "exa_wm_src_sample_argb.g7b"
+#include "exa_wm_mask_affine.g7b"
+#include "exa_wm_mask_sample_argb.g7b"
+#include "exa_wm_ca.g6b"
+#include "exa_wm_write.g7b"
+};
+
+static const uint32_t ps_kernel_maskca_projective[][4] = {
+#include "exa_wm_src_projective.g7b"
+#include "exa_wm_src_sample_argb.g7b"
+#include "exa_wm_mask_projective.g7b"
+#include "exa_wm_mask_sample_argb.g7b"
+#include "exa_wm_ca.g6b"
+#include "exa_wm_write.g7b"
+};
+
+static const uint32_t ps_kernel_maskca_srcalpha_affine[][4] = {
+#include "exa_wm_src_affine.g7b"
+#include "exa_wm_src_sample_a.g7b"
+#include "exa_wm_mask_affine.g7b"
+#include "exa_wm_mask_sample_argb.g7b"
+#include "exa_wm_ca_srcalpha.g6b"
+#include "exa_wm_write.g7b"
+};
+
+static const uint32_t ps_kernel_maskca_srcalpha_projective[][4] = {
+#include "exa_wm_src_projective.g7b"
+#include "exa_wm_src_sample_a.g7b"
+#include "exa_wm_mask_projective.g7b"
+#include "exa_wm_mask_sample_argb.g7b"
+#include "exa_wm_ca_srcalpha.g6b"
+#include "exa_wm_write.g7b"
+};
+
+static const uint32_t ps_kernel_masknoca_affine[][4] = {
+#include "exa_wm_src_affine.g7b"
+#include "exa_wm_src_sample_argb.g7b"
+#include "exa_wm_mask_affine.g7b"
+#include "exa_wm_mask_sample_a.g7b"
+#include "exa_wm_noca.g6b"
+#include "exa_wm_write.g7b"
+};
+
+static const uint32_t ps_kernel_masknoca_projective[][4] = {
+#include "exa_wm_src_projective.g7b"
+#include "exa_wm_src_sample_argb.g7b"
+#include "exa_wm_mask_projective.g7b"
+#include "exa_wm_mask_sample_a.g7b"
+#include "exa_wm_noca.g6b"
+#include "exa_wm_write.g7b"
+};
+
+static const uint32_t ps_kernel_packed[][4] = {
+#include "exa_wm_src_affine.g7b"
+#include "exa_wm_src_sample_argb.g7b"
+#include "exa_wm_yuv_rgb.g7b"
+#include "exa_wm_write.g7b"
+};
+
+static const uint32_t ps_kernel_planar[][4] = {
+#include "exa_wm_src_affine.g7b"
+#include "exa_wm_src_sample_planar.g7b"
+#include "exa_wm_yuv_rgb.g7b"
+#include "exa_wm_write.g7b"
+};
+
+#define compare(old) brw_test_compare(__FUNCTION__, p.gen, p.store, p.nr_insn, (struct brw_instruction *)old, ARRAY_SIZE(old))
+#define GEN 70
+
+static void gen7_ps_nomask_affine(void)
+{
+       uint32_t store[1024];
+       struct brw_compile p;
+
+       brw_compile_init(&p, GEN, store);
+       brw_wm_kernel__affine(&p, 8);
+
+       compare(ps_kernel_nomask_affine);
+}
+
+static void gen7_ps_mask_affine(void)
+{
+       uint32_t store[1024];
+       struct brw_compile p;
+
+       brw_compile_init(&p, GEN, store);
+       brw_wm_kernel__affine_mask(&p, 8);
+
+       compare(ps_kernel_masknoca_affine);
+}
+
+static void gen7_ps_maskca_affine(void)
+{
+       uint32_t store[1024];
+       struct brw_compile p;
+
+       brw_compile_init(&p, GEN, store);
+       brw_wm_kernel__affine_mask_ca(&p, 8);
+
+       compare(ps_kernel_maskca_affine);
+}
+
+static void gen7_ps_masksa_affine(void)
+{
+       uint32_t store[1024];
+       struct brw_compile p;
+
+       brw_compile_init(&p, GEN, store);
+       brw_wm_kernel__affine_mask_sa(&p, 8);
+
+       compare(ps_kernel_maskca_srcalpha_affine);
+}
+
+static void gen7_ps_nomask_projective(void)
+{
+       uint32_t store[1024];
+       struct brw_compile p;
+
+       brw_compile_init(&p, GEN, store);
+       brw_wm_kernel__projective(&p, 8);
+
+       compare(ps_kernel_nomask_projective);
+}
+
+static void gen7_ps_opacity(void)
+{
+       uint32_t store[1024];
+       struct brw_compile p;
+
+       brw_compile_init(&p, GEN, store);
+       brw_wm_kernel__affine_opacity(&p, 16);
+
+       compare(ps_kernel_nomask_affine);
+}
+
+void brw_test_gen7(void)
+{
+       gen7_ps_nomask_affine();
+       gen7_ps_mask_affine();
+       gen7_ps_maskca_affine();
+       gen7_ps_masksa_affine();
+
+       gen7_ps_nomask_projective();
+
+       gen7_ps_opacity();
+}
diff --git a/src/sna/brw/brw_wm.c b/src/sna/brw/brw_wm.c
new file mode 100644 (file)
index 0000000..f54e55e
--- /dev/null
@@ -0,0 +1,681 @@
+#include "brw.h"
+
+#define X16 8
+#define Y16 10
+
+static void brw_wm_xy(struct brw_compile *p, int dw)
+{
+       struct brw_reg r1 = brw_vec1_grf(1, 0);
+       struct brw_reg r1_uw = __retype_uw(r1);
+       struct brw_reg x_uw, y_uw;
+
+       brw_set_compression_control(p, BRW_COMPRESSION_NONE);
+
+       if (dw == 16) {
+               x_uw = brw_uw16_grf(30, 0);
+               y_uw = brw_uw16_grf(28, 0);
+       } else {
+               x_uw = brw_uw8_grf(30, 0);
+               y_uw = brw_uw8_grf(28, 0);
+       }
+
+       brw_ADD(p,
+               x_uw,
+               __stride(__suboffset(r1_uw, 4), 2, 4, 0),
+               brw_imm_v(0x10101010));
+       brw_ADD(p,
+               y_uw,
+               __stride(__suboffset(r1_uw, 5), 2, 4, 0),
+               brw_imm_v(0x11001100));
+
+       brw_set_compression_control(p, BRW_COMPRESSION_COMPRESSED);
+
+       brw_ADD(p, brw_vec8_grf(X16, 0), vec8(x_uw), brw_negate(r1));
+       brw_ADD(p, brw_vec8_grf(Y16, 0), vec8(y_uw), brw_negate(__suboffset(r1, 1)));
+}
+
+static void brw_wm_affine_st(struct brw_compile *p, int dw,
+                            int channel, int msg)
+{
+       int uv;
+
+       if (dw == 16) {
+               brw_set_compression_control(p, BRW_COMPRESSION_COMPRESSED);
+               uv = p->gen >= 60 ? 6 : 3;
+       } else {
+               brw_set_compression_control(p, BRW_COMPRESSION_NONE);
+               uv = p->gen >= 60 ? 4 : 3;
+       }
+       uv += 2*channel;
+
+       msg++;
+       if (p->gen >= 60) {
+               brw_PLN(p,
+                       brw_message_reg(msg),
+                       brw_vec1_grf(uv, 0),
+                       brw_vec8_grf(2, 0));
+               msg += dw/8;
+
+               brw_PLN(p,
+                       brw_message_reg(msg),
+                       brw_vec1_grf(uv, 4),
+                       brw_vec8_grf(2, 0));
+       } else {
+               struct brw_reg r = brw_vec1_grf(uv, 0);
+
+               brw_LINE(p, brw_null_reg(), __suboffset(r, 0), brw_vec8_grf(X16, 0));
+               brw_MAC(p, brw_message_reg(msg), __suboffset(r, 1), brw_vec8_grf(Y16, 0));
+               msg += dw/8;
+
+               brw_LINE(p, brw_null_reg(), __suboffset(r, 4), brw_vec8_grf(X16, 0));
+               brw_MAC(p, brw_message_reg(msg), __suboffset(r, 5), brw_vec8_grf(Y16, 0));
+       }
+}
+
+static inline unsigned simd(int dw)
+{
+       return dw == 16 ? BRW_SAMPLER_SIMD_MODE_SIMD16 : BRW_SAMPLER_SIMD_MODE_SIMD8;
+}
+
+static inline struct brw_reg sample_result(int dw, int result)
+{
+       return brw_reg(BRW_GENERAL_REGISTER_FILE, result, 0,
+                      BRW_REGISTER_TYPE_UW,
+                      dw == 16 ? BRW_VERTICAL_STRIDE_16 : BRW_VERTICAL_STRIDE_8,
+                      dw == 16 ? BRW_WIDTH_16 : BRW_WIDTH_8,
+                      BRW_HORIZONTAL_STRIDE_1,
+                      BRW_SWIZZLE_XYZW,
+                      WRITEMASK_XYZW);
+}
+
+static int brw_wm_sample(struct brw_compile *p, int dw,
+                        int channel, int msg, int result)
+{
+       struct brw_reg src0;
+       bool header;
+       int len;
+
+       len = dw == 16 ? 4 : 2;
+       if (p->gen >= 60) {
+               header = false;
+               src0 = brw_message_reg(++msg);
+       } else {
+               header = true;
+               src0 = brw_vec8_grf(0, 0);
+       }
+
+       brw_SAMPLE(p, sample_result(dw, result), msg, src0,
+                  channel+1, channel, WRITEMASK_XYZW, 0,
+                  2*len, len+header, header, simd(dw));
+       return result;
+}
+
+static int brw_wm_sample__alpha(struct brw_compile *p, int dw,
+                               int channel, int msg, int result)
+{
+       struct brw_reg src0;
+       int mlen, rlen;
+
+       if (dw == 8) {
+               /* SIMD8 sample return is not masked */
+               mlen = 3;
+               rlen = 4;
+       } else {
+               mlen = 5;
+               rlen = 2;
+       }
+
+       if (p->gen >= 60)
+               src0 = brw_message_reg(msg);
+       else
+               src0 = brw_vec8_grf(0, 0);
+
+       brw_SAMPLE(p, sample_result(dw, result), msg, src0,
+                  channel+1, channel, WRITEMASK_W, 0,
+                  rlen, mlen, true, simd(dw));
+
+       if (dw == 8)
+               result += 3;
+
+       return result;
+}
+
+static int brw_wm_affine(struct brw_compile *p, int dw,
+                        int channel, int msg, int result)
+{
+       brw_wm_affine_st(p, dw, channel, msg);
+       return brw_wm_sample(p, dw, channel, msg, result);
+}
+
+static int brw_wm_affine__alpha(struct brw_compile *p, int dw,
+                               int channel, int msg, int result)
+{
+       brw_wm_affine_st(p, dw, channel, msg);
+       return brw_wm_sample__alpha(p, dw, channel, msg, result);
+}
+
+static inline struct brw_reg null_result(int dw)
+{
+       return brw_reg(BRW_ARCHITECTURE_REGISTER_FILE, BRW_ARF_NULL, 0,
+                      BRW_REGISTER_TYPE_UW,
+                      dw == 16 ? BRW_VERTICAL_STRIDE_16 : BRW_VERTICAL_STRIDE_8,
+                      dw == 16 ? BRW_WIDTH_16 : BRW_WIDTH_8,
+                      BRW_HORIZONTAL_STRIDE_1,
+                      BRW_SWIZZLE_XYZW,
+                      WRITEMASK_XYZW);
+}
+
+static void brw_fb_write(struct brw_compile *p, int dw)
+{
+       struct brw_instruction *insn;
+       unsigned msg_control, msg_type, msg_len;
+       struct brw_reg src0;
+       bool header;
+
+       if (dw == 16) {
+               brw_set_compression_control(p, BRW_COMPRESSION_COMPRESSED);
+               msg_control = BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD16_SINGLE_SOURCE;
+               msg_len = 8;
+       } else {
+               brw_set_compression_control(p, BRW_COMPRESSION_NONE);
+               msg_control = BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD8_SINGLE_SOURCE_SUBSPAN01;
+               msg_len = 4;
+       }
+
+       if (p->gen < 60) {
+               brw_push_insn_state(p);
+               brw_set_compression_control(p, BRW_COMPRESSION_NONE);
+               brw_set_mask_control(p, BRW_MASK_DISABLE);
+               brw_MOV(p, brw_message_reg(1), brw_vec8_grf(1, 0));
+               brw_pop_insn_state(p);
+
+               msg_len += 2;
+       }
+
+       /* The execution mask is ignored for render target writes. */
+       insn = brw_next_insn(p, BRW_OPCODE_SEND);
+       insn->header.predicate_control = 0;
+       insn->header.compression_control = BRW_COMPRESSION_NONE;
+
+       if (p->gen >= 60) {
+               msg_type = GEN6_DATAPORT_WRITE_MESSAGE_RENDER_TARGET_WRITE;
+               src0 = brw_message_reg(2);
+               header = false;
+       } else {
+               insn->header.destreg__conditionalmod = 0;
+               msg_type = BRW_DATAPORT_WRITE_MESSAGE_RENDER_TARGET_WRITE;
+               src0 = __retype_uw(brw_vec8_grf(0, 0));
+               header = true;
+       }
+
+       brw_set_dest(p, insn, null_result(dw));
+       brw_set_src0(p, insn, src0);
+       brw_set_dp_write_message(p, insn, 0,
+                                msg_control, msg_type, msg_len,
+                                header, true, 0, true, false);
+}
+
+static void brw_wm_write(struct brw_compile *p, int dw, int src)
+{
+       int n;
+
+       if (dw == 8 && p->gen >= 60) {
+               /* XXX pixel execution mask? */
+               brw_set_compression_control(p, BRW_COMPRESSION_NONE);
+
+               brw_MOV(p, brw_message_reg(2), brw_vec8_grf(src+0, 0));
+               brw_MOV(p, brw_message_reg(3), brw_vec8_grf(src+1, 0));
+               brw_MOV(p, brw_message_reg(4), brw_vec8_grf(src+2, 0));
+               brw_MOV(p, brw_message_reg(5), brw_vec8_grf(src+3, 0));
+               goto done;
+       }
+
+       brw_set_compression_control(p, BRW_COMPRESSION_COMPRESSED);
+
+       for (n = 0; n < 4; n++) {
+               if (p->gen >= 60) {
+                       brw_MOV(p,
+                               brw_message_reg(2 + 2*n),
+                               brw_vec8_grf(src + 2*n, 0));
+               } else if (p->gen >= 45 && dw == 16) {
+                       brw_MOV(p,
+                               brw_message_reg(2 + n + BRW_MRF_COMPR4),
+                               brw_vec8_grf(src + 2*n, 0));
+               } else {
+                       brw_set_compression_control(p, BRW_COMPRESSION_NONE);
+                       brw_MOV(p,
+                               brw_message_reg(2 + n),
+                               brw_vec8_grf(src + 2*n, 0));
+
+                       if (dw == 16) {
+                               brw_set_compression_control(p, BRW_COMPRESSION_2NDHALF);
+                               brw_MOV(p,
+                                       brw_message_reg(2 + n + 4),
+                                       brw_vec8_grf(src + 2*n+1, 0));
+                       }
+               }
+       }
+
+done:
+       brw_fb_write(p, dw);
+}
+
+static void brw_wm_write__mask(struct brw_compile *p, int dw,
+                              int src, int mask)
+{
+       int n;
+
+       if (dw == 8 && p->gen >= 60) {
+               brw_set_compression_control(p, BRW_COMPRESSION_NONE);
+
+               brw_MUL(p,
+                       brw_message_reg(2),
+                       brw_vec8_grf(src+0, 0),
+                       brw_vec8_grf(mask, 0));
+               brw_MUL(p,
+                       brw_message_reg(3),
+                       brw_vec8_grf(src+1, 0),
+                       brw_vec8_grf(mask, 0));
+               brw_MUL(p,
+                       brw_message_reg(4),
+                       brw_vec8_grf(src+2, 0),
+                       brw_vec8_grf(mask, 0));
+               brw_MUL(p,
+                       brw_message_reg(5),
+                       brw_vec8_grf(src+3, 0),
+                       brw_vec8_grf(mask, 0));
+
+               goto done;
+       }
+
+       brw_set_compression_control(p, BRW_COMPRESSION_COMPRESSED);
+
+       for (n = 0; n < 4; n++) {
+               if (p->gen >= 60) {
+                       brw_MUL(p,
+                               brw_message_reg(2 + 2*n),
+                               brw_vec8_grf(src + 2*n, 0),
+                               brw_vec8_grf(mask, 0));
+               } else if (p->gen >= 45 && dw == 16) {
+                       brw_MUL(p,
+                               brw_message_reg(2 + n + BRW_MRF_COMPR4),
+                               brw_vec8_grf(src + 2*n, 0),
+                               brw_vec8_grf(mask, 0));
+               } else {
+                       brw_set_compression_control(p, BRW_COMPRESSION_NONE);
+                       brw_MUL(p,
+                               brw_message_reg(2 + n),
+                               brw_vec8_grf(src + 2*n, 0),
+                               brw_vec8_grf(mask, 0));
+
+                       if (dw == 16) {
+                               brw_set_compression_control(p, BRW_COMPRESSION_2NDHALF);
+                               brw_MUL(p,
+                                       brw_message_reg(2 + n + 4),
+                                       brw_vec8_grf(src + 2*n+1, 0),
+                                       brw_vec8_grf(mask+1, 0));
+                       }
+               }
+       }
+
+done:
+       brw_fb_write(p, dw);
+}
+
+static void brw_wm_write__opacity(struct brw_compile *p, int dw,
+                                 int src, int mask)
+{
+       int n;
+
+       if (dw == 8 && p->gen >= 60) {
+               brw_set_compression_control(p, BRW_COMPRESSION_NONE);
+
+               brw_MUL(p,
+                       brw_message_reg(2),
+                       brw_vec8_grf(src+0, 0),
+                       brw_vec1_grf(mask, 3));
+               brw_MUL(p,
+                       brw_message_reg(3),
+                       brw_vec8_grf(src+1, 0),
+                       brw_vec1_grf(mask, 3));
+               brw_MUL(p,
+                       brw_message_reg(4),
+                       brw_vec8_grf(src+2, 0),
+                       brw_vec1_grf(mask, 3));
+               brw_MUL(p,
+                       brw_message_reg(5),
+                       brw_vec8_grf(src+3, 0),
+                       brw_vec1_grf(mask, 3));
+
+               goto done;
+       }
+
+       brw_set_compression_control(p, BRW_COMPRESSION_COMPRESSED);
+
+       for (n = 0; n < 4; n++) {
+               if (p->gen >= 60) {
+                       brw_MUL(p,
+                               brw_message_reg(2 + 2*n),
+                               brw_vec8_grf(src + 2*n, 0),
+                               brw_vec1_grf(mask, 3));
+               } else if (p->gen >= 45 && dw == 16) {
+                       brw_MUL(p,
+                               brw_message_reg(2 + n + BRW_MRF_COMPR4),
+                               brw_vec8_grf(src + 2*n, 0),
+                               brw_vec1_grf(mask, 3));
+               } else {
+                       brw_set_compression_control(p, BRW_COMPRESSION_NONE);
+                       brw_MUL(p,
+                               brw_message_reg(2 + n),
+                               brw_vec8_grf(src + 2*n, 0),
+                               brw_vec1_grf(mask, 3));
+
+                       if (dw == 16) {
+                               brw_set_compression_control(p, BRW_COMPRESSION_2NDHALF);
+                               brw_MUL(p,
+                                       brw_message_reg(2 + n + 4),
+                                       brw_vec8_grf(src + 2*n+1, 0),
+                                       brw_vec1_grf(mask, 3));
+                       }
+               }
+       }
+
+done:
+       brw_fb_write(p, dw);
+}
+
+static void brw_wm_write__mask_ca(struct brw_compile *p, int dw,
+                                 int src, int mask)
+{
+       int n;
+
+       if (dw == 8 && p->gen >= 60) {
+               brw_set_compression_control(p, BRW_COMPRESSION_NONE);
+
+               brw_MUL(p,
+                       brw_message_reg(2),
+                       brw_vec8_grf(src  + 0, 0),
+                       brw_vec8_grf(mask + 0, 0));
+               brw_MUL(p,
+                       brw_message_reg(3),
+                       brw_vec8_grf(src  + 1, 0),
+                       brw_vec8_grf(mask + 1, 0));
+               brw_MUL(p,
+                       brw_message_reg(4),
+                       brw_vec8_grf(src  + 2, 0),
+                       brw_vec8_grf(mask + 2, 0));
+               brw_MUL(p,
+                       brw_message_reg(5),
+                       brw_vec8_grf(src  + 3, 0),
+                       brw_vec8_grf(mask + 3, 0));
+
+               goto done;
+       }
+
+       brw_set_compression_control(p, BRW_COMPRESSION_COMPRESSED);
+
+       for (n = 0; n < 4; n++) {
+               if (p->gen >= 60) {
+                       brw_MUL(p,
+                               brw_message_reg(2 + 2*n),
+                               brw_vec8_grf(src + 2*n, 0),
+                               brw_vec8_grf(mask + 2*n, 0));
+               } else if (p->gen >= 45 && dw == 16) {
+                       brw_MUL(p,
+                               brw_message_reg(2 + n + BRW_MRF_COMPR4),
+                               brw_vec8_grf(src + 2*n, 0),
+                               brw_vec8_grf(mask + 2*n, 0));
+               } else {
+                       brw_set_compression_control(p, BRW_COMPRESSION_NONE);
+                       brw_MUL(p,
+                               brw_message_reg(2 + n),
+                               brw_vec8_grf(src + 2*n, 0),
+                               brw_vec8_grf(mask + 2*n, 0));
+
+                       if (dw == 16) {
+                               brw_set_compression_control(p, BRW_COMPRESSION_2NDHALF);
+                               brw_MUL(p,
+                                       brw_message_reg(2 + n + 4),
+                                       brw_vec8_grf(src + 2*n + 1, 0),
+                                       brw_vec8_grf(mask + 2*n + 1, 0));
+                       }
+               }
+       }
+
+done:
+       brw_fb_write(p, dw);
+}
+
+bool
+brw_wm_kernel__affine(struct brw_compile *p, int dispatch)
+{
+       if (p->gen < 60)
+               brw_wm_xy(p, dispatch);
+       brw_wm_write(p, dispatch, brw_wm_affine(p, dispatch, 0, 1, 12));
+
+       return true;
+}
+
+bool
+brw_wm_kernel__affine_mask(struct brw_compile *p, int dispatch)
+{
+       int src, mask;
+
+       if (p->gen < 60)
+               brw_wm_xy(p, dispatch);
+
+       src = brw_wm_affine(p, dispatch, 0, 1, 12);
+       mask = brw_wm_affine__alpha(p, dispatch, 1, 6, 20);
+       brw_wm_write__mask(p, dispatch, src, mask);
+
+       return true;
+}
+
+bool
+brw_wm_kernel__affine_mask_ca(struct brw_compile *p, int dispatch)
+{
+       int src, mask;
+
+       if (p->gen < 60)
+               brw_wm_xy(p, dispatch);
+
+       src = brw_wm_affine(p, dispatch, 0, 1, 12);
+       mask = brw_wm_affine(p, dispatch, 1, 6, 20);
+       brw_wm_write__mask_ca(p, dispatch, src, mask);
+
+       return true;
+}
+
+bool
+brw_wm_kernel__affine_mask_sa(struct brw_compile *p, int dispatch)
+{
+       int src, mask;
+
+       if (p->gen < 60)
+               brw_wm_xy(p, dispatch);
+
+       src = brw_wm_affine__alpha(p, dispatch, 0, 1, 12);
+       mask = brw_wm_affine(p, dispatch, 1, 6, 16);
+       brw_wm_write__mask(p, dispatch, mask, src);
+
+       return true;
+}
+
+/* Projective variants */
+
+static void brw_wm_projective_st(struct brw_compile *p, int dw,
+                                int channel, int msg)
+{
+       int uv;
+
+       if (dw == 16) {
+               brw_set_compression_control(p, BRW_COMPRESSION_COMPRESSED);
+               uv = p->gen >= 60 ? 6 : 3;
+       } else {
+               brw_set_compression_control(p, BRW_COMPRESSION_NONE);
+               uv = p->gen >= 60 ? 4 : 3;
+       }
+       uv += 2*channel;
+
+       msg++;
+       if (p->gen >= 60) {
+               /* First compute 1/z */
+               brw_PLN(p,
+                       brw_message_reg(msg),
+                       brw_vec1_grf(uv+1, 0),
+                       brw_vec8_grf(2, 0));
+
+               if (dw == 16) {
+                       brw_set_compression_control(p, BRW_COMPRESSION_NONE);
+                       brw_math_invert(p, brw_vec8_grf(30, 0), brw_vec8_grf(30, 0));
+                       brw_math_invert(p, brw_vec8_grf(31, 0), brw_vec8_grf(31, 0));
+                       brw_set_compression_control(p, BRW_COMPRESSION_COMPRESSED);
+               } else
+                       brw_math_invert(p, brw_vec8_grf(30, 0), brw_vec8_grf(30, 0));
+               brw_PLN(p,
+                       brw_vec8_grf(28, 0),
+                       brw_vec1_grf(uv, 0),
+                       brw_vec8_grf(2, 0));
+               brw_MUL(p,
+                       brw_message_reg(msg),
+                       brw_vec8_grf(28, 0),
+                       brw_vec8_grf(30, 0));
+               msg += dw/8;
+
+               brw_PLN(p,
+                       brw_vec8_grf(28, 0),
+                       brw_vec1_grf(uv, 0),
+                       brw_vec8_grf(4, 0));
+               brw_MUL(p,
+                       brw_message_reg(msg),
+                       brw_vec8_grf(28, 0),
+                       brw_vec8_grf(30, 0));
+       } else {
+               struct brw_reg r = brw_vec1_grf(uv, 0);
+
+               /* First compute 1/z */
+               brw_LINE(p, brw_null_reg(), brw_vec1_grf(uv+1, 0), brw_vec8_grf(X16, 0));
+               brw_MAC(p, brw_vec8_grf(30, 0), brw_vec1_grf(uv+1, 1), brw_vec8_grf(Y16, 0));
+
+               if (dw == 16) {
+                       brw_set_compression_control(p, BRW_COMPRESSION_NONE);
+                       brw_math_invert(p, brw_vec8_grf(30, 0), brw_vec8_grf(30, 0));
+                       brw_math_invert(p, brw_vec8_grf(31, 0), brw_vec8_grf(31, 0));
+                       brw_set_compression_control(p, BRW_COMPRESSION_COMPRESSED);
+               } else
+                       brw_math_invert(p, brw_vec8_grf(30, 0), brw_vec8_grf(30, 0));
+
+               /* Now compute the output s,t values */
+               brw_LINE(p, brw_null_reg(), __suboffset(r, 0), brw_vec8_grf(X16, 0));
+               brw_MAC(p, brw_vec8_grf(28, 0), __suboffset(r, 1), brw_vec8_grf(Y16, 0));
+               brw_MUL(p, brw_message_reg(msg), brw_vec8_grf(28, 0), brw_vec8_grf(30, 0));
+               msg += dw/8;
+
+               brw_LINE(p, brw_null_reg(), __suboffset(r, 4), brw_vec8_grf(X16, 0));
+               brw_MAC(p, brw_vec8_grf(28, 0), __suboffset(r, 5), brw_vec8_grf(Y16, 0));
+               brw_MUL(p, brw_message_reg(msg), brw_vec8_grf(28, 0), brw_vec8_grf(30, 0));
+       }
+}
+
+static int brw_wm_projective(struct brw_compile *p, int dw,
+                            int channel, int msg, int result)
+{
+       brw_wm_projective_st(p, dw, channel, msg);
+       return brw_wm_sample(p, dw, channel, msg, result);
+}
+
+static int brw_wm_projective__alpha(struct brw_compile *p, int dw,
+                                    int channel, int msg, int result)
+{
+       brw_wm_projective_st(p, dw, channel, msg);
+       return brw_wm_sample__alpha(p, dw, channel, msg, result);
+}
+
+bool
+brw_wm_kernel__projective(struct brw_compile *p, int dispatch)
+{
+       if (p->gen < 60)
+               brw_wm_xy(p, dispatch);
+       brw_wm_write(p, dispatch, brw_wm_projective(p, dispatch, 0, 1, 12));
+
+       return true;
+}
+
+bool
+brw_wm_kernel__projective_mask(struct brw_compile *p, int dispatch)
+{
+       int src, mask;
+
+       if (p->gen < 60)
+               brw_wm_xy(p, dispatch);
+
+       src = brw_wm_projective(p, dispatch, 0, 1, 12);
+       mask = brw_wm_projective__alpha(p, dispatch, 1, 6, 20);
+       brw_wm_write__mask(p, dispatch, src, mask);
+
+       return true;
+}
+
+bool
+brw_wm_kernel__projective_mask_ca(struct brw_compile *p, int dispatch)
+{
+       int src, mask;
+
+       if (p->gen < 60)
+               brw_wm_xy(p, dispatch);
+
+       src = brw_wm_projective(p, dispatch, 0, 1, 12);
+       mask = brw_wm_projective(p, dispatch, 1, 6, 20);
+       brw_wm_write__mask_ca(p, dispatch, src, mask);
+
+       return true;
+}
+
+bool
+brw_wm_kernel__projective_mask_sa(struct brw_compile *p, int dispatch)
+{
+       int src, mask;
+
+       if (p->gen < 60)
+               brw_wm_xy(p, dispatch);
+
+       src = brw_wm_projective__alpha(p, dispatch, 0, 1, 12);
+       mask = brw_wm_projective(p, dispatch, 1, 6, 16);
+       brw_wm_write__mask(p, dispatch, mask, src);
+
+       return true;
+}
+
+bool
+brw_wm_kernel__affine_opacity(struct brw_compile *p, int dispatch)
+{
+       int src, mask;
+
+       if (p->gen < 60) {
+               brw_wm_xy(p, dispatch);
+               mask = 4;
+       } else
+               mask = dispatch == 16 ? 8 : 6;
+
+       src = brw_wm_affine(p, dispatch, 0, 1, 12);
+       brw_wm_write__opacity(p, dispatch, src, mask);
+
+       return true;
+}
+
+bool
+brw_wm_kernel__projective_opacity(struct brw_compile *p, int dispatch)
+{
+       int src, mask;
+
+       if (p->gen < 60) {
+               brw_wm_xy(p, dispatch);
+               mask = 4;
+       } else
+               mask = dispatch == 16 ? 8 : 6;
+
+       src = brw_wm_projective(p, dispatch, 0, 1, 12);
+       brw_wm_write__opacity(p, dispatch, src, mask);
+
+       return true;
+}
diff --git a/src/sna/compiler.h b/src/sna/compiler.h
new file mode 100644 (file)
index 0000000..ff80365
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2011 Intel 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.
+ *
+ * Authors:
+ *    Chris Wilson <chris@chris-wilson.co.uk>
+ *
+ */
+
+#ifndef _SNA_COMPILER_H_
+#define _SNA_COMPILER_H_
+
+#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
+#define likely(expr) (__builtin_expect (!!(expr), 1))
+#define unlikely(expr) (__builtin_expect (!!(expr), 0))
+#define noinline __attribute__((noinline))
+#define force_inline inline __attribute__((always_inline))
+#define fastcall __attribute__((regparm(3)))
+#define must_check __attribute__((warn_unused_result))
+#define constant __attribute__((const))
+#else
+#define likely(expr) (expr)
+#define unlikely(expr) (expr)
+#define noinline
+#define force_inline
+#define fastcall
+#define must_check
+#define constant
+#endif
+
+#ifdef HAVE_VALGRIND
+#define VG(x) x
+#else
+#define VG(x)
+#endif
+
+#define VG_CLEAR(s) VG(memset(&s, 0, sizeof(s)))
+
+#define COMPILE_TIME_ASSERT(E) ((void)sizeof(char[1 - 2*!(E)]))
+
+#endif /* _SNA_COMPILER_H_ */
diff --git a/src/sna/fb/Makefile.am b/src/sna/fb/Makefile.am
new file mode 100644 (file)
index 0000000..72d9bbf
--- /dev/null
@@ -0,0 +1,38 @@
+noinst_LTLIBRARIES = libfb.la
+
+libfb_la_CFLAGS = @CWARNFLAGS@ @XORG_CFLAGS@
+libfb_la_LIBADD = $(PIXMAN_LIBS)
+
+libfb_la_SOURCES =     \
+       fb.h            \
+       sfb.h           \
+       fbarc.c         \
+       fbarcbits.h     \
+       fbbitmap.c      \
+       fbblt.c         \
+       fbbltone.c      \
+       fbclip.c        \
+       fbclip.h        \
+       fbcopy.c        \
+       fbfill.c        \
+       fbgc.c          \
+       fbglyph.c       \
+       fbglyphbits.h   \
+       fbimage.c       \
+       fbline.c        \
+       fblinebits.h    \
+       fbpict.c        \
+       fbpict.h        \
+       fbpoint.c       \
+       fbpointbits.h   \
+       fbpush.c        \
+       fbrop.h         \
+       fbseg.c         \
+       fbsegbits.h     \
+       fbspan.c        \
+       fbstipple.c     \
+       fbtile.c        \
+       fbutil.c        \
+       $(NULL)
+
+EXTRA_DIST = README
diff --git a/src/sna/fb/Makefile.in b/src/sna/fb/Makefile.in
new file mode 100644 (file)
index 0000000..dee77af
--- /dev/null
@@ -0,0 +1,754 @@
+# Makefile.in generated by automake 1.11.6 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
+# Foundation, Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+
+VPATH = @srcdir@
+am__make_dryrun = \
+  { \
+    am__dry=no; \
+    case $$MAKEFLAGS in \
+      *\\[\ \  ]*) \
+        echo 'am--echo: ; @echo "AM"  OK' | $(MAKE) -f - 2>/dev/null \
+          | grep '^AM OK$$' >/dev/null || am__dry=yes;; \
+      *) \
+        for am__flg in $$MAKEFLAGS; do \
+          case $$am__flg in \
+            *=*|--*) ;; \
+            *n*) am__dry=yes; break;; \
+          esac; \
+        done;; \
+    esac; \
+    test $$am__dry = yes; \
+  }
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+subdir = src/sna/fb
+DIST_COMMON = README $(srcdir)/Makefile.am $(srcdir)/Makefile.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+       $(ACLOCAL_M4)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+LTLIBRARIES = $(noinst_LTLIBRARIES)
+libfb_la_DEPENDENCIES =
+am_libfb_la_OBJECTS = libfb_la-fbarc.lo libfb_la-fbbitmap.lo \
+       libfb_la-fbblt.lo libfb_la-fbbltone.lo libfb_la-fbclip.lo \
+       libfb_la-fbcopy.lo libfb_la-fbfill.lo libfb_la-fbgc.lo \
+       libfb_la-fbglyph.lo libfb_la-fbimage.lo libfb_la-fbline.lo \
+       libfb_la-fbpict.lo libfb_la-fbpoint.lo libfb_la-fbpush.lo \
+       libfb_la-fbseg.lo libfb_la-fbspan.lo libfb_la-fbstipple.lo \
+       libfb_la-fbtile.lo libfb_la-fbutil.lo
+libfb_la_OBJECTS = $(am_libfb_la_OBJECTS)
+AM_V_lt = $(am__v_lt_@AM_V@)
+am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
+am__v_lt_0 = --silent
+libfb_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+       $(LIBTOOLFLAGS) --mode=link $(CCLD) $(libfb_la_CFLAGS) \
+       $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
+DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
+depcomp = $(SHELL) $(top_srcdir)/depcomp
+am__depfiles_maybe = depfiles
+am__mv = mv -f
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+       $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+       $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \
+       $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
+       $(AM_CFLAGS) $(CFLAGS)
+AM_V_CC = $(am__v_CC_@AM_V@)
+am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@)
+am__v_CC_0 = @echo "  CC    " $@;
+AM_V_at = $(am__v_at_@AM_V@)
+am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
+am__v_at_0 = @
+CCLD = $(CC)
+LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+       $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+       $(AM_LDFLAGS) $(LDFLAGS) -o $@
+AM_V_CCLD = $(am__v_CCLD_@AM_V@)
+am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
+am__v_CCLD_0 = @echo "  CCLD  " $@;
+AM_V_GEN = $(am__v_GEN_@AM_V@)
+am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
+am__v_GEN_0 = @echo "  GEN   " $@;
+SOURCES = $(libfb_la_SOURCES)
+DIST_SOURCES = $(libfb_la_SOURCES)
+am__can_run_installinfo = \
+  case $$AM_UPDATE_INFO_DIR in \
+    n|no|NO) false;; \
+    *) (install-info --version) >/dev/null 2>&1;; \
+  esac
+ETAGS = etags
+CTAGS = ctags
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+ADMIN_MAN_DIR = @ADMIN_MAN_DIR@
+ADMIN_MAN_SUFFIX = @ADMIN_MAN_SUFFIX@
+AMTAR = @AMTAR@
+AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
+APP_MAN_DIR = @APP_MAN_DIR@
+APP_MAN_SUFFIX = @APP_MAN_SUFFIX@
+AR = @AR@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+BASE_CFLAGS = @BASE_CFLAGS@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CHANGELOG_CMD = @CHANGELOG_CMD@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CWARNFLAGS = @CWARNFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DLLTOOL = @DLLTOOL@
+DRI2_CFLAGS = @DRI2_CFLAGS@
+DRI2_LIBS = @DRI2_LIBS@
+DRIVER_MAN_DIR = @DRIVER_MAN_DIR@
+DRIVER_MAN_SUFFIX = @DRIVER_MAN_SUFFIX@
+DRIVER_NAME = @DRIVER_NAME@
+DRI_CFLAGS = @DRI_CFLAGS@
+DRI_LIBS = @DRI_LIBS@
+DRMINTEL_CFLAGS = @DRMINTEL_CFLAGS@
+DRMINTEL_LIBS = @DRMINTEL_LIBS@
+DRM_CFLAGS = @DRM_CFLAGS@
+DRM_LIBS = @DRM_LIBS@
+DSYMUTIL = @DSYMUTIL@
+DUMPBIN = @DUMPBIN@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+FGREP = @FGREP@
+FILE_MAN_DIR = @FILE_MAN_DIR@
+FILE_MAN_SUFFIX = @FILE_MAN_SUFFIX@
+GEN4ASM_CFLAGS = @GEN4ASM_CFLAGS@
+GEN4ASM_LIBS = @GEN4ASM_LIBS@
+GREP = @GREP@
+INSTALL = @INSTALL@
+INSTALL_CMD = @INSTALL_CMD@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+LD = @LD@
+LDFLAGS = @LDFLAGS@
+LIBGLAMOR_CFLAGS = @LIBGLAMOR_CFLAGS@
+LIBGLAMOR_EGL_CFLAGS = @LIBGLAMOR_EGL_CFLAGS@
+LIBGLAMOR_EGL_LIBS = @LIBGLAMOR_EGL_LIBS@
+LIBGLAMOR_LIBS = @LIBGLAMOR_LIBS@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBTOOL = @LIBTOOL@
+LIB_MAN_DIR = @LIB_MAN_DIR@
+LIB_MAN_SUFFIX = @LIB_MAN_SUFFIX@
+LIPO = @LIPO@
+LN_S = @LN_S@
+LTLIBOBJS = @LTLIBOBJS@
+MAINT = @MAINT@
+MAKEINFO = @MAKEINFO@
+MANIFEST_TOOL = @MANIFEST_TOOL@
+MAN_SUBSTS = @MAN_SUBSTS@
+MISC_MAN_DIR = @MISC_MAN_DIR@
+MISC_MAN_SUFFIX = @MISC_MAN_SUFFIX@
+MKDIR_P = @MKDIR_P@
+NM = @NM@
+NMEDIT = @NMEDIT@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+OTOOL = @OTOOL@
+OTOOL64 = @OTOOL64@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_URL = @PACKAGE_URL@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PCIACCESS_CFLAGS = @PCIACCESS_CFLAGS@
+PCIACCESS_LIBS = @PCIACCESS_LIBS@
+PKG_CONFIG = @PKG_CONFIG@
+PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
+PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
+RANLIB = @RANLIB@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STRICT_CFLAGS = @STRICT_CFLAGS@
+STRIP = @STRIP@
+UDEV_CFLAGS = @UDEV_CFLAGS@
+UDEV_LIBS = @UDEV_LIBS@
+VALGRIND_CFLAGS = @VALGRIND_CFLAGS@
+VALGRIND_LIBS = @VALGRIND_LIBS@
+VERSION = @VERSION@
+X11_CFLAGS = @X11_CFLAGS@
+X11_LIBS = @X11_LIBS@
+XORG_CFLAGS = @XORG_CFLAGS@
+XORG_LIBS = @XORG_LIBS@
+XORG_MAN_PAGE = @XORG_MAN_PAGE@
+XVMCLIB_CFLAGS = @XVMCLIB_CFLAGS@
+XVMCLIB_LIBS = @XVMCLIB_LIBS@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_AR = @ac_ct_AR@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+moduledir = @moduledir@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+noinst_LTLIBRARIES = libfb.la
+libfb_la_CFLAGS = @CWARNFLAGS@ @XORG_CFLAGS@
+libfb_la_LIBADD = $(PIXMAN_LIBS)
+libfb_la_SOURCES = \
+       fb.h            \
+       sfb.h           \
+       fbarc.c         \
+       fbarcbits.h     \
+       fbbitmap.c      \
+       fbblt.c         \
+       fbbltone.c      \
+       fbclip.c        \
+       fbclip.h        \
+       fbcopy.c        \
+       fbfill.c        \
+       fbgc.c          \
+       fbglyph.c       \
+       fbglyphbits.h   \
+       fbimage.c       \
+       fbline.c        \
+       fblinebits.h    \
+       fbpict.c        \
+       fbpict.h        \
+       fbpoint.c       \
+       fbpointbits.h   \
+       fbpush.c        \
+       fbrop.h         \
+       fbseg.c         \
+       fbsegbits.h     \
+       fbspan.c        \
+       fbstipple.c     \
+       fbtile.c        \
+       fbutil.c        \
+       $(NULL)
+
+EXTRA_DIST = README
+all: all-am
+
+.SUFFIXES:
+.SUFFIXES: .c .lo .o .obj
+$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am  $(am__configure_deps)
+       @for dep in $?; do \
+         case '$(am__configure_deps)' in \
+           *$$dep*) \
+             ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+               && { if test -f $@; then exit 0; else break; fi; }; \
+             exit 1;; \
+         esac; \
+       done; \
+       echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/sna/fb/Makefile'; \
+       $(am__cd) $(top_srcdir) && \
+         $(AUTOMAKE) --foreign src/sna/fb/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+       @case '$?' in \
+         *config.status*) \
+           cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+         *) \
+           echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+           cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+       esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+       cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
+       cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
+       cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+
+clean-noinstLTLIBRARIES:
+       -test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES)
+       @list='$(noinst_LTLIBRARIES)'; for p in $$list; do \
+         dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \
+         test "$$dir" != "$$p" || dir=.; \
+         echo "rm -f \"$${dir}/so_locations\""; \
+         rm -f "$${dir}/so_locations"; \
+       done
+libfb.la: $(libfb_la_OBJECTS) $(libfb_la_DEPENDENCIES) $(EXTRA_libfb_la_DEPENDENCIES) 
+       $(AM_V_CCLD)$(libfb_la_LINK)  $(libfb_la_OBJECTS) $(libfb_la_LIBADD) $(LIBS)
+
+mostlyclean-compile:
+       -rm -f *.$(OBJEXT)
+
+distclean-compile:
+       -rm -f *.tab.c
+
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfb_la-fbarc.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfb_la-fbbitmap.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfb_la-fbblt.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfb_la-fbbltone.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfb_la-fbclip.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfb_la-fbcopy.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfb_la-fbfill.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfb_la-fbgc.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfb_la-fbglyph.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfb_la-fbimage.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfb_la-fbline.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfb_la-fbpict.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfb_la-fbpoint.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfb_la-fbpush.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfb_la-fbseg.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfb_la-fbspan.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfb_la-fbstipple.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfb_la-fbtile.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfb_la-fbutil.Plo@am__quote@
+
+.c.o:
+@am__fastdepCC_TRUE@   $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(COMPILE) -c $<
+
+.c.obj:
+@am__fastdepCC_TRUE@   $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+@am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(COMPILE) -c `$(CYGPATH_W) '$<'`
+
+.c.lo:
+@am__fastdepCC_TRUE@   $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $<
+
+libfb_la-fbarc.lo: fbarc.c
+@am__fastdepCC_TRUE@   $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libfb_la_CFLAGS) $(CFLAGS) -MT libfb_la-fbarc.lo -MD -MP -MF $(DEPDIR)/libfb_la-fbarc.Tpo -c -o libfb_la-fbarc.lo `test -f 'fbarc.c' || echo '$(srcdir)/'`fbarc.c
+@am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) $(DEPDIR)/libfb_la-fbarc.Tpo $(DEPDIR)/libfb_la-fbarc.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='fbarc.c' object='libfb_la-fbarc.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libfb_la_CFLAGS) $(CFLAGS) -c -o libfb_la-fbarc.lo `test -f 'fbarc.c' || echo '$(srcdir)/'`fbarc.c
+
+libfb_la-fbbitmap.lo: fbbitmap.c
+@am__fastdepCC_TRUE@   $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libfb_la_CFLAGS) $(CFLAGS) -MT libfb_la-fbbitmap.lo -MD -MP -MF $(DEPDIR)/libfb_la-fbbitmap.Tpo -c -o libfb_la-fbbitmap.lo `test -f 'fbbitmap.c' || echo '$(srcdir)/'`fbbitmap.c
+@am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) $(DEPDIR)/libfb_la-fbbitmap.Tpo $(DEPDIR)/libfb_la-fbbitmap.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='fbbitmap.c' object='libfb_la-fbbitmap.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libfb_la_CFLAGS) $(CFLAGS) -c -o libfb_la-fbbitmap.lo `test -f 'fbbitmap.c' || echo '$(srcdir)/'`fbbitmap.c
+
+libfb_la-fbblt.lo: fbblt.c
+@am__fastdepCC_TRUE@   $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libfb_la_CFLAGS) $(CFLAGS) -MT libfb_la-fbblt.lo -MD -MP -MF $(DEPDIR)/libfb_la-fbblt.Tpo -c -o libfb_la-fbblt.lo `test -f 'fbblt.c' || echo '$(srcdir)/'`fbblt.c
+@am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) $(DEPDIR)/libfb_la-fbblt.Tpo $(DEPDIR)/libfb_la-fbblt.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='fbblt.c' object='libfb_la-fbblt.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libfb_la_CFLAGS) $(CFLAGS) -c -o libfb_la-fbblt.lo `test -f 'fbblt.c' || echo '$(srcdir)/'`fbblt.c
+
+libfb_la-fbbltone.lo: fbbltone.c
+@am__fastdepCC_TRUE@   $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libfb_la_CFLAGS) $(CFLAGS) -MT libfb_la-fbbltone.lo -MD -MP -MF $(DEPDIR)/libfb_la-fbbltone.Tpo -c -o libfb_la-fbbltone.lo `test -f 'fbbltone.c' || echo '$(srcdir)/'`fbbltone.c
+@am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) $(DEPDIR)/libfb_la-fbbltone.Tpo $(DEPDIR)/libfb_la-fbbltone.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='fbbltone.c' object='libfb_la-fbbltone.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libfb_la_CFLAGS) $(CFLAGS) -c -o libfb_la-fbbltone.lo `test -f 'fbbltone.c' || echo '$(srcdir)/'`fbbltone.c
+
+libfb_la-fbclip.lo: fbclip.c
+@am__fastdepCC_TRUE@   $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libfb_la_CFLAGS) $(CFLAGS) -MT libfb_la-fbclip.lo -MD -MP -MF $(DEPDIR)/libfb_la-fbclip.Tpo -c -o libfb_la-fbclip.lo `test -f 'fbclip.c' || echo '$(srcdir)/'`fbclip.c
+@am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) $(DEPDIR)/libfb_la-fbclip.Tpo $(DEPDIR)/libfb_la-fbclip.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='fbclip.c' object='libfb_la-fbclip.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libfb_la_CFLAGS) $(CFLAGS) -c -o libfb_la-fbclip.lo `test -f 'fbclip.c' || echo '$(srcdir)/'`fbclip.c
+
+libfb_la-fbcopy.lo: fbcopy.c
+@am__fastdepCC_TRUE@   $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libfb_la_CFLAGS) $(CFLAGS) -MT libfb_la-fbcopy.lo -MD -MP -MF $(DEPDIR)/libfb_la-fbcopy.Tpo -c -o libfb_la-fbcopy.lo `test -f 'fbcopy.c' || echo '$(srcdir)/'`fbcopy.c
+@am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) $(DEPDIR)/libfb_la-fbcopy.Tpo $(DEPDIR)/libfb_la-fbcopy.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='fbcopy.c' object='libfb_la-fbcopy.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libfb_la_CFLAGS) $(CFLAGS) -c -o libfb_la-fbcopy.lo `test -f 'fbcopy.c' || echo '$(srcdir)/'`fbcopy.c
+
+libfb_la-fbfill.lo: fbfill.c
+@am__fastdepCC_TRUE@   $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libfb_la_CFLAGS) $(CFLAGS) -MT libfb_la-fbfill.lo -MD -MP -MF $(DEPDIR)/libfb_la-fbfill.Tpo -c -o libfb_la-fbfill.lo `test -f 'fbfill.c' || echo '$(srcdir)/'`fbfill.c
+@am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) $(DEPDIR)/libfb_la-fbfill.Tpo $(DEPDIR)/libfb_la-fbfill.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='fbfill.c' object='libfb_la-fbfill.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libfb_la_CFLAGS) $(CFLAGS) -c -o libfb_la-fbfill.lo `test -f 'fbfill.c' || echo '$(srcdir)/'`fbfill.c
+
+libfb_la-fbgc.lo: fbgc.c
+@am__fastdepCC_TRUE@   $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libfb_la_CFLAGS) $(CFLAGS) -MT libfb_la-fbgc.lo -MD -MP -MF $(DEPDIR)/libfb_la-fbgc.Tpo -c -o libfb_la-fbgc.lo `test -f 'fbgc.c' || echo '$(srcdir)/'`fbgc.c
+@am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) $(DEPDIR)/libfb_la-fbgc.Tpo $(DEPDIR)/libfb_la-fbgc.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='fbgc.c' object='libfb_la-fbgc.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libfb_la_CFLAGS) $(CFLAGS) -c -o libfb_la-fbgc.lo `test -f 'fbgc.c' || echo '$(srcdir)/'`fbgc.c
+
+libfb_la-fbglyph.lo: fbglyph.c
+@am__fastdepCC_TRUE@   $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libfb_la_CFLAGS) $(CFLAGS) -MT libfb_la-fbglyph.lo -MD -MP -MF $(DEPDIR)/libfb_la-fbglyph.Tpo -c -o libfb_la-fbglyph.lo `test -f 'fbglyph.c' || echo '$(srcdir)/'`fbglyph.c
+@am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) $(DEPDIR)/libfb_la-fbglyph.Tpo $(DEPDIR)/libfb_la-fbglyph.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='fbglyph.c' object='libfb_la-fbglyph.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libfb_la_CFLAGS) $(CFLAGS) -c -o libfb_la-fbglyph.lo `test -f 'fbglyph.c' || echo '$(srcdir)/'`fbglyph.c
+
+libfb_la-fbimage.lo: fbimage.c
+@am__fastdepCC_TRUE@   $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libfb_la_CFLAGS) $(CFLAGS) -MT libfb_la-fbimage.lo -MD -MP -MF $(DEPDIR)/libfb_la-fbimage.Tpo -c -o libfb_la-fbimage.lo `test -f 'fbimage.c' || echo '$(srcdir)/'`fbimage.c
+@am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) $(DEPDIR)/libfb_la-fbimage.Tpo $(DEPDIR)/libfb_la-fbimage.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='fbimage.c' object='libfb_la-fbimage.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libfb_la_CFLAGS) $(CFLAGS) -c -o libfb_la-fbimage.lo `test -f 'fbimage.c' || echo '$(srcdir)/'`fbimage.c
+
+libfb_la-fbline.lo: fbline.c
+@am__fastdepCC_TRUE@   $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libfb_la_CFLAGS) $(CFLAGS) -MT libfb_la-fbline.lo -MD -MP -MF $(DEPDIR)/libfb_la-fbline.Tpo -c -o libfb_la-fbline.lo `test -f 'fbline.c' || echo '$(srcdir)/'`fbline.c
+@am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) $(DEPDIR)/libfb_la-fbline.Tpo $(DEPDIR)/libfb_la-fbline.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='fbline.c' object='libfb_la-fbline.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libfb_la_CFLAGS) $(CFLAGS) -c -o libfb_la-fbline.lo `test -f 'fbline.c' || echo '$(srcdir)/'`fbline.c
+
+libfb_la-fbpict.lo: fbpict.c
+@am__fastdepCC_TRUE@   $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libfb_la_CFLAGS) $(CFLAGS) -MT libfb_la-fbpict.lo -MD -MP -MF $(DEPDIR)/libfb_la-fbpict.Tpo -c -o libfb_la-fbpict.lo `test -f 'fbpict.c' || echo '$(srcdir)/'`fbpict.c
+@am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) $(DEPDIR)/libfb_la-fbpict.Tpo $(DEPDIR)/libfb_la-fbpict.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='fbpict.c' object='libfb_la-fbpict.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libfb_la_CFLAGS) $(CFLAGS) -c -o libfb_la-fbpict.lo `test -f 'fbpict.c' || echo '$(srcdir)/'`fbpict.c
+
+libfb_la-fbpoint.lo: fbpoint.c
+@am__fastdepCC_TRUE@   $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libfb_la_CFLAGS) $(CFLAGS) -MT libfb_la-fbpoint.lo -MD -MP -MF $(DEPDIR)/libfb_la-fbpoint.Tpo -c -o libfb_la-fbpoint.lo `test -f 'fbpoint.c' || echo '$(srcdir)/'`fbpoint.c
+@am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) $(DEPDIR)/libfb_la-fbpoint.Tpo $(DEPDIR)/libfb_la-fbpoint.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='fbpoint.c' object='libfb_la-fbpoint.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libfb_la_CFLAGS) $(CFLAGS) -c -o libfb_la-fbpoint.lo `test -f 'fbpoint.c' || echo '$(srcdir)/'`fbpoint.c
+
+libfb_la-fbpush.lo: fbpush.c
+@am__fastdepCC_TRUE@   $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libfb_la_CFLAGS) $(CFLAGS) -MT libfb_la-fbpush.lo -MD -MP -MF $(DEPDIR)/libfb_la-fbpush.Tpo -c -o libfb_la-fbpush.lo `test -f 'fbpush.c' || echo '$(srcdir)/'`fbpush.c
+@am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) $(DEPDIR)/libfb_la-fbpush.Tpo $(DEPDIR)/libfb_la-fbpush.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='fbpush.c' object='libfb_la-fbpush.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libfb_la_CFLAGS) $(CFLAGS) -c -o libfb_la-fbpush.lo `test -f 'fbpush.c' || echo '$(srcdir)/'`fbpush.c
+
+libfb_la-fbseg.lo: fbseg.c
+@am__fastdepCC_TRUE@   $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libfb_la_CFLAGS) $(CFLAGS) -MT libfb_la-fbseg.lo -MD -MP -MF $(DEPDIR)/libfb_la-fbseg.Tpo -c -o libfb_la-fbseg.lo `test -f 'fbseg.c' || echo '$(srcdir)/'`fbseg.c
+@am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) $(DEPDIR)/libfb_la-fbseg.Tpo $(DEPDIR)/libfb_la-fbseg.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='fbseg.c' object='libfb_la-fbseg.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libfb_la_CFLAGS) $(CFLAGS) -c -o libfb_la-fbseg.lo `test -f 'fbseg.c' || echo '$(srcdir)/'`fbseg.c
+
+libfb_la-fbspan.lo: fbspan.c
+@am__fastdepCC_TRUE@   $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libfb_la_CFLAGS) $(CFLAGS) -MT libfb_la-fbspan.lo -MD -MP -MF $(DEPDIR)/libfb_la-fbspan.Tpo -c -o libfb_la-fbspan.lo `test -f 'fbspan.c' || echo '$(srcdir)/'`fbspan.c
+@am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) $(DEPDIR)/libfb_la-fbspan.Tpo $(DEPDIR)/libfb_la-fbspan.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='fbspan.c' object='libfb_la-fbspan.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libfb_la_CFLAGS) $(CFLAGS) -c -o libfb_la-fbspan.lo `test -f 'fbspan.c' || echo '$(srcdir)/'`fbspan.c
+
+libfb_la-fbstipple.lo: fbstipple.c
+@am__fastdepCC_TRUE@   $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libfb_la_CFLAGS) $(CFLAGS) -MT libfb_la-fbstipple.lo -MD -MP -MF $(DEPDIR)/libfb_la-fbstipple.Tpo -c -o libfb_la-fbstipple.lo `test -f 'fbstipple.c' || echo '$(srcdir)/'`fbstipple.c
+@am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) $(DEPDIR)/libfb_la-fbstipple.Tpo $(DEPDIR)/libfb_la-fbstipple.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='fbstipple.c' object='libfb_la-fbstipple.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libfb_la_CFLAGS) $(CFLAGS) -c -o libfb_la-fbstipple.lo `test -f 'fbstipple.c' || echo '$(srcdir)/'`fbstipple.c
+
+libfb_la-fbtile.lo: fbtile.c
+@am__fastdepCC_TRUE@   $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libfb_la_CFLAGS) $(CFLAGS) -MT libfb_la-fbtile.lo -MD -MP -MF $(DEPDIR)/libfb_la-fbtile.Tpo -c -o libfb_la-fbtile.lo `test -f 'fbtile.c' || echo '$(srcdir)/'`fbtile.c
+@am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) $(DEPDIR)/libfb_la-fbtile.Tpo $(DEPDIR)/libfb_la-fbtile.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='fbtile.c' object='libfb_la-fbtile.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libfb_la_CFLAGS) $(CFLAGS) -c -o libfb_la-fbtile.lo `test -f 'fbtile.c' || echo '$(srcdir)/'`fbtile.c
+
+libfb_la-fbutil.lo: fbutil.c
+@am__fastdepCC_TRUE@   $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libfb_la_CFLAGS) $(CFLAGS) -MT libfb_la-fbutil.lo -MD -MP -MF $(DEPDIR)/libfb_la-fbutil.Tpo -c -o libfb_la-fbutil.lo `test -f 'fbutil.c' || echo '$(srcdir)/'`fbutil.c
+@am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) $(DEPDIR)/libfb_la-fbutil.Tpo $(DEPDIR)/libfb_la-fbutil.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='fbutil.c' object='libfb_la-fbutil.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libfb_la_CFLAGS) $(CFLAGS) -c -o libfb_la-fbutil.lo `test -f 'fbutil.c' || echo '$(srcdir)/'`fbutil.c
+
+mostlyclean-libtool:
+       -rm -f *.lo
+
+clean-libtool:
+       -rm -rf .libs _libs
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+       list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+       unique=`for i in $$list; do \
+           if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+         done | \
+         $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+             END { if (nonempty) { for (i in files) print i; }; }'`; \
+       mkid -fID $$unique
+tags: TAGS
+
+TAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+               $(TAGS_FILES) $(LISP)
+       set x; \
+       here=`pwd`; \
+       list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+       unique=`for i in $$list; do \
+           if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+         done | \
+         $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+             END { if (nonempty) { for (i in files) print i; }; }'`; \
+       shift; \
+       if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
+         test -n "$$unique" || unique=$$empty_fix; \
+         if test $$# -gt 0; then \
+           $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+             "$$@" $$unique; \
+         else \
+           $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+             $$unique; \
+         fi; \
+       fi
+ctags: CTAGS
+CTAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+               $(TAGS_FILES) $(LISP)
+       list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+       unique=`for i in $$list; do \
+           if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+         done | \
+         $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+             END { if (nonempty) { for (i in files) print i; }; }'`; \
+       test -z "$(CTAGS_ARGS)$$unique" \
+         || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+            $$unique
+
+GTAGS:
+       here=`$(am__cd) $(top_builddir) && pwd` \
+         && $(am__cd) $(top_srcdir) \
+         && gtags -i $(GTAGS_ARGS) "$$here"
+
+distclean-tags:
+       -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+distdir: $(DISTFILES)
+       @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+       topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+       list='$(DISTFILES)'; \
+         dist_files=`for file in $$list; do echo $$file; done | \
+         sed -e "s|^$$srcdirstrip/||;t" \
+             -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+       case $$dist_files in \
+         */*) $(MKDIR_P) `echo "$$dist_files" | \
+                          sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+                          sort -u` ;; \
+       esac; \
+       for file in $$dist_files; do \
+         if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+         if test -d $$d/$$file; then \
+           dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+           if test -d "$(distdir)/$$file"; then \
+             find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+           fi; \
+           if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+             cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+             find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+           fi; \
+           cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+         else \
+           test -f "$(distdir)/$$file" \
+           || cp -p $$d/$$file "$(distdir)/$$file" \
+           || exit 1; \
+         fi; \
+       done
+check-am: all-am
+check: check-am
+all-am: Makefile $(LTLIBRARIES)
+installdirs:
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+       @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+       if test -z '$(STRIP)'; then \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+             install; \
+       else \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+           "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+       fi
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+       -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+       -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+
+maintainer-clean-generic:
+       @echo "This command is intended for maintainers to use"
+       @echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-generic clean-libtool clean-noinstLTLIBRARIES \
+       mostlyclean-am
+
+distclean: distclean-am
+       -rm -rf ./$(DEPDIR)
+       -rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+       distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+html-am:
+
+info: info-am
+
+info-am:
+
+install-data-am:
+
+install-dvi: install-dvi-am
+
+install-dvi-am:
+
+install-exec-am:
+
+install-html: install-html-am
+
+install-html-am:
+
+install-info: install-info-am
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-am
+
+install-pdf-am:
+
+install-ps: install-ps-am
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+       -rm -rf ./$(DEPDIR)
+       -rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+       mostlyclean-libtool
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am:
+
+.MAKE: install-am install-strip
+
+.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
+       clean-libtool clean-noinstLTLIBRARIES ctags distclean \
+       distclean-compile distclean-generic distclean-libtool \
+       distclean-tags distdir dvi dvi-am html html-am info info-am \
+       install install-am install-data install-data-am install-dvi \
+       install-dvi-am install-exec install-exec-am install-html \
+       install-html-am install-info install-info-am install-man \
+       install-pdf install-pdf-am install-ps install-ps-am \
+       install-strip installcheck installcheck-am installdirs \
+       maintainer-clean maintainer-clean-generic mostlyclean \
+       mostlyclean-compile mostlyclean-generic mostlyclean-libtool \
+       pdf pdf-am ps ps-am tags uninstall uninstall-am
+
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/src/sna/fb/README b/src/sna/fb/README
new file mode 100644 (file)
index 0000000..1542124
--- /dev/null
@@ -0,0 +1 @@
+Note this code is intended to live inside pixman in the long term.
diff --git a/src/sna/fb/fb.h b/src/sna/fb/fb.h
new file mode 100644 (file)
index 0000000..e58e039
--- /dev/null
@@ -0,0 +1,566 @@
+/*
+ * Copyright © 1998 Keith Packard
+ * Copyright © 2012 Intel Corporation
+ *
+ * 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 Keith Packard not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission.  Keith Packard makes no
+ * representations about the suitability of this software for any purpose.  It
+ * is provided "as is" without express or implied warranty.
+ *
+ * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL KEITH PACKARD 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.
+ */
+
+#ifndef FB_H
+#define FB_H
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <xorg-server.h>
+#include <servermd.h>
+#include <gcstruct.h>
+#include <colormap.h>
+#include <windowstr.h>
+
+#include <stdbool.h>
+#include <pixman.h>
+
+#if HAS_DEBUG_FULL
+#define DBG(x) ErrorF x
+#else
+#define DBG(x)
+#endif
+
+#include "sfb.h"
+
+#define WRITE(ptr, val) (*(ptr) = (val))
+#define READ(ptr) (*(ptr))
+
+/*
+ * This single define controls the basic size of data manipulated
+ * by this software; it must be log2(sizeof (FbBits) * 8)
+ */
+#define FB_SHIFT    LOG2_BITMAP_PAD
+
+#define FB_UNIT            (1 << FB_SHIFT)
+#define FB_HALFUNIT (1 << (FB_SHIFT-1))
+#define FB_MASK            (FB_UNIT - 1)
+#define FB_ALLONES  ((FbBits) -1)
+
+#if IMAGE_BYTE_ORDER != LSBFirst
+#error "IMAGE_BYTE_ORDER must be LSBFirst"
+#endif
+
+#if GLYPHPADBYTES != 4
+#error "GLYPHPADBYTES must be 4"
+#endif
+
+#if FB_SHIFT != 5
+#error "FB_SHIFT ala LOG2_BITMAP_PAD must be 5"
+#endif
+
+#define FB_STIP_SHIFT  LOG2_BITMAP_PAD
+#define FB_STIP_UNIT   (1 << FB_STIP_SHIFT)
+#define FB_STIP_MASK   (FB_STIP_UNIT - 1)
+#define FB_STIP_ALLONES        ((FbStip) -1)
+#define FbFullMask(n)   ((n) == FB_UNIT ? FB_ALLONES : ((((FbBits) 1) << n) - 1))
+
+typedef uint32_t FbBits;
+typedef FbBits FbStip;
+typedef int FbStride;
+
+#include "fbrop.h"
+
+#define FbScrLeft(x,n) ((x) >> (n))
+#define FbScrRight(x,n)        ((x) << (n))
+/* #define FbLeftBits(x,n)     ((x) & ((((FbBits) 1) << (n)) - 1)) */
+#define FbLeftStipBits(x,n) ((x) & ((((FbStip) 1) << (n)) - 1))
+#define FbStipMoveLsb(x,s,n)   (FbStipRight (x,(s)-(n)))
+#define FbPatternOffsetBits    0
+
+#define FbStipLeft(x,n)        FbScrLeft(x,n)
+#define FbStipRight(x,n) FbScrRight(x,n)
+
+#define FbRotLeft(x,n) FbScrLeft(x,n) | (n ? FbScrRight(x,FB_UNIT-n) : 0)
+#define FbRotRight(x,n)        FbScrRight(x,n) | (n ? FbScrLeft(x,FB_UNIT-n) : 0)
+
+#define FbRotStipLeft(x,n)  FbStipLeft(x,n) | (n ? FbStipRight(x,FB_STIP_UNIT-n) : 0)
+#define FbRotStipRight(x,n)  FbStipRight(x,n) | (n ? FbStipLeft(x,FB_STIP_UNIT-n) : 0)
+
+#define FbLeftMask(x)      ( ((x) & FB_MASK) ? \
+                            FbScrRight(FB_ALLONES,(x) & FB_MASK) : 0)
+#define FbRightMask(x)     ( ((FB_UNIT - (x)) & FB_MASK) ? \
+                            FbScrLeft(FB_ALLONES,(FB_UNIT - (x)) & FB_MASK) : 0)
+
+#define FbLeftStipMask(x)   ( ((x) & FB_STIP_MASK) ? \
+                            FbStipRight(FB_STIP_ALLONES,(x) & FB_STIP_MASK) : 0)
+#define FbRightStipMask(x)  ( ((FB_STIP_UNIT - (x)) & FB_STIP_MASK) ? \
+                            FbScrLeft(FB_STIP_ALLONES,(FB_STIP_UNIT - (x)) & FB_STIP_MASK) : 0)
+
+#define FbBitsMask(x,w)        (FbScrRight(FB_ALLONES,(x) & FB_MASK) & \
+                        FbScrLeft(FB_ALLONES,(FB_UNIT - ((x) + (w))) & FB_MASK))
+
+#define FbStipMask(x,w)        (FbStipRight(FB_STIP_ALLONES,(x) & FB_STIP_MASK) & \
+                        FbStipLeft(FB_STIP_ALLONES,(FB_STIP_UNIT - ((x)+(w))) & FB_STIP_MASK))
+
+#define FbMaskBits(x,w,l,n,r) { \
+    n = (w); \
+    r = FbRightMask((x)+n); \
+    l = FbLeftMask(x); \
+    if (l) { \
+       n -= FB_UNIT - ((x) & FB_MASK); \
+       if (n < 0) { \
+           n = 0; \
+           l &= r; \
+           r = 0; \
+       } \
+    } \
+    n >>= FB_SHIFT; \
+}
+
+#define FbByteMaskInvalid   0x10
+
+#define FbPatternOffset(o,t)  ((o) ^ (FbPatternOffsetBits & ~(sizeof (t) - 1)))
+
+#define FbPtrOffset(p,o,t)             ((t *) ((CARD8 *) (p) + (o)))
+#define FbSelectPatternPart(xor,o,t)   ((xor) >> (FbPatternOffset (o,t) << 3))
+#define FbStorePart(dst,off,t,xor)     (WRITE(FbPtrOffset(dst,off,t), \
+                                        FbSelectPart(xor,off,t)))
+#ifndef FbSelectPart
+#define FbSelectPart(x,o,t) FbSelectPatternPart(x,o,t)
+#endif
+
+#define FbMaskBitsBytes(x,w,copy,l,lb,n,r,rb) { \
+    n = (w); \
+    lb = 0; \
+    rb = 0; \
+    r = FbRightMask((x)+n); \
+    if (r) { \
+       /* compute right byte length */ \
+       if ((copy) && (((x) + n) & 7) == 0) { \
+           rb = (((x) + n) & FB_MASK) >> 3; \
+       } else { \
+           rb = FbByteMaskInvalid; \
+       } \
+    } \
+    l = FbLeftMask(x); \
+    if (l) { \
+       /* compute left byte length */ \
+       if ((copy) && ((x) & 7) == 0) { \
+           lb = ((x) & FB_MASK) >> 3; \
+       } else { \
+           lb = FbByteMaskInvalid; \
+       } \
+       /* subtract out the portion painted by leftMask */ \
+       n -= FB_UNIT - ((x) & FB_MASK); \
+       if (n < 0) { \
+           if (lb != FbByteMaskInvalid) { \
+               if (rb == FbByteMaskInvalid) { \
+                   lb = FbByteMaskInvalid; \
+               } else if (rb) { \
+                   lb |= (rb - lb) << (FB_SHIFT - 3); \
+                   rb = 0; \
+               } \
+           } \
+           n = 0; \
+           l &= r; \
+           r = 0; \
+       }\
+    } \
+    n >>= FB_SHIFT; \
+}
+
+#define FbDoLeftMaskByteRRop(dst,lb,l,and,xor) { \
+    switch (lb) { \
+    case (sizeof (FbBits) - 3) | (1 << (FB_SHIFT - 3)): \
+       FbStorePart(dst,sizeof (FbBits) - 3,CARD8,xor); \
+       break; \
+    case (sizeof (FbBits) - 3) | (2 << (FB_SHIFT - 3)): \
+       FbStorePart(dst,sizeof (FbBits) - 3,CARD8,xor); \
+       FbStorePart(dst,sizeof (FbBits) - 2,CARD8,xor); \
+       break; \
+    case (sizeof (FbBits) - 2) | (1 << (FB_SHIFT - 3)): \
+       FbStorePart(dst,sizeof (FbBits) - 2,CARD8,xor); \
+       break; \
+    case sizeof (FbBits) - 3: \
+       FbStorePart(dst,sizeof (FbBits) - 3,CARD8,xor); \
+    case sizeof (FbBits) - 2: \
+       FbStorePart(dst,sizeof (FbBits) - 2,CARD16,xor); \
+       break; \
+    case sizeof (FbBits) - 1: \
+       FbStorePart(dst,sizeof (FbBits) - 1,CARD8,xor); \
+       break; \
+    default: \
+       WRITE(dst, FbDoMaskRRop(READ(dst), and, xor, l)); \
+       break; \
+    } \
+}
+
+#define FbDoRightMaskByteRRop(dst,rb,r,and,xor) { \
+    switch (rb) { \
+    case 1: \
+       FbStorePart(dst,0,CARD8,xor); \
+       break; \
+    case 2: \
+       FbStorePart(dst,0,CARD16,xor); \
+       break; \
+    case 3: \
+       FbStorePart(dst,0,CARD16,xor); \
+       FbStorePart(dst,2,CARD8,xor); \
+       break; \
+    default: \
+       WRITE(dst, FbDoMaskRRop (READ(dst), and, xor, r)); \
+    } \
+}
+
+#define FbMaskStip(x,w,l,n,r) { \
+    n = (w); \
+    r = FbRightStipMask((x)+n); \
+    l = FbLeftStipMask(x); \
+    if (l) { \
+       n -= FB_STIP_UNIT - ((x) & FB_STIP_MASK); \
+       if (n < 0) { \
+           n = 0; \
+           l &= r; \
+           r = 0; \
+       } \
+    } \
+    n >>= FB_STIP_SHIFT; \
+}
+
+/*
+ * These macros are used to transparently stipple
+ * in copy mode; the expected usage is with 'n' constant
+ * so all of the conditional parts collapse into a minimal
+ * sequence of partial word writes
+ *
+ * 'n' is the bytemask of which bytes to store, 'a' is the address
+ * of the FbBits base unit, 'o' is the offset within that unit
+ *
+ * The term "lane" comes from the hardware term "byte-lane" which
+ */
+
+#define FbLaneCase1(n,a,o)                                             \
+    if ((n) == 0x01) {                                                 \
+       WRITE((CARD8 *) ((a)+FbPatternOffset(o,CARD8)), fgxor);         \
+    }
+
+#define FbLaneCase2(n,a,o)                                             \
+    if ((n) == 0x03) {                                                 \
+       WRITE((CARD16 *) ((a)+FbPatternOffset(o,CARD16)), fgxor);       \
+    } else {                                                           \
+       FbLaneCase1((n)&1,a,o)                                          \
+       FbLaneCase1((n)>>1,a,(o)+1)                                     \
+    }
+
+#define FbLaneCase4(n,a,o)                                             \
+    if ((n) == 0x0f) {                                                 \
+       WRITE((CARD32 *) ((a)+FbPatternOffset(o,CARD32)), fgxor);       \
+    } else {                                                           \
+       FbLaneCase2((n)&3,a,o)                                          \
+       FbLaneCase2((n)>>2,a,(o)+2)                                     \
+    }
+
+#define FbLaneCase(n,a)   FbLaneCase4(n,(CARD8 *) (a),0)
+
+typedef struct {
+       long changes;
+       long serial;
+       GCFuncs *old_funcs;
+       void *priv;
+
+       FbBits and, xor;            /* reduced rop values */
+       FbBits bgand, bgxor;        /* for stipples */
+       FbBits fg, bg, pm;          /* expanded and filled */
+       unsigned int dashLength;    /* total of all dash elements */
+       unsigned char evenStipple;  /* stipple is even */
+       unsigned char bpp;          /* current drawable bpp */
+} FbGCPrivate, *FbGCPrivPtr;
+
+extern DevPrivateKeyRec sna_gc_key;
+extern DevPrivateKeyRec sna_window_key;
+
+static inline FbGCPrivate *fb_gc(GCPtr gc)
+{
+       return dixGetPrivateAddr(&gc->devPrivates, &sna_gc_key);
+}
+
+static inline PixmapPtr fbGetWindowPixmap(WindowPtr window)
+{
+       return *(PixmapPtr *)dixGetPrivateAddr(&window->devPrivates, &sna_window_key);
+}
+
+#ifdef ROOTLESS
+#define __fbPixDrawableX(p)    ((p)->drawable.x)
+#define __fbPixDrawableY(p)    ((p)->drawable.y)
+#else
+#define __fbPixDrawableX(p)    0
+#define __fbPixDrawableY(p)    0
+#endif
+
+#ifdef COMPOSITE
+#define __fbPixOffXWin(p)      (__fbPixDrawableX(p) - (p)->screen_x)
+#define __fbPixOffYWin(p)      (__fbPixDrawableY(p) - (p)->screen_y)
+#else
+#define __fbPixOffXWin(p)      (__fbPixDrawableX(p))
+#define __fbPixOffYWin(p)      (__fbPixDrawableY(p))
+#endif
+#define __fbPixOffXPix(p)      (__fbPixDrawableX(p))
+#define __fbPixOffYPix(p)      (__fbPixDrawableY(p))
+
+#define fbGetDrawablePixmap(drawable, pixmap, xoff, yoff) {            \
+    if ((drawable)->type != DRAWABLE_PIXMAP) {                         \
+       (pixmap) = fbGetWindowPixmap((WindowPtr)drawable);              \
+       (xoff) = __fbPixOffXWin(pixmap);                                \
+       (yoff) = __fbPixOffYWin(pixmap);                                \
+    } else {                                                           \
+       (pixmap) = (PixmapPtr) (drawable);                              \
+       (xoff) = __fbPixOffXPix(pixmap);                                \
+       (yoff) = __fbPixOffYPix(pixmap);                                \
+    }                                                                  \
+}
+
+#define fbGetPixmapBitsData(pixmap, pointer, stride, bpp) {            \
+    (pointer) = (FbBits *) (pixmap)->devPrivate.ptr;                   \
+    (stride) = ((int) (pixmap)->devKind) / sizeof (FbBits); (void)(stride);\
+    (bpp) = (pixmap)->drawable.bitsPerPixel;  (void)(bpp);             \
+}
+
+#define fbGetPixmapStipData(pixmap, pointer, stride, bpp) {            \
+    (pointer) = (FbStip *) (pixmap)->devPrivate.ptr;                   \
+    (stride) = ((int) (pixmap)->devKind) / sizeof (FbStip); (void)(stride);\
+    (bpp) = (pixmap)->drawable.bitsPerPixel;  (void)(bpp);             \
+}
+
+#define fbGetDrawable(drawable, pointer, stride, bpp, xoff, yoff) {    \
+    PixmapPtr   _pPix;                                                 \
+    fbGetDrawablePixmap(drawable, _pPix, xoff, yoff);                  \
+    fbGetPixmapBitsData(_pPix, pointer, stride, bpp);                  \
+}
+
+#define fbGetStipDrawable(drawable, pointer, stride, bpp, xoff, yoff) {        \
+    PixmapPtr   _pPix;                                                 \
+    fbGetDrawablePixmap(drawable, _pPix, xoff, yoff);                  \
+    fbGetPixmapStipData(_pPix, pointer, stride, bpp);                  \
+}
+
+/*
+ * XFree86 empties the root BorderClip when the VT is inactive,
+ * here's a macro which uses that to disable GetImage and GetSpans
+ */
+#define fbWindowEnabled(pWin) \
+    RegionNotEmpty(&(pWin)->drawable.pScreen->root->borderClip)
+#define fbDrawableEnabled(drawable) \
+    ((drawable)->type == DRAWABLE_PIXMAP ? \
+     TRUE : fbWindowEnabled((WindowPtr) drawable))
+
+#define FbPowerOfTwo(w)            (((w) & ((w) - 1)) == 0)
+/*
+ * Accelerated tiles are power of 2 width <= FB_UNIT
+ */
+#define FbEvenTile(w)      ((w) <= FB_UNIT && FbPowerOfTwo(w))
+/*
+ * Accelerated stipples are power of 2 width and <= FB_UNIT/dstBpp
+ * with dstBpp a power of 2 as well
+ */
+#define FbEvenStip(w,bpp)   ((w) * (bpp) <= FB_UNIT && FbPowerOfTwo(w) && FbPowerOfTwo(bpp))
+
+inline static int16_t fbBound(int16_t a, uint16_t b)
+{
+       int v = (int)a + (int)b;
+       if (v > MAXSHORT)
+               return MAXSHORT;
+       return v;
+}
+
+extern void
+fbPolyArc(DrawablePtr drawable, GCPtr gc, int narcs, xArc * parcs);
+
+extern void
+fbBlt(FbBits *src, FbStride srcStride, int srcX,
+      FbBits *dst, FbStride dstStride, int dstX,
+      int width, int height,
+      int alu, FbBits pm, int bpp,
+      Bool reverse, Bool upsidedown);
+
+#if FB_STIP_SHIFT == FB_SHIFT
+static inline void
+fbBltStip(FbStip *src, FbStride srcStride, int srcX,
+         FbStip *dst, FbStride dstStride, int dstX,
+         int width, int height, int alu, FbBits pm, int bpp)
+{
+       fbBlt((FbBits *)src, srcStride, srcX,
+             (FbBits *)dst, dstStride, dstX,
+             width, height, alu, pm, bpp,
+             FALSE, FALSE);
+}
+#else
+#error FB_STIP_SHIFT must equal FB_SHIFT
+#endif
+
+extern void
+fbBltOne(FbStip *src, FbStride srcStride, int srcX,
+         FbBits *dst, FbStride dstStride, int dstX,
+         int dstBpp, int width, int height,
+        FbBits fgand, FbBits fbxor, FbBits bgand, FbBits bgxor);
+
+extern void
+fbBltPlane(FbBits *src, FbStride srcStride, int srcX, int srcBpp,
+           FbStip *dst, FbStride dstStride, int dstX,
+           int width, int height,
+           FbStip fgand, FbStip fgxor, FbStip bgand, FbStip bgxor,
+          Pixel planeMask);
+
+extern void
+fbCopyNtoN(DrawablePtr src, DrawablePtr dst, GCPtr gc,
+           BoxPtr pbox, int nbox,
+           int dx, int dy,
+           Bool reverse, Bool upsidedown, Pixel bitplane, void *closure);
+
+extern void
+fbCopy1toN(DrawablePtr src, DrawablePtr dst, GCPtr gc,
+           BoxPtr pbox, int nbox,
+           int dx, int dy,
+           Bool reverse, Bool upsidedown, Pixel bitplane, void *closure);
+
+extern void
+fbCopyNto1(DrawablePtr src, DrawablePtr dst, GCPtr gc,
+           BoxPtr pbox, int nbox,
+           int dx, int dy,
+           Bool reverse, Bool upsidedown, Pixel bitplane, void *closure);
+
+extern RegionPtr
+fbCopyArea(DrawablePtr src, DrawablePtr dst, GCPtr gc,
+          int sx, int sy,
+          int width, int height,
+          int dx, int dy);
+
+extern RegionPtr
+fbCopyPlane(DrawablePtr src, DrawablePtr dst, GCPtr gc,
+           int sx, int sy,
+           int width, int height,
+           int dx, int dy,
+           unsigned long bitplane);
+
+extern void
+fbFill(DrawablePtr drawable, GCPtr gc, int x, int y, int width, int height);
+
+extern void
+fbSolidBoxClipped(DrawablePtr drawable, GCPtr gc,
+                  int x1, int y1, int x2, int y2);
+
+extern void
+fbPolyFillRect(DrawablePtr drawable, GCPtr gc, int n, xRectangle *rec);
+
+extern void
+fbFillSpans(DrawablePtr drawable, GCPtr gc,
+            int n, DDXPointPtr pt, int *width, int fSorted);
+
+extern void
+fbPadPixmap(PixmapPtr pPixmap);
+
+extern void
+fbValidateGC(GCPtr gc, unsigned long changes, DrawablePtr drawable);
+
+extern void
+fbGetSpans(DrawablePtr drawable, int wMax,
+           DDXPointPtr pt, int *width, int n, char *dst);
+
+extern void
+fbPolyGlyphBlt(DrawablePtr drawable, GCPtr gc, int x, int y,
+               unsigned int n, CharInfoPtr *info, pointer glyphs);
+
+extern void
+fbImageGlyphBlt(DrawablePtr drawable, GCPtr gc, int x, int y,
+                unsigned int n, CharInfoPtr *info, pointer glyphs);
+
+extern void
+fbPutImage(DrawablePtr drawable, GCPtr gc, int depth,
+           int x, int y, int w, int h,
+          int leftPad, int format, char *image);
+
+extern void
+fbPutXYImage(DrawablePtr drawable, GCPtr gc,
+             FbBits fg, FbBits bg, FbBits pm,
+             int alu, Bool opaque,
+             int x, int y, int width, int height,
+            FbStip * src, FbStride srcStride, int srcX);
+
+extern void
+fbGetImage(DrawablePtr drawable,
+           int x, int y, int w, int h,
+          unsigned int format, unsigned long planeMask, char *d);
+
+extern void
+fbPolyLine(DrawablePtr drawable, GCPtr gc, int mode, int n, DDXPointPtr pt);
+
+extern void
+fbFixCoordModePrevious(int n, DDXPointPtr pt);
+
+extern void
+fbPolySegment(DrawablePtr drawable, GCPtr gc, int n, xSegment *seg);
+
+extern RegionPtr
+fbBitmapToRegion(PixmapPtr pixmap);
+
+extern void
+fbPolyPoint(DrawablePtr drawable, GCPtr gc,
+           int mode, int n, xPoint *pt,
+           unsigned flags);
+
+extern void
+fbPushImage(DrawablePtr drawable, GCPtr gc,
+            FbStip *src, FbStride srcStride, int srcX,
+           int x, int y, int width, int height);
+
+extern void
+fbPushPixels(GCPtr gc, PixmapPtr pBitmap, DrawablePtr drawable,
+            int dx, int dy, int xOrg, int yOrg);
+
+extern void
+fbSetSpans(DrawablePtr drawable, GCPtr gc,
+           char *src, DDXPointPtr pt, int *width, int n, int fSorted);
+
+extern void
+fbSegment(DrawablePtr drawable, GCPtr gc,
+          int xa, int ya, int xb, int yb,
+         bool drawLast, int *dashOffset);
+
+extern void
+fbSegment1(DrawablePtr drawable, GCPtr gc, const BoxRec *clip,
+          int xa, int ya, int xb, int yb,
+         bool drawLast, int *dashOffset);
+
+extern void
+fbTransparentSpan(FbBits * dst, FbBits stip, FbBits fgxor, int n);
+
+extern void
+fbStipple(FbBits *dst, FbStride dstStride, int dstX, int dstBpp,
+          int width, int height,
+          FbStip *stip, FbStride stipStride,
+          int stipWidth, int stipHeight,
+          Bool even,
+          FbBits fgand, FbBits fgxor, FbBits bgand, FbBits bgxor,
+         int xRot, int yRot);
+
+extern void
+fbTile(FbBits *dst, FbStride dstStride, int dstX, int width, int height,
+       FbBits *tile, FbStride tileStride, int tileWidth, int tileHeight,
+       int alu, FbBits pm, int bpp,
+       int xRot, int yRot);
+
+extern FbBits fbReplicatePixel(Pixel p, int bpp);
+
+#endif  /* FB_H */
diff --git a/src/sna/fb/fbarc.c b/src/sna/fb/fbarc.c
new file mode 100644 (file)
index 0000000..2222d0b
--- /dev/null
@@ -0,0 +1,122 @@
+/*
+ * Copyright © 1998 Keith Packard
+ * Copyright © 2012 Intel Corporation
+ *
+ * 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 Keith Packard not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission.  Keith Packard makes no
+ * representations about the suitability of this software for any purpose.  It
+ * is provided "as is" without express or implied warranty.
+ *
+ * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL KEITH PACKARD 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 "fb.h"
+#include <mi.h>
+#include <mizerarc.h>
+#include <limits.h>
+
+#define ARC        fbArc8
+#define BITS       BYTE
+#define BITS2      CARD16
+#define BITS4      CARD32
+#include "fbarcbits.h"
+#undef BITS
+#undef BITS2
+#undef BITS4
+#undef ARC
+
+#define ARC        fbArc16
+#define BITS       CARD16
+#define BITS2      CARD32
+#include "fbarcbits.h"
+#undef BITS
+#undef BITS2
+#undef ARC
+
+#define ARC        fbArc32
+#define BITS       CARD32
+#include "fbarcbits.h"
+#undef BITS
+#undef ARC
+
+void
+fbPolyArc(DrawablePtr drawable, GCPtr gc, int n, xArc *arc)
+{
+       DBG(("%s x %d, width=%d, fill=%d, line=%d\n",
+            __FUNCTION__, n, gc->lineWidth, gc->lineStyle, gc->fillStyle));
+
+       if (gc->lineWidth == 0) {
+               void (*raster)(FbBits *dst, FbStride dstStride, int dstBpp,
+                              xArc *arc, int dx, int dy,
+                              FbBits and, FbBits xor);
+
+               raster = 0;
+               if (gc->lineStyle == LineSolid && gc->fillStyle == FillSolid) {
+                       switch (drawable->bitsPerPixel) {
+                       case 8:
+                               raster = fbArc8;
+                               break;
+                       case 16:
+                               raster = fbArc16;
+                               break;
+                       case 32:
+                               raster = fbArc32;
+                               break;
+                       }
+               }
+               if (raster) {
+                       FbGCPrivPtr pgc = fb_gc(gc);
+                       FbBits *dst;
+                       FbStride dstStride;
+                       int dstBpp;
+                       int dstXoff, dstYoff;
+                       BoxRec box;
+                       int x2, y2;
+
+                       fbGetDrawable(drawable, dst, dstStride, dstBpp, dstXoff, dstYoff);
+                       while (n--) {
+                               if (miCanZeroArc(arc)) {
+                                       box.x1 = arc->x + drawable->x;
+                                       box.y1 = arc->y + drawable->y;
+                                       /*
+                                        * Because box.x2 and box.y2 get truncated to 16 bits, and the
+                                        * RECT_IN_REGION test treats the resulting number as a signed
+                                        * integer, the RECT_IN_REGION test alone can go the wrong way.
+                                        * This can result in a server crash because the rendering
+                                        * routines in this file deal directly with cpu addresses
+                                        * of pixels to be stored, and do not clip or otherwise check
+                                        * that all such addresses are within their respective pixmaps.
+                                        * So we only allow the RECT_IN_REGION test to be used for
+                                        * values that can be expressed correctly in a signed short.
+                                        */
+                                       x2 = box.x1 + (int) arc->width + 1;
+                                       box.x2 = x2;
+                                       y2 = box.y1 + (int) arc->height + 1;
+                                       box.y2 = y2;
+                                       if ((x2 <= SHRT_MAX) && (y2 <= SHRT_MAX) &&
+                                           (RegionContainsRect(gc->pCompositeClip, &box) == rgnIN)) {
+                                               raster(dst, dstStride, dstBpp,
+                                                      arc, drawable->x + dstXoff,
+                                                       drawable->y + dstYoff, pgc->and, pgc->xor);
+                                       } else
+                                               miZeroPolyArc(drawable, gc, 1, arc);
+                               } else
+                                       miPolyArc(drawable, gc, 1, arc);
+                               arc++;
+                       }
+               } else
+                       miZeroPolyArc(drawable, gc, n, arc);
+       } else
+               miPolyArc(drawable, gc, n, arc);
+}
diff --git a/src/sna/fb/fbarcbits.h b/src/sna/fb/fbarcbits.h
new file mode 100644 (file)
index 0000000..a37206c
--- /dev/null
@@ -0,0 +1,204 @@
+/*
+ * Copyright © 1998 Keith Packard
+ * Copyright © 2012 Intel Corporation
+ *
+ * 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 Keith Packard not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission.  Keith Packard makes no
+ * representations about the suitability of this software for any purpose.  It
+ * is provided "as is" without express or implied warranty.
+ *
+ * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL KEITH PACKARD 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.
+ */
+
+#define isClipped(c,ul,lr)  (((c) | ((c) - (ul)) | ((lr) - (c))) & 0x80008000)
+#define RROP(b,a,x)    WRITE((b), FbDoRRop (READ(b), (a), (x)))
+
+#define ARCCOPY(d)  WRITE(d,xorBits)
+#define ARCRROP(d)  RROP(d,andBits,xorBits)
+
+static void
+ARC(FbBits * dst,
+    FbStride dstStride,
+    int dstBpp, xArc * arc, int drawX, int drawY, FbBits and, FbBits xor)
+{
+       BITS *bits;
+       FbStride bitsStride;
+       miZeroArcRec info;
+       Bool do360;
+       int x;
+       BITS *yorgp, *yorgop;
+       BITS andBits, xorBits;
+       int yoffset, dyoffset;
+       int y, a, b, d, mask;
+       int k1, k3, dx, dy;
+
+       bits = (BITS *) dst;
+       bitsStride = dstStride * (sizeof(FbBits) / sizeof(BITS));
+       andBits = (BITS) and;
+       xorBits = (BITS) xor;
+       do360 = miZeroArcSetup(arc, &info, TRUE);
+       yorgp = bits + ((info.yorg + drawY) * bitsStride);
+       yorgop = bits + ((info.yorgo + drawY) * bitsStride);
+       info.xorg = (info.xorg + drawX);
+       info.xorgo = (info.xorgo + drawX);
+       MIARCSETUP();
+       yoffset = y ? bitsStride : 0;
+       dyoffset = 0;
+       mask = info.initialMask;
+
+       if (!(arc->width & 1)) {
+               if (andBits == 0) {
+                       if (mask & 2)
+                               ARCCOPY(yorgp + info.xorgo);
+                       if (mask & 8)
+                               ARCCOPY(yorgop + info.xorgo);
+               } else {
+                       if (mask & 2)
+                               ARCRROP(yorgp + info.xorgo);
+                       if (mask & 8)
+                               ARCRROP(yorgop + info.xorgo);
+               }
+       }
+       if (!info.end.x || !info.end.y) {
+               mask = info.end.mask;
+               info.end = info.altend;
+       }
+       if (do360 && (arc->width == arc->height) && !(arc->width & 1)) {
+               int xoffset = bitsStride;
+               BITS *yorghb = yorgp + (info.h * bitsStride) + info.xorg;
+               BITS *yorgohb = yorghb - info.h;
+
+               yorgp += info.xorg;
+               yorgop += info.xorg;
+               yorghb += info.h;
+               while (1) {
+                       if (andBits == 0) {
+                               ARCCOPY(yorgp + yoffset + x);
+                               ARCCOPY(yorgp + yoffset - x);
+                               ARCCOPY(yorgop - yoffset - x);
+                               ARCCOPY(yorgop - yoffset + x);
+                       } else {
+                               ARCRROP(yorgp + yoffset + x);
+                               ARCRROP(yorgp + yoffset - x);
+                               ARCRROP(yorgop - yoffset - x);
+                               ARCRROP(yorgop - yoffset + x);
+                       }
+                       if (a < 0)
+                               break;
+                       if (andBits == 0) {
+                               ARCCOPY(yorghb - xoffset - y);
+                               ARCCOPY(yorgohb - xoffset + y);
+                               ARCCOPY(yorgohb + xoffset + y);
+                               ARCCOPY(yorghb + xoffset - y);
+                       } else {
+                               ARCRROP(yorghb - xoffset - y);
+                               ARCRROP(yorgohb - xoffset + y);
+                               ARCRROP(yorgohb + xoffset + y);
+                               ARCRROP(yorghb + xoffset - y);
+                       }
+                       xoffset += bitsStride;
+                       MIARCCIRCLESTEP(yoffset += bitsStride;
+                                      );
+               }
+               yorgp -= info.xorg;
+               yorgop -= info.xorg;
+               x = info.w;
+               yoffset = info.h * bitsStride;
+       } else if (do360) {
+               while (y < info.h || x < info.w) {
+                       MIARCOCTANTSHIFT(dyoffset = bitsStride;
+                                       );
+                       if (andBits == 0) {
+                               ARCCOPY(yorgp + yoffset + info.xorg + x);
+                               ARCCOPY(yorgp + yoffset + info.xorgo - x);
+                               ARCCOPY(yorgop - yoffset + info.xorgo - x);
+                               ARCCOPY(yorgop - yoffset + info.xorg + x);
+                       } else {
+                               ARCRROP(yorgp + yoffset + info.xorg + x);
+                               ARCRROP(yorgp + yoffset + info.xorgo - x);
+                               ARCRROP(yorgop - yoffset + info.xorgo - x);
+                               ARCRROP(yorgop - yoffset + info.xorg + x);
+                       }
+                       MIARCSTEP(yoffset += dyoffset;
+                                 , yoffset += bitsStride;
+                                );
+               }
+       } else {
+               while (y < info.h || x < info.w) {
+                       MIARCOCTANTSHIFT(dyoffset = bitsStride;
+                                       );
+                       if ((x == info.start.x) || (y == info.start.y)) {
+                               mask = info.start.mask;
+                               info.start = info.altstart;
+                       }
+                       if (andBits == 0) {
+                               if (mask & 1)
+                                       ARCCOPY(yorgp + yoffset + info.xorg + x);
+                               if (mask & 2)
+                                       ARCCOPY(yorgp + yoffset + info.xorgo - x);
+                               if (mask & 4)
+                                       ARCCOPY(yorgop - yoffset + info.xorgo - x);
+                               if (mask & 8)
+                                       ARCCOPY(yorgop - yoffset + info.xorg + x);
+                       } else {
+                               if (mask & 1)
+                                       ARCRROP(yorgp + yoffset + info.xorg + x);
+                               if (mask & 2)
+                                       ARCRROP(yorgp + yoffset + info.xorgo - x);
+                               if (mask & 4)
+                                       ARCRROP(yorgop - yoffset + info.xorgo - x);
+                               if (mask & 8)
+                                       ARCRROP(yorgop - yoffset + info.xorg + x);
+                       }
+                       if ((x == info.end.x) || (y == info.end.y)) {
+                               mask = info.end.mask;
+                               info.end = info.altend;
+                       }
+                       MIARCSTEP(yoffset += dyoffset;
+                                 , yoffset += bitsStride;
+                                );
+               }
+       }
+       if ((x == info.start.x) || (y == info.start.y))
+               mask = info.start.mask;
+       if (andBits == 0) {
+               if (mask & 1)
+                       ARCCOPY(yorgp + yoffset + info.xorg + x);
+               if (mask & 4)
+                       ARCCOPY(yorgop - yoffset + info.xorgo - x);
+               if (arc->height & 1) {
+                       if (mask & 2)
+                               ARCCOPY(yorgp + yoffset + info.xorgo - x);
+                       if (mask & 8)
+                               ARCCOPY(yorgop - yoffset + info.xorg + x);
+               }
+       } else {
+               if (mask & 1)
+                       ARCRROP(yorgp + yoffset + info.xorg + x);
+               if (mask & 4)
+                       ARCRROP(yorgop - yoffset + info.xorgo - x);
+               if (arc->height & 1) {
+                       if (mask & 2)
+                               ARCRROP(yorgp + yoffset + info.xorgo - x);
+                       if (mask & 8)
+                               ARCRROP(yorgop - yoffset + info.xorg + x);
+               }
+       }
+}
+
+#undef ARCCOPY
+#undef ARCRROP
+
+#undef RROP
+#undef isClipped
diff --git a/src/sna/fb/fbbitmap.c b/src/sna/fb/fbbitmap.c
new file mode 100644 (file)
index 0000000..7c037fe
--- /dev/null
@@ -0,0 +1,159 @@
+/*
+ * Copyright © 1998 Keith Packard
+ * Copyright © 2012 Intel Corporation
+ *
+ * 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 Keith Packard not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission.  Keith Packard makes no
+ * representations about the suitability of this software for any purpose.  It
+ * is provided "as is" without express or implied warranty.
+ *
+ * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL KEITH PACKARD 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 <stdlib.h>
+
+#include "fb.h"
+
+static inline void add(RegionPtr region,
+                      int16_t x1, int16_t y1, int16_t x2, int16_t y2)
+{
+       BoxPtr r;
+
+       if (region->data->numRects == region->data->size)
+               RegionRectAlloc(region, 1);
+
+       r = RegionBoxptr(region) + region->data->numRects++;
+       r->x1 = x1; r->y1 = y1;
+       r->x2 = x2; r->y2 = y2;
+
+       DBG(("%s[%d/%d]: (%d, %d), (%d, %d)\n",
+            __FUNCTION__,
+            region->data->numRects, region->data->size,
+            x1, y1, x2, y2));
+
+       if (x1 < region->extents.x1)
+               region->extents.x1 = x1;
+       if (x2 > region->extents.x2)
+               region->extents.x2 = x2;
+}
+
+#define MASK_0 (FB_ALLONES & ~FbScrRight(FB_ALLONES, 1))
+
+/* Convert bitmap clip mask into clipping region.
+ * First, goes through each line and makes boxes by noting the transitions
+ * from 0 to 1 and 1 to 0.
+ * Then it coalesces the current line with the previous if they have boxes
+ * at the same X coordinates.
+ */
+RegionPtr
+fbBitmapToRegion(PixmapPtr pixmap)
+{
+       FbBits maskw;
+       register RegionPtr region;
+       const FbBits *bits, *line, *end;
+       int width, y1, y2, base, x1;
+       int stride, i;
+
+       DBG(("%s bitmap=%dx%d\n", __FUNCTION__,
+            pixmap->drawable.width, pixmap->drawable.height));
+
+       region = RegionCreate(NULL, 1);
+       if (!region)
+               return NullRegion;
+
+       line = (FbBits *) pixmap->devPrivate.ptr;
+       stride = pixmap->devKind >> (FB_SHIFT - 3);
+
+       width = pixmap->drawable.width;
+       maskw = 0;
+       if (width & 7)
+               maskw = FB_ALLONES & ~FbScrRight(FB_ALLONES, width & FB_MASK);
+       region->extents.x1 = width;
+       region->extents.x2 = 0;
+       y2 = 0;
+       while (y2 < pixmap->drawable.height) {
+               y1 = y2++;
+               bits = line;
+               line += stride;
+               while (y2 < pixmap->drawable.height &&
+                      memcmp(bits, line, width >> 3) == 0 &&
+                      (maskw == 0 || (bits[width >> FB_SHIFT] & maskw) == (line[width >> FB_SHIFT] & maskw)))
+                       line += stride, y2++;
+
+               if (READ(bits) & MASK_0)
+                       x1 = 0;
+               else
+                       x1 = -1;
+
+               /* Process all words which are fully in the pixmap */
+               end = bits + (width >> FB_SHIFT);
+               for (base = 0; bits < end; base += FB_UNIT) {
+                       FbBits w = READ(bits++);
+                       if (x1 < 0) {
+                               if (!w)
+                                       continue;
+                       } else {
+                               if (!~w)
+                                       continue;
+                       }
+                       for (i = 0; i < FB_UNIT; i++) {
+                               if (w & MASK_0) {
+                                       if (x1 < 0)
+                                               x1 = base + i;
+                               } else {
+                                       if (x1 >= 0) {
+                                               add(region, x1, y1, base + i, y2);
+                                               x1 = -1;
+                                       }
+                               }
+                               w = FbScrLeft(w, 1);
+                       }
+               }
+               if (width & FB_MASK) {
+                       FbBits w = READ(bits++);
+                       for (i = 0; i < (width & FB_MASK); i++) {
+                               if (w & MASK_0) {
+                                       if (x1 < 0)
+                                               x1 = base + i;
+                               } else {
+                                       if (x1 >= 0) {
+                                               add(region, x1, y1, base + i, y2);
+                                               x1 = -1;
+                                       }
+                               }
+                               w = FbScrLeft(w, 1);
+                       }
+               }
+               if (x1 >= 0)
+                       add(region, x1, y1, width, y2);
+       }
+
+       if (region->data->numRects) {
+               region->extents.y1 = RegionBoxptr(region)->y1;
+               region->extents.y2 = RegionEnd(region)->y2;
+               if (region->data->numRects == 1) {
+                       free(region->data);
+                       region->data = NULL;
+               }
+       } else
+               region->extents.x1 = region->extents.x2 = 0;
+
+       DBG(("%s: region extents=(%d, %d), (%d, %d) x %d\n",
+            __FUNCTION__,
+            region->extents.x1, region->extents.y1,
+            region->extents.x2, region->extents.y2,
+            RegionNumRects(region)));
+
+       return region;
+}
diff --git a/src/sna/fb/fbblt.c b/src/sna/fb/fbblt.c
new file mode 100644 (file)
index 0000000..62ed2a1
--- /dev/null
@@ -0,0 +1,321 @@
+/*
+ * Copyright © 1998 Keith Packard
+ * Copyright © 2012 Intel Corporation
+ *
+ * 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 Keith Packard not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission.  Keith Packard makes no
+ * representations about the suitability of this software for any purpose.  It
+ * is provided "as is" without express or implied warranty.
+ *
+ * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL KEITH PACKARD 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 <string.h>
+#include "fb.h"
+
+typedef struct _mergeRopBits {
+    FbBits ca1, cx1, ca2, cx2;
+} FbMergeRopRec, *FbMergeRopPtr;
+
+#define O 0
+#define I FB_ALLONES
+
+static const FbMergeRopRec FbMergeRopBits[16] = {
+       {O, O, O, O},               /* clear         0x0         0 */
+       {I, O, O, O},               /* and           0x1         src AND dst */
+       {I, O, I, O},               /* andReverse    0x2         src AND NOT dst */
+       {O, O, I, O},               /* copy          0x3         src */
+       {I, I, O, O},               /* andInverted   0x4         NOT src AND dst */
+       {O, I, O, O},               /* noop          0x5         dst */
+       {O, I, I, O},               /* xor           0x6         src XOR dst */
+       {I, I, I, O},               /* or            0x7         src OR dst */
+       {I, I, I, I},               /* nor           0x8         NOT src AND NOT dst */
+       {O, I, I, I},               /* equiv         0x9         NOT src XOR dst */
+       {O, I, O, I},               /* invert        0xa         NOT dst */
+       {I, I, O, I},               /* orReverse     0xb         src OR NOT dst */
+       {O, O, I, I},               /* copyInverted  0xc         NOT src */
+       {I, O, I, I},               /* orInverted    0xd         NOT src OR dst */
+       {I, O, O, I},               /* nand          0xe         NOT src OR NOT dst */
+       {O, O, O, I},               /* set           0xf         1 */
+};
+
+#undef O
+#undef I
+
+#define FbDeclareMergeRop() FbBits   _ca1, _cx1, _ca2, _cx2;
+#define FbDeclarePrebuiltMergeRop()    FbBits  _cca, _ccx;
+
+#define FbInitializeMergeRop(alu,pm) {\
+    const FbMergeRopRec  *_bits; \
+    _bits = &FbMergeRopBits[alu]; \
+    _ca1 = _bits->ca1 &  pm; \
+    _cx1 = _bits->cx1 | ~pm; \
+    _ca2 = _bits->ca2 &  pm; \
+    _cx2 = _bits->cx2 &  pm; \
+}
+
+#define InitializeShifts(sx,dx,ls,rs) { \
+    if (sx != dx) { \
+       if (sx > dx) { \
+           ls = sx - dx; \
+           rs = FB_UNIT - ls; \
+       } else { \
+           rs = dx - sx; \
+           ls = FB_UNIT - rs; \
+       } \
+    } \
+}
+
+static void
+fbBlt__rop(FbBits *srcLine, FbStride srcStride, int srcX,
+          FbBits *dstLine, FbStride dstStride, int dstX,
+          int width, int height,
+          int alu, FbBits pm, int bpp,
+          Bool reverse, Bool upsidedown)
+{
+       FbBits *src, *dst;
+       int leftShift, rightShift;
+       FbBits startmask, endmask;
+       FbBits bits, bits1;
+       int n, nmiddle;
+       Bool destInvarient;
+       int startbyte, endbyte;
+
+       FbDeclareMergeRop();
+
+       FbInitializeMergeRop(alu, pm);
+       destInvarient = FbDestInvarientMergeRop();
+       if (upsidedown) {
+               srcLine += (height - 1) * (srcStride);
+               dstLine += (height - 1) * (dstStride);
+               srcStride = -srcStride;
+               dstStride = -dstStride;
+       }
+       FbMaskBitsBytes(dstX, width, destInvarient, startmask, startbyte,
+                       nmiddle, endmask, endbyte);
+       if (reverse) {
+               srcLine += ((srcX + width - 1) >> FB_SHIFT) + 1;
+               dstLine += ((dstX + width - 1) >> FB_SHIFT) + 1;
+               srcX = (srcX + width - 1) & FB_MASK;
+               dstX = (dstX + width - 1) & FB_MASK;
+       } else {
+               srcLine += srcX >> FB_SHIFT;
+               dstLine += dstX >> FB_SHIFT;
+               srcX &= FB_MASK;
+               dstX &= FB_MASK;
+       }
+       if (srcX == dstX) {
+               while (height--) {
+                       src = srcLine;
+                       srcLine += srcStride;
+                       dst = dstLine;
+                       dstLine += dstStride;
+                       if (reverse) {
+                               if (endmask) {
+                                       bits = READ(--src);
+                                       --dst;
+                                       FbDoRightMaskByteMergeRop(dst, bits, endbyte, endmask);
+                               }
+                               n = nmiddle;
+                               if (destInvarient) {
+                                       while (n--)
+                                               WRITE(--dst, FbDoDestInvarientMergeRop(READ(--src)));
+                               } else {
+                                       while (n--) {
+                                               bits = READ(--src);
+                                               --dst;
+                                               WRITE(dst, FbDoMergeRop(bits, READ(dst)));
+                                       }
+                               }
+                               if (startmask) {
+                                       bits = READ(--src);
+                                       --dst;
+                                       FbDoLeftMaskByteMergeRop(dst, bits, startbyte, startmask);
+                               }
+                       } else {
+                               if (startmask) {
+                                       bits = READ(src++);
+                                       FbDoLeftMaskByteMergeRop(dst, bits, startbyte, startmask);
+                                       dst++;
+                               }
+                               n = nmiddle;
+                               if (destInvarient) {
+                                       while (n--)
+                                               WRITE(dst++, FbDoDestInvarientMergeRop(READ(src++)));
+                               } else {
+                                       while (n--) {
+                                               bits = READ(src++);
+                                               WRITE(dst, FbDoMergeRop(bits, READ(dst)));
+                                               dst++;
+                                       }
+                               }
+                               if (endmask) {
+                                       bits = READ(src);
+                                       FbDoRightMaskByteMergeRop(dst, bits, endbyte, endmask);
+                               }
+                       }
+               }
+       } else {
+               if (srcX > dstX) {
+                       leftShift = srcX - dstX;
+                       rightShift = FB_UNIT - leftShift;
+               } else {
+                       rightShift = dstX - srcX;
+                       leftShift = FB_UNIT - rightShift;
+               }
+               while (height--) {
+                       src = srcLine;
+                       srcLine += srcStride;
+                       dst = dstLine;
+                       dstLine += dstStride;
+
+                       bits1 = 0;
+                       if (reverse) {
+                               if (srcX < dstX)
+                                       bits1 = READ(--src);
+                               if (endmask) {
+                                       bits = FbScrRight(bits1, rightShift);
+                                       if (FbScrRight(endmask, leftShift)) {
+                                               bits1 = READ(--src);
+                                               bits |= FbScrLeft(bits1, leftShift);
+                                       }
+                                       --dst;
+                                       FbDoRightMaskByteMergeRop(dst, bits, endbyte, endmask);
+                               }
+                               n = nmiddle;
+                               if (destInvarient) {
+                                       while (n--) {
+                                               bits = FbScrRight(bits1, rightShift);
+                                               bits1 = READ(--src);
+                                               bits |= FbScrLeft(bits1, leftShift);
+                                               --dst;
+                                               WRITE(dst, FbDoDestInvarientMergeRop(bits));
+                                       }
+                               } else {
+                                       while (n--) {
+                                               bits = FbScrRight(bits1, rightShift);
+                                               bits1 = READ(--src);
+                                               bits |= FbScrLeft(bits1, leftShift);
+                                               --dst;
+                                               WRITE(dst, FbDoMergeRop(bits, READ(dst)));
+                                       }
+                               }
+                               if (startmask) {
+                                       bits = FbScrRight(bits1, rightShift);
+                                       if (FbScrRight(startmask, leftShift)) {
+                                               bits1 = READ(--src);
+                                               bits |= FbScrLeft(bits1, leftShift);
+                                       }
+                                       --dst;
+                                       FbDoLeftMaskByteMergeRop(dst, bits, startbyte, startmask);
+                               }
+                       } else {
+                               if (srcX > dstX)
+                                       bits1 = READ(src++);
+                               if (startmask) {
+                                       bits = FbScrLeft(bits1, leftShift);
+                                       if (FbScrLeft(startmask, rightShift)) {
+                                               bits1 = READ(src++);
+                                               bits |= FbScrRight(bits1, rightShift);
+                                       }
+                                       FbDoLeftMaskByteMergeRop(dst, bits, startbyte, startmask);
+                                       dst++;
+                               }
+                               n = nmiddle;
+                               if (destInvarient) {
+                                       while (n--) {
+                                               bits = FbScrLeft(bits1, leftShift);
+                                               bits1 = READ(src++);
+                                               bits |= FbScrRight(bits1, rightShift);
+                                               WRITE(dst, FbDoDestInvarientMergeRop(bits));
+                                               dst++;
+                                       }
+                               } else {
+                                       while (n--) {
+                                               bits = FbScrLeft(bits1, leftShift);
+                                               bits1 = READ(src++);
+                                               bits |= FbScrRight(bits1, rightShift);
+                                               WRITE(dst, FbDoMergeRop(bits, READ(dst)));
+                                               dst++;
+                                       }
+                               }
+                               if (endmask) {
+                                       bits = FbScrLeft(bits1, leftShift);
+                                       if (FbScrLeft(endmask, rightShift)) {
+                                               bits1 = READ(src);
+                                               bits |= FbScrRight(bits1, rightShift);
+                                       }
+                                       FbDoRightMaskByteMergeRop(dst, bits, endbyte, endmask);
+                               }
+                       }
+               }
+       }
+}
+
+void
+fbBlt(FbBits *srcLine, FbStride srcStride, int srcX,
+      FbBits *dstLine, FbStride dstStride, int dstX,
+      int width, int height,
+      int alu, FbBits pm, int bpp,
+      Bool reverse, Bool upsidedown)
+{
+       DBG(("%s %dx%d, alu=%d, pm=%d, bpp=%d\n",
+            __FUNCTION__, width, height, alu, pm, bpp));
+
+       if (alu == GXcopy && pm == FB_ALLONES && ((srcX|dstX|width) & 7) == 0) {
+               CARD8 *s = (CARD8 *) srcLine;
+               CARD8 *d = (CARD8 *) dstLine;
+               void *(*func)(void *, const void *, size_t);
+               int i;
+
+               srcStride *= sizeof(FbBits);
+               dstStride *= sizeof(FbBits);
+               width >>= 3;
+               s += srcX >> 3;
+               d += dstX >> 3;
+
+               DBG(("%s fast blt, src_stride=%d, dst_stride=%d, width=%d (offset=%d)\n",
+                    __FUNCTION__,
+                    srcStride, dstStride, width, s - d));
+
+               if (width == srcStride && width == dstStride) {
+                       width *= height;
+                       height = 1;
+               }
+
+               if ((s < d && s + width > d) || (d < s && d + width > s))
+                       func = memmove;
+               else
+                       func = memcpy;
+               if (!upsidedown) {
+                       for (i = 0; i < height; i++)
+                               func(d + i * dstStride,
+                                    s + i * srcStride,
+                                    width);
+               } else {
+                       for (i = height; i--; )
+                               func(d + i * dstStride,
+                                    s + i * srcStride,
+                                    width);
+               }
+
+               return;
+       }
+
+       fbBlt__rop(srcLine, srcStride, srcX,
+                  dstLine, dstStride, dstX,
+                  width, height,
+                  alu, pm, bpp,
+                  reverse, upsidedown);
+}
diff --git a/src/sna/fb/fbbltone.c b/src/sna/fb/fbbltone.c
new file mode 100644 (file)
index 0000000..697d20b
--- /dev/null
@@ -0,0 +1,413 @@
+/*
+ * Copyright © 1998 Keith Packard
+ * Copyright © 2012 Intel Corporation
+ *
+ * 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 Keith Packard not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission.  Keith Packard makes no
+ * representations about the suitability of this software for any purpose.  It
+ * is provided "as is" without express or implied warranty.
+ *
+ * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL KEITH PACKARD 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 "fb.h"
+
+#ifdef __clang__
+/* shift overflow is intentional */
+#pragma clang diagnostic ignored "-Wshift-overflow"
+#endif
+
+/*
+ *  Example: srcX = 13 dstX = 8        (FB unit 32 dstBpp 8)
+ *
+ *     **** **** **** **** **** **** **** ****
+ *                     ^
+ *     ********  ********  ********  ********
+ *               ^
+ *  leftShift = 12
+ *  rightShift = 20
+ *
+ *  Example: srcX = 0 dstX = 8 (FB unit 32 dstBpp 8)
+ *
+ *     **** **** **** **** **** **** **** ****
+ *     ^               
+ *     ********  ********  ********  ********
+ *               ^
+ *
+ *  leftShift = 24
+ *  rightShift = 8
+ */
+
+#define LoadBits {\
+    if (leftShift) { \
+       bitsRight = (src < srcEnd ? READ(src++) : 0); \
+       bits = (FbStipLeft (bitsLeft, leftShift) | \
+               FbStipRight(bitsRight, rightShift)); \
+       bitsLeft = bitsRight; \
+    } else \
+       bits = (src < srcEnd ? READ(src++) : 0); \
+}
+
+#define LaneCases1(n,a)            case n: FbLaneCase(n,a); break
+#define LaneCases2(n,a)            LaneCases1(n,a); LaneCases1(n+1,a)
+#define LaneCases4(n,a)            LaneCases2(n,a); LaneCases2(n+2,a)
+#define LaneCases8(n,a)            LaneCases4(n,a); LaneCases4(n+4,a)
+#define LaneCases16(n,a)    LaneCases8(n,a); LaneCases8(n+8,a)
+#define LaneCases32(n,a)    LaneCases16(n,a); LaneCases16(n+16,a)
+#define LaneCases64(n,a)    LaneCases32(n,a); LaneCases32(n+32,a)
+#define LaneCases128(n,a)   LaneCases64(n,a); LaneCases64(n+64,a)
+#define LaneCases256(n,a)   LaneCases128(n,a); LaneCases128(n+128,a)
+
+#define LaneCases(a)       LaneCases16(0,a)
+
+static const CARD8 fb8Lane[16] = {
+    0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
+};
+
+static const CARD8 fb16Lane[16] = {
+    0, 3, 12, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+};
+
+static const CARD8 fb32Lane[16] = {
+    0, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+};
+
+static const CARD8 * const fbLaneTable[33] = {
+    0, 0, 0, 0, 0, 0, 0, 0,
+    fb8Lane, 0, 0, 0, 0, 0, 0, 0,
+    fb16Lane, 0, 0, 0, 0, 0, 0, 0,
+    0, 0, 0, 0, 0, 0, 0, 0,
+    fb32Lane
+};
+
+void
+fbBltOne(FbStip * src, FbStride srcStride,      /* FbStip units per scanline */
+         int srcX,              /* bit position of source */
+         FbBits * dst, FbStride dstStride,      /* FbBits units per scanline */
+         int dstX,              /* bit position of dest */
+         int dstBpp,            /* bits per destination unit */
+         int width,             /* width in bits of destination */
+         int height,            /* height in scanlines */
+         FbBits fgand,          /* rrop values */
+         FbBits fgxor, FbBits bgand, FbBits bgxor)
+{
+       const FbBits *fbBits;
+       FbBits *srcEnd;
+       int pixelsPerDst;           /* dst pixels per FbBits */
+       int unitsPerSrc;            /* src patterns per FbStip */
+       int leftShift, rightShift;  /* align source with dest */
+       FbBits startmask, endmask;  /* dest scanline masks */
+       FbStip bits = 0, bitsLeft, bitsRight;       /* source bits */
+       FbStip left;
+       FbBits mask;
+       int nDst;                   /* dest longwords (w.o. end) */
+       int w;
+       int n, nmiddle;
+       int dstS;                   /* stipple-relative dst X coordinate */
+       Bool copy;                  /* accelerate dest-invariant */
+       Bool transparent;           /* accelerate 0 nop */
+       int srcinc;                 /* source units consumed */
+       Bool endNeedsLoad = FALSE;  /* need load for endmask */
+       const CARD8 *fbLane;
+       int startbyte, endbyte;
+
+       /*
+        * Do not read past the end of the buffer!
+        */
+       srcEnd = src + height * srcStride;
+
+       /*
+        * Number of destination units in FbBits == number of stipple pixels
+        * used each time
+        */
+       pixelsPerDst = FB_UNIT / dstBpp;
+
+       /*
+        * Number of source stipple patterns in FbStip 
+        */
+       unitsPerSrc = FB_STIP_UNIT / pixelsPerDst;
+
+       copy = FALSE;
+       transparent = FALSE;
+       if (bgand == 0 && fgand == 0)
+               copy = TRUE;
+       else if (bgand == FB_ALLONES && bgxor == 0)
+               transparent = TRUE;
+
+       /*
+        * Adjust source and dest to nearest FbBits boundary
+        */
+       src += srcX >> FB_STIP_SHIFT;
+       dst += dstX >> FB_SHIFT;
+       srcX &= FB_STIP_MASK;
+       dstX &= FB_MASK;
+
+       FbMaskBitsBytes(dstX, width, copy,
+                       startmask, startbyte, nmiddle, endmask, endbyte);
+
+       /*
+        * Compute effective dest alignment requirement for
+        * source -- must align source to dest unit boundary
+        */
+       dstS = dstX / dstBpp;
+       /*
+        * Compute shift constants for effective alignement
+        */
+       if (srcX >= dstS) {
+               leftShift = srcX - dstS;
+               rightShift = FB_STIP_UNIT - leftShift;
+       } else {
+               rightShift = dstS - srcX;
+               leftShift = FB_STIP_UNIT - rightShift;
+       }
+       /*
+        * Get pointer to stipple mask array for this depth
+        */
+       fbBits = 0;                 /* unused */
+       if (pixelsPerDst <= 8)
+               fbBits = fbStippleTable[pixelsPerDst];
+       fbLane = 0;
+       if (transparent && fgand == 0 && dstBpp >= 8)
+               fbLane = fbLaneTable[dstBpp];
+
+       /*
+        * Compute total number of destination words written, but 
+        * don't count endmask 
+        */
+       nDst = nmiddle;
+       if (startmask)
+               nDst++;
+
+       dstStride -= nDst;
+
+       /*
+        * Compute total number of source words consumed
+        */
+
+       srcinc = (nDst + unitsPerSrc - 1) / unitsPerSrc;
+
+       if (srcX > dstS)
+               srcinc++;
+       if (endmask) {
+               endNeedsLoad = nDst % unitsPerSrc == 0;
+               if (endNeedsLoad)
+                       srcinc++;
+       }
+
+       srcStride -= srcinc;
+
+       /*
+        * Copy rectangle
+        */
+       while (height--) {
+               w = nDst;               /* total units across scanline */
+               n = unitsPerSrc;        /* units avail in single stipple */
+               if (n > w)
+                       n = w;
+
+               bitsLeft = 0;
+               if (srcX > dstS)
+                       bitsLeft = READ(src++);
+               if (n) {
+                       /*
+                        * Load first set of stipple bits
+                        */
+                       LoadBits;
+
+                       /*
+                        * Consume stipple bits for startmask
+                        */
+                       if (startmask) {
+                               mask = fbBits[FbLeftStipBits(bits, pixelsPerDst)];
+                               if (fbLane) {
+                                       fbTransparentSpan(dst, mask & startmask, fgxor, 1);
+                               } else {
+                                       if (mask || !transparent)
+                                               FbDoLeftMaskByteStippleRRop(dst, mask,
+                                                                           fgand, fgxor, bgand, bgxor,
+                                                                           startbyte, startmask);
+                               }
+                               bits = FbStipLeft(bits, pixelsPerDst);
+                               dst++;
+                               n--;
+                               w--;
+                       }
+                       /*
+                        * Consume stipple bits across scanline
+                        */
+                       for (;;) {
+                               w -= n;
+                               if (copy) {
+                                       while (n--) {
+#if FB_UNIT > 32
+                                               if (pixelsPerDst == 16)
+                                                       mask = FbStipple16Bits(FbLeftStipBits(bits, 16));
+                                               else
+#endif
+                                                       mask = fbBits[FbLeftStipBits(bits, pixelsPerDst)];
+                                               WRITE(dst, FbOpaqueStipple(mask, fgxor, bgxor));
+                                               dst++;
+                                               bits = FbStipLeft(bits, pixelsPerDst);
+                                       }
+                               }
+                               else {
+                                       if (fbLane) {
+                                               while (bits && n) {
+                                                       switch (fbLane[FbLeftStipBits(bits, pixelsPerDst)]) {
+                                                               LaneCases((CARD8 *) dst);
+                                                       }
+                                                       bits = FbStipLeft(bits, pixelsPerDst);
+                                                       dst++;
+                                                       n--;
+                                               }
+                                               dst += n;
+                                       } else {
+                                               while (n--) {
+                                                       left = FbLeftStipBits(bits, pixelsPerDst);
+                                                       if (left || !transparent) {
+                                                               mask = fbBits[left];
+                                                               WRITE(dst, FbStippleRRop(READ(dst), mask,
+                                                                                        fgand, fgxor, bgand,
+                                                                                        bgxor));
+                                                       }
+                                                       dst++;
+                                                       bits = FbStipLeft(bits, pixelsPerDst);
+                                               }
+                                       }
+                               }
+                               if (!w)
+                                       break;
+                               /*
+                                * Load another set and reset number of available units
+                                */
+                               LoadBits;
+                               n = unitsPerSrc;
+                               if (n > w)
+                                       n = w;
+                       }
+               }
+               /*
+                * Consume stipple bits for endmask
+                */
+               if (endmask) {
+                       if (endNeedsLoad) {
+                               LoadBits;
+                       }
+                       mask = fbBits[FbLeftStipBits(bits, pixelsPerDst)];
+                       if (fbLane) {
+                               fbTransparentSpan(dst, mask & endmask, fgxor, 1);
+                       } else {
+                               if (mask || !transparent)
+                                       FbDoRightMaskByteStippleRRop(dst, mask,
+                                                                    fgand, fgxor, bgand, bgxor,
+                                                                    endbyte, endmask);
+                       }
+               }
+               dst += dstStride;
+               src += srcStride;
+       }
+}
+
+/*
+ * Not very efficient, but simple -- copy a single plane
+ * from an N bit image to a 1 bit image
+ */
+
+void
+fbBltPlane(FbBits * src,
+           FbStride srcStride,
+           int srcX,
+           int srcBpp,
+           FbStip * dst,
+           FbStride dstStride,
+           int dstX,
+           int width,
+           int height,
+           FbStip fgand,
+           FbStip fgxor, FbStip bgand, FbStip bgxor, Pixel planeMask)
+{
+       FbBits *s;
+       FbBits pm;
+       FbBits srcMask;
+       FbBits srcMaskFirst;
+       FbBits srcMask0 = 0;
+       FbBits srcBits;
+
+       FbStip dstBits;
+       FbStip *d;
+       FbStip dstMask;
+       FbStip dstMaskFirst;
+       FbStip dstUnion;
+       int w;
+       int wt;
+
+       if (!width)
+               return;
+
+       src += srcX >> FB_SHIFT;
+       srcX &= FB_MASK;
+
+       dst += dstX >> FB_STIP_SHIFT;
+       dstX &= FB_STIP_MASK;
+
+       w = width / srcBpp;
+
+       pm = fbReplicatePixel(planeMask, srcBpp);
+       srcMaskFirst = pm & FbBitsMask(srcX, srcBpp);
+       srcMask0 = pm & FbBitsMask(0, srcBpp);
+
+       dstMaskFirst = FbStipMask(dstX, 1);
+       while (height--) {
+               d = dst;
+               dst += dstStride;
+               s = src;
+               src += srcStride;
+
+               srcMask = srcMaskFirst;
+               srcBits = READ(s++);
+
+               dstMask = dstMaskFirst;
+               dstUnion = 0;
+               dstBits = 0;
+
+               wt = w;
+
+               while (wt--) {
+                       if (!srcMask) {
+                               srcBits = READ(s++);
+                               srcMask = srcMask0;
+                       }
+                       if (!dstMask) {
+                               WRITE(d, FbStippleRRopMask(READ(d), dstBits,
+                                                          fgand, fgxor, bgand, bgxor,
+                                                          dstUnion));
+                               d++;
+                               dstMask = FbStipMask(0, 1);
+                               dstUnion = 0;
+                               dstBits = 0;
+                       }
+                       if (srcBits & srcMask)
+                               dstBits |= dstMask;
+                       dstUnion |= dstMask;
+                       if (srcBpp == FB_UNIT)
+                               srcMask = 0;
+                       else
+                               srcMask = FbScrRight(srcMask, srcBpp);
+                       dstMask = FbStipRight(dstMask, 1);
+               }
+               if (dstUnion)
+                       WRITE(d, FbStippleRRopMask(READ(d), dstBits,
+                                                  fgand, fgxor, bgand, bgxor, dstUnion));
+       }
+}
diff --git a/src/sna/fb/fbclip.c b/src/sna/fb/fbclip.c
new file mode 100644 (file)
index 0000000..37011a7
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * Copyright © 2012 Intel 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.
+ *
+ * Authors:
+ *    Chris Wilson <chris@chris-wilson.co.uk>
+ *
+ */
+
+#include "fb.h"
+#include "fbclip.h"
+
+static const BoxRec *
+find_clip_row_for_y(const BoxRec *begin, const BoxRec *end, int16_t y)
+{
+       const BoxRec *mid;
+
+       if (end == begin)
+               return end;
+
+       if (end - begin == 1) {
+               if (begin->y2 > y)
+                       return begin;
+               else
+                       return end;
+       }
+
+       mid = begin + (end - begin) / 2;
+       if (mid->y2 > y)
+               return find_clip_row_for_y(begin, mid, y);
+       else
+               return find_clip_row_for_y(mid, end, y);
+}
+
+const BoxRec *
+fbClipBoxes(const RegionRec *region, const BoxRec *box, const BoxRec **end)
+{
+       const BoxRec *c0, *c1;
+
+       DBG(("%s: box=(%d, %d),(%d, %d); region=(%d, %d),(%d, %d) x %ld\n",
+            __FUNCTION__,
+            box->x1, box->y1, box->x2, box->y2,
+            region->extents.x1, region->extents.y1,
+            region->extents.x2, region->extents.y2,
+            region->data ? region->data->numRects : 1));
+
+       if (box->x1 >= region->extents.x2 || box->x2 <= region->extents.x1 ||
+           box->y1 >= region->extents.y2 || box->y2 <= region->extents.y1) {
+               DBG(("%s: no intersection\n", __FUNCTION__));
+               return *end = box;
+       }
+
+       if (region->data == NULL) {
+               *end = &region->extents + 1;
+               return &region->extents;
+       }
+
+       c0 = (const BoxRec *)(region->data + 1);
+       c1 = c0 + region->data->numRects;
+
+       if (c0->y2 <= box->y1) {
+               DBG(("%s: first clip (%d, %d), (%d, %d) before box (%d, %d), (%d, %d)\n",
+                    __FUNCTION__,
+                    c0->x1, c0->y1, c0->x2, c0->y2,
+                    box->x1, box->y1, box->x2, box->y2));
+               c0 = find_clip_row_for_y(c0, c1, box->y1);
+       }
+
+       DBG(("%s: c0=(%d, %d),(%d, %d) x %ld\n",
+            __FUNCTION__, c0->x1, c0->y1, c0->x2, c0->y2, c1 - c0));
+
+       *end = c1;
+       return c0;
+}
diff --git a/src/sna/fb/fbclip.h b/src/sna/fb/fbclip.h
new file mode 100644 (file)
index 0000000..f07e63c
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * Copyright © 2012 Intel 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.
+ *
+ * Authors:
+ *    Chris Wilson <chris@chris-wilson.co.uk>
+ *
+ */
+
+#ifndef FBCLIP_H
+#define FBCLIP_H
+
+extern const BoxRec *
+fbClipBoxes(const RegionRec *region, const BoxRec *box, const BoxRec **end);
+
+inline static bool
+box_intersect(BoxPtr a, const BoxRec *b)
+{
+       if (a->x1 < b->x1)
+               a->x1 = b->x1;
+       if (a->x2 > b->x2)
+               a->x2 = b->x2;
+       if (a->y1 < b->y1)
+               a->y1 = b->y1;
+       if (a->y2 > b->y2)
+               a->y2 = b->y2;
+
+       return a->x1 < a->x2 && a->y1 < a->y2;
+}
+
+#define run_box(b, c) \
+       DBG(("%s: box=(%d, %d), (%d, %d), clip=(%d, %d), (%d, %d)\n", \
+            __FUNCTION__, (b)->x1, (b)->y1, (b)->x2, (b)->y2, (c)->x1, (c)->y1, (c)->x2, (c)->y2)); \
+       if ((b)->y2 <= (c)->y1) break; \
+       if ((b)->x1 >= (c)->x2) continue; \
+       if ((b)->x2 <= (c)->x1) { if ((b)->y2 <= (c)->y2) break; continue; }
+
+static inline void
+fbDrawableRun(DrawablePtr d, GCPtr gc, const BoxRec *box,
+             void (*func)(DrawablePtr, GCPtr, const BoxRec *b, void *data),
+             void *data)
+{
+       const BoxRec *c, *end;
+       for (c = fbClipBoxes(gc->pCompositeClip, box, &end); c != end; c++) {
+               BoxRec b;
+
+               run_box(box, c);
+
+               b = *box;
+               if (box_intersect(&b, c))
+                       func(d, gc, &b, data);
+       }
+}
+
+static inline void
+fbDrawableRunUnclipped(DrawablePtr d, GCPtr gc, const BoxRec *box,
+                      void (*func)(DrawablePtr, GCPtr, const BoxRec *b, void *data),
+                      void *data)
+{
+       const BoxRec *c, *end;
+       for (c = fbClipBoxes(gc->pCompositeClip, box, &end); c != end; c++) {
+               run_box(box, c);
+               func(d, gc, c, data);
+       }
+}
+
+#endif /* FBCLIP_H */
diff --git a/src/sna/fb/fbcopy.c b/src/sna/fb/fbcopy.c
new file mode 100644 (file)
index 0000000..a486a5b
--- /dev/null
@@ -0,0 +1,225 @@
+/*
+ * Copyright © 1998 Keith Packard
+ * Copyright © 2012 Intel Corporation
+ *
+ * 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 Keith Packard not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission.  Keith Packard makes no
+ * representations about the suitability of this software for any purpose.  It
+ * is provided "as is" without express or implied warranty.
+ *
+ * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL KEITH PACKARD 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 <stdlib.h>
+
+#include "fb.h"
+#include <mi.h>
+
+void
+fbCopyNtoN(DrawablePtr src_drawable, DrawablePtr dst_drawable, GCPtr gc,
+           BoxPtr box, int nbox,
+           int dx, int dy,
+          Bool reverse, Bool upsidedown, Pixel bitplane,
+          void *closure)
+{
+       CARD8 alu = gc ? gc->alu : GXcopy;
+       FbBits pm = gc ? fb_gc(gc)->pm : FB_ALLONES;
+       FbBits *src, *dst;
+       FbStride srcStride, dstStride;
+       int dstBpp, srcBpp;
+       int srcXoff, srcYoff;
+       int dstXoff, dstYoff;
+
+       fbGetDrawable(src_drawable, src, srcStride, srcBpp, srcXoff, srcYoff);
+       fbGetDrawable(dst_drawable, dst, dstStride, dstBpp, dstXoff, dstYoff);
+
+       src += (dy + srcYoff) * srcStride;
+       srcXoff += dx;
+       dst += dstYoff * dstStride;
+       do {
+               fbBlt(src + box->y1 * srcStride, srcStride,
+                     (box->x1 + srcXoff) * srcBpp,
+                     dst + box->y1 * dstStride, dstStride,
+                     (box->x1 + dstXoff) * dstBpp,
+                     (box->x2 - box->x1) * dstBpp,
+                     (box->y2 - box->y1),
+                     alu, pm, dstBpp, reverse, upsidedown);
+       } while (box++, --nbox);
+}
+
+void
+fbCopy1toN(DrawablePtr src_drawable, DrawablePtr dst_drawable, GCPtr gc,
+           BoxPtr box, int nbox,
+           int dx, int dy,
+          Bool reverse, Bool upsidedown, Pixel bitplane,
+          void *closure)
+{
+       FbGCPrivPtr pgc = fb_gc(gc);
+       FbBits *src;
+       FbStride srcStride;
+       int srcBpp;
+       int srcXoff, srcYoff;
+       FbBits *dst;
+       FbStride dstStride;
+       int dstBpp;
+       int dstXoff, dstYoff;
+
+       fbGetDrawable(src_drawable, src, srcStride, srcBpp, srcXoff, srcYoff);
+       fbGetDrawable(dst_drawable, dst, dstStride, dstBpp, dstXoff, dstYoff);
+
+       while (nbox--) {
+               if (dstBpp == 1) {
+                       fbBlt(src + (box->y1 + dy + srcYoff) * srcStride,
+                             srcStride,
+                             (box->x1 + dx + srcXoff) * srcBpp,
+                             dst + (box->y1 + dstYoff) * dstStride,
+                             dstStride,
+                             (box->x1 + dstXoff) * dstBpp,
+                             (box->x2 - box->x1) * dstBpp,
+                             (box->y2 - box->y1),
+                             FbOpaqueStipple1Rop(gc->alu,
+                                                 gc->fgPixel, gc->bgPixel),
+                             pgc->pm, dstBpp, reverse, upsidedown);
+               } else {
+                       fbBltOne((FbStip *) (src + (box->y1 + dy + srcYoff) * srcStride),
+                                srcStride * (FB_UNIT / FB_STIP_UNIT),
+                                (box->x1 + dx + srcXoff),
+                                dst + (box->y1 + dstYoff) * dstStride,
+                                dstStride,
+                                (box->x1 + dstXoff) * dstBpp,
+                                dstBpp,
+                                (box->x2 - box->x1) * dstBpp,
+                                (box->y2 - box->y1),
+                                pgc->and, pgc->xor, pgc->bgand, pgc->bgxor);
+               }
+               box++;
+       }
+}
+
+void
+fbCopyNto1(DrawablePtr src_drawable, DrawablePtr dst_drawable, GCPtr gc,
+           BoxPtr box, int nbox,
+           int dx, int dy,
+          Bool reverse, Bool upsidedown, Pixel bitplane, void *closure)
+{
+       FbGCPrivPtr pgc = fb_gc(gc);
+
+       while (nbox--) {
+               if (dst_drawable->bitsPerPixel == 1) {
+                       FbBits *src;
+                       FbStride srcStride;
+                       int srcBpp;
+                       int srcXoff, srcYoff;
+
+                       FbStip *dst;
+                       FbStride dstStride;
+                       int dstBpp;
+                       int dstXoff, dstYoff;
+
+                       fbGetDrawable(src_drawable, src,
+                                     srcStride, srcBpp, srcXoff, srcYoff);
+                       fbGetStipDrawable(dst_drawable,
+                                         dst, dstStride, dstBpp, dstXoff, dstYoff);
+                       fbBltPlane(src + (box->y1 + dy + srcYoff) * srcStride, srcStride,
+                                  (box->x1 + dx + srcXoff) * srcBpp, srcBpp,
+                                  dst + (box->y1 + dstYoff) * dstStride, dstStride,
+                                  (box->x1 + dstXoff) * dstBpp,
+                                  (box->x2 - box->x1) * srcBpp, (box->y2 - box->y1),
+                                  (FbStip) pgc->and, (FbStip) pgc->xor,
+                                  (FbStip) pgc->bgand, (FbStip) pgc->bgxor, bitplane);
+               } else {
+                       FbBits *src;
+                       FbStride srcStride;
+                       int srcBpp;
+                       int srcXoff, srcYoff;
+
+                       FbBits *dst;
+                       FbStride dstStride;
+                       int dstBpp;
+                       int dstXoff, dstYoff;
+
+                       FbStip *tmp;
+                       FbStride tmpStride;
+                       int width, height;
+
+                       width = box->x2 - box->x1;
+                       height = box->y2 - box->y1;
+
+                       tmpStride = ((width + FB_STIP_MASK) >> FB_STIP_SHIFT);
+                       tmp = malloc(tmpStride * height * sizeof(FbStip));
+                       if (!tmp)
+                               return;
+
+                       fbGetDrawable(src_drawable, src,
+                                     srcStride, srcBpp, srcXoff, srcYoff);
+                       fbGetDrawable(dst_drawable, dst,
+                                     dstStride, dstBpp, dstXoff, dstYoff);
+
+                       fbBltPlane(src + (box->y1 + dy + srcYoff) * srcStride,
+                                  srcStride,
+                                  (box->x1 + dx + srcXoff) * srcBpp,
+                                  srcBpp,
+                                  tmp,
+                                  tmpStride,
+                                  0,
+                                  width * srcBpp,
+                                  height,
+                                  fbAndStip(GXcopy, FB_ALLONES, FB_ALLONES),
+                                  fbXorStip(GXcopy, FB_ALLONES, FB_ALLONES),
+                                  fbAndStip(GXcopy, 0, FB_ALLONES),
+                                  fbXorStip(GXcopy, 0, FB_ALLONES), bitplane);
+                       fbBltOne(tmp,
+                                tmpStride,
+                                0,
+                                dst + (box->y1 + dstYoff) * dstStride,
+                                dstStride,
+                                (box->x1 + dstXoff) * dstBpp,
+                                dstBpp,
+                                width * dstBpp,
+                                height,
+                                pgc->and, pgc->xor, pgc->bgand, pgc->bgxor);
+                       free(tmp);
+               }
+               box++;
+       }
+}
+
+RegionPtr
+fbCopyArea(DrawablePtr src, DrawablePtr dst, GCPtr gc,
+          int sx, int sy,
+          int width, int height,
+          int dx, int dy)
+{
+       return miDoCopy(src, dst, gc, sx, sy, width, height, dx, dy,
+                       fbCopyNtoN, 0, 0);
+}
+
+RegionPtr
+fbCopyPlane(DrawablePtr src, DrawablePtr dst, GCPtr gc,
+           int sx, int sy,
+           int width, int height,
+           int dx, int dy,
+           unsigned long bitplane)
+{
+       if (src->bitsPerPixel > 1)
+               return miDoCopy(src, dst, gc, sx, sy, width, height, dx, dy,
+                               fbCopyNto1, (Pixel) bitplane, 0);
+       else if (bitplane & 1)
+               return miDoCopy(src, dst, gc, sx, sy, width, height, dx, dy,
+                               fbCopy1toN, (Pixel) bitplane, 0);
+       else
+               return miHandleExposures(src, dst, gc,
+                                        sx, sy, width, height, dx, dy,
+                                        bitplane);
+}
diff --git a/src/sna/fb/fbfill.c b/src/sna/fb/fbfill.c
new file mode 100644 (file)
index 0000000..a9ae2bc
--- /dev/null
@@ -0,0 +1,221 @@
+/*
+ * Copyright © 1998 Keith Packard
+ * Copyright © 2012 Intel Corporation
+ *
+ * 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 Keith Packard not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission.  Keith Packard makes no
+ * representations about the suitability of this software for any purpose.  It
+ * is provided "as is" without express or implied warranty.
+ *
+ * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL KEITH PACKARD 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 "fb.h"
+#include "fbclip.h"
+
+static void
+fbSolid(FbBits * dst,
+        FbStride dstStride,
+        int dstX, int bpp, int width, int height, FbBits and, FbBits xor)
+{
+       FbBits startmask, endmask;
+       int n, nmiddle;
+       int startbyte, endbyte;
+
+       dst += dstX >> FB_SHIFT;
+       dstX &= FB_MASK;
+       FbMaskBitsBytes(dstX, width, and == 0, startmask, startbyte,
+                       nmiddle, endmask, endbyte);
+       if (startmask)
+               dstStride--;
+       dstStride -= nmiddle;
+       while (height--) {
+               if (startmask) {
+                       FbDoLeftMaskByteRRop(dst, startbyte, startmask, and, xor);
+                       dst++;
+               }
+               n = nmiddle;
+               if (!and)
+                       while (n--)
+                               WRITE(dst++, xor);
+               else
+                       while (n--) {
+                               WRITE(dst, FbDoRRop(READ(dst), and, xor));
+                               dst++;
+                       }
+               if (endmask)
+                       FbDoRightMaskByteRRop(dst, endbyte, endmask, and, xor);
+               dst += dstStride;
+       }
+}
+
+void
+fbFill(DrawablePtr drawable, GCPtr gc, int x, int y, int width, int height)
+{
+       FbBits *dst;
+       FbStride dstStride;
+       int dstBpp;
+       int dstXoff, dstYoff;
+       FbGCPrivPtr pgc = fb_gc(gc);
+
+       DBG(("%s (%d, %d)x(%d, %d), style=%d\n",
+            __FUNCTION__, x, y, width, height, gc->fillStyle));
+
+       fbGetDrawable(drawable, dst, dstStride, dstBpp, dstXoff, dstYoff);
+
+       switch (gc->fillStyle) {
+       case FillSolid:
+               if (pgc->and ||
+                   !pixman_fill((uint32_t *) dst, dstStride, dstBpp,
+                                x + dstXoff, y + dstYoff,
+                                width, height, pgc->xor))
+                       fbSolid(dst + (y + dstYoff) * dstStride,
+                               dstStride,
+                               (x + dstXoff) * dstBpp,
+                               dstBpp, width * dstBpp, height, pgc->and, pgc->xor);
+               break;
+
+       case FillStippled:
+       case FillOpaqueStippled:
+               {
+                       PixmapPtr pStip = gc->stipple;
+                       int stipWidth = pStip->drawable.width;
+                       int stipHeight = pStip->drawable.height;
+
+                       if (dstBpp == 1) {
+                               int alu;
+                               FbBits *stip;
+                               FbStride stipStride;
+                               int stipBpp;
+                               _X_UNUSED int stipXoff, stipYoff;
+
+                               if (gc->fillStyle == FillStippled)
+                                       alu = FbStipple1Rop(gc->alu, gc->fgPixel);
+                               else
+                                       alu = FbOpaqueStipple1Rop(gc->alu, gc->fgPixel, gc->bgPixel);
+                               fbGetDrawable(&pStip->drawable, stip, stipStride, stipBpp, stipXoff,
+                                             stipYoff);
+                               fbTile(dst + (y + dstYoff) * dstStride, dstStride, x + dstXoff,
+                                      width, height, stip, stipStride, stipWidth, stipHeight, alu,
+                                      pgc->pm, dstBpp, (gc->patOrg.x + drawable->x + dstXoff),
+                                      gc->patOrg.y + drawable->y - y);
+                       } else {
+                               FbStip *stip;
+                               FbStride stipStride;
+                               int stipBpp;
+                               _X_UNUSED int stipXoff, stipYoff;
+                               FbBits fgand, fgxor, bgand, bgxor;
+
+                               fgand = pgc->and;
+                               fgxor = pgc->xor;
+                               if (gc->fillStyle == FillStippled) {
+                                       bgand = fbAnd(GXnoop, (FbBits) 0, FB_ALLONES);
+                                       bgxor = fbXor(GXnoop, (FbBits) 0, FB_ALLONES);
+                               } else {
+                                       bgand = pgc->bgand;
+                                       bgxor = pgc->bgxor;
+                               }
+
+                               fbGetStipDrawable(&pStip->drawable, stip, stipStride, stipBpp,
+                                                 stipXoff, stipYoff);
+                               fbStipple(dst + (y + dstYoff) * dstStride, dstStride,
+                                         (x + dstXoff) * dstBpp, dstBpp, width * dstBpp, height,
+                                         stip, stipStride, stipWidth, stipHeight,
+                                         pgc->evenStipple, fgand, fgxor, bgand, bgxor,
+                                         gc->patOrg.x + drawable->x + dstXoff,
+                                         gc->patOrg.y + drawable->y - y);
+                       }
+                       break;
+               }
+
+       case FillTiled:
+               {
+                       PixmapPtr tile = gc->tile.pixmap;
+
+                       fbTile(dst + (y + dstYoff) * dstStride, dstStride,
+                              (x + dstXoff) * dstBpp, width * dstBpp, height,
+                              tile->devPrivate.ptr, tile->devKind / sizeof(FbBits),
+                              tile->drawable.width * tile->drawable.bitsPerPixel,
+                              tile->drawable.height,
+                              gc->alu, pgc->pm, dstBpp,
+                              (gc->patOrg.x + drawable->x + dstXoff) * dstBpp,
+                              gc->patOrg.y + drawable->y - y);
+                       break;
+               }
+       }
+}
+
+static void
+_fbSolidBox(DrawablePtr drawable, GCPtr gc, const BoxRec *b, void *_data)
+{
+       FbBits *dst;
+       FbStride stride;
+       int dx, dy, bpp;
+       FbBits and = fbAnd(GXcopy, fb_gc(gc)->bg, fb_gc(gc)->pm);
+       FbBits xor = fbXor(GXcopy, fb_gc(gc)->bg, fb_gc(gc)->pm);
+
+       fbGetDrawable(drawable, dst, stride, bpp, dx, dy);
+
+       if (and ||
+           !pixman_fill((uint32_t *) dst, stride, bpp,
+                        b->x1 + dx, b->y1 + dy,
+                        (b->x2 - b->x1), (b->y2 - b->y1), xor))
+               fbSolid(dst + (b->y1 + dy) * stride, stride,
+                       (b->x1 + dx) * bpp, bpp,
+                       (b->x2 - b->x1) * bpp, (b->y2 - b->y1),
+                       and, xor);
+}
+
+void
+fbSolidBoxClipped(DrawablePtr drawable, GCPtr gc,
+                  int x1, int y1, int x2, int y2)
+{
+       BoxRec box;
+
+       box.x1 = x1;
+       box.y1 = y1;
+       box.x2 = x2;
+       box.y2 = y2;
+
+       fbDrawableRun(drawable, gc, &box, _fbSolidBox, NULL);
+}
+
+inline static void
+fbFillBox(DrawablePtr drawable, GCPtr gc, const BoxRec *box, void *data)
+{
+       DBG(("%s box=(%d, %d), (%d, %d)\n", __FUNCTION__,
+            box->x1, box->y1, box->x2, box->y2));
+       fbFill(drawable, gc,
+              box->x1, box->y1,
+              box->x2 - box->x1, box->y2 - box->y1);
+}
+
+void
+fbPolyFillRect(DrawablePtr drawable, GCPtr gc, int n, xRectangle *r)
+{
+       DBG(("%s x %d\n", __FUNCTION__, n));
+       while (n--) {
+               BoxRec b;
+
+               b.x1 = r->x + drawable->x;
+               b.y1 = r->y + drawable->y;
+               b.x2 = fbBound(b.x1, r->width);
+               b.y2 = fbBound(b.y1, r->height);
+               r++;
+
+               DBG(("%s: rectangle (%d, %d), (%d, %d)\n",
+                    __FUNCTION__, b.x1, b.y1, b.x2, b.y2));
+               fbDrawableRun(drawable, gc, &b, fbFillBox, NULL);
+       }
+}
diff --git a/src/sna/fb/fbgc.c b/src/sna/fb/fbgc.c
new file mode 100644 (file)
index 0000000..83956c4
--- /dev/null
@@ -0,0 +1,198 @@
+/*
+ * Copyright © 1998 Keith Packard
+ * Copyright © 2012 Intel Corporation
+ *
+ * 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 Keith Packard not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission.  Keith Packard makes no
+ * representations about the suitability of this software for any purpose.  It
+ * is provided "as is" without express or implied warranty.
+ *
+ * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL KEITH PACKARD 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 "fb.h"
+#include <gcstruct.h>
+#include <migc.h>
+#include <scrnintstr.h>
+
+/*
+ * Pad pixmap to FB_UNIT bits wide
+ */
+void
+fbPadPixmap(PixmapPtr pPixmap)
+{
+       int width;
+       FbBits *bits;
+       FbBits b;
+       FbBits mask;
+       int height;
+       int w;
+       int stride;
+       int bpp;
+       _X_UNUSED int xOff, yOff;
+
+       fbGetDrawable(&pPixmap->drawable, bits, stride, bpp, xOff, yOff);
+
+       width = pPixmap->drawable.width * pPixmap->drawable.bitsPerPixel;
+       height = pPixmap->drawable.height;
+       mask = FbBitsMask(0, width);
+       while (height--) {
+               b = READ(bits) & mask;
+               w = width;
+               while (w < FB_UNIT) {
+                       b = b | FbScrRight(b, w);
+                       w <<= 1;
+               }
+               WRITE(bits, b);
+               bits += stride;
+       }
+}
+
+/*
+ * Verify that 'bits' repeats every 'len' bits
+ */
+static Bool
+fbBitsRepeat(FbBits bits, int len, int width)
+{
+       FbBits mask = FbBitsMask(0, len);
+       FbBits orig = bits & mask;
+       int i;
+
+       if (width > FB_UNIT)
+               width = FB_UNIT;
+       for (i = 0; i < width / len; i++) {
+               if ((bits & mask) != orig)
+                       return FALSE;
+               bits = FbScrLeft(bits, len);
+       }
+       return TRUE;
+}
+
+/*
+ * Check whether an entire bitmap line is a repetition of
+ * the first 'len' bits
+ */
+static Bool
+fbLineRepeat(FbBits * bits, int len, int width)
+{
+       FbBits first = bits[0];
+
+       if (!fbBitsRepeat(first, len, width))
+               return FALSE;
+       width = (width + FB_UNIT - 1) >> FB_SHIFT;
+       bits++;
+       while (--width)
+               if (READ(bits) != first)
+                       return FALSE;
+       return TRUE;
+}
+
+/*
+ * The even stipple code wants the first FB_UNIT/bpp bits on
+ * each scanline to represent the entire stipple
+ */
+static Bool
+fbCanEvenStipple(PixmapPtr pStipple, int bpp)
+{
+       int len = FB_UNIT / bpp;
+       FbBits *bits;
+       int stride;
+       int stip_bpp;
+       _X_UNUSED int stipXoff, stipYoff;
+       int h;
+
+       /* make sure the stipple width is a multiple of the even stipple width */
+       if (pStipple->drawable.width % len != 0)
+               return FALSE;
+
+       fbGetDrawable(&pStipple->drawable, bits, stride, stip_bpp, stipXoff,
+                     stipYoff);
+       h = pStipple->drawable.height;
+       /* check to see that the stipple repeats horizontally */
+       while (h--) {
+               if (!fbLineRepeat(bits, len, pStipple->drawable.width))
+                       return FALSE;
+
+               bits += stride;
+       }
+       return TRUE;
+}
+
+void
+fbValidateGC(GCPtr gc, unsigned long changes, DrawablePtr drawable)
+{
+       FbGCPrivPtr pgc = fb_gc(gc);
+       FbBits mask;
+
+       DBG(("%s changes=%lx\n", __FUNCTION__, changes));
+
+       if (changes & GCStipple) {
+               pgc->evenStipple = FALSE;
+
+               if (gc->stipple) {
+                       /* can we do an even stipple ?? */
+                       if (FbEvenStip(gc->stipple->drawable.width,
+                                      drawable->bitsPerPixel) &&
+                           (fbCanEvenStipple(gc->stipple, drawable->bitsPerPixel)))
+                               pgc->evenStipple = TRUE;
+               }
+       }
+
+       /*
+        * Recompute reduced rop values
+        */
+       if (changes & (GCForeground | GCBackground | GCPlaneMask | GCFunction)) {
+               int s;
+               FbBits depthMask;
+
+               mask = FbFullMask(drawable->bitsPerPixel);
+               depthMask = FbFullMask(drawable->depth);
+
+               DBG(("%s: computing rrop mask=%08x, depthMask=%08x, fg=%08x, bg=%08x, planemask=%08x\n",
+                    __FUNCTION__, mask, depthMask, (int)gc->fgPixel, (int)gc->bgPixel, (int)gc->planemask));
+
+               pgc->fg = gc->fgPixel & mask;
+               pgc->bg = gc->bgPixel & mask;
+
+               if ((gc->planemask & depthMask) == depthMask)
+                       pgc->pm = mask;
+               else
+                       pgc->pm = gc->planemask & mask;
+
+               s = drawable->bitsPerPixel;
+               while (s < FB_UNIT) {
+                       pgc->fg |= pgc->fg << s;
+                       pgc->bg |= pgc->bg << s;
+                       pgc->pm |= pgc->pm << s;
+                       s <<= 1;
+               }
+               pgc->and = fbAnd(gc->alu, pgc->fg, pgc->pm);
+               pgc->xor = fbXor(gc->alu, pgc->fg, pgc->pm);
+               pgc->bgand = fbAnd(gc->alu, pgc->bg, pgc->pm);
+               pgc->bgxor = fbXor(gc->alu, pgc->bg, pgc->pm);
+
+               DBG(("%s: rrop fg=%08x, bg=%08x, pm=%08x, and=%08x, xor=%08x, bgand=%08x, bgxor=%08x\n",
+                    __FUNCTION__, pgc->fg, pgc->bg, pgc->pm, pgc->and, pgc->xor, pgc->bgand, pgc->bgxor));
+       }
+
+       if (changes & GCDashList) {
+               unsigned short n = gc->numInDashList;
+               unsigned char *dash = gc->dash;
+               unsigned int dashLength = 0;
+
+               while (n--)
+                       dashLength += (unsigned int) *dash++;
+               pgc->dashLength = dashLength;
+       }
+}
diff --git a/src/sna/fb/fbglyph.c b/src/sna/fb/fbglyph.c
new file mode 100644 (file)
index 0000000..789e5b8
--- /dev/null
@@ -0,0 +1,277 @@
+/*
+ * Copyright © 1998 Keith Packard
+ * Copyright © 2012 Intel Corporation
+ *
+ * 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 Keith Packard not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission.  Keith Packard makes no
+ * representations about the suitability of this software for any purpose.  It
+ * is provided "as is" without express or implied warranty.
+ *
+ * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL KEITH PACKARD 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 "fb.h"
+#include <X11/fonts/fontstruct.h>
+#include <dixfontstr.h>
+
+#define GLYPH      fbGlyph8
+#define BITS       BYTE
+#define BITS2      CARD16
+#define BITS4      CARD32
+#include "fbglyphbits.h"
+#undef BITS
+#undef BITS2
+#undef BITS4
+#undef GLYPH
+
+#define GLYPH      fbGlyph16
+#define BITS       CARD16
+#define BITS2      CARD32
+#include "fbglyphbits.h"
+#undef BITS
+#undef BITS2
+#undef GLYPH
+
+#define GLYPH      fbGlyph32
+#define BITS       CARD32
+#include "fbglyphbits.h"
+#undef BITS
+#undef GLYPH
+
+static bool
+fbGlyphIn(GCPtr gc, int x, int y, int width, int height)
+{
+       BoxRec box;
+       BoxPtr extents = RegionExtents(gc->pCompositeClip);
+
+       /*
+        * Check extents by hand to avoid 16 bit overflows
+        */
+       if (x < (int) extents->x1 || (int) extents->x2 < x + width)
+               return FALSE;
+       if (y < (int) extents->y1 || (int) extents->y2 < y + height)
+               return FALSE;
+
+       box.x1 = x;
+       box.x2 = x + width;
+       box.y1 = y;
+       box.y2 = y + height;
+       return RegionContainsRect(gc->pCompositeClip, &box) == rgnIN;
+}
+
+#define WRITE1(d,n,fg) WRITE((d) + (n), (CARD8) fg)
+#define WRITE2(d,n,fg) WRITE((CARD16 *) &(d[n]), (CARD16) fg)
+#define WRITE4(d,n,fg) WRITE((CARD32 *) &(d[n]), (CARD32) fg)
+
+/*
+ * This is a bit tricky, but it's brief.  Write 12 bytes worth
+ * of dest, which is four pixels, at a time.  This gives constant
+ * code for each pattern as they're always aligned the same
+ *
+ *  a b c d  a b c d  a b c d  bytes
+ *  A B C A  B C A B  C A B C  pixels
+ * 
+ *    f0        f1       f2
+ *  A B C A  B C A B  C A B C  pixels LSB
+ *  C A B C  A B C A  B C A B  pixels MSB
+ *
+ *             LSB     MSB
+ *  A          f0      f1
+ *  B          f1      f2
+ *  C          f2      f0
+ *  A B                f0      f2
+ *  B C                f1      f0
+ *  C A                f2      f1
+ *  A B C A    f0      f1
+ *  B C A B    f1      f2
+ *  C A B C    f2      f0
+ */
+
+#undef _A
+#undef _B
+#undef _C
+#undef _AB
+#undef _BC
+#undef _CA
+#undef _ABCA
+#undef _BCAB
+#undef _CABC
+
+#define _A     f0
+#define _B     f1
+#define _C     f2
+#define _AB    f0
+#define _BC    f1
+#define _CA    f2
+#define _ABCA  f0
+#define _BCAB  f1
+#define _CABC  f2
+#define CASE(a,b,c,d)  (a | (b << 1) | (c << 2) | (d << 3))
+
+void
+fbPolyGlyphBlt(DrawablePtr drawable, GCPtr gc,
+               int x, int y,
+               unsigned int nglyph, CharInfoPtr * ppci, pointer glyphs)
+{
+       FbGCPrivPtr pgc = fb_gc(gc);
+       CharInfoPtr pci;
+       unsigned char *pglyph;      /* pointer bits in glyph */
+       int gx, gy;
+       int gWidth, gHeight;        /* width and height of glyph */
+       FbStride gStride;           /* stride of glyph */
+       void (*raster) (FbBits *, FbStride, int, FbStip *, FbBits, int, int);
+       FbBits *dst = 0;
+       FbStride dstStride = 0;
+       int dstBpp = 0;
+       int dstXoff = 0, dstYoff = 0;
+
+       DBG(("%s x %d\n", __FUNCTION__, nglyph));
+
+       raster = 0;
+       if (gc->fillStyle == FillSolid && pgc->and == 0) {
+               dstBpp = drawable->bitsPerPixel;
+               switch (dstBpp) {
+               case 8:
+                       raster = fbGlyph8;
+                       break;
+               case 16:
+                       raster = fbGlyph16;
+                       break;
+               case 32:
+                       raster = fbGlyph32;
+                       break;
+               }
+       }
+       x += drawable->x;
+       y += drawable->y;
+
+       while (nglyph--) {
+               pci = *ppci++;
+               pglyph = FONTGLYPHBITS(glyphs, pci);
+               gWidth = GLYPHWIDTHPIXELS(pci);
+               gHeight = GLYPHHEIGHTPIXELS(pci);
+               if (gWidth && gHeight) {
+                       gx = x + pci->metrics.leftSideBearing;
+                       gy = y - pci->metrics.ascent;
+                       if (raster && gWidth <= sizeof(FbStip) * 8 &&
+                           fbGlyphIn(gc, gx, gy, gWidth, gHeight)) {
+                               fbGetDrawable(drawable, dst, dstStride, dstBpp, dstXoff,
+                                             dstYoff);
+                               raster(dst + (gy + dstYoff) * dstStride, dstStride, dstBpp,
+                                         (FbStip *) pglyph, pgc->xor, gx + dstXoff, gHeight);
+                       } else {
+                               gStride = GLYPHWIDTHBYTESPADDED(pci) / sizeof(FbStip);
+                               fbPushImage(drawable, gc,
+                                           (FbStip *)pglyph,
+                                           gStride, 0, gx, gy, gWidth, gHeight);
+                       }
+               }
+               x += pci->metrics.characterWidth;
+       }
+}
+
+void
+fbImageGlyphBlt(DrawablePtr drawable, GCPtr gc,
+                int x, int y,
+                unsigned int nglyph, CharInfoPtr * ppciInit, pointer glyphs)
+{
+       FbGCPrivPtr pgc = fb_gc(gc);
+       CharInfoPtr *ppci;
+       CharInfoPtr pci;
+       unsigned char *pglyph;      /* pointer bits in glyph */
+       int gWidth, gHeight;        /* width and height of glyph */
+       FbStride gStride;           /* stride of glyph */
+       bool opaque;
+       int n;
+       int gx, gy;
+       void (*raster)(FbBits *, FbStride, int, FbStip *, FbBits, int, int);
+       FbBits *dst = 0;
+       FbStride dstStride = 0;
+       int dstBpp = 0;
+       int dstXoff = 0, dstYoff = 0;
+
+       DBG(("%s x %d\n", __FUNCTION__, nglyph));
+
+       raster = 0;
+       if (pgc->and == 0) {
+               dstBpp = drawable->bitsPerPixel;
+               switch (dstBpp) {
+               case 8:
+                       raster = fbGlyph8;
+                       break;
+               case 16:
+                       raster = fbGlyph16;
+                       break;
+               case 32:
+                       raster = fbGlyph32;
+                       break;
+               }
+       }
+
+       x += drawable->x;
+       y += drawable->y;
+
+       if (TERMINALFONT(gc->font) && !raster) {
+               opaque = TRUE;
+       } else {
+               int xBack, widthBack;
+               int yBack, heightBack;
+
+               ppci = ppciInit;
+               n = nglyph;
+               widthBack = 0;
+               while (n--)
+                       widthBack += (*ppci++)->metrics.characterWidth;
+
+               xBack = x;
+               if (widthBack < 0) {
+                       xBack += widthBack;
+                       widthBack = -widthBack;
+               }
+               yBack = y - FONTASCENT(gc->font);
+               heightBack = FONTASCENT(gc->font) + FONTDESCENT(gc->font);
+               fbSolidBoxClipped(drawable, gc,
+                                 xBack, yBack,
+                                 xBack + widthBack,
+                                 yBack + heightBack);
+               opaque = FALSE;
+       }
+
+       ppci = ppciInit;
+       while (nglyph--) {
+               pci = *ppci++;
+               pglyph = FONTGLYPHBITS(glyphs, pci);
+               gWidth = GLYPHWIDTHPIXELS(pci);
+               gHeight = GLYPHHEIGHTPIXELS(pci);
+               if (gWidth && gHeight) {
+                       gx = x + pci->metrics.leftSideBearing;
+                       gy = y - pci->metrics.ascent;
+                       if (raster && gWidth <= sizeof(FbStip) * 8 &&
+                           fbGlyphIn(gc, gx, gy, gWidth, gHeight)) {
+                               fbGetDrawable(drawable, dst, dstStride, dstBpp, dstXoff,
+                                             dstYoff);
+                               raster(dst + (gy + dstYoff) * dstStride, dstStride, dstBpp,
+                                      (FbStip *) pglyph, pgc->fg, gx + dstXoff, gHeight);
+                       } else {
+                               gStride = GLYPHWIDTHBYTESPADDED(pci) / sizeof(FbStip);
+                               fbPutXYImage(drawable, gc,
+                                            pgc->fg, pgc->bg, pgc->pm,
+                                            GXcopy, opaque,
+                                            gx, gy, gWidth, gHeight,
+                                            (FbStip *) pglyph, gStride, 0);
+                       }
+               }
+               x += pci->metrics.characterWidth;
+       }
+}
diff --git a/src/sna/fb/fbglyphbits.h b/src/sna/fb/fbglyphbits.h
new file mode 100644 (file)
index 0000000..af0f00f
--- /dev/null
@@ -0,0 +1,140 @@
+/*
+ * Copyright © 1998 Keith Packard
+ * Copyright © 2012 Intel Corporation
+ *
+ * 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 Keith Packard not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission.  Keith Packard makes no
+ * representations about the suitability of this software for any purpose.  It
+ * is provided "as is" without express or implied warranty.
+ *
+ * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL KEITH PACKARD 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.
+ */
+
+#define isClipped(c,ul,lr)  (((c) | ((c) - (ul)) | ((lr) - (c))) & 0x80008000)
+#define RROP(b,a,x)    WRITE((b), FbDoRRop (READ(b), (a), (x)))
+
+#define WRITE_ADDR1(n)     (n)
+#define WRITE_ADDR2(n)     (n)
+#define WRITE_ADDR4(n)     (n)
+
+#define WRITE1(d,n,fg)     WRITE(d + WRITE_ADDR1(n), (BITS) (fg))
+
+#ifdef BITS2
+#define WRITE2(d,n,fg)     WRITE((BITS2 *) &((d)[WRITE_ADDR2(n)]), (BITS2) (fg))
+#else
+#define WRITE2(d,n,fg)     (WRITE1(d,n,fg), WRITE1(d,(n)+1,fg))
+#endif
+
+#ifdef BITS4
+#define WRITE4(d,n,fg)     WRITE((BITS4 *) &((d)[WRITE_ADDR4(n)]), (BITS4) (fg))
+#else
+#define WRITE4(d,n,fg)     (WRITE2(d,n,fg), WRITE2(d,(n)+2,fg))
+#endif
+
+static void
+GLYPH(FbBits * dstBits,
+      FbStride dstStride,
+      int dstBpp, FbStip * stipple, FbBits fg, int x, int height)
+{
+       int lshift;
+       FbStip bits;
+       BITS *dstLine;
+       BITS *dst;
+       int n;
+       int shift;
+
+       dstLine = (BITS *) dstBits;
+       dstLine += x & ~3;
+       dstStride *= (sizeof(FbBits) / sizeof(BITS));
+       shift = x & 3;
+       lshift = 4 - shift;
+       while (height--) {
+               bits = *stipple++;
+               dst = (BITS *) dstLine;
+               n = lshift;
+               while (bits) {
+                       switch (FbStipMoveLsb(FbLeftStipBits(bits, n), 4, n)) {
+                       case 0:
+                               break;
+                       case 1:
+                               WRITE1(dst, 0, fg);
+                               break;
+                       case 2:
+                               WRITE1(dst, 1, fg);
+                               break;
+                       case 3:
+                               WRITE2(dst, 0, fg);
+                               break;
+                       case 4:
+                               WRITE1(dst, 2, fg);
+                               break;
+                       case 5:
+                               WRITE1(dst, 0, fg);
+                               WRITE1(dst, 2, fg);
+                               break;
+                       case 6:
+                               WRITE1(dst, 1, fg);
+                               WRITE1(dst, 2, fg);
+                               break;
+                       case 7:
+                               WRITE2(dst, 0, fg);
+                               WRITE1(dst, 2, fg);
+                               break;
+                       case 8:
+                               WRITE1(dst, 3, fg);
+                               break;
+                       case 9:
+                               WRITE1(dst, 0, fg);
+                               WRITE1(dst, 3, fg);
+                               break;
+                       case 10:
+                               WRITE1(dst, 1, fg);
+                               WRITE1(dst, 3, fg);
+                               break;
+                       case 11:
+                               WRITE2(dst, 0, fg);
+                               WRITE1(dst, 3, fg);
+                               break;
+                       case 12:
+                               WRITE2(dst, 2, fg);
+                               break;
+                       case 13:
+                               WRITE1(dst, 0, fg);
+                               WRITE2(dst, 2, fg);
+                               break;
+                       case 14:
+                               WRITE1(dst, 1, fg);
+                               WRITE2(dst, 2, fg);
+                               break;
+                       case 15:
+                               WRITE4(dst, 0, fg);
+                               break;
+                       }
+                       bits = FbStipLeft(bits, n);
+                       n = 4;
+                       dst += 4;
+               }
+               dstLine += dstStride;
+       }
+}
+
+#undef WRITE_ADDR1
+#undef WRITE_ADDR2
+#undef WRITE_ADDR4
+#undef WRITE1
+#undef WRITE2
+#undef WRITE4
+
+#undef RROP
+#undef isClipped
diff --git a/src/sna/fb/fbimage.c b/src/sna/fb/fbimage.c
new file mode 100644 (file)
index 0000000..5af2389
--- /dev/null
@@ -0,0 +1,254 @@
+/*
+ * Copyright © 1998 Keith Packard
+ * Copyright © 2012 Intel Corporation
+ *
+ * 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 Keith Packard not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission.  Keith Packard makes no
+ * representations about the suitability of this software for any purpose.  It
+ * is provided "as is" without express or implied warranty.
+ *
+ * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL KEITH PACKARD 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 <string.h>
+
+#include "fb.h"
+#include "fbclip.h"
+
+struct fbPutZImage {
+       FbStip *src, *dst;
+       FbStride src_stride, dst_stride;
+
+       int dst_x, dst_y;
+       int x0, y0;
+};
+
+inline static void
+_fbPutZImage(DrawablePtr drawable, GCPtr gc, const BoxRec *b, void *_data)
+{
+       struct fbPutZImage *data = _data;
+       int bpp = drawable->bitsPerPixel;
+
+       fbBltStip(data->src + (b->y1 - data->y0) * data->src_stride, data->src_stride,
+                 (b->x1 - data->x0) * bpp,
+                 data->dst + (b->y1 + data->dst_y) * data->dst_stride,
+                 data->dst_stride,
+                 (b->x1 + data->dst_x) * bpp,
+                 (b->x2 - b->x1) * bpp, (b->y2 - b->y1),
+                 gc->alu, fb_gc(gc)->pm, bpp);
+}
+
+static void
+fbPutZImage(DrawablePtr drawable, GCPtr gc,
+            int x, int y, int width, int height,
+           FbStip *src, FbStride srcStride)
+{
+       PixmapPtr pixmap;
+       struct fbPutZImage data;
+       BoxRec box;
+
+       box.x1 = data.x0 = x;
+       box.y1 = data.y0 = y;
+       box.x2 = x + width;
+       box.y2 = y + height;
+       data.src = src;
+       data.src_stride = srcStride;
+
+       fbGetDrawablePixmap(drawable, pixmap, data.dst_x, data.dst_y);
+       data.dst = pixmap->devPrivate.ptr;
+       data.dst_stride = pixmap->devKind / sizeof(FbStip);
+
+       fbDrawableRun(drawable, gc, &box, _fbPutZImage, &data);
+}
+
+struct fbPutXYImage {
+       FbStip *src, *dst;
+       FbStride src_stride, dst_stride;
+
+       int dst_x, dst_y, src_x;
+       int x0, y0;
+
+       int alu, pm;
+       FbBits fgand, fgxor, bgand, bgxor;
+};
+
+inline static void
+_fbPutXYImage1(DrawablePtr drawable, GCPtr gc, const BoxRec *b, void *_data)
+{
+       struct fbPutXYImage *data = _data;
+       int bpp = drawable->bitsPerPixel;
+
+       fbBltStip(data->src + (b->y1 - data->y0) * data->src_stride, data->src_stride,
+                 (b->x1 - data->x0) + data->src_x,
+                 (FbStip *) (data->dst + (b->y1 + data->dst_y) * data->dst_stride),
+                 data->dst_stride,
+                 (b->x1 + data->dst_x) * bpp,
+                 (b->x2 - b->x1) * bpp, (b->y2 - b->y1),
+                 data->alu, data->pm, bpp);
+}
+
+inline static void
+_fbPutXYImageN(DrawablePtr drawable, GCPtr gc, const BoxRec *b, void *_data)
+{
+       struct fbPutXYImage *data = _data;
+       int bpp = drawable->bitsPerPixel;
+
+       fbBltOne(data->src + (b->y1 - data->y0) * data->src_stride,
+                data->src_stride,
+                (b->x1 - data->x0) + data->src_x,
+                data->dst + (b->y1 + data->dst_y) * data->dst_stride,
+                data->dst_stride,
+                (b->x1 + data->dst_x) * bpp, bpp,
+                (b->x2 - b->x1) * bpp, (b->y2 - b->y1),
+                data->fgand, data->fgxor,
+                data->bgand, data->bgxor);
+}
+
+void
+fbPutXYImage(DrawablePtr drawable, GCPtr gc,
+             FbBits fg, FbBits bg, FbBits pm, int alu, Bool opaque,
+             int x, int y, int width, int height,
+            FbStip *src, FbStride srcStride, int srcX)
+{
+       PixmapPtr pixmap;
+       struct fbPutXYImage data;
+       BoxRec box;
+
+       box.x1 = data.x0 = x;
+       box.y1 = data.y0 = y;
+       box.x2 = x + width;
+       box.y2 = y + height;
+       data.src = src;
+       data.src_stride = srcStride;
+       data.src_x = srcX;
+
+       fbGetDrawablePixmap(drawable, pixmap, data.dst_x, data.dst_y);
+       data.dst = pixmap->devPrivate.ptr;
+       data.dst_stride = pixmap->devKind / sizeof(FbStip);
+
+       if (drawable->bitsPerPixel == 1) {
+               if (opaque)
+                       data.alu = FbOpaqueStipple1Rop(alu, fg, bg);
+               else
+                       data.alu = FbStipple1Rop(alu, fg);
+               data.pm = pm;
+
+               fbDrawableRun(drawable, gc, &box, _fbPutXYImage1, &data);
+       } else {
+               data.fgand = fbAnd(alu, fg, pm);
+               data.fgxor = fbXor(alu, fg, pm);
+               if (opaque) {
+                       data.bgand = fbAnd(alu, bg, pm);
+                       data.bgxor = fbXor(alu, bg, pm);
+               } else {
+                       data.bgand = fbAnd(GXnoop, (FbBits) 0, FB_ALLONES);
+                       data.bgxor = fbXor(GXnoop, (FbBits) 0, FB_ALLONES);
+               }
+
+               fbDrawableRun(drawable, gc, &box, _fbPutXYImageN, &data);
+       }
+}
+
+void
+fbPutImage(DrawablePtr drawable, GCPtr gc, int depth,
+           int x, int y, int w, int h,
+          int leftPad, int format, char *image)
+{
+       FbGCPrivPtr pgc = fb_gc(gc);
+       unsigned long i;
+       FbStride srcStride;
+       FbStip *src = (FbStip *)image;
+
+       DBG(("%s (%d, %d)x(%d, %d)\n", __FUNCTION__, x, y, w, h));
+
+       x += drawable->x;
+       y += drawable->y;
+
+       switch (format) {
+       case XYBitmap:
+               srcStride = BitmapBytePad(w + leftPad) / sizeof(FbStip);
+               fbPutXYImage(drawable, gc,
+                            pgc->fg, pgc->bg, pgc->pm,
+                            gc->alu, TRUE,
+                            x, y, w, h,
+                            src, srcStride, leftPad);
+               break;
+       case XYPixmap:
+               srcStride = BitmapBytePad(w + leftPad) / sizeof(FbStip);
+               for (i = (unsigned long) 1 << (drawable->depth - 1); i; i >>= 1) {
+                       if (i & gc->planemask) {
+                               fbPutXYImage(drawable, gc,
+                                            FB_ALLONES,
+                                            0,
+                                            fbReplicatePixel(i, drawable->bitsPerPixel),
+                                            gc->alu,
+                                            TRUE, x, y, w, h, src, srcStride, leftPad);
+                               src += srcStride * h;
+                       }
+               }
+               break;
+       case ZPixmap:
+               srcStride = PixmapBytePad(w, drawable->depth) / sizeof(FbStip);
+               fbPutZImage(drawable, gc,
+                           x, y, w, h, src, srcStride);
+       }
+}
+
+void
+fbGetImage(DrawablePtr drawable,
+           int x, int y, int w, int h,
+          unsigned int format, unsigned long planeMask, char *d)
+{
+       FbBits *src;
+       FbStride srcStride;
+       int srcBpp;
+       int srcXoff, srcYoff;
+       FbStip *dst;
+       FbStride dstStride;
+
+       DBG(("%s (%d, %d)x(%d, %d)\n", __FUNCTION__, x, y, w, h));
+
+       fbGetDrawable(drawable, src, srcStride, srcBpp, srcXoff, srcYoff);
+
+       x += drawable->x;
+       y += drawable->y;
+
+       dst = (FbStip *) d;
+       if (format == ZPixmap || srcBpp == 1) {
+               FbBits pm;
+
+               pm = fbReplicatePixel(planeMask, srcBpp);
+               dstStride = PixmapBytePad(w, drawable->depth);
+               if (pm != FB_ALLONES)
+                       memset(d, 0, dstStride * h);
+               dstStride /= sizeof(FbStip);
+               fbBltStip((FbStip *)(src + (y + srcYoff) * srcStride), srcStride,
+                         (x + srcXoff) * srcBpp,
+                         dst, dstStride, 0, w * srcBpp, h, GXcopy, pm, srcBpp);
+       } else {
+               dstStride = BitmapBytePad(w) / sizeof(FbStip);
+               fbBltPlane(src + (y + srcYoff) * srcStride,
+                          srcStride,
+                          (x + srcXoff) * srcBpp,
+                          srcBpp,
+                          dst,
+                          dstStride,
+                          0,
+                          w * srcBpp, h,
+                          fbAndStip(GXcopy, FB_STIP_ALLONES, FB_STIP_ALLONES),
+                          fbXorStip(GXcopy, FB_STIP_ALLONES, FB_STIP_ALLONES),
+                          fbAndStip(GXcopy, 0, FB_STIP_ALLONES),
+                          fbXorStip(GXcopy, 0, FB_STIP_ALLONES), planeMask);
+       }
+}
diff --git a/src/sna/fb/fbline.c b/src/sna/fb/fbline.c
new file mode 100644 (file)
index 0000000..04d5343
--- /dev/null
@@ -0,0 +1,179 @@
+/*
+ * Copyright © 1998 Keith Packard
+ * Copyright © 2012 Intel Corporation
+ *
+ * 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 Keith Packard not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission.  Keith Packard makes no
+ * representations about the suitability of this software for any purpose.  It
+ * is provided "as is" without express or implied warranty.
+ *
+ * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL KEITH PACKARD 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 "fb.h"
+#include <mi.h>
+#include <micoord.h>
+#include <miline.h>
+#include <scrnintstr.h>
+
+#define POLYLINE    fbPolyline8
+#define POLYSEGMENT fbPolySegment8
+#define BITS       BYTE
+#define BITS2      CARD16
+#define BITS4      CARD32
+#include "fblinebits.h"
+#undef BITS
+#undef BITS2
+#undef BITS4
+#undef POLYSEGMENT
+#undef POLYLINE
+
+#define POLYLINE    fbPolyline16
+#define POLYSEGMENT fbPolySegment16
+#define BITS       CARD16
+#define BITS2      CARD32
+#include "fblinebits.h"
+#undef BITS
+#undef BITS2
+#undef POLYSEGMENT
+#undef POLYLINE
+
+#define POLYLINE    fbPolyline32
+#define POLYSEGMENT fbPolySegment32
+#define BITS       CARD32
+#include "fblinebits.h"
+#undef BITS
+#undef POLYSEGMENT
+#undef POLYLINE
+
+static void
+fbZeroLine(DrawablePtr drawable, GCPtr gc, int mode, int n, DDXPointPtr pt)
+{
+       int x1, y1, x2, y2;
+       int x, y;
+       int dashOffset;
+
+       x = drawable->x;
+       y = drawable->y;
+       x1 = pt->x;
+       y1 = pt->y;
+       dashOffset = gc->dashOffset;
+       while (--n) {
+               ++pt;
+               x2 = pt->x;
+               y2 = pt->y;
+               if (mode == CoordModePrevious) {
+                       x2 += x1;
+                       y2 += y1;
+               }
+               fbSegment(drawable, gc,
+                         x1 + x, y1 + y,
+                         x2 + x, y2 + y,
+                         n == 1 && gc->capStyle != CapNotLast, &dashOffset);
+               x1 = x2;
+               y1 = y2;
+       }
+}
+
+static void
+fbZeroSegment(DrawablePtr drawable, GCPtr gc, int n, xSegment *seg)
+{
+       int dashOffset;
+       int16_t x, y;
+       Bool drawLast = gc->capStyle != CapNotLast;
+
+       x = drawable->x;
+       y = drawable->y;
+       while (n--) {
+               dashOffset = gc->dashOffset;
+               fbSegment(drawable, gc,
+                         seg->x1 + x, seg->y1 + y,
+                         seg->x2 + x, seg->y2 + y,
+                         drawLast, &dashOffset);
+               seg++;
+       }
+}
+
+void
+fbFixCoordModePrevious(int n, DDXPointPtr pt)
+{
+       int16_t x = pt->x;
+       int16_t y = pt->y;
+       while (--n) {
+               pt++;
+               x = (pt->x += x);
+               y = (pt->y += y);
+       }
+}
+
+void
+fbPolyLine(DrawablePtr drawable, GCPtr gc, int mode, int n, DDXPointPtr pt)
+{
+       void (*raster)(DrawablePtr, GCPtr, int mode, int n, DDXPointPtr pt);
+
+       DBG(("%s x %d, width=%d, fill=%d, line=%d\n",
+            __FUNCTION__, n, gc->lineWidth, gc->fillStyle, gc->lineStyle));
+
+       if (gc->lineWidth == 0) {
+               raster = fbZeroLine;
+               if (gc->fillStyle == FillSolid && gc->lineStyle == LineSolid) {
+                       switch (drawable->bitsPerPixel) {
+                       case 8:
+                               raster = fbPolyline8;
+                               break;
+                       case 16:
+                               raster = fbPolyline16;
+                               break;
+                       case 32:
+                               raster = fbPolyline32;
+                               break;
+                       }
+               }
+       } else {
+               if (gc->lineStyle != LineSolid)
+                       raster = miWideDash;
+               else
+                       raster = miWideLine;
+       }
+       raster(drawable, gc, mode, n, pt);
+}
+
+void
+fbPolySegment(DrawablePtr drawable, GCPtr gc, int n, xSegment *seg)
+{
+       void (*raster)(DrawablePtr drawable, GCPtr gc, int n, xSegment * seg);
+
+       DBG(("%s x %d, width=%d, fill=%d, line=%d\n",
+            __FUNCTION__, n, gc->lineWidth, gc->fillStyle, gc->lineStyle));
+
+       if (gc->lineWidth == 0) {
+               raster = fbZeroSegment;
+               if (gc->fillStyle == FillSolid && gc->lineStyle == LineSolid) {
+                       switch (drawable->bitsPerPixel) {
+                       case 8:
+                               raster = fbPolySegment8;
+                               break;
+                       case 16:
+                               raster = fbPolySegment16;
+                               break;
+                       case 32:
+                               raster = fbPolySegment32;
+                               break;
+                       }
+               }
+       } else
+               raster = miPolySegment;
+
+       raster(drawable, gc, n, seg);
+}
diff --git a/src/sna/fb/fblinebits.h b/src/sna/fb/fblinebits.h
new file mode 100644 (file)
index 0000000..db315d8
--- /dev/null
@@ -0,0 +1,284 @@
+/*
+ * Copyright © 1998 Keith Packard
+ * Copyright © 2012 Intel Corporation
+ *
+ * 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 Keith Packard not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission.  Keith Packard makes no
+ * representations about the suitability of this software for any purpose.  It
+ * is provided "as is" without express or implied warranty.
+ *
+ * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL KEITH PACKARD 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.
+ */
+
+#define isClipped(c,ul,lr)  (((c) | ((c) - (ul)) | ((lr) - (c))) & 0x80008000)
+#define RROP(b,a,x)    WRITE((b), FbDoRRop (READ(b), (a), (x)))
+
+static void
+POLYLINE(DrawablePtr drawable, GCPtr gc, int mode, int n_0, DDXPointPtr pt_0)
+{
+       int xoff = drawable->x;
+       int yoff = drawable->y;
+       unsigned int bias = miGetZeroLineBias(drawable->pScreen);
+       const BoxRec *clip = RegionRects(gc->pCompositeClip);
+       const BoxRec *const last_clip = clip + RegionNumRects(gc->pCompositeClip);
+
+       FbBits *dst;
+       int dstStride;
+       int dstBpp;
+       int dstXoff, dstYoff;
+
+       BITS *bits, *bitsBase;
+       FbStride bitsStride;
+       BITS xor = fb_gc(gc)->xor;
+       BITS and = fb_gc(gc)->and;
+
+
+       int e, e1, e3, len;
+       int stepmajor, stepminor;
+       int octant;
+
+       if (mode == CoordModePrevious)
+               fbFixCoordModePrevious(n_0, pt_0);
+
+       fbGetDrawable(drawable, dst, dstStride, dstBpp, dstXoff, dstYoff);
+       bitsStride = dstStride * (sizeof(FbBits) / sizeof(BITS));
+       bitsBase =
+               ((BITS *) dst) + (yoff + dstYoff) * bitsStride + (xoff + dstXoff);
+       do {
+               INT32 *pt = (INT32 *)pt_0;
+               int n = n_0;
+               INT32 pt1, pt2;
+
+               INT32 ul = coordToInt(clip->x1 - xoff, clip->y1 - yoff);
+               INT32 lr = coordToInt(clip->x2 - xoff - 1, clip->y2 - yoff - 1);
+
+               pt1 = *pt++; n--;
+               pt2 = *pt++; n--;
+               for (;;) {
+                       if (isClipped(pt1, ul, lr) | isClipped(pt2, ul, lr)) {
+                               int dashoffset = 0;
+                               fbSegment1(drawable, gc, clip,
+                                         intToX(pt1) + xoff, intToY(pt1) + yoff,
+                                         intToX(pt2) + xoff, intToY(pt2) + yoff,
+                                         n == 0 && gc->capStyle != CapNotLast, &dashoffset);
+                               if (!n)
+                                       return;
+
+                               pt1 = pt2;
+                               pt2 = *pt++;
+                               n--;
+                       } else {
+                               bits = bitsBase + intToY(pt1) * bitsStride + intToX(pt1);
+                               for (;;) {
+                                       CalcLineDeltas(intToX(pt1), intToY(pt1),
+                                                      intToX(pt2), intToY(pt2),
+                                                      len, e1, stepmajor, stepminor, 1, bitsStride,
+                                                      octant);
+                                       if (len < e1) {
+                                               e3 = len;
+                                               len = e1;
+                                               e1 = e3;
+
+                                               e3 = stepminor;
+                                               stepminor = stepmajor;
+                                               stepmajor = e3;
+                                               SetYMajorOctant(octant);
+                                       }
+                                       e = -len;
+                                       e1 <<= 1;
+                                       e3 = e << 1;
+                                       FIXUP_ERROR(e, octant, bias);
+                                       if (and == 0) {
+                                               while (len--) {
+                                                       WRITE(bits, xor);
+                                                       bits += stepmajor;
+                                                       e += e1;
+                                                       if (e >= 0) {
+                                                               bits += stepminor;
+                                                               e += e3;
+                                                       }
+                                               }
+                                       } else {
+                                               while (len--) {
+                                                       RROP(bits, and, xor);
+                                                       bits += stepmajor;
+                                                       e += e1;
+                                                       if (e >= 0) {
+                                                               bits += stepminor;
+                                                               e += e3;
+                                                       }
+                                               }
+                                       }
+                                       if (!n) {
+                                               if (gc->capStyle != CapNotLast &&
+                                                   pt2 != *((INT32 *)pt_0)) {
+                                                       RROP(bits, and, xor);
+                                               }
+                                               return;
+                                       }
+                                       pt1 = pt2;
+                                       pt2 = *pt++;
+                                       --n;
+                                       if (isClipped(pt2, ul, lr))
+                                               break;
+                               }
+                       }
+               }
+       } while (++clip != last_clip);
+}
+
+static void
+POLYSEGMENT(DrawablePtr drawable, GCPtr gc, int n_0, xSegment *seg_0)
+{
+       int xoff = drawable->x;
+       int yoff = drawable->y;
+       unsigned int bias = miGetZeroLineBias(drawable->pScreen);
+       const BoxRec *clip = RegionRects(gc->pCompositeClip);
+       const BoxRec *const last_clip = clip + RegionNumRects(gc->pCompositeClip);
+
+       FbBits *dst;
+       int dstStride;
+       int dstBpp;
+       int dstXoff, dstYoff;
+
+       BITS *bits, *bitsBase;
+       FbStride bitsStride;
+       FbBits xor = fb_gc(gc)->xor;
+       FbBits and = fb_gc(gc)->and;
+
+       int e, e1, e3, len;
+       int stepmajor, stepminor;
+       int octant;
+       bool capNotLast = gc->capStyle == CapNotLast;
+
+       fbGetDrawable(drawable, dst, dstStride, dstBpp, dstXoff, dstYoff);
+       bitsStride = dstStride * (sizeof(FbBits) / sizeof(BITS));
+       bitsBase =
+               ((BITS *) dst) + (yoff + dstYoff) * bitsStride + (xoff + dstXoff);
+
+       do {
+               INT32 ul = coordToInt(clip->x1 - xoff, clip->y1 - yoff);
+               INT32 lr = coordToInt(clip->x2 - xoff - 1, clip->y2 - yoff - 1);
+               uint64_t *pt = (uint64_t *)seg_0;
+               int n = n_0;
+
+               while (n--) {
+                       union {
+                               int32_t pt32[2];
+                               uint64_t pt64;
+                       } u;
+
+                       u.pt64 = *pt++;
+                       if (isClipped(u.pt32[0], ul, lr) | isClipped(u.pt32[1], ul, lr)) {
+                               int dashoffset = 0;
+                               fbSegment1(drawable, gc, clip,
+                                         intToX(u.pt32[0]) + xoff, intToY(u.pt32[0]) + yoff,
+                                         intToX(u.pt32[1]) + xoff, intToY(u.pt32[1]) + yoff,
+                                         !capNotLast, &dashoffset);
+                       } else {
+                               CalcLineDeltas(intToX(u.pt32[0]), intToY(u.pt32[0]),
+                                              intToX(u.pt32[1]), intToY(u.pt32[1]),
+                                              len, e1, stepmajor, stepminor, 1, bitsStride,
+                                              octant);
+                               if (e1 == 0 && len > 3) {
+                                       int x1, x2;
+                                       FbBits *dstLine;
+                                       int dstX, width;
+                                       FbBits startmask, endmask;
+                                       int nmiddle;
+
+                                       if (stepmajor < 0) {
+                                               x1 = intToX(u.pt32[1]);
+                                               x2 = intToX(u.pt32[0]) + 1;
+                                               if (capNotLast)
+                                                       x1++;
+                                       } else {
+                                               x1 = intToX(u.pt32[0]);
+                                               x2 = intToX(u.pt32[1]);
+                                               if (!capNotLast)
+                                                       x2++;
+                                       }
+                                       dstX = (x1 + xoff + dstXoff) * (sizeof(BITS) * 8);
+                                       width = (x2 - x1) * (sizeof(BITS) * 8);
+
+                                       dstLine = dst + (intToY(u.pt32[0]) + yoff + dstYoff) * dstStride;
+                                       dstLine += dstX >> FB_SHIFT;
+                                       dstX &= FB_MASK;
+                                       FbMaskBits(dstX, width, startmask, nmiddle, endmask);
+                                       if (startmask) {
+                                               WRITE(dstLine,
+                                                     FbDoMaskRRop(READ(dstLine), and, xor,
+                                                                  startmask));
+                                               dstLine++;
+                                       }
+                                       if (!and)
+                                               while (nmiddle--)
+                                                       WRITE(dstLine++, xor);
+                                       else
+                                               while (nmiddle--) {
+                                                       WRITE(dstLine,
+                                                             FbDoRRop(READ(dstLine), and, xor));
+                                                       dstLine++;
+                                               }
+                                       if (endmask)
+                                               WRITE(dstLine,
+                                                     FbDoMaskRRop(READ(dstLine), and, xor,
+                                                                  endmask));
+                               } else {
+                                       bits = bitsBase + intToY(u.pt32[0]) * bitsStride + intToX(u.pt32[0]);
+                                       if (len < e1) {
+                                               e3 = len;
+                                               len = e1;
+                                               e1 = e3;
+
+                                               e3 = stepminor;
+                                               stepminor = stepmajor;
+                                               stepmajor = e3;
+                                               SetYMajorOctant(octant);
+                                       }
+                                       e = -len;
+                                       e1 <<= 1;
+                                       e3 = e << 1;
+                                       FIXUP_ERROR(e, octant, bias);
+                                       if (!capNotLast)
+                                               len++;
+                                       if (and == 0) {
+                                               while (len--) {
+                                                       WRITE(bits, xor);
+                                                       bits += stepmajor;
+                                                       e += e1;
+                                                       if (e >= 0) {
+                                                               bits += stepminor;
+                                                               e += e3;
+                                                       }
+                                               }
+                                       } else {
+                                               while (len--) {
+                                                       RROP(bits, and, xor);
+                                                       bits += stepmajor;
+                                                       e += e1;
+                                                       if (e >= 0) {
+                                                               bits += stepminor;
+                                                               e += e3;
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+               }
+       } while (++clip != last_clip);
+}
+
+#undef RROP
+#undef isClipped
diff --git a/src/sna/fb/fbpict.c b/src/sna/fb/fbpict.c
new file mode 100644 (file)
index 0000000..a203851
--- /dev/null
@@ -0,0 +1,354 @@
+/*
+ * Copyright © 2000 SuSE, Inc.
+ * Copyright © 2007 Red Hat, Inc.
+ * Copyright © 2012 Intel Corporation
+ *
+ * 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 SuSE not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  SuSE makes no representations about the
+ * suitability of this software for any purpose.  It is provided "as is"
+ * without express or implied warranty.
+ *
+ * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE
+ * 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.
+ *
+ * Author:  Keith Packard, SuSE, Inc.
+ */
+
+#include <string.h>
+
+#include "fb.h"
+
+#include <picturestr.h>
+#include <mipict.h>
+#include "fbpict.h"
+
+static void
+SourceValidateOnePicture(PicturePtr picture)
+{
+       DrawablePtr drawable = picture->pDrawable;
+       ScreenPtr screen;
+
+       if (!drawable)
+               return;
+
+       screen = drawable->pScreen;
+       if (screen->SourceValidate)
+               screen->SourceValidate(drawable,
+                                      0, 0, drawable->width, drawable->height,
+                                      picture->subWindowMode);
+}
+
+static void
+fbCompositeSourceValidate(PicturePtr picture)
+{
+       SourceValidateOnePicture(picture);
+       if (picture->alphaMap)
+               SourceValidateOnePicture(picture->alphaMap);
+}
+
+void
+fbComposite(CARD8 op,
+            PicturePtr pSrc,
+            PicturePtr pMask,
+            PicturePtr pDst,
+            INT16 xSrc,
+            INT16 ySrc,
+            INT16 xMask,
+            INT16 yMask, INT16 xDst, INT16 yDst, CARD16 width, CARD16 height)
+{
+       pixman_image_t *src, *mask, *dest;
+       int src_xoff, src_yoff;
+       int msk_xoff, msk_yoff;
+       int dst_xoff, dst_yoff;
+
+       fbCompositeSourceValidate(pSrc);
+       if (pMask)
+               fbCompositeSourceValidate(pMask);
+
+       src = image_from_pict(pSrc, FALSE, &src_xoff, &src_yoff);
+       mask = image_from_pict(pMask, FALSE, &msk_xoff, &msk_yoff);
+       dest = image_from_pict(pDst, TRUE, &dst_xoff, &dst_yoff);
+
+       if (src && dest && !(pMask && !mask)) {
+               pixman_image_composite(op, src, mask, dest,
+                                      xSrc + src_xoff, ySrc + src_yoff,
+                                      xMask + msk_xoff, yMask + msk_yoff,
+                                      xDst + dst_xoff, yDst + dst_yoff, width, height);
+       }
+
+       free_pixman_pict(pSrc, src);
+       free_pixman_pict(pMask, mask);
+       free_pixman_pict(pDst, dest);
+}
+
+static pixman_image_t *
+create_solid_fill_image(PicturePtr pict)
+{
+       PictSolidFill *solid = &pict->pSourcePict->solidFill;
+       pixman_color_t color;
+       CARD32 a, r, g, b;
+
+       a = (solid->color & 0xff000000) >> 24;
+       r = (solid->color & 0x00ff0000) >> 16;
+       g = (solid->color & 0x0000ff00) >> 8;
+       b = (solid->color & 0x000000ff) >> 0;
+
+       color.alpha = (a << 8) | a;
+       color.red = (r << 8) | r;
+       color.green = (g << 8) | g;
+       color.blue = (b << 8) | b;
+
+       return pixman_image_create_solid_fill(&color);
+}
+
+static pixman_image_t *
+create_linear_gradient_image(PictGradient * gradient)
+{
+       PictLinearGradient *linear = (PictLinearGradient *) gradient;
+       pixman_point_fixed_t p1;
+       pixman_point_fixed_t p2;
+
+       p1.x = linear->p1.x;
+       p1.y = linear->p1.y;
+       p2.x = linear->p2.x;
+       p2.y = linear->p2.y;
+
+       return pixman_image_create_linear_gradient(&p1, &p2,
+                                                  (pixman_gradient_stop_t *)
+                                                  gradient->stops,
+                                                  gradient->nstops);
+}
+
+static pixman_image_t *
+create_radial_gradient_image(PictGradient * gradient)
+{
+       PictRadialGradient *radial = (PictRadialGradient *) gradient;
+       pixman_point_fixed_t c1;
+       pixman_point_fixed_t c2;
+
+       c1.x = radial->c1.x;
+       c1.y = radial->c1.y;
+       c2.x = radial->c2.x;
+       c2.y = radial->c2.y;
+
+       return pixman_image_create_radial_gradient(&c1, &c2, radial->c1.radius,
+                                                  radial->c2.radius,
+                                                  (pixman_gradient_stop_t *)
+                                                  gradient->stops,
+                                                  gradient->nstops);
+}
+
+static pixman_image_t *
+create_conical_gradient_image(PictGradient * gradient)
+{
+       PictConicalGradient *conical = (PictConicalGradient *) gradient;
+       pixman_point_fixed_t center;
+
+       center.x = conical->center.x;
+       center.y = conical->center.y;
+
+       return pixman_image_create_conical_gradient(&center, conical->angle,
+                                                   (pixman_gradient_stop_t *)
+                                                   gradient->stops,
+                                                   gradient->nstops);
+}
+
+static pixman_image_t *
+create_bits_picture(PicturePtr pict, Bool has_clip, int *xoff, int *yoff)
+{
+       PixmapPtr pixmap;
+       FbBits *bits;
+       FbStride stride;
+       int bpp;
+       pixman_image_t *image;
+
+       fbGetDrawablePixmap(pict->pDrawable, pixmap, *xoff, *yoff);
+       fbGetPixmapBitsData(pixmap, bits, stride, bpp);
+
+       image = pixman_image_create_bits((pixman_format_code_t) pict->format,
+                                        pixmap->drawable.width,
+                                        pixmap->drawable.height, (uint32_t *) bits,
+                                        stride * sizeof(FbStride));
+
+       if (!image)
+               return NULL;
+
+       /* pCompositeClip is undefined for source pictures, so
+        * only set the clip region for pictures with drawables
+        */
+       if (has_clip) {
+               if (pict->clientClipType != CT_NONE)
+                       pixman_image_set_has_client_clip(image, TRUE);
+
+               if (*xoff || *yoff)
+                       pixman_region_translate(pict->pCompositeClip, *xoff, *yoff);
+
+               pixman_image_set_clip_region(image, pict->pCompositeClip);
+
+               if (*xoff || *yoff)
+                       pixman_region_translate(pict->pCompositeClip, -*xoff, -*yoff);
+       }
+
+       /* Indexed table */
+       if (pict->pFormat->index.devPrivate)
+               pixman_image_set_indexed(image, pict->pFormat->index.devPrivate);
+
+       /* Add in drawable origin to position within the image */
+       *xoff += pict->pDrawable->x;
+       *yoff += pict->pDrawable->y;
+
+       return image;
+}
+
+static pixman_image_t *image_from_pict_internal(PicturePtr pict, Bool has_clip,
+                                                int *xoff, int *yoff,
+                                                Bool is_alpha_map);
+
+static void
+set_image_properties(pixman_image_t * image, PicturePtr pict, Bool has_clip,
+                     int *xoff, int *yoff, Bool is_alpha_map)
+{
+       pixman_repeat_t repeat;
+       pixman_filter_t filter;
+
+       if (pict->transform) {
+               /* For source images, adjust the transform to account
+                * for the drawable offset within the pixman image,
+                * then set the offset to 0 as it will be used
+                * to compute positions within the transformed image.
+                */
+               if (!has_clip) {
+                       struct pixman_transform adjusted;
+
+                       adjusted = *pict->transform;
+                       pixman_transform_translate(&adjusted,
+                                                  NULL,
+                                                  pixman_int_to_fixed(*xoff),
+                                                  pixman_int_to_fixed(*yoff));
+                       pixman_image_set_transform(image, &adjusted);
+                       *xoff = 0;
+                       *yoff = 0;
+               }
+               else
+                       pixman_image_set_transform(image, pict->transform);
+       }
+
+       switch (pict->repeatType) {
+       default:
+       case RepeatNone:
+               repeat = PIXMAN_REPEAT_NONE;
+               break;
+
+       case RepeatPad:
+               repeat = PIXMAN_REPEAT_PAD;
+               break;
+
+       case RepeatNormal:
+               repeat = PIXMAN_REPEAT_NORMAL;
+               break;
+
+       case RepeatReflect:
+               repeat = PIXMAN_REPEAT_REFLECT;
+               break;
+       }
+
+       pixman_image_set_repeat(image, repeat);
+
+       /* Fetch alpha map unless 'pict' is being used
+        * as the alpha map for this operation
+        */
+       if (pict->alphaMap && !is_alpha_map) {
+               int alpha_xoff, alpha_yoff;
+               pixman_image_t *alpha_map =
+                       image_from_pict_internal(pict->alphaMap, FALSE, &alpha_xoff,
+                                                &alpha_yoff, TRUE);
+
+               pixman_image_set_alpha_map(image, alpha_map, pict->alphaOrigin.x,
+                                          pict->alphaOrigin.y);
+
+               free_pixman_pict(pict->alphaMap, alpha_map);
+       }
+
+       pixman_image_set_component_alpha(image, pict->componentAlpha);
+
+       switch (pict->filter) {
+       default:
+       case PictFilterNearest:
+       case PictFilterFast:
+               filter = PIXMAN_FILTER_NEAREST;
+               break;
+
+       case PictFilterBilinear:
+       case PictFilterGood:
+               filter = PIXMAN_FILTER_BILINEAR;
+               break;
+
+       case PictFilterConvolution:
+               filter = PIXMAN_FILTER_CONVOLUTION;
+               break;
+       }
+
+       pixman_image_set_filter(image, filter,
+                               (pixman_fixed_t *) pict->filter_params,
+                               pict->filter_nparams);
+       pixman_image_set_source_clipping(image, TRUE);
+}
+
+static pixman_image_t *
+image_from_pict_internal(PicturePtr pict, Bool has_clip, int *xoff, int *yoff,
+                         Bool is_alpha_map)
+{
+       pixman_image_t *image = NULL;
+
+       if (!pict)
+               return NULL;
+
+       if (pict->pDrawable) {
+               image = create_bits_picture(pict, has_clip, xoff, yoff);
+       }
+       else if (pict->pSourcePict) {
+               SourcePict *sp = pict->pSourcePict;
+
+               if (sp->type == SourcePictTypeSolidFill) {
+                       image = create_solid_fill_image(pict);
+               }
+               else {
+                       PictGradient *gradient = &pict->pSourcePict->gradient;
+
+                       if (sp->type == SourcePictTypeLinear)
+                               image = create_linear_gradient_image(gradient);
+                       else if (sp->type == SourcePictTypeRadial)
+                               image = create_radial_gradient_image(gradient);
+                       else if (sp->type == SourcePictTypeConical)
+                               image = create_conical_gradient_image(gradient);
+               }
+               *xoff = *yoff = 0;
+       }
+
+       if (image)
+               set_image_properties(image, pict, has_clip, xoff, yoff, is_alpha_map);
+
+       return image;
+}
+
+pixman_image_t *
+image_from_pict(PicturePtr pict, Bool has_clip, int *xoff, int *yoff)
+{
+       return image_from_pict_internal(pict, has_clip, xoff, yoff, FALSE);
+}
+
+void
+free_pixman_pict(PicturePtr pict, pixman_image_t * image)
+{
+       if (image)
+                pixman_image_unref(image);
+}
diff --git a/src/sna/fb/fbpict.h b/src/sna/fb/fbpict.h
new file mode 100644 (file)
index 0000000..1ce09df
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
+ * Copyright © 2012 Intel Corporation
+ *
+ * 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 Keith Packard not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission.  Keith Packard makes no
+ * representations about the suitability of this software for any purpose.  It
+ * is provided "as is" without express or implied warranty.
+ *
+ * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL KEITH PACKARD 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.
+ */
+
+#ifndef FBPICT_H
+#define FBPICT_H
+
+#include "sfb.h"
+
+extern void
+fbComposite(CARD8 op,
+            PicturePtr pSrc,
+            PicturePtr pMask,
+            PicturePtr pDst,
+            INT16 xSrc,
+            INT16 ySrc,
+            INT16 xMask,
+            INT16 yMask, INT16 xDst, INT16 yDst, CARD16 width, CARD16 height);
+
+extern pixman_image_t *image_from_pict(PicturePtr pict,
+                                      Bool has_clip,
+                                      int *xoff, int *yoff);
+
+extern void free_pixman_pict(PicturePtr, pixman_image_t *);
+
+#endif  /* FBPICT_H */
diff --git a/src/sna/fb/fbpoint.c b/src/sna/fb/fbpoint.c
new file mode 100644 (file)
index 0000000..3df79a2
--- /dev/null
@@ -0,0 +1,134 @@
+/*
+ * Copyright © 1998 Keith Packard
+ * Copyright © 2012 Intel Corporation
+ *
+ * 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 Keith Packard not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission.  Keith Packard makes no
+ * representations about the suitability of this software for any purpose.  It
+ * is provided "as is" without express or implied warranty.
+ *
+ * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL KEITH PACKARD 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 "fb.h"
+#include <micoord.h>
+
+#define DOTS       fbDots8
+#define DOTS__SIMPLE fbDots8__simple
+#define BITS       BYTE
+#include "fbpointbits.h"
+#undef BITS
+#undef DOTS__SIMPLE
+#undef DOTS
+
+#define DOTS       fbDots16
+#define DOTS__SIMPLE fbDots16__simple
+#define BITS       CARD16
+#include "fbpointbits.h"
+#undef BITS
+#undef DOTS__SIMPLE
+#undef DOTS
+
+#define DOTS       fbDots32
+#define DOTS__SIMPLE fbDots32__simple
+#define BITS       CARD32
+#include "fbpointbits.h"
+#undef BITS
+#undef DOTS__SIMPLE
+#undef DOTS
+
+static void
+fbDots(FbBits *dstOrig, FbStride dstStride, int dstBpp,
+       RegionPtr clip,
+       xPoint *pts, int n,
+       int xorg, int yorg,
+       int xoff, int yoff,
+       FbBits andOrig, FbBits xorOrig)
+{
+       FbStip *dst = (FbStip *) dstOrig;
+       FbStip and = andOrig;
+       FbStip xor = xorOrig;
+
+       while (n--) {
+               int x = pts->x + xorg;
+               int y = pts->y + yorg;
+               pts++;
+               if (RegionContainsPoint(clip, x, y, NULL)) {
+                       FbStip mask;
+                       FbStip *d;
+
+                       x = (x + xoff) * dstBpp;
+                       d = dst + ((y + yoff) * dstStride) + (x >> FB_STIP_SHIFT);
+                       x &= FB_STIP_MASK;
+
+                       mask = FbStipMask(x, dstBpp);
+                       WRITE(d, FbDoMaskRRop(READ(d), and, xor, mask));
+               }
+       }
+}
+
+void
+fbPolyPoint(DrawablePtr drawable, GCPtr gc,
+           int mode, int n, xPoint *pt, unsigned flags)
+{
+       FbBits *dst;
+       FbStride dstStride;
+       int dstBpp;
+       int dstXoff, dstYoff;
+       void (*dots)(FbBits *dst, FbStride dstStride, int dstBpp,
+                    RegionPtr clip,
+                    xPoint *pts, int n,
+                    int xorg, int yorg,
+                    int xoff, int yoff,
+                    FbBits and, FbBits xor);
+
+       DBG(("%s x %d, clip=[(%d, %d), (%d, %d)]x%d\n", __FUNCTION__, n,
+            gc->pCompositeClip->extents.x1, gc->pCompositeClip->extents.y1,
+            gc->pCompositeClip->extents.x2, gc->pCompositeClip->extents.y2,
+            RegionNumRects(gc->pCompositeClip)));
+
+       if (mode == CoordModePrevious)
+               fbFixCoordModePrevious(n, pt);
+
+       fbGetDrawable(drawable, dst, dstStride, dstBpp, dstXoff, dstYoff);
+       dots = fbDots;
+       if ((flags & 2) == 0 && fb_gc(gc)->and == 0) {
+               switch (dstBpp) {
+               case 8:
+                       dots = fbDots8__simple;
+                       break;
+               case 16:
+                       dots = fbDots16__simple;
+                       break;
+               case 32:
+                       dots = fbDots32__simple;
+                       break;
+               }
+       } else {
+               switch (dstBpp) {
+               case 8:
+                       dots = fbDots8;
+                       break;
+               case 16:
+                       dots = fbDots16;
+                       break;
+               case 32:
+                       dots = fbDots32;
+                       break;
+               }
+       }
+       dots(dst, dstStride, dstBpp, gc->pCompositeClip, pt, n,
+            drawable->x, drawable->y, dstXoff, dstYoff,
+            fb_gc(gc)->and, fb_gc(gc)->xor);
+}
diff --git a/src/sna/fb/fbpointbits.h b/src/sna/fb/fbpointbits.h
new file mode 100644 (file)
index 0000000..60bf488
--- /dev/null
@@ -0,0 +1,148 @@
+/*
+ * Copyright © 1998 Keith Packard
+ * Copyright © 2012 Intel Corporation
+ *
+ * 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 Keith Packard not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission.  Keith Packard makes no
+ * representations about the suitability of this software for any purpose.  It
+ * is provided "as is" without express or implied warranty.
+ *
+ * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL KEITH PACKARD 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.
+ */
+
+#define RROP(b,a,x) WRITE((b), FbDoRRop (READ(b), (a), (x)))
+#define isClipped(c,ul,lr)  (((c) | ((c) - (ul)) | ((lr) - (c))) & 0x80008000)
+
+static void
+DOTS(FbBits * dst,
+     FbStride dstStride,
+     int dstBpp,
+     RegionPtr region,
+     xPoint * ptsOrig,
+     int npt, int xorg, int yorg, int xoff, int yoff, FbBits and, FbBits xor)
+{
+       uint32_t *pts = (uint32_t *) ptsOrig;
+       BITS *bits = (BITS *) dst;
+       BITS bxor = (BITS) xor;
+       BITS band = (BITS) and;
+       FbStride bitsStride = dstStride * (sizeof(FbBits) / sizeof(BITS));
+
+       if (region->data == NULL) {
+               INT32 ul = coordToInt(region->extents.x1 - xorg,
+                                     region->extents.y1 - yorg);
+               INT32 lr = coordToInt(region->extents.x2 - xorg - 1,
+                                     region->extents.y2 - yorg - 1);
+
+               bits += bitsStride * (yorg + yoff) + (xorg + xoff);
+               if (and == 0) {
+                       while (npt >= 2) {
+                               union {
+                                       uint32_t pt32[2];
+                                       uint64_t pt64;
+                               } pt;
+                               pt.pt64 = *(uint64_t *)pts;
+                               if (!isClipped(pt.pt32[0], ul, lr)) {
+                                       BITS *point = bits + intToY(pt.pt32[0]) * bitsStride + intToX(pt.pt32[0]);
+                                       WRITE(point, bxor);
+                               }
+                               if (!isClipped(pt.pt32[1], ul, lr)) {
+                                       BITS *point = bits + intToY(pt.pt32[1]) * bitsStride + intToX(pt.pt32[1]);
+                                       WRITE(point, bxor);
+                               }
+
+                               pts += 2;
+                               npt -= 2;
+                       }
+                       if (npt) {
+                               uint32_t pt = *pts;
+                               if (!isClipped(pt, ul, lr)) {
+                                       BITS *point = bits + intToY(pt) * bitsStride + intToX(pt);
+                                       WRITE(point, bxor);
+                               }
+                       }
+               } else {
+                       while (npt--) {
+                               uint32_t pt = *pts++;
+                               if (!isClipped(pt, ul, lr)) {
+                                       BITS *point = bits + intToY(pt) * bitsStride + intToX(pt);
+                                       RROP(point, band, bxor);
+                               }
+                       }
+               }
+       } else {
+               bits += bitsStride * yoff + xoff;
+               if (and == 0) {
+                       while (npt--) {
+                               uint32_t pt = *pts++;
+                               int x = intToX(pt) + xorg;
+                               int y = intToY(pt) + yorg;
+                               if (RegionContainsPoint(region, x, y, NULL)) {
+                                       BITS *point = bits + y * bitsStride + x;
+                                       WRITE(point, bxor);
+                               }
+                       }
+               } else {
+                       while (npt--) {
+                               uint32_t pt = *pts++;
+                               int x = intToX(pt) + xorg;
+                               int y = intToY(pt) + yorg;
+                               if (RegionContainsPoint(region, x, y, NULL)) {
+                                       BITS *point = bits + y * bitsStride + x;
+                                       RROP(point, band, bxor);
+                               }
+                       }
+               }
+       }
+}
+
+static void
+DOTS__SIMPLE(FbBits * dst,
+            FbStride dstStride,
+            int dstBpp,
+            RegionPtr region,
+            xPoint * ptsOrig,
+            int npt, int xorg, int yorg, int xoff, int yoff,
+            FbBits and, FbBits xor)
+{
+       uint32_t *pts = (uint32_t *) ptsOrig;
+       BITS *bits = (BITS *) dst, *p;
+       BITS bxor = (BITS) xor;
+       FbStride bitsStride = dstStride * (sizeof(FbBits) / sizeof(BITS));
+
+       bits += bitsStride * (yorg + yoff) + (xorg + xoff);
+       while (npt >= 2) {
+               union {
+                       uint32_t pt32[2];
+                       uint64_t pt64;
+               } pt;
+               pt.pt64 = *(uint64_t *)pts;
+
+               p = bits + intToY(pt.pt32[0]) * bitsStride + intToX(pt.pt32[0]);
+               WRITE(p, bxor);
+
+               p = bits + intToY(pt.pt32[1]) * bitsStride + intToX(pt.pt32[1]);
+               WRITE(p, bxor);
+
+               pts += 2;
+               npt -= 2;
+       }
+       if (npt) {
+               uint32_t pt = *pts;
+               p = bits + intToY(pt) * bitsStride + intToX(pt);
+               WRITE(p, bxor);
+       }
+}
+
+#undef RROP
+#undef isClipped
diff --git a/src/sna/fb/fbpush.c b/src/sna/fb/fbpush.c
new file mode 100644 (file)
index 0000000..c53f0ad
--- /dev/null
@@ -0,0 +1,177 @@
+/*
+ * Copyright © 1998 Keith Packard
+ * Copyright © 2012 Intel Corporation
+ *
+ * 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 Keith Packard not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission.  Keith Packard makes no
+ * representations about the suitability of this software for any purpose.  It
+ * is provided "as is" without express or implied warranty.
+ *
+ * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL KEITH PACKARD 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 "fb.h"
+#include "fbclip.h"
+
+static void
+fbPushPattern(DrawablePtr drawable, GCPtr gc,
+              FbStip *src, FbStride srcStride, int srcX,
+             int x, int y, int width, int height)
+{
+       FbStip *s, bitsMask, bitsMask0, bits;
+       int xspan;
+       int w;
+       int lenspan;
+
+       src += srcX >> FB_STIP_SHIFT;
+       srcX &= FB_STIP_MASK;
+
+       bitsMask0 = FbStipMask(srcX, 1);
+
+       while (height--) {
+               bitsMask = bitsMask0;
+               w = width;
+               s = src;
+               src += srcStride;
+               bits = READ(s++);
+               xspan = x;
+               while (w) {
+                       if (bits & bitsMask) {
+                               lenspan = 0;
+                               do {
+                                       if (++lenspan == w)
+                                               break;
+
+                                       bitsMask = FbStipRight(bitsMask, 1);
+                                       if (!bitsMask) {
+                                               bits = READ(s++);
+                                               bitsMask = FbBitsMask(0, 1);
+                                       }
+                               } while (bits & bitsMask);
+                               fbFill(drawable, gc, xspan, y, lenspan, 1);
+                               xspan += lenspan;
+                               w -= lenspan;
+                       } else {
+                               do {
+                                       xspan++;
+                                       if (!--w)
+                                               break;
+
+                                       bitsMask = FbStipRight(bitsMask, 1);
+                                       if (!bitsMask) {
+                                               bits = READ(s++);
+                                               bitsMask = FbBitsMask(0, 1);
+                                       }
+                               } while (!(bits & bitsMask));
+                       }
+               }
+               y++;
+       }
+}
+
+static void
+fbPushFill(DrawablePtr drawable, GCPtr gc,
+           FbStip *src, FbStride srcStride, int srcX,
+          int x, int y, int width, int height)
+{
+       FbGCPrivPtr pgc = fb_gc(gc);
+
+       if (gc->fillStyle == FillSolid) {
+               FbBits *dst;
+               FbStride dstStride;
+               int dstBpp;
+               int dstXoff, dstYoff;
+               int dstX;
+               int dstWidth;
+
+               fbGetDrawable(drawable, dst,
+                             dstStride, dstBpp, dstXoff, dstYoff);
+               dst = dst + (y + dstYoff) * dstStride;
+               dstX = (x + dstXoff) * dstBpp;
+               dstWidth = width * dstBpp;
+               if (dstBpp == 1) {
+                       fbBltStip(src, srcStride, srcX,
+                                 (FbStip *)dst, dstStride, dstX,
+                                 dstWidth, height,
+                                 FbStipple1Rop(gc->alu, gc->fgPixel), pgc->pm, dstBpp);
+               } else {
+                       fbBltOne(src, srcStride, srcX,
+                                dst, dstStride, dstX, dstBpp,
+                                dstWidth, height,
+                                pgc->and, pgc->xor,
+                                fbAnd(GXnoop, (FbBits) 0, FB_ALLONES),
+                                fbXor(GXnoop, (FbBits) 0, FB_ALLONES));
+               }
+       } else
+               fbPushPattern(drawable, gc, src, srcStride, srcX,
+                             x, y, width, height);
+}
+
+struct fbPushImage {
+       FbStip *src;
+       FbStride stride;
+       int x0, y0;
+};
+
+inline static void
+_fbPushImage(DrawablePtr drawable, GCPtr gc, const BoxRec *b, void *_data)
+{
+       struct fbPushImage *data = _data;
+
+       fbPushFill(drawable, gc,
+                  data->src + (b->y1 - data->y0) * data->stride, data->stride,
+                  b->x1 - data->x0,
+                  b->x1, b->y1,
+                  b->x2 - b->x1, b->y2 - b->y1);
+}
+
+void
+fbPushImage(DrawablePtr drawable, GCPtr gc,
+            FbStip *src, FbStride stride, int dx,
+           int x, int y, int width, int height)
+{
+       struct fbPushImage data;
+       BoxRec box;
+
+       DBG(("%s (%d, %d)x(%d, %d)", __FUNCTION__, x, y, width, height));
+
+       data.src = src;
+       data.stride = stride;
+       data.y0 = y;
+       data.x0 = x - dx;
+
+       box.x1 = x;
+       box.y1 = y;
+       box.x2 = x + width;
+       box.y2 = y + height;
+       fbDrawableRun(drawable, gc, &box, _fbPushImage, &data);
+}
+
+void
+fbPushPixels(GCPtr gc, PixmapPtr bitmap, DrawablePtr drawable,
+            int dx, int dy, int xOrg, int yOrg)
+{
+       FbStip *stip;
+       FbStride stipStride;
+       int stipBpp;
+       _X_UNUSED int stipXoff, stipYoff;
+
+       DBG(("%s bitmap=%x%d\n", __FUNCTION__,
+            bitmap->drawable.width, bitmap->drawable.height));
+
+       fbGetStipDrawable(&bitmap->drawable, stip,
+                         stipStride, stipBpp, stipXoff, stipYoff);
+
+       fbPushImage(drawable, gc, stip, stipStride, 0, xOrg, yOrg, dx, dy);
+}
diff --git a/src/sna/fb/fbrop.h b/src/sna/fb/fbrop.h
new file mode 100644 (file)
index 0000000..9eb1fc3
--- /dev/null
@@ -0,0 +1,111 @@
+/*
+ * Copyright © 1998 Keith Packard
+ * Copyright © 2012 Intel Corporation
+ *
+ * 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 Keith Packard not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission.  Keith Packard makes no
+ * representations about the suitability of this software for any purpose.  It
+ * is provided "as is" without express or implied warranty.
+ *
+ * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL KEITH PACKARD 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.
+ */
+
+#ifndef _FBROP_H_
+#define _FBROP_H_
+
+#define FbDestInvarientRop(alu,pm)  ((pm) == FB_ALLONES && \
+                                    (((alu) >> 1 & 5) == ((alu) & 5)))
+
+#define FbDestInvarientMergeRop()   (_ca1 == 0 && _cx1 == 0)
+
+/* AND has higher precedence than XOR */
+
+#define FbDoMergeRop(src, dst) \
+    (((dst) & (((src) & _ca1) ^ _cx1)) ^ (((src) & _ca2) ^ _cx2))
+
+#define FbDoDestInvarientMergeRop(src) (((src) & _ca2) ^ _cx2)
+
+#define FbDoMaskMergeRop(src, dst, mask) \
+    (((dst) & ((((src) & _ca1) ^ _cx1) | ~(mask))) ^ ((((src) & _ca2) ^ _cx2) & (mask)))
+
+#define FbDoLeftMaskByteMergeRop(dst, src, lb, l) { \
+    FbBits  __xor = ((src) & _ca2) ^ _cx2; \
+    FbDoLeftMaskByteRRop(dst,lb,l,((src) & _ca1) ^ _cx1,__xor); \
+}
+
+#define FbDoRightMaskByteMergeRop(dst, src, rb, r) { \
+    FbBits  __xor = ((src) & _ca2) ^ _cx2; \
+    FbDoRightMaskByteRRop(dst,rb,r,((src) & _ca1) ^ _cx1,__xor); \
+}
+
+#define FbDoRRop(dst, and, xor)        (((dst) & (and)) ^ (xor))
+
+#define FbDoMaskRRop(dst, and, xor, mask) \
+    (((dst) & ((and) | ~(mask))) ^ (xor & mask))
+
+/*
+ * Take a single bit (0 or 1) and generate a full mask
+ */
+#define fbFillFromBit(b,t)     (~((t) ((b) & 1)-1))
+
+#define fbXorT(rop,fg,pm,t) ((((fg) & fbFillFromBit((rop) >> 1,t)) | \
+                             (~(fg) & fbFillFromBit((rop) >> 3,t))) & (pm))
+
+#define fbAndT(rop,fg,pm,t) ((((fg) & fbFillFromBit (rop ^ (rop>>1),t)) | \
+                             (~(fg) & fbFillFromBit((rop>>2) ^ (rop>>3),t))) | \
+                            ~(pm))
+
+#define fbXor(rop,fg,pm)       fbXorT(rop,fg,pm,FbBits)
+
+#define fbAnd(rop,fg,pm)       fbAndT(rop,fg,pm,FbBits)
+
+#define fbXorStip(rop,fg,pm)    fbXorT(rop,fg,pm,FbStip)
+
+#define fbAndStip(rop,fg,pm)   fbAndT(rop,fg,pm,FbStip)
+
+/*
+ * Stippling operations; 
+ */
+extern const FbBits *const fbStippleTable[];
+
+#define FbStippleRRop(dst, b, fa, fx, ba, bx) \
+    (FbDoRRop(dst, fa, fx) & b) | (FbDoRRop(dst, ba, bx) & ~b)
+
+#define FbStippleRRopMask(dst, b, fa, fx, ba, bx, m) \
+    (FbDoMaskRRop(dst, fa, fx, m) & (b)) | (FbDoMaskRRop(dst, ba, bx, m) & ~(b))
+
+#define FbDoLeftMaskByteStippleRRop(dst, b, fa, fx, ba, bx, lb, l) { \
+    FbBits  __xor = ((fx) & (b)) | ((bx) & ~(b)); \
+    FbDoLeftMaskByteRRop(dst, lb, l, ((fa) & (b)) | ((ba) & ~(b)), __xor); \
+}
+
+#define FbDoRightMaskByteStippleRRop(dst, b, fa, fx, ba, bx, rb, r) { \
+    FbBits  __xor = ((fx) & (b)) | ((bx) & ~(b)); \
+    FbDoRightMaskByteRRop(dst, rb, r, ((fa) & (b)) | ((ba) & ~(b)), __xor); \
+}
+
+#define FbOpaqueStipple(b, fg, bg) (((fg) & (b)) | ((bg) & ~(b)))
+
+/*
+ * Compute rop for using tile code for 1-bit dest stipples; modifies
+ * existing rop to flip depending on pixel values
+ */
+#define FbStipple1RopPick(alu,b)    (((alu) >> (2 - (((b) & 1) << 1))) & 3)
+
+#define FbOpaqueStipple1Rop(alu,fg,bg)    (FbStipple1RopPick(alu,fg) | \
+                                          (FbStipple1RopPick(alu,bg) << 2))
+
+#define FbStipple1Rop(alu,fg)      (FbStipple1RopPick(alu,fg) | 4)
+
+#endif
diff --git a/src/sna/fb/fbseg.c b/src/sna/fb/fbseg.c
new file mode 100644 (file)
index 0000000..5b8173f
--- /dev/null
@@ -0,0 +1,563 @@
+/*
+ * Copyright © 1998 Keith Packard
+ * Copyright © 2012 Intel Corporation
+ *
+ * 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 Keith Packard not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission.  Keith Packard makes no
+ * representations about the suitability of this software for any purpose.  It
+ * is provided "as is" without express or implied warranty.
+ *
+ * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL KEITH PACKARD 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 <stdlib.h>
+
+#include "fb.h"
+#include "fbclip.h"
+#include <mi.h>
+#include <miline.h>
+#include <scrnintstr.h>
+
+#define FbDashDeclare  \
+    unsigned char      *__dash, *__firstDash, *__lastDash
+
+#define FbDashInit(gc,pgc,dashOffset,dashlen,even) {       \
+    (even) = TRUE;                                         \
+    __firstDash = (gc)->dash;                              \
+    __lastDash = __firstDash + (gc)->numInDashList;        \
+    (dashOffset) %= (pgc)->dashLength;             \
+                                                           \
+    __dash = __firstDash;                                  \
+    while ((dashOffset) >= ((dashlen) = *__dash)) {        \
+       (dashOffset) -= (dashlen);                          \
+       (even) = 1-(even);                                  \
+       if (++__dash == __lastDash)                         \
+           __dash = __firstDash;                           \
+    }                                                      \
+    (dashlen) -= (dashOffset);                             \
+}
+
+#define FbDashNext(dashlen) {                              \
+    if (++__dash == __lastDash)                                    \
+       __dash = __firstDash;                               \
+    (dashlen) = *__dash;                                   \
+}
+
+/* as numInDashList is always even, this case can skip a test */
+
+#define FbDashNextEven(dashlen) {                          \
+    (dashlen) = *++__dash;                                 \
+}
+
+#define FbDashNextOdd(dashlen) FbDashNext(dashlen)
+
+#define FbDashStep(dashlen,even) {                         \
+    if (!--(dashlen)) {                                            \
+       FbDashNext(dashlen);                                \
+       (even) = 1-(even);                                  \
+    }                                                      \
+}
+
+#define fbBresShiftMask(mask,dir,bpp) ((bpp == FB_STIP_UNIT) ? 0 : \
+                                       ((dir < 0) ? FbStipLeft(mask,bpp) : \
+                                        FbStipRight(mask,bpp)))
+
+typedef void FbBres(DrawablePtr drawable,
+                    GCPtr gc,
+                    int dashOffset,
+                    int sdx,
+                    int sdy,
+                    int axis, int x, int y, int e, int e1, int e3, int len);
+
+#define BRESSOLID   fbBresSolid8
+#define BRESSOLIDR  fbBresSolidR8
+#define BRESDASH    fbBresDash8
+#define BITS       BYTE
+#define BITS2      CARD16
+#define BITS4      CARD32
+#include "fbsegbits.h"
+#undef BRESSOLID
+#undef BRESSOLIDR
+#undef BRESDASH
+#undef BITS
+#undef BITS2
+#undef BITS4
+
+#define BRESSOLID   fbBresSolid16
+#define BRESSOLIDR  fbBresSolidR16
+#define BRESDASH    fbBresDash16
+#define BITS       CARD16
+#define BITS2      CARD32
+#include "fbsegbits.h"
+#undef BRESSOLID
+#undef BRESSOLIDR
+#undef BRESDASH
+#undef BITS
+#undef BITS2
+
+#define BRESSOLID   fbBresSolid32
+#define BRESSOLIDR  fbBresSolidR32
+#define BRESDASH    fbBresDash32
+#define BITS       CARD32
+#include "fbsegbits.h"
+#undef BRESSOLID
+#undef BRESSOLIDR
+#undef BRESDASH
+#undef BITS
+
+static void
+fbBresSolid(DrawablePtr drawable, GCPtr gc, int dashOffset,
+            int sdx, int sdy, int axis,
+           int x1, int y1,
+           int e, int e1, int e3, int len)
+{
+       FbStip *dst;
+       FbStride stride;
+       int bpp;
+       int dx, dy;
+       FbGCPrivPtr pgc = fb_gc(gc);
+       FbStip and = (FbStip) pgc->and;
+       FbStip xor = (FbStip) pgc->xor;
+       FbStip mask, mask0;
+       FbStip bits;
+
+       fbGetStipDrawable(drawable, dst, stride, bpp, dx, dy);
+       dst += ((y1 + dy) * stride);
+       x1 = (x1 + dx) * bpp;
+       dst += x1 >> FB_STIP_SHIFT;
+       x1 &= FB_STIP_MASK;
+       mask0 = FbStipMask(0, bpp);
+       mask = FbStipRight(mask0, x1);
+       if (sdx < 0)
+               mask0 = FbStipRight(mask0, FB_STIP_UNIT - bpp);
+       if (sdy < 0)
+               stride = -stride;
+       if (axis == X_AXIS) {
+               bits = 0;
+               while (len--) {
+                       bits |= mask;
+                       mask = fbBresShiftMask(mask, sdx, bpp);
+                       if (!mask) {
+                               WRITE(dst, FbDoMaskRRop(READ(dst), and, xor, bits));
+                               bits = 0;
+                               dst += sdx;
+                               mask = mask0;
+                       }
+                       e += e1;
+                       if (e >= 0) {
+                               WRITE(dst, FbDoMaskRRop(READ(dst), and, xor, bits));
+                               bits = 0;
+                               dst += stride;
+                               e += e3;
+                       }
+               }
+               if (bits)
+                       WRITE(dst, FbDoMaskRRop(READ(dst), and, xor, bits));
+       } else {
+               while (len--) {
+                       WRITE(dst, FbDoMaskRRop(READ(dst), and, xor, mask));
+                       dst += stride;
+                       e += e1;
+                       if (e >= 0) {
+                               e += e3;
+                               mask = fbBresShiftMask(mask, sdx, bpp);
+                               if (!mask) {
+                                       dst += sdx;
+                                       mask = mask0;
+                               }
+                       }
+               }
+       }
+}
+
+static void
+fbBresDash(DrawablePtr drawable, GCPtr gc, int dashOffset,
+           int sdx, int sdy, int axis,
+          int x1, int y1,
+          int e, int e1, int e3, int len)
+{
+       FbStip *dst;
+       FbStride stride;
+       int bpp;
+       int dx, dy;
+       FbGCPrivPtr pgc = fb_gc(gc);
+       FbStip and = (FbStip) pgc->and;
+       FbStip xor = (FbStip) pgc->xor;
+       FbStip bgand = (FbStip) pgc->bgand;
+       FbStip bgxor = (FbStip) pgc->bgxor;
+       FbStip mask, mask0;
+
+       FbDashDeclare;
+       int dashlen;
+       bool even;
+       bool doOdd;
+
+       fbGetStipDrawable(drawable, dst, stride, bpp, dx, dy);
+       doOdd = gc->lineStyle == LineDoubleDash;
+
+       FbDashInit(gc, pgc, dashOffset, dashlen, even);
+
+       dst += ((y1 + dy) * stride);
+       x1 = (x1 + dx) * bpp;
+       dst += x1 >> FB_STIP_SHIFT;
+       x1 &= FB_STIP_MASK;
+       mask0 = FbStipMask(0, bpp);
+       mask = FbStipRight(mask0, x1);
+       if (sdx < 0)
+               mask0 = FbStipRight(mask0, FB_STIP_UNIT - bpp);
+       if (sdy < 0)
+               stride = -stride;
+       while (len--) {
+               if (even)
+                       WRITE(dst, FbDoMaskRRop(READ(dst), and, xor, mask));
+               else if (doOdd)
+                       WRITE(dst, FbDoMaskRRop(READ(dst), bgand, bgxor, mask));
+               if (axis == X_AXIS) {
+                       mask = fbBresShiftMask(mask, sdx, bpp);
+                       if (!mask) {
+                               dst += sdx;
+                               mask = mask0;
+                       }
+                       e += e1;
+                       if (e >= 0) {
+                               dst += stride;
+                               e += e3;
+                       }
+               } else {
+                       dst += stride;
+                       e += e1;
+                       if (e >= 0) {
+                               e += e3;
+                               mask = fbBresShiftMask(mask, sdx, bpp);
+                               if (!mask) {
+                                       dst += sdx;
+                                       mask = mask0;
+                               }
+                       }
+               }
+               FbDashStep(dashlen, even);
+       }
+}
+
+static void
+fbBresFill(DrawablePtr drawable, GCPtr gc, int dashOffset,
+           int sdx, int sdy, int axis,
+          int x1, int y1,
+          int e, int e1, int e3, int len)
+{
+       while (len--) {
+               fbFill(drawable, gc, x1, y1, 1, 1);
+               if (axis == X_AXIS) {
+                       x1 += sdx;
+                       e += e1;
+                       if (e >= 0) {
+                               e += e3;
+                               y1 += sdy;
+                       }
+               } else {
+                       y1 += sdy;
+                       e += e1;
+                       if (e >= 0) {
+                               e += e3;
+                               x1 += sdx;
+                       }
+               }
+       }
+}
+
+static void
+fbSetFg(DrawablePtr drawable, GCPtr gc, Pixel fg)
+{
+       if (fg != gc->fgPixel) {
+               gc->fgPixel = fg;
+               fbValidateGC(gc, GCForeground, drawable);
+       }
+}
+
+static void
+fbBresFillDash(DrawablePtr drawable,
+               GCPtr gc,
+               int dashOffset,
+               int sdx,
+               int sdy,
+               int axis, int x1, int y1, int e, int e1, int e3, int len)
+{
+       FbGCPrivPtr pgc = fb_gc(gc);
+
+       FbDashDeclare;
+       int dashlen;
+       bool even;
+       bool doOdd;
+       bool doBg;
+       Pixel fg, bg;
+
+       fg = gc->fgPixel;
+       bg = gc->bgPixel;
+
+       /* whether to fill the odd dashes */
+       doOdd = gc->lineStyle == LineDoubleDash;
+       /* whether to switch fg to bg when filling odd dashes */
+       doBg = doOdd && (gc->fillStyle == FillSolid ||
+                        gc->fillStyle == FillStippled);
+
+       /* compute current dash position */
+       FbDashInit(gc, pgc, dashOffset, dashlen, even);
+
+       while (len--) {
+               if (even || doOdd) {
+                       if (doBg) {
+                               if (even)
+                                       fbSetFg(drawable, gc, fg);
+                               else
+                                       fbSetFg(drawable, gc, bg);
+                       }
+                       fbFill(drawable, gc, x1, y1, 1, 1);
+               }
+               if (axis == X_AXIS) {
+                       x1 += sdx;
+                       e += e1;
+                       if (e >= 0) {
+                               e += e3;
+                               y1 += sdy;
+                       }
+               } else {
+                       y1 += sdy;
+                       e += e1;
+                       if (e >= 0) {
+                               e += e3;
+                               x1 += sdx;
+                       }
+               }
+               FbDashStep(dashlen, even);
+       }
+       if (doBg)
+               fbSetFg(drawable, gc, fg);
+}
+
+static FbBres *
+fbSelectBres(DrawablePtr drawable, GCPtr gc)
+{
+       FbGCPrivPtr pgc = fb_gc(gc);
+       int bpp = drawable->bitsPerPixel;
+       FbBres *bres;
+
+       DBG(("%s: line=%d, fill=%d, and=%lx, bgand=%lx\n",
+            __FUNCTION__, gc->lineStyle, gc->fillStyle, pgc->and, pgc->bgand));
+       assert(gc->lineWidth == 0);
+
+       if (gc->lineStyle == LineSolid) {
+               bres = fbBresFill;
+               if (gc->fillStyle == FillSolid) {
+                       bres = fbBresSolid;
+                       if (pgc->and == 0) {
+                               switch (bpp) {
+                               case 8:
+                                       bres = fbBresSolid8;
+                                       break;
+                               case 16:
+                                       bres = fbBresSolid16;
+                                       break;
+                               case 32:
+                                       bres = fbBresSolid32;
+                                       break;
+                               }
+                       } else {
+                               switch (bpp) {
+                               case 8:
+                                       bres = fbBresSolidR8;
+                                       break;
+                               case 16:
+                                       bres = fbBresSolidR16;
+                                       break;
+                               case 32:
+                                       bres = fbBresSolidR32;
+                                       break;
+                               }
+                       }
+               }
+       } else {
+               bres = fbBresFillDash;
+               if (gc->fillStyle == FillSolid) {
+                       bres = fbBresDash;
+                       if (pgc->and == 0 &&
+                           (gc->lineStyle == LineOnOffDash || pgc->bgand == 0)) {
+                               switch (bpp) {
+                               case 8:
+                                       bres = fbBresDash8;
+                                       break;
+                               case 16:
+                                       bres = fbBresDash16;
+                                       break;
+                               case 32:
+                                       bres = fbBresDash32;
+                                       break;
+                               }
+                       }
+               }
+       }
+       return bres;
+}
+
+struct fbSegment {
+       FbBres *bres;
+       bool drawLast;
+       int *dashOffset;
+       int x1, y1, x2, y2;
+};
+
+static void
+_fbSegment(DrawablePtr drawable, GCPtr gc, const BoxRec *b, void *_data)
+{
+       struct fbSegment *data = _data;
+       const unsigned int bias = miGetZeroLineBias(drawable->pScreen);
+       int adx, ady;               /* abs values of dx and dy */
+       int sdx, sdy;               /* sign of dx and dy */
+       int e, e1, e2, e3;          /* bresenham error and increments */
+       int len, axis, octant;
+       int dashoff, doff;
+       unsigned int oc1, oc2;
+
+       DBG(("%s box=(%d, %d),(%d, %d)\n",
+            __FUNCTION__, b->x1, b->y1, b->x2, b->y2));
+
+       CalcLineDeltas(data->x1, data->y1, data->x2, data->y2,
+                      adx, ady, sdx, sdy, 1, 1, octant);
+
+       if (adx > ady) {
+               axis = X_AXIS;
+               e1 = ady << 1;
+               e2 = e1 - (adx << 1);
+               e = e1 - adx;
+               len = adx;
+       } else {
+               axis = Y_AXIS;
+               e1 = adx << 1;
+               e2 = e1 - (ady << 1);
+               e = e1 - ady;
+               SetYMajorOctant(octant);
+               len = ady;
+       }
+
+       FIXUP_ERROR(e, octant, bias);
+
+       /*
+        * Adjust error terms to compare against zero
+        */
+       e3 = e2 - e1;
+       e = e - e1;
+
+       if (data->drawLast)
+               len++;
+       dashoff = *data->dashOffset;
+       *data->dashOffset = dashoff + len;
+
+       oc1 = 0;
+       oc2 = 0;
+       OUTCODES(oc1, data->x1, data->y1, b);
+       OUTCODES(oc2, data->x2, data->y2, b);
+       if ((oc1 | oc2) == 0) {
+               data->bres(drawable, gc, dashoff,
+                          sdx, sdy, axis, data->x1, data->y1, e, e1, e3, len);
+       } else if (oc1 & oc2) {
+       } else {
+               int new_x1 = data->x1, new_y1 = data->y1;
+               int new_x2 = data->x2, new_y2 = data->y2;
+               int clip1 = 0, clip2 = 0;
+               int clipdx, clipdy;
+               int err;
+
+               if (miZeroClipLine(b->x1, b->y1, b->x2-1, b->y2-1,
+                                  &new_x1, &new_y1, &new_x2, &new_y2,
+                                  adx, ady, &clip1, &clip2,
+                                  octant, bias, oc1, oc2) == -1)
+                       return;
+
+               if (axis == X_AXIS)
+                       len = abs(new_x2 - new_x1);
+               else
+                       len = abs(new_y2 - new_y1);
+               if (clip2 != 0 || data->drawLast)
+                       len++;
+               if (len) {
+                       /* unwind bresenham error term to first point */
+                       doff = dashoff;
+                       err = e;
+                       if (clip1) {
+                               clipdx = abs(new_x1 - data->x1);
+                               clipdy = abs(new_y1 - data->y1);
+                               if (axis == X_AXIS) {
+                                       doff += clipdx;
+                                       err += e3 * clipdy + e1 * clipdx;
+                               } else {
+                                       doff += clipdy;
+                                       err += e3 * clipdx + e1 * clipdy;
+                               }
+                       }
+                       data->bres(drawable, gc, doff,
+                                  sdx, sdy, axis, new_x1, new_y1,
+                                  err, e1, e3, len);
+               }
+       }
+}
+
+void
+fbSegment(DrawablePtr drawable, GCPtr gc,
+          int x1, int y1, int x2, int y2,
+         bool drawLast, int *dashOffset)
+{
+       struct fbSegment data;
+       BoxRec box;
+
+       DBG(("%s (%d, %d), (%d, %d), drawLast?=%d\n",
+            __FUNCTION__, x1, y1, x2, y2, drawLast));
+
+       /* simple overestimate of line extents for clipping */
+       box.x1 = x1 - 1;
+       box.y1 = y1 - 1;
+       box.x2 = x2 + 1;
+       box.y2 = y2 + 1;
+
+       data.x1 = x1;
+       data.y1 = y1;
+       data.x2 = x2;
+       data.y2 = y2;
+
+       data.dashOffset = dashOffset;
+       data.drawLast = drawLast;
+       data.bres = fbSelectBres(drawable, gc);
+
+       fbDrawableRunUnclipped(drawable, gc, &box, _fbSegment, &data);
+}
+
+void
+fbSegment1(DrawablePtr drawable, GCPtr gc, const BoxRec *b,
+          int x1, int y1, int x2, int y2,
+          bool drawLast, int *dashOffset)
+{
+       struct fbSegment data;
+
+       DBG(("%s (%d, %d), (%d, %d), drawLast?=%d\n",
+            __FUNCTION__, x1, y1, x2, y2, drawLast));
+
+       data.x1 = x1;
+       data.y1 = y1;
+       data.x2 = x2;
+       data.y2 = y2;
+
+       data.dashOffset = dashOffset;
+       data.drawLast = drawLast;
+       data.bres = fbSelectBres(drawable, gc);
+
+       _fbSegment(drawable, gc, b, &data);
+}
diff --git a/src/sna/fb/fbsegbits.h b/src/sna/fb/fbsegbits.h
new file mode 100644 (file)
index 0000000..590ad30
--- /dev/null
@@ -0,0 +1,212 @@
+/*
+ * Copyright © 1998 Keith Packard
+ * Copyright © 2012 Intel Corporation
+ *
+ * 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 Keith Packard not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission.  Keith Packard makes no
+ * representations about the suitability of this software for any purpose.  It
+ * is provided "as is" without express or implied warranty.
+ *
+ * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL KEITH PACKARD 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.
+ */
+
+#define isClipped(c,ul,lr)  (((c) | ((c) - (ul)) | ((lr) - (c))) & 0x80008000)
+#define RROP(b,a,x)    WRITE((b), FbDoRRop (READ(b), (a), (x)))
+
+static void
+BRESSOLID(DrawablePtr drawable, GCPtr gc, int dashOffset,
+         int sdx, int sdy, int axis,
+         int x1, int y1, int e, int e1, int e3, int len)
+{
+       FbBits *dst;
+       FbStride stride;
+       int bpp, dx, dy;
+       BITS *bits;
+       FbStride major, minor;
+       BITS xor = fb_gc(gc)->xor;
+
+       fbGetDrawable(drawable, dst, stride, bpp, dx, dy);
+       bits = (BITS *)(dst + (y1 + dy) * stride) + (x1 + dx);
+       stride = stride * (sizeof(FbBits) / sizeof(BITS));
+       if (sdy < 0)
+               stride = -stride;
+       if (axis == X_AXIS) {
+               major = sdx;
+               minor = stride;
+       } else {
+               major = stride;
+               minor = sdx;
+       }
+       while (len--) {
+               WRITE(bits, xor);
+               bits += major;
+               e += e1;
+               if (e >= 0) {
+                       bits += minor;
+                       e += e3;
+               }
+       }
+}
+
+static void
+BRESSOLIDR(DrawablePtr drawable, GCPtr gc, int dashOffset,
+          int sdx, int sdy, int axis,
+          int x1, int y1, int e, int e1, int e3, int len)
+{
+       FbBits *dst;
+       FbStride stride;
+       int bpp, dx, dy;
+       BITS *bits;
+       FbStride major, minor;
+       BITS and = fb_gc(gc)->and;
+       BITS xor = fb_gc(gc)->xor;
+
+       fbGetDrawable(drawable, dst, stride, bpp, dx, dy);
+       bits = (BITS *)(dst + (y1 + dy) * stride) + (x1 + dx);
+       stride = stride * (sizeof(FbBits) / sizeof(BITS));
+       if (sdy < 0)
+               stride = -stride;
+       if (axis == X_AXIS) {
+               major = sdx;
+               minor = stride;
+       } else {
+               major = stride;
+               minor = sdx;
+       }
+       while (len--) {
+               RROP(bits, and, xor);
+               bits += major;
+               e += e1;
+               if (e >= 0) {
+                       bits += minor;
+                       e += e3;
+               }
+       }
+}
+
+static void
+BRESDASH(DrawablePtr drawable, GCPtr gc, int dashOffset,
+        int sdx, int sdy, int axis,
+        int x1, int y1, int e, int e1, int e3, int len)
+{
+       FbBits *dst;
+       FbStride stride;
+       int bpp, dx, dy;
+       BITS *bits;
+       FbStride major, minor;
+
+       FbDashDeclare;
+       int dashlen;
+       bool even;
+       bool doOdd = gc->lineStyle == LineDoubleDash;
+       BITS xorfg = fb_gc(gc)->xor;
+       BITS xorbg = fb_gc(gc)->bgxor;
+
+       fbGetDrawable(drawable, dst, stride, bpp, dx, dy);
+
+       FbDashInit(gc, fb_gc(gc), dashOffset, dashlen, even);
+
+       bits = ((BITS *) (dst + ((y1 + dy) * stride))) + (x1 + dx);
+       stride = stride * (sizeof(FbBits) / sizeof(BITS));
+       if (sdy < 0)
+               stride = -stride;
+       if (axis == X_AXIS) {
+               major = sdx;
+               minor = stride;
+       } else {
+               major = stride;
+               minor = sdx;
+       }
+       if (dashlen >= len)
+               dashlen = len;
+       if (doOdd) {
+               if (!even)
+                       goto doubleOdd;
+               for (;;) {
+                       len -= dashlen;
+                       while (dashlen--) {
+                               WRITE(bits, xorfg);
+                               bits += major;
+                               if ((e += e1) >= 0) {
+                                       e += e3;
+                                       bits += minor;
+                               }
+                       }
+                       if (!len)
+                               break;
+
+                       FbDashNextEven(dashlen);
+
+                       if (dashlen >= len)
+                               dashlen = len;
+doubleOdd:
+                       len -= dashlen;
+                       while (dashlen--) {
+                               WRITE(bits, xorbg);
+                               bits += major;
+                               if ((e += e1) >= 0) {
+                                       e += e3;
+                                       bits += minor;
+                               }
+                       }
+                       if (!len)
+                               break;
+
+                       FbDashNextOdd(dashlen);
+
+                       if (dashlen >= len)
+                               dashlen = len;
+               }
+       } else {
+               if (!even)
+                       goto onOffOdd;
+               for (;;) {
+                       len -= dashlen;
+                       while (dashlen--) {
+                               WRITE(bits, xorfg);
+                               bits += major;
+                               if ((e += e1) >= 0) {
+                                       e += e3;
+                                       bits += minor;
+                               }
+                       }
+                       if (!len)
+                               break;
+
+                       FbDashNextEven(dashlen);
+
+                       if (dashlen >= len)
+                               dashlen = len;
+onOffOdd:
+                       len -= dashlen;
+                       while (dashlen--) {
+                               bits += major;
+                               if ((e += e1) >= 0) {
+                                       e += e3;
+                                       bits += minor;
+                               }
+                       }
+                       if (!len)
+                               break;
+
+                       FbDashNextOdd(dashlen);
+
+                       if (dashlen >= len)
+                               dashlen = len;
+               }
+       }
+}
+
+#undef RROP
+#undef isClipped
diff --git a/src/sna/fb/fbspan.c b/src/sna/fb/fbspan.c
new file mode 100644 (file)
index 0000000..45cb7cc
--- /dev/null
@@ -0,0 +1,131 @@
+/*
+ * Copyright © 1998 Keith Packard
+ * Copyright © 2012 Intel Corporation
+ *
+ * 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 Keith Packard not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission.  Keith Packard makes no
+ * representations about the suitability of this software for any purpose.  It
+ * is provided "as is" without express or implied warranty.
+ *
+ * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL KEITH PACKARD 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 "fb.h"
+#include "fbclip.h"
+
+inline static void
+fbFillSpan(DrawablePtr drawable, GCPtr gc, const BoxRec *b, void *data)
+{
+       DBG(("%s (%d,%d)+%d\n", __FUNCTION__, b->x1, b->y1, b->x2-b->x1));
+       fbFill(drawable, gc, b->x1, b->y1, b->x2 - b->x1, 1);
+}
+
+void
+fbFillSpans(DrawablePtr drawable, GCPtr gc,
+           int n, DDXPointPtr pt, int *width, int fSorted)
+{
+       DBG(("%s x %d\n", __FUNCTION__, n));
+       while (n--) {
+               BoxRec box;
+
+               *(DDXPointPtr)&box = *pt++;
+               box.x2 = box.x1 + *width++;
+               box.y2 = box.y1 + 1;
+
+               /* XXX fSorted */
+               fbDrawableRun(drawable, gc, &box, fbFillSpan, NULL);
+       }
+}
+
+struct fbSetSpan {
+       char *src;
+       DDXPointRec pt;
+       FbStride stride;
+       FbBits *dst;
+       int dx, dy;
+};
+
+inline static void
+fbSetSpan(DrawablePtr drawable, GCPtr gc, const BoxRec *b, void *_data)
+{
+       struct fbSetSpan *data = _data;
+       int xoff, bpp;
+
+       xoff = (int) (((long)data->src) & (FB_MASK >> 3));
+       bpp = drawable->bitsPerPixel;
+
+       fbBlt((FbBits *)(data->src - xoff), 0,
+             (b->x1 - data->pt.x) * bpp + (xoff << 3),
+             data->dst + (b->y1 + data->dy) * data->stride, data->stride,
+             (b->x1 + data->dx) * bpp,
+             (b->x2 - b->x1) * bpp, 1,
+             gc->alu, fb_gc(gc)->pm, bpp,
+             FALSE, FALSE);
+}
+
+void
+fbSetSpans(DrawablePtr drawable, GCPtr gc,
+           char *src, DDXPointPtr pt, int *width, int n, int fSorted)
+{
+       struct fbSetSpan data;
+       PixmapPtr pixmap;
+
+       DBG(("%s x %d\n", __FUNCTION__, n));
+
+       fbGetDrawablePixmap(drawable, pixmap, data.dx, data.dy);
+       data.dst = pixmap->devPrivate.ptr;
+       data.stride = pixmap->devKind / sizeof(FbStip);
+
+       data.src = src;
+       while (n--) {
+               BoxRec box;
+
+               *(DDXPointPtr)&box = data.pt = *pt;
+               box.x2 = box.x1 + *width;
+               box.y2 = box.y1 + 1;
+
+               fbDrawableRun(drawable, gc, &box, fbSetSpan, &data);
+
+               data.src += PixmapBytePad(*width, drawable->depth);
+               width++;
+               pt++;
+       }
+}
+
+void
+fbGetSpans(DrawablePtr drawable, int wMax,
+           DDXPointPtr pt, int *width, int n, char *dst)
+{
+       FbBits *src, *d;
+       FbStride srcStride;
+       int srcBpp;
+       int srcXoff, srcYoff;
+       int xoff;
+
+       fbGetDrawable(drawable, src, srcStride, srcBpp, srcXoff, srcYoff);
+
+       DBG(("%s x %d\n", __FUNCTION__, n));
+       while (n--) {
+               xoff = (int) (((long) dst) & (FB_MASK >> 3));
+               d = (FbBits *) (dst - xoff);
+               fbBlt(src + (pt->y + srcYoff) * srcStride, srcStride,
+                     (pt->x + srcXoff) * srcBpp,
+                     d, 1, xoff << 3, *width * srcBpp,
+                     1, GXcopy, FB_ALLONES, srcBpp,
+                     FALSE, FALSE);
+               dst += PixmapBytePad(*width, drawable->depth);
+               pt++;
+               width++;
+       }
+}
diff --git a/src/sna/fb/fbstipple.c b/src/sna/fb/fbstipple.c
new file mode 100644 (file)
index 0000000..d02970a
--- /dev/null
@@ -0,0 +1,223 @@
+/*
+ * Copyright © 1998 Keith Packard
+ * Copyright © 2012 Intel Corporation
+ *
+ * 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 Keith Packard not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission.  Keith Packard makes no
+ * representations about the suitability of this software for any purpose.  It
+ * is provided "as is" without express or implied warranty.
+ *
+ * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL KEITH PACKARD 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 "fb.h"
+
+/*
+ * This is a slight abuse of the preprocessor to generate repetitive
+ * code, the idea is to generate code for each case of a copy-mode
+ * transparent stipple
+ */
+#define LaneCases1(c,a) \
+       case c: while (n--) { FbLaneCase(c,a); a++; } break
+#define LaneCases2(c,a)            LaneCases1(c,a); LaneCases1(c+1,a)
+#define LaneCases4(c,a)            LaneCases2(c,a); LaneCases2(c+2,a)
+#define LaneCases8(c,a)            LaneCases4(c,a); LaneCases4(c+4,a)
+#define LaneCases16(c,a)    LaneCases8(c,a); LaneCases8(c+8,a)
+
+#define LaneCases(a)       LaneCases16(0,a)
+
+/*
+ * Repeat a transparent stipple across a scanline n times
+ */
+
+void
+fbTransparentSpan(FbBits * dst, FbBits stip, FbBits fgxor, int n)
+{
+       FbStip s;
+
+       s = ((FbStip) (stip) & 0x01);
+       s |= ((FbStip) (stip >> 8) & 0x02);
+       s |= ((FbStip) (stip >> 16) & 0x04);
+       s |= ((FbStip) (stip >> 24) & 0x08);
+       switch (s) {
+               LaneCases(dst);
+       }
+}
+
+static void
+fbEvenStipple(FbBits *dst, FbStride dstStride, int dstX, int dstBpp,
+              int width, int height,
+              FbStip *stip, FbStride stipStride,
+              int stipHeight,
+              FbBits fgand, FbBits fgxor, FbBits bgand, FbBits bgxor,
+             int xRot, int yRot)
+{
+       FbBits startmask, endmask;
+       FbBits mask, and, xor;
+       int nmiddle, n;
+       FbStip *s, *stipEnd, bits;
+       int rot, stipX, stipY;
+       int pixelsPerDst;
+       const FbBits *fbBits;
+       Bool transparent;
+       int startbyte, endbyte;
+
+       /*
+        * Check for a transparent stipple (stencil)
+        */
+       transparent = FALSE;
+       if (dstBpp >= 8 && fgand == 0 && bgand == FB_ALLONES && bgxor == 0)
+               transparent = TRUE;
+
+       pixelsPerDst = FB_UNIT / dstBpp;
+       /*
+        * Adjust dest pointers
+        */
+       dst += dstX >> FB_SHIFT;
+       dstX &= FB_MASK;
+       FbMaskBitsBytes(dstX, width, fgand == 0 && bgand == 0,
+                       startmask, startbyte, nmiddle, endmask, endbyte);
+
+       if (startmask)
+               dstStride--;
+       dstStride -= nmiddle;
+
+       xRot *= dstBpp;
+       /*
+        * Compute stip start scanline and rotation parameters
+        */
+       stipEnd = stip + stipStride * stipHeight;
+       modulus(-yRot, stipHeight, stipY);
+       s = stip + stipStride * stipY;
+       modulus(-xRot, FB_UNIT, stipX);
+       rot = stipX;
+
+       /*
+        * Get pointer to stipple mask array for this depth
+        */
+       /* fbStippleTable covers all valid bpp (4,8,16,32) */
+       fbBits = fbStippleTable[pixelsPerDst];
+
+       while (height--) {
+               /*
+                * Extract stipple bits for this scanline;
+                */
+               bits = READ(s);
+               s += stipStride;
+               if (s == stipEnd)
+                       s = stip;
+               mask = fbBits[FbLeftStipBits(bits, pixelsPerDst)];
+               /*
+                * Rotate into position and compute reduced rop values
+                */
+               mask = FbRotLeft(mask, rot);
+               and = (fgand & mask) | (bgand & ~mask);
+               xor = (fgxor & mask) | (bgxor & ~mask);
+
+               if (transparent) {
+                       if (startmask) {
+                               fbTransparentSpan(dst, mask & startmask, fgxor, 1);
+                               dst++;
+                       }
+                       fbTransparentSpan(dst, mask, fgxor, nmiddle);
+                       dst += nmiddle;
+                       if (endmask)
+                               fbTransparentSpan(dst, mask & endmask, fgxor, 1);
+               } else {
+                       /*
+                        * Fill scanline
+                        */
+                       if (startmask) {
+                               FbDoLeftMaskByteRRop(dst, startbyte, startmask, and, xor);
+                               dst++;
+                       }
+                       n = nmiddle;
+                       if (!and)
+                               while (n--)
+                                       WRITE(dst++, xor);
+                       else {
+                               while (n--) {
+                                       WRITE(dst, FbDoRRop(READ(dst), and, xor));
+                                       dst++;
+                               }
+                       }
+                       if (endmask)
+                               FbDoRightMaskByteRRop(dst, endbyte, endmask, and, xor);
+               }
+               dst += dstStride;
+       }
+}
+
+static void
+fbOddStipple(FbBits *dst, FbStride dstStride, int dstX, int dstBpp,
+             int width, int height,
+             FbStip *stip, FbStride stipStride,
+             int stipWidth, int stipHeight,
+             FbBits fgand, FbBits fgxor, FbBits bgand, FbBits bgxor,
+            int xRot, int yRot)
+{
+       int stipX, stipY, sx;
+       int widthTmp;
+       int h, w;
+       int x, y;
+
+       modulus(-yRot, stipHeight, stipY);
+       modulus(dstX / dstBpp - xRot, stipWidth, stipX);
+       y = 0;
+       while (height) {
+               h = stipHeight - stipY;
+               if (h > height)
+                       h = height;
+               height -= h;
+               widthTmp = width;
+               x = dstX;
+               sx = stipX;
+               while (widthTmp) {
+                       w = (stipWidth - sx) * dstBpp;
+                       if (w > widthTmp)
+                               w = widthTmp;
+                       widthTmp -= w;
+                       fbBltOne(stip + stipY * stipStride,
+                                stipStride,
+                                sx,
+                                dst + y * dstStride,
+                                dstStride, x, dstBpp, w, h, fgand, fgxor, bgand, bgxor);
+                       x += w;
+                       sx = 0;
+               }
+               y += h;
+               stipY = 0;
+       }
+}
+
+void
+fbStipple(FbBits *dst, FbStride dstStride, int dstX, int dstBpp,
+          int width, int height,
+          FbStip *stip, FbStride stipStride,
+          int stipWidth, int stipHeight, Bool even,
+          FbBits fgand, FbBits fgxor, FbBits bgand, FbBits bgxor,
+         int xRot, int yRot)
+{
+       DBG(("%s stipple=%dx%d, size=%dx%d\n",
+            __FUNCTION__, stipWidth, stipHeight, width, height));
+
+       if (even)
+               fbEvenStipple(dst, dstStride, dstX, dstBpp, width, height,
+                             stip, stipStride, stipHeight,
+                             fgand, fgxor, bgand, bgxor, xRot, yRot);
+       else
+               fbOddStipple(dst, dstStride, dstX, dstBpp, width, height,
+                            stip, stipStride, stipWidth, stipHeight,
+                            fgand, fgxor, bgand, bgxor, xRot, yRot);
+}
diff --git a/src/sna/fb/fbtile.c b/src/sna/fb/fbtile.c
new file mode 100644 (file)
index 0000000..c350671
--- /dev/null
@@ -0,0 +1,151 @@
+/*
+ * Copyright © 1998 Keith Packard
+ * Copyright © 2012 Intel Corporation
+ *
+ * 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 Keith Packard not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission.  Keith Packard makes no
+ * representations about the suitability of this software for any purpose.  It
+ * is provided "as is" without express or implied warranty.
+ *
+ * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL KEITH PACKARD 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 "fb.h"
+
+/*
+ * Accelerated tile fill -- tile width is a power of two not greater
+ * than FB_UNIT
+ */
+
+static void
+fbEvenTile(FbBits *dst, FbStride dstStride, int dstX, int width, int height,
+           FbBits *tile, FbStride tileStride, int tileHeight,
+          int alu, FbBits pm,
+          int xRot, int yRot)
+{
+       FbBits *t, *tileEnd, bits;
+       FbBits startmask, endmask;
+       FbBits and, xor;
+       int n, nmiddle;
+       int tileX, tileY;
+       int rot;
+       int startbyte, endbyte;
+
+       dst += dstX >> FB_SHIFT;
+       dstX &= FB_MASK;
+       FbMaskBitsBytes(dstX, width, FbDestInvarientRop(alu, pm),
+                       startmask, startbyte, nmiddle, endmask, endbyte);
+       if (startmask)
+               dstStride--;
+       dstStride -= nmiddle;
+
+       /*
+        * Compute tile start scanline and rotation parameters
+        */
+       tileEnd = tile + tileHeight * tileStride;
+       modulus(-yRot, tileHeight, tileY);
+       t = tile + tileY * tileStride;
+       modulus(-xRot, FB_UNIT, tileX);
+       rot = tileX;
+
+       while (height--) {
+               /*
+                * Pick up bits for this scanline
+                */
+               bits = READ(t);
+               t += tileStride;
+               if (t >= tileEnd)
+                       t = tile;
+               bits = FbRotLeft(bits, rot);
+               and = fbAnd(alu, bits, pm);
+               xor = fbXor(alu, bits, pm);
+
+               if (startmask) {
+                       FbDoLeftMaskByteRRop(dst, startbyte, startmask, and, xor);
+                       dst++;
+               }
+               n = nmiddle;
+               if (!and)
+                       while (n--)
+                               WRITE(dst++, xor);
+               else
+                       while (n--) {
+                               WRITE(dst, FbDoRRop(READ(dst), and, xor));
+                               dst++;
+                       }
+               if (endmask)
+                       FbDoRightMaskByteRRop(dst, endbyte, endmask, and, xor);
+               dst += dstStride;
+       }
+}
+
+static void
+fbOddTile(FbBits *dst, FbStride dstStride, int dstX,
+          int width, int height,
+          FbBits *tile, FbStride tileStride,
+          int tileWidth, int tileHeight,
+         int alu, FbBits pm, int bpp,
+         int xRot, int yRot)
+{
+       int tileX, tileY;
+       int x, y;
+
+       DBG(("%s tile=%dx%d, size=%dx%d\n", __FUNCTION__,
+            tileWidth, tileHeight, width, height));
+
+       modulus(-yRot, tileHeight, tileY);
+       y = 0;
+       while (height) {
+               int ww = width;
+               int h = tileHeight - tileY;
+               if (h > height)
+                       h = height;
+               height -= h;
+               x = dstX;
+               modulus(dstX - xRot, tileWidth, tileX);
+               while (ww) {
+                       int w = tileWidth - tileX;
+                       if (w > ww)
+                               w = ww;
+                       ww -= w;
+                       fbBlt(tile + tileY * tileStride, tileStride, tileX,
+                             dst + y * dstStride, dstStride,
+                             x, w, h, alu, pm, bpp, FALSE, FALSE);
+                       x += w;
+                       tileX = 0;
+               }
+               y += h;
+               tileY = 0;
+       }
+}
+
+void
+fbTile(FbBits *dst, FbStride dstStride, int dstX,
+       int width, int height,
+       FbBits *tile, FbStride tileStride,
+       int tileWidth, int tileHeight,
+       int alu, FbBits pm, int bpp,
+       int xRot, int yRot)
+{
+       DBG(("%s tile=%dx%d, size=%dx%d\n", __FUNCTION__,
+            tileWidth, tileHeight, width, height));
+
+       if (FbEvenTile(tileWidth))
+               fbEvenTile(dst, dstStride, dstX, width, height,
+                          tile, tileStride, tileHeight, alu, pm, xRot, yRot);
+       else
+               fbOddTile(dst, dstStride, dstX, width, height,
+                         tile, tileStride, tileWidth, tileHeight,
+                         alu, pm, bpp, xRot, yRot);
+}
diff --git a/src/sna/fb/fbutil.c b/src/sna/fb/fbutil.c
new file mode 100644 (file)
index 0000000..61b63ad
--- /dev/null
@@ -0,0 +1,126 @@
+/*
+ * Copyright © 1998 Keith Packard
+ * Copyright © 2012 Intel Corporation
+ *
+ * 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 Keith Packard not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission.  Keith Packard makes no
+ * representations about the suitability of this software for any purpose.  It
+ * is provided "as is" without express or implied warranty.
+ *
+ * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL KEITH PACKARD 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 "fb.h"
+
+FbBits
+fbReplicatePixel(Pixel p, int bpp)
+{
+       FbBits b = p;
+
+       b &= FbFullMask(bpp);
+       while (bpp < FB_UNIT) {
+               b |= b << bpp;
+               bpp <<= 1;
+       }
+       return b;
+}
+
+/*
+ * Stipple masks are independent of bit/byte order as long
+ * as bitorder == byteorder.  FB doesn't handle the case
+ * where these differ
+ */
+#define __mask(x,w)    ((FB_ALLONES << ((x) & FB_MASK)) & \
+                        (FB_ALLONES >> ((FB_UNIT - ((x) + (w))) & FB_MASK)))
+#define _mask(x,w)     __mask((x)*(w),(w))
+#define mask(b,n,w)    ((((b) >> (n)) & 1) * _mask(n,w))
+
+#define _C1(b,n,w) mask(b,n,w)
+#define _C2(b,n,w) (_C1(b,n,w) | _C1(b,n+1,w))
+#define _C4(b,n,w) (_C2(b,n,w) | _C2(b,n+2,w))
+#define C8(b,w) (_C4(b,0,w) | _C4(b,4,w))
+#define C4(b,w) _C4(b,0,w)
+#define C2(b,w) _C2(b,0,w)
+#define C1(b,w) _C1(b,0,w)
+
+static const FbBits fbStipple8Bits[256] = {
+       C8(0, 4), C8(1, 4), C8(2, 4), C8(3, 4), C8(4, 4), C8(5, 4),
+       C8(6, 4), C8(7, 4), C8(8, 4), C8(9, 4), C8(10, 4), C8(11, 4),
+       C8(12, 4), C8(13, 4), C8(14, 4), C8(15, 4), C8(16, 4), C8(17, 4),
+       C8(18, 4), C8(19, 4), C8(20, 4), C8(21, 4), C8(22, 4), C8(23, 4),
+       C8(24, 4), C8(25, 4), C8(26, 4), C8(27, 4), C8(28, 4), C8(29, 4),
+       C8(30, 4), C8(31, 4), C8(32, 4), C8(33, 4), C8(34, 4), C8(35, 4),
+       C8(36, 4), C8(37, 4), C8(38, 4), C8(39, 4), C8(40, 4), C8(41, 4),
+       C8(42, 4), C8(43, 4), C8(44, 4), C8(45, 4), C8(46, 4), C8(47, 4),
+       C8(48, 4), C8(49, 4), C8(50, 4), C8(51, 4), C8(52, 4), C8(53, 4),
+       C8(54, 4), C8(55, 4), C8(56, 4), C8(57, 4), C8(58, 4), C8(59, 4),
+       C8(60, 4), C8(61, 4), C8(62, 4), C8(63, 4), C8(64, 4), C8(65, 4),
+       C8(66, 4), C8(67, 4), C8(68, 4), C8(69, 4), C8(70, 4), C8(71, 4),
+       C8(72, 4), C8(73, 4), C8(74, 4), C8(75, 4), C8(76, 4), C8(77, 4),
+       C8(78, 4), C8(79, 4), C8(80, 4), C8(81, 4), C8(82, 4), C8(83, 4),
+       C8(84, 4), C8(85, 4), C8(86, 4), C8(87, 4), C8(88, 4), C8(89, 4),
+       C8(90, 4), C8(91, 4), C8(92, 4), C8(93, 4), C8(94, 4), C8(95, 4),
+       C8(96, 4), C8(97, 4), C8(98, 4), C8(99, 4), C8(100, 4), C8(101, 4),
+       C8(102, 4), C8(103, 4), C8(104, 4), C8(105, 4), C8(106, 4), C8(107, 4),
+       C8(108, 4), C8(109, 4), C8(110, 4), C8(111, 4), C8(112, 4), C8(113, 4),
+       C8(114, 4), C8(115, 4), C8(116, 4), C8(117, 4), C8(118, 4), C8(119, 4),
+       C8(120, 4), C8(121, 4), C8(122, 4), C8(123, 4), C8(124, 4), C8(125, 4),
+       C8(126, 4), C8(127, 4), C8(128, 4), C8(129, 4), C8(130, 4), C8(131, 4),
+       C8(132, 4), C8(133, 4), C8(134, 4), C8(135, 4), C8(136, 4), C8(137, 4),
+       C8(138, 4), C8(139, 4), C8(140, 4), C8(141, 4), C8(142, 4), C8(143, 4),
+       C8(144, 4), C8(145, 4), C8(146, 4), C8(147, 4), C8(148, 4), C8(149, 4),
+       C8(150, 4), C8(151, 4), C8(152, 4), C8(153, 4), C8(154, 4), C8(155, 4),
+       C8(156, 4), C8(157, 4), C8(158, 4), C8(159, 4), C8(160, 4), C8(161, 4),
+       C8(162, 4), C8(163, 4), C8(164, 4), C8(165, 4), C8(166, 4), C8(167, 4),
+       C8(168, 4), C8(169, 4), C8(170, 4), C8(171, 4), C8(172, 4), C8(173, 4),
+       C8(174, 4), C8(175, 4), C8(176, 4), C8(177, 4), C8(178, 4), C8(179, 4),
+       C8(180, 4), C8(181, 4), C8(182, 4), C8(183, 4), C8(184, 4), C8(185, 4),
+       C8(186, 4), C8(187, 4), C8(188, 4), C8(189, 4), C8(190, 4), C8(191, 4),
+       C8(192, 4), C8(193, 4), C8(194, 4), C8(195, 4), C8(196, 4), C8(197, 4),
+       C8(198, 4), C8(199, 4), C8(200, 4), C8(201, 4), C8(202, 4), C8(203, 4),
+       C8(204, 4), C8(205, 4), C8(206, 4), C8(207, 4), C8(208, 4), C8(209, 4),
+       C8(210, 4), C8(211, 4), C8(212, 4), C8(213, 4), C8(214, 4), C8(215, 4),
+       C8(216, 4), C8(217, 4), C8(218, 4), C8(219, 4), C8(220, 4), C8(221, 4),
+       C8(222, 4), C8(223, 4), C8(224, 4), C8(225, 4), C8(226, 4), C8(227, 4),
+       C8(228, 4), C8(229, 4), C8(230, 4), C8(231, 4), C8(232, 4), C8(233, 4),
+       C8(234, 4), C8(235, 4), C8(236, 4), C8(237, 4), C8(238, 4), C8(239, 4),
+       C8(240, 4), C8(241, 4), C8(242, 4), C8(243, 4), C8(244, 4), C8(245, 4),
+       C8(246, 4), C8(247, 4), C8(248, 4), C8(249, 4), C8(250, 4), C8(251, 4),
+       C8(252, 4), C8(253, 4), C8(254, 4), C8(255, 4),
+};
+
+static const FbBits fbStipple4Bits[16] = {
+       C4(0, 8), C4(1, 8), C4(2, 8), C4(3, 8), C4(4, 8), C4(5, 8),
+       C4(6, 8), C4(7, 8), C4(8, 8), C4(9, 8), C4(10, 8), C4(11, 8),
+       C4(12, 8), C4(13, 8), C4(14, 8), C4(15, 8),
+};
+
+static const FbBits fbStipple2Bits[4] = {
+       C2(0, 16), C2(1, 16), C2(2, 16), C2(3, 16),
+};
+
+static const FbBits fbStipple1Bits[2] = {
+       C1(0, 32), C1(1, 32),
+};
+const FbBits *const fbStippleTable[] = {
+       0,
+       fbStipple1Bits,
+       fbStipple2Bits,
+       0,
+       fbStipple4Bits,
+       0,
+       0,
+       0,
+       fbStipple8Bits,
+};
diff --git a/src/sna/fb/sfb.h b/src/sna/fb/sfb.h
new file mode 100644 (file)
index 0000000..a4d9d17
--- /dev/null
@@ -0,0 +1,40 @@
+/* And rename to avoid symbol clashes with UXA */
+#define fbPolyArc sfbPolyArc
+#define fbBlt sfbBlt
+#define fbBltOne sfbBltOne
+#define fbBltPlane sfbBltPlane
+#define fbCopyNtoN sfbCopyNtoN
+#define fbCopy1toN sfbCopy1toN
+#define fbCopyNto1 sfbCopyNto1
+#define fbCopyArea sfbCopyArea
+#define fbCopyPlane sfbCopyPlane
+#define fbFill sfbFill
+#define fbSolidBoxClipped sfbSolidBoxClipped
+#define fbPolyFillRect sfbPolyFillRect
+#define fbFillSpans sfbFillSpans
+#define fbPadPixmap sfbPadPixmap
+#define fbValidateGC sfbValidateGC
+#define fbGetSpans sfbGetSpans
+#define fbPolyGlyphBlt sfbPolyGlyphBlt
+#define fbImageGlyphBlt sfbImageGlyphBlt
+#define fbPutImage sfbPutImage
+#define fbPuXYtImage sfbPutXYImage
+#define fbGetImage sfbGetImage
+#define fbPolyLine sfbPolyLine
+#define fbFixCoordModePrevious sfbFixCoordModePrevious
+#define fbPolySegment sfbPolySegment
+#define fbBitmapToRegion sfbBitmapToRegion
+#define fbPolyPoint sfbPolyPoint
+#define fbPushImage sfbPushImage
+#define fbPushPixels sfbPushPixels
+#define fbSetSpans sfbSetSpans
+#define fbSegment sfbSegment
+#define fbSegment1 sfbSegment1
+#define fbTransparentSpan sfbTransparentSpan
+#define fbStipple sfbStipple
+#define fbTile sfbTile
+#define fbReplicatePixel sfbReplicatePixel
+
+#define fbComposite sfbComposite
+#define image_from_pict simage_from_pict
+#define free_pixmap_pict sfree_pixmap_pict
diff --git a/src/sna/gen2_render.c b/src/sna/gen2_render.c
new file mode 100644 (file)
index 0000000..ca61bd3
--- /dev/null
@@ -0,0 +1,3166 @@
+/*
+ * Copyright © 2006,2011 Intel 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.
+ *
+ * Authors:
+ *    Wang Zhenyu <zhenyu.z.wang@intel.com>
+ *    Eric Anholt <eric@anholt.net>
+ *    Chris Wilson <chris@chris-wilson.co.uk>
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "sna.h"
+#include "sna_reg.h"
+#include "sna_render.h"
+#include "sna_render_inline.h"
+
+#include "gen2_render.h"
+
+#define NO_COMPOSITE 0
+#define NO_COMPOSITE_SPANS 0
+#define NO_COPY 0
+#define NO_COPY_BOXES 0
+#define NO_FILL 0
+#define NO_FILL_ONE 0
+#define NO_FILL_BOXES 0
+
+#define PREFER_BLT_FILL 1
+#define PREFER_BLT_COPY 1
+
+#define MAX_3D_SIZE 2048
+#define MAX_3D_PITCH 8192
+
+#define BATCH(v) batch_emit(sna, v)
+#define BATCH_F(v) batch_emit_float(sna, v)
+#define VERTEX(v) batch_emit_float(sna, v)
+
+static const struct blendinfo {
+       bool dst_alpha;
+       bool src_alpha;
+       uint32_t src_blend;
+       uint32_t dst_blend;
+} gen2_blend_op[] = {
+       /* Clear */
+       {0, 0, BLENDFACTOR_ZERO, BLENDFACTOR_ZERO},
+       /* Src */
+       {0, 0, BLENDFACTOR_ONE, BLENDFACTOR_ZERO},
+       /* Dst */
+       {0, 0, BLENDFACTOR_ZERO, BLENDFACTOR_ONE},
+       /* Over */
+       {0, 1, BLENDFACTOR_ONE, BLENDFACTOR_INV_SRC_ALPHA},
+       /* OverReverse */
+       {1, 0, BLENDFACTOR_INV_DST_ALPHA, BLENDFACTOR_ONE},
+       /* In */
+       {1, 0, BLENDFACTOR_DST_ALPHA, BLENDFACTOR_ZERO},
+       /* InReverse */
+       {0, 1, BLENDFACTOR_ZERO, BLENDFACTOR_SRC_ALPHA},
+       /* Out */
+       {1, 0, BLENDFACTOR_INV_DST_ALPHA, BLENDFACTOR_ZERO},
+       /* OutReverse */
+       {0, 1, BLENDFACTOR_ZERO, BLENDFACTOR_INV_SRC_ALPHA},
+       /* Atop */
+       {1, 1, BLENDFACTOR_DST_ALPHA, BLENDFACTOR_INV_SRC_ALPHA},
+       /* AtopReverse */
+       {1, 1, BLENDFACTOR_INV_DST_ALPHA, BLENDFACTOR_SRC_ALPHA},
+       /* Xor */
+       {1, 1, BLENDFACTOR_INV_DST_ALPHA, BLENDFACTOR_INV_SRC_ALPHA},
+       /* Add */
+       {0, 0, BLENDFACTOR_ONE, BLENDFACTOR_ONE},
+};
+
+static const struct formatinfo {
+       unsigned int fmt;
+       uint32_t card_fmt;
+} i8xx_tex_formats[] = {
+       {PICT_a8, MAPSURF_8BIT | MT_8BIT_A8},
+       {PICT_a8r8g8b8, MAPSURF_32BIT | MT_32BIT_ARGB8888},
+       {PICT_a8b8g8r8, MAPSURF_32BIT | MT_32BIT_ABGR8888},
+       {PICT_r5g6b5, MAPSURF_16BIT | MT_16BIT_RGB565},
+       {PICT_a1r5g5b5, MAPSURF_16BIT | MT_16BIT_ARGB1555},
+       {PICT_a4r4g4b4, MAPSURF_16BIT | MT_16BIT_ARGB4444},
+}, i85x_tex_formats[] = {
+       {PICT_x8r8g8b8, MAPSURF_32BIT | MT_32BIT_XRGB8888},
+       {PICT_x8b8g8r8, MAPSURF_32BIT | MT_32BIT_XBGR8888},
+};
+
+static inline bool
+too_large(int width, int height)
+{
+       return width > MAX_3D_SIZE || height > MAX_3D_SIZE;
+}
+
+static inline uint32_t
+gen2_buf_tiling(uint32_t tiling)
+{
+       uint32_t v = 0;
+       switch (tiling) {
+       default: assert(0);
+       case I915_TILING_Y: v |= BUF_3D_TILE_WALK_Y;
+       case I915_TILING_X: v |= BUF_3D_TILED_SURFACE;
+       case I915_TILING_NONE: break;
+       }
+       return v;
+}
+
+static uint32_t
+gen2_get_dst_format(uint32_t format)
+{
+#define BIAS DSTORG_HORT_BIAS(0x8) | DSTORG_VERT_BIAS(0x8)
+       switch (format) {
+       default:
+               assert(0);
+       case PICT_a8r8g8b8:
+       case PICT_x8r8g8b8:
+               return COLR_BUF_ARGB8888 | BIAS;
+       case PICT_r5g6b5:
+               return COLR_BUF_RGB565 | BIAS;
+       case PICT_a1r5g5b5:
+       case PICT_x1r5g5b5:
+               return COLR_BUF_ARGB1555 | BIAS;
+       case PICT_a8:
+               return COLR_BUF_8BIT | BIAS;
+       case PICT_a4r4g4b4:
+       case PICT_x4r4g4b4:
+               return COLR_BUF_ARGB4444 | BIAS;
+       }
+#undef BIAS
+}
+
+static bool
+gen2_check_dst_format(uint32_t format)
+{
+       switch (format) {
+       case PICT_a8r8g8b8:
+       case PICT_x8r8g8b8:
+       case PICT_r5g6b5:
+       case PICT_a1r5g5b5:
+       case PICT_x1r5g5b5:
+       case PICT_a8:
+       case PICT_a4r4g4b4:
+       case PICT_x4r4g4b4:
+               return true;
+       default:
+               return false;
+       }
+}
+
+static uint32_t
+gen2_get_card_format(struct sna *sna, uint32_t format)
+{
+       unsigned int i;
+
+       for (i = 0; i < ARRAY_SIZE(i8xx_tex_formats); i++)
+               if (i8xx_tex_formats[i].fmt == format)
+                       return i8xx_tex_formats[i].card_fmt;
+
+       if (sna->kgem.gen < 21) {
+               /* Whilst these are not directly supported on 830/845,
+                * we only enable them when we can implicitly convert
+                * them to a supported variant through the texture
+                * combiners.
+                */
+               for (i = 0; i < ARRAY_SIZE(i85x_tex_formats); i++)
+                       if (i85x_tex_formats[i].fmt == format)
+                               return i8xx_tex_formats[1+i].card_fmt;
+       } else {
+               for (i = 0; i < ARRAY_SIZE(i85x_tex_formats); i++)
+                       if (i85x_tex_formats[i].fmt == format)
+                               return i85x_tex_formats[i].card_fmt;
+       }
+
+       assert(0);
+       return 0;
+}
+
+static uint32_t
+gen2_check_format(struct sna *sna, PicturePtr p)
+{
+       unsigned int i;
+
+       for (i = 0; i < ARRAY_SIZE(i8xx_tex_formats); i++)
+               if (i8xx_tex_formats[i].fmt == p->format)
+                       return true;
+
+       if (sna->kgem.gen > 21) {
+               for (i = 0; i < ARRAY_SIZE(i85x_tex_formats); i++)
+                       if (i85x_tex_formats[i].fmt == p->format)
+                               return true;
+       }
+
+       return false;
+}
+
+static uint32_t
+gen2_sampler_tiling_bits(uint32_t tiling)
+{
+       uint32_t bits = 0;
+       switch (tiling) {
+       default:
+               assert(0);
+       case I915_TILING_Y:
+               bits |= TM0S1_TILE_WALK;
+       case I915_TILING_X:
+               bits |= TM0S1_TILED_SURFACE;
+       case I915_TILING_NONE:
+               break;
+       }
+       return bits;
+}
+
+static bool
+gen2_check_filter(PicturePtr picture)
+{
+       switch (picture->filter) {
+       case PictFilterNearest:
+       case PictFilterBilinear:
+               return true;
+       default:
+               return false;
+       }
+}
+
+static bool
+gen2_check_repeat(PicturePtr picture)
+{
+       if (!picture->repeat)
+               return true;
+
+       switch (picture->repeatType) {
+       case RepeatNone:
+       case RepeatNormal:
+       case RepeatPad:
+       case RepeatReflect:
+               return true;
+       default:
+               return false;
+       }
+}
+
+static void
+gen2_emit_texture(struct sna *sna,
+                 const struct sna_composite_channel *channel,
+                 int unit)
+{
+       uint32_t wrap_mode_u, wrap_mode_v;
+       uint32_t texcoordtype;
+       uint32_t filter;
+
+       if (channel->is_affine)
+               texcoordtype = TEXCOORDTYPE_CARTESIAN;
+       else
+               texcoordtype = TEXCOORDTYPE_HOMOGENEOUS;
+
+       switch (channel->repeat) {
+       default:
+               assert(0);
+       case RepeatNone:
+               wrap_mode_u = TEXCOORDMODE_CLAMP_BORDER;
+               break;
+       case RepeatNormal:
+               wrap_mode_u = TEXCOORDMODE_WRAP;
+               break;
+       case RepeatPad:
+               wrap_mode_u = TEXCOORDMODE_CLAMP;
+               break;
+       case RepeatReflect:
+               wrap_mode_u = TEXCOORDMODE_MIRROR;
+               break;
+       }
+       if (channel->is_linear)
+               wrap_mode_v = TEXCOORDMODE_WRAP;
+       else
+               wrap_mode_v = wrap_mode_u;
+
+       switch (channel->filter) {
+       default:
+               assert(0);
+       case PictFilterNearest:
+               filter = (FILTER_NEAREST << TM0S3_MAG_FILTER_SHIFT |
+                         FILTER_NEAREST << TM0S3_MIN_FILTER_SHIFT |
+                         MIPFILTER_NONE << TM0S3_MIP_FILTER_SHIFT);
+               break;
+       case PictFilterBilinear:
+               filter = (FILTER_LINEAR << TM0S3_MAG_FILTER_SHIFT |
+                         FILTER_LINEAR << TM0S3_MIN_FILTER_SHIFT |
+                         MIPFILTER_NONE << TM0S3_MIP_FILTER_SHIFT);
+               break;
+       }
+
+       BATCH(_3DSTATE_LOAD_STATE_IMMEDIATE_2 | LOAD_TEXTURE_MAP(unit) | 4);
+       BATCH(kgem_add_reloc(&sna->kgem, sna->kgem.nbatch,
+                            channel->bo,
+                            I915_GEM_DOMAIN_SAMPLER << 16,
+                            0));
+       BATCH(((channel->height - 1) << TM0S1_HEIGHT_SHIFT) |
+             ((channel->width - 1)  << TM0S1_WIDTH_SHIFT) |
+             gen2_get_card_format(sna, channel->pict_format) |
+             gen2_sampler_tiling_bits(channel->bo->tiling));
+       BATCH((channel->bo->pitch / 4 - 1) << TM0S2_PITCH_SHIFT | TM0S2_MAP_2D);
+       BATCH(filter);
+       BATCH(0);       /* default color */
+
+       BATCH(_3DSTATE_MAP_COORD_SET_CMD | TEXCOORD_SET(unit) |
+             ENABLE_TEXCOORD_PARAMS | TEXCOORDS_ARE_NORMAL | texcoordtype |
+             ENABLE_ADDR_V_CNTL | TEXCOORD_ADDR_V_MODE(wrap_mode_v) |
+             ENABLE_ADDR_U_CNTL | TEXCOORD_ADDR_U_MODE(wrap_mode_u));
+}
+
+static void
+gen2_get_blend_factors(const struct sna_composite_op *op,
+                      int blend,
+                      uint32_t *c_out,
+                      uint32_t *a_out)
+{
+       uint32_t cblend, ablend;
+
+       /* If component alpha is active in the mask and the blend operation
+        * uses the source alpha, then we know we don't need the source
+        * value (otherwise we would have hit a fallback earlier), so we
+        * provide the source alpha (src.A * mask.X) as output color.
+        * Conversely, if CA is set and we don't need the source alpha, then
+        * we produce the source value (src.X * mask.X) and the source alpha
+        * is unused..  Otherwise, we provide the non-CA source value
+        * (src.X * mask.A).
+        *
+        * The PICT_FORMAT_RGB(pict) == 0 fixups are not needed on 855+'s a8
+        * pictures, but we need to implement it for 830/845 and there's no
+        * harm done in leaving it in.
+        */
+       cblend = TB0C_LAST_STAGE | TB0C_RESULT_SCALE_1X | TB0C_OUTPUT_WRITE_CURRENT;
+       ablend = TB0A_RESULT_SCALE_1X | TB0A_OUTPUT_WRITE_CURRENT;
+
+
+       /* Get the source picture's channels into TBx_ARG1 */
+       if ((op->has_component_alpha && gen2_blend_op[blend].src_alpha) ||
+           op->dst.format == PICT_a8) {
+               /* Producing source alpha value, so the first set of channels
+                * is src.A instead of src.X.  We also do this if the destination
+                * is a8, in which case src.G is what's written, and the other
+                * channels are ignored.
+                */
+               if (op->src.is_solid) {
+                       ablend |= TB0A_ARG1_SEL_DIFFUSE;
+                       cblend |= TB0C_ARG1_SEL_DIFFUSE | TB0C_ARG1_REPLICATE_ALPHA;
+               } else {
+                       ablend |= TB0A_ARG1_SEL_TEXEL0;
+                       cblend |= TB0C_ARG1_SEL_TEXEL0 | TB0C_ARG1_REPLICATE_ALPHA;
+               }
+       } else {
+               if (op->src.is_solid)
+                       cblend |= TB0C_ARG1_SEL_DIFFUSE;
+               else if (PICT_FORMAT_RGB(op->src.pict_format) != 0)
+                       cblend |= TB0C_ARG1_SEL_TEXEL0;
+               else
+                       cblend |= TB0C_ARG1_SEL_ONE | TB0C_ARG1_INVERT; /* 0.0 */
+               if (op->src.is_solid)
+                       ablend |= TB0A_ARG1_SEL_DIFFUSE;
+               else if (op->src.is_opaque)
+                       ablend |= TB0A_ARG1_SEL_ONE;
+               else
+                       ablend |= TB0A_ARG1_SEL_TEXEL0;
+       }
+
+       if (op->mask.bo) {
+               if (op->src.is_solid) {
+                       cblend |= TB0C_ARG2_SEL_TEXEL0;
+                       ablend |= TB0A_ARG2_SEL_TEXEL0;
+               } else {
+                       cblend |= TB0C_ARG2_SEL_TEXEL1;
+                       ablend |= TB0A_ARG2_SEL_TEXEL1;
+               }
+
+               if (op->dst.format == PICT_a8 || !op->has_component_alpha)
+                       cblend |= TB0C_ARG2_REPLICATE_ALPHA;
+
+               cblend |= TB0C_OP_MODULATE;
+               ablend |= TB0A_OP_MODULATE;
+       } else {
+               cblend |= TB0C_OP_ARG1;
+               ablend |= TB0A_OP_ARG1;
+       }
+
+       *c_out = cblend;
+       *a_out = ablend;
+}
+
+static uint32_t gen2_get_blend_cntl(int op,
+                                   bool has_component_alpha,
+                                   uint32_t dst_format)
+{
+       uint32_t sblend, dblend;
+
+       if (op <= PictOpSrc)
+               return S8_ENABLE_COLOR_BUFFER_WRITE;
+
+       sblend = gen2_blend_op[op].src_blend;
+       dblend = gen2_blend_op[op].dst_blend;
+
+       /* If there's no dst alpha channel, adjust the blend op so that
+        * we'll treat it as always 1.
+        */
+       if (PICT_FORMAT_A(dst_format) == 0 && gen2_blend_op[op].dst_alpha) {
+               if (sblend == BLENDFACTOR_DST_ALPHA)
+                       sblend = BLENDFACTOR_ONE;
+               else if (sblend == BLENDFACTOR_INV_DST_ALPHA)
+                       sblend = BLENDFACTOR_ZERO;
+       }
+
+       /* If the source alpha is being used, then we should only be in a case
+        * where the source blend factor is 0, and the source blend value is
+        * the mask channels multiplied by the source picture's alpha.
+        */
+       if (has_component_alpha && gen2_blend_op[op].src_alpha) {
+               if (dblend == BLENDFACTOR_SRC_ALPHA)
+                       dblend = BLENDFACTOR_SRC_COLR;
+               else if (dblend == BLENDFACTOR_INV_SRC_ALPHA)
+                       dblend = BLENDFACTOR_INV_SRC_COLR;
+       }
+
+       return (sblend << S8_SRC_BLEND_FACTOR_SHIFT |
+               dblend << S8_DST_BLEND_FACTOR_SHIFT |
+               S8_ENABLE_COLOR_BLEND | S8_BLENDFUNC_ADD |
+               S8_ENABLE_COLOR_BUFFER_WRITE);
+}
+
+static void gen2_emit_invariant(struct sna *sna)
+{
+       int i;
+
+       for (i = 0; i < 4; i++) {
+               BATCH(_3DSTATE_MAP_CUBE | MAP_UNIT(i));
+               BATCH(_3DSTATE_MAP_TEX_STREAM_CMD | MAP_UNIT(i) |
+                     DISABLE_TEX_STREAM_BUMP |
+                     ENABLE_TEX_STREAM_COORD_SET | TEX_STREAM_COORD_SET(i) |
+                     ENABLE_TEX_STREAM_MAP_IDX | TEX_STREAM_MAP_IDX(i));
+               BATCH(_3DSTATE_MAP_COORD_TRANSFORM);
+               BATCH(DISABLE_TEX_TRANSFORM | TEXTURE_SET(i));
+       }
+
+       BATCH(_3DSTATE_MAP_COORD_SETBIND_CMD);
+       BATCH(TEXBIND_SET3(TEXCOORDSRC_VTXSET_3) |
+             TEXBIND_SET2(TEXCOORDSRC_VTXSET_2) |
+             TEXBIND_SET1(TEXCOORDSRC_VTXSET_1) |
+             TEXBIND_SET0(TEXCOORDSRC_VTXSET_0));
+
+       BATCH(_3DSTATE_SCISSOR_ENABLE_CMD | DISABLE_SCISSOR_RECT);
+
+       BATCH(_3DSTATE_VERTEX_TRANSFORM);
+       BATCH(DISABLE_VIEWPORT_TRANSFORM | DISABLE_PERSPECTIVE_DIVIDE);
+
+       BATCH(_3DSTATE_W_STATE_CMD);
+       BATCH(MAGIC_W_STATE_DWORD1);
+       BATCH_F(1.0);
+
+       BATCH(_3DSTATE_INDPT_ALPHA_BLEND_CMD |
+             DISABLE_INDPT_ALPHA_BLEND |
+             ENABLE_ALPHA_BLENDFUNC | ABLENDFUNC_ADD);
+
+       BATCH(_3DSTATE_CONST_BLEND_COLOR_CMD);
+       BATCH(0);
+
+       BATCH(_3DSTATE_MODES_1_CMD |
+             ENABLE_COLR_BLND_FUNC | BLENDFUNC_ADD |
+             ENABLE_SRC_BLND_FACTOR | SRC_BLND_FACT(BLENDFACTOR_ONE) |
+             ENABLE_DST_BLND_FACTOR | DST_BLND_FACT(BLENDFACTOR_ZERO));
+
+       BATCH(_3DSTATE_ENABLES_1_CMD |
+             DISABLE_LOGIC_OP |
+             DISABLE_STENCIL_TEST |
+             DISABLE_DEPTH_BIAS |
+             DISABLE_SPEC_ADD |
+             DISABLE_FOG |
+             DISABLE_ALPHA_TEST |
+             DISABLE_DEPTH_TEST |
+             ENABLE_COLOR_BLEND);
+
+       BATCH(_3DSTATE_ENABLES_2_CMD |
+             DISABLE_STENCIL_WRITE |
+             DISABLE_DITHER |
+             DISABLE_DEPTH_WRITE |
+             ENABLE_COLOR_MASK |
+             ENABLE_COLOR_WRITE |
+             ENABLE_TEX_CACHE);
+
+       sna->render_state.gen2.need_invariant = false;
+}
+
+static void
+gen2_get_batch(struct sna *sna)
+{
+       kgem_set_mode(&sna->kgem, KGEM_RENDER);
+
+       if (!kgem_check_batch(&sna->kgem, 30+40)) {
+               DBG(("%s: flushing batch: size %d > %d\n",
+                    __FUNCTION__, 30+40,
+                    sna->kgem.surface-sna->kgem.nbatch));
+               kgem_submit(&sna->kgem);
+               _kgem_set_mode(&sna->kgem, KGEM_RENDER);
+       }
+
+       if (!kgem_check_reloc(&sna->kgem, 3)) {
+               DBG(("%s: flushing batch: reloc %d >= %d\n",
+                    __FUNCTION__,
+                    sna->kgem.nreloc + 3,
+                    (int)KGEM_RELOC_SIZE(&sna->kgem)));
+               kgem_submit(&sna->kgem);
+               _kgem_set_mode(&sna->kgem, KGEM_RENDER);
+       }
+
+       if (!kgem_check_exec(&sna->kgem, 3)) {
+               DBG(("%s: flushing batch: exec %d >= %d\n",
+                    __FUNCTION__,
+                    sna->kgem.nexec + 1,
+                    (int)KGEM_EXEC_SIZE(&sna->kgem)));
+               kgem_submit(&sna->kgem);
+               _kgem_set_mode(&sna->kgem, KGEM_RENDER);
+       }
+
+       if (sna->render_state.gen2.need_invariant)
+               gen2_emit_invariant(sna);
+}
+
+static void gen2_emit_target(struct sna *sna, const struct sna_composite_op *op)
+{
+       assert(!too_large(op->dst.width, op->dst.height));
+       assert(op->dst.bo->pitch >= 8 && op->dst.bo->pitch <= MAX_3D_PITCH);
+       assert(sna->render_state.gen2.vertex_offset == 0);
+
+       if (sna->render_state.gen2.target == op->dst.bo->unique_id) {
+               kgem_bo_mark_dirty(op->dst.bo);
+               return;
+       }
+
+       BATCH(_3DSTATE_BUF_INFO_CMD);
+       BATCH(BUF_3D_ID_COLOR_BACK |
+             gen2_buf_tiling(op->dst.bo->tiling) |
+             BUF_3D_PITCH(op->dst.bo->pitch));
+       BATCH(kgem_add_reloc(&sna->kgem, sna->kgem.nbatch,
+                            op->dst.bo,
+                            I915_GEM_DOMAIN_RENDER << 16 |
+                            I915_GEM_DOMAIN_RENDER,
+                            0));
+
+       BATCH(_3DSTATE_DST_BUF_VARS_CMD);
+       BATCH(gen2_get_dst_format(op->dst.format));
+
+       BATCH(_3DSTATE_DRAW_RECT_CMD);
+       BATCH(0);
+       BATCH(0);       /* ymin, xmin */
+       BATCH(DRAW_YMAX(op->dst.height - 1) |
+             DRAW_XMAX(op->dst.width - 1));
+       BATCH(0);       /* yorig, xorig */
+
+       sna->render_state.gen2.target = op->dst.bo->unique_id;
+}
+
+static void gen2_disable_logic_op(struct sna *sna)
+{
+       if (!sna->render_state.gen2.logic_op_enabled)
+               return;
+
+       DBG(("%s\n", __FUNCTION__));
+
+       BATCH(_3DSTATE_ENABLES_1_CMD |
+             DISABLE_LOGIC_OP | ENABLE_COLOR_BLEND);
+
+       sna->render_state.gen2.logic_op_enabled = 0;
+}
+
+static void gen2_enable_logic_op(struct sna *sna, int op)
+{
+       static const uint8_t logic_op[] = {
+               LOGICOP_CLEAR,          /* GXclear */
+               LOGICOP_AND,            /* GXand */
+               LOGICOP_AND_RVRSE,      /* GXandReverse */
+               LOGICOP_COPY,           /* GXcopy */
+               LOGICOP_AND_INV,        /* GXandInverted */
+               LOGICOP_NOOP,           /* GXnoop */
+               LOGICOP_XOR,            /* GXxor */
+               LOGICOP_OR,             /* GXor */
+               LOGICOP_NOR,            /* GXnor */
+               LOGICOP_EQUIV,          /* GXequiv */
+               LOGICOP_INV,            /* GXinvert */
+               LOGICOP_OR_RVRSE,       /* GXorReverse */
+               LOGICOP_COPY_INV,       /* GXcopyInverted */
+               LOGICOP_OR_INV,         /* GXorInverted */
+               LOGICOP_NAND,           /* GXnand */
+               LOGICOP_SET             /* GXset */
+       };
+
+       if (sna->render_state.gen2.logic_op_enabled != op+1) {
+               if (!sna->render_state.gen2.logic_op_enabled) {
+                       if (op == GXclear || op == GXcopy)
+                               return;
+
+                       DBG(("%s\n", __FUNCTION__));
+
+                       BATCH(_3DSTATE_ENABLES_1_CMD |
+                             ENABLE_LOGIC_OP | DISABLE_COLOR_BLEND);
+               }
+
+               BATCH(_3DSTATE_MODES_4_CMD |
+                     ENABLE_LOGIC_OP_FUNC | LOGIC_OP_FUNC(logic_op[op]));
+               sna->render_state.gen2.logic_op_enabled = op+1;
+       }
+}
+
+static void gen2_emit_composite_state(struct sna *sna,
+                                     const struct sna_composite_op *op)
+{
+       uint32_t texcoordfmt, v, unwind;
+       uint32_t cblend, ablend;
+       int tex;
+
+       gen2_get_batch(sna);
+
+       if (kgem_bo_is_dirty(op->src.bo) || kgem_bo_is_dirty(op->mask.bo)) {
+               if (op->src.bo == op->dst.bo || op->mask.bo == op->dst.bo)
+                       BATCH(MI_FLUSH | MI_INVALIDATE_MAP_CACHE);
+               else
+                       BATCH(_3DSTATE_MODES_5_CMD |
+                             PIPELINE_FLUSH_RENDER_CACHE |
+                             PIPELINE_FLUSH_TEXTURE_CACHE);
+               kgem_clear_dirty(&sna->kgem);
+       }
+
+       gen2_emit_target(sna, op);
+
+       unwind = sna->kgem.nbatch;
+       BATCH(_3DSTATE_LOAD_STATE_IMMEDIATE_1 |
+             I1_LOAD_S(2) | I1_LOAD_S(3) | I1_LOAD_S(8) | 2);
+       BATCH((!op->src.is_solid + (op->mask.bo != NULL)) << 12);
+       BATCH(S3_CULLMODE_NONE | S3_VERTEXHAS_XY);
+       BATCH(gen2_get_blend_cntl(op->op,
+                                 op->has_component_alpha,
+                                 op->dst.format));
+       if (memcmp(sna->kgem.batch + sna->render_state.gen2.ls1 + 1,
+                  sna->kgem.batch + unwind + 1,
+                  3 * sizeof(uint32_t)) == 0)
+               sna->kgem.nbatch = unwind;
+       else
+               sna->render_state.gen2.ls1 = unwind;
+
+       gen2_disable_logic_op(sna);
+
+       gen2_get_blend_factors(op, op->op, &cblend, &ablend);
+       unwind = sna->kgem.nbatch;
+       BATCH(_3DSTATE_LOAD_STATE_IMMEDIATE_2 |
+             LOAD_TEXTURE_BLEND_STAGE(0) | 1);
+       BATCH(cblend);
+       BATCH(ablend);
+       if (memcmp(sna->kgem.batch + sna->render_state.gen2.ls2 + 1,
+                  sna->kgem.batch + unwind + 1,
+                  2 * sizeof(uint32_t)) == 0)
+               sna->kgem.nbatch = unwind;
+       else
+               sna->render_state.gen2.ls2 = unwind;
+
+       tex = texcoordfmt = 0;
+       if (!op->src.is_solid) {
+               if (op->src.is_affine)
+                       texcoordfmt |= TEXCOORDFMT_2D << (2*tex);
+               else
+                       texcoordfmt |= TEXCOORDFMT_3D << (2*tex);
+               gen2_emit_texture(sna, &op->src, tex++);
+       } else {
+               if (op->src.u.gen2.pixel != sna->render_state.gen2.diffuse) {
+                       BATCH(_3DSTATE_DFLT_DIFFUSE_CMD);
+                       BATCH(op->src.u.gen2.pixel);
+                       sna->render_state.gen2.diffuse = op->src.u.gen2.pixel;
+               }
+       }
+       if (op->mask.bo) {
+               if (op->mask.is_affine)
+                       texcoordfmt |= TEXCOORDFMT_2D << (2*tex);
+               else
+                       texcoordfmt |= TEXCOORDFMT_3D << (2*tex);
+               gen2_emit_texture(sna, &op->mask, tex++);
+       }
+
+       v = _3DSTATE_VERTEX_FORMAT_2_CMD | texcoordfmt;
+       if (sna->render_state.gen2.vft != v) {
+               BATCH(v);
+               sna->render_state.gen2.vft = v;
+       }
+}
+
+static inline void
+gen2_emit_composite_dstcoord(struct sna *sna, int dstX, int dstY)
+{
+       VERTEX(dstX);
+       VERTEX(dstY);
+}
+
+inline static void
+gen2_emit_composite_linear(struct sna *sna,
+                          const struct sna_composite_channel *channel,
+                          int16_t x, int16_t y)
+{
+       float v;
+
+       v = (x * channel->u.gen2.linear_dx +
+            y * channel->u.gen2.linear_dy +
+            channel->u.gen2.linear_offset);
+       DBG(("%s: (%d, %d) -> %f\n", __FUNCTION__, x, y, v));
+       VERTEX(v);
+       VERTEX(v);
+}
+
+static void
+gen2_emit_composite_texcoord(struct sna *sna,
+                            const struct sna_composite_channel *channel,
+                            int16_t x, int16_t y)
+{
+       float s = 0, t = 0, w = 1;
+
+       x += channel->offset[0];
+       y += channel->offset[1];
+
+       if (channel->is_affine) {
+               sna_get_transformed_coordinates(x, y,
+                                               channel->transform,
+                                               &s, &t);
+               VERTEX(s * channel->scale[0]);
+               VERTEX(t * channel->scale[1]);
+       } else {
+               sna_get_transformed_coordinates_3d(x, y,
+                                                  channel->transform,
+                                                  &s, &t, &w);
+               VERTEX(s * channel->scale[0]);
+               VERTEX(t * channel->scale[1]);
+               VERTEX(w);
+       }
+}
+
+static void
+gen2_emit_composite_vertex(struct sna *sna,
+                          const struct sna_composite_op *op,
+                          int16_t srcX, int16_t srcY,
+                          int16_t mskX, int16_t mskY,
+                          int16_t dstX, int16_t dstY)
+{
+       gen2_emit_composite_dstcoord(sna, dstX, dstY);
+       if (op->src.is_linear)
+               gen2_emit_composite_linear(sna, &op->src, srcX, srcY);
+       else if (!op->src.is_solid)
+               gen2_emit_composite_texcoord(sna, &op->src, srcX, srcY);
+
+       if (op->mask.is_linear)
+               gen2_emit_composite_linear(sna, &op->mask, mskX, mskY);
+       else if (op->mask.bo)
+               gen2_emit_composite_texcoord(sna, &op->mask, mskX, mskY);
+}
+
+fastcall static void
+gen2_emit_composite_primitive(struct sna *sna,
+                             const struct sna_composite_op *op,
+                             const struct sna_composite_rectangles *r)
+{
+       gen2_emit_composite_vertex(sna, op,
+                                  r->src.x + r->width,
+                                  r->src.y + r->height,
+                                  r->mask.x + r->width,
+                                  r->mask.y + r->height,
+                                  op->dst.x + r->dst.x + r->width,
+                                  op->dst.y + r->dst.y + r->height);
+       gen2_emit_composite_vertex(sna, op,
+                                  r->src.x,
+                                  r->src.y + r->height,
+                                  r->mask.x,
+                                  r->mask.y + r->height,
+                                  op->dst.x + r->dst.x,
+                                  op->dst.y + r->dst.y + r->height);
+       gen2_emit_composite_vertex(sna, op,
+                                  r->src.x,
+                                  r->src.y,
+                                  r->mask.x,
+                                  r->mask.y,
+                                  op->dst.x + r->dst.x,
+                                  op->dst.y + r->dst.y);
+}
+
+fastcall static void
+gen2_emit_composite_primitive_constant(struct sna *sna,
+                                      const struct sna_composite_op *op,
+                                      const struct sna_composite_rectangles *r)
+{
+       int16_t dst_x = r->dst.x + op->dst.x;
+       int16_t dst_y = r->dst.y + op->dst.y;
+
+       gen2_emit_composite_dstcoord(sna, dst_x + r->width, dst_y + r->height);
+       gen2_emit_composite_dstcoord(sna, dst_x, dst_y + r->height);
+       gen2_emit_composite_dstcoord(sna, dst_x, dst_y);
+}
+
+fastcall static void
+gen2_emit_composite_primitive_linear(struct sna *sna,
+                                      const struct sna_composite_op *op,
+                                      const struct sna_composite_rectangles *r)
+{
+       int16_t dst_x = r->dst.x + op->dst.x;
+       int16_t dst_y = r->dst.y + op->dst.y;
+
+       gen2_emit_composite_dstcoord(sna, dst_x + r->width, dst_y + r->height);
+       gen2_emit_composite_linear(sna, &op->src,
+                                  r->src.x + r->width, r->src.y + r->height);
+
+       gen2_emit_composite_dstcoord(sna, dst_x, dst_y + r->height);
+       gen2_emit_composite_linear(sna, &op->src,
+                                  r->src.x, r->src.y + r->height);
+
+       gen2_emit_composite_dstcoord(sna, dst_x, dst_y);
+       gen2_emit_composite_linear(sna, &op->src,
+                                  r->src.x, r->src.y);
+}
+
+fastcall static void
+gen2_emit_composite_primitive_identity(struct sna *sna,
+                                      const struct sna_composite_op *op,
+                                      const struct sna_composite_rectangles *r)
+{
+       float w = r->width;
+       float h = r->height;
+       float *v;
+
+       v = (float *)sna->kgem.batch + sna->kgem.nbatch;
+       sna->kgem.nbatch += 12;
+
+       v[8] = v[4] = r->dst.x + op->dst.x;
+       v[0] = v[4] + w;
+
+       v[9] = r->dst.y + op->dst.y;
+       v[5] = v[1] = v[9] + h;
+
+       v[10] = v[6] = (r->src.x + op->src.offset[0]) * op->src.scale[0];
+       v[2] = v[6] + w * op->src.scale[0];
+
+       v[11] = (r->src.y + op->src.offset[1]) * op->src.scale[1];
+       v[7] = v[3] = v[11] + h * op->src.scale[1];
+}
+
+fastcall static void
+gen2_emit_composite_primitive_affine(struct sna *sna,
+                                    const struct sna_composite_op *op,
+                                    const struct sna_composite_rectangles *r)
+{
+       PictTransform *transform = op->src.transform;
+       int16_t dst_x = r->dst.x + op->dst.x;
+       int16_t dst_y = r->dst.y + op->dst.y;
+       int src_x = r->src.x + (int)op->src.offset[0];
+       int src_y = r->src.y + (int)op->src.offset[1];
+       float sx, sy;
+
+       _sna_get_transformed_coordinates(src_x + r->width, src_y + r->height,
+                                        transform,
+                                        &sx, &sy);
+
+       gen2_emit_composite_dstcoord(sna, dst_x + r->width, dst_y + r->height);
+       VERTEX(sx * op->src.scale[0]);
+       VERTEX(sy * op->src.scale[1]);
+
+       _sna_get_transformed_coordinates(src_x, src_y + r->height,
+                                        transform,
+                                        &sx, &sy);
+       gen2_emit_composite_dstcoord(sna, dst_x, dst_y + r->height);
+       VERTEX(sx * op->src.scale[0]);
+       VERTEX(sy * op->src.scale[1]);
+
+       _sna_get_transformed_coordinates(src_x, src_y,
+                                        transform,
+                                        &sx, &sy);
+       gen2_emit_composite_dstcoord(sna, dst_x, dst_y);
+       VERTEX(sx * op->src.scale[0]);
+       VERTEX(sy * op->src.scale[1]);
+}
+
+fastcall static void
+gen2_emit_composite_primitive_constant_identity_mask(struct sna *sna,
+                                                    const struct sna_composite_op *op,
+                                                    const struct sna_composite_rectangles *r)
+{
+       float w = r->width;
+       float h = r->height;
+       float *v;
+
+       v = (float *)sna->kgem.batch + sna->kgem.nbatch;
+       sna->kgem.nbatch += 12;
+
+       v[8] = v[4] = r->dst.x + op->dst.x;
+       v[0] = v[4] + w;
+
+       v[9] = r->dst.y + op->dst.y;
+       v[5] = v[1] = v[9] + h;
+
+       v[10] = v[6] = (r->mask.x + op->mask.offset[0]) * op->mask.scale[0];
+       v[2] = v[6] + w * op->mask.scale[0];
+
+       v[11] = (r->mask.y + op->mask.offset[1]) * op->mask.scale[1];
+       v[7] = v[3] = v[11] + h * op->mask.scale[1];
+}
+
+static void gen2_magic_ca_pass(struct sna *sna,
+                              const struct sna_composite_op *op)
+{
+       uint32_t ablend, cblend, *src, *dst;
+       int n;
+
+       if (!op->need_magic_ca_pass)
+               return;
+
+       DBG(("%s: batch=%x, vertex=%x\n", __FUNCTION__,
+            sna->kgem.nbatch, sna->render_state.gen2.vertex_offset));
+
+       assert(op->mask.bo);
+       assert(op->has_component_alpha);
+
+       BATCH(_3DSTATE_LOAD_STATE_IMMEDIATE_1 | I1_LOAD_S(8) | 0);
+       BATCH(BLENDFACTOR_ONE << S8_SRC_BLEND_FACTOR_SHIFT |
+             BLENDFACTOR_ONE << S8_DST_BLEND_FACTOR_SHIFT |
+             S8_ENABLE_COLOR_BLEND | S8_BLENDFUNC_ADD |
+             S8_ENABLE_COLOR_BUFFER_WRITE);
+       sna->render_state.gen2.ls1 = 0;
+
+       gen2_get_blend_factors(op, PictOpAdd, &cblend, &ablend);
+       BATCH(_3DSTATE_LOAD_STATE_IMMEDIATE_2 |
+             LOAD_TEXTURE_BLEND_STAGE(0) | 1);
+       BATCH(cblend);
+       BATCH(ablend);
+       sna->render_state.gen2.ls2 = 0;
+
+       src = sna->kgem.batch + sna->render_state.gen2.vertex_offset;
+       dst = sna->kgem.batch + sna->kgem.nbatch;
+       n = 1 + sna->render.vertex_index;
+       sna->kgem.nbatch += n;
+       while (n--)
+               *dst++ = *src++;
+}
+
+static void gen2_vertex_flush(struct sna *sna,
+                             const struct sna_composite_op *op)
+{
+       if (sna->render.vertex_index == 0)
+               return;
+
+       sna->kgem.batch[sna->render_state.gen2.vertex_offset] |=
+               sna->render.vertex_index - 1;
+
+       gen2_magic_ca_pass(sna, op);
+
+       sna->render_state.gen2.vertex_offset = 0;
+       sna->render.vertex_index = 0;
+}
+
+inline static int gen2_get_rectangles(struct sna *sna,
+                                     const struct sna_composite_op *op,
+                                     int want)
+{
+       struct gen2_render_state *state = &sna->render_state.gen2;
+       int rem = batch_space(sna), size, need;
+
+       DBG(("%s: want=%d, floats_per_vertex=%d, rem=%d\n",
+            __FUNCTION__, want, op->floats_per_vertex, rem));
+
+       assert(op->floats_per_vertex);
+
+       need = 1;
+       size = op->floats_per_rect;
+       if (op->need_magic_ca_pass)
+               need += 6 + size*sna->render.vertex_index, size *= 2;
+
+       DBG(("%s: want=%d, need=%d,size=%d, rem=%d\n",
+            __FUNCTION__, want, need, size, rem));
+       if (rem < need + size) {
+               gen2_vertex_flush(sna, op);
+               kgem_submit(&sna->kgem);
+               _kgem_set_mode(&sna->kgem, KGEM_RENDER);
+               return 0;
+       }
+
+       rem -= need;
+       if (state->vertex_offset == 0) {
+               if ((sna->kgem.batch[sna->kgem.nbatch-1] & ~0xffff) ==
+                   (PRIM3D_INLINE | PRIM3D_RECTLIST)) {
+                       uint32_t *b = &sna->kgem.batch[sna->kgem.nbatch-1];
+                       sna->render.vertex_index = 1 + (*b & 0xffff);
+                       *b = PRIM3D_INLINE | PRIM3D_RECTLIST;
+                       state->vertex_offset = sna->kgem.nbatch - 1;
+                       assert(!op->need_magic_ca_pass);
+               } else {
+                       state->vertex_offset = sna->kgem.nbatch;
+                       BATCH(PRIM3D_INLINE | PRIM3D_RECTLIST);
+               }
+       }
+
+       if (want > 1 && want * size > rem)
+               want = rem / size;
+
+       assert(want);
+       sna->render.vertex_index += want*op->floats_per_rect;
+       return want;
+}
+
+fastcall static void
+gen2_render_composite_blt(struct sna *sna,
+                         const struct sna_composite_op *op,
+                         const struct sna_composite_rectangles *r)
+{
+       if (!gen2_get_rectangles(sna, op, 1)) {
+               gen2_emit_composite_state(sna, op);
+               gen2_get_rectangles(sna, op, 1);
+       }
+
+       op->prim_emit(sna, op, r);
+}
+
+fastcall static void
+gen2_render_composite_box(struct sna *sna,
+                         const struct sna_composite_op *op,
+                         const BoxRec *box)
+{
+       struct sna_composite_rectangles r;
+
+       if (!gen2_get_rectangles(sna, op, 1)) {
+               gen2_emit_composite_state(sna, op);
+               gen2_get_rectangles(sna, op, 1);
+       }
+
+       DBG(("  %s: (%d, %d) x (%d, %d)\n", __FUNCTION__,
+            box->x1, box->y1,
+            box->x2 - box->x1,
+            box->y2 - box->y1));
+
+       r.dst.x  = box->x1; r.dst.y  = box->y1;
+       r.width = box->x2 - box->x1;
+       r.height = box->y2 - box->y1;
+       r.src = r.mask = r.dst;
+
+       op->prim_emit(sna, op, &r);
+}
+
+static void
+gen2_render_composite_boxes(struct sna *sna,
+                           const struct sna_composite_op *op,
+                           const BoxRec *box, int nbox)
+{
+       do {
+               int nbox_this_time;
+
+               nbox_this_time = gen2_get_rectangles(sna, op, nbox);
+               if (nbox_this_time == 0) {
+                       gen2_emit_composite_state(sna, op);
+                       nbox_this_time = gen2_get_rectangles(sna, op, nbox);
+               }
+               nbox -= nbox_this_time;
+
+               do {
+                       struct sna_composite_rectangles r;
+
+                       DBG(("  %s: (%d, %d) x (%d, %d)\n", __FUNCTION__,
+                            box->x1, box->y1,
+                            box->x2 - box->x1,
+                            box->y2 - box->y1));
+
+                       r.dst.x  = box->x1; r.dst.y  = box->y1;
+                       r.width = box->x2 - box->x1;
+                       r.height = box->y2 - box->y1;
+                       r.src = r.mask = r.dst;
+
+                       op->prim_emit(sna, op, &r);
+                       box++;
+               } while (--nbox_this_time);
+       } while (nbox);
+}
+
+static void gen2_render_composite_done(struct sna *sna,
+                                      const struct sna_composite_op *op)
+{
+       gen2_vertex_flush(sna, op);
+
+       if (op->mask.bo)
+               kgem_bo_destroy(&sna->kgem, op->mask.bo);
+       if (op->src.bo)
+               kgem_bo_destroy(&sna->kgem, op->src.bo);
+       sna_render_composite_redirect_done(sna, op);
+}
+
+static bool
+gen2_composite_solid_init(struct sna *sna,
+                         struct sna_composite_channel *channel,
+                         uint32_t color)
+{
+       channel->filter = PictFilterNearest;
+       channel->repeat = RepeatNormal;
+       channel->is_solid  = true;
+       channel->width  = 1;
+       channel->height = 1;
+       channel->pict_format = PICT_a8r8g8b8;
+
+       channel->bo = NULL;
+       channel->u.gen2.pixel = color;
+
+       channel->scale[0]  = channel->scale[1]  = 1;
+       channel->offset[0] = channel->offset[1] = 0;
+       return true;
+}
+
+#define xFixedToDouble(f) pixman_fixed_to_double(f)
+
+static bool
+gen2_composite_linear_init(struct sna *sna,
+                          PicturePtr picture,
+                          struct sna_composite_channel *channel,
+                          int x, int y,
+                          int w, int h,
+                          int dst_x, int dst_y)
+{
+       PictLinearGradient *linear =
+               (PictLinearGradient *)picture->pSourcePict;
+       pixman_fixed_t tx, ty;
+       float x0, y0, sf;
+       float dx, dy;
+
+       DBG(("%s: p1=(%f, %f), p2=(%f, %f)\n",
+            __FUNCTION__,
+            xFixedToDouble(linear->p1.x), xFixedToDouble(linear->p1.y),
+            xFixedToDouble(linear->p2.x), xFixedToDouble(linear->p2.y)));
+
+       if (linear->p2.x == linear->p1.x && linear->p2.y == linear->p1.y)
+               return 0;
+
+       if (!sna_transform_is_affine(picture->transform)) {
+               DBG(("%s: fallback due to projective transform\n",
+                    __FUNCTION__));
+               return sna_render_picture_fixup(sna, picture, channel,
+                                               x, y, w, h, dst_x, dst_y);
+       }
+
+       channel->bo = sna_render_get_gradient(sna, (PictGradient *)linear);
+       if (!channel->bo)
+               return 0;
+
+       channel->filter = PictFilterNearest;
+       channel->repeat = picture->repeat ? picture->repeatType : RepeatNone;
+       channel->is_linear = true;
+       channel->width  = channel->bo->pitch / 4;
+       channel->height = 1;
+       channel->pict_format = PICT_a8r8g8b8;
+
+       channel->scale[0]  = channel->scale[1]  = 1;
+       channel->offset[0] = channel->offset[1] = 0;
+
+       if (sna_transform_is_translation(picture->transform, &tx, &ty)) {
+               dx = xFixedToDouble(linear->p2.x - linear->p1.x);
+               dy = xFixedToDouble(linear->p2.y - linear->p1.y);
+
+               x0 = xFixedToDouble(linear->p1.x);
+               y0 = xFixedToDouble(linear->p1.y);
+
+               if (tx | ty) {
+                       x0 -= pixman_fixed_to_double(tx);
+                       y0 -= pixman_fixed_to_double(ty);
+               }
+       } else {
+               struct pixman_f_vector p1, p2;
+               struct pixman_f_transform m, inv;
+
+               pixman_f_transform_from_pixman_transform(&m, picture->transform);
+               DBG(("%s: transform = [%f %f %f, %f %f %f, %f %f %f]\n",
+                    __FUNCTION__,
+                    m.m[0][0], m.m[0][1], m.m[0][2],
+                    m.m[1][0], m.m[1][1], m.m[1][2],
+                    m.m[2][0], m.m[2][1], m.m[2][2]));
+               if (!pixman_f_transform_invert(&inv, &m))
+                       return 0;
+
+               p1.v[0] = pixman_fixed_to_double(linear->p1.x);
+               p1.v[1] = pixman_fixed_to_double(linear->p1.y);
+               p1.v[2] = 1.;
+               pixman_f_transform_point(&inv, &p1);
+
+               p2.v[0] = pixman_fixed_to_double(linear->p2.x);
+               p2.v[1] = pixman_fixed_to_double(linear->p2.y);
+               p2.v[2] = 1.;
+               pixman_f_transform_point(&inv, &p2);
+
+               DBG(("%s: untransformed: p1=(%f, %f, %f), p2=(%f, %f, %f)\n",
+                    __FUNCTION__,
+                    p1.v[0], p1.v[1], p1.v[2],
+                    p2.v[0], p2.v[1], p2.v[2]));
+
+               dx = p2.v[0] - p1.v[0];
+               dy = p2.v[1] - p1.v[1];
+
+               x0 = p1.v[0];
+               y0 = p1.v[1];
+       }
+
+       sf = dx*dx + dy*dy;
+       dx /= sf;
+       dy /= sf;
+
+       channel->u.gen2.linear_dx = dx;
+       channel->u.gen2.linear_dy = dy;
+       channel->u.gen2.linear_offset = -dx*(x0+dst_x-x) + -dy*(y0+dst_y-y);
+
+       DBG(("%s: dx=%f, dy=%f, offset=%f\n",
+            __FUNCTION__, dx, dy, channel->u.gen2.linear_offset));
+
+       return channel->bo != NULL;
+}
+
+static bool source_is_covered(PicturePtr picture,
+                             int x, int y,
+                             int width, int height)
+{
+       int x1, y1, x2, y2;
+
+       if (picture->repeat && picture->repeatType != RepeatNone)
+               return true;
+
+       if (picture->pDrawable == NULL)
+               return false;
+
+       if (picture->transform) {
+               pixman_box16_t sample;
+
+               sample.x1 = x;
+               sample.y1 = y;
+               sample.x2 = x + width;
+               sample.y2 = y + height;
+
+               pixman_transform_bounds(picture->transform, &sample);
+
+               x1 = sample.x1;
+               x2 = sample.x2;
+               y1 = sample.y1;
+               y2 = sample.y2;
+       } else {
+               x1 = x;
+               y1 = y;
+               x2 = x + width;
+               y2 = y + height;
+       }
+
+       return
+               x1 >= 0 && y1 >= 0 &&
+               x2 <= picture->pDrawable->width &&
+               y2 <= picture->pDrawable->height;
+}
+
+static bool
+gen2_check_card_format(struct sna *sna,
+                      PicturePtr picture,
+                      struct sna_composite_channel *channel,
+                      int x, int y, int w, int h)
+{
+       uint32_t format = picture->format;
+       unsigned int i;
+
+       for (i = 0; i < ARRAY_SIZE(i8xx_tex_formats); i++) {
+               if (i8xx_tex_formats[i].fmt == format)
+                       return true;
+       }
+
+       for (i = 0; i < ARRAY_SIZE(i85x_tex_formats); i++) {
+               if (i85x_tex_formats[i].fmt == format) {
+                       if (sna->kgem.gen >= 21)
+                               return true;
+
+                       if (source_is_covered(picture, x, y, w,h)) {
+                               channel->is_opaque = true;
+                               return true;
+                       }
+
+                       return false;
+               }
+       }
+
+       return false;
+}
+
+static int
+gen2_composite_picture(struct sna *sna,
+                      PicturePtr picture,
+                      struct sna_composite_channel *channel,
+                      int x, int y,
+                      int w, int h,
+                      int dst_x, int dst_y,
+                      bool precise)
+{
+       PixmapPtr pixmap;
+       uint32_t color;
+       int16_t dx, dy;
+
+       DBG(("%s: (%d, %d)x(%d, %d), dst=(%d, %d)\n",
+            __FUNCTION__, x, y, w, h, dst_x, dst_y));
+
+       channel->is_solid = false;
+       channel->is_linear = false;
+       channel->is_opaque = false;
+       channel->is_affine = true;
+       channel->transform = NULL;
+
+       if (sna_picture_is_solid(picture, &color))
+               return gen2_composite_solid_init(sna, channel, color);
+
+       if (!gen2_check_repeat(picture)) {
+               DBG(("%s -- fallback, unhandled repeat %d\n",
+                    __FUNCTION__, picture->repeat));
+               return sna_render_picture_fixup(sna, picture, channel,
+                                               x, y, w, h, dst_x, dst_y);
+       }
+
+       if (!gen2_check_filter(picture)) {
+               DBG(("%s -- fallback, unhandled filter %d\n",
+                    __FUNCTION__, picture->filter));
+               return sna_render_picture_fixup(sna, picture, channel,
+                                               x, y, w, h, dst_x, dst_y);
+       }
+
+       if (picture->pDrawable == NULL) {
+               int ret;
+
+               if (picture->pSourcePict->type == SourcePictTypeLinear)
+                       return gen2_composite_linear_init(sna, picture, channel,
+                                                         x, y,
+                                                         w, h,
+                                                         dst_x, dst_y);
+
+               DBG(("%s -- fallback, unhandled source %d\n",
+                    __FUNCTION__, picture->pSourcePict->type));
+               ret = -1;
+               if (!precise)
+                       ret = sna_render_picture_approximate_gradient(sna, picture, channel,
+                                                                     x, y, w, h, dst_x, dst_y);
+               if (ret == -1)
+                       ret = sna_render_picture_fixup(sna, picture, channel,
+                                                      x, y, w, h, dst_x, dst_y);
+               return ret;
+       }
+
+       if (picture->alphaMap) {
+               DBG(("%s -- fallback, alphamap\n", __FUNCTION__));
+               return sna_render_picture_fixup(sna, picture, channel,
+                                               x, y, w, h, dst_x, dst_y);
+       }
+
+       channel->repeat = picture->repeat ? picture->repeatType : RepeatNone;
+       channel->filter = picture->filter;
+
+       pixmap = get_drawable_pixmap(picture->pDrawable);
+       get_drawable_deltas(picture->pDrawable, pixmap, &dx, &dy);
+
+       x += dx + picture->pDrawable->x;
+       y += dy + picture->pDrawable->y;
+
+       channel->is_affine = sna_transform_is_affine(picture->transform);
+       if (sna_transform_is_integer_translation(picture->transform, &dx, &dy)) {
+               DBG(("%s: integer translation (%d, %d), removing\n",
+                    __FUNCTION__, dx, dy));
+               x += dx;
+               y += dy;
+               channel->transform = NULL;
+               channel->filter = PictFilterNearest;
+       } else
+               channel->transform = picture->transform;
+
+       if (!gen2_check_card_format(sna, picture, channel, x,  y, w ,h))
+               return sna_render_picture_convert(sna, picture, channel, pixmap,
+                                                 x, y, w, h, dst_x, dst_y);
+
+       channel->pict_format = picture->format;
+       if (too_large(pixmap->drawable.width, pixmap->drawable.height))
+               return sna_render_picture_extract(sna, picture, channel,
+                                                 x, y, w, h, dst_x, dst_y);
+
+       return sna_render_pixmap_bo(sna, channel, pixmap,
+                                   x, y, w, h, dst_x, dst_y);
+}
+
+static bool
+gen2_composite_set_target(struct sna *sna,
+                         struct sna_composite_op *op,
+                         PicturePtr dst)
+{
+       struct sna_pixmap *priv;
+
+       op->dst.pixmap = get_drawable_pixmap(dst->pDrawable);
+       op->dst.format = dst->format;
+       op->dst.width  = op->dst.pixmap->drawable.width;
+       op->dst.height = op->dst.pixmap->drawable.height;
+
+       priv = sna_pixmap_force_to_gpu(op->dst.pixmap, MOVE_WRITE | MOVE_READ);
+       if (priv == NULL)
+               return false;
+
+       if (priv->gpu_bo->pitch < 8) {
+               struct kgem_bo *bo;
+
+               if (priv->pinned)
+                       return false;
+
+               bo = kgem_replace_bo(&sna->kgem, priv->gpu_bo,
+                                    op->dst.width, op->dst.height, 8,
+                                    op->dst.pixmap->drawable.bitsPerPixel);
+               if (bo == NULL)
+                       return false;
+
+               kgem_bo_destroy(&sna->kgem, priv->gpu_bo);
+               priv->gpu_bo = bo;
+       }
+
+       op->dst.bo = priv->gpu_bo;
+       op->damage = &priv->gpu_damage;
+       if (sna_damage_is_all(&priv->gpu_damage, op->dst.width, op->dst.height))
+               op->damage = NULL;
+
+       get_drawable_deltas(dst->pDrawable, op->dst.pixmap,
+                           &op->dst.x, &op->dst.y);
+       return true;
+}
+
+static bool
+try_blt(struct sna *sna,
+       PicturePtr dst,
+       PicturePtr src,
+       int width, int height)
+{
+       uint32_t color;
+
+       if (sna->kgem.mode != KGEM_RENDER) {
+               DBG(("%s: already performing BLT\n", __FUNCTION__));
+               return true;
+       }
+
+       if (too_large(width, height)) {
+               DBG(("%s: operation too large for 3D pipe (%d, %d)\n",
+                    __FUNCTION__, width, height));
+               return true;
+       }
+
+       if (too_large(dst->pDrawable->width, dst->pDrawable->height)) {
+               DBG(("%s: target too large for 3D pipe (%d, %d)\n",
+                    __FUNCTION__,
+                    dst->pDrawable->width, dst->pDrawable->height));
+               return true;
+       }
+
+       /* If it is a solid, try to use the BLT paths */
+       if (sna_picture_is_solid(src, &color))
+               return true;
+
+       if (!src->pDrawable)
+               return false;
+
+       if (too_large(src->pDrawable->width, src->pDrawable->height)) {
+               DBG(("%s: source too large for 3D pipe (%d, %d)\n",
+                    __FUNCTION__,
+                    src->pDrawable->width, src->pDrawable->height));
+               return true;
+       }
+
+       return !is_gpu(src->pDrawable);
+}
+
+static bool
+is_unhandled_gradient(PicturePtr picture)
+{
+       if (picture->pDrawable)
+               return false;
+
+       switch (picture->pSourcePict->type) {
+       case SourcePictTypeSolidFill:
+       case SourcePictTypeLinear:
+               return false;
+       default:
+               return true;
+       }
+}
+
+static bool
+has_alphamap(PicturePtr p)
+{
+       return p->alphaMap != NULL;
+}
+
+static bool
+untransformed(PicturePtr p)
+{
+       return !p->transform || pixman_transform_is_int_translate(p->transform);
+}
+
+static bool
+need_upload(PicturePtr p)
+{
+       return p->pDrawable && unattached(p->pDrawable) && untransformed(p);
+}
+
+static bool
+source_is_busy(PixmapPtr pixmap)
+{
+       struct sna_pixmap *priv = sna_pixmap(pixmap);
+       if (priv == NULL)
+               return false;
+
+       if (priv->clear)
+               return false;
+
+       if (priv->gpu_bo && kgem_bo_is_busy(priv->gpu_bo))
+               return true;
+
+       if (priv->cpu_bo && kgem_bo_is_busy(priv->cpu_bo))
+               return true;
+
+       return priv->gpu_damage && !priv->cpu_damage;
+}
+
+static bool
+source_fallback(PicturePtr p, PixmapPtr pixmap)
+{
+       if (sna_picture_is_solid(p, NULL))
+               return false;
+
+       if (is_unhandled_gradient(p) || !gen2_check_repeat(p))
+               return true;
+
+       if (pixmap && source_is_busy(pixmap))
+               return false;
+
+       return has_alphamap(p) || !gen2_check_filter(p) || need_upload(p);
+}
+
+static bool
+gen2_composite_fallback(struct sna *sna,
+                       PicturePtr src,
+                       PicturePtr mask,
+                       PicturePtr dst)
+{
+       struct sna_pixmap *priv;
+       PixmapPtr src_pixmap;
+       PixmapPtr mask_pixmap;
+       PixmapPtr dst_pixmap;
+       bool src_fallback, mask_fallback;
+
+       if (!gen2_check_dst_format(dst->format)) {
+               DBG(("%s: unknown destination format: %d\n",
+                    __FUNCTION__, dst->format));
+               return true;
+       }
+
+       dst_pixmap = get_drawable_pixmap(dst->pDrawable);
+
+       src_pixmap = src->pDrawable ? get_drawable_pixmap(src->pDrawable) : NULL;
+       src_fallback = source_fallback(src, src_pixmap);
+
+       if (mask) {
+               mask_pixmap = mask->pDrawable ? get_drawable_pixmap(mask->pDrawable) : NULL;
+               mask_fallback = source_fallback(mask, mask_pixmap);
+       } else {
+               mask_pixmap = NULL;
+               mask_fallback = NULL;
+       }
+
+       /* If we are using the destination as a source and need to
+        * readback in order to upload the source, do it all
+        * on the cpu.
+        */
+       if (src_pixmap == dst_pixmap && src_fallback) {
+               DBG(("%s: src is dst and will fallback\n",__FUNCTION__));
+               return true;
+       }
+       if (mask_pixmap == dst_pixmap && mask_fallback) {
+               DBG(("%s: mask is dst and will fallback\n",__FUNCTION__));
+               return true;
+       }
+
+       /* If anything is on the GPU, push everything out to the GPU */
+       priv = sna_pixmap(dst_pixmap);
+       if (priv && priv->gpu_damage && !priv->clear) {
+               DBG(("%s: dst is already on the GPU, try to use GPU\n",
+                    __FUNCTION__));
+               return false;
+       }
+
+       if (src_pixmap && !src_fallback) {
+               DBG(("%s: src is already on the GPU, try to use GPU\n",
+                    __FUNCTION__));
+               return false;
+       }
+       if (mask_pixmap && !mask_fallback) {
+               DBG(("%s: mask is already on the GPU, try to use GPU\n",
+                    __FUNCTION__));
+               return false;
+       }
+
+       /* However if the dst is not on the GPU and we need to
+        * render one of the sources using the CPU, we may
+        * as well do the entire operation in place onthe CPU.
+        */
+       if (src_fallback) {
+               DBG(("%s: dst is on the CPU and src will fallback\n",
+                    __FUNCTION__));
+               return true;
+       }
+
+       if (mask && mask_fallback) {
+               DBG(("%s: dst is on the CPU and mask will fallback\n",
+                    __FUNCTION__));
+               return true;
+       }
+
+       if (too_large(dst_pixmap->drawable.width,
+                     dst_pixmap->drawable.height) &&
+           (priv == NULL || DAMAGE_IS_ALL(priv->cpu_damage))) {
+               DBG(("%s: dst is on the CPU and too large\n", __FUNCTION__));
+               return true;
+       }
+
+       DBG(("%s: dst is not on the GPU and the operation should not fallback\n",
+            __FUNCTION__));
+       return false;
+}
+
+static int
+reuse_source(struct sna *sna,
+            PicturePtr src, struct sna_composite_channel *sc, int src_x, int src_y,
+            PicturePtr mask, struct sna_composite_channel *mc, int msk_x, int msk_y)
+{
+       uint32_t color;
+
+       if (src_x != msk_x || src_y != msk_y)
+               return false;
+
+       if (src == mask) {
+               DBG(("%s: mask is source\n", __FUNCTION__));
+               *mc = *sc;
+               mc->bo = kgem_bo_reference(mc->bo);
+               return true;
+       }
+
+       if (sna_picture_is_solid(mask, &color))
+               return gen2_composite_solid_init(sna, mc, color);
+
+       if (sc->is_solid)
+               return false;
+
+       if (src->pDrawable == NULL || mask->pDrawable != src->pDrawable)
+               return false;
+
+       DBG(("%s: mask reuses source drawable\n", __FUNCTION__));
+
+       if (!sna_transform_equal(src->transform, mask->transform))
+               return false;
+
+       if (!sna_picture_alphamap_equal(src, mask))
+               return false;
+
+       if (!gen2_check_repeat(mask))
+               return false;
+
+       if (!gen2_check_filter(mask))
+               return false;
+
+       if (!gen2_check_format(sna, mask))
+               return false;
+
+       DBG(("%s: reusing source channel for mask with a twist\n",
+            __FUNCTION__));
+
+       *mc = *sc;
+       mc->repeat = mask->repeat ? mask->repeatType : RepeatNone;
+       mc->filter = mask->filter;
+       mc->pict_format = mask->format;
+       mc->bo = kgem_bo_reference(mc->bo);
+       return true;
+}
+
+static bool
+gen2_render_composite(struct sna *sna,
+                     uint8_t op,
+                     PicturePtr src,
+                     PicturePtr mask,
+                     PicturePtr dst,
+                     int16_t src_x,  int16_t src_y,
+                     int16_t mask_x, int16_t mask_y,
+                     int16_t dst_x,  int16_t dst_y,
+                     int16_t width,  int16_t height,
+                     struct sna_composite_op *tmp)
+{
+       DBG(("%s()\n", __FUNCTION__));
+
+       if (op >= ARRAY_SIZE(gen2_blend_op)) {
+               DBG(("%s: fallback due to unhandled blend op: %d\n",
+                    __FUNCTION__, op));
+               return false;
+       }
+
+#if NO_COMPOSITE
+       if (mask)
+               return false;
+
+       return sna_blt_composite(sna, op,
+                                src, dst,
+                                src_x, src_y,
+                                dst_x, dst_y,
+                                width, height, tmp, true);
+#endif
+
+       /* Try to use the BLT engine unless it implies a
+        * 3D -> 2D context switch.
+        */
+       if (mask == NULL &&
+           try_blt(sna, dst, src, width, height) &&
+           sna_blt_composite(sna,
+                             op, src, dst,
+                             src_x, src_y,
+                             dst_x, dst_y,
+                             width, height,
+                             tmp, false))
+               return true;
+
+       if (gen2_composite_fallback(sna, src, mask, dst))
+               return false;
+
+       if (need_tiling(sna, width, height))
+               return sna_tiling_composite(op, src, mask, dst,
+                                           src_x,  src_y,
+                                           mask_x, mask_y,
+                                           dst_x,  dst_y,
+                                           width,  height,
+                                           tmp);
+
+       if (!gen2_composite_set_target(sna, tmp, dst)) {
+               DBG(("%s: unable to set render target\n",
+                    __FUNCTION__));
+               return false;
+       }
+
+       sna_render_reduce_damage(tmp, dst_x, dst_y, width, height);
+
+       tmp->op = op;
+       if (too_large(tmp->dst.width, tmp->dst.height) ||
+           tmp->dst.bo->pitch > MAX_3D_PITCH) {
+               if (!sna_render_composite_redirect(sna, tmp,
+                                                  dst_x, dst_y, width, height))
+                       return false;
+       }
+
+       switch (gen2_composite_picture(sna, src, &tmp->src,
+                                      src_x, src_y,
+                                      width, height,
+                                      dst_x, dst_y,
+                                      dst->polyMode == PolyModePrecise)) {
+       case -1:
+               goto cleanup_dst;
+       case 0:
+               gen2_composite_solid_init(sna, &tmp->src, 0);
+               break;
+       case 1:
+               if (mask == NULL && tmp->src.bo &&
+                   sna_blt_composite__convert(sna,
+                                              dst_x, dst_y, width, height,
+                                              tmp))
+                       return true;
+               break;
+       }
+
+       if (mask) {
+               if (!reuse_source(sna,
+                                 src, &tmp->src, src_x, src_y,
+                                 mask, &tmp->mask, mask_x, mask_y)) {
+                       switch (gen2_composite_picture(sna, mask, &tmp->mask,
+                                                      mask_x, mask_y,
+                                                      width,  height,
+                                                      dst_x,  dst_y,
+                                                      dst->polyMode == PolyModePrecise)) {
+                       case -1:
+                               goto cleanup_src;
+                       case 0:
+                               gen2_composite_solid_init(sna, &tmp->mask, 0);
+                       case 1:
+                               break;
+                       }
+               }
+
+               if (mask->componentAlpha && PICT_FORMAT_RGB(mask->format)) {
+                       /* Check if it's component alpha that relies on a source alpha
+                        * and on the source value.  We can only get one of those
+                        * into the single source value that we get to blend with.
+                        */
+                       tmp->has_component_alpha = true;
+                       if (gen2_blend_op[op].src_alpha &&
+                           (gen2_blend_op[op].src_blend != BLENDFACTOR_ZERO)) {
+                               if (op != PictOpOver)
+                                       return false;
+
+                               tmp->need_magic_ca_pass = true;
+                               tmp->op = PictOpOutReverse;
+                       }
+               }
+
+               /* convert solid to a texture (pure convenience) */
+               if (tmp->mask.is_solid)
+                       tmp->mask.bo = sna_render_get_solid(sna, tmp->mask.u.gen2.pixel);
+       }
+
+       tmp->floats_per_vertex = 2;
+       if (!tmp->src.is_solid)
+               tmp->floats_per_vertex += tmp->src.is_affine ? 2 : 3;
+       if (tmp->mask.bo)
+               tmp->floats_per_vertex += tmp->mask.is_affine ? 2 : 3;
+       tmp->floats_per_rect = 3*tmp->floats_per_vertex;
+
+       tmp->prim_emit = gen2_emit_composite_primitive;
+       if (tmp->mask.bo) {
+               if (tmp->mask.transform == NULL) {
+                       if (tmp->src.is_solid)
+                               tmp->prim_emit = gen2_emit_composite_primitive_constant_identity_mask;
+               }
+       } else {
+               if (tmp->src.is_solid)
+                       tmp->prim_emit = gen2_emit_composite_primitive_constant;
+               else if (tmp->src.is_linear)
+                       tmp->prim_emit = gen2_emit_composite_primitive_linear;
+               else if (tmp->src.transform == NULL)
+                       tmp->prim_emit = gen2_emit_composite_primitive_identity;
+               else if (tmp->src.is_affine)
+                       tmp->prim_emit = gen2_emit_composite_primitive_affine;
+       }
+
+       tmp->blt   = gen2_render_composite_blt;
+       tmp->box   = gen2_render_composite_box;
+       tmp->boxes = gen2_render_composite_boxes;
+       tmp->done  = gen2_render_composite_done;
+
+       if (!kgem_check_bo(&sna->kgem,
+                          tmp->dst.bo, tmp->src.bo, tmp->mask.bo,
+                          NULL)) {
+               kgem_submit(&sna->kgem);
+               if (!kgem_check_bo(&sna->kgem,
+                                  tmp->dst.bo, tmp->src.bo, tmp->mask.bo,
+                                  NULL))
+                       goto cleanup_mask;
+       }
+
+       gen2_emit_composite_state(sna, tmp);
+       return true;
+
+cleanup_mask:
+       if (tmp->mask.bo)
+               kgem_bo_destroy(&sna->kgem, tmp->mask.bo);
+cleanup_src:
+       if (tmp->src.bo)
+               kgem_bo_destroy(&sna->kgem, tmp->src.bo);
+cleanup_dst:
+       if (tmp->redirect.real_bo)
+               kgem_bo_destroy(&sna->kgem, tmp->dst.bo);
+       return false;
+}
+
+fastcall static void
+gen2_emit_composite_spans_primitive_constant(struct sna *sna,
+                                            const struct sna_composite_spans_op *op,
+                                            const BoxRec *box,
+                                            float opacity)
+{
+       float *v = (float *)sna->kgem.batch + sna->kgem.nbatch;
+       uint32_t alpha = (uint8_t)(255 * opacity) << 24;
+       sna->kgem.nbatch += 9;
+
+       v[0] = op->base.dst.x + box->x2;
+       v[1] = op->base.dst.y + box->y2;
+       *((uint32_t *)v + 2) = alpha;
+
+       v[3] = op->base.dst.x + box->x1;
+       v[4] = v[1];
+       *((uint32_t *)v + 5) = alpha;
+
+       v[6] = v[3];
+       v[7] = op->base.dst.y + box->y1;
+       *((uint32_t *)v + 8) = alpha;
+}
+
+fastcall static void
+gen2_emit_composite_spans_primitive_linear(struct sna *sna,
+                                            const struct sna_composite_spans_op *op,
+                                            const BoxRec *box,
+                                            float opacity)
+{
+       union {
+               float f;
+               uint32_t u;
+       } alpha;
+
+       alpha.u = (uint8_t)(255 * opacity) << 24;
+
+       gen2_emit_composite_dstcoord(sna,
+                                    op->base.dst.x + box->x2,
+                                    op->base.dst.y + box->y2);
+       VERTEX(alpha.f);
+       gen2_emit_composite_linear(sna, &op->base.src, box->x2, box->y2);
+
+       gen2_emit_composite_dstcoord(sna,
+                                    op->base.dst.x + box->x1,
+                                    op->base.dst.y + box->y2);
+       VERTEX(alpha.f);
+       gen2_emit_composite_linear(sna, &op->base.src, box->x1, box->y2);
+
+       gen2_emit_composite_dstcoord(sna,
+                                    op->base.dst.x + box->x1,
+                                    op->base.dst.y + box->y1);
+       VERTEX(alpha.f);
+       gen2_emit_composite_linear(sna, &op->base.src, box->x1, box->y1);
+}
+
+fastcall static void
+gen2_emit_composite_spans_primitive_identity_source(struct sna *sna,
+                                                   const struct sna_composite_spans_op *op,
+                                                   const BoxRec *box,
+                                                   float opacity)
+{
+       float *v = (float *)sna->kgem.batch + sna->kgem.nbatch;
+       uint32_t alpha = (uint8_t)(255 * opacity) << 24;
+       sna->kgem.nbatch += 15;
+
+       v[0] = op->base.dst.x + box->x2;
+       v[1] = op->base.dst.y + box->y2;
+       *((uint32_t *)v + 2) = alpha;
+       v[3] = (op->base.src.offset[0] + box->x2) * op->base.src.scale[0];
+       v[4] = (op->base.src.offset[1] + box->y2) * op->base.src.scale[1];
+
+       v[5] = op->base.dst.x + box->x1;
+       v[6] = v[1];
+       *((uint32_t *)v + 7) = alpha;
+       v[8] = (op->base.src.offset[0] + box->x1) * op->base.src.scale[0];
+       v[9] = v[4];
+
+       v[10] = v[5];
+       v[11] = op->base.dst.y + box->y1;
+       *((uint32_t *)v + 12) = alpha;
+       v[13] = v[8];
+       v[14] = (op->base.src.offset[1] + box->y1) * op->base.src.scale[1];
+}
+
+fastcall static void
+gen2_emit_composite_spans_primitive_affine_source(struct sna *sna,
+                                                 const struct sna_composite_spans_op *op,
+                                                 const BoxRec *box,
+                                                 float opacity)
+{
+       PictTransform *transform = op->base.src.transform;
+       uint32_t alpha = (uint8_t)(255 * opacity) << 24;
+       float x, y, *v;
+       
+       v = (float *)sna->kgem.batch + sna->kgem.nbatch;
+       sna->kgem.nbatch += 15;
+
+       v[0]  = op->base.dst.x + box->x2;
+       v[6]  = v[1] = op->base.dst.y + box->y2;
+       v[10] = v[5] = op->base.dst.x + box->x1;
+       v[11] = op->base.dst.y + box->y1;
+       *((uint32_t *)v + 2) = alpha;
+       *((uint32_t *)v + 7) = alpha;
+       *((uint32_t *)v + 12) = alpha;
+
+       _sna_get_transformed_coordinates((int)op->base.src.offset[0] + box->x2,
+                                        (int)op->base.src.offset[1] + box->y2,
+                                        transform,
+                                        &x, &y);
+       v[3] = x * op->base.src.scale[0];
+       v[4] = y * op->base.src.scale[1];
+
+       _sna_get_transformed_coordinates((int)op->base.src.offset[0] + box->x1,
+                                        (int)op->base.src.offset[1] + box->y2,
+                                        transform,
+                                        &x, &y);
+       v[8] = x * op->base.src.scale[0];
+       v[9] = y * op->base.src.scale[1];
+
+       _sna_get_transformed_coordinates((int)op->base.src.offset[0] + box->x1,
+                                        (int)op->base.src.offset[1] + box->y1,
+                                        transform,
+                                        &x, &y);
+       v[13] = x * op->base.src.scale[0];
+       v[14] = y * op->base.src.scale[1];
+}
+
+static void
+gen2_emit_composite_spans_vertex(struct sna *sna,
+                                const struct sna_composite_spans_op *op,
+                                int16_t x, int16_t y,
+                                float opacity)
+{
+       gen2_emit_composite_dstcoord(sna, x + op->base.dst.x, y + op->base.dst.y);
+       BATCH((uint8_t)(opacity * 255) << 24);
+       assert(!op->base.src.is_solid);
+       if (op->base.src.is_linear)
+               gen2_emit_composite_linear(sna, &op->base.src, x, y);
+       else
+               gen2_emit_composite_texcoord(sna, &op->base.src, x, y);
+}
+
+fastcall static void
+gen2_emit_composite_spans_primitive(struct sna *sna,
+                                   const struct sna_composite_spans_op *op,
+                                   const BoxRec *box,
+                                   float opacity)
+{
+       gen2_emit_composite_spans_vertex(sna, op, box->x2, box->y2, opacity);
+       gen2_emit_composite_spans_vertex(sna, op, box->x1, box->y2, opacity);
+       gen2_emit_composite_spans_vertex(sna, op, box->x1, box->y1, opacity);
+}
+
+static void
+gen2_emit_spans_pipeline(struct sna *sna,
+                        const struct sna_composite_spans_op *op)
+{
+       uint32_t cblend, ablend;
+       uint32_t unwind;
+
+       cblend =
+               TB0C_LAST_STAGE | TB0C_RESULT_SCALE_1X | TB0C_OP_MODULATE |
+               TB0C_ARG1_SEL_DIFFUSE | TB0C_ARG1_REPLICATE_ALPHA |
+               TB0C_OUTPUT_WRITE_CURRENT;
+       ablend =
+               TB0A_RESULT_SCALE_1X | TB0A_OP_MODULATE |
+               TB0A_ARG1_SEL_DIFFUSE |
+               TB0A_OUTPUT_WRITE_CURRENT;
+
+       if (op->base.src.is_solid) {
+               ablend |= TB0A_ARG2_SEL_SPECULAR;
+               cblend |= TB0C_ARG2_SEL_SPECULAR;
+               if (op->base.dst.format == PICT_a8)
+                       cblend |= TB0C_ARG2_REPLICATE_ALPHA;
+       } else if (op->base.dst.format == PICT_a8) {
+               ablend |= TB0A_ARG2_SEL_TEXEL0;
+               cblend |= TB0C_ARG2_SEL_TEXEL0 | TB0C_ARG2_REPLICATE_ALPHA;
+       } else {
+               if (PICT_FORMAT_RGB(op->base.src.pict_format) != 0)
+                       cblend |= TB0C_ARG2_SEL_TEXEL0;
+               else
+                       cblend |= TB0C_ARG2_SEL_ONE | TB0C_ARG2_INVERT;
+
+               if (op->base.src.is_opaque)
+                       ablend |= TB0A_ARG2_SEL_ONE;
+               else
+                       ablend |= TB0A_ARG2_SEL_TEXEL0;
+       }
+
+       unwind = sna->kgem.nbatch;
+       BATCH(_3DSTATE_LOAD_STATE_IMMEDIATE_2 |
+             LOAD_TEXTURE_BLEND_STAGE(0) | 1);
+       BATCH(cblend);
+       BATCH(ablend);
+       if (memcmp(sna->kgem.batch + sna->render_state.gen2.ls2 + 1,
+                  sna->kgem.batch + unwind + 1,
+                  2 * sizeof(uint32_t)) == 0)
+               sna->kgem.nbatch = unwind;
+       else
+               sna->render_state.gen2.ls2 = unwind;
+}
+
+static void gen2_emit_composite_spans_state(struct sna *sna,
+                                           const struct sna_composite_spans_op *op)
+{
+       uint32_t unwind;
+
+       gen2_get_batch(sna);
+       gen2_emit_target(sna, &op->base);
+
+       unwind = sna->kgem.nbatch;
+       BATCH(_3DSTATE_LOAD_STATE_IMMEDIATE_1 |
+             I1_LOAD_S(2) | I1_LOAD_S(3) | I1_LOAD_S(8) | 2);
+       BATCH(!op->base.src.is_solid << 12);
+       BATCH(S3_CULLMODE_NONE | S3_VERTEXHAS_XY | S3_DIFFUSE_PRESENT);
+       BATCH(gen2_get_blend_cntl(op->base.op, false, op->base.dst.format));
+       if (memcmp(sna->kgem.batch + sna->render_state.gen2.ls1 + 1,
+                  sna->kgem.batch + unwind + 1,
+                  3 * sizeof(uint32_t)) == 0)
+               sna->kgem.nbatch = unwind;
+       else
+               sna->render_state.gen2.ls1 = unwind;
+
+       gen2_disable_logic_op(sna);
+       gen2_emit_spans_pipeline(sna, op);
+
+       if (op->base.src.is_solid) {
+               if (op->base.src.u.gen2.pixel != sna->render_state.gen2.specular) {
+                       BATCH(_3DSTATE_DFLT_SPECULAR_CMD);
+                       BATCH(op->base.src.u.gen2.pixel);
+                       sna->render_state.gen2.specular = op->base.src.u.gen2.pixel;
+               }
+       } else {
+               uint32_t v =_3DSTATE_VERTEX_FORMAT_2_CMD |
+                       (op->base.src.is_affine ? TEXCOORDFMT_2D : TEXCOORDFMT_3D);
+               if (sna->render_state.gen2.vft != v) {
+                       BATCH(v);
+                       sna->render_state.gen2.vft = v;
+               }
+               gen2_emit_texture(sna, &op->base.src, 0);
+       }
+}
+
+fastcall static void
+gen2_render_composite_spans_box(struct sna *sna,
+                               const struct sna_composite_spans_op *op,
+                               const BoxRec *box, float opacity)
+{
+       DBG(("%s: src=+(%d, %d), opacity=%f, dst=+(%d, %d), box=(%d, %d) x (%d, %d)\n",
+            __FUNCTION__,
+            op->base.src.offset[0], op->base.src.offset[1],
+            opacity,
+            op->base.dst.x, op->base.dst.y,
+            box->x1, box->y1,
+            box->x2 - box->x1,
+            box->y2 - box->y1));
+
+       if (gen2_get_rectangles(sna, &op->base, 1) == 0) {
+               gen2_emit_composite_spans_state(sna, op);
+               gen2_get_rectangles(sna, &op->base, 1);
+       }
+
+       op->prim_emit(sna, op, box, opacity);
+}
+
+static void
+gen2_render_composite_spans_boxes(struct sna *sna,
+                                 const struct sna_composite_spans_op *op,
+                                 const BoxRec *box, int nbox,
+                                 float opacity)
+{
+       DBG(("%s: nbox=%d, src=+(%d, %d), opacity=%f, dst=+(%d, %d)\n",
+            __FUNCTION__, nbox,
+            op->base.src.offset[0], op->base.src.offset[1],
+            opacity,
+            op->base.dst.x, op->base.dst.y));
+
+       do {
+               int nbox_this_time;
+
+               nbox_this_time = gen2_get_rectangles(sna, &op->base, nbox);
+               if (nbox_this_time == 0) {
+                       gen2_emit_composite_spans_state(sna, op);
+                       nbox_this_time = gen2_get_rectangles(sna, &op->base, nbox);
+               }
+               nbox -= nbox_this_time;
+
+               do {
+                       DBG(("  %s: (%d, %d) x (%d, %d)\n", __FUNCTION__,
+                            box->x1, box->y1,
+                            box->x2 - box->x1,
+                            box->y2 - box->y1));
+
+                       op->prim_emit(sna, op, box++, opacity);
+               } while (--nbox_this_time);
+       } while (nbox);
+}
+
+fastcall static void
+gen2_render_composite_spans_done(struct sna *sna,
+                                const struct sna_composite_spans_op *op)
+{
+       DBG(("%s()\n", __FUNCTION__));
+
+       gen2_vertex_flush(sna, &op->base);
+
+       if (op->base.src.bo)
+               kgem_bo_destroy(&sna->kgem, op->base.src.bo);
+
+       sna_render_composite_redirect_done(sna, &op->base);
+}
+
+static bool
+gen2_check_composite_spans(struct sna *sna,
+                          uint8_t op, PicturePtr src, PicturePtr dst,
+                          int16_t width, int16_t height, unsigned flags)
+{
+       if (op >= ARRAY_SIZE(gen2_blend_op))
+               return false;
+
+       if (gen2_composite_fallback(sna, src, NULL, dst))
+               return false;
+
+       if (need_tiling(sna, width, height)) {
+               if (!is_gpu(dst->pDrawable)) {
+                       DBG(("%s: fallback, tiled operation not on GPU\n",
+                            __FUNCTION__));
+                       return false;
+               }
+       }
+
+       return true;
+}
+
+static bool
+gen2_render_composite_spans(struct sna *sna,
+                           uint8_t op,
+                           PicturePtr src,
+                           PicturePtr dst,
+                           int16_t src_x,  int16_t src_y,
+                           int16_t dst_x,  int16_t dst_y,
+                           int16_t width,  int16_t height,
+                           unsigned flags,
+                           struct sna_composite_spans_op *tmp)
+{
+       DBG(("%s(src=(%d, %d), dst=(%d, %d), size=(%d, %d))\n", __FUNCTION__,
+            src_x, src_y, dst_x, dst_y, width, height));
+
+       assert(gen2_check_composite_spans(sna, op, src, dst, width, height, flags));
+       if (need_tiling(sna, width, height)) {
+               DBG(("%s: tiling, operation (%dx%d) too wide for pipeline\n",
+                    __FUNCTION__, width, height));
+               return sna_tiling_composite_spans(op, src, dst,
+                                                 src_x, src_y, dst_x, dst_y,
+                                                 width, height, flags, tmp);
+       }
+
+       if (!gen2_composite_set_target(sna, &tmp->base, dst)) {
+               DBG(("%s: unable to set render target\n",
+                    __FUNCTION__));
+               return false;
+       }
+       sna_render_reduce_damage(&tmp->base, dst_x, dst_y, width, height);
+
+       tmp->base.op = op;
+       if (too_large(tmp->base.dst.width, tmp->base.dst.height) ||
+           tmp->base.dst.bo->pitch > MAX_3D_PITCH) {
+               if (!sna_render_composite_redirect(sna, &tmp->base,
+                                                  dst_x, dst_y, width, height))
+                       return false;
+       }
+
+       switch (gen2_composite_picture(sna, src, &tmp->base.src,
+                                      src_x, src_y,
+                                      width, height,
+                                      dst_x, dst_y,
+                                      dst->polyMode == PolyModePrecise)) {
+       case -1:
+               goto cleanup_dst;
+       case 0:
+               gen2_composite_solid_init(sna, &tmp->base.src, 0);
+       case 1:
+               break;
+       }
+
+       tmp->prim_emit = gen2_emit_composite_spans_primitive;
+       tmp->base.floats_per_vertex = 3;
+       if (tmp->base.src.is_solid) {
+               tmp->prim_emit = gen2_emit_composite_spans_primitive_constant;
+       } else if (tmp->base.src.is_linear) {
+               tmp->base.floats_per_vertex += 2;
+               tmp->prim_emit = gen2_emit_composite_spans_primitive_linear;
+       } else {
+               assert(tmp->base.src.bo);
+               tmp->base.floats_per_vertex += tmp->base.src.is_affine ? 2 : 3;
+               if (tmp->base.src.transform == NULL)
+                       tmp->prim_emit = gen2_emit_composite_spans_primitive_identity_source;
+               else if (tmp->base.src.is_affine)
+                       tmp->prim_emit = gen2_emit_composite_spans_primitive_affine_source;
+       }
+       tmp->base.mask.bo = NULL;
+       tmp->base.floats_per_rect = 3*tmp->base.floats_per_vertex;
+
+       tmp->box   = gen2_render_composite_spans_box;
+       tmp->boxes = gen2_render_composite_spans_boxes;
+       tmp->done  = gen2_render_composite_spans_done;
+
+       if (!kgem_check_bo(&sna->kgem,
+                          tmp->base.dst.bo, tmp->base.src.bo,
+                          NULL)) {
+               kgem_submit(&sna->kgem);
+               if (!kgem_check_bo(&sna->kgem,
+                                  tmp->base.dst.bo, tmp->base.src.bo,
+                                  NULL))
+                       goto cleanup_src;
+       }
+
+       gen2_emit_composite_spans_state(sna, tmp);
+       return true;
+
+cleanup_src:
+       if (tmp->base.src.bo)
+               kgem_bo_destroy(&sna->kgem, tmp->base.src.bo);
+cleanup_dst:
+       if (tmp->base.redirect.real_bo)
+               kgem_bo_destroy(&sna->kgem, tmp->base.dst.bo);
+       return false;
+}
+
+static void
+gen2_emit_fill_pipeline(struct sna *sna, const struct sna_composite_op *op)
+{
+       uint32_t blend, unwind;
+
+       unwind = sna->kgem.nbatch;
+       BATCH(_3DSTATE_LOAD_STATE_IMMEDIATE_2 |
+             LOAD_TEXTURE_BLEND_STAGE(0) | 1);
+
+       blend = TB0C_LAST_STAGE | TB0C_RESULT_SCALE_1X | TB0C_OP_ARG1 |
+               TB0C_ARG1_SEL_DIFFUSE |
+               TB0C_OUTPUT_WRITE_CURRENT;
+       if (op->dst.format == PICT_a8)
+               blend |= TB0C_ARG1_REPLICATE_ALPHA;
+       BATCH(blend);
+
+       BATCH(TB0A_RESULT_SCALE_1X | TB0A_OP_ARG1 |
+             TB0A_ARG1_SEL_DIFFUSE |
+             TB0A_OUTPUT_WRITE_CURRENT);
+
+       if (memcmp(sna->kgem.batch + sna->render_state.gen2.ls2 + 1,
+                  sna->kgem.batch + unwind + 1,
+                  2 * sizeof(uint32_t)) == 0)
+               sna->kgem.nbatch = unwind;
+       else
+               sna->render_state.gen2.ls2 = unwind;
+}
+
+static void gen2_emit_fill_composite_state(struct sna *sna,
+                                          const struct sna_composite_op *op,
+                                          uint32_t pixel)
+{
+       uint32_t ls1;
+
+       gen2_get_batch(sna);
+       gen2_emit_target(sna, op);
+
+       ls1 = sna->kgem.nbatch;
+       BATCH(_3DSTATE_LOAD_STATE_IMMEDIATE_1 |
+             I1_LOAD_S(2) | I1_LOAD_S(3) | I1_LOAD_S(8) | 2);
+       BATCH(0);
+       BATCH(S3_CULLMODE_NONE | S3_VERTEXHAS_XY);
+       BATCH(gen2_get_blend_cntl(op->op, false, op->dst.format));
+       if (memcmp(sna->kgem.batch + sna->render_state.gen2.ls1 + 1,
+                  sna->kgem.batch + ls1 + 1,
+                  3 * sizeof(uint32_t)) == 0)
+               sna->kgem.nbatch = ls1;
+       else
+               sna->render_state.gen2.ls1 = ls1;
+
+       gen2_emit_fill_pipeline(sna, op);
+
+       if (pixel != sna->render_state.gen2.diffuse) {
+               BATCH(_3DSTATE_DFLT_DIFFUSE_CMD);
+               BATCH(pixel);
+               sna->render_state.gen2.diffuse = pixel;
+       }
+}
+
+static bool
+gen2_render_fill_boxes_try_blt(struct sna *sna,
+                              CARD8 op, PictFormat format,
+                              const xRenderColor *color,
+                              PixmapPtr dst, struct kgem_bo *dst_bo,
+                              const BoxRec *box, int n)
+{
+       uint8_t alu;
+       uint32_t pixel;
+
+       if (op > PictOpSrc)
+               return false;
+
+       if (op == PictOpClear) {
+               alu = GXclear;
+               pixel = 0;
+       } else if (!sna_get_pixel_from_rgba(&pixel,
+                                           color->red,
+                                           color->green,
+                                           color->blue,
+                                           color->alpha,
+                                           format))
+               return false;
+       else
+               alu = GXcopy;
+
+       return sna_blt_fill_boxes(sna, alu,
+                                 dst_bo, dst->drawable.bitsPerPixel,
+                                 pixel, box, n);
+}
+
+static inline bool prefer_blt_fill(struct sna *sna)
+{
+#if PREFER_BLT_FILL
+       return true;
+#else
+       return sna->kgem.mode != KGEM_RENDER;
+#endif
+}
+
+static inline bool prefer_blt_copy(struct sna *sna, unsigned flags)
+{
+#if PREFER_BLT_COPY
+       return true;
+#else
+       return sna->kgem.mode != KGEM_RENDER;
+#endif
+}
+
+static bool
+gen2_render_fill_boxes(struct sna *sna,
+                      CARD8 op,
+                      PictFormat format,
+                      const xRenderColor *color,
+                      PixmapPtr dst, struct kgem_bo *dst_bo,
+                      const BoxRec *box, int n)
+{
+       struct sna_composite_op tmp;
+       uint32_t pixel;
+
+       if (op >= ARRAY_SIZE(gen2_blend_op)) {
+               DBG(("%s: fallback due to unhandled blend op: %d\n",
+                    __FUNCTION__, op));
+               return false;
+       }
+
+#if NO_FILL_BOXES
+       return gen2_render_fill_boxes_try_blt(sna, op, format, color,
+                                             dst, dst_bo,
+                                             box, n);
+#endif
+
+       DBG(("%s (op=%d, format=%x, color=(%04x,%04x,%04x, %04x))\n",
+            __FUNCTION__, op, (int)format,
+            color->red, color->green, color->blue, color->alpha));
+
+       if (too_large(dst->drawable.width, dst->drawable.height) ||
+           dst_bo->pitch < 8 || dst_bo->pitch > MAX_3D_PITCH ||
+           !gen2_check_dst_format(format)) {
+               DBG(("%s: try blt, too large or incompatible destination\n",
+                    __FUNCTION__));
+               if (gen2_render_fill_boxes_try_blt(sna, op, format, color,
+                                                  dst, dst_bo,
+                                                  box, n))
+                       return true;
+
+               if (!gen2_check_dst_format(format))
+                       return false;
+
+               assert(dst_bo->pitch >= 8);
+               return sna_tiling_fill_boxes(sna, op, format, color,
+                                            dst, dst_bo, box, n);
+       }
+
+       if (prefer_blt_fill(sna) &&
+           gen2_render_fill_boxes_try_blt(sna, op, format, color,
+                                          dst, dst_bo,
+                                          box, n))
+               return true;
+
+       if (op == PictOpClear)
+               pixel = 0;
+       else if (!sna_get_pixel_from_rgba(&pixel,
+                                         color->red,
+                                         color->green,
+                                         color->blue,
+                                         color->alpha,
+                                         PICT_a8r8g8b8))
+               return false;
+
+       DBG(("%s: using shader for op=%d, format=%x, pixel=%x\n",
+            __FUNCTION__, op, (int)format, pixel));
+
+       memset(&tmp, 0, sizeof(tmp));
+       tmp.op = op;
+       tmp.dst.pixmap = dst;
+       tmp.dst.width = dst->drawable.width;
+       tmp.dst.height = dst->drawable.height;
+       tmp.dst.format = format;
+       tmp.dst.bo = dst_bo;
+       tmp.floats_per_vertex = 2;
+       tmp.floats_per_rect = 6;
+
+       if (!kgem_check_bo(&sna->kgem, dst_bo, NULL)) {
+               kgem_submit(&sna->kgem);
+               assert(kgem_check_bo(&sna->kgem, dst_bo, NULL));
+       }
+
+       gen2_emit_fill_composite_state(sna, &tmp, pixel);
+
+       do {
+               int n_this_time = gen2_get_rectangles(sna, &tmp, n);
+               if (n_this_time == 0) {
+                       gen2_emit_fill_composite_state(sna, &tmp, pixel);
+                       n_this_time = gen2_get_rectangles(sna, &tmp, n);
+               }
+               n -= n_this_time;
+
+               do {
+                       DBG(("  (%d, %d), (%d, %d): %x\n",
+                            box->x1, box->y1, box->x2, box->y2, pixel));
+                       VERTEX(box->x2);
+                       VERTEX(box->y2);
+                       VERTEX(box->x1);
+                       VERTEX(box->y2);
+                       VERTEX(box->x1);
+                       VERTEX(box->y1);
+                       box++;
+               } while (--n_this_time);
+       } while (n);
+
+       gen2_vertex_flush(sna, &tmp);
+       return true;
+}
+
+static void gen2_emit_fill_state(struct sna *sna,
+                                const struct sna_composite_op *op)
+{
+       uint32_t ls1;
+
+       gen2_get_batch(sna);
+       gen2_emit_target(sna, op);
+
+       ls1 = sna->kgem.nbatch;
+       BATCH(_3DSTATE_LOAD_STATE_IMMEDIATE_1 |
+             I1_LOAD_S(2) | I1_LOAD_S(3) | I1_LOAD_S(8) | 2);
+       BATCH(0);
+       BATCH(S3_CULLMODE_NONE | S3_VERTEXHAS_XY);
+       BATCH(S8_ENABLE_COLOR_BUFFER_WRITE);
+       if (memcmp(sna->kgem.batch + sna->render_state.gen2.ls1 + 1,
+                  sna->kgem.batch + ls1 + 1,
+                  3 * sizeof(uint32_t)) == 0)
+               sna->kgem.nbatch = ls1;
+       else
+               sna->render_state.gen2.ls1 = ls1;
+
+       gen2_enable_logic_op(sna, op->op);
+       gen2_emit_fill_pipeline(sna, op);
+
+       if (op->src.u.gen2.pixel != sna->render_state.gen2.diffuse) {
+               BATCH(_3DSTATE_DFLT_DIFFUSE_CMD);
+               BATCH(op->src.u.gen2.pixel);
+               sna->render_state.gen2.diffuse = op->src.u.gen2.pixel;
+       }
+}
+
+static void
+gen2_render_fill_op_blt(struct sna *sna,
+                       const struct sna_fill_op *op,
+                       int16_t x, int16_t y, int16_t w, int16_t h)
+{
+       if (!gen2_get_rectangles(sna, &op->base, 1)) {
+               gen2_emit_fill_state(sna, &op->base);
+               gen2_get_rectangles(sna, &op->base, 1);
+       }
+
+       VERTEX(x+w);
+       VERTEX(y+h);
+       VERTEX(x);
+       VERTEX(y+h);
+       VERTEX(x);
+       VERTEX(y);
+}
+
+fastcall static void
+gen2_render_fill_op_box(struct sna *sna,
+                       const struct sna_fill_op *op,
+                       const BoxRec *box)
+{
+       if (!gen2_get_rectangles(sna, &op->base, 1)) {
+               gen2_emit_fill_state(sna, &op->base);
+               gen2_get_rectangles(sna, &op->base, 1);
+       }
+
+       VERTEX(box->x2);
+       VERTEX(box->y2);
+       VERTEX(box->x1);
+       VERTEX(box->y2);
+       VERTEX(box->x1);
+       VERTEX(box->y1);
+}
+
+fastcall static void
+gen2_render_fill_op_boxes(struct sna *sna,
+                         const struct sna_fill_op *op,
+                         const BoxRec *box,
+                         int nbox)
+{
+       DBG(("%s: (%d, %d),(%d, %d)... x %d\n", __FUNCTION__,
+            box->x1, box->y1, box->x2, box->y2, nbox));
+
+       do {
+               int nbox_this_time = gen2_get_rectangles(sna, &op->base, nbox);
+               if (nbox_this_time == 0) {
+                       gen2_emit_fill_state(sna, &op->base);
+                       nbox_this_time = gen2_get_rectangles(sna, &op->base, nbox);
+               }
+               nbox -= nbox_this_time;
+
+               do {
+                       VERTEX(box->x2);
+                       VERTEX(box->y2);
+                       VERTEX(box->x1);
+                       VERTEX(box->y2);
+                       VERTEX(box->x1);
+                       VERTEX(box->y1);
+                       box++;
+               } while (--nbox_this_time);
+       } while (nbox);
+}
+
+static void
+gen2_render_fill_op_done(struct sna *sna, const struct sna_fill_op *op)
+{
+       gen2_vertex_flush(sna, &op->base);
+}
+
+static bool
+gen2_render_fill(struct sna *sna, uint8_t alu,
+                PixmapPtr dst, struct kgem_bo *dst_bo,
+                uint32_t color,
+                struct sna_fill_op *tmp)
+{
+#if NO_FILL
+       return sna_blt_fill(sna, alu,
+                           dst_bo, dst->drawable.bitsPerPixel,
+                           color,
+                           tmp);
+#endif
+
+       /* Prefer to use the BLT if already engaged */
+       if (prefer_blt_fill(sna) &&
+           sna_blt_fill(sna, alu,
+                        dst_bo, dst->drawable.bitsPerPixel,
+                        color,
+                        tmp))
+               return true;
+
+       /* Must use the BLT if we can't RENDER... */
+       if (too_large(dst->drawable.width, dst->drawable.height) ||
+           dst_bo->pitch < 8 || dst_bo->pitch > MAX_3D_PITCH)
+               return sna_blt_fill(sna, alu,
+                                   dst_bo, dst->drawable.bitsPerPixel,
+                                   color,
+                                   tmp);
+
+       tmp->base.op = alu;
+       tmp->base.dst.pixmap = dst;
+       tmp->base.dst.width = dst->drawable.width;
+       tmp->base.dst.height = dst->drawable.height;
+       tmp->base.dst.format = sna_format_for_depth(dst->drawable.depth);
+       tmp->base.dst.bo = dst_bo;
+       tmp->base.dst.x = tmp->base.dst.y = 0;
+       tmp->base.floats_per_vertex = 2;
+       tmp->base.floats_per_rect = 6;
+
+       tmp->base.src.u.gen2.pixel =
+               sna_rgba_for_color(color, dst->drawable.depth);
+
+       if (!kgem_check_bo(&sna->kgem, dst_bo, NULL)) {
+               kgem_submit(&sna->kgem);
+               return sna_blt_fill(sna, alu,
+                                   dst_bo, dst->drawable.bitsPerPixel,
+                                   color,
+                                   tmp);
+       }
+
+       tmp->blt   = gen2_render_fill_op_blt;
+       tmp->box   = gen2_render_fill_op_box;
+       tmp->boxes = gen2_render_fill_op_boxes;
+       tmp->done  = gen2_render_fill_op_done;
+
+       gen2_emit_fill_state(sna, &tmp->base);
+       return true;
+}
+
+static bool
+gen2_render_fill_one_try_blt(struct sna *sna, PixmapPtr dst, struct kgem_bo *bo,
+                            uint32_t color,
+                            int16_t x1, int16_t y1, int16_t x2, int16_t y2,
+                            uint8_t alu)
+{
+       BoxRec box;
+
+       box.x1 = x1;
+       box.y1 = y1;
+       box.x2 = x2;
+       box.y2 = y2;
+
+       return sna_blt_fill_boxes(sna, alu,
+                                 bo, dst->drawable.bitsPerPixel,
+                                 color, &box, 1);
+}
+
+static bool
+gen2_render_fill_one(struct sna *sna, PixmapPtr dst, struct kgem_bo *bo,
+                    uint32_t color,
+                    int16_t x1, int16_t y1,
+                    int16_t x2, int16_t y2,
+                    uint8_t alu)
+{
+       struct sna_composite_op tmp;
+
+#if NO_FILL_ONE
+       return gen2_render_fill_one_try_blt(sna, dst, bo, color,
+                                           x1, y1, x2, y2, alu);
+#endif
+
+       /* Prefer to use the BLT if already engaged */
+       if (prefer_blt_fill(sna) &&
+           gen2_render_fill_one_try_blt(sna, dst, bo, color,
+                                        x1, y1, x2, y2, alu))
+               return true;
+
+       /* Must use the BLT if we can't RENDER... */
+       if (too_large(dst->drawable.width, dst->drawable.height) ||
+           bo->pitch < 8 || bo->pitch > MAX_3D_PITCH)
+               return gen2_render_fill_one_try_blt(sna, dst, bo, color,
+                                                   x1, y1, x2, y2, alu);
+
+       if (!kgem_check_bo(&sna->kgem, bo, NULL)) {
+               kgem_submit(&sna->kgem);
+               if (gen2_render_fill_one_try_blt(sna, dst, bo, color,
+                                                x1, y1, x2, y2, alu))
+                       return true;
+               assert(kgem_check_bo(&sna->kgem, bo, NULL));
+       }
+
+       tmp.op = alu;
+       tmp.dst.pixmap = dst;
+       tmp.dst.width = dst->drawable.width;
+       tmp.dst.height = dst->drawable.height;
+       tmp.dst.format = sna_format_for_depth(dst->drawable.depth);
+       tmp.dst.bo = bo;
+       tmp.floats_per_vertex = 2;
+       tmp.floats_per_rect = 6;
+       tmp.need_magic_ca_pass = false;
+
+       tmp.src.u.gen2.pixel =
+               sna_rgba_for_color(color, dst->drawable.depth);
+
+       gen2_emit_fill_state(sna, &tmp);
+       gen2_get_rectangles(sna, &tmp, 1);
+       DBG(("%s: (%d, %d), (%d, %d): %x\n", __FUNCTION__,
+            x1, y1, x2, y2, tmp.src.u.gen2.pixel));
+       VERTEX(x2);
+       VERTEX(y2);
+       VERTEX(x1);
+       VERTEX(y2);
+       VERTEX(x1);
+       VERTEX(y1);
+       gen2_vertex_flush(sna, &tmp);
+
+       return true;
+}
+
+static void
+gen2_render_copy_setup_source(struct sna_composite_channel *channel,
+                             PixmapPtr pixmap,
+                             struct kgem_bo *bo)
+{
+       channel->filter = PictFilterNearest;
+       channel->repeat = RepeatNone;
+       channel->width  = pixmap->drawable.width;
+       channel->height = pixmap->drawable.height;
+       channel->scale[0] = 1.f/pixmap->drawable.width;
+       channel->scale[1] = 1.f/pixmap->drawable.height;
+       channel->offset[0] = 0;
+       channel->offset[1] = 0;
+       channel->pict_format = sna_format_for_depth(pixmap->drawable.depth);
+       channel->bo = bo;
+       channel->is_affine = 1;
+}
+
+static void
+gen2_emit_copy_pipeline(struct sna *sna, const struct sna_composite_op *op)
+{
+       uint32_t blend, unwind;
+
+       unwind = sna->kgem.nbatch;
+       BATCH(_3DSTATE_LOAD_STATE_IMMEDIATE_2 |
+             LOAD_TEXTURE_BLEND_STAGE(0) | 1);
+
+       blend = TB0C_LAST_STAGE | TB0C_RESULT_SCALE_1X | TB0C_OP_ARG1 |
+               TB0C_OUTPUT_WRITE_CURRENT;
+       if (op->dst.format == PICT_a8)
+               blend |= TB0C_ARG1_REPLICATE_ALPHA;
+       else if (PICT_FORMAT_RGB(op->src.pict_format) != 0)
+               blend |= TB0C_ARG1_SEL_TEXEL0;
+       else
+               blend |= TB0C_ARG1_SEL_ONE | TB0C_ARG1_INVERT;  /* 0.0 */
+       BATCH(blend);
+
+       blend = TB0A_RESULT_SCALE_1X | TB0A_OP_ARG1 |
+               TB0A_OUTPUT_WRITE_CURRENT;
+       if (PICT_FORMAT_A(op->src.pict_format) == 0)
+               blend |= TB0A_ARG1_SEL_ONE;
+       else
+               blend |= TB0A_ARG1_SEL_TEXEL0;
+       BATCH(blend);
+
+       if (memcmp(sna->kgem.batch + sna->render_state.gen2.ls2 + 1,
+                  sna->kgem.batch + unwind + 1,
+                  2 * sizeof(uint32_t)) == 0)
+               sna->kgem.nbatch = unwind;
+       else
+               sna->render_state.gen2.ls2 = unwind;
+}
+
+static void gen2_emit_copy_state(struct sna *sna, const struct sna_composite_op *op)
+{
+       uint32_t ls1, v;
+
+       gen2_get_batch(sna);
+
+       if (kgem_bo_is_dirty(op->src.bo)) {
+               if (op->src.bo == op->dst.bo)
+                       BATCH(MI_FLUSH | MI_INVALIDATE_MAP_CACHE);
+               else
+                       BATCH(_3DSTATE_MODES_5_CMD |
+                             PIPELINE_FLUSH_RENDER_CACHE |
+                             PIPELINE_FLUSH_TEXTURE_CACHE);
+               kgem_clear_dirty(&sna->kgem);
+       }
+       gen2_emit_target(sna, op);
+
+       ls1 = sna->kgem.nbatch;
+       BATCH(_3DSTATE_LOAD_STATE_IMMEDIATE_1 |
+             I1_LOAD_S(2) | I1_LOAD_S(3) | I1_LOAD_S(8) | 2);
+       BATCH(1<<12);
+       BATCH(S3_CULLMODE_NONE | S3_VERTEXHAS_XY);
+       BATCH(S8_ENABLE_COLOR_BUFFER_WRITE);
+       if (memcmp(sna->kgem.batch + sna->render_state.gen2.ls1 + 1,
+                  sna->kgem.batch + ls1 + 1,
+                  3 * sizeof(uint32_t)) == 0)
+               sna->kgem.nbatch = ls1;
+       else
+               sna->render_state.gen2.ls1 = ls1;
+
+       gen2_enable_logic_op(sna, op->op);
+       gen2_emit_copy_pipeline(sna, op);
+
+       v = _3DSTATE_VERTEX_FORMAT_2_CMD | TEXCOORDFMT_2D;
+       if (sna->render_state.gen2.vft != v) {
+               BATCH(v);
+               sna->render_state.gen2.vft = v;
+       }
+
+       gen2_emit_texture(sna, &op->src, 0);
+}
+
+static bool
+gen2_render_copy_boxes(struct sna *sna, uint8_t alu,
+                      PixmapPtr src, struct kgem_bo *src_bo, int16_t src_dx, int16_t src_dy,
+                      PixmapPtr dst, struct kgem_bo *dst_bo, int16_t dst_dx, int16_t dst_dy,
+                      const BoxRec *box, int n, unsigned flags)
+{
+       struct sna_composite_op tmp;
+
+#if NO_COPY_BOXES
+       if (!sna_blt_compare_depth(&src->drawable, &dst->drawable))
+               return false;
+
+       return sna_blt_copy_boxes(sna, alu,
+                                 src_bo, src_dx, src_dy,
+                                 dst_bo, dst_dx, dst_dy,
+                                 dst->drawable.bitsPerPixel,
+                                 box, n);
+#endif
+
+       DBG(("%s (%d, %d)->(%d, %d) x %d\n",
+            __FUNCTION__, src_dx, src_dy, dst_dx, dst_dy, n));
+
+       if (prefer_blt_copy(sna, flags) &&
+           sna_blt_compare_depth(&src->drawable, &dst->drawable) &&
+           sna_blt_copy_boxes(sna, alu,
+                              src_bo, src_dx, src_dy,
+                              dst_bo, dst_dx, dst_dy,
+                              dst->drawable.bitsPerPixel,
+                              box, n))
+               return true;
+
+       if (src_bo == dst_bo || /* XXX handle overlap using 3D ? */
+           too_large(src->drawable.width, src->drawable.height) ||
+           src_bo->pitch > MAX_3D_PITCH || dst_bo->pitch < 8) {
+fallback:
+               return sna_blt_copy_boxes_fallback(sna, alu,
+                                                  src, src_bo, src_dx, src_dy,
+                                                  dst, dst_bo, dst_dx, dst_dy,
+                                                  box, n);
+       }
+
+       if (!kgem_check_bo(&sna->kgem, dst_bo, src_bo, NULL)) {
+               kgem_submit(&sna->kgem);
+               if (!kgem_check_bo(&sna->kgem, dst_bo, src_bo, NULL))
+                       goto fallback;
+       }
+
+       memset(&tmp, 0, sizeof(tmp));
+       tmp.op = alu;
+
+       tmp.dst.pixmap = dst;
+       tmp.dst.width = dst->drawable.width;
+       tmp.dst.height = dst->drawable.height;
+       tmp.dst.format = sna_format_for_depth(dst->drawable.depth);
+       tmp.dst.bo = dst_bo;
+       tmp.dst.x = tmp.dst.y = 0;
+       tmp.damage = NULL;
+
+       sna_render_composite_redirect_init(&tmp);
+       if (too_large(tmp.dst.width, tmp.dst.height) ||
+           dst_bo->pitch > MAX_3D_PITCH) {
+               BoxRec extents = box[0];
+               int i;
+
+               for (i = 1; i < n; i++) {
+                       if (box[i].x1 < extents.x1)
+                               extents.x1 = box[i].x1;
+                       if (box[i].y1 < extents.y1)
+                               extents.y1 = box[i].y1;
+
+                       if (box[i].x2 > extents.x2)
+                               extents.x2 = box[i].x2;
+                       if (box[i].y2 > extents.y2)
+                               extents.y2 = box[i].y2;
+               }
+               if (!sna_render_composite_redirect(sna, &tmp,
+                                                  extents.x1 + dst_dx,
+                                                  extents.y1 + dst_dy,
+                                                  extents.x2 - extents.x1,
+                                                  extents.y2 - extents.y1))
+                       goto fallback_tiled;
+       }
+
+       tmp.floats_per_vertex = 4;
+       tmp.floats_per_rect = 12;
+
+       dst_dx += tmp.dst.x;
+       dst_dy += tmp.dst.y;
+       tmp.dst.x = tmp.dst.y = 0;
+
+       gen2_render_copy_setup_source(&tmp.src, src, src_bo);
+       gen2_emit_copy_state(sna, &tmp);
+       do {
+               int n_this_time;
+
+               n_this_time = gen2_get_rectangles(sna, &tmp, n);
+               if (n_this_time == 0) {
+                       gen2_emit_copy_state(sna, &tmp);
+                       n_this_time = gen2_get_rectangles(sna, &tmp, n);
+               }
+               n -= n_this_time;
+
+               do {
+                       DBG(("  (%d, %d) -> (%d, %d) + (%d, %d)\n",
+                            box->x1 + src_dx, box->y1 + src_dy,
+                            box->x1 + dst_dx, box->y1 + dst_dy,
+                            box->x2 - box->x1, box->y2 - box->y1));
+                       VERTEX(box->x2 + dst_dx);
+                       VERTEX(box->y2 + dst_dy);
+                       VERTEX((box->x2 + src_dx) * tmp.src.scale[0]);
+                       VERTEX((box->y2 + src_dy) * tmp.src.scale[1]);
+
+                       VERTEX(box->x1 + dst_dx);
+                       VERTEX(box->y2 + dst_dy);
+                       VERTEX((box->x1 + src_dx) * tmp.src.scale[0]);
+                       VERTEX((box->y2 + src_dy) * tmp.src.scale[1]);
+
+                       VERTEX(box->x1 + dst_dx);
+                       VERTEX(box->y1 + dst_dy);
+                       VERTEX((box->x1 + src_dx) * tmp.src.scale[0]);
+                       VERTEX((box->y1 + src_dy) * tmp.src.scale[1]);
+
+                       box++;
+               } while (--n_this_time);
+       } while (n);
+
+       gen2_vertex_flush(sna, &tmp);
+       sna_render_composite_redirect_done(sna, &tmp);
+       return true;
+
+fallback_tiled:
+       return sna_tiling_copy_boxes(sna, alu,
+                                    src, src_bo, src_dx, src_dy,
+                                    dst, dst_bo, dst_dx, dst_dy,
+                                    box, n);
+}
+
+static void
+gen2_render_copy_blt(struct sna *sna,
+                    const struct sna_copy_op *op,
+                    int16_t sx, int16_t sy,
+                    int16_t w, int16_t h,
+                    int16_t dx, int16_t dy)
+{
+       if (!gen2_get_rectangles(sna, &op->base, 1)) {
+               gen2_emit_copy_state(sna, &op->base);
+               gen2_get_rectangles(sna, &op->base, 1);
+       }
+
+       VERTEX(dx+w);
+       VERTEX(dy+h);
+       VERTEX((sx+w)*op->base.src.scale[0]);
+       VERTEX((sy+h)*op->base.src.scale[1]);
+
+       VERTEX(dx);
+       VERTEX(dy+h);
+       VERTEX(sx*op->base.src.scale[0]);
+       VERTEX((sy+h)*op->base.src.scale[1]);
+
+       VERTEX(dx);
+       VERTEX(dy);
+       VERTEX(sx*op->base.src.scale[0]);
+       VERTEX(sy*op->base.src.scale[1]);
+}
+
+static void
+gen2_render_copy_done(struct sna *sna, const struct sna_copy_op *op)
+{
+       gen2_vertex_flush(sna, &op->base);
+}
+
+static bool
+gen2_render_copy(struct sna *sna, uint8_t alu,
+                PixmapPtr src, struct kgem_bo *src_bo,
+                PixmapPtr dst, struct kgem_bo *dst_bo,
+                struct sna_copy_op *tmp)
+{
+#if NO_COPY
+       if (!sna_blt_compare_depth(&src->drawable, &dst->drawable))
+               return false;
+
+       return sna_blt_copy(sna, alu,
+                           src_bo, dst_bo,
+                           dst->drawable.bitsPerPixel,
+                           tmp);
+#endif
+
+       /* Prefer to use the BLT */
+       if (prefer_blt_copy(sna, 0) &&
+           sna_blt_compare_depth(&src->drawable, &dst->drawable) &&
+           sna_blt_copy(sna, alu,
+                        src_bo, dst_bo,
+                        dst->drawable.bitsPerPixel,
+                        tmp))
+               return true;
+
+       /* Must use the BLT if we can't RENDER... */
+       if (too_large(src->drawable.width, src->drawable.height) ||
+           too_large(dst->drawable.width, dst->drawable.height) ||
+           src_bo->pitch > MAX_3D_PITCH ||
+           dst_bo->pitch < 8 || dst_bo->pitch > MAX_3D_PITCH) {
+fallback:
+               if (!sna_blt_compare_depth(&src->drawable, &dst->drawable))
+                       return false;
+
+               return sna_blt_copy(sna, alu, src_bo, dst_bo,
+                                   dst->drawable.bitsPerPixel,
+                                   tmp);
+       }
+
+       tmp->base.op = alu;
+
+       tmp->base.dst.pixmap = dst;
+       tmp->base.dst.width = dst->drawable.width;
+       tmp->base.dst.height = dst->drawable.height;
+       tmp->base.dst.format = sna_format_for_depth(dst->drawable.depth);
+       tmp->base.dst.bo = dst_bo;
+
+       gen2_render_copy_setup_source(&tmp->base.src, src, src_bo);
+       tmp->base.mask.bo = NULL;
+
+       tmp->base.floats_per_vertex = 4;
+       tmp->base.floats_per_rect = 12;
+
+       if (!kgem_check_bo(&sna->kgem, dst_bo, src_bo, NULL)) {
+               kgem_submit(&sna->kgem);
+               if (!kgem_check_bo(&sna->kgem, dst_bo, src_bo, NULL))
+                       goto fallback;
+       }
+
+       tmp->blt  = gen2_render_copy_blt;
+       tmp->done = gen2_render_copy_done;
+
+       gen2_emit_composite_state(sna, &tmp->base);
+       return true;
+}
+
+static void
+gen2_render_reset(struct sna *sna)
+{
+       sna->render_state.gen2.need_invariant = true;
+       sna->render_state.gen2.logic_op_enabled = 0;
+       sna->render_state.gen2.vertex_offset = 0;
+       sna->render_state.gen2.target = 0;
+
+       sna->render_state.gen2.ls1 = 0;
+       sna->render_state.gen2.ls2 = 0;
+       sna->render_state.gen2.vft = 0;
+
+       sna->render_state.gen2.diffuse = 0x0c0ffee0;
+       sna->render_state.gen2.specular = 0x0c0ffee0;
+}
+
+static void
+gen2_render_flush(struct sna *sna)
+{
+       assert(sna->render.vertex_index == 0);
+}
+
+static void
+gen2_render_context_switch(struct kgem *kgem,
+                          int new_mode)
+{
+       struct sna *sna = container_of(kgem, struct sna, kgem);
+
+       if (!kgem->mode)
+               return;
+
+       /* Reload BLT registers following a lost context */
+       sna->blt_state.fill_bo = 0;
+
+       if (kgem_is_idle(kgem)) {
+               DBG(("%s: GPU idle, flushing\n", __FUNCTION__));
+               _kgem_submit(kgem);
+       }
+}
+
+bool gen2_render_init(struct sna *sna)
+{
+       struct sna_render *render = &sna->render;
+
+       sna->kgem.context_switch = gen2_render_context_switch;
+
+       /* Use the BLT (and overlay) for everything except when forced to
+        * use the texture combiners.
+        */
+       render->composite = gen2_render_composite;
+#if !NO_COMPOSITE_SPANS
+       render->check_composite_spans = gen2_check_composite_spans;
+       render->composite_spans = gen2_render_composite_spans;
+#endif
+       render->fill_boxes = gen2_render_fill_boxes;
+       render->fill = gen2_render_fill;
+       render->fill_one = gen2_render_fill_one;
+       render->copy = gen2_render_copy;
+       render->copy_boxes = gen2_render_copy_boxes;
+
+       /* XXX YUV color space conversion for video? */
+
+       render->reset = gen2_render_reset;
+       render->flush = gen2_render_flush;
+
+       render->max_3d_size = MAX_3D_SIZE;
+       render->max_3d_pitch = MAX_3D_PITCH;
+       return true;
+}
diff --git a/src/sna/gen2_render.h b/src/sna/gen2_render.h
new file mode 100644 (file)
index 0000000..2f41e9a
--- /dev/null
@@ -0,0 +1,795 @@
+/**************************************************************************
+ *
+ * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * 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, sub license, 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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 GEN2_RENDER_H
+#define GEN2_RENDER_H
+
+#define CMD_3D (0x3<<29)
+
+#define PRIM3D_INLINE          (CMD_3D | (0x1f<<24))
+#define PRIM3D_TRILIST         (0x0<<18)
+#define PRIM3D_TRISTRIP                (0x1<<18)
+#define PRIM3D_TRISTRIP_RVRSE  (0x2<<18)
+#define PRIM3D_TRIFAN          (0x3<<18)
+#define PRIM3D_POLY            (0x4<<18)
+#define PRIM3D_LINELIST                (0x5<<18)
+#define PRIM3D_LINESTRIP       (0x6<<18)
+#define PRIM3D_RECTLIST                (0x7<<18)
+#define PRIM3D_POINTLIST       (0x8<<18)
+#define PRIM3D_DIB             (0x9<<18)
+#define PRIM3D_CLEAR_RECT      (0xa<<18)
+#define PRIM3D_ZONE_INIT       (0xd<<18)
+#define PRIM3D_MASK            (0x1f<<18)
+
+#define _3DSTATE_AA_CMD                        (CMD_3D | (0x06<<24))
+#define AA_LINE_ECAAR_WIDTH_ENABLE     (1<<16)
+#define AA_LINE_ECAAR_WIDTH_0_5                0
+#define AA_LINE_ECAAR_WIDTH_1_0                (1<<14)
+#define AA_LINE_ECAAR_WIDTH_2_0                (2<<14)
+#define AA_LINE_ECAAR_WIDTH_4_0                (3<<14)
+#define AA_LINE_REGION_WIDTH_ENABLE    (1<<8)
+#define AA_LINE_REGION_WIDTH_0_5       0
+#define AA_LINE_REGION_WIDTH_1_0       (1<<6)
+#define AA_LINE_REGION_WIDTH_2_0       (2<<6)
+#define AA_LINE_REGION_WIDTH_4_0       (3<<6)
+#define AA_LINE_ENABLE                 ((1<<1) | 1)
+#define AA_LINE_DISABLE                        (1<<1)
+
+#define _3DSTATE_BUF_INFO_CMD  (CMD_3D | (0x1d<<24) | (0x8e<<16) | 1)
+/* Dword 1 */
+#define BUF_3D_ID_COLOR_BACK   (0x3<<24)
+#define BUF_3D_ID_DEPTH                (0x7<<24)
+#define BUF_3D_USE_FENCE       (1<<23)
+#define BUF_3D_TILED_SURFACE   (1<<22)
+#define BUF_3D_TILE_WALK_X     0
+#define BUF_3D_TILE_WALK_Y     (1<<21)
+#define BUF_3D_PITCH(x)         (((x)/4)<<2)
+/* Dword 2 */
+#define BUF_3D_ADDR(x)         ((x) & ~0x3)
+
+#define _3DSTATE_COLOR_FACTOR_CMD      (CMD_3D | (0x1d<<24) | (0x1<<16))
+
+#define _3DSTATE_COLOR_FACTOR_N_CMD(stage)     (CMD_3D | (0x1d<<24) | \
+                                                ((0x90+(stage))<<16))
+
+#define _3DSTATE_CONST_BLEND_COLOR_CMD (CMD_3D | (0x1d<<24) | (0x88<<16))
+
+#define _3DSTATE_DFLT_DIFFUSE_CMD      (CMD_3D | (0x1d<<24) | (0x99<<16))
+
+#define _3DSTATE_DFLT_SPECULAR_CMD     (CMD_3D | (0x1d<<24) | (0x9a<<16))
+
+#define _3DSTATE_DFLT_Z_CMD            (CMD_3D | (0x1d<<24) | (0x98<<16))
+
+#define _3DSTATE_DST_BUF_VARS_CMD      (CMD_3D | (0x1d<<24) | (0x85<<16))
+/* Dword 1 */
+#define DSTORG_HORT_BIAS(x)            ((x)<<20)
+#define DSTORG_VERT_BIAS(x)            ((x)<<16)
+#define COLOR_4_2_2_CHNL_WRT_ALL       0
+#define COLOR_4_2_2_CHNL_WRT_Y         (1<<12)
+#define COLOR_4_2_2_CHNL_WRT_CR                (2<<12)
+#define COLOR_4_2_2_CHNL_WRT_CB                (3<<12)
+#define COLOR_4_2_2_CHNL_WRT_CRCB      (4<<12)
+#define COLR_BUF_8BIT                  0
+#define COLR_BUF_RGB555                        (1<<8)
+#define COLR_BUF_RGB565                        (2<<8)
+#define COLR_BUF_ARGB8888              (3<<8)
+#define COLR_BUF_ARGB4444              (8<<8)
+#define COLR_BUF_ARGB1555              (9<<8)
+#define DEPTH_IS_Z                     0
+#define DEPTH_IS_W                     (1<<6)
+#define DEPTH_FRMT_16_FIXED            0
+#define DEPTH_FRMT_16_FLOAT            (1<<2)
+#define DEPTH_FRMT_24_FIXED_8_OTHER    (2<<2)
+#define DEPTH_FRMT_24_FLOAT_8_OTHER    (3<<2)
+#define VERT_LINE_STRIDE_1             (1<<1)
+#define VERT_LINE_STRIDE_0             0
+#define VERT_LINE_STRIDE_OFS_1         1
+#define VERT_LINE_STRIDE_OFS_0         0
+
+#define _3DSTATE_DRAW_RECT_CMD         (CMD_3D|(0x1d<<24)|(0x80<<16)|3)
+/* Dword 1 */
+#define DRAW_RECT_DIS_DEPTH_OFS                (1<<30)
+#define DRAW_DITHER_OFS_X(x)           ((x)<<26)
+#define DRAW_DITHER_OFS_Y(x)           ((x)<<24)
+/* Dword 2 */
+#define DRAW_YMIN(x)                   ((x)<<16)
+#define DRAW_XMIN(x)                   (x)
+/* Dword 3 */
+#define DRAW_YMAX(x)                   ((x)<<16)
+#define DRAW_XMAX(x)                   (x)
+/* Dword 4 */
+#define DRAW_YORG(x)                   ((x)<<16)
+#define DRAW_XORG(x)                   (x)
+
+#define _3DSTATE_ENABLES_1_CMD         (CMD_3D|(0x3<<24))
+#define ENABLE_LOGIC_OP_MASK           ((1<<23)|(1<<22))
+#define ENABLE_LOGIC_OP                        ((1<<23)|(1<<22))
+#define DISABLE_LOGIC_OP               (1<<23)
+#define ENABLE_STENCIL_TEST            ((1<<21)|(1<<20))
+#define DISABLE_STENCIL_TEST           (1<<21)
+#define ENABLE_DEPTH_BIAS              ((1<<11)|(1<<10))
+#define DISABLE_DEPTH_BIAS             (1<<11)
+#define ENABLE_SPEC_ADD_MASK           ((1<<9)|(1<<8))
+#define ENABLE_SPEC_ADD                        ((1<<9)|(1<<8))
+#define DISABLE_SPEC_ADD               (1<<9)
+#define ENABLE_DIS_FOG_MASK            ((1<<7)|(1<<6))
+#define ENABLE_FOG                     ((1<<7)|(1<<6))
+#define DISABLE_FOG                    (1<<7)
+#define ENABLE_DIS_ALPHA_TEST_MASK     ((1<<5)|(1<<4))
+#define ENABLE_ALPHA_TEST              ((1<<5)|(1<<4))
+#define DISABLE_ALPHA_TEST             (1<<5)
+#define ENABLE_DIS_CBLEND_MASK         ((1<<3)|(1<<2))
+#define ENABLE_COLOR_BLEND             ((1<<3)|(1<<2))
+#define DISABLE_COLOR_BLEND            (1<<3)
+#define ENABLE_DIS_DEPTH_TEST_MASK     ((1<<1)|1)
+#define ENABLE_DEPTH_TEST              ((1<<1)|1)
+#define DISABLE_DEPTH_TEST             (1<<1)
+
+/* _3DSTATE_ENABLES_2, p138 */
+#define _3DSTATE_ENABLES_2_CMD         (CMD_3D|(0x4<<24))
+#define ENABLE_STENCIL_WRITE           ((1<<21)|(1<<20))
+#define DISABLE_STENCIL_WRITE          (1<<21)
+#define ENABLE_TEX_CACHE               ((1<<17)|(1<<16))
+#define DISABLE_TEX_CACHE              (1<<17)
+#define ENABLE_DITHER                  ((1<<9)|(1<<8))
+#define DISABLE_DITHER                 (1<<9)
+#define ENABLE_COLOR_MASK              (1<<10)
+#define WRITEMASK_ALPHA                        (1<<7)
+#define WRITEMASK_ALPHA_SHIFT          7
+#define WRITEMASK_RED                  (1<<6)
+#define WRITEMASK_RED_SHIFT            6
+#define WRITEMASK_GREEN                        (1<<5)
+#define WRITEMASK_GREEN_SHIFT          5
+#define WRITEMASK_BLUE                 (1<<4)
+#define WRITEMASK_BLUE_SHIFT           4
+#define WRITEMASK_MASK                 ((1<<4)|(1<<5)|(1<<6)|(1<<7))
+#define ENABLE_COLOR_WRITE             ((1<<3)|(1<<2))
+#define DISABLE_COLOR_WRITE            (1<<3)
+#define ENABLE_DIS_DEPTH_WRITE_MASK    0x3
+#define ENABLE_DEPTH_WRITE             ((1<<1)|1)
+#define DISABLE_DEPTH_WRITE            (1<<1)
+
+/* _3DSTATE_FOG_COLOR, p139 */
+#define _3DSTATE_FOG_COLOR_CMD         (CMD_3D|(0x15<<24))
+#define FOG_COLOR_RED(x)               ((x)<<16)
+#define FOG_COLOR_GREEN(x)             ((x)<<8)
+#define FOG_COLOR_BLUE(x)              (x)
+
+/* _3DSTATE_FOG_MODE, p140 */
+#define _3DSTATE_FOG_MODE_CMD          (CMD_3D|(0x1d<<24)|(0x89<<16)|2)
+/* Dword 1 */
+#define FOGFUNC_ENABLE                 (1<<31)
+#define FOGFUNC_VERTEX                 0
+#define FOGFUNC_PIXEL_EXP              (1<<28)
+#define FOGFUNC_PIXEL_EXP2             (2<<28)
+#define FOGFUNC_PIXEL_LINEAR           (3<<28)
+#define FOGSRC_INDEX_Z                 (1<<27)
+#define FOGSRC_INDEX_W                 ((1<<27)|(1<<25))
+#define FOG_LINEAR_CONST               (1<<24)
+#define FOG_CONST_1(x)                 ((x)<<4)
+#define ENABLE_FOG_DENSITY             (1<<23)
+/* Dword 2 */
+#define FOG_CONST_2(x)                 (x)
+/* Dword 3 */
+#define FOG_DENSITY(x)                 (x)
+
+/* _3DSTATE_INDEPENDENT_ALPHA_BLEND, p142 */
+#define _3DSTATE_INDPT_ALPHA_BLEND_CMD (CMD_3D|(0x0b<<24))
+#define ENABLE_INDPT_ALPHA_BLEND       ((1<<23)|(1<<22))
+#define DISABLE_INDPT_ALPHA_BLEND      (1<<23)
+#define ALPHA_BLENDFUNC_MASK           0x3f0000
+#define ENABLE_ALPHA_BLENDFUNC         (1<<21)
+#define ABLENDFUNC_ADD                 0
+#define ABLENDFUNC_SUB                 (1<<16)
+#define ABLENDFUNC_RVSE_SUB            (2<<16)
+#define ABLENDFUNC_MIN                 (3<<16)
+#define ABLENDFUNC_MAX                 (4<<16)
+#define SRC_DST_ABLEND_MASK            0xfff
+#define ENABLE_SRC_ABLEND_FACTOR       (1<<11)
+#define SRC_ABLEND_FACT(x)             ((x)<<6)
+#define ENABLE_DST_ABLEND_FACTOR       (1<<5)
+#define DST_ABLEND_FACT(x)             (x)
+
+#define BLENDFACTOR_ZERO               0x01
+#define BLENDFACTOR_ONE                        0x02
+#define BLENDFACTOR_SRC_COLR           0x03
+#define BLENDFACTOR_INV_SRC_COLR       0x04
+#define BLENDFACTOR_SRC_ALPHA          0x05
+#define BLENDFACTOR_INV_SRC_ALPHA      0x06
+#define BLENDFACTOR_DST_ALPHA          0x07
+#define BLENDFACTOR_INV_DST_ALPHA      0x08
+#define BLENDFACTOR_DST_COLR           0x09
+#define BLENDFACTOR_INV_DST_COLR       0x0a
+#define BLENDFACTOR_SRC_ALPHA_SATURATE 0x0b
+#define BLENDFACTOR_CONST_COLOR                0x0c
+#define BLENDFACTOR_INV_CONST_COLOR    0x0d
+#define BLENDFACTOR_CONST_ALPHA                0x0e
+#define BLENDFACTOR_INV_CONST_ALPHA    0x0f
+#define BLENDFACTOR_MASK               0x0f
+
+/* _3DSTATE_MAP_BLEND_ARG, p152 */
+#define _3DSTATE_MAP_BLEND_ARG_CMD(stage)      (CMD_3D|(0x0e<<24)|((stage)<<20))
+
+#define TEXPIPE_COLOR                  0
+#define TEXPIPE_ALPHA                  (1<<18)
+#define TEXPIPE_KILL                   (2<<18)
+#define TEXBLEND_ARG0                  0
+#define TEXBLEND_ARG1                  (1<<15)
+#define TEXBLEND_ARG2                  (2<<15)
+#define TEXBLEND_ARG3                  (3<<15)
+#define TEXBLENDARG_MODIFY_PARMS       (1<<6)
+#define TEXBLENDARG_REPLICATE_ALPHA    (1<<5)
+#define TEXBLENDARG_INV_ARG            (1<<4)
+#define TEXBLENDARG_ONE                        0
+#define TEXBLENDARG_FACTOR             0x01
+#define TEXBLENDARG_ACCUM              0x02
+#define TEXBLENDARG_DIFFUSE            0x03
+#define TEXBLENDARG_SPEC               0x04
+#define TEXBLENDARG_CURRENT            0x05
+#define TEXBLENDARG_TEXEL0             0x06
+#define TEXBLENDARG_TEXEL1             0x07
+#define TEXBLENDARG_TEXEL2             0x08
+#define TEXBLENDARG_TEXEL3             0x09
+#define TEXBLENDARG_FACTOR_N           0x0e
+
+/* _3DSTATE_MAP_BLEND_OP, p155 */
+#define _3DSTATE_MAP_BLEND_OP_CMD(stage)       (CMD_3D|(0x0d<<24)|((stage)<<20))
+#if 0
+#   define TEXPIPE_COLOR               0
+#   define TEXPIPE_ALPHA               (1<<18)
+#   define TEXPIPE_KILL                        (2<<18)
+#endif
+#define ENABLE_TEXOUTPUT_WRT_SEL       (1<<17)
+#define TEXOP_OUTPUT_CURRENT           0
+#define TEXOP_OUTPUT_ACCUM             (1<<15)
+#define ENABLE_TEX_CNTRL_STAGE         ((1<<12)|(1<<11))
+#define DISABLE_TEX_CNTRL_STAGE                (1<<12)
+#define TEXOP_SCALE_SHIFT              9
+#define TEXOP_SCALE_1X                 (0 << TEXOP_SCALE_SHIFT)
+#define TEXOP_SCALE_2X                 (1 << TEXOP_SCALE_SHIFT)
+#define TEXOP_SCALE_4X                 (2 << TEXOP_SCALE_SHIFT)
+#define TEXOP_MODIFY_PARMS             (1<<8)
+#define TEXOP_LAST_STAGE               (1<<7)
+#define TEXBLENDOP_KILLPIXEL           0x02
+#define TEXBLENDOP_ARG1                        0x01
+#define TEXBLENDOP_ARG2                        0x02
+#define TEXBLENDOP_MODULATE            0x03
+#define TEXBLENDOP_ADD                 0x06
+#define TEXBLENDOP_ADDSIGNED           0x07
+#define TEXBLENDOP_BLEND               0x08
+#define TEXBLENDOP_BLEND_AND_ADD       0x09
+#define TEXBLENDOP_SUBTRACT            0x0a
+#define TEXBLENDOP_DOT3                        0x0b
+#define TEXBLENDOP_DOT4                        0x0c
+#define TEXBLENDOP_MODULATE_AND_ADD    0x0d
+#define TEXBLENDOP_MODULATE_2X_AND_ADD 0x0e
+#define TEXBLENDOP_MODULATE_4X_AND_ADD 0x0f
+
+/* _3DSTATE_MAP_BUMP_TABLE, p160 TODO */
+/* _3DSTATE_MAP_COLOR_CHROMA_KEY, p161 TODO */
+
+#define _3DSTATE_MAP_COORD_TRANSFORM   ((3<<29)|(0x1d<<24)|(0x8c<<16))
+#define DISABLE_TEX_TRANSFORM          (1<<28)
+#define TEXTURE_SET(x)                 (x<<29)
+
+#define _3DSTATE_VERTEX_TRANSFORM      ((3<<29)|(0x1d<<24)|(0x8b<<16))
+#define DISABLE_VIEWPORT_TRANSFORM     (1<<31)
+#define DISABLE_PERSPECTIVE_DIVIDE     (1<<29)
+
+/* _3DSTATE_MAP_COORD_SET_BINDINGS, p162 */
+#define _3DSTATE_MAP_COORD_SETBIND_CMD (CMD_3D|(0x1d<<24)|(0x02<<16))
+#define TEXBIND_MASK3                  ((1<<15)|(1<<14)|(1<<13)|(1<<12))
+#define TEXBIND_MASK2                  ((1<<11)|(1<<10)|(1<<9)|(1<<8))
+#define TEXBIND_MASK1                  ((1<<7)|(1<<6)|(1<<5)|(1<<4))
+#define TEXBIND_MASK0                  ((1<<3)|(1<<2)|(1<<1)|1)
+
+#define TEXBIND_SET3(x)                        ((x)<<12)
+#define TEXBIND_SET2(x)                        ((x)<<8)
+#define TEXBIND_SET1(x)                        ((x)<<4)
+#define TEXBIND_SET0(x)                        (x)
+
+#define TEXCOORDSRC_KEEP               0
+#define TEXCOORDSRC_DEFAULT            0x01
+#define TEXCOORDSRC_VTXSET_0           0x08
+#define TEXCOORDSRC_VTXSET_1           0x09
+#define TEXCOORDSRC_VTXSET_2           0x0a
+#define TEXCOORDSRC_VTXSET_3           0x0b
+#define TEXCOORDSRC_VTXSET_4           0x0c
+#define TEXCOORDSRC_VTXSET_5           0x0d
+#define TEXCOORDSRC_VTXSET_6           0x0e
+#define TEXCOORDSRC_VTXSET_7           0x0f
+
+#define MAP_UNIT(unit)                 ((unit)<<16)
+#define MAP_UNIT_MASK                  (0x7<<16)
+
+/* _3DSTATE_MAP_COORD_SETS, p164 */
+#define _3DSTATE_MAP_COORD_SET_CMD     (CMD_3D|(0x1c<<24)|(0x01<<19))
+#define TEXCOORD_SET(n)                        ((n)<<16)
+#define ENABLE_TEXCOORD_PARAMS         (1<<15)
+#define TEXCOORDS_ARE_NORMAL           (1<<14)
+#define TEXCOORDS_ARE_IN_TEXELUNITS    0
+#define TEXCOORDTYPE_CARTESIAN         0
+#define TEXCOORDTYPE_HOMOGENEOUS       (1<<11)
+#define TEXCOORDTYPE_VECTOR            (2<<11)
+#define TEXCOORDTYPE_MASK              (0x7<<11)
+#define ENABLE_ADDR_V_CNTL             (1<<7)
+#define ENABLE_ADDR_U_CNTL             (1<<3)
+#define TEXCOORD_ADDR_V_MODE(x)                ((x)<<4)
+#define TEXCOORD_ADDR_U_MODE(x)                (x)
+#define TEXCOORDMODE_WRAP              0
+#define TEXCOORDMODE_MIRROR            1
+#define TEXCOORDMODE_CLAMP             2
+#define TEXCOORDMODE_WRAP_SHORTEST     3
+#define TEXCOORDMODE_CLAMP_BORDER      4
+#define TEXCOORD_ADDR_V_MASK           0x70
+#define TEXCOORD_ADDR_U_MASK           0x7
+
+/* _3DSTATE_MAP_CUBE, p168 TODO */
+#define _3DSTATE_MAP_CUBE              (CMD_3D|(0x1c<<24)|(0x0a<<19))
+#define CUBE_NEGX_ENABLE                (1<<5)
+#define CUBE_POSX_ENABLE                (1<<4)
+#define CUBE_NEGY_ENABLE                (1<<3)
+#define CUBE_POSY_ENABLE                (1<<2)
+#define CUBE_NEGZ_ENABLE                (1<<1)
+#define CUBE_POSZ_ENABLE                (1<<0)
+
+#define _3DSTATE_MAP_INFO_CMD          (CMD_3D|(0x1d<<24)|(0x0<<16)|3)
+#define TEXMAP_INDEX(x)                        ((x)<<28)
+#define MAP_SURFACE_8BIT               (1<<24)
+#define MAP_SURFACE_16BIT              (2<<24)
+#define MAP_SURFACE_32BIT              (3<<24)
+#define MAP_FORMAT_2D                  (0)
+#define MAP_FORMAT_3D_CUBE             (1<<11)
+
+/* _3DSTATE_MODES_1, p190 */
+#define _3DSTATE_MODES_1_CMD           (CMD_3D|(0x08<<24))
+#define BLENDFUNC_MASK                 0x3f0000
+#define ENABLE_COLR_BLND_FUNC          (1<<21)
+#define BLENDFUNC_ADD                  0
+#define BLENDFUNC_SUB                  (1<<16)
+#define BLENDFUNC_RVRSE_SUB            (2<<16)
+#define BLENDFUNC_MIN                  (3<<16)
+#define BLENDFUNC_MAX                  (4<<16)
+#define SRC_DST_BLND_MASK              0xfff
+#define ENABLE_SRC_BLND_FACTOR         (1<<11)
+#define ENABLE_DST_BLND_FACTOR         (1<<5)
+#define SRC_BLND_FACT(x)               ((x)<<6)
+#define DST_BLND_FACT(x)               (x)
+
+/* _3DSTATE_MODES_2, p192 */
+#define _3DSTATE_MODES_2_CMD           (CMD_3D|(0x0f<<24))
+#define ENABLE_GLOBAL_DEPTH_BIAS       (1<<22)
+#define GLOBAL_DEPTH_BIAS(x)           ((x)<<14)
+#define ENABLE_ALPHA_TEST_FUNC         (1<<13)
+#define ENABLE_ALPHA_REF_VALUE         (1<<8)
+#define ALPHA_TEST_FUNC(x)             ((x)<<9)
+#define ALPHA_REF_VALUE(x)             (x)
+
+#define ALPHA_TEST_REF_MASK            0x3fff
+
+/* _3DSTATE_MODES_3, p193 */
+#define _3DSTATE_MODES_3_CMD           (CMD_3D|(0x02<<24))
+#define DEPTH_TEST_FUNC_MASK           0x1f0000
+#define ENABLE_DEPTH_TEST_FUNC         (1<<20)
+/* Uses COMPAREFUNC */
+#define DEPTH_TEST_FUNC(x)             ((x)<<16)
+#define ENABLE_ALPHA_SHADE_MODE                (1<<11)
+#define ENABLE_FOG_SHADE_MODE          (1<<9)
+#define ENABLE_SPEC_SHADE_MODE         (1<<7)
+#define ENABLE_COLOR_SHADE_MODE                (1<<5)
+#define ALPHA_SHADE_MODE(x)            ((x)<<10)
+#define FOG_SHADE_MODE(x)              ((x)<<8)
+#define SPEC_SHADE_MODE(x)             ((x)<<6)
+#define COLOR_SHADE_MODE(x)            ((x)<<4)
+#define CULLMODE_MASK                  0xf
+#define ENABLE_CULL_MODE               (1<<3)
+#define CULLMODE_BOTH                  0
+#define CULLMODE_NONE                  1
+#define CULLMODE_CW                    2
+#define CULLMODE_CCW                   3
+
+#define SHADE_MODE_LINEAR              0
+#define SHADE_MODE_FLAT                        0x1
+
+/* _3DSTATE_MODES_4, p195 */
+#define _3DSTATE_MODES_4_CMD           (CMD_3D|(0x16<<24))
+#define ENABLE_LOGIC_OP_FUNC           (1<<23)
+#define LOGIC_OP_FUNC(x)               ((x)<<18)
+#define LOGICOP_MASK                   ((1<<18)|(1<<19)|(1<<20)|(1<<21))
+#define LOGICOP_CLEAR                  0
+#define LOGICOP_NOR                    0x1
+#define LOGICOP_AND_INV                        0x2
+#define LOGICOP_COPY_INV               0x3
+#define LOGICOP_AND_RVRSE              0x4
+#define LOGICOP_INV                    0x5
+#define LOGICOP_XOR                    0x6
+#define LOGICOP_NAND                   0x7
+#define LOGICOP_AND                    0x8
+#define LOGICOP_EQUIV                  0x9
+#define LOGICOP_NOOP                   0xa
+#define LOGICOP_OR_INV                 0xb
+#define LOGICOP_COPY                   0xc
+#define LOGICOP_OR_RVRSE               0xd
+#define LOGICOP_OR                     0xe
+#define LOGICOP_SET                    0xf
+#define MODE4_ENABLE_STENCIL_TEST_MASK ((1<<17)|(0xff00))
+#define ENABLE_STENCIL_TEST_MASK       (1<<17)
+#define STENCIL_TEST_MASK(x)           ((x)<<8)
+#define MODE4_ENABLE_STENCIL_WRITE_MASK        ((1<<16)|(0x00ff))
+#define ENABLE_STENCIL_WRITE_MASK      (1<<16)
+#define STENCIL_WRITE_MASK(x)          ((x)&0xff)
+
+/* _3DSTATE_MODES_5, p196 */
+#define _3DSTATE_MODES_5_CMD           (CMD_3D|(0x0c<<24))
+#define ENABLE_SPRITE_POINT_TEX                (1<<23)
+#define SPRITE_POINT_TEX_ON            (1<<22)
+#define PIPELINE_FLUSH_RENDER_CACHE    (1<<18)
+#define PIPELINE_FLUSH_TEXTURE_CACHE   (1<<16)
+#define FIXED_LINE_WIDTH_MASK          0xfc00
+#define ENABLE_FIXED_LINE_WIDTH                (1<<15)
+#define FIXED_LINE_WIDTH(x)            ((x)<<10)
+#define FIXED_POINT_WIDTH_MASK         0x3ff
+#define ENABLE_FIXED_POINT_WIDTH       (1<<9)
+#define FIXED_POINT_WIDTH(x)           (x)
+
+/* _3DSTATE_RASTERIZATION_RULES, p198 */
+#define _3DSTATE_RASTER_RULES_CMD      (CMD_3D|(0x07<<24))
+#define ENABLE_POINT_RASTER_RULE       (1<<15)
+#define OGL_POINT_RASTER_RULE          (1<<13)
+#define ENABLE_LINE_STRIP_PROVOKE_VRTX (1<<8)
+#define ENABLE_TRI_FAN_PROVOKE_VRTX    (1<<5)
+#define ENABLE_TRI_STRIP_PROVOKE_VRTX  (1<<2)
+#define LINE_STRIP_PROVOKE_VRTX(x)     ((x)<<6)
+#define TRI_FAN_PROVOKE_VRTX(x)                ((x)<<3)
+#define TRI_STRIP_PROVOKE_VRTX(x)      (x)
+
+/* _3DSTATE_SCISSOR_ENABLE, p200 */
+#define _3DSTATE_SCISSOR_ENABLE_CMD    (CMD_3D|(0x1c<<24)|(0x10<<19))
+#define ENABLE_SCISSOR_RECT            ((1<<1) | 1)
+#define DISABLE_SCISSOR_RECT           (1<<1)
+
+/* _3DSTATE_SCISSOR_RECTANGLE_0, p201 */
+#define _3DSTATE_SCISSOR_RECT_0_CMD    (CMD_3D|(0x1d<<24)|(0x81<<16)|1)
+/* Dword 1 */
+#define SCISSOR_RECT_0_YMIN(x)         ((x)<<16)
+#define SCISSOR_RECT_0_XMIN(x)         (x)
+/* Dword 2 */
+#define SCISSOR_RECT_0_YMAX(x)         ((x)<<16)
+#define SCISSOR_RECT_0_XMAX(x)         (x)
+
+/* _3DSTATE_STENCIL_TEST, p202 */
+#define _3DSTATE_STENCIL_TEST_CMD      (CMD_3D|(0x09<<24))
+#define ENABLE_STENCIL_PARMS           (1<<23)
+#define STENCIL_OPS_MASK               (0xffc000)
+#define STENCIL_FAIL_OP(x)             ((x)<<20)
+#define STENCIL_PASS_DEPTH_FAIL_OP(x)  ((x)<<17)
+#define STENCIL_PASS_DEPTH_PASS_OP(x)  ((x)<<14)
+
+#define ENABLE_STENCIL_TEST_FUNC_MASK  ((1<<13)|(1<<12)|(1<<11)|(1<<10)|(1<<9))
+#define ENABLE_STENCIL_TEST_FUNC       (1<<13)
+/* Uses COMPAREFUNC */
+#define STENCIL_TEST_FUNC(x)           ((x)<<9)
+#define STENCIL_REF_VALUE_MASK         ((1<<8)|0xff)
+#define ENABLE_STENCIL_REF_VALUE       (1<<8)
+#define STENCIL_REF_VALUE(x)           (x)
+
+/* _3DSTATE_VERTEX_FORMAT, p204 */
+#define _3DSTATE_VFT0_CMD      (CMD_3D|(0x05<<24))
+#define VFT0_POINT_WIDTH       (1<<12)
+#define VFT0_TEX_COUNT_MASK    (7<<8)
+#define VFT0_TEX_COUNT_SHIFT    8
+#define VFT0_TEX_COUNT(x)      ((x)<<8)
+#define VFT0_SPEC              (1<<7)
+#define VFT0_DIFFUSE           (1<<6)
+#define VFT0_DEPTH_OFFSET      (1<<5)
+#define VFT0_XYZ               (1<<1)
+#define VFT0_XYZW              (2<<1)
+#define VFT0_XY                        (3<<1)
+#define VFT0_XYW               (4<<1)
+#define VFT0_XYZW_MASK          (7<<1)
+
+/* _3DSTATE_VERTEX_FORMAT_2, p206 */
+#define _3DSTATE_VERTEX_FORMAT_2_CMD   (CMD_3D|(0x0a<<24))
+#define VFT1_TEX7_FMT(x)       ((x)<<14)
+#define VFT1_TEX6_FMT(x)       ((x)<<12)
+#define VFT1_TEX5_FMT(x)       ((x)<<10)
+#define VFT1_TEX4_FMT(x)       ((x)<<8)
+#define VFT1_TEX3_FMT(x)       ((x)<<6)
+#define VFT1_TEX2_FMT(x)       ((x)<<4)
+#define VFT1_TEX1_FMT(x)       ((x)<<2)
+#define VFT1_TEX0_FMT(x)       (x)
+#define VFT1_TEX0_MASK          3
+#define VFT1_TEX1_SHIFT         2
+#define TEXCOORDFMT_2D         0
+#define TEXCOORDFMT_3D         1
+#define TEXCOORDFMT_4D         2
+#define TEXCOORDFMT_1D         3
+
+/*New stuff picked up along the way */
+
+#define MLC_LOD_BIAS_MASK ((1<<7)-1)
+
+/* _3DSTATE_VERTEX_TRANSFORM, p207 */
+#define _3DSTATE_VERTEX_TRANS_CMD      (CMD_3D|(0x1d<<24)|(0x8b<<16)|0)
+#define _3DSTATE_VERTEX_TRANS_MTX_CMD  (CMD_3D|(0x1d<<24)|(0x8b<<16)|6)
+/* Dword 1 */
+#define ENABLE_VIEWPORT_TRANSFORM      ((1<<31)|(1<<30))
+#define DISABLE_VIEWPORT_TRANSFORM     (1<<31)
+#define ENABLE_PERSP_DIVIDE            ((1<<29)|(1<<28))
+#define DISABLE_PERSP_DIVIDE           (1<<29)
+#define VRTX_TRANS_LOAD_MATRICES       0x7421
+#define VRTX_TRANS_NO_LOAD_MATRICES    0x0000
+/* Dword 2 -> 7  are matrix elements */
+
+/* _3DSTATE_W_STATE, p209 */
+#define _3DSTATE_W_STATE_CMD           (CMD_3D|(0x1d<<24)|(0x8d<<16)|1)
+/* Dword 1 */
+#define MAGIC_W_STATE_DWORD1           0x00000008
+/* Dword 2 */
+#define WFAR_VALUE(x)                  (x)
+
+/* Stipple command, carried over from the i810, apparently:
+ */
+#define _3DSTATE_STIPPLE           (CMD_3D|(0x1d<<24)|(0x83<<16))
+#define ST1_ENABLE               (1<<16)
+#define ST1_MASK                 (0xffff)
+
+#define _3DSTATE_LOAD_STATE_IMMEDIATE_1             (CMD_3D|(0x1d<<24)|(0x04<<16))
+#define I1_LOAD_S(n)                        (1<<((n)+4))
+#define S3_POINT_WIDTH_SHIFT                23
+#define S3_LINE_WIDTH_SHIFT                 19
+#define S3_ALPHA_SHADE_MODE_SHIFT           18
+#define S3_FOG_SHADE_MODE_SHIFT                     17
+#define S3_SPEC_SHADE_MODE_SHIFT            16
+#define S3_COLOR_SHADE_MODE_SHIFT           15
+#define S3_CULL_MODE_SHIFT                  13
+#define    S3_CULLMODE_BOTH                 (0)
+#define    S3_CULLMODE_NONE                 (1<<13)
+#define    S3_CULLMODE_CW                   (2<<13)
+#define    S3_CULLMODE_CCW                  (3<<13)
+#define S3_POINT_WIDTH_PRESENT              (1<<12)
+#define S3_SPEC_FOG_PRESENT                 (1<<11)
+#define S3_DIFFUSE_PRESENT                  (1<<10)
+#define S3_DEPTH_OFFSET_PRESENT                     (1<<9)
+#define S3_POSITION_SHIFT                   6
+#define    S3_VERTEXHAS_XYZ                 (1<<6)
+#define    S3_VERTEXHAS_XYZW                (2<<6)
+#define    S3_VERTEXHAS_XY                  (3<<6)
+#define    S3_VERTEXHAS_XYW                 (4<<6)
+#define S3_ENABLE_SPEC_ADD                  (1<<5)
+#define S3_ENABLE_FOG                       (1<<4)
+#define S3_ENABLE_LOCAL_DEPTH_BIAS          (1<<3)
+#define S3_ENABLE_SPRITE_POINT              (1<<1)
+#define S3_ENABLE_ANTIALIASING              1
+#define S7_ENABLE_LOGIC_OP                  (1<<0)
+#define S8_ENABLE_ALPHA_TEST                (1<<31)
+#define S8_ALPHA_TEST_FUNC_SHIFT            28
+#define S8_ALPHA_REFVALUE_SHIFT                     20
+#define S8_ENABLE_DEPTH_TEST                (1<<19)
+#define S8_DEPTH_TEST_FUNC_SHIFT            16
+#define S8_ENABLE_COLOR_BLEND               (1<<15)
+#define S8_COLOR_BLEND_FUNC_SHIFT           12
+#define    S8_BLENDFUNC_ADD                 (0)
+#define    S8_BLENDFUNC_SUB                 (1<<12)
+#define    S8_BLENDFUNC_RVRSE_SUB           (2<<12)
+#define    S8_BLENDFUNC_MIN                 (3<<12)
+#define    S8_BLENDFUNC_MAX                         (4<<12)
+#define S8_SRC_BLEND_FACTOR_SHIFT           8
+#define S8_DST_BLEND_FACTOR_SHIFT           4
+#define S8_ENABLE_DEPTH_BUFFER_WRITE        (1<<3)
+#define S8_ENABLE_COLOR_BUFFER_WRITE        (1<<2)
+
+#define _3DSTATE_LOAD_STATE_IMMEDIATE_2      (CMD_3D|(0x1d<<24)|(0x03<<16))
+#define LOAD_TEXTURE_MAP(x)                   (1<<((x)+11))
+#define LOAD_TEXTURE_BLEND_STAGE(x)          (1<<((x)+7))
+#define LOAD_GLOBAL_COLOR_FACTOR            (1<<6)
+
+#define TM0S0_ADDRESS_MASK              0xfffffffc
+#define TM0S0_USE_FENCE                 (1<<1)
+
+#define TM0S1_HEIGHT_SHIFT              21
+#define TM0S1_WIDTH_SHIFT               10
+#define TM0S1_PALETTE_SELECT            (1<<9)
+#define TM0S1_MAPSURF_FORMAT_MASK       (0x7 << 6)
+#define TM0S1_MAPSURF_FORMAT_SHIFT      6
+#define    MAPSURF_8BIT_INDEXED                   (0<<6)
+#define    MAPSURF_8BIT                           (1<<6)
+#define    MAPSURF_16BIT                  (2<<6)
+#define    MAPSURF_32BIT                  (3<<6)
+#define    MAPSURF_411                    (4<<6)
+#define    MAPSURF_422                    (5<<6)
+#define    MAPSURF_COMPRESSED             (6<<6)
+#define    MAPSURF_4BIT_INDEXED                   (7<<6)
+#define TM0S1_MT_FORMAT_MASK         (0x7 << 3)
+#define TM0S1_MT_FORMAT_SHIFT        3
+#define    MT_4BIT_IDX_ARGB8888                   (7<<3)       /* SURFACE_4BIT_INDEXED */
+#define    MT_8BIT_IDX_RGB565             (0<<3)       /* SURFACE_8BIT_INDEXED */
+#define    MT_8BIT_IDX_ARGB1555                   (1<<3)
+#define    MT_8BIT_IDX_ARGB4444                   (2<<3)
+#define    MT_8BIT_IDX_AY88               (3<<3)
+#define    MT_8BIT_IDX_ABGR8888                   (4<<3)
+#define    MT_8BIT_IDX_BUMP_88DVDU        (5<<3)
+#define    MT_8BIT_IDX_BUMP_655LDVDU      (6<<3)
+#define    MT_8BIT_IDX_ARGB8888                   (7<<3)
+#define    MT_8BIT_I8                     (0<<3)       /* SURFACE_8BIT */
+#define    MT_8BIT_L8                     (1<<3)
+#define    MT_8BIT_A8                     (4<<3)
+#define    MT_16BIT_RGB565                (0<<3)       /* SURFACE_16BIT */
+#define    MT_16BIT_ARGB1555              (1<<3)
+#define    MT_16BIT_ARGB4444              (2<<3)
+#define    MT_16BIT_AY88                  (3<<3)
+#define    MT_16BIT_DIB_ARGB1555_8888      (4<<3)
+#define    MT_16BIT_BUMP_88DVDU                   (5<<3)
+#define    MT_16BIT_BUMP_655LDVDU         (6<<3)
+#define    MT_16BIT_DIB_RGB565_8888       (7<<3)
+#define    MT_32BIT_ARGB8888              (0<<3)       /* SURFACE_32BIT */
+#define    MT_32BIT_ABGR8888              (1<<3)
+#define    MT_32BIT_XRGB8888              (2<<3)
+#define    MT_32BIT_XBGR8888              (3<<3)
+#define    MT_32BIT_BUMP_XLDVDU_8888      (6<<3)
+#define    MT_32BIT_DIB_8888              (7<<3)
+#define    MT_411_YUV411                  (0<<3)       /* SURFACE_411 */
+#define    MT_422_YCRCB_SWAPY             (0<<3)       /* SURFACE_422 */
+#define    MT_422_YCRCB_NORMAL            (1<<3)
+#define    MT_422_YCRCB_SWAPUV            (2<<3)
+#define    MT_422_YCRCB_SWAPUVY                   (3<<3)
+#define    MT_COMPRESS_DXT1               (0<<3)       /* SURFACE_COMPRESSED */
+#define    MT_COMPRESS_DXT2_3             (1<<3)
+#define    MT_COMPRESS_DXT4_5             (2<<3)
+#define    MT_COMPRESS_FXT1               (3<<3)
+#define TM0S1_COLORSPACE_CONVERSION     (1 << 2)
+#define TM0S1_TILED_SURFACE             (1 << 1)
+#define TM0S1_TILE_WALK                 (1 << 0)
+
+#define TM0S2_PITCH_SHIFT               21
+#define TM0S2_CUBE_FACE_ENA_SHIFT       15
+#define TM0S2_CUBE_FACE_ENA_MASK        (1<<15)
+#define TM0S2_MAP_FORMAT                (1<<14)
+#define    TM0S2_MAP_2D                        (0<<14)
+#define    TM0S2_MAP_3D_CUBE           (1<<14)
+#define TM0S2_VERTICAL_LINE_STRIDE      (1<<13)
+#define TM0S2_VERITCAL_LINE_STRIDE_OFF  (1<<12)
+#define TM0S2_OUTPUT_CHAN_SHIFT         10
+#define TM0S2_OUTPUT_CHAN_MASK          (3<<10)
+
+#define TM0S3_MIP_FILTER_MASK           (0x3<<30)
+#define TM0S3_MIP_FILTER_SHIFT          30
+#define MIPFILTER_NONE         0
+#define MIPFILTER_NEAREST      1
+#define MIPFILTER_LINEAR       3
+#define TM0S3_MAG_FILTER_MASK           (0x3<<28)
+#define TM0S3_MAG_FILTER_SHIFT          28
+#define TM0S3_MIN_FILTER_MASK           (0x3<<26)
+#define TM0S3_MIN_FILTER_SHIFT          26
+#define FILTER_NEAREST         0
+#define FILTER_LINEAR          1
+#define FILTER_ANISOTROPIC     2
+
+#define TM0S3_LOD_BIAS_SHIFT           17
+#define TM0S3_LOD_BIAS_MASK            (0x1ff<<17)
+#define TM0S3_MAX_MIP_SHIFT            9
+#define TM0S3_MAX_MIP_MASK             (0xff<<9)
+#define TM0S3_MIN_MIP_SHIFT            3
+#define TM0S3_MIN_MIP_MASK             (0x3f<<3)
+#define TM0S3_KILL_PIXEL               (1<<2)
+#define TM0S3_KEYED_FILTER             (1<<1)
+#define TM0S3_CHROMA_KEY               (1<<0)
+
+/* _3DSTATE_MAP_TEXEL_STREAM, p188 */
+#define _3DSTATE_MAP_TEX_STREAM_CMD    (CMD_3D|(0x1c<<24)|(0x05<<19))
+#define DISABLE_TEX_STREAM_BUMP                (1<<12)
+#define ENABLE_TEX_STREAM_BUMP         ((1<<12)|(1<<11))
+#define TEX_MODIFY_UNIT_0              0
+#define TEX_MODIFY_UNIT_1              (1<<8)
+#define ENABLE_TEX_STREAM_COORD_SET    (1<<7)
+#define TEX_STREAM_COORD_SET(x)                ((x)<<4)
+#define ENABLE_TEX_STREAM_MAP_IDX      (1<<3)
+#define TEX_STREAM_MAP_IDX(x)          (x)
+
+#define FLUSH_MAP_CACHE    (1<<0)
+
+#define _3DSTATE_MAP_FILTER_CMD    (CMD_3D|(0x1c<<24)|(0x02<<19))
+#define FILTER_TEXMAP_INDEX(x) ((x) << 16)
+#define MAG_MODE_FILTER_ENABLE (1 << 5)
+#define MIN_MODE_FILTER_ENABLE (1 << 2)
+#define MAG_MAPFILTER_NEAREST (0 << 3)
+#define MAG_MAPFILTER_LINEAR  (1 << 3)
+#define MAG_MAPFILTER_ANISOTROPIC (2 << 3)
+#define MIN_MAPFILTER_NEAREST (0)
+#define MIN_MAPFILTER_LINEAR  (1)
+#define MIN_MAPFILTER_ANISOTROPIC (2)
+#define ENABLE_KEYS    (1<<15)
+#define DISABLE_COLOR_KEY      0
+#define DISABLE_CHROMA_KEY     0
+#define DISABLE_KILL_PIXEL     0
+#define ENABLE_MIP_MODE_FILTER (1 << 9)
+#define MIPFILTER_NONE         0
+#define MIPFILTER_NEAREST      1
+#define MIPFILTER_LINEAR       3
+
+#define TB0C_LAST_STAGE                        (1 << 31)
+#define TB0C_RESULT_SCALE_1X           (0 << 29)
+#define TB0C_RESULT_SCALE_2X           (1 << 29)
+#define TB0C_RESULT_SCALE_4X           (2 << 29)
+#define TB0C_OP_ARG1                   (1 << 25)
+#define TB0C_OP_MODULATE               (3 << 25)
+#define TB0C_OUTPUT_WRITE_CURRENT      (0 << 24)
+#define TB0C_OUTPUT_WRITE_ACCUM                (1 << 24)
+#define TB0C_ARG3_REPLICATE_ALPHA      (1<<23)
+#define TB0C_ARG3_INVERT               (1<<22)
+#define TB0C_ARG3_SEL_XXX
+#define TB0C_ARG2_REPLICATE_ALPHA      (1<<17)
+#define TB0C_ARG2_INVERT               (1<<16)
+#define TB0C_ARG2_SEL_ONE              (0 << 12)
+#define TB0C_ARG2_SEL_DIFFUSE          (3 << 12)
+#define TB0C_ARG2_SEL_SPECULAR         (4 << 12)
+#define TB0C_ARG2_SEL_FACTOR           (1 << 12)
+#define TB0C_ARG2_SEL_TEXEL0           (6 << 12)
+#define TB0C_ARG2_SEL_TEXEL1           (7 << 12)
+#define TB0C_ARG2_SEL_TEXEL2           (8 << 12)
+#define TB0C_ARG2_SEL_TEXEL3           (9 << 12)
+#define TB0C_ARG1_REPLICATE_ALPHA      (1<<11)
+#define TB0C_ARG1_INVERT               (1<<10)
+#define TB0C_ARG1_SEL_ONE              (0 << 6)
+#define TB0C_ARG1_SEL_DIFFUSE          (3 << 6)
+#define TB0C_ARG1_SEL_SPECULAR         (4 << 6)
+#define TB0C_ARG1_SEL_TEXEL0           (6 << 6)
+#define TB0C_ARG1_SEL_TEXEL1           (7 << 6)
+#define TB0C_ARG1_SEL_TEXEL2           (8 << 6)
+#define TB0C_ARG1_SEL_TEXEL3           (9 << 6)
+#define TB0C_ARG0_REPLICATE_ALPHA      (1<<5)
+#define TB0C_ARG0_SEL_XXX
+
+#define TB0A_CTR_STAGE_ENABLE          (1<<31)
+#define TB0A_RESULT_SCALE_1X           (0 << 29)
+#define TB0A_RESULT_SCALE_2X           (1 << 29)
+#define TB0A_RESULT_SCALE_4X           (2 << 29)
+#define TB0A_OP_ARG1                   (1 << 25)
+#define TB0A_OP_MODULATE               (3 << 25)
+#define TB0A_OUTPUT_WRITE_CURRENT      (0<<24)
+#define TB0A_OUTPUT_WRITE_ACCUM                (1<<24)
+#define TB0A_CTR_STAGE_SEL_BITS_XXX
+#define TB0A_ARG3_SEL_XXX
+#define TB0A_ARG3_INVERT               (1<<17)
+#define TB0A_ARG2_INVERT               (1<<16)
+#define TB0A_ARG2_SEL_ONE              (0 << 12)
+#define TB0A_ARG2_SEL_DIFFUSE          (3 << 12)
+#define TB0A_ARG2_SEL_SPECULAR         (4 << 12)
+#define TB0A_ARG2_SEL_TEXEL0           (6 << 12)
+#define TB0A_ARG2_SEL_TEXEL1           (7 << 12)
+#define TB0A_ARG2_SEL_TEXEL2           (8 << 12)
+#define TB0A_ARG2_SEL_TEXEL3           (9 << 12)
+#define TB0A_ARG1_INVERT               (1<<10)
+#define TB0A_ARG1_SEL_ONE              (0 << 6)
+#define TB0A_ARG1_SEL_DIFFUSE          (3 << 6)
+#define TB0A_ARG1_SEL_SPECULAR         (4 << 6)
+#define TB0A_ARG1_SEL_TEXEL0           (6 << 6)
+#define TB0A_ARG1_SEL_TEXEL1           (7 << 6)
+#define TB0A_ARG1_SEL_TEXEL2           (8 << 6)
+#define TB0A_ARG1_SEL_TEXEL3           (9 << 6)
+
+#endif /* GEN2_RENDER_H */
diff --git a/src/sna/gen3_render.c b/src/sna/gen3_render.c
new file mode 100644 (file)
index 0000000..4c4271e
--- /dev/null
@@ -0,0 +1,4701 @@
+/*
+ * Copyright © 2010-2011 Intel 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.
+ *
+ * Authors:
+ *    Chris Wilson <chris@chris-wilson.co.uk>
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "sna.h"
+#include "sna_render.h"
+#include "sna_render_inline.h"
+#include "sna_reg.h"
+#include "sna_video.h"
+
+#include "gen3_render.h"
+
+#define NO_COMPOSITE 0
+#define NO_COMPOSITE_SPANS 0
+#define NO_COPY 0
+#define NO_COPY_BOXES 0
+#define NO_FILL 0
+#define NO_FILL_ONE 0
+#define NO_FILL_BOXES 0
+
+#define PREFER_BLT_FILL 1
+
+enum {
+       SHADER_NONE = 0,
+       SHADER_ZERO,
+       SHADER_BLACK,
+       SHADER_WHITE,
+       SHADER_CONSTANT,
+       SHADER_LINEAR,
+       SHADER_RADIAL,
+       SHADER_TEXTURE,
+       SHADER_OPACITY,
+};
+
+#define MAX_3D_SIZE 2048
+#define MAX_3D_PITCH 8192
+
+#define OUT_BATCH(v) batch_emit(sna, v)
+#define OUT_BATCH_F(v) batch_emit_float(sna, v)
+#define OUT_VERTEX(v) vertex_emit(sna, v)
+
+enum gen3_radial_mode {
+       RADIAL_ONE,
+       RADIAL_TWO
+};
+
+static const struct blendinfo {
+       bool dst_alpha;
+       bool src_alpha;
+       uint32_t src_blend;
+       uint32_t dst_blend;
+} gen3_blend_op[] = {
+       /* Clear */     {0, 0, BLENDFACT_ZERO, BLENDFACT_ZERO},
+       /* Src */       {0, 0, BLENDFACT_ONE, BLENDFACT_ZERO},
+       /* Dst */       {0, 0, BLENDFACT_ZERO, BLENDFACT_ONE},
+       /* Over */      {0, 1, BLENDFACT_ONE, BLENDFACT_INV_SRC_ALPHA},
+       /* OverReverse */ {1, 0, BLENDFACT_INV_DST_ALPHA, BLENDFACT_ONE},
+       /* In */        {1, 0, BLENDFACT_DST_ALPHA, BLENDFACT_ZERO},
+       /* InReverse */ {0, 1, BLENDFACT_ZERO, BLENDFACT_SRC_ALPHA},
+       /* Out */       {1, 0, BLENDFACT_INV_DST_ALPHA, BLENDFACT_ZERO},
+       /* OutReverse */ {0, 1, BLENDFACT_ZERO, BLENDFACT_INV_SRC_ALPHA},
+       /* Atop */      {1, 1, BLENDFACT_DST_ALPHA, BLENDFACT_INV_SRC_ALPHA},
+       /* AtopReverse */ {1, 1, BLENDFACT_INV_DST_ALPHA, BLENDFACT_SRC_ALPHA},
+       /* Xor */       {1, 1, BLENDFACT_INV_DST_ALPHA, BLENDFACT_INV_SRC_ALPHA},
+       /* Add */       {0, 0, BLENDFACT_ONE, BLENDFACT_ONE},
+};
+
+#define S6_COLOR_WRITE_ONLY \
+       (S6_COLOR_WRITE_ENABLE | \
+        BLENDFUNC_ADD << S6_CBUF_BLEND_FUNC_SHIFT | \
+        BLENDFACT_ONE << S6_CBUF_SRC_BLEND_FACT_SHIFT | \
+        BLENDFACT_ZERO << S6_CBUF_DST_BLEND_FACT_SHIFT)
+
+static const struct formatinfo {
+       unsigned int fmt, xfmt;
+       uint32_t card_fmt;
+       bool rb_reversed;
+} gen3_tex_formats[] = {
+       {PICT_a8, 0, MAPSURF_8BIT | MT_8BIT_A8, false},
+       {PICT_a8r8g8b8, 0, MAPSURF_32BIT | MT_32BIT_ARGB8888, false},
+       {PICT_x8r8g8b8, 0, MAPSURF_32BIT | MT_32BIT_XRGB8888, false},
+       {PICT_a8b8g8r8, 0, MAPSURF_32BIT | MT_32BIT_ABGR8888, false},
+       {PICT_x8b8g8r8, 0, MAPSURF_32BIT | MT_32BIT_XBGR8888, false},
+       {PICT_a2r10g10b10, PICT_x2r10g10b10, MAPSURF_32BIT | MT_32BIT_ARGB2101010, false},
+       {PICT_a2b10g10r10, PICT_x2b10g10r10, MAPSURF_32BIT | MT_32BIT_ABGR2101010, false},
+       {PICT_r5g6b5, 0, MAPSURF_16BIT | MT_16BIT_RGB565, false},
+       {PICT_b5g6r5, 0, MAPSURF_16BIT | MT_16BIT_RGB565, true},
+       {PICT_a1r5g5b5, PICT_x1r5g5b5, MAPSURF_16BIT | MT_16BIT_ARGB1555, false},
+       {PICT_a1b5g5r5, PICT_x1b5g5r5, MAPSURF_16BIT | MT_16BIT_ARGB1555, true},
+       {PICT_a4r4g4b4, PICT_x4r4g4b4, MAPSURF_16BIT | MT_16BIT_ARGB4444, false},
+       {PICT_a4b4g4r4, PICT_x4b4g4r4, MAPSURF_16BIT | MT_16BIT_ARGB4444, true},
+};
+
+#define xFixedToDouble(f) pixman_fixed_to_double(f)
+
+static inline bool too_large(int width, int height)
+{
+       return width > MAX_3D_SIZE || height > MAX_3D_SIZE;
+}
+
+static inline uint32_t gen3_buf_tiling(uint32_t tiling)
+{
+       uint32_t v = 0;
+       switch (tiling) {
+       case I915_TILING_Y: v |= BUF_3D_TILE_WALK_Y;
+       case I915_TILING_X: v |= BUF_3D_TILED_SURFACE;
+       case I915_TILING_NONE: break;
+       }
+       return v;
+}
+
+static inline bool
+gen3_check_pitch_3d(struct kgem_bo *bo)
+{
+       return bo->pitch <= MAX_3D_PITCH;
+}
+
+static uint32_t gen3_get_blend_cntl(int op,
+                                   bool has_component_alpha,
+                                   uint32_t dst_format)
+{
+       uint32_t sblend = gen3_blend_op[op].src_blend;
+       uint32_t dblend = gen3_blend_op[op].dst_blend;
+
+       if (op <= PictOpSrc) /* for clear and src disable blending */
+               return S6_COLOR_WRITE_ONLY;
+
+       /* If there's no dst alpha channel, adjust the blend op so that we'll
+        * treat it as always 1.
+        */
+       if (gen3_blend_op[op].dst_alpha) {
+               if (PICT_FORMAT_A(dst_format) == 0) {
+                       if (sblend == BLENDFACT_DST_ALPHA)
+                               sblend = BLENDFACT_ONE;
+                       else if (sblend == BLENDFACT_INV_DST_ALPHA)
+                               sblend = BLENDFACT_ZERO;
+               }
+
+               /* gen3 engine reads 8bit color buffer into green channel
+                * in cases like color buffer blending etc., and also writes
+                * back green channel.  So with dst_alpha blend we should use
+                * color factor. See spec on "8-bit rendering".
+                */
+               if (dst_format == PICT_a8) {
+                       if (sblend == BLENDFACT_DST_ALPHA)
+                               sblend = BLENDFACT_DST_COLR;
+                       else if (sblend == BLENDFACT_INV_DST_ALPHA)
+                               sblend = BLENDFACT_INV_DST_COLR;
+               }
+       }
+
+       /* If the source alpha is being used, then we should only be in a case
+        * where the source blend factor is 0, and the source blend value is the
+        * mask channels multiplied by the source picture's alpha.
+        */
+       if (has_component_alpha && gen3_blend_op[op].src_alpha) {
+               if (dblend == BLENDFACT_SRC_ALPHA)
+                       dblend = BLENDFACT_SRC_COLR;
+               else if (dblend == BLENDFACT_INV_SRC_ALPHA)
+                       dblend = BLENDFACT_INV_SRC_COLR;
+       }
+
+       return (S6_CBUF_BLEND_ENABLE | S6_COLOR_WRITE_ENABLE |
+               BLENDFUNC_ADD << S6_CBUF_BLEND_FUNC_SHIFT |
+               sblend << S6_CBUF_SRC_BLEND_FACT_SHIFT |
+               dblend << S6_CBUF_DST_BLEND_FACT_SHIFT);
+}
+
+static bool gen3_check_dst_format(uint32_t format)
+{
+       switch (format) {
+       case PICT_a8r8g8b8:
+       case PICT_x8r8g8b8:
+       case PICT_a8b8g8r8:
+       case PICT_x8b8g8r8:
+       case PICT_r5g6b5:
+       case PICT_b5g6r5:
+       case PICT_a1r5g5b5:
+       case PICT_x1r5g5b5:
+       case PICT_a1b5g5r5:
+       case PICT_x1b5g5r5:
+       case PICT_a2r10g10b10:
+       case PICT_x2r10g10b10:
+       case PICT_a2b10g10r10:
+       case PICT_x2b10g10r10:
+       case PICT_a8:
+       case PICT_a4r4g4b4:
+       case PICT_x4r4g4b4:
+       case PICT_a4b4g4r4:
+       case PICT_x4b4g4r4:
+               return true;
+       default:
+               return false;
+       }
+}
+
+static bool gen3_dst_rb_reversed(uint32_t format)
+{
+       switch (format) {
+       case PICT_a8r8g8b8:
+       case PICT_x8r8g8b8:
+       case PICT_r5g6b5:
+       case PICT_a1r5g5b5:
+       case PICT_x1r5g5b5:
+       case PICT_a2r10g10b10:
+       case PICT_x2r10g10b10:
+       case PICT_a8:
+       case PICT_a4r4g4b4:
+       case PICT_x4r4g4b4:
+               return false;
+       default:
+               return true;
+       }
+}
+
+#define DSTORG_HORT_BIAS(x)             ((x)<<20)
+#define DSTORG_VERT_BIAS(x)             ((x)<<16)
+
+static uint32_t gen3_get_dst_format(uint32_t format)
+{
+#define BIAS (DSTORG_HORT_BIAS(0x8) | DSTORG_VERT_BIAS(0x8))
+       switch (format) {
+       default:
+       case PICT_a8r8g8b8:
+       case PICT_x8r8g8b8:
+       case PICT_a8b8g8r8:
+       case PICT_x8b8g8r8:
+               return BIAS | COLR_BUF_ARGB8888;
+       case PICT_r5g6b5:
+       case PICT_b5g6r5:
+               return BIAS | COLR_BUF_RGB565;
+       case PICT_a1r5g5b5:
+       case PICT_x1r5g5b5:
+       case PICT_a1b5g5r5:
+       case PICT_x1b5g5r5:
+               return BIAS | COLR_BUF_ARGB1555;
+       case PICT_a2r10g10b10:
+       case PICT_x2r10g10b10:
+       case PICT_a2b10g10r10:
+       case PICT_x2b10g10r10:
+               return BIAS | COLR_BUF_ARGB2AAA;
+       case PICT_a8:
+               return BIAS | COLR_BUF_8BIT;
+       case PICT_a4r4g4b4:
+       case PICT_x4r4g4b4:
+       case PICT_a4b4g4r4:
+       case PICT_x4b4g4r4:
+               return BIAS | COLR_BUF_ARGB4444;
+       }
+#undef BIAS
+}
+
+static bool gen3_check_format(PicturePtr p)
+{
+       switch (p->format) {
+       case PICT_a8:
+       case PICT_a8r8g8b8:
+       case PICT_x8r8g8b8:
+       case PICT_a8b8g8r8:
+       case PICT_x8b8g8r8:
+       case PICT_a2r10g10b10:
+       case PICT_a2b10g10r10:
+       case PICT_r5g6b5:
+       case PICT_b5g6r5:
+       case PICT_a1r5g5b5:
+       case PICT_a1b5g5r5:
+       case PICT_a4r4g4b4:
+       case PICT_a4b4g4r4:
+               return true;
+       default:
+               return false;
+       }
+}
+
+static bool gen3_check_xformat(PicturePtr p)
+{
+       switch (p->format) {
+       case PICT_a8r8g8b8:
+       case PICT_x8r8g8b8:
+       case PICT_a8b8g8r8:
+       case PICT_x8b8g8r8:
+       case PICT_r5g6b5:
+       case PICT_b5g6r5:
+       case PICT_a1r5g5b5:
+       case PICT_x1r5g5b5:
+       case PICT_a1b5g5r5:
+       case PICT_x1b5g5r5:
+       case PICT_a2r10g10b10:
+       case PICT_x2r10g10b10:
+       case PICT_a2b10g10r10:
+       case PICT_x2b10g10r10:
+       case PICT_a8:
+       case PICT_a4r4g4b4:
+       case PICT_x4r4g4b4:
+       case PICT_a4b4g4r4:
+       case PICT_x4b4g4r4:
+               return true;
+       default:
+               return false;
+       }
+}
+
+static uint32_t gen3_texture_repeat(uint32_t repeat)
+{
+#define REPEAT(x) \
+       (SS3_NORMALIZED_COORDS | \
+        TEXCOORDMODE_##x << SS3_TCX_ADDR_MODE_SHIFT | \
+        TEXCOORDMODE_##x << SS3_TCY_ADDR_MODE_SHIFT)
+       switch (repeat) {
+       default:
+       case RepeatNone:
+               return REPEAT(CLAMP_BORDER);
+       case RepeatNormal:
+               return REPEAT(WRAP);
+       case RepeatPad:
+               return REPEAT(CLAMP_EDGE);
+       case RepeatReflect:
+               return REPEAT(MIRROR);
+       }
+#undef REPEAT
+}
+
+static uint32_t gen3_gradient_repeat(uint32_t repeat)
+{
+#define REPEAT(x) \
+       (SS3_NORMALIZED_COORDS | \
+        TEXCOORDMODE_##x  << SS3_TCX_ADDR_MODE_SHIFT | \
+        TEXCOORDMODE_WRAP << SS3_TCY_ADDR_MODE_SHIFT)
+       switch (repeat) {
+       default:
+       case RepeatNone:
+               return REPEAT(CLAMP_BORDER);
+       case RepeatNormal:
+               return REPEAT(WRAP);
+       case RepeatPad:
+               return REPEAT(CLAMP_EDGE);
+       case RepeatReflect:
+               return REPEAT(MIRROR);
+       }
+#undef REPEAT
+}
+
+static bool gen3_check_repeat(PicturePtr p)
+{
+       if (!p->repeat)
+               return true;
+
+       switch (p->repeatType) {
+       case RepeatNone:
+       case RepeatNormal:
+       case RepeatPad:
+       case RepeatReflect:
+               return true;
+       default:
+               return false;
+       }
+}
+
+static uint32_t gen3_filter(uint32_t filter)
+{
+       switch (filter) {
+       default:
+               assert(0);
+       case PictFilterNearest:
+               return (FILTER_NEAREST << SS2_MAG_FILTER_SHIFT |
+                       FILTER_NEAREST << SS2_MIN_FILTER_SHIFT |
+                       MIPFILTER_NONE << SS2_MIP_FILTER_SHIFT);
+       case PictFilterBilinear:
+               return (FILTER_LINEAR  << SS2_MAG_FILTER_SHIFT |
+                       FILTER_LINEAR  << SS2_MIN_FILTER_SHIFT |
+                       MIPFILTER_NONE << SS2_MIP_FILTER_SHIFT);
+       }
+}
+
+static bool gen3_check_filter(PicturePtr p)
+{
+       switch (p->filter) {
+       case PictFilterNearest:
+       case PictFilterBilinear:
+               return true;
+       default:
+               return false;
+       }
+}
+
+static inline void
+gen3_emit_composite_dstcoord(struct sna *sna, int16_t dstX, int16_t dstY)
+{
+       OUT_VERTEX(dstX);
+       OUT_VERTEX(dstY);
+}
+
+fastcall static void
+gen3_emit_composite_primitive_constant(struct sna *sna,
+                                      const struct sna_composite_op *op,
+                                      const struct sna_composite_rectangles *r)
+{
+       int16_t dst_x = r->dst.x + op->dst.x;
+       int16_t dst_y = r->dst.y + op->dst.y;
+
+       gen3_emit_composite_dstcoord(sna, dst_x + r->width, dst_y + r->height);
+       gen3_emit_composite_dstcoord(sna, dst_x, dst_y + r->height);
+       gen3_emit_composite_dstcoord(sna, dst_x, dst_y);
+}
+
+fastcall static void
+gen3_emit_composite_primitive_identity_gradient(struct sna *sna,
+                                               const struct sna_composite_op *op,
+                                               const struct sna_composite_rectangles *r)
+{
+       int16_t dst_x, dst_y;
+       int16_t src_x, src_y;
+
+       dst_x = r->dst.x + op->dst.x;
+       dst_y = r->dst.y + op->dst.y;
+       src_x = r->src.x + op->src.offset[0];
+       src_y = r->src.y + op->src.offset[1];
+
+       gen3_emit_composite_dstcoord(sna, dst_x + r->width, dst_y + r->height);
+       OUT_VERTEX(src_x + r->width);
+       OUT_VERTEX(src_y + r->height);
+
+       gen3_emit_composite_dstcoord(sna, dst_x, dst_y + r->height);
+       OUT_VERTEX(src_x);
+       OUT_VERTEX(src_y + r->height);
+
+       gen3_emit_composite_dstcoord(sna, dst_x, dst_y);
+       OUT_VERTEX(src_x);
+       OUT_VERTEX(src_y);
+}
+
+fastcall static void
+gen3_emit_composite_primitive_affine_gradient(struct sna *sna,
+                                             const struct sna_composite_op *op,
+                                             const struct sna_composite_rectangles *r)
+{
+       PictTransform *transform = op->src.transform;
+       int16_t dst_x, dst_y;
+       int16_t src_x, src_y;
+       float sx, sy;
+
+       dst_x = r->dst.x + op->dst.x;
+       dst_y = r->dst.y + op->dst.y;
+       src_x = r->src.x + op->src.offset[0];
+       src_y = r->src.y + op->src.offset[1];
+
+       sna_get_transformed_coordinates(src_x + r->width, src_y + r->height,
+                                       transform,
+                                       &sx, &sy);
+       gen3_emit_composite_dstcoord(sna, dst_x + r->width, dst_y + r->height);
+       OUT_VERTEX(sx);
+       OUT_VERTEX(sy);
+
+       sna_get_transformed_coordinates(src_x, src_y + r->height,
+                                       transform,
+                                       &sx, &sy);
+       gen3_emit_composite_dstcoord(sna, dst_x, dst_y + r->height);
+       OUT_VERTEX(sx);
+       OUT_VERTEX(sy);
+
+       sna_get_transformed_coordinates(src_x, src_y,
+                                       transform,
+                                       &sx, &sy);
+       gen3_emit_composite_dstcoord(sna, dst_x, dst_y);
+       OUT_VERTEX(sx);
+       OUT_VERTEX(sy);
+}
+
+fastcall static void
+gen3_emit_composite_primitive_identity_source(struct sna *sna,
+                                             const struct sna_composite_op *op,
+                                             const struct sna_composite_rectangles *r)
+{
+       float w = r->width;
+       float h = r->height;
+       float *v;
+
+       v = sna->render.vertices + sna->render.vertex_used;
+       sna->render.vertex_used += 12;
+
+       v[8] = v[4] = r->dst.x + op->dst.x;
+       v[0] = v[4] + w;
+
+       v[9] = r->dst.y + op->dst.y;
+       v[5] = v[1] = v[9] + h;
+
+       v[10] = v[6] = (r->src.x + op->src.offset[0]) * op->src.scale[0];
+       v[2] = v[6] + w * op->src.scale[0];
+
+       v[11] = (r->src.y + op->src.offset[1]) * op->src.scale[1];
+       v[7] = v[3] = v[11] + h * op->src.scale[1];
+}
+
+fastcall static void
+gen3_emit_composite_primitive_identity_source_no_offset(struct sna *sna,
+                                                       const struct sna_composite_op *op,
+                                                       const struct sna_composite_rectangles *r)
+{
+       float w = r->width;
+       float h = r->height;
+       float *v;
+
+       v = sna->render.vertices + sna->render.vertex_used;
+       sna->render.vertex_used += 12;
+
+       v[8] = v[4] = r->dst.x;
+       v[9] = r->dst.y;
+
+       v[0] = v[4] + w;
+       v[5] = v[1] = v[9] + h;
+
+       v[10] = v[6] = r->src.x * op->src.scale[0];
+       v[11] = r->src.y * op->src.scale[1];
+
+       v[2] = v[6] + w * op->src.scale[0];
+       v[7] = v[3] = v[11] + h * op->src.scale[1];
+}
+
+fastcall static void
+gen3_emit_composite_primitive_affine_source(struct sna *sna,
+                                           const struct sna_composite_op *op,
+                                           const struct sna_composite_rectangles *r)
+{
+       PictTransform *transform = op->src.transform;
+       int16_t dst_x = r->dst.x + op->dst.x;
+       int16_t dst_y = r->dst.y + op->dst.y;
+       int src_x = r->src.x + (int)op->src.offset[0];
+       int src_y = r->src.y + (int)op->src.offset[1];
+       float sx, sy;
+
+       _sna_get_transformed_coordinates(src_x + r->width, src_y + r->height,
+                                        transform,
+                                        &sx, &sy);
+
+       gen3_emit_composite_dstcoord(sna, dst_x + r->width, dst_y + r->height);
+       OUT_VERTEX(sx * op->src.scale[0]);
+       OUT_VERTEX(sy * op->src.scale[1]);
+
+       _sna_get_transformed_coordinates(src_x, src_y + r->height,
+                                        transform,
+                                        &sx, &sy);
+       gen3_emit_composite_dstcoord(sna, dst_x, dst_y + r->height);
+       OUT_VERTEX(sx * op->src.scale[0]);
+       OUT_VERTEX(sy * op->src.scale[1]);
+
+       _sna_get_transformed_coordinates(src_x, src_y,
+                                        transform,
+                                        &sx, &sy);
+       gen3_emit_composite_dstcoord(sna, dst_x, dst_y);
+       OUT_VERTEX(sx * op->src.scale[0]);
+       OUT_VERTEX(sy * op->src.scale[1]);
+}
+
+fastcall static void
+gen3_emit_composite_primitive_constant_identity_mask(struct sna *sna,
+                                                    const struct sna_composite_op *op,
+                                                    const struct sna_composite_rectangles *r)
+{
+       float w = r->width;
+       float h = r->height;
+       float *v;
+
+       v = sna->render.vertices + sna->render.vertex_used;
+       sna->render.vertex_used += 12;
+
+       v[8] = v[4] = r->dst.x + op->dst.x;
+       v[0] = v[4] + w;
+
+       v[9] = r->dst.y + op->dst.y;
+       v[5] = v[1] = v[9] + h;
+
+       v[10] = v[6] = (r->mask.x + op->mask.offset[0]) * op->mask.scale[0];
+       v[2] = v[6] + w * op->mask.scale[0];
+
+       v[11] = (r->mask.y + op->mask.offset[1]) * op->mask.scale[1];
+       v[7] = v[3] = v[11] + h * op->mask.scale[1];
+}
+
+fastcall static void
+gen3_emit_composite_primitive_constant_identity_mask_no_offset(struct sna *sna,
+                                                              const struct sna_composite_op *op,
+                                                              const struct sna_composite_rectangles *r)
+{
+       float w = r->width;
+       float h = r->height;
+       float *v;
+
+       v = sna->render.vertices + sna->render.vertex_used;
+       sna->render.vertex_used += 12;
+
+       v[8] = v[4] = r->dst.x;
+       v[9] = r->dst.y;
+
+       v[0] = v[4] + w;
+       v[5] = v[1] = v[9] + h;
+
+       v[10] = v[6] = r->mask.x * op->mask.scale[0];
+       v[11] = r->mask.y * op->mask.scale[1];
+
+       v[2] = v[6] + w * op->mask.scale[0];
+       v[7] = v[3] = v[11] + h * op->mask.scale[1];
+}
+
+fastcall static void
+gen3_emit_composite_primitive_identity_source_mask(struct sna *sna,
+                                                  const struct sna_composite_op *op,
+                                                  const struct sna_composite_rectangles *r)
+{
+       float dst_x, dst_y;
+       float src_x, src_y;
+       float msk_x, msk_y;
+       float w, h;
+       float *v;
+
+       dst_x = r->dst.x + op->dst.x;
+       dst_y = r->dst.y + op->dst.y;
+       src_x = r->src.x + op->src.offset[0];
+       src_y = r->src.y + op->src.offset[1];
+       msk_x = r->mask.x + op->mask.offset[0];
+       msk_y = r->mask.y + op->mask.offset[1];
+       w = r->width;
+       h = r->height;
+
+       v = sna->render.vertices + sna->render.vertex_used;
+       sna->render.vertex_used += 18;
+
+       v[0] = dst_x + w;
+       v[1] = dst_y + h;
+       v[2] = (src_x + w) * op->src.scale[0];
+       v[3] = (src_y + h) * op->src.scale[1];
+       v[4] = (msk_x + w) * op->mask.scale[0];
+       v[5] = (msk_y + h) * op->mask.scale[1];
+
+       v[6] = dst_x;
+       v[7] = v[1];
+       v[8] = src_x * op->src.scale[0];
+       v[9] = v[3];
+       v[10] = msk_x * op->mask.scale[0];
+       v[11] =v[5];
+
+       v[12] = v[6];
+       v[13] = dst_y;
+       v[14] = v[8];
+       v[15] = src_y * op->src.scale[1];
+       v[16] = v[10];
+       v[17] = msk_y * op->mask.scale[1];
+}
+
+fastcall static void
+gen3_emit_composite_primitive_affine_source_mask(struct sna *sna,
+                                                const struct sna_composite_op *op,
+                                                const struct sna_composite_rectangles *r)
+{
+       int16_t src_x, src_y;
+       float dst_x, dst_y;
+       float msk_x, msk_y;
+       float w, h;
+       float *v;
+
+       dst_x = r->dst.x + op->dst.x;
+       dst_y = r->dst.y + op->dst.y;
+       src_x = r->src.x + op->src.offset[0];
+       src_y = r->src.y + op->src.offset[1];
+       msk_x = r->mask.x + op->mask.offset[0];
+       msk_y = r->mask.y + op->mask.offset[1];
+       w = r->width;
+       h = r->height;
+
+       v = sna->render.vertices + sna->render.vertex_used;
+       sna->render.vertex_used += 18;
+
+       v[0] = dst_x + w;
+       v[1] = dst_y + h;
+       sna_get_transformed_coordinates(src_x + r->width, src_y + r->height,
+                                       op->src.transform,
+                                       &v[2], &v[3]);
+       v[2] *= op->src.scale[0];
+       v[3] *= op->src.scale[1];
+       v[4] = (msk_x + w) * op->mask.scale[0];
+       v[5] = (msk_y + h) * op->mask.scale[1];
+
+       v[6] = dst_x;
+       v[7] = v[1];
+       sna_get_transformed_coordinates(src_x, src_y + r->height,
+                                       op->src.transform,
+                                       &v[8], &v[9]);
+       v[8] *= op->src.scale[0];
+       v[9] *= op->src.scale[1];
+       v[10] = msk_x * op->mask.scale[0];
+       v[11] =v[5];
+
+       v[12] = v[6];
+       v[13] = dst_y;
+       sna_get_transformed_coordinates(src_x, src_y,
+                                       op->src.transform,
+                                       &v[14], &v[15]);
+       v[14] *= op->src.scale[0];
+       v[15] *= op->src.scale[1];
+       v[16] = v[10];
+       v[17] = msk_y * op->mask.scale[1];
+}
+
+static void
+gen3_emit_composite_texcoord(struct sna *sna,
+                            const struct sna_composite_channel *channel,
+                            int16_t x, int16_t y)
+{
+       float s = 0, t = 0, w = 1;
+
+       switch (channel->u.gen3.type) {
+       case SHADER_OPACITY:
+       case SHADER_NONE:
+       case SHADER_ZERO:
+       case SHADER_BLACK:
+       case SHADER_WHITE:
+       case SHADER_CONSTANT:
+               break;
+
+       case SHADER_LINEAR:
+       case SHADER_RADIAL:
+       case SHADER_TEXTURE:
+               x += channel->offset[0];
+               y += channel->offset[1];
+               if (channel->is_affine) {
+                       sna_get_transformed_coordinates(x, y,
+                                                       channel->transform,
+                                                       &s, &t);
+                       OUT_VERTEX(s * channel->scale[0]);
+                       OUT_VERTEX(t * channel->scale[1]);
+               } else {
+                       sna_get_transformed_coordinates_3d(x, y,
+                                                          channel->transform,
+                                                          &s, &t, &w);
+                       OUT_VERTEX(s * channel->scale[0]);
+                       OUT_VERTEX(t * channel->scale[1]);
+                       OUT_VERTEX(0);
+                       OUT_VERTEX(w);
+               }
+               break;
+       }
+}
+
+static void
+gen3_emit_composite_vertex(struct sna *sna,
+                          const struct sna_composite_op *op,
+                          int16_t srcX, int16_t srcY,
+                          int16_t maskX, int16_t maskY,
+                          int16_t dstX, int16_t dstY)
+{
+       gen3_emit_composite_dstcoord(sna, dstX, dstY);
+       gen3_emit_composite_texcoord(sna, &op->src, srcX, srcY);
+       gen3_emit_composite_texcoord(sna, &op->mask, maskX, maskY);
+}
+
+fastcall static void
+gen3_emit_composite_primitive(struct sna *sna,
+                             const struct sna_composite_op *op,
+                             const struct sna_composite_rectangles *r)
+{
+       gen3_emit_composite_vertex(sna, op,
+                                  r->src.x + r->width,
+                                  r->src.y + r->height,
+                                  r->mask.x + r->width,
+                                  r->mask.y + r->height,
+                                  op->dst.x + r->dst.x + r->width,
+                                  op->dst.y + r->dst.y + r->height);
+       gen3_emit_composite_vertex(sna, op,
+                                  r->src.x,
+                                  r->src.y + r->height,
+                                  r->mask.x,
+                                  r->mask.y + r->height,
+                                  op->dst.x + r->dst.x,
+                                  op->dst.y + r->dst.y + r->height);
+       gen3_emit_composite_vertex(sna, op,
+                                  r->src.x,
+                                  r->src.y,
+                                  r->mask.x,
+                                  r->mask.y,
+                                  op->dst.x + r->dst.x,
+                                  op->dst.y + r->dst.y);
+}
+
+static inline void
+gen3_2d_perspective(struct sna *sna, int in, int out)
+{
+       gen3_fs_rcp(out, 0, gen3_fs_operand(in, W, W, W, W));
+       gen3_fs_mul(out,
+                   gen3_fs_operand(in, X, Y, ZERO, ONE),
+                   gen3_fs_operand_reg(out));
+}
+
+static inline void
+gen3_linear_coord(struct sna *sna,
+                 const struct sna_composite_channel *channel,
+                 int in, int out)
+{
+       int c = channel->u.gen3.constants;
+
+       if (!channel->is_affine) {
+               gen3_2d_perspective(sna, in, FS_U0);
+               in = FS_U0;
+       }
+
+       gen3_fs_mov(out, gen3_fs_operand_zero());
+       gen3_fs_dp3(out, MASK_X,
+                   gen3_fs_operand(in, X, Y, ONE, ZERO),
+                   gen3_fs_operand_reg(c));
+}
+
+static void
+gen3_radial_coord(struct sna *sna,
+                 const struct sna_composite_channel *channel,
+                 int in, int out)
+{
+       int c = channel->u.gen3.constants;
+
+       if (!channel->is_affine) {
+               gen3_2d_perspective(sna, in, FS_U0);
+               in = FS_U0;
+       }
+
+       switch (channel->u.gen3.mode) {
+       case RADIAL_ONE:
+               /*
+                  pdx = (x - c1x) / dr, pdy = (y - c1y) / dr;
+                  r² = pdx*pdx + pdy*pdy
+                  t = r²/sqrt(r²) - r1/dr;
+                  */
+               gen3_fs_mad(FS_U0, MASK_X | MASK_Y,
+                           gen3_fs_operand(in, X, Y, ZERO, ZERO),
+                           gen3_fs_operand(c, Z, Z, ZERO, ZERO),
+                           gen3_fs_operand(c, NEG_X, NEG_Y, ZERO, ZERO));
+               gen3_fs_dp2add(FS_U0, MASK_X,
+                              gen3_fs_operand(FS_U0, X, Y, ZERO, ZERO),
+                              gen3_fs_operand(FS_U0, X, Y, ZERO, ZERO),
+                              gen3_fs_operand_zero());
+               gen3_fs_rsq(out, MASK_X, gen3_fs_operand(FS_U0, X, X, X, X));
+               gen3_fs_mad(out, 0,
+                           gen3_fs_operand(FS_U0, X, ZERO, ZERO, ZERO),
+                           gen3_fs_operand(out, X, ZERO, ZERO, ZERO),
+                           gen3_fs_operand(c, W, ZERO, ZERO, ZERO));
+               break;
+
+       case RADIAL_TWO:
+               /*
+                  pdx = x - c1x, pdy = y - c1y;
+                  A = dx² + dy² - dr²
+                  B = -2*(pdx*dx + pdy*dy + r1*dr);
+                  C = pdx² + pdy² - r1²;
+                  det = B*B - 4*A*C;
+                  t = (-B + sqrt (det)) / (2 * A)
+                  */
+
+               /* u0.x = pdx, u0.y = pdy, u[0].z = r1; */
+               gen3_fs_add(FS_U0,
+                           gen3_fs_operand(in, X, Y, ZERO, ZERO),
+                           gen3_fs_operand(c, X, Y, Z, ZERO));
+               /* u0.x = pdx, u0.y = pdy, u[0].z = r1, u[0].w = B; */
+               gen3_fs_dp3(FS_U0, MASK_W,
+                           gen3_fs_operand(FS_U0, X, Y, ONE, ZERO),
+                           gen3_fs_operand(c+1, X, Y, Z, ZERO));
+               /* u1.x = pdx² + pdy² - r1²; [C] */
+               gen3_fs_dp3(FS_U1, MASK_X,
+                           gen3_fs_operand(FS_U0, X, Y, Z, ZERO),
+                           gen3_fs_operand(FS_U0, X, Y, NEG_Z, ZERO));
+               /* u1.x = C, u1.y = B, u1.z=-4*A; */
+               gen3_fs_mov_masked(FS_U1, MASK_Y, gen3_fs_operand(FS_U0, W, W, W, W));
+               gen3_fs_mov_masked(FS_U1, MASK_Z, gen3_fs_operand(c, W, W, W, W));
+               /* u1.x = B² - 4*A*C */
+               gen3_fs_dp2add(FS_U1, MASK_X,
+                              gen3_fs_operand(FS_U1, X, Y, ZERO, ZERO),
+                              gen3_fs_operand(FS_U1, Z, Y, ZERO, ZERO),
+                              gen3_fs_operand_zero());
+               /* out.x = -B + sqrt (B² - 4*A*C), */
+               gen3_fs_rsq(out, MASK_X, gen3_fs_operand(FS_U1, X, X, X, X));
+               gen3_fs_mad(out, MASK_X,
+                           gen3_fs_operand(out, X, ZERO, ZERO, ZERO),
+                           gen3_fs_operand(FS_U1, X, ZERO, ZERO, ZERO),
+                           gen3_fs_operand(FS_U0, NEG_W, ZERO, ZERO, ZERO));
+               /* out.x = (-B + sqrt (B² - 4*A*C)) / (2 * A), */
+               gen3_fs_mul(out,
+                           gen3_fs_operand(out, X, ZERO, ZERO, ZERO),
+                           gen3_fs_operand(c+1, W, ZERO, ZERO, ZERO));
+               break;
+       }
+}
+
+static void
+gen3_composite_emit_shader(struct sna *sna,
+                          const struct sna_composite_op *op,
+                          uint8_t blend)
+{
+       bool dst_is_alpha = PIXMAN_FORMAT_RGB(op->dst.format) == 0;
+       const struct sna_composite_channel *src, *mask;
+       struct gen3_render_state *state = &sna->render_state.gen3;
+       uint32_t shader_offset, id;
+       int src_reg, mask_reg;
+       int t, length;
+
+       src = &op->src;
+       mask = &op->mask;
+       if (mask->u.gen3.type == SHADER_NONE)
+               mask = NULL;
+
+       if (mask && src->is_opaque &&
+           gen3_blend_op[blend].src_alpha &&
+           op->has_component_alpha) {
+               src = mask;
+               mask = NULL;
+       }
+
+       id = (src->u.gen3.type |
+             src->is_affine << 4 |
+             src->alpha_fixup << 5 |
+             src->rb_reversed << 6);
+       if (mask) {
+               id |= (mask->u.gen3.type << 8 |
+                      mask->is_affine << 12 |
+                      gen3_blend_op[blend].src_alpha << 13 |
+                      op->has_component_alpha << 14 |
+                      mask->alpha_fixup << 15 |
+                      mask->rb_reversed << 16);
+       }
+       id |= dst_is_alpha << 24;
+       id |= op->rb_reversed << 25;
+
+       if (id == state->last_shader)
+               return;
+
+       state->last_shader = id;
+
+       shader_offset = sna->kgem.nbatch++;
+       t = 0;
+       switch (src->u.gen3.type) {
+       case SHADER_NONE:
+       case SHADER_OPACITY:
+               assert(0);
+       case SHADER_ZERO:
+       case SHADER_BLACK:
+       case SHADER_WHITE:
+               break;
+       case SHADER_CONSTANT:
+               gen3_fs_dcl(FS_T8);
+               src_reg = FS_T8;
+               break;
+       case SHADER_TEXTURE:
+       case SHADER_RADIAL:
+       case SHADER_LINEAR:
+               gen3_fs_dcl(FS_S0);
+               gen3_fs_dcl(FS_T0);
+               t++;
+               break;
+       }
+
+       if (mask == NULL) {
+               switch (src->u.gen3.type) {
+               case SHADER_ZERO:
+                       gen3_fs_mov(FS_OC, gen3_fs_operand_zero());
+                       goto done;
+               case SHADER_BLACK:
+                       if (dst_is_alpha)
+                               gen3_fs_mov(FS_OC, gen3_fs_operand_one());
+                       else
+                               gen3_fs_mov(FS_OC, gen3_fs_operand(FS_R0, ZERO, ZERO, ZERO, ONE));
+                       goto done;
+               case SHADER_WHITE:
+                       gen3_fs_mov(FS_OC, gen3_fs_operand_one());
+                       goto done;
+               }
+               if (src->alpha_fixup && dst_is_alpha) {
+                       gen3_fs_mov(FS_OC, gen3_fs_operand_one());
+                       goto done;
+               }
+               /* No mask, so load directly to output color */
+               if (src->u.gen3.type != SHADER_CONSTANT) {
+                       if (dst_is_alpha || src->rb_reversed ^ op->rb_reversed)
+                               src_reg = FS_R0;
+                       else
+                               src_reg = FS_OC;
+               }
+               switch (src->u.gen3.type) {
+               case SHADER_LINEAR:
+                       gen3_linear_coord(sna, src, FS_T0, FS_R0);
+                       gen3_fs_texld(src_reg, FS_S0, FS_R0);
+                       break;
+
+               case SHADER_RADIAL:
+                       gen3_radial_coord(sna, src, FS_T0, FS_R0);
+                       gen3_fs_texld(src_reg, FS_S0, FS_R0);
+                       break;
+
+               case SHADER_TEXTURE:
+                       if (src->is_affine)
+                               gen3_fs_texld(src_reg, FS_S0, FS_T0);
+                       else
+                               gen3_fs_texldp(src_reg, FS_S0, FS_T0);
+                       break;
+
+               case SHADER_NONE:
+               case SHADER_WHITE:
+               case SHADER_BLACK:
+               case SHADER_ZERO:
+                       assert(0);
+               case SHADER_CONSTANT:
+                       break;
+               }
+
+               if (src_reg != FS_OC) {
+                       if (src->alpha_fixup)
+                               gen3_fs_mov(FS_OC,
+                                           src->rb_reversed ^ op->rb_reversed ?
+                                           gen3_fs_operand(src_reg, Z, Y, X, ONE) :
+                                           gen3_fs_operand(src_reg, X, Y, Z, ONE));
+                       else if (dst_is_alpha)
+                               gen3_fs_mov(FS_OC, gen3_fs_operand(src_reg, W, W, W, W));
+                       else if (src->rb_reversed ^ op->rb_reversed)
+                               gen3_fs_mov(FS_OC, gen3_fs_operand(src_reg, Z, Y, X, W));
+                       else
+                               gen3_fs_mov(FS_OC, gen3_fs_operand_reg(src_reg));
+               } else if (src->alpha_fixup)
+                       gen3_fs_mov_masked(FS_OC, MASK_W, gen3_fs_operand_one());
+       } else {
+               int out_reg = FS_OC;
+               if (op->rb_reversed)
+                       out_reg = FS_U0;
+
+               switch (mask->u.gen3.type) {
+               case SHADER_CONSTANT:
+                       gen3_fs_dcl(FS_T9);
+                       mask_reg = FS_T9;
+                       break;
+               case SHADER_TEXTURE:
+               case SHADER_LINEAR:
+               case SHADER_RADIAL:
+                       gen3_fs_dcl(FS_S0 + t);
+                       /* fall through */
+               case SHADER_OPACITY:
+                       gen3_fs_dcl(FS_T0 + t);
+                       break;
+               case SHADER_ZERO:
+               case SHADER_BLACK:
+                       assert(0);
+               case SHADER_NONE:
+               case SHADER_WHITE:
+                       break;
+               }
+
+               t = 0;
+               switch (src->u.gen3.type) {
+               case SHADER_LINEAR:
+                       gen3_linear_coord(sna, src, FS_T0, FS_R0);
+                       gen3_fs_texld(FS_R0, FS_S0, FS_R0);
+                       src_reg = FS_R0;
+                       t++;
+                       break;
+
+               case SHADER_RADIAL:
+                       gen3_radial_coord(sna, src, FS_T0, FS_R0);
+                       gen3_fs_texld(FS_R0, FS_S0, FS_R0);
+                       src_reg = FS_R0;
+                       t++;
+                       break;
+
+               case SHADER_TEXTURE:
+                       if (src->is_affine)
+                               gen3_fs_texld(FS_R0, FS_S0, FS_T0);
+                       else
+                               gen3_fs_texldp(FS_R0, FS_S0, FS_T0);
+                       src_reg = FS_R0;
+                       t++;
+                       break;
+
+               case SHADER_CONSTANT:
+               case SHADER_NONE:
+               case SHADER_ZERO:
+               case SHADER_BLACK:
+               case SHADER_WHITE:
+                       break;
+               }
+               if (src->alpha_fixup)
+                       gen3_fs_mov_masked(src_reg, MASK_W, gen3_fs_operand_one());
+               if (src->rb_reversed)
+                       gen3_fs_mov(src_reg, gen3_fs_operand(src_reg, Z, Y, X, W));
+
+               switch (mask->u.gen3.type) {
+               case SHADER_LINEAR:
+                       gen3_linear_coord(sna, mask, FS_T0 + t, FS_R1);
+                       gen3_fs_texld(FS_R1, FS_S0 + t, FS_R1);
+                       mask_reg = FS_R1;
+                       break;
+
+               case SHADER_RADIAL:
+                       gen3_radial_coord(sna, mask, FS_T0 + t, FS_R1);
+                       gen3_fs_texld(FS_R1, FS_S0 + t, FS_R1);
+                       mask_reg = FS_R1;
+                       break;
+
+               case SHADER_TEXTURE:
+                       if (mask->is_affine)
+                               gen3_fs_texld(FS_R1, FS_S0 + t, FS_T0 + t);
+                       else
+                               gen3_fs_texldp(FS_R1, FS_S0 + t, FS_T0 + t);
+                       mask_reg = FS_R1;
+                       break;
+
+               case SHADER_OPACITY:
+                       switch (src->u.gen3.type) {
+                       case SHADER_BLACK:
+                       case SHADER_WHITE:
+                               if (dst_is_alpha || src->u.gen3.type == SHADER_WHITE) {
+                                       gen3_fs_mov(out_reg,
+                                                   gen3_fs_operand(FS_T0 + t, X, X, X, X));
+                               } else {
+                                       gen3_fs_mov(out_reg,
+                                                   gen3_fs_operand(FS_T0 + t, ZERO, ZERO, ZERO, X));
+                               }
+                               break;
+                       default:
+                               if (dst_is_alpha) {
+                                       gen3_fs_mul(out_reg,
+                                                   gen3_fs_operand(src_reg, W, W, W, W),
+                                                   gen3_fs_operand(FS_T0 + t, X, X, X, X));
+                               } else {
+                                       gen3_fs_mul(out_reg,
+                                                   gen3_fs_operand(src_reg, X, Y, Z, W),
+                                                   gen3_fs_operand(FS_T0 + t, X, X, X, X));
+                               }
+                       }
+                       goto mask_done;
+
+               case SHADER_CONSTANT:
+               case SHADER_ZERO:
+               case SHADER_BLACK:
+               case SHADER_WHITE:
+               case SHADER_NONE:
+                       break;
+               }
+               if (mask->alpha_fixup)
+                       gen3_fs_mov_masked(mask_reg, MASK_W, gen3_fs_operand_one());
+               if (mask->rb_reversed)
+                       gen3_fs_mov(mask_reg, gen3_fs_operand(mask_reg, Z, Y, X, W));
+
+               if (dst_is_alpha) {
+                       switch (src->u.gen3.type) {
+                       case SHADER_BLACK:
+                       case SHADER_WHITE:
+                               gen3_fs_mov(out_reg,
+                                           gen3_fs_operand(mask_reg, W, W, W, W));
+                               break;
+                       default:
+                               gen3_fs_mul(out_reg,
+                                           gen3_fs_operand(src_reg, W, W, W, W),
+                                           gen3_fs_operand(mask_reg, W, W, W, W));
+                               break;
+                       }
+               } else {
+                       /* If component alpha is active in the mask and the blend
+                        * operation uses the source alpha, then we know we don't
+                        * need the source value (otherwise we would have hit a
+                        * fallback earlier), so we provide the source alpha (src.A *
+                        * mask.X) as output color.
+                        * Conversely, if CA is set and we don't need the source alpha,
+                        * then we produce the source value (src.X * mask.X) and the
+                        * source alpha is unused.  Otherwise, we provide the non-CA
+                        * source value (src.X * mask.A).
+                        */
+                       if (op->has_component_alpha) {
+                               switch (src->u.gen3.type) {
+                               case SHADER_BLACK:
+                                       if (gen3_blend_op[blend].src_alpha)
+                                               gen3_fs_mov(out_reg,
+                                                           gen3_fs_operand_reg(mask_reg));
+                                       else
+                                               gen3_fs_mov(out_reg,
+                                                           gen3_fs_operand(mask_reg, ZERO, ZERO, ZERO, W));
+                                       break;
+                               case SHADER_WHITE:
+                                       gen3_fs_mov(out_reg,
+                                                   gen3_fs_operand_reg(mask_reg));
+                                       break;
+                               default:
+                                       if (gen3_blend_op[blend].src_alpha)
+                                               gen3_fs_mul(out_reg,
+                                                           gen3_fs_operand(src_reg, W, W, W, W),
+                                                           gen3_fs_operand_reg(mask_reg));
+                                       else
+                                               gen3_fs_mul(out_reg,
+                                                           gen3_fs_operand_reg(src_reg),
+                                                           gen3_fs_operand_reg(mask_reg));
+                                       break;
+                               }
+                       } else {
+                               switch (src->u.gen3.type) {
+                               case SHADER_WHITE:
+                                       gen3_fs_mov(out_reg,
+                                                   gen3_fs_operand(mask_reg, W, W, W, W));
+                                       break;
+                               case SHADER_BLACK:
+                                       gen3_fs_mov(out_reg,
+                                                   gen3_fs_operand(mask_reg, ZERO, ZERO, ZERO, W));
+                                       break;
+                               default:
+                                       gen3_fs_mul(out_reg,
+                                                   gen3_fs_operand_reg(src_reg),
+                                                   gen3_fs_operand(mask_reg, W, W, W, W));
+                                       break;
+                               }
+                       }
+               }
+mask_done:
+               if (op->rb_reversed)
+                       gen3_fs_mov(FS_OC, gen3_fs_operand(FS_U0, Z, Y, X, W));
+       }
+
+done:
+       length = sna->kgem.nbatch - shader_offset;
+       sna->kgem.batch[shader_offset] =
+               _3DSTATE_PIXEL_SHADER_PROGRAM | (length - 2);
+}
+
+static uint32_t gen3_ms_tiling(uint32_t tiling)
+{
+       uint32_t v = 0;
+       switch (tiling) {
+       case I915_TILING_Y: v |= MS3_TILE_WALK;
+       case I915_TILING_X: v |= MS3_TILED_SURFACE;
+       case I915_TILING_NONE: break;
+       }
+       return v;
+}
+
+static void gen3_emit_invariant(struct sna *sna)
+{
+       /* Disable independent alpha blend */
+       OUT_BATCH(_3DSTATE_INDEPENDENT_ALPHA_BLEND_CMD | IAB_MODIFY_ENABLE |
+                 IAB_MODIFY_FUNC | BLENDFUNC_ADD << IAB_FUNC_SHIFT |
+                 IAB_MODIFY_SRC_FACTOR | BLENDFACT_ONE << IAB_SRC_FACTOR_SHIFT |
+                 IAB_MODIFY_DST_FACTOR | BLENDFACT_ZERO << IAB_DST_FACTOR_SHIFT);
+
+       OUT_BATCH(_3DSTATE_COORD_SET_BINDINGS |
+                 CSB_TCB(0, 0) |
+                 CSB_TCB(1, 1) |
+                 CSB_TCB(2, 2) |
+                 CSB_TCB(3, 3) |
+                 CSB_TCB(4, 4) |
+                 CSB_TCB(5, 5) |
+                 CSB_TCB(6, 6) |
+                 CSB_TCB(7, 7));
+
+       OUT_BATCH(_3DSTATE_LOAD_STATE_IMMEDIATE_1 | I1_LOAD_S(3) | I1_LOAD_S(4) | I1_LOAD_S(5) | I1_LOAD_S(6) | 3);
+       OUT_BATCH(0); /* Disable texture coordinate wrap-shortest */
+       OUT_BATCH((1 << S4_POINT_WIDTH_SHIFT) |
+                 S4_LINE_WIDTH_ONE |
+                 S4_CULLMODE_NONE |
+                 S4_VFMT_XY);
+       OUT_BATCH(0); /* Disable fog/stencil. *Enable* write mask. */
+       OUT_BATCH(S6_COLOR_WRITE_ONLY); /* Disable blending, depth */
+
+       OUT_BATCH(_3DSTATE_SCISSOR_ENABLE_CMD | DISABLE_SCISSOR_RECT);
+       OUT_BATCH(_3DSTATE_DEPTH_SUBRECT_DISABLE);
+
+       OUT_BATCH(_3DSTATE_LOAD_INDIRECT);
+       OUT_BATCH(0x00000000);
+
+       OUT_BATCH(_3DSTATE_STIPPLE);
+       OUT_BATCH(0x00000000);
+
+       sna->render_state.gen3.need_invariant = false;
+}
+
+#define MAX_OBJECTS 3 /* worst case: dst + src + mask  */
+
+static void
+gen3_get_batch(struct sna *sna)
+{
+       kgem_set_mode(&sna->kgem, KGEM_RENDER);
+
+       if (!kgem_check_batch(&sna->kgem, 200)) {
+               DBG(("%s: flushing batch: size %d > %d\n",
+                    __FUNCTION__, 200,
+                    sna->kgem.surface-sna->kgem.nbatch));
+               kgem_submit(&sna->kgem);
+               _kgem_set_mode(&sna->kgem, KGEM_RENDER);
+       }
+
+       if (!kgem_check_reloc(&sna->kgem, MAX_OBJECTS)) {
+               DBG(("%s: flushing batch: reloc %d >= %d\n",
+                    __FUNCTION__,
+                    sna->kgem.nreloc,
+                    (int)KGEM_RELOC_SIZE(&sna->kgem) - MAX_OBJECTS));
+               kgem_submit(&sna->kgem);
+               _kgem_set_mode(&sna->kgem, KGEM_RENDER);
+       }
+
+       if (!kgem_check_exec(&sna->kgem, MAX_OBJECTS)) {
+               DBG(("%s: flushing batch: exec %d >= %d\n",
+                    __FUNCTION__,
+                    sna->kgem.nexec,
+                    (int)KGEM_EXEC_SIZE(&sna->kgem) - MAX_OBJECTS - 1));
+               kgem_submit(&sna->kgem);
+               _kgem_set_mode(&sna->kgem, KGEM_RENDER);
+       }
+
+       if (sna->render_state.gen3.need_invariant)
+               gen3_emit_invariant(sna);
+#undef MAX_OBJECTS
+}
+
+static void gen3_emit_target(struct sna *sna,
+                            struct kgem_bo *bo,
+                            int width,
+                            int height,
+                            int format)
+{
+       struct gen3_render_state *state = &sna->render_state.gen3;
+
+       assert(!too_large(width, height));
+
+       /* BUF_INFO is an implicit flush, so skip if the target is unchanged. */
+       assert(bo->unique_id != 0);
+       if (bo->unique_id != state->current_dst) {
+               uint32_t v;
+
+               DBG(("%s: setting new target id=%d, handle=%d\n",
+                    __FUNCTION__, bo->unique_id, bo->handle));
+
+               OUT_BATCH(_3DSTATE_BUF_INFO_CMD);
+               OUT_BATCH(BUF_3D_ID_COLOR_BACK |
+                         gen3_buf_tiling(bo->tiling) |
+                         bo->pitch);
+               OUT_BATCH(kgem_add_reloc(&sna->kgem, sna->kgem.nbatch,
+                                        bo,
+                                        I915_GEM_DOMAIN_RENDER << 16 |
+                                        I915_GEM_DOMAIN_RENDER,
+                                        0));
+
+               OUT_BATCH(_3DSTATE_DST_BUF_VARS_CMD);
+               OUT_BATCH(gen3_get_dst_format(format));
+
+               v = DRAW_YMAX(height - 1) | DRAW_XMAX(width - 1);
+               if (v != state->last_drawrect_limit) {
+                       OUT_BATCH(_3DSTATE_DRAW_RECT_CMD);
+                       OUT_BATCH(0); /* XXX dither origin? */
+                       OUT_BATCH(0);
+                       OUT_BATCH(v);
+                       OUT_BATCH(0);
+                       state->last_drawrect_limit = v;
+               }
+
+               state->current_dst = bo->unique_id;
+       }
+       kgem_bo_mark_dirty(bo);
+}
+
+static void gen3_emit_composite_state(struct sna *sna,
+                                     const struct sna_composite_op *op)
+{
+       struct gen3_render_state *state = &sna->render_state.gen3;
+       uint32_t map[4];
+       uint32_t sampler[4];
+       struct kgem_bo *bo[2];
+       unsigned int tex_count, n;
+       uint32_t ss2;
+
+       gen3_get_batch(sna);
+
+       if (kgem_bo_is_dirty(op->src.bo) || kgem_bo_is_dirty(op->mask.bo)) {
+               if (op->src.bo == op->dst.bo || op->mask.bo == op->dst.bo)
+                       OUT_BATCH(MI_FLUSH | MI_INVALIDATE_MAP_CACHE);
+               else
+                       OUT_BATCH(_3DSTATE_MODES_5_CMD |
+                                 PIPELINE_FLUSH_RENDER_CACHE |
+                                 PIPELINE_FLUSH_TEXTURE_CACHE);
+               kgem_clear_dirty(&sna->kgem);
+       }
+
+       gen3_emit_target(sna,
+                        op->dst.bo,
+                        op->dst.width,
+                        op->dst.height,
+                        op->dst.format);
+
+       ss2 = ~0;
+       tex_count = 0;
+       switch (op->src.u.gen3.type) {
+       case SHADER_OPACITY:
+       case SHADER_NONE:
+               assert(0);
+       case SHADER_ZERO:
+       case SHADER_BLACK:
+       case SHADER_WHITE:
+               break;
+       case SHADER_CONSTANT:
+               if (op->src.u.gen3.mode != state->last_diffuse) {
+                       OUT_BATCH(_3DSTATE_DFLT_DIFFUSE_CMD);
+                       OUT_BATCH(op->src.u.gen3.mode);
+                       state->last_diffuse = op->src.u.gen3.mode;
+               }
+               break;
+       case SHADER_LINEAR:
+       case SHADER_RADIAL:
+       case SHADER_TEXTURE:
+               ss2 &= ~S2_TEXCOORD_FMT(tex_count, TEXCOORDFMT_NOT_PRESENT);
+               ss2 |= S2_TEXCOORD_FMT(tex_count,
+                                      op->src.is_affine ? TEXCOORDFMT_2D : TEXCOORDFMT_4D);
+               map[tex_count * 2 + 0] =
+                       op->src.card_format |
+                       gen3_ms_tiling(op->src.bo->tiling) |
+                       (op->src.height - 1) << MS3_HEIGHT_SHIFT |
+                       (op->src.width - 1) << MS3_WIDTH_SHIFT;
+               map[tex_count * 2 + 1] =
+                       (op->src.bo->pitch / 4 - 1) << MS4_PITCH_SHIFT;
+
+               sampler[tex_count * 2 + 0] = op->src.filter;
+               sampler[tex_count * 2 + 1] =
+                       op->src.repeat |
+                       tex_count << SS3_TEXTUREMAP_INDEX_SHIFT;
+               bo[tex_count] = op->src.bo;
+               tex_count++;
+               break;
+       }
+       switch (op->mask.u.gen3.type) {
+       case SHADER_NONE:
+       case SHADER_ZERO:
+       case SHADER_BLACK:
+       case SHADER_WHITE:
+               break;
+       case SHADER_CONSTANT:
+               if (op->mask.u.gen3.mode != state->last_specular) {
+                       OUT_BATCH(_3DSTATE_DFLT_SPEC_CMD);
+                       OUT_BATCH(op->mask.u.gen3.mode);
+                       state->last_specular = op->mask.u.gen3.mode;
+               }
+               break;
+       case SHADER_LINEAR:
+       case SHADER_RADIAL:
+       case SHADER_TEXTURE:
+               ss2 &= ~S2_TEXCOORD_FMT(tex_count, TEXCOORDFMT_NOT_PRESENT);
+               ss2 |= S2_TEXCOORD_FMT(tex_count,
+                                      op->mask.is_affine ? TEXCOORDFMT_2D : TEXCOORDFMT_4D);
+               map[tex_count * 2 + 0] =
+                       op->mask.card_format |
+                       gen3_ms_tiling(op->mask.bo->tiling) |
+                       (op->mask.height - 1) << MS3_HEIGHT_SHIFT |
+                       (op->mask.width - 1) << MS3_WIDTH_SHIFT;
+               map[tex_count * 2 + 1] =
+                       (op->mask.bo->pitch / 4 - 1) << MS4_PITCH_SHIFT;
+
+               sampler[tex_count * 2 + 0] = op->mask.filter;
+               sampler[tex_count * 2 + 1] =
+                       op->mask.repeat |
+                       tex_count << SS3_TEXTUREMAP_INDEX_SHIFT;
+               bo[tex_count] = op->mask.bo;
+               tex_count++;
+               break;
+       case SHADER_OPACITY:
+               ss2 &= ~S2_TEXCOORD_FMT(tex_count, TEXCOORDFMT_NOT_PRESENT);
+               ss2 |= S2_TEXCOORD_FMT(tex_count, TEXCOORDFMT_1D);
+               break;
+       }
+
+       {
+               uint32_t blend_offset = sna->kgem.nbatch;
+
+               OUT_BATCH(_3DSTATE_LOAD_STATE_IMMEDIATE_1 | I1_LOAD_S(2) | I1_LOAD_S(6) | 1);
+               OUT_BATCH(ss2);
+               OUT_BATCH(gen3_get_blend_cntl(op->op,
+                                             op->has_component_alpha,
+                                             op->dst.format));
+
+               if (memcmp(sna->kgem.batch + state->last_blend + 1,
+                          sna->kgem.batch + blend_offset + 1,
+                          2 * 4) == 0)
+                       sna->kgem.nbatch = blend_offset;
+               else
+                       state->last_blend = blend_offset;
+       }
+
+       if (op->u.gen3.num_constants) {
+               int count = op->u.gen3.num_constants;
+               if (state->last_constants) {
+                       int last = sna->kgem.batch[state->last_constants+1];
+                       if (last == (1 << (count >> 2)) - 1 &&
+                           memcmp(&sna->kgem.batch[state->last_constants+2],
+                                  op->u.gen3.constants,
+                                  count * sizeof(uint32_t)) == 0)
+                               count = 0;
+               }
+               if (count) {
+                       state->last_constants = sna->kgem.nbatch;
+                       OUT_BATCH(_3DSTATE_PIXEL_SHADER_CONSTANTS | count);
+                       OUT_BATCH((1 << (count >> 2)) - 1);
+
+                       memcpy(sna->kgem.batch + sna->kgem.nbatch,
+                              op->u.gen3.constants,
+                              count * sizeof(uint32_t));
+                       sna->kgem.nbatch += count;
+               }
+       }
+
+       if (tex_count != 0) {
+               uint32_t rewind;
+
+               n = 0;
+               if (tex_count == state->tex_count) {
+                       for (; n < tex_count; n++) {
+                               if (map[2*n+0] != state->tex_map[2*n+0] ||
+                                   map[2*n+1] != state->tex_map[2*n+1] ||
+                                   state->tex_handle[n] != bo[n]->handle ||
+                                   state->tex_delta[n] != bo[n]->delta)
+                                       break;
+                       }
+               }
+               if (n < tex_count) {
+                       OUT_BATCH(_3DSTATE_MAP_STATE | (3 * tex_count));
+                       OUT_BATCH((1 << tex_count) - 1);
+                       for (n = 0; n < tex_count; n++) {
+                               OUT_BATCH(kgem_add_reloc(&sna->kgem,
+                                                        sna->kgem.nbatch,
+                                                        bo[n],
+                                                        I915_GEM_DOMAIN_SAMPLER<< 16,
+                                                        0));
+                               OUT_BATCH(map[2*n + 0]);
+                               OUT_BATCH(map[2*n + 1]);
+
+                               state->tex_map[2*n+0] = map[2*n+0];
+                               state->tex_map[2*n+1] = map[2*n+1];
+                               state->tex_handle[n] = bo[n]->handle;
+                               state->tex_delta[n] = bo[n]->delta;
+                       }
+                       state->tex_count = n;
+               }
+
+               rewind = sna->kgem.nbatch;
+               OUT_BATCH(_3DSTATE_SAMPLER_STATE | (3 * tex_count));
+               OUT_BATCH((1 << tex_count) - 1);
+               for (n = 0; n < tex_count; n++) {
+                       OUT_BATCH(sampler[2*n + 0]);
+                       OUT_BATCH(sampler[2*n + 1]);
+                       OUT_BATCH(0);
+               }
+               if (state->last_sampler &&
+                   memcmp(&sna->kgem.batch[state->last_sampler+1],
+                          &sna->kgem.batch[rewind + 1],
+                          (3*tex_count + 1)*sizeof(uint32_t)) == 0)
+                       sna->kgem.nbatch = rewind;
+               else
+                       state->last_sampler = rewind;
+       }
+
+       gen3_composite_emit_shader(sna, op, op->op);
+}
+
+static void gen3_magic_ca_pass(struct sna *sna,
+                              const struct sna_composite_op *op)
+{
+       if (!op->need_magic_ca_pass)
+               return;
+
+       DBG(("%s(%d)\n", __FUNCTION__,
+            sna->render.vertex_index - sna->render.vertex_start));
+
+       OUT_BATCH(_3DSTATE_LOAD_STATE_IMMEDIATE_1 | I1_LOAD_S(6) | 0);
+       OUT_BATCH(gen3_get_blend_cntl(PictOpAdd, true, op->dst.format));
+       gen3_composite_emit_shader(sna, op, PictOpAdd);
+
+       OUT_BATCH(PRIM3D_RECTLIST | PRIM3D_INDIRECT_SEQUENTIAL |
+                 (sna->render.vertex_index - sna->render.vertex_start));
+       OUT_BATCH(sna->render.vertex_start);
+
+       sna->render_state.gen3.last_blend = 0;
+}
+
+static void gen3_vertex_flush(struct sna *sna)
+{
+       assert(sna->render_state.gen3.vertex_offset);
+
+       DBG(("%s[%x] = %d\n", __FUNCTION__,
+            4*sna->render_state.gen3.vertex_offset,
+            sna->render.vertex_index - sna->render.vertex_start));
+
+       sna->kgem.batch[sna->render_state.gen3.vertex_offset] =
+               PRIM3D_RECTLIST | PRIM3D_INDIRECT_SEQUENTIAL |
+               (sna->render.vertex_index - sna->render.vertex_start);
+       sna->kgem.batch[sna->render_state.gen3.vertex_offset + 1] =
+               sna->render.vertex_start;
+
+       sna->render_state.gen3.vertex_offset = 0;
+}
+
+static int gen3_vertex_finish(struct sna *sna)
+{
+       struct kgem_bo *bo;
+
+       DBG(("%s: used=%d/%d, vbo active? %d\n",
+            __FUNCTION__, sna->render.vertex_used, sna->render.vertex_size,
+            sna->render.vbo ? sna->render.vbo->handle : 0));
+       assert(sna->render.vertex_used);
+       assert(sna->render.vertex_used <= sna->render.vertex_size);
+
+       bo = sna->render.vbo;
+       if (bo) {
+               if (sna->render_state.gen3.vertex_offset)
+                       gen3_vertex_flush(sna);
+
+               DBG(("%s: reloc = %d\n", __FUNCTION__,
+                    sna->render.vertex_reloc[0]));
+
+               sna->kgem.batch[sna->render.vertex_reloc[0]] =
+                       kgem_add_reloc(&sna->kgem, sna->render.vertex_reloc[0],
+                                      bo, I915_GEM_DOMAIN_VERTEX << 16, 0);
+
+               sna->render.vertex_reloc[0] = 0;
+               sna->render.vertex_used = 0;
+               sna->render.vertex_index = 0;
+
+               kgem_bo_destroy(&sna->kgem, bo);
+       }
+
+       sna->render.vertices = NULL;
+       sna->render.vbo = kgem_create_linear(&sna->kgem,
+                                            256*1024, CREATE_GTT_MAP);
+       if (sna->render.vbo)
+               sna->render.vertices = kgem_bo_map(&sna->kgem, sna->render.vbo);
+       if (sna->render.vertices == NULL) {
+               if (sna->render.vbo)
+                       kgem_bo_destroy(&sna->kgem, sna->render.vbo);
+               sna->render.vbo = NULL;
+               return 0;
+       }
+       assert(sna->render.vbo->snoop == false);
+
+       if (sna->render.vertex_used) {
+               memcpy(sna->render.vertices,
+                      sna->render.vertex_data,
+                      sizeof(float)*sna->render.vertex_used);
+       }
+       sna->render.vertex_size = 64 * 1024 - 1;
+       return sna->render.vertex_size - sna->render.vertex_used;
+}
+
+static void gen3_vertex_close(struct sna *sna)
+{
+       struct kgem_bo *bo, *free_bo = NULL;
+       unsigned int delta = 0;
+
+       assert(sna->render_state.gen3.vertex_offset == 0);
+
+       DBG(("%s: used=%d/%d, vbo active? %d\n",
+            __FUNCTION__, sna->render.vertex_used, sna->render.vertex_size,
+            sna->render.vbo ? sna->render.vbo->handle : 0));
+
+       if (sna->render.vertex_used == 0)
+               return;
+
+       bo = sna->render.vbo;
+       if (bo) {
+               if (sna->render.vertex_size - sna->render.vertex_used < 64) {
+                       DBG(("%s: discarding full vbo\n", __FUNCTION__));
+                       sna->render.vbo = NULL;
+                       sna->render.vertices = sna->render.vertex_data;
+                       sna->render.vertex_size = ARRAY_SIZE(sna->render.vertex_data);
+                       free_bo = bo;
+               } else if (IS_CPU_MAP(bo->map)) {
+                       DBG(("%s: converting CPU map to GTT\n", __FUNCTION__));
+                       sna->render.vertices = kgem_bo_map__gtt(&sna->kgem, bo);
+                       if (sna->render.vertices == NULL) {
+                               DBG(("%s: discarding non-mappable vertices\n",__FUNCTION__));
+                               sna->render.vbo = NULL;
+                               sna->render.vertices = sna->render.vertex_data;
+                               sna->render.vertex_size = ARRAY_SIZE(sna->render.vertex_data);
+                               free_bo = bo;
+                       }
+               }
+       } else {
+               if (sna->kgem.nbatch + sna->render.vertex_used <= sna->kgem.surface) {
+                       DBG(("%s: copy to batch: %d @ %d\n", __FUNCTION__,
+                            sna->render.vertex_used, sna->kgem.nbatch));
+                       memcpy(sna->kgem.batch + sna->kgem.nbatch,
+                              sna->render.vertex_data,
+                              sna->render.vertex_used * 4);
+                       delta = sna->kgem.nbatch * 4;
+                       bo = NULL;
+                       sna->kgem.nbatch += sna->render.vertex_used;
+               } else {
+                       DBG(("%s: new vbo: %d\n", __FUNCTION__,
+                            sna->render.vertex_used));
+                       bo = kgem_create_linear(&sna->kgem,
+                                               4*sna->render.vertex_used, 0);
+                       if (bo) {
+                               assert(bo->snoop == false);
+                               kgem_bo_write(&sna->kgem, bo,
+                                             sna->render.vertex_data,
+                                             4*sna->render.vertex_used);
+                       }
+                       free_bo = bo;
+               }
+       }
+
+       DBG(("%s: reloc = %d\n", __FUNCTION__,
+            sna->render.vertex_reloc[0]));
+
+       if (sna->render.vertex_reloc[0]) {
+               sna->kgem.batch[sna->render.vertex_reloc[0]] =
+                       kgem_add_reloc(&sna->kgem, sna->render.vertex_reloc[0],
+                                      bo, I915_GEM_DOMAIN_VERTEX << 16, delta);
+               sna->render.vertex_reloc[0] = 0;
+       }
+
+       if (sna->render.vbo == NULL) {
+               DBG(("%s: resetting vbo\n", __FUNCTION__));
+               sna->render.vertex_used = 0;
+               sna->render.vertex_index = 0;
+               assert(sna->render.vertices == sna->render.vertex_data);
+               assert(sna->render.vertex_size == ARRAY_SIZE(sna->render.vertex_data));
+       }
+
+       if (free_bo)
+               kgem_bo_destroy(&sna->kgem, free_bo);
+}
+
+static bool gen3_rectangle_begin(struct sna *sna,
+                                const struct sna_composite_op *op)
+{
+       struct gen3_render_state *state = &sna->render_state.gen3;
+       int ndwords, i1_cmd = 0, i1_len = 0;
+
+       ndwords = 2;
+       if (op->need_magic_ca_pass)
+               ndwords += 100;
+       if (sna->render.vertex_reloc[0] == 0)
+               i1_len++, i1_cmd |= I1_LOAD_S(0), ndwords++;
+       if (state->floats_per_vertex != op->floats_per_vertex)
+               i1_len++, i1_cmd |= I1_LOAD_S(1), ndwords++;
+
+       if (!kgem_check_batch(&sna->kgem, ndwords+1))
+               return false;
+
+       if (i1_cmd) {
+               OUT_BATCH(_3DSTATE_LOAD_STATE_IMMEDIATE_1 | i1_cmd | (i1_len - 1));
+               if (sna->render.vertex_reloc[0] == 0)
+                       sna->render.vertex_reloc[0] = sna->kgem.nbatch++;
+               if (state->floats_per_vertex != op->floats_per_vertex) {
+                       state->floats_per_vertex = op->floats_per_vertex;
+                       OUT_BATCH(state->floats_per_vertex << S1_VERTEX_WIDTH_SHIFT |
+                                 state->floats_per_vertex << S1_VERTEX_PITCH_SHIFT);
+               }
+       }
+
+       if (sna->kgem.nbatch == 2 + state->last_vertex_offset) {
+               state->vertex_offset = state->last_vertex_offset;
+       } else {
+               state->vertex_offset = sna->kgem.nbatch;
+               OUT_BATCH(MI_NOOP); /* to be filled later */
+               OUT_BATCH(MI_NOOP);
+               sna->render.vertex_start = sna->render.vertex_index;
+               state->last_vertex_offset = state->vertex_offset;
+       }
+
+       return true;
+}
+
+static int gen3_get_rectangles__flush(struct sna *sna,
+                                     const struct sna_composite_op *op)
+{
+       if (!kgem_check_batch(&sna->kgem, op->need_magic_ca_pass ? 105: 5))
+               return 0;
+       if (!kgem_check_reloc_and_exec(&sna->kgem, 1))
+               return 0;
+
+       if (op->need_magic_ca_pass && sna->render.vbo)
+               return 0;
+
+       return gen3_vertex_finish(sna);
+}
+
+inline static int gen3_get_rectangles(struct sna *sna,
+                                     const struct sna_composite_op *op,
+                                     int want)
+{
+       int rem;
+
+       DBG(("%s: want=%d, rem=%d\n",
+            __FUNCTION__, want*op->floats_per_rect, vertex_space(sna)));
+
+       assert(sna->render.vertex_index * op->floats_per_vertex == sna->render.vertex_used);
+
+start:
+       rem = vertex_space(sna);
+       if (unlikely(op->floats_per_rect > rem)) {
+               DBG(("flushing vbo for %s: %d < %d\n",
+                    __FUNCTION__, rem, op->floats_per_rect));
+               rem = gen3_get_rectangles__flush(sna, op);
+               if (unlikely(rem == 0))
+                       goto flush;
+       }
+
+       if (unlikely(sna->render_state.gen3.vertex_offset == 0 &&
+                    !gen3_rectangle_begin(sna, op)))
+               goto flush;
+
+       if (want > 1 && want * op->floats_per_rect > rem)
+               want = rem / op->floats_per_rect;
+       sna->render.vertex_index += 3*want;
+
+       assert(want);
+       assert(sna->render.vertex_index * op->floats_per_vertex <= sna->render.vertex_size);
+       return want;
+
+flush:
+       DBG(("%s: flushing batch\n", __FUNCTION__));
+       if (sna->render_state.gen3.vertex_offset) {
+               gen3_vertex_flush(sna);
+               gen3_magic_ca_pass(sna, op);
+       }
+       _kgem_submit(&sna->kgem);
+       gen3_emit_composite_state(sna, op);
+       goto start;
+}
+
+fastcall static void
+gen3_render_composite_blt(struct sna *sna,
+                         const struct sna_composite_op *op,
+                         const struct sna_composite_rectangles *r)
+{
+       DBG(("%s: src=(%d, %d)+(%d, %d), mask=(%d, %d)+(%d, %d), dst=(%d, %d)+(%d, %d), size=(%d, %d)\n", __FUNCTION__,
+            r->src.x, r->src.y, op->src.offset[0], op->src.offset[1],
+            r->mask.x, r->mask.y, op->mask.offset[0], op->mask.offset[1],
+            r->dst.x, r->dst.y, op->dst.x, op->dst.y,
+            r->width, r->height));
+
+       gen3_get_rectangles(sna, op, 1);
+
+       op->prim_emit(sna, op, r);
+}
+
+fastcall static void
+gen3_render_composite_box(struct sna *sna,
+                         const struct sna_composite_op *op,
+                         const BoxRec *box)
+{
+       struct sna_composite_rectangles r;
+
+       DBG(("%s: src=+(%d, %d), mask=+(%d, %d), dst=+(%d, %d)\n",
+            __FUNCTION__,
+            op->src.offset[0], op->src.offset[1],
+            op->mask.offset[0], op->mask.offset[1],
+            op->dst.x, op->dst.y));
+
+       gen3_get_rectangles(sna, op, 1);
+
+       r.dst.x  = box->x1;
+       r.dst.y  = box->y1;
+       r.width  = box->x2 - box->x1;
+       r.height = box->y2 - box->y1;
+       r.src = r.mask = r.dst;
+
+       op->prim_emit(sna, op, &r);
+}
+
+static void
+gen3_render_composite_boxes(struct sna *sna,
+                           const struct sna_composite_op *op,
+                           const BoxRec *box, int nbox)
+{
+       DBG(("%s: nbox=%d, src=+(%d, %d), mask=+(%d, %d), dst=+(%d, %d)\n",
+            __FUNCTION__, nbox,
+            op->src.offset[0], op->src.offset[1],
+            op->mask.offset[0], op->mask.offset[1],
+            op->dst.x, op->dst.y));
+
+       do {
+               int nbox_this_time;
+
+               nbox_this_time = gen3_get_rectangles(sna, op, nbox);
+               nbox -= nbox_this_time;
+
+               do {
+                       struct sna_composite_rectangles r;
+
+                       DBG(("  %s: (%d, %d) x (%d, %d)\n", __FUNCTION__,
+                            box->x1, box->y1,
+                            box->x2 - box->x1,
+                            box->y2 - box->y1));
+
+                       r.dst.x  = box->x1; r.dst.y  = box->y1;
+                       r.width = box->x2 - box->x1;
+                       r.height = box->y2 - box->y1;
+                       r.src = r.mask = r.dst;
+
+                       op->prim_emit(sna, op, &r);
+                       box++;
+               } while (--nbox_this_time);
+       } while (nbox);
+}
+
+static void
+gen3_render_composite_done(struct sna *sna,
+                          const struct sna_composite_op *op)
+{
+       DBG(("%s()\n", __FUNCTION__));
+
+       if (sna->render_state.gen3.vertex_offset) {
+               gen3_vertex_flush(sna);
+               gen3_magic_ca_pass(sna, op);
+       }
+
+       if (op->mask.bo)
+               kgem_bo_destroy(&sna->kgem, op->mask.bo);
+       if (op->src.bo)
+               kgem_bo_destroy(&sna->kgem, op->src.bo);
+
+       sna_render_composite_redirect_done(sna, op);
+}
+
+static void
+discard_vbo(struct sna *sna)
+{
+       kgem_bo_destroy(&sna->kgem, sna->render.vbo);
+       sna->render.vbo = NULL;
+       sna->render.vertices = sna->render.vertex_data;
+       sna->render.vertex_size = ARRAY_SIZE(sna->render.vertex_data);
+       sna->render.vertex_used = 0;
+       sna->render.vertex_index = 0;
+}
+
+static void
+gen3_render_reset(struct sna *sna)
+{
+       struct gen3_render_state *state = &sna->render_state.gen3;
+
+       state->need_invariant = true;
+       state->current_dst = 0;
+       state->tex_count = 0;
+       state->last_drawrect_limit = ~0U;
+       state->last_target = 0;
+       state->last_blend = 0;
+       state->last_constants = 0;
+       state->last_sampler = 0;
+       state->last_shader = 0x7fffffff;
+       state->last_diffuse = 0xcc00ffee;
+       state->last_specular = 0xcc00ffee;
+
+       state->floats_per_vertex = 0;
+       state->last_floats_per_vertex = 0;
+       state->last_vertex_offset = 0;
+       state->vertex_offset = 0;
+
+       if (sna->render.vbo != NULL &&
+           !kgem_bo_is_mappable(&sna->kgem, sna->render.vbo)) {
+               DBG(("%s: discarding vbo as next access will stall: %d\n",
+                    __FUNCTION__, sna->render.vbo->presumed_offset));
+               discard_vbo(sna);
+       }
+}
+
+static void
+gen3_render_retire(struct kgem *kgem)
+{
+       struct sna *sna;
+
+       sna = container_of(kgem, struct sna, kgem);
+       if (sna->render.vertex_reloc[0] == 0 &&
+           sna->render.vbo && !kgem_bo_is_busy(sna->render.vbo)) {
+               DBG(("%s: resetting idle vbo\n", __FUNCTION__));
+               sna->render.vertex_used = 0;
+               sna->render.vertex_index = 0;
+       }
+}
+
+static void
+gen3_render_expire(struct kgem *kgem)
+{
+       struct sna *sna;
+
+       sna = container_of(kgem, struct sna, kgem);
+       if (sna->render.vbo && !sna->render.vertex_used) {
+               DBG(("%s: discarding vbo\n", __FUNCTION__));
+               discard_vbo(sna);
+       }
+}
+
+static bool gen3_composite_channel_set_format(struct sna_composite_channel *channel,
+                                             CARD32 format)
+{
+       unsigned int i;
+
+       for (i = 0; i < ARRAY_SIZE(gen3_tex_formats); i++) {
+               if (gen3_tex_formats[i].fmt == format) {
+                       channel->card_format = gen3_tex_formats[i].card_fmt;
+                       channel->rb_reversed = gen3_tex_formats[i].rb_reversed;
+                       return true;
+               }
+       }
+       return false;
+}
+
+static bool source_is_covered(PicturePtr picture,
+                             int x, int y,
+                             int width, int height)
+{
+       int x1, y1, x2, y2;
+
+       if (picture->repeat && picture->repeatType != RepeatNone)
+               return true;
+
+       if (picture->pDrawable == NULL)
+               return false;
+
+       if (picture->transform) {
+               pixman_box16_t sample;
+
+               sample.x1 = x;
+               sample.y1 = y;
+               sample.x2 = x + width;
+               sample.y2 = y + height;
+
+               pixman_transform_bounds(picture->transform, &sample);
+
+               x1 = sample.x1;
+               x2 = sample.x2;
+               y1 = sample.y1;
+               y2 = sample.y2;
+       } else {
+               x1 = x;
+               y1 = y;
+               x2 = x + width;
+               y2 = y + height;
+       }
+
+       return
+               x1 >= 0 && y1 >= 0 &&
+               x2 <= picture->pDrawable->width &&
+               y2 <= picture->pDrawable->height;
+}
+
+static bool gen3_composite_channel_set_xformat(PicturePtr picture,
+                                              struct sna_composite_channel *channel,
+                                              int x, int y,
+                                              int width, int height)
+{
+       unsigned int i;
+
+       if (PICT_FORMAT_A(picture->format) != 0)
+               return false;
+
+       if (width == 0 || height == 0)
+               return false;
+
+       if (!source_is_covered(picture, x, y, width, height))
+               return false;
+
+       for (i = 0; i < ARRAY_SIZE(gen3_tex_formats); i++) {
+               if (gen3_tex_formats[i].xfmt == picture->format) {
+                       channel->card_format = gen3_tex_formats[i].card_fmt;
+                       channel->rb_reversed = gen3_tex_formats[i].rb_reversed;
+                       channel->alpha_fixup = true;
+                       return true;
+               }
+       }
+
+       return false;
+}
+
+static int
+gen3_init_solid(struct sna_composite_channel *channel, uint32_t color)
+{
+       channel->u.gen3.mode = color;
+       channel->u.gen3.type = SHADER_CONSTANT;
+       if (color == 0)
+               channel->u.gen3.type = SHADER_ZERO;
+       else if (color == 0xff000000)
+               channel->u.gen3.type = SHADER_BLACK;
+       else if (color == 0xffffffff)
+               channel->u.gen3.type = SHADER_WHITE;
+
+       channel->bo = NULL;
+       channel->is_opaque = (color >> 24) == 0xff;
+       channel->is_affine = 1;
+       channel->alpha_fixup = 0;
+       channel->rb_reversed = 0;
+
+       DBG(("%s: color=%08x, is_opaque=%d, type=%d\n",
+            __FUNCTION__, color, channel->is_opaque, channel->u.gen3.type));
+
+       /* for consistency */
+       channel->repeat = RepeatNormal;
+       channel->filter = PictFilterNearest;
+       channel->pict_format = PICT_a8r8g8b8;
+       channel->card_format = MAPSURF_32BIT | MT_32BIT_ARGB8888;
+
+       return 1;
+}
+
+static void gen3_composite_channel_convert(struct sna_composite_channel *channel)
+{
+       if (channel->u.gen3.type == SHADER_TEXTURE)
+               channel->repeat = gen3_texture_repeat(channel->repeat);
+       else
+               channel->repeat = gen3_gradient_repeat(channel->repeat);
+
+       channel->filter = gen3_filter(channel->filter);
+       if (channel->card_format == 0)
+               gen3_composite_channel_set_format(channel, channel->pict_format);
+}
+
+static bool gen3_gradient_setup(struct sna *sna,
+                               PicturePtr picture,
+                               struct sna_composite_channel *channel,
+                               int16_t ox, int16_t oy)
+{
+       int16_t dx, dy;
+
+       if (picture->repeat == 0) {
+               channel->repeat = RepeatNone;
+       } else switch (picture->repeatType) {
+       case RepeatNone:
+       case RepeatNormal:
+       case RepeatPad:
+       case RepeatReflect:
+               channel->repeat = picture->repeatType;
+               break;
+       default:
+               return false;
+       }
+
+       channel->bo =
+               sna_render_get_gradient(sna,
+                                       (PictGradient *)picture->pSourcePict);
+       if (channel->bo == NULL)
+               return false;
+
+       channel->pict_format = PICT_a8r8g8b8;
+       channel->card_format = MAPSURF_32BIT | MT_32BIT_ARGB8888;
+       channel->filter = PictFilterNearest;
+       channel->is_affine = sna_transform_is_affine(picture->transform);
+       if (sna_transform_is_integer_translation(picture->transform, &dx, &dy)) {
+               DBG(("%s: integer translation (%d, %d), removing\n",
+                    __FUNCTION__, dx, dy));
+               ox += dx;
+               oy += dy;
+               channel->transform = NULL;
+       } else
+               channel->transform = picture->transform;
+       channel->width  = channel->bo->pitch / 4;
+       channel->height = 1;
+       channel->offset[0] = ox;
+       channel->offset[1] = oy;
+       channel->scale[0] = channel->scale[1] = 1;
+       return true;
+}
+
+static int
+gen3_init_linear(struct sna *sna,
+                PicturePtr picture,
+                struct sna_composite_op *op,
+                struct sna_composite_channel *channel,
+                int ox, int oy)
+{
+       PictLinearGradient *linear =
+               (PictLinearGradient *)picture->pSourcePict;
+       float x0, y0, sf;
+       float dx, dy, offset;
+       int n;
+
+       DBG(("%s: p1=(%f, %f), p2=(%f, %f)\n",
+            __FUNCTION__,
+            xFixedToDouble(linear->p1.x), xFixedToDouble(linear->p1.y),
+            xFixedToDouble(linear->p2.x), xFixedToDouble(linear->p2.y)));
+
+       if (linear->p2.x == linear->p1.x && linear->p2.y == linear->p1.y)
+               return 0;
+
+       dx = xFixedToDouble(linear->p2.x - linear->p1.x);
+       dy = xFixedToDouble(linear->p2.y - linear->p1.y);
+       sf = dx*dx + dy*dy;
+       dx /= sf;
+       dy /= sf;
+
+       x0 = xFixedToDouble(linear->p1.x);
+       y0 = xFixedToDouble(linear->p1.y);
+       offset = dx*x0 + dy*y0;
+
+       n = op->u.gen3.num_constants;
+       channel->u.gen3.constants = FS_C0 + n / 4;
+       op->u.gen3.constants[n++] = dx;
+       op->u.gen3.constants[n++] = dy;
+       op->u.gen3.constants[n++] = -offset;
+       op->u.gen3.constants[n++] = 0;
+
+       if (!gen3_gradient_setup(sna, picture, channel, ox, oy))
+               return -1;
+
+       channel->u.gen3.type = SHADER_LINEAR;
+       op->u.gen3.num_constants = n;
+
+       DBG(("%s: dx=%f, dy=%f, offset=%f, constants=%d\n",
+            __FUNCTION__, dx, dy, -offset, channel->u.gen3.constants - FS_C0));
+       return 1;
+}
+
+static int
+gen3_init_radial(struct sna *sna,
+                PicturePtr picture,
+                struct sna_composite_op *op,
+                struct sna_composite_channel *channel,
+                int ox, int oy)
+{
+       PictRadialGradient *radial = (PictRadialGradient *)picture->pSourcePict;
+       double dx, dy, dr, r1;
+       int n;
+
+       dx = xFixedToDouble(radial->c2.x - radial->c1.x);
+       dy = xFixedToDouble(radial->c2.y - radial->c1.y);
+       dr = xFixedToDouble(radial->c2.radius - radial->c1.radius);
+
+       r1 = xFixedToDouble(radial->c1.radius);
+
+       n = op->u.gen3.num_constants;
+       channel->u.gen3.constants = FS_C0 + n / 4;
+       if (radial->c2.x == radial->c1.x && radial->c2.y == radial->c1.y) {
+               if (radial->c2.radius == radial->c1.radius) {
+                       channel->u.gen3.type = SHADER_ZERO;
+                       return 1;
+               }
+
+               op->u.gen3.constants[n++] = xFixedToDouble(radial->c1.x) / dr;
+               op->u.gen3.constants[n++] = xFixedToDouble(radial->c1.y) / dr;
+               op->u.gen3.constants[n++] = 1. / dr;
+               op->u.gen3.constants[n++] = -r1 / dr;
+
+               channel->u.gen3.mode = RADIAL_ONE;
+       } else {
+               op->u.gen3.constants[n++] = -xFixedToDouble(radial->c1.x);
+               op->u.gen3.constants[n++] = -xFixedToDouble(radial->c1.y);
+               op->u.gen3.constants[n++] = r1;
+               op->u.gen3.constants[n++] = -4 * (dx*dx + dy*dy - dr*dr);
+
+               op->u.gen3.constants[n++] = -2 * dx;
+               op->u.gen3.constants[n++] = -2 * dy;
+               op->u.gen3.constants[n++] = -2 * r1 * dr;
+               op->u.gen3.constants[n++] = 1 / (2 * (dx*dx + dy*dy - dr*dr));
+
+               channel->u.gen3.mode = RADIAL_TWO;
+       }
+
+       if (!gen3_gradient_setup(sna, picture, channel, ox, oy))
+               return -1;
+
+       channel->u.gen3.type = SHADER_RADIAL;
+       op->u.gen3.num_constants = n;
+       return 1;
+}
+
+static bool
+sna_picture_is_clear(PicturePtr picture,
+                    int x, int y, int w, int h,
+                    uint32_t *color)
+{
+       struct sna_pixmap *priv;
+
+       if (!picture->pDrawable)
+               return false;
+
+       priv = sna_pixmap(get_drawable_pixmap(picture->pDrawable));
+       if (priv == NULL || !priv->clear)
+               return false;
+
+       if (!source_is_covered(picture, x, y, w, h))
+               return false;
+
+       *color = priv->clear_color;
+       return true;
+}
+
+static int
+gen3_composite_picture(struct sna *sna,
+                      PicturePtr picture,
+                      struct sna_composite_op *op,
+                      struct sna_composite_channel *channel,
+                      int16_t x, int16_t y,
+                      int16_t w, int16_t h,
+                      int16_t dst_x, int16_t dst_y,
+                      bool precise)
+{
+       PixmapPtr pixmap;
+       uint32_t color;
+       int16_t dx, dy;
+
+       DBG(("%s: (%d, %d)x(%d, %d), dst=(%d, %d)\n",
+            __FUNCTION__, x, y, w, h, dst_x, dst_y));
+
+       channel->card_format = 0;
+
+       if (picture->pDrawable == NULL) {
+               SourcePict *source = picture->pSourcePict;
+               int ret = -1;
+
+               switch (source->type) {
+               case SourcePictTypeSolidFill:
+                       DBG(("%s: solid fill [%08x], format %x\n",
+                            __FUNCTION__, source->solidFill.color, picture->format));
+                       ret = gen3_init_solid(channel, source->solidFill.color);
+                       break;
+
+               case SourcePictTypeLinear:
+                       ret = gen3_init_linear(sna, picture, op, channel,
+                                              x - dst_x, y - dst_y);
+                       break;
+
+               case SourcePictTypeRadial:
+                       ret = gen3_init_radial(sna, picture, op, channel,
+                                              x - dst_x, y - dst_y);
+                       break;
+               }
+
+               if (ret == -1) {
+                       if (!precise)
+                               ret = sna_render_picture_approximate_gradient(sna, picture, channel,
+                                                                             x, y, w, h, dst_x, dst_y);
+                       if (ret == -1)
+                               ret = sna_render_picture_fixup(sna, picture, channel,
+                                                              x, y, w, h, dst_x, dst_y);
+               }
+               return ret;
+       }
+
+       if (picture->alphaMap) {
+               DBG(("%s -- fallback, alphamap\n", __FUNCTION__));
+               return sna_render_picture_fixup(sna, picture, channel,
+                                               x, y, w, h, dst_x, dst_y);
+       }
+
+       if (sna_picture_is_solid(picture, &color)) {
+               DBG(("%s: solid drawable [%08x]\n", __FUNCTION__, color));
+               return gen3_init_solid(channel, color);
+       }
+
+       if (sna_picture_is_clear(picture, x, y, w, h, &color)) {
+               DBG(("%s: clear drawable [%08x]\n", __FUNCTION__, color));
+               return gen3_init_solid(channel, color_convert(color, picture->format, PICT_a8r8g8b8));
+       }
+
+       if (!gen3_check_repeat(picture))
+               return sna_render_picture_fixup(sna, picture, channel,
+                                               x, y, w, h, dst_x, dst_y);
+
+       if (!gen3_check_filter(picture))
+               return sna_render_picture_fixup(sna, picture, channel,
+                                               x, y, w, h, dst_x, dst_y);
+
+       channel->repeat = picture->repeat ? picture->repeatType : RepeatNone;
+       channel->filter = picture->filter;
+       channel->pict_format = picture->format;
+
+       pixmap = get_drawable_pixmap(picture->pDrawable);
+       get_drawable_deltas(picture->pDrawable, pixmap, &dx, &dy);
+
+       x += dx + picture->pDrawable->x;
+       y += dy + picture->pDrawable->y;
+
+       if (sna_transform_is_integer_translation(picture->transform, &dx, &dy)) {
+               DBG(("%s: integer translation (%d, %d), removing\n",
+                    __FUNCTION__, dx, dy));
+               x += dx;
+               y += dy;
+               channel->transform = NULL;
+               channel->filter = PictFilterNearest;
+       } else {
+               channel->transform = picture->transform;
+               channel->is_affine = sna_transform_is_affine(picture->transform);
+       }
+
+       if (!gen3_composite_channel_set_format(channel, picture->format) &&
+           !gen3_composite_channel_set_xformat(picture, channel, x, y, w, h))
+               return sna_render_picture_convert(sna, picture, channel, pixmap,
+                                                 x, y, w, h, dst_x, dst_y);
+
+       if (too_large(pixmap->drawable.width, pixmap->drawable.height)) {
+               DBG(("%s: pixmap too large (%dx%d), extracting (%d, %d)x(%d,%d)\n",
+                    __FUNCTION__,
+                    pixmap->drawable.width, pixmap->drawable.height,
+                    x, y, w, h));
+               return sna_render_picture_extract(sna, picture, channel,
+                                                 x, y, w, h, dst_x, dst_y);
+       }
+
+       return sna_render_pixmap_bo(sna, channel, pixmap,
+                                   x, y, w, h, dst_x, dst_y);
+}
+
+static inline bool
+source_use_blt(struct sna *sna, PicturePtr picture)
+{
+       /* If it is a solid, try to use the BLT paths */
+       if (!picture->pDrawable)
+               return picture->pSourcePict->type == SourcePictTypeSolidFill;
+
+       if (picture->pDrawable->width  == 1 &&
+           picture->pDrawable->height == 1 &&
+           picture->repeat)
+               return true;
+
+       if (too_large(picture->pDrawable->width, picture->pDrawable->height))
+               return true;
+
+       return !is_gpu(picture->pDrawable);
+}
+
+static bool
+try_blt(struct sna *sna,
+       PicturePtr dst,
+       PicturePtr src,
+       int width, int height)
+{
+       if (sna->kgem.mode != KGEM_RENDER) {
+               DBG(("%s: already performing BLT\n", __FUNCTION__));
+               return true;
+       }
+
+       if (too_large(width, height)) {
+               DBG(("%s: operation too large for 3D pipe (%d, %d)\n",
+                    __FUNCTION__, width, height));
+               return true;
+       }
+
+       if (too_large(dst->pDrawable->width, dst->pDrawable->height)) {
+               DBG(("%s: target too large for 3D pipe (%d, %d)\n",
+                    __FUNCTION__,
+                    dst->pDrawable->width, dst->pDrawable->height));
+               return true;
+       }
+
+       /* is the source picture only in cpu memory e.g. a shm pixmap? */
+       return source_use_blt(sna, src);
+}
+
+static void
+gen3_align_vertex(struct sna *sna,
+                 const struct sna_composite_op *op)
+{
+       if (op->floats_per_vertex != sna->render_state.gen3.last_floats_per_vertex) {
+               if (sna->render.vertex_size - sna->render.vertex_used < 2*op->floats_per_rect)
+                       gen3_vertex_finish(sna);
+
+               DBG(("aligning vertex: was %d, now %d floats per vertex, %d->%d\n",
+                    sna->render_state.gen3.last_floats_per_vertex,
+                    op->floats_per_vertex,
+                    sna->render.vertex_index,
+                    (sna->render.vertex_used + op->floats_per_vertex - 1) / op->floats_per_vertex));
+               sna->render.vertex_index = (sna->render.vertex_used + op->floats_per_vertex - 1) / op->floats_per_vertex;
+               sna->render.vertex_used = sna->render.vertex_index * op->floats_per_vertex;
+               assert(sna->render.vertex_used < sna->render.vertex_size - op->floats_per_rect);
+               sna->render_state.gen3.last_floats_per_vertex = op->floats_per_vertex;
+       }
+}
+
+static bool
+gen3_composite_set_target(struct sna *sna,
+                         struct sna_composite_op *op,
+                         PicturePtr dst,
+                         int x, int y, int w, int h)
+{
+       BoxRec box;
+
+       op->dst.pixmap = get_drawable_pixmap(dst->pDrawable);
+       op->dst.format = dst->format;
+       op->dst.width = op->dst.pixmap->drawable.width;
+       op->dst.height = op->dst.pixmap->drawable.height;
+
+       if (w && h) {
+               box.x1 = x;
+               box.y1 = y;
+               box.x2 = x + w;
+               box.y2 = y + h;
+       } else
+               sna_render_picture_extents(dst, &box);
+
+       op->dst.bo = sna_drawable_use_bo (dst->pDrawable,
+                                         PREFER_GPU | FORCE_GPU | RENDER_GPU,
+                                         &box, &op->damage);
+       if (op->dst.bo == NULL)
+               return false;
+
+       /* For single-stream mode there should be no minimum alignment
+        * required, except that the width must be at least 2 elements.
+        */
+       if (op->dst.bo->pitch < 2*op->dst.pixmap->drawable.bitsPerPixel) {
+               struct sna_pixmap *priv;
+
+               priv = sna_pixmap_move_to_gpu (op->dst.pixmap,
+                                              MOVE_READ | MOVE_WRITE);
+               if (priv == NULL || priv->pinned)
+                       return false;
+
+               if (priv->gpu_bo->pitch < 2*op->dst.pixmap->drawable.bitsPerPixel) {
+                       struct kgem_bo *bo;
+
+                       bo = kgem_replace_bo(&sna->kgem, priv->gpu_bo,
+                                            op->dst.width, op->dst.height,
+                                            2*op->dst.pixmap->drawable.bitsPerPixel,
+                                            op->dst.pixmap->drawable.bitsPerPixel);
+                       if (bo == NULL)
+                               return false;
+
+                       kgem_bo_destroy(&sna->kgem, priv->gpu_bo);
+                       priv->gpu_bo = bo;
+               }
+
+               op->dst.bo = priv->gpu_bo;
+               op->damage = &priv->gpu_damage;
+               if (sna_damage_is_all(op->damage,
+                                     op->dst.width, op->dst.height))
+                       op->damage = NULL;
+       }
+
+       get_drawable_deltas(dst->pDrawable, op->dst.pixmap,
+                           &op->dst.x, &op->dst.y);
+
+       DBG(("%s: pixmap=%p, format=%08x, size=%dx%d, pitch=%d, delta=(%d,%d),damage=%p\n",
+            __FUNCTION__,
+            op->dst.pixmap, (int)op->dst.format,
+            op->dst.width, op->dst.height,
+            op->dst.bo->pitch,
+            op->dst.x, op->dst.y,
+            op->damage ? *op->damage : (void *)-1));
+
+       assert(op->dst.bo->proxy == NULL);
+       return true;
+}
+
+static inline uint8_t
+mul_8_8(uint8_t a, uint8_t b)
+{
+    uint16_t t = a * (uint16_t)b + 0x7f;
+    return ((t >> 8) + t) >> 8;
+}
+
+static inline uint32_t multa(uint32_t s, uint32_t m, int shift)
+{
+       return mul_8_8((s >> shift) & 0xff, m >> 24) << shift;
+}
+
+static inline bool is_constant_ps(uint32_t type)
+{
+       switch (type) {
+       case SHADER_NONE: /* be warned! */
+       case SHADER_ZERO:
+       case SHADER_BLACK:
+       case SHADER_WHITE:
+       case SHADER_CONSTANT:
+               return true;
+       default:
+               return false;
+       }
+}
+
+static bool
+has_alphamap(PicturePtr p)
+{
+       return p->alphaMap != NULL;
+}
+
+static bool
+untransformed(PicturePtr p)
+{
+       return !p->transform || pixman_transform_is_int_translate(p->transform);
+}
+
+static bool
+need_upload(PicturePtr p)
+{
+       return p->pDrawable && unattached(p->pDrawable) && untransformed(p);
+}
+
+static bool
+source_is_busy(PixmapPtr pixmap)
+{
+       struct sna_pixmap *priv = sna_pixmap(pixmap);
+       if (priv == NULL)
+               return false;
+
+       if (priv->clear)
+               return false;
+
+       if (priv->gpu_bo && kgem_bo_is_busy(priv->gpu_bo))
+               return true;
+
+       if (priv->cpu_bo && kgem_bo_is_busy(priv->cpu_bo))
+               return true;
+
+       return priv->gpu_damage && !priv->cpu_damage;
+}
+
+static bool
+source_fallback(PicturePtr p, PixmapPtr pixmap)
+{
+       if (sna_picture_is_solid(p, NULL))
+               return false;
+
+       if (!gen3_check_xformat(p) || !gen3_check_repeat(p))
+               return true;
+
+       if (pixmap && source_is_busy(pixmap))
+               return false;
+
+       return has_alphamap(p) || !gen3_check_filter(p) || need_upload(p);
+}
+
+static bool
+gen3_composite_fallback(struct sna *sna,
+                       uint8_t op,
+                       PicturePtr src,
+                       PicturePtr mask,
+                       PicturePtr dst)
+{
+       struct sna_pixmap *priv;
+       PixmapPtr src_pixmap;
+       PixmapPtr mask_pixmap;
+       PixmapPtr dst_pixmap;
+       bool src_fallback, mask_fallback;
+
+       if (!gen3_check_dst_format(dst->format)) {
+               DBG(("%s: unknown destination format: %d\n",
+                    __FUNCTION__, dst->format));
+               return true;
+       }
+
+       dst_pixmap = get_drawable_pixmap(dst->pDrawable);
+
+       src_pixmap = src->pDrawable ? get_drawable_pixmap(src->pDrawable) : NULL;
+       src_fallback = source_fallback(src, src_pixmap);
+
+       if (mask) {
+               mask_pixmap = mask->pDrawable ? get_drawable_pixmap(mask->pDrawable) : NULL;
+               mask_fallback = source_fallback(mask, mask_pixmap);
+       } else {
+               mask_pixmap = NULL;
+               mask_fallback = false;
+       }
+
+       /* If we are using the destination as a source and need to
+        * readback in order to upload the source, do it all
+        * on the cpu.
+        */
+       if (src_pixmap == dst_pixmap && src_fallback) {
+               DBG(("%s: src is dst and will fallback\n",__FUNCTION__));
+               return true;
+       }
+       if (mask_pixmap == dst_pixmap && mask_fallback) {
+               DBG(("%s: mask is dst and will fallback\n",__FUNCTION__));
+               return true;
+       }
+
+       if (mask &&
+           mask->componentAlpha && PICT_FORMAT_RGB(mask->format) &&
+           op != PictOpOver &&
+           gen3_blend_op[op].src_blend != BLENDFACT_ZERO)
+       {
+               DBG(("%s: component-alpha mask with op=%d, should fallback\n",
+                    __FUNCTION__, op));
+               return true;
+       }
+
+       /* If anything is on the GPU, push everything out to the GPU */
+       priv = sna_pixmap(dst_pixmap);
+       if (priv && priv->gpu_damage && !priv->clear) {
+               DBG(("%s: dst is already on the GPU, try to use GPU\n",
+                    __FUNCTION__));
+               return false;
+       }
+
+       if (src_pixmap && !src_fallback) {
+               DBG(("%s: src is already on the GPU, try to use GPU\n",
+                    __FUNCTION__));
+               return false;
+       }
+       if (mask_pixmap && !mask_fallback) {
+               DBG(("%s: mask is already on the GPU, try to use GPU\n",
+                    __FUNCTION__));
+               return false;
+       }
+
+       /* However if the dst is not on the GPU and we need to
+        * render one of the sources using the CPU, we may
+        * as well do the entire operation in place onthe CPU.
+        */
+       if (src_fallback) {
+               DBG(("%s: dst is on the CPU and src will fallback\n",
+                    __FUNCTION__));
+               return true;
+       }
+
+       if (mask && mask_fallback) {
+               DBG(("%s: dst is on the CPU and mask will fallback\n",
+                    __FUNCTION__));
+               return true;
+       }
+
+       if (too_large(dst_pixmap->drawable.width,
+                     dst_pixmap->drawable.height) &&
+           (priv == NULL || DAMAGE_IS_ALL(priv->cpu_damage))) {
+               DBG(("%s: dst is on the CPU and too large\n", __FUNCTION__));
+               return true;
+       }
+
+       DBG(("%s: dst is not on the GPU and the operation should not fallback\n",
+            __FUNCTION__));
+       return false;
+}
+
+static int
+reuse_source(struct sna *sna,
+            PicturePtr src, struct sna_composite_channel *sc, int src_x, int src_y,
+            PicturePtr mask, struct sna_composite_channel *mc, int msk_x, int msk_y)
+{
+       if (src_x != msk_x || src_y != msk_y)
+               return false;
+
+       if (mask == src) {
+               *mc = *sc;
+               if (mc->bo)
+                       kgem_bo_reference(mc->bo);
+               return true;
+       }
+
+       if ((src->pDrawable == NULL || mask->pDrawable != src->pDrawable))
+               return false;
+
+       if (sc->is_solid)
+               return false;
+
+       DBG(("%s: mask reuses source drawable\n", __FUNCTION__));
+
+       if (!sna_transform_equal(src->transform, mask->transform))
+               return false;
+
+       if (!sna_picture_alphamap_equal(src, mask))
+               return false;
+
+       if (!gen3_check_repeat(mask))
+               return false;
+
+       if (!gen3_check_filter(mask))
+               return false;
+
+       if (!gen3_check_format(mask))
+               return false;
+
+       DBG(("%s: reusing source channel for mask with a twist\n",
+            __FUNCTION__));
+
+       *mc = *sc;
+       mc->repeat = gen3_texture_repeat(mask->repeat ? mask->repeatType : RepeatNone);
+       mc->filter = gen3_filter(mask->filter);
+       mc->pict_format = mask->format;
+       gen3_composite_channel_set_format(mc, mask->format);
+       if (mc->bo)
+               kgem_bo_reference(mc->bo);
+       return true;
+}
+
+static bool
+gen3_render_composite(struct sna *sna,
+                     uint8_t op,
+                     PicturePtr src,
+                     PicturePtr mask,
+                     PicturePtr dst,
+                     int16_t src_x,  int16_t src_y,
+                     int16_t mask_x, int16_t mask_y,
+                     int16_t dst_x,  int16_t dst_y,
+                     int16_t width,  int16_t height,
+                     struct sna_composite_op *tmp)
+{
+       DBG(("%s()\n", __FUNCTION__));
+
+       if (op >= ARRAY_SIZE(gen3_blend_op)) {
+               DBG(("%s: fallback due to unhandled blend op: %d\n",
+                    __FUNCTION__, op));
+               return false;
+       }
+
+       /* Try to use the BLT engine unless it implies a
+        * 3D -> 2D context switch.
+        */
+       if (mask == NULL &&
+           try_blt(sna, dst, src, width, height) &&
+           sna_blt_composite(sna,
+                             op, src, dst,
+                             src_x, src_y,
+                             dst_x, dst_y,
+                             width, height,
+                             tmp, false))
+               return true;
+
+       if (gen3_composite_fallback(sna, op, src, mask, dst))
+               return false;
+
+       if (need_tiling(sna, width, height))
+               return sna_tiling_composite(op, src, mask, dst,
+                                           src_x,  src_y,
+                                           mask_x, mask_y,
+                                           dst_x,  dst_y,
+                                           width,  height,
+                                           tmp);
+
+       if (!gen3_composite_set_target(sna, tmp, dst,
+                                      dst_x, dst_y, width, height)) {
+               DBG(("%s: unable to set render target\n",
+                    __FUNCTION__));
+               return false;
+       }
+
+       tmp->op = op;
+       tmp->rb_reversed = gen3_dst_rb_reversed(tmp->dst.format);
+       if (too_large(tmp->dst.width, tmp->dst.height) ||
+           !gen3_check_pitch_3d(tmp->dst.bo)) {
+               if (!sna_render_composite_redirect(sna, tmp,
+                                                  dst_x, dst_y, width, height))
+                       return false;
+       }
+
+       tmp->u.gen3.num_constants = 0;
+       tmp->src.u.gen3.type = SHADER_TEXTURE;
+       tmp->src.is_affine = true;
+       DBG(("%s: preparing source\n", __FUNCTION__));
+       switch (gen3_composite_picture(sna, src, tmp, &tmp->src,
+                                      src_x, src_y,
+                                      width, height,
+                                      dst_x, dst_y,
+                                      dst->polyMode == PolyModePrecise)) {
+       case -1:
+               goto cleanup_dst;
+       case 0:
+               tmp->src.u.gen3.type = SHADER_ZERO;
+               break;
+       case 1:
+               if (mask == NULL && tmp->src.bo &&
+                   sna_blt_composite__convert(sna,
+                                              dst_x, dst_y, width, height,
+                                              tmp))
+                       return true;
+
+               gen3_composite_channel_convert(&tmp->src);
+               break;
+       }
+       DBG(("%s: source type=%d\n", __FUNCTION__, tmp->src.u.gen3.type));
+
+       tmp->mask.u.gen3.type = SHADER_NONE;
+       tmp->mask.is_affine = true;
+       tmp->need_magic_ca_pass = false;
+       tmp->has_component_alpha = false;
+       if (mask && tmp->src.u.gen3.type != SHADER_ZERO) {
+               if (!reuse_source(sna,
+                                 src, &tmp->src, src_x, src_y,
+                                 mask, &tmp->mask, mask_x, mask_y)) {
+                       tmp->mask.u.gen3.type = SHADER_TEXTURE;
+                       DBG(("%s: preparing mask\n", __FUNCTION__));
+                       switch (gen3_composite_picture(sna, mask, tmp, &tmp->mask,
+                                                      mask_x, mask_y,
+                                                      width,  height,
+                                                      dst_x,  dst_y,
+                                                      dst->polyMode == PolyModePrecise)) {
+                       case -1:
+                               goto cleanup_src;
+                       case 0:
+                               tmp->mask.u.gen3.type = SHADER_ZERO;
+                               break;
+                       case 1:
+                               gen3_composite_channel_convert(&tmp->mask);
+                               break;
+                       }
+               }
+               DBG(("%s: mask type=%d\n", __FUNCTION__, tmp->mask.u.gen3.type));
+               if (tmp->mask.u.gen3.type == SHADER_ZERO) {
+                       if (tmp->src.bo) {
+                               kgem_bo_destroy(&sna->kgem,
+                                               tmp->src.bo);
+                               tmp->src.bo = NULL;
+                       }
+                       tmp->src.u.gen3.type = SHADER_ZERO;
+                       tmp->mask.u.gen3.type = SHADER_NONE;
+               }
+
+               if (tmp->mask.u.gen3.type != SHADER_NONE) {
+                       if (mask->componentAlpha && PICT_FORMAT_RGB(mask->format)) {
+                               /* Check if it's component alpha that relies on a source alpha
+                                * and on the source value.  We can only get one of those
+                                * into the single source value that we get to blend with.
+                                */
+                               DBG(("%s: component-alpha mask: %d\n",
+                                    __FUNCTION__, tmp->mask.u.gen3.type));
+                               tmp->has_component_alpha = true;
+                               if (tmp->mask.u.gen3.type == SHADER_WHITE) {
+                                       tmp->mask.u.gen3.type = SHADER_NONE;
+                                       tmp->has_component_alpha = false;
+                               } else if (gen3_blend_op[op].src_alpha &&
+                                          (gen3_blend_op[op].src_blend != BLENDFACT_ZERO)) {
+                                       if (op != PictOpOver)
+                                               goto cleanup_mask;
+
+                                       tmp->need_magic_ca_pass = true;
+                                       tmp->op = PictOpOutReverse;
+                                       sna->render.vertex_start = sna->render.vertex_index;
+                               }
+                       } else {
+                               if (tmp->mask.is_opaque) {
+                                       tmp->mask.u.gen3.type = SHADER_NONE;
+                               } else if (is_constant_ps(tmp->src.u.gen3.type) &&
+                                          is_constant_ps(tmp->mask.u.gen3.type)) {
+                                       uint32_t v;
+
+                                       v = multa(tmp->src.u.gen3.mode,
+                                                 tmp->mask.u.gen3.mode,
+                                                 24);
+                                       v |= multa(tmp->src.u.gen3.mode,
+                                                  tmp->mask.u.gen3.mode,
+                                                  16);
+                                       v |= multa(tmp->src.u.gen3.mode,
+                                                  tmp->mask.u.gen3.mode,
+                                                  8);
+                                       v |= multa(tmp->src.u.gen3.mode,
+                                                  tmp->mask.u.gen3.mode,
+                                                  0);
+
+                                       DBG(("%s: combining constant source/mask: %x x %x -> %x\n",
+                                            __FUNCTION__,
+                                            tmp->src.u.gen3.mode,
+                                            tmp->mask.u.gen3.mode,
+                                            v));
+
+                                       tmp->src.u.gen3.type = SHADER_CONSTANT;
+                                       tmp->src.u.gen3.mode = v;
+                                       tmp->src.is_opaque = false;
+
+                                       tmp->mask.u.gen3.type = SHADER_NONE;
+                               }
+                       }
+               }
+       }
+       DBG(("%s: final src/mask type=%d/%d, affine=%d/%d\n", __FUNCTION__,
+            tmp->src.u.gen3.type, tmp->mask.u.gen3.type,
+            tmp->src.is_affine, tmp->mask.is_affine));
+
+       tmp->prim_emit = gen3_emit_composite_primitive;
+       if (is_constant_ps(tmp->mask.u.gen3.type)) {
+               switch (tmp->src.u.gen3.type) {
+               case SHADER_NONE:
+               case SHADER_ZERO:
+               case SHADER_BLACK:
+               case SHADER_WHITE:
+               case SHADER_CONSTANT:
+                       tmp->prim_emit = gen3_emit_composite_primitive_constant;
+                       break;
+               case SHADER_LINEAR:
+               case SHADER_RADIAL:
+                       if (tmp->src.transform == NULL)
+                               tmp->prim_emit = gen3_emit_composite_primitive_identity_gradient;
+                       else if (tmp->src.is_affine)
+                               tmp->prim_emit = gen3_emit_composite_primitive_affine_gradient;
+                       break;
+               case SHADER_TEXTURE:
+                       if (tmp->src.transform == NULL) {
+                               if ((tmp->src.offset[0]|tmp->src.offset[1]|tmp->dst.x|tmp->dst.y) == 0)
+                                       tmp->prim_emit = gen3_emit_composite_primitive_identity_source_no_offset;
+                               else
+                                       tmp->prim_emit = gen3_emit_composite_primitive_identity_source;
+                       } else if (tmp->src.is_affine)
+                               tmp->prim_emit = gen3_emit_composite_primitive_affine_source;
+                       break;
+               }
+       } else if (tmp->mask.u.gen3.type == SHADER_TEXTURE) {
+               if (tmp->mask.transform == NULL) {
+                       if (is_constant_ps(tmp->src.u.gen3.type)) {
+                               if ((tmp->mask.offset[0]|tmp->mask.offset[1]|tmp->dst.x|tmp->dst.y) == 0)
+                                       tmp->prim_emit = gen3_emit_composite_primitive_constant_identity_mask_no_offset;
+                               else
+                                       tmp->prim_emit = gen3_emit_composite_primitive_constant_identity_mask;
+                       } else if (tmp->src.transform == NULL)
+                               tmp->prim_emit = gen3_emit_composite_primitive_identity_source_mask;
+                       else if (tmp->src.is_affine)
+                               tmp->prim_emit = gen3_emit_composite_primitive_affine_source_mask;
+               }
+       }
+
+       tmp->floats_per_vertex = 2;
+       if (!is_constant_ps(tmp->src.u.gen3.type))
+               tmp->floats_per_vertex += tmp->src.is_affine ? 2 : 4;
+       if (!is_constant_ps(tmp->mask.u.gen3.type))
+               tmp->floats_per_vertex += tmp->mask.is_affine ? 2 : 4;
+       DBG(("%s: floats_per_vertex = 2 + %d + %d = %d [specialised emitter? %d]\n", __FUNCTION__,
+            !is_constant_ps(tmp->src.u.gen3.type) ? tmp->src.is_affine ? 2 : 4 : 0,
+            !is_constant_ps(tmp->mask.u.gen3.type) ? tmp->mask.is_affine ? 2 : 4 : 0,
+            tmp->floats_per_vertex,
+            tmp->prim_emit != gen3_emit_composite_primitive));
+       tmp->floats_per_rect = 3 * tmp->floats_per_vertex;
+
+       tmp->blt   = gen3_render_composite_blt;
+       tmp->box   = gen3_render_composite_box;
+       tmp->boxes = gen3_render_composite_boxes;
+       tmp->done  = gen3_render_composite_done;
+
+       if (!kgem_check_bo(&sna->kgem,
+                          tmp->dst.bo, tmp->src.bo, tmp->mask.bo,
+                          NULL)) {
+               kgem_submit(&sna->kgem);
+               if (!kgem_check_bo(&sna->kgem,
+                                  tmp->dst.bo, tmp->src.bo, tmp->mask.bo,
+                                  NULL))
+                       goto cleanup_mask;
+       }
+
+       gen3_emit_composite_state(sna, tmp);
+       gen3_align_vertex(sna, tmp);
+       return true;
+
+cleanup_mask:
+       if (tmp->mask.bo)
+               kgem_bo_destroy(&sna->kgem, tmp->mask.bo);
+cleanup_src:
+       if (tmp->src.bo)
+               kgem_bo_destroy(&sna->kgem, tmp->src.bo);
+cleanup_dst:
+       if (tmp->redirect.real_bo)
+               kgem_bo_destroy(&sna->kgem, tmp->dst.bo);
+       return false;
+}
+
+static void
+gen3_emit_composite_spans_vertex(struct sna *sna,
+                                const struct sna_composite_spans_op *op,
+                                int16_t x, int16_t y,
+                                float opacity)
+{
+       gen3_emit_composite_dstcoord(sna, x + op->base.dst.x, y + op->base.dst.y);
+       gen3_emit_composite_texcoord(sna, &op->base.src, x, y);
+       OUT_VERTEX(opacity);
+}
+
+fastcall static void
+gen3_emit_composite_spans_primitive_zero(struct sna *sna,
+                                        const struct sna_composite_spans_op *op,
+                                        const BoxRec *box,
+                                        float opacity)
+{
+       float *v = sna->render.vertices + sna->render.vertex_used;
+       sna->render.vertex_used += 6;
+
+       v[0] = op->base.dst.x + box->x2;
+       v[1] = op->base.dst.y + box->y2;
+
+       v[2] = op->base.dst.x + box->x1;
+       v[3] = v[1];
+
+       v[4] = v[2];
+       v[5] = op->base.dst.x + box->y1;
+}
+
+fastcall static void
+gen3_emit_composite_spans_primitive_zero_no_offset(struct sna *sna,
+                                                  const struct sna_composite_spans_op *op,
+                                                  const BoxRec *box,
+                                                  float opacity)
+{
+       float *v = sna->render.vertices + sna->render.vertex_used;
+       sna->render.vertex_used += 6;
+
+       v[0] = box->x2;
+       v[3] = v[1] = box->y2;
+       v[4] = v[2] = box->x1;
+       v[5] = box->y1;
+}
+
+fastcall static void
+gen3_emit_composite_spans_primitive_constant(struct sna *sna,
+                                            const struct sna_composite_spans_op *op,
+                                            const BoxRec *box,
+                                            float opacity)
+{
+       float *v = sna->render.vertices + sna->render.vertex_used;
+       sna->render.vertex_used += 9;
+
+       v[0] = op->base.dst.x + box->x2;
+       v[6] = v[3] = op->base.dst.x + box->x1;
+       v[4] = v[1] = op->base.dst.y + box->y2;
+       v[7] = op->base.dst.y + box->y1;
+       v[8] = v[5] = v[2] = opacity;
+}
+
+fastcall static void
+gen3_emit_composite_spans_primitive_constant_no_offset(struct sna *sna,
+                                                      const struct sna_composite_spans_op *op,
+                                                      const BoxRec *box,
+                                                      float opacity)
+{
+       float *v = sna->render.vertices + sna->render.vertex_used;
+       sna->render.vertex_used += 9;
+
+       v[0] = box->x2;
+       v[6] = v[3] = box->x1;
+       v[4] = v[1] = box->y2;
+       v[7] = box->y1;
+       v[8] = v[5] = v[2] = opacity;
+}
+
+fastcall static void
+gen3_emit_composite_spans_primitive_identity_source(struct sna *sna,
+                                                   const struct sna_composite_spans_op *op,
+                                                   const BoxRec *box,
+                                                   float opacity)
+{
+       float *v = sna->render.vertices + sna->render.vertex_used;
+       sna->render.vertex_used += 15;
+
+       v[0] = op->base.dst.x + box->x2;
+       v[1] = op->base.dst.y + box->y2;
+       v[2] = (op->base.src.offset[0] + box->x2) * op->base.src.scale[0];
+       v[3] = (op->base.src.offset[1] + box->y2) * op->base.src.scale[1];
+       v[4] = opacity;
+
+       v[5] = op->base.dst.x + box->x1;
+       v[6] = v[1];
+       v[7] = (op->base.src.offset[0] + box->x1) * op->base.src.scale[0];
+       v[8] = v[3];
+       v[9] = opacity;
+
+       v[10] = v[5];
+       v[11] = op->base.dst.y + box->y1;
+       v[12] = v[7];
+       v[13] = (op->base.src.offset[1] + box->y1) * op->base.src.scale[1];
+       v[14] = opacity;
+}
+
+fastcall static void
+gen3_emit_composite_spans_primitive_affine_source(struct sna *sna,
+                                                 const struct sna_composite_spans_op *op,
+                                                 const BoxRec *box,
+                                                 float opacity)
+{
+       PictTransform *transform = op->base.src.transform;
+       float x, y, *v;
+
+       v = sna->render.vertices + sna->render.vertex_used;
+       sna->render.vertex_used += 15;
+
+       v[0]  = op->base.dst.x + box->x2;
+       v[6]  = v[1] = op->base.dst.y + box->y2;
+       v[10] = v[5] = op->base.dst.x + box->x1;
+       v[11] = op->base.dst.y + box->y1;
+       v[4]  = opacity;
+       v[9]  = opacity;
+       v[14] = opacity;
+
+       _sna_get_transformed_coordinates((int)op->base.src.offset[0] + box->x2,
+                                        (int)op->base.src.offset[1] + box->y2,
+                                        transform,
+                                        &x, &y);
+       v[2] = x * op->base.src.scale[0];
+       v[3] = y * op->base.src.scale[1];
+
+       _sna_get_transformed_coordinates((int)op->base.src.offset[0] + box->x1,
+                                        (int)op->base.src.offset[1] + box->y2,
+                                        transform,
+                                        &x, &y);
+       v[7] = x * op->base.src.scale[0];
+       v[8] = y * op->base.src.scale[1];
+
+       _sna_get_transformed_coordinates((int)op->base.src.offset[0] + box->x1,
+                                        (int)op->base.src.offset[1] + box->y1,
+                                        transform,
+                                        &x, &y);
+       v[12] = x * op->base.src.scale[0];
+       v[13] = y * op->base.src.scale[1];
+}
+
+fastcall static void
+gen3_emit_composite_spans_primitive_identity_gradient(struct sna *sna,
+                                                     const struct sna_composite_spans_op *op,
+                                                     const BoxRec *box,
+                                                     float opacity)
+{
+       float *v = sna->render.vertices + sna->render.vertex_used;
+       sna->render.vertex_used += 15;
+
+       v[0] = op->base.dst.x + box->x2;
+       v[1] = op->base.dst.y + box->y2;
+       v[2] = op->base.src.offset[0] + box->x2;
+       v[3] = op->base.src.offset[1] + box->y2;
+       v[4] = opacity;
+
+       v[5] = op->base.dst.x + box->x1;
+       v[6] = v[1];
+       v[7] = op->base.src.offset[0] + box->x1;
+       v[8] = v[3];
+       v[9] = opacity;
+
+       v[10] = v[5];
+       v[11] = op->base.dst.y + box->y1;
+       v[12] = v[7];
+       v[13] = op->base.src.offset[1] + box->y1;
+       v[14] = opacity;
+}
+
+fastcall static void
+gen3_emit_composite_spans_primitive_affine_gradient(struct sna *sna,
+                                                   const struct sna_composite_spans_op *op,
+                                                   const BoxRec *box,
+                                                   float opacity)
+{
+       PictTransform *transform = op->base.src.transform;
+       float *v = sna->render.vertices + sna->render.vertex_used;
+       sna->render.vertex_used += 15;
+
+       v[0] = op->base.dst.x + box->x2;
+       v[1] = op->base.dst.y + box->y2;
+       _sna_get_transformed_coordinates((int)op->base.src.offset[0] + box->x2,
+                                        (int)op->base.src.offset[1] + box->y2,
+                                        transform,
+                                        &v[2], &v[3]);
+       v[4] = opacity;
+
+       v[5] = op->base.dst.x + box->x1;
+       v[6] = v[1];
+       _sna_get_transformed_coordinates((int)op->base.src.offset[0] + box->x1,
+                                        (int)op->base.src.offset[1] + box->y2,
+                                        transform,
+                                        &v[7], &v[8]);
+       v[9] = opacity;
+
+       v[10] = v[5];
+       v[11] = op->base.dst.y + box->y1;
+       _sna_get_transformed_coordinates((int)op->base.src.offset[0] + box->x1,
+                                        (int)op->base.src.offset[1] + box->y1,
+                                        transform,
+                                        &v[12], &v[13]);
+       v[14] = opacity;
+}
+
+fastcall static void
+gen3_emit_composite_spans_primitive(struct sna *sna,
+                                   const struct sna_composite_spans_op *op,
+                                   const BoxRec *box,
+                                   float opacity)
+{
+       gen3_emit_composite_spans_vertex(sna, op,
+                                        box->x2, box->y2,
+                                        opacity);
+       gen3_emit_composite_spans_vertex(sna, op,
+                                        box->x1, box->y2,
+                                        opacity);
+       gen3_emit_composite_spans_vertex(sna, op,
+                                        box->x1, box->y1,
+                                        opacity);
+}
+
+fastcall static void
+gen3_render_composite_spans_constant_box(struct sna *sna,
+                                        const struct sna_composite_spans_op *op,
+                                        const BoxRec *box, float opacity)
+{
+       float *v;
+       DBG(("%s: src=+(%d, %d), opacity=%f, dst=+(%d, %d), box=(%d, %d) x (%d, %d)\n",
+            __FUNCTION__,
+            op->base.src.offset[0], op->base.src.offset[1],
+            opacity,
+            op->base.dst.x, op->base.dst.y,
+            box->x1, box->y1,
+            box->x2 - box->x1,
+            box->y2 - box->y1));
+
+       gen3_get_rectangles(sna, &op->base, 1);
+
+       v = sna->render.vertices + sna->render.vertex_used;
+       sna->render.vertex_used += 9;
+
+       v[0] = box->x2;
+       v[6] = v[3] = box->x1;
+       v[4] = v[1] = box->y2;
+       v[7] = box->y1;
+       v[8] = v[5] = v[2] = opacity;
+}
+
+fastcall static void
+gen3_render_composite_spans_box(struct sna *sna,
+                               const struct sna_composite_spans_op *op,
+                               const BoxRec *box, float opacity)
+{
+       DBG(("%s: src=+(%d, %d), opacity=%f, dst=+(%d, %d), box=(%d, %d) x (%d, %d)\n",
+            __FUNCTION__,
+            op->base.src.offset[0], op->base.src.offset[1],
+            opacity,
+            op->base.dst.x, op->base.dst.y,
+            box->x1, box->y1,
+            box->x2 - box->x1,
+            box->y2 - box->y1));
+
+       gen3_get_rectangles(sna, &op->base, 1);
+       op->prim_emit(sna, op, box, opacity);
+}
+
+static void
+gen3_render_composite_spans_boxes(struct sna *sna,
+                                 const struct sna_composite_spans_op *op,
+                                 const BoxRec *box, int nbox,
+                                 float opacity)
+{
+       DBG(("%s: nbox=%d, src=+(%d, %d), opacity=%f, dst=+(%d, %d)\n",
+            __FUNCTION__, nbox,
+            op->base.src.offset[0], op->base.src.offset[1],
+            opacity,
+            op->base.dst.x, op->base.dst.y));
+
+       do {
+               int nbox_this_time;
+
+               nbox_this_time = gen3_get_rectangles(sna, &op->base, nbox);
+               nbox -= nbox_this_time;
+
+               do {
+                       DBG(("  %s: (%d, %d) x (%d, %d)\n", __FUNCTION__,
+                            box->x1, box->y1,
+                            box->x2 - box->x1,
+                            box->y2 - box->y1));
+
+                       op->prim_emit(sna, op, box++, opacity);
+               } while (--nbox_this_time);
+       } while (nbox);
+}
+
+fastcall static void
+gen3_render_composite_spans_done(struct sna *sna,
+                                const struct sna_composite_spans_op *op)
+{
+       if (sna->render_state.gen3.vertex_offset)
+               gen3_vertex_flush(sna);
+
+       DBG(("%s()\n", __FUNCTION__));
+
+       if (op->base.src.bo)
+               kgem_bo_destroy(&sna->kgem, op->base.src.bo);
+
+       sna_render_composite_redirect_done(sna, &op->base);
+}
+
+static bool
+gen3_check_composite_spans(struct sna *sna,
+                          uint8_t op, PicturePtr src, PicturePtr dst,
+                          int16_t width, int16_t height, unsigned flags)
+{
+       if (op >= ARRAY_SIZE(gen3_blend_op))
+               return false;
+
+       if (gen3_composite_fallback(sna, op, src, NULL, dst))
+               return false;
+
+       if (need_tiling(sna, width, height)) {
+               if (!is_gpu(dst->pDrawable)) {
+                       DBG(("%s: fallback, tiled operation not on GPU\n",
+                            __FUNCTION__));
+                       return false;
+               }
+       }
+
+       return true;
+}
+
+static bool
+gen3_render_composite_spans(struct sna *sna,
+                           uint8_t op,
+                           PicturePtr src,
+                           PicturePtr dst,
+                           int16_t src_x,  int16_t src_y,
+                           int16_t dst_x,  int16_t dst_y,
+                           int16_t width,  int16_t height,
+                           unsigned flags,
+                           struct sna_composite_spans_op *tmp)
+{
+       bool no_offset;
+
+       DBG(("%s(src=(%d, %d), dst=(%d, %d), size=(%d, %d))\n", __FUNCTION__,
+            src_x, src_y, dst_x, dst_y, width, height));
+
+       assert(gen3_check_composite_spans(sna, op, src, dst, width, height, flags));
+
+       if (need_tiling(sna, width, height)) {
+               DBG(("%s: tiling, operation (%dx%d) too wide for pipeline\n",
+                    __FUNCTION__, width, height));
+               return sna_tiling_composite_spans(op, src, dst,
+                                                 src_x, src_y, dst_x, dst_y,
+                                                 width, height, flags, tmp);
+       }
+
+       if (!gen3_composite_set_target(sna, &tmp->base, dst,
+                                      dst_x, dst_y, width, height)) {
+               DBG(("%s: unable to set render target\n",
+                    __FUNCTION__));
+               return false;
+       }
+
+       tmp->base.op = op;
+       tmp->base.rb_reversed = gen3_dst_rb_reversed(tmp->base.dst.format);
+       if (too_large(tmp->base.dst.width, tmp->base.dst.height) ||
+           !gen3_check_pitch_3d(tmp->base.dst.bo)) {
+               if (!sna_render_composite_redirect(sna, &tmp->base,
+                                                  dst_x, dst_y, width, height))
+                       return false;
+       }
+
+       tmp->base.src.u.gen3.type = SHADER_TEXTURE;
+       tmp->base.src.is_affine = true;
+       DBG(("%s: preparing source\n", __FUNCTION__));
+       switch (gen3_composite_picture(sna, src, &tmp->base, &tmp->base.src,
+                                      src_x, src_y,
+                                      width, height,
+                                      dst_x, dst_y,
+                                      dst->polyMode == PolyModePrecise)) {
+       case -1:
+               goto cleanup_dst;
+       case 0:
+               tmp->base.src.u.gen3.type = SHADER_ZERO;
+               break;
+       case 1:
+               gen3_composite_channel_convert(&tmp->base.src);
+               break;
+       }
+       DBG(("%s: source type=%d\n", __FUNCTION__, tmp->base.src.u.gen3.type));
+
+       if (tmp->base.src.u.gen3.type != SHADER_ZERO)
+               tmp->base.mask.u.gen3.type = SHADER_OPACITY;
+
+       no_offset = tmp->base.dst.x == 0 && tmp->base.dst.y == 0;
+       tmp->box   = gen3_render_composite_spans_box;
+       tmp->boxes = gen3_render_composite_spans_boxes;
+       tmp->done  = gen3_render_composite_spans_done;
+       tmp->prim_emit = gen3_emit_composite_spans_primitive;
+       switch (tmp->base.src.u.gen3.type) {
+       case SHADER_NONE:
+               assert(0);
+       case SHADER_ZERO:
+               tmp->prim_emit = no_offset ? gen3_emit_composite_spans_primitive_zero_no_offset : gen3_emit_composite_spans_primitive_zero;
+               break;
+       case SHADER_BLACK:
+       case SHADER_WHITE:
+       case SHADER_CONSTANT:
+               if (no_offset) {
+                       tmp->box = gen3_render_composite_spans_constant_box;
+                       tmp->prim_emit = gen3_emit_composite_spans_primitive_constant_no_offset;
+               } else
+                       tmp->prim_emit = gen3_emit_composite_spans_primitive_constant;
+               break;
+       case SHADER_LINEAR:
+       case SHADER_RADIAL:
+               if (tmp->base.src.transform == NULL)
+                       tmp->prim_emit = gen3_emit_composite_spans_primitive_identity_gradient;
+               else if (tmp->base.src.is_affine)
+                       tmp->prim_emit = gen3_emit_composite_spans_primitive_affine_gradient;
+               break;
+       case SHADER_TEXTURE:
+               if (tmp->base.src.transform == NULL)
+                       tmp->prim_emit = gen3_emit_composite_spans_primitive_identity_source;
+               else if (tmp->base.src.is_affine)
+                       tmp->prim_emit = gen3_emit_composite_spans_primitive_affine_source;
+               break;
+       }
+
+       tmp->base.mask.bo = NULL;
+
+       tmp->base.floats_per_vertex = 2;
+       if (!is_constant_ps(tmp->base.src.u.gen3.type))
+               tmp->base.floats_per_vertex += tmp->base.src.is_affine ? 2 : 3;
+       tmp->base.floats_per_vertex +=
+               tmp->base.mask.u.gen3.type == SHADER_OPACITY;
+       tmp->base.floats_per_rect = 3 * tmp->base.floats_per_vertex;
+
+       if (!kgem_check_bo(&sna->kgem,
+                          tmp->base.dst.bo, tmp->base.src.bo,
+                          NULL)) {
+               kgem_submit(&sna->kgem);
+               if (!kgem_check_bo(&sna->kgem,
+                                  tmp->base.dst.bo, tmp->base.src.bo,
+                                  NULL))
+                       goto cleanup_src;
+       }
+
+       gen3_emit_composite_state(sna, &tmp->base);
+       gen3_align_vertex(sna, &tmp->base);
+       return true;
+
+cleanup_src:
+       if (tmp->base.src.bo)
+               kgem_bo_destroy(&sna->kgem, tmp->base.src.bo);
+cleanup_dst:
+       if (tmp->base.redirect.real_bo)
+               kgem_bo_destroy(&sna->kgem, tmp->base.dst.bo);
+       return false;
+}
+
+static void
+gen3_emit_video_state(struct sna *sna,
+                     struct sna_video *video,
+                     struct sna_video_frame *frame,
+                     PixmapPtr pixmap,
+                     struct kgem_bo *dst_bo,
+                     int width, int height)
+{
+       struct gen3_render_state *state = &sna->render_state.gen3;
+       uint32_t id, ms3, rewind;
+
+       gen3_emit_target(sna, dst_bo, width, height,
+                        sna_format_for_depth(pixmap->drawable.depth));
+
+       /* XXX share with composite? Is it worth the effort? */
+       if ((state->last_shader & (1<<31)) == 0) {
+               OUT_BATCH(_3DSTATE_LOAD_STATE_IMMEDIATE_1 |
+                         I1_LOAD_S(1) | I1_LOAD_S(2) | I1_LOAD_S(6) |
+                         2);
+               OUT_BATCH((4 << S1_VERTEX_WIDTH_SHIFT) | (4 << S1_VERTEX_PITCH_SHIFT));
+               OUT_BATCH(S2_TEXCOORD_FMT(0, TEXCOORDFMT_2D) |
+                         S2_TEXCOORD_FMT(1, TEXCOORDFMT_NOT_PRESENT) |
+                         S2_TEXCOORD_FMT(2, TEXCOORDFMT_NOT_PRESENT) |
+                         S2_TEXCOORD_FMT(3, TEXCOORDFMT_NOT_PRESENT) |
+                         S2_TEXCOORD_FMT(4, TEXCOORDFMT_NOT_PRESENT) |
+                         S2_TEXCOORD_FMT(5, TEXCOORDFMT_NOT_PRESENT) |
+                         S2_TEXCOORD_FMT(6, TEXCOORDFMT_NOT_PRESENT) |
+                         S2_TEXCOORD_FMT(7, TEXCOORDFMT_NOT_PRESENT));
+               OUT_BATCH((2 << S6_CBUF_SRC_BLEND_FACT_SHIFT) |
+                         (1 << S6_CBUF_DST_BLEND_FACT_SHIFT) |
+                         S6_COLOR_WRITE_ENABLE);
+
+               state->last_blend = 0;
+               state->floats_per_vertex = 4;
+       }
+
+       if (!is_planar_fourcc(frame->id)) {
+               rewind = sna->kgem.nbatch;
+               OUT_BATCH(_3DSTATE_PIXEL_SHADER_CONSTANTS | 4);
+               OUT_BATCH(0x0000001);   /* constant 0 */
+               /* constant 0: brightness/contrast */
+               OUT_BATCH_F(video->brightness / 128.0);
+               OUT_BATCH_F(video->contrast / 255.0);
+               OUT_BATCH_F(0.0);
+               OUT_BATCH_F(0.0);
+               if (state->last_constants &&
+                   memcmp(&sna->kgem.batch[state->last_constants],
+                          &sna->kgem.batch[rewind],
+                          6*sizeof(uint32_t)) == 0)
+                       sna->kgem.nbatch = rewind;
+               else
+                       state->last_constants = rewind;
+
+               rewind = sna->kgem.nbatch;
+               OUT_BATCH(_3DSTATE_SAMPLER_STATE | 3);
+               OUT_BATCH(0x00000001);
+               OUT_BATCH(SS2_COLORSPACE_CONVERSION |
+                         (FILTER_LINEAR << SS2_MAG_FILTER_SHIFT) |
+                         (FILTER_LINEAR << SS2_MIN_FILTER_SHIFT));
+               OUT_BATCH((TEXCOORDMODE_CLAMP_EDGE <<
+                          SS3_TCX_ADDR_MODE_SHIFT) |
+                         (TEXCOORDMODE_CLAMP_EDGE <<
+                          SS3_TCY_ADDR_MODE_SHIFT) |
+                         (0 << SS3_TEXTUREMAP_INDEX_SHIFT) |
+                         SS3_NORMALIZED_COORDS);
+               OUT_BATCH(0x00000000);
+               if (state->last_sampler &&
+                   memcmp(&sna->kgem.batch[state->last_sampler],
+                          &sna->kgem.batch[rewind],
+                          5*sizeof(uint32_t)) == 0)
+                       sna->kgem.nbatch = rewind;
+               else
+                       state->last_sampler = rewind;
+
+               OUT_BATCH(_3DSTATE_MAP_STATE | 3);
+               OUT_BATCH(0x00000001);  /* texture map #1 */
+               OUT_BATCH(kgem_add_reloc(&sna->kgem, sna->kgem.nbatch,
+                                        frame->bo,
+                                        I915_GEM_DOMAIN_SAMPLER << 16,
+                                        0));
+
+               ms3 = MAPSURF_422;
+               switch (frame->id) {
+               case FOURCC_YUY2:
+                       ms3 |= MT_422_YCRCB_NORMAL;
+                       break;
+               case FOURCC_UYVY:
+                       ms3 |= MT_422_YCRCB_SWAPY;
+                       break;
+               }
+               ms3 |= (frame->height - 1) << MS3_HEIGHT_SHIFT;
+               ms3 |= (frame->width - 1) << MS3_WIDTH_SHIFT;
+               OUT_BATCH(ms3);
+               OUT_BATCH(((frame->pitch[0] / 4) - 1) << MS4_PITCH_SHIFT);
+
+               id = 1<<31 | 1<<1 | !!video->brightness;
+               if (state->last_shader != id) {
+                       state->last_shader = id;
+                       id = sna->kgem.nbatch++;
+
+                       gen3_fs_dcl(FS_S0);
+                       gen3_fs_dcl(FS_T0);
+                       gen3_fs_texld(FS_OC, FS_S0, FS_T0);
+                       if (video->brightness != 0) {
+                               gen3_fs_add(FS_OC,
+                                           gen3_fs_operand_reg(FS_OC),
+                                           gen3_fs_operand(FS_C0, X, X, X, ZERO));
+                       }
+
+                       sna->kgem.batch[id] =
+                               _3DSTATE_PIXEL_SHADER_PROGRAM |
+                               (sna->kgem.nbatch - id - 2);
+               }
+       } else {
+               /* For the planar formats, we set up three samplers --
+                * one for each plane, in a Y8 format.  Because I
+                * couldn't get the special PLANAR_TO_PACKED
+                * shader setup to work, I did the manual pixel shader:
+                *
+                * y' = y - .0625
+                * u' = u - .5
+                * v' = v - .5;
+                *
+                * r = 1.1643 * y' + 0.0     * u' + 1.5958  * v'
+                * g = 1.1643 * y' - 0.39173 * u' - 0.81290 * v'
+                * b = 1.1643 * y' + 2.017   * u' + 0.0     * v'
+                *
+                * register assignment:
+                * r0 = (y',u',v',0)
+                * r1 = (y,y,y,y)
+                * r2 = (u,u,u,u)
+                * r3 = (v,v,v,v)
+                * OC = (r,g,b,1)
+                */
+               rewind = sna->kgem.nbatch;
+               OUT_BATCH(_3DSTATE_PIXEL_SHADER_CONSTANTS | (22 - 2));
+               OUT_BATCH(0x000001f);   /* constants 0-4 */
+               /* constant 0: normalization offsets */
+               OUT_BATCH_F(-0.0625);
+               OUT_BATCH_F(-0.5);
+               OUT_BATCH_F(-0.5);
+               OUT_BATCH_F(0.0);
+               /* constant 1: r coefficients */
+               OUT_BATCH_F(1.1643);
+               OUT_BATCH_F(0.0);
+               OUT_BATCH_F(1.5958);
+               OUT_BATCH_F(0.0);
+               /* constant 2: g coefficients */
+               OUT_BATCH_F(1.1643);
+               OUT_BATCH_F(-0.39173);
+               OUT_BATCH_F(-0.81290);
+               OUT_BATCH_F(0.0);
+               /* constant 3: b coefficients */
+               OUT_BATCH_F(1.1643);
+               OUT_BATCH_F(2.017);
+               OUT_BATCH_F(0.0);
+               OUT_BATCH_F(0.0);
+               /* constant 4: brightness/contrast */
+               OUT_BATCH_F(video->brightness / 128.0);
+               OUT_BATCH_F(video->contrast / 255.0);
+               OUT_BATCH_F(0.0);
+               OUT_BATCH_F(0.0);
+               if (state->last_constants &&
+                   memcmp(&sna->kgem.batch[state->last_constants],
+                          &sna->kgem.batch[rewind],
+                          22*sizeof(uint32_t)) == 0)
+                       sna->kgem.nbatch = rewind;
+               else
+                       state->last_constants = rewind;
+
+               rewind = sna->kgem.nbatch;
+               OUT_BATCH(_3DSTATE_SAMPLER_STATE | 9);
+               OUT_BATCH(0x00000007);
+               /* sampler 0 */
+               OUT_BATCH((FILTER_LINEAR << SS2_MAG_FILTER_SHIFT) |
+                         (FILTER_LINEAR << SS2_MIN_FILTER_SHIFT));
+               OUT_BATCH((TEXCOORDMODE_CLAMP_EDGE <<
+                          SS3_TCX_ADDR_MODE_SHIFT) |
+                         (TEXCOORDMODE_CLAMP_EDGE <<
+                          SS3_TCY_ADDR_MODE_SHIFT) |
+                         (0 << SS3_TEXTUREMAP_INDEX_SHIFT) |
+                         SS3_NORMALIZED_COORDS);
+               OUT_BATCH(0x00000000);
+               /* sampler 1 */
+               OUT_BATCH((FILTER_LINEAR << SS2_MAG_FILTER_SHIFT) |
+                         (FILTER_LINEAR << SS2_MIN_FILTER_SHIFT));
+               OUT_BATCH((TEXCOORDMODE_CLAMP_EDGE <<
+                          SS3_TCX_ADDR_MODE_SHIFT) |
+                         (TEXCOORDMODE_CLAMP_EDGE <<
+                          SS3_TCY_ADDR_MODE_SHIFT) |
+                         (1 << SS3_TEXTUREMAP_INDEX_SHIFT) |
+                         SS3_NORMALIZED_COORDS);
+               OUT_BATCH(0x00000000);
+               /* sampler 2 */
+               OUT_BATCH((FILTER_LINEAR << SS2_MAG_FILTER_SHIFT) |
+                         (FILTER_LINEAR << SS2_MIN_FILTER_SHIFT));
+               OUT_BATCH((TEXCOORDMODE_CLAMP_EDGE <<
+                          SS3_TCX_ADDR_MODE_SHIFT) |
+                         (TEXCOORDMODE_CLAMP_EDGE <<
+                          SS3_TCY_ADDR_MODE_SHIFT) |
+                         (2 << SS3_TEXTUREMAP_INDEX_SHIFT) |
+                         SS3_NORMALIZED_COORDS);
+               OUT_BATCH(0x00000000);
+               if (state->last_sampler &&
+                   memcmp(&sna->kgem.batch[state->last_sampler],
+                          &sna->kgem.batch[rewind],
+                          11*sizeof(uint32_t)) == 0)
+                       sna->kgem.nbatch = rewind;
+               else
+                       state->last_sampler = rewind;
+
+               OUT_BATCH(_3DSTATE_MAP_STATE | 9);
+               OUT_BATCH(0x00000007);
+
+               OUT_BATCH(kgem_add_reloc(&sna->kgem, sna->kgem.nbatch,
+                                        frame->bo,
+                                        I915_GEM_DOMAIN_SAMPLER << 16,
+                                        0));
+
+               ms3 = MAPSURF_8BIT | MT_8BIT_I8;
+               ms3 |= (frame->height - 1) << MS3_HEIGHT_SHIFT;
+               ms3 |= (frame->width - 1) << MS3_WIDTH_SHIFT;
+               OUT_BATCH(ms3);
+               /* check to see if Y has special pitch than normal
+                * double u/v pitch, e.g i915 XvMC hw requires at
+                * least 1K alignment, so Y pitch might
+                * be same as U/V's.*/
+               if (frame->pitch[1])
+                       OUT_BATCH(((frame->pitch[1] / 4) - 1) << MS4_PITCH_SHIFT);
+               else
+                       OUT_BATCH(((frame->pitch[0] * 2 / 4) - 1) << MS4_PITCH_SHIFT);
+
+               OUT_BATCH(kgem_add_reloc(&sna->kgem, sna->kgem.nbatch,
+                                        frame->bo,
+                                        I915_GEM_DOMAIN_SAMPLER << 16,
+                                        frame->UBufOffset));
+
+               ms3 = MAPSURF_8BIT | MT_8BIT_I8;
+               ms3 |= (frame->height / 2 - 1) << MS3_HEIGHT_SHIFT;
+               ms3 |= (frame->width / 2 - 1) << MS3_WIDTH_SHIFT;
+               OUT_BATCH(ms3);
+               OUT_BATCH(((frame->pitch[0] / 4) - 1) << MS4_PITCH_SHIFT);
+
+               OUT_BATCH(kgem_add_reloc(&sna->kgem, sna->kgem.nbatch,
+                                        frame->bo,
+                                        I915_GEM_DOMAIN_SAMPLER << 16,
+                                        frame->VBufOffset));
+
+               ms3 = MAPSURF_8BIT | MT_8BIT_I8;
+               ms3 |= (frame->height / 2 - 1) << MS3_HEIGHT_SHIFT;
+               ms3 |= (frame->width / 2 - 1) << MS3_WIDTH_SHIFT;
+               OUT_BATCH(ms3);
+               OUT_BATCH(((frame->pitch[0] / 4) - 1) << MS4_PITCH_SHIFT);
+
+               id = 1<<31 | 2<<1 | !!video->brightness;
+               if (state->last_shader != id) {
+                       state->last_shader = id;
+                       id = sna->kgem.nbatch++;
+
+                       /* Declare samplers */
+                       gen3_fs_dcl(FS_S0);     /* Y */
+                       gen3_fs_dcl(FS_S1);     /* U */
+                       gen3_fs_dcl(FS_S2);     /* V */
+                       gen3_fs_dcl(FS_T0);     /* normalized coords */
+
+                       /* Load samplers to temporaries. */
+                       gen3_fs_texld(FS_R1, FS_S0, FS_T0);
+                       gen3_fs_texld(FS_R2, FS_S1, FS_T0);
+                       gen3_fs_texld(FS_R3, FS_S2, FS_T0);
+
+                       /* Move the sampled YUV data in R[123] to the first
+                        * 3 channels of R0.
+                        */
+                       gen3_fs_mov_masked(FS_R0, MASK_X,
+                                          gen3_fs_operand_reg(FS_R1));
+                       gen3_fs_mov_masked(FS_R0, MASK_Y,
+                                          gen3_fs_operand_reg(FS_R2));
+                       gen3_fs_mov_masked(FS_R0, MASK_Z,
+                                          gen3_fs_operand_reg(FS_R3));
+
+                       /* Normalize the YUV data */
+                       gen3_fs_add(FS_R0, gen3_fs_operand_reg(FS_R0),
+                                   gen3_fs_operand_reg(FS_C0));
+                       /* dot-product the YUV data in R0 by the vectors of
+                        * coefficients for calculating R, G, and B, storing
+                        * the results in the R, G, or B channels of the output
+                        * color.  The OC results are implicitly clamped
+                        * at the end of the program.
+                        */
+                       gen3_fs_dp3(FS_OC, MASK_X,
+                                   gen3_fs_operand_reg(FS_R0),
+                                   gen3_fs_operand_reg(FS_C1));
+                       gen3_fs_dp3(FS_OC, MASK_Y,
+                                   gen3_fs_operand_reg(FS_R0),
+                                   gen3_fs_operand_reg(FS_C2));
+                       gen3_fs_dp3(FS_OC, MASK_Z,
+                                   gen3_fs_operand_reg(FS_R0),
+                                   gen3_fs_operand_reg(FS_C3));
+                       /* Set alpha of the output to 1.0, by wiring W to 1
+                        * and not actually using the source.
+                        */
+                       gen3_fs_mov_masked(FS_OC, MASK_W,
+                                          gen3_fs_operand_one());
+
+                       if (video->brightness != 0) {
+                               gen3_fs_add(FS_OC,
+                                           gen3_fs_operand_reg(FS_OC),
+                                           gen3_fs_operand(FS_C4, X, X, X, ZERO));
+                       }
+
+                       sna->kgem.batch[id] =
+                               _3DSTATE_PIXEL_SHADER_PROGRAM |
+                               (sna->kgem.nbatch - id - 2);
+               }
+       }
+
+}
+
+static void
+gen3_video_get_batch(struct sna *sna)
+{
+       kgem_set_mode(&sna->kgem, KGEM_RENDER);
+
+       if (!kgem_check_batch(&sna->kgem, 120) ||
+           !kgem_check_reloc(&sna->kgem, 4) ||
+           !kgem_check_exec(&sna->kgem, 2)) {
+               _kgem_submit(&sna->kgem);
+               _kgem_set_mode(&sna->kgem, KGEM_RENDER);
+       }
+
+       if (sna->render_state.gen3.need_invariant)
+               gen3_emit_invariant(sna);
+}
+
+static int
+gen3_get_inline_rectangles(struct sna *sna, int want, int floats_per_vertex)
+{
+       int size = floats_per_vertex * 3;
+       int rem = batch_space(sna) - 1;
+
+       if (size * want > rem)
+               want = rem / size;
+
+       return want;
+}
+
+static bool
+gen3_render_video(struct sna *sna,
+                 struct sna_video *video,
+                 struct sna_video_frame *frame,
+                 RegionPtr dstRegion,
+                 short src_w, short src_h,
+                 short drw_w, short drw_h,
+                 PixmapPtr pixmap)
+{
+       struct sna_pixmap *priv = sna_pixmap(pixmap);
+       BoxPtr pbox = REGION_RECTS(dstRegion);
+       int nbox = REGION_NUM_RECTS(dstRegion);
+       int dxo = dstRegion->extents.x1;
+       int dyo = dstRegion->extents.y1;
+       int width = dstRegion->extents.x2 - dxo;
+       int height = dstRegion->extents.y2 - dyo;
+       float src_scale_x, src_scale_y;
+       int pix_xoff, pix_yoff;
+       struct kgem_bo *dst_bo;
+       int copy = 0;
+
+       DBG(("%s: %dx%d -> %dx%d\n", __FUNCTION__, src_w, src_h, drw_w, drw_h));
+
+       dst_bo = priv->gpu_bo;
+       if (dst_bo == NULL)
+               return false;
+
+       if (too_large(pixmap->drawable.width, pixmap->drawable.height) ||
+           !gen3_check_pitch_3d(dst_bo)) {
+               int bpp = pixmap->drawable.bitsPerPixel;
+
+               dst_bo = kgem_create_2d(&sna->kgem,
+                                       width, height, bpp,
+                                       kgem_choose_tiling(&sna->kgem,
+                                                          I915_TILING_X,
+                                                          width, height, bpp),
+                                       0);
+               if (!dst_bo)
+                       return false;
+
+               pix_xoff = -dxo;
+               pix_yoff = -dyo;
+               copy = 1;
+       } else {
+               width = pixmap->drawable.width;
+               height = pixmap->drawable.height;
+
+               /* Set up the offset for translating from the given region
+                * (in screen coordinates) to the backing pixmap.
+                */
+#ifdef COMPOSITE
+               pix_xoff = -pixmap->screen_x + pixmap->drawable.x;
+               pix_yoff = -pixmap->screen_y + pixmap->drawable.y;
+#else
+               pix_xoff = 0;
+               pix_yoff = 0;
+#endif
+       }
+
+       src_scale_x = ((float)src_w / frame->width) / drw_w;
+       src_scale_y = ((float)src_h / frame->height) / drw_h;
+
+       DBG(("%s: src offset=(%d, %d), scale=(%f, %f), dst offset=(%d, %d)\n",
+            __FUNCTION__,
+            dxo, dyo, src_scale_x, src_scale_y, pix_xoff, pix_yoff));
+
+       gen3_video_get_batch(sna);
+       gen3_emit_video_state(sna, video, frame, pixmap,
+                             dst_bo, width, height);
+       do {
+               int nbox_this_time = gen3_get_inline_rectangles(sna, nbox, 4);
+               if (nbox_this_time == 0) {
+                       gen3_video_get_batch(sna);
+                       gen3_emit_video_state(sna, video, frame, pixmap,
+                                             dst_bo, width, height);
+                       nbox_this_time = gen3_get_inline_rectangles(sna, nbox, 4);
+               }
+               nbox -= nbox_this_time;
+
+               OUT_BATCH(PRIM3D_RECTLIST | (12 * nbox_this_time - 1));
+               while (nbox_this_time--) {
+                       int box_x1 = pbox->x1;
+                       int box_y1 = pbox->y1;
+                       int box_x2 = pbox->x2;
+                       int box_y2 = pbox->y2;
+
+                       pbox++;
+
+                       DBG(("%s: box (%d, %d), (%d, %d)\n",
+                            __FUNCTION__, box_x1, box_y1, box_x2, box_y2));
+
+                       /* bottom right */
+                       OUT_BATCH_F(box_x2 + pix_xoff);
+                       OUT_BATCH_F(box_y2 + pix_yoff);
+                       OUT_BATCH_F((box_x2 - dxo) * src_scale_x);
+                       OUT_BATCH_F((box_y2 - dyo) * src_scale_y);
+
+                       /* bottom left */
+                       OUT_BATCH_F(box_x1 + pix_xoff);
+                       OUT_BATCH_F(box_y2 + pix_yoff);
+                       OUT_BATCH_F((box_x1 - dxo) * src_scale_x);
+                       OUT_BATCH_F((box_y2 - dyo) * src_scale_y);
+
+                       /* top left */
+                       OUT_BATCH_F(box_x1 + pix_xoff);
+                       OUT_BATCH_F(box_y1 + pix_yoff);
+                       OUT_BATCH_F((box_x1 - dxo) * src_scale_x);
+                       OUT_BATCH_F((box_y1 - dyo) * src_scale_y);
+               }
+       } while (nbox);
+
+       if (copy) {
+#ifdef COMPOSITE
+               pix_xoff = -pixmap->screen_x + pixmap->drawable.x;
+               pix_yoff = -pixmap->screen_y + pixmap->drawable.y;
+#else
+               pix_xoff = 0;
+               pix_yoff = 0;
+#endif
+               sna_blt_copy_boxes(sna, GXcopy,
+                                  dst_bo, -dxo, -dyo,
+                                  priv->gpu_bo, pix_xoff, pix_yoff,
+                                  pixmap->drawable.bitsPerPixel,
+                                  REGION_RECTS(dstRegion),
+                                  REGION_NUM_RECTS(dstRegion));
+
+               kgem_bo_destroy(&sna->kgem, dst_bo);
+       }
+
+       if (!DAMAGE_IS_ALL(priv->gpu_damage)) {
+               if ((pix_xoff | pix_yoff) == 0) {
+                       sna_damage_add(&priv->gpu_damage, dstRegion);
+                       sna_damage_subtract(&priv->cpu_damage, dstRegion);
+               } else {
+                       sna_damage_add_boxes(&priv->gpu_damage,
+                                            REGION_RECTS(dstRegion),
+                                            REGION_NUM_RECTS(dstRegion),
+                                            pix_xoff, pix_yoff);
+                       sna_damage_subtract_boxes(&priv->cpu_damage,
+                                                 REGION_RECTS(dstRegion),
+                                                 REGION_NUM_RECTS(dstRegion),
+                                                 pix_xoff, pix_yoff);
+               }
+       }
+       priv->clear = false;
+
+       return true;
+}
+
+static void
+gen3_render_copy_setup_source(struct sna_composite_channel *channel,
+                             PixmapPtr pixmap,
+                             struct kgem_bo *bo)
+{
+       channel->u.gen3.type = SHADER_TEXTURE;
+       channel->filter = gen3_filter(PictFilterNearest);
+       channel->repeat = gen3_texture_repeat(RepeatNone);
+       channel->width  = pixmap->drawable.width;
+       channel->height = pixmap->drawable.height;
+       channel->scale[0] = 1.f/pixmap->drawable.width;
+       channel->scale[1] = 1.f/pixmap->drawable.height;
+       channel->offset[0] = 0;
+       channel->offset[1] = 0;
+       gen3_composite_channel_set_format(channel,
+                                         sna_format_for_depth(pixmap->drawable.depth));
+       channel->bo = bo;
+       channel->is_affine = 1;
+}
+
+static bool
+gen3_render_copy_boxes(struct sna *sna, uint8_t alu,
+                      PixmapPtr src, struct kgem_bo *src_bo, int16_t src_dx, int16_t src_dy,
+                      PixmapPtr dst, struct kgem_bo *dst_bo, int16_t dst_dx, int16_t dst_dy,
+                      const BoxRec *box, int n, unsigned flags)
+{
+       struct sna_composite_op tmp;
+
+#if NO_COPY_BOXES
+       if (!sna_blt_compare_depth(&src->drawable, &dst->drawable))
+               return false;
+
+       return sna_blt_copy_boxes(sna, alu,
+                                 src_bo, src_dx, src_dy,
+                                 dst_bo, dst_dx, dst_dy,
+                                 dst->drawable.bitsPerPixel,
+                                 box, n);
+#endif
+
+       DBG(("%s (%d, %d)->(%d, %d) x %d\n",
+            __FUNCTION__, src_dx, src_dy, dst_dx, dst_dy, n));
+
+       if (sna_blt_compare_depth(&src->drawable, &dst->drawable) &&
+           sna_blt_copy_boxes(sna, alu,
+                              src_bo, src_dx, src_dy,
+                              dst_bo, dst_dx, dst_dy,
+                              dst->drawable.bitsPerPixel,
+                              box, n))
+               return true;
+
+       if (!(alu == GXcopy || alu == GXclear) ||
+           src_bo == dst_bo || /* XXX handle overlap using 3D ? */
+           src_bo->pitch > MAX_3D_PITCH ||
+           too_large(src->drawable.width, src->drawable.height)) {
+fallback_blt:
+               if (!kgem_bo_can_blt(&sna->kgem, src_bo) ||
+                   !kgem_bo_can_blt(&sna->kgem, dst_bo))
+                       return false;
+
+               return sna_blt_copy_boxes_fallback(sna, alu,
+                                                  src, src_bo, src_dx, src_dy,
+                                                  dst, dst_bo, dst_dx, dst_dy,
+                                                  box, n);
+       }
+
+       if (!kgem_check_bo(&sna->kgem, dst_bo, src_bo, NULL)) {
+               kgem_submit(&sna->kgem);
+               if (!kgem_check_bo(&sna->kgem, dst_bo, src_bo, NULL))
+                       goto fallback_blt;
+       }
+
+       memset(&tmp, 0, sizeof(tmp));
+       tmp.op = alu == GXcopy ? PictOpSrc : PictOpClear;
+
+       tmp.dst.pixmap = dst;
+       tmp.dst.width = dst->drawable.width;
+       tmp.dst.height = dst->drawable.height;
+       tmp.dst.format = sna_format_for_depth(dst->drawable.depth);
+       tmp.dst.bo = dst_bo;
+       tmp.dst.x = tmp.dst.y = 0;
+       tmp.damage = NULL;
+
+       sna_render_composite_redirect_init(&tmp);
+       if (too_large(tmp.dst.width, tmp.dst.height) ||
+           dst_bo->pitch > MAX_3D_PITCH) {
+               BoxRec extents = box[0];
+               int i;
+
+               for (i = 1; i < n; i++) {
+                       if (box[i].x1 < extents.x1)
+                               extents.x1 = box[i].x1;
+                       if (box[i].y1 < extents.y1)
+                               extents.y1 = box[i].y1;
+
+                       if (box[i].x2 > extents.x2)
+                               extents.x2 = box[i].x2;
+                       if (box[i].y2 > extents.y2)
+                               extents.y2 = box[i].y2;
+               }
+               if (!sna_render_composite_redirect(sna, &tmp,
+                                                  extents.x1 + dst_dx,
+                                                  extents.y1 + dst_dy,
+                                                  extents.x2 - extents.x1,
+                                                  extents.y2 - extents.y1))
+                       goto fallback_tiled;
+       }
+
+       gen3_render_copy_setup_source(&tmp.src, src, src_bo);
+
+       tmp.floats_per_vertex = 4;
+       tmp.floats_per_rect = 12;
+       tmp.mask.bo = NULL;
+       tmp.mask.u.gen3.type = SHADER_NONE;
+
+       dst_dx += tmp.dst.x;
+       dst_dy += tmp.dst.y;
+       tmp.dst.x = tmp.dst.y = 0;
+
+       gen3_emit_composite_state(sna, &tmp);
+       gen3_align_vertex(sna, &tmp);
+
+       do {
+               int n_this_time;
+
+               n_this_time = gen3_get_rectangles(sna, &tmp, n);
+               n -= n_this_time;
+
+               do {
+                       DBG(("  (%d, %d) -> (%d, %d) + (%d, %d)\n",
+                            box->x1 + src_dx, box->y1 + src_dy,
+                            box->x1 + dst_dx, box->y1 + dst_dy,
+                            box->x2 - box->x1, box->y2 - box->y1));
+                       OUT_VERTEX(box->x2 + dst_dx);
+                       OUT_VERTEX(box->y2 + dst_dy);
+                       OUT_VERTEX((box->x2 + src_dx) * tmp.src.scale[0]);
+                       OUT_VERTEX((box->y2 + src_dy) * tmp.src.scale[1]);
+
+                       OUT_VERTEX(box->x1 + dst_dx);
+                       OUT_VERTEX(box->y2 + dst_dy);
+                       OUT_VERTEX((box->x1 + src_dx) * tmp.src.scale[0]);
+                       OUT_VERTEX((box->y2 + src_dy) * tmp.src.scale[1]);
+
+                       OUT_VERTEX(box->x1 + dst_dx);
+                       OUT_VERTEX(box->y1 + dst_dy);
+                       OUT_VERTEX((box->x1 + src_dx) * tmp.src.scale[0]);
+                       OUT_VERTEX((box->y1 + src_dy) * tmp.src.scale[1]);
+
+                       box++;
+               } while (--n_this_time);
+       } while (n);
+
+       gen3_vertex_flush(sna);
+       sna_render_composite_redirect_done(sna, &tmp);
+       return true;
+
+fallback_tiled:
+       return sna_tiling_copy_boxes(sna, alu,
+                                    src, src_bo, src_dx, src_dy,
+                                    dst, dst_bo, dst_dx, dst_dy,
+                                    box, n);
+}
+
+static void
+gen3_render_copy_blt(struct sna *sna,
+                    const struct sna_copy_op *op,
+                    int16_t sx, int16_t sy,
+                    int16_t w, int16_t h,
+                    int16_t dx, int16_t dy)
+{
+       gen3_get_rectangles(sna, &op->base, 1);
+
+       OUT_VERTEX(dx+w);
+       OUT_VERTEX(dy+h);
+       OUT_VERTEX((sx+w)*op->base.src.scale[0]);
+       OUT_VERTEX((sy+h)*op->base.src.scale[1]);
+
+       OUT_VERTEX(dx);
+       OUT_VERTEX(dy+h);
+       OUT_VERTEX(sx*op->base.src.scale[0]);
+       OUT_VERTEX((sy+h)*op->base.src.scale[1]);
+
+       OUT_VERTEX(dx);
+       OUT_VERTEX(dy);
+       OUT_VERTEX(sx*op->base.src.scale[0]);
+       OUT_VERTEX(sy*op->base.src.scale[1]);
+}
+
+static void
+gen3_render_copy_done(struct sna *sna, const struct sna_copy_op *op)
+{
+       if (sna->render_state.gen3.vertex_offset)
+               gen3_vertex_flush(sna);
+}
+
+static bool
+gen3_render_copy(struct sna *sna, uint8_t alu,
+                PixmapPtr src, struct kgem_bo *src_bo,
+                PixmapPtr dst, struct kgem_bo *dst_bo,
+                struct sna_copy_op *tmp)
+{
+#if NO_COPY
+       if (!sna_blt_compare_depth(&src->drawable, &dst->drawable))
+               return false;
+
+       return sna_blt_copy(sna, alu,
+                           src_bo, dst_bo,
+                           dst->drawable.bitsPerPixel,
+                           tmp);
+#endif
+
+       /* Prefer to use the BLT */
+       if (sna->kgem.mode != KGEM_RENDER &&
+           sna_blt_compare_depth(&src->drawable, &dst->drawable) &&
+           sna_blt_copy(sna, alu,
+                        src_bo, dst_bo,
+                        dst->drawable.bitsPerPixel,
+                        tmp))
+               return true;
+
+       /* Must use the BLT if we can't RENDER... */
+       if (!(alu == GXcopy || alu == GXclear) ||
+           too_large(src->drawable.width, src->drawable.height) ||
+           too_large(dst->drawable.width, dst->drawable.height) ||
+           src_bo->pitch > MAX_3D_PITCH || dst_bo->pitch > MAX_3D_PITCH) {
+fallback:
+               if (!sna_blt_compare_depth(&src->drawable, &dst->drawable))
+                       return false;
+
+               return sna_blt_copy(sna, alu, src_bo, dst_bo,
+                                   dst->drawable.bitsPerPixel,
+                                   tmp);
+       }
+
+       tmp->base.op = alu == GXcopy ? PictOpSrc : PictOpClear;
+
+       tmp->base.dst.pixmap = dst;
+       tmp->base.dst.width = dst->drawable.width;
+       tmp->base.dst.height = dst->drawable.height;
+       tmp->base.dst.format = sna_format_for_depth(dst->drawable.depth);
+       tmp->base.dst.bo = dst_bo;
+
+       gen3_render_copy_setup_source(&tmp->base.src, src, src_bo);
+
+       tmp->base.floats_per_vertex = 4;
+       tmp->base.floats_per_rect = 12;
+       tmp->base.mask.bo = NULL;
+       tmp->base.mask.u.gen3.type = SHADER_NONE;
+
+       if (!kgem_check_bo(&sna->kgem, dst_bo, src_bo, NULL)) {
+               kgem_submit(&sna->kgem);
+               if (!kgem_check_bo(&sna->kgem, dst_bo, src_bo, NULL))
+                       goto fallback;
+       }
+
+       tmp->blt  = gen3_render_copy_blt;
+       tmp->done = gen3_render_copy_done;
+
+       gen3_emit_composite_state(sna, &tmp->base);
+       gen3_align_vertex(sna, &tmp->base);
+       return true;
+}
+
+static bool
+gen3_render_fill_boxes_try_blt(struct sna *sna,
+                              CARD8 op, PictFormat format,
+                              const xRenderColor *color,
+                              PixmapPtr dst, struct kgem_bo *dst_bo,
+                              const BoxRec *box, int n)
+{
+       uint8_t alu;
+       uint32_t pixel;
+
+       if (dst_bo->tiling == I915_TILING_Y) {
+               DBG(("%s: y-tiling, can't blit\n", __FUNCTION__));
+               assert(!too_large(dst->drawable.width, dst->drawable.height));
+               return false;
+       }
+
+       if (op > PictOpSrc)
+               return false;
+
+       if (op == PictOpClear) {
+               alu = GXclear;
+               pixel = 0;
+       } else if (!sna_get_pixel_from_rgba(&pixel,
+                                           color->red,
+                                           color->green,
+                                           color->blue,
+                                           color->alpha,
+                                           format))
+               return false;
+       else
+               alu = GXcopy;
+
+       return sna_blt_fill_boxes(sna, alu,
+                                 dst_bo, dst->drawable.bitsPerPixel,
+                                 pixel, box, n);
+}
+
+static inline bool prefer_fill_blt(struct sna *sna)
+{
+#if PREFER_BLT_FILL
+       return true;
+#else
+       return sna->kgem.mode != KGEM_RENDER;
+#endif
+}
+
+static bool
+gen3_render_fill_boxes(struct sna *sna,
+                      CARD8 op,
+                      PictFormat format,
+                      const xRenderColor *color,
+                      PixmapPtr dst, struct kgem_bo *dst_bo,
+                      const BoxRec *box, int n)
+{
+       struct sna_composite_op tmp;
+       uint32_t pixel;
+
+       if (op >= ARRAY_SIZE(gen3_blend_op)) {
+               DBG(("%s: fallback due to unhandled blend op: %d\n",
+                    __FUNCTION__, op));
+               return false;
+       }
+
+#if NO_FILL_BOXES
+       return gen3_render_fill_boxes_try_blt(sna, op, format, color,
+                                             dst, dst_bo,
+                                             box, n);
+#endif
+
+       DBG(("%s (op=%d, format=%x, color=(%04x,%04x,%04x, %04x))\n",
+            __FUNCTION__, op, (int)format,
+            color->red, color->green, color->blue, color->alpha));
+
+       if (too_large(dst->drawable.width, dst->drawable.height) ||
+           dst_bo->pitch > MAX_3D_PITCH ||
+           !gen3_check_dst_format(format)) {
+               DBG(("%s: try blt, too large or incompatible destination\n",
+                    __FUNCTION__));
+               if (gen3_render_fill_boxes_try_blt(sna, op, format, color,
+                                                  dst, dst_bo,
+                                                  box, n))
+                       return true;
+
+               if (!gen3_check_dst_format(format))
+                       return false;
+
+               return sna_tiling_fill_boxes(sna, op, format, color,
+                                            dst, dst_bo, box, n);
+       }
+
+       if (prefer_fill_blt(sna) &&
+           gen3_render_fill_boxes_try_blt(sna, op, format, color,
+                                          dst, dst_bo,
+                                          box, n))
+               return true;
+
+       if (op == PictOpClear) {
+               pixel = 0;
+       } else {
+               if (!sna_get_pixel_from_rgba(&pixel,
+                                            color->red,
+                                            color->green,
+                                            color->blue,
+                                            color->alpha,
+                                            PICT_a8r8g8b8)) {
+                       assert(0);
+                       return false;
+               }
+       }
+       DBG(("%s: using shader for op=%d, format=%x, pixel=%x\n",
+            __FUNCTION__, op, (int)format, pixel));
+
+       tmp.op = op;
+       tmp.dst.pixmap = dst;
+       tmp.dst.width = dst->drawable.width;
+       tmp.dst.height = dst->drawable.height;
+       tmp.dst.format = format;
+       tmp.dst.bo = dst_bo;
+       tmp.floats_per_vertex = 2;
+       tmp.floats_per_rect = 6;
+       tmp.rb_reversed = 0;
+       tmp.has_component_alpha = 0;
+       tmp.need_magic_ca_pass = false;
+
+       gen3_init_solid(&tmp.src, pixel);
+       tmp.mask.bo = NULL;
+       tmp.mask.u.gen3.type = SHADER_NONE;
+       tmp.u.gen3.num_constants = 0;
+
+       if (!kgem_check_bo(&sna->kgem, dst_bo, NULL)) {
+               kgem_submit(&sna->kgem);
+               assert(kgem_check_bo(&sna->kgem, dst_bo, NULL));
+       }
+
+       gen3_emit_composite_state(sna, &tmp);
+       gen3_align_vertex(sna, &tmp);
+
+       do {
+               int n_this_time;
+
+               n_this_time = gen3_get_rectangles(sna, &tmp, n);
+               n -= n_this_time;
+
+               do {
+                       DBG(("  (%d, %d), (%d, %d): %x\n",
+                            box->x1, box->y1, box->x2, box->y2, pixel));
+                       OUT_VERTEX(box->x2);
+                       OUT_VERTEX(box->y2);
+                       OUT_VERTEX(box->x1);
+                       OUT_VERTEX(box->y2);
+                       OUT_VERTEX(box->x1);
+                       OUT_VERTEX(box->y1);
+                       box++;
+               } while (--n_this_time);
+       } while (n);
+
+       gen3_vertex_flush(sna);
+       return true;
+}
+
+static void
+gen3_render_fill_op_blt(struct sna *sna,
+                       const struct sna_fill_op *op,
+                       int16_t x, int16_t y, int16_t w, int16_t h)
+{
+       gen3_get_rectangles(sna, &op->base, 1);
+
+       OUT_VERTEX(x+w);
+       OUT_VERTEX(y+h);
+       OUT_VERTEX(x);
+       OUT_VERTEX(y+h);
+       OUT_VERTEX(x);
+       OUT_VERTEX(y);
+}
+
+fastcall static void
+gen3_render_fill_op_box(struct sna *sna,
+                       const struct sna_fill_op *op,
+                       const BoxRec *box)
+{
+       gen3_get_rectangles(sna, &op->base, 1);
+
+       OUT_VERTEX(box->x2);
+       OUT_VERTEX(box->y2);
+       OUT_VERTEX(box->x1);
+       OUT_VERTEX(box->y2);
+       OUT_VERTEX(box->x1);
+       OUT_VERTEX(box->y1);
+}
+
+fastcall static void
+gen3_render_fill_op_boxes(struct sna *sna,
+                         const struct sna_fill_op *op,
+                         const BoxRec *box,
+                         int nbox)
+{
+       DBG(("%s: (%d, %d),(%d, %d)... x %d\n", __FUNCTION__,
+            box->x1, box->y1, box->x2, box->y2, nbox));
+
+       do {
+               int nbox_this_time;
+
+               nbox_this_time = gen3_get_rectangles(sna, &op->base, nbox);
+               nbox -= nbox_this_time;
+
+               do {
+                       OUT_VERTEX(box->x2);
+                       OUT_VERTEX(box->y2);
+                       OUT_VERTEX(box->x1);
+                       OUT_VERTEX(box->y2);
+                       OUT_VERTEX(box->x1);
+                       OUT_VERTEX(box->y1);
+                       box++;
+               } while (--nbox_this_time);
+       } while (nbox);
+}
+
+static void
+gen3_render_fill_op_done(struct sna *sna, const struct sna_fill_op *op)
+{
+       if (sna->render_state.gen3.vertex_offset)
+               gen3_vertex_flush(sna);
+}
+
+static bool
+gen3_render_fill(struct sna *sna, uint8_t alu,
+                PixmapPtr dst, struct kgem_bo *dst_bo,
+                uint32_t color,
+                struct sna_fill_op *tmp)
+{
+#if NO_FILL
+       return sna_blt_fill(sna, alu,
+                           dst_bo, dst->drawable.bitsPerPixel,
+                           color,
+                           tmp);
+#endif
+
+       /* Prefer to use the BLT if already engaged */
+       if (prefer_fill_blt(sna) &&
+           sna_blt_fill(sna, alu,
+                        dst_bo, dst->drawable.bitsPerPixel,
+                        color,
+                        tmp))
+               return true;
+
+       /* Must use the BLT if we can't RENDER... */
+       if (!(alu == GXcopy || alu == GXclear) ||
+           too_large(dst->drawable.width, dst->drawable.height) ||
+           dst_bo->pitch > MAX_3D_PITCH)
+               return sna_blt_fill(sna, alu,
+                                   dst_bo, dst->drawable.bitsPerPixel,
+                                   color,
+                                   tmp);
+
+       if (alu == GXclear)
+               color = 0;
+
+       tmp->base.op = color == 0 ? PictOpClear : PictOpSrc;
+       tmp->base.dst.pixmap = dst;
+       tmp->base.dst.width = dst->drawable.width;
+       tmp->base.dst.height = dst->drawable.height;
+       tmp->base.dst.format = sna_format_for_depth(dst->drawable.depth);
+       tmp->base.dst.bo = dst_bo;
+       tmp->base.floats_per_vertex = 2;
+       tmp->base.floats_per_rect = 6;
+       tmp->base.need_magic_ca_pass = 0;
+       tmp->base.has_component_alpha = 0;
+       tmp->base.rb_reversed = 0;
+
+       gen3_init_solid(&tmp->base.src,
+                       sna_rgba_for_color(color, dst->drawable.depth));
+       tmp->base.mask.bo = NULL;
+       tmp->base.mask.u.gen3.type = SHADER_NONE;
+       tmp->base.u.gen3.num_constants = 0;
+
+       if (!kgem_check_bo(&sna->kgem, dst_bo, NULL)) {
+               kgem_submit(&sna->kgem);
+               assert(kgem_check_bo(&sna->kgem, dst_bo, NULL));
+       }
+
+       tmp->blt   = gen3_render_fill_op_blt;
+       tmp->box   = gen3_render_fill_op_box;
+       tmp->boxes = gen3_render_fill_op_boxes;
+       tmp->done  = gen3_render_fill_op_done;
+
+       gen3_emit_composite_state(sna, &tmp->base);
+       gen3_align_vertex(sna, &tmp->base);
+       return true;
+}
+
+static bool
+gen3_render_fill_one_try_blt(struct sna *sna, PixmapPtr dst, struct kgem_bo *bo,
+                            uint32_t color,
+                            int16_t x1, int16_t y1, int16_t x2, int16_t y2,
+                            uint8_t alu)
+{
+       BoxRec box;
+
+       box.x1 = x1;
+       box.y1 = y1;
+       box.x2 = x2;
+       box.y2 = y2;
+
+       return sna_blt_fill_boxes(sna, alu,
+                                 bo, dst->drawable.bitsPerPixel,
+                                 color, &box, 1);
+}
+
+static bool
+gen3_render_fill_one(struct sna *sna, PixmapPtr dst, struct kgem_bo *bo,
+                    uint32_t color,
+                    int16_t x1, int16_t y1,
+                    int16_t x2, int16_t y2,
+                    uint8_t alu)
+{
+       struct sna_composite_op tmp;
+
+#if NO_FILL_ONE
+       return gen3_render_fill_one_try_blt(sna, dst, bo, color,
+                                           x1, y1, x2, y2, alu);
+#endif
+
+       /* Prefer to use the BLT if already engaged */
+       if (prefer_fill_blt(sna) &&
+           gen3_render_fill_one_try_blt(sna, dst, bo, color,
+                                        x1, y1, x2, y2, alu))
+               return true;
+
+       /* Must use the BLT if we can't RENDER... */
+       if (!(alu == GXcopy || alu == GXclear) ||
+           too_large(dst->drawable.width, dst->drawable.height) ||
+           bo->pitch > MAX_3D_PITCH)
+               return gen3_render_fill_one_try_blt(sna, dst, bo, color,
+                                                   x1, y1, x2, y2, alu);
+
+       if (alu == GXclear)
+               color = 0;
+
+       tmp.op = color == 0 ? PictOpClear : PictOpSrc;
+       tmp.dst.pixmap = dst;
+       tmp.dst.width = dst->drawable.width;
+       tmp.dst.height = dst->drawable.height;
+       tmp.dst.format = sna_format_for_depth(dst->drawable.depth);
+       tmp.dst.bo = bo;
+       tmp.floats_per_vertex = 2;
+       tmp.floats_per_rect = 6;
+       tmp.need_magic_ca_pass = 0;
+       tmp.has_component_alpha = 0;
+       tmp.rb_reversed = 0;
+
+       gen3_init_solid(&tmp.src,
+                       sna_rgba_for_color(color, dst->drawable.depth));
+       tmp.mask.bo = NULL;
+       tmp.mask.u.gen3.type = SHADER_NONE;
+       tmp.u.gen3.num_constants = 0;
+
+       if (!kgem_check_bo(&sna->kgem, bo, NULL)) {
+               kgem_submit(&sna->kgem);
+               if (gen3_render_fill_one_try_blt(sna, dst, bo, color,
+                                                x1, y1, x2, y2, alu))
+                       return true;
+       }
+
+       gen3_emit_composite_state(sna, &tmp);
+       gen3_align_vertex(sna, &tmp);
+       gen3_get_rectangles(sna, &tmp, 1);
+       DBG(("  (%d, %d), (%d, %d): %x\n", x1, y1, x2, y2, color));
+       OUT_VERTEX(x2);
+       OUT_VERTEX(y2);
+       OUT_VERTEX(x1);
+       OUT_VERTEX(y2);
+       OUT_VERTEX(x1);
+       OUT_VERTEX(y1);
+       gen3_vertex_flush(sna);
+
+       return true;
+}
+
+static void gen3_render_flush(struct sna *sna)
+{
+       gen3_vertex_close(sna);
+}
+
+static void
+gen3_render_fini(struct sna *sna)
+{
+}
+
+bool gen3_render_init(struct sna *sna)
+{
+       struct sna_render *render = &sna->render;
+
+#if !NO_COMPOSITE
+       render->composite = gen3_render_composite;
+#endif
+#if !NO_COMPOSITE_SPANS
+       render->check_composite_spans = gen3_check_composite_spans;
+       render->composite_spans = gen3_render_composite_spans;
+#endif
+
+       render->video = gen3_render_video;
+
+       render->copy_boxes = gen3_render_copy_boxes;
+       render->copy = gen3_render_copy;
+
+       render->fill_boxes = gen3_render_fill_boxes;
+       render->fill = gen3_render_fill;
+       render->fill_one = gen3_render_fill_one;
+
+       render->reset = gen3_render_reset;
+       render->flush = gen3_render_flush;
+       render->fini = gen3_render_fini;
+
+       render->max_3d_size = MAX_3D_SIZE;
+       render->max_3d_pitch = MAX_3D_PITCH;
+
+       sna->kgem.retire = gen3_render_retire;
+       sna->kgem.expire = gen3_render_expire;
+       return true;
+}
diff --git a/src/sna/gen3_render.h b/src/sna/gen3_render.h
new file mode 100644 (file)
index 0000000..3272d5c
--- /dev/null
@@ -0,0 +1,1479 @@
+/**************************************************************************
+ *
+ * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * 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, sub license, 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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 _I915_REG_H_
+#define _I915_REG_H_
+
+#define CMD_3D (3 << 29)
+
+#define I915_SET_FIELD( var, mask, value ) (var &= ~(mask), var |= value)
+
+#define PRIM3D                 (CMD_3D | (0x1f<<24))
+#define PRIM3D_INDIRECT_SEQUENTIAL      ((1<<23) | (0<<17))
+#define PRIM3D_TRILIST         (PRIM3D | (0x0<<18))
+#define PRIM3D_TRISTRIP                (PRIM3D | (0x1<<18))
+#define PRIM3D_TRISTRIP_RVRSE  (PRIM3D | (0x2<<18))
+#define PRIM3D_TRIFAN          (PRIM3D | (0x3<<18))
+#define PRIM3D_POLY            (PRIM3D | (0x4<<18))
+#define PRIM3D_LINELIST                (PRIM3D | (0x5<<18))
+#define PRIM3D_LINESTRIP       (PRIM3D | (0x6<<18))
+#define PRIM3D_RECTLIST                (PRIM3D | (0x7<<18))
+#define PRIM3D_POINTLIST       (PRIM3D | (0x8<<18))
+#define PRIM3D_DIB             (PRIM3D | (0x9<<18))
+#define PRIM3D_CLEAR_RECT      (PRIM3D | (0xa<<18))
+#define PRIM3D_ZONE_INIT       (PRIM3D | (0xd<<18))
+#define PRIM3D_MASK            (0x1f<<18)
+
+
+/* p137 */
+#define _3DSTATE_AA_CMD                        (CMD_3D | (0x06<<24))
+#define AA_LINE_ECAAR_WIDTH_ENABLE     (1<<16)
+#define AA_LINE_ECAAR_WIDTH_0_5                0
+#define AA_LINE_ECAAR_WIDTH_1_0                (1<<14)
+#define AA_LINE_ECAAR_WIDTH_2_0                (2<<14)
+#define AA_LINE_ECAAR_WIDTH_4_0                (3<<14)
+#define AA_LINE_REGION_WIDTH_ENABLE    (1<<8)
+#define AA_LINE_REGION_WIDTH_0_5       0
+#define AA_LINE_REGION_WIDTH_1_0       (1<<6)
+#define AA_LINE_REGION_WIDTH_2_0       (2<<6)
+#define AA_LINE_REGION_WIDTH_4_0       (3<<6)
+
+/* 3DSTATE_BACKFACE_STENCIL_OPS, p138*/
+#define _3DSTATE_BACKFACE_STENCIL_OPS    (CMD_3D | (0x8<<24))
+#define BFO_ENABLE_STENCIL_REF          (1<<23)
+#define BFO_STENCIL_REF_SHIFT           15
+#define BFO_STENCIL_REF_MASK            (0xff<<15)
+#define BFO_ENABLE_STENCIL_FUNCS        (1<<14)
+#define BFO_STENCIL_TEST_SHIFT          11
+#define BFO_STENCIL_TEST_MASK           (0x7<<11)
+#define BFO_STENCIL_FAIL_SHIFT          8
+#define BFO_STENCIL_FAIL_MASK           (0x7<<8)
+#define BFO_STENCIL_PASS_Z_FAIL_SHIFT   5
+#define BFO_STENCIL_PASS_Z_FAIL_MASK    (0x7<<5)
+#define BFO_STENCIL_PASS_Z_PASS_SHIFT   2
+#define BFO_STENCIL_PASS_Z_PASS_MASK    (0x7<<2)
+#define BFO_ENABLE_STENCIL_TWO_SIDE     (1<<1)
+#define BFO_STENCIL_TWO_SIDE            (1<<0)
+
+/* 3DSTATE_BACKFACE_STENCIL_MASKS, p140 */
+#define _3DSTATE_BACKFACE_STENCIL_MASKS    (CMD_3D | (0x9<<24))
+#define BFM_ENABLE_STENCIL_TEST_MASK      (1<<17)
+#define BFM_ENABLE_STENCIL_WRITE_MASK     (1<<16)
+#define BFM_STENCIL_TEST_MASK_SHIFT       8
+#define BFM_STENCIL_TEST_MASK_MASK        (0xff<<8)
+#define BFM_STENCIL_WRITE_MASK_SHIFT      0
+#define BFM_STENCIL_WRITE_MASK_MASK       (0xff<<0)
+
+/* 3DSTATE_BIN_CONTROL p141 */
+
+/* p143 */
+#define _3DSTATE_BUF_INFO_CMD  (CMD_3D | (0x1d<<24) | (0x8e<<16) | 1)
+/* Dword 1 */
+#define BUF_3D_ID_COLOR_BACK   (0x3<<24)
+#define BUF_3D_ID_DEPTH                (0x7<<24)
+#define BUF_3D_USE_FENCE       (1<<23)
+#define BUF_3D_TILED_SURFACE   (1<<22)
+#define BUF_3D_TILE_WALK_X     0
+#define BUF_3D_TILE_WALK_Y     (1<<21)
+/* Dword 2 */
+#define BUF_3D_ADDR(x)         ((x) & ~0x3)
+
+/* 3DSTATE_CHROMA_KEY */
+
+/* 3DSTATE_CLEAR_PARAMETERS, p150 */
+#define _3DSTATE_CLEAR_PARAMETERS   (CMD_3D | (0x1d<<24) | (0x9c<<16) | 5)
+/* Dword 1 */
+#define CLEARPARAM_CLEAR_RECT      (1 << 16)
+#define CLEARPARAM_ZONE_INIT       (0 << 16)
+#define CLEARPARAM_WRITE_COLOR     (1 << 2)
+#define CLEARPARAM_WRITE_DEPTH     (1 << 1)
+#define CLEARPARAM_WRITE_STENCIL    (1 << 0)
+
+/* 3DSTATE_CONSTANT_BLEND_COLOR, p153 */
+#define _3DSTATE_CONST_BLEND_COLOR_CMD (CMD_3D | (0x1d<<24) | (0x88<<16))
+
+/* 3DSTATE_COORD_SET_BINDINGS, p154 */
+#define _3DSTATE_COORD_SET_BINDINGS      (CMD_3D | (0x16<<24))
+#define CSB_TCB(iunit, eunit)           ((eunit)<<(iunit*3))
+
+/* p156 */
+#define _3DSTATE_DFLT_DIFFUSE_CMD      (CMD_3D | (0x1d<<24) | (0x99<<16))
+
+/* p157 */
+#define _3DSTATE_DFLT_SPEC_CMD         (CMD_3D | (0x1d<<24) | (0x9a<<16))
+
+/* p158 */
+#define _3DSTATE_DFLT_Z_CMD            (CMD_3D | (0x1d<<24) | (0x98<<16))
+
+/* 3DSTATE_DEPTH_OFFSET_SCALE, p159 */
+#define _3DSTATE_DEPTH_OFFSET_SCALE       (CMD_3D | (0x1d<<24) | (0x97<<16))
+/* scale in dword 1 */
+
+/* The depth subrectangle is not supported, but must be disabled. */
+/* 3DSTATE_DEPTH_SUBRECT_DISABLE, p160 */
+#define _3DSTATE_DEPTH_SUBRECT_DISABLE (CMD_3D | (0x1c<<24) | (0x11<<19) | (1 << 1) | (0 << 0))
+
+/* p161 */
+#define _3DSTATE_DST_BUF_VARS_CMD      (CMD_3D | (0x1d<<24) | (0x85<<16))
+/* Dword 1 */
+#define TEX_DEFAULT_COLOR_OGL           (0<<30)
+#define TEX_DEFAULT_COLOR_D3D           (1<<30)
+#define ZR_EARLY_DEPTH                  (1<<29)
+#define LOD_PRECLAMP_OGL                (1<<28)
+#define LOD_PRECLAMP_D3D                (0<<28)
+#define DITHER_FULL_ALWAYS              (0<<26)
+#define DITHER_FULL_ON_FB_BLEND         (1<<26)
+#define DITHER_CLAMPED_ALWAYS           (2<<26)
+#define LINEAR_GAMMA_BLEND_32BPP        (1<<25)
+#define DEBUG_DISABLE_ENH_DITHER        (1<<24)
+#define DSTORG_HORT_BIAS(x)            ((x)<<20)
+#define DSTORG_VERT_BIAS(x)            ((x)<<16)
+#define COLOR_4_2_2_CHNL_WRT_ALL       0
+#define COLOR_4_2_2_CHNL_WRT_Y         (1<<12)
+#define COLOR_4_2_2_CHNL_WRT_CR                (2<<12)
+#define COLOR_4_2_2_CHNL_WRT_CB                (3<<12)
+#define COLOR_4_2_2_CHNL_WRT_CRCB      (4<<12)
+#define COLR_BUF_8BIT                  0
+#define COLR_BUF_RGB555                        (1<<8)
+#define COLR_BUF_RGB565                        (2<<8)
+#define COLR_BUF_ARGB8888              (3<<8)
+#define COLR_BUF_ARGB4444              (8<<8)
+#define COLR_BUF_ARGB1555              (9<<8)
+#define COLR_BUF_ARGB2AAA              (0xa<<8)
+#define DEPTH_IS_Z                     0
+#define DEPTH_IS_W                     (1<<6)
+#define DEPTH_FRMT_16_FIXED            0
+#define DEPTH_FRMT_16_FLOAT            (1<<2)
+#define DEPTH_FRMT_24_FIXED_8_OTHER    (2<<2)
+#define DEPTH_FRMT_24_FLOAT_8_OTHER    (3<<2)
+#define VERT_LINE_STRIDE_1             (1<<1)
+#define VERT_LINE_STRIDE_0             0
+#define VERT_LINE_STRIDE_OFS_1         1
+#define VERT_LINE_STRIDE_OFS_0         0
+
+/* p166 */
+#define _3DSTATE_DRAW_RECT_CMD         (CMD_3D|(0x1d<<24)|(0x80<<16)|3)
+/* Dword 1 */
+#define DRAW_RECT_DIS_DEPTH_OFS                (1<<30)
+#define DRAW_DITHER_OFS_X(x)           ((x)<<26)
+#define DRAW_DITHER_OFS_Y(x)           ((x)<<24)
+/* Dword 2 */
+#define DRAW_YMIN(x)                   ((uint16_t)(x)<<16)
+#define DRAW_XMIN(x)                   ((uint16_t)(x))
+/* Dword 3 */
+#define DRAW_YMAX(x)                   ((uint16_t)(x)<<16)
+#define DRAW_XMAX(x)                   ((uint16_t)(x))
+/* Dword 4 */
+#define DRAW_YORG(x)                   ((uint16_t)(x)<<16)
+#define DRAW_XORG(x)                   ((uint16_t)(x))
+
+/* 3DSTATE_FILTER_COEFFICIENTS_4X4, p170 */
+
+/* 3DSTATE_FILTER_COEFFICIENTS_6X5, p172 */
+
+/* _3DSTATE_FOG_COLOR, p173 */
+#define _3DSTATE_FOG_COLOR_CMD         (CMD_3D|(0x15<<24))
+#define FOG_COLOR_RED(x)               ((x)<<16)
+#define FOG_COLOR_GREEN(x)             ((x)<<8)
+#define FOG_COLOR_BLUE(x)              (x)
+
+/* _3DSTATE_FOG_MODE, p174 */
+#define _3DSTATE_FOG_MODE_CMD          (CMD_3D|(0x1d<<24)|(0x89<<16)|2)
+/* Dword 1 */
+#define FMC1_FOGFUNC_MODIFY_ENABLE     (1<<31)
+#define FMC1_FOGFUNC_VERTEX            (0<<28)
+#define FMC1_FOGFUNC_PIXEL_EXP         (1<<28)
+#define FMC1_FOGFUNC_PIXEL_EXP2                (2<<28)
+#define FMC1_FOGFUNC_PIXEL_LINEAR      (3<<28)
+#define FMC1_FOGFUNC_MASK              (3<<28)
+#define FMC1_FOGINDEX_MODIFY_ENABLE     (1<<27)
+#define FMC1_FOGINDEX_Z                        (0<<25)
+#define FMC1_FOGINDEX_W                        (1<<25)
+#define FMC1_C1_C2_MODIFY_ENABLE       (1<<24)
+#define FMC1_DENSITY_MODIFY_ENABLE     (1<<23)
+#define FMC1_C1_ONE                    (1<<13)
+#define FMC1_C1_MASK                   (0xffff<<4)
+/* Dword 2 */
+#define FMC2_C2_ONE                    (1<<16)
+/* Dword 3 */
+#define FMC3_D_ONE                     (1<<16)
+
+/* _3DSTATE_INDEPENDENT_ALPHA_BLEND, p177 */
+#define _3DSTATE_INDEPENDENT_ALPHA_BLEND_CMD   (CMD_3D|(0x0b<<24))
+#define IAB_MODIFY_ENABLE              (1<<23)
+#define IAB_ENABLE                     (1<<22)
+#define IAB_MODIFY_FUNC                        (1<<21)
+#define IAB_FUNC_SHIFT                 16
+#define IAB_MODIFY_SRC_FACTOR          (1<<11)
+#define IAB_SRC_FACTOR_SHIFT           6
+#define IAB_SRC_FACTOR_MASK            (BLENDFACT_MASK<<6)
+#define IAB_MODIFY_DST_FACTOR          (1<<5)
+#define IAB_DST_FACTOR_SHIFT           0
+#define IAB_DST_FACTOR_MASK            (BLENDFACT_MASK<<0)
+
+#define BLENDFACT_ZERO                 0x01
+#define BLENDFACT_ONE                  0x02
+#define BLENDFACT_SRC_COLR             0x03
+#define BLENDFACT_INV_SRC_COLR         0x04
+#define BLENDFACT_SRC_ALPHA            0x05
+#define BLENDFACT_INV_SRC_ALPHA                0x06
+#define BLENDFACT_DST_ALPHA            0x07
+#define BLENDFACT_INV_DST_ALPHA                0x08
+#define BLENDFACT_DST_COLR             0x09
+#define BLENDFACT_INV_DST_COLR         0x0a
+#define BLENDFACT_SRC_ALPHA_SATURATE   0x0b
+#define BLENDFACT_CONST_COLOR          0x0c
+#define BLENDFACT_INV_CONST_COLOR      0x0d
+#define BLENDFACT_CONST_ALPHA          0x0e
+#define BLENDFACT_INV_CONST_ALPHA      0x0f
+#define BLENDFACT_MASK                 0x0f
+
+#define BLENDFUNC_ADD                  0x0
+#define BLENDFUNC_SUBTRACT             0x1
+#define BLENDFUNC_REVERSE_SUBTRACT     0x2
+#define BLENDFUNC_MIN                  0x3
+#define BLENDFUNC_MAX                  0x4
+#define BLENDFUNC_MASK                 0x7
+
+/* 3DSTATE_LOAD_INDIRECT, p180 */
+
+#define _3DSTATE_LOAD_INDIRECT         (CMD_3D|(0x1d<<24)|(0x7<<16))
+#define LI0_STATE_STATIC_INDIRECT       (0x01<<8)
+#define LI0_STATE_DYNAMIC_INDIRECT      (0x02<<8)
+#define LI0_STATE_SAMPLER               (0x04<<8)
+#define LI0_STATE_MAP                   (0x08<<8)
+#define LI0_STATE_PROGRAM               (0x10<<8)
+#define LI0_STATE_CONSTANTS             (0x20<<8)
+
+#define SIS0_BUFFER_ADDRESS(x)          ((x)&~0x3)
+#define SIS0_FORCE_LOAD                 (1<<1)
+#define SIS0_BUFFER_VALID               (1<<0)
+#define SIS1_BUFFER_LENGTH(x)           ((x)&0xff)
+
+#define DIS0_BUFFER_ADDRESS(x)          ((x)&~0x3)
+#define DIS0_BUFFER_RESET               (1<<1)
+#define DIS0_BUFFER_VALID               (1<<0)
+
+#define SSB0_BUFFER_ADDRESS(x)          ((x)&~0x3)
+#define SSB0_FORCE_LOAD                 (1<<1)
+#define SSB0_BUFFER_VALID               (1<<0)
+#define SSB1_BUFFER_LENGTH(x)           ((x)&0xff)
+
+#define MSB0_BUFFER_ADDRESS(x)          ((x)&~0x3)
+#define MSB0_FORCE_LOAD                 (1<<1)
+#define MSB0_BUFFER_VALID               (1<<0)
+#define MSB1_BUFFER_LENGTH(x)           ((x)&0xff)
+
+#define PSP0_BUFFER_ADDRESS(x)          ((x)&~0x3)
+#define PSP0_FORCE_LOAD                 (1<<1)
+#define PSP0_BUFFER_VALID               (1<<0)
+#define PSP1_BUFFER_LENGTH(x)           ((x)&0xff)
+
+#define PSC0_BUFFER_ADDRESS(x)          ((x)&~0x3)
+#define PSC0_FORCE_LOAD                 (1<<1)
+#define PSC0_BUFFER_VALID               (1<<0)
+#define PSC1_BUFFER_LENGTH(x)           ((x)&0xff)
+
+/* _3DSTATE_RASTERIZATION_RULES */
+#define _3DSTATE_RASTER_RULES_CMD      (CMD_3D|(0x07<<24))
+#define ENABLE_POINT_RASTER_RULE       (1<<15)
+#define OGL_POINT_RASTER_RULE          (1<<13)
+#define ENABLE_TEXKILL_3D_4D            (1<<10)
+#define TEXKILL_3D                      (0<<9)
+#define TEXKILL_4D                      (1<<9)
+#define ENABLE_LINE_STRIP_PROVOKE_VRTX (1<<8)
+#define ENABLE_TRI_FAN_PROVOKE_VRTX    (1<<5)
+#define LINE_STRIP_PROVOKE_VRTX(x)     ((x)<<6)
+#define TRI_FAN_PROVOKE_VRTX(x)        ((x)<<3)
+
+/* _3DSTATE_SCISSOR_ENABLE, p256 */
+#define _3DSTATE_SCISSOR_ENABLE_CMD    (CMD_3D|(0x1c<<24)|(0x10<<19))
+#define ENABLE_SCISSOR_RECT            ((1<<1) | 1)
+#define DISABLE_SCISSOR_RECT           (1<<1)
+
+/* _3DSTATE_SCISSOR_RECTANGLE_0, p257 */
+#define _3DSTATE_SCISSOR_RECT_0_CMD    (CMD_3D|(0x1d<<24)|(0x81<<16)|1)
+/* Dword 1 */
+#define SCISSOR_RECT_0_YMIN(x)         ((x)<<16)
+#define SCISSOR_RECT_0_XMIN(x)         (x)
+/* Dword 2 */
+#define SCISSOR_RECT_0_YMAX(x)         ((x)<<16)
+#define SCISSOR_RECT_0_XMAX(x)         (x)
+
+/* p189 */
+#define _3DSTATE_LOAD_STATE_IMMEDIATE_1   ((0x3<<29)|(0x1d<<24)|(0x04<<16))
+#define I1_LOAD_S(n)                      (1<<(4+n))
+
+#define S0_VB_OFFSET_MASK              0xffffffc
+#define S0_AUTO_CACHE_INV_DISABLE      (1<<0)
+
+#define S1_VERTEX_WIDTH_SHIFT          24
+#define S1_VERTEX_WIDTH_MASK           (0x3f<<24)
+#define S1_VERTEX_PITCH_SHIFT          16
+#define S1_VERTEX_PITCH_MASK           (0x3f<<16)
+
+#define TEXCOORDFMT_2D                 0x0
+#define TEXCOORDFMT_3D                 0x1
+#define TEXCOORDFMT_4D                 0x2
+#define TEXCOORDFMT_1D                 0x3
+#define TEXCOORDFMT_2D_16              0x4
+#define TEXCOORDFMT_4D_16              0x5
+#define TEXCOORDFMT_NOT_PRESENT        0xf
+#define S2_TEXCOORD_FMT0_MASK            0xf
+#define S2_TEXCOORD_FMT1_SHIFT           4
+#define S2_TEXCOORD_FMT(unit, type)    ((type)<<(unit*4))
+#define S2_TEXCOORD_NONE               (~0)
+
+#define TEXCOORD_WRAP_SHORTEST_TCX     8
+#define TEXCOORD_WRAP_SHORTEST_TCY     4
+#define TEXCOORD_WRAP_SHORTEST_TCZ     2
+#define TEXCOORD_PERSPECTIVE_DISABLE   1
+
+#define S3_WRAP_SHORTEST_TCX(unit)     (TEXCOORD_WRAP_SHORTEST_TCX << ((unit) * 4))
+#define S3_WRAP_SHORTEST_TCY(unit)     (TEXCOORD_WRAP_SHORTEST_TCY << ((unit) * 4))
+#define S3_WRAP_SHORTEST_TCZ(unit)     (TEXCOORD_WRAP_SHORTEST_TCZ << ((unit) * 4))
+#define S3_PERSPECTIVE_DISABLE(unit)   (TEXCOORD_PERSPECTIVE_DISABLE << ((unit) * 4))
+
+/* S3 not interesting */
+
+#define S4_POINT_WIDTH_SHIFT           23
+#define S4_POINT_WIDTH_MASK            (0x1ff<<23)
+#define S4_LINE_WIDTH_SHIFT            19
+#define S4_LINE_WIDTH_ONE              (0x2<<19)
+#define S4_LINE_WIDTH_MASK             (0xf<<19)
+#define S4_FLATSHADE_ALPHA             (1<<18)
+#define S4_FLATSHADE_FOG               (1<<17)
+#define S4_FLATSHADE_SPECULAR          (1<<16)
+#define S4_FLATSHADE_COLOR             (1<<15)
+#define S4_CULLMODE_BOTH              (0<<13)
+#define S4_CULLMODE_NONE              (1<<13)
+#define S4_CULLMODE_CW                (2<<13)
+#define S4_CULLMODE_CCW                       (3<<13)
+#define S4_CULLMODE_MASK              (3<<13)
+#define S4_VFMT_POINT_WIDTH            (1<<12)
+#define S4_VFMT_SPEC_FOG               (1<<11)
+#define S4_VFMT_COLOR                  (1<<10)
+#define S4_VFMT_DEPTH_OFFSET           (1<<9)
+#define S4_VFMT_XYZ                   (1<<6)
+#define S4_VFMT_XYZW                  (2<<6)
+#define S4_VFMT_XY                            (3<<6)
+#define S4_VFMT_XYW                   (4<<6)
+#define S4_VFMT_XYZW_MASK              (7<<6)
+#define S4_FORCE_DEFAULT_DIFFUSE       (1<<5)
+#define S4_FORCE_DEFAULT_SPECULAR      (1<<4)
+#define S4_LOCAL_DEPTH_OFFSET_ENABLE   (1<<3)
+#define S4_VFMT_FOG_PARAM              (1<<2)
+#define S4_SPRITE_POINT_ENABLE         (1<<1)
+#define S4_LINE_ANTIALIAS_ENABLE       (1<<0)
+
+#define S4_VFMT_MASK (S4_VFMT_POINT_WIDTH   |  \
+                     S4_VFMT_SPEC_FOG      |   \
+                     S4_VFMT_COLOR         |   \
+                     S4_VFMT_DEPTH_OFFSET  |   \
+                     S4_VFMT_XYZW_MASK     |   \
+                     S4_VFMT_FOG_PARAM)
+
+#define S5_WRITEDISABLE_ALPHA          (1<<31)
+#define S5_WRITEDISABLE_RED            (1<<30)
+#define S5_WRITEDISABLE_GREEN          (1<<29)
+#define S5_WRITEDISABLE_BLUE           (1<<28)
+#define S5_WRITEDISABLE_MASK           (0xf<<28)
+#define S5_FORCE_DEFAULT_POINT_SIZE    (1<<27)
+#define S5_LAST_PIXEL_ENABLE           (1<<26)
+#define S5_GLOBAL_DEPTH_OFFSET_ENABLE  (1<<25)
+#define S5_FOG_ENABLE                  (1<<24)
+#define S5_STENCIL_REF_SHIFT           16
+#define S5_STENCIL_REF_MASK            (0xff<<16)
+#define S5_STENCIL_TEST_FUNC_SHIFT     13
+#define S5_STENCIL_TEST_FUNC_MASK      (0x7<<13)
+#define S5_STENCIL_FAIL_SHIFT          10
+#define S5_STENCIL_FAIL_MASK           (0x7<<10)
+#define S5_STENCIL_PASS_Z_FAIL_SHIFT   7
+#define S5_STENCIL_PASS_Z_FAIL_MASK    (0x7<<7)
+#define S5_STENCIL_PASS_Z_PASS_SHIFT   4
+#define S5_STENCIL_PASS_Z_PASS_MASK    (0x7<<4)
+#define S5_STENCIL_WRITE_ENABLE        (1<<3)
+#define S5_STENCIL_TEST_ENABLE         (1<<2)
+#define S5_COLOR_DITHER_ENABLE         (1<<1)
+#define S5_LOGICOP_ENABLE              (1<<0)
+
+#define S6_ALPHA_TEST_ENABLE           (1<<31)
+#define S6_ALPHA_TEST_FUNC_SHIFT       28
+#define S6_ALPHA_TEST_FUNC_MASK        (0x7<<28)
+#define S6_ALPHA_REF_SHIFT             20
+#define S6_ALPHA_REF_MASK              (0xff<<20)
+#define S6_DEPTH_TEST_ENABLE           (1<<19)
+#define S6_DEPTH_TEST_FUNC_SHIFT       16
+#define S6_DEPTH_TEST_FUNC_MASK        (0x7<<16)
+#define S6_CBUF_BLEND_ENABLE           (1<<15)
+#define S6_CBUF_BLEND_FUNC_SHIFT       12
+#define S6_CBUF_BLEND_FUNC_MASK        (0x7<<12)
+#define S6_CBUF_SRC_BLEND_FACT_SHIFT   8
+#define S6_CBUF_SRC_BLEND_FACT_MASK    (0xf<<8)
+#define S6_CBUF_DST_BLEND_FACT_SHIFT   4
+#define S6_CBUF_DST_BLEND_FACT_MASK    (0xf<<4)
+#define S6_DEPTH_WRITE_ENABLE          (1<<3)
+#define S6_COLOR_WRITE_ENABLE          (1<<2)
+#define S6_TRISTRIP_PV_SHIFT           0
+#define S6_TRISTRIP_PV_MASK            (0x3<<0)
+
+#define S7_DEPTH_OFFSET_CONST_MASK     ~0
+
+/* 3DSTATE_MAP_DEINTERLACER_PARAMETERS */
+/* 3DSTATE_MAP_PALETTE_LOAD_32, p206 */
+
+/* _3DSTATE_MODES_4, p218 */
+#define _3DSTATE_MODES_4_CMD           (CMD_3D|(0x0d<<24))
+#define ENABLE_LOGIC_OP_FUNC           (1<<23)
+#define LOGIC_OP_FUNC(x)               ((x)<<18)
+#define LOGICOP_MASK                   (0xf<<18)
+#define LOGICOP_COPY                   0xc
+#define MODE4_ENABLE_STENCIL_TEST_MASK ((1<<17)|(0xff00))
+#define ENABLE_STENCIL_TEST_MASK       (1<<17)
+#define STENCIL_TEST_MASK(x)           ((x)<<8)
+#define MODE4_ENABLE_STENCIL_WRITE_MASK        ((1<<16)|(0x00ff))
+#define ENABLE_STENCIL_WRITE_MASK      (1<<16)
+#define STENCIL_WRITE_MASK(x)          ((x)&0xff)
+
+/* _3DSTATE_MODES_5, p220 */
+#define _3DSTATE_MODES_5_CMD           (CMD_3D|(0x0c<<24))
+#define PIPELINE_FLUSH_RENDER_CACHE    (1<<18)
+#define PIPELINE_FLUSH_TEXTURE_CACHE   (1<<16)
+
+/* p221 */
+#define _3DSTATE_PIXEL_SHADER_CONSTANTS  (CMD_3D|(0x1d<<24)|(0x6<<16))
+#define PS1_REG(n)                      (1<<(n))
+#define PS2_CONST_X(n)                  (n)
+#define PS3_CONST_Y(n)                  (n)
+#define PS4_CONST_Z(n)                  (n)
+#define PS5_CONST_W(n)                  (n)
+
+/* p222 */
+
+#define I915_MAX_TEX_INDIRECT 4
+#define I915_MAX_TEX_INSN     32
+#define I915_MAX_ALU_INSN     64
+#define I915_MAX_DECL_INSN    27
+#define I915_MAX_TEMPORARY    16
+
+/* Each instruction is 3 dwords long, though most don't require all
+ * this space.  Maximum of 123 instructions.  Smaller maxes per insn
+ * type.
+ */
+#define _3DSTATE_PIXEL_SHADER_PROGRAM    (CMD_3D|(0x1d<<24)|(0x5<<16))
+
+#define REG_TYPE_R                 0   /* temporary regs, no need to
+                                        * dcl, must be written before
+                                        * read -- Preserved between
+                                        * phases.
+                                        */
+#define REG_TYPE_T                 1   /* Interpolated values, must be
+                                        * dcl'ed before use.
+                                        *
+                                        * 0..7: texture coord,
+                                        * 8: diffuse spec,
+                                        * 9: specular color,
+                                        * 10: fog parameter in w.
+                                        */
+#define REG_TYPE_CONST             2   /* Restriction: only one const
+                                        * can be referenced per
+                                        * instruction, though it may be
+                                        * selected for multiple inputs.
+                                        * Constants not initialized
+                                        * default to zero.
+                                        */
+#define REG_TYPE_S                 3   /* sampler */
+#define REG_TYPE_OC                4   /* output color (rgba) */
+#define REG_TYPE_OD                5   /* output depth (w), xyz are
+                                        * temporaries.  If not written,
+                                        * interpolated depth is used?
+                                        */
+#define REG_TYPE_U                 6   /* unpreserved temporaries */
+#define REG_TYPE_MASK              0x7
+#define REG_NR_MASK                0xf
+
+/* REG_TYPE_T:
+ */
+#define T_TEX0     0
+#define T_TEX1     1
+#define T_TEX2     2
+#define T_TEX3     3
+#define T_TEX4     4
+#define T_TEX5     5
+#define T_TEX6     6
+#define T_TEX7     7
+#define T_DIFFUSE  8
+#define T_SPECULAR 9
+#define T_FOG_W    10          /* interpolated fog is in W coord */
+
+/* Arithmetic instructions */
+
+/* .replicate_swizzle == selection and replication of a particular
+ * scalar channel, ie., .xxxx, .yyyy, .zzzz or .wwww
+ */
+#define A0_NOP    (0x0<<24)    /* no operation */
+#define A0_ADD    (0x1<<24)    /* dst = src0 + src1 */
+#define A0_MOV    (0x2<<24)    /* dst = src0 */
+#define A0_MUL    (0x3<<24)    /* dst = src0 * src1 */
+#define A0_MAD    (0x4<<24)    /* dst = src0 * src1 + src2 */
+#define A0_DP2ADD (0x5<<24)    /* dst.xyzw = src0.xy dot src1.xy + src2.replicate_swizzle */
+#define A0_DP3    (0x6<<24)    /* dst.xyzw = src0.xyz dot src1.xyz */
+#define A0_DP4    (0x7<<24)    /* dst.xyzw = src0.xyzw dot src1.xyzw */
+#define A0_FRC    (0x8<<24)    /* dst = src0 - floor(src0) */
+#define A0_RCP    (0x9<<24)    /* dst.xyzw = 1/(src0.replicate_swizzle) */
+#define A0_RSQ    (0xa<<24)    /* dst.xyzw = 1/(sqrt(abs(src0.replicate_swizzle))) */
+#define A0_EXP    (0xb<<24)    /* dst.xyzw = exp2(src0.replicate_swizzle) */
+#define A0_LOG    (0xc<<24)    /* dst.xyzw = log2(abs(src0.replicate_swizzle)) */
+#define A0_CMP    (0xd<<24)    /* dst = (src0 >= 0.0) ? src1 : src2 */
+#define A0_MIN    (0xe<<24)    /* dst = (src0 < src1) ? src0 : src1 */
+#define A0_MAX    (0xf<<24)    /* dst = (src0 >= src1) ? src0 : src1 */
+#define A0_FLR    (0x10<<24)   /* dst = floor(src0) */
+#define A0_MOD    (0x11<<24)   /* dst = src0 fmod 1.0 */
+#define A0_TRC    (0x12<<24)   /* dst = int(src0) */
+#define A0_SGE    (0x13<<24)   /* dst = src0 >= src1 ? 1.0 : 0.0 */
+#define A0_SLT    (0x14<<24)   /* dst = src0 < src1 ? 1.0 : 0.0 */
+#define A0_DEST_SATURATE                 (1<<22)
+#define A0_DEST_TYPE_SHIFT                19
+/* Allow: R, OC, OD, U */
+#define A0_DEST_NR_SHIFT                 14
+/* Allow R: 0..15, OC,OD: 0..0, U: 0..2 */
+#define A0_DEST_CHANNEL_X                (1<<10)
+#define A0_DEST_CHANNEL_Y                (2<<10)
+#define A0_DEST_CHANNEL_Z                (4<<10)
+#define A0_DEST_CHANNEL_W                (8<<10)
+#define A0_DEST_CHANNEL_ALL              (0xf<<10)
+#define A0_DEST_CHANNEL_SHIFT            10
+#define A0_SRC0_TYPE_SHIFT               7
+#define A0_SRC0_NR_SHIFT                 2
+
+#define A0_DEST_CHANNEL_XY              (A0_DEST_CHANNEL_X|A0_DEST_CHANNEL_Y)
+#define A0_DEST_CHANNEL_XYZ             (A0_DEST_CHANNEL_XY|A0_DEST_CHANNEL_Z)
+
+#define SRC_X        0
+#define SRC_Y        1
+#define SRC_Z        2
+#define SRC_W        3
+#define SRC_ZERO     4
+#define SRC_ONE      5
+
+#define A1_SRC0_CHANNEL_X_NEGATE         (1<<31)
+#define A1_SRC0_CHANNEL_X_SHIFT          28
+#define A1_SRC0_CHANNEL_Y_NEGATE         (1<<27)
+#define A1_SRC0_CHANNEL_Y_SHIFT          24
+#define A1_SRC0_CHANNEL_Z_NEGATE         (1<<23)
+#define A1_SRC0_CHANNEL_Z_SHIFT          20
+#define A1_SRC0_CHANNEL_W_NEGATE         (1<<19)
+#define A1_SRC0_CHANNEL_W_SHIFT          16
+#define A1_SRC1_TYPE_SHIFT               13
+#define A1_SRC1_NR_SHIFT                 8
+#define A1_SRC1_CHANNEL_X_NEGATE         (1<<7)
+#define A1_SRC1_CHANNEL_X_SHIFT          4
+#define A1_SRC1_CHANNEL_Y_NEGATE         (1<<3)
+#define A1_SRC1_CHANNEL_Y_SHIFT          0
+
+#define A2_SRC1_CHANNEL_Z_NEGATE         (1<<31)
+#define A2_SRC1_CHANNEL_Z_SHIFT          28
+#define A2_SRC1_CHANNEL_W_NEGATE         (1<<27)
+#define A2_SRC1_CHANNEL_W_SHIFT          24
+#define A2_SRC2_TYPE_SHIFT               21
+#define A2_SRC2_NR_SHIFT                 16
+#define A2_SRC2_CHANNEL_X_NEGATE         (1<<15)
+#define A2_SRC2_CHANNEL_X_SHIFT          12
+#define A2_SRC2_CHANNEL_Y_NEGATE         (1<<11)
+#define A2_SRC2_CHANNEL_Y_SHIFT          8
+#define A2_SRC2_CHANNEL_Z_NEGATE         (1<<7)
+#define A2_SRC2_CHANNEL_Z_SHIFT          4
+#define A2_SRC2_CHANNEL_W_NEGATE         (1<<3)
+#define A2_SRC2_CHANNEL_W_SHIFT          0
+
+/* Texture instructions */
+#define T0_TEXLD     (0x15<<24)        /* Sample texture using predeclared
+                                * sampler and address, and output
+                                * filtered texel data to destination
+                                * register */
+#define T0_TEXLDP    (0x16<<24)        /* Same as texld but performs a
+                                * perspective divide of the texture
+                                * coordinate .xyz values by .w before
+                                * sampling. */
+#define T0_TEXLDB    (0x17<<24)        /* Same as texld but biases the
+                                * computed LOD by w.  Only S4.6 two's
+                                * comp is used.  This implies that a
+                                * float to fixed conversion is
+                                * done. */
+#define T0_TEXKILL   (0x18<<24)        /* Does not perform a sampling
+                                * operation.  Simply kills the pixel
+                                * if any channel of the address
+                                * register is < 0.0. */
+#define T0_DEST_TYPE_SHIFT                19
+/* Allow: R, OC, OD, U */
+/* Note: U (unpreserved) regs do not retain their values between
+ * phases (cannot be used for feedback)
+ *
+ * Note: oC and OD registers can only be used as the destination of a
+ * texture instruction once per phase (this is an implementation
+ * restriction).
+ */
+#define T0_DEST_NR_SHIFT                 14
+/* Allow R: 0..15, OC,OD: 0..0, U: 0..2 */
+#define T0_SAMPLER_NR_SHIFT              0     /* This field ignored for TEXKILL */
+#define T0_SAMPLER_NR_MASK               (0xf<<0)
+
+#define T1_ADDRESS_REG_TYPE_SHIFT        24    /* Reg to use as texture coord */
+/* Allow R, T, OC, OD -- R, OC, OD are 'dependent' reads, new program phase */
+#define T1_ADDRESS_REG_NR_SHIFT          17
+#define T2_MBZ                           0
+
+/* Declaration instructions */
+#define D0_DCL       (0x19<<24)        /* Declare a t (interpolated attrib)
+                                * register or an s (sampler)
+                                * register. */
+#define D0_SAMPLE_TYPE_SHIFT              22
+#define D0_SAMPLE_TYPE_2D                 (0x0<<22)
+#define D0_SAMPLE_TYPE_CUBE               (0x1<<22)
+#define D0_SAMPLE_TYPE_VOLUME             (0x2<<22)
+#define D0_SAMPLE_TYPE_MASK               (0x3<<22)
+
+#define D0_TYPE_SHIFT                19
+/* Allow: T, S */
+#define D0_NR_SHIFT                  14
+/* Allow T: 0..10, S: 0..15 */
+#define D0_CHANNEL_X                (1<<10)
+#define D0_CHANNEL_Y                (2<<10)
+#define D0_CHANNEL_Z                (4<<10)
+#define D0_CHANNEL_W                (8<<10)
+#define D0_CHANNEL_ALL              (0xf<<10)
+#define D0_CHANNEL_NONE             (0<<10)
+
+#define D0_CHANNEL_XY               (D0_CHANNEL_X|D0_CHANNEL_Y)
+#define D0_CHANNEL_XYZ              (D0_CHANNEL_XY|D0_CHANNEL_Z)
+
+/* I915 Errata: Do not allow (xz), (xw), (xzw) combinations for diffuse
+ * or specular declarations.
+ *
+ * For T dcls, only allow: (x), (xy), (xyz), (w), (xyzw)
+ *
+ * Must be zero for S (sampler) dcls
+ */
+#define D1_MBZ                          0
+#define D2_MBZ                          0
+
+/* p207.
+ * The DWORD count is 3 times the number of bits set in MS1_MAPMASK_MASK
+ */
+#define _3DSTATE_MAP_STATE               (CMD_3D|(0x1d<<24)|(0x0<<16))
+
+#define MS1_MAPMASK_SHIFT               0
+#define MS1_MAPMASK_MASK                (0x8fff<<0)
+
+#define MS2_UNTRUSTED_SURFACE           (1<<31)
+#define MS2_ADDRESS_MASK                0xfffffffc
+#define MS2_VERTICAL_LINE_STRIDE        (1<<1)
+#define MS2_VERTICAL_OFFSET             (1<<1)
+
+#define MS3_HEIGHT_SHIFT              21
+#define MS3_WIDTH_SHIFT               10
+#define MS3_PALETTE_SELECT            (1<<9)
+#define MS3_MAPSURF_FORMAT_SHIFT      7
+#define MS3_MAPSURF_FORMAT_MASK       (0x7<<7)
+#define    MAPSURF_8BIT                           (1<<7)
+#define    MAPSURF_16BIT                  (2<<7)
+#define    MAPSURF_32BIT                  (3<<7)
+#define    MAPSURF_422                    (5<<7)
+#define    MAPSURF_COMPRESSED             (6<<7)
+#define    MAPSURF_4BIT_INDEXED                   (7<<7)
+#define MS3_MT_FORMAT_MASK         (0x7 << 3)
+#define MS3_MT_FORMAT_SHIFT        3
+#define    MT_4BIT_IDX_ARGB8888                   (7<<3)       /* SURFACE_4BIT_INDEXED */
+#define    MT_8BIT_I8                     (0<<3)       /* SURFACE_8BIT */
+#define    MT_8BIT_L8                     (1<<3)
+#define    MT_8BIT_A8                     (4<<3)
+#define    MT_8BIT_MONO8                  (5<<3)
+#define    MT_16BIT_RGB565                (0<<3)       /* SURFACE_16BIT */
+#define    MT_16BIT_ARGB1555              (1<<3)
+#define    MT_16BIT_ARGB4444              (2<<3)
+#define    MT_16BIT_AY88                  (3<<3)
+#define    MT_16BIT_88DVDU                (5<<3)
+#define    MT_16BIT_BUMP_655LDVDU         (6<<3)
+#define    MT_16BIT_I16                           (7<<3)
+#define    MT_16BIT_L16                           (8<<3)
+#define    MT_16BIT_A16                           (9<<3)
+#define    MT_32BIT_ARGB8888              (0<<3)       /* SURFACE_32BIT */
+#define    MT_32BIT_ABGR8888              (1<<3)
+#define    MT_32BIT_XRGB8888              (2<<3)
+#define    MT_32BIT_XBGR8888              (3<<3)
+#define    MT_32BIT_QWVU8888              (4<<3)
+#define    MT_32BIT_AXVU8888              (5<<3)
+#define    MT_32BIT_LXVU8888              (6<<3)
+#define    MT_32BIT_XLVU8888              (7<<3)
+#define    MT_32BIT_ARGB2101010                   (8<<3)
+#define    MT_32BIT_ABGR2101010                   (9<<3)
+#define    MT_32BIT_AWVU2101010                   (0xA<<3)
+#define    MT_32BIT_GR1616                (0xB<<3)
+#define    MT_32BIT_VU1616                (0xC<<3)
+#define    MT_32BIT_xI824                 (0xD<<3)
+#define    MT_32BIT_xA824                 (0xE<<3)
+#define    MT_32BIT_xL824                 (0xF<<3)
+#define    MT_422_YCRCB_SWAPY             (0<<3)       /* SURFACE_422 */
+#define    MT_422_YCRCB_NORMAL            (1<<3)
+#define    MT_422_YCRCB_SWAPUV            (2<<3)
+#define    MT_422_YCRCB_SWAPUVY                   (3<<3)
+#define    MT_COMPRESS_DXT1               (0<<3)       /* SURFACE_COMPRESSED */
+#define    MT_COMPRESS_DXT2_3             (1<<3)
+#define    MT_COMPRESS_DXT4_5             (2<<3)
+#define    MT_COMPRESS_FXT1               (3<<3)
+#define    MT_COMPRESS_DXT1_RGB                   (4<<3)
+#define MS3_USE_FENCE_REGS              (1<<2)
+#define MS3_TILED_SURFACE             (1<<1)
+#define MS3_TILE_WALK                 (1<<0)
+
+/* The pitch is the pitch measured in DWORDS, minus 1 */
+#define MS4_PITCH_SHIFT                 21
+#define MS4_CUBE_FACE_ENA_NEGX          (1<<20)
+#define MS4_CUBE_FACE_ENA_POSX          (1<<19)
+#define MS4_CUBE_FACE_ENA_NEGY          (1<<18)
+#define MS4_CUBE_FACE_ENA_POSY          (1<<17)
+#define MS4_CUBE_FACE_ENA_NEGZ          (1<<16)
+#define MS4_CUBE_FACE_ENA_POSZ          (1<<15)
+#define MS4_CUBE_FACE_ENA_MASK          (0x3f<<15)
+#define MS4_MAX_LOD_SHIFT              9
+#define MS4_MAX_LOD_MASK               (0x3f<<9)
+#define MS4_MIP_LAYOUT_LEGACY           (0<<8)
+#define MS4_MIP_LAYOUT_BELOW_LPT        (0<<8)
+#define MS4_MIP_LAYOUT_RIGHT_LPT        (1<<8)
+#define MS4_VOLUME_DEPTH_SHIFT          0
+#define MS4_VOLUME_DEPTH_MASK           (0xff<<0)
+
+/* p244.
+ * The DWORD count is 3 times the number of bits set in SS1_MAPMASK_MASK.
+ */
+#define _3DSTATE_SAMPLER_STATE         (CMD_3D|(0x1d<<24)|(0x1<<16))
+
+#define SS1_MAPMASK_SHIFT               0
+#define SS1_MAPMASK_MASK                (0x8fff<<0)
+
+#define SS2_REVERSE_GAMMA_ENABLE        (1<<31)
+#define SS2_PACKED_TO_PLANAR_ENABLE     (1<<30)
+#define SS2_COLORSPACE_CONVERSION       (1<<29)
+#define SS2_CHROMAKEY_SHIFT             27
+#define SS2_BASE_MIP_LEVEL_SHIFT        22
+#define SS2_BASE_MIP_LEVEL_MASK         (0x1f<<22)
+#define SS2_MIP_FILTER_SHIFT            20
+#define SS2_MIP_FILTER_MASK             (0x3<<20)
+#define   MIPFILTER_NONE               0
+#define   MIPFILTER_NEAREST    1
+#define   MIPFILTER_LINEAR     3
+#define SS2_MAG_FILTER_SHIFT          17
+#define SS2_MAG_FILTER_MASK           (0x7<<17)
+#define   FILTER_NEAREST       0
+#define   FILTER_LINEAR                1
+#define   FILTER_ANISOTROPIC   2
+#define   FILTER_4X4_1         3
+#define   FILTER_4X4_2         4
+#define   FILTER_4X4_FLAT      5
+#define   FILTER_6X5_MONO      6       /* XXX - check */
+#define SS2_MIN_FILTER_SHIFT          14
+#define SS2_MIN_FILTER_MASK           (0x7<<14)
+#define SS2_LOD_BIAS_SHIFT            5
+#define SS2_LOD_BIAS_ONE              (0x10<<5)
+#define SS2_LOD_BIAS_MASK             (0x1ff<<5)
+/* Shadow requires:
+ *  MT_X8{I,L,A}24 or MT_{I,L,A}16 texture format
+ *  FILTER_4X4_x  MIN and MAG filters
+ */
+#define SS2_SHADOW_ENABLE             (1<<4)
+#define SS2_MAX_ANISO_MASK            (1<<3)
+#define SS2_MAX_ANISO_2               (0<<3)
+#define SS2_MAX_ANISO_4               (1<<3)
+#define SS2_SHADOW_FUNC_SHIFT         0
+#define SS2_SHADOW_FUNC_MASK          (0x7<<0)
+/* SS2_SHADOW_FUNC values: see COMPAREFUNC_* */
+
+#define SS3_MIN_LOD_SHIFT            24
+#define SS3_MIN_LOD_ONE              (0x10<<24)
+#define SS3_MIN_LOD_MASK             (0xff<<24)
+#define SS3_KILL_PIXEL_ENABLE        (1<<17)
+#define SS3_TCX_ADDR_MODE_SHIFT      12
+#define SS3_TCX_ADDR_MODE_MASK       (0x7<<12)
+#define   TEXCOORDMODE_WRAP            0
+#define   TEXCOORDMODE_MIRROR          1
+#define   TEXCOORDMODE_CLAMP_EDGE      2
+#define   TEXCOORDMODE_CUBE            3
+#define   TEXCOORDMODE_CLAMP_BORDER    4
+#define   TEXCOORDMODE_MIRROR_ONCE      5
+#define SS3_TCY_ADDR_MODE_SHIFT      9
+#define SS3_TCY_ADDR_MODE_MASK       (0x7<<9)
+#define SS3_TCZ_ADDR_MODE_SHIFT      6
+#define SS3_TCZ_ADDR_MODE_MASK       (0x7<<6)
+#define SS3_NORMALIZED_COORDS        (1<<5)
+#define SS3_TEXTUREMAP_INDEX_SHIFT   1
+#define SS3_TEXTUREMAP_INDEX_MASK    (0xf<<1)
+#define SS3_DEINTERLACER_ENABLE      (1<<0)
+
+#define SS4_BORDER_COLOR_MASK        (~0)
+
+/* 3DSTATE_SPAN_STIPPLE, p258
+ */
+#define _3DSTATE_STIPPLE           ((0x3<<29)|(0x1d<<24)|(0x83<<16))
+#define ST1_ENABLE               (1<<16)
+#define ST1_MASK                 (0xffff)
+
+#define FLUSH_MAP_CACHE    (1<<0)
+#define FLUSH_RENDER_CACHE (1<<1)
+
+#endif
+/* -*- c-basic-offset: 4 -*- */
+/*
+ * Copyright © 2006,2010 Intel 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.
+ *
+ * Authors:
+ *    Eric Anholt <eric@anholt.net>
+ *    Chris Wilson <chris@chris-wilson.co.uk>
+ *
+ */
+
+/* Each instruction is 3 dwords long, though most don't require all
+ * this space.  Maximum of 123 instructions.  Smaller maxes per insn
+ * type.
+ */
+#define _3DSTATE_PIXEL_SHADER_PROGRAM    (CMD_3D|(0x1d<<24)|(0x5<<16))
+
+#define REG_TYPE_R                 0 /* temporary regs, no need to
+                                     * dcl, must be written before
+                                     * read -- Preserved between
+                                     * phases.
+                                     */
+#define REG_TYPE_T                 1 /* Interpolated values, must be
+                                     * dcl'ed before use.
+                                     *
+                                     * 0..7: texture coord,
+                                     * 8: diffuse spec,
+                                     * 9: specular color,
+                                     * 10: fog parameter in w.
+                                     */
+#define REG_TYPE_CONST             2 /* Restriction: only one const
+                                     * can be referenced per
+                                     * instruction, though it may be
+                                     * selected for multiple inputs.
+                                     * Constants not initialized
+                                     * default to zero.
+                                     */
+#define REG_TYPE_S                 3 /* sampler */
+#define REG_TYPE_OC                4 /* output color (rgba) */
+#define REG_TYPE_OD                5 /* output depth (w), xyz are
+                                     * temporaries.  If not written,
+                                     * interpolated depth is used?
+                                     */
+#define REG_TYPE_U                 6 /* unpreserved temporaries */
+#define REG_TYPE_MASK              0x7
+#define REG_TYPE_SHIFT            4
+#define REG_NR_MASK                0xf
+
+/* REG_TYPE_T:
+*/
+#define T_TEX0     0
+#define T_TEX1     1
+#define T_TEX2     2
+#define T_TEX3     3
+#define T_TEX4     4
+#define T_TEX5     5
+#define T_TEX6     6
+#define T_TEX7     7
+#define T_DIFFUSE  8
+#define T_SPECULAR 9
+#define T_FOG_W    10          /* interpolated fog is in W coord */
+
+/* Arithmetic instructions */
+
+/* .replicate_swizzle == selection and replication of a particular
+ * scalar channel, ie., .xxxx, .yyyy, .zzzz or .wwww
+ */
+#define A0_NOP    (0x0<<24)            /* no operation */
+#define A0_ADD    (0x1<<24)            /* dst = src0 + src1 */
+#define A0_MOV    (0x2<<24)            /* dst = src0 */
+#define A0_MUL    (0x3<<24)            /* dst = src0 * src1 */
+#define A0_MAD    (0x4<<24)            /* dst = src0 * src1 + src2 */
+#define A0_DP2ADD (0x5<<24)            /* dst.xyzw = src0.xy dot src1.xy + src2.replicate_swizzle */
+#define A0_DP3    (0x6<<24)            /* dst.xyzw = src0.xyz dot src1.xyz */
+#define A0_DP4    (0x7<<24)            /* dst.xyzw = src0.xyzw dot src1.xyzw */
+#define A0_FRC    (0x8<<24)            /* dst = src0 - floor(src0) */
+#define A0_RCP    (0x9<<24)            /* dst.xyzw = 1/(src0.replicate_swizzle) */
+#define A0_RSQ    (0xa<<24)            /* dst.xyzw = 1/(sqrt(abs(src0.replicate_swizzle))) */
+#define A0_EXP    (0xb<<24)            /* dst.xyzw = exp2(src0.replicate_swizzle) */
+#define A0_LOG    (0xc<<24)            /* dst.xyzw = log2(abs(src0.replicate_swizzle)) */
+#define A0_CMP    (0xd<<24)            /* dst = (src0 >= 0.0) ? src1 : src2 */
+#define A0_MIN    (0xe<<24)            /* dst = (src0 < src1) ? src0 : src1 */
+#define A0_MAX    (0xf<<24)            /* dst = (src0 >= src1) ? src0 : src1 */
+#define A0_FLR    (0x10<<24)           /* dst = floor(src0) */
+#define A0_MOD    (0x11<<24)           /* dst = src0 fmod 1.0 */
+#define A0_TRC    (0x12<<24)           /* dst = int(src0) */
+#define A0_SGE    (0x13<<24)           /* dst = src0 >= src1 ? 1.0 : 0.0 */
+#define A0_SLT    (0x14<<24)           /* dst = src0 < src1 ? 1.0 : 0.0 */
+#define A0_DEST_SATURATE                 (1<<22)
+#define A0_DEST_TYPE_SHIFT                19
+/* Allow: R, OC, OD, U */
+#define A0_DEST_NR_SHIFT                 14
+/* Allow R: 0..15, OC,OD: 0..0, U: 0..2 */
+#define A0_DEST_CHANNEL_X                (1<<10)
+#define A0_DEST_CHANNEL_Y                (2<<10)
+#define A0_DEST_CHANNEL_Z                (4<<10)
+#define A0_DEST_CHANNEL_W                (8<<10)
+#define A0_DEST_CHANNEL_ALL              (0xf<<10)
+#define A0_DEST_CHANNEL_SHIFT            10
+#define A0_SRC0_TYPE_SHIFT               7
+#define A0_SRC0_NR_SHIFT                 2
+
+#define A0_DEST_CHANNEL_XY              (A0_DEST_CHANNEL_X|A0_DEST_CHANNEL_Y)
+#define A0_DEST_CHANNEL_XYZ             (A0_DEST_CHANNEL_XY|A0_DEST_CHANNEL_Z)
+
+#define SRC_X        0
+#define SRC_Y        1
+#define SRC_Z        2
+#define SRC_W        3
+#define SRC_ZERO     4
+#define SRC_ONE      5
+
+#define A1_SRC0_CHANNEL_X_NEGATE         (1<<31)
+#define A1_SRC0_CHANNEL_X_SHIFT          28
+#define A1_SRC0_CHANNEL_Y_NEGATE         (1<<27)
+#define A1_SRC0_CHANNEL_Y_SHIFT          24
+#define A1_SRC0_CHANNEL_Z_NEGATE         (1<<23)
+#define A1_SRC0_CHANNEL_Z_SHIFT          20
+#define A1_SRC0_CHANNEL_W_NEGATE         (1<<19)
+#define A1_SRC0_CHANNEL_W_SHIFT          16
+#define A1_SRC1_TYPE_SHIFT               13
+#define A1_SRC1_NR_SHIFT                 8
+#define A1_SRC1_CHANNEL_X_NEGATE         (1<<7)
+#define A1_SRC1_CHANNEL_X_SHIFT          4
+#define A1_SRC1_CHANNEL_Y_NEGATE         (1<<3)
+#define A1_SRC1_CHANNEL_Y_SHIFT          0
+
+#define A2_SRC1_CHANNEL_Z_NEGATE         (1<<31)
+#define A2_SRC1_CHANNEL_Z_SHIFT          28
+#define A2_SRC1_CHANNEL_W_NEGATE         (1<<27)
+#define A2_SRC1_CHANNEL_W_SHIFT          24
+#define A2_SRC2_TYPE_SHIFT               21
+#define A2_SRC2_NR_SHIFT                 16
+#define A2_SRC2_CHANNEL_X_NEGATE         (1<<15)
+#define A2_SRC2_CHANNEL_X_SHIFT          12
+#define A2_SRC2_CHANNEL_Y_NEGATE         (1<<11)
+#define A2_SRC2_CHANNEL_Y_SHIFT          8
+#define A2_SRC2_CHANNEL_Z_NEGATE         (1<<7)
+#define A2_SRC2_CHANNEL_Z_SHIFT          4
+#define A2_SRC2_CHANNEL_W_NEGATE         (1<<3)
+#define A2_SRC2_CHANNEL_W_SHIFT          0
+
+/* Texture instructions */
+#define T0_TEXLD     (0x15<<24)        /* Sample texture using predeclared
+                                * sampler and address, and output
+                                * filtered texel data to destination
+                                * register */
+#define T0_TEXLDP    (0x16<<24)        /* Same as texld but performs a
+                                * perspective divide of the texture
+                                * coordinate .xyz values by .w before
+                                * sampling. */
+#define T0_TEXLDB    (0x17<<24)        /* Same as texld but biases the
+                                * computed LOD by w.  Only S4.6 two's
+                                * comp is used.  This implies that a
+                                * float to fixed conversion is
+                                * done. */
+#define T0_TEXKILL   (0x18<<24)        /* Does not perform a sampling
+                                * operation.  Simply kills the pixel
+                                * if any channel of the address
+                                * register is < 0.0. */
+#define T0_DEST_TYPE_SHIFT                19
+/* Allow: R, OC, OD, U */
+/* Note: U (unpreserved) regs do not retain their values between
+ * phases (cannot be used for feedback)
+ *
+ * Note: oC and OD registers can only be used as the destination of a
+ * texture instruction once per phase (this is an implementation
+ * restriction).
+ */
+#define T0_DEST_NR_SHIFT                 14
+/* Allow R: 0..15, OC,OD: 0..0, U: 0..2 */
+#define T0_SAMPLER_NR_SHIFT              0 /* This field ignored for TEXKILL */
+#define T0_SAMPLER_NR_MASK               (0xf<<0)
+
+#define T1_ADDRESS_REG_TYPE_SHIFT        24 /* Reg to use as texture coord */
+/* Allow R, T, OC, OD -- R, OC, OD are 'dependent' reads, new program phase */
+#define T1_ADDRESS_REG_NR_SHIFT          17
+#define T2_MBZ                           0
+
+/* Declaration instructions */
+#define D0_DCL       (0x19<<24)        /* Declare a t (interpolated attrib)
+                                * register or an s (sampler)
+                                * register. */
+#define D0_SAMPLE_TYPE_SHIFT              22
+#define D0_SAMPLE_TYPE_2D                 (0x0<<22)
+#define D0_SAMPLE_TYPE_CUBE               (0x1<<22)
+#define D0_SAMPLE_TYPE_VOLUME             (0x2<<22)
+#define D0_SAMPLE_TYPE_MASK               (0x3<<22)
+
+#define D0_TYPE_SHIFT                19
+/* Allow: T, S */
+#define D0_NR_SHIFT                  14
+/* Allow T: 0..10, S: 0..15 */
+#define D0_CHANNEL_X                (1<<10)
+#define D0_CHANNEL_Y                (2<<10)
+#define D0_CHANNEL_Z                (4<<10)
+#define D0_CHANNEL_W                (8<<10)
+#define D0_CHANNEL_ALL              (0xf<<10)
+#define D0_CHANNEL_NONE             (0<<10)
+
+#define D0_CHANNEL_XY               (D0_CHANNEL_X|D0_CHANNEL_Y)
+#define D0_CHANNEL_XYZ              (D0_CHANNEL_XY|D0_CHANNEL_Z)
+
+/* I915 Errata: Do not allow (xz), (xw), (xzw) combinations for diffuse
+ * or specular declarations.
+ *
+ * For T dcls, only allow: (x), (xy), (xyz), (w), (xyzw)
+ *
+ * Must be zero for S (sampler) dcls
+ */
+#define D1_MBZ                          0
+#define D2_MBZ                          0
+
+
+/* MASK_* are the unshifted bitmasks of the destination mask in arithmetic
+ * operations
+ */
+#define MASK_X                 0x1
+#define MASK_Y                 0x2
+#define MASK_Z                 0x4
+#define MASK_W                 0x8
+#define MASK_XYZ               (MASK_X | MASK_Y | MASK_Z)
+#define MASK_XYZW              (MASK_XYZ | MASK_W)
+#define MASK_SATURATE          0x10
+
+/* Temporary, undeclared regs. Preserved between phases */
+#define FS_R0                  ((REG_TYPE_R << REG_TYPE_SHIFT) | 0)
+#define FS_R1                  ((REG_TYPE_R << REG_TYPE_SHIFT) | 1)
+#define FS_R2                  ((REG_TYPE_R << REG_TYPE_SHIFT) | 2)
+#define FS_R3                  ((REG_TYPE_R << REG_TYPE_SHIFT) | 3)
+
+/* Texture coordinate regs.  Must be declared. */
+#define FS_T0                  ((REG_TYPE_T << REG_TYPE_SHIFT) | 0)
+#define FS_T1                  ((REG_TYPE_T << REG_TYPE_SHIFT) | 1)
+#define FS_T2                  ((REG_TYPE_T << REG_TYPE_SHIFT) | 2)
+#define FS_T3                  ((REG_TYPE_T << REG_TYPE_SHIFT) | 3)
+#define FS_T4                  ((REG_TYPE_T << REG_TYPE_SHIFT) | 4)
+#define FS_T5                  ((REG_TYPE_T << REG_TYPE_SHIFT) | 5)
+#define FS_T6                  ((REG_TYPE_T << REG_TYPE_SHIFT) | 6)
+#define FS_T7                  ((REG_TYPE_T << REG_TYPE_SHIFT) | 7)
+#define FS_T8                  ((REG_TYPE_T << REG_TYPE_SHIFT) | 8)
+#define FS_T9                  ((REG_TYPE_T << REG_TYPE_SHIFT) | 9)
+#define FS_T10                 ((REG_TYPE_T << REG_TYPE_SHIFT) | 10)
+
+/* Constant values */
+#define FS_C0                  ((REG_TYPE_CONST << REG_TYPE_SHIFT) | 0)
+#define FS_C1                  ((REG_TYPE_CONST << REG_TYPE_SHIFT) | 1)
+#define FS_C2                  ((REG_TYPE_CONST << REG_TYPE_SHIFT) | 2)
+#define FS_C3                  ((REG_TYPE_CONST << REG_TYPE_SHIFT) | 3)
+#define FS_C4                  ((REG_TYPE_CONST << REG_TYPE_SHIFT) | 4)
+#define FS_C5                  ((REG_TYPE_CONST << REG_TYPE_SHIFT) | 5)
+#define FS_C6                  ((REG_TYPE_CONST << REG_TYPE_SHIFT) | 6)
+#define FS_C7                  ((REG_TYPE_CONST << REG_TYPE_SHIFT) | 7)
+
+/* Sampler regs */
+#define FS_S0                  ((REG_TYPE_S << REG_TYPE_SHIFT) | 0)
+#define FS_S1                  ((REG_TYPE_S << REG_TYPE_SHIFT) | 1)
+#define FS_S2                  ((REG_TYPE_S << REG_TYPE_SHIFT) | 2)
+#define FS_S3                  ((REG_TYPE_S << REG_TYPE_SHIFT) | 3)
+
+/* Output color */
+#define FS_OC                  ((REG_TYPE_OC << REG_TYPE_SHIFT) | 0)
+
+/* Output depth */
+#define FS_OD                  ((REG_TYPE_OD << REG_TYPE_SHIFT) | 0)
+
+/* Unpreserved temporary regs */
+#define FS_U0                  ((REG_TYPE_U << REG_TYPE_SHIFT) | 0)
+#define FS_U1                  ((REG_TYPE_U << REG_TYPE_SHIFT) | 1)
+#define FS_U2                  ((REG_TYPE_U << REG_TYPE_SHIFT) | 2)
+#define FS_U3                  ((REG_TYPE_U << REG_TYPE_SHIFT) | 3)
+
+#define X_CHANNEL_SHIFT (REG_TYPE_SHIFT + 3)
+#define Y_CHANNEL_SHIFT (X_CHANNEL_SHIFT + 4)
+#define Z_CHANNEL_SHIFT (Y_CHANNEL_SHIFT + 4)
+#define W_CHANNEL_SHIFT (Z_CHANNEL_SHIFT + 4)
+
+#define REG_CHANNEL_MASK 0xf
+
+#define REG_NR(reg)            ((reg) & REG_NR_MASK)
+#define REG_TYPE(reg)          (((reg) >> REG_TYPE_SHIFT) & REG_TYPE_MASK)
+#define REG_X(reg)             (((reg) >> X_CHANNEL_SHIFT) & REG_CHANNEL_MASK)
+#define REG_Y(reg)             (((reg) >> Y_CHANNEL_SHIFT) & REG_CHANNEL_MASK)
+#define REG_Z(reg)             (((reg) >> Z_CHANNEL_SHIFT) & REG_CHANNEL_MASK)
+#define REG_W(reg)             (((reg) >> W_CHANNEL_SHIFT) & REG_CHANNEL_MASK)
+
+enum gen3_fs_channel {
+       X_CHANNEL_VAL = 0,
+       Y_CHANNEL_VAL,
+       Z_CHANNEL_VAL,
+       W_CHANNEL_VAL,
+       ZERO_CHANNEL_VAL,
+       ONE_CHANNEL_VAL,
+
+       NEG_X_CHANNEL_VAL = X_CHANNEL_VAL | 0x8,
+       NEG_Y_CHANNEL_VAL = Y_CHANNEL_VAL | 0x8,
+       NEG_Z_CHANNEL_VAL = Z_CHANNEL_VAL | 0x8,
+       NEG_W_CHANNEL_VAL = W_CHANNEL_VAL | 0x8,
+       NEG_ONE_CHANNEL_VAL = ONE_CHANNEL_VAL | 0x8
+};
+
+#define gen3_fs_operand(reg, x, y, z, w) \
+       (reg) | \
+(x##_CHANNEL_VAL << X_CHANNEL_SHIFT) | \
+(y##_CHANNEL_VAL << Y_CHANNEL_SHIFT) | \
+(z##_CHANNEL_VAL << Z_CHANNEL_SHIFT) | \
+(w##_CHANNEL_VAL << W_CHANNEL_SHIFT)
+
+/**
+ * Construct an operand description for using a register with no swizzling
+ */
+#define gen3_fs_operand_reg(reg)                                       \
+       gen3_fs_operand(reg, X, Y, Z, W)
+
+#define gen3_fs_operand_reg_negate(reg)                                        \
+       gen3_fs_operand(reg, NEG_X, NEG_Y, NEG_Z, NEG_W)
+
+/**
+ * Returns an operand containing (0.0, 0.0, 0.0, 0.0).
+ */
+#define gen3_fs_operand_zero() gen3_fs_operand(FS_R0, ZERO, ZERO, ZERO, ZERO)
+
+/**
+ * Returns an unused operand
+ */
+#define gen3_fs_operand_none() gen3_fs_operand_zero()
+
+/**
+ * Returns an operand containing (1.0, 1.0, 1.0, 1.0).
+ */
+#define gen3_fs_operand_one() gen3_fs_operand(FS_R0, ONE, ONE, ONE, ONE)
+
+#define gen3_get_hardware_channel_val(val, shift, negate) \
+       (((val & 0x7) << shift) | ((val & 0x8) ? negate : 0))
+
+/**
+ * Outputs a fragment shader command to declare a sampler or texture register.
+ */
+#define gen3_fs_dcl(reg)                                               \
+       do {                                                                    \
+               OUT_BATCH(D0_DCL | \
+                         (REG_TYPE(reg) << D0_TYPE_SHIFT) | \
+                         (REG_NR(reg) << D0_NR_SHIFT) | \
+                         ((REG_TYPE(reg) != REG_TYPE_S) ? D0_CHANNEL_ALL : 0)); \
+               OUT_BATCH(0); \
+               OUT_BATCH(0); \
+       } while (0)
+
+#define gen3_fs_texld(dest_reg, sampler_reg, address_reg)              \
+       do {                                                                    \
+               OUT_BATCH(T0_TEXLD | \
+                         (REG_TYPE(dest_reg) << T0_DEST_TYPE_SHIFT) | \
+                         (REG_NR(dest_reg) << T0_DEST_NR_SHIFT) | \
+                         (REG_NR(sampler_reg) << T0_SAMPLER_NR_SHIFT)); \
+               OUT_BATCH((REG_TYPE(address_reg) << T1_ADDRESS_REG_TYPE_SHIFT) | \
+                         (REG_NR(address_reg) << T1_ADDRESS_REG_NR_SHIFT)); \
+               OUT_BATCH(0); \
+       } while (0)
+
+#define gen3_fs_texldp(dest_reg, sampler_reg, address_reg)             \
+       do {                                                                    \
+               OUT_BATCH(T0_TEXLDP | \
+                         (REG_TYPE(dest_reg) << T0_DEST_TYPE_SHIFT) | \
+                         (REG_NR(dest_reg) << T0_DEST_NR_SHIFT) | \
+                         (REG_NR(sampler_reg) << T0_SAMPLER_NR_SHIFT)); \
+               OUT_BATCH((REG_TYPE(address_reg) << T1_ADDRESS_REG_TYPE_SHIFT) | \
+                         (REG_NR(address_reg) << T1_ADDRESS_REG_NR_SHIFT)); \
+               OUT_BATCH(0); \
+       } while (0)
+
+#define gen3_fs_arith_masked(op, dest_reg, dest_mask, operand0, operand1, operand2)    \
+       _gen3_fs_arith_masked(A0_##op, dest_reg, dest_mask, operand0, operand1, operand2)
+
+#define gen3_fs_arith(op, dest_reg, operand0, operand1, operand2)      \
+       _gen3_fs_arith(A0_##op, dest_reg, operand0, operand1, operand2)
+
+#define _gen3_fs_arith_masked(cmd, dest_reg, dest_mask, operand0, operand1, operand2) \
+       do { \
+               /* Set up destination register and write mask */ \
+               OUT_BATCH(cmd | \
+                         (REG_TYPE(dest_reg) << A0_DEST_TYPE_SHIFT) | \
+                         (REG_NR(dest_reg) << A0_DEST_NR_SHIFT) | \
+                         (((dest_mask) & ~MASK_SATURATE) << A0_DEST_CHANNEL_SHIFT) | \
+                         (((dest_mask) & MASK_SATURATE) ? A0_DEST_SATURATE : 0) | \
+                         /* Set up operand 0 */ \
+                         (REG_TYPE(operand0) << A0_SRC0_TYPE_SHIFT) | \
+                         (REG_NR(operand0) << A0_SRC0_NR_SHIFT)); \
+               OUT_BATCH(gen3_get_hardware_channel_val(REG_X(operand0), \
+                                                       A1_SRC0_CHANNEL_X_SHIFT, \
+                                                       A1_SRC0_CHANNEL_X_NEGATE) | \
+                         gen3_get_hardware_channel_val(REG_Y(operand0), \
+                                                       A1_SRC0_CHANNEL_Y_SHIFT, \
+                                                       A1_SRC0_CHANNEL_Y_NEGATE) | \
+                         gen3_get_hardware_channel_val(REG_Z(operand0), \
+                                                       A1_SRC0_CHANNEL_Z_SHIFT, \
+                                                       A1_SRC0_CHANNEL_Z_NEGATE) | \
+                         gen3_get_hardware_channel_val(REG_W(operand0), \
+                                                       A1_SRC0_CHANNEL_W_SHIFT, \
+                                                       A1_SRC0_CHANNEL_W_NEGATE) | \
+                         /* Set up operand 1 */ \
+                         (REG_TYPE(operand1) << A1_SRC1_TYPE_SHIFT) | \
+                         (REG_NR(operand1) << A1_SRC1_NR_SHIFT) | \
+                         gen3_get_hardware_channel_val(REG_X(operand1), \
+                                                       A1_SRC1_CHANNEL_X_SHIFT, \
+                                                       A1_SRC1_CHANNEL_X_NEGATE) | \
+                         gen3_get_hardware_channel_val(REG_Y(operand1), \
+                                                       A1_SRC1_CHANNEL_Y_SHIFT, \
+                                                       A1_SRC1_CHANNEL_Y_NEGATE)); \
+               OUT_BATCH(gen3_get_hardware_channel_val(REG_Z(operand1), \
+                                                       A2_SRC1_CHANNEL_Z_SHIFT, \
+                                                       A2_SRC1_CHANNEL_Z_NEGATE) | \
+                         gen3_get_hardware_channel_val(REG_W(operand1), \
+                                                       A2_SRC1_CHANNEL_W_SHIFT, \
+                                                       A2_SRC1_CHANNEL_W_NEGATE) | \
+                         /* Set up operand 2 */ \
+                         (REG_TYPE(operand2) << A2_SRC2_TYPE_SHIFT) | \
+                         (REG_NR(operand2) << A2_SRC2_NR_SHIFT) | \
+                         gen3_get_hardware_channel_val(REG_X(operand2), \
+                                                       A2_SRC2_CHANNEL_X_SHIFT, \
+                                                       A2_SRC2_CHANNEL_X_NEGATE) | \
+                         gen3_get_hardware_channel_val(REG_Y(operand2), \
+                                                       A2_SRC2_CHANNEL_Y_SHIFT, \
+                                                       A2_SRC2_CHANNEL_Y_NEGATE) | \
+                         gen3_get_hardware_channel_val(REG_Z(operand2), \
+                                                       A2_SRC2_CHANNEL_Z_SHIFT, \
+                                                       A2_SRC2_CHANNEL_Z_NEGATE) | \
+                         gen3_get_hardware_channel_val(REG_W(operand2), \
+                                                       A2_SRC2_CHANNEL_W_SHIFT, \
+                                                       A2_SRC2_CHANNEL_W_NEGATE)); \
+       } while (0)
+
+#define _gen3_fs_arith(cmd, dest_reg, operand0, operand1, operand2) do {\
+       /* Set up destination register and write mask */ \
+       OUT_BATCH(cmd | \
+                 (REG_TYPE(dest_reg) << A0_DEST_TYPE_SHIFT) | \
+                 (REG_NR(dest_reg) << A0_DEST_NR_SHIFT) | \
+                 (A0_DEST_CHANNEL_ALL) | \
+                 /* Set up operand 0 */ \
+                 (REG_TYPE(operand0) << A0_SRC0_TYPE_SHIFT) | \
+                 (REG_NR(operand0) << A0_SRC0_NR_SHIFT)); \
+       OUT_BATCH(gen3_get_hardware_channel_val(REG_X(operand0), \
+                                               A1_SRC0_CHANNEL_X_SHIFT, \
+                                               A1_SRC0_CHANNEL_X_NEGATE) | \
+                 gen3_get_hardware_channel_val(REG_Y(operand0), \
+                                               A1_SRC0_CHANNEL_Y_SHIFT, \
+                                               A1_SRC0_CHANNEL_Y_NEGATE) | \
+                 gen3_get_hardware_channel_val(REG_Z(operand0), \
+                                               A1_SRC0_CHANNEL_Z_SHIFT, \
+                                               A1_SRC0_CHANNEL_Z_NEGATE) | \
+                 gen3_get_hardware_channel_val(REG_W(operand0), \
+                                               A1_SRC0_CHANNEL_W_SHIFT, \
+                                               A1_SRC0_CHANNEL_W_NEGATE) | \
+                 /* Set up operand 1 */ \
+                 (REG_TYPE(operand1) << A1_SRC1_TYPE_SHIFT) | \
+                 (REG_NR(operand1) << A1_SRC1_NR_SHIFT) | \
+                 gen3_get_hardware_channel_val(REG_X(operand1), \
+                                               A1_SRC1_CHANNEL_X_SHIFT, \
+                                               A1_SRC1_CHANNEL_X_NEGATE) | \
+                 gen3_get_hardware_channel_val(REG_Y(operand1), \
+                                               A1_SRC1_CHANNEL_Y_SHIFT, \
+                                               A1_SRC1_CHANNEL_Y_NEGATE)); \
+       OUT_BATCH(gen3_get_hardware_channel_val(REG_Z(operand1), \
+                                               A2_SRC1_CHANNEL_Z_SHIFT, \
+                                               A2_SRC1_CHANNEL_Z_NEGATE) | \
+                 gen3_get_hardware_channel_val(REG_W(operand1), \
+                                               A2_SRC1_CHANNEL_W_SHIFT, \
+                                               A2_SRC1_CHANNEL_W_NEGATE) | \
+                 /* Set up operand 2 */ \
+                 (REG_TYPE(operand2) << A2_SRC2_TYPE_SHIFT) | \
+                 (REG_NR(operand2) << A2_SRC2_NR_SHIFT) | \
+                 gen3_get_hardware_channel_val(REG_X(operand2), \
+                                               A2_SRC2_CHANNEL_X_SHIFT, \
+                                               A2_SRC2_CHANNEL_X_NEGATE) | \
+                 gen3_get_hardware_channel_val(REG_Y(operand2), \
+                                               A2_SRC2_CHANNEL_Y_SHIFT, \
+                                               A2_SRC2_CHANNEL_Y_NEGATE) | \
+                 gen3_get_hardware_channel_val(REG_Z(operand2), \
+                                               A2_SRC2_CHANNEL_Z_SHIFT, \
+                                               A2_SRC2_CHANNEL_Z_NEGATE) | \
+                 gen3_get_hardware_channel_val(REG_W(operand2), \
+                                               A2_SRC2_CHANNEL_W_SHIFT, \
+                                               A2_SRC2_CHANNEL_W_NEGATE)); \
+} while (0)
+
+#define gen3_fs_mov(dest_reg, operand0)                                        \
+       gen3_fs_arith(MOV, dest_reg, \
+                     operand0,                 \
+                     gen3_fs_operand_none(),                   \
+                     gen3_fs_operand_none())
+
+#define gen3_fs_mov_masked(dest_reg, dest_mask, operand0)              \
+       gen3_fs_arith_masked (MOV, dest_reg, dest_mask, \
+                             operand0, \
+                             gen3_fs_operand_none(), \
+                             gen3_fs_operand_none())
+
+
+#define gen3_fs_frc(dest_reg, operand0)                                        \
+       gen3_fs_arith (FRC, dest_reg, \
+                      operand0,                        \
+                      gen3_fs_operand_none(),                  \
+                      gen3_fs_operand_none())
+
+/** Add operand0 and operand1 and put the result in dest_reg */
+#define gen3_fs_add(dest_reg, operand0, operand1)                      \
+       gen3_fs_arith (ADD, dest_reg, \
+                      operand0, operand1,      \
+                      gen3_fs_operand_none())
+
+/** Multiply operand0 and operand1 and put the result in dest_reg */
+#define gen3_fs_mul(dest_reg, operand0, operand1)                      \
+       gen3_fs_arith (MUL, dest_reg, \
+                      operand0, operand1,      \
+                      gen3_fs_operand_none())
+
+/** Computes 1/(operand0.replicate_swizzle) puts the result in dest_reg */
+#define gen3_fs_rcp(dest_reg, dest_mask, operand0)             \
+       do {                                                                    \
+               if (dest_mask) {                                                        \
+                       gen3_fs_arith_masked (RCP, dest_reg, dest_mask, \
+                                             operand0,                 \
+                                             gen3_fs_operand_none (),                  \
+                                             gen3_fs_operand_none ());                 \
+               } else { \
+                       gen3_fs_arith (RCP, dest_reg, \
+                                      operand0, \
+                                      gen3_fs_operand_none (), \
+                                      gen3_fs_operand_none ()); \
+               } \
+       } while (0)
+
+/** Computes 1/sqrt(operand0.replicate_swizzle) puts the result in dest_reg */
+#define gen3_fs_rsq(dest_reg, dest_mask, operand0)             \
+       do {                                                                    \
+               if (dest_mask) {                                                        \
+                       gen3_fs_arith_masked (RSQ, dest_reg, dest_mask, \
+                                             operand0,                 \
+                                             gen3_fs_operand_none (),                  \
+                                             gen3_fs_operand_none ());                 \
+               } else { \
+                       gen3_fs_arith (RSQ, dest_reg, \
+                                      operand0, \
+                                      gen3_fs_operand_none (), \
+                                      gen3_fs_operand_none ()); \
+               } \
+       } while (0)
+
+/** Puts the minimum of operand0 and operand1 in dest_reg */
+#define gen3_fs_min(dest_reg, operand0, operand1)                      \
+       gen3_fs_arith (MIN, dest_reg, \
+                      operand0, operand1, \
+                      gen3_fs_operand_none())
+
+/** Puts the maximum of operand0 and operand1 in dest_reg */
+#define gen3_fs_max(dest_reg, operand0, operand1)                      \
+       gen3_fs_arith (MAX, dest_reg, \
+                      operand0, operand1, \
+                      gen3_fs_operand_none())
+
+#define gen3_fs_cmp(dest_reg, operand0, operand1, operand2)            \
+       gen3_fs_arith (CMP, dest_reg, operand0, operand1, operand2)
+
+/** Perform operand0 * operand1 + operand2 and put the result in dest_reg */
+#define gen3_fs_mad(dest_reg, dest_mask, op0, op1, op2)        \
+       do {                                                                    \
+               if (dest_mask) {                                                        \
+                       gen3_fs_arith_masked (MAD, dest_reg, dest_mask, op0, op1, op2); \
+               } else { \
+                       gen3_fs_arith (MAD, dest_reg, op0, op1, op2); \
+               } \
+       } while (0)
+
+#define gen3_fs_dp2add(dest_reg, dest_mask, op0, op1, op2)     \
+       do {                                                                    \
+               if (dest_mask) {                                                        \
+                       gen3_fs_arith_masked (DP2ADD, dest_reg, dest_mask, op0, op1, op2); \
+               } else { \
+                       gen3_fs_arith (DP2ADD, dest_reg, op0, op1, op2); \
+               } \
+       } while (0)
+
+/**
+ * Perform a 3-component dot-product of operand0 and operand1 and put the
+ * resulting scalar in the channels of dest_reg specified by the dest_mask.
+ */
+#define gen3_fs_dp3(dest_reg, dest_mask, op0, op1)     \
+       do {                                                                    \
+               if (dest_mask) {                                                        \
+                       gen3_fs_arith_masked (DP3, dest_reg, dest_mask, \
+                                             op0, op1,\
+                                             gen3_fs_operand_none());                  \
+               } else { \
+                       gen3_fs_arith (DP3, dest_reg, op0, op1,\
+                                      gen3_fs_operand_none());                 \
+               } \
+       } while (0)
+
+/**
+ * Perform a 4-component dot-product of operand0 and operand1 and put the
+ * resulting scalar in the channels of dest_reg specified by the dest_mask.
+ */
+#define gen3_fs_dp4(dest_reg, dest_mask, op0, op1)     \
+       do {                                                                    \
+               if (dest_mask) {                                                        \
+                       gen3_fs_arith_masked (DP4, dest_reg, dest_mask, \
+                                             op0, op1,\
+                                             gen3_fs_operand_none());                  \
+               } else { \
+                       gen3_fs_arith (DP4, dest_reg, op0, op1,\
+                                      gen3_fs_operand_none());                 \
+               } \
+       } while (0)
+
+#define SHADER_TRAPEZOIDS (1 << 24)
diff --git a/src/sna/gen4_render.c b/src/sna/gen4_render.c
new file mode 100644 (file)
index 0000000..ceef528
--- /dev/null
@@ -0,0 +1,3732 @@
+/*
+ * Copyright © 2006,2008,2011 Intel Corporation
+ * Copyright © 2007 Red Hat, Inc.
+ *
+ * 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.
+ *
+ * Authors:
+ *    Wang Zhenyu <zhenyu.z.wang@sna.com>
+ *    Eric Anholt <eric@anholt.net>
+ *    Carl Worth <cworth@redhat.com>
+ *    Keith Packard <keithp@keithp.com>
+ *    Chris Wilson <chris@chris-wilson.co.uk>
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "sna.h"
+#include "sna_reg.h"
+#include "sna_render.h"
+#include "sna_render_inline.h"
+#include "sna_video.h"
+
+#include "brw/brw.h"
+#include "gen4_render.h"
+
+/* gen4 has a serious issue with its shaders that we need to flush
+ * after every rectangle... So until that is resolved, prefer
+ * the BLT engine.
+ */
+#define PREFER_BLT 1
+#define FLUSH_EVERY_VERTEX 1
+
+#define NO_COMPOSITE 0
+#define NO_COMPOSITE_SPANS 0
+#define NO_COPY 0
+#define NO_COPY_BOXES 0
+#define NO_FILL 0
+#define NO_FILL_ONE 0
+#define NO_FILL_BOXES 0
+#define NO_VIDEO 0
+
+#if FLUSH_EVERY_VERTEX
+#define _FLUSH() do { \
+       gen4_vertex_flush(sna); \
+       OUT_BATCH(MI_FLUSH | MI_INHIBIT_RENDER_CACHE_FLUSH); \
+} while (0)
+#define FLUSH(OP) do { \
+       if ((OP)->mask.bo == NULL) _FLUSH(); \
+} while (0)
+#else
+#define _FLUSH()
+#define FLUSH(OP)
+#endif
+
+#define GEN4_GRF_BLOCKS(nreg)    ((nreg + 15) / 16 - 1)
+
+/* Set up a default static partitioning of the URB, which is supposed to
+ * allow anything we would want to do, at potentially lower performance.
+ */
+#define URB_CS_ENTRY_SIZE     1
+#define URB_CS_ENTRIES       0
+
+#define URB_VS_ENTRY_SIZE     1
+#define URB_VS_ENTRIES       32
+
+#define URB_GS_ENTRY_SIZE     0
+#define URB_GS_ENTRIES       0
+
+#define URB_CLIP_ENTRY_SIZE   0
+#define URB_CLIP_ENTRIES      0
+
+#define URB_SF_ENTRY_SIZE     2
+#define URB_SF_ENTRIES       64
+
+/*
+ * this program computes dA/dx and dA/dy for the texture coordinates along
+ * with the base texture coordinate. It was extracted from the Mesa driver
+ */
+
+#define SF_KERNEL_NUM_GRF 16
+#define PS_KERNEL_NUM_GRF 32
+
+static const struct gt_info {
+       uint32_t max_sf_threads;
+       uint32_t max_wm_threads;
+       uint32_t urb_size;
+} gen4_gt_info = {
+       24, 32, 256,
+}, g4x_gt_info = {
+       24, 50, 384,
+};
+
+static const uint32_t ps_kernel_packed_static[][4] = {
+#include "exa_wm_xy.g4b"
+#include "exa_wm_src_affine.g4b"
+#include "exa_wm_src_sample_argb.g4b"
+#include "exa_wm_yuv_rgb.g4b"
+#include "exa_wm_write.g4b"
+};
+
+static const uint32_t ps_kernel_planar_static[][4] = {
+#include "exa_wm_xy.g4b"
+#include "exa_wm_src_affine.g4b"
+#include "exa_wm_src_sample_planar.g4b"
+#include "exa_wm_yuv_rgb.g4b"
+#include "exa_wm_write.g4b"
+};
+
+#define NOKERNEL(kernel_enum, func, masked) \
+    [kernel_enum] = {func, 0, masked}
+#define KERNEL(kernel_enum, kernel, masked) \
+    [kernel_enum] = {&kernel, sizeof(kernel), masked}
+static const struct wm_kernel_info {
+       const void *data;
+       unsigned int size;
+       bool has_mask;
+} wm_kernels[] = {
+       NOKERNEL(WM_KERNEL, brw_wm_kernel__affine, false),
+       NOKERNEL(WM_KERNEL_P, brw_wm_kernel__projective, false),
+
+       NOKERNEL(WM_KERNEL_MASK, brw_wm_kernel__affine_mask, true),
+       NOKERNEL(WM_KERNEL_MASK_P, brw_wm_kernel__projective_mask, true),
+
+       NOKERNEL(WM_KERNEL_MASKCA, brw_wm_kernel__affine_mask_ca, true),
+       NOKERNEL(WM_KERNEL_MASKCA_P, brw_wm_kernel__projective_mask_ca, true),
+
+       NOKERNEL(WM_KERNEL_MASKSA, brw_wm_kernel__affine_mask_sa, true),
+       NOKERNEL(WM_KERNEL_MASKSA_P, brw_wm_kernel__projective_mask_sa, true),
+
+       NOKERNEL(WM_KERNEL_OPACITY, brw_wm_kernel__affine_opacity, true),
+       NOKERNEL(WM_KERNEL_OPACITY_P, brw_wm_kernel__projective_opacity, true),
+
+       KERNEL(WM_KERNEL_VIDEO_PLANAR, ps_kernel_planar_static, false),
+       KERNEL(WM_KERNEL_VIDEO_PACKED, ps_kernel_packed_static, false),
+};
+#undef KERNEL
+
+static const struct blendinfo {
+       bool src_alpha;
+       uint32_t src_blend;
+       uint32_t dst_blend;
+} gen4_blend_op[] = {
+       /* Clear */     {0, GEN4_BLENDFACTOR_ZERO, GEN4_BLENDFACTOR_ZERO},
+       /* Src */       {0, GEN4_BLENDFACTOR_ONE, GEN4_BLENDFACTOR_ZERO},
+       /* Dst */       {0, GEN4_BLENDFACTOR_ZERO, GEN4_BLENDFACTOR_ONE},
+       /* Over */      {1, GEN4_BLENDFACTOR_ONE, GEN4_BLENDFACTOR_INV_SRC_ALPHA},
+       /* OverReverse */ {0, GEN4_BLENDFACTOR_INV_DST_ALPHA, GEN4_BLENDFACTOR_ONE},
+       /* In */        {0, GEN4_BLENDFACTOR_DST_ALPHA, GEN4_BLENDFACTOR_ZERO},
+       /* InReverse */ {1, GEN4_BLENDFACTOR_ZERO, GEN4_BLENDFACTOR_SRC_ALPHA},
+       /* Out */       {0, GEN4_BLENDFACTOR_INV_DST_ALPHA, GEN4_BLENDFACTOR_ZERO},
+       /* OutReverse */ {1, GEN4_BLENDFACTOR_ZERO, GEN4_BLENDFACTOR_INV_SRC_ALPHA},
+       /* Atop */      {1, GEN4_BLENDFACTOR_DST_ALPHA, GEN4_BLENDFACTOR_INV_SRC_ALPHA},
+       /* AtopReverse */ {1, GEN4_BLENDFACTOR_INV_DST_ALPHA, GEN4_BLENDFACTOR_SRC_ALPHA},
+       /* Xor */       {1, GEN4_BLENDFACTOR_INV_DST_ALPHA, GEN4_BLENDFACTOR_INV_SRC_ALPHA},
+       /* Add */       {0, GEN4_BLENDFACTOR_ONE, GEN4_BLENDFACTOR_ONE},
+};
+
+/**
+ * Highest-valued BLENDFACTOR used in gen4_blend_op.
+ *
+ * This leaves out GEN4_BLENDFACTOR_INV_DST_COLOR,
+ * GEN4_BLENDFACTOR_INV_CONST_{COLOR,ALPHA},
+ * GEN4_BLENDFACTOR_INV_SRC1_{COLOR,ALPHA}
+ */
+#define GEN4_BLENDFACTOR_COUNT (GEN4_BLENDFACTOR_INV_DST_ALPHA + 1)
+
+#define BLEND_OFFSET(s, d) \
+       (((s) * GEN4_BLENDFACTOR_COUNT + (d)) * 64)
+
+#define SAMPLER_OFFSET(sf, se, mf, me, k) \
+       ((((((sf) * EXTEND_COUNT + (se)) * FILTER_COUNT + (mf)) * EXTEND_COUNT + (me)) * KERNEL_COUNT + (k)) * 64)
+
+static void
+gen4_emit_pipelined_pointers(struct sna *sna,
+                            const struct sna_composite_op *op,
+                            int blend, int kernel);
+
+#define OUT_BATCH(v) batch_emit(sna, v)
+#define OUT_VERTEX(x,y) vertex_emit_2s(sna, x,y)
+#define OUT_VERTEX_F(v) vertex_emit(sna, v)
+
+#define GEN4_MAX_3D_SIZE 8192
+
+static inline bool too_large(int width, int height)
+{
+       return width > GEN4_MAX_3D_SIZE || height > GEN4_MAX_3D_SIZE;
+}
+
+static int
+gen4_choose_composite_kernel(int op, bool has_mask, bool is_ca, bool is_affine)
+{
+       int base;
+
+       if (has_mask) {
+               if (is_ca) {
+                       if (gen4_blend_op[op].src_alpha)
+                               base = WM_KERNEL_MASKSA;
+                       else
+                               base = WM_KERNEL_MASKCA;
+               } else
+                       base = WM_KERNEL_MASK;
+       } else
+               base = WM_KERNEL;
+
+       return base + !is_affine;
+}
+
+static void gen4_magic_ca_pass(struct sna *sna,
+                              const struct sna_composite_op *op)
+{
+       struct gen4_render_state *state = &sna->render_state.gen4;
+
+       if (!op->need_magic_ca_pass)
+               return;
+
+       DBG(("%s: CA fixup\n", __FUNCTION__));
+       assert(op->mask.bo != NULL);
+       assert(op->has_component_alpha);
+
+       if (FLUSH_EVERY_VERTEX)
+               OUT_BATCH(MI_FLUSH | MI_INHIBIT_RENDER_CACHE_FLUSH);
+
+       gen4_emit_pipelined_pointers(sna, op, PictOpAdd,
+                                    gen4_choose_composite_kernel(PictOpAdd,
+                                                                 true, true, op->is_affine));
+
+       OUT_BATCH(GEN4_3DPRIMITIVE |
+                 GEN4_3DPRIMITIVE_VERTEX_SEQUENTIAL |
+                 (_3DPRIM_RECTLIST << GEN4_3DPRIMITIVE_TOPOLOGY_SHIFT) |
+                 (0 << 9) |
+                 4);
+       OUT_BATCH(sna->render.vertex_index - sna->render.vertex_start);
+       OUT_BATCH(sna->render.vertex_start);
+       OUT_BATCH(1);   /* single instance */
+       OUT_BATCH(0);   /* start instance location */
+       OUT_BATCH(0);   /* index buffer offset, ignored */
+
+       state->last_primitive = sna->kgem.nbatch;
+}
+
+static void gen4_vertex_flush(struct sna *sna)
+{
+       if (sna->render_state.gen4.vertex_offset == 0)
+               return;
+
+       DBG(("%s[%x] = %d\n", __FUNCTION__,
+            4*sna->render_state.gen4.vertex_offset,
+            sna->render.vertex_index - sna->render.vertex_start));
+       sna->kgem.batch[sna->render_state.gen4.vertex_offset] =
+               sna->render.vertex_index - sna->render.vertex_start;
+       sna->render_state.gen4.vertex_offset = 0;
+}
+
+static int gen4_vertex_finish(struct sna *sna)
+{
+       struct kgem_bo *bo;
+       unsigned int i;
+
+       assert(sna->render.vertex_used);
+       assert(sna->render.nvertex_reloc);
+
+       /* Note: we only need dword alignment (currently) */
+
+       bo = sna->render.vbo;
+       if (bo) {
+               gen4_vertex_flush(sna);
+
+               for (i = 0; i < sna->render.nvertex_reloc; i++) {
+                       DBG(("%s: reloc[%d] = %d\n", __FUNCTION__,
+                            i, sna->render.vertex_reloc[i]));
+
+                       sna->kgem.batch[sna->render.vertex_reloc[i]] =
+                               kgem_add_reloc(&sna->kgem,
+                                              sna->render.vertex_reloc[i], bo,
+                                              I915_GEM_DOMAIN_VERTEX << 16,
+                                              0);
+               }
+
+               sna->render.nvertex_reloc = 0;
+               sna->render.vertex_used = 0;
+               sna->render.vertex_index = 0;
+               sna->render_state.gen4.vb_id = 0;
+
+               kgem_bo_destroy(&sna->kgem, bo);
+       }
+
+       sna->render.vertices = NULL;
+       sna->render.vbo = kgem_create_linear(&sna->kgem,
+                                            256*1024, CREATE_GTT_MAP);
+       if (sna->render.vbo)
+               sna->render.vertices = kgem_bo_map(&sna->kgem, sna->render.vbo);
+       if (sna->render.vertices == NULL) {
+               if (sna->render.vbo)
+                       kgem_bo_destroy(&sna->kgem, sna->render.vbo);
+               sna->render.vbo = NULL;
+               return 0;
+       }
+
+       if (sna->render.vertex_used) {
+               memcpy(sna->render.vertices,
+                      sna->render.vertex_data,
+                      sizeof(float)*sna->render.vertex_used);
+       }
+       sna->render.vertex_size = 64 * 1024 - 1;
+       return sna->render.vertex_size - sna->render.vertex_used;
+}
+
+static void gen4_vertex_close(struct sna *sna)
+{
+       struct kgem_bo *bo, *free_bo = NULL;
+       unsigned int i, delta = 0;
+
+       assert(sna->render_state.gen4.vertex_offset == 0);
+       if (!sna->render_state.gen4.vb_id)
+               return;
+
+       DBG(("%s: used=%d, vbo active? %d\n",
+            __FUNCTION__, sna->render.vertex_used, sna->render.vbo != NULL));
+
+       bo = sna->render.vbo;
+       if (bo) {
+               if (sna->render.vertex_size - sna->render.vertex_used < 64) {
+                       DBG(("%s: discarding full vbo\n", __FUNCTION__));
+                       sna->render.vbo = NULL;
+                       sna->render.vertices = sna->render.vertex_data;
+                       sna->render.vertex_size = ARRAY_SIZE(sna->render.vertex_data);
+                       free_bo = bo;
+               } else if (IS_CPU_MAP(bo->map)) {
+                       DBG(("%s: converting CPU map to GTT\n", __FUNCTION__));
+                       sna->render.vertices =
+                               kgem_bo_map__gtt(&sna->kgem, sna->render.vbo);
+                       if (sna->render.vertices == NULL) {
+                               sna->render.vbo = NULL;
+                               sna->render.vertices = sna->render.vertex_data;
+                               sna->render.vertex_size = ARRAY_SIZE(sna->render.vertex_data);
+                               free_bo = bo;
+                       }
+               }
+       } else {
+               if (sna->kgem.nbatch + sna->render.vertex_used <= sna->kgem.surface) {
+                       DBG(("%s: copy to batch: %d @ %d\n", __FUNCTION__,
+                            sna->render.vertex_used, sna->kgem.nbatch));
+                       memcpy(sna->kgem.batch + sna->kgem.nbatch,
+                              sna->render.vertex_data,
+                              sna->render.vertex_used * 4);
+                       delta = sna->kgem.nbatch * 4;
+                       bo = NULL;
+                       sna->kgem.nbatch += sna->render.vertex_used;
+               } else {
+                       bo = kgem_create_linear(&sna->kgem,
+                                               4*sna->render.vertex_used, 0);
+                       if (bo && !kgem_bo_write(&sna->kgem, bo,
+                                                sna->render.vertex_data,
+                                                4*sna->render.vertex_used)) {
+                               kgem_bo_destroy(&sna->kgem, bo);
+                               bo = NULL;
+                       }
+                       DBG(("%s: new vbo: %d\n", __FUNCTION__,
+                            sna->render.vertex_used));
+                       free_bo = bo;
+               }
+       }
+
+       assert(sna->render.nvertex_reloc);
+       for (i = 0; i < sna->render.nvertex_reloc; i++) {
+               DBG(("%s: reloc[%d] = %d\n", __FUNCTION__,
+                    i, sna->render.vertex_reloc[i]));
+
+               sna->kgem.batch[sna->render.vertex_reloc[i]] =
+                       kgem_add_reloc(&sna->kgem,
+                                      sna->render.vertex_reloc[i], bo,
+                                      I915_GEM_DOMAIN_VERTEX << 16,
+                                      delta);
+       }
+       sna->render.nvertex_reloc = 0;
+
+       if (sna->render.vbo == NULL) {
+               sna->render.vertex_used = 0;
+               sna->render.vertex_index = 0;
+       }
+
+       if (free_bo)
+               kgem_bo_destroy(&sna->kgem, free_bo);
+}
+
+
+static uint32_t gen4_get_blend(int op,
+                              bool has_component_alpha,
+                              uint32_t dst_format)
+{
+       uint32_t src, dst;
+
+       src = gen4_blend_op[op].src_blend;
+       dst = gen4_blend_op[op].dst_blend;
+
+       /* If there's no dst alpha channel, adjust the blend op so that we'll treat
+        * it as always 1.
+        */
+       if (PICT_FORMAT_A(dst_format) == 0) {
+               if (src == GEN4_BLENDFACTOR_DST_ALPHA)
+                       src = GEN4_BLENDFACTOR_ONE;
+               else if (src == GEN4_BLENDFACTOR_INV_DST_ALPHA)
+                       src = GEN4_BLENDFACTOR_ZERO;
+       }
+
+       /* If the source alpha is being used, then we should only be in a
+        * case where the source blend factor is 0, and the source blend
+        * value is the mask channels multiplied by the source picture's alpha.
+        */
+       if (has_component_alpha && gen4_blend_op[op].src_alpha) {
+               if (dst == GEN4_BLENDFACTOR_SRC_ALPHA)
+                       dst = GEN4_BLENDFACTOR_SRC_COLOR;
+               else if (dst == GEN4_BLENDFACTOR_INV_SRC_ALPHA)
+                       dst = GEN4_BLENDFACTOR_INV_SRC_COLOR;
+       }
+
+       DBG(("blend op=%d, dst=%x [A=%d] => src=%d, dst=%d => offset=%x\n",
+            op, dst_format, PICT_FORMAT_A(dst_format),
+            src, dst, BLEND_OFFSET(src, dst)));
+       return BLEND_OFFSET(src, dst);
+}
+
+static uint32_t gen4_get_card_format(PictFormat format)
+{
+       switch (format) {
+       default:
+               return -1;
+       case PICT_a8r8g8b8:
+               return GEN4_SURFACEFORMAT_B8G8R8A8_UNORM;
+       case PICT_x8r8g8b8:
+               return GEN4_SURFACEFORMAT_B8G8R8X8_UNORM;
+       case PICT_a8b8g8r8:
+               return GEN4_SURFACEFORMAT_R8G8B8A8_UNORM;
+       case PICT_x8b8g8r8:
+               return GEN4_SURFACEFORMAT_R8G8B8X8_UNORM;
+       case PICT_a2r10g10b10:
+               return GEN4_SURFACEFORMAT_B10G10R10A2_UNORM;
+       case PICT_x2r10g10b10:
+               return GEN4_SURFACEFORMAT_B10G10R10X2_UNORM;
+       case PICT_r8g8b8:
+               return GEN4_SURFACEFORMAT_R8G8B8_UNORM;
+       case PICT_r5g6b5:
+               return GEN4_SURFACEFORMAT_B5G6R5_UNORM;
+       case PICT_a1r5g5b5:
+               return GEN4_SURFACEFORMAT_B5G5R5A1_UNORM;
+       case PICT_a8:
+               return GEN4_SURFACEFORMAT_A8_UNORM;
+       case PICT_a4r4g4b4:
+               return GEN4_SURFACEFORMAT_B4G4R4A4_UNORM;
+       }
+}
+
+static uint32_t gen4_get_dest_format(PictFormat format)
+{
+       switch (format) {
+       default:
+               return -1;
+       case PICT_a8r8g8b8:
+       case PICT_x8r8g8b8:
+               return GEN4_SURFACEFORMAT_B8G8R8A8_UNORM;
+       case PICT_a8b8g8r8:
+       case PICT_x8b8g8r8:
+               return GEN4_SURFACEFORMAT_R8G8B8A8_UNORM;
+       case PICT_a2r10g10b10:
+       case PICT_x2r10g10b10:
+               return GEN4_SURFACEFORMAT_B10G10R10A2_UNORM;
+       case PICT_r5g6b5:
+               return GEN4_SURFACEFORMAT_B5G6R5_UNORM;
+       case PICT_x1r5g5b5:
+       case PICT_a1r5g5b5:
+               return GEN4_SURFACEFORMAT_B5G5R5A1_UNORM;
+       case PICT_a8:
+               return GEN4_SURFACEFORMAT_A8_UNORM;
+       case PICT_a4r4g4b4:
+       case PICT_x4r4g4b4:
+               return GEN4_SURFACEFORMAT_B4G4R4A4_UNORM;
+       }
+}
+
+static bool gen4_check_dst_format(PictFormat format)
+{
+       if (gen4_get_dest_format(format) != -1)
+               return true;
+
+       DBG(("%s: unhandled format: %x\n", __FUNCTION__, (int)format));
+       return false;
+}
+
+static bool gen4_check_format(uint32_t format)
+{
+       if (gen4_get_card_format(format) != -1)
+               return true;
+
+       DBG(("%s: unhandled format: %x\n", __FUNCTION__, (int)format));
+       return false;
+}
+
+typedef struct gen4_surface_state_padded {
+       struct gen4_surface_state state;
+       char pad[32 - sizeof(struct gen4_surface_state)];
+} gen4_surface_state_padded;
+
+static void null_create(struct sna_static_stream *stream)
+{
+       /* A bunch of zeros useful for legacy border color and depth-stencil */
+       sna_static_stream_map(stream, 64, 64);
+}
+
+static void
+sampler_state_init(struct gen4_sampler_state *sampler_state,
+                  sampler_filter_t filter,
+                  sampler_extend_t extend)
+{
+       sampler_state->ss0.lod_preclamp = 1;    /* GL mode */
+
+       /* We use the legacy mode to get the semantics specified by
+        * the Render extension. */
+       sampler_state->ss0.border_color_mode = GEN4_BORDER_COLOR_MODE_LEGACY;
+
+       switch (filter) {
+       default:
+       case SAMPLER_FILTER_NEAREST:
+               sampler_state->ss0.min_filter = GEN4_MAPFILTER_NEAREST;
+               sampler_state->ss0.mag_filter = GEN4_MAPFILTER_NEAREST;
+               break;
+       case SAMPLER_FILTER_BILINEAR:
+               sampler_state->ss0.min_filter = GEN4_MAPFILTER_LINEAR;
+               sampler_state->ss0.mag_filter = GEN4_MAPFILTER_LINEAR;
+               break;
+       }
+
+       switch (extend) {
+       default:
+       case SAMPLER_EXTEND_NONE:
+               sampler_state->ss1.r_wrap_mode = GEN4_TEXCOORDMODE_CLAMP_BORDER;
+               sampler_state->ss1.s_wrap_mode = GEN4_TEXCOORDMODE_CLAMP_BORDER;
+               sampler_state->ss1.t_wrap_mode = GEN4_TEXCOORDMODE_CLAMP_BORDER;
+               break;
+       case SAMPLER_EXTEND_REPEAT:
+               sampler_state->ss1.r_wrap_mode = GEN4_TEXCOORDMODE_WRAP;
+               sampler_state->ss1.s_wrap_mode = GEN4_TEXCOORDMODE_WRAP;
+               sampler_state->ss1.t_wrap_mode = GEN4_TEXCOORDMODE_WRAP;
+               break;
+       case SAMPLER_EXTEND_PAD:
+               sampler_state->ss1.r_wrap_mode = GEN4_TEXCOORDMODE_CLAMP;
+               sampler_state->ss1.s_wrap_mode = GEN4_TEXCOORDMODE_CLAMP;
+               sampler_state->ss1.t_wrap_mode = GEN4_TEXCOORDMODE_CLAMP;
+               break;
+       case SAMPLER_EXTEND_REFLECT:
+               sampler_state->ss1.r_wrap_mode = GEN4_TEXCOORDMODE_MIRROR;
+               sampler_state->ss1.s_wrap_mode = GEN4_TEXCOORDMODE_MIRROR;
+               sampler_state->ss1.t_wrap_mode = GEN4_TEXCOORDMODE_MIRROR;
+               break;
+       }
+}
+
+static uint32_t gen4_filter(uint32_t filter)
+{
+       switch (filter) {
+       default:
+               assert(0);
+       case PictFilterNearest:
+               return SAMPLER_FILTER_NEAREST;
+       case PictFilterBilinear:
+               return SAMPLER_FILTER_BILINEAR;
+       }
+}
+
+static uint32_t gen4_check_filter(PicturePtr picture)
+{
+       switch (picture->filter) {
+       case PictFilterNearest:
+       case PictFilterBilinear:
+               return true;
+       default:
+               DBG(("%s: unknown filter: %s [%d]\n",
+                    __FUNCTION__,
+                    PictureGetFilterName(picture->filter),
+                    picture->filter));
+               return false;
+       }
+}
+
+static uint32_t gen4_repeat(uint32_t repeat)
+{
+       switch (repeat) {
+       default:
+               assert(0);
+       case RepeatNone:
+               return SAMPLER_EXTEND_NONE;
+       case RepeatNormal:
+               return SAMPLER_EXTEND_REPEAT;
+       case RepeatPad:
+               return SAMPLER_EXTEND_PAD;
+       case RepeatReflect:
+               return SAMPLER_EXTEND_REFLECT;
+       }
+}
+
+static bool gen4_check_repeat(PicturePtr picture)
+{
+       if (!picture->repeat)
+               return true;
+
+       switch (picture->repeatType) {
+       case RepeatNone:
+       case RepeatNormal:
+       case RepeatPad:
+       case RepeatReflect:
+               return true;
+       default:
+               DBG(("%s: unknown repeat: %d\n",
+                    __FUNCTION__, picture->repeatType));
+               return false;
+       }
+}
+
+/**
+ * Sets up the common fields for a surface state buffer for the given
+ * picture in the given surface state buffer.
+ */
+static uint32_t
+gen4_bind_bo(struct sna *sna,
+            struct kgem_bo *bo,
+            uint32_t width,
+            uint32_t height,
+            uint32_t format,
+            bool is_dst)
+{
+       struct gen4_surface_state *ss;
+       uint32_t domains;
+       uint16_t offset;
+
+       assert(!kgem_bo_is_snoop(bo));
+
+       /* After the first bind, we manage the cache domains within the batch */
+       offset = kgem_bo_get_binding(bo, format);
+       if (offset) {
+               if (is_dst)
+                       kgem_bo_mark_dirty(bo);
+               return offset * sizeof(uint32_t);
+       }
+
+       offset = sna->kgem.surface -=
+               sizeof(struct gen4_surface_state_padded) / sizeof(uint32_t);
+       ss = memset(sna->kgem.batch + offset, 0, sizeof(*ss));
+
+       ss->ss0.surface_type = GEN4_SURFACE_2D;
+       ss->ss0.surface_format = format;
+
+       if (is_dst)
+               domains = I915_GEM_DOMAIN_RENDER << 16 | I915_GEM_DOMAIN_RENDER;
+       else
+               domains = I915_GEM_DOMAIN_SAMPLER << 16;
+
+       ss->ss0.data_return_format = GEN4_SURFACERETURNFORMAT_FLOAT32;
+       ss->ss0.color_blend = 1;
+       ss->ss1.base_addr =
+               kgem_add_reloc(&sna->kgem, offset + 1, bo, domains, 0);
+
+       ss->ss2.height = height - 1;
+       ss->ss2.width  = width - 1;
+       ss->ss3.pitch  = bo->pitch - 1;
+       ss->ss3.tiled_surface = bo->tiling != I915_TILING_NONE;
+       ss->ss3.tile_walk     = bo->tiling == I915_TILING_Y;
+
+       kgem_bo_set_binding(bo, format, offset);
+
+       DBG(("[%x] bind bo(handle=%d, addr=%d), format=%d, width=%d, height=%d, pitch=%d, tiling=%d -> %s\n",
+            offset, bo->handle, ss->ss1.base_addr,
+            ss->ss0.surface_format, width, height, bo->pitch, bo->tiling,
+            domains & 0xffff ? "render" : "sampler"));
+
+       return offset * sizeof(uint32_t);
+}
+
+fastcall static void
+gen4_emit_composite_primitive_solid(struct sna *sna,
+                                   const struct sna_composite_op *op,
+                                   const struct sna_composite_rectangles *r)
+{
+       float *v;
+       union {
+               struct sna_coordinate p;
+               float f;
+       } dst;
+
+       v = sna->render.vertices + sna->render.vertex_used;
+       sna->render.vertex_used += 9;
+
+       dst.p.x = r->dst.x + r->width;
+       dst.p.y = r->dst.y + r->height;
+       v[0] = dst.f;
+       v[1] = 1.;
+       v[2] = 1.;
+
+       dst.p.x = r->dst.x;
+       v[3] = dst.f;
+       v[4] = 0.;
+       v[5] = 1.;
+
+       dst.p.y = r->dst.y;
+       v[6] = dst.f;
+       v[7] = 0.;
+       v[8] = 0.;
+}
+
+fastcall static void
+gen4_emit_composite_primitive_identity_source(struct sna *sna,
+                                             const struct sna_composite_op *op,
+                                             const struct sna_composite_rectangles *r)
+{
+       const float *sf = op->src.scale;
+       float sx, sy, *v;
+       union {
+               struct sna_coordinate p;
+               float f;
+       } dst;
+
+       v = sna->render.vertices + sna->render.vertex_used;
+       sna->render.vertex_used += 9;
+
+       sx = r->src.x + op->src.offset[0];
+       sy = r->src.y + op->src.offset[1];
+
+       dst.p.x = r->dst.x + r->width;
+       dst.p.y = r->dst.y + r->height;
+       v[0] = dst.f;
+       v[1] = (sx + r->width) * sf[0];
+       v[2] = (sy + r->height) * sf[1];
+
+       dst.p.x = r->dst.x;
+       v[3] = dst.f;
+       v[4] = sx * sf[0];
+       v[5] = v[2];
+
+       dst.p.y = r->dst.y;
+       v[6] = dst.f;
+       v[7] = v[4];
+       v[8] = sy * sf[1];
+}
+
+fastcall static void
+gen4_emit_composite_primitive_affine_source(struct sna *sna,
+                                           const struct sna_composite_op *op,
+                                           const struct sna_composite_rectangles *r)
+{
+       union {
+               struct sna_coordinate p;
+               float f;
+       } dst;
+       float *v;
+
+       v = sna->render.vertices + sna->render.vertex_used;
+       sna->render.vertex_used += 9;
+
+       dst.p.x = r->dst.x + r->width;
+       dst.p.y = r->dst.y + r->height;
+       v[0] = dst.f;
+       _sna_get_transformed_coordinates(op->src.offset[0] + r->src.x + r->width,
+                                        op->src.offset[1] + r->src.y + r->height,
+                                        op->src.transform,
+                                        &v[1], &v[2]);
+       v[1] *= op->src.scale[0];
+       v[2] *= op->src.scale[1];
+
+       dst.p.x = r->dst.x;
+       v[3] = dst.f;
+       _sna_get_transformed_coordinates(op->src.offset[0] + r->src.x,
+                                        op->src.offset[1] + r->src.y + r->height,
+                                        op->src.transform,
+                                        &v[4], &v[5]);
+       v[4] *= op->src.scale[0];
+       v[5] *= op->src.scale[1];
+
+       dst.p.y = r->dst.y;
+       v[6] = dst.f;
+       _sna_get_transformed_coordinates(op->src.offset[0] + r->src.x,
+                                        op->src.offset[1] + r->src.y,
+                                        op->src.transform,
+                                        &v[7], &v[8]);
+       v[7] *= op->src.scale[0];
+       v[8] *= op->src.scale[1];
+}
+
+fastcall static void
+gen4_emit_composite_primitive_identity_source_mask(struct sna *sna,
+                                                  const struct sna_composite_op *op,
+                                                  const struct sna_composite_rectangles *r)
+{
+       union {
+               struct sna_coordinate p;
+               float f;
+       } dst;
+       float src_x, src_y;
+       float msk_x, msk_y;
+       float w, h;
+       float *v;
+
+       src_x = r->src.x + op->src.offset[0];
+       src_y = r->src.y + op->src.offset[1];
+       msk_x = r->mask.x + op->mask.offset[0];
+       msk_y = r->mask.y + op->mask.offset[1];
+       w = r->width;
+       h = r->height;
+
+       v = sna->render.vertices + sna->render.vertex_used;
+       sna->render.vertex_used += 15;
+
+       dst.p.x = r->dst.x + r->width;
+       dst.p.y = r->dst.y + r->height;
+       v[0] = dst.f;
+       v[1] = (src_x + w) * op->src.scale[0];
+       v[2] = (src_y + h) * op->src.scale[1];
+       v[3] = (msk_x + w) * op->mask.scale[0];
+       v[4] = (msk_y + h) * op->mask.scale[1];
+
+       dst.p.x = r->dst.x;
+       v[5] = dst.f;
+       v[6] = src_x * op->src.scale[0];
+       v[7] = v[2];
+       v[8] = msk_x * op->mask.scale[0];
+       v[9] = v[4];
+
+       dst.p.y = r->dst.y;
+       v[10] = dst.f;
+       v[11] = v[6];
+       v[12] = src_y * op->src.scale[1];
+       v[13] = v[8];
+       v[14] = msk_y * op->mask.scale[1];
+}
+
+fastcall static void
+gen4_emit_composite_primitive(struct sna *sna,
+                             const struct sna_composite_op *op,
+                             const struct sna_composite_rectangles *r)
+{
+       float src_x[3], src_y[3], src_w[3], mask_x[3], mask_y[3], mask_w[3];
+       bool is_affine = op->is_affine;
+       const float *src_sf = op->src.scale;
+       const float *mask_sf = op->mask.scale;
+
+       if (is_affine) {
+               sna_get_transformed_coordinates(r->src.x + op->src.offset[0],
+                                               r->src.y + op->src.offset[1],
+                                               op->src.transform,
+                                               &src_x[0],
+                                               &src_y[0]);
+
+               sna_get_transformed_coordinates(r->src.x + op->src.offset[0],
+                                               r->src.y + op->src.offset[1] + r->height,
+                                               op->src.transform,
+                                               &src_x[1],
+                                               &src_y[1]);
+
+               sna_get_transformed_coordinates(r->src.x + op->src.offset[0] + r->width,
+                                               r->src.y + op->src.offset[1] + r->height,
+                                               op->src.transform,
+                                               &src_x[2],
+                                               &src_y[2]);
+       } else {
+               sna_get_transformed_coordinates_3d(r->src.x + op->src.offset[0],
+                                                  r->src.y + op->src.offset[1],
+                                                  op->src.transform,
+                                                  &src_x[0],
+                                                  &src_y[0],
+                                                  &src_w[0]);
+               sna_get_transformed_coordinates_3d(r->src.x + op->src.offset[0],
+                                                  r->src.y + op->src.offset[1] + r->height,
+                                                  op->src.transform,
+                                                  &src_x[1],
+                                                  &src_y[1],
+                                                  &src_w[1]);
+               sna_get_transformed_coordinates_3d(r->src.x + op->src.offset[0] + r->width,
+                                                  r->src.y + op->src.offset[1] + r->height,
+                                                  op->src.transform,
+                                                  &src_x[2],
+                                                  &src_y[2],
+                                                  &src_w[2]);
+       }
+
+       if (op->mask.bo) {
+               if (is_affine) {
+                       sna_get_transformed_coordinates(r->mask.x + op->mask.offset[0],
+                                                       r->mask.y + op->mask.offset[1],
+                                                       op->mask.transform,
+                                                       &mask_x[0],
+                                                       &mask_y[0]);
+
+                       sna_get_transformed_coordinates(r->mask.x + op->mask.offset[0],
+                                                       r->mask.y + op->mask.offset[1] + r->height,
+                                                       op->mask.transform,
+                                                       &mask_x[1],
+                                                       &mask_y[1]);
+
+                       sna_get_transformed_coordinates(r->mask.x + op->mask.offset[0] + r->width,
+                                                       r->mask.y + op->mask.offset[1] + r->height,
+                                                       op->mask.transform,
+                                                       &mask_x[2],
+                                                       &mask_y[2]);
+               } else {
+                       sna_get_transformed_coordinates_3d(r->mask.x + op->mask.offset[0],
+                                                          r->mask.y + op->mask.offset[1],
+                                                          op->mask.transform,
+                                                          &mask_x[0],
+                                                          &mask_y[0],
+                                                          &mask_w[0]);
+                       sna_get_transformed_coordinates_3d(r->mask.x + op->mask.offset[0],
+                                                          r->mask.y + op->mask.offset[1] + r->height,
+                                                          op->mask.transform,
+                                                          &mask_x[1],
+                                                          &mask_y[1],
+                                                          &mask_w[1]);
+                       sna_get_transformed_coordinates_3d(r->mask.x + op->mask.offset[0] + r->width,
+                                                          r->mask.y + op->mask.offset[1] + r->height,
+                                                          op->mask.transform,
+                                                          &mask_x[2],
+                                                          &mask_y[2],
+                                                          &mask_w[2]);
+               }
+       }
+
+       OUT_VERTEX(r->dst.x + r->width, r->dst.y + r->height);
+       OUT_VERTEX_F(src_x[2] * src_sf[0]);
+       OUT_VERTEX_F(src_y[2] * src_sf[1]);
+       if (!is_affine)
+               OUT_VERTEX_F(src_w[2]);
+       if (op->mask.bo) {
+               OUT_VERTEX_F(mask_x[2] * mask_sf[0]);
+               OUT_VERTEX_F(mask_y[2] * mask_sf[1]);
+               if (!is_affine)
+                       OUT_VERTEX_F(mask_w[2]);
+       }
+
+       OUT_VERTEX(r->dst.x, r->dst.y + r->height);
+       OUT_VERTEX_F(src_x[1] * src_sf[0]);
+       OUT_VERTEX_F(src_y[1] * src_sf[1]);
+       if (!is_affine)
+               OUT_VERTEX_F(src_w[1]);
+       if (op->mask.bo) {
+               OUT_VERTEX_F(mask_x[1] * mask_sf[0]);
+               OUT_VERTEX_F(mask_y[1] * mask_sf[1]);
+               if (!is_affine)
+                       OUT_VERTEX_F(mask_w[1]);
+       }
+
+       OUT_VERTEX(r->dst.x, r->dst.y);
+       OUT_VERTEX_F(src_x[0] * src_sf[0]);
+       OUT_VERTEX_F(src_y[0] * src_sf[1]);
+       if (!is_affine)
+               OUT_VERTEX_F(src_w[0]);
+       if (op->mask.bo) {
+               OUT_VERTEX_F(mask_x[0] * mask_sf[0]);
+               OUT_VERTEX_F(mask_y[0] * mask_sf[1]);
+               if (!is_affine)
+                       OUT_VERTEX_F(mask_w[0]);
+       }
+}
+
+static void gen4_emit_vertex_buffer(struct sna *sna,
+                                   const struct sna_composite_op *op)
+{
+       int id = op->u.gen4.ve_id;
+
+       OUT_BATCH(GEN4_3DSTATE_VERTEX_BUFFERS | 3);
+       OUT_BATCH((id << VB0_BUFFER_INDEX_SHIFT) | VB0_VERTEXDATA |
+                 (4*op->floats_per_vertex << VB0_BUFFER_PITCH_SHIFT));
+       sna->render.vertex_reloc[sna->render.nvertex_reloc++] = sna->kgem.nbatch;
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+
+       sna->render_state.gen4.vb_id |= 1 << id;
+}
+
+static void gen4_emit_primitive(struct sna *sna)
+{
+       if (sna->kgem.nbatch == sna->render_state.gen4.last_primitive) {
+               sna->render_state.gen4.vertex_offset = sna->kgem.nbatch - 5;
+               return;
+       }
+
+       OUT_BATCH(GEN4_3DPRIMITIVE |
+                 GEN4_3DPRIMITIVE_VERTEX_SEQUENTIAL |
+                 (_3DPRIM_RECTLIST << GEN4_3DPRIMITIVE_TOPOLOGY_SHIFT) |
+                 (0 << 9) |
+                 4);
+       sna->render_state.gen4.vertex_offset = sna->kgem.nbatch;
+       OUT_BATCH(0);   /* vertex count, to be filled in later */
+       OUT_BATCH(sna->render.vertex_index);
+       OUT_BATCH(1);   /* single instance */
+       OUT_BATCH(0);   /* start instance location */
+       OUT_BATCH(0);   /* index buffer offset, ignored */
+       sna->render.vertex_start = sna->render.vertex_index;
+
+       sna->render_state.gen4.last_primitive = sna->kgem.nbatch;
+}
+
+static bool gen4_rectangle_begin(struct sna *sna,
+                                const struct sna_composite_op *op)
+{
+       int id = op->u.gen4.ve_id;
+       int ndwords;
+
+       /* 7xpipelined pointers + 6xprimitive + 1xflush */
+       ndwords = op->need_magic_ca_pass? 20 : 6;
+       if (FLUSH_EVERY_VERTEX)
+               ndwords += 1;
+       if ((sna->render_state.gen4.vb_id & (1 << id)) == 0)
+               ndwords += 5;
+
+       if (!kgem_check_batch(&sna->kgem, ndwords))
+               return false;
+
+       if ((sna->render_state.gen4.vb_id & (1 << id)) == 0)
+               gen4_emit_vertex_buffer(sna, op);
+       if (sna->render_state.gen4.vertex_offset == 0)
+               gen4_emit_primitive(sna);
+
+       return true;
+}
+
+static int gen4_get_rectangles__flush(struct sna *sna,
+                                     const struct sna_composite_op *op)
+{
+       if (!kgem_check_batch(&sna->kgem, (FLUSH_EVERY_VERTEX || op->need_magic_ca_pass) ? 25 : 6))
+               return 0;
+       if (!kgem_check_reloc_and_exec(&sna->kgem, 1))
+               return 0;
+
+       if (op->need_magic_ca_pass && sna->render.vbo)
+               return 0;
+
+       return gen4_vertex_finish(sna);
+}
+
+inline static int gen4_get_rectangles(struct sna *sna,
+                                     const struct sna_composite_op *op,
+                                     int want,
+                                     void (*emit_state)(struct sna *sna, const struct sna_composite_op *op))
+{
+       int rem;
+
+start:
+       rem = vertex_space(sna);
+       if (rem < op->floats_per_rect) {
+               DBG(("flushing vbo for %s: %d < %d\n",
+                    __FUNCTION__, rem, op->floats_per_rect));
+               rem = gen4_get_rectangles__flush(sna, op);
+               if (unlikely(rem == 0))
+                       goto flush;
+       }
+
+       if (unlikely(sna->render_state.gen4.vertex_offset == 0 &&
+                    !gen4_rectangle_begin(sna, op)))
+               goto flush;
+
+       if (want > 1 && want * op->floats_per_rect > rem)
+               want = rem / op->floats_per_rect;
+
+       sna->render.vertex_index += 3*want;
+       return want;
+
+flush:
+       if (sna->render_state.gen4.vertex_offset) {
+               gen4_vertex_flush(sna);
+               gen4_magic_ca_pass(sna, op);
+       }
+       _kgem_submit(&sna->kgem);
+       emit_state(sna, op);
+       goto start;
+}
+
+static uint32_t *
+gen4_composite_get_binding_table(struct sna *sna,
+                                uint16_t *offset)
+{
+       sna->kgem.surface -=
+               sizeof(struct gen4_surface_state_padded) / sizeof(uint32_t);
+
+       DBG(("%s(%x)\n", __FUNCTION__, 4*sna->kgem.surface));
+
+       /* Clear all surplus entries to zero in case of prefetch */
+       *offset = sna->kgem.surface;
+       return memset(sna->kgem.batch + sna->kgem.surface,
+                     0, sizeof(struct gen4_surface_state_padded));
+}
+
+static void
+gen4_emit_urb(struct sna *sna)
+{
+       int urb_vs_start, urb_vs_size;
+       int urb_gs_start, urb_gs_size;
+       int urb_clip_start, urb_clip_size;
+       int urb_sf_start, urb_sf_size;
+       int urb_cs_start, urb_cs_size;
+
+       if (!sna->render_state.gen4.needs_urb)
+               return;
+
+       urb_vs_start = 0;
+       urb_vs_size = URB_VS_ENTRIES * URB_VS_ENTRY_SIZE;
+       urb_gs_start = urb_vs_start + urb_vs_size;
+       urb_gs_size = URB_GS_ENTRIES * URB_GS_ENTRY_SIZE;
+       urb_clip_start = urb_gs_start + urb_gs_size;
+       urb_clip_size = URB_CLIP_ENTRIES * URB_CLIP_ENTRY_SIZE;
+       urb_sf_start = urb_clip_start + urb_clip_size;
+       urb_sf_size = URB_SF_ENTRIES * URB_SF_ENTRY_SIZE;
+       urb_cs_start = urb_sf_start + urb_sf_size;
+       urb_cs_size = URB_CS_ENTRIES * URB_CS_ENTRY_SIZE;
+
+       OUT_BATCH(GEN4_URB_FENCE |
+                 UF0_CS_REALLOC |
+                 UF0_SF_REALLOC |
+                 UF0_CLIP_REALLOC |
+                 UF0_GS_REALLOC |
+                 UF0_VS_REALLOC |
+                 1);
+       OUT_BATCH(((urb_clip_start + urb_clip_size) << UF1_CLIP_FENCE_SHIFT) |
+                 ((urb_gs_start + urb_gs_size) << UF1_GS_FENCE_SHIFT) |
+                 ((urb_vs_start + urb_vs_size) << UF1_VS_FENCE_SHIFT));
+       OUT_BATCH(((urb_cs_start + urb_cs_size) << UF2_CS_FENCE_SHIFT) |
+                 ((urb_sf_start + urb_sf_size) << UF2_SF_FENCE_SHIFT));
+
+       /* Constant buffer state */
+       OUT_BATCH(GEN4_CS_URB_STATE | 0);
+       OUT_BATCH((URB_CS_ENTRY_SIZE - 1) << 4 | URB_CS_ENTRIES << 0);
+
+       sna->render_state.gen4.needs_urb = false;
+}
+
+static void
+gen4_emit_state_base_address(struct sna *sna)
+{
+       assert(sna->render_state.gen4.general_bo->proxy == NULL);
+       OUT_BATCH(GEN4_STATE_BASE_ADDRESS | 4);
+       OUT_BATCH(kgem_add_reloc(&sna->kgem, /* general */
+                                sna->kgem.nbatch,
+                                sna->render_state.gen4.general_bo,
+                                I915_GEM_DOMAIN_INSTRUCTION << 16,
+                                BASE_ADDRESS_MODIFY));
+       OUT_BATCH(kgem_add_reloc(&sna->kgem, /* surface */
+                                sna->kgem.nbatch,
+                                NULL,
+                                I915_GEM_DOMAIN_INSTRUCTION << 16,
+                                BASE_ADDRESS_MODIFY));
+       OUT_BATCH(0); /* media */
+
+       /* upper bounds, all disabled */
+       OUT_BATCH(BASE_ADDRESS_MODIFY);
+       OUT_BATCH(0);
+}
+
+static void
+gen4_emit_invariant(struct sna *sna)
+{
+       assert(sna->kgem.surface == sna->kgem.batch_size);
+
+       if (sna->kgem.gen >= 45)
+               OUT_BATCH(NEW_PIPELINE_SELECT | PIPELINE_SELECT_3D);
+       else
+               OUT_BATCH(GEN4_PIPELINE_SELECT | PIPELINE_SELECT_3D);
+
+       gen4_emit_state_base_address(sna);
+
+       sna->render_state.gen4.needs_invariant = false;
+}
+
+static void
+gen4_get_batch(struct sna *sna)
+{
+       kgem_set_mode(&sna->kgem, KGEM_RENDER);
+
+       if (!kgem_check_batch_with_surfaces(&sna->kgem, 150, 4)) {
+               DBG(("%s: flushing batch: %d < %d+%d\n",
+                    __FUNCTION__, sna->kgem.surface - sna->kgem.nbatch,
+                    150, 4*8));
+               kgem_submit(&sna->kgem);
+               _kgem_set_mode(&sna->kgem, KGEM_RENDER);
+       }
+
+       if (sna->render_state.gen4.needs_invariant)
+               gen4_emit_invariant(sna);
+}
+
+static void
+gen4_align_vertex(struct sna *sna, const struct sna_composite_op *op)
+{
+       assert(op->floats_per_rect == 3*op->floats_per_vertex);
+       if (op->floats_per_vertex != sna->render_state.gen4.floats_per_vertex) {
+               if (sna->render.vertex_size - sna->render.vertex_used < 2*op->floats_per_rect)
+                       gen4_vertex_finish(sna);
+
+               DBG(("aligning vertex: was %d, now %d floats per vertex, %d->%d\n",
+                    sna->render_state.gen4.floats_per_vertex,
+                    op->floats_per_vertex,
+                    sna->render.vertex_index,
+                    (sna->render.vertex_used + op->floats_per_vertex - 1) / op->floats_per_vertex));
+               sna->render.vertex_index = (sna->render.vertex_used + op->floats_per_vertex - 1) / op->floats_per_vertex;
+               sna->render.vertex_used = sna->render.vertex_index * op->floats_per_vertex;
+               sna->render_state.gen4.floats_per_vertex = op->floats_per_vertex;
+       }
+}
+
+static void
+gen4_emit_binding_table(struct sna *sna, uint16_t offset)
+{
+       if (sna->render_state.gen4.surface_table == offset)
+               return;
+
+       sna->render_state.gen4.surface_table = offset;
+
+       /* Binding table pointers */
+       OUT_BATCH(GEN4_3DSTATE_BINDING_TABLE_POINTERS | 4);
+       OUT_BATCH(0);           /* vs */
+       OUT_BATCH(0);           /* gs */
+       OUT_BATCH(0);           /* clip */
+       OUT_BATCH(0);           /* sf */
+       /* Only the PS uses the binding table */
+       OUT_BATCH(offset*4);
+}
+
+static void
+gen4_emit_pipelined_pointers(struct sna *sna,
+                            const struct sna_composite_op *op,
+                            int blend, int kernel)
+{
+       uint32_t key;
+       uint16_t sp, bp;
+
+       DBG(("%s: has_mask=%d, src=(%d, %d), mask=(%d, %d),kernel=%d, blend=%d, ca=%d, format=%x\n",
+            __FUNCTION__, op->mask.bo != NULL,
+            op->src.filter, op->src.repeat,
+            op->mask.filter, op->mask.repeat,
+            kernel, blend, op->has_component_alpha, (int)op->dst.format));
+
+       sp = SAMPLER_OFFSET(op->src.filter, op->src.repeat,
+                           op->mask.filter, op->mask.repeat,
+                           kernel);
+       bp = gen4_get_blend(blend, op->has_component_alpha, op->dst.format);
+
+       DBG(("%s: sp=%d, bp=%d\n", __FUNCTION__, sp, bp));
+
+       key = sp | bp << 16;
+       if (key == sna->render_state.gen4.last_pipelined_pointers)
+               return;
+
+       OUT_BATCH(GEN4_3DSTATE_PIPELINED_POINTERS | 5);
+       OUT_BATCH(sna->render_state.gen4.vs);
+       OUT_BATCH(GEN4_GS_DISABLE); /* passthrough */
+       OUT_BATCH(GEN4_CLIP_DISABLE); /* passthrough */
+       OUT_BATCH(sna->render_state.gen4.sf[op->mask.bo != NULL]);
+       OUT_BATCH(sna->render_state.gen4.wm + sp);
+       OUT_BATCH(sna->render_state.gen4.cc + bp);
+
+       sna->render_state.gen4.last_pipelined_pointers = key;
+       gen4_emit_urb(sna);
+}
+
+static void
+gen4_emit_drawing_rectangle(struct sna *sna, const struct sna_composite_op *op)
+{
+       uint32_t limit = (op->dst.height - 1) << 16 | (op->dst.width - 1);
+       uint32_t offset = (uint16_t)op->dst.y << 16 | (uint16_t)op->dst.x;
+
+       assert(!too_large(op->dst.x, op->dst.y));
+       assert(!too_large(op->dst.width, op->dst.height));
+
+       if (sna->render_state.gen4.drawrect_limit == limit &&
+           sna->render_state.gen4.drawrect_offset == offset)
+               return;
+       sna->render_state.gen4.drawrect_offset = offset;
+       sna->render_state.gen4.drawrect_limit = limit;
+
+       OUT_BATCH(GEN4_3DSTATE_DRAWING_RECTANGLE | (4 - 2));
+       OUT_BATCH(0);
+       OUT_BATCH(limit);
+       OUT_BATCH(offset);
+}
+
+static void
+gen4_emit_vertex_elements(struct sna *sna,
+                         const struct sna_composite_op *op)
+{
+       /*
+        * vertex data in vertex buffer
+        *    position: (x, y)
+        *    texture coordinate 0: (u0, v0) if (is_affine is true) else (u0, v0, w0)
+        *    texture coordinate 1 if (has_mask is true): same as above
+        */
+       struct gen4_render_state *render = &sna->render_state.gen4;
+       bool has_mask = op->mask.bo != NULL;
+       int nelem = has_mask ? 2 : 1;
+       int selem;
+       uint32_t w_component;
+       uint32_t src_format;
+       int id = op->u.gen4.ve_id;
+
+       if (render->ve_id == id)
+               return;
+
+       render->ve_id = id;
+
+       if (op->is_affine) {
+               src_format = GEN4_SURFACEFORMAT_R32G32_FLOAT;
+               w_component = GEN4_VFCOMPONENT_STORE_1_FLT;
+               selem = 2;
+       } else {
+               src_format = GEN4_SURFACEFORMAT_R32G32B32_FLOAT;
+               w_component = GEN4_VFCOMPONENT_STORE_SRC;
+               selem = 3;
+       }
+
+       /* The VUE layout
+        *    dword 0-3: position (x, y, 1.0, 1.0),
+        *    dword 4-7: texture coordinate 0 (u0, v0, w0, 1.0)
+        *    [optional] dword 8-11: texture coordinate 1 (u1, v1, w1, 1.0)
+        */
+       OUT_BATCH(GEN4_3DSTATE_VERTEX_ELEMENTS | (2 * (1 + nelem) - 1));
+
+       /* x,y */
+       OUT_BATCH(id << VE0_VERTEX_BUFFER_INDEX_SHIFT | VE0_VALID |
+                 GEN4_SURFACEFORMAT_R16G16_SSCALED << VE0_FORMAT_SHIFT |
+                 0 << VE0_OFFSET_SHIFT); /* offsets vb in bytes */
+       OUT_BATCH(GEN4_VFCOMPONENT_STORE_SRC << VE1_VFCOMPONENT_0_SHIFT |
+                 GEN4_VFCOMPONENT_STORE_SRC << VE1_VFCOMPONENT_1_SHIFT |
+                 GEN4_VFCOMPONENT_STORE_1_FLT << VE1_VFCOMPONENT_2_SHIFT |
+                 GEN4_VFCOMPONENT_STORE_1_FLT << VE1_VFCOMPONENT_3_SHIFT |
+                 (1*4) << VE1_DESTINATION_ELEMENT_OFFSET_SHIFT);       /* VUE offset in dwords */
+
+       /* u0, v0, w0 */
+       OUT_BATCH(id << VE0_VERTEX_BUFFER_INDEX_SHIFT | VE0_VALID |
+                 src_format << VE0_FORMAT_SHIFT |
+                 4 << VE0_OFFSET_SHIFT);       /* offset vb in bytes */
+       OUT_BATCH(GEN4_VFCOMPONENT_STORE_SRC << VE1_VFCOMPONENT_0_SHIFT |
+                 GEN4_VFCOMPONENT_STORE_SRC << VE1_VFCOMPONENT_1_SHIFT |
+                 w_component << VE1_VFCOMPONENT_2_SHIFT |
+                 GEN4_VFCOMPONENT_STORE_1_FLT << VE1_VFCOMPONENT_3_SHIFT |
+                 (2*4) << VE1_DESTINATION_ELEMENT_OFFSET_SHIFT);       /* VUE offset in dwords */
+
+       /* u1, v1, w1 */
+       if (has_mask) {
+               OUT_BATCH(id << VE0_VERTEX_BUFFER_INDEX_SHIFT | VE0_VALID |
+                         src_format << VE0_FORMAT_SHIFT |
+                         ((1 + selem) * 4) << VE0_OFFSET_SHIFT); /* vb offset in bytes */
+               OUT_BATCH(GEN4_VFCOMPONENT_STORE_SRC << VE1_VFCOMPONENT_0_SHIFT |
+                         GEN4_VFCOMPONENT_STORE_SRC << VE1_VFCOMPONENT_1_SHIFT |
+                         w_component << VE1_VFCOMPONENT_2_SHIFT |
+                         GEN4_VFCOMPONENT_STORE_1_FLT << VE1_VFCOMPONENT_3_SHIFT |
+                         (3*4) << VE1_DESTINATION_ELEMENT_OFFSET_SHIFT);       /* VUE offset in dwords */
+       }
+}
+
+static void
+gen4_emit_state(struct sna *sna,
+               const struct sna_composite_op *op,
+               uint16_t wm_binding_table)
+{
+       if (FLUSH_EVERY_VERTEX)
+               OUT_BATCH(MI_FLUSH | MI_INHIBIT_RENDER_CACHE_FLUSH);
+
+       gen4_emit_drawing_rectangle(sna, op);
+       gen4_emit_binding_table(sna, wm_binding_table);
+       gen4_emit_pipelined_pointers(sna, op, op->op, op->u.gen4.wm_kernel);
+       gen4_emit_vertex_elements(sna, op);
+
+       if (kgem_bo_is_dirty(op->src.bo) || kgem_bo_is_dirty(op->mask.bo)) {
+               DBG(("%s: flushing dirty (%d, %d)\n", __FUNCTION__,
+                    kgem_bo_is_dirty(op->src.bo),
+                    kgem_bo_is_dirty(op->mask.bo)));
+               OUT_BATCH(MI_FLUSH);
+               kgem_clear_dirty(&sna->kgem);
+               kgem_bo_mark_dirty(op->dst.bo);
+       }
+}
+
+static void
+gen4_bind_surfaces(struct sna *sna,
+                  const struct sna_composite_op *op)
+{
+       uint32_t *binding_table;
+       uint16_t offset;
+
+       gen4_get_batch(sna);
+
+       binding_table = gen4_composite_get_binding_table(sna, &offset);
+
+       binding_table[0] =
+               gen4_bind_bo(sna,
+                           op->dst.bo, op->dst.width, op->dst.height,
+                           gen4_get_dest_format(op->dst.format),
+                           true);
+       binding_table[1] =
+               gen4_bind_bo(sna,
+                            op->src.bo, op->src.width, op->src.height,
+                            op->src.card_format,
+                            false);
+       if (op->mask.bo)
+               binding_table[2] =
+                       gen4_bind_bo(sna,
+                                    op->mask.bo,
+                                    op->mask.width,
+                                    op->mask.height,
+                                    op->mask.card_format,
+                                    false);
+
+       if (sna->kgem.surface == offset &&
+           *(uint64_t *)(sna->kgem.batch + sna->render_state.gen4.surface_table) == *(uint64_t*)binding_table &&
+           (op->mask.bo == NULL ||
+            sna->kgem.batch[sna->render_state.gen4.surface_table+2] == binding_table[2])) {
+               sna->kgem.surface += sizeof(struct gen4_surface_state_padded) / sizeof(uint32_t);
+               offset = sna->render_state.gen4.surface_table;
+       }
+
+       gen4_emit_state(sna, op, offset);
+}
+
+fastcall static void
+gen4_render_composite_blt(struct sna *sna,
+                         const struct sna_composite_op *op,
+                         const struct sna_composite_rectangles *r)
+{
+       DBG(("%s: src=(%d, %d)+(%d, %d), mask=(%d, %d)+(%d, %d), dst=(%d, %d)+(%d, %d), size=(%d, %d)\n",
+            __FUNCTION__,
+            r->src.x, r->src.y, op->src.offset[0], op->src.offset[1],
+            r->mask.x, r->mask.y, op->mask.offset[0], op->mask.offset[1],
+            r->dst.x, r->dst.y, op->dst.x, op->dst.y,
+            r->width, r->height));
+
+       gen4_get_rectangles(sna, op, 1, gen4_bind_surfaces);
+       op->prim_emit(sna, op, r);
+
+       /* XXX are the shaders fubar? */
+       FLUSH(op);
+}
+
+fastcall static void
+gen4_render_composite_box(struct sna *sna,
+                         const struct sna_composite_op *op,
+                         const BoxRec *box)
+{
+       struct sna_composite_rectangles r;
+
+       r.dst.x = box->x1;
+       r.dst.y = box->y1;
+       r.width  = box->x2 - box->x1;
+       r.height = box->y2 - box->y1;
+       r.mask = r.src = r.dst;
+
+       gen4_render_composite_blt(sna, op, &r);
+}
+
+static void
+gen4_render_composite_boxes(struct sna *sna,
+                           const struct sna_composite_op *op,
+                           const BoxRec *box, int nbox)
+{
+       DBG(("%s(%d) delta=(%d, %d), src=(%d, %d)/(%d, %d), mask=(%d, %d)/(%d, %d)\n",
+            __FUNCTION__, nbox, op->dst.x, op->dst.y,
+            op->src.offset[0], op->src.offset[1],
+            op->src.width, op->src.height,
+            op->mask.offset[0], op->mask.offset[1],
+            op->mask.width, op->mask.height));
+
+       do {
+               struct sna_composite_rectangles r;
+
+               r.dst.x = box->x1;
+               r.dst.y = box->y1;
+               r.width  = box->x2 - box->x1;
+               r.height = box->y2 - box->y1;
+               r.mask = r.src = r.dst;
+               gen4_render_composite_blt(sna, op, &r);
+               box++;
+       } while (--nbox);
+}
+
+#ifndef MAX
+#define MAX(a,b) ((a) > (b) ? (a) : (b))
+#endif
+
+static uint32_t gen4_bind_video_source(struct sna *sna,
+                                      struct kgem_bo *src_bo,
+                                      uint32_t src_offset,
+                                      int src_width,
+                                      int src_height,
+                                      int src_pitch,
+                                      uint32_t src_surf_format)
+{
+       struct gen4_surface_state *ss;
+
+       sna->kgem.surface -= sizeof(struct gen4_surface_state_padded) / sizeof(uint32_t);
+
+       ss = memset(sna->kgem.batch + sna->kgem.surface, 0, sizeof(*ss));
+       ss->ss0.surface_type = GEN4_SURFACE_2D;
+       ss->ss0.surface_format = src_surf_format;
+       ss->ss0.color_blend = 1;
+
+       ss->ss1.base_addr =
+               kgem_add_reloc(&sna->kgem,
+                              sna->kgem.surface + 1,
+                              src_bo,
+                              I915_GEM_DOMAIN_SAMPLER << 16,
+                              src_offset);
+
+       ss->ss2.width  = src_width - 1;
+       ss->ss2.height = src_height - 1;
+       ss->ss3.pitch  = src_pitch - 1;
+
+       return sna->kgem.surface * sizeof(uint32_t);
+}
+
+static void gen4_video_bind_surfaces(struct sna *sna,
+                                    const struct sna_composite_op *op)
+{
+       struct sna_video_frame *frame = op->priv;
+       uint32_t src_surf_format;
+       uint32_t src_surf_base[6];
+       int src_width[6];
+       int src_height[6];
+       int src_pitch[6];
+       uint32_t *binding_table;
+       uint16_t offset;
+       int n_src, n;
+
+       src_surf_base[0] = 0;
+       src_surf_base[1] = 0;
+       src_surf_base[2] = frame->VBufOffset;
+       src_surf_base[3] = frame->VBufOffset;
+       src_surf_base[4] = frame->UBufOffset;
+       src_surf_base[5] = frame->UBufOffset;
+
+       if (is_planar_fourcc(frame->id)) {
+               src_surf_format = GEN4_SURFACEFORMAT_R8_UNORM;
+               src_width[1]  = src_width[0]  = frame->width;
+               src_height[1] = src_height[0] = frame->height;
+               src_pitch[1]  = src_pitch[0]  = frame->pitch[1];
+               src_width[4]  = src_width[5]  = src_width[2]  = src_width[3] =
+                       frame->width / 2;
+               src_height[4] = src_height[5] = src_height[2] = src_height[3] =
+                       frame->height / 2;
+               src_pitch[4]  = src_pitch[5]  = src_pitch[2]  = src_pitch[3] =
+                       frame->pitch[0];
+               n_src = 6;
+       } else {
+               if (frame->id == FOURCC_UYVY)
+                       src_surf_format = GEN4_SURFACEFORMAT_YCRCB_SWAPY;
+               else
+                       src_surf_format = GEN4_SURFACEFORMAT_YCRCB_NORMAL;
+
+               src_width[0]  = frame->width;
+               src_height[0] = frame->height;
+               src_pitch[0]  = frame->pitch[0];
+               n_src = 1;
+       }
+
+       gen4_get_batch(sna);
+
+       binding_table = gen4_composite_get_binding_table(sna, &offset);
+
+       binding_table[0] =
+               gen4_bind_bo(sna,
+                            op->dst.bo, op->dst.width, op->dst.height,
+                            gen4_get_dest_format(op->dst.format),
+                            true);
+       for (n = 0; n < n_src; n++) {
+               binding_table[1+n] =
+                       gen4_bind_video_source(sna,
+                                              frame->bo,
+                                              src_surf_base[n],
+                                              src_width[n],
+                                              src_height[n],
+                                              src_pitch[n],
+                                              src_surf_format);
+       }
+
+       gen4_emit_state(sna, op, offset);
+}
+
+static bool
+gen4_render_video(struct sna *sna,
+                 struct sna_video *video,
+                 struct sna_video_frame *frame,
+                 RegionPtr dstRegion,
+                 short src_w, short src_h,
+                 short drw_w, short drw_h,
+                 PixmapPtr pixmap)
+{
+       struct sna_composite_op tmp;
+       int nbox, dxo, dyo, pix_xoff, pix_yoff;
+       float src_scale_x, src_scale_y;
+       struct sna_pixmap *priv;
+       BoxPtr box;
+
+       DBG(("%s: %dx%d -> %dx%d\n", __FUNCTION__, src_w, src_h, drw_w, drw_h));
+
+       priv = sna_pixmap_force_to_gpu(pixmap, MOVE_READ | MOVE_WRITE);
+       if (priv == NULL)
+               return false;
+
+       memset(&tmp, 0, sizeof(tmp));
+
+       tmp.op = PictOpSrc;
+       tmp.dst.pixmap = pixmap;
+       tmp.dst.width  = pixmap->drawable.width;
+       tmp.dst.height = pixmap->drawable.height;
+       tmp.dst.format = sna_format_for_depth(pixmap->drawable.depth);
+       tmp.dst.bo = priv->gpu_bo;
+
+       tmp.src.filter = SAMPLER_FILTER_BILINEAR;
+       tmp.src.repeat = SAMPLER_EXTEND_PAD;
+       tmp.src.bo = frame->bo;
+       tmp.mask.bo = NULL;
+       tmp.u.gen4.wm_kernel =
+               is_planar_fourcc(frame->id) ? WM_KERNEL_VIDEO_PLANAR : WM_KERNEL_VIDEO_PACKED;
+       tmp.u.gen4.ve_id = 1;
+       tmp.is_affine = true;
+       tmp.floats_per_vertex = 3;
+       tmp.floats_per_rect = 9;
+       tmp.priv = frame;
+
+       if (!kgem_check_bo(&sna->kgem, tmp.dst.bo, frame->bo, NULL)) {
+               kgem_submit(&sna->kgem);
+               assert(kgem_check_bo(&sna->kgem, tmp.dst.bo, frame->bo, NULL));
+       }
+
+       gen4_video_bind_surfaces(sna, &tmp);
+       gen4_align_vertex(sna, &tmp);
+
+       /* Set up the offset for translating from the given region (in screen
+        * coordinates) to the backing pixmap.
+        */
+#ifdef COMPOSITE
+       pix_xoff = -pixmap->screen_x + pixmap->drawable.x;
+       pix_yoff = -pixmap->screen_y + pixmap->drawable.y;
+#else
+       pix_xoff = 0;
+       pix_yoff = 0;
+#endif
+
+       dxo = dstRegion->extents.x1;
+       dyo = dstRegion->extents.y1;
+
+       /* Use normalized texture coordinates */
+       src_scale_x = ((float)src_w / frame->width) / (float)drw_w;
+       src_scale_y = ((float)src_h / frame->height) / (float)drw_h;
+
+       box = REGION_RECTS(dstRegion);
+       nbox = REGION_NUM_RECTS(dstRegion);
+       while (nbox--) {
+               BoxRec r;
+
+               r.x1 = box->x1 + pix_xoff;
+               r.x2 = box->x2 + pix_xoff;
+               r.y1 = box->y1 + pix_yoff;
+               r.y2 = box->y2 + pix_yoff;
+
+               gen4_get_rectangles(sna, &tmp, 1, gen4_video_bind_surfaces);
+
+               OUT_VERTEX(r.x2, r.y2);
+               OUT_VERTEX_F((box->x2 - dxo) * src_scale_x);
+               OUT_VERTEX_F((box->y2 - dyo) * src_scale_y);
+
+               OUT_VERTEX(r.x1, r.y2);
+               OUT_VERTEX_F((box->x1 - dxo) * src_scale_x);
+               OUT_VERTEX_F((box->y2 - dyo) * src_scale_y);
+
+               OUT_VERTEX(r.x1, r.y1);
+               OUT_VERTEX_F((box->x1 - dxo) * src_scale_x);
+               OUT_VERTEX_F((box->y1 - dyo) * src_scale_y);
+
+               _FLUSH();
+
+               if (!DAMAGE_IS_ALL(priv->gpu_damage)) {
+                       sna_damage_add_box(&priv->gpu_damage, &r);
+                       sna_damage_subtract_box(&priv->cpu_damage, &r);
+               }
+               box++;
+       }
+       priv->clear = false;
+
+       gen4_vertex_flush(sna);
+       return true;
+}
+
+static bool
+gen4_composite_solid_init(struct sna *sna,
+                         struct sna_composite_channel *channel,
+                         uint32_t color)
+{
+       channel->filter = PictFilterNearest;
+       channel->repeat = RepeatNormal;
+       channel->is_affine = true;
+       channel->is_solid  = true;
+       channel->transform = NULL;
+       channel->width  = 1;
+       channel->height = 1;
+       channel->card_format = GEN4_SURFACEFORMAT_B8G8R8A8_UNORM;
+
+       channel->bo = sna_render_get_solid(sna, color);
+
+       channel->scale[0]  = channel->scale[1]  = 1;
+       channel->offset[0] = channel->offset[1] = 0;
+       return channel->bo != NULL;
+}
+
+static bool
+gen4_composite_linear_init(struct sna *sna,
+                          PicturePtr picture,
+                          struct sna_composite_channel *channel,
+                          int x, int y,
+                          int w, int h,
+                          int dst_x, int dst_y)
+{
+       PictLinearGradient *linear =
+               (PictLinearGradient *)picture->pSourcePict;
+       pixman_fixed_t tx, ty;
+       float x0, y0, sf;
+       float dx, dy;
+
+       DBG(("%s: p1=(%f, %f), p2=(%f, %f), src=(%d, %d), dst=(%d, %d), size=(%d, %d)\n",
+            __FUNCTION__,
+            pixman_fixed_to_double(linear->p1.x), pixman_fixed_to_double(linear->p1.y),
+            pixman_fixed_to_double(linear->p2.x), pixman_fixed_to_double(linear->p2.y),
+            x, y, dst_x, dst_y, w, h));
+
+       if (linear->p2.x == linear->p1.x && linear->p2.y == linear->p1.y)
+               return 0;
+
+       if (!sna_transform_is_affine(picture->transform)) {
+               DBG(("%s: fallback due to projective transform\n",
+                    __FUNCTION__));
+               return sna_render_picture_fixup(sna, picture, channel,
+                                               x, y, w, h, dst_x, dst_y);
+       }
+
+       channel->bo = sna_render_get_gradient(sna, (PictGradient *)linear);
+       if (!channel->bo)
+               return 0;
+
+       channel->filter = PictFilterNearest;
+       channel->repeat = picture->repeat ? picture->repeatType : RepeatNone;
+       channel->width  = channel->bo->pitch / 4;
+       channel->height = 1;
+       channel->pict_format = PICT_a8r8g8b8;
+
+       channel->scale[0]  = channel->scale[1]  = 1;
+       channel->offset[0] = channel->offset[1] = 0;
+
+       if (sna_transform_is_translation(picture->transform, &tx, &ty)) {
+               dx = pixman_fixed_to_double(linear->p2.x - linear->p1.x);
+               dy = pixman_fixed_to_double(linear->p2.y - linear->p1.y);
+
+               x0 = pixman_fixed_to_double(linear->p1.x);
+               y0 = pixman_fixed_to_double(linear->p1.y);
+
+               if (tx | ty) {
+                       x0 -= pixman_fixed_to_double(tx);
+                       y0 -= pixman_fixed_to_double(ty);
+               }
+       } else {
+               struct pixman_f_vector p1, p2;
+               struct pixman_f_transform m, inv;
+
+               pixman_f_transform_from_pixman_transform(&m, picture->transform);
+               DBG(("%s: transform = [%f %f %f, %f %f %f, %f %f %f]\n",
+                    __FUNCTION__,
+                    m.m[0][0], m.m[0][1], m.m[0][2],
+                    m.m[1][0], m.m[1][1], m.m[1][2],
+                    m.m[2][0], m.m[2][1], m.m[2][2]));
+               if (!pixman_f_transform_invert(&inv, &m))
+                       return 0;
+
+               p1.v[0] = pixman_fixed_to_double(linear->p1.x);
+               p1.v[1] = pixman_fixed_to_double(linear->p1.y);
+               p1.v[2] = 1.;
+               pixman_f_transform_point(&inv, &p1);
+
+               p2.v[0] = pixman_fixed_to_double(linear->p2.x);
+               p2.v[1] = pixman_fixed_to_double(linear->p2.y);
+               p2.v[2] = 1.;
+               pixman_f_transform_point(&inv, &p2);
+
+               DBG(("%s: untransformed: p1=(%f, %f, %f), p2=(%f, %f, %f)\n",
+                    __FUNCTION__,
+                    p1.v[0], p1.v[1], p1.v[2],
+                    p2.v[0], p2.v[1], p2.v[2]));
+
+               dx = p2.v[0] - p1.v[0];
+               dy = p2.v[1] - p1.v[1];
+
+               x0 = p1.v[0];
+               y0 = p1.v[1];
+       }
+
+       sf = dx*dx + dy*dy;
+       dx /= sf;
+       dy /= sf;
+
+       channel->embedded_transform.matrix[0][0] = pixman_double_to_fixed(dx);
+       channel->embedded_transform.matrix[0][1] = pixman_double_to_fixed(dy);
+       channel->embedded_transform.matrix[0][2] = -pixman_double_to_fixed(dx*(x0+dst_x-x) + dy*(y0+dst_y-y));
+
+       channel->embedded_transform.matrix[1][0] = 0;
+       channel->embedded_transform.matrix[1][1] = 0;
+       channel->embedded_transform.matrix[1][2] = pixman_double_to_fixed(.5);
+
+       channel->embedded_transform.matrix[2][0] = 0;
+       channel->embedded_transform.matrix[2][1] = 0;
+       channel->embedded_transform.matrix[2][2] = pixman_fixed_1;
+
+       channel->transform = &channel->embedded_transform;
+       channel->is_affine = 1;
+
+       DBG(("%s: dx=%f, dy=%f, offset=%f\n",
+            __FUNCTION__, dx, dy, -dx*(x0-x+dst_x) + -dy*(y0-y+dst_y)));
+
+       return channel->bo != NULL;
+}
+
+static int
+gen4_composite_picture(struct sna *sna,
+                      PicturePtr picture,
+                      struct sna_composite_channel *channel,
+                      int x, int y,
+                      int w, int h,
+                      int dst_x, int dst_y,
+                      bool precise)
+{
+       PixmapPtr pixmap;
+       uint32_t color;
+       int16_t dx, dy;
+
+       DBG(("%s: (%d, %d)x(%d, %d), dst=(%d, %d)\n",
+            __FUNCTION__, x, y, w, h, dst_x, dst_y));
+
+       channel->is_solid = false;
+       channel->card_format = -1;
+
+       if (sna_picture_is_solid(picture, &color))
+               return gen4_composite_solid_init(sna, channel, color);
+
+       if (picture->pDrawable == NULL) {
+               int ret;
+
+               if (picture->pSourcePict->type == SourcePictTypeLinear)
+                       return gen4_composite_linear_init(sna, picture, channel,
+                                                         x, y,
+                                                         w, h,
+                                                         dst_x, dst_y);
+
+               DBG(("%s -- fixup, gradient\n", __FUNCTION__));
+               ret = -1;
+               if (!precise)
+                       ret = sna_render_picture_approximate_gradient(sna, picture, channel,
+                                                                     x, y, w, h, dst_x, dst_y);
+               if (ret == -1)
+                       ret = sna_render_picture_fixup(sna, picture, channel,
+                                                      x, y, w, h, dst_x, dst_y);
+               return ret;
+       }
+
+       if (picture->alphaMap) {
+               DBG(("%s -- fallback, alphamap\n", __FUNCTION__));
+               return sna_render_picture_fixup(sna, picture, channel,
+                                               x, y, w, h, dst_x, dst_y);
+       }
+
+       if (!gen4_check_repeat(picture)) {
+               DBG(("%s: unknown repeat mode fixup\n", __FUNCTION__));
+               return sna_render_picture_fixup(sna, picture, channel,
+                                               x, y, w, h, dst_x, dst_y);
+       }
+
+       if (!gen4_check_filter(picture)) {
+               DBG(("%s: unhandled filter fixup\n", __FUNCTION__));
+               return sna_render_picture_fixup(sna, picture, channel,
+                                               x, y, w, h, dst_x, dst_y);
+       }
+
+       channel->repeat = picture->repeat ? picture->repeatType : RepeatNone;
+       channel->filter = picture->filter;
+
+       pixmap = get_drawable_pixmap(picture->pDrawable);
+       get_drawable_deltas(picture->pDrawable, pixmap, &dx, &dy);
+
+       x += dx + picture->pDrawable->x;
+       y += dy + picture->pDrawable->y;
+
+       channel->is_affine = sna_transform_is_affine(picture->transform);
+       if (sna_transform_is_integer_translation(picture->transform, &dx, &dy)) {
+               DBG(("%s: integer translation (%d, %d), removing\n",
+                    __FUNCTION__, dx, dy));
+               x += dx;
+               y += dy;
+               channel->transform = NULL;
+               channel->filter = PictFilterNearest;
+       } else
+               channel->transform = picture->transform;
+
+       channel->pict_format = picture->format;
+       channel->card_format = gen4_get_card_format(picture->format);
+       if (channel->card_format == -1)
+               return sna_render_picture_convert(sna, picture, channel, pixmap,
+                                                 x, y, w, h, dst_x, dst_y);
+
+       if (too_large(pixmap->drawable.width, pixmap->drawable.height))
+               return sna_render_picture_extract(sna, picture, channel,
+                                                 x, y, w, h, dst_x, dst_y);
+
+       return sna_render_pixmap_bo(sna, channel, pixmap,
+                                   x, y, w, h, dst_x, dst_y);
+}
+
+static void gen4_composite_channel_convert(struct sna_composite_channel *channel)
+{
+       DBG(("%s: repeat %d -> %d, filter %d -> %d\n",
+            __FUNCTION__,
+            channel->repeat, gen4_repeat(channel->repeat),
+            channel->filter, gen4_repeat(channel->filter)));
+       channel->repeat = gen4_repeat(channel->repeat);
+       channel->filter = gen4_filter(channel->filter);
+       if (channel->card_format == (unsigned)-1)
+               channel->card_format = gen4_get_card_format(channel->pict_format);
+}
+
+static void
+gen4_render_composite_done(struct sna *sna,
+                          const struct sna_composite_op *op)
+{
+       DBG(("%s()\n", __FUNCTION__));
+
+       if (sna->render_state.gen4.vertex_offset) {
+               gen4_vertex_flush(sna);
+               gen4_magic_ca_pass(sna, op);
+       }
+
+       if (op->mask.bo)
+               kgem_bo_destroy(&sna->kgem, op->mask.bo);
+       if (op->src.bo)
+               kgem_bo_destroy(&sna->kgem, op->src.bo);
+
+       sna_render_composite_redirect_done(sna, op);
+}
+
+static bool
+gen4_composite_set_target(PicturePtr dst, struct sna_composite_op *op)
+{
+       struct sna_pixmap *priv;
+
+       if (!gen4_check_dst_format(dst->format)) {
+               DBG(("%s: incompatible render target format %08x\n",
+                    __FUNCTION__, dst->format));
+               return false;
+       }
+
+       op->dst.pixmap = get_drawable_pixmap(dst->pDrawable);
+       op->dst.width  = op->dst.pixmap->drawable.width;
+       op->dst.height = op->dst.pixmap->drawable.height;
+       op->dst.format = dst->format;
+       priv = sna_pixmap_force_to_gpu(op->dst.pixmap, MOVE_READ | MOVE_WRITE);
+       if (priv == NULL)
+               return false;
+
+       op->dst.bo = priv->gpu_bo;
+       op->damage = &priv->gpu_damage;
+       if (sna_damage_is_all(&priv->gpu_damage, op->dst.width, op->dst.height))
+               op->damage = NULL;
+       DBG(("%s: all-damaged=%d, damage=%p\n", __FUNCTION__,
+            sna_damage_is_all(&priv->gpu_damage, op->dst.width, op->dst.height),
+           op->damage));
+
+       get_drawable_deltas(dst->pDrawable, op->dst.pixmap,
+                           &op->dst.x, &op->dst.y);
+       return true;
+}
+
+static inline bool
+picture_is_cpu(PicturePtr picture)
+{
+       if (!picture->pDrawable)
+               return false;
+
+       return !is_gpu(picture->pDrawable);
+}
+
+static inline bool prefer_blt(struct sna *sna)
+{
+#if PREFER_BLT
+       return true;
+       (void)sna;
+#else
+       return sna->kgem.mode != KGEM_RENDER;
+#endif
+}
+
+static bool
+try_blt(struct sna *sna,
+       PicturePtr dst, PicturePtr src,
+       int width, int height)
+{
+       if (prefer_blt(sna)) {
+               DBG(("%s: already performing BLT\n", __FUNCTION__));
+               return true;
+       }
+
+       if (too_large(width, height)) {
+               DBG(("%s: operation too large for 3D pipe (%d, %d)\n",
+                    __FUNCTION__, width, height));
+               return true;
+       }
+
+       if (too_large(dst->pDrawable->width, dst->pDrawable->height))
+               return true;
+
+       /* The blitter is much faster for solids */
+       if (sna_picture_is_solid(src, NULL))
+               return true;
+
+       /* is the source picture only in cpu memory e.g. a shm pixmap? */
+       return picture_is_cpu(src);
+}
+
+static bool
+check_gradient(PicturePtr picture)
+{
+       switch (picture->pSourcePict->type) {
+       case SourcePictTypeSolidFill:
+       case SourcePictTypeLinear:
+               return false;
+       default:
+               return true;
+       }
+}
+
+static bool
+has_alphamap(PicturePtr p)
+{
+       return p->alphaMap != NULL;
+}
+
+static bool
+untransformed(PicturePtr p)
+{
+       return !p->transform || pixman_transform_is_int_translate(p->transform);
+}
+
+static bool
+need_upload(PicturePtr p)
+{
+       return p->pDrawable && untransformed(p) && !is_gpu(p->pDrawable);
+}
+
+static bool
+source_is_busy(PixmapPtr pixmap)
+{
+       struct sna_pixmap *priv = sna_pixmap(pixmap);
+       if (priv == NULL)
+               return false;
+
+       if (priv->clear)
+               return false;
+
+       if (priv->gpu_bo && kgem_bo_is_busy(priv->gpu_bo))
+               return true;
+
+       return priv->gpu_damage && !priv->cpu_damage;
+}
+
+static bool
+source_fallback(PicturePtr p, PixmapPtr pixmap)
+{
+       if (sna_picture_is_solid(p, NULL))
+               return false;
+
+       if (p->pSourcePict)
+               return check_gradient(p);
+
+       if (!gen4_check_repeat(p) || !gen4_check_format(p->format))
+               return true;
+
+       /* soft errors: perfer to upload/compute rather than readback */
+       if (pixmap && source_is_busy(pixmap))
+               return false;
+
+       return has_alphamap(p) || !gen4_check_filter(p) || need_upload(p);
+}
+
+static bool
+gen4_composite_fallback(struct sna *sna,
+                       PicturePtr src,
+                       PicturePtr mask,
+                       PicturePtr dst)
+{
+       struct sna_pixmap *priv;
+       PixmapPtr src_pixmap;
+       PixmapPtr mask_pixmap;
+       PixmapPtr dst_pixmap;
+       bool src_fallback, mask_fallback;
+
+       if (!gen4_check_dst_format(dst->format)) {
+               DBG(("%s: unknown destination format: %d\n",
+                    __FUNCTION__, dst->format));
+               return true;
+       }
+
+       dst_pixmap = get_drawable_pixmap(dst->pDrawable);
+
+       src_pixmap = src->pDrawable ? get_drawable_pixmap(src->pDrawable) : NULL;
+       src_fallback = source_fallback(src, src_pixmap);
+
+       if (mask) {
+               mask_pixmap = mask->pDrawable ? get_drawable_pixmap(mask->pDrawable) : NULL;
+               mask_fallback = source_fallback(mask, mask_pixmap);
+       } else {
+               mask_pixmap = NULL;
+               mask_fallback = false;
+       }
+
+       /* If we are using the destination as a source and need to
+        * readback in order to upload the source, do it all
+        * on the cpu.
+        */
+       if (src_pixmap == dst_pixmap && src_fallback) {
+               DBG(("%s: src is dst and will fallback\n",__FUNCTION__));
+               return true;
+       }
+       if (mask_pixmap == dst_pixmap && mask_fallback) {
+               DBG(("%s: mask is dst and will fallback\n",__FUNCTION__));
+               return true;
+       }
+
+       /* If anything is on the GPU, push everything out to the GPU */
+       priv = sna_pixmap(dst_pixmap);
+       if (priv && priv->gpu_damage && !priv->clear) {
+               DBG(("%s: dst is already on the GPU, try to use GPU\n",
+                    __FUNCTION__));
+               return false;
+       }
+
+       if (src_pixmap && !src_fallback) {
+               DBG(("%s: src is already on the GPU, try to use GPU\n",
+                    __FUNCTION__));
+               return false;
+       }
+       if (mask_pixmap && !mask_fallback) {
+               DBG(("%s: mask is already on the GPU, try to use GPU\n",
+                    __FUNCTION__));
+               return false;
+       }
+
+       /* However if the dst is not on the GPU and we need to
+        * render one of the sources using the CPU, we may
+        * as well do the entire operation in place onthe CPU.
+        */
+       if (src_fallback) {
+               DBG(("%s: dst is on the CPU and src will fallback\n",
+                    __FUNCTION__));
+               return true;
+       }
+
+       if (mask_fallback) {
+               DBG(("%s: dst is on the CPU and mask will fallback\n",
+                    __FUNCTION__));
+               return true;
+       }
+
+       if (too_large(dst_pixmap->drawable.width,
+                     dst_pixmap->drawable.height) &&
+           (priv == NULL || DAMAGE_IS_ALL(priv->cpu_damage))) {
+               DBG(("%s: dst is on the CPU and too large\n", __FUNCTION__));
+               return true;
+       }
+
+       DBG(("%s: dst is not on the GPU and the operation should not fallback\n",
+            __FUNCTION__));
+       return false;
+}
+
+static int
+reuse_source(struct sna *sna,
+            PicturePtr src, struct sna_composite_channel *sc, int src_x, int src_y,
+            PicturePtr mask, struct sna_composite_channel *mc, int msk_x, int msk_y)
+{
+       uint32_t color;
+
+       if (src_x != msk_x || src_y != msk_y)
+               return false;
+
+       if (src == mask) {
+               DBG(("%s: mask is source\n", __FUNCTION__));
+               *mc = *sc;
+               mc->bo = kgem_bo_reference(mc->bo);
+               return true;
+       }
+
+       if (sna_picture_is_solid(mask, &color))
+               return gen4_composite_solid_init(sna, mc, color);
+
+       if (sc->is_solid)
+               return false;
+
+       if (src->pDrawable == NULL || mask->pDrawable != src->pDrawable)
+               return false;
+
+       DBG(("%s: mask reuses source drawable\n", __FUNCTION__));
+
+       if (!sna_transform_equal(src->transform, mask->transform))
+               return false;
+
+       if (!sna_picture_alphamap_equal(src, mask))
+               return false;
+
+       if (!gen4_check_repeat(mask))
+               return false;
+
+       if (!gen4_check_filter(mask))
+               return false;
+
+       if (!gen4_check_format(mask->format))
+               return false;
+
+       DBG(("%s: reusing source channel for mask with a twist\n",
+            __FUNCTION__));
+
+       *mc = *sc;
+       mc->repeat = gen4_repeat(mask->repeat ? mask->repeatType : RepeatNone);
+       mc->filter = gen4_filter(mask->filter);
+       mc->pict_format = mask->format;
+       mc->card_format = gen4_get_card_format(mask->format);
+       mc->bo = kgem_bo_reference(mc->bo);
+       return true;
+}
+
+static bool
+gen4_render_composite(struct sna *sna,
+                     uint8_t op,
+                     PicturePtr src,
+                     PicturePtr mask,
+                     PicturePtr dst,
+                     int16_t src_x, int16_t src_y,
+                     int16_t msk_x, int16_t msk_y,
+                     int16_t dst_x, int16_t dst_y,
+                     int16_t width, int16_t height,
+                     struct sna_composite_op *tmp)
+{
+       DBG(("%s: %dx%d, current mode=%d\n", __FUNCTION__,
+            width, height, sna->kgem.mode));
+
+       if (op >= ARRAY_SIZE(gen4_blend_op))
+               return false;
+
+       if (mask == NULL &&
+           try_blt(sna, dst, src, width, height) &&
+           sna_blt_composite(sna, op,
+                             src, dst,
+                             src_x, src_y,
+                             dst_x, dst_y,
+                             width, height,
+                             tmp, false))
+               return true;
+
+       if (gen4_composite_fallback(sna, src, mask, dst))
+               return false;
+
+       if (need_tiling(sna, width, height))
+               return sna_tiling_composite(op, src, mask, dst,
+                                           src_x, src_y,
+                                           msk_x, msk_y,
+                                           dst_x, dst_y,
+                                           width, height,
+                                           tmp);
+
+       if (!gen4_composite_set_target(dst, tmp))
+               return false;
+       sna_render_reduce_damage(tmp, dst_x, dst_y, width, height);
+
+       if (too_large(tmp->dst.width, tmp->dst.height) &&
+           !sna_render_composite_redirect(sna, tmp,
+                                          dst_x, dst_y, width, height))
+               return false;
+
+       switch (gen4_composite_picture(sna, src, &tmp->src,
+                                      src_x, src_y,
+                                      width, height,
+                                      dst_x, dst_y,
+                                      dst->polyMode == PolyModePrecise)) {
+       case -1:
+               DBG(("%s: failed to prepare source\n", __FUNCTION__));
+               goto cleanup_dst;
+       case 0:
+               if (!gen4_composite_solid_init(sna, &tmp->src, 0))
+                       goto cleanup_dst;
+               /* fall through to fixup */
+       case 1:
+               if (mask == NULL &&
+                   sna_blt_composite__convert(sna,
+                                              dst_x, dst_y, width, height,
+                                              tmp))
+                       return true;
+
+               gen4_composite_channel_convert(&tmp->src);
+               break;
+       }
+
+       tmp->op = op;
+       tmp->is_affine = tmp->src.is_affine;
+       tmp->has_component_alpha = false;
+       tmp->need_magic_ca_pass = false;
+
+       tmp->prim_emit = gen4_emit_composite_primitive;
+       if (mask) {
+               if (mask->componentAlpha && PICT_FORMAT_RGB(mask->format)) {
+                       tmp->has_component_alpha = true;
+
+                       /* Check if it's component alpha that relies on a source alpha and on
+                        * the source value.  We can only get one of those into the single
+                        * source value that we get to blend with.
+                        */
+                       if (gen4_blend_op[op].src_alpha &&
+                           (gen4_blend_op[op].src_blend != GEN4_BLENDFACTOR_ZERO)) {
+                               if (op != PictOpOver) {
+                                       DBG(("%s -- fallback: unhandled component alpha blend\n",
+                                            __FUNCTION__));
+
+                                       goto cleanup_src;
+                               }
+
+                               tmp->need_magic_ca_pass = true;
+                               tmp->op = PictOpOutReverse;
+                       }
+               }
+
+               if (!reuse_source(sna,
+                                 src, &tmp->src, src_x, src_y,
+                                 mask, &tmp->mask, msk_x, msk_y)) {
+                       switch (gen4_composite_picture(sna, mask, &tmp->mask,
+                                                      msk_x, msk_y,
+                                                      width, height,
+                                                      dst_x, dst_y,
+                                                      dst->polyMode == PolyModePrecise)) {
+                       case -1:
+                               DBG(("%s: failed to prepare mask\n", __FUNCTION__));
+                               goto cleanup_src;
+                       case 0:
+                               if (!gen4_composite_solid_init(sna, &tmp->mask, 0))
+                                       goto cleanup_src;
+                               /* fall through to fixup */
+                       case 1:
+                               gen4_composite_channel_convert(&tmp->mask);
+                               break;
+                       }
+               }
+
+               tmp->is_affine &= tmp->mask.is_affine;
+
+               if (tmp->src.transform == NULL && tmp->mask.transform == NULL)
+                       tmp->prim_emit = gen4_emit_composite_primitive_identity_source_mask;
+
+               tmp->floats_per_vertex = 5 + 2 * !tmp->is_affine;
+       } else {
+               if (tmp->src.is_solid)
+                       tmp->prim_emit = gen4_emit_composite_primitive_solid;
+               else if (tmp->src.transform == NULL)
+                       tmp->prim_emit = gen4_emit_composite_primitive_identity_source;
+               else if (tmp->src.is_affine)
+                       tmp->prim_emit = gen4_emit_composite_primitive_affine_source;
+
+               tmp->floats_per_vertex = 3 + !tmp->is_affine;
+       }
+       tmp->floats_per_rect = 3*tmp->floats_per_vertex;
+
+       tmp->u.gen4.wm_kernel =
+               gen4_choose_composite_kernel(tmp->op,
+                                            tmp->mask.bo != NULL,
+                                            tmp->has_component_alpha,
+                                            tmp->is_affine);
+       tmp->u.gen4.ve_id = (tmp->mask.bo != NULL) << 1 | tmp->is_affine;
+
+       tmp->blt   = gen4_render_composite_blt;
+       tmp->box   = gen4_render_composite_box;
+       tmp->boxes = gen4_render_composite_boxes;
+       tmp->done  = gen4_render_composite_done;
+
+       if (!kgem_check_bo(&sna->kgem,
+                          tmp->dst.bo, tmp->src.bo, tmp->mask.bo,
+                          NULL)) {
+               kgem_submit(&sna->kgem);
+               if (!kgem_check_bo(&sna->kgem,
+                                    tmp->dst.bo, tmp->src.bo, tmp->mask.bo,
+                                    NULL))
+                       goto cleanup_mask;
+       }
+
+       gen4_bind_surfaces(sna, tmp);
+       gen4_align_vertex(sna, tmp);
+       return true;
+
+cleanup_mask:
+       if (tmp->mask.bo)
+               kgem_bo_destroy(&sna->kgem, tmp->mask.bo);
+cleanup_src:
+       if (tmp->src.bo)
+               kgem_bo_destroy(&sna->kgem, tmp->src.bo);
+cleanup_dst:
+       if (tmp->redirect.real_bo)
+               kgem_bo_destroy(&sna->kgem, tmp->dst.bo);
+       return false;
+}
+
+/* A poor man's span interface. But better than nothing? */
+#if !NO_COMPOSITE_SPANS
+inline static void
+gen4_emit_composite_texcoord(struct sna *sna,
+                            const struct sna_composite_channel *channel,
+                            int16_t x, int16_t y)
+{
+       float t[3];
+
+       if (channel->is_affine) {
+               sna_get_transformed_coordinates(x + channel->offset[0],
+                                               y + channel->offset[1],
+                                               channel->transform,
+                                               &t[0], &t[1]);
+               OUT_VERTEX_F(t[0] * channel->scale[0]);
+               OUT_VERTEX_F(t[1] * channel->scale[1]);
+       } else {
+               t[0] = t[1] = 0; t[2] = 1;
+               sna_get_transformed_coordinates_3d(x + channel->offset[0],
+                                                  y + channel->offset[1],
+                                                  channel->transform,
+                                                  &t[0], &t[1], &t[2]);
+               OUT_VERTEX_F(t[0] * channel->scale[0]);
+               OUT_VERTEX_F(t[1] * channel->scale[1]);
+               OUT_VERTEX_F(t[2]);
+       }
+}
+
+inline static void
+gen4_emit_composite_texcoord_affine(struct sna *sna,
+                                   const struct sna_composite_channel *channel,
+                                   int16_t x, int16_t y)
+{
+       float t[2];
+
+       sna_get_transformed_coordinates(x + channel->offset[0],
+                                       y + channel->offset[1],
+                                       channel->transform,
+                                       &t[0], &t[1]);
+       OUT_VERTEX_F(t[0] * channel->scale[0]);
+       OUT_VERTEX_F(t[1] * channel->scale[1]);
+}
+
+inline static void
+gen4_emit_composite_spans_vertex(struct sna *sna,
+                                const struct sna_composite_spans_op *op,
+                                int16_t x, int16_t y)
+{
+       OUT_VERTEX(x, y);
+       gen4_emit_composite_texcoord(sna, &op->base.src, x, y);
+}
+
+fastcall static void
+gen4_emit_composite_spans_primitive(struct sna *sna,
+                                   const struct sna_composite_spans_op *op,
+                                   const BoxRec *box,
+                                   float opacity)
+{
+       gen4_emit_composite_spans_vertex(sna, op, box->x2, box->y2);
+       OUT_VERTEX_F(opacity);
+       OUT_VERTEX_F(1);
+       if (!op->base.is_affine)
+               OUT_VERTEX_F(1);
+
+       gen4_emit_composite_spans_vertex(sna, op, box->x1, box->y2);
+       OUT_VERTEX_F(opacity);
+       OUT_VERTEX_F(1);
+       if (!op->base.is_affine)
+               OUT_VERTEX_F(1);
+
+       gen4_emit_composite_spans_vertex(sna, op, box->x1, box->y1);
+       OUT_VERTEX_F(opacity);
+       OUT_VERTEX_F(0);
+       if (!op->base.is_affine)
+               OUT_VERTEX_F(1);
+}
+
+fastcall static void
+gen4_emit_composite_spans_solid(struct sna *sna,
+                               const struct sna_composite_spans_op *op,
+                               const BoxRec *box,
+                               float opacity)
+{
+       OUT_VERTEX(box->x2, box->y2);
+       OUT_VERTEX_F(1); OUT_VERTEX_F(1);
+       OUT_VERTEX_F(opacity); OUT_VERTEX_F(1);
+
+       OUT_VERTEX(box->x1, box->y2);
+       OUT_VERTEX_F(0); OUT_VERTEX_F(1);
+       OUT_VERTEX_F(opacity); OUT_VERTEX_F(1);
+
+       OUT_VERTEX(box->x1, box->y1);
+       OUT_VERTEX_F(0); OUT_VERTEX_F(0);
+       OUT_VERTEX_F(opacity); OUT_VERTEX_F(0);
+}
+
+fastcall static void
+gen4_emit_composite_spans_affine(struct sna *sna,
+                                const struct sna_composite_spans_op *op,
+                                const BoxRec *box,
+                                float opacity)
+{
+       OUT_VERTEX(box->x2, box->y2);
+       gen4_emit_composite_texcoord_affine(sna, &op->base.src,
+                                           box->x2, box->y2);
+       OUT_VERTEX_F(opacity);
+       OUT_VERTEX_F(1);
+
+       OUT_VERTEX(box->x1, box->y2);
+       gen4_emit_composite_texcoord_affine(sna, &op->base.src,
+                                           box->x1, box->y2);
+       OUT_VERTEX_F(opacity);
+       OUT_VERTEX_F(1);
+
+       OUT_VERTEX(box->x1, box->y1);
+       gen4_emit_composite_texcoord_affine(sna, &op->base.src,
+                                           box->x1, box->y1);
+       OUT_VERTEX_F(opacity);
+       OUT_VERTEX_F(0);
+}
+
+fastcall static void
+gen4_render_composite_spans_box(struct sna *sna,
+                               const struct sna_composite_spans_op *op,
+                               const BoxRec *box, float opacity)
+{
+       DBG(("%s: src=+(%d, %d), opacity=%f, dst=+(%d, %d), box=(%d, %d) x (%d, %d)\n",
+            __FUNCTION__,
+            op->base.src.offset[0], op->base.src.offset[1],
+            opacity,
+            op->base.dst.x, op->base.dst.y,
+            box->x1, box->y1,
+            box->x2 - box->x1,
+            box->y2 - box->y1));
+
+       gen4_get_rectangles(sna, &op->base, 1, gen4_bind_surfaces);
+       op->prim_emit(sna, op, box, opacity);
+}
+
+static void
+gen4_render_composite_spans_boxes(struct sna *sna,
+                                 const struct sna_composite_spans_op *op,
+                                 const BoxRec *box, int nbox,
+                                 float opacity)
+{
+       DBG(("%s: nbox=%d, src=+(%d, %d), opacity=%f, dst=+(%d, %d)\n",
+            __FUNCTION__, nbox,
+            op->base.src.offset[0], op->base.src.offset[1],
+            opacity,
+            op->base.dst.x, op->base.dst.y));
+
+       do {
+               gen4_render_composite_spans_box(sna, op, box++, opacity);
+       } while (--nbox);
+}
+
+fastcall static void
+gen4_render_composite_spans_done(struct sna *sna,
+                                const struct sna_composite_spans_op *op)
+{
+       gen4_vertex_flush(sna);
+
+       DBG(("%s()\n", __FUNCTION__));
+
+       kgem_bo_destroy(&sna->kgem, op->base.mask.bo);
+       if (op->base.src.bo)
+               kgem_bo_destroy(&sna->kgem, op->base.src.bo);
+
+       sna_render_composite_redirect_done(sna, &op->base);
+}
+
+static bool
+gen4_check_composite_spans(struct sna *sna,
+                          uint8_t op, PicturePtr src, PicturePtr dst,
+                          int16_t width, int16_t height,
+                          unsigned flags)
+{
+       if ((flags & COMPOSITE_SPANS_RECTILINEAR) == 0)
+               return false;
+
+       if (op >= ARRAY_SIZE(gen4_blend_op))
+               return false;
+
+       if (gen4_composite_fallback(sna, src, NULL, dst))
+               return false;
+
+       if (need_tiling(sna, width, height) && !is_gpu(dst->pDrawable))
+               return false;
+
+       return true;
+}
+
+static bool
+gen4_render_composite_spans(struct sna *sna,
+                           uint8_t op,
+                           PicturePtr src,
+                           PicturePtr dst,
+                           int16_t src_x,  int16_t src_y,
+                           int16_t dst_x,  int16_t dst_y,
+                           int16_t width,  int16_t height,
+                           unsigned flags,
+                           struct sna_composite_spans_op *tmp)
+{
+       DBG(("%s: %dx%d with flags=%x, current mode=%d\n", __FUNCTION__,
+            width, height, flags, sna->kgem.ring));
+
+       assert(gen4_check_composite_spans(sna, op, src, dst, width, height, flags));
+
+       if (need_tiling(sna, width, height)) {
+               DBG(("%s: tiling, operation (%dx%d) too wide for pipeline\n",
+                    __FUNCTION__, width, height));
+               return sna_tiling_composite_spans(op, src, dst,
+                                                 src_x, src_y, dst_x, dst_y,
+                                                 width, height, flags, tmp);
+       }
+
+       tmp->base.op = op;
+       if (!gen4_composite_set_target(dst, &tmp->base))
+               return false;
+       sna_render_reduce_damage(&tmp->base, dst_x, dst_y, width, height);
+
+       if (too_large(tmp->base.dst.width, tmp->base.dst.height)) {
+               if (!sna_render_composite_redirect(sna, &tmp->base,
+                                                  dst_x, dst_y, width, height))
+                       return false;
+       }
+
+       switch (gen4_composite_picture(sna, src, &tmp->base.src,
+                                      src_x, src_y,
+                                      width, height,
+                                      dst_x, dst_y,
+                                      dst->polyMode == PolyModePrecise)) {
+       case -1:
+               goto cleanup_dst;
+       case 0:
+               if (!gen4_composite_solid_init(sna, &tmp->base.src, 0))
+                       goto cleanup_dst;
+               /* fall through to fixup */
+       case 1:
+               gen4_composite_channel_convert(&tmp->base.src);
+               break;
+       }
+
+       tmp->base.mask.bo = sna_render_get_solid(sna, 0);
+       if (tmp->base.mask.bo == NULL)
+               goto cleanup_src;
+
+       tmp->base.is_affine = tmp->base.src.is_affine;
+       tmp->base.has_component_alpha = false;
+       tmp->base.need_magic_ca_pass = false;
+
+       tmp->prim_emit = gen4_emit_composite_spans_primitive;
+       if (tmp->base.src.is_solid)
+               tmp->prim_emit = gen4_emit_composite_spans_solid;
+       else if (tmp->base.is_affine)
+               tmp->prim_emit = gen4_emit_composite_spans_affine;
+       tmp->base.floats_per_vertex = 5 + 2*!tmp->base.is_affine;
+       tmp->base.floats_per_rect = 3 * tmp->base.floats_per_vertex;
+
+       tmp->base.u.gen5.wm_kernel = WM_KERNEL_OPACITY | !tmp->base.is_affine;
+       tmp->base.u.gen4.ve_id = 1 << 1 | tmp->base.is_affine;
+
+       tmp->box   = gen4_render_composite_spans_box;
+       tmp->boxes = gen4_render_composite_spans_boxes;
+       tmp->done  = gen4_render_composite_spans_done;
+
+       if (!kgem_check_bo(&sna->kgem,
+                          tmp->base.dst.bo, tmp->base.src.bo,
+                          NULL))  {
+               kgem_submit(&sna->kgem);
+               if (!kgem_check_bo(&sna->kgem,
+                                  tmp->base.dst.bo, tmp->base.src.bo,
+                                  NULL))
+                       goto cleanup_src;
+       }
+
+       gen4_bind_surfaces(sna, &tmp->base);
+       gen4_align_vertex(sna, &tmp->base);
+       return true;
+
+cleanup_src:
+       if (tmp->base.src.bo)
+               kgem_bo_destroy(&sna->kgem, tmp->base.src.bo);
+cleanup_dst:
+       if (tmp->base.redirect.real_bo)
+               kgem_bo_destroy(&sna->kgem, tmp->base.dst.bo);
+       return false;
+}
+#endif
+
+static void
+gen4_copy_bind_surfaces(struct sna *sna, const struct sna_composite_op *op)
+{
+       uint32_t *binding_table;
+       uint16_t offset;
+
+       gen4_get_batch(sna);
+
+       binding_table = gen4_composite_get_binding_table(sna, &offset);
+
+       binding_table[0] =
+               gen4_bind_bo(sna,
+                            op->dst.bo, op->dst.width, op->dst.height,
+                            gen4_get_dest_format(op->dst.format),
+                            true);
+       binding_table[1] =
+               gen4_bind_bo(sna,
+                            op->src.bo, op->src.width, op->src.height,
+                            op->src.card_format,
+                            false);
+
+       if (sna->kgem.surface == offset &&
+           *(uint64_t *)(sna->kgem.batch + sna->render_state.gen4.surface_table) == *(uint64_t*)binding_table) {
+               sna->kgem.surface += sizeof(struct gen4_surface_state_padded) / sizeof(uint32_t);
+               offset = sna->render_state.gen4.surface_table;
+       }
+
+       gen4_emit_state(sna, op, offset);
+}
+
+static void
+gen4_render_copy_one(struct sna *sna,
+                    const struct sna_composite_op *op,
+                    int sx, int sy,
+                    int w, int h,
+                    int dx, int dy)
+{
+       gen4_get_rectangles(sna, op, 1, gen4_copy_bind_surfaces);
+
+       OUT_VERTEX(dx+w, dy+h);
+       OUT_VERTEX_F((sx+w)*op->src.scale[0]);
+       OUT_VERTEX_F((sy+h)*op->src.scale[1]);
+
+       OUT_VERTEX(dx, dy+h);
+       OUT_VERTEX_F(sx*op->src.scale[0]);
+       OUT_VERTEX_F((sy+h)*op->src.scale[1]);
+
+       OUT_VERTEX(dx, dy);
+       OUT_VERTEX_F(sx*op->src.scale[0]);
+       OUT_VERTEX_F(sy*op->src.scale[1]);
+
+       _FLUSH();
+}
+
+static inline bool prefer_blt_copy(struct sna *sna, unsigned flags)
+{
+#if PREFER_BLT
+       return true;
+       (void)sna;
+#else
+       return sna->kgem.mode != KGEM_RENDER;
+#endif
+       (void)flags;
+}
+
+static bool
+gen4_render_copy_boxes(struct sna *sna, uint8_t alu,
+                      PixmapPtr src, struct kgem_bo *src_bo, int16_t src_dx, int16_t src_dy,
+                      PixmapPtr dst, struct kgem_bo *dst_bo, int16_t dst_dx, int16_t dst_dy,
+                      const BoxRec *box, int n, unsigned flags)
+{
+       struct sna_composite_op tmp;
+
+       DBG(("%s x %d\n", __FUNCTION__, n));
+
+       if (prefer_blt_copy(sna, flags) &&
+           sna_blt_compare_depth(&src->drawable, &dst->drawable) &&
+           sna_blt_copy_boxes(sna, alu,
+                              src_bo, src_dx, src_dy,
+                              dst_bo, dst_dx, dst_dy,
+                              dst->drawable.bitsPerPixel,
+                              box, n))
+               return true;
+
+       if (!(alu == GXcopy || alu == GXclear) || src_bo == dst_bo) {
+fallback_blt:
+               if (!sna_blt_compare_depth(&src->drawable, &dst->drawable))
+                       return false;
+
+               return sna_blt_copy_boxes_fallback(sna, alu,
+                                                  src, src_bo, src_dx, src_dy,
+                                                  dst, dst_bo, dst_dx, dst_dy,
+                                                  box, n);
+       }
+
+       memset(&tmp, 0, sizeof(tmp));
+
+       DBG(("%s (%d, %d)->(%d, %d) x %d\n",
+            __FUNCTION__, src_dx, src_dy, dst_dx, dst_dy, n));
+
+       if (dst->drawable.depth == src->drawable.depth) {
+               tmp.dst.format = sna_render_format_for_depth(dst->drawable.depth);
+               tmp.src.pict_format = tmp.dst.format;
+       } else {
+               tmp.dst.format = sna_format_for_depth(dst->drawable.depth);
+               tmp.src.pict_format = sna_format_for_depth(src->drawable.depth);
+       }
+       if (!gen4_check_format(tmp.src.pict_format))
+               goto fallback_blt;
+
+       tmp.op = alu == GXcopy ? PictOpSrc : PictOpClear;
+
+       tmp.dst.pixmap = dst;
+       tmp.dst.width  = dst->drawable.width;
+       tmp.dst.height = dst->drawable.height;
+       tmp.dst.x = tmp.dst.y = 0;
+       tmp.dst.bo = dst_bo;
+       tmp.damage = NULL;
+
+       sna_render_composite_redirect_init(&tmp);
+       if (too_large(tmp.dst.width, tmp.dst.height)) {
+               BoxRec extents = box[0];
+               int i;
+
+               for (i = 1; i < n; i++) {
+                       if (box[i].x1 < extents.x1)
+                               extents.x1 = box[i].x1;
+                       if (box[i].y1 < extents.y1)
+                               extents.y1 = box[i].y1;
+
+                       if (box[i].x2 > extents.x2)
+                               extents.x2 = box[i].x2;
+                       if (box[i].y2 > extents.y2)
+                               extents.y2 = box[i].y2;
+               }
+               if (!sna_render_composite_redirect(sna, &tmp,
+                                                  extents.x1 + dst_dx,
+                                                  extents.y1 + dst_dy,
+                                                  extents.x2 - extents.x1,
+                                                  extents.y2 - extents.y1))
+                       goto fallback_tiled;
+       }
+
+       tmp.src.filter = SAMPLER_FILTER_NEAREST;
+       tmp.src.repeat = SAMPLER_EXTEND_NONE;
+       tmp.src.card_format = gen4_get_card_format(tmp.src.pict_format);
+       if (too_large(src->drawable.width, src->drawable.height)) {
+               BoxRec extents = box[0];
+               int i;
+
+               for (i = 1; i < n; i++) {
+                       if (extents.x1 < box[i].x1)
+                               extents.x1 = box[i].x1;
+                       if (extents.y1 < box[i].y1)
+                               extents.y1 = box[i].y1;
+
+                       if (extents.x2 > box[i].x2)
+                               extents.x2 = box[i].x2;
+                       if (extents.y2 > box[i].y2)
+                               extents.y2 = box[i].y2;
+               }
+
+               if (!sna_render_pixmap_partial(sna, src, src_bo, &tmp.src,
+                                              extents.x1 + src_dx,
+                                              extents.y1 + src_dy,
+                                              extents.x2 - extents.x1,
+                                              extents.y2 - extents.y1))
+                       goto fallback_tiled_dst;
+       } else {
+               tmp.src.bo = kgem_bo_reference(src_bo);
+               tmp.src.width  = src->drawable.width;
+               tmp.src.height = src->drawable.height;
+               tmp.src.offset[0] = tmp.src.offset[1] = 0;
+               tmp.src.scale[0] = 1.f/src->drawable.width;
+               tmp.src.scale[1] = 1.f/src->drawable.height;
+       }
+
+       tmp.is_affine = true;
+       tmp.floats_per_vertex = 3;
+       tmp.floats_per_rect = 9;
+       tmp.u.gen4.wm_kernel = WM_KERNEL;
+       tmp.u.gen4.ve_id = 1;
+
+       if (!kgem_check_bo(&sna->kgem, dst_bo, src_bo, NULL)) {
+               kgem_submit(&sna->kgem);
+               if (!kgem_check_bo(&sna->kgem, dst_bo, src_bo, NULL))
+                       goto fallback_tiled_src;
+       }
+
+       dst_dx += tmp.dst.x;
+       dst_dy += tmp.dst.y;
+       tmp.dst.x = tmp.dst.y = 0;
+
+       src_dx += tmp.src.offset[0];
+       src_dy += tmp.src.offset[1];
+
+       gen4_copy_bind_surfaces(sna, &tmp);
+       gen4_align_vertex(sna, &tmp);
+
+       do {
+               gen4_render_copy_one(sna, &tmp,
+                                    box->x1 + src_dx, box->y1 + src_dy,
+                                    box->x2 - box->x1, box->y2 - box->y1,
+                                    box->x1 + dst_dx, box->y1 + dst_dy);
+               box++;
+       } while (--n);
+
+       gen4_vertex_flush(sna);
+       sna_render_composite_redirect_done(sna, &tmp);
+       kgem_bo_destroy(&sna->kgem, tmp.src.bo);
+       return true;
+
+fallback_tiled_src:
+       kgem_bo_destroy(&sna->kgem, tmp.src.bo);
+fallback_tiled_dst:
+       if (tmp.redirect.real_bo)
+               kgem_bo_destroy(&sna->kgem, tmp.dst.bo);
+fallback_tiled:
+       return sna_tiling_copy_boxes(sna, alu,
+                                    src, src_bo, src_dx, src_dy,
+                                    dst, dst_bo, dst_dx, dst_dy,
+                                    box, n);
+}
+
+static void
+gen4_render_copy_blt(struct sna *sna,
+                    const struct sna_copy_op *op,
+                    int16_t sx, int16_t sy,
+                    int16_t w,  int16_t h,
+                    int16_t dx, int16_t dy)
+{
+       gen4_render_copy_one(sna, &op->base, sx, sy, w, h, dx, dy);
+}
+
+static void
+gen4_render_copy_done(struct sna *sna, const struct sna_copy_op *op)
+{
+       gen4_vertex_flush(sna);
+}
+
+static bool
+gen4_render_copy(struct sna *sna, uint8_t alu,
+                PixmapPtr src, struct kgem_bo *src_bo,
+                PixmapPtr dst, struct kgem_bo *dst_bo,
+                struct sna_copy_op *op)
+{
+       DBG(("%s: src=%ld, dst=%ld, alu=%d\n",
+            __FUNCTION__,
+            src->drawable.serialNumber,
+            dst->drawable.serialNumber,
+            alu));
+
+       if (prefer_blt(sna) &&
+           sna_blt_compare_depth(&src->drawable, &dst->drawable) &&
+           sna_blt_copy(sna, alu,
+                        src_bo, dst_bo,
+                        dst->drawable.bitsPerPixel,
+                        op))
+               return true;
+
+       if (!(alu == GXcopy || alu == GXclear) || src_bo == dst_bo ||
+           too_large(src->drawable.width, src->drawable.height) ||
+           too_large(dst->drawable.width, dst->drawable.height)) {
+fallback:
+               if (!sna_blt_compare_depth(&src->drawable, &dst->drawable))
+                       return false;
+
+               return sna_blt_copy(sna, alu, src_bo, dst_bo,
+                                   dst->drawable.bitsPerPixel,
+                                   op);
+       }
+
+       if (dst->drawable.depth == src->drawable.depth) {
+               op->base.dst.format = sna_render_format_for_depth(dst->drawable.depth);
+               op->base.src.pict_format = op->base.dst.format;
+       } else {
+               op->base.dst.format = sna_format_for_depth(dst->drawable.depth);
+               op->base.src.pict_format = sna_format_for_depth(src->drawable.depth);
+       }
+       if (!gen4_check_format(op->base.src.pict_format))
+               goto fallback;
+
+       op->base.op = alu == GXcopy ? PictOpSrc : PictOpClear;
+
+       op->base.dst.pixmap = dst;
+       op->base.dst.width  = dst->drawable.width;
+       op->base.dst.height = dst->drawable.height;
+       op->base.dst.bo = dst_bo;
+
+       op->base.src.bo = src_bo;
+       op->base.src.card_format =
+               gen4_get_card_format(op->base.src.pict_format);
+       op->base.src.width  = src->drawable.width;
+       op->base.src.height = src->drawable.height;
+       op->base.src.scale[0] = 1.f/src->drawable.width;
+       op->base.src.scale[1] = 1.f/src->drawable.height;
+       op->base.src.filter = SAMPLER_FILTER_NEAREST;
+       op->base.src.repeat = SAMPLER_EXTEND_NONE;
+
+       op->base.is_affine = true;
+       op->base.floats_per_vertex = 3;
+       op->base.floats_per_rect = 9;
+       op->base.u.gen4.wm_kernel = WM_KERNEL;
+       op->base.u.gen4.ve_id = 1;
+
+       if (!kgem_check_bo(&sna->kgem, dst_bo, src_bo, NULL)) {
+               kgem_submit(&sna->kgem);
+               if (!kgem_check_bo(&sna->kgem, dst_bo, src_bo, NULL))
+                       goto fallback;
+       }
+
+       if (kgem_bo_is_dirty(src_bo)) {
+               if (sna_blt_compare_depth(&src->drawable, &dst->drawable) &&
+                   sna_blt_copy(sna, alu,
+                                src_bo, dst_bo,
+                                dst->drawable.bitsPerPixel,
+                                op))
+                       return true;
+       }
+
+       gen4_copy_bind_surfaces(sna, &op->base);
+       gen4_align_vertex(sna, &op->base);
+
+       op->blt  = gen4_render_copy_blt;
+       op->done = gen4_render_copy_done;
+       return true;
+}
+
+static void
+gen4_fill_bind_surfaces(struct sna *sna, const struct sna_composite_op *op)
+{
+       uint32_t *binding_table;
+       uint16_t offset;
+
+       gen4_get_batch(sna);
+
+       binding_table = gen4_composite_get_binding_table(sna, &offset);
+
+       binding_table[0] =
+               gen4_bind_bo(sna,
+                            op->dst.bo, op->dst.width, op->dst.height,
+                            gen4_get_dest_format(op->dst.format),
+                            true);
+       binding_table[1] =
+               gen4_bind_bo(sna,
+                            op->src.bo, 1, 1,
+                            GEN4_SURFACEFORMAT_B8G8R8A8_UNORM,
+                            false);
+
+       if (sna->kgem.surface == offset &&
+           *(uint64_t *)(sna->kgem.batch + sna->render_state.gen4.surface_table) == *(uint64_t*)binding_table) {
+               sna->kgem.surface +=
+                       sizeof(struct gen4_surface_state_padded)/sizeof(uint32_t);
+               offset = sna->render_state.gen4.surface_table;
+       }
+
+       gen4_emit_state(sna, op, offset);
+}
+
+static void
+gen4_render_fill_rectangle(struct sna *sna,
+                          const struct sna_composite_op *op,
+                          int x, int y, int w, int h)
+{
+       gen4_get_rectangles(sna, op, 1, gen4_fill_bind_surfaces);
+
+       OUT_VERTEX(x+w, y+h);
+       OUT_VERTEX_F(1);
+       OUT_VERTEX_F(1);
+
+       OUT_VERTEX(x, y+h);
+       OUT_VERTEX_F(0);
+       OUT_VERTEX_F(1);
+
+       OUT_VERTEX(x, y);
+       OUT_VERTEX_F(0);
+       OUT_VERTEX_F(0);
+
+       _FLUSH();
+}
+
+static bool
+gen4_render_fill_boxes(struct sna *sna,
+                      CARD8 op,
+                      PictFormat format,
+                      const xRenderColor *color,
+                      PixmapPtr dst, struct kgem_bo *dst_bo,
+                      const BoxRec *box, int n)
+{
+       struct sna_composite_op tmp;
+       uint32_t pixel;
+
+       if (op >= ARRAY_SIZE(gen4_blend_op)) {
+               DBG(("%s: fallback due to unhandled blend op: %d\n",
+                    __FUNCTION__, op));
+               return false;
+       }
+
+       if (op <= PictOpSrc &&
+           (prefer_blt(sna) ||
+            too_large(dst->drawable.width, dst->drawable.height) ||
+            !gen4_check_dst_format(format))) {
+               uint8_t alu = GXinvalid;
+
+               pixel = 0;
+               if (op == PictOpClear)
+                       alu = GXclear;
+               else if (sna_get_pixel_from_rgba(&pixel,
+                                                color->red,
+                                                color->green,
+                                                color->blue,
+                                                color->alpha,
+                                                format))
+                       alu = GXcopy;
+
+               if (alu != GXinvalid &&
+                   sna_blt_fill_boxes(sna, alu,
+                                      dst_bo, dst->drawable.bitsPerPixel,
+                                      pixel, box, n))
+                       return true;
+
+               if (!gen4_check_dst_format(format))
+                       return false;
+
+               if (too_large(dst->drawable.width, dst->drawable.height))
+                       return sna_tiling_fill_boxes(sna, op, format, color,
+                                                    dst, dst_bo, box, n);
+       }
+
+       if (op == PictOpClear) {
+               pixel = 0;
+               op = PictOpSrc;
+       } else if (!sna_get_pixel_from_rgba(&pixel,
+                                           color->red,
+                                           color->green,
+                                           color->blue,
+                                           color->alpha,
+                                           PICT_a8r8g8b8))
+               return false;
+
+       DBG(("%s(%08x x %d)\n", __FUNCTION__, pixel, n));
+
+       memset(&tmp, 0, sizeof(tmp));
+
+       tmp.op = op;
+
+       tmp.dst.pixmap = dst;
+       tmp.dst.width  = dst->drawable.width;
+       tmp.dst.height = dst->drawable.height;
+       tmp.dst.format = format;
+       tmp.dst.bo = dst_bo;
+
+       tmp.src.bo = sna_render_get_solid(sna, pixel);
+       tmp.src.filter = SAMPLER_FILTER_NEAREST;
+       tmp.src.repeat = SAMPLER_EXTEND_REPEAT;
+
+       tmp.is_affine = true;
+       tmp.floats_per_vertex = 3;
+       tmp.floats_per_rect = 9;
+       tmp.u.gen4.wm_kernel = WM_KERNEL;
+       tmp.u.gen4.ve_id = 1;
+
+       if (!kgem_check_bo(&sna->kgem, dst_bo, NULL)) {
+               kgem_submit(&sna->kgem);
+               assert(kgem_check_bo(&sna->kgem, dst_bo, NULL));
+       }
+
+       gen4_fill_bind_surfaces(sna, &tmp);
+       gen4_align_vertex(sna, &tmp);
+
+       do {
+               gen4_render_fill_rectangle(sna, &tmp,
+                                          box->x1, box->y1,
+                                          box->x2 - box->x1,
+                                          box->y2 - box->y1);
+               box++;
+       } while (--n);
+
+       gen4_vertex_flush(sna);
+       kgem_bo_destroy(&sna->kgem, tmp.src.bo);
+       return true;
+}
+
+static void
+gen4_render_fill_op_blt(struct sna *sna, const struct sna_fill_op *op,
+                       int16_t x, int16_t y, int16_t w, int16_t h)
+{
+       gen4_render_fill_rectangle(sna, &op->base, x, y, w, h);
+}
+
+fastcall static void
+gen4_render_fill_op_box(struct sna *sna,
+                       const struct sna_fill_op *op,
+                       const BoxRec *box)
+{
+       gen4_render_fill_rectangle(sna, &op->base,
+                                  box->x1, box->y1,
+                                  box->x2-box->x1, box->y2-box->y1);
+}
+
+fastcall static void
+gen4_render_fill_op_boxes(struct sna *sna,
+                         const struct sna_fill_op *op,
+                         const BoxRec *box,
+                         int nbox)
+{
+       do {
+               gen4_render_fill_rectangle(sna, &op->base,
+                                          box->x1, box->y1,
+                                          box->x2-box->x1, box->y2-box->y1);
+               box++;
+       } while (--nbox);
+}
+
+static void
+gen4_render_fill_op_done(struct sna *sna, const struct sna_fill_op *op)
+{
+       gen4_vertex_flush(sna);
+       kgem_bo_destroy(&sna->kgem, op->base.src.bo);
+}
+
+static bool
+gen4_render_fill(struct sna *sna, uint8_t alu,
+                PixmapPtr dst, struct kgem_bo *dst_bo,
+                uint32_t color,
+                struct sna_fill_op *op)
+{
+       if (prefer_blt(sna) &&
+           sna_blt_fill(sna, alu,
+                        dst_bo, dst->drawable.bitsPerPixel,
+                        color,
+                        op))
+               return true;
+
+       if (!(alu == GXcopy || alu == GXclear) ||
+           too_large(dst->drawable.width, dst->drawable.height))
+               return sna_blt_fill(sna, alu,
+                                   dst_bo, dst->drawable.bitsPerPixel,
+                                   color,
+                                   op);
+
+       if (alu == GXclear)
+               color = 0;
+
+       op->base.op = color == 0 ? PictOpClear : PictOpSrc;
+
+       op->base.dst.pixmap = dst;
+       op->base.dst.width  = dst->drawable.width;
+       op->base.dst.height = dst->drawable.height;
+       op->base.dst.format = sna_format_for_depth(dst->drawable.depth);
+       op->base.dst.bo = dst_bo;
+       op->base.dst.x = op->base.dst.y = 0;
+
+       op->base.need_magic_ca_pass = 0;
+       op->base.has_component_alpha = 0;
+
+       op->base.src.bo =
+               sna_render_get_solid(sna,
+                                    sna_rgba_for_color(color,
+                                                       dst->drawable.depth));
+       op->base.src.filter = SAMPLER_FILTER_NEAREST;
+       op->base.src.repeat = SAMPLER_EXTEND_REPEAT;
+
+       op->base.mask.bo = NULL;
+       op->base.mask.filter = SAMPLER_FILTER_NEAREST;
+       op->base.mask.repeat = SAMPLER_EXTEND_NONE;
+
+       op->base.is_affine = true;
+       op->base.floats_per_vertex = 3;
+       op->base.floats_per_rect = 9;
+       op->base.u.gen4.wm_kernel = WM_KERNEL;
+       op->base.u.gen4.ve_id = 1;
+
+       if (!kgem_check_bo(&sna->kgem, dst_bo, NULL)) {
+               kgem_submit(&sna->kgem);
+               assert(kgem_check_bo(&sna->kgem, dst_bo, NULL));
+       }
+
+       gen4_fill_bind_surfaces(sna, &op->base);
+       gen4_align_vertex(sna, &op->base);
+
+       op->blt   = gen4_render_fill_op_blt;
+       op->box   = gen4_render_fill_op_box;
+       op->boxes = gen4_render_fill_op_boxes;
+       op->done  = gen4_render_fill_op_done;
+       return true;
+}
+
+static bool
+gen4_render_fill_one_try_blt(struct sna *sna, PixmapPtr dst, struct kgem_bo *bo,
+                            uint32_t color,
+                            int16_t x1, int16_t y1, int16_t x2, int16_t y2,
+                            uint8_t alu)
+{
+       BoxRec box;
+
+       box.x1 = x1;
+       box.y1 = y1;
+       box.x2 = x2;
+       box.y2 = y2;
+
+       return sna_blt_fill_boxes(sna, alu,
+                                 bo, dst->drawable.bitsPerPixel,
+                                 color, &box, 1);
+}
+
+static bool
+gen4_render_fill_one(struct sna *sna, PixmapPtr dst, struct kgem_bo *bo,
+                    uint32_t color,
+                    int16_t x1, int16_t y1,
+                    int16_t x2, int16_t y2,
+                    uint8_t alu)
+{
+       struct sna_composite_op tmp;
+
+       DBG(("%s: color=%08x\n", __FUNCTION__, color));
+
+       if (gen4_render_fill_one_try_blt(sna, dst, bo, color,
+                                        x1, y1, x2, y2, alu))
+               return true;
+
+       /* Must use the BLT if we can't RENDER... */
+       if (!(alu == GXcopy || alu == GXclear) ||
+           too_large(dst->drawable.width, dst->drawable.height))
+               return false;
+
+       if (alu == GXclear)
+               color = 0;
+
+       tmp.op = color == 0 ? PictOpClear : PictOpSrc;
+
+       tmp.dst.pixmap = dst;
+       tmp.dst.width  = dst->drawable.width;
+       tmp.dst.height = dst->drawable.height;
+       tmp.dst.format = sna_format_for_depth(dst->drawable.depth);
+       tmp.dst.bo = bo;
+       tmp.dst.x = tmp.dst.y = 0;
+
+       tmp.src.bo =
+               sna_render_get_solid(sna,
+                                    sna_rgba_for_color(color,
+                                                       dst->drawable.depth));
+       tmp.src.filter = SAMPLER_FILTER_NEAREST;
+       tmp.src.repeat = SAMPLER_EXTEND_REPEAT;
+
+       tmp.mask.bo = NULL;
+       tmp.mask.filter = SAMPLER_FILTER_NEAREST;
+       tmp.mask.repeat = SAMPLER_EXTEND_NONE;
+
+       tmp.is_affine = true;
+       tmp.floats_per_vertex = 3;
+       tmp.floats_per_rect = 9;
+       tmp.has_component_alpha = 0;
+       tmp.need_magic_ca_pass = false;
+
+       tmp.u.gen4.wm_kernel = WM_KERNEL;
+       tmp.u.gen4.ve_id = 1;
+
+       if (!kgem_check_bo(&sna->kgem, bo, NULL)) {
+               _kgem_submit(&sna->kgem);
+               assert(kgem_check_bo(&sna->kgem, bo, NULL));
+       }
+
+       gen4_fill_bind_surfaces(sna, &tmp);
+       gen4_align_vertex(sna, &tmp);
+
+       gen4_render_fill_rectangle(sna, &tmp, x1, y1, x2 - x1, y2 - y1);
+
+       gen4_vertex_flush(sna);
+       kgem_bo_destroy(&sna->kgem, tmp.src.bo);
+
+       return true;
+}
+
+static void
+gen4_render_flush(struct sna *sna)
+{
+       gen4_vertex_close(sna);
+}
+
+static void
+discard_vbo(struct sna *sna)
+{
+       kgem_bo_destroy(&sna->kgem, sna->render.vbo);
+       sna->render.vbo = NULL;
+       sna->render.vertices = sna->render.vertex_data;
+       sna->render.vertex_size = ARRAY_SIZE(sna->render.vertex_data);
+       sna->render.vertex_used = 0;
+       sna->render.vertex_index = 0;
+}
+
+static void
+gen4_render_retire(struct kgem *kgem)
+{
+       struct sna *sna;
+
+       sna = container_of(kgem, struct sna, kgem);
+       if (kgem->nbatch == 0 && sna->render.vbo && !kgem_bo_is_busy(sna->render.vbo)) {
+               DBG(("%s: resetting idle vbo\n", __FUNCTION__));
+               sna->render.vertex_used = 0;
+               sna->render.vertex_index = 0;
+       }
+}
+
+static void
+gen4_render_expire(struct kgem *kgem)
+{
+       struct sna *sna;
+
+       sna = container_of(kgem, struct sna, kgem);
+       if (sna->render.vbo && !sna->render.vertex_used) {
+               DBG(("%s: discarding vbo\n", __FUNCTION__));
+               discard_vbo(sna);
+       }
+}
+
+static void gen4_render_reset(struct sna *sna)
+{
+       sna->render_state.gen4.needs_invariant = true;
+       sna->render_state.gen4.needs_urb = true;
+       sna->render_state.gen4.vb_id = 0;
+       sna->render_state.gen4.ve_id = -1;
+       sna->render_state.gen4.last_primitive = -1;
+       sna->render_state.gen4.last_pipelined_pointers = -1;
+
+       sna->render_state.gen4.drawrect_offset = -1;
+       sna->render_state.gen4.drawrect_limit = -1;
+       sna->render_state.gen4.surface_table = -1;
+
+       if (sna->render.vbo &&
+           !kgem_bo_is_mappable(&sna->kgem, sna->render.vbo)) {
+               DBG(("%s: discarding unmappable vbo\n", __FUNCTION__));
+               discard_vbo(sna);
+       }
+}
+
+static void gen4_render_fini(struct sna *sna)
+{
+       kgem_bo_destroy(&sna->kgem, sna->render_state.gen4.general_bo);
+}
+
+static uint32_t gen4_create_vs_unit_state(struct sna_static_stream *stream)
+{
+       struct gen4_vs_unit_state *vs = sna_static_stream_map(stream, sizeof(*vs), 32);
+
+       /* Set up the vertex shader to be disabled (passthrough) */
+       vs->thread4.nr_urb_entries = URB_VS_ENTRIES;
+       vs->thread4.urb_entry_allocation_size = URB_VS_ENTRY_SIZE - 1;
+       vs->vs6.vs_enable = 0;
+       vs->vs6.vert_cache_disable = 1;
+
+       return sna_static_stream_offsetof(stream, vs);
+}
+
+static uint32_t gen4_create_sf_state(struct sna_static_stream *stream,
+                                    const struct gt_info *info,
+                                    uint32_t kernel)
+{
+       struct gen4_sf_unit_state *sf;
+
+       sf = sna_static_stream_map(stream, sizeof(*sf), 32);
+
+       sf->thread0.grf_reg_count = GEN4_GRF_BLOCKS(SF_KERNEL_NUM_GRF);
+       sf->thread0.kernel_start_pointer = kernel >> 6;
+       sf->thread3.const_urb_entry_read_length = 0;    /* no const URBs */
+       sf->thread3.const_urb_entry_read_offset = 0;    /* no const URBs */
+       sf->thread3.urb_entry_read_length = 1;  /* 1 URB per vertex */
+       /* don't smash vertex header, read start from dw8 */
+       sf->thread3.urb_entry_read_offset = 1;
+       sf->thread3.dispatch_grf_start_reg = 3;
+       sf->thread4.max_threads = info->max_sf_threads - 1;
+       sf->thread4.urb_entry_allocation_size = URB_SF_ENTRY_SIZE - 1;
+       sf->thread4.nr_urb_entries = URB_SF_ENTRIES;
+       sf->sf5.viewport_transform = false;     /* skip viewport */
+       sf->sf6.cull_mode = GEN4_CULLMODE_NONE;
+       sf->sf6.scissor = 0;
+       sf->sf7.trifan_pv = 2;
+       sf->sf6.dest_org_vbias = 0x8;
+       sf->sf6.dest_org_hbias = 0x8;
+
+       return sna_static_stream_offsetof(stream, sf);
+}
+
+static uint32_t gen4_create_sampler_state(struct sna_static_stream *stream,
+                                         sampler_filter_t src_filter,
+                                         sampler_extend_t src_extend,
+                                         sampler_filter_t mask_filter,
+                                         sampler_extend_t mask_extend)
+{
+       struct gen4_sampler_state *sampler_state;
+
+       sampler_state = sna_static_stream_map(stream,
+                                             sizeof(struct gen4_sampler_state) * 2,
+                                             32);
+       sampler_state_init(&sampler_state[0], src_filter, src_extend);
+       sampler_state_init(&sampler_state[1], mask_filter, mask_extend);
+
+       return sna_static_stream_offsetof(stream, sampler_state);
+}
+
+static void gen4_init_wm_state(struct gen4_wm_unit_state *wm,
+                              const struct gt_info *info,
+                              bool has_mask,
+                              uint32_t kernel,
+                              uint32_t sampler)
+{
+       assert((kernel & 63) == 0);
+       wm->thread0.kernel_start_pointer = kernel >> 6;
+       wm->thread0.grf_reg_count = GEN4_GRF_BLOCKS(PS_KERNEL_NUM_GRF);
+
+       wm->thread1.single_program_flow = 0;
+
+       wm->thread3.const_urb_entry_read_length = 0;
+       wm->thread3.const_urb_entry_read_offset = 0;
+
+       wm->thread3.urb_entry_read_offset = 0;
+       wm->thread3.dispatch_grf_start_reg = 3;
+
+       assert((sampler & 31) == 0);
+       wm->wm4.sampler_state_pointer = sampler >> 5;
+       wm->wm4.sampler_count = 1;
+
+       wm->wm5.max_threads = info->max_wm_threads - 1;
+       wm->wm5.transposed_urb_read = 0;
+       wm->wm5.thread_dispatch_enable = 1;
+       /* just use 16-pixel dispatch (4 subspans), don't need to change kernel
+        * start point
+        */
+       wm->wm5.enable_16_pix = 1;
+       wm->wm5.enable_8_pix = 0;
+       wm->wm5.early_depth_test = 1;
+
+       /* Each pair of attributes (src/mask coords) is two URB entries */
+       if (has_mask) {
+               wm->thread1.binding_table_entry_count = 3;
+               wm->thread3.urb_entry_read_length = 4;
+       } else {
+               wm->thread1.binding_table_entry_count = 2;
+               wm->thread3.urb_entry_read_length = 2;
+       }
+}
+
+static uint32_t gen4_create_cc_viewport(struct sna_static_stream *stream)
+{
+       struct gen4_cc_viewport vp;
+
+       vp.min_depth = -1.e35;
+       vp.max_depth = 1.e35;
+
+       return sna_static_stream_add(stream, &vp, sizeof(vp), 32);
+}
+
+static uint32_t gen4_create_cc_unit_state(struct sna_static_stream *stream)
+{
+       uint8_t *ptr, *base;
+       uint32_t vp;
+       int i, j;
+
+       vp = gen4_create_cc_viewport(stream);
+       base = ptr =
+               sna_static_stream_map(stream,
+                                     GEN4_BLENDFACTOR_COUNT*GEN4_BLENDFACTOR_COUNT*64,
+                                     64);
+
+       for (i = 0; i < GEN4_BLENDFACTOR_COUNT; i++) {
+               for (j = 0; j < GEN4_BLENDFACTOR_COUNT; j++) {
+                       struct gen4_cc_unit_state *state =
+                               (struct gen4_cc_unit_state *)ptr;
+
+                       state->cc3.blend_enable =
+                               !(j == GEN4_BLENDFACTOR_ZERO && i == GEN4_BLENDFACTOR_ONE);
+                       state->cc4.cc_viewport_state_offset = vp >> 5;
+
+                       state->cc5.logicop_func = 0xc;  /* COPY */
+                       state->cc5.ia_blend_function = GEN4_BLENDFUNCTION_ADD;
+
+                       /* Fill in alpha blend factors same as color, for the future. */
+                       state->cc5.ia_src_blend_factor = i;
+                       state->cc5.ia_dest_blend_factor = j;
+
+                       state->cc6.blend_function = GEN4_BLENDFUNCTION_ADD;
+                       state->cc6.clamp_post_alpha_blend = 1;
+                       state->cc6.clamp_pre_alpha_blend = 1;
+                       state->cc6.src_blend_factor = i;
+                       state->cc6.dest_blend_factor = j;
+
+                       ptr += 64;
+               }
+       }
+
+       return sna_static_stream_offsetof(stream, base);
+}
+
+static bool gen4_render_setup(struct sna *sna)
+{
+       struct gen4_render_state *state = &sna->render_state.gen4;
+       struct sna_static_stream general;
+       struct gen4_wm_unit_state_padded *wm_state;
+       const struct gt_info *info;
+       uint32_t sf[2], wm[KERNEL_COUNT];
+       int i, j, k, l, m;
+
+       if (sna->kgem.gen == 45)
+               info = &g4x_gt_info;
+       else
+               info = &gen4_gt_info;
+
+       sna_static_stream_init(&general);
+
+       /* Zero pad the start. If you see an offset of 0x0 in the batchbuffer
+        * dumps, you know it points to zero.
+        */
+       null_create(&general);
+
+       sf[0] = sna_static_stream_compile_sf(sna, &general, brw_sf_kernel__nomask);
+       sf[1] = sna_static_stream_compile_sf(sna, &general, brw_sf_kernel__mask);
+       for (m = 0; m < KERNEL_COUNT; m++) {
+               if (wm_kernels[m].size) {
+                       wm[m] = sna_static_stream_add(&general,
+                                                     wm_kernels[m].data,
+                                                     wm_kernels[m].size,
+                                                     64);
+               } else {
+                       wm[m] = sna_static_stream_compile_wm(sna, &general,
+                                                            wm_kernels[m].data,
+                                                            16);
+               }
+       }
+
+       state->vs = gen4_create_vs_unit_state(&general);
+       state->sf[0] = gen4_create_sf_state(&general, info, sf[0]);
+       state->sf[1] = gen4_create_sf_state(&general, info, sf[1]);
+
+       wm_state = sna_static_stream_map(&general,
+                                         sizeof(*wm_state) * KERNEL_COUNT *
+                                         FILTER_COUNT * EXTEND_COUNT *
+                                         FILTER_COUNT * EXTEND_COUNT,
+                                         64);
+       state->wm = sna_static_stream_offsetof(&general, wm_state);
+       for (i = 0; i < FILTER_COUNT; i++) {
+               for (j = 0; j < EXTEND_COUNT; j++) {
+                       for (k = 0; k < FILTER_COUNT; k++) {
+                               for (l = 0; l < EXTEND_COUNT; l++) {
+                                       uint32_t sampler_state;
+
+                                       sampler_state =
+                                               gen4_create_sampler_state(&general,
+                                                                         i, j,
+                                                                         k, l);
+
+                                       for (m = 0; m < KERNEL_COUNT; m++) {
+                                               gen4_init_wm_state(&wm_state->state, info,
+                                                                  wm_kernels[m].has_mask,
+                                                                  wm[m], sampler_state);
+                                               wm_state++;
+                                       }
+                               }
+                       }
+               }
+       }
+
+       state->cc = gen4_create_cc_unit_state(&general);
+
+       state->general_bo = sna_static_stream_fini(sna, &general);
+       return state->general_bo != NULL;
+}
+
+bool gen4_render_init(struct sna *sna)
+{
+       if (!gen4_render_setup(sna))
+               return false;
+
+       sna->kgem.retire = gen4_render_retire;
+       sna->kgem.expire = gen4_render_expire;
+
+#if !NO_COMPOSITE
+       sna->render.composite = gen4_render_composite;
+#endif
+#if !NO_COMPOSITE_SPANS
+       sna->render.check_composite_spans = gen4_check_composite_spans;
+       sna->render.composite_spans = gen4_render_composite_spans;
+#endif
+
+#if !NO_VIDEO
+       sna->render.video = gen4_render_video;
+#endif
+
+#if !NO_COPY_BOXES
+       sna->render.copy_boxes = gen4_render_copy_boxes;
+#endif
+#if !NO_COPY
+       sna->render.copy = gen4_render_copy;
+#endif
+
+#if !NO_FILL_BOXES
+       sna->render.fill_boxes = gen4_render_fill_boxes;
+#endif
+#if !NO_FILL
+       sna->render.fill = gen4_render_fill;
+#endif
+#if !NO_FILL_ONE
+       sna->render.fill_one = gen4_render_fill_one;
+#endif
+
+       sna->render.flush = gen4_render_flush;
+       sna->render.reset = gen4_render_reset;
+       sna->render.fini = gen4_render_fini;
+
+       sna->render.max_3d_size = GEN4_MAX_3D_SIZE;
+       sna->render.max_3d_pitch = 1 << 18;
+       return true;
+}
diff --git a/src/sna/gen4_render.h b/src/sna/gen4_render.h
new file mode 100644 (file)
index 0000000..49d232e
--- /dev/null
@@ -0,0 +1,2646 @@
+/**************************************************************************
+ *
+ * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * 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, sub license, 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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 GEN5_RENDER_H
+#define GEN5_RENDER_H
+
+#define GEN4_3D(Pipeline,Opcode,Subopcode) ((3 << 29) | \
+                                          ((Pipeline) << 27) | \
+                                          ((Opcode) << 24) | \
+                                          ((Subopcode) << 16))
+
+#define GEN4_URB_FENCE                         GEN4_3D(0, 0, 0)
+#define GEN4_CS_URB_STATE                      GEN4_3D(0, 0, 1)
+#define GEN4_CONSTANT_BUFFER                   GEN4_3D(0, 0, 2)
+#define GEN4_STATE_PREFETCH                    GEN4_3D(0, 0, 3)
+
+#define GEN4_STATE_BASE_ADDRESS                        GEN4_3D(0, 1, 1)
+#define GEN4_STATE_SIP                         GEN4_3D(0, 1, 2)
+#define GEN4_PIPELINE_SELECT                   GEN4_3D(0, 1, 4)
+
+#define NEW_PIPELINE_SELECT                    GEN4_3D(1, 1, 4)
+
+#define GEN4_MEDIA_STATE_POINTERS              GEN4_3D(2, 0, 0)
+#define GEN4_MEDIA_OBJECT                      GEN4_3D(2, 1, 0)
+
+#define GEN4_3DSTATE_PIPELINED_POINTERS                GEN4_3D(3, 0, 0)
+#define GEN4_3DSTATE_BINDING_TABLE_POINTERS    GEN4_3D(3, 0, 1)
+
+#define GEN4_3DSTATE_VERTEX_BUFFERS            GEN4_3D(3, 0, 8)
+#define GEN4_3DSTATE_VERTEX_ELEMENTS           GEN4_3D(3, 0, 9)
+#define GEN4_3DSTATE_INDEX_BUFFER              GEN4_3D(3, 0, 0xa)
+#define GEN4_3DSTATE_VF_STATISTICS             GEN4_3D(3, 0, 0xb)
+
+#define GEN4_3DSTATE_DRAWING_RECTANGLE         GEN4_3D(3, 1, 0)
+#define GEN4_3DSTATE_CONSTANT_COLOR            GEN4_3D(3, 1, 1)
+#define GEN4_3DSTATE_SAMPLER_PALETTE_LOAD      GEN4_3D(3, 1, 2)
+#define GEN4_3DSTATE_CHROMA_KEY                        GEN4_3D(3, 1, 4)
+#define GEN4_3DSTATE_DEPTH_BUFFER              GEN4_3D(3, 1, 5)
+# define GEN4_3DSTATE_DEPTH_BUFFER_TYPE_SHIFT  29
+# define GEN4_3DSTATE_DEPTH_BUFFER_FORMAT_SHIFT        18
+
+#define GEN4_3DSTATE_POLY_STIPPLE_OFFSET               GEN4_3D(3, 1, 6)
+#define GEN4_3DSTATE_POLY_STIPPLE_PATTERN      GEN4_3D(3, 1, 7)
+#define GEN4_3DSTATE_LINE_STIPPLE              GEN4_3D(3, 1, 8)
+#define GEN4_3DSTATE_GLOBAL_DEPTH_OFFSET_CLAMP GEN4_3D(3, 1, 9)
+/* These two are BLC and CTG only, not BW or CL */
+#define GEN4_3DSTATE_AA_LINE_PARAMS            GEN4_3D(3, 1, 0xa)
+#define GEN4_3DSTATE_GS_SVB_INDEX              GEN4_3D(3, 1, 0xb)
+
+#define GEN4_PIPE_CONTROL                      GEN4_3D(3, 2, 0)
+
+#define GEN4_3DPRIMITIVE                               GEN4_3D(3, 3, 0)
+
+#define GEN4_3DSTATE_CLEAR_PARAMS              GEN4_3D(3, 1, 0x10)
+/* DW1 */
+# define GEN4_3DSTATE_DEPTH_CLEAR_VALID                (1 << 15)
+
+#define PIPELINE_SELECT_3D             0
+#define PIPELINE_SELECT_MEDIA          1
+
+#define UF0_CS_REALLOC                 (1 << 13)
+#define UF0_VFE_REALLOC                        (1 << 12)
+#define UF0_SF_REALLOC                 (1 << 11)
+#define UF0_CLIP_REALLOC               (1 << 10)
+#define UF0_GS_REALLOC                 (1 << 9)
+#define UF0_VS_REALLOC                 (1 << 8)
+#define UF1_CLIP_FENCE_SHIFT           20
+#define UF1_GS_FENCE_SHIFT             10
+#define UF1_VS_FENCE_SHIFT             0
+#define UF2_CS_FENCE_SHIFT             20
+#define UF2_VFE_FENCE_SHIFT            10
+#define UF2_SF_FENCE_SHIFT             0
+
+/* for GEN4_STATE_BASE_ADDRESS */
+#define BASE_ADDRESS_MODIFY            (1 << 0)
+
+/* for GEN4_3DSTATE_PIPELINED_POINTERS */
+#define GEN4_GS_DISABLE                       0
+#define GEN4_GS_ENABLE                1
+#define GEN4_CLIP_DISABLE             0
+#define GEN4_CLIP_ENABLE                      1
+
+/* for GEN4_PIPE_CONTROL */
+#define GEN4_PIPE_CONTROL_NOWRITE       (0 << 14)
+#define GEN4_PIPE_CONTROL_WRITE_QWORD   (1 << 14)
+#define GEN4_PIPE_CONTROL_WRITE_DEPTH   (2 << 14)
+#define GEN4_PIPE_CONTROL_WRITE_TIME    (3 << 14)
+#define GEN4_PIPE_CONTROL_DEPTH_STALL   (1 << 13)
+#define GEN4_PIPE_CONTROL_WC_FLUSH      (1 << 12)
+#define GEN4_PIPE_CONTROL_IS_FLUSH      (1 << 11)
+#define GEN4_PIPE_CONTROL_TC_FLUSH      (1 << 10)
+#define GEN4_PIPE_CONTROL_NOTIFY_ENABLE (1 << 8)
+#define GEN4_PIPE_CONTROL_GLOBAL_GTT    (1 << 2)
+#define GEN4_PIPE_CONTROL_LOCAL_PGTT    (0 << 2)
+#define GEN4_PIPE_CONTROL_DEPTH_CACHE_FLUSH    (1 << 0)
+
+/* VERTEX_BUFFER_STATE Structure */
+#define VB0_BUFFER_INDEX_SHIFT         27
+#define VB0_VERTEXDATA                 (0 << 26)
+#define VB0_INSTANCEDATA               (1 << 26)
+#define VB0_BUFFER_PITCH_SHIFT         0
+
+/* VERTEX_ELEMENT_STATE Structure */
+#define VE0_VERTEX_BUFFER_INDEX_SHIFT  27
+#define VE0_VALID                      (1 << 26)
+#define VE0_FORMAT_SHIFT               16
+#define VE0_OFFSET_SHIFT               0
+#define VE1_VFCOMPONENT_0_SHIFT                28
+#define VE1_VFCOMPONENT_1_SHIFT                24
+#define VE1_VFCOMPONENT_2_SHIFT                20
+#define VE1_VFCOMPONENT_3_SHIFT                16
+#define VE1_DESTINATION_ELEMENT_OFFSET_SHIFT   0
+
+/* 3DPRIMITIVE bits */
+#define GEN4_3DPRIMITIVE_VERTEX_SEQUENTIAL (0 << 15)
+#define GEN4_3DPRIMITIVE_VERTEX_RANDOM   (1 << 15)
+/* Primitive types are in gen4_defines.h */
+#define GEN4_3DPRIMITIVE_TOPOLOGY_SHIFT          10
+
+#define GEN4_SVG_CTL                  0x7400
+
+#define GEN4_SVG_CTL_GS_BA            (0 << 8)
+#define GEN4_SVG_CTL_SS_BA            (1 << 8)
+#define GEN4_SVG_CTL_IO_BA            (2 << 8)
+#define GEN4_SVG_CTL_GS_AUB           (3 << 8)
+#define GEN4_SVG_CTL_IO_AUB           (4 << 8)
+#define GEN4_SVG_CTL_SIP                      (5 << 8)
+
+#define GEN4_SVG_RDATA                0x7404
+#define GEN4_SVG_WORK_CTL             0x7408
+
+#define GEN4_VF_CTL                   0x7500
+
+#define GEN4_VF_CTL_SNAPSHOT_COMPLETE             (1 << 31)
+#define GEN4_VF_CTL_SNAPSHOT_MUX_SELECT_THREADID          (0 << 8)
+#define GEN4_VF_CTL_SNAPSHOT_MUX_SELECT_VF_DEBUG          (1 << 8)
+#define GEN4_VF_CTL_SNAPSHOT_TYPE_VERTEX_SEQUENCE   (0 << 4)
+#define GEN4_VF_CTL_SNAPSHOT_TYPE_VERTEX_INDEX    (1 << 4)
+#define GEN4_VF_CTL_SKIP_INITIAL_PRIMITIVES       (1 << 3)
+#define GEN4_VF_CTL_MAX_PRIMITIVES_LIMIT_ENABLE           (1 << 2)
+#define GEN4_VF_CTL_VERTEX_RANGE_LIMIT_ENABLE     (1 << 1)
+#define GEN4_VF_CTL_SNAPSHOT_ENABLE               (1 << 0)
+
+#define GEN4_VF_STRG_VAL                      0x7504
+#define GEN4_VF_STR_VL_OVR            0x7508
+#define GEN4_VF_VC_OVR                0x750c
+#define GEN4_VF_STR_PSKIP             0x7510
+#define GEN4_VF_MAX_PRIM                      0x7514
+#define GEN4_VF_RDATA                 0x7518
+
+#define GEN4_VS_CTL                   0x7600
+#define GEN4_VS_CTL_SNAPSHOT_COMPLETE             (1 << 31)
+#define GEN4_VS_CTL_SNAPSHOT_MUX_VERTEX_0         (0 << 8)
+#define GEN4_VS_CTL_SNAPSHOT_MUX_VERTEX_1         (1 << 8)
+#define GEN4_VS_CTL_SNAPSHOT_MUX_VALID_COUNT      (2 << 8)
+#define GEN4_VS_CTL_SNAPSHOT_MUX_VS_KERNEL_POINTER  (3 << 8)
+#define GEN4_VS_CTL_SNAPSHOT_ALL_THREADS                  (1 << 2)
+#define GEN4_VS_CTL_THREAD_SNAPSHOT_ENABLE        (1 << 1)
+#define GEN4_VS_CTL_SNAPSHOT_ENABLE               (1 << 0)
+
+#define GEN4_VS_STRG_VAL                      0x7604
+#define GEN4_VS_RDATA                 0x7608
+
+#define GEN4_SF_CTL                   0x7b00
+#define GEN4_SF_CTL_SNAPSHOT_COMPLETE             (1 << 31)
+#define GEN4_SF_CTL_SNAPSHOT_MUX_VERTEX_0_FF_ID           (0 << 8)
+#define GEN4_SF_CTL_SNAPSHOT_MUX_VERTEX_0_REL_COUNT (1 << 8)
+#define GEN4_SF_CTL_SNAPSHOT_MUX_VERTEX_1_FF_ID           (2 << 8)
+#define GEN4_SF_CTL_SNAPSHOT_MUX_VERTEX_1_REL_COUNT (3 << 8)
+#define GEN4_SF_CTL_SNAPSHOT_MUX_VERTEX_2_FF_ID           (4 << 8)
+#define GEN4_SF_CTL_SNAPSHOT_MUX_VERTEX_2_REL_COUNT (5 << 8)
+#define GEN4_SF_CTL_SNAPSHOT_MUX_VERTEX_COUNT     (6 << 8)
+#define GEN4_SF_CTL_SNAPSHOT_MUX_SF_KERNEL_POINTER  (7 << 8)
+#define GEN4_SF_CTL_MIN_MAX_PRIMITIVE_RANGE_ENABLE  (1 << 4)
+#define GEN4_SF_CTL_DEBUG_CLIP_RECTANGLE_ENABLE           (1 << 3)
+#define GEN4_SF_CTL_SNAPSHOT_ALL_THREADS                  (1 << 2)
+#define GEN4_SF_CTL_THREAD_SNAPSHOT_ENABLE        (1 << 1)
+#define GEN4_SF_CTL_SNAPSHOT_ENABLE               (1 << 0)
+
+#define GEN4_SF_STRG_VAL                      0x7b04
+#define GEN4_SF_RDATA                 0x7b18
+
+#define GEN4_WIZ_CTL                  0x7c00
+#define GEN4_WIZ_CTL_SNAPSHOT_COMPLETE            (1 << 31)
+#define GEN4_WIZ_CTL_SUBSPAN_INSTANCE_SHIFT       16
+#define GEN4_WIZ_CTL_SNAPSHOT_MUX_WIZ_KERNEL_POINTER   (0 << 8)
+#define GEN4_WIZ_CTL_SNAPSHOT_MUX_SUBSPAN_INSTANCE     (1 << 8)
+#define GEN4_WIZ_CTL_SNAPSHOT_MUX_PRIMITIVE_SEQUENCE   (2 << 8)
+#define GEN4_WIZ_CTL_SINGLE_SUBSPAN_DISPATCH         (1 << 6)
+#define GEN4_WIZ_CTL_IGNORE_COLOR_SCOREBOARD_STALLS    (1 << 5)
+#define GEN4_WIZ_CTL_ENABLE_SUBSPAN_INSTANCE_COMPARE   (1 << 4)
+#define GEN4_WIZ_CTL_USE_UPSTREAM_SNAPSHOT_FLAG              (1 << 3)
+#define GEN4_WIZ_CTL_SNAPSHOT_ALL_THREADS            (1 << 2)
+#define GEN4_WIZ_CTL_THREAD_SNAPSHOT_ENABLE          (1 << 1)
+#define GEN4_WIZ_CTL_SNAPSHOT_ENABLE                 (1 << 0)
+
+#define GEN4_WIZ_STRG_VAL                            0x7c04
+#define GEN4_WIZ_RDATA                               0x7c18
+
+#define GEN4_TS_CTL                   0x7e00
+#define GEN4_TS_CTL_SNAPSHOT_COMPLETE             (1 << 31)
+#define GEN4_TS_CTL_SNAPSHOT_MESSAGE_ERROR        (0 << 8)
+#define GEN4_TS_CTL_SNAPSHOT_INTERFACE_DESCRIPTOR   (3 << 8)
+#define GEN4_TS_CTL_SNAPSHOT_ALL_CHILD_THREADS    (1 << 2)
+#define GEN4_TS_CTL_SNAPSHOT_ALL_ROOT_THREADS             (1 << 1)
+#define GEN4_TS_CTL_SNAPSHOT_ENABLE               (1 << 0)
+
+#define GEN4_TS_STRG_VAL                      0x7e04
+#define GEN4_TS_RDATA                 0x7e08
+
+#define GEN4_TD_CTL                   0x8000
+#define GEN4_TD_CTL_MUX_SHIFT         8
+#define GEN4_TD_CTL_EXTERNAL_HALT_R0_DEBUG_MATCH          (1 << 7)
+#define GEN4_TD_CTL_FORCE_EXTERNAL_HALT                   (1 << 6)
+#define GEN4_TD_CTL_EXCEPTION_MASK_OVERRIDE       (1 << 5)
+#define GEN4_TD_CTL_FORCE_THREAD_BREAKPOINT_ENABLE  (1 << 4)
+#define GEN4_TD_CTL_BREAKPOINT_ENABLE             (1 << 2)
+#define GEN4_TD_CTL2                  0x8004
+#define GEN4_TD_CTL2_ILLEGAL_OPCODE_EXCEPTION_OVERRIDE (1 << 28)
+#define GEN4_TD_CTL2_MASKSTACK_EXCEPTION_OVERRIDE      (1 << 26)
+#define GEN4_TD_CTL2_SOFTWARE_EXCEPTION_OVERRIDE             (1 << 25)
+#define GEN4_TD_CTL2_ACTIVE_THREAD_LIMIT_SHIFT       16
+#define GEN4_TD_CTL2_ACTIVE_THREAD_LIMIT_ENABLE              (1 << 8)
+#define GEN4_TD_CTL2_THREAD_SPAWNER_EXECUTION_MASK_ENABLE (1 << 7)
+#define GEN4_TD_CTL2_WIZ_EXECUTION_MASK_ENABLE       (1 << 6)
+#define GEN4_TD_CTL2_SF_EXECUTION_MASK_ENABLE        (1 << 5)
+#define GEN4_TD_CTL2_CLIPPER_EXECUTION_MASK_ENABLE     (1 << 4)
+#define GEN4_TD_CTL2_GS_EXECUTION_MASK_ENABLE        (1 << 3)
+#define GEN4_TD_CTL2_VS_EXECUTION_MASK_ENABLE        (1 << 0)
+#define GEN4_TD_VF_VS_EMSK            0x8008
+#define GEN4_TD_GS_EMSK                       0x800c
+#define GEN4_TD_CLIP_EMSK             0x8010
+#define GEN4_TD_SF_EMSK                       0x8014
+#define GEN4_TD_WIZ_EMSK                      0x8018
+#define GEN4_TD_0_6_EHTRG_VAL         0x801c
+#define GEN4_TD_0_7_EHTRG_VAL         0x8020
+#define GEN4_TD_0_6_EHTRG_MSK           0x8024
+#define GEN4_TD_0_7_EHTRG_MSK         0x8028
+#define GEN4_TD_RDATA                 0x802c
+#define GEN4_TD_TS_EMSK                       0x8030
+
+#define GEN4_EU_CTL                   0x8800
+#define GEN4_EU_CTL_SELECT_SHIFT              16
+#define GEN4_EU_CTL_DATA_MUX_SHIFT      8
+#define GEN4_EU_ATT_0                 0x8810
+#define GEN4_EU_ATT_1                 0x8814
+#define GEN4_EU_ATT_DATA_0            0x8820
+#define GEN4_EU_ATT_DATA_1            0x8824
+#define GEN4_EU_ATT_CLR_0             0x8830
+#define GEN4_EU_ATT_CLR_1             0x8834
+#define GEN4_EU_RDATA                 0x8840
+
+/* 3D state:
+ */
+#define _3DOP_3DSTATE_PIPELINED       0x0
+#define _3DOP_3DSTATE_NONPIPELINED    0x1
+#define _3DOP_3DCONTROL               0x2
+#define _3DOP_3DPRIMITIVE             0x3
+
+#define _3DSTATE_PIPELINED_POINTERS       0x00
+#define _3DSTATE_BINDING_TABLE_POINTERS   0x01
+#define _3DSTATE_VERTEX_BUFFERS           0x08
+#define _3DSTATE_VERTEX_ELEMENTS          0x09
+#define _3DSTATE_INDEX_BUFFER             0x0A
+#define _3DSTATE_VF_STATISTICS            0x0B
+#define _3DSTATE_DRAWING_RECTANGLE            0x00
+#define _3DSTATE_CONSTANT_COLOR               0x01
+#define _3DSTATE_SAMPLER_PALETTE_LOAD         0x02
+#define _3DSTATE_CHROMA_KEY                   0x04
+#define _3DSTATE_DEPTH_BUFFER                 0x05
+#define _3DSTATE_POLY_STIPPLE_OFFSET          0x06
+#define _3DSTATE_POLY_STIPPLE_PATTERN         0x07
+#define _3DSTATE_LINE_STIPPLE                 0x08
+#define _3DSTATE_GLOBAL_DEPTH_OFFSET_CLAMP    0x09
+#define _3DCONTROL    0x00
+#define _3DPRIMITIVE  0x00
+
+#define _3DPRIM_POINTLIST         0x01
+#define _3DPRIM_LINELIST          0x02
+#define _3DPRIM_LINESTRIP         0x03
+#define _3DPRIM_TRILIST           0x04
+#define _3DPRIM_TRISTRIP          0x05
+#define _3DPRIM_TRIFAN            0x06
+#define _3DPRIM_QUADLIST          0x07
+#define _3DPRIM_QUADSTRIP         0x08
+#define _3DPRIM_LINELIST_ADJ      0x09
+#define _3DPRIM_LINESTRIP_ADJ     0x0A
+#define _3DPRIM_TRILIST_ADJ       0x0B
+#define _3DPRIM_TRISTRIP_ADJ      0x0C
+#define _3DPRIM_TRISTRIP_REVERSE  0x0D
+#define _3DPRIM_POLYGON           0x0E
+#define _3DPRIM_RECTLIST          0x0F
+#define _3DPRIM_LINELOOP          0x10
+#define _3DPRIM_POINTLIST_BF      0x11
+#define _3DPRIM_LINESTRIP_CONT    0x12
+#define _3DPRIM_LINESTRIP_BF      0x13
+#define _3DPRIM_LINESTRIP_CONT_BF 0x14
+#define _3DPRIM_TRIFAN_NOSTIPPLE  0x15
+
+#define _3DPRIM_VERTEXBUFFER_ACCESS_SEQUENTIAL 0
+#define _3DPRIM_VERTEXBUFFER_ACCESS_RANDOM     1
+
+#define GEN4_ANISORATIO_2     0 
+#define GEN4_ANISORATIO_4     1 
+#define GEN4_ANISORATIO_6     2 
+#define GEN4_ANISORATIO_8     3 
+#define GEN4_ANISORATIO_10    4 
+#define GEN4_ANISORATIO_12    5 
+#define GEN4_ANISORATIO_14    6 
+#define GEN4_ANISORATIO_16    7
+
+#define GEN4_BLENDFACTOR_ONE                 0x1
+#define GEN4_BLENDFACTOR_SRC_COLOR           0x2
+#define GEN4_BLENDFACTOR_SRC_ALPHA           0x3
+#define GEN4_BLENDFACTOR_DST_ALPHA           0x4
+#define GEN4_BLENDFACTOR_DST_COLOR           0x5
+#define GEN4_BLENDFACTOR_SRC_ALPHA_SATURATE  0x6
+#define GEN4_BLENDFACTOR_CONST_COLOR         0x7
+#define GEN4_BLENDFACTOR_CONST_ALPHA         0x8
+#define GEN4_BLENDFACTOR_SRC1_COLOR          0x9
+#define GEN4_BLENDFACTOR_SRC1_ALPHA          0x0A
+#define GEN4_BLENDFACTOR_ZERO                0x11
+#define GEN4_BLENDFACTOR_INV_SRC_COLOR       0x12
+#define GEN4_BLENDFACTOR_INV_SRC_ALPHA       0x13
+#define GEN4_BLENDFACTOR_INV_DST_ALPHA       0x14
+#define GEN4_BLENDFACTOR_INV_DST_COLOR       0x15
+#define GEN4_BLENDFACTOR_INV_CONST_COLOR     0x17
+#define GEN4_BLENDFACTOR_INV_CONST_ALPHA     0x18
+#define GEN4_BLENDFACTOR_INV_SRC1_COLOR      0x19
+#define GEN4_BLENDFACTOR_INV_SRC1_ALPHA      0x1A
+
+#define GEN4_BLENDFUNCTION_ADD               0
+#define GEN4_BLENDFUNCTION_SUBTRACT          1
+#define GEN4_BLENDFUNCTION_REVERSE_SUBTRACT  2
+#define GEN4_BLENDFUNCTION_MIN               3
+#define GEN4_BLENDFUNCTION_MAX               4
+
+#define GEN4_ALPHATEST_FORMAT_UNORM8         0
+#define GEN4_ALPHATEST_FORMAT_FLOAT32        1
+
+#define GEN4_CHROMAKEY_KILL_ON_ANY_MATCH  0
+#define GEN4_CHROMAKEY_REPLACE_BLACK      1
+
+#define GEN4_CLIP_API_OGL     0
+#define GEN4_CLIP_API_DX      1
+
+#define GEN4_CLIPMODE_NORMAL              0
+#define GEN4_CLIPMODE_CLIP_ALL            1
+#define GEN4_CLIPMODE_CLIP_NON_REJECTED   2
+#define GEN4_CLIPMODE_REJECT_ALL          3
+#define GEN4_CLIPMODE_ACCEPT_ALL          4
+
+#define GEN4_CLIP_NDCSPACE     0
+#define GEN4_CLIP_SCREENSPACE  1
+
+#define GEN4_COMPAREFUNCTION_ALWAYS       0
+#define GEN4_COMPAREFUNCTION_NEVER        1
+#define GEN4_COMPAREFUNCTION_LESS         2
+#define GEN4_COMPAREFUNCTION_EQUAL        3
+#define GEN4_COMPAREFUNCTION_LEQUAL       4
+#define GEN4_COMPAREFUNCTION_GREATER      5
+#define GEN4_COMPAREFUNCTION_NOTEQUAL     6
+#define GEN4_COMPAREFUNCTION_GEQUAL       7
+
+#define GEN4_COVERAGE_PIXELS_HALF     0
+#define GEN4_COVERAGE_PIXELS_1        1
+#define GEN4_COVERAGE_PIXELS_2        2
+#define GEN4_COVERAGE_PIXELS_4        3
+
+#define GEN4_CULLMODE_BOTH        0
+#define GEN4_CULLMODE_NONE        1
+#define GEN4_CULLMODE_FRONT       2
+#define GEN4_CULLMODE_BACK        3
+
+#define GEN4_DEFAULTCOLOR_R8G8B8A8_UNORM      0
+#define GEN4_DEFAULTCOLOR_R32G32B32A32_FLOAT  1
+
+#define GEN4_DEPTHFORMAT_D32_FLOAT_S8X24_UINT     0
+#define GEN4_DEPTHFORMAT_D32_FLOAT                1
+#define GEN4_DEPTHFORMAT_D24_UNORM_S8_UINT        2
+#define GEN4_DEPTHFORMAT_D16_UNORM                5
+
+#define GEN4_FLOATING_POINT_IEEE_754        0
+#define GEN4_FLOATING_POINT_NON_IEEE_754    1
+
+#define GEN4_FRONTWINDING_CW      0
+#define GEN4_FRONTWINDING_CCW     1
+
+#define GEN4_INDEX_BYTE     0
+#define GEN4_INDEX_WORD     1
+#define GEN4_INDEX_DWORD    2
+
+#define GEN4_LOGICOPFUNCTION_CLEAR            0
+#define GEN4_LOGICOPFUNCTION_NOR              1
+#define GEN4_LOGICOPFUNCTION_AND_INVERTED     2
+#define GEN4_LOGICOPFUNCTION_COPY_INVERTED    3
+#define GEN4_LOGICOPFUNCTION_AND_REVERSE      4
+#define GEN4_LOGICOPFUNCTION_INVERT           5
+#define GEN4_LOGICOPFUNCTION_XOR              6
+#define GEN4_LOGICOPFUNCTION_NAND             7
+#define GEN4_LOGICOPFUNCTION_AND              8
+#define GEN4_LOGICOPFUNCTION_EQUIV            9
+#define GEN4_LOGICOPFUNCTION_NOOP             10
+#define GEN4_LOGICOPFUNCTION_OR_INVERTED      11
+#define GEN4_LOGICOPFUNCTION_COPY             12
+#define GEN4_LOGICOPFUNCTION_OR_REVERSE       13
+#define GEN4_LOGICOPFUNCTION_OR               14
+#define GEN4_LOGICOPFUNCTION_SET              15  
+
+#define GEN4_MAPFILTER_NEAREST        0x0 
+#define GEN4_MAPFILTER_LINEAR         0x1 
+#define GEN4_MAPFILTER_ANISOTROPIC    0x2
+
+#define GEN4_MIPFILTER_NONE        0   
+#define GEN4_MIPFILTER_NEAREST     1   
+#define GEN4_MIPFILTER_LINEAR      3
+
+#define GEN4_POLYGON_FRONT_FACING     0
+#define GEN4_POLYGON_BACK_FACING      1
+
+#define GEN4_PREFILTER_ALWAYS     0x0 
+#define GEN4_PREFILTER_NEVER      0x1
+#define GEN4_PREFILTER_LESS       0x2
+#define GEN4_PREFILTER_EQUAL      0x3
+#define GEN4_PREFILTER_LEQUAL     0x4
+#define GEN4_PREFILTER_GREATER    0x5
+#define GEN4_PREFILTER_NOTEQUAL   0x6
+#define GEN4_PREFILTER_GEQUAL     0x7
+
+#define GEN4_PROVOKING_VERTEX_0    0
+#define GEN4_PROVOKING_VERTEX_1    1 
+#define GEN4_PROVOKING_VERTEX_2    2
+
+#define GEN4_RASTRULE_UPPER_LEFT  0    
+#define GEN4_RASTRULE_UPPER_RIGHT 1
+
+#define GEN4_RENDERTARGET_CLAMPRANGE_UNORM    0
+#define GEN4_RENDERTARGET_CLAMPRANGE_SNORM    1
+#define GEN4_RENDERTARGET_CLAMPRANGE_FORMAT   2
+
+#define GEN4_STENCILOP_KEEP               0
+#define GEN4_STENCILOP_ZERO               1
+#define GEN4_STENCILOP_REPLACE            2
+#define GEN4_STENCILOP_INCRSAT            3
+#define GEN4_STENCILOP_DECRSAT            4
+#define GEN4_STENCILOP_INCR               5
+#define GEN4_STENCILOP_DECR               6
+#define GEN4_STENCILOP_INVERT             7
+
+#define GEN4_SURFACE_MIPMAPLAYOUT_BELOW   0
+#define GEN4_SURFACE_MIPMAPLAYOUT_RIGHT   1
+
+#define GEN4_SURFACEFORMAT_R32G32B32A32_FLOAT             0x000
+#define GEN4_SURFACEFORMAT_R32G32B32A32_SINT              0x001
+#define GEN4_SURFACEFORMAT_R32G32B32A32_UINT              0x002
+#define GEN4_SURFACEFORMAT_R32G32B32A32_UNORM             0x003
+#define GEN4_SURFACEFORMAT_R32G32B32A32_SNORM             0x004
+#define GEN4_SURFACEFORMAT_R64G64_FLOAT                   0x005
+#define GEN4_SURFACEFORMAT_R32G32B32X32_FLOAT             0x006
+#define GEN4_SURFACEFORMAT_R32G32B32A32_SSCALED           0x007
+#define GEN4_SURFACEFORMAT_R32G32B32A32_USCALED           0x008
+#define GEN4_SURFACEFORMAT_R32G32B32_FLOAT                0x040
+#define GEN4_SURFACEFORMAT_R32G32B32_SINT                 0x041
+#define GEN4_SURFACEFORMAT_R32G32B32_UINT                 0x042
+#define GEN4_SURFACEFORMAT_R32G32B32_UNORM                0x043
+#define GEN4_SURFACEFORMAT_R32G32B32_SNORM                0x044
+#define GEN4_SURFACEFORMAT_R32G32B32_SSCALED              0x045
+#define GEN4_SURFACEFORMAT_R32G32B32_USCALED              0x046
+#define GEN4_SURFACEFORMAT_R16G16B16A16_UNORM             0x080
+#define GEN4_SURFACEFORMAT_R16G16B16A16_SNORM             0x081
+#define GEN4_SURFACEFORMAT_R16G16B16A16_SINT              0x082
+#define GEN4_SURFACEFORMAT_R16G16B16A16_UINT              0x083
+#define GEN4_SURFACEFORMAT_R16G16B16A16_FLOAT             0x084
+#define GEN4_SURFACEFORMAT_R32G32_FLOAT                   0x085
+#define GEN4_SURFACEFORMAT_R32G32_SINT                    0x086
+#define GEN4_SURFACEFORMAT_R32G32_UINT                    0x087
+#define GEN4_SURFACEFORMAT_R32_FLOAT_X8X24_TYPELESS       0x088
+#define GEN4_SURFACEFORMAT_X32_TYPELESS_G8X24_UINT        0x089
+#define GEN4_SURFACEFORMAT_L32A32_FLOAT                   0x08A
+#define GEN4_SURFACEFORMAT_R32G32_UNORM                   0x08B
+#define GEN4_SURFACEFORMAT_R32G32_SNORM                   0x08C
+#define GEN4_SURFACEFORMAT_R64_FLOAT                      0x08D
+#define GEN4_SURFACEFORMAT_R16G16B16X16_UNORM             0x08E
+#define GEN4_SURFACEFORMAT_R16G16B16X16_FLOAT             0x08F
+#define GEN4_SURFACEFORMAT_A32X32_FLOAT                   0x090
+#define GEN4_SURFACEFORMAT_L32X32_FLOAT                   0x091
+#define GEN4_SURFACEFORMAT_I32X32_FLOAT                   0x092
+#define GEN4_SURFACEFORMAT_R16G16B16A16_SSCALED           0x093
+#define GEN4_SURFACEFORMAT_R16G16B16A16_USCALED           0x094
+#define GEN4_SURFACEFORMAT_R32G32_SSCALED                 0x095
+#define GEN4_SURFACEFORMAT_R32G32_USCALED                 0x096
+#define GEN4_SURFACEFORMAT_B8G8R8A8_UNORM                 0x0C0
+#define GEN4_SURFACEFORMAT_B8G8R8A8_UNORM_SRGB            0x0C1
+#define GEN4_SURFACEFORMAT_R10G10B10A2_UNORM              0x0C2
+#define GEN4_SURFACEFORMAT_R10G10B10A2_UNORM_SRGB         0x0C3
+#define GEN4_SURFACEFORMAT_R10G10B10A2_UINT               0x0C4
+#define GEN4_SURFACEFORMAT_R10G10B10_SNORM_A2_UNORM       0x0C5
+#define GEN4_SURFACEFORMAT_R8G8B8A8_UNORM                 0x0C7
+#define GEN4_SURFACEFORMAT_R8G8B8A8_UNORM_SRGB            0x0C8
+#define GEN4_SURFACEFORMAT_R8G8B8A8_SNORM                 0x0C9
+#define GEN4_SURFACEFORMAT_R8G8B8A8_SINT                  0x0CA
+#define GEN4_SURFACEFORMAT_R8G8B8A8_UINT                  0x0CB
+#define GEN4_SURFACEFORMAT_R16G16_UNORM                   0x0CC
+#define GEN4_SURFACEFORMAT_R16G16_SNORM                   0x0CD
+#define GEN4_SURFACEFORMAT_R16G16_SINT                    0x0CE
+#define GEN4_SURFACEFORMAT_R16G16_UINT                    0x0CF
+#define GEN4_SURFACEFORMAT_R16G16_FLOAT                   0x0D0
+#define GEN4_SURFACEFORMAT_B10G10R10A2_UNORM              0x0D1
+#define GEN4_SURFACEFORMAT_B10G10R10A2_UNORM_SRGB         0x0D2
+#define GEN4_SURFACEFORMAT_R11G11B10_FLOAT                0x0D3
+#define GEN4_SURFACEFORMAT_R32_SINT                       0x0D6
+#define GEN4_SURFACEFORMAT_R32_UINT                       0x0D7
+#define GEN4_SURFACEFORMAT_R32_FLOAT                      0x0D8
+#define GEN4_SURFACEFORMAT_R24_UNORM_X8_TYPELESS          0x0D9
+#define GEN4_SURFACEFORMAT_X24_TYPELESS_G8_UINT           0x0DA
+#define GEN4_SURFACEFORMAT_L16A16_UNORM                   0x0DF
+#define GEN4_SURFACEFORMAT_I24X8_UNORM                    0x0E0
+#define GEN4_SURFACEFORMAT_L24X8_UNORM                    0x0E1
+#define GEN4_SURFACEFORMAT_A24X8_UNORM                    0x0E2
+#define GEN4_SURFACEFORMAT_I32_FLOAT                      0x0E3
+#define GEN4_SURFACEFORMAT_L32_FLOAT                      0x0E4
+#define GEN4_SURFACEFORMAT_A32_FLOAT                      0x0E5
+#define GEN4_SURFACEFORMAT_B8G8R8X8_UNORM                 0x0E9
+#define GEN4_SURFACEFORMAT_B8G8R8X8_UNORM_SRGB            0x0EA
+#define GEN4_SURFACEFORMAT_R8G8B8X8_UNORM                 0x0EB
+#define GEN4_SURFACEFORMAT_R8G8B8X8_UNORM_SRGB            0x0EC
+#define GEN4_SURFACEFORMAT_R9G9B9E5_SHAREDEXP             0x0ED
+#define GEN4_SURFACEFORMAT_B10G10R10X2_UNORM              0x0EE
+#define GEN4_SURFACEFORMAT_L16A16_FLOAT                   0x0F0
+#define GEN4_SURFACEFORMAT_R32_UNORM                      0x0F1
+#define GEN4_SURFACEFORMAT_R32_SNORM                      0x0F2
+#define GEN4_SURFACEFORMAT_R10G10B10X2_USCALED            0x0F3
+#define GEN4_SURFACEFORMAT_R8G8B8A8_SSCALED               0x0F4
+#define GEN4_SURFACEFORMAT_R8G8B8A8_USCALED               0x0F5
+#define GEN4_SURFACEFORMAT_R16G16_SSCALED                 0x0F6
+#define GEN4_SURFACEFORMAT_R16G16_USCALED                 0x0F7
+#define GEN4_SURFACEFORMAT_R32_SSCALED                    0x0F8
+#define GEN4_SURFACEFORMAT_R32_USCALED                    0x0F9
+#define GEN4_SURFACEFORMAT_B5G6R5_UNORM                   0x100
+#define GEN4_SURFACEFORMAT_B5G6R5_UNORM_SRGB              0x101
+#define GEN4_SURFACEFORMAT_B5G5R5A1_UNORM                 0x102
+#define GEN4_SURFACEFORMAT_B5G5R5A1_UNORM_SRGB            0x103
+#define GEN4_SURFACEFORMAT_B4G4R4A4_UNORM                 0x104
+#define GEN4_SURFACEFORMAT_B4G4R4A4_UNORM_SRGB            0x105
+#define GEN4_SURFACEFORMAT_R8G8_UNORM                     0x106
+#define GEN4_SURFACEFORMAT_R8G8_SNORM                     0x107
+#define GEN4_SURFACEFORMAT_R8G8_SINT                      0x108
+#define GEN4_SURFACEFORMAT_R8G8_UINT                      0x109
+#define GEN4_SURFACEFORMAT_R16_UNORM                      0x10A
+#define GEN4_SURFACEFORMAT_R16_SNORM                      0x10B
+#define GEN4_SURFACEFORMAT_R16_SINT                       0x10C
+#define GEN4_SURFACEFORMAT_R16_UINT                       0x10D
+#define GEN4_SURFACEFORMAT_R16_FLOAT                      0x10E
+#define GEN4_SURFACEFORMAT_I16_UNORM                      0x111
+#define GEN4_SURFACEFORMAT_L16_UNORM                      0x112
+#define GEN4_SURFACEFORMAT_A16_UNORM                      0x113
+#define GEN4_SURFACEFORMAT_L8A8_UNORM                     0x114
+#define GEN4_SURFACEFORMAT_I16_FLOAT                      0x115
+#define GEN4_SURFACEFORMAT_L16_FLOAT                      0x116
+#define GEN4_SURFACEFORMAT_A16_FLOAT                      0x117
+#define GEN4_SURFACEFORMAT_R5G5_SNORM_B6_UNORM            0x119
+#define GEN4_SURFACEFORMAT_B5G5R5X1_UNORM                 0x11A
+#define GEN4_SURFACEFORMAT_B5G5R5X1_UNORM_SRGB            0x11B
+#define GEN4_SURFACEFORMAT_R8G8_SSCALED                   0x11C
+#define GEN4_SURFACEFORMAT_R8G8_USCALED                   0x11D
+#define GEN4_SURFACEFORMAT_R16_SSCALED                    0x11E
+#define GEN4_SURFACEFORMAT_R16_USCALED                    0x11F
+#define GEN4_SURFACEFORMAT_R8_UNORM                       0x140
+#define GEN4_SURFACEFORMAT_R8_SNORM                       0x141
+#define GEN4_SURFACEFORMAT_R8_SINT                        0x142
+#define GEN4_SURFACEFORMAT_R8_UINT                        0x143
+#define GEN4_SURFACEFORMAT_A8_UNORM                       0x144
+#define GEN4_SURFACEFORMAT_I8_UNORM                       0x145
+#define GEN4_SURFACEFORMAT_L8_UNORM                       0x146
+#define GEN4_SURFACEFORMAT_P4A4_UNORM                     0x147
+#define GEN4_SURFACEFORMAT_A4P4_UNORM                     0x148
+#define GEN4_SURFACEFORMAT_R8_SSCALED                     0x149
+#define GEN4_SURFACEFORMAT_R8_USCALED                     0x14A
+#define GEN4_SURFACEFORMAT_R1_UINT                        0x181
+#define GEN4_SURFACEFORMAT_YCRCB_NORMAL                   0x182
+#define GEN4_SURFACEFORMAT_YCRCB_SWAPUVY                  0x183
+#define GEN4_SURFACEFORMAT_BC1_UNORM                      0x186
+#define GEN4_SURFACEFORMAT_BC2_UNORM                      0x187
+#define GEN4_SURFACEFORMAT_BC3_UNORM                      0x188
+#define GEN4_SURFACEFORMAT_BC4_UNORM                      0x189
+#define GEN4_SURFACEFORMAT_BC5_UNORM                      0x18A
+#define GEN4_SURFACEFORMAT_BC1_UNORM_SRGB                 0x18B
+#define GEN4_SURFACEFORMAT_BC2_UNORM_SRGB                 0x18C
+#define GEN4_SURFACEFORMAT_BC3_UNORM_SRGB                 0x18D
+#define GEN4_SURFACEFORMAT_MONO8                          0x18E
+#define GEN4_SURFACEFORMAT_YCRCB_SWAPUV                   0x18F
+#define GEN4_SURFACEFORMAT_YCRCB_SWAPY                    0x190
+#define GEN4_SURFACEFORMAT_DXT1_RGB                       0x191
+#define GEN4_SURFACEFORMAT_FXT1                           0x192
+#define GEN4_SURFACEFORMAT_R8G8B8_UNORM                   0x193
+#define GEN4_SURFACEFORMAT_R8G8B8_SNORM                   0x194
+#define GEN4_SURFACEFORMAT_R8G8B8_SSCALED                 0x195
+#define GEN4_SURFACEFORMAT_R8G8B8_USCALED                 0x196
+#define GEN4_SURFACEFORMAT_R64G64B64A64_FLOAT             0x197
+#define GEN4_SURFACEFORMAT_R64G64B64_FLOAT                0x198
+#define GEN4_SURFACEFORMAT_BC4_SNORM                      0x199
+#define GEN4_SURFACEFORMAT_BC5_SNORM                      0x19A
+#define GEN4_SURFACEFORMAT_R16G16B16_UNORM                0x19C
+#define GEN4_SURFACEFORMAT_R16G16B16_SNORM                0x19D
+#define GEN4_SURFACEFORMAT_R16G16B16_SSCALED              0x19E
+#define GEN4_SURFACEFORMAT_R16G16B16_USCALED              0x19F
+
+#define GEN4_SURFACERETURNFORMAT_FLOAT32  0
+#define GEN4_SURFACERETURNFORMAT_S1       1
+
+#define GEN4_SURFACE_1D      0
+#define GEN4_SURFACE_2D      1
+#define GEN4_SURFACE_3D      2
+#define GEN4_SURFACE_CUBE    3
+#define GEN4_SURFACE_BUFFER  4
+#define GEN4_SURFACE_NULL    7
+
+#define GEN4_BORDER_COLOR_MODE_DEFAULT 0
+#define GEN4_BORDER_COLOR_MODE_LEGACY  1
+
+#define GEN4_TEXCOORDMODE_WRAP            0
+#define GEN4_TEXCOORDMODE_MIRROR          1
+#define GEN4_TEXCOORDMODE_CLAMP           2
+#define GEN4_TEXCOORDMODE_CUBE            3
+#define GEN4_TEXCOORDMODE_CLAMP_BORDER    4
+#define GEN4_TEXCOORDMODE_MIRROR_ONCE     5
+
+#define GEN4_THREAD_PRIORITY_NORMAL   0
+#define GEN4_THREAD_PRIORITY_HIGH     1
+
+#define GEN4_TILEWALK_XMAJOR                 0
+#define GEN4_TILEWALK_YMAJOR                 1
+
+#define GEN4_VERTEX_SUBPIXEL_PRECISION_8BITS  0
+#define GEN4_VERTEX_SUBPIXEL_PRECISION_4BITS  1
+
+#define GEN4_VERTEXBUFFER_ACCESS_VERTEXDATA     0
+#define GEN4_VERTEXBUFFER_ACCESS_INSTANCEDATA   1
+
+#define GEN4_VFCOMPONENT_NOSTORE      0
+#define GEN4_VFCOMPONENT_STORE_SRC    1
+#define GEN4_VFCOMPONENT_STORE_0      2
+#define GEN4_VFCOMPONENT_STORE_1_FLT  3
+#define GEN4_VFCOMPONENT_STORE_1_INT  4
+#define GEN4_VFCOMPONENT_STORE_VID    5
+#define GEN4_VFCOMPONENT_STORE_IID    6
+#define GEN4_VFCOMPONENT_STORE_PID    7
+
+
+
+/* Execution Unit (EU) defines
+ */
+
+#define GEN4_ALIGN_1   0
+#define GEN4_ALIGN_16  1
+
+#define GEN4_ADDRESS_DIRECT                        0
+#define GEN4_ADDRESS_REGISTER_INDIRECT_REGISTER    1
+
+#define GEN4_CHANNEL_X     0
+#define GEN4_CHANNEL_Y     1
+#define GEN4_CHANNEL_Z     2
+#define GEN4_CHANNEL_W     3
+
+#define GEN4_COMPRESSION_NONE          0
+#define GEN4_COMPRESSION_2NDHALF       1
+#define GEN4_COMPRESSION_COMPRESSED    2
+
+#define GEN4_CONDITIONAL_NONE  0
+#define GEN4_CONDITIONAL_Z     1
+#define GEN4_CONDITIONAL_NZ    2
+#define GEN4_CONDITIONAL_EQ    1       /* Z */
+#define GEN4_CONDITIONAL_NEQ   2       /* NZ */
+#define GEN4_CONDITIONAL_G     3
+#define GEN4_CONDITIONAL_GE    4
+#define GEN4_CONDITIONAL_L     5
+#define GEN4_CONDITIONAL_LE    6
+#define GEN4_CONDITIONAL_C     7
+#define GEN4_CONDITIONAL_O     8
+
+#define GEN4_DEBUG_NONE        0
+#define GEN4_DEBUG_BREAKPOINT  1
+
+#define GEN4_DEPENDENCY_NORMAL         0
+#define GEN4_DEPENDENCY_NOTCLEARED     1
+#define GEN4_DEPENDENCY_NOTCHECKED     2
+#define GEN4_DEPENDENCY_DISABLE        3
+
+#define GEN4_EXECUTE_1     0
+#define GEN4_EXECUTE_2     1
+#define GEN4_EXECUTE_4     2
+#define GEN4_EXECUTE_8     3
+#define GEN4_EXECUTE_16    4
+#define GEN4_EXECUTE_32    5
+
+#define GEN4_HORIZONTAL_STRIDE_0   0
+#define GEN4_HORIZONTAL_STRIDE_1   1
+#define GEN4_HORIZONTAL_STRIDE_2   2
+#define GEN4_HORIZONTAL_STRIDE_4   3
+
+#define GEN4_INSTRUCTION_NORMAL    0
+#define GEN4_INSTRUCTION_SATURATE  1
+
+#define GEN4_MASK_ENABLE   0
+#define GEN4_MASK_DISABLE  1
+
+#define GEN4_OPCODE_MOV        1
+#define GEN4_OPCODE_SEL        2
+#define GEN4_OPCODE_NOT        4
+#define GEN4_OPCODE_AND        5
+#define GEN4_OPCODE_OR         6
+#define GEN4_OPCODE_XOR        7
+#define GEN4_OPCODE_SHR        8
+#define GEN4_OPCODE_SHL        9
+#define GEN4_OPCODE_RSR        10
+#define GEN4_OPCODE_RSL        11
+#define GEN4_OPCODE_ASR        12
+#define GEN4_OPCODE_CMP        16
+#define GEN4_OPCODE_JMPI       32
+#define GEN4_OPCODE_IF         34
+#define GEN4_OPCODE_IFF        35
+#define GEN4_OPCODE_ELSE       36
+#define GEN4_OPCODE_ENDIF      37
+#define GEN4_OPCODE_DO         38
+#define GEN4_OPCODE_WHILE      39
+#define GEN4_OPCODE_BREAK      40
+#define GEN4_OPCODE_CONTINUE   41
+#define GEN4_OPCODE_HALT       42
+#define GEN4_OPCODE_MSAVE      44
+#define GEN4_OPCODE_MRESTORE   45
+#define GEN4_OPCODE_PUSH       46
+#define GEN4_OPCODE_POP        47
+#define GEN4_OPCODE_WAIT       48
+#define GEN4_OPCODE_SEND       49
+#define GEN4_OPCODE_ADD        64
+#define GEN4_OPCODE_MUL        65
+#define GEN4_OPCODE_AVG        66
+#define GEN4_OPCODE_FRC        67
+#define GEN4_OPCODE_RNDU       68
+#define GEN4_OPCODE_RNDD       69
+#define GEN4_OPCODE_RNDE       70
+#define GEN4_OPCODE_RNDZ       71
+#define GEN4_OPCODE_MAC        72
+#define GEN4_OPCODE_MACH       73
+#define GEN4_OPCODE_LZD        74
+#define GEN4_OPCODE_SAD2       80
+#define GEN4_OPCODE_SADA2      81
+#define GEN4_OPCODE_DP4        84
+#define GEN4_OPCODE_DPH        85
+#define GEN4_OPCODE_DP3        86
+#define GEN4_OPCODE_DP2        87
+#define GEN4_OPCODE_DPA2       88
+#define GEN4_OPCODE_LINE       89
+#define GEN4_OPCODE_NOP        126
+
+#define GEN4_PREDICATE_NONE             0
+#define GEN4_PREDICATE_NORMAL           1
+#define GEN4_PREDICATE_ALIGN1_ANYV             2
+#define GEN4_PREDICATE_ALIGN1_ALLV             3
+#define GEN4_PREDICATE_ALIGN1_ANY2H            4
+#define GEN4_PREDICATE_ALIGN1_ALL2H            5
+#define GEN4_PREDICATE_ALIGN1_ANY4H            6
+#define GEN4_PREDICATE_ALIGN1_ALL4H            7
+#define GEN4_PREDICATE_ALIGN1_ANY8H            8
+#define GEN4_PREDICATE_ALIGN1_ALL8H            9
+#define GEN4_PREDICATE_ALIGN1_ANY16H           10
+#define GEN4_PREDICATE_ALIGN1_ALL16H           11
+#define GEN4_PREDICATE_ALIGN16_REPLICATE_X     2
+#define GEN4_PREDICATE_ALIGN16_REPLICATE_Y     3
+#define GEN4_PREDICATE_ALIGN16_REPLICATE_Z     4
+#define GEN4_PREDICATE_ALIGN16_REPLICATE_W     5
+#define GEN4_PREDICATE_ALIGN16_ANY4H           6
+#define GEN4_PREDICATE_ALIGN16_ALL4H           7
+
+#define GEN4_ARCHITECTURE_REGISTER_FILE    0
+#define GEN4_GENERAL_REGISTER_FILE         1
+#define GEN4_MESSAGE_REGISTER_FILE         2
+#define GEN4_IMMEDIATE_VALUE               3
+
+#define GEN4_REGISTER_TYPE_UD  0
+#define GEN4_REGISTER_TYPE_D   1
+#define GEN4_REGISTER_TYPE_UW  2
+#define GEN4_REGISTER_TYPE_W   3
+#define GEN4_REGISTER_TYPE_UB  4
+#define GEN4_REGISTER_TYPE_B   5
+#define GEN4_REGISTER_TYPE_VF  5       /* packed float vector, immediates only? */
+#define GEN4_REGISTER_TYPE_HF  6
+#define GEN4_REGISTER_TYPE_V   6       /* packed int vector, immediates only, uword dest only */
+#define GEN4_REGISTER_TYPE_F   7
+
+#define GEN4_ARF_NULL                  0x00
+#define GEN4_ARF_ADDRESS               0x10
+#define GEN4_ARF_ACCUMULATOR           0x20   
+#define GEN4_ARF_FLAG                  0x30
+#define GEN4_ARF_MASK                  0x40
+#define GEN4_ARF_MASK_STACK            0x50
+#define GEN4_ARF_MASK_STACK_DEPTH      0x60
+#define GEN4_ARF_STATE                 0x70
+#define GEN4_ARF_CONTROL               0x80
+#define GEN4_ARF_NOTIFICATION_COUNT    0x90
+#define GEN4_ARF_IP                    0xA0
+
+#define GEN4_AMASK   0
+#define GEN4_IMASK   1
+#define GEN4_LMASK   2
+#define GEN4_CMASK   3
+
+
+
+#define GEN4_THREAD_NORMAL     0
+#define GEN4_THREAD_ATOMIC     1
+#define GEN4_THREAD_SWITCH     2
+
+#define GEN4_VERTICAL_STRIDE_0                 0
+#define GEN4_VERTICAL_STRIDE_1                 1
+#define GEN4_VERTICAL_STRIDE_2                 2
+#define GEN4_VERTICAL_STRIDE_4                 3
+#define GEN4_VERTICAL_STRIDE_8                 4
+#define GEN4_VERTICAL_STRIDE_16                5
+#define GEN4_VERTICAL_STRIDE_32                6
+#define GEN4_VERTICAL_STRIDE_64                7
+#define GEN4_VERTICAL_STRIDE_128               8
+#define GEN4_VERTICAL_STRIDE_256               9
+#define GEN4_VERTICAL_STRIDE_ONE_DIMENSIONAL   0xF
+
+#define GEN4_WIDTH_1       0
+#define GEN4_WIDTH_2       1
+#define GEN4_WIDTH_4       2
+#define GEN4_WIDTH_8       3
+#define GEN4_WIDTH_16      4
+
+#define GEN4_STATELESS_BUFFER_BOUNDARY_1K      0
+#define GEN4_STATELESS_BUFFER_BOUNDARY_2K      1
+#define GEN4_STATELESS_BUFFER_BOUNDARY_4K      2
+#define GEN4_STATELESS_BUFFER_BOUNDARY_8K      3
+#define GEN4_STATELESS_BUFFER_BOUNDARY_16K     4
+#define GEN4_STATELESS_BUFFER_BOUNDARY_32K     5
+#define GEN4_STATELESS_BUFFER_BOUNDARY_64K     6
+#define GEN4_STATELESS_BUFFER_BOUNDARY_128K    7
+#define GEN4_STATELESS_BUFFER_BOUNDARY_256K    8
+#define GEN4_STATELESS_BUFFER_BOUNDARY_512K    9
+#define GEN4_STATELESS_BUFFER_BOUNDARY_1M      10
+#define GEN4_STATELESS_BUFFER_BOUNDARY_2M      11
+
+#define GEN4_POLYGON_FACING_FRONT      0
+#define GEN4_POLYGON_FACING_BACK       1
+
+#define GEN4_MESSAGE_TARGET_NULL               0
+#define GEN4_MESSAGE_TARGET_MATH               1
+#define GEN4_MESSAGE_TARGET_SAMPLER            2
+#define GEN4_MESSAGE_TARGET_GATEWAY            3
+#define GEN4_MESSAGE_TARGET_DATAPORT_READ      4
+#define GEN4_MESSAGE_TARGET_DATAPORT_WRITE     5
+#define GEN4_MESSAGE_TARGET_URB                6
+#define GEN4_MESSAGE_TARGET_THREAD_SPAWNER     7
+
+#define GEN4_SAMPLER_RETURN_FORMAT_FLOAT32     0
+#define GEN4_SAMPLER_RETURN_FORMAT_UINT32      2
+#define GEN4_SAMPLER_RETURN_FORMAT_SINT32      3
+
+#define GEN4_SAMPLER_MESSAGE_SIMD8_SAMPLE              0
+#define GEN4_SAMPLER_MESSAGE_SIMD16_SAMPLE             0
+#define GEN4_SAMPLER_MESSAGE_SIMD16_SAMPLE_BIAS        0
+#define GEN4_SAMPLER_MESSAGE_SIMD8_KILLPIX             1
+#define GEN4_SAMPLER_MESSAGE_SIMD4X2_SAMPLE_LOD        1
+#define GEN4_SAMPLER_MESSAGE_SIMD16_SAMPLE_LOD         1
+#define GEN4_SAMPLER_MESSAGE_SIMD4X2_SAMPLE_GRADIENTS  2
+#define GEN4_SAMPLER_MESSAGE_SIMD8_SAMPLE_GRADIENTS    2
+#define GEN4_SAMPLER_MESSAGE_SIMD4X2_SAMPLE_COMPARE    0
+#define GEN4_SAMPLER_MESSAGE_SIMD16_SAMPLE_COMPARE     2
+#define GEN4_SAMPLER_MESSAGE_SIMD4X2_RESINFO           2
+#define GEN4_SAMPLER_MESSAGE_SIMD8_RESINFO             2
+#define GEN4_SAMPLER_MESSAGE_SIMD16_RESINFO            2
+#define GEN4_SAMPLER_MESSAGE_SIMD4X2_LD                3
+#define GEN4_SAMPLER_MESSAGE_SIMD8_LD                  3
+#define GEN4_SAMPLER_MESSAGE_SIMD16_LD                 3
+
+#define GEN4_DATAPORT_OWORD_BLOCK_1_OWORDLOW   0
+#define GEN4_DATAPORT_OWORD_BLOCK_1_OWORDHIGH  1
+#define GEN4_DATAPORT_OWORD_BLOCK_2_OWORDS     2
+#define GEN4_DATAPORT_OWORD_BLOCK_4_OWORDS     3
+#define GEN4_DATAPORT_OWORD_BLOCK_8_OWORDS     4
+
+#define GEN4_DATAPORT_OWORD_DUAL_BLOCK_1OWORD     0
+#define GEN4_DATAPORT_OWORD_DUAL_BLOCK_4OWORDS    2
+
+#define GEN4_DATAPORT_DWORD_SCATTERED_BLOCK_8DWORDS   2
+#define GEN4_DATAPORT_DWORD_SCATTERED_BLOCK_16DWORDS  3
+
+#define GEN4_DATAPORT_READ_MESSAGE_OWORD_BLOCK_READ          0
+#define GEN4_DATAPORT_READ_MESSAGE_OWORD_DUAL_BLOCK_READ     1
+#define GEN4_DATAPORT_READ_MESSAGE_DWORD_BLOCK_READ          2
+#define GEN4_DATAPORT_READ_MESSAGE_DWORD_SCATTERED_READ      3
+
+#define GEN4_DATAPORT_READ_TARGET_DATA_CACHE      0
+#define GEN4_DATAPORT_READ_TARGET_RENDER_CACHE    1
+#define GEN4_DATAPORT_READ_TARGET_SAMPLER_CACHE   2
+
+#define GEN4_DATAPORT_RENDER_TARGET_WRITE_SIMD16_SINGLE_SOURCE                0
+#define GEN4_DATAPORT_RENDER_TARGET_WRITE_SIMD16_SINGLE_SOURCE_REPLICATED     1
+#define GEN4_DATAPORT_RENDER_TARGET_WRITE_SIMD8_DUAL_SOURCE_SUBSPAN01         2
+#define GEN4_DATAPORT_RENDER_TARGET_WRITE_SIMD8_DUAL_SOURCE_SUBSPAN23         3
+#define GEN4_DATAPORT_RENDER_TARGET_WRITE_SIMD8_SINGLE_SOURCE_SUBSPAN01       4
+
+#define GEN4_DATAPORT_WRITE_MESSAGE_OWORD_BLOCK_WRITE                0
+#define GEN4_DATAPORT_WRITE_MESSAGE_OWORD_DUAL_BLOCK_WRITE           1
+#define GEN4_DATAPORT_WRITE_MESSAGE_DWORD_BLOCK_WRITE                2
+#define GEN4_DATAPORT_WRITE_MESSAGE_DWORD_SCATTERED_WRITE            3
+#define GEN4_DATAPORT_WRITE_MESSAGE_RENDER_TARGET_WRITE              4
+#define GEN4_DATAPORT_WRITE_MESSAGE_STREAMED_VERTEX_BUFFER_WRITE     5
+#define GEN4_DATAPORT_WRITE_MESSAGE_FLUSH_RENDER_CACHE               7
+
+#define GEN4_MATH_FUNCTION_INV                              1
+#define GEN4_MATH_FUNCTION_LOG                              2
+#define GEN4_MATH_FUNCTION_EXP                              3
+#define GEN4_MATH_FUNCTION_SQRT                             4
+#define GEN4_MATH_FUNCTION_RSQ                              5
+#define GEN4_MATH_FUNCTION_SIN                              6 /* was 7 */
+#define GEN4_MATH_FUNCTION_COS                              7 /* was 8 */
+#define GEN4_MATH_FUNCTION_SINCOS                           8 /* was 6 */
+#define GEN4_MATH_FUNCTION_TAN                              9
+#define GEN4_MATH_FUNCTION_POW                              10
+#define GEN4_MATH_FUNCTION_INT_DIV_QUOTIENT_AND_REMAINDER   11
+#define GEN4_MATH_FUNCTION_INT_DIV_QUOTIENT                 12
+#define GEN4_MATH_FUNCTION_INT_DIV_REMAINDER                13
+
+#define GEN4_MATH_INTEGER_UNSIGNED     0
+#define GEN4_MATH_INTEGER_SIGNED       1
+
+#define GEN4_MATH_PRECISION_FULL        0
+#define GEN4_MATH_PRECISION_PARTIAL     1
+
+#define GEN4_MATH_SATURATE_NONE         0
+#define GEN4_MATH_SATURATE_SATURATE     1
+
+#define GEN4_MATH_DATA_VECTOR  0
+#define GEN4_MATH_DATA_SCALAR  1
+
+#define GEN4_URB_OPCODE_WRITE  0
+
+#define GEN4_URB_SWIZZLE_NONE          0
+#define GEN4_URB_SWIZZLE_INTERLEAVE    1
+#define GEN4_URB_SWIZZLE_TRANSPOSE     2
+
+#define GEN4_SCRATCH_SPACE_SIZE_1K     0
+#define GEN4_SCRATCH_SPACE_SIZE_2K     1
+#define GEN4_SCRATCH_SPACE_SIZE_4K     2
+#define GEN4_SCRATCH_SPACE_SIZE_8K     3
+#define GEN4_SCRATCH_SPACE_SIZE_16K    4
+#define GEN4_SCRATCH_SPACE_SIZE_32K    5
+#define GEN4_SCRATCH_SPACE_SIZE_64K    6
+#define GEN4_SCRATCH_SPACE_SIZE_128K   7
+#define GEN4_SCRATCH_SPACE_SIZE_256K   8
+#define GEN4_SCRATCH_SPACE_SIZE_512K   9
+#define GEN4_SCRATCH_SPACE_SIZE_1M     10
+#define GEN4_SCRATCH_SPACE_SIZE_2M     11
+
+
+
+
+#define CMD_URB_FENCE                 0x6000
+#define CMD_CONST_BUFFER_STATE        0x6001
+#define CMD_CONST_BUFFER              0x6002
+
+#define CMD_STATE_BASE_ADDRESS        0x6101
+#define CMD_STATE_INSN_POINTER        0x6102
+#define CMD_PIPELINE_SELECT           0x6104
+
+#define CMD_PIPELINED_STATE_POINTERS  0x7800
+#define CMD_BINDING_TABLE_PTRS        0x7801
+#define CMD_VERTEX_BUFFER             0x7808
+#define CMD_VERTEX_ELEMENT            0x7809
+#define CMD_INDEX_BUFFER              0x780a
+#define CMD_VF_STATISTICS             0x780b
+
+#define CMD_DRAW_RECT                 0x7900
+#define CMD_BLEND_CONSTANT_COLOR      0x7901
+#define CMD_CHROMA_KEY                0x7904
+#define CMD_DEPTH_BUFFER              0x7905
+#define CMD_POLY_STIPPLE_OFFSET       0x7906
+#define CMD_POLY_STIPPLE_PATTERN      0x7907
+#define CMD_LINE_STIPPLE_PATTERN      0x7908
+#define CMD_GLOBAL_DEPTH_OFFSET_CLAMP 0x7908
+
+#define CMD_PIPE_CONTROL              0x7a00
+
+#define CMD_3D_PRIM                   0x7b00
+
+#define CMD_MI_FLUSH                  0x0200
+
+
+/* Various values from the R0 vertex header:
+ */
+#define R02_PRIM_END    0x1
+#define R02_PRIM_START  0x2
+
+/* media pipeline */
+
+#define GEN4_VFE_MODE_GENERIC          0x0
+#define GEN4_VFE_MODE_VLD_MPEG2                0x1
+#define GEN4_VFE_MODE_IS                       0x2
+#define GEN4_VFE_MODE_AVC_MC           0x4
+#define GEN4_VFE_MODE_AVC_IT           0x7
+#define GEN4_VFE_MODE_VC1_IT           0xB
+
+#define GEN4_VFE_DEBUG_COUNTER_FREE    0
+#define GEN4_VFE_DEBUG_COUNTER_FROZEN  1
+#define GEN4_VFE_DEBUG_COUNTER_ONCE    2
+#define GEN4_VFE_DEBUG_COUNTER_ALWAYS  3
+
+/* VLD_STATE */
+#define GEN4_MPEG_TOP_FIELD            1
+#define GEN4_MPEG_BOTTOM_FIELD         2
+#define GEN4_MPEG_FRAME                        3
+#define GEN4_MPEG_QSCALE_LINEAR                0
+#define GEN4_MPEG_QSCALE_NONLINEAR     1
+#define GEN4_MPEG_ZIGZAG_SCAN          0
+#define GEN4_MPEG_ALTER_VERTICAL_SCAN  1
+#define GEN4_MPEG_I_PICTURE            1
+#define GEN4_MPEG_P_PICTURE            2
+#define GEN4_MPEG_B_PICTURE            3
+
+/* Command packets:
+ */
+struct header
+{
+   unsigned int length:16;
+   unsigned int opcode:16;
+};
+
+
+union header_union
+{
+   struct header bits;
+   unsigned int dword;
+};
+
+struct gen4_3d_control
+{   
+   struct 
+   {
+      unsigned int length:8;
+      unsigned int notify_enable:1;
+      unsigned int pad:3;
+      unsigned int wc_flush_enable:1; 
+      unsigned int depth_stall_enable:1; 
+      unsigned int operation:2; 
+      unsigned int opcode:16; 
+   } header;
+   
+   struct
+   {
+      unsigned int pad:2;
+      unsigned int dest_addr_type:1; 
+      unsigned int dest_addr:29; 
+   } dest;
+   
+   unsigned int dword2;   
+   unsigned int dword3;   
+};
+
+
+struct gen4_3d_primitive
+{
+   struct
+   {
+      unsigned int length:8; 
+      unsigned int pad:2;
+      unsigned int topology:5; 
+      unsigned int indexed:1; 
+      unsigned int opcode:16; 
+   } header;
+
+   unsigned int verts_per_instance;  
+   unsigned int start_vert_location;  
+   unsigned int instance_count;  
+   unsigned int start_instance_location;  
+   unsigned int base_vert_location;  
+};
+
+/* These seem to be passed around as function args, so it works out
+ * better to keep them as #defines:
+ */
+#define GEN4_FLUSH_READ_CACHE           0x1
+#define GEN4_FLUSH_STATE_CACHE          0x2
+#define GEN4_INHIBIT_FLUSH_RENDER_CACHE 0x4
+#define GEN4_FLUSH_SNAPSHOT_COUNTERS    0x8
+
+struct gen4_mi_flush
+{
+   unsigned int flags:4;
+   unsigned int pad:12;
+   unsigned int opcode:16;
+};
+
+struct gen4_vf_statistics
+{
+   unsigned int statistics_enable:1;
+   unsigned int pad:15;
+   unsigned int opcode:16;
+};
+
+
+
+struct gen4_binding_table_pointers
+{
+   struct header header;
+   unsigned int vs; 
+   unsigned int gs; 
+   unsigned int clp; 
+   unsigned int sf; 
+   unsigned int wm; 
+};
+
+
+struct gen4_blend_constant_color
+{
+   struct header header;
+   float blend_constant_color[4];  
+};
+
+
+struct gen4_depthbuffer
+{
+   union header_union header;
+   
+   union {
+      struct {
+        unsigned int pitch:18; 
+        unsigned int format:3; 
+        unsigned int pad:4;
+        unsigned int depth_offset_disable:1; 
+        unsigned int tile_walk:1; 
+        unsigned int tiled_surface:1; 
+        unsigned int pad2:1;
+        unsigned int surface_type:3; 
+      } bits;
+      unsigned int dword;
+   } dword1;
+   
+   unsigned int dword2_base_addr; 
+   union {
+      struct {
+        unsigned int pad:1;
+        unsigned int mipmap_layout:1; 
+        unsigned int lod:4; 
+        unsigned int width:13; 
+        unsigned int height:13; 
+      } bits;
+      unsigned int dword;
+   } dword3;
+
+   union {
+      struct {
+        unsigned int pad:12;
+        unsigned int min_array_element:9; 
+        unsigned int depth:11; 
+      } bits;
+      unsigned int dword;
+   } dword4;
+};
+
+struct gen4_drawrect
+{
+   struct header header;
+   unsigned int xmin:16; 
+   unsigned int ymin:16; 
+   unsigned int xmax:16; 
+   unsigned int ymax:16; 
+   unsigned int xorg:16;  
+   unsigned int yorg:16;  
+};
+
+
+
+
+struct gen4_global_depth_offset_clamp
+{
+   struct header header;
+   float depth_offset_clamp;  
+};
+
+struct gen4_indexbuffer
+{   
+   union {
+      struct
+      {
+        unsigned int length:8; 
+        unsigned int index_format:2; 
+        unsigned int cut_index_enable:1; 
+        unsigned int pad:5; 
+        unsigned int opcode:16; 
+      } bits;
+      unsigned int dword;
+
+   } header;
+
+   unsigned int buffer_start; 
+   unsigned int buffer_end; 
+};
+
+
+struct gen4_line_stipple
+{   
+   struct header header;
+  
+   struct
+   {
+      unsigned int pattern:16; 
+      unsigned int pad:16;
+   } bits0;
+   
+   struct
+   {
+      unsigned int repeat_count:9; 
+      unsigned int pad:7;
+      unsigned int inverse_repeat_count:16; 
+   } bits1;
+};
+
+
+struct gen4_pipelined_state_pointers
+{
+   struct header header;
+   
+   struct {
+      unsigned int pad:5;
+      unsigned int offset:27; 
+   } vs;
+   
+   struct
+   {
+      unsigned int enable:1;
+      unsigned int pad:4;
+      unsigned int offset:27; 
+   } gs;
+   
+   struct
+   {
+      unsigned int enable:1;
+      unsigned int pad:4;
+      unsigned int offset:27; 
+   } clp;
+   
+   struct
+   {
+      unsigned int pad:5;
+      unsigned int offset:27; 
+   } sf;
+
+   struct
+   {
+      unsigned int pad:5;
+      unsigned int offset:27; 
+   } wm;
+   
+   struct
+   {
+      unsigned int pad:5;
+      unsigned int offset:27; /* KW: check me! */
+   } cc;
+};
+
+
+struct gen4_polygon_stipple_offset
+{
+   struct header header;
+
+   struct {
+      unsigned int y_offset:5; 
+      unsigned int pad:3;
+      unsigned int x_offset:5; 
+      unsigned int pad0:19;
+   } bits0;
+};
+
+
+
+struct gen4_polygon_stipple
+{
+   struct header header;
+   unsigned int stipple[32];
+};
+
+
+
+struct gen4_pipeline_select
+{
+   struct
+   {
+      unsigned int pipeline_select:1;   
+      unsigned int pad:15;
+      unsigned int opcode:16;   
+   } header;
+};
+
+
+struct gen4_pipe_control
+{
+   struct
+   {
+      unsigned int length:8;
+      unsigned int notify_enable:1;
+      unsigned int pad:2;
+      unsigned int instruction_state_cache_flush_enable:1;
+      unsigned int write_cache_flush_enable:1;
+      unsigned int depth_stall_enable:1;
+      unsigned int post_sync_operation:2;
+
+      unsigned int opcode:16;
+   } header;
+
+   struct
+   {
+      unsigned int pad:2;
+      unsigned int dest_addr_type:1;
+      unsigned int dest_addr:29;
+   } bits1;
+
+   unsigned int data0;
+   unsigned int data1;
+};
+
+
+struct gen4_urb_fence
+{
+   struct
+   {
+      unsigned int length:8;   
+      unsigned int vs_realloc:1;   
+      unsigned int gs_realloc:1;   
+      unsigned int clp_realloc:1;   
+      unsigned int sf_realloc:1;   
+      unsigned int vfe_realloc:1;   
+      unsigned int cs_realloc:1;   
+      unsigned int pad:2;
+      unsigned int opcode:16;   
+   } header;
+
+   struct
+   {
+      unsigned int vs_fence:10;  
+      unsigned int gs_fence:10;  
+      unsigned int clp_fence:10;  
+      unsigned int pad:2;
+   } bits0;
+
+   struct
+   {
+      unsigned int sf_fence:10;  
+      unsigned int vf_fence:10;  
+      unsigned int cs_fence:10;  
+      unsigned int pad:2;
+   } bits1;
+};
+
+struct gen4_constant_buffer_state /* previously gen4_command_streamer */
+{
+   struct header header;
+
+   struct
+   {
+      unsigned int nr_urb_entries:3;   
+      unsigned int pad:1;
+      unsigned int urb_entry_size:5;   
+      unsigned int pad0:23;
+   } bits0;
+};
+
+struct gen4_constant_buffer
+{
+   struct
+   {
+      unsigned int length:8;   
+      unsigned int valid:1;   
+      unsigned int pad:7;
+      unsigned int opcode:16;   
+   } header;
+
+   struct
+   {
+      unsigned int buffer_length:6;   
+      unsigned int buffer_address:26;  
+   } bits0;
+};
+
+struct gen4_state_base_address
+{
+   struct header header;
+
+   struct
+   {
+      unsigned int modify_enable:1;
+      unsigned int pad:4;
+      unsigned int general_state_address:27;  
+   } bits0;
+
+   struct
+   {
+      unsigned int modify_enable:1;
+      unsigned int pad:4;
+      unsigned int surface_state_address:27;  
+   } bits1;
+
+   struct
+   {
+      unsigned int modify_enable:1;
+      unsigned int pad:4;
+      unsigned int indirect_object_state_address:27;  
+   } bits2;
+
+   struct
+   {
+      unsigned int modify_enable:1;
+      unsigned int pad:11;
+      unsigned int general_state_upper_bound:20;  
+   } bits3;
+
+   struct
+   {
+      unsigned int modify_enable:1;
+      unsigned int pad:11;
+      unsigned int indirect_object_state_upper_bound:20;  
+   } bits4;
+};
+
+struct gen4_state_prefetch
+{
+   struct header header;
+
+   struct
+   {
+      unsigned int prefetch_count:3;   
+      unsigned int pad:3;
+      unsigned int prefetch_pointer:26;  
+   } bits0;
+};
+
+struct gen4_system_instruction_pointer
+{
+   struct header header;
+
+   struct
+   {
+      unsigned int pad:4;
+      unsigned int system_instruction_pointer:28;  
+   } bits0;
+};
+
+
+
+
+/* State structs for the various fixed function units:
+ */
+
+
+struct thread0
+{
+   unsigned int pad0:1;
+   unsigned int grf_reg_count:3; 
+   unsigned int pad1:2;
+   unsigned int kernel_start_pointer:26; 
+};
+
+struct thread1
+{
+   unsigned int ext_halt_exception_enable:1; 
+   unsigned int sw_exception_enable:1; 
+   unsigned int mask_stack_exception_enable:1; 
+   unsigned int timeout_exception_enable:1; 
+   unsigned int illegal_op_exception_enable:1; 
+   unsigned int pad0:3;
+   unsigned int depth_coef_urb_read_offset:6;  /* WM only */
+   unsigned int pad1:2;
+   unsigned int floating_point_mode:1; 
+   unsigned int thread_priority:1; 
+   unsigned int binding_table_entry_count:8; 
+   unsigned int pad3:5;
+   unsigned int single_program_flow:1; 
+};
+
+struct thread2
+{
+   unsigned int per_thread_scratch_space:4; 
+   unsigned int pad0:6;
+   unsigned int scratch_space_base_pointer:22; 
+};
+
+   
+struct thread3
+{
+   unsigned int dispatch_grf_start_reg:4; 
+   unsigned int urb_entry_read_offset:6; 
+   unsigned int pad0:1;
+   unsigned int urb_entry_read_length:6; 
+   unsigned int pad1:1;
+   unsigned int const_urb_entry_read_offset:6; 
+   unsigned int pad2:1;
+   unsigned int const_urb_entry_read_length:6; 
+   unsigned int pad3:1;
+};
+
+
+
+struct gen4_clip_unit_state
+{
+   struct thread0 thread0;
+   struct thread1 thread1;
+   struct thread2 thread2;
+   struct thread3 thread3;
+
+   struct
+   {
+      unsigned int pad0:9;
+      unsigned int gs_output_stats:1; /* not always */
+      unsigned int stats_enable:1; 
+      unsigned int nr_urb_entries:7; 
+      unsigned int pad1:1;
+      unsigned int urb_entry_allocation_size:5; 
+      unsigned int pad2:1;
+      unsigned int max_threads:6;      /* may be less */
+      unsigned int pad3:1;
+   } thread4;   
+      
+   struct
+   {
+      unsigned int pad0:13;
+      unsigned int clip_mode:3; 
+      unsigned int userclip_enable_flags:8; 
+      unsigned int userclip_must_clip:1; 
+      unsigned int pad1:1;
+      unsigned int guard_band_enable:1; 
+      unsigned int viewport_z_clip_enable:1; 
+      unsigned int viewport_xy_clip_enable:1; 
+      unsigned int vertex_position_space:1; 
+      unsigned int api_mode:1; 
+      unsigned int pad2:1;
+   } clip5;
+   
+   struct
+   {
+      unsigned int pad0:5;
+      unsigned int clipper_viewport_state_ptr:27; 
+   } clip6;
+
+   
+   float viewport_xmin;  
+   float viewport_xmax;  
+   float viewport_ymin;  
+   float viewport_ymax;  
+};
+
+
+
+struct gen4_cc_unit_state
+{
+   struct
+   {
+      unsigned int pad0:3;
+      unsigned int bf_stencil_pass_depth_pass_op:3; 
+      unsigned int bf_stencil_pass_depth_fail_op:3; 
+      unsigned int bf_stencil_fail_op:3; 
+      unsigned int bf_stencil_func:3; 
+      unsigned int bf_stencil_enable:1; 
+      unsigned int pad1:2;
+      unsigned int stencil_write_enable:1; 
+      unsigned int stencil_pass_depth_pass_op:3; 
+      unsigned int stencil_pass_depth_fail_op:3; 
+      unsigned int stencil_fail_op:3; 
+      unsigned int stencil_func:3; 
+      unsigned int stencil_enable:1; 
+   } cc0;
+
+   
+   struct
+   {
+      unsigned int bf_stencil_ref:8; 
+      unsigned int stencil_write_mask:8; 
+      unsigned int stencil_test_mask:8; 
+      unsigned int stencil_ref:8; 
+   } cc1;
+
+   
+   struct
+   {
+      unsigned int logicop_enable:1; 
+      unsigned int pad0:10;
+      unsigned int depth_write_enable:1; 
+      unsigned int depth_test_function:3; 
+      unsigned int depth_test:1; 
+      unsigned int bf_stencil_write_mask:8; 
+      unsigned int bf_stencil_test_mask:8; 
+   } cc2;
+
+   
+   struct
+   {
+      unsigned int pad0:8;
+      unsigned int alpha_test_func:3; 
+      unsigned int alpha_test:1; 
+      unsigned int blend_enable:1; 
+      unsigned int ia_blend_enable:1; 
+      unsigned int pad1:1;
+      unsigned int alpha_test_format:1;
+      unsigned int pad2:16;
+   } cc3;
+   
+   struct
+   {
+      unsigned int pad0:5; 
+      unsigned int cc_viewport_state_offset:27; 
+   } cc4;
+   
+   struct
+   {
+      unsigned int pad0:2;
+      unsigned int ia_dest_blend_factor:5; 
+      unsigned int ia_src_blend_factor:5; 
+      unsigned int ia_blend_function:3; 
+      unsigned int statistics_enable:1; 
+      unsigned int logicop_func:4; 
+      unsigned int pad1:11;
+      unsigned int dither_enable:1; 
+   } cc5;
+
+   struct
+   {
+      unsigned int clamp_post_alpha_blend:1; 
+      unsigned int clamp_pre_alpha_blend:1; 
+      unsigned int clamp_range:2; 
+      unsigned int pad0:11;
+      unsigned int y_dither_offset:2; 
+      unsigned int x_dither_offset:2; 
+      unsigned int dest_blend_factor:5; 
+      unsigned int src_blend_factor:5; 
+      unsigned int blend_function:3; 
+   } cc6;
+
+   struct {
+      union {
+        float f;  
+        unsigned char ub[4];
+      } alpha_ref;
+   } cc7;
+};
+
+
+
+struct gen4_sf_unit_state
+{
+   struct thread0 thread0;
+   struct {
+      unsigned int pad0:7;
+      unsigned int sw_exception_enable:1; 
+      unsigned int pad1:3;
+      unsigned int mask_stack_exception_enable:1; 
+      unsigned int pad2:1;
+      unsigned int illegal_op_exception_enable:1; 
+      unsigned int pad3:2;
+      unsigned int floating_point_mode:1; 
+      unsigned int thread_priority:1; 
+      unsigned int binding_table_entry_count:8; 
+      unsigned int pad4:5;
+      unsigned int single_program_flow:1; 
+   } sf1;
+   
+   struct thread2 thread2;
+   struct thread3 thread3;
+
+   struct
+   {
+      unsigned int pad0:10;
+      unsigned int stats_enable:1; 
+      unsigned int nr_urb_entries:7; 
+      unsigned int pad1:1;
+      unsigned int urb_entry_allocation_size:5; 
+      unsigned int pad2:1;
+      unsigned int max_threads:6; 
+      unsigned int pad3:1;
+   } thread4;   
+
+   struct
+   {
+      unsigned int front_winding:1; 
+      unsigned int viewport_transform:1; 
+      unsigned int pad0:3;
+      unsigned int sf_viewport_state_offset:27; 
+   } sf5;
+   
+   struct
+   {
+      unsigned int pad0:9;
+      unsigned int dest_org_vbias:4; 
+      unsigned int dest_org_hbias:4; 
+      unsigned int scissor:1; 
+      unsigned int disable_2x2_trifilter:1; 
+      unsigned int disable_zero_pix_trifilter:1; 
+      unsigned int point_rast_rule:2; 
+      unsigned int line_endcap_aa_region_width:2; 
+      unsigned int line_width:4; 
+      unsigned int fast_scissor_disable:1; 
+      unsigned int cull_mode:2; 
+      unsigned int aa_enable:1; 
+   } sf6;
+
+   struct
+   {
+      unsigned int point_size:11; 
+      unsigned int use_point_size_state:1; 
+      unsigned int subpixel_precision:1; 
+      unsigned int sprite_point:1; 
+      unsigned int pad0:11;
+      unsigned int trifan_pv:2; 
+      unsigned int linestrip_pv:2; 
+      unsigned int tristrip_pv:2; 
+      unsigned int line_last_pixel_enable:1; 
+   } sf7;
+
+};
+
+
+struct gen4_gs_unit_state
+{
+   struct thread0 thread0;
+   struct thread1 thread1;
+   struct thread2 thread2;
+   struct thread3 thread3;
+
+   struct
+   {
+      unsigned int pad0:10;
+      unsigned int stats_enable:1; 
+      unsigned int nr_urb_entries:7; 
+      unsigned int pad1:1;
+      unsigned int urb_entry_allocation_size:5; 
+      unsigned int pad2:1;
+      unsigned int max_threads:1; 
+      unsigned int pad3:6;
+   } thread4;   
+      
+   struct
+   {
+      unsigned int sampler_count:3; 
+      unsigned int pad0:2;
+      unsigned int sampler_state_pointer:27; 
+   } gs5;
+
+   
+   struct
+   {
+      unsigned int max_vp_index:4; 
+      unsigned int pad0:26;
+      unsigned int reorder_enable:1; 
+      unsigned int pad1:1;
+   } gs6;
+};
+
+
+struct gen4_vs_unit_state
+{
+   struct thread0 thread0;
+   struct thread1 thread1;
+   struct thread2 thread2;
+   struct thread3 thread3;
+   
+   struct
+   {
+      unsigned int pad0:10;
+      unsigned int stats_enable:1; 
+      unsigned int nr_urb_entries:7; 
+      unsigned int pad1:1;
+      unsigned int urb_entry_allocation_size:5; 
+      unsigned int pad2:1;
+      unsigned int max_threads:4; 
+      unsigned int pad3:3;
+   } thread4;   
+
+   struct
+   {
+      unsigned int sampler_count:3; 
+      unsigned int pad0:2;
+      unsigned int sampler_state_pointer:27; 
+   } vs5;
+
+   struct
+   {
+      unsigned int vs_enable:1; 
+      unsigned int vert_cache_disable:1; 
+      unsigned int pad0:30;
+   } vs6;
+};
+
+
+struct gen4_wm_unit_state
+{
+   struct thread0 thread0;
+   struct thread1 thread1;
+   struct thread2 thread2;
+   struct thread3 thread3;
+   
+   struct {
+      unsigned int stats_enable:1; 
+      unsigned int pad0:1;
+      unsigned int sampler_count:3; 
+      unsigned int sampler_state_pointer:27; 
+   } wm4;
+   
+   struct
+   {
+      unsigned int enable_8_pix:1; 
+      unsigned int enable_16_pix:1; 
+      unsigned int enable_32_pix:1; 
+      unsigned int pad0:7;
+      unsigned int legacy_global_depth_bias:1; 
+      unsigned int line_stipple:1; 
+      unsigned int depth_offset:1; 
+      unsigned int polygon_stipple:1; 
+      unsigned int line_aa_region_width:2; 
+      unsigned int line_endcap_aa_region_width:2; 
+      unsigned int early_depth_test:1; 
+      unsigned int thread_dispatch_enable:1; 
+      unsigned int program_uses_depth:1; 
+      unsigned int program_computes_depth:1; 
+      unsigned int program_uses_killpixel:1; 
+      unsigned int legacy_line_rast: 1; 
+      unsigned int transposed_urb_read:1; 
+      unsigned int max_threads:7; 
+   } wm5;
+   
+   float global_depth_offset_constant;  
+   float global_depth_offset_scale;   
+
+   struct {
+      unsigned int pad0:1;
+      unsigned int grf_reg_count_1:3; 
+      unsigned int pad1:2;
+      unsigned int kernel_start_pointer_1:26;
+   } wm8;       
+
+   struct {
+      unsigned int pad0:1;
+      unsigned int grf_reg_count_2:3; 
+      unsigned int pad1:2;
+      unsigned int kernel_start_pointer_2:26;
+   } wm9;       
+
+   struct {
+      unsigned int pad0:1;
+      unsigned int grf_reg_count_3:3; 
+      unsigned int pad1:2;
+      unsigned int kernel_start_pointer_3:26;
+   } wm10;       
+};
+
+struct gen4_wm_unit_state_padded {
+       struct gen4_wm_unit_state state;
+       char pad[64 - sizeof(struct gen4_wm_unit_state)];
+};
+
+/* The hardware supports two different modes for border color. The
+ * default (OpenGL) mode uses floating-point color channels, while the
+ * legacy mode uses 4 bytes.
+ *
+ * More significantly, the legacy mode respects the components of the
+ * border color for channels not present in the source, (whereas the
+ * default mode will ignore the border color's alpha channel and use
+ * alpha==1 for an RGB source, for example).
+ *
+ * The legacy mode matches the semantics specified by the Render
+ * extension.
+ */
+struct gen4_sampler_default_border_color {
+   float color[4];
+};
+
+struct gen4_sampler_legacy_border_color {
+   uint8_t color[4];
+};
+
+struct gen4_sampler_state
+{
+   
+   struct
+   {
+      unsigned int shadow_function:3; 
+      unsigned int lod_bias:11; 
+      unsigned int min_filter:3; 
+      unsigned int mag_filter:3; 
+      unsigned int mip_filter:2; 
+      unsigned int base_level:5; 
+      unsigned int pad:1;
+      unsigned int lod_preclamp:1; 
+      unsigned int border_color_mode:1; 
+      unsigned int pad0:1;
+      unsigned int disable:1; 
+   } ss0;
+
+   struct
+   {
+      unsigned int r_wrap_mode:3; 
+      unsigned int t_wrap_mode:3; 
+      unsigned int s_wrap_mode:3; 
+      unsigned int pad:3;
+      unsigned int max_lod:10; 
+      unsigned int min_lod:10; 
+   } ss1;
+
+   
+   struct
+   {
+      unsigned int pad:5;
+      unsigned int border_color_pointer:27; 
+   } ss2;
+   
+   struct
+   {
+      unsigned int pad:19;
+      unsigned int max_aniso:3; 
+      unsigned int chroma_key_mode:1; 
+      unsigned int chroma_key_index:2; 
+      unsigned int chroma_key_enable:1; 
+      unsigned int monochrome_filter_width:3; 
+      unsigned int monochrome_filter_height:3; 
+   } ss3;
+};
+
+
+struct gen4_clipper_viewport
+{
+   float xmin;  
+   float xmax;  
+   float ymin;  
+   float ymax;  
+};
+
+struct gen4_cc_viewport
+{
+   float min_depth;  
+   float max_depth;  
+};
+
+struct gen4_sf_viewport
+{
+   struct {
+      float m00;  
+      float m11;  
+      float m22;  
+      float m30;  
+      float m31;  
+      float m32;  
+   } viewport;
+
+   struct {
+      short xmin;
+      short ymin;
+      short xmax;
+      short ymax;
+   } scissor;
+};
+
+/* Documented in the subsystem/shared-functions/sampler chapter...
+ */
+struct gen4_surface_state
+{
+   struct {
+      unsigned int cube_pos_z:1; 
+      unsigned int cube_neg_z:1; 
+      unsigned int cube_pos_y:1; 
+      unsigned int cube_neg_y:1; 
+      unsigned int cube_pos_x:1; 
+      unsigned int cube_neg_x:1; 
+      unsigned int pad:3;
+      unsigned int render_cache_read_mode:1;
+      unsigned int mipmap_layout_mode:1; 
+      unsigned int vert_line_stride_ofs:1; 
+      unsigned int vert_line_stride:1; 
+      unsigned int color_blend:1; 
+      unsigned int writedisable_blue:1; 
+      unsigned int writedisable_green:1; 
+      unsigned int writedisable_red:1; 
+      unsigned int writedisable_alpha:1; 
+      unsigned int surface_format:9; 
+      unsigned int data_return_format:1; 
+      unsigned int pad0:1;
+      unsigned int surface_type:3; 
+   } ss0;
+   
+   struct {
+      unsigned int base_addr;  
+   } ss1;
+   
+   struct {
+      unsigned int render_target_rotation:2;
+      unsigned int mip_count:4; 
+      unsigned int width:13; 
+      unsigned int height:13; 
+   } ss2;
+
+   struct {
+      unsigned int tile_walk:1; 
+      unsigned int tiled_surface:1; 
+      unsigned int pad:1; 
+      unsigned int pitch:18; 
+      unsigned int depth:11; 
+   } ss3;
+   
+   struct {
+      unsigned int pad:19;
+      unsigned int min_array_elt:9; 
+      unsigned int min_lod:4; 
+   } ss4;
+
+   struct {
+       unsigned int pad:20;
+       unsigned int y_offset:4;
+       unsigned int pad2:1;
+       unsigned int x_offset:7;
+   } ss5;
+};
+
+
+
+struct gen4_vertex_buffer_state
+{
+   struct {
+      unsigned int pitch:11; 
+      unsigned int pad:15;
+      unsigned int access_type:1; 
+      unsigned int vb_index:5; 
+   } vb0;
+   
+   unsigned int start_addr; 
+   unsigned int max_index;   
+#if 1
+   unsigned int instance_data_step_rate; /* not included for sequential/random vertices? */
+#endif
+};
+
+#define GEN4_VBP_MAX 17
+
+struct gen4_vb_array_state {
+   struct header header;
+   struct gen4_vertex_buffer_state vb[GEN4_VBP_MAX];
+};
+
+
+struct gen4_vertex_element_state
+{
+   struct
+   {
+      unsigned int src_offset:11; 
+      unsigned int pad:5;
+      unsigned int src_format:9; 
+      unsigned int pad0:1;
+      unsigned int valid:1; 
+      unsigned int vertex_buffer_index:5; 
+   } ve0;
+   
+   struct
+   {
+      unsigned int dst_offset:8; 
+      unsigned int pad:8;
+      unsigned int vfcomponent3:4; 
+      unsigned int vfcomponent2:4; 
+      unsigned int vfcomponent1:4; 
+      unsigned int vfcomponent0:4; 
+   } ve1;
+};
+
+#define GEN4_VEP_MAX 18
+
+struct gen4_vertex_element_packet {
+   struct header header;
+   struct gen4_vertex_element_state ve[GEN4_VEP_MAX]; /* note: less than _TNL_ATTRIB_MAX */
+};
+
+
+struct gen4_urb_immediate {
+   unsigned int opcode:4;
+   unsigned int offset:6;
+   unsigned int swizzle_control:2; 
+   unsigned int pad:1;
+   unsigned int allocate:1;
+   unsigned int used:1;
+   unsigned int complete:1;
+   unsigned int response_length:4;
+   unsigned int msg_length:4;
+   unsigned int msg_target:4;
+   unsigned int pad1:3;
+   unsigned int end_of_thread:1;
+};
+
+/* Instruction format for the execution units:
+ */
+struct gen4_instruction
+{
+   struct 
+   {
+      unsigned int opcode:7;
+      unsigned int pad:1;
+      unsigned int access_mode:1;
+      unsigned int mask_control:1;
+      unsigned int dependency_control:2;
+      unsigned int compression_control:2;
+      unsigned int thread_control:2;
+      unsigned int predicate_control:4;
+      unsigned int predicate_inverse:1;
+      unsigned int execution_size:3;
+      unsigned int destreg__conditonalmod:4; /* destreg - send, conditionalmod - others */
+      unsigned int pad0:2;
+      unsigned int debug_control:1;
+      unsigned int saturate:1;
+   } header;
+
+   union {
+      struct
+      {
+        unsigned int dest_reg_file:2;
+        unsigned int dest_reg_type:3;
+        unsigned int src0_reg_file:2;
+        unsigned int src0_reg_type:3;
+        unsigned int src1_reg_file:2;
+        unsigned int src1_reg_type:3;
+        unsigned int pad:1;
+        unsigned int dest_subreg_nr:5;
+        unsigned int dest_reg_nr:8;
+        unsigned int dest_horiz_stride:2;
+        unsigned int dest_address_mode:1;
+      } da1;
+
+      struct
+      {
+        unsigned int dest_reg_file:2;
+        unsigned int dest_reg_type:3;
+        unsigned int src0_reg_file:2;
+        unsigned int src0_reg_type:3;
+        unsigned int pad:6;
+        int dest_indirect_offset:10;   /* offset against the deref'd address reg */
+        unsigned int dest_subreg_nr:3; /* subnr for the address reg a0.x */
+        unsigned int dest_horiz_stride:2;
+        unsigned int dest_address_mode:1;
+      } ia1;
+
+      struct
+      {
+        unsigned int dest_reg_file:2;
+        unsigned int dest_reg_type:3;
+        unsigned int src0_reg_file:2;
+        unsigned int src0_reg_type:3;
+        unsigned int src1_reg_file:2;
+        unsigned int src1_reg_type:3;
+        unsigned int pad0:1;
+        unsigned int dest_writemask:4;
+        unsigned int dest_subreg_nr:1;
+        unsigned int dest_reg_nr:8;
+        unsigned int pad1:2;
+        unsigned int dest_address_mode:1;
+      } da16;
+
+      struct
+      {
+        unsigned int dest_reg_file:2;
+        unsigned int dest_reg_type:3;
+        unsigned int src0_reg_file:2;
+        unsigned int src0_reg_type:3;
+        unsigned int pad0:6;
+        unsigned int dest_writemask:4;
+        int dest_indirect_offset:6;
+        unsigned int dest_subreg_nr:3;
+        unsigned int pad1:2;
+        unsigned int dest_address_mode:1;
+      } ia16;
+   } bits1;
+
+
+   union {
+      struct
+      {
+        unsigned int src0_subreg_nr:5;
+        unsigned int src0_reg_nr:8;
+        unsigned int src0_abs:1;
+        unsigned int src0_negate:1;
+        unsigned int src0_address_mode:1;
+        unsigned int src0_horiz_stride:2;
+        unsigned int src0_width:3;
+        unsigned int src0_vert_stride:4;
+        unsigned int flag_reg_nr:1;
+        unsigned int pad:6;
+      } da1;
+
+      struct
+      {
+        int src0_indirect_offset:10;
+        unsigned int src0_subreg_nr:3;
+        unsigned int src0_abs:1;
+        unsigned int src0_negate:1;
+        unsigned int src0_address_mode:1;
+        unsigned int src0_horiz_stride:2;
+        unsigned int src0_width:3;
+        unsigned int src0_vert_stride:4;
+        unsigned int flag_reg_nr:1;
+        unsigned int pad:6;    
+      } ia1;
+
+      struct
+      {
+        unsigned int src0_swz_x:2;
+        unsigned int src0_swz_y:2;
+        unsigned int src0_subreg_nr:1;
+        unsigned int src0_reg_nr:8;
+        unsigned int src0_abs:1;
+        unsigned int src0_negate:1;
+        unsigned int src0_address_mode:1;
+        unsigned int src0_swz_z:2;
+        unsigned int src0_swz_w:2;
+        unsigned int pad0:1;
+        unsigned int src0_vert_stride:4;
+        unsigned int flag_reg_nr:1;
+        unsigned int pad1:6;
+      } da16;
+
+      struct
+      {
+        unsigned int src0_swz_x:2;
+        unsigned int src0_swz_y:2;
+        int src0_indirect_offset:6;
+        unsigned int src0_subreg_nr:3;
+        unsigned int src0_abs:1;
+        unsigned int src0_negate:1;
+        unsigned int src0_address_mode:1;
+        unsigned int src0_swz_z:2;
+        unsigned int src0_swz_w:2;
+        unsigned int pad0:1;
+        unsigned int src0_vert_stride:4;
+        unsigned int flag_reg_nr:1;
+        unsigned int pad1:6;
+      } ia16;
+
+   } bits2;
+
+   union
+   {
+      struct
+      {
+        unsigned int src1_subreg_nr:5;
+        unsigned int src1_reg_nr:8;
+        unsigned int src1_abs:1;
+        unsigned int src1_negate:1;
+        unsigned int pad:1;
+        unsigned int src1_horiz_stride:2;
+        unsigned int src1_width:3;
+        unsigned int src1_vert_stride:4;
+        unsigned int pad0:7;
+      } da1;
+
+      struct
+      {
+        unsigned int src1_swz_x:2;
+        unsigned int src1_swz_y:2;
+        unsigned int src1_subreg_nr:1;
+        unsigned int src1_reg_nr:8;
+        unsigned int src1_abs:1;
+        unsigned int src1_negate:1;
+        unsigned int pad0:1;
+        unsigned int src1_swz_z:2;
+        unsigned int src1_swz_w:2;
+        unsigned int pad1:1;
+        unsigned int src1_vert_stride:4;
+        unsigned int pad2:7;
+      } da16;
+
+      struct
+      {
+        int  src1_indirect_offset:10;
+        unsigned int src1_subreg_nr:3;
+        unsigned int src1_abs:1;
+        unsigned int src1_negate:1;
+        unsigned int pad0:1;
+        unsigned int src1_horiz_stride:2;
+        unsigned int src1_width:3;
+        unsigned int src1_vert_stride:4;
+        unsigned int flag_reg_nr:1;
+        unsigned int pad1:6;   
+      } ia1;
+
+      struct
+      {
+        unsigned int src1_swz_x:2;
+        unsigned int src1_swz_y:2;
+        int  src1_indirect_offset:6;
+        unsigned int src1_subreg_nr:3;
+        unsigned int src1_abs:1;
+        unsigned int src1_negate:1;
+        unsigned int pad0:1;
+        unsigned int src1_swz_z:2;
+        unsigned int src1_swz_w:2;
+        unsigned int pad1:1;
+        unsigned int src1_vert_stride:4;
+        unsigned int flag_reg_nr:1;
+        unsigned int pad2:6;
+      } ia16;
+
+
+      struct
+      {
+        int  jump_count:16;    /* note: signed */
+        unsigned int  pop_count:4;
+        unsigned int  pad0:12;
+      } if_else;
+
+      struct {
+        unsigned int function:4;
+        unsigned int int_type:1;
+        unsigned int precision:1;
+        unsigned int saturate:1;
+        unsigned int data_type:1;
+        unsigned int pad0:8;
+        unsigned int response_length:4;
+        unsigned int msg_length:4;
+        unsigned int msg_target:4;
+        unsigned int pad1:3;
+        unsigned int end_of_thread:1;
+      } math;
+
+      struct {
+        unsigned int binding_table_index:8;
+        unsigned int sampler:4;
+        unsigned int return_format:2; 
+        unsigned int msg_type:2;   
+        unsigned int response_length:4;
+        unsigned int msg_length:4;
+        unsigned int msg_target:4;
+        unsigned int pad1:3;
+        unsigned int end_of_thread:1;
+      } sampler;
+
+      struct gen4_urb_immediate urb;
+
+      struct {
+        unsigned int binding_table_index:8;
+        unsigned int msg_control:4;  
+        unsigned int msg_type:2;  
+        unsigned int target_cache:2;    
+        unsigned int response_length:4;
+        unsigned int msg_length:4;
+        unsigned int msg_target:4;
+        unsigned int pad1:3;
+        unsigned int end_of_thread:1;
+      } dp_read;
+
+      struct {
+        unsigned int binding_table_index:8;
+        unsigned int msg_control:3;
+        unsigned int pixel_scoreboard_clear:1;
+        unsigned int msg_type:3;    
+        unsigned int send_commit_msg:1;
+        unsigned int response_length:4;
+        unsigned int msg_length:4;
+        unsigned int msg_target:4;
+        unsigned int pad1:3;
+        unsigned int end_of_thread:1;
+      } dp_write;
+
+      struct {
+        unsigned int pad:16;
+        unsigned int response_length:4;
+        unsigned int msg_length:4;
+        unsigned int msg_target:4;
+        unsigned int pad1:3;
+        unsigned int end_of_thread:1;
+      } generic;
+
+      unsigned int ud;
+   } bits3;
+};
+
+/* media pipeline */
+
+struct gen4_vfe_state {
+    struct {
+       unsigned int per_thread_scratch_space:4;
+       unsigned int pad3:3;
+       unsigned int extend_vfe_state_present:1;
+       unsigned int pad2:2;
+       unsigned int scratch_base:22;
+    } vfe0;
+
+    struct {
+       unsigned int debug_counter_control:2;
+       unsigned int children_present:1;
+       unsigned int vfe_mode:4;
+       unsigned int pad2:2;
+       unsigned int num_urb_entries:7;
+       unsigned int urb_entry_alloc_size:9;
+       unsigned int max_threads:7;
+    } vfe1;
+
+    struct {
+       unsigned int pad4:4;
+       unsigned int interface_descriptor_base:28;
+    } vfe2;
+};
+
+struct gen4_vld_state {
+    struct {
+       unsigned int pad6:6;
+       unsigned int scan_order:1;
+       unsigned int intra_vlc_format:1;
+       unsigned int quantizer_scale_type:1;
+       unsigned int concealment_motion_vector:1;
+       unsigned int frame_predict_frame_dct:1;
+       unsigned int top_field_first:1;
+       unsigned int picture_structure:2;
+       unsigned int intra_dc_precision:2;
+       unsigned int f_code_0_0:4;
+       unsigned int f_code_0_1:4;
+       unsigned int f_code_1_0:4;
+       unsigned int f_code_1_1:4;
+    } vld0;
+
+    struct {
+       unsigned int pad2:9;
+       unsigned int picture_coding_type:2;
+       unsigned int pad:21;
+    } vld1;
+
+    struct {
+       unsigned int index_0:4;
+       unsigned int index_1:4;
+       unsigned int index_2:4;
+       unsigned int index_3:4;
+       unsigned int index_4:4;
+       unsigned int index_5:4;
+       unsigned int index_6:4;
+       unsigned int index_7:4;
+    } desc_remap_table0;
+
+    struct {
+       unsigned int index_8:4;
+       unsigned int index_9:4;
+       unsigned int index_10:4;
+       unsigned int index_11:4;
+       unsigned int index_12:4;
+       unsigned int index_13:4;
+       unsigned int index_14:4;
+       unsigned int index_15:4;
+    } desc_remap_table1;
+};
+
+struct gen4_interface_descriptor {
+    struct {
+       unsigned int grf_reg_blocks:4;
+       unsigned int pad:2;
+       unsigned int kernel_start_pointer:26;
+    } desc0;
+
+    struct {
+       unsigned int pad:7;
+       unsigned int software_exception:1;
+       unsigned int pad2:3;
+       unsigned int maskstack_exception:1;
+       unsigned int pad3:1;
+       unsigned int illegal_opcode_exception:1;
+       unsigned int pad4:2;
+       unsigned int floating_point_mode:1;
+       unsigned int thread_priority:1;
+       unsigned int single_program_flow:1;
+       unsigned int pad5:1;
+       unsigned int const_urb_entry_read_offset:6;
+       unsigned int const_urb_entry_read_len:6;
+    } desc1;
+
+    struct {
+       unsigned int pad:2;
+       unsigned int sampler_count:3;
+       unsigned int sampler_state_pointer:27;
+    } desc2;
+
+    struct {
+       unsigned int binding_table_entry_count:5;
+       unsigned int binding_table_pointer:27;
+    } desc3;
+};
+
+struct gen6_blend_state
+{
+       struct {
+               unsigned int dest_blend_factor:5;
+               unsigned int source_blend_factor:5;
+               unsigned int pad3:1;
+               unsigned int blend_func:3;
+               unsigned int pad2:1;
+               unsigned int ia_dest_blend_factor:5;
+               unsigned int ia_source_blend_factor:5;
+               unsigned int pad1:1;
+               unsigned int ia_blend_func:3;
+               unsigned int pad0:1;
+               unsigned int ia_blend_enable:1;
+               unsigned int blend_enable:1;
+       } blend0;
+
+       struct {
+               unsigned int post_blend_clamp_enable:1;
+               unsigned int pre_blend_clamp_enable:1;
+               unsigned int clamp_range:2;
+               unsigned int pad0:4;
+               unsigned int x_dither_offset:2;
+               unsigned int y_dither_offset:2;
+               unsigned int dither_enable:1;
+               unsigned int alpha_test_func:3;
+               unsigned int alpha_test_enable:1;
+               unsigned int pad1:1;
+               unsigned int logic_op_func:4;
+               unsigned int logic_op_enable:1;
+               unsigned int pad2:1;
+               unsigned int write_disable_b:1;
+               unsigned int write_disable_g:1;
+               unsigned int write_disable_r:1;
+               unsigned int write_disable_a:1;
+               unsigned int pad3:1;
+               unsigned int alpha_to_coverage_dither:1;
+               unsigned int alpha_to_one:1;
+               unsigned int alpha_to_coverage:1;
+       } blend1;
+};
+
+struct gen6_color_calc_state
+{
+       struct {
+               unsigned int alpha_test_format:1;
+               unsigned int pad0:14;
+               unsigned int round_disable:1;
+               unsigned int bf_stencil_ref:8;
+               unsigned int stencil_ref:8;
+       } cc0;
+
+       union {
+               float alpha_ref_f;
+               struct {
+                       unsigned int ui:8;
+                       unsigned int pad0:24;
+               } alpha_ref_fi;
+       } cc1;
+
+       float constant_r;
+       float constant_g;
+       float constant_b;
+       float constant_a;
+};
+
+struct gen6_depth_stencil_state
+{
+       struct {
+               unsigned int pad0:3;
+               unsigned int bf_stencil_pass_depth_pass_op:3;
+               unsigned int bf_stencil_pass_depth_fail_op:3;
+               unsigned int bf_stencil_fail_op:3;
+               unsigned int bf_stencil_func:3;
+               unsigned int bf_stencil_enable:1;
+               unsigned int pad1:2;
+               unsigned int stencil_write_enable:1;
+               unsigned int stencil_pass_depth_pass_op:3;
+               unsigned int stencil_pass_depth_fail_op:3;
+               unsigned int stencil_fail_op:3;
+               unsigned int stencil_func:3;
+               unsigned int stencil_enable:1;
+       } ds0;
+
+       struct {
+               unsigned int bf_stencil_write_mask:8;
+               unsigned int bf_stencil_test_mask:8;
+               unsigned int stencil_write_mask:8;
+               unsigned int stencil_test_mask:8;
+       } ds1;
+
+       struct {
+               unsigned int pad0:26;
+               unsigned int depth_write_enable:1;
+               unsigned int depth_test_func:3;
+               unsigned int pad1:1;
+               unsigned int depth_test_enable:1;
+       } ds2;
+};
+
+typedef enum {
+       SAMPLER_FILTER_NEAREST = 0,
+       SAMPLER_FILTER_BILINEAR,
+       FILTER_COUNT
+} sampler_filter_t;
+
+typedef enum {
+       SAMPLER_EXTEND_NONE = 0,
+       SAMPLER_EXTEND_REPEAT,
+       SAMPLER_EXTEND_PAD,
+       SAMPLER_EXTEND_REFLECT,
+       EXTEND_COUNT
+} sampler_extend_t;
+
+typedef enum {
+       WM_KERNEL = 0,
+       WM_KERNEL_P,
+
+       WM_KERNEL_MASK,
+       WM_KERNEL_MASK_P,
+
+       WM_KERNEL_MASKCA,
+       WM_KERNEL_MASKCA_P,
+
+       WM_KERNEL_MASKSA,
+       WM_KERNEL_MASKSA_P,
+
+       WM_KERNEL_OPACITY,
+       WM_KERNEL_OPACITY_P,
+
+       WM_KERNEL_VIDEO_PLANAR,
+       WM_KERNEL_VIDEO_PACKED,
+       KERNEL_COUNT
+} wm_kernel_t;
+
+#endif
diff --git a/src/sna/gen5_render.c b/src/sna/gen5_render.c
new file mode 100644 (file)
index 0000000..afd729e
--- /dev/null
@@ -0,0 +1,3857 @@
+/*
+ * Copyright © 2006,2008,2011 Intel Corporation
+ * Copyright © 2007 Red Hat, Inc.
+ *
+ * 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.
+ *
+ * Authors:
+ *    Wang Zhenyu <zhenyu.z.wang@sna.com>
+ *    Eric Anholt <eric@anholt.net>
+ *    Carl Worth <cworth@redhat.com>
+ *    Keith Packard <keithp@keithp.com>
+ *    Chris Wilson <chris@chris-wilson.co.uk>
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "sna.h"
+#include "sna_reg.h"
+#include "sna_render.h"
+#include "sna_render_inline.h"
+#include "sna_video.h"
+
+#include "brw/brw.h"
+#include "gen5_render.h"
+
+#define NO_COMPOSITE_SPANS 0
+
+#define PREFER_BLT_FILL 1
+
+#define DBG_NO_STATE_CACHE 0
+#define DBG_NO_SURFACE_CACHE 0
+
+#define MAX_3D_SIZE 8192
+
+#define GEN5_GRF_BLOCKS(nreg)    ((nreg + 15) / 16 - 1)
+
+/* Set up a default static partitioning of the URB, which is supposed to
+ * allow anything we would want to do, at potentially lower performance.
+ */
+#define URB_CS_ENTRY_SIZE     1
+#define URB_CS_ENTRIES       0
+
+#define URB_VS_ENTRY_SIZE     1
+#define URB_VS_ENTRIES       256 /* minimum of 8 */
+
+#define URB_GS_ENTRY_SIZE     0
+#define URB_GS_ENTRIES       0
+
+#define URB_CLIP_ENTRY_SIZE   0
+#define URB_CLIP_ENTRIES      0
+
+#define URB_SF_ENTRY_SIZE     2
+#define URB_SF_ENTRIES       64
+
+/*
+ * this program computes dA/dx and dA/dy for the texture coordinates along
+ * with the base texture coordinate. It was extracted from the Mesa driver
+ */
+
+#define SF_KERNEL_NUM_GRF  16
+#define SF_MAX_THREADS    48
+
+#define PS_KERNEL_NUM_GRF   32
+#define PS_MAX_THREADS     72
+
+static const uint32_t ps_kernel_packed_static[][4] = {
+#include "exa_wm_xy.g5b"
+#include "exa_wm_src_affine.g5b"
+#include "exa_wm_src_sample_argb.g5b"
+#include "exa_wm_yuv_rgb.g5b"
+#include "exa_wm_write.g5b"
+};
+
+static const uint32_t ps_kernel_planar_static[][4] = {
+#include "exa_wm_xy.g5b"
+#include "exa_wm_src_affine.g5b"
+#include "exa_wm_src_sample_planar.g5b"
+#include "exa_wm_yuv_rgb.g5b"
+#include "exa_wm_write.g5b"
+};
+
+#define NOKERNEL(kernel_enum, func, masked) \
+    [kernel_enum] = {func, 0, masked}
+#define KERNEL(kernel_enum, kernel, masked) \
+    [kernel_enum] = {&kernel, sizeof(kernel), masked}
+static const struct wm_kernel_info {
+       const void *data;
+       unsigned int size;
+       bool has_mask;
+} wm_kernels[] = {
+       NOKERNEL(WM_KERNEL, brw_wm_kernel__affine, false),
+       NOKERNEL(WM_KERNEL_P, brw_wm_kernel__projective, false),
+
+       NOKERNEL(WM_KERNEL_MASK, brw_wm_kernel__affine_mask, true),
+       NOKERNEL(WM_KERNEL_MASK_P, brw_wm_kernel__projective_mask, true),
+
+       NOKERNEL(WM_KERNEL_MASKCA, brw_wm_kernel__affine_mask_ca, true),
+       NOKERNEL(WM_KERNEL_MASKCA_P, brw_wm_kernel__projective_mask_ca, true),
+
+       NOKERNEL(WM_KERNEL_MASKSA, brw_wm_kernel__affine_mask_sa, true),
+       NOKERNEL(WM_KERNEL_MASKSA_P, brw_wm_kernel__projective_mask_sa, true),
+
+       NOKERNEL(WM_KERNEL_OPACITY, brw_wm_kernel__affine_opacity, true),
+       NOKERNEL(WM_KERNEL_OPACITY_P, brw_wm_kernel__projective_opacity, true),
+
+       KERNEL(WM_KERNEL_VIDEO_PLANAR, ps_kernel_planar_static, false),
+       KERNEL(WM_KERNEL_VIDEO_PACKED, ps_kernel_packed_static, false),
+};
+#undef KERNEL
+
+static const struct blendinfo {
+       bool src_alpha;
+       uint32_t src_blend;
+       uint32_t dst_blend;
+} gen5_blend_op[] = {
+       /* Clear */     {0, GEN5_BLENDFACTOR_ZERO, GEN5_BLENDFACTOR_ZERO},
+       /* Src */       {0, GEN5_BLENDFACTOR_ONE, GEN5_BLENDFACTOR_ZERO},
+       /* Dst */       {0, GEN5_BLENDFACTOR_ZERO, GEN5_BLENDFACTOR_ONE},
+       /* Over */      {1, GEN5_BLENDFACTOR_ONE, GEN5_BLENDFACTOR_INV_SRC_ALPHA},
+       /* OverReverse */ {0, GEN5_BLENDFACTOR_INV_DST_ALPHA, GEN5_BLENDFACTOR_ONE},
+       /* In */        {0, GEN5_BLENDFACTOR_DST_ALPHA, GEN5_BLENDFACTOR_ZERO},
+       /* InReverse */ {1, GEN5_BLENDFACTOR_ZERO, GEN5_BLENDFACTOR_SRC_ALPHA},
+       /* Out */       {0, GEN5_BLENDFACTOR_INV_DST_ALPHA, GEN5_BLENDFACTOR_ZERO},
+       /* OutReverse */ {1, GEN5_BLENDFACTOR_ZERO, GEN5_BLENDFACTOR_INV_SRC_ALPHA},
+       /* Atop */      {1, GEN5_BLENDFACTOR_DST_ALPHA, GEN5_BLENDFACTOR_INV_SRC_ALPHA},
+       /* AtopReverse */ {1, GEN5_BLENDFACTOR_INV_DST_ALPHA, GEN5_BLENDFACTOR_SRC_ALPHA},
+       /* Xor */       {1, GEN5_BLENDFACTOR_INV_DST_ALPHA, GEN5_BLENDFACTOR_INV_SRC_ALPHA},
+       /* Add */       {0, GEN5_BLENDFACTOR_ONE, GEN5_BLENDFACTOR_ONE},
+};
+
+/**
+ * Highest-valued BLENDFACTOR used in gen5_blend_op.
+ *
+ * This leaves out GEN5_BLENDFACTOR_INV_DST_COLOR,
+ * GEN5_BLENDFACTOR_INV_CONST_{COLOR,ALPHA},
+ * GEN5_BLENDFACTOR_INV_SRC1_{COLOR,ALPHA}
+ */
+#define GEN5_BLENDFACTOR_COUNT (GEN5_BLENDFACTOR_INV_DST_ALPHA + 1)
+
+#define BLEND_OFFSET(s, d) \
+       (((s) * GEN5_BLENDFACTOR_COUNT + (d)) * 64)
+
+#define SAMPLER_OFFSET(sf, se, mf, me, k) \
+       ((((((sf) * EXTEND_COUNT + (se)) * FILTER_COUNT + (mf)) * EXTEND_COUNT + (me)) * KERNEL_COUNT + (k)) * 64)
+
+static bool
+gen5_emit_pipelined_pointers(struct sna *sna,
+                            const struct sna_composite_op *op,
+                            int blend, int kernel);
+
+#define OUT_BATCH(v) batch_emit(sna, v)
+#define OUT_VERTEX(x,y) vertex_emit_2s(sna, x,y)
+#define OUT_VERTEX_F(v) vertex_emit(sna, v)
+
+static inline bool too_large(int width, int height)
+{
+       return width > MAX_3D_SIZE || height > MAX_3D_SIZE;
+}
+
+static int
+gen5_choose_composite_kernel(int op, bool has_mask, bool is_ca, bool is_affine)
+{
+       int base;
+
+       if (has_mask) {
+               if (is_ca) {
+                       if (gen5_blend_op[op].src_alpha)
+                               base = WM_KERNEL_MASKSA;
+                       else
+                               base = WM_KERNEL_MASKCA;
+               } else
+                       base = WM_KERNEL_MASK;
+       } else
+               base = WM_KERNEL;
+
+       return base + !is_affine;
+}
+
+static void gen5_magic_ca_pass(struct sna *sna,
+                              const struct sna_composite_op *op)
+{
+       struct gen5_render_state *state = &sna->render_state.gen5;
+
+       if (!op->need_magic_ca_pass)
+               return;
+
+       assert(sna->render.vertex_index > sna->render.vertex_start);
+
+       DBG(("%s: CA fixup\n", __FUNCTION__));
+
+       gen5_emit_pipelined_pointers
+               (sna, op, PictOpAdd,
+                gen5_choose_composite_kernel(PictOpAdd,
+                                             true, true, op->is_affine));
+
+       OUT_BATCH(GEN5_3DPRIMITIVE |
+                 GEN5_3DPRIMITIVE_VERTEX_SEQUENTIAL |
+                 (_3DPRIM_RECTLIST << GEN5_3DPRIMITIVE_TOPOLOGY_SHIFT) |
+                 (0 << 9) |
+                 4);
+       OUT_BATCH(sna->render.vertex_index - sna->render.vertex_start);
+       OUT_BATCH(sna->render.vertex_start);
+       OUT_BATCH(1);   /* single instance */
+       OUT_BATCH(0);   /* start instance location */
+       OUT_BATCH(0);   /* index buffer offset, ignored */
+
+       state->last_primitive = sna->kgem.nbatch;
+}
+
+static void gen5_vertex_flush(struct sna *sna)
+{
+       assert(sna->render_state.gen5.vertex_offset);
+       assert(sna->render.vertex_index > sna->render.vertex_start);
+
+       DBG(("%s[%x] = %d\n", __FUNCTION__,
+            4*sna->render_state.gen5.vertex_offset,
+            sna->render.vertex_index - sna->render.vertex_start));
+       sna->kgem.batch[sna->render_state.gen5.vertex_offset] =
+               sna->render.vertex_index - sna->render.vertex_start;
+       sna->render_state.gen5.vertex_offset = 0;
+}
+
+static int gen5_vertex_finish(struct sna *sna)
+{
+       struct kgem_bo *bo;
+       unsigned int i;
+
+       assert(sna->render.vertex_used);
+       assert(sna->render.nvertex_reloc);
+
+       /* Note: we only need dword alignment (currently) */
+
+       bo = sna->render.vbo;
+       if (bo) {
+               if (sna->render_state.gen5.vertex_offset)
+                       gen5_vertex_flush(sna);
+
+               for (i = 0; i < sna->render.nvertex_reloc; i++) {
+                       DBG(("%s: reloc[%d] = %d\n", __FUNCTION__,
+                            i, sna->render.vertex_reloc[i]));
+
+                       sna->kgem.batch[sna->render.vertex_reloc[i]] =
+                               kgem_add_reloc(&sna->kgem,
+                                              sna->render.vertex_reloc[i], bo,
+                                              I915_GEM_DOMAIN_VERTEX << 16,
+                                              0);
+                       sna->kgem.batch[sna->render.vertex_reloc[i]+1] =
+                               kgem_add_reloc(&sna->kgem,
+                                              sna->render.vertex_reloc[i]+1, bo,
+                                              I915_GEM_DOMAIN_VERTEX << 16,
+                                              sna->render.vertex_used * 4 - 1);
+               }
+
+               sna->render.nvertex_reloc = 0;
+               sna->render.vertex_used = 0;
+               sna->render.vertex_index = 0;
+               sna->render_state.gen5.vb_id = 0;
+
+               kgem_bo_destroy(&sna->kgem, bo);
+       }
+
+       sna->render.vertices = NULL;
+       sna->render.vbo = kgem_create_linear(&sna->kgem,
+                                            256*1024, CREATE_GTT_MAP);
+       if (sna->render.vbo)
+               sna->render.vertices = kgem_bo_map(&sna->kgem, sna->render.vbo);
+       if (sna->render.vertices == NULL) {
+               if (sna->render.vbo)
+                       kgem_bo_destroy(&sna->kgem, sna->render.vbo);
+               sna->render.vbo = NULL;
+               return 0;
+       }
+
+       if (sna->render.vertex_used) {
+               memcpy(sna->render.vertices,
+                      sna->render.vertex_data,
+                      sizeof(float)*sna->render.vertex_used);
+       }
+       sna->render.vertex_size = 64 * 1024 - 1;
+       return sna->render.vertex_size - sna->render.vertex_used;
+}
+
+static void gen5_vertex_close(struct sna *sna)
+{
+       struct kgem_bo *bo, *free_bo = NULL;
+       unsigned int i, delta = 0;
+
+       assert(sna->render_state.gen5.vertex_offset == 0);
+       if (!sna->render_state.gen5.vb_id)
+               return;
+
+       DBG(("%s: used=%d, vbo active? %d\n",
+            __FUNCTION__, sna->render.vertex_used, sna->render.vbo != NULL));
+
+       bo = sna->render.vbo;
+       if (bo) {
+               if (sna->render.vertex_size - sna->render.vertex_used < 64) {
+                       DBG(("%s: discarding full vbo\n", __FUNCTION__));
+                       sna->render.vbo = NULL;
+                       sna->render.vertices = sna->render.vertex_data;
+                       sna->render.vertex_size = ARRAY_SIZE(sna->render.vertex_data);
+                       free_bo = bo;
+               } else if (IS_CPU_MAP(bo->map)) {
+                       DBG(("%s: converting CPU map to GTT\n", __FUNCTION__));
+                       sna->render.vertices =
+                               kgem_bo_map__gtt(&sna->kgem, sna->render.vbo);
+                       if (sna->render.vertices == NULL) {
+                               sna->render.vbo = NULL;
+                               sna->render.vertices = sna->render.vertex_data;
+                               sna->render.vertex_size = ARRAY_SIZE(sna->render.vertex_data);
+                               free_bo = bo;
+                       }
+               }
+       } else {
+               if (sna->kgem.nbatch + sna->render.vertex_used <= sna->kgem.surface) {
+                       DBG(("%s: copy to batch: %d @ %d\n", __FUNCTION__,
+                            sna->render.vertex_used, sna->kgem.nbatch));
+                       memcpy(sna->kgem.batch + sna->kgem.nbatch,
+                              sna->render.vertex_data,
+                              sna->render.vertex_used * 4);
+                       delta = sna->kgem.nbatch * 4;
+                       bo = NULL;
+                       sna->kgem.nbatch += sna->render.vertex_used;
+               } else {
+                       bo = kgem_create_linear(&sna->kgem,
+                                               4*sna->render.vertex_used, 0);
+                       if (bo && !kgem_bo_write(&sna->kgem, bo,
+                                                sna->render.vertex_data,
+                                                4*sna->render.vertex_used)) {
+                               kgem_bo_destroy(&sna->kgem, bo);
+                               bo = NULL;
+                       }
+                       DBG(("%s: new vbo: %d\n", __FUNCTION__,
+                            sna->render.vertex_used));
+                       free_bo = bo;
+               }
+       }
+
+       assert(sna->render.nvertex_reloc);
+       for (i = 0; i < sna->render.nvertex_reloc; i++) {
+               DBG(("%s: reloc[%d] = %d\n", __FUNCTION__,
+                    i, sna->render.vertex_reloc[i]));
+
+               sna->kgem.batch[sna->render.vertex_reloc[i]] =
+                       kgem_add_reloc(&sna->kgem,
+                                      sna->render.vertex_reloc[i], bo,
+                                      I915_GEM_DOMAIN_VERTEX << 16,
+                                      delta);
+               sna->kgem.batch[sna->render.vertex_reloc[i]+1] =
+                       kgem_add_reloc(&sna->kgem,
+                                      sna->render.vertex_reloc[i]+1, bo,
+                                      I915_GEM_DOMAIN_VERTEX << 16,
+                                      delta + sna->render.vertex_used * 4 - 1);
+       }
+       sna->render.nvertex_reloc = 0;
+
+       if (sna->render.vbo == NULL) {
+               sna->render.vertex_used = 0;
+               sna->render.vertex_index = 0;
+       }
+
+       if (free_bo)
+               kgem_bo_destroy(&sna->kgem, free_bo);
+}
+
+static uint32_t gen5_get_blend(int op,
+                              bool has_component_alpha,
+                              uint32_t dst_format)
+{
+       uint32_t src, dst;
+
+       src = gen5_blend_op[op].src_blend;
+       dst = gen5_blend_op[op].dst_blend;
+
+       /* If there's no dst alpha channel, adjust the blend op so that we'll treat
+        * it as always 1.
+        */
+       if (PICT_FORMAT_A(dst_format) == 0) {
+               if (src == GEN5_BLENDFACTOR_DST_ALPHA)
+                       src = GEN5_BLENDFACTOR_ONE;
+               else if (src == GEN5_BLENDFACTOR_INV_DST_ALPHA)
+                       src = GEN5_BLENDFACTOR_ZERO;
+       }
+
+       /* If the source alpha is being used, then we should only be in a
+        * case where the source blend factor is 0, and the source blend
+        * value is the mask channels multiplied by the source picture's alpha.
+        */
+       if (has_component_alpha && gen5_blend_op[op].src_alpha) {
+               if (dst == GEN5_BLENDFACTOR_SRC_ALPHA)
+                       dst = GEN5_BLENDFACTOR_SRC_COLOR;
+               else if (dst == GEN5_BLENDFACTOR_INV_SRC_ALPHA)
+                       dst = GEN5_BLENDFACTOR_INV_SRC_COLOR;
+       }
+
+       DBG(("blend op=%d, dst=%x [A=%d] => src=%d, dst=%d => offset=%x\n",
+            op, dst_format, PICT_FORMAT_A(dst_format),
+            src, dst, BLEND_OFFSET(src, dst)));
+       return BLEND_OFFSET(src, dst);
+}
+
+static uint32_t gen5_get_card_format(PictFormat format)
+{
+       switch (format) {
+       default:
+               return -1;
+       case PICT_a8r8g8b8:
+               return GEN5_SURFACEFORMAT_B8G8R8A8_UNORM;
+       case PICT_x8r8g8b8:
+               return GEN5_SURFACEFORMAT_B8G8R8X8_UNORM;
+       case PICT_a8b8g8r8:
+               return GEN5_SURFACEFORMAT_R8G8B8A8_UNORM;
+       case PICT_x8b8g8r8:
+               return GEN5_SURFACEFORMAT_R8G8B8X8_UNORM;
+       case PICT_a2r10g10b10:
+               return GEN5_SURFACEFORMAT_B10G10R10A2_UNORM;
+       case PICT_x2r10g10b10:
+               return GEN5_SURFACEFORMAT_B10G10R10X2_UNORM;
+       case PICT_r8g8b8:
+               return GEN5_SURFACEFORMAT_R8G8B8_UNORM;
+       case PICT_r5g6b5:
+               return GEN5_SURFACEFORMAT_B5G6R5_UNORM;
+       case PICT_a1r5g5b5:
+               return GEN5_SURFACEFORMAT_B5G5R5A1_UNORM;
+       case PICT_a8:
+               return GEN5_SURFACEFORMAT_A8_UNORM;
+       case PICT_a4r4g4b4:
+               return GEN5_SURFACEFORMAT_B4G4R4A4_UNORM;
+       }
+}
+
+static uint32_t gen5_get_dest_format(PictFormat format)
+{
+       switch (format) {
+       default:
+               return -1;
+       case PICT_a8r8g8b8:
+       case PICT_x8r8g8b8:
+               return GEN5_SURFACEFORMAT_B8G8R8A8_UNORM;
+       case PICT_a8b8g8r8:
+       case PICT_x8b8g8r8:
+               return GEN5_SURFACEFORMAT_R8G8B8A8_UNORM;
+       case PICT_a2r10g10b10:
+       case PICT_x2r10g10b10:
+               return GEN5_SURFACEFORMAT_B10G10R10A2_UNORM;
+       case PICT_r5g6b5:
+               return GEN5_SURFACEFORMAT_B5G6R5_UNORM;
+       case PICT_x1r5g5b5:
+       case PICT_a1r5g5b5:
+               return GEN5_SURFACEFORMAT_B5G5R5A1_UNORM;
+       case PICT_a8:
+               return GEN5_SURFACEFORMAT_A8_UNORM;
+       case PICT_a4r4g4b4:
+       case PICT_x4r4g4b4:
+               return GEN5_SURFACEFORMAT_B4G4R4A4_UNORM;
+       }
+}
+
+static bool gen5_check_dst_format(PictFormat format)
+{
+       if (gen5_get_dest_format(format) != -1)
+               return true;
+
+       DBG(("%s: unhandled format: %x\n", __FUNCTION__, (int)format));
+       return false;
+}
+
+static bool gen5_check_format(uint32_t format)
+{
+       if (gen5_get_card_format(format) != -1)
+               return true;
+
+       DBG(("%s: unhandled format: %x\n", __FUNCTION__, (int)format));
+       return false;
+}
+
+typedef struct gen5_surface_state_padded {
+       struct gen5_surface_state state;
+       char pad[32 - sizeof(struct gen5_surface_state)];
+} gen5_surface_state_padded;
+
+static void null_create(struct sna_static_stream *stream)
+{
+       /* A bunch of zeros useful for legacy border color and depth-stencil */
+       sna_static_stream_map(stream, 64, 64);
+}
+
+static void
+sampler_state_init(struct gen5_sampler_state *sampler_state,
+                  sampler_filter_t filter,
+                  sampler_extend_t extend)
+{
+       sampler_state->ss0.lod_preclamp = 1;    /* GL mode */
+
+       /* We use the legacy mode to get the semantics specified by
+        * the Render extension. */
+       sampler_state->ss0.border_color_mode = GEN5_BORDER_COLOR_MODE_LEGACY;
+
+       switch (filter) {
+       default:
+       case SAMPLER_FILTER_NEAREST:
+               sampler_state->ss0.min_filter = GEN5_MAPFILTER_NEAREST;
+               sampler_state->ss0.mag_filter = GEN5_MAPFILTER_NEAREST;
+               break;
+       case SAMPLER_FILTER_BILINEAR:
+               sampler_state->ss0.min_filter = GEN5_MAPFILTER_LINEAR;
+               sampler_state->ss0.mag_filter = GEN5_MAPFILTER_LINEAR;
+               break;
+       }
+
+       switch (extend) {
+       default:
+       case SAMPLER_EXTEND_NONE:
+               sampler_state->ss1.r_wrap_mode = GEN5_TEXCOORDMODE_CLAMP_BORDER;
+               sampler_state->ss1.s_wrap_mode = GEN5_TEXCOORDMODE_CLAMP_BORDER;
+               sampler_state->ss1.t_wrap_mode = GEN5_TEXCOORDMODE_CLAMP_BORDER;
+               break;
+       case SAMPLER_EXTEND_REPEAT:
+               sampler_state->ss1.r_wrap_mode = GEN5_TEXCOORDMODE_WRAP;
+               sampler_state->ss1.s_wrap_mode = GEN5_TEXCOORDMODE_WRAP;
+               sampler_state->ss1.t_wrap_mode = GEN5_TEXCOORDMODE_WRAP;
+               break;
+       case SAMPLER_EXTEND_PAD:
+               sampler_state->ss1.r_wrap_mode = GEN5_TEXCOORDMODE_CLAMP;
+               sampler_state->ss1.s_wrap_mode = GEN5_TEXCOORDMODE_CLAMP;
+               sampler_state->ss1.t_wrap_mode = GEN5_TEXCOORDMODE_CLAMP;
+               break;
+       case SAMPLER_EXTEND_REFLECT:
+               sampler_state->ss1.r_wrap_mode = GEN5_TEXCOORDMODE_MIRROR;
+               sampler_state->ss1.s_wrap_mode = GEN5_TEXCOORDMODE_MIRROR;
+               sampler_state->ss1.t_wrap_mode = GEN5_TEXCOORDMODE_MIRROR;
+               break;
+       }
+}
+
+static uint32_t gen5_filter(uint32_t filter)
+{
+       switch (filter) {
+       default:
+               assert(0);
+       case PictFilterNearest:
+               return SAMPLER_FILTER_NEAREST;
+       case PictFilterBilinear:
+               return SAMPLER_FILTER_BILINEAR;
+       }
+}
+
+static uint32_t gen5_check_filter(PicturePtr picture)
+{
+       switch (picture->filter) {
+       case PictFilterNearest:
+       case PictFilterBilinear:
+               return true;
+       default:
+               DBG(("%s: unknown filter: %x\n", __FUNCTION__, picture->filter));
+               return false;
+       }
+}
+
+static uint32_t gen5_repeat(uint32_t repeat)
+{
+       switch (repeat) {
+       default:
+               assert(0);
+       case RepeatNone:
+               return SAMPLER_EXTEND_NONE;
+       case RepeatNormal:
+               return SAMPLER_EXTEND_REPEAT;
+       case RepeatPad:
+               return SAMPLER_EXTEND_PAD;
+       case RepeatReflect:
+               return SAMPLER_EXTEND_REFLECT;
+       }
+}
+
+static bool gen5_check_repeat(PicturePtr picture)
+{
+       if (!picture->repeat)
+               return true;
+
+       switch (picture->repeatType) {
+       case RepeatNone:
+       case RepeatNormal:
+       case RepeatPad:
+       case RepeatReflect:
+               return true;
+       default:
+               DBG(("%s: unknown repeat: %x\n",
+                    __FUNCTION__, picture->repeatType));
+               return false;
+       }
+}
+
+static uint32_t
+gen5_tiling_bits(uint32_t tiling)
+{
+       switch (tiling) {
+       default: assert(0);
+       case I915_TILING_NONE: return 0;
+       case I915_TILING_X: return GEN5_SURFACE_TILED;
+       case I915_TILING_Y: return GEN5_SURFACE_TILED | GEN5_SURFACE_TILED_Y;
+       }
+}
+
+/**
+ * Sets up the common fields for a surface state buffer for the given
+ * picture in the given surface state buffer.
+ */
+static uint32_t
+gen5_bind_bo(struct sna *sna,
+            struct kgem_bo *bo,
+            uint32_t width,
+            uint32_t height,
+            uint32_t format,
+            bool is_dst)
+{
+       uint32_t domains;
+       uint16_t offset;
+       uint32_t *ss;
+
+       /* After the first bind, we manage the cache domains within the batch */
+       if (!DBG_NO_SURFACE_CACHE) {
+               offset = kgem_bo_get_binding(bo, format);
+               if (offset) {
+                       if (is_dst)
+                               kgem_bo_mark_dirty(bo);
+                       return offset * sizeof(uint32_t);
+               }
+       }
+
+       offset = sna->kgem.surface -=
+               sizeof(struct gen5_surface_state_padded) / sizeof(uint32_t);
+       ss = sna->kgem.batch + offset;
+
+       ss[0] = (GEN5_SURFACE_2D << GEN5_SURFACE_TYPE_SHIFT |
+                GEN5_SURFACE_BLEND_ENABLED |
+                format << GEN5_SURFACE_FORMAT_SHIFT);
+
+       if (is_dst)
+               domains = I915_GEM_DOMAIN_RENDER << 16 | I915_GEM_DOMAIN_RENDER;
+       else
+               domains = I915_GEM_DOMAIN_SAMPLER << 16;
+       ss[1] = kgem_add_reloc(&sna->kgem, offset + 1, bo, domains, 0);
+
+       ss[2] = ((width - 1)  << GEN5_SURFACE_WIDTH_SHIFT |
+                (height - 1) << GEN5_SURFACE_HEIGHT_SHIFT);
+       ss[3] = (gen5_tiling_bits(bo->tiling) |
+                (bo->pitch - 1) << GEN5_SURFACE_PITCH_SHIFT);
+       ss[4] = 0;
+       ss[5] = 0;
+
+       kgem_bo_set_binding(bo, format, offset);
+
+       DBG(("[%x] bind bo(handle=%d, addr=%d), format=%d, width=%d, height=%d, pitch=%d, tiling=%d -> %s\n",
+            offset, bo->handle, ss[1],
+            format, width, height, bo->pitch, bo->tiling,
+            domains & 0xffff ? "render" : "sampler"));
+
+       return offset * sizeof(uint32_t);
+}
+
+fastcall static void
+gen5_emit_composite_primitive_solid(struct sna *sna,
+                                   const struct sna_composite_op *op,
+                                   const struct sna_composite_rectangles *r)
+{
+       float *v;
+       union {
+               struct sna_coordinate p;
+               float f;
+       } dst;
+
+       v = sna->render.vertices + sna->render.vertex_used;
+       sna->render.vertex_used += 9;
+
+       dst.p.x = r->dst.x + r->width;
+       dst.p.y = r->dst.y + r->height;
+       v[0] = dst.f;
+       v[1] = 1.;
+       v[2] = 1.;
+
+       dst.p.x = r->dst.x;
+       v[3] = dst.f;
+       v[4] = 0.;
+       v[5] = 1.;
+
+       dst.p.y = r->dst.y;
+       v[6] = dst.f;
+       v[7] = 0.;
+       v[8] = 0.;
+}
+
+fastcall static void
+gen5_emit_composite_primitive_identity_source(struct sna *sna,
+                                             const struct sna_composite_op *op,
+                                             const struct sna_composite_rectangles *r)
+{
+       const float *sf = op->src.scale;
+       float sx, sy, *v;
+       union {
+               struct sna_coordinate p;
+               float f;
+       } dst;
+
+       v = sna->render.vertices + sna->render.vertex_used;
+       sna->render.vertex_used += 9;
+
+       sx = r->src.x + op->src.offset[0];
+       sy = r->src.y + op->src.offset[1];
+
+       dst.p.x = r->dst.x + r->width;
+       dst.p.y = r->dst.y + r->height;
+       v[0] = dst.f;
+       v[1] = (sx + r->width) * sf[0];
+       v[5] = v[2] = (sy + r->height) * sf[1];
+
+       dst.p.x = r->dst.x;
+       v[3] = dst.f;
+       v[7] = v[4] = sx * sf[0];
+
+       dst.p.y = r->dst.y;
+       v[6] = dst.f;
+       v[8] = sy * sf[1];
+}
+
+fastcall static void
+gen5_emit_composite_primitive_affine_source(struct sna *sna,
+                                           const struct sna_composite_op *op,
+                                           const struct sna_composite_rectangles *r)
+{
+       union {
+               struct sna_coordinate p;
+               float f;
+       } dst;
+       float *v;
+
+       v = sna->render.vertices + sna->render.vertex_used;
+       sna->render.vertex_used += 9;
+
+       dst.p.x = r->dst.x + r->width;
+       dst.p.y = r->dst.y + r->height;
+       v[0] = dst.f;
+       _sna_get_transformed_coordinates(op->src.offset[0] + r->src.x + r->width,
+                                        op->src.offset[1] + r->src.y + r->height,
+                                        op->src.transform,
+                                        &v[1], &v[2]);
+       v[1] *= op->src.scale[0];
+       v[2] *= op->src.scale[1];
+
+       dst.p.x = r->dst.x;
+       v[3] = dst.f;
+       _sna_get_transformed_coordinates(op->src.offset[0] + r->src.x,
+                                        op->src.offset[1] + r->src.y + r->height,
+                                        op->src.transform,
+                                        &v[4], &v[5]);
+       v[4] *= op->src.scale[0];
+       v[5] *= op->src.scale[1];
+
+       dst.p.y = r->dst.y;
+       v[6] = dst.f;
+       _sna_get_transformed_coordinates(op->src.offset[0] + r->src.x,
+                                        op->src.offset[1] + r->src.y,
+                                        op->src.transform,
+                                        &v[7], &v[8]);
+       v[7] *= op->src.scale[0];
+       v[8] *= op->src.scale[1];
+}
+
+fastcall static void
+gen5_emit_composite_primitive_identity_source_mask(struct sna *sna,
+                                                  const struct sna_composite_op *op,
+                                                  const struct sna_composite_rectangles *r)
+{
+       union {
+               struct sna_coordinate p;
+               float f;
+       } dst;
+       float src_x, src_y;
+       float msk_x, msk_y;
+       float w, h;
+       float *v;
+
+       src_x = r->src.x + op->src.offset[0];
+       src_y = r->src.y + op->src.offset[1];
+       msk_x = r->mask.x + op->mask.offset[0];
+       msk_y = r->mask.y + op->mask.offset[1];
+       w = r->width;
+       h = r->height;
+
+       v = sna->render.vertices + sna->render.vertex_used;
+       sna->render.vertex_used += 15;
+
+       dst.p.x = r->dst.x + r->width;
+       dst.p.y = r->dst.y + r->height;
+       v[0] = dst.f;
+       v[1] = (src_x + w) * op->src.scale[0];
+       v[2] = (src_y + h) * op->src.scale[1];
+       v[3] = (msk_x + w) * op->mask.scale[0];
+       v[4] = (msk_y + h) * op->mask.scale[1];
+
+       dst.p.x = r->dst.x;
+       v[5] = dst.f;
+       v[6] = src_x * op->src.scale[0];
+       v[7] = v[2];
+       v[8] = msk_x * op->mask.scale[0];
+       v[9] = v[4];
+
+       dst.p.y = r->dst.y;
+       v[10] = dst.f;
+       v[11] = v[6];
+       v[12] = src_y * op->src.scale[1];
+       v[13] = v[8];
+       v[14] = msk_y * op->mask.scale[1];
+}
+
+fastcall static void
+gen5_emit_composite_primitive(struct sna *sna,
+                             const struct sna_composite_op *op,
+                             const struct sna_composite_rectangles *r)
+{
+       float src_x[3], src_y[3], src_w[3], mask_x[3], mask_y[3], mask_w[3];
+       bool is_affine = op->is_affine;
+       const float *src_sf = op->src.scale;
+       const float *mask_sf = op->mask.scale;
+
+       if (is_affine) {
+               sna_get_transformed_coordinates(r->src.x + op->src.offset[0],
+                                               r->src.y + op->src.offset[1],
+                                               op->src.transform,
+                                               &src_x[0],
+                                               &src_y[0]);
+
+               sna_get_transformed_coordinates(r->src.x + op->src.offset[0],
+                                               r->src.y + op->src.offset[1] + r->height,
+                                               op->src.transform,
+                                               &src_x[1],
+                                               &src_y[1]);
+
+               sna_get_transformed_coordinates(r->src.x + op->src.offset[0] + r->width,
+                                               r->src.y + op->src.offset[1] + r->height,
+                                               op->src.transform,
+                                               &src_x[2],
+                                               &src_y[2]);
+       } else {
+               sna_get_transformed_coordinates_3d(r->src.x + op->src.offset[0],
+                                                  r->src.y + op->src.offset[1],
+                                                  op->src.transform,
+                                                  &src_x[0],
+                                                  &src_y[0],
+                                                  &src_w[0]);
+               sna_get_transformed_coordinates_3d(r->src.x + op->src.offset[0],
+                                                  r->src.y + op->src.offset[1] + r->height,
+                                                  op->src.transform,
+                                                  &src_x[1],
+                                                  &src_y[1],
+                                                  &src_w[1]);
+               sna_get_transformed_coordinates_3d(r->src.x + op->src.offset[0] + r->width,
+                                                  r->src.y + op->src.offset[1] + r->height,
+                                                  op->src.transform,
+                                                  &src_x[2],
+                                                  &src_y[2],
+                                                  &src_w[2]);
+       }
+
+       if (op->mask.bo) {
+               if (is_affine) {
+                       sna_get_transformed_coordinates(r->mask.x + op->mask.offset[0],
+                                                       r->mask.y + op->mask.offset[1],
+                                                       op->mask.transform,
+                                                       &mask_x[0],
+                                                       &mask_y[0]);
+
+                       sna_get_transformed_coordinates(r->mask.x + op->mask.offset[0],
+                                                       r->mask.y + op->mask.offset[1] + r->height,
+                                                       op->mask.transform,
+                                                       &mask_x[1],
+                                                       &mask_y[1]);
+
+                       sna_get_transformed_coordinates(r->mask.x + op->mask.offset[0] + r->width,
+                                                       r->mask.y + op->mask.offset[1] + r->height,
+                                                       op->mask.transform,
+                                                       &mask_x[2],
+                                                       &mask_y[2]);
+               } else {
+                       sna_get_transformed_coordinates_3d(r->mask.x + op->mask.offset[0],
+                                                          r->mask.y + op->mask.offset[1],
+                                                          op->mask.transform,
+                                                          &mask_x[0],
+                                                          &mask_y[0],
+                                                          &mask_w[0]);
+
+                       sna_get_transformed_coordinates_3d(r->mask.x + op->mask.offset[0],
+                                                          r->mask.y + op->mask.offset[1] + r->height,
+                                                          op->mask.transform,
+                                                          &mask_x[1],
+                                                          &mask_y[1],
+                                                          &mask_w[1]);
+                       sna_get_transformed_coordinates_3d(r->mask.x + op->mask.offset[0] + r->width,
+                                                          r->mask.y + op->mask.offset[1] + r->height,
+                                                          op->mask.transform,
+                                                          &mask_x[2],
+                                                          &mask_y[2],
+                                                          &mask_w[2]);
+               }
+       }
+
+       OUT_VERTEX(r->dst.x + r->width, r->dst.y + r->height);
+       OUT_VERTEX_F(src_x[2] * src_sf[0]);
+       OUT_VERTEX_F(src_y[2] * src_sf[1]);
+       if (!is_affine)
+               OUT_VERTEX_F(src_w[2]);
+       if (op->mask.bo) {
+               OUT_VERTEX_F(mask_x[2] * mask_sf[0]);
+               OUT_VERTEX_F(mask_y[2] * mask_sf[1]);
+               if (!is_affine)
+                       OUT_VERTEX_F(mask_w[2]);
+       }
+
+       OUT_VERTEX(r->dst.x, r->dst.y + r->height);
+       OUT_VERTEX_F(src_x[1] * src_sf[0]);
+       OUT_VERTEX_F(src_y[1] * src_sf[1]);
+       if (!is_affine)
+               OUT_VERTEX_F(src_w[1]);
+       if (op->mask.bo) {
+               OUT_VERTEX_F(mask_x[1] * mask_sf[0]);
+               OUT_VERTEX_F(mask_y[1] * mask_sf[1]);
+               if (!is_affine)
+                       OUT_VERTEX_F(mask_w[1]);
+       }
+
+       OUT_VERTEX(r->dst.x, r->dst.y);
+       OUT_VERTEX_F(src_x[0] * src_sf[0]);
+       OUT_VERTEX_F(src_y[0] * src_sf[1]);
+       if (!is_affine)
+               OUT_VERTEX_F(src_w[0]);
+       if (op->mask.bo) {
+               OUT_VERTEX_F(mask_x[0] * mask_sf[0]);
+               OUT_VERTEX_F(mask_y[0] * mask_sf[1]);
+               if (!is_affine)
+                       OUT_VERTEX_F(mask_w[0]);
+       }
+}
+
+static void gen5_emit_vertex_buffer(struct sna *sna,
+                                   const struct sna_composite_op *op)
+{
+       int id = op->u.gen5.ve_id;
+
+       assert((unsigned)id <= 3);
+
+       OUT_BATCH(GEN5_3DSTATE_VERTEX_BUFFERS | 3);
+       OUT_BATCH((id << VB0_BUFFER_INDEX_SHIFT) | VB0_VERTEXDATA |
+                 (4*op->floats_per_vertex << VB0_BUFFER_PITCH_SHIFT));
+       sna->render.vertex_reloc[sna->render.nvertex_reloc++] = sna->kgem.nbatch;
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+
+       sna->render_state.gen5.vb_id |= 1 << id;
+}
+
+static void gen5_emit_primitive(struct sna *sna)
+{
+       if (sna->kgem.nbatch == sna->render_state.gen5.last_primitive) {
+               sna->render_state.gen5.vertex_offset = sna->kgem.nbatch - 5;
+               return;
+       }
+
+       OUT_BATCH(GEN5_3DPRIMITIVE |
+                 GEN5_3DPRIMITIVE_VERTEX_SEQUENTIAL |
+                 (_3DPRIM_RECTLIST << GEN5_3DPRIMITIVE_TOPOLOGY_SHIFT) |
+                 (0 << 9) |
+                 4);
+       sna->render_state.gen5.vertex_offset = sna->kgem.nbatch;
+       OUT_BATCH(0);   /* vertex count, to be filled in later */
+       OUT_BATCH(sna->render.vertex_index);
+       OUT_BATCH(1);   /* single instance */
+       OUT_BATCH(0);   /* start instance location */
+       OUT_BATCH(0);   /* index buffer offset, ignored */
+       sna->render.vertex_start = sna->render.vertex_index;
+
+       sna->render_state.gen5.last_primitive = sna->kgem.nbatch;
+}
+
+static bool gen5_rectangle_begin(struct sna *sna,
+                                const struct sna_composite_op *op)
+{
+       int id = op->u.gen5.ve_id;
+       int ndwords;
+
+       assert((unsigned)id <= 3);
+
+       ndwords = op->need_magic_ca_pass ? 20 : 6;
+       if ((sna->render_state.gen5.vb_id & (1 << id)) == 0)
+               ndwords += 5;
+
+       if (!kgem_check_batch(&sna->kgem, ndwords))
+               return false;
+
+       if ((sna->render_state.gen5.vb_id & (1 << id)) == 0)
+               gen5_emit_vertex_buffer(sna, op);
+       if (sna->render_state.gen5.vertex_offset == 0)
+               gen5_emit_primitive(sna);
+
+       return true;
+}
+
+static int gen5_get_rectangles__flush(struct sna *sna,
+                                     const struct sna_composite_op *op)
+{
+       if (!kgem_check_batch(&sna->kgem, op->need_magic_ca_pass ? 20 : 6))
+               return 0;
+       if (!kgem_check_exec(&sna->kgem, 1))
+               return 0;
+       if (!kgem_check_reloc(&sna->kgem, 2))
+               return 0;
+
+       if (op->need_magic_ca_pass && sna->render.vbo)
+               return 0;
+
+       return gen5_vertex_finish(sna);
+}
+
+inline static int gen5_get_rectangles(struct sna *sna,
+                                     const struct sna_composite_op *op,
+                                     int want,
+                                     void (*emit_state)(struct sna *sna,
+                                                        const struct sna_composite_op *op))
+{
+       int rem;
+
+start:
+       rem = vertex_space(sna);
+       if (rem < op->floats_per_rect) {
+               DBG(("flushing vbo for %s: %d < %d\n",
+                    __FUNCTION__, rem, op->floats_per_rect));
+               rem = gen5_get_rectangles__flush(sna, op);
+               if (unlikely (rem == 0))
+                       goto flush;
+       }
+
+       if (unlikely(sna->render_state.gen5.vertex_offset == 0 &&
+                    !gen5_rectangle_begin(sna, op)))
+               goto flush;
+
+       if (want * op->floats_per_rect > rem)
+               want = rem / op->floats_per_rect;
+
+       sna->render.vertex_index += 3*want;
+       return want;
+
+flush:
+       if (sna->render_state.gen5.vertex_offset) {
+               gen5_vertex_flush(sna);
+               gen5_magic_ca_pass(sna, op);
+       }
+       _kgem_submit(&sna->kgem);
+       emit_state(sna, op);
+       goto start;
+}
+
+static uint32_t *
+gen5_composite_get_binding_table(struct sna *sna,
+                                uint16_t *offset)
+{
+       uint32_t *table;
+
+       sna->kgem.surface -=
+               sizeof(struct gen5_surface_state_padded) / sizeof(uint32_t);
+       /* Clear all surplus entries to zero in case of prefetch */
+       table = memset(sna->kgem.batch + sna->kgem.surface,
+                      0, sizeof(struct gen5_surface_state_padded));
+       *offset = sna->kgem.surface;
+
+       DBG(("%s(%x)\n", __FUNCTION__, 4*sna->kgem.surface));
+
+       return table;
+}
+
+static void
+gen5_emit_urb(struct sna *sna)
+{
+       int urb_vs_start, urb_vs_size;
+       int urb_gs_start, urb_gs_size;
+       int urb_clip_start, urb_clip_size;
+       int urb_sf_start, urb_sf_size;
+       int urb_cs_start, urb_cs_size;
+
+       urb_vs_start = 0;
+       urb_vs_size = URB_VS_ENTRIES * URB_VS_ENTRY_SIZE;
+       urb_gs_start = urb_vs_start + urb_vs_size;
+       urb_gs_size = URB_GS_ENTRIES * URB_GS_ENTRY_SIZE;
+       urb_clip_start = urb_gs_start + urb_gs_size;
+       urb_clip_size = URB_CLIP_ENTRIES * URB_CLIP_ENTRY_SIZE;
+       urb_sf_start = urb_clip_start + urb_clip_size;
+       urb_sf_size = URB_SF_ENTRIES * URB_SF_ENTRY_SIZE;
+       urb_cs_start = urb_sf_start + urb_sf_size;
+       urb_cs_size = URB_CS_ENTRIES * URB_CS_ENTRY_SIZE;
+
+       OUT_BATCH(GEN5_URB_FENCE |
+                 UF0_CS_REALLOC |
+                 UF0_SF_REALLOC |
+                 UF0_CLIP_REALLOC |
+                 UF0_GS_REALLOC |
+                 UF0_VS_REALLOC |
+                 1);
+       OUT_BATCH(((urb_clip_start + urb_clip_size) << UF1_CLIP_FENCE_SHIFT) |
+                 ((urb_gs_start + urb_gs_size) << UF1_GS_FENCE_SHIFT) |
+                 ((urb_vs_start + urb_vs_size) << UF1_VS_FENCE_SHIFT));
+       OUT_BATCH(((urb_cs_start + urb_cs_size) << UF2_CS_FENCE_SHIFT) |
+                 ((urb_sf_start + urb_sf_size) << UF2_SF_FENCE_SHIFT));
+
+       /* Constant buffer state */
+       OUT_BATCH(GEN5_CS_URB_STATE | 0);
+       OUT_BATCH((URB_CS_ENTRY_SIZE - 1) << 4 | URB_CS_ENTRIES << 0);
+}
+
+static void
+gen5_emit_state_base_address(struct sna *sna)
+{
+       assert(sna->render_state.gen5.general_bo->proxy == NULL);
+       OUT_BATCH(GEN5_STATE_BASE_ADDRESS | 6);
+       OUT_BATCH(kgem_add_reloc(&sna->kgem, /* general */
+                                sna->kgem.nbatch,
+                                sna->render_state.gen5.general_bo,
+                                I915_GEM_DOMAIN_INSTRUCTION << 16,
+                                BASE_ADDRESS_MODIFY));
+       OUT_BATCH(kgem_add_reloc(&sna->kgem, /* surface */
+                                sna->kgem.nbatch,
+                                NULL,
+                                I915_GEM_DOMAIN_INSTRUCTION << 16,
+                                BASE_ADDRESS_MODIFY));
+       OUT_BATCH(0); /* media */
+       OUT_BATCH(kgem_add_reloc(&sna->kgem, /* instruction */
+                                sna->kgem.nbatch,
+                                sna->render_state.gen5.general_bo,
+                                I915_GEM_DOMAIN_INSTRUCTION << 16,
+                                BASE_ADDRESS_MODIFY));
+
+       /* upper bounds, all disabled */
+       OUT_BATCH(BASE_ADDRESS_MODIFY);
+       OUT_BATCH(0);
+       OUT_BATCH(BASE_ADDRESS_MODIFY);
+}
+
+static void
+gen5_emit_invariant(struct sna *sna)
+{
+       /* Ironlake errata workaround: Before disabling the clipper,
+        * you have to MI_FLUSH to get the pipeline idle.
+        *
+        * However, the kernel flushes the pipeline between batches,
+        * so we should be safe....
+        * OUT_BATCH(MI_FLUSH | MI_INHIBIT_RENDER_CACHE_FLUSH);
+        */
+       OUT_BATCH(GEN5_PIPELINE_SELECT | PIPELINE_SELECT_3D);
+
+       gen5_emit_state_base_address(sna);
+
+       sna->render_state.gen5.needs_invariant = false;
+}
+
+static void
+gen5_get_batch(struct sna *sna)
+{
+       kgem_set_mode(&sna->kgem, KGEM_RENDER);
+
+       if (!kgem_check_batch_with_surfaces(&sna->kgem, 150, 4)) {
+               DBG(("%s: flushing batch: %d < %d+%d\n",
+                    __FUNCTION__, sna->kgem.surface - sna->kgem.nbatch,
+                    150, 4*8));
+               kgem_submit(&sna->kgem);
+               _kgem_set_mode(&sna->kgem, KGEM_RENDER);
+       }
+
+       if (sna->render_state.gen5.needs_invariant)
+               gen5_emit_invariant(sna);
+}
+
+static void
+gen5_align_vertex(struct sna *sna, const struct sna_composite_op *op)
+{
+       if (op->floats_per_vertex != sna->render_state.gen5.floats_per_vertex) {
+               if (sna->render.vertex_size - sna->render.vertex_used < 2*op->floats_per_rect)
+                       gen5_vertex_finish(sna);
+
+               DBG(("aligning vertex: was %d, now %d floats per vertex, %d->%d\n",
+                    sna->render_state.gen5.floats_per_vertex,
+                    op->floats_per_vertex,
+                    sna->render.vertex_index,
+                    (sna->render.vertex_used + op->floats_per_vertex - 1) / op->floats_per_vertex));
+               sna->render.vertex_index = (sna->render.vertex_used + op->floats_per_vertex - 1) / op->floats_per_vertex;
+               sna->render.vertex_used = sna->render.vertex_index * op->floats_per_vertex;
+               sna->render_state.gen5.floats_per_vertex = op->floats_per_vertex;
+       }
+}
+
+static void
+gen5_emit_binding_table(struct sna *sna, uint16_t offset)
+{
+       if (!DBG_NO_STATE_CACHE &&
+           sna->render_state.gen5.surface_table == offset)
+               return;
+
+       sna->render_state.gen5.surface_table = offset;
+
+       /* Binding table pointers */
+       OUT_BATCH(GEN5_3DSTATE_BINDING_TABLE_POINTERS | 4);
+       OUT_BATCH(0);           /* vs */
+       OUT_BATCH(0);           /* gs */
+       OUT_BATCH(0);           /* clip */
+       OUT_BATCH(0);           /* sf */
+       /* Only the PS uses the binding table */
+       OUT_BATCH(offset*4);
+}
+
+static bool
+gen5_emit_pipelined_pointers(struct sna *sna,
+                            const struct sna_composite_op *op,
+                            int blend, int kernel)
+{
+       uint16_t offset = sna->kgem.nbatch, last;
+
+       OUT_BATCH(GEN5_3DSTATE_PIPELINED_POINTERS | 5);
+       OUT_BATCH(sna->render_state.gen5.vs);
+       OUT_BATCH(GEN5_GS_DISABLE); /* passthrough */
+       OUT_BATCH(GEN5_CLIP_DISABLE); /* passthrough */
+       OUT_BATCH(sna->render_state.gen5.sf[op->mask.bo != NULL]);
+       OUT_BATCH(sna->render_state.gen5.wm +
+                 SAMPLER_OFFSET(op->src.filter, op->src.repeat,
+                                op->mask.filter, op->mask.repeat,
+                                kernel));
+       OUT_BATCH(sna->render_state.gen5.cc +
+                 gen5_get_blend(blend, op->has_component_alpha, op->dst.format));
+
+       last = sna->render_state.gen5.last_pipelined_pointers;
+       if (!DBG_NO_STATE_CACHE && last &&
+           sna->kgem.batch[offset + 1] == sna->kgem.batch[last + 1] &&
+           sna->kgem.batch[offset + 3] == sna->kgem.batch[last + 3] &&
+           sna->kgem.batch[offset + 4] == sna->kgem.batch[last + 4] &&
+           sna->kgem.batch[offset + 5] == sna->kgem.batch[last + 5] &&
+           sna->kgem.batch[offset + 6] == sna->kgem.batch[last + 6]) {
+               sna->kgem.nbatch = offset;
+               return false;
+       } else {
+               sna->render_state.gen5.last_pipelined_pointers = offset;
+               return true;
+       }
+}
+
+static void
+gen5_emit_drawing_rectangle(struct sna *sna, const struct sna_composite_op *op)
+{
+       uint32_t limit = (op->dst.height - 1) << 16 | (op->dst.width - 1);
+       uint32_t offset = (uint16_t)op->dst.y << 16 | (uint16_t)op->dst.x;
+
+       assert(!too_large(op->dst.x, op->dst.y));
+       assert(!too_large(op->dst.width, op->dst.height));
+
+       if (!DBG_NO_STATE_CACHE &&
+           sna->render_state.gen5.drawrect_limit == limit &&
+           sna->render_state.gen5.drawrect_offset == offset)
+               return;
+       sna->render_state.gen5.drawrect_offset = offset;
+       sna->render_state.gen5.drawrect_limit = limit;
+
+       OUT_BATCH(GEN5_3DSTATE_DRAWING_RECTANGLE | (4 - 2));
+       OUT_BATCH(0x00000000);
+       OUT_BATCH(limit);
+       OUT_BATCH(offset);
+}
+
+static void
+gen5_emit_vertex_elements(struct sna *sna,
+                         const struct sna_composite_op *op)
+{
+       /*
+        * vertex data in vertex buffer
+        *    position: (x, y)
+        *    texture coordinate 0: (u0, v0) if (is_affine is true) else (u0, v0, w0)
+        *    texture coordinate 1 if (has_mask is true): same as above
+        */
+       struct gen5_render_state *render = &sna->render_state.gen5;
+       bool has_mask = op->mask.bo != NULL;
+       bool is_affine = op->is_affine;
+       int nelem = has_mask ? 2 : 1;
+       int selem = is_affine ? 2 : 3;
+       uint32_t w_component;
+       uint32_t src_format;
+       int id = op->u.gen5.ve_id;
+
+       assert((unsigned)id <= 3);
+       if (!DBG_NO_STATE_CACHE && render->ve_id == id)
+               return;
+
+       render->ve_id = id;
+
+       if (is_affine) {
+               src_format = GEN5_SURFACEFORMAT_R32G32_FLOAT;
+               w_component = GEN5_VFCOMPONENT_STORE_1_FLT;
+       } else {
+               src_format = GEN5_SURFACEFORMAT_R32G32B32_FLOAT;
+               w_component = GEN5_VFCOMPONENT_STORE_SRC;
+       }
+
+       /* The VUE layout
+        *    dword 0-3: pad (0.0, 0.0, 0.0. 0.0)
+        *    dword 4-7: position (x, y, 1.0, 1.0),
+        *    dword 8-11: texture coordinate 0 (u0, v0, w0, 1.0)
+        *    dword 12-15: texture coordinate 1 (u1, v1, w1, 1.0)
+        *
+        * dword 4-15 are fetched from vertex buffer
+        */
+       OUT_BATCH(GEN5_3DSTATE_VERTEX_ELEMENTS |
+               ((2 * (2 + nelem)) + 1 - 2));
+
+       OUT_BATCH((id << VE0_VERTEX_BUFFER_INDEX_SHIFT) | VE0_VALID |
+                 (GEN5_SURFACEFORMAT_R32G32B32A32_FLOAT << VE0_FORMAT_SHIFT) |
+                 (0 << VE0_OFFSET_SHIFT));
+       OUT_BATCH((GEN5_VFCOMPONENT_STORE_0 << VE1_VFCOMPONENT_0_SHIFT) |
+                 (GEN5_VFCOMPONENT_STORE_0 << VE1_VFCOMPONENT_1_SHIFT) |
+                 (GEN5_VFCOMPONENT_STORE_0 << VE1_VFCOMPONENT_2_SHIFT) |
+                 (GEN5_VFCOMPONENT_STORE_0 << VE1_VFCOMPONENT_3_SHIFT));
+
+       /* x,y */
+       OUT_BATCH((id << VE0_VERTEX_BUFFER_INDEX_SHIFT) | VE0_VALID |
+                 (GEN5_SURFACEFORMAT_R16G16_SSCALED << VE0_FORMAT_SHIFT) |
+                 (0 << VE0_OFFSET_SHIFT)); /* offsets vb in bytes */
+       OUT_BATCH((GEN5_VFCOMPONENT_STORE_SRC << VE1_VFCOMPONENT_0_SHIFT) |
+                 (GEN5_VFCOMPONENT_STORE_SRC << VE1_VFCOMPONENT_1_SHIFT) |
+                 (GEN5_VFCOMPONENT_STORE_1_FLT << VE1_VFCOMPONENT_2_SHIFT) |
+                 (GEN5_VFCOMPONENT_STORE_1_FLT << VE1_VFCOMPONENT_3_SHIFT));
+
+       /* u0, v0, w0 */
+       OUT_BATCH((id << VE0_VERTEX_BUFFER_INDEX_SHIFT) | VE0_VALID |
+                 (src_format << VE0_FORMAT_SHIFT) |
+                 (4 << VE0_OFFSET_SHIFT));     /* offset vb in bytes */
+       OUT_BATCH((GEN5_VFCOMPONENT_STORE_SRC << VE1_VFCOMPONENT_0_SHIFT) |
+                 (GEN5_VFCOMPONENT_STORE_SRC << VE1_VFCOMPONENT_1_SHIFT) |
+                 (w_component << VE1_VFCOMPONENT_2_SHIFT) |
+                 (GEN5_VFCOMPONENT_STORE_1_FLT << VE1_VFCOMPONENT_3_SHIFT));
+
+       /* u1, v1, w1 */
+       if (has_mask) {
+               OUT_BATCH((id << VE0_VERTEX_BUFFER_INDEX_SHIFT) | VE0_VALID |
+                         (src_format << VE0_FORMAT_SHIFT) |
+                         (((1 + selem) * 4) << VE0_OFFSET_SHIFT)); /* vb offset in bytes */
+               OUT_BATCH((GEN5_VFCOMPONENT_STORE_SRC << VE1_VFCOMPONENT_0_SHIFT) |
+                         (GEN5_VFCOMPONENT_STORE_SRC << VE1_VFCOMPONENT_1_SHIFT) |
+                         (w_component << VE1_VFCOMPONENT_2_SHIFT) |
+                         (GEN5_VFCOMPONENT_STORE_1_FLT << VE1_VFCOMPONENT_3_SHIFT));
+       }
+}
+
+static void
+gen5_emit_state(struct sna *sna,
+               const struct sna_composite_op *op,
+               uint16_t offset)
+{
+       /* drawrect must be first for Ironlake BLT workaround */
+       gen5_emit_drawing_rectangle(sna, op);
+
+       gen5_emit_binding_table(sna, offset);
+       if (gen5_emit_pipelined_pointers(sna, op, op->op, op->u.gen5.wm_kernel))
+               gen5_emit_urb(sna);
+       gen5_emit_vertex_elements(sna, op);
+
+       if (kgem_bo_is_dirty(op->src.bo) || kgem_bo_is_dirty(op->mask.bo)) {
+               OUT_BATCH(MI_FLUSH);
+               kgem_clear_dirty(&sna->kgem);
+               kgem_bo_mark_dirty(op->dst.bo);
+       }
+}
+
+static void gen5_bind_surfaces(struct sna *sna,
+                              const struct sna_composite_op *op)
+{
+       uint32_t *binding_table;
+       uint16_t offset;
+
+       gen5_get_batch(sna);
+
+       binding_table = gen5_composite_get_binding_table(sna, &offset);
+
+       binding_table[0] =
+               gen5_bind_bo(sna,
+                           op->dst.bo, op->dst.width, op->dst.height,
+                           gen5_get_dest_format(op->dst.format),
+                           true);
+       binding_table[1] =
+               gen5_bind_bo(sna,
+                            op->src.bo, op->src.width, op->src.height,
+                            op->src.card_format,
+                            false);
+       if (op->mask.bo)
+               binding_table[2] =
+                       gen5_bind_bo(sna,
+                                    op->mask.bo,
+                                    op->mask.width,
+                                    op->mask.height,
+                                    op->mask.card_format,
+                                    false);
+
+       if (sna->kgem.surface == offset &&
+           *(uint64_t *)(sna->kgem.batch + sna->render_state.gen5.surface_table) == *(uint64_t*)binding_table &&
+           (op->mask.bo == NULL ||
+            sna->kgem.batch[sna->render_state.gen5.surface_table+2] == binding_table[2])) {
+               sna->kgem.surface += sizeof(struct gen5_surface_state_padded) / sizeof(uint32_t);
+               offset = sna->render_state.gen5.surface_table;
+       }
+
+       gen5_emit_state(sna, op, offset);
+}
+
+fastcall static void
+gen5_render_composite_blt(struct sna *sna,
+                         const struct sna_composite_op *op,
+                         const struct sna_composite_rectangles *r)
+{
+       DBG(("%s: src=(%d, %d)+(%d, %d), mask=(%d, %d)+(%d, %d), dst=(%d, %d)+(%d, %d), size=(%d, %d)\n",
+            __FUNCTION__,
+            r->src.x, r->src.y, op->src.offset[0], op->src.offset[1],
+            r->mask.x, r->mask.y, op->mask.offset[0], op->mask.offset[1],
+            r->dst.x, r->dst.y, op->dst.x, op->dst.y,
+            r->width, r->height));
+
+       gen5_get_rectangles(sna, op, 1, gen5_bind_surfaces);
+       op->prim_emit(sna, op, r);
+}
+
+fastcall static void
+gen5_render_composite_box(struct sna *sna,
+                         const struct sna_composite_op *op,
+                         const BoxRec *box)
+{
+       struct sna_composite_rectangles r;
+
+       DBG(("  %s: (%d, %d), (%d, %d)\n",
+            __FUNCTION__,
+            box->x1, box->y1, box->x2, box->y2));
+
+       gen5_get_rectangles(sna, op, 1, gen5_bind_surfaces);
+
+       r.dst.x = box->x1;
+       r.dst.y = box->y1;
+       r.width  = box->x2 - box->x1;
+       r.height = box->y2 - box->y1;
+       r.mask = r.src = r.dst;
+
+       op->prim_emit(sna, op, &r);
+}
+
+static void
+gen5_render_composite_boxes(struct sna *sna,
+                           const struct sna_composite_op *op,
+                           const BoxRec *box, int nbox)
+{
+       DBG(("%s(%d) delta=(%d, %d), src=(%d, %d)/(%d, %d), mask=(%d, %d)/(%d, %d)\n",
+            __FUNCTION__, nbox, op->dst.x, op->dst.y,
+            op->src.offset[0], op->src.offset[1],
+            op->src.width, op->src.height,
+            op->mask.offset[0], op->mask.offset[1],
+            op->mask.width, op->mask.height));
+
+       do {
+               int nbox_this_time;
+
+               nbox_this_time = gen5_get_rectangles(sna, op, nbox,
+                                                    gen5_bind_surfaces);
+               nbox -= nbox_this_time;
+
+               do {
+                       struct sna_composite_rectangles r;
+
+                       DBG(("  %s: (%d, %d), (%d, %d)\n",
+                            __FUNCTION__,
+                            box->x1, box->y1, box->x2, box->y2));
+
+                       r.dst.x = box->x1;
+                       r.dst.y = box->y1;
+                       r.width  = box->x2 - box->x1;
+                       r.height = box->y2 - box->y1;
+                       r.mask = r.src = r.dst;
+                       op->prim_emit(sna, op, &r);
+                       box++;
+               } while (--nbox_this_time);
+       } while (nbox);
+}
+
+#ifndef MAX
+#define MAX(a,b) ((a) > (b) ? (a) : (b))
+#endif
+
+static uint32_t gen5_bind_video_source(struct sna *sna,
+                                      struct kgem_bo *src_bo,
+                                      uint32_t src_offset,
+                                      int src_width,
+                                      int src_height,
+                                      int src_pitch,
+                                      uint32_t src_surf_format)
+{
+       struct gen5_surface_state *ss;
+
+       sna->kgem.surface -= sizeof(struct gen5_surface_state_padded) / sizeof(uint32_t);
+
+       ss = memset(sna->kgem.batch + sna->kgem.surface, 0, sizeof(*ss));
+       ss->ss0.surface_type = GEN5_SURFACE_2D;
+       ss->ss0.surface_format = src_surf_format;
+       ss->ss0.color_blend = 1;
+
+       ss->ss1.base_addr =
+               kgem_add_reloc(&sna->kgem,
+                              sna->kgem.surface + 1,
+                              src_bo,
+                              I915_GEM_DOMAIN_SAMPLER << 16,
+                              src_offset);
+
+       ss->ss2.width  = src_width - 1;
+       ss->ss2.height = src_height - 1;
+       ss->ss3.pitch  = src_pitch - 1;
+
+       return sna->kgem.surface * sizeof(uint32_t);
+}
+
+static void gen5_video_bind_surfaces(struct sna *sna,
+                                    const struct sna_composite_op *op)
+{
+       struct sna_video_frame *frame = op->priv;
+       uint32_t src_surf_format;
+       uint32_t src_surf_base[6];
+       int src_width[6];
+       int src_height[6];
+       int src_pitch[6];
+       uint32_t *binding_table;
+       int n_src, n;
+       uint16_t offset;
+
+
+       src_surf_base[0] = 0;
+       src_surf_base[1] = 0;
+       src_surf_base[2] = frame->VBufOffset;
+       src_surf_base[3] = frame->VBufOffset;
+       src_surf_base[4] = frame->UBufOffset;
+       src_surf_base[5] = frame->UBufOffset;
+
+       if (is_planar_fourcc(frame->id)) {
+               src_surf_format = GEN5_SURFACEFORMAT_R8_UNORM;
+               src_width[1]  = src_width[0]  = frame->width;
+               src_height[1] = src_height[0] = frame->height;
+               src_pitch[1]  = src_pitch[0]  = frame->pitch[1];
+               src_width[4]  = src_width[5]  = src_width[2]  = src_width[3] =
+                       frame->width / 2;
+               src_height[4] = src_height[5] = src_height[2] = src_height[3] =
+                       frame->height / 2;
+               src_pitch[4]  = src_pitch[5]  = src_pitch[2]  = src_pitch[3] =
+                       frame->pitch[0];
+               n_src = 6;
+       } else {
+               if (frame->id == FOURCC_UYVY)
+                       src_surf_format = GEN5_SURFACEFORMAT_YCRCB_SWAPY;
+               else
+                       src_surf_format = GEN5_SURFACEFORMAT_YCRCB_NORMAL;
+
+               src_width[0]  = frame->width;
+               src_height[0] = frame->height;
+               src_pitch[0]  = frame->pitch[0];
+               n_src = 1;
+       }
+
+       gen5_get_batch(sna);
+       binding_table = gen5_composite_get_binding_table(sna, &offset);
+
+       binding_table[0] =
+               gen5_bind_bo(sna,
+                            op->dst.bo, op->dst.width, op->dst.height,
+                            gen5_get_dest_format(op->dst.format),
+                            true);
+       for (n = 0; n < n_src; n++) {
+               binding_table[1+n] =
+                       gen5_bind_video_source(sna,
+                                              frame->bo,
+                                              src_surf_base[n],
+                                              src_width[n],
+                                              src_height[n],
+                                              src_pitch[n],
+                                              src_surf_format);
+       }
+
+       gen5_emit_state(sna, op, offset);
+}
+
+static bool
+gen5_render_video(struct sna *sna,
+                 struct sna_video *video,
+                 struct sna_video_frame *frame,
+                 RegionPtr dstRegion,
+                 short src_w, short src_h,
+                 short drw_w, short drw_h,
+                 PixmapPtr pixmap)
+{
+       struct sna_composite_op tmp;
+       int nbox, dxo, dyo, pix_xoff, pix_yoff;
+       float src_scale_x, src_scale_y;
+       struct sna_pixmap *priv;
+       BoxPtr box;
+
+       DBG(("%s: %dx%d -> %dx%d\n", __FUNCTION__, src_w, src_h, drw_w, drw_h));
+
+       priv = sna_pixmap_force_to_gpu(pixmap, MOVE_READ | MOVE_WRITE);
+       if (priv == NULL)
+               return false;
+
+       memset(&tmp, 0, sizeof(tmp));
+
+       tmp.op = PictOpSrc;
+       tmp.dst.pixmap = pixmap;
+       tmp.dst.width  = pixmap->drawable.width;
+       tmp.dst.height = pixmap->drawable.height;
+       tmp.dst.format = sna_format_for_depth(pixmap->drawable.depth);
+       tmp.dst.bo = priv->gpu_bo;
+
+       tmp.src.filter = SAMPLER_FILTER_BILINEAR;
+       tmp.src.repeat = SAMPLER_EXTEND_PAD;
+       tmp.src.bo = frame->bo;
+       tmp.mask.bo = NULL;
+       tmp.u.gen5.wm_kernel =
+               is_planar_fourcc(frame->id) ? WM_KERNEL_VIDEO_PLANAR : WM_KERNEL_VIDEO_PACKED;
+       tmp.u.gen5.ve_id = 1;
+       tmp.is_affine = true;
+       tmp.floats_per_vertex = 3;
+       tmp.floats_per_rect = 9;
+       tmp.priv = frame;
+
+       if (!kgem_check_bo(&sna->kgem, tmp.dst.bo, frame->bo, NULL)) {
+               kgem_submit(&sna->kgem);
+               assert(kgem_check_bo(&sna->kgem, tmp.dst.bo, frame->bo, NULL));
+       }
+
+       gen5_video_bind_surfaces(sna, &tmp);
+       gen5_align_vertex(sna, &tmp);
+
+       /* Set up the offset for translating from the given region (in screen
+        * coordinates) to the backing pixmap.
+        */
+#ifdef COMPOSITE
+       pix_xoff = -pixmap->screen_x + pixmap->drawable.x;
+       pix_yoff = -pixmap->screen_y + pixmap->drawable.y;
+#else
+       pix_xoff = 0;
+       pix_yoff = 0;
+#endif
+
+       dxo = dstRegion->extents.x1;
+       dyo = dstRegion->extents.y1;
+
+       /* Use normalized texture coordinates */
+       src_scale_x = ((float)src_w / frame->width) / (float)drw_w;
+       src_scale_y = ((float)src_h / frame->height) / (float)drw_h;
+
+       box = REGION_RECTS(dstRegion);
+       nbox = REGION_NUM_RECTS(dstRegion);
+       while (nbox--) {
+               BoxRec r;
+
+               r.x1 = box->x1 + pix_xoff;
+               r.x2 = box->x2 + pix_xoff;
+               r.y1 = box->y1 + pix_yoff;
+               r.y2 = box->y2 + pix_yoff;
+
+               gen5_get_rectangles(sna, &tmp, 1, gen5_video_bind_surfaces);
+
+               OUT_VERTEX(r.x2, r.y2);
+               OUT_VERTEX_F((box->x2 - dxo) * src_scale_x);
+               OUT_VERTEX_F((box->y2 - dyo) * src_scale_y);
+
+               OUT_VERTEX(r.x1, r.y2);
+               OUT_VERTEX_F((box->x1 - dxo) * src_scale_x);
+               OUT_VERTEX_F((box->y2 - dyo) * src_scale_y);
+
+               OUT_VERTEX(r.x1, r.y1);
+               OUT_VERTEX_F((box->x1 - dxo) * src_scale_x);
+               OUT_VERTEX_F((box->y1 - dyo) * src_scale_y);
+
+               if (!DAMAGE_IS_ALL(priv->gpu_damage)) {
+                       sna_damage_add_box(&priv->gpu_damage, &r);
+                       sna_damage_subtract_box(&priv->cpu_damage, &r);
+               }
+               box++;
+       }
+       priv->clear = false;
+
+       gen5_vertex_flush(sna);
+       return true;
+}
+
+static int
+gen5_composite_solid_init(struct sna *sna,
+                         struct sna_composite_channel *channel,
+                         uint32_t color)
+{
+       channel->filter = PictFilterNearest;
+       channel->repeat = RepeatNormal;
+       channel->is_affine = true;
+       channel->is_solid  = true;
+       channel->transform = NULL;
+       channel->width  = 1;
+       channel->height = 1;
+       channel->card_format = GEN5_SURFACEFORMAT_B8G8R8A8_UNORM;
+
+       channel->bo = sna_render_get_solid(sna, color);
+
+       channel->scale[0]  = channel->scale[1]  = 1;
+       channel->offset[0] = channel->offset[1] = 0;
+       return channel->bo != NULL;
+}
+
+static bool
+gen5_composite_linear_init(struct sna *sna,
+                          PicturePtr picture,
+                          struct sna_composite_channel *channel,
+                          int x, int y,
+                          int w, int h,
+                          int dst_x, int dst_y)
+{
+       PictLinearGradient *linear =
+               (PictLinearGradient *)picture->pSourcePict;
+       pixman_fixed_t tx, ty;
+       float x0, y0, sf;
+       float dx, dy;
+
+       DBG(("%s: p1=(%f, %f), p2=(%f, %f), src=(%d, %d), dst=(%d, %d), size=(%d, %d)\n",
+            __FUNCTION__,
+            pixman_fixed_to_double(linear->p1.x), pixman_fixed_to_double(linear->p1.y),
+            pixman_fixed_to_double(linear->p2.x), pixman_fixed_to_double(linear->p2.y),
+            x, y, dst_x, dst_y, w, h));
+
+       if (linear->p2.x == linear->p1.x && linear->p2.y == linear->p1.y)
+               return 0;
+
+       if (!sna_transform_is_affine(picture->transform)) {
+               DBG(("%s: fallback due to projective transform\n",
+                    __FUNCTION__));
+               return sna_render_picture_fixup(sna, picture, channel,
+                                               x, y, w, h, dst_x, dst_y);
+       }
+
+       channel->bo = sna_render_get_gradient(sna, (PictGradient *)linear);
+       if (!channel->bo)
+               return 0;
+
+       channel->filter = PictFilterNearest;
+       channel->repeat = picture->repeat ? picture->repeatType : RepeatNone;
+       channel->width  = channel->bo->pitch / 4;
+       channel->height = 1;
+       channel->pict_format = PICT_a8r8g8b8;
+
+       channel->scale[0]  = channel->scale[1]  = 1;
+       channel->offset[0] = channel->offset[1] = 0;
+
+       if (sna_transform_is_translation(picture->transform, &tx, &ty)) {
+               dx = pixman_fixed_to_double(linear->p2.x - linear->p1.x);
+               dy = pixman_fixed_to_double(linear->p2.y - linear->p1.y);
+
+               x0 = pixman_fixed_to_double(linear->p1.x);
+               y0 = pixman_fixed_to_double(linear->p1.y);
+
+               if (tx | ty) {
+                       x0 -= pixman_fixed_to_double(tx);
+                       y0 -= pixman_fixed_to_double(ty);
+               }
+       } else {
+               struct pixman_f_vector p1, p2;
+               struct pixman_f_transform m, inv;
+
+               pixman_f_transform_from_pixman_transform(&m, picture->transform);
+               DBG(("%s: transform = [%f %f %f, %f %f %f, %f %f %f]\n",
+                    __FUNCTION__,
+                    m.m[0][0], m.m[0][1], m.m[0][2],
+                    m.m[1][0], m.m[1][1], m.m[1][2],
+                    m.m[2][0], m.m[2][1], m.m[2][2]));
+               if (!pixman_f_transform_invert(&inv, &m))
+                       return 0;
+
+               p1.v[0] = pixman_fixed_to_double(linear->p1.x);
+               p1.v[1] = pixman_fixed_to_double(linear->p1.y);
+               p1.v[2] = 1.;
+               pixman_f_transform_point(&inv, &p1);
+
+               p2.v[0] = pixman_fixed_to_double(linear->p2.x);
+               p2.v[1] = pixman_fixed_to_double(linear->p2.y);
+               p2.v[2] = 1.;
+               pixman_f_transform_point(&inv, &p2);
+
+               DBG(("%s: untransformed: p1=(%f, %f, %f), p2=(%f, %f, %f)\n",
+                    __FUNCTION__,
+                    p1.v[0], p1.v[1], p1.v[2],
+                    p2.v[0], p2.v[1], p2.v[2]));
+
+               dx = p2.v[0] - p1.v[0];
+               dy = p2.v[1] - p1.v[1];
+
+               x0 = p1.v[0];
+               y0 = p1.v[1];
+       }
+
+       sf = dx*dx + dy*dy;
+       dx /= sf;
+       dy /= sf;
+
+       channel->embedded_transform.matrix[0][0] = pixman_double_to_fixed(dx);
+       channel->embedded_transform.matrix[0][1] = pixman_double_to_fixed(dy);
+       channel->embedded_transform.matrix[0][2] = -pixman_double_to_fixed(dx*(x0+dst_x-x) + dy*(y0+dst_y-y));
+
+       channel->embedded_transform.matrix[1][0] = 0;
+       channel->embedded_transform.matrix[1][1] = 0;
+       channel->embedded_transform.matrix[1][2] = pixman_double_to_fixed(.5);
+
+       channel->embedded_transform.matrix[2][0] = 0;
+       channel->embedded_transform.matrix[2][1] = 0;
+       channel->embedded_transform.matrix[2][2] = pixman_fixed_1;
+
+       channel->transform = &channel->embedded_transform;
+       channel->is_affine = 1;
+
+       DBG(("%s: dx=%f, dy=%f, offset=%f\n",
+            __FUNCTION__, dx, dy, -dx*(x0-x+dst_x) + -dy*(y0-y+dst_y)));
+
+       return channel->bo != NULL;
+}
+
+static int
+gen5_composite_picture(struct sna *sna,
+                      PicturePtr picture,
+                      struct sna_composite_channel *channel,
+                      int x, int y,
+                      int w, int h,
+                      int dst_x, int dst_y,
+                      bool precise)
+{
+       PixmapPtr pixmap;
+       uint32_t color;
+       int16_t dx, dy;
+
+       DBG(("%s: (%d, %d)x(%d, %d), dst=(%d, %d)\n",
+            __FUNCTION__, x, y, w, h, dst_x, dst_y));
+
+       channel->is_solid = false;
+       channel->card_format = -1;
+
+       if (sna_picture_is_solid(picture, &color))
+               return gen5_composite_solid_init(sna, channel, color);
+
+       if (picture->pDrawable == NULL) {
+               int ret;
+
+               if (picture->pSourcePict->type == SourcePictTypeLinear)
+                       return gen5_composite_linear_init(sna, picture, channel,
+                                                         x, y,
+                                                         w, h,
+                                                         dst_x, dst_y);
+
+               DBG(("%s -- fixup, gradient\n", __FUNCTION__));
+               ret = -1;
+               if (!precise)
+                       ret = sna_render_picture_approximate_gradient(sna, picture, channel,
+                                                                     x, y, w, h, dst_x, dst_y);
+               if (ret == -1)
+                       ret = sna_render_picture_fixup(sna, picture, channel,
+                                                      x, y, w, h, dst_x, dst_y);
+               return ret;
+       }
+
+       if (picture->alphaMap) {
+               DBG(("%s -- fallback, alphamap\n", __FUNCTION__));
+               return sna_render_picture_fixup(sna, picture, channel,
+                                               x, y, w, h, dst_x, dst_y);
+       }
+
+       if (!gen5_check_repeat(picture))
+               return sna_render_picture_fixup(sna, picture, channel,
+                                               x, y, w, h, dst_x, dst_y);
+
+       if (!gen5_check_filter(picture))
+               return sna_render_picture_fixup(sna, picture, channel,
+                                               x, y, w, h, dst_x, dst_y);
+
+       channel->repeat = picture->repeat ? picture->repeatType : RepeatNone;
+       channel->filter = picture->filter;
+
+       pixmap = get_drawable_pixmap(picture->pDrawable);
+       get_drawable_deltas(picture->pDrawable, pixmap, &dx, &dy);
+
+       x += dx + picture->pDrawable->x;
+       y += dy + picture->pDrawable->y;
+
+       channel->is_affine = sna_transform_is_affine(picture->transform);
+       if (sna_transform_is_integer_translation(picture->transform, &dx, &dy)) {
+               DBG(("%s: integer translation (%d, %d), removing\n",
+                    __FUNCTION__, dx, dy));
+               x += dx;
+               y += dy;
+               channel->transform = NULL;
+               channel->filter = PictFilterNearest;
+       } else
+               channel->transform = picture->transform;
+
+       channel->pict_format = picture->format;
+       channel->card_format = gen5_get_card_format(picture->format);
+       if (channel->card_format == -1)
+               return sna_render_picture_convert(sna, picture, channel, pixmap,
+                                                 x, y, w, h, dst_x, dst_y);
+
+       if (too_large(pixmap->drawable.width, pixmap->drawable.height))
+               return sna_render_picture_extract(sna, picture, channel,
+                                                 x, y, w, h, dst_x, dst_y);
+
+       return sna_render_pixmap_bo(sna, channel, pixmap,
+                                   x, y, w, h, dst_x, dst_y);
+}
+
+static void gen5_composite_channel_convert(struct sna_composite_channel *channel)
+{
+       channel->repeat = gen5_repeat(channel->repeat);
+       channel->filter = gen5_filter(channel->filter);
+       if (channel->card_format == (unsigned)-1)
+               channel->card_format = gen5_get_card_format(channel->pict_format);
+}
+
+static void
+gen5_render_composite_done(struct sna *sna,
+                          const struct sna_composite_op *op)
+{
+       if (sna->render_state.gen5.vertex_offset) {
+               gen5_vertex_flush(sna);
+               gen5_magic_ca_pass(sna,op);
+       }
+
+       DBG(("%s()\n", __FUNCTION__));
+
+       if (op->mask.bo)
+               kgem_bo_destroy(&sna->kgem, op->mask.bo);
+       if (op->src.bo)
+               kgem_bo_destroy(&sna->kgem, op->src.bo);
+
+       sna_render_composite_redirect_done(sna, op);
+}
+
+static bool
+gen5_composite_set_target(struct sna *sna,
+                         struct sna_composite_op *op,
+                         PicturePtr dst,
+                         int x, int y, int w, int h)
+{
+       BoxRec box;
+
+       op->dst.pixmap = get_drawable_pixmap(dst->pDrawable);
+       op->dst.format = dst->format;
+       op->dst.width = op->dst.pixmap->drawable.width;
+       op->dst.height = op->dst.pixmap->drawable.height;
+
+       if (w && h) {
+               box.x1 = x;
+               box.y1 = y;
+               box.x2 = x + w;
+               box.y2 = y + h;
+       } else
+               sna_render_picture_extents(dst, &box);
+
+       op->dst.bo = sna_drawable_use_bo (dst->pDrawable,
+                                         PREFER_GPU | FORCE_GPU | RENDER_GPU,
+                                         &box, &op->damage);
+       if (op->dst.bo == NULL)
+               return false;
+
+       get_drawable_deltas(dst->pDrawable, op->dst.pixmap,
+                           &op->dst.x, &op->dst.y);
+
+       DBG(("%s: pixmap=%p, format=%08x, size=%dx%d, pitch=%d, delta=(%d,%d),damage=%p\n",
+            __FUNCTION__,
+            op->dst.pixmap, (int)op->dst.format,
+            op->dst.width, op->dst.height,
+            op->dst.bo->pitch,
+            op->dst.x, op->dst.y,
+            op->damage ? *op->damage : (void *)-1));
+
+       assert(op->dst.bo->proxy == NULL);
+
+       if (too_large(op->dst.width, op->dst.height) &&
+           !sna_render_composite_redirect(sna, op, x, y, w, h))
+               return false;
+
+       return true;
+}
+
+static inline bool
+picture_is_cpu(PicturePtr picture)
+{
+       if (!picture->pDrawable)
+               return false;
+
+       return !is_gpu(picture->pDrawable);
+}
+
+static bool
+try_blt(struct sna *sna,
+       PicturePtr dst, PicturePtr src,
+       int width, int height)
+{
+       if (sna->kgem.mode != KGEM_RENDER) {
+               DBG(("%s: already performing BLT\n", __FUNCTION__));
+               return true;
+       }
+
+       if (too_large(width, height)) {
+               DBG(("%s: operation too large for 3D pipe (%d, %d)\n",
+                    __FUNCTION__, width, height));
+               return true;
+       }
+
+       if (too_large(dst->pDrawable->width, dst->pDrawable->height))
+               return true;
+
+       /* The blitter is much faster for solids */
+       if (sna_picture_is_solid(src, NULL))
+               return true;
+
+       /* is the source picture only in cpu memory e.g. a shm pixmap? */
+       return picture_is_cpu(src);
+}
+
+static bool
+is_gradient(PicturePtr picture)
+{
+       if (picture->pDrawable)
+               return false;
+
+       switch (picture->pSourcePict->type) {
+       case SourcePictTypeSolidFill:
+       case SourcePictTypeLinear:
+               return false;
+       default:
+               return true;
+       }
+}
+
+static bool
+has_alphamap(PicturePtr p)
+{
+       return p->alphaMap != NULL;
+}
+
+static bool
+untransformed(PicturePtr p)
+{
+       return !p->transform || pixman_transform_is_int_translate(p->transform);
+}
+
+static bool
+need_upload(PicturePtr p)
+{
+       return p->pDrawable && untransformed(p) && !is_gpu(p->pDrawable);
+}
+
+static bool
+source_is_busy(PixmapPtr pixmap)
+{
+       struct sna_pixmap *priv = sna_pixmap(pixmap);
+       if (priv == NULL)
+               return false;
+
+       if (priv->clear)
+               return false;
+
+       if (priv->gpu_bo && kgem_bo_is_busy(priv->gpu_bo))
+               return true;
+
+       if (priv->cpu_bo && kgem_bo_is_busy(priv->cpu_bo))
+               return true;
+
+       return priv->gpu_damage && !priv->cpu_damage;
+}
+
+static bool
+source_fallback(PicturePtr p, PixmapPtr pixmap)
+{
+       if (sna_picture_is_solid(p, NULL))
+               return false;
+
+       if (is_gradient(p) ||
+           !gen5_check_repeat(p) ||
+           !gen5_check_format(p->format))
+               return true;
+
+       if (pixmap && source_is_busy(pixmap))
+               return false;
+
+       return has_alphamap(p) || !gen5_check_filter(p) || need_upload(p);
+}
+
+static bool
+gen5_composite_fallback(struct sna *sna,
+                       PicturePtr src,
+                       PicturePtr mask,
+                       PicturePtr dst)
+{
+       struct sna_pixmap *priv;
+       PixmapPtr src_pixmap;
+       PixmapPtr mask_pixmap;
+       PixmapPtr dst_pixmap;
+       bool src_fallback, mask_fallback;
+
+       if (!gen5_check_dst_format(dst->format)) {
+               DBG(("%s: unknown destination format: %d\n",
+                    __FUNCTION__, dst->format));
+               return true;
+       }
+
+       dst_pixmap = get_drawable_pixmap(dst->pDrawable);
+
+       src_pixmap = src->pDrawable ? get_drawable_pixmap(src->pDrawable) : NULL;
+       src_fallback = source_fallback(src, src_pixmap);
+
+       if (mask) {
+               mask_pixmap = mask->pDrawable ? get_drawable_pixmap(mask->pDrawable) : NULL;
+               mask_fallback = source_fallback(mask, mask_pixmap);
+       } else {
+               mask_pixmap = NULL;
+               mask_fallback = false;
+       }
+
+       /* If we are using the destination as a source and need to
+        * readback in order to upload the source, do it all
+        * on the cpu.
+        */
+       if (src_pixmap == dst_pixmap && src_fallback) {
+               DBG(("%s: src is dst and will fallback\n",__FUNCTION__));
+               return true;
+       }
+       if (mask_pixmap == dst_pixmap && mask_fallback) {
+               DBG(("%s: mask is dst and will fallback\n",__FUNCTION__));
+               return true;
+       }
+
+       /* If anything is on the GPU, push everything out to the GPU */
+       priv = sna_pixmap(dst_pixmap);
+       if (priv && priv->gpu_damage && !priv->clear) {
+               DBG(("%s: dst is already on the GPU, try to use GPU\n",
+                    __FUNCTION__));
+               return false;
+       }
+
+       if (src_pixmap && !src_fallback) {
+               DBG(("%s: src is already on the GPU, try to use GPU\n",
+                    __FUNCTION__));
+               return false;
+       }
+       if (mask_pixmap && !mask_fallback) {
+               DBG(("%s: mask is already on the GPU, try to use GPU\n",
+                    __FUNCTION__));
+               return false;
+       }
+
+       /* However if the dst is not on the GPU and we need to
+        * render one of the sources using the CPU, we may
+        * as well do the entire operation in place onthe CPU.
+        */
+       if (src_fallback) {
+               DBG(("%s: dst is on the CPU and src will fallback\n",
+                    __FUNCTION__));
+               return true;
+       }
+
+       if (mask_fallback) {
+               DBG(("%s: dst is on the CPU and mask will fallback\n",
+                    __FUNCTION__));
+               return true;
+       }
+
+       if (too_large(dst_pixmap->drawable.width,
+                     dst_pixmap->drawable.height) &&
+           (priv == NULL || DAMAGE_IS_ALL(priv->cpu_damage))) {
+               DBG(("%s: dst is on the CPU and too large\n", __FUNCTION__));
+               return true;
+       }
+
+       DBG(("%s: dst is not on the GPU and the operation should not fallback\n",
+            __FUNCTION__));
+       return false;
+}
+
+static int
+reuse_source(struct sna *sna,
+            PicturePtr src, struct sna_composite_channel *sc, int src_x, int src_y,
+            PicturePtr mask, struct sna_composite_channel *mc, int msk_x, int msk_y)
+{
+       uint32_t color;
+
+       if (src_x != msk_x || src_y != msk_y)
+               return false;
+
+       if (src == mask) {
+               DBG(("%s: mask is source\n", __FUNCTION__));
+               *mc = *sc;
+               mc->bo = kgem_bo_reference(mc->bo);
+               return true;
+       }
+
+       if (sna_picture_is_solid(mask, &color))
+               return gen5_composite_solid_init(sna, mc, color);
+
+       if (sc->is_solid)
+               return false;
+
+       if (src->pDrawable == NULL || mask->pDrawable != src->pDrawable)
+               return false;
+
+       DBG(("%s: mask reuses source drawable\n", __FUNCTION__));
+
+       if (!sna_transform_equal(src->transform, mask->transform))
+               return false;
+
+       if (!sna_picture_alphamap_equal(src, mask))
+               return false;
+
+       if (!gen5_check_repeat(mask))
+               return false;
+
+       if (!gen5_check_filter(mask))
+               return false;
+
+       if (!gen5_check_format(mask->format))
+               return false;
+
+       DBG(("%s: reusing source channel for mask with a twist\n",
+            __FUNCTION__));
+
+       *mc = *sc;
+       mc->repeat = gen5_repeat(mask->repeat ? mask->repeatType : RepeatNone);
+       mc->filter = gen5_filter(mask->filter);
+       mc->pict_format = mask->format;
+       mc->card_format = gen5_get_card_format(mask->format);
+       mc->bo = kgem_bo_reference(mc->bo);
+       return true;
+}
+
+static bool
+gen5_render_composite(struct sna *sna,
+                     uint8_t op,
+                     PicturePtr src,
+                     PicturePtr mask,
+                     PicturePtr dst,
+                     int16_t src_x, int16_t src_y,
+                     int16_t msk_x, int16_t msk_y,
+                     int16_t dst_x, int16_t dst_y,
+                     int16_t width, int16_t height,
+                     struct sna_composite_op *tmp)
+{
+       DBG(("%s: %dx%d, current mode=%d\n", __FUNCTION__,
+            width, height, sna->kgem.mode));
+
+       if (op >= ARRAY_SIZE(gen5_blend_op)) {
+               DBG(("%s: unhandled blend op %d\n", __FUNCTION__, op));
+               return false;
+       }
+
+       if (mask == NULL &&
+           try_blt(sna, dst, src, width, height) &&
+           sna_blt_composite(sna, op,
+                             src, dst,
+                             src_x, src_y,
+                             dst_x, dst_y,
+                             width, height,
+                             tmp, false))
+               return true;
+
+       if (gen5_composite_fallback(sna, src, mask, dst))
+               return false;
+
+       if (need_tiling(sna, width, height))
+               return sna_tiling_composite(op, src, mask, dst,
+                                           src_x, src_y,
+                                           msk_x, msk_y,
+                                           dst_x, dst_y,
+                                           width, height,
+                                           tmp);
+
+       if (!gen5_composite_set_target(sna, tmp, dst,
+                                      dst_x, dst_y, width, height)) {
+               DBG(("%s: failed to set composite target\n", __FUNCTION__));
+               return false;
+       }
+
+       DBG(("%s: preparing source\n", __FUNCTION__));
+       switch (gen5_composite_picture(sna, src, &tmp->src,
+                                      src_x, src_y,
+                                      width, height,
+                                      dst_x, dst_y,
+                                      dst->polyMode == PolyModePrecise)) {
+       case -1:
+               DBG(("%s: failed to prepare source picture\n", __FUNCTION__));
+               goto cleanup_dst;
+       case 0:
+               if (!gen5_composite_solid_init(sna, &tmp->src, 0))
+                       goto cleanup_dst;
+               /* fall through to fixup */
+       case 1:
+               if (mask == NULL &&
+                   sna_blt_composite__convert(sna,
+                                              dst_x, dst_y, width, height,
+                                              tmp))
+                       return true;
+
+               gen5_composite_channel_convert(&tmp->src);
+               break;
+       }
+
+       tmp->op = op;
+       tmp->is_affine = tmp->src.is_affine;
+       tmp->has_component_alpha = false;
+       tmp->need_magic_ca_pass = false;
+
+       tmp->prim_emit = gen5_emit_composite_primitive;
+       if (mask) {
+               if (mask->componentAlpha && PICT_FORMAT_RGB(mask->format)) {
+                       tmp->has_component_alpha = true;
+
+                       /* Check if it's component alpha that relies on a source alpha and on
+                        * the source value.  We can only get one of those into the single
+                        * source value that we get to blend with.
+                        */
+                       if (gen5_blend_op[op].src_alpha &&
+                           (gen5_blend_op[op].src_blend != GEN5_BLENDFACTOR_ZERO)) {
+                               if (op != PictOpOver) {
+                                       DBG(("%s: unhandled CA blend op %d\n", __FUNCTION__, op));
+                                       goto cleanup_src;
+                               }
+
+                               tmp->need_magic_ca_pass = true;
+                               tmp->op = PictOpOutReverse;
+                       }
+               }
+
+               if (!reuse_source(sna,
+                                 src, &tmp->src, src_x, src_y,
+                                 mask, &tmp->mask, msk_x, msk_y)) {
+                       DBG(("%s: preparing mask\n", __FUNCTION__));
+                       switch (gen5_composite_picture(sna, mask, &tmp->mask,
+                                                      msk_x, msk_y,
+                                                      width, height,
+                                                      dst_x, dst_y,
+                                                      dst->polyMode == PolyModePrecise)) {
+                       case -1:
+                               DBG(("%s: failed to prepare mask picture\n", __FUNCTION__));
+                               goto cleanup_src;
+                       case 0:
+                               if (!gen5_composite_solid_init(sna, &tmp->mask, 0))
+                                       goto cleanup_src;
+                               /* fall through to fixup */
+                       case 1:
+                               gen5_composite_channel_convert(&tmp->mask);
+                               break;
+                       }
+               }
+
+               tmp->is_affine &= tmp->mask.is_affine;
+
+               if (tmp->src.transform == NULL && tmp->mask.transform == NULL)
+                       tmp->prim_emit = gen5_emit_composite_primitive_identity_source_mask;
+
+               tmp->floats_per_vertex = 5 + 2 * !tmp->is_affine;
+       } else {
+               if (tmp->src.is_solid)
+                       tmp->prim_emit = gen5_emit_composite_primitive_solid;
+               else if (tmp->src.transform == NULL)
+                       tmp->prim_emit = gen5_emit_composite_primitive_identity_source;
+               else if (tmp->src.is_affine)
+                       tmp->prim_emit = gen5_emit_composite_primitive_affine_source;
+
+               tmp->floats_per_vertex = 3 + !tmp->is_affine;
+       }
+       tmp->floats_per_rect = 3*tmp->floats_per_vertex;
+
+       tmp->u.gen5.wm_kernel =
+               gen5_choose_composite_kernel(tmp->op,
+                                            tmp->mask.bo != NULL,
+                                            tmp->has_component_alpha,
+                                            tmp->is_affine);
+       tmp->u.gen5.ve_id = (tmp->mask.bo != NULL) << 1 | tmp->is_affine;
+
+       tmp->blt   = gen5_render_composite_blt;
+       tmp->box   = gen5_render_composite_box;
+       tmp->boxes = gen5_render_composite_boxes;
+       tmp->done  = gen5_render_composite_done;
+
+       if (!kgem_check_bo(&sna->kgem,
+                          tmp->dst.bo, tmp->src.bo, tmp->mask.bo, NULL)) {
+               kgem_submit(&sna->kgem);
+               if (!kgem_check_bo(&sna->kgem,
+                                  tmp->dst.bo, tmp->src.bo, tmp->mask.bo, NULL))
+                       goto cleanup_mask;
+       }
+
+       gen5_bind_surfaces(sna, tmp);
+       gen5_align_vertex(sna, tmp);
+       return true;
+
+cleanup_mask:
+       if (tmp->mask.bo)
+               kgem_bo_destroy(&sna->kgem, tmp->mask.bo);
+cleanup_src:
+       if (tmp->src.bo)
+               kgem_bo_destroy(&sna->kgem, tmp->src.bo);
+cleanup_dst:
+       if (tmp->redirect.real_bo)
+               kgem_bo_destroy(&sna->kgem, tmp->dst.bo);
+       return false;
+}
+
+#if !NO_COMPOSITE_SPANS
+inline static void
+gen5_emit_composite_texcoord(struct sna *sna,
+                            const struct sna_composite_channel *channel,
+                            int16_t x, int16_t y)
+{
+       float t[3];
+
+       if (channel->is_affine) {
+               sna_get_transformed_coordinates(x + channel->offset[0],
+                                               y + channel->offset[1],
+                                               channel->transform,
+                                               &t[0], &t[1]);
+               OUT_VERTEX_F(t[0] * channel->scale[0]);
+               OUT_VERTEX_F(t[1] * channel->scale[1]);
+       } else {
+               t[0] = t[1] = 0; t[2] = 1;
+               sna_get_transformed_coordinates_3d(x + channel->offset[0],
+                                                  y + channel->offset[1],
+                                                  channel->transform,
+                                                  &t[0], &t[1], &t[2]);
+               OUT_VERTEX_F(t[0] * channel->scale[0]);
+               OUT_VERTEX_F(t[1] * channel->scale[1]);
+               OUT_VERTEX_F(t[2]);
+       }
+}
+
+inline static void
+gen5_emit_composite_texcoord_affine(struct sna *sna,
+                                   const struct sna_composite_channel *channel,
+                                   int16_t x, int16_t y)
+{
+       float t[2];
+
+       sna_get_transformed_coordinates(x + channel->offset[0],
+                                       y + channel->offset[1],
+                                       channel->transform,
+                                       &t[0], &t[1]);
+       OUT_VERTEX_F(t[0] * channel->scale[0]);
+       OUT_VERTEX_F(t[1] * channel->scale[1]);
+}
+
+inline static void
+gen5_emit_composite_spans_vertex(struct sna *sna,
+                                const struct sna_composite_spans_op *op,
+                                int16_t x, int16_t y)
+{
+       OUT_VERTEX(x, y);
+       gen5_emit_composite_texcoord(sna, &op->base.src, x, y);
+}
+
+fastcall static void
+gen5_emit_composite_spans_primitive(struct sna *sna,
+                                   const struct sna_composite_spans_op *op,
+                                   const BoxRec *box,
+                                   float opacity)
+{
+       gen5_emit_composite_spans_vertex(sna, op, box->x2, box->y2);
+       OUT_VERTEX_F(opacity);
+       OUT_VERTEX_F(1);
+       if (!op->base.is_affine)
+               OUT_VERTEX_F(1);
+
+       gen5_emit_composite_spans_vertex(sna, op, box->x1, box->y2);
+       OUT_VERTEX_F(opacity);
+       OUT_VERTEX_F(1);
+       if (!op->base.is_affine)
+               OUT_VERTEX_F(1);
+
+       gen5_emit_composite_spans_vertex(sna, op, box->x1, box->y1);
+       OUT_VERTEX_F(opacity);
+       OUT_VERTEX_F(0);
+       if (!op->base.is_affine)
+               OUT_VERTEX_F(1);
+}
+
+fastcall static void
+gen5_emit_composite_spans_solid(struct sna *sna,
+                               const struct sna_composite_spans_op *op,
+                               const BoxRec *box,
+                               float opacity)
+{
+       OUT_VERTEX(box->x2, box->y2);
+       OUT_VERTEX_F(1); OUT_VERTEX_F(1);
+       OUT_VERTEX_F(opacity); OUT_VERTEX_F(1);
+
+       OUT_VERTEX(box->x1, box->y2);
+       OUT_VERTEX_F(0); OUT_VERTEX_F(1);
+       OUT_VERTEX_F(opacity); OUT_VERTEX_F(1);
+
+       OUT_VERTEX(box->x1, box->y1);
+       OUT_VERTEX_F(0); OUT_VERTEX_F(0);
+       OUT_VERTEX_F(opacity); OUT_VERTEX_F(0);
+}
+
+fastcall static void
+gen5_emit_composite_spans_affine(struct sna *sna,
+                                const struct sna_composite_spans_op *op,
+                                const BoxRec *box,
+                                float opacity)
+{
+       OUT_VERTEX(box->x2, box->y2);
+       gen5_emit_composite_texcoord_affine(sna, &op->base.src,
+                                           box->x2, box->y2);
+       OUT_VERTEX_F(opacity);
+       OUT_VERTEX_F(1);
+
+       OUT_VERTEX(box->x1, box->y2);
+       gen5_emit_composite_texcoord_affine(sna, &op->base.src,
+                                           box->x1, box->y2);
+       OUT_VERTEX_F(opacity);
+       OUT_VERTEX_F(1);
+
+       OUT_VERTEX(box->x1, box->y1);
+       gen5_emit_composite_texcoord_affine(sna, &op->base.src,
+                                           box->x1, box->y1);
+       OUT_VERTEX_F(opacity);
+       OUT_VERTEX_F(0);
+}
+
+fastcall static void
+gen5_render_composite_spans_box(struct sna *sna,
+                               const struct sna_composite_spans_op *op,
+                               const BoxRec *box, float opacity)
+{
+       DBG(("%s: src=+(%d, %d), opacity=%f, dst=+(%d, %d), box=(%d, %d) x (%d, %d)\n",
+            __FUNCTION__,
+            op->base.src.offset[0], op->base.src.offset[1],
+            opacity,
+            op->base.dst.x, op->base.dst.y,
+            box->x1, box->y1,
+            box->x2 - box->x1,
+            box->y2 - box->y1));
+
+       gen5_get_rectangles(sna, &op->base, 1, gen5_bind_surfaces);
+       op->prim_emit(sna, op, box, opacity);
+}
+
+static void
+gen5_render_composite_spans_boxes(struct sna *sna,
+                                 const struct sna_composite_spans_op *op,
+                                 const BoxRec *box, int nbox,
+                                 float opacity)
+{
+       DBG(("%s: nbox=%d, src=+(%d, %d), opacity=%f, dst=+(%d, %d)\n",
+            __FUNCTION__, nbox,
+            op->base.src.offset[0], op->base.src.offset[1],
+            opacity,
+            op->base.dst.x, op->base.dst.y));
+
+       do {
+               int nbox_this_time;
+
+               nbox_this_time = gen5_get_rectangles(sna, &op->base, nbox,
+                                                    gen5_bind_surfaces);
+               nbox -= nbox_this_time;
+
+               do {
+                       DBG(("  %s: (%d, %d) x (%d, %d)\n", __FUNCTION__,
+                            box->x1, box->y1,
+                            box->x2 - box->x1,
+                            box->y2 - box->y1));
+
+                       op->prim_emit(sna, op, box++, opacity);
+               } while (--nbox_this_time);
+       } while (nbox);
+}
+
+fastcall static void
+gen5_render_composite_spans_done(struct sna *sna,
+                                const struct sna_composite_spans_op *op)
+{
+       if (sna->render_state.gen5.vertex_offset)
+               gen5_vertex_flush(sna);
+
+       DBG(("%s()\n", __FUNCTION__));
+
+       kgem_bo_destroy(&sna->kgem, op->base.mask.bo);
+       if (op->base.src.bo)
+               kgem_bo_destroy(&sna->kgem, op->base.src.bo);
+
+       sna_render_composite_redirect_done(sna, &op->base);
+}
+
+static bool
+gen5_check_composite_spans(struct sna *sna,
+                          uint8_t op, PicturePtr src, PicturePtr dst,
+                          int16_t width, int16_t height,
+                          unsigned flags)
+{
+       if ((flags & COMPOSITE_SPANS_RECTILINEAR) == 0)
+               return false;
+
+       if (op >= ARRAY_SIZE(gen5_blend_op))
+               return false;
+
+       if (gen5_composite_fallback(sna, src, NULL, dst))
+               return false;
+
+       if (need_tiling(sna, width, height)) {
+               if (!is_gpu(dst->pDrawable)) {
+                       DBG(("%s: fallback, tiled operation not on GPU\n",
+                            __FUNCTION__));
+                       return false;
+               }
+       }
+
+       return true;
+}
+
+static bool
+gen5_render_composite_spans(struct sna *sna,
+                           uint8_t op,
+                           PicturePtr src,
+                           PicturePtr dst,
+                           int16_t src_x,  int16_t src_y,
+                           int16_t dst_x,  int16_t dst_y,
+                           int16_t width,  int16_t height,
+                           unsigned flags,
+                           struct sna_composite_spans_op *tmp)
+{
+       DBG(("%s: %dx%d with flags=%x, current mode=%d\n", __FUNCTION__,
+            width, height, flags, sna->kgem.ring));
+
+       assert(gen5_check_composite_spans(sna, op, src, dst, width, height, flags));
+
+       if (need_tiling(sna, width, height)) {
+               DBG(("%s: tiling, operation (%dx%d) too wide for pipeline\n",
+                    __FUNCTION__, width, height));
+               return sna_tiling_composite_spans(op, src, dst,
+                                                 src_x, src_y, dst_x, dst_y,
+                                                 width, height, flags, tmp);
+       }
+
+       tmp->base.op = op;
+       if (!gen5_composite_set_target(sna, &tmp->base, dst,
+                                      dst_x, dst_y, width, height))
+               return false;
+
+       switch (gen5_composite_picture(sna, src, &tmp->base.src,
+                                      src_x, src_y,
+                                      width, height,
+                                      dst_x, dst_y,
+                                      dst->polyMode == PolyModePrecise)) {
+       case -1:
+               goto cleanup_dst;
+       case 0:
+               if (!gen5_composite_solid_init(sna, &tmp->base.src, 0))
+                       goto cleanup_dst;
+               /* fall through to fixup */
+       case 1:
+               gen5_composite_channel_convert(&tmp->base.src);
+               break;
+       }
+
+       tmp->base.mask.bo = sna_render_get_solid(sna, 0);
+       if (tmp->base.mask.bo == NULL)
+               goto cleanup_src;
+
+       tmp->base.is_affine = tmp->base.src.is_affine;
+       tmp->base.has_component_alpha = false;
+       tmp->base.need_magic_ca_pass = false;
+
+       tmp->prim_emit = gen5_emit_composite_spans_primitive;
+       if (tmp->base.src.is_solid)
+               tmp->prim_emit = gen5_emit_composite_spans_solid;
+       else if (tmp->base.is_affine)
+               tmp->prim_emit = gen5_emit_composite_spans_affine;
+       tmp->base.floats_per_vertex = 5 + 2*!tmp->base.is_affine;
+       tmp->base.floats_per_rect = 3 * tmp->base.floats_per_vertex;
+
+       tmp->base.u.gen5.wm_kernel = WM_KERNEL_OPACITY | !tmp->base.is_affine;
+       tmp->base.u.gen5.ve_id = 1 << 1 | tmp->base.is_affine;
+
+       tmp->box   = gen5_render_composite_spans_box;
+       tmp->boxes = gen5_render_composite_spans_boxes;
+       tmp->done  = gen5_render_composite_spans_done;
+
+       if (!kgem_check_bo(&sna->kgem,
+                          tmp->base.dst.bo, tmp->base.src.bo,
+                          NULL))  {
+               kgem_submit(&sna->kgem);
+               if (!kgem_check_bo(&sna->kgem,
+                                  tmp->base.dst.bo, tmp->base.src.bo,
+                                  NULL))
+                       goto cleanup_src;
+       }
+
+       gen5_bind_surfaces(sna, &tmp->base);
+       gen5_align_vertex(sna, &tmp->base);
+       return true;
+
+cleanup_src:
+       if (tmp->base.src.bo)
+               kgem_bo_destroy(&sna->kgem, tmp->base.src.bo);
+cleanup_dst:
+       if (tmp->base.redirect.real_bo)
+               kgem_bo_destroy(&sna->kgem, tmp->base.dst.bo);
+       return false;
+}
+#endif
+
+static void
+gen5_copy_bind_surfaces(struct sna *sna,
+                       const struct sna_composite_op *op)
+{
+       uint32_t *binding_table;
+       uint16_t offset;
+
+       gen5_get_batch(sna);
+
+       binding_table = gen5_composite_get_binding_table(sna, &offset);
+
+       binding_table[0] =
+               gen5_bind_bo(sna,
+                            op->dst.bo, op->dst.width, op->dst.height,
+                            gen5_get_dest_format(op->dst.format),
+                            true);
+       binding_table[1] =
+               gen5_bind_bo(sna,
+                            op->src.bo, op->src.width, op->src.height,
+                            op->src.card_format,
+                            false);
+
+       if (sna->kgem.surface == offset &&
+           *(uint64_t *)(sna->kgem.batch + sna->render_state.gen5.surface_table) == *(uint64_t*)binding_table) {
+               sna->kgem.surface += sizeof(struct gen5_surface_state_padded) / sizeof(uint32_t);
+               offset = sna->render_state.gen5.surface_table;
+       }
+
+       gen5_emit_state(sna, op, offset);
+}
+
+static bool
+gen5_render_copy_boxes(struct sna *sna, uint8_t alu,
+                      PixmapPtr src, struct kgem_bo *src_bo, int16_t src_dx, int16_t src_dy,
+                      PixmapPtr dst, struct kgem_bo *dst_bo, int16_t dst_dx, int16_t dst_dy,
+                      const BoxRec *box, int n, unsigned flags)
+{
+       struct sna_composite_op tmp;
+
+       if (sna_blt_compare_depth(&src->drawable, &dst->drawable) &&
+           sna_blt_copy_boxes(sna, alu,
+                              src_bo, src_dx, src_dy,
+                              dst_bo, dst_dx, dst_dy,
+                              dst->drawable.bitsPerPixel,
+                              box, n))
+               return true;
+
+       if (!(alu == GXcopy || alu == GXclear) || src_bo == dst_bo) {
+fallback_blt:
+               if (!sna_blt_compare_depth(&src->drawable, &dst->drawable))
+                       return false;
+
+               return sna_blt_copy_boxes_fallback(sna, alu,
+                                                  src, src_bo, src_dx, src_dy,
+                                                  dst, dst_bo, dst_dx, dst_dy,
+                                                  box, n);
+       }
+
+       memset(&tmp, 0, sizeof(tmp));
+
+       if (dst->drawable.depth == src->drawable.depth) {
+               tmp.dst.format = sna_render_format_for_depth(dst->drawable.depth);
+               tmp.src.pict_format = tmp.dst.format;
+       } else {
+               tmp.dst.format = sna_format_for_depth(dst->drawable.depth);
+               tmp.src.pict_format = sna_format_for_depth(src->drawable.depth);
+       }
+       if (!gen5_check_format(tmp.src.pict_format)) {
+               DBG(("%s: unsupported source format, %x, use BLT\n",
+                    __FUNCTION__, tmp.src.pict_format));
+               goto fallback_blt;
+       }
+
+       DBG(("%s (%d, %d)->(%d, %d) x %d\n",
+            __FUNCTION__, src_dx, src_dy, dst_dx, dst_dy, n));
+
+       tmp.op = alu == GXcopy ? PictOpSrc : PictOpClear;
+
+       tmp.dst.pixmap = dst;
+       tmp.dst.width  = dst->drawable.width;
+       tmp.dst.height = dst->drawable.height;
+       tmp.dst.x = tmp.dst.y = 0;
+       tmp.dst.bo = dst_bo;
+       tmp.damage = NULL;
+
+       sna_render_composite_redirect_init(&tmp);
+       if (too_large(tmp.dst.width, tmp.dst.height)) {
+               BoxRec extents = box[0];
+               int i;
+
+               for (i = 1; i < n; i++) {
+                       if (box[i].x1 < extents.x1)
+                               extents.x1 = box[i].x1;
+                       if (box[i].y1 < extents.y1)
+                               extents.y1 = box[i].y1;
+
+                       if (box[i].x2 > extents.x2)
+                               extents.x2 = box[i].x2;
+                       if (box[i].y2 > extents.y2)
+                               extents.y2 = box[i].y2;
+               }
+
+               if (!sna_render_composite_redirect(sna, &tmp,
+                                                  extents.x1 + dst_dx,
+                                                  extents.y1 + dst_dy,
+                                                  extents.x2 - extents.x1,
+                                                  extents.y2 - extents.y1))
+                       goto fallback_tiled;
+       }
+
+       tmp.src.filter = SAMPLER_FILTER_NEAREST;
+       tmp.src.repeat = SAMPLER_EXTEND_NONE;
+       tmp.src.card_format = gen5_get_card_format(tmp.src.pict_format);
+       if (too_large(src->drawable.width, src->drawable.height)) {
+               BoxRec extents = box[0];
+               int i;
+
+               for (i = 1; i < n; i++) {
+                       if (extents.x1 < box[i].x1)
+                               extents.x1 = box[i].x1;
+                       if (extents.y1 < box[i].y1)
+                               extents.y1 = box[i].y1;
+
+                       if (extents.x2 > box[i].x2)
+                               extents.x2 = box[i].x2;
+                       if (extents.y2 > box[i].y2)
+                               extents.y2 = box[i].y2;
+               }
+
+               if (!sna_render_pixmap_partial(sna, src, src_bo, &tmp.src,
+                                              extents.x1 + src_dx,
+                                              extents.y1 + src_dy,
+                                              extents.x2 - extents.x1,
+                                              extents.y2 - extents.y1))
+                       goto fallback_tiled_dst;
+       } else {
+               tmp.src.bo = kgem_bo_reference(src_bo);
+               tmp.src.width  = src->drawable.width;
+               tmp.src.height = src->drawable.height;
+               tmp.src.offset[0] = tmp.src.offset[1] = 0;
+               tmp.src.scale[0] = 1.f/src->drawable.width;
+               tmp.src.scale[1] = 1.f/src->drawable.height;
+       }
+
+       tmp.is_affine = true;
+       tmp.floats_per_vertex = 3;
+       tmp.floats_per_rect = 9;
+       tmp.u.gen5.wm_kernel = WM_KERNEL;
+       tmp.u.gen5.ve_id = 1;
+
+       if (!kgem_check_bo(&sna->kgem, dst_bo, src_bo, NULL)) {
+               kgem_submit(&sna->kgem);
+               if (!kgem_check_bo(&sna->kgem, dst_bo, src_bo, NULL))
+                       goto fallback_tiled_src;
+       }
+
+       dst_dx += tmp.dst.x;
+       dst_dy += tmp.dst.y;
+       tmp.dst.x = tmp.dst.y = 0;
+
+       src_dx += tmp.src.offset[0];
+       src_dy += tmp.src.offset[1];
+
+       gen5_copy_bind_surfaces(sna, &tmp);
+       gen5_align_vertex(sna, &tmp);
+
+       do {
+               int n_this_time;
+
+               n_this_time = gen5_get_rectangles(sna, &tmp, n,
+                                                 gen5_copy_bind_surfaces);
+               n -= n_this_time;
+
+               do {
+                       DBG(("  (%d, %d) -> (%d, %d) + (%d, %d)\n",
+                            box->x1 + src_dx, box->y1 + src_dy,
+                            box->x1 + dst_dx, box->y1 + dst_dy,
+                            box->x2 - box->x1, box->y2 - box->y1));
+                       OUT_VERTEX(box->x2 + dst_dx, box->y2 + dst_dy);
+                       OUT_VERTEX_F((box->x2 + src_dx) * tmp.src.scale[0]);
+                       OUT_VERTEX_F((box->y2 + src_dy) * tmp.src.scale[1]);
+
+                       OUT_VERTEX(box->x1 + dst_dx, box->y2 + dst_dy);
+                       OUT_VERTEX_F((box->x1 + src_dx) * tmp.src.scale[0]);
+                       OUT_VERTEX_F((box->y2 + src_dy) * tmp.src.scale[1]);
+
+                       OUT_VERTEX(box->x1 + dst_dx, box->y1 + dst_dy);
+                       OUT_VERTEX_F((box->x1 + src_dx) * tmp.src.scale[0]);
+                       OUT_VERTEX_F((box->y1 + src_dy) * tmp.src.scale[1]);
+
+                       box++;
+               } while (--n_this_time);
+       } while (n);
+
+       gen5_vertex_flush(sna);
+       sna_render_composite_redirect_done(sna, &tmp);
+       kgem_bo_destroy(&sna->kgem, tmp.src.bo);
+       return true;
+
+fallback_tiled_src:
+       kgem_bo_destroy(&sna->kgem, tmp.src.bo);
+fallback_tiled_dst:
+       if (tmp.redirect.real_bo)
+               kgem_bo_destroy(&sna->kgem, tmp.dst.bo);
+fallback_tiled:
+       return sna_tiling_copy_boxes(sna, alu,
+                                    src, src_bo, src_dx, src_dy,
+                                    dst, dst_bo, dst_dx, dst_dy,
+                                    box, n);
+}
+
+static void
+gen5_render_copy_blt(struct sna *sna,
+                    const struct sna_copy_op *op,
+                    int16_t sx, int16_t sy,
+                    int16_t w,  int16_t h,
+                    int16_t dx, int16_t dy)
+{
+       DBG(("%s: src=(%d, %d), dst=(%d, %d), size=(%d, %d)\n", __FUNCTION__,
+            sx, sy, dx, dy, w, h));
+
+       gen5_get_rectangles(sna, &op->base, 1, gen5_copy_bind_surfaces);
+
+       OUT_VERTEX(dx+w, dy+h);
+       OUT_VERTEX_F((sx+w)*op->base.src.scale[0]);
+       OUT_VERTEX_F((sy+h)*op->base.src.scale[1]);
+
+       OUT_VERTEX(dx, dy+h);
+       OUT_VERTEX_F(sx*op->base.src.scale[0]);
+       OUT_VERTEX_F((sy+h)*op->base.src.scale[1]);
+
+       OUT_VERTEX(dx, dy);
+       OUT_VERTEX_F(sx*op->base.src.scale[0]);
+       OUT_VERTEX_F(sy*op->base.src.scale[1]);
+}
+
+static void
+gen5_render_copy_done(struct sna *sna,
+                     const struct sna_copy_op *op)
+{
+       if (sna->render_state.gen5.vertex_offset)
+               gen5_vertex_flush(sna);
+
+       DBG(("%s()\n", __FUNCTION__));
+}
+
+static bool
+gen5_render_copy(struct sna *sna, uint8_t alu,
+                PixmapPtr src, struct kgem_bo *src_bo,
+                PixmapPtr dst, struct kgem_bo *dst_bo,
+                struct sna_copy_op *op)
+{
+       DBG(("%s (alu=%d)\n", __FUNCTION__, alu));
+
+       if (sna_blt_compare_depth(&src->drawable, &dst->drawable) &&
+           sna_blt_copy(sna, alu,
+                        src_bo, dst_bo,
+                        dst->drawable.bitsPerPixel,
+                        op))
+               return true;
+
+       if (!(alu == GXcopy || alu == GXclear) || src_bo == dst_bo ||
+           too_large(src->drawable.width, src->drawable.height) ||
+           too_large(dst->drawable.width, dst->drawable.height)) {
+fallback:
+               if (!sna_blt_compare_depth(&src->drawable, &dst->drawable))
+                       return false;
+
+               return sna_blt_copy(sna, alu, src_bo, dst_bo,
+                                   dst->drawable.bitsPerPixel,
+                                   op);
+       }
+
+       if (dst->drawable.depth == src->drawable.depth) {
+               op->base.dst.format = sna_render_format_for_depth(dst->drawable.depth);
+               op->base.src.pict_format = op->base.dst.format;
+       } else {
+               op->base.dst.format = sna_format_for_depth(dst->drawable.depth);
+               op->base.src.pict_format = sna_format_for_depth(src->drawable.depth);
+       }
+       if (!gen5_check_format(op->base.src.pict_format))
+               goto fallback;
+
+       op->base.op = alu == GXcopy ? PictOpSrc : PictOpClear;
+
+       op->base.dst.pixmap = dst;
+       op->base.dst.width  = dst->drawable.width;
+       op->base.dst.height = dst->drawable.height;
+       op->base.dst.bo = dst_bo;
+
+       op->base.src.bo = src_bo;
+       op->base.src.card_format =
+               gen5_get_card_format(op->base.src.pict_format);
+       op->base.src.width  = src->drawable.width;
+       op->base.src.height = src->drawable.height;
+       op->base.src.scale[0] = 1.f/src->drawable.width;
+       op->base.src.scale[1] = 1.f/src->drawable.height;
+       op->base.src.filter = SAMPLER_FILTER_NEAREST;
+       op->base.src.repeat = SAMPLER_EXTEND_NONE;
+
+       op->base.is_affine = true;
+       op->base.floats_per_vertex = 3;
+       op->base.floats_per_rect = 9;
+       op->base.u.gen5.wm_kernel = WM_KERNEL;
+       op->base.u.gen5.ve_id = 1;
+
+       if (!kgem_check_bo(&sna->kgem, dst_bo, src_bo, NULL))  {
+               kgem_submit(&sna->kgem);
+               if (!kgem_check_bo(&sna->kgem, dst_bo, src_bo, NULL))
+                       goto fallback;
+       }
+
+       if (kgem_bo_is_dirty(src_bo)) {
+               if (sna_blt_compare_depth(&src->drawable, &dst->drawable) &&
+                   sna_blt_copy(sna, alu,
+                                src_bo, dst_bo,
+                                dst->drawable.bitsPerPixel,
+                                op))
+                       return true;
+       }
+
+       gen5_copy_bind_surfaces(sna, &op->base);
+       gen5_align_vertex(sna, &op->base);
+
+       op->blt  = gen5_render_copy_blt;
+       op->done = gen5_render_copy_done;
+       return true;
+}
+
+static void
+gen5_fill_bind_surfaces(struct sna *sna,
+                       const struct sna_composite_op *op)
+{
+       uint32_t *binding_table;
+       uint16_t offset;
+
+       gen5_get_batch(sna);
+
+       binding_table = gen5_composite_get_binding_table(sna, &offset);
+
+       binding_table[0] =
+               gen5_bind_bo(sna,
+                            op->dst.bo, op->dst.width, op->dst.height,
+                            gen5_get_dest_format(op->dst.format),
+                            true);
+       binding_table[1] =
+               gen5_bind_bo(sna,
+                            op->src.bo, 1, 1,
+                            GEN5_SURFACEFORMAT_B8G8R8A8_UNORM,
+                            false);
+
+       if (sna->kgem.surface == offset &&
+           *(uint64_t *)(sna->kgem.batch + sna->render_state.gen5.surface_table) == *(uint64_t*)binding_table) {
+               sna->kgem.surface +=
+                       sizeof(struct gen5_surface_state_padded)/sizeof(uint32_t);
+               offset = sna->render_state.gen5.surface_table;
+       }
+
+       gen5_emit_state(sna, op, offset);
+}
+
+static inline bool prefer_blt_fill(struct sna *sna)
+{
+#if PREFER_BLT_FILL
+       return true;
+#else
+       return sna->kgem.mode != KGEM_RENDER;
+#endif
+}
+
+static bool
+gen5_render_fill_boxes(struct sna *sna,
+                      CARD8 op,
+                      PictFormat format,
+                      const xRenderColor *color,
+                      PixmapPtr dst, struct kgem_bo *dst_bo,
+                      const BoxRec *box, int n)
+{
+       struct sna_composite_op tmp;
+       uint32_t pixel;
+
+       DBG(("%s op=%x, color=(%04x,%04x,%04x,%04x), boxes=%d x [((%d, %d), (%d, %d))...]\n",
+            __FUNCTION__, op,
+            color->red, color->green, color->blue, color->alpha,
+            n, box->x1, box->y1, box->x2, box->y2));
+
+       if (op >= ARRAY_SIZE(gen5_blend_op)) {
+               DBG(("%s: fallback due to unhandled blend op: %d\n",
+                    __FUNCTION__, op));
+               return false;
+       }
+
+       if (op <= PictOpSrc &&
+           (prefer_blt_fill(sna) ||
+            too_large(dst->drawable.width, dst->drawable.height) ||
+            !gen5_check_dst_format(format))) {
+               uint8_t alu = GXinvalid;
+
+               pixel = 0;
+               if (op == PictOpClear)
+                       alu = GXclear;
+               else if (sna_get_pixel_from_rgba(&pixel,
+                                                color->red,
+                                                color->green,
+                                                color->blue,
+                                                color->alpha,
+                                                format))
+                       alu = GXcopy;
+
+               if (alu != GXinvalid &&
+                   sna_blt_fill_boxes(sna, alu,
+                                      dst_bo, dst->drawable.bitsPerPixel,
+                                      pixel, box, n))
+                       return true;
+
+               if (!gen5_check_dst_format(format))
+                       return false;
+
+               if (too_large(dst->drawable.width, dst->drawable.height))
+                       return sna_tiling_fill_boxes(sna, op, format, color,
+                                                    dst, dst_bo, box, n);
+       }
+
+       if (op == PictOpClear)
+               pixel = 0;
+       else if (!sna_get_pixel_from_rgba(&pixel,
+                                         color->red,
+                                         color->green,
+                                         color->blue,
+                                         color->alpha,
+                                         PICT_a8r8g8b8))
+               return false;
+
+       memset(&tmp, 0, sizeof(tmp));
+
+       tmp.op = op;
+
+       tmp.dst.pixmap = dst;
+       tmp.dst.width  = dst->drawable.width;
+       tmp.dst.height = dst->drawable.height;
+       tmp.dst.format = format;
+       tmp.dst.bo = dst_bo;
+
+       tmp.src.bo = sna_render_get_solid(sna, pixel);
+       tmp.src.filter = SAMPLER_FILTER_NEAREST;
+       tmp.src.repeat = SAMPLER_EXTEND_REPEAT;
+
+       tmp.is_affine = true;
+       tmp.floats_per_vertex = 3;
+       tmp.floats_per_rect = 9;
+       tmp.u.gen5.wm_kernel = WM_KERNEL;
+       tmp.u.gen5.ve_id = 1;
+
+       if (!kgem_check_bo(&sna->kgem, dst_bo, NULL)) {
+               kgem_submit(&sna->kgem);
+               assert(kgem_check_bo(&sna->kgem, dst_bo, NULL));
+       }
+
+       gen5_fill_bind_surfaces(sna, &tmp);
+       gen5_align_vertex(sna, &tmp);
+
+       do {
+               int n_this_time;
+
+               n_this_time = gen5_get_rectangles(sna, &tmp, n,
+                                                 gen5_fill_bind_surfaces);
+               n -= n_this_time;
+
+               do {
+                       DBG(("  (%d, %d), (%d, %d)\n",
+                            box->x1, box->y1, box->x2, box->y2));
+                       OUT_VERTEX(box->x2, box->y2);
+                       OUT_VERTEX_F(1);
+                       OUT_VERTEX_F(1);
+
+                       OUT_VERTEX(box->x1, box->y2);
+                       OUT_VERTEX_F(0);
+                       OUT_VERTEX_F(1);
+
+                       OUT_VERTEX(box->x1, box->y1);
+                       OUT_VERTEX_F(0);
+                       OUT_VERTEX_F(0);
+
+                       box++;
+               } while (--n_this_time);
+       } while (n);
+
+       gen5_vertex_flush(sna);
+       kgem_bo_destroy(&sna->kgem, tmp.src.bo);
+       return true;
+}
+
+static void
+gen5_render_fill_op_blt(struct sna *sna,
+                       const struct sna_fill_op *op,
+                       int16_t x, int16_t y, int16_t w, int16_t h)
+{
+       DBG(("%s (%d, %d)x(%d, %d)\n", __FUNCTION__, x,y,w,h));
+
+       gen5_get_rectangles(sna, &op->base, 1, gen5_fill_bind_surfaces);
+
+       OUT_VERTEX(x+w, y+h);
+       OUT_VERTEX_F(1);
+       OUT_VERTEX_F(1);
+
+       OUT_VERTEX(x, y+h);
+       OUT_VERTEX_F(0);
+       OUT_VERTEX_F(1);
+
+       OUT_VERTEX(x, y);
+       OUT_VERTEX_F(0);
+       OUT_VERTEX_F(0);
+}
+
+fastcall static void
+gen5_render_fill_op_box(struct sna *sna,
+                       const struct sna_fill_op *op,
+                       const BoxRec *box)
+{
+       DBG(("%s: (%d, %d),(%d, %d)\n", __FUNCTION__,
+            box->x1, box->y1, box->x2, box->y2));
+
+       gen5_get_rectangles(sna, &op->base, 1, gen5_fill_bind_surfaces);
+
+       OUT_VERTEX(box->x2, box->y2);
+       OUT_VERTEX_F(1);
+       OUT_VERTEX_F(1);
+
+       OUT_VERTEX(box->x1, box->y2);
+       OUT_VERTEX_F(0);
+       OUT_VERTEX_F(1);
+
+       OUT_VERTEX(box->x1, box->y1);
+       OUT_VERTEX_F(0);
+       OUT_VERTEX_F(0);
+}
+
+fastcall static void
+gen5_render_fill_op_boxes(struct sna *sna,
+                         const struct sna_fill_op *op,
+                         const BoxRec *box,
+                         int nbox)
+{
+       DBG(("%s: (%d, %d),(%d, %d)... x %d\n", __FUNCTION__,
+            box->x1, box->y1, box->x2, box->y2, nbox));
+
+       do {
+               int nbox_this_time;
+
+               nbox_this_time = gen5_get_rectangles(sna, &op->base, nbox,
+                                                    gen5_fill_bind_surfaces);
+               nbox -= nbox_this_time;
+
+               do {
+                       OUT_VERTEX(box->x2, box->y2);
+                       OUT_VERTEX_F(1);
+                       OUT_VERTEX_F(1);
+
+                       OUT_VERTEX(box->x1, box->y2);
+                       OUT_VERTEX_F(0);
+                       OUT_VERTEX_F(1);
+
+                       OUT_VERTEX(box->x1, box->y1);
+                       OUT_VERTEX_F(0);
+                       OUT_VERTEX_F(0);
+                       box++;
+               } while (--nbox_this_time);
+       } while (nbox);
+}
+
+static void
+gen5_render_fill_op_done(struct sna *sna,
+                        const struct sna_fill_op *op)
+{
+       if (sna->render_state.gen5.vertex_offset)
+               gen5_vertex_flush(sna);
+       kgem_bo_destroy(&sna->kgem, op->base.src.bo);
+
+       DBG(("%s()\n", __FUNCTION__));
+}
+
+static bool
+gen5_render_fill(struct sna *sna, uint8_t alu,
+                PixmapPtr dst, struct kgem_bo *dst_bo,
+                uint32_t color,
+                struct sna_fill_op *op)
+{
+       DBG(("%s(alu=%d, color=%08x)\n", __FUNCTION__, alu, color));
+
+       if (prefer_blt_fill(sna) &&
+           sna_blt_fill(sna, alu,
+                        dst_bo, dst->drawable.bitsPerPixel,
+                        color,
+                        op))
+               return true;
+
+       if (!(alu == GXcopy || alu == GXclear) ||
+           too_large(dst->drawable.width, dst->drawable.height))
+               return sna_blt_fill(sna, alu,
+                                   dst_bo, dst->drawable.bitsPerPixel,
+                                   color,
+                                   op);
+
+       if (alu == GXclear)
+               color = 0;
+
+       op->base.op = color == 0 ? PictOpClear : PictOpSrc;
+
+       op->base.dst.pixmap = dst;
+       op->base.dst.width  = dst->drawable.width;
+       op->base.dst.height = dst->drawable.height;
+       op->base.dst.format = sna_format_for_depth(dst->drawable.depth);
+       op->base.dst.bo = dst_bo;
+       op->base.dst.x = op->base.dst.y = 0;
+
+       op->base.need_magic_ca_pass = 0;
+       op->base.has_component_alpha = 0;
+
+       op->base.src.bo =
+               sna_render_get_solid(sna,
+                                    sna_rgba_for_color(color,
+                                                       dst->drawable.depth));
+       op->base.src.filter = SAMPLER_FILTER_NEAREST;
+       op->base.src.repeat = SAMPLER_EXTEND_REPEAT;
+
+       op->base.mask.bo = NULL;
+       op->base.mask.filter = SAMPLER_FILTER_NEAREST;
+       op->base.mask.repeat = SAMPLER_EXTEND_NONE;
+
+       op->base.is_affine = true;
+       op->base.floats_per_vertex = 3;
+       op->base.floats_per_rect = 9;
+       op->base.u.gen5.wm_kernel = WM_KERNEL;
+       op->base.u.gen5.ve_id = 1;
+
+       if (!kgem_check_bo(&sna->kgem, dst_bo, NULL)) {
+               kgem_submit(&sna->kgem);
+               assert(kgem_check_bo(&sna->kgem, dst_bo, NULL));
+       }
+
+       gen5_fill_bind_surfaces(sna, &op->base);
+       gen5_align_vertex(sna, &op->base);
+
+       op->blt   = gen5_render_fill_op_blt;
+       op->box   = gen5_render_fill_op_box;
+       op->boxes = gen5_render_fill_op_boxes;
+       op->done  = gen5_render_fill_op_done;
+       return true;
+}
+
+static bool
+gen5_render_fill_one_try_blt(struct sna *sna, PixmapPtr dst, struct kgem_bo *bo,
+                            uint32_t color,
+                            int16_t x1, int16_t y1, int16_t x2, int16_t y2,
+                            uint8_t alu)
+{
+       BoxRec box;
+
+       box.x1 = x1;
+       box.y1 = y1;
+       box.x2 = x2;
+       box.y2 = y2;
+
+       return sna_blt_fill_boxes(sna, alu,
+                                 bo, dst->drawable.bitsPerPixel,
+                                 color, &box, 1);
+}
+
+static bool
+gen5_render_fill_one(struct sna *sna, PixmapPtr dst, struct kgem_bo *bo,
+                    uint32_t color,
+                    int16_t x1, int16_t y1,
+                    int16_t x2, int16_t y2,
+                    uint8_t alu)
+{
+       struct sna_composite_op tmp;
+
+#if NO_FILL_ONE
+       return gen5_render_fill_one_try_blt(sna, dst, bo, color,
+                                           x1, y1, x2, y2, alu);
+#endif
+
+       /* Prefer to use the BLT if already engaged */
+       if (prefer_blt_fill(sna) &&
+           gen5_render_fill_one_try_blt(sna, dst, bo, color,
+                                        x1, y1, x2, y2, alu))
+               return true;
+
+       /* Must use the BLT if we can't RENDER... */
+       if (!(alu == GXcopy || alu == GXclear) ||
+           too_large(dst->drawable.width, dst->drawable.height))
+               return gen5_render_fill_one_try_blt(sna, dst, bo, color,
+                                                   x1, y1, x2, y2, alu);
+
+       if (alu == GXclear)
+               color = 0;
+
+       tmp.op = color == 0 ? PictOpClear : PictOpSrc;
+
+       tmp.dst.pixmap = dst;
+       tmp.dst.width  = dst->drawable.width;
+       tmp.dst.height = dst->drawable.height;
+       tmp.dst.format = sna_format_for_depth(dst->drawable.depth);
+       tmp.dst.bo = bo;
+       tmp.dst.x = tmp.dst.y = 0;
+
+       tmp.src.bo =
+               sna_render_get_solid(sna,
+                                    sna_rgba_for_color(color,
+                                                       dst->drawable.depth));
+       tmp.src.filter = SAMPLER_FILTER_NEAREST;
+       tmp.src.repeat = SAMPLER_EXTEND_REPEAT;
+
+       tmp.mask.bo = NULL;
+       tmp.mask.filter = SAMPLER_FILTER_NEAREST;
+       tmp.mask.repeat = SAMPLER_EXTEND_NONE;
+
+       tmp.is_affine = true;
+       tmp.floats_per_vertex = 3;
+       tmp.floats_per_rect = 9;
+       tmp.has_component_alpha = 0;
+       tmp.need_magic_ca_pass = false;
+
+       tmp.u.gen5.wm_kernel = WM_KERNEL;
+       tmp.u.gen5.ve_id = 1;
+
+       if (!kgem_check_bo(&sna->kgem, bo, NULL)) {
+               _kgem_submit(&sna->kgem);
+               assert(kgem_check_bo(&sna->kgem, bo, NULL));
+       }
+
+       gen5_fill_bind_surfaces(sna, &tmp);
+       gen5_align_vertex(sna, &tmp);
+
+       gen5_get_rectangles(sna, &tmp, 1, gen5_fill_bind_surfaces);
+
+       DBG(("  (%d, %d), (%d, %d)\n", x1, y1, x2, y2));
+       OUT_VERTEX(x2, y2);
+       OUT_VERTEX_F(1);
+       OUT_VERTEX_F(1);
+
+       OUT_VERTEX(x1, y2);
+       OUT_VERTEX_F(0);
+       OUT_VERTEX_F(1);
+
+       OUT_VERTEX(x1, y1);
+       OUT_VERTEX_F(0);
+       OUT_VERTEX_F(0);
+
+       gen5_vertex_flush(sna);
+       kgem_bo_destroy(&sna->kgem, tmp.src.bo);
+
+       return true;
+}
+
+static void
+gen5_render_flush(struct sna *sna)
+{
+       gen5_vertex_close(sna);
+}
+
+static void
+gen5_render_context_switch(struct kgem *kgem,
+                          int new_mode)
+{
+       if (!kgem->mode)
+               return;
+
+       /* WaNonPipelinedStateCommandFlush
+        *
+        * Ironlake has a limitation that a 3D or Media command can't
+        * be the first command after a BLT, unless it's
+        * non-pipelined.
+        *
+        * We do this by ensuring that the non-pipelined drawrect
+        * is always emitted first following a switch from BLT.
+        */
+       if (kgem->mode == KGEM_BLT) {
+               struct sna *sna = to_sna_from_kgem(kgem);
+               DBG(("%s: forcing drawrect on next state emission\n",
+                    __FUNCTION__));
+               sna->render_state.gen5.drawrect_limit = -1;
+       }
+
+       if (kgem_is_idle(kgem)) {
+               DBG(("%s: GPU idle, flushing\n", __FUNCTION__));
+               _kgem_submit(kgem);
+       }
+}
+
+static void
+discard_vbo(struct sna *sna)
+{
+       kgem_bo_destroy(&sna->kgem, sna->render.vbo);
+       sna->render.vbo = NULL;
+       sna->render.vertices = sna->render.vertex_data;
+       sna->render.vertex_size = ARRAY_SIZE(sna->render.vertex_data);
+       sna->render.vertex_used = 0;
+       sna->render.vertex_index = 0;
+}
+
+static void
+gen5_render_retire(struct kgem *kgem)
+{
+       struct sna *sna;
+
+       sna = container_of(kgem, struct sna, kgem);
+       if (kgem->nbatch == 0 && sna->render.vbo && !kgem_bo_is_busy(sna->render.vbo)) {
+               DBG(("%s: resetting idle vbo\n", __FUNCTION__));
+               sna->render.vertex_used = 0;
+               sna->render.vertex_index = 0;
+       }
+}
+
+static void
+gen5_render_expire(struct kgem *kgem)
+{
+       struct sna *sna;
+
+       sna = container_of(kgem, struct sna, kgem);
+       if (sna->render.vbo && !sna->render.vertex_used) {
+               DBG(("%s: discarding vbo\n", __FUNCTION__));
+               discard_vbo(sna);
+       }
+}
+
+static void gen5_render_reset(struct sna *sna)
+{
+       sna->render_state.gen5.needs_invariant = true;
+       sna->render_state.gen5.vb_id = 0;
+       sna->render_state.gen5.ve_id = -1;
+       sna->render_state.gen5.last_primitive = -1;
+       sna->render_state.gen5.last_pipelined_pointers = 0;
+
+       sna->render_state.gen5.drawrect_offset = -1;
+       sna->render_state.gen5.drawrect_limit = -1;
+       sna->render_state.gen5.surface_table = -1;
+
+       if (sna->render.vbo &&
+           !kgem_bo_is_mappable(&sna->kgem, sna->render.vbo)) {
+               DBG(("%s: discarding unmappable vbo\n", __FUNCTION__));
+               discard_vbo(sna);
+       }
+}
+
+static void gen5_render_fini(struct sna *sna)
+{
+       kgem_bo_destroy(&sna->kgem, sna->render_state.gen5.general_bo);
+}
+
+static uint32_t gen5_create_vs_unit_state(struct sna_static_stream *stream)
+{
+       struct gen5_vs_unit_state *vs = sna_static_stream_map(stream, sizeof(*vs), 32);
+
+       /* Set up the vertex shader to be disabled (passthrough) */
+       vs->thread4.nr_urb_entries = URB_VS_ENTRIES >> 2;
+       vs->thread4.urb_entry_allocation_size = URB_VS_ENTRY_SIZE - 1;
+       vs->vs6.vs_enable = 0;
+       vs->vs6.vert_cache_disable = 1;
+
+       return sna_static_stream_offsetof(stream, vs);
+}
+
+static uint32_t gen5_create_sf_state(struct sna_static_stream *stream,
+                                    uint32_t kernel)
+{
+       struct gen5_sf_unit_state *sf_state;
+
+       sf_state = sna_static_stream_map(stream, sizeof(*sf_state), 32);
+
+       sf_state->thread0.grf_reg_count = GEN5_GRF_BLOCKS(SF_KERNEL_NUM_GRF);
+       sf_state->thread0.kernel_start_pointer = kernel >> 6;
+
+       sf_state->thread3.const_urb_entry_read_length = 0;      /* no const URBs */
+       sf_state->thread3.const_urb_entry_read_offset = 0;      /* no const URBs */
+       sf_state->thread3.urb_entry_read_length = 1;    /* 1 URB per vertex */
+       /* don't smash vertex header, read start from dw8 */
+       sf_state->thread3.urb_entry_read_offset = 1;
+       sf_state->thread3.dispatch_grf_start_reg = 3;
+       sf_state->thread4.max_threads = SF_MAX_THREADS - 1;
+       sf_state->thread4.urb_entry_allocation_size = URB_SF_ENTRY_SIZE - 1;
+       sf_state->thread4.nr_urb_entries = URB_SF_ENTRIES;
+       sf_state->sf5.viewport_transform = false;       /* skip viewport */
+       sf_state->sf6.cull_mode = GEN5_CULLMODE_NONE;
+       sf_state->sf6.scissor = 0;
+       sf_state->sf7.trifan_pv = 2;
+       sf_state->sf6.dest_org_vbias = 0x8;
+       sf_state->sf6.dest_org_hbias = 0x8;
+
+       return sna_static_stream_offsetof(stream, sf_state);
+}
+
+static uint32_t gen5_create_sampler_state(struct sna_static_stream *stream,
+                                         sampler_filter_t src_filter,
+                                         sampler_extend_t src_extend,
+                                         sampler_filter_t mask_filter,
+                                         sampler_extend_t mask_extend)
+{
+       struct gen5_sampler_state *sampler_state;
+
+       sampler_state = sna_static_stream_map(stream,
+                                             sizeof(struct gen5_sampler_state) * 2,
+                                             32);
+       sampler_state_init(&sampler_state[0], src_filter, src_extend);
+       sampler_state_init(&sampler_state[1], mask_filter, mask_extend);
+
+       return sna_static_stream_offsetof(stream, sampler_state);
+}
+
+static void gen5_init_wm_state(struct gen5_wm_unit_state *state,
+                              bool has_mask,
+                              uint32_t kernel,
+                              uint32_t sampler)
+{
+       state->thread0.grf_reg_count = GEN5_GRF_BLOCKS(PS_KERNEL_NUM_GRF);
+       state->thread0.kernel_start_pointer = kernel >> 6;
+
+       state->thread1.single_program_flow = 0;
+
+       /* scratch space is not used in our kernel */
+       state->thread2.scratch_space_base_pointer = 0;
+       state->thread2.per_thread_scratch_space = 0;
+
+       state->thread3.const_urb_entry_read_length = 0;
+       state->thread3.const_urb_entry_read_offset = 0;
+
+       state->thread3.urb_entry_read_offset = 0;
+       /* wm kernel use urb from 3, see wm_program in compiler module */
+       state->thread3.dispatch_grf_start_reg = 3;      /* must match kernel */
+
+       state->wm4.sampler_count = 0;   /* hardware requirement */
+
+       state->wm4.sampler_state_pointer = sampler >> 5;
+       state->wm5.max_threads = PS_MAX_THREADS - 1;
+       state->wm5.transposed_urb_read = 0;
+       state->wm5.thread_dispatch_enable = 1;
+       /* just use 16-pixel dispatch (4 subspans), don't need to change kernel
+        * start point
+        */
+       state->wm5.enable_16_pix = 1;
+       state->wm5.enable_8_pix = 0;
+       state->wm5.early_depth_test = 1;
+
+       /* Each pair of attributes (src/mask coords) is two URB entries */
+       if (has_mask) {
+               state->thread1.binding_table_entry_count = 3;   /* 2 tex and fb */
+               state->thread3.urb_entry_read_length = 4;
+       } else {
+               state->thread1.binding_table_entry_count = 2;   /* 1 tex and fb */
+               state->thread3.urb_entry_read_length = 2;
+       }
+
+       /* binding table entry count is only used for prefetching,
+        * and it has to be set 0 for Ironlake
+        */
+       state->thread1.binding_table_entry_count = 0;
+}
+
+static uint32_t gen5_create_cc_viewport(struct sna_static_stream *stream)
+{
+       struct gen5_cc_viewport vp;
+
+       vp.min_depth = -1.e35;
+       vp.max_depth = 1.e35;
+
+       return sna_static_stream_add(stream, &vp, sizeof(vp), 32);
+}
+
+static uint32_t gen5_create_cc_unit_state(struct sna_static_stream *stream)
+{
+       uint8_t *ptr, *base;
+       uint32_t vp;
+       int i, j;
+
+       vp = gen5_create_cc_viewport(stream);
+       base = ptr =
+               sna_static_stream_map(stream,
+                                     GEN5_BLENDFACTOR_COUNT*GEN5_BLENDFACTOR_COUNT*64,
+                                     64);
+
+       for (i = 0; i < GEN5_BLENDFACTOR_COUNT; i++) {
+               for (j = 0; j < GEN5_BLENDFACTOR_COUNT; j++) {
+                       struct gen5_cc_unit_state *state =
+                               (struct gen5_cc_unit_state *)ptr;
+
+                       state->cc3.blend_enable =
+                               !(j == GEN5_BLENDFACTOR_ZERO && i == GEN5_BLENDFACTOR_ONE);
+                       state->cc4.cc_viewport_state_offset = vp >> 5;
+
+                       state->cc5.logicop_func = 0xc;  /* COPY */
+                       state->cc5.ia_blend_function = GEN5_BLENDFUNCTION_ADD;
+
+                       /* Fill in alpha blend factors same as color, for the future. */
+                       state->cc5.ia_src_blend_factor = i;
+                       state->cc5.ia_dest_blend_factor = j;
+
+                       state->cc6.blend_function = GEN5_BLENDFUNCTION_ADD;
+                       state->cc6.clamp_post_alpha_blend = 1;
+                       state->cc6.clamp_pre_alpha_blend = 1;
+                       state->cc6.src_blend_factor = i;
+                       state->cc6.dest_blend_factor = j;
+
+                       ptr += 64;
+               }
+       }
+
+       return sna_static_stream_offsetof(stream, base);
+}
+
+static bool gen5_render_setup(struct sna *sna)
+{
+       struct gen5_render_state *state = &sna->render_state.gen5;
+       struct sna_static_stream general;
+       struct gen5_wm_unit_state_padded *wm_state;
+       uint32_t sf[2], wm[KERNEL_COUNT];
+       int i, j, k, l, m;
+
+       sna_static_stream_init(&general);
+
+       /* Zero pad the start. If you see an offset of 0x0 in the batchbuffer
+        * dumps, you know it points to zero.
+        */
+       null_create(&general);
+
+       /* Set up the two SF states (one for blending with a mask, one without) */
+       sf[0] = sna_static_stream_compile_sf(sna, &general, brw_sf_kernel__nomask);
+       sf[1] = sna_static_stream_compile_sf(sna, &general, brw_sf_kernel__mask);
+
+       for (m = 0; m < KERNEL_COUNT; m++) {
+               if (wm_kernels[m].size) {
+                       wm[m] = sna_static_stream_add(&general,
+                                                     wm_kernels[m].data,
+                                                     wm_kernels[m].size,
+                                                     64);
+               } else {
+                       wm[m] = sna_static_stream_compile_wm(sna, &general,
+                                                            wm_kernels[m].data,
+                                                            16);
+               }
+               assert(wm[m]);
+       }
+
+       state->vs = gen5_create_vs_unit_state(&general);
+
+       state->sf[0] = gen5_create_sf_state(&general, sf[0]);
+       state->sf[1] = gen5_create_sf_state(&general, sf[1]);
+
+
+       /* Set up the WM states: each filter/extend type for source and mask, per
+        * kernel.
+        */
+       wm_state = sna_static_stream_map(&general,
+                                         sizeof(*wm_state) * KERNEL_COUNT *
+                                         FILTER_COUNT * EXTEND_COUNT *
+                                         FILTER_COUNT * EXTEND_COUNT,
+                                         64);
+       state->wm = sna_static_stream_offsetof(&general, wm_state);
+       for (i = 0; i < FILTER_COUNT; i++) {
+               for (j = 0; j < EXTEND_COUNT; j++) {
+                       for (k = 0; k < FILTER_COUNT; k++) {
+                               for (l = 0; l < EXTEND_COUNT; l++) {
+                                       uint32_t sampler_state;
+
+                                       sampler_state =
+                                               gen5_create_sampler_state(&general,
+                                                                         i, j,
+                                                                         k, l);
+
+                                       for (m = 0; m < KERNEL_COUNT; m++) {
+                                               gen5_init_wm_state(&wm_state->state,
+                                                                  wm_kernels[m].has_mask,
+                                                                  wm[m],
+                                                                  sampler_state);
+                                               wm_state++;
+                                       }
+                               }
+                       }
+               }
+       }
+
+       state->cc = gen5_create_cc_unit_state(&general);
+
+       state->general_bo = sna_static_stream_fini(sna, &general);
+       return state->general_bo != NULL;
+}
+
+bool gen5_render_init(struct sna *sna)
+{
+       if (!gen5_render_setup(sna))
+               return false;
+
+       sna->kgem.context_switch = gen5_render_context_switch;
+       sna->kgem.retire = gen5_render_retire;
+       sna->kgem.expire = gen5_render_expire;
+
+       sna->render.composite = gen5_render_composite;
+#if !NO_COMPOSITE_SPANS
+       sna->render.check_composite_spans = gen5_check_composite_spans;
+       sna->render.composite_spans = gen5_render_composite_spans;
+#endif
+       sna->render.video = gen5_render_video;
+
+       sna->render.copy_boxes = gen5_render_copy_boxes;
+       sna->render.copy = gen5_render_copy;
+
+       sna->render.fill_boxes = gen5_render_fill_boxes;
+       sna->render.fill = gen5_render_fill;
+       sna->render.fill_one = gen5_render_fill_one;
+
+       sna->render.flush = gen5_render_flush;
+       sna->render.reset = gen5_render_reset;
+       sna->render.fini = gen5_render_fini;
+
+       sna->render.max_3d_size = MAX_3D_SIZE;
+       sna->render.max_3d_pitch = 1 << 18;
+       return true;
+}
diff --git a/src/sna/gen5_render.h b/src/sna/gen5_render.h
new file mode 100644 (file)
index 0000000..b6e5b0c
--- /dev/null
@@ -0,0 +1,2780 @@
+/**************************************************************************
+ *
+ * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * 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, sub license, 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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 GEN5_RENDER_H
+#define GEN5_RENDER_H
+
+#define GEN5_3D(Pipeline,Opcode,Subopcode) ((3 << 29) | \
+                                          ((Pipeline) << 27) | \
+                                          ((Opcode) << 24) | \
+                                          ((Subopcode) << 16))
+
+#define GEN5_URB_FENCE                         GEN5_3D(0, 0, 0)
+#define GEN5_CS_URB_STATE                      GEN5_3D(0, 0, 1)
+#define GEN5_CONSTANT_BUFFER                   GEN5_3D(0, 0, 2)
+#define GEN5_STATE_PREFETCH                    GEN5_3D(0, 0, 3)
+
+#define GEN5_STATE_BASE_ADDRESS                        GEN5_3D(0, 1, 1)
+#define GEN5_STATE_SIP                         GEN5_3D(0, 1, 2)
+
+#define GEN5_PIPELINE_SELECT                   GEN5_3D(1, 1, 4)
+
+#define GEN5_MEDIA_STATE_POINTERS              GEN5_3D(2, 0, 0)
+#define GEN5_MEDIA_OBJECT                      GEN5_3D(2, 1, 0)
+
+#define GEN5_3DSTATE_PIPELINED_POINTERS                GEN5_3D(3, 0, 0)
+#define GEN5_3DSTATE_BINDING_TABLE_POINTERS    GEN5_3D(3, 0, 1)
+# define GEN6_3DSTATE_BINDING_TABLE_MODIFY_PS  (1 << 12)/* for GEN6 */
+# define GEN6_3DSTATE_BINDING_TABLE_MODIFY_GS  (1 << 9) /* for GEN6 */
+# define GEN6_3DSTATE_BINDING_TABLE_MODIFY_VS  (1 << 8) /* for GEN6 */
+
+#define GEN5_3DSTATE_VERTEX_BUFFERS            GEN5_3D(3, 0, 8)
+#define GEN5_3DSTATE_VERTEX_ELEMENTS           GEN5_3D(3, 0, 9)
+#define GEN5_3DSTATE_INDEX_BUFFER              GEN5_3D(3, 0, 0xa)
+#define GEN5_3DSTATE_VF_STATISTICS             GEN5_3D(3, 0, 0xb)
+
+#define GEN5_3DSTATE_DRAWING_RECTANGLE         GEN5_3D(3, 1, 0)
+#define GEN5_3DSTATE_CONSTANT_COLOR            GEN5_3D(3, 1, 1)
+#define GEN5_3DSTATE_SAMPLER_PALETTE_LOAD      GEN5_3D(3, 1, 2)
+#define GEN5_3DSTATE_CHROMA_KEY                        GEN5_3D(3, 1, 4)
+#define GEN5_3DSTATE_DEPTH_BUFFER              GEN5_3D(3, 1, 5)
+# define GEN5_3DSTATE_DEPTH_BUFFER_TYPE_SHIFT  29
+# define GEN5_3DSTATE_DEPTH_BUFFER_FORMAT_SHIFT        18
+
+#define GEN5_3DSTATE_POLY_STIPPLE_OFFSET               GEN5_3D(3, 1, 6)
+#define GEN5_3DSTATE_POLY_STIPPLE_PATTERN      GEN5_3D(3, 1, 7)
+#define GEN5_3DSTATE_LINE_STIPPLE              GEN5_3D(3, 1, 8)
+#define GEN5_3DSTATE_GLOBAL_DEPTH_OFFSET_CLAMP GEN5_3D(3, 1, 9)
+/* These two are BLC and CTG only, not BW or CL */
+#define GEN5_3DSTATE_AA_LINE_PARAMS            GEN5_3D(3, 1, 0xa)
+#define GEN5_3DSTATE_GS_SVB_INDEX              GEN5_3D(3, 1, 0xb)
+
+#define GEN5_PIPE_CONTROL                      GEN5_3D(3, 2, 0)
+
+#define GEN5_3DPRIMITIVE                               GEN5_3D(3, 3, 0)
+
+#define GEN5_3DSTATE_CLEAR_PARAMS              GEN5_3D(3, 1, 0x10)
+/* DW1 */
+# define GEN5_3DSTATE_DEPTH_CLEAR_VALID                (1 << 15)
+
+/* for GEN6+ */
+#define GEN6_3DSTATE_SAMPLER_STATE_POINTERS    GEN5_3D(3, 0, 0x02)
+# define GEN6_3DSTATE_SAMPLER_STATE_MODIFY_PS  (1 << 12)
+# define GEN6_3DSTATE_SAMPLER_STATE_MODIFY_GS  (1 << 9)
+# define GEN6_3DSTATE_SAMPLER_STATE_MODIFY_VS  (1 << 8)
+
+#define GEN6_3DSTATE_URB                       GEN5_3D(3, 0, 0x05)
+/* DW1 */
+# define GEN6_3DSTATE_URB_VS_SIZE_SHIFT                16
+# define GEN6_3DSTATE_URB_VS_ENTRIES_SHIFT     0
+/* DW2 */
+# define GEN6_3DSTATE_URB_GS_ENTRIES_SHIFT     8
+# define GEN6_3DSTATE_URB_GS_SIZE_SHIFT                0
+
+#define GEN6_3DSTATE_VIEWPORT_STATE_POINTERS   GEN5_3D(3, 0, 0x0d)
+# define GEN6_3DSTATE_VIEWPORT_STATE_MODIFY_CC         (1 << 12)
+# define GEN6_3DSTATE_VIEWPORT_STATE_MODIFY_SF         (1 << 11)
+# define GEN6_3DSTATE_VIEWPORT_STATE_MODIFY_CLIP       (1 << 10)
+
+#define GEN6_3DSTATE_CC_STATE_POINTERS         GEN5_3D(3, 0, 0x0e)
+
+#define GEN6_3DSTATE_VS                                GEN5_3D(3, 0, 0x10)
+
+#define GEN6_3DSTATE_GS                                GEN5_3D(3, 0, 0x11)
+/* DW4 */
+# define GEN6_3DSTATE_GS_DISPATCH_START_GRF_SHIFT      0
+
+#define GEN6_3DSTATE_CLIP                      GEN5_3D(3, 0, 0x12)
+
+#define GEN6_3DSTATE_SF                                GEN5_3D(3, 0, 0x13)
+/* DW1 */
+# define GEN6_3DSTATE_SF_NUM_OUTPUTS_SHIFT             22
+# define GEN6_3DSTATE_SF_URB_ENTRY_READ_LENGTH_SHIFT   11
+# define GEN6_3DSTATE_SF_URB_ENTRY_READ_OFFSET_SHIFT   4
+/* DW2 */
+/* DW3 */
+# define GEN6_3DSTATE_SF_CULL_BOTH                     (0 << 29)
+# define GEN6_3DSTATE_SF_CULL_NONE                     (1 << 29)
+# define GEN6_3DSTATE_SF_CULL_FRONT                    (2 << 29)
+# define GEN6_3DSTATE_SF_CULL_BACK                     (3 << 29)
+/* DW4 */
+# define GEN6_3DSTATE_SF_TRI_PROVOKE_SHIFT             29
+# define GEN6_3DSTATE_SF_LINE_PROVOKE_SHIFT            27
+# define GEN6_3DSTATE_SF_TRIFAN_PROVOKE_SHIFT          25
+
+
+#define GEN6_3DSTATE_WM                                GEN5_3D(3, 0, 0x14)
+/* DW2 */
+# define GEN6_3DSTATE_WM_SAMPLER_COUNT_SHITF                   27
+# define GEN6_3DSTATE_WM_BINDING_TABLE_ENTRY_COUNT_SHIFT       18
+/* DW4 */
+# define GEN6_3DSTATE_WM_DISPATCH_START_GRF_0_SHIFT            16
+/* DW5 */
+# define GEN6_3DSTATE_WM_MAX_THREADS_SHIFT                     25
+# define GEN6_3DSTATE_WM_DISPATCH_ENABLE                       (1 << 19)
+# define GEN6_3DSTATE_WM_16_DISPATCH_ENABLE                    (1 << 1)
+# define GEN6_3DSTATE_WM_8_DISPATCH_ENABLE                     (1 << 0)
+/* DW6 */
+# define GEN6_3DSTATE_WM_NUM_SF_OUTPUTS_SHIFT                  20
+# define GEN6_3DSTATE_WM_NONPERSPECTIVE_SAMPLE_BARYCENTRIC     (1 << 15)
+# define GEN6_3DSTATE_WM_NONPERSPECTIVE_CENTROID_BARYCENTRIC   (1 << 14)
+# define GEN6_3DSTATE_WM_NONPERSPECTIVE_PIXEL_BARYCENTRIC      (1 << 13)
+# define GEN6_3DSTATE_WM_PERSPECTIVE_SAMPLE_BARYCENTRIC                (1 << 12)
+# define GEN6_3DSTATE_WM_PERSPECTIVE_CENTROID_BARYCENTRIC      (1 << 11)
+# define GEN6_3DSTATE_WM_PERSPECTIVE_PIXEL_BARYCENTRIC         (1 << 10)
+
+
+#define GEN6_3DSTATE_CONSTANT_VS               GEN5_3D(3, 0, 0x15)
+#define GEN6_3DSTATE_CONSTANT_GS               GEN5_3D(3, 0, 0x16)
+#define GEN6_3DSTATE_CONSTANT_PS               GEN5_3D(3, 0, 0x17)
+
+#define GEN6_3DSTATE_SAMPLE_MASK               GEN5_3D(3, 0, 0x18)
+
+#define GEN6_3DSTATE_MULTISAMPLE               GEN5_3D(3, 1, 0x0d)
+/* DW1 */
+# define GEN6_3DSTATE_MULTISAMPLE_PIXEL_LOCATION_CENTER                (0 << 4)
+# define GEN6_3DSTATE_MULTISAMPLE_PIXEL_LOCATION_UPPER_LEFT    (1 << 4)
+# define GEN6_3DSTATE_MULTISAMPLE_NUMSAMPLES_1                 (0 << 1)
+# define GEN6_3DSTATE_MULTISAMPLE_NUMSAMPLES_4                 (2 << 1)
+# define GEN6_3DSTATE_MULTISAMPLE_NUMSAMPLES_8                 (3 << 1)
+
+#define PIPELINE_SELECT_3D             0
+#define PIPELINE_SELECT_MEDIA          1
+
+#define UF0_CS_REALLOC                 (1 << 13)
+#define UF0_VFE_REALLOC                        (1 << 12)
+#define UF0_SF_REALLOC                 (1 << 11)
+#define UF0_CLIP_REALLOC               (1 << 10)
+#define UF0_GS_REALLOC                 (1 << 9)
+#define UF0_VS_REALLOC                 (1 << 8)
+#define UF1_CLIP_FENCE_SHIFT           20
+#define UF1_GS_FENCE_SHIFT             10
+#define UF1_VS_FENCE_SHIFT             0
+#define UF2_CS_FENCE_SHIFT             20
+#define UF2_VFE_FENCE_SHIFT            10
+#define UF2_SF_FENCE_SHIFT             0
+
+/* for GEN5_STATE_BASE_ADDRESS */
+#define BASE_ADDRESS_MODIFY            (1 << 0)
+
+/* for GEN5_3DSTATE_PIPELINED_POINTERS */
+#define GEN5_GS_DISABLE                       0
+#define GEN5_GS_ENABLE                1
+#define GEN5_CLIP_DISABLE             0
+#define GEN5_CLIP_ENABLE                      1
+
+/* for GEN5_PIPE_CONTROL */
+#define GEN5_PIPE_CONTROL_NOWRITE       (0 << 14)
+#define GEN5_PIPE_CONTROL_WRITE_QWORD   (1 << 14)
+#define GEN5_PIPE_CONTROL_WRITE_DEPTH   (2 << 14)
+#define GEN5_PIPE_CONTROL_WRITE_TIME    (3 << 14)
+#define GEN5_PIPE_CONTROL_DEPTH_STALL   (1 << 13)
+#define GEN5_PIPE_CONTROL_WC_FLUSH      (1 << 12)
+#define GEN5_PIPE_CONTROL_IS_FLUSH      (1 << 11)
+#define GEN5_PIPE_CONTROL_TC_FLUSH      (1 << 10)
+#define GEN5_PIPE_CONTROL_NOTIFY_ENABLE (1 << 8)
+#define GEN5_PIPE_CONTROL_GLOBAL_GTT    (1 << 2)
+#define GEN5_PIPE_CONTROL_LOCAL_PGTT    (0 << 2)
+#define GEN5_PIPE_CONTROL_DEPTH_CACHE_FLUSH    (1 << 0)
+
+/* VERTEX_BUFFER_STATE Structure */
+#define VB0_BUFFER_INDEX_SHIFT         27
+#define GEN6_VB0_BUFFER_INDEX_SHIFT    26
+#define VB0_VERTEXDATA                 (0 << 26)
+#define VB0_INSTANCEDATA               (1 << 26)
+#define GEN6_VB0_VERTEXDATA            (0 << 20)
+#define GEN6_VB0_INSTANCEDATA          (1 << 20)
+#define VB0_BUFFER_PITCH_SHIFT         0
+
+/* VERTEX_ELEMENT_STATE Structure */
+#define VE0_VERTEX_BUFFER_INDEX_SHIFT  27
+#define GEN6_VE0_VERTEX_BUFFER_INDEX_SHIFT     26 /* for GEN6 */
+#define VE0_VALID                      (1 << 26)
+#define GEN6_VE0_VALID                 (1 << 25) /* for GEN6 */
+#define VE0_FORMAT_SHIFT               16
+#define VE0_OFFSET_SHIFT               0
+#define VE1_VFCOMPONENT_0_SHIFT                28
+#define VE1_VFCOMPONENT_1_SHIFT                24
+#define VE1_VFCOMPONENT_2_SHIFT                20
+#define VE1_VFCOMPONENT_3_SHIFT                16
+#define VE1_DESTINATION_ELEMENT_OFFSET_SHIFT   0
+
+/* 3DPRIMITIVE bits */
+#define GEN5_3DPRIMITIVE_VERTEX_SEQUENTIAL (0 << 15)
+#define GEN5_3DPRIMITIVE_VERTEX_RANDOM   (1 << 15)
+/* Primitive types are in gen5_defines.h */
+#define GEN5_3DPRIMITIVE_TOPOLOGY_SHIFT          10
+
+#define GEN5_SVG_CTL                  0x7400
+
+#define GEN5_SVG_CTL_GS_BA            (0 << 8)
+#define GEN5_SVG_CTL_SS_BA            (1 << 8)
+#define GEN5_SVG_CTL_IO_BA            (2 << 8)
+#define GEN5_SVG_CTL_GS_AUB           (3 << 8)
+#define GEN5_SVG_CTL_IO_AUB           (4 << 8)
+#define GEN5_SVG_CTL_SIP                      (5 << 8)
+
+#define GEN5_SVG_RDATA                0x7404
+#define GEN5_SVG_WORK_CTL             0x7408
+
+#define GEN5_VF_CTL                   0x7500
+
+#define GEN5_VF_CTL_SNAPSHOT_COMPLETE             (1 << 31)
+#define GEN5_VF_CTL_SNAPSHOT_MUX_SELECT_THREADID          (0 << 8)
+#define GEN5_VF_CTL_SNAPSHOT_MUX_SELECT_VF_DEBUG          (1 << 8)
+#define GEN5_VF_CTL_SNAPSHOT_TYPE_VERTEX_SEQUENCE   (0 << 4)
+#define GEN5_VF_CTL_SNAPSHOT_TYPE_VERTEX_INDEX    (1 << 4)
+#define GEN5_VF_CTL_SKIP_INITIAL_PRIMITIVES       (1 << 3)
+#define GEN5_VF_CTL_MAX_PRIMITIVES_LIMIT_ENABLE           (1 << 2)
+#define GEN5_VF_CTL_VERTEX_RANGE_LIMIT_ENABLE     (1 << 1)
+#define GEN5_VF_CTL_SNAPSHOT_ENABLE               (1 << 0)
+
+#define GEN5_VF_STRG_VAL                      0x7504
+#define GEN5_VF_STR_VL_OVR            0x7508
+#define GEN5_VF_VC_OVR                0x750c
+#define GEN5_VF_STR_PSKIP             0x7510
+#define GEN5_VF_MAX_PRIM                      0x7514
+#define GEN5_VF_RDATA                 0x7518
+
+#define GEN5_VS_CTL                   0x7600
+#define GEN5_VS_CTL_SNAPSHOT_COMPLETE             (1 << 31)
+#define GEN5_VS_CTL_SNAPSHOT_MUX_VERTEX_0         (0 << 8)
+#define GEN5_VS_CTL_SNAPSHOT_MUX_VERTEX_1         (1 << 8)
+#define GEN5_VS_CTL_SNAPSHOT_MUX_VALID_COUNT      (2 << 8)
+#define GEN5_VS_CTL_SNAPSHOT_MUX_VS_KERNEL_POINTER  (3 << 8)
+#define GEN5_VS_CTL_SNAPSHOT_ALL_THREADS                  (1 << 2)
+#define GEN5_VS_CTL_THREAD_SNAPSHOT_ENABLE        (1 << 1)
+#define GEN5_VS_CTL_SNAPSHOT_ENABLE               (1 << 0)
+
+#define GEN5_VS_STRG_VAL                      0x7604
+#define GEN5_VS_RDATA                 0x7608
+
+#define GEN5_SF_CTL                   0x7b00
+#define GEN5_SF_CTL_SNAPSHOT_COMPLETE             (1 << 31)
+#define GEN5_SF_CTL_SNAPSHOT_MUX_VERTEX_0_FF_ID           (0 << 8)
+#define GEN5_SF_CTL_SNAPSHOT_MUX_VERTEX_0_REL_COUNT (1 << 8)
+#define GEN5_SF_CTL_SNAPSHOT_MUX_VERTEX_1_FF_ID           (2 << 8)
+#define GEN5_SF_CTL_SNAPSHOT_MUX_VERTEX_1_REL_COUNT (3 << 8)
+#define GEN5_SF_CTL_SNAPSHOT_MUX_VERTEX_2_FF_ID           (4 << 8)
+#define GEN5_SF_CTL_SNAPSHOT_MUX_VERTEX_2_REL_COUNT (5 << 8)
+#define GEN5_SF_CTL_SNAPSHOT_MUX_VERTEX_COUNT     (6 << 8)
+#define GEN5_SF_CTL_SNAPSHOT_MUX_SF_KERNEL_POINTER  (7 << 8)
+#define GEN5_SF_CTL_MIN_MAX_PRIMITIVE_RANGE_ENABLE  (1 << 4)
+#define GEN5_SF_CTL_DEBUG_CLIP_RECTANGLE_ENABLE           (1 << 3)
+#define GEN5_SF_CTL_SNAPSHOT_ALL_THREADS                  (1 << 2)
+#define GEN5_SF_CTL_THREAD_SNAPSHOT_ENABLE        (1 << 1)
+#define GEN5_SF_CTL_SNAPSHOT_ENABLE               (1 << 0)
+
+#define GEN5_SF_STRG_VAL                      0x7b04
+#define GEN5_SF_RDATA                 0x7b18
+
+#define GEN5_WIZ_CTL                  0x7c00
+#define GEN5_WIZ_CTL_SNAPSHOT_COMPLETE            (1 << 31)
+#define GEN5_WIZ_CTL_SUBSPAN_INSTANCE_SHIFT       16
+#define GEN5_WIZ_CTL_SNAPSHOT_MUX_WIZ_KERNEL_POINTER   (0 << 8)
+#define GEN5_WIZ_CTL_SNAPSHOT_MUX_SUBSPAN_INSTANCE     (1 << 8)
+#define GEN5_WIZ_CTL_SNAPSHOT_MUX_PRIMITIVE_SEQUENCE   (2 << 8)
+#define GEN5_WIZ_CTL_SINGLE_SUBSPAN_DISPATCH         (1 << 6)
+#define GEN5_WIZ_CTL_IGNORE_COLOR_SCOREBOARD_STALLS    (1 << 5)
+#define GEN5_WIZ_CTL_ENABLE_SUBSPAN_INSTANCE_COMPARE   (1 << 4)
+#define GEN5_WIZ_CTL_USE_UPSTREAM_SNAPSHOT_FLAG              (1 << 3)
+#define GEN5_WIZ_CTL_SNAPSHOT_ALL_THREADS            (1 << 2)
+#define GEN5_WIZ_CTL_THREAD_SNAPSHOT_ENABLE          (1 << 1)
+#define GEN5_WIZ_CTL_SNAPSHOT_ENABLE                 (1 << 0)
+
+#define GEN5_WIZ_STRG_VAL                            0x7c04
+#define GEN5_WIZ_RDATA                               0x7c18
+
+#define GEN5_TS_CTL                   0x7e00
+#define GEN5_TS_CTL_SNAPSHOT_COMPLETE             (1 << 31)
+#define GEN5_TS_CTL_SNAPSHOT_MESSAGE_ERROR        (0 << 8)
+#define GEN5_TS_CTL_SNAPSHOT_INTERFACE_DESCRIPTOR   (3 << 8)
+#define GEN5_TS_CTL_SNAPSHOT_ALL_CHILD_THREADS    (1 << 2)
+#define GEN5_TS_CTL_SNAPSHOT_ALL_ROOT_THREADS             (1 << 1)
+#define GEN5_TS_CTL_SNAPSHOT_ENABLE               (1 << 0)
+
+#define GEN5_TS_STRG_VAL                      0x7e04
+#define GEN5_TS_RDATA                 0x7e08
+
+#define GEN5_TD_CTL                   0x8000
+#define GEN5_TD_CTL_MUX_SHIFT         8
+#define GEN5_TD_CTL_EXTERNAL_HALT_R0_DEBUG_MATCH          (1 << 7)
+#define GEN5_TD_CTL_FORCE_EXTERNAL_HALT                   (1 << 6)
+#define GEN5_TD_CTL_EXCEPTION_MASK_OVERRIDE       (1 << 5)
+#define GEN5_TD_CTL_FORCE_THREAD_BREAKPOINT_ENABLE  (1 << 4)
+#define GEN5_TD_CTL_BREAKPOINT_ENABLE             (1 << 2)
+#define GEN5_TD_CTL2                  0x8004
+#define GEN5_TD_CTL2_ILLEGAL_OPCODE_EXCEPTION_OVERRIDE (1 << 28)
+#define GEN5_TD_CTL2_MASKSTACK_EXCEPTION_OVERRIDE      (1 << 26)
+#define GEN5_TD_CTL2_SOFTWARE_EXCEPTION_OVERRIDE             (1 << 25)
+#define GEN5_TD_CTL2_ACTIVE_THREAD_LIMIT_SHIFT       16
+#define GEN5_TD_CTL2_ACTIVE_THREAD_LIMIT_ENABLE              (1 << 8)
+#define GEN5_TD_CTL2_THREAD_SPAWNER_EXECUTION_MASK_ENABLE (1 << 7)
+#define GEN5_TD_CTL2_WIZ_EXECUTION_MASK_ENABLE       (1 << 6)
+#define GEN5_TD_CTL2_SF_EXECUTION_MASK_ENABLE        (1 << 5)
+#define GEN5_TD_CTL2_CLIPPER_EXECUTION_MASK_ENABLE     (1 << 4)
+#define GEN5_TD_CTL2_GS_EXECUTION_MASK_ENABLE        (1 << 3)
+#define GEN5_TD_CTL2_VS_EXECUTION_MASK_ENABLE        (1 << 0)
+#define GEN5_TD_VF_VS_EMSK            0x8008
+#define GEN5_TD_GS_EMSK                       0x800c
+#define GEN5_TD_CLIP_EMSK             0x8010
+#define GEN5_TD_SF_EMSK                       0x8014
+#define GEN5_TD_WIZ_EMSK                      0x8018
+#define GEN5_TD_0_6_EHTRG_VAL         0x801c
+#define GEN5_TD_0_7_EHTRG_VAL         0x8020
+#define GEN5_TD_0_6_EHTRG_MSK           0x8024
+#define GEN5_TD_0_7_EHTRG_MSK         0x8028
+#define GEN5_TD_RDATA                 0x802c
+#define GEN5_TD_TS_EMSK                       0x8030
+
+#define GEN5_EU_CTL                   0x8800
+#define GEN5_EU_CTL_SELECT_SHIFT              16
+#define GEN5_EU_CTL_DATA_MUX_SHIFT      8
+#define GEN5_EU_ATT_0                 0x8810
+#define GEN5_EU_ATT_1                 0x8814
+#define GEN5_EU_ATT_DATA_0            0x8820
+#define GEN5_EU_ATT_DATA_1            0x8824
+#define GEN5_EU_ATT_CLR_0             0x8830
+#define GEN5_EU_ATT_CLR_1             0x8834
+#define GEN5_EU_RDATA                 0x8840
+
+/* 3D state:
+ */
+#define _3DOP_3DSTATE_PIPELINED       0x0
+#define _3DOP_3DSTATE_NONPIPELINED    0x1
+#define _3DOP_3DCONTROL               0x2
+#define _3DOP_3DPRIMITIVE             0x3
+
+#define _3DSTATE_PIPELINED_POINTERS       0x00
+#define _3DSTATE_BINDING_TABLE_POINTERS   0x01
+#define _3DSTATE_VERTEX_BUFFERS           0x08
+#define _3DSTATE_VERTEX_ELEMENTS          0x09
+#define _3DSTATE_INDEX_BUFFER             0x0A
+#define _3DSTATE_VF_STATISTICS            0x0B
+#define _3DSTATE_DRAWING_RECTANGLE            0x00
+#define _3DSTATE_CONSTANT_COLOR               0x01
+#define _3DSTATE_SAMPLER_PALETTE_LOAD         0x02
+#define _3DSTATE_CHROMA_KEY                   0x04
+#define _3DSTATE_DEPTH_BUFFER                 0x05
+#define _3DSTATE_POLY_STIPPLE_OFFSET          0x06
+#define _3DSTATE_POLY_STIPPLE_PATTERN         0x07
+#define _3DSTATE_LINE_STIPPLE                 0x08
+#define _3DSTATE_GLOBAL_DEPTH_OFFSET_CLAMP    0x09
+#define _3DCONTROL    0x00
+#define _3DPRIMITIVE  0x00
+
+#define _3DPRIM_POINTLIST         0x01
+#define _3DPRIM_LINELIST          0x02
+#define _3DPRIM_LINESTRIP         0x03
+#define _3DPRIM_TRILIST           0x04
+#define _3DPRIM_TRISTRIP          0x05
+#define _3DPRIM_TRIFAN            0x06
+#define _3DPRIM_QUADLIST          0x07
+#define _3DPRIM_QUADSTRIP         0x08
+#define _3DPRIM_LINELIST_ADJ      0x09
+#define _3DPRIM_LINESTRIP_ADJ     0x0A
+#define _3DPRIM_TRILIST_ADJ       0x0B
+#define _3DPRIM_TRISTRIP_ADJ      0x0C
+#define _3DPRIM_TRISTRIP_REVERSE  0x0D
+#define _3DPRIM_POLYGON           0x0E
+#define _3DPRIM_RECTLIST          0x0F
+#define _3DPRIM_LINELOOP          0x10
+#define _3DPRIM_POINTLIST_BF      0x11
+#define _3DPRIM_LINESTRIP_CONT    0x12
+#define _3DPRIM_LINESTRIP_BF      0x13
+#define _3DPRIM_LINESTRIP_CONT_BF 0x14
+#define _3DPRIM_TRIFAN_NOSTIPPLE  0x15
+
+#define _3DPRIM_VERTEXBUFFER_ACCESS_SEQUENTIAL 0
+#define _3DPRIM_VERTEXBUFFER_ACCESS_RANDOM     1
+
+#define GEN5_ANISORATIO_2     0 
+#define GEN5_ANISORATIO_4     1 
+#define GEN5_ANISORATIO_6     2 
+#define GEN5_ANISORATIO_8     3 
+#define GEN5_ANISORATIO_10    4 
+#define GEN5_ANISORATIO_12    5 
+#define GEN5_ANISORATIO_14    6 
+#define GEN5_ANISORATIO_16    7
+
+#define GEN5_BLENDFACTOR_ONE                 0x1
+#define GEN5_BLENDFACTOR_SRC_COLOR           0x2
+#define GEN5_BLENDFACTOR_SRC_ALPHA           0x3
+#define GEN5_BLENDFACTOR_DST_ALPHA           0x4
+#define GEN5_BLENDFACTOR_DST_COLOR           0x5
+#define GEN5_BLENDFACTOR_SRC_ALPHA_SATURATE  0x6
+#define GEN5_BLENDFACTOR_CONST_COLOR         0x7
+#define GEN5_BLENDFACTOR_CONST_ALPHA         0x8
+#define GEN5_BLENDFACTOR_SRC1_COLOR          0x9
+#define GEN5_BLENDFACTOR_SRC1_ALPHA          0x0A
+#define GEN5_BLENDFACTOR_ZERO                0x11
+#define GEN5_BLENDFACTOR_INV_SRC_COLOR       0x12
+#define GEN5_BLENDFACTOR_INV_SRC_ALPHA       0x13
+#define GEN5_BLENDFACTOR_INV_DST_ALPHA       0x14
+#define GEN5_BLENDFACTOR_INV_DST_COLOR       0x15
+#define GEN5_BLENDFACTOR_INV_CONST_COLOR     0x17
+#define GEN5_BLENDFACTOR_INV_CONST_ALPHA     0x18
+#define GEN5_BLENDFACTOR_INV_SRC1_COLOR      0x19
+#define GEN5_BLENDFACTOR_INV_SRC1_ALPHA      0x1A
+
+#define GEN5_BLENDFUNCTION_ADD               0
+#define GEN5_BLENDFUNCTION_SUBTRACT          1
+#define GEN5_BLENDFUNCTION_REVERSE_SUBTRACT  2
+#define GEN5_BLENDFUNCTION_MIN               3
+#define GEN5_BLENDFUNCTION_MAX               4
+
+#define GEN5_ALPHATEST_FORMAT_UNORM8         0
+#define GEN5_ALPHATEST_FORMAT_FLOAT32        1
+
+#define GEN5_CHROMAKEY_KILL_ON_ANY_MATCH  0
+#define GEN5_CHROMAKEY_REPLACE_BLACK      1
+
+#define GEN5_CLIP_API_OGL     0
+#define GEN5_CLIP_API_DX      1
+
+#define GEN5_CLIPMODE_NORMAL              0
+#define GEN5_CLIPMODE_CLIP_ALL            1
+#define GEN5_CLIPMODE_CLIP_NON_REJECTED   2
+#define GEN5_CLIPMODE_REJECT_ALL          3
+#define GEN5_CLIPMODE_ACCEPT_ALL          4
+
+#define GEN5_CLIP_NDCSPACE     0
+#define GEN5_CLIP_SCREENSPACE  1
+
+#define GEN5_COMPAREFUNCTION_ALWAYS       0
+#define GEN5_COMPAREFUNCTION_NEVER        1
+#define GEN5_COMPAREFUNCTION_LESS         2
+#define GEN5_COMPAREFUNCTION_EQUAL        3
+#define GEN5_COMPAREFUNCTION_LEQUAL       4
+#define GEN5_COMPAREFUNCTION_GREATER      5
+#define GEN5_COMPAREFUNCTION_NOTEQUAL     6
+#define GEN5_COMPAREFUNCTION_GEQUAL       7
+
+#define GEN5_COVERAGE_PIXELS_HALF     0
+#define GEN5_COVERAGE_PIXELS_1        1
+#define GEN5_COVERAGE_PIXELS_2        2
+#define GEN5_COVERAGE_PIXELS_4        3
+
+#define GEN5_CULLMODE_BOTH        0
+#define GEN5_CULLMODE_NONE        1
+#define GEN5_CULLMODE_FRONT       2
+#define GEN5_CULLMODE_BACK        3
+
+#define GEN5_DEFAULTCOLOR_R8G8B8A8_UNORM      0
+#define GEN5_DEFAULTCOLOR_R32G32B32A32_FLOAT  1
+
+#define GEN5_DEPTHFORMAT_D32_FLOAT_S8X24_UINT     0
+#define GEN5_DEPTHFORMAT_D32_FLOAT                1
+#define GEN5_DEPTHFORMAT_D24_UNORM_S8_UINT        2
+#define GEN5_DEPTHFORMAT_D16_UNORM                5
+
+#define GEN5_FLOATING_POINT_IEEE_754        0
+#define GEN5_FLOATING_POINT_NON_IEEE_754    1
+
+#define GEN5_FRONTWINDING_CW      0
+#define GEN5_FRONTWINDING_CCW     1
+
+#define GEN5_INDEX_BYTE     0
+#define GEN5_INDEX_WORD     1
+#define GEN5_INDEX_DWORD    2
+
+#define GEN5_LOGICOPFUNCTION_CLEAR            0
+#define GEN5_LOGICOPFUNCTION_NOR              1
+#define GEN5_LOGICOPFUNCTION_AND_INVERTED     2
+#define GEN5_LOGICOPFUNCTION_COPY_INVERTED    3
+#define GEN5_LOGICOPFUNCTION_AND_REVERSE      4
+#define GEN5_LOGICOPFUNCTION_INVERT           5
+#define GEN5_LOGICOPFUNCTION_XOR              6
+#define GEN5_LOGICOPFUNCTION_NAND             7
+#define GEN5_LOGICOPFUNCTION_AND              8
+#define GEN5_LOGICOPFUNCTION_EQUIV            9
+#define GEN5_LOGICOPFUNCTION_NOOP             10
+#define GEN5_LOGICOPFUNCTION_OR_INVERTED      11
+#define GEN5_LOGICOPFUNCTION_COPY             12
+#define GEN5_LOGICOPFUNCTION_OR_REVERSE       13
+#define GEN5_LOGICOPFUNCTION_OR               14
+#define GEN5_LOGICOPFUNCTION_SET              15  
+
+#define GEN5_MAPFILTER_NEAREST        0x0 
+#define GEN5_MAPFILTER_LINEAR         0x1 
+#define GEN5_MAPFILTER_ANISOTROPIC    0x2
+
+#define GEN5_MIPFILTER_NONE        0   
+#define GEN5_MIPFILTER_NEAREST     1   
+#define GEN5_MIPFILTER_LINEAR      3
+
+#define GEN5_POLYGON_FRONT_FACING     0
+#define GEN5_POLYGON_BACK_FACING      1
+
+#define GEN5_PREFILTER_ALWAYS     0x0 
+#define GEN5_PREFILTER_NEVER      0x1
+#define GEN5_PREFILTER_LESS       0x2
+#define GEN5_PREFILTER_EQUAL      0x3
+#define GEN5_PREFILTER_LEQUAL     0x4
+#define GEN5_PREFILTER_GREATER    0x5
+#define GEN5_PREFILTER_NOTEQUAL   0x6
+#define GEN5_PREFILTER_GEQUAL     0x7
+
+#define GEN5_PROVOKING_VERTEX_0    0
+#define GEN5_PROVOKING_VERTEX_1    1 
+#define GEN5_PROVOKING_VERTEX_2    2
+
+#define GEN5_RASTRULE_UPPER_LEFT  0    
+#define GEN5_RASTRULE_UPPER_RIGHT 1
+
+#define GEN5_RENDERTARGET_CLAMPRANGE_UNORM    0
+#define GEN5_RENDERTARGET_CLAMPRANGE_SNORM    1
+#define GEN5_RENDERTARGET_CLAMPRANGE_FORMAT   2
+
+#define GEN5_STENCILOP_KEEP               0
+#define GEN5_STENCILOP_ZERO               1
+#define GEN5_STENCILOP_REPLACE            2
+#define GEN5_STENCILOP_INCRSAT            3
+#define GEN5_STENCILOP_DECRSAT            4
+#define GEN5_STENCILOP_INCR               5
+#define GEN5_STENCILOP_DECR               6
+#define GEN5_STENCILOP_INVERT             7
+
+#define GEN5_SURFACE_MIPMAPLAYOUT_BELOW   0
+#define GEN5_SURFACE_MIPMAPLAYOUT_RIGHT   1
+
+#define GEN5_SURFACEFORMAT_R32G32B32A32_FLOAT             0x000
+#define GEN5_SURFACEFORMAT_R32G32B32A32_SINT              0x001
+#define GEN5_SURFACEFORMAT_R32G32B32A32_UINT              0x002
+#define GEN5_SURFACEFORMAT_R32G32B32A32_UNORM             0x003
+#define GEN5_SURFACEFORMAT_R32G32B32A32_SNORM             0x004
+#define GEN5_SURFACEFORMAT_R64G64_FLOAT                   0x005
+#define GEN5_SURFACEFORMAT_R32G32B32X32_FLOAT             0x006
+#define GEN5_SURFACEFORMAT_R32G32B32A32_SSCALED           0x007
+#define GEN5_SURFACEFORMAT_R32G32B32A32_USCALED           0x008
+#define GEN5_SURFACEFORMAT_R32G32B32_FLOAT                0x040
+#define GEN5_SURFACEFORMAT_R32G32B32_SINT                 0x041
+#define GEN5_SURFACEFORMAT_R32G32B32_UINT                 0x042
+#define GEN5_SURFACEFORMAT_R32G32B32_UNORM                0x043
+#define GEN5_SURFACEFORMAT_R32G32B32_SNORM                0x044
+#define GEN5_SURFACEFORMAT_R32G32B32_SSCALED              0x045
+#define GEN5_SURFACEFORMAT_R32G32B32_USCALED              0x046
+#define GEN5_SURFACEFORMAT_R16G16B16A16_UNORM             0x080
+#define GEN5_SURFACEFORMAT_R16G16B16A16_SNORM             0x081
+#define GEN5_SURFACEFORMAT_R16G16B16A16_SINT              0x082
+#define GEN5_SURFACEFORMAT_R16G16B16A16_UINT              0x083
+#define GEN5_SURFACEFORMAT_R16G16B16A16_FLOAT             0x084
+#define GEN5_SURFACEFORMAT_R32G32_FLOAT                   0x085
+#define GEN5_SURFACEFORMAT_R32G32_SINT                    0x086
+#define GEN5_SURFACEFORMAT_R32G32_UINT                    0x087
+#define GEN5_SURFACEFORMAT_R32_FLOAT_X8X24_TYPELESS       0x088
+#define GEN5_SURFACEFORMAT_X32_TYPELESS_G8X24_UINT        0x089
+#define GEN5_SURFACEFORMAT_L32A32_FLOAT                   0x08A
+#define GEN5_SURFACEFORMAT_R32G32_UNORM                   0x08B
+#define GEN5_SURFACEFORMAT_R32G32_SNORM                   0x08C
+#define GEN5_SURFACEFORMAT_R64_FLOAT                      0x08D
+#define GEN5_SURFACEFORMAT_R16G16B16X16_UNORM             0x08E
+#define GEN5_SURFACEFORMAT_R16G16B16X16_FLOAT             0x08F
+#define GEN5_SURFACEFORMAT_A32X32_FLOAT                   0x090
+#define GEN5_SURFACEFORMAT_L32X32_FLOAT                   0x091
+#define GEN5_SURFACEFORMAT_I32X32_FLOAT                   0x092
+#define GEN5_SURFACEFORMAT_R16G16B16A16_SSCALED           0x093
+#define GEN5_SURFACEFORMAT_R16G16B16A16_USCALED           0x094
+#define GEN5_SURFACEFORMAT_R32G32_SSCALED                 0x095
+#define GEN5_SURFACEFORMAT_R32G32_USCALED                 0x096
+#define GEN5_SURFACEFORMAT_B8G8R8A8_UNORM                 0x0C0
+#define GEN5_SURFACEFORMAT_B8G8R8A8_UNORM_SRGB            0x0C1
+#define GEN5_SURFACEFORMAT_R10G10B10A2_UNORM              0x0C2
+#define GEN5_SURFACEFORMAT_R10G10B10A2_UNORM_SRGB         0x0C3
+#define GEN5_SURFACEFORMAT_R10G10B10A2_UINT               0x0C4
+#define GEN5_SURFACEFORMAT_R10G10B10_SNORM_A2_UNORM       0x0C5
+#define GEN5_SURFACEFORMAT_R8G8B8A8_UNORM                 0x0C7
+#define GEN5_SURFACEFORMAT_R8G8B8A8_UNORM_SRGB            0x0C8
+#define GEN5_SURFACEFORMAT_R8G8B8A8_SNORM                 0x0C9
+#define GEN5_SURFACEFORMAT_R8G8B8A8_SINT                  0x0CA
+#define GEN5_SURFACEFORMAT_R8G8B8A8_UINT                  0x0CB
+#define GEN5_SURFACEFORMAT_R16G16_UNORM                   0x0CC
+#define GEN5_SURFACEFORMAT_R16G16_SNORM                   0x0CD
+#define GEN5_SURFACEFORMAT_R16G16_SINT                    0x0CE
+#define GEN5_SURFACEFORMAT_R16G16_UINT                    0x0CF
+#define GEN5_SURFACEFORMAT_R16G16_FLOAT                   0x0D0
+#define GEN5_SURFACEFORMAT_B10G10R10A2_UNORM              0x0D1
+#define GEN5_SURFACEFORMAT_B10G10R10A2_UNORM_SRGB         0x0D2
+#define GEN5_SURFACEFORMAT_R11G11B10_FLOAT                0x0D3
+#define GEN5_SURFACEFORMAT_R32_SINT                       0x0D6
+#define GEN5_SURFACEFORMAT_R32_UINT                       0x0D7
+#define GEN5_SURFACEFORMAT_R32_FLOAT                      0x0D8
+#define GEN5_SURFACEFORMAT_R24_UNORM_X8_TYPELESS          0x0D9
+#define GEN5_SURFACEFORMAT_X24_TYPELESS_G8_UINT           0x0DA
+#define GEN5_SURFACEFORMAT_L16A16_UNORM                   0x0DF
+#define GEN5_SURFACEFORMAT_I24X8_UNORM                    0x0E0
+#define GEN5_SURFACEFORMAT_L24X8_UNORM                    0x0E1
+#define GEN5_SURFACEFORMAT_A24X8_UNORM                    0x0E2
+#define GEN5_SURFACEFORMAT_I32_FLOAT                      0x0E3
+#define GEN5_SURFACEFORMAT_L32_FLOAT                      0x0E4
+#define GEN5_SURFACEFORMAT_A32_FLOAT                      0x0E5
+#define GEN5_SURFACEFORMAT_B8G8R8X8_UNORM                 0x0E9
+#define GEN5_SURFACEFORMAT_B8G8R8X8_UNORM_SRGB            0x0EA
+#define GEN5_SURFACEFORMAT_R8G8B8X8_UNORM                 0x0EB
+#define GEN5_SURFACEFORMAT_R8G8B8X8_UNORM_SRGB            0x0EC
+#define GEN5_SURFACEFORMAT_R9G9B9E5_SHAREDEXP             0x0ED
+#define GEN5_SURFACEFORMAT_B10G10R10X2_UNORM              0x0EE
+#define GEN5_SURFACEFORMAT_L16A16_FLOAT                   0x0F0
+#define GEN5_SURFACEFORMAT_R32_UNORM                      0x0F1
+#define GEN5_SURFACEFORMAT_R32_SNORM                      0x0F2
+#define GEN5_SURFACEFORMAT_R10G10B10X2_USCALED            0x0F3
+#define GEN5_SURFACEFORMAT_R8G8B8A8_SSCALED               0x0F4
+#define GEN5_SURFACEFORMAT_R8G8B8A8_USCALED               0x0F5
+#define GEN5_SURFACEFORMAT_R16G16_SSCALED                 0x0F6
+#define GEN5_SURFACEFORMAT_R16G16_USCALED                 0x0F7
+#define GEN5_SURFACEFORMAT_R32_SSCALED                    0x0F8
+#define GEN5_SURFACEFORMAT_R32_USCALED                    0x0F9
+#define GEN5_SURFACEFORMAT_B5G6R5_UNORM                   0x100
+#define GEN5_SURFACEFORMAT_B5G6R5_UNORM_SRGB              0x101
+#define GEN5_SURFACEFORMAT_B5G5R5A1_UNORM                 0x102
+#define GEN5_SURFACEFORMAT_B5G5R5A1_UNORM_SRGB            0x103
+#define GEN5_SURFACEFORMAT_B4G4R4A4_UNORM                 0x104
+#define GEN5_SURFACEFORMAT_B4G4R4A4_UNORM_SRGB            0x105
+#define GEN5_SURFACEFORMAT_R8G8_UNORM                     0x106
+#define GEN5_SURFACEFORMAT_R8G8_SNORM                     0x107
+#define GEN5_SURFACEFORMAT_R8G8_SINT                      0x108
+#define GEN5_SURFACEFORMAT_R8G8_UINT                      0x109
+#define GEN5_SURFACEFORMAT_R16_UNORM                      0x10A
+#define GEN5_SURFACEFORMAT_R16_SNORM                      0x10B
+#define GEN5_SURFACEFORMAT_R16_SINT                       0x10C
+#define GEN5_SURFACEFORMAT_R16_UINT                       0x10D
+#define GEN5_SURFACEFORMAT_R16_FLOAT                      0x10E
+#define GEN5_SURFACEFORMAT_I16_UNORM                      0x111
+#define GEN5_SURFACEFORMAT_L16_UNORM                      0x112
+#define GEN5_SURFACEFORMAT_A16_UNORM                      0x113
+#define GEN5_SURFACEFORMAT_L8A8_UNORM                     0x114
+#define GEN5_SURFACEFORMAT_I16_FLOAT                      0x115
+#define GEN5_SURFACEFORMAT_L16_FLOAT                      0x116
+#define GEN5_SURFACEFORMAT_A16_FLOAT                      0x117
+#define GEN5_SURFACEFORMAT_R5G5_SNORM_B6_UNORM            0x119
+#define GEN5_SURFACEFORMAT_B5G5R5X1_UNORM                 0x11A
+#define GEN5_SURFACEFORMAT_B5G5R5X1_UNORM_SRGB            0x11B
+#define GEN5_SURFACEFORMAT_R8G8_SSCALED                   0x11C
+#define GEN5_SURFACEFORMAT_R8G8_USCALED                   0x11D
+#define GEN5_SURFACEFORMAT_R16_SSCALED                    0x11E
+#define GEN5_SURFACEFORMAT_R16_USCALED                    0x11F
+#define GEN5_SURFACEFORMAT_R8_UNORM                       0x140
+#define GEN5_SURFACEFORMAT_R8_SNORM                       0x141
+#define GEN5_SURFACEFORMAT_R8_SINT                        0x142
+#define GEN5_SURFACEFORMAT_R8_UINT                        0x143
+#define GEN5_SURFACEFORMAT_A8_UNORM                       0x144
+#define GEN5_SURFACEFORMAT_I8_UNORM                       0x145
+#define GEN5_SURFACEFORMAT_L8_UNORM                       0x146
+#define GEN5_SURFACEFORMAT_P4A4_UNORM                     0x147
+#define GEN5_SURFACEFORMAT_A4P4_UNORM                     0x148
+#define GEN5_SURFACEFORMAT_R8_SSCALED                     0x149
+#define GEN5_SURFACEFORMAT_R8_USCALED                     0x14A
+#define GEN5_SURFACEFORMAT_R1_UINT                        0x181
+#define GEN5_SURFACEFORMAT_YCRCB_NORMAL                   0x182
+#define GEN5_SURFACEFORMAT_YCRCB_SWAPUVY                  0x183
+#define GEN5_SURFACEFORMAT_BC1_UNORM                      0x186
+#define GEN5_SURFACEFORMAT_BC2_UNORM                      0x187
+#define GEN5_SURFACEFORMAT_BC3_UNORM                      0x188
+#define GEN5_SURFACEFORMAT_BC4_UNORM                      0x189
+#define GEN5_SURFACEFORMAT_BC5_UNORM                      0x18A
+#define GEN5_SURFACEFORMAT_BC1_UNORM_SRGB                 0x18B
+#define GEN5_SURFACEFORMAT_BC2_UNORM_SRGB                 0x18C
+#define GEN5_SURFACEFORMAT_BC3_UNORM_SRGB                 0x18D
+#define GEN5_SURFACEFORMAT_MONO8                          0x18E
+#define GEN5_SURFACEFORMAT_YCRCB_SWAPUV                   0x18F
+#define GEN5_SURFACEFORMAT_YCRCB_SWAPY                    0x190
+#define GEN5_SURFACEFORMAT_DXT1_RGB                       0x191
+#define GEN5_SURFACEFORMAT_FXT1                           0x192
+#define GEN5_SURFACEFORMAT_R8G8B8_UNORM                   0x193
+#define GEN5_SURFACEFORMAT_R8G8B8_SNORM                   0x194
+#define GEN5_SURFACEFORMAT_R8G8B8_SSCALED                 0x195
+#define GEN5_SURFACEFORMAT_R8G8B8_USCALED                 0x196
+#define GEN5_SURFACEFORMAT_R64G64B64A64_FLOAT             0x197
+#define GEN5_SURFACEFORMAT_R64G64B64_FLOAT                0x198
+#define GEN5_SURFACEFORMAT_BC4_SNORM                      0x199
+#define GEN5_SURFACEFORMAT_BC5_SNORM                      0x19A
+#define GEN5_SURFACEFORMAT_R16G16B16_UNORM                0x19C
+#define GEN5_SURFACEFORMAT_R16G16B16_SNORM                0x19D
+#define GEN5_SURFACEFORMAT_R16G16B16_SSCALED              0x19E
+#define GEN5_SURFACEFORMAT_R16G16B16_USCALED              0x19F
+
+#define GEN5_SURFACERETURNFORMAT_FLOAT32  0
+#define GEN5_SURFACERETURNFORMAT_S1       1
+
+#define GEN5_SURFACE_1D      0
+#define GEN5_SURFACE_2D      1
+#define GEN5_SURFACE_3D      2
+#define GEN5_SURFACE_CUBE    3
+#define GEN5_SURFACE_BUFFER  4
+#define GEN5_SURFACE_NULL    7
+
+#define GEN5_BORDER_COLOR_MODE_DEFAULT 0
+#define GEN5_BORDER_COLOR_MODE_LEGACY  1
+
+#define GEN5_TEXCOORDMODE_WRAP            0
+#define GEN5_TEXCOORDMODE_MIRROR          1
+#define GEN5_TEXCOORDMODE_CLAMP           2
+#define GEN5_TEXCOORDMODE_CUBE            3
+#define GEN5_TEXCOORDMODE_CLAMP_BORDER    4
+#define GEN5_TEXCOORDMODE_MIRROR_ONCE     5
+
+#define GEN5_THREAD_PRIORITY_NORMAL   0
+#define GEN5_THREAD_PRIORITY_HIGH     1
+
+#define GEN5_TILEWALK_XMAJOR                 0
+#define GEN5_TILEWALK_YMAJOR                 1
+
+#define GEN5_VERTEX_SUBPIXEL_PRECISION_8BITS  0
+#define GEN5_VERTEX_SUBPIXEL_PRECISION_4BITS  1
+
+#define GEN5_VERTEXBUFFER_ACCESS_VERTEXDATA     0
+#define GEN5_VERTEXBUFFER_ACCESS_INSTANCEDATA   1
+
+#define GEN5_VFCOMPONENT_NOSTORE      0
+#define GEN5_VFCOMPONENT_STORE_SRC    1
+#define GEN5_VFCOMPONENT_STORE_0      2
+#define GEN5_VFCOMPONENT_STORE_1_FLT  3
+#define GEN5_VFCOMPONENT_STORE_1_INT  4
+#define GEN5_VFCOMPONENT_STORE_VID    5
+#define GEN5_VFCOMPONENT_STORE_IID    6
+#define GEN5_VFCOMPONENT_STORE_PID    7
+
+
+
+/* Execution Unit (EU) defines
+ */
+
+#define GEN5_ALIGN_1   0
+#define GEN5_ALIGN_16  1
+
+#define GEN5_ADDRESS_DIRECT                        0
+#define GEN5_ADDRESS_REGISTER_INDIRECT_REGISTER    1
+
+#define GEN5_CHANNEL_X     0
+#define GEN5_CHANNEL_Y     1
+#define GEN5_CHANNEL_Z     2
+#define GEN5_CHANNEL_W     3
+
+#define GEN5_COMPRESSION_NONE          0
+#define GEN5_COMPRESSION_2NDHALF       1
+#define GEN5_COMPRESSION_COMPRESSED    2
+
+#define GEN5_CONDITIONAL_NONE  0
+#define GEN5_CONDITIONAL_Z     1
+#define GEN5_CONDITIONAL_NZ    2
+#define GEN5_CONDITIONAL_EQ    1       /* Z */
+#define GEN5_CONDITIONAL_NEQ   2       /* NZ */
+#define GEN5_CONDITIONAL_G     3
+#define GEN5_CONDITIONAL_GE    4
+#define GEN5_CONDITIONAL_L     5
+#define GEN5_CONDITIONAL_LE    6
+#define GEN5_CONDITIONAL_C     7
+#define GEN5_CONDITIONAL_O     8
+
+#define GEN5_DEBUG_NONE        0
+#define GEN5_DEBUG_BREAKPOINT  1
+
+#define GEN5_DEPENDENCY_NORMAL         0
+#define GEN5_DEPENDENCY_NOTCLEARED     1
+#define GEN5_DEPENDENCY_NOTCHECKED     2
+#define GEN5_DEPENDENCY_DISABLE        3
+
+#define GEN5_EXECUTE_1     0
+#define GEN5_EXECUTE_2     1
+#define GEN5_EXECUTE_4     2
+#define GEN5_EXECUTE_8     3
+#define GEN5_EXECUTE_16    4
+#define GEN5_EXECUTE_32    5
+
+#define GEN5_HORIZONTAL_STRIDE_0   0
+#define GEN5_HORIZONTAL_STRIDE_1   1
+#define GEN5_HORIZONTAL_STRIDE_2   2
+#define GEN5_HORIZONTAL_STRIDE_4   3
+
+#define GEN5_INSTRUCTION_NORMAL    0
+#define GEN5_INSTRUCTION_SATURATE  1
+
+#define GEN5_MASK_ENABLE   0
+#define GEN5_MASK_DISABLE  1
+
+#define GEN5_OPCODE_MOV        1
+#define GEN5_OPCODE_SEL        2
+#define GEN5_OPCODE_NOT        4
+#define GEN5_OPCODE_AND        5
+#define GEN5_OPCODE_OR         6
+#define GEN5_OPCODE_XOR        7
+#define GEN5_OPCODE_SHR        8
+#define GEN5_OPCODE_SHL        9
+#define GEN5_OPCODE_RSR        10
+#define GEN5_OPCODE_RSL        11
+#define GEN5_OPCODE_ASR        12
+#define GEN5_OPCODE_CMP        16
+#define GEN5_OPCODE_JMPI       32
+#define GEN5_OPCODE_IF         34
+#define GEN5_OPCODE_IFF        35
+#define GEN5_OPCODE_ELSE       36
+#define GEN5_OPCODE_ENDIF      37
+#define GEN5_OPCODE_DO         38
+#define GEN5_OPCODE_WHILE      39
+#define GEN5_OPCODE_BREAK      40
+#define GEN5_OPCODE_CONTINUE   41
+#define GEN5_OPCODE_HALT       42
+#define GEN5_OPCODE_MSAVE      44
+#define GEN5_OPCODE_MRESTORE   45
+#define GEN5_OPCODE_PUSH       46
+#define GEN5_OPCODE_POP        47
+#define GEN5_OPCODE_WAIT       48
+#define GEN5_OPCODE_SEND       49
+#define GEN5_OPCODE_ADD        64
+#define GEN5_OPCODE_MUL        65
+#define GEN5_OPCODE_AVG        66
+#define GEN5_OPCODE_FRC        67
+#define GEN5_OPCODE_RNDU       68
+#define GEN5_OPCODE_RNDD       69
+#define GEN5_OPCODE_RNDE       70
+#define GEN5_OPCODE_RNDZ       71
+#define GEN5_OPCODE_MAC        72
+#define GEN5_OPCODE_MACH       73
+#define GEN5_OPCODE_LZD        74
+#define GEN5_OPCODE_SAD2       80
+#define GEN5_OPCODE_SADA2      81
+#define GEN5_OPCODE_DP4        84
+#define GEN5_OPCODE_DPH        85
+#define GEN5_OPCODE_DP3        86
+#define GEN5_OPCODE_DP2        87
+#define GEN5_OPCODE_DPA2       88
+#define GEN5_OPCODE_LINE       89
+#define GEN5_OPCODE_NOP        126
+
+#define GEN5_PREDICATE_NONE             0
+#define GEN5_PREDICATE_NORMAL           1
+#define GEN5_PREDICATE_ALIGN1_ANYV             2
+#define GEN5_PREDICATE_ALIGN1_ALLV             3
+#define GEN5_PREDICATE_ALIGN1_ANY2H            4
+#define GEN5_PREDICATE_ALIGN1_ALL2H            5
+#define GEN5_PREDICATE_ALIGN1_ANY4H            6
+#define GEN5_PREDICATE_ALIGN1_ALL4H            7
+#define GEN5_PREDICATE_ALIGN1_ANY8H            8
+#define GEN5_PREDICATE_ALIGN1_ALL8H            9
+#define GEN5_PREDICATE_ALIGN1_ANY16H           10
+#define GEN5_PREDICATE_ALIGN1_ALL16H           11
+#define GEN5_PREDICATE_ALIGN16_REPLICATE_X     2
+#define GEN5_PREDICATE_ALIGN16_REPLICATE_Y     3
+#define GEN5_PREDICATE_ALIGN16_REPLICATE_Z     4
+#define GEN5_PREDICATE_ALIGN16_REPLICATE_W     5
+#define GEN5_PREDICATE_ALIGN16_ANY4H           6
+#define GEN5_PREDICATE_ALIGN16_ALL4H           7
+
+#define GEN5_ARCHITECTURE_REGISTER_FILE    0
+#define GEN5_GENERAL_REGISTER_FILE         1
+#define GEN5_MESSAGE_REGISTER_FILE         2
+#define GEN5_IMMEDIATE_VALUE               3
+
+#define GEN5_REGISTER_TYPE_UD  0
+#define GEN5_REGISTER_TYPE_D   1
+#define GEN5_REGISTER_TYPE_UW  2
+#define GEN5_REGISTER_TYPE_W   3
+#define GEN5_REGISTER_TYPE_UB  4
+#define GEN5_REGISTER_TYPE_B   5
+#define GEN5_REGISTER_TYPE_VF  5       /* packed float vector, immediates only? */
+#define GEN5_REGISTER_TYPE_HF  6
+#define GEN5_REGISTER_TYPE_V   6       /* packed int vector, immediates only, uword dest only */
+#define GEN5_REGISTER_TYPE_F   7
+
+#define GEN5_ARF_NULL                  0x00
+#define GEN5_ARF_ADDRESS               0x10
+#define GEN5_ARF_ACCUMULATOR           0x20   
+#define GEN5_ARF_FLAG                  0x30
+#define GEN5_ARF_MASK                  0x40
+#define GEN5_ARF_MASK_STACK            0x50
+#define GEN5_ARF_MASK_STACK_DEPTH      0x60
+#define GEN5_ARF_STATE                 0x70
+#define GEN5_ARF_CONTROL               0x80
+#define GEN5_ARF_NOTIFICATION_COUNT    0x90
+#define GEN5_ARF_IP                    0xA0
+
+#define GEN5_AMASK   0
+#define GEN5_IMASK   1
+#define GEN5_LMASK   2
+#define GEN5_CMASK   3
+
+
+
+#define GEN5_THREAD_NORMAL     0
+#define GEN5_THREAD_ATOMIC     1
+#define GEN5_THREAD_SWITCH     2
+
+#define GEN5_VERTICAL_STRIDE_0                 0
+#define GEN5_VERTICAL_STRIDE_1                 1
+#define GEN5_VERTICAL_STRIDE_2                 2
+#define GEN5_VERTICAL_STRIDE_4                 3
+#define GEN5_VERTICAL_STRIDE_8                 4
+#define GEN5_VERTICAL_STRIDE_16                5
+#define GEN5_VERTICAL_STRIDE_32                6
+#define GEN5_VERTICAL_STRIDE_64                7
+#define GEN5_VERTICAL_STRIDE_128               8
+#define GEN5_VERTICAL_STRIDE_256               9
+#define GEN5_VERTICAL_STRIDE_ONE_DIMENSIONAL   0xF
+
+#define GEN5_WIDTH_1       0
+#define GEN5_WIDTH_2       1
+#define GEN5_WIDTH_4       2
+#define GEN5_WIDTH_8       3
+#define GEN5_WIDTH_16      4
+
+#define GEN5_STATELESS_BUFFER_BOUNDARY_1K      0
+#define GEN5_STATELESS_BUFFER_BOUNDARY_2K      1
+#define GEN5_STATELESS_BUFFER_BOUNDARY_4K      2
+#define GEN5_STATELESS_BUFFER_BOUNDARY_8K      3
+#define GEN5_STATELESS_BUFFER_BOUNDARY_16K     4
+#define GEN5_STATELESS_BUFFER_BOUNDARY_32K     5
+#define GEN5_STATELESS_BUFFER_BOUNDARY_64K     6
+#define GEN5_STATELESS_BUFFER_BOUNDARY_128K    7
+#define GEN5_STATELESS_BUFFER_BOUNDARY_256K    8
+#define GEN5_STATELESS_BUFFER_BOUNDARY_512K    9
+#define GEN5_STATELESS_BUFFER_BOUNDARY_1M      10
+#define GEN5_STATELESS_BUFFER_BOUNDARY_2M      11
+
+#define GEN5_POLYGON_FACING_FRONT      0
+#define GEN5_POLYGON_FACING_BACK       1
+
+#define GEN5_MESSAGE_TARGET_NULL               0
+#define GEN5_MESSAGE_TARGET_MATH               1
+#define GEN5_MESSAGE_TARGET_SAMPLER            2
+#define GEN5_MESSAGE_TARGET_GATEWAY            3
+#define GEN5_MESSAGE_TARGET_DATAPORT_READ      4
+#define GEN5_MESSAGE_TARGET_DATAPORT_WRITE     5
+#define GEN5_MESSAGE_TARGET_URB                6
+#define GEN5_MESSAGE_TARGET_THREAD_SPAWNER     7
+
+#define GEN5_SAMPLER_RETURN_FORMAT_FLOAT32     0
+#define GEN5_SAMPLER_RETURN_FORMAT_UINT32      2
+#define GEN5_SAMPLER_RETURN_FORMAT_SINT32      3
+
+#define GEN5_SAMPLER_MESSAGE_SIMD8_SAMPLE              0
+#define GEN5_SAMPLER_MESSAGE_SIMD16_SAMPLE             0
+#define GEN5_SAMPLER_MESSAGE_SIMD16_SAMPLE_BIAS        0
+#define GEN5_SAMPLER_MESSAGE_SIMD8_KILLPIX             1
+#define GEN5_SAMPLER_MESSAGE_SIMD4X2_SAMPLE_LOD        1
+#define GEN5_SAMPLER_MESSAGE_SIMD16_SAMPLE_LOD         1
+#define GEN5_SAMPLER_MESSAGE_SIMD4X2_SAMPLE_GRADIENTS  2
+#define GEN5_SAMPLER_MESSAGE_SIMD8_SAMPLE_GRADIENTS    2
+#define GEN5_SAMPLER_MESSAGE_SIMD4X2_SAMPLE_COMPARE    0
+#define GEN5_SAMPLER_MESSAGE_SIMD16_SAMPLE_COMPARE     2
+#define GEN5_SAMPLER_MESSAGE_SIMD4X2_RESINFO           2
+#define GEN5_SAMPLER_MESSAGE_SIMD8_RESINFO             2
+#define GEN5_SAMPLER_MESSAGE_SIMD16_RESINFO            2
+#define GEN5_SAMPLER_MESSAGE_SIMD4X2_LD                3
+#define GEN5_SAMPLER_MESSAGE_SIMD8_LD                  3
+#define GEN5_SAMPLER_MESSAGE_SIMD16_LD                 3
+
+#define GEN5_DATAPORT_OWORD_BLOCK_1_OWORDLOW   0
+#define GEN5_DATAPORT_OWORD_BLOCK_1_OWORDHIGH  1
+#define GEN5_DATAPORT_OWORD_BLOCK_2_OWORDS     2
+#define GEN5_DATAPORT_OWORD_BLOCK_4_OWORDS     3
+#define GEN5_DATAPORT_OWORD_BLOCK_8_OWORDS     4
+
+#define GEN5_DATAPORT_OWORD_DUAL_BLOCK_1OWORD     0
+#define GEN5_DATAPORT_OWORD_DUAL_BLOCK_4OWORDS    2
+
+#define GEN5_DATAPORT_DWORD_SCATTERED_BLOCK_8DWORDS   2
+#define GEN5_DATAPORT_DWORD_SCATTERED_BLOCK_16DWORDS  3
+
+#define GEN5_DATAPORT_READ_MESSAGE_OWORD_BLOCK_READ          0
+#define GEN5_DATAPORT_READ_MESSAGE_OWORD_DUAL_BLOCK_READ     1
+#define GEN5_DATAPORT_READ_MESSAGE_DWORD_BLOCK_READ          2
+#define GEN5_DATAPORT_READ_MESSAGE_DWORD_SCATTERED_READ      3
+
+#define GEN5_DATAPORT_READ_TARGET_DATA_CACHE      0
+#define GEN5_DATAPORT_READ_TARGET_RENDER_CACHE    1
+#define GEN5_DATAPORT_READ_TARGET_SAMPLER_CACHE   2
+
+#define GEN5_DATAPORT_RENDER_TARGET_WRITE_SIMD16_SINGLE_SOURCE                0
+#define GEN5_DATAPORT_RENDER_TARGET_WRITE_SIMD16_SINGLE_SOURCE_REPLICATED     1
+#define GEN5_DATAPORT_RENDER_TARGET_WRITE_SIMD8_DUAL_SOURCE_SUBSPAN01         2
+#define GEN5_DATAPORT_RENDER_TARGET_WRITE_SIMD8_DUAL_SOURCE_SUBSPAN23         3
+#define GEN5_DATAPORT_RENDER_TARGET_WRITE_SIMD8_SINGLE_SOURCE_SUBSPAN01       4
+
+#define GEN5_DATAPORT_WRITE_MESSAGE_OWORD_BLOCK_WRITE                0
+#define GEN5_DATAPORT_WRITE_MESSAGE_OWORD_DUAL_BLOCK_WRITE           1
+#define GEN5_DATAPORT_WRITE_MESSAGE_DWORD_BLOCK_WRITE                2
+#define GEN5_DATAPORT_WRITE_MESSAGE_DWORD_SCATTERED_WRITE            3
+#define GEN5_DATAPORT_WRITE_MESSAGE_RENDER_TARGET_WRITE              4
+#define GEN5_DATAPORT_WRITE_MESSAGE_STREAMED_VERTEX_BUFFER_WRITE     5
+#define GEN5_DATAPORT_WRITE_MESSAGE_FLUSH_RENDER_CACHE               7
+
+#define GEN5_MATH_FUNCTION_INV                              1
+#define GEN5_MATH_FUNCTION_LOG                              2
+#define GEN5_MATH_FUNCTION_EXP                              3
+#define GEN5_MATH_FUNCTION_SQRT                             4
+#define GEN5_MATH_FUNCTION_RSQ                              5
+#define GEN5_MATH_FUNCTION_SIN                              6 /* was 7 */
+#define GEN5_MATH_FUNCTION_COS                              7 /* was 8 */
+#define GEN5_MATH_FUNCTION_SINCOS                           8 /* was 6 */
+#define GEN5_MATH_FUNCTION_TAN                              9
+#define GEN5_MATH_FUNCTION_POW                              10
+#define GEN5_MATH_FUNCTION_INT_DIV_QUOTIENT_AND_REMAINDER   11
+#define GEN5_MATH_FUNCTION_INT_DIV_QUOTIENT                 12
+#define GEN5_MATH_FUNCTION_INT_DIV_REMAINDER                13
+
+#define GEN5_MATH_INTEGER_UNSIGNED     0
+#define GEN5_MATH_INTEGER_SIGNED       1
+
+#define GEN5_MATH_PRECISION_FULL        0
+#define GEN5_MATH_PRECISION_PARTIAL     1
+
+#define GEN5_MATH_SATURATE_NONE         0
+#define GEN5_MATH_SATURATE_SATURATE     1
+
+#define GEN5_MATH_DATA_VECTOR  0
+#define GEN5_MATH_DATA_SCALAR  1
+
+#define GEN5_URB_OPCODE_WRITE  0
+
+#define GEN5_URB_SWIZZLE_NONE          0
+#define GEN5_URB_SWIZZLE_INTERLEAVE    1
+#define GEN5_URB_SWIZZLE_TRANSPOSE     2
+
+#define GEN5_SCRATCH_SPACE_SIZE_1K     0
+#define GEN5_SCRATCH_SPACE_SIZE_2K     1
+#define GEN5_SCRATCH_SPACE_SIZE_4K     2
+#define GEN5_SCRATCH_SPACE_SIZE_8K     3
+#define GEN5_SCRATCH_SPACE_SIZE_16K    4
+#define GEN5_SCRATCH_SPACE_SIZE_32K    5
+#define GEN5_SCRATCH_SPACE_SIZE_64K    6
+#define GEN5_SCRATCH_SPACE_SIZE_128K   7
+#define GEN5_SCRATCH_SPACE_SIZE_256K   8
+#define GEN5_SCRATCH_SPACE_SIZE_512K   9
+#define GEN5_SCRATCH_SPACE_SIZE_1M     10
+#define GEN5_SCRATCH_SPACE_SIZE_2M     11
+
+
+
+
+#define CMD_URB_FENCE                 0x6000
+#define CMD_CONST_BUFFER_STATE        0x6001
+#define CMD_CONST_BUFFER              0x6002
+
+#define CMD_STATE_BASE_ADDRESS        0x6101
+#define CMD_STATE_INSN_POINTER        0x6102
+#define CMD_PIPELINE_SELECT           0x6104
+
+#define CMD_PIPELINED_STATE_POINTERS  0x7800
+#define CMD_BINDING_TABLE_PTRS        0x7801
+#define CMD_VERTEX_BUFFER             0x7808
+#define CMD_VERTEX_ELEMENT            0x7809
+#define CMD_INDEX_BUFFER              0x780a
+#define CMD_VF_STATISTICS             0x780b
+
+#define CMD_DRAW_RECT                 0x7900
+#define CMD_BLEND_CONSTANT_COLOR      0x7901
+#define CMD_CHROMA_KEY                0x7904
+#define CMD_DEPTH_BUFFER              0x7905
+#define CMD_POLY_STIPPLE_OFFSET       0x7906
+#define CMD_POLY_STIPPLE_PATTERN      0x7907
+#define CMD_LINE_STIPPLE_PATTERN      0x7908
+#define CMD_GLOBAL_DEPTH_OFFSET_CLAMP 0x7908
+
+#define CMD_PIPE_CONTROL              0x7a00
+
+#define CMD_3D_PRIM                   0x7b00
+
+#define CMD_MI_FLUSH                  0x0200
+
+
+/* Various values from the R0 vertex header:
+ */
+#define R02_PRIM_END    0x1
+#define R02_PRIM_START  0x2
+
+/* media pipeline */
+
+#define GEN5_VFE_MODE_GENERIC          0x0
+#define GEN5_VFE_MODE_VLD_MPEG2                0x1
+#define GEN5_VFE_MODE_IS                       0x2
+#define GEN5_VFE_MODE_AVC_MC           0x4
+#define GEN5_VFE_MODE_AVC_IT           0x7
+#define GEN5_VFE_MODE_VC1_IT           0xB
+
+#define GEN5_VFE_DEBUG_COUNTER_FREE    0
+#define GEN5_VFE_DEBUG_COUNTER_FROZEN  1
+#define GEN5_VFE_DEBUG_COUNTER_ONCE    2
+#define GEN5_VFE_DEBUG_COUNTER_ALWAYS  3
+
+/* VLD_STATE */
+#define GEN5_MPEG_TOP_FIELD            1
+#define GEN5_MPEG_BOTTOM_FIELD         2
+#define GEN5_MPEG_FRAME                        3
+#define GEN5_MPEG_QSCALE_LINEAR                0
+#define GEN5_MPEG_QSCALE_NONLINEAR     1
+#define GEN5_MPEG_ZIGZAG_SCAN          0
+#define GEN5_MPEG_ALTER_VERTICAL_SCAN  1
+#define GEN5_MPEG_I_PICTURE            1
+#define GEN5_MPEG_P_PICTURE            2
+#define GEN5_MPEG_B_PICTURE            3
+
+/* Command packets:
+ */
+struct header
+{
+   unsigned int length:16;
+   unsigned int opcode:16;
+};
+
+
+union header_union
+{
+   struct header bits;
+   unsigned int dword;
+};
+
+struct gen5_3d_control
+{   
+   struct 
+   {
+      unsigned int length:8;
+      unsigned int notify_enable:1;
+      unsigned int pad:3;
+      unsigned int wc_flush_enable:1; 
+      unsigned int depth_stall_enable:1; 
+      unsigned int operation:2; 
+      unsigned int opcode:16; 
+   } header;
+   
+   struct
+   {
+      unsigned int pad:2;
+      unsigned int dest_addr_type:1; 
+      unsigned int dest_addr:29; 
+   } dest;
+   
+   unsigned int dword2;   
+   unsigned int dword3;   
+};
+
+
+struct gen5_3d_primitive
+{
+   struct
+   {
+      unsigned int length:8; 
+      unsigned int pad:2;
+      unsigned int topology:5; 
+      unsigned int indexed:1; 
+      unsigned int opcode:16; 
+   } header;
+
+   unsigned int verts_per_instance;  
+   unsigned int start_vert_location;  
+   unsigned int instance_count;  
+   unsigned int start_instance_location;  
+   unsigned int base_vert_location;  
+};
+
+/* These seem to be passed around as function args, so it works out
+ * better to keep them as #defines:
+ */
+#define GEN5_FLUSH_READ_CACHE           0x1
+#define GEN5_FLUSH_STATE_CACHE          0x2
+#define GEN5_INHIBIT_FLUSH_RENDER_CACHE 0x4
+#define GEN5_FLUSH_SNAPSHOT_COUNTERS    0x8
+
+struct gen5_mi_flush
+{
+   unsigned int flags:4;
+   unsigned int pad:12;
+   unsigned int opcode:16;
+};
+
+struct gen5_vf_statistics
+{
+   unsigned int statistics_enable:1;
+   unsigned int pad:15;
+   unsigned int opcode:16;
+};
+
+
+
+struct gen5_binding_table_pointers
+{
+   struct header header;
+   unsigned int vs; 
+   unsigned int gs; 
+   unsigned int clp; 
+   unsigned int sf; 
+   unsigned int wm; 
+};
+
+
+struct gen5_blend_constant_color
+{
+   struct header header;
+   float blend_constant_color[4];  
+};
+
+
+struct gen5_depthbuffer
+{
+   union header_union header;
+   
+   union {
+      struct {
+        unsigned int pitch:18; 
+        unsigned int format:3; 
+        unsigned int pad:4;
+        unsigned int depth_offset_disable:1; 
+        unsigned int tile_walk:1; 
+        unsigned int tiled_surface:1; 
+        unsigned int pad2:1;
+        unsigned int surface_type:3; 
+      } bits;
+      unsigned int dword;
+   } dword1;
+   
+   unsigned int dword2_base_addr; 
+   union {
+      struct {
+        unsigned int pad:1;
+        unsigned int mipmap_layout:1; 
+        unsigned int lod:4; 
+        unsigned int width:13; 
+        unsigned int height:13; 
+      } bits;
+      unsigned int dword;
+   } dword3;
+
+   union {
+      struct {
+        unsigned int pad:12;
+        unsigned int min_array_element:9; 
+        unsigned int depth:11; 
+      } bits;
+      unsigned int dword;
+   } dword4;
+};
+
+struct gen5_drawrect
+{
+   struct header header;
+   unsigned int xmin:16; 
+   unsigned int ymin:16; 
+   unsigned int xmax:16; 
+   unsigned int ymax:16; 
+   unsigned int xorg:16;  
+   unsigned int yorg:16;  
+};
+
+
+
+
+struct gen5_global_depth_offset_clamp
+{
+   struct header header;
+   float depth_offset_clamp;  
+};
+
+struct gen5_indexbuffer
+{   
+   union {
+      struct
+      {
+        unsigned int length:8; 
+        unsigned int index_format:2; 
+        unsigned int cut_index_enable:1; 
+        unsigned int pad:5; 
+        unsigned int opcode:16; 
+      } bits;
+      unsigned int dword;
+
+   } header;
+
+   unsigned int buffer_start; 
+   unsigned int buffer_end; 
+};
+
+
+struct gen5_line_stipple
+{   
+   struct header header;
+  
+   struct
+   {
+      unsigned int pattern:16; 
+      unsigned int pad:16;
+   } bits0;
+   
+   struct
+   {
+      unsigned int repeat_count:9; 
+      unsigned int pad:7;
+      unsigned int inverse_repeat_count:16; 
+   } bits1;
+};
+
+
+struct gen5_pipelined_state_pointers
+{
+   struct header header;
+   
+   struct {
+      unsigned int pad:5;
+      unsigned int offset:27; 
+   } vs;
+   
+   struct
+   {
+      unsigned int enable:1;
+      unsigned int pad:4;
+      unsigned int offset:27; 
+   } gs;
+   
+   struct
+   {
+      unsigned int enable:1;
+      unsigned int pad:4;
+      unsigned int offset:27; 
+   } clp;
+   
+   struct
+   {
+      unsigned int pad:5;
+      unsigned int offset:27; 
+   } sf;
+
+   struct
+   {
+      unsigned int pad:5;
+      unsigned int offset:27; 
+   } wm;
+   
+   struct
+   {
+      unsigned int pad:5;
+      unsigned int offset:27; /* KW: check me! */
+   } cc;
+};
+
+
+struct gen5_polygon_stipple_offset
+{
+   struct header header;
+
+   struct {
+      unsigned int y_offset:5; 
+      unsigned int pad:3;
+      unsigned int x_offset:5; 
+      unsigned int pad0:19;
+   } bits0;
+};
+
+
+
+struct gen5_polygon_stipple
+{
+   struct header header;
+   unsigned int stipple[32];
+};
+
+
+
+struct gen5_pipeline_select
+{
+   struct
+   {
+      unsigned int pipeline_select:1;   
+      unsigned int pad:15;
+      unsigned int opcode:16;   
+   } header;
+};
+
+
+struct gen5_pipe_control
+{
+   struct
+   {
+      unsigned int length:8;
+      unsigned int notify_enable:1;
+      unsigned int pad:2;
+      unsigned int instruction_state_cache_flush_enable:1;
+      unsigned int write_cache_flush_enable:1;
+      unsigned int depth_stall_enable:1;
+      unsigned int post_sync_operation:2;
+
+      unsigned int opcode:16;
+   } header;
+
+   struct
+   {
+      unsigned int pad:2;
+      unsigned int dest_addr_type:1;
+      unsigned int dest_addr:29;
+   } bits1;
+
+   unsigned int data0;
+   unsigned int data1;
+};
+
+
+struct gen5_urb_fence
+{
+   struct
+   {
+      unsigned int length:8;   
+      unsigned int vs_realloc:1;   
+      unsigned int gs_realloc:1;   
+      unsigned int clp_realloc:1;   
+      unsigned int sf_realloc:1;   
+      unsigned int vfe_realloc:1;   
+      unsigned int cs_realloc:1;   
+      unsigned int pad:2;
+      unsigned int opcode:16;   
+   } header;
+
+   struct
+   {
+      unsigned int vs_fence:10;  
+      unsigned int gs_fence:10;  
+      unsigned int clp_fence:10;  
+      unsigned int pad:2;
+   } bits0;
+
+   struct
+   {
+      unsigned int sf_fence:10;  
+      unsigned int vf_fence:10;  
+      unsigned int cs_fence:10;  
+      unsigned int pad:2;
+   } bits1;
+};
+
+struct gen5_constant_buffer_state /* previously gen5_command_streamer */
+{
+   struct header header;
+
+   struct
+   {
+      unsigned int nr_urb_entries:3;   
+      unsigned int pad:1;
+      unsigned int urb_entry_size:5;   
+      unsigned int pad0:23;
+   } bits0;
+};
+
+struct gen5_constant_buffer
+{
+   struct
+   {
+      unsigned int length:8;   
+      unsigned int valid:1;   
+      unsigned int pad:7;
+      unsigned int opcode:16;   
+   } header;
+
+   struct
+   {
+      unsigned int buffer_length:6;   
+      unsigned int buffer_address:26;  
+   } bits0;
+};
+
+struct gen5_state_base_address
+{
+   struct header header;
+
+   struct
+   {
+      unsigned int modify_enable:1;
+      unsigned int pad:4;
+      unsigned int general_state_address:27;  
+   } bits0;
+
+   struct
+   {
+      unsigned int modify_enable:1;
+      unsigned int pad:4;
+      unsigned int surface_state_address:27;  
+   } bits1;
+
+   struct
+   {
+      unsigned int modify_enable:1;
+      unsigned int pad:4;
+      unsigned int indirect_object_state_address:27;  
+   } bits2;
+
+   struct
+   {
+      unsigned int modify_enable:1;
+      unsigned int pad:11;
+      unsigned int general_state_upper_bound:20;  
+   } bits3;
+
+   struct
+   {
+      unsigned int modify_enable:1;
+      unsigned int pad:11;
+      unsigned int indirect_object_state_upper_bound:20;  
+   } bits4;
+};
+
+struct gen5_state_prefetch
+{
+   struct header header;
+
+   struct
+   {
+      unsigned int prefetch_count:3;   
+      unsigned int pad:3;
+      unsigned int prefetch_pointer:26;  
+   } bits0;
+};
+
+struct gen5_system_instruction_pointer
+{
+   struct header header;
+
+   struct
+   {
+      unsigned int pad:4;
+      unsigned int system_instruction_pointer:28;  
+   } bits0;
+};
+
+
+
+
+/* State structs for the various fixed function units:
+ */
+
+
+struct thread0
+{
+   unsigned int pad0:1;
+   unsigned int grf_reg_count:3; 
+   unsigned int pad1:2;
+   unsigned int kernel_start_pointer:26; 
+};
+
+struct thread1
+{
+   unsigned int ext_halt_exception_enable:1; 
+   unsigned int sw_exception_enable:1; 
+   unsigned int mask_stack_exception_enable:1; 
+   unsigned int timeout_exception_enable:1; 
+   unsigned int illegal_op_exception_enable:1; 
+   unsigned int pad0:3;
+   unsigned int depth_coef_urb_read_offset:6;  /* WM only */
+   unsigned int pad1:2;
+   unsigned int floating_point_mode:1; 
+   unsigned int thread_priority:1; 
+   unsigned int binding_table_entry_count:8; 
+   unsigned int pad3:5;
+   unsigned int single_program_flow:1; 
+};
+
+struct thread2
+{
+   unsigned int per_thread_scratch_space:4; 
+   unsigned int pad0:6;
+   unsigned int scratch_space_base_pointer:22; 
+};
+
+   
+struct thread3
+{
+   unsigned int dispatch_grf_start_reg:4; 
+   unsigned int urb_entry_read_offset:6; 
+   unsigned int pad0:1;
+   unsigned int urb_entry_read_length:6; 
+   unsigned int pad1:1;
+   unsigned int const_urb_entry_read_offset:6; 
+   unsigned int pad2:1;
+   unsigned int const_urb_entry_read_length:6; 
+   unsigned int pad3:1;
+};
+
+
+
+struct gen5_clip_unit_state
+{
+   struct thread0 thread0;
+   struct thread1 thread1;
+   struct thread2 thread2;
+   struct thread3 thread3;
+
+   struct
+   {
+      unsigned int pad0:9;
+      unsigned int gs_output_stats:1; /* not always */
+      unsigned int stats_enable:1; 
+      unsigned int nr_urb_entries:7; 
+      unsigned int pad1:1;
+      unsigned int urb_entry_allocation_size:5; 
+      unsigned int pad2:1;
+      unsigned int max_threads:6;      /* may be less */
+      unsigned int pad3:1;
+   } thread4;   
+      
+   struct
+   {
+      unsigned int pad0:13;
+      unsigned int clip_mode:3; 
+      unsigned int userclip_enable_flags:8; 
+      unsigned int userclip_must_clip:1; 
+      unsigned int pad1:1;
+      unsigned int guard_band_enable:1; 
+      unsigned int viewport_z_clip_enable:1; 
+      unsigned int viewport_xy_clip_enable:1; 
+      unsigned int vertex_position_space:1; 
+      unsigned int api_mode:1; 
+      unsigned int pad2:1;
+   } clip5;
+   
+   struct
+   {
+      unsigned int pad0:5;
+      unsigned int clipper_viewport_state_ptr:27; 
+   } clip6;
+
+   
+   float viewport_xmin;  
+   float viewport_xmax;  
+   float viewport_ymin;  
+   float viewport_ymax;  
+};
+
+
+
+struct gen5_cc_unit_state
+{
+   struct
+   {
+      unsigned int pad0:3;
+      unsigned int bf_stencil_pass_depth_pass_op:3; 
+      unsigned int bf_stencil_pass_depth_fail_op:3; 
+      unsigned int bf_stencil_fail_op:3; 
+      unsigned int bf_stencil_func:3; 
+      unsigned int bf_stencil_enable:1; 
+      unsigned int pad1:2;
+      unsigned int stencil_write_enable:1; 
+      unsigned int stencil_pass_depth_pass_op:3; 
+      unsigned int stencil_pass_depth_fail_op:3; 
+      unsigned int stencil_fail_op:3; 
+      unsigned int stencil_func:3; 
+      unsigned int stencil_enable:1; 
+   } cc0;
+
+   
+   struct
+   {
+      unsigned int bf_stencil_ref:8; 
+      unsigned int stencil_write_mask:8; 
+      unsigned int stencil_test_mask:8; 
+      unsigned int stencil_ref:8; 
+   } cc1;
+
+   
+   struct
+   {
+      unsigned int logicop_enable:1; 
+      unsigned int pad0:10;
+      unsigned int depth_write_enable:1; 
+      unsigned int depth_test_function:3; 
+      unsigned int depth_test:1; 
+      unsigned int bf_stencil_write_mask:8; 
+      unsigned int bf_stencil_test_mask:8; 
+   } cc2;
+
+   
+   struct
+   {
+      unsigned int pad0:8;
+      unsigned int alpha_test_func:3; 
+      unsigned int alpha_test:1; 
+      unsigned int blend_enable:1; 
+      unsigned int ia_blend_enable:1; 
+      unsigned int pad1:1;
+      unsigned int alpha_test_format:1;
+      unsigned int pad2:16;
+   } cc3;
+   
+   struct
+   {
+      unsigned int pad0:5; 
+      unsigned int cc_viewport_state_offset:27; 
+   } cc4;
+   
+   struct
+   {
+      unsigned int pad0:2;
+      unsigned int ia_dest_blend_factor:5; 
+      unsigned int ia_src_blend_factor:5; 
+      unsigned int ia_blend_function:3; 
+      unsigned int statistics_enable:1; 
+      unsigned int logicop_func:4; 
+      unsigned int pad1:11;
+      unsigned int dither_enable:1; 
+   } cc5;
+
+   struct
+   {
+      unsigned int clamp_post_alpha_blend:1; 
+      unsigned int clamp_pre_alpha_blend:1; 
+      unsigned int clamp_range:2; 
+      unsigned int pad0:11;
+      unsigned int y_dither_offset:2; 
+      unsigned int x_dither_offset:2; 
+      unsigned int dest_blend_factor:5; 
+      unsigned int src_blend_factor:5; 
+      unsigned int blend_function:3; 
+   } cc6;
+
+   struct {
+      union {
+        float f;  
+        unsigned char ub[4];
+      } alpha_ref;
+   } cc7;
+};
+
+
+
+struct gen5_sf_unit_state
+{
+   struct thread0 thread0;
+   struct {
+      unsigned int pad0:7;
+      unsigned int sw_exception_enable:1; 
+      unsigned int pad1:3;
+      unsigned int mask_stack_exception_enable:1; 
+      unsigned int pad2:1;
+      unsigned int illegal_op_exception_enable:1; 
+      unsigned int pad3:2;
+      unsigned int floating_point_mode:1; 
+      unsigned int thread_priority:1; 
+      unsigned int binding_table_entry_count:8; 
+      unsigned int pad4:5;
+      unsigned int single_program_flow:1; 
+   } sf1;
+   
+   struct thread2 thread2;
+   struct thread3 thread3;
+
+   struct
+   {
+      unsigned int pad0:10;
+      unsigned int stats_enable:1; 
+      unsigned int nr_urb_entries:7; 
+      unsigned int pad1:1;
+      unsigned int urb_entry_allocation_size:5; 
+      unsigned int pad2:1;
+      unsigned int max_threads:6; 
+      unsigned int pad3:1;
+   } thread4;   
+
+   struct
+   {
+      unsigned int front_winding:1; 
+      unsigned int viewport_transform:1; 
+      unsigned int pad0:3;
+      unsigned int sf_viewport_state_offset:27; 
+   } sf5;
+   
+   struct
+   {
+      unsigned int pad0:9;
+      unsigned int dest_org_vbias:4; 
+      unsigned int dest_org_hbias:4; 
+      unsigned int scissor:1; 
+      unsigned int disable_2x2_trifilter:1; 
+      unsigned int disable_zero_pix_trifilter:1; 
+      unsigned int point_rast_rule:2; 
+      unsigned int line_endcap_aa_region_width:2; 
+      unsigned int line_width:4; 
+      unsigned int fast_scissor_disable:1; 
+      unsigned int cull_mode:2; 
+      unsigned int aa_enable:1; 
+   } sf6;
+
+   struct
+   {
+      unsigned int point_size:11; 
+      unsigned int use_point_size_state:1; 
+      unsigned int subpixel_precision:1; 
+      unsigned int sprite_point:1; 
+      unsigned int pad0:11;
+      unsigned int trifan_pv:2; 
+      unsigned int linestrip_pv:2; 
+      unsigned int tristrip_pv:2; 
+      unsigned int line_last_pixel_enable:1; 
+   } sf7;
+
+};
+
+
+struct gen5_gs_unit_state
+{
+   struct thread0 thread0;
+   struct thread1 thread1;
+   struct thread2 thread2;
+   struct thread3 thread3;
+
+   struct
+   {
+      unsigned int pad0:10;
+      unsigned int stats_enable:1; 
+      unsigned int nr_urb_entries:7; 
+      unsigned int pad1:1;
+      unsigned int urb_entry_allocation_size:5; 
+      unsigned int pad2:1;
+      unsigned int max_threads:1; 
+      unsigned int pad3:6;
+   } thread4;   
+      
+   struct
+   {
+      unsigned int sampler_count:3; 
+      unsigned int pad0:2;
+      unsigned int sampler_state_pointer:27; 
+   } gs5;
+
+   
+   struct
+   {
+      unsigned int max_vp_index:4; 
+      unsigned int pad0:26;
+      unsigned int reorder_enable:1; 
+      unsigned int pad1:1;
+   } gs6;
+};
+
+
+struct gen5_vs_unit_state
+{
+   struct thread0 thread0;
+   struct thread1 thread1;
+   struct thread2 thread2;
+   struct thread3 thread3;
+   
+   struct
+   {
+      unsigned int pad0:10;
+      unsigned int stats_enable:1; 
+      unsigned int nr_urb_entries:7; 
+      unsigned int pad1:1;
+      unsigned int urb_entry_allocation_size:5; 
+      unsigned int pad2:1;
+      unsigned int max_threads:4; 
+      unsigned int pad3:3;
+   } thread4;   
+
+   struct
+   {
+      unsigned int sampler_count:3; 
+      unsigned int pad0:2;
+      unsigned int sampler_state_pointer:27; 
+   } vs5;
+
+   struct
+   {
+      unsigned int vs_enable:1; 
+      unsigned int vert_cache_disable:1; 
+      unsigned int pad0:30;
+   } vs6;
+};
+
+
+struct gen5_wm_unit_state
+{
+   struct thread0 thread0;
+   struct thread1 thread1;
+   struct thread2 thread2;
+   struct thread3 thread3;
+   
+   struct {
+      unsigned int stats_enable:1; 
+      unsigned int pad0:1;
+      unsigned int sampler_count:3; 
+      unsigned int sampler_state_pointer:27; 
+   } wm4;
+   
+   struct
+   {
+      unsigned int enable_8_pix:1; 
+      unsigned int enable_16_pix:1; 
+      unsigned int enable_32_pix:1; 
+      unsigned int pad0:7;
+      unsigned int legacy_global_depth_bias:1; 
+      unsigned int line_stipple:1; 
+      unsigned int depth_offset:1; 
+      unsigned int polygon_stipple:1; 
+      unsigned int line_aa_region_width:2; 
+      unsigned int line_endcap_aa_region_width:2; 
+      unsigned int early_depth_test:1; 
+      unsigned int thread_dispatch_enable:1; 
+      unsigned int program_uses_depth:1; 
+      unsigned int program_computes_depth:1; 
+      unsigned int program_uses_killpixel:1; 
+      unsigned int legacy_line_rast: 1; 
+      unsigned int transposed_urb_read:1; 
+      unsigned int max_threads:7; 
+   } wm5;
+   
+   float global_depth_offset_constant;  
+   float global_depth_offset_scale;   
+
+   struct {
+      unsigned int pad0:1;
+      unsigned int grf_reg_count_1:3; 
+      unsigned int pad1:2;
+      unsigned int kernel_start_pointer_1:26;
+   } wm8;       
+
+   struct {
+      unsigned int pad0:1;
+      unsigned int grf_reg_count_2:3; 
+      unsigned int pad1:2;
+      unsigned int kernel_start_pointer_2:26;
+   } wm9;       
+
+   struct {
+      unsigned int pad0:1;
+      unsigned int grf_reg_count_3:3; 
+      unsigned int pad1:2;
+      unsigned int kernel_start_pointer_3:26;
+   } wm10;       
+};
+
+struct gen5_wm_unit_state_padded {
+       struct gen5_wm_unit_state state;
+       char pad[64 - sizeof(struct gen5_wm_unit_state)];
+};
+
+/* The hardware supports two different modes for border color. The
+ * default (OpenGL) mode uses floating-point color channels, while the
+ * legacy mode uses 4 bytes.
+ *
+ * More significantly, the legacy mode respects the components of the
+ * border color for channels not present in the source, (whereas the
+ * default mode will ignore the border color's alpha channel and use
+ * alpha==1 for an RGB source, for example).
+ *
+ * The legacy mode matches the semantics specified by the Render
+ * extension.
+ */
+struct gen5_sampler_default_border_color {
+   float color[4];
+};
+
+struct gen5_sampler_legacy_border_color {
+   uint8_t color[4];
+};
+
+struct gen5_sampler_state
+{
+   
+   struct
+   {
+      unsigned int shadow_function:3; 
+      unsigned int lod_bias:11; 
+      unsigned int min_filter:3; 
+      unsigned int mag_filter:3; 
+      unsigned int mip_filter:2; 
+      unsigned int base_level:5; 
+      unsigned int pad:1;
+      unsigned int lod_preclamp:1; 
+      unsigned int border_color_mode:1; 
+      unsigned int pad0:1;
+      unsigned int disable:1; 
+   } ss0;
+
+   struct
+   {
+      unsigned int r_wrap_mode:3; 
+      unsigned int t_wrap_mode:3; 
+      unsigned int s_wrap_mode:3; 
+      unsigned int pad:3;
+      unsigned int max_lod:10; 
+      unsigned int min_lod:10; 
+   } ss1;
+
+   
+   struct
+   {
+      unsigned int pad:5;
+      unsigned int border_color_pointer:27; 
+   } ss2;
+   
+   struct
+   {
+      unsigned int pad:19;
+      unsigned int max_aniso:3; 
+      unsigned int chroma_key_mode:1; 
+      unsigned int chroma_key_index:2; 
+      unsigned int chroma_key_enable:1; 
+      unsigned int monochrome_filter_width:3; 
+      unsigned int monochrome_filter_height:3; 
+   } ss3;
+};
+
+
+struct gen5_clipper_viewport
+{
+   float xmin;  
+   float xmax;  
+   float ymin;  
+   float ymax;  
+};
+
+struct gen5_cc_viewport
+{
+   float min_depth;  
+   float max_depth;  
+};
+
+struct gen5_sf_viewport
+{
+   struct {
+      float m00;  
+      float m11;  
+      float m22;  
+      float m30;  
+      float m31;  
+      float m32;  
+   } viewport;
+
+   struct {
+      short xmin;
+      short ymin;
+      short xmax;
+      short ymax;
+   } scissor;
+};
+
+/* Documented in the subsystem/shared-functions/sampler chapter...
+ */
+struct gen5_surface_state
+{
+   struct {
+      unsigned int cube_pos_z:1; 
+      unsigned int cube_neg_z:1; 
+      unsigned int cube_pos_y:1; 
+      unsigned int cube_neg_y:1; 
+      unsigned int cube_pos_x:1; 
+      unsigned int cube_neg_x:1; 
+      unsigned int pad:3;
+      unsigned int render_cache_read_mode:1;
+      unsigned int mipmap_layout_mode:1; 
+      unsigned int vert_line_stride_ofs:1; 
+      unsigned int vert_line_stride:1; 
+      unsigned int color_blend:1; 
+      unsigned int writedisable_blue:1; 
+      unsigned int writedisable_green:1; 
+      unsigned int writedisable_red:1; 
+      unsigned int writedisable_alpha:1; 
+      unsigned int surface_format:9; 
+      unsigned int data_return_format:1; 
+      unsigned int pad0:1;
+      unsigned int surface_type:3; 
+   } ss0;
+   
+   struct {
+      unsigned int base_addr;  
+   } ss1;
+   
+   struct {
+      unsigned int render_target_rotation:2;
+      unsigned int mip_count:4; 
+      unsigned int width:13; 
+      unsigned int height:13; 
+   } ss2;
+
+   struct {
+      unsigned int tile_walk:1; 
+      unsigned int tiled_surface:1; 
+      unsigned int pad:1; 
+      unsigned int pitch:18; 
+      unsigned int depth:11; 
+   } ss3;
+   
+   struct {
+      unsigned int pad:19;
+      unsigned int min_array_elt:9; 
+      unsigned int min_lod:4; 
+   } ss4;
+
+   struct {
+       unsigned int pad:20;
+       unsigned int y_offset:4;
+       unsigned int pad2:1;
+       unsigned int x_offset:7;
+   } ss5;
+};
+
+/* Surface state DW0 */
+#define GEN5_SURFACE_RC_READ_WRITE       (1 << 8)
+#define GEN5_SURFACE_MIPLAYOUT_SHIFT     10
+#define GEN5_SURFACE_MIPMAPLAYOUT_BELOW   0
+#define GEN5_SURFACE_MIPMAPLAYOUT_RIGHT   1
+#define GEN5_SURFACE_CUBEFACE_ENABLES    0x3f
+#define GEN5_SURFACE_BLEND_ENABLED       (1 << 13)
+#define GEN5_SURFACE_WRITEDISABLE_B_SHIFT        14
+#define GEN5_SURFACE_WRITEDISABLE_G_SHIFT        15
+#define GEN5_SURFACE_WRITEDISABLE_R_SHIFT        16
+#define GEN5_SURFACE_WRITEDISABLE_A_SHIFT        17
+#define GEN5_SURFACE_FORMAT_SHIFT        18
+#define GEN5_SURFACE_FORMAT_MASK         INTEL_MASK(26, 18)
+
+#define GEN5_SURFACE_TYPE_SHIFT          29
+#define GEN5_SURFACE_TYPE_MASK           GEN5_MASK(31, 29)
+#define GEN5_SURFACE_1D      0
+#define GEN5_SURFACE_2D      1
+#define GEN5_SURFACE_3D      2
+#define GEN5_SURFACE_CUBE    3
+#define GEN5_SURFACE_BUFFER  4
+#define GEN5_SURFACE_NULL    7
+
+/* Surface state DW2 */
+#define GEN5_SURFACE_HEIGHT_SHIFT        19
+#define GEN5_SURFACE_HEIGHT_MASK         GEN5_MASK(31, 19)
+#define GEN5_SURFACE_WIDTH_SHIFT         6
+#define GEN5_SURFACE_WIDTH_MASK          GEN5_MASK(18, 6)
+#define GEN5_SURFACE_LOD_SHIFT           2
+#define GEN5_SURFACE_LOD_MASK            GEN5_MASK(5, 2)
+
+/* Surface state DW3 */
+#define GEN5_SURFACE_DEPTH_SHIFT         21
+#define GEN5_SURFACE_DEPTH_MASK          GEN5_MASK(31, 21)
+#define GEN5_SURFACE_PITCH_SHIFT         3
+#define GEN5_SURFACE_PITCH_MASK          GEN5_MASK(19, 3)
+#define GEN5_SURFACE_TILED               (1 << 1)
+#define GEN5_SURFACE_TILED_Y             (1 << 0)
+
+/* Surface state DW4 */
+#define GEN5_SURFACE_MIN_LOD_SHIFT       28
+#define GEN5_SURFACE_MIN_LOD_MASK        GEN5_MASK(31, 28)
+
+/* Surface state DW5 */
+#define GEN5_SURFACE_X_OFFSET_SHIFT      25
+#define GEN5_SURFACE_X_OFFSET_MASK       GEN5_MASK(31, 25)
+#define GEN5_SURFACE_Y_OFFSET_SHIFT      20
+#define GEN5_SURFACE_Y_OFFSET_MASK       GEN5_MASK(23, 20)
+
+struct gen5_vertex_buffer_state
+{
+   struct {
+      unsigned int pitch:11; 
+      unsigned int pad:15;
+      unsigned int access_type:1; 
+      unsigned int vb_index:5; 
+   } vb0;
+   
+   unsigned int start_addr; 
+   unsigned int max_index;   
+#if 1
+   unsigned int instance_data_step_rate; /* not included for sequential/random vertices? */
+#endif
+};
+
+#define GEN5_VBP_MAX 17
+
+struct gen5_vb_array_state {
+   struct header header;
+   struct gen5_vertex_buffer_state vb[GEN5_VBP_MAX];
+};
+
+
+struct gen5_vertex_element_state
+{
+   struct
+   {
+      unsigned int src_offset:11; 
+      unsigned int pad:5;
+      unsigned int src_format:9; 
+      unsigned int pad0:1;
+      unsigned int valid:1; 
+      unsigned int vertex_buffer_index:5; 
+   } ve0;
+   
+   struct
+   {
+      unsigned int dst_offset:8; 
+      unsigned int pad:8;
+      unsigned int vfcomponent3:4; 
+      unsigned int vfcomponent2:4; 
+      unsigned int vfcomponent1:4; 
+      unsigned int vfcomponent0:4; 
+   } ve1;
+};
+
+#define GEN5_VEP_MAX 18
+
+struct gen5_vertex_element_packet {
+   struct header header;
+   struct gen5_vertex_element_state ve[GEN5_VEP_MAX]; /* note: less than _TNL_ATTRIB_MAX */
+};
+
+
+struct gen5_urb_immediate {
+   unsigned int opcode:4;
+   unsigned int offset:6;
+   unsigned int swizzle_control:2; 
+   unsigned int pad:1;
+   unsigned int allocate:1;
+   unsigned int used:1;
+   unsigned int complete:1;
+   unsigned int response_length:4;
+   unsigned int msg_length:4;
+   unsigned int msg_target:4;
+   unsigned int pad1:3;
+   unsigned int end_of_thread:1;
+};
+
+/* Instruction format for the execution units:
+ */
+struct gen5_instruction
+{
+   struct 
+   {
+      unsigned int opcode:7;
+      unsigned int pad:1;
+      unsigned int access_mode:1;
+      unsigned int mask_control:1;
+      unsigned int dependency_control:2;
+      unsigned int compression_control:2;
+      unsigned int thread_control:2;
+      unsigned int predicate_control:4;
+      unsigned int predicate_inverse:1;
+      unsigned int execution_size:3;
+      unsigned int destreg__conditonalmod:4; /* destreg - send, conditionalmod - others */
+      unsigned int pad0:2;
+      unsigned int debug_control:1;
+      unsigned int saturate:1;
+   } header;
+
+   union {
+      struct
+      {
+        unsigned int dest_reg_file:2;
+        unsigned int dest_reg_type:3;
+        unsigned int src0_reg_file:2;
+        unsigned int src0_reg_type:3;
+        unsigned int src1_reg_file:2;
+        unsigned int src1_reg_type:3;
+        unsigned int pad:1;
+        unsigned int dest_subreg_nr:5;
+        unsigned int dest_reg_nr:8;
+        unsigned int dest_horiz_stride:2;
+        unsigned int dest_address_mode:1;
+      } da1;
+
+      struct
+      {
+        unsigned int dest_reg_file:2;
+        unsigned int dest_reg_type:3;
+        unsigned int src0_reg_file:2;
+        unsigned int src0_reg_type:3;
+        unsigned int pad:6;
+        int dest_indirect_offset:10;   /* offset against the deref'd address reg */
+        unsigned int dest_subreg_nr:3; /* subnr for the address reg a0.x */
+        unsigned int dest_horiz_stride:2;
+        unsigned int dest_address_mode:1;
+      } ia1;
+
+      struct
+      {
+        unsigned int dest_reg_file:2;
+        unsigned int dest_reg_type:3;
+        unsigned int src0_reg_file:2;
+        unsigned int src0_reg_type:3;
+        unsigned int src1_reg_file:2;
+        unsigned int src1_reg_type:3;
+        unsigned int pad0:1;
+        unsigned int dest_writemask:4;
+        unsigned int dest_subreg_nr:1;
+        unsigned int dest_reg_nr:8;
+        unsigned int pad1:2;
+        unsigned int dest_address_mode:1;
+      } da16;
+
+      struct
+      {
+        unsigned int dest_reg_file:2;
+        unsigned int dest_reg_type:3;
+        unsigned int src0_reg_file:2;
+        unsigned int src0_reg_type:3;
+        unsigned int pad0:6;
+        unsigned int dest_writemask:4;
+        int dest_indirect_offset:6;
+        unsigned int dest_subreg_nr:3;
+        unsigned int pad1:2;
+        unsigned int dest_address_mode:1;
+      } ia16;
+   } bits1;
+
+
+   union {
+      struct
+      {
+        unsigned int src0_subreg_nr:5;
+        unsigned int src0_reg_nr:8;
+        unsigned int src0_abs:1;
+        unsigned int src0_negate:1;
+        unsigned int src0_address_mode:1;
+        unsigned int src0_horiz_stride:2;
+        unsigned int src0_width:3;
+        unsigned int src0_vert_stride:4;
+        unsigned int flag_reg_nr:1;
+        unsigned int pad:6;
+      } da1;
+
+      struct
+      {
+        int src0_indirect_offset:10;
+        unsigned int src0_subreg_nr:3;
+        unsigned int src0_abs:1;
+        unsigned int src0_negate:1;
+        unsigned int src0_address_mode:1;
+        unsigned int src0_horiz_stride:2;
+        unsigned int src0_width:3;
+        unsigned int src0_vert_stride:4;
+        unsigned int flag_reg_nr:1;
+        unsigned int pad:6;    
+      } ia1;
+
+      struct
+      {
+        unsigned int src0_swz_x:2;
+        unsigned int src0_swz_y:2;
+        unsigned int src0_subreg_nr:1;
+        unsigned int src0_reg_nr:8;
+        unsigned int src0_abs:1;
+        unsigned int src0_negate:1;
+        unsigned int src0_address_mode:1;
+        unsigned int src0_swz_z:2;
+        unsigned int src0_swz_w:2;
+        unsigned int pad0:1;
+        unsigned int src0_vert_stride:4;
+        unsigned int flag_reg_nr:1;
+        unsigned int pad1:6;
+      } da16;
+
+      struct
+      {
+        unsigned int src0_swz_x:2;
+        unsigned int src0_swz_y:2;
+        int src0_indirect_offset:6;
+        unsigned int src0_subreg_nr:3;
+        unsigned int src0_abs:1;
+        unsigned int src0_negate:1;
+        unsigned int src0_address_mode:1;
+        unsigned int src0_swz_z:2;
+        unsigned int src0_swz_w:2;
+        unsigned int pad0:1;
+        unsigned int src0_vert_stride:4;
+        unsigned int flag_reg_nr:1;
+        unsigned int pad1:6;
+      } ia16;
+
+   } bits2;
+
+   union
+   {
+      struct
+      {
+        unsigned int src1_subreg_nr:5;
+        unsigned int src1_reg_nr:8;
+        unsigned int src1_abs:1;
+        unsigned int src1_negate:1;
+        unsigned int pad:1;
+        unsigned int src1_horiz_stride:2;
+        unsigned int src1_width:3;
+        unsigned int src1_vert_stride:4;
+        unsigned int pad0:7;
+      } da1;
+
+      struct
+      {
+        unsigned int src1_swz_x:2;
+        unsigned int src1_swz_y:2;
+        unsigned int src1_subreg_nr:1;
+        unsigned int src1_reg_nr:8;
+        unsigned int src1_abs:1;
+        unsigned int src1_negate:1;
+        unsigned int pad0:1;
+        unsigned int src1_swz_z:2;
+        unsigned int src1_swz_w:2;
+        unsigned int pad1:1;
+        unsigned int src1_vert_stride:4;
+        unsigned int pad2:7;
+      } da16;
+
+      struct
+      {
+        int  src1_indirect_offset:10;
+        unsigned int src1_subreg_nr:3;
+        unsigned int src1_abs:1;
+        unsigned int src1_negate:1;
+        unsigned int pad0:1;
+        unsigned int src1_horiz_stride:2;
+        unsigned int src1_width:3;
+        unsigned int src1_vert_stride:4;
+        unsigned int flag_reg_nr:1;
+        unsigned int pad1:6;   
+      } ia1;
+
+      struct
+      {
+        unsigned int src1_swz_x:2;
+        unsigned int src1_swz_y:2;
+        int  src1_indirect_offset:6;
+        unsigned int src1_subreg_nr:3;
+        unsigned int src1_abs:1;
+        unsigned int src1_negate:1;
+        unsigned int pad0:1;
+        unsigned int src1_swz_z:2;
+        unsigned int src1_swz_w:2;
+        unsigned int pad1:1;
+        unsigned int src1_vert_stride:4;
+        unsigned int flag_reg_nr:1;
+        unsigned int pad2:6;
+      } ia16;
+
+
+      struct
+      {
+        int  jump_count:16;    /* note: signed */
+        unsigned int  pop_count:4;
+        unsigned int  pad0:12;
+      } if_else;
+
+      struct {
+        unsigned int function:4;
+        unsigned int int_type:1;
+        unsigned int precision:1;
+        unsigned int saturate:1;
+        unsigned int data_type:1;
+        unsigned int pad0:8;
+        unsigned int response_length:4;
+        unsigned int msg_length:4;
+        unsigned int msg_target:4;
+        unsigned int pad1:3;
+        unsigned int end_of_thread:1;
+      } math;
+
+      struct {
+        unsigned int binding_table_index:8;
+        unsigned int sampler:4;
+        unsigned int return_format:2; 
+        unsigned int msg_type:2;   
+        unsigned int response_length:4;
+        unsigned int msg_length:4;
+        unsigned int msg_target:4;
+        unsigned int pad1:3;
+        unsigned int end_of_thread:1;
+      } sampler;
+
+      struct gen5_urb_immediate urb;
+
+      struct {
+        unsigned int binding_table_index:8;
+        unsigned int msg_control:4;  
+        unsigned int msg_type:2;  
+        unsigned int target_cache:2;    
+        unsigned int response_length:4;
+        unsigned int msg_length:4;
+        unsigned int msg_target:4;
+        unsigned int pad1:3;
+        unsigned int end_of_thread:1;
+      } dp_read;
+
+      struct {
+        unsigned int binding_table_index:8;
+        unsigned int msg_control:3;
+        unsigned int pixel_scoreboard_clear:1;
+        unsigned int msg_type:3;    
+        unsigned int send_commit_msg:1;
+        unsigned int response_length:4;
+        unsigned int msg_length:4;
+        unsigned int msg_target:4;
+        unsigned int pad1:3;
+        unsigned int end_of_thread:1;
+      } dp_write;
+
+      struct {
+        unsigned int pad:16;
+        unsigned int response_length:4;
+        unsigned int msg_length:4;
+        unsigned int msg_target:4;
+        unsigned int pad1:3;
+        unsigned int end_of_thread:1;
+      } generic;
+
+      unsigned int ud;
+   } bits3;
+};
+
+/* media pipeline */
+
+struct gen5_vfe_state {
+    struct {
+       unsigned int per_thread_scratch_space:4;
+       unsigned int pad3:3;
+       unsigned int extend_vfe_state_present:1;
+       unsigned int pad2:2;
+       unsigned int scratch_base:22;
+    } vfe0;
+
+    struct {
+       unsigned int debug_counter_control:2;
+       unsigned int children_present:1;
+       unsigned int vfe_mode:4;
+       unsigned int pad2:2;
+       unsigned int num_urb_entries:7;
+       unsigned int urb_entry_alloc_size:9;
+       unsigned int max_threads:7;
+    } vfe1;
+
+    struct {
+       unsigned int pad4:4;
+       unsigned int interface_descriptor_base:28;
+    } vfe2;
+};
+
+struct gen5_vld_state {
+    struct {
+       unsigned int pad6:6;
+       unsigned int scan_order:1;
+       unsigned int intra_vlc_format:1;
+       unsigned int quantizer_scale_type:1;
+       unsigned int concealment_motion_vector:1;
+       unsigned int frame_predict_frame_dct:1;
+       unsigned int top_field_first:1;
+       unsigned int picture_structure:2;
+       unsigned int intra_dc_precision:2;
+       unsigned int f_code_0_0:4;
+       unsigned int f_code_0_1:4;
+       unsigned int f_code_1_0:4;
+       unsigned int f_code_1_1:4;
+    } vld0;
+
+    struct {
+       unsigned int pad2:9;
+       unsigned int picture_coding_type:2;
+       unsigned int pad:21;
+    } vld1;
+
+    struct {
+       unsigned int index_0:4;
+       unsigned int index_1:4;
+       unsigned int index_2:4;
+       unsigned int index_3:4;
+       unsigned int index_4:4;
+       unsigned int index_5:4;
+       unsigned int index_6:4;
+       unsigned int index_7:4;
+    } desc_remap_table0;
+
+    struct {
+       unsigned int index_8:4;
+       unsigned int index_9:4;
+       unsigned int index_10:4;
+       unsigned int index_11:4;
+       unsigned int index_12:4;
+       unsigned int index_13:4;
+       unsigned int index_14:4;
+       unsigned int index_15:4;
+    } desc_remap_table1;
+};
+
+struct gen5_interface_descriptor {
+    struct {
+       unsigned int grf_reg_blocks:4;
+       unsigned int pad:2;
+       unsigned int kernel_start_pointer:26;
+    } desc0;
+
+    struct {
+       unsigned int pad:7;
+       unsigned int software_exception:1;
+       unsigned int pad2:3;
+       unsigned int maskstack_exception:1;
+       unsigned int pad3:1;
+       unsigned int illegal_opcode_exception:1;
+       unsigned int pad4:2;
+       unsigned int floating_point_mode:1;
+       unsigned int thread_priority:1;
+       unsigned int single_program_flow:1;
+       unsigned int pad5:1;
+       unsigned int const_urb_entry_read_offset:6;
+       unsigned int const_urb_entry_read_len:6;
+    } desc1;
+
+    struct {
+       unsigned int pad:2;
+       unsigned int sampler_count:3;
+       unsigned int sampler_state_pointer:27;
+    } desc2;
+
+    struct {
+       unsigned int binding_table_entry_count:5;
+       unsigned int binding_table_pointer:27;
+    } desc3;
+};
+
+struct gen6_blend_state
+{
+       struct {
+               unsigned int dest_blend_factor:5;
+               unsigned int source_blend_factor:5;
+               unsigned int pad3:1;
+               unsigned int blend_func:3;
+               unsigned int pad2:1;
+               unsigned int ia_dest_blend_factor:5;
+               unsigned int ia_source_blend_factor:5;
+               unsigned int pad1:1;
+               unsigned int ia_blend_func:3;
+               unsigned int pad0:1;
+               unsigned int ia_blend_enable:1;
+               unsigned int blend_enable:1;
+       } blend0;
+
+       struct {
+               unsigned int post_blend_clamp_enable:1;
+               unsigned int pre_blend_clamp_enable:1;
+               unsigned int clamp_range:2;
+               unsigned int pad0:4;
+               unsigned int x_dither_offset:2;
+               unsigned int y_dither_offset:2;
+               unsigned int dither_enable:1;
+               unsigned int alpha_test_func:3;
+               unsigned int alpha_test_enable:1;
+               unsigned int pad1:1;
+               unsigned int logic_op_func:4;
+               unsigned int logic_op_enable:1;
+               unsigned int pad2:1;
+               unsigned int write_disable_b:1;
+               unsigned int write_disable_g:1;
+               unsigned int write_disable_r:1;
+               unsigned int write_disable_a:1;
+               unsigned int pad3:1;
+               unsigned int alpha_to_coverage_dither:1;
+               unsigned int alpha_to_one:1;
+               unsigned int alpha_to_coverage:1;
+       } blend1;
+};
+
+struct gen6_color_calc_state
+{
+       struct {
+               unsigned int alpha_test_format:1;
+               unsigned int pad0:14;
+               unsigned int round_disable:1;
+               unsigned int bf_stencil_ref:8;
+               unsigned int stencil_ref:8;
+       } cc0;
+
+       union {
+               float alpha_ref_f;
+               struct {
+                       unsigned int ui:8;
+                       unsigned int pad0:24;
+               } alpha_ref_fi;
+       } cc1;
+
+       float constant_r;
+       float constant_g;
+       float constant_b;
+       float constant_a;
+};
+
+struct gen6_depth_stencil_state
+{
+       struct {
+               unsigned int pad0:3;
+               unsigned int bf_stencil_pass_depth_pass_op:3;
+               unsigned int bf_stencil_pass_depth_fail_op:3;
+               unsigned int bf_stencil_fail_op:3;
+               unsigned int bf_stencil_func:3;
+               unsigned int bf_stencil_enable:1;
+               unsigned int pad1:2;
+               unsigned int stencil_write_enable:1;
+               unsigned int stencil_pass_depth_pass_op:3;
+               unsigned int stencil_pass_depth_fail_op:3;
+               unsigned int stencil_fail_op:3;
+               unsigned int stencil_func:3;
+               unsigned int stencil_enable:1;
+       } ds0;
+
+       struct {
+               unsigned int bf_stencil_write_mask:8;
+               unsigned int bf_stencil_test_mask:8;
+               unsigned int stencil_write_mask:8;
+               unsigned int stencil_test_mask:8;
+       } ds1;
+
+       struct {
+               unsigned int pad0:26;
+               unsigned int depth_write_enable:1;
+               unsigned int depth_test_func:3;
+               unsigned int pad1:1;
+               unsigned int depth_test_enable:1;
+       } ds2;
+};
+
+typedef enum {
+       SAMPLER_FILTER_NEAREST = 0,
+       SAMPLER_FILTER_BILINEAR,
+       FILTER_COUNT
+} sampler_filter_t;
+
+typedef enum {
+       SAMPLER_EXTEND_NONE = 0,
+       SAMPLER_EXTEND_REPEAT,
+       SAMPLER_EXTEND_PAD,
+       SAMPLER_EXTEND_REFLECT,
+       EXTEND_COUNT
+} sampler_extend_t;
+
+typedef enum {
+       WM_KERNEL = 0,
+       WM_KERNEL_P,
+
+       WM_KERNEL_MASK,
+       WM_KERNEL_MASK_P,
+
+       WM_KERNEL_MASKCA,
+       WM_KERNEL_MASKCA_P,
+
+       WM_KERNEL_MASKSA,
+       WM_KERNEL_MASKSA_P,
+
+       WM_KERNEL_OPACITY,
+       WM_KERNEL_OPACITY_P,
+
+       WM_KERNEL_VIDEO_PLANAR,
+       WM_KERNEL_VIDEO_PACKED,
+       KERNEL_COUNT
+} wm_kernel_t;
+#endif
diff --git a/src/sna/gen6_render.c b/src/sna/gen6_render.c
new file mode 100644 (file)
index 0000000..4990062
--- /dev/null
@@ -0,0 +1,4310 @@
+/*
+ * Copyright © 2006,2008,2011 Intel Corporation
+ * Copyright © 2007 Red Hat, Inc.
+ *
+ * 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.
+ *
+ * Authors:
+ *    Wang Zhenyu <zhenyu.z.wang@sna.com>
+ *    Eric Anholt <eric@anholt.net>
+ *    Carl Worth <cworth@redhat.com>
+ *    Keith Packard <keithp@keithp.com>
+ *    Chris Wilson <chris@chris-wilson.co.uk>
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "sna.h"
+#include "sna_reg.h"
+#include "sna_render.h"
+#include "sna_render_inline.h"
+#include "sna_video.h"
+
+#include "brw/brw.h"
+#include "gen6_render.h"
+
+#define NO_COMPOSITE 0
+#define NO_COMPOSITE_SPANS 0
+#define NO_COPY 0
+#define NO_COPY_BOXES 0
+#define NO_FILL 0
+#define NO_FILL_BOXES 0
+#define NO_FILL_ONE 0
+#define NO_FILL_CLEAR 0
+
+#define NO_RING_SWITCH 0
+#define PREFER_RENDER 0
+
+#define USE_8_PIXEL_DISPATCH 1
+#define USE_16_PIXEL_DISPATCH 1
+#define USE_32_PIXEL_DISPATCH 0
+
+#if !USE_8_PIXEL_DISPATCH && !USE_16_PIXEL_DISPATCH && !USE_32_PIXEL_DISPATCH
+#error "Must select at least 8, 16 or 32 pixel dispatch"
+#endif
+
+#define GEN6_MAX_SIZE 8192
+
+struct gt_info {
+       int max_vs_threads;
+       int max_gs_threads;
+       int max_wm_threads;
+       struct {
+               int size;
+               int max_vs_entries;
+               int max_gs_entries;
+       } urb;
+};
+
+static const struct gt_info gt1_info = {
+       .max_vs_threads = 24,
+       .max_gs_threads = 21,
+       .max_wm_threads = 40,
+       .urb = { 32, 256, 256 },
+};
+
+static const struct gt_info gt2_info = {
+       .max_vs_threads = 60,
+       .max_gs_threads = 60,
+       .max_wm_threads = 80,
+       .urb = { 64, 256, 256 },
+};
+
+static const uint32_t ps_kernel_packed[][4] = {
+#include "exa_wm_src_affine.g6b"
+#include "exa_wm_src_sample_argb.g6b"
+#include "exa_wm_yuv_rgb.g6b"
+#include "exa_wm_write.g6b"
+};
+
+static const uint32_t ps_kernel_planar[][4] = {
+#include "exa_wm_src_affine.g6b"
+#include "exa_wm_src_sample_planar.g6b"
+#include "exa_wm_yuv_rgb.g6b"
+#include "exa_wm_write.g6b"
+};
+
+#define NOKERNEL(kernel_enum, func, ns) \
+    [GEN6_WM_KERNEL_##kernel_enum] = {#kernel_enum, func, 0, ns}
+#define KERNEL(kernel_enum, kernel, ns) \
+    [GEN6_WM_KERNEL_##kernel_enum] = {#kernel_enum, kernel, sizeof(kernel), ns}
+
+static const struct wm_kernel_info {
+       const char *name;
+       const void *data;
+       unsigned int size;
+       unsigned int num_surfaces;
+} wm_kernels[] = {
+       NOKERNEL(NOMASK, brw_wm_kernel__affine, 2),
+       NOKERNEL(NOMASK_P, brw_wm_kernel__projective, 2),
+
+       NOKERNEL(MASK, brw_wm_kernel__affine_mask, 3),
+       NOKERNEL(MASK_P, brw_wm_kernel__projective_mask, 3),
+
+       NOKERNEL(MASKCA, brw_wm_kernel__affine_mask_ca, 3),
+       NOKERNEL(MASKCA_P, brw_wm_kernel__projective_mask_ca, 3),
+
+       NOKERNEL(MASKSA, brw_wm_kernel__affine_mask_sa, 3),
+       NOKERNEL(MASKSA_P, brw_wm_kernel__projective_mask_sa, 3),
+
+       NOKERNEL(OPACITY, brw_wm_kernel__affine_opacity, 2),
+       NOKERNEL(OPACITY_P, brw_wm_kernel__projective_opacity, 2),
+
+       KERNEL(VIDEO_PLANAR, ps_kernel_planar, 7),
+       KERNEL(VIDEO_PACKED, ps_kernel_packed, 2),
+};
+#undef KERNEL
+
+static const struct blendinfo {
+       bool src_alpha;
+       uint32_t src_blend;
+       uint32_t dst_blend;
+} gen6_blend_op[] = {
+       /* Clear */     {0, GEN6_BLENDFACTOR_ZERO, GEN6_BLENDFACTOR_ZERO},
+       /* Src */       {0, GEN6_BLENDFACTOR_ONE, GEN6_BLENDFACTOR_ZERO},
+       /* Dst */       {0, GEN6_BLENDFACTOR_ZERO, GEN6_BLENDFACTOR_ONE},
+       /* Over */      {1, GEN6_BLENDFACTOR_ONE, GEN6_BLENDFACTOR_INV_SRC_ALPHA},
+       /* OverReverse */ {0, GEN6_BLENDFACTOR_INV_DST_ALPHA, GEN6_BLENDFACTOR_ONE},
+       /* In */        {0, GEN6_BLENDFACTOR_DST_ALPHA, GEN6_BLENDFACTOR_ZERO},
+       /* InReverse */ {1, GEN6_BLENDFACTOR_ZERO, GEN6_BLENDFACTOR_SRC_ALPHA},
+       /* Out */       {0, GEN6_BLENDFACTOR_INV_DST_ALPHA, GEN6_BLENDFACTOR_ZERO},
+       /* OutReverse */ {1, GEN6_BLENDFACTOR_ZERO, GEN6_BLENDFACTOR_INV_SRC_ALPHA},
+       /* Atop */      {1, GEN6_BLENDFACTOR_DST_ALPHA, GEN6_BLENDFACTOR_INV_SRC_ALPHA},
+       /* AtopReverse */ {1, GEN6_BLENDFACTOR_INV_DST_ALPHA, GEN6_BLENDFACTOR_SRC_ALPHA},
+       /* Xor */       {1, GEN6_BLENDFACTOR_INV_DST_ALPHA, GEN6_BLENDFACTOR_INV_SRC_ALPHA},
+       /* Add */       {0, GEN6_BLENDFACTOR_ONE, GEN6_BLENDFACTOR_ONE},
+};
+
+/**
+ * Highest-valued BLENDFACTOR used in gen6_blend_op.
+ *
+ * This leaves out GEN6_BLENDFACTOR_INV_DST_COLOR,
+ * GEN6_BLENDFACTOR_INV_CONST_{COLOR,ALPHA},
+ * GEN6_BLENDFACTOR_INV_SRC1_{COLOR,ALPHA}
+ */
+#define GEN6_BLENDFACTOR_COUNT (GEN6_BLENDFACTOR_INV_DST_ALPHA + 1)
+
+#define GEN6_BLEND_STATE_PADDED_SIZE   ALIGN(sizeof(struct gen6_blend_state), 64)
+
+#define BLEND_OFFSET(s, d) \
+       (((s) * GEN6_BLENDFACTOR_COUNT + (d)) * GEN6_BLEND_STATE_PADDED_SIZE)
+
+#define NO_BLEND BLEND_OFFSET(GEN6_BLENDFACTOR_ONE, GEN6_BLENDFACTOR_ZERO)
+#define CLEAR BLEND_OFFSET(GEN6_BLENDFACTOR_ZERO, GEN6_BLENDFACTOR_ZERO)
+
+#define SAMPLER_OFFSET(sf, se, mf, me) \
+       (((((sf) * EXTEND_COUNT + (se)) * FILTER_COUNT + (mf)) * EXTEND_COUNT + (me) + 2) * 2 * sizeof(struct gen6_sampler_state))
+
+#define VERTEX_2s2s 0
+
+#define COPY_SAMPLER 0
+#define COPY_VERTEX VERTEX_2s2s
+#define COPY_FLAGS(a) GEN6_SET_FLAGS(COPY_SAMPLER, (a) == GXcopy ? NO_BLEND : CLEAR, GEN6_WM_KERNEL_NOMASK, COPY_VERTEX)
+
+#define FILL_SAMPLER (2 * sizeof(struct gen6_sampler_state))
+#define FILL_VERTEX VERTEX_2s2s
+#define FILL_FLAGS(op, format) GEN6_SET_FLAGS(FILL_SAMPLER, gen6_get_blend((op), false, (format)), GEN6_WM_KERNEL_NOMASK, FILL_VERTEX)
+#define FILL_FLAGS_NOBLEND GEN6_SET_FLAGS(FILL_SAMPLER, NO_BLEND, GEN6_WM_KERNEL_NOMASK, FILL_VERTEX)
+
+#define VIDEO_SAMPLER \
+       SAMPLER_OFFSET(SAMPLER_FILTER_BILINEAR, SAMPLER_EXTEND_PAD, \
+                      SAMPLER_FILTER_NEAREST, SAMPLER_EXTEND_NONE)
+
+#define GEN6_SAMPLER(f) (((f) >> 16) & 0xfff0)
+#define GEN6_BLEND(f) (((f) >> 0) & 0xfff0)
+#define GEN6_KERNEL(f) (((f) >> 16) & 0xf)
+#define GEN6_VERTEX(f) (((f) >> 0) & 0xf)
+#define GEN6_SET_FLAGS(S, B, K, V)  (((S) | (K)) << 16 | ((B) | (V)))
+
+#define OUT_BATCH(v) batch_emit(sna, v)
+#define OUT_VERTEX(x,y) vertex_emit_2s(sna, x,y)
+#define OUT_VERTEX_F(v) vertex_emit(sna, v)
+
+static inline bool too_large(int width, int height)
+{
+       return width > GEN6_MAX_SIZE || height > GEN6_MAX_SIZE;
+}
+
+static uint32_t gen6_get_blend(int op,
+                              bool has_component_alpha,
+                              uint32_t dst_format)
+{
+       uint32_t src, dst;
+
+       src = gen6_blend_op[op].src_blend;
+       dst = gen6_blend_op[op].dst_blend;
+
+       /* If there's no dst alpha channel, adjust the blend op so that
+        * we'll treat it always as 1.
+        */
+       if (PICT_FORMAT_A(dst_format) == 0) {
+               if (src == GEN6_BLENDFACTOR_DST_ALPHA)
+                       src = GEN6_BLENDFACTOR_ONE;
+               else if (src == GEN6_BLENDFACTOR_INV_DST_ALPHA)
+                       src = GEN6_BLENDFACTOR_ZERO;
+       }
+
+       /* If the source alpha is being used, then we should only be in a
+        * case where the source blend factor is 0, and the source blend
+        * value is the mask channels multiplied by the source picture's alpha.
+        */
+       if (has_component_alpha && gen6_blend_op[op].src_alpha) {
+               if (dst == GEN6_BLENDFACTOR_SRC_ALPHA)
+                       dst = GEN6_BLENDFACTOR_SRC_COLOR;
+               else if (dst == GEN6_BLENDFACTOR_INV_SRC_ALPHA)
+                       dst = GEN6_BLENDFACTOR_INV_SRC_COLOR;
+       }
+
+       DBG(("blend op=%d, dst=%x [A=%d] => src=%d, dst=%d => offset=%x\n",
+            op, dst_format, PICT_FORMAT_A(dst_format),
+            src, dst, (int)BLEND_OFFSET(src, dst)));
+       return BLEND_OFFSET(src, dst);
+}
+
+static uint32_t gen6_get_card_format(PictFormat format)
+{
+       switch (format) {
+       default:
+               return -1;
+       case PICT_a8r8g8b8:
+               return GEN6_SURFACEFORMAT_B8G8R8A8_UNORM;
+       case PICT_x8r8g8b8:
+               return GEN6_SURFACEFORMAT_B8G8R8X8_UNORM;
+       case PICT_a8b8g8r8:
+               return GEN6_SURFACEFORMAT_R8G8B8A8_UNORM;
+       case PICT_x8b8g8r8:
+               return GEN6_SURFACEFORMAT_R8G8B8X8_UNORM;
+       case PICT_a2r10g10b10:
+               return GEN6_SURFACEFORMAT_B10G10R10A2_UNORM;
+       case PICT_x2r10g10b10:
+               return GEN6_SURFACEFORMAT_B10G10R10X2_UNORM;
+       case PICT_r8g8b8:
+               return GEN6_SURFACEFORMAT_R8G8B8_UNORM;
+       case PICT_r5g6b5:
+               return GEN6_SURFACEFORMAT_B5G6R5_UNORM;
+       case PICT_a1r5g5b5:
+               return GEN6_SURFACEFORMAT_B5G5R5A1_UNORM;
+       case PICT_a8:
+               return GEN6_SURFACEFORMAT_A8_UNORM;
+       case PICT_a4r4g4b4:
+               return GEN6_SURFACEFORMAT_B4G4R4A4_UNORM;
+       }
+}
+
+static uint32_t gen6_get_dest_format(PictFormat format)
+{
+       switch (format) {
+       default:
+               return -1;
+       case PICT_a8r8g8b8:
+       case PICT_x8r8g8b8:
+               return GEN6_SURFACEFORMAT_B8G8R8A8_UNORM;
+       case PICT_a8b8g8r8:
+       case PICT_x8b8g8r8:
+               return GEN6_SURFACEFORMAT_R8G8B8A8_UNORM;
+       case PICT_a2r10g10b10:
+       case PICT_x2r10g10b10:
+               return GEN6_SURFACEFORMAT_B10G10R10A2_UNORM;
+       case PICT_r5g6b5:
+               return GEN6_SURFACEFORMAT_B5G6R5_UNORM;
+       case PICT_x1r5g5b5:
+       case PICT_a1r5g5b5:
+               return GEN6_SURFACEFORMAT_B5G5R5A1_UNORM;
+       case PICT_a8:
+               return GEN6_SURFACEFORMAT_A8_UNORM;
+       case PICT_a4r4g4b4:
+       case PICT_x4r4g4b4:
+               return GEN6_SURFACEFORMAT_B4G4R4A4_UNORM;
+       }
+}
+
+static bool gen6_check_dst_format(PictFormat format)
+{
+       if (gen6_get_dest_format(format) != -1)
+               return true;
+
+       DBG(("%s: unhandled format: %x\n", __FUNCTION__, (int)format));
+       return false;
+}
+
+static bool gen6_check_format(uint32_t format)
+{
+       if (gen6_get_card_format(format) != -1)
+               return true;
+
+       DBG(("%s: unhandled format: %x\n", __FUNCTION__, (int)format));
+       return false;
+}
+
+static uint32_t gen6_filter(uint32_t filter)
+{
+       switch (filter) {
+       default:
+               assert(0);
+       case PictFilterNearest:
+               return SAMPLER_FILTER_NEAREST;
+       case PictFilterBilinear:
+               return SAMPLER_FILTER_BILINEAR;
+       }
+}
+
+static uint32_t gen6_check_filter(PicturePtr picture)
+{
+       switch (picture->filter) {
+       case PictFilterNearest:
+       case PictFilterBilinear:
+               return true;
+       default:
+               return false;
+       }
+}
+
+static uint32_t gen6_repeat(uint32_t repeat)
+{
+       switch (repeat) {
+       default:
+               assert(0);
+       case RepeatNone:
+               return SAMPLER_EXTEND_NONE;
+       case RepeatNormal:
+               return SAMPLER_EXTEND_REPEAT;
+       case RepeatPad:
+               return SAMPLER_EXTEND_PAD;
+       case RepeatReflect:
+               return SAMPLER_EXTEND_REFLECT;
+       }
+}
+
+static bool gen6_check_repeat(PicturePtr picture)
+{
+       if (!picture->repeat)
+               return true;
+
+       switch (picture->repeatType) {
+       case RepeatNone:
+       case RepeatNormal:
+       case RepeatPad:
+       case RepeatReflect:
+               return true;
+       default:
+               return false;
+       }
+}
+
+static int
+gen6_choose_composite_kernel(int op, bool has_mask, bool is_ca, bool is_affine)
+{
+       int base;
+
+       if (has_mask) {
+               if (is_ca) {
+                       if (gen6_blend_op[op].src_alpha)
+                               base = GEN6_WM_KERNEL_MASKSA;
+                       else
+                               base = GEN6_WM_KERNEL_MASKCA;
+               } else
+                       base = GEN6_WM_KERNEL_MASK;
+       } else
+               base = GEN6_WM_KERNEL_NOMASK;
+
+       return base + !is_affine;
+}
+
+static void
+gen6_emit_urb(struct sna *sna)
+{
+       OUT_BATCH(GEN6_3DSTATE_URB | (3 - 2));
+       OUT_BATCH(((1 - 1) << GEN6_3DSTATE_URB_VS_SIZE_SHIFT) |
+                 (sna->render_state.gen6.info->urb.max_vs_entries << GEN6_3DSTATE_URB_VS_ENTRIES_SHIFT)); /* at least 24 on GEN6 */
+       OUT_BATCH((0 << GEN6_3DSTATE_URB_GS_SIZE_SHIFT) |
+                 (0 << GEN6_3DSTATE_URB_GS_ENTRIES_SHIFT)); /* no GS thread */
+}
+
+static void
+gen6_emit_state_base_address(struct sna *sna)
+{
+       OUT_BATCH(GEN6_STATE_BASE_ADDRESS | (10 - 2));
+       OUT_BATCH(0); /* general */
+       OUT_BATCH(kgem_add_reloc(&sna->kgem, /* surface */
+                                sna->kgem.nbatch,
+                                NULL,
+                                I915_GEM_DOMAIN_INSTRUCTION << 16,
+                                BASE_ADDRESS_MODIFY));
+       OUT_BATCH(kgem_add_reloc(&sna->kgem, /* instruction */
+                                sna->kgem.nbatch,
+                                sna->render_state.gen6.general_bo,
+                                I915_GEM_DOMAIN_INSTRUCTION << 16,
+                                BASE_ADDRESS_MODIFY));
+       OUT_BATCH(0); /* indirect */
+       OUT_BATCH(kgem_add_reloc(&sna->kgem,
+                                sna->kgem.nbatch,
+                                sna->render_state.gen6.general_bo,
+                                I915_GEM_DOMAIN_INSTRUCTION << 16,
+                                BASE_ADDRESS_MODIFY));
+
+       /* upper bounds, disable */
+       OUT_BATCH(0);
+       OUT_BATCH(BASE_ADDRESS_MODIFY);
+       OUT_BATCH(0);
+       OUT_BATCH(BASE_ADDRESS_MODIFY);
+}
+
+static void
+gen6_emit_viewports(struct sna *sna)
+{
+       OUT_BATCH(GEN6_3DSTATE_VIEWPORT_STATE_POINTERS |
+                 GEN6_3DSTATE_VIEWPORT_STATE_MODIFY_CC |
+                 (4 - 2));
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(sna->render_state.gen6.cc_vp);
+}
+
+static void
+gen6_emit_vs(struct sna *sna)
+{
+       /* disable VS constant buffer */
+       OUT_BATCH(GEN6_3DSTATE_CONSTANT_VS | (5 - 2));
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+
+       OUT_BATCH(GEN6_3DSTATE_VS | (6 - 2));
+       OUT_BATCH(0); /* no VS kernel */
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0); /* pass-through */
+}
+
+static void
+gen6_emit_gs(struct sna *sna)
+{
+       /* disable GS constant buffer */
+       OUT_BATCH(GEN6_3DSTATE_CONSTANT_GS | (5 - 2));
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+
+       OUT_BATCH(GEN6_3DSTATE_GS | (7 - 2));
+       OUT_BATCH(0); /* no GS kernel */
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0); /* pass-through */
+}
+
+static void
+gen6_emit_clip(struct sna *sna)
+{
+       OUT_BATCH(GEN6_3DSTATE_CLIP | (4 - 2));
+       OUT_BATCH(0);
+       OUT_BATCH(0); /* pass-through */
+       OUT_BATCH(0);
+}
+
+static void
+gen6_emit_wm_constants(struct sna *sna)
+{
+       /* disable WM constant buffer */
+       OUT_BATCH(GEN6_3DSTATE_CONSTANT_PS | (5 - 2));
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+}
+
+static void
+gen6_emit_null_depth_buffer(struct sna *sna)
+{
+       OUT_BATCH(GEN6_3DSTATE_DEPTH_BUFFER | (7 - 2));
+       OUT_BATCH(GEN6_SURFACE_NULL << GEN6_3DSTATE_DEPTH_BUFFER_TYPE_SHIFT |
+                 GEN6_DEPTHFORMAT_D32_FLOAT << GEN6_3DSTATE_DEPTH_BUFFER_FORMAT_SHIFT);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+
+       OUT_BATCH(GEN6_3DSTATE_CLEAR_PARAMS | (2 - 2));
+       OUT_BATCH(0);
+}
+
+static void
+gen6_emit_invariant(struct sna *sna)
+{
+       OUT_BATCH(GEN6_PIPELINE_SELECT | PIPELINE_SELECT_3D);
+
+       OUT_BATCH(GEN6_3DSTATE_MULTISAMPLE | (3 - 2));
+       OUT_BATCH(GEN6_3DSTATE_MULTISAMPLE_PIXEL_LOCATION_CENTER |
+                 GEN6_3DSTATE_MULTISAMPLE_NUMSAMPLES_1); /* 1 sample/pixel */
+       OUT_BATCH(0);
+
+       OUT_BATCH(GEN6_3DSTATE_SAMPLE_MASK | (2 - 2));
+       OUT_BATCH(1);
+
+       gen6_emit_urb(sna);
+
+       gen6_emit_state_base_address(sna);
+
+       gen6_emit_viewports(sna);
+       gen6_emit_vs(sna);
+       gen6_emit_gs(sna);
+       gen6_emit_clip(sna);
+       gen6_emit_wm_constants(sna);
+       gen6_emit_null_depth_buffer(sna);
+
+       sna->render_state.gen6.needs_invariant = false;
+}
+
+static bool
+gen6_emit_cc(struct sna *sna, int blend)
+{
+       struct gen6_render_state *render = &sna->render_state.gen6;
+
+       if (render->blend == blend)
+               return blend != NO_BLEND;
+
+       DBG(("%s: blend = %x\n", __FUNCTION__, blend));
+
+       OUT_BATCH(GEN6_3DSTATE_CC_STATE_POINTERS | (4 - 2));
+       OUT_BATCH((render->cc_blend + blend) | 1);
+       if (render->blend == (unsigned)-1) {
+               OUT_BATCH(1);
+               OUT_BATCH(1);
+       } else {
+               OUT_BATCH(0);
+               OUT_BATCH(0);
+       }
+
+       render->blend = blend;
+       return blend != NO_BLEND;
+}
+
+static void
+gen6_emit_sampler(struct sna *sna, uint32_t state)
+{
+       if (sna->render_state.gen6.samplers == state)
+               return;
+
+       sna->render_state.gen6.samplers = state;
+
+       DBG(("%s: sampler = %x\n", __FUNCTION__, state));
+
+       OUT_BATCH(GEN6_3DSTATE_SAMPLER_STATE_POINTERS |
+                 GEN6_3DSTATE_SAMPLER_STATE_MODIFY_PS |
+                 (4 - 2));
+       OUT_BATCH(0); /* VS */
+       OUT_BATCH(0); /* GS */
+       OUT_BATCH(sna->render_state.gen6.wm_state + state);
+}
+
+static void
+gen6_emit_sf(struct sna *sna, bool has_mask)
+{
+       int num_sf_outputs = has_mask ? 2 : 1;
+
+       if (sna->render_state.gen6.num_sf_outputs == num_sf_outputs)
+               return;
+
+       DBG(("%s: num_sf_outputs=%d, read_length=%d, read_offset=%d\n",
+            __FUNCTION__, num_sf_outputs, 1, 0));
+
+       sna->render_state.gen6.num_sf_outputs = num_sf_outputs;
+
+       OUT_BATCH(GEN6_3DSTATE_SF | (20 - 2));
+       OUT_BATCH(num_sf_outputs << GEN6_3DSTATE_SF_NUM_OUTPUTS_SHIFT |
+                 1 << GEN6_3DSTATE_SF_URB_ENTRY_READ_LENGTH_SHIFT |
+                 1 << GEN6_3DSTATE_SF_URB_ENTRY_READ_OFFSET_SHIFT);
+       OUT_BATCH(0);
+       OUT_BATCH(GEN6_3DSTATE_SF_CULL_NONE);
+       OUT_BATCH(2 << GEN6_3DSTATE_SF_TRIFAN_PROVOKE_SHIFT); /* DW4 */
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0); /* DW9 */
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0); /* DW14 */
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0); /* DW19 */
+}
+
+static void
+gen6_emit_wm(struct sna *sna, unsigned int kernel, bool has_mask)
+{
+       const uint32_t *kernels;
+
+       if (sna->render_state.gen6.kernel == kernel)
+               return;
+
+       sna->render_state.gen6.kernel = kernel;
+       kernels = sna->render_state.gen6.wm_kernel[kernel];
+
+       DBG(("%s: switching to %s, num_surfaces=%d (8-pixel? %d, 16-pixel? %d,32-pixel? %d)\n",
+            __FUNCTION__,
+            wm_kernels[kernel].name, wm_kernels[kernel].num_surfaces,
+           kernels[0], kernels[1], kernels[2]));
+
+       OUT_BATCH(GEN6_3DSTATE_WM | (9 - 2));
+       OUT_BATCH(kernels[0] ?: kernels[1] ?: kernels[2]);
+       OUT_BATCH(1 << GEN6_3DSTATE_WM_SAMPLER_COUNT_SHIFT |
+                 wm_kernels[kernel].num_surfaces << GEN6_3DSTATE_WM_BINDING_TABLE_ENTRY_COUNT_SHIFT);
+       OUT_BATCH(0); /* scratch space */
+       OUT_BATCH((kernels[0] ? 4 : kernels[1] ? 6 : 8) << GEN6_3DSTATE_WM_DISPATCH_0_START_GRF_SHIFT |
+                 8 << GEN6_3DSTATE_WM_DISPATCH_1_START_GRF_SHIFT |
+                 6 << GEN6_3DSTATE_WM_DISPATCH_2_START_GRF_SHIFT);
+       OUT_BATCH((sna->render_state.gen6.info->max_wm_threads - 1) << GEN6_3DSTATE_WM_MAX_THREADS_SHIFT |
+                 (kernels[0] ? GEN6_3DSTATE_WM_8_DISPATCH_ENABLE : 0) |
+                 (kernels[1] ? GEN6_3DSTATE_WM_16_DISPATCH_ENABLE : 0) |
+                 (kernels[2] ? GEN6_3DSTATE_WM_32_DISPATCH_ENABLE : 0) |
+                 GEN6_3DSTATE_WM_DISPATCH_ENABLE);
+       OUT_BATCH((1 + has_mask) << GEN6_3DSTATE_WM_NUM_SF_OUTPUTS_SHIFT |
+                 GEN6_3DSTATE_WM_PERSPECTIVE_PIXEL_BARYCENTRIC);
+       OUT_BATCH(kernels[2]);
+       OUT_BATCH(kernels[1]);
+}
+
+static bool
+gen6_emit_binding_table(struct sna *sna, uint16_t offset)
+{
+       if (sna->render_state.gen6.surface_table == offset)
+               return false;
+
+       /* Binding table pointers */
+       OUT_BATCH(GEN6_3DSTATE_BINDING_TABLE_POINTERS |
+                 GEN6_3DSTATE_BINDING_TABLE_MODIFY_PS |
+                 (4 - 2));
+       OUT_BATCH(0);           /* vs */
+       OUT_BATCH(0);           /* gs */
+       /* Only the PS uses the binding table */
+       OUT_BATCH(offset*4);
+
+       sna->render_state.gen6.surface_table = offset;
+       return true;
+}
+
+static bool
+gen6_emit_drawing_rectangle(struct sna *sna,
+                           const struct sna_composite_op *op)
+{
+       uint32_t limit = (op->dst.height - 1) << 16 | (op->dst.width - 1);
+       uint32_t offset = (uint16_t)op->dst.y << 16 | (uint16_t)op->dst.x;
+
+       assert(!too_large(op->dst.x, op->dst.y));
+       assert(!too_large(op->dst.width, op->dst.height));
+
+       if (sna->render_state.gen6.drawrect_limit  == limit &&
+           sna->render_state.gen6.drawrect_offset == offset)
+               return false;
+
+       /* [DevSNB-C+{W/A}] Before any depth stall flush (including those
+        * produced by non-pipelined state commands), software needs to first
+        * send a PIPE_CONTROL with no bits set except Post-Sync Operation !=
+        * 0.
+        *
+        * [Dev-SNB{W/A}]: Pipe-control with CS-stall bit set must be sent
+        * BEFORE the pipe-control with a post-sync op and no write-cache
+        * flushes.
+        */
+       if (!sna->render_state.gen6.first_state_packet) {
+               OUT_BATCH(GEN6_PIPE_CONTROL | (4 - 2));
+               OUT_BATCH(GEN6_PIPE_CONTROL_CS_STALL |
+                         GEN6_PIPE_CONTROL_STALL_AT_SCOREBOARD);
+               OUT_BATCH(0);
+               OUT_BATCH(0);
+       }
+
+       OUT_BATCH(GEN6_PIPE_CONTROL | (4 - 2));
+       OUT_BATCH(GEN6_PIPE_CONTROL_WRITE_TIME);
+       OUT_BATCH(kgem_add_reloc(&sna->kgem, sna->kgem.nbatch,
+                                sna->render_state.gen6.general_bo,
+                                I915_GEM_DOMAIN_INSTRUCTION << 16 |
+                                I915_GEM_DOMAIN_INSTRUCTION,
+                                64));
+       OUT_BATCH(0);
+
+       OUT_BATCH(GEN6_3DSTATE_DRAWING_RECTANGLE | (4 - 2));
+       OUT_BATCH(0);
+       OUT_BATCH(limit);
+       OUT_BATCH(offset);
+
+       sna->render_state.gen6.drawrect_offset = offset;
+       sna->render_state.gen6.drawrect_limit = limit;
+       return true;
+}
+
+static void
+gen6_emit_vertex_elements(struct sna *sna,
+                         const struct sna_composite_op *op)
+{
+       /*
+        * vertex data in vertex buffer
+        *    position: (x, y)
+        *    texture coordinate 0: (u0, v0) if (is_affine is true) else (u0, v0, w0)
+        *    texture coordinate 1 if (has_mask is true): same as above
+        */
+       struct gen6_render_state *render = &sna->render_state.gen6;
+       uint32_t src_format, dw, offset;
+       int id = GEN6_VERTEX(op->u.gen6.flags);
+       bool has_mask;
+
+       DBG(("%s: setup id=%d\n", __FUNCTION__, id));
+
+       if (render->ve_id == id)
+               return;
+       render->ve_id = id;
+
+       if (id == VERTEX_2s2s) {
+               DBG(("%s: setup COPY\n", __FUNCTION__));
+
+               OUT_BATCH(GEN6_3DSTATE_VERTEX_ELEMENTS |
+                         ((2 * (1 + 2)) + 1 - 2));
+
+               OUT_BATCH(id << VE0_VERTEX_BUFFER_INDEX_SHIFT | VE0_VALID |
+                         GEN6_SURFACEFORMAT_R32G32B32A32_FLOAT << VE0_FORMAT_SHIFT |
+                         0 << VE0_OFFSET_SHIFT);
+               OUT_BATCH(GEN6_VFCOMPONENT_STORE_0 << VE1_VFCOMPONENT_0_SHIFT |
+                         GEN6_VFCOMPONENT_STORE_0 << VE1_VFCOMPONENT_1_SHIFT |
+                         GEN6_VFCOMPONENT_STORE_0 << VE1_VFCOMPONENT_2_SHIFT |
+                         GEN6_VFCOMPONENT_STORE_0 << VE1_VFCOMPONENT_3_SHIFT);
+
+               /* x,y */
+               OUT_BATCH(id << VE0_VERTEX_BUFFER_INDEX_SHIFT | VE0_VALID |
+                         GEN6_SURFACEFORMAT_R16G16_SSCALED << VE0_FORMAT_SHIFT |
+                         0 << VE0_OFFSET_SHIFT);
+               OUT_BATCH(GEN6_VFCOMPONENT_STORE_SRC << VE1_VFCOMPONENT_0_SHIFT |
+                         GEN6_VFCOMPONENT_STORE_SRC << VE1_VFCOMPONENT_1_SHIFT |
+                         GEN6_VFCOMPONENT_STORE_0 << VE1_VFCOMPONENT_2_SHIFT |
+                         GEN6_VFCOMPONENT_STORE_1_FLT << VE1_VFCOMPONENT_3_SHIFT);
+
+               /* u0, v0, w0 */
+               OUT_BATCH(id << VE0_VERTEX_BUFFER_INDEX_SHIFT | VE0_VALID |
+                         GEN6_SURFACEFORMAT_R16G16_SSCALED << VE0_FORMAT_SHIFT |
+                         4 << VE0_OFFSET_SHIFT);
+               OUT_BATCH(GEN6_VFCOMPONENT_STORE_SRC << VE1_VFCOMPONENT_0_SHIFT |
+                         GEN6_VFCOMPONENT_STORE_SRC << VE1_VFCOMPONENT_1_SHIFT |
+                         GEN6_VFCOMPONENT_STORE_0 << VE1_VFCOMPONENT_2_SHIFT |
+                         GEN6_VFCOMPONENT_STORE_1_FLT << VE1_VFCOMPONENT_3_SHIFT);
+               return;
+       }
+
+       /* The VUE layout
+        *    dword 0-3: pad (0.0, 0.0, 0.0. 0.0)
+        *    dword 4-7: position (x, y, 1.0, 1.0),
+        *    dword 8-11: texture coordinate 0 (u0, v0, w0, 1.0)
+        *    dword 12-15: texture coordinate 1 (u1, v1, w1, 1.0)
+        *
+        * dword 4-15 are fetched from vertex buffer
+        */
+       has_mask = (id >> 2) != 0;
+       OUT_BATCH(GEN6_3DSTATE_VERTEX_ELEMENTS |
+               ((2 * (3 + has_mask)) + 1 - 2));
+
+       OUT_BATCH(id << VE0_VERTEX_BUFFER_INDEX_SHIFT | VE0_VALID |
+                 GEN6_SURFACEFORMAT_R32G32B32A32_FLOAT << VE0_FORMAT_SHIFT |
+                 0 << VE0_OFFSET_SHIFT);
+       OUT_BATCH(GEN6_VFCOMPONENT_STORE_0 << VE1_VFCOMPONENT_0_SHIFT |
+                 GEN6_VFCOMPONENT_STORE_0 << VE1_VFCOMPONENT_1_SHIFT |
+                 GEN6_VFCOMPONENT_STORE_0 << VE1_VFCOMPONENT_2_SHIFT |
+                 GEN6_VFCOMPONENT_STORE_0 << VE1_VFCOMPONENT_3_SHIFT);
+
+       /* x,y */
+       OUT_BATCH(id << VE0_VERTEX_BUFFER_INDEX_SHIFT | VE0_VALID |
+                 GEN6_SURFACEFORMAT_R16G16_SSCALED << VE0_FORMAT_SHIFT |
+                 0 << VE0_OFFSET_SHIFT);
+       OUT_BATCH(GEN6_VFCOMPONENT_STORE_SRC << VE1_VFCOMPONENT_0_SHIFT |
+                 GEN6_VFCOMPONENT_STORE_SRC << VE1_VFCOMPONENT_1_SHIFT |
+                 GEN6_VFCOMPONENT_STORE_0 << VE1_VFCOMPONENT_2_SHIFT |
+                 GEN6_VFCOMPONENT_STORE_1_FLT << VE1_VFCOMPONENT_3_SHIFT);
+       offset = 4;
+
+       /* u0, v0, w0 */
+       DBG(("%s: first channel %d floats, offset=%d\n", __FUNCTION__, id & 3, offset));
+       dw = GEN6_VFCOMPONENT_STORE_1_FLT << VE1_VFCOMPONENT_3_SHIFT;
+       switch (id & 3) {
+       case 1:
+               src_format = GEN6_SURFACEFORMAT_R32_FLOAT;
+               dw |= GEN6_VFCOMPONENT_STORE_SRC << VE1_VFCOMPONENT_0_SHIFT;
+               dw |= GEN6_VFCOMPONENT_STORE_0 << VE1_VFCOMPONENT_1_SHIFT;
+               dw |= GEN6_VFCOMPONENT_STORE_0 << VE1_VFCOMPONENT_2_SHIFT;
+               break;
+       default:
+               assert(0);
+       case 2:
+               src_format = GEN6_SURFACEFORMAT_R32G32_FLOAT;
+               dw |= GEN6_VFCOMPONENT_STORE_SRC << VE1_VFCOMPONENT_0_SHIFT;
+               dw |= GEN6_VFCOMPONENT_STORE_SRC << VE1_VFCOMPONENT_1_SHIFT;
+               dw |= GEN6_VFCOMPONENT_STORE_0 << VE1_VFCOMPONENT_2_SHIFT;
+               break;
+       case 3:
+               src_format = GEN6_SURFACEFORMAT_R32G32B32_FLOAT;
+               dw |= GEN6_VFCOMPONENT_STORE_SRC << VE1_VFCOMPONENT_0_SHIFT;
+               dw |= GEN6_VFCOMPONENT_STORE_SRC << VE1_VFCOMPONENT_1_SHIFT;
+               dw |= GEN6_VFCOMPONENT_STORE_SRC << VE1_VFCOMPONENT_2_SHIFT;
+               break;
+       }
+       OUT_BATCH(id << VE0_VERTEX_BUFFER_INDEX_SHIFT | VE0_VALID |
+                 src_format << VE0_FORMAT_SHIFT |
+                 offset << VE0_OFFSET_SHIFT);
+       OUT_BATCH(dw);
+       offset += (id & 3) * sizeof(float);
+
+       /* u1, v1, w1 */
+       if (has_mask) {
+               DBG(("%s: second channel %d floats, offset=%d\n", __FUNCTION__, (id >> 2) & 3, offset));
+               dw = GEN6_VFCOMPONENT_STORE_1_FLT << VE1_VFCOMPONENT_3_SHIFT;
+               switch ((id >> 2) & 3) {
+               case 1:
+                       src_format = GEN6_SURFACEFORMAT_R32_FLOAT;
+                       dw |= GEN6_VFCOMPONENT_STORE_SRC << VE1_VFCOMPONENT_0_SHIFT;
+                       dw |= GEN6_VFCOMPONENT_STORE_0 << VE1_VFCOMPONENT_1_SHIFT;
+                       dw |= GEN6_VFCOMPONENT_STORE_0 << VE1_VFCOMPONENT_2_SHIFT;
+                       break;
+               default:
+                       assert(0);
+               case 2:
+                       src_format = GEN6_SURFACEFORMAT_R32G32_FLOAT;
+                       dw |= GEN6_VFCOMPONENT_STORE_SRC << VE1_VFCOMPONENT_0_SHIFT;
+                       dw |= GEN6_VFCOMPONENT_STORE_SRC << VE1_VFCOMPONENT_1_SHIFT;
+                       dw |= GEN6_VFCOMPONENT_STORE_0 << VE1_VFCOMPONENT_2_SHIFT;
+                       break;
+               case 3:
+                       src_format = GEN6_SURFACEFORMAT_R32G32B32_FLOAT;
+                       dw |= GEN6_VFCOMPONENT_STORE_SRC << VE1_VFCOMPONENT_0_SHIFT;
+                       dw |= GEN6_VFCOMPONENT_STORE_SRC << VE1_VFCOMPONENT_1_SHIFT;
+                       dw |= GEN6_VFCOMPONENT_STORE_SRC << VE1_VFCOMPONENT_2_SHIFT;
+                       break;
+               }
+               OUT_BATCH(id << VE0_VERTEX_BUFFER_INDEX_SHIFT | VE0_VALID |
+                         src_format << VE0_FORMAT_SHIFT |
+                         offset << VE0_OFFSET_SHIFT);
+               OUT_BATCH(dw);
+       }
+}
+
+static void
+gen6_emit_flush(struct sna *sna)
+{
+       OUT_BATCH(GEN6_PIPE_CONTROL | (4 - 2));
+       OUT_BATCH(GEN6_PIPE_CONTROL_WC_FLUSH |
+                 GEN6_PIPE_CONTROL_TC_FLUSH |
+                 GEN6_PIPE_CONTROL_CS_STALL);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+}
+
+static void
+gen6_emit_state(struct sna *sna,
+               const struct sna_composite_op *op,
+               uint16_t wm_binding_table)
+{
+       bool need_stall = wm_binding_table & 1;
+
+       if (gen6_emit_cc(sna, GEN6_BLEND(op->u.gen6.flags)))
+               need_stall = false;
+       gen6_emit_sampler(sna, GEN6_SAMPLER(op->u.gen6.flags));
+       gen6_emit_sf(sna, GEN6_VERTEX(op->u.gen6.flags) >> 2);
+       gen6_emit_wm(sna, GEN6_KERNEL(op->u.gen6.flags), GEN6_VERTEX(op->u.gen6.flags) >> 2);
+       gen6_emit_vertex_elements(sna, op);
+
+       need_stall |= gen6_emit_binding_table(sna, wm_binding_table & ~1);
+       if (gen6_emit_drawing_rectangle(sna, op))
+               need_stall = false;
+       if (kgem_bo_is_dirty(op->src.bo) || kgem_bo_is_dirty(op->mask.bo)) {
+               gen6_emit_flush(sna);
+               kgem_clear_dirty(&sna->kgem);
+               if (op->dst.bo->exec)
+                       kgem_bo_mark_dirty(op->dst.bo);
+               need_stall = false;
+       }
+       if (need_stall) {
+               OUT_BATCH(GEN6_PIPE_CONTROL | (4 - 2));
+               OUT_BATCH(GEN6_PIPE_CONTROL_CS_STALL |
+                         GEN6_PIPE_CONTROL_STALL_AT_SCOREBOARD);
+               OUT_BATCH(0);
+               OUT_BATCH(0);
+       }
+       sna->render_state.gen6.first_state_packet = false;
+}
+
+static void gen6_magic_ca_pass(struct sna *sna,
+                              const struct sna_composite_op *op)
+{
+       struct gen6_render_state *state = &sna->render_state.gen6;
+
+       if (!op->need_magic_ca_pass)
+               return;
+
+       DBG(("%s: CA fixup (%d -> %d)\n", __FUNCTION__,
+            sna->render.vertex_start, sna->render.vertex_index));
+
+       gen6_emit_flush(sna);
+
+       gen6_emit_cc(sna, gen6_get_blend(PictOpAdd, true, op->dst.format));
+       gen6_emit_wm(sna,
+                    gen6_choose_composite_kernel(PictOpAdd,
+                                                 true, true,
+                                                 op->is_affine),
+                    true);
+
+       OUT_BATCH(GEN6_3DPRIMITIVE |
+                 GEN6_3DPRIMITIVE_VERTEX_SEQUENTIAL |
+                 _3DPRIM_RECTLIST << GEN6_3DPRIMITIVE_TOPOLOGY_SHIFT |
+                 0 << 9 |
+                 4);
+       OUT_BATCH(sna->render.vertex_index - sna->render.vertex_start);
+       OUT_BATCH(sna->render.vertex_start);
+       OUT_BATCH(1);   /* single instance */
+       OUT_BATCH(0);   /* start instance location */
+       OUT_BATCH(0);   /* index buffer offset, ignored */
+
+       state->last_primitive = sna->kgem.nbatch;
+}
+
+static void gen6_vertex_flush(struct sna *sna)
+{
+       assert(sna->render_state.gen6.vertex_offset);
+
+       DBG(("%s[%x] = %d\n", __FUNCTION__,
+            4*sna->render_state.gen6.vertex_offset,
+            sna->render.vertex_index - sna->render.vertex_start));
+       sna->kgem.batch[sna->render_state.gen6.vertex_offset] =
+               sna->render.vertex_index - sna->render.vertex_start;
+       sna->render_state.gen6.vertex_offset = 0;
+}
+
+static int gen6_vertex_finish(struct sna *sna)
+{
+       struct kgem_bo *bo;
+       unsigned int i;
+
+       DBG(("%s: used=%d / %d\n", __FUNCTION__,
+            sna->render.vertex_used, sna->render.vertex_size));
+       assert(sna->render.vertex_used);
+       assert(sna->render.nvertex_reloc);
+
+       /* Note: we only need dword alignment (currently) */
+
+       bo = sna->render.vbo;
+       if (bo) {
+               if (sna->render_state.gen6.vertex_offset)
+                       gen6_vertex_flush(sna);
+
+               for (i = 0; i < sna->render.nvertex_reloc; i++) {
+                       DBG(("%s: reloc[%d] = %d\n", __FUNCTION__,
+                            i, sna->render.vertex_reloc[i]));
+
+                       sna->kgem.batch[sna->render.vertex_reloc[i]] =
+                               kgem_add_reloc(&sna->kgem,
+                                              sna->render.vertex_reloc[i], bo,
+                                              I915_GEM_DOMAIN_VERTEX << 16,
+                                              0);
+                       sna->kgem.batch[sna->render.vertex_reloc[i]+1] =
+                               kgem_add_reloc(&sna->kgem,
+                                              sna->render.vertex_reloc[i]+1, bo,
+                                              I915_GEM_DOMAIN_VERTEX << 16,
+                                              sna->render.vertex_used * 4 - 1);
+               }
+
+               sna->render.nvertex_reloc = 0;
+               sna->render.vertex_used = 0;
+               sna->render.vertex_index = 0;
+               sna->render_state.gen6.vb_id = 0;
+
+               kgem_bo_destroy(&sna->kgem, bo);
+       }
+
+       sna->render.vertices = NULL;
+       sna->render.vbo = kgem_create_linear(&sna->kgem,
+                                            256*1024, CREATE_GTT_MAP);
+       if (sna->render.vbo)
+               sna->render.vertices = kgem_bo_map(&sna->kgem, sna->render.vbo);
+       if (sna->render.vertices == NULL) {
+               if (sna->render.vbo)
+                       kgem_bo_destroy(&sna->kgem, sna->render.vbo);
+               sna->render.vbo = NULL;
+               return 0;
+       }
+
+       DBG(("%s: create vbo handle=%d\n", __FUNCTION__, sna->render.vbo->handle));
+
+       kgem_bo_sync__cpu(&sna->kgem, sna->render.vbo);
+       if (sna->render.vertex_used) {
+               DBG(("%s: copying initial buffer x %d to handle=%d\n",
+                    __FUNCTION__,
+                    sna->render.vertex_used,
+                    sna->render.vbo->handle));
+               memcpy(sna->render.vertices,
+                      sna->render.vertex_data,
+                      sizeof(float)*sna->render.vertex_used);
+       }
+       sna->render.vertex_size = 64 * 1024 - 1;
+       return sna->render.vertex_size - sna->render.vertex_used;
+}
+
+static void gen6_vertex_close(struct sna *sna)
+{
+       struct kgem_bo *bo, *free_bo = NULL;
+       unsigned int i, delta = 0;
+
+       assert(sna->render_state.gen6.vertex_offset == 0);
+
+       if (!sna->render_state.gen6.vb_id)
+               return;
+
+       DBG(("%s: used=%d, vbo active? %d\n",
+            __FUNCTION__, sna->render.vertex_used, sna->render.vbo ? sna->render.vbo->handle : 0));
+
+       bo = sna->render.vbo;
+       if (bo) {
+               if (sna->render.vertex_size - sna->render.vertex_used < 64) {
+                       DBG(("%s: discarding vbo (full), handle=%d\n", __FUNCTION__, sna->render.vbo->handle));
+                       sna->render.vbo = NULL;
+                       sna->render.vertices = sna->render.vertex_data;
+                       sna->render.vertex_size = ARRAY_SIZE(sna->render.vertex_data);
+                       free_bo = bo;
+               }
+       } else {
+               if (sna->kgem.nbatch + sna->render.vertex_used <= sna->kgem.surface) {
+                       DBG(("%s: copy to batch: %d @ %d\n", __FUNCTION__,
+                            sna->render.vertex_used, sna->kgem.nbatch));
+                       memcpy(sna->kgem.batch + sna->kgem.nbatch,
+                              sna->render.vertex_data,
+                              sna->render.vertex_used * 4);
+                       delta = sna->kgem.nbatch * 4;
+                       bo = NULL;
+                       sna->kgem.nbatch += sna->render.vertex_used;
+               } else {
+                       bo = kgem_create_linear(&sna->kgem,
+                                               4*sna->render.vertex_used, 0);
+                       if (bo && !kgem_bo_write(&sna->kgem, bo,
+                                                sna->render.vertex_data,
+                                                4*sna->render.vertex_used)) {
+                               kgem_bo_destroy(&sna->kgem, bo);
+                               bo = NULL;
+                       }
+                       DBG(("%s: new vbo: %d\n", __FUNCTION__,
+                            sna->render.vertex_used));
+                       free_bo = bo;
+               }
+       }
+
+       assert(sna->render.nvertex_reloc);
+       for (i = 0; i < sna->render.nvertex_reloc; i++) {
+               DBG(("%s: reloc[%d] = %d\n", __FUNCTION__,
+                    i, sna->render.vertex_reloc[i]));
+
+               sna->kgem.batch[sna->render.vertex_reloc[i]] =
+                       kgem_add_reloc(&sna->kgem,
+                                      sna->render.vertex_reloc[i], bo,
+                                      I915_GEM_DOMAIN_VERTEX << 16,
+                                      delta);
+               sna->kgem.batch[sna->render.vertex_reloc[i]+1] =
+                       kgem_add_reloc(&sna->kgem,
+                                      sna->render.vertex_reloc[i]+1, bo,
+                                      I915_GEM_DOMAIN_VERTEX << 16,
+                                      delta + sna->render.vertex_used * 4 - 1);
+       }
+       sna->render.nvertex_reloc = 0;
+
+       if (sna->render.vbo == NULL) {
+               sna->render.vertex_used = 0;
+               sna->render.vertex_index = 0;
+               assert(sna->render.vertices == sna->render.vertex_data);
+               assert(sna->render.vertex_size == ARRAY_SIZE(sna->render.vertex_data));
+       }
+
+       if (free_bo)
+               kgem_bo_destroy(&sna->kgem, free_bo);
+}
+
+typedef struct gen6_surface_state_padded {
+       struct gen6_surface_state state;
+       char pad[32 - sizeof(struct gen6_surface_state)];
+} gen6_surface_state_padded;
+
+static void null_create(struct sna_static_stream *stream)
+{
+       /* A bunch of zeros useful for legacy border color and depth-stencil */
+       sna_static_stream_map(stream, 64, 64);
+}
+
+static void scratch_create(struct sna_static_stream *stream)
+{
+       /* 64 bytes of scratch space for random writes, such as
+        * the pipe-control w/a.
+        */
+       sna_static_stream_map(stream, 64, 64);
+}
+
+static void
+sampler_state_init(struct gen6_sampler_state *sampler_state,
+                  sampler_filter_t filter,
+                  sampler_extend_t extend)
+{
+       sampler_state->ss0.lod_preclamp = 1;    /* GL mode */
+
+       /* We use the legacy mode to get the semantics specified by
+        * the Render extension. */
+       sampler_state->ss0.border_color_mode = GEN6_BORDER_COLOR_MODE_LEGACY;
+
+       switch (filter) {
+       default:
+       case SAMPLER_FILTER_NEAREST:
+               sampler_state->ss0.min_filter = GEN6_MAPFILTER_NEAREST;
+               sampler_state->ss0.mag_filter = GEN6_MAPFILTER_NEAREST;
+               break;
+       case SAMPLER_FILTER_BILINEAR:
+               sampler_state->ss0.min_filter = GEN6_MAPFILTER_LINEAR;
+               sampler_state->ss0.mag_filter = GEN6_MAPFILTER_LINEAR;
+               break;
+       }
+
+       switch (extend) {
+       default:
+       case SAMPLER_EXTEND_NONE:
+               sampler_state->ss1.r_wrap_mode = GEN6_TEXCOORDMODE_CLAMP_BORDER;
+               sampler_state->ss1.s_wrap_mode = GEN6_TEXCOORDMODE_CLAMP_BORDER;
+               sampler_state->ss1.t_wrap_mode = GEN6_TEXCOORDMODE_CLAMP_BORDER;
+               break;
+       case SAMPLER_EXTEND_REPEAT:
+               sampler_state->ss1.r_wrap_mode = GEN6_TEXCOORDMODE_WRAP;
+               sampler_state->ss1.s_wrap_mode = GEN6_TEXCOORDMODE_WRAP;
+               sampler_state->ss1.t_wrap_mode = GEN6_TEXCOORDMODE_WRAP;
+               break;
+       case SAMPLER_EXTEND_PAD:
+               sampler_state->ss1.r_wrap_mode = GEN6_TEXCOORDMODE_CLAMP;
+               sampler_state->ss1.s_wrap_mode = GEN6_TEXCOORDMODE_CLAMP;
+               sampler_state->ss1.t_wrap_mode = GEN6_TEXCOORDMODE_CLAMP;
+               break;
+       case SAMPLER_EXTEND_REFLECT:
+               sampler_state->ss1.r_wrap_mode = GEN6_TEXCOORDMODE_MIRROR;
+               sampler_state->ss1.s_wrap_mode = GEN6_TEXCOORDMODE_MIRROR;
+               sampler_state->ss1.t_wrap_mode = GEN6_TEXCOORDMODE_MIRROR;
+               break;
+       }
+}
+
+static void
+sampler_copy_init(struct gen6_sampler_state *ss)
+{
+       sampler_state_init(ss, SAMPLER_FILTER_NEAREST, SAMPLER_EXTEND_NONE);
+       ss->ss3.non_normalized_coord = 1;
+
+       sampler_state_init(ss+1, SAMPLER_FILTER_NEAREST, SAMPLER_EXTEND_NONE);
+}
+
+static void
+sampler_fill_init(struct gen6_sampler_state *ss)
+{
+       sampler_state_init(ss, SAMPLER_FILTER_NEAREST, SAMPLER_EXTEND_REPEAT);
+       ss->ss3.non_normalized_coord = 1;
+
+       sampler_state_init(ss+1, SAMPLER_FILTER_NEAREST, SAMPLER_EXTEND_NONE);
+}
+
+static uint32_t gen6_create_cc_viewport(struct sna_static_stream *stream)
+{
+       struct gen6_cc_viewport vp;
+
+       vp.min_depth = -1.e35;
+       vp.max_depth = 1.e35;
+
+       return sna_static_stream_add(stream, &vp, sizeof(vp), 32);
+}
+
+static uint32_t
+gen6_tiling_bits(uint32_t tiling)
+{
+       switch (tiling) {
+       default: assert(0);
+       case I915_TILING_NONE: return 0;
+       case I915_TILING_X: return GEN6_SURFACE_TILED;
+       case I915_TILING_Y: return GEN6_SURFACE_TILED | GEN6_SURFACE_TILED_Y;
+       }
+}
+
+/**
+ * Sets up the common fields for a surface state buffer for the given
+ * picture in the given surface state buffer.
+ */
+static int
+gen6_bind_bo(struct sna *sna,
+            struct kgem_bo *bo,
+            uint32_t width,
+            uint32_t height,
+            uint32_t format,
+            bool is_dst)
+{
+       uint32_t *ss;
+       uint32_t domains;
+       uint16_t offset;
+
+       /* After the first bind, we manage the cache domains within the batch */
+       offset = kgem_bo_get_binding(bo, format);
+       if (offset) {
+               DBG(("[%x]  bo(handle=%d), format=%d, reuse %s binding\n",
+                    offset, bo->handle, format,
+                    is_dst ? "render" : "sampler"));
+               if (is_dst)
+                       kgem_bo_mark_dirty(bo);
+               return offset * sizeof(uint32_t);
+       }
+
+       offset = sna->kgem.surface -=
+               sizeof(struct gen6_surface_state_padded) / sizeof(uint32_t);
+       ss = sna->kgem.batch + offset;
+       ss[0] = (GEN6_SURFACE_2D << GEN6_SURFACE_TYPE_SHIFT |
+                GEN6_SURFACE_BLEND_ENABLED |
+                format << GEN6_SURFACE_FORMAT_SHIFT);
+       if (is_dst)
+               domains = I915_GEM_DOMAIN_RENDER << 16 |I915_GEM_DOMAIN_RENDER;
+       else
+               domains = I915_GEM_DOMAIN_SAMPLER << 16;
+       ss[1] = kgem_add_reloc(&sna->kgem, offset + 1, bo, domains, 0);
+       ss[2] = ((width - 1)  << GEN6_SURFACE_WIDTH_SHIFT |
+                (height - 1) << GEN6_SURFACE_HEIGHT_SHIFT);
+       assert(bo->pitch <= (1 << 18));
+       ss[3] = (gen6_tiling_bits(bo->tiling) |
+                (bo->pitch - 1) << GEN6_SURFACE_PITCH_SHIFT);
+       ss[4] = 0;
+       ss[5] = 0;
+
+       kgem_bo_set_binding(bo, format, offset);
+
+       DBG(("[%x] bind bo(handle=%d, addr=%d), format=%d, width=%d, height=%d, pitch=%d, tiling=%d -> %s\n",
+            offset, bo->handle, ss[1],
+            format, width, height, bo->pitch, bo->tiling,
+            domains & 0xffff ? "render" : "sampler"));
+
+       return offset * sizeof(uint32_t);
+}
+
+fastcall static void
+gen6_emit_composite_primitive_solid(struct sna *sna,
+                                   const struct sna_composite_op *op,
+                                   const struct sna_composite_rectangles *r)
+{
+       float *v;
+       union {
+               struct sna_coordinate p;
+               float f;
+       } dst;
+
+       DBG(("%s: [%d+9] = (%d, %d)x(%d, %d)\n", __FUNCTION__,
+            sna->render.vertex_used, r->dst.x, r->dst.y, r->width, r->height));
+
+       v = sna->render.vertices + sna->render.vertex_used;
+       sna->render.vertex_used += 9;
+       assert(sna->render.vertex_used <= sna->render.vertex_size);
+       assert(!too_large(op->dst.x + r->dst.x + r->width,
+                         op->dst.y + r->dst.y + r->height));
+
+       dst.p.x = r->dst.x + r->width;
+       dst.p.y = r->dst.y + r->height;
+       v[0] = dst.f;
+       dst.p.x = r->dst.x;
+       v[3] = dst.f;
+       dst.p.y = r->dst.y;
+       v[6] = dst.f;
+
+       v[5] = v[2] = v[1] = 1.;
+       v[8] = v[7] = v[4] = 0.;
+}
+
+fastcall static void
+gen6_emit_composite_primitive_identity_source(struct sna *sna,
+                                             const struct sna_composite_op *op,
+                                             const struct sna_composite_rectangles *r)
+{
+       union {
+               struct sna_coordinate p;
+               float f;
+       } dst;
+       float *v;
+
+       v = sna->render.vertices + sna->render.vertex_used;
+       sna->render.vertex_used += 9;
+
+       dst.p.x = r->dst.x + r->width;
+       dst.p.y = r->dst.y + r->height;
+       v[0] = dst.f;
+       dst.p.x = r->dst.x;
+       v[3] = dst.f;
+       dst.p.y = r->dst.y;
+       v[6] = dst.f;
+
+       v[7] = v[4] = (r->src.x + op->src.offset[0]) * op->src.scale[0];
+       v[1] = v[4] + r->width * op->src.scale[0];
+
+       v[8] = (r->src.y + op->src.offset[1]) * op->src.scale[1];
+       v[5] = v[2] = v[8] + r->height * op->src.scale[1];
+}
+
+fastcall static void
+gen6_emit_composite_primitive_simple_source(struct sna *sna,
+                                           const struct sna_composite_op *op,
+                                           const struct sna_composite_rectangles *r)
+{
+       float *v;
+       union {
+               struct sna_coordinate p;
+               float f;
+       } dst;
+
+       float xx = op->src.transform->matrix[0][0];
+       float x0 = op->src.transform->matrix[0][2];
+       float yy = op->src.transform->matrix[1][1];
+       float y0 = op->src.transform->matrix[1][2];
+       float sx = op->src.scale[0];
+       float sy = op->src.scale[1];
+       int16_t tx = op->src.offset[0];
+       int16_t ty = op->src.offset[1];
+
+       v = sna->render.vertices + sna->render.vertex_used;
+       sna->render.vertex_used += 3*3;
+
+       dst.p.x = r->dst.x + r->width;
+       dst.p.y = r->dst.y + r->height;
+       v[0] = dst.f;
+       v[1] = ((r->src.x + r->width + tx) * xx + x0) * sx;
+       v[5] = v[2] = ((r->src.y + r->height + ty) * yy + y0) * sy;
+
+       dst.p.x = r->dst.x;
+       v[3] = dst.f;
+       v[7] = v[4] = ((r->src.x + tx) * xx + x0) * sx;
+
+       dst.p.y = r->dst.y;
+       v[6] = dst.f;
+       v[8] = ((r->src.y + ty) * yy + y0) * sy;
+}
+
+fastcall static void
+gen6_emit_composite_primitive_affine_source(struct sna *sna,
+                                           const struct sna_composite_op *op,
+                                           const struct sna_composite_rectangles *r)
+{
+       union {
+               struct sna_coordinate p;
+               float f;
+       } dst;
+       float *v;
+
+       v = sna->render.vertices + sna->render.vertex_used;
+       sna->render.vertex_used += 9;
+
+       dst.p.x = r->dst.x + r->width;
+       dst.p.y = r->dst.y + r->height;
+       v[0] = dst.f;
+       _sna_get_transformed_coordinates(op->src.offset[0] + r->src.x + r->width,
+                                        op->src.offset[1] + r->src.y + r->height,
+                                        op->src.transform,
+                                        &v[1], &v[2]);
+       v[1] *= op->src.scale[0];
+       v[2] *= op->src.scale[1];
+
+       dst.p.x = r->dst.x;
+       v[3] = dst.f;
+       _sna_get_transformed_coordinates(op->src.offset[0] + r->src.x,
+                                        op->src.offset[1] + r->src.y + r->height,
+                                        op->src.transform,
+                                        &v[4], &v[5]);
+       v[4] *= op->src.scale[0];
+       v[5] *= op->src.scale[1];
+
+       dst.p.y = r->dst.y;
+       v[6] = dst.f;
+       _sna_get_transformed_coordinates(op->src.offset[0] + r->src.x,
+                                        op->src.offset[1] + r->src.y,
+                                        op->src.transform,
+                                        &v[7], &v[8]);
+       v[7] *= op->src.scale[0];
+       v[8] *= op->src.scale[1];
+}
+
+fastcall static void
+gen6_emit_composite_primitive_identity_source_mask(struct sna *sna,
+                                                  const struct sna_composite_op *op,
+                                                  const struct sna_composite_rectangles *r)
+{
+       union {
+               struct sna_coordinate p;
+               float f;
+       } dst;
+       float src_x, src_y;
+       float msk_x, msk_y;
+       float w, h;
+       float *v;
+
+       src_x = r->src.x + op->src.offset[0];
+       src_y = r->src.y + op->src.offset[1];
+       msk_x = r->mask.x + op->mask.offset[0];
+       msk_y = r->mask.y + op->mask.offset[1];
+       w = r->width;
+       h = r->height;
+
+       v = sna->render.vertices + sna->render.vertex_used;
+       sna->render.vertex_used += 15;
+
+       dst.p.x = r->dst.x + r->width;
+       dst.p.y = r->dst.y + r->height;
+       v[0] = dst.f;
+       v[1] = (src_x + w) * op->src.scale[0];
+       v[2] = (src_y + h) * op->src.scale[1];
+       v[3] = (msk_x + w) * op->mask.scale[0];
+       v[4] = (msk_y + h) * op->mask.scale[1];
+
+       dst.p.x = r->dst.x;
+       v[5] = dst.f;
+       v[6] = src_x * op->src.scale[0];
+       v[7] = v[2];
+       v[8] = msk_x * op->mask.scale[0];
+       v[9] = v[4];
+
+       dst.p.y = r->dst.y;
+       v[10] = dst.f;
+       v[11] = v[6];
+       v[12] = src_y * op->src.scale[1];
+       v[13] = v[8];
+       v[14] = msk_y * op->mask.scale[1];
+}
+
+inline static void
+gen6_emit_composite_texcoord(struct sna *sna,
+                            const struct sna_composite_channel *channel,
+                            int16_t x, int16_t y)
+{
+       x += channel->offset[0];
+       y += channel->offset[1];
+
+       if (channel->is_affine) {
+               float s, t;
+
+               sna_get_transformed_coordinates(x, y,
+                                               channel->transform,
+                                               &s, &t);
+               OUT_VERTEX_F(s * channel->scale[0]);
+               OUT_VERTEX_F(t * channel->scale[1]);
+       } else {
+               float s, t, w;
+
+               sna_get_transformed_coordinates_3d(x, y,
+                                                  channel->transform,
+                                                  &s, &t, &w);
+               OUT_VERTEX_F(s * channel->scale[0]);
+               OUT_VERTEX_F(t * channel->scale[1]);
+               OUT_VERTEX_F(w);
+       }
+}
+
+static void
+gen6_emit_composite_vertex(struct sna *sna,
+                          const struct sna_composite_op *op,
+                          int16_t srcX, int16_t srcY,
+                          int16_t mskX, int16_t mskY,
+                          int16_t dstX, int16_t dstY)
+{
+       OUT_VERTEX(dstX, dstY);
+       gen6_emit_composite_texcoord(sna, &op->src, srcX, srcY);
+       gen6_emit_composite_texcoord(sna, &op->mask, mskX, mskY);
+}
+
+fastcall static void
+gen6_emit_composite_primitive(struct sna *sna,
+                             const struct sna_composite_op *op,
+                             const struct sna_composite_rectangles *r)
+{
+       gen6_emit_composite_vertex(sna, op,
+                                  r->src.x + r->width,  r->src.y + r->height,
+                                  r->mask.x + r->width, r->mask.y + r->height,
+                                  r->dst.x + r->width, r->dst.y + r->height);
+       gen6_emit_composite_vertex(sna, op,
+                                  r->src.x,  r->src.y + r->height,
+                                  r->mask.x, r->mask.y + r->height,
+                                  r->dst.x,  r->dst.y + r->height);
+       gen6_emit_composite_vertex(sna, op,
+                                  r->src.x,  r->src.y,
+                                  r->mask.x, r->mask.y,
+                                  r->dst.x,  r->dst.y);
+}
+
+static void gen6_emit_vertex_buffer(struct sna *sna,
+                                   const struct sna_composite_op *op)
+{
+       int id = GEN6_VERTEX(op->u.gen6.flags);
+
+       OUT_BATCH(GEN6_3DSTATE_VERTEX_BUFFERS | 3);
+       OUT_BATCH(id << VB0_BUFFER_INDEX_SHIFT | VB0_VERTEXDATA |
+                 4*op->floats_per_vertex << VB0_BUFFER_PITCH_SHIFT);
+       sna->render.vertex_reloc[sna->render.nvertex_reloc++] = sna->kgem.nbatch;
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+
+       sna->render_state.gen6.vb_id |= 1 << id;
+}
+
+static void gen6_emit_primitive(struct sna *sna)
+{
+       if (sna->kgem.nbatch == sna->render_state.gen6.last_primitive) {
+               DBG(("%s: continuing previous primitive, start=%d, index=%d\n",
+                    __FUNCTION__,
+                    sna->render.vertex_start,
+                    sna->render.vertex_index));
+               sna->render_state.gen6.vertex_offset = sna->kgem.nbatch - 5;
+               return;
+       }
+
+       OUT_BATCH(GEN6_3DPRIMITIVE |
+                 GEN6_3DPRIMITIVE_VERTEX_SEQUENTIAL |
+                 _3DPRIM_RECTLIST << GEN6_3DPRIMITIVE_TOPOLOGY_SHIFT |
+                 0 << 9 |
+                 4);
+       sna->render_state.gen6.vertex_offset = sna->kgem.nbatch;
+       OUT_BATCH(0);   /* vertex count, to be filled in later */
+       OUT_BATCH(sna->render.vertex_index);
+       OUT_BATCH(1);   /* single instance */
+       OUT_BATCH(0);   /* start instance location */
+       OUT_BATCH(0);   /* index buffer offset, ignored */
+       sna->render.vertex_start = sna->render.vertex_index;
+       DBG(("%s: started new primitive: index=%d\n",
+            __FUNCTION__, sna->render.vertex_start));
+
+       sna->render_state.gen6.last_primitive = sna->kgem.nbatch;
+}
+
+static bool gen6_rectangle_begin(struct sna *sna,
+                                const struct sna_composite_op *op)
+{
+       int id = 1 << GEN6_VERTEX(op->u.gen6.flags);
+       int ndwords;
+
+       ndwords = op->need_magic_ca_pass ? 60 : 6;
+       if ((sna->render_state.gen6.vb_id & id) == 0)
+               ndwords += 5;
+       if (!kgem_check_batch(&sna->kgem, ndwords))
+               return false;
+
+       if ((sna->render_state.gen6.vb_id & id) == 0)
+               gen6_emit_vertex_buffer(sna, op);
+
+       gen6_emit_primitive(sna);
+       return true;
+}
+
+static int gen6_get_rectangles__flush(struct sna *sna,
+                                     const struct sna_composite_op *op)
+{
+       if (!kgem_check_batch(&sna->kgem, op->need_magic_ca_pass ? 65 : 5))
+               return 0;
+       if (!kgem_check_exec(&sna->kgem, 1))
+               return 0;
+       if (!kgem_check_reloc(&sna->kgem, 2))
+               return 0;
+
+       if (op->need_magic_ca_pass && sna->render.vbo)
+               return 0;
+
+       return gen6_vertex_finish(sna);
+}
+
+inline static int gen6_get_rectangles(struct sna *sna,
+                                     const struct sna_composite_op *op,
+                                     int want,
+                                     void (*emit_state)(struct sna *, const struct sna_composite_op *op))
+{
+       int rem;
+
+start:
+       rem = vertex_space(sna);
+       if (rem < op->floats_per_rect) {
+               DBG(("flushing vbo for %s: %d < %d\n",
+                    __FUNCTION__, rem, op->floats_per_rect));
+               rem = gen6_get_rectangles__flush(sna, op);
+               if (unlikely(rem == 0))
+                       goto flush;
+       }
+
+       if (unlikely(sna->render_state.gen6.vertex_offset == 0 &&
+                    !gen6_rectangle_begin(sna, op)))
+               goto flush;
+
+       if (want > 1 && want * op->floats_per_rect > rem)
+               want = rem / op->floats_per_rect;
+
+       assert(want > 0);
+       sna->render.vertex_index += 3*want;
+       return want;
+
+flush:
+       if (sna->render_state.gen6.vertex_offset) {
+               gen6_vertex_flush(sna);
+               gen6_magic_ca_pass(sna, op);
+       }
+       _kgem_submit(&sna->kgem);
+       emit_state(sna, op);
+       goto start;
+}
+
+inline static uint32_t *gen6_composite_get_binding_table(struct sna *sna,
+                                                        uint16_t *offset)
+{
+       uint32_t *table;
+
+       sna->kgem.surface -=
+               sizeof(struct gen6_surface_state_padded) / sizeof(uint32_t);
+       /* Clear all surplus entries to zero in case of prefetch */
+       table = memset(sna->kgem.batch + sna->kgem.surface,
+                      0, sizeof(struct gen6_surface_state_padded));
+
+       DBG(("%s(%x)\n", __FUNCTION__, 4*sna->kgem.surface));
+
+       *offset = sna->kgem.surface;
+       return table;
+}
+
+static uint32_t
+gen6_choose_composite_vertex_buffer(const struct sna_composite_op *op)
+{
+       int id = 2 + !op->is_affine;
+       if (op->mask.bo)
+               id |= id << 2;
+       assert(id > 0 && id < 16);
+       return id;
+}
+
+static void
+gen6_get_batch(struct sna *sna)
+{
+       kgem_set_mode(&sna->kgem, KGEM_RENDER);
+
+       if (!kgem_check_batch_with_surfaces(&sna->kgem, 150, 4)) {
+               DBG(("%s: flushing batch: %d < %d+%d\n",
+                    __FUNCTION__, sna->kgem.surface - sna->kgem.nbatch,
+                    150, 4*8));
+               kgem_submit(&sna->kgem);
+               _kgem_set_mode(&sna->kgem, KGEM_RENDER);
+       }
+
+       if (sna->render_state.gen6.needs_invariant)
+               gen6_emit_invariant(sna);
+}
+
+static void gen6_emit_composite_state(struct sna *sna,
+                                     const struct sna_composite_op *op)
+{
+       uint32_t *binding_table;
+       uint16_t offset;
+       bool dirty;
+
+       gen6_get_batch(sna);
+       dirty = kgem_bo_is_dirty(op->dst.bo);
+
+       binding_table = gen6_composite_get_binding_table(sna, &offset);
+
+       binding_table[0] =
+               gen6_bind_bo(sna,
+                           op->dst.bo, op->dst.width, op->dst.height,
+                           gen6_get_dest_format(op->dst.format),
+                           true);
+       binding_table[1] =
+               gen6_bind_bo(sna,
+                            op->src.bo, op->src.width, op->src.height,
+                            op->src.card_format,
+                            false);
+       if (op->mask.bo) {
+               binding_table[2] =
+                       gen6_bind_bo(sna,
+                                    op->mask.bo,
+                                    op->mask.width,
+                                    op->mask.height,
+                                    op->mask.card_format,
+                                    false);
+       }
+
+       if (sna->kgem.surface == offset &&
+           *(uint64_t *)(sna->kgem.batch + sna->render_state.gen6.surface_table) == *(uint64_t*)binding_table &&
+           (op->mask.bo == NULL ||
+            sna->kgem.batch[sna->render_state.gen6.surface_table+2] == binding_table[2])) {
+               sna->kgem.surface += sizeof(struct gen6_surface_state_padded) / sizeof(uint32_t);
+               offset = sna->render_state.gen6.surface_table;
+       }
+
+       gen6_emit_state(sna, op, offset | dirty);
+}
+
+static void
+gen6_align_vertex(struct sna *sna, const struct sna_composite_op *op)
+{
+       assert (sna->render_state.gen6.vertex_offset == 0);
+       if (op->floats_per_vertex != sna->render_state.gen6.floats_per_vertex) {
+               if (sna->render.vertex_size - sna->render.vertex_used < 2*op->floats_per_rect)
+                       /* XXX propagate failure */
+                       gen6_vertex_finish(sna);
+
+               DBG(("aligning vertex: was %d, now %d floats per vertex, %d->%d\n",
+                    sna->render_state.gen6.floats_per_vertex,
+                    op->floats_per_vertex,
+                    sna->render.vertex_index,
+                    (sna->render.vertex_used + op->floats_per_vertex - 1) / op->floats_per_vertex));
+               sna->render.vertex_index = (sna->render.vertex_used + op->floats_per_vertex - 1) / op->floats_per_vertex;
+               sna->render.vertex_used = sna->render.vertex_index * op->floats_per_vertex;
+               sna->render_state.gen6.floats_per_vertex = op->floats_per_vertex;
+       }
+}
+
+fastcall static void
+gen6_render_composite_blt(struct sna *sna,
+                         const struct sna_composite_op *op,
+                         const struct sna_composite_rectangles *r)
+{
+       gen6_get_rectangles(sna, op, 1, gen6_emit_composite_state);
+       op->prim_emit(sna, op, r);
+}
+
+fastcall static void
+gen6_render_composite_box(struct sna *sna,
+                         const struct sna_composite_op *op,
+                         const BoxRec *box)
+{
+       struct sna_composite_rectangles r;
+
+       gen6_get_rectangles(sna, op, 1, gen6_emit_composite_state);
+
+       DBG(("  %s: (%d, %d), (%d, %d)\n",
+            __FUNCTION__,
+            box->x1, box->y1, box->x2, box->y2));
+
+       r.dst.x = box->x1;
+       r.dst.y = box->y1;
+       r.width  = box->x2 - box->x1;
+       r.height = box->y2 - box->y1;
+       r.src = r.mask = r.dst;
+
+       op->prim_emit(sna, op, &r);
+}
+
+static void
+gen6_render_composite_boxes(struct sna *sna,
+                           const struct sna_composite_op *op,
+                           const BoxRec *box, int nbox)
+{
+       DBG(("composite_boxes(%d)\n", nbox));
+
+       do {
+               int nbox_this_time;
+
+               nbox_this_time = gen6_get_rectangles(sna, op, nbox,
+                                                    gen6_emit_composite_state);
+               nbox -= nbox_this_time;
+
+               do {
+                       struct sna_composite_rectangles r;
+
+                       DBG(("  %s: (%d, %d), (%d, %d)\n",
+                            __FUNCTION__,
+                            box->x1, box->y1, box->x2, box->y2));
+
+                       r.dst.x = box->x1;
+                       r.dst.y = box->y1;
+                       r.width  = box->x2 - box->x1;
+                       r.height = box->y2 - box->y1;
+                       r.src = r.mask = r.dst;
+
+                       op->prim_emit(sna, op, &r);
+                       box++;
+               } while (--nbox_this_time);
+       } while (nbox);
+}
+
+#ifndef MAX
+#define MAX(a,b) ((a) > (b) ? (a) : (b))
+#endif
+
+static uint32_t
+gen6_composite_create_blend_state(struct sna_static_stream *stream)
+{
+       char *base, *ptr;
+       int src, dst;
+
+       base = sna_static_stream_map(stream,
+                                    GEN6_BLENDFACTOR_COUNT * GEN6_BLENDFACTOR_COUNT * GEN6_BLEND_STATE_PADDED_SIZE,
+                                    64);
+
+       ptr = base;
+       for (src = 0; src < GEN6_BLENDFACTOR_COUNT; src++) {
+               for (dst= 0; dst < GEN6_BLENDFACTOR_COUNT; dst++) {
+                       struct gen6_blend_state *blend =
+                               (struct gen6_blend_state *)ptr;
+
+                       blend->blend0.dest_blend_factor = dst;
+                       blend->blend0.source_blend_factor = src;
+                       blend->blend0.blend_func = GEN6_BLENDFUNCTION_ADD;
+                       blend->blend0.blend_enable =
+                               !(dst == GEN6_BLENDFACTOR_ZERO && src == GEN6_BLENDFACTOR_ONE);
+
+                       blend->blend1.post_blend_clamp_enable = 1;
+                       blend->blend1.pre_blend_clamp_enable = 1;
+
+                       ptr += GEN6_BLEND_STATE_PADDED_SIZE;
+               }
+       }
+
+       return sna_static_stream_offsetof(stream, base);
+}
+
+static uint32_t gen6_bind_video_source(struct sna *sna,
+                                      struct kgem_bo *src_bo,
+                                      uint32_t src_offset,
+                                      int src_width,
+                                      int src_height,
+                                      int src_pitch,
+                                      uint32_t src_surf_format)
+{
+       struct gen6_surface_state *ss;
+
+       sna->kgem.surface -= sizeof(struct gen6_surface_state_padded) / sizeof(uint32_t);
+
+       ss = memset(sna->kgem.batch + sna->kgem.surface, 0, sizeof(*ss));
+       ss->ss0.surface_type = GEN6_SURFACE_2D;
+       ss->ss0.surface_format = src_surf_format;
+
+       ss->ss1.base_addr =
+               kgem_add_reloc(&sna->kgem,
+                              sna->kgem.surface + 1,
+                              src_bo,
+                              I915_GEM_DOMAIN_SAMPLER << 16,
+                              src_offset);
+
+       ss->ss2.width  = src_width - 1;
+       ss->ss2.height = src_height - 1;
+       ss->ss3.pitch  = src_pitch - 1;
+
+       return sna->kgem.surface * sizeof(uint32_t);
+}
+
+static void gen6_emit_video_state(struct sna *sna,
+                                 const struct sna_composite_op *op)
+{
+       struct sna_video_frame *frame = op->priv;
+       uint32_t src_surf_format;
+       uint32_t src_surf_base[6];
+       int src_width[6];
+       int src_height[6];
+       int src_pitch[6];
+       uint32_t *binding_table;
+       uint16_t offset;
+       bool dirty;
+       int n_src, n;
+
+       gen6_get_batch(sna);
+       dirty = kgem_bo_is_dirty(op->dst.bo);
+
+       src_surf_base[0] = 0;
+       src_surf_base[1] = 0;
+       src_surf_base[2] = frame->VBufOffset;
+       src_surf_base[3] = frame->VBufOffset;
+       src_surf_base[4] = frame->UBufOffset;
+       src_surf_base[5] = frame->UBufOffset;
+
+       if (is_planar_fourcc(frame->id)) {
+               src_surf_format = GEN6_SURFACEFORMAT_R8_UNORM;
+               src_width[1]  = src_width[0]  = frame->width;
+               src_height[1] = src_height[0] = frame->height;
+               src_pitch[1]  = src_pitch[0]  = frame->pitch[1];
+               src_width[4]  = src_width[5]  = src_width[2]  = src_width[3] =
+                       frame->width / 2;
+               src_height[4] = src_height[5] = src_height[2] = src_height[3] =
+                       frame->height / 2;
+               src_pitch[4]  = src_pitch[5]  = src_pitch[2]  = src_pitch[3] =
+                       frame->pitch[0];
+               n_src = 6;
+       } else {
+               if (frame->id == FOURCC_UYVY)
+                       src_surf_format = GEN6_SURFACEFORMAT_YCRCB_SWAPY;
+               else
+                       src_surf_format = GEN6_SURFACEFORMAT_YCRCB_NORMAL;
+
+               src_width[0]  = frame->width;
+               src_height[0] = frame->height;
+               src_pitch[0]  = frame->pitch[0];
+               n_src = 1;
+       }
+
+       binding_table = gen6_composite_get_binding_table(sna, &offset);
+
+       binding_table[0] =
+               gen6_bind_bo(sna,
+                            op->dst.bo, op->dst.width, op->dst.height,
+                            gen6_get_dest_format(op->dst.format),
+                            true);
+       for (n = 0; n < n_src; n++) {
+               binding_table[1+n] =
+                       gen6_bind_video_source(sna,
+                                              frame->bo,
+                                              src_surf_base[n],
+                                              src_width[n],
+                                              src_height[n],
+                                              src_pitch[n],
+                                              src_surf_format);
+       }
+
+       gen6_emit_state(sna, op, offset | dirty);
+}
+
+static bool
+gen6_render_video(struct sna *sna,
+                 struct sna_video *video,
+                 struct sna_video_frame *frame,
+                 RegionPtr dstRegion,
+                 short src_w, short src_h,
+                 short drw_w, short drw_h,
+                 PixmapPtr pixmap)
+{
+       struct sna_composite_op tmp;
+       int nbox, dxo, dyo, pix_xoff, pix_yoff;
+       float src_scale_x, src_scale_y;
+       struct sna_pixmap *priv;
+       BoxPtr box;
+
+       DBG(("%s: src=(%d, %d), dst=(%d, %d), %dx[(%d, %d), (%d, %d)...]\n",
+            __FUNCTION__, src_w, src_h, drw_w, drw_h,
+            REGION_NUM_RECTS(dstRegion),
+            REGION_EXTENTS(NULL, dstRegion)->x1,
+            REGION_EXTENTS(NULL, dstRegion)->y1,
+            REGION_EXTENTS(NULL, dstRegion)->x2,
+            REGION_EXTENTS(NULL, dstRegion)->y2));
+
+       priv = sna_pixmap_force_to_gpu(pixmap, MOVE_READ | MOVE_WRITE);
+       if (priv == NULL)
+               return false;
+
+       memset(&tmp, 0, sizeof(tmp));
+
+       tmp.dst.pixmap = pixmap;
+       tmp.dst.width  = pixmap->drawable.width;
+       tmp.dst.height = pixmap->drawable.height;
+       tmp.dst.format = sna_render_format_for_depth(pixmap->drawable.depth);
+       tmp.dst.bo = priv->gpu_bo;
+
+       tmp.src.bo = frame->bo;
+       tmp.mask.bo = NULL;
+
+       tmp.floats_per_vertex = 3;
+       tmp.floats_per_rect = 9;
+
+       tmp.u.gen6.flags =
+               GEN6_SET_FLAGS(VIDEO_SAMPLER, NO_BLEND,
+                              is_planar_fourcc(frame->id) ?
+                              GEN6_WM_KERNEL_VIDEO_PLANAR :
+                              GEN6_WM_KERNEL_VIDEO_PACKED,
+                              2);
+       tmp.priv = frame;
+
+       kgem_set_mode(&sna->kgem, KGEM_RENDER);
+       if (!kgem_check_bo(&sna->kgem, tmp.dst.bo, frame->bo, NULL)) {
+               kgem_submit(&sna->kgem);
+               assert(kgem_check_bo(&sna->kgem, tmp.dst.bo, frame->bo, NULL));
+               _kgem_set_mode(&sna->kgem, KGEM_RENDER);
+       }
+
+       gen6_emit_video_state(sna, &tmp);
+       gen6_align_vertex(sna, &tmp);
+
+       /* Set up the offset for translating from the given region (in screen
+        * coordinates) to the backing pixmap.
+        */
+#ifdef COMPOSITE
+       pix_xoff = -pixmap->screen_x + pixmap->drawable.x;
+       pix_yoff = -pixmap->screen_y + pixmap->drawable.y;
+#else
+       pix_xoff = 0;
+       pix_yoff = 0;
+#endif
+
+       dxo = dstRegion->extents.x1;
+       dyo = dstRegion->extents.y1;
+
+       /* Use normalized texture coordinates */
+       src_scale_x = ((float)src_w / frame->width) / (float)drw_w;
+       src_scale_y = ((float)src_h / frame->height) / (float)drw_h;
+
+       box = REGION_RECTS(dstRegion);
+       nbox = REGION_NUM_RECTS(dstRegion);
+       while (nbox--) {
+               BoxRec r;
+
+               r.x1 = box->x1 + pix_xoff;
+               r.x2 = box->x2 + pix_xoff;
+               r.y1 = box->y1 + pix_yoff;
+               r.y2 = box->y2 + pix_yoff;
+
+               gen6_get_rectangles(sna, &tmp, 1, gen6_emit_video_state);
+
+               OUT_VERTEX(r.x2, r.y2);
+               OUT_VERTEX_F((box->x2 - dxo) * src_scale_x);
+               OUT_VERTEX_F((box->y2 - dyo) * src_scale_y);
+
+               OUT_VERTEX(r.x1, r.y2);
+               OUT_VERTEX_F((box->x1 - dxo) * src_scale_x);
+               OUT_VERTEX_F((box->y2 - dyo) * src_scale_y);
+
+               OUT_VERTEX(r.x1, r.y1);
+               OUT_VERTEX_F((box->x1 - dxo) * src_scale_x);
+               OUT_VERTEX_F((box->y1 - dyo) * src_scale_y);
+
+               if (!DAMAGE_IS_ALL(priv->gpu_damage)) {
+                       sna_damage_add_box(&priv->gpu_damage, &r);
+                       sna_damage_subtract_box(&priv->cpu_damage, &r);
+               }
+               box++;
+       }
+       priv->clear = false;
+
+       gen6_vertex_flush(sna);
+       return true;
+}
+
+static bool
+gen6_composite_solid_init(struct sna *sna,
+                         struct sna_composite_channel *channel,
+                         uint32_t color)
+{
+       DBG(("%s: color=%x\n", __FUNCTION__, color));
+
+       channel->filter = PictFilterNearest;
+       channel->repeat = RepeatNormal;
+       channel->is_affine = true;
+       channel->is_solid  = true;
+       channel->is_opaque = (color >> 24) == 0xff;
+       channel->transform = NULL;
+       channel->width  = 1;
+       channel->height = 1;
+       channel->card_format = GEN6_SURFACEFORMAT_B8G8R8A8_UNORM;
+
+       channel->bo = sna_render_get_solid(sna, color);
+
+       channel->scale[0]  = channel->scale[1]  = 1;
+       channel->offset[0] = channel->offset[1] = 0;
+       return channel->bo != NULL;
+}
+
+static bool
+gen6_composite_linear_init(struct sna *sna,
+                          PicturePtr picture,
+                          struct sna_composite_channel *channel,
+                          int x, int y,
+                          int w, int h,
+                          int dst_x, int dst_y)
+{
+       PictLinearGradient *linear =
+               (PictLinearGradient *)picture->pSourcePict;
+       pixman_fixed_t tx, ty;
+       float x0, y0, sf;
+       float dx, dy;
+
+       DBG(("%s: p1=(%f, %f), p2=(%f, %f), src=(%d, %d), dst=(%d, %d), size=(%d, %d)\n",
+            __FUNCTION__,
+            pixman_fixed_to_double(linear->p1.x), pixman_fixed_to_double(linear->p1.y),
+            pixman_fixed_to_double(linear->p2.x), pixman_fixed_to_double(linear->p2.y),
+            x, y, dst_x, dst_y, w, h));
+
+       if (linear->p2.x == linear->p1.x && linear->p2.y == linear->p1.y)
+               return 0;
+
+       if (!sna_transform_is_affine(picture->transform)) {
+               DBG(("%s: fallback due to projective transform\n",
+                    __FUNCTION__));
+               return sna_render_picture_fixup(sna, picture, channel,
+                                               x, y, w, h, dst_x, dst_y);
+       }
+
+       channel->bo = sna_render_get_gradient(sna, (PictGradient *)linear);
+       if (!channel->bo)
+               return 0;
+
+       channel->filter = PictFilterNearest;
+       channel->repeat = picture->repeat ? picture->repeatType : RepeatNone;
+       channel->width  = channel->bo->pitch / 4;
+       channel->height = 1;
+       channel->pict_format = PICT_a8r8g8b8;
+
+       channel->scale[0]  = channel->scale[1]  = 1;
+       channel->offset[0] = channel->offset[1] = 0;
+
+       if (sna_transform_is_translation(picture->transform, &tx, &ty)) {
+               dx = pixman_fixed_to_double(linear->p2.x - linear->p1.x);
+               dy = pixman_fixed_to_double(linear->p2.y - linear->p1.y);
+
+               x0 = pixman_fixed_to_double(linear->p1.x);
+               y0 = pixman_fixed_to_double(linear->p1.y);
+
+               if (tx | ty) {
+                       x0 -= pixman_fixed_to_double(tx);
+                       y0 -= pixman_fixed_to_double(ty);
+               }
+       } else {
+               struct pixman_f_vector p1, p2;
+               struct pixman_f_transform m, inv;
+
+               pixman_f_transform_from_pixman_transform(&m, picture->transform);
+               DBG(("%s: transform = [%f %f %f, %f %f %f, %f %f %f]\n",
+                    __FUNCTION__,
+                    m.m[0][0], m.m[0][1], m.m[0][2],
+                    m.m[1][0], m.m[1][1], m.m[1][2],
+                    m.m[2][0], m.m[2][1], m.m[2][2]));
+               if (!pixman_f_transform_invert(&inv, &m))
+                       return 0;
+
+               p1.v[0] = pixman_fixed_to_double(linear->p1.x);
+               p1.v[1] = pixman_fixed_to_double(linear->p1.y);
+               p1.v[2] = 1.;
+               pixman_f_transform_point(&inv, &p1);
+
+               p2.v[0] = pixman_fixed_to_double(linear->p2.x);
+               p2.v[1] = pixman_fixed_to_double(linear->p2.y);
+               p2.v[2] = 1.;
+               pixman_f_transform_point(&inv, &p2);
+
+               DBG(("%s: untransformed: p1=(%f, %f, %f), p2=(%f, %f, %f)\n",
+                    __FUNCTION__,
+                    p1.v[0], p1.v[1], p1.v[2],
+                    p2.v[0], p2.v[1], p2.v[2]));
+
+               dx = p2.v[0] - p1.v[0];
+               dy = p2.v[1] - p1.v[1];
+
+               x0 = p1.v[0];
+               y0 = p1.v[1];
+       }
+
+       sf = dx*dx + dy*dy;
+       dx /= sf;
+       dy /= sf;
+
+       channel->embedded_transform.matrix[0][0] = pixman_double_to_fixed(dx);
+       channel->embedded_transform.matrix[0][1] = pixman_double_to_fixed(dy);
+       channel->embedded_transform.matrix[0][2] = -pixman_double_to_fixed(dx*(x0+dst_x-x) + dy*(y0+dst_y-y));
+
+       channel->embedded_transform.matrix[1][0] = 0;
+       channel->embedded_transform.matrix[1][1] = 0;
+       channel->embedded_transform.matrix[1][2] = pixman_double_to_fixed(.5);
+
+       channel->embedded_transform.matrix[2][0] = 0;
+       channel->embedded_transform.matrix[2][1] = 0;
+       channel->embedded_transform.matrix[2][2] = pixman_fixed_1;
+
+       channel->transform = &channel->embedded_transform;
+       channel->is_affine = 1;
+
+       DBG(("%s: dx=%f, dy=%f, offset=%f\n",
+            __FUNCTION__, dx, dy, -dx*(x0-x+dst_x) + -dy*(y0-y+dst_y)));
+
+       return channel->bo != NULL;
+}
+
+static int
+gen6_composite_picture(struct sna *sna,
+                      PicturePtr picture,
+                      struct sna_composite_channel *channel,
+                      int x, int y,
+                      int w, int h,
+                      int dst_x, int dst_y,
+                      bool precise)
+{
+       PixmapPtr pixmap;
+       uint32_t color;
+       int16_t dx, dy;
+
+       DBG(("%s: (%d, %d)x(%d, %d), dst=(%d, %d)\n",
+            __FUNCTION__, x, y, w, h, dst_x, dst_y));
+
+       channel->is_solid = false;
+       channel->card_format = -1;
+
+       if (sna_picture_is_solid(picture, &color))
+               return gen6_composite_solid_init(sna, channel, color);
+
+       if (picture->pDrawable == NULL) {
+               int ret;
+
+               if (picture->pSourcePict->type == SourcePictTypeLinear)
+                       return gen6_composite_linear_init(sna, picture, channel,
+                                                         x, y,
+                                                         w, h,
+                                                         dst_x, dst_y);
+
+               DBG(("%s -- fixup, gradient\n", __FUNCTION__));
+               ret = -1;
+               if (!precise)
+                       ret = sna_render_picture_approximate_gradient(sna, picture, channel,
+                                                                     x, y, w, h, dst_x, dst_y);
+               if (ret == -1)
+                       ret = sna_render_picture_fixup(sna, picture, channel,
+                                                      x, y, w, h, dst_x, dst_y);
+               return ret;
+       }
+
+       if (picture->alphaMap) {
+               DBG(("%s -- fixup, alphamap\n", __FUNCTION__));
+               return sna_render_picture_fixup(sna, picture, channel,
+                                               x, y, w, h, dst_x, dst_y);
+       }
+
+       if (!gen6_check_repeat(picture))
+               return sna_render_picture_fixup(sna, picture, channel,
+                                               x, y, w, h, dst_x, dst_y);
+
+       if (!gen6_check_filter(picture))
+               return sna_render_picture_fixup(sna, picture, channel,
+                                               x, y, w, h, dst_x, dst_y);
+
+       channel->repeat = picture->repeat ? picture->repeatType : RepeatNone;
+       channel->filter = picture->filter;
+
+       pixmap = get_drawable_pixmap(picture->pDrawable);
+       get_drawable_deltas(picture->pDrawable, pixmap, &dx, &dy);
+
+       x += dx + picture->pDrawable->x;
+       y += dy + picture->pDrawable->y;
+
+       channel->is_affine = sna_transform_is_affine(picture->transform);
+       if (sna_transform_is_integer_translation(picture->transform, &dx, &dy)) {
+               DBG(("%s: integer translation (%d, %d), removing\n",
+                    __FUNCTION__, dx, dy));
+               x += dx;
+               y += dy;
+               channel->transform = NULL;
+               channel->filter = PictFilterNearest;
+       } else
+               channel->transform = picture->transform;
+
+       channel->pict_format = picture->format;
+       channel->card_format = gen6_get_card_format(picture->format);
+       if (channel->card_format == (unsigned)-1)
+               return sna_render_picture_convert(sna, picture, channel, pixmap,
+                                                 x, y, w, h, dst_x, dst_y);
+
+       if (too_large(pixmap->drawable.width, pixmap->drawable.height)) {
+               DBG(("%s: extracting from pixmap %dx%d\n", __FUNCTION__,
+                    pixmap->drawable.width, pixmap->drawable.height));
+               return sna_render_picture_extract(sna, picture, channel,
+                                                 x, y, w, h, dst_x, dst_y);
+       }
+
+       return sna_render_pixmap_bo(sna, channel, pixmap,
+                                   x, y, w, h, dst_x, dst_y);
+}
+
+inline static void gen6_composite_channel_convert(struct sna_composite_channel *channel)
+{
+       channel->repeat = gen6_repeat(channel->repeat);
+       channel->filter = gen6_filter(channel->filter);
+       if (channel->card_format == (unsigned)-1)
+               channel->card_format = gen6_get_card_format(channel->pict_format);
+       assert(channel->card_format != (unsigned)-1);
+}
+
+static void gen6_render_composite_done(struct sna *sna,
+                                      const struct sna_composite_op *op)
+{
+       DBG(("%s\n", __FUNCTION__));
+
+       if (sna->render_state.gen6.vertex_offset) {
+               gen6_vertex_flush(sna);
+               gen6_magic_ca_pass(sna, op);
+       }
+
+       if (op->mask.bo)
+               kgem_bo_destroy(&sna->kgem, op->mask.bo);
+       if (op->src.bo)
+               kgem_bo_destroy(&sna->kgem, op->src.bo);
+
+       sna_render_composite_redirect_done(sna, op);
+}
+
+static bool
+gen6_composite_set_target(struct sna *sna,
+                         struct sna_composite_op *op,
+                         PicturePtr dst,
+                         int x, int y, int w, int h)
+{
+       BoxRec box;
+
+       op->dst.pixmap = get_drawable_pixmap(dst->pDrawable);
+       op->dst.format = dst->format;
+       op->dst.width = op->dst.pixmap->drawable.width;
+       op->dst.height = op->dst.pixmap->drawable.height;
+
+       if (w && h) {
+               box.x1 = x;
+               box.y1 = y;
+               box.x2 = x + w;
+               box.y2 = y + h;
+       } else
+               sna_render_picture_extents(dst, &box);
+
+       op->dst.bo = sna_drawable_use_bo (dst->pDrawable,
+                                         PREFER_GPU | FORCE_GPU | RENDER_GPU,
+                                         &box, &op->damage);
+       if (op->dst.bo == NULL)
+               return false;
+
+       get_drawable_deltas(dst->pDrawable, op->dst.pixmap,
+                           &op->dst.x, &op->dst.y);
+
+       DBG(("%s: pixmap=%p, format=%08x, size=%dx%d, pitch=%d, delta=(%d,%d),damage=%p\n",
+            __FUNCTION__,
+            op->dst.pixmap, (int)op->dst.format,
+            op->dst.width, op->dst.height,
+            op->dst.bo->pitch,
+            op->dst.x, op->dst.y,
+            op->damage ? *op->damage : (void *)-1));
+
+       assert(op->dst.bo->proxy == NULL);
+
+       if (too_large(op->dst.width, op->dst.height) &&
+           !sna_render_composite_redirect(sna, op, x, y, w, h))
+               return false;
+
+       return true;
+}
+
+static bool prefer_blt_ring(struct sna *sna)
+{
+       if (PREFER_RENDER)
+               return PREFER_RENDER < 0;
+
+       return sna->kgem.ring != KGEM_RENDER;
+}
+
+static bool can_switch_to_blt(struct sna *sna)
+{
+       if (sna->kgem.ring == KGEM_BLT)
+               return true;
+
+       if (NO_RING_SWITCH)
+               return false;
+
+       if (!sna->kgem.has_semaphores)
+               return false;
+
+       return sna->kgem.mode == KGEM_NONE || kgem_is_idle(&sna->kgem);
+}
+
+static inline bool untiled_tlb_miss(struct kgem_bo *bo)
+{
+       return bo->tiling == I915_TILING_NONE && bo->pitch >= 4096;
+}
+
+static bool prefer_blt_bo(struct sna *sna, struct kgem_bo *bo)
+{
+       return untiled_tlb_miss(bo) && bo->pitch < MAXSHORT;
+}
+
+static bool
+try_blt(struct sna *sna,
+       PicturePtr dst, PicturePtr src,
+       int width, int height)
+{
+       if (prefer_blt_ring(sna)) {
+               DBG(("%s: already performing BLT\n", __FUNCTION__));
+               return true;
+       }
+
+       if (too_large(width, height)) {
+               DBG(("%s: operation too large for 3D pipe (%d, %d)\n",
+                    __FUNCTION__, width, height));
+               return true;
+       }
+
+       if (can_switch_to_blt(sna) && sna_picture_is_solid(src, NULL))
+               return true;
+
+       return false;
+}
+
+static bool
+check_gradient(PicturePtr picture)
+{
+       if (picture->pDrawable)
+               return false;
+
+       switch (picture->pSourcePict->type) {
+       case SourcePictTypeSolidFill:
+       case SourcePictTypeLinear:
+               return false;
+       default:
+               return true;
+       }
+}
+
+static bool
+has_alphamap(PicturePtr p)
+{
+       return p->alphaMap != NULL;
+}
+
+static bool
+untransformed(PicturePtr p)
+{
+       return !p->transform || pixman_transform_is_int_translate(p->transform);
+}
+
+static bool
+need_upload(PicturePtr p)
+{
+       return p->pDrawable && unattached(p->pDrawable) && untransformed(p);
+}
+
+static bool
+source_is_busy(PixmapPtr pixmap)
+{
+       struct sna_pixmap *priv = sna_pixmap(pixmap);
+       if (priv == NULL || priv->clear)
+               return false;
+
+       if (priv->gpu_bo && kgem_bo_is_busy(priv->gpu_bo))
+               return true;
+
+       if (priv->cpu_bo && kgem_bo_is_busy(priv->cpu_bo))
+               return true;
+
+       return priv->gpu_damage && !priv->cpu_damage;
+}
+
+static bool
+source_fallback(PicturePtr p, PixmapPtr pixmap)
+{
+       if (sna_picture_is_solid(p, NULL))
+               return false;
+
+       if (p->pSourcePict)
+               return check_gradient(p);
+
+       if (!gen6_check_repeat(p) || !gen6_check_format(p->format))
+               return true;
+
+       if (pixmap && source_is_busy(pixmap))
+               return false;
+
+       return has_alphamap(p) || !gen6_check_filter(p) || need_upload(p);
+}
+
+static bool
+gen6_composite_fallback(struct sna *sna,
+                       PicturePtr src,
+                       PicturePtr mask,
+                       PicturePtr dst)
+{
+       struct sna_pixmap *priv;
+       PixmapPtr src_pixmap;
+       PixmapPtr mask_pixmap;
+       PixmapPtr dst_pixmap;
+       bool src_fallback, mask_fallback;
+
+       if (!gen6_check_dst_format(dst->format)) {
+               DBG(("%s: unknown destination format: %d\n",
+                    __FUNCTION__, dst->format));
+               return true;
+       }
+
+       dst_pixmap = get_drawable_pixmap(dst->pDrawable);
+
+       src_pixmap = src->pDrawable ? get_drawable_pixmap(src->pDrawable) : NULL;
+       src_fallback = source_fallback(src, src_pixmap);
+
+       if (mask) {
+               mask_pixmap = mask->pDrawable ? get_drawable_pixmap(mask->pDrawable) : NULL;
+               mask_fallback = source_fallback(mask, mask_pixmap);
+       } else {
+               mask_pixmap = NULL;
+               mask_fallback = false;
+       }
+
+       /* If we are using the destination as a source and need to
+        * readback in order to upload the source, do it all
+        * on the cpu.
+        */
+       if (src_pixmap == dst_pixmap && src_fallback) {
+               DBG(("%s: src is dst and will fallback\n",__FUNCTION__));
+               return true;
+       }
+       if (mask_pixmap == dst_pixmap && mask_fallback) {
+               DBG(("%s: mask is dst and will fallback\n",__FUNCTION__));
+               return true;
+       }
+
+       /* If anything is on the GPU, push everything out to the GPU */
+       priv = sna_pixmap(dst_pixmap);
+       if (priv &&
+           ((priv->gpu_damage && !priv->clear) ||
+            (priv->cpu_bo && kgem_bo_is_busy(priv->cpu_bo)))) {
+               DBG(("%s: dst is already on the GPU, try to use GPU\n",
+                    __FUNCTION__));
+               return false;
+       }
+
+       if (src_pixmap && !src_fallback) {
+               DBG(("%s: src is already on the GPU, try to use GPU\n",
+                    __FUNCTION__));
+               return false;
+       }
+       if (mask_pixmap && !mask_fallback) {
+               DBG(("%s: mask is already on the GPU, try to use GPU\n",
+                    __FUNCTION__));
+               return false;
+       }
+
+       /* However if the dst is not on the GPU and we need to
+        * render one of the sources using the CPU, we may
+        * as well do the entire operation in place onthe CPU.
+        */
+       if (src_fallback) {
+               DBG(("%s: dst is on the CPU and src will fallback\n",
+                    __FUNCTION__));
+               return true;
+       }
+
+       if (mask && mask_fallback) {
+               DBG(("%s: dst is on the CPU and mask will fallback\n",
+                    __FUNCTION__));
+               return true;
+       }
+
+       if (too_large(dst_pixmap->drawable.width,
+                     dst_pixmap->drawable.height) &&
+           (priv == NULL || DAMAGE_IS_ALL(priv->cpu_damage))) {
+               DBG(("%s: dst is on the CPU and too large\n", __FUNCTION__));
+               return true;
+       }
+
+       DBG(("%s: dst is not on the GPU and the operation should not fallback\n",
+            __FUNCTION__));
+       return false;
+}
+
+static int
+reuse_source(struct sna *sna,
+            PicturePtr src, struct sna_composite_channel *sc, int src_x, int src_y,
+            PicturePtr mask, struct sna_composite_channel *mc, int msk_x, int msk_y)
+{
+       uint32_t color;
+
+       if (src_x != msk_x || src_y != msk_y)
+               return false;
+
+       if (src == mask) {
+               DBG(("%s: mask is source\n", __FUNCTION__));
+               *mc = *sc;
+               mc->bo = kgem_bo_reference(mc->bo);
+               return true;
+       }
+
+       if (sna_picture_is_solid(mask, &color))
+               return gen6_composite_solid_init(sna, mc, color);
+
+       if (sc->is_solid)
+               return false;
+
+       if (src->pDrawable == NULL || mask->pDrawable != src->pDrawable)
+               return false;
+
+       DBG(("%s: mask reuses source drawable\n", __FUNCTION__));
+
+       if (!sna_transform_equal(src->transform, mask->transform))
+               return false;
+
+       if (!sna_picture_alphamap_equal(src, mask))
+               return false;
+
+       if (!gen6_check_repeat(mask))
+               return false;
+
+       if (!gen6_check_filter(mask))
+               return false;
+
+       if (!gen6_check_format(mask->format))
+               return false;
+
+       DBG(("%s: reusing source channel for mask with a twist\n",
+            __FUNCTION__));
+
+       *mc = *sc;
+       mc->repeat = gen6_repeat(mask->repeat ? mask->repeatType : RepeatNone);
+       mc->filter = gen6_filter(mask->filter);
+       mc->pict_format = mask->format;
+       mc->card_format = gen6_get_card_format(mask->format);
+       mc->bo = kgem_bo_reference(mc->bo);
+       return true;
+}
+
+static bool
+prefer_blt_composite(struct sna *sna, struct sna_composite_op *tmp)
+{
+       if (sna->kgem.ring == KGEM_BLT)
+               return true;
+
+       if (!prefer_blt_ring(sna))
+               return false;
+
+       return (prefer_blt_bo(sna, tmp->dst.bo) ||
+               prefer_blt_bo(sna, tmp->src.bo));
+}
+
+static bool
+gen6_render_composite(struct sna *sna,
+                     uint8_t op,
+                     PicturePtr src,
+                     PicturePtr mask,
+                     PicturePtr dst,
+                     int16_t src_x, int16_t src_y,
+                     int16_t msk_x, int16_t msk_y,
+                     int16_t dst_x, int16_t dst_y,
+                     int16_t width, int16_t height,
+                     struct sna_composite_op *tmp)
+{
+       if (op >= ARRAY_SIZE(gen6_blend_op))
+               return false;
+
+       DBG(("%s: %dx%d, current mode=%d\n", __FUNCTION__,
+            width, height, sna->kgem.ring));
+
+       if (mask == NULL &&
+           try_blt(sna, dst, src, width, height) &&
+           sna_blt_composite(sna, op,
+                             src, dst,
+                             src_x, src_y,
+                             dst_x, dst_y,
+                             width, height,
+                             tmp, false))
+               return true;
+
+       if (gen6_composite_fallback(sna, src, mask, dst))
+               return false;
+
+       if (need_tiling(sna, width, height))
+               return sna_tiling_composite(op, src, mask, dst,
+                                           src_x, src_y,
+                                           msk_x, msk_y,
+                                           dst_x, dst_y,
+                                           width, height,
+                                           tmp);
+
+       if (op == PictOpClear)
+               op = PictOpSrc;
+       tmp->op = op;
+       if (!gen6_composite_set_target(sna, tmp, dst,
+                                      dst_x, dst_y, width, height))
+               return false;
+
+       switch (gen6_composite_picture(sna, src, &tmp->src,
+                                      src_x, src_y,
+                                      width, height,
+                                      dst_x, dst_y,
+                                      dst->polyMode == PolyModePrecise)) {
+       case -1:
+               goto cleanup_dst;
+       case 0:
+               if (!gen6_composite_solid_init(sna, &tmp->src, 0))
+                       goto cleanup_dst;
+               /* fall through to fixup */
+       case 1:
+               /* Did we just switch rings to prepare the source? */
+               if (mask == NULL &&
+                   prefer_blt_composite(sna, tmp) &&
+                   sna_blt_composite__convert(sna,
+                                              dst_x, dst_y, width, height,
+                                              tmp))
+                       return true;
+
+               gen6_composite_channel_convert(&tmp->src);
+               break;
+       }
+
+       tmp->is_affine = tmp->src.is_affine;
+       tmp->has_component_alpha = false;
+       tmp->need_magic_ca_pass = false;
+
+       tmp->mask.bo = NULL;
+       tmp->mask.filter = SAMPLER_FILTER_NEAREST;
+       tmp->mask.repeat = SAMPLER_EXTEND_NONE;
+
+       tmp->prim_emit = gen6_emit_composite_primitive;
+       if (mask) {
+               if (mask->componentAlpha && PICT_FORMAT_RGB(mask->format)) {
+                       tmp->has_component_alpha = true;
+
+                       /* Check if it's component alpha that relies on a source alpha and on
+                        * the source value.  We can only get one of those into the single
+                        * source value that we get to blend with.
+                        */
+                       if (gen6_blend_op[op].src_alpha &&
+                           (gen6_blend_op[op].src_blend != GEN6_BLENDFACTOR_ZERO)) {
+                               if (op != PictOpOver)
+                                       goto cleanup_src;
+
+                               tmp->need_magic_ca_pass = true;
+                               tmp->op = PictOpOutReverse;
+                       }
+               }
+
+               if (!reuse_source(sna,
+                                 src, &tmp->src, src_x, src_y,
+                                 mask, &tmp->mask, msk_x, msk_y)) {
+                       switch (gen6_composite_picture(sna, mask, &tmp->mask,
+                                                      msk_x, msk_y,
+                                                      width, height,
+                                                      dst_x, dst_y,
+                                                      dst->polyMode == PolyModePrecise)) {
+                       case -1:
+                               goto cleanup_src;
+                       case 0:
+                               if (!gen6_composite_solid_init(sna, &tmp->mask, 0))
+                                       goto cleanup_src;
+                               /* fall through to fixup */
+                       case 1:
+                               gen6_composite_channel_convert(&tmp->mask);
+                               break;
+                       }
+               }
+
+               tmp->is_affine &= tmp->mask.is_affine;
+
+               if (tmp->src.transform == NULL && tmp->mask.transform == NULL)
+                       tmp->prim_emit = gen6_emit_composite_primitive_identity_source_mask;
+
+               tmp->floats_per_vertex = 5 + 2 * !tmp->is_affine;
+       } else {
+               if (tmp->src.is_solid) {
+                       DBG(("%s: choosing gen6_emit_composite_primitive_solid\n",
+                            __FUNCTION__));
+                       tmp->prim_emit = gen6_emit_composite_primitive_solid;
+                       if (tmp->src.is_opaque && op == PictOpOver)
+                               tmp->op = PictOpSrc;
+               } else if (tmp->src.transform == NULL) {
+                       DBG(("%s: choosing gen6_emit_composite_primitive_identity_source\n",
+                            __FUNCTION__));
+                       tmp->prim_emit = gen6_emit_composite_primitive_identity_source;
+               } else if (tmp->src.is_affine) {
+                       if (tmp->src.transform->matrix[0][1] == 0 &&
+                           tmp->src.transform->matrix[1][0] == 0) {
+                               tmp->src.scale[0] /= tmp->src.transform->matrix[2][2];
+                               tmp->src.scale[1] /= tmp->src.transform->matrix[2][2];
+                               DBG(("%s: choosing gen6_emit_composite_primitive_simple_source\n",
+                                    __FUNCTION__));
+                               tmp->prim_emit = gen6_emit_composite_primitive_simple_source;
+                       } else {
+                               DBG(("%s: choosing gen6_emit_composite_primitive_affine_source\n",
+                                    __FUNCTION__));
+                               tmp->prim_emit = gen6_emit_composite_primitive_affine_source;
+                       }
+               }
+
+               tmp->floats_per_vertex = 3 + !tmp->is_affine;
+       }
+       tmp->floats_per_rect = 3 * tmp->floats_per_vertex;
+
+       tmp->u.gen6.flags =
+               GEN6_SET_FLAGS(SAMPLER_OFFSET(tmp->src.filter,
+                                             tmp->src.repeat,
+                                             tmp->mask.filter,
+                                             tmp->mask.repeat),
+                              gen6_get_blend(tmp->op,
+                                             tmp->has_component_alpha,
+                                             tmp->dst.format),
+                              gen6_choose_composite_kernel(tmp->op,
+                                                           tmp->mask.bo != NULL,
+                                                           tmp->has_component_alpha,
+                                                           tmp->is_affine),
+                              gen6_choose_composite_vertex_buffer(tmp));
+
+       tmp->blt   = gen6_render_composite_blt;
+       tmp->box   = gen6_render_composite_box;
+       tmp->boxes = gen6_render_composite_boxes;
+       tmp->done  = gen6_render_composite_done;
+
+       kgem_set_mode(&sna->kgem, KGEM_RENDER);
+       if (!kgem_check_bo(&sna->kgem,
+                          tmp->dst.bo, tmp->src.bo, tmp->mask.bo,
+                          NULL)) {
+               kgem_submit(&sna->kgem);
+               if (!kgem_check_bo(&sna->kgem,
+                                  tmp->dst.bo, tmp->src.bo, tmp->mask.bo,
+                                  NULL))
+                       goto cleanup_mask;
+               _kgem_set_mode(&sna->kgem, KGEM_RENDER);
+       }
+
+       gen6_emit_composite_state(sna, tmp);
+       gen6_align_vertex(sna, tmp);
+       return true;
+
+cleanup_mask:
+       if (tmp->mask.bo)
+               kgem_bo_destroy(&sna->kgem, tmp->mask.bo);
+cleanup_src:
+       if (tmp->src.bo)
+               kgem_bo_destroy(&sna->kgem, tmp->src.bo);
+cleanup_dst:
+       if (tmp->redirect.real_bo)
+               kgem_bo_destroy(&sna->kgem, tmp->dst.bo);
+       return false;
+}
+
+#if !NO_COMPOSITE_SPANS
+inline static void
+gen6_emit_composite_texcoord_affine(struct sna *sna,
+                                   const struct sna_composite_channel *channel,
+                                   int16_t x, int16_t y)
+{
+       float t[2];
+
+       sna_get_transformed_coordinates(x + channel->offset[0],
+                                       y + channel->offset[1],
+                                       channel->transform,
+                                       &t[0], &t[1]);
+       OUT_VERTEX_F(t[0] * channel->scale[0]);
+       OUT_VERTEX_F(t[1] * channel->scale[1]);
+}
+
+inline static void
+gen6_emit_composite_spans_vertex(struct sna *sna,
+                                const struct sna_composite_spans_op *op,
+                                int16_t x, int16_t y)
+{
+       OUT_VERTEX(x, y);
+       gen6_emit_composite_texcoord(sna, &op->base.src, x, y);
+}
+
+fastcall static void
+gen6_emit_composite_spans_primitive(struct sna *sna,
+                                   const struct sna_composite_spans_op *op,
+                                   const BoxRec *box,
+                                   float opacity)
+{
+       gen6_emit_composite_spans_vertex(sna, op, box->x2, box->y2);
+       OUT_VERTEX_F(opacity);
+
+       gen6_emit_composite_spans_vertex(sna, op, box->x1, box->y2);
+       OUT_VERTEX_F(opacity);
+
+       gen6_emit_composite_spans_vertex(sna, op, box->x1, box->y1);
+       OUT_VERTEX_F(opacity);
+}
+
+fastcall static void
+gen6_emit_composite_spans_solid(struct sna *sna,
+                               const struct sna_composite_spans_op *op,
+                               const BoxRec *box,
+                               float opacity)
+{
+       OUT_VERTEX(box->x2, box->y2);
+       OUT_VERTEX_F(1); OUT_VERTEX_F(1);
+       OUT_VERTEX_F(opacity);
+
+       OUT_VERTEX(box->x1, box->y2);
+       OUT_VERTEX_F(0); OUT_VERTEX_F(1);
+       OUT_VERTEX_F(opacity);
+
+       OUT_VERTEX(box->x1, box->y1);
+       OUT_VERTEX_F(0); OUT_VERTEX_F(0);
+       OUT_VERTEX_F(opacity);
+}
+
+fastcall static void
+gen6_emit_composite_spans_identity(struct sna *sna,
+                                  const struct sna_composite_spans_op *op,
+                                  const BoxRec *box,
+                                  float opacity)
+{
+       float *v;
+       union {
+               struct sna_coordinate p;
+               float f;
+       } dst;
+
+       float sx = op->base.src.scale[0];
+       float sy = op->base.src.scale[1];
+       int16_t tx = op->base.src.offset[0];
+       int16_t ty = op->base.src.offset[1];
+
+       v = sna->render.vertices + sna->render.vertex_used;
+       sna->render.vertex_used += 3*4;
+       assert(sna->render.vertex_used <= sna->render.vertex_size);
+
+       dst.p.x = box->x2;
+       dst.p.y = box->y2;
+       v[0] = dst.f;
+       v[1] = (box->x2 + tx) * sx;
+       v[6] = v[2] = (box->y2 + ty) * sy;
+
+       dst.p.x = box->x1;
+       v[4] = dst.f;
+       v[9] = v[5] = (box->x1 + tx) * sx;
+
+       dst.p.y = box->y1;
+       v[8] = dst.f;
+       v[10] = (box->y1 + ty) * sy;
+
+       v[11] = v[7] = v[3] = opacity;
+}
+
+fastcall static void
+gen6_emit_composite_spans_simple(struct sna *sna,
+                                const struct sna_composite_spans_op *op,
+                                const BoxRec *box,
+                                float opacity)
+{
+       float *v;
+       union {
+               struct sna_coordinate p;
+               float f;
+       } dst;
+
+       float xx = op->base.src.transform->matrix[0][0];
+       float x0 = op->base.src.transform->matrix[0][2];
+       float yy = op->base.src.transform->matrix[1][1];
+       float y0 = op->base.src.transform->matrix[1][2];
+       float sx = op->base.src.scale[0];
+       float sy = op->base.src.scale[1];
+       int16_t tx = op->base.src.offset[0];
+       int16_t ty = op->base.src.offset[1];
+
+       v = sna->render.vertices + sna->render.vertex_used;
+       sna->render.vertex_used += 3*4;
+       assert(sna->render.vertex_used <= sna->render.vertex_size);
+
+       dst.p.x = box->x2;
+       dst.p.y = box->y2;
+       v[0] = dst.f;
+       v[1] = ((box->x2 + tx) * xx + x0) * sx;
+       v[6] = v[2] = ((box->y2 + ty) * yy + y0) * sy;
+
+       dst.p.x = box->x1;
+       v[4] = dst.f;
+       v[9] = v[5] = ((box->x1 + tx) * xx + x0) * sx;
+
+       dst.p.y = box->y1;
+       v[8] = dst.f;
+       v[10] = ((box->y1 + ty) * yy + y0) * sy;
+
+       v[11] = v[7] = v[3] = opacity;
+}
+
+fastcall static void
+gen6_emit_composite_spans_affine(struct sna *sna,
+                                const struct sna_composite_spans_op *op,
+                                const BoxRec *box,
+                                float opacity)
+{
+       OUT_VERTEX(box->x2, box->y2);
+       gen6_emit_composite_texcoord_affine(sna, &op->base.src,
+                                           box->x2, box->y2);
+       OUT_VERTEX_F(opacity);
+
+       OUT_VERTEX(box->x1, box->y2);
+       gen6_emit_composite_texcoord_affine(sna, &op->base.src,
+                                           box->x1, box->y2);
+       OUT_VERTEX_F(opacity);
+
+       OUT_VERTEX(box->x1, box->y1);
+       gen6_emit_composite_texcoord_affine(sna, &op->base.src,
+                                           box->x1, box->y1);
+       OUT_VERTEX_F(opacity);
+}
+
+fastcall static void
+gen6_render_composite_spans_box(struct sna *sna,
+                               const struct sna_composite_spans_op *op,
+                               const BoxRec *box, float opacity)
+{
+       DBG(("%s: src=+(%d, %d), opacity=%f, dst=+(%d, %d), box=(%d, %d) x (%d, %d)\n",
+            __FUNCTION__,
+            op->base.src.offset[0], op->base.src.offset[1],
+            opacity,
+            op->base.dst.x, op->base.dst.y,
+            box->x1, box->y1,
+            box->x2 - box->x1,
+            box->y2 - box->y1));
+
+       gen6_get_rectangles(sna, &op->base, 1, gen6_emit_composite_state);
+       op->prim_emit(sna, op, box, opacity);
+}
+
+static void
+gen6_render_composite_spans_boxes(struct sna *sna,
+                                 const struct sna_composite_spans_op *op,
+                                 const BoxRec *box, int nbox,
+                                 float opacity)
+{
+       DBG(("%s: nbox=%d, src=+(%d, %d), opacity=%f, dst=+(%d, %d)\n",
+            __FUNCTION__, nbox,
+            op->base.src.offset[0], op->base.src.offset[1],
+            opacity,
+            op->base.dst.x, op->base.dst.y));
+
+       do {
+               int nbox_this_time;
+
+               nbox_this_time = gen6_get_rectangles(sna, &op->base, nbox,
+                                                    gen6_emit_composite_state);
+               nbox -= nbox_this_time;
+
+               do {
+                       DBG(("  %s: (%d, %d) x (%d, %d)\n", __FUNCTION__,
+                            box->x1, box->y1,
+                            box->x2 - box->x1,
+                            box->y2 - box->y1));
+
+                       op->prim_emit(sna, op, box++, opacity);
+               } while (--nbox_this_time);
+       } while (nbox);
+}
+
+fastcall static void
+gen6_render_composite_spans_done(struct sna *sna,
+                                const struct sna_composite_spans_op *op)
+{
+       DBG(("%s()\n", __FUNCTION__));
+
+       if (sna->render_state.gen6.vertex_offset)
+               gen6_vertex_flush(sna);
+
+       if (op->base.src.bo)
+               kgem_bo_destroy(&sna->kgem, op->base.src.bo);
+
+       sna_render_composite_redirect_done(sna, &op->base);
+}
+
+static bool
+gen6_check_composite_spans(struct sna *sna,
+                          uint8_t op, PicturePtr src, PicturePtr dst,
+                          int16_t width, int16_t height, unsigned flags)
+{
+       if ((flags & COMPOSITE_SPANS_RECTILINEAR) == 0)
+               return false;
+
+       if (op >= ARRAY_SIZE(gen6_blend_op))
+               return false;
+
+       if (gen6_composite_fallback(sna, src, NULL, dst))
+               return false;
+
+       if (need_tiling(sna, width, height)) {
+               if (!is_gpu(dst->pDrawable)) {
+                       DBG(("%s: fallback, tiled operation not on GPU\n",
+                            __FUNCTION__));
+                       return false;
+               }
+       }
+
+       return true;
+}
+
+static bool
+gen6_render_composite_spans(struct sna *sna,
+                           uint8_t op,
+                           PicturePtr src,
+                           PicturePtr dst,
+                           int16_t src_x,  int16_t src_y,
+                           int16_t dst_x,  int16_t dst_y,
+                           int16_t width,  int16_t height,
+                           unsigned flags,
+                           struct sna_composite_spans_op *tmp)
+{
+       DBG(("%s: %dx%d with flags=%x, current mode=%d\n", __FUNCTION__,
+            width, height, flags, sna->kgem.ring));
+
+       assert(gen6_check_composite_spans(sna, op, src, dst, width, height, flags));
+
+       if (need_tiling(sna, width, height)) {
+               DBG(("%s: tiling, operation (%dx%d) too wide for pipeline\n",
+                    __FUNCTION__, width, height));
+               return sna_tiling_composite_spans(op, src, dst,
+                                                 src_x, src_y, dst_x, dst_y,
+                                                 width, height, flags, tmp);
+       }
+
+       tmp->base.op = op;
+       if (!gen6_composite_set_target(sna, &tmp->base, dst,
+                                      dst_x, dst_y, width, height))
+               return false;
+
+       switch (gen6_composite_picture(sna, src, &tmp->base.src,
+                                      src_x, src_y,
+                                      width, height,
+                                      dst_x, dst_y,
+                                      dst->polyMode == PolyModePrecise)) {
+       case -1:
+               goto cleanup_dst;
+       case 0:
+               if (!gen6_composite_solid_init(sna, &tmp->base.src, 0))
+                       goto cleanup_dst;
+               /* fall through to fixup */
+       case 1:
+               gen6_composite_channel_convert(&tmp->base.src);
+               break;
+       }
+       tmp->base.mask.bo = NULL;
+
+       tmp->base.is_affine = tmp->base.src.is_affine;
+       tmp->base.need_magic_ca_pass = false;
+
+       tmp->prim_emit = gen6_emit_composite_spans_primitive;
+       if (tmp->base.src.is_solid) {
+               tmp->prim_emit = gen6_emit_composite_spans_solid;
+       } else if (tmp->base.src.transform == NULL) {
+               tmp->prim_emit = gen6_emit_composite_spans_identity;
+       } else if (tmp->base.is_affine) {
+               if (tmp->base.src.transform->matrix[0][1] == 0 &&
+                   tmp->base.src.transform->matrix[1][0] == 0) {
+                       tmp->base.src.scale[0] /= tmp->base.src.transform->matrix[2][2];
+                       tmp->base.src.scale[1] /= tmp->base.src.transform->matrix[2][2];
+                       tmp->prim_emit = gen6_emit_composite_spans_simple;
+               } else
+                       tmp->prim_emit = gen6_emit_composite_spans_affine;
+       }
+       tmp->base.floats_per_vertex = 4 + !tmp->base.is_affine;
+       tmp->base.floats_per_rect = 3 * tmp->base.floats_per_vertex;
+
+       tmp->base.u.gen6.flags =
+               GEN6_SET_FLAGS(SAMPLER_OFFSET(tmp->base.src.filter,
+                                             tmp->base.src.repeat,
+                                             SAMPLER_FILTER_NEAREST,
+                                             SAMPLER_EXTEND_PAD),
+                              gen6_get_blend(tmp->base.op, false, tmp->base.dst.format),
+                              GEN6_WM_KERNEL_OPACITY | !tmp->base.is_affine,
+                              1 << 2 | (2+!tmp->base.is_affine));
+
+       tmp->box   = gen6_render_composite_spans_box;
+       tmp->boxes = gen6_render_composite_spans_boxes;
+       tmp->done  = gen6_render_composite_spans_done;
+
+       kgem_set_mode(&sna->kgem, KGEM_RENDER);
+       if (!kgem_check_bo(&sna->kgem,
+                          tmp->base.dst.bo, tmp->base.src.bo,
+                          NULL)) {
+               kgem_submit(&sna->kgem);
+               if (!kgem_check_bo(&sna->kgem,
+                                  tmp->base.dst.bo, tmp->base.src.bo,
+                                  NULL))
+                       goto cleanup_src;
+               _kgem_set_mode(&sna->kgem, KGEM_RENDER);
+       }
+
+       gen6_emit_composite_state(sna, &tmp->base);
+       gen6_align_vertex(sna, &tmp->base);
+       return true;
+
+cleanup_src:
+       if (tmp->base.src.bo)
+               kgem_bo_destroy(&sna->kgem, tmp->base.src.bo);
+cleanup_dst:
+       if (tmp->base.redirect.real_bo)
+               kgem_bo_destroy(&sna->kgem, tmp->base.dst.bo);
+       return false;
+}
+#endif
+
+static void
+gen6_emit_copy_state(struct sna *sna,
+                    const struct sna_composite_op *op)
+{
+       uint32_t *binding_table;
+       uint16_t offset;
+       bool dirty;
+
+       gen6_get_batch(sna);
+       dirty = kgem_bo_is_dirty(op->dst.bo);
+
+       binding_table = gen6_composite_get_binding_table(sna, &offset);
+
+       binding_table[0] =
+               gen6_bind_bo(sna,
+                            op->dst.bo, op->dst.width, op->dst.height,
+                            gen6_get_dest_format(op->dst.format),
+                            true);
+       binding_table[1] =
+               gen6_bind_bo(sna,
+                            op->src.bo, op->src.width, op->src.height,
+                            op->src.card_format,
+                            false);
+
+       if (sna->kgem.surface == offset &&
+           *(uint64_t *)(sna->kgem.batch + sna->render_state.gen6.surface_table) == *(uint64_t*)binding_table) {
+               sna->kgem.surface += sizeof(struct gen6_surface_state_padded) / sizeof(uint32_t);
+               offset = sna->render_state.gen6.surface_table;
+       }
+
+       gen6_emit_state(sna, op, offset | dirty);
+}
+
+static inline bool prefer_blt_copy(struct sna *sna,
+                                  struct kgem_bo *src_bo,
+                                  struct kgem_bo *dst_bo,
+                                  unsigned flags)
+{
+       if (PREFER_RENDER)
+               return PREFER_RENDER > 0;
+
+       return (sna->kgem.ring == KGEM_BLT ||
+               (flags & COPY_LAST && sna->kgem.mode == KGEM_NONE) ||
+               prefer_blt_bo(sna, src_bo) ||
+               prefer_blt_bo(sna, dst_bo));
+}
+
+inline static void boxes_extents(const BoxRec *box, int n, BoxRec *extents)
+{
+       *extents = box[0];
+       while (--n) {
+               box++;
+
+               if (box->x1 < extents->x1)
+                       extents->x1 = box->x1;
+               if (box->x2 > extents->x2)
+                       extents->x2 = box->x2;
+
+               if (box->y1 < extents->y1)
+                       extents->y1 = box->y1;
+               if (box->y2 > extents->y2)
+                       extents->y2 = box->y2;
+       }
+}
+
+static inline bool
+overlaps(struct sna *sna,
+        struct kgem_bo *src_bo, int16_t src_dx, int16_t src_dy,
+        struct kgem_bo *dst_bo, int16_t dst_dx, int16_t dst_dy,
+        const BoxRec *box, int n, BoxRec *extents)
+{
+       if (src_bo != dst_bo)
+               return false;
+
+       boxes_extents(box, n, extents);
+       return (extents->x2 + src_dx > extents->x1 + dst_dx &&
+               extents->x1 + src_dx < extents->x2 + dst_dx &&
+               extents->y2 + src_dy > extents->y1 + dst_dy &&
+               extents->y1 + src_dy < extents->y2 + dst_dy);
+}
+
+static bool
+gen6_render_copy_boxes(struct sna *sna, uint8_t alu,
+                      PixmapPtr src, struct kgem_bo *src_bo, int16_t src_dx, int16_t src_dy,
+                      PixmapPtr dst, struct kgem_bo *dst_bo, int16_t dst_dx, int16_t dst_dy,
+                      const BoxRec *box, int n, unsigned flags)
+{
+       struct sna_composite_op tmp;
+       BoxRec extents;
+
+       DBG(("%s (%d, %d)->(%d, %d) x %d, alu=%x, self-copy=%d, overlaps? %d\n",
+            __FUNCTION__, src_dx, src_dy, dst_dx, dst_dy, n, alu,
+            src_bo == dst_bo,
+            overlaps(sna,
+                     src_bo, src_dx, src_dy,
+                     dst_bo, dst_dx, dst_dy,
+                     box, n, &extents)));
+
+       if (prefer_blt_copy(sna, src_bo, dst_bo, flags) &&
+           sna_blt_compare_depth(&src->drawable, &dst->drawable) &&
+           sna_blt_copy_boxes(sna, alu,
+                              src_bo, src_dx, src_dy,
+                              dst_bo, dst_dx, dst_dy,
+                              dst->drawable.bitsPerPixel,
+                              box, n))
+               return true;
+
+       if (!(alu == GXcopy || alu == GXclear)) {
+fallback_blt:
+               if (!sna_blt_compare_depth(&src->drawable, &dst->drawable))
+                       return false;
+
+               return sna_blt_copy_boxes_fallback(sna, alu,
+                                                  src, src_bo, src_dx, src_dy,
+                                                  dst, dst_bo, dst_dx, dst_dy,
+                                                  box, n);
+       }
+
+       if (overlaps(sna,
+                    src_bo, src_dx, src_dy,
+                    dst_bo, dst_dx, dst_dy,
+                    box, n, &extents)) {
+               if (too_large(extents.x2-extents.x1, extents.y2-extents.y1))
+                       goto fallback_blt;
+
+               if ((flags & COPY_LAST || can_switch_to_blt(sna)) &&
+                   sna_blt_compare_depth(&src->drawable, &dst->drawable) &&
+                   sna_blt_copy_boxes(sna, alu,
+                                      src_bo, src_dx, src_dy,
+                                      dst_bo, dst_dx, dst_dy,
+                                      dst->drawable.bitsPerPixel,
+                                      box, n))
+                       return true;
+
+               return sna_render_copy_boxes__overlap(sna, alu,
+                                                     src, src_bo, src_dx, src_dy,
+                                                     dst, dst_bo, dst_dx, dst_dy,
+                                                     box, n, &extents);
+       }
+
+       if (dst->drawable.depth == src->drawable.depth) {
+               tmp.dst.format = sna_render_format_for_depth(dst->drawable.depth);
+               tmp.src.pict_format = tmp.dst.format;
+       } else {
+               tmp.dst.format = sna_format_for_depth(dst->drawable.depth);
+               tmp.src.pict_format = sna_format_for_depth(src->drawable.depth);
+       }
+       if (!gen6_check_format(tmp.src.pict_format))
+               goto fallback_blt;
+
+       tmp.dst.pixmap = dst;
+       tmp.dst.width  = dst->drawable.width;
+       tmp.dst.height = dst->drawable.height;
+       tmp.dst.bo = dst_bo;
+       tmp.dst.x = tmp.dst.y = 0;
+       tmp.damage = NULL;
+
+       sna_render_composite_redirect_init(&tmp);
+       if (too_large(tmp.dst.width, tmp.dst.height)) {
+               int i;
+
+               extents = box[0];
+               for (i = 1; i < n; i++) {
+                       if (box[i].x1 < extents.x1)
+                               extents.x1 = box[i].x1;
+                       if (box[i].y1 < extents.y1)
+                               extents.y1 = box[i].y1;
+
+                       if (box[i].x2 > extents.x2)
+                               extents.x2 = box[i].x2;
+                       if (box[i].y2 > extents.y2)
+                               extents.y2 = box[i].y2;
+               }
+
+               if (!sna_render_composite_redirect(sna, &tmp,
+                                                  extents.x1 + dst_dx,
+                                                  extents.y1 + dst_dy,
+                                                  extents.x2 - extents.x1,
+                                                  extents.y2 - extents.y1))
+                       goto fallback_tiled;
+
+               dst_dx += tmp.dst.x;
+               dst_dy += tmp.dst.y;
+
+               tmp.dst.x = tmp.dst.y = 0;
+       }
+
+       tmp.src.card_format = gen6_get_card_format(tmp.src.pict_format);
+       if (too_large(src->drawable.width, src->drawable.height)) {
+               int i;
+
+               extents = box[0];
+               for (i = 1; i < n; i++) {
+                       if (extents.x1 < box[i].x1)
+                               extents.x1 = box[i].x1;
+                       if (extents.y1 < box[i].y1)
+                               extents.y1 = box[i].y1;
+
+                       if (extents.x2 > box[i].x2)
+                               extents.x2 = box[i].x2;
+                       if (extents.y2 > box[i].y2)
+                               extents.y2 = box[i].y2;
+               }
+
+               if (!sna_render_pixmap_partial(sna, src, src_bo, &tmp.src,
+                                              extents.x1 + src_dx,
+                                              extents.y1 + src_dy,
+                                              extents.x2 - extents.x1,
+                                              extents.y2 - extents.y1)) {
+                       DBG(("%s: unable to extract partial pixmap\n", __FUNCTION__));
+                       goto fallback_tiled_dst;
+               }
+
+               src_dx += tmp.src.offset[0];
+               src_dy += tmp.src.offset[1];
+       } else {
+               tmp.src.bo = src_bo;
+               tmp.src.width  = src->drawable.width;
+               tmp.src.height = src->drawable.height;
+       }
+
+       tmp.mask.bo = NULL;
+
+       tmp.floats_per_vertex = 2;
+       tmp.floats_per_rect = 6;
+       tmp.need_magic_ca_pass = 0;
+
+       tmp.u.gen6.flags = COPY_FLAGS(alu);
+       assert(GEN6_KERNEL(tmp.u.gen6.flags) == GEN6_WM_KERNEL_NOMASK);
+       assert(GEN6_SAMPLER(tmp.u.gen6.flags) == COPY_SAMPLER);
+       assert(GEN6_VERTEX(tmp.u.gen6.flags) == COPY_VERTEX);
+
+       kgem_set_mode(&sna->kgem, KGEM_RENDER);
+       if (!kgem_check_bo(&sna->kgem, tmp.dst.bo, tmp.src.bo, NULL)) {
+               kgem_submit(&sna->kgem);
+               if (!kgem_check_bo(&sna->kgem, tmp.dst.bo, tmp.src.bo, NULL)) {
+                       DBG(("%s: too large for a single operation\n",
+                            __FUNCTION__));
+                       goto fallback_tiled_src;
+               }
+               _kgem_set_mode(&sna->kgem, KGEM_RENDER);
+       }
+
+       gen6_emit_copy_state(sna, &tmp);
+       gen6_align_vertex(sna, &tmp);
+
+       do {
+               int16_t *v;
+               int n_this_time;
+
+               n_this_time = gen6_get_rectangles(sna, &tmp, n,
+                                                 gen6_emit_copy_state);
+               n -= n_this_time;
+
+               v = (int16_t *)(sna->render.vertices + sna->render.vertex_used);
+               sna->render.vertex_used += 6 * n_this_time;
+               assert(sna->render.vertex_used <= sna->render.vertex_size);
+               do {
+
+                       DBG(("  (%d, %d) -> (%d, %d) + (%d, %d)\n",
+                            box->x1 + src_dx, box->y1 + src_dy,
+                            box->x1 + dst_dx, box->y1 + dst_dy,
+                            box->x2 - box->x1, box->y2 - box->y1));
+                       v[0] = box->x2 + dst_dx;
+                       v[2] = box->x2 + src_dx;
+                       v[1]  = v[5] = box->y2 + dst_dy;
+                       v[3]  = v[7] = box->y2 + src_dy;
+                       v[8]  = v[4] = box->x1 + dst_dx;
+                       v[10] = v[6] = box->x1 + src_dx;
+                       v[9]  = box->y1 + dst_dy;
+                       v[11] = box->y1 + src_dy;
+                       v += 12; box++;
+               } while (--n_this_time);
+       } while (n);
+
+       gen6_vertex_flush(sna);
+       sna_render_composite_redirect_done(sna, &tmp);
+       if (tmp.src.bo != src_bo)
+               kgem_bo_destroy(&sna->kgem, tmp.src.bo);
+       return true;
+
+fallback_tiled_src:
+       if (tmp.src.bo != src_bo)
+               kgem_bo_destroy(&sna->kgem, tmp.src.bo);
+fallback_tiled_dst:
+       if (tmp.redirect.real_bo)
+               kgem_bo_destroy(&sna->kgem, tmp.dst.bo);
+fallback_tiled:
+       return sna_tiling_copy_boxes(sna, alu,
+                                    src, src_bo, src_dx, src_dy,
+                                    dst, dst_bo, dst_dx, dst_dy,
+                                    box, n);
+}
+
+static void
+gen6_render_copy_blt(struct sna *sna,
+                    const struct sna_copy_op *op,
+                    int16_t sx, int16_t sy,
+                    int16_t w,  int16_t h,
+                    int16_t dx, int16_t dy)
+{
+       int16_t *v;
+
+       gen6_get_rectangles(sna, &op->base, 1, gen6_emit_copy_state);
+
+       v = (int16_t *)&sna->render.vertices[sna->render.vertex_used];
+       sna->render.vertex_used += 6;
+       assert(sna->render.vertex_used <= sna->render.vertex_size);
+
+       v[0]  = dx+w; v[1]  = dy+h;
+       v[2]  = sx+w; v[3]  = sy+h;
+       v[4]  = dx;   v[5]  = dy+h;
+       v[6]  = sx;   v[7]  = sy+h;
+       v[8]  = dx;   v[9]  = dy;
+       v[10] = sx;   v[11] = sy;
+}
+
+static void
+gen6_render_copy_done(struct sna *sna, const struct sna_copy_op *op)
+{
+       DBG(("%s()\n", __FUNCTION__));
+
+       if (sna->render_state.gen6.vertex_offset)
+               gen6_vertex_flush(sna);
+}
+
+static bool
+gen6_render_copy(struct sna *sna, uint8_t alu,
+                PixmapPtr src, struct kgem_bo *src_bo,
+                PixmapPtr dst, struct kgem_bo *dst_bo,
+                struct sna_copy_op *op)
+{
+       DBG(("%s (alu=%d, src=(%dx%d), dst=(%dx%d))\n",
+            __FUNCTION__, alu,
+            src->drawable.width, src->drawable.height,
+            dst->drawable.width, dst->drawable.height));
+
+       if (prefer_blt_copy(sna, src_bo, dst_bo, 0) &&
+           sna_blt_compare_depth(&src->drawable, &dst->drawable) &&
+           sna_blt_copy(sna, alu,
+                        src_bo, dst_bo,
+                        dst->drawable.bitsPerPixel,
+                        op))
+               return true;
+
+       if (!(alu == GXcopy || alu == GXclear) || src_bo == dst_bo ||
+           too_large(src->drawable.width, src->drawable.height) ||
+           too_large(dst->drawable.width, dst->drawable.height)) {
+fallback:
+               if (!sna_blt_compare_depth(&src->drawable, &dst->drawable))
+                       return false;
+
+               return sna_blt_copy(sna, alu, src_bo, dst_bo,
+                                   dst->drawable.bitsPerPixel,
+                                   op);
+       }
+
+       if (dst->drawable.depth == src->drawable.depth) {
+               op->base.dst.format = sna_render_format_for_depth(dst->drawable.depth);
+               op->base.src.pict_format = op->base.dst.format;
+       } else {
+               op->base.dst.format = sna_format_for_depth(dst->drawable.depth);
+               op->base.src.pict_format = sna_format_for_depth(src->drawable.depth);
+       }
+       if (!gen6_check_format(op->base.src.pict_format))
+               goto fallback;
+
+       op->base.dst.pixmap = dst;
+       op->base.dst.width  = dst->drawable.width;
+       op->base.dst.height = dst->drawable.height;
+       op->base.dst.bo = dst_bo;
+
+       op->base.src.bo = src_bo;
+       op->base.src.card_format =
+               gen6_get_card_format(op->base.src.pict_format);
+       op->base.src.width  = src->drawable.width;
+       op->base.src.height = src->drawable.height;
+
+       op->base.mask.bo = NULL;
+
+       op->base.floats_per_vertex = 2;
+       op->base.floats_per_rect = 6;
+
+       op->base.u.gen6.flags = COPY_FLAGS(alu);
+       assert(GEN6_KERNEL(op->base.u.gen6.flags) == GEN6_WM_KERNEL_NOMASK);
+       assert(GEN6_SAMPLER(op->base.u.gen6.flags) == COPY_SAMPLER);
+       assert(GEN6_VERTEX(op->base.u.gen6.flags) == COPY_VERTEX);
+
+       kgem_set_mode(&sna->kgem, KGEM_RENDER);
+       if (!kgem_check_bo(&sna->kgem, dst_bo, src_bo, NULL)) {
+               kgem_submit(&sna->kgem);
+               if (!kgem_check_bo(&sna->kgem, dst_bo, src_bo, NULL))
+                       goto fallback;
+               _kgem_set_mode(&sna->kgem, KGEM_RENDER);
+       }
+
+       gen6_emit_copy_state(sna, &op->base);
+       gen6_align_vertex(sna, &op->base);
+
+       op->blt  = gen6_render_copy_blt;
+       op->done = gen6_render_copy_done;
+       return true;
+}
+
+static void
+gen6_emit_fill_state(struct sna *sna, const struct sna_composite_op *op)
+{
+       uint32_t *binding_table;
+       uint16_t offset;
+       bool dirty;
+
+       gen6_get_batch(sna);
+       dirty = kgem_bo_is_dirty(op->dst.bo);
+
+       binding_table = gen6_composite_get_binding_table(sna, &offset);
+
+       binding_table[0] =
+               gen6_bind_bo(sna,
+                            op->dst.bo, op->dst.width, op->dst.height,
+                            gen6_get_dest_format(op->dst.format),
+                            true);
+       binding_table[1] =
+               gen6_bind_bo(sna,
+                            op->src.bo, 1, 1,
+                            GEN6_SURFACEFORMAT_B8G8R8A8_UNORM,
+                            false);
+
+       if (sna->kgem.surface == offset &&
+           *(uint64_t *)(sna->kgem.batch + sna->render_state.gen6.surface_table) == *(uint64_t*)binding_table) {
+               sna->kgem.surface +=
+                       sizeof(struct gen6_surface_state_padded)/sizeof(uint32_t);
+               offset = sna->render_state.gen6.surface_table;
+       }
+
+       gen6_emit_state(sna, op, offset | dirty);
+}
+
+static inline bool prefer_blt_fill(struct sna *sna,
+                                  struct kgem_bo *bo)
+{
+       if (PREFER_RENDER)
+               return PREFER_RENDER < 0;
+
+       return (can_switch_to_blt(sna) ||
+               prefer_blt_ring(sna) ||
+               untiled_tlb_miss(bo));
+}
+
+static bool
+gen6_render_fill_boxes(struct sna *sna,
+                      CARD8 op,
+                      PictFormat format,
+                      const xRenderColor *color,
+                      PixmapPtr dst, struct kgem_bo *dst_bo,
+                      const BoxRec *box, int n)
+{
+       struct sna_composite_op tmp;
+       uint32_t pixel;
+
+       DBG(("%s (op=%d, color=(%04x, %04x, %04x, %04x) [%08x])\n",
+            __FUNCTION__, op,
+            color->red, color->green, color->blue, color->alpha, (int)format));
+
+       if (op >= ARRAY_SIZE(gen6_blend_op)) {
+               DBG(("%s: fallback due to unhandled blend op: %d\n",
+                    __FUNCTION__, op));
+               return false;
+       }
+
+       if (prefer_blt_fill(sna, dst_bo) || !gen6_check_dst_format(format)) {
+               uint8_t alu = GXinvalid;
+
+               if (op <= PictOpSrc) {
+                       pixel = 0;
+                       if (op == PictOpClear)
+                               alu = GXclear;
+                       else if (sna_get_pixel_from_rgba(&pixel,
+                                                        color->red,
+                                                        color->green,
+                                                        color->blue,
+                                                        color->alpha,
+                                                        format))
+                               alu = GXcopy;
+               }
+
+               if (alu != GXinvalid &&
+                   sna_blt_fill_boxes(sna, alu,
+                                      dst_bo, dst->drawable.bitsPerPixel,
+                                      pixel, box, n))
+                       return true;
+
+               if (!gen6_check_dst_format(format))
+                       return false;
+       }
+
+       if (op == PictOpClear) {
+               pixel = 0;
+               op = PictOpSrc;
+       } else if (!sna_get_pixel_from_rgba(&pixel,
+                                           color->red,
+                                           color->green,
+                                           color->blue,
+                                           color->alpha,
+                                           PICT_a8r8g8b8))
+               return false;
+
+       DBG(("%s(%08x x %d [(%d, %d), (%d, %d) ...])\n",
+            __FUNCTION__, pixel, n,
+            box[0].x1, box[0].y1, box[0].x2, box[0].y2));
+
+       tmp.dst.pixmap = dst;
+       tmp.dst.width  = dst->drawable.width;
+       tmp.dst.height = dst->drawable.height;
+       tmp.dst.format = format;
+       tmp.dst.bo = dst_bo;
+       tmp.dst.x = tmp.dst.y = 0;
+
+       sna_render_composite_redirect_init(&tmp);
+       if (too_large(dst->drawable.width, dst->drawable.height)) {
+               BoxRec extents;
+
+               boxes_extents(box, n, &extents);
+               if (!sna_render_composite_redirect(sna, &tmp,
+                                                  extents.x1, extents.y1,
+                                                  extents.x2 - extents.x1,
+                                                  extents.y2 - extents.y1))
+                       return sna_tiling_fill_boxes(sna, op, format, color,
+                                                    dst, dst_bo, box, n);
+       }
+
+       tmp.src.bo = sna_render_get_solid(sna, pixel);
+       tmp.mask.bo = NULL;
+
+       tmp.floats_per_vertex = 2;
+       tmp.floats_per_rect = 6;
+       tmp.need_magic_ca_pass = false;
+
+       tmp.u.gen6.flags = FILL_FLAGS(op, format);
+       assert(GEN6_KERNEL(tmp.u.gen6.flags) == GEN6_WM_KERNEL_NOMASK);
+       assert(GEN6_SAMPLER(tmp.u.gen6.flags) == FILL_SAMPLER);
+       assert(GEN6_VERTEX(tmp.u.gen6.flags) == FILL_VERTEX);
+
+       if (!kgem_check_bo(&sna->kgem, dst_bo, NULL)) {
+               kgem_submit(&sna->kgem);
+               assert(kgem_check_bo(&sna->kgem, dst_bo, NULL));
+       }
+
+       gen6_emit_fill_state(sna, &tmp);
+       gen6_align_vertex(sna, &tmp);
+
+       do {
+               int n_this_time;
+               int16_t *v;
+
+               n_this_time = gen6_get_rectangles(sna, &tmp, n,
+                                                 gen6_emit_fill_state);
+               n -= n_this_time;
+
+               v = (int16_t *)(sna->render.vertices + sna->render.vertex_used);
+               sna->render.vertex_used += 6 * n_this_time;
+               assert(sna->render.vertex_used <= sna->render.vertex_size);
+               do {
+                       DBG(("  (%d, %d), (%d, %d)\n",
+                            box->x1, box->y1, box->x2, box->y2));
+
+                       v[0] = box->x2;
+                       v[5] = v[1] = box->y2;
+                       v[8] = v[4] = box->x1;
+                       v[9] = box->y1;
+                       v[2] = v[3]  = v[7]  = 1;
+                       v[6] = v[10] = v[11] = 0;
+                       v += 12; box++;
+               } while (--n_this_time);
+       } while (n);
+
+       gen6_vertex_flush(sna);
+       kgem_bo_destroy(&sna->kgem, tmp.src.bo);
+       sna_render_composite_redirect_done(sna, &tmp);
+       return true;
+}
+
+static void
+gen6_render_op_fill_blt(struct sna *sna,
+                       const struct sna_fill_op *op,
+                       int16_t x, int16_t y, int16_t w, int16_t h)
+{
+       int16_t *v;
+
+       DBG(("%s: (%d, %d)x(%d, %d)\n", __FUNCTION__, x, y, w, h));
+
+       gen6_get_rectangles(sna, &op->base, 1, gen6_emit_fill_state);
+
+       v = (int16_t *)&sna->render.vertices[sna->render.vertex_used];
+       sna->render.vertex_used += 6;
+       assert(sna->render.vertex_used <= sna->render.vertex_size);
+
+       v[0] = x+w;
+       v[4] = v[8] = x;
+       v[1] = v[5] = y+h;
+       v[9] = y;
+
+       v[2] = v[3]  = v[7]  = 1;
+       v[6] = v[10] = v[11] = 0;
+}
+
+fastcall static void
+gen6_render_op_fill_box(struct sna *sna,
+                       const struct sna_fill_op *op,
+                       const BoxRec *box)
+{
+       int16_t *v;
+
+       DBG(("%s: (%d, %d),(%d, %d)\n", __FUNCTION__,
+            box->x1, box->y1, box->x2, box->y2));
+
+       gen6_get_rectangles(sna, &op->base, 1, gen6_emit_fill_state);
+
+       v = (int16_t *)&sna->render.vertices[sna->render.vertex_used];
+       sna->render.vertex_used += 6;
+       assert(sna->render.vertex_used <= sna->render.vertex_size);
+
+       v[0] = box->x2;
+       v[8] = v[4] = box->x1;
+       v[5] = v[1] = box->y2;
+       v[9] = box->y1;
+
+       v[7] = v[2]  = v[3]  = 1;
+       v[6] = v[10] = v[11] = 0;
+}
+
+fastcall static void
+gen6_render_op_fill_boxes(struct sna *sna,
+                         const struct sna_fill_op *op,
+                         const BoxRec *box,
+                         int nbox)
+{
+       DBG(("%s: (%d, %d),(%d, %d)... x %d\n", __FUNCTION__,
+            box->x1, box->y1, box->x2, box->y2, nbox));
+
+       do {
+               int nbox_this_time;
+               int16_t *v;
+
+               nbox_this_time = gen6_get_rectangles(sna, &op->base, nbox,
+                                                    gen6_emit_fill_state);
+               nbox -= nbox_this_time;
+
+               v = (int16_t *)&sna->render.vertices[sna->render.vertex_used];
+               sna->render.vertex_used += 6 * nbox_this_time;
+               assert(sna->render.vertex_used <= sna->render.vertex_size);
+
+               do {
+                       v[0] = box->x2;
+                       v[8] = v[4] = box->x1;
+                       v[5] = v[1] = box->y2;
+                       v[9] = box->y1;
+                       v[7] = v[2]  = v[3]  = 1;
+                       v[6] = v[10] = v[11] = 0;
+                       box++; v += 12;
+               } while (--nbox_this_time);
+       } while (nbox);
+}
+
+static void
+gen6_render_op_fill_done(struct sna *sna, const struct sna_fill_op *op)
+{
+       DBG(("%s()\n", __FUNCTION__));
+
+       if (sna->render_state.gen6.vertex_offset)
+               gen6_vertex_flush(sna);
+       kgem_bo_destroy(&sna->kgem, op->base.src.bo);
+}
+
+static bool
+gen6_render_fill(struct sna *sna, uint8_t alu,
+                PixmapPtr dst, struct kgem_bo *dst_bo,
+                uint32_t color,
+                struct sna_fill_op *op)
+{
+       DBG(("%s: (alu=%d, color=%x)\n", __FUNCTION__, alu, color));
+
+       if (prefer_blt_fill(sna, dst_bo) &&
+           sna_blt_fill(sna, alu,
+                        dst_bo, dst->drawable.bitsPerPixel,
+                        color,
+                        op))
+               return true;
+
+       if (!(alu == GXcopy || alu == GXclear) ||
+           too_large(dst->drawable.width, dst->drawable.height))
+               return sna_blt_fill(sna, alu,
+                                   dst_bo, dst->drawable.bitsPerPixel,
+                                   color,
+                                   op);
+
+       if (alu == GXclear)
+               color = 0;
+
+       op->base.dst.pixmap = dst;
+       op->base.dst.width  = dst->drawable.width;
+       op->base.dst.height = dst->drawable.height;
+       op->base.dst.format = sna_format_for_depth(dst->drawable.depth);
+       op->base.dst.bo = dst_bo;
+       op->base.dst.x = op->base.dst.y = 0;
+
+       op->base.src.bo =
+               sna_render_get_solid(sna,
+                                    sna_rgba_for_color(color,
+                                                       dst->drawable.depth));
+       op->base.mask.bo = NULL;
+
+       op->base.need_magic_ca_pass = false;
+       op->base.floats_per_vertex = 2;
+       op->base.floats_per_rect = 6;
+
+       op->base.u.gen6.flags = FILL_FLAGS_NOBLEND;
+       assert(GEN6_KERNEL(op->base.u.gen6.flags) == GEN6_WM_KERNEL_NOMASK);
+       assert(GEN6_SAMPLER(op->base.u.gen6.flags) == FILL_SAMPLER);
+       assert(GEN6_VERTEX(op->base.u.gen6.flags) == FILL_VERTEX);
+
+       if (!kgem_check_bo(&sna->kgem, dst_bo, NULL)) {
+               kgem_submit(&sna->kgem);
+               assert(kgem_check_bo(&sna->kgem, dst_bo, NULL));
+       }
+
+       gen6_emit_fill_state(sna, &op->base);
+       gen6_align_vertex(sna, &op->base);
+
+       op->blt  = gen6_render_op_fill_blt;
+       op->box  = gen6_render_op_fill_box;
+       op->boxes = gen6_render_op_fill_boxes;
+       op->done = gen6_render_op_fill_done;
+       return true;
+}
+
+static bool
+gen6_render_fill_one_try_blt(struct sna *sna, PixmapPtr dst, struct kgem_bo *bo,
+                            uint32_t color,
+                            int16_t x1, int16_t y1, int16_t x2, int16_t y2,
+                            uint8_t alu)
+{
+       BoxRec box;
+
+       box.x1 = x1;
+       box.y1 = y1;
+       box.x2 = x2;
+       box.y2 = y2;
+
+       return sna_blt_fill_boxes(sna, alu,
+                                 bo, dst->drawable.bitsPerPixel,
+                                 color, &box, 1);
+}
+
+static bool
+gen6_render_fill_one(struct sna *sna, PixmapPtr dst, struct kgem_bo *bo,
+                    uint32_t color,
+                    int16_t x1, int16_t y1,
+                    int16_t x2, int16_t y2,
+                    uint8_t alu)
+{
+       struct sna_composite_op tmp;
+       int16_t *v;
+
+       /* Prefer to use the BLT if already engaged */
+       if (prefer_blt_fill(sna, bo) &&
+           gen6_render_fill_one_try_blt(sna, dst, bo, color,
+                                        x1, y1, x2, y2, alu))
+               return true;
+
+       /* Must use the BLT if we can't RENDER... */
+       if (!(alu == GXcopy || alu == GXclear) ||
+           too_large(dst->drawable.width, dst->drawable.height))
+               return gen6_render_fill_one_try_blt(sna, dst, bo, color,
+                                                   x1, y1, x2, y2, alu);
+
+       if (alu == GXclear)
+               color = 0;
+
+       tmp.dst.pixmap = dst;
+       tmp.dst.width  = dst->drawable.width;
+       tmp.dst.height = dst->drawable.height;
+       tmp.dst.format = sna_format_for_depth(dst->drawable.depth);
+       tmp.dst.bo = bo;
+       tmp.dst.x = tmp.dst.y = 0;
+
+       tmp.src.bo =
+               sna_render_get_solid(sna,
+                                    sna_rgba_for_color(color,
+                                                       dst->drawable.depth));
+       tmp.mask.bo = NULL;
+
+       tmp.floats_per_vertex = 2;
+       tmp.floats_per_rect = 6;
+       tmp.need_magic_ca_pass = false;
+
+       tmp.u.gen6.flags = FILL_FLAGS_NOBLEND;
+       assert(GEN6_KERNEL(tmp.u.gen6.flags) == GEN6_WM_KERNEL_NOMASK);
+       assert(GEN6_SAMPLER(tmp.u.gen6.flags) == FILL_SAMPLER);
+       assert(GEN6_VERTEX(tmp.u.gen6.flags) == FILL_VERTEX);
+
+       if (!kgem_check_bo(&sna->kgem, bo, NULL)) {
+               _kgem_submit(&sna->kgem);
+               assert(kgem_check_bo(&sna->kgem, bo, NULL));
+       }
+
+       gen6_emit_fill_state(sna, &tmp);
+       gen6_align_vertex(sna, &tmp);
+
+       gen6_get_rectangles(sna, &tmp, 1, gen6_emit_fill_state);
+
+       DBG(("  (%d, %d), (%d, %d)\n", x1, y1, x2, y2));
+
+       v = (int16_t *)&sna->render.vertices[sna->render.vertex_used];
+       sna->render.vertex_used += 6;
+       assert(sna->render.vertex_used <= sna->render.vertex_size);
+
+       v[0] = x2;
+       v[8] = v[4] = x1;
+       v[5] = v[1] = y2;
+       v[9] = y1;
+       v[7] = v[2]  = v[3]  = 1;
+       v[6] = v[10] = v[11] = 0;
+
+       gen6_vertex_flush(sna);
+       kgem_bo_destroy(&sna->kgem, tmp.src.bo);
+
+       return true;
+}
+
+static bool
+gen6_render_clear_try_blt(struct sna *sna, PixmapPtr dst, struct kgem_bo *bo)
+{
+       BoxRec box;
+
+       box.x1 = 0;
+       box.y1 = 0;
+       box.x2 = dst->drawable.width;
+       box.y2 = dst->drawable.height;
+
+       return sna_blt_fill_boxes(sna, GXclear,
+                                 bo, dst->drawable.bitsPerPixel,
+                                 0, &box, 1);
+}
+
+static bool
+gen6_render_clear(struct sna *sna, PixmapPtr dst, struct kgem_bo *bo)
+{
+       struct sna_composite_op tmp;
+       int16_t *v;
+
+       DBG(("%s: %dx%d\n",
+            __FUNCTION__,
+            dst->drawable.width,
+            dst->drawable.height));
+
+       /* Prefer to use the BLT if, and only if, already engaged */
+       if (sna->kgem.ring == KGEM_BLT &&
+           gen6_render_clear_try_blt(sna, dst, bo))
+               return true;
+
+       /* Must use the BLT if we can't RENDER... */
+       if (too_large(dst->drawable.width, dst->drawable.height))
+               return gen6_render_clear_try_blt(sna, dst, bo);
+
+       tmp.dst.pixmap = dst;
+       tmp.dst.width  = dst->drawable.width;
+       tmp.dst.height = dst->drawable.height;
+       tmp.dst.format = sna_format_for_depth(dst->drawable.depth);
+       tmp.dst.bo = bo;
+       tmp.dst.x = tmp.dst.y = 0;
+
+       tmp.src.bo = sna_render_get_solid(sna, 0);
+       tmp.mask.bo = NULL;
+
+       tmp.floats_per_vertex = 2;
+       tmp.floats_per_rect = 6;
+       tmp.need_magic_ca_pass = false;
+
+       tmp.u.gen6.flags = FILL_FLAGS_NOBLEND;
+       assert(GEN6_KERNEL(tmp.u.gen6.flags) == GEN6_WM_KERNEL_NOMASK);
+       assert(GEN6_SAMPLER(tmp.u.gen6.flags) == FILL_SAMPLER);
+       assert(GEN6_VERTEX(tmp.u.gen6.flags) == FILL_VERTEX);
+
+       if (!kgem_check_bo(&sna->kgem, bo, NULL)) {
+               _kgem_submit(&sna->kgem);
+               assert(kgem_check_bo(&sna->kgem, bo, NULL));
+       }
+
+       gen6_emit_fill_state(sna, &tmp);
+       gen6_align_vertex(sna, &tmp);
+
+       gen6_get_rectangles(sna, &tmp, 1, gen6_emit_fill_state);
+
+       v = (int16_t *)&sna->render.vertices[sna->render.vertex_used];
+       sna->render.vertex_used += 6;
+       assert(sna->render.vertex_used <= sna->render.vertex_size);
+
+       v[0] = dst->drawable.width;
+       v[5] = v[1] = dst->drawable.height;
+       v[8] = v[4] = 0;
+       v[9] = 0;
+
+       v[7] = v[2]  = v[3]  = 1;
+       v[6] = v[10] = v[11] = 0;
+
+       gen6_vertex_flush(sna);
+       kgem_bo_destroy(&sna->kgem, tmp.src.bo);
+
+       return true;
+}
+
+static void gen6_render_flush(struct sna *sna)
+{
+       gen6_vertex_close(sna);
+}
+
+static void
+gen6_render_context_switch(struct kgem *kgem,
+                          int new_mode)
+{
+       if (!new_mode)
+               return;
+
+        DBG(("%s: from %d to %d\n", __FUNCTION__, kgem->mode, new_mode));
+
+       if (kgem->mode)
+               kgem_submit(kgem);
+
+       kgem->ring = new_mode;
+}
+
+static void
+gen6_render_retire(struct kgem *kgem)
+{
+       struct sna *sna;
+
+       if (kgem->ring && (kgem->has_semaphores || !kgem->need_retire))
+               kgem->ring = kgem->mode;
+
+       sna = container_of(kgem, struct sna, kgem);
+       if (kgem->nbatch == 0 && sna->render.vbo && !kgem_bo_is_busy(sna->render.vbo)) {
+               DBG(("%s: resetting idle vbo handle=%d\n", __FUNCTION__, sna->render.vbo->handle));
+               sna->render.vertex_used = 0;
+               sna->render.vertex_index = 0;
+       }
+}
+
+static void
+gen6_render_expire(struct kgem *kgem)
+{
+       struct sna *sna;
+
+       sna = container_of(kgem, struct sna, kgem);
+       if (sna->render.vbo && !sna->render.vertex_used) {
+               DBG(("%s: discarding vbo handle=%d\n", __FUNCTION__, sna->render.vbo->handle));
+               kgem_bo_destroy(kgem, sna->render.vbo);
+               sna->render.vbo = NULL;
+               sna->render.vertices = sna->render.vertex_data;
+               sna->render.vertex_size = ARRAY_SIZE(sna->render.vertex_data);
+               sna->render.vertex_used = 0;
+               sna->render.vertex_index = 0;
+       }
+}
+
+static void gen6_render_reset(struct sna *sna)
+{
+       sna->render_state.gen6.needs_invariant = true;
+       sna->render_state.gen6.first_state_packet = true;
+       sna->render_state.gen6.vb_id = 0;
+       sna->render_state.gen6.ve_id = 3 << 2;
+       sna->render_state.gen6.last_primitive = -1;
+
+       sna->render_state.gen6.num_sf_outputs = 0;
+       sna->render_state.gen6.samplers = -1;
+       sna->render_state.gen6.blend = -1;
+       sna->render_state.gen6.kernel = -1;
+       sna->render_state.gen6.drawrect_offset = -1;
+       sna->render_state.gen6.drawrect_limit = -1;
+       sna->render_state.gen6.surface_table = -1;
+}
+
+static void gen6_render_fini(struct sna *sna)
+{
+       kgem_bo_destroy(&sna->kgem, sna->render_state.gen6.general_bo);
+}
+
+static bool gen6_render_setup(struct sna *sna)
+{
+       struct gen6_render_state *state = &sna->render_state.gen6;
+       struct sna_static_stream general;
+       struct gen6_sampler_state *ss;
+       int i, j, k, l, m;
+
+       state->info = &gt1_info;
+       if (DEVICE_ID(sna->PciInfo) & 0x20)
+               state->info = &gt2_info; /* XXX requires GT_MODE WiZ disabled */
+
+       sna_static_stream_init(&general);
+
+       /* Zero pad the start. If you see an offset of 0x0 in the batchbuffer
+        * dumps, you know it points to zero.
+        */
+       null_create(&general);
+       scratch_create(&general);
+
+       for (m = 0; m < GEN6_KERNEL_COUNT; m++) {
+               if (wm_kernels[m].size) {
+                       state->wm_kernel[m][1] =
+                               sna_static_stream_add(&general,
+                                                     wm_kernels[m].data,
+                                                     wm_kernels[m].size,
+                                                     64);
+               } else {
+                       if (USE_8_PIXEL_DISPATCH) {
+                               state->wm_kernel[m][0] =
+                                       sna_static_stream_compile_wm(sna, &general,
+                                                                    wm_kernels[m].data, 8);
+                       }
+
+                       if (USE_16_PIXEL_DISPATCH) {
+                               state->wm_kernel[m][1] =
+                                       sna_static_stream_compile_wm(sna, &general,
+                                                                    wm_kernels[m].data, 16);
+                       }
+
+                       if (USE_32_PIXEL_DISPATCH) {
+                               state->wm_kernel[m][2] =
+                                       sna_static_stream_compile_wm(sna, &general,
+                                                                    wm_kernels[m].data, 32);
+                       }
+               }
+               if ((state->wm_kernel[m][0]|state->wm_kernel[m][1]|state->wm_kernel[m][2]) == 0) {
+                       state->wm_kernel[m][1] =
+                               sna_static_stream_compile_wm(sna, &general,
+                                                            wm_kernels[m].data, 16);
+               }
+       }
+
+       ss = sna_static_stream_map(&general,
+                                  2 * sizeof(*ss) *
+                                  (2 +
+                                   FILTER_COUNT * EXTEND_COUNT *
+                                   FILTER_COUNT * EXTEND_COUNT),
+                                  32);
+       state->wm_state = sna_static_stream_offsetof(&general, ss);
+       sampler_copy_init(ss); ss += 2;
+       sampler_fill_init(ss); ss += 2;
+       for (i = 0; i < FILTER_COUNT; i++) {
+               for (j = 0; j < EXTEND_COUNT; j++) {
+                       for (k = 0; k < FILTER_COUNT; k++) {
+                               for (l = 0; l < EXTEND_COUNT; l++) {
+                                       sampler_state_init(ss++, i, j);
+                                       sampler_state_init(ss++, k, l);
+                               }
+                       }
+               }
+       }
+
+       state->cc_vp = gen6_create_cc_viewport(&general);
+       state->cc_blend = gen6_composite_create_blend_state(&general);
+
+       state->general_bo = sna_static_stream_fini(sna, &general);
+       return state->general_bo != NULL;
+}
+
+bool gen6_render_init(struct sna *sna)
+{
+       if (!gen6_render_setup(sna))
+               return false;
+
+       sna->kgem.context_switch = gen6_render_context_switch;
+       sna->kgem.retire = gen6_render_retire;
+       sna->kgem.expire = gen6_render_expire;
+
+#if !NO_COMPOSITE
+       sna->render.composite = gen6_render_composite;
+#endif
+#if !NO_COMPOSITE_SPANS
+       sna->render.check_composite_spans = gen6_check_composite_spans;
+       sna->render.composite_spans = gen6_render_composite_spans;
+#endif
+       sna->render.video = gen6_render_video;
+
+#if !NO_COPY_BOXES
+       sna->render.copy_boxes = gen6_render_copy_boxes;
+#endif
+#if !NO_COPY
+       sna->render.copy = gen6_render_copy;
+#endif
+
+#if !NO_FILL_BOXES
+       sna->render.fill_boxes = gen6_render_fill_boxes;
+#endif
+#if !NO_FILL
+       sna->render.fill = gen6_render_fill;
+#endif
+#if !NO_FILL_ONE
+       sna->render.fill_one = gen6_render_fill_one;
+#endif
+#if !NO_FILL_CLEAR
+       sna->render.clear = gen6_render_clear;
+#endif
+
+       sna->render.flush = gen6_render_flush;
+       sna->render.reset = gen6_render_reset;
+       sna->render.fini = gen6_render_fini;
+
+       sna->render.max_3d_size = GEN6_MAX_SIZE;
+       sna->render.max_3d_pitch = 1 << 18;
+       return true;
+}
diff --git a/src/sna/gen6_render.h b/src/sna/gen6_render.h
new file mode 100644 (file)
index 0000000..2201a62
--- /dev/null
@@ -0,0 +1,1563 @@
+#ifndef GEN6_RENDER_H
+#define GEN6_RENDER_H
+
+#define GEN6_MASK(high, low) (((1 << ((high) - (low) + 1)) - 1) << (low))
+
+#define GEN6_3D(Pipeline,Opcode,Subopcode) ((3 << 29) | \
+                                          ((Pipeline) << 27) | \
+                                          ((Opcode) << 24) | \
+                                          ((Subopcode) << 16))
+
+#define GEN6_STATE_BASE_ADDRESS                        GEN6_3D(0, 1, 1)
+#define GEN6_STATE_SIP                         GEN6_3D(0, 1, 2)
+
+#define GEN6_PIPELINE_SELECT                   GEN6_3D(1, 1, 4)
+
+#define GEN6_MEDIA_STATE_POINTERS              GEN6_3D(2, 0, 0)
+#define GEN6_MEDIA_OBJECT                      GEN6_3D(2, 1, 0)
+
+#define GEN6_3DSTATE_BINDING_TABLE_POINTERS    GEN6_3D(3, 0, 1)
+# define GEN6_3DSTATE_BINDING_TABLE_MODIFY_PS  (1 << 12)/* for GEN6 */
+# define GEN6_3DSTATE_BINDING_TABLE_MODIFY_GS  (1 << 9) /* for GEN6 */
+# define GEN6_3DSTATE_BINDING_TABLE_MODIFY_VS  (1 << 8) /* for GEN6 */
+
+#define GEN6_3DSTATE_VERTEX_BUFFERS            GEN6_3D(3, 0, 8)
+#define GEN6_3DSTATE_VERTEX_ELEMENTS           GEN6_3D(3, 0, 9)
+#define GEN6_3DSTATE_INDEX_BUFFER              GEN6_3D(3, 0, 0xa)
+#define GEN6_3DSTATE_VF_STATISTICS             GEN6_3D(3, 0, 0xb)
+
+#define GEN6_3DSTATE_DRAWING_RECTANGLE         GEN6_3D(3, 1, 0)
+#define GEN6_3DSTATE_CONSTANT_COLOR            GEN6_3D(3, 1, 1)
+#define GEN6_3DSTATE_SAMPLER_PALETTE_LOAD      GEN6_3D(3, 1, 2)
+#define GEN6_3DSTATE_CHROMA_KEY                        GEN6_3D(3, 1, 4)
+#define GEN6_3DSTATE_DEPTH_BUFFER              GEN6_3D(3, 1, 5)
+# define GEN6_3DSTATE_DEPTH_BUFFER_TYPE_SHIFT  29
+# define GEN6_3DSTATE_DEPTH_BUFFER_FORMAT_SHIFT        18
+
+#define GEN6_3DSTATE_POLY_STIPPLE_OFFSET               GEN6_3D(3, 1, 6)
+#define GEN6_3DSTATE_POLY_STIPPLE_PATTERN      GEN6_3D(3, 1, 7)
+#define GEN6_3DSTATE_LINE_STIPPLE              GEN6_3D(3, 1, 8)
+#define GEN6_3DSTATE_GLOBAL_DEPTH_OFFSET_CLAMP GEN6_3D(3, 1, 9)
+/* These two are BLC and CTG only, not BW or CL */
+#define GEN6_3DSTATE_AA_LINE_PARAMS            GEN6_3D(3, 1, 0xa)
+#define GEN6_3DSTATE_GS_SVB_INDEX              GEN6_3D(3, 1, 0xb)
+
+#define GEN6_3DPRIMITIVE                               GEN6_3D(3, 3, 0)
+
+#define GEN6_3DSTATE_CLEAR_PARAMS              GEN6_3D(3, 1, 0x10)
+/* DW1 */
+# define GEN6_3DSTATE_DEPTH_CLEAR_VALID                (1 << 15)
+
+#define GEN6_3DSTATE_SAMPLER_STATE_POINTERS    GEN6_3D(3, 0, 0x02)
+# define GEN6_3DSTATE_SAMPLER_STATE_MODIFY_PS  (1 << 12)
+# define GEN6_3DSTATE_SAMPLER_STATE_MODIFY_GS  (1 << 9)
+# define GEN6_3DSTATE_SAMPLER_STATE_MODIFY_VS  (1 << 8)
+
+#define GEN6_3DSTATE_URB                       GEN6_3D(3, 0, 0x05)
+/* DW1 */
+# define GEN6_3DSTATE_URB_VS_SIZE_SHIFT                16
+# define GEN6_3DSTATE_URB_VS_ENTRIES_SHIFT     0
+/* DW2 */
+# define GEN6_3DSTATE_URB_GS_ENTRIES_SHIFT     8
+# define GEN6_3DSTATE_URB_GS_SIZE_SHIFT                0
+
+#define GEN6_3DSTATE_VIEWPORT_STATE_POINTERS   GEN6_3D(3, 0, 0x0d)
+# define GEN6_3DSTATE_VIEWPORT_STATE_MODIFY_CC         (1 << 12)
+# define GEN6_3DSTATE_VIEWPORT_STATE_MODIFY_SF         (1 << 11)
+# define GEN6_3DSTATE_VIEWPORT_STATE_MODIFY_CLIP       (1 << 10)
+
+#define GEN6_3DSTATE_CC_STATE_POINTERS         GEN6_3D(3, 0, 0x0e)
+
+#define GEN6_3DSTATE_VS                                GEN6_3D(3, 0, 0x10)
+
+#define GEN6_3DSTATE_GS                                GEN6_3D(3, 0, 0x11)
+/* DW4 */
+# define GEN6_3DSTATE_GS_DISPATCH_START_GRF_SHIFT      0
+
+#define GEN6_3DSTATE_CLIP                      GEN6_3D(3, 0, 0x12)
+
+#define GEN6_3DSTATE_SF                                GEN6_3D(3, 0, 0x13)
+/* DW1 */
+# define GEN6_3DSTATE_SF_NUM_OUTPUTS_SHIFT             22
+# define GEN6_3DSTATE_SF_URB_ENTRY_READ_LENGTH_SHIFT   11
+# define GEN6_3DSTATE_SF_URB_ENTRY_READ_OFFSET_SHIFT   4
+/* DW2 */
+/* DW3 */
+# define GEN6_3DSTATE_SF_CULL_BOTH                     (0 << 29)
+# define GEN6_3DSTATE_SF_CULL_NONE                     (1 << 29)
+# define GEN6_3DSTATE_SF_CULL_FRONT                    (2 << 29)
+# define GEN6_3DSTATE_SF_CULL_BACK                     (3 << 29)
+/* DW4 */
+# define GEN6_3DSTATE_SF_TRI_PROVOKE_SHIFT             29
+# define GEN6_3DSTATE_SF_LINE_PROVOKE_SHIFT            27
+# define GEN6_3DSTATE_SF_TRIFAN_PROVOKE_SHIFT          25
+
+#define GEN6_3DSTATE_WM                                GEN6_3D(3, 0, 0x14)
+/* DW2 */
+# define GEN6_3DSTATE_WM_SAMPLER_COUNT_SHIFT                   27
+# define GEN6_3DSTATE_WM_BINDING_TABLE_ENTRY_COUNT_SHIFT       18
+/* DW4 */
+# define GEN6_3DSTATE_WM_DISPATCH_0_START_GRF_SHIFT            16
+# define GEN6_3DSTATE_WM_DISPATCH_1_START_GRF_SHIFT            8
+# define GEN6_3DSTATE_WM_DISPATCH_2_START_GRF_SHIFT            0
+/* DW5 */
+# define GEN6_3DSTATE_WM_MAX_THREADS_SHIFT                     25
+# define GEN6_3DSTATE_WM_DISPATCH_ENABLE                       (1 << 19)
+# define GEN6_3DSTATE_WM_32_DISPATCH_ENABLE                    (1 << 2)
+# define GEN6_3DSTATE_WM_16_DISPATCH_ENABLE                    (1 << 1)
+# define GEN6_3DSTATE_WM_8_DISPATCH_ENABLE                     (1 << 0)
+/* DW6 */
+# define GEN6_3DSTATE_WM_NUM_SF_OUTPUTS_SHIFT                  20
+# define GEN6_3DSTATE_WM_NONPERSPECTIVE_SAMPLE_BARYCENTRIC     (1 << 15)
+# define GEN6_3DSTATE_WM_NONPERSPECTIVE_CENTROID_BARYCENTRIC   (1 << 14)
+# define GEN6_3DSTATE_WM_NONPERSPECTIVE_PIXEL_BARYCENTRIC      (1 << 13)
+# define GEN6_3DSTATE_WM_PERSPECTIVE_SAMPLE_BARYCENTRIC                (1 << 12)
+# define GEN6_3DSTATE_WM_PERSPECTIVE_CENTROID_BARYCENTRIC      (1 << 11)
+# define GEN6_3DSTATE_WM_PERSPECTIVE_PIXEL_BARYCENTRIC         (1 << 10)
+
+
+#define GEN6_3DSTATE_CONSTANT_VS               GEN6_3D(3, 0, 0x15)
+#define GEN6_3DSTATE_CONSTANT_GS               GEN6_3D(3, 0, 0x16)
+#define GEN6_3DSTATE_CONSTANT_PS               GEN6_3D(3, 0, 0x17)
+
+#define GEN6_3DSTATE_SAMPLE_MASK               GEN6_3D(3, 0, 0x18)
+
+#define GEN6_3DSTATE_MULTISAMPLE               GEN6_3D(3, 1, 0x0d)
+/* DW1 */
+# define GEN6_3DSTATE_MULTISAMPLE_PIXEL_LOCATION_CENTER                (0 << 4)
+# define GEN6_3DSTATE_MULTISAMPLE_PIXEL_LOCATION_UPPER_LEFT    (1 << 4)
+# define GEN6_3DSTATE_MULTISAMPLE_NUMSAMPLES_1                 (0 << 1)
+# define GEN6_3DSTATE_MULTISAMPLE_NUMSAMPLES_4                 (2 << 1)
+# define GEN6_3DSTATE_MULTISAMPLE_NUMSAMPLES_8                 (3 << 1)
+
+#define PIPELINE_SELECT_3D             0
+#define PIPELINE_SELECT_MEDIA          1
+
+/* for GEN6_STATE_BASE_ADDRESS */
+#define BASE_ADDRESS_MODIFY            (1 << 0)
+
+/* VERTEX_BUFFER_STATE Structure */
+#define VB0_BUFFER_INDEX_SHIFT 26
+#define VB0_VERTEXDATA                 (0 << 20)
+#define VB0_INSTANCEDATA               (1 << 20)
+#define VB0_BUFFER_PITCH_SHIFT         0
+
+/* VERTEX_ELEMENT_STATE Structure */
+#define VE0_VERTEX_BUFFER_INDEX_SHIFT  26 /* for GEN6 */
+#define VE0_VALID                      (1 << 25) /* for GEN6 */
+#define VE0_FORMAT_SHIFT               16
+#define VE0_OFFSET_SHIFT               0
+#define VE1_VFCOMPONENT_0_SHIFT                28
+#define VE1_VFCOMPONENT_1_SHIFT                24
+#define VE1_VFCOMPONENT_2_SHIFT                20
+#define VE1_VFCOMPONENT_3_SHIFT                16
+#define VE1_DESTINATION_ELEMENT_OFFSET_SHIFT   0
+
+/* 3DPRIMITIVE bits */
+#define GEN6_3DPRIMITIVE_VERTEX_SEQUENTIAL (0 << 15)
+#define GEN6_3DPRIMITIVE_VERTEX_RANDOM   (1 << 15)
+/* Primitive types are in gen6_defines.h */
+#define GEN6_3DPRIMITIVE_TOPOLOGY_SHIFT          10
+
+#define GEN6_SVG_CTL                  0x7400
+
+#define GEN6_SVG_CTL_GS_BA            (0 << 8)
+#define GEN6_SVG_CTL_SS_BA            (1 << 8)
+#define GEN6_SVG_CTL_IO_BA            (2 << 8)
+#define GEN6_SVG_CTL_GS_AUB           (3 << 8)
+#define GEN6_SVG_CTL_IO_AUB           (4 << 8)
+#define GEN6_SVG_CTL_SIP                      (5 << 8)
+
+#define GEN6_SVG_RDATA                0x7404
+#define GEN6_SVG_WORK_CTL             0x7408
+
+#define GEN6_VF_CTL                   0x7500
+
+#define GEN6_VF_CTL_SNAPSHOT_COMPLETE             (1 << 31)
+#define GEN6_VF_CTL_SNAPSHOT_MUX_SELECT_THREADID          (0 << 8)
+#define GEN6_VF_CTL_SNAPSHOT_MUX_SELECT_VF_DEBUG          (1 << 8)
+#define GEN6_VF_CTL_SNAPSHOT_TYPE_VERTEX_SEQUENCE   (0 << 4)
+#define GEN6_VF_CTL_SNAPSHOT_TYPE_VERTEX_INDEX    (1 << 4)
+#define GEN6_VF_CTL_SKIP_INITIAL_PRIMITIVES       (1 << 3)
+#define GEN6_VF_CTL_MAX_PRIMITIVES_LIMIT_ENABLE           (1 << 2)
+#define GEN6_VF_CTL_VERTEX_RANGE_LIMIT_ENABLE     (1 << 1)
+#define GEN6_VF_CTL_SNAPSHOT_ENABLE               (1 << 0)
+
+#define GEN6_VF_STRG_VAL                      0x7504
+#define GEN6_VF_STR_VL_OVR            0x7508
+#define GEN6_VF_VC_OVR                0x750c
+#define GEN6_VF_STR_PSKIP             0x7510
+#define GEN6_VF_MAX_PRIM                      0x7514
+#define GEN6_VF_RDATA                 0x7518
+
+#define GEN6_VS_CTL                   0x7600
+#define GEN6_VS_CTL_SNAPSHOT_COMPLETE             (1 << 31)
+#define GEN6_VS_CTL_SNAPSHOT_MUX_VERTEX_0         (0 << 8)
+#define GEN6_VS_CTL_SNAPSHOT_MUX_VERTEX_1         (1 << 8)
+#define GEN6_VS_CTL_SNAPSHOT_MUX_VALID_COUNT      (2 << 8)
+#define GEN6_VS_CTL_SNAPSHOT_MUX_VS_KERNEL_POINTER  (3 << 8)
+#define GEN6_VS_CTL_SNAPSHOT_ALL_THREADS                  (1 << 2)
+#define GEN6_VS_CTL_THREAD_SNAPSHOT_ENABLE        (1 << 1)
+#define GEN6_VS_CTL_SNAPSHOT_ENABLE               (1 << 0)
+
+#define GEN6_VS_STRG_VAL                      0x7604
+#define GEN6_VS_RDATA                 0x7608
+
+#define GEN6_SF_CTL                   0x7b00
+#define GEN6_SF_CTL_SNAPSHOT_COMPLETE             (1 << 31)
+#define GEN6_SF_CTL_SNAPSHOT_MUX_VERTEX_0_FF_ID           (0 << 8)
+#define GEN6_SF_CTL_SNAPSHOT_MUX_VERTEX_0_REL_COUNT (1 << 8)
+#define GEN6_SF_CTL_SNAPSHOT_MUX_VERTEX_1_FF_ID           (2 << 8)
+#define GEN6_SF_CTL_SNAPSHOT_MUX_VERTEX_1_REL_COUNT (3 << 8)
+#define GEN6_SF_CTL_SNAPSHOT_MUX_VERTEX_2_FF_ID           (4 << 8)
+#define GEN6_SF_CTL_SNAPSHOT_MUX_VERTEX_2_REL_COUNT (5 << 8)
+#define GEN6_SF_CTL_SNAPSHOT_MUX_VERTEX_COUNT     (6 << 8)
+#define GEN6_SF_CTL_SNAPSHOT_MUX_SF_KERNEL_POINTER  (7 << 8)
+#define GEN6_SF_CTL_MIN_MAX_PRIMITIVE_RANGE_ENABLE  (1 << 4)
+#define GEN6_SF_CTL_DEBUG_CLIP_RECTANGLE_ENABLE           (1 << 3)
+#define GEN6_SF_CTL_SNAPSHOT_ALL_THREADS                  (1 << 2)
+#define GEN6_SF_CTL_THREAD_SNAPSHOT_ENABLE        (1 << 1)
+#define GEN6_SF_CTL_SNAPSHOT_ENABLE               (1 << 0)
+
+#define GEN6_SF_STRG_VAL                      0x7b04
+#define GEN6_SF_RDATA                 0x7b18
+
+#define GEN6_WIZ_CTL                  0x7c00
+#define GEN6_WIZ_CTL_SNAPSHOT_COMPLETE            (1 << 31)
+#define GEN6_WIZ_CTL_SUBSPAN_INSTANCE_SHIFT       16
+#define GEN6_WIZ_CTL_SNAPSHOT_MUX_WIZ_KERNEL_POINTER   (0 << 8)
+#define GEN6_WIZ_CTL_SNAPSHOT_MUX_SUBSPAN_INSTANCE     (1 << 8)
+#define GEN6_WIZ_CTL_SNAPSHOT_MUX_PRIMITIVE_SEQUENCE   (2 << 8)
+#define GEN6_WIZ_CTL_SINGLE_SUBSPAN_DISPATCH         (1 << 6)
+#define GEN6_WIZ_CTL_IGNORE_COLOR_SCOREBOARD_STALLS    (1 << 5)
+#define GEN6_WIZ_CTL_ENABLE_SUBSPAN_INSTANCE_COMPARE   (1 << 4)
+#define GEN6_WIZ_CTL_USE_UPSTREAM_SNAPSHOT_FLAG              (1 << 3)
+#define GEN6_WIZ_CTL_SNAPSHOT_ALL_THREADS            (1 << 2)
+#define GEN6_WIZ_CTL_THREAD_SNAPSHOT_ENABLE          (1 << 1)
+#define GEN6_WIZ_CTL_SNAPSHOT_ENABLE                 (1 << 0)
+
+#define GEN6_WIZ_STRG_VAL                            0x7c04
+#define GEN6_WIZ_RDATA                               0x7c18
+
+#define GEN6_TS_CTL                   0x7e00
+#define GEN6_TS_CTL_SNAPSHOT_COMPLETE             (1 << 31)
+#define GEN6_TS_CTL_SNAPSHOT_MESSAGE_ERROR        (0 << 8)
+#define GEN6_TS_CTL_SNAPSHOT_INTERFACE_DESCRIPTOR   (3 << 8)
+#define GEN6_TS_CTL_SNAPSHOT_ALL_CHILD_THREADS    (1 << 2)
+#define GEN6_TS_CTL_SNAPSHOT_ALL_ROOT_THREADS             (1 << 1)
+#define GEN6_TS_CTL_SNAPSHOT_ENABLE               (1 << 0)
+
+#define GEN6_TS_STRG_VAL                      0x7e04
+#define GEN6_TS_RDATA                 0x7e08
+
+#define GEN6_TD_CTL                   0x8000
+#define GEN6_TD_CTL_MUX_SHIFT         8
+#define GEN6_TD_CTL_EXTERNAL_HALT_R0_DEBUG_MATCH          (1 << 7)
+#define GEN6_TD_CTL_FORCE_EXTERNAL_HALT                   (1 << 6)
+#define GEN6_TD_CTL_EXCEPTION_MASK_OVERRIDE       (1 << 5)
+#define GEN6_TD_CTL_FORCE_THREAD_BREAKPOINT_ENABLE  (1 << 4)
+#define GEN6_TD_CTL_BREAKPOINT_ENABLE             (1 << 2)
+#define GEN6_TD_CTL2                  0x8004
+#define GEN6_TD_CTL2_ILLEGAL_OPCODE_EXCEPTION_OVERRIDE (1 << 28)
+#define GEN6_TD_CTL2_MASKSTACK_EXCEPTION_OVERRIDE      (1 << 26)
+#define GEN6_TD_CTL2_SOFTWARE_EXCEPTION_OVERRIDE             (1 << 25)
+#define GEN6_TD_CTL2_ACTIVE_THREAD_LIMIT_SHIFT       16
+#define GEN6_TD_CTL2_ACTIVE_THREAD_LIMIT_ENABLE              (1 << 8)
+#define GEN6_TD_CTL2_THREAD_SPAWNER_EXECUTION_MASK_ENABLE (1 << 7)
+#define GEN6_TD_CTL2_WIZ_EXECUTION_MASK_ENABLE       (1 << 6)
+#define GEN6_TD_CTL2_SF_EXECUTION_MASK_ENABLE        (1 << 5)
+#define GEN6_TD_CTL2_CLIPPER_EXECUTION_MASK_ENABLE     (1 << 4)
+#define GEN6_TD_CTL2_GS_EXECUTION_MASK_ENABLE        (1 << 3)
+#define GEN6_TD_CTL2_VS_EXECUTION_MASK_ENABLE        (1 << 0)
+#define GEN6_TD_VF_VS_EMSK            0x8008
+#define GEN6_TD_GS_EMSK                       0x800c
+#define GEN6_TD_CLIP_EMSK             0x8010
+#define GEN6_TD_SF_EMSK                       0x8014
+#define GEN6_TD_WIZ_EMSK                      0x8018
+#define GEN6_TD_0_6_EHTRG_VAL         0x801c
+#define GEN6_TD_0_7_EHTRG_VAL         0x8020
+#define GEN6_TD_0_6_EHTRG_MSK           0x8024
+#define GEN6_TD_0_7_EHTRG_MSK         0x8028
+#define GEN6_TD_RDATA                 0x802c
+#define GEN6_TD_TS_EMSK                       0x8030
+
+#define GEN6_EU_CTL                   0x8800
+#define GEN6_EU_CTL_SELECT_SHIFT              16
+#define GEN6_EU_CTL_DATA_MUX_SHIFT      8
+#define GEN6_EU_ATT_0                 0x8810
+#define GEN6_EU_ATT_1                 0x8814
+#define GEN6_EU_ATT_DATA_0            0x8820
+#define GEN6_EU_ATT_DATA_1            0x8824
+#define GEN6_EU_ATT_CLR_0             0x8830
+#define GEN6_EU_ATT_CLR_1             0x8834
+#define GEN6_EU_RDATA                 0x8840
+
+#define GEN6_3D(Pipeline,Opcode,Subopcode) ((3 << 29) | \
+                                          ((Pipeline) << 27) | \
+                                          ((Opcode) << 24) | \
+                                          ((Subopcode) << 16))
+
+#define GEN6_STATE_BASE_ADDRESS                        GEN6_3D(0, 1, 1)
+#define GEN6_STATE_SIP                         GEN6_3D(0, 1, 2)
+
+#define GEN6_PIPELINE_SELECT                   GEN6_3D(1, 1, 4)
+
+#define GEN6_MEDIA_STATE_POINTERS              GEN6_3D(2, 0, 0)
+#define GEN6_MEDIA_OBJECT                      GEN6_3D(2, 1, 0)
+
+#define GEN6_3DSTATE_BINDING_TABLE_POINTERS    GEN6_3D(3, 0, 1)
+# define GEN6_3DSTATE_BINDING_TABLE_MODIFY_PS  (1 << 12)/* for GEN6 */
+# define GEN6_3DSTATE_BINDING_TABLE_MODIFY_GS  (1 << 9) /* for GEN6 */
+# define GEN6_3DSTATE_BINDING_TABLE_MODIFY_VS  (1 << 8) /* for GEN6 */
+
+#define GEN6_3DSTATE_VERTEX_BUFFERS            GEN6_3D(3, 0, 8)
+#define GEN6_3DSTATE_VERTEX_ELEMENTS           GEN6_3D(3, 0, 9)
+#define GEN6_3DSTATE_INDEX_BUFFER              GEN6_3D(3, 0, 0xa)
+#define GEN6_3DSTATE_VF_STATISTICS             GEN6_3D(3, 0, 0xb)
+
+#define GEN6_3DSTATE_DRAWING_RECTANGLE         GEN6_3D(3, 1, 0)
+#define GEN6_3DSTATE_CONSTANT_COLOR            GEN6_3D(3, 1, 1)
+#define GEN6_3DSTATE_SAMPLER_PALETTE_LOAD      GEN6_3D(3, 1, 2)
+#define GEN6_3DSTATE_CHROMA_KEY                        GEN6_3D(3, 1, 4)
+#define GEN6_3DSTATE_DEPTH_BUFFER              GEN6_3D(3, 1, 5)
+# define GEN6_3DSTATE_DEPTH_BUFFER_TYPE_SHIFT  29
+# define GEN6_3DSTATE_DEPTH_BUFFER_FORMAT_SHIFT        18
+
+#define GEN6_3DSTATE_POLY_STIPPLE_OFFSET               GEN6_3D(3, 1, 6)
+#define GEN6_3DSTATE_POLY_STIPPLE_PATTERN      GEN6_3D(3, 1, 7)
+#define GEN6_3DSTATE_LINE_STIPPLE              GEN6_3D(3, 1, 8)
+#define GEN6_3DSTATE_GLOBAL_DEPTH_OFFSET_CLAMP GEN6_3D(3, 1, 9)
+/* These two are BLC and CTG only, not BW or CL */
+#define GEN6_3DSTATE_AA_LINE_PARAMS            GEN6_3D(3, 1, 0xa)
+#define GEN6_3DSTATE_GS_SVB_INDEX              GEN6_3D(3, 1, 0xb)
+
+#define GEN6_3DPRIMITIVE                               GEN6_3D(3, 3, 0)
+
+#define GEN6_3DSTATE_CLEAR_PARAMS              GEN6_3D(3, 1, 0x10)
+/* DW1 */
+# define GEN6_3DSTATE_DEPTH_CLEAR_VALID                (1 << 15)
+
+/* for GEN6+ */
+#define GEN6_3DSTATE_SAMPLER_STATE_POINTERS    GEN6_3D(3, 0, 0x02)
+# define GEN6_3DSTATE_SAMPLER_STATE_MODIFY_PS  (1 << 12)
+# define GEN6_3DSTATE_SAMPLER_STATE_MODIFY_GS  (1 << 9)
+# define GEN6_3DSTATE_SAMPLER_STATE_MODIFY_VS  (1 << 8)
+
+#define GEN6_3DSTATE_URB                       GEN6_3D(3, 0, 0x05)
+/* DW1 */
+# define GEN6_3DSTATE_URB_VS_SIZE_SHIFT                16
+# define GEN6_3DSTATE_URB_VS_ENTRIES_SHIFT     0
+/* DW2 */
+# define GEN6_3DSTATE_URB_GS_ENTRIES_SHIFT     8
+# define GEN6_3DSTATE_URB_GS_SIZE_SHIFT                0
+
+#define GEN6_3DSTATE_VIEWPORT_STATE_POINTERS   GEN6_3D(3, 0, 0x0d)
+# define GEN6_3DSTATE_VIEWPORT_STATE_MODIFY_CC         (1 << 12)
+# define GEN6_3DSTATE_VIEWPORT_STATE_MODIFY_SF         (1 << 11)
+# define GEN6_3DSTATE_VIEWPORT_STATE_MODIFY_CLIP       (1 << 10)
+
+#define GEN6_3DSTATE_CC_STATE_POINTERS         GEN6_3D(3, 0, 0x0e)
+
+#define GEN6_3DSTATE_VS                                GEN6_3D(3, 0, 0x10)
+
+#define GEN6_3DSTATE_GS                                GEN6_3D(3, 0, 0x11)
+/* DW4 */
+# define GEN6_3DSTATE_GS_DISPATCH_START_GRF_SHIFT      0
+
+#define GEN6_3DSTATE_CLIP                      GEN6_3D(3, 0, 0x12)
+
+#define GEN6_3DSTATE_SF                                GEN6_3D(3, 0, 0x13)
+/* DW1 */
+# define GEN6_3DSTATE_SF_NUM_OUTPUTS_SHIFT             22
+# define GEN6_3DSTATE_SF_URB_ENTRY_READ_LENGTH_SHIFT   11
+# define GEN6_3DSTATE_SF_URB_ENTRY_READ_OFFSET_SHIFT   4
+/* DW2 */
+/* DW3 */
+# define GEN6_3DSTATE_SF_CULL_BOTH                     (0 << 29)
+# define GEN6_3DSTATE_SF_CULL_NONE                     (1 << 29)
+# define GEN6_3DSTATE_SF_CULL_FRONT                    (2 << 29)
+# define GEN6_3DSTATE_SF_CULL_BACK                     (3 << 29)
+/* DW4 */
+# define GEN6_3DSTATE_SF_TRI_PROVOKE_SHIFT             29
+# define GEN6_3DSTATE_SF_LINE_PROVOKE_SHIFT            27
+# define GEN6_3DSTATE_SF_TRIFAN_PROVOKE_SHIFT          25
+
+
+#define GEN6_3DSTATE_WM                                GEN6_3D(3, 0, 0x14)
+/* DW2 */
+# define GEN6_3DSTATE_WM_SAMPLER_COUNT_SHITF                   27
+# define GEN6_3DSTATE_WM_BINDING_TABLE_ENTRY_COUNT_SHIFT       18
+/* DW4 */
+# define GEN6_3DSTATE_WM_DISPATCH_START_GRF_0_SHIFT            16
+/* DW5 */
+# define GEN6_3DSTATE_WM_MAX_THREADS_SHIFT                     25
+# define GEN6_3DSTATE_WM_DISPATCH_ENABLE                       (1 << 19)
+# define GEN6_3DSTATE_WM_16_DISPATCH_ENABLE                    (1 << 1)
+# define GEN6_3DSTATE_WM_8_DISPATCH_ENABLE                     (1 << 0)
+/* DW6 */
+# define GEN6_3DSTATE_WM_NUM_SF_OUTPUTS_SHIFT                  20
+# define GEN6_3DSTATE_WM_NONPERSPECTIVE_SAMPLE_BARYCENTRIC     (1 << 15)
+# define GEN6_3DSTATE_WM_NONPERSPECTIVE_CENTROID_BARYCENTRIC   (1 << 14)
+# define GEN6_3DSTATE_WM_NONPERSPECTIVE_PIXEL_BARYCENTRIC      (1 << 13)
+# define GEN6_3DSTATE_WM_PERSPECTIVE_SAMPLE_BARYCENTRIC                (1 << 12)
+# define GEN6_3DSTATE_WM_PERSPECTIVE_CENTROID_BARYCENTRIC      (1 << 11)
+# define GEN6_3DSTATE_WM_PERSPECTIVE_PIXEL_BARYCENTRIC         (1 << 10)
+
+
+#define GEN6_3DSTATE_CONSTANT_VS               GEN6_3D(3, 0, 0x15)
+#define GEN6_3DSTATE_CONSTANT_GS               GEN6_3D(3, 0, 0x16)
+#define GEN6_3DSTATE_CONSTANT_PS               GEN6_3D(3, 0, 0x17)
+
+#define GEN6_3DSTATE_SAMPLE_MASK               GEN6_3D(3, 0, 0x18)
+
+#define GEN6_3DSTATE_MULTISAMPLE               GEN6_3D(3, 1, 0x0d)
+/* DW1 */
+# define GEN6_3DSTATE_MULTISAMPLE_PIXEL_LOCATION_CENTER                (0 << 4)
+# define GEN6_3DSTATE_MULTISAMPLE_PIXEL_LOCATION_UPPER_LEFT    (1 << 4)
+# define GEN6_3DSTATE_MULTISAMPLE_NUMSAMPLES_1                 (0 << 1)
+# define GEN6_3DSTATE_MULTISAMPLE_NUMSAMPLES_4                 (2 << 1)
+# define GEN6_3DSTATE_MULTISAMPLE_NUMSAMPLES_8                 (3 << 1)
+
+#define PIPELINE_SELECT_3D             0
+#define PIPELINE_SELECT_MEDIA          1
+
+#define UF0_CS_REALLOC                 (1 << 13)
+#define UF0_VFE_REALLOC                        (1 << 12)
+#define UF0_SF_REALLOC                 (1 << 11)
+#define UF0_CLIP_REALLOC               (1 << 10)
+#define UF0_GS_REALLOC                 (1 << 9)
+#define UF0_VS_REALLOC                 (1 << 8)
+#define UF1_CLIP_FENCE_SHIFT           20
+#define UF1_GS_FENCE_SHIFT             10
+#define UF1_VS_FENCE_SHIFT             0
+#define UF2_CS_FENCE_SHIFT             20
+#define UF2_VFE_FENCE_SHIFT            10
+#define UF2_SF_FENCE_SHIFT             0
+
+/* for GEN6_STATE_BASE_ADDRESS */
+#define BASE_ADDRESS_MODIFY            (1 << 0)
+
+/* for GEN6_3DSTATE_PIPELINED_POINTERS */
+#define GEN6_GS_DISABLE                       0
+#define GEN6_GS_ENABLE                1
+#define GEN6_CLIP_DISABLE             0
+#define GEN6_CLIP_ENABLE                      1
+
+/* for GEN6_PIPE_CONTROL */
+#define GEN6_PIPE_CONTROL              GEN6_3D(3, 2, 0)
+#define GEN6_PIPE_CONTROL_CS_STALL      (1 << 20)
+#define GEN6_PIPE_CONTROL_NOWRITE       (0 << 14)
+#define GEN6_PIPE_CONTROL_WRITE_QWORD   (1 << 14)
+#define GEN6_PIPE_CONTROL_WRITE_DEPTH   (2 << 14)
+#define GEN6_PIPE_CONTROL_WRITE_TIME    (3 << 14)
+#define GEN6_PIPE_CONTROL_DEPTH_STALL   (1 << 13)
+#define GEN6_PIPE_CONTROL_WC_FLUSH      (1 << 12)
+#define GEN6_PIPE_CONTROL_IS_FLUSH      (1 << 11)
+#define GEN6_PIPE_CONTROL_TC_FLUSH      (1 << 10)
+#define GEN6_PIPE_CONTROL_NOTIFY_ENABLE (1 << 8)
+#define GEN6_PIPE_CONTROL_GLOBAL_GTT    (1 << 2)
+#define GEN6_PIPE_CONTROL_LOCAL_PGTT    (0 << 2)
+#define GEN6_PIPE_CONTROL_STALL_AT_SCOREBOARD   (1 << 1)
+#define GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH    (1 << 0)
+
+/* 3DPRIMITIVE bits */
+#define GEN6_3DPRIMITIVE_VERTEX_SEQUENTIAL (0 << 15)
+#define GEN6_3DPRIMITIVE_VERTEX_RANDOM   (1 << 15)
+/* Primitive types are in gen6_defines.h */
+#define GEN6_3DPRIMITIVE_TOPOLOGY_SHIFT          10
+
+#define GEN6_SVG_CTL                  0x7400
+
+#define GEN6_SVG_CTL_GS_BA            (0 << 8)
+#define GEN6_SVG_CTL_SS_BA            (1 << 8)
+#define GEN6_SVG_CTL_IO_BA            (2 << 8)
+#define GEN6_SVG_CTL_GS_AUB           (3 << 8)
+#define GEN6_SVG_CTL_IO_AUB           (4 << 8)
+#define GEN6_SVG_CTL_SIP                      (5 << 8)
+
+#define GEN6_SVG_RDATA                0x7404
+#define GEN6_SVG_WORK_CTL             0x7408
+
+#define GEN6_VF_CTL                   0x7500
+
+#define GEN6_VF_CTL_SNAPSHOT_COMPLETE             (1 << 31)
+#define GEN6_VF_CTL_SNAPSHOT_MUX_SELECT_THREADID          (0 << 8)
+#define GEN6_VF_CTL_SNAPSHOT_MUX_SELECT_VF_DEBUG          (1 << 8)
+#define GEN6_VF_CTL_SNAPSHOT_TYPE_VERTEX_SEQUENCE   (0 << 4)
+#define GEN6_VF_CTL_SNAPSHOT_TYPE_VERTEX_INDEX    (1 << 4)
+#define GEN6_VF_CTL_SKIP_INITIAL_PRIMITIVES       (1 << 3)
+#define GEN6_VF_CTL_MAX_PRIMITIVES_LIMIT_ENABLE           (1 << 2)
+#define GEN6_VF_CTL_VERTEX_RANGE_LIMIT_ENABLE     (1 << 1)
+#define GEN6_VF_CTL_SNAPSHOT_ENABLE               (1 << 0)
+
+#define GEN6_VF_STRG_VAL                      0x7504
+#define GEN6_VF_STR_VL_OVR            0x7508
+#define GEN6_VF_VC_OVR                0x750c
+#define GEN6_VF_STR_PSKIP             0x7510
+#define GEN6_VF_MAX_PRIM                      0x7514
+#define GEN6_VF_RDATA                 0x7518
+
+#define GEN6_VS_CTL                   0x7600
+#define GEN6_VS_CTL_SNAPSHOT_COMPLETE             (1 << 31)
+#define GEN6_VS_CTL_SNAPSHOT_MUX_VERTEX_0         (0 << 8)
+#define GEN6_VS_CTL_SNAPSHOT_MUX_VERTEX_1         (1 << 8)
+#define GEN6_VS_CTL_SNAPSHOT_MUX_VALID_COUNT      (2 << 8)
+#define GEN6_VS_CTL_SNAPSHOT_MUX_VS_KERNEL_POINTER  (3 << 8)
+#define GEN6_VS_CTL_SNAPSHOT_ALL_THREADS                  (1 << 2)
+#define GEN6_VS_CTL_THREAD_SNAPSHOT_ENABLE        (1 << 1)
+#define GEN6_VS_CTL_SNAPSHOT_ENABLE               (1 << 0)
+
+#define GEN6_VS_STRG_VAL                      0x7604
+#define GEN6_VS_RDATA                 0x7608
+
+#define GEN6_SF_CTL                   0x7b00
+#define GEN6_SF_CTL_SNAPSHOT_COMPLETE             (1 << 31)
+#define GEN6_SF_CTL_SNAPSHOT_MUX_VERTEX_0_FF_ID           (0 << 8)
+#define GEN6_SF_CTL_SNAPSHOT_MUX_VERTEX_0_REL_COUNT (1 << 8)
+#define GEN6_SF_CTL_SNAPSHOT_MUX_VERTEX_1_FF_ID           (2 << 8)
+#define GEN6_SF_CTL_SNAPSHOT_MUX_VERTEX_1_REL_COUNT (3 << 8)
+#define GEN6_SF_CTL_SNAPSHOT_MUX_VERTEX_2_FF_ID           (4 << 8)
+#define GEN6_SF_CTL_SNAPSHOT_MUX_VERTEX_2_REL_COUNT (5 << 8)
+#define GEN6_SF_CTL_SNAPSHOT_MUX_VERTEX_COUNT     (6 << 8)
+#define GEN6_SF_CTL_SNAPSHOT_MUX_SF_KERNEL_POINTER  (7 << 8)
+#define GEN6_SF_CTL_MIN_MAX_PRIMITIVE_RANGE_ENABLE  (1 << 4)
+#define GEN6_SF_CTL_DEBUG_CLIP_RECTANGLE_ENABLE           (1 << 3)
+#define GEN6_SF_CTL_SNAPSHOT_ALL_THREADS                  (1 << 2)
+#define GEN6_SF_CTL_THREAD_SNAPSHOT_ENABLE        (1 << 1)
+#define GEN6_SF_CTL_SNAPSHOT_ENABLE               (1 << 0)
+
+#define GEN6_SF_STRG_VAL                      0x7b04
+#define GEN6_SF_RDATA                 0x7b18
+
+#define GEN6_WIZ_CTL                  0x7c00
+#define GEN6_WIZ_CTL_SNAPSHOT_COMPLETE            (1 << 31)
+#define GEN6_WIZ_CTL_SUBSPAN_INSTANCE_SHIFT       16
+#define GEN6_WIZ_CTL_SNAPSHOT_MUX_WIZ_KERNEL_POINTER   (0 << 8)
+#define GEN6_WIZ_CTL_SNAPSHOT_MUX_SUBSPAN_INSTANCE     (1 << 8)
+#define GEN6_WIZ_CTL_SNAPSHOT_MUX_PRIMITIVE_SEQUENCE   (2 << 8)
+#define GEN6_WIZ_CTL_SINGLE_SUBSPAN_DISPATCH         (1 << 6)
+#define GEN6_WIZ_CTL_IGNORE_COLOR_SCOREBOARD_STALLS    (1 << 5)
+#define GEN6_WIZ_CTL_ENABLE_SUBSPAN_INSTANCE_COMPARE   (1 << 4)
+#define GEN6_WIZ_CTL_USE_UPSTREAM_SNAPSHOT_FLAG              (1 << 3)
+#define GEN6_WIZ_CTL_SNAPSHOT_ALL_THREADS            (1 << 2)
+#define GEN6_WIZ_CTL_THREAD_SNAPSHOT_ENABLE          (1 << 1)
+#define GEN6_WIZ_CTL_SNAPSHOT_ENABLE                 (1 << 0)
+
+#define GEN6_WIZ_STRG_VAL                            0x7c04
+#define GEN6_WIZ_RDATA                               0x7c18
+
+#define GEN6_TS_CTL                   0x7e00
+#define GEN6_TS_CTL_SNAPSHOT_COMPLETE             (1 << 31)
+#define GEN6_TS_CTL_SNAPSHOT_MESSAGE_ERROR        (0 << 8)
+#define GEN6_TS_CTL_SNAPSHOT_INTERFACE_DESCRIPTOR   (3 << 8)
+#define GEN6_TS_CTL_SNAPSHOT_ALL_CHILD_THREADS    (1 << 2)
+#define GEN6_TS_CTL_SNAPSHOT_ALL_ROOT_THREADS             (1 << 1)
+#define GEN6_TS_CTL_SNAPSHOT_ENABLE               (1 << 0)
+
+#define GEN6_TS_STRG_VAL                      0x7e04
+#define GEN6_TS_RDATA                 0x7e08
+
+#define GEN6_TD_CTL                   0x8000
+#define GEN6_TD_CTL_MUX_SHIFT         8
+#define GEN6_TD_CTL_EXTERNAL_HALT_R0_DEBUG_MATCH          (1 << 7)
+#define GEN6_TD_CTL_FORCE_EXTERNAL_HALT                   (1 << 6)
+#define GEN6_TD_CTL_EXCEPTION_MASK_OVERRIDE       (1 << 5)
+#define GEN6_TD_CTL_FORCE_THREAD_BREAKPOINT_ENABLE  (1 << 4)
+#define GEN6_TD_CTL_BREAKPOINT_ENABLE             (1 << 2)
+#define GEN6_TD_CTL2                  0x8004
+#define GEN6_TD_CTL2_ILLEGAL_OPCODE_EXCEPTION_OVERRIDE (1 << 28)
+#define GEN6_TD_CTL2_MASKSTACK_EXCEPTION_OVERRIDE      (1 << 26)
+#define GEN6_TD_CTL2_SOFTWARE_EXCEPTION_OVERRIDE             (1 << 25)
+#define GEN6_TD_CTL2_ACTIVE_THREAD_LIMIT_SHIFT       16
+#define GEN6_TD_CTL2_ACTIVE_THREAD_LIMIT_ENABLE              (1 << 8)
+#define GEN6_TD_CTL2_THREAD_SPAWNER_EXECUTION_MASK_ENABLE (1 << 7)
+#define GEN6_TD_CTL2_WIZ_EXECUTION_MASK_ENABLE       (1 << 6)
+#define GEN6_TD_CTL2_SF_EXECUTION_MASK_ENABLE        (1 << 5)
+#define GEN6_TD_CTL2_CLIPPER_EXECUTION_MASK_ENABLE     (1 << 4)
+#define GEN6_TD_CTL2_GS_EXECUTION_MASK_ENABLE        (1 << 3)
+#define GEN6_TD_CTL2_VS_EXECUTION_MASK_ENABLE        (1 << 0)
+#define GEN6_TD_VF_VS_EMSK            0x8008
+#define GEN6_TD_GS_EMSK                       0x800c
+#define GEN6_TD_CLIP_EMSK             0x8010
+#define GEN6_TD_SF_EMSK                       0x8014
+#define GEN6_TD_WIZ_EMSK                      0x8018
+#define GEN6_TD_0_6_EHTRG_VAL         0x801c
+#define GEN6_TD_0_7_EHTRG_VAL         0x8020
+#define GEN6_TD_0_6_EHTRG_MSK           0x8024
+#define GEN6_TD_0_7_EHTRG_MSK         0x8028
+#define GEN6_TD_RDATA                 0x802c
+#define GEN6_TD_TS_EMSK                       0x8030
+
+#define GEN6_EU_CTL                   0x8800
+#define GEN6_EU_CTL_SELECT_SHIFT              16
+#define GEN6_EU_CTL_DATA_MUX_SHIFT      8
+#define GEN6_EU_ATT_0                 0x8810
+#define GEN6_EU_ATT_1                 0x8814
+#define GEN6_EU_ATT_DATA_0            0x8820
+#define GEN6_EU_ATT_DATA_1            0x8824
+#define GEN6_EU_ATT_CLR_0             0x8830
+#define GEN6_EU_ATT_CLR_1             0x8834
+#define GEN6_EU_RDATA                 0x8840
+
+/* 3D state:
+ */
+#define _3DOP_3DSTATE_PIPELINED       0x0
+#define _3DOP_3DSTATE_NONPIPELINED    0x1
+#define _3DOP_3DCONTROL               0x2
+#define _3DOP_3DPRIMITIVE             0x3
+
+#define _3DSTATE_PIPELINED_POINTERS       0x00
+#define _3DSTATE_BINDING_TABLE_POINTERS   0x01
+#define _3DSTATE_VERTEX_BUFFERS           0x08
+#define _3DSTATE_VERTEX_ELEMENTS          0x09
+#define _3DSTATE_INDEX_BUFFER             0x0A
+#define _3DSTATE_VF_STATISTICS            0x0B
+#define _3DSTATE_DRAWING_RECTANGLE            0x00
+#define _3DSTATE_CONSTANT_COLOR               0x01
+#define _3DSTATE_SAMPLER_PALETTE_LOAD         0x02
+#define _3DSTATE_CHROMA_KEY                   0x04
+#define _3DSTATE_DEPTH_BUFFER                 0x05
+#define _3DSTATE_POLY_STIPPLE_OFFSET          0x06
+#define _3DSTATE_POLY_STIPPLE_PATTERN         0x07
+#define _3DSTATE_LINE_STIPPLE                 0x08
+#define _3DSTATE_GLOBAL_DEPTH_OFFSET_CLAMP    0x09
+#define _3DCONTROL    0x00
+#define _3DPRIMITIVE  0x00
+
+#define _3DPRIM_POINTLIST         0x01
+#define _3DPRIM_LINELIST          0x02
+#define _3DPRIM_LINESTRIP         0x03
+#define _3DPRIM_TRILIST           0x04
+#define _3DPRIM_TRISTRIP          0x05
+#define _3DPRIM_TRIFAN            0x06
+#define _3DPRIM_QUADLIST          0x07
+#define _3DPRIM_QUADSTRIP         0x08
+#define _3DPRIM_LINELIST_ADJ      0x09
+#define _3DPRIM_LINESTRIP_ADJ     0x0A
+#define _3DPRIM_TRILIST_ADJ       0x0B
+#define _3DPRIM_TRISTRIP_ADJ      0x0C
+#define _3DPRIM_TRISTRIP_REVERSE  0x0D
+#define _3DPRIM_POLYGON           0x0E
+#define _3DPRIM_RECTLIST          0x0F
+#define _3DPRIM_LINELOOP          0x10
+#define _3DPRIM_POINTLIST_BF      0x11
+#define _3DPRIM_LINESTRIP_CONT    0x12
+#define _3DPRIM_LINESTRIP_BF      0x13
+#define _3DPRIM_LINESTRIP_CONT_BF 0x14
+#define _3DPRIM_TRIFAN_NOSTIPPLE  0x15
+
+#define _3DPRIM_VERTEXBUFFER_ACCESS_SEQUENTIAL 0
+#define _3DPRIM_VERTEXBUFFER_ACCESS_RANDOM     1
+
+#define GEN6_ANISORATIO_2     0 
+#define GEN6_ANISORATIO_4     1 
+#define GEN6_ANISORATIO_6     2 
+#define GEN6_ANISORATIO_8     3 
+#define GEN6_ANISORATIO_10    4 
+#define GEN6_ANISORATIO_12    5 
+#define GEN6_ANISORATIO_14    6 
+#define GEN6_ANISORATIO_16    7
+
+#define GEN6_BLENDFACTOR_ONE                 0x1
+#define GEN6_BLENDFACTOR_SRC_COLOR           0x2
+#define GEN6_BLENDFACTOR_SRC_ALPHA           0x3
+#define GEN6_BLENDFACTOR_DST_ALPHA           0x4
+#define GEN6_BLENDFACTOR_DST_COLOR           0x5
+#define GEN6_BLENDFACTOR_SRC_ALPHA_SATURATE  0x6
+#define GEN6_BLENDFACTOR_CONST_COLOR         0x7
+#define GEN6_BLENDFACTOR_CONST_ALPHA         0x8
+#define GEN6_BLENDFACTOR_SRC1_COLOR          0x9
+#define GEN6_BLENDFACTOR_SRC1_ALPHA          0x0A
+#define GEN6_BLENDFACTOR_ZERO                0x11
+#define GEN6_BLENDFACTOR_INV_SRC_COLOR       0x12
+#define GEN6_BLENDFACTOR_INV_SRC_ALPHA       0x13
+#define GEN6_BLENDFACTOR_INV_DST_ALPHA       0x14
+#define GEN6_BLENDFACTOR_INV_DST_COLOR       0x15
+#define GEN6_BLENDFACTOR_INV_CONST_COLOR     0x17
+#define GEN6_BLENDFACTOR_INV_CONST_ALPHA     0x18
+#define GEN6_BLENDFACTOR_INV_SRC1_COLOR      0x19
+#define GEN6_BLENDFACTOR_INV_SRC1_ALPHA      0x1A
+
+#define GEN6_BLENDFUNCTION_ADD               0
+#define GEN6_BLENDFUNCTION_SUBTRACT          1
+#define GEN6_BLENDFUNCTION_REVERSE_SUBTRACT  2
+#define GEN6_BLENDFUNCTION_MIN               3
+#define GEN6_BLENDFUNCTION_MAX               4
+
+#define GEN6_ALPHATEST_FORMAT_UNORM8         0
+#define GEN6_ALPHATEST_FORMAT_FLOAT32        1
+
+#define GEN6_CHROMAKEY_KILL_ON_ANY_MATCH  0
+#define GEN6_CHROMAKEY_REPLACE_BLACK      1
+
+#define GEN6_CLIP_API_OGL     0
+#define GEN6_CLIP_API_DX      1
+
+#define GEN6_CLIPMODE_NORMAL              0
+#define GEN6_CLIPMODE_CLIP_ALL            1
+#define GEN6_CLIPMODE_CLIP_NON_REJECTED   2
+#define GEN6_CLIPMODE_REJECT_ALL          3
+#define GEN6_CLIPMODE_ACCEPT_ALL          4
+
+#define GEN6_CLIP_NDCSPACE     0
+#define GEN6_CLIP_SCREENSPACE  1
+
+#define GEN6_COMPAREFUNCTION_ALWAYS       0
+#define GEN6_COMPAREFUNCTION_NEVER        1
+#define GEN6_COMPAREFUNCTION_LESS         2
+#define GEN6_COMPAREFUNCTION_EQUAL        3
+#define GEN6_COMPAREFUNCTION_LEQUAL       4
+#define GEN6_COMPAREFUNCTION_GREATER      5
+#define GEN6_COMPAREFUNCTION_NOTEQUAL     6
+#define GEN6_COMPAREFUNCTION_GEQUAL       7
+
+#define GEN6_COVERAGE_PIXELS_HALF     0
+#define GEN6_COVERAGE_PIXELS_1        1
+#define GEN6_COVERAGE_PIXELS_2        2
+#define GEN6_COVERAGE_PIXELS_4        3
+
+#define GEN6_CULLMODE_BOTH        0
+#define GEN6_CULLMODE_NONE        1
+#define GEN6_CULLMODE_FRONT       2
+#define GEN6_CULLMODE_BACK        3
+
+#define GEN6_DEFAULTCOLOR_R8G8B8A8_UNORM      0
+#define GEN6_DEFAULTCOLOR_R32G32B32A32_FLOAT  1
+
+#define GEN6_DEPTHFORMAT_D32_FLOAT_S8X24_UINT     0
+#define GEN6_DEPTHFORMAT_D32_FLOAT                1
+#define GEN6_DEPTHFORMAT_D24_UNORM_S8_UINT        2
+#define GEN6_DEPTHFORMAT_D16_UNORM                5
+
+#define GEN6_FLOATING_POINT_IEEE_754        0
+#define GEN6_FLOATING_POINT_NON_IEEE_754    1
+
+#define GEN6_FRONTWINDING_CW      0
+#define GEN6_FRONTWINDING_CCW     1
+
+#define GEN6_INDEX_BYTE     0
+#define GEN6_INDEX_WORD     1
+#define GEN6_INDEX_DWORD    2
+
+#define GEN6_LOGICOPFUNCTION_CLEAR            0
+#define GEN6_LOGICOPFUNCTION_NOR              1
+#define GEN6_LOGICOPFUNCTION_AND_INVERTED     2
+#define GEN6_LOGICOPFUNCTION_COPY_INVERTED    3
+#define GEN6_LOGICOPFUNCTION_AND_REVERSE      4
+#define GEN6_LOGICOPFUNCTION_INVERT           5
+#define GEN6_LOGICOPFUNCTION_XOR              6
+#define GEN6_LOGICOPFUNCTION_NAND             7
+#define GEN6_LOGICOPFUNCTION_AND              8
+#define GEN6_LOGICOPFUNCTION_EQUIV            9
+#define GEN6_LOGICOPFUNCTION_NOOP             10
+#define GEN6_LOGICOPFUNCTION_OR_INVERTED      11
+#define GEN6_LOGICOPFUNCTION_COPY             12
+#define GEN6_LOGICOPFUNCTION_OR_REVERSE       13
+#define GEN6_LOGICOPFUNCTION_OR               14
+#define GEN6_LOGICOPFUNCTION_SET              15  
+
+#define GEN6_MAPFILTER_NEAREST        0x0 
+#define GEN6_MAPFILTER_LINEAR         0x1 
+#define GEN6_MAPFILTER_ANISOTROPIC    0x2
+
+#define GEN6_MIPFILTER_NONE        0   
+#define GEN6_MIPFILTER_NEAREST     1   
+#define GEN6_MIPFILTER_LINEAR      3
+
+#define GEN6_POLYGON_FRONT_FACING     0
+#define GEN6_POLYGON_BACK_FACING      1
+
+#define GEN6_PREFILTER_ALWAYS     0x0 
+#define GEN6_PREFILTER_NEVER      0x1
+#define GEN6_PREFILTER_LESS       0x2
+#define GEN6_PREFILTER_EQUAL      0x3
+#define GEN6_PREFILTER_LEQUAL     0x4
+#define GEN6_PREFILTER_GREATER    0x5
+#define GEN6_PREFILTER_NOTEQUAL   0x6
+#define GEN6_PREFILTER_GEQUAL     0x7
+
+#define GEN6_PROVOKING_VERTEX_0    0
+#define GEN6_PROVOKING_VERTEX_1    1 
+#define GEN6_PROVOKING_VERTEX_2    2
+
+#define GEN6_RASTRULE_UPPER_LEFT  0    
+#define GEN6_RASTRULE_UPPER_RIGHT 1
+
+#define GEN6_RENDERTARGET_CLAMPRANGE_UNORM    0
+#define GEN6_RENDERTARGET_CLAMPRANGE_SNORM    1
+#define GEN6_RENDERTARGET_CLAMPRANGE_FORMAT   2
+
+#define GEN6_STENCILOP_KEEP               0
+#define GEN6_STENCILOP_ZERO               1
+#define GEN6_STENCILOP_REPLACE            2
+#define GEN6_STENCILOP_INCRSAT            3
+#define GEN6_STENCILOP_DECRSAT            4
+#define GEN6_STENCILOP_INCR               5
+#define GEN6_STENCILOP_DECR               6
+#define GEN6_STENCILOP_INVERT             7
+
+#define GEN6_SURFACE_MIPMAPLAYOUT_BELOW   0
+#define GEN6_SURFACE_MIPMAPLAYOUT_RIGHT   1
+
+#define GEN6_SURFACEFORMAT_R32G32B32A32_FLOAT             0x000
+#define GEN6_SURFACEFORMAT_R32G32B32A32_SINT              0x001
+#define GEN6_SURFACEFORMAT_R32G32B32A32_UINT              0x002
+#define GEN6_SURFACEFORMAT_R32G32B32A32_UNORM             0x003
+#define GEN6_SURFACEFORMAT_R32G32B32A32_SNORM             0x004
+#define GEN6_SURFACEFORMAT_R64G64_FLOAT                   0x005
+#define GEN6_SURFACEFORMAT_R32G32B32X32_FLOAT             0x006
+#define GEN6_SURFACEFORMAT_R32G32B32A32_SSCALED           0x007
+#define GEN6_SURFACEFORMAT_R32G32B32A32_USCALED           0x008
+#define GEN6_SURFACEFORMAT_R32G32B32_FLOAT                0x040
+#define GEN6_SURFACEFORMAT_R32G32B32_SINT                 0x041
+#define GEN6_SURFACEFORMAT_R32G32B32_UINT                 0x042
+#define GEN6_SURFACEFORMAT_R32G32B32_UNORM                0x043
+#define GEN6_SURFACEFORMAT_R32G32B32_SNORM                0x044
+#define GEN6_SURFACEFORMAT_R32G32B32_SSCALED              0x045
+#define GEN6_SURFACEFORMAT_R32G32B32_USCALED              0x046
+#define GEN6_SURFACEFORMAT_R16G16B16A16_UNORM             0x080
+#define GEN6_SURFACEFORMAT_R16G16B16A16_SNORM             0x081
+#define GEN6_SURFACEFORMAT_R16G16B16A16_SINT              0x082
+#define GEN6_SURFACEFORMAT_R16G16B16A16_UINT              0x083
+#define GEN6_SURFACEFORMAT_R16G16B16A16_FLOAT             0x084
+#define GEN6_SURFACEFORMAT_R32G32_FLOAT                   0x085
+#define GEN6_SURFACEFORMAT_R32G32_SINT                    0x086
+#define GEN6_SURFACEFORMAT_R32G32_UINT                    0x087
+#define GEN6_SURFACEFORMAT_R32_FLOAT_X8X24_TYPELESS       0x088
+#define GEN6_SURFACEFORMAT_X32_TYPELESS_G8X24_UINT        0x089
+#define GEN6_SURFACEFORMAT_L32A32_FLOAT                   0x08A
+#define GEN6_SURFACEFORMAT_R32G32_UNORM                   0x08B
+#define GEN6_SURFACEFORMAT_R32G32_SNORM                   0x08C
+#define GEN6_SURFACEFORMAT_R64_FLOAT                      0x08D
+#define GEN6_SURFACEFORMAT_R16G16B16X16_UNORM             0x08E
+#define GEN6_SURFACEFORMAT_R16G16B16X16_FLOAT             0x08F
+#define GEN6_SURFACEFORMAT_A32X32_FLOAT                   0x090
+#define GEN6_SURFACEFORMAT_L32X32_FLOAT                   0x091
+#define GEN6_SURFACEFORMAT_I32X32_FLOAT                   0x092
+#define GEN6_SURFACEFORMAT_R16G16B16A16_SSCALED           0x093
+#define GEN6_SURFACEFORMAT_R16G16B16A16_USCALED           0x094
+#define GEN6_SURFACEFORMAT_R32G32_SSCALED                 0x095
+#define GEN6_SURFACEFORMAT_R32G32_USCALED                 0x096
+#define GEN6_SURFACEFORMAT_B8G8R8A8_UNORM                 0x0C0
+#define GEN6_SURFACEFORMAT_B8G8R8A8_UNORM_SRGB            0x0C1
+#define GEN6_SURFACEFORMAT_R10G10B10A2_UNORM              0x0C2
+#define GEN6_SURFACEFORMAT_R10G10B10A2_UNORM_SRGB         0x0C3
+#define GEN6_SURFACEFORMAT_R10G10B10A2_UINT               0x0C4
+#define GEN6_SURFACEFORMAT_R10G10B10_SNORM_A2_UNORM       0x0C5
+#define GEN6_SURFACEFORMAT_R8G8B8A8_UNORM                 0x0C7
+#define GEN6_SURFACEFORMAT_R8G8B8A8_UNORM_SRGB            0x0C8
+#define GEN6_SURFACEFORMAT_R8G8B8A8_SNORM                 0x0C9
+#define GEN6_SURFACEFORMAT_R8G8B8A8_SINT                  0x0CA
+#define GEN6_SURFACEFORMAT_R8G8B8A8_UINT                  0x0CB
+#define GEN6_SURFACEFORMAT_R16G16_UNORM                   0x0CC
+#define GEN6_SURFACEFORMAT_R16G16_SNORM                   0x0CD
+#define GEN6_SURFACEFORMAT_R16G16_SINT                    0x0CE
+#define GEN6_SURFACEFORMAT_R16G16_UINT                    0x0CF
+#define GEN6_SURFACEFORMAT_R16G16_FLOAT                   0x0D0
+#define GEN6_SURFACEFORMAT_B10G10R10A2_UNORM              0x0D1
+#define GEN6_SURFACEFORMAT_B10G10R10A2_UNORM_SRGB         0x0D2
+#define GEN6_SURFACEFORMAT_R11G11B10_FLOAT                0x0D3
+#define GEN6_SURFACEFORMAT_R32_SINT                       0x0D6
+#define GEN6_SURFACEFORMAT_R32_UINT                       0x0D7
+#define GEN6_SURFACEFORMAT_R32_FLOAT                      0x0D8
+#define GEN6_SURFACEFORMAT_R24_UNORM_X8_TYPELESS          0x0D9
+#define GEN6_SURFACEFORMAT_X24_TYPELESS_G8_UINT           0x0DA
+#define GEN6_SURFACEFORMAT_L16A16_UNORM                   0x0DF
+#define GEN6_SURFACEFORMAT_I24X8_UNORM                    0x0E0
+#define GEN6_SURFACEFORMAT_L24X8_UNORM                    0x0E1
+#define GEN6_SURFACEFORMAT_A24X8_UNORM                    0x0E2
+#define GEN6_SURFACEFORMAT_I32_FLOAT                      0x0E3
+#define GEN6_SURFACEFORMAT_L32_FLOAT                      0x0E4
+#define GEN6_SURFACEFORMAT_A32_FLOAT                      0x0E5
+#define GEN6_SURFACEFORMAT_B8G8R8X8_UNORM                 0x0E9
+#define GEN6_SURFACEFORMAT_B8G8R8X8_UNORM_SRGB            0x0EA
+#define GEN6_SURFACEFORMAT_R8G8B8X8_UNORM                 0x0EB
+#define GEN6_SURFACEFORMAT_R8G8B8X8_UNORM_SRGB            0x0EC
+#define GEN6_SURFACEFORMAT_R9G9B9E5_SHAREDEXP             0x0ED
+#define GEN6_SURFACEFORMAT_B10G10R10X2_UNORM              0x0EE
+#define GEN6_SURFACEFORMAT_L16A16_FLOAT                   0x0F0
+#define GEN6_SURFACEFORMAT_R32_UNORM                      0x0F1
+#define GEN6_SURFACEFORMAT_R32_SNORM                      0x0F2
+#define GEN6_SURFACEFORMAT_R10G10B10X2_USCALED            0x0F3
+#define GEN6_SURFACEFORMAT_R8G8B8A8_SSCALED               0x0F4
+#define GEN6_SURFACEFORMAT_R8G8B8A8_USCALED               0x0F5
+#define GEN6_SURFACEFORMAT_R16G16_SSCALED                 0x0F6
+#define GEN6_SURFACEFORMAT_R16G16_USCALED                 0x0F7
+#define GEN6_SURFACEFORMAT_R32_SSCALED                    0x0F8
+#define GEN6_SURFACEFORMAT_R32_USCALED                    0x0F9
+#define GEN6_SURFACEFORMAT_B5G6R5_UNORM                   0x100
+#define GEN6_SURFACEFORMAT_B5G6R5_UNORM_SRGB              0x101
+#define GEN6_SURFACEFORMAT_B5G5R5A1_UNORM                 0x102
+#define GEN6_SURFACEFORMAT_B5G5R5A1_UNORM_SRGB            0x103
+#define GEN6_SURFACEFORMAT_B4G4R4A4_UNORM                 0x104
+#define GEN6_SURFACEFORMAT_B4G4R4A4_UNORM_SRGB            0x105
+#define GEN6_SURFACEFORMAT_R8G8_UNORM                     0x106
+#define GEN6_SURFACEFORMAT_R8G8_SNORM                     0x107
+#define GEN6_SURFACEFORMAT_R8G8_SINT                      0x108
+#define GEN6_SURFACEFORMAT_R8G8_UINT                      0x109
+#define GEN6_SURFACEFORMAT_R16_UNORM                      0x10A
+#define GEN6_SURFACEFORMAT_R16_SNORM                      0x10B
+#define GEN6_SURFACEFORMAT_R16_SINT                       0x10C
+#define GEN6_SURFACEFORMAT_R16_UINT                       0x10D
+#define GEN6_SURFACEFORMAT_R16_FLOAT                      0x10E
+#define GEN6_SURFACEFORMAT_I16_UNORM                      0x111
+#define GEN6_SURFACEFORMAT_L16_UNORM                      0x112
+#define GEN6_SURFACEFORMAT_A16_UNORM                      0x113
+#define GEN6_SURFACEFORMAT_L8A8_UNORM                     0x114
+#define GEN6_SURFACEFORMAT_I16_FLOAT                      0x115
+#define GEN6_SURFACEFORMAT_L16_FLOAT                      0x116
+#define GEN6_SURFACEFORMAT_A16_FLOAT                      0x117
+#define GEN6_SURFACEFORMAT_R5G5_SNORM_B6_UNORM            0x119
+#define GEN6_SURFACEFORMAT_B5G5R5X1_UNORM                 0x11A
+#define GEN6_SURFACEFORMAT_B5G5R5X1_UNORM_SRGB            0x11B
+#define GEN6_SURFACEFORMAT_R8G8_SSCALED                   0x11C
+#define GEN6_SURFACEFORMAT_R8G8_USCALED                   0x11D
+#define GEN6_SURFACEFORMAT_R16_SSCALED                    0x11E
+#define GEN6_SURFACEFORMAT_R16_USCALED                    0x11F
+#define GEN6_SURFACEFORMAT_R8_UNORM                       0x140
+#define GEN6_SURFACEFORMAT_R8_SNORM                       0x141
+#define GEN6_SURFACEFORMAT_R8_SINT                        0x142
+#define GEN6_SURFACEFORMAT_R8_UINT                        0x143
+#define GEN6_SURFACEFORMAT_A8_UNORM                       0x144
+#define GEN6_SURFACEFORMAT_I8_UNORM                       0x145
+#define GEN6_SURFACEFORMAT_L8_UNORM                       0x146
+#define GEN6_SURFACEFORMAT_P4A4_UNORM                     0x147
+#define GEN6_SURFACEFORMAT_A4P4_UNORM                     0x148
+#define GEN6_SURFACEFORMAT_R8_SSCALED                     0x149
+#define GEN6_SURFACEFORMAT_R8_USCALED                     0x14A
+#define GEN6_SURFACEFORMAT_R1_UINT                        0x181
+#define GEN6_SURFACEFORMAT_YCRCB_NORMAL                   0x182
+#define GEN6_SURFACEFORMAT_YCRCB_SWAPUVY                  0x183
+#define GEN6_SURFACEFORMAT_BC1_UNORM                      0x186
+#define GEN6_SURFACEFORMAT_BC2_UNORM                      0x187
+#define GEN6_SURFACEFORMAT_BC3_UNORM                      0x188
+#define GEN6_SURFACEFORMAT_BC4_UNORM                      0x189
+#define GEN6_SURFACEFORMAT_BC5_UNORM                      0x18A
+#define GEN6_SURFACEFORMAT_BC1_UNORM_SRGB                 0x18B
+#define GEN6_SURFACEFORMAT_BC2_UNORM_SRGB                 0x18C
+#define GEN6_SURFACEFORMAT_BC3_UNORM_SRGB                 0x18D
+#define GEN6_SURFACEFORMAT_MONO8                          0x18E
+#define GEN6_SURFACEFORMAT_YCRCB_SWAPUV                   0x18F
+#define GEN6_SURFACEFORMAT_YCRCB_SWAPY                    0x190
+#define GEN6_SURFACEFORMAT_DXT1_RGB                       0x191
+#define GEN6_SURFACEFORMAT_FXT1                           0x192
+#define GEN6_SURFACEFORMAT_R8G8B8_UNORM                   0x193
+#define GEN6_SURFACEFORMAT_R8G8B8_SNORM                   0x194
+#define GEN6_SURFACEFORMAT_R8G8B8_SSCALED                 0x195
+#define GEN6_SURFACEFORMAT_R8G8B8_USCALED                 0x196
+#define GEN6_SURFACEFORMAT_R64G64B64A64_FLOAT             0x197
+#define GEN6_SURFACEFORMAT_R64G64B64_FLOAT                0x198
+#define GEN6_SURFACEFORMAT_BC4_SNORM                      0x199
+#define GEN6_SURFACEFORMAT_BC5_SNORM                      0x19A
+#define GEN6_SURFACEFORMAT_R16G16B16_UNORM                0x19C
+#define GEN6_SURFACEFORMAT_R16G16B16_SNORM                0x19D
+#define GEN6_SURFACEFORMAT_R16G16B16_SSCALED              0x19E
+#define GEN6_SURFACEFORMAT_R16G16B16_USCALED              0x19F
+
+#define GEN6_SURFACERETURNFORMAT_FLOAT32  0
+#define GEN6_SURFACERETURNFORMAT_S1       1
+
+#define GEN6_SURFACE_1D      0
+#define GEN6_SURFACE_2D      1
+#define GEN6_SURFACE_3D      2
+#define GEN6_SURFACE_CUBE    3
+#define GEN6_SURFACE_BUFFER  4
+#define GEN6_SURFACE_NULL    7
+
+#define GEN6_BORDER_COLOR_MODE_DEFAULT 0
+#define GEN6_BORDER_COLOR_MODE_LEGACY  1
+
+#define GEN6_TEXCOORDMODE_WRAP            0
+#define GEN6_TEXCOORDMODE_MIRROR          1
+#define GEN6_TEXCOORDMODE_CLAMP           2
+#define GEN6_TEXCOORDMODE_CUBE            3
+#define GEN6_TEXCOORDMODE_CLAMP_BORDER    4
+#define GEN6_TEXCOORDMODE_MIRROR_ONCE     5
+
+#define GEN6_THREAD_PRIORITY_NORMAL   0
+#define GEN6_THREAD_PRIORITY_HIGH     1
+
+#define GEN6_TILEWALK_XMAJOR                 0
+#define GEN6_TILEWALK_YMAJOR                 1
+
+#define GEN6_VERTEX_SUBPIXEL_PRECISION_8BITS  0
+#define GEN6_VERTEX_SUBPIXEL_PRECISION_4BITS  1
+
+#define GEN6_VERTEXBUFFER_ACCESS_VERTEXDATA     0
+#define GEN6_VERTEXBUFFER_ACCESS_INSTANCEDATA   1
+
+#define GEN6_VFCOMPONENT_NOSTORE      0
+#define GEN6_VFCOMPONENT_STORE_SRC    1
+#define GEN6_VFCOMPONENT_STORE_0      2
+#define GEN6_VFCOMPONENT_STORE_1_FLT  3
+#define GEN6_VFCOMPONENT_STORE_1_INT  4
+#define GEN6_VFCOMPONENT_STORE_VID    5
+#define GEN6_VFCOMPONENT_STORE_IID    6
+#define GEN6_VFCOMPONENT_STORE_PID    7
+
+
+
+/* Execution Unit (EU) defines
+ */
+
+#define GEN6_ALIGN_1   0
+#define GEN6_ALIGN_16  1
+
+#define GEN6_ADDRESS_DIRECT                        0
+#define GEN6_ADDRESS_REGISTER_INDIRECT_REGISTER    1
+
+#define GEN6_CHANNEL_X     0
+#define GEN6_CHANNEL_Y     1
+#define GEN6_CHANNEL_Z     2
+#define GEN6_CHANNEL_W     3
+
+#define GEN6_COMPRESSION_NONE          0
+#define GEN6_COMPRESSION_2NDHALF       1
+#define GEN6_COMPRESSION_COMPRESSED    2
+
+#define GEN6_CONDITIONAL_NONE  0
+#define GEN6_CONDITIONAL_Z     1
+#define GEN6_CONDITIONAL_NZ    2
+#define GEN6_CONDITIONAL_EQ    1       /* Z */
+#define GEN6_CONDITIONAL_NEQ   2       /* NZ */
+#define GEN6_CONDITIONAL_G     3
+#define GEN6_CONDITIONAL_GE    4
+#define GEN6_CONDITIONAL_L     5
+#define GEN6_CONDITIONAL_LE    6
+#define GEN6_CONDITIONAL_C     7
+#define GEN6_CONDITIONAL_O     8
+
+#define GEN6_DEBUG_NONE        0
+#define GEN6_DEBUG_BREAKPOINT  1
+
+#define GEN6_DEPENDENCY_NORMAL         0
+#define GEN6_DEPENDENCY_NOTCLEARED     1
+#define GEN6_DEPENDENCY_NOTCHECKED     2
+#define GEN6_DEPENDENCY_DISABLE        3
+
+#define GEN6_EXECUTE_1     0
+#define GEN6_EXECUTE_2     1
+#define GEN6_EXECUTE_4     2
+#define GEN6_EXECUTE_8     3
+#define GEN6_EXECUTE_16    4
+#define GEN6_EXECUTE_32    5
+
+#define GEN6_HORIZONTAL_STRIDE_0   0
+#define GEN6_HORIZONTAL_STRIDE_1   1
+#define GEN6_HORIZONTAL_STRIDE_2   2
+#define GEN6_HORIZONTAL_STRIDE_4   3
+
+#define GEN6_INSTRUCTION_NORMAL    0
+#define GEN6_INSTRUCTION_SATURATE  1
+
+#define GEN6_MASK_ENABLE   0
+#define GEN6_MASK_DISABLE  1
+
+#define GEN6_OPCODE_MOV        1
+#define GEN6_OPCODE_SEL        2
+#define GEN6_OPCODE_NOT        4
+#define GEN6_OPCODE_AND        5
+#define GEN6_OPCODE_OR         6
+#define GEN6_OPCODE_XOR        7
+#define GEN6_OPCODE_SHR        8
+#define GEN6_OPCODE_SHL        9
+#define GEN6_OPCODE_RSR        10
+#define GEN6_OPCODE_RSL        11
+#define GEN6_OPCODE_ASR        12
+#define GEN6_OPCODE_CMP        16
+#define GEN6_OPCODE_JMPI       32
+#define GEN6_OPCODE_IF         34
+#define GEN6_OPCODE_IFF        35
+#define GEN6_OPCODE_ELSE       36
+#define GEN6_OPCODE_ENDIF      37
+#define GEN6_OPCODE_DO         38
+#define GEN6_OPCODE_WHILE      39
+#define GEN6_OPCODE_BREAK      40
+#define GEN6_OPCODE_CONTINUE   41
+#define GEN6_OPCODE_HALT       42
+#define GEN6_OPCODE_MSAVE      44
+#define GEN6_OPCODE_MRESTORE   45
+#define GEN6_OPCODE_PUSH       46
+#define GEN6_OPCODE_POP        47
+#define GEN6_OPCODE_WAIT       48
+#define GEN6_OPCODE_SEND       49
+#define GEN6_OPCODE_ADD        64
+#define GEN6_OPCODE_MUL        65
+#define GEN6_OPCODE_AVG        66
+#define GEN6_OPCODE_FRC        67
+#define GEN6_OPCODE_RNDU       68
+#define GEN6_OPCODE_RNDD       69
+#define GEN6_OPCODE_RNDE       70
+#define GEN6_OPCODE_RNDZ       71
+#define GEN6_OPCODE_MAC        72
+#define GEN6_OPCODE_MACH       73
+#define GEN6_OPCODE_LZD        74
+#define GEN6_OPCODE_SAD2       80
+#define GEN6_OPCODE_SADA2      81
+#define GEN6_OPCODE_DP4        84
+#define GEN6_OPCODE_DPH        85
+#define GEN6_OPCODE_DP3        86
+#define GEN6_OPCODE_DP2        87
+#define GEN6_OPCODE_DPA2       88
+#define GEN6_OPCODE_LINE       89
+#define GEN6_OPCODE_NOP        126
+
+#define GEN6_PREDICATE_NONE             0
+#define GEN6_PREDICATE_NORMAL           1
+#define GEN6_PREDICATE_ALIGN1_ANYV             2
+#define GEN6_PREDICATE_ALIGN1_ALLV             3
+#define GEN6_PREDICATE_ALIGN1_ANY2H            4
+#define GEN6_PREDICATE_ALIGN1_ALL2H            5
+#define GEN6_PREDICATE_ALIGN1_ANY4H            6
+#define GEN6_PREDICATE_ALIGN1_ALL4H            7
+#define GEN6_PREDICATE_ALIGN1_ANY8H            8
+#define GEN6_PREDICATE_ALIGN1_ALL8H            9
+#define GEN6_PREDICATE_ALIGN1_ANY16H           10
+#define GEN6_PREDICATE_ALIGN1_ALL16H           11
+#define GEN6_PREDICATE_ALIGN16_REPLICATE_X     2
+#define GEN6_PREDICATE_ALIGN16_REPLICATE_Y     3
+#define GEN6_PREDICATE_ALIGN16_REPLICATE_Z     4
+#define GEN6_PREDICATE_ALIGN16_REPLICATE_W     5
+#define GEN6_PREDICATE_ALIGN16_ANY4H           6
+#define GEN6_PREDICATE_ALIGN16_ALL4H           7
+
+#define GEN6_ARCHITECTURE_REGISTER_FILE    0
+#define GEN6_GENERAL_REGISTER_FILE         1
+#define GEN6_MESSAGE_REGISTER_FILE         2
+#define GEN6_IMMEDIATE_VALUE               3
+
+#define GEN6_REGISTER_TYPE_UD  0
+#define GEN6_REGISTER_TYPE_D   1
+#define GEN6_REGISTER_TYPE_UW  2
+#define GEN6_REGISTER_TYPE_W   3
+#define GEN6_REGISTER_TYPE_UB  4
+#define GEN6_REGISTER_TYPE_B   5
+#define GEN6_REGISTER_TYPE_VF  5       /* packed float vector, immediates only? */
+#define GEN6_REGISTER_TYPE_HF  6
+#define GEN6_REGISTER_TYPE_V   6       /* packed int vector, immediates only, uword dest only */
+#define GEN6_REGISTER_TYPE_F   7
+
+#define GEN6_ARF_NULL                  0x00
+#define GEN6_ARF_ADDRESS               0x10
+#define GEN6_ARF_ACCUMULATOR           0x20   
+#define GEN6_ARF_FLAG                  0x30
+#define GEN6_ARF_MASK                  0x40
+#define GEN6_ARF_MASK_STACK            0x50
+#define GEN6_ARF_MASK_STACK_DEPTH      0x60
+#define GEN6_ARF_STATE                 0x70
+#define GEN6_ARF_CONTROL               0x80
+#define GEN6_ARF_NOTIFICATION_COUNT    0x90
+#define GEN6_ARF_IP                    0xA0
+
+#define GEN6_AMASK   0
+#define GEN6_IMASK   1
+#define GEN6_LMASK   2
+#define GEN6_CMASK   3
+
+
+
+#define GEN6_THREAD_NORMAL     0
+#define GEN6_THREAD_ATOMIC     1
+#define GEN6_THREAD_SWITCH     2
+
+#define GEN6_VERTICAL_STRIDE_0                 0
+#define GEN6_VERTICAL_STRIDE_1                 1
+#define GEN6_VERTICAL_STRIDE_2                 2
+#define GEN6_VERTICAL_STRIDE_4                 3
+#define GEN6_VERTICAL_STRIDE_8                 4
+#define GEN6_VERTICAL_STRIDE_16                5
+#define GEN6_VERTICAL_STRIDE_32                6
+#define GEN6_VERTICAL_STRIDE_64                7
+#define GEN6_VERTICAL_STRIDE_128               8
+#define GEN6_VERTICAL_STRIDE_256               9
+#define GEN6_VERTICAL_STRIDE_ONE_DIMENSIONAL   0xF
+
+#define GEN6_WIDTH_1       0
+#define GEN6_WIDTH_2       1
+#define GEN6_WIDTH_4       2
+#define GEN6_WIDTH_8       3
+#define GEN6_WIDTH_16      4
+
+#define GEN6_STATELESS_BUFFER_BOUNDARY_1K      0
+#define GEN6_STATELESS_BUFFER_BOUNDARY_2K      1
+#define GEN6_STATELESS_BUFFER_BOUNDARY_4K      2
+#define GEN6_STATELESS_BUFFER_BOUNDARY_8K      3
+#define GEN6_STATELESS_BUFFER_BOUNDARY_16K     4
+#define GEN6_STATELESS_BUFFER_BOUNDARY_32K     5
+#define GEN6_STATELESS_BUFFER_BOUNDARY_64K     6
+#define GEN6_STATELESS_BUFFER_BOUNDARY_128K    7
+#define GEN6_STATELESS_BUFFER_BOUNDARY_256K    8
+#define GEN6_STATELESS_BUFFER_BOUNDARY_512K    9
+#define GEN6_STATELESS_BUFFER_BOUNDARY_1M      10
+#define GEN6_STATELESS_BUFFER_BOUNDARY_2M      11
+
+#define GEN6_POLYGON_FACING_FRONT      0
+#define GEN6_POLYGON_FACING_BACK       1
+
+#define GEN6_MESSAGE_TARGET_NULL               0
+#define GEN6_MESSAGE_TARGET_MATH               1
+#define GEN6_MESSAGE_TARGET_SAMPLER            2
+#define GEN6_MESSAGE_TARGET_GATEWAY            3
+#define GEN6_MESSAGE_TARGET_DATAPORT_READ      4
+#define GEN6_MESSAGE_TARGET_DATAPORT_WRITE     5
+#define GEN6_MESSAGE_TARGET_URB                6
+#define GEN6_MESSAGE_TARGET_THREAD_SPAWNER     7
+
+#define GEN6_SAMPLER_RETURN_FORMAT_FLOAT32     0
+#define GEN6_SAMPLER_RETURN_FORMAT_UINT32      2
+#define GEN6_SAMPLER_RETURN_FORMAT_SINT32      3
+
+#define GEN6_SAMPLER_MESSAGE_SIMD8_SAMPLE              0
+#define GEN6_SAMPLER_MESSAGE_SIMD16_SAMPLE             0
+#define GEN6_SAMPLER_MESSAGE_SIMD16_SAMPLE_BIAS        0
+#define GEN6_SAMPLER_MESSAGE_SIMD8_KILLPIX             1
+#define GEN6_SAMPLER_MESSAGE_SIMD4X2_SAMPLE_LOD        1
+#define GEN6_SAMPLER_MESSAGE_SIMD16_SAMPLE_LOD         1
+#define GEN6_SAMPLER_MESSAGE_SIMD4X2_SAMPLE_GRADIENTS  2
+#define GEN6_SAMPLER_MESSAGE_SIMD8_SAMPLE_GRADIENTS    2
+#define GEN6_SAMPLER_MESSAGE_SIMD4X2_SAMPLE_COMPARE    0
+#define GEN6_SAMPLER_MESSAGE_SIMD16_SAMPLE_COMPARE     2
+#define GEN6_SAMPLER_MESSAGE_SIMD4X2_RESINFO           2
+#define GEN6_SAMPLER_MESSAGE_SIMD8_RESINFO             2
+#define GEN6_SAMPLER_MESSAGE_SIMD16_RESINFO            2
+#define GEN6_SAMPLER_MESSAGE_SIMD4X2_LD                3
+#define GEN6_SAMPLER_MESSAGE_SIMD8_LD                  3
+#define GEN6_SAMPLER_MESSAGE_SIMD16_LD                 3
+
+#define GEN6_DATAPORT_OWORD_BLOCK_1_OWORDLOW   0
+#define GEN6_DATAPORT_OWORD_BLOCK_1_OWORDHIGH  1
+#define GEN6_DATAPORT_OWORD_BLOCK_2_OWORDS     2
+#define GEN6_DATAPORT_OWORD_BLOCK_4_OWORDS     3
+#define GEN6_DATAPORT_OWORD_BLOCK_8_OWORDS     4
+
+#define GEN6_DATAPORT_OWORD_DUAL_BLOCK_1OWORD     0
+#define GEN6_DATAPORT_OWORD_DUAL_BLOCK_4OWORDS    2
+
+#define GEN6_DATAPORT_DWORD_SCATTERED_BLOCK_8DWORDS   2
+#define GEN6_DATAPORT_DWORD_SCATTERED_BLOCK_16DWORDS  3
+
+#define GEN6_DATAPORT_READ_TARGET_DATA_CACHE      0
+#define GEN6_DATAPORT_READ_TARGET_RENDER_CACHE    1
+#define GEN6_DATAPORT_READ_TARGET_SAMPLER_CACHE   2
+
+#define GEN6_DATAPORT_RENDER_TARGET_WRITE_SIMD16_SINGLE_SOURCE                0
+#define GEN6_DATAPORT_RENDER_TARGET_WRITE_SIMD16_SINGLE_SOURCE_REPLICATED     1
+#define GEN6_DATAPORT_RENDER_TARGET_WRITE_SIMD8_DUAL_SOURCE_SUBSPAN01         2
+#define GEN6_DATAPORT_RENDER_TARGET_WRITE_SIMD8_DUAL_SOURCE_SUBSPAN23         3
+#define GEN6_DATAPORT_RENDER_TARGET_WRITE_SIMD8_SINGLE_SOURCE_SUBSPAN01       4
+
+#define GEN6_MATH_INTEGER_UNSIGNED     0
+#define GEN6_MATH_INTEGER_SIGNED       1
+
+#define GEN6_MATH_PRECISION_FULL        0
+#define GEN6_MATH_PRECISION_PARTIAL     1
+
+#define GEN6_MATH_SATURATE_NONE         0
+#define GEN6_MATH_SATURATE_SATURATE     1
+
+#define GEN6_MATH_DATA_VECTOR  0
+#define GEN6_MATH_DATA_SCALAR  1
+
+#define GEN6_URB_OPCODE_WRITE  0
+
+#define GEN6_URB_SWIZZLE_NONE          0
+#define GEN6_URB_SWIZZLE_INTERLEAVE    1
+#define GEN6_URB_SWIZZLE_TRANSPOSE     2
+
+#define GEN6_SCRATCH_SPACE_SIZE_1K     0
+#define GEN6_SCRATCH_SPACE_SIZE_2K     1
+#define GEN6_SCRATCH_SPACE_SIZE_4K     2
+#define GEN6_SCRATCH_SPACE_SIZE_8K     3
+#define GEN6_SCRATCH_SPACE_SIZE_16K    4
+#define GEN6_SCRATCH_SPACE_SIZE_32K    5
+#define GEN6_SCRATCH_SPACE_SIZE_64K    6
+#define GEN6_SCRATCH_SPACE_SIZE_128K   7
+#define GEN6_SCRATCH_SPACE_SIZE_256K   8
+#define GEN6_SCRATCH_SPACE_SIZE_512K   9
+#define GEN6_SCRATCH_SPACE_SIZE_1M     10
+#define GEN6_SCRATCH_SPACE_SIZE_2M     11
+
+/* The hardware supports two different modes for border color. The
+ * default (OpenGL) mode uses floating-point color channels, while the
+ * legacy mode uses 4 bytes.
+ *
+ * More significantly, the legacy mode respects the components of the
+ * border color for channels not present in the source, (whereas the
+ * default mode will ignore the border color's alpha channel and use
+ * alpha==1 for an RGB source, for example).
+ *
+ * The legacy mode matches the semantics specified by the Render
+ * extension.
+ */
+struct gen6_sampler_default_border_color {
+   float color[4];
+};
+
+struct gen6_sampler_legacy_border_color {
+   uint8_t color[4];
+};
+
+struct gen6_sampler_state {
+   struct {
+      uint32_t shadow_function:3;
+      uint32_t lod_bias:11;
+      uint32_t min_filter:3;
+      uint32_t mag_filter:3;
+      uint32_t mip_filter:2;
+      uint32_t base_level:5;
+      uint32_t pad:1;
+      uint32_t lod_preclamp:1;
+      uint32_t border_color_mode:1;
+      uint32_t pad0:1;
+      uint32_t disable:1;
+   } ss0;
+
+   struct {
+      uint32_t r_wrap_mode:3;
+      uint32_t t_wrap_mode:3;
+      uint32_t s_wrap_mode:3;
+      uint32_t pad:3;
+      uint32_t max_lod:10;
+      uint32_t min_lod:10;
+   } ss1;
+
+   struct {
+      uint32_t border_color;
+   } ss2;
+
+   struct {
+      uint32_t non_normalized_coord:1;
+      uint32_t pad:12;
+      uint32_t address_round:6;
+      uint32_t max_aniso:3;
+      uint32_t chroma_key_mode:1;
+      uint32_t chroma_key_index:2;
+      uint32_t chroma_key_enable:1;
+      uint32_t monochrome_filter_width:3;
+      uint32_t monochrome_filter_height:3;
+   } ss3;
+};
+
+struct gen6_blend_state {
+       struct {
+               uint32_t dest_blend_factor:5;
+               uint32_t source_blend_factor:5;
+               uint32_t pad3:1;
+               uint32_t blend_func:3;
+               uint32_t pad2:1;
+               uint32_t ia_dest_blend_factor:5;
+               uint32_t ia_source_blend_factor:5;
+               uint32_t pad1:1;
+               uint32_t ia_blend_func:3;
+               uint32_t pad0:1;
+               uint32_t ia_blend_enable:1;
+               uint32_t blend_enable:1;
+       } blend0;
+
+       struct {
+               uint32_t post_blend_clamp_enable:1;
+               uint32_t pre_blend_clamp_enable:1;
+               uint32_t clamp_range:2;
+               uint32_t pad0:4;
+               uint32_t x_dither_offset:2;
+               uint32_t y_dither_offset:2;
+               uint32_t dither_enable:1;
+               uint32_t alpha_test_func:3;
+               uint32_t alpha_test_enable:1;
+               uint32_t pad1:1;
+               uint32_t logic_op_func:4;
+               uint32_t logic_op_enable:1;
+               uint32_t pad2:1;
+               uint32_t write_disable_b:1;
+               uint32_t write_disable_g:1;
+               uint32_t write_disable_r:1;
+               uint32_t write_disable_a:1;
+               uint32_t pad3:1;
+               uint32_t alpha_to_coverage_dither:1;
+               uint32_t alpha_to_one:1;
+               uint32_t alpha_to_coverage:1;
+       } blend1;
+};
+
+struct gen6_color_calc_state {
+       struct {
+               uint32_t alpha_test_format:1;
+               uint32_t pad0:14;
+               uint32_t round_disable:1;
+               uint32_t bf_stencil_ref:8;
+               uint32_t stencil_ref:8;
+       } cc0;
+
+       union {
+               float alpha_ref_f;
+               struct {
+                       uint32_t ui:8;
+                       uint32_t pad0:24;
+               } alpha_ref_fi;
+       } cc1;
+
+       float constant_r;
+       float constant_g;
+       float constant_b;
+       float constant_a;
+};
+
+struct gen6_depth_stencil_state {
+       struct {
+               uint32_t pad0:3;
+               uint32_t bf_stencil_pass_depth_pass_op:3;
+               uint32_t bf_stencil_pass_depth_fail_op:3;
+               uint32_t bf_stencil_fail_op:3;
+               uint32_t bf_stencil_func:3;
+               uint32_t bf_stencil_enable:1;
+               uint32_t pad1:2;
+               uint32_t stencil_write_enable:1;
+               uint32_t stencil_pass_depth_pass_op:3;
+               uint32_t stencil_pass_depth_fail_op:3;
+               uint32_t stencil_fail_op:3;
+               uint32_t stencil_func:3;
+               uint32_t stencil_enable:1;
+       } ds0;
+
+       struct {
+               uint32_t bf_stencil_write_mask:8;
+               uint32_t bf_stencil_test_mask:8;
+               uint32_t stencil_write_mask:8;
+               uint32_t stencil_test_mask:8;
+       } ds1;
+
+       struct {
+               uint32_t pad0:26;
+               uint32_t depth_write_enable:1;
+               uint32_t depth_test_func:3;
+               uint32_t pad1:1;
+               uint32_t depth_test_enable:1;
+       } ds2;
+};
+
+struct gen6_surface_state {
+       struct {
+               uint32_t cube_pos_z:1;
+               uint32_t cube_neg_z:1;
+               uint32_t cube_pos_y:1;
+               uint32_t cube_neg_y:1;
+               uint32_t cube_pos_x:1;
+               uint32_t cube_neg_x:1;
+               uint32_t pad:3;
+               uint32_t render_cache_read_mode:1;
+               uint32_t mipmap_layout_mode:1;
+               uint32_t vert_line_stride_ofs:1;
+               uint32_t vert_line_stride:1;
+               uint32_t color_blend:1;
+               uint32_t writedisable_blue:1;
+               uint32_t writedisable_green:1;
+               uint32_t writedisable_red:1;
+               uint32_t writedisable_alpha:1;
+               uint32_t surface_format:9;
+               uint32_t data_return_format:1;
+               uint32_t pad0:1;
+               uint32_t surface_type:3;
+       } ss0;
+
+       struct {
+               uint32_t base_addr;
+       } ss1;
+
+       struct {
+               uint32_t render_target_rotation:2;
+               uint32_t mip_count:4;
+               uint32_t width:13;
+               uint32_t height:13;
+       } ss2;
+
+       struct {
+               uint32_t tile_walk:1;
+               uint32_t tiled_surface:1;
+               uint32_t pad:1;
+               uint32_t pitch:18;
+               uint32_t depth:11;
+       } ss3;
+
+       struct {
+               uint32_t pad:19;
+               uint32_t min_array_elt:9;
+               uint32_t min_lod:4;
+       } ss4;
+
+       struct {
+               uint32_t pad:20;
+               uint32_t y_offset:4;
+               uint32_t pad2:1;
+               uint32_t x_offset:7;
+       } ss5;
+};
+
+/* Surface state DW0 */
+#define GEN6_SURFACE_RC_READ_WRITE       (1 << 8)
+#define GEN6_SURFACE_MIPLAYOUT_SHIFT     10
+#define GEN6_SURFACE_MIPMAPLAYOUT_BELOW   0
+#define GEN6_SURFACE_MIPMAPLAYOUT_RIGHT   1
+#define GEN6_SURFACE_CUBEFACE_ENABLES    0x3f
+#define GEN6_SURFACE_BLEND_ENABLED       (1 << 13)
+#define GEN6_SURFACE_WRITEDISABLE_B_SHIFT        14
+#define GEN6_SURFACE_WRITEDISABLE_G_SHIFT        15
+#define GEN6_SURFACE_WRITEDISABLE_R_SHIFT        16
+#define GEN6_SURFACE_WRITEDISABLE_A_SHIFT        17
+#define GEN6_SURFACE_FORMAT_SHIFT        18
+#define GEN6_SURFACE_FORMAT_MASK         INTEL_MASK(26, 18)
+
+#define GEN6_SURFACE_TYPE_SHIFT          29
+#define GEN6_SURFACE_TYPE_MASK           GEN6_MASK(31, 29)
+#define GEN6_SURFACE_1D      0
+#define GEN6_SURFACE_2D      1
+#define GEN6_SURFACE_3D      2
+#define GEN6_SURFACE_CUBE    3
+#define GEN6_SURFACE_BUFFER  4
+#define GEN6_SURFACE_NULL    7
+
+/* Surface state DW2 */
+#define GEN6_SURFACE_HEIGHT_SHIFT        19
+#define GEN6_SURFACE_HEIGHT_MASK         GEN6_MASK(31, 19)
+#define GEN6_SURFACE_WIDTH_SHIFT         6
+#define GEN6_SURFACE_WIDTH_MASK          GEN6_MASK(18, 6)
+#define GEN6_SURFACE_LOD_SHIFT           2
+#define GEN6_SURFACE_LOD_MASK            GEN6_MASK(5, 2)
+
+/* Surface state DW3 */
+#define GEN6_SURFACE_DEPTH_SHIFT         21
+#define GEN6_SURFACE_DEPTH_MASK          GEN6_MASK(31, 21)
+#define GEN6_SURFACE_PITCH_SHIFT         3
+#define GEN6_SURFACE_PITCH_MASK          GEN6_MASK(19, 3)
+#define GEN6_SURFACE_TILED               (1 << 1)
+#define GEN6_SURFACE_TILED_Y             (1 << 0)
+
+/* Surface state DW4 */
+#define GEN6_SURFACE_MIN_LOD_SHIFT       28
+#define GEN6_SURFACE_MIN_LOD_MASK        GEN6_MASK(31, 28)
+
+/* Surface state DW5 */
+#define GEN6_SURFACE_X_OFFSET_SHIFT      25
+#define GEN6_SURFACE_X_OFFSET_MASK       GEN6_MASK(31, 25)
+#define GEN6_SURFACE_Y_OFFSET_SHIFT      20
+#define GEN6_SURFACE_Y_OFFSET_MASK       GEN6_MASK(23, 20)
+
+struct gen6_cc_viewport {
+       float min_depth;
+       float max_depth;
+};
+
+typedef enum {
+       SAMPLER_FILTER_NEAREST = 0,
+       SAMPLER_FILTER_BILINEAR,
+       FILTER_COUNT
+} sampler_filter_t;
+
+typedef enum {
+       SAMPLER_EXTEND_NONE = 0,
+       SAMPLER_EXTEND_REPEAT,
+       SAMPLER_EXTEND_PAD,
+       SAMPLER_EXTEND_REFLECT,
+       EXTEND_COUNT
+} sampler_extend_t;
+
+#endif
diff --git a/src/sna/gen7_render.c b/src/sna/gen7_render.c
new file mode 100644 (file)
index 0000000..1f59eb3
--- /dev/null
@@ -0,0 +1,4383 @@
+/*
+ * Copyright © 2006,2008,2011 Intel Corporation
+ * Copyright © 2007 Red Hat, Inc.
+ *
+ * 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.
+ *
+ * Authors:
+ *    Wang Zhenyu <zhenyu.z.wang@sna.com>
+ *    Eric Anholt <eric@anholt.net>
+ *    Carl Worth <cworth@redhat.com>
+ *    Keith Packard <keithp@keithp.com>
+ *    Chris Wilson <chris@chris-wilson.co.uk>
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "sna.h"
+#include "sna_reg.h"
+#include "sna_render.h"
+#include "sna_render_inline.h"
+#include "sna_video.h"
+
+#include "brw/brw.h"
+#include "gen7_render.h"
+
+#define NO_COMPOSITE 0
+#define NO_COMPOSITE_SPANS 0
+#define NO_COPY 0
+#define NO_COPY_BOXES 0
+#define NO_FILL 0
+#define NO_FILL_BOXES 0
+#define NO_FILL_ONE 0
+#define NO_FILL_CLEAR 0
+
+#define NO_RING_SWITCH 0
+
+#define USE_8_PIXEL_DISPATCH 1
+#define USE_16_PIXEL_DISPATCH 1
+#define USE_32_PIXEL_DISPATCH 0
+
+#if !USE_8_PIXEL_DISPATCH && !USE_16_PIXEL_DISPATCH && !USE_32_PIXEL_DISPATCH
+#error "Must select at least 8, 16 or 32 pixel dispatch"
+#endif
+
+#define GEN7_MAX_SIZE 16384
+
+/* XXX Todo
+ *
+ * STR (software tiled rendering) mode. No, really.
+ * 64x32 pixel blocks align with the rendering cache. Worth considering.
+ */
+
+#define is_aligned(x, y) (((x) & ((y) - 1)) == 0)
+
+struct gt_info {
+       uint32_t max_vs_threads;
+       uint32_t max_gs_threads;
+       uint32_t max_wm_threads;
+       struct {
+               int size;
+               int max_vs_entries;
+               int max_gs_entries;
+       } urb;
+};
+
+static const struct gt_info ivb_gt_info = {
+       .max_vs_threads = 16,
+       .max_gs_threads = 16,
+       .max_wm_threads = (16-1) << IVB_PS_MAX_THREADS_SHIFT,
+       .urb = { 128, 64, 64 },
+};
+
+static const struct gt_info ivb_gt1_info = {
+       .max_vs_threads = 36,
+       .max_gs_threads = 36,
+       .max_wm_threads = (48-1) << IVB_PS_MAX_THREADS_SHIFT,
+       .urb = { 128, 512, 192 },
+};
+
+static const struct gt_info ivb_gt2_info = {
+       .max_vs_threads = 128,
+       .max_gs_threads = 128,
+       .max_wm_threads = (172-1) << IVB_PS_MAX_THREADS_SHIFT,
+       .urb = { 256, 704, 320 },
+};
+
+static const struct gt_info hsw_gt_info = {
+       .max_vs_threads = 8,
+       .max_gs_threads = 8,
+       .max_wm_threads =
+               (8 - 1) << HSW_PS_MAX_THREADS_SHIFT |
+               1 << HSW_PS_SAMPLE_MASK_SHIFT,
+       .urb = { 128, 64, 64 },
+};
+
+static const uint32_t ps_kernel_packed[][4] = {
+#include "exa_wm_src_affine.g7b"
+#include "exa_wm_src_sample_argb.g7b"
+#include "exa_wm_yuv_rgb.g7b"
+#include "exa_wm_write.g7b"
+};
+
+static const uint32_t ps_kernel_planar[][4] = {
+#include "exa_wm_src_affine.g7b"
+#include "exa_wm_src_sample_planar.g7b"
+#include "exa_wm_yuv_rgb.g7b"
+#include "exa_wm_write.g7b"
+};
+
+#define KERNEL(kernel_enum, kernel, num_surfaces) \
+    [GEN7_WM_KERNEL_##kernel_enum] = {#kernel_enum, kernel, sizeof(kernel), num_surfaces}
+#define NOKERNEL(kernel_enum, func, num_surfaces) \
+    [GEN7_WM_KERNEL_##kernel_enum] = {#kernel_enum, (void *)func, 0, num_surfaces}
+static const struct wm_kernel_info {
+       const char *name;
+       const void *data;
+       unsigned int size;
+       int num_surfaces;
+} wm_kernels[] = {
+       NOKERNEL(NOMASK, brw_wm_kernel__affine, 2),
+       NOKERNEL(NOMASK_P, brw_wm_kernel__projective, 2),
+
+       NOKERNEL(MASK, brw_wm_kernel__affine_mask, 3),
+       NOKERNEL(MASK_P, brw_wm_kernel__projective_mask, 3),
+
+       NOKERNEL(MASKCA, brw_wm_kernel__affine_mask_ca, 3),
+       NOKERNEL(MASKCA_P, brw_wm_kernel__projective_mask_ca, 3),
+
+       NOKERNEL(MASKSA, brw_wm_kernel__affine_mask_sa, 3),
+       NOKERNEL(MASKSA_P, brw_wm_kernel__projective_mask_sa, 3),
+
+       NOKERNEL(OPACITY, brw_wm_kernel__affine_opacity, 2),
+       NOKERNEL(OPACITY_P, brw_wm_kernel__projective_opacity, 2),
+
+       KERNEL(VIDEO_PLANAR, ps_kernel_planar, 7),
+       KERNEL(VIDEO_PACKED, ps_kernel_packed, 2),
+};
+#undef KERNEL
+
+static const struct blendinfo {
+       bool src_alpha;
+       uint32_t src_blend;
+       uint32_t dst_blend;
+} gen7_blend_op[] = {
+       /* Clear */     {0, GEN7_BLENDFACTOR_ZERO, GEN7_BLENDFACTOR_ZERO},
+       /* Src */       {0, GEN7_BLENDFACTOR_ONE, GEN7_BLENDFACTOR_ZERO},
+       /* Dst */       {0, GEN7_BLENDFACTOR_ZERO, GEN7_BLENDFACTOR_ONE},
+       /* Over */      {1, GEN7_BLENDFACTOR_ONE, GEN7_BLENDFACTOR_INV_SRC_ALPHA},
+       /* OverReverse */ {0, GEN7_BLENDFACTOR_INV_DST_ALPHA, GEN7_BLENDFACTOR_ONE},
+       /* In */        {0, GEN7_BLENDFACTOR_DST_ALPHA, GEN7_BLENDFACTOR_ZERO},
+       /* InReverse */ {1, GEN7_BLENDFACTOR_ZERO, GEN7_BLENDFACTOR_SRC_ALPHA},
+       /* Out */       {0, GEN7_BLENDFACTOR_INV_DST_ALPHA, GEN7_BLENDFACTOR_ZERO},
+       /* OutReverse */ {1, GEN7_BLENDFACTOR_ZERO, GEN7_BLENDFACTOR_INV_SRC_ALPHA},
+       /* Atop */      {1, GEN7_BLENDFACTOR_DST_ALPHA, GEN7_BLENDFACTOR_INV_SRC_ALPHA},
+       /* AtopReverse */ {1, GEN7_BLENDFACTOR_INV_DST_ALPHA, GEN7_BLENDFACTOR_SRC_ALPHA},
+       /* Xor */       {1, GEN7_BLENDFACTOR_INV_DST_ALPHA, GEN7_BLENDFACTOR_INV_SRC_ALPHA},
+       /* Add */       {0, GEN7_BLENDFACTOR_ONE, GEN7_BLENDFACTOR_ONE},
+};
+
+/**
+ * Highest-valued BLENDFACTOR used in gen7_blend_op.
+ *
+ * This leaves out GEN7_BLENDFACTOR_INV_DST_COLOR,
+ * GEN7_BLENDFACTOR_INV_CONST_{COLOR,ALPHA},
+ * GEN7_BLENDFACTOR_INV_SRC1_{COLOR,ALPHA}
+ */
+#define GEN7_BLENDFACTOR_COUNT (GEN7_BLENDFACTOR_INV_DST_ALPHA + 1)
+
+#define GEN7_BLEND_STATE_PADDED_SIZE   ALIGN(sizeof(struct gen7_blend_state), 64)
+
+#define BLEND_OFFSET(s, d) \
+       (((s) * GEN7_BLENDFACTOR_COUNT + (d)) * GEN7_BLEND_STATE_PADDED_SIZE)
+
+#define NO_BLEND BLEND_OFFSET(GEN7_BLENDFACTOR_ONE, GEN7_BLENDFACTOR_ZERO)
+#define CLEAR BLEND_OFFSET(GEN7_BLENDFACTOR_ZERO, GEN7_BLENDFACTOR_ZERO)
+
+#define SAMPLER_OFFSET(sf, se, mf, me) \
+       ((((((sf) * EXTEND_COUNT + (se)) * FILTER_COUNT + (mf)) * EXTEND_COUNT + (me)) + 2) * 2 * sizeof(struct gen7_sampler_state))
+
+#define VERTEX_2s2s 0
+
+#define COPY_SAMPLER 0
+#define COPY_VERTEX VERTEX_2s2s
+#define COPY_FLAGS(a) GEN7_SET_FLAGS(COPY_SAMPLER, (a) == GXcopy ? NO_BLEND : CLEAR, GEN7_WM_KERNEL_NOMASK, COPY_VERTEX)
+
+#define FILL_SAMPLER (2 * sizeof(struct gen7_sampler_state))
+#define FILL_VERTEX VERTEX_2s2s
+#define FILL_FLAGS(op, format) GEN7_SET_FLAGS(FILL_SAMPLER, gen7_get_blend((op), false, (format)), GEN7_WM_KERNEL_NOMASK, FILL_VERTEX)
+#define FILL_FLAGS_NOBLEND GEN7_SET_FLAGS(FILL_SAMPLER, NO_BLEND, GEN7_WM_KERNEL_NOMASK, FILL_VERTEX)
+
+#define VIDEO_SAMPLER \
+       SAMPLER_OFFSET(SAMPLER_FILTER_BILINEAR, SAMPLER_EXTEND_PAD, \
+                      SAMPLER_FILTER_NEAREST, SAMPLER_EXTEND_NONE)
+
+#define GEN7_SAMPLER(f) (((f) >> 16) & 0xfff0)
+#define GEN7_BLEND(f) (((f) >> 0) & 0xfff0)
+#define GEN7_KERNEL(f) (((f) >> 16) & 0xf)
+#define GEN7_VERTEX(f) (((f) >> 0) & 0xf)
+#define GEN7_SET_FLAGS(S, B, K, V)  (((S) | (K)) << 16 | ((B) | (V)))
+
+#define OUT_BATCH(v) batch_emit(sna, v)
+#define OUT_VERTEX(x,y) vertex_emit_2s(sna, x,y)
+#define OUT_VERTEX_F(v) vertex_emit(sna, v)
+
+static inline bool too_large(int width, int height)
+{
+       return width > GEN7_MAX_SIZE || height > GEN7_MAX_SIZE;
+}
+
+static uint32_t gen7_get_blend(int op,
+                              bool has_component_alpha,
+                              uint32_t dst_format)
+{
+       uint32_t src, dst;
+
+       src = gen7_blend_op[op].src_blend;
+       dst = gen7_blend_op[op].dst_blend;
+
+       /* If there's no dst alpha channel, adjust the blend op so that
+        * we'll treat it always as 1.
+        */
+       if (PICT_FORMAT_A(dst_format) == 0) {
+               if (src == GEN7_BLENDFACTOR_DST_ALPHA)
+                       src = GEN7_BLENDFACTOR_ONE;
+               else if (src == GEN7_BLENDFACTOR_INV_DST_ALPHA)
+                       src = GEN7_BLENDFACTOR_ZERO;
+       }
+
+       /* If the source alpha is being used, then we should only be in a
+        * case where the source blend factor is 0, and the source blend
+        * value is the mask channels multiplied by the source picture's alpha.
+        */
+       if (has_component_alpha && gen7_blend_op[op].src_alpha) {
+               if (dst == GEN7_BLENDFACTOR_SRC_ALPHA)
+                       dst = GEN7_BLENDFACTOR_SRC_COLOR;
+               else if (dst == GEN7_BLENDFACTOR_INV_SRC_ALPHA)
+                       dst = GEN7_BLENDFACTOR_INV_SRC_COLOR;
+       }
+
+       DBG(("blend op=%d, dst=%x [A=%d] => src=%d, dst=%d => offset=%x\n",
+            op, dst_format, PICT_FORMAT_A(dst_format),
+            src, dst, (int)BLEND_OFFSET(src, dst)));
+       return BLEND_OFFSET(src, dst);
+}
+
+static uint32_t gen7_get_card_format(PictFormat format)
+{
+       switch (format) {
+       default:
+               return -1;
+       case PICT_a8r8g8b8:
+               return GEN7_SURFACEFORMAT_B8G8R8A8_UNORM;
+       case PICT_x8r8g8b8:
+               return GEN7_SURFACEFORMAT_B8G8R8X8_UNORM;
+       case PICT_a8b8g8r8:
+               return GEN7_SURFACEFORMAT_R8G8B8A8_UNORM;
+       case PICT_x8b8g8r8:
+               return GEN7_SURFACEFORMAT_R8G8B8X8_UNORM;
+       case PICT_a2r10g10b10:
+               return GEN7_SURFACEFORMAT_B10G10R10A2_UNORM;
+       case PICT_x2r10g10b10:
+               return GEN7_SURFACEFORMAT_B10G10R10X2_UNORM;
+       case PICT_r8g8b8:
+               return GEN7_SURFACEFORMAT_R8G8B8_UNORM;
+       case PICT_r5g6b5:
+               return GEN7_SURFACEFORMAT_B5G6R5_UNORM;
+       case PICT_a1r5g5b5:
+               return GEN7_SURFACEFORMAT_B5G5R5A1_UNORM;
+       case PICT_a8:
+               return GEN7_SURFACEFORMAT_A8_UNORM;
+       case PICT_a4r4g4b4:
+               return GEN7_SURFACEFORMAT_B4G4R4A4_UNORM;
+       }
+}
+
+static uint32_t gen7_get_dest_format(PictFormat format)
+{
+       switch (format) {
+       default:
+               return -1;
+       case PICT_a8r8g8b8:
+       case PICT_x8r8g8b8:
+               return GEN7_SURFACEFORMAT_B8G8R8A8_UNORM;
+       case PICT_a8b8g8r8:
+       case PICT_x8b8g8r8:
+               return GEN7_SURFACEFORMAT_R8G8B8A8_UNORM;
+       case PICT_a2r10g10b10:
+       case PICT_x2r10g10b10:
+               return GEN7_SURFACEFORMAT_B10G10R10A2_UNORM;
+       case PICT_r5g6b5:
+               return GEN7_SURFACEFORMAT_B5G6R5_UNORM;
+       case PICT_x1r5g5b5:
+       case PICT_a1r5g5b5:
+               return GEN7_SURFACEFORMAT_B5G5R5A1_UNORM;
+       case PICT_a8:
+               return GEN7_SURFACEFORMAT_A8_UNORM;
+       case PICT_a4r4g4b4:
+       case PICT_x4r4g4b4:
+               return GEN7_SURFACEFORMAT_B4G4R4A4_UNORM;
+       }
+}
+
+static bool gen7_check_dst_format(PictFormat format)
+{
+       if (gen7_get_dest_format(format) != -1)
+               return true;
+
+       DBG(("%s: unhandled format: %x\n", __FUNCTION__, (int)format));
+       return false;
+}
+
+static bool gen7_check_format(uint32_t format)
+{
+       if (gen7_get_card_format(format) != -1)
+               return true;
+
+       DBG(("%s: unhandled format: %x\n", __FUNCTION__, (int)format));
+       return false;
+}
+
+static uint32_t gen7_filter(uint32_t filter)
+{
+       switch (filter) {
+       default:
+               assert(0);
+       case PictFilterNearest:
+               return SAMPLER_FILTER_NEAREST;
+       case PictFilterBilinear:
+               return SAMPLER_FILTER_BILINEAR;
+       }
+}
+
+static uint32_t gen7_check_filter(PicturePtr picture)
+{
+       switch (picture->filter) {
+       case PictFilterNearest:
+       case PictFilterBilinear:
+               return true;
+       default:
+               return false;
+       }
+}
+
+static uint32_t gen7_repeat(uint32_t repeat)
+{
+       switch (repeat) {
+       default:
+               assert(0);
+       case RepeatNone:
+               return SAMPLER_EXTEND_NONE;
+       case RepeatNormal:
+               return SAMPLER_EXTEND_REPEAT;
+       case RepeatPad:
+               return SAMPLER_EXTEND_PAD;
+       case RepeatReflect:
+               return SAMPLER_EXTEND_REFLECT;
+       }
+}
+
+static bool gen7_check_repeat(PicturePtr picture)
+{
+       if (!picture->repeat)
+               return true;
+
+       switch (picture->repeatType) {
+       case RepeatNone:
+       case RepeatNormal:
+       case RepeatPad:
+       case RepeatReflect:
+               return true;
+       default:
+               return false;
+       }
+}
+
+static int
+gen7_choose_composite_kernel(int op, bool has_mask, bool is_ca, bool is_affine)
+{
+       int base;
+
+       if (has_mask) {
+               if (is_ca) {
+                       if (gen7_blend_op[op].src_alpha)
+                               base = GEN7_WM_KERNEL_MASKSA;
+                       else
+                               base = GEN7_WM_KERNEL_MASKCA;
+               } else
+                       base = GEN7_WM_KERNEL_MASK;
+       } else
+               base = GEN7_WM_KERNEL_NOMASK;
+
+       return base + !is_affine;
+}
+
+static void
+gen7_emit_urb(struct sna *sna)
+{
+       OUT_BATCH(GEN7_3DSTATE_PUSH_CONSTANT_ALLOC_PS | (2 - 2));
+       OUT_BATCH(8); /* in 1KBs */
+
+       /* num of VS entries must be divisible by 8 if size < 9 */
+       OUT_BATCH(GEN7_3DSTATE_URB_VS | (2 - 2));
+       OUT_BATCH((sna->render_state.gen7.info->urb.max_vs_entries << GEN7_URB_ENTRY_NUMBER_SHIFT) |
+                 (2 - 1) << GEN7_URB_ENTRY_SIZE_SHIFT |
+                 (1 << GEN7_URB_STARTING_ADDRESS_SHIFT));
+
+       OUT_BATCH(GEN7_3DSTATE_URB_HS | (2 - 2));
+       OUT_BATCH((0 << GEN7_URB_ENTRY_SIZE_SHIFT) |
+                 (2 << GEN7_URB_STARTING_ADDRESS_SHIFT));
+
+       OUT_BATCH(GEN7_3DSTATE_URB_DS | (2 - 2));
+       OUT_BATCH((0 << GEN7_URB_ENTRY_SIZE_SHIFT) |
+                 (2 << GEN7_URB_STARTING_ADDRESS_SHIFT));
+
+       OUT_BATCH(GEN7_3DSTATE_URB_GS | (2 - 2));
+       OUT_BATCH((0 << GEN7_URB_ENTRY_SIZE_SHIFT) |
+                 (1 << GEN7_URB_STARTING_ADDRESS_SHIFT));
+}
+
+static void
+gen7_emit_state_base_address(struct sna *sna)
+{
+       OUT_BATCH(GEN7_STATE_BASE_ADDRESS | (10 - 2));
+       OUT_BATCH(0); /* general */
+       OUT_BATCH(kgem_add_reloc(&sna->kgem, /* surface */
+                                sna->kgem.nbatch,
+                                NULL,
+                                I915_GEM_DOMAIN_INSTRUCTION << 16,
+                                BASE_ADDRESS_MODIFY));
+       OUT_BATCH(kgem_add_reloc(&sna->kgem, /* instruction */
+                                sna->kgem.nbatch,
+                                sna->render_state.gen7.general_bo,
+                                I915_GEM_DOMAIN_INSTRUCTION << 16,
+                                BASE_ADDRESS_MODIFY));
+       OUT_BATCH(0); /* indirect */
+       OUT_BATCH(kgem_add_reloc(&sna->kgem,
+                                sna->kgem.nbatch,
+                                sna->render_state.gen7.general_bo,
+                                I915_GEM_DOMAIN_INSTRUCTION << 16,
+                                BASE_ADDRESS_MODIFY));
+
+       /* upper bounds, disable */
+       OUT_BATCH(0);
+       OUT_BATCH(BASE_ADDRESS_MODIFY);
+       OUT_BATCH(0);
+       OUT_BATCH(BASE_ADDRESS_MODIFY);
+}
+
+static void
+gen7_disable_vs(struct sna *sna)
+{
+       /* For future reference:
+        * A PIPE_CONTROL with post-sync op set to 1 and a depth stall needs
+        * to be emitted just prior to change VS state, i.e. 3DSTATE_VS,
+        * 3DSTATE_URB_VS, 3DSTATE_CONSTANT_VS,
+        * 3DSTATE_BINDING_TABLE_POINTER_VS, 3DSTATE_SAMPLER_STATE_POINTER_VS.
+        *
+        * Here we saved by the full-flush incurred when emitting
+        * the batchbuffer.
+        */
+       OUT_BATCH(GEN7_3DSTATE_VS | (6 - 2));
+       OUT_BATCH(0); /* no VS kernel */
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0); /* pass-through */
+
+#if 0
+       OUT_BATCH(GEN7_3DSTATE_CONSTANT_VS | (7 - 2));
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+
+       OUT_BATCH(GEN7_3DSTATE_BINDING_TABLE_POINTERS_VS | (2 - 2));
+       OUT_BATCH(0);
+
+       OUT_BATCH(GEN7_3DSTATE_SAMPLER_STATE_POINTERS_VS | (2 - 2));
+       OUT_BATCH(0);
+#endif
+}
+
+static void
+gen7_disable_hs(struct sna *sna)
+{
+       OUT_BATCH(GEN7_3DSTATE_HS | (7 - 2));
+       OUT_BATCH(0); /* no HS kernel */
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0); /* pass-through */
+
+#if 0
+       OUT_BATCH(GEN7_3DSTATE_CONSTANT_HS | (7 - 2));
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+
+       OUT_BATCH(GEN7_3DSTATE_BINDING_TABLE_POINTERS_HS | (2 - 2));
+       OUT_BATCH(0);
+
+       OUT_BATCH(GEN7_3DSTATE_SAMPLER_STATE_POINTERS_HS | (2 - 2));
+       OUT_BATCH(0);
+#endif
+}
+
+static void
+gen7_disable_te(struct sna *sna)
+{
+       OUT_BATCH(GEN7_3DSTATE_TE | (4 - 2));
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+}
+
+static void
+gen7_disable_ds(struct sna *sna)
+{
+       OUT_BATCH(GEN7_3DSTATE_DS | (6 - 2));
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+
+#if 0
+       OUT_BATCH(GEN7_3DSTATE_CONSTANT_DS | (7 - 2));
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+
+       OUT_BATCH(GEN7_3DSTATE_BINDING_TABLE_POINTERS_DS | (2 - 2));
+       OUT_BATCH(0);
+
+       OUT_BATCH(GEN7_3DSTATE_SAMPLER_STATE_POINTERS_DS | (2 - 2));
+       OUT_BATCH(0);
+#endif
+}
+
+static void
+gen7_disable_gs(struct sna *sna)
+{
+       OUT_BATCH(GEN7_3DSTATE_GS | (7 - 2));
+       OUT_BATCH(0); /* no GS kernel */
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0); /* pass-through */
+
+#if 0
+       OUT_BATCH(GEN7_3DSTATE_CONSTANT_GS | (7 - 2));
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+
+       OUT_BATCH(GEN7_3DSTATE_BINDING_TABLE_POINTERS_GS | (2 - 2));
+       OUT_BATCH(0);
+
+       OUT_BATCH(GEN7_3DSTATE_SAMPLER_STATE_POINTERS_GS | (2 - 2));
+       OUT_BATCH(0);
+#endif
+}
+
+static void
+gen7_disable_streamout(struct sna *sna)
+{
+       OUT_BATCH(GEN7_3DSTATE_STREAMOUT | (3 - 2));
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+}
+
+static void
+gen7_emit_sf_invariant(struct sna *sna)
+{
+       OUT_BATCH(GEN7_3DSTATE_SF | (7 - 2));
+       OUT_BATCH(0);
+       OUT_BATCH(GEN7_3DSTATE_SF_CULL_NONE);
+       OUT_BATCH(2 << GEN7_3DSTATE_SF_TRIFAN_PROVOKE_SHIFT);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+}
+
+static void
+gen7_emit_cc_invariant(struct sna *sna)
+{
+#if 0 /* unused, no change */
+       OUT_BATCH(GEN7_3DSTATE_CC_STATE_POINTERS | (2 - 2));
+       OUT_BATCH(0);
+
+       OUT_BATCH(GEN7_3DSTATE_DEPTH_STENCIL_STATE_POINTERS | (2 - 2));
+       OUT_BATCH(0);
+#endif
+
+       assert(is_aligned(sna->render_state.gen7.cc_vp, 32));
+       OUT_BATCH(GEN7_3DSTATE_VIEWPORT_STATE_POINTERS_CC | (2 - 2));
+       OUT_BATCH(sna->render_state.gen7.cc_vp);
+}
+
+static void
+gen7_disable_clip(struct sna *sna)
+{
+       OUT_BATCH(GEN7_3DSTATE_CLIP | (4 - 2));
+       OUT_BATCH(0);
+       OUT_BATCH(0); /* pass-through */
+       OUT_BATCH(0);
+
+       OUT_BATCH(GEN7_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CL | (2 - 2));
+       OUT_BATCH(0);
+}
+
+static void
+gen7_emit_wm_invariant(struct sna *sna)
+{
+       OUT_BATCH(GEN7_3DSTATE_WM | (3 - 2));
+       OUT_BATCH(GEN7_WM_DISPATCH_ENABLE |
+                 GEN7_WM_PERSPECTIVE_PIXEL_BARYCENTRIC);
+       OUT_BATCH(0);
+
+#if 0
+       /* XXX length bias of 7 in old spec? */
+       OUT_BATCH(GEN7_3DSTATE_CONSTANT_PS | (7 - 2));
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+#endif
+}
+
+static void
+gen7_emit_null_depth_buffer(struct sna *sna)
+{
+       OUT_BATCH(GEN7_3DSTATE_DEPTH_BUFFER | (7 - 2));
+       OUT_BATCH(GEN7_SURFACE_NULL << GEN7_3DSTATE_DEPTH_BUFFER_TYPE_SHIFT |
+                 GEN7_DEPTHFORMAT_D32_FLOAT << GEN7_3DSTATE_DEPTH_BUFFER_FORMAT_SHIFT);
+       OUT_BATCH(0); /* disable depth, stencil and hiz */
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+
+       OUT_BATCH(GEN7_3DSTATE_CLEAR_PARAMS | (3 - 2));
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+}
+
+static void
+gen7_emit_invariant(struct sna *sna)
+{
+       OUT_BATCH(GEN7_PIPELINE_SELECT | PIPELINE_SELECT_3D);
+
+       OUT_BATCH(GEN7_3DSTATE_MULTISAMPLE | (4 - 2));
+       OUT_BATCH(GEN7_3DSTATE_MULTISAMPLE_PIXEL_LOCATION_CENTER |
+                 GEN7_3DSTATE_MULTISAMPLE_NUMSAMPLES_1); /* 1 sample/pixel */
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+
+       OUT_BATCH(GEN7_3DSTATE_SAMPLE_MASK | (2 - 2));
+       OUT_BATCH(1);
+
+       gen7_emit_urb(sna);
+
+       gen7_emit_state_base_address(sna);
+
+       gen7_disable_vs(sna);
+       gen7_disable_hs(sna);
+       gen7_disable_te(sna);
+       gen7_disable_ds(sna);
+       gen7_disable_gs(sna);
+       gen7_disable_clip(sna);
+       gen7_emit_sf_invariant(sna);
+       gen7_emit_wm_invariant(sna);
+       gen7_emit_cc_invariant(sna);
+       gen7_disable_streamout(sna);
+       gen7_emit_null_depth_buffer(sna);
+
+       sna->render_state.gen7.needs_invariant = false;
+}
+
+static void
+gen7_emit_cc(struct sna *sna, uint32_t blend_offset)
+{
+       struct gen7_render_state *render = &sna->render_state.gen7;
+
+       if (render->blend == blend_offset)
+               return;
+
+       DBG(("%s: blend = %x\n", __FUNCTION__, blend_offset));
+
+       /* XXX can have upto 8 blend states preload, selectable via
+        * Render Target Index. What other side-effects of Render Target Index?
+        */
+
+       assert (is_aligned(render->cc_blend + blend_offset, 64));
+       OUT_BATCH(GEN7_3DSTATE_BLEND_STATE_POINTERS | (2 - 2));
+       OUT_BATCH((render->cc_blend + blend_offset) | 1);
+
+       render->blend = blend_offset;
+}
+
+static void
+gen7_emit_sampler(struct sna *sna, uint32_t state)
+{
+       if (sna->render_state.gen7.samplers == state)
+               return;
+
+       sna->render_state.gen7.samplers = state;
+
+       DBG(("%s: sampler = %x\n", __FUNCTION__, state));
+
+       assert (is_aligned(sna->render_state.gen7.wm_state + state, 32));
+       OUT_BATCH(GEN7_3DSTATE_SAMPLER_STATE_POINTERS_PS | (2 - 2));
+       OUT_BATCH(sna->render_state.gen7.wm_state + state);
+}
+
+static void
+gen7_emit_sf(struct sna *sna, bool has_mask)
+{
+       int num_sf_outputs = has_mask ? 2 : 1;
+
+       if (sna->render_state.gen7.num_sf_outputs == num_sf_outputs)
+               return;
+
+       DBG(("%s: num_sf_outputs=%d, read_length=%d, read_offset=%d\n",
+            __FUNCTION__, num_sf_outputs, 1, 0));
+
+       sna->render_state.gen7.num_sf_outputs = num_sf_outputs;
+
+       OUT_BATCH(GEN7_3DSTATE_SBE | (14 - 2));
+       OUT_BATCH(num_sf_outputs << GEN7_SBE_NUM_OUTPUTS_SHIFT |
+                 1 << GEN7_SBE_URB_ENTRY_READ_LENGTH_SHIFT |
+                 1 << GEN7_SBE_URB_ENTRY_READ_OFFSET_SHIFT);
+       OUT_BATCH(0);
+       OUT_BATCH(0); /* dw4 */
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0); /* dw8 */
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0); /* dw12 */
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+}
+
+static void
+gen7_emit_wm(struct sna *sna, int kernel)
+{
+       const uint32_t *kernels;
+
+       if (sna->render_state.gen7.kernel == kernel)
+               return;
+
+       sna->render_state.gen7.kernel = kernel;
+       kernels = sna->render_state.gen7.wm_kernel[kernel];
+
+       DBG(("%s: switching to %s, num_surfaces=%d (8-wide? %d, 16-wide? %d, 32-wide? %d)\n",
+            __FUNCTION__,
+            wm_kernels[kernel].name,
+            wm_kernels[kernel].num_surfaces,
+            kernels[0], kernels[1], kernels[2]));
+
+       OUT_BATCH(GEN7_3DSTATE_PS | (8 - 2));
+       OUT_BATCH(kernels[0] ?: kernels[1] ?: kernels[2]);
+       OUT_BATCH(1 << GEN7_PS_SAMPLER_COUNT_SHIFT |
+                 wm_kernels[kernel].num_surfaces << GEN7_PS_BINDING_TABLE_ENTRY_COUNT_SHIFT);
+       OUT_BATCH(0); /* scratch address */
+       OUT_BATCH(sna->render_state.gen7.info->max_wm_threads |
+                 (kernels[0] ? GEN7_PS_8_DISPATCH_ENABLE : 0) |
+                 (kernels[1] ? GEN7_PS_16_DISPATCH_ENABLE : 0) |
+                 (kernels[2] ? GEN7_PS_32_DISPATCH_ENABLE : 0) |
+                 GEN7_PS_ATTRIBUTE_ENABLE);
+       OUT_BATCH((kernels[0] ? 4 : kernels[1] ? 6 : 8) << GEN7_PS_DISPATCH_START_GRF_SHIFT_0 |
+                 8 << GEN7_PS_DISPATCH_START_GRF_SHIFT_1 |
+                 6 << GEN7_PS_DISPATCH_START_GRF_SHIFT_2);
+       OUT_BATCH(kernels[2]);
+       OUT_BATCH(kernels[1]);
+}
+
+static bool
+gen7_emit_binding_table(struct sna *sna, uint16_t offset)
+{
+       if (sna->render_state.gen7.surface_table == offset)
+               return false;
+
+       /* Binding table pointers */
+       assert(is_aligned(4*offset, 32));
+       OUT_BATCH(GEN7_3DSTATE_BINDING_TABLE_POINTERS_PS | (2 - 2));
+       OUT_BATCH(offset*4);
+
+       sna->render_state.gen7.surface_table = offset;
+       return true;
+}
+
+static bool
+gen7_emit_drawing_rectangle(struct sna *sna,
+                           const struct sna_composite_op *op)
+{
+       uint32_t limit = (op->dst.height - 1) << 16 | (op->dst.width - 1);
+       uint32_t offset = (uint16_t)op->dst.y << 16 | (uint16_t)op->dst.x;
+
+       assert(!too_large(op->dst.x, op->dst.y));
+       assert(!too_large(op->dst.width, op->dst.height));
+
+       if (sna->render_state.gen7.drawrect_limit == limit &&
+           sna->render_state.gen7.drawrect_offset == offset)
+               return true;
+
+       sna->render_state.gen7.drawrect_offset = offset;
+       sna->render_state.gen7.drawrect_limit = limit;
+
+       OUT_BATCH(GEN7_3DSTATE_DRAWING_RECTANGLE | (4 - 2));
+       OUT_BATCH(0);
+       OUT_BATCH(limit);
+       OUT_BATCH(offset);
+       return false;
+}
+
+static void
+gen7_emit_vertex_elements(struct sna *sna,
+                         const struct sna_composite_op *op)
+{
+       /*
+        * vertex data in vertex buffer
+        *    position: (x, y)
+        *    texture coordinate 0: (u0, v0) if (is_affine is true) else (u0, v0, w0)
+        *    texture coordinate 1 if (has_mask is true): same as above
+        */
+       struct gen7_render_state *render = &sna->render_state.gen7;
+       uint32_t src_format, dw, offset;
+       int id = GEN7_VERTEX(op->u.gen7.flags);
+       bool has_mask;
+
+       DBG(("%s: setup id=%d\n", __FUNCTION__, id));
+
+       if (render->ve_id == id)
+               return;
+       render->ve_id = id;
+
+       if (id == VERTEX_2s2s) {
+               DBG(("%s: setup COPY\n", __FUNCTION__));
+
+               OUT_BATCH(GEN7_3DSTATE_VERTEX_ELEMENTS |
+                         ((2 * (1 + 2)) + 1 - 2));
+
+               OUT_BATCH(VERTEX_2s2s << GEN7_VE0_VERTEX_BUFFER_INDEX_SHIFT | GEN7_VE0_VALID |
+                         GEN7_SURFACEFORMAT_R32G32B32A32_FLOAT << GEN7_VE0_FORMAT_SHIFT |
+                         0 << GEN7_VE0_OFFSET_SHIFT);
+               OUT_BATCH(GEN7_VFCOMPONENT_STORE_0 << GEN7_VE1_VFCOMPONENT_0_SHIFT |
+                         GEN7_VFCOMPONENT_STORE_0 << GEN7_VE1_VFCOMPONENT_1_SHIFT |
+                         GEN7_VFCOMPONENT_STORE_0 << GEN7_VE1_VFCOMPONENT_2_SHIFT |
+                         GEN7_VFCOMPONENT_STORE_0 << GEN7_VE1_VFCOMPONENT_3_SHIFT);
+
+               /* x,y */
+               OUT_BATCH(VERTEX_2s2s << GEN7_VE0_VERTEX_BUFFER_INDEX_SHIFT | GEN7_VE0_VALID |
+                         GEN7_SURFACEFORMAT_R16G16_SSCALED << GEN7_VE0_FORMAT_SHIFT |
+                         0 << GEN7_VE0_OFFSET_SHIFT); /* offsets vb in bytes */
+               OUT_BATCH(GEN7_VFCOMPONENT_STORE_SRC << GEN7_VE1_VFCOMPONENT_0_SHIFT |
+                         GEN7_VFCOMPONENT_STORE_SRC << GEN7_VE1_VFCOMPONENT_1_SHIFT |
+                         GEN7_VFCOMPONENT_STORE_0 << GEN7_VE1_VFCOMPONENT_2_SHIFT |
+                         GEN7_VFCOMPONENT_STORE_1_FLT << GEN7_VE1_VFCOMPONENT_3_SHIFT);
+
+               OUT_BATCH(VERTEX_2s2s << GEN7_VE0_VERTEX_BUFFER_INDEX_SHIFT | GEN7_VE0_VALID |
+                         GEN7_SURFACEFORMAT_R16G16_SSCALED << GEN7_VE0_FORMAT_SHIFT |
+                         4 << GEN7_VE0_OFFSET_SHIFT);  /* offset vb in bytes */
+               OUT_BATCH(GEN7_VFCOMPONENT_STORE_SRC << GEN7_VE1_VFCOMPONENT_0_SHIFT |
+                         GEN7_VFCOMPONENT_STORE_SRC << GEN7_VE1_VFCOMPONENT_1_SHIFT |
+                         GEN7_VFCOMPONENT_STORE_0 << GEN7_VE1_VFCOMPONENT_2_SHIFT |
+                         GEN7_VFCOMPONENT_STORE_1_FLT << GEN7_VE1_VFCOMPONENT_3_SHIFT);
+               return;
+       }
+
+       /* The VUE layout
+        *    dword 0-3: pad (0.0, 0.0, 0.0. 0.0)
+        *    dword 4-7: position (x, y, 1.0, 1.0),
+        *    dword 8-11: texture coordinate 0 (u0, v0, w0, 1.0)
+        *    dword 12-15: texture coordinate 1 (u1, v1, w1, 1.0)
+        *
+        * dword 4-15 are fetched from vertex buffer
+        */
+       has_mask = (id >> 2) != 0;
+       OUT_BATCH(GEN7_3DSTATE_VERTEX_ELEMENTS |
+               ((2 * (3 + has_mask)) + 1 - 2));
+
+       OUT_BATCH(id << GEN7_VE0_VERTEX_BUFFER_INDEX_SHIFT | GEN7_VE0_VALID |
+                 GEN7_SURFACEFORMAT_R32G32B32A32_FLOAT << GEN7_VE0_FORMAT_SHIFT |
+                 0 << GEN7_VE0_OFFSET_SHIFT);
+       OUT_BATCH(GEN7_VFCOMPONENT_STORE_0 << GEN7_VE1_VFCOMPONENT_0_SHIFT |
+                 GEN7_VFCOMPONENT_STORE_0 << GEN7_VE1_VFCOMPONENT_1_SHIFT |
+                 GEN7_VFCOMPONENT_STORE_0 << GEN7_VE1_VFCOMPONENT_2_SHIFT |
+                 GEN7_VFCOMPONENT_STORE_0 << GEN7_VE1_VFCOMPONENT_3_SHIFT);
+
+       /* x,y */
+       OUT_BATCH(id << GEN7_VE0_VERTEX_BUFFER_INDEX_SHIFT | GEN7_VE0_VALID |
+                 GEN7_SURFACEFORMAT_R16G16_SSCALED << GEN7_VE0_FORMAT_SHIFT |
+                 0 << GEN7_VE0_OFFSET_SHIFT);
+       OUT_BATCH(GEN7_VFCOMPONENT_STORE_SRC << GEN7_VE1_VFCOMPONENT_0_SHIFT |
+                 GEN7_VFCOMPONENT_STORE_SRC << GEN7_VE1_VFCOMPONENT_1_SHIFT |
+                 GEN7_VFCOMPONENT_STORE_0 << GEN7_VE1_VFCOMPONENT_2_SHIFT |
+                 GEN7_VFCOMPONENT_STORE_1_FLT << GEN7_VE1_VFCOMPONENT_3_SHIFT);
+       offset = 4;
+
+       /* u0, v0, w0 */
+       DBG(("%s: first channel %d floats, offset=%d\n", __FUNCTION__, id & 3, offset));
+       dw = GEN7_VFCOMPONENT_STORE_1_FLT << GEN7_VE1_VFCOMPONENT_3_SHIFT;
+       switch (id & 3) {
+       case 1:
+               src_format = GEN7_SURFACEFORMAT_R32_FLOAT;
+               dw |= GEN7_VFCOMPONENT_STORE_SRC << GEN7_VE1_VFCOMPONENT_0_SHIFT;
+               dw |= GEN7_VFCOMPONENT_STORE_0 << GEN7_VE1_VFCOMPONENT_1_SHIFT;
+               dw |= GEN7_VFCOMPONENT_STORE_0 << GEN7_VE1_VFCOMPONENT_2_SHIFT;
+               break;
+       default:
+               assert(0);
+       case 2:
+               src_format = GEN7_SURFACEFORMAT_R32G32_FLOAT;
+               dw |= GEN7_VFCOMPONENT_STORE_SRC << GEN7_VE1_VFCOMPONENT_0_SHIFT;
+               dw |= GEN7_VFCOMPONENT_STORE_SRC << GEN7_VE1_VFCOMPONENT_1_SHIFT;
+               dw |= GEN7_VFCOMPONENT_STORE_0 << GEN7_VE1_VFCOMPONENT_2_SHIFT;
+               break;
+       case 3:
+               src_format = GEN7_SURFACEFORMAT_R32G32B32_FLOAT;
+               dw |= GEN7_VFCOMPONENT_STORE_SRC << GEN7_VE1_VFCOMPONENT_0_SHIFT;
+               dw |= GEN7_VFCOMPONENT_STORE_SRC << GEN7_VE1_VFCOMPONENT_1_SHIFT;
+               dw |= GEN7_VFCOMPONENT_STORE_SRC << GEN7_VE1_VFCOMPONENT_2_SHIFT;
+               break;
+       }
+       OUT_BATCH(id << GEN7_VE0_VERTEX_BUFFER_INDEX_SHIFT | GEN7_VE0_VALID |
+                 src_format << GEN7_VE0_FORMAT_SHIFT |
+                 offset << GEN7_VE0_OFFSET_SHIFT);
+       OUT_BATCH(dw);
+       offset += (id & 3) * sizeof(float);
+
+       /* u1, v1, w1 */
+       if (has_mask) {
+               DBG(("%s: second channel %d floats, offset=%d\n", __FUNCTION__, (id >> 2) & 3, offset));
+               dw = GEN7_VFCOMPONENT_STORE_1_FLT << GEN7_VE1_VFCOMPONENT_3_SHIFT;
+               switch ((id >> 2) & 3) {
+               case 1:
+                       src_format = GEN7_SURFACEFORMAT_R32_FLOAT;
+                       dw |= GEN7_VFCOMPONENT_STORE_SRC << GEN7_VE1_VFCOMPONENT_0_SHIFT;
+                       dw |= GEN7_VFCOMPONENT_STORE_0 << GEN7_VE1_VFCOMPONENT_1_SHIFT;
+                       dw |= GEN7_VFCOMPONENT_STORE_0 << GEN7_VE1_VFCOMPONENT_2_SHIFT;
+                       break;
+               default:
+                       assert(0);
+               case 2:
+                       src_format = GEN7_SURFACEFORMAT_R32G32_FLOAT;
+                       dw |= GEN7_VFCOMPONENT_STORE_SRC << GEN7_VE1_VFCOMPONENT_0_SHIFT;
+                       dw |= GEN7_VFCOMPONENT_STORE_SRC << GEN7_VE1_VFCOMPONENT_1_SHIFT;
+                       dw |= GEN7_VFCOMPONENT_STORE_0 << GEN7_VE1_VFCOMPONENT_2_SHIFT;
+                       break;
+               case 3:
+                       src_format = GEN7_SURFACEFORMAT_R32G32B32_FLOAT;
+                       dw |= GEN7_VFCOMPONENT_STORE_SRC << GEN7_VE1_VFCOMPONENT_0_SHIFT;
+                       dw |= GEN7_VFCOMPONENT_STORE_SRC << GEN7_VE1_VFCOMPONENT_1_SHIFT;
+                       dw |= GEN7_VFCOMPONENT_STORE_SRC << GEN7_VE1_VFCOMPONENT_2_SHIFT;
+                       break;
+               }
+               OUT_BATCH(id << GEN7_VE0_VERTEX_BUFFER_INDEX_SHIFT | GEN7_VE0_VALID |
+                         src_format << GEN7_VE0_FORMAT_SHIFT |
+                         offset << GEN7_VE0_OFFSET_SHIFT);
+               OUT_BATCH(dw);
+       }
+}
+
+inline static void
+gen7_emit_pipe_invalidate(struct sna *sna)
+{
+       OUT_BATCH(GEN7_PIPE_CONTROL | (4 - 2));
+       OUT_BATCH(GEN7_PIPE_CONTROL_WC_FLUSH |
+                 GEN7_PIPE_CONTROL_TC_FLUSH |
+                 GEN7_PIPE_CONTROL_CS_STALL);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+}
+
+inline static void
+gen7_emit_pipe_flush(struct sna *sna)
+{
+       OUT_BATCH(GEN7_PIPE_CONTROL | (4 - 2));
+       OUT_BATCH(GEN7_PIPE_CONTROL_WC_FLUSH);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+}
+
+inline static void
+gen7_emit_pipe_stall(struct sna *sna)
+{
+       OUT_BATCH(GEN7_PIPE_CONTROL | (4 - 2));
+       OUT_BATCH(GEN7_PIPE_CONTROL_CS_STALL |
+                 GEN7_PIPE_CONTROL_STALL_AT_SCOREBOARD);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+}
+
+static void
+gen7_emit_state(struct sna *sna,
+               const struct sna_composite_op *op,
+               uint16_t wm_binding_table)
+{
+       bool need_stall;
+
+       if (sna->render_state.gen7.emit_flush)
+               gen7_emit_pipe_flush(sna);
+
+       gen7_emit_cc(sna, GEN7_BLEND(op->u.gen7.flags));
+       gen7_emit_sampler(sna, GEN7_SAMPLER(op->u.gen7.flags));
+       gen7_emit_sf(sna, GEN7_VERTEX(op->u.gen7.flags) >> 2);
+       gen7_emit_wm(sna, GEN7_KERNEL(op->u.gen7.flags));
+       gen7_emit_vertex_elements(sna, op);
+
+       need_stall = gen7_emit_binding_table(sna, wm_binding_table);
+       need_stall &= gen7_emit_drawing_rectangle(sna, op);
+
+       if (kgem_bo_is_dirty(op->src.bo) || kgem_bo_is_dirty(op->mask.bo)) {
+               gen7_emit_pipe_invalidate(sna);
+               kgem_clear_dirty(&sna->kgem);
+               if (op->dst.bo->exec)
+                       kgem_bo_mark_dirty(op->dst.bo);
+               need_stall = false;
+       }
+       if (need_stall)
+               gen7_emit_pipe_stall(sna);
+
+       sna->render_state.gen7.emit_flush =
+               GEN7_BLEND(op->u.gen7.flags) != NO_BLEND;
+}
+
+static void gen7_magic_ca_pass(struct sna *sna,
+                              const struct sna_composite_op *op)
+{
+       struct gen7_render_state *state = &sna->render_state.gen7;
+
+       if (!op->need_magic_ca_pass)
+               return;
+
+       DBG(("%s: CA fixup (%d -> %d)\n", __FUNCTION__,
+            sna->render.vertex_start, sna->render.vertex_index));
+
+       gen7_emit_pipe_invalidate(sna);
+
+       gen7_emit_cc(sna, gen7_get_blend(PictOpAdd, true, op->dst.format));
+       gen7_emit_wm(sna,
+                    gen7_choose_composite_kernel(PictOpAdd,
+                                                 true, true,
+                                                 op->is_affine));
+
+       OUT_BATCH(GEN7_3DPRIMITIVE | (7- 2));
+       OUT_BATCH(GEN7_3DPRIMITIVE_VERTEX_SEQUENTIAL | _3DPRIM_RECTLIST);
+       OUT_BATCH(sna->render.vertex_index - sna->render.vertex_start);
+       OUT_BATCH(sna->render.vertex_start);
+       OUT_BATCH(1);   /* single instance */
+       OUT_BATCH(0);   /* start instance location */
+       OUT_BATCH(0);   /* index buffer offset, ignored */
+
+       state->last_primitive = sna->kgem.nbatch;
+}
+
+static void gen7_vertex_flush(struct sna *sna)
+{
+       assert(sna->render_state.gen7.vertex_offset);
+
+       DBG(("%s[%x] = %d\n", __FUNCTION__,
+            4*sna->render_state.gen7.vertex_offset,
+            sna->render.vertex_index - sna->render.vertex_start));
+       sna->kgem.batch[sna->render_state.gen7.vertex_offset] =
+               sna->render.vertex_index - sna->render.vertex_start;
+       sna->render_state.gen7.vertex_offset = 0;
+}
+
+static int gen7_vertex_finish(struct sna *sna)
+{
+       struct kgem_bo *bo;
+       unsigned int i;
+
+       assert(sna->render.vertex_used);
+       assert(sna->render.nvertex_reloc);
+
+       /* Note: we only need dword alignment (currently) */
+
+       bo = sna->render.vbo;
+       if (bo) {
+               if (sna->render_state.gen7.vertex_offset)
+                       gen7_vertex_flush(sna);
+
+               for (i = 0; i < sna->render.nvertex_reloc; i++) {
+                       DBG(("%s: reloc[%d] = %d\n", __FUNCTION__,
+                            i, sna->render.vertex_reloc[i]));
+
+                       sna->kgem.batch[sna->render.vertex_reloc[i]] =
+                               kgem_add_reloc(&sna->kgem,
+                                              sna->render.vertex_reloc[i], bo,
+                                              I915_GEM_DOMAIN_VERTEX << 16,
+                                              0);
+                       sna->kgem.batch[sna->render.vertex_reloc[i]+1] =
+                               kgem_add_reloc(&sna->kgem,
+                                              sna->render.vertex_reloc[i]+1, bo,
+                                              I915_GEM_DOMAIN_VERTEX << 16,
+                                              sna->render.vertex_used * 4 - 1);
+               }
+
+               sna->render.nvertex_reloc = 0;
+               sna->render.vertex_used = 0;
+               sna->render.vertex_index = 0;
+               sna->render_state.gen7.vb_id = 0;
+
+               kgem_bo_destroy(&sna->kgem, bo);
+       }
+
+       sna->render.vertices = NULL;
+       sna->render.vbo = kgem_create_linear(&sna->kgem,
+                                            256*1024, CREATE_GTT_MAP);
+       if (sna->render.vbo)
+               sna->render.vertices = kgem_bo_map(&sna->kgem, sna->render.vbo);
+       if (sna->render.vertices == NULL) {
+               if (sna->render.vbo)
+                       kgem_bo_destroy(&sna->kgem, sna->render.vbo);
+               sna->render.vbo = NULL;
+               return 0;
+       }
+
+       kgem_bo_sync__cpu(&sna->kgem, sna->render.vbo);
+       if (sna->render.vertex_used) {
+               memcpy(sna->render.vertices,
+                      sna->render.vertex_data,
+                      sizeof(float)*sna->render.vertex_used);
+       }
+       sna->render.vertex_size = 64 * 1024 - 1;
+       return sna->render.vertex_size - sna->render.vertex_used;
+}
+
+static void gen7_vertex_close(struct sna *sna)
+{
+       struct kgem_bo *bo, *free_bo = NULL;
+       unsigned int i, delta = 0;
+
+       assert(sna->render_state.gen7.vertex_offset == 0);
+
+       if (!sna->render_state.gen7.vb_id)
+               return;
+
+       DBG(("%s: used=%d, vbo active? %d\n",
+            __FUNCTION__, sna->render.vertex_used, sna->render.vbo ? sna->render.vbo->handle : 0));
+
+       bo = sna->render.vbo;
+       if (bo) {
+               if (sna->render.vertex_size - sna->render.vertex_used < 64) {
+                       DBG(("%s: discarding vbo (full), handle=%d\n", __FUNCTION__, sna->render.vbo->handle));
+                       sna->render.vbo = NULL;
+                       sna->render.vertices = sna->render.vertex_data;
+                       sna->render.vertex_size = ARRAY_SIZE(sna->render.vertex_data);
+                       free_bo = bo;
+               }
+       } else {
+               if (sna->kgem.nbatch + sna->render.vertex_used <= sna->kgem.surface) {
+                       DBG(("%s: copy to batch: %d @ %d\n", __FUNCTION__,
+                            sna->render.vertex_used, sna->kgem.nbatch));
+                       memcpy(sna->kgem.batch + sna->kgem.nbatch,
+                              sna->render.vertex_data,
+                              sna->render.vertex_used * 4);
+                       delta = sna->kgem.nbatch * 4;
+                       bo = NULL;
+                       sna->kgem.nbatch += sna->render.vertex_used;
+               } else {
+                       bo = kgem_create_linear(&sna->kgem,
+                                               4*sna->render.vertex_used, 0);
+                       if (bo && !kgem_bo_write(&sna->kgem, bo,
+                                                sna->render.vertex_data,
+                                                4*sna->render.vertex_used)) {
+                               kgem_bo_destroy(&sna->kgem, bo);
+                               bo = NULL;
+                       }
+                       DBG(("%s: new vbo: %d\n", __FUNCTION__,
+                            sna->render.vertex_used));
+                       free_bo = bo;
+               }
+       }
+
+       assert(sna->render.nvertex_reloc);
+       for (i = 0; i < sna->render.nvertex_reloc; i++) {
+               DBG(("%s: reloc[%d] = %d\n", __FUNCTION__,
+                    i, sna->render.vertex_reloc[i]));
+
+               sna->kgem.batch[sna->render.vertex_reloc[i]] =
+                       kgem_add_reloc(&sna->kgem,
+                                      sna->render.vertex_reloc[i], bo,
+                                      I915_GEM_DOMAIN_VERTEX << 16,
+                                      delta);
+               sna->kgem.batch[sna->render.vertex_reloc[i]+1] =
+                       kgem_add_reloc(&sna->kgem,
+                                      sna->render.vertex_reloc[i]+1, bo,
+                                      I915_GEM_DOMAIN_VERTEX << 16,
+                                      delta + sna->render.vertex_used * 4 - 1);
+       }
+       sna->render.nvertex_reloc = 0;
+
+       if (sna->render.vbo == NULL) {
+               sna->render.vertex_used = 0;
+               sna->render.vertex_index = 0;
+               assert(sna->render.vertices == sna->render.vertex_data);
+               assert(sna->render.vertex_size == ARRAY_SIZE(sna->render.vertex_data));
+       }
+
+       if (free_bo)
+               kgem_bo_destroy(&sna->kgem, free_bo);
+}
+
+static void null_create(struct sna_static_stream *stream)
+{
+       /* A bunch of zeros useful for legacy border color and depth-stencil */
+       sna_static_stream_map(stream, 64, 64);
+}
+
+static void
+sampler_state_init(struct gen7_sampler_state *sampler_state,
+                  sampler_filter_t filter,
+                  sampler_extend_t extend)
+{
+       sampler_state->ss0.lod_preclamp = 1;    /* GL mode */
+
+       /* We use the legacy mode to get the semantics specified by
+        * the Render extension. */
+       sampler_state->ss0.default_color_mode = GEN7_BORDER_COLOR_MODE_LEGACY;
+
+       switch (filter) {
+       default:
+       case SAMPLER_FILTER_NEAREST:
+               sampler_state->ss0.min_filter = GEN7_MAPFILTER_NEAREST;
+               sampler_state->ss0.mag_filter = GEN7_MAPFILTER_NEAREST;
+               break;
+       case SAMPLER_FILTER_BILINEAR:
+               sampler_state->ss0.min_filter = GEN7_MAPFILTER_LINEAR;
+               sampler_state->ss0.mag_filter = GEN7_MAPFILTER_LINEAR;
+               break;
+       }
+
+       switch (extend) {
+       default:
+       case SAMPLER_EXTEND_NONE:
+               sampler_state->ss3.r_wrap_mode = GEN7_TEXCOORDMODE_CLAMP_BORDER;
+               sampler_state->ss3.s_wrap_mode = GEN7_TEXCOORDMODE_CLAMP_BORDER;
+               sampler_state->ss3.t_wrap_mode = GEN7_TEXCOORDMODE_CLAMP_BORDER;
+               break;
+       case SAMPLER_EXTEND_REPEAT:
+               sampler_state->ss3.r_wrap_mode = GEN7_TEXCOORDMODE_WRAP;
+               sampler_state->ss3.s_wrap_mode = GEN7_TEXCOORDMODE_WRAP;
+               sampler_state->ss3.t_wrap_mode = GEN7_TEXCOORDMODE_WRAP;
+               break;
+       case SAMPLER_EXTEND_PAD:
+               sampler_state->ss3.r_wrap_mode = GEN7_TEXCOORDMODE_CLAMP;
+               sampler_state->ss3.s_wrap_mode = GEN7_TEXCOORDMODE_CLAMP;
+               sampler_state->ss3.t_wrap_mode = GEN7_TEXCOORDMODE_CLAMP;
+               break;
+       case SAMPLER_EXTEND_REFLECT:
+               sampler_state->ss3.r_wrap_mode = GEN7_TEXCOORDMODE_MIRROR;
+               sampler_state->ss3.s_wrap_mode = GEN7_TEXCOORDMODE_MIRROR;
+               sampler_state->ss3.t_wrap_mode = GEN7_TEXCOORDMODE_MIRROR;
+               break;
+       }
+}
+
+static void
+sampler_copy_init(struct gen7_sampler_state *ss)
+{
+       sampler_state_init(ss, SAMPLER_FILTER_NEAREST, SAMPLER_EXTEND_NONE);
+       ss->ss3.non_normalized_coord = 1;
+
+       sampler_state_init(ss+1, SAMPLER_FILTER_NEAREST, SAMPLER_EXTEND_NONE);
+}
+
+static void
+sampler_fill_init(struct gen7_sampler_state *ss)
+{
+       sampler_state_init(ss, SAMPLER_FILTER_NEAREST, SAMPLER_EXTEND_REPEAT);
+       ss->ss3.non_normalized_coord = 1;
+
+       sampler_state_init(ss+1, SAMPLER_FILTER_NEAREST, SAMPLER_EXTEND_NONE);
+}
+
+static uint32_t gen7_create_cc_viewport(struct sna_static_stream *stream)
+{
+       struct gen7_cc_viewport vp;
+
+       vp.min_depth = -1.e35;
+       vp.max_depth = 1.e35;
+
+       return sna_static_stream_add(stream, &vp, sizeof(vp), 32);
+}
+
+static uint32_t
+gen7_tiling_bits(uint32_t tiling)
+{
+       switch (tiling) {
+       default: assert(0);
+       case I915_TILING_NONE: return 0;
+       case I915_TILING_X: return GEN7_SURFACE_TILED;
+       case I915_TILING_Y: return GEN7_SURFACE_TILED | GEN7_SURFACE_TILED_Y;
+       }
+}
+
+/**
+ * Sets up the common fields for a surface state buffer for the given
+ * picture in the given surface state buffer.
+ */
+static uint32_t
+gen7_bind_bo(struct sna *sna,
+            struct kgem_bo *bo,
+            uint32_t width,
+            uint32_t height,
+            uint32_t format,
+            bool is_dst)
+{
+       uint32_t *ss;
+       uint32_t domains;
+       int offset;
+
+       COMPILE_TIME_ASSERT(sizeof(struct gen7_surface_state) == 32);
+
+       /* After the first bind, we manage the cache domains within the batch */
+       offset = kgem_bo_get_binding(bo, format);
+       if (offset) {
+               if (is_dst)
+                       kgem_bo_mark_dirty(bo);
+               return offset * sizeof(uint32_t);
+       }
+
+       offset = sna->kgem.surface -=
+               sizeof(struct gen7_surface_state) / sizeof(uint32_t);
+       ss = sna->kgem.batch + offset;
+       ss[0] = (GEN7_SURFACE_2D << GEN7_SURFACE_TYPE_SHIFT |
+                gen7_tiling_bits(bo->tiling) |
+                format << GEN7_SURFACE_FORMAT_SHIFT);
+       if (is_dst)
+               domains = I915_GEM_DOMAIN_RENDER << 16 |I915_GEM_DOMAIN_RENDER;
+       else
+               domains = I915_GEM_DOMAIN_SAMPLER << 16;
+       ss[1] = kgem_add_reloc(&sna->kgem, offset + 1, bo, domains, 0);
+       ss[2] = ((width - 1)  << GEN7_SURFACE_WIDTH_SHIFT |
+                (height - 1) << GEN7_SURFACE_HEIGHT_SHIFT);
+       ss[3] = (bo->pitch - 1) << GEN7_SURFACE_PITCH_SHIFT;
+       ss[4] = 0;
+       ss[5] = 0;
+       ss[6] = 0;
+       ss[7] = 0;
+       if (sna->kgem.gen == 75)
+               ss[7] |= HSW_SURFACE_SWIZZLE(RED, GREEN, BLUE, ALPHA);
+
+       kgem_bo_set_binding(bo, format, offset);
+
+       DBG(("[%x] bind bo(handle=%d, addr=%d), format=%d, width=%d, height=%d, pitch=%d, tiling=%d -> %s\n",
+            offset, bo->handle, ss[1],
+            format, width, height, bo->pitch, bo->tiling,
+            domains & 0xffff ? "render" : "sampler"));
+
+       return offset * sizeof(uint32_t);
+}
+
+fastcall static void
+gen7_emit_composite_primitive_solid(struct sna *sna,
+                                   const struct sna_composite_op *op,
+                                   const struct sna_composite_rectangles *r)
+{
+       float *v;
+       union {
+               struct sna_coordinate p;
+               float f;
+       } dst;
+
+       v = sna->render.vertices + sna->render.vertex_used;
+       sna->render.vertex_used += 9;
+       assert(sna->render.vertex_used <= sna->render.vertex_size);
+       assert(!too_large(op->dst.x + r->dst.x + r->width,
+                         op->dst.y + r->dst.y + r->height));
+
+       dst.p.x = r->dst.x + r->width;
+       dst.p.y = r->dst.y + r->height;
+       v[0] = dst.f;
+       dst.p.x = r->dst.x;
+       v[3] = dst.f;
+       dst.p.y = r->dst.y;
+       v[6] = dst.f;
+
+       v[5] = v[2] = v[1] = 1.;
+       v[8] = v[7] = v[4] = 0.;
+}
+
+fastcall static void
+gen7_emit_composite_primitive_identity_source(struct sna *sna,
+                                             const struct sna_composite_op *op,
+                                             const struct sna_composite_rectangles *r)
+{
+       union {
+               struct sna_coordinate p;
+               float f;
+       } dst;
+       float *v;
+
+       v = sna->render.vertices + sna->render.vertex_used;
+       sna->render.vertex_used += 9;
+
+       dst.p.x = r->dst.x + r->width;
+       dst.p.y = r->dst.y + r->height;
+       v[0] = dst.f;
+       dst.p.x = r->dst.x;
+       v[3] = dst.f;
+       dst.p.y = r->dst.y;
+       v[6] = dst.f;
+
+       v[7] = v[4] = (r->src.x + op->src.offset[0]) * op->src.scale[0];
+       v[1] = v[4] + r->width * op->src.scale[0];
+
+       v[8] = (r->src.y + op->src.offset[1]) * op->src.scale[1];
+       v[5] = v[2] = v[8] + r->height * op->src.scale[1];
+}
+
+fastcall static void
+gen7_emit_composite_primitive_simple_source(struct sna *sna,
+                                           const struct sna_composite_op *op,
+                                           const struct sna_composite_rectangles *r)
+{
+       float *v;
+       union {
+               struct sna_coordinate p;
+               float f;
+       } dst;
+
+       float xx = op->src.transform->matrix[0][0];
+       float x0 = op->src.transform->matrix[0][2];
+       float yy = op->src.transform->matrix[1][1];
+       float y0 = op->src.transform->matrix[1][2];
+       float sx = op->src.scale[0];
+       float sy = op->src.scale[1];
+       int16_t tx = op->src.offset[0];
+       int16_t ty = op->src.offset[1];
+
+       v = sna->render.vertices + sna->render.vertex_used;
+       sna->render.vertex_used += 3*3;
+
+       dst.p.x = r->dst.x + r->width;
+       dst.p.y = r->dst.y + r->height;
+       v[0] = dst.f;
+       v[1] = ((r->src.x + r->width + tx) * xx + x0) * sx;
+       v[5] = v[2] = ((r->src.y + r->height + ty) * yy + y0) * sy;
+
+       dst.p.x = r->dst.x;
+       v[3] = dst.f;
+       v[7] = v[4] = ((r->src.x + tx) * xx + x0) * sx;
+
+       dst.p.y = r->dst.y;
+       v[6] = dst.f;
+       v[8] = ((r->src.y + ty) * yy + y0) * sy;
+}
+
+fastcall static void
+gen7_emit_composite_primitive_affine_source(struct sna *sna,
+                                           const struct sna_composite_op *op,
+                                           const struct sna_composite_rectangles *r)
+{
+       union {
+               struct sna_coordinate p;
+               float f;
+       } dst;
+       float *v;
+
+       v = sna->render.vertices + sna->render.vertex_used;
+       sna->render.vertex_used += 9;
+
+       dst.p.x = r->dst.x + r->width;
+       dst.p.y = r->dst.y + r->height;
+       v[0] = dst.f;
+       _sna_get_transformed_coordinates(op->src.offset[0] + r->src.x + r->width,
+                                        op->src.offset[1] + r->src.y + r->height,
+                                        op->src.transform,
+                                        &v[1], &v[2]);
+       v[1] *= op->src.scale[0];
+       v[2] *= op->src.scale[1];
+
+       dst.p.x = r->dst.x;
+       v[3] = dst.f;
+       _sna_get_transformed_coordinates(op->src.offset[0] + r->src.x,
+                                        op->src.offset[1] + r->src.y + r->height,
+                                        op->src.transform,
+                                        &v[4], &v[5]);
+       v[4] *= op->src.scale[0];
+       v[5] *= op->src.scale[1];
+
+       dst.p.y = r->dst.y;
+       v[6] = dst.f;
+       _sna_get_transformed_coordinates(op->src.offset[0] + r->src.x,
+                                        op->src.offset[1] + r->src.y,
+                                        op->src.transform,
+                                        &v[7], &v[8]);
+       v[7] *= op->src.scale[0];
+       v[8] *= op->src.scale[1];
+}
+
+fastcall static void
+gen7_emit_composite_primitive_identity_source_mask(struct sna *sna,
+                                                  const struct sna_composite_op *op,
+                                                  const struct sna_composite_rectangles *r)
+{
+       union {
+               struct sna_coordinate p;
+               float f;
+       } dst;
+       float src_x, src_y;
+       float msk_x, msk_y;
+       float w, h;
+       float *v;
+
+       src_x = r->src.x + op->src.offset[0];
+       src_y = r->src.y + op->src.offset[1];
+       msk_x = r->mask.x + op->mask.offset[0];
+       msk_y = r->mask.y + op->mask.offset[1];
+       w = r->width;
+       h = r->height;
+
+       v = sna->render.vertices + sna->render.vertex_used;
+       sna->render.vertex_used += 15;
+
+       dst.p.x = r->dst.x + r->width;
+       dst.p.y = r->dst.y + r->height;
+       v[0] = dst.f;
+       v[1] = (src_x + w) * op->src.scale[0];
+       v[2] = (src_y + h) * op->src.scale[1];
+       v[3] = (msk_x + w) * op->mask.scale[0];
+       v[4] = (msk_y + h) * op->mask.scale[1];
+
+       dst.p.x = r->dst.x;
+       v[5] = dst.f;
+       v[6] = src_x * op->src.scale[0];
+       v[7] = v[2];
+       v[8] = msk_x * op->mask.scale[0];
+       v[9] = v[4];
+
+       dst.p.y = r->dst.y;
+       v[10] = dst.f;
+       v[11] = v[6];
+       v[12] = src_y * op->src.scale[1];
+       v[13] = v[8];
+       v[14] = msk_y * op->mask.scale[1];
+}
+
+inline static void
+gen7_emit_composite_texcoord(struct sna *sna,
+                            const struct sna_composite_channel *channel,
+                            int16_t x, int16_t y)
+{
+       x += channel->offset[0];
+       y += channel->offset[1];
+
+       if (channel->is_affine) {
+               float s, t;
+
+               sna_get_transformed_coordinates(x, y,
+                                               channel->transform,
+                                               &s, &t);
+               OUT_VERTEX_F(s * channel->scale[0]);
+               OUT_VERTEX_F(t * channel->scale[1]);
+       } else {
+               float s, t, w;
+
+               sna_get_transformed_coordinates_3d(x, y,
+                                                  channel->transform,
+                                                  &s, &t, &w);
+               OUT_VERTEX_F(s * channel->scale[0]);
+               OUT_VERTEX_F(t * channel->scale[1]);
+               OUT_VERTEX_F(w);
+       }
+}
+
+static void
+gen7_emit_composite_vertex(struct sna *sna,
+                          const struct sna_composite_op *op,
+                          int16_t srcX, int16_t srcY,
+                          int16_t mskX, int16_t mskY,
+                          int16_t dstX, int16_t dstY)
+{
+       OUT_VERTEX(dstX, dstY);
+       gen7_emit_composite_texcoord(sna, &op->src, srcX, srcY);
+       gen7_emit_composite_texcoord(sna, &op->mask, mskX, mskY);
+}
+
+fastcall static void
+gen7_emit_composite_primitive(struct sna *sna,
+                             const struct sna_composite_op *op,
+                             const struct sna_composite_rectangles *r)
+{
+       gen7_emit_composite_vertex(sna, op,
+                                  r->src.x + r->width,  r->src.y + r->height,
+                                  r->mask.x + r->width, r->mask.y + r->height,
+                                  r->dst.x + r->width, r->dst.y + r->height);
+       gen7_emit_composite_vertex(sna, op,
+                                  r->src.x,  r->src.y + r->height,
+                                  r->mask.x, r->mask.y + r->height,
+                                  r->dst.x,  r->dst.y + r->height);
+       gen7_emit_composite_vertex(sna, op,
+                                  r->src.x,  r->src.y,
+                                  r->mask.x, r->mask.y,
+                                  r->dst.x,  r->dst.y);
+}
+
+static void gen7_emit_vertex_buffer(struct sna *sna,
+                                   const struct sna_composite_op *op)
+{
+       int id = GEN7_VERTEX(op->u.gen7.flags);
+
+       OUT_BATCH(GEN7_3DSTATE_VERTEX_BUFFERS | (5 - 2));
+       OUT_BATCH(id << GEN7_VB0_BUFFER_INDEX_SHIFT |
+                 GEN7_VB0_VERTEXDATA |
+                 GEN7_VB0_ADDRESS_MODIFY_ENABLE |
+                 4*op->floats_per_vertex << GEN7_VB0_BUFFER_PITCH_SHIFT);
+       sna->render.vertex_reloc[sna->render.nvertex_reloc++] = sna->kgem.nbatch;
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+       OUT_BATCH(0);
+
+       sna->render_state.gen7.vb_id |= 1 << id;
+}
+
+static void gen7_emit_primitive(struct sna *sna)
+{
+       if (sna->kgem.nbatch == sna->render_state.gen7.last_primitive) {
+               sna->render_state.gen7.vertex_offset = sna->kgem.nbatch - 5;
+               return;
+       }
+
+       OUT_BATCH(GEN7_3DPRIMITIVE | (7- 2));
+       OUT_BATCH(GEN7_3DPRIMITIVE_VERTEX_SEQUENTIAL | _3DPRIM_RECTLIST);
+       sna->render_state.gen7.vertex_offset = sna->kgem.nbatch;
+       OUT_BATCH(0);   /* vertex count, to be filled in later */
+       OUT_BATCH(sna->render.vertex_index);
+       OUT_BATCH(1);   /* single instance */
+       OUT_BATCH(0);   /* start instance location */
+       OUT_BATCH(0);   /* index buffer offset, ignored */
+       sna->render.vertex_start = sna->render.vertex_index;
+
+       sna->render_state.gen7.last_primitive = sna->kgem.nbatch;
+}
+
+static bool gen7_rectangle_begin(struct sna *sna,
+                                const struct sna_composite_op *op)
+{
+       int id = 1 << GEN7_VERTEX(op->u.gen7.flags);
+       int ndwords;
+
+       ndwords = op->need_magic_ca_pass ? 60 : 6;
+       if ((sna->render_state.gen7.vb_id & id) == 0)
+               ndwords += 5;
+       if (!kgem_check_batch(&sna->kgem, ndwords))
+               return false;
+
+       if ((sna->render_state.gen7.vb_id & id) == 0)
+               gen7_emit_vertex_buffer(sna, op);
+
+       gen7_emit_primitive(sna);
+       return true;
+}
+
+static int gen7_get_rectangles__flush(struct sna *sna,
+                                     const struct sna_composite_op *op)
+{
+       if (!kgem_check_batch(&sna->kgem, op->need_magic_ca_pass ? 65 : 6))
+               return 0;
+       if (!kgem_check_exec(&sna->kgem, 1))
+               return 0;
+       if (!kgem_check_reloc(&sna->kgem, 2))
+               return 0;
+
+       if (op->need_magic_ca_pass && sna->render.vbo)
+               return 0;
+
+       return gen7_vertex_finish(sna);
+}
+
+inline static int gen7_get_rectangles(struct sna *sna,
+                                     const struct sna_composite_op *op,
+                                     int want,
+                                     void (*emit_state)(struct sna *sna, const struct sna_composite_op *op))
+{
+       int rem;
+
+start:
+       rem = vertex_space(sna);
+       if (rem < op->floats_per_rect) {
+               DBG(("flushing vbo for %s: %d < %d\n",
+                    __FUNCTION__, rem, op->floats_per_rect));
+               rem = gen7_get_rectangles__flush(sna, op);
+               if (unlikely(rem == 0))
+                       goto flush;
+       }
+
+       if (unlikely(sna->render_state.gen7.vertex_offset == 0 &&
+                    !gen7_rectangle_begin(sna, op)))
+               goto flush;
+
+       if (want > 1 && want * op->floats_per_rect > rem)
+               want = rem / op->floats_per_rect;
+
+       assert(want > 0);
+       sna->render.vertex_index += 3*want;
+       return want;
+
+flush:
+       if (sna->render_state.gen7.vertex_offset) {
+               gen7_vertex_flush(sna);
+               gen7_magic_ca_pass(sna, op);
+       }
+       _kgem_submit(&sna->kgem);
+       emit_state(sna, op);
+       goto start;
+}
+
+inline static uint32_t *gen7_composite_get_binding_table(struct sna *sna,
+                                                        uint16_t *offset)
+{
+       uint32_t *table;
+
+       sna->kgem.surface -=
+               sizeof(struct gen7_surface_state) / sizeof(uint32_t);
+       /* Clear all surplus entries to zero in case of prefetch */
+       table = memset(sna->kgem.batch + sna->kgem.surface,
+                      0, sizeof(struct gen7_surface_state));
+
+       DBG(("%s(%x)\n", __FUNCTION__, 4*sna->kgem.surface));
+
+       *offset = sna->kgem.surface;
+       return table;
+}
+
+static uint32_t
+gen7_choose_composite_vertex_buffer(const struct sna_composite_op *op)
+{
+       int id = 2 + !op->is_affine;
+       if (op->mask.bo)
+               id |= id << 2;
+       assert(id > 0 && id < 16);
+       return id;
+}
+
+static void
+gen7_get_batch(struct sna *sna)
+{
+       kgem_set_mode(&sna->kgem, KGEM_RENDER);
+
+       if (!kgem_check_batch_with_surfaces(&sna->kgem, 150, 4)) {
+               DBG(("%s: flushing batch: %d < %d+%d\n",
+                    __FUNCTION__, sna->kgem.surface - sna->kgem.nbatch,
+                    150, 4*8));
+               _kgem_submit(&sna->kgem);
+               _kgem_set_mode(&sna->kgem, KGEM_RENDER);
+       }
+
+       assert(sna->kgem.mode == KGEM_RENDER);
+       assert(sna->kgem.ring == KGEM_RENDER);
+
+       if (sna->render_state.gen7.needs_invariant)
+               gen7_emit_invariant(sna);
+}
+
+static void gen7_emit_composite_state(struct sna *sna,
+                                     const struct sna_composite_op *op)
+{
+       uint32_t *binding_table;
+       uint16_t offset;
+
+       gen7_get_batch(sna);
+
+       binding_table = gen7_composite_get_binding_table(sna, &offset);
+
+       binding_table[0] =
+               gen7_bind_bo(sna,
+                           op->dst.bo, op->dst.width, op->dst.height,
+                           gen7_get_dest_format(op->dst.format),
+                           true);
+       binding_table[1] =
+               gen7_bind_bo(sna,
+                            op->src.bo, op->src.width, op->src.height,
+                            op->src.card_format,
+                            false);
+       if (op->mask.bo) {
+               binding_table[2] =
+                       gen7_bind_bo(sna,
+                                    op->mask.bo,
+                                    op->mask.width,
+                                    op->mask.height,
+                                    op->mask.card_format,
+                                    false);
+       }
+
+       if (sna->kgem.surface == offset &&
+           *(uint64_t *)(sna->kgem.batch + sna->render_state.gen7.surface_table) == *(uint64_t*)binding_table &&
+           (op->mask.bo == NULL ||
+            sna->kgem.batch[sna->render_state.gen7.surface_table+2] == binding_table[2])) {
+               sna->kgem.surface += sizeof(struct gen7_surface_state) / sizeof(uint32_t);
+               offset = sna->render_state.gen7.surface_table;
+       }
+
+       gen7_emit_state(sna, op, offset);
+}
+
+static void
+gen7_align_vertex(struct sna *sna, const struct sna_composite_op *op)
+{
+       if (op->floats_per_vertex != sna->render_state.gen7.floats_per_vertex) {
+               if (sna->render.vertex_size - sna->render.vertex_used < 2*op->floats_per_rect)
+                       gen7_vertex_finish(sna);
+
+               DBG(("aligning vertex: was %d, now %d floats per vertex, %d->%d\n",
+                    sna->render_state.gen7.floats_per_vertex,
+                    op->floats_per_vertex,
+                    sna->render.vertex_index,
+                    (sna->render.vertex_used + op->floats_per_vertex - 1) / op->floats_per_vertex));
+               sna->render.vertex_index = (sna->render.vertex_used + op->floats_per_vertex - 1) / op->floats_per_vertex;
+               sna->render.vertex_used = sna->render.vertex_index * op->floats_per_vertex;
+               sna->render_state.gen7.floats_per_vertex = op->floats_per_vertex;
+       }
+}
+
+fastcall static void
+gen7_render_composite_blt(struct sna *sna,
+                         const struct sna_composite_op *op,
+                         const struct sna_composite_rectangles *r)
+{
+       gen7_get_rectangles(sna, op, 1, gen7_emit_composite_state);
+       op->prim_emit(sna, op, r);
+}
+
+fastcall static void
+gen7_render_composite_box(struct sna *sna,
+                         const struct sna_composite_op *op,
+                         const BoxRec *box)
+{
+       struct sna_composite_rectangles r;
+
+       gen7_get_rectangles(sna, op, 1, gen7_emit_composite_state);
+
+       DBG(("  %s: (%d, %d), (%d, %d)\n",
+            __FUNCTION__,
+            box->x1, box->y1, box->x2, box->y2));
+
+       r.dst.x = box->x1;
+       r.dst.y = box->y1;
+       r.width  = box->x2 - box->x1;
+       r.height = box->y2 - box->y1;
+       r.src = r.mask = r.dst;
+
+       op->prim_emit(sna, op, &r);
+}
+
+static void
+gen7_render_composite_boxes(struct sna *sna,
+                           const struct sna_composite_op *op,
+                           const BoxRec *box, int nbox)
+{
+       DBG(("composite_boxes(%d)\n", nbox));
+
+       do {
+               int nbox_this_time;
+
+               nbox_this_time = gen7_get_rectangles(sna, op, nbox,
+                                                    gen7_emit_composite_state);
+               nbox -= nbox_this_time;
+
+               do {
+                       struct sna_composite_rectangles r;
+
+                       DBG(("  %s: (%d, %d), (%d, %d)\n",
+                            __FUNCTION__,
+                            box->x1, box->y1, box->x2, box->y2));
+
+                       r.dst.x = box->x1;
+                       r.dst.y = box->y1;
+                       r.width  = box->x2 - box->x1;
+                       r.height = box->y2 - box->y1;
+                       r.src = r.mask = r.dst;
+
+                       op->prim_emit(sna, op, &r);
+                       box++;
+               } while (--nbox_this_time);
+       } while (nbox);
+}
+
+#ifndef MAX
+#define MAX(a,b) ((a) > (b) ? (a) : (b))
+#endif
+
+static uint32_t
+gen7_composite_create_blend_state(struct sna_static_stream *stream)
+{
+       char *base, *ptr;
+       int src, dst;
+
+       base = sna_static_stream_map(stream,
+                                    GEN7_BLENDFACTOR_COUNT * GEN7_BLENDFACTOR_COUNT * GEN7_BLEND_STATE_PADDED_SIZE,
+                                    64);
+
+       ptr = base;
+       for (src = 0; src < GEN7_BLENDFACTOR_COUNT; src++) {
+               for (dst= 0; dst < GEN7_BLENDFACTOR_COUNT; dst++) {
+                       struct gen7_blend_state *blend =
+                               (struct gen7_blend_state *)ptr;
+
+                       blend->blend0.dest_blend_factor = dst;
+                       blend->blend0.source_blend_factor = src;
+                       blend->blend0.blend_func = GEN7_BLENDFUNCTION_ADD;
+                       blend->blend0.blend_enable =
+                               !(dst == GEN7_BLENDFACTOR_ZERO && src == GEN7_BLENDFACTOR_ONE);
+
+                       blend->blend1.post_blend_clamp_enable = 1;
+                       blend->blend1.pre_blend_clamp_enable = 1;
+
+                       ptr += GEN7_BLEND_STATE_PADDED_SIZE;
+               }
+       }
+
+       return sna_static_stream_offsetof(stream, base);
+}
+
+static uint32_t gen7_bind_video_source(struct sna *sna,
+                                      struct kgem_bo *src_bo,
+                                      uint32_t src_offset,
+                                      int src_width,
+                                      int src_height,
+                                      int src_pitch,
+                                      uint32_t src_surf_format)
+{
+       struct gen7_surface_state *ss;
+
+       sna->kgem.surface -= sizeof(struct gen7_surface_state) / sizeof(uint32_t);
+
+       ss = memset(sna->kgem.batch + sna->kgem.surface, 0, sizeof(*ss));
+       ss->ss0.surface_type = GEN7_SURFACE_2D;
+       ss->ss0.surface_format = src_surf_format;
+
+       ss->ss1.base_addr =
+               kgem_add_reloc(&sna->kgem,
+                              sna->kgem.surface + 1,
+                              src_bo,
+                              I915_GEM_DOMAIN_SAMPLER << 16,
+                              src_offset);
+
+       ss->ss2.width  = src_width - 1;
+       ss->ss2.height = src_height - 1;
+       ss->ss3.pitch  = src_pitch - 1;
+
+       return sna->kgem.surface * sizeof(uint32_t);
+}
+
+static void gen7_emit_video_state(struct sna *sna,
+                                 const struct sna_composite_op *op)
+{
+       struct sna_video_frame *frame = op->priv;
+       uint32_t src_surf_format;
+       uint32_t src_surf_base[6];
+       int src_width[6];
+       int src_height[6];
+       int src_pitch[6];
+       uint32_t *binding_table;
+       uint16_t offset;
+       int n_src, n;
+
+       gen7_get_batch(sna);
+
+       src_surf_base[0] = 0;
+       src_surf_base[1] = 0;
+       src_surf_base[2] = frame->VBufOffset;
+       src_surf_base[3] = frame->VBufOffset;
+       src_surf_base[4] = frame->UBufOffset;
+       src_surf_base[5] = frame->UBufOffset;
+
+       if (is_planar_fourcc(frame->id)) {
+               src_surf_format = GEN7_SURFACEFORMAT_R8_UNORM;
+               src_width[1]  = src_width[0]  = frame->width;
+               src_height[1] = src_height[0] = frame->height;
+               src_pitch[1]  = src_pitch[0]  = frame->pitch[1];
+               src_width[4]  = src_width[5]  = src_width[2]  = src_width[3] =
+                       frame->width / 2;
+               src_height[4] = src_height[5] = src_height[2] = src_height[3] =
+                       frame->height / 2;
+               src_pitch[4]  = src_pitch[5]  = src_pitch[2]  = src_pitch[3] =
+                       frame->pitch[0];
+               n_src = 6;
+       } else {
+               if (frame->id == FOURCC_UYVY)
+                       src_surf_format = GEN7_SURFACEFORMAT_YCRCB_SWAPY;
+               else
+                       src_surf_format = GEN7_SURFACEFORMAT_YCRCB_NORMAL;
+
+               src_width[0]  = frame->width;
+               src_height[0] = frame->height;
+               src_pitch[0]  = frame->pitch[0];
+               n_src = 1;
+       }
+
+       binding_table = gen7_composite_get_binding_table(sna, &offset);
+
+       binding_table[0] =
+               gen7_bind_bo(sna,
+                            op->dst.bo, op->dst.width, op->dst.height,
+                            gen7_get_dest_format(op->dst.format),
+                            true);
+       for (n = 0; n < n_src; n++) {
+               binding_table[1+n] =
+                       gen7_bind_video_source(sna,
+                                              frame->bo,
+                                              src_surf_base[n],
+                                              src_width[n],
+                                              src_height[n],
+                                              src_pitch[n],
+                                              src_surf_format);
+       }
+
+       gen7_emit_state(sna, op, offset);
+}
+
+static bool
+gen7_render_video(struct sna *sna,
+                 struct sna_video *video,
+                 struct sna_video_frame *frame,
+                 RegionPtr dstRegion,
+                 short src_w, short src_h,
+                 short drw_w, short drw_h,
+                 PixmapPtr pixmap)
+{
+       struct sna_composite_op tmp;
+       int nbox, dxo, dyo, pix_xoff, pix_yoff;
+       float src_scale_x, src_scale_y;
+       struct sna_pixmap *priv;
+       BoxPtr box;
+
+       DBG(("%s: src=(%d, %d), dst=(%d, %d), %dx[(%d, %d), (%d, %d)...]\n",
+            __FUNCTION__, src_w, src_h, drw_w, drw_h,
+            REGION_NUM_RECTS(dstRegion),
+            REGION_EXTENTS(NULL, dstRegion)->x1,
+            REGION_EXTENTS(NULL, dstRegion)->y1,
+            REGION_EXTENTS(NULL, dstRegion)->x2,
+            REGION_EXTENTS(NULL, dstRegion)->y2));
+
+       priv = sna_pixmap_force_to_gpu(pixmap, MOVE_READ | MOVE_WRITE);
+       if (priv == NULL)
+               return false;
+
+       memset(&tmp, 0, sizeof(tmp));
+
+       tmp.dst.pixmap = pixmap;
+       tmp.dst.width  = pixmap->drawable.width;
+       tmp.dst.height = pixmap->drawable.height;
+       tmp.dst.format = sna_render_format_for_depth(pixmap->drawable.depth);
+       tmp.dst.bo = priv->gpu_bo;
+
+       tmp.src.bo = frame->bo;
+       tmp.mask.bo = NULL;
+
+       tmp.floats_per_vertex = 3;
+       tmp.floats_per_rect = 9;
+
+       tmp.u.gen7.flags =
+               GEN7_SET_FLAGS(VIDEO_SAMPLER, NO_BLEND,
+                              is_planar_fourcc(frame->id) ?
+                              GEN7_WM_KERNEL_VIDEO_PLANAR :
+                              GEN7_WM_KERNEL_VIDEO_PACKED,
+                              2);
+       tmp.priv = frame;
+
+       kgem_set_mode(&sna->kgem, KGEM_RENDER);
+       if (!kgem_check_bo(&sna->kgem, tmp.dst.bo, frame->bo, NULL)) {
+               kgem_submit(&sna->kgem);
+               assert(kgem_check_bo(&sna->kgem, tmp.dst.bo, frame->bo, NULL));
+               _kgem_set_mode(&sna->kgem, KGEM_RENDER);
+       }
+
+       gen7_emit_video_state(sna, &tmp);
+       gen7_align_vertex(sna, &tmp);
+
+       /* Set up the offset for translating from the given region (in screen
+        * coordinates) to the backing pixmap.
+        */
+#ifdef COMPOSITE
+       pix_xoff = -pixmap->screen_x + pixmap->drawable.x;
+       pix_yoff = -pixmap->screen_y + pixmap->drawable.y;
+#else
+       pix_xoff = 0;
+       pix_yoff = 0;
+#endif
+
+       dxo = dstRegion->extents.x1;
+       dyo = dstRegion->extents.y1;
+
+       /* Use normalized texture coordinates */
+       src_scale_x = ((float)src_w / frame->width) / (float)drw_w;
+       src_scale_y = ((float)src_h / frame->height) / (float)drw_h;
+
+       box = REGION_RECTS(dstRegion);
+       nbox = REGION_NUM_RECTS(dstRegion);
+       while (nbox--) {
+               BoxRec r;
+
+               r.x1 = box->x1 + pix_xoff;
+               r.x2 = box->x2 + pix_xoff;
+               r.y1 = box->y1 + pix_yoff;
+               r.y2 = box->y2 + pix_yoff;
+
+               gen7_get_rectangles(sna, &tmp, 1, gen7_emit_video_state);
+
+               OUT_VERTEX(r.x2, r.y2);
+               OUT_VERTEX_F((box->x2 - dxo) * src_scale_x);
+               OUT_VERTEX_F((box->y2 - dyo) * src_scale_y);
+
+               OUT_VERTEX(r.x1, r.y2);
+               OUT_VERTEX_F((box->x1 - dxo) * src_scale_x);
+               OUT_VERTEX_F((box->y2 - dyo) * src_scale_y);
+
+               OUT_VERTEX(r.x1, r.y1);
+               OUT_VERTEX_F((box->x1 - dxo) * src_scale_x);
+               OUT_VERTEX_F((box->y1 - dyo) * src_scale_y);
+
+               if (!DAMAGE_IS_ALL(priv->gpu_damage)) {
+                       sna_damage_add_box(&priv->gpu_damage, &r);
+                       sna_damage_subtract_box(&priv->cpu_damage, &r);
+               }
+               box++;
+       }
+       priv->clear = false;
+
+       gen7_vertex_flush(sna);
+       return true;
+}
+
+static bool
+gen7_composite_solid_init(struct sna *sna,
+                         struct sna_composite_channel *channel,
+                         uint32_t color)
+{
+       DBG(("%s: color=%x\n", __FUNCTION__, color));
+
+       channel->filter = PictFilterNearest;
+       channel->repeat = RepeatNormal;
+       channel->is_affine = true;
+       channel->is_solid  = true;
+       channel->is_opaque = (color >> 24) == 0xff;
+       channel->transform = NULL;
+       channel->width  = 1;
+       channel->height = 1;
+       channel->card_format = GEN7_SURFACEFORMAT_B8G8R8A8_UNORM;
+
+       channel->bo = sna_render_get_solid(sna, color);
+
+       channel->scale[0]  = channel->scale[1]  = 1;
+       channel->offset[0] = channel->offset[1] = 0;
+       return channel->bo != NULL;
+}
+
+static bool
+gen7_composite_linear_init(struct sna *sna,
+                          PicturePtr picture,
+                          struct sna_composite_channel *channel,
+                          int x, int y,
+                          int w, int h,
+                          int dst_x, int dst_y)
+{
+       PictLinearGradient *linear =
+               (PictLinearGradient *)picture->pSourcePict;
+       pixman_fixed_t tx, ty;
+       float x0, y0, sf;
+       float dx, dy;
+
+       DBG(("%s: p1=(%f, %f), p2=(%f, %f), src=(%d, %d), dst=(%d, %d), size=(%d, %d)\n",
+            __FUNCTION__,
+            pixman_fixed_to_double(linear->p1.x), pixman_fixed_to_double(linear->p1.y),
+            pixman_fixed_to_double(linear->p2.x), pixman_fixed_to_double(linear->p2.y),
+            x, y, dst_x, dst_y, w, h));
+
+       if (linear->p2.x == linear->p1.x && linear->p2.y == linear->p1.y)
+               return 0;
+
+       if (!sna_transform_is_affine(picture->transform)) {
+               DBG(("%s: fallback due to projective transform\n",
+                    __FUNCTION__));
+               return sna_render_picture_fixup(sna, picture, channel,
+                                               x, y, w, h, dst_x, dst_y);
+       }
+
+       channel->bo = sna_render_get_gradient(sna, (PictGradient *)linear);
+       if (!channel->bo)
+               return 0;
+
+       channel->filter = PictFilterNearest;
+       channel->repeat = picture->repeat ? picture->repeatType : RepeatNone;
+       channel->width  = channel->bo->pitch / 4;
+       channel->height = 1;
+       channel->pict_format = PICT_a8r8g8b8;
+
+       channel->scale[0]  = channel->scale[1]  = 1;
+       channel->offset[0] = channel->offset[1] = 0;
+
+       if (sna_transform_is_translation(picture->transform, &tx, &ty)) {
+               dx = pixman_fixed_to_double(linear->p2.x - linear->p1.x);
+               dy = pixman_fixed_to_double(linear->p2.y - linear->p1.y);
+
+               x0 = pixman_fixed_to_double(linear->p1.x);
+               y0 = pixman_fixed_to_double(linear->p1.y);
+
+               if (tx | ty) {
+                       x0 -= pixman_fixed_to_double(tx);
+                       y0 -= pixman_fixed_to_double(ty);
+               }
+       } else {
+               struct pixman_f_vector p1, p2;
+               struct pixman_f_transform m, inv;
+
+               pixman_f_transform_from_pixman_transform(&m, picture->transform);
+               DBG(("%s: transform = [%f %f %f, %f %f %f, %f %f %f]\n",
+                    __FUNCTION__,
+                    m.m[0][0], m.m[0][1], m.m[0][2],
+                    m.m[1][0], m.m[1][1], m.m[1][2],
+                    m.m[2][0], m.m[2][1], m.m[2][2]));
+               if (!pixman_f_transform_invert(&inv, &m))
+                       return 0;
+
+               p1.v[0] = pixman_fixed_to_double(linear->p1.x);
+               p1.v[1] = pixman_fixed_to_double(linear->p1.y);
+               p1.v[2] = 1.;
+               pixman_f_transform_point(&inv, &p1);
+
+               p2.v[0] = pixman_fixed_to_double(linear->p2.x);
+               p2.v[1] = pixman_fixed_to_double(linear->p2.y);
+               p2.v[2] = 1.;
+               pixman_f_transform_point(&inv, &p2);
+
+               DBG(("%s: untransformed: p1=(%f, %f, %f), p2=(%f, %f, %f)\n",
+                    __FUNCTION__,
+                    p1.v[0], p1.v[1], p1.v[2],
+                    p2.v[0], p2.v[1], p2.v[2]));
+
+               dx = p2.v[0] - p1.v[0];
+               dy = p2.v[1] - p1.v[1];
+
+               x0 = p1.v[0];
+               y0 = p1.v[1];
+       }
+
+       sf = dx*dx + dy*dy;
+       dx /= sf;
+       dy /= sf;
+
+       channel->embedded_transform.matrix[0][0] = pixman_double_to_fixed(dx);
+       channel->embedded_transform.matrix[0][1] = pixman_double_to_fixed(dy);
+       channel->embedded_transform.matrix[0][2] = -pixman_double_to_fixed(dx*(x0+dst_x-x) + dy*(y0+dst_y-y));
+
+       channel->embedded_transform.matrix[1][0] = 0;
+       channel->embedded_transform.matrix[1][1] = 0;
+       channel->embedded_transform.matrix[1][2] = pixman_double_to_fixed(.5);
+
+       channel->embedded_transform.matrix[2][0] = 0;
+       channel->embedded_transform.matrix[2][1] = 0;
+       channel->embedded_transform.matrix[2][2] = pixman_fixed_1;
+
+       channel->transform = &channel->embedded_transform;
+       channel->is_affine = 1;
+
+       DBG(("%s: dx=%f, dy=%f, offset=%f\n",
+            __FUNCTION__, dx, dy, -dx*(x0-x+dst_x) + -dy*(y0-y+dst_y)));
+
+       return channel->bo != NULL;
+}
+
+static int
+gen7_composite_picture(struct sna *sna,
+                      PicturePtr picture,
+                      struct sna_composite_channel *channel,
+                      int x, int y,
+                      int w, int h,
+                      int dst_x, int dst_y,
+                      bool precise)
+{
+       PixmapPtr pixmap;
+       uint32_t color;
+       int16_t dx, dy;
+
+       DBG(("%s: (%d, %d)x(%d, %d), dst=(%d, %d)\n",
+            __FUNCTION__, x, y, w, h, dst_x, dst_y));
+
+       channel->is_solid = false;
+       channel->card_format = -1;
+
+       if (sna_picture_is_solid(picture, &color))
+               return gen7_composite_solid_init(sna, channel, color);
+
+       if (picture->pDrawable == NULL) {
+               int ret;
+
+               if (picture->pSourcePict->type == SourcePictTypeLinear)
+                       return gen7_composite_linear_init(sna, picture, channel,
+                                                         x, y,
+                                                         w, h,
+                                                         dst_x, dst_y);
+
+               DBG(("%s -- fixup, gradient\n", __FUNCTION__));
+               ret = -1;
+               if (!precise)
+                       ret = sna_render_picture_approximate_gradient(sna, picture, channel,
+                                                                     x, y, w, h, dst_x, dst_y);
+               if (ret == -1)
+                       ret = sna_render_picture_fixup(sna, picture, channel,
+                                                      x, y, w, h, dst_x, dst_y);
+               return ret;
+       }
+
+       if (picture->alphaMap) {
+               DBG(("%s -- fallback, alphamap\n", __FUNCTION__));
+               return sna_render_picture_fixup(sna, picture, channel,
+                                               x, y, w, h, dst_x, dst_y);
+       }
+
+       if (!gen7_check_repeat(picture))
+               return sna_render_picture_fixup(sna, picture, channel,
+                                               x, y, w, h, dst_x, dst_y);
+
+       if (!gen7_check_filter(picture))
+               return sna_render_picture_fixup(sna, picture, channel,
+                                               x, y, w, h, dst_x, dst_y);
+
+       channel->repeat = picture->repeat ? picture->repeatType : RepeatNone;
+       channel->filter = picture->filter;
+
+       pixmap = get_drawable_pixmap(picture->pDrawable);
+       get_drawable_deltas(picture->pDrawable, pixmap, &dx, &dy);
+
+       x += dx + picture->pDrawable->x;
+       y += dy + picture->pDrawable->y;
+
+       channel->is_affine = sna_transform_is_affine(picture->transform);
+       if (sna_transform_is_integer_translation(picture->transform, &dx, &dy)) {
+               DBG(("%s: integer translation (%d, %d), removing\n",
+                    __FUNCTION__, dx, dy));
+               x += dx;
+               y += dy;
+               channel->transform = NULL;
+               channel->filter = PictFilterNearest;
+       } else
+               channel->transform = picture->transform;
+
+       channel->pict_format = picture->format;
+       channel->card_format = gen7_get_card_format(picture->format);
+       if (channel->card_format == (unsigned)-1)
+               return sna_render_picture_convert(sna, picture, channel, pixmap,
+                                                 x, y, w, h, dst_x, dst_y);
+
+       if (too_large(pixmap->drawable.width, pixmap->drawable.height)) {
+               DBG(("%s: extracting from pixmap %dx%d\n", __FUNCTION__,
+                    pixmap->drawable.width, pixmap->drawable.height));
+               return sna_render_picture_extract(sna, picture, channel,
+                                                 x, y, w, h, dst_x, dst_y);
+       }
+
+       return sna_render_pixmap_bo(sna, channel, pixmap,
+                                   x, y, w, h, dst_x, dst_y);
+}
+
+static void gen7_composite_channel_convert(struct sna_composite_channel *channel)
+{
+       channel->repeat = gen7_repeat(channel->repeat);
+       channel->filter = gen7_filter(channel->filter);
+       if (channel->card_format == (unsigned)-1)
+               channel->card_format = gen7_get_card_format(channel->pict_format);
+       assert(channel->card_format != (unsigned)-1);
+}
+
+static void gen7_render_composite_done(struct sna *sna,
+                                      const struct sna_composite_op *op)
+{
+       if (sna->render_state.gen7.vertex_offset) {
+               gen7_vertex_flush(sna);
+               gen7_magic_ca_pass(sna, op);
+       }
+
+       if (op->mask.bo)
+               kgem_bo_destroy(&sna->kgem, op->mask.bo);
+       if (op->src.bo)
+               kgem_bo_destroy(&sna->kgem, op->src.bo);
+
+       sna_render_composite_redirect_done(sna, op);
+}
+
+static bool
+gen7_composite_set_target(struct sna *sna,
+                         struct sna_composite_op *op,
+                         PicturePtr dst,
+                         int x, int y, int w, int h)
+{
+       BoxRec box;
+
+       op->dst.pixmap = get_drawable_pixmap(dst->pDrawable);
+       op->dst.format = dst->format;
+       op->dst.width = op->dst.pixmap->drawable.width;
+       op->dst.height = op->dst.pixmap->drawable.height;
+
+       if (w && h) {
+               box.x1 = x;
+               box.y1 = y;
+               box.x2 = x + w;
+               box.y2 = y + h;
+       } else
+               sna_render_picture_extents(dst, &box);
+
+       op->dst.bo = sna_drawable_use_bo (dst->pDrawable,
+                                         PREFER_GPU | FORCE_GPU | RENDER_GPU,
+                                         &box, &op->damage);
+       if (op->dst.bo == NULL)
+               return false;
+
+       get_drawable_deltas(dst->pDrawable, op->dst.pixmap,
+                           &op->dst.x, &op->dst.y);
+
+       DBG(("%s: pixmap=%p, format=%08x, size=%dx%d, pitch=%d, delta=(%d,%d),damage=%p\n",
+            __FUNCTION__,
+            op->dst.pixmap, (int)op->dst.format,
+            op->dst.width, op->dst.height,
+            op->dst.bo->pitch,
+            op->dst.x, op->dst.y,
+            op->damage ? *op->damage : (void *)-1));
+
+       assert(op->dst.bo->proxy == NULL);
+
+       if (too_large(op->dst.width, op->dst.height) &&
+           !sna_render_composite_redirect(sna, op, x, y, w, h))
+               return false;
+
+       return true;
+}
+
+inline static bool can_switch_to_blt(struct sna *sna)
+{
+       if (sna->kgem.ring == KGEM_BLT)
+               return true;
+
+       if (NO_RING_SWITCH)
+               return false;
+
+       if (!sna->kgem.has_semaphores)
+               return false;
+
+       return sna->kgem.mode == KGEM_NONE || kgem_is_idle(&sna->kgem);
+}
+
+static inline bool untiled_tlb_miss(struct kgem_bo *bo)
+{
+       return bo->tiling == I915_TILING_NONE && bo->pitch >= 4096;
+}
+
+static bool prefer_blt_bo(struct sna *sna, struct kgem_bo *bo)
+{
+       return untiled_tlb_miss(bo) && bo->pitch < MAXSHORT;
+}
+
+inline static bool prefer_blt_ring(struct sna *sna)
+{
+       return sna->kgem.ring != KGEM_RENDER || can_switch_to_blt(sna);
+}
+
+static bool
+try_blt(struct sna *sna,
+       PicturePtr dst, PicturePtr src,
+       int width, int height)
+{
+       if (sna->kgem.ring == KGEM_BLT) {
+               DBG(("%s: already performing BLT\n", __FUNCTION__));
+               return true;
+       }
+
+       if (too_large(width, height)) {
+               DBG(("%s: operation too large for 3D pipe (%d, %d)\n",
+                    __FUNCTION__, width, height));
+               return true;
+       }
+
+       if (can_switch_to_blt(sna)) {
+               if (sna_picture_is_solid(src, NULL))
+                       return true;
+
+               if (dst->pDrawable == src->pDrawable)
+                       return true;
+
+               if (src->pDrawable &&
+                   get_drawable_pixmap(dst->pDrawable) == get_drawable_pixmap(src->pDrawable))
+                       return true;
+       }
+
+       return false;
+}
+
+static bool
+check_gradient(PicturePtr picture)
+{
+       if (picture->pDrawable)
+               return false;
+
+       switch (picture->pSourcePict->type) {
+       case SourcePictTypeSolidFill:
+       case SourcePictTypeLinear:
+               return false;
+       default:
+               return true;
+       }
+}
+
+static bool
+has_alphamap(PicturePtr p)
+{
+       return p->alphaMap != NULL;
+}
+
+static bool
+untransformed(PicturePtr p)
+{
+       return !p->transform || pixman_transform_is_int_translate(p->transform);
+}
+
+static bool
+need_upload(PicturePtr p)
+{
+       return p->pDrawable && unattached(p->pDrawable) && untransformed(p);
+}
+
+static bool
+source_is_busy(PixmapPtr pixmap)
+{
+       struct sna_pixmap *priv = sna_pixmap(pixmap);
+       if (priv == NULL || priv->clear)
+               return false;
+
+       if (priv->gpu_bo && kgem_bo_is_busy(priv->gpu_bo))
+               return true;
+
+       if (priv->cpu_bo && kgem_bo_is_busy(priv->cpu_bo))
+               return true;
+
+       return priv->gpu_damage && !priv->cpu_damage;
+}
+
+static bool
+source_fallback(PicturePtr p, PixmapPtr pixmap)
+{
+       if (sna_picture_is_solid(p, NULL))
+               return false;
+
+       if (p->pSourcePict)
+               return check_gradient(p);
+
+       if (!gen7_check_repeat(p) || !gen7_check_format(p->format))
+               return true;
+
+       if (pixmap && source_is_busy(pixmap))
+               return false;
+
+       return has_alphamap(p) || !gen7_check_filter(p) || need_upload(p);
+}
+
+static bool
+gen7_composite_fallback(struct sna *sna,
+                       PicturePtr src,
+                       PicturePtr mask,
+                       PicturePtr dst)
+{
+       struct sna_pixmap *priv;
+       PixmapPtr src_pixmap;
+       PixmapPtr mask_pixmap;
+       PixmapPtr dst_pixmap;
+       bool src_fallback, mask_fallback;
+
+       if (!gen7_check_dst_format(dst->format)) {
+               DBG(("%s: unknown destination format: %d\n",
+                    __FUNCTION__, dst->format));
+               return true;
+       }
+
+       dst_pixmap = get_drawable_pixmap(dst->pDrawable);
+
+       src_pixmap = src->pDrawable ? get_drawable_pixmap(src->pDrawable) : NULL;
+       src_fallback = source_fallback(src, src_pixmap);
+
+       if (mask) {
+               mask_pixmap = mask->pDrawable ? get_drawable_pixmap(mask->pDrawable) : NULL;
+               mask_fallback = source_fallback(mask, mask_pixmap);
+       } else {
+               mask_pixmap = NULL;
+               mask_fallback = false;
+       }
+
+       /* If we are using the destination as a source and need to
+        * readback in order to upload the source, do it all
+        * on the cpu.
+        */
+       if (src_pixmap == dst_pixmap && src_fallback) {
+               DBG(("%s: src is dst and will fallback\n",__FUNCTION__));
+               return true;
+       }
+       if (mask_pixmap == dst_pixmap && mask_fallback) {
+               DBG(("%s: mask is dst and will fallback\n",__FUNCTION__));
+               return true;
+       }
+
+       /* If anything is on the GPU, push everything out to the GPU */
+       priv = sna_pixmap(dst_pixmap);
+       if (priv &&
+           ((priv->gpu_damage && !priv->clear) ||
+            (priv->cpu_bo && kgem_bo_is_busy(priv->cpu_bo)))) {
+               DBG(("%s: dst is already on the GPU, try to use GPU\n",
+                    __FUNCTION__));
+               return false;
+       }
+
+       if (src_pixmap && !src_fallback) {
+               DBG(("%s: src is already on the GPU, try to use GPU\n",
+                    __FUNCTION__));
+               return false;
+       }
+       if (mask_pixmap && !mask_fallback) {
+               DBG(("%s: mask is already on the GPU, try to use GPU\n",
+                    __FUNCTION__));
+               return false;
+       }
+
+       /* However if the dst is not on the GPU and we need to
+        * render one of the sources using the CPU, we may
+        * as well do the entire operation in place onthe CPU.
+        */
+       if (src_fallback) {
+               DBG(("%s: dst is on the CPU and src will fallback\n",
+                    __FUNCTION__));
+               return true;
+       }
+
+       if (mask && mask_fallback) {
+               DBG(("%s: dst is on the CPU and mask will fallback\n",
+                    __FUNCTION__));
+               return true;
+       }
+
+       if (too_large(dst_pixmap->drawable.width,
+                     dst_pixmap->drawable.height) &&
+           (priv == NULL || DAMAGE_IS_ALL(priv->cpu_damage))) {
+               DBG(("%s: dst is on the CPU and too large\n", __FUNCTION__));
+               return true;
+       }
+
+       DBG(("%s: dst is not on the GPU and the operation should not fallback\n",
+            __FUNCTION__));
+       return false;
+}
+
+static int
+reuse_source(struct sna *sna,
+            PicturePtr src, struct sna_composite_channel *sc, int src_x, int src_y,
+            PicturePtr mask, struct sna_composite_channel *mc, int msk_x, int msk_y)
+{
+       uint32_t color;
+
+       if (src_x != msk_x || src_y != msk_y)
+               return false;
+
+       if (src == mask) {
+               DBG(("%s: mask is source\n", __FUNCTION__));
+               *mc = *sc;
+               mc->bo = kgem_bo_reference(mc->bo);
+               return true;
+       }
+
+       if (sna_picture_is_solid(mask, &color))
+               return gen7_composite_solid_init(sna, mc, color);
+
+       if (sc->is_solid)
+               return false;
+
+       if (src->pDrawable == NULL || mask->pDrawable != src->pDrawable)
+               return false;
+
+       DBG(("%s: mask reuses source drawable\n", __FUNCTION__));
+
+       if (!sna_transform_equal(src->transform, mask->transform))
+               return false;
+
+       if (!sna_picture_alphamap_equal(src, mask))
+               return false;
+
+       if (!gen7_check_repeat(mask))
+               return false;
+
+       if (!gen7_check_filter(mask))
+               return false;
+
+       if (!gen7_check_format(mask->format))
+               return false;
+
+       DBG(("%s: reusing source channel for mask with a twist\n",
+            __FUNCTION__));
+
+       *mc = *sc;
+       mc->repeat = gen7_repeat(mask->repeat ? mask->repeatType : RepeatNone);
+       mc->filter = gen7_filter(mask->filter);
+       mc->pict_format = mask->format;
+       mc->card_format = gen7_get_card_format(mask->format);
+       mc->bo = kgem_bo_reference(mc->bo);
+       return true;
+}
+
+static bool
+prefer_blt_composite(struct sna *sna, struct sna_composite_op *tmp)
+{
+       if (sna->kgem.ring == KGEM_BLT)
+               return true;
+
+       if (!prefer_blt_ring(sna))
+               return false;
+
+       return (prefer_blt_bo(sna, tmp->dst.bo) ||
+               prefer_blt_bo(sna, tmp->src.bo));
+}
+
+static bool
+gen7_render_composite(struct sna *sna,
+                     uint8_t op,
+                     PicturePtr src,
+                     PicturePtr mask,
+                     PicturePtr dst,
+                     int16_t src_x, int16_t src_y,
+                     int16_t msk_x, int16_t msk_y,
+                     int16_t dst_x, int16_t dst_y,
+                     int16_t width, int16_t height,
+                     struct sna_composite_op *tmp)
+{
+       if (op >= ARRAY_SIZE(gen7_blend_op))
+               return false;
+
+       DBG(("%s: %dx%d, current mode=%d\n", __FUNCTION__,
+            width, height, sna->kgem.ring));
+
+       if (mask == NULL &&
+           try_blt(sna, dst, src, width, height) &&
+           sna_blt_composite(sna, op,
+                             src, dst,
+                             src_x, src_y,
+                             dst_x, dst_y,
+                             width, height,
+                             tmp, false))
+               return true;
+
+       if (gen7_composite_fallback(sna, src, mask, dst))
+               return false;
+
+       if (need_tiling(sna, width, height))
+               return sna_tiling_composite(op, src, mask, dst,
+                                           src_x, src_y,
+                                           msk_x, msk_y,
+                                           dst_x, dst_y,
+                                           width, height,
+                                           tmp);
+
+       if (op == PictOpClear)
+               op = PictOpSrc;
+       tmp->op = op;
+       if (!gen7_composite_set_target(sna, tmp, dst,
+                                      dst_x, dst_y, width, height))
+               return false;
+
+       switch (gen7_composite_picture(sna, src, &tmp->src,
+                                      src_x, src_y,
+                                      width, height,
+                                      dst_x, dst_y,
+                                      dst->polyMode == PolyModePrecise)) {
+       case -1:
+               goto cleanup_dst;
+       case 0:
+               if (!gen7_composite_solid_init(sna, &tmp->src, 0))
+                       goto cleanup_dst;
+               /* fall through to fixup */
+       case 1:
+               /* Did we just switch rings to prepare the source? */
+               if (mask == NULL &&
+                   prefer_blt_composite(sna, tmp) &&
+                   sna_blt_composite__convert(sna,
+                                              dst_x, dst_y, width, height,
+                                              tmp))
+                       return true;
+
+               gen7_composite_channel_convert(&tmp->src);
+               break;
+       }
+
+       tmp->is_affine = tmp->src.is_affine;
+       tmp->has_component_alpha = false;
+       tmp->need_magic_ca_pass = false;
+
+       tmp->mask.bo = NULL;
+       tmp->mask.filter = SAMPLER_FILTER_NEAREST;
+       tmp->mask.repeat = SAMPLER_EXTEND_NONE;
+
+       tmp->prim_emit = gen7_emit_composite_primitive;
+       if (mask) {
+               if (mask->componentAlpha && PICT_FORMAT_RGB(mask->format)) {
+                       tmp->has_component_alpha = true;
+
+                       /* Check if it's component alpha that relies on a source alpha and on
+                        * the source value.  We can only get one of those into the single
+                        * source value that we get to blend with.
+                        */
+                       if (gen7_blend_op[op].src_alpha &&
+                           (gen7_blend_op[op].src_blend != GEN7_BLENDFACTOR_ZERO)) {
+                               if (op != PictOpOver)
+                                       goto cleanup_src;
+
+                               tmp->need_magic_ca_pass = true;
+                               tmp->op = PictOpOutReverse;
+                       }
+               }
+
+               if (!reuse_source(sna,
+                                 src, &tmp->src, src_x, src_y,
+                                 mask, &tmp->mask, msk_x, msk_y)) {
+                       switch (gen7_composite_picture(sna, mask, &tmp->mask,
+                                                      msk_x, msk_y,
+                                                      width, height,
+                                                      dst_x, dst_y,
+                                                      dst->polyMode == PolyModePrecise)) {
+                       case -1:
+                               goto cleanup_src;
+                       case 0:
+                               if (!gen7_composite_solid_init(sna, &tmp->mask, 0))
+                                       goto cleanup_src;
+                               /* fall through to fixup */
+                       case 1:
+                               gen7_composite_channel_convert(&tmp->mask);
+                               break;
+                       }
+               }
+
+               tmp->is_affine &= tmp->mask.is_affine;
+
+               if (tmp->src.transform == NULL && tmp->mask.transform == NULL)
+                       tmp->prim_emit = gen7_emit_composite_primitive_identity_source_mask;
+
+               tmp->floats_per_vertex = 5 + 2 * !tmp->is_affine;
+       } else {
+               if (tmp->src.is_solid) {
+                       tmp->prim_emit = gen7_emit_composite_primitive_solid;
+                       if (tmp->src.is_opaque && op == PictOpOver)
+                               tmp->op = PictOpSrc;
+               } else if (tmp->src.transform == NULL)
+                       tmp->prim_emit = gen7_emit_composite_primitive_identity_source;
+               else if (tmp->src.is_affine) {
+                       if (tmp->src.transform->matrix[0][1] == 0 &&
+                           tmp->src.transform->matrix[1][0] == 0) {
+                               tmp->src.scale[0] /= tmp->src.transform->matrix[2][2];
+                               tmp->src.scale[1] /= tmp->src.transform->matrix[2][2];
+                               tmp->prim_emit = gen7_emit_composite_primitive_simple_source;
+                       } else
+                               tmp->prim_emit = gen7_emit_composite_primitive_affine_source;
+               }
+
+               tmp->floats_per_vertex = 3 + !tmp->is_affine;
+       }
+       tmp->floats_per_rect = 3 * tmp->floats_per_vertex;
+
+       tmp->u.gen7.flags =
+               GEN7_SET_FLAGS(SAMPLER_OFFSET(tmp->src.filter,
+                                             tmp->src.repeat,
+                                             tmp->mask.filter,
+                                             tmp->mask.repeat),
+                              gen7_get_blend(tmp->op,
+                                             tmp->has_component_alpha,
+                                             tmp->dst.format),
+                              gen7_choose_composite_kernel(tmp->op,
+                                                           tmp->mask.bo != NULL,
+                                                           tmp->has_component_alpha,
+                                                           tmp->is_affine),
+                              gen7_choose_composite_vertex_buffer(tmp));
+
+       tmp->blt   = gen7_render_composite_blt;
+       tmp->box   = gen7_render_composite_box;
+       tmp->boxes = gen7_render_composite_boxes;
+       tmp->done  = gen7_render_composite_done;
+
+       kgem_set_mode(&sna->kgem, KGEM_RENDER);
+       if (!kgem_check_bo(&sna->kgem,
+                          tmp->dst.bo, tmp->src.bo, tmp->mask.bo,
+                          NULL)) {
+               kgem_submit(&sna->kgem);
+               if (!kgem_check_bo(&sna->kgem,
+                                  tmp->dst.bo, tmp->src.bo, tmp->mask.bo,
+                                  NULL))
+                       goto cleanup_mask;
+               _kgem_set_mode(&sna->kgem, KGEM_RENDER);
+       }
+
+       gen7_emit_composite_state(sna, tmp);
+       gen7_align_vertex(sna, tmp);
+       return true;
+
+cleanup_mask:
+       if (tmp->mask.bo)
+               kgem_bo_destroy(&sna->kgem, tmp->mask.bo);
+cleanup_src:
+       if (tmp->src.bo)
+               kgem_bo_destroy(&sna->kgem, tmp->src.bo);
+cleanup_dst:
+       if (tmp->redirect.real_bo)
+               kgem_bo_destroy(&sna->kgem, tmp->dst.bo);
+       return false;
+}
+
+#if !NO_COMPOSITE_SPANS
+inline static void
+gen7_emit_composite_texcoord_affine(struct sna *sna,
+                                   const struct sna_composite_channel *channel,
+                                   int16_t x, int16_t y)
+{
+       float t[2];
+
+       sna_get_transformed_coordinates(x + channel->offset[0],
+                                       y + channel->offset[1],
+                                       channel->transform,
+                                       &t[0], &t[1]);
+       OUT_VERTEX_F(t[0] * channel->scale[0]);
+       OUT_VERTEX_F(t[1] * channel->scale[1]);
+}
+
+inline static void
+gen7_emit_composite_spans_vertex(struct sna *sna,
+                                const struct sna_composite_spans_op *op,
+                                int16_t x, int16_t y)
+{
+       OUT_VERTEX(x, y);
+       gen7_emit_composite_texcoord(sna, &op->base.src, x, y);
+}
+
+fastcall static void
+gen7_emit_composite_spans_primitive(struct sna *sna,
+                                   const struct sna_composite_spans_op *op,
+                                   const BoxRec *box,
+                                   float opacity)
+{
+       gen7_emit_composite_spans_vertex(sna, op, box->x2, box->y2);
+       OUT_VERTEX_F(opacity);
+
+       gen7_emit_composite_spans_vertex(sna, op, box->x1, box->y2);
+       OUT_VERTEX_F(opacity);
+
+       gen7_emit_composite_spans_vertex(sna, op, box->x1, box->y1);
+       OUT_VERTEX_F(opacity);
+}
+
+fastcall static void
+gen7_emit_composite_spans_solid(struct sna *sna,
+                               const struct sna_composite_spans_op *op,
+                               const BoxRec *box,
+                               float opacity)
+{
+       OUT_VERTEX(box->x2, box->y2);
+       OUT_VERTEX_F(1); OUT_VERTEX_F(1);
+       OUT_VERTEX_F(opacity);
+
+       OUT_VERTEX(box->x1, box->y2);
+       OUT_VERTEX_F(0); OUT_VERTEX_F(1);
+       OUT_VERTEX_F(opacity);
+
+       OUT_VERTEX(box->x1, box->y1);
+       OUT_VERTEX_F(0); OUT_VERTEX_F(0);
+       OUT_VERTEX_F(opacity);
+}
+
+fastcall static void
+gen7_emit_composite_spans_identity(struct sna *sna,
+                                  const struct sna_composite_spans_op *op,
+                                  const BoxRec *box,
+                                  float opacity)
+{
+       float *v;
+       union {
+               struct sna_coordinate p;
+               float f;
+       } dst;
+
+       float sx = op->base.src.scale[0];
+       float sy = op->base.src.scale[1];
+       int16_t tx = op->base.src.offset[0];
+       int16_t ty = op->base.src.offset[1];
+
+       v = sna->render.vertices + sna->render.vertex_used;
+       sna->render.vertex_used += 3*4;
+       assert(sna->render.vertex_used <= sna->render.vertex_size);
+
+       dst.p.x = box->x2;
+       dst.p.y = box->y2;
+       v[0] = dst.f;
+       v[1] = (box->x2 + tx) * sx;
+       v[6] = v[2] = (box->y2 + ty) * sy;
+
+       dst.p.x = box->x1;
+       v[4] = dst.f;
+       v[9] = v[5] = (box->x1 + tx) * sx;
+
+       dst.p.y = box->y1;
+       v[8] = dst.f;
+       v[10] = (box->y1 + ty) * sy;
+
+       v[11] = v[7] = v[3] = opacity;
+}
+
+fastcall static void
+gen7_emit_composite_spans_simple(struct sna *sna,
+                                const struct sna_composite_spans_op *op,
+                                const BoxRec *box,
+                                float opacity)
+{
+       float *v;
+       union {
+               struct sna_coordinate p;
+               float f;
+       } dst;
+
+       float xx = op->base.src.transform->matrix[0][0];
+       float x0 = op->base.src.transform->matrix[0][2];
+       float yy = op->base.src.transform->matrix[1][1];
+       float y0 = op->base.src.transform->matrix[1][2];
+       float sx = op->base.src.scale[0];
+       float sy = op->base.src.scale[1];
+       int16_t tx = op->base.src.offset[0];
+       int16_t ty = op->base.src.offset[1];
+
+       v = sna->render.vertices + sna->render.vertex_used;
+       sna->render.vertex_used += 3*4;
+       assert(sna->render.vertex_used <= sna->render.vertex_size);
+
+       dst.p.x = box->x2;
+       dst.p.y = box->y2;
+       v[0] = dst.f;
+       v[1] = ((box->x2 + tx) * xx + x0) * sx;
+       v[6] = v[2] = ((box->y2 + ty) * yy + y0) * sy;
+
+       dst.p.x = box->x1;
+       v[4] = dst.f;
+       v[9] = v[5] = ((box->x1 + tx) * xx + x0) * sx;
+
+       dst.p.y = box->y1;
+       v[8] = dst.f;
+       v[10] = ((box->y1 + ty) * yy + y0) * sy;
+
+       v[11] = v[7] = v[3] = opacity;
+}
+
+fastcall static void
+gen7_emit_composite_spans_affine(struct sna *sna,
+                                const struct sna_composite_spans_op *op,
+                                const BoxRec *box,
+                                float opacity)
+{
+       OUT_VERTEX(box->x2, box->y2);
+       gen7_emit_composite_texcoord_affine(sna, &op->base.src,
+                                           box->x2, box->y2);
+       OUT_VERTEX_F(opacity);
+
+       OUT_VERTEX(box->x1, box->y2);
+       gen7_emit_composite_texcoord_affine(sna, &op->base.src,
+                                           box->x1, box->y2);
+       OUT_VERTEX_F(opacity);
+
+       OUT_VERTEX(box->x1, box->y1);
+       gen7_emit_composite_texcoord_affine(sna, &op->base.src,
+                                           box->x1, box->y1);
+       OUT_VERTEX_F(opacity);
+}
+
+fastcall static void
+gen7_render_composite_spans_box(struct sna *sna,
+                               const struct sna_composite_spans_op *op,
+                               const BoxRec *box, float opacity)
+{
+       DBG(("%s: src=+(%d, %d), opacity=%f, dst=+(%d, %d), box=(%d, %d) x (%d, %d)\n",
+            __FUNCTION__,
+            op->base.src.offset[0], op->base.src.offset[1],
+            opacity,
+            op->base.dst.x, op->base.dst.y,
+            box->x1, box->y1,
+            box->x2 - box->x1,
+            box->y2 - box->y1));
+
+       gen7_get_rectangles(sna, &op->base, 1, gen7_emit_composite_state);
+       op->prim_emit(sna, op, box, opacity);
+}
+
+static void
+gen7_render_composite_spans_boxes(struct sna *sna,
+                                 const struct sna_composite_spans_op *op,
+                                 const BoxRec *box, int nbox,
+                                 float opacity)
+{
+       DBG(("%s: nbox=%d, src=+(%d, %d), opacity=%f, dst=+(%d, %d)\n",
+            __FUNCTION__, nbox,
+            op->base.src.offset[0], op->base.src.offset[1],
+            opacity,
+            op->base.dst.x, op->base.dst.y));
+
+       do {
+               int nbox_this_time;
+
+               nbox_this_time = gen7_get_rectangles(sna, &op->base, nbox,
+                                                    gen7_emit_composite_state);
+               nbox -= nbox_this_time;
+
+               do {
+                       DBG(("  %s: (%d, %d) x (%d, %d)\n", __FUNCTION__,
+                            box->x1, box->y1,
+                            box->x2 - box->x1,
+                            box->y2 - box->y1));
+
+                       op->prim_emit(sna, op, box++, opacity);
+               } while (--nbox_this_time);
+       } while (nbox);
+}
+
+fastcall static void
+gen7_render_composite_spans_done(struct sna *sna,
+                                const struct sna_composite_spans_op *op)
+{
+       if (sna->render_state.gen7.vertex_offset)
+               gen7_vertex_flush(sna);
+
+       DBG(("%s()\n", __FUNCTION__));
+
+       if (op->base.src.bo)
+               kgem_bo_destroy(&sna->kgem, op->base.src.bo);
+
+       sna_render_composite_redirect_done(sna, &op->base);
+}
+
+static bool
+gen7_check_composite_spans(struct sna *sna,
+                          uint8_t op, PicturePtr src, PicturePtr dst,
+                          int16_t width, int16_t height, unsigned flags)
+{
+       if (op >= ARRAY_SIZE(gen7_blend_op))
+               return false;
+
+       if (gen7_composite_fallback(sna, src, NULL, dst))
+               return false;
+
+       if (need_tiling(sna, width, height)) {
+               if (!is_gpu(dst->pDrawable)) {
+                       DBG(("%s: fallback, tiled operation not on GPU\n",
+                            __FUNCTION__));
+                       return false;
+               }
+       }
+
+       return true;
+}
+
+static bool
+gen7_render_composite_spans(struct sna *sna,
+                           uint8_t op,
+                           PicturePtr src,
+                           PicturePtr dst,
+                           int16_t src_x,  int16_t src_y,
+                           int16_t dst_x,  int16_t dst_y,
+                           int16_t width,  int16_t height,
+                           unsigned flags,
+                           struct sna_composite_spans_op *tmp)
+{
+       DBG(("%s: %dx%d with flags=%x, current mode=%d\n", __FUNCTION__,
+            width, height, flags, sna->kgem.ring));
+
+       assert(gen7_check_composite_spans(sna, op, src, dst, width, height, flags));
+
+       if (need_tiling(sna, width, height)) {
+               DBG(("%s: tiling, operation (%dx%d) too wide for pipeline\n",
+                    __FUNCTION__, width, height));
+               return sna_tiling_composite_spans(op, src, dst,
+                                                 src_x, src_y, dst_x, dst_y,
+                                                 width, height, flags, tmp);
+       }
+
+       tmp->base.op = op;
+       if (!gen7_composite_set_target(sna, &tmp->base, dst,
+                                      dst_x, dst_y, width, height))
+               return false;
+
+       switch (gen7_composite_picture(sna, src, &tmp->base.src,
+                                      src_x, src_y,
+                                      width, height,
+                                      dst_x, dst_y,
+                                      dst->polyMode == PolyModePrecise)) {
+       case -1:
+               goto cleanup_dst;
+       case 0:
+               if (!gen7_composite_solid_init(sna, &tmp->base.src, 0))
+                       goto cleanup_dst;
+               /* fall through to fixup */
+       case 1:
+               gen7_composite_channel_convert(&tmp->base.src);
+               break;
+       }
+       tmp->base.mask.bo = NULL;
+
+       tmp->base.is_affine = tmp->base.src.is_affine;
+       tmp->base.need_magic_ca_pass = false;
+
+       tmp->prim_emit = gen7_emit_composite_spans_primitive;
+       if (tmp->base.src.is_solid) {
+               tmp->prim_emit = gen7_emit_composite_spans_solid;
+       } else if (tmp->base.src.transform == NULL) {
+               tmp->prim_emit = gen7_emit_composite_spans_identity;
+       } else if (tmp->base.is_affine) {
+               if (tmp->base.src.transform->matrix[0][1] == 0 &&
+                   tmp->base.src.transform->matrix[1][0] == 0) {
+                       tmp->base.src.scale[0] /= tmp->base.src.transform->matrix[2][2];
+                       tmp->base.src.scale[1] /= tmp->base.src.transform->matrix[2][2];
+                       tmp->prim_emit = gen7_emit_composite_spans_simple;
+               } else
+                       tmp->prim_emit = gen7_emit_composite_spans_affine;
+       }
+       tmp->base.floats_per_vertex = 4 + !tmp->base.is_affine;
+       tmp->base.floats_per_rect = 3 * tmp->base.floats_per_vertex;
+
+       tmp->base.u.gen7.flags =
+               GEN7_SET_FLAGS(SAMPLER_OFFSET(tmp->base.src.filter,
+                                             tmp->base.src.repeat,
+                                             SAMPLER_FILTER_NEAREST,
+                                             SAMPLER_EXTEND_PAD),
+                              gen7_get_blend(tmp->base.op, false, tmp->base.dst.format),
+                              GEN7_WM_KERNEL_OPACITY | !tmp->base.is_affine,
+                              1 << 2 | (2+!tmp->base.is_affine));
+
+       tmp->box   = gen7_render_composite_spans_box;
+       tmp->boxes = gen7_render_composite_spans_boxes;
+       tmp->done  = gen7_render_composite_spans_done;
+
+       kgem_set_mode(&sna->kgem, KGEM_RENDER);
+       if (!kgem_check_bo(&sna->kgem,
+                          tmp->base.dst.bo, tmp->base.src.bo,
+                          NULL)) {
+               kgem_submit(&sna->kgem);
+               if (!kgem_check_bo(&sna->kgem,
+                                  tmp->base.dst.bo, tmp->base.src.bo,
+                                  NULL))
+                       goto cleanup_src;
+               _kgem_set_mode(&sna->kgem, KGEM_RENDER);
+       }
+
+       gen7_emit_composite_state(sna, &tmp->base);
+       gen7_align_vertex(sna, &tmp->base);
+       return true;
+
+cleanup_src:
+       if (tmp->base.src.bo)
+               kgem_bo_destroy(&sna->kgem, tmp->base.src.bo);
+cleanup_dst:
+       if (tmp->base.redirect.real_bo)
+               kgem_bo_destroy(&sna->kgem, tmp->base.dst.bo);
+       return false;
+}
+#endif
+
+static void
+gen7_emit_copy_state(struct sna *sna,
+                    const struct sna_composite_op *op)
+{
+       uint32_t *binding_table;
+       uint16_t offset;
+
+       gen7_get_batch(sna);
+
+       binding_table = gen7_composite_get_binding_table(sna, &offset);
+
+       binding_table[0] =
+               gen7_bind_bo(sna,
+                            op->dst.bo, op->dst.width, op->dst.height,
+                            gen7_get_dest_format(op->dst.format),
+                            true);
+       binding_table[1] =
+               gen7_bind_bo(sna,
+                            op->src.bo, op->src.width, op->src.height,
+                            op->src.card_format,
+                            false);
+
+       if (sna->kgem.surface == offset &&
+           *(uint64_t *)(sna->kgem.batch + sna->render_state.gen7.surface_table) == *(uint64_t*)binding_table) {
+               sna->kgem.surface += sizeof(struct gen7_surface_state) / sizeof(uint32_t);
+               offset = sna->render_state.gen7.surface_table;
+       }
+
+       assert(GEN7_BLEND(op->u.gen7.flags) == NO_BLEND);
+       gen7_emit_state(sna, op, offset);
+}
+
+static inline bool prefer_blt_copy(struct sna *sna,
+                                  struct kgem_bo *src_bo,
+                                  struct kgem_bo *dst_bo,
+                                  unsigned flags)
+{
+       return (sna->kgem.ring == KGEM_BLT ||
+               (flags & COPY_LAST && sna->kgem.mode == KGEM_NONE) ||
+               prefer_blt_bo(sna, src_bo) ||
+               prefer_blt_bo(sna, dst_bo));
+}
+
+inline static void boxes_extents(const BoxRec *box, int n, BoxRec *extents)
+{
+       *extents = box[0];
+       while (--n) {
+               box++;
+
+               if (box->x1 < extents->x1)
+                       extents->x1 = box->x1;
+               if (box->x2 > extents->x2)
+                       extents->x2 = box->x2;
+
+               if (box->y1 < extents->y1)
+                       extents->y1 = box->y1;
+               if (box->y2 > extents->y2)
+                       extents->y2 = box->y2;
+       }
+}
+
+static inline bool
+overlaps(struct sna *sna,
+        struct kgem_bo *src_bo, int16_t src_dx, int16_t src_dy,
+        struct kgem_bo *dst_bo, int16_t dst_dx, int16_t dst_dy,
+        const BoxRec *box, int n, BoxRec *extents)
+{
+       if (src_bo != dst_bo)
+               return false;
+
+       boxes_extents(box, n, extents);
+       return (extents->x2 + src_dx > extents->x1 + dst_dx &&
+               extents->x1 + src_dx < extents->x2 + dst_dx &&
+               extents->y2 + src_dy > extents->y1 + dst_dy &&
+               extents->y1 + src_dy < extents->y2 + dst_dy);
+}
+
+static bool
+gen7_render_copy_boxes(struct sna *sna, uint8_t alu,
+                      PixmapPtr src, struct kgem_bo *src_bo, int16_t src_dx, int16_t src_dy,
+                      PixmapPtr dst, struct kgem_bo *dst_bo, int16_t dst_dx, int16_t dst_dy,
+                      const BoxRec *box, int n, unsigned flags)
+{
+       struct sna_composite_op tmp;
+       BoxRec extents;
+
+       DBG(("%s (%d, %d)->(%d, %d) x %d, alu=%x, self-copy=%d, overlaps? %d\n",
+            __FUNCTION__, src_dx, src_dy, dst_dx, dst_dy, n, alu,
+            src_bo == dst_bo,
+            overlaps(sna,
+                     src_bo, src_dx, src_dy,
+                     dst_bo, dst_dx, dst_dy,
+                     box, n, &extents)));
+
+       if (prefer_blt_copy(sna, src_bo, dst_bo, flags) &&
+           sna_blt_compare_depth(&src->drawable, &dst->drawable) &&
+           sna_blt_copy_boxes(sna, alu,
+                              src_bo, src_dx, src_dy,
+                              dst_bo, dst_dx, dst_dy,
+                              dst->drawable.bitsPerPixel,
+                              box, n))
+               return true;
+
+       if (!(alu == GXcopy || alu == GXclear)) {
+fallback_blt:
+               if (!sna_blt_compare_depth(&src->drawable, &dst->drawable))
+                       return false;
+
+               return sna_blt_copy_boxes_fallback(sna, alu,
+                                                  src, src_bo, src_dx, src_dy,
+                                                  dst, dst_bo, dst_dx, dst_dy,
+                                                  box, n);
+       }
+
+       if (overlaps(sna,
+                    src_bo, src_dx, src_dy,
+                    dst_bo, dst_dx, dst_dy,
+                    box, n, &extents)) {
+               if (too_large(extents.x2-extents.x1, extents.y2-extents.y1))
+                       goto fallback_blt;
+
+               if ((flags & COPY_LAST || can_switch_to_blt(sna)) &&
+                   sna_blt_compare_depth(&src->drawable, &dst->drawable) &&
+                   sna_blt_copy_boxes(sna, alu,
+                                      src_bo, src_dx, src_dy,
+                                      dst_bo, dst_dx, dst_dy,
+                                      dst->drawable.bitsPerPixel,
+                                      box, n))
+                       return true;
+
+               return sna_render_copy_boxes__overlap(sna, alu,
+                                                     src, src_bo, src_dx, src_dy,
+                                                     dst, dst_bo, dst_dx, dst_dy,
+                                                     box, n, &extents);
+       }
+
+       if (dst->drawable.depth == src->drawable.depth) {
+               tmp.dst.format = sna_render_format_for_depth(dst->drawable.depth);
+               tmp.src.pict_format = tmp.dst.format;
+       } else {
+               tmp.dst.format = sna_format_for_depth(dst->drawable.depth);
+               tmp.src.pict_format = sna_format_for_depth(src->drawable.depth);
+       }
+       if (!gen7_check_format(tmp.src.pict_format))
+               goto fallback_blt;
+
+       tmp.dst.pixmap = dst;
+       tmp.dst.width  = dst->drawable.width;
+       tmp.dst.height = dst->drawable.height;
+       tmp.dst.bo = dst_bo;
+       tmp.dst.x = tmp.dst.y = 0;
+       tmp.damage = NULL;
+
+       sna_render_composite_redirect_init(&tmp);
+       if (too_large(tmp.dst.width, tmp.dst.height)) {
+               int i;
+
+               extents = box[0];
+               for (i = 1; i < n; i++) {
+                       if (box[i].x1 < extents.x1)
+                               extents.x1 = box[i].x1;
+                       if (box[i].y1 < extents.y1)
+                               extents.y1 = box[i].y1;
+
+                       if (box[i].x2 > extents.x2)
+                               extents.x2 = box[i].x2;
+                       if (box[i].y2 > extents.y2)
+                               extents.y2 = box[i].y2;
+               }
+
+               if (!sna_render_composite_redirect(sna, &tmp,
+                                                  extents.x1 + dst_dx,
+                                                  extents.y1 + dst_dy,
+                                                  extents.x2 - extents.x1,
+                                                  extents.y2 - extents.y1))
+                       goto fallback_tiled;
+
+               dst_dx += tmp.dst.x;
+               dst_dy += tmp.dst.y;
+
+               tmp.dst.x = tmp.dst.y = 0;
+       }
+
+       tmp.src.card_format = gen7_get_card_format(tmp.src.pict_format);
+       if (too_large(src->drawable.width, src->drawable.height)) {
+               int i;
+
+               extents = box[0];
+               for (i = 1; i < n; i++) {
+                       if (extents.x1 < box[i].x1)
+                               extents.x1 = box[i].x1;
+                       if (extents.y1 < box[i].y1)
+                               extents.y1 = box[i].y1;
+
+                       if (extents.x2 > box[i].x2)
+                               extents.x2 = box[i].x2;
+                       if (extents.y2 > box[i].y2)
+                               extents.y2 = box[i].y2;
+               }
+
+               if (!sna_render_pixmap_partial(sna, src, src_bo, &tmp.src,
+                                              extents.x1 + src_dx,
+                                              extents.y1 + src_dy,
+                                              extents.x2 - extents.x1,
+                                              extents.y2 - extents.y1))
+                       goto fallback_tiled_dst;
+
+               src_dx += tmp.src.offset[0];
+               src_dy += tmp.src.offset[1];
+       } else {
+               tmp.src.bo = src_bo;
+               tmp.src.width  = src->drawable.width;
+               tmp.src.height = src->drawable.height;
+       }
+
+       tmp.mask.bo = NULL;
+
+       tmp.floats_per_vertex = 2;
+       tmp.floats_per_rect = 6;
+       tmp.need_magic_ca_pass = 0;
+
+       tmp.u.gen7.flags = COPY_FLAGS(alu);
+
+       kgem_set_mode(&sna->kgem, KGEM_RENDER);
+       if (!kgem_check_bo(&sna->kgem, tmp.dst.bo, tmp.src.bo, NULL)) {
+               kgem_submit(&sna->kgem);
+               if (!kgem_check_bo(&sna->kgem, tmp.dst.bo, tmp.src.bo, NULL))
+                       goto fallback_tiled_src;
+               _kgem_set_mode(&sna->kgem, KGEM_RENDER);
+       }
+
+       gen7_emit_copy_state(sna, &tmp);
+       gen7_align_vertex(sna, &tmp);
+
+       do {
+               int16_t *v;
+               int n_this_time;
+
+               n_this_time = gen7_get_rectangles(sna, &tmp, n,
+                                                 gen7_emit_copy_state);
+               n -= n_this_time;
+
+               v = (int16_t *)(sna->render.vertices + sna->render.vertex_used);
+               sna->render.vertex_used += 6 * n_this_time;
+               assert(sna->render.vertex_used <= sna->render.vertex_size);
+               do {
+
+                       DBG(("  (%d, %d) -> (%d, %d) + (%d, %d)\n",
+                            box->x1 + src_dx, box->y1 + src_dy,
+                            box->x1 + dst_dx, box->y1 + dst_dy,
+                            box->x2 - box->x1, box->y2 - box->y1));
+                       v[0] = box->x2 + dst_dx;
+                       v[2] = box->x2 + src_dx;
+                       v[1]  = v[5] = box->y2 + dst_dy;
+                       v[3]  = v[7] = box->y2 + src_dy;
+                       v[8]  = v[4] = box->x1 + dst_dx;
+                       v[10] = v[6] = box->x1 + src_dx;
+                       v[9]  = box->y1 + dst_dy;
+                       v[11] = box->y1 + src_dy;
+                       v += 12; box++;
+               } while (--n_this_time);
+       } while (n);
+
+       gen7_vertex_flush(sna);
+       sna_render_composite_redirect_done(sna, &tmp);
+       if (tmp.src.bo != src_bo)
+               kgem_bo_destroy(&sna->kgem, tmp.src.bo);
+       return true;
+
+fallback_tiled_src:
+       if (tmp.src.bo != src_bo)
+               kgem_bo_destroy(&sna->kgem, tmp.src.bo);
+fallback_tiled_dst:
+       if (tmp.redirect.real_bo)
+               kgem_bo_destroy(&sna->kgem, tmp.dst.bo);
+fallback_tiled:
+       return sna_tiling_copy_boxes(sna, alu,
+                                    src, src_bo, src_dx, src_dy,
+                                    dst, dst_bo, dst_dx, dst_dy,
+                                    box, n);
+}
+
+static void
+gen7_render_copy_blt(struct sna *sna,
+                    const struct sna_copy_op *op,
+                    int16_t sx, int16_t sy,
+                    int16_t w,  int16_t h,
+                    int16_t dx, int16_t dy)
+{
+       int16_t *v;
+
+       gen7_get_rectangles(sna, &op->base, 1, gen7_emit_copy_state);
+
+       v = (int16_t *)&sna->render.vertices[sna->render.vertex_used];
+       sna->render.vertex_used += 6;
+       assert(sna->render.vertex_used <= sna->render.vertex_size);
+
+       v[0]  = dx+w; v[1]  = dy+h;
+       v[2]  = sx+w; v[3]  = sy+h;
+       v[4]  = dx;   v[5]  = dy+h;
+       v[6]  = sx;   v[7]  = sy+h;
+       v[8]  = dx;   v[9]  = dy;
+       v[10] = sx;   v[11] = sy;
+}
+
+static void
+gen7_render_copy_done(struct sna *sna, const struct sna_copy_op *op)
+{
+       if (sna->render_state.gen7.vertex_offset)
+               gen7_vertex_flush(sna);
+}
+
+static bool
+gen7_render_copy(struct sna *sna, uint8_t alu,
+                PixmapPtr src, struct kgem_bo *src_bo,
+                PixmapPtr dst, struct kgem_bo *dst_bo,
+                struct sna_copy_op *op)
+{
+       DBG(("%s (alu=%d, src=(%dx%d), dst=(%dx%d))\n",
+            __FUNCTION__, alu,
+            src->drawable.width, src->drawable.height,
+            dst->drawable.width, dst->drawable.height));
+
+       if (prefer_blt_copy(sna, src_bo, dst_bo, 0) &&
+           sna_blt_compare_depth(&src->drawable, &dst->drawable) &&
+           sna_blt_copy(sna, alu,
+                        src_bo, dst_bo,
+                        dst->drawable.bitsPerPixel,
+                        op))
+               return true;
+
+       if (!(alu == GXcopy || alu == GXclear) || src_bo == dst_bo ||
+           too_large(src->drawable.width, src->drawable.height) ||
+           too_large(dst->drawable.width, dst->drawable.height)) {
+fallback:
+               if (!sna_blt_compare_depth(&src->drawable, &dst->drawable))
+                       return false;
+
+               return sna_blt_copy(sna, alu, src_bo, dst_bo,
+                                   dst->drawable.bitsPerPixel,
+                                   op);
+       }
+
+       if (dst->drawable.depth == src->drawable.depth) {
+               op->base.dst.format = sna_render_format_for_depth(dst->drawable.depth);
+               op->base.src.pict_format = op->base.dst.format;
+       } else {
+               op->base.dst.format = sna_format_for_depth(dst->drawable.depth);
+               op->base.src.pict_format = sna_format_for_depth(src->drawable.depth);
+       }
+       if (!gen7_check_format(op->base.src.pict_format))
+               goto fallback;
+
+       op->base.dst.pixmap = dst;
+       op->base.dst.width  = dst->drawable.width;
+       op->base.dst.height = dst->drawable.height;
+       op->base.dst.bo = dst_bo;
+
+       op->base.src.bo = src_bo;
+       op->base.src.card_format =
+               gen7_get_card_format(op->base.src.pict_format);
+       op->base.src.width  = src->drawable.width;
+       op->base.src.height = src->drawable.height;
+
+       op->base.mask.bo = NULL;
+
+       op->base.floats_per_vertex = 2;
+       op->base.floats_per_rect = 6;
+
+       op->base.u.gen7.flags = COPY_FLAGS(alu);
+
+       kgem_set_mode(&sna->kgem, KGEM_RENDER);
+       if (!kgem_check_bo(&sna->kgem, dst_bo, src_bo, NULL)) {
+               kgem_submit(&sna->kgem);
+               if (!kgem_check_bo(&sna->kgem, dst_bo, src_bo, NULL))
+                       goto fallback;
+               _kgem_set_mode(&sna->kgem, KGEM_RENDER);
+       }
+
+       gen7_emit_copy_state(sna, &op->base);
+       gen7_align_vertex(sna, &op->base);
+
+       op->blt  = gen7_render_copy_blt;
+       op->done = gen7_render_copy_done;
+       return true;
+}
+
+static void
+gen7_emit_fill_state(struct sna *sna, const struct sna_composite_op *op)
+{
+       uint32_t *binding_table;
+       uint16_t offset;
+
+       /* XXX Render Target Fast Clear
+        * Set RTFC Enable in PS and render a rectangle.
+        * Limited to a clearing the full MSC surface only with a
+        * specific kernel.
+        */
+
+       gen7_get_batch(sna);
+
+       binding_table = gen7_composite_get_binding_table(sna, &offset);
+
+       binding_table[0] =
+               gen7_bind_bo(sna,
+                            op->dst.bo, op->dst.width, op->dst.height,
+                            gen7_get_dest_format(op->dst.format),
+                            true);
+       binding_table[1] =
+               gen7_bind_bo(sna,
+                            op->src.bo, 1, 1,
+                            GEN7_SURFACEFORMAT_B8G8R8A8_UNORM,
+                            false);
+
+       if (sna->kgem.surface == offset &&
+           *(uint64_t *)(sna->kgem.batch + sna->render_state.gen7.surface_table) == *(uint64_t*)binding_table) {
+               sna->kgem.surface +=
+                       sizeof(struct gen7_surface_state)/sizeof(uint32_t);
+               offset = sna->render_state.gen7.surface_table;
+       }
+
+       gen7_emit_state(sna, op, offset);
+}
+
+static inline bool prefer_blt_fill(struct sna *sna,
+                                  struct kgem_bo *bo)
+{
+       return prefer_blt_ring(sna) || untiled_tlb_miss(bo);
+}
+
+static bool
+gen7_render_fill_boxes(struct sna *sna,
+                      CARD8 op,
+                      PictFormat format,
+                      const xRenderColor *color,
+                      PixmapPtr dst, struct kgem_bo *dst_bo,
+                      const BoxRec *box, int n)
+{
+       struct sna_composite_op tmp;
+       uint32_t pixel;
+
+       DBG(("%s (op=%d, color=(%04x, %04x, %04x, %04x) [%08x])\n",
+            __FUNCTION__, op,
+            color->red, color->green, color->blue, color->alpha, (int)format));
+
+       if (op >= ARRAY_SIZE(gen7_blend_op)) {
+               DBG(("%s: fallback due to unhandled blend op: %d\n",
+                    __FUNCTION__, op));
+               return false;
+       }
+
+       if (prefer_blt_fill(sna, dst_bo) || !gen7_check_dst_format(format)) {
+               uint8_t alu = GXinvalid;
+
+               if (op <= PictOpSrc) {
+                       pixel = 0;
+                       if (op == PictOpClear)
+                               alu = GXclear;
+                       else if (sna_get_pixel_from_rgba(&pixel,
+                                                        color->red,
+                                                        color->green,
+                                                        color->blue,
+                                                        color->alpha,
+                                                        format))
+                               alu = GXcopy;
+               }
+
+               if (alu != GXinvalid &&
+                   sna_blt_fill_boxes(sna, alu,
+                                      dst_bo, dst->drawable.bitsPerPixel,
+                                      pixel, box, n))
+                       return true;
+
+               if (!gen7_check_dst_format(format))
+                       return false;
+       }
+
+       if (op == PictOpClear) {
+               pixel = 0;
+               op = PictOpSrc;
+       } else if (!sna_get_pixel_from_rgba(&pixel,
+                                           color->red,
+                                           color->green,
+                                           color->blue,
+                                           color->alpha,
+                                           PICT_a8r8g8b8))
+               return false;
+
+       DBG(("%s(%08x x %d [(%d, %d), (%d, %d) ...])\n",
+            __FUNCTION__, pixel, n,
+            box[0].x1, box[0].y1, box[0].x2, box[0].y2));
+
+       tmp.dst.pixmap = dst;
+       tmp.dst.width  = dst->drawable.width;
+       tmp.dst.height = dst->drawable.height;
+       tmp.dst.format = format;
+       tmp.dst.bo = dst_bo;
+       tmp.dst.x = tmp.dst.y = 0;
+
+       sna_render_composite_redirect_init(&tmp);
+       if (too_large(dst->drawable.width, dst->drawable.height)) {
+               BoxRec extents;
+
+               boxes_extents(box, n, &extents);
+               if (!sna_render_composite_redirect(sna, &tmp,
+                                                  extents.x1, extents.y1,
+                                                  extents.x2 - extents.x1,
+                                                  extents.y2 - extents.y1))
+                       return sna_tiling_fill_boxes(sna, op, format, color,
+                                                    dst, dst_bo, box, n);
+       }
+
+       tmp.src.bo = sna_render_get_solid(sna, pixel);
+       tmp.mask.bo = NULL;
+
+       tmp.floats_per_vertex = 2;
+       tmp.floats_per_rect = 6;
+       tmp.need_magic_ca_pass = false;
+
+       tmp.u.gen7.flags = FILL_FLAGS(op, format);
+
+       if (!kgem_check_bo(&sna->kgem, dst_bo, NULL)) {
+               kgem_submit(&sna->kgem);
+               assert(kgem_check_bo(&sna->kgem, dst_bo, NULL));
+       }
+
+       gen7_emit_fill_state(sna, &tmp);
+       gen7_align_vertex(sna, &tmp);
+
+       do {
+               int n_this_time;
+               int16_t *v;
+
+               n_this_time = gen7_get_rectangles(sna, &tmp, n,
+                                                 gen7_emit_fill_state);
+               n -= n_this_time;
+
+               v = (int16_t *)(sna->render.vertices + sna->render.vertex_used);
+               sna->render.vertex_used += 6 * n_this_time;
+               assert(sna->render.vertex_used <= sna->render.vertex_size);
+               do {
+                       DBG(("  (%d, %d), (%d, %d)\n",
+                            box->x1, box->y1, box->x2, box->y2));
+
+                       v[0] = box->x2;
+                       v[5] = v[1] = box->y2;
+                       v[8] = v[4] = box->x1;
+                       v[9] = box->y1;
+                       v[2] = v[3]  = v[7]  = 1;
+                       v[6] = v[10] = v[11] = 0;
+                       v += 12; box++;
+               } while (--n_this_time);
+       } while (n);
+
+       gen7_vertex_flush(sna);
+       kgem_bo_destroy(&sna->kgem, tmp.src.bo);
+       sna_render_composite_redirect_done(sna, &tmp);
+       return true;
+}
+
+static void
+gen7_render_fill_op_blt(struct sna *sna,
+                       const struct sna_fill_op *op,
+                       int16_t x, int16_t y, int16_t w, int16_t h)
+{
+       int16_t *v;
+
+       DBG(("%s: (%d, %d)x(%d, %d)\n", __FUNCTION__, x, y, w, h));
+
+       gen7_get_rectangles(sna, &op->base, 1, gen7_emit_fill_state);
+
+       v = (int16_t *)&sna->render.vertices[sna->render.vertex_used];
+       sna->render.vertex_used += 6;
+       assert(sna->render.vertex_used <= sna->render.vertex_size);
+
+       v[0] = x+w;
+       v[4] = v[8] = x;
+       v[1] = v[5] = y+h;
+       v[9] = y;
+
+       v[2] = v[3]  = v[7]  = 1;
+       v[6] = v[10] = v[11] = 0;
+}
+
+fastcall static void
+gen7_render_fill_op_box(struct sna *sna,
+                       const struct sna_fill_op *op,
+                       const BoxRec *box)
+{
+       int16_t *v;
+
+       DBG(("%s: (%d, %d),(%d, %d)\n", __FUNCTION__,
+            box->x1, box->y1, box->x2, box->y2));
+
+       gen7_get_rectangles(sna, &op->base, 1, gen7_emit_fill_state);
+
+       v = (int16_t *)&sna->render.vertices[sna->render.vertex_used];
+       sna->render.vertex_used += 6;
+       assert(sna->render.vertex_used <= sna->render.vertex_size);
+
+       v[0] = box->x2;
+       v[8] = v[4] = box->x1;
+       v[5] = v[1] = box->y2;
+       v[9] = box->y1;
+
+       v[7] = v[2]  = v[3]  = 1;
+       v[6] = v[10] = v[11] = 0;
+}
+
+fastcall static void
+gen7_render_fill_op_boxes(struct sna *sna,
+                         const struct sna_fill_op *op,
+                         const BoxRec *box,
+                         int nbox)
+{
+       DBG(("%s: (%d, %d),(%d, %d)... x %d\n", __FUNCTION__,
+            box->x1, box->y1, box->x2, box->y2, nbox));
+
+       do {
+               int nbox_this_time;
+               int16_t *v;
+
+               nbox_this_time = gen7_get_rectangles(sna, &op->base, nbox,
+                                                    gen7_emit_fill_state);
+               nbox -= nbox_this_time;
+
+               v = (int16_t *)&sna->render.vertices[sna->render.vertex_used];
+               sna->render.vertex_used += 6 * nbox_this_time;
+               assert(sna->render.vertex_used <= sna->render.vertex_size);
+
+               do {
+                       v[0] = box->x2;
+                       v[8] = v[4] = box->x1;
+                       v[5] = v[1] = box->y2;
+                       v[9] = box->y1;
+                       v[7] = v[2]  = v[3]  = 1;
+                       v[6] = v[10] = v[11] = 0;
+                       box++; v += 12;
+               } while (--nbox_this_time);
+       } while (nbox);
+}
+
+static void
+gen7_render_fill_op_done(struct sna *sna, const struct sna_fill_op *op)
+{
+       if (sna->render_state.gen7.vertex_offset)
+               gen7_vertex_flush(sna);
+       kgem_bo_destroy(&sna->kgem, op->base.src.bo);
+}
+
+static bool
+gen7_render_fill(struct sna *sna, uint8_t alu,
+                PixmapPtr dst, struct kgem_bo *dst_bo,
+                uint32_t color,
+                struct sna_fill_op *op)
+{
+       DBG(("%s: (alu=%d, color=%x)\n", __FUNCTION__, alu, color));
+
+       if (prefer_blt_fill(sna, dst_bo) &&
+           sna_blt_fill(sna, alu,
+                        dst_bo, dst->drawable.bitsPerPixel,
+                        color,
+                        op))
+               return true;
+
+       if (!(alu == GXcopy || alu == GXclear) ||
+           too_large(dst->drawable.width, dst->drawable.height))
+               return sna_blt_fill(sna, alu,
+                                   dst_bo, dst->drawable.bitsPerPixel,
+                                   color,
+                                   op);
+
+       if (alu == GXclear)
+               color = 0;
+
+       op->base.dst.pixmap = dst;
+       op->base.dst.width  = dst->drawable.width;
+       op->base.dst.height = dst->drawable.height;
+       op->base.dst.format = sna_format_for_depth(dst->drawable.depth);
+       op->base.dst.bo = dst_bo;
+       op->base.dst.x = op->base.dst.y = 0;
+
+       op->base.src.bo =
+               sna_render_get_solid(sna,
+                                    sna_rgba_for_color(color,
+                                                       dst->drawable.depth));
+       op->base.mask.bo = NULL;
+
+       op->base.need_magic_ca_pass = false;
+       op->base.floats_per_vertex = 2;
+       op->base.floats_per_rect = 6;
+
+       op->base.u.gen7.flags = FILL_FLAGS_NOBLEND;
+
+       if (!kgem_check_bo(&sna->kgem, dst_bo, NULL)) {
+               kgem_submit(&sna->kgem);
+               assert(kgem_check_bo(&sna->kgem, dst_bo, NULL));
+       }
+
+       gen7_emit_fill_state(sna, &op->base);
+       gen7_align_vertex(sna, &op->base);
+
+       op->blt   = gen7_render_fill_op_blt;
+       op->box   = gen7_render_fill_op_box;
+       op->boxes = gen7_render_fill_op_boxes;
+       op->done  = gen7_render_fill_op_done;
+       return true;
+}
+
+static bool
+gen7_render_fill_one_try_blt(struct sna *sna, PixmapPtr dst, struct kgem_bo *bo,
+                            uint32_t color,
+                            int16_t x1, int16_t y1, int16_t x2, int16_t y2,
+                            uint8_t alu)
+{
+       BoxRec box;
+
+       box.x1 = x1;
+       box.y1 = y1;
+       box.x2 = x2;
+       box.y2 = y2;
+
+       return sna_blt_fill_boxes(sna, alu,
+                                 bo, dst->drawable.bitsPerPixel,
+                                 color, &box, 1);
+}
+
+static bool
+gen7_render_fill_one(struct sna *sna, PixmapPtr dst, struct kgem_bo *bo,
+                    uint32_t color,
+                    int16_t x1, int16_t y1,
+                    int16_t x2, int16_t y2,
+                    uint8_t alu)
+{
+       struct sna_composite_op tmp;
+       int16_t *v;
+
+       /* Prefer to use the BLT if already engaged */
+       if (prefer_blt_fill(sna, bo) &&
+           gen7_render_fill_one_try_blt(sna, dst, bo, color,
+                                        x1, y1, x2, y2, alu))
+               return true;
+
+       /* Must use the BLT if we can't RENDER... */
+       if (!(alu == GXcopy || alu == GXclear) ||
+           too_large(dst->drawable.width, dst->drawable.height))
+               return gen7_render_fill_one_try_blt(sna, dst, bo, color,
+                                                   x1, y1, x2, y2, alu);
+
+       if (alu == GXclear)
+               color = 0;
+
+       tmp.dst.pixmap = dst;
+       tmp.dst.width  = dst->drawable.width;
+       tmp.dst.height = dst->drawable.height;
+       tmp.dst.format = sna_format_for_depth(dst->drawable.depth);
+       tmp.dst.bo = bo;
+       tmp.dst.x = tmp.dst.y = 0;
+
+       tmp.src.bo =
+               sna_render_get_solid(sna,
+                                    sna_rgba_for_color(color,
+                                                       dst->drawable.depth));
+       tmp.mask.bo = NULL;
+
+       tmp.floats_per_vertex = 2;
+       tmp.floats_per_rect = 6;
+       tmp.need_magic_ca_pass = false;
+
+       tmp.u.gen7.flags = FILL_FLAGS_NOBLEND;
+
+       if (!kgem_check_bo(&sna->kgem, bo, NULL)) {
+               _kgem_submit(&sna->kgem);
+               assert(kgem_check_bo(&sna->kgem, bo, NULL));
+       }
+
+       gen7_emit_fill_state(sna, &tmp);
+       gen7_align_vertex(sna, &tmp);
+
+       gen7_get_rectangles(sna, &tmp, 1, gen7_emit_fill_state);
+
+       DBG(("  (%d, %d), (%d, %d)\n", x1, y1, x2, y2));
+
+       v = (int16_t *)&sna->render.vertices[sna->render.vertex_used];
+       sna->render.vertex_used += 6;
+       assert(sna->render.vertex_used <= sna->render.vertex_size);
+
+       v[0] = x2;
+       v[8] = v[4] = x1;
+       v[5] = v[1] = y2;
+       v[9] = y1;
+       v[7] = v[2]  = v[3]  = 1;
+       v[6] = v[10] = v[11] = 0;
+
+       gen7_vertex_flush(sna);
+       kgem_bo_destroy(&sna->kgem, tmp.src.bo);
+
+       return true;
+}
+
+static bool
+gen7_render_clear_try_blt(struct sna *sna, PixmapPtr dst, struct kgem_bo *bo)
+{
+       BoxRec box;
+
+       box.x1 = 0;
+       box.y1 = 0;
+       box.x2 = dst->drawable.width;
+       box.y2 = dst->drawable.height;
+
+       return sna_blt_fill_boxes(sna, GXclear,
+                                 bo, dst->drawable.bitsPerPixel,
+                                 0, &box, 1);
+}
+
+static bool
+gen7_render_clear(struct sna *sna, PixmapPtr dst, struct kgem_bo *bo)
+{
+       struct sna_composite_op tmp;
+       int16_t *v;
+
+       DBG(("%s: %dx%d\n",
+            __FUNCTION__,
+            dst->drawable.width,
+            dst->drawable.height));
+
+       /* Prefer to use the BLT if already engaged */
+       if (sna->kgem.ring == KGEM_BLT &&
+           gen7_render_clear_try_blt(sna, dst, bo))
+               return true;
+
+       /* Must use the BLT if we can't RENDER... */
+       if (too_large(dst->drawable.width, dst->drawable.height))
+               return gen7_render_clear_try_blt(sna, dst, bo);
+
+       tmp.dst.pixmap = dst;
+       tmp.dst.width  = dst->drawable.width;
+       tmp.dst.height = dst->drawable.height;
+       tmp.dst.format = sna_format_for_depth(dst->drawable.depth);
+       tmp.dst.bo = bo;
+       tmp.dst.x = tmp.dst.y = 0;
+
+       tmp.src.bo = sna_render_get_solid(sna, 0);
+       tmp.mask.bo = NULL;
+
+       tmp.floats_per_vertex = 2;
+       tmp.floats_per_rect = 6;
+       tmp.need_magic_ca_pass = false;
+
+       tmp.u.gen7.flags = FILL_FLAGS_NOBLEND;
+
+       if (!kgem_check_bo(&sna->kgem, bo, NULL)) {
+               _kgem_submit(&sna->kgem);
+               assert(kgem_check_bo(&sna->kgem, bo, NULL));
+       }
+
+       gen7_emit_fill_state(sna, &tmp);
+       gen7_align_vertex(sna, &tmp);
+
+       gen7_get_rectangles(sna, &tmp, 1, gen7_emit_fill_state);
+
+       v = (int16_t *)&sna->render.vertices[sna->render.vertex_used];
+       sna->render.vertex_used += 6;
+       assert(sna->render.vertex_used <= sna->render.vertex_size);
+
+       v[0] = dst->drawable.width;
+       v[5] = v[1] = dst->drawable.height;
+       v[8] = v[4] = 0;
+       v[9] = 0;
+
+       v[7] = v[2]  = v[3]  = 1;
+       v[6] = v[10] = v[11] = 0;
+
+       gen7_vertex_flush(sna);
+       kgem_bo_destroy(&sna->kgem, tmp.src.bo);
+
+       return true;
+}
+
+static void gen7_render_flush(struct sna *sna)
+{
+       gen7_vertex_close(sna);
+}
+
+static void
+gen7_render_context_switch(struct kgem *kgem,
+                          int new_mode)
+{
+       if (!new_mode)
+               return;
+
+       if (kgem->mode) {
+               DBG(("%s: switch rings %d -> %d\n",
+                    __FUNCTION__, kgem->mode, new_mode));
+               kgem_submit(kgem);
+       }
+
+       kgem->ring = new_mode;
+}
+
+static void
+gen7_render_retire(struct kgem *kgem)
+{
+       struct sna *sna;
+
+       if (kgem->ring && (kgem->has_semaphores || !kgem->need_retire))
+               kgem->ring = kgem->mode;
+
+       sna = container_of(kgem, struct sna, kgem);
+       if (kgem->nbatch == 0 && sna->render.vbo && !kgem_bo_is_busy(sna->render.vbo)) {
+               DBG(("%s: resetting idle vbo\n", __FUNCTION__));
+               sna->render.vertex_used = 0;
+               sna->render.vertex_index = 0;
+       }
+}
+
+static void
+gen7_render_expire(struct kgem *kgem)
+{
+       struct sna *sna;
+
+       sna = container_of(kgem, struct sna, kgem);
+       if (sna->render.vbo && !sna->render.vertex_used) {
+               DBG(("%s: discarding vbo\n", __FUNCTION__));
+               kgem_bo_destroy(kgem, sna->render.vbo);
+               sna->render.vbo = NULL;
+               sna->render.vertices = sna->render.vertex_data;
+               sna->render.vertex_size = ARRAY_SIZE(sna->render.vertex_data);
+               sna->render.vertex_used = 0;
+               sna->render.vertex_index = 0;
+       }
+}
+
+static void gen7_render_reset(struct sna *sna)
+{
+       sna->render_state.gen7.emit_flush = false;
+       sna->render_state.gen7.needs_invariant = true;
+       sna->render_state.gen7.vb_id = 0;
+       sna->render_state.gen7.ve_id = 3 << 2;
+       sna->render_state.gen7.last_primitive = -1;
+
+       sna->render_state.gen7.num_sf_outputs = 0;
+       sna->render_state.gen7.samplers = -1;
+       sna->render_state.gen7.blend = -1;
+       sna->render_state.gen7.kernel = -1;
+       sna->render_state.gen7.drawrect_offset = -1;
+       sna->render_state.gen7.drawrect_limit = -1;
+       sna->render_state.gen7.surface_table = -1;
+}
+
+static void gen7_render_fini(struct sna *sna)
+{
+       kgem_bo_destroy(&sna->kgem, sna->render_state.gen7.general_bo);
+}
+
+static bool gen7_render_setup(struct sna *sna)
+{
+       struct gen7_render_state *state = &sna->render_state.gen7;
+       struct sna_static_stream general;
+       struct gen7_sampler_state *ss;
+       int i, j, k, l, m;
+
+       if (sna->kgem.gen == 70) {
+               state->info = &ivb_gt_info;
+               if (DEVICE_ID(sna->PciInfo) & 0xf) {
+                       state->info = &ivb_gt1_info;
+                       if (DEVICE_ID(sna->PciInfo) & 0x20)
+                               state->info = &ivb_gt2_info; /* XXX requires GT_MODE WiZ disabled */
+               }
+       } else if (sna->kgem.gen == 75) {
+               state->info = &hsw_gt_info;
+       } else
+               return false;
+
+       sna_static_stream_init(&general);
+
+       /* Zero pad the start. If you see an offset of 0x0 in the batchbuffer
+        * dumps, you know it points to zero.
+        */
+       null_create(&general);
+
+       for (m = 0; m < GEN7_WM_KERNEL_COUNT; m++) {
+               if (wm_kernels[m].size) {
+                       state->wm_kernel[m][1] =
+                               sna_static_stream_add(&general,
+                                                     wm_kernels[m].data,
+                                                     wm_kernels[m].size,
+                                                     64);
+               } else {
+                       if (USE_8_PIXEL_DISPATCH) {
+                               state->wm_kernel[m][0] =
+                                       sna_static_stream_compile_wm(sna, &general,
+                                                                    wm_kernels[m].data, 8);
+                       }
+
+                       if (USE_16_PIXEL_DISPATCH) {
+                               state->wm_kernel[m][1] =
+                                       sna_static_stream_compile_wm(sna, &general,
+                                                                    wm_kernels[m].data, 16);
+                       }
+
+                       if (USE_32_PIXEL_DISPATCH) {
+                               state->wm_kernel[m][2] =
+                                       sna_static_stream_compile_wm(sna, &general,
+                                                                    wm_kernels[m].data, 32);
+                       }
+               }
+               assert(state->wm_kernel[m][0]|state->wm_kernel[m][1]|state->wm_kernel[m][2]);
+       }
+
+       ss = sna_static_stream_map(&general,
+                                  2 * sizeof(*ss) *
+                                  (2 +
+                                   FILTER_COUNT * EXTEND_COUNT *
+                                   FILTER_COUNT * EXTEND_COUNT),
+                                  32);
+       state->wm_state = sna_static_stream_offsetof(&general, ss);
+       sampler_copy_init(ss); ss += 2;
+       sampler_fill_init(ss); ss += 2;
+       for (i = 0; i < FILTER_COUNT; i++) {
+               for (j = 0; j < EXTEND_COUNT; j++) {
+                       for (k = 0; k < FILTER_COUNT; k++) {
+                               for (l = 0; l < EXTEND_COUNT; l++) {
+                                       sampler_state_init(ss++, i, j);
+                                       sampler_state_init(ss++, k, l);
+                               }
+                       }
+               }
+       }
+
+       state->cc_vp = gen7_create_cc_viewport(&general);
+       state->cc_blend = gen7_composite_create_blend_state(&general);
+
+       state->general_bo = sna_static_stream_fini(sna, &general);
+       return state->general_bo != NULL;
+}
+
+bool gen7_render_init(struct sna *sna)
+{
+       if (!gen7_render_setup(sna))
+               return false;
+
+       sna->kgem.context_switch = gen7_render_context_switch;
+       sna->kgem.retire = gen7_render_retire;
+       sna->kgem.expire = gen7_render_expire;
+
+#if !NO_COMPOSITE
+       sna->render.composite = gen7_render_composite;
+#endif
+#if !NO_COMPOSITE_SPANS
+       sna->render.check_composite_spans = gen7_check_composite_spans;
+       sna->render.composite_spans = gen7_render_composite_spans;
+#endif
+       sna->render.video = gen7_render_video;
+
+#if !NO_COPY_BOXES
+       sna->render.copy_boxes = gen7_render_copy_boxes;
+#endif
+#if !NO_COPY
+       sna->render.copy = gen7_render_copy;
+#endif
+
+#if !NO_FILL_BOXES
+       sna->render.fill_boxes = gen7_render_fill_boxes;
+#endif
+#if !NO_FILL
+       sna->render.fill = gen7_render_fill;
+#endif
+#if !NO_FILL_ONE
+       sna->render.fill_one = gen7_render_fill_one;
+#endif
+#if !NO_FILL_CLEAR
+       sna->render.clear = gen7_render_clear;
+#endif
+
+       sna->render.flush = gen7_render_flush;
+       sna->render.reset = gen7_render_reset;
+       sna->render.fini = gen7_render_fini;
+
+       sna->render.max_3d_size = GEN7_MAX_SIZE;
+       sna->render.max_3d_pitch = 1 << 18;
+       return true;
+}
diff --git a/src/sna/gen7_render.h b/src/sna/gen7_render.h
new file mode 100644 (file)
index 0000000..1661d4c
--- /dev/null
@@ -0,0 +1,1364 @@
+#ifndef GEN7_RENDER_H
+#define GEN7_RENDER_H
+
+#define INTEL_MASK(high, low) (((1 << ((high) - (low) + 1)) - 1) << (low))
+
+#define GEN7_3D(Pipeline,Opcode,Subopcode) ((3 << 29) | \
+                                          ((Pipeline) << 27) | \
+                                          ((Opcode) << 24) | \
+                                          ((Subopcode) << 16))
+
+#define GEN7_STATE_BASE_ADDRESS                        GEN7_3D(0, 1, 1)
+#define GEN7_STATE_SIP                         GEN7_3D(0, 1, 2)
+
+#define GEN7_PIPELINE_SELECT                   GEN7_3D(1, 1, 4)
+
+#define GEN7_MEDIA_STATE_POINTERS              GEN7_3D(2, 0, 0)
+#define GEN7_MEDIA_OBJECT                      GEN7_3D(2, 1, 0)
+
+#define GEN7_3DSTATE_VERTEX_BUFFERS            GEN7_3D(3, 0, 8)
+#define GEN7_3DSTATE_VERTEX_ELEMENTS           GEN7_3D(3, 0, 9)
+#define GEN7_3DSTATE_INDEX_BUFFER              GEN7_3D(3, 0, 0xa)
+#define GEN7_3DSTATE_VF_STATISTICS             GEN7_3D(3, 0, 0xb)
+
+#define GEN7_3DSTATE_DRAWING_RECTANGLE         GEN7_3D(3, 1, 0)
+#define GEN7_3DSTATE_CONSTANT_COLOR            GEN7_3D(3, 1, 1)
+#define GEN7_3DSTATE_SAMPLER_PALETTE_LOAD      GEN7_3D(3, 1, 2)
+#define GEN7_3DSTATE_CHROMA_KEY                        GEN7_3D(3, 1, 4)
+
+#define GEN7_3DSTATE_POLY_STIPPLE_OFFSET               GEN7_3D(3, 1, 6)
+#define GEN7_3DSTATE_POLY_STIPPLE_PATTERN      GEN7_3D(3, 1, 7)
+#define GEN7_3DSTATE_LINE_STIPPLE              GEN7_3D(3, 1, 8)
+#define GEN7_3DSTATE_GLOBAL_DEPTH_OFFSET_CLAMP GEN7_3D(3, 1, 9)
+/* These two are BLC and CTG only, not BW or CL */
+#define GEN7_3DSTATE_AA_LINE_PARAMS            GEN7_3D(3, 1, 0xa)
+#define GEN7_3DSTATE_GS_SVB_INDEX              GEN7_3D(3, 1, 0xb)
+
+#define GEN7_3DPRIMITIVE                               GEN7_3D(3, 3, 0)
+
+#define GEN7_3DSTATE_SAMPLER_STATE_POINTERS    GEN7_3D(3, 0, 0x02)
+# define GEN7_3DSTATE_SAMPLER_STATE_MODIFY_PS  (1 << 12)
+# define GEN7_3DSTATE_SAMPLER_STATE_MODIFY_GS  (1 << 9)
+# define GEN7_3DSTATE_SAMPLER_STATE_MODIFY_VS  (1 << 8)
+
+#define GEN7_3DSTATE_URB                       GEN7_3D(3, 0, 0x05)
+/* DW1 */
+# define GEN7_3DSTATE_URB_VS_SIZE_SHIFT                16
+# define GEN7_3DSTATE_URB_VS_ENTRIES_SHIFT     0
+/* DW2 */
+# define GEN7_3DSTATE_URB_GS_ENTRIES_SHIFT     8
+# define GEN7_3DSTATE_URB_GS_SIZE_SHIFT                0
+
+#define GEN7_3DSTATE_VIEWPORT_STATE_POINTERS   GEN7_3D(3, 0, 0x0d)
+# define GEN7_3DSTATE_VIEWPORT_STATE_MODIFY_CC         (1 << 12)
+# define GEN7_3DSTATE_VIEWPORT_STATE_MODIFY_SF         (1 << 11)
+# define GEN7_3DSTATE_VIEWPORT_STATE_MODIFY_CLIP       (1 << 10)
+
+#define GEN7_3DSTATE_CC_STATE_POINTERS         GEN7_3D(3, 0, 0x0e)
+
+#define GEN7_3DSTATE_VS                                GEN7_3D(3, 0, 0x10)
+
+#define GEN7_3DSTATE_GS                                GEN7_3D(3, 0, 0x11)
+/* DW4 */
+# define GEN7_3DSTATE_GS_DISPATCH_START_GRF_SHIFT      0
+
+#define GEN7_3DSTATE_CLIP                      GEN7_3D(3, 0, 0x12)
+
+#define GEN7_3DSTATE_SF                                GEN7_3D(3, 0, 0x13)
+/* DW1 */
+# define GEN7_3DSTATE_SF_NUM_OUTPUTS_SHIFT             22
+# define GEN7_3DSTATE_SF_URB_ENTRY_READ_LENGTH_SHIFT   11
+# define GEN7_3DSTATE_SF_URB_ENTRY_READ_OFFSET_SHIFT   4
+/* DW2 */
+/* DW3 */
+# define GEN7_3DSTATE_SF_CULL_BOTH                     (0 << 29)
+# define GEN7_3DSTATE_SF_CULL_NONE                     (1 << 29)
+# define GEN7_3DSTATE_SF_CULL_FRONT                    (2 << 29)
+# define GEN7_3DSTATE_SF_CULL_BACK                     (3 << 29)
+/* DW4 */
+# define GEN7_3DSTATE_SF_TRI_PROVOKE_SHIFT             29
+# define GEN7_3DSTATE_SF_LINE_PROVOKE_SHIFT            27
+# define GEN7_3DSTATE_SF_TRIFAN_PROVOKE_SHIFT          25
+
+#define GEN7_3DSTATE_WM                                GEN7_3D(3, 0, 0x14)
+/* DW1 */
+# define GEN7_WM_STATISTICS_ENABLE                              (1 << 31)
+# define GEN7_WM_DEPTH_CLEAR                                    (1 << 30)
+# define GEN7_WM_DISPATCH_ENABLE                                (1 << 29)
+# define GEN7_WM_DEPTH_RESOLVE                                  (1 << 28)
+# define GEN7_WM_HIERARCHICAL_DEPTH_RESOLVE                     (1 << 27)
+# define GEN7_WM_KILL_ENABLE                                    (1 << 25)
+# define GEN7_WM_PSCDEPTH_OFF                                   (0 << 23)
+# define GEN7_WM_PSCDEPTH_ON                                    (1 << 23)
+# define GEN7_WM_PSCDEPTH_ON_GE                                 (2 << 23)
+# define GEN7_WM_PSCDEPTH_ON_LE                                 (3 << 23)
+# define GEN7_WM_USES_SOURCE_DEPTH                              (1 << 20)
+# define GEN7_WM_USES_SOURCE_W                                  (1 << 19)
+# define GEN7_WM_POSITION_ZW_PIXEL                              (0 << 17)
+# define GEN7_WM_POSITION_ZW_CENTROID                           (2 << 17)
+# define GEN7_WM_POSITION_ZW_SAMPLE                             (3 << 17)
+# define GEN7_WM_NONPERSPECTIVE_SAMPLE_BARYCENTRIC              (1 << 16)
+# define GEN7_WM_NONPERSPECTIVE_CENTROID_BARYCENTRIC            (1 << 15)
+# define GEN7_WM_NONPERSPECTIVE_PIXEL_BARYCENTRIC               (1 << 14)
+# define GEN7_WM_PERSPECTIVE_SAMPLE_BARYCENTRIC                 (1 << 13)
+# define GEN7_WM_PERSPECTIVE_CENTROID_BARYCENTRIC               (1 << 12)
+# define GEN7_WM_PERSPECTIVE_PIXEL_BARYCENTRIC                  (1 << 11)
+# define GEN7_WM_USES_INPUT_COVERAGE_MASK                       (1 << 10)
+# define GEN7_WM_LINE_END_CAP_AA_WIDTH_0_5                      (0 << 8)
+# define GEN7_WM_LINE_END_CAP_AA_WIDTH_1_0                      (1 << 8)
+# define GEN7_WM_LINE_END_CAP_AA_WIDTH_2_0                      (2 << 8)
+# define GEN7_WM_LINE_END_CAP_AA_WIDTH_4_0                      (3 << 8)
+# define GEN7_WM_LINE_AA_WIDTH_0_5                              (0 << 6)
+# define GEN7_WM_LINE_AA_WIDTH_1_0                              (1 << 6)
+# define GEN7_WM_LINE_AA_WIDTH_2_0                              (2 << 6)
+# define GEN7_WM_LINE_AA_WIDTH_4_0                              (3 << 6)
+# define GEN7_WM_POLYGON_STIPPLE_ENABLE                         (1 << 4)
+# define GEN7_WM_LINE_STIPPLE_ENABLE                            (1 << 3)
+# define GEN7_WM_POINT_RASTRULE_UPPER_RIGHT                     (1 << 2)
+# define GEN7_WM_MSRAST_OFF_PIXEL                               (0 << 0)
+# define GEN7_WM_MSRAST_OFF_PATTERN                             (1 << 0)
+# define GEN7_WM_MSRAST_ON_PIXEL                                (2 << 0)
+# define GEN7_WM_MSRAST_ON_PATTERN                              (3 << 0)
+/* DW2 */
+# define GEN7_WM_MSDISPMODE_PERPIXEL                            (1 << 31)
+
+
+#define GEN7_3DSTATE_CONSTANT_VS               GEN7_3D(3, 0, 0x15)
+#define GEN7_3DSTATE_CONSTANT_GS               GEN7_3D(3, 0, 0x16)
+#define GEN7_3DSTATE_CONSTANT_PS               GEN7_3D(3, 0, 0x17)
+
+#define GEN7_3DSTATE_SAMPLE_MASK               GEN7_3D(3, 0, 0x18)
+
+#define GEN7_3DSTATE_MULTISAMPLE               GEN7_3D(3, 1, 0x0d)
+/* DW1 */
+# define GEN7_3DSTATE_MULTISAMPLE_PIXEL_LOCATION_CENTER                (0 << 4)
+# define GEN7_3DSTATE_MULTISAMPLE_PIXEL_LOCATION_UPPER_LEFT    (1 << 4)
+# define GEN7_3DSTATE_MULTISAMPLE_NUMSAMPLES_1                 (0 << 1)
+# define GEN7_3DSTATE_MULTISAMPLE_NUMSAMPLES_4                 (2 << 1)
+# define GEN7_3DSTATE_MULTISAMPLE_NUMSAMPLES_8                 (3 << 1)
+
+#define PIPELINE_SELECT_3D             0
+#define PIPELINE_SELECT_MEDIA          1
+
+/* for GEN7_STATE_BASE_ADDRESS */
+#define BASE_ADDRESS_MODIFY            (1 << 0)
+
+/* for GEN7_PIPE_CONTROL */
+#define GEN7_PIPE_CONTROL                      GEN7_3D(3, 2, 0)
+#define GEN7_PIPE_CONTROL_CS_STALL      (1 << 20)
+#define GEN7_PIPE_CONTROL_NOWRITE       (0 << 14)
+#define GEN7_PIPE_CONTROL_WRITE_QWORD   (1 << 14)
+#define GEN7_PIPE_CONTROL_WRITE_DEPTH   (2 << 14)
+#define GEN7_PIPE_CONTROL_WRITE_TIME    (3 << 14)
+#define GEN7_PIPE_CONTROL_DEPTH_STALL   (1 << 13)
+#define GEN7_PIPE_CONTROL_WC_FLUSH      (1 << 12)
+#define GEN7_PIPE_CONTROL_IS_FLUSH      (1 << 11)
+#define GEN7_PIPE_CONTROL_TC_FLUSH      (1 << 10)
+#define GEN7_PIPE_CONTROL_NOTIFY_ENABLE (1 << 8)
+#define GEN7_PIPE_CONTROL_GLOBAL_GTT    (1 << 2)
+#define GEN7_PIPE_CONTROL_LOCAL_PGTT    (0 << 2)
+#define GEN7_PIPE_CONTROL_STALL_AT_SCOREBOARD   (1 << 1)
+#define GEN7_PIPE_CONTROL_DEPTH_CACHE_FLUSH    (1 << 0)
+
+/* VERTEX_BUFFER_STATE Structure */
+#define GEN7_VB0_BUFFER_INDEX_SHIFT    26
+#define GEN7_VB0_VERTEXDATA            (0 << 20)
+#define GEN7_VB0_INSTANCEDATA          (1 << 20)
+#define GEN7_VB0_BUFFER_PITCH_SHIFT    0
+#define GEN7_VB0_ADDRESS_MODIFY_ENABLE (1 << 14)
+
+/* VERTEX_ELEMENT_STATE Structure */
+#define GEN7_VE0_VERTEX_BUFFER_INDEX_SHIFT             26
+#define GEN7_VE0_VALID                                 (1 << 25)
+#define GEN7_VE0_FORMAT_SHIFT                          16
+#define GEN7_VE0_OFFSET_SHIFT                          0
+#define GEN7_VE1_VFCOMPONENT_0_SHIFT                   28
+#define GEN7_VE1_VFCOMPONENT_1_SHIFT                   24
+#define GEN7_VE1_VFCOMPONENT_2_SHIFT                   20
+#define GEN7_VE1_VFCOMPONENT_3_SHIFT                   16
+#define GEN7_VE1_DESTINATION_ELEMENT_OFFSET_SHIFT      0
+
+/* 3DPRIMITIVE bits */
+#define GEN7_3DPRIMITIVE_VERTEX_SEQUENTIAL (0 << 15)
+#define GEN7_3DPRIMITIVE_VERTEX_RANDOM   (1 << 15)
+
+#define GEN7_SVG_CTL                  0x7400
+
+#define GEN7_SVG_CTL_GS_BA            (0 << 8)
+#define GEN7_SVG_CTL_SS_BA            (1 << 8)
+#define GEN7_SVG_CTL_IO_BA            (2 << 8)
+#define GEN7_SVG_CTL_GS_AUB           (3 << 8)
+#define GEN7_SVG_CTL_IO_AUB           (4 << 8)
+#define GEN7_SVG_CTL_SIP                      (5 << 8)
+
+#define GEN7_VF_CTL_SNAPSHOT_COMPLETE             (1 << 31)
+#define GEN7_VF_CTL_SNAPSHOT_MUX_SELECT_THREADID          (0 << 8)
+#define GEN7_VF_CTL_SNAPSHOT_MUX_SELECT_VF_DEBUG          (1 << 8)
+#define GEN7_VF_CTL_SNAPSHOT_TYPE_VERTEX_SEQUENCE   (0 << 4)
+#define GEN7_VF_CTL_SNAPSHOT_TYPE_VERTEX_INDEX    (1 << 4)
+#define GEN7_VF_CTL_SKIP_INITIAL_PRIMITIVES       (1 << 3)
+#define GEN7_VF_CTL_MAX_PRIMITIVES_LIMIT_ENABLE           (1 << 2)
+#define GEN7_VF_CTL_VERTEX_RANGE_LIMIT_ENABLE     (1 << 1)
+#define GEN7_VF_CTL_SNAPSHOT_ENABLE               (1 << 0)
+
+#define GEN7_VF_STRG_VAL                      0x7504
+#define GEN7_VF_STR_VL_OVR            0x7508
+#define GEN7_VF_VC_OVR                0x750c
+#define GEN7_VF_STR_PSKIP             0x7510
+#define GEN7_VF_MAX_PRIM                      0x7514
+#define GEN7_VF_RDATA                 0x7518
+
+#define GEN7_VS_CTL                   0x7600
+#define GEN7_VS_CTL_SNAPSHOT_COMPLETE             (1 << 31)
+#define GEN7_VS_CTL_SNAPSHOT_MUX_VERTEX_0         (0 << 8)
+#define GEN7_VS_CTL_SNAPSHOT_MUX_VERTEX_1         (1 << 8)
+#define GEN7_VS_CTL_SNAPSHOT_MUX_VALID_COUNT      (2 << 8)
+#define GEN7_VS_CTL_SNAPSHOT_MUX_VS_KERNEL_POINTER  (3 << 8)
+#define GEN7_VS_CTL_SNAPSHOT_ALL_THREADS                  (1 << 2)
+#define GEN7_VS_CTL_THREAD_SNAPSHOT_ENABLE        (1 << 1)
+#define GEN7_VS_CTL_SNAPSHOT_ENABLE               (1 << 0)
+
+#define GEN7_VS_STRG_VAL                      0x7604
+#define GEN7_VS_RDATA                 0x7608
+
+#define GEN7_SF_CTL                   0x7b00
+#define GEN7_SF_CTL_SNAPSHOT_COMPLETE             (1 << 31)
+#define GEN7_SF_CTL_SNAPSHOT_MUX_VERTEX_0_FF_ID           (0 << 8)
+#define GEN7_SF_CTL_SNAPSHOT_MUX_VERTEX_0_REL_COUNT (1 << 8)
+#define GEN7_SF_CTL_SNAPSHOT_MUX_VERTEX_1_FF_ID           (2 << 8)
+#define GEN7_SF_CTL_SNAPSHOT_MUX_VERTEX_1_REL_COUNT (3 << 8)
+#define GEN7_SF_CTL_SNAPSHOT_MUX_VERTEX_2_FF_ID           (4 << 8)
+#define GEN7_SF_CTL_SNAPSHOT_MUX_VERTEX_2_REL_COUNT (5 << 8)
+#define GEN7_SF_CTL_SNAPSHOT_MUX_VERTEX_COUNT     (6 << 8)
+#define GEN7_SF_CTL_SNAPSHOT_MUX_SF_KERNEL_POINTER  (7 << 8)
+#define GEN7_SF_CTL_MIN_MAX_PRIMITIVE_RANGE_ENABLE  (1 << 4)
+#define GEN7_SF_CTL_DEBUG_CLIP_RECTANGLE_ENABLE           (1 << 3)
+#define GEN7_SF_CTL_SNAPSHOT_ALL_THREADS                  (1 << 2)
+#define GEN7_SF_CTL_THREAD_SNAPSHOT_ENABLE        (1 << 1)
+#define GEN7_SF_CTL_SNAPSHOT_ENABLE               (1 << 0)
+
+#define GEN7_SF_STRG_VAL                      0x7b04
+#define GEN7_SF_RDATA                 0x7b18
+
+#define GEN7_WIZ_CTL                  0x7c00
+#define GEN7_WIZ_CTL_SNAPSHOT_COMPLETE            (1 << 31)
+#define GEN7_WIZ_CTL_SUBSPAN_INSTANCE_SHIFT       16
+#define GEN7_WIZ_CTL_SNAPSHOT_MUX_WIZ_KERNEL_POINTER   (0 << 8)
+#define GEN7_WIZ_CTL_SNAPSHOT_MUX_SUBSPAN_INSTANCE     (1 << 8)
+#define GEN7_WIZ_CTL_SNAPSHOT_MUX_PRIMITIVE_SEQUENCE   (2 << 8)
+#define GEN7_WIZ_CTL_SINGLE_SUBSPAN_DISPATCH         (1 << 6)
+#define GEN7_WIZ_CTL_IGNORE_COLOR_SCOREBOARD_STALLS    (1 << 5)
+#define GEN7_WIZ_CTL_ENABLE_SUBSPAN_INSTANCE_COMPARE   (1 << 4)
+#define GEN7_WIZ_CTL_USE_UPSTREAM_SNAPSHOT_FLAG              (1 << 3)
+#define GEN7_WIZ_CTL_SNAPSHOT_ALL_THREADS            (1 << 2)
+#define GEN7_WIZ_CTL_THREAD_SNAPSHOT_ENABLE          (1 << 1)
+#define GEN7_WIZ_CTL_SNAPSHOT_ENABLE                 (1 << 0)
+
+#define GEN7_WIZ_STRG_VAL                            0x7c04
+#define GEN7_WIZ_RDATA                               0x7c18
+
+#define GEN7_TS_CTL                   0x7e00
+#define GEN7_TS_CTL_SNAPSHOT_COMPLETE             (1 << 31)
+#define GEN7_TS_CTL_SNAPSHOT_MESSAGE_ERROR        (0 << 8)
+#define GEN7_TS_CTL_SNAPSHOT_INTERFACE_DESCRIPTOR   (3 << 8)
+#define GEN7_TS_CTL_SNAPSHOT_ALL_CHILD_THREADS    (1 << 2)
+#define GEN7_TS_CTL_SNAPSHOT_ALL_ROOT_THREADS     (1 << 1)
+#define GEN7_TS_CTL_SNAPSHOT_ENABLE               (1 << 0)
+
+#define GEN7_TS_STRG_VAL                      0x7e04
+#define GEN7_TS_RDATA                 0x7e08
+
+#define GEN7_TD_CTL                   0x8000
+#define GEN7_TD_CTL_MUX_SHIFT         8
+#define GEN7_TD_CTL_EXTERNAL_HALT_R0_DEBUG_MATCH          (1 << 7)
+#define GEN7_TD_CTL_FORCE_EXTERNAL_HALT                   (1 << 6)
+#define GEN7_TD_CTL_EXCEPTION_MASK_OVERRIDE       (1 << 5)
+#define GEN7_TD_CTL_FORCE_THREAD_BREAKPOINT_ENABLE  (1 << 4)
+#define GEN7_TD_CTL_BREAKPOINT_ENABLE             (1 << 2)
+#define GEN7_TD_CTL2                  0x8004
+#define GEN7_TD_CTL2_ILLEGAL_OPCODE_EXCEPTION_OVERRIDE (1 << 28)
+#define GEN7_TD_CTL2_MASKSTACK_EXCEPTION_OVERRIDE      (1 << 26)
+#define GEN7_TD_CTL2_SOFTWARE_EXCEPTION_OVERRIDE             (1 << 25)
+#define GEN7_TD_CTL2_ACTIVE_THREAD_LIMIT_SHIFT       16
+#define GEN7_TD_CTL2_ACTIVE_THREAD_LIMIT_ENABLE              (1 << 8)
+#define GEN7_TD_CTL2_THREAD_SPAWNER_EXECUTION_MASK_ENABLE (1 << 7)
+#define GEN7_TD_CTL2_WIZ_EXECUTION_MASK_ENABLE       (1 << 6)
+#define GEN7_TD_CTL2_SF_EXECUTION_MASK_ENABLE        (1 << 5)
+#define GEN7_TD_CTL2_CLIPPER_EXECUTION_MASK_ENABLE     (1 << 4)
+#define GEN7_TD_CTL2_GS_EXECUTION_MASK_ENABLE        (1 << 3)
+#define GEN7_TD_CTL2_VS_EXECUTION_MASK_ENABLE        (1 << 0)
+#define GEN7_TD_VF_VS_EMSK            0x8008
+#define GEN7_TD_GS_EMSK                       0x800c
+#define GEN7_TD_CLIP_EMSK             0x8010
+#define GEN7_TD_SF_EMSK                       0x8014
+#define GEN7_TD_WIZ_EMSK                      0x8018
+#define GEN7_TD_0_6_EHTRG_VAL         0x801c
+#define GEN7_TD_0_7_EHTRG_VAL         0x8020
+#define GEN7_TD_0_6_EHTRG_MSK           0x8024
+#define GEN7_TD_0_7_EHTRG_MSK         0x8028
+#define GEN7_TD_RDATA                 0x802c
+#define GEN7_TD_TS_EMSK                       0x8030
+
+#define GEN7_EU_CTL                   0x8800
+#define GEN7_EU_CTL_SELECT_SHIFT              16
+#define GEN7_EU_CTL_DATA_MUX_SHIFT      8
+#define GEN7_EU_ATT_0                 0x8810
+#define GEN7_EU_ATT_1                 0x8814
+#define GEN7_EU_ATT_DATA_0            0x8820
+#define GEN7_EU_ATT_DATA_1            0x8824
+#define GEN7_EU_ATT_CLR_0             0x8830
+#define GEN7_EU_ATT_CLR_1             0x8834
+#define GEN7_EU_RDATA                 0x8840
+
+#define _3DPRIM_POINTLIST         0x01
+#define _3DPRIM_LINELIST          0x02
+#define _3DPRIM_LINESTRIP         0x03
+#define _3DPRIM_TRILIST           0x04
+#define _3DPRIM_TRISTRIP          0x05
+#define _3DPRIM_TRIFAN            0x06
+#define _3DPRIM_QUADLIST          0x07
+#define _3DPRIM_QUADSTRIP         0x08
+#define _3DPRIM_LINELIST_ADJ      0x09
+#define _3DPRIM_LINESTRIP_ADJ     0x0A
+#define _3DPRIM_TRILIST_ADJ       0x0B
+#define _3DPRIM_TRISTRIP_ADJ      0x0C
+#define _3DPRIM_TRISTRIP_REVERSE  0x0D
+#define _3DPRIM_POLYGON           0x0E
+#define _3DPRIM_RECTLIST          0x0F
+#define _3DPRIM_LINELOOP          0x10
+#define _3DPRIM_POINTLIST_BF      0x11
+#define _3DPRIM_LINESTRIP_CONT    0x12
+#define _3DPRIM_LINESTRIP_BF      0x13
+#define _3DPRIM_LINESTRIP_CONT_BF 0x14
+#define _3DPRIM_TRIFAN_NOSTIPPLE  0x15
+
+#define _3DPRIM_VERTEXBUFFER_ACCESS_SEQUENTIAL 0
+#define _3DPRIM_VERTEXBUFFER_ACCESS_RANDOM     1
+
+#define GEN7_ANISORATIO_2     0
+#define GEN7_ANISORATIO_4     1
+#define GEN7_ANISORATIO_6     2
+#define GEN7_ANISORATIO_8     3
+#define GEN7_ANISORATIO_10    4
+#define GEN7_ANISORATIO_12    5
+#define GEN7_ANISORATIO_14    6
+#define GEN7_ANISORATIO_16    7
+
+#define GEN7_BLENDFACTOR_ONE                 0x1
+#define GEN7_BLENDFACTOR_SRC_COLOR           0x2
+#define GEN7_BLENDFACTOR_SRC_ALPHA           0x3
+#define GEN7_BLENDFACTOR_DST_ALPHA           0x4
+#define GEN7_BLENDFACTOR_DST_COLOR           0x5
+#define GEN7_BLENDFACTOR_SRC_ALPHA_SATURATE  0x6
+#define GEN7_BLENDFACTOR_CONST_COLOR         0x7
+#define GEN7_BLENDFACTOR_CONST_ALPHA         0x8
+#define GEN7_BLENDFACTOR_SRC1_COLOR          0x9
+#define GEN7_BLENDFACTOR_SRC1_ALPHA          0x0A
+#define GEN7_BLENDFACTOR_ZERO                0x11
+#define GEN7_BLENDFACTOR_INV_SRC_COLOR       0x12
+#define GEN7_BLENDFACTOR_INV_SRC_ALPHA       0x13
+#define GEN7_BLENDFACTOR_INV_DST_ALPHA       0x14
+#define GEN7_BLENDFACTOR_INV_DST_COLOR       0x15
+#define GEN7_BLENDFACTOR_INV_CONST_COLOR     0x17
+#define GEN7_BLENDFACTOR_INV_CONST_ALPHA     0x18
+#define GEN7_BLENDFACTOR_INV_SRC1_COLOR      0x19
+#define GEN7_BLENDFACTOR_INV_SRC1_ALPHA      0x1A
+
+#define GEN7_BLENDFUNCTION_ADD               0
+#define GEN7_BLENDFUNCTION_SUBTRACT          1
+#define GEN7_BLENDFUNCTION_REVERSE_SUBTRACT  2
+#define GEN7_BLENDFUNCTION_MIN               3
+#define GEN7_BLENDFUNCTION_MAX               4
+
+#define GEN7_ALPHATEST_FORMAT_UNORM8         0
+#define GEN7_ALPHATEST_FORMAT_FLOAT32        1
+
+#define GEN7_CHROMAKEY_KILL_ON_ANY_MATCH  0
+#define GEN7_CHROMAKEY_REPLACE_BLACK      1
+
+#define GEN7_CLIP_API_OGL     0
+#define GEN7_CLIP_API_DX      1
+
+#define GEN7_CLIPMODE_NORMAL              0
+#define GEN7_CLIPMODE_CLIP_ALL            1
+#define GEN7_CLIPMODE_CLIP_NON_REJECTED   2
+#define GEN7_CLIPMODE_REJECT_ALL          3
+#define GEN7_CLIPMODE_ACCEPT_ALL          4
+
+#define GEN7_CLIP_NDCSPACE     0
+#define GEN7_CLIP_SCREENSPACE  1
+
+#define GEN7_COMPAREFUNCTION_ALWAYS       0
+#define GEN7_COMPAREFUNCTION_NEVER        1
+#define GEN7_COMPAREFUNCTION_LESS         2
+#define GEN7_COMPAREFUNCTION_EQUAL        3
+#define GEN7_COMPAREFUNCTION_LEQUAL       4
+#define GEN7_COMPAREFUNCTION_GREATER      5
+#define GEN7_COMPAREFUNCTION_NOTEQUAL     6
+#define GEN7_COMPAREFUNCTION_GEQUAL       7
+
+#define GEN7_COVERAGE_PIXELS_HALF     0
+#define GEN7_COVERAGE_PIXELS_1        1
+#define GEN7_COVERAGE_PIXELS_2        2
+#define GEN7_COVERAGE_PIXELS_4        3
+
+#define GEN7_CULLMODE_BOTH        0
+#define GEN7_CULLMODE_NONE        1
+#define GEN7_CULLMODE_FRONT       2
+#define GEN7_CULLMODE_BACK        3
+
+#define GEN7_DEFAULTCOLOR_R8G8B8A8_UNORM      0
+#define GEN7_DEFAULTCOLOR_R32G32B32A32_FLOAT  1
+
+#define GEN7_DEPTHFORMAT_D32_FLOAT_S8X24_UINT     0
+#define GEN7_DEPTHFORMAT_D32_FLOAT                1
+#define GEN7_DEPTHFORMAT_D24_UNORM_S8_UINT        2
+#define GEN7_DEPTHFORMAT_D16_UNORM                5
+
+#define GEN7_FLOATING_POINT_IEEE_754        0
+#define GEN7_FLOATING_POINT_NON_IEEE_754    1
+
+#define GEN7_FRONTWINDING_CW      0
+#define GEN7_FRONTWINDING_CCW     1
+
+#define GEN7_INDEX_BYTE     0
+#define GEN7_INDEX_WORD     1
+#define GEN7_INDEX_DWORD    2
+
+#define GEN7_LOGICOPFUNCTION_CLEAR            0
+#define GEN7_LOGICOPFUNCTION_NOR              1
+#define GEN7_LOGICOPFUNCTION_AND_INVERTED     2
+#define GEN7_LOGICOPFUNCTION_COPY_INVERTED    3
+#define GEN7_LOGICOPFUNCTION_AND_REVERSE      4
+#define GEN7_LOGICOPFUNCTION_INVERT           5
+#define GEN7_LOGICOPFUNCTION_XOR              6
+#define GEN7_LOGICOPFUNCTION_NAND             7
+#define GEN7_LOGICOPFUNCTION_AND              8
+#define GEN7_LOGICOPFUNCTION_EQUIV            9
+#define GEN7_LOGICOPFUNCTION_NOOP             10
+#define GEN7_LOGICOPFUNCTION_OR_INVERTED      11
+#define GEN7_LOGICOPFUNCTION_COPY             12
+#define GEN7_LOGICOPFUNCTION_OR_REVERSE       13
+#define GEN7_LOGICOPFUNCTION_OR               14
+#define GEN7_LOGICOPFUNCTION_SET              15
+
+#define GEN7_MAPFILTER_NEAREST        0x0
+#define GEN7_MAPFILTER_LINEAR         0x1
+#define GEN7_MAPFILTER_ANISOTROPIC    0x2
+
+#define GEN7_MIPFILTER_NONE        0
+#define GEN7_MIPFILTER_NEAREST     1
+#define GEN7_MIPFILTER_LINEAR      3
+
+#define GEN7_POLYGON_FRONT_FACING     0
+#define GEN7_POLYGON_BACK_FACING      1
+
+#define GEN7_PREFILTER_ALWAYS     0x0
+#define GEN7_PREFILTER_NEVER      0x1
+#define GEN7_PREFILTER_LESS       0x2
+#define GEN7_PREFILTER_EQUAL      0x3
+#define GEN7_PREFILTER_LEQUAL     0x4
+#define GEN7_PREFILTER_GREATER    0x5
+#define GEN7_PREFILTER_NOTEQUAL   0x6
+#define GEN7_PREFILTER_GEQUAL     0x7
+
+#define GEN7_PROVOKING_VERTEX_0    0
+#define GEN7_PROVOKING_VERTEX_1    1
+#define GEN7_PROVOKING_VERTEX_2    2
+
+#define GEN7_RASTRULE_UPPER_LEFT  0
+#define GEN7_RASTRULE_UPPER_RIGHT 1
+
+#define GEN7_RENDERTARGET_CLAMPRANGE_UNORM    0
+#define GEN7_RENDERTARGET_CLAMPRANGE_SNORM    1
+#define GEN7_RENDERTARGET_CLAMPRANGE_FORMAT   2
+
+#define GEN7_STENCILOP_KEEP               0
+#define GEN7_STENCILOP_ZERO               1
+#define GEN7_STENCILOP_REPLACE            2
+#define GEN7_STENCILOP_INCRSAT            3
+#define GEN7_STENCILOP_DECRSAT            4
+#define GEN7_STENCILOP_INCR               5
+#define GEN7_STENCILOP_DECR               6
+#define GEN7_STENCILOP_INVERT             7
+
+#define GEN7_SURFACE_MIPMAPLAYOUT_BELOW   0
+#define GEN7_SURFACE_MIPMAPLAYOUT_RIGHT   1
+
+#define GEN7_SURFACEFORMAT_R32G32B32A32_FLOAT             0x000
+#define GEN7_SURFACEFORMAT_R32G32B32A32_SINT              0x001
+#define GEN7_SURFACEFORMAT_R32G32B32A32_UINT              0x002
+#define GEN7_SURFACEFORMAT_R32G32B32A32_UNORM             0x003
+#define GEN7_SURFACEFORMAT_R32G32B32A32_SNORM             0x004
+#define GEN7_SURFACEFORMAT_R64G64_FLOAT                   0x005
+#define GEN7_SURFACEFORMAT_R32G32B32X32_FLOAT             0x006
+#define GEN7_SURFACEFORMAT_R32G32B32A32_SSCALED           0x007
+#define GEN7_SURFACEFORMAT_R32G32B32A32_USCALED           0x008
+#define GEN7_SURFACEFORMAT_R32G32B32_FLOAT                0x040
+#define GEN7_SURFACEFORMAT_R32G32B32_SINT                 0x041
+#define GEN7_SURFACEFORMAT_R32G32B32_UINT                 0x042
+#define GEN7_SURFACEFORMAT_R32G32B32_UNORM                0x043
+#define GEN7_SURFACEFORMAT_R32G32B32_SNORM                0x044
+#define GEN7_SURFACEFORMAT_R32G32B32_SSCALED              0x045
+#define GEN7_SURFACEFORMAT_R32G32B32_USCALED              0x046
+#define GEN7_SURFACEFORMAT_R16G16B16A16_UNORM             0x080
+#define GEN7_SURFACEFORMAT_R16G16B16A16_SNORM             0x081
+#define GEN7_SURFACEFORMAT_R16G16B16A16_SINT              0x082
+#define GEN7_SURFACEFORMAT_R16G16B16A16_UINT              0x083
+#define GEN7_SURFACEFORMAT_R16G16B16A16_FLOAT             0x084
+#define GEN7_SURFACEFORMAT_R32G32_FLOAT                   0x085
+#define GEN7_SURFACEFORMAT_R32G32_SINT                    0x086
+#define GEN7_SURFACEFORMAT_R32G32_UINT                    0x087
+#define GEN7_SURFACEFORMAT_R32_FLOAT_X8X24_TYPELESS       0x088
+#define GEN7_SURFACEFORMAT_X32_TYPELESS_G8X24_UINT        0x089
+#define GEN7_SURFACEFORMAT_L32A32_FLOAT                   0x08A
+#define GEN7_SURFACEFORMAT_R32G32_UNORM                   0x08B
+#define GEN7_SURFACEFORMAT_R32G32_SNORM                   0x08C
+#define GEN7_SURFACEFORMAT_R64_FLOAT                      0x08D
+#define GEN7_SURFACEFORMAT_R16G16B16X16_UNORM             0x08E
+#define GEN7_SURFACEFORMAT_R16G16B16X16_FLOAT             0x08F
+#define GEN7_SURFACEFORMAT_A32X32_FLOAT                   0x090
+#define GEN7_SURFACEFORMAT_L32X32_FLOAT                   0x091
+#define GEN7_SURFACEFORMAT_I32X32_FLOAT                   0x092
+#define GEN7_SURFACEFORMAT_R16G16B16A16_SSCALED           0x093
+#define GEN7_SURFACEFORMAT_R16G16B16A16_USCALED           0x094
+#define GEN7_SURFACEFORMAT_R32G32_SSCALED                 0x095
+#define GEN7_SURFACEFORMAT_R32G32_USCALED                 0x096
+#define GEN7_SURFACEFORMAT_B8G8R8A8_UNORM                 0x0C0
+#define GEN7_SURFACEFORMAT_B8G8R8A8_UNORM_SRGB            0x0C1
+#define GEN7_SURFACEFORMAT_R10G10B10A2_UNORM              0x0C2
+#define GEN7_SURFACEFORMAT_R10G10B10A2_UNORM_SRGB         0x0C3
+#define GEN7_SURFACEFORMAT_R10G10B10A2_UINT               0x0C4
+#define GEN7_SURFACEFORMAT_R10G10B10_SNORM_A2_UNORM       0x0C5
+#define GEN7_SURFACEFORMAT_R8G8B8A8_UNORM                 0x0C7
+#define GEN7_SURFACEFORMAT_R8G8B8A8_UNORM_SRGB            0x0C8
+#define GEN7_SURFACEFORMAT_R8G8B8A8_SNORM                 0x0C9
+#define GEN7_SURFACEFORMAT_R8G8B8A8_SINT                  0x0CA
+#define GEN7_SURFACEFORMAT_R8G8B8A8_UINT                  0x0CB
+#define GEN7_SURFACEFORMAT_R16G16_UNORM                   0x0CC
+#define GEN7_SURFACEFORMAT_R16G16_SNORM                   0x0CD
+#define GEN7_SURFACEFORMAT_R16G16_SINT                    0x0CE
+#define GEN7_SURFACEFORMAT_R16G16_UINT                    0x0CF
+#define GEN7_SURFACEFORMAT_R16G16_FLOAT                   0x0D0
+#define GEN7_SURFACEFORMAT_B10G10R10A2_UNORM              0x0D1
+#define GEN7_SURFACEFORMAT_B10G10R10A2_UNORM_SRGB         0x0D2
+#define GEN7_SURFACEFORMAT_R11G11B10_FLOAT                0x0D3
+#define GEN7_SURFACEFORMAT_R32_SINT                       0x0D6
+#define GEN7_SURFACEFORMAT_R32_UINT                       0x0D7
+#define GEN7_SURFACEFORMAT_R32_FLOAT                      0x0D8
+#define GEN7_SURFACEFORMAT_R24_UNORM_X8_TYPELESS          0x0D9
+#define GEN7_SURFACEFORMAT_X24_TYPELESS_G8_UINT           0x0DA
+#define GEN7_SURFACEFORMAT_L16A16_UNORM                   0x0DF
+#define GEN7_SURFACEFORMAT_I24X8_UNORM                    0x0E0
+#define GEN7_SURFACEFORMAT_L24X8_UNORM                    0x0E1
+#define GEN7_SURFACEFORMAT_A24X8_UNORM                    0x0E2
+#define GEN7_SURFACEFORMAT_I32_FLOAT                      0x0E3
+#define GEN7_SURFACEFORMAT_L32_FLOAT                      0x0E4
+#define GEN7_SURFACEFORMAT_A32_FLOAT                      0x0E5
+#define GEN7_SURFACEFORMAT_B8G8R8X8_UNORM                 0x0E9
+#define GEN7_SURFACEFORMAT_B8G8R8X8_UNORM_SRGB            0x0EA
+#define GEN7_SURFACEFORMAT_R8G8B8X8_UNORM                 0x0EB
+#define GEN7_SURFACEFORMAT_R8G8B8X8_UNORM_SRGB            0x0EC
+#define GEN7_SURFACEFORMAT_R9G9B9E5_SHAREDEXP             0x0ED
+#define GEN7_SURFACEFORMAT_B10G10R10X2_UNORM              0x0EE
+#define GEN7_SURFACEFORMAT_L16A16_FLOAT                   0x0F0
+#define GEN7_SURFACEFORMAT_R32_UNORM                      0x0F1
+#define GEN7_SURFACEFORMAT_R32_SNORM                      0x0F2
+#define GEN7_SURFACEFORMAT_R10G10B10X2_USCALED            0x0F3
+#define GEN7_SURFACEFORMAT_R8G8B8A8_SSCALED               0x0F4
+#define GEN7_SURFACEFORMAT_R8G8B8A8_USCALED               0x0F5
+#define GEN7_SURFACEFORMAT_R16G16_SSCALED                 0x0F6
+#define GEN7_SURFACEFORMAT_R16G16_USCALED                 0x0F7
+#define GEN7_SURFACEFORMAT_R32_SSCALED                    0x0F8
+#define GEN7_SURFACEFORMAT_R32_USCALED                    0x0F9
+#define GEN7_SURFACEFORMAT_B5G6R5_UNORM                   0x100
+#define GEN7_SURFACEFORMAT_B5G6R5_UNORM_SRGB              0x101
+#define GEN7_SURFACEFORMAT_B5G5R5A1_UNORM                 0x102
+#define GEN7_SURFACEFORMAT_B5G5R5A1_UNORM_SRGB            0x103
+#define GEN7_SURFACEFORMAT_B4G4R4A4_UNORM                 0x104
+#define GEN7_SURFACEFORMAT_B4G4R4A4_UNORM_SRGB            0x105
+#define GEN7_SURFACEFORMAT_R8G8_UNORM                     0x106
+#define GEN7_SURFACEFORMAT_R8G8_SNORM                     0x107
+#define GEN7_SURFACEFORMAT_R8G8_SINT                      0x108
+#define GEN7_SURFACEFORMAT_R8G8_UINT                      0x109
+#define GEN7_SURFACEFORMAT_R16_UNORM                      0x10A
+#define GEN7_SURFACEFORMAT_R16_SNORM                      0x10B
+#define GEN7_SURFACEFORMAT_R16_SINT                       0x10C
+#define GEN7_SURFACEFORMAT_R16_UINT                       0x10D
+#define GEN7_SURFACEFORMAT_R16_FLOAT                      0x10E
+#define GEN7_SURFACEFORMAT_I16_UNORM                      0x111
+#define GEN7_SURFACEFORMAT_L16_UNORM                      0x112
+#define GEN7_SURFACEFORMAT_A16_UNORM                      0x113
+#define GEN7_SURFACEFORMAT_L8A8_UNORM                     0x114
+#define GEN7_SURFACEFORMAT_I16_FLOAT                      0x115
+#define GEN7_SURFACEFORMAT_L16_FLOAT                      0x116
+#define GEN7_SURFACEFORMAT_A16_FLOAT                      0x117
+#define GEN7_SURFACEFORMAT_R5G5_SNORM_B6_UNORM            0x119
+#define GEN7_SURFACEFORMAT_B5G5R5X1_UNORM                 0x11A
+#define GEN7_SURFACEFORMAT_B5G5R5X1_UNORM_SRGB            0x11B
+#define GEN7_SURFACEFORMAT_R8G8_SSCALED                   0x11C
+#define GEN7_SURFACEFORMAT_R8G8_USCALED                   0x11D
+#define GEN7_SURFACEFORMAT_R16_SSCALED                    0x11E
+#define GEN7_SURFACEFORMAT_R16_USCALED                    0x11F
+#define GEN7_SURFACEFORMAT_R8_UNORM                       0x140
+#define GEN7_SURFACEFORMAT_R8_SNORM                       0x141
+#define GEN7_SURFACEFORMAT_R8_SINT                        0x142
+#define GEN7_SURFACEFORMAT_R8_UINT                        0x143
+#define GEN7_SURFACEFORMAT_A8_UNORM                       0x144
+#define GEN7_SURFACEFORMAT_I8_UNORM                       0x145
+#define GEN7_SURFACEFORMAT_L8_UNORM                       0x146
+#define GEN7_SURFACEFORMAT_P4A4_UNORM                     0x147
+#define GEN7_SURFACEFORMAT_A4P4_UNORM                     0x148
+#define GEN7_SURFACEFORMAT_R8_SSCALED                     0x149
+#define GEN7_SURFACEFORMAT_R8_USCALED                     0x14A
+#define GEN7_SURFACEFORMAT_R1_UINT                        0x181
+#define GEN7_SURFACEFORMAT_YCRCB_NORMAL                   0x182
+#define GEN7_SURFACEFORMAT_YCRCB_SWAPUVY                  0x183
+#define GEN7_SURFACEFORMAT_BC1_UNORM                      0x186
+#define GEN7_SURFACEFORMAT_BC2_UNORM                      0x187
+#define GEN7_SURFACEFORMAT_BC3_UNORM                      0x188
+#define GEN7_SURFACEFORMAT_BC4_UNORM                      0x189
+#define GEN7_SURFACEFORMAT_BC5_UNORM                      0x18A
+#define GEN7_SURFACEFORMAT_BC1_UNORM_SRGB                 0x18B
+#define GEN7_SURFACEFORMAT_BC2_UNORM_SRGB                 0x18C
+#define GEN7_SURFACEFORMAT_BC3_UNORM_SRGB                 0x18D
+#define GEN7_SURFACEFORMAT_MONO8                          0x18E
+#define GEN7_SURFACEFORMAT_YCRCB_SWAPUV                   0x18F
+#define GEN7_SURFACEFORMAT_YCRCB_SWAPY                    0x190
+#define GEN7_SURFACEFORMAT_DXT1_RGB                       0x191
+#define GEN7_SURFACEFORMAT_FXT1                           0x192
+#define GEN7_SURFACEFORMAT_R8G8B8_UNORM                   0x193
+#define GEN7_SURFACEFORMAT_R8G8B8_SNORM                   0x194
+#define GEN7_SURFACEFORMAT_R8G8B8_SSCALED                 0x195
+#define GEN7_SURFACEFORMAT_R8G8B8_USCALED                 0x196
+#define GEN7_SURFACEFORMAT_R64G64B64A64_FLOAT             0x197
+#define GEN7_SURFACEFORMAT_R64G64B64_FLOAT                0x198
+#define GEN7_SURFACEFORMAT_BC4_SNORM                      0x199
+#define GEN7_SURFACEFORMAT_BC5_SNORM                      0x19A
+#define GEN7_SURFACEFORMAT_R16G16B16_UNORM                0x19C
+#define GEN7_SURFACEFORMAT_R16G16B16_SNORM                0x19D
+#define GEN7_SURFACEFORMAT_R16G16B16_SSCALED              0x19E
+#define GEN7_SURFACEFORMAT_R16G16B16_USCALED              0x19F
+
+#define GEN7_SURFACERETURNFORMAT_FLOAT32  0
+#define GEN7_SURFACERETURNFORMAT_S1       1
+
+#define GEN7_SURFACE_1D      0
+#define GEN7_SURFACE_2D      1
+#define GEN7_SURFACE_3D      2
+#define GEN7_SURFACE_CUBE    3
+#define GEN7_SURFACE_BUFFER  4
+#define GEN7_SURFACE_NULL    7
+
+#define GEN7_BORDER_COLOR_MODE_DEFAULT 0
+#define GEN7_BORDER_COLOR_MODE_LEGACY  1
+
+#define GEN7_TEXCOORDMODE_WRAP            0
+#define GEN7_TEXCOORDMODE_MIRROR          1
+#define GEN7_TEXCOORDMODE_CLAMP           2
+#define GEN7_TEXCOORDMODE_CUBE            3
+#define GEN7_TEXCOORDMODE_CLAMP_BORDER    4
+#define GEN7_TEXCOORDMODE_MIRROR_ONCE     5
+
+#define GEN7_THREAD_PRIORITY_NORMAL   0
+#define GEN7_THREAD_PRIORITY_HIGH     1
+
+#define GEN7_TILEWALK_XMAJOR                 0
+#define GEN7_TILEWALK_YMAJOR                 1
+
+#define GEN7_VERTEX_SUBPIXEL_PRECISION_8BITS  0
+#define GEN7_VERTEX_SUBPIXEL_PRECISION_4BITS  1
+
+#define GEN7_VERTEXBUFFER_ACCESS_VERTEXDATA     0
+#define GEN7_VERTEXBUFFER_ACCESS_INSTANCEDATA   1
+
+#define GEN7_VFCOMPONENT_NOSTORE      0
+#define GEN7_VFCOMPONENT_STORE_SRC    1
+#define GEN7_VFCOMPONENT_STORE_0      2
+#define GEN7_VFCOMPONENT_STORE_1_FLT  3
+#define GEN7_VFCOMPONENT_STORE_1_INT  4
+#define GEN7_VFCOMPONENT_STORE_VID    5
+#define GEN7_VFCOMPONENT_STORE_IID    6
+#define GEN7_VFCOMPONENT_STORE_PID    7
+
+
+/* Execution Unit (EU) defines
+ */
+
+#define GEN7_ALIGN_1   0
+#define GEN7_ALIGN_16  1
+
+#define GEN7_ADDRESS_DIRECT                        0
+#define GEN7_ADDRESS_REGISTER_INDIRECT_REGISTER    1
+
+#define GEN7_CHANNEL_X     0
+#define GEN7_CHANNEL_Y     1
+#define GEN7_CHANNEL_Z     2
+#define GEN7_CHANNEL_W     3
+
+#define GEN7_COMPRESSION_NONE          0
+#define GEN7_COMPRESSION_2NDHALF       1
+#define GEN7_COMPRESSION_COMPRESSED    2
+
+#define GEN7_CONDITIONAL_NONE  0
+#define GEN7_CONDITIONAL_Z     1
+#define GEN7_CONDITIONAL_NZ    2
+#define GEN7_CONDITIONAL_EQ    1       /* Z */
+#define GEN7_CONDITIONAL_NEQ   2       /* NZ */
+#define GEN7_CONDITIONAL_G     3
+#define GEN7_CONDITIONAL_GE    4
+#define GEN7_CONDITIONAL_L     5
+#define GEN7_CONDITIONAL_LE    6
+#define GEN7_CONDITIONAL_C     7
+#define GEN7_CONDITIONAL_O     8
+
+#define GEN7_DEBUG_NONE        0
+#define GEN7_DEBUG_BREAKPOINT  1
+
+#define GEN7_DEPENDENCY_NORMAL         0
+#define GEN7_DEPENDENCY_NOTCLEARED     1
+#define GEN7_DEPENDENCY_NOTCHECKED     2
+#define GEN7_DEPENDENCY_DISABLE        3
+
+#define GEN7_EXECUTE_1     0
+#define GEN7_EXECUTE_2     1
+#define GEN7_EXECUTE_4     2
+#define GEN7_EXECUTE_8     3
+#define GEN7_EXECUTE_16    4
+#define GEN7_EXECUTE_32    5
+
+#define GEN7_HORIZONTAL_STRIDE_0   0
+#define GEN7_HORIZONTAL_STRIDE_1   1
+#define GEN7_HORIZONTAL_STRIDE_2   2
+#define GEN7_HORIZONTAL_STRIDE_4   3
+
+#define GEN7_INSTRUCTION_NORMAL    0
+#define GEN7_INSTRUCTION_SATURATE  1
+
+#define INTEL_MASK_ENABLE   0
+#define INTEL_MASK_DISABLE  1
+
+#define GEN7_OPCODE_MOV        1
+#define GEN7_OPCODE_SEL        2
+#define GEN7_OPCODE_NOT        4
+#define GEN7_OPCODE_AND        5
+#define GEN7_OPCODE_OR         6
+#define GEN7_OPCODE_XOR        7
+#define GEN7_OPCODE_SHR        8
+#define GEN7_OPCODE_SHL        9
+#define GEN7_OPCODE_RSR        10
+#define GEN7_OPCODE_RSL        11
+#define GEN7_OPCODE_ASR        12
+#define GEN7_OPCODE_CMP        16
+#define GEN7_OPCODE_JMPI       32
+#define GEN7_OPCODE_IF         34
+#define GEN7_OPCODE_IFF        35
+#define GEN7_OPCODE_ELSE       36
+#define GEN7_OPCODE_ENDIF      37
+#define GEN7_OPCODE_DO         38
+#define GEN7_OPCODE_WHILE      39
+#define GEN7_OPCODE_BREAK      40
+#define GEN7_OPCODE_CONTINUE   41
+#define GEN7_OPCODE_HALT       42
+#define GEN7_OPCODE_MSAVE      44
+#define GEN7_OPCODE_MRESTORE   45
+#define GEN7_OPCODE_PUSH       46
+#define GEN7_OPCODE_POP        47
+#define GEN7_OPCODE_WAIT       48
+#define GEN7_OPCODE_SEND       49
+#define GEN7_OPCODE_ADD        64
+#define GEN7_OPCODE_MUL        65
+#define GEN7_OPCODE_AVG        66
+#define GEN7_OPCODE_FRC        67
+#define GEN7_OPCODE_RNDU       68
+#define GEN7_OPCODE_RNDD       69
+#define GEN7_OPCODE_RNDE       70
+#define GEN7_OPCODE_RNDZ       71
+#define GEN7_OPCODE_MAC        72
+#define GEN7_OPCODE_MACH       73
+#define GEN7_OPCODE_LZD        74
+#define GEN7_OPCODE_SAD2       80
+#define GEN7_OPCODE_SADA2      81
+#define GEN7_OPCODE_DP4        84
+#define GEN7_OPCODE_DPH        85
+#define GEN7_OPCODE_DP3        86
+#define GEN7_OPCODE_DP2        87
+#define GEN7_OPCODE_DPA2       88
+#define GEN7_OPCODE_LINE       89
+#define GEN7_OPCODE_NOP        126
+
+#define GEN7_PREDICATE_NONE             0
+#define GEN7_PREDICATE_NORMAL           1
+#define GEN7_PREDICATE_ALIGN1_ANYV             2
+#define GEN7_PREDICATE_ALIGN1_ALLV             3
+#define GEN7_PREDICATE_ALIGN1_ANY2H            4
+#define GEN7_PREDICATE_ALIGN1_ALL2H            5
+#define GEN7_PREDICATE_ALIGN1_ANY4H            6
+#define GEN7_PREDICATE_ALIGN1_ALL4H            7
+#define GEN7_PREDICATE_ALIGN1_ANY8H            8
+#define GEN7_PREDICATE_ALIGN1_ALL8H            9
+#define GEN7_PREDICATE_ALIGN1_ANY16H           10
+#define GEN7_PREDICATE_ALIGN1_ALL16H           11
+#define GEN7_PREDICATE_ALIGN16_REPLICATE_X     2
+#define GEN7_PREDICATE_ALIGN16_REPLICATE_Y     3
+#define GEN7_PREDICATE_ALIGN16_REPLICATE_Z     4
+#define GEN7_PREDICATE_ALIGN16_REPLICATE_W     5
+#define GEN7_PREDICATE_ALIGN16_ANY4H           6
+#define GEN7_PREDICATE_ALIGN16_ALL4H           7
+
+#define GEN7_ARCHITECTURE_REGISTER_FILE    0
+#define GEN7_GENERAL_REGISTER_FILE         1
+#define GEN7_MESSAGE_REGISTER_FILE         2
+#define GEN7_IMMEDIATE_VALUE               3
+
+#define GEN7_REGISTER_TYPE_UD  0
+#define GEN7_REGISTER_TYPE_D   1
+#define GEN7_REGISTER_TYPE_UW  2
+#define GEN7_REGISTER_TYPE_W   3
+#define GEN7_REGISTER_TYPE_UB  4
+#define GEN7_REGISTER_TYPE_B   5
+#define GEN7_REGISTER_TYPE_VF  5       /* packed float vector, immediates only? */
+#define GEN7_REGISTER_TYPE_HF  6
+#define GEN7_REGISTER_TYPE_V   6       /* packed int vector, immediates only, uword dest only */
+#define GEN7_REGISTER_TYPE_F   7
+
+#define GEN7_ARF_NULL                  0x00
+#define GEN7_ARF_ADDRESS               0x10
+#define GEN7_ARF_ACCUMULATOR           0x20
+#define GEN7_ARF_FLAG                  0x30
+#define GEN7_ARF_MASK                  0x40
+#define GEN7_ARF_MASK_STACK            0x50
+#define GEN7_ARF_MASK_STACK_DEPTH      0x60
+#define GEN7_ARF_STATE                 0x70
+#define GEN7_ARF_CONTROL               0x80
+#define GEN7_ARF_NOTIFICATION_COUNT    0x90
+#define GEN7_ARF_IP                    0xA0
+
+#define GEN7_AMASK   0
+#define GEN7_IMASK   1
+#define GEN7_LMASK   2
+#define GEN7_CMASK   3
+
+#define GEN7_THREAD_NORMAL     0
+#define GEN7_THREAD_ATOMIC     1
+#define GEN7_THREAD_SWITCH     2
+
+#define GEN7_VERTICAL_STRIDE_0                 0
+#define GEN7_VERTICAL_STRIDE_1                 1
+#define GEN7_VERTICAL_STRIDE_2                 2
+#define GEN7_VERTICAL_STRIDE_4                 3
+#define GEN7_VERTICAL_STRIDE_8                 4
+#define GEN7_VERTICAL_STRIDE_16                5
+#define GEN7_VERTICAL_STRIDE_32                6
+#define GEN7_VERTICAL_STRIDE_64                7
+#define GEN7_VERTICAL_STRIDE_128               8
+#define GEN7_VERTICAL_STRIDE_256               9
+#define GEN7_VERTICAL_STRIDE_ONE_DIMENSIONAL   0xF
+
+#define GEN7_WIDTH_1       0
+#define GEN7_WIDTH_2       1
+#define GEN7_WIDTH_4       2
+#define GEN7_WIDTH_8       3
+#define GEN7_WIDTH_16      4
+
+#define GEN7_STATELESS_BUFFER_BOUNDARY_1K      0
+#define GEN7_STATELESS_BUFFER_BOUNDARY_2K      1
+#define GEN7_STATELESS_BUFFER_BOUNDARY_4K      2
+#define GEN7_STATELESS_BUFFER_BOUNDARY_8K      3
+#define GEN7_STATELESS_BUFFER_BOUNDARY_16K     4
+#define GEN7_STATELESS_BUFFER_BOUNDARY_32K     5
+#define GEN7_STATELESS_BUFFER_BOUNDARY_64K     6
+#define GEN7_STATELESS_BUFFER_BOUNDARY_128K    7
+#define GEN7_STATELESS_BUFFER_BOUNDARY_256K    8
+#define GEN7_STATELESS_BUFFER_BOUNDARY_512K    9
+#define GEN7_STATELESS_BUFFER_BOUNDARY_1M      10
+#define GEN7_STATELESS_BUFFER_BOUNDARY_2M      11
+
+#define GEN7_POLYGON_FACING_FRONT      0
+#define GEN7_POLYGON_FACING_BACK       1
+
+#define GEN7_MESSAGE_TARGET_NULL               0
+#define GEN7_MESSAGE_TARGET_MATH               1
+#define GEN7_MESSAGE_TARGET_SAMPLER            2
+#define GEN7_MESSAGE_TARGET_GATEWAY            3
+#define GEN7_MESSAGE_TARGET_DATAPORT_READ      4
+#define GEN7_MESSAGE_TARGET_DATAPORT_WRITE     5
+#define GEN7_MESSAGE_TARGET_URB                6
+#define GEN7_MESSAGE_TARGET_THREAD_SPAWNER     7
+
+#define GEN7_SAMPLER_RETURN_FORMAT_FLOAT32     0
+#define GEN7_SAMPLER_RETURN_FORMAT_UINT32      2
+#define GEN7_SAMPLER_RETURN_FORMAT_SINT32      3
+
+#define GEN7_SAMPLER_MESSAGE_SIMD8_SAMPLE              0
+#define GEN7_SAMPLER_MESSAGE_SIMD16_SAMPLE             0
+#define GEN7_SAMPLER_MESSAGE_SIMD16_SAMPLE_BIAS        0
+#define GEN7_SAMPLER_MESSAGE_SIMD8_KILLPIX             1
+#define GEN7_SAMPLER_MESSAGE_SIMD4X2_SAMPLE_LOD        1
+#define GEN7_SAMPLER_MESSAGE_SIMD16_SAMPLE_LOD         1
+#define GEN7_SAMPLER_MESSAGE_SIMD4X2_SAMPLE_GRADIENTS  2
+#define GEN7_SAMPLER_MESSAGE_SIMD8_SAMPLE_GRADIENTS    2
+#define GEN7_SAMPLER_MESSAGE_SIMD4X2_SAMPLE_COMPARE    0
+#define GEN7_SAMPLER_MESSAGE_SIMD16_SAMPLE_COMPARE     2
+#define GEN7_SAMPLER_MESSAGE_SIMD4X2_RESINFO           2
+#define GEN7_SAMPLER_MESSAGE_SIMD8_RESINFO             2
+#define GEN7_SAMPLER_MESSAGE_SIMD16_RESINFO            2
+#define GEN7_SAMPLER_MESSAGE_SIMD4X2_LD                3
+#define GEN7_SAMPLER_MESSAGE_SIMD8_LD                  3
+#define GEN7_SAMPLER_MESSAGE_SIMD16_LD                 3
+
+#define GEN7_DATAPORT_OWORD_BLOCK_1_OWORDLOW   0
+#define GEN7_DATAPORT_OWORD_BLOCK_1_OWORDHIGH  1
+#define GEN7_DATAPORT_OWORD_BLOCK_2_OWORDS     2
+#define GEN7_DATAPORT_OWORD_BLOCK_4_OWORDS     3
+#define GEN7_DATAPORT_OWORD_BLOCK_8_OWORDS     4
+
+#define GEN7_DATAPORT_OWORD_DUAL_BLOCK_1OWORD     0
+#define GEN7_DATAPORT_OWORD_DUAL_BLOCK_4OWORDS    2
+
+#define GEN7_DATAPORT_DWORD_SCATTERED_BLOCK_8DWORDS   2
+#define GEN7_DATAPORT_DWORD_SCATTERED_BLOCK_16DWORDS  3
+
+#define GEN7_DATAPORT_READ_MESSAGE_OWORD_BLOCK_READ          0
+#define GEN7_DATAPORT_READ_MESSAGE_OWORD_DUAL_BLOCK_READ     1
+#define GEN7_DATAPORT_READ_MESSAGE_DWORD_BLOCK_READ          2
+#define GEN7_DATAPORT_READ_MESSAGE_DWORD_SCATTERED_READ      3
+
+#define GEN7_DATAPORT_READ_TARGET_DATA_CACHE      0
+#define GEN7_DATAPORT_READ_TARGET_RENDER_CACHE    1
+#define GEN7_DATAPORT_READ_TARGET_SAMPLER_CACHE   2
+
+#define GEN7_DATAPORT_RENDER_TARGET_WRITE_SIMD16_SINGLE_SOURCE                0
+#define GEN7_DATAPORT_RENDER_TARGET_WRITE_SIMD16_SINGLE_SOURCE_REPLICATED     1
+#define GEN7_DATAPORT_RENDER_TARGET_WRITE_SIMD8_DUAL_SOURCE_SUBSPAN01         2
+#define GEN7_DATAPORT_RENDER_TARGET_WRITE_SIMD8_DUAL_SOURCE_SUBSPAN23         3
+#define GEN7_DATAPORT_RENDER_TARGET_WRITE_SIMD8_SINGLE_SOURCE_SUBSPAN01       4
+
+#define GEN7_DATAPORT_WRITE_MESSAGE_OWORD_BLOCK_WRITE                0
+#define GEN7_DATAPORT_WRITE_MESSAGE_OWORD_DUAL_BLOCK_WRITE           1
+#define GEN7_DATAPORT_WRITE_MESSAGE_DWORD_BLOCK_WRITE                2
+#define GEN7_DATAPORT_WRITE_MESSAGE_DWORD_SCATTERED_WRITE            3
+#define GEN7_DATAPORT_WRITE_MESSAGE_RENDER_TARGET_WRITE              4
+#define GEN7_DATAPORT_WRITE_MESSAGE_STREAMED_VERTEX_BUFFER_WRITE     5
+#define GEN7_DATAPORT_WRITE_MESSAGE_FLUSH_RENDER_CACHE               7
+
+#define GEN7_MATH_FUNCTION_INV                              1
+#define GEN7_MATH_FUNCTION_LOG                              2
+#define GEN7_MATH_FUNCTION_EXP                              3
+#define GEN7_MATH_FUNCTION_SQRT                             4
+#define GEN7_MATH_FUNCTION_RSQ                              5
+#define GEN7_MATH_FUNCTION_SIN                              6 /* was 7 */
+#define GEN7_MATH_FUNCTION_COS                              7 /* was 8 */
+#define GEN7_MATH_FUNCTION_SINCOS                           8 /* was 6 */
+#define GEN7_MATH_FUNCTION_TAN                              9
+#define GEN7_MATH_FUNCTION_POW                              10
+#define GEN7_MATH_FUNCTION_INT_DIV_QUOTIENT_AND_REMAINDER   11
+#define GEN7_MATH_FUNCTION_INT_DIV_QUOTIENT                 12
+#define GEN7_MATH_FUNCTION_INT_DIV_REMAINDER                13
+
+#define GEN7_MATH_INTEGER_UNSIGNED     0
+#define GEN7_MATH_INTEGER_SIGNED       1
+
+#define GEN7_MATH_PRECISION_FULL        0
+#define GEN7_MATH_PRECISION_PARTIAL     1
+
+#define GEN7_MATH_SATURATE_NONE         0
+#define GEN7_MATH_SATURATE_SATURATE     1
+
+#define GEN7_MATH_DATA_VECTOR  0
+#define GEN7_MATH_DATA_SCALAR  1
+
+#define GEN7_URB_OPCODE_WRITE  0
+
+#define GEN7_URB_SWIZZLE_NONE          0
+#define GEN7_URB_SWIZZLE_INTERLEAVE    1
+#define GEN7_URB_SWIZZLE_TRANSPOSE     2
+
+#define GEN7_SCRATCH_SPACE_SIZE_1K     0
+#define GEN7_SCRATCH_SPACE_SIZE_2K     1
+#define GEN7_SCRATCH_SPACE_SIZE_4K     2
+#define GEN7_SCRATCH_SPACE_SIZE_8K     3
+#define GEN7_SCRATCH_SPACE_SIZE_16K    4
+#define GEN7_SCRATCH_SPACE_SIZE_32K    5
+#define GEN7_SCRATCH_SPACE_SIZE_64K    6
+#define GEN7_SCRATCH_SPACE_SIZE_128K   7
+#define GEN7_SCRATCH_SPACE_SIZE_256K   8
+#define GEN7_SCRATCH_SPACE_SIZE_512K   9
+#define GEN7_SCRATCH_SPACE_SIZE_1M     10
+#define GEN7_SCRATCH_SPACE_SIZE_2M     11
+
+/* The hardware supports two different modes for border color. The
+ * default (OpenGL) mode uses floating-point color channels, while the
+ * legacy mode uses 4 bytes.
+ *
+ * More significantly, the legacy mode respects the components of the
+ * border color for channels not present in the source, (whereas the
+ * default mode will ignore the border color's alpha channel and use
+ * alpha==1 for an RGB source, for example).
+ *
+ * The legacy mode matches the semantics specified by the Render
+ * extension.
+ */
+struct gen7_sampler_default_border_color {
+   float color[4];
+};
+
+struct gen7_sampler_legacy_border_color {
+   uint8_t color[4];
+};
+
+struct gen7_blend_state {
+       struct {
+               uint32_t dest_blend_factor:5;
+               uint32_t source_blend_factor:5;
+               uint32_t pad3:1;
+               uint32_t blend_func:3;
+               uint32_t pad2:1;
+               uint32_t ia_dest_blend_factor:5;
+               uint32_t ia_source_blend_factor:5;
+               uint32_t pad1:1;
+               uint32_t ia_blend_func:3;
+               uint32_t pad0:1;
+               uint32_t ia_blend_enable:1;
+               uint32_t blend_enable:1;
+       } blend0;
+
+       struct {
+               uint32_t post_blend_clamp_enable:1;
+               uint32_t pre_blend_clamp_enable:1;
+               uint32_t clamp_range:2;
+               uint32_t pad0:4;
+               uint32_t x_dither_offset:2;
+               uint32_t y_dither_offset:2;
+               uint32_t dither_enable:1;
+               uint32_t alpha_test_func:3;
+               uint32_t alpha_test_enable:1;
+               uint32_t pad1:1;
+               uint32_t logic_op_func:4;
+               uint32_t logic_op_enable:1;
+               uint32_t pad2:1;
+               uint32_t write_disable_b:1;
+               uint32_t write_disable_g:1;
+               uint32_t write_disable_r:1;
+               uint32_t write_disable_a:1;
+               uint32_t pad3:1;
+               uint32_t alpha_to_coverage_dither:1;
+               uint32_t alpha_to_one:1;
+               uint32_t alpha_to_coverage:1;
+       } blend1;
+};
+
+struct gen7_color_calc_state {
+       struct {
+               uint32_t alpha_test_format:1;
+               uint32_t pad0:14;
+               uint32_t round_disable:1;
+               uint32_t bf_stencil_ref:8;
+               uint32_t stencil_ref:8;
+       } cc0;
+
+       union {
+               float alpha_ref_f;
+               struct {
+                       uint32_t ui:8;
+                       uint32_t pad0:24;
+               } alpha_ref_fi;
+       } cc1;
+
+       float constant_r;
+       float constant_g;
+       float constant_b;
+       float constant_a;
+};
+
+struct gen7_depth_stencil_state {
+       struct {
+               uint32_t pad0:3;
+               uint32_t bf_stencil_pass_depth_pass_op:3;
+               uint32_t bf_stencil_pass_depth_fail_op:3;
+               uint32_t bf_stencil_fail_op:3;
+               uint32_t bf_stencil_func:3;
+               uint32_t bf_stencil_enable:1;
+               uint32_t pad1:2;
+               uint32_t stencil_write_enable:1;
+               uint32_t stencil_pass_depth_pass_op:3;
+               uint32_t stencil_pass_depth_fail_op:3;
+               uint32_t stencil_fail_op:3;
+               uint32_t stencil_func:3;
+               uint32_t stencil_enable:1;
+       } ds0;
+
+       struct {
+               uint32_t bf_stencil_write_mask:8;
+               uint32_t bf_stencil_test_mask:8;
+               uint32_t stencil_write_mask:8;
+               uint32_t stencil_test_mask:8;
+       } ds1;
+
+       struct {
+               uint32_t pad0:26;
+               uint32_t depth_write_enable:1;
+               uint32_t depth_test_func:3;
+               uint32_t pad1:1;
+               uint32_t depth_test_enable:1;
+       } ds2;
+};
+
+struct gen7_surface_state {
+       struct {
+               unsigned int cube_pos_z:1;
+               unsigned int cube_neg_z:1;
+               unsigned int cube_pos_y:1;
+               unsigned int cube_neg_y:1;
+               unsigned int cube_pos_x:1;
+               unsigned int cube_neg_x:1;
+               unsigned int pad2:2;
+               unsigned int render_cache_read_write:1;
+               unsigned int pad1:1;
+               unsigned int surface_array_spacing:1;
+               unsigned int vert_line_stride_ofs:1;
+               unsigned int vert_line_stride:1;
+               unsigned int tile_walk:1;
+               unsigned int tiled_surface:1;
+               unsigned int horizontal_alignment:1;
+               unsigned int vertical_alignment:2;
+               unsigned int surface_format:9;     /**< BRW_SURFACEFORMAT_x */
+               unsigned int pad0:1;
+               unsigned int is_array:1;
+               unsigned int surface_type:3;       /**< BRW_SURFACE_1D/2D/3D/CUBE */
+       } ss0;
+
+       struct {
+               unsigned int base_addr;
+       } ss1;
+
+       struct {
+               unsigned int width:14;
+               unsigned int pad1:2;
+               unsigned int height:14;
+               unsigned int pad0:2;
+       } ss2;
+
+       struct {
+               unsigned int pitch:18;
+               unsigned int pad:3;
+               unsigned int depth:11;
+       } ss3;
+
+       struct {
+               unsigned int multisample_position_palette_index:3;
+               unsigned int num_multisamples:3;
+               unsigned int multisampled_surface_storage_format:1;
+               unsigned int render_target_view_extent:11;
+               unsigned int min_array_elt:11;
+               unsigned int rotation:2;
+               unsigned int pad0:1;
+       } ss4;
+
+       struct {
+               unsigned int mip_count:4;
+               unsigned int min_lod:4;
+               unsigned int pad1:12;
+               unsigned int y_offset:4;
+               unsigned int pad0:1;
+               unsigned int x_offset:7;
+       } ss5;
+
+       struct {
+               unsigned int pad; /* Multisample Control Surface stuff */
+       } ss6;
+
+       struct {
+               unsigned int resource_min_lod:12;
+               unsigned int pad0:16;
+               unsigned int alpha_clear_color:1;
+               unsigned int blue_clear_color:1;
+               unsigned int green_clear_color:1;
+               unsigned int red_clear_color:1;
+       } ss7;
+};
+
+struct gen7_sampler_state {
+       struct {
+               unsigned int aniso_algorithm:1;
+               unsigned int lod_bias:13;
+               unsigned int min_filter:3;
+               unsigned int mag_filter:3;
+               unsigned int mip_filter:2;
+               unsigned int base_level:5;
+               unsigned int pad1:1;
+               unsigned int lod_preclamp:1;
+               unsigned int default_color_mode:1;
+               unsigned int pad0:1;
+               unsigned int disable:1;
+       } ss0;
+
+       struct {
+               unsigned int cube_control_mode:1;
+               unsigned int shadow_function:3;
+               unsigned int pad:4;
+               unsigned int max_lod:12;
+               unsigned int min_lod:12;
+       } ss1;
+
+       struct {
+               unsigned int pad:5;
+               unsigned int default_color_pointer:27;
+       } ss2;
+
+       struct {
+               unsigned int r_wrap_mode:3;
+               unsigned int t_wrap_mode:3;
+               unsigned int s_wrap_mode:3;
+               unsigned int pad:1;
+               unsigned int non_normalized_coord:1;
+               unsigned int trilinear_quality:2;
+               unsigned int address_round:6;
+               unsigned int max_aniso:3;
+               unsigned int chroma_key_mode:1;
+               unsigned int chroma_key_index:2;
+               unsigned int chroma_key_enable:1;
+               unsigned int pad0:6;
+       } ss3;
+};
+
+/* Surface state DW0 */
+#define GEN7_SURFACE_RC_READ_WRITE     (1 << 8)
+#define GEN7_SURFACE_TILED             (1 << 14)
+#define GEN7_SURFACE_TILED_Y           (1 << 13)
+#define GEN7_SURFACE_FORMAT_SHIFT      18
+#define GEN7_SURFACE_TYPE_SHIFT                29
+
+/* Surface state DW2 */
+#define GEN7_SURFACE_HEIGHT_SHIFT        16
+#define GEN7_SURFACE_WIDTH_SHIFT         0
+
+/* Surface state DW3 */
+#define GEN7_SURFACE_DEPTH_SHIFT         21
+#define GEN7_SURFACE_PITCH_SHIFT         0
+
+#define HSW_SWIZZLE_ZERO               0
+#define HSW_SWIZZLE_ONE                        1
+#define HSW_SWIZZLE_RED                        4
+#define HSW_SWIZZLE_GREEN              5
+#define HSW_SWIZZLE_BLUE               6
+#define HSW_SWIZZLE_ALPHA              7
+#define __HSW_SURFACE_SWIZZLE(r,g,b,a) \
+       ((a) << 16 | (b) << 19 | (g) << 22 | (r) << 25)
+#define HSW_SURFACE_SWIZZLE(r,g,b,a) \
+       __HSW_SURFACE_SWIZZLE(HSW_SWIZZLE_##r, HSW_SWIZZLE_##g, HSW_SWIZZLE_##b, HSW_SWIZZLE_##a)
+
+/* _3DSTATE_VERTEX_BUFFERS on GEN7*/
+/* DW1 */
+#define GEN7_VB0_ADDRESS_MODIFYENABLE   (1 << 14)
+
+/* _3DPRIMITIVE on GEN7 */
+/* DW1 */
+# define GEN7_3DPRIM_VERTEXBUFFER_ACCESS_SEQUENTIAL     (0 << 8)
+# define GEN7_3DPRIM_VERTEXBUFFER_ACCESS_RANDOM         (1 << 8)
+
+#define GEN7_3DSTATE_CLEAR_PARAMS               GEN7_3D(3, 0, 0x04)
+#define GEN7_3DSTATE_DEPTH_BUFFER               GEN7_3D(3, 0, 0x05)
+# define GEN7_3DSTATE_DEPTH_BUFFER_TYPE_SHIFT  29
+# define GEN7_3DSTATE_DEPTH_BUFFER_FORMAT_SHIFT        18
+/* DW1 */
+# define GEN7_3DSTATE_DEPTH_CLEAR_VALID                (1 << 15)
+
+#define GEN7_3DSTATE_CONSTANT_HS                GEN7_3D(3, 0, 0x19)
+#define GEN7_3DSTATE_CONSTANT_DS                GEN7_3D(3, 0, 0x1a)
+
+#define GEN7_3DSTATE_HS                         GEN7_3D(3, 0, 0x1b)
+#define GEN7_3DSTATE_TE                         GEN7_3D(3, 0, 0x1c)
+#define GEN7_3DSTATE_DS                         GEN7_3D(3, 0, 0x1d)
+#define GEN7_3DSTATE_STREAMOUT                  GEN7_3D(3, 0, 0x1e)
+#define GEN7_3DSTATE_SBE                        GEN7_3D(3, 0, 0x1f)
+
+/* DW1 */
+# define GEN7_SBE_SWIZZLE_CONTROL_MODE          (1 << 28)
+# define GEN7_SBE_NUM_OUTPUTS_SHIFT             22
+# define GEN7_SBE_SWIZZLE_ENABLE                (1 << 21)
+# define GEN7_SBE_POINT_SPRITE_LOWERLEFT        (1 << 20)
+# define GEN7_SBE_URB_ENTRY_READ_LENGTH_SHIFT   11
+# define GEN7_SBE_URB_ENTRY_READ_OFFSET_SHIFT   4
+
+#define GEN7_3DSTATE_PS                                 GEN7_3D(3, 0, 0x20)
+/* DW1: kernel pointer */
+/* DW2 */
+# define GEN7_PS_SPF_MODE                               (1 << 31)
+# define GEN7_PS_VECTOR_MASK_ENABLE                     (1 << 30)
+# define GEN7_PS_SAMPLER_COUNT_SHIFT                    27
+# define GEN7_PS_BINDING_TABLE_ENTRY_COUNT_SHIFT        18
+# define GEN7_PS_FLOATING_POINT_MODE_IEEE_754           (0 << 16)
+# define GEN7_PS_FLOATING_POINT_MODE_ALT                (1 << 16)
+/* DW3: scratch space */
+/* DW4 */
+# define IVB_PS_MAX_THREADS_SHIFT                      24
+# define HSW_PS_MAX_THREADS_SHIFT                      23
+# define HSW_PS_SAMPLE_MASK_SHIFT                      12
+# define GEN7_PS_PUSH_CONSTANT_ENABLE                   (1 << 11)
+# define GEN7_PS_ATTRIBUTE_ENABLE                       (1 << 10)
+# define GEN7_PS_OMASK_TO_RENDER_TARGET                 (1 << 9)
+# define GEN7_PS_DUAL_SOURCE_BLEND_ENABLE               (1 << 7)
+# define GEN7_PS_POSOFFSET_NONE                         (0 << 3)
+# define GEN7_PS_POSOFFSET_CENTROID                     (2 << 3)
+# define GEN7_PS_POSOFFSET_SAMPLE                       (3 << 3)
+# define GEN7_PS_32_DISPATCH_ENABLE                     (1 << 2)
+# define GEN7_PS_16_DISPATCH_ENABLE                     (1 << 1)
+# define GEN7_PS_8_DISPATCH_ENABLE                      (1 << 0)
+/* DW5 */
+# define GEN7_PS_DISPATCH_START_GRF_SHIFT_0             16
+# define GEN7_PS_DISPATCH_START_GRF_SHIFT_1             8
+# define GEN7_PS_DISPATCH_START_GRF_SHIFT_2             0
+/* DW6: kernel 1 pointer */
+/* DW7: kernel 2 pointer */
+
+#define GEN7_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CL      GEN7_3D(3, 0, 0x21)
+#define GEN7_3DSTATE_VIEWPORT_STATE_POINTERS_CC         GEN7_3D(3, 0, 0x23)
+
+#define GEN7_3DSTATE_BLEND_STATE_POINTERS               GEN7_3D(3, 0, 0x24)
+#define GEN7_3DSTATE_DEPTH_STENCIL_STATE_POINTERS       GEN7_3D(3, 0, 0x25)
+
+#define GEN7_3DSTATE_BINDING_TABLE_POINTERS_VS          GEN7_3D(3, 0, 0x26)
+#define GEN7_3DSTATE_BINDING_TABLE_POINTERS_HS          GEN7_3D(3, 0, 0x27)
+#define GEN7_3DSTATE_BINDING_TABLE_POINTERS_DS          GEN7_3D(3, 0, 0x28)
+#define GEN7_3DSTATE_BINDING_TABLE_POINTERS_GS          GEN7_3D(3, 0, 0x29)
+#define GEN7_3DSTATE_BINDING_TABLE_POINTERS_PS          GEN7_3D(3, 0, 0x2a)
+
+#define GEN7_3DSTATE_SAMPLER_STATE_POINTERS_VS          GEN7_3D(3, 0, 0x2b)
+#define GEN7_3DSTATE_SAMPLER_STATE_POINTERS_GS          GEN7_3D(3, 0, 0x2e)
+#define GEN7_3DSTATE_SAMPLER_STATE_POINTERS_PS          GEN7_3D(3, 0, 0x2f)
+
+#define GEN7_3DSTATE_URB_VS                             GEN7_3D(3, 0, 0x30)
+#define GEN7_3DSTATE_URB_HS                             GEN7_3D(3, 0, 0x31)
+#define GEN7_3DSTATE_URB_DS                             GEN7_3D(3, 0, 0x32)
+#define GEN7_3DSTATE_URB_GS                             GEN7_3D(3, 0, 0x33)
+/* DW1 */
+# define GEN7_URB_ENTRY_NUMBER_SHIFT            0
+# define GEN7_URB_ENTRY_SIZE_SHIFT              16
+# define GEN7_URB_STARTING_ADDRESS_SHIFT        25
+
+#define GEN7_3DSTATE_PUSH_CONSTANT_ALLOC_VS             GEN7_3D(3, 1, 0x12)
+#define GEN7_3DSTATE_PUSH_CONSTANT_ALLOC_PS             GEN7_3D(3, 1, 0x16)
+/* DW1 */
+# define GEN7_PUSH_CONSTANT_BUFFER_OFFSET_SHIFT 16
+
+struct gen7_cc_viewport {
+       float min_depth;
+       float max_depth;
+};
+
+typedef enum {
+       SAMPLER_FILTER_NEAREST = 0,
+       SAMPLER_FILTER_BILINEAR,
+       FILTER_COUNT
+} sampler_filter_t;
+
+typedef enum {
+       SAMPLER_EXTEND_NONE = 0,
+       SAMPLER_EXTEND_REPEAT,
+       SAMPLER_EXTEND_PAD,
+       SAMPLER_EXTEND_REFLECT,
+       EXTEND_COUNT
+} sampler_extend_t;
+
+#endif
diff --git a/src/sna/kgem.c b/src/sna/kgem.c
new file mode 100644 (file)
index 0000000..7826aad
--- /dev/null
@@ -0,0 +1,5120 @@
+/*
+ * Copyright (c) 2011 Intel 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.
+ *
+ * Authors:
+ *    Chris Wilson <chris@chris-wilson.co.uk>
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "sna.h"
+#include "sna_reg.h"
+
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#include <time.h>
+#include <errno.h>
+#include <fcntl.h>
+
+#include <xf86drm.h>
+
+#ifdef HAVE_VALGRIND
+#include <valgrind.h>
+#include <memcheck.h>
+#endif
+
+#if HAVE_SYS_SYSINFO_H
+#include <sys/sysinfo.h>
+#endif
+
+static struct kgem_bo *
+search_linear_cache(struct kgem *kgem, unsigned int num_pages, unsigned flags);
+
+static struct kgem_bo *
+search_snoop_cache(struct kgem *kgem, unsigned int num_pages, unsigned flags);
+
+#define DBG_NO_HW 0
+#define DBG_NO_TILING 0
+#define DBG_NO_CACHE 0
+#define DBG_NO_CACHE_LEVEL 0
+#define DBG_NO_CPU 0
+#define DBG_NO_USERPTR 0
+#define DBG_NO_LLC 0
+#define DBG_NO_SEMAPHORES 0
+#define DBG_NO_MADV 0
+#define DBG_NO_UPLOAD_CACHE 0
+#define DBG_NO_UPLOAD_ACTIVE 0
+#define DBG_NO_MAP_UPLOAD 0
+#define DBG_NO_RELAXED_FENCING 0
+#define DBG_DUMP 0
+
+#define SHOW_BATCH 0
+
+/* Worst case seems to be 965gm where we cannot write within a cacheline that
+ * is being simultaneously being read by the GPU, or within the sampler
+ * prefetch. In general, the chipsets seem to have a requirement that sampler
+ * offsets be aligned to a cacheline (64 bytes).
+ */
+#define UPLOAD_ALIGNMENT 128
+
+#define PAGE_ALIGN(x) ALIGN(x, PAGE_SIZE)
+#define NUM_PAGES(x) (((x) + PAGE_SIZE-1) / PAGE_SIZE)
+
+#define MAX_GTT_VMA_CACHE 512
+#define MAX_CPU_VMA_CACHE INT16_MAX
+#define MAP_PRESERVE_TIME 10
+
+#define MAP(ptr) ((void*)((uintptr_t)(ptr) & ~3))
+#define MAKE_CPU_MAP(ptr) ((void*)((uintptr_t)(ptr) | 1))
+#define MAKE_USER_MAP(ptr) ((void*)((uintptr_t)(ptr) | 3))
+#define IS_USER_MAP(ptr) ((uintptr_t)(ptr) & 2)
+#define __MAP_TYPE(ptr) ((uintptr_t)(ptr) & 3)
+
+#define LOCAL_I915_PARAM_HAS_SEMAPHORES         20
+
+#define LOCAL_I915_GEM_USERPTR       0x32
+#define LOCAL_IOCTL_I915_GEM_USERPTR DRM_IOWR (DRM_COMMAND_BASE + LOCAL_I915_GEM_USERPTR, struct local_i915_gem_userptr)
+struct local_i915_gem_userptr {
+       uint64_t user_ptr;
+       uint32_t user_size;
+       uint32_t flags;
+#define I915_USERPTR_READ_ONLY 0x1
+       uint32_t handle;
+};
+
+#define UNCACHED       0
+#define SNOOPED                1
+
+struct local_i915_gem_cacheing {
+       uint32_t handle;
+       uint32_t cacheing;
+};
+
+#define LOCAL_I915_GEM_SET_CACHEING    0x2f
+#define LOCAL_IOCTL_I915_GEM_SET_CACHEING DRM_IOW(DRM_COMMAND_BASE + LOCAL_I915_GEM_SET_CACHEING, struct local_i915_gem_cacheing)
+
+struct kgem_buffer {
+       struct kgem_bo base;
+       void *mem;
+       uint32_t used;
+       uint32_t need_io : 1;
+       uint32_t write : 2;
+       uint32_t mmapped : 1;
+};
+
+static struct kgem_bo *__kgem_freed_bo;
+static struct kgem_request *__kgem_freed_request;
+static struct drm_i915_gem_exec_object2 _kgem_dummy_exec;
+
+static inline int bytes(struct kgem_bo *bo)
+{
+       return __kgem_bo_size(bo);
+}
+
+#define bucket(B) (B)->size.pages.bucket
+#define num_pages(B) (B)->size.pages.count
+
+#ifdef DEBUG_MEMORY
+static void debug_alloc(struct kgem *kgem, size_t size)
+{
+       kgem->debug_memory.bo_allocs++;
+       kgem->debug_memory.bo_bytes += size;
+}
+static void debug_alloc__bo(struct kgem *kgem, struct kgem_bo *bo)
+{
+       debug_alloc(kgem, bytes(bo));
+}
+#else
+#define debug_alloc(k, b)
+#define debug_alloc__bo(k, b)
+#endif
+
+static void kgem_sna_reset(struct kgem *kgem)
+{
+       struct sna *sna = container_of(kgem, struct sna, kgem);
+
+       sna->render.reset(sna);
+       sna->blt_state.fill_bo = 0;
+}
+
+static void kgem_sna_flush(struct kgem *kgem)
+{
+       struct sna *sna = container_of(kgem, struct sna, kgem);
+
+       sna->render.flush(sna);
+
+       if (sna->render.solid_cache.dirty)
+               sna_render_flush_solid(sna);
+}
+
+static int gem_set_tiling(int fd, uint32_t handle, int tiling, int stride)
+{
+       struct drm_i915_gem_set_tiling set_tiling;
+       int ret;
+
+       if (DBG_NO_TILING)
+               return I915_TILING_NONE;
+
+       VG_CLEAR(set_tiling);
+       do {
+               set_tiling.handle = handle;
+               set_tiling.tiling_mode = tiling;
+               set_tiling.stride = stride;
+
+               ret = ioctl(fd, DRM_IOCTL_I915_GEM_SET_TILING, &set_tiling);
+       } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
+       return set_tiling.tiling_mode;
+}
+
+static bool gem_set_cacheing(int fd, uint32_t handle, int cacheing)
+{
+       struct local_i915_gem_cacheing arg;
+
+       VG_CLEAR(arg);
+       arg.handle = handle;
+       arg.cacheing = cacheing;
+       return drmIoctl(fd, LOCAL_IOCTL_I915_GEM_SET_CACHEING, &arg) == 0;
+}
+
+static uint32_t gem_userptr(int fd, void *ptr, int size, int read_only)
+{
+       struct local_i915_gem_userptr arg;
+
+       VG_CLEAR(arg);
+       arg.user_ptr = (uintptr_t)ptr;
+       arg.user_size = size;
+       arg.flags = 0;
+       if (read_only)
+               arg.flags |= I915_USERPTR_READ_ONLY;
+
+       if (drmIoctl(fd, LOCAL_IOCTL_I915_GEM_USERPTR, &arg)) {
+               DBG(("%s: failed to map %p + %d bytes: %d\n",
+                    __FUNCTION__, ptr, size, errno));
+               return 0;
+       }
+
+       return arg.handle;
+}
+
+static bool __kgem_throttle_retire(struct kgem *kgem, unsigned flags)
+{
+       if (flags & CREATE_NO_RETIRE) {
+               DBG(("%s: not retiring per-request\n", __FUNCTION__));
+               return false;
+       }
+
+       if (!kgem->need_retire) {
+               DBG(("%s: nothing to retire\n", __FUNCTION__));
+               return false;
+       }
+
+       if (kgem_retire(kgem))
+               return true;
+
+       if (flags & CREATE_NO_THROTTLE || !kgem->need_throttle) {
+               DBG(("%s: not throttling\n", __FUNCTION__));
+               return false;
+       }
+
+       kgem_throttle(kgem);
+       return kgem_retire(kgem);
+}
+
+static void *__kgem_bo_map__gtt(struct kgem *kgem, struct kgem_bo *bo)
+{
+       struct drm_i915_gem_mmap_gtt mmap_arg;
+       void *ptr;
+
+       DBG(("%s(handle=%d, size=%d)\n", __FUNCTION__,
+            bo->handle, bytes(bo)));
+       assert(bo->proxy == NULL);
+
+retry_gtt:
+       VG_CLEAR(mmap_arg);
+       mmap_arg.handle = bo->handle;
+       if (drmIoctl(kgem->fd, DRM_IOCTL_I915_GEM_MMAP_GTT, &mmap_arg)) {
+               ErrorF("%s: failed to retrieve GTT offset for handle=%d: %d\n",
+                      __FUNCTION__, bo->handle, errno);
+               (void)__kgem_throttle_retire(kgem, 0);
+               if (kgem_expire_cache(kgem))
+                       goto retry_gtt;
+
+               return NULL;
+       }
+
+retry_mmap:
+       ptr = mmap(0, bytes(bo), PROT_READ | PROT_WRITE, MAP_SHARED,
+                  kgem->fd, mmap_arg.offset);
+       if (ptr == MAP_FAILED) {
+               ErrorF("%s: failed to mmap %d, %d bytes, into GTT domain: %d\n",
+                      __FUNCTION__, bo->handle, bytes(bo), errno);
+               if (__kgem_throttle_retire(kgem, 0))
+                       goto retry_mmap;
+
+               ptr = NULL;
+       }
+
+       return ptr;
+}
+
+static int __gem_write(int fd, uint32_t handle,
+                      int offset, int length,
+                      const void *src)
+{
+       struct drm_i915_gem_pwrite pwrite;
+
+       DBG(("%s(handle=%d, offset=%d, len=%d)\n", __FUNCTION__,
+            handle, offset, length));
+
+       VG_CLEAR(pwrite);
+       pwrite.handle = handle;
+       pwrite.offset = offset;
+       pwrite.size = length;
+       pwrite.data_ptr = (uintptr_t)src;
+       return drmIoctl(fd, DRM_IOCTL_I915_GEM_PWRITE, &pwrite);
+}
+
+static int gem_write(int fd, uint32_t handle,
+                    int offset, int length,
+                    const void *src)
+{
+       struct drm_i915_gem_pwrite pwrite;
+
+       DBG(("%s(handle=%d, offset=%d, len=%d)\n", __FUNCTION__,
+            handle, offset, length));
+
+       VG_CLEAR(pwrite);
+       pwrite.handle = handle;
+       /* align the transfer to cachelines; fortuitously this is safe! */
+       if ((offset | length) & 63) {
+               pwrite.offset = offset & ~63;
+               pwrite.size = ALIGN(offset+length, 64) - pwrite.offset;
+               pwrite.data_ptr = (uintptr_t)src + pwrite.offset - offset;
+       } else {
+               pwrite.offset = offset;
+               pwrite.size = length;
+               pwrite.data_ptr = (uintptr_t)src;
+       }
+       return drmIoctl(fd, DRM_IOCTL_I915_GEM_PWRITE, &pwrite);
+}
+
+static int gem_read(int fd, uint32_t handle, const void *dst,
+                   int offset, int length)
+{
+       struct drm_i915_gem_pread pread;
+       int ret;
+
+       DBG(("%s(handle=%d, len=%d)\n", __FUNCTION__,
+            handle, length));
+
+       VG_CLEAR(pread);
+       pread.handle = handle;
+       pread.offset = offset;
+       pread.size = length;
+       pread.data_ptr = (uintptr_t)dst;
+       ret = drmIoctl(fd, DRM_IOCTL_I915_GEM_PREAD, &pread);
+       if (ret) {
+               DBG(("%s: failed, errno=%d\n", __FUNCTION__, errno));
+               return ret;
+       }
+
+       VG(VALGRIND_MAKE_MEM_DEFINED(dst, length));
+       return 0;
+}
+
+static bool
+kgem_busy(struct kgem *kgem, int handle)
+{
+       struct drm_i915_gem_busy busy;
+
+       VG_CLEAR(busy);
+       busy.handle = handle;
+       busy.busy = !kgem->wedged;
+       (void)drmIoctl(kgem->fd, DRM_IOCTL_I915_GEM_BUSY, &busy);
+       DBG(("%s: handle=%d, busy=%d, wedged=%d\n",
+            __FUNCTION__, handle, busy.busy, kgem->wedged));
+
+       return busy.busy;
+}
+
+void kgem_bo_retire(struct kgem *kgem, struct kgem_bo *bo)
+{
+       DBG(("%s: handle=%d, domain=%d\n",
+            __FUNCTION__, bo->handle, bo->domain));
+       assert(bo->flush || !kgem_busy(kgem, bo->handle));
+
+       if (bo->rq)
+               kgem_retire(kgem);
+
+       if (bo->exec == NULL) {
+               DBG(("%s: retiring bo handle=%d (needed flush? %d), rq? %d\n",
+                    __FUNCTION__, bo->handle, bo->needs_flush, bo->rq != NULL));
+               assert(list_is_empty(&bo->vma));
+               bo->rq = NULL;
+               list_del(&bo->request);
+
+               bo->needs_flush = false;
+       }
+
+       bo->domain = DOMAIN_NONE;
+}
+
+bool kgem_bo_write(struct kgem *kgem, struct kgem_bo *bo,
+                  const void *data, int length)
+{
+       assert(bo->refcnt);
+       assert(!bo->purged);
+       assert(bo->flush || !kgem_busy(kgem, bo->handle));
+       assert(bo->proxy == NULL);
+
+       assert(length <= bytes(bo));
+       if (gem_write(kgem->fd, bo->handle, 0, length, data))
+               return false;
+
+       DBG(("%s: flush=%d, domain=%d\n", __FUNCTION__, bo->flush, bo->domain));
+       kgem_bo_retire(kgem, bo);
+       return true;
+}
+
+static uint32_t gem_create(int fd, int num_pages)
+{
+       struct drm_i915_gem_create create;
+
+       VG_CLEAR(create);
+       create.handle = 0;
+       create.size = PAGE_SIZE * num_pages;
+       (void)drmIoctl(fd, DRM_IOCTL_I915_GEM_CREATE, &create);
+
+       return create.handle;
+}
+
+static bool
+kgem_bo_set_purgeable(struct kgem *kgem, struct kgem_bo *bo)
+{
+#if DBG_NO_MADV
+       return true;
+#else
+       struct drm_i915_gem_madvise madv;
+
+       assert(bo->exec == NULL);
+       assert(!bo->purged);
+
+       VG_CLEAR(madv);
+       madv.handle = bo->handle;
+       madv.madv = I915_MADV_DONTNEED;
+       if (drmIoctl(kgem->fd, DRM_IOCTL_I915_GEM_MADVISE, &madv) == 0) {
+               bo->purged = 1;
+               kgem->need_purge |= !madv.retained && bo->domain == DOMAIN_GPU;
+               return madv.retained;
+       }
+
+       return true;
+#endif
+}
+
+static bool
+kgem_bo_is_retained(struct kgem *kgem, struct kgem_bo *bo)
+{
+#if DBG_NO_MADV
+       return true;
+#else
+       struct drm_i915_gem_madvise madv;
+
+       if (!bo->purged)
+               return true;
+
+       VG_CLEAR(madv);
+       madv.handle = bo->handle;
+       madv.madv = I915_MADV_DONTNEED;
+       if (drmIoctl(kgem->fd, DRM_IOCTL_I915_GEM_MADVISE, &madv) == 0)
+               return madv.retained;
+
+       return false;
+#endif
+}
+
+static bool
+kgem_bo_clear_purgeable(struct kgem *kgem, struct kgem_bo *bo)
+{
+#if DBG_NO_MADV
+       return true;
+#else
+       struct drm_i915_gem_madvise madv;
+
+       assert(bo->purged);
+
+       VG_CLEAR(madv);
+       madv.handle = bo->handle;
+       madv.madv = I915_MADV_WILLNEED;
+       if (drmIoctl(kgem->fd, DRM_IOCTL_I915_GEM_MADVISE, &madv) == 0) {
+               bo->purged = !madv.retained;
+               kgem->need_purge |= !madv.retained && bo->domain == DOMAIN_GPU;
+               return madv.retained;
+       }
+
+       return false;
+#endif
+}
+
+static void gem_close(int fd, uint32_t handle)
+{
+       struct drm_gem_close close;
+
+       VG_CLEAR(close);
+       close.handle = handle;
+       (void)drmIoctl(fd, DRM_IOCTL_GEM_CLOSE, &close);
+}
+
+constant inline static unsigned long __fls(unsigned long word)
+{
+       asm("bsr %1,%0"
+           : "=r" (word)
+           : "rm" (word));
+       return word;
+}
+
+constant inline static int cache_bucket(int num_pages)
+{
+       return __fls(num_pages);
+}
+
+static struct kgem_bo *__kgem_bo_init(struct kgem_bo *bo,
+                                     int handle, int num_pages)
+{
+       assert(num_pages);
+       memset(bo, 0, sizeof(*bo));
+
+       bo->refcnt = 1;
+       bo->handle = handle;
+       num_pages(bo) = num_pages;
+       bucket(bo) = cache_bucket(num_pages);
+       bo->reusable = true;
+       bo->domain = DOMAIN_CPU;
+       list_init(&bo->request);
+       list_init(&bo->list);
+       list_init(&bo->vma);
+
+       return bo;
+}
+
+static struct kgem_bo *__kgem_bo_alloc(int handle, int num_pages)
+{
+       struct kgem_bo *bo;
+
+       if (__kgem_freed_bo) {
+               bo = __kgem_freed_bo;
+               __kgem_freed_bo = *(struct kgem_bo **)bo;
+       } else {
+               bo = malloc(sizeof(*bo));
+               if (bo == NULL)
+                       return NULL;
+       }
+
+       return __kgem_bo_init(bo, handle, num_pages);
+}
+
+static struct kgem_request _kgem_static_request;
+
+static struct kgem_request *__kgem_request_alloc(void)
+{
+       struct kgem_request *rq;
+
+       rq = __kgem_freed_request;
+       if (rq) {
+               __kgem_freed_request = *(struct kgem_request **)rq;
+       } else {
+               rq = malloc(sizeof(*rq));
+               if (rq == NULL)
+                       rq = &_kgem_static_request;
+       }
+
+       list_init(&rq->buffers);
+       rq->bo = NULL;
+       rq->ring = 0;
+
+       return rq;
+}
+
+static void __kgem_request_free(struct kgem_request *rq)
+{
+       _list_del(&rq->list);
+       *(struct kgem_request **)rq = __kgem_freed_request;
+       __kgem_freed_request = rq;
+}
+
+static struct list *inactive(struct kgem *kgem, int num_pages)
+{
+       return &kgem->inactive[cache_bucket(num_pages)];
+}
+
+static struct list *active(struct kgem *kgem, int num_pages, int tiling)
+{
+       return &kgem->active[cache_bucket(num_pages)][tiling];
+}
+
+static size_t
+agp_aperture_size(struct pci_device *dev, unsigned gen)
+{
+       /* XXX assume that only future chipsets are unknown and follow
+        * the post gen2 PCI layout.
+        */
+       return dev->regions[gen < 30 ? 0 : 2].size;
+}
+
+static size_t
+total_ram_size(void)
+{
+#if HAVE_SYS_SYSINFO_H
+       struct sysinfo info;
+       if (sysinfo(&info) == 0)
+               return info.totalram * info.mem_unit;
+#endif
+
+       return 0;
+}
+
+static size_t
+cpu_cache_size(void)
+{
+       FILE *file = fopen("/proc/cpuinfo", "r");
+       size_t size = -1;
+       if (file) {
+               size_t len = 0;
+               char *line = NULL;
+               while (getline(&line, &len, file) != -1) {
+                       int mb;
+                       if (sscanf(line, "cache size : %d KB", &mb) == 1) {
+                               /* Paranoid check against gargantuan caches */
+                               if (mb <= 1<<20)
+                                       size = mb * 1024;
+                               break;
+                       }
+               }
+               free(line);
+               fclose(file);
+       }
+       if (size == -1)
+               ErrorF("Unknown CPU cache size\n");
+       return size;
+}
+
+static int gem_param(struct kgem *kgem, int name)
+{
+       drm_i915_getparam_t gp;
+       int v = -1; /* No param uses the sign bit, reserve it for errors */
+
+       VG_CLEAR(gp);
+       gp.param = name;
+       gp.value = &v;
+       if (drmIoctl(kgem->fd, DRM_IOCTL_I915_GETPARAM, &gp))
+               return -1;
+
+       VG(VALGRIND_MAKE_MEM_DEFINED(&v, sizeof(v)));
+       return v;
+}
+
+static bool test_has_semaphores_enabled(struct kgem *kgem)
+{
+       FILE *file;
+       bool detected = false;
+       int ret;
+
+       if (DBG_NO_SEMAPHORES)
+               return false;
+
+       ret = gem_param(kgem, LOCAL_I915_PARAM_HAS_SEMAPHORES);
+       if (ret != -1)
+               return ret > 0;
+
+       file = fopen("/sys/module/i915/parameters/semaphores", "r");
+       if (file) {
+               int value;
+               if (fscanf(file, "%d", &value) == 1)
+                       detected = value != 0;
+               fclose(file);
+       }
+
+       return detected;
+}
+
+static bool __kgem_throttle(struct kgem *kgem)
+{
+       if (drmIoctl(kgem->fd, DRM_IOCTL_I915_GEM_THROTTLE, NULL) == 0)
+               return false;
+
+       return errno == EIO;
+}
+
+static bool is_hw_supported(struct kgem *kgem,
+                           struct pci_device *dev)
+{
+       if (DBG_NO_HW)
+               return false;
+
+       if (kgem->gen == (unsigned)-1) /* unknown chipset, assume future gen */
+               return kgem->has_blt;
+
+       /* Although pre-855gm the GMCH is fubar, it works mostly. So
+        * let the user decide through "NoAccel" whether or not to risk
+        * hw acceleration.
+        */
+
+       if (kgem->gen == 60 && dev->revision < 8) {
+               /* pre-production SNB with dysfunctional BLT */
+               return false;
+       }
+
+       if (kgem->gen >= 60) /* Only if the kernel supports the BLT ring */
+               return kgem->has_blt;
+
+       return true;
+}
+
+static bool test_has_relaxed_fencing(struct kgem *kgem)
+{
+       if (kgem->gen < 40) {
+               if (DBG_NO_RELAXED_FENCING)
+                       return false;
+
+               return gem_param(kgem, I915_PARAM_HAS_RELAXED_FENCING) > 0;
+       } else
+               return true;
+}
+
+static bool test_has_llc(struct kgem *kgem)
+{
+       int has_llc = -1;
+
+       if (DBG_NO_LLC)
+               return false;
+
+#if defined(I915_PARAM_HAS_LLC) /* Expected in libdrm-2.4.31 */
+       has_llc = gem_param(kgem, I915_PARAM_HAS_LLC);
+#endif
+       if (has_llc == -1) {
+               DBG(("%s: no kernel/drm support for HAS_LLC, assuming support for LLC based on GPU generation\n", __FUNCTION__));
+               has_llc = kgem->gen >= 60;
+       }
+
+       return has_llc;
+}
+
+static bool test_has_cacheing(struct kgem *kgem)
+{
+       uint32_t handle;
+       bool ret;
+
+       if (DBG_NO_CACHE_LEVEL)
+               return false;
+
+       /* Incoherent blt and sampler hangs the GPU */
+       if (kgem->gen == 40)
+               return false;
+
+       handle = gem_create(kgem->fd, 1);
+       if (handle == 0)
+               return false;
+
+       ret = gem_set_cacheing(kgem->fd, handle, UNCACHED);
+       gem_close(kgem->fd, handle);
+       return ret;
+}
+
+static bool test_has_userptr(struct kgem *kgem)
+{
+#if defined(USE_USERPTR)
+       uint32_t handle;
+       void *ptr;
+
+       if (DBG_NO_USERPTR)
+               return false;
+
+       /* Incoherent blt and sampler hangs the GPU */
+       if (kgem->gen == 40)
+               return false;
+
+       ptr = malloc(PAGE_SIZE);
+       handle = gem_userptr(kgem->fd, ptr, PAGE_SIZE, false);
+       gem_close(kgem->fd, handle);
+       free(ptr);
+
+       return handle != 0;
+#else
+       return false;
+#endif
+}
+
+static int kgem_get_screen_index(struct kgem *kgem)
+{
+       struct sna *sna = container_of(kgem, struct sna, kgem);
+       return sna->scrn->scrnIndex;
+}
+
+void kgem_init(struct kgem *kgem, int fd, struct pci_device *dev, int gen)
+{
+       struct drm_i915_gem_get_aperture aperture;
+       size_t totalram;
+       unsigned half_gpu_max;
+       unsigned int i, j;
+
+       DBG(("%s: fd=%d, gen=%d\n", __FUNCTION__, fd, gen));
+
+       memset(kgem, 0, sizeof(*kgem));
+
+       kgem->fd = fd;
+       kgem->gen = gen;
+
+       kgem->has_blt = gem_param(kgem, I915_PARAM_HAS_BLT) > 0;
+       DBG(("%s: has BLT ring? %d\n", __FUNCTION__,
+            kgem->has_blt));
+
+       kgem->has_relaxed_delta =
+               gem_param(kgem, I915_PARAM_HAS_RELAXED_DELTA) > 0;
+       DBG(("%s: has relaxed delta? %d\n", __FUNCTION__,
+            kgem->has_relaxed_delta));
+
+       kgem->has_relaxed_fencing = test_has_relaxed_fencing(kgem);
+       DBG(("%s: has relaxed fencing? %d\n", __FUNCTION__,
+            kgem->has_relaxed_fencing));
+
+       kgem->has_llc = test_has_llc(kgem);
+       DBG(("%s: has shared last-level-cache? %d\n", __FUNCTION__,
+            kgem->has_llc));
+
+       kgem->has_cacheing = test_has_cacheing(kgem);
+       DBG(("%s: has set-cache-level? %d\n", __FUNCTION__,
+            kgem->has_cacheing));
+
+       kgem->has_userptr = test_has_userptr(kgem);
+       DBG(("%s: has userptr? %d\n", __FUNCTION__,
+            kgem->has_userptr));
+
+       kgem->has_semaphores = false;
+       if (kgem->has_blt && test_has_semaphores_enabled(kgem))
+               kgem->has_semaphores = true;
+       DBG(("%s: semaphores enabled? %d\n", __FUNCTION__,
+            kgem->has_semaphores));
+
+       kgem->can_blt_cpu = gen >= 30;
+       DBG(("%s: can blt to cpu? %d\n", __FUNCTION__,
+            kgem->can_blt_cpu));
+
+       if (!is_hw_supported(kgem, dev)) {
+               xf86DrvMsg(kgem_get_screen_index(kgem), X_WARNING,
+                          "Detected unsupported/dysfunctional hardware, disabling acceleration.\n");
+               kgem->wedged = 1;
+       } else if (__kgem_throttle(kgem)) {
+               xf86DrvMsg(kgem_get_screen_index(kgem), X_WARNING,
+                          "Detected a hung GPU, disabling acceleration.\n");
+               kgem->wedged = 1;
+       }
+
+       kgem->batch_size = ARRAY_SIZE(kgem->batch);
+       if (gen == 22)
+               /* 865g cannot handle a batch spanning multiple pages */
+               kgem->batch_size = PAGE_SIZE / sizeof(uint32_t);
+       if (gen >= 70 && gen < 80)
+               kgem->batch_size = 16*1024;
+       if (!kgem->has_relaxed_delta)
+               kgem->batch_size = 4*1024;
+
+       DBG(("%s: maximum batch size? %d\n", __FUNCTION__,
+            kgem->batch_size));
+
+       kgem->min_alignment = 4;
+       if (gen < 40)
+               kgem->min_alignment = 64;
+
+       kgem->half_cpu_cache_pages = cpu_cache_size() >> 13;
+       DBG(("%s: half cpu cache %d pages\n", __FUNCTION__,
+            kgem->half_cpu_cache_pages));
+
+       list_init(&kgem->requests[0]);
+       list_init(&kgem->requests[1]);
+       list_init(&kgem->batch_buffers);
+       list_init(&kgem->active_buffers);
+       list_init(&kgem->flushing);
+       list_init(&kgem->large);
+       list_init(&kgem->large_inactive);
+       list_init(&kgem->snoop);
+       for (i = 0; i < ARRAY_SIZE(kgem->inactive); i++)
+               list_init(&kgem->inactive[i]);
+       for (i = 0; i < ARRAY_SIZE(kgem->active); i++) {
+               for (j = 0; j < ARRAY_SIZE(kgem->active[i]); j++)
+                       list_init(&kgem->active[i][j]);
+       }
+       for (i = 0; i < ARRAY_SIZE(kgem->vma); i++) {
+               for (j = 0; j < ARRAY_SIZE(kgem->vma[i].inactive); j++)
+                       list_init(&kgem->vma[i].inactive[j]);
+       }
+       kgem->vma[MAP_GTT].count = -MAX_GTT_VMA_CACHE;
+       kgem->vma[MAP_CPU].count = -MAX_CPU_VMA_CACHE;
+
+       kgem->next_request = __kgem_request_alloc();
+
+       DBG(("%s: cpu bo enabled %d: llc? %d, set-cache-level? %d, userptr? %d\n", __FUNCTION__,
+            !DBG_NO_CPU && (kgem->has_llc | kgem->has_userptr | kgem->has_cacheing),
+            kgem->has_llc, kgem->has_cacheing, kgem->has_userptr));
+
+       VG_CLEAR(aperture);
+       aperture.aper_size = 0;
+       (void)drmIoctl(fd, DRM_IOCTL_I915_GEM_GET_APERTURE, &aperture);
+       if (aperture.aper_size == 0)
+               aperture.aper_size = 64*1024*1024;
+
+       kgem->aperture_total = aperture.aper_size;
+       kgem->aperture_high = aperture.aper_size * 3/4;
+       kgem->aperture_low = aperture.aper_size * 1/3;
+       DBG(("%s: aperture low=%d [%d], high=%d [%d]\n", __FUNCTION__,
+            kgem->aperture_low, kgem->aperture_low / (1024*1024),
+            kgem->aperture_high, kgem->aperture_high / (1024*1024)));
+
+       kgem->aperture_mappable = agp_aperture_size(dev, gen);
+       if (kgem->aperture_mappable == 0 ||
+           kgem->aperture_mappable > aperture.aper_size)
+               kgem->aperture_mappable = aperture.aper_size;
+       DBG(("%s: aperture mappable=%d [%d MiB]\n", __FUNCTION__,
+            kgem->aperture_mappable, kgem->aperture_mappable / (1024*1024)));
+
+       kgem->buffer_size = 64 * 1024;
+       while (kgem->buffer_size < kgem->aperture_mappable >> 10)
+               kgem->buffer_size *= 2;
+       DBG(("%s: buffer size=%d [%d KiB]\n", __FUNCTION__,
+            kgem->buffer_size, kgem->buffer_size / 1024));
+
+       kgem->max_object_size = 2 * aperture.aper_size / 3;
+       kgem->max_gpu_size = kgem->max_object_size;
+       if (!kgem->has_llc)
+               kgem->max_gpu_size = MAX_CACHE_SIZE;
+       if (gen < 40) {
+               /* If we have to use fences for blitting, we have to make
+                * sure we can fit them into the aperture.
+                */
+               kgem->max_gpu_size = kgem->aperture_mappable / 2;
+               if (kgem->max_gpu_size > kgem->aperture_low)
+                       kgem->max_gpu_size = kgem->aperture_low;
+       }
+
+       totalram = total_ram_size();
+       if (totalram == 0) {
+               DBG(("%s: total ram size unknown, assuming maximum of total aperture\n",
+                    __FUNCTION__));
+               totalram = kgem->aperture_total;
+       }
+       DBG(("%s: total ram=%ld\n", __FUNCTION__, (long)totalram));
+       if (kgem->max_object_size > totalram / 2)
+               kgem->max_object_size = totalram / 2;
+       if (kgem->max_gpu_size > totalram / 4)
+               kgem->max_gpu_size = totalram / 4;
+
+       half_gpu_max = kgem->max_gpu_size / 2;
+       if (kgem->gen >= 40)
+               kgem->max_cpu_size = half_gpu_max;
+       else
+               kgem->max_cpu_size = kgem->max_object_size;
+
+       kgem->max_copy_tile_size = (MAX_CACHE_SIZE + 1)/2;
+       if (kgem->max_copy_tile_size > half_gpu_max)
+               kgem->max_copy_tile_size = half_gpu_max;
+
+       if (kgem->has_llc)
+               kgem->max_upload_tile_size = kgem->max_copy_tile_size;
+       else
+               kgem->max_upload_tile_size = kgem->aperture_mappable / 4;
+       if (kgem->max_upload_tile_size > half_gpu_max)
+               kgem->max_upload_tile_size = half_gpu_max;
+
+       kgem->large_object_size = MAX_CACHE_SIZE;
+       if (kgem->large_object_size > kgem->max_gpu_size)
+               kgem->large_object_size = kgem->max_gpu_size;
+
+       if (kgem->has_llc | kgem->has_cacheing | kgem->has_userptr) {
+               if (kgem->large_object_size > kgem->max_cpu_size)
+                       kgem->large_object_size = kgem->max_cpu_size;
+       } else
+               kgem->max_cpu_size = 0;
+       if (DBG_NO_CPU)
+               kgem->max_cpu_size = 0;
+
+       DBG(("%s: maximum object size=%d\n",
+            __FUNCTION__, kgem->max_object_size));
+       DBG(("%s: large object thresold=%d\n",
+            __FUNCTION__, kgem->large_object_size));
+       DBG(("%s: max object sizes (gpu=%d, cpu=%d, tile upload=%d, copy=%d)\n",
+            __FUNCTION__,
+            kgem->max_gpu_size, kgem->max_cpu_size,
+            kgem->max_upload_tile_size, kgem->max_copy_tile_size));
+
+       /* Convert the aperture thresholds to pages */
+       kgem->aperture_low /= PAGE_SIZE;
+       kgem->aperture_high /= PAGE_SIZE;
+
+       kgem->fence_max = gem_param(kgem, I915_PARAM_NUM_FENCES_AVAIL) - 2;
+       if ((int)kgem->fence_max < 0)
+               kgem->fence_max = 5; /* minimum safe value for all hw */
+       DBG(("%s: max fences=%d\n", __FUNCTION__, kgem->fence_max));
+}
+
+/* XXX hopefully a good approximation */
+static uint32_t kgem_get_unique_id(struct kgem *kgem)
+{
+       uint32_t id;
+       id = ++kgem->unique_id;
+       if (id == 0)
+               id = ++kgem->unique_id;
+       return id;
+}
+
+inline static uint32_t kgem_pitch_alignment(struct kgem *kgem, unsigned flags)
+{
+       if (flags & CREATE_PRIME)
+               return 256;
+       if (flags & CREATE_SCANOUT)
+               return 64;
+       return kgem->min_alignment;
+}
+
+static uint32_t kgem_untiled_pitch(struct kgem *kgem,
+                                  uint32_t width, uint32_t bpp,
+                                  unsigned flags)
+{
+       width = ALIGN(width, 2) * bpp >> 3;
+       return ALIGN(width, kgem_pitch_alignment(kgem, flags));
+}
+
+void kgem_get_tile_size(struct kgem *kgem, int tiling,
+                       int *tile_width, int *tile_height, int *tile_size)
+{
+       if (kgem->gen <= 30) {
+               if (tiling) {
+                       if (kgem->gen < 30) {
+                               *tile_width = 128;
+                               *tile_height = 16;
+                               *tile_size = 2048;
+                       } else {
+                               *tile_width = 512;
+                               *tile_height = 8;
+                               *tile_size = 4096;
+                       }
+               } else {
+                       *tile_width = 1;
+                       *tile_height = 1;
+                       *tile_size = 1;
+               }
+       } else switch (tiling) {
+       default:
+       case I915_TILING_NONE:
+               *tile_width = 1;
+               *tile_height = 1;
+               *tile_size = 1;
+               break;
+       case I915_TILING_X:
+               *tile_width = 512;
+               *tile_height = 8;
+               *tile_size = 4096;
+               break;
+       case I915_TILING_Y:
+               *tile_width = 128;
+               *tile_height = 32;
+               *tile_size = 4096;
+               break;
+       }
+}
+
+static uint32_t kgem_surface_size(struct kgem *kgem,
+                                 bool relaxed_fencing,
+                                 unsigned flags,
+                                 uint32_t width,
+                                 uint32_t height,
+                                 uint32_t bpp,
+                                 uint32_t tiling,
+                                 uint32_t *pitch)
+{
+       uint32_t tile_width, tile_height;
+       uint32_t size;
+
+       assert(width <= MAXSHORT);
+       assert(height <= MAXSHORT);
+
+       if (kgem->gen <= 30) {
+               if (tiling) {
+                       if (kgem->gen < 30) {
+                               tile_width = 128;
+                               tile_height = 16;
+                       } else {
+                               tile_width = 512;
+                               tile_height =  8;
+                       }
+               } else {
+                       tile_width = 2 * bpp >> 3;
+                       tile_width = ALIGN(tile_width,
+                                          kgem_pitch_alignment(kgem, flags));
+                       tile_height = 2;
+               }
+       } else switch (tiling) {
+       default:
+       case I915_TILING_NONE:
+               tile_width = 2 * bpp >> 3;
+               tile_width = ALIGN(tile_width,
+                                  kgem_pitch_alignment(kgem, flags));
+               tile_height = 2;
+               break;
+       case I915_TILING_X:
+               tile_width = 512;
+               tile_height = 8;
+               break;
+       case I915_TILING_Y:
+               tile_width = 128;
+               tile_height = 32;
+               break;
+       }
+
+       *pitch = ALIGN(width * bpp / 8, tile_width);
+       height = ALIGN(height, tile_height);
+       if (kgem->gen >= 40)
+               return PAGE_ALIGN(*pitch * height);
+
+       /* If it is too wide for the blitter, don't even bother.  */
+       if (tiling != I915_TILING_NONE) {
+               if (*pitch > 8192)
+                       return 0;
+
+               for (size = tile_width; size < *pitch; size <<= 1)
+                       ;
+               *pitch = size;
+       } else {
+               if (*pitch >= 32768)
+                       return 0;
+       }
+
+       size = *pitch * height;
+       if (relaxed_fencing || tiling == I915_TILING_NONE)
+               return PAGE_ALIGN(size);
+
+       /*  We need to allocate a pot fence region for a tiled buffer. */
+       if (kgem->gen < 30)
+               tile_width = 512 * 1024;
+       else
+               tile_width = 1024 * 1024;
+       while (tile_width < size)
+               tile_width *= 2;
+       return tile_width;
+}
+
+static uint32_t kgem_aligned_height(struct kgem *kgem,
+                                   uint32_t height, uint32_t tiling)
+{
+       uint32_t tile_height;
+
+       if (kgem->gen <= 30) {
+               tile_height = tiling ? kgem->gen < 30 ? 16 : 8 : 1;
+       } else switch (tiling) {
+       default:
+       case I915_TILING_NONE:
+               tile_height = 2;
+               break;
+       case I915_TILING_X:
+               tile_height = 8;
+               break;
+       case I915_TILING_Y:
+               tile_height = 32;
+               break;
+       }
+
+       return ALIGN(height, tile_height);
+}
+
+static struct drm_i915_gem_exec_object2 *
+kgem_add_handle(struct kgem *kgem, struct kgem_bo *bo)
+{
+       struct drm_i915_gem_exec_object2 *exec;
+
+       DBG(("%s: handle=%d, index=%d\n",
+            __FUNCTION__, bo->handle, kgem->nexec));
+
+       assert(kgem->nexec < ARRAY_SIZE(kgem->exec));
+       exec = memset(&kgem->exec[kgem->nexec++], 0, sizeof(*exec));
+       exec->handle = bo->handle;
+       exec->offset = bo->presumed_offset;
+
+       kgem->aperture += num_pages(bo);
+
+       return exec;
+}
+
+void _kgem_add_bo(struct kgem *kgem, struct kgem_bo *bo)
+{
+       bo->exec = kgem_add_handle(kgem, bo);
+       bo->rq = kgem->next_request;
+
+       list_move_tail(&bo->request, &kgem->next_request->buffers);
+
+       /* XXX is it worth working around gcc here? */
+       kgem->flush |= bo->flush;
+}
+
+static uint32_t kgem_end_batch(struct kgem *kgem)
+{
+       kgem->batch[kgem->nbatch++] = MI_BATCH_BUFFER_END;
+       if (kgem->nbatch & 1)
+               kgem->batch[kgem->nbatch++] = MI_NOOP;
+
+       return kgem->nbatch;
+}
+
+static void kgem_fixup_self_relocs(struct kgem *kgem, struct kgem_bo *bo)
+{
+       int n;
+
+       for (n = 0; n < kgem->nreloc; n++) {
+               if (kgem->reloc[n].target_handle == 0) {
+                       kgem->reloc[n].target_handle = bo->handle;
+                       kgem->reloc[n].presumed_offset = bo->presumed_offset;
+                       kgem->batch[kgem->reloc[n].offset/sizeof(kgem->batch[0])] =
+                               kgem->reloc[n].delta + bo->presumed_offset;
+               }
+       }
+}
+
+static void kgem_bo_binding_free(struct kgem *kgem, struct kgem_bo *bo)
+{
+       struct kgem_bo_binding *b;
+
+       b = bo->binding.next;
+       while (b) {
+               struct kgem_bo_binding *next = b->next;
+               free (b);
+               b = next;
+       }
+}
+
+static void kgem_bo_release_map(struct kgem *kgem, struct kgem_bo *bo)
+{
+       int type = IS_CPU_MAP(bo->map);
+
+       assert(!IS_USER_MAP(bo->map));
+
+       DBG(("%s: releasing %s vma for handle=%d, count=%d\n",
+            __FUNCTION__, type ? "CPU" : "GTT",
+            bo->handle, kgem->vma[type].count));
+
+       VG(if (type) VALGRIND_MAKE_MEM_NOACCESS(MAP(bo->map), bytes(bo)));
+       munmap(MAP(bo->map), bytes(bo));
+       bo->map = NULL;
+
+       if (!list_is_empty(&bo->vma)) {
+               list_del(&bo->vma);
+               kgem->vma[type].count--;
+       }
+}
+
+static void kgem_bo_free(struct kgem *kgem, struct kgem_bo *bo)
+{
+       DBG(("%s: handle=%d\n", __FUNCTION__, bo->handle));
+       assert(bo->refcnt == 0);
+       assert(bo->exec == NULL);
+       assert(!bo->snoop || bo->rq == NULL);
+
+#ifdef DEBUG_MEMORY
+       kgem->debug_memory.bo_allocs--;
+       kgem->debug_memory.bo_bytes -= bytes(bo);
+#endif
+
+       kgem_bo_binding_free(kgem, bo);
+
+       if (IS_USER_MAP(bo->map)) {
+               assert(bo->rq == NULL);
+               assert(MAP(bo->map) != bo || bo->io);
+               if (bo != MAP(bo->map)) {
+                       DBG(("%s: freeing snooped base\n", __FUNCTION__));
+                       free(MAP(bo->map));
+               }
+               bo->map = NULL;
+       }
+       if (bo->map)
+               kgem_bo_release_map(kgem, bo);
+       assert(list_is_empty(&bo->vma));
+
+       _list_del(&bo->list);
+       _list_del(&bo->request);
+       gem_close(kgem->fd, bo->handle);
+
+       if (!bo->io) {
+               *(struct kgem_bo **)bo = __kgem_freed_bo;
+               __kgem_freed_bo = bo;
+       } else
+               free(bo);
+}
+
+inline static void kgem_bo_move_to_inactive(struct kgem *kgem,
+                                           struct kgem_bo *bo)
+{
+       DBG(("%s: moving handle=%d to inactive\n", __FUNCTION__, bo->handle));
+
+       assert(bo->refcnt == 0);
+       assert(bo->reusable);
+       assert(bo->rq == NULL);
+       assert(bo->exec == NULL);
+       assert(bo->domain != DOMAIN_GPU);
+       assert(!kgem_busy(kgem, bo->handle));
+       assert(!bo->proxy);
+       assert(!bo->io);
+       assert(!bo->needs_flush);
+       assert(list_is_empty(&bo->vma));
+
+       kgem->need_expire = true;
+
+       if (bucket(bo) >= NUM_CACHE_BUCKETS) {
+               list_move(&bo->list, &kgem->large_inactive);
+               return;
+       }
+
+       assert(bo->flush == false);
+       list_move(&bo->list, &kgem->inactive[bucket(bo)]);
+       if (bo->map) {
+               int type = IS_CPU_MAP(bo->map);
+               if (bucket(bo) >= NUM_CACHE_BUCKETS ||
+                   (!type && !kgem_bo_is_mappable(kgem, bo))) {
+                       munmap(MAP(bo->map), bytes(bo));
+                       bo->map = NULL;
+               }
+               if (bo->map) {
+                       list_add(&bo->vma, &kgem->vma[type].inactive[bucket(bo)]);
+                       kgem->vma[type].count++;
+               }
+       }
+}
+
+inline static void kgem_bo_remove_from_inactive(struct kgem *kgem,
+                                               struct kgem_bo *bo)
+{
+       DBG(("%s: removing handle=%d from inactive\n", __FUNCTION__, bo->handle));
+
+       list_del(&bo->list);
+       assert(bo->rq == NULL);
+       assert(bo->exec == NULL);
+       if (bo->map) {
+               assert(!list_is_empty(&bo->vma));
+               list_del(&bo->vma);
+               kgem->vma[IS_CPU_MAP(bo->map)].count--;
+       }
+}
+
+inline static void kgem_bo_remove_from_active(struct kgem *kgem,
+                                             struct kgem_bo *bo)
+{
+       DBG(("%s: removing handle=%d from active\n", __FUNCTION__, bo->handle));
+
+       list_del(&bo->list);
+       assert(bo->rq != NULL);
+       if (bo->rq == &_kgem_static_request)
+               list_del(&bo->request);
+       assert(list_is_empty(&bo->vma));
+}
+
+static void kgem_bo_clear_scanout(struct kgem *kgem, struct kgem_bo *bo)
+{
+       if (!bo->scanout)
+               return;
+
+       assert(bo->proxy == NULL);
+
+       DBG(("%s: handle=%d, fb=%d (reusable=%d)\n",
+            __FUNCTION__, bo->handle, bo->delta, bo->reusable));
+       if (bo->delta) {
+               /* XXX will leak if we are not DRM_MASTER. *shrug* */
+               drmModeRmFB(kgem->fd, bo->delta);
+               bo->delta = 0;
+       }
+
+       bo->scanout = false;
+       bo->needs_flush = true;
+       bo->flush = false;
+       bo->reusable = true;
+
+       if (kgem->has_llc &&
+           gem_set_cacheing(kgem->fd, bo->handle, SNOOPED))
+               bo->reusable = false;
+}
+
+static void _kgem_bo_delete_buffer(struct kgem *kgem, struct kgem_bo *bo)
+{
+       struct kgem_buffer *io = (struct kgem_buffer *)bo->proxy;
+
+       DBG(("%s: size=%d, offset=%d, parent used=%d\n",
+            __FUNCTION__, bo->size.bytes, bo->delta, io->used));
+
+       if (ALIGN(bo->delta + bo->size.bytes, UPLOAD_ALIGNMENT) == io->used)
+               io->used = bo->delta;
+}
+
+static void kgem_bo_move_to_snoop(struct kgem *kgem, struct kgem_bo *bo)
+{
+       assert(bo->refcnt == 0);
+       assert(bo->exec == NULL);
+
+       if (num_pages(bo) > kgem->max_cpu_size >> 13) {
+               DBG(("%s handle=%d discarding large CPU buffer (%d >%d pages)\n",
+                    __FUNCTION__, bo->handle, num_pages(bo), kgem->max_cpu_size >> 13));
+               kgem_bo_free(kgem, bo);
+               return;
+       }
+
+       assert(bo->tiling == I915_TILING_NONE);
+       assert(bo->rq == NULL);
+
+       DBG(("%s: moving %d to snoop cachee\n", __FUNCTION__, bo->handle));
+       list_add(&bo->list, &kgem->snoop);
+}
+
+static struct kgem_bo *
+search_snoop_cache(struct kgem *kgem, unsigned int num_pages, unsigned flags)
+{
+       struct kgem_bo *bo, *first = NULL;
+
+       DBG(("%s: num_pages=%d, flags=%x\n", __FUNCTION__, num_pages, flags));
+
+       if ((kgem->has_cacheing | kgem->has_userptr) == 0)
+               return NULL;
+
+       if (list_is_empty(&kgem->snoop)) {
+               DBG(("%s: inactive and cache empty\n", __FUNCTION__));
+               if (!__kgem_throttle_retire(kgem, flags)) {
+                       DBG(("%s: nothing retired\n", __FUNCTION__));
+                       return NULL;
+               }
+       }
+
+       list_for_each_entry(bo, &kgem->snoop, list) {
+               assert(bo->refcnt == 0);
+               assert(bo->snoop);
+               assert(bo->proxy == NULL);
+               assert(bo->tiling == I915_TILING_NONE);
+               assert(bo->rq == NULL);
+               assert(bo->exec == NULL);
+
+               if (num_pages > num_pages(bo))
+                       continue;
+
+               if (num_pages(bo) > 2*num_pages) {
+                       if (first == NULL)
+                               first = bo;
+                       continue;
+               }
+
+               list_del(&bo->list);
+               bo->pitch = 0;
+               bo->delta = 0;
+
+               DBG(("  %s: found handle=%d (num_pages=%d) in snoop cache\n",
+                    __FUNCTION__, bo->handle, num_pages(bo)));
+               return bo;
+       }
+
+       if (first) {
+               list_del(&first->list);
+               first->pitch = 0;
+               first->delta = 0;
+
+               DBG(("  %s: found handle=%d (num_pages=%d) in snoop cache\n",
+                    __FUNCTION__, first->handle, num_pages(first)));
+               return first;
+       }
+
+       return NULL;
+}
+
+static void __kgem_bo_destroy(struct kgem *kgem, struct kgem_bo *bo)
+{
+       DBG(("%s: handle=%d\n", __FUNCTION__, bo->handle));
+
+       assert(list_is_empty(&bo->list));
+       assert(bo->refcnt == 0);
+       assert(!bo->purged);
+       assert(bo->proxy == NULL);
+
+       bo->binding.offset = 0;
+       kgem_bo_clear_scanout(kgem, bo);
+
+       if (DBG_NO_CACHE)
+               goto destroy;
+
+       if (bo->snoop && !bo->flush) {
+               DBG(("%s: handle=%d is snooped\n", __FUNCTION__, bo->handle));
+               assert(!bo->flush);
+               assert(list_is_empty(&bo->list));
+               if (bo->rq == NULL) {
+                       if (bo->needs_flush && kgem_busy(kgem, bo->handle)) {
+                               DBG(("%s: handle=%d is snooped, tracking until free\n",
+                                    __FUNCTION__, bo->handle));
+                               list_add(&bo->request, &kgem->flushing);
+                               bo->rq = &_kgem_static_request;
+                       }
+               }
+               if (bo->rq == NULL)
+                       kgem_bo_move_to_snoop(kgem, bo);
+               return;
+       }
+
+       if (bo->io) {
+               struct kgem_bo *base;
+
+               assert(!bo->snoop);
+               base = malloc(sizeof(*base));
+               if (base) {
+                       DBG(("%s: transferring io handle=%d to bo\n",
+                            __FUNCTION__, bo->handle));
+                       /* transfer the handle to a minimum bo */
+                       memcpy(base, bo, sizeof(*base));
+                       base->io = false;
+                       list_init(&base->list);
+                       list_replace(&bo->request, &base->request);
+                       list_replace(&bo->vma, &base->vma);
+                       free(bo);
+                       bo = base;
+               } else
+                       bo->reusable = false;
+       }
+
+       if (!bo->reusable) {
+               DBG(("%s: handle=%d, not reusable\n",
+                    __FUNCTION__, bo->handle));
+               goto destroy;
+       }
+
+       if (!kgem->has_llc && IS_CPU_MAP(bo->map) && bo->domain != DOMAIN_CPU)
+               kgem_bo_release_map(kgem, bo);
+
+       assert(list_is_empty(&bo->vma));
+       assert(list_is_empty(&bo->list));
+       assert(bo->snoop == false);
+       assert(bo->io == false);
+       assert(bo->scanout == false);
+
+       if (bo->rq) {
+               struct list *cache;
+
+               DBG(("%s: handle=%d -> active\n", __FUNCTION__, bo->handle));
+               if (bucket(bo) < NUM_CACHE_BUCKETS)
+                       cache = &kgem->active[bucket(bo)][bo->tiling];
+               else
+                       cache = &kgem->large;
+               list_add(&bo->list, cache);
+               return;
+       }
+
+       assert(bo->exec == NULL);
+       assert(list_is_empty(&bo->request));
+
+       if (bo->needs_flush) {
+               if ((bo->needs_flush = kgem_busy(kgem, bo->handle))) {
+                       struct list *cache;
+
+                       DBG(("%s: handle=%d -> flushing\n",
+                            __FUNCTION__, bo->handle));
+
+                       list_add(&bo->request, &kgem->flushing);
+                       if (bucket(bo) < NUM_CACHE_BUCKETS)
+                               cache = &kgem->active[bucket(bo)][bo->tiling];
+                       else
+                               cache = &kgem->large;
+                       list_add(&bo->list, cache);
+                       bo->rq = &_kgem_static_request;
+                       return;
+               }
+
+               bo->domain = DOMAIN_NONE;
+       }
+
+       if (!IS_CPU_MAP(bo->map)) {
+               if (!kgem_bo_set_purgeable(kgem, bo))
+                       goto destroy;
+
+               if (!kgem->has_llc && bo->domain == DOMAIN_CPU)
+                       goto destroy;
+
+               DBG(("%s: handle=%d, purged\n",
+                    __FUNCTION__, bo->handle));
+       }
+
+       kgem_bo_move_to_inactive(kgem, bo);
+       return;
+
+destroy:
+       if (!bo->exec)
+               kgem_bo_free(kgem, bo);
+}
+
+static void kgem_bo_unref(struct kgem *kgem, struct kgem_bo *bo)
+{
+       assert(bo->refcnt);
+       if (--bo->refcnt == 0)
+               __kgem_bo_destroy(kgem, bo);
+}
+
+static void kgem_buffer_release(struct kgem *kgem, struct kgem_buffer *bo)
+{
+       while (!list_is_empty(&bo->base.vma)) {
+               struct kgem_bo *cached;
+
+               cached = list_first_entry(&bo->base.vma, struct kgem_bo, vma);
+               assert(cached->proxy == &bo->base);
+               list_del(&cached->vma);
+
+               assert(*(struct kgem_bo **)cached->map == cached);
+               *(struct kgem_bo **)cached->map = NULL;
+               cached->map = NULL;
+
+               kgem_bo_destroy(kgem, cached);
+       }
+}
+
+static bool kgem_retire__buffers(struct kgem *kgem)
+{
+       bool retired = false;
+
+       while (!list_is_empty(&kgem->active_buffers)) {
+               struct kgem_buffer *bo =
+                       list_last_entry(&kgem->active_buffers,
+                                       struct kgem_buffer,
+                                       base.list);
+
+               if (bo->base.rq)
+                       break;
+
+               DBG(("%s: releasing upload cache for handle=%d? %d\n",
+                    __FUNCTION__, bo->base.handle, !list_is_empty(&bo->base.vma)));
+               list_del(&bo->base.list);
+               kgem_buffer_release(kgem, bo);
+               kgem_bo_unref(kgem, &bo->base);
+               retired = true;
+       }
+
+       return retired;
+}
+
+static bool kgem_retire__flushing(struct kgem *kgem)
+{
+       struct kgem_bo *bo, *next;
+       bool retired = false;
+
+       list_for_each_entry_safe(bo, next, &kgem->flushing, request) {
+               assert(bo->rq == &_kgem_static_request);
+               assert(bo->exec == NULL);
+
+               if (kgem_busy(kgem, bo->handle))
+                       break;
+
+               bo->needs_flush = false;
+               bo->domain = DOMAIN_NONE;
+               bo->rq = NULL;
+               list_del(&bo->request);
+
+               if (!bo->refcnt) {
+                       if (bo->snoop) {
+                               kgem_bo_move_to_snoop(kgem, bo);
+                       } else if (kgem_bo_set_purgeable(kgem, bo)) {
+                               assert(bo->reusable);
+                               kgem_bo_move_to_inactive(kgem, bo);
+                               retired = true;
+                       } else
+                               kgem_bo_free(kgem, bo);
+               }
+       }
+#if HAS_DEBUG_FULL
+       {
+               int count = 0;
+               list_for_each_entry(bo, &kgem->flushing, request)
+                       count++;
+               ErrorF("%s: %d bo on flushing list\n", __FUNCTION__, count);
+       }
+#endif
+
+       return retired;
+}
+
+static bool kgem_retire__requests(struct kgem *kgem)
+{
+       struct kgem_bo *bo;
+       bool retired = false;
+       int n;
+
+       for (n = 0; n < ARRAY_SIZE(kgem->requests); n++) {
+               while (!list_is_empty(&kgem->requests[n])) {
+                       struct kgem_request *rq;
+
+                       rq = list_first_entry(&kgem->requests[n],
+                                             struct kgem_request,
+                                             list);
+                       if (kgem_busy(kgem, rq->bo->handle))
+                               break;
+
+                       DBG(("%s: request %d complete\n",
+                            __FUNCTION__, rq->bo->handle));
+
+                       while (!list_is_empty(&rq->buffers)) {
+                               bo = list_first_entry(&rq->buffers,
+                                                     struct kgem_bo,
+                                                     request);
+
+                               assert(bo->rq == rq);
+                               assert(bo->exec == NULL);
+                               assert(bo->domain == DOMAIN_GPU);
+
+                               list_del(&bo->request);
+
+                               if (bo->needs_flush)
+                                       bo->needs_flush = kgem_busy(kgem, bo->handle);
+                               if (bo->needs_flush) {
+                                       DBG(("%s: moving %d to flushing\n",
+                                            __FUNCTION__, bo->handle));
+                                       list_add(&bo->request, &kgem->flushing);
+                                       bo->rq = &_kgem_static_request;
+                               } else {
+                                       bo->domain = DOMAIN_NONE;
+                                       bo->rq = NULL;
+                               }
+
+                               if (bo->refcnt)
+                                       continue;
+
+                               if (bo->snoop) {
+                                       if (bo->needs_flush) {
+                                               list_add(&bo->request, &kgem->flushing);
+                                               bo->rq = &_kgem_static_request;
+                                       } else {
+                                               kgem_bo_move_to_snoop(kgem, bo);
+                                       }
+                                       continue;
+                               }
+
+                               if (!bo->reusable) {
+                                       DBG(("%s: closing %d\n",
+                                            __FUNCTION__, bo->handle));
+                                       kgem_bo_free(kgem, bo);
+                                       continue;
+                               }
+
+                               if (!bo->needs_flush) {
+                                       if (kgem_bo_set_purgeable(kgem, bo)) {
+                                               kgem_bo_move_to_inactive(kgem, bo);
+                                               retired = true;
+                                       } else {
+                                               DBG(("%s: closing %d\n",
+                                                    __FUNCTION__, bo->handle));
+                                               kgem_bo_free(kgem, bo);
+                                       }
+                               }
+                       }
+
+                       assert(rq->bo->rq == NULL);
+                       assert(list_is_empty(&rq->bo->request));
+
+                       if (--rq->bo->refcnt == 0) {
+                               if (kgem_bo_set_purgeable(kgem, rq->bo)) {
+                                       kgem_bo_move_to_inactive(kgem, rq->bo);
+                                       retired = true;
+                               } else {
+                                       DBG(("%s: closing %d\n",
+                                            __FUNCTION__, rq->bo->handle));
+                                       kgem_bo_free(kgem, rq->bo);
+                               }
+                       }
+
+                       __kgem_request_free(rq);
+                       kgem->num_requests--;
+               }
+
+#if HAS_DEBUG_FULL
+               {
+                       int count = 0;
+
+                       list_for_each_entry(bo, &kgem->requests[n], request)
+                               count++;
+
+                       bo = NULL;
+                       if (!list_is_empty(&kgem->requests[n]))
+                               bo = list_first_entry(&kgem->requests[n],
+                                                     struct kgem_request,
+                                                     list)->bo;
+
+                       ErrorF("%s: ring=%d, %d outstanding requests, oldest=%d\n",
+                              __FUNCTION__, n, count, bo ? bo->handle : 0);
+               }
+#endif
+       }
+
+#if HAS_DEBUG_FULL
+       {
+               int count = 0;
+
+               for (n = 0; n < ARRAY_SIZE(kgem->requests); n++)
+                       list_for_each_entry(bo, &kgem->requests[n], request)
+                               count++;
+
+               assert(count == kgem->num_requests);
+       }
+#endif
+
+       return retired;
+}
+
+bool kgem_retire(struct kgem *kgem)
+{
+       bool retired = false;
+
+       DBG(("%s\n", __FUNCTION__));
+
+       retired |= kgem_retire__flushing(kgem);
+       if (kgem->num_requests)
+               retired |= kgem_retire__requests(kgem);
+       retired |= kgem_retire__buffers(kgem);
+
+       kgem->need_retire =
+               kgem->num_requests ||
+               !list_is_empty(&kgem->flushing);
+       DBG(("%s -- retired=%d, need_retire=%d\n",
+            __FUNCTION__, retired, kgem->need_retire));
+
+       kgem->retire(kgem);
+
+       return retired;
+}
+
+bool __kgem_is_idle(struct kgem *kgem)
+{
+       int n;
+
+       assert(kgem->num_requests);
+
+       for (n = 0; n < ARRAY_SIZE(kgem->requests); n++) {
+               struct kgem_request *rq;
+
+               if (list_is_empty(&kgem->requests[n]))
+                       continue;
+
+               rq = list_last_entry(&kgem->requests[n],
+                                    struct kgem_request, list);
+               if (kgem_busy(kgem, rq->bo->handle)) {
+                       DBG(("%s: last requests handle=%d still busy\n",
+                            __FUNCTION__, rq->bo->handle));
+                       return false;
+               }
+
+               DBG(("%s: ring=%d idle (handle=%d)\n",
+                    __FUNCTION__, n, rq->bo->handle));
+       }
+       kgem_retire__requests(kgem);
+       assert(kgem->num_requests == 0);
+       return true;
+}
+
+static void kgem_commit(struct kgem *kgem)
+{
+       struct kgem_request *rq = kgem->next_request;
+       struct kgem_bo *bo, *next;
+
+       list_for_each_entry_safe(bo, next, &rq->buffers, request) {
+               assert(next->request.prev == &bo->request);
+
+               DBG(("%s: release handle=%d (proxy? %d), dirty? %d flush? %d, snoop? %d -> offset=%x\n",
+                    __FUNCTION__, bo->handle, bo->proxy != NULL,
+                    bo->dirty, bo->needs_flush, bo->snoop,
+                    (unsigned)bo->exec->offset));
+
+               assert(!bo->purged);
+               assert(bo->exec);
+               assert(bo->proxy == NULL || bo->exec == &_kgem_dummy_exec);
+               assert(bo->rq == rq || (bo->proxy->rq == rq));
+
+               bo->presumed_offset = bo->exec->offset;
+               bo->exec = NULL;
+
+               if (!bo->refcnt && !bo->reusable) {
+                       assert(!bo->snoop);
+                       kgem_bo_free(kgem, bo);
+                       continue;
+               }
+
+               bo->binding.offset = 0;
+               bo->domain = DOMAIN_GPU;
+               bo->dirty = false;
+
+               if (bo->proxy) {
+                       /* proxies are not used for domain tracking */
+                       list_del(&bo->request);
+                       bo->rq = NULL;
+                       bo->exec = NULL;
+               }
+       }
+
+       if (rq == &_kgem_static_request) {
+               struct drm_i915_gem_set_domain set_domain;
+
+               DBG(("%s: syncing due to allocation failure\n", __FUNCTION__));
+
+               VG_CLEAR(set_domain);
+               set_domain.handle = rq->bo->handle;
+               set_domain.read_domains = I915_GEM_DOMAIN_GTT;
+               set_domain.write_domain = I915_GEM_DOMAIN_GTT;
+               if (drmIoctl(kgem->fd, DRM_IOCTL_I915_GEM_SET_DOMAIN, &set_domain)) {
+                       DBG(("%s: sync: GPU hang detected\n", __FUNCTION__));
+                       kgem_throttle(kgem);
+               }
+
+               kgem_retire(kgem);
+               assert(list_is_empty(&rq->buffers));
+
+               gem_close(kgem->fd, rq->bo->handle);
+       } else {
+               list_add_tail(&rq->list, &kgem->requests[rq->ring]);
+               kgem->need_throttle = kgem->need_retire = 1;
+               kgem->num_requests++;
+       }
+
+       kgem->next_request = NULL;
+}
+
+static void kgem_close_list(struct kgem *kgem, struct list *head)
+{
+       while (!list_is_empty(head))
+               kgem_bo_free(kgem, list_first_entry(head, struct kgem_bo, list));
+}
+
+static void kgem_close_inactive(struct kgem *kgem)
+{
+       unsigned int i;
+
+       for (i = 0; i < ARRAY_SIZE(kgem->inactive); i++)
+               kgem_close_list(kgem, &kgem->inactive[i]);
+}
+
+static void kgem_finish_buffers(struct kgem *kgem)
+{
+       struct kgem_buffer *bo, *next;
+
+       list_for_each_entry_safe(bo, next, &kgem->batch_buffers, base.list) {
+               DBG(("%s: buffer handle=%d, used=%d, exec?=%d, write=%d, mmapped=%d\n",
+                    __FUNCTION__, bo->base.handle, bo->used, bo->base.exec!=NULL,
+                    bo->write, bo->mmapped));
+
+               assert(next->base.list.prev == &bo->base.list);
+               assert(bo->base.io);
+               assert(bo->base.refcnt >= 1);
+
+               if (!bo->base.exec) {
+                       DBG(("%s: skipping unattached handle=%d, used=%d\n",
+                            __FUNCTION__, bo->base.handle, bo->used));
+                       continue;
+               }
+
+               if (!bo->write) {
+                       assert(bo->base.exec || bo->base.refcnt > 1);
+                       goto decouple;
+               }
+
+               if (bo->mmapped) {
+                       int used;
+
+                       assert(!bo->need_io);
+
+                       used = ALIGN(bo->used + PAGE_SIZE-1, PAGE_SIZE);
+                       if (!DBG_NO_UPLOAD_ACTIVE &&
+                           used + PAGE_SIZE <= bytes(&bo->base) &&
+                           (kgem->has_llc || !IS_CPU_MAP(bo->base.map))) {
+                               DBG(("%s: retaining upload buffer (%d/%d)\n",
+                                    __FUNCTION__, bo->used, bytes(&bo->base)));
+                               assert(!bo->base.snoop);
+                               bo->used = used;
+                               list_move(&bo->base.list,
+                                         &kgem->active_buffers);
+                               continue;
+                       }
+                       DBG(("%s: discarding mmapped buffer, used=%d, map type=%d\n",
+                            __FUNCTION__, bo->used, (int)__MAP_TYPE(bo->base.map)));
+                       goto decouple;
+               }
+
+               if (!bo->used) {
+                       /* Unless we replace the handle in the execbuffer,
+                        * then this bo will become active. So decouple it
+                        * from the buffer list and track it in the normal
+                        * manner.
+                        */
+                       goto decouple;
+               }
+
+               assert(bo->need_io);
+               assert(bo->base.rq == kgem->next_request);
+               assert(bo->base.domain != DOMAIN_GPU);
+
+               if (bo->base.refcnt == 1 &&
+                   bo->base.size.pages.count > 1 &&
+                   bo->used < bytes(&bo->base) / 2) {
+                       struct kgem_bo *shrink;
+
+                       shrink = search_linear_cache(kgem,
+                                                    PAGE_ALIGN(bo->used),
+                                                    CREATE_INACTIVE | CREATE_NO_RETIRE);
+                       if (shrink) {
+                               int n;
+
+                               DBG(("%s: used=%d, shrinking %d to %d, handle %d to %d\n",
+                                    __FUNCTION__,
+                                    bo->used, bytes(&bo->base), bytes(shrink),
+                                    bo->base.handle, shrink->handle));
+
+                               assert(bo->used <= bytes(shrink));
+                               gem_write(kgem->fd, shrink->handle,
+                                         0, bo->used, bo->mem);
+
+                               for (n = 0; n < kgem->nreloc; n++) {
+                                       if (kgem->reloc[n].target_handle == bo->base.handle) {
+                                               kgem->reloc[n].target_handle = shrink->handle;
+                                               kgem->reloc[n].presumed_offset = shrink->presumed_offset;
+                                               kgem->batch[kgem->reloc[n].offset/sizeof(kgem->batch[0])] =
+                                                       kgem->reloc[n].delta + shrink->presumed_offset;
+                                       }
+                               }
+
+                               bo->base.exec->handle = shrink->handle;
+                               bo->base.exec->offset = shrink->presumed_offset;
+                               shrink->exec = bo->base.exec;
+                               shrink->rq = bo->base.rq;
+                               list_replace(&bo->base.request,
+                                            &shrink->request);
+                               list_init(&bo->base.request);
+                               shrink->needs_flush = bo->base.dirty;
+
+                               bo->base.exec = NULL;
+                               bo->base.rq = NULL;
+                               bo->base.dirty = false;
+                               bo->base.needs_flush = false;
+                               bo->used = 0;
+
+                               goto decouple;
+                       }
+               }
+
+               DBG(("%s: handle=%d, uploading %d/%d\n",
+                    __FUNCTION__, bo->base.handle, bo->used, bytes(&bo->base)));
+               assert(!kgem_busy(kgem, bo->base.handle));
+               assert(bo->used <= bytes(&bo->base));
+               gem_write(kgem->fd, bo->base.handle,
+                         0, bo->used, bo->mem);
+               bo->need_io = 0;
+
+decouple:
+               DBG(("%s: releasing handle=%d\n",
+                    __FUNCTION__, bo->base.handle));
+               list_del(&bo->base.list);
+               kgem_bo_unref(kgem, &bo->base);
+       }
+}
+
+static void kgem_cleanup(struct kgem *kgem)
+{
+       int n;
+
+       for (n = 0; n < ARRAY_SIZE(kgem->requests); n++) {
+               while (!list_is_empty(&kgem->requests[n])) {
+                       struct kgem_request *rq;
+
+                       rq = list_first_entry(&kgem->requests[n],
+                                             struct kgem_request,
+                                             list);
+                       while (!list_is_empty(&rq->buffers)) {
+                               struct kgem_bo *bo;
+
+                               bo = list_first_entry(&rq->buffers,
+                                                     struct kgem_bo,
+                                                     request);
+
+                               list_del(&bo->request);
+                               bo->rq = NULL;
+                               bo->exec = NULL;
+                               bo->domain = DOMAIN_NONE;
+                               bo->dirty = false;
+                               if (bo->refcnt == 0)
+                                       kgem_bo_free(kgem, bo);
+                       }
+
+                       __kgem_request_free(rq);
+               }
+       }
+
+       kgem->num_requests = 0;
+       kgem_close_inactive(kgem);
+}
+
+static int kgem_batch_write(struct kgem *kgem, uint32_t handle, uint32_t size)
+{
+       int ret;
+
+       assert(!kgem_busy(kgem, handle));
+
+       /* If there is no surface data, just upload the batch */
+       if (kgem->surface == kgem->batch_size)
+               return gem_write(kgem->fd, handle,
+                                0, sizeof(uint32_t)*kgem->nbatch,
+                                kgem->batch);
+
+       /* Are the batch pages conjoint with the surface pages? */
+       if (kgem->surface < kgem->nbatch + PAGE_SIZE/sizeof(uint32_t)) {
+               assert(size == PAGE_ALIGN(kgem->batch_size*sizeof(uint32_t)));
+               return gem_write(kgem->fd, handle,
+                                0, kgem->batch_size*sizeof(uint32_t),
+                                kgem->batch);
+       }
+
+       /* Disjoint surface/batch, upload separately */
+       ret = gem_write(kgem->fd, handle,
+                       0, sizeof(uint32_t)*kgem->nbatch,
+                       kgem->batch);
+       if (ret)
+               return ret;
+
+       ret = PAGE_ALIGN(sizeof(uint32_t) * kgem->batch_size);
+       ret -= sizeof(uint32_t) * kgem->surface;
+       assert(size-ret >= kgem->nbatch*sizeof(uint32_t));
+       return __gem_write(kgem->fd, handle,
+                       size - ret, (kgem->batch_size - kgem->surface)*sizeof(uint32_t),
+                       kgem->batch + kgem->surface);
+}
+
+void kgem_reset(struct kgem *kgem)
+{
+       if (kgem->next_request) {
+               struct kgem_request *rq = kgem->next_request;
+
+               while (!list_is_empty(&rq->buffers)) {
+                       struct kgem_bo *bo =
+                               list_first_entry(&rq->buffers,
+                                                struct kgem_bo,
+                                                request);
+                       list_del(&bo->request);
+
+                       bo->binding.offset = 0;
+                       bo->exec = NULL;
+                       bo->dirty = false;
+                       bo->rq = NULL;
+                       bo->domain = DOMAIN_NONE;
+
+                       if (!bo->refcnt) {
+                               DBG(("%s: discarding handle=%d\n",
+                                    __FUNCTION__, bo->handle));
+                               kgem_bo_free(kgem, bo);
+                       }
+               }
+
+               if (kgem->next_request != &_kgem_static_request)
+                       free(kgem->next_request);
+       }
+
+       kgem->nfence = 0;
+       kgem->nexec = 0;
+       kgem->nreloc = 0;
+       kgem->aperture = 0;
+       kgem->aperture_fenced = 0;
+       kgem->nbatch = 0;
+       kgem->surface = kgem->batch_size;
+       kgem->mode = KGEM_NONE;
+       kgem->flush = 0;
+
+       kgem->next_request = __kgem_request_alloc();
+
+       kgem_sna_reset(kgem);
+}
+
+static int compact_batch_surface(struct kgem *kgem)
+{
+       int size, shrink, n;
+
+       if (!kgem->has_relaxed_delta)
+               return kgem->batch_size;
+
+       /* See if we can pack the contents into one or two pages */
+       n = ALIGN(kgem->batch_size, 1024);
+       size = n - kgem->surface + kgem->nbatch;
+       size = ALIGN(size, 1024);
+
+       shrink = n - size;
+       if (shrink) {
+               DBG(("shrinking from %d to %d\n", kgem->batch_size, size));
+
+               shrink *= sizeof(uint32_t);
+               for (n = 0; n < kgem->nreloc; n++) {
+                       if (kgem->reloc[n].read_domains == I915_GEM_DOMAIN_INSTRUCTION &&
+                           kgem->reloc[n].target_handle == 0)
+                               kgem->reloc[n].delta -= shrink;
+
+                       if (kgem->reloc[n].offset >= sizeof(uint32_t)*kgem->nbatch)
+                               kgem->reloc[n].offset -= shrink;
+               }
+       }
+
+       return size * sizeof(uint32_t);
+}
+
+void _kgem_submit(struct kgem *kgem)
+{
+       struct kgem_request *rq;
+       uint32_t batch_end;
+       int size;
+
+       assert(!DBG_NO_HW);
+       assert(!kgem->wedged);
+
+       assert(kgem->nbatch);
+       assert(kgem->nbatch <= KGEM_BATCH_SIZE(kgem));
+       assert(kgem->nbatch <= kgem->surface);
+
+       batch_end = kgem_end_batch(kgem);
+       kgem_sna_flush(kgem);
+
+       DBG(("batch[%d/%d]: %d %d %d %d, nreloc=%d, nexec=%d, nfence=%d, aperture=%d\n",
+            kgem->mode, kgem->ring, batch_end, kgem->nbatch, kgem->surface, kgem->batch_size,
+            kgem->nreloc, kgem->nexec, kgem->nfence, kgem->aperture));
+
+       assert(kgem->nbatch <= kgem->batch_size);
+       assert(kgem->nbatch <= kgem->surface);
+       assert(kgem->nreloc <= ARRAY_SIZE(kgem->reloc));
+       assert(kgem->nexec < ARRAY_SIZE(kgem->exec));
+       assert(kgem->nfence <= kgem->fence_max);
+
+       kgem_finish_buffers(kgem);
+
+#if HAS_DEBUG_FULL && SHOW_BATCH
+       __kgem_batch_debug(kgem, batch_end);
+#endif
+
+       rq = kgem->next_request;
+       if (kgem->surface != kgem->batch_size)
+               size = compact_batch_surface(kgem);
+       else
+               size = kgem->nbatch * sizeof(kgem->batch[0]);
+       rq->bo = kgem_create_linear(kgem, size, CREATE_NO_THROTTLE);
+       if (rq->bo) {
+               uint32_t handle = rq->bo->handle;
+               int i;
+
+               assert(!rq->bo->needs_flush);
+
+               i = kgem->nexec++;
+               kgem->exec[i].handle = handle;
+               kgem->exec[i].relocation_count = kgem->nreloc;
+               kgem->exec[i].relocs_ptr = (uintptr_t)kgem->reloc;
+               kgem->exec[i].alignment = 0;
+               kgem->exec[i].offset = 0;
+               kgem->exec[i].flags = 0;
+               kgem->exec[i].rsvd1 = 0;
+               kgem->exec[i].rsvd2 = 0;
+
+               rq->bo->exec = &kgem->exec[i];
+               rq->bo->rq = rq; /* useful sanity check */
+               list_add(&rq->bo->request, &rq->buffers);
+               rq->ring = kgem->ring == KGEM_BLT;
+
+               kgem_fixup_self_relocs(kgem, rq->bo);
+
+               if (kgem_batch_write(kgem, handle, size) == 0) {
+                       struct drm_i915_gem_execbuffer2 execbuf;
+                       int ret, retry = 3;
+
+                       VG_CLEAR(execbuf);
+                       execbuf.buffers_ptr = (uintptr_t)kgem->exec;
+                       execbuf.buffer_count = kgem->nexec;
+                       execbuf.batch_start_offset = 0;
+                       execbuf.batch_len = batch_end*sizeof(uint32_t);
+                       execbuf.cliprects_ptr = 0;
+                       execbuf.num_cliprects = 0;
+                       execbuf.DR1 = 0;
+                       execbuf.DR4 = 0;
+                       execbuf.flags = kgem->ring;
+                       execbuf.rsvd1 = 0;
+                       execbuf.rsvd2 = 0;
+
+                       if (DBG_DUMP) {
+                               int fd = open("/tmp/i915-batchbuffers.dump",
+                                             O_WRONLY | O_CREAT | O_APPEND,
+                                             0666);
+                               if (fd != -1) {
+                                       ret = write(fd, kgem->batch, batch_end*sizeof(uint32_t));
+                                       fd = close(fd);
+                               }
+                       }
+
+                       ret = drmIoctl(kgem->fd,
+                                      DRM_IOCTL_I915_GEM_EXECBUFFER2,
+                                      &execbuf);
+                       while (ret == -1 && errno == EBUSY && retry--) {
+                               __kgem_throttle(kgem);
+                               ret = drmIoctl(kgem->fd,
+                                              DRM_IOCTL_I915_GEM_EXECBUFFER2,
+                                              &execbuf);
+                       }
+                       if (ret == -1 && (errno == EIO || errno == EBUSY)) {
+                               DBG(("%s: GPU hang detected\n", __FUNCTION__));
+                               kgem_throttle(kgem);
+                               ret = 0;
+                       }
+#if !NDEBUG
+                       if (ret < 0) {
+                               ret = errno;
+                               ErrorF("batch[%d/%d]: %d %d %d, nreloc=%d, nexec=%d, nfence=%d, aperture=%d: errno=%d\n",
+                                      kgem->mode, kgem->ring, batch_end, kgem->nbatch, kgem->surface,
+                                      kgem->nreloc, kgem->nexec, kgem->nfence, kgem->aperture, errno);
+
+                               for (i = 0; i < kgem->nexec; i++) {
+                                       struct kgem_bo *bo, *found = NULL;
+
+                                       list_for_each_entry(bo, &kgem->next_request->buffers, request) {
+                                               if (bo->handle == kgem->exec[i].handle) {
+                                                       found = bo;
+                                                       break;
+                                               }
+                                       }
+                                       ErrorF("exec[%d] = handle:%d, presumed offset: %x, size: %d, tiling %d, fenced %d, snooped %d, deleted %d\n",
+                                              i,
+                                              kgem->exec[i].handle,
+                                              (int)kgem->exec[i].offset,
+                                              found ? kgem_bo_size(found) : -1,
+                                              found ? found->tiling : -1,
+                                              (int)(kgem->exec[i].flags & EXEC_OBJECT_NEEDS_FENCE),
+                                              found ? found->snoop : -1,
+                                              found ? found->purged : -1);
+                               }
+                               for (i = 0; i < kgem->nreloc; i++) {
+                                       ErrorF("reloc[%d] = pos:%d, target:%d, delta:%d, read:%x, write:%x, offset:%x\n",
+                                              i,
+                                              (int)kgem->reloc[i].offset,
+                                              kgem->reloc[i].target_handle,
+                                              kgem->reloc[i].delta,
+                                              kgem->reloc[i].read_domains,
+                                              kgem->reloc[i].write_domain,
+                                              (int)kgem->reloc[i].presumed_offset);
+                               }
+
+                               i = open("/tmp/batchbuffer", O_WRONLY | O_CREAT | O_APPEND, 0666);
+                               if (i != -1) {
+                                       i = write(i, kgem->batch, batch_end*sizeof(uint32_t));
+                                       (void)i;
+                               }
+
+                               FatalError("SNA: failed to submit batchbuffer, errno=%d\n", ret);
+                       }
+#endif
+
+                       if (DEBUG_FLUSH_SYNC) {
+                               struct drm_i915_gem_set_domain set_domain;
+
+                               DBG(("%s: debug sync, starting\n", __FUNCTION__));
+
+                               VG_CLEAR(set_domain);
+                               set_domain.handle = handle;
+                               set_domain.read_domains = I915_GEM_DOMAIN_GTT;
+                               set_domain.write_domain = I915_GEM_DOMAIN_GTT;
+
+                               ret = drmIoctl(kgem->fd, DRM_IOCTL_I915_GEM_SET_DOMAIN, &set_domain);
+                               if (ret == -1) {
+                                       DBG(("%s: sync: GPU hang detected\n", __FUNCTION__));
+                                       kgem_throttle(kgem);
+                               }
+
+                               DBG(("%s: debug sync, completed\n", __FUNCTION__));
+                       }
+               }
+
+               kgem_commit(kgem);
+       }
+       if (kgem->wedged)
+               kgem_cleanup(kgem);
+
+       kgem_reset(kgem);
+
+       assert(kgem->next_request != NULL);
+}
+
+void kgem_throttle(struct kgem *kgem)
+{
+       kgem->need_throttle = 0;
+       if (kgem->wedged)
+               return;
+
+       kgem->wedged = __kgem_throttle(kgem);
+       if (kgem->wedged) {
+               xf86DrvMsg(kgem_get_screen_index(kgem), X_ERROR,
+                          "Detected a hung GPU, disabling acceleration.\n");
+               xf86DrvMsg(kgem_get_screen_index(kgem), X_ERROR,
+                          "When reporting this, please include i915_error_state from debugfs and the full dmesg.\n");
+       }
+}
+
+void kgem_purge_cache(struct kgem *kgem)
+{
+       struct kgem_bo *bo, *next;
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(kgem->inactive); i++) {
+               list_for_each_entry_safe(bo, next, &kgem->inactive[i], list) {
+                       if (!kgem_bo_is_retained(kgem, bo)) {
+                               DBG(("%s: purging %d\n",
+                                    __FUNCTION__, bo->handle));
+                               kgem_bo_free(kgem, bo);
+                       }
+               }
+       }
+
+       kgem->need_purge = false;
+}
+
+bool kgem_expire_cache(struct kgem *kgem)
+{
+       time_t now, expire;
+       struct kgem_bo *bo;
+       unsigned int size = 0, count = 0;
+       bool idle;
+       unsigned int i;
+
+       time(&now);
+
+       while (__kgem_freed_bo) {
+               bo = __kgem_freed_bo;
+               __kgem_freed_bo = *(struct kgem_bo **)bo;
+               free(bo);
+       }
+
+       while (__kgem_freed_request) {
+               struct kgem_request *rq = __kgem_freed_request;
+               __kgem_freed_request = *(struct kgem_request **)rq;
+               free(rq);
+       }
+
+       while (!list_is_empty(&kgem->large_inactive)) {
+               kgem_bo_free(kgem,
+                            list_first_entry(&kgem->large_inactive,
+                                             struct kgem_bo, list));
+
+       }
+
+       expire = 0;
+       list_for_each_entry(bo, &kgem->snoop, list) {
+               if (bo->delta) {
+                       expire = now - MAX_INACTIVE_TIME/2;
+                       break;
+               }
+
+               bo->delta = now;
+       }
+       if (expire) {
+               while (!list_is_empty(&kgem->snoop)) {
+                       bo = list_last_entry(&kgem->snoop, struct kgem_bo, list);
+
+                       if (bo->delta > expire)
+                               break;
+
+                       kgem_bo_free(kgem, bo);
+               }
+       }
+#ifdef DEBUG_MEMORY
+       {
+               long snoop_size = 0;
+               int snoop_count = 0;
+               list_for_each_entry(bo, &kgem->snoop, list)
+                       snoop_count++, snoop_size += bytes(bo);
+               ErrorF("%s: still allocated %d bo, %ld bytes, in snoop cache\n",
+                      __FUNCTION__, snoop_count, snoop_size);
+       }
+#endif
+
+       kgem_retire(kgem);
+       if (kgem->wedged)
+               kgem_cleanup(kgem);
+
+       kgem->expire(kgem);
+
+       if (kgem->need_purge)
+               kgem_purge_cache(kgem);
+
+       expire = 0;
+
+       idle = !kgem->need_retire;
+       for (i = 0; i < ARRAY_SIZE(kgem->inactive); i++) {
+               idle &= list_is_empty(&kgem->inactive[i]);
+               list_for_each_entry(bo, &kgem->inactive[i], list) {
+                       if (bo->delta) {
+                               expire = now - MAX_INACTIVE_TIME;
+                               break;
+                       }
+
+                       bo->delta = now;
+               }
+       }
+       if (idle) {
+               DBG(("%s: idle\n", __FUNCTION__));
+               kgem->need_expire = false;
+               return false;
+       }
+       if (expire == 0)
+               return true;
+
+       idle = !kgem->need_retire;
+       for (i = 0; i < ARRAY_SIZE(kgem->inactive); i++) {
+               struct list preserve;
+
+               list_init(&preserve);
+               while (!list_is_empty(&kgem->inactive[i])) {
+                       bo = list_last_entry(&kgem->inactive[i],
+                                            struct kgem_bo, list);
+
+                       if (bo->delta > expire) {
+                               idle = false;
+                               break;
+                       }
+
+                       if (bo->map && bo->delta + MAP_PRESERVE_TIME > expire) {
+                               idle = false;
+                               list_move_tail(&bo->list, &preserve);
+                       } else {
+                               count++;
+                               size += bytes(bo);
+                               kgem_bo_free(kgem, bo);
+                               DBG(("%s: expiring %d\n",
+                                    __FUNCTION__, bo->handle));
+                       }
+               }
+               if (!list_is_empty(&preserve)) {
+                       preserve.prev->next = kgem->inactive[i].next;
+                       kgem->inactive[i].next->prev = preserve.prev;
+                       kgem->inactive[i].next = preserve.next;
+                       preserve.next->prev = &kgem->inactive[i];
+               }
+       }
+
+#ifdef DEBUG_MEMORY
+       {
+               long inactive_size = 0;
+               int inactive_count = 0;
+               for (i = 0; i < ARRAY_SIZE(kgem->inactive); i++)
+                       list_for_each_entry(bo, &kgem->inactive[i], list)
+                               inactive_count++, inactive_size += bytes(bo);
+               ErrorF("%s: still allocated %d bo, %ld bytes, in inactive cache\n",
+                      __FUNCTION__, inactive_count, inactive_size);
+       }
+#endif
+
+       DBG(("%s: expired %d objects, %d bytes, idle? %d\n",
+            __FUNCTION__, count, size, idle));
+
+       kgem->need_expire = !idle;
+       return !idle;
+       (void)count;
+       (void)size;
+}
+
+void kgem_cleanup_cache(struct kgem *kgem)
+{
+       unsigned int i;
+       int n;
+
+       /* sync to the most recent request */
+       for (n = 0; n < ARRAY_SIZE(kgem->requests); n++) {
+               if (!list_is_empty(&kgem->requests[n])) {
+                       struct kgem_request *rq;
+                       struct drm_i915_gem_set_domain set_domain;
+
+                       rq = list_first_entry(&kgem->requests[n],
+                                             struct kgem_request,
+                                             list);
+
+                       DBG(("%s: sync on cleanup\n", __FUNCTION__));
+
+                       VG_CLEAR(set_domain);
+                       set_domain.handle = rq->bo->handle;
+                       set_domain.read_domains = I915_GEM_DOMAIN_GTT;
+                       set_domain.write_domain = I915_GEM_DOMAIN_GTT;
+                       (void)drmIoctl(kgem->fd,
+                                      DRM_IOCTL_I915_GEM_SET_DOMAIN,
+                                      &set_domain);
+               }
+       }
+
+       kgem_retire(kgem);
+       kgem_cleanup(kgem);
+
+       for (i = 0; i < ARRAY_SIZE(kgem->inactive); i++) {
+               while (!list_is_empty(&kgem->inactive[i]))
+                       kgem_bo_free(kgem,
+                                    list_last_entry(&kgem->inactive[i],
+                                                    struct kgem_bo, list));
+       }
+
+       while (!list_is_empty(&kgem->snoop))
+               kgem_bo_free(kgem,
+                            list_last_entry(&kgem->snoop,
+                                            struct kgem_bo, list));
+
+       while (__kgem_freed_bo) {
+               struct kgem_bo *bo = __kgem_freed_bo;
+               __kgem_freed_bo = *(struct kgem_bo **)bo;
+               free(bo);
+       }
+
+       kgem->need_purge = false;
+       kgem->need_expire = false;
+}
+
+static struct kgem_bo *
+search_linear_cache(struct kgem *kgem, unsigned int num_pages, unsigned flags)
+{
+       struct kgem_bo *bo, *first = NULL;
+       bool use_active = (flags & CREATE_INACTIVE) == 0;
+       struct list *cache;
+
+       DBG(("%s: num_pages=%d, flags=%x, use_active? %d\n",
+            __FUNCTION__, num_pages, flags, use_active));
+
+       if (num_pages >= MAX_CACHE_SIZE / PAGE_SIZE)
+               return NULL;
+
+       if (!use_active && list_is_empty(inactive(kgem, num_pages))) {
+               DBG(("%s: inactive and cache bucket empty\n",
+                    __FUNCTION__));
+
+               if (flags & CREATE_NO_RETIRE) {
+                       DBG(("%s: can not retire\n", __FUNCTION__));
+                       return NULL;
+               }
+
+               if (list_is_empty(active(kgem, num_pages, I915_TILING_NONE))) {
+                       DBG(("%s: active cache bucket empty\n", __FUNCTION__));
+                       return NULL;
+               }
+
+               if (!__kgem_throttle_retire(kgem, 0)) {
+                       DBG(("%s: nothing retired\n", __FUNCTION__));
+                       return NULL;
+               }
+
+               if (list_is_empty(inactive(kgem, num_pages))) {
+                       DBG(("%s: active cache bucket still empty after retire\n",
+                            __FUNCTION__));
+                       return NULL;
+               }
+       }
+
+       if (!use_active && flags & (CREATE_CPU_MAP | CREATE_GTT_MAP)) {
+               int for_cpu = !!(flags & CREATE_CPU_MAP);
+               DBG(("%s: searching for inactive %s map\n",
+                    __FUNCTION__, for_cpu ? "cpu" : "gtt"));
+               cache = &kgem->vma[for_cpu].inactive[cache_bucket(num_pages)];
+               list_for_each_entry(bo, cache, vma) {
+                       assert(IS_CPU_MAP(bo->map) == for_cpu);
+                       assert(bucket(bo) == cache_bucket(num_pages));
+                       assert(bo->proxy == NULL);
+                       assert(bo->rq == NULL);
+                       assert(bo->exec == NULL);
+
+                       if (num_pages > num_pages(bo)) {
+                               DBG(("inactive too small: %d < %d\n",
+                                    num_pages(bo), num_pages));
+                               continue;
+                       }
+
+                       if (bo->purged && !kgem_bo_clear_purgeable(kgem, bo)) {
+                               kgem_bo_free(kgem, bo);
+                               break;
+                       }
+
+                       if (I915_TILING_NONE != bo->tiling &&
+                           gem_set_tiling(kgem->fd, bo->handle,
+                                          I915_TILING_NONE, 0) != I915_TILING_NONE)
+                               continue;
+
+                       kgem_bo_remove_from_inactive(kgem, bo);
+
+                       bo->tiling = I915_TILING_NONE;
+                       bo->pitch = 0;
+                       bo->delta = 0;
+                       DBG(("  %s: found handle=%d (num_pages=%d) in linear vma cache\n",
+                            __FUNCTION__, bo->handle, num_pages(bo)));
+                       assert(use_active || bo->domain != DOMAIN_GPU);
+                       assert(!bo->needs_flush);
+                       //assert(!kgem_busy(kgem, bo->handle));
+                       return bo;
+               }
+
+               if (flags & CREATE_EXACT)
+                       return NULL;
+       }
+
+       cache = use_active ? active(kgem, num_pages, I915_TILING_NONE) : inactive(kgem, num_pages);
+       list_for_each_entry(bo, cache, list) {
+               assert(bo->refcnt == 0);
+               assert(bo->reusable);
+               assert(!!bo->rq == !!use_active);
+               assert(bo->proxy == NULL);
+
+               if (num_pages > num_pages(bo))
+                       continue;
+
+               if (use_active &&
+                   kgem->gen <= 40 &&
+                   bo->tiling != I915_TILING_NONE)
+                       continue;
+
+               if (bo->purged && !kgem_bo_clear_purgeable(kgem, bo)) {
+                       kgem_bo_free(kgem, bo);
+                       break;
+               }
+
+               if (I915_TILING_NONE != bo->tiling) {
+                       if (flags & (CREATE_CPU_MAP | CREATE_GTT_MAP))
+                               continue;
+
+                       if (first)
+                               continue;
+
+                       if (gem_set_tiling(kgem->fd, bo->handle,
+                                          I915_TILING_NONE, 0) != I915_TILING_NONE)
+                               continue;
+
+                       bo->tiling = I915_TILING_NONE;
+               }
+
+               if (bo->map) {
+                       if (flags & (CREATE_CPU_MAP | CREATE_GTT_MAP)) {
+                               int for_cpu = !!(flags & CREATE_CPU_MAP);
+                               if (IS_CPU_MAP(bo->map) != for_cpu) {
+                                       if (first != NULL)
+                                               break;
+
+                                       first = bo;
+                                       continue;
+                               }
+                       } else {
+                               if (first != NULL)
+                                       break;
+
+                               first = bo;
+                               continue;
+                       }
+               } else {
+                       if (flags & (CREATE_CPU_MAP | CREATE_GTT_MAP)) {
+                               if (first != NULL)
+                                       break;
+
+                               first = bo;
+                               continue;
+                       }
+               }
+
+               if (use_active)
+                       kgem_bo_remove_from_active(kgem, bo);
+               else
+                       kgem_bo_remove_from_inactive(kgem, bo);
+
+               assert(bo->tiling == I915_TILING_NONE);
+               bo->pitch = 0;
+               bo->delta = 0;
+               DBG(("  %s: found handle=%d (num_pages=%d) in linear %s cache\n",
+                    __FUNCTION__, bo->handle, num_pages(bo),
+                    use_active ? "active" : "inactive"));
+               assert(list_is_empty(&bo->list));
+               assert(use_active || bo->domain != DOMAIN_GPU);
+               assert(!bo->needs_flush || use_active);
+               //assert(use_active || !kgem_busy(kgem, bo->handle));
+               return bo;
+       }
+
+       if (first) {
+               assert(first->tiling == I915_TILING_NONE);
+
+               if (use_active)
+                       kgem_bo_remove_from_active(kgem, first);
+               else
+                       kgem_bo_remove_from_inactive(kgem, first);
+
+               first->pitch = 0;
+               first->delta = 0;
+               DBG(("  %s: found handle=%d (near-miss) (num_pages=%d) in linear %s cache\n",
+                    __FUNCTION__, first->handle, num_pages(first),
+                    use_active ? "active" : "inactive"));
+               assert(list_is_empty(&first->list));
+               assert(use_active || first->domain != DOMAIN_GPU);
+               assert(!first->needs_flush || use_active);
+               //assert(use_active || !kgem_busy(kgem, first->handle));
+               return first;
+       }
+
+       return NULL;
+}
+
+struct kgem_bo *kgem_create_for_name(struct kgem *kgem, uint32_t name)
+{
+       struct drm_gem_open open_arg;
+       struct kgem_bo *bo;
+
+       DBG(("%s(name=%d)\n", __FUNCTION__, name));
+
+       VG_CLEAR(open_arg);
+       open_arg.name = name;
+       if (drmIoctl(kgem->fd, DRM_IOCTL_GEM_OPEN, &open_arg))
+               return NULL;
+
+       DBG(("%s: new handle=%d\n", __FUNCTION__, open_arg.handle));
+       bo = __kgem_bo_alloc(open_arg.handle, open_arg.size / PAGE_SIZE);
+       if (bo == NULL) {
+               gem_close(kgem->fd, open_arg.handle);
+               return NULL;
+       }
+
+       bo->reusable = false;
+       bo->flush = true;
+
+       debug_alloc__bo(kgem, bo);
+       return bo;
+}
+
+struct kgem_bo *kgem_create_for_prime(struct kgem *kgem, int name, uint32_t size)
+{
+#ifdef DRM_IOCTL_PRIME_FD_TO_HANDLE
+       struct drm_prime_handle args;
+       struct drm_i915_gem_get_tiling tiling;
+       struct kgem_bo *bo;
+
+       DBG(("%s(name=%d)\n", __FUNCTION__, name));
+
+       VG_CLEAR(args);
+       args.fd = name;
+       args.flags = 0;
+       if (drmIoctl(kgem->fd, DRM_IOCTL_PRIME_FD_TO_HANDLE, &args))
+               return NULL;
+
+       VG_CLEAR(tiling);
+       tiling.handle = args.handle;
+       if (drmIoctl(kgem->fd, DRM_IOCTL_I915_GEM_GET_TILING, &tiling)) {
+               gem_close(kgem->fd, args.handle);
+               return NULL;
+       }
+
+       DBG(("%s: new handle=%d, tiling=%d\n", __FUNCTION__,
+            args.handle, tiling.tiling_mode));
+       bo = __kgem_bo_alloc(args.handle, NUM_PAGES(size));
+       if (bo == NULL) {
+               gem_close(kgem->fd, args.handle);
+               return NULL;
+       }
+
+       bo->tiling = tiling.tiling_mode;
+       bo->reusable = false;
+
+       debug_alloc__bo(kgem, bo);
+       return bo;
+#else
+       return NULL;
+#endif
+}
+
+int kgem_bo_export_to_prime(struct kgem *kgem, struct kgem_bo *bo)
+{
+#ifdef DRM_IOCTL_PRIME_HANDLE_TO_FD
+       struct drm_prime_handle args;
+
+       VG_CLEAR(args);
+       args.handle = bo->handle;
+       args.flags = DRM_CLOEXEC;
+
+       if (drmIoctl(kgem->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &args))
+               return -1;
+
+       bo->reusable = false;
+       return args.fd;
+#else
+       return -1;
+#endif
+}
+
+struct kgem_bo *kgem_create_linear(struct kgem *kgem, int size, unsigned flags)
+{
+       struct kgem_bo *bo;
+       uint32_t handle;
+
+       DBG(("%s(%d)\n", __FUNCTION__, size));
+
+       if (flags & CREATE_GTT_MAP && kgem->has_llc) {
+               flags &= ~CREATE_GTT_MAP;
+               flags |= CREATE_CPU_MAP;
+       }
+
+       size = (size + PAGE_SIZE - 1) / PAGE_SIZE;
+       bo = search_linear_cache(kgem, size, CREATE_INACTIVE | flags);
+       if (bo) {
+               bo->refcnt = 1;
+               return bo;
+       }
+
+       handle = gem_create(kgem->fd, size);
+       if (handle == 0)
+               return NULL;
+
+       DBG(("%s: new handle=%d, num_pages=%d\n", __FUNCTION__, handle, size));
+       bo = __kgem_bo_alloc(handle, size);
+       if (bo == NULL) {
+               gem_close(kgem->fd, handle);
+               return NULL;
+       }
+
+       debug_alloc__bo(kgem, bo);
+       return bo;
+}
+
+int kgem_choose_tiling(struct kgem *kgem, int tiling, int width, int height, int bpp)
+{
+       if (DBG_NO_TILING)
+               return tiling < 0 ? tiling : I915_TILING_NONE;
+
+       if (kgem->gen < 40) {
+               if (tiling && width * bpp > 8192 * 8) {
+                       DBG(("%s: pitch too large for tliing [%d]\n",
+                            __FUNCTION__, width*bpp/8));
+                       tiling = I915_TILING_NONE;
+                       goto done;
+               }
+       } else {
+               if (width*bpp > (MAXSHORT-512) * 8) {
+                       DBG(("%s: large pitch [%d], forcing TILING_X\n",
+                            __FUNCTION__, width*bpp/8));
+                       if (tiling > 0)
+                               tiling = -tiling;
+                       else if (tiling == 0)
+                               tiling = -I915_TILING_X;
+               } else if (tiling && (width|height) > 8192) {
+                       DBG(("%s: large tiled buffer [%dx%d], forcing TILING_X\n",
+                            __FUNCTION__, width, height));
+                       tiling = -I915_TILING_X;
+               }
+       }
+
+       if (tiling < 0)
+               return tiling;
+
+       if (tiling && height == 1) {
+               DBG(("%s: disabling tiling [%d] for single row\n",
+                    __FUNCTION__,height));
+               tiling = I915_TILING_NONE;
+               goto done;
+       }
+       if (tiling == I915_TILING_Y && height <= 16) {
+               DBG(("%s: too short [%d] for TILING_Y\n",
+                    __FUNCTION__,height));
+               tiling = I915_TILING_X;
+       }
+       if (tiling && width * bpp > 8 * (4096 - 64)) {
+               DBG(("%s: TLB miss between lines %dx%d (pitch=%d), forcing tiling %d\n",
+                    __FUNCTION__,
+                    width, height, width*bpp/8,
+                    tiling));
+               return -tiling;
+       }
+       if (tiling == I915_TILING_X && height < 4) {
+               DBG(("%s: too short [%d] for TILING_X\n",
+                    __FUNCTION__, height));
+               tiling = I915_TILING_NONE;
+               goto done;
+       }
+
+       if (tiling == I915_TILING_X && width * bpp <= 8*512/2) {
+               DBG(("%s: too thin [width %d, %d bpp] for TILING_X\n",
+                    __FUNCTION__, width, bpp));
+               tiling = I915_TILING_NONE;
+               goto done;
+       }
+       if (tiling == I915_TILING_Y && width * bpp <= 8*128/2) {
+               DBG(("%s: too thin [%d] for TILING_Y\n",
+                    __FUNCTION__, width));
+               tiling = I915_TILING_NONE;
+               goto done;
+       }
+
+       if (tiling && ALIGN(height, 2) * ALIGN(width*bpp, 8*64) <= 4096 * 8) {
+               DBG(("%s: too small [%d bytes] for TILING_%c\n", __FUNCTION__,
+                    ALIGN(height, 2) * ALIGN(width*bpp, 8*64) / 8,
+                    tiling == I915_TILING_X ? 'X' : 'Y'));
+               tiling = I915_TILING_NONE;
+               goto done;
+       }
+
+       if (tiling && width * bpp >= 8 * 4096 / 2) {
+               DBG(("%s: TLB near-miss between lines %dx%d (pitch=%d), forcing tiling %d\n",
+                    __FUNCTION__,
+                    width, height, width*bpp/8,
+                    tiling));
+               return -tiling;
+       }
+
+done:
+       DBG(("%s: %dx%d -> %d\n", __FUNCTION__, width, height, tiling));
+       return tiling;
+}
+
+static int bits_per_pixel(int depth)
+{
+       switch (depth) {
+       case 8: return 8;
+       case 15:
+       case 16: return 16;
+       case 24:
+       case 30:
+       case 32: return 32;
+       default: return 0;
+       }
+}
+
+unsigned kgem_can_create_2d(struct kgem *kgem,
+                           int width, int height, int depth)
+{
+       uint32_t pitch, size;
+       unsigned flags = 0;
+       int bpp;
+
+       DBG(("%s: %dx%d @ %d\n", __FUNCTION__, width, height, depth));
+
+       bpp = bits_per_pixel(depth);
+       if (bpp == 0) {
+               DBG(("%s: unhandled depth %d\n", __FUNCTION__, depth));
+               return 0;
+       }
+
+       if (width > MAXSHORT || height > MAXSHORT) {
+               DBG(("%s: unhandled size %dx%d\n",
+                    __FUNCTION__, width, height));
+               return 0;
+       }
+
+       size = kgem_surface_size(kgem, false, 0,
+                                width, height, bpp,
+                                I915_TILING_NONE, &pitch);
+       if (size > 0 && size <= kgem->max_cpu_size)
+               flags |= KGEM_CAN_CREATE_CPU | KGEM_CAN_CREATE_GPU;
+       if (size > 0 && size <= kgem->aperture_mappable/4)
+               flags |= KGEM_CAN_CREATE_GTT;
+       if (size > kgem->large_object_size)
+               flags |= KGEM_CAN_CREATE_LARGE;
+       if (size > kgem->max_object_size) {
+               DBG(("%s: too large (untiled) %d > %d\n",
+                    __FUNCTION__, size, kgem->max_object_size));
+               return 0;
+       }
+
+       size = kgem_surface_size(kgem, false, 0,
+                                width, height, bpp,
+                                kgem_choose_tiling(kgem, I915_TILING_X,
+                                                   width, height, bpp),
+                                &pitch);
+       if (size > 0 && size <= kgem->max_gpu_size)
+               flags |= KGEM_CAN_CREATE_GPU;
+       if (size > 0 && size <= kgem->aperture_mappable/4)
+               flags |= KGEM_CAN_CREATE_GTT;
+       if (size > kgem->large_object_size)
+               flags |= KGEM_CAN_CREATE_LARGE;
+       if (size > kgem->max_object_size) {
+               DBG(("%s: too large (tiled) %d > %d\n",
+                    __FUNCTION__, size, kgem->max_object_size));
+               return 0;
+       }
+
+       return flags;
+}
+
+inline int kgem_bo_fenced_size(struct kgem *kgem, struct kgem_bo *bo)
+{
+       unsigned int size;
+
+       assert(bo->tiling);
+       assert(kgem->gen < 40);
+
+       if (kgem->gen < 30)
+               size = 512 * 1024;
+       else
+               size = 1024 * 1024;
+       while (size < bytes(bo))
+               size *= 2;
+
+       return size;
+}
+
+struct kgem_bo *kgem_create_2d(struct kgem *kgem,
+                              int width,
+                              int height,
+                              int bpp,
+                              int tiling,
+                              uint32_t flags)
+{
+       struct list *cache;
+       struct kgem_bo *bo;
+       uint32_t pitch, untiled_pitch, tiled_height, size;
+       uint32_t handle;
+       int i, bucket, retry;
+
+       if (tiling < 0)
+               tiling = -tiling, flags |= CREATE_EXACT;
+
+       DBG(("%s(%dx%d, bpp=%d, tiling=%d, exact=%d, inactive=%d, cpu-mapping=%d, gtt-mapping=%d, scanout?=%d, prime?=%d, temp?=%d)\n", __FUNCTION__,
+            width, height, bpp, tiling,
+            !!(flags & CREATE_EXACT),
+            !!(flags & CREATE_INACTIVE),
+            !!(flags & CREATE_CPU_MAP),
+            !!(flags & CREATE_GTT_MAP),
+            !!(flags & CREATE_SCANOUT),
+            !!(flags & CREATE_PRIME),
+            !!(flags & CREATE_TEMPORARY)));
+
+       size = kgem_surface_size(kgem, kgem->has_relaxed_fencing, flags,
+                                width, height, bpp, tiling, &pitch);
+       assert(size && size <= kgem->max_object_size);
+       size /= PAGE_SIZE;
+       bucket = cache_bucket(size);
+
+       if (bucket >= NUM_CACHE_BUCKETS) {
+               DBG(("%s: large bo num pages=%d, bucket=%d\n",
+                    __FUNCTION__, size, bucket));
+
+               if (flags & CREATE_INACTIVE)
+                       goto large_inactive;
+
+               tiled_height = kgem_aligned_height(kgem, height, tiling);
+               untiled_pitch = kgem_untiled_pitch(kgem, width, bpp, flags);
+
+               list_for_each_entry(bo, &kgem->large, list) {
+                       assert(!bo->purged);
+                       assert(bo->refcnt == 0);
+                       assert(bo->reusable);
+
+                       if (kgem->gen < 40) {
+                               if (bo->pitch < pitch) {
+                                       DBG(("tiled and pitch too small: tiling=%d, (want %d), pitch=%d, need %d\n",
+                                            bo->tiling, tiling,
+                                            bo->pitch, pitch));
+                                       continue;
+                               }
+
+                               if (bo->pitch * tiled_height > bytes(bo))
+                                       continue;
+                       } else {
+                               if (num_pages(bo) < size)
+                                       continue;
+
+                               if (bo->pitch != pitch || bo->tiling != tiling) {
+                                       if (gem_set_tiling(kgem->fd, bo->handle,
+                                                          tiling, pitch) != tiling)
+                                               continue;
+
+                                       bo->pitch = pitch;
+                               }
+                       }
+
+                       kgem_bo_remove_from_active(kgem, bo);
+
+                       bo->unique_id = kgem_get_unique_id(kgem);
+                       bo->delta = 0;
+                       DBG(("  1:from active: pitch=%d, tiling=%d, handle=%d, id=%d\n",
+                            bo->pitch, bo->tiling, bo->handle, bo->unique_id));
+                       assert(bo->pitch*kgem_aligned_height(kgem, height, bo->tiling) <= kgem_bo_size(bo));
+                       bo->refcnt = 1;
+                       return bo;
+               }
+
+large_inactive:
+               list_for_each_entry(bo, &kgem->large_inactive, list) {
+                       assert(bo->refcnt == 0);
+                       assert(bo->reusable);
+
+                       if (size > num_pages(bo))
+                               continue;
+
+                       if (bo->tiling != tiling ||
+                           (tiling != I915_TILING_NONE && bo->pitch != pitch)) {
+                               if (tiling != gem_set_tiling(kgem->fd,
+                                                            bo->handle,
+                                                            tiling, pitch))
+                                       continue;
+                       }
+
+                       if (bo->purged && !kgem_bo_clear_purgeable(kgem, bo)) {
+                               kgem_bo_free(kgem, bo);
+                               break;
+                       }
+
+                       list_del(&bo->list);
+
+                       bo->unique_id = kgem_get_unique_id(kgem);
+                       bo->pitch = pitch;
+                       bo->delta = 0;
+                       DBG(("  1:from large inactive: pitch=%d, tiling=%d, handle=%d, id=%d\n",
+                            bo->pitch, bo->tiling, bo->handle, bo->unique_id));
+                       assert(bo->pitch*kgem_aligned_height(kgem, height, bo->tiling) <= kgem_bo_size(bo));
+                       bo->refcnt = 1;
+                       return bo;
+               }
+
+               goto create;
+       }
+
+       if (flags & (CREATE_CPU_MAP | CREATE_GTT_MAP)) {
+               int for_cpu = !!(flags & CREATE_CPU_MAP);
+               if (kgem->has_llc && tiling == I915_TILING_NONE)
+                       for_cpu = 1;
+               /* We presume that we will need to upload to this bo,
+                * and so would prefer to have an active VMA.
+                */
+               cache = &kgem->vma[for_cpu].inactive[bucket];
+               do {
+                       list_for_each_entry(bo, cache, vma) {
+                               assert(bucket(bo) == bucket);
+                               assert(bo->refcnt == 0);
+                               assert(bo->map);
+                               assert(IS_CPU_MAP(bo->map) == for_cpu);
+                               assert(bo->rq == NULL);
+                               assert(list_is_empty(&bo->request));
+
+                               if (size > num_pages(bo)) {
+                                       DBG(("inactive too small: %d < %d\n",
+                                            num_pages(bo), size));
+                                       continue;
+                               }
+
+                               if (bo->tiling != tiling ||
+                                   (tiling != I915_TILING_NONE && bo->pitch != pitch)) {
+                                       DBG(("inactive vma with wrong tiling: %d < %d\n",
+                                            bo->tiling, tiling));
+                                       continue;
+                               }
+
+                               if (bo->purged && !kgem_bo_clear_purgeable(kgem, bo)) {
+                                       kgem_bo_free(kgem, bo);
+                                       break;
+                               }
+
+                               bo->pitch = pitch;
+                               bo->delta = 0;
+                               bo->unique_id = kgem_get_unique_id(kgem);
+
+                               kgem_bo_remove_from_inactive(kgem, bo);
+
+                               DBG(("  from inactive vma: pitch=%d, tiling=%d: handle=%d, id=%d\n",
+                                    bo->pitch, bo->tiling, bo->handle, bo->unique_id));
+                               assert(bo->reusable);
+                               assert(bo->domain != DOMAIN_GPU && !kgem_busy(kgem, bo->handle));
+                               assert(bo->pitch*kgem_aligned_height(kgem, height, bo->tiling) <= kgem_bo_size(bo));
+                               bo->refcnt = 1;
+                               return bo;
+                       }
+               } while (!list_is_empty(cache) &&
+                        __kgem_throttle_retire(kgem, flags));
+       }
+
+       if (flags & CREATE_INACTIVE)
+               goto skip_active_search;
+
+       /* Best active match */
+       retry = NUM_CACHE_BUCKETS - bucket;
+       if (retry > 3 && (flags & CREATE_TEMPORARY) == 0)
+               retry = 3;
+search_again:
+       assert(bucket < NUM_CACHE_BUCKETS);
+       cache = &kgem->active[bucket][tiling];
+       if (tiling) {
+               tiled_height = kgem_aligned_height(kgem, height, tiling);
+               list_for_each_entry(bo, cache, list) {
+                       assert(!bo->purged);
+                       assert(bo->refcnt == 0);
+                       assert(bucket(bo) == bucket);
+                       assert(bo->reusable);
+                       assert(bo->tiling == tiling);
+
+                       if (kgem->gen < 40) {
+                               if (bo->pitch < pitch) {
+                                       DBG(("tiled and pitch too small: tiling=%d, (want %d), pitch=%d, need %d\n",
+                                            bo->tiling, tiling,
+                                            bo->pitch, pitch));
+                                       continue;
+                               }
+
+                               if (bo->pitch * tiled_height > bytes(bo))
+                                       continue;
+                       } else {
+                               if (num_pages(bo) < size)
+                                       continue;
+
+                               if (bo->pitch != pitch) {
+                                       gem_set_tiling(kgem->fd,
+                                                      bo->handle,
+                                                      tiling, pitch);
+
+                                       bo->pitch = pitch;
+                               }
+                       }
+
+                       kgem_bo_remove_from_active(kgem, bo);
+
+                       bo->unique_id = kgem_get_unique_id(kgem);
+                       bo->delta = 0;
+                       DBG(("  1:from active: pitch=%d, tiling=%d, handle=%d, id=%d\n",
+                            bo->pitch, bo->tiling, bo->handle, bo->unique_id));
+                       assert(bo->pitch*kgem_aligned_height(kgem, height, bo->tiling) <= kgem_bo_size(bo));
+                       bo->refcnt = 1;
+                       return bo;
+               }
+       } else {
+               list_for_each_entry(bo, cache, list) {
+                       assert(bucket(bo) == bucket);
+                       assert(!bo->purged);
+                       assert(bo->refcnt == 0);
+                       assert(bo->reusable);
+                       assert(bo->tiling == tiling);
+
+                       if (num_pages(bo) < size)
+                               continue;
+
+                       kgem_bo_remove_from_active(kgem, bo);
+
+                       bo->pitch = pitch;
+                       bo->unique_id = kgem_get_unique_id(kgem);
+                       bo->delta = 0;
+                       DBG(("  1:from active: pitch=%d, tiling=%d, handle=%d, id=%d\n",
+                            bo->pitch, bo->tiling, bo->handle, bo->unique_id));
+                       assert(bo->pitch*kgem_aligned_height(kgem, height, bo->tiling) <= kgem_bo_size(bo));
+                       bo->refcnt = 1;
+                       return bo;
+               }
+       }
+
+       if (--retry && flags & CREATE_EXACT) {
+               if (kgem->gen >= 40) {
+                       for (i = I915_TILING_NONE; i <= I915_TILING_Y; i++) {
+                               if (i == tiling)
+                                       continue;
+
+                               cache = &kgem->active[bucket][i];
+                               list_for_each_entry(bo, cache, list) {
+                                       assert(!bo->purged);
+                                       assert(bo->refcnt == 0);
+                                       assert(bo->reusable);
+
+                                       if (num_pages(bo) < size)
+                                               continue;
+
+                                       if (tiling != gem_set_tiling(kgem->fd,
+                                                                    bo->handle,
+                                                                    tiling, pitch))
+                                               continue;
+
+                                       kgem_bo_remove_from_active(kgem, bo);
+
+                                       bo->unique_id = kgem_get_unique_id(kgem);
+                                       bo->pitch = pitch;
+                                       bo->tiling = tiling;
+                                       bo->delta = 0;
+                                       DBG(("  1:from active: pitch=%d, tiling=%d, handle=%d, id=%d\n",
+                                            bo->pitch, bo->tiling, bo->handle, bo->unique_id));
+                                       assert(bo->pitch*kgem_aligned_height(kgem, height, bo->tiling) <= kgem_bo_size(bo));
+                                       bo->refcnt = 1;
+                                       return bo;
+                               }
+                       }
+               }
+
+               bucket++;
+               goto search_again;
+       }
+
+       if ((flags & CREATE_EXACT) == 0) { /* allow an active near-miss? */
+               untiled_pitch = kgem_untiled_pitch(kgem, width, bpp, flags);
+               i = tiling;
+               while (--i >= 0) {
+                       tiled_height = kgem_surface_size(kgem, kgem->has_relaxed_fencing, flags,
+                                                        width, height, bpp, tiling, &pitch);
+                       cache = active(kgem, tiled_height / PAGE_SIZE, i);
+                       tiled_height = kgem_aligned_height(kgem, height, i);
+                       list_for_each_entry(bo, cache, list) {
+                               assert(!bo->purged);
+                               assert(bo->refcnt == 0);
+                               assert(bo->reusable);
+
+                               if (bo->tiling) {
+                                       if (bo->pitch < pitch) {
+                                               DBG(("tiled and pitch too small: tiling=%d, (want %d), pitch=%d, need %d\n",
+                                                    bo->tiling, tiling,
+                                                    bo->pitch, pitch));
+                                               continue;
+                                       }
+                               } else
+                                       bo->pitch = untiled_pitch;
+
+                               if (bo->pitch * tiled_height > bytes(bo))
+                                       continue;
+
+                               kgem_bo_remove_from_active(kgem, bo);
+
+                               bo->unique_id = kgem_get_unique_id(kgem);
+                               bo->delta = 0;
+                               DBG(("  1:from active: pitch=%d, tiling=%d, handle=%d, id=%d\n",
+                                    bo->pitch, bo->tiling, bo->handle, bo->unique_id));
+                               assert(bo->pitch*kgem_aligned_height(kgem, height, bo->tiling) <= kgem_bo_size(bo));
+                               bo->refcnt = 1;
+                               return bo;
+                       }
+               }
+       }
+
+skip_active_search:
+       bucket = cache_bucket(size);
+       retry = NUM_CACHE_BUCKETS - bucket;
+       if (retry > 3)
+               retry = 3;
+search_inactive:
+       /* Now just look for a close match and prefer any currently active */
+       assert(bucket < NUM_CACHE_BUCKETS);
+       cache = &kgem->inactive[bucket];
+       list_for_each_entry(bo, cache, list) {
+               assert(bucket(bo) == bucket);
+               assert(bo->reusable);
+
+               if (size > num_pages(bo)) {
+                       DBG(("inactive too small: %d < %d\n",
+                            num_pages(bo), size));
+                       continue;
+               }
+
+               if (bo->tiling != tiling ||
+                   (tiling != I915_TILING_NONE && bo->pitch != pitch)) {
+                       if (tiling != gem_set_tiling(kgem->fd,
+                                                    bo->handle,
+                                                    tiling, pitch))
+                               continue;
+
+                       if (bo->map)
+                               kgem_bo_release_map(kgem, bo);
+               }
+
+               if (bo->purged && !kgem_bo_clear_purgeable(kgem, bo)) {
+                       kgem_bo_free(kgem, bo);
+                       break;
+               }
+
+               kgem_bo_remove_from_inactive(kgem, bo);
+
+               bo->pitch = pitch;
+               bo->tiling = tiling;
+
+               bo->delta = 0;
+               bo->unique_id = kgem_get_unique_id(kgem);
+               assert(bo->pitch);
+               DBG(("  from inactive: pitch=%d, tiling=%d: handle=%d, id=%d\n",
+                    bo->pitch, bo->tiling, bo->handle, bo->unique_id));
+               assert(bo->refcnt == 0);
+               assert(bo->reusable);
+               assert((flags & CREATE_INACTIVE) == 0 || bo->domain != DOMAIN_GPU);
+               assert((flags & CREATE_INACTIVE) == 0 || !kgem_busy(kgem, bo->handle));
+               assert(bo->pitch*kgem_aligned_height(kgem, height, bo->tiling) <= kgem_bo_size(bo));
+               bo->refcnt = 1;
+               return bo;
+       }
+
+       if (flags & CREATE_INACTIVE &&
+           !list_is_empty(&kgem->active[bucket][tiling]) &&
+           __kgem_throttle_retire(kgem, flags)) {
+               flags &= ~CREATE_INACTIVE;
+               goto search_inactive;
+       }
+
+       if (--retry) {
+               bucket++;
+               flags &= ~CREATE_INACTIVE;
+               goto search_inactive;
+       }
+
+create:
+       if (bucket >= NUM_CACHE_BUCKETS)
+               size = ALIGN(size, 1024);
+       handle = gem_create(kgem->fd, size);
+       if (handle == 0)
+               return NULL;
+
+       bo = __kgem_bo_alloc(handle, size);
+       if (!bo) {
+               gem_close(kgem->fd, handle);
+               return NULL;
+       }
+
+       bo->domain = DOMAIN_CPU;
+       bo->unique_id = kgem_get_unique_id(kgem);
+       bo->pitch = pitch;
+       if (tiling != I915_TILING_NONE)
+               bo->tiling = gem_set_tiling(kgem->fd, handle, tiling, pitch);
+       if (bucket >= NUM_CACHE_BUCKETS) {
+               DBG(("%s: marking large bo for automatic flushing\n",
+                    __FUNCTION__));
+               bo->flush = true;
+       }
+
+       assert(bytes(bo) >= bo->pitch * kgem_aligned_height(kgem, height, bo->tiling));
+
+       debug_alloc__bo(kgem, bo);
+
+       DBG(("  new pitch=%d, tiling=%d, handle=%d, id=%d, num_pages=%d [%d], bucket=%d\n",
+            bo->pitch, bo->tiling, bo->handle, bo->unique_id,
+            size, num_pages(bo), bucket(bo)));
+       return bo;
+}
+
+struct kgem_bo *kgem_create_cpu_2d(struct kgem *kgem,
+                                  int width,
+                                  int height,
+                                  int bpp,
+                                  uint32_t flags)
+{
+       struct kgem_bo *bo;
+       int stride, size;
+
+       if (DBG_NO_CPU)
+               return NULL;
+
+       DBG(("%s(%dx%d, bpp=%d)\n", __FUNCTION__, width, height, bpp));
+
+       if (kgem->has_llc) {
+               bo = kgem_create_2d(kgem, width, height, bpp,
+                                   I915_TILING_NONE, flags);
+               if (bo == NULL)
+                       return bo;
+
+               assert(bo->tiling == I915_TILING_NONE);
+
+               if (kgem_bo_map__cpu(kgem, bo) == NULL) {
+                       kgem_bo_destroy(kgem, bo);
+                       return NULL;
+               }
+
+               return bo;
+       }
+
+       assert(width > 0 && height > 0);
+       stride = ALIGN(width, 2) * bpp >> 3;
+       stride = ALIGN(stride, 4);
+       size = stride * ALIGN(height, 2);
+       assert(size >= PAGE_SIZE);
+
+       DBG(("%s: %dx%d, %d bpp, stride=%d\n",
+            __FUNCTION__, width, height, bpp, stride));
+
+       bo = search_snoop_cache(kgem, NUM_PAGES(size), 0);
+       if (bo) {
+               assert(bo->tiling == I915_TILING_NONE);
+               assert(bo->snoop);
+               bo->refcnt = 1;
+               bo->pitch = stride;
+               bo->unique_id = kgem_get_unique_id(kgem);
+               return bo;
+       }
+
+       if (kgem->has_cacheing) {
+               bo = kgem_create_linear(kgem, size, flags);
+               if (bo == NULL)
+                       return NULL;
+
+               assert(bo->tiling == I915_TILING_NONE);
+
+               if (!gem_set_cacheing(kgem->fd, bo->handle, SNOOPED)) {
+                       kgem_bo_destroy(kgem, bo);
+                       return NULL;
+               }
+               bo->snoop = true;
+
+               if (kgem_bo_map__cpu(kgem, bo) == NULL) {
+                       kgem_bo_destroy(kgem, bo);
+                       return NULL;
+               }
+
+               bo->pitch = stride;
+               bo->unique_id = kgem_get_unique_id(kgem);
+               return bo;
+       }
+
+       if (kgem->has_userptr) {
+               void *ptr;
+
+               /* XXX */
+               //if (posix_memalign(&ptr, 64, ALIGN(size, 64)))
+               if (posix_memalign(&ptr, PAGE_SIZE, ALIGN(size, PAGE_SIZE)))
+                       return NULL;
+
+               bo = kgem_create_map(kgem, ptr, size, false);
+               if (bo == NULL) {
+                       free(ptr);
+                       return NULL;
+               }
+
+               bo->map = MAKE_USER_MAP(ptr);
+               bo->pitch = stride;
+               bo->unique_id = kgem_get_unique_id(kgem);
+               return bo;
+       }
+
+       return NULL;
+}
+
+void _kgem_bo_destroy(struct kgem *kgem, struct kgem_bo *bo)
+{
+       DBG(("%s: handle=%d, proxy? %d\n",
+            __FUNCTION__, bo->handle, bo->proxy != NULL));
+
+       if (bo->proxy) {
+               _list_del(&bo->vma);
+               _list_del(&bo->request);
+               if (bo->io && bo->exec == NULL)
+                       _kgem_bo_delete_buffer(kgem, bo);
+               kgem_bo_unref(kgem, bo->proxy);
+               kgem_bo_binding_free(kgem, bo);
+               free(bo);
+               return;
+       }
+
+       __kgem_bo_destroy(kgem, bo);
+}
+
+bool __kgem_flush(struct kgem *kgem, struct kgem_bo *bo)
+{
+       /* The kernel will emit a flush *and* update its own flushing lists. */
+       if (!bo->needs_flush)
+               return false;
+
+       bo->needs_flush = kgem_busy(kgem, bo->handle);
+       DBG(("%s: handle=%d, busy?=%d\n",
+            __FUNCTION__, bo->handle, bo->needs_flush));
+       return bo->needs_flush;
+}
+
+bool kgem_check_bo(struct kgem *kgem, ...)
+{
+       va_list ap;
+       struct kgem_bo *bo;
+       int num_exec = 0;
+       int num_pages = 0;
+
+       if (kgem_flush(kgem))
+               return false;
+
+       va_start(ap, kgem);
+       while ((bo = va_arg(ap, struct kgem_bo *))) {
+               if (bo->exec)
+                       continue;
+
+               while (bo->proxy) {
+                       bo = bo->proxy;
+                       if (bo->exec)
+                               continue;
+               }
+               num_pages += num_pages(bo);
+               num_exec++;
+       }
+       va_end(ap);
+
+       DBG(("%s: num_pages=+%d, num_exec=+%d\n",
+            __FUNCTION__, num_pages, num_exec));
+
+       if (!num_pages)
+               return true;
+
+       if (kgem->aperture > kgem->aperture_low && kgem_is_idle(kgem)) {
+               DBG(("%s: current aperture usage (%d) is greater than low water mark (%d)\n",
+                    __FUNCTION__, kgem->aperture, kgem->aperture_low));
+               return false;
+       }
+
+       if (num_pages + kgem->aperture > kgem->aperture_high) {
+               DBG(("%s: final aperture usage (%d) is greater than high water mark (%d)\n",
+                    __FUNCTION__, num_pages + kgem->aperture, kgem->aperture_high));
+               return false;
+       }
+
+       if (kgem->nexec + num_exec >= KGEM_EXEC_SIZE(kgem)) {
+               DBG(("%s: out of exec slots (%d + %d / %d)\n", __FUNCTION__,
+                    kgem->nexec, num_exec, KGEM_EXEC_SIZE(kgem)));
+               return false;
+       }
+
+       return true;
+}
+
+bool kgem_check_bo_fenced(struct kgem *kgem, struct kgem_bo *bo)
+{
+       uint32_t size;
+
+       if (kgem_flush(kgem))
+               return false;
+
+       while (bo->proxy)
+               bo = bo->proxy;
+       if (bo->exec) {
+               if (kgem->gen < 40 &&
+                   bo->tiling != I915_TILING_NONE &&
+                   (bo->exec->flags & EXEC_OBJECT_NEEDS_FENCE) == 0) {
+                       if (kgem->nfence >= kgem->fence_max)
+                               return false;
+
+                       size = kgem->aperture_fenced;
+                       size += kgem_bo_fenced_size(kgem, bo);
+                       if (size > kgem->aperture_mappable)
+                               return false;
+               }
+
+               return true;
+       }
+
+       if (kgem->aperture > kgem->aperture_low)
+               return false;
+
+       if (kgem->nexec >= KGEM_EXEC_SIZE(kgem) - 1)
+               return false;
+
+       if (kgem->gen < 40 &&
+           bo->tiling != I915_TILING_NONE &&
+           kgem->nfence >= kgem->fence_max)
+               return false;
+
+       size = kgem->aperture;
+       size += num_pages(bo);
+       return size <= kgem->aperture_high;
+}
+
+bool kgem_check_many_bo_fenced(struct kgem *kgem, ...)
+{
+       va_list ap;
+       struct kgem_bo *bo;
+       int num_fence = 0;
+       int num_exec = 0;
+       int num_pages = 0;
+       int fenced_size = 0;
+
+       if (kgem_flush(kgem))
+               return false;
+
+       va_start(ap, kgem);
+       while ((bo = va_arg(ap, struct kgem_bo *))) {
+               while (bo->proxy)
+                       bo = bo->proxy;
+               if (bo->exec) {
+                       if (kgem->gen >= 40 || bo->tiling == I915_TILING_NONE)
+                               continue;
+
+                       if ((bo->exec->flags & EXEC_OBJECT_NEEDS_FENCE) == 0) {
+                               fenced_size += kgem_bo_fenced_size(kgem, bo);
+                               num_fence++;
+                       }
+
+                       continue;
+               }
+
+               num_pages += num_pages(bo);
+               num_exec++;
+               if (kgem->gen < 40 && bo->tiling) {
+                       fenced_size += kgem_bo_fenced_size(kgem, bo);
+                       num_fence++;
+               }
+       }
+       va_end(ap);
+
+       if (fenced_size + kgem->aperture_fenced > kgem->aperture_mappable)
+               return false;
+
+       if (kgem->nfence + num_fence > kgem->fence_max)
+               return false;
+
+       if (!num_pages)
+               return true;
+
+       if (kgem->aperture > kgem->aperture_low)
+               return false;
+
+       if (num_pages + kgem->aperture > kgem->aperture_high)
+               return false;
+
+       if (kgem->nexec + num_exec >= KGEM_EXEC_SIZE(kgem))
+               return false;
+
+       return true;
+}
+
+uint32_t kgem_add_reloc(struct kgem *kgem,
+                       uint32_t pos,
+                       struct kgem_bo *bo,
+                       uint32_t read_write_domain,
+                       uint32_t delta)
+{
+       int index;
+
+       DBG(("%s: handle=%d, pos=%d, delta=%d, domains=%08x\n",
+            __FUNCTION__, bo ? bo->handle : 0, pos, delta, read_write_domain));
+
+       assert((read_write_domain & 0x7fff) == 0 || bo != NULL);
+
+       index = kgem->nreloc++;
+       assert(index < ARRAY_SIZE(kgem->reloc));
+       kgem->reloc[index].offset = pos * sizeof(kgem->batch[0]);
+       if (bo) {
+               assert(bo->refcnt);
+               assert(!bo->purged);
+
+               while (bo->proxy) {
+                       DBG(("%s: adding proxy [delta=%d] for handle=%d\n",
+                            __FUNCTION__, bo->delta, bo->handle));
+                       delta += bo->delta;
+                       assert(bo->handle == bo->proxy->handle);
+                       /* need to release the cache upon batch submit */
+                       if (bo->exec == NULL) {
+                               list_move_tail(&bo->request,
+                                              &kgem->next_request->buffers);
+                               bo->rq = kgem->next_request;
+                               bo->exec = &_kgem_dummy_exec;
+                       }
+
+                       bo = bo->proxy;
+                       assert(bo->refcnt);
+                       assert(!bo->purged);
+               }
+
+               if (bo->exec == NULL)
+                       _kgem_add_bo(kgem, bo);
+               assert(bo->rq == kgem->next_request);
+
+               if (kgem->gen < 40 && read_write_domain & KGEM_RELOC_FENCED) {
+                       if (bo->tiling &&
+                           (bo->exec->flags & EXEC_OBJECT_NEEDS_FENCE) == 0) {
+                               assert(kgem->nfence < kgem->fence_max);
+                               kgem->aperture_fenced +=
+                                       kgem_bo_fenced_size(kgem, bo);
+                               kgem->nfence++;
+                       }
+                       bo->exec->flags |= EXEC_OBJECT_NEEDS_FENCE;
+               }
+
+               kgem->reloc[index].delta = delta;
+               kgem->reloc[index].target_handle = bo->handle;
+               kgem->reloc[index].presumed_offset = bo->presumed_offset;
+
+               if (read_write_domain & 0x7ff)
+                       kgem_bo_mark_dirty(bo);
+
+               delta += bo->presumed_offset;
+       } else {
+               kgem->reloc[index].delta = delta;
+               kgem->reloc[index].target_handle = 0;
+               kgem->reloc[index].presumed_offset = 0;
+       }
+       kgem->reloc[index].read_domains = read_write_domain >> 16;
+       kgem->reloc[index].write_domain = read_write_domain & 0x7fff;
+
+       return delta;
+}
+
+static void kgem_trim_vma_cache(struct kgem *kgem, int type, int bucket)
+{
+       int i, j;
+
+       DBG(("%s: type=%d, count=%d (bucket: %d)\n",
+            __FUNCTION__, type, kgem->vma[type].count, bucket));
+       if (kgem->vma[type].count <= 0)
+              return;
+
+       if (kgem->need_purge)
+               kgem_purge_cache(kgem);
+
+       /* vma are limited on a per-process basis to around 64k.
+        * This includes all malloc arenas as well as other file
+        * mappings. In order to be fair and not hog the cache,
+        * and more importantly not to exhaust that limit and to
+        * start failing mappings, we keep our own number of open
+        * vma to within a conservative value.
+        */
+       i = 0;
+       while (kgem->vma[type].count > 0) {
+               struct kgem_bo *bo = NULL;
+
+               for (j = 0;
+                    bo == NULL && j < ARRAY_SIZE(kgem->vma[type].inactive);
+                    j++) {
+                       struct list *head = &kgem->vma[type].inactive[i++%ARRAY_SIZE(kgem->vma[type].inactive)];
+                       if (!list_is_empty(head))
+                               bo = list_last_entry(head, struct kgem_bo, vma);
+               }
+               if (bo == NULL)
+                       break;
+
+               DBG(("%s: discarding inactive %s vma cache for %d\n",
+                    __FUNCTION__,
+                    IS_CPU_MAP(bo->map) ? "CPU" : "GTT", bo->handle));
+               assert(IS_CPU_MAP(bo->map) == type);
+               assert(bo->map);
+               assert(bo->rq == NULL);
+
+               VG(if (type) VALGRIND_MAKE_MEM_NOACCESS(MAP(bo->map), bytes(bo)));
+               munmap(MAP(bo->map), bytes(bo));
+               bo->map = NULL;
+               list_del(&bo->vma);
+               kgem->vma[type].count--;
+
+               if (!bo->purged && !kgem_bo_set_purgeable(kgem, bo)) {
+                       DBG(("%s: freeing unpurgeable old mapping\n",
+                            __FUNCTION__));
+                       kgem_bo_free(kgem, bo);
+               }
+       }
+}
+
+void *kgem_bo_map__async(struct kgem *kgem, struct kgem_bo *bo)
+{
+       void *ptr;
+
+       DBG(("%s: handle=%d, offset=%d, tiling=%d, map=%p, domain=%d\n", __FUNCTION__,
+            bo->handle, bo->presumed_offset, bo->tiling, bo->map, bo->domain));
+
+       assert(!bo->purged);
+       assert(bo->proxy == NULL);
+       assert(list_is_empty(&bo->list));
+
+       if (bo->tiling == I915_TILING_NONE && !bo->scanout && kgem->has_llc) {
+               DBG(("%s: converting request for GTT map into CPU map\n",
+                    __FUNCTION__));
+               return kgem_bo_map__cpu(kgem, bo);
+       }
+
+       if (IS_CPU_MAP(bo->map))
+               kgem_bo_release_map(kgem, bo);
+
+       ptr = bo->map;
+       if (ptr == NULL) {
+               assert(kgem_bo_size(bo) <= kgem->aperture_mappable / 2);
+
+               kgem_trim_vma_cache(kgem, MAP_GTT, bucket(bo));
+
+               ptr = __kgem_bo_map__gtt(kgem, bo);
+               if (ptr == NULL)
+                       return NULL;
+
+               /* Cache this mapping to avoid the overhead of an
+                * excruciatingly slow GTT pagefault. This is more an
+                * issue with compositing managers which need to frequently
+                * flush CPU damage to their GPU bo.
+                */
+               bo->map = ptr;
+               DBG(("%s: caching GTT vma for %d\n", __FUNCTION__, bo->handle));
+       }
+
+       return ptr;
+}
+
+void *kgem_bo_map(struct kgem *kgem, struct kgem_bo *bo)
+{
+       void *ptr;
+
+       DBG(("%s: handle=%d, offset=%d, tiling=%d, map=%p, domain=%d\n", __FUNCTION__,
+            bo->handle, bo->presumed_offset, bo->tiling, bo->map, bo->domain));
+
+       assert(!bo->purged);
+       assert(bo->proxy == NULL);
+       assert(list_is_empty(&bo->list));
+       assert(bo->exec == NULL);
+
+       if (bo->tiling == I915_TILING_NONE && !bo->scanout &&
+           (kgem->has_llc || bo->domain == DOMAIN_CPU)) {
+               DBG(("%s: converting request for GTT map into CPU map\n",
+                    __FUNCTION__));
+               ptr = kgem_bo_map__cpu(kgem, bo);
+               kgem_bo_sync__cpu(kgem, bo);
+               return ptr;
+       }
+
+       if (IS_CPU_MAP(bo->map))
+               kgem_bo_release_map(kgem, bo);
+
+       ptr = bo->map;
+       if (ptr == NULL) {
+               assert(kgem_bo_size(bo) <= kgem->aperture_mappable / 2);
+
+               kgem_trim_vma_cache(kgem, MAP_GTT, bucket(bo));
+
+               ptr = __kgem_bo_map__gtt(kgem, bo);
+               if (ptr == NULL)
+                       return NULL;
+
+               /* Cache this mapping to avoid the overhead of an
+                * excruciatingly slow GTT pagefault. This is more an
+                * issue with compositing managers which need to frequently
+                * flush CPU damage to their GPU bo.
+                */
+               bo->map = ptr;
+               DBG(("%s: caching GTT vma for %d\n", __FUNCTION__, bo->handle));
+       }
+
+       if (bo->domain != DOMAIN_GTT) {
+               struct drm_i915_gem_set_domain set_domain;
+
+               DBG(("%s: sync: needs_flush? %d, domain? %d, busy? %d\n", __FUNCTION__,
+                    bo->needs_flush, bo->domain, kgem_busy(kgem, bo->handle)));
+
+               /* XXX use PROT_READ to avoid the write flush? */
+
+               VG_CLEAR(set_domain);
+               set_domain.handle = bo->handle;
+               set_domain.read_domains = I915_GEM_DOMAIN_GTT;
+               set_domain.write_domain = I915_GEM_DOMAIN_GTT;
+               if (drmIoctl(kgem->fd, DRM_IOCTL_I915_GEM_SET_DOMAIN, &set_domain) == 0) {
+                       kgem_bo_retire(kgem, bo);
+                       bo->domain = DOMAIN_GTT;
+               }
+       }
+
+       return ptr;
+}
+
+void *kgem_bo_map__gtt(struct kgem *kgem, struct kgem_bo *bo)
+{
+       void *ptr;
+
+       DBG(("%s: handle=%d, offset=%d, tiling=%d, map=%p, domain=%d\n", __FUNCTION__,
+            bo->handle, bo->presumed_offset, bo->tiling, bo->map, bo->domain));
+
+       assert(!bo->purged);
+       assert(bo->exec == NULL);
+       assert(list_is_empty(&bo->list));
+
+       if (IS_CPU_MAP(bo->map))
+               kgem_bo_release_map(kgem, bo);
+
+       ptr = bo->map;
+       if (ptr == NULL) {
+               assert(bytes(bo) <= kgem->aperture_mappable / 4);
+
+               kgem_trim_vma_cache(kgem, MAP_GTT, bucket(bo));
+
+               ptr = __kgem_bo_map__gtt(kgem, bo);
+               if (ptr == NULL)
+                       return NULL;
+
+               /* Cache this mapping to avoid the overhead of an
+                * excruciatingly slow GTT pagefault. This is more an
+                * issue with compositing managers which need to frequently
+                * flush CPU damage to their GPU bo.
+                */
+               bo->map = ptr;
+               DBG(("%s: caching GTT vma for %d\n", __FUNCTION__, bo->handle));
+       }
+
+       return ptr;
+}
+
+void *kgem_bo_map__debug(struct kgem *kgem, struct kgem_bo *bo)
+{
+       if (bo->map)
+               return MAP(bo->map);
+
+       kgem_trim_vma_cache(kgem, MAP_GTT, bucket(bo));
+       return bo->map = __kgem_bo_map__gtt(kgem, bo);
+}
+
+void *kgem_bo_map__cpu(struct kgem *kgem, struct kgem_bo *bo)
+{
+       struct drm_i915_gem_mmap mmap_arg;
+
+       DBG(("%s(handle=%d, size=%d, mapped? %d)\n",
+            __FUNCTION__, bo->handle, bytes(bo), (int)__MAP_TYPE(bo->map)));
+       assert(!bo->purged);
+       assert(list_is_empty(&bo->list));
+       assert(!bo->scanout);
+       assert(bo->proxy == NULL);
+
+       if (IS_CPU_MAP(bo->map))
+               return MAP(bo->map);
+
+       if (bo->map)
+               kgem_bo_release_map(kgem, bo);
+
+       kgem_trim_vma_cache(kgem, MAP_CPU, bucket(bo));
+
+retry:
+       VG_CLEAR(mmap_arg);
+       mmap_arg.handle = bo->handle;
+       mmap_arg.offset = 0;
+       mmap_arg.size = bytes(bo);
+       if (drmIoctl(kgem->fd, DRM_IOCTL_I915_GEM_MMAP, &mmap_arg)) {
+               ErrorF("%s: failed to mmap %d, %d bytes, into CPU domain: %d\n",
+                      __FUNCTION__, bo->handle, bytes(bo), errno);
+               if (__kgem_throttle_retire(kgem, 0))
+                       goto retry;
+
+               return NULL;
+       }
+
+       VG(VALGRIND_MAKE_MEM_DEFINED(mmap_arg.addr_ptr, bytes(bo)));
+
+       DBG(("%s: caching CPU vma for %d\n", __FUNCTION__, bo->handle));
+       bo->map = MAKE_CPU_MAP(mmap_arg.addr_ptr);
+       return (void *)(uintptr_t)mmap_arg.addr_ptr;
+}
+
+void *__kgem_bo_map__cpu(struct kgem *kgem, struct kgem_bo *bo)
+{
+       struct drm_i915_gem_mmap mmap_arg;
+
+       DBG(("%s(handle=%d, size=%d, mapped? %d)\n",
+            __FUNCTION__, bo->handle, bytes(bo), (int)__MAP_TYPE(bo->map)));
+        assert(bo->refcnt);
+       assert(!bo->purged);
+       assert(list_is_empty(&bo->list));
+       assert(bo->proxy == NULL);
+
+       if (IS_CPU_MAP(bo->map))
+               return MAP(bo->map);
+
+retry:
+       VG_CLEAR(mmap_arg);
+       mmap_arg.handle = bo->handle;
+       mmap_arg.offset = 0;
+       mmap_arg.size = bytes(bo);
+       if (drmIoctl(kgem->fd, DRM_IOCTL_I915_GEM_MMAP, &mmap_arg)) {
+               ErrorF("%s: failed to mmap %d, %d bytes, into CPU domain: %d\n",
+                      __FUNCTION__, bo->handle, bytes(bo), errno);
+               if (__kgem_throttle_retire(kgem, 0))
+                       goto retry;
+
+               return NULL;
+       }
+
+       VG(VALGRIND_MAKE_MEM_DEFINED(mmap_arg.addr_ptr, bytes(bo)));
+       if (bo->map == NULL) {
+               DBG(("%s: caching CPU vma for %d\n", __FUNCTION__, bo->handle));
+               bo->map = MAKE_CPU_MAP(mmap_arg.addr_ptr);
+       }
+       return (void *)(uintptr_t)mmap_arg.addr_ptr;
+}
+
+void __kgem_bo_unmap__cpu(struct kgem *kgem, struct kgem_bo *bo, void *ptr)
+{
+       DBG(("%s(handle=%d, size=%d)\n",
+            __FUNCTION__, bo->handle, bytes(bo)));
+        assert(bo->refcnt);
+
+       if (IS_CPU_MAP(bo->map)) {
+                assert(ptr == MAP(bo->map));
+                return;
+        }
+
+       munmap(ptr, bytes(bo));
+}
+
+uint32_t kgem_bo_flink(struct kgem *kgem, struct kgem_bo *bo)
+{
+       struct drm_gem_flink flink;
+
+       VG_CLEAR(flink);
+       flink.handle = bo->handle;
+       if (drmIoctl(kgem->fd, DRM_IOCTL_GEM_FLINK, &flink))
+               return 0;
+
+       DBG(("%s: flinked handle=%d to name=%d, marking non-reusable\n",
+            __FUNCTION__, flink.handle, flink.name));
+
+       /* Ordinarily giving the name aware makes the buffer non-reusable.
+        * However, we track the lifetime of all clients and their hold
+        * on the buffer, and *presuming* they do not pass it on to a third
+        * party, we track the lifetime accurately.
+        */
+       bo->reusable = false;
+
+       /* The bo is outside of our control, so presume it is written to */
+       bo->needs_flush = true;
+       if (bo->domain != DOMAIN_GPU)
+               bo->domain = DOMAIN_NONE;
+
+       /* Henceforth, we need to broadcast all updates to clients and
+        * flush our rendering before doing so.
+        */
+       bo->flush = true;
+       if (bo->exec)
+               kgem->flush = 1;
+
+       return flink.name;
+}
+
+struct kgem_bo *kgem_create_map(struct kgem *kgem,
+                               void *ptr, uint32_t size,
+                               bool read_only)
+{
+       struct kgem_bo *bo;
+       uint32_t handle;
+
+       if (!kgem->has_userptr)
+               return NULL;
+
+       handle = gem_userptr(kgem->fd, ptr, size, read_only);
+       if (handle == 0)
+               return NULL;
+
+       bo = __kgem_bo_alloc(handle, NUM_PAGES(size));
+       if (bo == NULL) {
+               gem_close(kgem->fd, handle);
+               return NULL;
+       }
+
+       bo->snoop = !kgem->has_llc;
+       debug_alloc__bo(kgem, bo);
+
+       DBG(("%s(ptr=%p, size=%d, pages=%d, read_only=%d) => handle=%d\n",
+            __FUNCTION__, ptr, size, NUM_PAGES(size), read_only, handle));
+       return bo;
+}
+
+void kgem_bo_sync__cpu(struct kgem *kgem, struct kgem_bo *bo)
+{
+       assert(bo->proxy == NULL);
+       kgem_bo_submit(kgem, bo);
+
+       if (bo->domain != DOMAIN_CPU) {
+               struct drm_i915_gem_set_domain set_domain;
+
+               DBG(("%s: sync: needs_flush? %d, domain? %d, busy? %d\n", __FUNCTION__,
+                    bo->needs_flush, bo->domain, kgem_busy(kgem, bo->handle)));
+
+               VG_CLEAR(set_domain);
+               set_domain.handle = bo->handle;
+               set_domain.read_domains = I915_GEM_DOMAIN_CPU;
+               set_domain.write_domain = I915_GEM_DOMAIN_CPU;
+
+               if (drmIoctl(kgem->fd, DRM_IOCTL_I915_GEM_SET_DOMAIN, &set_domain) == 0) {
+                       kgem_bo_retire(kgem, bo);
+                       bo->domain = DOMAIN_CPU;
+               }
+       }
+}
+
+void kgem_bo_sync__gtt(struct kgem *kgem, struct kgem_bo *bo)
+{
+       assert(bo->proxy == NULL);
+       kgem_bo_submit(kgem, bo);
+
+       if (bo->domain != DOMAIN_GTT) {
+               struct drm_i915_gem_set_domain set_domain;
+
+               DBG(("%s: sync: needs_flush? %d, domain? %d, busy? %d\n", __FUNCTION__,
+                    bo->needs_flush, bo->domain, kgem_busy(kgem, bo->handle)));
+
+               VG_CLEAR(set_domain);
+               set_domain.handle = bo->handle;
+               set_domain.read_domains = I915_GEM_DOMAIN_GTT;
+               set_domain.write_domain = I915_GEM_DOMAIN_GTT;
+
+               if (drmIoctl(kgem->fd, DRM_IOCTL_I915_GEM_SET_DOMAIN, &set_domain) == 0) {
+                       kgem_bo_retire(kgem, bo);
+                       bo->domain = DOMAIN_GTT;
+               }
+       }
+}
+
+void kgem_clear_dirty(struct kgem *kgem)
+{
+       struct kgem_request *rq = kgem->next_request;
+       struct kgem_bo *bo;
+
+       list_for_each_entry(bo, &rq->buffers, request) {
+               if (!bo->dirty)
+                       break;
+
+               bo->dirty = false;
+       }
+}
+
+struct kgem_bo *kgem_create_proxy(struct kgem *kgem,
+                                 struct kgem_bo *target,
+                                 int offset, int length)
+{
+       struct kgem_bo *bo;
+
+       DBG(("%s: target handle=%d [proxy? %d], offset=%d, length=%d, io=%d\n",
+            __FUNCTION__, target->handle, target->proxy ? target->proxy->delta : -1,
+            offset, length, target->io));
+
+       bo = __kgem_bo_alloc(target->handle, length);
+       if (bo == NULL)
+               return NULL;
+
+       bo->unique_id = kgem_get_unique_id(kgem);
+       bo->reusable = false;
+       bo->size.bytes = length;
+
+       bo->io = target->io && target->proxy == NULL;
+       bo->dirty = target->dirty;
+       bo->tiling = target->tiling;
+       bo->pitch = target->pitch;
+
+       bo->proxy = kgem_bo_reference(target);
+       bo->delta = offset;
+
+       if (target->exec) {
+               list_move_tail(&bo->request, &kgem->next_request->buffers);
+               bo->exec = &_kgem_dummy_exec;
+       }
+       bo->rq = target->rq;
+
+       return bo;
+}
+
+static struct kgem_buffer *
+buffer_alloc(void)
+{
+       struct kgem_buffer *bo;
+
+       bo = malloc(sizeof(*bo));
+       if (bo == NULL)
+               return NULL;
+
+       bo->mem = NULL;
+       bo->need_io = false;
+       bo->mmapped = true;
+
+       return bo;
+}
+
+static struct kgem_buffer *
+buffer_alloc_with_data(int num_pages)
+{
+       struct kgem_buffer *bo;
+
+       bo = malloc(sizeof(*bo) + 2*UPLOAD_ALIGNMENT + num_pages * PAGE_SIZE);
+       if (bo == NULL)
+               return NULL;
+
+       bo->mem = (void *)ALIGN((uintptr_t)bo + sizeof(*bo), UPLOAD_ALIGNMENT);
+       bo->mmapped = false;
+       return bo;
+}
+
+static inline bool
+use_snoopable_buffer(struct kgem *kgem, uint32_t flags)
+{
+       if ((flags & KGEM_BUFFER_WRITE) == 0)
+               return kgem->gen >= 30;
+
+       return true;
+}
+
+static void
+init_buffer_from_bo(struct kgem_buffer *bo, struct kgem_bo *old)
+{
+       DBG(("%s: reusing handle=%d for buffer\n",
+            __FUNCTION__, old->handle));
+
+       assert(old->proxy == NULL);
+
+       memcpy(&bo->base, old, sizeof(*old));
+       if (old->rq)
+               list_replace(&old->request, &bo->base.request);
+       else
+               list_init(&bo->base.request);
+       list_replace(&old->vma, &bo->base.vma);
+       list_init(&bo->base.list);
+       free(old);
+
+       assert(bo->base.tiling == I915_TILING_NONE);
+
+       bo->base.refcnt = 1;
+}
+
+static struct kgem_buffer *
+search_snoopable_buffer(struct kgem *kgem, unsigned alloc)
+{
+       struct kgem_buffer *bo;
+       struct kgem_bo *old;
+
+       old = search_snoop_cache(kgem, alloc, 0);
+       if (old) {
+               if (!old->io) {
+                       bo = buffer_alloc();
+                       if (bo == NULL)
+                               return NULL;
+
+                       init_buffer_from_bo(bo, old);
+               } else {
+                       bo = (struct kgem_buffer *)old;
+                       bo->base.refcnt = 1;
+               }
+
+               DBG(("%s: created CPU handle=%d for buffer, size %d\n",
+                    __FUNCTION__, bo->base.handle, num_pages(&bo->base)));
+
+               assert(bo->base.snoop);
+               assert(bo->base.tiling == I915_TILING_NONE);
+               assert(num_pages(&bo->base) >= alloc);
+               assert(bo->mmapped == true);
+               assert(bo->need_io == false);
+
+               bo->mem = kgem_bo_map__cpu(kgem, &bo->base);
+               if (bo->mem == NULL) {
+                       bo->base.refcnt = 0;
+                       kgem_bo_free(kgem, &bo->base);
+                       bo = NULL;
+               }
+
+               return bo;
+       }
+
+       return NULL;
+}
+
+static struct kgem_buffer *
+create_snoopable_buffer(struct kgem *kgem, unsigned alloc)
+{
+       struct kgem_buffer *bo;
+       uint32_t handle;
+
+       assert(!kgem->has_llc);
+
+       if (kgem->has_cacheing) {
+               struct kgem_bo *old;
+
+               bo = buffer_alloc();
+               if (bo == NULL)
+                       return NULL;
+
+               old = search_linear_cache(kgem, alloc,
+                                        CREATE_INACTIVE | CREATE_CPU_MAP | CREATE_EXACT);
+               if (old) {
+                       init_buffer_from_bo(bo, old);
+               } else {
+                       handle = gem_create(kgem->fd, alloc);
+                       if (handle == 0) {
+                               free(bo);
+                               return NULL;
+                       }
+
+                       debug_alloc(kgem, alloc);
+                       __kgem_bo_init(&bo->base, handle, alloc);
+                       DBG(("%s: created CPU handle=%d for buffer, size %d\n",
+                            __FUNCTION__, bo->base.handle, alloc));
+               }
+
+               assert(bo->base.refcnt == 1);
+               assert(bo->mmapped == true);
+               assert(bo->need_io == false);
+
+               if (!gem_set_cacheing(kgem->fd, bo->base.handle, SNOOPED))
+                       goto free_cacheing;
+
+               bo->base.snoop = true;
+
+               bo->mem = kgem_bo_map__cpu(kgem, &bo->base);
+               if (bo->mem == NULL)
+                       goto free_cacheing;
+
+               return bo;
+
+free_cacheing:
+               bo->base.refcnt = 0; /* for valgrind */
+               kgem_bo_free(kgem, &bo->base);
+       }
+
+       if (kgem->has_userptr) {
+               bo = buffer_alloc();
+               if (bo == NULL)
+                       return NULL;
+
+               //if (posix_memalign(&ptr, 64, ALIGN(size, 64)))
+               if (posix_memalign(&bo->mem, PAGE_SIZE, alloc *PAGE_SIZE)) {
+                       free(bo);
+                       return NULL;
+               }
+
+               handle = gem_userptr(kgem->fd, bo->mem, alloc * PAGE_SIZE, false);
+               if (handle == 0) {
+                       free(bo->mem);
+                       free(bo);
+                       return NULL;
+               }
+
+               debug_alloc(kgem, alloc);
+               __kgem_bo_init(&bo->base, handle, alloc);
+               DBG(("%s: created snoop handle=%d for buffer\n",
+                    __FUNCTION__, bo->base.handle));
+
+               assert(bo->mmapped == true);
+               assert(bo->need_io == false);
+
+               bo->base.refcnt = 1;
+               bo->base.snoop = true;
+               bo->base.map = MAKE_USER_MAP(bo->mem);
+
+               return bo;
+       }
+
+       return NULL;
+}
+
+struct kgem_bo *kgem_create_buffer(struct kgem *kgem,
+                                  uint32_t size, uint32_t flags,
+                                  void **ret)
+{
+       struct kgem_buffer *bo;
+       unsigned offset, alloc;
+       struct kgem_bo *old;
+
+       DBG(("%s: size=%d, flags=%x [write?=%d, inplace?=%d, last?=%d]\n",
+            __FUNCTION__, size, flags,
+            !!(flags & KGEM_BUFFER_WRITE),
+            !!(flags & KGEM_BUFFER_INPLACE),
+            !!(flags & KGEM_BUFFER_LAST)));
+       assert(size);
+       /* we should never be asked to create anything TOO large */
+       assert(size <= kgem->max_object_size);
+
+       if (kgem->has_llc)
+               flags &= ~KGEM_BUFFER_INPLACE;
+
+#if !DBG_NO_UPLOAD_CACHE
+       list_for_each_entry(bo, &kgem->batch_buffers, base.list) {
+               assert(bo->base.io);
+               assert(bo->base.refcnt >= 1);
+
+               /* We can reuse any write buffer which we can fit */
+               if (flags == KGEM_BUFFER_LAST &&
+                   bo->write == KGEM_BUFFER_WRITE &&
+                   bo->base.refcnt == 1 && !bo->mmapped &&
+                   size <= bytes(&bo->base)) {
+                       DBG(("%s: reusing write buffer for read of %d bytes? used=%d, total=%d\n",
+                            __FUNCTION__, size, bo->used, bytes(&bo->base)));
+                       gem_write(kgem->fd, bo->base.handle,
+                                 0, bo->used, bo->mem);
+                       kgem_buffer_release(kgem, bo);
+                       bo->need_io = 0;
+                       bo->write = 0;
+                       offset = 0;
+                       bo->used = size;
+                       goto done;
+               }
+
+               if (flags & KGEM_BUFFER_WRITE) {
+                       if ((bo->write & KGEM_BUFFER_WRITE) == 0 ||
+                           (((bo->write & ~flags) & KGEM_BUFFER_INPLACE) &&
+                            !bo->base.snoop)) {
+                               DBG(("%s: skip write %x buffer, need %x\n",
+                                    __FUNCTION__, bo->write, flags));
+                               continue;
+                       }
+                       assert(bo->mmapped || bo->need_io);
+               } else {
+                       if (bo->write & KGEM_BUFFER_WRITE) {
+                               DBG(("%s: skip write %x buffer, need %x\n",
+                                    __FUNCTION__, bo->write, flags));
+                               continue;
+                       }
+               }
+
+               if (bo->used + size <= bytes(&bo->base)) {
+                       DBG(("%s: reusing buffer? used=%d + size=%d, total=%d\n",
+                            __FUNCTION__, bo->used, size, bytes(&bo->base)));
+                       offset = bo->used;
+                       bo->used += size;
+                       goto done;
+               }
+       }
+
+       if (flags & KGEM_BUFFER_WRITE) {
+               list_for_each_entry(bo, &kgem->active_buffers, base.list) {
+                       assert(bo->base.io);
+                       assert(bo->base.refcnt >= 1);
+                       assert(bo->mmapped);
+                       assert(!bo->base.snoop);
+                       assert(!IS_CPU_MAP(bo->base.map) || kgem->has_llc);
+
+                       if ((bo->write & ~flags) & KGEM_BUFFER_INPLACE) {
+                               DBG(("%s: skip write %x buffer, need %x\n",
+                                    __FUNCTION__, bo->write, flags));
+                               continue;
+                       }
+
+                       if (bo->used + size <= bytes(&bo->base)) {
+                               DBG(("%s: reusing buffer? used=%d + size=%d, total=%d\n",
+                                    __FUNCTION__, bo->used, size, bytes(&bo->base)));
+                               offset = bo->used;
+                               bo->used += size;
+                               list_move(&bo->base.list, &kgem->batch_buffers);
+                               goto done;
+                       }
+               }
+       }
+#endif
+
+#if !DBG_NO_MAP_UPLOAD
+       /* Be a little more generous and hope to hold fewer mmappings */
+       alloc = ALIGN(2*size, kgem->buffer_size);
+       if (alloc > MAX_CACHE_SIZE)
+               alloc = ALIGN(size, kgem->buffer_size);
+       if (alloc > MAX_CACHE_SIZE)
+               alloc = PAGE_ALIGN(size);
+       alloc /= PAGE_SIZE;
+       if (kgem->has_llc) {
+               bo = buffer_alloc();
+               if (bo == NULL)
+                       return NULL;
+
+               old = NULL;
+               if ((flags & KGEM_BUFFER_WRITE) == 0)
+                       old = search_linear_cache(kgem, alloc, CREATE_CPU_MAP);
+               if (old == NULL)
+                       old = search_linear_cache(kgem, alloc, CREATE_INACTIVE | CREATE_CPU_MAP);
+               if (old == NULL)
+                       old = search_linear_cache(kgem, NUM_PAGES(size), CREATE_INACTIVE | CREATE_CPU_MAP);
+               if (old) {
+                       DBG(("%s: found LLC handle=%d for buffer\n",
+                            __FUNCTION__, old->handle));
+
+                       init_buffer_from_bo(bo, old);
+               } else {
+                       uint32_t handle = gem_create(kgem->fd, alloc);
+                       if (handle == 0) {
+                               free(bo);
+                               return NULL;
+                       }
+                       __kgem_bo_init(&bo->base, handle, alloc);
+                       DBG(("%s: created LLC handle=%d for buffer\n",
+                            __FUNCTION__, bo->base.handle));
+
+                       debug_alloc(kgem, alloc);
+               }
+
+               assert(bo->mmapped);
+               assert(!bo->need_io);
+
+               bo->mem = kgem_bo_map__cpu(kgem, &bo->base);
+               if (bo->mem) {
+                       if (flags & KGEM_BUFFER_WRITE)
+                               kgem_bo_sync__cpu(kgem, &bo->base);
+
+                       alloc = num_pages(&bo->base);
+                       goto init;
+               } else {
+                       bo->base.refcnt = 0; /* for valgrind */
+                       kgem_bo_free(kgem, &bo->base);
+               }
+       }
+
+       if (PAGE_SIZE * alloc > kgem->aperture_mappable / 4)
+               flags &= ~KGEM_BUFFER_INPLACE;
+
+       if ((flags & KGEM_BUFFER_WRITE_INPLACE) == KGEM_BUFFER_WRITE_INPLACE) {
+               /* The issue with using a GTT upload buffer is that we may
+                * cause eviction-stalls in order to free up some GTT space.
+                * An is-mappable? ioctl could help us detect when we are
+                * about to block, or some per-page magic in the kernel.
+                *
+                * XXX This is especially noticeable on memory constrained
+                * devices like gen2 or with relatively slow gpu like i3.
+                */
+               DBG(("%s: searching for an inactive GTT map for upload\n",
+                    __FUNCTION__));
+               old = search_linear_cache(kgem, alloc,
+                                         CREATE_EXACT | CREATE_INACTIVE | CREATE_GTT_MAP);
+#if HAVE_I915_GEM_BUFFER_INFO
+               if (old) {
+                       struct drm_i915_gem_buffer_info info;
+
+                       /* An example of such a non-blocking ioctl might work */
+
+                       VG_CLEAR(info);
+                       info.handle = handle;
+                       if (drmIoctl(kgem->fd,
+                                    DRM_IOCTL_I915_GEM_BUFFER_INFO,
+                                    &fino) == 0) {
+                               old->presumed_offset = info.addr;
+                               if ((info.flags & I915_GEM_MAPPABLE) == 0) {
+                                       kgem_bo_move_to_inactive(kgem, old);
+                                       old = NULL;
+                               }
+                       }
+               }
+#endif
+               if (old == NULL)
+                       old = search_linear_cache(kgem, NUM_PAGES(size),
+                                                 CREATE_EXACT | CREATE_INACTIVE | CREATE_GTT_MAP);
+               if (old == NULL) {
+                       old = search_linear_cache(kgem, alloc, CREATE_INACTIVE);
+                       if (old && !kgem_bo_is_mappable(kgem, old)) {
+                               _kgem_bo_destroy(kgem, old);
+                               old = NULL;
+                       }
+               }
+               if (old) {
+                       DBG(("%s: reusing handle=%d for buffer\n",
+                            __FUNCTION__, old->handle));
+                       assert(kgem_bo_is_mappable(kgem, old));
+                       assert(!old->snoop);
+                       assert(old->rq == NULL);
+
+                       bo = buffer_alloc();
+                       if (bo == NULL)
+                               return NULL;
+
+                       init_buffer_from_bo(bo, old);
+                       assert(num_pages(&bo->base) >= NUM_PAGES(size));
+
+                       assert(bo->mmapped);
+                       assert(bo->base.refcnt == 1);
+
+                       bo->mem = kgem_bo_map(kgem, &bo->base);
+                       if (bo->mem) {
+                               alloc = num_pages(&bo->base);
+                               if (IS_CPU_MAP(bo->base.map))
+                                   flags &= ~KGEM_BUFFER_INPLACE;
+                               goto init;
+                       } else {
+                               bo->base.refcnt = 0;
+                               kgem_bo_free(kgem, &bo->base);
+                       }
+               }
+       }
+#else
+       flags &= ~KGEM_BUFFER_INPLACE;
+#endif
+       /* Be more parsimonious with pwrite/pread/cacheable buffers */
+       if ((flags & KGEM_BUFFER_INPLACE) == 0)
+               alloc = NUM_PAGES(size);
+
+       if (use_snoopable_buffer(kgem, flags)) {
+               bo = search_snoopable_buffer(kgem, alloc);
+               if (bo) {
+                       if (flags & KGEM_BUFFER_WRITE)
+                               kgem_bo_sync__cpu(kgem, &bo->base);
+                       flags &= ~KGEM_BUFFER_INPLACE;
+                       alloc = num_pages(&bo->base);
+                       goto init;
+               }
+
+               if ((flags & KGEM_BUFFER_WRITE_INPLACE) != KGEM_BUFFER_WRITE_INPLACE) {
+                       bo = create_snoopable_buffer(kgem, alloc);
+                       if (bo) {
+                               flags &= ~KGEM_BUFFER_INPLACE;
+                               goto init;
+                       }
+               }
+       }
+
+       flags &= ~KGEM_BUFFER_INPLACE;
+
+       old = NULL;
+       if ((flags & KGEM_BUFFER_WRITE) == 0)
+               old = search_linear_cache(kgem, alloc, 0);
+       if (old == NULL)
+               old = search_linear_cache(kgem, alloc, CREATE_INACTIVE);
+       if (old) {
+               DBG(("%s: reusing ordinary handle %d for io\n",
+                    __FUNCTION__, old->handle));
+               alloc = num_pages(old);
+               bo = buffer_alloc_with_data(alloc);
+               if (bo == NULL)
+                       return NULL;
+
+               init_buffer_from_bo(bo, old);
+               bo->need_io = flags & KGEM_BUFFER_WRITE;
+       } else {
+               if (use_snoopable_buffer(kgem, flags)) {
+                       bo = create_snoopable_buffer(kgem, alloc);
+                       if (bo)
+                               goto init;
+               }
+
+               bo = buffer_alloc();
+               if (bo == NULL)
+                       return NULL;
+
+               old = search_linear_cache(kgem, alloc,
+                                         CREATE_INACTIVE | CREATE_CPU_MAP);
+               if (old) {
+                       DBG(("%s: reusing cpu map handle=%d for buffer\n",
+                            __FUNCTION__, old->handle));
+
+                       alloc = num_pages(old);
+                       init_buffer_from_bo(bo, old);
+               } else {
+                       uint32_t handle = gem_create(kgem->fd, alloc);
+                       if (handle == 0) {
+                               free(bo);
+                               return NULL;
+                       }
+
+                       DBG(("%s: created handle=%d for buffer\n",
+                            __FUNCTION__, bo->base.handle));
+
+                       __kgem_bo_init(&bo->base, handle, alloc);
+                       debug_alloc(kgem, alloc * PAGE_SIZE);
+               }
+
+               assert(bo->mmapped);
+               assert(!bo->need_io);
+               assert(bo->base.refcnt == 1);
+
+               bo->mem = kgem_bo_map__cpu(kgem, &bo->base);
+               if (bo->mem != NULL) {
+                       if (flags & KGEM_BUFFER_WRITE)
+                               kgem_bo_sync__cpu(kgem, &bo->base);
+                       goto init;
+               }
+
+               DBG(("%s: failing back to new pwrite buffer\n", __FUNCTION__));
+               old = &bo->base;
+               bo = buffer_alloc_with_data(alloc);
+               if (bo == NULL) {
+                       free(old);
+                       return NULL;
+               }
+
+               init_buffer_from_bo(bo, old);
+
+               assert(bo->mem);
+               assert(!bo->mmapped);
+               assert(bo->base.refcnt == 1);
+
+               bo->need_io = flags & KGEM_BUFFER_WRITE;
+       }
+init:
+       bo->base.io = true;
+       assert(bo->base.refcnt == 1);
+       assert(num_pages(&bo->base) == alloc);
+       assert(!bo->need_io || !bo->base.needs_flush);
+       assert(!bo->need_io || bo->base.domain != DOMAIN_GPU);
+       assert(bo->mem);
+       assert(!bo->mmapped || bo->base.map != NULL);
+
+       bo->used = size;
+       bo->write = flags & KGEM_BUFFER_WRITE_INPLACE;
+       offset = 0;
+
+       assert(list_is_empty(&bo->base.list));
+       list_add(&bo->base.list, &kgem->batch_buffers);
+
+       DBG(("%s(pages=%d) new handle=%d, used=%d, write=%d\n",
+            __FUNCTION__, alloc, bo->base.handle, bo->used, bo->write));
+
+done:
+       bo->used = ALIGN(bo->used, UPLOAD_ALIGNMENT);
+       assert(bo->mem);
+       *ret = (char *)bo->mem + offset;
+       return kgem_create_proxy(kgem, &bo->base, offset, size);
+}
+
+bool kgem_buffer_is_inplace(struct kgem_bo *_bo)
+{
+       struct kgem_buffer *bo = (struct kgem_buffer *)_bo->proxy;
+       return bo->write & KGEM_BUFFER_WRITE_INPLACE;
+}
+
+struct kgem_bo *kgem_create_buffer_2d(struct kgem *kgem,
+                                     int width, int height, int bpp,
+                                     uint32_t flags,
+                                     void **ret)
+{
+       struct kgem_bo *bo;
+       int stride;
+
+       assert(width > 0 && height > 0);
+       assert(ret != NULL);
+       stride = ALIGN(width, 2) * bpp >> 3;
+       stride = ALIGN(stride, 4);
+
+       DBG(("%s: %dx%d, %d bpp, stride=%d\n",
+            __FUNCTION__, width, height, bpp, stride));
+
+       bo = kgem_create_buffer(kgem, stride * ALIGN(height, 2), flags, ret);
+       if (bo == NULL) {
+               DBG(("%s: allocation failure for upload buffer\n",
+                    __FUNCTION__));
+               return NULL;
+       }
+       assert(*ret != NULL);
+
+       if (height & 1) {
+               struct kgem_buffer *io = (struct kgem_buffer *)bo->proxy;
+               int min;
+
+               assert(io->used);
+
+               /* Having padded this surface to ensure that accesses to
+                * the last pair of rows is valid, remove the padding so
+                * that it can be allocated to other pixmaps.
+                */
+               min = bo->delta + height * stride;
+               min = ALIGN(min, UPLOAD_ALIGNMENT);
+               if (io->used != min) {
+                       DBG(("%s: trimming buffer from %d to %d\n",
+                            __FUNCTION__, io->used, min));
+                       io->used = min;
+               }
+               bo->size.bytes -= stride;
+       }
+
+       bo->pitch = stride;
+       bo->unique_id = kgem_get_unique_id(kgem);
+       return bo;
+}
+
+struct kgem_bo *kgem_upload_source_image(struct kgem *kgem,
+                                        const void *data,
+                                        BoxPtr box,
+                                        int stride, int bpp)
+{
+       int width = box->x2 - box->x1;
+       int height = box->y2 - box->y1;
+       struct kgem_bo *bo;
+       void *dst;
+
+       DBG(("%s : (%d, %d), (%d, %d), stride=%d, bpp=%d\n",
+            __FUNCTION__, box->x1, box->y1, box->x2, box->y2, stride, bpp));
+
+       assert(data);
+       assert(width > 0);
+       assert(height > 0);
+       assert(stride);
+       assert(bpp);
+
+       bo = kgem_create_buffer_2d(kgem,
+                                  width, height, bpp,
+                                  KGEM_BUFFER_WRITE_INPLACE, &dst);
+       if (bo)
+               memcpy_blt(data, dst, bpp,
+                          stride, bo->pitch,
+                          box->x1, box->y1,
+                          0, 0,
+                          width, height);
+
+       return bo;
+}
+
+void kgem_proxy_bo_attach(struct kgem_bo *bo,
+                         struct kgem_bo **ptr)
+{
+       DBG(("%s: handle=%d\n", __FUNCTION__, bo->handle));
+       assert(bo->map == NULL);
+       assert(bo->proxy);
+       list_add(&bo->vma, &bo->proxy->vma);
+       bo->map = ptr;
+       *ptr = kgem_bo_reference(bo);
+}
+
+void kgem_buffer_read_sync(struct kgem *kgem, struct kgem_bo *_bo)
+{
+       struct kgem_buffer *bo;
+       uint32_t offset = _bo->delta, length = _bo->size.bytes;
+
+       /* We expect the caller to have already submitted the batch */
+       assert(_bo->io);
+       assert(_bo->exec == NULL);
+       assert(_bo->rq == NULL);
+       assert(_bo->proxy);
+
+       _bo = _bo->proxy;
+       assert(_bo->proxy == NULL);
+       assert(_bo->exec == NULL);
+
+       bo = (struct kgem_buffer *)_bo;
+
+       DBG(("%s(offset=%d, length=%d, snooped=%d)\n", __FUNCTION__,
+            offset, length, bo->base.snoop));
+
+       if (bo->mmapped) {
+               struct drm_i915_gem_set_domain set_domain;
+
+               DBG(("%s: sync: needs_flush? %d, domain? %d, busy? %d\n",
+                    __FUNCTION__,
+                    bo->base.needs_flush,
+                    bo->base.domain,
+                    kgem_busy(kgem, bo->base.handle)));
+
+               VG_CLEAR(set_domain);
+               set_domain.handle = bo->base.handle;
+               set_domain.write_domain = 0;
+               set_domain.read_domains =
+                       IS_CPU_MAP(bo->base.map) ? I915_GEM_DOMAIN_CPU : I915_GEM_DOMAIN_GTT;
+
+               if (drmIoctl(kgem->fd,
+                            DRM_IOCTL_I915_GEM_SET_DOMAIN, &set_domain))
+                       return;
+       } else {
+               if (gem_read(kgem->fd,
+                            bo->base.handle, (char *)bo->mem+offset,
+                            offset, length))
+                       return;
+       }
+       kgem_bo_retire(kgem, &bo->base);
+}
+
+uint32_t kgem_bo_get_binding(struct kgem_bo *bo, uint32_t format)
+{
+       struct kgem_bo_binding *b;
+
+       for (b = &bo->binding; b && b->offset; b = b->next)
+               if (format == b->format)
+                       return b->offset;
+
+       return 0;
+}
+
+void kgem_bo_set_binding(struct kgem_bo *bo, uint32_t format, uint16_t offset)
+{
+       struct kgem_bo_binding *b;
+
+       for (b = &bo->binding; b; b = b->next) {
+               if (b->offset)
+                       continue;
+
+               b->offset = offset;
+               b->format = format;
+
+               if (b->next)
+                       b->next->offset = 0;
+
+               return;
+       }
+
+       b = malloc(sizeof(*b));
+       if (b) {
+               b->next = bo->binding.next;
+               b->format = format;
+               b->offset = offset;
+               bo->binding.next = b;
+       }
+}
+
+int kgem_bo_get_swizzling(struct kgem *kgem, struct kgem_bo *bo)
+{
+       struct drm_i915_gem_get_tiling tiling;
+
+       VG_CLEAR(tiling);
+       tiling.handle = bo->handle;
+       if (drmIoctl(kgem->fd, DRM_IOCTL_I915_GEM_GET_TILING, &tiling))
+               return 0;
+
+       assert(bo->tiling == tiling.tiling_mode);
+       return tiling.swizzle_mode;
+}
+
+struct kgem_bo *
+kgem_replace_bo(struct kgem *kgem,
+               struct kgem_bo *src,
+               uint32_t width,
+               uint32_t height,
+               uint32_t pitch,
+               uint32_t bpp)
+{
+       struct kgem_bo *dst;
+       uint32_t br00, br13;
+       uint32_t handle;
+       uint32_t size;
+       uint32_t *b;
+
+       DBG(("%s: replacing bo handle=%d, size=%dx%d pitch=%d, with pitch=%d\n",
+            __FUNCTION__, src->handle,  width, height, src->pitch, pitch));
+
+       /* We only expect to be called to fixup small buffers, hence why
+        * we only attempt to allocate a linear bo.
+        */
+       assert(src->tiling == I915_TILING_NONE);
+
+       size = height * pitch;
+       size = PAGE_ALIGN(size) / PAGE_SIZE;
+
+       dst = search_linear_cache(kgem, size, 0);
+       if (dst == NULL)
+               dst = search_linear_cache(kgem, size, CREATE_INACTIVE);
+       if (dst == NULL) {
+               handle = gem_create(kgem->fd, size);
+               if (handle == 0)
+                       return NULL;
+
+               dst = __kgem_bo_alloc(handle, size);
+               if (dst== NULL) {
+                       gem_close(kgem->fd, handle);
+                       return NULL;
+               }
+
+               debug_alloc__bo(kgem, dst);
+       }
+       dst->pitch = pitch;
+       dst->unique_id = kgem_get_unique_id(kgem);
+       dst->refcnt = 1;
+
+       kgem_set_mode(kgem, KGEM_BLT);
+       if (!kgem_check_batch(kgem, 8) ||
+           !kgem_check_reloc(kgem, 2) ||
+           !kgem_check_many_bo_fenced(kgem, src, dst, NULL)) {
+               _kgem_submit(kgem);
+               _kgem_set_mode(kgem, KGEM_BLT);
+       }
+
+       br00 = XY_SRC_COPY_BLT_CMD;
+       br13 = pitch;
+       pitch = src->pitch;
+       if (kgem->gen >= 40 && src->tiling) {
+               br00 |= BLT_SRC_TILED;
+               pitch >>= 2;
+       }
+
+       br13 |= 0xcc << 16;
+       switch (bpp) {
+       default:
+       case 32: br00 |= BLT_WRITE_ALPHA | BLT_WRITE_RGB;
+                br13 |= 1 << 25; /* RGB8888 */
+       case 16: br13 |= 1 << 24; /* RGB565 */
+       case 8: break;
+       }
+
+       b = kgem->batch + kgem->nbatch;
+       b[0] = br00;
+       b[1] = br13;
+       b[2] = 0;
+       b[3] = height << 16 | width;
+       b[4] = kgem_add_reloc(kgem, kgem->nbatch + 4, dst,
+                             I915_GEM_DOMAIN_RENDER << 16 |
+                             I915_GEM_DOMAIN_RENDER |
+                             KGEM_RELOC_FENCED,
+                             0);
+       b[5] = 0;
+       b[6] = pitch;
+       b[7] = kgem_add_reloc(kgem, kgem->nbatch + 7, src,
+                             I915_GEM_DOMAIN_RENDER << 16 |
+                             KGEM_RELOC_FENCED,
+                             0);
+       kgem->nbatch += 8;
+
+       return dst;
+}
diff --git a/src/sna/kgem.h b/src/sna/kgem.h
new file mode 100644 (file)
index 0000000..cdbb7cb
--- /dev/null
@@ -0,0 +1,605 @@
+/*
+ * Copyright (c) 2011 Intel 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.
+ *
+ * Authors:
+ *    Chris Wilson <chris@chris-wilson.co.uk>
+ *
+ */
+
+#ifndef KGEM_H
+#define KGEM_H
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <stdarg.h>
+
+#include <i915_drm.h>
+
+#include "compiler.h"
+
+#if HAS_DEBUG_FULL
+#define DBG(x) ErrorF x
+#else
+#define DBG(x)
+#endif
+
+struct kgem_bo {
+       struct kgem_bo *proxy;
+
+       struct list list;
+       struct list request;
+       struct list vma;
+
+       void *map;
+#define IS_CPU_MAP(ptr) ((uintptr_t)(ptr) & 1)
+#define IS_GTT_MAP(ptr) (ptr && ((uintptr_t)(ptr) & 1) == 0)
+       struct kgem_request *rq;
+       struct drm_i915_gem_exec_object2 *exec;
+
+       struct kgem_bo_binding {
+               struct kgem_bo_binding *next;
+               uint32_t format;
+               uint16_t offset;
+       } binding;
+
+       uint32_t unique_id;
+       uint32_t refcnt;
+       uint32_t handle;
+       uint32_t presumed_offset;
+       uint32_t delta;
+       union {
+               struct {
+                       uint32_t count:27;
+#define PAGE_SIZE 4096
+                       uint32_t bucket:5;
+#define NUM_CACHE_BUCKETS 16
+#define MAX_CACHE_SIZE (1 << (NUM_CACHE_BUCKETS+12))
+               } pages;
+               uint32_t bytes;
+       } size;
+       uint32_t pitch : 18; /* max 128k */
+       uint32_t tiling : 2;
+       uint32_t reusable : 1;
+       uint32_t dirty : 1;
+       uint32_t domain : 2;
+       uint32_t needs_flush : 1;
+       uint32_t snoop : 1;
+       uint32_t io : 1;
+       uint32_t flush : 1;
+       uint32_t scanout : 1;
+       uint32_t purged : 1;
+};
+#define DOMAIN_NONE 0
+#define DOMAIN_CPU 1
+#define DOMAIN_GTT 2
+#define DOMAIN_GPU 3
+
+struct kgem_request {
+       struct list list;
+       struct kgem_bo *bo;
+       struct list buffers;
+       int ring;
+};
+
+enum {
+       MAP_GTT = 0,
+       MAP_CPU,
+       NUM_MAP_TYPES,
+};
+
+struct kgem {
+       int fd;
+       int wedged;
+       unsigned gen;
+
+       uint32_t unique_id;
+
+       enum kgem_mode {
+               /* order matches I915_EXEC_RING ordering */
+               KGEM_NONE = 0,
+               KGEM_RENDER,
+               KGEM_BSD,
+               KGEM_BLT,
+       } mode, ring;
+
+       struct list flushing;
+       struct list large;
+       struct list large_inactive;
+       struct list active[NUM_CACHE_BUCKETS][3];
+       struct list inactive[NUM_CACHE_BUCKETS];
+       struct list snoop;
+       struct list batch_buffers, active_buffers;
+
+       struct list requests[2];
+       struct kgem_request *next_request;
+       uint32_t num_requests;
+
+       struct {
+               struct list inactive[NUM_CACHE_BUCKETS];
+               int16_t count;
+       } vma[NUM_MAP_TYPES];
+
+       uint16_t nbatch;
+       uint16_t surface;
+       uint16_t nexec;
+       uint16_t nreloc;
+       uint16_t nfence;
+       uint16_t batch_size;
+       uint16_t min_alignment;
+
+       uint32_t flush:1;
+       uint32_t need_expire:1;
+       uint32_t need_purge:1;
+       uint32_t need_retire:1;
+       uint32_t need_throttle:1;
+       uint32_t busy:1;
+
+       uint32_t has_userptr :1;
+       uint32_t has_blt :1;
+       uint32_t has_relaxed_fencing :1;
+       uint32_t has_relaxed_delta :1;
+       uint32_t has_semaphores :1;
+       uint32_t has_cacheing :1;
+       uint32_t has_llc :1;
+
+       uint32_t can_blt_cpu :1;
+
+       uint16_t fence_max;
+       uint16_t half_cpu_cache_pages;
+       uint32_t aperture_total, aperture_high, aperture_low, aperture_mappable;
+       uint32_t aperture, aperture_fenced;
+       uint32_t max_upload_tile_size, max_copy_tile_size;
+       uint32_t max_gpu_size, max_cpu_size;
+       uint32_t large_object_size, max_object_size;
+       uint32_t buffer_size;
+
+       void (*context_switch)(struct kgem *kgem, int new_mode);
+       void (*retire)(struct kgem *kgem);
+       void (*expire)(struct kgem *kgem);
+
+       uint32_t batch[64*1024-8];
+       struct drm_i915_gem_exec_object2 exec[256];
+       struct drm_i915_gem_relocation_entry reloc[4096];
+
+#ifdef DEBUG_MEMORY
+       struct {
+               int bo_allocs;
+               size_t bo_bytes;
+       } debug_memory;
+#endif
+};
+
+#define KGEM_BATCH_RESERVED 1
+#define KGEM_RELOC_RESERVED 4
+#define KGEM_EXEC_RESERVED 1
+
+#ifndef ARRAY_SIZE
+#define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
+#endif
+
+#define KGEM_BATCH_SIZE(K) ((K)->batch_size-KGEM_BATCH_RESERVED)
+#define KGEM_EXEC_SIZE(K) (int)(ARRAY_SIZE((K)->exec)-KGEM_EXEC_RESERVED)
+#define KGEM_RELOC_SIZE(K) (int)(ARRAY_SIZE((K)->reloc)-KGEM_RELOC_RESERVED)
+
+void kgem_init(struct kgem *kgem, int fd, struct pci_device *dev, int gen);
+void kgem_reset(struct kgem *kgem);
+
+struct kgem_bo *kgem_create_map(struct kgem *kgem,
+                               void *ptr, uint32_t size,
+                               bool read_only);
+
+struct kgem_bo *kgem_create_for_name(struct kgem *kgem, uint32_t name);
+struct kgem_bo *kgem_create_for_prime(struct kgem *kgem, int name, uint32_t size);
+int kgem_bo_export_to_prime(struct kgem *kgem, struct kgem_bo *bo);
+
+struct kgem_bo *kgem_create_linear(struct kgem *kgem, int size, unsigned flags);
+struct kgem_bo *kgem_create_proxy(struct kgem *kgem,
+                                 struct kgem_bo *target,
+                                 int offset, int length);
+
+struct kgem_bo *kgem_upload_source_image(struct kgem *kgem,
+                                        const void *data,
+                                        BoxPtr box,
+                                        int stride, int bpp);
+void kgem_proxy_bo_attach(struct kgem_bo *bo, struct kgem_bo **ptr);
+
+int kgem_choose_tiling(struct kgem *kgem,
+                      int tiling, int width, int height, int bpp);
+unsigned kgem_can_create_2d(struct kgem *kgem, int width, int height, int depth);
+#define KGEM_CAN_CREATE_GPU    0x1
+#define KGEM_CAN_CREATE_CPU    0x2
+#define KGEM_CAN_CREATE_LARGE  0x4
+#define KGEM_CAN_CREATE_GTT    0x8
+
+struct kgem_bo *
+kgem_replace_bo(struct kgem *kgem,
+               struct kgem_bo *src,
+               uint32_t width,
+               uint32_t height,
+               uint32_t pitch,
+               uint32_t bpp);
+enum {
+       CREATE_EXACT = 0x1,
+       CREATE_INACTIVE = 0x2,
+       CREATE_CPU_MAP = 0x4,
+       CREATE_GTT_MAP = 0x8,
+       CREATE_SCANOUT = 0x10,
+       CREATE_PRIME = 0x20,
+       CREATE_TEMPORARY = 0x40,
+       CREATE_NO_RETIRE = 0x80,
+       CREATE_NO_THROTTLE = 0x100,
+};
+struct kgem_bo *kgem_create_2d(struct kgem *kgem,
+                              int width,
+                              int height,
+                              int bpp,
+                              int tiling,
+                              uint32_t flags);
+struct kgem_bo *kgem_create_cpu_2d(struct kgem *kgem,
+                                  int width,
+                                  int height,
+                                  int bpp,
+                                  uint32_t flags);
+
+uint32_t kgem_bo_get_binding(struct kgem_bo *bo, uint32_t format);
+void kgem_bo_set_binding(struct kgem_bo *bo, uint32_t format, uint16_t offset);
+int kgem_bo_get_swizzling(struct kgem *kgem, struct kgem_bo *bo);
+
+void kgem_bo_retire(struct kgem *kgem, struct kgem_bo *bo);
+bool kgem_retire(struct kgem *kgem);
+bool __kgem_is_idle(struct kgem *kgem);
+static inline bool kgem_is_idle(struct kgem *kgem)
+{
+       if (kgem->num_requests == 0) {
+               DBG(("%s: no outstanding requests\n", __FUNCTION__));
+               return true;
+       }
+
+       return __kgem_is_idle(kgem);
+}
+
+void _kgem_submit(struct kgem *kgem);
+static inline void kgem_submit(struct kgem *kgem)
+{
+       if (kgem->nbatch)
+               _kgem_submit(kgem);
+}
+
+static inline bool kgem_flush(struct kgem *kgem)
+{
+       return kgem->flush && kgem_is_idle(kgem);
+}
+
+static inline void kgem_bo_submit(struct kgem *kgem, struct kgem_bo *bo)
+{
+       if (bo->exec)
+               _kgem_submit(kgem);
+}
+
+bool __kgem_flush(struct kgem *kgem, struct kgem_bo *bo);
+static inline void kgem_bo_flush(struct kgem *kgem, struct kgem_bo *bo)
+{
+       kgem_bo_submit(kgem, bo);
+
+       if (!bo->needs_flush)
+               return;
+
+       /* If the kernel fails to emit the flush, then it will be forced when
+        * we assume direct access. And as the useual failure is EIO, we do
+        * not actualy care.
+        */
+       (void)__kgem_flush(kgem, bo);
+}
+
+static inline struct kgem_bo *kgem_bo_reference(struct kgem_bo *bo)
+{
+       assert(bo->refcnt);
+       bo->refcnt++;
+       return bo;
+}
+
+void _kgem_bo_destroy(struct kgem *kgem, struct kgem_bo *bo);
+static inline void kgem_bo_destroy(struct kgem *kgem, struct kgem_bo *bo)
+{
+       assert(bo->refcnt);
+       if (--bo->refcnt == 0)
+               _kgem_bo_destroy(kgem, bo);
+}
+
+void kgem_clear_dirty(struct kgem *kgem);
+
+static inline void kgem_set_mode(struct kgem *kgem, enum kgem_mode mode)
+{
+       assert(!kgem->wedged);
+
+#if DEBUG_FLUSH_BATCH
+       kgem_submit(kgem);
+#endif
+
+       if (kgem->mode == mode)
+               return;
+
+       kgem->context_switch(kgem, mode);
+       kgem->mode = mode;
+}
+
+static inline void _kgem_set_mode(struct kgem *kgem, enum kgem_mode mode)
+{
+       assert(kgem->mode == KGEM_NONE);
+       assert(kgem->nbatch == 0);
+       kgem->context_switch(kgem, mode);
+       kgem->mode = mode;
+}
+
+static inline bool kgem_check_batch(struct kgem *kgem, int num_dwords)
+{
+       return likely(kgem->nbatch + num_dwords + KGEM_BATCH_RESERVED <= kgem->surface);
+}
+
+static inline bool kgem_check_reloc(struct kgem *kgem, int n)
+{
+       return likely(kgem->nreloc + n <= KGEM_RELOC_SIZE(kgem));
+}
+
+static inline bool kgem_check_exec(struct kgem *kgem, int n)
+{
+       return likely(kgem->nexec + n <= KGEM_EXEC_SIZE(kgem));
+}
+
+static inline bool kgem_check_reloc_and_exec(struct kgem *kgem, int n)
+{
+       return kgem_check_reloc(kgem, n) && kgem_check_exec(kgem, n);
+}
+
+static inline bool kgem_check_batch_with_surfaces(struct kgem *kgem,
+                                                 int num_dwords,
+                                                 int num_surfaces)
+{
+       return (int)(kgem->nbatch + num_dwords + KGEM_BATCH_RESERVED) <= (int)(kgem->surface - num_surfaces*8) &&
+               kgem_check_reloc(kgem, num_surfaces) &&
+               kgem_check_exec(kgem, num_surfaces);
+}
+
+static inline uint32_t *kgem_get_batch(struct kgem *kgem, int num_dwords)
+{
+       if (!kgem_check_batch(kgem, num_dwords))
+               _kgem_submit(kgem);
+
+       return kgem->batch + kgem->nbatch;
+}
+
+static inline void kgem_advance_batch(struct kgem *kgem, int num_dwords)
+{
+       kgem->nbatch += num_dwords;
+}
+
+bool kgem_check_bo(struct kgem *kgem, ...) __attribute__((sentinel(0)));
+bool kgem_check_bo_fenced(struct kgem *kgem, struct kgem_bo *bo);
+bool kgem_check_many_bo_fenced(struct kgem *kgem, ...) __attribute__((sentinel(0)));
+
+void _kgem_add_bo(struct kgem *kgem, struct kgem_bo *bo);
+static inline void kgem_add_bo(struct kgem *kgem, struct kgem_bo *bo)
+{
+       if (bo->proxy)
+               bo = bo->proxy;
+
+       if (bo->exec == NULL)
+               _kgem_add_bo(kgem, bo);
+}
+
+#define KGEM_RELOC_FENCED 0x8000
+uint32_t kgem_add_reloc(struct kgem *kgem,
+                       uint32_t pos,
+                       struct kgem_bo *bo,
+                       uint32_t read_write_domains,
+                       uint32_t delta);
+
+void *kgem_bo_map(struct kgem *kgem, struct kgem_bo *bo);
+void *kgem_bo_map__async(struct kgem *kgem, struct kgem_bo *bo);
+void *kgem_bo_map__gtt(struct kgem *kgem, struct kgem_bo *bo);
+void kgem_bo_sync__gtt(struct kgem *kgem, struct kgem_bo *bo);
+void *kgem_bo_map__debug(struct kgem *kgem, struct kgem_bo *bo);
+void *kgem_bo_map__cpu(struct kgem *kgem, struct kgem_bo *bo);
+void kgem_bo_sync__cpu(struct kgem *kgem, struct kgem_bo *bo);
+void *__kgem_bo_map__cpu(struct kgem *kgem, struct kgem_bo *bo);
+void __kgem_bo_unmap__cpu(struct kgem *kgem, struct kgem_bo *bo, void *ptr);
+uint32_t kgem_bo_flink(struct kgem *kgem, struct kgem_bo *bo);
+
+bool kgem_bo_write(struct kgem *kgem, struct kgem_bo *bo,
+                  const void *data, int length);
+
+int kgem_bo_fenced_size(struct kgem *kgem, struct kgem_bo *bo);
+void kgem_get_tile_size(struct kgem *kgem, int tiling,
+                       int *tile_width, int *tile_height, int *tile_size);
+
+static inline int __kgem_buffer_size(struct kgem_bo *bo)
+{
+       assert(bo->proxy != NULL);
+       return bo->size.bytes;
+}
+
+static inline int __kgem_bo_size(struct kgem_bo *bo)
+{
+       assert(bo->proxy == NULL);
+       return PAGE_SIZE * bo->size.pages.count;
+}
+
+static inline int kgem_bo_size(struct kgem_bo *bo)
+{
+       if (bo->proxy)
+               return __kgem_buffer_size(bo);
+       else
+               return __kgem_bo_size(bo);
+}
+
+static inline bool kgem_bo_blt_pitch_is_ok(struct kgem *kgem,
+                                          struct kgem_bo *bo)
+{
+       int pitch = bo->pitch;
+       if (kgem->gen >= 40 && bo->tiling)
+               pitch /= 4;
+       if (pitch > MAXSHORT) {
+               DBG(("%s: can not blt to handle=%d, adjusted pitch=%d\n",
+                    __FUNCTION__, bo->handle, pitch));
+               return false;
+       }
+
+       return true;
+}
+
+static inline bool kgem_bo_can_blt(struct kgem *kgem,
+                                  struct kgem_bo *bo)
+{
+       if (bo->tiling == I915_TILING_Y) {
+               DBG(("%s: can not blt to handle=%d, tiling=Y\n",
+                    __FUNCTION__, bo->handle));
+               return false;
+       }
+
+       return kgem_bo_blt_pitch_is_ok(kgem, bo);
+}
+
+static inline bool kgem_bo_is_mappable(struct kgem *kgem,
+                                      struct kgem_bo *bo)
+{
+       DBG(("%s: domain=%d, offset: %d size: %d\n",
+            __FUNCTION__, bo->domain, bo->presumed_offset, kgem_bo_size(bo)));
+
+       if (bo->domain == DOMAIN_GTT)
+               return true;
+
+       if (kgem->gen < 40 && bo->tiling &&
+           bo->presumed_offset & (kgem_bo_fenced_size(kgem, bo) - 1))
+               return false;
+
+       if (!bo->presumed_offset)
+               return kgem_bo_size(bo) <= kgem->aperture_mappable / 4;
+
+       return bo->presumed_offset + kgem_bo_size(bo) <= kgem->aperture_mappable;
+}
+
+static inline bool kgem_bo_mapped(struct kgem *kgem, struct kgem_bo *bo)
+{
+       DBG(("%s: map=%p, tiling=%d, domain=%d\n",
+            __FUNCTION__, bo->map, bo->tiling, bo->domain));
+
+       if (bo->map == NULL)
+               return bo->tiling == I915_TILING_NONE && bo->domain == DOMAIN_CPU;
+
+       if (bo->tiling == I915_TILING_X && !bo->scanout && kgem->has_llc)
+               return IS_CPU_MAP(bo->map);
+
+       return IS_CPU_MAP(bo->map) == !bo->tiling;
+}
+
+static inline bool kgem_bo_can_map(struct kgem *kgem, struct kgem_bo *bo)
+{
+       if (kgem_bo_mapped(kgem, bo))
+               return true;
+
+       if (!bo->tiling && kgem->has_llc)
+               return true;
+
+       return kgem_bo_size(bo) <= kgem->aperture_mappable / 4;
+}
+
+static inline bool kgem_bo_is_snoop(struct kgem_bo *bo)
+{
+       while (bo->proxy)
+               bo = bo->proxy;
+       return bo->snoop;
+}
+
+static inline bool kgem_bo_is_busy(struct kgem_bo *bo)
+{
+       DBG(("%s: handle=%d, domain: %d exec? %d, rq? %d\n", __FUNCTION__,
+            bo->handle, bo->domain, bo->exec != NULL, bo->rq != NULL));
+       return bo->rq;
+}
+
+static inline bool __kgem_bo_is_busy(struct kgem *kgem, struct kgem_bo *bo)
+{
+       DBG(("%s: handle=%d, domain: %d exec? %d, rq? %d\n", __FUNCTION__,
+            bo->handle, bo->domain, bo->exec != NULL, bo->rq != NULL));
+       if (kgem_flush(kgem))
+               kgem_submit(kgem);
+       if (bo->rq && !bo->exec)
+               kgem_retire(kgem);
+       return kgem_bo_is_busy(bo);
+}
+
+static inline bool kgem_bo_is_dirty(struct kgem_bo *bo)
+{
+       if (bo == NULL)
+               return false;
+
+       return bo->dirty;
+}
+
+static inline void kgem_bo_mark_dirty(struct kgem_bo *bo)
+{
+       do {
+               if (bo->dirty)
+                       return;
+
+               DBG(("%s: handle=%d\n", __FUNCTION__, bo->handle));
+               assert(bo->exec);
+               assert(bo->rq);
+
+               bo->needs_flush = bo->dirty = true;
+               list_move(&bo->request, &bo->rq->buffers);
+       } while ((bo = bo->proxy));
+}
+
+#define KGEM_BUFFER_WRITE      0x1
+#define KGEM_BUFFER_INPLACE    0x2
+#define KGEM_BUFFER_LAST       0x4
+
+#define KGEM_BUFFER_WRITE_INPLACE (KGEM_BUFFER_WRITE | KGEM_BUFFER_INPLACE)
+
+struct kgem_bo *kgem_create_buffer(struct kgem *kgem,
+                                  uint32_t size, uint32_t flags,
+                                  void **ret);
+struct kgem_bo *kgem_create_buffer_2d(struct kgem *kgem,
+                                     int width, int height, int bpp,
+                                     uint32_t flags,
+                                     void **ret);
+bool kgem_buffer_is_inplace(struct kgem_bo *bo);
+void kgem_buffer_read_sync(struct kgem *kgem, struct kgem_bo *bo);
+
+void kgem_throttle(struct kgem *kgem);
+#define MAX_INACTIVE_TIME 10
+bool kgem_expire_cache(struct kgem *kgem);
+void kgem_purge_cache(struct kgem *kgem);
+void kgem_cleanup_cache(struct kgem *kgem);
+
+#if HAS_EXTRA_DEBUG
+void __kgem_batch_debug(struct kgem *kgem, uint32_t nbatch);
+#else
+static inline void __kgem_batch_debug(struct kgem *kgem, uint32_t nbatch)
+{
+       (void)kgem;
+       (void)nbatch;
+}
+#endif
+
+#endif /* KGEM_H */
diff --git a/src/sna/kgem_debug.c b/src/sna/kgem_debug.c
new file mode 100644 (file)
index 0000000..2dc1b45
--- /dev/null
@@ -0,0 +1,424 @@
+/*
+ * Copyright © 2007-2011 Intel 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.
+ *
+ * Authors:
+ *    Eric Anholt <eric@anholt.net>
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/mman.h>
+#include <assert.h>
+
+#include "sna.h"
+#include "sna_reg.h"
+
+#include "kgem_debug.h"
+
+struct drm_i915_gem_relocation_entry *
+kgem_debug_get_reloc_entry(struct kgem *kgem, uint32_t offset)
+{
+       int i;
+
+       offset *= sizeof(uint32_t);
+
+       for (i = 0; i < kgem->nreloc; i++)
+               if (kgem->reloc[i].offset == offset)
+                       return kgem->reloc+i;
+
+       assert(!"valid relocation entry, unknown batch offset");
+       return NULL;
+}
+
+struct kgem_bo *
+kgem_debug_get_bo_for_reloc_entry(struct kgem *kgem,
+                                 struct drm_i915_gem_relocation_entry *reloc)
+{
+       struct kgem_bo *bo;
+
+       if (reloc == NULL)
+               return NULL;
+
+       list_for_each_entry(bo, &kgem->next_request->buffers, request)
+               if (bo->handle == reloc->target_handle && bo->proxy == NULL)
+                       break;
+
+       assert(&bo->request != &kgem->next_request->buffers);
+
+       return bo;
+}
+
+static int kgem_debug_handle_is_fenced(struct kgem *kgem, uint32_t handle)
+{
+       int i;
+
+       for (i = 0; i < kgem->nexec; i++)
+               if (kgem->exec[i].handle == handle)
+                       return kgem->exec[i].flags & EXEC_OBJECT_NEEDS_FENCE;
+
+       return 0;
+}
+
+static int kgem_debug_handle_tiling(struct kgem *kgem, uint32_t handle)
+{
+       struct kgem_bo *bo;
+
+       list_for_each_entry(bo, &kgem->next_request->buffers, request)
+               if (bo->handle == handle)
+                       return bo->tiling;
+
+       return 0;
+}
+
+void
+kgem_debug_print(const uint32_t *data,
+                uint32_t offset, unsigned int index,
+                char *fmt, ...)
+{
+       va_list va;
+       char buf[240];
+       int len;
+
+       len = snprintf(buf, sizeof(buf),
+                      "0x%08x: 0x%08x: %s",
+                      (offset + index) * 4,
+                      data[index],
+                      index == 0 ? "" : "   ");
+
+       va_start(va, fmt);
+       vsnprintf(buf + len, sizeof(buf) - len, fmt, va);
+       va_end(va);
+
+       ErrorF("%s", buf);
+}
+
+static int
+decode_nop(struct kgem *kgem, uint32_t offset)
+{
+       uint32_t *data = kgem->batch + offset;
+       kgem_debug_print(data, offset, 0, "UNKNOWN\n");
+       assert(0);
+       return 1;
+}
+
+static int
+decode_mi(struct kgem *kgem, uint32_t offset)
+{
+       static const struct {
+               uint32_t opcode;
+               int len_mask;
+               int min_len;
+               int max_len;
+               const char *name;
+       } opcodes[] = {
+               { 0x08, 0, 1, 1, "MI_ARB_ON_OFF" },
+               { 0x0a, 0, 1, 1, "MI_BATCH_BUFFER_END" },
+               { 0x30, 0x3f, 3, 3, "MI_BATCH_BUFFER" },
+               { 0x31, 0x3f, 2, 2, "MI_BATCH_BUFFER_START" },
+               { 0x14, 0x3f, 3, 3, "MI_DISPLAY_BUFFER_INFO" },
+               { 0x04, 0, 1, 1, "MI_FLUSH" },
+               { 0x22, 0x1f, 3, 3, "MI_LOAD_REGISTER_IMM" },
+               { 0x13, 0x3f, 2, 2, "MI_LOAD_SCAN_LINES_EXCL" },
+               { 0x12, 0x3f, 2, 2, "MI_LOAD_SCAN_LINES_INCL" },
+               { 0x00, 0, 1, 1, "MI_NOOP" },
+               { 0x11, 0x3f, 2, 2, "MI_OVERLAY_FLIP" },
+               { 0x07, 0, 1, 1, "MI_REPORT_HEAD" },
+               { 0x18, 0x3f, 2, 2, "MI_SET_CONTEXT" },
+               { 0x20, 0x3f, 3, 4, "MI_STORE_DATA_IMM" },
+               { 0x21, 0x3f, 3, 4, "MI_STORE_DATA_INDEX" },
+               { 0x24, 0x3f, 3, 3, "MI_STORE_REGISTER_MEM" },
+               { 0x02, 0, 1, 1, "MI_USER_INTERRUPT" },
+               { 0x03, 0, 1, 1, "MI_WAIT_FOR_EVENT" },
+               { 0x16, 0x7f, 3, 3, "MI_SEMAPHORE_MBOX" },
+               { 0x26, 0x1f, 3, 4, "MI_FLUSH_DW" },
+               { 0x0b, 0, 1, 1, "MI_SUSPEND_FLUSH" },
+       };
+       uint32_t *data = kgem->batch + offset;
+       int op;
+
+       for (op = 0; op < ARRAY_SIZE(opcodes); op++) {
+               if ((data[0] & 0x1f800000) >> 23 == opcodes[op].opcode) {
+                       unsigned int len = 1, i;
+
+                       kgem_debug_print(data, offset, 0, "%s\n", opcodes[op].name);
+                       if (opcodes[op].max_len > 1) {
+                               len = (data[0] & opcodes[op].len_mask) + 2;
+                               if (len < opcodes[op].min_len ||
+                                   len > opcodes[op].max_len)
+                               {
+                                       ErrorF("Bad length (%d) in %s, [%d, %d]\n",
+                                              len, opcodes[op].name,
+                                              opcodes[op].min_len,
+                                              opcodes[op].max_len);
+                                       assert(0);
+                               }
+                       }
+
+                       for (i = 1; i < len; i++)
+                               kgem_debug_print(data, offset, i, "dword %d\n", i);
+
+                       return len;
+               }
+       }
+
+       kgem_debug_print(data, offset, 0, "MI UNKNOWN\n");
+       assert(0);
+       return 1;
+}
+
+static int
+decode_2d(struct kgem *kgem, uint32_t offset)
+{
+       static const struct {
+               uint32_t opcode;
+               int min_len;
+               int max_len;
+               const char *name;
+       } opcodes[] = {
+               { 0x40, 5, 5, "COLOR_BLT" },
+               { 0x43, 6, 6, "SRC_COPY_BLT" },
+               { 0x01, 8, 8, "XY_SETUP_BLT" },
+               { 0x11, 9, 9, "XY_SETUP_MONO_PATTERN_SL_BLT" },
+               { 0x03, 3, 3, "XY_SETUP_CLIP_BLT" },
+               { 0x24, 2, 2, "XY_PIXEL_BLT" },
+               { 0x25, 3, 3, "XY_SCANLINES_BLT" },
+               { 0x26, 4, 4, "Y_TEXT_BLT" },
+               { 0x31, 5, 134, "XY_TEXT_IMMEDIATE_BLT" },
+               { 0x50, 6, 6, "XY_COLOR_BLT" },
+               { 0x51, 6, 6, "XY_PAT_BLT" },
+               { 0x76, 8, 8, "XY_PAT_CHROMA_BLT" },
+               { 0x72, 7, 135, "XY_PAT_BLT_IMMEDIATE" },
+               { 0x77, 9, 137, "XY_PAT_CHROMA_BLT_IMMEDIATE" },
+               { 0x52, 9, 9, "XY_MONO_PAT_BLT" },
+               { 0x59, 7, 7, "XY_MONO_PAT_FIXED_BLT" },
+               { 0x53, 8, 8, "XY_SRC_COPY_BLT" },
+               { 0x54, 8, 8, "XY_MONO_SRC_COPY_BLT" },
+               { 0x71, 9, 137, "XY_MONO_SRC_COPY_IMMEDIATE_BLT" },
+               { 0x55, 9, 9, "XY_FULL_BLT" },
+               { 0x55, 9, 137, "XY_FULL_IMMEDIATE_PATTERN_BLT" },
+               { 0x56, 9, 9, "XY_FULL_MONO_SRC_BLT" },
+               { 0x75, 10, 138, "XY_FULL_MONO_SRC_IMMEDIATE_PATTERN_BLT" },
+               { 0x57, 12, 12, "XY_FULL_MONO_PATTERN_BLT" },
+               { 0x58, 12, 12, "XY_FULL_MONO_PATTERN_MONO_SRC_BLT" },
+       };
+
+       unsigned int op, len;
+       const char *format = NULL;
+       uint32_t *data = kgem->batch + offset;
+       struct drm_i915_gem_relocation_entry *reloc;
+
+       /* Special case the two most common ops that we detail in full */
+       switch ((data[0] & 0x1fc00000) >> 22) {
+       case 0x50:
+               kgem_debug_print(data, offset, 0,
+                         "XY_COLOR_BLT (rgb %sabled, alpha %sabled, dst tile %d)\n",
+                         (data[0] & (1 << 20)) ? "en" : "dis",
+                         (data[0] & (1 << 21)) ? "en" : "dis",
+                         (data[0] >> 11) & 1);
+
+               len = (data[0] & 0x000000ff) + 2;
+               assert(len == 6);
+
+               switch ((data[1] >> 24) & 0x3) {
+               case 0:
+                       format="8";
+                       break;
+               case 1:
+                       format="565";
+                       break;
+               case 2:
+                       format="1555";
+                       break;
+               case 3:
+                       format="8888";
+                       break;
+               }
+
+               kgem_debug_print(data, offset, 1, "format %s, rop %x, pitch %d, "
+                         "clipping %sabled\n", format,
+                         (data[1] >> 16) & 0xff,
+                         (short)(data[1] & 0xffff),
+                         data[1] & (1 << 30) ? "en" : "dis");
+               kgem_debug_print(data, offset, 2, "(%d,%d)\n",
+                         data[2] & 0xffff, data[2] >> 16);
+               kgem_debug_print(data, offset, 3, "(%d,%d)\n",
+                         data[3] & 0xffff, data[3] >> 16);
+               reloc = kgem_debug_get_reloc_entry(kgem, offset+4);
+               kgem_debug_print(data, offset, 4, "dst offset 0x%08x [handle=%d, delta=%d, read=%x, write=%x (fenced? %d, tiling? %d)]\n",
+                                data[4],
+                                reloc->target_handle, reloc->delta,
+                                reloc->read_domains, reloc->write_domain,
+                                kgem_debug_handle_is_fenced(kgem, reloc->target_handle),
+                                kgem_debug_handle_tiling(kgem, reloc->target_handle));
+               kgem_debug_print(data, offset, 5, "color\n");
+               assert(kgem->gen >= 40 ||
+                      kgem_debug_handle_is_fenced(kgem, reloc->target_handle));
+               return len;
+
+       case 0x53:
+               kgem_debug_print(data, offset, 0,
+                         "XY_SRC_COPY_BLT (rgb %sabled, alpha %sabled, "
+                         "src tile %d, dst tile %d)\n",
+                         (data[0] & (1 << 20)) ? "en" : "dis",
+                         (data[0] & (1 << 21)) ? "en" : "dis",
+                         (data[0] >> 15) & 1,
+                         (data[0] >> 11) & 1);
+
+               len = (data[0] & 0x000000ff) + 2;
+               assert(len == 8);
+
+               switch ((data[1] >> 24) & 0x3) {
+               case 0:
+                       format="8";
+                       break;
+               case 1:
+                       format="565";
+                       break;
+               case 2:
+                       format="1555";
+                       break;
+               case 3:
+                       format="8888";
+                       break;
+               }
+
+               kgem_debug_print(data, offset, 1, "format %s, rop %x, dst pitch %d, "
+                                "clipping %sabled\n", format,
+                                (data[1] >> 16) & 0xff,
+                                (short)(data[1] & 0xffff),
+                                data[1] & (1 << 30) ? "en" : "dis");
+               kgem_debug_print(data, offset, 2, "dst (%d,%d)\n",
+                                data[2] & 0xffff, data[2] >> 16);
+               kgem_debug_print(data, offset, 3, "dst (%d,%d)\n",
+                                data[3] & 0xffff, data[3] >> 16);
+               reloc = kgem_debug_get_reloc_entry(kgem, offset+4);
+               assert(reloc);
+               kgem_debug_print(data, offset, 4, "dst offset 0x%08x [handle=%d, delta=%d, read=%x, write=%x, (fenced? %d, tiling? %d)]\n",
+                                data[4],
+                                reloc->target_handle, reloc->delta,
+                                reloc->read_domains, reloc->write_domain,
+                                kgem_debug_handle_is_fenced(kgem, reloc->target_handle),
+                                kgem_debug_handle_tiling(kgem, reloc->target_handle));
+               assert(kgem->gen >= 40 ||
+                      kgem_debug_handle_is_fenced(kgem, reloc->target_handle));
+
+               kgem_debug_print(data, offset, 5, "src (%d,%d)\n",
+                                data[5] & 0xffff, data[5] >> 16);
+               kgem_debug_print(data, offset, 6, "src pitch %d\n",
+                                (short)(data[6] & 0xffff));
+               reloc = kgem_debug_get_reloc_entry(kgem, offset+7);
+               assert(reloc);
+               kgem_debug_print(data, offset, 7, "src offset 0x%08x [handle=%d, delta=%d, read=%x, write=%x (fenced? %d, tiling? %d)]\n",
+                                data[7],
+                                reloc->target_handle, reloc->delta,
+                                reloc->read_domains, reloc->write_domain,
+                                kgem_debug_handle_is_fenced(kgem, reloc->target_handle),
+                                kgem_debug_handle_tiling(kgem, reloc->target_handle));
+               assert(kgem->gen >= 40 ||
+                      kgem_debug_handle_is_fenced(kgem, reloc->target_handle));
+
+               return len;
+       }
+
+       for (op = 0; op < ARRAY_SIZE(opcodes); op++) {
+               if ((data[0] & 0x1fc00000) >> 22 == opcodes[op].opcode) {
+                       unsigned int i;
+
+                       len = 1;
+                       kgem_debug_print(data, offset, 0, "%s\n", opcodes[op].name);
+                       if (opcodes[op].max_len > 1) {
+                               len = (data[0] & 0x000000ff) + 2;
+                               assert(len >= opcodes[op].min_len &&
+                                      len <= opcodes[op].max_len);
+                       }
+
+                       for (i = 1; i < len; i++)
+                               kgem_debug_print(data, offset, i, "dword %d\n", i);
+
+                       return len;
+               }
+       }
+
+       kgem_debug_print(data, offset, 0, "2D UNKNOWN\n");
+       assert(0);
+       return 1;
+}
+
+static int (*decode_3d(int gen))(struct kgem*, uint32_t)
+{
+       if (gen >= 80) {
+       } else if (gen >= 70) {
+               return kgem_gen7_decode_3d;
+       } else if (gen >= 60) {
+               return kgem_gen6_decode_3d;
+       } else if (gen >= 50) {
+               return kgem_gen5_decode_3d;
+       } else if (gen >= 40) {
+               return kgem_gen4_decode_3d;
+       } else if (gen >= 30) {
+               return kgem_gen3_decode_3d;
+       } else if (gen >= 20) {
+               return kgem_gen2_decode_3d;
+       }
+       assert(0);
+}
+
+static void (*finish_state(int gen))(struct kgem*)
+{
+       if (gen >= 80) {
+       } else if (gen >= 70) {
+               return kgem_gen7_finish_state;
+       } else if (gen >= 60) {
+               return kgem_gen6_finish_state;
+       } else if (gen >= 50) {
+               return kgem_gen5_finish_state;
+       } else if (gen >= 40) {
+               return kgem_gen4_finish_state;
+       } else if (gen >= 30) {
+               return kgem_gen3_finish_state;
+       } else if (gen >= 20) {
+               return kgem_gen2_finish_state;
+       }
+       assert(0);
+}
+
+void __kgem_batch_debug(struct kgem *kgem, uint32_t nbatch)
+{
+       int (*const decode[])(struct kgem *, uint32_t) = {
+               decode_mi,
+               decode_nop,
+               decode_2d,
+               decode_3d(kgem->gen),
+       };
+       uint32_t offset = 0;
+
+       while (offset < nbatch) {
+               int class = (kgem->batch[offset] & 0xe0000000) >> 29;
+               assert(class < ARRAY_SIZE(decode));
+               offset += decode[class](kgem, offset);
+       }
+
+       finish_state(kgem->gen)(kgem);
+}
diff --git a/src/sna/kgem_debug.h b/src/sna/kgem_debug.h
new file mode 100644 (file)
index 0000000..82d6f66
--- /dev/null
@@ -0,0 +1,34 @@
+#ifndef KGEM_DEBUG_H
+#define KGEM_DEBUG_H
+
+void
+kgem_debug_print(const uint32_t *data,
+                uint32_t offset, unsigned int index,
+                char *fmt, ...);
+
+struct drm_i915_gem_relocation_entry *
+kgem_debug_get_reloc_entry(struct kgem *kgem, uint32_t offset);
+
+struct kgem_bo *
+kgem_debug_get_bo_for_reloc_entry(struct kgem *kgem,
+                                 struct drm_i915_gem_relocation_entry *reloc);
+
+int kgem_gen7_decode_3d(struct kgem *kgem, uint32_t offset);
+void kgem_gen7_finish_state(struct kgem *kgem);
+
+int kgem_gen6_decode_3d(struct kgem *kgem, uint32_t offset);
+void kgem_gen6_finish_state(struct kgem *kgem);
+
+int kgem_gen5_decode_3d(struct kgem *kgem, uint32_t offset);
+void kgem_gen5_finish_state(struct kgem *kgem);
+
+int kgem_gen4_decode_3d(struct kgem *kgem, uint32_t offset);
+void kgem_gen4_finish_state(struct kgem *kgem);
+
+int kgem_gen3_decode_3d(struct kgem *kgem, uint32_t offset);
+void kgem_gen3_finish_state(struct kgem *kgem);
+
+int kgem_gen2_decode_3d(struct kgem *kgem, uint32_t offset);
+void kgem_gen2_finish_state(struct kgem *kgem);
+
+#endif
diff --git a/src/sna/kgem_debug_gen2.c b/src/sna/kgem_debug_gen2.c
new file mode 100644 (file)
index 0000000..09f3873
--- /dev/null
@@ -0,0 +1,687 @@
+/*
+ * Copyright © 2007-2011 Intel 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.
+ *
+ * Authors:
+ *    Eric Anholt <eric@anholt.net>
+ *    Chris Wilson <chris@chris-wilson.co.uk>
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/mman.h>
+#include <assert.h>
+
+#include "sna.h"
+#include "sna_reg.h"
+
+#include "gen2_render.h"
+
+#include "kgem_debug.h"
+
+static struct state {
+       int vertex_format;
+} state;
+
+static inline float int_as_float(uint32_t dw)
+{
+       union {
+               float f;
+               uint32_t dw;
+       } u;
+       u.dw = dw;
+       return u.f;
+}
+
+static int
+decode_3d_primitive(struct kgem *kgem, uint32_t offset)
+{
+    uint32_t *data = kgem->batch + offset;
+    char immediate = (data[0] & (1 << 23)) == 0;
+    unsigned int len;
+    const char *primtype;
+
+    switch ((data[0] >> 18) & 0xf) {
+    case 0x0: primtype = "TRILIST"; break;
+    case 0x1: primtype = "TRISTRIP"; break;
+    case 0x2: primtype = "TRISTRIP_REVERSE"; break;
+    case 0x3: primtype = "TRIFAN"; break;
+    case 0x4: primtype = "POLYGON"; break;
+    case 0x5: primtype = "LINELIST"; break;
+    case 0x6: primtype = "LINESTRIP"; break;
+    case 0x7: primtype = "RECTLIST"; break;
+    case 0x8: primtype = "POINTLIST"; break;
+    case 0x9: primtype = "DIB"; break;
+    case 0xa: primtype = "CLEAR_RECT"; break;
+    default: primtype = "unknown"; break;
+    }
+
+    /* XXX: 3DPRIM_DIB not supported */
+    if (immediate) {
+       len = (data[0] & 0x0003ffff) + 2;
+       kgem_debug_print(data, offset, 0, "3DPRIMITIVE inline %s\n", primtype);
+#if 0
+       if (!saved_s2_set || !saved_s4_set) {
+           fprintf(out, "unknown vertex format\n");
+           for (i = 1; i < len; i++) {
+               kgem_debug_print(data, offset, i,
+                         "           vertex data (%f float)\n",
+                         int_as_float(data[i]));
+           }
+       } else {
+           unsigned int vertex = 0;
+           for (i = 1; i < len;) {
+               unsigned int tc;
+
+#define VERTEX_OUT(fmt, ...) do {                                      \
+    if (i < len)                                                       \
+       kgem_debug_print(data, offset, i, " V%d."fmt"\n", vertex, __VA_ARGS__); \
+    else                                                               \
+       fprintf(out, " missing data in V%d\n", vertex);                 \
+    i++;                                                               \
+} while (0)
+
+               VERTEX_OUT("X = %f", int_as_float(data[i]));
+               VERTEX_OUT("Y = %f", int_as_float(data[i]));
+               switch (saved_s4 >> 6 & 0x7) {
+               case 0x1:
+                   VERTEX_OUT("Z = %f", int_as_float(data[i]));
+                   break;
+               case 0x2:
+                   VERTEX_OUT("Z = %f", int_as_float(data[i]));
+                   VERTEX_OUT("W = %f", int_as_float(data[i]));
+                   break;
+               case 0x3:
+                   break;
+               case 0x4:
+                   VERTEX_OUT("W = %f", int_as_float(data[i]));
+                   break;
+               default:
+                   fprintf(out, "bad S4 position mask\n");
+               }
+
+               if (saved_s4 & (1 << 10)) {
+                   VERTEX_OUT("color = (A=0x%02x, R=0x%02x, G=0x%02x, "
+                              "B=0x%02x)",
+                              data[i] >> 24,
+                              (data[i] >> 16) & 0xff,
+                              (data[i] >> 8) & 0xff,
+                              data[i] & 0xff);
+               }
+               if (saved_s4 & (1 << 11)) {
+                   VERTEX_OUT("spec = (A=0x%02x, R=0x%02x, G=0x%02x, "
+                              "B=0x%02x)",
+                              data[i] >> 24,
+                              (data[i] >> 16) & 0xff,
+                              (data[i] >> 8) & 0xff,
+                              data[i] & 0xff);
+               }
+               if (saved_s4 & (1 << 12))
+                   VERTEX_OUT("width = 0x%08x)", data[i]);
+
+               for (tc = 0; tc <= 7; tc++) {
+                   switch ((saved_s2 >> (tc * 4)) & 0xf) {
+                   case 0x0:
+                       VERTEX_OUT("T%d.X = %f", tc, int_as_float(data[i]));
+                       VERTEX_OUT("T%d.Y = %f", tc, int_as_float(data[i]));
+                       break;
+                   case 0x1:
+                       VERTEX_OUT("T%d.X = %f", tc, int_as_float(data[i]));
+                       VERTEX_OUT("T%d.Y = %f", tc, int_as_float(data[i]));
+                       VERTEX_OUT("T%d.Z = %f", tc, int_as_float(data[i]));
+                       break;
+                   case 0x2:
+                       VERTEX_OUT("T%d.X = %f", tc, int_as_float(data[i]));
+                       VERTEX_OUT("T%d.Y = %f", tc, int_as_float(data[i]));
+                       VERTEX_OUT("T%d.Z = %f", tc, int_as_float(data[i]));
+                       VERTEX_OUT("T%d.W = %f", tc, int_as_float(data[i]));
+                       break;
+                   case 0x3:
+                       VERTEX_OUT("T%d.X = %f", tc, int_as_float(data[i]));
+                       break;
+                   case 0x4:
+                       VERTEX_OUT("T%d.XY = 0x%08x half-float", tc, data[i]);
+                       break;
+                   case 0x5:
+                       VERTEX_OUT("T%d.XY = 0x%08x half-float", tc, data[i]);
+                       VERTEX_OUT("T%d.ZW = 0x%08x half-float", tc, data[i]);
+                       break;
+                   case 0xf:
+                       break;
+                   default:
+                       fprintf(out, "bad S2.T%d format\n", tc);
+                   }
+               }
+               vertex++;
+           }
+       }
+#endif
+    } else {
+       /* indirect vertices */
+       len = data[0] & 0x0000ffff; /* index count */
+#if 0
+       if (data[0] & (1 << 17)) {
+           /* random vertex access */
+           kgem_debug_print(data, offset, 0,
+                     "3DPRIMITIVE random indirect %s (%d)\n", primtype, len);
+           if (len == 0) {
+               /* vertex indices continue until 0xffff is found */
+               for (i = 1; i < count; i++) {
+                   if ((data[i] & 0xffff) == 0xffff) {
+                       kgem_debug_print(data, offset, i,
+                                 "    indices: (terminator)\n");
+                       ret = i;
+                       goto out;
+                   } else if ((data[i] >> 16) == 0xffff) {
+                       kgem_debug_print(data, offset, i,
+                                 "    indices: 0x%04x, (terminator)\n",
+                                 data[i] & 0xffff);
+                       ret = i;
+                       goto out;
+                   } else {
+                       kgem_debug_print(data, offset, i,
+                                 "    indices: 0x%04x, 0x%04x\n",
+                                 data[i] & 0xffff, data[i] >> 16);
+                   }
+               }
+               fprintf(out,
+                       "3DPRIMITIVE: no terminator found in index buffer\n");
+               ret = count;
+               goto out;
+           } else {
+               /* fixed size vertex index buffer */
+               for (j = 1, i = 0; i < len; i += 2, j++) {
+                   if (i * 2 == len - 1) {
+                       kgem_debug_print(data, offset, j,
+                                 "    indices: 0x%04x\n",
+                                 data[j] & 0xffff);
+                   } else {
+                       kgem_debug_print(data, offset, j,
+                                 "    indices: 0x%04x, 0x%04x\n",
+                                 data[j] & 0xffff, data[j] >> 16);
+                   }
+               }
+           }
+           ret = (len + 1) / 2 + 1;
+           goto out;
+       } else {
+           /* sequential vertex access */
+           kgem_debug_print(data, offset, 0,
+                     "3DPRIMITIVE sequential indirect %s, %d starting from "
+                     "%d\n", primtype, len, data[1] & 0xffff);
+           kgem_debug_print(data, offset, 1, "           start\n");
+           ret = 2;
+           goto out;
+       }
+#endif
+    }
+
+    return len;
+}
+
+static int
+decode_3d_1d(struct kgem *kgem, uint32_t offset)
+{
+    uint32_t *data = kgem->batch + offset;
+    unsigned int len, i, idx, word, map;
+    const char *format, *zformat, *type;
+    uint32_t opcode;
+
+    static const struct {
+       uint32_t opcode;
+       int min_len;
+       int max_len;
+       const char *name;
+    } opcodes_3d_1d[] = {
+       { 0x86, 4, 4, "3DSTATE_CHROMA_KEY" },
+       { 0x88, 2, 2, "3DSTATE_CONSTANT_BLEND_COLOR" },
+       { 0x99, 2, 2, "3DSTATE_DEFAULT_DIFFUSE" },
+       { 0x9a, 2, 2, "3DSTATE_DEFAULT_SPECULAR" },
+       { 0x98, 2, 2, "3DSTATE_DEFAULT_Z" },
+       { 0x97, 2, 2, "3DSTATE_DEPTH_OFFSET_SCALE" },
+       { 0x9d, 65, 65, "3DSTATE_FILTER_COEFFICIENTS_4X4" },
+       { 0x9e, 4, 4, "3DSTATE_MONO_FILTER" },
+       { 0x89, 4, 4, "3DSTATE_FOG_MODE" },
+       { 0x8f, 2, 16, "3DSTATE_MAP_PALLETE_LOAD_32" },
+       { 0x83, 2, 2, "3DSTATE_SPAN_STIPPLE" },
+       { 0x8c, 2, 2, "3DSTATE_MAP_COORD_TRANSFORM" },
+       { 0x8b, 2, 2, "3DSTATE_MAP_VERTEX_TRANSFORM" },
+       { 0x8d, 3, 3, "3DSTATE_W_STATE" },
+       { 0x01, 2, 2, "3DSTATE_COLOR_FACTOR" },
+       { 0x02, 2, 2, "3DSTATE_MAP_COORD_SETBIND" },
+    }, *opcode_3d_1d;
+
+    opcode = (data[0] & 0x00ff0000) >> 16;
+
+    switch (opcode) {
+    case 0x07:
+       /* This instruction is unusual.  A 0 length means just 1 DWORD instead of
+        * 2.  The 0 length is specified in one place to be unsupported, but
+        * stated to be required in another, and 0 length LOAD_INDIRECTs appear
+        * to cause no harm at least.
+        */
+       kgem_debug_print(data, offset, 0, "3DSTATE_LOAD_INDIRECT\n");
+       len = (data[0] & 0x000000ff) + 1;
+       i = 1;
+       if (data[0] & (0x01 << 8)) {
+           kgem_debug_print(data, offset, i++, "SIS.0\n");
+           kgem_debug_print(data, offset, i++, "SIS.1\n");
+       }
+       if (data[0] & (0x02 << 8)) {
+           kgem_debug_print(data, offset, i++, "DIS.0\n");
+       }
+       if (data[0] & (0x04 << 8)) {
+           kgem_debug_print(data, offset, i++, "SSB.0\n");
+           kgem_debug_print(data, offset, i++, "SSB.1\n");
+       }
+       if (data[0] & (0x08 << 8)) {
+           kgem_debug_print(data, offset, i++, "MSB.0\n");
+           kgem_debug_print(data, offset, i++, "MSB.1\n");
+       }
+       if (data[0] & (0x10 << 8)) {
+           kgem_debug_print(data, offset, i++, "PSP.0\n");
+           kgem_debug_print(data, offset, i++, "PSP.1\n");
+       }
+       if (data[0] & (0x20 << 8)) {
+           kgem_debug_print(data, offset, i++, "PSC.0\n");
+           kgem_debug_print(data, offset, i++, "PSC.1\n");
+       }
+       assert(len == i);
+       return len;
+    case 0x04:
+       kgem_debug_print(data, offset, 0, "3DSTATE_LOAD_STATE_IMMEDIATE_1\n");
+       len = (data[0] & 0x0000000f) + 2;
+       i = 1;
+       for (word = 0; word <= 8; word++) {
+           if (data[0] & (1 << (4 + word))) {
+               kgem_debug_print(data, offset, i, "S%d: 0x%08x\n", i, data[i]);
+               i++;
+           }
+       }
+       assert (len ==i);
+       return len;
+    case 0x03:
+       kgem_debug_print(data, offset, 0, "3DSTATE_LOAD_STATE_IMMEDIATE_2\n");
+       len = (data[0] & 0x0000000f) + 2;
+       i = 1;
+       for (word = 6; word <= 14; word++) {
+           if (data[0] & (1 << word)) {
+               if (word == 6)
+                   kgem_debug_print(data, offset, i++, "TBCF\n");
+               else if (word >= 7 && word <= 10) {
+                   kgem_debug_print(data, offset, i++, "TB%dC\n", word - 7);
+                   kgem_debug_print(data, offset, i++, "TB%dA\n", word - 7);
+               } else if (word >= 11 && word <= 14) {
+                   kgem_debug_print(data, offset, i, "TM%dS0: offset=0x%08x, %s\n",
+                             word - 11,
+                             data[i]&0xfffffffe,
+                             data[i]&1?"use fence":"");
+                   i++;
+                   kgem_debug_print(data, offset, i, "TM%dS1: height=%i, width=%i, %s\n",
+                             word - 11,
+                             data[i]>>21, (data[i]>>10)&0x3ff,
+                             data[i]&2?(data[i]&1?"y-tiled":"x-tiled"):"");
+                   i++;
+                   kgem_debug_print(data, offset, i, "TM%dS2: pitch=%i, \n",
+                             word - 11,
+                             ((data[i]>>21) + 1)*4);
+                   i++;
+                   kgem_debug_print(data, offset, i++, "TM%dS3\n", word - 11);
+                   kgem_debug_print(data, offset, i++, "TM%dS4: dflt color\n", word - 11);
+               }
+           }
+       }
+       assert (len == i);
+       return len;
+    case 0x00:
+       kgem_debug_print(data, offset, 0, "3DSTATE_MAP_STATE\n");
+       len = (data[0] & 0x0000003f) + 2;
+       kgem_debug_print(data, offset, 1, "mask\n");
+
+       i = 2;
+       for (map = 0; map <= 15; map++) {
+           if (data[1] & (1 << map)) {
+               int width, height, pitch, dword;
+               const char *tiling;
+
+               dword = data[i];
+               kgem_debug_print(data, offset, i++, "map %d MS2 %s%s%s\n", map,
+                         dword&(1<<31)?"untrusted surface, ":"",
+                         dword&(1<<1)?"vertical line stride enable, ":"",
+                         dword&(1<<0)?"vertical ofs enable, ":"");
+
+               dword = data[i];
+               width = ((dword >> 10) & ((1 << 11) - 1))+1;
+               height = ((dword >> 21) & ((1 << 11) - 1))+1;
+
+               tiling = "none";
+               if (dword & (1 << 2))
+                       tiling = "fenced";
+               else if (dword & (1 << 1))
+                       tiling = dword & (1 << 0) ? "Y" : "X";
+               type = " BAD";
+               format = "BAD";
+               switch ((dword>>7) & 0x7) {
+               case 1:
+                   type = "8b";
+                   switch ((dword>>3) & 0xf) {
+                   case 0: format = "I"; break;
+                   case 1: format = "L"; break;
+                   case 2: format = "A"; break;
+                   case 3: format = " mono"; break; }
+                   break;
+               case 2:
+                   type = "16b";
+                   switch ((dword>>3) & 0xf) {
+                   case 0: format = " rgb565"; break;
+                   case 1: format = " argb1555"; break;
+                   case 2: format = " argb4444"; break;
+                   case 5: format = " ay88"; break;
+                   case 6: format = " bump655"; break;
+                   case 7: format = "I"; break;
+                   case 8: format = "L"; break;
+                   case 9: format = "A"; break; }
+                   break;
+               case 3:
+                   type = "32b";
+                   switch ((dword>>3) & 0xf) {
+                   case 0: format = " argb8888"; break;
+                   case 1: format = " abgr8888"; break;
+                   case 2: format = " xrgb8888"; break;
+                   case 3: format = " xbgr8888"; break;
+                   case 4: format = " qwvu8888"; break;
+                   case 5: format = " axvu8888"; break;
+                   case 6: format = " lxvu8888"; break;
+                   case 7: format = " xlvu8888"; break;
+                   case 8: format = " argb2101010"; break;
+                   case 9: format = " abgr2101010"; break;
+                   case 10: format = " awvu2101010"; break;
+                   case 11: format = " gr1616"; break;
+                   case 12: format = " vu1616"; break;
+                   case 13: format = " xI824"; break;
+                   case 14: format = " xA824"; break;
+                   case 15: format = " xL824"; break; }
+                   break;
+               case 5:
+                   type = "422";
+                   switch ((dword>>3) & 0xf) {
+                   case 0: format = " yuv_swapy"; break;
+                   case 1: format = " yuv"; break;
+                   case 2: format = " yuv_swapuv"; break;
+                   case 3: format = " yuv_swapuvy"; break; }
+                   break;
+               case 6:
+                   type = "compressed";
+                   switch ((dword>>3) & 0x7) {
+                   case 0: format = " dxt1"; break;
+                   case 1: format = " dxt2_3"; break;
+                   case 2: format = " dxt4_5"; break;
+                   case 3: format = " fxt1"; break;
+                   case 4: format = " dxt1_rb"; break; }
+                   break;
+               case 7:
+                   type = "4b indexed";
+                   switch ((dword>>3) & 0xf) {
+                   case 7: format = " argb8888"; break; }
+                   break;
+               }
+               dword = data[i];
+               kgem_debug_print(data, offset, i++, "map %d MS3 [width=%d, height=%d, format=%s%s, tiling=%s%s]\n",
+                         map, width, height, type, format, tiling,
+                         dword&(1<<9)?" palette select":"");
+
+               dword = data[i];
+               pitch = 4*(((dword >> 21) & ((1 << 11) - 1))+1);
+               kgem_debug_print(data, offset, i++, "map %d MS4 [pitch=%d, max_lod=%i, vol_depth=%i, cube_face_ena=%x, %s]\n",
+                         map, pitch,
+                         (dword>>9)&0x3f, dword&0xff, (dword>>15)&0x3f,
+                         dword&(1<<8)?"miplayout legacy":"miplayout right");
+           }
+       }
+       assert (len == i);
+       return len;
+    case 0x85:
+       len = (data[0] & 0x0000000f) + 2;
+       assert (len == 2);
+       kgem_debug_print(data, offset, 0,
+                 "3DSTATE_DEST_BUFFER_VARIABLES\n");
+
+       switch ((data[1] >> 8) & 0xf) {
+       case 0x0: format = "g8"; break;
+       case 0x1: format = "x1r5g5b5"; break;
+       case 0x2: format = "r5g6b5"; break;
+       case 0x3: format = "a8r8g8b8"; break;
+       case 0x4: format = "ycrcb_swapy"; break;
+       case 0x5: format = "ycrcb_normal"; break;
+       case 0x6: format = "ycrcb_swapuv"; break;
+       case 0x7: format = "ycrcb_swapuvy"; break;
+       case 0x8: format = "a4r4g4b4"; break;
+       case 0x9: format = "a1r5g5b5"; break;
+       case 0xa: format = "a2r10g10b10"; break;
+       default: format = "BAD"; break;
+       }
+       switch ((data[1] >> 2) & 0x3) {
+       case 0x0: zformat = "u16"; break;
+       case 0x1: zformat = "f16"; break;
+       case 0x2: zformat = "u24x8"; break;
+       default: zformat = "BAD"; break;
+       }
+       kgem_debug_print(data, offset, 1, "%s format, %s depth format, early Z %sabled\n",
+                 format, zformat,
+                 (data[1] & (1 << 31)) ? "en" : "dis");
+       return len;
+
+    case 0x8e:
+       {
+           const char *name, *tiling;
+
+           len = (data[0] & 0x0000000f) + 2;
+           assert (len == 3);
+
+           switch((data[1] >> 24) & 0x7) {
+           case 0x3: name = "color"; break;
+           case 0x7: name = "depth"; break;
+           default: name = "unknown"; break;
+           }
+
+           tiling = "none";
+           if (data[1] & (1 << 23))
+               tiling = "fenced";
+           else if (data[1] & (1 << 22))
+               tiling = data[1] & (1 << 21) ? "Y" : "X";
+
+           kgem_debug_print(data, offset, 0, "3DSTATE_BUFFER_INFO\n");
+           kgem_debug_print(data, offset, 1, "%s, tiling = %s, pitch=%d\n", name, tiling, data[1]&0xffff);
+
+           kgem_debug_print(data, offset, 2, "address\n");
+           return len;
+       }
+
+    case 0x81:
+       len = (data[0] & 0x0000000f) + 2;
+       assert (len == 3);
+
+       kgem_debug_print(data, offset, 0,
+                 "3DSTATE_SCISSOR_RECTANGLE\n");
+       kgem_debug_print(data, offset, 1, "(%d,%d)\n",
+                 data[1] & 0xffff, data[1] >> 16);
+       kgem_debug_print(data, offset, 2, "(%d,%d)\n",
+                 data[2] & 0xffff, data[2] >> 16);
+       return len;
+
+    case 0x80:
+       len = (data[0] & 0x0000000f) + 2;
+       assert (len == 5);
+
+       kgem_debug_print(data, offset, 0,
+                 "3DSTATE_DRAWING_RECTANGLE\n");
+       kgem_debug_print(data, offset, 1, "%s\n",
+                 data[1]&(1<<30)?"depth ofs disabled ":"");
+       kgem_debug_print(data, offset, 2, "(%d,%d)\n",
+                 data[2] & 0xffff, data[2] >> 16);
+       kgem_debug_print(data, offset, 3, "(%d,%d)\n",
+                 data[3] & 0xffff, data[3] >> 16);
+       kgem_debug_print(data, offset, 4, "(%d,%d)\n",
+                 data[4] & 0xffff, data[4] >> 16);
+       return len;
+
+    case 0x9c:
+       len = (data[0] & 0x0000000f) + 2;
+       assert (len == 7);
+
+       kgem_debug_print(data, offset, 0,
+                 "3DSTATE_CLEAR_PARAMETERS\n");
+       kgem_debug_print(data, offset, 1, "prim_type=%s, clear=%s%s%s\n",
+                 data[1]&(1<<16)?"CLEAR_RECT":"ZONE_INIT",
+                 data[1]&(1<<2)?"color,":"",
+                 data[1]&(1<<1)?"depth,":"",
+                 data[1]&(1<<0)?"stencil,":"");
+       kgem_debug_print(data, offset, 2, "clear color\n");
+       kgem_debug_print(data, offset, 3, "clear depth/stencil\n");
+       kgem_debug_print(data, offset, 4, "color value (rgba8888)\n");
+       kgem_debug_print(data, offset, 5, "depth value %f\n",
+                 int_as_float(data[5]));
+       kgem_debug_print(data, offset, 6, "clear stencil\n");
+       return len;
+    }
+
+    for (idx = 0; idx < ARRAY_SIZE(opcodes_3d_1d); idx++) {
+       opcode_3d_1d = &opcodes_3d_1d[idx];
+       if (((data[0] & 0x00ff0000) >> 16) == opcode_3d_1d->opcode) {
+           len = 1;
+
+           kgem_debug_print(data, offset, 0, "%s\n", opcode_3d_1d->name);
+           if (opcode_3d_1d->max_len > 1) {
+               len = (data[0] & 0x0000ffff) + 2;
+               assert (len >= opcode_3d_1d->min_len &&
+                       len <= opcode_3d_1d->max_len);
+           }
+
+           for (i = 1; i < len; i++)
+               kgem_debug_print(data, offset, i, "dword %d\n", i);
+
+           return len;
+       }
+    }
+
+    kgem_debug_print(data, offset, 0, "3D UNKNOWN: 3d_1d opcode = 0x%x\n", opcode);
+    return 1;
+}
+
+static int
+decode_3d_1c(struct kgem *kgem, uint32_t offset)
+{
+    uint32_t *data = kgem->batch + offset;
+    uint32_t opcode;
+
+    opcode = (data[0] & 0x00f80000) >> 19;
+
+    switch (opcode) {
+    case 0x11:
+       kgem_debug_print(data, offset, 0, "3DSTATE_DEPTH_SUBRECTANGLE_DISABLE\n");
+       return 1;
+    case 0x10:
+       kgem_debug_print(data, offset, 0, "3DSTATE_SCISSOR_ENABLE %s\n",
+               data[0]&1?"enabled":"disabled");
+       return 1;
+    case 0x01:
+       kgem_debug_print(data, offset, 0, "3DSTATE_MAP_COORD_SET_I830\n");
+       return 1;
+    case 0x0a:
+       kgem_debug_print(data, offset, 0, "3DSTATE_MAP_CUBE_I830\n");
+       return 1;
+    case 0x05:
+       kgem_debug_print(data, offset, 0, "3DSTATE_MAP_TEX_STREAM_I830\n");
+       return 1;
+    }
+
+    kgem_debug_print(data, offset, 0, "3D UNKNOWN: 3d_1c opcode = 0x%x\n",
+             opcode);
+    return 1;
+}
+
+int kgem_gen2_decode_3d(struct kgem *kgem, uint32_t offset)
+{
+    const static struct {
+       uint32_t opcode;
+       int min_len;
+       int max_len;
+       const char *name;
+    } opcodes[] = {
+       { 0x02, 1, 1, "3DSTATE_MODES_3" },
+       { 0x03, 1, 1, "3DSTATE_ENABLES_1"},
+       { 0x04, 1, 1, "3DSTATE_ENABLES_2"},
+       { 0x05, 1, 1, "3DSTATE_VFT0"},
+       { 0x06, 1, 1, "3DSTATE_AA"},
+       { 0x07, 1, 1, "3DSTATE_RASTERIZATION_RULES" },
+       { 0x08, 1, 1, "3DSTATE_MODES_1" },
+       { 0x09, 1, 1, "3DSTATE_STENCIL_TEST" },
+       { 0x0a, 1, 1, "3DSTATE_VFT1"},
+       { 0x0b, 1, 1, "3DSTATE_INDPT_ALPHA_BLEND" },
+       { 0x0c, 1, 1, "3DSTATE_MODES_5" },
+       { 0x0d, 1, 1, "3DSTATE_MAP_BLEND_OP" },
+       { 0x0e, 1, 1, "3DSTATE_MAP_BLEND_ARG" },
+       { 0x0f, 1, 1, "3DSTATE_MODES_2" },
+       { 0x15, 1, 1, "3DSTATE_FOG_COLOR" },
+       { 0x16, 1, 1, "3DSTATE_MODES_4" },
+    };
+    uint32_t *data = kgem->batch + offset;
+    uint32_t opcode = (data[0] & 0x1f000000) >> 24;
+    uint32_t idx;
+
+    switch (opcode) {
+    case 0x1f:
+       return decode_3d_primitive(kgem, offset);
+    case 0x1d:
+       return decode_3d_1d(kgem, offset);
+    case 0x1c:
+       return decode_3d_1c(kgem, offset);
+    }
+
+    /* Catch the known instructions */
+    for (idx = 0; idx < ARRAY_SIZE(opcodes); idx++) {
+       if (opcode == opcodes[idx].opcode) {
+           unsigned int len = 1, i;
+
+           kgem_debug_print(data, offset, 0, "%s\n", opcodes[idx].name);
+           if (opcodes[idx].max_len > 1) {
+               len = (data[0] & 0xf) + 2;
+               assert(len >= opcodes[idx].min_len &&
+                      len <= opcodes[idx].max_len);
+           }
+
+           for (i = 1; i < len; i++)
+               kgem_debug_print(data, offset, i, "dword %d\n", i);
+           return len;
+       }
+    }
+
+    kgem_debug_print(data, offset, 0, "3D UNKNOWN: 3d opcode = 0x%x\n", opcode);
+    return 1;
+}
+
+void kgem_gen2_finish_state(struct kgem *kgem)
+{
+       memset(&state, 0, sizeof(state));
+}
diff --git a/src/sna/kgem_debug_gen3.c b/src/sna/kgem_debug_gen3.c
new file mode 100644 (file)
index 0000000..1634225
--- /dev/null
@@ -0,0 +1,1600 @@
+/*
+ * Copyright © 2007-2011 Intel 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.
+ *
+ * Authors:
+ *    Eric Anholt <eric@anholt.net>
+ *    Chris Wilson <chris@chris-wilson.co.uk>
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/mman.h>
+#include <assert.h>
+
+#include "sna.h"
+#include "sna_reg.h"
+
+#include "gen3_render.h"
+
+#include "kgem_debug.h"
+
+enum type {
+       T_FLOAT32,
+       T_FLOAT16,
+};
+
+static struct state {
+       struct vertex_buffer {
+               int handle;
+               void *base;
+               const char *ptr;
+               int pitch;
+
+               struct kgem_bo *current;
+       } vb;
+       struct vertex_elements {
+               int offset;
+               bool valid;
+               enum type type;
+               int size;
+               uint8_t swizzle[4];
+       } ve[33];
+       int num_ve;
+} state;
+
+static float int_as_float(int i)
+{
+       union {
+               float f;
+               int i;
+       } x;
+       x.i = i;
+       return x.f;
+}
+
+static void gen3_update_vertex_buffer_addr(struct kgem *kgem,
+                                          uint32_t offset)
+{
+       uint32_t handle;
+       struct kgem_bo *bo = NULL;
+       void *base, *ptr;
+       int i;
+
+       offset *= sizeof(uint32_t);
+
+       for (i = 0; i < kgem->nreloc; i++)
+               if (kgem->reloc[i].offset == offset)
+                       break;
+       assert(i < kgem->nreloc);
+       handle = kgem->reloc[i].target_handle;
+
+       if (handle == 0) {
+               base = kgem->batch;
+       } else {
+               list_for_each_entry(bo, &kgem->next_request->buffers, request)
+                       if (bo->handle == handle)
+                               break;
+               assert(&bo->request != &kgem->next_request->buffers);
+               base = kgem_bo_map__debug(kgem, bo);
+       }
+       ptr = (char *)base + kgem->reloc[i].delta;
+
+       state.vb.current = bo;
+       state.vb.base = base;
+       state.vb.ptr = ptr;
+}
+
+static void gen3_update_vertex_buffer_pitch(struct kgem *kgem,
+                                          uint32_t offset)
+{
+       state.vb.pitch = kgem->batch[offset] >> 16 & 0x3f;
+       state.vb.pitch *= sizeof(uint32_t);
+}
+
+static void gen3_update_vertex_elements(struct kgem *kgem, uint32_t data)
+{
+       state.ve[1].valid = 1;
+
+       switch ((data >> 6) & 7) {
+       case 1:
+               state.ve[1].type = T_FLOAT32;
+               state.ve[1].size = 3;
+               state.ve[1].swizzle[0] = 1;
+               state.ve[1].swizzle[1] = 1;
+               state.ve[1].swizzle[2] = 1;
+               state.ve[1].swizzle[3] = 3;
+               break;
+       case 2:
+               state.ve[1].type = T_FLOAT32;
+               state.ve[1].size = 4;
+               state.ve[1].swizzle[0] = 1;
+               state.ve[1].swizzle[1] = 1;
+               state.ve[1].swizzle[2] = 1;
+               state.ve[1].swizzle[3] = 1;
+               break;
+       case 3:
+               state.ve[1].type = T_FLOAT32;
+               state.ve[1].size = 2;
+               state.ve[1].swizzle[0] = 1;
+               state.ve[1].swizzle[1] = 1;
+               state.ve[1].swizzle[2] = 2;
+               state.ve[1].swizzle[3] = 3;
+               break;
+       case 4:
+               state.ve[1].type = T_FLOAT32;
+               state.ve[1].size = 3;
+               state.ve[1].swizzle[0] = 1;
+               state.ve[1].swizzle[1] = 1;
+               state.ve[1].swizzle[2] = 3;
+               state.ve[1].swizzle[3] = 1;
+               break;
+       }
+
+       state.ve[2].valid = 0;
+       state.ve[3].valid = 0;
+}
+
+static void gen3_update_vertex_texcoords(struct kgem *kgem, uint32_t data)
+{
+       int id;
+       for (id = 0; id < 8; id++) {
+               uint32_t fmt = (data >> (id*4)) & 0xf;
+               int width;
+
+               state.ve[id+4].valid = fmt != 0xf;
+
+               width = 0;
+               switch (fmt) {
+               case 0:
+                       state.ve[id+4].type = T_FLOAT32;
+                       width = state.ve[id+4].size = 2;
+                       break;
+               case 1:
+                       state.ve[id+4].type = T_FLOAT32;
+                       width = state.ve[id+4].size = 3;
+                       break;
+               case 2:
+                       state.ve[id+4].type = T_FLOAT32;
+                       width = state.ve[id+4].size = 4;
+                       break;
+               case 3:
+                       state.ve[id+4].type = T_FLOAT32;
+                       width = state.ve[id+4].size = 1;
+                       break;
+               case 4:
+                       state.ve[id+4].type = T_FLOAT16;
+                       width = state.ve[id+4].size = 2;
+                       break;
+               case 5:
+                       state.ve[id+4].type = T_FLOAT16;
+                       width = state.ve[id+4].size = 4;
+                       break;
+               }
+
+               state.ve[id+4].swizzle[0] = width > 0 ? 1 : 2;
+               state.ve[id+4].swizzle[1] = width > 1 ? 1 : 2;
+               state.ve[id+4].swizzle[2] = width > 2 ? 1 : 2;
+               state.ve[id+4].swizzle[3] = width > 3 ? 1 : 2;
+       }
+}
+
+static void gen3_update_vertex_elements_offsets(struct kgem *kgem)
+{
+       int i, offset;
+
+       for (i = offset = 0; i < ARRAY_SIZE(state.ve); i++) {
+               if (!state.ve[i].valid)
+                       continue;
+
+               state.ve[i].offset = offset;
+               offset += 4 * state.ve[i].size;
+               state.num_ve = i;
+       }
+}
+
+static void vertices_float32_out(const struct vertex_elements *ve, const float *f, int max)
+{
+       int c;
+
+       ErrorF("(");
+       for (c = 0; c < max; c++) {
+               switch (ve->swizzle[c]) {
+               case 0: ErrorF("#"); break;
+               case 1: ErrorF("%f", f[c]); break;
+               case 2: ErrorF("0.0"); break;
+               case 3: ErrorF("1.0"); break;
+               case 4: ErrorF("0x1"); break;
+               case 5: break;
+               default: ErrorF("?");
+               }
+               if (c < max-1)
+                       ErrorF(", ");
+       }
+       ErrorF(")");
+}
+
+static void ve_out(const struct vertex_elements *ve, const void *ptr)
+{
+       switch (ve->type) {
+       case T_FLOAT32:
+               vertices_float32_out(ve, ptr, ve->size);
+               break;
+       case T_FLOAT16:
+               //vertices_float16_out(ve, ptr, ve->size);
+               break;
+       }
+}
+
+static void indirect_vertex_out(struct kgem *kgem, uint32_t v)
+{
+       const struct vertex_buffer *vb = &state.vb;
+       int i = 1;
+
+       do {
+               const struct vertex_elements *ve = &state.ve[i];
+               const void *ptr = vb->ptr + v * vb->pitch + ve->offset;
+
+               if (!ve->valid)
+                       continue;
+
+               ve_out(ve, ptr);
+
+               while (++i <= state.num_ve && !state.ve[i].valid)
+                       ;
+
+               if (i <= state.num_ve)
+                       ErrorF(", ");
+       } while (i <= state.num_ve);
+}
+
+static int inline_vertex_out(struct kgem *kgem, void *base)
+{
+       const struct vertex_buffer *vb = &state.vb;
+       int i = 1;
+
+       do {
+               const struct vertex_elements *ve = &state.ve[i];
+               const void *ptr = (char *)base + ve->offset;
+
+               if (!ve->valid)
+                       continue;
+
+               ve_out(ve, ptr);
+
+               while (++i <= state.num_ve && !state.ve[i].valid)
+                       ;
+
+               if (i <= state.num_ve)
+                       ErrorF(", ");
+       } while (i <= state.num_ve);
+
+       return vb->pitch;
+}
+
+static int
+gen3_decode_3d_1c(struct kgem *kgem, uint32_t offset)
+{
+       uint32_t *data = kgem->batch + offset;
+       uint32_t opcode;
+
+       opcode = (data[0] & 0x00f80000) >> 19;
+
+       switch (opcode) {
+       case 0x11:
+               kgem_debug_print(data, offset, 0, "3DSTATE_DEPTH_SUBRECTANGLE_DISABLE\n");
+               return 1;
+       case 0x10:
+               kgem_debug_print(data, offset, 0, "3DSTATE_SCISSOR_ENABLE %s\n",
+                         data[0]&1?"enabled":"disabled");
+               return 1;
+       case 0x01:
+               kgem_debug_print(data, offset, 0, "3DSTATE_MAP_COORD_SET_I830\n");
+               return 1;
+       case 0x0a:
+               kgem_debug_print(data, offset, 0, "3DSTATE_MAP_CUBE_I830\n");
+               return 1;
+       case 0x05:
+               kgem_debug_print(data, offset, 0, "3DSTATE_MAP_TEX_STREAM_I830\n");
+               return 1;
+       }
+
+       kgem_debug_print(data, offset, 0, "3D UNKNOWN: 3d_1c opcode = 0x%x\n",
+                 opcode);
+       assert(0);
+       return 1;
+}
+
+/** Sets the string dstname to describe the destination of the PS instruction */
+static void
+gen3_get_instruction_dst(uint32_t *data, int i, char *dstname, int do_mask)
+{
+    uint32_t a0 = data[i];
+    int dst_nr = (a0 >> 14) & 0xf;
+    char dstmask[8];
+    const char *sat;
+
+    if (do_mask) {
+       if (((a0 >> 10) & 0xf) == 0xf) {
+           dstmask[0] = 0;
+       } else {
+           int dstmask_index = 0;
+
+           dstmask[dstmask_index++] = '.';
+           if (a0 & (1 << 10))
+               dstmask[dstmask_index++] = 'x';
+           if (a0 & (1 << 11))
+               dstmask[dstmask_index++] = 'y';
+           if (a0 & (1 << 12))
+               dstmask[dstmask_index++] = 'z';
+           if (a0 & (1 << 13))
+               dstmask[dstmask_index++] = 'w';
+           dstmask[dstmask_index++] = 0;
+       }
+
+       if (a0 & (1 << 22))
+           sat = ".sat";
+       else
+           sat = "";
+    } else {
+       dstmask[0] = 0;
+       sat = "";
+    }
+
+    switch ((a0 >> 19) & 0x7) {
+    case 0:
+           assert(dst_nr <= 15);
+       sprintf(dstname, "R%d%s%s", dst_nr, dstmask, sat);
+       break;
+    case 4:
+       assert(dst_nr == 0);
+       sprintf(dstname, "oC%s%s", dstmask, sat);
+       break;
+    case 5:
+       assert(dst_nr == 0);
+       sprintf(dstname, "oD%s%s",  dstmask, sat);
+       break;
+    case 6:
+       assert(dst_nr <= 3);
+       sprintf(dstname, "U%d%s%s", dst_nr, dstmask, sat);
+       break;
+    default:
+       sprintf(dstname, "RESERVED");
+       break;
+    }
+}
+
+static const char *
+gen3_get_channel_swizzle(uint32_t select)
+{
+    switch (select & 0x7) {
+    case 0:
+       return (select & 8) ? "-x" : "x";
+    case 1:
+       return (select & 8) ? "-y" : "y";
+    case 2:
+       return (select & 8) ? "-z" : "z";
+    case 3:
+       return (select & 8) ? "-w" : "w";
+    case 4:
+       return (select & 8) ? "-0" : "0";
+    case 5:
+       return (select & 8) ? "-1" : "1";
+    default:
+       return (select & 8) ? "-bad" : "bad";
+    }
+}
+
+static void
+gen3_get_instruction_src_name(uint32_t src_type, uint32_t src_nr, char *name)
+{
+       switch (src_type) {
+       case 0:
+               sprintf(name, "R%d", src_nr);
+               assert(src_nr <= 15);
+               break;
+       case 1:
+               if (src_nr < 8)
+                       sprintf(name, "T%d", src_nr);
+               else if (src_nr == 8)
+                       sprintf(name, "DIFFUSE");
+               else if (src_nr == 9)
+                       sprintf(name, "SPECULAR");
+               else if (src_nr == 10)
+                       sprintf(name, "FOG");
+               else {
+                       assert(0);
+                       sprintf(name, "RESERVED");
+               }
+               break;
+       case 2:
+               sprintf(name, "C%d", src_nr);
+               assert(src_nr <= 31);
+               break;
+       case 4:
+               sprintf(name, "oC");
+               assert(src_nr == 0);
+               break;
+       case 5:
+               sprintf(name, "oD");
+               assert(src_nr == 0);
+               break;
+       case 6:
+               sprintf(name, "U%d", src_nr);
+               assert(src_nr <= 3);
+               break;
+       default:
+               sprintf(name, "RESERVED");
+               assert(0);
+               break;
+       }
+}
+
+static void
+gen3_get_instruction_src0(uint32_t *data, int i, char *srcname)
+{
+    uint32_t a0 = data[i];
+    uint32_t a1 = data[i + 1];
+    int src_nr = (a0 >> 2) & 0x1f;
+    const char *swizzle_x = gen3_get_channel_swizzle((a1 >> 28) & 0xf);
+    const char *swizzle_y = gen3_get_channel_swizzle((a1 >> 24) & 0xf);
+    const char *swizzle_z = gen3_get_channel_swizzle((a1 >> 20) & 0xf);
+    const char *swizzle_w = gen3_get_channel_swizzle((a1 >> 16) & 0xf);
+    char swizzle[100];
+
+    gen3_get_instruction_src_name((a0 >> 7) & 0x7, src_nr, srcname);
+    sprintf(swizzle, ".%s%s%s%s", swizzle_x, swizzle_y, swizzle_z, swizzle_w);
+    if (strcmp(swizzle, ".xyzw") != 0)
+       strcat(srcname, swizzle);
+}
+
+static void
+gen3_get_instruction_src1(uint32_t *data, int i, char *srcname)
+{
+    uint32_t a1 = data[i + 1];
+    uint32_t a2 = data[i + 2];
+    int src_nr = (a1 >> 8) & 0x1f;
+    const char *swizzle_x = gen3_get_channel_swizzle((a1 >> 4) & 0xf);
+    const char *swizzle_y = gen3_get_channel_swizzle((a1 >> 0) & 0xf);
+    const char *swizzle_z = gen3_get_channel_swizzle((a2 >> 28) & 0xf);
+    const char *swizzle_w = gen3_get_channel_swizzle((a2 >> 24) & 0xf);
+    char swizzle[100];
+
+    gen3_get_instruction_src_name((a1 >> 13) & 0x7, src_nr, srcname);
+    sprintf(swizzle, ".%s%s%s%s", swizzle_x, swizzle_y, swizzle_z, swizzle_w);
+    if (strcmp(swizzle, ".xyzw") != 0)
+       strcat(srcname, swizzle);
+}
+
+static void
+gen3_get_instruction_src2(uint32_t *data, int i, char *srcname)
+{
+    uint32_t a2 = data[i + 2];
+    int src_nr = (a2 >> 16) & 0x1f;
+    const char *swizzle_x = gen3_get_channel_swizzle((a2 >> 12) & 0xf);
+    const char *swizzle_y = gen3_get_channel_swizzle((a2 >> 8) & 0xf);
+    const char *swizzle_z = gen3_get_channel_swizzle((a2 >> 4) & 0xf);
+    const char *swizzle_w = gen3_get_channel_swizzle((a2 >> 0) & 0xf);
+    char swizzle[100];
+
+    gen3_get_instruction_src_name((a2 >> 21) & 0x7, src_nr, srcname);
+    sprintf(swizzle, ".%s%s%s%s", swizzle_x, swizzle_y, swizzle_z, swizzle_w);
+    if (strcmp(swizzle, ".xyzw") != 0)
+       strcat(srcname, swizzle);
+}
+
+static void
+gen3_get_instruction_addr(uint32_t src_type, uint32_t src_nr, char *name)
+{
+       switch (src_type) {
+       case 0:
+               sprintf(name, "R%d", src_nr);
+               assert(src_nr <= 15);
+               break;
+       case 1:
+               if (src_nr < 8)
+                       sprintf(name, "T%d", src_nr);
+               else if (src_nr == 8)
+                       sprintf(name, "DIFFUSE");
+               else if (src_nr == 9)
+                       sprintf(name, "SPECULAR");
+               else if (src_nr == 10)
+                       sprintf(name, "FOG");
+               else {
+                       assert(0);
+                       sprintf(name, "RESERVED");
+               }
+               break;
+       case 4:
+               sprintf(name, "oC");
+               assert(src_nr == 0);
+               break;
+       case 5:
+               sprintf(name, "oD");
+               assert(src_nr == 0);
+               break;
+       default:
+               assert(0);
+               sprintf(name, "RESERVED");
+               break;
+       }
+}
+
+static void
+gen3_decode_alu1(uint32_t *data, uint32_t offset,
+                int i, char *instr_prefix, const char *op_name)
+{
+    char dst[100], src0[100];
+
+    gen3_get_instruction_dst(data, i, dst, 1);
+    gen3_get_instruction_src0(data, i, src0);
+
+    kgem_debug_print(data, offset, i++, "%s: %s %s, %s\n", instr_prefix,
+             op_name, dst, src0);
+    kgem_debug_print(data, offset, i++, "%s\n", instr_prefix);
+    kgem_debug_print(data, offset, i++, "%s\n", instr_prefix);
+}
+
+static void
+gen3_decode_alu2(uint32_t *data, uint32_t offset,
+                int i, char *instr_prefix, const char *op_name)
+{
+    char dst[100], src0[100], src1[100];
+
+    gen3_get_instruction_dst(data, i, dst, 1);
+    gen3_get_instruction_src0(data, i, src0);
+    gen3_get_instruction_src1(data, i, src1);
+
+    kgem_debug_print(data, offset, i++, "%s: %s %s, %s, %s\n", instr_prefix,
+             op_name, dst, src0, src1);
+    kgem_debug_print(data, offset, i++, "%s\n", instr_prefix);
+    kgem_debug_print(data, offset, i++, "%s\n", instr_prefix);
+}
+
+static void
+gen3_decode_alu3(uint32_t *data, uint32_t offset,
+                int i, char *instr_prefix, const char *op_name)
+{
+    char dst[100], src0[100], src1[100], src2[100];
+
+    gen3_get_instruction_dst(data, i, dst, 1);
+    gen3_get_instruction_src0(data, i, src0);
+    gen3_get_instruction_src1(data, i, src1);
+    gen3_get_instruction_src2(data, i, src2);
+
+    kgem_debug_print(data, offset, i++, "%s: %s %s, %s, %s, %s\n", instr_prefix,
+             op_name, dst, src0, src1, src2);
+    kgem_debug_print(data, offset, i++, "%s\n", instr_prefix);
+    kgem_debug_print(data, offset, i++, "%s\n", instr_prefix);
+}
+
+static void
+gen3_decode_tex(uint32_t *data, uint32_t offset, int i, char *instr_prefix,
+               const char *tex_name)
+{
+    uint32_t t0 = data[i];
+    uint32_t t1 = data[i + 1];
+    char dst_name[100];
+    char addr_name[100];
+    int sampler_nr;
+
+    gen3_get_instruction_dst(data, i, dst_name, 0);
+    gen3_get_instruction_addr((t1 >> 24) & 0x7,
+                             (t1 >> 17) & 0xf,
+                             addr_name);
+    sampler_nr = t0 & 0xf;
+
+    kgem_debug_print(data, offset, i++, "%s: %s %s, S%d, %s\n", instr_prefix,
+             tex_name, dst_name, sampler_nr, addr_name);
+    kgem_debug_print(data, offset, i++, "%s\n", instr_prefix);
+    kgem_debug_print(data, offset, i++, "%s\n", instr_prefix);
+}
+
+static void
+gen3_decode_dcl(uint32_t *data, uint32_t offset, int i, char *instr_prefix)
+{
+       uint32_t d0 = data[i];
+       const char *sampletype;
+       int dcl_nr = (d0 >> 14) & 0xf;
+       const char *dcl_x = d0 & (1 << 10) ? "x" : "";
+       const char *dcl_y = d0 & (1 << 11) ? "y" : "";
+       const char *dcl_z = d0 & (1 << 12) ? "z" : "";
+       const char *dcl_w = d0 & (1 << 13) ? "w" : "";
+       char dcl_mask[10];
+
+       switch ((d0 >> 19) & 0x3) {
+       case 1:
+               sprintf(dcl_mask, ".%s%s%s%s", dcl_x, dcl_y, dcl_z, dcl_w);
+               assert (strcmp(dcl_mask, "."));
+
+               assert(dcl_nr <= 10);
+               if (dcl_nr < 8) {
+                       if (strcmp(dcl_mask, ".x") != 0 &&
+                           strcmp(dcl_mask, ".xy") != 0 &&
+                           strcmp(dcl_mask, ".xz") != 0 &&
+                           strcmp(dcl_mask, ".w") != 0 &&
+                           strcmp(dcl_mask, ".xyzw") != 0) {
+                               assert(0);
+                       }
+                       kgem_debug_print(data, offset, i++, "%s: DCL T%d%s\n", instr_prefix,
+                                 dcl_nr, dcl_mask);
+               } else {
+                       if (strcmp(dcl_mask, ".xz") == 0)
+                               assert(0);
+                       else if (strcmp(dcl_mask, ".xw") == 0)
+                               assert(0);
+                       else if (strcmp(dcl_mask, ".xzw") == 0)
+                               assert(0);
+
+                       if (dcl_nr == 8) {
+                               kgem_debug_print(data, offset, i++, "%s: DCL DIFFUSE%s\n", instr_prefix,
+                                         dcl_mask);
+                       } else if (dcl_nr == 9) {
+                               kgem_debug_print(data, offset, i++, "%s: DCL SPECULAR%s\n", instr_prefix,
+                                         dcl_mask);
+                       } else if (dcl_nr == 10) {
+                               kgem_debug_print(data, offset, i++, "%s: DCL FOG%s\n", instr_prefix,
+                                         dcl_mask);
+                       }
+               }
+               kgem_debug_print(data, offset, i++, "%s\n", instr_prefix);
+               kgem_debug_print(data, offset, i++, "%s\n", instr_prefix);
+               break;
+       case 3:
+               switch ((d0 >> 22) & 0x3) {
+               case 0:
+                       sampletype = "2D";
+                       break;
+               case 1:
+                       sampletype = "CUBE";
+                       break;
+               case 2:
+                       sampletype = "3D";
+                       break;
+               default:
+                       sampletype = "RESERVED";
+                       break;
+               }
+               assert(dcl_nr <= 15);
+               kgem_debug_print(data, offset, i++, "%s: DCL S%d %s\n", instr_prefix,
+                         dcl_nr, sampletype);
+               kgem_debug_print(data, offset, i++, "%s\n", instr_prefix);
+               kgem_debug_print(data, offset, i++, "%s\n", instr_prefix);
+               break;
+       default:
+               kgem_debug_print(data, offset, i++, "%s: DCL RESERVED%d\n", instr_prefix, dcl_nr);
+               kgem_debug_print(data, offset, i++, "%s\n", instr_prefix);
+               kgem_debug_print(data, offset, i++, "%s\n", instr_prefix);
+       }
+}
+
+static void
+gen3_decode_instruction(uint32_t *data, uint32_t offset,
+                       int i, char *instr_prefix)
+{
+    switch ((data[i] >> 24) & 0x1f) {
+    case 0x0:
+       kgem_debug_print(data, offset, i++, "%s: NOP\n", instr_prefix);
+       kgem_debug_print(data, offset, i++, "%s\n", instr_prefix);
+       kgem_debug_print(data, offset, i++, "%s\n", instr_prefix);
+       break;
+    case 0x01:
+       gen3_decode_alu2(data, offset, i, instr_prefix, "ADD");
+       break;
+    case 0x02:
+       gen3_decode_alu1(data, offset, i, instr_prefix, "MOV");
+       break;
+    case 0x03:
+       gen3_decode_alu2(data, offset, i, instr_prefix, "MUL");
+       break;
+    case 0x04:
+       gen3_decode_alu3(data, offset, i, instr_prefix, "MAD");
+       break;
+    case 0x05:
+       gen3_decode_alu3(data, offset, i, instr_prefix, "DP2ADD");
+       break;
+    case 0x06:
+       gen3_decode_alu2(data, offset, i, instr_prefix, "DP3");
+       break;
+    case 0x07:
+       gen3_decode_alu2(data, offset, i, instr_prefix, "DP4");
+       break;
+    case 0x08:
+       gen3_decode_alu1(data, offset, i, instr_prefix, "FRC");
+       break;
+    case 0x09:
+       gen3_decode_alu1(data, offset, i, instr_prefix, "RCP");
+       break;
+    case 0x0a:
+       gen3_decode_alu1(data, offset, i, instr_prefix, "RSQ");
+       break;
+    case 0x0b:
+       gen3_decode_alu1(data, offset, i, instr_prefix, "EXP");
+       break;
+    case 0x0c:
+       gen3_decode_alu1(data, offset, i, instr_prefix, "LOG");
+       break;
+    case 0x0d:
+       gen3_decode_alu2(data, offset, i, instr_prefix, "CMP");
+       break;
+    case 0x0e:
+       gen3_decode_alu2(data, offset, i, instr_prefix, "MIN");
+       break;
+    case 0x0f:
+       gen3_decode_alu2(data, offset, i, instr_prefix, "MAX");
+       break;
+    case 0x10:
+       gen3_decode_alu1(data, offset, i, instr_prefix, "FLR");
+       break;
+    case 0x11:
+       gen3_decode_alu1(data, offset, i, instr_prefix, "MOD");
+       break;
+    case 0x12:
+       gen3_decode_alu1(data, offset, i, instr_prefix, "TRC");
+       break;
+    case 0x13:
+       gen3_decode_alu2(data, offset, i, instr_prefix, "SGE");
+       break;
+    case 0x14:
+       gen3_decode_alu2(data, offset, i, instr_prefix, "SLT");
+       break;
+    case 0x15:
+       gen3_decode_tex(data, offset, i, instr_prefix, "TEXLD");
+       break;
+    case 0x16:
+       gen3_decode_tex(data, offset, i, instr_prefix, "TEXLDP");
+       break;
+    case 0x17:
+       gen3_decode_tex(data, offset, i, instr_prefix, "TEXLDB");
+       break;
+    case 0x19:
+       gen3_decode_dcl(data, offset, i, instr_prefix);
+       break;
+    default:
+       kgem_debug_print(data, offset, i++, "%s: unknown\n", instr_prefix);
+       kgem_debug_print(data, offset, i++, "%s\n", instr_prefix);
+       kgem_debug_print(data, offset, i++, "%s\n", instr_prefix);
+       break;
+    }
+}
+
+static const char *
+gen3_decode_compare_func(uint32_t op)
+{
+       switch (op&0x7) {
+       case 0: return "always";
+       case 1: return "never";
+       case 2: return "less";
+       case 3: return "equal";
+       case 4: return "lequal";
+       case 5: return "greater";
+       case 6: return "notequal";
+       case 7: return "gequal";
+       }
+       return "";
+}
+
+static const char *
+gen3_decode_stencil_op(uint32_t op)
+{
+       switch (op&0x7) {
+       case 0: return "keep";
+       case 1: return "zero";
+       case 2: return "replace";
+       case 3: return "incr_sat";
+       case 4: return "decr_sat";
+       case 5: return "greater";
+       case 6: return "incr";
+       case 7: return "decr";
+       }
+       return "";
+}
+
+#if 0
+/* part of MODES_4 */
+static const char *
+gen3_decode_logic_op(uint32_t op)
+{
+       switch (op&0xf) {
+       case 0: return "clear";
+       case 1: return "nor";
+       case 2: return "and_inv";
+       case 3: return "copy_inv";
+       case 4: return "and_rvrse";
+       case 5: return "inv";
+       case 6: return "xor";
+       case 7: return "nand";
+       case 8: return "and";
+       case 9: return "equiv";
+       case 10: return "noop";
+       case 11: return "or_inv";
+       case 12: return "copy";
+       case 13: return "or_rvrse";
+       case 14: return "or";
+       case 15: return "set";
+       }
+       return "";
+}
+#endif
+
+static const char *
+gen3_decode_blend_fact(uint32_t op)
+{
+       switch (op&0xf) {
+       case 1: return "zero";
+       case 2: return "one";
+       case 3: return "src_colr";
+       case 4: return "inv_src_colr";
+       case 5: return "src_alpha";
+       case 6: return "inv_src_alpha";
+       case 7: return "dst_alpha";
+       case 8: return "inv_dst_alpha";
+       case 9: return "dst_colr";
+       case 10: return "inv_dst_colr";
+       case 11: return "src_alpha_sat";
+       case 12: return "cnst_colr";
+       case 13: return "inv_cnst_colr";
+       case 14: return "cnst_alpha";
+       case 15: return "inv_const_alpha";
+       }
+       return "";
+}
+
+static const char *
+decode_tex_coord_mode(uint32_t mode)
+{
+    switch (mode&0x7) {
+    case 0: return "wrap";
+    case 1: return "mirror";
+    case 2: return "clamp_edge";
+    case 3: return "cube";
+    case 4: return "clamp_border";
+    case 5: return "mirror_once";
+    }
+    return "";
+}
+
+static const char *
+gen3_decode_sample_filter(uint32_t mode)
+{
+       switch (mode&0x7) {
+       case 0: return "nearest";
+       case 1: return "linear";
+       case 2: return "anisotropic";
+       case 3: return "4x4_1";
+       case 4: return "4x4_2";
+       case 5: return "4x4_flat";
+       case 6: return "6x5_mono";
+       }
+       return "";
+}
+
+static int
+gen3_decode_load_state_immediate_1(struct kgem *kgem, uint32_t offset)
+{
+       const uint32_t *data = kgem->batch + offset;
+       int len, i, word;
+
+       kgem_debug_print(data, offset, 0, "3DSTATE_LOAD_STATE_IMMEDIATE_1\n");
+       len = (data[0] & 0x0000000f) + 2;
+       i = 1;
+       for (word = 0; word <= 8; word++) {
+               if (data[0] & (1 << (4 + word))) {
+                       switch (word) {
+                       case 0:
+                               kgem_debug_print(data, offset, i, "S0: vbo offset: 0x%08x%s\n",
+                                         data[i]&(~1),data[i]&1?", auto cache invalidate disabled":"");
+                               gen3_update_vertex_buffer_addr(kgem, offset + i);
+                               break;
+                       case 1:
+                               kgem_debug_print(data, offset, i, "S1: vertex width: %i, vertex pitch: %i\n",
+                                         (data[i]>>24)&0x3f,(data[i]>>16)&0x3f);
+                               gen3_update_vertex_buffer_pitch(kgem, offset + i);
+                               break;
+                       case 2:
+                               {
+                                       char buf[200];
+                                       int len = 0;
+                                       int tex_num;
+                                       for (tex_num = 0; tex_num < 8; tex_num++) {
+                                               switch((data[i]>>tex_num*4)&0xf) {
+                                               case 0: len += sprintf(buf + len, "%i=2D ", tex_num); break;
+                                               case 1: len += sprintf(buf + len, "%i=3D ", tex_num); break;
+                                               case 2: len += sprintf(buf + len, "%i=4D ", tex_num); break;
+                                               case 3: len += sprintf(buf + len, "%i=1D ", tex_num); break;
+                                               case 4: len += sprintf(buf + len, "%i=2D_16 ", tex_num); break;
+                                               case 5: len += sprintf(buf + len, "%i=4D_16 ", tex_num); break;
+                                               case 0xf: len += sprintf(buf + len, "%i=NP ", tex_num); break;
+                                               }
+                                       }
+                                       kgem_debug_print(data, offset, i, "S2: texcoord formats: %s\n", buf);
+                                       gen3_update_vertex_texcoords(kgem, data[i]);
+                               }
+
+                               break;
+                       case 3:
+                               kgem_debug_print(data, offset, i, "S3: not documented\n");
+                               break;
+                       case 4:
+                               {
+                                       const char *cullmode = "";
+                                       const char *vfmt_xyzw = "";
+                                       switch((data[i]>>13)&0x3) {
+                                       case 0: cullmode = "both"; break;
+                                       case 1: cullmode = "none"; break;
+                                       case 2: cullmode = "cw"; break;
+                                       case 3: cullmode = "ccw"; break;
+                                       }
+                                       switch(data[i] & (7<<6 | 1<<2)) {
+                                       case 1<<6: vfmt_xyzw = "XYZ,"; break;
+                                       case 2<<6: vfmt_xyzw = "XYZW,"; break;
+                                       case 3<<6: vfmt_xyzw = "XY,"; break;
+                                       case 4<<6: vfmt_xyzw = "XYW,"; break;
+                                       case 1<<6 | 1<<2: vfmt_xyzw = "XYZF,"; break;
+                                       case 2<<6 | 1<<2: vfmt_xyzw = "XYZWF,"; break;
+                                       case 3<<6 | 1<<2: vfmt_xyzw = "XYF,"; break;
+                                       case 4<<6 | 1<<2: vfmt_xyzw = "XYWF,"; break;
+                                       }
+                                       kgem_debug_print(data, offset, i, "S4: point_width=%i, line_width=%.1f,"
+                                                 "%s%s%s%s%s cullmode=%s, vfmt=%s%s%s%s%s%s%s%s "
+                                                 "%s%s%s\n",
+                                                 (data[i]>>23)&0x1ff,
+                                                 ((data[i]>>19)&0xf) / 2.0,
+                                                 data[i]&(0xf<<15)?" flatshade=":"",
+                                                 data[i]&(1<<18)?"Alpha,":"",
+                                                 data[i]&(1<<17)?"Fog,":"",
+                                                 data[i]&(1<<16)?"Specular,":"",
+                                                 data[i]&(1<<15)?"Color,":"",
+                                                 cullmode,
+                                                 data[i]&(1<<12)?"PointWidth,":"",
+                                                 data[i]&(1<<11)?"SpecFog,":"",
+                                                 data[i]&(1<<10)?"Color,":"",
+                                                 data[i]&(1<<9)?"DepthOfs,":"",
+                                                 vfmt_xyzw,
+                                                 data[i]&(1<<9)?"FogParam,":"",
+                                                 data[i]&(1<<5)?"force default diffuse, ":"",
+                                                 data[i]&(1<<4)?"force default specular, ":"",
+                                                 data[i]&(1<<3)?"local depth ofs enable, ":"",
+                                                 data[i]&(1<<1)?"point sprite enable, ":"",
+                                                 data[i]&(1<<0)?"line AA enable, ":"");
+                                       gen3_update_vertex_elements(kgem, data[i]);
+                                       break;
+                               }
+                       case 5:
+                               {
+                                       kgem_debug_print(data, offset, i, "S5:%s%s%s%s%s"
+                                                 "%s%s%s%s stencil_ref=0x%x, stencil_test=%s, "
+                                                 "stencil_fail=%s, stencil_pass_z_fail=%s, "
+                                                 "stencil_pass_z_pass=%s, %s%s%s%s\n",
+                                                 data[i]&(0xf<<28)?" write_disable=":"",
+                                                 data[i]&(1<<31)?"Alpha,":"",
+                                                 data[i]&(1<<30)?"Red,":"",
+                                                 data[i]&(1<<29)?"Green,":"",
+                                                 data[i]&(1<<28)?"Blue,":"",
+                                                 data[i]&(1<<27)?" force default point size,":"",
+                                                 data[i]&(1<<26)?" last pixel enable,":"",
+                                                 data[i]&(1<<25)?" global depth ofs enable,":"",
+                                                 data[i]&(1<<24)?" fog enable,":"",
+                                                 (data[i]>>16)&0xff,
+                                                 gen3_decode_compare_func(data[i]>>13),
+                                                 gen3_decode_stencil_op(data[i]>>10),
+                                                 gen3_decode_stencil_op(data[i]>>7),
+                                                 gen3_decode_stencil_op(data[i]>>4),
+                                                 data[i]&(1<<3)?"stencil write enable, ":"",
+                                                 data[i]&(1<<2)?"stencil test enable, ":"",
+                                                 data[i]&(1<<1)?"color dither enable, ":"",
+                                                 data[i]&(1<<0)?"logicop enable, ":"");
+                               }
+                               break;
+                       case 6:
+                               kgem_debug_print(data, offset, i, "S6: %salpha_test=%s, alpha_ref=0x%x, "
+                                         "depth_test=%s, %ssrc_blnd_fct=%s, dst_blnd_fct=%s, "
+                                         "%s%stristrip_provoking_vertex=%i\n",
+                                         data[i]&(1<<31)?"alpha test enable, ":"",
+                                         gen3_decode_compare_func(data[i]>>28),
+                                         data[i]&(0xff<<20),
+                                         gen3_decode_compare_func(data[i]>>16),
+                                         data[i]&(1<<15)?"cbuf blend enable, ":"",
+                                         gen3_decode_blend_fact(data[i]>>8),
+                                         gen3_decode_blend_fact(data[i]>>4),
+                                         data[i]&(1<<3)?"depth write enable, ":"",
+                                         data[i]&(1<<2)?"cbuf write enable, ":"",
+                                         data[i]&(0x3));
+                               break;
+                       case 7:
+                               kgem_debug_print(data, offset, i, "S7: depth offset constant: 0x%08x\n", data[i]);
+                               break;
+                       }
+                       i++;
+               }
+       }
+
+       assert(len == i);
+       return len;
+}
+
+static int
+gen3_decode_3d_1d(struct kgem *kgem, uint32_t offset)
+{
+       uint32_t *data = kgem->batch + offset;
+       unsigned int len, i, c, idx, word, map, sampler, instr;
+       const char *format, *zformat, *type;
+       uint32_t opcode;
+       static const struct {
+               uint32_t opcode;
+               int min_len;
+               int max_len;
+               const char *name;
+       } opcodes_3d_1d[] = {
+               { 0x86, 4, 4, "3DSTATE_CHROMA_KEY" },
+               { 0x88, 2, 2, "3DSTATE_CONSTANT_BLEND_COLOR" },
+               { 0x99, 2, 2, "3DSTATE_DEFAULT_DIFFUSE" },
+               { 0x9a, 2, 2, "3DSTATE_DEFAULT_SPECULAR" },
+               { 0x98, 2, 2, "3DSTATE_DEFAULT_Z" },
+               { 0x97, 2, 2, "3DSTATE_DEPTH_OFFSET_SCALE" },
+               { 0x9d, 65, 65, "3DSTATE_FILTER_COEFFICIENTS_4X4" },
+               { 0x9e, 4, 4, "3DSTATE_MONO_FILTER" },
+               { 0x89, 4, 4, "3DSTATE_FOG_MODE" },
+               { 0x8f, 2, 16, "3DSTATE_MAP_PALLETE_LOAD_32" },
+               { 0x83, 2, 2, "3DSTATE_SPAN_STIPPLE" },
+       }, *opcode_3d_1d;
+
+       opcode = (data[0] & 0x00ff0000) >> 16;
+
+       switch (opcode) {
+       case 0x07:
+               /* This instruction is unusual.  A 0 length means just 1 DWORD instead of
+                * 2.  The 0 length is specified in one place to be unsupported, but
+                * stated to be required in another, and 0 length LOAD_INDIRECTs appear
+                * to cause no harm at least.
+                */
+               kgem_debug_print(data, offset, 0, "3DSTATE_LOAD_INDIRECT\n");
+               len = (data[0] & 0x000000ff) + 1;
+               i = 1;
+               if (data[0] & (0x01 << 8)) {
+                       kgem_debug_print(data, offset, i++, "SIS.0\n");
+                       kgem_debug_print(data, offset, i++, "SIS.1\n");
+               }
+               if (data[0] & (0x02 << 8)) {
+                       kgem_debug_print(data, offset, i++, "DIS.0\n");
+               }
+               if (data[0] & (0x04 << 8)) {
+                       kgem_debug_print(data, offset, i++, "SSB.0\n");
+                       kgem_debug_print(data, offset, i++, "SSB.1\n");
+               }
+               if (data[0] & (0x08 << 8)) {
+                       kgem_debug_print(data, offset, i++, "MSB.0\n");
+                       kgem_debug_print(data, offset, i++, "MSB.1\n");
+               }
+               if (data[0] & (0x10 << 8)) {
+                       kgem_debug_print(data, offset, i++, "PSP.0\n");
+                       kgem_debug_print(data, offset, i++, "PSP.1\n");
+               }
+               if (data[0] & (0x20 << 8)) {
+                       kgem_debug_print(data, offset, i++, "PSC.0\n");
+                       kgem_debug_print(data, offset, i++, "PSC.1\n");
+               }
+               assert(len == i);
+               return len;
+       case 0x04:
+               return gen3_decode_load_state_immediate_1(kgem, offset);
+       case 0x03:
+               kgem_debug_print(data, offset, 0, "3DSTATE_LOAD_STATE_IMMEDIATE_2\n");
+               len = (data[0] & 0x0000000f) + 2;
+               i = 1;
+               for (word = 6; word <= 14; word++) {
+                       if (data[0] & (1 << word)) {
+                               if (word == 6)
+                                       kgem_debug_print(data, offset, i++, "TBCF\n");
+                               else if (word >= 7 && word <= 10) {
+                                       kgem_debug_print(data, offset, i++, "TB%dC\n", word - 7);
+                                       kgem_debug_print(data, offset, i++, "TB%dA\n", word - 7);
+                               } else if (word >= 11 && word <= 14) {
+                                       kgem_debug_print(data, offset, i, "TM%dS0: offset=0x%08x, %s\n",
+                                                 word - 11,
+                                                 data[i]&0xfffffffe,
+                                                 data[i]&1?"use fence":"");
+                                       i++;
+                                       kgem_debug_print(data, offset, i, "TM%dS1: height=%i, width=%i, %s\n",
+                                                 word - 11,
+                                                 data[i]>>21, (data[i]>>10)&0x3ff,
+                                                 data[i]&2?(data[i]&1?"y-tiled":"x-tiled"):"");
+                                       i++;
+                                       kgem_debug_print(data, offset, i, "TM%dS2: pitch=%i, \n",
+                                                 word - 11,
+                                                 ((data[i]>>21) + 1)*4);
+                                       i++;
+                                       kgem_debug_print(data, offset, i++, "TM%dS3\n", word - 11);
+                                       kgem_debug_print(data, offset, i++, "TM%dS4: dflt color\n", word - 11);
+                               }
+                       }
+               }
+               assert(len == i);
+               return len;
+       case 0x00:
+               kgem_debug_print(data, offset, 0, "3DSTATE_MAP_STATE\n");
+               len = (data[0] & 0x0000003f) + 2;
+               kgem_debug_print(data, offset, 1, "mask\n");
+
+               i = 2;
+               for (map = 0; map <= 15; map++) {
+                       if (data[1] & (1 << map)) {
+                               int width, height, pitch, dword;
+                               struct drm_i915_gem_relocation_entry *reloc;
+                               const char *tiling;
+
+                               reloc = kgem_debug_get_reloc_entry(kgem, &data[i] - kgem->batch);
+                               assert(reloc->target_handle);
+
+                               dword = data[i];
+                               kgem_debug_print(data, offset, i++, "map %d MS2 %s%s%s, handle=%d\n", map,
+                                         dword&(1<<31)?"untrusted surface, ":"",
+                                         dword&(1<<1)?"vertical line stride enable, ":"",
+                                         dword&(1<<0)?"vertical ofs enable, ":"",
+                                         reloc->target_handle);
+
+                               dword = data[i];
+                               width = ((dword >> 10) & ((1 << 11) - 1))+1;
+                               height = ((dword >> 21) & ((1 << 11) - 1))+1;
+
+                               tiling = "none";
+                               if (dword & (1 << 2))
+                                       tiling = "fenced";
+                               else if (dword & (1 << 1))
+                                       tiling = dword & (1 << 0) ? "Y" : "X";
+                               type = " BAD";
+                               format = " (invalid)";
+                               switch ((dword>>7) & 0x7) {
+                               case 1:
+                                       type = "8";
+                                       switch ((dword>>3) & 0xf) {
+                                       case 0: format = "I"; break;
+                                       case 1: format = "L"; break;
+                                       case 4: format = "A"; break;
+                                       case 5: format = " mono"; break;
+                                       }
+                                       break;
+                               case 2:
+                                       type = "16";
+                                       switch ((dword>>3) & 0xf) {
+                                       case 0: format = " rgb565"; break;
+                                       case 1: format = " argb1555"; break;
+                                       case 2: format = " argb4444"; break;
+                                       case 3: format = " ay88"; break;
+                                       case 5: format = " 88dvdu"; break;
+                                       case 6: format = " bump655"; break;
+                                       case 7: format = "I"; break;
+                                       case 8: format = "L"; break;
+                                       case 9: format = "A"; break;
+                                       }
+                                       break;
+                               case 3:
+                                       type = "32";
+                                       switch ((dword>>3) & 0xf) {
+                                       case 0: format = " argb8888"; break;
+                                       case 1: format = " abgr8888"; break;
+                                       case 2: format = " xrgb8888"; break;
+                                       case 3: format = " xbgr8888"; break;
+                                       case 4: format = " qwvu8888"; break;
+                                       case 5: format = " axvu8888"; break;
+                                       case 6: format = " lxvu8888"; break;
+                                       case 7: format = " xlvu8888"; break;
+                                       case 8: format = " argb2101010"; break;
+                                       case 9: format = " abgr2101010"; break;
+                                       case 10: format = " awvu2101010"; break;
+                                       case 11: format = " gr1616"; break;
+                                       case 12: format = " vu1616"; break;
+                                       case 13: format = " xI824"; break;
+                                       case 14: format = " xA824"; break;
+                                       case 15: format = " xL824"; break;
+                                       }
+                                       break;
+                               case 5:
+                                       type = "422";
+                                       switch ((dword>>3) & 0xf) {
+                                       case 0: format = " yuv_swapy"; break;
+                                       case 1: format = " yuv"; break;
+                                       case 2: format = " yuv_swapuv"; break;
+                                       case 3: format = " yuv_swapuvy"; break;
+                                       }
+                                       break;
+                               case 6:
+                                       type = "compressed";
+                                       switch ((dword>>3) & 0x7) {
+                                       case 0: format = " dxt1"; break;
+                                       case 1: format = " dxt2_3"; break;
+                                       case 2: format = " dxt4_5"; break;
+                                       case 3: format = " fxt1"; break;
+                                       case 4: format = " dxt1_rb"; break;
+                                       }
+                                       break;
+                               case 7:
+                                       type = "4b indexed";
+                                       switch ((dword>>3) & 0xf) {
+                                       case 7: format = " argb8888"; break;
+                                       }
+                                       break;
+                               default:
+                                       format = "BAD";
+                                       break;
+                               }
+                               dword = data[i];
+                               kgem_debug_print(data, offset, i++, "map %d MS3 [width=%d, height=%d, format=%s%s, tiling=%s%s]\n",
+                                         map, width, height, type, format, tiling,
+                                         dword&(1<<9)?" palette select":"");
+
+                               dword = data[i];
+                               pitch = 4*(((dword >> 21) & ((1 << 11) - 1))+1);
+                               kgem_debug_print(data, offset, i++, "map %d MS4 [pitch=%d, max_lod=%i, vol_depth=%i, cube_face_ena=%x, %s]\n",
+                                         map, pitch,
+                                         (dword>>9)&0x3f, dword&0xff, (dword>>15)&0x3f,
+                                         dword&(1<<8)?"miplayout legacy":"miplayout right");
+                       }
+               }
+               assert(len == i);
+               return len;
+       case 0x06:
+               kgem_debug_print(data, offset, 0, "3DSTATE_PIXEL_SHADER_CONSTANTS\n");
+               len = (data[0] & 0x000000ff) + 2;
+
+               i = 2;
+               for (c = 0; c <= 31; c++) {
+                       if (data[1] & (1 << c)) {
+                               kgem_debug_print(data, offset, i, "C%d.X = %f\n",
+                                         c, int_as_float(data[i]));
+                               i++;
+                               kgem_debug_print(data, offset, i, "C%d.Y = %f\n",
+                                         c, int_as_float(data[i]));
+                               i++;
+                               kgem_debug_print(data, offset, i, "C%d.Z = %f\n",
+                                         c, int_as_float(data[i]));
+                               i++;
+                               kgem_debug_print(data, offset, i, "C%d.W = %f\n",
+                                         c, int_as_float(data[i]));
+                               i++;
+                       }
+               }
+               assert(len == i);
+               return len;
+       case 0x05:
+               kgem_debug_print(data, offset, 0, "3DSTATE_PIXEL_SHADER_PROGRAM\n");
+               len = (data[0] & 0x000000ff) + 2;
+               assert(((len-1) % 3) == 0);
+               assert(len <= 370);
+               i = 1;
+               for (instr = 0; instr < (len - 1) / 3; instr++) {
+                       char instr_prefix[10];
+
+                       sprintf(instr_prefix, "PS%03d", instr);
+                       gen3_decode_instruction(data, offset, i, instr_prefix);
+                       i += 3;
+               }
+               return len;
+       case 0x01:
+               kgem_debug_print(data, offset, 0, "3DSTATE_SAMPLER_STATE\n");
+               kgem_debug_print(data, offset, 1, "mask\n");
+               len = (data[0] & 0x0000003f) + 2;
+               i = 2;
+               for (sampler = 0; sampler <= 15; sampler++) {
+                       if (data[1] & (1 << sampler)) {
+                               uint32_t dword;
+                               const char *mip_filter = "";
+                               dword = data[i];
+                               switch ((dword>>20)&0x3) {
+                               case 0: mip_filter = "none"; break;
+                               case 1: mip_filter = "nearest"; break;
+                               case 3: mip_filter = "linear"; break;
+                               }
+                               kgem_debug_print(data, offset, i++, "sampler %d SS2:%s%s%s "
+                                         "base_mip_level=%i, mip_filter=%s, mag_filter=%s, min_filter=%s "
+                                         "lod_bias=%.2f,%s max_aniso=%i, shadow_func=%s\n", sampler,
+                                         dword&(1<<31)?" reverse gamma,":"",
+                                         dword&(1<<30)?" packed2planar,":"",
+                                         dword&(1<<29)?" colorspace conversion,":"",
+                                         (dword>>22)&0x1f,
+                                         mip_filter,
+                                         gen3_decode_sample_filter(dword>>17),
+                                         gen3_decode_sample_filter(dword>>14),
+                                         ((dword>>5)&0x1ff)/(0x10*1.0),
+                                         dword&(1<<4)?" shadow,":"",
+                                         dword&(1<<3)?4:2,
+                                         gen3_decode_compare_func(dword));
+                               dword = data[i];
+                               kgem_debug_print(data, offset, i++, "sampler %d SS3: min_lod=%.2f,%s "
+                                         "tcmode_x=%s, tcmode_y=%s, tcmode_z=%s,%s texmap_idx=%i,%s\n",
+                                         sampler, ((dword>>24)&0xff)/(0x10*1.0),
+                                         dword&(1<<17)?" kill pixel enable,":"",
+                                         decode_tex_coord_mode(dword>>12),
+                                         decode_tex_coord_mode(dword>>9),
+                                         decode_tex_coord_mode(dword>>6),
+                                         dword&(1<<5)?" normalized coords,":"",
+                                         (dword>>1)&0xf,
+                                         dword&(1<<0)?" deinterlacer,":"");
+                               kgem_debug_print(data, offset, i++, "sampler %d SS4: border color\n",
+                                         sampler);
+                       }
+               }
+               assert(len == i);
+               return len;
+       case 0x85:
+               len = (data[0] & 0x0000000f) + 2;
+               assert(len == 2);
+
+               kgem_debug_print(data, offset, 0,
+                         "3DSTATE_DEST_BUFFER_VARIABLES\n");
+
+               switch ((data[1] >> 8) & 0xf) {
+               case 0x0: format = "g8"; break;
+               case 0x1: format = "x1r5g5b5"; break;
+               case 0x2: format = "r5g6b5"; break;
+               case 0x3: format = "a8r8g8b8"; break;
+               case 0x4: format = "ycrcb_swapy"; break;
+               case 0x5: format = "ycrcb_normal"; break;
+               case 0x6: format = "ycrcb_swapuv"; break;
+               case 0x7: format = "ycrcb_swapuvy"; break;
+               case 0x8: format = "a4r4g4b4"; break;
+               case 0x9: format = "a1r5g5b5"; break;
+               case 0xa: format = "a2r10g10b10"; break;
+               default: format = "BAD"; break;
+               }
+               switch ((data[1] >> 2) & 0x3) {
+               case 0x0: zformat = "u16"; break;
+               case 0x1: zformat = "f16"; break;
+               case 0x2: zformat = "u24x8"; break;
+               default: zformat = "BAD"; break;
+               }
+               kgem_debug_print(data, offset, 1, "%s format, %s depth format, early Z %sabled\n",
+                         format, zformat,
+                         (data[1] & (1 << 31)) ? "en" : "dis");
+               return len;
+
+       case 0x8e:
+               {
+                       const char *name, *tiling;
+
+                       len = (data[0] & 0x0000000f) + 2;
+                       assert(len == 3);
+
+                       switch((data[1] >> 24) & 0x7) {
+                       case 0x3: name = "color"; break;
+                       case 0x7: name = "depth"; break;
+                       default: name = "unknown"; break;
+                       }
+
+                       tiling = "none";
+                       if (data[1] & (1 << 23))
+                               tiling = "fenced";
+                       else if (data[1] & (1 << 22))
+                               tiling = data[1] & (1 << 21) ? "Y" : "X";
+
+                       kgem_debug_print(data, offset, 0, "3DSTATE_BUFFER_INFO\n");
+                       kgem_debug_print(data, offset, 1, "%s, tiling = %s, pitch=%d\n", name, tiling, data[1]&0xffff);
+
+                       kgem_debug_print(data, offset, 2, "address\n");
+                       return len;
+               }
+       case 0x81:
+               len = (data[0] & 0x0000000f) + 2;
+               assert(len == 3);
+
+               kgem_debug_print(data, offset, 0,
+                         "3DSTATE_SCISSOR_RECTANGLE\n");
+               kgem_debug_print(data, offset, 1, "(%d,%d)\n",
+                         data[1] & 0xffff, data[1] >> 16);
+               kgem_debug_print(data, offset, 2, "(%d,%d)\n",
+                         data[2] & 0xffff, data[2] >> 16);
+
+               return len;
+       case 0x80:
+               len = (data[0] & 0x0000000f) + 2;
+               assert(len == 5);
+
+               kgem_debug_print(data, offset, 0,
+                         "3DSTATE_DRAWING_RECTANGLE\n");
+               kgem_debug_print(data, offset, 1, "%s\n",
+                         data[1]&(1<<30)?"depth ofs disabled ":"");
+               kgem_debug_print(data, offset, 2, "(%d,%d)\n",
+                         data[2] & 0xffff, data[2] >> 16);
+               kgem_debug_print(data, offset, 3, "(%d,%d)\n",
+                         data[3] & 0xffff, data[3] >> 16);
+               kgem_debug_print(data, offset, 4, "(%d,%d)\n",
+                         (int16_t)(data[4] & 0xffff),
+                         (int16_t)(data[4] >> 16));
+
+               return len;
+       case 0x9c:
+               len = (data[0] & 0x0000000f) + 2;
+               assert(len == 7);
+
+               kgem_debug_print(data, offset, 0,
+                         "3DSTATE_CLEAR_PARAMETERS\n");
+               kgem_debug_print(data, offset, 1, "prim_type=%s, clear=%s%s%s\n",
+                         data[1]&(1<<16)?"CLEAR_RECT":"ZONE_INIT",
+                         data[1]&(1<<2)?"color,":"",
+                         data[1]&(1<<1)?"depth,":"",
+                         data[1]&(1<<0)?"stencil,":"");
+               kgem_debug_print(data, offset, 2, "clear color\n");
+               kgem_debug_print(data, offset, 3, "clear depth/stencil\n");
+               kgem_debug_print(data, offset, 4, "color value (rgba8888)\n");
+               kgem_debug_print(data, offset, 5, "depth value %f\n",
+                         int_as_float(data[5]));
+               kgem_debug_print(data, offset, 6, "clear stencil\n");
+               return len;
+       }
+
+       for (idx = 0; idx < ARRAY_SIZE(opcodes_3d_1d); idx++) {
+               opcode_3d_1d = &opcodes_3d_1d[idx];
+               if (((data[0] & 0x00ff0000) >> 16) == opcode_3d_1d->opcode) {
+                       len = (data[0] & 0xf) + 2;
+                       kgem_debug_print(data, offset, 0, "%s\n", opcode_3d_1d->name);
+                       for (i = 1; i < len; i++)
+                               kgem_debug_print(data, offset, i, "dword %d\n", i);
+
+                       return len;
+               }
+       }
+
+       kgem_debug_print(data, offset, 0, "3D UNKNOWN: 3d_1d opcode = 0x%x\n", opcode);
+       assert(0);
+       return 1;
+}
+
+#define VERTEX_OUT(fmt, ...) do {                                      \
+       kgem_debug_print(data, offset, i, " V%d."fmt"\n", vertex, __VA_ARGS__); \
+       i++;                                                            \
+} while (0)
+
+static int
+gen3_decode_3d_primitive(struct kgem *kgem, uint32_t offset)
+{
+       uint32_t *data = kgem->batch + offset;
+       char immediate = (data[0] & (1 << 23)) == 0;
+       unsigned int len, i, ret;
+       const char *primtype;
+       unsigned int vertex = 0;
+
+       switch ((data[0] >> 18) & 0xf) {
+       case 0x0: primtype = "TRILIST"; break;
+       case 0x1: primtype = "TRISTRIP"; break;
+       case 0x2: primtype = "TRISTRIP_REVERSE"; break;
+       case 0x3: primtype = "TRIFAN"; break;
+       case 0x4: primtype = "POLYGON"; break;
+       case 0x5: primtype = "LINELIST"; break;
+       case 0x6: primtype = "LINESTRIP"; break;
+       case 0x7: primtype = "RECTLIST"; break;
+       case 0x8: primtype = "POINTLIST"; break;
+       case 0x9: primtype = "DIB"; break;
+       case 0xa: primtype = "CLEAR_RECT"; assert(0); break;
+       default: primtype = "unknown"; break;
+       }
+
+       gen3_update_vertex_elements_offsets(kgem);
+
+       /* XXX: 3DPRIM_DIB not supported */
+       if (immediate) {
+               len = (data[0] & 0x0003ffff) + 2;
+               kgem_debug_print(data, offset, 0, "3DPRIMITIVE inline %s\n", primtype);
+               for (i = 1; i < len; ) {
+                       ErrorF("    [%d]: ", vertex);
+                       i += inline_vertex_out(kgem, data + i) / sizeof(uint32_t);
+                       ErrorF("\n");
+                       vertex++;
+               }
+
+               ret = len;
+       } else {
+               /* indirect vertices */
+               len = data[0] & 0x0000ffff; /* index count */
+               if (data[0] & (1 << 17)) {
+                       /* random vertex access */
+                       kgem_debug_print(data, offset, 0,
+                                 "3DPRIMITIVE random indirect %s (%d)\n", primtype, len);
+                       assert(0);
+                       if (len == 0) {
+                               /* vertex indices continue until 0xffff is found */
+                       } else {
+                               /* fixed size vertex index buffer */
+                       }
+                       ret = (len + 1) / 2 + 1;
+                       goto out;
+               } else {
+                       /* sequential vertex access */
+                       vertex = data[1] & 0xffff;
+                       kgem_debug_print(data, offset, 0,
+                                 "3DPRIMITIVE sequential indirect %s, %d starting from "
+                                 "%d\n", primtype, len, vertex);
+                       kgem_debug_print(data, offset, 1, "  start\n");
+                       for (i = 0; i < len; i++) {
+                               ErrorF("    [%d]: ", vertex);
+                               indirect_vertex_out(kgem, vertex++);
+                               ErrorF("\n");
+                       }
+                       ret = 2;
+                       goto out;
+               }
+       }
+
+out:
+       return ret;
+}
+
+int kgem_gen3_decode_3d(struct kgem *kgem, uint32_t offset)
+{
+    static const struct {
+       uint32_t opcode;
+       int min_len;
+       int max_len;
+       const char *name;
+    } opcodes[] = {
+       { 0x06, 1, 1, "3DSTATE_ANTI_ALIASING" },
+       { 0x08, 1, 1, "3DSTATE_BACKFACE_STENCIL_OPS" },
+       { 0x09, 1, 1, "3DSTATE_BACKFACE_STENCIL_MASKS" },
+       { 0x16, 1, 1, "3DSTATE_COORD_SET_BINDINGS" },
+       { 0x15, 1, 1, "3DSTATE_FOG_COLOR" },
+       { 0x0b, 1, 1, "3DSTATE_INDEPENDENT_ALPHA_BLEND" },
+       { 0x0d, 1, 1, "3DSTATE_MODES_4" },
+       { 0x0c, 1, 1, "3DSTATE_MODES_5" },
+       { 0x07, 1, 1, "3DSTATE_RASTERIZATION_RULES" },
+    };
+    uint32_t *data = kgem->batch + offset;
+    uint32_t opcode;
+    unsigned int idx;
+
+    opcode = (data[0] & 0x1f000000) >> 24;
+
+    switch (opcode) {
+    case 0x1f:
+       return gen3_decode_3d_primitive(kgem, offset);
+    case 0x1d:
+       return gen3_decode_3d_1d(kgem, offset);
+    case 0x1c:
+       return gen3_decode_3d_1c(kgem, offset);
+    }
+
+    for (idx = 0; idx < ARRAY_SIZE(opcodes); idx++) {
+       if (opcode == opcodes[idx].opcode) {
+           unsigned int len = 1, i;
+
+           kgem_debug_print(data, offset, 0, "%s\n", opcodes[idx].name);
+           if (opcodes[idx].max_len > 1) {
+               len = (data[0] & 0xff) + 2;
+               assert(len >= opcodes[idx].min_len ||
+                      len <= opcodes[idx].max_len);
+           }
+
+           for (i = 1; i < len; i++)
+               kgem_debug_print(data, offset, i, "dword %d\n", i);
+           return len;
+       }
+    }
+
+    kgem_debug_print(data, offset, 0, "3D UNKNOWN: 3d opcode = 0x%x\n", opcode);
+    return 1;
+}
+
+
+void kgem_gen3_finish_state(struct kgem *kgem)
+{
+       memset(&state, 0, sizeof(state));
+}
diff --git a/src/sna/kgem_debug_gen4.c b/src/sna/kgem_debug_gen4.c
new file mode 100644 (file)
index 0000000..9b80dc8
--- /dev/null
@@ -0,0 +1,688 @@
+/*
+ * Copyright © 2007-2011 Intel 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.
+ *
+ * Authors:
+ *    Eric Anholt <eric@anholt.net>
+ *    Chris Wilson <chris@chris-wilson.co.uk>
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/mman.h>
+#include <assert.h>
+
+#include "sna.h"
+#include "sna_reg.h"
+
+#include "gen4_render.h"
+
+#include "kgem_debug.h"
+
+static struct state {
+       struct vertex_buffer {
+               int handle;
+               void *base;
+               const char *ptr;
+               int pitch;
+
+               struct kgem_bo *current;
+       } vb[33];
+       struct vertex_elements {
+               int buffer;
+               int offset;
+               bool valid;
+               uint32_t type;
+               uint8_t swizzle[4];
+       } ve[33];
+       int num_ve;
+
+       struct dynamic_state {
+               struct kgem_bo *current;
+               void *base, *ptr;
+       } dynamic_state;
+} state;
+
+static void gen4_update_vertex_buffer(struct kgem *kgem, const uint32_t *data)
+{
+       uint32_t reloc = sizeof(uint32_t) * (&data[1] - kgem->batch);
+       struct kgem_bo *bo = NULL;
+       void *base, *ptr;
+       int i;
+
+       for (i = 0; i < kgem->nreloc; i++)
+               if (kgem->reloc[i].offset == reloc)
+                       break;
+       assert(i < kgem->nreloc);
+       reloc = kgem->reloc[i].target_handle;
+
+       if (reloc == 0) {
+               base = kgem->batch;
+       } else {
+               list_for_each_entry(bo, &kgem->next_request->buffers, request)
+                       if (bo->handle == reloc)
+                               break;
+               assert(&bo->request != &kgem->next_request->buffers);
+               base = kgem_bo_map__debug(kgem, bo);
+       }
+       ptr = (char *)base + kgem->reloc[i].delta;
+
+       i = data[0] >> 27;
+
+       state.vb[i].current = bo;
+       state.vb[i].base = base;
+       state.vb[i].ptr = ptr;
+       state.vb[i].pitch = data[0] & 0x7ff;
+}
+
+static uint32_t
+get_ve_component(uint32_t data, int component)
+{
+       return (data >> (16 + (3 - component) * 4)) & 0x7;
+}
+
+static void gen4_update_vertex_elements(struct kgem *kgem, int id, const uint32_t *data)
+{
+       state.ve[id].buffer = data[0] >> 27;
+       state.ve[id].valid = !!(data[0] & (1 << 26));
+       state.ve[id].type = (data[0] >> 16) & 0x1ff;
+       state.ve[id].offset = data[0] & 0x7ff;
+       state.ve[id].swizzle[0] = get_ve_component(data[1], 0);
+       state.ve[id].swizzle[1] = get_ve_component(data[1], 1);
+       state.ve[id].swizzle[2] = get_ve_component(data[1], 2);
+       state.ve[id].swizzle[3] = get_ve_component(data[1], 3);
+}
+
+static void vertices_sint16_out(const struct vertex_elements *ve, const int16_t *v, int max)
+{
+       int c;
+
+       ErrorF("(");
+       for (c = 0; c < max; c++) {
+               switch (ve->swizzle[c]) {
+               case 0: ErrorF("#"); break;
+               case 1: ErrorF("%d", v[c]); break;
+               case 2: ErrorF("0.0"); break;
+               case 3: ErrorF("1.0"); break;
+               case 4: ErrorF("0x1"); break;
+               case 5: break;
+               default: ErrorF("?");
+               }
+               if (c < 3)
+                       ErrorF(", ");
+       }
+       for (; c < 4; c++) {
+               switch (ve->swizzle[c]) {
+               case 0: ErrorF("#"); break;
+               case 1: ErrorF("1.0"); break;
+               case 2: ErrorF("0.0"); break;
+               case 3: ErrorF("1.0"); break;
+               case 4: ErrorF("0x1"); break;
+               case 5: break;
+               default: ErrorF("?");
+               }
+               if (c < 3)
+                       ErrorF(", ");
+       }
+       ErrorF(")");
+}
+
+static void vertices_float_out(const struct vertex_elements *ve, const float *f, int max)
+{
+       int c, o;
+
+       ErrorF("(");
+       for (c = o = 0; c < 4 && o < max; c++) {
+               switch (ve->swizzle[c]) {
+               case 0: ErrorF("#"); break;
+               case 1: ErrorF("%f", f[o++]); break;
+               case 2: ErrorF("0.0"); break;
+               case 3: ErrorF("1.0"); break;
+               case 4: ErrorF("0x1"); break;
+               case 5: break;
+               default: ErrorF("?");
+               }
+               if (c < 3)
+                       ErrorF(", ");
+       }
+       for (; c < 4; c++) {
+               switch (ve->swizzle[c]) {
+               case 0: ErrorF("#"); break;
+               case 1: ErrorF("1.0"); break;
+               case 2: ErrorF("0.0"); break;
+               case 3: ErrorF("1.0"); break;
+               case 4: ErrorF("0x1"); break;
+               case 5: break;
+               default: ErrorF("?");
+               }
+               if (c < 3)
+                       ErrorF(", ");
+       }
+       ErrorF(")");
+}
+
+static void ve_out(const struct vertex_elements *ve, const void *ptr)
+{
+       switch (ve->type) {
+       case GEN4_SURFACEFORMAT_R32_FLOAT:
+               vertices_float_out(ve, ptr, 1);
+               break;
+       case GEN4_SURFACEFORMAT_R32G32_FLOAT:
+               vertices_float_out(ve, ptr, 2);
+               break;
+       case GEN4_SURFACEFORMAT_R32G32B32_FLOAT:
+               vertices_float_out(ve, ptr, 3);
+               break;
+       case GEN4_SURFACEFORMAT_R32G32B32A32_FLOAT:
+               vertices_float_out(ve, ptr, 4);
+               break;
+       case GEN4_SURFACEFORMAT_R16_SINT:
+               vertices_sint16_out(ve, ptr, 1);
+               break;
+       case GEN4_SURFACEFORMAT_R16G16_SINT:
+               vertices_sint16_out(ve, ptr, 2);
+               break;
+       case GEN4_SURFACEFORMAT_R16G16B16A16_SINT:
+               vertices_sint16_out(ve, ptr, 4);
+               break;
+       case GEN4_SURFACEFORMAT_R16_SSCALED:
+               vertices_sint16_out(ve, ptr, 1);
+               break;
+       case GEN4_SURFACEFORMAT_R16G16_SSCALED:
+               vertices_sint16_out(ve, ptr, 2);
+               break;
+       case GEN4_SURFACEFORMAT_R16G16B16A16_SSCALED:
+               vertices_sint16_out(ve, ptr, 4);
+               break;
+       }
+}
+
+static void indirect_vertex_out(struct kgem *kgem, uint32_t v)
+{
+       int i = 0;
+
+       do {
+               const struct vertex_elements *ve = &state.ve[i];
+               const struct vertex_buffer *vb = &state.vb[ve->buffer];
+               const void *ptr = vb->ptr + v * vb->pitch + ve->offset;
+
+               if (!ve->valid)
+                       continue;
+
+               ve_out(ve, ptr);
+
+               while (++i <= state.num_ve && !state.ve[i].valid)
+                       ;
+
+               if (i <= state.num_ve)
+                       ErrorF(", ");
+       } while (i <= state.num_ve);
+}
+
+static void primitive_out(struct kgem *kgem, uint32_t *data)
+{
+       int n;
+
+       assert((data[0] & (1<<15)) == 0); /* XXX index buffers */
+
+       for (n = 0; n < data[1]; n++) {
+               int v = data[2] + n;
+               ErrorF("        [%d:%d] = ", n, v);
+               indirect_vertex_out(kgem, v);
+               ErrorF("\n");
+       }
+}
+
+static void
+state_base_out(uint32_t *data, uint32_t offset, unsigned int index,
+              const char *name)
+{
+    if (data[index] & 1)
+       kgem_debug_print(data, offset, index,
+                 "%s state base address 0x%08x\n",
+                 name, data[index] & ~1);
+    else
+       kgem_debug_print(data, offset, index,
+                 "%s state base not updated\n",
+                 name);
+}
+
+static void
+state_max_out(uint32_t *data, uint32_t offset, unsigned int index,
+             const char *name)
+{
+       if (data[index] == 1)
+               kgem_debug_print(data, offset, index,
+                         "%s state upper bound disabled\n", name);
+       else if (data[index] & 1)
+               kgem_debug_print(data, offset, index,
+                         "%s state upper bound 0x%08x\n",
+                         name, data[index] & ~1);
+       else
+               kgem_debug_print(data, offset, index,
+                         "%s state upper bound not updated\n",
+                         name);
+}
+
+static const char *
+get_965_surfacetype(unsigned int surfacetype)
+{
+       switch (surfacetype) {
+       case 0: return "1D";
+       case 1: return "2D";
+       case 2: return "3D";
+       case 3: return "CUBE";
+       case 4: return "BUFFER";
+       case 7: return "NULL";
+       default: return "unknown";
+       }
+}
+
+static const char *
+get_965_depthformat(unsigned int depthformat)
+{
+       switch (depthformat) {
+       case 0: return "s8_z24float";
+       case 1: return "z32float";
+       case 2: return "z24s8";
+       case 5: return "z16";
+       default: return "unknown";
+       }
+}
+
+static const char *
+get_965_element_component(uint32_t data, int component)
+{
+       uint32_t component_control = (data >> (16 + (3 - component) * 4)) & 0x7;
+
+       switch (component_control) {
+       case 0:
+               return "nostore";
+       case 1:
+               switch (component) {
+               case 0: return "X";
+               case 1: return "Y";
+               case 2: return "Z";
+               case 3: return "W";
+               default: return "fail";
+               }
+       case 2:
+               return "0.0";
+       case 3:
+               return "1.0";
+       case 4:
+               return "0x1";
+       case 5:
+               return "VID";
+       default:
+               return "fail";
+       }
+}
+
+static const char *
+get_965_prim_type(uint32_t data)
+{
+       uint32_t primtype = (data >> 10) & 0x1f;
+
+       switch (primtype) {
+       case 0x01: return "point list";
+       case 0x02: return "line list";
+       case 0x03: return "line strip";
+       case 0x04: return "tri list";
+       case 0x05: return "tri strip";
+       case 0x06: return "tri fan";
+       case 0x07: return "quad list";
+       case 0x08: return "quad strip";
+       case 0x09: return "line list adj";
+       case 0x0a: return "line strip adj";
+       case 0x0b: return "tri list adj";
+       case 0x0c: return "tri strip adj";
+       case 0x0d: return "tri strip reverse";
+       case 0x0e: return "polygon";
+       case 0x0f: return "rect list";
+       case 0x10: return "line loop";
+       case 0x11: return "point list bf";
+       case 0x12: return "line strip cont";
+       case 0x13: return "line strip bf";
+       case 0x14: return "line strip cont bf";
+       case 0x15: return "tri fan no stipple";
+       default: return "fail";
+       }
+}
+
+#if 0
+struct reloc {
+       struct kgem_bo *bo;
+       void *base;
+};
+
+static void *
+get_reloc(struct kgem *kgem,
+         void *base, const uint32_t *reloc,
+         struct reloc *r)
+{
+       uint32_t delta = *reloc;
+
+       memset(r, 0, sizeof(*r));
+
+       if (base == 0) {
+               uint32_t handle = sizeof(uint32_t) * (reloc - kgem->batch);
+               struct kgem_bo *bo = NULL;
+               int i;
+
+               for (i = 0; i < kgem->nreloc; i++)
+                       if (kgem->reloc[i].offset == handle)
+                               break;
+               assert(i < kgem->nreloc);
+               handle = kgem->reloc[i].target_handle;
+               delta = kgem->reloc[i].delta;
+
+               if (handle == 0) {
+                       base = kgem->batch;
+               } else {
+                       list_for_each_entry(bo, &kgem->next_request->buffers, request)
+                               if (bo->handle == handle)
+                                       break;
+                       assert(&bo->request != &kgem->next_request->buffers);
+                       base = kgem_bo_map__debug(kgem, bo);
+                       r->bo = bo;
+                       r->base = base;
+               }
+       }
+
+       return (char *)base + delta;
+}
+#endif
+
+int kgem_gen4_decode_3d(struct kgem *kgem, uint32_t offset)
+{
+       static const struct {
+               uint32_t opcode;
+               int min_len;
+               int max_len;
+               const char *name;
+       } opcodes[] = {
+               { 0x6000, 3, 3, "URB_FENCE" },
+               { 0x6001, 2, 2, "CS_URB_FENCE" },
+               { 0x6002, 2, 2, "CONSTANT_BUFFER" },
+               { 0x6101, 6, 6, "STATE_BASE_ADDRESS" },
+               { 0x6102, 2, 2 , "STATE_SIP" },
+               { 0x6104, 1, 1, "3DSTATE_PIPELINE_SELECT" },
+               { 0x680b, 1, 1, "3DSTATE_VF_STATISTICS" },
+               { 0x6904, 1, 1, "3DSTATE_PIPELINE_SELECT" },
+               { 0x7800, 7, 7, "3DSTATE_PIPELINED_POINTERS" },
+               { 0x7801, 6, 6, "3DSTATE_BINDING_TABLE_POINTERS" },
+               { 0x7808, 5, 257, "3DSTATE_VERTEX_BUFFERS" },
+               { 0x7809, 3, 256, "3DSTATE_VERTEX_ELEMENTS" },
+               { 0x780a, 3, 3, "3DSTATE_INDEX_BUFFER" },
+               { 0x780b, 1, 1, "3DSTATE_VF_STATISTICS" },
+               { 0x7900, 4, 4, "3DSTATE_DRAWING_RECTANGLE" },
+               { 0x7901, 5, 5, "3DSTATE_CONSTANT_COLOR" },
+               { 0x7905, 5, 7, "3DSTATE_DEPTH_BUFFER" },
+               { 0x7906, 2, 2, "3DSTATE_POLY_STIPPLE_OFFSET" },
+               { 0x7907, 33, 33, "3DSTATE_POLY_STIPPLE_PATTERN" },
+               { 0x7908, 3, 3, "3DSTATE_LINE_STIPPLE" },
+               { 0x7909, 2, 2, "3DSTATE_GLOBAL_DEPTH_OFFSET_CLAMP" },
+               { 0x7909, 2, 2, "3DSTATE_CLEAR_PARAMS" },
+               { 0x790a, 3, 3, "3DSTATE_AA_LINE_PARAMETERS" },
+               { 0x790b, 4, 4, "3DSTATE_GS_SVB_INDEX" },
+               { 0x790d, 3, 3, "3DSTATE_MULTISAMPLE" },
+               { 0x7910, 2, 2, "3DSTATE_CLEAR_PARAMS" },
+               { 0x7b00, 6, 6, "3DPRIMITIVE" },
+               { 0x7805, 3, 3, "3DSTATE_URB" },
+               { 0x7815, 5, 5, "3DSTATE_CONSTANT_VS_STATE" },
+               { 0x7816, 5, 5, "3DSTATE_CONSTANT_GS_STATE" },
+               { 0x7817, 5, 5, "3DSTATE_CONSTANT_PS_STATE" },
+               { 0x7818, 2, 2, "3DSTATE_SAMPLE_MASK" },
+       };
+       uint32_t *data = kgem->batch + offset;
+       uint32_t op;
+       unsigned int len;
+       int i;
+       const char *desc1 = NULL;
+
+       len = (data[0] & 0xff) + 2;
+       op = (data[0] & 0xffff0000) >> 16;
+       switch (op) {
+       case 0x6000:
+               assert(len == 3);
+
+               kgem_debug_print(data, offset, 0, "URB_FENCE: %s%s%s%s%s%s\n",
+                         (data[0] >> 13) & 1 ? "cs " : "",
+                         (data[0] >> 12) & 1 ? "vfe " : "",
+                         (data[0] >> 11) & 1 ? "sf " : "",
+                         (data[0] >> 10) & 1 ? "clip " : "",
+                         (data[0] >> 9)  & 1 ? "gs " : "",
+                         (data[0] >> 8)  & 1 ? "vs " : "");
+               kgem_debug_print(data, offset, 1,
+                         "vs fence: %d, gs_fence: %d, clip_fence: %d\n",
+                         data[1] & 0x3ff,
+                         (data[1] >> 10) & 0x3ff,
+                         (data[1] >> 20) & 0x3ff);
+               kgem_debug_print(data, offset, 2,
+                         "sf fence: %d, vfe_fence: %d, cs_fence: %d\n",
+                          data[2] & 0x3ff,
+                          (data[2] >> 10) & 0x3ff,
+                          (data[2] >> 20) & 0x7ff);
+               return len;
+
+       case 0x6001:
+               kgem_debug_print(data, offset, 0, "CS_URB_STATE\n");
+               kgem_debug_print(data, offset, 1, "entry_size: %d [%d bytes], n_entries: %d\n",
+                         (data[1] >> 4) & 0x1f,
+                         (((data[1] >> 4) & 0x1f) + 1) * 64,
+                         data[1] & 0x7);
+               return len;
+       case 0x6002:
+               kgem_debug_print(data, offset, 0, "CONSTANT_BUFFER: %s\n",
+                         (data[0] >> 8) & 1 ? "valid" : "invalid");
+               kgem_debug_print(data, offset, 1, "offset: 0x%08x, length: %d bytes\n",
+                         data[1] & ~0x3f, ((data[1] & 0x3f) + 1) * 64);
+               return len;
+       case 0x6101:
+               i = 0;
+               kgem_debug_print(data, offset, i++, "STATE_BASE_ADDRESS\n");
+               assert(len == 6);
+
+               state_base_out(data, offset, i++, "general");
+               state_base_out(data, offset, i++, "surface");
+               state_base_out(data, offset, i++, "media");
+
+               state_max_out(data, offset, i++, "general");
+               state_max_out(data, offset, i++, "media");
+
+               return len;
+
+       case 0x7801:
+               assert(len == 6);
+
+               kgem_debug_print(data, offset, 0,
+                         "3DSTATE_BINDING_TABLE_POINTERS\n");
+               kgem_debug_print(data, offset, 1, "VS binding table\n");
+               kgem_debug_print(data, offset, 2, "GS binding table\n");
+               kgem_debug_print(data, offset, 3, "CLIP binding table\n");
+               kgem_debug_print(data, offset, 4, "SF binding table\n");
+               kgem_debug_print(data, offset, 5, "WM binding table\n");
+
+               return len;
+
+       case 0x7808:
+               assert((len - 1) % 4 == 0);
+               kgem_debug_print(data, offset, 0, "3DSTATE_VERTEX_BUFFERS\n");
+
+               for (i = 1; i < len;) {
+                       gen4_update_vertex_buffer(kgem, data + i);
+
+                       kgem_debug_print(data, offset, i, "buffer %d: %s, pitch %db\n",
+                                 data[i] >> 27,
+                                 data[i] & (1 << 20) ? "random" : "sequential",
+                                 data[i] & 0x07ff);
+                       i++;
+                       kgem_debug_print(data, offset, i++, "buffer address\n");
+                       kgem_debug_print(data, offset, i++, "max index\n");
+                       kgem_debug_print(data, offset, i++, "mbz\n");
+               }
+               return len;
+
+       case 0x7809:
+               assert((len + 1) % 2 == 0);
+               kgem_debug_print(data, offset, 0, "3DSTATE_VERTEX_ELEMENTS\n");
+
+               memset(state.ve, 0, sizeof(state.ve)); /* XXX? */
+               for (i = 1; i < len;) {
+                       gen4_update_vertex_elements(kgem, (i - 1)/2, data + i);
+
+                       kgem_debug_print(data, offset, i, "buffer %d: %svalid, type 0x%04x, "
+                                 "src offset 0x%04x bytes\n",
+                                 data[i] >> 27,
+                                 data[i] & (1 << 26) ? "" : "in",
+                                 (data[i] >> 16) & 0x1ff,
+                                 data[i] & 0x07ff);
+                       i++;
+                       kgem_debug_print(data, offset, i, "(%s, %s, %s, %s), "
+                                 "dst offset 0x%02x bytes\n",
+                                 get_965_element_component(data[i], 0),
+                                 get_965_element_component(data[i], 1),
+                                 get_965_element_component(data[i], 2),
+                                 get_965_element_component(data[i], 3),
+                                 (data[i] & 0xff) * 4);
+                       i++;
+               }
+               state.num_ve = (len - 1) / 2; /* XXX? */
+               return len;
+
+       case 0x780a:
+               assert(len == 3);
+               kgem_debug_print(data, offset, 0, "3DSTATE_INDEX_BUFFER\n");
+               kgem_debug_print(data, offset, 1, "beginning buffer address\n");
+               kgem_debug_print(data, offset, 2, "ending buffer address\n");
+               return len;
+
+       case 0x7900:
+               assert(len == 4);
+               kgem_debug_print(data, offset, 0,
+                         "3DSTATE_DRAWING_RECTANGLE\n");
+               kgem_debug_print(data, offset, 1, "top left: %d,%d\n",
+                         data[1] & 0xffff,
+                         (data[1] >> 16) & 0xffff);
+               kgem_debug_print(data, offset, 2, "bottom right: %d,%d\n",
+                         data[2] & 0xffff,
+                         (data[2] >> 16) & 0xffff);
+               kgem_debug_print(data, offset, 3, "origin: %d,%d\n",
+                         (int)data[3] & 0xffff,
+                         ((int)data[3] >> 16) & 0xffff);
+               return len;
+
+       case 0x7905:
+               assert(len == 7);
+               kgem_debug_print(data, offset, 0,
+                         "3DSTATE_DEPTH_BUFFER\n");
+               kgem_debug_print(data, offset, 1, "%s, %s, pitch = %d bytes, %stiled, HiZ %d, Seperate Stencil %d\n",
+                         get_965_surfacetype(data[1] >> 29),
+                         get_965_depthformat((data[1] >> 18) & 0x7),
+                         (data[1] & 0x0001ffff) + 1,
+                         data[1] & (1 << 27) ? "" : "not ",
+                         (data[1] & (1 << 22)) != 0,
+                         (data[1] & (1 << 21)) != 0);
+               kgem_debug_print(data, offset, 2, "depth offset\n");
+               kgem_debug_print(data, offset, 3, "%dx%d\n",
+                         ((data[3] & 0x0007ffc0) >> 6) + 1,
+                         ((data[3] & 0xfff80000) >> 19) + 1);
+               kgem_debug_print(data, offset, 4, "volume depth\n");
+               kgem_debug_print(data, offset, 5, "\n");
+               kgem_debug_print(data, offset, 6, "\n");
+               return len;
+
+       case 0x7a00:
+               assert(len == 4 || len == 5);
+               switch ((data[1] >> 14) & 0x3) {
+               case 0: desc1 = "no write"; break;
+               case 1: desc1 = "qword write"; break;
+               case 2: desc1 = "PS_DEPTH_COUNT write"; break;
+               case 3: desc1 = "TIMESTAMP write"; break;
+               }
+               kgem_debug_print(data, offset, 0, "PIPE_CONTROL\n");
+               kgem_debug_print(data, offset, 1,
+                         "%s, %scs stall, %stlb invalidate, "
+                         "%ssync gfdt, %sdepth stall, %sRC write flush, "
+                         "%sinst flush, %sTC flush\n",
+                         desc1,
+                         data[1] & (1 << 20) ? "" : "no ",
+                         data[1] & (1 << 18) ? "" : "no ",
+                         data[1] & (1 << 17) ? "" : "no ",
+                         data[1] & (1 << 13) ? "" : "no ",
+                         data[1] & (1 << 12) ? "" : "no ",
+                         data[1] & (1 << 11) ? "" : "no ",
+                         data[1] & (1 << 10) ? "" : "no ");
+               if (len == 5) {
+                       kgem_debug_print(data, offset, 2, "destination address\n");
+                       kgem_debug_print(data, offset, 3, "immediate dword low\n");
+                       kgem_debug_print(data, offset, 4, "immediate dword high\n");
+               } else {
+                       for (i = 2; i < len; i++) {
+                               kgem_debug_print(data, offset, i, "\n");
+                       }
+               }
+               return len;
+
+       case 0x7b00:
+               assert(len == 6);
+               kgem_debug_print(data, offset, 0,
+                         "3DPRIMITIVE: %s %s\n",
+                         get_965_prim_type(data[0]),
+                         (data[0] & (1 << 15)) ? "random" : "sequential");
+               kgem_debug_print(data, offset, 1, "vertex count\n");
+               kgem_debug_print(data, offset, 2, "start vertex\n");
+               kgem_debug_print(data, offset, 3, "instance count\n");
+               kgem_debug_print(data, offset, 4, "start instance\n");
+               kgem_debug_print(data, offset, 5, "index bias\n");
+               primitive_out(kgem, data);
+               return len;
+       }
+
+       /* For the rest, just dump the bytes */
+       for (i = 0; i < ARRAY_SIZE(opcodes); i++)
+               if (op == opcodes[i].opcode)
+                       break;
+
+       assert(i < ARRAY_SIZE(opcodes));
+
+       len = 1;
+       kgem_debug_print(data, offset, 0, "%s\n", opcodes[i].name);
+       if (opcodes[i].max_len > 1) {
+               len = (data[0] & 0xff) + 2;
+               assert(len >= opcodes[i].min_len &&
+                      len <= opcodes[i].max_len);
+       }
+
+       for (i = 1; i < len; i++)
+               kgem_debug_print(data, offset, i, "dword %d\n", i);
+
+       return len;
+}
+
+void kgem_gen4_finish_state(struct kgem *kgem)
+{
+       memset(&state, 0, sizeof(state));
+}
diff --git a/src/sna/kgem_debug_gen5.c b/src/sna/kgem_debug_gen5.c
new file mode 100644 (file)
index 0000000..e23ceb1
--- /dev/null
@@ -0,0 +1,664 @@
+/*
+ * Copyright © 2007-2011 Intel 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.
+ *
+ * Authors:
+ *    Eric Anholt <eric@anholt.net>
+ *    Chris Wilson <chris@chris-wilson.co.uk>
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/mman.h>
+#include <assert.h>
+
+#include "sna.h"
+#include "sna_reg.h"
+
+#include "gen5_render.h"
+
+#include "kgem_debug.h"
+
+static struct state {
+       struct vertex_buffer {
+               int handle;
+               void *base;
+               int size;
+               const char *ptr;
+               int pitch;
+
+               struct kgem_bo *current;
+       } vb[17];
+       struct vertex_elements {
+               int buffer;
+               int offset;
+               bool valid;
+               uint32_t type;
+               uint8_t swizzle[4];
+       } ve[17];
+       int num_ve;
+
+       struct dynamic_state {
+               struct kgem_bo *current;
+               void *base, *ptr;
+       } dynamic_state;
+} state;
+
+static void gen5_update_vertex_buffer(struct kgem *kgem, const uint32_t *data)
+{
+       struct drm_i915_gem_relocation_entry *reloc;
+       struct kgem_bo *bo = NULL;
+       void *base, *ptr;
+       int i, size;
+
+       reloc = kgem_debug_get_reloc_entry(kgem, &data[1] - kgem->batch);
+       if (reloc->target_handle == 0) {
+               base = kgem->batch;
+               size = kgem->nbatch * sizeof(uint32_t);
+       } else {
+               bo = kgem_debug_get_bo_for_reloc_entry(kgem, reloc);
+               base = kgem_bo_map__debug(kgem, bo);
+               size = kgem_bo_size(bo);
+       }
+       ptr = (char *)base + reloc->delta;
+
+       i = data[0] >> 27;
+
+       state.vb[i].handle = reloc->target_handle;
+       state.vb[i].current = bo;
+       state.vb[i].base = base;
+       state.vb[i].ptr = ptr;
+       state.vb[i].pitch = data[0] & 0x7ff;
+       state.vb[i].size = size;
+}
+
+static uint32_t
+get_ve_component(uint32_t data, int component)
+{
+       return (data >> (16 + (3 - component) * 4)) & 0x7;
+}
+
+static void gen5_update_vertex_elements(struct kgem *kgem, int id, const uint32_t *data)
+{
+       state.ve[id].buffer = data[0] >> 27;
+       state.ve[id].valid = !!(data[0] & (1 << 26));
+       state.ve[id].type = (data[0] >> 16) & 0x1ff;
+       state.ve[id].offset = data[0] & 0x7ff;
+       state.ve[id].swizzle[0] = get_ve_component(data[1], 0);
+       state.ve[id].swizzle[1] = get_ve_component(data[1], 1);
+       state.ve[id].swizzle[2] = get_ve_component(data[1], 2);
+       state.ve[id].swizzle[3] = get_ve_component(data[1], 3);
+}
+
+static void vertices_sint16_out(const struct vertex_elements *ve, const int16_t *v, int max)
+{
+       int c, o;
+
+       ErrorF("(");
+       for (c = o = 0; c < 4 && o < max; c++) {
+               switch (ve->swizzle[c]) {
+               case 0: ErrorF("#"); break;
+               case 1: ErrorF("%d", v[o++]); break;
+               case 2: ErrorF("0.0"); break;
+               case 3: ErrorF("1.0"); break;
+               case 4: ErrorF("0x1"); break;
+               case 5: break;
+               default: ErrorF("?");
+               }
+               if (o < max)
+                       ErrorF(", ");
+       }
+       ErrorF(")");
+}
+
+static void vertices_float_out(const struct vertex_elements *ve, const float *f, int max)
+{
+       int c, o;
+
+       ErrorF("(");
+       for (c = o = 0; c < 4 && o < max; c++) {
+               switch (ve->swizzle[c]) {
+               case 0: ErrorF("#"); break;
+               case 1: ErrorF("%f", f[o++]); break;
+               case 2: ErrorF("0.0"); break;
+               case 3: ErrorF("1.0"); break;
+               case 4: ErrorF("0x1"); break;
+               case 5: break;
+               default: ErrorF("?");
+               }
+               if (o < max)
+                       ErrorF(", ");
+       }
+       ErrorF(")");
+}
+
+static void ve_out(const struct vertex_elements *ve, const void *ptr)
+{
+       switch (ve->type) {
+       case GEN5_SURFACEFORMAT_R32_FLOAT:
+               vertices_float_out(ve, ptr, 1);
+               break;
+       case GEN5_SURFACEFORMAT_R32G32_FLOAT:
+               vertices_float_out(ve, ptr, 2);
+               break;
+       case GEN5_SURFACEFORMAT_R32G32B32_FLOAT:
+               vertices_float_out(ve, ptr, 3);
+               break;
+       case GEN5_SURFACEFORMAT_R32G32B32A32_FLOAT:
+               vertices_float_out(ve, ptr, 4);
+               break;
+       case GEN5_SURFACEFORMAT_R16_SINT:
+               vertices_sint16_out(ve, ptr, 1);
+               break;
+       case GEN5_SURFACEFORMAT_R16G16_SINT:
+               vertices_sint16_out(ve, ptr, 2);
+               break;
+       case GEN5_SURFACEFORMAT_R16G16B16A16_SINT:
+               vertices_sint16_out(ve, ptr, 4);
+               break;
+       case GEN5_SURFACEFORMAT_R16_SSCALED:
+               vertices_sint16_out(ve, ptr, 1);
+               break;
+       case GEN5_SURFACEFORMAT_R16G16_SSCALED:
+               vertices_sint16_out(ve, ptr, 2);
+               break;
+       case GEN5_SURFACEFORMAT_R16G16B16A16_SSCALED:
+               vertices_sint16_out(ve, ptr, 4);
+               break;
+       }
+}
+
+static void indirect_vertex_out(struct kgem *kgem, uint32_t v)
+{
+       int i = 1;
+
+       do {
+               const struct vertex_elements *ve = &state.ve[i];
+               const struct vertex_buffer *vb = &state.vb[ve->buffer];
+               const void *ptr = vb->ptr + v * vb->pitch + ve->offset;
+
+               if (!ve->valid)
+                       continue;
+
+               assert(vb->pitch);
+               assert(ve->offset + v*vb->pitch < vb->size);
+
+               ve_out(ve, ptr);
+
+               while (++i <= state.num_ve && !state.ve[i].valid)
+                       ;
+
+               if (i <= state.num_ve)
+                       ErrorF(", ");
+       } while (i <= state.num_ve);
+}
+
+static void primitive_out(struct kgem *kgem, uint32_t *data)
+{
+       int n;
+
+       assert((data[0] & (1<<15)) == 0); /* XXX index buffers */
+
+       for (n = 0; n < data[1]; n++) {
+               int v = data[2] + n;
+               ErrorF("        [%d:%d] = ", n, v);
+               indirect_vertex_out(kgem, v);
+               ErrorF("\n");
+       }
+}
+
+static void
+state_base_out(uint32_t *data, uint32_t offset, unsigned int index,
+              const char *name)
+{
+    if (data[index] & 1)
+       kgem_debug_print(data, offset, index,
+                 "%s state base address 0x%08x\n",
+                 name, data[index] & ~1);
+    else
+       kgem_debug_print(data, offset, index,
+                 "%s state base not updated\n",
+                 name);
+}
+
+static void
+state_max_out(uint32_t *data, uint32_t offset, unsigned int index,
+             const char *name)
+{
+       if (data[index] == 1)
+               kgem_debug_print(data, offset, index,
+                         "%s state upper bound disabled\n", name);
+       else if (data[index] & 1)
+               kgem_debug_print(data, offset, index,
+                         "%s state upper bound 0x%08x\n",
+                         name, data[index] & ~1);
+       else
+               kgem_debug_print(data, offset, index,
+                         "%s state upper bound not updated\n",
+                         name);
+}
+
+static const char *
+get_965_surfacetype(unsigned int surfacetype)
+{
+       switch (surfacetype) {
+       case 0: return "1D";
+       case 1: return "2D";
+       case 2: return "3D";
+       case 3: return "CUBE";
+       case 4: return "BUFFER";
+       case 7: return "NULL";
+       default: return "unknown";
+       }
+}
+
+static const char *
+get_965_depthformat(unsigned int depthformat)
+{
+       switch (depthformat) {
+       case 0: return "s8_z24float";
+       case 1: return "z32float";
+       case 2: return "z24s8";
+       case 5: return "z16";
+       default: return "unknown";
+       }
+}
+
+static const char *
+get_965_element_component(uint32_t data, int component)
+{
+       uint32_t component_control = (data >> (16 + (3 - component) * 4)) & 0x7;
+
+       switch (component_control) {
+       case 0:
+               return "nostore";
+       case 1:
+               switch (component) {
+               case 0: return "X";
+               case 1: return "Y";
+               case 2: return "Z";
+               case 3: return "W";
+               default: return "fail";
+               }
+       case 2:
+               return "0.0";
+       case 3:
+               return "1.0";
+       case 4:
+               return "0x1";
+       case 5:
+               return "VID";
+       default:
+               return "fail";
+       }
+}
+
+static const char *
+get_965_prim_type(uint32_t data)
+{
+       uint32_t primtype = (data >> 10) & 0x1f;
+
+       switch (primtype) {
+       case 0x01: return "point list";
+       case 0x02: return "line list";
+       case 0x03: return "line strip";
+       case 0x04: return "tri list";
+       case 0x05: return "tri strip";
+       case 0x06: return "tri fan";
+       case 0x07: return "quad list";
+       case 0x08: return "quad strip";
+       case 0x09: return "line list adj";
+       case 0x0a: return "line strip adj";
+       case 0x0b: return "tri list adj";
+       case 0x0c: return "tri strip adj";
+       case 0x0d: return "tri strip reverse";
+       case 0x0e: return "polygon";
+       case 0x0f: return "rect list";
+       case 0x10: return "line loop";
+       case 0x11: return "point list bf";
+       case 0x12: return "line strip cont";
+       case 0x13: return "line strip bf";
+       case 0x14: return "line strip cont bf";
+       case 0x15: return "tri fan no stipple";
+       default: return "fail";
+       }
+}
+
+#if 0
+struct reloc {
+       struct kgem_bo *bo;
+       void *base;
+};
+
+static void *
+get_reloc(struct kgem *kgem,
+         void *base, const uint32_t *reloc,
+         struct reloc *r)
+{
+       uint32_t delta = *reloc;
+
+       memset(r, 0, sizeof(*r));
+
+       if (base == 0) {
+               uint32_t handle = sizeof(uint32_t) * (reloc - kgem->batch);
+               struct kgem_bo *bo = NULL;
+               int i;
+
+               for (i = 0; i < kgem->nreloc; i++)
+                       if (kgem->reloc[i].offset == handle)
+                               break;
+               assert(i < kgem->nreloc);
+               handle = kgem->reloc[i].target_handle;
+               delta = kgem->reloc[i].delta;
+
+               if (handle == 0) {
+                       base = kgem->batch;
+               } else {
+                       list_for_each_entry(bo, &kgem->next_request->buffers, request)
+                               if (bo->handle == handle)
+                                       break;
+                       assert(&bo->request != &kgem->next_request->buffers);
+                       base = kgem_bo_map(kgem, bo, PROT_READ);
+                       r->bo = bo;
+                       r->base = base;
+               }
+       }
+
+       return (char *)base + delta;
+}
+#endif
+
+int kgem_gen5_decode_3d(struct kgem *kgem, uint32_t offset)
+{
+       static const struct {
+               uint32_t opcode;
+               int min_len;
+               int max_len;
+               const char *name;
+       } opcodes[] = {
+               { 0x6000, 3, 3, "URB_FENCE" },
+               { 0x6001, 2, 2, "CS_URB_FENCE" },
+               { 0x6002, 2, 2, "CONSTANT_BUFFER" },
+               { 0x6101, 6, 6, "STATE_BASE_ADDRESS" },
+               { 0x6102, 2, 2 , "STATE_SIP" },
+               { 0x6104, 1, 1, "3DSTATE_PIPELINE_SELECT" },
+               { 0x680b, 1, 1, "3DSTATE_VF_STATISTICS" },
+               { 0x6904, 1, 1, "3DSTATE_PIPELINE_SELECT" },
+               { 0x7800, 7, 7, "3DSTATE_PIPELINED_POINTERS" },
+               { 0x7801, 6, 6, "3DSTATE_BINDING_TABLE_POINTERS" },
+               { 0x7808, 5, 257, "3DSTATE_VERTEX_BUFFERS" },
+               { 0x7809, 3, 256, "3DSTATE_VERTEX_ELEMENTS" },
+               { 0x780a, 3, 3, "3DSTATE_INDEX_BUFFER" },
+               { 0x780b, 1, 1, "3DSTATE_VF_STATISTICS" },
+               { 0x7900, 4, 4, "3DSTATE_DRAWING_RECTANGLE" },
+               { 0x7901, 5, 5, "3DSTATE_CONSTANT_COLOR" },
+               { 0x7905, 5, 7, "3DSTATE_DEPTH_BUFFER" },
+               { 0x7906, 2, 2, "3DSTATE_POLY_STIPPLE_OFFSET" },
+               { 0x7907, 33, 33, "3DSTATE_POLY_STIPPLE_PATTERN" },
+               { 0x7908, 3, 3, "3DSTATE_LINE_STIPPLE" },
+               { 0x7909, 2, 2, "3DSTATE_GLOBAL_DEPTH_OFFSET_CLAMP" },
+               { 0x7909, 2, 2, "3DSTATE_CLEAR_PARAMS" },
+               { 0x790a, 3, 3, "3DSTATE_AA_LINE_PARAMETERS" },
+               { 0x790b, 4, 4, "3DSTATE_GS_SVB_INDEX" },
+               { 0x790d, 3, 3, "3DSTATE_MULTISAMPLE" },
+               { 0x7910, 2, 2, "3DSTATE_CLEAR_PARAMS" },
+               { 0x7b00, 6, 6, "3DPRIMITIVE" },
+               { 0x7805, 3, 3, "3DSTATE_URB" },
+               { 0x7815, 5, 5, "3DSTATE_CONSTANT_VS_STATE" },
+               { 0x7816, 5, 5, "3DSTATE_CONSTANT_GS_STATE" },
+               { 0x7817, 5, 5, "3DSTATE_CONSTANT_PS_STATE" },
+               { 0x7818, 2, 2, "3DSTATE_SAMPLE_MASK" },
+       };
+       uint32_t *data = kgem->batch + offset;
+       uint32_t op;
+       unsigned int len;
+       int i;
+       const char *desc1 = NULL;
+
+       len = (data[0] & 0xff) + 2;
+       op = (data[0] & 0xffff0000) >> 16;
+       switch (op) {
+       case 0x6000:
+               assert(len == 3);
+
+               kgem_debug_print(data, offset, 0, "URB_FENCE: %s%s%s%s%s%s\n",
+                         (data[0] >> 13) & 1 ? "cs " : "",
+                         (data[0] >> 12) & 1 ? "vfe " : "",
+                         (data[0] >> 11) & 1 ? "sf " : "",
+                         (data[0] >> 10) & 1 ? "clip " : "",
+                         (data[0] >> 9)  & 1 ? "gs " : "",
+                         (data[0] >> 8)  & 1 ? "vs " : "");
+               kgem_debug_print(data, offset, 1,
+                         "vs fence: %d, gs_fence: %d, clip_fence: %d\n",
+                         data[1] & 0x3ff,
+                         (data[1] >> 10) & 0x3ff,
+                         (data[1] >> 20) & 0x3ff);
+               kgem_debug_print(data, offset, 2,
+                         "sf fence: %d, vfe_fence: %d, cs_fence: %d\n",
+                          data[2] & 0x3ff,
+                          (data[2] >> 10) & 0x3ff,
+                          (data[2] >> 20) & 0x7ff);
+               return len;
+
+       case 0x6001:
+               kgem_debug_print(data, offset, 0, "CS_URB_STATE\n");
+               kgem_debug_print(data, offset, 1, "entry_size: %d [%d bytes], n_entries: %d\n",
+                         (data[1] >> 4) & 0x1f,
+                         (((data[1] >> 4) & 0x1f) + 1) * 64,
+                         data[1] & 0x7);
+               return len;
+       case 0x6002:
+               kgem_debug_print(data, offset, 0, "CONSTANT_BUFFER: %s\n",
+                         (data[0] >> 8) & 1 ? "valid" : "invalid");
+               kgem_debug_print(data, offset, 1, "offset: 0x%08x, length: %d bytes\n",
+                         data[1] & ~0x3f, ((data[1] & 0x3f) + 1) * 64);
+               return len;
+       case 0x6101:
+               i = 0;
+               kgem_debug_print(data, offset, i++, "STATE_BASE_ADDRESS\n");
+               assert(len == 8);
+
+               state_base_out(data, offset, i++, "general");
+               state_base_out(data, offset, i++, "surface");
+               state_base_out(data, offset, i++, "media");
+               state_base_out(data, offset, i++, "instruction");
+
+               state_max_out(data, offset, i++, "general");
+               state_max_out(data, offset, i++, "media");
+               state_max_out(data, offset, i++, "instruction");
+
+               return len;
+
+       case 0x7801:
+               assert(len == 6);
+
+               kgem_debug_print(data, offset, 0,
+                         "3DSTATE_BINDING_TABLE_POINTERS\n");
+               kgem_debug_print(data, offset, 1, "VS binding table\n");
+               kgem_debug_print(data, offset, 2, "GS binding table\n");
+               kgem_debug_print(data, offset, 3, "CLIP binding table\n");
+               kgem_debug_print(data, offset, 4, "SF binding table\n");
+               kgem_debug_print(data, offset, 5, "WM binding table\n");
+
+               return len;
+
+       case 0x7808:
+               assert((len - 1) % 4 == 0);
+               kgem_debug_print(data, offset, 0, "3DSTATE_VERTEX_BUFFERS\n");
+
+               for (i = 1; i < len;) {
+                       gen5_update_vertex_buffer(kgem, data + i);
+
+                       kgem_debug_print(data, offset, i, "buffer %d: %s, pitch %db\n",
+                                 data[i] >> 27,
+                                 data[i] & (1 << 20) ? "random" : "sequential",
+                                 data[i] & 0x07ff);
+                       i++;
+                       kgem_debug_print(data, offset, i++, "buffer address\n");
+                       kgem_debug_print(data, offset, i++, "max index\n");
+                       kgem_debug_print(data, offset, i++, "mbz\n");
+               }
+               return len;
+
+       case 0x7809:
+               assert((len + 1) % 2 == 0);
+               kgem_debug_print(data, offset, 0, "3DSTATE_VERTEX_ELEMENTS\n");
+
+               memset(state.ve, 0, sizeof(state.ve)); /* XXX? */
+               for (i = 1; i < len;) {
+                       gen5_update_vertex_elements(kgem, (i - 1)/2, data + i);
+
+                       kgem_debug_print(data, offset, i, "buffer %d: %svalid, type 0x%04x, "
+                                 "src offset 0x%04x bytes\n",
+                                 data[i] >> 27,
+                                 data[i] & (1 << 26) ? "" : "in",
+                                 (data[i] >> 16) & 0x1ff,
+                                 data[i] & 0x07ff);
+                       i++;
+                       kgem_debug_print(data, offset, i, "(%s, %s, %s, %s), "
+                                 "dst offset 0x%02x bytes\n",
+                                 get_965_element_component(data[i], 0),
+                                 get_965_element_component(data[i], 1),
+                                 get_965_element_component(data[i], 2),
+                                 get_965_element_component(data[i], 3),
+                                 (data[i] & 0xff) * 4);
+                       i++;
+               }
+               state.num_ve = (len - 1) / 2; /* XXX? */
+               return len;
+
+       case 0x780a:
+               assert(len == 3);
+               kgem_debug_print(data, offset, 0, "3DSTATE_INDEX_BUFFER\n");
+               kgem_debug_print(data, offset, 1, "beginning buffer address\n");
+               kgem_debug_print(data, offset, 2, "ending buffer address\n");
+               return len;
+
+       case 0x7900:
+               assert(len == 4);
+               kgem_debug_print(data, offset, 0,
+                         "3DSTATE_DRAWING_RECTANGLE\n");
+               kgem_debug_print(data, offset, 1, "top left: %d,%d\n",
+                         data[1] & 0xffff,
+                         (data[1] >> 16) & 0xffff);
+               kgem_debug_print(data, offset, 2, "bottom right: %d,%d\n",
+                         data[2] & 0xffff,
+                         (data[2] >> 16) & 0xffff);
+               kgem_debug_print(data, offset, 3, "origin: %d,%d\n",
+                         (int)data[3] & 0xffff,
+                         ((int)data[3] >> 16) & 0xffff);
+               return len;
+
+       case 0x7905:
+               assert(len == 7);
+               kgem_debug_print(data, offset, 0,
+                         "3DSTATE_DEPTH_BUFFER\n");
+               kgem_debug_print(data, offset, 1, "%s, %s, pitch = %d bytes, %stiled, HiZ %d, Seperate Stencil %d\n",
+                         get_965_surfacetype(data[1] >> 29),
+                         get_965_depthformat((data[1] >> 18) & 0x7),
+                         (data[1] & 0x0001ffff) + 1,
+                         data[1] & (1 << 27) ? "" : "not ",
+                         (data[1] & (1 << 22)) != 0,
+                         (data[1] & (1 << 21)) != 0);
+               kgem_debug_print(data, offset, 2, "depth offset\n");
+               kgem_debug_print(data, offset, 3, "%dx%d\n",
+                         ((data[3] & 0x0007ffc0) >> 6) + 1,
+                         ((data[3] & 0xfff80000) >> 19) + 1);
+               kgem_debug_print(data, offset, 4, "volume depth\n");
+               kgem_debug_print(data, offset, 5, "\n");
+               kgem_debug_print(data, offset, 6, "\n");
+               return len;
+
+       case 0x7a00:
+               assert(len == 4 || len == 5);
+               switch ((data[1] >> 14) & 0x3) {
+               case 0: desc1 = "no write"; break;
+               case 1: desc1 = "qword write"; break;
+               case 2: desc1 = "PS_DEPTH_COUNT write"; break;
+               case 3: desc1 = "TIMESTAMP write"; break;
+               }
+               kgem_debug_print(data, offset, 0, "PIPE_CONTROL\n");
+               kgem_debug_print(data, offset, 1,
+                         "%s, %scs stall, %stlb invalidate, "
+                         "%ssync gfdt, %sdepth stall, %sRC write flush, "
+                         "%sinst flush, %sTC flush\n",
+                         desc1,
+                         data[1] & (1 << 20) ? "" : "no ",
+                         data[1] & (1 << 18) ? "" : "no ",
+                         data[1] & (1 << 17) ? "" : "no ",
+                         data[1] & (1 << 13) ? "" : "no ",
+                         data[1] & (1 << 12) ? "" : "no ",
+                         data[1] & (1 << 11) ? "" : "no ",
+                         data[1] & (1 << 10) ? "" : "no ");
+               if (len == 5) {
+                       kgem_debug_print(data, offset, 2, "destination address\n");
+                       kgem_debug_print(data, offset, 3, "immediate dword low\n");
+                       kgem_debug_print(data, offset, 4, "immediate dword high\n");
+               } else {
+                       for (i = 2; i < len; i++) {
+                               kgem_debug_print(data, offset, i, "\n");
+                       }
+               }
+               return len;
+
+       case 0x7b00:
+               assert(len == 6);
+               kgem_debug_print(data, offset, 0,
+                         "3DPRIMITIVE: %s %s\n",
+                         get_965_prim_type(data[0]),
+                         (data[0] & (1 << 15)) ? "random" : "sequential");
+               kgem_debug_print(data, offset, 1, "vertex count\n");
+               kgem_debug_print(data, offset, 2, "start vertex\n");
+               kgem_debug_print(data, offset, 3, "instance count\n");
+               kgem_debug_print(data, offset, 4, "start instance\n");
+               kgem_debug_print(data, offset, 5, "index bias\n");
+               primitive_out(kgem, data);
+               return len;
+       }
+
+       /* For the rest, just dump the bytes */
+       for (i = 0; i < ARRAY_SIZE(opcodes); i++)
+               if (op == opcodes[i].opcode)
+                       break;
+
+       assert(i < ARRAY_SIZE(opcodes));
+
+       len = 1;
+       kgem_debug_print(data, offset, 0, "%s\n", opcodes[i].name);
+       if (opcodes[i].max_len > 1) {
+               len = (data[0] & 0xff) + 2;
+               assert(len >= opcodes[i].min_len &&
+                      len <= opcodes[i].max_len);
+       }
+
+       for (i = 1; i < len; i++)
+               kgem_debug_print(data, offset, i, "dword %d\n", i);
+
+       return len;
+}
+
+void kgem_gen5_finish_state(struct kgem *kgem)
+{
+       memset(&state, 0, sizeof(state));
+}
diff --git a/src/sna/kgem_debug_gen6.c b/src/sna/kgem_debug_gen6.c
new file mode 100644 (file)
index 0000000..e0b09d5
--- /dev/null
@@ -0,0 +1,1075 @@
+/*
+ * Copyright © 2007-2011 Intel 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.
+ *
+ * Authors:
+ *    Eric Anholt <eric@anholt.net>
+ *    Chris Wilson <chris"chris-wilson.co.uk>
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/mman.h>
+#include <assert.h>
+
+#include "sna.h"
+#include "sna_reg.h"
+#include "gen6_render.h"
+
+#include "kgem_debug.h"
+
+static struct state {
+       struct vertex_buffer {
+               int handle;
+               const char *ptr;
+               int pitch;
+
+               struct kgem_bo *current;
+       } vb[33];
+       struct vertex_elements {
+               int buffer;
+               int offset;
+               bool valid;
+               uint32_t type;
+               uint8_t swizzle[4];
+       } ve[33];
+       int num_ve;
+
+       struct dynamic_state {
+               struct kgem_bo *current;
+               void *base, *ptr;
+       } dynamic_state;
+} state;
+
+static void gen6_update_vertex_buffer(struct kgem *kgem, const uint32_t *data)
+{
+       uint32_t reloc = sizeof(uint32_t) * (&data[1] - kgem->batch);
+       struct kgem_bo *bo = NULL;
+       void *base;
+       int i;
+
+       for (i = 0; i < kgem->nreloc; i++)
+               if (kgem->reloc[i].offset == reloc)
+                       break;
+       assert(i < kgem->nreloc);
+       reloc = kgem->reloc[i].target_handle;
+
+       if (reloc == 0) {
+               base = kgem->batch;
+       } else {
+               list_for_each_entry(bo, &kgem->next_request->buffers, request)
+                       if (bo->handle == reloc)
+                               break;
+               assert(&bo->request != &kgem->next_request->buffers);
+               base = kgem_bo_map__debug(kgem, bo);
+       }
+
+       base = (char *)base + kgem->reloc[i].delta;
+       i = data[0] >> 26;
+
+       state.vb[i].current = bo;
+       state.vb[i].ptr = base;
+       state.vb[i].pitch = data[0] & 0x7ff;
+}
+
+static void gen6_update_dynamic_buffer(struct kgem *kgem, const uint32_t offset)
+{
+       uint32_t reloc = sizeof(uint32_t) * offset;
+       struct kgem_bo *bo = NULL;
+       void *base, *ptr;
+       int i;
+
+       if ((kgem->batch[offset] & 1) == 0)
+               return;
+
+       for (i = 0; i < kgem->nreloc; i++)
+               if (kgem->reloc[i].offset == reloc)
+                       break;
+       if(i < kgem->nreloc) {
+               reloc = kgem->reloc[i].target_handle;
+
+               if (reloc == 0) {
+                       base = kgem->batch;
+               } else {
+                       list_for_each_entry(bo, &kgem->next_request->buffers, request)
+                               if (bo->handle == reloc)
+                                       break;
+                       assert(&bo->request != &kgem->next_request->buffers);
+                       base = kgem_bo_map__debug(kgem, bo);
+               }
+               ptr = (char *)base + (kgem->reloc[i].delta & ~1);
+       } else {
+               bo = NULL;
+               base = NULL;
+               ptr = NULL;
+       }
+
+       state.dynamic_state.current = bo;
+       state.dynamic_state.base = base;
+       state.dynamic_state.ptr = ptr;
+}
+
+static uint32_t
+get_ve_component(uint32_t data, int component)
+{
+       return (data >> (16 + (3 - component) * 4)) & 0x7;
+}
+
+static void gen6_update_vertex_elements(struct kgem *kgem, int id, const uint32_t *data)
+{
+       state.ve[id].buffer = data[0] >> 26;
+       state.ve[id].valid = !!(data[0] & (1 << 25));
+       state.ve[id].type = (data[0] >> 16) & 0x1ff;
+       state.ve[id].offset = data[0] & 0x7ff;
+       state.ve[id].swizzle[0] = get_ve_component(data[1], 0);
+       state.ve[id].swizzle[1] = get_ve_component(data[1], 1);
+       state.ve[id].swizzle[2] = get_ve_component(data[1], 2);
+       state.ve[id].swizzle[3] = get_ve_component(data[1], 3);
+}
+
+static void gen6_update_sf_state(struct kgem *kgem, uint32_t *data)
+{
+       state.num_ve = 1 + ((data[1] >> 22) & 0x3f);
+}
+
+static void vertices_sint16_out(const struct vertex_elements *ve, const int16_t *v, int max)
+{
+       int c;
+
+       ErrorF("(");
+       for (c = 0; c < max; c++) {
+               switch (ve->swizzle[c]) {
+               case 0: ErrorF("#"); break;
+               case 1: ErrorF("%d", v[c]); break;
+               case 2: ErrorF("0.0"); break;
+               case 3: ErrorF("1.0"); break;
+               case 4: ErrorF("0x1"); break;
+               case 5: break;
+               default: ErrorF("?");
+               }
+               if (c < 3)
+                       ErrorF(", ");
+       }
+       for (; c < 4; c++) {
+               switch (ve->swizzle[c]) {
+               case 0: ErrorF("#"); break;
+               case 1: ErrorF("1.0"); break;
+               case 2: ErrorF("0.0"); break;
+               case 3: ErrorF("1.0"); break;
+               case 4: ErrorF("0x1"); break;
+               case 5: break;
+               default: ErrorF("?");
+               }
+               if (c < 3)
+                       ErrorF(", ");
+       }
+       ErrorF(")");
+}
+
+static void vertices_float_out(const struct vertex_elements *ve, const float *f, int max)
+{
+       int c, o;
+
+       ErrorF("(");
+       for (c = o = 0; c < 4 && o < max; c++) {
+               switch (ve->swizzle[c]) {
+               case 0: ErrorF("#"); break;
+               case 1: ErrorF("%f", f[o++]); break;
+               case 2: ErrorF("0.0"); break;
+               case 3: ErrorF("1.0"); break;
+               case 4: ErrorF("0x1"); break;
+               case 5: break;
+               default: ErrorF("?");
+               }
+               if (c < 3)
+                       ErrorF(", ");
+       }
+       for (; c < 4; c++) {
+               switch (ve->swizzle[c]) {
+               case 0: ErrorF("#"); break;
+               case 1: ErrorF("1.0"); break;
+               case 2: ErrorF("0.0"); break;
+               case 3: ErrorF("1.0"); break;
+               case 4: ErrorF("0x1"); break;
+               case 5: break;
+               default: ErrorF("?");
+               }
+               if (c < 3)
+                       ErrorF(", ");
+       }
+       ErrorF(")");
+}
+
+static void ve_out(const struct vertex_elements *ve, const void *ptr)
+{
+       switch (ve->type) {
+       case GEN6_SURFACEFORMAT_R32_FLOAT:
+               vertices_float_out(ve, ptr, 1);
+               break;
+       case GEN6_SURFACEFORMAT_R32G32_FLOAT:
+               vertices_float_out(ve, ptr, 2);
+               break;
+       case GEN6_SURFACEFORMAT_R32G32B32_FLOAT:
+               vertices_float_out(ve, ptr, 3);
+               break;
+       case GEN6_SURFACEFORMAT_R32G32B32A32_FLOAT:
+               vertices_float_out(ve, ptr, 4);
+               break;
+       case GEN6_SURFACEFORMAT_R16_SINT:
+               vertices_sint16_out(ve, ptr, 1);
+               break;
+       case GEN6_SURFACEFORMAT_R16G16_SINT:
+               vertices_sint16_out(ve, ptr, 2);
+               break;
+       case GEN6_SURFACEFORMAT_R16G16B16A16_SINT:
+               vertices_sint16_out(ve, ptr, 4);
+               break;
+       case GEN6_SURFACEFORMAT_R16_SSCALED:
+               vertices_sint16_out(ve, ptr, 1);
+               break;
+       case GEN6_SURFACEFORMAT_R16G16_SSCALED:
+               vertices_sint16_out(ve, ptr, 2);
+               break;
+       case GEN6_SURFACEFORMAT_R16G16B16A16_SSCALED:
+               vertices_sint16_out(ve, ptr, 4);
+               break;
+       }
+}
+
+static void indirect_vertex_out(struct kgem *kgem, uint32_t v)
+{
+       int i = 1;
+
+       do {
+               const struct vertex_elements *ve = &state.ve[i];
+               const struct vertex_buffer *vb = &state.vb[ve->buffer];
+               const void *ptr = vb->ptr + v * vb->pitch + ve->offset;
+
+               if (ve->valid)
+                       ve_out(ve, ptr);
+
+               while (++i <= state.num_ve && !state.ve[i].valid)
+                       ;
+
+               if (i <= state.num_ve)
+                       ErrorF(", ");
+       } while (i <= state.num_ve);
+}
+
+static void primitive_out(struct kgem *kgem, uint32_t *data)
+{
+       int n;
+
+       assert((data[0] & (1<<15)) == 0); /* XXX index buffers */
+
+       for (n = 0; n < data[1]; n++) {
+               int v = data[2] + n;
+               ErrorF("        [%d:%d] = ", n, v);
+               indirect_vertex_out(kgem, v);
+               ErrorF("\n");
+       }
+}
+
+static void finish_state(struct kgem *kgem)
+{
+       memset(&state, 0, sizeof(state));
+}
+
+static void
+state_base_out(uint32_t *data, uint32_t offset, unsigned int index,
+              const char *name)
+{
+    if (data[index] & 1)
+       kgem_debug_print(data, offset, index,
+                 "%s state base address 0x%08x\n",
+                 name, data[index] & ~1);
+    else
+       kgem_debug_print(data, offset, index,
+                 "%s state base not updated\n",
+                 name);
+}
+
+static void
+state_max_out(uint32_t *data, uint32_t offset, unsigned int index,
+             const char *name)
+{
+       if (data[index] == 1)
+               kgem_debug_print(data, offset, index,
+                         "%s state upper bound disabled\n", name);
+       else if (data[index] & 1)
+               kgem_debug_print(data, offset, index,
+                         "%s state upper bound 0x%08x\n",
+                         name, data[index] & ~1);
+       else
+               kgem_debug_print(data, offset, index,
+                         "%s state upper bound not updated\n",
+                         name);
+}
+
+static const char *
+get_965_surfacetype(unsigned int surfacetype)
+{
+       switch (surfacetype) {
+       case 0: return "1D";
+       case 1: return "2D";
+       case 2: return "3D";
+       case 3: return "CUBE";
+       case 4: return "BUFFER";
+       case 7: return "NULL";
+       default: return "unknown";
+       }
+}
+
+static const char *
+get_965_depthformat(unsigned int depthformat)
+{
+       switch (depthformat) {
+       case 0: return "s8_z24float";
+       case 1: return "z32float";
+       case 2: return "z24s8";
+       case 5: return "z16";
+       default: return "unknown";
+       }
+}
+
+static const char *
+get_965_element_component(uint32_t data, int component)
+{
+       uint32_t component_control = (data >> (16 + (3 - component) * 4)) & 0x7;
+
+       switch (component_control) {
+       case 0:
+               return "nostore";
+       case 1:
+               switch (component) {
+               case 0: return "X";
+               case 1: return "Y";
+               case 2: return "Z";
+               case 3: return "W";
+               default: return "fail";
+               }
+       case 2:
+               return "0.0";
+       case 3:
+               return "1.0";
+       case 4:
+               return "0x1";
+       case 5:
+               return "VID";
+       default:
+               return "fail";
+       }
+}
+
+static const char *
+get_965_prim_type(uint32_t data)
+{
+       uint32_t primtype = (data >> 10) & 0x1f;
+
+       switch (primtype) {
+       case 0x01: return "point list";
+       case 0x02: return "line list";
+       case 0x03: return "line strip";
+       case 0x04: return "tri list";
+       case 0x05: return "tri strip";
+       case 0x06: return "tri fan";
+       case 0x07: return "quad list";
+       case 0x08: return "quad strip";
+       case 0x09: return "line list adj";
+       case 0x0a: return "line strip adj";
+       case 0x0b: return "tri list adj";
+       case 0x0c: return "tri strip adj";
+       case 0x0d: return "tri strip reverse";
+       case 0x0e: return "polygon";
+       case 0x0f: return "rect list";
+       case 0x10: return "line loop";
+       case 0x11: return "point list bf";
+       case 0x12: return "line strip cont";
+       case 0x13: return "line strip bf";
+       case 0x14: return "line strip cont bf";
+       case 0x15: return "tri fan no stipple";
+       default: return "fail";
+       }
+}
+
+struct reloc {
+       struct kgem_bo *bo;
+       void *base;
+};
+
+static void *
+get_reloc(struct kgem *kgem,
+         void *base, const uint32_t *reloc,
+         struct reloc *r)
+{
+       uint32_t delta = *reloc;
+
+       memset(r, 0, sizeof(*r));
+
+       if (base == 0) {
+               uint32_t handle = sizeof(uint32_t) * (reloc - kgem->batch);
+               struct kgem_bo *bo = NULL;
+               int i;
+
+               for (i = 0; i < kgem->nreloc; i++)
+                       if (kgem->reloc[i].offset == handle)
+                               break;
+               assert(i < kgem->nreloc);
+               handle = kgem->reloc[i].target_handle;
+               delta = kgem->reloc[i].delta;
+
+               if (handle == 0) {
+                       base = kgem->batch;
+               } else {
+                       list_for_each_entry(bo, &kgem->next_request->buffers, request)
+                               if (bo->handle == handle)
+                                       break;
+                       assert(&bo->request != &kgem->next_request->buffers);
+                       base = kgem_bo_map__debug(kgem, bo);
+                       r->bo = bo;
+                       r->base = base;
+               }
+       }
+
+       return (char *)base + (delta & ~3);
+}
+
+static const char *
+gen6_filter_to_string(uint32_t filter)
+{
+       switch (filter) {
+       default:
+       case GEN6_MAPFILTER_NEAREST: return "nearest";
+       case GEN6_MAPFILTER_LINEAR: return "linear";
+       }
+}
+
+static const char *
+gen6_repeat_to_string(uint32_t repeat)
+{
+       switch (repeat) {
+       default:
+       case GEN6_TEXCOORDMODE_CLAMP_BORDER: return "border";
+       case GEN6_TEXCOORDMODE_WRAP: return "wrap";
+       case GEN6_TEXCOORDMODE_CLAMP: return "clamp";
+       case GEN6_TEXCOORDMODE_MIRROR: return "mirror";
+       }
+}
+
+static void
+gen6_decode_sampler_state(struct kgem *kgem, const uint32_t *reloc)
+{
+       const struct gen6_sampler_state *ss;
+       struct reloc r;
+       const char *min, *mag;
+       const char *s_wrap, *t_wrap, *r_wrap;
+
+       ss = get_reloc(kgem, state.dynamic_state.ptr, reloc, &r);
+
+       min = gen6_filter_to_string(ss->ss0.min_filter);
+       mag = gen6_filter_to_string(ss->ss0.mag_filter);
+
+       s_wrap = gen6_repeat_to_string(ss->ss1.s_wrap_mode);
+       t_wrap = gen6_repeat_to_string(ss->ss1.t_wrap_mode);
+       r_wrap = gen6_repeat_to_string(ss->ss1.r_wrap_mode);
+
+       ErrorF("  Sampler 0:\n");
+       ErrorF("    filter: min=%s, mag=%s\n", min, mag);
+       ErrorF("    wrap: s=%s, t=%s, r=%s\n", s_wrap, t_wrap, r_wrap);
+
+       ss++;
+       min = gen6_filter_to_string(ss->ss0.min_filter);
+       mag = gen6_filter_to_string(ss->ss0.mag_filter);
+
+       s_wrap = gen6_repeat_to_string(ss->ss1.s_wrap_mode);
+       t_wrap = gen6_repeat_to_string(ss->ss1.t_wrap_mode);
+       r_wrap = gen6_repeat_to_string(ss->ss1.r_wrap_mode);
+
+       ErrorF("  Sampler 1:\n");
+       ErrorF("    filter: min=%s, mag=%s\n", min, mag);
+       ErrorF("    wrap: s=%s, t=%s, r=%s\n", s_wrap, t_wrap, r_wrap);
+}
+
+static const char *
+gen6_blend_factor_to_string(uint32_t v)
+{
+       switch (v) {
+#define C(x) case GEN6_BLENDFACTOR_##x: return #x;
+               C(ONE);
+               C(SRC_COLOR);
+               C(SRC_ALPHA);
+               C(DST_ALPHA);
+               C(DST_COLOR);
+               C(SRC_ALPHA_SATURATE);
+               C(CONST_COLOR);
+               C(CONST_ALPHA);
+               C(SRC1_COLOR);
+               C(SRC1_ALPHA);
+               C(ZERO);
+               C(INV_SRC_COLOR);
+               C(INV_SRC_ALPHA);
+               C(INV_DST_ALPHA);
+               C(INV_DST_COLOR);
+               C(INV_CONST_COLOR);
+               C(INV_CONST_ALPHA);
+               C(INV_SRC1_COLOR);
+               C(INV_SRC1_ALPHA);
+#undef C
+       default: return "???";
+       }
+}
+
+static const char *
+gen6_blend_function_to_string(uint32_t v)
+{
+       switch (v) {
+#define C(x) case GEN6_BLENDFUNCTION_##x: return #x;
+               C(ADD);
+               C(SUBTRACT);
+               C(REVERSE_SUBTRACT);
+               C(MIN);
+               C(MAX);
+#undef C
+       default: return "???";
+       }
+}
+
+static float unpack_float(uint32_t dw)
+{
+       union {
+               float f;
+               uint32_t dw;
+       } u;
+       u.dw = dw;
+       return u.f;
+}
+
+static void
+gen6_decode_blend(struct kgem *kgem, const uint32_t *reloc)
+{
+       const struct gen6_blend_state *blend;
+       struct reloc r;
+       const char *dst, *src;
+       const char *func;
+
+       blend = get_reloc(kgem, state.dynamic_state.ptr, reloc, &r);
+
+       dst = gen6_blend_factor_to_string(blend->blend0.dest_blend_factor);
+       src = gen6_blend_factor_to_string(blend->blend0.source_blend_factor);
+       func = gen6_blend_function_to_string(blend->blend0.blend_func);
+
+       ErrorF("  Blend (%s): function %s, src=%s, dst=%s\n",
+              blend->blend0.blend_enable ? "enabled" : "disabled",
+              func, src, dst);
+}
+
+int kgem_gen6_decode_3d(struct kgem *kgem, uint32_t offset)
+{
+       static const struct {
+               uint32_t opcode;
+               int min_len;
+               int max_len;
+               const char *name;
+       } opcodes[] = {
+               { 0x6101, 6, 6, "STATE_BASE_ADDRESS" },
+               { 0x6102, 2, 2 , "STATE_SIP" },
+               { 0x6104, 1, 1, "3DSTATE_PIPELINE_SELECT" },
+               { 0x680b, 1, 1, "3DSTATE_VF_STATISTICS" },
+               { 0x6904, 1, 1, "3DSTATE_PIPELINE_SELECT" },
+               { 0x7800, 7, 7, "3DSTATE_PIPELINED_POINTERS" },
+               { 0x7801, 6, 6, "3DSTATE_BINDING_TABLE_POINTERS" },
+               { 0x7808, 5, 257, "3DSTATE_VERTEX_BUFFERS" },
+               { 0x7809, 3, 256, "3DSTATE_VERTEX_ELEMENTS" },
+               { 0x780a, 3, 3, "3DSTATE_INDEX_BUFFER" },
+               { 0x780b, 1, 1, "3DSTATE_VF_STATISTICS" },
+               { 0x7900, 4, 4, "3DSTATE_DRAWING_RECTANGLE" },
+               { 0x7901, 5, 5, "3DSTATE_CONSTANT_COLOR" },
+               { 0x7905, 5, 7, "3DSTATE_DEPTH_BUFFER" },
+               { 0x7906, 2, 2, "3DSTATE_POLY_STIPPLE_OFFSET" },
+               { 0x7907, 33, 33, "3DSTATE_POLY_STIPPLE_PATTERN" },
+               { 0x7908, 3, 3, "3DSTATE_LINE_STIPPLE" },
+               { 0x7909, 2, 2, "3DSTATE_GLOBAL_DEPTH_OFFSET_CLAMP" },
+               { 0x7909, 2, 2, "3DSTATE_CLEAR_PARAMS" },
+               { 0x790a, 3, 3, "3DSTATE_AA_LINE_PARAMETERS" },
+               { 0x790b, 4, 4, "3DSTATE_GS_SVB_INDEX" },
+               { 0x790d, 3, 3, "3DSTATE_MULTISAMPLE" },
+               { 0x7910, 2, 2, "3DSTATE_CLEAR_PARAMS" },
+               { 0x7b00, 6, 6, "3DPRIMITIVE" },
+               { 0x7802, 4, 4, "3DSTATE_SAMPLER_STATE_POINTERS" },
+               { 0x7805, 3, 3, "3DSTATE_URB" },
+               { 0x780d, 4, 4, "3DSTATE_VIEWPORT_STATE_POINTERS" },
+               { 0x780e, 4, 4, "3DSTATE_CC_STATE_POINTERS" },
+               { 0x780f, 2, 2, "3DSTATE_SCISSOR_STATE_POINTERS" },
+               { 0x7810, 6, 6, "3DSTATE_VS_STATE" },
+               { 0x7811, 7, 7, "3DSTATE_GS_STATE" },
+               { 0x7812, 4, 4, "3DSTATE_CLIP_STATE" },
+               { 0x7813, 20, 20, "3DSTATE_SF_STATE" },
+               { 0x7814, 9, 9, "3DSTATE_WM_STATE" },
+               { 0x7815, 5, 5, "3DSTATE_CONSTANT_VS_STATE" },
+               { 0x7816, 5, 5, "3DSTATE_CONSTANT_GS_STATE" },
+               { 0x7817, 5, 5, "3DSTATE_CONSTANT_WM_STATE" },
+               { 0x7818, 2, 2, "3DSTATE_SAMPLE_MASK" },
+       };
+       uint32_t *data = kgem->batch + offset;
+       uint32_t op;
+       unsigned int len;
+       int i, j;
+       const char *desc1 = NULL;
+
+       len = (data[0] & 0xff) + 2;
+       op = (data[0] & 0xffff0000) >> 16;
+       switch (op) {
+       case 0x6101:
+               i = 0;
+               kgem_debug_print(data, offset, i++, "STATE_BASE_ADDRESS\n");
+               if (kgem->gen >= 60) {
+                       assert(len == 10);
+
+                       state_base_out(data, offset, i++, "general");
+                       state_base_out(data, offset, i++, "surface");
+                       state_base_out(data, offset, i++, "dynamic");
+                       state_base_out(data, offset, i++, "indirect");
+                       state_base_out(data, offset, i++, "instruction");
+
+                       state_max_out(data, offset, i++, "general");
+                       state_max_out(data, offset, i++, "dynamic");
+                       state_max_out(data, offset, i++, "indirect");
+                       state_max_out(data, offset, i++, "instruction");
+
+                       gen6_update_dynamic_buffer(kgem, offset + 3);
+               } else if (kgem->gen >= 50) {
+                       assert(len == 8);
+
+                       state_base_out(data, offset, i++, "general");
+                       state_base_out(data, offset, i++, "surface");
+                       state_base_out(data, offset, i++, "media");
+                       state_base_out(data, offset, i++, "instruction");
+
+                       state_max_out(data, offset, i++, "general");
+                       state_max_out(data, offset, i++, "media");
+                       state_max_out(data, offset, i++, "instruction");
+               }
+
+               return len;
+
+       case 0x7801:
+               if (kgem->gen >= 60) {
+                       assert(len == 4);
+
+                       kgem_debug_print(data, offset, 0,
+                                 "3DSTATE_BINDING_TABLE_POINTERS: VS mod %d, "
+                                 "GS mod %d, WM mod %d\n",
+                                 (data[0] & (1 << 8)) != 0,
+                                 (data[0] & (1 << 9)) != 0,
+                                 (data[0] & (1 << 12)) != 0);
+                       kgem_debug_print(data, offset, 1, "VS binding table\n");
+                       kgem_debug_print(data, offset, 2, "GS binding table\n");
+                       kgem_debug_print(data, offset, 3, "WM binding table\n");
+               } else if (kgem->gen >= 40) {
+                       assert(len == 6);
+
+                       kgem_debug_print(data, offset, 0,
+                                 "3DSTATE_BINDING_TABLE_POINTERS\n");
+                       kgem_debug_print(data, offset, 1, "VS binding table\n");
+                       kgem_debug_print(data, offset, 2, "GS binding table\n");
+                       kgem_debug_print(data, offset, 3, "CLIP binding table\n");
+                       kgem_debug_print(data, offset, 4, "SF binding table\n");
+                       kgem_debug_print(data, offset, 5, "WM binding table\n");
+               }
+
+               return len;
+
+       case 0x7802:
+               assert(len == 4);
+               kgem_debug_print(data, offset, 0, "3DSTATE_SAMPLER_STATE_POINTERS: VS mod %d, "
+                         "GS mod %d, WM mod %d\n",
+                         (data[0] & (1 << 8)) != 0,
+                         (data[0] & (1 << 9)) != 0,
+                         (data[0] & (1 << 12)) != 0);
+               kgem_debug_print(data, offset, 1, "VS sampler state\n");
+               kgem_debug_print(data, offset, 2, "GS sampler state\n");
+               kgem_debug_print(data, offset, 3, "WM sampler state\n");
+               gen6_decode_sampler_state(kgem, &data[3]);
+               return len;
+
+       case 0x7808:
+               assert((len - 1) % 4 == 0);
+               kgem_debug_print(data, offset, 0, "3DSTATE_VERTEX_BUFFERS\n");
+
+               for (i = 1; i < len;) {
+                       gen6_update_vertex_buffer(kgem, data + i);
+
+                       kgem_debug_print(data, offset, i, "buffer %d: %s, pitch %db\n",
+                                 data[i] >> 26,
+                                 data[i] & (1 << 20) ? "random" : "sequential",
+                                 data[i] & 0x07ff);
+                       i++;
+                       kgem_debug_print(data, offset, i++, "buffer address\n");
+                       kgem_debug_print(data, offset, i++, "max index\n");
+                       kgem_debug_print(data, offset, i++, "mbz\n");
+               }
+               return len;
+
+       case 0x7809:
+               assert((len + 1) % 2 == 0);
+               kgem_debug_print(data, offset, 0, "3DSTATE_VERTEX_ELEMENTS\n");
+
+               for (i = 1; i < len;) {
+                       gen6_update_vertex_elements(kgem, (i - 1)/2, data + i);
+
+                       kgem_debug_print(data, offset, i, "buffer %d: %svalid, type 0x%04x, "
+                                 "src offset 0x%04x bytes\n",
+                                 data[i] >> 26,
+                                 data[i] & (1 << 25) ? "" : "in",
+                                 (data[i] >> 16) & 0x1ff,
+                                 data[i] & 0x07ff);
+                       i++;
+                       kgem_debug_print(data, offset, i, "(%s, %s, %s, %s), "
+                                 "dst offset 0x%02x bytes\n",
+                                 get_965_element_component(data[i], 0),
+                                 get_965_element_component(data[i], 1),
+                                 get_965_element_component(data[i], 2),
+                                 get_965_element_component(data[i], 3),
+                                 (data[i] & 0xff) * 4);
+                       i++;
+               }
+               return len;
+
+       case 0x780d:
+               assert(len == 4);
+               kgem_debug_print(data, offset, 0, "3DSTATE_VIEWPORT_STATE_POINTERS\n");
+               kgem_debug_print(data, offset, 1, "clip\n");
+               kgem_debug_print(data, offset, 2, "sf\n");
+               kgem_debug_print(data, offset, 3, "cc\n");
+               return len;
+
+       case 0x780a:
+               assert(len == 3);
+               kgem_debug_print(data, offset, 0, "3DSTATE_INDEX_BUFFER\n");
+               kgem_debug_print(data, offset, 1, "beginning buffer address\n");
+               kgem_debug_print(data, offset, 2, "ending buffer address\n");
+               return len;
+
+       case 0x780e:
+               assert(len == 4);
+               kgem_debug_print(data, offset, 0, "3DSTATE_CC_STATE_POINTERS\n");
+               kgem_debug_print(data, offset, 1, "blend%s\n",
+                                data[1] & 1 ? " update" : "");
+               if (data[1] & 1)
+                       gen6_decode_blend(kgem, data+1);
+               kgem_debug_print(data, offset, 2, "depth+stencil%s\n",
+                                data[2] & 1 ? " update" : "");
+               kgem_debug_print(data, offset, 3, "cc%s\n",
+                                data[3] & 1 ? " update" : "");
+               return len;
+
+       case 0x780f:
+               assert(len == 2);
+               kgem_debug_print(data, offset, 0, "3DSTATE_SCISSOR_POINTERS\n");
+               kgem_debug_print(data, offset, 1, "scissor rect offset\n");
+               return len;
+
+       case 0x7810:
+               assert(len == 6);
+               kgem_debug_print(data, offset, 0, "3DSTATE_VS\n");
+               kgem_debug_print(data, offset, 1, "kernel pointer\n");
+               kgem_debug_print(data, offset, 2, "SPF=%d, VME=%d, Sampler Count %d, "
+                         "Binding table count %d\n",
+                         (data[2] >> 31) & 1,
+                         (data[2] >> 30) & 1,
+                         (data[2] >> 27) & 7,
+                         (data[2] >> 18) & 0xff);
+               kgem_debug_print(data, offset, 3, "scratch offset\n");
+               kgem_debug_print(data, offset, 4, "Dispatch GRF start %d, VUE read length %d, "
+                         "VUE read offset %d\n",
+                         (data[4] >> 20) & 0x1f,
+                         (data[4] >> 11) & 0x3f,
+                         (data[4] >> 4) & 0x3f);
+               kgem_debug_print(data, offset, 5, "Max Threads %d, Vertex Cache %sable, "
+                         "VS func %sable\n",
+                         ((data[5] >> 25) & 0x7f) + 1,
+                         (data[5] & (1 << 1)) != 0 ? "dis" : "en",
+                         (data[5] & 1) != 0 ? "en" : "dis");
+               return len;
+
+       case 0x7811:
+               assert(len == 7);
+               kgem_debug_print(data, offset, 0, "3DSTATE_GS\n");
+               kgem_debug_print(data, offset, 1, "kernel pointer\n");
+               kgem_debug_print(data, offset, 2, "SPF=%d, VME=%d, Sampler Count %d, "
+                         "Binding table count %d\n",
+                         (data[2] >> 31) & 1,
+                         (data[2] >> 30) & 1,
+                         (data[2] >> 27) & 7,
+                         (data[2] >> 18) & 0xff);
+               kgem_debug_print(data, offset, 3, "scratch offset\n");
+               kgem_debug_print(data, offset, 4, "Dispatch GRF start %d, VUE read length %d, "
+                         "VUE read offset %d\n",
+                         (data[4] & 0xf),
+                         (data[4] >> 11) & 0x3f,
+                         (data[4] >> 4) & 0x3f);
+               kgem_debug_print(data, offset, 5, "Max Threads %d, Rendering %sable\n",
+                         ((data[5] >> 25) & 0x7f) + 1,
+                         (data[5] & (1 << 8)) != 0 ? "en" : "dis");
+               kgem_debug_print(data, offset, 6, "Reorder %sable, Discard Adjaceny %sable, "
+                         "GS %sable\n",
+                         (data[6] & (1 << 30)) != 0 ? "en" : "dis",
+                         (data[6] & (1 << 29)) != 0 ? "en" : "dis",
+                         (data[6] & (1 << 15)) != 0 ? "en" : "dis");
+               return len;
+
+       case 0x7812:
+               assert(len == 4);
+               kgem_debug_print(data, offset, 0, "3DSTATE_CLIP\n");
+               kgem_debug_print(data, offset, 1, "UserClip distance cull test mask 0x%x\n",
+                         data[1] & 0xff);
+               kgem_debug_print(data, offset, 2, "Clip %sable, API mode %s, Viewport XY test %sable, "
+                         "Viewport Z test %sable, Guardband test %sable, Clip mode %d, "
+                         "Perspective Divide %sable, Non-Perspective Barycentric %sable, "
+                         "Tri Provoking %d, Line Provoking %d, Trifan Provoking %d\n",
+                         (data[2] & (1 << 31)) != 0 ? "en" : "dis",
+                         (data[2] & (1 << 30)) != 0 ? "D3D" : "OGL",
+                         (data[2] & (1 << 28)) != 0 ? "en" : "dis",
+                         (data[2] & (1 << 27)) != 0 ? "en" : "dis",
+                         (data[2] & (1 << 26)) != 0 ? "en" : "dis",
+                         (data[2] >> 13) & 7,
+                         (data[2] & (1 << 9)) != 0 ? "dis" : "en",
+                         (data[2] & (1 << 8)) != 0 ? "en" : "dis",
+                         (data[2] >> 4) & 3,
+                         (data[2] >> 2) & 3,
+                         (data[2] & 3));
+               kgem_debug_print(data, offset, 3, "Min PointWidth %d, Max PointWidth %d, "
+                         "Force Zero RTAIndex %sable, Max VPIndex %d\n",
+                         (data[3] >> 17) & 0x7ff,
+                         (data[3] >> 6) & 0x7ff,
+                         (data[3] & (1 << 5)) != 0 ? "en" : "dis",
+                         (data[3] & 0xf));
+               return len;
+
+       case 0x7813:
+               gen6_update_sf_state(kgem, data);
+               assert(len == 20);
+               kgem_debug_print(data, offset, 0, "3DSTATE_SF\n");
+               kgem_debug_print(data, offset, 1, "Attrib Out %d, Attrib Swizzle %sable, VUE read length %d, "
+                         "VUE read offset %d\n",
+                         (data[1] >> 22) & 0x3f,
+                         (data[1] & (1 << 21)) != 0 ? "en" : "dis",
+                         (data[1] >> 11) & 0x1f,
+                         (data[1] >> 4) & 0x3f);
+               kgem_debug_print(data, offset, 2, "Legacy Global DepthBias %sable, FrontFace fill %d, BF fill %d, "
+                         "VP transform %sable, FrontWinding_%s\n",
+                         (data[2] & (1 << 11)) != 0 ? "en" : "dis",
+                         (data[2] >> 5) & 3,
+                         (data[2] >> 3) & 3,
+                         (data[2] & (1 << 1)) != 0 ? "en" : "dis",
+                         (data[2] & 1) != 0 ? "CCW" : "CW");
+               kgem_debug_print(data, offset, 3, "AA %sable, CullMode %d, Scissor %sable, Multisample m ode %d\n",
+                         (data[3] & (1 << 31)) != 0 ? "en" : "dis",
+                         (data[3] >> 29) & 3,
+                         (data[3] & (1 << 11)) != 0 ? "en" : "dis",
+                         (data[3] >> 8) & 3);
+               kgem_debug_print(data, offset, 4, "Last Pixel %sable, SubPixel Precision %d, Use PixelWidth %d\n",
+                         (data[4] & (1 << 31)) != 0 ? "en" : "dis",
+                         (data[4] & (1 << 12)) != 0 ? 4 : 8,
+                         (data[4] & (1 << 11)) != 0);
+               kgem_debug_print(data, offset, 5, "Global Depth Offset Constant %f\n", unpack_float(data[5]));
+               kgem_debug_print(data, offset, 6, "Global Depth Offset Scale %f\n", unpack_float(data[6]));
+               kgem_debug_print(data, offset, 7, "Global Depth Offset Clamp %f\n", unpack_float(data[7]));
+               for (i = 0, j = 0; i < 8; i++, j+=2)
+                       kgem_debug_print(data, offset, i+8, "Attrib %d (Override %s%s%s%s, Const Source %d, Swizzle Select %d, "
+                                 "Source %d); Attrib %d (Override %s%s%s%s, Const Source %d, Swizzle Select %d, Source %d)\n",
+                                 j+1,
+                                 (data[8+i] & (1 << 31)) != 0 ? "W":"",
+                                 (data[8+i] & (1 << 30)) != 0 ? "Z":"",
+                                 (data[8+i] & (1 << 29)) != 0 ? "Y":"",
+                                 (data[8+i] & (1 << 28)) != 0 ? "X":"",
+                                 (data[8+i] >> 25) & 3, (data[8+i] >> 22) & 3,
+                                 (data[8+i] >> 16) & 0x1f,
+                                 j,
+                                 (data[8+i] & (1 << 15)) != 0 ? "W":"",
+                                 (data[8+i] & (1 << 14)) != 0 ? "Z":"",
+                                 (data[8+i] & (1 << 13)) != 0 ? "Y":"",
+                                 (data[8+i] & (1 << 12)) != 0 ? "X":"",
+                                 (data[8+i] >> 9) & 3, (data[8+i] >> 6) & 3,
+                                 (data[8+i] & 0x1f));
+               kgem_debug_print(data, offset, 16, "Point Sprite TexCoord Enable\n");
+               kgem_debug_print(data, offset, 17, "Const Interp Enable\n");
+               kgem_debug_print(data, offset, 18, "Attrib 7-0 WrapShortest Enable\n");
+               kgem_debug_print(data, offset, 19, "Attrib 15-8 WrapShortest Enable\n");
+
+               return len;
+
+       case 0x7814:
+               assert(len == 9);
+               kgem_debug_print(data, offset, 0, "3DSTATE_WM\n");
+               kgem_debug_print(data, offset, 1, "kernel start pointer 0\n");
+               kgem_debug_print(data, offset, 2, "SPF=%d, VME=%d, Sampler Count %d, "
+                         "Binding table count %d\n",
+                         (data[2] >> 31) & 1,
+                         (data[2] >> 30) & 1,
+                         (data[2] >> 27) & 7,
+                         (data[2] >> 18) & 0xff);
+               kgem_debug_print(data, offset, 3, "scratch offset\n");
+               kgem_debug_print(data, offset, 4, "Depth Clear %d, Depth Resolve %d, HiZ Resolve %d, "
+                         "Dispatch GRF start[0] %d, start[1] %d, start[2] %d\n",
+                         (data[4] & (1 << 30)) != 0,
+                         (data[4] & (1 << 28)) != 0,
+                         (data[4] & (1 << 27)) != 0,
+                         (data[4] >> 16) & 0x7f,
+                         (data[4] >> 8) & 0x7f,
+                         (data[4] & 0x7f));
+               kgem_debug_print(data, offset, 5, "MaxThreads %d, PS KillPixel %d, PS computed Z %d, "
+                         "PS use sourceZ %d, Thread Dispatch %d, PS use sourceW %d, Dispatch32 %d, "
+                         "Dispatch16 %d, Dispatch8 %d\n",
+                         ((data[5] >> 25) & 0x7f) + 1,
+                         (data[5] & (1 << 22)) != 0,
+                         (data[5] & (1 << 21)) != 0,
+                         (data[5] & (1 << 20)) != 0,
+                         (data[5] & (1 << 19)) != 0,
+                         (data[5] & (1 << 8)) != 0,
+                         (data[5] & (1 << 2)) != 0,
+                         (data[5] & (1 << 1)) != 0,
+                         (data[5] & (1 << 0)) != 0);
+               kgem_debug_print(data, offset, 6, "Num SF output %d, Pos XY offset %d, ZW interp mode %d , "
+                         "Barycentric interp mode 0x%x, Point raster rule %d, Multisample mode %d, "
+                         "Multisample Dispatch mode %d\n",
+                         (data[6] >> 20) & 0x3f,
+                         (data[6] >> 18) & 3,
+                         (data[6] >> 16) & 3,
+                         (data[6] >> 10) & 0x3f,
+                         (data[6] & (1 << 9)) != 0,
+                         (data[6] >> 1) & 3,
+                         (data[6] & 1));
+               kgem_debug_print(data, offset, 7, "kernel start pointer 1\n");
+               kgem_debug_print(data, offset, 8, "kernel start pointer 2\n");
+
+               return len;
+
+       case 0x7900:
+               assert(len == 4);
+               kgem_debug_print(data, offset, 0,
+                                "3DSTATE_DRAWING_RECTANGLE\n");
+               kgem_debug_print(data, offset, 1, "top left: %d, %d\n",
+                                (uint16_t)(data[1] & 0xffff),
+                                (uint16_t)(data[1] >> 16));
+               kgem_debug_print(data, offset, 2, "bottom right: %d, %d\n",
+                                (uint16_t)(data[2] & 0xffff),
+                                (uint16_t)(data[2] >> 16));
+               kgem_debug_print(data, offset, 3, "origin: %d, %d\n",
+                                (int16_t)(data[3] & 0xffff),
+                                (int16_t)(data[3] >> 16));
+               return len;
+
+       case 0x7905:
+               assert(len == 7);
+               kgem_debug_print(data, offset, 0,
+                         "3DSTATE_DEPTH_BUFFER\n");
+               kgem_debug_print(data, offset, 1, "%s, %s, pitch = %d bytes, %stiled, HiZ %d, Seperate Stencil %d\n",
+                         get_965_surfacetype(data[1] >> 29),
+                         get_965_depthformat((data[1] >> 18) & 0x7),
+                         (data[1] & 0x0001ffff) + 1,
+                         data[1] & (1 << 27) ? "" : "not ",
+                         (data[1] & (1 << 22)) != 0,
+                         (data[1] & (1 << 21)) != 0);
+               kgem_debug_print(data, offset, 2, "depth offset\n");
+               kgem_debug_print(data, offset, 3, "%dx%d\n",
+                         ((data[3] & 0x0007ffc0) >> 6) + 1,
+                         ((data[3] & 0xfff80000) >> 19) + 1);
+               kgem_debug_print(data, offset, 4, "volume depth\n");
+               kgem_debug_print(data, offset, 5, "\n");
+               kgem_debug_print(data, offset, 6, "\n");
+               return len;
+
+       case 0x7a00:
+               assert(len == 4 || len == 5);
+               switch ((data[1] >> 14) & 0x3) {
+               case 0: desc1 = "no write"; break;
+               case 1: desc1 = "qword write"; break;
+               case 2: desc1 = "PS_DEPTH_COUNT write"; break;
+               case 3: desc1 = "TIMESTAMP write"; break;
+               }
+               kgem_debug_print(data, offset, 0, "PIPE_CONTROL\n");
+               kgem_debug_print(data, offset, 1,
+                         "%s, %scs stall, %stlb invalidate, "
+                         "%ssync gfdt, %sdepth stall, %sRC write flush, "
+                         "%sinst flush, %sTC flush\n",
+                         desc1,
+                         data[1] & (1 << 20) ? "" : "no ",
+                         data[1] & (1 << 18) ? "" : "no ",
+                         data[1] & (1 << 17) ? "" : "no ",
+                         data[1] & (1 << 13) ? "" : "no ",
+                         data[1] & (1 << 12) ? "" : "no ",
+                         data[1] & (1 << 11) ? "" : "no ",
+                         data[1] & (1 << 10) ? "" : "no ");
+               if (len == 5) {
+                       kgem_debug_print(data, offset, 2, "destination address\n");
+                       kgem_debug_print(data, offset, 3, "immediate dword low\n");
+                       kgem_debug_print(data, offset, 4, "immediate dword high\n");
+               } else {
+                       for (i = 2; i < len; i++) {
+                               kgem_debug_print(data, offset, i, "\n");
+                       }
+               }
+               return len;
+
+       case 0x7b00:
+               assert(len == 6);
+               kgem_debug_print(data, offset, 0,
+                         "3DPRIMITIVE: %s %s\n",
+                         get_965_prim_type(data[0]),
+                         (data[0] & (1 << 15)) ? "random" : "sequential");
+               kgem_debug_print(data, offset, 1, "vertex count\n");
+               kgem_debug_print(data, offset, 2, "start vertex\n");
+               kgem_debug_print(data, offset, 3, "instance count\n");
+               kgem_debug_print(data, offset, 4, "start instance\n");
+               kgem_debug_print(data, offset, 5, "index bias\n");
+               primitive_out(kgem, data);
+               return len;
+       }
+
+       /* For the rest, just dump the bytes */
+       for (i = 0; i < ARRAY_SIZE(opcodes); i++)
+               if (op == opcodes[i].opcode)
+                       break;
+
+       assert(i < ARRAY_SIZE(opcodes));
+
+       len = 1;
+       kgem_debug_print(data, offset, 0, "%s\n", opcodes[i].name);
+       if (opcodes[i].max_len > 1) {
+               len = (data[0] & 0xff) + 2;
+               assert(len >= opcodes[i].min_len &&
+                      len <= opcodes[i].max_len);
+       }
+
+       for (i = 1; i < len; i++)
+               kgem_debug_print(data, offset, i, "dword %d\n", i);
+
+       return len;
+}
+
+void kgem_gen6_finish_state(struct kgem *kgem)
+{
+       finish_state(kgem);
+}
diff --git a/src/sna/kgem_debug_gen7.c b/src/sna/kgem_debug_gen7.c
new file mode 100644 (file)
index 0000000..1bc014b
--- /dev/null
@@ -0,0 +1,716 @@
+/*
+ * Copyright © 2007-2011 Intel 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.
+ *
+ * Authors:
+ *    Eric Anholt <eric@anholt.net>
+ *    Chris Wilson <chris"chris-wilson.co.uk>
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/mman.h>
+#include <assert.h>
+
+#include "sna.h"
+#include "sna_reg.h"
+#include "gen7_render.h"
+
+#include "kgem_debug.h"
+
+static struct state {
+       struct vertex_buffer {
+               int handle;
+               void *base;
+               const char *ptr;
+               int pitch;
+
+               struct kgem_bo *current;
+       } vb[33];
+       struct vertex_elements {
+               int buffer;
+               int offset;
+               bool valid;
+               uint32_t type;
+               uint8_t swizzle[4];
+       } ve[33];
+       int num_ve;
+
+       struct dynamic_state {
+               struct kgem_bo *current;
+               void *base, *ptr;
+       } dynamic_state;
+} state;
+
+static void gen7_update_vertex_buffer(struct kgem *kgem, const uint32_t *data)
+{
+       uint32_t reloc = sizeof(uint32_t) * (&data[1] - kgem->batch);
+       struct kgem_bo *bo = NULL;
+       void *base, *ptr;
+       int i;
+
+       for (i = 0; i < kgem->nreloc; i++)
+               if (kgem->reloc[i].offset == reloc)
+                       break;
+       assert(i < kgem->nreloc);
+       reloc = kgem->reloc[i].target_handle;
+
+       if (reloc == 0) {
+               base = kgem->batch;
+       } else {
+               list_for_each_entry(bo, &kgem->next_request->buffers, request)
+                       if (bo->handle == reloc)
+                               break;
+               assert(&bo->request != &kgem->next_request->buffers);
+               base = kgem_bo_map__debug(kgem, bo);
+       }
+       ptr = (char *)base + kgem->reloc[i].delta;
+
+       i = data[0] >> 26;
+
+       state.vb[i].current = bo;
+       state.vb[i].base = base;
+       state.vb[i].ptr = ptr;
+       state.vb[i].pitch = data[0] & 0x7ff;
+}
+
+static void gen7_update_dynamic_buffer(struct kgem *kgem, const uint32_t offset)
+{
+       uint32_t reloc = sizeof(uint32_t) * offset;
+       struct kgem_bo *bo = NULL;
+       void *base, *ptr;
+       int i;
+
+       if ((kgem->batch[offset] & 1) == 0)
+               return;
+
+       for (i = 0; i < kgem->nreloc; i++)
+               if (kgem->reloc[i].offset == reloc)
+                       break;
+       if(i < kgem->nreloc) {
+               reloc = kgem->reloc[i].target_handle;
+
+               if (reloc == 0) {
+                       base = kgem->batch;
+               } else {
+                       list_for_each_entry(bo, &kgem->next_request->buffers, request)
+                               if (bo->handle == reloc)
+                                       break;
+                       assert(&bo->request != &kgem->next_request->buffers);
+                       base = kgem_bo_map__debug(kgem, bo);
+               }
+               ptr = (char *)base + (kgem->reloc[i].delta & ~1);
+       } else {
+               bo = NULL;
+               base = NULL;
+               ptr = NULL;
+       }
+
+       state.dynamic_state.current = bo;
+       state.dynamic_state.base = base;
+       state.dynamic_state.ptr = ptr;
+}
+
+static uint32_t
+get_ve_component(uint32_t data, int component)
+{
+       return (data >> (16 + (3 - component) * 4)) & 0x7;
+}
+
+static void gen7_update_vertex_elements(struct kgem *kgem, int id, const uint32_t *data)
+{
+       state.ve[id].buffer = data[0] >> 26;
+       state.ve[id].valid = !!(data[0] & (1 << 25));
+       state.ve[id].type = (data[0] >> 16) & 0x1ff;
+       state.ve[id].offset = data[0] & 0x7ff;
+       state.ve[id].swizzle[0] = get_ve_component(data[1], 0);
+       state.ve[id].swizzle[1] = get_ve_component(data[1], 1);
+       state.ve[id].swizzle[2] = get_ve_component(data[1], 2);
+       state.ve[id].swizzle[3] = get_ve_component(data[1], 3);
+}
+
+static void gen7_update_sf_state(struct kgem *kgem, uint32_t *data)
+{
+       state.num_ve = 1 + ((data[1] >> 22) & 0x3f);
+}
+
+static void vertices_sint16_out(const struct vertex_elements *ve, const int16_t *v, int max)
+{
+       int c;
+
+       ErrorF("(");
+       for (c = 0; c < max; c++) {
+               switch (ve->swizzle[c]) {
+               case 0: ErrorF("#"); break;
+               case 1: ErrorF("%d", v[c]); break;
+               case 2: ErrorF("0.0"); break;
+               case 3: ErrorF("1.0"); break;
+               case 4: ErrorF("0x1"); break;
+               case 5: break;
+               default: ErrorF("?");
+               }
+               if (c < 3)
+                       ErrorF(", ");
+       }
+       for (; c < 4; c++) {
+               switch (ve->swizzle[c]) {
+               case 0: ErrorF("#"); break;
+               case 1: ErrorF("1.0"); break;
+               case 2: ErrorF("0.0"); break;
+               case 3: ErrorF("1.0"); break;
+               case 4: ErrorF("0x1"); break;
+               case 5: break;
+               default: ErrorF("?");
+               }
+               if (c < 3)
+                       ErrorF(", ");
+       }
+       ErrorF(")");
+}
+
+static void vertices_float_out(const struct vertex_elements *ve, const float *f, int max)
+{
+       int c, o;
+
+       ErrorF("(");
+       for (c = o = 0; c < 4 && o < max; c++) {
+               switch (ve->swizzle[c]) {
+               case 0: ErrorF("#"); break;
+               case 1: ErrorF("%f", f[o++]); break;
+               case 2: ErrorF("0.0"); break;
+               case 3: ErrorF("1.0"); break;
+               case 4: ErrorF("0x1"); break;
+               case 5: break;
+               default: ErrorF("?");
+               }
+               if (c < 3)
+                       ErrorF(", ");
+       }
+       for (; c < 4; c++) {
+               switch (ve->swizzle[c]) {
+               case 0: ErrorF("#"); break;
+               case 1: ErrorF("1.0"); break;
+               case 2: ErrorF("0.0"); break;
+               case 3: ErrorF("1.0"); break;
+               case 4: ErrorF("0x1"); break;
+               case 5: break;
+               default: ErrorF("?");
+               }
+               if (c < 3)
+                       ErrorF(", ");
+       }
+       ErrorF(")");
+}
+
+static void ve_out(const struct vertex_elements *ve, const void *ptr)
+{
+       switch (ve->type) {
+       case GEN7_SURFACEFORMAT_R32_FLOAT:
+               vertices_float_out(ve, ptr, 1);
+               break;
+       case GEN7_SURFACEFORMAT_R32G32_FLOAT:
+               vertices_float_out(ve, ptr, 2);
+               break;
+       case GEN7_SURFACEFORMAT_R32G32B32_FLOAT:
+               vertices_float_out(ve, ptr, 3);
+               break;
+       case GEN7_SURFACEFORMAT_R32G32B32A32_FLOAT:
+               vertices_float_out(ve, ptr, 4);
+               break;
+       case GEN7_SURFACEFORMAT_R16_SINT:
+               vertices_sint16_out(ve, ptr, 1);
+               break;
+       case GEN7_SURFACEFORMAT_R16G16_SINT:
+               vertices_sint16_out(ve, ptr, 2);
+               break;
+       case GEN7_SURFACEFORMAT_R16G16B16A16_SINT:
+               vertices_sint16_out(ve, ptr, 4);
+               break;
+       case GEN7_SURFACEFORMAT_R16_SSCALED:
+               vertices_sint16_out(ve, ptr, 1);
+               break;
+       case GEN7_SURFACEFORMAT_R16G16_SSCALED:
+               vertices_sint16_out(ve, ptr, 2);
+               break;
+       case GEN7_SURFACEFORMAT_R16G16B16A16_SSCALED:
+               vertices_sint16_out(ve, ptr, 4);
+               break;
+       }
+}
+
+static void indirect_vertex_out(struct kgem *kgem, uint32_t v)
+{
+       int i = 1;
+
+       do {
+               const struct vertex_elements *ve = &state.ve[i];
+               const struct vertex_buffer *vb = &state.vb[ve->buffer];
+               const void *ptr = vb->ptr + v * vb->pitch + ve->offset;
+
+               if (!ve->valid)
+                       continue;
+
+               ve_out(ve, ptr);
+
+               while (++i <= state.num_ve && !state.ve[i].valid)
+                       ;
+
+               if (i <= state.num_ve)
+                       ErrorF(", ");
+       } while (i <= state.num_ve);
+}
+
+static void primitive_out(struct kgem *kgem, uint32_t *data)
+{
+       int n;
+
+       assert((data[0] & (1<<15)) == 0); /* XXX index buffers */
+
+       for (n = 0; n < data[2]; n++) {
+               int v = data[3] + n;
+               ErrorF("        [%d:%d] = ", n, v);
+               indirect_vertex_out(kgem, v);
+               ErrorF("\n");
+       }
+}
+
+static void finish_state(struct kgem *kgem)
+{
+       memset(&state, 0, sizeof(state));
+}
+
+static void
+state_base_out(uint32_t *data, uint32_t offset, unsigned int index,
+              const char *name)
+{
+    if (data[index] & 1)
+       kgem_debug_print(data, offset, index,
+                 "%s state base address 0x%08x\n",
+                 name, data[index] & ~1);
+    else
+       kgem_debug_print(data, offset, index,
+                 "%s state base not updated\n",
+                 name);
+}
+
+static void
+state_max_out(uint32_t *data, uint32_t offset, unsigned int index,
+             const char *name)
+{
+       if (data[index] == 1)
+               kgem_debug_print(data, offset, index,
+                         "%s state upper bound disabled\n", name);
+       else if (data[index] & 1)
+               kgem_debug_print(data, offset, index,
+                         "%s state upper bound 0x%08x\n",
+                         name, data[index] & ~1);
+       else
+               kgem_debug_print(data, offset, index,
+                         "%s state upper bound not updated\n",
+                         name);
+}
+
+static const char *
+get_965_surfacetype(unsigned int surfacetype)
+{
+       switch (surfacetype) {
+       case 0: return "1D";
+       case 1: return "2D";
+       case 2: return "3D";
+       case 3: return "CUBE";
+       case 4: return "BUFFER";
+       case 7: return "NULL";
+       default: return "unknown";
+       }
+}
+
+static const char *
+get_965_depthformat(unsigned int depthformat)
+{
+       switch (depthformat) {
+       case 0: return "s8_z24float";
+       case 1: return "z32float";
+       case 2: return "z24s8";
+       case 5: return "z16";
+       default: return "unknown";
+       }
+}
+
+static const char *
+get_element_component(uint32_t data, int component)
+{
+       uint32_t component_control = (data >> (16 + (3 - component) * 4)) & 0x7;
+
+       switch (component_control) {
+       case 0:
+               return "nostore";
+       case 1:
+               switch (component) {
+               case 0: return "X";
+               case 1: return "Y";
+               case 2: return "Z";
+               case 3: return "W";
+               default: return "fail";
+               }
+       case 2:
+               return "0.0";
+       case 3:
+               return "1.0";
+       case 4:
+               return "0x1";
+       case 5:
+               return "VID";
+       default:
+               return "fail";
+       }
+}
+
+static const char *
+get_prim_type(uint32_t data)
+{
+       uint32_t primtype = data & 0x1f;
+
+       switch (primtype) {
+       case 0x01: return "point list";
+       case 0x02: return "line list";
+       case 0x03: return "line strip";
+       case 0x04: return "tri list";
+       case 0x05: return "tri strip";
+       case 0x06: return "tri fan";
+       case 0x07: return "quad list";
+       case 0x08: return "quad strip";
+       case 0x09: return "line list adj";
+       case 0x0a: return "line strip adj";
+       case 0x0b: return "tri list adj";
+       case 0x0c: return "tri strip adj";
+       case 0x0d: return "tri strip reverse";
+       case 0x0e: return "polygon";
+       case 0x0f: return "rect list";
+       case 0x10: return "line loop";
+       case 0x11: return "point list bf";
+       case 0x12: return "line strip cont";
+       case 0x13: return "line strip bf";
+       case 0x14: return "line strip cont bf";
+       case 0x15: return "tri fan no stipple";
+       default: return "fail";
+       }
+}
+
+struct reloc {
+       struct kgem_bo *bo;
+       void *base;
+};
+
+static void *
+get_reloc(struct kgem *kgem,
+         void *base, const uint32_t *reloc,
+         struct reloc *r)
+{
+       uint32_t delta = *reloc;
+
+       memset(r, 0, sizeof(*r));
+
+       if (base == 0) {
+               uint32_t handle = sizeof(uint32_t) * (reloc - kgem->batch);
+               struct kgem_bo *bo = NULL;
+               int i;
+
+               for (i = 0; i < kgem->nreloc; i++)
+                       if (kgem->reloc[i].offset == handle)
+                               break;
+               assert(i < kgem->nreloc);
+               handle = kgem->reloc[i].target_handle;
+               delta = kgem->reloc[i].delta;
+
+               if (handle == 0) {
+                       base = kgem->batch;
+               } else {
+                       list_for_each_entry(bo, &kgem->next_request->buffers, request)
+                               if (bo->handle == handle)
+                                       break;
+                       assert(&bo->request != &kgem->next_request->buffers);
+                       base = kgem_bo_map__debug(kgem, bo);
+                       r->bo = bo;
+                       r->base = base;
+               }
+       }
+
+       return (char *)base + (delta & ~3);
+}
+
+static const char *
+gen7_filter_to_string(uint32_t filter)
+{
+       switch (filter) {
+       default:
+       case GEN7_MAPFILTER_NEAREST: return "nearest";
+       case GEN7_MAPFILTER_LINEAR: return "linear";
+       }
+}
+
+static const char *
+gen7_repeat_to_string(uint32_t repeat)
+{
+       switch (repeat) {
+       default:
+       case GEN7_TEXCOORDMODE_CLAMP_BORDER: return "border";
+       case GEN7_TEXCOORDMODE_WRAP: return "wrap";
+       case GEN7_TEXCOORDMODE_CLAMP: return "clamp";
+       case GEN7_TEXCOORDMODE_MIRROR: return "mirror";
+       }
+}
+
+static void
+gen7_decode_sampler_state(struct kgem *kgem, const uint32_t *reloc)
+{
+       const struct gen7_sampler_state *ss;
+       struct reloc r;
+       const char *min, *mag;
+       const char *s_wrap, *t_wrap, *r_wrap;
+
+       ss = get_reloc(kgem, state.dynamic_state.ptr, reloc, &r);
+
+       min = gen7_filter_to_string(ss->ss0.min_filter);
+       mag = gen7_filter_to_string(ss->ss0.mag_filter);
+
+       s_wrap = gen7_repeat_to_string(ss->ss3.s_wrap_mode);
+       t_wrap = gen7_repeat_to_string(ss->ss3.t_wrap_mode);
+       r_wrap = gen7_repeat_to_string(ss->ss3.r_wrap_mode);
+
+       ErrorF("  Sampler 0:\n");
+       ErrorF("    filter: min=%s, mag=%s\n", min, mag);
+       ErrorF("    wrap: s=%s, t=%s, r=%s\n", s_wrap, t_wrap, r_wrap);
+
+       ss++;
+       min = gen7_filter_to_string(ss->ss0.min_filter);
+       mag = gen7_filter_to_string(ss->ss0.mag_filter);
+
+       s_wrap = gen7_repeat_to_string(ss->ss3.s_wrap_mode);
+       t_wrap = gen7_repeat_to_string(ss->ss3.t_wrap_mode);
+       r_wrap = gen7_repeat_to_string(ss->ss3.r_wrap_mode);
+
+       ErrorF("  Sampler 1:\n");
+       ErrorF("    filter: min=%s, mag=%s\n", min, mag);
+       ErrorF("    wrap: s=%s, t=%s, r=%s\n", s_wrap, t_wrap, r_wrap);
+}
+
+static const char *
+gen7_blend_factor_to_string(uint32_t v)
+{
+       switch (v) {
+#define C(x) case GEN7_BLENDFACTOR_##x: return #x;
+               C(ONE);
+               C(SRC_COLOR);
+               C(SRC_ALPHA);
+               C(DST_ALPHA);
+               C(DST_COLOR);
+               C(SRC_ALPHA_SATURATE);
+               C(CONST_COLOR);
+               C(CONST_ALPHA);
+               C(SRC1_COLOR);
+               C(SRC1_ALPHA);
+               C(ZERO);
+               C(INV_SRC_COLOR);
+               C(INV_SRC_ALPHA);
+               C(INV_DST_ALPHA);
+               C(INV_DST_COLOR);
+               C(INV_CONST_COLOR);
+               C(INV_CONST_ALPHA);
+               C(INV_SRC1_COLOR);
+               C(INV_SRC1_ALPHA);
+#undef C
+       default: return "???";
+       }
+}
+
+static const char *
+gen7_blend_function_to_string(uint32_t v)
+{
+       switch (v) {
+#define C(x) case GEN7_BLENDFUNCTION_##x: return #x;
+               C(ADD);
+               C(SUBTRACT);
+               C(REVERSE_SUBTRACT);
+               C(MIN);
+               C(MAX);
+#undef C
+       default: return "???";
+       }
+}
+
+static void
+gen7_decode_blend(struct kgem *kgem, const uint32_t *reloc)
+{
+       const struct gen7_blend_state *blend;
+       struct reloc r;
+       const char *dst, *src;
+       const char *func;
+
+       blend = get_reloc(kgem, state.dynamic_state.ptr, reloc, &r);
+
+       dst = gen7_blend_factor_to_string(blend->blend0.dest_blend_factor);
+       src = gen7_blend_factor_to_string(blend->blend0.source_blend_factor);
+       func = gen7_blend_function_to_string(blend->blend0.blend_func);
+
+       ErrorF("  Blend (%s): function %s, src=%s, dst=%s\n",
+              blend->blend0.blend_enable ? "enabled" : "disabled",
+              func, src, dst);
+}
+
+int kgem_gen7_decode_3d(struct kgem *kgem, uint32_t offset)
+{
+       static const struct {
+               uint32_t opcode;
+               int min_len;
+               int max_len;
+               const char *name;
+       } opcodes[] = {
+               { 0x6101, 6, 6, "STATE_BASE_ADDRESS" },
+               { 0x6102, 2, 2 , "STATE_SIP" },
+               { 0x6104, 1, 1, "3DSTATE_PIPELINE_SELECT" },
+               { 0x780a, 3, 3, "3DSTATE_INDEX_BUFFER" },
+               { 0x7900, 4, 4, "3DSTATE_DRAWING_RECTANGLE" },
+       };
+       uint32_t *data = kgem->batch + offset;
+       uint32_t op;
+       unsigned int len;
+       int i;
+       const char *name;
+
+       len = (data[0] & 0xff) + 2;
+       op = (data[0] & 0xffff0000) >> 16;
+       switch (op) {
+       case 0x6101:
+               i = 0;
+               kgem_debug_print(data, offset, i++, "STATE_BASE_ADDRESS\n");
+               assert(len == 10);
+
+               state_base_out(data, offset, i++, "general");
+               state_base_out(data, offset, i++, "surface");
+               state_base_out(data, offset, i++, "dynamic");
+               state_base_out(data, offset, i++, "indirect");
+               state_base_out(data, offset, i++, "instruction");
+
+               state_max_out(data, offset, i++, "general");
+               state_max_out(data, offset, i++, "dynamic");
+               state_max_out(data, offset, i++, "indirect");
+               state_max_out(data, offset, i++, "instruction");
+
+               gen7_update_dynamic_buffer(kgem, offset + 3);
+
+               return len;
+
+       case 0x7808:
+               assert((len - 1) % 4 == 0);
+               kgem_debug_print(data, offset, 0, "3DSTATE_VERTEX_BUFFERS\n");
+
+               for (i = 1; i < len;) {
+                       gen7_update_vertex_buffer(kgem, data + i);
+
+                       kgem_debug_print(data, offset, i, "buffer %d: %s, pitch %db\n",
+                                 data[i] >> 26,
+                                 data[i] & (1 << 20) ? "random" : "sequential",
+                                 data[i] & 0x07ff);
+                       i++;
+                       kgem_debug_print(data, offset, i++, "buffer address\n");
+                       kgem_debug_print(data, offset, i++, "max index\n");
+                       kgem_debug_print(data, offset, i++, "mbz\n");
+               }
+               return len;
+
+       case 0x7809:
+               assert((len + 1) % 2 == 0);
+               kgem_debug_print(data, offset, 0, "3DSTATE_VERTEX_ELEMENTS\n");
+
+               for (i = 1; i < len;) {
+                       gen7_update_vertex_elements(kgem, (i - 1)/2, data + i);
+
+                       kgem_debug_print(data, offset, i, "buffer %d: %svalid, type 0x%04x, "
+                                 "src offset 0x%04x bytes\n",
+                                 data[i] >> 26,
+                                 data[i] & (1 << 25) ? "" : "in",
+                                 (data[i] >> 16) & 0x1ff,
+                                 data[i] & 0x07ff);
+                       i++;
+                       kgem_debug_print(data, offset, i, "(%s, %s, %s, %s), "
+                                 "dst offset 0x%02x bytes\n",
+                                 get_element_component(data[i], 0),
+                                 get_element_component(data[i], 1),
+                                 get_element_component(data[i], 2),
+                                 get_element_component(data[i], 3),
+                                 (data[i] & 0xff) * 4);
+                       i++;
+               }
+               return len;
+
+       case 0x780a:
+               assert(len == 3);
+               kgem_debug_print(data, offset, 0, "3DSTATE_INDEX_BUFFER\n");
+               kgem_debug_print(data, offset, 1, "beginning buffer address\n");
+               kgem_debug_print(data, offset, 2, "ending buffer address\n");
+               return len;
+
+       case 0x7b00:
+               assert(len == 7);
+               kgem_debug_print(data, offset, 0, "3DPRIMITIVE\n");
+               kgem_debug_print(data, offset, 1, "type %s, %s\n",
+                         get_prim_type(data[1]),
+                         (data[1] & (1 << 15)) ? "random" : "sequential");
+               kgem_debug_print(data, offset, 2, "vertex count\n");
+               kgem_debug_print(data, offset, 3, "start vertex\n");
+               kgem_debug_print(data, offset, 4, "instance count\n");
+               kgem_debug_print(data, offset, 5, "start instance\n");
+               kgem_debug_print(data, offset, 6, "index bias\n");
+               primitive_out(kgem, data);
+               return len;
+       }
+
+       /* For the rest, just dump the bytes */
+       name = NULL;
+       for (i = 0; i < ARRAY_SIZE(opcodes); i++)
+               if (op == opcodes[i].opcode) {
+                       name = opcodes[i].name;
+                       break;
+               }
+
+       len = (data[0] & 0xff) + 2;
+       if (name == NULL) {
+               kgem_debug_print(data, offset, 0, "unknown\n");
+       } else {
+               kgem_debug_print(data, offset, 0, "%s\n", opcodes[i].name);
+               if (opcodes[i].max_len > 1) {
+                       assert(len >= opcodes[i].min_len &&
+                                       len <= opcodes[i].max_len);
+               }
+       }
+       for (i = 1; i < len; i++)
+               kgem_debug_print(data, offset, i, "dword %d\n", i);
+
+       return len;
+}
+
+void kgem_gen7_finish_state(struct kgem *kgem)
+{
+       finish_state(kgem);
+}
diff --git a/src/sna/rop.h b/src/sna/rop.h
new file mode 100644 (file)
index 0000000..9db15cf
--- /dev/null
@@ -0,0 +1,264 @@
+#ifndef ROP_H
+#define ROP_H
+
+#define ROP_0          0x00
+#define ROP_DPSoon     0x01
+#define ROP_DPSona     0x02
+#define ROP_PSon       0x03
+#define ROP_SDPona     0x04
+#define ROP_DPon       0x05
+#define ROP_PDSxnon    0x06
+#define ROP_PDSaon     0x07
+#define ROP_SDPnaa     0x08
+#define ROP_PDSxon     0x09
+#define ROP_DPna       0x0A
+#define ROP_PSDnaon    0x0B
+#define ROP_SPna       0x0C
+#define ROP_PDSnaon    0x0D
+#define ROP_PDSonon    0x0E
+#define ROP_Pn         0x0F
+#define ROP_PDSona     0x10
+#define ROP_DSon       0x11
+#define ROP_SDPxnon    0x12
+#define ROP_SDPaon     0x13
+#define ROP_DPSxnon    0x14
+#define ROP_DPSaon     0x15
+#define ROP_PSDPSanaxx 0x16
+#define ROP_SSPxDSxaxn 0x17
+#define ROP_SPxPDxa    0x18
+#define ROP_SDPSanaxn  0x19
+#define ROP_PDSPaox    0x1A
+#define ROP_SDPSxaxn   0x1B
+#define ROP_PSDPaox    0x1C
+#define ROP_DSPDxaxn   0x1D
+#define ROP_PDSox      0x1E
+#define ROP_PDSoan     0x1F
+#define ROP_DPSnaa     0x20
+#define ROP_SDPxon     0x21
+#define ROP_DSna       0x22
+#define ROP_SPDnaon    0x23
+#define ROP_SPxDSxa    0x24
+#define ROP_PDSPanaxn  0x25
+#define ROP_SDPSaox    0x26
+#define ROP_SDPSxnox   0x27
+#define ROP_DPSxa      0x28
+#define ROP_PSDPSaoxxn 0x29
+#define ROP_DPSana     0x2A
+#define ROP_SSPxPDxaxn 0x2B
+#define ROP_SPDSoax    0x2C
+#define ROP_PSDnox     0x2D
+#define ROP_PSDPxox    0x2E
+#define ROP_PSDnoan    0x2F
+#define ROP_PSna       0x30
+#define ROP_SDPnaon    0x31
+#define ROP_SDPSoox    0x32
+#define ROP_Sn         0x33
+#define ROP_SPDSaox    0x34
+#define ROP_SPDSxnox   0x35
+#define ROP_SDPox      0x36
+#define ROP_SDPoan     0x37
+#define ROP_PSDPoax    0x38
+#define ROP_SPDnox     0x39
+#define ROP_SPDSxox    0x3A
+#define ROP_SPDnoan    0x3B
+#define ROP_PSx                0x3C
+#define ROP_SPDSonox   0x3D
+#define ROP_SPDSnaox   0x3E
+#define ROP_PSan       0x3F
+#define ROP_PSDnaa     0x40
+#define ROP_DPSxon     0x41
+#define ROP_SDxPDxa    0x42
+#define ROP_SPDSanaxn  0x43
+#define ROP_SDna       0x44
+#define ROP_DPSnaon    0x45
+#define ROP_DSPDaox    0x46
+#define ROP_PSDPxaxn   0x47
+#define ROP_SDPxa      0x48
+#define ROP_PDSPDaoxxn 0x49
+#define ROP_DPSDoax    0x4A
+#define ROP_PDSnox     0x4B
+#define ROP_SDPana     0x4C
+#define ROP_SSPxDSxoxn 0x4D
+#define ROP_PDSPxox    0x4E
+#define ROP_PDSnoan    0x4F
+#define ROP_PDna       0x50
+#define ROP_DSPnaon    0x51
+#define ROP_DPSDaox    0x52
+#define ROP_SPDSxaxn   0x53
+#define ROP_DPSonon    0x54
+#define ROP_Dn         0x55
+#define ROP_DPSox      0x56
+#define ROP_DPSoan     0x57
+#define ROP_PDSPoax    0x58
+#define ROP_DPSnox     0x59
+#define ROP_DPx                0x5A
+#define ROP_DPSDonox   0x5B
+#define ROP_DPSDxox    0x5C
+#define ROP_DPSnoan    0x5D
+#define ROP_DPSDnaox   0x5E
+#define ROP_DPan       0x5F
+#define ROP_PDSxa      0x60
+#define ROP_DSPDSaoxxn 0x61
+#define ROP_DSPDoax    0x62
+#define ROP_SDPnox     0x63
+#define ROP_SDPSoax    0x64
+#define ROP_DSPnox     0x65
+#define ROP_DSx                0x66
+#define ROP_SDPSonox   0x67
+#define ROP_DSPDSonoxxn        0x68
+#define ROP_PDSxxn     0x69
+#define ROP_DPSax      0x6A
+#define ROP_PSDPSoaxxn 0x6B
+#define ROP_SDPax      0x6C
+#define ROP_PDSPDoaxxn 0x6D
+#define ROP_SDPSnoax   0x6E
+#define ROP_PDSxnan    0x6F
+#define ROP_PDSana     0x70
+#define ROP_SSDxPDxaxn 0x71
+#define ROP_SDPSxox    0x72
+#define ROP_SDPnoan    0x73
+#define ROP_DSPDxox    0x74
+#define ROP_DSPnoan    0x75
+#define ROP_SDPSnaox   0x76
+#define ROP_DSan       0x77
+#define ROP_PDSax      0x78
+#define ROP_DSPDSoaxxn 0x79
+#define ROP_DPSDnoax   0x7A
+#define ROP_SDPxnan    0x7B
+#define ROP_SPDSnoax   0x7C
+#define ROP_DPSxnan    0x7D
+#define ROP_SPxDSxo    0x7E
+#define ROP_DPSaan     0x7F
+#define ROP_DPSaa      0x80
+#define ROP_SPxDSxon   0x81
+#define ROP_DPSxna     0x82
+#define ROP_SPDSnoaxn  0x83
+#define ROP_SDPxna     0x84
+#define ROP_PDSPnoaxn  0x85
+#define ROP_DSPDSoaxx  0x86
+#define ROP_PDSaxn     0x87
+#define ROP_DSa                0x88
+#define ROP_SDPSnaoxn  0x89
+#define ROP_DSPnoa     0x8A
+#define ROP_DSPDxoxn   0x8B
+#define ROP_SDPnoa     0x8C
+#define ROP_SDPSxoxn   0x8D
+#define ROP_SSDxPDxax  0x8E
+#define ROP_PDSanan    0x8F
+#define ROP_PDSxna     0x90
+#define ROP_SDPSnoaxn  0x91
+#define ROP_DPSDPoaxx  0x92
+#define ROP_SPDaxn     0x93
+#define ROP_PSDPSoaxx  0x94
+#define ROP_DPSaxn     0x95
+#define ROP_DPSxx      0x96
+#define ROP_PSDPSonoxx 0x97
+#define ROP_SDPSonoxn  0x98
+#define ROP_DSxn       0x99
+#define ROP_DPSnax     0x9A
+#define ROP_SDPSoaxn   0x9B
+#define ROP_SPDnax     0x9C
+#define ROP_DSPDoaxn   0x9D
+#define ROP_DSPDSaoxx  0x9E
+#define ROP_PDSxan     0x9F
+#define ROP_DPa                0xA0
+#define ROP_PDSPnaoxn  0xA1
+#define ROP_DPSnoa     0xA2
+#define ROP_DPSDxoxn   0xA3
+#define ROP_PDSPonoxn  0xA4
+#define ROP_PDxn       0xA5
+#define ROP_DSPnax     0xA6
+#define ROP_PDSPoaxn   0xA7
+#define ROP_DPSoa      0xA8
+#define ROP_DPSoxn     0xA9
+#define ROP_D          0xAA
+#define ROP_DPSono     0xAB
+#define ROP_SPDSxax    0xAC
+#define ROP_DPSDaoxn   0xAD
+#define ROP_DSPnao     0xAE
+#define ROP_DPno       0xAF
+#define ROP_PDSnoa     0xB0
+#define ROP_PDSPxoxn   0xB1
+#define ROP_SSPxDSxox  0xB2
+#define ROP_SDPanan    0xB3
+#define ROP_PSDnax     0xB4
+#define ROP_DPSDoaxn   0xB5
+#define ROP_DPSDPaoxx  0xB6
+#define ROP_SDPxan     0xB7
+#define ROP_PSDPxax    0xB8
+#define ROP_DSPDaoxn   0xB9
+#define ROP_DPSnao     0xBA
+#define ROP_DSno       0xBB
+#define ROP_SPDSanax   0xBC
+#define ROP_SDxPDxan   0xBD
+#define ROP_DPSxo      0xBE
+#define ROP_DPSano     0xBF
+#define ROP_Psa                0xC0
+#define ROP_SPDSnaoxn  0xC1
+#define ROP_SPDSonoxn  0xC2
+#define ROP_PSxn       0xC3
+#define ROP_SPDnoa     0xC4
+#define ROP_SPDSxoxn   0xC5
+#define ROP_SDPnax     0xC6
+#define ROP_PSDPoaxn   0xC7
+#define ROP_SDPoa      0xC8
+#define ROP_SPDoxn     0xC9
+#define ROP_DPSDxax    0xCA
+#define ROP_SPDSaoxn   0xCB
+#define ROP_S          0xCC
+#define ROP_SDPono     0xCD
+#define ROP_SDPnao     0xCE
+#define ROP_SPno       0xCF
+#define ROP_PSDnoa     0xD0
+#define ROP_PSDPxoxn   0xD1
+#define ROP_PDSnax     0xD2
+#define ROP_SPDSoaxn   0xD3
+#define ROP_SSPxPDxax  0xD4
+#define ROP_DPSanan    0xD5
+#define ROP_PSDPSaoxx  0xD6
+#define ROP_DPSxan     0xD7
+#define ROP_PDSPxax    0xD8
+#define ROP_SDPSaoxn   0xD9
+#define ROP_DPSDanax   0xDA
+#define ROP_SPxDSxan   0xDB
+#define ROP_SPDnao     0xDC
+#define ROP_SDno       0xDD
+#define ROP_SDPxo      0xDE
+#define ROP_SDPano     0xDF
+#define ROP_PDSoa      0xE0
+#define ROP_PDSoxn     0xE1
+#define ROP_DSPDxax    0xE2
+#define ROP_PSDPaoxn   0xE3
+#define ROP_SDPSxax    0xE4
+#define ROP_PDSPaoxn   0xE5
+#define ROP_SDPSanax   0xE6
+#define ROP_SPxPDxan   0xE7
+#define ROP_SSPxDSxax  0xE8
+#define ROP_DSPDSanaxxn        0xE9
+#define ROP_DPSao      0xEA
+#define ROP_DPSxno     0xEB
+#define ROP_SDPao      0xEC
+#define ROP_SDPxno     0xED
+#define ROP_DSo                0xEE
+#define ROP_SDPnoo     0xEF
+#define ROP_P          0xF0
+#define ROP_PDSono     0xF1
+#define ROP_PDSnao     0xF2
+#define ROP_PSno       0xF3
+#define ROP_PSDnao     0xF4
+#define ROP_PDno       0xF5
+#define ROP_PDSxo      0xF6
+#define ROP_PDSano     0xF7
+#define ROP_PDSao      0xF8
+#define ROP_PDSxno     0xF9
+#define ROP_DPo                0xFA
+#define ROP_DPSnoo     0xFB
+#define ROP_PSo                0xFC
+#define ROP_PSDnoo     0xFD
+#define ROP_DPSoo      0xFE
+#define ROP_1          0xFF
+
+#define NO_SRC_ROP(rop) \
+   ((rop == GXnoop) || (rop == GXset) || (rop == GXclear) || (rop == GXinvert))
+
+#endif /* ROP_H */
diff --git a/src/sna/sna.h b/src/sna/sna.h
new file mode 100644 (file)
index 0000000..031be72
--- /dev/null
@@ -0,0 +1,804 @@
+/**************************************************************************
+
+Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
+Copyright © 2002 David Dawes
+
+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, sub license, 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 NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS 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.
+
+**************************************************************************/
+
+/*
+ * Authors:
+ *   Keith Whitwell <keith@tungstengraphics.com>
+ *   David Dawes <dawes@xfree86.org>
+ *
+ */
+
+#ifndef _SNA_H_
+#define _SNA_H_
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdint.h>
+#include "compiler.h"
+
+#include <xorg-server.h>
+
+#include <xf86Crtc.h>
+#if XF86_CRTC_VERSION >= 5
+#define HAS_PIXMAP_SHARING 1
+#endif
+
+#include <xf86str.h>
+#include <windowstr.h>
+#include <glyphstr.h>
+#include <picturestr.h>
+#include <gcstruct.h>
+
+#include <pciaccess.h>
+
+#include <xf86drmMode.h>
+
+#include "../compat-api.h"
+#include <drm.h>
+#include <i915_drm.h>
+
+#ifdef HAVE_DRI2_H
+#include <dri2.h>
+#endif
+
+#if HAVE_UDEV
+#include <libudev.h>
+#endif
+
+#if HAS_DEBUG_FULL
+#define DBG(x) ErrorF x
+#else
+#define DBG(x)
+#endif
+
+#define DEBUG_NO_RENDER 0
+#define DEBUG_NO_BLT 0
+
+#define DEBUG_FLUSH_BATCH 0
+#define DEBUG_FLUSH_SYNC 0
+
+#define TEST_ALL 0
+#define TEST_ACCEL (TEST_ALL || 0)
+#define TEST_BATCH (TEST_ALL || 0)
+#define TEST_BLT (TEST_ALL || 0)
+#define TEST_COMPOSITE (TEST_ALL || 0)
+#define TEST_DAMAGE (TEST_ALL || 0)
+#define TEST_GRADIENT (TEST_ALL || 0)
+#define TEST_GLYPHS (TEST_ALL || 0)
+#define TEST_IO (TEST_ALL || 0)
+#define TEST_KGEM (TEST_ALL || 0)
+#define TEST_RENDER (TEST_ALL || 0)
+
+#include "intel_driver.h"
+#include "intel_list.h"
+#include "kgem.h"
+#include "sna_damage.h"
+#include "sna_render.h"
+#include "fb/fb.h"
+
+#define SNA_CURSOR_X                   64
+#define SNA_CURSOR_Y                   SNA_CURSOR_X
+
+struct sna_pixmap {
+       PixmapPtr pixmap;
+       struct kgem_bo *gpu_bo, *cpu_bo;
+       struct sna_damage *gpu_damage, *cpu_damage;
+       void *ptr;
+
+       struct list list;
+       struct list inactive;
+
+       uint32_t stride;
+       uint32_t clear_color;
+
+       uint32_t flush;
+
+#define SOURCE_BIAS 4
+       uint16_t source_count;
+       uint8_t pinned :3;
+#define PIN_SCANOUT 0x1
+#define PIN_DRI 0x2
+#define PIN_PRIME 0x4
+       uint8_t mapped :1;
+       uint8_t shm :1;
+       uint8_t clear :1;
+       uint8_t undamaged :1;
+       uint8_t create :3;
+       uint8_t header :1;
+       uint8_t cpu :1;
+};
+
+struct sna_glyph {
+       PicturePtr atlas;
+       pixman_image_t *image;
+       struct sna_coordinate coordinate;
+       uint16_t size, pos;
+};
+
+static inline PixmapPtr get_window_pixmap(WindowPtr window)
+{
+       return fbGetWindowPixmap(window);
+}
+
+static inline PixmapPtr get_drawable_pixmap(DrawablePtr drawable)
+{
+       if (drawable->type == DRAWABLE_PIXMAP)
+               return (PixmapPtr)drawable;
+       else
+               return get_window_pixmap((WindowPtr)drawable);
+}
+
+extern DevPrivateKeyRec sna_pixmap_key;
+
+constant static inline struct sna_pixmap *sna_pixmap(PixmapPtr pixmap)
+{
+       return ((void **)dixGetPrivateAddr(&pixmap->devPrivates, &sna_pixmap_key))[1];
+}
+
+static inline struct sna_pixmap *sna_pixmap_from_drawable(DrawablePtr drawable)
+{
+       return sna_pixmap(get_drawable_pixmap(drawable));
+}
+
+struct sna_gc {
+       long changes;
+       long serial;
+
+       GCFuncs *old_funcs;
+       void *priv;
+};
+
+static inline struct sna_gc *sna_gc(GCPtr gc)
+{
+       return dixGetPrivateAddr(&gc->devPrivates, &sna_gc_key);
+}
+
+enum {
+       FLUSH_TIMER = 0,
+       THROTTLE_TIMER,
+       EXPIRE_TIMER,
+       INACTIVE_TIMER,
+#if DEBUG_MEMORY
+       DEBUG_MEMORY_TIMER,
+#endif
+       NUM_TIMERS
+};
+
+struct sna {
+       ScrnInfoPtr scrn;
+
+       unsigned flags;
+#define SNA_NO_THROTTLE                0x1
+#define SNA_NO_DELAYED_FLUSH   0x2
+#define SNA_NO_WAIT            0x4
+#define SNA_NO_FLIP            0x8
+#define SNA_TEAR_FREE          0x10
+#define SNA_FORCE_SHADOW       0x20
+
+       unsigned watch_flush;
+
+       struct timeval timer_tv;
+       uint32_t timer_expire[NUM_TIMERS];
+       uint16_t timer_active;
+
+       int vblank_interval;
+
+       struct list flush_pixmaps;
+       struct list active_pixmaps;
+       struct list inactive_clock[2];
+
+       PixmapPtr front;
+       PixmapPtr freed_pixmap;
+
+       struct sna_mode {
+               drmModeResPtr kmode;
+
+               int shadow_active;
+               DamagePtr shadow_damage;
+               struct kgem_bo *shadow;
+               int shadow_flip;
+
+               struct list outputs;
+               struct list crtcs;
+       } mode;
+
+       struct sna_dri {
+               void *flip_pending;
+       } dri;
+
+       unsigned int tiling;
+#define SNA_TILING_FB          0x1
+#define SNA_TILING_2D          0x2
+#define SNA_TILING_3D          0x4
+#define SNA_TILING_ALL (~0)
+
+       EntityInfoPtr pEnt;
+       struct pci_device *PciInfo;
+       const struct intel_device_info *info;
+
+       ScreenBlockHandlerProcPtr BlockHandler;
+       ScreenWakeupHandlerProcPtr WakeupHandler;
+       CloseScreenProcPtr CloseScreen;
+
+       PicturePtr clear;
+       struct {
+               uint32_t fill_bo;
+               uint32_t fill_pixel;
+               uint32_t fill_alu;
+       } blt_state;
+       union {
+               struct gen2_render_state gen2;
+               struct gen3_render_state gen3;
+               struct gen4_render_state gen4;
+               struct gen5_render_state gen5;
+               struct gen6_render_state gen6;
+               struct gen7_render_state gen7;
+       } render_state;
+       uint32_t have_render;
+
+       bool dri_available;
+       bool dri_open;
+       char *deviceName;
+
+       /* Broken-out options. */
+       OptionInfoPtr Options;
+
+       /* Driver phase/state information */
+       bool suspended;
+
+#if HAVE_UDEV
+       struct udev_monitor *uevent_monitor;
+       InputHandlerProc uevent_handler;
+#endif
+
+       struct kgem kgem;
+       struct sna_render render;
+
+#if DEBUG_MEMORY
+       struct {
+              int shadow_pixels_allocs;
+              int cpu_bo_allocs;
+              size_t shadow_pixels_bytes;
+              size_t cpu_bo_bytes;
+       } debug_memory;
+#endif
+};
+
+bool sna_mode_pre_init(ScrnInfoPtr scrn, struct sna *sna);
+void sna_mode_adjust_frame(struct sna *sna, int x, int y);
+extern void sna_mode_update(struct sna *sna);
+extern void sna_mode_disable_unused(struct sna *sna);
+extern void sna_mode_wakeup(struct sna *sna);
+extern void sna_mode_redisplay(struct sna *sna);
+extern void sna_mode_fini(struct sna *sna);
+
+extern int sna_page_flip(struct sna *sna,
+                        struct kgem_bo *bo,
+                        void *data,
+                        int ref_crtc_hw_id);
+
+constant static inline struct sna *
+to_sna(ScrnInfoPtr scrn)
+{
+       return (struct sna *)(scrn->driverPrivate);
+}
+
+constant static inline struct sna *
+to_sna_from_screen(ScreenPtr screen)
+{
+       return to_sna(xf86ScreenToScrn(screen));
+}
+
+constant static inline struct sna *
+to_sna_from_pixmap(PixmapPtr pixmap)
+{
+       return ((void **)dixGetPrivateAddr(&pixmap->devPrivates, &sna_pixmap_key))[0];
+}
+
+constant static inline struct sna *
+to_sna_from_drawable(DrawablePtr drawable)
+{
+       return to_sna_from_screen(drawable->pScreen);
+}
+
+static inline struct sna *
+to_sna_from_kgem(struct kgem *kgem)
+{
+       return container_of(kgem, struct sna, kgem);
+}
+
+#ifndef ARRAY_SIZE
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
+#endif
+
+#ifndef ALIGN
+#define ALIGN(i,m)     (((i) + (m) - 1) & ~((m) - 1))
+#endif
+
+#ifndef MIN
+#define MIN(a,b)       ((a) <= (b) ? (a) : (b))
+#endif
+
+#ifndef MAX
+#define MAX(a,b)       ((a) >= (b) ? (a) : (b))
+#endif
+
+extern xf86CrtcPtr sna_covering_crtc(ScrnInfoPtr scrn,
+                                    const BoxRec *box,
+                                    xf86CrtcPtr desired);
+
+extern bool sna_wait_for_scanline(struct sna *sna, PixmapPtr pixmap,
+                                 xf86CrtcPtr crtc, const BoxRec *clip);
+
+#if HAVE_DRI2_H
+bool sna_dri_open(struct sna *sna, ScreenPtr pScreen);
+void sna_dri_page_flip_handler(struct sna *sna, struct drm_event_vblank *event);
+void sna_dri_vblank_handler(struct sna *sna, struct drm_event_vblank *event);
+void sna_dri_destroy_window(WindowPtr win);
+void sna_dri_close(struct sna *sna, ScreenPtr pScreen);
+#else
+static inline bool sna_dri_open(struct sna *sna, ScreenPtr pScreen) { return false; }
+static inline void sna_dri_page_flip_handler(struct sna *sna, struct drm_event_vblank *event) { }
+static inline void sna_dri_vblank_handler(struct sna *sna, struct drm_event_vblank *event) { }
+static inline void sna_dri_destroy_window(WindowPtr win) { }
+static inline void sna_dri_close(struct sna *sna, ScreenPtr pScreen) { }
+#endif
+
+extern int sna_crtc_to_pipe(xf86CrtcPtr crtc);
+extern int sna_crtc_to_plane(xf86CrtcPtr crtc);
+extern int sna_crtc_id(xf86CrtcPtr crtc);
+
+CARD32 sna_format_for_depth(int depth);
+CARD32 sna_render_format_for_depth(int depth);
+
+void sna_debug_flush(struct sna *sna);
+
+static inline void
+get_drawable_deltas(DrawablePtr drawable, PixmapPtr pixmap, int16_t *x, int16_t *y)
+{
+#ifdef COMPOSITE
+       if (drawable->type == DRAWABLE_WINDOW) {
+               *x = -pixmap->screen_x;
+               *y = -pixmap->screen_y;
+               return;
+       }
+#endif
+       *x = *y = 0;
+}
+
+static inline int
+get_drawable_dx(DrawablePtr drawable)
+{
+#ifdef COMPOSITE
+       if (drawable->type == DRAWABLE_WINDOW)
+               return -get_drawable_pixmap(drawable)->screen_x;
+#endif
+       return 0;
+}
+
+static inline int
+get_drawable_dy(DrawablePtr drawable)
+{
+#ifdef COMPOSITE
+       if (drawable->type == DRAWABLE_WINDOW)
+               return -get_drawable_pixmap(drawable)->screen_y;
+#endif
+       return 0;
+}
+
+bool sna_pixmap_attach_to_bo(PixmapPtr pixmap, struct kgem_bo *bo);
+static inline bool sna_pixmap_is_scanout(struct sna *sna, PixmapPtr pixmap)
+{
+       return (pixmap == sna->front &&
+               !sna->mode.shadow_active &&
+               (sna->flags & SNA_NO_WAIT) == 0);
+}
+
+PixmapPtr sna_pixmap_create_upload(ScreenPtr screen,
+                                  int width, int height, int depth,
+                                  unsigned flags);
+PixmapPtr sna_pixmap_create_unattached(ScreenPtr screen,
+                                      int width, int height, int depth);
+void sna_pixmap_destroy(PixmapPtr pixmap);
+
+#define MOVE_WRITE 0x1
+#define MOVE_READ 0x2
+#define MOVE_INPLACE_HINT 0x4
+#define MOVE_ASYNC_HINT 0x8
+#define MOVE_SOURCE_HINT 0x10
+#define MOVE_WHOLE_HINT 0x20
+#define __MOVE_FORCE 0x40
+#define __MOVE_DRI 0x80
+
+struct sna_pixmap *sna_pixmap_move_to_gpu(PixmapPtr pixmap, unsigned flags);
+static inline struct sna_pixmap *
+sna_pixmap_force_to_gpu(PixmapPtr pixmap, unsigned flags)
+{
+       /* Unlike move-to-gpu, we ignore wedged and always create the GPU bo */
+       DBG(("%s(pixmap=%p, flags=%x)\n", __FUNCTION__, pixmap, flags));
+       return sna_pixmap_move_to_gpu(pixmap, flags | __MOVE_FORCE);
+}
+bool must_check _sna_pixmap_move_to_cpu(PixmapPtr pixmap, unsigned flags);
+static inline bool must_check sna_pixmap_move_to_cpu(PixmapPtr pixmap, unsigned flags)
+{
+       if (flags == MOVE_READ) {
+               struct sna_pixmap *priv = sna_pixmap(pixmap);
+               if (priv == NULL)
+                       return true;
+       }
+
+       return _sna_pixmap_move_to_cpu(pixmap, flags);
+}
+bool must_check sna_drawable_move_region_to_cpu(DrawablePtr drawable,
+                                               RegionPtr region,
+                                               unsigned flags);
+
+bool must_check sna_drawable_move_to_cpu(DrawablePtr drawable, unsigned flags);
+
+static inline bool must_check
+sna_drawable_move_to_gpu(DrawablePtr drawable, unsigned flags)
+{
+       return sna_pixmap_move_to_gpu(get_drawable_pixmap(drawable), flags) != NULL;
+}
+
+void sna_add_flush_pixmap(struct sna *sna,
+                         struct sna_pixmap *priv,
+                         struct kgem_bo *bo);
+
+struct kgem_bo *sna_pixmap_change_tiling(PixmapPtr pixmap, uint32_t tiling);
+
+#define PREFER_GPU     0x1
+#define FORCE_GPU      0x2
+#define RENDER_GPU     0x4
+#define IGNORE_CPU     0x8
+struct kgem_bo *
+sna_drawable_use_bo(DrawablePtr drawable, unsigned flags, const BoxRec *box,
+                   struct sna_damage ***damage);
+
+static inline bool
+box_inplace(PixmapPtr pixmap, const BoxRec *box)
+{
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+       return ((int)(box->x2 - box->x1) * (int)(box->y2 - box->y1) * pixmap->drawable.bitsPerPixel >> 12) >= sna->kgem.half_cpu_cache_pages;
+}
+
+static inline bool
+region_subsumes_drawable(RegionPtr region, DrawablePtr drawable)
+{
+       const BoxRec *extents;
+
+       if (region->data)
+               return false;
+
+       extents = RegionExtents(region);
+       return  extents->x1 <= 0 && extents->y1 <= 0 &&
+               extents->x2 >= drawable->width &&
+               extents->y2 >= drawable->height;
+}
+
+static inline bool
+region_subsumes_damage(const RegionRec *region, struct sna_damage *damage)
+{
+       const BoxRec *re, *de;
+
+       DBG(("%s?\n", __FUNCTION__));
+       assert(damage);
+
+       re = &region->extents;
+       de = &DAMAGE_PTR(damage)->extents;
+       DBG(("%s: region (%d, %d), (%d, %d), damage (%d, %d), (%d, %d)\n",
+            __FUNCTION__,
+            re->x1, re->y1, re->x2, re->y2,
+            de->x1, de->y1, de->x2, de->y2));
+
+       if (re->x2 < de->x2 || re->x1 > de->x1 ||
+           re->y2 < de->y2 || re->y1 > de->y1) {
+               DBG(("%s: not contained\n", __FUNCTION__));
+               return false;
+       }
+
+       if (region->data == NULL) {
+               DBG(("%s: singular region contains damage\n", __FUNCTION__));
+               return true;
+       }
+
+       return pixman_region_contains_rectangle((RegionPtr)region,
+                                               (BoxPtr)de) == PIXMAN_REGION_IN;
+}
+
+
+static inline bool
+sna_drawable_is_clear(DrawablePtr d)
+{
+       struct sna_pixmap *priv = sna_pixmap(get_drawable_pixmap(d));
+       return priv && priv->clear && priv->clear_color == 0;
+}
+
+static inline struct kgem_bo *sna_pixmap_get_bo(PixmapPtr pixmap)
+{
+       return sna_pixmap(pixmap)->gpu_bo;
+}
+
+static inline struct kgem_bo *sna_pixmap_pin(PixmapPtr pixmap, unsigned flags)
+{
+       struct sna_pixmap *priv;
+
+       priv = sna_pixmap_force_to_gpu(pixmap, MOVE_READ | MOVE_WRITE);
+       if (!priv)
+               return NULL;
+
+       priv->pinned |= flags;
+       return priv->gpu_bo;
+}
+
+
+static inline bool
+_sna_transform_point(const PictTransform *transform,
+                    int64_t x, int64_t y, int64_t result[3])
+{
+       int j;
+
+       for (j = 0; j < 3; j++)
+               result[j] = (transform->matrix[j][0] * x +
+                            transform->matrix[j][1] * y +
+                            transform->matrix[j][2]);
+
+       return result[2] != 0;
+}
+
+static inline void
+_sna_get_transformed_coordinates(int x, int y,
+                                const PictTransform *transform,
+                                float *x_out, float *y_out)
+{
+
+       int64_t result[3];
+
+       _sna_transform_point(transform, x, y, result);
+       *x_out = result[0] / (double)result[2];
+       *y_out = result[1] / (double)result[2];
+}
+
+void
+sna_get_transformed_coordinates(int x, int y,
+                               const PictTransform *transform,
+                               float *x_out, float *y_out);
+
+void
+sna_get_transformed_coordinates_3d(int x, int y,
+                                  const PictTransform *transform,
+                                  float *x_out, float *y_out, float *z_out);
+
+bool sna_transform_is_affine(const PictTransform *t);
+bool sna_transform_is_integer_translation(const PictTransform *t,
+                                         int16_t *tx, int16_t *ty);
+bool sna_transform_is_translation(const PictTransform *t,
+                                 pixman_fixed_t *tx, pixman_fixed_t *ty);
+
+static inline bool
+sna_transform_equal(const PictTransform *a, const PictTransform *b)
+{
+       if (a == b)
+               return true;
+
+       if (a == NULL || b == NULL)
+               return false;
+
+       return memcmp(a, b, sizeof(*a)) == 0;
+}
+
+static inline bool
+sna_picture_alphamap_equal(PicturePtr a, PicturePtr b)
+{
+       if (a->alphaMap != b->alphaMap)
+               return false;
+
+       if (a->alphaMap)
+               return false;
+
+       return (a->alphaOrigin.x == b->alphaOrigin.x &&
+               a->alphaOrigin.y == b->alphaOrigin.y);
+}
+
+static inline bool wedged(struct sna *sna)
+{
+       return unlikely(sna->kgem.wedged);
+}
+
+static inline bool can_render(struct sna *sna)
+{
+       return likely(!sna->kgem.wedged && sna->have_render);
+}
+
+static inline uint32_t pixmap_size(PixmapPtr pixmap)
+{
+       return (pixmap->drawable.height - 1) * pixmap->devKind +
+               pixmap->drawable.width * pixmap->drawable.bitsPerPixel/8;
+}
+
+bool sna_accel_init(ScreenPtr sreen, struct sna *sna);
+void sna_accel_create(struct sna *sna);
+void sna_accel_block_handler(struct sna *sna, struct timeval **tv);
+void sna_accel_wakeup_handler(struct sna *sna);
+void sna_accel_watch_flush(struct sna *sna, int enable);
+void sna_accel_close(struct sna *sna);
+void sna_accel_free(struct sna *sna);
+
+void sna_copy_fbcon(struct sna *sna);
+
+bool sna_composite_create(struct sna *sna);
+void sna_composite_close(struct sna *sna);
+
+void sna_composite(CARD8 op,
+                  PicturePtr src,
+                  PicturePtr mask,
+                  PicturePtr dst,
+                  INT16 src_x,  INT16 src_y,
+                  INT16 mask_x, INT16 mask_y,
+                  INT16 dst_x,  INT16 dst_y,
+                  CARD16 width, CARD16 height);
+void sna_composite_rectangles(CARD8             op,
+                             PicturePtr                 dst,
+                             xRenderColor      *color,
+                             int                        num_rects,
+                             xRectangle                *rects);
+void sna_composite_trapezoids(CARD8 op,
+                             PicturePtr src,
+                             PicturePtr dst,
+                             PictFormatPtr maskFormat,
+                             INT16 xSrc, INT16 ySrc,
+                             int ntrap, xTrapezoid *traps);
+void sna_add_traps(PicturePtr picture, INT16 x, INT16 y, int n, xTrap *t);
+
+void sna_composite_triangles(CARD8 op,
+                            PicturePtr src,
+                            PicturePtr dst,
+                            PictFormatPtr maskFormat,
+                            INT16 xSrc, INT16 ySrc,
+                            int ntri, xTriangle *tri);
+
+void sna_composite_tristrip(CARD8 op,
+                           PicturePtr src,
+                           PicturePtr dst,
+                           PictFormatPtr maskFormat,
+                           INT16 xSrc, INT16 ySrc,
+                           int npoints, xPointFixed *points);
+
+void sna_composite_trifan(CARD8 op,
+                         PicturePtr src,
+                         PicturePtr dst,
+                         PictFormatPtr maskFormat,
+                         INT16 xSrc, INT16 ySrc,
+                         int npoints, xPointFixed *points);
+
+bool sna_gradients_create(struct sna *sna);
+void sna_gradients_close(struct sna *sna);
+
+bool sna_glyphs_create(struct sna *sna);
+void sna_glyphs(CARD8 op,
+               PicturePtr src,
+               PicturePtr dst,
+               PictFormatPtr mask,
+               INT16 xSrc, INT16 ySrc,
+               int nlist,
+               GlyphListPtr list,
+               GlyphPtr *glyphs);
+void sna_glyphs__shared(CARD8 op,
+                       PicturePtr src,
+                       PicturePtr dst,
+                       PictFormatPtr mask,
+                       INT16 src_x, INT16 src_y,
+                       int nlist, GlyphListPtr list, GlyphPtr *glyphs);
+void sna_glyph_unrealize(ScreenPtr screen, GlyphPtr glyph);
+void sna_glyphs_close(struct sna *sna);
+
+void sna_read_boxes(struct sna *sna,
+                   struct kgem_bo *src_bo, int16_t src_dx, int16_t src_dy,
+                   PixmapPtr dst, int16_t dst_dx, int16_t dst_dy,
+                   const BoxRec *box, int n);
+bool sna_write_boxes(struct sna *sna, PixmapPtr dst,
+                    struct kgem_bo *dst_bo, int16_t dst_dx, int16_t dst_dy,
+                    const void *src, int stride, int16_t src_dx, int16_t src_dy,
+                    const BoxRec *box, int n);
+void sna_write_boxes__xor(struct sna *sna, PixmapPtr dst,
+                         struct kgem_bo *dst_bo, int16_t dst_dx, int16_t dst_dy,
+                         const void *src, int stride, int16_t src_dx, int16_t src_dy,
+                         const BoxRec *box, int nbox,
+                         uint32_t and, uint32_t or);
+
+bool sna_replace(struct sna *sna,
+                PixmapPtr pixmap,
+                struct kgem_bo **bo,
+                const void *src, int stride);
+struct kgem_bo *sna_replace__xor(struct sna *sna,
+                                PixmapPtr pixmap,
+                                struct kgem_bo *bo,
+                                const void *src, int stride,
+                                uint32_t and, uint32_t or);
+
+bool
+sna_compute_composite_extents(BoxPtr extents,
+                             PicturePtr src, PicturePtr mask, PicturePtr dst,
+                             INT16 src_x,  INT16 src_y,
+                             INT16 mask_x, INT16 mask_y,
+                             INT16 dst_x,  INT16 dst_y,
+                             CARD16 width, CARD16 height);
+bool
+sna_compute_composite_region(RegionPtr region,
+                            PicturePtr src, PicturePtr mask, PicturePtr dst,
+                            INT16 src_x,  INT16 src_y,
+                            INT16 mask_x, INT16 mask_y,
+                            INT16 dst_x,  INT16 dst_y,
+                            CARD16 width, CARD16 height);
+
+void
+memcpy_blt(const void *src, void *dst, int bpp,
+          int32_t src_stride, int32_t dst_stride,
+          int16_t src_x, int16_t src_y,
+          int16_t dst_x, int16_t dst_y,
+          uint16_t width, uint16_t height);
+void
+memcpy_to_tiled_x(const void *src, void *dst, int bpp, int swizzling,
+                 int32_t src_stride, int32_t dst_stride,
+                 int16_t src_x, int16_t src_y,
+                 int16_t dst_x, int16_t dst_y,
+                 uint16_t width, uint16_t height);
+void
+memmove_box(const void *src, void *dst,
+           int bpp, int32_t stride,
+           const BoxRec *box,
+           int dx, int dy);
+
+void
+memcpy_xor(const void *src, void *dst, int bpp,
+          int32_t src_stride, int32_t dst_stride,
+          int16_t src_x, int16_t src_y,
+          int16_t dst_x, int16_t dst_y,
+          uint16_t width, uint16_t height,
+          uint32_t and, uint32_t or);
+
+#define SNA_CREATE_FB 0x10
+#define SNA_CREATE_SCRATCH 0x11
+
+inline static bool is_power_of_two(unsigned x)
+{
+       return (x & (x-1)) == 0;
+}
+
+inline static bool is_clipped(const RegionRec *r,
+                             const DrawableRec *d)
+{
+       return (r->data ||
+               r->extents.x2 - r->extents.x1 != d->width ||
+               r->extents.y2 - r->extents.y1 != d->height);
+}
+
+#endif /* _SNA_H */
diff --git a/src/sna/sna_accel.c b/src/sna/sna_accel.c
new file mode 100644 (file)
index 0000000..7f64741
--- /dev/null
@@ -0,0 +1,14577 @@
+/*
+ * Copyright (c) 2011 Intel 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.
+ *
+ * Authors:
+ *    Chris Wilson <chris@chris-wilson.co.uk>
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "sna.h"
+#include "sna_reg.h"
+#include "rop.h"
+
+#include <X11/fonts/font.h>
+#include <X11/fonts/fontstruct.h>
+
+#include <dixfontstr.h>
+
+#include <mi.h>
+#include <migc.h>
+#include <miline.h>
+#include <micmap.h>
+#ifdef RENDER
+#include <mipict.h>
+#endif
+#include <shmint.h>
+
+#include <sys/time.h>
+#include <sys/mman.h>
+#include <unistd.h>
+
+#define FORCE_INPLACE 0
+#define FORCE_FALLBACK 0
+#define FORCE_FLUSH 0
+
+#define DEFAULT_TILING I915_TILING_X
+
+#define USE_INPLACE 1
+#define USE_WIDE_SPANS 0 /* -1 force CPU, 1 force GPU */
+#define USE_ZERO_SPANS 1 /* -1 force CPU, 1 force GPU */
+#define USE_INACTIVE 0
+#define USE_CPU_BO 1
+
+#define MIGRATE_ALL 0
+#define DBG_NO_CPU_UPLOAD 0
+#define DBG_NO_CPU_DOWNLOAD 0
+
+#define ACCEL_FILL_SPANS 1
+#define ACCEL_SET_SPANS 1
+#define ACCEL_PUT_IMAGE 1
+#define ACCEL_COPY_AREA 1
+#define ACCEL_COPY_PLANE 1
+#define ACCEL_COPY_WINDOW 1
+#define ACCEL_POLY_POINT 1
+#define ACCEL_POLY_LINE 1
+#define ACCEL_POLY_SEGMENT 1
+#define ACCEL_POLY_RECTANGLE 1
+#define ACCEL_POLY_ARC 1
+#define ACCEL_POLY_FILL_POLYGON 1
+#define ACCEL_POLY_FILL_RECT 1
+#define ACCEL_POLY_FILL_ARC 1
+#define ACCEL_POLY_TEXT8 1
+#define ACCEL_POLY_TEXT16 1
+#define ACCEL_POLY_GLYPH 1
+#define ACCEL_IMAGE_TEXT8 1
+#define ACCEL_IMAGE_TEXT16 1
+#define ACCEL_IMAGE_GLYPH 1
+#define ACCEL_PUSH_PIXELS 1
+
+#define NO_TILE_8x8 0
+#define NO_STIPPLE_8x8 0
+
+#if 0
+static void __sna_fallback_flush(DrawablePtr d)
+{
+       PixmapPtr pixmap = get_drawable_pixmap(d);
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+       struct sna_pixmap *priv;
+       BoxRec box;
+       PixmapPtr tmp;
+       int i, j;
+       char *src, *dst;
+
+       DBG(("%s: uploading CPU damage...\n", __FUNCTION__));
+       priv = sna_pixmap_move_to_gpu(pixmap, MOVE_READ);
+       if (priv == NULL)
+               return;
+
+       DBG(("%s: downloading GPU damage...\n", __FUNCTION__));
+       if (!sna_pixmap_move_to_cpu(pixmap, MOVE_READ))
+               return;
+
+       box.x1 = box.y1 = 0;
+       box.x2 = pixmap->drawable.width;
+       box.y2 = pixmap->drawable.height;
+
+       tmp = sna_pixmap_create_unattached(pixmap->drawable.pScreen,
+                                          pixmap->drawable.width,
+                                          pixmap->drawable.height,
+                                          pixmap->drawable.depth,
+                                          0);
+
+       DBG(("%s: comparing with direct read...\n", __FUNCTION__));
+       sna_read_boxes(sna,
+                      priv->gpu_bo, 0, 0,
+                      tmp, 0, 0,
+                      &box, 1);
+
+       src = pixmap->devPrivate.ptr;
+       dst = tmp->devPrivate.ptr;
+       for (i = 0; i < tmp->drawable.height; i++) {
+               if (memcmp(src, dst, tmp->drawable.width * tmp->drawable.bitsPerPixel >> 3)) {
+                       for (j = 0; src[j] == dst[j]; j++)
+                               ;
+                       ErrorF("mismatch at (%d, %d)\n",
+                              8*j / tmp->drawable.bitsPerPixel, i);
+                       abort();
+               }
+               src += pixmap->devKind;
+               dst += tmp->devKind;
+       }
+       tmp->drawable.pScreen->DestroyPixmap(tmp);
+}
+#define FALLBACK_FLUSH(d) __sna_fallback_flush(d)
+#else
+#define FALLBACK_FLUSH(d)
+#endif
+
+static int sna_font_key;
+
+static const uint8_t copy_ROP[] = {
+       ROP_0,          /* GXclear */
+       ROP_DSa,        /* GXand */
+       ROP_SDna,       /* GXandReverse */
+       ROP_S,          /* GXcopy */
+       ROP_DSna,       /* GXandInverted */
+       ROP_D,          /* GXnoop */
+       ROP_DSx,        /* GXxor */
+       ROP_DSo,        /* GXor */
+       ROP_DSon,       /* GXnor */
+       ROP_DSxn,       /* GXequiv */
+       ROP_Dn,         /* GXinvert */
+       ROP_SDno,       /* GXorReverse */
+       ROP_Sn,         /* GXcopyInverted */
+       ROP_DSno,       /* GXorInverted */
+       ROP_DSan,       /* GXnand */
+       ROP_1           /* GXset */
+};
+static const uint8_t fill_ROP[] = {
+       ROP_0,
+       ROP_DPa,
+       ROP_PDna,
+       ROP_P,
+       ROP_DPna,
+       ROP_D,
+       ROP_DPx,
+       ROP_DPo,
+       ROP_DPon,
+       ROP_PDxn,
+       ROP_Dn,
+       ROP_PDno,
+       ROP_Pn,
+       ROP_DPno,
+       ROP_DPan,
+       ROP_1
+};
+
+static const GCOps sna_gc_ops;
+static const GCOps sna_gc_ops__cpu;
+static GCOps sna_gc_ops__tmp;
+static const GCFuncs sna_gc_funcs;
+static const GCFuncs sna_gc_funcs__cpu;
+
+static inline void region_set(RegionRec *r, const BoxRec *b)
+{
+       r->extents = *b;
+       r->data = NULL;
+}
+
+static inline void region_maybe_clip(RegionRec *r, RegionRec *clip)
+{
+       if (clip->data)
+               RegionIntersect(r, r, clip);
+}
+
+static inline bool region_is_singular(const RegionRec *r)
+{
+       return r->data == NULL;
+}
+
+typedef struct box32 {
+       int32_t x1, y1, x2, y2;
+} Box32Rec;
+
+#define PM_IS_SOLID(_draw, _pm) \
+       (((_pm) & FbFullMask((_draw)->depth)) == FbFullMask((_draw)->depth))
+
+#ifdef DEBUG_PIXMAP
+static void _assert_pixmap_contains_box(PixmapPtr pixmap, const BoxRec *box, const char *function)
+{
+       if (box->x1 < 0 || box->y1 < 0 ||
+           box->x2 > pixmap->drawable.width ||
+           box->y2 > pixmap->drawable.height)
+       {
+               ErrorF("%s: damage box is beyond the pixmap: box=(%d, %d), (%d, %d), pixmap=(%d, %d)\n",
+                      __FUNCTION__,
+                      box->x1, box->y1, box->x2, box->y2,
+                      pixmap->drawable.width,
+                      pixmap->drawable.height);
+               assert(0);
+       }
+}
+
+static void _assert_pixmap_contains_box_with_offset(PixmapPtr pixmap, const BoxRec *box, int dx, int dy, const char *function)
+{
+       BoxRec b = *box;
+       b.x1 += dx; b.x2 += dx;
+       b.y1 += dy; b.y2 += dy;
+       _assert_pixmap_contains_box(pixmap, &b, function);
+}
+
+static void _assert_pixmap_contains_boxes(PixmapPtr pixmap, const BoxRec *box, int n, int dx, int dy, const char *function)
+{
+       BoxRec extents;
+
+       extents = *box;
+       while (--n) {
+               ++box;
+
+               if (box->x1 < extents.x1)
+                       extents.x1 = box->x1;
+               if (box->x2 > extents.x2)
+                       extents.x2 = box->x2;
+
+               if (box->y1 < extents.y1)
+                       extents.y1 = box->y1;
+               if (box->y2 > extents.y2)
+                       extents.y2 = box->y2;
+       }
+       extents.x1 += dx;
+       extents.x2 += dx;
+       extents.y1 += dy;
+       extents.y2 += dy;
+       _assert_pixmap_contains_box(pixmap, &extents, function);
+}
+
+
+static void _assert_pixmap_contains_points(PixmapPtr pixmap, const DDXPointRec *pt, int n, int dx, int dy, const char *function)
+{
+       BoxRec extents;
+
+       extents.x2 = extents.x1 = pt->x;
+       extents.y2 = extents.y1 = pt->y;
+       while (--n) {
+               ++pt;
+
+               if (pt->x < extents.x1)
+                       extents.x1 = pt->x;
+               else if (pt->x > extents.x2)
+                       extents.x2 = pt->x;
+
+               if (pt->y < extents.y1)
+                       extents.y1 = pt->y;
+               else if (pt->y > extents.y2)
+                       extents.y2 = pt->y;
+       }
+       extents.x1 += dx;
+       extents.x2 += dx + 1;
+       extents.y1 += dy;
+       extents.y2 += dy + 1;
+       _assert_pixmap_contains_box(pixmap, &extents, function);
+}
+
+static void _assert_drawable_contains_box(DrawablePtr drawable, const BoxRec *box, const char *function)
+{
+       if (box->x1 < drawable->x ||
+           box->y1 < drawable->y ||
+           box->x2 > drawable->x + drawable->width ||
+           box->y2 > drawable->y + drawable->height)
+       {
+               ErrorF("%s: damage box is beyond the drawable: box=(%d, %d), (%d, %d), drawable=(%d, %d)x(%d, %d)\n",
+                      __FUNCTION__,
+                      box->x1, box->y1, box->x2, box->y2,
+                      drawable->x, drawable->y,
+                      drawable->width, drawable->height);
+               assert(0);
+       }
+}
+
+static void assert_pixmap_damage(PixmapPtr p)
+{
+       struct sna_pixmap *priv;
+       RegionRec reg, cpu, gpu;
+
+       priv = sna_pixmap(p);
+       if (priv == NULL)
+               return;
+
+       if (priv->clear) {
+               assert(DAMAGE_IS_ALL(priv->gpu_damage));
+               assert(priv->cpu_damage == NULL);
+       }
+
+       if (DAMAGE_IS_ALL(priv->gpu_damage) && DAMAGE_IS_ALL(priv->cpu_damage)) {
+               /* special upload buffer */
+               assert(priv->gpu_bo && priv->gpu_bo->proxy);
+               assert(priv->cpu_bo == NULL);
+               return;
+       }
+
+       assert(!DAMAGE_IS_ALL(priv->gpu_damage) || priv->cpu_damage == NULL);
+       assert(!DAMAGE_IS_ALL(priv->cpu_damage) || priv->gpu_damage == NULL);
+
+       /* Avoid reducing damage to minimise interferrence */
+       RegionNull(&reg);
+       RegionNull(&gpu);
+       RegionNull(&cpu);
+
+       if (priv->gpu_damage)
+               _sna_damage_debug_get_region(DAMAGE_PTR(priv->gpu_damage), &gpu);
+
+       if (priv->cpu_damage)
+               _sna_damage_debug_get_region(DAMAGE_PTR(priv->cpu_damage), &cpu);
+
+       RegionIntersect(&reg, &cpu, &gpu);
+       assert(!RegionNotEmpty(&reg));
+
+       RegionUninit(&reg);
+       RegionUninit(&gpu);
+       RegionUninit(&cpu);
+}
+
+#define assert_pixmap_contains_box(p, b) _assert_pixmap_contains_box(p, b, __FUNCTION__)
+#define assert_pixmap_contains_box_with_offset(p, b, dx, dy) _assert_pixmap_contains_box_with_offset(p, b, dx, dy, __FUNCTION__)
+#define assert_drawable_contains_box(d, b) _assert_drawable_contains_box(d, b, __FUNCTION__)
+#define assert_pixmap_contains_boxes(p, b, n, x, y) _assert_pixmap_contains_boxes(p, b, n, x, y, __FUNCTION__)
+#define assert_pixmap_contains_points(p, pt, n, x, y) _assert_pixmap_contains_points(p, pt, n, x, y, __FUNCTION__)
+
+#else
+#define assert_pixmap_contains_box(p, b)
+#define assert_pixmap_contains_box_with_offset(p, b, dx, dy)
+#define assert_pixmap_contains_boxes(p, b, n, x, y)
+#define assert_pixmap_contains_points(p, pt, n, x, y)
+#define assert_drawable_contains_box(d, b)
+#define assert_pixmap_damage(p)
+#endif
+
+inline static bool
+sna_fill_init_blt(struct sna_fill_op *fill,
+                 struct sna *sna,
+                 PixmapPtr pixmap,
+                 struct kgem_bo *bo,
+                 uint8_t alu,
+                 uint32_t pixel)
+{
+       return sna->render.fill(sna, alu, pixmap, bo, pixel, fill);
+}
+
+static bool
+sna_copy_init_blt(struct sna_copy_op *copy,
+                 struct sna *sna,
+                 PixmapPtr src, struct kgem_bo *src_bo,
+                 PixmapPtr dst, struct kgem_bo *dst_bo,
+                 uint8_t alu)
+{
+       memset(copy, 0, sizeof(*copy));
+       return sna->render.copy(sna, alu, src, src_bo, dst, dst_bo, copy);
+}
+
+static void sna_pixmap_free_gpu(struct sna *sna, struct sna_pixmap *priv)
+{
+       sna_damage_destroy(&priv->gpu_damage);
+       priv->clear = false;
+
+       if (priv->gpu_bo && !priv->pinned) {
+               kgem_bo_destroy(&sna->kgem, priv->gpu_bo);
+               priv->gpu_bo = NULL;
+       }
+
+       if (priv->mapped) {
+               assert(!priv->shm);
+               priv->pixmap->devPrivate.ptr = NULL;
+               priv->mapped = false;
+       }
+
+       list_del(&priv->inactive);
+
+       /* and reset the upload counter */
+       priv->source_count = SOURCE_BIAS;
+}
+
+static bool must_check
+sna_pixmap_alloc_cpu(struct sna *sna,
+                    PixmapPtr pixmap,
+                    struct sna_pixmap *priv,
+                    bool from_gpu)
+{
+       /* Restore after a GTT mapping? */
+       assert(!priv->shm);
+       if (priv->ptr)
+               goto done;
+
+       DBG(("%s: pixmap=%ld\n", __FUNCTION__, pixmap->drawable.serialNumber));
+       assert(priv->stride);
+
+       if (priv->create & KGEM_CAN_CREATE_CPU) {
+               DBG(("%s: allocating CPU buffer (%dx%d)\n", __FUNCTION__,
+                    pixmap->drawable.width, pixmap->drawable.height));
+
+               priv->cpu_bo = kgem_create_cpu_2d(&sna->kgem,
+                                                 pixmap->drawable.width,
+                                                 pixmap->drawable.height,
+                                                 pixmap->drawable.bitsPerPixel,
+                                                 from_gpu ? 0 : CREATE_CPU_MAP | CREATE_INACTIVE);
+               if (priv->cpu_bo) {
+                       DBG(("%s: allocated CPU handle=%d (snooped? %d)\n", __FUNCTION__,
+                            priv->cpu_bo->handle, priv->cpu_bo->snoop));
+
+                       priv->ptr = kgem_bo_map__cpu(&sna->kgem, priv->cpu_bo);
+                       priv->stride = priv->cpu_bo->pitch;
+#ifdef DEBUG_MEMORY
+                       sna->debug_memory.cpu_bo_allocs++;
+                       sna->debug_memory.cpu_bo_bytes += kgem_bo_size(priv->cpu_bo);
+#endif
+               }
+       }
+
+       if (priv->ptr == NULL) {
+               DBG(("%s: allocating ordinary memory for shadow pixels [%d bytes]\n",
+                    __FUNCTION__, priv->stride * pixmap->drawable.height));
+               priv->ptr = malloc(priv->stride * pixmap->drawable.height);
+       }
+
+       assert(priv->ptr);
+done:
+       pixmap->devPrivate.ptr = priv->ptr;
+       pixmap->devKind = priv->stride;
+       assert(priv->stride);
+       return priv->ptr != NULL;
+}
+
+static void sna_pixmap_free_cpu(struct sna *sna, struct sna_pixmap *priv)
+{
+       assert(priv->cpu_damage == NULL);
+       assert(list_is_empty(&priv->list));
+
+       if (priv->cpu_bo) {
+               DBG(("%s: discarding CPU buffer, handle=%d, size=%d\n",
+                    __FUNCTION__, priv->cpu_bo->handle, kgem_bo_size(priv->cpu_bo)));
+#ifdef DEBUG_MEMORY
+               sna->debug_memory.cpu_bo_allocs--;
+               sna->debug_memory.cpu_bo_bytes -= kgem_bo_size(priv->cpu_bo);
+#endif
+               if (priv->cpu_bo->flush) {
+                       assert(priv->cpu_bo->reusable == false);
+                       kgem_bo_sync__cpu(&sna->kgem, priv->cpu_bo);
+                       sna_accel_watch_flush(sna, -1);
+               }
+               kgem_bo_destroy(&sna->kgem, priv->cpu_bo);
+               priv->cpu_bo = NULL;
+       } else
+               free(priv->ptr);
+
+       priv->ptr = NULL;
+       if (!priv->mapped)
+               priv->pixmap->devPrivate.ptr = NULL;
+}
+
+static inline uint32_t default_tiling(PixmapPtr pixmap,
+                                     uint32_t tiling)
+{
+       struct sna_pixmap *priv = sna_pixmap(pixmap);
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+
+       /* Try to avoid hitting the Y-tiling GTT mapping bug on 855GM */
+       if (sna->kgem.gen == 21)
+               return I915_TILING_X;
+
+       /* Only on later generations was the render pipeline
+        * more flexible than the BLT. So on gen2/3, prefer to
+        * keep large objects accessible through the BLT.
+        */
+       if (sna->kgem.gen < 40 &&
+           (pixmap->drawable.width  > sna->render.max_3d_size ||
+            pixmap->drawable.height > sna->render.max_3d_size))
+               return I915_TILING_X;
+
+       if (tiling == I915_TILING_Y &&
+           sna_damage_is_all(&priv->cpu_damage,
+                             pixmap->drawable.width,
+                             pixmap->drawable.height)) {
+               DBG(("%s: entire source is damaged, using Y-tiling\n",
+                    __FUNCTION__));
+               sna_damage_destroy(&priv->gpu_damage);
+               priv->undamaged = false;
+
+               return I915_TILING_Y;
+       }
+
+       return tiling;
+}
+
+constant static uint32_t sna_pixmap_choose_tiling(PixmapPtr pixmap,
+                                                 uint32_t tiling)
+{
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+       uint32_t bit;
+
+       /* Use tiling by default, but disable per user request */
+       if (pixmap->usage_hint == SNA_CREATE_FB) {
+               tiling = -I915_TILING_X;
+               bit = SNA_TILING_FB;
+       } else {
+               tiling = default_tiling(pixmap, tiling);
+               bit = SNA_TILING_2D;
+       }
+       if ((sna->tiling && (1 << bit)) == 0)
+               tiling = I915_TILING_NONE;
+
+       /* Also adjust tiling if it is not supported or likely to
+        * slow us down,
+        */
+       return kgem_choose_tiling(&sna->kgem, tiling,
+                                 pixmap->drawable.width,
+                                 pixmap->drawable.height,
+                                 pixmap->drawable.bitsPerPixel);
+}
+
+struct kgem_bo *sna_pixmap_change_tiling(PixmapPtr pixmap, uint32_t tiling)
+{
+       struct sna_pixmap *priv = sna_pixmap(pixmap);
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+       struct kgem_bo *bo;
+       BoxRec box;
+
+       DBG(("%s: changing tiling %d -> %d for %dx%d pixmap\n",
+            __FUNCTION__, priv->gpu_bo->tiling, tiling,
+            pixmap->drawable.width, pixmap->drawable.height));
+
+       if (priv->pinned) {
+               DBG(("%s: can't convert pinned bo\n", __FUNCTION__));
+               return NULL;
+       }
+
+       if (wedged(sna)) {
+               DBG(("%s: can't convert bo, wedged\n", __FUNCTION__));
+               return NULL;
+       }
+
+       assert_pixmap_damage(pixmap);
+
+       bo = kgem_create_2d(&sna->kgem,
+                           pixmap->drawable.width,
+                           pixmap->drawable.height,
+                           pixmap->drawable.bitsPerPixel,
+                           tiling, 0);
+       if (bo == NULL) {
+               DBG(("%s: allocation failed\n", __FUNCTION__));
+               return NULL;
+       }
+
+       box.x1 = box.y1 = 0;
+       box.x2 = pixmap->drawable.width;
+       box.y2 = pixmap->drawable.height;
+
+       if (!sna->render.copy_boxes(sna, GXcopy,
+                                   pixmap, priv->gpu_bo, 0, 0,
+                                   pixmap, bo, 0, 0,
+                                   &box, 1, 0)) {
+               DBG(("%s: copy failed\n", __FUNCTION__));
+               kgem_bo_destroy(&sna->kgem, bo);
+               return NULL;
+       }
+
+       kgem_bo_destroy(&sna->kgem, priv->gpu_bo);
+
+       if (priv->mapped) {
+               assert(!priv->shm);
+               pixmap->devPrivate.ptr = NULL;
+               priv->mapped = false;
+       }
+
+       return priv->gpu_bo = bo;
+}
+
+static inline void sna_set_pixmap(PixmapPtr pixmap, struct sna_pixmap *sna)
+{
+       ((void **)dixGetPrivateAddr(&pixmap->devPrivates, &sna_pixmap_key))[1] = sna;
+       assert(sna_pixmap(pixmap) == sna);
+}
+
+static struct sna_pixmap *
+_sna_pixmap_init(struct sna_pixmap *priv, PixmapPtr pixmap)
+{
+       list_init(&priv->list);
+       list_init(&priv->inactive);
+       priv->source_count = SOURCE_BIAS;
+       priv->pixmap = pixmap;
+
+       return priv;
+}
+
+static struct sna_pixmap *
+_sna_pixmap_reset(PixmapPtr pixmap)
+{
+       struct sna_pixmap *priv;
+
+       assert(pixmap->drawable.type == DRAWABLE_PIXMAP);
+       assert(pixmap->drawable.class == 0);
+       assert(pixmap->drawable.x == 0);
+       assert(pixmap->drawable.y == 0);
+
+       priv = sna_pixmap(pixmap);
+       assert(priv != NULL);
+
+       memset(priv, 0, sizeof(*priv));
+       return _sna_pixmap_init(priv, pixmap);
+}
+
+static struct sna_pixmap *sna_pixmap_attach(PixmapPtr pixmap)
+{
+       struct sna_pixmap *priv;
+
+       priv = calloc(1, sizeof(*priv));
+       if (!priv)
+               return NULL;
+
+       sna_set_pixmap(pixmap, priv);
+       return _sna_pixmap_init(priv, pixmap);
+}
+
+bool sna_pixmap_attach_to_bo(PixmapPtr pixmap, struct kgem_bo *bo)
+{
+       struct sna_pixmap *priv;
+
+       priv = sna_pixmap_attach(pixmap);
+       if (!priv)
+               return false;
+
+       priv->gpu_bo = kgem_bo_reference(bo);
+       sna_damage_all(&priv->gpu_damage,
+                      pixmap->drawable.width,
+                      pixmap->drawable.height);
+
+       return true;
+}
+
+static int bits_per_pixel(int depth)
+{
+       switch (depth) {
+       case 1: return 1;
+       case 4:
+       case 8: return 8;
+       case 15:
+       case 16: return 16;
+       case 24:
+       case 30:
+       case 32: return 32;
+       default: return 0;
+       }
+}
+static PixmapPtr
+create_pixmap(struct sna *sna, ScreenPtr screen,
+             int width, int height, int depth,
+             unsigned usage_hint)
+{
+       PixmapPtr pixmap;
+       size_t datasize;
+       size_t stride;
+       int base, bpp;
+
+       bpp = bits_per_pixel(depth);
+       if (bpp == 0)
+               return NullPixmap;
+
+       stride = ((width * bpp + FB_MASK) >> FB_SHIFT) * sizeof(FbBits);
+       if (stride / 4 > 32767 || height > 32767)
+               return NullPixmap;
+
+       datasize = height * stride;
+       base = screen->totalPixmapSize;
+       if (base & 15) {
+               int adjust = 16 - (base & 15);
+               base += adjust;
+               datasize += adjust;
+       }
+
+       pixmap = AllocatePixmap(screen, datasize);
+       if (!pixmap)
+               return NullPixmap;
+
+       ((void **)dixGetPrivateAddr(&pixmap->devPrivates, &sna_pixmap_key))[0] = sna;
+       assert(to_sna_from_pixmap(pixmap) == sna);
+
+       pixmap->drawable.type = DRAWABLE_PIXMAP;
+       pixmap->drawable.class = 0;
+       pixmap->drawable.pScreen = screen;
+       pixmap->drawable.depth = depth;
+       pixmap->drawable.bitsPerPixel = bpp;
+       pixmap->drawable.id = 0;
+       pixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
+       pixmap->drawable.x = 0;
+       pixmap->drawable.y = 0;
+       pixmap->drawable.width = width;
+       pixmap->drawable.height = height;
+       pixmap->devKind = stride;
+       pixmap->refcnt = 1;
+       pixmap->devPrivate.ptr =  (char *)pixmap + base;
+
+#ifdef COMPOSITE
+       pixmap->screen_x = 0;
+       pixmap->screen_y = 0;
+#endif
+
+       pixmap->usage_hint = usage_hint;
+
+       DBG(("%s: serial=%ld, usage=%d, %dx%d\n",
+            __FUNCTION__,
+            pixmap->drawable.serialNumber,
+            pixmap->usage_hint,
+            pixmap->drawable.width,
+            pixmap->drawable.height));
+
+       return pixmap;
+}
+
+static PixmapPtr
+sna_pixmap_create_shm(ScreenPtr screen,
+                     int width, int height, int depth,
+                     char *addr)
+{
+       struct sna *sna = to_sna_from_screen(screen);
+       int bpp = bits_per_pixel(depth);
+       int pitch = PixmapBytePad(width, depth);
+       struct sna_pixmap *priv;
+       PixmapPtr pixmap;
+
+       DBG(("%s(%dx%d, depth=%d, bpp=%d, pitch=%d)\n",
+            __FUNCTION__, width, height, depth, bpp, pitch));
+
+       if (wedged(sna) || bpp == 0 || pitch*height <= 4096) {
+fallback:
+               pixmap = sna_pixmap_create_unattached(screen, 0, 0, depth);
+               if (pixmap == NULL)
+                       return NULL;
+
+               if (!screen->ModifyPixmapHeader(pixmap, width, height, depth,
+                                               bpp, pitch, addr)) {
+                       screen->DestroyPixmap(pixmap);
+                       return NULL;
+               }
+
+               return pixmap;
+       }
+
+       if (sna->freed_pixmap) {
+               pixmap = sna->freed_pixmap;
+               sna->freed_pixmap = pixmap->devPrivate.ptr;
+
+               pixmap->usage_hint = 0;
+               pixmap->refcnt = 1;
+
+               pixmap->drawable.width = width;
+               pixmap->drawable.height = height;
+               pixmap->drawable.depth = depth;
+               pixmap->drawable.bitsPerPixel = bpp;
+               pixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
+
+               DBG(("%s: serial=%ld, %dx%d\n",
+                    __FUNCTION__,
+                    pixmap->drawable.serialNumber,
+                    pixmap->drawable.width,
+                    pixmap->drawable.height));
+
+               priv = _sna_pixmap_reset(pixmap);
+       } else {
+               pixmap = create_pixmap(sna, screen, 0, 0, depth, 0);
+               if (pixmap == NullPixmap)
+                       return NullPixmap;
+
+               pixmap->drawable.width = width;
+               pixmap->drawable.height = height;
+               pixmap->drawable.depth = depth;
+               pixmap->drawable.bitsPerPixel = bpp;
+
+               priv = sna_pixmap_attach(pixmap);
+               if (!priv) {
+                       FreePixmap(pixmap);
+                       return NullPixmap;
+               }
+       }
+
+       priv->cpu_bo = kgem_create_map(&sna->kgem, addr, pitch*height, false);
+       if (priv->cpu_bo == NULL) {
+               priv->header = true;
+               sna_pixmap_destroy(pixmap);
+               goto fallback;
+       }
+       priv->cpu_bo->flush = true;
+       priv->cpu_bo->pitch = pitch;
+       priv->cpu_bo->reusable = false;
+       sna_accel_watch_flush(sna, 1);
+#ifdef DEBUG_MEMORY
+       sna->debug_memory.cpu_bo_allocs++;
+       sna->debug_memory.cpu_bo_bytes += kgem_bo_size(priv->cpu_bo);
+#endif
+
+       priv->cpu = true;
+       priv->shm = true;
+       sna_damage_all(&priv->cpu_damage, width, height);
+
+       pixmap->devKind = pitch;
+       pixmap->devPrivate.ptr = addr;
+       return pixmap;
+}
+
+PixmapPtr
+sna_pixmap_create_unattached(ScreenPtr screen,
+                            int width, int height, int depth)
+{
+       return create_pixmap(to_sna_from_screen(screen),
+                            screen, width, height, depth,
+                            CREATE_PIXMAP_USAGE_SCRATCH);
+}
+
+static PixmapPtr
+sna_pixmap_create_scratch(ScreenPtr screen,
+                         int width, int height, int depth,
+                         uint32_t tiling)
+{
+       struct sna *sna = to_sna_from_screen(screen);
+       struct sna_pixmap *priv;
+       PixmapPtr pixmap;
+       int bpp;
+
+       DBG(("%s(%d, %d, %d, tiling=%d)\n", __FUNCTION__,
+            width, height, depth, tiling));
+
+       bpp = bits_per_pixel(depth);
+       if (tiling == I915_TILING_Y && !sna->have_render)
+               tiling = I915_TILING_X;
+
+       if (tiling == I915_TILING_Y &&
+           (width > sna->render.max_3d_size ||
+            height > sna->render.max_3d_size))
+               tiling = I915_TILING_X;
+
+       tiling = kgem_choose_tiling(&sna->kgem, tiling, width, height, bpp);
+
+       /* you promise never to access this via the cpu... */
+       if (sna->freed_pixmap) {
+               pixmap = sna->freed_pixmap;
+               sna->freed_pixmap = pixmap->devPrivate.ptr;
+
+               pixmap->usage_hint = CREATE_PIXMAP_USAGE_SCRATCH;
+               pixmap->refcnt = 1;
+
+               pixmap->drawable.width = width;
+               pixmap->drawable.height = height;
+               pixmap->drawable.depth = depth;
+               pixmap->drawable.bitsPerPixel = bpp;
+               pixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
+
+               DBG(("%s: serial=%ld, usage=%d, %dx%d\n",
+                    __FUNCTION__,
+                    pixmap->drawable.serialNumber,
+                    pixmap->usage_hint,
+                    pixmap->drawable.width,
+                    pixmap->drawable.height));
+
+               priv = _sna_pixmap_reset(pixmap);
+       } else {
+               pixmap = create_pixmap(sna, screen, 0, 0, depth,
+                                      CREATE_PIXMAP_USAGE_SCRATCH);
+               if (pixmap == NullPixmap)
+                       return NullPixmap;
+
+               pixmap->drawable.width = width;
+               pixmap->drawable.height = height;
+               pixmap->drawable.depth = depth;
+               pixmap->drawable.bitsPerPixel = bpp;
+
+               priv = sna_pixmap_attach(pixmap);
+               if (!priv) {
+                       FreePixmap(pixmap);
+                       return NullPixmap;
+               }
+       }
+
+       priv->stride = PixmapBytePad(width, depth);
+       pixmap->devPrivate.ptr = NULL;
+
+       priv->gpu_bo = kgem_create_2d(&sna->kgem,
+                                     width, height, bpp, tiling,
+                                     CREATE_TEMPORARY);
+       if (priv->gpu_bo == NULL) {
+               free(priv);
+               FreePixmap(pixmap);
+               return NullPixmap;
+       }
+
+       priv->header = true;
+       sna_damage_all(&priv->gpu_damage, width, height);
+
+       return pixmap;
+}
+
+#ifdef CREATE_PIXMAP_USAGE_SHARED
+static Bool
+sna_share_pixmap_backing(PixmapPtr pixmap, ScreenPtr slave, void **fd_handle)
+{
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+       struct sna_pixmap *priv;
+       int fd;
+
+       DBG(("%s: pixmap=%ld\n", __FUNCTION__, pixmap->drawable.serialNumber));
+
+       priv = sna_pixmap_move_to_gpu(pixmap,
+                                     MOVE_READ | MOVE_WRITE | __MOVE_DRI | __MOVE_FORCE);
+       if (priv == NULL)
+               return FALSE;
+
+       assert(!priv->shm);
+       assert(priv->gpu_bo);
+       assert(priv->stride);
+
+       /* XXX negotiate format and stride restrictions */
+       if (priv->gpu_bo->tiling != I915_TILING_NONE ||
+           priv->gpu_bo->pitch & 255) {
+               struct kgem_bo *bo;
+               BoxRec box;
+
+               DBG(("%s: removing tiling %d, and aligning pitch  for %dx%d pixmap=%ld\n",
+                    __FUNCTION__, priv->gpu_bo->tiling,
+                    pixmap->drawable.width, pixmap->drawable.height,
+                    pixmap->drawable.serialNumber));
+
+               if (priv->pinned & ~(PIN_DRI | PIN_PRIME)) {
+                       DBG(("%s: can't convert pinned bo\n", __FUNCTION__));
+                       return FALSE;
+               }
+
+               assert_pixmap_damage(pixmap);
+
+               bo = kgem_create_2d(&sna->kgem,
+                                   pixmap->drawable.width,
+                                   pixmap->drawable.height,
+                                   pixmap->drawable.bitsPerPixel,
+                                   I915_TILING_NONE,
+                                   CREATE_GTT_MAP | CREATE_PRIME);
+               if (bo == NULL) {
+                       DBG(("%s: allocation failed\n", __FUNCTION__));
+                       return FALSE;
+               }
+
+               box.x1 = box.y1 = 0;
+               box.x2 = pixmap->drawable.width;
+               box.y2 = pixmap->drawable.height;
+
+               assert(!wedged(sna)); /* XXX */
+               if (!sna->render.copy_boxes(sna, GXcopy,
+                                           pixmap, priv->gpu_bo, 0, 0,
+                                           pixmap, bo, 0, 0,
+                                           &box, 1, 0)) {
+                       DBG(("%s: copy failed\n", __FUNCTION__));
+                       kgem_bo_destroy(&sna->kgem, bo);
+                       return FALSE;
+               }
+
+               kgem_bo_destroy(&sna->kgem, priv->gpu_bo);
+               priv->gpu_bo = bo;
+
+               if (priv->mapped) {
+                       pixmap->devPrivate.ptr = NULL;
+                       priv->mapped = false;
+               }
+       }
+       assert(priv->gpu_bo->tiling == I915_TILING_NONE);
+       assert((priv->gpu_bo->pitch & 255) == 0);
+
+       /* And export the bo->pitch via pixmap->devKind */
+       pixmap->devPrivate.ptr = kgem_bo_map__async(&sna->kgem, priv->gpu_bo);
+       if (pixmap->devPrivate.ptr == NULL)
+               return FALSE;
+
+       pixmap->devKind = priv->gpu_bo->pitch;
+       priv->mapped = true;
+
+       fd = kgem_bo_export_to_prime(&sna->kgem, priv->gpu_bo);
+       if (fd == -1)
+               return FALSE;
+
+       priv->pinned |= PIN_PRIME;
+
+       *fd_handle = (void *)(intptr_t)fd;
+       return TRUE;
+}
+
+static Bool
+sna_set_shared_pixmap_backing(PixmapPtr pixmap, void *fd_handle)
+{
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+       struct sna_pixmap *priv;
+       struct kgem_bo *bo;
+
+       DBG(("%s: pixmap=%ld, size=%dx%d, depth=%d/%d, stride=%d\n",
+            __FUNCTION__, pixmap->drawable.serialNumber,
+            pixmap->drawable.width, pixmap->drawable.height,
+            pixmap->drawable.depth, pixmap->drawable.bitsPerPixel,
+            pixmap->devKind));
+
+       priv = sna_pixmap(pixmap);
+       if (priv == NULL)
+               return FALSE;
+
+       assert(!priv->pinned);
+       assert(priv->gpu_bo == NULL);
+       assert(priv->cpu_bo == NULL);
+       assert(priv->cpu_damage == NULL);
+       assert(priv->gpu_damage == NULL);
+
+       bo = kgem_create_for_prime(&sna->kgem,
+                                  (intptr_t)fd_handle,
+                                  pixmap->devKind * pixmap->drawable.height);
+       if (bo == NULL)
+               return FALSE;
+
+       sna_damage_all(&priv->gpu_damage,
+                      pixmap->drawable.width,
+                      pixmap->drawable.height);
+
+       bo->pitch = pixmap->devKind;
+       priv->stride = pixmap->devKind;
+
+       priv->gpu_bo = bo;
+       priv->pinned |= PIN_PRIME;
+
+       close((intptr_t)fd_handle);
+       return TRUE;
+}
+
+static PixmapPtr
+sna_create_pixmap_shared(struct sna *sna, ScreenPtr screen,
+                        int width, int height, int depth)
+{
+       PixmapPtr pixmap;
+       struct sna_pixmap *priv;
+
+       DBG(("%s: depth=%d\n", __FUNCTION__, depth));
+
+       /* Create a stub to be attached later */
+       pixmap = create_pixmap(sna, screen, 0, 0, depth, 0);
+       if (pixmap == NullPixmap)
+               return NullPixmap;
+
+       pixmap->devKind = 0;
+       pixmap->devPrivate.ptr = NULL;
+
+       priv = sna_pixmap_attach(pixmap);
+       if (priv == NULL) {
+               free(pixmap);
+               return NullPixmap;
+       }
+
+       priv->stride = 0;
+       priv->create = 0;
+
+       if (width|height) {
+               int bpp = bits_per_pixel(depth);
+
+               priv->gpu_bo = kgem_create_2d(&sna->kgem,
+                                             width, height, bpp,
+                                             I915_TILING_NONE,
+                                             CREATE_GTT_MAP | CREATE_PRIME);
+               if (priv->gpu_bo == NULL) {
+                       free(priv);
+                       FreePixmap(pixmap);
+                       return NullPixmap;
+               }
+
+               /* minimal interface for sharing is linear, 256 byte pitch */
+               assert(priv->gpu_bo->tiling == I915_TILING_NONE);
+               assert((priv->gpu_bo->pitch & 255) == 0);
+
+               pixmap->devPrivate.ptr =
+                       kgem_bo_map__async(&sna->kgem, priv->gpu_bo);
+               if (pixmap->devPrivate.ptr == NULL) {
+                       free(priv);
+                       FreePixmap(pixmap);
+                       return FALSE;
+               }
+
+               pixmap->devKind = priv->gpu_bo->pitch;
+               pixmap->drawable.width = width;
+               pixmap->drawable.height = height;
+
+               priv->stride = priv->gpu_bo->pitch;
+               priv->mapped = true;
+
+               sna_damage_all(&priv->gpu_damage, width, height);
+       }
+
+       return pixmap;
+}
+#endif
+
+static PixmapPtr sna_create_pixmap(ScreenPtr screen,
+                                  int width, int height, int depth,
+                                  unsigned int usage)
+{
+       struct sna *sna = to_sna_from_screen(screen);
+       PixmapPtr pixmap;
+       unsigned flags;
+       int pad;
+
+       DBG(("%s(%d, %d, %d, usage=%x)\n", __FUNCTION__,
+            width, height, depth, usage));
+
+#ifdef CREATE_PIXMAP_USAGE_SHARED
+       if (usage == CREATE_PIXMAP_USAGE_SHARED)
+               return sna_create_pixmap_shared(sna, screen,
+                                               width, height, depth);
+#endif
+
+       if ((width|height) == 0) {
+               usage = -1;
+               goto fallback;
+       }
+       assert(width && height);
+
+       flags = kgem_can_create_2d(&sna->kgem, width, height, depth);
+       if (flags == 0) {
+               DBG(("%s: can not use GPU, just creating shadow\n",
+                    __FUNCTION__));
+               goto fallback;
+       }
+
+       if (!can_render(sna))
+               flags = 0;
+
+       if (usage == CREATE_PIXMAP_USAGE_SCRATCH) {
+               if (flags & KGEM_CAN_CREATE_GPU)
+                       return sna_pixmap_create_scratch(screen,
+                                                        width, height, depth,
+                                                        I915_TILING_X);
+               else
+                       goto fallback;
+       }
+
+       if (usage == SNA_CREATE_SCRATCH) {
+               if (flags & KGEM_CAN_CREATE_GPU)
+                       return sna_pixmap_create_scratch(screen,
+                                                        width, height, depth,
+                                                        I915_TILING_Y);
+               else
+                       goto fallback;
+       }
+
+       if (usage == CREATE_PIXMAP_USAGE_GLYPH_PICTURE)
+               flags &= ~KGEM_CAN_CREATE_GPU;
+       if (usage == CREATE_PIXMAP_USAGE_BACKING_PIXMAP)
+               usage = 0;
+
+       pad = PixmapBytePad(width, depth);
+       if (pad * height <= 4096) {
+               DBG(("%s: small buffer [%d], attaching to shadow pixmap\n",
+                    __FUNCTION__, pad * height));
+               pixmap = create_pixmap(sna, screen,
+                                      width, height, depth, usage);
+               if (pixmap == NullPixmap)
+                       return NullPixmap;
+
+               sna_pixmap_attach(pixmap);
+       } else {
+               struct sna_pixmap *priv;
+
+               DBG(("%s: creating GPU pixmap %dx%d, stride=%d, flags=%x\n",
+                    __FUNCTION__, width, height, pad, flags));
+
+               pixmap = create_pixmap(sna, screen, 0, 0, depth, usage);
+               if (pixmap == NullPixmap)
+                       return NullPixmap;
+
+               pixmap->drawable.width = width;
+               pixmap->drawable.height = height;
+               pixmap->devKind = pad;
+               pixmap->devPrivate.ptr = NULL;
+
+               priv = sna_pixmap_attach(pixmap);
+               if (priv == NULL) {
+                       free(pixmap);
+                       goto fallback;
+               }
+
+               priv->stride = pad;
+               priv->create = flags;
+       }
+
+       return pixmap;
+
+fallback:
+       return create_pixmap(sna, screen, width, height, depth, usage);
+}
+
+void sna_add_flush_pixmap(struct sna *sna,
+                         struct sna_pixmap *priv,
+                         struct kgem_bo *bo)
+{
+       DBG(("%s: marking pixmap=%ld for flushing\n",
+            __FUNCTION__, priv->pixmap->drawable.serialNumber));
+       assert(bo);
+       list_move(&priv->list, &sna->flush_pixmaps);
+
+       if (bo->exec == NULL) {
+               DBG(("%s: new flush bo, flushin before\n", __FUNCTION__));
+               kgem_submit(&sna->kgem);
+       }
+}
+
+static void __sna_free_pixmap(struct sna *sna,
+                             PixmapPtr pixmap,
+                             struct sna_pixmap *priv)
+{
+       list_del(&priv->list);
+       list_del(&priv->inactive);
+
+       sna_damage_destroy(&priv->gpu_damage);
+       sna_damage_destroy(&priv->cpu_damage);
+
+       sna_pixmap_free_cpu(sna, priv);
+
+       if (priv->header) {
+               assert(!priv->shm);
+               pixmap->devPrivate.ptr = sna->freed_pixmap;
+               sna->freed_pixmap = pixmap;
+       } else {
+               free(priv);
+               FreePixmap(pixmap);
+       }
+}
+
+static Bool sna_destroy_pixmap(PixmapPtr pixmap)
+{
+       struct sna *sna;
+       struct sna_pixmap *priv;
+
+       if (--pixmap->refcnt)
+               return TRUE;
+
+       priv = sna_pixmap(pixmap);
+       DBG(("%s: pixmap=%ld, attached?=%d\n",
+            __FUNCTION__, pixmap->drawable.serialNumber, priv != NULL));
+       if (priv == NULL) {
+               FreePixmap(pixmap);
+               return TRUE;
+       }
+
+       assert_pixmap_damage(pixmap);
+       sna = to_sna_from_pixmap(pixmap);
+
+       /* Always release the gpu bo back to the lower levels of caching */
+       if (priv->gpu_bo) {
+               kgem_bo_destroy(&sna->kgem, priv->gpu_bo);
+               priv->gpu_bo = NULL;
+       }
+
+       if (priv->shm && kgem_bo_is_busy(priv->cpu_bo)) {
+               sna_add_flush_pixmap(sna, priv, priv->cpu_bo);
+               kgem_bo_submit(&sna->kgem, priv->cpu_bo); /* XXX ShmDetach */
+       } else
+               __sna_free_pixmap(sna, pixmap, priv);
+       return TRUE;
+}
+
+void sna_pixmap_destroy(PixmapPtr pixmap)
+{
+       assert(pixmap->refcnt == 1);
+       assert(sna_pixmap(pixmap) == NULL || sna_pixmap(pixmap)->header == true);
+
+       sna_destroy_pixmap(pixmap);
+}
+
+static inline bool pixmap_inplace(struct sna *sna,
+                                 PixmapPtr pixmap,
+                                 struct sna_pixmap *priv)
+{
+       if (FORCE_INPLACE)
+               return FORCE_INPLACE > 0;
+
+       if (wedged(sna) && !priv->pinned)
+               return false;
+
+       if (priv->mapped)
+               return true;
+
+       return (pixmap->devKind * pixmap->drawable.height >> 12) >
+               sna->kgem.half_cpu_cache_pages;
+}
+
+static bool
+sna_pixmap_create_mappable_gpu(PixmapPtr pixmap)
+{
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+       struct sna_pixmap *priv = sna_pixmap(pixmap);;
+
+       if (wedged(sna))
+               return false;
+
+       assert_pixmap_damage(pixmap);
+
+       assert(priv->gpu_bo == NULL);
+       priv->gpu_bo =
+               kgem_create_2d(&sna->kgem,
+                              pixmap->drawable.width,
+                              pixmap->drawable.height,
+                              pixmap->drawable.bitsPerPixel,
+                              sna_pixmap_choose_tiling(pixmap, DEFAULT_TILING),
+                              CREATE_GTT_MAP | CREATE_INACTIVE);
+
+       return priv->gpu_bo && kgem_bo_is_mappable(&sna->kgem, priv->gpu_bo);
+}
+
+static inline bool use_cpu_bo_for_download(struct sna *sna,
+                                          struct sna_pixmap *priv,
+                                          const BoxRec *box)
+{
+       if (DBG_NO_CPU_DOWNLOAD)
+               return false;
+
+       if (wedged(sna))
+               return false;
+
+       if (priv->cpu_bo == NULL || !sna->kgem.can_blt_cpu)
+               return false;
+
+       if (kgem_bo_is_busy(priv->gpu_bo) || kgem_bo_is_busy(priv->cpu_bo)) {
+               DBG(("%s: yes, either bo is busy, so use GPU for readback\n",
+                    __FUNCTION__));
+               return true;
+       }
+
+       /* Is it worth detiling? */
+       if (kgem_bo_is_mappable(&sna->kgem, priv->gpu_bo) &&
+           (box->y2 - box->y1 - 1) * priv->gpu_bo->pitch < 4096) {
+               DBG(("%s: no, tiny transfer, expect to read inplace\n",
+                    __FUNCTION__));
+               return false;
+       }
+
+       DBG(("%s: yes, default action\n", __FUNCTION__));
+       return true;
+}
+
+static inline bool use_cpu_bo_for_upload(struct sna_pixmap *priv,
+                                        unsigned flags)
+{
+       if (DBG_NO_CPU_UPLOAD)
+               return false;
+
+       if (priv->cpu_bo == NULL)
+               return false;
+
+       DBG(("%s? flags=%x, gpu busy?=%d, cpu busy?=%d\n", __FUNCTION__,
+            flags,
+            kgem_bo_is_busy(priv->gpu_bo),
+            kgem_bo_is_busy(priv->cpu_bo)));
+
+       if (flags & (MOVE_WRITE | MOVE_ASYNC_HINT))
+               return true;
+
+       return kgem_bo_is_busy(priv->gpu_bo) || kgem_bo_is_busy(priv->cpu_bo);
+}
+
+static inline bool operate_inplace(struct sna_pixmap *priv, unsigned flags)
+{
+       if ((flags & MOVE_INPLACE_HINT) == 0 || priv->gpu_bo == NULL)
+               return false;
+
+       if (flags & MOVE_WRITE && kgem_bo_is_busy(priv->gpu_bo))
+               return false;
+
+       return priv->stride != 0;
+}
+
+bool
+_sna_pixmap_move_to_cpu(PixmapPtr pixmap, unsigned int flags)
+{
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+       struct sna_pixmap *priv;
+
+       DBG(("%s(pixmap=%ld, %dx%d, flags=%x)\n", __FUNCTION__,
+            pixmap->drawable.serialNumber,
+            pixmap->drawable.width,
+            pixmap->drawable.height,
+            flags));
+
+       assert_pixmap_damage(pixmap);
+
+       priv = sna_pixmap(pixmap);
+       if (priv == NULL) {
+               DBG(("%s: not attached\n", __FUNCTION__));
+               return true;
+       }
+
+       DBG(("%s: gpu_bo=%d, gpu_damage=%p, cpu_damage=%p, is-clear?=%d\n",
+            __FUNCTION__,
+            priv->gpu_bo ? priv->gpu_bo->handle : 0,
+            priv->gpu_damage, priv->cpu_damage, priv->clear));
+
+       if (USE_INPLACE && (flags & MOVE_READ) == 0) {
+               assert(flags & MOVE_WRITE);
+               DBG(("%s: no readbck, discarding gpu damage [%d], pending clear[%d]\n",
+                    __FUNCTION__, priv->gpu_damage != NULL, priv->clear));
+
+               if (priv->create & KGEM_CAN_CREATE_GPU &&
+                   pixmap_inplace(sna, pixmap, priv)) {
+                       assert(!priv->shm);
+                       DBG(("%s: write inplace\n", __FUNCTION__));
+                       if (priv->gpu_bo) {
+                               if (__kgem_bo_is_busy(&sna->kgem,
+                                                     priv->gpu_bo)) {
+                                       if (priv->pinned)
+                                               goto skip_inplace_map;
+
+                                       DBG(("%s: discard busy GPU bo\n", __FUNCTION__));
+                                       sna_pixmap_free_gpu(sna, priv);
+                               }
+                       }
+                       if (priv->gpu_bo == NULL &&
+                           !sna_pixmap_create_mappable_gpu(pixmap))
+                               goto skip_inplace_map;
+
+                       if (!priv->mapped) {
+                               pixmap->devPrivate.ptr =
+                                       kgem_bo_map(&sna->kgem, priv->gpu_bo);
+                               if (pixmap->devPrivate.ptr == NULL)
+                                       goto skip_inplace_map;
+
+                               priv->mapped = true;
+                       }
+                       pixmap->devKind = priv->gpu_bo->pitch;
+
+                       sna_damage_all(&priv->gpu_damage,
+                                      pixmap->drawable.width,
+                                      pixmap->drawable.height);
+                       sna_damage_destroy(&priv->cpu_damage);
+                       priv->undamaged = false;
+                       priv->clear = false;
+                       priv->cpu = false;
+                       list_del(&priv->list);
+                       if (priv->cpu_bo) {
+                               assert(!priv->shm);
+                               assert(!priv->cpu_bo->flush);
+                               sna_pixmap_free_cpu(sna, priv);
+                       }
+
+                       assert_pixmap_damage(pixmap);
+                       return true;
+               }
+
+skip_inplace_map:
+               sna_damage_destroy(&priv->gpu_damage);
+               if (priv->cpu_bo && !priv->cpu_bo->flush &&
+                   __kgem_bo_is_busy(&sna->kgem, priv->cpu_bo)) {
+                       DBG(("%s: discarding busy CPU bo\n", __FUNCTION__));
+                       assert(!priv->shm);
+                       assert(priv->gpu_bo == NULL || priv->gpu_damage == NULL);
+
+                       sna_damage_destroy(&priv->cpu_damage);
+                       priv->undamaged = false;
+
+                       sna_pixmap_free_gpu(sna, priv);
+                       sna_pixmap_free_cpu(sna, priv);
+               }
+       }
+
+       if (DAMAGE_IS_ALL(priv->cpu_damage)) {
+               DBG(("%s: CPU all-damaged\n", __FUNCTION__));
+               goto done;
+       }
+
+       assert(priv->gpu_bo == NULL || priv->gpu_bo->proxy == NULL);
+
+       if (operate_inplace(priv, flags) &&
+           pixmap_inplace(sna, pixmap, priv) &&
+           sna_pixmap_move_to_gpu(pixmap, flags)) {
+               kgem_bo_submit(&sna->kgem, priv->gpu_bo);
+
+               DBG(("%s: try to operate inplace\n", __FUNCTION__));
+               assert(priv->cpu == false);
+
+               pixmap->devPrivate.ptr =
+                       kgem_bo_map(&sna->kgem, priv->gpu_bo);
+               if (pixmap->devPrivate.ptr != NULL) {
+                       priv->mapped = true;
+                       pixmap->devKind = priv->gpu_bo->pitch;
+                       if (flags & MOVE_WRITE) {
+                               sna_damage_all(&priv->gpu_damage,
+                                              pixmap->drawable.width,
+                                              pixmap->drawable.height);
+                               sna_damage_destroy(&priv->cpu_damage);
+                               list_del(&priv->list);
+                               priv->undamaged = false;
+                               priv->clear = false;
+                       }
+
+                       assert_pixmap_damage(pixmap);
+                       DBG(("%s: operate inplace\n", __FUNCTION__));
+                       return true;
+               }
+
+               priv->mapped = false;
+       }
+
+       if (priv->mapped) {
+               assert(!priv->shm);
+               pixmap->devPrivate.ptr = NULL;
+               priv->mapped = false;
+       }
+
+       if (priv->clear && priv->cpu_bo && !priv->cpu_bo->flush &&
+           __kgem_bo_is_busy(&sna->kgem, priv->cpu_bo)) {
+               assert(!priv->shm);
+               assert(DAMAGE_IS_ALL(priv->gpu_damage));
+               sna_pixmap_free_cpu(sna, priv);
+       }
+
+       if (pixmap->devPrivate.ptr == NULL &&
+           !sna_pixmap_alloc_cpu(sna, pixmap, priv, priv->gpu_damage != NULL))
+               return false;
+
+       if (priv->clear) {
+               DBG(("%s: applying clear [%08x]\n",
+                    __FUNCTION__, priv->clear_color));
+
+               if (priv->cpu_bo) {
+                       DBG(("%s: syncing CPU bo\n", __FUNCTION__));
+                       kgem_bo_sync__cpu(&sna->kgem, priv->cpu_bo);
+               }
+
+               if (priv->clear_color == 0 || pixmap->drawable.bitsPerPixel == 8) {
+                       memset(pixmap->devPrivate.ptr, priv->clear_color,
+                              pixmap->devKind * pixmap->drawable.height);
+               } else {
+                       pixman_fill(pixmap->devPrivate.ptr,
+                                   pixmap->devKind/sizeof(uint32_t),
+                                   pixmap->drawable.bitsPerPixel,
+                                   0, 0,
+                                   pixmap->drawable.width,
+                                   pixmap->drawable.height,
+                                   priv->clear_color);
+               }
+
+               sna_damage_all(&priv->cpu_damage,
+                              pixmap->drawable.width,
+                              pixmap->drawable.height);
+               sna_pixmap_free_gpu(sna, priv);
+               priv->undamaged = false;
+               priv->clear = false;
+       }
+
+       if (priv->gpu_damage) {
+               BoxPtr box;
+               int n;
+
+               DBG(("%s: flushing GPU damage\n", __FUNCTION__));
+
+               n = sna_damage_get_boxes(priv->gpu_damage, &box);
+               if (n) {
+                       bool ok = false;
+
+                       if (use_cpu_bo_for_download(sna, priv, &priv->gpu_damage->extents)) {
+                               DBG(("%s: using CPU bo for download from GPU\n", __FUNCTION__));
+                               ok = sna->render.copy_boxes(sna, GXcopy,
+                                                           pixmap, priv->gpu_bo, 0, 0,
+                                                           pixmap, priv->cpu_bo, 0, 0,
+                                                           box, n, COPY_LAST);
+                       }
+                       if (!ok)
+                               sna_read_boxes(sna,
+                                              priv->gpu_bo, 0, 0,
+                                              pixmap, 0, 0,
+                                              box, n);
+               }
+
+               __sna_damage_destroy(DAMAGE_PTR(priv->gpu_damage));
+               priv->gpu_damage = NULL;
+               priv->undamaged = true;
+       }
+
+       if (flags & MOVE_WRITE || priv->create & KGEM_CAN_CREATE_LARGE) {
+               DBG(("%s: marking as damaged\n", __FUNCTION__));
+               sna_damage_all(&priv->cpu_damage,
+                              pixmap->drawable.width,
+                              pixmap->drawable.height);
+               sna_pixmap_free_gpu(sna, priv);
+               priv->undamaged = false;
+
+               if (priv->flush) {
+                       assert(!priv->shm);
+                       sna_add_flush_pixmap(sna, priv, priv->gpu_bo);
+               }
+       }
+
+done:
+       if (flags & MOVE_WRITE) {
+               priv->source_count = SOURCE_BIAS;
+               assert(priv->gpu_bo == NULL || priv->gpu_bo->proxy == NULL);
+               if (priv->gpu_bo && priv->gpu_bo->domain != DOMAIN_GPU) {
+                       DBG(("%s: discarding inactive GPU bo\n", __FUNCTION__));
+                       assert(DAMAGE_IS_ALL(priv->cpu_damage));
+                       sna_pixmap_free_gpu(sna, priv);
+                       priv->undamaged = false;
+               }
+       }
+
+       if (priv->cpu_bo) {
+               if ((flags & MOVE_ASYNC_HINT) == 0) {
+                       DBG(("%s: syncing CPU bo\n", __FUNCTION__));
+                       kgem_bo_sync__cpu(&sna->kgem, priv->cpu_bo);
+               }
+               if (flags & MOVE_WRITE) {
+                       DBG(("%s: discarding GPU bo in favour of CPU bo\n", __FUNCTION__));
+                       sna_pixmap_free_gpu(sna, priv);
+                       priv->undamaged = false;
+               }
+       }
+       priv->cpu = (flags & MOVE_ASYNC_HINT) == 0;
+       assert(pixmap->devPrivate.ptr);
+       assert(pixmap->devKind);
+       assert_pixmap_damage(pixmap);
+       return true;
+}
+
+static bool
+region_overlaps_damage(const RegionRec *region,
+                      struct sna_damage *damage,
+                      int dx, int dy)
+{
+       const BoxRec *re, *de;
+
+       DBG(("%s?\n", __FUNCTION__));
+
+       if (damage == NULL)
+               return false;
+
+       if (DAMAGE_IS_ALL(damage))
+               return true;
+
+       re = &region->extents;
+       de = &DAMAGE_PTR(damage)->extents;
+       DBG(("%s: region (%d, %d), (%d, %d), damage (%d, %d), (%d, %d)\n",
+            __FUNCTION__,
+            re->x1, re->y1, re->x2, re->y2,
+            de->x1, de->y1, de->x2, de->y2));
+
+       return (re->x1 + dx < de->x2 && re->x2 + dx > de->x1 &&
+               re->y1 + dy < de->y2 && re->y2 + dy > de->y1);
+}
+
+#ifndef NDEBUG
+static bool
+pixmap_contains_damage(PixmapPtr pixmap, struct sna_damage *damage)
+{
+       if (damage == NULL)
+               return true;
+
+       damage = DAMAGE_PTR(damage);
+       return (damage->extents.x2 <= pixmap->drawable.width &&
+               damage->extents.y2 <= pixmap->drawable.height &&
+               damage->extents.x1 >= 0 &&
+               damage->extents.y1 >= 0);
+}
+#endif
+
+static inline bool region_inplace(struct sna *sna,
+                                 PixmapPtr pixmap,
+                                 RegionPtr region,
+                                 struct sna_pixmap *priv,
+                                 bool write_only)
+{
+       assert_pixmap_damage(pixmap);
+
+       if (FORCE_INPLACE)
+               return FORCE_INPLACE > 0;
+
+       if (wedged(sna) && !priv->pinned)
+               return false;
+
+       if (priv->cpu) {
+               DBG(("%s: no, preferring last action of CPU\n", __FUNCTION__));
+               return false;
+       }
+
+       if (!write_only &&
+           region_overlaps_damage(region, priv->cpu_damage, 0, 0)) {
+               DBG(("%s: no, uncovered CPU damage pending\n", __FUNCTION__));
+               return false;
+       }
+
+       if (priv->flush) {
+               DBG(("%s: yes, exported via dri, will flush\n", __FUNCTION__));
+               return true;
+       }
+
+       if (priv->mapped) {
+               DBG(("%s: yes, already mapped, continuiung\n", __FUNCTION__));
+               return true;
+       }
+
+       if (DAMAGE_IS_ALL(priv->gpu_damage)) {
+               DBG(("%s: yes, already wholly damaged on the GPU\n", __FUNCTION__));
+               return true;
+       }
+
+       DBG(("%s: (%dx%d), inplace? %d\n",
+            __FUNCTION__,
+            region->extents.x2 - region->extents.x1,
+            region->extents.y2 - region->extents.y1,
+            ((int)(region->extents.x2 - region->extents.x1) *
+             (int)(region->extents.y2 - region->extents.y1) *
+             pixmap->drawable.bitsPerPixel >> 12)
+            >= sna->kgem.half_cpu_cache_pages));
+       return ((int)(region->extents.x2 - region->extents.x1) *
+               (int)(region->extents.y2 - region->extents.y1) *
+               pixmap->drawable.bitsPerPixel >> 12)
+               >= sna->kgem.half_cpu_cache_pages;
+}
+
+bool
+sna_drawable_move_region_to_cpu(DrawablePtr drawable,
+                               RegionPtr region,
+                               unsigned flags)
+{
+       PixmapPtr pixmap = get_drawable_pixmap(drawable);
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+       struct sna_pixmap *priv;
+       int16_t dx, dy;
+
+       DBG(("%s(pixmap=%ld (%dx%d), [(%d, %d), (%d, %d)], flags=%d)\n",
+            __FUNCTION__, pixmap->drawable.serialNumber,
+            pixmap->drawable.width, pixmap->drawable.height,
+            RegionExtents(region)->x1, RegionExtents(region)->y1,
+            RegionExtents(region)->x2, RegionExtents(region)->y2,
+            flags));
+
+       assert_pixmap_damage(pixmap);
+       if (flags & MOVE_WRITE) {
+               assert_drawable_contains_box(drawable, &region->extents);
+       }
+
+       priv = sna_pixmap(pixmap);
+       if (priv == NULL) {
+               DBG(("%s: not attached to %p\n", __FUNCTION__, pixmap));
+               return true;
+       }
+
+       if (sna_damage_is_all(&priv->cpu_damage,
+                             pixmap->drawable.width,
+                             pixmap->drawable.height)) {
+               DBG(("%s: pixmap=%ld all damaged on CPU\n",
+                    __FUNCTION__, pixmap->drawable.serialNumber));
+
+               sna_damage_destroy(&priv->gpu_damage);
+               priv->undamaged = false;
+
+               if (flags & MOVE_WRITE)
+                       sna_pixmap_free_gpu(sna, priv);
+
+               if (pixmap->devPrivate.ptr == NULL &&
+                   !sna_pixmap_alloc_cpu(sna, pixmap, priv, false))
+                       return false;
+
+               goto out;
+       }
+
+       if (flags & MOVE_WHOLE_HINT)
+               return _sna_pixmap_move_to_cpu(pixmap, flags);
+
+       if (priv->gpu_bo == NULL &&
+           (priv->create & KGEM_CAN_CREATE_GPU) == 0 &&
+           flags & MOVE_WRITE)
+               return _sna_pixmap_move_to_cpu(pixmap, flags);
+
+       get_drawable_deltas(drawable, pixmap, &dx, &dy);
+       DBG(("%s: delta=(%d, %d)\n", __FUNCTION__, dx, dy));
+       if (dx | dy)
+               RegionTranslate(region, dx, dy);
+
+       if (region_subsumes_drawable(region, &pixmap->drawable)) {
+               DBG(("%s: region subsumes drawable\n", __FUNCTION__));
+               if (dx | dy)
+                       RegionTranslate(region, -dx, -dy);
+               return _sna_pixmap_move_to_cpu(pixmap, flags);
+       }
+
+       if (USE_INPLACE && (flags & MOVE_READ) == 0) {
+               DBG(("%s: no read, checking to see if we can stream the write into the GPU bo\n",
+                    __FUNCTION__));
+               assert(flags & MOVE_WRITE);
+
+               if (priv->stride && priv->gpu_bo &&
+                   region_inplace(sna, pixmap, region, priv, true)) {
+                       assert(priv->gpu_bo->proxy == NULL);
+                       if (!__kgem_bo_is_busy(&sna->kgem, priv->gpu_bo)) {
+                               pixmap->devPrivate.ptr =
+                                       kgem_bo_map(&sna->kgem, priv->gpu_bo);
+                               if (pixmap->devPrivate.ptr == NULL) {
+                                       if (dx | dy)
+                                               RegionTranslate(region, -dx, -dy);
+                                       return false;
+                               }
+
+                               priv->mapped = true;
+                               pixmap->devKind = priv->gpu_bo->pitch;
+
+                               sna_damage_subtract(&priv->cpu_damage, region);
+                               if (priv->cpu_damage == NULL) {
+                                       list_del(&priv->list);
+                                       sna_damage_all(&priv->gpu_damage,
+                                                      pixmap->drawable.width,
+                                                      pixmap->drawable.height);
+                                       priv->undamaged = false;
+                               } else
+                                       sna_damage_add(&priv->gpu_damage,
+                                                      region);
+
+                               priv->clear = false;
+                               priv->cpu = false;
+                               assert_pixmap_damage(pixmap);
+                               if (dx | dy)
+                                       RegionTranslate(region, -dx, -dy);
+                               return true;
+                       }
+               }
+
+               if (priv->cpu_bo && !priv->cpu_bo->flush) {
+                       if (__kgem_bo_is_busy(&sna->kgem, priv->cpu_bo)) {
+                               sna_damage_subtract(&priv->cpu_damage, region);
+                               if (!sna_pixmap_move_to_gpu(pixmap, MOVE_WRITE)) {
+                                       if (dx | dy)
+                                               RegionTranslate(region, -dx, -dy);
+                                       return false;
+                               }
+
+                               assert(!priv->shm);
+                               sna_pixmap_free_cpu(sna, priv);
+                       }
+               }
+
+               if (priv->gpu_bo == NULL && priv->stride &&
+                   sna_pixmap_choose_tiling(pixmap, DEFAULT_TILING) != I915_TILING_NONE &&
+                   region_inplace(sna, pixmap, region, priv, true) &&
+                   sna_pixmap_create_mappable_gpu(pixmap)) {
+                       pixmap->devPrivate.ptr =
+                               kgem_bo_map(&sna->kgem, priv->gpu_bo);
+                       if (pixmap->devPrivate.ptr == NULL) {
+                               if (dx | dy)
+                                       RegionTranslate(region, -dx, -dy);
+                               return false;
+                       }
+
+                       priv->mapped = true;
+                       pixmap->devKind = priv->gpu_bo->pitch;
+
+                       sna_damage_subtract(&priv->cpu_damage, region);
+                       if (priv->cpu_damage == NULL) {
+                               list_del(&priv->list);
+                               sna_damage_all(&priv->gpu_damage,
+                                              pixmap->drawable.width,
+                                              pixmap->drawable.height);
+                               priv->undamaged = false;
+                       } else
+                               sna_damage_add(&priv->gpu_damage, region);
+
+                       assert_pixmap_damage(pixmap);
+                       priv->clear = false;
+                       priv->cpu = false;
+                       if (dx | dy)
+                               RegionTranslate(region, -dx, -dy);
+                       return true;
+               }
+       }
+
+       if (operate_inplace(priv, flags) &&
+           region_inplace(sna, pixmap, region, priv, (flags & MOVE_READ) == 0)) {
+               kgem_bo_submit(&sna->kgem, priv->gpu_bo);
+
+               DBG(("%s: try to operate inplace\n", __FUNCTION__));
+
+               pixmap->devPrivate.ptr =
+                       kgem_bo_map(&sna->kgem, priv->gpu_bo);
+               if (pixmap->devPrivate.ptr != NULL) {
+                       priv->mapped = true;
+                       pixmap->devKind = priv->gpu_bo->pitch;
+                       if (flags & MOVE_WRITE &&
+                           !DAMAGE_IS_ALL(priv->gpu_damage)) {
+                               sna_damage_add(&priv->gpu_damage, region);
+                               if (sna_damage_is_all(&priv->gpu_damage,
+                                                     pixmap->drawable.width,
+                                                     pixmap->drawable.height)) {
+                                       DBG(("%s: replaced entire pixmap, destroying CPU shadow\n",
+                                            __FUNCTION__));
+                                       sna_damage_destroy(&priv->cpu_damage);
+                                       priv->undamaged = false;
+                                       list_del(&priv->list);
+                               } else
+                                       sna_damage_subtract(&priv->cpu_damage,
+                                                           region);
+                       }
+                       assert_pixmap_damage(pixmap);
+                       priv->clear = false;
+                       priv->cpu = false;
+                       if (dx | dy)
+                               RegionTranslate(region, -dx, -dy);
+                       DBG(("%s: operate inplace\n", __FUNCTION__));
+                       return true;
+               }
+
+               priv->mapped = false;
+       }
+
+       if (priv->clear && flags & MOVE_WRITE) {
+               DBG(("%s: pending clear, moving whole pixmap for partial write\n", __FUNCTION__));
+               if (dx | dy)
+                       RegionTranslate(region, -dx, -dy);
+               return _sna_pixmap_move_to_cpu(pixmap, flags | MOVE_READ);
+       }
+
+       if (priv->mapped) {
+               assert(!priv->shm);
+               pixmap->devPrivate.ptr = NULL;
+               priv->mapped = false;
+       }
+
+       if (pixmap->devPrivate.ptr == NULL &&
+           !sna_pixmap_alloc_cpu(sna, pixmap, priv, priv->gpu_damage != NULL)) {
+               if (dx | dy)
+                       RegionTranslate(region, -dx, -dy);
+               return false;
+       }
+
+       if (priv->gpu_bo == NULL) {
+               assert(priv->gpu_damage == NULL);
+               goto done;
+       }
+
+       assert(priv->gpu_bo->proxy == NULL);
+       if (priv->clear) {
+               int n = REGION_NUM_RECTS(region);
+               BoxPtr box = REGION_RECTS(region);
+
+               DBG(("%s: pending clear, doing partial fill\n", __FUNCTION__));
+               if (priv->cpu_bo) {
+                       DBG(("%s: syncing CPU bo\n", __FUNCTION__));
+                       kgem_bo_sync__cpu(&sna->kgem, priv->cpu_bo);
+               }
+
+               do {
+                       pixman_fill(pixmap->devPrivate.ptr,
+                                   pixmap->devKind/sizeof(uint32_t),
+                                   pixmap->drawable.bitsPerPixel,
+                                   box->x1, box->y1,
+                                   box->x2 - box->x1,
+                                   box->y2 - box->y1,
+                                   priv->clear_color);
+                       box++;
+               } while (--n);
+
+               if (region->extents.x2 - region->extents.x1 > 1 ||
+                   region->extents.y2 - region->extents.y1 > 1) {
+                       sna_damage_subtract(&priv->gpu_damage, region);
+                       priv->clear = false;
+               }
+               goto done;
+       }
+
+       if ((flags & MOVE_READ) == 0) {
+               assert(flags & MOVE_WRITE);
+               sna_damage_subtract(&priv->gpu_damage, region);
+               goto done;
+       }
+
+       if (MIGRATE_ALL && priv->gpu_damage) {
+               BoxPtr box;
+               int n = sna_damage_get_boxes(priv->gpu_damage, &box);
+               if (n) {
+                       bool ok;
+
+                       DBG(("%s: forced migration\n", __FUNCTION__));
+
+                       assert(pixmap_contains_damage(pixmap, priv->gpu_damage));
+
+                       ok = false;
+                       if (use_cpu_bo_for_download(sna, priv, &priv->gpu_damage->extents)) {
+                               DBG(("%s: using CPU bo for download from GPU\n", __FUNCTION__));
+                               ok = sna->render.copy_boxes(sna, GXcopy,
+                                                           pixmap, priv->gpu_bo, 0, 0,
+                                                           pixmap, priv->cpu_bo, 0, 0,
+                                                           box, n, COPY_LAST);
+                       }
+                       if (!ok)
+                               sna_read_boxes(sna,
+                                              priv->gpu_bo, 0, 0,
+                                              pixmap, 0, 0,
+                                              box, n);
+               }
+               sna_damage_destroy(&priv->gpu_damage);
+               priv->undamaged = true;
+       }
+
+       if (priv->gpu_damage &&
+           (DAMAGE_IS_ALL(priv->gpu_damage) ||
+            sna_damage_overlaps_box(priv->gpu_damage, &region->extents))) {
+               DBG(("%s: region (%dx%d) overlaps gpu damage\n",
+                    __FUNCTION__,
+                    region->extents.x2 - region->extents.x1,
+                    region->extents.y2 - region->extents.y1));
+
+               if (priv->cpu_damage == NULL) {
+                       if ((flags & MOVE_WRITE) == 0 &&
+                           region->extents.x2 - region->extents.x1 == 1 &&
+                           region->extents.y2 - region->extents.y1 == 1) {
+                               /*  Often associated with synchronisation, KISS */
+                               DBG(("%s: single pixel read\n", __FUNCTION__));
+                               sna_read_boxes(sna,
+                                              priv->gpu_bo, 0, 0,
+                                              pixmap, 0, 0,
+                                              &region->extents, 1);
+                               goto done;
+                       }
+               } else {
+                       if (sna_damage_contains_box__no_reduce(priv->cpu_damage,
+                                                              &region->extents)) {
+                               DBG(("%s: region already in CPU damage\n",
+                                    __FUNCTION__));
+                               goto done;
+                       }
+               }
+
+               if (sna_damage_contains_box(priv->gpu_damage,
+                                           &region->extents) != PIXMAN_REGION_OUT) {
+                       RegionRec want, *r = region;
+
+                       DBG(("%s: region (%dx%d) intersects gpu damage\n",
+                            __FUNCTION__,
+                            region->extents.x2 - region->extents.x1,
+                            region->extents.y2 - region->extents.y1));
+
+                       if ((flags & MOVE_WRITE) == 0 &&
+                           region->extents.x2 - region->extents.x1 == 1 &&
+                           region->extents.y2 - region->extents.y1 == 1) {
+                               sna_read_boxes(sna,
+                                              priv->gpu_bo, 0, 0,
+                                              pixmap, 0, 0,
+                                              &region->extents, 1);
+                               goto done;
+                       }
+
+                       /* Expand the region to move 32x32 pixel blocks at a
+                        * time, as we assume that we will continue writing
+                        * afterwards and so aim to coallesce subsequent
+                        * reads.
+                        */
+                       if (flags & MOVE_WRITE) {
+                               int n = REGION_NUM_RECTS(region), i;
+                               BoxPtr boxes = REGION_RECTS(region);
+                               BoxPtr blocks = malloc(sizeof(BoxRec) * REGION_NUM_RECTS(region));
+                               if (blocks) {
+                                       for (i = 0; i < n; i++) {
+                                               blocks[i].x1 = boxes[i].x1 & ~31;
+                                               if (blocks[i].x1 < 0)
+                                                       blocks[i].x1 = 0;
+
+                                               blocks[i].x2 = (boxes[i].x2 + 31) & ~31;
+                                               if (blocks[i].x2 > pixmap->drawable.width)
+                                                       blocks[i].x2 = pixmap->drawable.width;
+
+                                               blocks[i].y1 = boxes[i].y1 & ~31;
+                                               if (blocks[i].y1 < 0)
+                                                       blocks[i].y1 = 0;
+
+                                               blocks[i].y2 = (boxes[i].y2 + 31) & ~31;
+                                               if (blocks[i].y2 > pixmap->drawable.height)
+                                                       blocks[i].y2 = pixmap->drawable.height;
+                                       }
+                                       if (pixman_region_init_rects(&want, blocks, i))
+                                               r = &want;
+                                       free(blocks);
+                               }
+                       }
+
+                       if (region_subsumes_damage(r, priv->gpu_damage)) {
+                               BoxPtr box;
+                               int n;
+
+                               DBG(("%s: region wholly contains damage\n",
+                                    __FUNCTION__));
+
+                               n = sna_damage_get_boxes(priv->gpu_damage,
+                                                        &box);
+                               if (n) {
+                                       bool ok = false;
+
+                                       if (use_cpu_bo_for_download(sna, priv, &priv->gpu_damage->extents)) {
+                                               DBG(("%s: using CPU bo for download from GPU\n", __FUNCTION__));
+                                               ok = sna->render.copy_boxes(sna, GXcopy,
+                                                                           pixmap, priv->gpu_bo, 0, 0,
+                                                                           pixmap, priv->cpu_bo, 0, 0,
+                                                                           box, n, COPY_LAST);
+                                       }
+
+                                       if (!ok)
+                                               sna_read_boxes(sna,
+                                                              priv->gpu_bo, 0, 0,
+                                                              pixmap, 0, 0,
+                                                              box, n);
+                               }
+
+                               sna_damage_destroy(&priv->gpu_damage);
+                               priv->undamaged = true;
+                       } else if (DAMAGE_IS_ALL(priv->gpu_damage) ||
+                                  sna_damage_contains_box__no_reduce(priv->gpu_damage,
+                                                                     &r->extents)) {
+                               BoxPtr box = REGION_RECTS(r);
+                               int n = REGION_NUM_RECTS(r);
+                               bool ok = false;
+
+                               DBG(("%s: region wholly inside damage\n",
+                                    __FUNCTION__));
+
+                               if (use_cpu_bo_for_download(sna, priv, &r->extents)) {
+                                       DBG(("%s: using CPU bo for download from GPU\n", __FUNCTION__));
+                                       ok = sna->render.copy_boxes(sna, GXcopy,
+                                                                   pixmap, priv->gpu_bo, 0, 0,
+                                                                   pixmap, priv->cpu_bo, 0, 0,
+                                                                   box, n, COPY_LAST);
+                               }
+                               if (!ok)
+                                       sna_read_boxes(sna,
+                                                      priv->gpu_bo, 0, 0,
+                                                      pixmap, 0, 0,
+                                                      box, n);
+
+                               sna_damage_subtract(&priv->gpu_damage, r);
+                               priv->undamaged = true;
+                       } else {
+                               RegionRec need;
+
+                               pixman_region_init(&need);
+                               if (sna_damage_intersect(priv->gpu_damage, r, &need)) {
+                                       BoxPtr box = REGION_RECTS(&need);
+                                       int n = REGION_NUM_RECTS(&need);
+                                       bool ok = false;
+
+                                       DBG(("%s: region intersects damage\n",
+                                            __FUNCTION__));
+
+                                       if (use_cpu_bo_for_download(sna, priv, &need.extents)) {
+                                               DBG(("%s: using CPU bo for download from GPU\n", __FUNCTION__));
+                                               ok = sna->render.copy_boxes(sna, GXcopy,
+                                                                           pixmap, priv->gpu_bo, 0, 0,
+                                                                           pixmap, priv->cpu_bo, 0, 0,
+                                                                           box, n, COPY_LAST);
+                                       }
+                                       if (!ok)
+                                               sna_read_boxes(sna,
+                                                              priv->gpu_bo, 0, 0,
+                                                              pixmap, 0, 0,
+                                                              box, n);
+
+                                       sna_damage_subtract(&priv->gpu_damage, r);
+                                       priv->undamaged = true;
+                                       RegionUninit(&need);
+                               }
+                       }
+                       if (r == &want)
+                               pixman_region_fini(&want);
+               }
+       }
+
+done:
+       if (flags & MOVE_WRITE) {
+               DBG(("%s: applying cpu damage\n", __FUNCTION__));
+               assert(!DAMAGE_IS_ALL(priv->cpu_damage));
+               assert_pixmap_contains_box(pixmap, RegionExtents(region));
+               sna_damage_add(&priv->cpu_damage, region);
+               sna_damage_reduce_all(&priv->cpu_damage,
+                                     pixmap->drawable.width,
+                                     pixmap->drawable.height);
+               if (DAMAGE_IS_ALL(priv->cpu_damage)) {
+                       if (priv->gpu_bo) {
+                               DBG(("%s: replaced entire pixmap\n",
+                                    __FUNCTION__));
+                               sna_pixmap_free_gpu(sna, priv);
+                       }
+                       priv->undamaged = false;
+               }
+               if (priv->flush) {
+                       assert(!priv->shm);
+                       sna_add_flush_pixmap(sna, priv, priv->gpu_bo);
+               }
+       }
+
+       if (dx | dy)
+               RegionTranslate(region, -dx, -dy);
+
+out:
+       if (flags & MOVE_WRITE) {
+               priv->source_count = SOURCE_BIAS;
+               assert(priv->gpu_bo == NULL || priv->gpu_bo->proxy == NULL);
+               assert(!priv->flush || !list_is_empty(&priv->list));
+       }
+       if ((flags & MOVE_ASYNC_HINT) == 0 && priv->cpu_bo) {
+               DBG(("%s: syncing cpu bo\n", __FUNCTION__));
+               kgem_bo_sync__cpu(&sna->kgem, priv->cpu_bo);
+       }
+       priv->cpu = (flags & MOVE_ASYNC_HINT) == 0;
+       assert(pixmap->devPrivate.ptr);
+       assert(pixmap->devKind);
+       assert_pixmap_damage(pixmap);
+       return true;
+}
+
+static inline bool box_empty(const BoxRec *box)
+{
+       return box->x2 <= box->x1 || box->y2 <= box->y1;
+}
+
+bool
+sna_drawable_move_to_cpu(DrawablePtr drawable, unsigned flags)
+{
+       RegionRec region;
+       PixmapPtr pixmap;
+       int16_t dx, dy;
+
+       if (drawable->type == DRAWABLE_PIXMAP)
+               return sna_pixmap_move_to_cpu((PixmapPtr)drawable, flags);
+
+       pixmap = get_window_pixmap((WindowPtr)drawable);
+       get_drawable_deltas(drawable, pixmap, &dx, &dy);
+
+       DBG(("%s: (%d, %d)x(%d, %d) + (%d, %d), flags=%x\n",
+            __FUNCTION__,
+            drawable->x, drawable->y,
+            drawable->width, drawable->height,
+            dx, dy, flags));
+
+       region.extents.x1 = drawable->x + dx;
+       region.extents.y1 = drawable->y + dy;
+       region.extents.x2 = region.extents.x1 + drawable->width;
+       region.extents.y2 = region.extents.y1 + drawable->height;
+       region.data = NULL;
+
+       if (region.extents.x1 < 0)
+               region.extents.x1 = 0;
+       if (region.extents.y1 < 0)
+               region.extents.y1 = 0;
+       if (region.extents.x2 > pixmap->drawable.width)
+               region.extents.x2 = pixmap->drawable.width;
+       if (region.extents.y2 > pixmap->drawable.height)
+               region.extents.y2 = pixmap->drawable.height;
+
+       if (box_empty(&region.extents))
+               return true;
+
+       return sna_drawable_move_region_to_cpu(&pixmap->drawable, &region, flags);
+}
+
+static bool alu_overwrites(uint8_t alu)
+{
+       switch (alu) {
+       case GXclear:
+       case GXcopy:
+       case GXcopyInverted:
+       case GXset:
+               return true;
+       default:
+               return false;
+       }
+}
+
+inline static bool drawable_gc_inplace_hint(DrawablePtr draw, GCPtr gc)
+{
+       if (!alu_overwrites(gc->alu))
+               return false;
+
+       if (!PM_IS_SOLID(draw, gc->planemask))
+               return false;
+
+       if (gc->fillStyle == FillStippled)
+               return false;
+
+       return true;
+}
+
+inline static unsigned
+drawable_gc_flags(DrawablePtr draw, GCPtr gc, bool partial)
+{
+       assert(sna_gc(gc)->changes == 0);
+
+       if (gc->fillStyle == FillStippled) {
+               DBG(("%s: read due to fill %d\n",
+                    __FUNCTION__, gc->fillStyle));
+               return MOVE_READ | MOVE_WRITE;
+       }
+
+       if (fb_gc(gc)->and) {
+               DBG(("%s: read due to rrop %d:%x\n",
+                    __FUNCTION__, gc->alu, (unsigned)fb_gc(gc)->and));
+               return MOVE_READ | MOVE_WRITE;
+       }
+
+       DBG(("%s: try operating on drawable inplace [hint? %d]\n",
+            __FUNCTION__, drawable_gc_inplace_hint(draw, gc)));
+
+       return (partial ? MOVE_READ : 0) | MOVE_WRITE | MOVE_INPLACE_HINT;
+}
+
+static inline struct sna_pixmap *
+sna_pixmap_mark_active(struct sna *sna, struct sna_pixmap *priv)
+{
+       assert(priv->gpu_bo);
+       if (USE_INACTIVE &&
+           !priv->pinned && priv->gpu_bo->proxy == NULL &&
+           (priv->create & KGEM_CAN_CREATE_LARGE) == 0)
+               list_move(&priv->inactive, &sna->active_pixmaps);
+       priv->cpu = false;
+       return priv;
+}
+
+static bool
+sna_pixmap_move_area_to_gpu(PixmapPtr pixmap, const BoxRec *box, unsigned int flags)
+{
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+       struct sna_pixmap *priv = sna_pixmap(pixmap);
+       RegionRec i, r;
+
+       DBG(("%s()\n", __FUNCTION__));
+
+       assert_pixmap_damage(pixmap);
+       assert_pixmap_contains_box(pixmap, box);
+       assert(!wedged(sna));
+
+       if (sna_damage_is_all(&priv->gpu_damage,
+                             pixmap->drawable.width,
+                             pixmap->drawable.height)) {
+               sna_damage_destroy(&priv->cpu_damage);
+               priv->undamaged = false;
+               list_del(&priv->list);
+               goto done;
+       }
+
+       if ((flags & MOVE_READ) == 0)
+               sna_damage_subtract_box(&priv->cpu_damage, box);
+
+       sna_damage_reduce(&priv->cpu_damage);
+       assert_pixmap_damage(pixmap);
+
+       if (priv->cpu_damage == NULL) {
+               priv->undamaged = false;
+               list_del(&priv->list);
+               return sna_pixmap_move_to_gpu(pixmap, flags);
+       }
+
+       if (priv->gpu_bo == NULL) {
+               unsigned create, tiling;
+
+               create = CREATE_INACTIVE;
+               if (pixmap->usage_hint == SNA_CREATE_FB)
+                       create |= CREATE_EXACT | CREATE_SCANOUT;
+
+               tiling = (flags & MOVE_SOURCE_HINT) ? I915_TILING_Y : DEFAULT_TILING;
+               tiling = sna_pixmap_choose_tiling(pixmap, tiling);
+
+               priv->gpu_bo = kgem_create_2d(&sna->kgem,
+                                             pixmap->drawable.width,
+                                             pixmap->drawable.height,
+                                             pixmap->drawable.bitsPerPixel,
+                                             tiling, create);
+               if (priv->gpu_bo == NULL)
+                       return false;
+
+               DBG(("%s: created gpu bo\n", __FUNCTION__));
+       }
+       assert(priv->gpu_bo->proxy == NULL);
+
+       if (priv->mapped) {
+               assert(!priv->shm);
+               pixmap->devPrivate.ptr = NULL;
+               priv->mapped = false;
+       }
+       if (pixmap->devPrivate.ptr == NULL) {
+               assert(priv->stride);
+               pixmap->devPrivate.ptr = priv->ptr;
+               pixmap->devKind = priv->stride;
+       }
+       assert(pixmap->devPrivate.ptr != NULL);
+
+       region_set(&r, box);
+       if (MIGRATE_ALL || region_subsumes_damage(&r, priv->cpu_damage)) {
+               int n;
+
+               n = sna_damage_get_boxes(priv->cpu_damage, (BoxPtr *)&box);
+               if (n) {
+                       bool ok = false;
+
+                       if (use_cpu_bo_for_upload(priv, 0)) {
+                               DBG(("%s: using CPU bo for upload to GPU\n", __FUNCTION__));
+                               ok = sna->render.copy_boxes(sna, GXcopy,
+                                                           pixmap, priv->cpu_bo, 0, 0,
+                                                           pixmap, priv->gpu_bo, 0, 0,
+                                                           box, n, 0);
+                               if (ok && priv->shm) {
+                                       assert(!priv->flush);
+                                       sna_add_flush_pixmap(sna, priv, priv->cpu_bo);
+                               }
+                       }
+                       if (!ok) {
+                               if (pixmap->devPrivate.ptr == NULL) {
+                                       assert(priv->stride && priv->ptr);
+                                       pixmap->devPrivate.ptr = priv->ptr;
+                                       pixmap->devKind = priv->stride;
+                               }
+                               if (n == 1 && !priv->pinned &&
+                                   box->x1 <= 0 && box->y1 <= 0 &&
+                                   box->x2 >= pixmap->drawable.width &&
+                                   box->y2 >= pixmap->drawable.height) {
+                                       ok = sna_replace(sna, pixmap,
+                                                        &priv->gpu_bo,
+                                                        pixmap->devPrivate.ptr,
+                                                        pixmap->devKind);
+                               } else {
+                                       ok = sna_write_boxes(sna, pixmap,
+                                                            priv->gpu_bo, 0, 0,
+                                                            pixmap->devPrivate.ptr,
+                                                            pixmap->devKind,
+                                                            0, 0,
+                                                            box, n);
+                               }
+                               if (!ok)
+                                       return false;
+                       }
+               }
+
+               sna_damage_destroy(&priv->cpu_damage);
+               list_del(&priv->list);
+               priv->undamaged = true;
+       } else if (DAMAGE_IS_ALL(priv->cpu_damage) ||
+                  sna_damage_contains_box__no_reduce(priv->cpu_damage, box)) {
+               bool ok = false;
+               if (use_cpu_bo_for_upload(priv, 0)) {
+                       DBG(("%s: using CPU bo for upload to GPU\n", __FUNCTION__));
+                       ok = sna->render.copy_boxes(sna, GXcopy,
+                                                   pixmap, priv->cpu_bo, 0, 0,
+                                                   pixmap, priv->gpu_bo, 0, 0,
+                                                   box, 1, 0);
+                       if (ok && priv->shm) {
+                               assert(!priv->flush);
+                               sna_add_flush_pixmap(sna, priv, priv->cpu_bo);
+                       }
+               }
+               if (!ok) {
+                       if (pixmap->devPrivate.ptr == NULL) {
+                               assert(priv->stride && priv->ptr);
+                               pixmap->devPrivate.ptr = priv->ptr;
+                               pixmap->devKind = priv->stride;
+                       }
+                       ok = sna_write_boxes(sna, pixmap,
+                                            priv->gpu_bo, 0, 0,
+                                            pixmap->devPrivate.ptr,
+                                            pixmap->devKind,
+                                            0, 0,
+                                            box, 1);
+               }
+               if (!ok)
+                       return false;
+
+               sna_damage_subtract(&priv->cpu_damage, &r);
+               priv->undamaged = true;
+       } else if (sna_damage_intersect(priv->cpu_damage, &r, &i)) {
+               int n = REGION_NUM_RECTS(&i);
+               bool ok;
+
+               box = REGION_RECTS(&i);
+               ok = false;
+               if (use_cpu_bo_for_upload(priv, 0)) {
+                       DBG(("%s: using CPU bo for upload to GPU\n", __FUNCTION__));
+                       ok = sna->render.copy_boxes(sna, GXcopy,
+                                                   pixmap, priv->cpu_bo, 0, 0,
+                                                   pixmap, priv->gpu_bo, 0, 0,
+                                                   box, n, 0);
+                       if (ok && priv->shm) {
+                               assert(!priv->flush);
+                               sna_add_flush_pixmap(sna, priv, priv->cpu_bo);
+                       }
+               }
+               if (!ok) {
+                       if (pixmap->devPrivate.ptr == NULL) {
+                               assert(priv->stride && priv->ptr);
+                               pixmap->devPrivate.ptr = priv->ptr;
+                               pixmap->devKind = priv->stride;
+                       }
+                       ok = sna_write_boxes(sna, pixmap,
+                                            priv->gpu_bo, 0, 0,
+                                            pixmap->devPrivate.ptr,
+                                            pixmap->devKind,
+                                            0, 0,
+                                            box, n);
+               }
+               if (!ok)
+                       return false;
+
+               sna_damage_subtract(&priv->cpu_damage, &r);
+               priv->undamaged = true;
+               RegionUninit(&i);
+       }
+
+       if (priv->shm) {
+               assert(!priv->flush);
+               sna_add_flush_pixmap(sna, priv, priv->cpu_bo);
+       }
+
+done:
+       if (flags & MOVE_WRITE) {
+               priv->clear = false;
+               if (priv->cpu_damage == NULL && box_inplace(pixmap, box)) {
+                       DBG(("%s: large operation on undamaged, promoting to full GPU\n",
+                            __FUNCTION__));
+                       sna_damage_all(&priv->gpu_damage,
+                                      pixmap->drawable.width,
+                                      pixmap->drawable.height);
+                       priv->undamaged = false;
+               }
+       }
+
+       assert(!priv->gpu_bo->proxy || (flags & MOVE_WRITE) == 0);
+       return sna_pixmap_mark_active(sna, priv) != NULL;
+}
+
+struct kgem_bo *
+sna_drawable_use_bo(DrawablePtr drawable, unsigned flags, const BoxRec *box,
+                   struct sna_damage ***damage)
+{
+       PixmapPtr pixmap = get_drawable_pixmap(drawable);
+       struct sna_pixmap *priv = sna_pixmap(pixmap);
+       struct sna *sna;
+       RegionRec region;
+       int16_t dx, dy;
+       int ret;
+
+       DBG(("%s pixmap=%ld, box=((%d, %d), (%d, %d)), flags=%x...\n",
+            __FUNCTION__,
+            pixmap->drawable.serialNumber,
+            box->x1, box->y1, box->x2, box->y2,
+            flags));
+
+       assert_pixmap_damage(pixmap);
+       assert_drawable_contains_box(drawable, box);
+
+       if (priv == NULL) {
+               DBG(("%s: not attached\n", __FUNCTION__));
+               return NULL;
+       }
+
+       if (priv->gpu_bo && priv->gpu_bo->proxy) {
+               DBG(("%s: cached upload proxy, discard and revert to GPU\n",
+                    __FUNCTION__));
+               assert(priv->gpu_damage == NULL);
+               kgem_bo_destroy(&to_sna_from_pixmap(pixmap)->kgem,
+                               priv->gpu_bo);
+               priv->gpu_bo = NULL;
+               goto use_cpu_bo;
+       }
+
+       if (priv->flush)
+               flags |= PREFER_GPU;
+       if (priv->shm)
+               flags &= ~PREFER_GPU;
+       if (priv->cpu && (flags & FORCE_GPU) == 0)
+               flags &= ~PREFER_GPU;
+
+       DBG(("%s: flush=%d, shm=%d, cpu=%d => flags=%x\n",
+            __FUNCTION__, priv->flush, priv->shm, priv->cpu, flags));
+
+       if ((flags & PREFER_GPU) == 0 &&
+           (!priv->gpu_damage || !kgem_bo_is_busy(priv->gpu_bo))) {
+               DBG(("%s: try cpu as GPU bo is idle\n", __FUNCTION__));
+               goto use_cpu_bo;
+       }
+
+       if (DAMAGE_IS_ALL(priv->gpu_damage)) {
+               DBG(("%s: use GPU fast path (all-damaged)\n", __FUNCTION__));
+               assert(priv->cpu_damage == NULL);
+               goto use_gpu_bo;
+       }
+
+       if (DAMAGE_IS_ALL(priv->cpu_damage)) {
+               if ((flags & FORCE_GPU) == 0 || priv->cpu_bo) {
+                       DBG(("%s: use CPU fast path (all-damaged), and not forced-gpu\n",
+                            __FUNCTION__));
+                       assert(priv->gpu_damage == NULL);
+                       goto use_cpu_bo;
+               }
+       }
+
+       DBG(("%s: gpu? %d, damaged? %d; cpu? %d, damaged? %d\n", __FUNCTION__,
+            priv->gpu_bo ? priv->gpu_bo->handle : 0, priv->gpu_damage != NULL,
+            priv->cpu_bo ? priv->cpu_bo->handle : 0, priv->cpu_damage != NULL));
+       if (priv->gpu_bo == NULL) {
+               unsigned int move;
+
+               if ((flags & FORCE_GPU) == 0 &&
+                   (priv->create & KGEM_CAN_CREATE_GPU) == 0) {
+                       DBG(("%s: untiled, will not force allocation\n",
+                            __FUNCTION__));
+                       goto use_cpu_bo;
+               }
+
+               if ((flags & IGNORE_CPU) == 0) {
+                       if (priv->cpu_bo) {
+                               if (to_sna_from_pixmap(pixmap)->kgem.can_blt_cpu) {
+                                       if (kgem_bo_is_busy(priv->cpu_bo)) {
+                                               DBG(("%s: already using CPU bo, will not force allocation\n",
+                                                    __FUNCTION__));
+                                               goto use_cpu_bo;
+                                       }
+
+                                       if ((flags & RENDER_GPU) == 0) {
+                                               DBG(("%s: prefer cpu", __FUNCTION__));
+                                               goto use_cpu_bo;
+                                       }
+                               } else {
+                                       if (kgem_bo_is_busy(priv->cpu_bo)) {
+                                               DBG(("%s: CPU bo active, must force allocation\n",
+                                                    __FUNCTION__));
+                                               goto create_gpu_bo;
+                                       }
+                               }
+                       }
+
+                       if ((flags & FORCE_GPU) == 0 && priv->cpu_damage) {
+                               if ((flags & PREFER_GPU) == 0) {
+                                       DBG(("%s: already damaged and prefer cpu",
+                                            __FUNCTION__));
+                                       goto use_cpu_bo;
+                               }
+
+                               if (!box_inplace(pixmap, box)) {
+                                       DBG(("%s: damaged with a small operation, will not force allocation\n",
+                                            __FUNCTION__));
+                                       goto use_cpu_bo;
+                               }
+                       }
+               } else if (priv->cpu_damage) {
+                       get_drawable_deltas(drawable, pixmap, &dx, &dy);
+
+                       region.extents = *box;
+                       region.extents.x1 += dx;
+                       region.extents.x2 += dx;
+                       region.extents.y1 += dy;
+                       region.extents.y2 += dy;
+                       region.data = NULL;
+
+                       sna_damage_subtract(&priv->cpu_damage, &region);
+                       if (priv->cpu_damage == NULL) {
+                               list_del(&priv->list);
+                               priv->undamaged = false;
+                       }
+               }
+
+create_gpu_bo:
+               move = MOVE_WRITE | MOVE_READ;
+               if (flags & FORCE_GPU)
+                       move |= __MOVE_FORCE;
+               if (!sna_pixmap_move_to_gpu(pixmap, move))
+                       goto use_cpu_bo;
+
+               DBG(("%s: allocated GPU bo for operation\n", __FUNCTION__));
+               goto done;
+       }
+
+       get_drawable_deltas(drawable, pixmap, &dx, &dy);
+
+       region.extents = *box;
+       region.extents.x1 += dx;
+       region.extents.x2 += dx;
+       region.extents.y1 += dy;
+       region.extents.y2 += dy;
+
+       DBG(("%s extents (%d, %d), (%d, %d)\n", __FUNCTION__,
+            region.extents.x1, region.extents.y1,
+            region.extents.x2, region.extents.y2));
+
+       if (priv->gpu_damage) {
+               if (!priv->cpu_damage) {
+                       if (sna_damage_contains_box__no_reduce(priv->gpu_damage,
+                                                              &region.extents)) {
+                               DBG(("%s: region wholly contained within GPU damage\n",
+                                    __FUNCTION__));
+                               goto use_gpu_bo;
+                       } else {
+                               DBG(("%s: partial GPU damage with no CPU damage, continuing to use GPU\n",
+                                    __FUNCTION__));
+                               goto move_to_gpu;
+                       }
+               }
+
+               ret = sna_damage_contains_box(priv->gpu_damage, &region.extents);
+               if (ret == PIXMAN_REGION_IN) {
+                       DBG(("%s: region wholly contained within GPU damage\n",
+                            __FUNCTION__));
+                       goto use_gpu_bo;
+               }
+
+               if (ret != PIXMAN_REGION_OUT) {
+                       DBG(("%s: region partially contained within GPU damage\n",
+                            __FUNCTION__));
+                       goto move_to_gpu;
+               }
+       }
+
+       if ((flags & IGNORE_CPU) == 0 && priv->cpu_damage) {
+               ret = sna_damage_contains_box(priv->cpu_damage, &region.extents);
+               if (ret == PIXMAN_REGION_IN) {
+                       DBG(("%s: region wholly contained within CPU damage\n",
+                            __FUNCTION__));
+                       goto use_cpu_bo;
+               }
+
+               if (box_inplace(pixmap, box)) {
+                       DBG(("%s: forcing inplace\n", __FUNCTION__));
+                       goto move_to_gpu;
+               }
+
+               if (ret != PIXMAN_REGION_OUT) {
+                       DBG(("%s: region partially contained within CPU damage\n",
+                            __FUNCTION__));
+                       goto use_cpu_bo;
+               }
+       }
+
+move_to_gpu:
+       if (!sna_pixmap_move_area_to_gpu(pixmap, &region.extents,
+                                        flags & IGNORE_CPU ? MOVE_WRITE : MOVE_READ | MOVE_WRITE)) {
+               DBG(("%s: failed to move-to-gpu, fallback\n", __FUNCTION__));
+               assert(priv->gpu_bo == NULL);
+               goto use_cpu_bo;
+       }
+
+done:
+       assert(priv->gpu_bo != NULL);
+       if (sna_damage_is_all(&priv->gpu_damage,
+                             pixmap->drawable.width,
+                             pixmap->drawable.height)) {
+               sna_damage_destroy(&priv->cpu_damage);
+               *damage = NULL;
+       } else
+               *damage = &priv->gpu_damage;
+
+       DBG(("%s: using GPU bo with damage? %d\n",
+            __FUNCTION__, *damage != NULL));
+       assert(priv->gpu_bo->proxy == NULL);
+       return priv->gpu_bo;
+
+use_gpu_bo:
+       DBG(("%s: using whole GPU bo\n", __FUNCTION__));
+       assert(priv->gpu_bo != NULL);
+       assert(priv->gpu_bo->proxy == NULL);
+       priv->clear = false;
+       priv->cpu = false;
+       if (USE_INACTIVE &&
+           !priv->pinned && (priv->create & KGEM_CAN_CREATE_LARGE) == 0)
+               list_move(&priv->inactive,
+                         &to_sna_from_pixmap(pixmap)->active_pixmaps);
+       *damage = NULL;
+       return priv->gpu_bo;
+
+use_cpu_bo:
+       if (!USE_CPU_BO)
+               return NULL;
+
+       if (priv->cpu_bo == NULL)
+               return NULL;
+
+       sna = to_sna_from_pixmap(pixmap);
+       if ((flags & FORCE_GPU) == 0 &&
+           !__kgem_bo_is_busy(&sna->kgem, priv->cpu_bo)) {
+               DBG(("%s: has CPU bo, but is idle and acceleration not forced\n",
+                    __FUNCTION__));
+               return NULL;
+       }
+
+       get_drawable_deltas(drawable, pixmap, &dx, &dy);
+
+       region.extents = *box;
+       region.extents.x1 += dx;
+       region.extents.x2 += dx;
+       region.extents.y1 += dy;
+       region.extents.y2 += dy;
+       region.data = NULL;
+
+       /* Both CPU and GPU are busy, prefer to use the GPU */
+       if (priv->gpu_bo && kgem_bo_is_busy(priv->gpu_bo))
+               goto move_to_gpu;
+
+       assert(priv->gpu_bo == NULL || priv->gpu_bo->proxy == NULL);
+
+       if (flags & RENDER_GPU) {
+               if (priv->gpu_bo && priv->gpu_bo->tiling)
+                       goto move_to_gpu;
+
+               if (priv->cpu_bo->pitch >= 4096)
+                       goto move_to_gpu;
+
+               if (!sna->kgem.can_blt_cpu)
+                       goto move_to_gpu;
+       }
+
+       if (!sna->kgem.can_blt_cpu)
+               return NULL;
+
+       if (!sna_drawable_move_region_to_cpu(&pixmap->drawable, &region,
+                                            MOVE_READ | MOVE_ASYNC_HINT)) {
+               DBG(("%s: failed to move-to-cpu, fallback\n", __FUNCTION__));
+               return NULL;
+       }
+
+       if (sna_damage_is_all(&priv->cpu_damage,
+                             pixmap->drawable.width,
+                             pixmap->drawable.height)) {
+               sna_damage_destroy(&priv->gpu_damage);
+               *damage = NULL;
+       } else
+               *damage = &priv->cpu_damage;
+
+       if (priv->shm) {
+               assert(!priv->flush);
+               sna_add_flush_pixmap(sna, priv, priv->cpu_bo);
+
+               /* As we may have flushed and retired,, recheck for busy bo */
+               if ((flags & FORCE_GPU) == 0 && !kgem_bo_is_busy(priv->cpu_bo))
+                       return NULL;
+       }
+       if (priv->flush) {
+               assert(!priv->shm);
+               sna_add_flush_pixmap(sna, priv, priv->gpu_bo);
+       }
+
+       DBG(("%s: using CPU bo with damage? %d\n",
+            __FUNCTION__, *damage != NULL));
+       return priv->cpu_bo;
+}
+
+PixmapPtr
+sna_pixmap_create_upload(ScreenPtr screen,
+                        int width, int height, int depth,
+                        unsigned flags)
+{
+       struct sna *sna = to_sna_from_screen(screen);
+       PixmapPtr pixmap;
+       struct sna_pixmap *priv;
+       int bpp = bits_per_pixel(depth);
+       void *ptr;
+
+       DBG(("%s(%d, %d, %d, flags=%x)\n", __FUNCTION__,
+            width, height, depth, flags));
+       assert(width);
+       assert(height);
+
+       if (sna->freed_pixmap) {
+               pixmap = sna->freed_pixmap;
+               sna->freed_pixmap = pixmap->devPrivate.ptr;
+
+               pixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
+               pixmap->refcnt = 1;
+       } else {
+               pixmap = create_pixmap(sna, screen, 0, 0, depth, 0);
+               if (!pixmap)
+                       return NullPixmap;
+
+               priv = malloc(sizeof(*priv));
+               if (!priv) {
+                       FreePixmap(pixmap);
+                       return NullPixmap;
+               }
+
+               sna_set_pixmap(pixmap, priv);
+       }
+
+       priv = _sna_pixmap_reset(pixmap);
+       priv->header = true;
+
+       priv->gpu_bo = kgem_create_buffer_2d(&sna->kgem,
+                                            width, height, bpp,
+                                            flags, &ptr);
+       if (!priv->gpu_bo) {
+               free(priv);
+               FreePixmap(pixmap);
+               return NullPixmap;
+       }
+
+       /* Marking both the shadow and the GPU bo is a little dubious,
+        * but will work so long as we always check before doing the
+        * transfer.
+        */
+       sna_damage_all(&priv->gpu_damage, width, height);
+       sna_damage_all(&priv->cpu_damage, width, height);
+
+       pixmap->drawable.width = width;
+       pixmap->drawable.height = height;
+       pixmap->drawable.depth = depth;
+       pixmap->drawable.bitsPerPixel = bpp;
+       pixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
+       pixmap->devKind = priv->gpu_bo->pitch;
+       pixmap->devPrivate.ptr = ptr;
+
+       pixmap->usage_hint = 0;
+       if (!kgem_buffer_is_inplace(priv->gpu_bo))
+               pixmap->usage_hint = 1;
+
+       DBG(("%s: serial=%ld, usage=%d\n",
+            __FUNCTION__,
+            pixmap->drawable.serialNumber,
+            pixmap->usage_hint));
+
+       return pixmap;
+}
+
+struct sna_pixmap *
+sna_pixmap_move_to_gpu(PixmapPtr pixmap, unsigned flags)
+{
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+       struct sna_pixmap *priv;
+       BoxPtr box;
+       int n;
+
+       DBG(("%s(pixmap=%ld, usage=%d), flags=%x\n",
+            __FUNCTION__,
+            pixmap->drawable.serialNumber,
+            pixmap->usage_hint,
+            flags));
+
+       if ((flags & __MOVE_FORCE) == 0 && wedged(sna))
+               return NULL;
+
+       priv = sna_pixmap(pixmap);
+       if (priv == NULL) {
+               DBG(("%s: not attached\n", __FUNCTION__));
+               if ((flags & __MOVE_DRI) == 0)
+                       return NULL;
+
+               DBG(("%s: forcing the creation on the GPU\n", __FUNCTION__));
+
+               priv = sna_pixmap_attach(pixmap);
+               if (priv == NULL)
+                       return NULL;
+
+               sna_damage_all(&priv->cpu_damage,
+                              pixmap->drawable.width,
+                              pixmap->drawable.height);
+       }
+
+       if (sna_damage_is_all(&priv->gpu_damage,
+                             pixmap->drawable.width,
+                             pixmap->drawable.height)) {
+               DBG(("%s: already all-damaged\n", __FUNCTION__));
+               sna_damage_destroy(&priv->cpu_damage);
+               priv->undamaged = true;
+               goto active;
+       }
+
+       if (flags & MOVE_WRITE && priv->gpu_bo && priv->gpu_bo->proxy) {
+               DBG(("%s: discarding cached upload buffer\n", __FUNCTION__));
+               kgem_bo_destroy(&sna->kgem, priv->gpu_bo);
+               priv->gpu_bo = NULL;
+       }
+
+       if ((flags & MOVE_READ) == 0)
+               sna_damage_destroy(&priv->cpu_damage);
+
+       sna_damage_reduce(&priv->cpu_damage);
+       assert_pixmap_damage(pixmap);
+       DBG(("%s: CPU damage? %d\n", __FUNCTION__, priv->cpu_damage != NULL));
+       if (priv->gpu_bo == NULL) {
+               DBG(("%s: creating GPU bo (%dx%d@%d), create=%x\n",
+                    __FUNCTION__,
+                    pixmap->drawable.width,
+                    pixmap->drawable.height,
+                    pixmap->drawable.bitsPerPixel,
+                    priv->create));
+               assert(!priv->mapped);
+               if (flags & __MOVE_FORCE || priv->create & KGEM_CAN_CREATE_GPU) {
+                       unsigned create, tiling;
+
+                       assert(pixmap->drawable.width > 0);
+                       assert(pixmap->drawable.height > 0);
+                       assert(pixmap->drawable.bitsPerPixel >= 8);
+
+                       tiling = (flags & MOVE_SOURCE_HINT) ? I915_TILING_Y : DEFAULT_TILING;
+                       tiling = sna_pixmap_choose_tiling(pixmap, tiling);
+
+                       create = 0;
+                       if (priv->cpu_damage && priv->cpu_bo == NULL)
+                               create = CREATE_GTT_MAP | CREATE_INACTIVE;
+
+                       priv->gpu_bo =
+                               kgem_create_2d(&sna->kgem,
+                                              pixmap->drawable.width,
+                                              pixmap->drawable.height,
+                                              pixmap->drawable.bitsPerPixel,
+                                              tiling, create);
+               }
+               if (priv->gpu_bo == NULL) {
+                       DBG(("%s: not creating GPU bo\n", __FUNCTION__));
+                       assert(list_is_empty(&priv->list));
+                       return NULL;
+               }
+
+               if (flags & MOVE_WRITE && priv->cpu_damage == NULL) {
+                       /* Presume that we will only ever write to the GPU
+                        * bo. Readbacks are expensive but fairly constant
+                        * in cost for all sizes i.e. it is the act of
+                        * synchronisation that takes the most time. This is
+                        * mitigated by avoiding fallbacks in the first place.
+                        */
+                       sna_damage_all(&priv->gpu_damage,
+                                      pixmap->drawable.width,
+                                      pixmap->drawable.height);
+                       DBG(("%s: marking as all-damaged for GPU\n",
+                            __FUNCTION__));
+                       goto active;
+               }
+       }
+
+       if (priv->gpu_bo->proxy) {
+               DBG(("%s: reusing cached upload\n", __FUNCTION__));
+               assert((flags & MOVE_WRITE) == 0);
+               return priv;
+       }
+
+       if (priv->cpu_damage == NULL)
+               goto done;
+
+       if (priv->mapped) {
+               assert(priv->stride);
+               pixmap->devPrivate.ptr = priv->ptr;
+               pixmap->devKind = priv->stride;
+               priv->mapped = false;
+       }
+
+       n = sna_damage_get_boxes(priv->cpu_damage, &box);
+       if (n) {
+               bool ok;
+
+               assert(pixmap_contains_damage(pixmap, priv->cpu_damage));
+               DBG(("%s: uploading %d damage boxes\n", __FUNCTION__, n));
+
+               if (!priv->cpu)
+                       flags |= MOVE_ASYNC_HINT;
+
+               ok = false;
+               if (use_cpu_bo_for_upload(priv, flags)) {
+                       DBG(("%s: using CPU bo for upload to GPU\n", __FUNCTION__));
+                       ok = sna->render.copy_boxes(sna, GXcopy,
+                                                   pixmap, priv->cpu_bo, 0, 0,
+                                                   pixmap, priv->gpu_bo, 0, 0,
+                                                   box, n, 0);
+               }
+               if (!ok) {
+                       if (pixmap->devPrivate.ptr == NULL) {
+                               assert(priv->stride && priv->ptr);
+                               pixmap->devPrivate.ptr = priv->ptr;
+                               pixmap->devKind = priv->stride;
+                       }
+                       if (n == 1 && !priv->pinned &&
+                           (box->x2 - box->x1) >= pixmap->drawable.width &&
+                           (box->y2 - box->y1) >= pixmap->drawable.height) {
+                               ok = sna_replace(sna, pixmap,
+                                                &priv->gpu_bo,
+                                                pixmap->devPrivate.ptr,
+                                                pixmap->devKind);
+                       } else {
+                               ok = sna_write_boxes(sna, pixmap,
+                                               priv->gpu_bo, 0, 0,
+                                               pixmap->devPrivate.ptr,
+                                               pixmap->devKind,
+                                               0, 0,
+                                               box, n);
+                       }
+                       if (!ok)
+                               return NULL;
+               }
+       }
+
+       __sna_damage_destroy(DAMAGE_PTR(priv->cpu_damage));
+       priv->cpu_damage = NULL;
+       priv->undamaged = true;
+
+       if (priv->shm) {
+               assert(!priv->flush);
+               sna_add_flush_pixmap(sna, priv, priv->cpu_bo);
+       }
+
+       /* For large bo, try to keep only a single copy around */
+       if (priv->create & KGEM_CAN_CREATE_LARGE) {
+               sna_damage_all(&priv->gpu_damage,
+                              pixmap->drawable.width,
+                              pixmap->drawable.height);
+               sna_pixmap_free_cpu(sna, priv);
+       }
+done:
+       list_del(&priv->list);
+
+       sna_damage_reduce_all(&priv->gpu_damage,
+                             pixmap->drawable.width,
+                             pixmap->drawable.height);
+       if (DAMAGE_IS_ALL(priv->gpu_damage)) {
+               priv->undamaged = false;
+               if (priv->ptr) {
+                       assert(priv->cpu_bo == NULL || !priv->cpu_bo->flush);
+                       assert(!priv->shm);
+                       sna_pixmap_free_cpu(sna, priv);
+               }
+       }
+
+active:
+       if (flags & MOVE_WRITE)
+               priv->clear = false;
+       assert(!priv->gpu_bo->proxy || (flags & MOVE_WRITE) == 0);
+       return sna_pixmap_mark_active(sna, priv);
+}
+
+static bool must_check sna_validate_pixmap(DrawablePtr draw, PixmapPtr pixmap)
+{
+       if (draw->bitsPerPixel == pixmap->drawable.bitsPerPixel &&
+           FbEvenTile(pixmap->drawable.width *
+                      pixmap->drawable.bitsPerPixel)) {
+               DBG(("%s: flushing pixmap\n", __FUNCTION__));
+               if (!sna_pixmap_move_to_cpu(pixmap, MOVE_READ))
+                       return false;
+
+               fbPadPixmap(pixmap);
+       }
+
+       return true;
+}
+
+static bool must_check sna_gc_move_to_cpu(GCPtr gc,
+                                         DrawablePtr drawable,
+                                         RegionPtr region)
+{
+       struct sna_gc *sgc = sna_gc(gc);
+       long changes = sgc->changes;
+
+       DBG(("%s, changes=%lx\n", __FUNCTION__, changes));
+
+       assert(gc->ops == (GCOps *)&sna_gc_ops);
+       gc->ops = (GCOps *)&sna_gc_ops__cpu;
+
+       sgc->old_funcs = gc->funcs;
+       gc->funcs = (GCFuncs *)&sna_gc_funcs__cpu;
+
+       sgc->priv = gc->pCompositeClip;
+       gc->pCompositeClip = region;
+
+       if (gc->clientClipType == CT_PIXMAP) {
+               PixmapPtr clip = gc->clientClip;
+               gc->clientClip = BitmapToRegion(gc->pScreen, clip);
+               gc->pScreen->DestroyPixmap(clip);
+               gc->clientClipType = gc->clientClip ? CT_REGION : CT_NONE;
+               changes |= GCClipMask;
+       } else
+               changes &= ~GCClipMask;
+
+       if (changes || drawable->serialNumber != sgc->serial) {
+               gc->serialNumber = sgc->serial;
+
+               if (fb_gc(gc)->bpp != drawable->bitsPerPixel) {
+                       changes |= GCStipple | GCForeground | GCBackground | GCPlaneMask;
+                       fb_gc(gc)->bpp = drawable->bitsPerPixel;
+               }
+
+               if (changes & GCTile && !gc->tileIsPixel) {
+                       DBG(("%s: flushing tile pixmap\n", __FUNCTION__));
+                       if (!sna_validate_pixmap(drawable, gc->tile.pixmap))
+                               return false;
+               }
+
+               if (changes & GCStipple && gc->stipple) {
+                       DBG(("%s: flushing stipple pixmap\n", __FUNCTION__));
+                       if (!sna_validate_pixmap(drawable, gc->stipple))
+                               return false;
+               }
+
+               fbValidateGC(gc, changes, drawable);
+
+               gc->serialNumber = drawable->serialNumber;
+               sgc->serial = drawable->serialNumber;
+       }
+       sgc->changes = 0;
+
+       switch (gc->fillStyle) {
+       case FillTiled:
+               return sna_drawable_move_to_cpu(&gc->tile.pixmap->drawable, MOVE_READ);
+       case FillStippled:
+       case FillOpaqueStippled:
+               return sna_drawable_move_to_cpu(&gc->stipple->drawable, MOVE_READ);
+       default:
+               return true;
+       }
+}
+
+static void sna_gc_move_to_gpu(GCPtr gc)
+{
+       assert(gc->ops == (GCOps *)&sna_gc_ops__cpu);
+       assert(gc->funcs == (GCFuncs *)&sna_gc_funcs__cpu);
+
+       gc->ops = (GCOps *)&sna_gc_ops;
+       gc->funcs = sna_gc(gc)->old_funcs;
+       gc->pCompositeClip = sna_gc(gc)->priv;
+}
+
+static inline bool clip_box(BoxPtr box, GCPtr gc)
+{
+       const BoxRec *clip;
+       bool clipped;
+
+       clip = &gc->pCompositeClip->extents;
+
+       clipped = !region_is_singular(gc->pCompositeClip);
+       if (box->x1 < clip->x1)
+               box->x1 = clip->x1, clipped = true;
+       if (box->x2 > clip->x2)
+               box->x2 = clip->x2, clipped = true;
+
+       if (box->y1 < clip->y1)
+               box->y1 = clip->y1, clipped = true;
+       if (box->y2 > clip->y2)
+               box->y2 = clip->y2, clipped = true;
+
+       return clipped;
+}
+
+static inline void translate_box(BoxPtr box, DrawablePtr d)
+{
+       box->x1 += d->x;
+       box->x2 += d->x;
+
+       box->y1 += d->y;
+       box->y2 += d->y;
+}
+
+static inline bool trim_and_translate_box(BoxPtr box, DrawablePtr d, GCPtr gc)
+{
+       translate_box(box, d);
+       return clip_box(box, gc);
+}
+
+static inline bool box32_clip(Box32Rec *box, GCPtr gc)
+{
+       bool clipped = !region_is_singular(gc->pCompositeClip);
+       const BoxRec *clip = &gc->pCompositeClip->extents;
+
+       if (box->x1 < clip->x1)
+               box->x1 = clip->x1, clipped = true;
+       if (box->x2 > clip->x2)
+               box->x2 = clip->x2, clipped = true;
+
+       if (box->y1 < clip->y1)
+               box->y1 = clip->y1, clipped = true;
+       if (box->y2 > clip->y2)
+               box->y2 = clip->y2, clipped = true;
+
+       return clipped;
+}
+
+static inline void box32_translate(Box32Rec *box, DrawablePtr d)
+{
+       box->x1 += d->x;
+       box->x2 += d->x;
+
+       box->y1 += d->y;
+       box->y2 += d->y;
+}
+
+static inline bool box32_trim_and_translate(Box32Rec *box, DrawablePtr d, GCPtr gc)
+{
+       box32_translate(box, d);
+       return box32_clip(box, gc);
+}
+
+static inline void box_add_pt(BoxPtr box, int16_t x, int16_t y)
+{
+       if (box->x1 > x)
+               box->x1 = x;
+       else if (box->x2 < x)
+               box->x2 = x;
+
+       if (box->y1 > y)
+               box->y1 = y;
+       else if (box->y2 < y)
+               box->y2 = y;
+}
+
+static int16_t bound(int16_t a, uint16_t b)
+{
+       int v = (int)a + (int)b;
+       if (v > MAXSHORT)
+               return MAXSHORT;
+       return v;
+}
+
+static int16_t clamp(int16_t a, int16_t b)
+{
+       int v = (int)a + (int)b;
+       if (v > MAXSHORT)
+               return MAXSHORT;
+       if (v < MINSHORT)
+               return MINSHORT;
+       return v;
+}
+
+static inline bool box32_to_box16(const Box32Rec *b32, BoxRec *b16)
+{
+       b16->x1 = b32->x1;
+       b16->y1 = b32->y1;
+       b16->x2 = b32->x2;
+       b16->y2 = b32->y2;
+
+       return b16->x2 > b16->x1 && b16->y2 > b16->y1;
+}
+
+static inline void box32_add_rect(Box32Rec *box, const xRectangle *r)
+{
+       int32_t v;
+
+       v = r->x;
+       if (box->x1 > v)
+               box->x1 = v;
+       v += r->width;
+       if (box->x2 < v)
+               box->x2 = v;
+
+       v = r->y;
+       if (box->y1 > v)
+               box->y1 = v;
+       v += r->height;
+       if (box->y2 < v)
+               box->y2 = v;
+}
+
+static bool
+sna_put_image_upload_blt(DrawablePtr drawable, GCPtr gc, RegionPtr region,
+                        int x, int y, int w, int h, char *bits, int stride)
+{
+       PixmapPtr pixmap = get_drawable_pixmap(drawable);
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+       struct sna_pixmap *priv = sna_pixmap(pixmap);
+       BoxPtr box;
+       int nbox;
+       int16_t dx, dy;
+
+       box = REGION_RECTS(region);
+       nbox = REGION_NUM_RECTS(region);
+
+       DBG(("%s: %d x [(%d, %d), (%d, %d)...]\n",
+            __FUNCTION__, nbox,
+            box->x1, box->y1, box->x2, box->y2));
+
+       if (gc->alu != GXcopy)
+               return false;
+
+       if (priv->gpu_bo == NULL &&
+           !sna_pixmap_create_mappable_gpu(pixmap))
+               return false;
+
+       assert(priv->gpu_bo);
+       assert(priv->gpu_bo->proxy == NULL);
+
+       if (!priv->pinned && nbox == 1 &&
+           box->x1 <= 0 && box->y1 <= 0 &&
+           box->x2 >= pixmap->drawable.width &&
+           box->y2 >= pixmap->drawable.height)
+               return sna_replace(sna, pixmap, &priv->gpu_bo, bits, stride);
+
+       get_drawable_deltas(drawable, pixmap, &dx, &dy);
+       x += dx + drawable->x;
+       y += dy + drawable->y;
+
+       return sna_write_boxes(sna, pixmap,
+                              priv->gpu_bo, 0, 0,
+                              bits, stride, -x, -y,
+                              box, nbox);
+}
+
+static bool upload_inplace(struct sna *sna,
+                          PixmapPtr pixmap,
+                          struct sna_pixmap *priv,
+                          RegionRec *region)
+{
+       if (priv->shm) {
+               DBG(("%s: no, SHM Pixmap\n", __FUNCTION__));
+               return false;
+       }
+
+       if (priv->create & KGEM_CAN_CREATE_LARGE) {
+               if (priv->gpu_bo) {
+                       DBG(("%s: yes, large buffer and already have GPU bo\n",
+                            __FUNCTION__));
+                       return true;
+               }
+               if (priv->cpu_bo){
+                       DBG(("%s: no, large buffer and already have CPU bo\n",
+                            __FUNCTION__));
+                       return false;
+               }
+       }
+
+       if (!region_inplace(sna, pixmap, region, priv, true)) {
+               DBG(("%s? no, region not suitable\n", __FUNCTION__));
+               return false;
+       }
+
+       if (sna->kgem.has_llc && !priv->flush) {
+               if (priv->cpu_bo) {
+                       if (priv->cpu_damage &&
+                           kgem_bo_is_busy(priv->cpu_bo) &&
+                           !region_subsumes_damage(region, priv->cpu_damage)) {
+                               DBG(("%s? yes, CPU bo is busy\n", __FUNCTION__));
+                               return true;
+                       }
+
+                       DBG(("%s? no, have CPU bo\n", __FUNCTION__));
+                       return false;
+               }
+
+               if (priv->create & KGEM_CAN_CREATE_CPU) {
+                       DBG(("%s? no, can create CPU bo\n", __FUNCTION__));
+                       return false;
+               }
+       }
+
+       if (priv->gpu_bo) {
+               if (priv->gpu_bo->proxy)
+                       return false;
+
+               if (!kgem_bo_can_map(&sna->kgem, priv->gpu_bo)) {
+                       DBG(("%s? no, GPU bo not mappable\n", __FUNCTION__));
+                       return false;
+               }
+
+               if (!kgem_bo_is_busy(priv->gpu_bo)) {
+                       DBG(("%s? yes, GPU bo is idle\n", __FUNCTION__));
+                       return true;
+               }
+
+               if (!priv->pinned &&
+                   region_subsumes_drawable(region, &pixmap->drawable)) {
+                       DBG(("%s? yes, will replace busy GPU\n", __FUNCTION__));
+                       return true;
+               }
+       }
+
+       if ((priv->create & (KGEM_CAN_CREATE_GPU | KGEM_CAN_CREATE_CPU)) == KGEM_CAN_CREATE_GPU &&
+           region_subsumes_drawable(region, &pixmap->drawable)) {
+               DBG(("%s? yes, will fill fresh GPU bo\n", __FUNCTION__));
+               return true;
+       }
+
+       return false;
+}
+
+static bool
+sna_put_zpixmap_blt(DrawablePtr drawable, GCPtr gc, RegionPtr region,
+                   int x, int y, int w, int  h, char *bits, int stride)
+{
+       PixmapPtr pixmap = get_drawable_pixmap(drawable);
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+       struct sna_pixmap *priv = sna_pixmap(pixmap);
+       char *dst_bits;
+       int dst_stride;
+       BoxRec *box;
+       int16_t dx, dy;
+       int n;
+
+       assert_pixmap_contains_box(pixmap, RegionExtents(region));
+
+       if (gc->alu != GXcopy)
+               return false;
+
+       if (!priv) {
+               if (drawable->depth < 8)
+                       return false;
+
+               goto blt;
+       }
+
+       /* XXX performing the upload inplace is currently about 20x slower
+        * for putimage10 on gen6 -- mostly due to slow page faulting in kernel.
+        * So we try again with vma caching and only for pixmaps who will be
+        * immediately flushed...
+        */
+       if (upload_inplace(sna, pixmap, priv, region) &&
+           sna_put_image_upload_blt(drawable, gc, region,
+                                    x, y, w, h, bits, stride)) {
+               assert(priv->cpu == false);
+               if (!DAMAGE_IS_ALL(priv->gpu_damage)) {
+                       DBG(("%s: marking damage\n", __FUNCTION__));
+                       if (region_subsumes_drawable(region, &pixmap->drawable))
+                               sna_damage_destroy(&priv->cpu_damage);
+                       else
+                               sna_damage_subtract(&priv->cpu_damage, region);
+                       if (priv->cpu_damage == NULL) {
+                               sna_damage_all(&priv->gpu_damage,
+                                              pixmap->drawable.width,
+                                              pixmap->drawable.height);
+                               list_del(&priv->list);
+                               priv->undamaged = false;
+                       } else
+                               sna_damage_add(&priv->gpu_damage, region);
+               }
+
+               /* And mark as having a valid GTT mapping for future uploads */
+               if (priv->stride && kgem_bo_can_map(&sna->kgem, priv->gpu_bo)) {
+                       pixmap->devPrivate.ptr =
+                               kgem_bo_map__async(&sna->kgem, priv->gpu_bo);
+                       if (pixmap->devPrivate.ptr) {
+                               priv->mapped = true;
+                               pixmap->devKind = priv->gpu_bo->pitch;
+                       }
+               }
+
+               assert_pixmap_damage(pixmap);
+               priv->clear = false;
+               return true;
+       }
+
+       if (priv->gpu_bo && priv->gpu_bo->proxy) {
+               DBG(("%s: discarding cached upload buffer\n", __FUNCTION__));
+               kgem_bo_destroy(&sna->kgem, priv->gpu_bo);
+               priv->gpu_bo = NULL;
+       }
+
+       /* If the GPU is currently accessing the CPU pixmap, then
+        * we will need to wait for that to finish before we can
+        * modify the memory.
+        *
+        * However, we can queue some writes to the GPU bo to avoid
+        * the wait. Or we can try to replace the CPU bo.
+        */
+       if (!priv->shm && priv->cpu_bo && __kgem_bo_is_busy(&sna->kgem, priv->cpu_bo)) {
+               assert(!priv->cpu_bo->flush);
+               DBG(("%s: cpu bo will stall, upload damage and discard\n",
+                    __FUNCTION__));
+               if (priv->cpu_damage) {
+                       if (!region_subsumes_drawable(region, &pixmap->drawable)) {
+                               sna_damage_subtract(&priv->cpu_damage, region);
+                               if (!sna_pixmap_move_to_gpu(pixmap,
+                                                           MOVE_WRITE))
+                                       return false;
+                       } else {
+                               sna_damage_destroy(&priv->cpu_damage);
+                               priv->undamaged = false;
+                       }
+                       assert(priv->cpu_damage == NULL);
+               }
+               sna_damage_all(&priv->gpu_damage,
+                              pixmap->drawable.width,
+                              pixmap->drawable.height);
+               sna_pixmap_free_cpu(sna, priv);
+       }
+
+       if (priv->mapped) {
+               assert(!priv->shm);
+               pixmap->devPrivate.ptr = NULL;
+               priv->mapped = false;
+       }
+
+       if (pixmap->devPrivate.ptr == NULL &&
+           !sna_pixmap_alloc_cpu(sna, pixmap, priv, false))
+               return true;
+
+       if (priv->cpu_bo) {
+               DBG(("%s: syncing CPU bo\n", __FUNCTION__));
+               kgem_bo_sync__cpu(&sna->kgem, priv->cpu_bo);
+       }
+
+       if (priv->clear) {
+               DBG(("%s: applying clear [%08x]\n",
+                    __FUNCTION__, priv->clear_color));
+
+               if (priv->clear_color == 0) {
+                       memset(pixmap->devPrivate.ptr,
+                              0, pixmap->devKind * pixmap->drawable.height);
+               } else {
+                       pixman_fill(pixmap->devPrivate.ptr,
+                                   pixmap->devKind/sizeof(uint32_t),
+                                   pixmap->drawable.bitsPerPixel,
+                                   0, 0,
+                                   pixmap->drawable.width,
+                                   pixmap->drawable.height,
+                                   priv->clear_color);
+               }
+
+               sna_damage_all(&priv->cpu_damage,
+                              pixmap->drawable.width,
+                              pixmap->drawable.height);
+               sna_pixmap_free_gpu(sna, priv);
+               priv->undamaged = false;
+       }
+
+       if (!DAMAGE_IS_ALL(priv->cpu_damage)) {
+               DBG(("%s: marking damage\n", __FUNCTION__));
+               if (region_subsumes_drawable(region, &pixmap->drawable)) {
+                       DBG(("%s: replacing entire pixmap\n", __FUNCTION__));
+                       sna_damage_all(&priv->cpu_damage,
+                                      pixmap->drawable.width,
+                                      pixmap->drawable.height);
+                       sna_pixmap_free_gpu(sna, priv);
+                       priv->undamaged = false;
+               } else {
+                       sna_damage_subtract(&priv->gpu_damage, region);
+                       sna_damage_add(&priv->cpu_damage, region);
+                       if (priv->gpu_bo &&
+                           sna_damage_is_all(&priv->cpu_damage,
+                                             pixmap->drawable.width,
+                                             pixmap->drawable.height)) {
+                               DBG(("%s: replaced entire pixmap\n", __FUNCTION__));
+                               sna_pixmap_free_gpu(sna, priv);
+                               priv->undamaged = false;
+                       }
+               }
+               if (priv->flush) {
+                       assert(!priv->shm);
+                       sna_add_flush_pixmap(sna, priv, priv->gpu_bo);
+               }
+       }
+       assert(!priv->flush || !list_is_empty(&priv->list));
+       priv->cpu = true;
+
+blt:
+       get_drawable_deltas(drawable, pixmap, &dx, &dy);
+       x += dx + drawable->x;
+       y += dy + drawable->y;
+
+       DBG(("%s: upload(%d, %d, %d, %d)\n", __FUNCTION__, x, y, w, h));
+
+       dst_stride = pixmap->devKind;
+       dst_bits = pixmap->devPrivate.ptr;
+
+       /* Region is pre-clipped and translated into pixmap space */
+       box = REGION_RECTS(region);
+       n = REGION_NUM_RECTS(region);
+       do {
+               DBG(("%s: copy box (%d, %d)->(%d, %d)x(%d, %d)\n",
+                    __FUNCTION__,
+                    box->x1 - x, box->y1 - y,
+                    box->x1, box->y1,
+                    box->x2 - box->x1, box->y2 - box->y1));
+
+               assert(box->x2 > box->x1);
+               assert(box->y2 > box->y1);
+
+               assert(box->x1 >= 0);
+               assert(box->y1 >= 0);
+               assert(box->x2 <= pixmap->drawable.width);
+               assert(box->y2 <= pixmap->drawable.height);
+
+               assert(box->x1 - x >= 0);
+               assert(box->y1 - y >= 0);
+               assert(box->x2 - x <= w);
+               assert(box->y2 - y <= h);
+
+               memcpy_blt(bits, dst_bits,
+                          pixmap->drawable.bitsPerPixel,
+                          stride, dst_stride,
+                          box->x1 - x, box->y1 - y,
+                          box->x1, box->y1,
+                          box->x2 - box->x1, box->y2 - box->y1);
+               box++;
+       } while (--n);
+
+       assert_pixmap_damage(pixmap);
+       return true;
+}
+
+static inline uint8_t byte_reverse(uint8_t b)
+{
+       return ((b * 0x80200802ULL) & 0x0884422110ULL) * 0x0101010101ULL >> 32;
+}
+
+static inline uint8_t blt_depth(int depth)
+{
+       switch (depth) {
+       case 8: return 0;
+       case 15: return 0x2;
+       case 16: return 0x1;
+       default: return 0x3;
+       }
+}
+
+static bool
+sna_put_xybitmap_blt(DrawablePtr drawable, GCPtr gc, RegionPtr region,
+                    int x, int y, int w, int  h, char *bits)
+{
+       PixmapPtr pixmap = get_drawable_pixmap(drawable);
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+       struct sna_damage **damage;
+       struct kgem_bo *bo;
+       BoxRec *box;
+       int16_t dx, dy;
+       int n;
+       uint8_t rop = copy_ROP[gc->alu];
+
+       bo = sna_drawable_use_bo(&pixmap->drawable, PREFER_GPU,
+                                &region->extents, &damage);
+       if (bo == NULL)
+               return false;
+
+       if (bo->tiling == I915_TILING_Y) {
+               DBG(("%s: converting bo from Y-tiling\n", __FUNCTION__));
+               assert(bo == sna_pixmap_get_bo(pixmap));
+               bo = sna_pixmap_change_tiling(pixmap, I915_TILING_X);
+               if (bo == NULL) {
+                       DBG(("%s: fallback -- unable to change tiling\n",
+                            __FUNCTION__));
+                       return false;
+               }
+       }
+
+       assert_pixmap_contains_box(pixmap, RegionExtents(region));
+       if (damage)
+               sna_damage_add(damage, region);
+       assert_pixmap_damage(pixmap);
+
+       DBG(("%s: upload(%d, %d, %d, %d)\n", __FUNCTION__, x, y, w, h));
+
+       get_drawable_deltas(drawable, pixmap, &dx, &dy);
+       x += dx + drawable->x;
+       y += dy + drawable->y;
+
+       kgem_set_mode(&sna->kgem, KGEM_BLT);
+
+       /* Region is pre-clipped and translated into pixmap space */
+       box = REGION_RECTS(region);
+       n = REGION_NUM_RECTS(region);
+       do {
+               int bx1 = (box->x1 - x) & ~7;
+               int bx2 = (box->x2 - x + 7) & ~7;
+               int bw = (bx2 - bx1)/8;
+               int bh = box->y2 - box->y1;
+               int bstride = ALIGN(bw, 2);
+               int src_stride;
+               uint8_t *dst, *src;
+               uint32_t *b;
+               struct kgem_bo *upload;
+               void *ptr;
+
+               if (!kgem_check_batch(&sna->kgem, 8) ||
+                   !kgem_check_bo_fenced(&sna->kgem, bo) ||
+                   !kgem_check_reloc_and_exec(&sna->kgem, 2)) {
+                       _kgem_submit(&sna->kgem);
+                       _kgem_set_mode(&sna->kgem, KGEM_BLT);
+               }
+
+               upload = kgem_create_buffer(&sna->kgem,
+                                           bstride*bh,
+                                           KGEM_BUFFER_WRITE_INPLACE,
+                                           &ptr);
+               if (!upload)
+                       break;
+
+               dst = ptr;
+               bstride -= bw;
+
+               src_stride = BitmapBytePad(w);
+               src = (uint8_t*)bits + (box->y1 - y) * src_stride + bx1/8;
+               src_stride -= bw;
+               do {
+                       int i = bw;
+                       do {
+                               *dst++ = byte_reverse(*src++);
+                       } while (--i);
+                       dst += bstride;
+                       src += src_stride;
+               } while (--bh);
+
+               b = sna->kgem.batch + sna->kgem.nbatch;
+               b[0] = XY_MONO_SRC_COPY | 3 << 20;
+               b[0] |= ((box->x1 - x) & 7) << 17;
+               b[1] = bo->pitch;
+               if (sna->kgem.gen >= 40 && bo->tiling) {
+                       b[0] |= BLT_DST_TILED;
+                       b[1] >>= 2;
+               }
+               b[1] |= blt_depth(drawable->depth) << 24;
+               b[1] |= rop << 16;
+               b[2] = box->y1 << 16 | box->x1;
+               b[3] = box->y2 << 16 | box->x2;
+               b[4] = kgem_add_reloc(&sna->kgem, sna->kgem.nbatch + 4, bo,
+                                     I915_GEM_DOMAIN_RENDER << 16 |
+                                     I915_GEM_DOMAIN_RENDER |
+                                     KGEM_RELOC_FENCED,
+                                     0);
+               b[5] = kgem_add_reloc(&sna->kgem, sna->kgem.nbatch + 5,
+                                     upload,
+                                     I915_GEM_DOMAIN_RENDER << 16 |
+                                     KGEM_RELOC_FENCED,
+                                     0);
+               b[6] = gc->bgPixel;
+               b[7] = gc->fgPixel;
+
+               sna->kgem.nbatch += 8;
+               kgem_bo_destroy(&sna->kgem, upload);
+
+               box++;
+       } while (--n);
+
+       sna->blt_state.fill_bo = 0;
+       return true;
+}
+
+static bool
+sna_put_xypixmap_blt(DrawablePtr drawable, GCPtr gc, RegionPtr region,
+                    int x, int y, int w, int  h, int left,char *bits)
+{
+       PixmapPtr pixmap = get_drawable_pixmap(drawable);
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+       struct sna_damage **damage;
+       struct kgem_bo *bo;
+       int16_t dx, dy;
+       unsigned i, skip;
+
+       if (gc->alu != GXcopy)
+               return false;
+
+       bo = sna_drawable_use_bo(&pixmap->drawable, PREFER_GPU,
+                                &region->extents, &damage);
+       if (bo == NULL)
+               return false;
+
+       if (bo->tiling == I915_TILING_Y) {
+               DBG(("%s: converting bo from Y-tiling\n", __FUNCTION__));
+               assert(bo == sna_pixmap_get_bo(pixmap));
+               bo = sna_pixmap_change_tiling(pixmap, I915_TILING_X);
+               if (bo == NULL) {
+                       DBG(("%s: fallback -- unable to change tiling\n",
+                            __FUNCTION__));
+                       return false;
+               }
+       }
+
+       assert_pixmap_contains_box(pixmap, RegionExtents(region));
+       if (damage)
+               sna_damage_add(damage, region);
+       assert_pixmap_damage(pixmap);
+
+       DBG(("%s: upload(%d, %d, %d, %d)\n", __FUNCTION__, x, y, w, h));
+
+       get_drawable_deltas(drawable, pixmap, &dx, &dy);
+       x += dx + drawable->x;
+       y += dy + drawable->y;
+
+       kgem_set_mode(&sna->kgem, KGEM_BLT);
+
+       skip = h * BitmapBytePad(w + left);
+       for (i = 1 << (gc->depth-1); i; i >>= 1, bits += skip) {
+               const BoxRec *box = REGION_RECTS(region);
+               int n = REGION_NUM_RECTS(region);
+
+               if ((gc->planemask & i) == 0)
+                       continue;
+
+               /* Region is pre-clipped and translated into pixmap space */
+               do {
+                       int bx1 = (box->x1 - x) & ~7;
+                       int bx2 = (box->x2 - x + 7) & ~7;
+                       int bw = (bx2 - bx1)/8;
+                       int bh = box->y2 - box->y1;
+                       int bstride = ALIGN(bw, 2);
+                       int src_stride;
+                       uint8_t *dst, *src;
+                       uint32_t *b;
+                       struct kgem_bo *upload;
+                       void *ptr;
+
+                       if (!kgem_check_batch(&sna->kgem, 12) ||
+                           !kgem_check_bo_fenced(&sna->kgem, bo) ||
+                           !kgem_check_reloc_and_exec(&sna->kgem, 2)) {
+                               _kgem_submit(&sna->kgem);
+                               _kgem_set_mode(&sna->kgem, KGEM_BLT);
+                       }
+
+                       upload = kgem_create_buffer(&sna->kgem,
+                                                   bstride*bh,
+                                                   KGEM_BUFFER_WRITE_INPLACE,
+                                                   &ptr);
+                       if (!upload)
+                               break;
+
+                       dst = ptr;
+                       bstride -= bw;
+
+                       src_stride = BitmapBytePad(w);
+                       src = (uint8_t*)bits + (box->y1 - y) * src_stride + bx1/8;
+                       src_stride -= bw;
+                       do {
+                               int j = bw;
+                               do {
+                                       *dst++ = byte_reverse(*src++);
+                               } while (--j);
+                               dst += bstride;
+                               src += src_stride;
+                       } while (--bh);
+
+                       b = sna->kgem.batch + sna->kgem.nbatch;
+                       b[0] = XY_FULL_MONO_PATTERN_MONO_SRC_BLT | 3 << 20;
+                       b[0] |= ((box->x1 - x) & 7) << 17;
+                       b[1] = bo->pitch;
+                       if (sna->kgem.gen >= 40 && bo->tiling) {
+                               b[0] |= BLT_DST_TILED;
+                               b[1] >>= 2;
+                       }
+                       b[1] |= 1 << 31; /* solid pattern */
+                       b[1] |= blt_depth(drawable->depth) << 24;
+                       b[1] |= 0xce << 16; /* S or (D and !P) */
+                       b[2] = box->y1 << 16 | box->x1;
+                       b[3] = box->y2 << 16 | box->x2;
+                       b[4] = kgem_add_reloc(&sna->kgem, sna->kgem.nbatch + 4,
+                                             bo,
+                                             I915_GEM_DOMAIN_RENDER << 16 |
+                                             I915_GEM_DOMAIN_RENDER |
+                                             KGEM_RELOC_FENCED,
+                                             0);
+                       b[5] = kgem_add_reloc(&sna->kgem, sna->kgem.nbatch + 5,
+                                             upload,
+                                             I915_GEM_DOMAIN_RENDER << 16 |
+                                             KGEM_RELOC_FENCED,
+                                             0);
+                       b[6] = 0;
+                       b[7] = i;
+                       b[8] = i;
+                       b[9] = i;
+                       b[10] = -1;
+                       b[11] = -1;
+
+                       sna->kgem.nbatch += 12;
+                       kgem_bo_destroy(&sna->kgem, upload);
+
+                       box++;
+               } while (--n);
+       }
+
+       sna->blt_state.fill_bo = 0;
+       return true;
+}
+
+static void
+sna_put_image(DrawablePtr drawable, GCPtr gc, int depth,
+             int x, int y, int w, int h, int left, int format,
+             char *bits)
+{
+       PixmapPtr pixmap = get_drawable_pixmap(drawable);
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+       struct sna_pixmap *priv = sna_pixmap(pixmap);
+       RegionRec region;
+       int16_t dx, dy;
+
+       DBG(("%s((%d, %d)x(%d, %d), depth=%d, format=%d)\n",
+            __FUNCTION__, x, y, w, h, depth, format));
+
+       if (w == 0 || h == 0)
+               return;
+
+       get_drawable_deltas(drawable, pixmap, &dx, &dy);
+
+       region.extents.x1 = x + drawable->x;
+       region.extents.y1 = y + drawable->y;
+       region.extents.x2 = region.extents.x1 + w;
+       region.extents.y2 = region.extents.y1 + h;
+       region.data = NULL;
+
+       if (!region_is_singular(gc->pCompositeClip) ||
+           gc->pCompositeClip->extents.x1 > region.extents.x1 ||
+           gc->pCompositeClip->extents.y1 > region.extents.y1 ||
+           gc->pCompositeClip->extents.x2 < region.extents.x2 ||
+           gc->pCompositeClip->extents.y2 < region.extents.y2) {
+               RegionIntersect(&region, &region, gc->pCompositeClip);
+               if (!RegionNotEmpty(&region))
+                       return;
+       }
+
+       if (priv == NULL) {
+               DBG(("%s: fallback -- unattached(%d, %d, %d, %d)\n",
+                    __FUNCTION__, x, y, w, h));
+               goto fallback;
+       }
+
+       RegionTranslate(&region, dx, dy);
+
+       if (FORCE_FALLBACK)
+               goto fallback;
+
+       if (wedged(sna))
+               goto fallback;
+
+       if (!ACCEL_PUT_IMAGE)
+               goto fallback;
+
+       switch (format) {
+       case ZPixmap:
+               if (!PM_IS_SOLID(drawable, gc->planemask))
+                       goto fallback;
+
+               if (sna_put_zpixmap_blt(drawable, gc, &region,
+                                       x, y, w, h,
+                                       bits, PixmapBytePad(w, depth)))
+                       return;
+               break;
+
+       case XYBitmap:
+               if (!PM_IS_SOLID(drawable, gc->planemask))
+                       goto fallback;
+
+               if (sna_put_xybitmap_blt(drawable, gc, &region,
+                                        x, y, w, h,
+                                        bits))
+                       return;
+               break;
+
+       case XYPixmap:
+               if (sna_put_xypixmap_blt(drawable, gc, &region,
+                                        x, y, w, h, left,
+                                        bits))
+                       return;
+               break;
+
+       default:
+               return;
+       }
+
+fallback:
+       DBG(("%s: fallback\n", __FUNCTION__));
+       RegionTranslate(&region, -dx, -dy);
+
+       if (!sna_gc_move_to_cpu(gc, drawable, &region))
+               goto out;
+       if (!sna_drawable_move_region_to_cpu(drawable, &region,
+                                             format == XYPixmap ?
+                                             MOVE_READ | MOVE_WRITE :
+                                             drawable_gc_flags(drawable, gc, false)))
+               goto out_gc;
+
+       DBG(("%s: fbPutImage(%d, %d, %d, %d)\n",
+            __FUNCTION__, x, y, w, h));
+       fbPutImage(drawable, gc, depth, x, y, w, h, left, format, bits);
+       FALLBACK_FLUSH(drawable);
+out_gc:
+       sna_gc_move_to_gpu(gc);
+out:
+       RegionUninit(&region);
+}
+
+static bool
+move_to_gpu(PixmapPtr pixmap, struct sna_pixmap *priv,
+           const BoxRec *box, uint8_t alu)
+{
+       int w = box->x2 - box->x1;
+       int h = box->y2 - box->y1;
+       int count;
+
+       if (DAMAGE_IS_ALL(priv->gpu_damage))
+               return true;
+
+       if (priv->gpu_bo) {
+               if (alu != GXcopy)
+                       return true;
+
+               if (!priv->cpu)
+                       return true;
+
+               if (priv->gpu_bo->tiling)
+                       return true;
+       } else {
+               if ((priv->create & KGEM_CAN_CREATE_GPU) == 0)
+                       return false;
+               if (priv->shm)
+                       return false;
+       }
+
+       count = priv->source_count++;
+       if (priv->cpu_bo) {
+               if (priv->cpu_bo->flush && count > SOURCE_BIAS)
+                       return true;
+
+               if (sna_pixmap_choose_tiling(pixmap,
+                                            DEFAULT_TILING) == I915_TILING_NONE)
+                       return false;
+
+               if (priv->cpu)
+                       return false;
+
+               return count > SOURCE_BIAS;
+       } else {
+               if (w == pixmap->drawable.width && h == pixmap->drawable.height)
+                       return count > SOURCE_BIAS;
+
+               return count * w*h >= (SOURCE_BIAS+2) * (int)pixmap->drawable.width * pixmap->drawable.height;
+       }
+}
+
+static BoxPtr
+reorder_boxes(BoxPtr box, int n, int dx, int dy)
+{
+       BoxPtr new, base, next, tmp;
+
+       DBG(("%s x %d dx=%d, dy=%d\n", __FUNCTION__, n, dx, dy));
+
+       if (dy <= 0 && dx <= 0) {
+               new = malloc(sizeof(BoxRec) * n);
+               if (new == NULL)
+                       return NULL;
+
+               tmp = new;
+               next = box + n;
+               do {
+                       *tmp++ = *--next;
+               } while (next != box);
+       } else if (dy < 0) {
+               new = malloc(sizeof(BoxRec) * n);
+               if (new == NULL)
+                       return NULL;
+
+               base = next = box + n - 1;
+               while (base >= box) {
+                       while (next >= box && base->y1 == next->y1)
+                               next--;
+                       tmp = next + 1;
+                       while (tmp <= base)
+                               *new++ = *tmp++;
+                       base = next;
+               }
+               new -= n;
+       } else {
+               new = malloc(sizeof(BoxRec) * n);
+               if (!new)
+                       return NULL;
+
+               base = next = box;
+               while (base < box + n) {
+                       while (next < box + n && next->y1 == base->y1)
+                               next++;
+                       tmp = next;
+                       while (tmp != base)
+                               *new++ = *--tmp;
+                       base = next;
+               }
+               new -= n;
+       }
+
+       return new;
+}
+
+static void
+sna_self_copy_boxes(DrawablePtr src, DrawablePtr dst, GCPtr gc,
+                   RegionPtr region,int dx, int dy,
+                   Pixel bitplane, void *closure)
+{
+       PixmapPtr pixmap = get_drawable_pixmap(src);
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+       struct sna_pixmap *priv = sna_pixmap(pixmap);
+       BoxPtr box = RegionRects(region);
+       int n = RegionNumRects(region);
+       int alu = gc ? gc->alu : GXcopy;
+       int16_t tx, ty;
+
+       assert(RegionNumRects(region));
+       if (((dx | dy) == 0 && alu == GXcopy))
+               return;
+
+       if (n > 1 && (dx | dy) < 0) {
+               box = reorder_boxes(box, n, dx, dy);
+               if (box == NULL)
+                       return;
+       }
+
+       DBG(("%s (boxes=%dx[(%d, %d), (%d, %d)...], src=+(%d, %d), alu=%d, pix.size=%dx%d)\n",
+            __FUNCTION__, n,
+            region->extents.x1, region->extents.y1,
+            region->extents.x2, region->extents.y2,
+            dx, dy, alu,
+            pixmap->drawable.width, pixmap->drawable.height));
+
+       get_drawable_deltas(src, pixmap, &tx, &ty);
+       dx += tx;
+       dy += ty;
+       if (dst != src)
+               get_drawable_deltas(dst, pixmap, &tx, &ty);
+
+       if (priv == NULL || DAMAGE_IS_ALL(priv->cpu_damage))
+               goto fallback;
+
+       if (priv->gpu_damage) {
+               if (alu == GXcopy && priv->clear)
+                       goto out;
+
+               assert(priv->gpu_bo->proxy == NULL);
+               if (!sna_pixmap_move_to_gpu(pixmap, MOVE_WRITE | MOVE_READ)) {
+                       DBG(("%s: fallback - not a pure copy and failed to move dst to GPU\n",
+                            __FUNCTION__));
+                       goto fallback;
+               }
+
+               if (!sna->render.copy_boxes(sna, alu,
+                                           pixmap, priv->gpu_bo, dx, dy,
+                                           pixmap, priv->gpu_bo, tx, ty,
+                                           box, n, 0)) {
+                       DBG(("%s: fallback - accelerated copy boxes failed\n",
+                            __FUNCTION__));
+                       goto fallback;
+               }
+
+               if (!DAMAGE_IS_ALL(priv->gpu_damage)) {
+                       RegionTranslate(region, tx, ty);
+                       sna_damage_add(&priv->gpu_damage, region);
+               }
+               assert_pixmap_damage(pixmap);
+       } else {
+fallback:
+               DBG(("%s: fallback", __FUNCTION__));
+               if (!sna_pixmap_move_to_cpu(pixmap, MOVE_READ | MOVE_WRITE))
+                       goto out;
+
+               if (alu == GXcopy && pixmap->drawable.bitsPerPixel >= 8) {
+                       FbBits *dst_bits, *src_bits;
+                       int stride = pixmap->devKind;
+                       int bpp = pixmap->drawable.bitsPerPixel;
+                       int i;
+
+                       dst_bits = (FbBits *)
+                               ((char *)pixmap->devPrivate.ptr +
+                                ty * stride + tx * bpp / 8);
+                       src_bits = (FbBits *)
+                               ((char *)pixmap->devPrivate.ptr +
+                                dy * stride + dx * bpp / 8);
+
+                       for (i = 0; i < n; i++)
+                               memmove_box(src_bits, dst_bits,
+                                           bpp, stride, box+i,
+                                           dx, dy);
+               } else {
+                       if (gc && !sna_gc_move_to_cpu(gc, dst, region))
+                               goto out;
+
+                       get_drawable_deltas(src, pixmap, &tx, &ty);
+                       miCopyRegion(src, dst, gc,
+                                    region, dx - tx, dy - ty,
+                                    fbCopyNtoN, 0, NULL);
+
+                       if (gc)
+                               sna_gc_move_to_gpu(gc);
+               }
+       }
+
+out:
+       if (box != RegionRects(region))
+               free(box);
+}
+
+static inline bool
+sna_pixmap_is_gpu(PixmapPtr pixmap)
+{
+       struct sna_pixmap *priv = sna_pixmap(pixmap);
+
+       if (priv == NULL || priv->clear)
+               return false;
+
+       if (DAMAGE_IS_ALL(priv->gpu_damage) ||
+           (priv->gpu_bo && kgem_bo_is_busy(priv->gpu_bo) && !priv->gpu_bo->proxy))
+               return true;
+
+       return priv->cpu_bo && kgem_bo_is_busy(priv->cpu_bo);
+}
+
+static int
+source_prefer_gpu(struct sna_pixmap *priv)
+{
+       if (priv == NULL) {
+               DBG(("%s: source unattached, use cpu\n", __FUNCTION__));
+               return 0;
+       }
+
+       if (priv->clear) {
+               DBG(("%s: source is clear, don't force use of GPU\n", __FUNCTION__));
+               return 0;
+       }
+
+       if (priv->gpu_damage) {
+               DBG(("%s: source has gpu damage, force gpu\n", __FUNCTION__));
+               return PREFER_GPU | FORCE_GPU;
+       }
+
+       if (priv->cpu_bo && kgem_bo_is_busy(priv->cpu_bo)) {
+               DBG(("%s: source has busy CPU bo, force gpu\n", __FUNCTION__));
+               return PREFER_GPU | FORCE_GPU;
+       }
+
+       if (DAMAGE_IS_ALL(priv->cpu_damage))
+               return 0;
+
+       DBG(("%s: source has GPU bo? %d\n",
+            __FUNCTION__, priv->gpu_bo != NULL));
+       return priv->gpu_bo != NULL;
+}
+
+static void
+sna_copy_boxes(DrawablePtr src, DrawablePtr dst, GCPtr gc,
+              RegionPtr region, int dx, int dy,
+              Pixel bitplane, void *closure)
+{
+       PixmapPtr src_pixmap = get_drawable_pixmap(src);
+       struct sna_pixmap *src_priv = sna_pixmap(src_pixmap);
+       PixmapPtr dst_pixmap = get_drawable_pixmap(dst);
+       struct sna_pixmap *dst_priv = sna_pixmap(dst_pixmap);
+       struct sna *sna = to_sna_from_pixmap(src_pixmap);
+       struct sna_damage **damage;
+       struct kgem_bo *bo;
+       unsigned hint;
+       int16_t src_dx, src_dy;
+       int16_t dst_dx, dst_dy;
+       BoxPtr box = RegionRects(region);
+       int n = RegionNumRects(region);
+       int alu = gc->alu;
+       int stride, bpp;
+       char *bits;
+       bool replaces;
+
+       assert(RegionNumRects(region));
+
+       if (src_pixmap == dst_pixmap)
+               return sna_self_copy_boxes(src, dst, gc,
+                                          region, dx, dy,
+                                          bitplane, closure);
+
+       DBG(("%s (boxes=%dx[(%d, %d), (%d, %d)...], src=+(%d, %d), alu=%d, src.size=%dx%d, dst.size=%dx%d)\n",
+            __FUNCTION__, n,
+            box[0].x1, box[0].y1, box[0].x2, box[0].y2,
+            dx, dy, alu,
+            src_pixmap->drawable.width, src_pixmap->drawable.height,
+            dst_pixmap->drawable.width, dst_pixmap->drawable.height));
+
+       assert_pixmap_damage(dst_pixmap);
+       assert_pixmap_damage(src_pixmap);
+
+       bpp = dst_pixmap->drawable.bitsPerPixel;
+
+       get_drawable_deltas(dst, dst_pixmap, &dst_dx, &dst_dy);
+       RegionTranslate(region, dst_dx, dst_dy);
+       get_drawable_deltas(src, src_pixmap, &src_dx, &src_dy);
+       src_dx += dx - dst_dx;
+       src_dy += dy - dst_dy;
+
+       assert_pixmap_contains_box(dst_pixmap, RegionExtents(region));
+       assert_pixmap_contains_box_with_offset(src_pixmap,
+                                              RegionExtents(region),
+                                              src_dx, src_dy);
+
+       replaces = n == 1 &&
+               box->x1 <= 0 &&
+               box->y1 <= 0 &&
+               box->x2 >= dst_pixmap->drawable.width &&
+               box->y2 >= dst_pixmap->drawable.height;
+
+       DBG(("%s: dst=(priv=%p, gpu_bo=%p, cpu_bo=%p), src=(priv=%p, gpu_bo=%p, cpu_bo=%p), replaces=%d\n",
+            __FUNCTION__,
+            dst_priv,
+            dst_priv ? dst_priv->gpu_bo : NULL,
+            dst_priv ? dst_priv->cpu_bo : NULL,
+            src_priv,
+            src_priv ? src_priv->gpu_bo : NULL,
+            src_priv ? src_priv->cpu_bo : NULL,
+            replaces));
+
+       if (dst_priv == NULL)
+               goto fallback;
+
+       hint = source_prefer_gpu(src_priv) ?:
+               region_inplace(sna, dst_pixmap, region,
+                              dst_priv, alu_overwrites(alu));
+       if (dst_priv->cpu_damage && alu_overwrites(alu)) {
+               DBG(("%s: overwritting CPU damage\n", __FUNCTION__));
+               if (region_subsumes_damage(region, dst_priv->cpu_damage)) {
+                       DBG(("%s: discarding existing CPU damage\n", __FUNCTION__));
+                       if (dst_priv->gpu_bo && dst_priv->gpu_bo->proxy) {
+                               kgem_bo_destroy(&sna->kgem, dst_priv->gpu_bo);
+                               dst_priv->gpu_bo = NULL;
+                       }
+                       sna_damage_destroy(&dst_priv->cpu_damage);
+                       list_del(&dst_priv->list);
+               }
+               if (region->data == NULL)
+                       hint |= IGNORE_CPU;
+       }
+
+       bo = sna_drawable_use_bo(&dst_pixmap->drawable, hint,
+                                &region->extents, &damage);
+       if (bo) {
+               if (src_priv && src_priv->clear) {
+                       DBG(("%s: applying src clear[%08x] to dst\n",
+                            __FUNCTION__, src_priv->clear_color));
+                       if (n == 1) {
+                               if (!sna->render.fill_one(sna,
+                                                         dst_pixmap, bo,
+                                                         src_priv->clear_color,
+                                                         box->x1, box->y1,
+                                                         box->x2, box->y2,
+                                                         alu)) {
+                                       DBG(("%s: unsupported fill\n",
+                                            __FUNCTION__));
+                                       goto fallback;
+                               }
+                       } else {
+                               struct sna_fill_op fill;
+
+                               if (!sna_fill_init_blt(&fill, sna,
+                                                      dst_pixmap, bo,
+                                                      alu, src_priv->clear_color)) {
+                                       DBG(("%s: unsupported fill\n",
+                                            __FUNCTION__));
+                                       goto fallback;
+                               }
+
+                               fill.boxes(sna, &fill, box, n);
+                               fill.done(sna, &fill);
+                       }
+
+                       if (damage)
+                               sna_damage_add(damage, region);
+                       return;
+               }
+
+               if (src_priv &&
+                   move_to_gpu(src_pixmap, src_priv, &region->extents, alu) &&
+                   sna_pixmap_move_to_gpu(src_pixmap, MOVE_READ)) {
+                       DBG(("%s: move whole src_pixmap to GPU and copy\n",
+                            __FUNCTION__));
+                       if (!sna->render.copy_boxes(sna, alu,
+                                                   src_pixmap, src_priv->gpu_bo, src_dx, src_dy,
+                                                   dst_pixmap, bo, 0, 0,
+                                                   box, n, 0)) {
+                               DBG(("%s: fallback - accelerated copy boxes failed\n",
+                                    __FUNCTION__));
+                               goto fallback;
+                       }
+
+                       if (damage)
+                               sna_damage_add(damage, region);
+                       return;
+               }
+
+               if (src_priv &&
+                   region_overlaps_damage(region, src_priv->gpu_damage,
+                                          src_dx, src_dy)) {
+                       BoxRec area;
+
+                       DBG(("%s: region overlaps GPU damage, upload and copy\n",
+                            __FUNCTION__));
+
+                       area = region->extents;
+                       area.x1 += src_dx;
+                       area.x2 += src_dx;
+                       area.y1 += src_dy;
+                       area.y2 += src_dy;
+
+                       if (!sna_pixmap_move_area_to_gpu(src_pixmap, &area,
+                                                        MOVE_READ))
+                               goto fallback;
+
+                       if (!sna->render.copy_boxes(sna, alu,
+                                                   src_pixmap, src_priv->gpu_bo, src_dx, src_dy,
+                                                   dst_pixmap, bo, 0, 0,
+                                                   box, n, 0)) {
+                               DBG(("%s: fallback - accelerated copy boxes failed\n",
+                                    __FUNCTION__));
+                               goto fallback;
+                       }
+
+                       if (damage)
+                               sna_damage_add(damage, region);
+                       return;
+               }
+
+               if (bo != dst_priv->gpu_bo)
+                       goto fallback;
+
+               if (src_priv && src_priv->cpu_bo) {
+                       bool ret;
+
+                       DBG(("%s: region overlaps CPU damage, copy from CPU bo\n",
+                            __FUNCTION__));
+
+                       assert(bo != dst_priv->cpu_bo);
+
+                       RegionTranslate(region, src_dx, src_dy);
+                       ret = sna_drawable_move_region_to_cpu(&src_pixmap->drawable,
+                                                             region,
+                                                             MOVE_READ | MOVE_ASYNC_HINT);
+                       RegionTranslate(region, -src_dx, -src_dy);
+                       if (!ret)
+                               goto fallback;
+
+                       if (!sna->render.copy_boxes(sna, alu,
+                                                   src_pixmap, src_priv->cpu_bo, src_dx, src_dy,
+                                                   dst_pixmap, bo, 0, 0,
+                                                   box, n, 0)) {
+                               DBG(("%s: fallback - accelerated copy boxes failed\n",
+                                    __FUNCTION__));
+                               goto fallback;
+                       }
+
+                       if (src_priv->shm) {
+                               assert(!src_priv->flush);
+                               sna_add_flush_pixmap(sna, src_priv, src_priv->cpu_bo);
+                       }
+
+                       if (damage)
+                               sna_damage_add(damage, region);
+                       return;
+               }
+
+               if (src_priv == NULL &&
+                   sna->kgem.has_userptr &&
+                   __kgem_bo_is_busy(&sna->kgem, bo) &&
+                   box_inplace(src_pixmap, &region->extents)) {
+                       struct kgem_bo *src_bo;
+                       bool ok = false;
+
+                       DBG(("%s: upload through a temporary map\n",
+                            __FUNCTION__));
+
+                       src_bo = kgem_create_map(&sna->kgem,
+                                                src_pixmap->devPrivate.ptr,
+                                                src_pixmap->devKind * src_pixmap->drawable.height,
+                                                true);
+                       if (src_bo) {
+                               src_bo->flush = true;
+                               src_bo->pitch = src_pixmap->devKind;
+                               src_bo->reusable = false;
+
+                               ok = sna->render.copy_boxes(sna, alu,
+                                                           src_pixmap, src_bo, src_dx, src_dy,
+                                                           dst_pixmap, bo, 0, 0,
+                                                           box, n, COPY_LAST);
+
+                               kgem_bo_sync__cpu(&sna->kgem, src_bo);
+                               kgem_bo_destroy(&sna->kgem, src_bo);
+                       }
+
+                       if (ok) {
+                               if (damage)
+                                       sna_damage_add(damage, region);
+                               return;
+                       }
+               }
+
+               if (alu != GXcopy) {
+                       PixmapPtr tmp;
+                       struct kgem_bo *src_bo;
+                       int i;
+
+                       assert(src_pixmap->drawable.depth != 1);
+
+                       DBG(("%s: creating temporary source upload for non-copy alu [%d]\n",
+                            __FUNCTION__, alu));
+
+                       tmp = sna_pixmap_create_upload(src->pScreen,
+                                                      region->extents.x2 - region->extents.x1,
+                                                      region->extents.y2 - region->extents.y1,
+                                                      src->depth,
+                                                      KGEM_BUFFER_WRITE_INPLACE);
+                       if (tmp == NullPixmap)
+                               return;
+
+                       src_bo = sna_pixmap_get_bo(tmp);
+                       assert(src_bo != NULL);
+
+                       dx = -region->extents.x1;
+                       dy = -region->extents.y1;
+                       for (i = 0; i < n; i++) {
+                               assert(box[i].x1 + src_dx >= 0);
+                               assert(box[i].y1 + src_dy >= 0);
+                               assert(box[i].x2 + src_dx <= src_pixmap->drawable.width);
+                               assert(box[i].y2 + src_dy <= src_pixmap->drawable.height);
+
+                               assert(box[i].x1 + dx >= 0);
+                               assert(box[i].y1 + dy >= 0);
+                               assert(box[i].x2 + dx <= tmp->drawable.width);
+                               assert(box[i].y2 + dy <= tmp->drawable.height);
+
+                               memcpy_blt(src_pixmap->devPrivate.ptr,
+                                          tmp->devPrivate.ptr,
+                                          src_pixmap->drawable.bitsPerPixel,
+                                          src_pixmap->devKind,
+                                          tmp->devKind,
+                                          box[i].x1 + src_dx,
+                                          box[i].y1 + src_dy,
+                                          box[i].x1 + dx,
+                                          box[i].y1 + dy,
+                                          box[i].x2 - box[i].x1,
+                                          box[i].y2 - box[i].y1);
+                       }
+
+                       if (n == 1 &&
+                           tmp->drawable.width == src_pixmap->drawable.width &&
+                           tmp->drawable.height == src_pixmap->drawable.height)
+                               kgem_proxy_bo_attach(src_bo, &src_priv->gpu_bo);
+
+                       if (!sna->render.copy_boxes(sna, alu,
+                                                   tmp, src_bo, dx, dy,
+                                                   dst_pixmap, bo, 0, 0,
+                                                   box, n, 0)) {
+                               DBG(("%s: fallback - accelerated copy boxes failed\n",
+                                    __FUNCTION__));
+                               tmp->drawable.pScreen->DestroyPixmap(tmp);
+                               goto fallback;
+                       }
+                       tmp->drawable.pScreen->DestroyPixmap(tmp);
+
+                       if (damage)
+                               sna_damage_add(damage, region);
+                       return;
+               } else {
+                       DBG(("%s: dst is on the GPU, src is on the CPU, uploading into dst\n",
+                            __FUNCTION__));
+
+                       if (src_priv) {
+                               /* Fixup the shadow pointer as necessary */
+                               if (src_priv->mapped) {
+                                       assert(!src_priv->shm);
+                                       src_pixmap->devPrivate.ptr = NULL;
+                                       src_priv->mapped = false;
+                               }
+                               if (src_pixmap->devPrivate.ptr == NULL) {
+                                       if (!src_priv->ptr) /* uninitialised!*/
+                                               return;
+                                       assert(src_priv->stride);
+                                       src_pixmap->devPrivate.ptr = src_priv->ptr;
+                                       src_pixmap->devKind = src_priv->stride;
+                               }
+                       }
+
+                       if (!dst_priv->pinned && replaces) {
+                               stride = src_pixmap->devKind;
+                               bits = src_pixmap->devPrivate.ptr;
+                               bits += (src_dy + box->y1) * stride + (src_dx + box->x1) * bpp / 8;
+
+                               if (!sna_replace(sna, dst_pixmap,
+                                                &dst_priv->gpu_bo,
+                                                bits, stride))
+                                       goto fallback;
+                       } else {
+                               assert(!DAMAGE_IS_ALL(dst_priv->cpu_damage));
+                               if (!sna_write_boxes(sna, dst_pixmap,
+                                                    dst_priv->gpu_bo, 0, 0,
+                                                    src_pixmap->devPrivate.ptr,
+                                                    src_pixmap->devKind,
+                                                    src_dx, src_dy,
+                                                    box, n))
+                                       goto fallback;
+                       }
+
+                       dst_priv->cpu = false;
+                       if (damage) {
+                               if (replaces) {
+                                       sna_damage_destroy(&dst_priv->cpu_damage);
+                                       sna_damage_all(&dst_priv->gpu_damage,
+                                                      dst_pixmap->drawable.width,
+                                                      dst_pixmap->drawable.height);
+                                       list_del(&dst_priv->list);
+                                       dst_priv->undamaged = false;
+                               } else
+                                       sna_damage_add(&dst_priv->gpu_damage,
+                                                      region);
+                               assert_pixmap_damage(dst_pixmap);
+                       }
+               }
+
+               return;
+       }
+
+fallback:
+       if (alu == GXcopy && src_priv && src_priv->clear) {
+               DBG(("%s: copying clear [%08x]\n",
+                    __FUNCTION__, src_priv->clear_color));
+
+               if (dst_priv) {
+                       if (!sna_drawable_move_region_to_cpu(&dst_pixmap->drawable,
+                                                            region,
+                                                            MOVE_WRITE | MOVE_INPLACE_HINT))
+                               return;
+               }
+
+               do {
+                       pixman_fill(dst_pixmap->devPrivate.ptr,
+                                   dst_pixmap->devKind/sizeof(uint32_t),
+                                   dst_pixmap->drawable.bitsPerPixel,
+                                   box->x1, box->y1,
+                                   box->x2 - box->x1,
+                                   box->y2 - box->y1,
+                                   src_priv->clear_color);
+                       box++;
+               } while (--n);
+       } else {
+               FbBits *dst_bits, *src_bits;
+               int dst_stride, src_stride;
+
+               DBG(("%s: fallback -- src=(%d, %d), dst=(%d, %d)\n",
+                    __FUNCTION__, src_dx, src_dy, dst_dx, dst_dy));
+               if (src_priv) {
+                       unsigned mode;
+
+                       RegionTranslate(region, src_dx, src_dy);
+
+                       assert_pixmap_contains_box(src_pixmap,
+                                                  RegionExtents(region));
+
+                       mode = MOVE_READ;
+                       if (src_priv->cpu_bo == NULL)
+                               mode |= MOVE_INPLACE_HINT;
+
+                       if (!sna_drawable_move_region_to_cpu(&src_pixmap->drawable,
+                                                            region, mode))
+                               return;
+
+                       RegionTranslate(region, -src_dx, -src_dy);
+               }
+
+               if (dst_priv) {
+                       unsigned mode;
+
+                       if (alu_overwrites(alu))
+                               mode = MOVE_WRITE | MOVE_INPLACE_HINT;
+                       else
+                               mode = MOVE_WRITE | MOVE_READ;
+                       if (!sna_drawable_move_region_to_cpu(&dst_pixmap->drawable,
+                                                            region, mode))
+                               return;
+               }
+
+               dst_stride = dst_pixmap->devKind;
+               src_stride = src_pixmap->devKind;
+
+               if (alu == GXcopy && bpp >= 8) {
+                       dst_bits = (FbBits *)dst_pixmap->devPrivate.ptr;
+                       src_bits = (FbBits *)
+                               ((char *)src_pixmap->devPrivate.ptr +
+                                src_dy * src_stride + src_dx * bpp / 8);
+
+                       do {
+                               DBG(("%s: memcpy_blt(box=(%d, %d), (%d, %d), src=(%d, %d), pitches=(%d, %d))\n",
+                                    __FUNCTION__,
+                                    box->x1, box->y1,
+                                    box->x2 - box->x1,
+                                    box->y2 - box->y1,
+                                    src_dx, src_dy,
+                                    src_stride, dst_stride));
+
+                               assert(box->x1 >= 0);
+                               assert(box->y1 >= 0);
+                               assert(box->x2 <= dst_pixmap->drawable.width);
+                               assert(box->y2 <= dst_pixmap->drawable.height);
+
+                               assert(box->x1 + src_dx >= 0);
+                               assert(box->y1 + src_dy >= 0);
+                               assert(box->x2 + src_dx <= src_pixmap->drawable.width);
+                               assert(box->y2 + src_dy <= src_pixmap->drawable.height);
+
+                               memcpy_blt(src_bits, dst_bits, bpp,
+                                          src_stride, dst_stride,
+                                          box->x1, box->y1,
+                                          box->x1, box->y1,
+                                          box->x2 - box->x1,
+                                          box->y2 - box->y1);
+                               box++;
+                       } while (--n);
+               } else {
+                       DBG(("%s: fallback -- miCopyRegion\n", __FUNCTION__));
+
+                       RegionTranslate(region, -dst_dx, -dst_dy);
+
+                       if (!sna_gc_move_to_cpu(gc, dst, region))
+                               return;
+
+                       miCopyRegion(src, dst, gc,
+                                    region, dx, dy,
+                                    fbCopyNtoN, 0, NULL);
+
+                       sna_gc_move_to_gpu(gc);
+               }
+       }
+}
+
+typedef void (*sna_copy_func)(DrawablePtr src, DrawablePtr dst, GCPtr gc,
+                             RegionPtr region, int dx, int dy,
+                             Pixel bitPlane, void *closure);
+
+inline static bool
+box_intersect(BoxPtr a, const BoxRec *b)
+{
+       if (a->x1 < b->x1)
+               a->x1 = b->x1;
+       if (a->x2 > b->x2)
+               a->x2 = b->x2;
+       if (a->y1 < b->y1)
+               a->y1 = b->y1;
+       if (a->y2 > b->y2)
+               a->y2 = b->y2;
+
+       return a->x1 < a->x2 && a->y1 < a->y2;
+}
+
+static RegionPtr
+sna_do_copy(DrawablePtr src, DrawablePtr dst, GCPtr gc,
+           int sx, int sy,
+           int width, int height,
+           int dx, int dy,
+           sna_copy_func copy, Pixel bitPlane, void *closure)
+{
+       RegionPtr clip, free_clip = NULL;
+       RegionRec region;
+       bool expose;
+
+       DBG(("%s: src=(%d, %d), dst=(%d, %d), size=(%dx%d)\n",
+            __FUNCTION__, sx, sy, dx, dy, width, height));
+
+       /* Short cut for unmapped windows */
+       if (dst->type == DRAWABLE_WINDOW && !((WindowPtr)dst)->realized) {
+               DBG(("%s: unmapped\n", __FUNCTION__));
+               return NULL;
+       }
+
+       if (src->pScreen->SourceValidate)
+               src->pScreen->SourceValidate(src, sx, sy,
+                                            width, height,
+                                            gc->subWindowMode);
+
+       sx += src->x;
+       sy += src->y;
+
+       dx += dst->x;
+       dy += dst->y;
+
+       DBG(("%s: after drawable: src=(%d, %d), dst=(%d, %d), size=(%dx%d)\n",
+            __FUNCTION__, sx, sy, dx, dy, width, height));
+
+       region.extents.x1 = dx;
+       region.extents.y1 = dy;
+       region.extents.x2 = bound(dx, width);
+       region.extents.y2 = bound(dy, height);
+       region.data = NULL;
+
+       DBG(("%s: dst extents (%d, %d), (%d, %d)\n", __FUNCTION__,
+            region.extents.x1, region.extents.y1,
+            region.extents.x2, region.extents.y2));
+
+       if (!box_intersect(&region.extents, &gc->pCompositeClip->extents)) {
+               DBG(("%s: dst clipped out\n", __FUNCTION__));
+               return NULL;
+       }
+
+       region.extents.x1 = clamp(region.extents.x1, sx - dx);
+       region.extents.x2 = clamp(region.extents.x2, sx - dx);
+       region.extents.y1 = clamp(region.extents.y1, sy - dy);
+       region.extents.y2 = clamp(region.extents.y2, sy - dy);
+
+       /* Compute source clip region */
+       clip = NULL;
+       if (src == dst && gc->clientClipType == CT_NONE) {
+               DBG(("%s: using gc clip for src\n", __FUNCTION__));
+               clip = gc->pCompositeClip;
+       } else if (src->type == DRAWABLE_PIXMAP) {
+               DBG(("%s: pixmap -- no source clipping\n", __FUNCTION__));
+       } else if (gc->subWindowMode == IncludeInferiors) {
+               /*
+                * XFree86 DDX empties the border clip when the
+                * VT is inactive, make sure the region isn't empty
+                */
+               if (((WindowPtr)src)->parent ||
+                   !RegionNotEmpty(&((WindowPtr)src)->borderClip)) {
+                       DBG(("%s: include inferiors\n", __FUNCTION__));
+                       free_clip = clip = NotClippedByChildren((WindowPtr)src);
+               }
+       } else {
+               DBG(("%s: window clip\n", __FUNCTION__));
+               clip = &((WindowPtr)src)->clipList;
+       }
+       if (clip == NULL) {
+               DBG(("%s: fast source clip against extents\n", __FUNCTION__));
+               expose = true;
+               if (region.extents.x1 < src->x) {
+                       region.extents.x1 = src->x;
+                       expose = false;
+               }
+               if (region.extents.y1 < src->y) {
+                       region.extents.y1 = src->y;
+                       expose = false;
+               }
+               if (region.extents.x2 > src->x + (int) src->width) {
+                       region.extents.x2 = src->x + (int) src->width;
+                       expose = false;
+               }
+               if (region.extents.y2 > src->y + (int) src->height) {
+                       region.extents.y2 = src->y + (int) src->height;
+                       expose = false;
+               }
+               if (box_empty(&region.extents))
+                       return NULL;
+       } else {
+               expose = false;
+               RegionIntersect(&region, &region, clip);
+               if (free_clip)
+                       RegionDestroy(free_clip);
+       }
+       DBG(("%s: src extents (%d, %d), (%d, %d) x %d\n", __FUNCTION__,
+            region.extents.x1, region.extents.y1,
+            region.extents.x2, region.extents.y2,
+            RegionNumRects(&region)));
+       RegionTranslate(&region, dx-sx, dy-sy);
+       if (gc->pCompositeClip->data)
+               RegionIntersect(&region, &region, gc->pCompositeClip);
+       DBG(("%s: copy region (%d, %d), (%d, %d) x %d\n", __FUNCTION__,
+            region.extents.x1, region.extents.y1,
+            region.extents.x2, region.extents.y2,
+            RegionNumRects(&region)));
+
+       if (RegionNotEmpty(&region))
+               copy(src, dst, gc, &region, sx-dx, sy-dy, bitPlane, closure);
+       RegionUninit(&region);
+
+       /* Pixmap sources generate a NoExposed (we return NULL to do this) */
+       clip = NULL;
+       if (!expose && gc->fExpose)
+               clip = miHandleExposures(src, dst, gc,
+                                        sx - src->x, sy - src->y,
+                                        width, height,
+                                        dx - dst->x, dy - dst->y,
+                                        (unsigned long) bitPlane);
+       return clip;
+}
+
+static RegionPtr
+sna_copy_area(DrawablePtr src, DrawablePtr dst, GCPtr gc,
+             int src_x, int src_y,
+             int width, int height,
+             int dst_x, int dst_y)
+{
+       struct sna *sna = to_sna_from_drawable(dst);
+
+       if (gc->planemask == 0)
+               return NULL;
+
+       DBG(("%s: src=(%d, %d)x(%d, %d)+(%d, %d) -> dst=(%d, %d)+(%d, %d)\n",
+            __FUNCTION__,
+            src_x, src_y, width, height, src->x, src->y,
+            dst_x, dst_y, dst->x, dst->y));
+
+       if (FORCE_FALLBACK || !ACCEL_COPY_AREA || wedged(sna) ||
+           !PM_IS_SOLID(dst, gc->planemask)) {
+               RegionRec region, *ret;
+
+               DBG(("%s: fallback -- wedged=%d, solid=%d [%x]\n",
+                    __FUNCTION__, sna->kgem.wedged,
+                    PM_IS_SOLID(dst, gc->planemask),
+                    (unsigned)gc->planemask));
+
+               region.extents.x1 = dst_x + dst->x;
+               region.extents.y1 = dst_y + dst->y;
+               region.extents.x2 = region.extents.x1 + width;
+               region.extents.y2 = region.extents.y1 + height;
+               region.data = NULL;
+               RegionIntersect(&region, &region, gc->pCompositeClip);
+
+               DBG(("%s: dst extents (%d, %d), (%d, %d)\n",
+                    __FUNCTION__,
+                    region.extents.x1, region.extents.y1,
+                    region.extents.x2, region.extents.y2));
+
+               {
+                       RegionRec clip;
+
+                       clip.extents.x1 = src->x - (src->x + src_x) + (dst->x + dst_x);
+                       clip.extents.y1 = src->y - (src->y + src_y) + (dst->y + dst_y);
+                       clip.extents.x2 = clip.extents.x1 + src->width;
+                       clip.extents.y2 = clip.extents.y1 + src->height;
+                       clip.data = NULL;
+
+                       DBG(("%s: src extents (%d, %d), (%d, %d)\n",
+                            __FUNCTION__,
+                            clip.extents.x1, clip.extents.y1,
+                            clip.extents.x2, clip.extents.y2));
+
+                       RegionIntersect(&region, &region, &clip);
+               }
+               DBG(("%s: dst^src extents (%d, %d), (%d, %d)\n",
+                    __FUNCTION__,
+                    region.extents.x1, region.extents.y1,
+                    region.extents.x2, region.extents.y2));
+
+               if (!RegionNotEmpty(&region))
+                       return NULL;
+
+               ret = NULL;
+               if (!sna_gc_move_to_cpu(gc, dst, &region))
+                       goto out;
+
+               if (!sna_drawable_move_region_to_cpu(dst, &region,
+                                                    drawable_gc_flags(dst, gc, false)))
+                       goto out_gc;
+
+               RegionTranslate(&region,
+                               src_x - dst_x - dst->x + src->x,
+                               src_y - dst_y - dst->y + src->y);
+               if (!sna_drawable_move_region_to_cpu(src, &region, MOVE_READ))
+                       goto out_gc;
+               RegionTranslate(&region,
+                               -(src_x - dst_x - dst->x + src->x),
+                               -(src_y - dst_y - dst->y + src->y));
+
+               ret = miDoCopy(src, dst, gc,
+                              src_x, src_y,
+                              width, height,
+                              dst_x, dst_y,
+                              fbCopyNtoN, 0, 0);
+               FALLBACK_FLUSH(dst);
+out_gc:
+               sna_gc_move_to_gpu(gc);
+out:
+               RegionUninit(&region);
+               return ret;
+       }
+
+       return sna_do_copy(src, dst, gc,
+                          src_x, src_y,
+                          width, height,
+                          dst_x, dst_y,
+                          src == dst ? sna_self_copy_boxes : sna_copy_boxes,
+                          0, NULL);
+}
+
+static const BoxRec *
+find_clip_box_for_y(const BoxRec *begin, const BoxRec *end, int16_t y)
+{
+    const BoxRec *mid;
+
+    if (end == begin)
+       return end;
+
+    if (end - begin == 1) {
+       if (begin->y2 > y)
+           return begin;
+       else
+           return end;
+    }
+
+    mid = begin + (end - begin) / 2;
+    if (mid->y2 > y)
+       /* If no box is found in [begin, mid], the function
+        * will return @mid, which is then known to be the
+        * correct answer.
+        */
+       return find_clip_box_for_y(begin, mid, y);
+    else
+       return find_clip_box_for_y(mid, end, y);
+}
+
+struct sna_fill_spans {
+       struct sna *sna;
+       PixmapPtr pixmap;
+       RegionRec region;
+       unsigned flags;
+       struct kgem_bo *bo;
+       struct sna_damage **damage;
+       int16_t dx, dy;
+       void *op;
+};
+
+static void
+sna_poly_point__cpu(DrawablePtr drawable, GCPtr gc,
+                   int mode, int n, DDXPointPtr pt)
+{
+       fbPolyPoint(drawable, gc, mode, n, pt, -1);
+}
+
+static void
+sna_poly_point__fill(DrawablePtr drawable, GCPtr gc,
+                    int mode, int n, DDXPointPtr pt)
+{
+       struct sna_fill_spans *data = sna_gc(gc)->priv;
+       struct sna_fill_op *op = data->op;
+       BoxRec box[512];
+       DDXPointRec last;
+
+       DBG(("%s: count=%d\n", __FUNCTION__, n));
+
+       last.x = drawable->x + data->dx;
+       last.y = drawable->y + data->dy;
+       while (n) {
+               BoxRec *b = box;
+               unsigned nbox = n;
+               if (nbox > ARRAY_SIZE(box))
+                       nbox = ARRAY_SIZE(box);
+               n -= nbox;
+               do {
+                       *(DDXPointRec *)b = *pt++;
+
+                       b->x1 += last.x;
+                       b->y1 += last.y;
+                       if (mode == CoordModePrevious)
+                               last = *(DDXPointRec *)b;
+
+                       b->x2 = b->x1 + 1;
+                       b->y2 = b->y1 + 1;
+                       b++;
+               } while (--nbox);
+               op->boxes(data->sna, op, box, b - box);
+       }
+}
+
+static void
+sna_poly_point__gpu(DrawablePtr drawable, GCPtr gc,
+                    int mode, int n, DDXPointPtr pt)
+{
+       struct sna_fill_spans *data = sna_gc(gc)->priv;
+       struct sna_fill_op fill;
+       BoxRec box[512];
+       DDXPointRec last;
+
+       if (!sna_fill_init_blt(&fill,
+                              data->sna, data->pixmap,
+                              data->bo, gc->alu, gc->fgPixel))
+               return;
+
+       DBG(("%s: count=%d\n", __FUNCTION__, n));
+
+       last.x = drawable->x;
+       last.y = drawable->y;
+       while (n) {
+               BoxRec *b = box;
+               unsigned nbox = n;
+               if (nbox > ARRAY_SIZE(box))
+                       nbox = ARRAY_SIZE(box);
+               n -= nbox;
+               do {
+                       *(DDXPointRec *)b = *pt++;
+
+                       b->x1 += last.x;
+                       b->y1 += last.y;
+                       if (mode == CoordModePrevious)
+                               last = *(DDXPointRec *)b;
+
+                       if (RegionContainsPoint(&data->region,
+                                               b->x1, b->y1, NULL)) {
+                               b->x1 += data->dx;
+                               b->y1 += data->dy;
+                               b->x2 = b->x1 + 1;
+                               b->y2 = b->y1 + 1;
+                               b++;
+                       }
+               } while (--nbox);
+               fill.boxes(data->sna, &fill, box, b - box);
+       }
+       fill.done(data->sna, &fill);
+}
+
+static void
+sna_poly_point__fill_clip_extents(DrawablePtr drawable, GCPtr gc,
+                                 int mode, int n, DDXPointPtr pt)
+{
+       struct sna_fill_spans *data = sna_gc(gc)->priv;
+       struct sna_fill_op *op = data->op;
+       const BoxRec *extents = &data->region.extents;
+       BoxRec box[512], *b = box;
+       const BoxRec *const last_box = b + ARRAY_SIZE(box);
+       DDXPointRec last;
+
+       DBG(("%s: count=%d\n", __FUNCTION__, n));
+
+       last.x = drawable->x + data->dx;
+       last.y = drawable->y + data->dy;
+       while (n--) {
+               *(DDXPointRec *)b = *pt++;
+
+               b->x1 += last.x;
+               b->y1 += last.y;
+               if (mode == CoordModePrevious)
+                       last = *(DDXPointRec *)b;
+
+               if (b->x1 >= extents->x1 && b->x1 < extents->x2 &&
+                   b->y1 >= extents->y1 && b->y1 < extents->y2) {
+                       b->x2 = b->x1 + 1;
+                       b->y2 = b->y1 + 1;
+                       if (++b == last_box) {
+                               op->boxes(data->sna, op, box, last_box - box);
+                               b = box;
+                       }
+               }
+       }
+       if (b != box)
+               op->boxes(data->sna, op, box, b - box);
+}
+
+static void
+sna_poly_point__fill_clip_boxes(DrawablePtr drawable, GCPtr gc,
+                               int mode, int n, DDXPointPtr pt)
+{
+       struct sna_fill_spans *data = sna_gc(gc)->priv;
+       struct sna_fill_op *op = data->op;
+       RegionRec *clip = &data->region;
+       BoxRec box[512], *b = box;
+       const BoxRec *const last_box = b + ARRAY_SIZE(box);
+       DDXPointRec last;
+
+       DBG(("%s: count=%d\n", __FUNCTION__, n));
+
+       last.x = drawable->x + data->dx;
+       last.y = drawable->y + data->dy;
+       while (n--) {
+               *(DDXPointRec *)b = *pt++;
+
+               b->x1 += last.x;
+               b->y1 += last.y;
+               if (mode == CoordModePrevious)
+                       last = *(DDXPointRec *)b;
+
+               if (RegionContainsPoint(clip, b->x1, b->y1, NULL)) {
+                       b->x2 = b->x1 + 1;
+                       b->y2 = b->y1 + 1;
+                       if (++b == last_box) {
+                               op->boxes(data->sna, op, box, last_box - box);
+                               b = box;
+                       }
+               }
+       }
+       if (b != box)
+               op->boxes(data->sna, op, box, b - box);
+}
+
+static void
+sna_fill_spans__fill(DrawablePtr drawable,
+                    GCPtr gc, int n,
+                    DDXPointPtr pt, int *width, int sorted)
+{
+       struct sna_fill_spans *data = sna_gc(gc)->priv;
+       struct sna_fill_op *op = data->op;
+       BoxRec box[512];
+
+       DBG(("%s: alu=%d, fg=%08lx, count=%d\n",
+            __FUNCTION__, gc->alu, gc->fgPixel, n));
+
+       while (n) {
+               BoxRec *b = box;
+               int nbox = n;
+               if (nbox > ARRAY_SIZE(box))
+                       nbox = ARRAY_SIZE(box);
+               n -= nbox;
+               do {
+                       *(DDXPointRec *)b = *pt++;
+                       b->x2 = b->x1 + (int)*width++;
+                       b->y2 = b->y1 + 1;
+                       DBG(("%s: (%d, %d), (%d, %d)\n",
+                            __FUNCTION__, b->x1, b->y1, b->x2, b->y2));
+                       assert(b->x1 >= drawable->x);
+                       assert(b->x2 <= drawable->x + drawable->width);
+                       assert(b->y1 >= drawable->y);
+                       assert(b->y2 <= drawable->y + drawable->height);
+                       if (b->x2 > b->x1) {
+                               if (b != box &&
+                                   b->y1 == b[-1].y2 &&
+                                   b->x1 == b[-1].x1 &&
+                                   b->x2 == b[-1].x2)
+                                       b[-1].y2 = b->y2;
+                               else
+                                       b++;
+                       }
+               } while (--nbox);
+               if (b != box)
+                       op->boxes(data->sna, op, box, b - box);
+       }
+}
+
+static void
+sna_fill_spans__dash(DrawablePtr drawable,
+                    GCPtr gc, int n,
+                    DDXPointPtr pt, int *width, int sorted)
+{
+       struct sna_fill_spans *data = sna_gc(gc)->priv;
+       struct sna_fill_op *op = data->op;
+
+       if (op->base.u.blt.pixel == gc->fgPixel)
+               sna_fill_spans__fill(drawable, gc, n, pt, width, sorted);
+}
+
+static void
+sna_fill_spans__fill_offset(DrawablePtr drawable,
+                           GCPtr gc, int n,
+                           DDXPointPtr pt, int *width, int sorted)
+{
+       struct sna_fill_spans *data = sna_gc(gc)->priv;
+       struct sna_fill_op *op = data->op;
+       BoxRec box[512];
+
+       DBG(("%s: alu=%d, fg=%08lx\n", __FUNCTION__, gc->alu, gc->fgPixel));
+
+       while (n) {
+               BoxRec *b = box;
+               int nbox = n;
+               if (nbox > ARRAY_SIZE(box))
+                       nbox = ARRAY_SIZE(box);
+               n -= nbox;
+               do {
+                       *(DDXPointRec *)b = *pt++;
+                       b->x1 += data->dx;
+                       b->y1 += data->dy;
+                       b->x2 = b->x1 + (int)*width++;
+                       b->y2 = b->y1 + 1;
+                       if (b->x2 > b->x1)
+                               b++;
+               } while (--nbox);
+               if (b != box)
+                       op->boxes(data->sna, op, box, b - box);
+       }
+}
+
+static void
+sna_fill_spans__dash_offset(DrawablePtr drawable,
+                           GCPtr gc, int n,
+                           DDXPointPtr pt, int *width, int sorted)
+{
+       struct sna_fill_spans *data = sna_gc(gc)->priv;
+       struct sna_fill_op *op = data->op;
+
+       if (op->base.u.blt.pixel == gc->fgPixel)
+               sna_fill_spans__fill_offset(drawable, gc, n, pt, width, sorted);
+}
+
+static void
+sna_fill_spans__fill_clip_extents(DrawablePtr drawable,
+                                 GCPtr gc, int n,
+                                 DDXPointPtr pt, int *width, int sorted)
+{
+       struct sna_fill_spans *data = sna_gc(gc)->priv;
+       struct sna_fill_op *op = data->op;
+       const BoxRec *extents = &data->region.extents;
+       BoxRec box[512], *b = box, *const last_box = box + ARRAY_SIZE(box);
+
+       DBG(("%s: alu=%d, fg=%08lx, count=%d, extents=(%d, %d), (%d, %d)\n",
+            __FUNCTION__, gc->alu, gc->fgPixel, n,
+            extents->x1, extents->y1,
+            extents->x2, extents->y2));
+
+       while (n--) {
+               DBG(("%s: [%d] pt=(%d, %d), width=%d\n",
+                    __FUNCTION__, n, pt->x, pt->y, *width));
+               *(DDXPointRec *)b = *pt++;
+               b->x2 = b->x1 + (int)*width++;
+               b->y2 = b->y1 + 1;
+               if (box_intersect(b, extents)) {
+                       DBG(("%s: [%d] clipped=(%d, %d), (%d, %d)\n",
+                            __FUNCTION__, n, b->x1, b->y1, b->x2, b->y2));
+                       if (data->dx|data->dy) {
+                               b->x1 += data->dx; b->x2 += data->dx;
+                               b->y1 += data->dy; b->y2 += data->dy;
+                       }
+                       if (b != box &&
+                           b->y1 == b[-1].y2 &&
+                           b->x1 == b[-1].x1 &&
+                           b->x2 == b[-1].x2) {
+                               b[-1].y2 = b->y2;
+                       } else if (++b == last_box) {
+                               op->boxes(data->sna, op, box, last_box - box);
+                               b = box;
+                       }
+               }
+       }
+       if (b != box)
+               op->boxes(data->sna, op, box, b - box);
+}
+
+static void
+sna_fill_spans__dash_clip_extents(DrawablePtr drawable,
+                                 GCPtr gc, int n,
+                                 DDXPointPtr pt, int *width, int sorted)
+{
+       struct sna_fill_spans *data = sna_gc(gc)->priv;
+       struct sna_fill_op *op = data->op;
+
+       if (op->base.u.blt.pixel == gc->fgPixel)
+               sna_fill_spans__fill_clip_extents(drawable, gc, n, pt, width, sorted);
+}
+
+static void
+sna_fill_spans__fill_clip_boxes(DrawablePtr drawable,
+                               GCPtr gc, int n,
+                               DDXPointPtr pt, int *width, int sorted)
+{
+       struct sna_fill_spans *data = sna_gc(gc)->priv;
+       struct sna_fill_op *op = data->op;
+       BoxRec box[512], *b = box, *const last_box = box + ARRAY_SIZE(box);
+       const BoxRec * const clip_start = RegionBoxptr(&data->region);
+       const BoxRec * const clip_end = clip_start + data->region.data->numRects;
+
+       DBG(("%s: alu=%d, fg=%08lx, count=%d, extents=(%d, %d), (%d, %d)\n",
+            __FUNCTION__, gc->alu, gc->fgPixel, n,
+            data->region.extents.x1, data->region.extents.y1,
+            data->region.extents.x2, data->region.extents.y2));
+
+       while (n--) {
+               int16_t X1 = pt->x;
+               int16_t y = pt->y;
+               int16_t X2 = X1 + (int)*width;
+               const BoxRec *c;
+
+               pt++;
+               width++;
+
+               if (y < data->region.extents.y1 || data->region.extents.y2 <= y)
+                       continue;
+
+               if (X1 < data->region.extents.x1)
+                       X1 = data->region.extents.x1;
+
+               if (X2 > data->region.extents.x2)
+                       X2 = data->region.extents.x2;
+
+               if (X1 >= X2)
+                       continue;
+
+               c = find_clip_box_for_y(clip_start, clip_end, y);
+               while (c != clip_end) {
+                       if (y + 1 <= c->y1 || X2 <= c->x1)
+                               break;
+
+                       if (X1 >= c->x2) {
+                               c++;
+                               continue;
+                       }
+
+                       b->x1 = c->x1;
+                       b->x2 = c->x2;
+                       c++;
+
+                       if (b->x1 < X1)
+                               b->x1 = X1;
+                       if (b->x2 > X2)
+                               b->x2 = X2;
+                       if (b->x2 <= b->x1)
+                               continue;
+
+                       b->x1 += data->dx;
+                       b->x2 += data->dx;
+                       b->y1 = y + data->dy;
+                       b->y2 = b->y1 + 1;
+                       if (++b == last_box) {
+                               op->boxes(data->sna, op, box, last_box - box);
+                               b = box;
+                       }
+               }
+       }
+       if (b != box)
+               op->boxes(data->sna, op, box, b - box);
+}
+
+static void
+sna_fill_spans__dash_clip_boxes(DrawablePtr drawable,
+                               GCPtr gc, int n,
+                               DDXPointPtr pt, int *width, int sorted)
+{
+       struct sna_fill_spans *data = sna_gc(gc)->priv;
+       struct sna_fill_op *op = data->op;
+
+       if (op->base.u.blt.pixel == gc->fgPixel)
+               sna_fill_spans__fill_clip_boxes(drawable, gc, n, pt, width, sorted);
+}
+
+static bool
+sna_fill_spans_blt(DrawablePtr drawable,
+                  struct kgem_bo *bo, struct sna_damage **damage,
+                  GCPtr gc, uint32_t pixel,
+                  int n, DDXPointPtr pt, int *width, int sorted,
+                  const BoxRec *extents, unsigned clipped)
+{
+       PixmapPtr pixmap = get_drawable_pixmap(drawable);
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+       int16_t dx, dy;
+       struct sna_fill_op fill;
+       BoxRec box[512], *b = box, *const last_box = box + ARRAY_SIZE(box);
+       static void * const jump[] = {
+               &&no_damage,
+               &&damage,
+               &&no_damage_clipped,
+               &&damage_clipped,
+       };
+       unsigned v;
+
+       DBG(("%s: alu=%d, fg=%08lx, damge=%p, clipped?=%d\n",
+            __FUNCTION__, gc->alu, gc->fgPixel, damage, clipped));
+
+       if (!sna_fill_init_blt(&fill, sna, pixmap, bo, gc->alu, pixel))
+               return false;
+
+       get_drawable_deltas(drawable, pixmap, &dx, &dy);
+
+       v = (damage != NULL) | clipped;
+       goto *jump[v];
+
+no_damage:
+       if (dx|dy) {
+               do {
+                       int nbox = n;
+                       if (nbox > last_box - box)
+                               nbox = last_box - box;
+                       n -= nbox;
+                       do {
+                               *(DDXPointRec *)b = *pt++;
+                               b->x1 += dx;
+                               b->y1 += dy;
+                               b->x2 = b->x1 + (int)*width++;
+                               b->y2 = b->y1 + 1;
+                               b++;
+                       } while (--nbox);
+                       fill.boxes(sna, &fill, box, b - box);
+                       b = box;
+               } while (n);
+       } else {
+               do {
+                       int nbox = n;
+                       if (nbox > last_box - box)
+                               nbox = last_box - box;
+                       n -= nbox;
+                       do {
+                               *(DDXPointRec *)b = *pt++;
+                               b->x2 = b->x1 + (int)*width++;
+                               b->y2 = b->y1 + 1;
+                               b++;
+                       } while (--nbox);
+                       fill.boxes(sna, &fill, box, b - box);
+                       b = box;
+               } while (n);
+       }
+       goto done;
+
+damage:
+       do {
+               *(DDXPointRec *)b = *pt++;
+               b->x1 += dx;
+               b->y1 += dy;
+               b->x2 = b->x1 + (int)*width++;
+               b->y2 = b->y1 + 1;
+
+               if (++b == last_box) {
+                       assert_pixmap_contains_boxes(pixmap, box, last_box-box, 0, 0);
+                       fill.boxes(sna, &fill, box, last_box - box);
+                       sna_damage_add_boxes(damage, box, last_box - box, 0, 0);
+                       b = box;
+               }
+       } while (--n);
+       if (b != box) {
+               assert_pixmap_contains_boxes(pixmap, box, b-box, 0, 0);
+               fill.boxes(sna, &fill, box, b - box);
+               sna_damage_add_boxes(damage, box, b - box, 0, 0);
+       }
+       goto done;
+
+no_damage_clipped:
+       {
+               RegionRec clip;
+
+               region_set(&clip, extents);
+               region_maybe_clip(&clip, gc->pCompositeClip);
+               if (!RegionNotEmpty(&clip))
+                       return true;
+
+               assert(dx + clip.extents.x1 >= 0);
+               assert(dy + clip.extents.y1 >= 0);
+               assert(dx + clip.extents.x2 <= pixmap->drawable.width);
+               assert(dy + clip.extents.y2 <= pixmap->drawable.height);
+
+               DBG(("%s: clip %d x [(%d, %d), (%d, %d)] x %d [(%d, %d)...]\n",
+                    __FUNCTION__,
+                    REGION_NUM_RECTS(&clip),
+                    clip.extents.x1, clip.extents.y1, clip.extents.x2, clip.extents.y2,
+                    n, pt->x, pt->y));
+
+               if (clip.data == NULL) {
+                       do {
+                               *(DDXPointRec *)b = *pt++;
+                               b->x2 = b->x1 + (int)*width++;
+                               b->y2 = b->y1 + 1;
+
+                               if (box_intersect(b, &clip.extents)) {
+                                       if (dx|dy) {
+                                               b->x1 += dx; b->x2 += dx;
+                                               b->y1 += dy; b->y2 += dy;
+                                       }
+                                       if (++b == last_box) {
+                                               fill.boxes(sna, &fill, box, last_box - box);
+                                               b = box;
+                                       }
+                               }
+                       } while (--n);
+               } else {
+                       const BoxRec * const clip_start = RegionBoxptr(&clip);
+                       const BoxRec * const clip_end = clip_start + clip.data->numRects;
+                       do {
+                               int16_t X1 = pt->x;
+                               int16_t y = pt->y;
+                               int16_t X2 = X1 + (int)*width;
+                               const BoxRec *c;
+
+                               pt++;
+                               width++;
+
+                               if (y < extents->y1 || extents->y2 <= y)
+                                       continue;
+
+                               if (X1 < extents->x1)
+                                       X1 = extents->x1;
+
+                               if (X2 > extents->x2)
+                                       X2 = extents->x2;
+
+                               if (X1 >= X2)
+                                       continue;
+
+                               c = find_clip_box_for_y(clip_start,
+                                                       clip_end,
+                                                       y);
+                               while (c != clip_end) {
+                                       if (y + 1 <= c->y1 || X2 <= c->x1)
+                                               break;
+
+                                       if (X1 >= c->x2) {
+                                               c++;
+                                               continue;
+                                       }
+
+                                       b->x1 = c->x1;
+                                       b->x2 = c->x2;
+                                       c++;
+
+                                       if (b->x1 < X1)
+                                               b->x1 = X1;
+                                       if (b->x2 > X2)
+                                               b->x2 = X2;
+                                       if (b->x2 <= b->x1)
+                                               continue;
+
+                                       b->x1 += dx;
+                                       b->x2 += dx;
+                                       b->y1 = y + dy;
+                                       b->y2 = b->y1 + 1;
+                                       if (++b == last_box) {
+                                               fill.boxes(sna, &fill, box, last_box - box);
+                                               b = box;
+                                       }
+                               }
+                       } while (--n);
+                       RegionUninit(&clip);
+               }
+               if (b != box)
+                       fill.boxes(sna, &fill, box, b - box);
+               goto done;
+       }
+
+damage_clipped:
+       {
+               RegionRec clip;
+
+               region_set(&clip, extents);
+               region_maybe_clip(&clip, gc->pCompositeClip);
+               if (!RegionNotEmpty(&clip))
+                       return true;
+
+               assert(dx + clip.extents.x1 >= 0);
+               assert(dy + clip.extents.y1 >= 0);
+               assert(dx + clip.extents.x2 <= pixmap->drawable.width);
+               assert(dy + clip.extents.y2 <= pixmap->drawable.height);
+
+               DBG(("%s: clip %d x [(%d, %d), (%d, %d)] x %d [(%d, %d)...]\n",
+                    __FUNCTION__,
+                    REGION_NUM_RECTS(&clip),
+                    clip.extents.x1, clip.extents.y1, clip.extents.x2, clip.extents.y2,
+                    n, pt->x, pt->y));
+
+               if (clip.data == NULL) {
+                       do {
+                               *(DDXPointRec *)b = *pt++;
+                               b->x2 = b->x1 + (int)*width++;
+                               b->y2 = b->y1 + 1;
+
+                               if (box_intersect(b, &clip.extents)) {
+                                       b->x1 += dx;
+                                       b->x2 += dx;
+                                       b->y1 += dy;
+                                       b->y2 += dy;
+                                       if (++b == last_box) {
+                                               assert_pixmap_contains_boxes(pixmap, box, b-box, 0, 0);
+                                               fill.boxes(sna, &fill, box, last_box - box);
+                                               sna_damage_add_boxes(damage, box, b - box, 0, 0);
+                                               b = box;
+                                       }
+                               }
+                       } while (--n);
+               } else {
+                       const BoxRec * const clip_start = RegionBoxptr(&clip);
+                       const BoxRec * const clip_end = clip_start + clip.data->numRects;
+                       do {
+                               int16_t X1 = pt->x;
+                               int16_t y = pt->y;
+                               int16_t X2 = X1 + (int)*width;
+                               const BoxRec *c;
+
+                               pt++;
+                               width++;
+
+                               if (y < extents->y1 || extents->y2 <= y)
+                                       continue;
+
+                               if (X1 < extents->x1)
+                                       X1 = extents->x1;
+
+                               if (X2 > extents->x2)
+                                       X2 = extents->x2;
+
+                               if (X1 >= X2)
+                                       continue;
+
+                               c = find_clip_box_for_y(clip_start,
+                                                       clip_end,
+                                                       y);
+                               while (c != clip_end) {
+                                       if (y + 1 <= c->y1 || X2 <= c->x1)
+                                               break;
+
+                                       if (X1 >= c->x2) {
+                                               c++;
+                                               continue;
+                                       }
+
+                                       b->x1 = c->x1;
+                                       b->x2 = c->x2;
+                                       c++;
+
+                                       if (b->x1 < X1)
+                                               b->x1 = X1;
+                                       if (b->x2 > X2)
+                                               b->x2 = X2;
+                                       if (b->x2 <= b->x1)
+                                               continue;
+
+                                       b->x1 += dx;
+                                       b->x2 += dx;
+                                       b->y1 = y + dy;
+                                       b->y2 = b->y1 + 1;
+                                       if (++b == last_box) {
+                                               assert_pixmap_contains_boxes(pixmap, box, last_box-box, 0, 0);
+                                               fill.boxes(sna, &fill, box, last_box - box);
+                                               sna_damage_add_boxes(damage, box, last_box - box, 0, 0);
+                                               b = box;
+                                       }
+                               }
+                       } while (--n);
+                       RegionUninit(&clip);
+               }
+               if (b != box) {
+                       assert_pixmap_contains_boxes(pixmap, box, b-box, 0, 0);
+                       fill.boxes(sna, &fill, box, b - box);
+                       sna_damage_add_boxes(damage, box, b - box, 0, 0);
+               }
+               goto done;
+       }
+
+done:
+       fill.done(sna, &fill);
+       assert_pixmap_damage(pixmap);
+       return true;
+}
+
+static bool
+sna_poly_fill_rect_tiled_blt(DrawablePtr drawable,
+                            struct kgem_bo *bo,
+                            struct sna_damage **damage,
+                            GCPtr gc, int n, xRectangle *rect,
+                            const BoxRec *extents, unsigned clipped);
+
+static bool
+sna_poly_fill_rect_stippled_blt(DrawablePtr drawable,
+                               struct kgem_bo *bo,
+                               struct sna_damage **damage,
+                               GCPtr gc, int n, xRectangle *rect,
+                               const BoxRec *extents, unsigned clipped);
+
+static inline bool
+gc_is_solid(GCPtr gc, uint32_t *color)
+{
+       if (gc->fillStyle == FillSolid ||
+           (gc->fillStyle == FillTiled && gc->tileIsPixel) ||
+           (gc->fillStyle == FillOpaqueStippled && gc->bgPixel == gc->fgPixel)) {
+               *color = gc->fillStyle == FillTiled ? gc->tile.pixel : gc->fgPixel;
+               return true;
+       }
+
+       return false;
+}
+
+static void
+sna_fill_spans__gpu(DrawablePtr drawable, GCPtr gc, int n,
+                   DDXPointPtr pt, int *width, int sorted)
+{
+       struct sna_fill_spans *data = sna_gc(gc)->priv;
+       uint32_t color;
+
+       DBG(("%s(n=%d, pt[0]=(%d, %d)+%d, sorted=%d\n",
+            __FUNCTION__, n, pt[0].x, pt[0].y, width[0], sorted));
+
+       assert(PM_IS_SOLID(drawable, gc->planemask));
+       if (n == 0)
+               return;
+
+       /* The mi routines do not attempt to keep the spans it generates
+        * within the clip, so we must run them through the clipper.
+        */
+
+       if (gc_is_solid(gc, &color)) {
+               sna_fill_spans_blt(drawable,
+                                  data->bo, NULL,
+                                  gc, color, n, pt, width, sorted,
+                                  &data->region.extents, 2);
+       } else {
+               /* Try converting these to a set of rectangles instead */
+               xRectangle *rect;
+               int i;
+
+               DBG(("%s: converting to rectagnles\n", __FUNCTION__));
+
+               rect = malloc (n * sizeof (xRectangle));
+               if (rect == NULL)
+                       return;
+
+               for (i = 0; i < n; i++) {
+                       rect[i].x = pt[i].x - drawable->x;
+                       rect[i].width = width[i];
+                       rect[i].y = pt[i].y - drawable->y;
+                       rect[i].height = 1;
+               }
+
+               if (gc->fillStyle == FillTiled) {
+                       (void)sna_poly_fill_rect_tiled_blt(drawable,
+                                                          data->bo, NULL,
+                                                          gc, n, rect,
+                                                          &data->region.extents, 2);
+               } else {
+                       (void)sna_poly_fill_rect_stippled_blt(drawable,
+                                                             data->bo, NULL,
+                                                             gc, n, rect,
+                                                             &data->region.extents, 2);
+               }
+               free (rect);
+       }
+}
+
+static unsigned
+sna_spans_extents(DrawablePtr drawable, GCPtr gc,
+                 int n, DDXPointPtr pt, int *width,
+                 BoxPtr out)
+{
+       BoxRec box;
+       bool clipped = false;
+
+       if (n == 0)
+               return 0;
+
+       box.x1 = pt->x;
+       box.x2 = box.x1 + *width;
+       box.y2 = box.y1 = pt->y;
+
+       while (--n) {
+               pt++;
+               width++;
+               if (box.x1 > pt->x)
+                       box.x1 = pt->x;
+               if (box.x2 < pt->x + *width)
+                       box.x2 = pt->x + *width;
+
+               if (box.y1 > pt->y)
+                       box.y1 = pt->y;
+               else if (box.y2 < pt->y)
+                       box.y2 = pt->y;
+       }
+       box.y2++;
+
+       if (gc)
+               clipped = clip_box(&box, gc);
+       if (box_empty(&box))
+               return 0;
+
+       *out = box;
+       return 1 | clipped << 1;
+}
+
+static void
+sna_fill_spans(DrawablePtr drawable, GCPtr gc, int n,
+              DDXPointPtr pt, int *width, int sorted)
+{
+       PixmapPtr pixmap = get_drawable_pixmap(drawable);
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+       struct sna_damage **damage;
+       struct kgem_bo *bo;
+       RegionRec region;
+       unsigned flags;
+       uint32_t color;
+
+       DBG(("%s(n=%d, pt[0]=(%d, %d)+%d, sorted=%d\n",
+            __FUNCTION__, n, pt[0].x, pt[0].y, width[0], sorted));
+
+       flags = sna_spans_extents(drawable, gc, n, pt, width, &region.extents);
+       if (flags == 0)
+               return;
+
+       DBG(("%s: extents (%d, %d), (%d, %d)\n", __FUNCTION__,
+            region.extents.x1, region.extents.y1,
+            region.extents.x2, region.extents.y2));
+
+       if (FORCE_FALLBACK)
+               goto fallback;
+
+       if (!ACCEL_FILL_SPANS)
+               goto fallback;
+
+       if (wedged(sna)) {
+               DBG(("%s: fallback -- wedged\n", __FUNCTION__));
+               goto fallback;
+       }
+
+       DBG(("%s: fillStyle=%x [%d], mask=%lx [%d]\n", __FUNCTION__,
+            gc->fillStyle, gc->fillStyle == FillSolid,
+            gc->planemask, PM_IS_SOLID(drawable, gc->planemask)));
+       if (!PM_IS_SOLID(drawable, gc->planemask))
+               goto fallback;
+
+       bo = sna_drawable_use_bo(drawable, PREFER_GPU,
+                                &region.extents, &damage);
+       if (bo) {
+               if (gc_is_solid(gc, &color)) {
+                       DBG(("%s: trying solid fill [alu=%d, pixel=%08lx] blt paths\n",
+                            __FUNCTION__, gc->alu, gc->fgPixel));
+
+                       sna_fill_spans_blt(drawable,
+                                          bo, damage,
+                                          gc, color, n, pt, width, sorted,
+                                          &region.extents, flags & 2);
+               } else {
+                       /* Try converting these to a set of rectangles instead */
+                       xRectangle *rect;
+                       int i;
+
+                       DBG(("%s: converting to rectagnles\n", __FUNCTION__));
+
+                       rect = malloc (n * sizeof (xRectangle));
+                       if (rect == NULL)
+                               return;
+
+                       for (i = 0; i < n; i++) {
+                               rect[i].x = pt[i].x - drawable->x;
+                               rect[i].width = width[i];
+                               rect[i].y = pt[i].y - drawable->y;
+                               rect[i].height = 1;
+                       }
+
+                       if (gc->fillStyle == FillTiled) {
+                               i = sna_poly_fill_rect_tiled_blt(drawable,
+                                                                bo, damage,
+                                                                gc, n, rect,
+                                                                &region.extents, flags & 2);
+                       } else {
+                               i = sna_poly_fill_rect_stippled_blt(drawable,
+                                                                   bo, damage,
+                                                                   gc, n, rect,
+                                                                   &region.extents, flags & 2);
+                       }
+                       free (rect);
+
+                       if (i)
+                               return;
+               }
+       }
+
+fallback:
+       DBG(("%s: fallback\n", __FUNCTION__));
+       region.data = NULL;
+       region_maybe_clip(&region, gc->pCompositeClip);
+       if (!RegionNotEmpty(&region))
+               return;
+
+       if (!sna_gc_move_to_cpu(gc, drawable, &region))
+               goto out;
+       if (!sna_drawable_move_region_to_cpu(drawable, &region,
+                                            drawable_gc_flags(drawable, gc, n > 1)))
+               goto out_gc;
+
+       DBG(("%s: fbFillSpans\n", __FUNCTION__));
+       fbFillSpans(drawable, gc, n, pt, width, sorted);
+       FALLBACK_FLUSH(drawable);
+out_gc:
+       sna_gc_move_to_gpu(gc);
+out:
+       RegionUninit(&region);
+}
+
+static void
+sna_set_spans(DrawablePtr drawable, GCPtr gc, char *src,
+             DDXPointPtr pt, int *width, int n, int sorted)
+{
+       RegionRec region;
+
+       if (sna_spans_extents(drawable, gc, n, pt, width, &region.extents) == 0)
+               return;
+
+       DBG(("%s: extents=(%d, %d), (%d, %d)\n", __FUNCTION__,
+            region.extents.x1, region.extents.y1,
+            region.extents.x2, region.extents.y2));
+
+       if (FORCE_FALLBACK)
+               goto fallback;
+
+       if (!ACCEL_SET_SPANS)
+               goto fallback;
+
+fallback:
+       region.data = NULL;
+       region_maybe_clip(&region, gc->pCompositeClip);
+       if (!RegionNotEmpty(&region))
+               return;
+
+       if (!sna_gc_move_to_cpu(gc, drawable, &region))
+               goto out;
+       if (!sna_drawable_move_region_to_cpu(drawable, &region,
+                                            drawable_gc_flags(drawable, gc, n > 1)))
+               goto out_gc;
+
+       DBG(("%s: fbSetSpans\n", __FUNCTION__));
+       fbSetSpans(drawable, gc, src, pt, width, n, sorted);
+       FALLBACK_FLUSH(drawable);
+out_gc:
+       sna_gc_move_to_gpu(gc);
+out:
+       RegionUninit(&region);
+}
+
+struct sna_copy_plane {
+       struct sna_damage **damage;
+       struct kgem_bo *bo;
+};
+
+static void
+sna_copy_bitmap_blt(DrawablePtr _bitmap, DrawablePtr drawable, GCPtr gc,
+                   RegionRec *region, int sx, int sy,
+                   Pixel bitplane, void *closure)
+{
+       PixmapPtr pixmap = get_drawable_pixmap(drawable);
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+       struct sna_copy_plane *arg = closure;
+       PixmapPtr bitmap = (PixmapPtr)_bitmap;
+       uint32_t br00, br13;
+       int16_t dx, dy;
+       BoxPtr box;
+       int n;
+
+       DBG(("%s: plane=%x (%d,%d),(%d,%d)x%d\n",
+            __FUNCTION__, (unsigned)bitplane, RegionNumRects(region),
+            region->extents.x1, region->extents.y1,
+            region->extents.x2, region->extents.y2));
+
+       box = RegionRects(region);
+       n = RegionNumRects(region);
+       assert(n);
+
+       get_drawable_deltas(drawable, pixmap, &dx, &dy);
+       assert_pixmap_contains_boxes(pixmap, box, n, dx, dy);
+
+       br00 = 3 << 20;
+       br13 = arg->bo->pitch;
+       if (sna->kgem.gen >= 40 && arg->bo->tiling) {
+               br00 |= BLT_DST_TILED;
+               br13 >>= 2;
+       }
+       br13 |= blt_depth(drawable->depth) << 24;
+       br13 |= copy_ROP[gc->alu] << 16;
+
+       kgem_set_mode(&sna->kgem, KGEM_BLT);
+       do {
+               int bx1 = (box->x1 + sx) & ~7;
+               int bx2 = (box->x2 + sx + 7) & ~7;
+               int bw = (bx2 - bx1)/8;
+               int bh = box->y2 - box->y1;
+               int bstride = ALIGN(bw, 2);
+               int src_stride;
+               uint8_t *dst, *src;
+               uint32_t *b;
+
+               DBG(("%s: box(%d, %d), (%d, %d), sx=(%d,%d) bx=[%d, %d]\n",
+                    __FUNCTION__,
+                    box->x1, box->y1,
+                    box->x2, box->y2,
+                    sx, sy, bx1, bx2));
+
+               src_stride = bstride*bh;
+               if (src_stride <= 128) {
+                       src_stride = ALIGN(src_stride, 8) / 4;
+                       if (!kgem_check_batch(&sna->kgem, 7+src_stride) ||
+                           !kgem_check_bo_fenced(&sna->kgem, arg->bo) ||
+                           !kgem_check_reloc(&sna->kgem, 1)) {
+                               _kgem_submit(&sna->kgem);
+                               _kgem_set_mode(&sna->kgem, KGEM_BLT);
+                       }
+
+                       b = sna->kgem.batch + sna->kgem.nbatch;
+                       b[0] = XY_MONO_SRC_COPY_IMM | (5 + src_stride) | br00;
+                       b[0] |= ((box->x1 + sx) & 7) << 17;
+                       b[1] = br13;
+                       b[2] = (box->y1 + dy) << 16 | (box->x1 + dx);
+                       b[3] = (box->y2 + dy) << 16 | (box->x2 + dx);
+                       b[4] = kgem_add_reloc(&sna->kgem, sna->kgem.nbatch + 4,
+                                             arg->bo,
+                                             I915_GEM_DOMAIN_RENDER << 16 |
+                                             I915_GEM_DOMAIN_RENDER |
+                                             KGEM_RELOC_FENCED,
+                                             0);
+                       b[5] = gc->bgPixel;
+                       b[6] = gc->fgPixel;
+
+                       sna->kgem.nbatch += 7 + src_stride;
+
+                       dst = (uint8_t *)&b[7];
+                       src_stride = bitmap->devKind;
+                       src = bitmap->devPrivate.ptr;
+                       src += (box->y1 + sy) * src_stride + bx1/8;
+                       src_stride -= bstride;
+                       do {
+                               int i = bstride;
+                               do {
+                                       *dst++ = byte_reverse(*src++);
+                                       *dst++ = byte_reverse(*src++);
+                                       i -= 2;
+                               } while (i);
+                               src += src_stride;
+                       } while (--bh);
+               } else {
+                       struct kgem_bo *upload;
+                       void *ptr;
+
+                       if (!kgem_check_batch(&sna->kgem, 8) ||
+                           !kgem_check_bo_fenced(&sna->kgem, arg->bo) ||
+                           !kgem_check_reloc_and_exec(&sna->kgem, 2)) {
+                               _kgem_submit(&sna->kgem);
+                               _kgem_set_mode(&sna->kgem, KGEM_BLT);
+                       }
+
+                       upload = kgem_create_buffer(&sna->kgem,
+                                                   bstride*bh,
+                                                   KGEM_BUFFER_WRITE_INPLACE,
+                                                   &ptr);
+                       if (!upload)
+                               break;
+
+                       b = sna->kgem.batch + sna->kgem.nbatch;
+                       b[0] = XY_MONO_SRC_COPY | br00;
+                       b[0] |= ((box->x1 + sx) & 7) << 17;
+                       b[1] = br13;
+                       b[2] = (box->y1 + dy) << 16 | (box->x1 + dx);
+                       b[3] = (box->y2 + dy) << 16 | (box->x2 + dx);
+                       b[4] = kgem_add_reloc(&sna->kgem, sna->kgem.nbatch + 4,
+                                             arg->bo,
+                                             I915_GEM_DOMAIN_RENDER << 16 |
+                                             I915_GEM_DOMAIN_RENDER |
+                                             KGEM_RELOC_FENCED,
+                                             0);
+                       b[5] = kgem_add_reloc(&sna->kgem, sna->kgem.nbatch + 5,
+                                             upload,
+                                             I915_GEM_DOMAIN_RENDER << 16 |
+                                             KGEM_RELOC_FENCED,
+                                             0);
+                       b[6] = gc->bgPixel;
+                       b[7] = gc->fgPixel;
+
+                       sna->kgem.nbatch += 8;
+
+                       dst = ptr;
+                       src_stride = bitmap->devKind;
+                       src = bitmap->devPrivate.ptr;
+                       src += (box->y1 + sy) * src_stride + bx1/8;
+                       src_stride -= bstride;
+                       do {
+                               int i = bstride;
+                               do {
+                                       *dst++ = byte_reverse(*src++);
+                                       *dst++ = byte_reverse(*src++);
+                                       i -= 2;
+                               } while (i);
+                               src += src_stride;
+                       } while (--bh);
+
+                       kgem_bo_destroy(&sna->kgem, upload);
+               }
+
+               box++;
+       } while (--n);
+
+       if (arg->damage) {
+               RegionTranslate(region, dx, dy);
+               sna_damage_add(arg->damage, region);
+       }
+       assert_pixmap_damage(pixmap);
+       sna->blt_state.fill_bo = 0;
+}
+
+static void
+sna_copy_plane_blt(DrawablePtr source, DrawablePtr drawable, GCPtr gc,
+                  RegionPtr region, int sx, int sy,
+                  Pixel bitplane, void *closure)
+{
+       PixmapPtr dst_pixmap = get_drawable_pixmap(drawable);
+       PixmapPtr src_pixmap = get_drawable_pixmap(source);
+       struct sna *sna = to_sna_from_pixmap(dst_pixmap);
+       struct sna_copy_plane *arg = closure;
+       int16_t dx, dy;
+       int bit = ffs(bitplane) - 1;
+       uint32_t br00, br13;
+       BoxPtr box = RegionRects(region);
+       int n = RegionNumRects(region);
+
+       DBG(("%s: plane=%x [%d] x%d\n", __FUNCTION__,
+            (unsigned)bitplane, bit, n));
+
+       if (n == 0)
+               return;
+
+       get_drawable_deltas(source, src_pixmap, &dx, &dy);
+       sx += dx;
+       sy += dy;
+
+       get_drawable_deltas(drawable, dst_pixmap, &dx, &dy);
+       assert_pixmap_contains_boxes(dst_pixmap, box, n, dx, dy);
+
+       br00 = XY_MONO_SRC_COPY | 3 << 20;
+       br13 = arg->bo->pitch;
+       if (sna->kgem.gen >= 40 && arg->bo->tiling) {
+               br00 |= BLT_DST_TILED;
+               br13 >>= 2;
+       }
+       br13 |= blt_depth(drawable->depth) << 24;
+       br13 |= copy_ROP[gc->alu] << 16;
+
+       kgem_set_mode(&sna->kgem, KGEM_BLT);
+       do {
+               int bx1 = (box->x1 + sx) & ~7;
+               int bx2 = (box->x2 + sx + 7) & ~7;
+               int bw = (bx2 - bx1)/8;
+               int bh = box->y2 - box->y1;
+               int bstride = ALIGN(bw, 2);
+               uint32_t *b;
+               struct kgem_bo *upload;
+               void *ptr;
+
+               DBG(("%s: box(%d, %d), (%d, %d), sx=(%d,%d) bx=[%d, %d]\n",
+                    __FUNCTION__,
+                    box->x1, box->y1,
+                    box->x2, box->y2,
+                    sx, sy, bx1, bx2));
+
+               if (!kgem_check_batch(&sna->kgem, 8) ||
+                   !kgem_check_bo_fenced(&sna->kgem, arg->bo) ||
+                   !kgem_check_reloc_and_exec(&sna->kgem, 2)) {
+                       _kgem_submit(&sna->kgem);
+                       _kgem_set_mode(&sna->kgem, KGEM_BLT);
+               }
+
+               upload = kgem_create_buffer(&sna->kgem,
+                                           bstride*bh,
+                                           KGEM_BUFFER_WRITE_INPLACE,
+                                           &ptr);
+               if (!upload)
+                       break;
+
+               switch (source->bitsPerPixel) {
+               case 32:
+                       {
+                               uint32_t *src = src_pixmap->devPrivate.ptr;
+                               uint32_t src_stride = src_pixmap->devKind/sizeof(uint32_t);
+                               uint8_t *dst = ptr;
+
+                               src += (box->y1 + sy) * src_stride;
+                               src += bx1;
+
+                               src_stride -= bw * 8;
+                               bstride -= bw;
+
+                               do {
+                                       int i = bw;
+                                       do {
+                                               uint8_t v = 0;
+
+                                               v |= ((*src++ >> bit) & 1) << 7;
+                                               v |= ((*src++ >> bit) & 1) << 6;
+                                               v |= ((*src++ >> bit) & 1) << 5;
+                                               v |= ((*src++ >> bit) & 1) << 4;
+                                               v |= ((*src++ >> bit) & 1) << 3;
+                                               v |= ((*src++ >> bit) & 1) << 2;
+                                               v |= ((*src++ >> bit) & 1) << 1;
+                                               v |= ((*src++ >> bit) & 1) << 0;
+
+                                               *dst++ = v;
+                                       } while (--i);
+                                       dst += bstride;
+                                       src += src_stride;
+                               } while (--bh);
+                               break;
+                       }
+               case 16:
+                       {
+                               uint16_t *src = src_pixmap->devPrivate.ptr;
+                               uint16_t src_stride = src_pixmap->devKind/sizeof(uint16_t);
+                               uint8_t *dst = ptr;
+
+                               src += (box->y1 + sy) * src_stride;
+                               src += bx1;
+
+                               src_stride -= bw * 8;
+                               bstride -= bw;
+
+                               do {
+                                       int i = bw;
+                                       do {
+                                               uint8_t v = 0;
+
+                                               v |= ((*src++ >> bit) & 1) << 7;
+                                               v |= ((*src++ >> bit) & 1) << 6;
+                                               v |= ((*src++ >> bit) & 1) << 5;
+                                               v |= ((*src++ >> bit) & 1) << 4;
+                                               v |= ((*src++ >> bit) & 1) << 3;
+                                               v |= ((*src++ >> bit) & 1) << 2;
+                                               v |= ((*src++ >> bit) & 1) << 1;
+                                               v |= ((*src++ >> bit) & 1) << 0;
+
+                                               *dst++ = v;
+                                       } while (--i);
+                                       dst += bstride;
+                                       src += src_stride;
+                               } while (--bh);
+                               break;
+                       }
+               case 8:
+                       {
+                               uint8_t *src = src_pixmap->devPrivate.ptr;
+                               uint8_t src_stride = src_pixmap->devKind/sizeof(uint8_t);
+                               uint8_t *dst = ptr;
+
+                               src += (box->y1 + sy) * src_stride;
+                               src += bx1;
+
+                               src_stride -= bw * 8;
+                               bstride -= bw;
+
+                               do {
+                                       int i = bw;
+                                       do {
+                                               uint8_t v = 0;
+
+                                               v |= ((*src++ >> bit) & 1) << 7;
+                                               v |= ((*src++ >> bit) & 1) << 6;
+                                               v |= ((*src++ >> bit) & 1) << 5;
+                                               v |= ((*src++ >> bit) & 1) << 4;
+                                               v |= ((*src++ >> bit) & 1) << 3;
+                                               v |= ((*src++ >> bit) & 1) << 2;
+                                               v |= ((*src++ >> bit) & 1) << 1;
+                                               v |= ((*src++ >> bit) & 1) << 0;
+
+                                               *dst++ = v;
+                                       } while (--i);
+                                       dst += bstride;
+                                       src += src_stride;
+                               } while (--bh);
+                               break;
+                       }
+               default:
+                       assert(0);
+                       return;
+               }
+
+               b = sna->kgem.batch + sna->kgem.nbatch;
+               b[0] = br00 | ((box->x1 + sx) & 7) << 17;
+               b[1] = br13;
+               b[2] = (box->y1 + dy) << 16 | (box->x1 + dx);
+               b[3] = (box->y2 + dy) << 16 | (box->x2 + dx);
+               b[4] = kgem_add_reloc(&sna->kgem, sna->kgem.nbatch + 4,
+                                     arg->bo,
+                                     I915_GEM_DOMAIN_RENDER << 16 |
+                                     I915_GEM_DOMAIN_RENDER |
+                                     KGEM_RELOC_FENCED,
+                                     0);
+               b[5] = kgem_add_reloc(&sna->kgem, sna->kgem.nbatch + 5,
+                                     upload,
+                                     I915_GEM_DOMAIN_RENDER << 16 |
+                                     KGEM_RELOC_FENCED,
+                                     0);
+               b[6] = gc->bgPixel;
+               b[7] = gc->fgPixel;
+
+               sna->kgem.nbatch += 8;
+               kgem_bo_destroy(&sna->kgem, upload);
+
+               box++;
+       } while (--n);
+
+       if (arg->damage) {
+               RegionTranslate(region, dx, dy);
+               sna_damage_add(arg->damage, region);
+       }
+       assert_pixmap_damage(dst_pixmap);
+       sna->blt_state.fill_bo = 0;
+}
+
+static RegionPtr
+sna_copy_plane(DrawablePtr src, DrawablePtr dst, GCPtr gc,
+              int src_x, int src_y,
+              int w, int h,
+              int dst_x, int dst_y,
+              unsigned long bit)
+{
+       PixmapPtr pixmap = get_drawable_pixmap(dst);
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+       RegionRec region, *ret = NULL;
+       struct sna_copy_plane arg;
+
+       DBG(("%s: src=(%d, %d), dst=(%d, %d), size=%dx%d\n", __FUNCTION__,
+            src_x, src_y, dst_x, dst_y, w, h));
+
+       if (gc->planemask == 0)
+               goto empty;
+
+       if (src->bitsPerPixel == 1 && (bit&1) == 0)
+               goto empty;
+
+       region.extents.x1 = dst_x + dst->x;
+       region.extents.y1 = dst_y + dst->y;
+       region.extents.x2 = region.extents.x1 + w;
+       region.extents.y2 = region.extents.y1 + h;
+       region.data = NULL;
+       RegionIntersect(&region, &region, gc->pCompositeClip);
+
+       DBG(("%s: dst extents (%d, %d), (%d, %d)\n",
+            __FUNCTION__,
+            region.extents.x1, region.extents.y1,
+            region.extents.x2, region.extents.y2));
+
+       {
+               RegionRec clip;
+
+               clip.extents.x1 = src->x - (src->x + src_x) + (dst->x + dst_x);
+               clip.extents.y1 = src->y - (src->y + src_y) + (dst->y + dst_y);
+               clip.extents.x2 = clip.extents.x1 + src->width;
+               clip.extents.y2 = clip.extents.y1 + src->height;
+               clip.data = NULL;
+
+               DBG(("%s: src extents (%d, %d), (%d, %d)\n",
+                    __FUNCTION__,
+                    clip.extents.x1, clip.extents.y1,
+                    clip.extents.x2, clip.extents.y2));
+
+               RegionIntersect(&region, &region, &clip);
+       }
+       DBG(("%s: dst^src extents (%d, %d), (%d, %d)\n",
+            __FUNCTION__,
+            region.extents.x1, region.extents.y1,
+            region.extents.x2, region.extents.y2));
+       if (!RegionNotEmpty(&region))
+               goto empty;
+
+       RegionTranslate(&region,
+                       src_x - dst_x - dst->x + src->x,
+                       src_y - dst_y - dst->y + src->y);
+
+       if (!sna_drawable_move_region_to_cpu(src, &region, MOVE_READ))
+               goto out;
+
+       RegionTranslate(&region,
+                       -(src_x - dst_x - dst->x + src->x),
+                       -(src_y - dst_y - dst->y + src->y));
+
+       if (FORCE_FALLBACK)
+               goto fallback;
+
+       if (!ACCEL_COPY_PLANE)
+               goto fallback;
+
+       if (wedged(sna))
+               goto fallback;
+
+       if (!PM_IS_SOLID(dst, gc->planemask))
+               goto fallback;
+
+       arg.bo = sna_drawable_use_bo(dst, PREFER_GPU,
+                                    &region.extents, &arg.damage);
+       if (arg.bo) {
+               if (arg.bo->tiling == I915_TILING_Y) {
+                       assert(arg.bo == sna_pixmap_get_bo(pixmap));
+                       arg.bo = sna_pixmap_change_tiling(pixmap, I915_TILING_X);
+                       if (arg.bo == NULL) {
+                               DBG(("%s: fallback -- unable to change tiling\n",
+                                    __FUNCTION__));
+                               goto fallback;
+                       }
+               }
+               RegionUninit(&region);
+               return sna_do_copy(src, dst, gc,
+                                  src_x, src_y,
+                                  w, h,
+                                  dst_x, dst_y,
+                                  src->depth == 1 ? sna_copy_bitmap_blt : sna_copy_plane_blt,
+                                  (Pixel)bit, &arg);
+       }
+
+fallback:
+       DBG(("%s: fallback\n", __FUNCTION__));
+       if (!sna_gc_move_to_cpu(gc, dst, &region))
+               goto out;
+       if (!sna_drawable_move_region_to_cpu(dst, &region,
+                                            drawable_gc_flags(dst, gc, false)))
+               goto out_gc;
+
+       DBG(("%s: fbCopyPlane(%d, %d, %d, %d, %d,%d) %x\n",
+            __FUNCTION__, src_x, src_y, w, h, dst_x, dst_y, (unsigned)bit));
+       ret = miDoCopy(src, dst, gc,
+                      src_x, src_y, w, h, dst_x, dst_y,
+                      src->bitsPerPixel > 1 ? fbCopyNto1 : fbCopy1toN,
+                      bit, 0);
+       FALLBACK_FLUSH(dst);
+out_gc:
+       sna_gc_move_to_gpu(gc);
+out:
+       RegionUninit(&region);
+       return ret;
+empty:
+       return miHandleExposures(src, dst, gc,
+                                src_x, src_y,
+                                w, h,
+                                dst_x, dst_y, bit);
+}
+
+static bool
+sna_poly_point_blt(DrawablePtr drawable,
+                  struct kgem_bo *bo,
+                  struct sna_damage **damage,
+                  GCPtr gc, int mode, int n, DDXPointPtr pt,
+                  bool clipped)
+{
+       PixmapPtr pixmap = get_drawable_pixmap(drawable);
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+       BoxRec box[512], *b = box, * const last_box = box + ARRAY_SIZE(box);
+       struct sna_fill_op fill;
+       DDXPointRec last;
+       int16_t dx, dy;
+
+       DBG(("%s: alu=%d, pixel=%08lx, clipped?=%d\n",
+            __FUNCTION__, gc->alu, gc->fgPixel, clipped));
+
+       if (!sna_fill_init_blt(&fill, sna, pixmap, bo, gc->alu, gc->fgPixel))
+               return false;
+
+       get_drawable_deltas(drawable, pixmap, &dx, &dy);
+
+       last.x = drawable->x;
+       last.y = drawable->y;
+
+       if (!clipped) {
+               last.x += dx;
+               last.y += dy;
+
+               assert_pixmap_contains_points(pixmap, pt, n, last.x, last.y);
+               sna_damage_add_points(damage, pt, n, last.x, last.y);
+               do {
+                       unsigned nbox = n;
+                       if (nbox > ARRAY_SIZE(box))
+                               nbox = ARRAY_SIZE(box);
+                       n -= nbox;
+                       do {
+                               *(DDXPointRec *)b = *pt++;
+
+                               b->x1 += last.x;
+                               b->y1 += last.y;
+                               if (mode == CoordModePrevious)
+                                       last = *(DDXPointRec *)b;
+
+                               b->x2 = b->x1 + 1;
+                               b->y2 = b->y1 + 1;
+                               b++;
+                       } while (--nbox);
+                       fill.boxes(sna, &fill, box, b - box);
+                       b = box;
+               } while (n);
+       } else {
+               RegionPtr clip = gc->pCompositeClip;
+
+               while (n--) {
+                       int x, y;
+
+                       x = pt->x;
+                       y = pt->y;
+                       pt++;
+                       if (mode == CoordModePrevious) {
+                               x += last.x;
+                               y += last.y;
+                               last.x = x;
+                               last.y = y;
+                       } else {
+                               x += drawable->x;
+                               y += drawable->y;
+                       }
+
+                       if (RegionContainsPoint(clip, x, y, NULL)) {
+                               b->x1 = x + dx;
+                               b->y1 = y + dy;
+                               b->x2 = b->x1 + 1;
+                               b->y2 = b->y1 + 1;
+                               if (++b == last_box){
+                                       assert_pixmap_contains_boxes(pixmap, box, last_box-box, 0, 0);
+                                       fill.boxes(sna, &fill, box, last_box - box);
+                                       if (damage)
+                                               sna_damage_add_boxes(damage, box, last_box-box, 0, 0);
+                                       b = box;
+                               }
+                       }
+               }
+               if (b != box){
+                       assert_pixmap_contains_boxes(pixmap, box, b-box, 0, 0);
+                       fill.boxes(sna, &fill, box, b - box);
+                       if (damage)
+                               sna_damage_add_boxes(damage, box, b-box, 0, 0);
+               }
+       }
+       fill.done(sna, &fill);
+       assert_pixmap_damage(pixmap);
+       return true;
+}
+
+static unsigned
+sna_poly_point_extents(DrawablePtr drawable, GCPtr gc,
+                      int mode, int n, DDXPointPtr pt, BoxPtr out)
+{
+       BoxRec box;
+       bool clipped;
+
+       if (n == 0)
+               return 0;
+
+       box.x2 = box.x1 = pt->x;
+       box.y2 = box.y1 = pt->y;
+       if (mode == CoordModePrevious) {
+               DDXPointRec last = *pt++;
+               while (--n) {
+                       last.x += pt->x;
+                       last.y += pt->y;
+                       pt++;
+                       box_add_pt(&box, last.x, last.y);
+               }
+       } else {
+               while (--n) {
+                       ++pt;
+                       box_add_pt(&box, pt->x, pt->y);
+               }
+       }
+       box.x2++;
+       box.y2++;
+
+       clipped = trim_and_translate_box(&box, drawable, gc);
+       if (box_empty(&box))
+               return 0;
+
+       *out = box;
+       return 1 | clipped << 1;
+}
+
+static void
+sna_poly_point(DrawablePtr drawable, GCPtr gc,
+              int mode, int n, DDXPointPtr pt)
+{
+       PixmapPtr pixmap = get_drawable_pixmap(drawable);
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+       RegionRec region;
+       unsigned flags;
+
+       DBG(("%s(mode=%d, n=%d, pt[0]=(%d, %d)\n",
+            __FUNCTION__, mode, n, pt[0].x, pt[0].y));
+
+       flags = sna_poly_point_extents(drawable, gc, mode, n, pt, &region.extents);
+       if (flags == 0)
+               return;
+
+       DBG(("%s: extents (%d, %d), (%d, %d), flags=%x\n", __FUNCTION__,
+            region.extents.x1, region.extents.y1,
+            region.extents.x2, region.extents.y2,
+            flags));
+
+       if (FORCE_FALLBACK)
+               goto fallback;
+
+       if (!ACCEL_POLY_POINT)
+               goto fallback;
+
+       if (wedged(sna)) {
+               DBG(("%s: fallback -- wedged\n", __FUNCTION__));
+               goto fallback;
+       }
+
+       if (PM_IS_SOLID(drawable, gc->planemask)) {
+               struct sna_damage **damage;
+               struct kgem_bo *bo;
+
+               DBG(("%s: trying solid fill [%08lx] blt paths\n",
+                    __FUNCTION__, gc->fgPixel));
+
+               if ((bo = sna_drawable_use_bo(drawable, 0,
+                                             &region.extents, &damage)) &&
+                   sna_poly_point_blt(drawable, bo, damage,
+                                      gc, mode, n, pt, flags & 2))
+                       return;
+       }
+
+fallback:
+       DBG(("%s: fallback\n", __FUNCTION__));
+       region.data = NULL;
+       region_maybe_clip(&region, gc->pCompositeClip);
+       if (!RegionNotEmpty(&region))
+               return;
+
+       if (!sna_gc_move_to_cpu(gc, drawable, &region))
+               goto out;
+       if (!sna_drawable_move_region_to_cpu(drawable, &region,
+                                            MOVE_READ | MOVE_WRITE))
+               goto out_gc;
+
+       DBG(("%s: fbPolyPoint\n", __FUNCTION__));
+       fbPolyPoint(drawable, gc, mode, n, pt, flags);
+       FALLBACK_FLUSH(drawable);
+out_gc:
+       sna_gc_move_to_gpu(gc);
+out:
+       RegionUninit(&region);
+}
+
+static bool
+sna_poly_zero_line_blt(DrawablePtr drawable,
+                      struct kgem_bo *bo,
+                      struct sna_damage **damage,
+                      GCPtr gc, int mode, const int _n, const DDXPointRec * const _pt,
+                      const BoxRec *extents, unsigned clipped)
+{
+       static void * const _jump[] = {
+               &&no_damage,
+               &&damage,
+
+               &&no_damage_offset,
+               &&damage_offset,
+       };
+
+       PixmapPtr pixmap = get_drawable_pixmap(drawable);
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+       int x2, y2, xstart, ystart, oc2;
+       unsigned int bias = miGetZeroLineBias(drawable->pScreen);
+       bool degenerate = true;
+       struct sna_fill_op fill;
+       RegionRec clip;
+       BoxRec box[512], *b, * const last_box = box + ARRAY_SIZE(box);
+       const BoxRec *last_extents;
+       int16_t dx, dy;
+       void *jump, *ret;
+
+       DBG(("%s: alu=%d, pixel=%lx, n=%d, clipped=%d, damage=%p\n",
+            __FUNCTION__, gc->alu, gc->fgPixel, _n, clipped, damage));
+       if (!sna_fill_init_blt(&fill, sna, pixmap, bo, gc->alu, gc->fgPixel))
+               return false;
+
+       get_drawable_deltas(drawable, pixmap, &dx, &dy);
+
+       region_set(&clip, extents);
+       if (clipped) {
+               region_maybe_clip(&clip, gc->pCompositeClip);
+               if (!RegionNotEmpty(&clip))
+                       return true;
+       }
+
+       jump = _jump[(damage != NULL) | !!(dx|dy) << 1];
+       DBG(("%s: [clipped=%x] extents=(%d, %d), (%d, %d), delta=(%d, %d), damage=%p\n",
+            __FUNCTION__, clipped,
+            clip.extents.x1, clip.extents.y1,
+            clip.extents.x2, clip.extents.y2,
+            dx, dy, damage));
+
+       extents = REGION_RECTS(&clip);
+       last_extents = extents + REGION_NUM_RECTS(&clip);
+
+       b = box;
+       do {
+               int n = _n;
+               const DDXPointRec *pt = _pt;
+
+               xstart = pt->x + drawable->x;
+               ystart = pt->y + drawable->y;
+
+               x2 = xstart;
+               y2 = ystart;
+               oc2 = 0;
+               OUTCODES(oc2, x2, y2, extents);
+
+               while (--n) {
+                       int16_t sdx, sdy;
+                       int adx, ady, length;
+                       int e, e1, e2, e3;
+                       int x1 = x2, x;
+                       int y1 = y2, y;
+                       int oc1 = oc2;
+                       int octant;
+
+                       ++pt;
+
+                       x2 = pt->x;
+                       y2 = pt->y;
+                       if (mode == CoordModePrevious) {
+                               x2 += x1;
+                               y2 += y1;
+                       } else {
+                               x2 += drawable->x;
+                               y2 += drawable->y;
+                       }
+                       DBG(("%s: segment (%d, %d) to (%d, %d)\n",
+                            __FUNCTION__, x1, y1, x2, y2));
+                       if (x2 == x1 && y2 == y1)
+                               continue;
+
+                       degenerate = false;
+
+                       oc2 = 0;
+                       OUTCODES(oc2, x2, y2, extents);
+                       if (oc1 & oc2)
+                               continue;
+
+                       CalcLineDeltas(x1, y1, x2, y2,
+                                      adx, ady, sdx, sdy,
+                                      1, 1, octant);
+
+                       DBG(("%s: adx=(%d, %d), sdx=(%d, %d), oc1=%x, oc2=%x\n",
+                            __FUNCTION__, adx, ady, sdx, sdy, oc1, oc2));
+                       if (adx == 0 || ady == 0) {
+                               if (x1 <= x2) {
+                                       b->x1 = x1;
+                                       b->x2 = x2;
+                               } else {
+                                       b->x1 = x2;
+                                       b->x2 = x1;
+                               }
+                               if (y1 <= y2) {
+                                       b->y1 = y1;
+                                       b->y2 = y2;
+                               } else {
+                                       b->y1 = y2;
+                                       b->y2 = y1;
+                               }
+                               b->x2++;
+                               b->y2++;
+                               if (oc1 | oc2) {
+                                       bool intersects;
+
+                                       intersects = box_intersect(b, extents);
+                                       assert(intersects);
+                               }
+                               if (++b == last_box) {
+                                       ret = &&rectangle_continue;
+                                       goto *jump;
+rectangle_continue:
+                                       b = box;
+                               }
+                       } else if (adx >= ady) {
+                               int x2_clipped = x2, y2_clipped = y2;
+                               bool dirty;
+
+                               /* X-major segment */
+                               e1 = ady << 1;
+                               e2 = e1 - (adx << 1);
+                               e  = e1 - adx;
+                               length = adx;
+
+                               FIXUP_ERROR(e, octant, bias);
+
+                               x = x1;
+                               y = y1;
+
+                               if (oc1 | oc2) {
+                                       int pt1_clipped, pt2_clipped;
+
+                                       if (miZeroClipLine(extents->x1, extents->y1,
+                                                          extents->x2-1, extents->y2-1,
+                                                          &x, &y, &x2_clipped, &y2_clipped,
+                                                          adx, ady,
+                                                          &pt1_clipped, &pt2_clipped,
+                                                          octant, bias, oc1, oc2) == -1)
+                                               continue;
+
+                                       length = abs(x2_clipped - x);
+                                       if (length == 0)
+                                               continue;
+
+                                       if (pt1_clipped) {
+                                               int clipdx = abs(x - x1);
+                                               int clipdy = abs(y - y1);
+                                               e += clipdy * e2 + (clipdx - clipdy) * e1;
+                                       }
+                               }
+
+                               e3 = e2 - e1;
+                               e  = e - e1;
+
+                               b->x1 = x;
+                               b->y1 = y;
+                               dirty = false;
+                               while (length--) {
+                                       e += e1;
+                                       dirty = true;
+                                       if (e >= 0) {
+                                               e += e3;
+
+                                               if (sdx < 0) {
+                                                       b->x2 = b->x1 + 1;
+                                                       b->x1 = x;
+                                               } else
+                                                       b->x2 = x + 1;
+                                               b->y2 = b->y1 + 1;
+
+                                               if (++b == last_box) {
+                                                       ret = &&X_continue;
+                                                       goto *jump;
+X_continue:
+                                                       b = box;
+                                               }
+
+                                               b->x1 = x + sdx;
+                                               b->y1 = y += sdy;
+                                               dirty = false;
+                                       }
+                                       x += sdx;
+                               }
+                               if (dirty) {
+                                       x -= sdx;
+                                       if (sdx < 0) {
+                                               b->x2 = b->x1 + 1;
+                                               b->x1 = x;
+                                       } else
+                                               b->x2 = x + 1;
+                                       b->y2 = b->y1 + 1;
+
+                                       if (++b == last_box) {
+                                               ret = &&X2_continue;
+                                               goto *jump;
+X2_continue:
+                                               b = box;
+                                       }
+                               }
+                       } else {
+                               int x2_clipped = x2, y2_clipped = y2;
+                               bool dirty;
+
+                               /* Y-major segment */
+                               e1 = adx << 1;
+                               e2 = e1 - (ady << 1);
+                               e  = e1 - ady;
+                               length  = ady;
+
+                               SetYMajorOctant(octant);
+                               FIXUP_ERROR(e, octant, bias);
+
+                               x = x1;
+                               y = y1;
+
+                               if (oc1 | oc2) {
+                                       int pt1_clipped, pt2_clipped;
+
+                                       if (miZeroClipLine(extents->x1, extents->y1,
+                                                          extents->x2-1, extents->y2-1,
+                                                          &x, &y, &x2_clipped, &y2_clipped,
+                                                          adx, ady,
+                                                          &pt1_clipped, &pt2_clipped,
+                                                          octant, bias, oc1, oc2) == -1)
+                                               continue;
+
+                                       length = abs(y2_clipped - y);
+                                       if (length == 0)
+                                               continue;
+
+                                       if (pt1_clipped) {
+                                               int clipdx = abs(x - x1);
+                                               int clipdy = abs(y - y1);
+                                               e += clipdx * e2 + (clipdy - clipdx) * e1;
+                                       }
+                               }
+
+                               e3 = e2 - e1;
+                               e  = e - e1;
+
+                               b->x1 = x;
+                               b->y1 = y;
+                               dirty = false;
+                               while (length--) {
+                                       e += e1;
+                                       dirty = true;
+                                       if (e >= 0) {
+                                               e += e3;
+
+                                               if (sdy < 0) {
+                                                       b->y2 = b->y1 + 1;
+                                                       b->y1 = y;
+                                               } else
+                                                       b->y2 = y + 1;
+                                               b->x2 = x + 1;
+
+                                               if (++b == last_box) {
+                                                       ret = &&Y_continue;
+                                                       goto *jump;
+Y_continue:
+                                                       b = box;
+                                               }
+
+                                               b->x1 = x += sdx;
+                                               b->y1 = y + sdy;
+                                               dirty = false;
+                                       }
+                                       y += sdy;
+                               }
+
+                               if (dirty) {
+                                       y -= sdy;
+                                       if (sdy < 0) {
+                                               b->y2 = b->y1 + 1;
+                                               b->y1 = y;
+                                       } else
+                                               b->y2 = y + 1;
+                                       b->x2 = x + 1;
+
+                                       if (++b == last_box) {
+                                               ret = &&Y2_continue;
+                                               goto *jump;
+Y2_continue:
+                                               b = box;
+                                       }
+                               }
+                       }
+               }
+
+#if 0
+               /* Only do the CapNotLast check on the last segment
+                * and only if the endpoint wasn't clipped.  And then, if the last
+                * point is the same as the first point, do not draw it, unless the
+                * line is degenerate
+                */
+               if (!pt2_clipped &&
+                   gc->capStyle != CapNotLast &&
+                   !(xstart == x2 && ystart == y2 && !degenerate))
+               {
+                       b->x2 = x2;
+                       b->y2 = y2;
+                       if (b->x2 < b->x1) {
+                               int16_t t = b->x1;
+                               b->x1 = b->x2;
+                               b->x2 = t;
+                       }
+                       if (b->y2 < b->y1) {
+                               int16_t t = b->y1;
+                               b->y1 = b->y2;
+                               b->y2 = t;
+                       }
+                       b->x2++;
+                       b->y2++;
+                       b++;
+               }
+#endif
+       } while (++extents != last_extents);
+
+       if (b != box) {
+               ret = &&done;
+               goto *jump;
+       }
+
+done:
+       fill.done(sna, &fill);
+       assert_pixmap_damage(pixmap);
+       RegionUninit(&clip);
+       return true;
+
+damage:
+       assert_pixmap_contains_boxes(pixmap, box, b-box, 0, 0);
+       sna_damage_add_boxes(damage, box, b-box, 0, 0);
+no_damage:
+       fill.boxes(sna, &fill, box, b-box);
+       goto *ret;
+
+no_damage_offset:
+       {
+               BoxRec *bb = box;
+               do {
+                       bb->x1 += dx;
+                       bb->x2 += dx;
+                       bb->y1 += dy;
+                       bb->y2 += dy;
+               } while (++bb != b);
+               assert_pixmap_contains_boxes(pixmap, box, b-box, 0, 0);
+               fill.boxes(sna, &fill, box, b - box);
+       }
+       goto *ret;
+
+damage_offset:
+       {
+               BoxRec *bb = box;
+               do {
+                       bb->x1 += dx;
+                       bb->x2 += dx;
+                       bb->y1 += dy;
+                       bb->y2 += dy;
+               } while (++bb != b);
+               assert_pixmap_contains_boxes(pixmap, box, b-box, 0, 0);
+               fill.boxes(sna, &fill, box, b - box);
+               sna_damage_add_boxes(damage, box, b - box, 0, 0);
+       }
+       goto *ret;
+}
+
+static bool
+sna_poly_line_blt(DrawablePtr drawable,
+                 struct kgem_bo *bo,
+                 struct sna_damage **damage,
+                 GCPtr gc, uint32_t pixel,
+                 int mode, int n, DDXPointPtr pt,
+                 const BoxRec *extents, bool clipped)
+{
+       PixmapPtr pixmap = get_drawable_pixmap(drawable);
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+       BoxRec boxes[512], *b = boxes, * const last_box = boxes + ARRAY_SIZE(boxes);
+       struct sna_fill_op fill;
+       DDXPointRec last;
+       int16_t dx, dy;
+
+       DBG(("%s: alu=%d, fg=%08x\n", __FUNCTION__, gc->alu, (unsigned)pixel));
+
+       if (!sna_fill_init_blt(&fill, sna, pixmap, bo, gc->alu, pixel))
+               return false;
+
+       get_drawable_deltas(drawable, pixmap, &dx, &dy);
+
+       if (!clipped) {
+               dx += drawable->x;
+               dy += drawable->y;
+
+               last.x = pt->x + dx;
+               last.y = pt->y + dy;
+               pt++;
+
+               while (--n) {
+                       DDXPointRec p;
+
+                       p = *pt++;
+                       if (mode == CoordModePrevious) {
+                               p.x += last.x;
+                               p.y += last.y;
+                       } else {
+                               p.x += dx;
+                               p.y += dy;
+                       }
+                       if (last.x == p.x) {
+                               b->x1 = last.x;
+                               b->x2 = last.x + 1;
+                       } else if (last.x < p.x) {
+                               b->x1 = last.x;
+                               b->x2 = p.x;
+                       } else {
+                               b->x1 = p.x;
+                               b->x2 = last.x;
+                       }
+                       if (last.y == p.y) {
+                               b->y1 = last.y;
+                               b->y2 = last.y + 1;
+                       } else if (last.y < p.y) {
+                               b->y1 = last.y;
+                               b->y2 = p.y;
+                       } else {
+                               b->y1 = p.y;
+                               b->y2 = last.y;
+                       }
+                       DBG(("%s: blt (%d, %d), (%d, %d)\n",
+                            __FUNCTION__,
+                            b->x1, b->y1, b->x2, b->y2));
+                       if (++b == last_box) {
+                               assert_pixmap_contains_boxes(pixmap, boxes, last_box-boxes, 0, 0);
+                               fill.boxes(sna, &fill, boxes, last_box - boxes);
+                               if (damage)
+                                       sna_damage_add_boxes(damage, boxes, last_box - boxes, 0, 0);
+                               b = boxes;
+                       }
+
+                       last = p;
+               }
+       } else {
+               RegionRec clip;
+
+               region_set(&clip, extents);
+               region_maybe_clip(&clip, gc->pCompositeClip);
+               if (!RegionNotEmpty(&clip))
+                       return true;
+
+               last.x = pt->x + drawable->x;
+               last.y = pt->y + drawable->y;
+               pt++;
+
+               if (clip.data == NULL) {
+                       while (--n) {
+                               DDXPointRec p;
+
+                               p = *pt++;
+                               if (mode == CoordModePrevious) {
+                                       p.x += last.x;
+                                       p.y += last.y;
+                               } else {
+                                       p.x += drawable->x;
+                                       p.y += drawable->y;
+                               }
+                               if (last.x == p.x) {
+                                       b->x1 = last.x;
+                                       b->x2 = last.x + 1;
+                               } else if (last.x < p.x) {
+                                       b->x1 = last.x;
+                                       b->x2 = p.x;
+                               } else {
+                                       b->x1 = p.x;
+                                       b->x2 = last.x;
+                               }
+                               if (last.y == p.y) {
+                                       b->y1 = last.y;
+                                       b->y2 = last.y + 1;
+                               } else if (last.y < p.y) {
+                                       b->y1 = last.y;
+                                       b->y2 = p.y;
+                               } else {
+                                       b->y1 = p.y;
+                                       b->y2 = last.y;
+                               }
+                               DBG(("%s: blt (%d, %d), (%d, %d)\n",
+                                    __FUNCTION__,
+                                    b->x1, b->y1, b->x2, b->y2));
+                               if (box_intersect(b, &clip.extents)) {
+                                       b->x1 += dx;
+                                       b->x2 += dx;
+                                       b->y1 += dy;
+                                       b->y2 += dy;
+                                       if (++b == last_box) {
+                                               assert_pixmap_contains_boxes(pixmap, boxes, last_box-boxes, 0, 0);
+                                               fill.boxes(sna, &fill, boxes, last_box - boxes);
+                                               if (damage)
+                                                       sna_damage_add_boxes(damage, boxes, last_box - boxes, 0, 0);
+                                               b = boxes;
+                                       }
+                               }
+
+                               last = p;
+                       }
+               } else {
+                       const BoxRec * const clip_start = RegionBoxptr(&clip);
+                       const BoxRec * const clip_end = clip_start + clip.data->numRects;
+                       const BoxRec *c;
+
+                       while (--n) {
+                               DDXPointRec p;
+                               BoxRec box;
+
+                               p = *pt++;
+                               if (mode == CoordModePrevious) {
+                                       p.x += last.x;
+                                       p.y += last.y;
+                               } else {
+                                       p.x += drawable->x;
+                                       p.y += drawable->y;
+                               }
+                               if (last.x == p.x) {
+                                       box.x1 = last.x;
+                                       box.x2 = last.x + 1;
+                               } else if (last.x < p.x) {
+                                       box.x1 = last.x;
+                                       box.x2 = p.x;
+                               } else {
+                                       box.x1 = p.x;
+                                       box.x2 = last.x;
+                               }
+                               if (last.y == p.y) {
+                                       box.y1 = last.y;
+                                       box.y2 = last.y + 1;
+                               } else if (last.y < p.y) {
+                                       box.y1 = last.y;
+                                       box.y2 = p.y;
+                               } else {
+                                       box.y1 = p.y;
+                                       box.y2 = last.y;
+                               }
+                               DBG(("%s: blt (%d, %d), (%d, %d)\n",
+                                    __FUNCTION__,
+                                    box.x1, box.y1, box.x2, box.y2));
+
+                               c = find_clip_box_for_y(clip_start,
+                                                       clip_end,
+                                                       box.y1);
+                               while (c != clip_end) {
+                                       if (box.y2 <= c->y1)
+                                               break;
+
+                                       *b = box;
+                                       if (box_intersect(b, c++)) {
+                                               b->x1 += dx;
+                                               b->x2 += dx;
+                                               b->y1 += dy;
+                                               b->y2 += dy;
+                                               if (++b == last_box) {
+                                                       assert_pixmap_contains_boxes(pixmap, boxes, last_box-boxes, 0, 0);
+                                                       fill.boxes(sna, &fill, boxes, last_box-boxes);
+                                                       if (damage)
+                                                               sna_damage_add_boxes(damage, boxes, last_box-boxes, 0, 0);
+                                                       b = boxes;
+                                               }
+                                       }
+                               }
+
+                               last = p;
+                       }
+               }
+               RegionUninit(&clip);
+       }
+       if (b != boxes) {
+               assert_pixmap_contains_boxes(pixmap, boxes, b-boxes, 0, 0);
+               fill.boxes(sna, &fill, boxes, b - boxes);
+               if (damage)
+                       sna_damage_add_boxes(damage, boxes, b - boxes, 0, 0);
+       }
+       fill.done(sna, &fill);
+       assert_pixmap_damage(pixmap);
+       return true;
+}
+
+static unsigned
+sna_poly_line_extents(DrawablePtr drawable, GCPtr gc,
+                     int mode, int n, DDXPointPtr pt,
+                     BoxPtr out)
+{
+       BoxRec box;
+       bool clip, blt = true;
+
+       if (n == 0)
+               return 0;
+
+       box.x2 = box.x1 = pt->x;
+       box.y2 = box.y1 = pt->y;
+       if (mode == CoordModePrevious) {
+               int x = box.x1;
+               int y = box.y1;
+               while (--n) {
+                       pt++;
+                       x += pt->x;
+                       y += pt->y;
+                       if (blt)
+                               blt &= pt->x == 0 || pt->y == 0;
+                       box_add_pt(&box, x, y);
+               }
+       } else {
+               int x = box.x1;
+               int y = box.y1;
+               while (--n) {
+                       pt++;
+                       if (blt) {
+                               blt &= pt->x == x || pt->y == y;
+                               x = pt->x;
+                               y = pt->y;
+                       }
+                       box_add_pt(&box, pt->x, pt->y);
+               }
+       }
+       box.x2++;
+       box.y2++;
+
+       if (gc->lineWidth) {
+               int extra = gc->lineWidth >> 1;
+               if (n > 1) {
+                       if (gc->joinStyle == JoinMiter)
+                               extra = 6 * gc->lineWidth;
+                       else if (gc->capStyle == CapProjecting)
+                               extra = gc->lineWidth;
+               }
+               if (extra) {
+                       box.x1 -= extra;
+                       box.x2 += extra;
+                       box.y1 -= extra;
+                       box.y2 += extra;
+               }
+       }
+
+       clip = trim_and_translate_box(&box, drawable, gc);
+       if (box_empty(&box))
+               return 0;
+
+       *out = box;
+       return 1 | blt << 2 | clip << 1;
+}
+
+/* Only use our spans code if the destination is busy and we can't perform
+ * the operation in place.
+ *
+ * Currently it looks to be faster to use the GPU for zero spans on all
+ * platforms.
+ */
+inline static int
+_use_zero_spans(DrawablePtr drawable, GCPtr gc, const BoxRec *extents)
+{
+       if (USE_ZERO_SPANS)
+               return USE_ZERO_SPANS > 0;
+
+       return !drawable_gc_inplace_hint(drawable, gc);
+}
+
+static int
+use_zero_spans(DrawablePtr drawable, GCPtr gc, const BoxRec *extents)
+{
+       bool ret = _use_zero_spans(drawable, gc, extents);
+       DBG(("%s? %d\n", __FUNCTION__, ret));
+       return ret;
+}
+
+/* Only use our spans code if the destination is busy and we can't perform
+ * the operation in place.
+ *
+ * Currently it looks to be faster to use the CPU for wide spans on all
+ * platforms, slow MI code. But that does not take into account the true
+ * cost of readback?
+ */
+inline static int
+_use_wide_spans(DrawablePtr drawable, GCPtr gc, const BoxRec *extents)
+{
+       if (USE_WIDE_SPANS)
+               return USE_WIDE_SPANS > 0;
+
+       return !drawable_gc_inplace_hint(drawable, gc);
+}
+
+static int
+use_wide_spans(DrawablePtr drawable, GCPtr gc, const BoxRec *extents)
+{
+       int ret = _use_wide_spans(drawable, gc, extents);
+       DBG(("%s? %d\n", __FUNCTION__, ret));
+       return ret;
+}
+
+static void
+sna_poly_line(DrawablePtr drawable, GCPtr gc,
+             int mode, int n, DDXPointPtr pt)
+{
+       struct sna_pixmap *priv;
+       struct sna_fill_spans data;
+       uint32_t color;
+
+       DBG(("%s(mode=%d, n=%d, pt[0]=(%d, %d), lineWidth=%d\n",
+            __FUNCTION__, mode, n, pt[0].x, pt[0].y, gc->lineWidth));
+
+       data.flags = sna_poly_line_extents(drawable, gc, mode, n, pt,
+                                          &data.region.extents);
+       if (data.flags == 0)
+               return;
+
+       DBG(("%s: extents (%d, %d), (%d, %d)\n", __FUNCTION__,
+            data.region.extents.x1, data.region.extents.y1,
+            data.region.extents.x2, data.region.extents.y2));
+
+       data.region.data = NULL;
+
+       if (FORCE_FALLBACK)
+               goto fallback;
+
+       if (!ACCEL_POLY_LINE)
+               goto fallback;
+
+       data.pixmap = get_drawable_pixmap(drawable);
+       data.sna = to_sna_from_pixmap(data.pixmap);
+       if (wedged(data.sna)) {
+               DBG(("%s: fallback -- wedged\n", __FUNCTION__));
+               goto fallback;
+       }
+
+       DBG(("%s: fill=%d [%d], line=%d [%d], width=%d, mask=%lu [%d], rectlinear=%d\n",
+            __FUNCTION__,
+            gc->fillStyle, gc->fillStyle == FillSolid,
+            gc->lineStyle, gc->lineStyle == LineSolid,
+            gc->lineWidth,
+            gc->planemask, PM_IS_SOLID(drawable, gc->planemask),
+            data.flags & 4));
+
+       if (!PM_IS_SOLID(drawable, gc->planemask))
+               goto fallback;
+
+       priv = sna_pixmap(data.pixmap);
+       if (!priv) {
+               DBG(("%s: not attached to pixmap %ld\n",
+                    __FUNCTION__, data.pixmap->drawable.serialNumber));
+               goto fallback;
+       }
+
+       if (gc->lineStyle != LineSolid) {
+               DBG(("%s: lineStyle, %d, is not solid\n",
+                    __FUNCTION__, gc->lineStyle));
+               goto spans_fallback;
+       }
+       if (!(gc->lineWidth == 0 ||
+             (gc->lineWidth == 1 && (n == 1 || gc->alu == GXcopy)))) {
+               DBG(("%s: non-zero lineWidth %d\n",
+                    __FUNCTION__, gc->lineWidth));
+               goto spans_fallback;
+       }
+
+       if (gc_is_solid(gc, &color)) {
+               DBG(("%s: trying solid fill [%08x]\n",
+                    __FUNCTION__, (unsigned)color));
+
+               if (data.flags & 4) {
+                       data.bo = sna_drawable_use_bo(drawable, PREFER_GPU,
+                                                     &data.region.extents,
+                                                     &data.damage);
+                       if (data.bo &&
+                           sna_poly_line_blt(drawable,
+                                             data.bo, data.damage,
+                                             gc, color, mode, n, pt,
+                                             &data.region.extents,
+                                             data.flags & 2))
+                               return;
+               } else { /* !rectilinear */
+                       if ((data.bo = sna_drawable_use_bo(drawable,
+                                                          use_zero_spans(drawable, gc, &data.region.extents),
+                                                          &data.region.extents,
+                                                          &data.damage)) &&
+                           sna_poly_zero_line_blt(drawable,
+                                                  data.bo, data.damage,
+                                                  gc, mode, n, pt,
+                                                  &data.region.extents,
+                                                  data.flags & 2))
+                               return;
+
+               }
+       } else if (data.flags & 4) {
+               /* Try converting these to a set of rectangles instead */
+               data.bo = sna_drawable_use_bo(drawable, PREFER_GPU,
+                                             &data.region.extents, &data.damage);
+               if (data.bo) {
+                       DDXPointRec p1, p2;
+                       xRectangle *rect;
+                       int i;
+
+                       DBG(("%s: converting to rectagnles\n", __FUNCTION__));
+
+                       rect = malloc (n * sizeof (xRectangle));
+                       if (rect == NULL)
+                               return;
+
+                       p1 = pt[0];
+                       for (i = 1; i < n; i++) {
+                               if (mode == CoordModePrevious) {
+                                       p2.x = p1.x + pt[i].x;
+                                       p2.y = p1.y + pt[i].y;
+                               } else
+                                       p2 = pt[i];
+                               if (p1.x < p2.x) {
+                                       rect[i].x = p1.x;
+                                       rect[i].width = p2.x - p1.x + 1;
+                               } else if (p1.x > p2.x) {
+                                       rect[i].x = p2.x;
+                                       rect[i].width = p1.x - p2.x + 1;
+                               } else {
+                                       rect[i].x = p1.x;
+                                       rect[i].width = 1;
+                               }
+                               if (p1.y < p2.y) {
+                                       rect[i].y = p1.y;
+                                       rect[i].height = p2.y - p1.y + 1;
+                               } else if (p1.y > p2.y) {
+                                       rect[i].y = p2.y;
+                                       rect[i].height = p1.y - p2.y + 1;
+                               } else {
+                                       rect[i].y = p1.y;
+                                       rect[i].height = 1;
+                               }
+
+                               /* don't paint last pixel */
+                               if (gc->capStyle == CapNotLast) {
+                                       if (p1.x == p2.x)
+                                               rect[i].height--;
+                                       else
+                                               rect[i].width--;
+                               }
+                               p1 = p2;
+                       }
+
+                       if (gc->fillStyle == FillTiled) {
+                               i = sna_poly_fill_rect_tiled_blt(drawable,
+                                                                data.bo, data.damage,
+                                                                gc, n - 1, rect + 1,
+                                                                &data.region.extents,
+                                                                data.flags & 2);
+                       } else {
+                               i = sna_poly_fill_rect_stippled_blt(drawable,
+                                                                   data.bo, data.damage,
+                                                                   gc, n - 1, rect + 1,
+                                                                   &data.region.extents,
+                                                                   data.flags & 2);
+                       }
+                       free (rect);
+
+                       if (i)
+                               return;
+               }
+       }
+
+spans_fallback:
+       if ((data.bo = sna_drawable_use_bo(drawable,
+                                          use_wide_spans(drawable, gc, &data.region.extents),
+                                          &data.region.extents, &data.damage))) {
+               DBG(("%s: converting line into spans\n", __FUNCTION__));
+               get_drawable_deltas(drawable, data.pixmap, &data.dx, &data.dy);
+               sna_gc(gc)->priv = &data;
+
+               if (gc->lineWidth == 0 && gc_is_solid(gc, &color)) {
+                       struct sna_fill_op fill;
+
+                       if (gc->lineStyle == LineSolid) {
+                               if (!sna_fill_init_blt(&fill,
+                                                      data.sna, data.pixmap,
+                                                      data.bo, gc->alu, color))
+                                       goto fallback;
+
+                               data.op = &fill;
+
+                               if ((data.flags & 2) == 0) {
+                                       if (data.dx | data.dy)
+                                               sna_gc_ops__tmp.FillSpans = sna_fill_spans__fill_offset;
+                                       else
+                                               sna_gc_ops__tmp.FillSpans = sna_fill_spans__fill;
+                               } else {
+                                       region_maybe_clip(&data.region,
+                                                         gc->pCompositeClip);
+                                       if (!RegionNotEmpty(&data.region))
+                                               return;
+
+                                       if (region_is_singular(&data.region))
+                                               sna_gc_ops__tmp.FillSpans = sna_fill_spans__fill_clip_extents;
+                                       else
+                                               sna_gc_ops__tmp.FillSpans = sna_fill_spans__fill_clip_boxes;
+                               }
+                               assert(gc->miTranslate);
+
+                               gc->ops = &sna_gc_ops__tmp;
+                               DBG(("%s: miZeroLine (solid fill)\n", __FUNCTION__));
+                               miZeroLine(drawable, gc, mode, n, pt);
+                               fill.done(data.sna, &fill);
+                       } else {
+                               data.op = &fill;
+
+                               if ((data.flags & 2) == 0) {
+                                       if (data.dx | data.dy)
+                                               sna_gc_ops__tmp.FillSpans = sna_fill_spans__dash_offset;
+                                       else
+                                               sna_gc_ops__tmp.FillSpans = sna_fill_spans__dash;
+                               } else {
+                                       region_maybe_clip(&data.region,
+                                                         gc->pCompositeClip);
+                                       if (!RegionNotEmpty(&data.region))
+                                               return;
+
+                                       if (region_is_singular(&data.region))
+                                               sna_gc_ops__tmp.FillSpans = sna_fill_spans__dash_clip_extents;
+                                       else
+                                               sna_gc_ops__tmp.FillSpans = sna_fill_spans__dash_clip_boxes;
+                               }
+                               assert(gc->miTranslate);
+
+                               DBG(("%s: miZeroLine (solid dash)\n", __FUNCTION__));
+                               if (!sna_fill_init_blt(&fill,
+                                                      data.sna, data.pixmap,
+                                                      data.bo, gc->alu, color))
+                                       goto fallback;
+
+                               gc->ops = &sna_gc_ops__tmp;
+                               miZeroDashLine(drawable, gc, mode, n, pt);
+                               fill.done(data.sna, &fill);
+
+                               if (sna_fill_init_blt(&fill,
+                                                      data.sna, data.pixmap,
+                                                      data.bo, gc->alu,
+                                                      gc->bgPixel)) {
+                                       miZeroDashLine(drawable, gc, mode, n, pt);
+                                       fill.done(data.sna, &fill);
+                               }
+                       }
+               } else {
+                       /* Note that the WideDash functions alternate
+                        * between filling using fgPixel and bgPixel
+                        * so we need to reset state between FillSpans and
+                        * cannot use the fill fast paths.
+                        */
+                       sna_gc_ops__tmp.FillSpans = sna_fill_spans__gpu;
+                       gc->ops = &sna_gc_ops__tmp;
+
+                       switch (gc->lineStyle) {
+                       default:
+                               assert(0);
+                       case LineSolid:
+                               if (gc->lineWidth == 0) {
+                                       DBG(("%s: miZeroLine\n", __FUNCTION__));
+                                       miZeroLine(drawable, gc, mode, n, pt);
+                               } else {
+                                       DBG(("%s: miWideLine\n", __FUNCTION__));
+                                       miWideLine(drawable, gc, mode, n, pt);
+                               }
+                               break;
+                       case LineOnOffDash:
+                       case LineDoubleDash:
+                               if (gc->lineWidth == 0) {
+                                       DBG(("%s: miZeroDashLine\n", __FUNCTION__));
+                                       miZeroDashLine(drawable, gc, mode, n, pt);
+                               } else {
+                                       DBG(("%s: miWideDash\n", __FUNCTION__));
+                                       miWideDash(drawable, gc, mode, n, pt);
+                               }
+                               break;
+                       }
+               }
+
+               gc->ops = (GCOps *)&sna_gc_ops;
+               if (data.damage) {
+                       if (data.dx | data.dy)
+                               pixman_region_translate(&data.region, data.dx, data.dy);
+                       assert_pixmap_contains_box(data.pixmap, &data.region.extents);
+                       sna_damage_add(data.damage, &data.region);
+                       assert_pixmap_damage(data.pixmap);
+               }
+               RegionUninit(&data.region);
+               return;
+       }
+
+fallback:
+       DBG(("%s: fallback\n", __FUNCTION__));
+       region_maybe_clip(&data.region, gc->pCompositeClip);
+       if (!RegionNotEmpty(&data.region))
+               return;
+
+       if (!sna_gc_move_to_cpu(gc, drawable, &data.region))
+               goto out;
+       if (!sna_drawable_move_region_to_cpu(drawable, &data.region,
+                                            drawable_gc_flags(drawable, gc,
+                                                              !(data.flags & 4 && n == 2))))
+               goto out_gc;
+
+       DBG(("%s: fbPolyLine\n", __FUNCTION__));
+       fbPolyLine(drawable, gc, mode, n, pt);
+       FALLBACK_FLUSH(drawable);
+
+out_gc:
+       sna_gc_move_to_gpu(gc);
+out:
+       RegionUninit(&data.region);
+}
+
+static inline void box_from_seg(BoxPtr b, xSegment *seg, GCPtr gc)
+{
+       if (seg->x1 == seg->x2) {
+               if (seg->y1 > seg->y2) {
+                       b->y2 = seg->y1 + 1;
+                       b->y1 = seg->y2 + 1;
+                       if (gc->capStyle != CapNotLast)
+                               b->y1--;
+               } else {
+                       b->y1 = seg->y1;
+                       b->y2 = seg->y2;
+                       if (gc->capStyle != CapNotLast)
+                               b->y2++;
+               }
+               b->x1 = seg->x1;
+               b->x2 = seg->x1 + 1;
+       } else {
+               if (seg->x1 > seg->x2) {
+                       b->x2 = seg->x1 + 1;
+                       b->x1 = seg->x2 + 1;
+                       if (gc->capStyle != CapNotLast)
+                               b->x1--;
+               } else {
+                       b->x1 = seg->x1;
+                       b->x2 = seg->x2;
+                       if (gc->capStyle != CapNotLast)
+                               b->x2++;
+               }
+               b->y1 = seg->y1;
+               b->y2 = seg->y1 + 1;
+       }
+
+       DBG(("%s: seg=(%d,%d),(%d,%d); box=(%d,%d),(%d,%d)\n",
+            __FUNCTION__,
+            seg->x1, seg->y1, seg->x2, seg->y2,
+            b->x1, b->y1, b->x2, b->y2));
+}
+
+static bool
+sna_poly_segment_blt(DrawablePtr drawable,
+                    struct kgem_bo *bo,
+                    struct sna_damage **damage,
+                    GCPtr gc, uint32_t pixel,
+                    int n, xSegment *seg,
+                    const BoxRec *extents, unsigned clipped)
+{
+       PixmapPtr pixmap = get_drawable_pixmap(drawable);
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+       BoxRec boxes[512], *b = boxes, * const last_box = boxes + ARRAY_SIZE(boxes);
+       struct sna_fill_op fill;
+       int16_t dx, dy;
+
+       DBG(("%s: n=%d, alu=%d, fg=%08lx, clipped=%d\n",
+            __FUNCTION__, n, gc->alu, gc->fgPixel, clipped));
+
+       if (!sna_fill_init_blt(&fill, sna, pixmap, bo, gc->alu, pixel))
+               return false;
+
+       get_drawable_deltas(drawable, pixmap, &dx, &dy);
+
+       if (!clipped) {
+               dx += drawable->x;
+               dy += drawable->y;
+               if (dx|dy) {
+                       do {
+                               unsigned nbox = n;
+                               if (nbox > ARRAY_SIZE(boxes))
+                                       nbox = ARRAY_SIZE(boxes);
+                               n -= nbox;
+                               do {
+                                       box_from_seg(b, seg++, gc);
+                                       if (b->y2 > b->y1 && b->x2 > b->x1) {
+                                               b->x1 += dx;
+                                               b->x2 += dx;
+                                               b->y1 += dy;
+                                               b->y2 += dy;
+                                               b++;
+                                       }
+                               } while (--nbox);
+
+                               if (b != boxes) {
+                                       fill.boxes(sna, &fill, boxes, b-boxes);
+                                       if (damage)
+                                               sna_damage_add_boxes(damage, boxes, b-boxes, 0, 0);
+                                       b = boxes;
+                               }
+                       } while (n);
+               } else {
+                       do {
+                               unsigned nbox = n;
+                               if (nbox > ARRAY_SIZE(boxes))
+                                       nbox = ARRAY_SIZE(boxes);
+                               n -= nbox;
+                               do {
+                                       box_from_seg(b++, seg++, gc);
+                               } while (--nbox);
+
+                               if (b != boxes) {
+                                       fill.boxes(sna, &fill, boxes, b-boxes);
+                                       if (damage)
+                                               sna_damage_add_boxes(damage, boxes, b-boxes, 0, 0);
+                                       b = boxes;
+                               }
+                       } while (n);
+               }
+       } else {
+               RegionRec clip;
+
+               region_set(&clip, extents);
+               region_maybe_clip(&clip, gc->pCompositeClip);
+               if (!RegionNotEmpty(&clip))
+                       goto done;
+
+               if (clip.data) {
+                       const BoxRec * const clip_start = RegionBoxptr(&clip);
+                       const BoxRec * const clip_end = clip_start + clip.data->numRects;
+                       const BoxRec *c;
+                       do {
+                               BoxRec box;
+
+                               box_from_seg(&box, seg++, gc);
+                               box.x1 += drawable->x;
+                               box.x2 += drawable->x;
+                               box.y1 += drawable->y;
+                               box.y2 += drawable->y;
+                               c = find_clip_box_for_y(clip_start,
+                                                       clip_end,
+                                                       box.y1);
+                               while (c != clip_end) {
+                                       if (box.y2 <= c->y1)
+                                               break;
+
+                                       *b = box;
+                                       if (box_intersect(b, c++)) {
+                                               b->x1 += dx;
+                                               b->x2 += dx;
+                                               b->y1 += dy;
+                                               b->y2 += dy;
+                                               if (++b == last_box) {
+                                                       fill.boxes(sna, &fill, boxes, last_box-boxes);
+                                                       if (damage)
+                                                               sna_damage_add_boxes(damage, boxes, last_box-boxes, 0, 0);
+                                                       b = boxes;
+                                               }
+                                       }
+                               }
+                       } while (--n);
+               } else {
+                       do {
+                               box_from_seg(b, seg++, gc);
+                               b->x1 += drawable->x;
+                               b->x2 += drawable->x;
+                               b->y1 += drawable->y;
+                               b->y2 += drawable->y;
+                               if (box_intersect(b, &clip.extents)) {
+                                       b->x1 += dx;
+                                       b->x2 += dx;
+                                       b->y1 += dy;
+                                       b->y2 += dy;
+                                       if (++b == last_box) {
+                                               fill.boxes(sna, &fill, boxes, last_box-boxes);
+                                               if (damage)
+                                                       sna_damage_add_boxes(damage, boxes, last_box-boxes, 0, 0);
+                                               b = boxes;
+                                       }
+                               }
+                       } while (--n);
+               }
+               RegionUninit(&clip);
+       }
+       if (b != boxes) {
+               fill.boxes(sna, &fill, boxes, b - boxes);
+               if (damage)
+                       sna_damage_add_boxes(damage, boxes, b - boxes, 0, 0);
+       }
+done:
+       fill.done(sna, &fill);
+       assert_pixmap_damage(pixmap);
+       return true;
+}
+
+static bool
+sna_poly_zero_segment_blt(DrawablePtr drawable,
+                         struct kgem_bo *bo,
+                         struct sna_damage **damage,
+                         GCPtr gc, const int _n, const xSegment *_s,
+                         const BoxRec *extents, unsigned clipped)
+{
+       static void * const _jump[] = {
+               &&no_damage,
+               &&damage,
+
+               &&no_damage_offset,
+               &&damage_offset,
+       };
+
+       PixmapPtr pixmap = get_drawable_pixmap(drawable);
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+       unsigned int bias = miGetZeroLineBias(drawable->pScreen);
+       struct sna_fill_op fill;
+       RegionRec clip;
+       const BoxRec *last_extents;
+       BoxRec box[512], *b;
+       BoxRec *const last_box = box + ARRAY_SIZE(box);
+       int16_t dx, dy;
+       void *jump, *ret;
+
+       DBG(("%s: alu=%d, pixel=%lx, n=%d, clipped=%d, damage=%p\n",
+            __FUNCTION__, gc->alu, gc->fgPixel, _n, clipped, damage));
+       if (!sna_fill_init_blt(&fill, sna, pixmap, bo, gc->alu, gc->fgPixel))
+               return false;
+
+       get_drawable_deltas(drawable, pixmap, &dx, &dy);
+
+       region_set(&clip, extents);
+       if (clipped) {
+               region_maybe_clip(&clip, gc->pCompositeClip);
+               if (!RegionNotEmpty(&clip))
+                       return true;
+       }
+       DBG(("%s: [clipped] extents=(%d, %d), (%d, %d), delta=(%d, %d)\n",
+            __FUNCTION__,
+            clip.extents.x1, clip.extents.y1,
+            clip.extents.x2, clip.extents.y2,
+            dx, dy));
+
+       jump = _jump[(damage != NULL) | !!(dx|dy) << 1];
+
+       b = box;
+       extents = REGION_RECTS(&clip);
+       last_extents = extents + REGION_NUM_RECTS(&clip);
+       do {
+               int n = _n;
+               const xSegment *s = _s;
+               do {
+                       int16_t sdx, sdy;
+                       int adx, ady, length;
+                       int e, e1, e2, e3;
+                       int x1, x2;
+                       int y1, y2;
+                       int oc1, oc2;
+                       int octant;
+
+                       x1 = s->x1 + drawable->x;
+                       y1 = s->y1 + drawable->y;
+                       x2 = s->x2 + drawable->x;
+                       y2 = s->y2 + drawable->y;
+                       s++;
+
+                       DBG(("%s: segment (%d, %d) to (%d, %d)\n",
+                            __FUNCTION__, x1, y1, x2, y2));
+                       if (x2 == x1 && y2 == y1)
+                               continue;
+
+                       oc1 = 0;
+                       OUTCODES(oc1, x1, y1, extents);
+                       oc2 = 0;
+                       OUTCODES(oc2, x2, y2, extents);
+                       if (oc1 & oc2)
+                               continue;
+
+                       CalcLineDeltas(x1, y1, x2, y2,
+                                      adx, ady, sdx, sdy,
+                                      1, 1, octant);
+
+                       DBG(("%s: adx=(%d, %d), sdx=(%d, %d)\n",
+                            __FUNCTION__, adx, ady, sdx, sdy));
+                       if (adx == 0 || ady == 0) {
+                               if (x1 <= x2) {
+                                       b->x1 = x1;
+                                       b->x2 = x2;
+                               } else {
+                                       b->x1 = x2;
+                                       b->x2 = x1;
+                               }
+                               if (y1 <= y2) {
+                                       b->y1 = y1;
+                                       b->y2 = y2;
+                               } else {
+                                       b->y1 = y2;
+                                       b->y2 = y1;
+                               }
+                               b->x2++;
+                               b->y2++;
+                               if (oc1 | oc2)
+                                       box_intersect(b, extents);
+                               if (++b == last_box) {
+                                       ret = &&rectangle_continue;
+                                       goto *jump;
+rectangle_continue:
+                                       b = box;
+                               }
+                       } else if (adx >= ady) {
+                               bool dirty;
+
+                               /* X-major segment */
+                               e1 = ady << 1;
+                               e2 = e1 - (adx << 1);
+                               e  = e1 - adx;
+                               length = adx;   /* don't draw endpoint in main loop */
+
+                               FIXUP_ERROR(e, octant, bias);
+
+                               if (oc1 | oc2) {
+                                       int pt1_clipped, pt2_clipped;
+                                       int x = x1, y = y1;
+
+                                       if (miZeroClipLine(extents->x1, extents->y1,
+                                                          extents->x2-1, extents->y2-1,
+                                                          &x1, &y1, &x2, &y2,
+                                                          adx, ady,
+                                                          &pt1_clipped, &pt2_clipped,
+                                                          octant, bias, oc1, oc2) == -1)
+                                               continue;
+
+                                       length = abs(x2 - x1);
+                                       if (length == 0)
+                                               continue;
+
+                                       if (pt1_clipped) {
+                                               int clipdx = abs(x1 - x);
+                                               int clipdy = abs(y1 - y);
+                                               e += clipdy * e2 + (clipdx - clipdy) * e1;
+                                       }
+                               }
+                               e3 = e2 - e1;
+                               e  = e - e1;
+
+                               b->x1 = x1;
+                               b->y1 = y1;
+                               dirty = false;
+                               while (length--) {
+                                       dirty = true;
+                                       e += e1;
+                                       if (e >= 0) {
+                                               e += e3;
+
+                                               if (sdx < 0) {
+                                                       b->x2 = b->x1 + 1;
+                                                       b->x1 = x1;
+                                               } else
+                                                       b->x2 = x1 + 1;
+                                               b->y2 = b->y1 + 1;
+
+                                               DBG(("%s: horizontal step: (%d, %d), box: (%d, %d), (%d, %d)\n",
+                                                    __FUNCTION__, x1, y1,
+                                                    b->x1, b->y1, b->x2, b->y2));
+
+                                               if (++b == last_box) {
+                                                       ret = &&X_continue;
+                                                       goto *jump;
+X_continue:
+                                                       b = box;
+                                               }
+
+                                               b->x1 = x1 + sdx;
+                                               b->y1 = y1 += sdy;
+                                               dirty = false;
+                                       }
+                                       x1 += sdx;
+                               }
+                               if (dirty) {
+                                       x1 -= sdx;
+                                       DBG(("%s: horizontal tail: (%d, %d)\n",
+                                            __FUNCTION__, x1, y1));
+                                       if (sdx < 0) {
+                                               b->x2 = b->x1 + 1;
+                                               b->x1 = x1;
+                                       } else
+                                               b->x2 = x1 + 1;
+                                       b->y2 = b->y1 + 1;
+
+                                       if (++b == last_box) {
+                                               ret = &&X2_continue;
+                                               goto *jump;
+X2_continue:
+                                               b = box;
+                                       }
+                               }
+                       } else {
+                               bool dirty;
+
+                               /* Y-major segment */
+                               e1 = adx << 1;
+                               e2 = e1 - (ady << 1);
+                               e  = e1 - ady;
+                               length  = ady;  /* don't draw endpoint in main loop */
+
+                               SetYMajorOctant(octant);
+                               FIXUP_ERROR(e, octant, bias);
+
+                               if (oc1 | oc2) {
+                                       int pt1_clipped, pt2_clipped;
+                                       int x = x1, y = y1;
+
+                                       if (miZeroClipLine(extents->x1, extents->y1,
+                                                          extents->x2-1, extents->y2-1,
+                                                          &x1, &y1, &x2, &y2,
+                                                          adx, ady,
+                                                          &pt1_clipped, &pt2_clipped,
+                                                          octant, bias, oc1, oc2) == -1)
+                                               continue;
+
+                                       length = abs(y2 - y1);
+                                       if (length == 0)
+                                               continue;
+
+                                       if (pt1_clipped) {
+                                               int clipdx = abs(x1 - x);
+                                               int clipdy = abs(y1 - y);
+                                               e += clipdx * e2 + (clipdy - clipdx) * e1;
+                                       }
+                               }
+
+                               e3 = e2 - e1;
+                               e  = e - e1;
+
+                               b->x1 = x1;
+                               b->y1 = y1;
+                               dirty = false;
+                               while (length--) {
+                                       e += e1;
+                                       dirty = true;
+                                       if (e >= 0) {
+                                               e += e3;
+
+                                               if (sdy < 0) {
+                                                       b->y2 = b->y1 + 1;
+                                                       b->y1 = y1;
+                                               } else
+                                                       b->y2 = y1 + 1;
+                                               b->x2 = x1 + 1;
+
+                                               if (++b == last_box) {
+                                                       ret = &&Y_continue;
+                                                       goto *jump;
+Y_continue:
+                                                       b = box;
+                                               }
+
+                                               b->x1 = x1 += sdx;
+                                               b->y1 = y1 + sdy;
+                                               dirty = false;
+                                       }
+                                       y1 += sdy;
+                               }
+
+                               if (dirty) {
+                                       y1 -= sdy;
+                                       if (sdy < 0) {
+                                               b->y2 = b->y1 + 1;
+                                               b->y1 = y1;
+                                       } else
+                                               b->y2 = y1 + 1;
+                                       b->x2 = x1 + 1;
+
+                                       if (++b == last_box) {
+                                               ret = &&Y2_continue;
+                                               goto *jump;
+Y2_continue:
+                                               b = box;
+                                       }
+                               }
+                       }
+               } while (--n);
+       } while (++extents != last_extents);
+
+       if (b != box) {
+               ret = &&done;
+               goto *jump;
+       }
+
+done:
+       fill.done(sna, &fill);
+       assert_pixmap_damage(pixmap);
+       RegionUninit(&clip);
+       return true;
+
+damage:
+       sna_damage_add_boxes(damage, box, b-box, 0, 0);
+no_damage:
+       fill.boxes(sna, &fill, box, b-box);
+       goto *ret;
+
+no_damage_offset:
+       {
+               BoxRec *bb = box;
+               do {
+                       bb->x1 += dx;
+                       bb->x2 += dx;
+                       bb->y1 += dy;
+                       bb->y2 += dy;
+               } while (++bb != b);
+               fill.boxes(sna, &fill, box, b - box);
+       }
+       goto *ret;
+
+damage_offset:
+       {
+               BoxRec *bb = box;
+               do {
+                       bb->x1 += dx;
+                       bb->x2 += dx;
+                       bb->y1 += dy;
+                       bb->y2 += dy;
+               } while (++bb != b);
+               fill.boxes(sna, &fill, box, b - box);
+               sna_damage_add_boxes(damage, box, b - box, 0, 0);
+       }
+       goto *ret;
+}
+
+static unsigned
+sna_poly_segment_extents(DrawablePtr drawable, GCPtr gc,
+                        int n, xSegment *seg,
+                        BoxPtr out)
+{
+       BoxRec box;
+       bool clipped, can_blit;
+
+       if (n == 0)
+               return 0;
+
+       if (seg->x2 >= seg->x1) {
+               box.x1 = seg->x1;
+               box.x2 = seg->x2;
+       } else {
+               box.x2 = seg->x1;
+               box.x1 = seg->x2;
+       }
+
+       if (seg->y2 >= seg->y1) {
+               box.y1 = seg->y1;
+               box.y2 = seg->y2;
+       } else {
+               box.y2 = seg->y1;
+               box.y1 = seg->y2;
+       }
+
+       can_blit = seg->x1 == seg->x2 || seg->y1 == seg->y2;
+       while (--n) {
+               seg++;
+               if (seg->x2 > seg->x1) {
+                       if (seg->x1 < box.x1) box.x1 = seg->x1;
+                       if (seg->x2 > box.x2) box.x2 = seg->x2;
+               } else {
+                       if (seg->x2 < box.x1) box.x1 = seg->x2;
+                       if (seg->x1 > box.x2) box.x2 = seg->x1;
+               }
+
+               if (seg->y2 > seg->y1) {
+                       if (seg->y1 < box.y1) box.y1 = seg->y1;
+                       if (seg->y2 > box.y2) box.y2 = seg->y2;
+               } else {
+                       if (seg->y2 < box.y1) box.y1 = seg->y2;
+                       if (seg->y1 > box.y2) box.y2 = seg->y1;
+               }
+
+               if (can_blit && !(seg->x1 == seg->x2 || seg->y1 == seg->y2))
+                       can_blit = false;
+       }
+
+       box.x2++;
+       box.y2++;
+
+       if (gc->lineWidth) {
+               int extra = gc->lineWidth;
+               if (gc->capStyle != CapProjecting)
+                       extra >>= 1;
+               if (extra) {
+                       box.x1 -= extra;
+                       box.x2 += extra;
+                       box.y1 -= extra;
+                       box.y2 += extra;
+               }
+       }
+
+       DBG(("%s: unclipped, untranslated extents (%d, %d), (%d, %d)\n",
+            __FUNCTION__, box.x1, box.y1, box.x2, box.y2));
+
+       clipped = trim_and_translate_box(&box, drawable, gc);
+       if (box_empty(&box))
+               return 0;
+
+       *out = box;
+       return 1 | clipped << 1 | can_blit << 2;
+}
+
+static void
+sna_poly_segment(DrawablePtr drawable, GCPtr gc, int n, xSegment *seg)
+{
+       struct sna_pixmap *priv;
+       struct sna_fill_spans data;
+       uint32_t color;
+
+       DBG(("%s(n=%d, first=((%d, %d), (%d, %d)), lineWidth=%d\n",
+            __FUNCTION__,
+            n, seg->x1, seg->y1, seg->x2, seg->y2,
+            gc->lineWidth));
+
+       data.flags = sna_poly_segment_extents(drawable, gc, n, seg,
+                                             &data.region.extents);
+       if (data.flags == 0)
+               return;
+
+       DBG(("%s: extents=(%d, %d), (%d, %d)\n", __FUNCTION__,
+            data.region.extents.x1, data.region.extents.y1,
+            data.region.extents.x2, data.region.extents.y2));
+
+       data.region.data = NULL;
+
+       if (FORCE_FALLBACK)
+               goto fallback;
+
+       if (!ACCEL_POLY_SEGMENT)
+               goto fallback;
+
+       data.pixmap = get_drawable_pixmap(drawable);
+       data.sna = to_sna_from_pixmap(data.pixmap);
+       priv = sna_pixmap(data.pixmap);
+       if (priv == NULL) {
+               DBG(("%s: fallback -- unattached\n", __FUNCTION__));
+               goto fallback;
+       }
+
+       if (wedged(data.sna)) {
+               DBG(("%s: fallback -- wedged\n", __FUNCTION__));
+               goto fallback;
+       }
+
+       DBG(("%s: fill=%d [%d], line=%d [%d], width=%d, mask=%lu [%d], rectlinear=%d\n",
+            __FUNCTION__,
+            gc->fillStyle, gc->fillStyle == FillSolid,
+            gc->lineStyle, gc->lineStyle == LineSolid,
+            gc->lineWidth,
+            gc->planemask, PM_IS_SOLID(drawable, gc->planemask),
+            data.flags & 4));
+       if (!PM_IS_SOLID(drawable, gc->planemask))
+               goto fallback;
+
+       if (gc->lineStyle != LineSolid || gc->lineWidth > 1)
+               goto spans_fallback;
+       if (gc_is_solid(gc, &color)) {
+               DBG(("%s: trying blt solid fill [%08x, flags=%x] paths\n",
+                    __FUNCTION__, (unsigned)color, data.flags));
+
+               if (data.flags & 4) {
+                       if ((data.bo = sna_drawable_use_bo(drawable, PREFER_GPU,
+                                                          &data.region.extents,
+                                                          &data.damage)) &&
+                            sna_poly_segment_blt(drawable,
+                                                data.bo, data.damage,
+                                                gc, color, n, seg,
+                                                &data.region.extents,
+                                                data.flags & 2))
+                               return;
+               } else {
+                       if ((data.bo = sna_drawable_use_bo(drawable,
+                                                          use_zero_spans(drawable, gc, &data.region.extents),
+                                                          &data.region.extents,
+                                                          &data.damage)) &&
+                           sna_poly_zero_segment_blt(drawable,
+                                                     data.bo, data.damage,
+                                                     gc, n, seg,
+                                                     &data.region.extents,
+                                                     data.flags & 2))
+                               return;
+               }
+       } else if (data.flags & 4) {
+               /* Try converting these to a set of rectangles instead */
+               xRectangle *rect;
+               int i;
+
+               data.bo = sna_drawable_use_bo(drawable, PREFER_GPU,
+                                             &data.region.extents,
+                                             &data.damage);
+               if (data.bo == NULL)
+                       goto fallback;
+
+               DBG(("%s: converting to rectagnles\n", __FUNCTION__));
+
+               rect = malloc (n * sizeof (xRectangle));
+               if (rect == NULL)
+                       return;
+
+               for (i = 0; i < n; i++) {
+                       if (seg[i].x1 < seg[i].x2) {
+                               rect[i].x = seg[i].x1;
+                               rect[i].width = seg[i].x2 - seg[i].x1 + 1;
+                       } else if (seg[i].x1 > seg[i].x2) {
+                               rect[i].x = seg[i].x2;
+                               rect[i].width = seg[i].x1 - seg[i].x2 + 1;
+                       } else {
+                               rect[i].x = seg[i].x1;
+                               rect[i].width = 1;
+                       }
+                       if (seg[i].y1 < seg[i].y2) {
+                               rect[i].y = seg[i].y1;
+                               rect[i].height = seg[i].y2 - seg[i].y1 + 1;
+                       } else if (seg[i].y1 > seg[i].y2) {
+                               rect[i].y = seg[i].y2;
+                               rect[i].height = seg[i].y1 - seg[i].y2 + 1;
+                       } else {
+                               rect[i].y = seg[i].y1;
+                               rect[i].height = 1;
+                       }
+
+                       /* don't paint last pixel */
+                       if (gc->capStyle == CapNotLast) {
+                               if (seg[i].x1 == seg[i].x2)
+                                       rect[i].height--;
+                               else
+                                       rect[i].width--;
+                       }
+               }
+
+               if (gc->fillStyle == FillTiled) {
+                       i = sna_poly_fill_rect_tiled_blt(drawable,
+                                                        data.bo, data.damage,
+                                                        gc, n, rect,
+                                                        &data.region.extents,
+                                                        data.flags & 2);
+               } else {
+                       i = sna_poly_fill_rect_stippled_blt(drawable,
+                                                           data.bo, data.damage,
+                                                           gc, n, rect,
+                                                           &data.region.extents,
+                                                           data.flags & 2);
+               }
+               free (rect);
+
+               if (i)
+                       return;
+       }
+
+spans_fallback:
+       if ((data.bo = sna_drawable_use_bo(drawable,
+                                          use_wide_spans(drawable, gc, &data.region.extents),
+                                          &data.region.extents,
+                                          &data.damage))) {
+               void (*line)(DrawablePtr, GCPtr, int, int, DDXPointPtr);
+               int i;
+
+               DBG(("%s: converting segments into spans\n", __FUNCTION__));
+
+               switch (gc->lineStyle) {
+               default:
+               case LineSolid:
+                       if (gc->lineWidth == 0)
+                               line = miZeroLine;
+                       else
+                               line = miWideLine;
+                       break;
+               case LineOnOffDash:
+               case LineDoubleDash:
+                       if (gc->lineWidth == 0)
+                               line = miZeroDashLine;
+                       else
+                               line = miWideDash;
+                       break;
+               }
+
+               get_drawable_deltas(drawable, data.pixmap, &data.dx, &data.dy);
+               sna_gc(gc)->priv = &data;
+
+               if (gc->lineWidth == 0 &&
+                   gc->lineStyle == LineSolid &&
+                   gc_is_solid(gc, &color)) {
+                       struct sna_fill_op fill;
+
+                       if (!sna_fill_init_blt(&fill,
+                                              data.sna, data.pixmap,
+                                              data.bo, gc->alu, color))
+                               goto fallback;
+
+                       data.op = &fill;
+
+                       if ((data.flags & 2) == 0) {
+                               if (data.dx | data.dy)
+                                       sna_gc_ops__tmp.FillSpans = sna_fill_spans__fill_offset;
+                               else
+                                       sna_gc_ops__tmp.FillSpans = sna_fill_spans__fill;
+                       } else {
+                               region_maybe_clip(&data.region,
+                                                 gc->pCompositeClip);
+                               if (!RegionNotEmpty(&data.region))
+                                       return;
+
+                               if (region_is_singular(&data.region))
+                                       sna_gc_ops__tmp.FillSpans = sna_fill_spans__fill_clip_extents;
+                               else
+                                       sna_gc_ops__tmp.FillSpans = sna_fill_spans__fill_clip_boxes;
+                       }
+                       assert(gc->miTranslate);
+                       gc->ops = &sna_gc_ops__tmp;
+                       for (i = 0; i < n; i++)
+                               line(drawable, gc, CoordModeOrigin, 2,
+                                    (DDXPointPtr)&seg[i]);
+
+                       fill.done(data.sna, &fill);
+               } else {
+                       sna_gc_ops__tmp.FillSpans = sna_fill_spans__gpu;
+                       gc->ops = &sna_gc_ops__tmp;
+
+                       for (i = 0; i < n; i++)
+                               line(drawable, gc, CoordModeOrigin, 2,
+                                    (DDXPointPtr)&seg[i]);
+               }
+
+               gc->ops = (GCOps *)&sna_gc_ops;
+               if (data.damage) {
+                       if (data.dx | data.dy)
+                               pixman_region_translate(&data.region, data.dx, data.dy);
+                       assert_pixmap_contains_box(data.pixmap, &data.region.extents);
+                       sna_damage_add(data.damage, &data.region);
+               }
+               assert_pixmap_damage(data.pixmap);
+               RegionUninit(&data.region);
+               return;
+       }
+
+fallback:
+       DBG(("%s: fallback\n", __FUNCTION__));
+       region_maybe_clip(&data.region, gc->pCompositeClip);
+       if (!RegionNotEmpty(&data.region))
+               return;
+
+       if (!sna_gc_move_to_cpu(gc, drawable, &data.region))
+               goto out;
+       if (!sna_drawable_move_region_to_cpu(drawable, &data.region,
+                                            drawable_gc_flags(drawable, gc,
+                                                              !(data.flags & 4 && n == 1))))
+               goto out_gc;
+
+       DBG(("%s: fbPolySegment\n", __FUNCTION__));
+       fbPolySegment(drawable, gc, n, seg);
+       FALLBACK_FLUSH(drawable);
+
+out_gc:
+       sna_gc_move_to_gpu(gc);
+out:
+       RegionUninit(&data.region);
+}
+
+static unsigned
+sna_poly_rectangle_extents(DrawablePtr drawable, GCPtr gc,
+                          int n, xRectangle *r,
+                          BoxPtr out)
+{
+       Box32Rec box;
+       int extra = gc->lineWidth >> 1;
+       bool clipped;
+
+       if (n == 0)
+               return 0;
+
+       box.x1 = r->x;
+       box.y1 = r->y;
+       box.x2 = box.x1 + r->width;
+       box.y2 = box.y1 + r->height;
+
+       while (--n)
+               box32_add_rect(&box, ++r);
+
+       box.x2++;
+       box.y2++;
+
+       if (extra) {
+               box.x1 -= extra;
+               box.x2 += extra;
+               box.y1 -= extra;
+               box.y2 += extra;
+       }
+
+       clipped = box32_trim_and_translate(&box, drawable, gc);
+       if (!box32_to_box16(&box, out))
+               return 0;
+
+       return 1 | clipped << 1;
+}
+
+static bool
+sna_poly_rectangle_blt(DrawablePtr drawable,
+                      struct kgem_bo *bo,
+                      struct sna_damage **damage,
+                      GCPtr gc, int n, xRectangle *r,
+                      const BoxRec *extents, unsigned clipped)
+{
+       PixmapPtr pixmap = get_drawable_pixmap(drawable);
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+       struct sna_fill_op fill;
+       BoxRec boxes[512], *b = boxes, *const last_box = boxes+ARRAY_SIZE(boxes);
+       int16_t dx, dy;
+       static void * const jump[] = {
+               &&wide,
+               &&zero,
+               &&wide_clipped,
+               &&zero_clipped,
+       };
+
+       DBG(("%s: n=%d, alu=%d, width=%d, fg=%08lx, damge=%p, clipped?=%d\n",
+            __FUNCTION__, n, gc->alu, gc->lineWidth, gc->fgPixel, damage, clipped));
+       if (!sna_fill_init_blt(&fill, sna, pixmap, bo, gc->alu, gc->fgPixel))
+               return false;
+
+       get_drawable_deltas(drawable, pixmap, &dx, &dy);
+
+       goto *jump[(gc->lineWidth <= 1) | clipped];
+
+zero:
+       dx += drawable->x;
+       dy += drawable->y;
+
+       do {
+               xRectangle rr = *r++;
+
+               if ((rr.width | rr.height) == 0)
+                       continue;
+
+               DBG(("%s - zero : r[%d] = (%d, %d) x (%d, %d)\n", __FUNCTION__,
+                    n, rr.x, rr.y, rr.width, rr.height));
+               rr.x += dx;
+               rr.y += dy;
+
+               if (b+4 > last_box) {
+                       fill.boxes(sna, &fill, boxes, b-boxes);
+                       if (damage)
+                               sna_damage_add_boxes(damage, boxes, b-boxes, 0, 0);
+                       b = boxes;
+               }
+
+               if (rr.width <= 1 || rr.height <= 1) {
+                       b->x1 = rr.x;
+                       b->y1 = rr.y;
+                       b->x2 = rr.x + rr.width + (rr.height != 0);
+                       b->y2 = rr.y + rr.height + (rr.width != 0);
+                       DBG(("%s: blt (%d, %d), (%d, %d)\n",
+                            __FUNCTION__,
+                            b->x1, b->y1, b->x2,b->y2));
+                       b++;
+               } else {
+                       b[0].x1 = rr.x;
+                       b[0].y1 = rr.y;
+                       b[0].x2 = rr.x + rr.width + 1;
+                       b[0].y2 = rr.y + 1;
+
+                       b[1] = b[0];
+                       b[1].y1 += rr.height;
+                       b[1].y2 += rr.height;
+
+                       b[2].y1 = rr.y + 1;
+                       b[2].y2 = rr.y + rr.height;
+                       b[2].x1 = rr.x;
+                       b[2].x2 = rr.x + 1;
+
+                       b[3] = b[2];
+                       b[3].x1 += rr.width;
+                       b[3].x2 += rr.width;
+
+                       b += 4;
+               }
+       } while (--n);
+       goto done;
+
+zero_clipped:
+       {
+               RegionRec clip;
+               BoxRec box[4];
+               int count;
+
+               region_set(&clip, extents);
+               region_maybe_clip(&clip, gc->pCompositeClip);
+               if (!RegionNotEmpty(&clip))
+                       goto done;
+
+               if (clip.data) {
+                       const BoxRec * const clip_start = RegionBoxptr(&clip);
+                       const BoxRec * const clip_end = clip_start + clip.data->numRects;
+                       const BoxRec *c;
+                       do {
+                               xRectangle rr = *r++;
+
+                               DBG(("%s - zero, clipped complex: r[%d] = (%d, %d) x (%d, %d)\n", __FUNCTION__,
+                                    n, rr.x, rr.y, rr.width, rr.height));
+
+                               if ((rr.width | rr.height) == 0)
+                                       continue;
+
+                               rr.x += drawable->x;
+                               rr.y += drawable->y;
+
+                               if (rr.width <= 1 || rr.height <= 1) {
+                                       box[0].x1 = rr.x;
+                                       box[0].y1 = rr.y;
+                                       box[0].x2 = rr.x + rr.width + (rr.height != 0);
+                                       box[0].y2 = rr.y + rr.height + (rr.width != 0);
+                                       count = 1;
+                               } else {
+                                       box[0].x1 = rr.x;
+                                       box[0].y1 = rr.y;
+                                       box[0].x2 = rr.x + rr.width + 1;
+                                       box[0].y2 = rr.y + 1;
+
+                                       box[1] = box[0];
+                                       box[1].y1 += rr.height;
+                                       box[1].y2 += rr.height;
+
+                                       box[2].y1 = rr.y + 1;
+                                       box[2].y2 = rr.y + rr.height;
+                                       box[2].x1 = rr.x;
+                                       box[2].x2 = rr.x + 1;
+
+                                       box[3] = box[2];
+                                       box[3].x1 += rr.width;
+                                       box[3].x2 += rr.width;
+                                       count = 4;
+                               }
+
+                               while (count--) {
+                                       c = find_clip_box_for_y(clip_start,
+                                                               clip_end,
+                                                               box[count].y1);
+                                       while (c != clip_end) {
+                                               if (box[count].y2 <= c->y1)
+                                                       break;
+
+                                               *b = box[count];
+                                               if (box_intersect(b, c++)) {
+                                                       b->x1 += dx;
+                                                       b->x2 += dx;
+                                                       b->y1 += dy;
+                                                       b->y2 += dy;
+                                                       if (++b == last_box) {
+                                                               fill.boxes(sna, &fill, boxes, last_box-boxes);
+                                                               if (damage)
+                                                                       sna_damage_add_boxes(damage, boxes, last_box-boxes, 0, 0);
+                                                               b = boxes;
+                                                       }
+                                               }
+
+                                       }
+                               }
+                       } while (--n);
+               } else {
+                       do {
+                               xRectangle rr = *r++;
+                               DBG(("%s - zero, clip: r[%d] = (%d, %d) x (%d, %d)\n", __FUNCTION__,
+                                    n, rr.x, rr.y, rr.width, rr.height));
+
+                               if ((rr.width | rr.height) == 0)
+                                       continue;
+
+                               rr.x += drawable->x;
+                               rr.y += drawable->y;
+
+                               if (rr.width <= 1 || rr.height <= 1) {
+                                       box[0].x1 = rr.x;
+                                       box[0].y1 = rr.y;
+                                       box[0].x2 = rr.x + rr.width + (rr.height != 0);
+                                       box[0].y2 = rr.y + rr.height + (rr.width != 0);
+                                       count = 1;
+                               } else {
+                                       box[0].x1 = rr.x;
+                                       box[0].y1 = rr.y;
+                                       box[0].x2 = rr.x + rr.width + 1;
+                                       box[0].y2 = rr.y + 1;
+
+                                       box[1] = box[0];
+                                       box[1].y1 += rr.height;
+                                       box[1].y2 += rr.height;
+
+                                       box[2].y1 = rr.y + 1;
+                                       box[2].y2 = rr.y + rr.height;
+                                       box[2].x1 = rr.x;
+                                       box[2].x2 = rr.x + 1;
+
+                                       box[3] = box[2];
+                                       box[3].x1 += rr.width;
+                                       box[3].x2 += rr.width;
+                                       count = 4;
+                               }
+
+                               while (count--) {
+                                       *b = box[count];
+                                       if (box_intersect(b, &clip.extents)) {
+                                               b->x1 += dx;
+                                               b->x2 += dx;
+                                               b->y1 += dy;
+                                               b->y2 += dy;
+                                               if (++b == last_box) {
+                                                       fill.boxes(sna, &fill, boxes, last_box-boxes);
+                                                       if (damage)
+                                                               sna_damage_add_boxes(damage, boxes, last_box-boxes, 0, 0);
+                                                       b = boxes;
+                                               }
+                                       }
+
+                               }
+                       } while (--n);
+               }
+               RegionUninit(&clip);
+       }
+       goto done;
+
+wide_clipped:
+       {
+               RegionRec clip;
+               BoxRec box[4];
+               int16_t offset2 = gc->lineWidth;
+               int16_t offset1 = offset2 >> 1;
+               int16_t offset3 = offset2 - offset1;
+
+               region_set(&clip, extents);
+               region_maybe_clip(&clip, gc->pCompositeClip);
+               DBG(("%s: wide clipped: extents=((%d, %d), (%d, %d))\n",
+                    __FUNCTION__,
+                    clip.extents.x1, clip.extents.y1,
+                    clip.extents.x2, clip.extents.y2));
+               if (!RegionNotEmpty(&clip))
+                       goto done;
+
+               if (clip.data) {
+                       const BoxRec * const clip_start = RegionBoxptr(&clip);
+                       const BoxRec * const clip_end = clip_start + clip.data->numRects;
+                       const BoxRec *c;
+                       do {
+                               xRectangle rr = *r++;
+                               int count;
+
+                               if ((rr.width | rr.height) == 0)
+                                       continue;
+
+                               rr.x += drawable->x;
+                               rr.y += drawable->y;
+
+                               if (rr.height <= offset2 || rr.width <= offset2) {
+                                       if (rr.height == 0) {
+                                               box[0].x1 = rr.x;
+                                               box[0].x2 = rr.x + rr.width;
+                                       } else {
+                                               box[0].x1 = rr.x - offset1;
+                                               box[0].x2 = rr.x + rr.width + offset3;
+                                       }
+                                       if (rr.width == 0) {
+                                               box[0].y1 = rr.y;
+                                               box[0].y2 = rr.y + rr.height;
+                                       } else {
+                                               box[0].y1 = rr.y - offset1;
+                                               box[0].y2 = rr.y + rr.height + offset3;
+                                       }
+                                       count = 1;
+                               } else {
+                                       box[0].x1 = rr.x - offset1;
+                                       box[0].x2 = box[0].x1 + rr.width + offset2;
+                                       box[0].y1 = rr.y - offset1;
+                                       box[0].y2 = box[0].y1 + offset2;
+
+                                       box[1].x1 = rr.x - offset1;
+                                       box[1].x2 = box[1].x1 + offset2;
+                                       box[1].y1 = rr.y + offset3;
+                                       box[1].y2 = rr.y + rr.height - offset1;
+
+                                       box[2] = box[1];
+                                       box[2].x1 += rr.width;
+                                       box[2].x2 += rr.width;
+
+                                       box[3] = box[0];
+                                       box[3].y1 += rr.height;
+                                       box[3].y2 += rr.height;
+                                       count = 4;
+                               }
+
+                               while (count--) {
+                                       c = find_clip_box_for_y(clip_start,
+                                                               clip_end,
+                                                               box[count].y1);
+                                       while (c != clip_end) {
+                                               if (box[count].y2 <= c->y1)
+                                                       break;
+
+                                               *b = box[count];
+                                               if (box_intersect(b, c++)) {
+                                                       b->x1 += dx;
+                                                       b->x2 += dx;
+                                                       b->y1 += dy;
+                                                       b->y2 += dy;
+                                                       if (++b == last_box) {
+                                                               fill.boxes(sna, &fill, boxes, last_box-boxes);
+                                                               if (damage)
+                                                                       sna_damage_add_boxes(damage, boxes, last_box-boxes, 0, 0);
+                                                               b = boxes;
+                                                       }
+                                               }
+                                       }
+                               }
+                       } while (--n);
+               } else {
+                       DBG(("%s: singular clip offset1=%d, offset2=%d, offset3=%d\n",
+                            __FUNCTION__, offset1, offset2, offset3));
+                       do {
+                               xRectangle rr = *r++;
+                               int count;
+                               rr.x += drawable->x;
+                               rr.y += drawable->y;
+
+                               DBG(("%s: r=(%d, %d)x(%d, %d)\n",
+                                    __FUNCTION__, rr.x, rr.y, rr.width, rr.height));
+                               if (rr.height <= offset2 || rr.width <= offset2) {
+                                       if (rr.height == 0) {
+                                               box[0].x1 = rr.x;
+                                               box[0].x2 = rr.x + rr.width;
+                                       } else {
+                                               box[0].x1 = rr.x - offset1;
+                                               box[0].x2 = box[0].x1 + rr.width + offset2;
+                                       }
+                                       if (rr.width == 0) {
+                                               box[0].y1 = rr.y;
+                                               box[0].y2 = rr.y + rr.height;
+                                       } else {
+                                               box[0].y1 = rr.y - offset1;
+                                               box[0].y2 = box[0].y1 + rr.height + offset2;
+                                       }
+                                       count = 1;
+                               } else {
+                                       box[0].x1 = rr.x - offset1;
+                                       box[0].x2 = box[0].x1 + rr.width + offset2;
+                                       box[0].y1 = rr.y - offset1;
+                                       box[0].y2 = box[0].y1 + offset2;
+                                       DBG(("%s: box[0]=(%d, %d), (%d, %d)\n",
+                                            __FUNCTION__,
+                                            box[0].x1, box[0].y1,
+                                            box[0].x2, box[0].y2));
+
+                                       box[1].x1 = rr.x - offset1;
+                                       box[1].x2 = box[1].x1 + offset2;
+                                       box[1].y1 = rr.y + offset3;
+                                       box[1].y2 = rr.y + rr.height - offset1;
+                                       DBG(("%s: box[1]=(%d, %d), (%d, %d)\n",
+                                            __FUNCTION__,
+                                            box[1].x1, box[1].y1,
+                                            box[1].x2, box[1].y2));
+
+                                       box[2] = box[1];
+                                       box[2].x1 += rr.width;
+                                       box[2].x2 += rr.width;
+                                       DBG(("%s: box[2]=(%d, %d), (%d, %d)\n",
+                                            __FUNCTION__,
+                                            box[2].x1, box[2].y1,
+                                            box[2].x2, box[2].y2));
+
+                                       box[3] = box[0];
+                                       box[3].y1 += rr.height;
+                                       box[3].y2 += rr.height;
+                                       DBG(("%s: box[3]=(%d, %d), (%d, %d)\n",
+                                            __FUNCTION__,
+                                            box[3].x1, box[3].y1,
+                                            box[3].x2, box[3].y2));
+
+                                       count = 4;
+                               }
+
+                               while (count--) {
+                                       *b = box[count];
+                                       if (box_intersect(b, &clip.extents)) {
+                                               b->x1 += dx;
+                                               b->x2 += dx;
+                                               b->y1 += dy;
+                                               b->y2 += dy;
+                                               if (++b == last_box) {
+                                                       fill.boxes(sna, &fill, boxes, last_box-boxes);
+                                                       if (damage)
+                                                               sna_damage_add_boxes(damage, boxes, last_box-boxes, 0, 0);
+                                                       b = boxes;
+                                               }
+                                       }
+                               }
+                       } while (--n);
+               }
+               RegionUninit(&clip);
+       }
+       goto done;
+
+wide:
+       {
+               int offset2 = gc->lineWidth;
+               int offset1 = offset2 >> 1;
+               int offset3 = offset2 - offset1;
+
+               dx += drawable->x;
+               dy += drawable->y;
+
+               do {
+                       xRectangle rr = *r++;
+
+                       if ((rr.width | rr.height) == 0)
+                               continue;
+
+                       rr.x += dx;
+                       rr.y += dy;
+
+                       if (b+4 > last_box) {
+                               fill.boxes(sna, &fill, boxes, last_box-boxes);
+                               if (damage)
+                                       sna_damage_add_boxes(damage, boxes, last_box-boxes, 0, 0);
+                               b = boxes;
+                       }
+
+                       if (rr.height <= offset2 || rr.width <= offset2) {
+                               if (rr.height == 0) {
+                                       b->x1 = rr.x;
+                                       b->x2 = rr.x + rr.width;
+                               } else {
+                                       b->x1 = rr.x - offset1;
+                                       b->x2 = rr.x + rr.width + offset3;
+                               }
+                               if (rr.width == 0) {
+                                       b->y1 = rr.y;
+                                       b->y2 = rr.y + rr.height;
+                               } else {
+                                       b->y1 = rr.y - offset1;
+                                       b->y2 = rr.y + rr.height + offset3;
+                               }
+                               b++;
+                       } else {
+                               b[0].x1 = rr.x - offset1;
+                               b[0].x2 = b[0].x1 + rr.width + offset2;
+                               b[0].y1 = rr.y - offset1;
+                               b[0].y2 = b[0].y1 + offset2;
+
+                               b[1].x1 = rr.x - offset1;
+                               b[1].x2 = b[1].x1 + offset2;
+                               b[1].y1 = rr.y + offset3;
+                               b[1].y2 = rr.y + rr.height - offset1;
+
+                               b[2] = b[1];
+                               b[2].x1 += rr.width;
+                               b[2].x2 += rr.width;
+
+                               b[3] = b[0];
+                               b[3].y1 += rr.height;
+                               b[3].y2 += rr.height;
+                               b += 4;
+                       }
+               } while (--n);
+       }
+       goto done;
+
+done:
+       if (b != boxes) {
+               fill.boxes(sna, &fill, boxes, b-boxes);
+               if (damage)
+                       sna_damage_add_boxes(damage, boxes, b-boxes, 0, 0);
+       }
+       fill.done(sna, &fill);
+       assert_pixmap_damage(pixmap);
+       return true;
+}
+
+static void
+sna_poly_rectangle(DrawablePtr drawable, GCPtr gc, int n, xRectangle *r)
+{
+       PixmapPtr pixmap = get_drawable_pixmap(drawable);
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+       struct sna_damage **damage;
+       struct kgem_bo *bo;
+       RegionRec region;
+       unsigned flags;
+
+       DBG(("%s(n=%d, first=((%d, %d)x(%d, %d)), lineWidth=%d\n",
+            __FUNCTION__,
+            n, r->x, r->y, r->width, r->height,
+            gc->lineWidth));
+
+       flags = sna_poly_rectangle_extents(drawable, gc, n, r, &region.extents);
+       if (flags == 0)
+               return;
+
+       DBG(("%s: extents=(%d, %d), (%d, %d), flags=%x\n", __FUNCTION__,
+            region.extents.x1, region.extents.y1,
+            region.extents.x2, region.extents.y2,
+            flags));
+
+       if (FORCE_FALLBACK)
+               goto fallback;
+
+       if (!ACCEL_POLY_RECTANGLE)
+               goto fallback;
+
+       if (wedged(sna)) {
+               DBG(("%s: fallback -- wedged\n", __FUNCTION__));
+               goto fallback;
+       }
+
+       DBG(("%s: line=%d [%d], join=%d [%d], mask=%lu [%d]\n",
+            __FUNCTION__,
+            gc->lineStyle, gc->lineStyle == LineSolid,
+            gc->joinStyle, gc->joinStyle == JoinMiter,
+            gc->planemask, PM_IS_SOLID(drawable, gc->planemask)));
+
+       if (!PM_IS_SOLID(drawable, gc->planemask))
+               goto fallback;
+
+       if (gc->lineStyle == LineSolid && gc->joinStyle == JoinMiter) {
+               DBG(("%s: trying blt solid fill [%08lx] paths\n",
+                    __FUNCTION__, gc->fgPixel));
+               if ((bo = sna_drawable_use_bo(drawable, PREFER_GPU,
+                                             &region.extents, &damage)) &&
+                   sna_poly_rectangle_blt(drawable, bo, damage,
+                                          gc, n, r, &region.extents, flags&2))
+                       return;
+       } else {
+               /* Not a trivial outline, but we still maybe able to break it
+                * down into simpler operations that we can accelerate.
+                */
+               if (sna_drawable_use_bo(drawable, PREFER_GPU,
+                                       &region.extents, &damage)) {
+                       miPolyRectangle(drawable, gc, n, r);
+                       return;
+               }
+       }
+
+fallback:
+       DBG(("%s: fallback\n", __FUNCTION__));
+
+       region.data = NULL;
+       region_maybe_clip(&region, gc->pCompositeClip);
+       if (!RegionNotEmpty(&region))
+               return;
+
+       if (!sna_gc_move_to_cpu(gc, drawable, &region))
+               goto out;
+       if (!sna_drawable_move_region_to_cpu(drawable, &region,
+                                            drawable_gc_flags(drawable, gc, true)))
+               goto out_gc;
+
+       DBG(("%s: miPolyRectangle\n", __FUNCTION__));
+       miPolyRectangle(drawable, gc, n, r);
+       FALLBACK_FLUSH(drawable);
+out_gc:
+       sna_gc_move_to_gpu(gc);
+out:
+       RegionUninit(&region);
+}
+
+static unsigned
+sna_poly_arc_extents(DrawablePtr drawable, GCPtr gc,
+                    int n, xArc *arc,
+                    BoxPtr out)
+{
+       BoxRec box;
+       bool clipped;
+       int v;
+
+       if (n == 0)
+               return 0;
+
+       box.x1 = arc->x;
+       box.x2 = bound(box.x1, arc->width);
+       box.y1 = arc->y;
+       box.y2 = bound(box.y1, arc->height);
+
+       while (--n) {
+               arc++;
+               if (box.x1 > arc->x)
+                       box.x1 = arc->x;
+               v = bound(arc->x, arc->width);
+               if (box.x2 < v)
+                       box.x2 = v;
+               if (box.y1 > arc->y)
+                       box.y1 = arc->y;
+               v = bound(arc->y, arc->height);
+               if (box.y2 < v)
+                       box.y2 = v;
+       }
+
+       v = gc->lineWidth >> 1;
+       if (v) {
+               box.x1 -= v;
+               box.x2 += v;
+               box.y1 -= v;
+               box.y2 += v;
+       }
+
+       box.x2++;
+       box.y2++;
+
+       clipped = trim_and_translate_box(&box, drawable, gc);
+       if (box_empty(&box))
+               return 0;
+
+       *out = box;
+       return 1 | clipped << 1;
+}
+
+static void
+sna_poly_arc(DrawablePtr drawable, GCPtr gc, int n, xArc *arc)
+{
+       struct sna_fill_spans data;
+       struct sna_pixmap *priv;
+
+       DBG(("%s(n=%d, lineWidth=%d\n", __FUNCTION__, n, gc->lineWidth));
+
+       data.flags = sna_poly_arc_extents(drawable, gc, n, arc,
+                                         &data.region.extents);
+       if (data.flags == 0)
+               return;
+
+       DBG(("%s: extents=(%d, %d), (%d, %d), flags=%x\n", __FUNCTION__,
+            data.region.extents.x1, data.region.extents.y1,
+            data.region.extents.x2, data.region.extents.y2,
+            data.flags));
+
+       data.region.data = NULL;
+
+       if (FORCE_FALLBACK)
+               goto fallback;
+
+       if (!ACCEL_POLY_ARC)
+               goto fallback;
+
+       data.pixmap = get_drawable_pixmap(drawable);
+       data.sna = to_sna_from_pixmap(data.pixmap);
+       priv = sna_pixmap(data.pixmap);
+       if (priv == NULL) {
+               DBG(("%s: fallback -- unattached\n", __FUNCTION__));
+               goto fallback;
+       }
+
+       if (wedged(data.sna)) {
+               DBG(("%s: fallback -- wedged\n", __FUNCTION__));
+               goto fallback;
+       }
+
+       if (!PM_IS_SOLID(drawable, gc->planemask))
+               goto fallback;
+
+       if ((data.bo = sna_drawable_use_bo(drawable,
+                                          use_wide_spans(drawable, gc, &data.region.extents),
+                                          &data.region.extents, &data.damage))) {
+               uint32_t color;
+
+               DBG(("%s: converting arcs into spans\n", __FUNCTION__));
+               get_drawable_deltas(drawable, data.pixmap, &data.dx, &data.dy);
+
+               if (gc_is_solid(gc, &color)) {
+                       sna_gc(gc)->priv = &data;
+
+                       assert(gc->miTranslate);
+                       if (gc->lineStyle == LineSolid) {
+                               struct sna_fill_op fill;
+
+                               if (!sna_fill_init_blt(&fill,
+                                                      data.sna, data.pixmap,
+                                                      data.bo, gc->alu, color))
+                                       goto fallback;
+
+                               if ((data.flags & 2) == 0) {
+                                       if (data.dx | data.dy)
+                                               sna_gc_ops__tmp.FillSpans = sna_fill_spans__fill_offset;
+                                       else
+                                               sna_gc_ops__tmp.FillSpans = sna_fill_spans__fill;
+                                       sna_gc_ops__tmp.PolyPoint = sna_poly_point__fill;
+                               } else {
+                                       region_maybe_clip(&data.region,
+                                                         gc->pCompositeClip);
+                                       if (!RegionNotEmpty(&data.region))
+                                               return;
+
+                                       if (region_is_singular(&data.region)) {
+                                               sna_gc_ops__tmp.FillSpans = sna_fill_spans__fill_clip_extents;
+                                               sna_gc_ops__tmp.PolyPoint = sna_poly_point__fill_clip_extents;
+                                       } else {
+                                               sna_gc_ops__tmp.FillSpans = sna_fill_spans__fill_clip_boxes;
+                                               sna_gc_ops__tmp.PolyPoint = sna_poly_point__fill_clip_boxes;
+                                       }
+                               }
+
+                               data.op = &fill;
+                               gc->ops = &sna_gc_ops__tmp;
+                               if (gc->lineWidth == 0)
+                                       miZeroPolyArc(drawable, gc, n, arc);
+                               else
+                                       miPolyArc(drawable, gc, n, arc);
+                               gc->ops = (GCOps *)&sna_gc_ops;
+
+                               fill.done(data.sna, &fill);
+                       } else {
+                               region_maybe_clip(&data.region,
+                                                 gc->pCompositeClip);
+                               if (!RegionNotEmpty(&data.region))
+                                       return;
+
+                               sna_gc_ops__tmp.FillSpans = sna_fill_spans__gpu;
+                               sna_gc_ops__tmp.PolyPoint = sna_poly_point__gpu;
+
+                               gc->ops = &sna_gc_ops__tmp;
+                               if (gc->lineWidth == 0)
+                                       miZeroPolyArc(drawable, gc, n, arc);
+                               else
+                                       miPolyArc(drawable, gc, n, arc);
+                               gc->ops = (GCOps *)&sna_gc_ops;
+                       }
+
+                       if (data.damage) {
+                               if (data.dx | data.dy)
+                                       pixman_region_translate(&data.region, data.dx, data.dy);
+                               assert_pixmap_contains_box(data.pixmap, &data.region.extents);
+                               sna_damage_add(data.damage, &data.region);
+                       }
+                       assert_pixmap_damage(data.pixmap);
+                       RegionUninit(&data.region);
+                       return;
+               }
+
+               /* XXX still around 10x slower for x11perf -ellipse */
+               if (gc->lineWidth == 0)
+                       miZeroPolyArc(drawable, gc, n, arc);
+               else
+                       miPolyArc(drawable, gc, n, arc);
+               return;
+       }
+
+fallback:
+       DBG(("%s -- fallback\n", __FUNCTION__));
+       region_maybe_clip(&data.region, gc->pCompositeClip);
+       if (!RegionNotEmpty(&data.region))
+               return;
+
+       if (!sna_gc_move_to_cpu(gc, drawable, &data.region))
+               goto out;
+       if (!sna_drawable_move_region_to_cpu(drawable, &data.region,
+                                            MOVE_READ | MOVE_WRITE))
+               goto out_gc;
+
+       DBG(("%s -- fbPolyArc\n", __FUNCTION__));
+       fbPolyArc(drawable, gc, n, arc);
+       FALLBACK_FLUSH(drawable);
+
+out_gc:
+       sna_gc_move_to_gpu(gc);
+out:
+       RegionUninit(&data.region);
+}
+
+static bool
+sna_poly_fill_rect_blt(DrawablePtr drawable,
+                      struct kgem_bo *bo,
+                      struct sna_damage **damage,
+                      GCPtr gc, uint32_t pixel,
+                      int n, xRectangle *rect,
+                      const BoxRec *extents,
+                      bool clipped)
+{
+       PixmapPtr pixmap = get_drawable_pixmap(drawable);
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+       struct sna_fill_op fill;
+       BoxRec boxes[512], *b = boxes, *const last_box = boxes+ARRAY_SIZE(boxes);
+       int16_t dx, dy;
+
+       DBG(("%s x %d [(%d, %d)x(%d, %d)...]+(%d,%d), clipped?=%d\n",
+            __FUNCTION__, n,
+            rect->x, rect->y, rect->width, rect->height,
+            drawable->x, drawable->y,
+            clipped));
+
+       if (n == 1 && region_is_singular(gc->pCompositeClip)) {
+               BoxRec r;
+               bool success = true;
+
+               r.x1 = rect->x + drawable->x;
+               r.y1 = rect->y + drawable->y;
+               r.x2 = bound(r.x1, rect->width);
+               r.y2 = bound(r.y1, rect->height);
+               if (box_intersect(&r, &gc->pCompositeClip->extents)) {
+                       get_drawable_deltas(drawable, pixmap, &dx, &dy);
+                       r.x1 += dx; r.y1 += dy;
+                       r.x2 += dx; r.y2 += dy;
+                       if (sna->render.fill_one(sna, pixmap, bo, pixel,
+                                                r.x1, r.y1, r.x2, r.y2,
+                                                gc->alu)) {
+                               if (damage) {
+                                       assert_pixmap_contains_box(pixmap, &r);
+                                       if (r.x2 - r.x1 == pixmap->drawable.width &&
+                                           r.y2 - r.y1 == pixmap->drawable.height) {
+                                               sna_damage_all(damage,
+                                                              pixmap->drawable.width,
+                                                              pixmap->drawable.height);
+                                       } else
+                                               sna_damage_add_box(damage, &r);
+                               }
+                               assert_pixmap_damage(pixmap);
+
+                               if ((gc->alu == GXcopy || gc->alu == GXclear) &&
+                                   r.x2 - r.x1 == pixmap->drawable.width &&
+                                   r.y2 - r.y1 == pixmap->drawable.height) {
+                                       struct sna_pixmap *priv = sna_pixmap(pixmap);
+                                       if (bo == priv->gpu_bo) {
+                                               sna_damage_all(&priv->gpu_damage,
+                                                              pixmap->drawable.width,
+                                                              pixmap->drawable.height);
+                                               sna_damage_destroy(&priv->cpu_damage);
+                                               list_del(&priv->list);
+                                               priv->undamaged = false;
+                                               priv->clear = true;
+                                               priv->clear_color = gc->alu == GXcopy ? pixel : 0;
+
+                                               DBG(("%s: pixmap=%ld, marking clear [%08x]\n",
+                                                    __FUNCTION__, pixmap->drawable.serialNumber, priv->clear_color));
+                                       }
+                               }
+                       } else
+                               success = false;
+               }
+
+               return success;
+       }
+
+       if (!sna_fill_init_blt(&fill, sna, pixmap, bo, gc->alu, pixel)) {
+               DBG(("%s: unsupported blt\n", __FUNCTION__));
+               return false;
+       }
+
+       get_drawable_deltas(drawable, pixmap, &dx, &dy);
+       if (!clipped) {
+               dx += drawable->x;
+               dy += drawable->y;
+
+               sna_damage_add_rectangles(damage, rect, n, dx, dy);
+               if (dx|dy) {
+                       do {
+                               unsigned nbox = n;
+                               if (nbox > ARRAY_SIZE(boxes))
+                                       nbox = ARRAY_SIZE(boxes);
+                               n -= nbox;
+                               do {
+                                       b->x1 = rect->x + dx;
+                                       b->y1 = rect->y + dy;
+                                       b->x2 = b->x1 + rect->width;
+                                       b->y2 = b->y1 + rect->height;
+                                       b++;
+                                       rect++;
+                               } while (--nbox);
+                               fill.boxes(sna, &fill, boxes, b-boxes);
+                               b = boxes;
+                       } while (n);
+               } else {
+                       do {
+                               unsigned nbox = n;
+                               if (nbox > ARRAY_SIZE(boxes))
+                                       nbox = ARRAY_SIZE(boxes);
+                               n -= nbox;
+                               do {
+                                       b->x1 = rect->x;
+                                       b->y1 = rect->y;
+                                       b->x2 = b->x1 + rect->width;
+                                       b->y2 = b->y1 + rect->height;
+                                       b++;
+                                       rect++;
+                               } while (--nbox);
+                               fill.boxes(sna, &fill, boxes, b-boxes);
+                               b = boxes;
+                       } while (n);
+               }
+       } else {
+               RegionRec clip;
+
+               region_set(&clip, extents);
+               region_maybe_clip(&clip, gc->pCompositeClip);
+               if (!RegionNotEmpty(&clip))
+                       goto done;
+
+               if (clip.data == NULL) {
+                       do {
+                               b->x1 = rect->x + drawable->x;
+                               b->y1 = rect->y + drawable->y;
+                               b->x2 = bound(b->x1, rect->width);
+                               b->y2 = bound(b->y1, rect->height);
+                               rect++;
+
+                               if (box_intersect(b, &clip.extents)) {
+                                       b->x1 += dx;
+                                       b->x2 += dx;
+                                       b->y1 += dy;
+                                       b->y2 += dy;
+                                       if (++b == last_box) {
+                                               fill.boxes(sna, &fill, boxes, last_box-boxes);
+                                               if (damage)
+                                                       sna_damage_add_boxes(damage, boxes, last_box-boxes, 0, 0);
+                                               b = boxes;
+                                       }
+                               }
+                       } while (--n);
+               } else {
+                       const BoxRec * const clip_start = RegionBoxptr(&clip);
+                       const BoxRec * const clip_end = clip_start + clip.data->numRects;
+                       const BoxRec *c;
+
+                       do {
+                               BoxRec box;
+
+                               box.x1 = rect->x + drawable->x;
+                               box.y1 = rect->y + drawable->y;
+                               box.x2 = bound(box.x1, rect->width);
+                               box.y2 = bound(box.y1, rect->height);
+                               rect++;
+
+                               c = find_clip_box_for_y(clip_start,
+                                                       clip_end,
+                                                       box.y1);
+                               while (c != clip_end) {
+                                       if (box.y2 <= c->y1)
+                                               break;
+
+                                       *b = box;
+                                       if (box_intersect(b, c++)) {
+                                               b->x1 += dx;
+                                               b->x2 += dx;
+                                               b->y1 += dy;
+                                               b->y2 += dy;
+                                               if (++b == last_box) {
+                                                       fill.boxes(sna, &fill, boxes, last_box-boxes);
+                                                       if (damage)
+                                                               sna_damage_add_boxes(damage, boxes, last_box-boxes, 0, 0);
+                                                       b = boxes;
+                                               }
+                                       }
+
+                               }
+                       } while (--n);
+               }
+
+               RegionUninit(&clip);
+               if (b != boxes) {
+                       fill.boxes(sna, &fill, boxes, b-boxes);
+                       if (damage)
+                               sna_damage_add_boxes(damage, boxes, b-boxes, 0, 0);
+               }
+       }
+done:
+       fill.done(sna, &fill);
+       assert_pixmap_damage(pixmap);
+       return true;
+}
+
+static uint32_t
+get_pixel(PixmapPtr pixmap)
+{
+       DBG(("%s\n", __FUNCTION__));
+       if (!sna_pixmap_move_to_cpu(pixmap, MOVE_READ))
+               return 0;
+
+       switch (pixmap->drawable.bitsPerPixel) {
+       case 32: return *(uint32_t *)pixmap->devPrivate.ptr;
+       case 16: return *(uint16_t *)pixmap->devPrivate.ptr;
+       default: return *(uint8_t *)pixmap->devPrivate.ptr;
+       }
+}
+
+static void
+sna_poly_fill_polygon(DrawablePtr draw, GCPtr gc,
+                     int shape, int mode,
+                     int n, DDXPointPtr pt)
+{
+       struct sna_fill_spans data;
+       struct sna_pixmap *priv;
+
+       DBG(("%s(n=%d, PlaneMask: %lx (solid %d), solid fill: %d [style=%d, tileIsPixel=%d], alu=%d)\n", __FUNCTION__,
+            n, gc->planemask, !!PM_IS_SOLID(draw, gc->planemask),
+            (gc->fillStyle == FillSolid ||
+             (gc->fillStyle == FillTiled && gc->tileIsPixel)),
+            gc->fillStyle, gc->tileIsPixel,
+            gc->alu));
+       DBG(("%s: draw=%ld, offset=(%d, %d), size=%dx%d\n",
+            __FUNCTION__, draw->serialNumber,
+            draw->x, draw->y, draw->width, draw->height));
+
+       data.flags = sna_poly_point_extents(draw, gc, mode, n, pt,
+                                           &data.region.extents);
+       if (data.flags == 0) {
+               DBG(("%s, nothing to do\n", __FUNCTION__));
+               return;
+       }
+
+       DBG(("%s: extents(%d, %d), (%d, %d), flags=%x\n", __FUNCTION__,
+            data.region.extents.x1, data.region.extents.y1,
+            data.region.extents.x2, data.region.extents.y2,
+            data.flags));
+
+       data.region.data = NULL;
+
+       if (FORCE_FALLBACK)
+               goto fallback;
+
+       if (!ACCEL_POLY_FILL_POLYGON)
+               goto fallback;
+
+       data.pixmap = get_drawable_pixmap(draw);
+       data.sna = to_sna_from_pixmap(data.pixmap);
+       priv = sna_pixmap(data.pixmap);
+       if (priv == NULL) {
+               DBG(("%s: fallback -- unattached\n", __FUNCTION__));
+               goto fallback;
+       }
+
+       if (wedged(data.sna)) {
+               DBG(("%s: fallback -- wedged\n", __FUNCTION__));
+               goto fallback;
+       }
+
+       if (!PM_IS_SOLID(draw, gc->planemask))
+               goto fallback;
+
+       if ((data.bo = sna_drawable_use_bo(draw,
+                                          (shape == Convex ? use_zero_spans : use_wide_spans)(draw, gc, &data.region.extents),
+                                          &data.region.extents,
+                                          &data.damage))) {
+               uint32_t color;
+
+               sna_gc(gc)->priv = &data;
+               get_drawable_deltas(draw, data.pixmap, &data.dx, &data.dy);
+
+               if (gc_is_solid(gc, &color)) {
+                       struct sna_fill_op fill;
+
+                       if (!sna_fill_init_blt(&fill,
+                                              data.sna, data.pixmap,
+                                              data.bo, gc->alu, color))
+                               goto fallback;
+
+                       data.op = &fill;
+
+                       if ((data.flags & 2) == 0) {
+                               if (data.dx | data.dy)
+                                       sna_gc_ops__tmp.FillSpans = sna_fill_spans__fill_offset;
+                               else
+                                       sna_gc_ops__tmp.FillSpans = sna_fill_spans__fill;
+                       } else {
+                               region_maybe_clip(&data.region,
+                                                 gc->pCompositeClip);
+                               if (!RegionNotEmpty(&data.region))
+                                       return;
+
+                               if (region_is_singular(&data.region))
+                                       sna_gc_ops__tmp.FillSpans = sna_fill_spans__fill_clip_extents;
+                               else
+                                       sna_gc_ops__tmp.FillSpans = sna_fill_spans__fill_clip_boxes;
+                       }
+                       assert(gc->miTranslate);
+                       gc->ops = &sna_gc_ops__tmp;
+
+                       miFillPolygon(draw, gc, shape, mode, n, pt);
+                       fill.done(data.sna, &fill);
+               } else {
+                       sna_gc_ops__tmp.FillSpans = sna_fill_spans__gpu;
+                       gc->ops = &sna_gc_ops__tmp;
+
+                       miFillPolygon(draw, gc, shape, mode, n, pt);
+               }
+
+               gc->ops = (GCOps *)&sna_gc_ops;
+               if (data.damage) {
+                       if (data.dx | data.dy)
+                               pixman_region_translate(&data.region, data.dx, data.dy);
+                       assert_pixmap_contains_box(data.pixmap, &data.region.extents);
+                       sna_damage_add(data.damage, &data.region);
+               }
+               assert_pixmap_damage(data.pixmap);
+               RegionUninit(&data.region);
+               return;
+       }
+
+fallback:
+       DBG(("%s: fallback (%d, %d), (%d, %d)\n", __FUNCTION__,
+            data.region.extents.x1, data.region.extents.y1,
+            data.region.extents.x2, data.region.extents.y2));
+       region_maybe_clip(&data.region, gc->pCompositeClip);
+       if (!RegionNotEmpty(&data.region)) {
+               DBG(("%s: nothing to do, all clipped\n", __FUNCTION__));
+               return;
+       }
+
+       if (!sna_gc_move_to_cpu(gc, draw, &data.region))
+               goto out;
+       if (!sna_drawable_move_region_to_cpu(draw, &data.region,
+                                            drawable_gc_flags(draw, gc, true)))
+               goto out_gc;
+
+       DBG(("%s: fallback -- miFillPolygon -> sna_fill_spans__cpu\n",
+            __FUNCTION__));
+       miFillPolygon(draw, gc, shape, mode, n, pt);
+out_gc:
+       sna_gc_move_to_gpu(gc);
+out:
+       RegionUninit(&data.region);
+}
+
+static struct kgem_bo *
+sna_pixmap_get_source_bo(PixmapPtr pixmap)
+{
+       struct sna_pixmap *priv = sna_pixmap(pixmap);
+
+       if (priv == NULL) {
+               struct kgem_bo *upload;
+               struct sna *sna = to_sna_from_pixmap(pixmap);
+               void *ptr;
+
+               upload = kgem_create_buffer_2d(&sna->kgem,
+                                              pixmap->drawable.width,
+                                              pixmap->drawable.height,
+                                              pixmap->drawable.bitsPerPixel,
+                                              KGEM_BUFFER_WRITE_INPLACE,
+                                              &ptr);
+               if (upload == NULL)
+                       return NULL;
+
+               memcpy_blt(pixmap->devPrivate.ptr, ptr,
+                          pixmap->drawable.bitsPerPixel,
+                          pixmap->devKind, upload->pitch,
+                          0, 0,
+                          0, 0,
+                          pixmap->drawable.width,
+                          pixmap->drawable.height);
+
+               return upload;
+       }
+
+       if (priv->gpu_damage && !sna_pixmap_move_to_gpu(pixmap, MOVE_READ))
+               return NULL;
+
+       if (priv->cpu_damage && priv->cpu_bo)
+               return kgem_bo_reference(priv->cpu_bo);
+
+       if (!sna_pixmap_force_to_gpu(pixmap, MOVE_READ))
+               return NULL;
+
+       return kgem_bo_reference(priv->gpu_bo);
+}
+
+/*
+static bool
+tile(DrawablePtr drawable,
+       struct kgem_bo *bo, struct sna_damage **damage,
+       PixmapPtr tile, const DDXPointRec * const origin, int alu,
+       int n, xRectangle *rect,
+       const BoxRec *extents, unsigned clipped)
+       */
+
+static bool
+sna_poly_fill_rect_tiled_8x8_blt(DrawablePtr drawable,
+                                struct kgem_bo *bo, struct sna_damage **damage,
+                                struct kgem_bo *tile_bo, GCPtr gc,
+                                int n, const xRectangle *r,
+                                const BoxRec *extents, unsigned clipped)
+{
+       PixmapPtr pixmap = get_drawable_pixmap(drawable);
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+       const DDXPointRec * const origin = &gc->patOrg;
+       uint32_t br00, br13;
+       int tx, ty;
+       int16_t dx, dy;
+       uint32_t *b;
+
+       if (NO_TILE_8x8)
+               return false;
+
+       DBG(("%s x %d [(%d, %d)x(%d, %d)...], clipped=%x\n",
+            __FUNCTION__, n, r->x, r->y, r->width, r->height, clipped));
+
+       kgem_set_mode(&sna->kgem, KGEM_BLT);
+       if (!kgem_check_batch(&sna->kgem, 8+2*3) ||
+           !kgem_check_reloc(&sna->kgem, 2) ||
+           !kgem_check_bo_fenced(&sna->kgem, bo)) {
+               _kgem_submit(&sna->kgem);
+               _kgem_set_mode(&sna->kgem, KGEM_BLT);
+       }
+
+       br00 = XY_SCANLINE_BLT;
+       br13 = bo->pitch;
+       if (sna->kgem.gen >= 40 && bo->tiling) {
+               br00 |= BLT_DST_TILED;
+               br13 >>= 2;
+       }
+       br13 |= blt_depth(drawable->depth) << 24;
+       br13 |= fill_ROP[gc->alu] << 16;
+
+       get_drawable_deltas(drawable, pixmap, &dx, &dy);
+       assert(extents->x1 + dx >= 0);
+       assert(extents->y1 + dy >= 0);
+       assert(extents->x2 + dx <= pixmap->drawable.width);
+       assert(extents->y2 + dy <= pixmap->drawable.height);
+
+       if (!clipped) {
+               dx += drawable->x;
+               dy += drawable->y;
+
+               sna_damage_add_rectangles(damage, r, n, dx, dy);
+               if (n == 1) {
+                       tx = (r->x - origin->x) % 8;
+                       if (tx < 0)
+                               tx = 8 - tx;
+                       ty = (r->y - origin->y) % 8;
+                       if (ty < 0)
+                               ty = 8 - ty;
+
+                       assert(r->x + dx >= 0);
+                       assert(r->y + dy >= 0);
+                       assert(r->x + dx + r->width  <= pixmap->drawable.width);
+                       assert(r->y + dy + r->height <= pixmap->drawable.height);
+
+                       b = sna->kgem.batch + sna->kgem.nbatch;
+                       b[0] = XY_PAT_BLT | tx << 12 | ty << 8 | 3 << 20 | (br00 & BLT_DST_TILED);
+                       b[1] = br13;
+                       b[2] = (r->y + dy) << 16 | (r->x + dx);
+                       b[3] = (r->y + r->height + dy) << 16 | (r->x + r->width + dx);
+                       b[4] = kgem_add_reloc(&sna->kgem, sna->kgem.nbatch + 4, bo,
+                                             I915_GEM_DOMAIN_RENDER << 16 |
+                                             I915_GEM_DOMAIN_RENDER |
+                                             KGEM_RELOC_FENCED,
+                                             0);
+                       b[5] = kgem_add_reloc(&sna->kgem, sna->kgem.nbatch + 5, tile_bo,
+                                             I915_GEM_DOMAIN_RENDER << 16 |
+                                             KGEM_RELOC_FENCED,
+                                             0);
+                       sna->kgem.nbatch += 6;
+               } else do {
+                       int n_this_time;
+
+                       b = sna->kgem.batch + sna->kgem.nbatch;
+                       b[0] = XY_SETUP_BLT | 3 << 20;
+                       b[1] = br13;
+                       b[2] = 0;
+                       b[3] = 0;
+                       b[4] = kgem_add_reloc(&sna->kgem, sna->kgem.nbatch + 4, bo,
+                                             I915_GEM_DOMAIN_RENDER << 16 |
+                                             I915_GEM_DOMAIN_RENDER |
+                                             KGEM_RELOC_FENCED,
+                                             0);
+                       b[5] = gc->bgPixel;
+                       b[6] = gc->fgPixel;
+                       b[7] = kgem_add_reloc(&sna->kgem, sna->kgem.nbatch + 7, tile_bo,
+                                             I915_GEM_DOMAIN_RENDER << 16 |
+                                             KGEM_RELOC_FENCED,
+                                             0);
+                       sna->kgem.nbatch += 8;
+
+                       n_this_time = n;
+                       if (3*n_this_time > sna->kgem.surface - sna->kgem.nbatch - KGEM_BATCH_RESERVED)
+                               n_this_time = (sna->kgem.surface - sna->kgem.nbatch - KGEM_BATCH_RESERVED) / 3;
+                       assert(n_this_time);
+                       n -= n_this_time;
+
+                       b = sna->kgem.batch + sna->kgem.nbatch;
+                       sna->kgem.nbatch += 3*n_this_time;
+                       do {
+                               assert(r->x + dx >= 0);
+                               assert(r->y + dy >= 0);
+                               assert(r->x + dx + r->width  <= pixmap->drawable.width);
+                               assert(r->y + dy + r->height <= pixmap->drawable.height);
+
+                               tx = (r->x - origin->x) % 8;
+                               if (tx < 0)
+                                       tx = 8 - tx;
+                               ty = (r->y - origin->y) % 8;
+                               if (ty < 0)
+                                       ty = 8 - ty;
+
+                               b[0] = br00 | tx << 12 | ty << 8;
+                               b[1] = (r->y + dy) << 16 | (r->x + dx);
+                               b[2] = (r->y + r->height + dy) << 16 | (r->x + r->width + dx);
+                               b += 3; r++;
+                       } while (--n_this_time);
+
+                       if (!n)
+                               break;
+
+                       _kgem_submit(&sna->kgem);
+                       _kgem_set_mode(&sna->kgem, KGEM_BLT);
+               } while (1);
+       } else {
+               RegionRec clip;
+
+               region_set(&clip, extents);
+               region_maybe_clip(&clip, gc->pCompositeClip);
+               if (!RegionNotEmpty(&clip))
+                       goto done;
+
+               b = sna->kgem.batch + sna->kgem.nbatch;
+               b[0] = XY_SETUP_BLT | 3 << 20;
+               b[1] = br13;
+               b[2] = 0;
+               b[3] = 0;
+               b[4] = kgem_add_reloc(&sna->kgem, sna->kgem.nbatch + 4, bo,
+                                     I915_GEM_DOMAIN_RENDER << 16 |
+                                     I915_GEM_DOMAIN_RENDER |
+                                     KGEM_RELOC_FENCED,
+                                     0);
+               b[5] = gc->bgPixel;
+               b[6] = gc->fgPixel;
+               b[7] = kgem_add_reloc(&sna->kgem, sna->kgem.nbatch + 7, tile_bo,
+                                     I915_GEM_DOMAIN_RENDER << 16 |
+                                     KGEM_RELOC_FENCED,
+                                     0);
+               sna->kgem.nbatch += 8;
+
+               if (clip.data == NULL) {
+                       const BoxRec *c = &clip.extents;
+                       while (n--) {
+                               BoxRec box;
+
+                               box.x1 = r->x + drawable->x;
+                               box.y1 = r->y + drawable->y;
+                               box.x2 = bound(box.x1, r->width);
+                               box.y2 = bound(box.y1, r->height);
+                               r++;
+
+                               if (box_intersect(&box, c)) {
+                                       if (!kgem_check_batch(&sna->kgem, 3)) {
+                                               _kgem_submit(&sna->kgem);
+                                               _kgem_set_mode(&sna->kgem, KGEM_BLT);
+                                               b = sna->kgem.batch + sna->kgem.nbatch;
+                                               b[0] = XY_SETUP_BLT | 3 << 20;
+                                               b[1] = br13;
+                                               b[2] = 0;
+                                               b[3] = 0;
+                                               b[4] = kgem_add_reloc(&sna->kgem, sna->kgem.nbatch + 4, bo,
+                                                                     I915_GEM_DOMAIN_RENDER << 16 |
+                                                                     I915_GEM_DOMAIN_RENDER |
+                                                                     KGEM_RELOC_FENCED,
+                                                                     0);
+                                               b[5] = gc->bgPixel;
+                                               b[6] = gc->fgPixel;
+                                               b[7] = kgem_add_reloc(&sna->kgem, sna->kgem.nbatch + 7, tile_bo,
+                                                                     I915_GEM_DOMAIN_RENDER << 16 |
+                                                                     KGEM_RELOC_FENCED,
+                                                                     0);
+                                               sna->kgem.nbatch += 8;
+                                       }
+
+                                       assert(box.x1 + dx >= 0);
+                                       assert(box.y1 + dy >= 0);
+                                       assert(box.x2 + dx <= pixmap->drawable.width);
+                                       assert(box.y2 + dy <= pixmap->drawable.height);
+
+                                       ty = (box.y1 - drawable->y - origin->y) % 8;
+                                       if (ty < 0)
+                                               ty = 8 - ty;
+
+                                       tx = (box.x1 - drawable->x - origin->x) % 8;
+                                       if (tx < 0)
+                                               tx = 8 - tx;
+
+                                       b = sna->kgem.batch + sna->kgem.nbatch;
+                                       b[0] = br00 | tx << 12 | ty << 8;
+                                       b[1] = (box.y1 + dy) << 16 | (box.x1 + dx);
+                                       b[2] = (box.y2 + dy) << 16 | (box.x2 + dx);
+                                       sna->kgem.nbatch += 3;
+                               }
+                       }
+               } else {
+                       const BoxRec * const clip_start = RegionBoxptr(&clip);
+                       const BoxRec * const clip_end = clip_start + clip.data->numRects;
+                       const BoxRec *c;
+
+                       do {
+                               BoxRec box;
+
+                               box.x1 = r->x + drawable->x;
+                               box.y1 = r->y + drawable->y;
+                               box.x2 = bound(box.x1, r->width);
+                               box.y2 = bound(box.y1, r->height);
+                               r++;
+
+                               c = find_clip_box_for_y(clip_start,
+                                                       clip_end,
+                                                       box.y1);
+                               while (c != clip_end) {
+                                       BoxRec bb;
+
+                                       if (box.y2 <= c->y1)
+                                               break;
+
+                                       bb = box;
+                                       if (box_intersect(&bb, c++)) {
+                                               if (!kgem_check_batch(&sna->kgem, 3)) {
+                                                       _kgem_submit(&sna->kgem);
+                                                       _kgem_set_mode(&sna->kgem, KGEM_BLT);
+                                                       b = sna->kgem.batch + sna->kgem.nbatch;
+                                                       b[0] = XY_SETUP_BLT | 3 << 20;
+                                                       b[1] = br13;
+                                                       b[2] = 0;
+                                                       b[3] = 0;
+                                                       b[4] = kgem_add_reloc(&sna->kgem, sna->kgem.nbatch + 4, bo,
+                                                                             I915_GEM_DOMAIN_RENDER << 16 |
+                                                                             I915_GEM_DOMAIN_RENDER |
+                                                                             KGEM_RELOC_FENCED,
+                                                                             0);
+                                                       b[5] = gc->bgPixel;
+                                                       b[6] = gc->fgPixel;
+                                                       b[7] = kgem_add_reloc(&sna->kgem, sna->kgem.nbatch + 7, tile_bo,
+                                                                             I915_GEM_DOMAIN_RENDER << 16 |
+                                                                             KGEM_RELOC_FENCED,
+                                                                             0);
+                                                       sna->kgem.nbatch += 8;
+                                               }
+
+                                               assert(bb.x1 + dx >= 0);
+                                               assert(bb.y1 + dy >= 0);
+                                               assert(bb.x2 + dx <= pixmap->drawable.width);
+                                               assert(bb.y2 + dy <= pixmap->drawable.height);
+
+                                               ty = (bb.y1 - drawable->y - origin->y) % 8;
+                                               if (ty < 0)
+                                                       ty = 8 - ty;
+
+                                               tx = (bb.x1 - drawable->x - origin->x) % 8;
+                                               if (tx < 0)
+                                                       tx = 8 - tx;
+
+                                               b = sna->kgem.batch + sna->kgem.nbatch;
+                                               b[0] = br00 | tx << 12 | ty << 8;
+                                               b[1] = (bb.y1 + dy) << 16 | (bb.x1 + dx);
+                                               b[2] = (bb.y2 + dy) << 16 | (bb.x2 + dx);
+                                               sna->kgem.nbatch += 3;
+                                       }
+                               }
+                       } while (--n);
+               }
+       }
+done:
+       assert_pixmap_damage(pixmap);
+       sna->blt_state.fill_bo = 0;
+       return true;
+}
+
+static bool
+sna_poly_fill_rect_tiled_nxm_blt(DrawablePtr drawable,
+                                struct kgem_bo *bo,
+                                struct sna_damage **damage,
+                                GCPtr gc, int n, const xRectangle *rect,
+                                const BoxRec *extents, unsigned clipped)
+{
+       PixmapPtr pixmap = get_drawable_pixmap(drawable);
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+       PixmapPtr tile = gc->tile.pixmap;
+       struct kgem_bo *upload;
+       int w, h, cpp;
+       void *ptr;
+       bool ret;
+
+       DBG(("%s: %dx%d\n", __FUNCTION__,
+            tile->drawable.width, tile->drawable.height));
+
+       if (!sna_pixmap_move_to_cpu(tile, MOVE_READ))
+               return false;
+
+       upload = kgem_create_buffer(&sna->kgem, 8*tile->drawable.bitsPerPixel,
+                                   KGEM_BUFFER_WRITE_INPLACE,
+                                   &ptr);
+       if (upload == NULL)
+               return false;
+
+       assert(tile->drawable.height && tile->drawable.height <= 8);
+       assert(tile->drawable.width && tile->drawable.width <= 8);
+
+       cpp = tile->drawable.bitsPerPixel/8;
+       for (h = 0; h < tile->drawable.height; h++) {
+               uint8_t *src = (uint8_t *)tile->devPrivate.ptr + tile->devKind*h;
+               uint8_t *dst = (uint8_t *)ptr + 8*cpp*h;
+
+               w = tile->drawable.width*cpp;
+               memcpy(dst, src, w);
+               while (w < 8*cpp) {
+                       memcpy(dst+w, dst, w);
+                       w *= 2;
+               }
+       }
+       while (h < 8) {
+               memcpy((uint8_t*)ptr + h*w, ptr, h*w);
+               h *= 2;
+       }
+
+       ret = sna_poly_fill_rect_tiled_8x8_blt(drawable, bo, damage,
+                                              upload, gc, n, rect,
+                                              extents, clipped);
+
+       kgem_bo_destroy(&sna->kgem, upload);
+       return ret;
+}
+
+static bool
+sna_poly_fill_rect_tiled_blt(DrawablePtr drawable,
+                            struct kgem_bo *bo,
+                            struct sna_damage **damage,
+                            GCPtr gc, int n, xRectangle *rect,
+                            const BoxRec *extents, unsigned clipped)
+{
+       PixmapPtr pixmap = get_drawable_pixmap(drawable);
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+       PixmapPtr tile = gc->tile.pixmap;
+       struct kgem_bo *tile_bo;
+       const DDXPointRec * const origin = &gc->patOrg;
+       struct sna_copy_op copy;
+       CARD32 alu = gc->alu;
+       int tile_width, tile_height;
+       int16_t dx, dy;
+
+       DBG(("%s x %d [(%d, %d)x(%d, %d)...]\n",
+            __FUNCTION__, n, rect->x, rect->y, rect->width, rect->height));
+
+       tile_width = tile->drawable.width;
+       tile_height = tile->drawable.height;
+       if ((tile_width | tile_height) == 1) {
+               DBG(("%s: single pixel tile pixmap ,converting to solid fill\n",
+                    __FUNCTION__));
+               return sna_poly_fill_rect_blt(drawable, bo, damage,
+                                             gc, get_pixel(tile),
+                                             n, rect,
+                                             extents, clipped);
+       }
+
+       /* XXX [248]x[238] tiling can be reduced to a pattern fill.
+        * Also we can do the lg2 reduction for BLT and use repeat modes for
+        * RENDER.
+        */
+
+       if ((tile->drawable.width | tile->drawable.height) == 8) {
+               bool ret;
+
+               tile_bo = sna_pixmap_get_source_bo(tile);
+               ret = sna_poly_fill_rect_tiled_8x8_blt(drawable, bo, damage,
+                                                      tile_bo, gc, n, rect,
+                                                      extents, clipped);
+               kgem_bo_destroy(&sna->kgem, tile_bo);
+
+               return ret;
+       }
+
+       if ((tile->drawable.width | tile->drawable.height) <= 0xc &&
+           is_power_of_two(tile->drawable.width) &&
+           is_power_of_two(tile->drawable.height))
+               return sna_poly_fill_rect_tiled_nxm_blt(drawable, bo, damage,
+                                                       gc, n, rect,
+                                                       extents, clipped);
+
+       tile_bo = sna_pixmap_get_source_bo(tile);
+       if (tile_bo == NULL) {
+               DBG(("%s: unable to move tile go GPU, fallback\n",
+                    __FUNCTION__));
+               return false;
+       }
+
+       if (!sna_copy_init_blt(&copy, sna, tile, tile_bo, pixmap, bo, alu)) {
+               DBG(("%s: unsupported blt\n", __FUNCTION__));
+               kgem_bo_destroy(&sna->kgem, tile_bo);
+               return false;
+       }
+
+       get_drawable_deltas(drawable, pixmap, &dx, &dy);
+       if (!clipped) {
+               dx += drawable->x;
+               dy += drawable->y;
+
+               sna_damage_add_rectangles(damage, rect, n, dx, dy);
+               do {
+                       xRectangle r = *rect++;
+                       int16_t tile_y = (r.y - origin->y) % tile_height;
+                       if (tile_y < 0)
+                               tile_y += tile_height;
+
+                       assert(r.x + dx >= 0);
+                       assert(r.y + dy >= 0);
+                       assert(r.x + dx + r.width  <= pixmap->drawable.width);
+                       assert(r.y + dy + r.height <= pixmap->drawable.height);
+
+                       r.y += dy;
+                       do {
+                               int16_t width = r.width;
+                               int16_t x = r.x + dx, tile_x;
+                               int16_t h = tile_height - tile_y;
+                               if (h > r.height)
+                                       h = r.height;
+                               r.height -= h;
+
+                               tile_x = (r.x - origin->x) % tile_width;
+                               if (tile_x < 0)
+                                       tile_x += tile_width;
+
+                               do {
+                                       int16_t w = tile_width - tile_x;
+                                       if (w > width)
+                                               w = width;
+                                       width -= w;
+
+                                       copy.blt(sna, &copy,
+                                                tile_x, tile_y,
+                                                w, h,
+                                                x, r.y);
+
+                                       x += w;
+                                       tile_x = 0;
+                               } while (width);
+                               r.y += h;
+                               tile_y = 0;
+                       } while (r.height);
+               } while (--n);
+       } else {
+               RegionRec clip;
+
+               region_set(&clip, extents);
+               region_maybe_clip(&clip, gc->pCompositeClip);
+               if (!RegionNotEmpty(&clip))
+                       goto done;
+
+               if (clip.data == NULL) {
+                       const BoxRec *box = &clip.extents;
+                       while (n--) {
+                               BoxRec r;
+
+                               r.x1 = rect->x + drawable->x;
+                               r.y1 = rect->y + drawable->y;
+                               r.x2 = bound(r.x1, rect->width);
+                               r.y2 = bound(r.y1, rect->height);
+                               rect++;
+
+                               if (box_intersect(&r, box)) {
+                                       int height = r.y2 - r.y1;
+                                       int dst_y = r.y1;
+                                       int tile_y = (r.y1 - drawable->y - origin->y) % tile_height;
+                                       if (tile_y < 0)
+                                               tile_y += tile_height;
+
+                                       while (height) {
+                                               int width = r.x2 - r.x1;
+                                               int dst_x = r.x1, tile_x;
+                                               int h = tile_height - tile_y;
+                                               if (h > height)
+                                                       h = height;
+                                               height -= h;
+
+                                               tile_x = (r.x1 - drawable->x - origin->x) % tile_width;
+                                               if (tile_x < 0)
+                                                       tile_x += tile_width;
+
+                                               while (width > 0) {
+                                                       int w = tile_width - tile_x;
+                                                       if (w > width)
+                                                               w = width;
+                                                       width -= w;
+
+                                                       copy.blt(sna, &copy,
+                                                                tile_x, tile_y,
+                                                                w, h,
+                                                                dst_x + dx, dst_y + dy);
+                                                       if (damage) {
+                                                               BoxRec b;
+
+                                                               b.x1 = dst_x + dx;
+                                                               b.y1 = dst_y + dy;
+                                                               b.x2 = b.x1 + w;
+                                                               b.y2 = b.y1 + h;
+
+                                                               assert_pixmap_contains_box(pixmap, &b);
+                                                               sna_damage_add_box(damage, &b);
+                                                       }
+
+                                                       dst_x += w;
+                                                       tile_x = 0;
+                                               }
+                                               dst_y += h;
+                                               tile_y = 0;
+                                       }
+                               }
+                       }
+               } else {
+                       while (n--) {
+                               RegionRec region;
+                               BoxRec *box;
+                               int nbox;
+
+                               region.extents.x1 = rect->x + drawable->x;
+                               region.extents.y1 = rect->y + drawable->y;
+                               region.extents.x2 = bound(region.extents.x1, rect->width);
+                               region.extents.y2 = bound(region.extents.y1, rect->height);
+                               rect++;
+
+                               region.data = NULL;
+                               RegionIntersect(&region, &region, &clip);
+
+                               nbox = REGION_NUM_RECTS(&region);
+                               box = REGION_RECTS(&region);
+                               while (nbox--) {
+                                       int height = box->y2 - box->y1;
+                                       int dst_y = box->y1;
+                                       int tile_y = (box->y1 - drawable->y - origin->y) % tile_height;
+                                       if (tile_y < 0)
+                                               tile_y += tile_height;
+
+                                       while (height) {
+                                               int width = box->x2 - box->x1;
+                                               int dst_x = box->x1, tile_x;
+                                               int h = tile_height - tile_y;
+                                               if (h > height)
+                                                       h = height;
+                                               height -= h;
+
+                                               tile_x = (box->x1 - drawable->x - origin->x) % tile_width;
+                                               if (tile_x < 0)
+                                                       tile_x += tile_width;
+
+                                               while (width > 0) {
+                                                       int w = tile_width - tile_x;
+                                                       if (w > width)
+                                                               w = width;
+                                                       width -= w;
+
+                                                       copy.blt(sna, &copy,
+                                                                tile_x, tile_y,
+                                                                w, h,
+                                                                dst_x + dx, dst_y + dy);
+                                                       if (damage) {
+                                                               BoxRec b;
+
+                                                               b.x1 = dst_x + dx;
+                                                               b.y1 = dst_y + dy;
+                                                               b.x2 = b.x1 + w;
+                                                               b.y2 = b.y1 + h;
+
+                                                               assert_pixmap_contains_box(pixmap, &b);
+                                                               sna_damage_add_box(damage, &b);
+                                                       }
+
+                                                       dst_x += w;
+                                                       tile_x = 0;
+                                               }
+                                               dst_y += h;
+                                               tile_y = 0;
+                                       }
+                                       box++;
+                               }
+
+                               RegionUninit(&region);
+                       }
+               }
+
+               RegionUninit(&clip);
+       }
+done:
+       copy.done(sna, &copy);
+       assert_pixmap_damage(pixmap);
+       kgem_bo_destroy(&sna->kgem, tile_bo);
+       return true;
+}
+
+static bool
+sna_poly_fill_rect_stippled_8x8_blt(DrawablePtr drawable,
+                                   struct kgem_bo *bo,
+                                   struct sna_damage **damage,
+                                   GCPtr gc, int n, xRectangle *r,
+                                   const BoxRec *extents, unsigned clipped)
+{
+       PixmapPtr pixmap = get_drawable_pixmap(drawable);
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+       uint32_t pat[2] = {0, 0}, br00, br13;
+       int16_t dx, dy;
+       uint32_t *b;
+
+       if (NO_STIPPLE_8x8)
+               return false;
+
+       DBG(("%s: alu=%d, upload (%d, %d), (%d, %d), origin (%d, %d)\n",
+            __FUNCTION__, gc->alu,
+            extents->x1, extents->y1,
+            extents->x2, extents->y2,
+            gc->patOrg.x, gc->patOrg.y));
+
+       get_drawable_deltas(drawable, pixmap, &dx, &dy);
+       {
+               unsigned px = (0 - gc->patOrg.x - dx) & 7;
+               unsigned py = (0 - gc->patOrg.y - dy) & 7;
+               DBG(("%s: pat offset (%d, %d)\n", __FUNCTION__ ,px, py));
+               br00 = XY_SCANLINE_BLT | px << 12 | py << 8 | 3 << 20;
+               br13 = bo->pitch;
+               if (sna->kgem.gen >= 40 && bo->tiling) {
+                       br00 |= BLT_DST_TILED;
+                       br13 >>= 2;
+               }
+               br13 |= (gc->fillStyle == FillStippled) << 28;
+               br13 |= blt_depth(drawable->depth) << 24;
+               br13 |= fill_ROP[gc->alu] << 16;
+       }
+
+       {
+               uint8_t *dst = (uint8_t *)pat;
+               const uint8_t *src = gc->stipple->devPrivate.ptr;
+               int stride = gc->stipple->devKind;
+               int j = gc->stipple->drawable.height;
+               do {
+                       *dst++ = byte_reverse(*src);
+                       src += stride;
+               } while (--j);
+       }
+
+       kgem_set_mode(&sna->kgem, KGEM_BLT);
+       if (!kgem_check_batch(&sna->kgem, 9 + 2*3) ||
+           !kgem_check_bo_fenced(&sna->kgem, bo) ||
+           !kgem_check_reloc(&sna->kgem, 1)) {
+               _kgem_submit(&sna->kgem);
+               _kgem_set_mode(&sna->kgem, KGEM_BLT);
+       }
+
+       if (!clipped) {
+               dx += drawable->x;
+               dy += drawable->y;
+
+               sna_damage_add_rectangles(damage, r, n, dx, dy);
+               if (n == 1) {
+                       DBG(("%s: single unclipped rect (%d, %d)x(%d, %d)\n",
+                            __FUNCTION__, r->x + dx, r->y + dy, r->width, r->height));
+
+                       b = sna->kgem.batch + sna->kgem.nbatch;
+                       b[0] = XY_MONO_PAT | (br00 & (BLT_DST_TILED | 0x7<<12 | 0x7<<8)) | 3<<20;
+                       b[1] = br13;
+                       b[2] = (r->y + dy) << 16 | (r->x + dx);
+                       b[3] = (r->y + r->height + dy) << 16 | (r->x + r->width + dx);
+                       b[4] = kgem_add_reloc(&sna->kgem, sna->kgem.nbatch + 4, bo,
+                                             I915_GEM_DOMAIN_RENDER << 16 |
+                                             I915_GEM_DOMAIN_RENDER |
+                                             KGEM_RELOC_FENCED,
+                                             0);
+                       b[5] = gc->bgPixel;
+                       b[6] = gc->fgPixel;
+                       b[7] = pat[0];
+                       b[8] = pat[1];
+                       sna->kgem.nbatch += 9;
+               } else do {
+                       int n_this_time;
+
+                       b = sna->kgem.batch + sna->kgem.nbatch;
+                       b[0] = XY_SETUP_MONO_PATTERN_SL_BLT | 3 << 20;
+                       b[1] = br13;
+                       b[2] = 0;
+                       b[3] = 0;
+                       b[4] = kgem_add_reloc(&sna->kgem, sna->kgem.nbatch + 4, bo,
+                                             I915_GEM_DOMAIN_RENDER << 16 |
+                                             I915_GEM_DOMAIN_RENDER |
+                                             KGEM_RELOC_FENCED,
+                                             0);
+                       b[5] = gc->bgPixel;
+                       b[6] = gc->fgPixel;
+                       b[7] = pat[0];
+                       b[8] = pat[1];
+                       sna->kgem.nbatch += 9;
+
+                       n_this_time = n;
+                       if (3*n_this_time > sna->kgem.surface - sna->kgem.nbatch - KGEM_BATCH_RESERVED)
+                               n_this_time = (sna->kgem.surface - sna->kgem.nbatch - KGEM_BATCH_RESERVED) / 3;
+                       assert(n_this_time);
+                       n -= n_this_time;
+
+                       b = sna->kgem.batch + sna->kgem.nbatch;
+                       sna->kgem.nbatch += 3 * n_this_time;
+                       do {
+                               DBG(("%s: rect (%d, %d)x(%d, %d)\n",
+                                    __FUNCTION__, r->x + dx, r->y + dy, r->width, r->height));
+                               assert(r->x + dx >= 0);
+                               assert(r->y + dy >= 0);
+                               assert(r->x + dx + r->width  <= pixmap->drawable.width);
+                               assert(r->y + dy + r->height <= pixmap->drawable.height);
+
+                               b[0] = br00;
+                               b[1] = (r->y + dy) << 16 | (r->x + dx);
+                               b[2] = (r->y + r->height + dy) << 16 | (r->x + r->width + dx);
+
+                               b += 3; r++;
+                       } while(--n_this_time);
+
+                       if (!n)
+                               break;
+
+                       _kgem_submit(&sna->kgem);
+                       _kgem_set_mode(&sna->kgem, KGEM_BLT);
+               } while (1);
+       } else {
+               RegionRec clip;
+
+               region_set(&clip, extents);
+               region_maybe_clip(&clip, gc->pCompositeClip);
+               if (!RegionNotEmpty(&clip))
+                       return true;
+
+               b = sna->kgem.batch + sna->kgem.nbatch;
+               b[0] = XY_SETUP_MONO_PATTERN_SL_BLT | 3 << 20;
+               b[1] = br13;
+               b[2] = 0;
+               b[3] = 0;
+               b[4] = kgem_add_reloc(&sna->kgem, sna->kgem.nbatch + 4, bo,
+                                     I915_GEM_DOMAIN_RENDER << 16 |
+                                     I915_GEM_DOMAIN_RENDER |
+                                     KGEM_RELOC_FENCED,
+                                     0);
+               b[5] = gc->bgPixel;
+               b[6] = gc->fgPixel;
+               b[7] = pat[0];
+               b[8] = pat[1];
+               sna->kgem.nbatch += 9;
+
+               if (clip.data == NULL) {
+                       do {
+                               BoxRec box;
+
+                               box.x1 = r->x + drawable->x;
+                               box.y1 = r->y + drawable->y;
+                               box.x2 = bound(box.x1, r->width);
+                               box.y2 = bound(box.y1, r->height);
+                               r++;
+
+                               if (box_intersect(&box, &clip.extents)) {
+                                       if (!kgem_check_batch(&sna->kgem, 3)) {
+                                               _kgem_submit(&sna->kgem);
+                                               _kgem_set_mode(&sna->kgem, KGEM_BLT);
+
+                                               b = sna->kgem.batch + sna->kgem.nbatch;
+                                               b[0] = XY_SETUP_MONO_PATTERN_SL_BLT | 3 << 20;
+                                               b[1] = br13;
+                                               b[2] = 0;
+                                               b[3] = 0;
+                                               b[4] = kgem_add_reloc(&sna->kgem, sna->kgem.nbatch + 4, bo,
+                                                                     I915_GEM_DOMAIN_RENDER << 16 |
+                                                                     I915_GEM_DOMAIN_RENDER |
+                                                                     KGEM_RELOC_FENCED,
+                                                                     0);
+                                               b[5] = gc->bgPixel;
+                                               b[6] = gc->fgPixel;
+                                               b[7] = pat[0];
+                                               b[8] = pat[1];
+                                               sna->kgem.nbatch += 9;
+                                       }
+
+                                       b = sna->kgem.batch + sna->kgem.nbatch;
+                                       sna->kgem.nbatch += 3;
+                                       b[0] = br00;
+                                       b[1] = (box.y1 + dy) << 16 | (box.x1 + dx);
+                                       b[2] = (box.y2 + dy) << 16 | (box.x2 + dx);
+                               }
+                       } while (--n);
+               } else {
+                       const BoxRec * const clip_start = RegionBoxptr(&clip);
+                       const BoxRec * const clip_end = clip_start + clip.data->numRects;
+                       const BoxRec *c;
+
+                       do {
+                               BoxRec box;
+
+                               box.x1 = r->x + drawable->x;
+                               box.y1 = r->y + drawable->y;
+                               box.x2 = bound(box.x1, r->width);
+                               box.y2 = bound(box.y1, r->height);
+                               r++;
+
+                               c = find_clip_box_for_y(clip_start,
+                                                       clip_end,
+                                                       box.y1);
+                               while (c != clip_end) {
+                                       BoxRec bb;
+                                       if (box.y2 <= c->y1)
+                                               break;
+
+                                       bb = box;
+                                       if (box_intersect(&bb, c++)) {
+                                               if (!kgem_check_batch(&sna->kgem, 3)) {
+                                                       _kgem_submit(&sna->kgem);
+                                                       _kgem_set_mode(&sna->kgem, KGEM_BLT);
+
+                                                       b = sna->kgem.batch + sna->kgem.nbatch;
+                                                       b[0] = XY_SETUP_MONO_PATTERN_SL_BLT | 3 << 20;
+                                                       b[1] = br13;
+                                                       b[2] = 0;
+                                                       b[3] = 0;
+                                                       b[4] = kgem_add_reloc(&sna->kgem, sna->kgem.nbatch + 4, bo,
+                                                                             I915_GEM_DOMAIN_RENDER << 16 |
+                                                                             I915_GEM_DOMAIN_RENDER |
+                                                                             KGEM_RELOC_FENCED,
+                                                                             0);
+                                                       b[5] = gc->bgPixel;
+                                                       b[6] = gc->fgPixel;
+                                                       b[7] = pat[0];
+                                                       b[8] = pat[1];
+                                                       sna->kgem.nbatch += 9;
+                                               }
+
+                                               b = sna->kgem.batch + sna->kgem.nbatch;
+                                               sna->kgem.nbatch += 3;
+                                               b[0] = br00;
+                                               b[1] = (bb.y1 + dy) << 16 | (bb.x1 + dx);
+                                               b[2] = (bb.y2 + dy) << 16 | (bb.x2 + dx);
+                                       }
+                               }
+                       } while (--n);
+               }
+       }
+
+       assert_pixmap_damage(pixmap);
+       sna->blt_state.fill_bo = 0;
+       return true;
+}
+
+static bool
+sna_poly_fill_rect_stippled_nxm_blt(DrawablePtr drawable,
+                                   struct kgem_bo *bo,
+                                   struct sna_damage **damage,
+                                   GCPtr gc, int n, xRectangle *r,
+                                   const BoxRec *extents, unsigned clipped)
+{
+       PixmapPtr scratch, stipple;
+       uint8_t bytes[8], *dst = bytes;
+       const uint8_t *src, *end;
+       int j, stride;
+       bool ret;
+
+       DBG(("%s: expanding %dx%d stipple to 8x8\n",
+            __FUNCTION__,
+            gc->stipple->drawable.width,
+            gc->stipple->drawable.height));
+
+       scratch = GetScratchPixmapHeader(drawable->pScreen,
+                                        8, 8, 1, 1, 1, bytes);
+       if (scratch == NullPixmap)
+               return false;
+
+       stipple = gc->stipple;
+       gc->stipple = scratch;
+
+       stride = stipple->devKind;
+       src = stipple->devPrivate.ptr;
+       end = src + stride * stipple->drawable.height;
+       for(j = 0; j < 8; j++) {
+               switch (stipple->drawable.width) {
+               case 1: *dst = (*src & 1) * 0xff; break;
+               case 2: *dst = (*src & 3) * 0x55; break;
+               case 4: *dst = (*src & 15) * 0x11; break;
+               case 8: *dst = *src; break;
+               default: assert(0); break;
+               }
+               dst++;
+               src += stride;
+               if (src == end)
+                       src = stipple->devPrivate.ptr;
+       }
+
+       ret = sna_poly_fill_rect_stippled_8x8_blt(drawable, bo, damage,
+                                                 gc, n, r, extents, clipped);
+
+       gc->stipple = stipple;
+       FreeScratchPixmapHeader(scratch);
+
+       return ret;
+}
+
+static bool
+sna_poly_fill_rect_stippled_1_blt(DrawablePtr drawable,
+                                 struct kgem_bo *bo,
+                                 struct sna_damage **damage,
+                                 GCPtr gc, int n, xRectangle *r,
+                                 const BoxRec *extents, unsigned clipped)
+{
+       PixmapPtr pixmap = get_drawable_pixmap(drawable);
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+       PixmapPtr stipple = gc->stipple;
+       const DDXPointRec *origin = &gc->patOrg;
+       int16_t dx, dy;
+       uint32_t br00, br13;
+
+       DBG(("%s: upload (%d, %d), (%d, %d), origin (%d, %d)\n", __FUNCTION__,
+            extents->x1, extents->y1,
+            extents->x2, extents->y2,
+            origin->x, origin->y));
+
+       get_drawable_deltas(drawable, pixmap, &dx, &dy);
+       kgem_set_mode(&sna->kgem, KGEM_BLT);
+
+       br00 = 3 << 20;
+       br13 = bo->pitch;
+       if (sna->kgem.gen >= 40 && bo->tiling) {
+               br00 |= BLT_DST_TILED;
+               br13 >>= 2;
+       }
+       br13 |= (gc->fillStyle == FillStippled) << 29;
+       br13 |= blt_depth(drawable->depth) << 24;
+       br13 |= copy_ROP[gc->alu] << 16;
+
+       if (!clipped) {
+               dx += drawable->x;
+               dy += drawable->y;
+
+               sna_damage_add_rectangles(damage, r, n, dx, dy);
+               do {
+                       int bx1 = (r->x - origin->x) & ~7;
+                       int bx2 = (r->x + r->width - origin->x + 7) & ~7;
+                       int bw = (bx2 - bx1)/8;
+                       int bh = r->height;
+                       int bstride = ALIGN(bw, 2);
+                       int src_stride;
+                       uint8_t *dst, *src;
+                       uint32_t *b;
+
+                       DBG(("%s: rect (%d, %d)x(%d, %d) stipple [%d,%d]\n",
+                            __FUNCTION__,
+                            r->x, r->y, r->width, r->height,
+                            bx1, bx2));
+
+                       src_stride = bstride*bh;
+                       if (src_stride <= 128) {
+                               src_stride = ALIGN(src_stride, 8) / 4;
+                               if (!kgem_check_batch(&sna->kgem, 7+src_stride) ||
+                                   !kgem_check_bo_fenced(&sna->kgem, bo) ||
+                                   !kgem_check_reloc(&sna->kgem, 1)) {
+                                       _kgem_submit(&sna->kgem);
+                                       _kgem_set_mode(&sna->kgem, KGEM_BLT);
+                               }
+
+                               b = sna->kgem.batch + sna->kgem.nbatch;
+                               b[0] = XY_MONO_SRC_COPY_IMM | (5 + src_stride) | br00;
+                               b[0] |= ((r->x - origin->x) & 7) << 17;
+                               b[1] = br13;
+                               b[2] = (r->y + dy) << 16 | (r->x + dx);
+                               b[3] = (r->y + r->height + dy) << 16 | (r->x + r->width + dx);
+                               b[4] = kgem_add_reloc(&sna->kgem,
+                                                     sna->kgem.nbatch + 4, bo,
+                                                     I915_GEM_DOMAIN_RENDER << 16 |
+                                                     I915_GEM_DOMAIN_RENDER |
+                                                     KGEM_RELOC_FENCED,
+                                                     0);
+                               b[5] = gc->bgPixel;
+                               b[6] = gc->fgPixel;
+
+                               sna->kgem.nbatch += 7 + src_stride;
+
+                               dst = (uint8_t *)&b[7];
+                               src_stride = stipple->devKind;
+                               src = stipple->devPrivate.ptr;
+                               src += (r->y - origin->y) * src_stride + bx1/8;
+                               src_stride -= bstride;
+                               do {
+                                       int i = bstride;
+                                       do {
+                                               *dst++ = byte_reverse(*src++);
+                                               *dst++ = byte_reverse(*src++);
+                                               i -= 2;
+                                       } while (i);
+                                       src += src_stride;
+                               } while (--bh);
+                       } else {
+                               struct kgem_bo *upload;
+                               void *ptr;
+
+                               if (!kgem_check_batch(&sna->kgem, 8) ||
+                                   !kgem_check_bo_fenced(&sna->kgem, bo) ||
+                                   !kgem_check_reloc_and_exec(&sna->kgem, 2)) {
+                                       _kgem_submit(&sna->kgem);
+                                       _kgem_set_mode(&sna->kgem, KGEM_BLT);
+                               }
+
+                               upload = kgem_create_buffer(&sna->kgem,
+                                                           bstride*bh,
+                                                           KGEM_BUFFER_WRITE_INPLACE,
+                                                           &ptr);
+                               if (!upload)
+                                       break;
+
+                               dst = ptr;
+                               src_stride = stipple->devKind;
+                               src = stipple->devPrivate.ptr;
+                               src += (r->y - origin->y) * src_stride + bx1/8;
+                               src_stride -= bstride;
+                               do {
+                                       int i = bstride;
+                                       do {
+                                               *dst++ = byte_reverse(*src++);
+                                               *dst++ = byte_reverse(*src++);
+                                               i -= 2;
+                                       } while (i);
+                                       src += src_stride;
+                               } while (--bh);
+                               b = sna->kgem.batch + sna->kgem.nbatch;
+                               b[0] = XY_MONO_SRC_COPY | br00;
+                               b[0] |= ((r->x - origin->x) & 7) << 17;
+                               b[1] = br13;
+                               b[2] = (r->y + dy) << 16 | (r->x + dx);
+                               b[3] = (r->y + r->height + dy) << 16 | (r->x + r->width + dx);
+                               b[4] = kgem_add_reloc(&sna->kgem,
+                                                     sna->kgem.nbatch + 4, bo,
+                                                     I915_GEM_DOMAIN_RENDER << 16 |
+                                                     I915_GEM_DOMAIN_RENDER |
+                                                     KGEM_RELOC_FENCED,
+                                                     0);
+                               b[5] = kgem_add_reloc(&sna->kgem, sna->kgem.nbatch + 5,
+                                                     upload,
+                                                     I915_GEM_DOMAIN_RENDER << 16 |
+                                                     KGEM_RELOC_FENCED,
+                                                     0);
+                               b[6] = gc->bgPixel;
+                               b[7] = gc->fgPixel;
+
+                               sna->kgem.nbatch += 8;
+                               kgem_bo_destroy(&sna->kgem, upload);
+                       }
+
+                       r++;
+               } while (--n);
+       } else {
+               RegionRec clip;
+               DDXPointRec pat;
+
+               region_set(&clip, extents);
+               region_maybe_clip(&clip, gc->pCompositeClip);
+               if (!RegionNotEmpty(&clip))
+                       return true;
+
+               pat.x = origin->x + drawable->x;
+               pat.y = origin->y + drawable->y;
+
+               if (clip.data == NULL) {
+                       do {
+                               BoxRec box;
+                               int bx1, bx2, bw, bh, bstride;
+                               int src_stride;
+                               uint8_t *dst, *src;
+                               uint32_t *b;
+                               struct kgem_bo *upload;
+                               void *ptr;
+
+                               box.x1 = r->x + drawable->x;
+                               box.x2 = bound(r->x, r->width);
+                               box.y1 = r->y + drawable->y;
+                               box.y2 = bound(r->y, r->height);
+                               r++;
+
+                               if (!box_intersect(&box, &clip.extents))
+                                       continue;
+
+                               bx1 = (box.x1 - pat.x) & ~7;
+                               bx2 = (box.x2 - pat.x + 7) & ~7;
+                               bw = (bx2 - bx1)/8;
+                               bh = box.y2 - box.y1;
+                               bstride = ALIGN(bw, 2);
+
+                               DBG(("%s: rect (%d, %d)x(%d, %d), box (%d,%d),(%d,%d) stipple [%d,%d], pitch=%d, stride=%d\n",
+                                    __FUNCTION__,
+                                    r->x, r->y, r->width, r->height,
+                                    box.x1, box.y1, box.x2, box.y2,
+                                    bx1, bx2, bw, bstride));
+
+                               src_stride = bstride*bh;
+                               if (src_stride <= 128) {
+                                       src_stride = ALIGN(src_stride, 8) / 4;
+                                       if (!kgem_check_batch(&sna->kgem, 7+src_stride) ||
+                                           !kgem_check_bo_fenced(&sna->kgem, bo) ||
+                                           !kgem_check_reloc(&sna->kgem, 1)) {
+                                               _kgem_submit(&sna->kgem);
+                                               _kgem_set_mode(&sna->kgem, KGEM_BLT);
+                                       }
+
+                                       b = sna->kgem.batch + sna->kgem.nbatch;
+                                       b[0] = XY_MONO_SRC_COPY_IMM | (5 + src_stride) | br00;
+                                       b[0] |= ((box.x1 - pat.x) & 7) << 17;
+                                       b[1] = br13;
+                                       b[2] = (box.y1 + dy) << 16 | (box.x1 + dx);
+                                       b[3] = (box.y2 + dy) << 16 | (box.x2 + dx);
+                                       b[4] = kgem_add_reloc(&sna->kgem,
+                                                             sna->kgem.nbatch + 4, bo,
+                                                             I915_GEM_DOMAIN_RENDER << 16 |
+                                                             I915_GEM_DOMAIN_RENDER |
+                                                             KGEM_RELOC_FENCED,
+                                                             0);
+                                       b[5] = gc->bgPixel;
+                                       b[6] = gc->fgPixel;
+
+                                       sna->kgem.nbatch += 7 + src_stride;
+
+                                       dst = (uint8_t *)&b[7];
+                                       src_stride = stipple->devKind;
+                                       src = stipple->devPrivate.ptr;
+                                       src += (box.y1 - pat.y) * src_stride + bx1/8;
+                                       src_stride -= bstride;
+                                       do {
+                                               int i = bstride;
+                                               do {
+                                                       *dst++ = byte_reverse(*src++);
+                                                       *dst++ = byte_reverse(*src++);
+                                                       i -= 2;
+                                               } while (i);
+                                               src += src_stride;
+                                       } while (--bh);
+                               } else {
+                                       if (!kgem_check_batch(&sna->kgem, 8) ||
+                                           !kgem_check_bo_fenced(&sna->kgem, bo) ||
+                                           !kgem_check_reloc_and_exec(&sna->kgem, 2)) {
+                                               _kgem_submit(&sna->kgem);
+                                               _kgem_set_mode(&sna->kgem, KGEM_BLT);
+                                       }
+
+                                       upload = kgem_create_buffer(&sna->kgem,
+                                                                   bstride*bh,
+                                                                   KGEM_BUFFER_WRITE_INPLACE,
+                                                                   &ptr);
+                                       if (!upload)
+                                               break;
+
+                                       dst = ptr;
+                                       src_stride = stipple->devKind;
+                                       src = stipple->devPrivate.ptr;
+                                       src += (box.y1 - pat.y) * src_stride + bx1/8;
+                                       src_stride -= bstride;
+                                       do {
+                                               int i = bstride;
+                                               do {
+                                                       *dst++ = byte_reverse(*src++);
+                                                       *dst++ = byte_reverse(*src++);
+                                                       i -= 2;
+                                               } while (i);
+                                               src += src_stride;
+                                       } while (--bh);
+
+                                       b = sna->kgem.batch + sna->kgem.nbatch;
+                                       b[0] = XY_MONO_SRC_COPY | br00;
+                                       b[0] |= ((box.x1 - pat.x) & 7) << 17;
+                                       b[1] = br13;
+                                       b[2] = (box.y1 + dy) << 16 | (box.x1 + dx);
+                                       b[3] = (box.y2 + dy) << 16 | (box.x2 + dx);
+                                       b[4] = kgem_add_reloc(&sna->kgem,
+                                                             sna->kgem.nbatch + 4, bo,
+                                                             I915_GEM_DOMAIN_RENDER << 16 |
+                                                             I915_GEM_DOMAIN_RENDER |
+                                                             KGEM_RELOC_FENCED,
+                                                             0);
+                                       b[5] = kgem_add_reloc(&sna->kgem, sna->kgem.nbatch + 5,
+                                                             upload,
+                                                             I915_GEM_DOMAIN_RENDER << 16 |
+                                                             KGEM_RELOC_FENCED,
+                                                             0);
+                                       b[6] = gc->bgPixel;
+                                       b[7] = gc->fgPixel;
+
+                                       sna->kgem.nbatch += 8;
+                                       kgem_bo_destroy(&sna->kgem, upload);
+                               }
+                       } while (--n);
+               } else {
+                       const BoxRec * const clip_start = RegionBoxptr(&clip);
+                       const BoxRec * const clip_end = clip_start + clip.data->numRects;
+                       const BoxRec *c;
+
+                       do {
+                               BoxRec unclipped;
+                               int bx1, bx2, bw, bh, bstride;
+                               int src_stride;
+                               uint8_t *dst, *src;
+                               uint32_t *b;
+                               struct kgem_bo *upload;
+                               void *ptr;
+
+                               unclipped.x1 = r->x + drawable->x;
+                               unclipped.x2 = bound(r->x, r->width);
+                               unclipped.y1 = r->y + drawable->y;
+                               unclipped.y2 = bound(r->y, r->height);
+                               r++;
+
+                               c = find_clip_box_for_y(clip_start,
+                                                       clip_end,
+                                                       unclipped.y1);
+                               while (c != clip_end) {
+                                       BoxRec box;
+
+                                       if (unclipped.y2 <= c->y1)
+                                               break;
+
+                                       box = unclipped;
+                                       if (!box_intersect(&box, c++))
+                                               continue;
+
+                                       bx1 = (box.x1 - pat.x) & ~7;
+                                       bx2 = (box.x2 - pat.x + 7) & ~7;
+                                       bw = (bx2 - bx1)/8;
+                                       bh = box.y2 - box.y1;
+                                       bstride = ALIGN(bw, 2);
+
+                                       DBG(("%s: rect (%d, %d)x(%d, %d), box (%d,%d),(%d,%d) stipple [%d,%d]\n",
+                                            __FUNCTION__,
+                                            r->x, r->y, r->width, r->height,
+                                            box.x1, box.y1, box.x2, box.y2,
+                                            bx1, bx2));
+
+                                       src_stride = bstride*bh;
+                                       if (src_stride <= 128) {
+                                               src_stride = ALIGN(src_stride, 8) / 4;
+                                               if (!kgem_check_batch(&sna->kgem, 7+src_stride) ||
+                                                   !kgem_check_bo_fenced(&sna->kgem, bo) ||
+                                                   !kgem_check_reloc(&sna->kgem, 1)) {
+                                                       _kgem_submit(&sna->kgem);
+                                                       _kgem_set_mode(&sna->kgem, KGEM_BLT);
+                                               }
+
+                                               b = sna->kgem.batch + sna->kgem.nbatch;
+                                               b[0] = XY_MONO_SRC_COPY_IMM | (5 + src_stride) | br00;
+                                               b[0] |= ((box.x1 - pat.x) & 7) << 17;
+                                               b[1] = br13;
+                                               b[2] = (box.y1 + dy) << 16 | (box.x1 + dx);
+                                               b[3] = (box.y2 + dy) << 16 | (box.x2 + dx);
+                                               b[4] = kgem_add_reloc(&sna->kgem,
+                                                                     sna->kgem.nbatch + 4, bo,
+                                                                     I915_GEM_DOMAIN_RENDER << 16 |
+                                                                     I915_GEM_DOMAIN_RENDER |
+                                                                     KGEM_RELOC_FENCED,
+                                                                     0);
+                                               b[5] = gc->bgPixel;
+                                               b[6] = gc->fgPixel;
+
+                                               sna->kgem.nbatch += 7 + src_stride;
+
+                                               dst = (uint8_t *)&b[7];
+                                               src_stride = stipple->devKind;
+                                               src = stipple->devPrivate.ptr;
+                                               src += (box.y1 - pat.y) * src_stride + bx1/8;
+                                               src_stride -= bstride;
+                                               do {
+                                                       int i = bstride;
+                                                       do {
+                                                               *dst++ = byte_reverse(*src++);
+                                                               *dst++ = byte_reverse(*src++);
+                                                               i -= 2;
+                                                       } while (i);
+                                                       src += src_stride;
+                                               } while (--bh);
+                                       } else {
+                                               if (!kgem_check_batch(&sna->kgem, 8) ||
+                                                   !kgem_check_bo_fenced(&sna->kgem, bo) ||
+                                                   !kgem_check_reloc_and_exec(&sna->kgem, 2)) {
+                                                       _kgem_submit(&sna->kgem);
+                                                       _kgem_set_mode(&sna->kgem, KGEM_BLT);
+                                               }
+
+                                               upload = kgem_create_buffer(&sna->kgem,
+                                                                           bstride*bh,
+                                                                           KGEM_BUFFER_WRITE_INPLACE,
+                                                                           &ptr);
+                                               if (!upload)
+                                                       break;
+
+                                               dst = ptr;
+                                               src_stride = stipple->devKind;
+                                               src = stipple->devPrivate.ptr;
+                                               src += (box.y1 - pat.y) * src_stride + bx1/8;
+                                               src_stride -= bstride;
+                                               do {
+                                                       int i = bstride;
+                                                       do {
+                                                               *dst++ = byte_reverse(*src++);
+                                                               *dst++ = byte_reverse(*src++);
+                                                               i -= 2;
+                                                       } while (i);
+                                                       src += src_stride;
+                                               } while (--bh);
+
+                                               b = sna->kgem.batch + sna->kgem.nbatch;
+                                               b[0] = XY_MONO_SRC_COPY | br00;
+                                               b[0] |= ((box.x1 - pat.x) & 7) << 17;
+                                               b[1] = br13;
+                                               b[2] = (box.y1 + dy) << 16 | (box.x1 + dx);
+                                               b[3] = (box.y2 + dy) << 16 | (box.x2 + dx);
+                                               b[4] = kgem_add_reloc(&sna->kgem,
+                                                                     sna->kgem.nbatch + 4, bo,
+                                                                     I915_GEM_DOMAIN_RENDER << 16 |
+                                                                     I915_GEM_DOMAIN_RENDER |
+                                                                     KGEM_RELOC_FENCED,
+                                                                     0);
+                                               b[5] = kgem_add_reloc(&sna->kgem, sna->kgem.nbatch + 5,
+                                                                     upload,
+                                                                     I915_GEM_DOMAIN_RENDER << 16 |
+                                                                     KGEM_RELOC_FENCED,
+                                                                     0);
+                                               b[6] = gc->bgPixel;
+                                               b[7] = gc->fgPixel;
+
+                                               sna->kgem.nbatch += 8;
+                                               kgem_bo_destroy(&sna->kgem, upload);
+                                       }
+                               }
+                       } while (--n);
+
+               }
+       }
+
+       sna->blt_state.fill_bo = 0;
+       return true;
+}
+
+static void
+sna_poly_fill_rect_stippled_n_box__imm(struct sna *sna,
+                                      struct kgem_bo *bo,
+                                      uint32_t br00, uint32_t br13,
+                                      const GC *gc,
+                                      const BoxRec *box,
+                                      const DDXPointRec *origin)
+{
+       int x1, x2, y1, y2;
+       uint32_t *b;
+
+       for (y1 = box->y1; y1 < box->y2; y1 = y2) {
+               int oy = (y1 - origin->y) % gc->stipple->drawable.height;
+               if (oy < 0)
+                       oy += gc->stipple->drawable.height;
+
+               y2 = box->y2;
+               if (y2 - y1 > gc->stipple->drawable.height - oy)
+                       y2 = y1 + gc->stipple->drawable.height - oy;
+
+               for (x1 = box->x1; x1 < box->x2; x1 = x2) {
+                       int bx1, bx2, bw, bh, len, ox;
+                       uint8_t *dst, *src;
+
+                       x2 = box->x2;
+                       ox = (x1 - origin->x) % gc->stipple->drawable.width;
+                       if (ox < 0)
+                               ox += gc->stipple->drawable.width;
+                       bx1 = ox & ~7;
+                       bx2 = ox + (x2 - x1);
+                       if (bx2 > gc->stipple->drawable.width) {
+                               bx2 = gc->stipple->drawable.width;
+                               x2 = x1 + bx2-ox;
+                       }
+                       bw = (bx2 - bx1 + 7)/8;
+                       bw = ALIGN(bw, 2);
+                       bh = y2 - y1;
+
+                       DBG(("%s: box((%d, %d)x(%d, %d)) origin=(%d, %d), pat=(%d, %d), up=(%d, %d), stipple=%dx%d\n",
+                            __FUNCTION__,
+                            x1, y1, x2-x1, y2-y1,
+                            origin->x, origin->y,
+                            ox, oy, bx1, bx2,
+                            gc->stipple->drawable.width,
+                            gc->stipple->drawable.height));
+
+                       len = bw*bh;
+                       len = ALIGN(len, 8) / 4;
+                       if (!kgem_check_batch(&sna->kgem, 7+len) ||
+                           !kgem_check_bo_fenced(&sna->kgem, bo) ||
+                           !kgem_check_reloc(&sna->kgem, 1)) {
+                               _kgem_submit(&sna->kgem);
+                               _kgem_set_mode(&sna->kgem, KGEM_BLT);
+                       }
+
+                       b = sna->kgem.batch + sna->kgem.nbatch;
+                       b[0] = br00 | (5 + len) | (ox & 7) << 17;
+                       b[1] = br13;
+                       b[2] = y1 << 16 | x1;
+                       b[3] = y2 << 16 | x2;
+                       b[4] = kgem_add_reloc(&sna->kgem, sna->kgem.nbatch + 4,
+                                             bo,
+                                             I915_GEM_DOMAIN_RENDER << 16 |
+                                             I915_GEM_DOMAIN_RENDER |
+                                             KGEM_RELOC_FENCED,
+                                             0);
+                       b[5] = gc->bgPixel;
+                       b[6] = gc->fgPixel;
+
+                       sna->kgem.nbatch += 7 + len;
+
+                       dst = (uint8_t *)&b[7];
+                       len = gc->stipple->devKind;
+                       src = gc->stipple->devPrivate.ptr;
+                       src += oy*len + ox/8;
+                       len -= bw;
+                       do {
+                               int i = bw;
+                               do {
+                                       *dst++ = byte_reverse(*src++);
+                                       *dst++ = byte_reverse(*src++);
+                                       i -= 2;
+                               } while (i);
+                               src += len;
+                       } while (--bh);
+               }
+       }
+}
+
+static void
+sna_poly_fill_rect_stippled_n_box(struct sna *sna,
+                                 struct kgem_bo *bo,
+                                 struct kgem_bo **tile,
+                                 uint32_t br00, uint32_t br13,
+                                 const GC *gc,
+                                 const BoxRec *box,
+                                 const DDXPointRec *origin)
+{
+       int x1, x2, y1, y2;
+       int w = gc->stipple->drawable.width;
+       int h = gc->stipple->drawable.height;
+       int stride = gc->stipple->devKind;
+       uint32_t *b;
+
+       if ((((box->y2-box->y1) | (box->x2-box->x1)) & ~31) == 0) {
+               br00 = XY_MONO_SRC_COPY_IMM |(br00 & (BLT_DST_TILED | 3 << 20));
+               sna_poly_fill_rect_stippled_n_box__imm(sna, bo,
+                                                      br00, br13, gc,
+                                                      box, origin);
+               return;
+       }
+
+       for (y1 = box->y1; y1 < box->y2; y1 = y2) {
+               int row, oy = (y1 - origin->y) % gc->stipple->drawable.height;
+               if (oy < 0)
+                       oy += h;
+
+               y2 = box->y2;
+               if (y2 - y1 > h - oy)
+                       y2 = y1 + h - oy;
+
+               row = oy * stride;
+               for (x1 = box->x1; x1 < box->x2; x1 = x2) {
+                       int bx1, bx2, bw, bh, len, ox;
+                       bool use_tile;
+
+                       x2 = box->x2;
+                       ox = (x1 - origin->x) % w;
+                       if (ox < 0)
+                               ox += w;
+                       bx1 = ox & ~7;
+                       bx2 = ox + (x2 - x1);
+                       if (bx2 > w) {
+                               bx2 = w;
+                               x2 = x1 + bx2-ox;
+                       }
+
+                       use_tile = y2-y1 == h && x2-x1 == w;
+
+                       DBG(("%s: box((%d, %d)x(%d, %d)) origin=(%d, %d), pat=(%d, %d), up=(%d, %d), stipple=%dx%d, full tile?=%d\n",
+                            __FUNCTION__,
+                            x1, y1, x2-x1, y2-y1,
+                            origin->x, origin->y,
+                            ox, oy, bx1, bx2, w, h,
+                            use_tile));
+
+                       bw = (bx2 - bx1 + 7)/8;
+                       bw = ALIGN(bw, 2);
+                       bh = y2 - y1;
+
+                       len = bw*bh;
+                       len = ALIGN(len, 8) / 4;
+                       if (!kgem_check_batch(&sna->kgem, 7+len) ||
+                           !kgem_check_bo_fenced(&sna->kgem, bo) ||
+                           !kgem_check_reloc(&sna->kgem, 2)) {
+                               _kgem_submit(&sna->kgem);
+                               _kgem_set_mode(&sna->kgem, KGEM_BLT);
+                       }
+
+                       b = sna->kgem.batch + sna->kgem.nbatch;
+
+                       if (!use_tile && len <= 128) {
+                               uint8_t *dst, *src;
+
+                               b[0] = XY_MONO_SRC_COPY_IMM;
+                               b[0] |= (br00 & (BLT_DST_TILED | 3 << 20));
+                               b[0] |= (ox & 7) << 17;
+                               b[0] |= (5 + len);
+                               b[1] = br13;
+                               b[2] = y1 << 16 | x1;
+                               b[3] = y2 << 16 | x2;
+                               b[4] = kgem_add_reloc(&sna->kgem, sna->kgem.nbatch + 4,
+                                                     bo,
+                                                     I915_GEM_DOMAIN_RENDER << 16 |
+                                                     I915_GEM_DOMAIN_RENDER |
+                                                     KGEM_RELOC_FENCED,
+                                                     0);
+                               b[5] = gc->bgPixel;
+                               b[6] = gc->fgPixel;
+
+                               sna->kgem.nbatch += 7 + len;
+
+                               dst = (uint8_t *)&b[7];
+                               len = gc->stipple->devKind;
+                               src = gc->stipple->devPrivate.ptr;
+                               src += oy*len + ox/8;
+                               len -= bw;
+                               do {
+                                       int i = bw;
+                                       do {
+                                               *dst++ = byte_reverse(*src++);
+                                               *dst++ = byte_reverse(*src++);
+                                               i -= 2;
+                                       } while (i);
+                                       src += len;
+                               } while (--bh);
+                       } else {
+                               bool has_tile = use_tile && *tile;
+                               struct kgem_bo *upload;
+                               uint8_t *dst, *src;
+                               void *ptr;
+
+                               if (has_tile) {
+                                       upload = kgem_bo_reference(*tile);
+                               } else {
+                                       upload = kgem_create_buffer(&sna->kgem, bw*bh,
+                                                                   KGEM_BUFFER_WRITE_INPLACE,
+                                                                   &ptr);
+                                       if (!upload)
+                                               return;
+                               }
+
+                               b = sna->kgem.batch + sna->kgem.nbatch;
+                               b[0] = br00 | (ox & 7) << 17;
+                               b[1] = br13;
+                               b[2] = y1 << 16 | x1;
+                               b[3] = y2 << 16 | x2;
+                               b[4] = kgem_add_reloc(&sna->kgem, sna->kgem.nbatch + 4,
+                                                     bo,
+                                                     I915_GEM_DOMAIN_RENDER << 16 |
+                                                     I915_GEM_DOMAIN_RENDER |
+                                                     KGEM_RELOC_FENCED,
+                                                     0);
+                               b[5] = kgem_add_reloc(&sna->kgem, sna->kgem.nbatch + 5,
+                                                     upload,
+                                                     I915_GEM_DOMAIN_RENDER << 16 |
+                                                     KGEM_RELOC_FENCED,
+                                                     0);
+                               b[6] = gc->bgPixel;
+                               b[7] = gc->fgPixel;
+
+                               sna->kgem.nbatch += 8;
+
+                               if (!has_tile) {
+                                       dst = ptr;
+                                       len = stride;
+                                       src = gc->stipple->devPrivate.ptr;
+                                       src += row + (ox >> 3);
+                                       len -= bw;
+                                       do {
+                                               int i = bw;
+                                               do {
+                                                       *dst++ = byte_reverse(*src++);
+                                                       *dst++ = byte_reverse(*src++);
+                                                       i -= 2;
+                                               } while (i);
+                                               src += len;
+                                       } while (--bh);
+                                       if (use_tile)
+                                               *tile = kgem_bo_reference(upload);
+                               }
+
+                               kgem_bo_destroy(&sna->kgem, upload);
+                       }
+               }
+       }
+}
+
+static bool
+sna_poly_fill_rect_stippled_n_blt__imm(DrawablePtr drawable,
+                                      struct kgem_bo *bo,
+                                      struct sna_damage **damage,
+                                      GCPtr gc, int n, xRectangle *r,
+                                      const BoxRec *extents, unsigned clipped)
+{
+       PixmapPtr pixmap = get_drawable_pixmap(drawable);
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+       DDXPointRec origin = gc->patOrg;
+       int16_t dx, dy;
+       uint32_t br00, br13;
+
+       DBG(("%s: upload (%d, %d), (%d, %d), origin (%d, %d), clipped=%d, alu=%d, opaque=%d\n", __FUNCTION__,
+            extents->x1, extents->y1,
+            extents->x2, extents->y2,
+            origin.x, origin.y,
+            clipped, gc->alu, gc->fillStyle == FillOpaqueStippled));
+
+       get_drawable_deltas(drawable, pixmap, &dx, &dy);
+       kgem_set_mode(&sna->kgem, KGEM_BLT);
+
+       br00 = XY_MONO_SRC_COPY_IMM | 3 << 20;
+       br13 = bo->pitch;
+       if (sna->kgem.gen >= 40 && bo->tiling) {
+               br00 |= BLT_DST_TILED;
+               br13 >>= 2;
+       }
+       br13 |= (gc->fillStyle == FillStippled) << 29;
+       br13 |= blt_depth(drawable->depth) << 24;
+       br13 |= copy_ROP[gc->alu] << 16;
+
+       origin.x += dx + drawable->x;
+       origin.y += dy + drawable->y;
+
+       if (!clipped) {
+               dx += drawable->x;
+               dy += drawable->y;
+
+               sna_damage_add_rectangles(damage, r, n, dx, dy);
+               do {
+                       BoxRec box;
+
+                       box.x1 = r->x + dx;
+                       box.y1 = r->y + dy;
+                       box.x2 = box.x1 + r->width;
+                       box.y2 = box.y1 + r->height;
+
+                       sna_poly_fill_rect_stippled_n_box__imm(sna, bo,
+                                                              br00, br13, gc,
+                                                              &box, &origin);
+                       r++;
+               } while (--n);
+       } else {
+               RegionRec clip;
+
+               region_set(&clip, extents);
+               region_maybe_clip(&clip, gc->pCompositeClip);
+               if (!RegionNotEmpty(&clip)) {
+                       DBG(("%s: all clipped\n", __FUNCTION__));
+                       return true;
+               }
+
+               if (clip.data == NULL) {
+                       DBG(("%s: clipped to extents ((%d, %d), (%d, %d))\n",
+                            __FUNCTION__,
+                            clip.extents.x1, clip.extents.y1,
+                            clip.extents.x2, clip.extents.y2));
+                       do {
+                               BoxRec box;
+
+                               box.x1 = r->x + drawable->x;
+                               box.x2 = bound(box.x1, r->width);
+                               box.y1 = r->y + drawable->y;
+                               box.y2 = bound(box.y1, r->height);
+                               r++;
+
+                               DBG(("%s: box (%d, %d), (%d, %d)\n",
+                                    __FUNCTION__,
+                                    box.x1, box.y1, box.x2, box.y2));
+                               if (!box_intersect(&box, &clip.extents))
+                                       continue;
+
+                               box.x1 += dx; box.x2 += dx;
+                               box.y1 += dy; box.y2 += dy;
+
+                               sna_poly_fill_rect_stippled_n_box__imm(sna, bo,
+                                                                      br00, br13, gc,
+                                                                      &box, &origin);
+                       } while (--n);
+               } else {
+                       const BoxRec * const clip_start = RegionBoxptr(&clip);
+                       const BoxRec * const clip_end = clip_start + clip.data->numRects;
+                       const BoxRec *c;
+
+                       DBG(("%s: clipped to boxes: start((%d, %d), (%d, %d)); end=((%d, %d), (%d, %d))\n", __FUNCTION__,
+                            clip_start->x1, clip_start->y1,
+                            clip_start->x2, clip_start->y2,
+                            clip_end->x1, clip_end->y1,
+                            clip_end->x2, clip_end->y2));
+                       do {
+                               BoxRec unclipped;
+
+                               unclipped.x1 = r->x + drawable->x;
+                               unclipped.x2 = bound(unclipped.x1, r->width);
+                               unclipped.y1 = r->y + drawable->y;
+                               unclipped.y2 = bound(unclipped.y1, r->height);
+                               r++;
+
+                               c = find_clip_box_for_y(clip_start,
+                                                       clip_end,
+                                                       unclipped.y1);
+                               while (c != clip_end) {
+                                       BoxRec box;
+
+                                       if (unclipped.y2 <= c->y1)
+                                               break;
+
+                                       box = unclipped;
+                                       if (!box_intersect(&box, c++))
+                                               continue;
+
+                                       box.x1 += dx; box.x2 += dx;
+                                       box.y1 += dy; box.y2 += dy;
+
+                                       sna_poly_fill_rect_stippled_n_box__imm(sna, bo,
+                                                                              br00, br13, gc,
+                                                                              &box, &origin);
+                               }
+                       } while (--n);
+               }
+       }
+
+       assert_pixmap_damage(pixmap);
+       sna->blt_state.fill_bo = 0;
+       return true;
+}
+
+static bool
+sna_poly_fill_rect_stippled_n_blt(DrawablePtr drawable,
+                                 struct kgem_bo *bo,
+                                 struct sna_damage **damage,
+                                 GCPtr gc, int n, xRectangle *r,
+                                 const BoxRec *extents, unsigned clipped)
+{
+       PixmapPtr pixmap = get_drawable_pixmap(drawable);
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+       DDXPointRec origin = gc->patOrg;
+       struct kgem_bo *tile = NULL;
+       int16_t dx, dy;
+       uint32_t br00, br13;
+
+       DBG(("%s: upload (%d, %d), (%d, %d), origin (%d, %d), clipped=%d, alu=%d, opaque=%d\n", __FUNCTION__,
+            extents->x1, extents->y1,
+            extents->x2, extents->y2,
+            origin.x, origin.y,
+            clipped, gc->alu, gc->fillStyle == FillOpaqueStippled));
+
+       if (((gc->stipple->drawable.width | gc->stipple->drawable.height) & ~31) == 0)
+               return sna_poly_fill_rect_stippled_n_blt__imm(drawable,
+                                                             bo, damage,
+                                                             gc, n, r,
+                                                             extents, clipped);
+
+       get_drawable_deltas(drawable, pixmap, &dx, &dy);
+       kgem_set_mode(&sna->kgem, KGEM_BLT);
+
+       br00 = XY_MONO_SRC_COPY | 3 << 20;
+       br13 = bo->pitch;
+       if (sna->kgem.gen >= 40 && bo->tiling) {
+               br00 |= BLT_DST_TILED;
+               br13 >>= 2;
+       }
+       br13 |= (gc->fillStyle == FillStippled) << 29;
+       br13 |= blt_depth(drawable->depth) << 24;
+       br13 |= copy_ROP[gc->alu] << 16;
+
+       origin.x += dx + drawable->x;
+       origin.y += dy + drawable->y;
+
+       if (!clipped) {
+               dx += drawable->x;
+               dy += drawable->y;
+
+               sna_damage_add_rectangles(damage, r, n, dx, dy);
+               do {
+                       BoxRec box;
+
+                       box.x1 = r->x + dx;
+                       box.y1 = r->y + dy;
+                       box.x2 = box.x1 + r->width;
+                       box.y2 = box.y1 + r->height;
+
+                       sna_poly_fill_rect_stippled_n_box(sna, bo, &tile,
+                                                         br00, br13, gc,
+                                                         &box, &origin);
+                       r++;
+               } while (--n);
+       } else {
+               RegionRec clip;
+
+               region_set(&clip, extents);
+               region_maybe_clip(&clip, gc->pCompositeClip);
+               if (!RegionNotEmpty(&clip)) {
+                       DBG(("%s: all clipped\n", __FUNCTION__));
+                       return true;
+               }
+
+               if (clip.data == NULL) {
+                       DBG(("%s: clipped to extents ((%d, %d), (%d, %d))\n",
+                            __FUNCTION__,
+                            clip.extents.x1, clip.extents.y1,
+                            clip.extents.x2, clip.extents.y2));
+                       do {
+                               BoxRec box;
+
+                               box.x1 = r->x + drawable->x;
+                               box.x2 = bound(box.x1, r->width);
+                               box.y1 = r->y + drawable->y;
+                               box.y2 = bound(box.y1, r->height);
+                               r++;
+
+                               DBG(("%s: box (%d, %d), (%d, %d)\n",
+                                    __FUNCTION__,
+                                    box.x1, box.y1, box.x2, box.y2));
+                               if (!box_intersect(&box, &clip.extents))
+                                       continue;
+
+                               box.x1 += dx; box.x2 += dx;
+                               box.y1 += dy; box.y2 += dy;
+
+                               sna_poly_fill_rect_stippled_n_box(sna, bo, &tile,
+                                                                 br00, br13, gc,
+                                                                 &box, &origin);
+                       } while (--n);
+               } else {
+                       const BoxRec * const clip_start = RegionBoxptr(&clip);
+                       const BoxRec * const clip_end = clip_start + clip.data->numRects;
+                       const BoxRec *c;
+
+                       DBG(("%s: clipped to boxes: start((%d, %d), (%d, %d)); end=((%d, %d), (%d, %d))\n", __FUNCTION__,
+                            clip_start->x1, clip_start->y1,
+                            clip_start->x2, clip_start->y2,
+                            clip_end->x1, clip_end->y1,
+                            clip_end->x2, clip_end->y2));
+                       do {
+                               BoxRec unclipped;
+
+                               unclipped.x1 = r->x + drawable->x;
+                               unclipped.x2 = bound(unclipped.x1, r->width);
+                               unclipped.y1 = r->y + drawable->y;
+                               unclipped.y2 = bound(unclipped.y1, r->height);
+                               r++;
+
+                               c = find_clip_box_for_y(clip_start,
+                                                       clip_end,
+                                                       unclipped.y1);
+                               while (c != clip_end) {
+                                       BoxRec box;
+
+                                       if (unclipped.y2 <= c->y1)
+                                               break;
+
+                                       box = unclipped;
+                                       if (!box_intersect(&box, c++))
+                                               continue;
+
+                                       box.x1 += dx; box.x2 += dx;
+                                       box.y1 += dy; box.y2 += dy;
+
+                                       sna_poly_fill_rect_stippled_n_box(sna, bo, &tile,
+                                                                         br00, br13, gc,
+                                                                         &box, &origin);
+                               }
+                       } while (--n);
+               }
+       }
+
+       assert_pixmap_damage(pixmap);
+       if (tile)
+               kgem_bo_destroy(&sna->kgem, tile);
+       sna->blt_state.fill_bo = 0;
+       return true;
+}
+
+static bool
+sna_poly_fill_rect_stippled_blt(DrawablePtr drawable,
+                               struct kgem_bo *bo,
+                               struct sna_damage **damage,
+                               GCPtr gc, int n, xRectangle *rect,
+                               const BoxRec *extents, unsigned clipped)
+{
+
+       PixmapPtr stipple = gc->stipple;
+
+       if (bo->tiling == I915_TILING_Y) {
+               PixmapPtr pixmap = get_drawable_pixmap(drawable);
+
+               DBG(("%s: converting bo from Y-tiling\n", __FUNCTION__));
+               /* This is cheating, but only the gpu_bo can be tiled */
+               assert(bo == sna_pixmap_get_bo(pixmap));
+               bo = sna_pixmap_change_tiling(pixmap, I915_TILING_X);
+               if (bo == NULL) {
+                       DBG(("%s: fallback -- unable to change tiling\n",
+                            __FUNCTION__));
+                       return false;
+               }
+       }
+
+       if (!sna_drawable_move_to_cpu(&stipple->drawable, MOVE_READ))
+               return false;
+
+       DBG(("%s: origin (%d, %d), extents (stipple): (%d, %d), stipple size %dx%d\n",
+            __FUNCTION__, gc->patOrg.x, gc->patOrg.y,
+            extents->x2 - gc->patOrg.x - drawable->x,
+            extents->y2 - gc->patOrg.y - drawable->y,
+            stipple->drawable.width, stipple->drawable.height));
+
+       if ((stipple->drawable.width | stipple->drawable.height) == 8)
+               return sna_poly_fill_rect_stippled_8x8_blt(drawable, bo, damage,
+                                                          gc, n, rect,
+                                                          extents, clipped);
+
+       if ((stipple->drawable.width | stipple->drawable.height) <= 0xc &&
+           is_power_of_two(stipple->drawable.width) &&
+           is_power_of_two(stipple->drawable.height))
+               return sna_poly_fill_rect_stippled_nxm_blt(drawable, bo, damage,
+                                                          gc, n, rect,
+                                                          extents, clipped);
+
+       if (extents->x2 - gc->patOrg.x - drawable->x <= stipple->drawable.width &&
+           extents->y2 - gc->patOrg.y - drawable->y <= stipple->drawable.height) {
+               if (stipple->drawable.width <= 8 && stipple->drawable.height <= 8)
+                       return sna_poly_fill_rect_stippled_8x8_blt(drawable, bo, damage,
+                                                                  gc, n, rect,
+                                                                  extents, clipped);
+               else
+                       return sna_poly_fill_rect_stippled_1_blt(drawable, bo, damage,
+                                                                gc, n, rect,
+                                                                extents, clipped);
+       } else {
+               return sna_poly_fill_rect_stippled_n_blt(drawable, bo, damage,
+                                                        gc, n, rect,
+                                                        extents, clipped);
+       }
+}
+
+static unsigned
+sna_poly_fill_rect_extents(DrawablePtr drawable, GCPtr gc,
+                          int *_n, xRectangle **_r,
+                          BoxPtr out)
+{
+       int n;
+       xRectangle *r;
+       Box32Rec box;
+       bool clipped;
+
+       if (*_n == 0)
+               return 0;
+
+       DBG(("%s: [0] = (%d, %d)x(%d, %d)\n",
+            __FUNCTION__, (*_r)->x, (*_r)->y, (*_r)->width, (*_r)->height));
+
+       /* Remove any zero-size rectangles from the array */
+       while (*_n && ((*_r)->width == 0 || (*_r)->height == 0))
+               --*_n, ++*_r;
+
+       if (*_n == 0)
+               return 0;
+
+       n = *_n;
+       r = *_r;
+
+       box.x1 = r->x;
+       box.x2 = box.x1 + r->width;
+       box.y1 = r->y;
+       box.y2 = box.y1 + r->height;
+       r++;
+
+       while (--n) {
+               if (r->width == 0 || r->height == 0)
+                       goto slow;
+
+               box32_add_rect(&box, r++);
+       }
+       goto done;
+slow:
+       {
+               xRectangle *rr = r;
+               do {
+                       do {
+                               --*_n, r++;
+                       } while (--n && (r->width == 0 || r->height == 0));
+                       while (n && r->width && r->height) {
+                               box32_add_rect(&box, r);
+                               *rr++ = *r++;
+                               n--;
+                       }
+               } while (n);
+       }
+done:
+
+       clipped = box32_trim_and_translate(&box, drawable, gc);
+       if (!box32_to_box16(&box, out))
+               return 0;
+
+       return 1 | clipped << 1;
+}
+
+static void
+sna_poly_fill_rect(DrawablePtr draw, GCPtr gc, int n, xRectangle *rect)
+{
+       PixmapPtr pixmap = get_drawable_pixmap(draw);
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+       struct sna_pixmap *priv = sna_pixmap(pixmap);
+       struct sna_damage **damage;
+       struct kgem_bo *bo;
+       RegionRec region;
+       unsigned flags, hint;
+       uint32_t color;
+
+       DBG(("%s(n=%d, PlaneMask: %lx (solid %d), solid fill: %d [style=%d, tileIsPixel=%d], alu=%d)\n", __FUNCTION__,
+            n, gc->planemask, !!PM_IS_SOLID(draw, gc->planemask),
+            (gc->fillStyle == FillSolid ||
+             (gc->fillStyle == FillTiled && gc->tileIsPixel)),
+            gc->fillStyle, gc->tileIsPixel,
+            gc->alu));
+
+       flags = sna_poly_fill_rect_extents(draw, gc, &n, &rect, &region.extents);
+       if (flags == 0) {
+               DBG(("%s, nothing to do\n", __FUNCTION__));
+               return;
+       }
+
+       DBG(("%s: extents(%d, %d), (%d, %d), flags=%x\n", __FUNCTION__,
+            region.extents.x1, region.extents.y1,
+            region.extents.x2, region.extents.y2,
+            flags));
+
+       if (FORCE_FALLBACK || !ACCEL_POLY_FILL_RECT) {
+               DBG(("%s: fallback forced\n", __FUNCTION__));
+               goto fallback;
+       }
+
+       if (priv == NULL) {
+               DBG(("%s: fallback -- unattached\n", __FUNCTION__));
+               goto fallback;
+       }
+
+       if (wedged(sna)) {
+               DBG(("%s: fallback -- wedged\n", __FUNCTION__));
+               goto fallback;
+       }
+
+       if (!PM_IS_SOLID(draw, gc->planemask)) {
+               DBG(("%s: fallback -- planemask=%#lx (not-solid)\n",
+                    __FUNCTION__, gc->planemask));
+               goto fallback;
+       }
+
+       /* Clear the cpu damage so that we refresh the GPU status of the
+        * pixmap upon a redraw after a period of inactivity.
+        */
+       hint = PREFER_GPU;
+       if (n == 1 && gc->fillStyle != FillStippled && alu_overwrites(gc->alu)) {
+               region.data = NULL;
+               if (priv->cpu_damage &&
+                   region_is_singular(gc->pCompositeClip)) {
+                       if (region_subsumes_damage(&region, priv->cpu_damage)) {
+                               DBG(("%s: discarding existing CPU damage\n", __FUNCTION__));
+                               if (priv->gpu_bo && priv->gpu_bo->proxy) {
+                                       kgem_bo_destroy(&sna->kgem, priv->gpu_bo);
+                                       priv->gpu_bo = NULL;
+                               }
+                               sna_damage_destroy(&priv->cpu_damage);
+                               list_del(&priv->list);
+                       }
+                       hint |= IGNORE_CPU;
+               }
+               if (priv->cpu_damage == NULL &&
+                   (region_subsumes_drawable(&region, &pixmap->drawable) ||
+                    box_inplace(pixmap, &region.extents))) {
+                       DBG(("%s: promoting to full GPU\n", __FUNCTION__));
+                       if (priv->gpu_bo) {
+                               sna_damage_all(&priv->gpu_damage,
+                                              pixmap->drawable.width,
+                                              pixmap->drawable.height);
+                               priv->undamaged = false;
+                       }
+               }
+               if (priv->cpu_damage == NULL) {
+                       DBG(("%s: dropping last-cpu hint\n", __FUNCTION__));
+                       priv->cpu = false;
+               }
+       }
+
+       /* If the source is already on the GPU, keep the operation on the GPU */
+       if (gc->fillStyle == FillTiled) {
+               if (!gc->tileIsPixel && sna_pixmap_is_gpu(gc->tile.pixmap)) {
+                       DBG(("%s: source is already on the gpu\n", __FUNCTION__));
+                       hint |= PREFER_GPU | FORCE_GPU;
+               }
+       }
+
+       bo = sna_drawable_use_bo(draw, hint, &region.extents, &damage);
+       if (bo == NULL) {
+               DBG(("%s: not using GPU, hint=%x\n", __FUNCTION__, hint));
+               goto fallback;
+       }
+
+       if (gc_is_solid(gc, &color)) {
+               DBG(("%s: solid fill [%08x], testing for blt\n",
+                    __FUNCTION__, color));
+
+               if (sna_poly_fill_rect_blt(draw,
+                                          bo, damage,
+                                          gc, color, n, rect,
+                                          &region.extents, flags & 2))
+                       return;
+       } else if (gc->fillStyle == FillTiled) {
+               DBG(("%s: tiled fill, testing for blt\n", __FUNCTION__));
+
+               if (sna_poly_fill_rect_tiled_blt(draw, bo, damage,
+                                                gc, n, rect,
+                                                &region.extents, flags & 2))
+                       return;
+       } else {
+               DBG(("%s: stippled fill, testing for blt\n", __FUNCTION__));
+
+               if (sna_poly_fill_rect_stippled_blt(draw, bo, damage,
+                                                   gc, n, rect,
+                                                   &region.extents, flags & 2))
+                       return;
+       }
+
+fallback:
+       DBG(("%s: fallback (%d, %d), (%d, %d)\n", __FUNCTION__,
+            region.extents.x1, region.extents.y1,
+            region.extents.x2, region.extents.y2));
+       region.data = NULL;
+       region_maybe_clip(&region, gc->pCompositeClip);
+       if (!RegionNotEmpty(&region)) {
+               DBG(("%s: nothing to do, all clipped\n", __FUNCTION__));
+               return;
+       }
+
+       if (!sna_gc_move_to_cpu(gc, draw, &region))
+               goto out;
+       if (!sna_drawable_move_region_to_cpu(draw, &region,
+                                            drawable_gc_flags(draw, gc, n > 1)))
+               goto out_gc;
+
+       DBG(("%s: fallback - fbPolyFillRect\n", __FUNCTION__));
+       fbPolyFillRect(draw, gc, n, rect);
+       FALLBACK_FLUSH(draw);
+out_gc:
+       sna_gc_move_to_gpu(gc);
+out:
+       RegionUninit(&region);
+}
+
+static void
+sna_poly_fill_arc(DrawablePtr draw, GCPtr gc, int n, xArc *arc)
+{
+       struct sna_fill_spans data;
+       struct sna_pixmap *priv;
+
+       DBG(("%s(n=%d, PlaneMask: %lx (solid %d), solid fill: %d [style=%d, tileIsPixel=%d], alu=%d)\n", __FUNCTION__,
+            n, gc->planemask, !!PM_IS_SOLID(draw, gc->planemask),
+            (gc->fillStyle == FillSolid ||
+             (gc->fillStyle == FillTiled && gc->tileIsPixel)),
+            gc->fillStyle, gc->tileIsPixel,
+            gc->alu));
+
+       data.flags = sna_poly_arc_extents(draw, gc, n, arc,
+                                         &data.region.extents);
+       if (data.flags == 0)
+               return;
+
+       DBG(("%s: extents(%d, %d), (%d, %d), flags=%x\n", __FUNCTION__,
+            data.region.extents.x1, data.region.extents.y1,
+            data.region.extents.x2, data.region.extents.y2,
+            data.flags));
+
+       data.region.data = NULL;
+
+       if (FORCE_FALLBACK)
+               goto fallback;
+
+       if (!ACCEL_POLY_FILL_ARC)
+               goto fallback;
+
+       data.pixmap = get_drawable_pixmap(draw);
+       data.sna = to_sna_from_pixmap(data.pixmap);
+       priv = sna_pixmap(data.pixmap);
+       if (priv == NULL) {
+               DBG(("%s: fallback -- unattached\n", __FUNCTION__));
+               goto fallback;
+       }
+
+       if (wedged(data.sna)) {
+               DBG(("%s: fallback -- wedged\n", __FUNCTION__));
+               goto fallback;
+       }
+
+       if (!PM_IS_SOLID(draw, gc->planemask))
+               goto fallback;
+
+       if ((data.bo = sna_drawable_use_bo(draw, PREFER_GPU,
+                                          &data.region.extents,
+                                          &data.damage))) {
+               uint32_t color;
+
+               get_drawable_deltas(draw, data.pixmap, &data.dx, &data.dy);
+               sna_gc(gc)->priv = &data;
+
+               if (gc_is_solid(gc, &color)) {
+                       struct sna_fill_op fill;
+
+                       if (!sna_fill_init_blt(&fill,
+                                              data.sna, data.pixmap,
+                                              data.bo, gc->alu, color))
+                               goto fallback;
+
+                       data.op = &fill;
+
+                       if ((data.flags & 2) == 0) {
+                               if (data.dx | data.dy)
+                                       sna_gc_ops__tmp.FillSpans = sna_fill_spans__fill_offset;
+                               else
+                                       sna_gc_ops__tmp.FillSpans = sna_fill_spans__fill;
+                       } else {
+                               region_maybe_clip(&data.region,
+                                                 gc->pCompositeClip);
+                               if (!RegionNotEmpty(&data.region))
+                                       return;
+
+                               if (region_is_singular(&data.region))
+                                       sna_gc_ops__tmp.FillSpans = sna_fill_spans__fill_clip_extents;
+                               else
+                                       sna_gc_ops__tmp.FillSpans = sna_fill_spans__fill_clip_boxes;
+                       }
+                       assert(gc->miTranslate);
+                       gc->ops = &sna_gc_ops__tmp;
+
+                       miPolyFillArc(draw, gc, n, arc);
+                       fill.done(data.sna, &fill);
+               } else {
+                       sna_gc_ops__tmp.FillSpans = sna_fill_spans__gpu;
+                       gc->ops = &sna_gc_ops__tmp;
+
+                       miPolyFillArc(draw, gc, n, arc);
+               }
+
+               gc->ops = (GCOps *)&sna_gc_ops;
+               if (data.damage) {
+                       if (data.dx | data.dy)
+                               pixman_region_translate(&data.region, data.dx, data.dy);
+                       assert_pixmap_contains_box(data.pixmap, &data.region.extents);
+                       sna_damage_add(data.damage, &data.region);
+               }
+               assert_pixmap_damage(data.pixmap);
+               RegionUninit(&data.region);
+               return;
+       }
+
+fallback:
+       DBG(("%s: fallback (%d, %d), (%d, %d)\n", __FUNCTION__,
+            data.region.extents.x1, data.region.extents.y1,
+            data.region.extents.x2, data.region.extents.y2));
+       region_maybe_clip(&data.region, gc->pCompositeClip);
+       if (!RegionNotEmpty(&data.region)) {
+               DBG(("%s: nothing to do, all clipped\n", __FUNCTION__));
+               return;
+       }
+
+       if (!sna_gc_move_to_cpu(gc, draw, &data.region))
+               goto out;
+       if (!sna_drawable_move_region_to_cpu(draw, &data.region,
+                                            drawable_gc_flags(draw, gc, true)))
+               goto out_gc;
+
+       DBG(("%s: fallback -- miPolyFillArc -> sna_fill_spans__cpu\n",
+            __FUNCTION__));
+
+       miPolyFillArc(draw, gc, n, arc);
+out_gc:
+       sna_gc_move_to_gpu(gc);
+out:
+       RegionUninit(&data.region);
+}
+
+struct sna_font {
+       CharInfoRec glyphs8[256];
+       CharInfoRec *glyphs16[256];
+};
+#define GLYPH_INVALID (void *)1
+#define GLYPH_EMPTY (void *)2
+#define GLYPH_CLEAR (void *)3
+
+static Bool
+sna_realize_font(ScreenPtr screen, FontPtr font)
+{
+       struct sna_font *priv;
+
+       DBG(("%s (key=%d)\n", __FUNCTION__, sna_font_key));
+
+       priv = calloc(1, sizeof(struct sna_font));
+       if (priv == NULL)
+               return FALSE;
+
+       if (!FontSetPrivate(font, sna_font_key, priv)) {
+               free(priv);
+               return FALSE;
+       }
+
+       return TRUE;
+}
+
+static Bool
+sna_unrealize_font(ScreenPtr screen, FontPtr font)
+{
+       struct sna_font *priv = FontGetPrivate(font, sna_font_key);
+       int i, j;
+
+       DBG(("%s (key=%d)\n", __FUNCTION__, sna_font_key));
+
+       if (priv == NULL)
+               return TRUE;
+
+       for (i = 0; i < 256; i++) {
+               if ((uintptr_t)priv->glyphs8[i].bits & ~3)
+                       free(priv->glyphs8[i].bits);
+       }
+       for (j = 0; j < 256; j++) {
+               if (priv->glyphs16[j] == NULL)
+                       continue;
+
+               for (i = 0; i < 256; i++) {
+                       if ((uintptr_t)priv->glyphs16[j][i].bits & ~3)
+                               free(priv->glyphs16[j][i].bits);
+               }
+               free(priv->glyphs16[j]);
+       }
+       free(priv);
+
+       FontSetPrivate(font, sna_font_key, NULL);
+       return TRUE;
+}
+
+static bool
+sna_glyph_blt(DrawablePtr drawable, GCPtr gc,
+             int _x, int _y, unsigned int _n,
+             CharInfoPtr *_info,
+             RegionRec *clip,
+             uint32_t fg, uint32_t bg,
+             bool transparent)
+{
+       PixmapPtr pixmap = get_drawable_pixmap(drawable);
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+       struct kgem_bo *bo;
+       struct sna_damage **damage;
+       const BoxRec *extents, *last_extents;
+       uint32_t *b;
+       int16_t dx, dy;
+       uint32_t br00;
+
+       uint8_t rop = transparent ? copy_ROP[gc->alu] : ROP_S;
+
+       DBG(("%s (%d, %d) x %d, fg=%08x, bg=%08x alu=%02x\n",
+            __FUNCTION__, _x, _y, _n, fg, bg, rop));
+
+       if (wedged(sna)) {
+               DBG(("%s: fallback -- wedged\n", __FUNCTION__));
+               return false;
+       }
+
+       bo = sna_drawable_use_bo(drawable, PREFER_GPU, &clip->extents, &damage);
+       if (bo == NULL)
+               return false;
+
+       if (bo->tiling == I915_TILING_Y) {
+               DBG(("%s: converting bo from Y-tiling\n", __FUNCTION__));
+               assert(bo == sna_pixmap_get_bo(pixmap));
+               bo = sna_pixmap_change_tiling(pixmap, I915_TILING_X);
+               if (bo == NULL) {
+                       DBG(("%s: fallback -- unable to change tiling\n",
+                            __FUNCTION__));
+                       return false;
+               }
+       }
+
+       get_drawable_deltas(drawable, pixmap, &dx, &dy);
+       _x += drawable->x + dx;
+       _y += drawable->y + dy;
+
+       RegionTranslate(clip, dx, dy);
+       extents = REGION_RECTS(clip);
+       last_extents = extents + REGION_NUM_RECTS(clip);
+
+       if (!transparent) /* emulate miImageGlyphBlt */
+               sna_blt_fill_boxes(sna, GXcopy,
+                                  bo, drawable->bitsPerPixel,
+                                  bg, extents, REGION_NUM_RECTS(clip));
+
+       kgem_set_mode(&sna->kgem, KGEM_BLT);
+       if (!kgem_check_batch(&sna->kgem, 16) ||
+           !kgem_check_bo_fenced(&sna->kgem, bo) ||
+           !kgem_check_reloc(&sna->kgem, 1)) {
+               _kgem_submit(&sna->kgem);
+               _kgem_set_mode(&sna->kgem, KGEM_BLT);
+       }
+
+       DBG(("%s: glyph clip box (%d, %d), (%d, %d)\n",
+            __FUNCTION__,
+            extents->x1, extents->y1,
+            extents->x2, extents->y2));
+
+       b = sna->kgem.batch + sna->kgem.nbatch;
+       b[0] = XY_SETUP_BLT | 3 << 20;
+       b[1] = bo->pitch;
+       if (sna->kgem.gen >= 40 && bo->tiling) {
+               b[0] |= BLT_DST_TILED;
+               b[1] >>= 2;
+       }
+       b[1] |= 1 << 30 | transparent << 29 | blt_depth(drawable->depth) << 24 | rop << 16;
+       b[2] = extents->y1 << 16 | extents->x1;
+       b[3] = extents->y2 << 16 | extents->x2;
+       b[4] = kgem_add_reloc(&sna->kgem, sna->kgem.nbatch + 4, bo,
+                             I915_GEM_DOMAIN_RENDER << 16 |
+                             I915_GEM_DOMAIN_RENDER |
+                             KGEM_RELOC_FENCED,
+                             0);
+       b[5] = bg;
+       b[6] = fg;
+       b[7] = 0;
+       sna->kgem.nbatch += 8;
+
+       br00 = XY_TEXT_IMMEDIATE_BLT;
+       if (bo->tiling && sna->kgem.gen >= 40)
+               br00 |= BLT_DST_TILED;
+
+       do {
+               CharInfoPtr *info = _info;
+               int x = _x, y = _y, n = _n;
+
+               do {
+                       CharInfoPtr c = *info++;
+                       int w = GLYPHWIDTHPIXELS(c);
+                       int h = GLYPHHEIGHTPIXELS(c);
+                       int w8 = (w + 7) >> 3;
+                       int x1, y1, len;
+
+                       if (c->bits == GLYPH_EMPTY)
+                               goto skip;
+
+                       if (!transparent && c->bits == GLYPH_CLEAR)
+                               goto skip;
+
+                       len = (w8 * h + 7) >> 3 << 1;
+                       x1 = x + c->metrics.leftSideBearing;
+                       y1 = y - c->metrics.ascent;
+
+                       DBG(("%s glyph: (%d, %d) -> (%d, %d) x (%d[%d], %d), len=%d\n" ,__FUNCTION__,
+                            x,y, x1, y1, w, w8, h, len));
+
+                       if (x1 >= extents->x2 || y1 >= extents->y2)
+                               goto skip;
+                       if (x1 + w <= extents->x1 || y1 + h <= extents->y1)
+                               goto skip;
+
+
+                       if (!kgem_check_batch(&sna->kgem, 3+len)) {
+                               _kgem_submit(&sna->kgem);
+                               _kgem_set_mode(&sna->kgem, KGEM_BLT);
+
+                               DBG(("%s: new batch, glyph clip box (%d, %d), (%d, %d)\n",
+                                    __FUNCTION__,
+                                    extents->x1, extents->y1,
+                                    extents->x2, extents->y2));
+
+                               b = sna->kgem.batch + sna->kgem.nbatch;
+                               b[0] = XY_SETUP_BLT | 3 << 20;
+                               b[1] = bo->pitch;
+                               if (sna->kgem.gen >= 40 && bo->tiling) {
+                                       b[0] |= BLT_DST_TILED;
+                                       b[1] >>= 2;
+                               }
+                               b[1] |= 1 << 30 | transparent << 29 | blt_depth(drawable->depth) << 24 | rop << 16;
+                               b[2] = extents->y1 << 16 | extents->x1;
+                               b[3] = extents->y2 << 16 | extents->x2;
+                               b[4] = kgem_add_reloc(&sna->kgem, sna->kgem.nbatch + 4, bo,
+                                                     I915_GEM_DOMAIN_RENDER << 16 |
+                                                     I915_GEM_DOMAIN_RENDER |
+                                                     KGEM_RELOC_FENCED,
+                                                     0);
+                               b[5] = bg;
+                               b[6] = fg;
+                               b[7] = 0;
+                               sna->kgem.nbatch += 8;
+                       }
+
+                       b = sna->kgem.batch + sna->kgem.nbatch;
+                       sna->kgem.nbatch += 3 + len;
+
+                       b[0] = br00 | (1 + len);
+                       b[1] = (uint16_t)y1 << 16 | (uint16_t)x1;
+                       b[2] = (uint16_t)(y1+h) << 16 | (uint16_t)(x1+w);
+                       if (c->bits == GLYPH_CLEAR) {
+                               memset(b+3, 0, len*4);
+                       } else {
+                               uint64_t *src = (uint64_t *)c->bits;
+                               uint64_t *dst = (uint64_t *)(b + 3);
+                               do  {
+                                       *dst++ = *src++;
+                                       len -= 2;
+                               } while (len);
+                       }
+
+                       if (damage) {
+                               BoxRec r;
+
+                               r.x1 = x1;
+                               r.y1 = y1;
+                               r.x2 = x1 + w;
+                               r.y2 = y1 + h;
+                               if (box_intersect(&r, extents))
+                                       sna_damage_add_box(damage, &r);
+                       }
+skip:
+                       x += c->metrics.characterWidth;
+               } while (--n);
+
+               if (++extents == last_extents)
+                       break;
+
+               if (kgem_check_batch(&sna->kgem, 3)) {
+                       b = sna->kgem.batch + sna->kgem.nbatch;
+                       sna->kgem.nbatch += 3;
+
+                       DBG(("%s: glyph clip box (%d, %d), (%d, %d)\n",
+                            __FUNCTION__,
+                            extents->x1, extents->y1,
+                            extents->x2, extents->y2));
+
+                       b[0] = XY_SETUP_CLIP;
+                       b[1] = extents->y1 << 16 | extents->x1;
+                       b[2] = extents->y2 << 16 | extents->x2;
+               }
+       } while (1);
+
+       assert_pixmap_damage(pixmap);
+       sna->blt_state.fill_bo = 0;
+       return true;
+}
+
+static void
+sna_glyph_extents(FontPtr font,
+                 CharInfoPtr *info,
+                 unsigned long count,
+                 ExtentInfoRec *extents)
+{
+       extents->drawDirection = font->info.drawDirection;
+       extents->fontAscent = font->info.fontAscent;
+       extents->fontDescent = font->info.fontDescent;
+
+       extents->overallAscent = info[0]->metrics.ascent;
+       extents->overallDescent = info[0]->metrics.descent;
+       extents->overallLeft = info[0]->metrics.leftSideBearing;
+       extents->overallRight = info[0]->metrics.rightSideBearing;
+       extents->overallWidth = info[0]->metrics.characterWidth;
+
+       while (--count) {
+               CharInfoPtr p =*++info;
+               int v;
+
+               if (p->metrics.ascent > extents->overallAscent)
+                       extents->overallAscent = p->metrics.ascent;
+               if (p->metrics.descent > extents->overallDescent)
+                       extents->overallDescent = p->metrics.descent;
+
+               v = extents->overallWidth + p->metrics.leftSideBearing;
+               if (v < extents->overallLeft)
+                       extents->overallLeft = v;
+
+               v = extents->overallWidth + p->metrics.rightSideBearing;
+               if (v > extents->overallRight)
+                       extents->overallRight = v;
+
+               extents->overallWidth += p->metrics.characterWidth;
+       }
+}
+
+static bool sna_set_glyph(CharInfoPtr in, CharInfoPtr out)
+{
+       int w = GLYPHWIDTHPIXELS(in);
+       int h = GLYPHHEIGHTPIXELS(in);
+       int stride = GLYPHWIDTHBYTESPADDED(in);
+       uint8_t *dst, *src;
+       int clear = 1;
+
+       out->metrics = in->metrics;
+
+       /* Skip empty glyphs */
+       if (w == 0 || h == 0 || ((w|h) == 1 && (in->bits[0] & 1) == 0)) {
+               out->bits = GLYPH_EMPTY;
+               return true;
+       }
+
+       w = (w + 7) >> 3;
+
+       out->bits = malloc((w*h + 7) & ~7);
+       if (out->bits == NULL)
+               return false;
+
+       VG(memset(out->bits, 0, (w*h + 7) & ~7));
+       src = (uint8_t *)in->bits;
+       dst = (uint8_t *)out->bits;
+       stride -= w;
+       do {
+               int i = w;
+               do {
+                       clear &= *src == 0;
+                       *dst++ = byte_reverse(*src++);
+               } while (--i);
+               src += stride;
+       } while (--h);
+
+       if (clear) {
+               free(out->bits);
+               out->bits = GLYPH_CLEAR;
+       }
+
+       return true;
+}
+
+inline static bool sna_get_glyph8(FontPtr font, struct sna_font *priv,
+                                 uint8_t g, CharInfoPtr *out)
+{
+       unsigned long n;
+       CharInfoPtr p, ret;
+
+       p = &priv->glyphs8[g];
+       if (p->bits) {
+               *out = p;
+               return p->bits != GLYPH_INVALID;
+       }
+
+       font->get_glyphs(font, 1, &g, Linear8Bit, &n, &ret);
+       if (n == 0) {
+               p->bits = GLYPH_INVALID;
+               return false;
+       }
+
+       return sna_set_glyph(ret, *out = p);
+}
+
+inline static bool sna_get_glyph16(FontPtr font, struct sna_font *priv,
+                                  uint16_t g, CharInfoPtr *out)
+{
+       unsigned long n;
+       CharInfoPtr page, p, ret;
+
+       page = priv->glyphs16[g>>8];
+       if (page == NULL)
+               page = priv->glyphs16[g>>8] = calloc(256, sizeof(CharInfoRec));
+
+       p = &page[g&0xff];
+       if (p->bits) {
+               *out = p;
+               return p->bits != GLYPH_INVALID;
+       }
+
+       font->get_glyphs(font, 1, (unsigned char *)&g,
+                        FONTLASTROW(font) ? TwoD16Bit : Linear16Bit,
+                        &n, &ret);
+       if (n == 0) {
+               p->bits = GLYPH_INVALID;
+               return false;
+       }
+
+       return sna_set_glyph(ret, *out = p);
+}
+
+static inline bool sna_font_too_large(FontPtr font)
+{
+       int top = max(FONTMAXBOUNDS(font, ascent), FONTASCENT(font));
+       int bot = max(FONTMAXBOUNDS(font, descent), FONTDESCENT(font));
+       int width = max(FONTMAXBOUNDS(font, characterWidth), -FONTMINBOUNDS(font, characterWidth));
+       DBG(("%s? (%d + %d) x %d: %d > 124\n", __FUNCTION__,
+            top, bot, width, (top + bot) * (width + 7)/8));
+       return (top + bot) * (width + 7)/8 > 124;
+}
+
+static int
+sna_poly_text8(DrawablePtr drawable, GCPtr gc,
+              int x, int y,
+              int count, char *chars)
+{
+       struct sna_font *priv = gc->font->devPrivates[sna_font_key];
+       CharInfoPtr info[255];
+       ExtentInfoRec extents;
+       RegionRec region;
+       long unsigned i, n;
+       uint32_t fg;
+
+       for (i = n = 0; i < count; i++) {
+               if (sna_get_glyph8(gc->font, priv, chars[i], &info[n]))
+                       n++;
+       }
+       if (n == 0)
+               return x;
+
+       sna_glyph_extents(gc->font, info, n, &extents);
+       region.extents.x1 = x + extents.overallLeft;
+       region.extents.y1 = y - extents.overallAscent;
+       region.extents.x2 = x + extents.overallRight;
+       region.extents.y2 = y + extents.overallDescent;
+
+       translate_box(&region.extents, drawable);
+       clip_box(&region.extents, gc);
+       if (box_empty(&region.extents))
+               return x + extents.overallRight;
+
+       region.data = NULL;
+       region_maybe_clip(&region, gc->pCompositeClip);
+       if (!RegionNotEmpty(&region))
+               return x + extents.overallRight;
+
+       if (FORCE_FALLBACK)
+               goto fallback;
+
+       if (!ACCEL_POLY_TEXT8)
+               goto fallback;
+
+       if (sna_font_too_large(gc->font))
+               goto fallback;
+
+       if (!PM_IS_SOLID(drawable, gc->planemask))
+               goto fallback;
+
+       if (!gc_is_solid(gc, &fg))
+               goto fallback;
+
+       if (!sna_glyph_blt(drawable, gc, x, y, n, info, &region, fg, -1, true)) {
+fallback:
+               DBG(("%s: fallback\n", __FUNCTION__));
+               gc->font->get_glyphs(gc->font, count, (unsigned char *)chars,
+                                    Linear8Bit, &n, info);
+
+               if (!sna_gc_move_to_cpu(gc, drawable, &region))
+                       goto out;
+               if (!sna_drawable_move_region_to_cpu(drawable, &region,
+                                                    MOVE_READ | MOVE_WRITE))
+                       goto out_gc;
+
+               DBG(("%s: fallback -- fbPolyGlyphBlt\n", __FUNCTION__));
+               fbPolyGlyphBlt(drawable, gc, x, y, n,
+                              info, FONTGLYPHS(gc->font));
+               FALLBACK_FLUSH(drawable);
+out_gc:
+               sna_gc_move_to_gpu(gc);
+       }
+out:
+       RegionUninit(&region);
+       return x + extents.overallRight;
+}
+
+static int
+sna_poly_text16(DrawablePtr drawable, GCPtr gc,
+               int x, int y,
+               int count, unsigned short *chars)
+{
+       struct sna_font *priv = gc->font->devPrivates[sna_font_key];
+       CharInfoPtr info[255];
+       ExtentInfoRec extents;
+       RegionRec region;
+       long unsigned i, n;
+       uint32_t fg;
+
+       for (i = n = 0; i < count; i++) {
+               if (sna_get_glyph16(gc->font, priv, chars[i], &info[n]))
+                       n++;
+       }
+       if (n == 0)
+               return x;
+
+       sna_glyph_extents(gc->font, info, n, &extents);
+       region.extents.x1 = x + extents.overallLeft;
+       region.extents.y1 = y - extents.overallAscent;
+       region.extents.x2 = x + extents.overallRight;
+       region.extents.y2 = y + extents.overallDescent;
+
+       translate_box(&region.extents, drawable);
+       clip_box(&region.extents, gc);
+       if (box_empty(&region.extents))
+               return x + extents.overallRight;
+
+       region.data = NULL;
+       region_maybe_clip(&region, gc->pCompositeClip);
+       if (!RegionNotEmpty(&region))
+               return x + extents.overallRight;
+
+       if (FORCE_FALLBACK)
+               goto fallback;
+
+       if (!ACCEL_POLY_TEXT16)
+               goto fallback;
+
+       if (sna_font_too_large(gc->font))
+               goto fallback;
+
+       if (!PM_IS_SOLID(drawable, gc->planemask))
+               goto fallback;
+
+       if (!gc_is_solid(gc, &fg))
+               goto fallback;
+
+       if (!sna_glyph_blt(drawable, gc, x, y, n, info, &region, fg, -1, true)) {
+fallback:
+               DBG(("%s: fallback\n", __FUNCTION__));
+               gc->font->get_glyphs(gc->font, count, (unsigned char *)chars,
+                                    FONTLASTROW(gc->font) ? TwoD16Bit : Linear16Bit,
+                                    &n, info);
+
+               if (!sna_gc_move_to_cpu(gc, drawable, &region))
+                       goto out;
+               if (!sna_drawable_move_region_to_cpu(drawable, &region,
+                                                    MOVE_READ | MOVE_WRITE))
+                       goto out_gc;
+
+               DBG(("%s: fallback -- fbPolyGlyphBlt\n", __FUNCTION__));
+               fbPolyGlyphBlt(drawable, gc, x, y, n,
+                              info, FONTGLYPHS(gc->font));
+               FALLBACK_FLUSH(drawable);
+out_gc:
+               sna_gc_move_to_gpu(gc);
+       }
+out:
+       RegionUninit(&region);
+       return x + extents.overallRight;
+}
+
+static void
+sna_image_text8(DrawablePtr drawable, GCPtr gc,
+              int x, int y,
+              int count, char *chars)
+{
+       struct sna_font *priv = gc->font->devPrivates[sna_font_key];
+       CharInfoPtr info[255];
+       ExtentInfoRec extents;
+       RegionRec region;
+       long unsigned i, n;
+
+       for (i = n = 0; i < count; i++) {
+               if (sna_get_glyph8(gc->font, priv, chars[i], &info[n]))
+                       n++;
+       }
+       if (n == 0)
+               return;
+
+       sna_glyph_extents(gc->font, info, n, &extents);
+       region.extents.x1 = x + MIN(0, extents.overallLeft);
+       region.extents.y1 = y - extents.fontAscent;
+       region.extents.x2 = x + MAX(extents.overallWidth, extents.overallRight);
+       region.extents.y2 = y + extents.fontDescent;
+
+       DBG(("%s: count=%ld/%d, extents=(left=%d, right=%d, width=%d, ascent=%d, descent=%d), box=(%d, %d), (%d, %d)\n",
+            __FUNCTION__, n, count,
+            extents.overallLeft, extents.overallRight, extents.overallWidth,
+            extents.fontAscent, extents.fontDescent,
+            region.extents.x1, region.extents.y1,
+            region.extents.x2, region.extents.y2));
+
+       translate_box(&region.extents, drawable);
+       clip_box(&region.extents, gc);
+       if (box_empty(&region.extents))
+               return;
+
+       region.data = NULL;
+       region_maybe_clip(&region, gc->pCompositeClip);
+       if (!RegionNotEmpty(&region))
+               return;
+
+       DBG(("%s: clipped extents (%d, %d), (%d, %d)\n",
+            __FUNCTION__,
+            region.extents.x1, region.extents.y1,
+            region.extents.x2, region.extents.y2));
+
+       if (FORCE_FALLBACK)
+               goto fallback;
+
+       if (!ACCEL_IMAGE_TEXT8)
+               goto fallback;
+
+       if (sna_font_too_large(gc->font))
+               goto fallback;
+
+       if (!PM_IS_SOLID(drawable, gc->planemask))
+               goto fallback;
+
+       if (!sna_glyph_blt(drawable, gc, x, y, n, info, &region,
+                          gc->fgPixel, gc->bgPixel, false)) {
+fallback:
+               DBG(("%s: fallback\n", __FUNCTION__));
+               gc->font->get_glyphs(gc->font, count, (unsigned char *)chars,
+                                    Linear8Bit, &n, info);
+
+               if (!sna_gc_move_to_cpu(gc, drawable, &region))
+                       goto out;
+               if (!sna_drawable_move_region_to_cpu(drawable, &region,
+                                                    MOVE_READ | MOVE_WRITE))
+                       goto out_gc;
+
+               DBG(("%s: fallback -- fbImageGlyphBlt\n", __FUNCTION__));
+               fbImageGlyphBlt(drawable, gc, x, y, n,
+                               info, FONTGLYPHS(gc->font));
+               FALLBACK_FLUSH(drawable);
+out_gc:
+               sna_gc_move_to_gpu(gc);
+       }
+out:
+       RegionUninit(&region);
+}
+
+static void
+sna_image_text16(DrawablePtr drawable, GCPtr gc,
+              int x, int y,
+              int count, unsigned short *chars)
+{
+       struct sna_font *priv = gc->font->devPrivates[sna_font_key];
+       CharInfoPtr info[255];
+       ExtentInfoRec extents;
+       RegionRec region;
+       long unsigned i, n;
+
+       for (i = n = 0; i < count; i++) {
+               if (sna_get_glyph16(gc->font, priv, chars[i], &info[n]))
+                       n++;
+       }
+       if (n == 0)
+               return;
+
+       sna_glyph_extents(gc->font, info, n, &extents);
+       region.extents.x1 = x + MIN(0, extents.overallLeft);
+       region.extents.y1 = y - extents.fontAscent;
+       region.extents.x2 = x + MAX(extents.overallWidth, extents.overallRight);
+       region.extents.y2 = y + extents.fontDescent;
+
+       DBG(("%s: count=%ld/%d, extents=(left=%d, right=%d, width=%d, ascent=%d, descent=%d), box=(%d, %d), (%d, %d)\n",
+            __FUNCTION__, n, count,
+            extents.overallLeft, extents.overallRight, extents.overallWidth,
+            extents.fontAscent, extents.fontDescent,
+            region.extents.x1, region.extents.y1,
+            region.extents.x2, region.extents.y2));
+
+       translate_box(&region.extents, drawable);
+       clip_box(&region.extents, gc);
+       if (box_empty(&region.extents))
+               return;
+
+       region.data = NULL;
+       region_maybe_clip(&region, gc->pCompositeClip);
+       if (!RegionNotEmpty(&region))
+               return;
+
+       DBG(("%s: clipped extents (%d, %d), (%d, %d)\n",
+            __FUNCTION__,
+            region.extents.x1, region.extents.y1,
+            region.extents.x2, region.extents.y2));
+
+       if (FORCE_FALLBACK)
+               goto fallback;
+
+       if (!ACCEL_IMAGE_TEXT16)
+               goto fallback;
+
+       if (sna_font_too_large(gc->font))
+               goto fallback;
+
+       if (!PM_IS_SOLID(drawable, gc->planemask))
+               goto fallback;
+
+       if (!sna_glyph_blt(drawable, gc, x, y, n, info, &region,
+                          gc->fgPixel, gc->bgPixel, false)) {
+fallback:
+               DBG(("%s: fallback\n", __FUNCTION__));
+               gc->font->get_glyphs(gc->font, count, (unsigned char *)chars,
+                                    FONTLASTROW(gc->font) ? TwoD16Bit : Linear16Bit,
+                                    &n, info);
+
+               if (!sna_gc_move_to_cpu(gc, drawable, &region))
+                       goto out;
+               if (!sna_drawable_move_region_to_cpu(drawable, &region,
+                                                    MOVE_READ | MOVE_WRITE))
+                       goto out_gc;
+
+               DBG(("%s: fallback -- fbImageGlyphBlt\n", __FUNCTION__));
+               fbImageGlyphBlt(drawable, gc, x, y, n,
+                               info, FONTGLYPHS(gc->font));
+               FALLBACK_FLUSH(drawable);
+out_gc:
+               sna_gc_move_to_gpu(gc);
+       }
+out:
+       RegionUninit(&region);
+}
+
+/* XXX Damage bypasses the Text interface and so we lose our custom gluphs */
+static bool
+sna_reversed_glyph_blt(DrawablePtr drawable, GCPtr gc,
+                      int _x, int _y, unsigned int _n,
+                      CharInfoPtr *_info, pointer _base,
+                      struct kgem_bo *bo,
+                      struct sna_damage **damage,
+                      RegionPtr clip,
+                      uint32_t fg, uint32_t bg,
+                      bool transparent)
+{
+       PixmapPtr pixmap = get_drawable_pixmap(drawable);
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+       const BoxRec *extents, *last_extents;
+       uint32_t *b;
+       int16_t dx, dy;
+       uint8_t rop = transparent ? copy_ROP[gc->alu] : ROP_S;
+
+       if (bo->tiling == I915_TILING_Y) {
+               DBG(("%s: converting bo from Y-tiling\n", __FUNCTION__));
+               assert(bo == sna_pixmap_get_bo(pixmap));
+               bo = sna_pixmap_change_tiling(pixmap, I915_TILING_X);
+               if (bo == NULL) {
+                       DBG(("%s: fallback -- unable to change tiling\n",
+                            __FUNCTION__));
+                       return false;
+               }
+       }
+
+       get_drawable_deltas(drawable, pixmap, &dx, &dy);
+       _x += drawable->x + dx;
+       _y += drawable->y + dy;
+
+       RegionTranslate(clip, dx, dy);
+       extents = REGION_RECTS(clip);
+       last_extents = extents + REGION_NUM_RECTS(clip);
+
+       if (!transparent) /* emulate miImageGlyphBlt */
+               sna_blt_fill_boxes(sna, GXcopy,
+                                  bo, drawable->bitsPerPixel,
+                                  bg, extents, REGION_NUM_RECTS(clip));
+
+       kgem_set_mode(&sna->kgem, KGEM_BLT);
+       if (!kgem_check_batch(&sna->kgem, 16) ||
+           !kgem_check_bo_fenced(&sna->kgem, bo) ||
+           !kgem_check_reloc(&sna->kgem, 1)) {
+               _kgem_submit(&sna->kgem);
+               _kgem_set_mode(&sna->kgem, KGEM_BLT);
+       }
+
+       DBG(("%s: glyph clip box (%d, %d), (%d, %d)\n",
+            __FUNCTION__,
+            extents->x1, extents->y1,
+            extents->x2, extents->y2));
+       b = sna->kgem.batch + sna->kgem.nbatch;
+       b[0] = XY_SETUP_BLT | 1 << 20;
+       b[1] = bo->pitch;
+       if (sna->kgem.gen >= 40 && bo->tiling) {
+               b[0] |= BLT_DST_TILED;
+               b[1] >>= 2;
+       }
+       b[1] |= 1 << 30 | transparent << 29 | blt_depth(drawable->depth) << 24 | rop << 16;
+       b[2] = extents->y1 << 16 | extents->x1;
+       b[3] = extents->y2 << 16 | extents->x2;
+       b[4] = kgem_add_reloc(&sna->kgem, sna->kgem.nbatch + 4, bo,
+                             I915_GEM_DOMAIN_RENDER << 16 |
+                             I915_GEM_DOMAIN_RENDER |
+                             KGEM_RELOC_FENCED,
+                             0);
+       b[5] = bg;
+       b[6] = fg;
+       b[7] = 0;
+       sna->kgem.nbatch += 8;
+
+       do {
+               CharInfoPtr *info = _info;
+               int x = _x, y = _y, n = _n;
+
+               do {
+                       CharInfoPtr c = *info++;
+                       uint8_t *glyph = FONTGLYPHBITS(base, c);
+                       int w = GLYPHWIDTHPIXELS(c);
+                       int h = GLYPHHEIGHTPIXELS(c);
+                       int stride = GLYPHWIDTHBYTESPADDED(c);
+                       int w8 = (w + 7) >> 3;
+                       int x1, y1, len, i;
+                       uint8_t *byte;
+
+                       if (w == 0 || h == 0)
+                               goto skip;
+
+                       len = (w8 * h + 7) >> 3 << 1;
+                       x1 = x + c->metrics.leftSideBearing;
+                       y1 = y - c->metrics.ascent;
+
+                       DBG(("%s glyph: (%d, %d) -> (%d, %d) x (%d[%d], %d), len=%d\n" ,__FUNCTION__,
+                            x,y, x1, y1, w, w8, h, len));
+
+                       if (x1 >= extents->x2 || y1 >= extents->y2 ||
+                           x1 + w <= extents->x1 || y1 + h <= extents->y1) {
+                               DBG(("%s: glyph is clipped (%d, %d)x(%d,%d) against extents (%d, %d), (%d, %d)\n",
+                                    __FUNCTION__,
+                                    x1, y1, w, h,
+                                    extents->x1, extents->y1,
+                                    extents->x2, extents->y2));
+                               goto skip;
+                       }
+
+                       if (!transparent) {
+                               int clear = 1, j = h;
+                               uint8_t *g = glyph;
+
+                               do {
+                                       i = w8;
+                                       do {
+                                               clear = *g++ == 0;
+                                       } while (clear && --i);
+                                       g += stride - w8;
+                               } while (clear && --j);
+                               if (clear) {
+                                       DBG(("%s: skipping clear glyph for ImageGlyph\n",
+                                            __FUNCTION__));
+                                       goto skip;
+                               }
+                       }
+
+                       if (!kgem_check_batch(&sna->kgem, 3+len)) {
+                               _kgem_submit(&sna->kgem);
+                               _kgem_set_mode(&sna->kgem, KGEM_BLT);
+
+                               DBG(("%s: new batch, glyph clip box (%d, %d), (%d, %d)\n",
+                                    __FUNCTION__,
+                                    extents->x1, extents->y1,
+                                    extents->x2, extents->y2));
+
+                               b = sna->kgem.batch + sna->kgem.nbatch;
+                               b[0] = XY_SETUP_BLT | 1 << 20;
+                               b[1] = bo->pitch;
+                               if (sna->kgem.gen >= 40 && bo->tiling) {
+                                       b[0] |= BLT_DST_TILED;
+                                       b[1] >>= 2;
+                               }
+                               b[1] |= 1 << 30 | transparent << 29 | blt_depth(drawable->depth) << 24 | rop << 16;
+                               b[2] = extents->y1 << 16 | extents->x1;
+                               b[3] = extents->y2 << 16 | extents->x2;
+                               b[4] = kgem_add_reloc(&sna->kgem, sna->kgem.nbatch + 4,
+                                                     bo,
+                                                     I915_GEM_DOMAIN_RENDER << 16 |
+                                                     I915_GEM_DOMAIN_RENDER |
+                                                     KGEM_RELOC_FENCED,
+                                                     0);
+                               b[5] = bg;
+                               b[6] = fg;
+                               b[7] = 0;
+                               sna->kgem.nbatch += 8;
+                       }
+
+                       b = sna->kgem.batch + sna->kgem.nbatch;
+                       sna->kgem.nbatch += 3 + len;
+
+                       b[0] = XY_TEXT_IMMEDIATE_BLT | (1 + len);
+                       if (bo->tiling && sna->kgem.gen >= 40)
+                               b[0] |= BLT_DST_TILED;
+                       b[1] = (uint16_t)y1 << 16 | (uint16_t)x1;
+                       b[2] = (uint16_t)(y1+h) << 16 | (uint16_t)(x1+w);
+
+                       byte = (uint8_t *)&b[3];
+                       stride -= w8;
+                       do {
+                               i = w8;
+                               do {
+                                       *byte++ = byte_reverse(*glyph++);
+                               } while (--i);
+                               glyph += stride;
+                       } while (--h);
+                       while ((byte - (uint8_t *)&b[3]) & 7)
+                               *byte++ = 0;
+                       assert((uint32_t *)byte == sna->kgem.batch + sna->kgem.nbatch);
+
+                       if (damage) {
+                               BoxRec r;
+
+                               r.x1 = x1;
+                               r.y1 = y1;
+                               r.x2 = x1 + w;
+                               r.y2 = y1 + h;
+                               if (box_intersect(&r, extents))
+                                       sna_damage_add_box(damage, &r);
+                       }
+skip:
+                       x += c->metrics.characterWidth;
+               } while (--n);
+
+               if (++extents == last_extents)
+                       break;
+
+               if (kgem_check_batch(&sna->kgem, 3 + 5)) {
+                       b = sna->kgem.batch + sna->kgem.nbatch;
+                       sna->kgem.nbatch += 3;
+
+                       DBG(("%s: glyph clip box (%d, %d), (%d, %d)\n",
+                            __FUNCTION__,
+                            extents->x1, extents->y1,
+                            extents->x2, extents->y2));
+
+                       b[0] = XY_SETUP_CLIP;
+                       b[1] = extents->y1 << 16 | extents->x1;
+                       b[2] = extents->y2 << 16 | extents->x2;
+               }
+       } while (1);
+
+       assert_pixmap_damage(pixmap);
+       sna->blt_state.fill_bo = 0;
+       return true;
+}
+
+static void
+sna_image_glyph(DrawablePtr drawable, GCPtr gc,
+               int x, int y, unsigned int n,
+               CharInfoPtr *info, pointer base)
+{
+       PixmapPtr pixmap = get_drawable_pixmap(drawable);
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+       ExtentInfoRec extents;
+       RegionRec region;
+       struct sna_damage **damage;
+       struct kgem_bo *bo;
+
+       if (n == 0)
+               return;
+
+       sna_glyph_extents(gc->font, info, n, &extents);
+       region.extents.x1 = x + MIN(0, extents.overallLeft);
+       region.extents.y1 = y - extents.fontAscent;
+       region.extents.x2 = x + MAX(extents.overallWidth, extents.overallRight);
+       region.extents.y2 = y + extents.fontDescent;
+
+       DBG(("%s: count=%d, extents=(left=%d, right=%d, width=%d, ascent=%d, descent=%d), box=(%d, %d), (%d, %d)\n",
+            __FUNCTION__, n,
+            extents.overallLeft, extents.overallRight, extents.overallWidth,
+            extents.fontAscent, extents.fontDescent,
+            region.extents.x1, region.extents.y1,
+            region.extents.x2, region.extents.y2));
+
+       translate_box(&region.extents, drawable);
+       clip_box(&region.extents, gc);
+       if (box_empty(&region.extents))
+               return;
+
+       DBG(("%s: extents(%d, %d), (%d, %d)\n", __FUNCTION__,
+            region.extents.x1, region.extents.y1,
+            region.extents.x2, region.extents.y2));
+
+       region.data = NULL;
+       region_maybe_clip(&region, gc->pCompositeClip);
+       if (!RegionNotEmpty(&region))
+               return;
+
+       if (FORCE_FALLBACK)
+               goto fallback;
+
+       if (!ACCEL_IMAGE_GLYPH)
+               goto fallback;
+
+       if (wedged(sna)) {
+               DBG(("%s: fallback -- wedged\n", __FUNCTION__));
+               goto fallback;
+       }
+
+       if (!PM_IS_SOLID(drawable, gc->planemask))
+               goto fallback;
+
+       if (sna_font_too_large(gc->font))
+               goto fallback;
+
+       if ((bo = sna_drawable_use_bo(drawable, PREFER_GPU,
+                                     &region.extents, &damage)) &&
+           sna_reversed_glyph_blt(drawable, gc, x, y, n, info, base,
+                                  bo, damage, &region,
+                                  gc->fgPixel, gc->bgPixel, false))
+               goto out;
+
+fallback:
+       DBG(("%s: fallback\n", __FUNCTION__));
+       if (!sna_gc_move_to_cpu(gc, drawable, &region))
+               goto out;
+       if (!sna_drawable_move_region_to_cpu(drawable, &region,
+                                            MOVE_READ | MOVE_WRITE))
+               goto out_gc;
+
+       DBG(("%s: fallback -- fbImageGlyphBlt\n", __FUNCTION__));
+       fbImageGlyphBlt(drawable, gc, x, y, n, info, base);
+       FALLBACK_FLUSH(drawable);
+
+out_gc:
+       sna_gc_move_to_gpu(gc);
+out:
+       RegionUninit(&region);
+}
+
+static void
+sna_poly_glyph(DrawablePtr drawable, GCPtr gc,
+              int x, int y, unsigned int n,
+              CharInfoPtr *info, pointer base)
+{
+       PixmapPtr pixmap = get_drawable_pixmap(drawable);
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+       ExtentInfoRec extents;
+       RegionRec region;
+       struct sna_damage **damage;
+       struct kgem_bo *bo;
+       uint32_t fg;
+
+       if (n == 0)
+               return;
+
+       sna_glyph_extents(gc->font, info, n, &extents);
+       region.extents.x1 = x + extents.overallLeft;
+       region.extents.y1 = y - extents.overallAscent;
+       region.extents.x2 = x + extents.overallRight;
+       region.extents.y2 = y + extents.overallDescent;
+
+       translate_box(&region.extents, drawable);
+       clip_box(&region.extents, gc);
+       if (box_empty(&region.extents))
+               return;
+
+       DBG(("%s: extents(%d, %d), (%d, %d)\n", __FUNCTION__,
+            region.extents.x1, region.extents.y1,
+            region.extents.x2, region.extents.y2));
+
+       region.data = NULL;
+       region_maybe_clip(&region, gc->pCompositeClip);
+       if (!RegionNotEmpty(&region))
+               return;
+
+       if (FORCE_FALLBACK)
+               goto fallback;
+
+       if (!ACCEL_POLY_GLYPH)
+               goto fallback;
+
+       if (wedged(sna)) {
+               DBG(("%s: fallback -- wedged\n", __FUNCTION__));
+               goto fallback;
+       }
+
+       if (!PM_IS_SOLID(drawable, gc->planemask))
+               goto fallback;
+
+       if (!gc_is_solid(gc, &fg))
+               goto fallback;
+
+       if (sna_font_too_large(gc->font))
+               goto fallback;
+
+       if ((bo = sna_drawable_use_bo(drawable, PREFER_GPU,
+                                     &region.extents, &damage)) &&
+           sna_reversed_glyph_blt(drawable, gc, x, y, n, info, base,
+                                  bo, damage, &region, fg, -1, true))
+               goto out;
+
+fallback:
+       DBG(("%s: fallback\n", __FUNCTION__));
+       if (!sna_gc_move_to_cpu(gc, drawable, &region))
+               goto out;
+       if (!sna_drawable_move_region_to_cpu(drawable, &region,
+                                            MOVE_READ | MOVE_WRITE))
+               goto out_gc;
+
+       DBG(("%s: fallback -- fbPolyGlyphBlt\n", __FUNCTION__));
+       fbPolyGlyphBlt(drawable, gc, x, y, n, info, base);
+       FALLBACK_FLUSH(drawable);
+
+out_gc:
+       sna_gc_move_to_gpu(gc);
+out:
+       RegionUninit(&region);
+}
+
+static bool
+sna_push_pixels_solid_blt(GCPtr gc,
+                         PixmapPtr bitmap,
+                         DrawablePtr drawable,
+                         RegionPtr region)
+{
+       PixmapPtr pixmap = get_drawable_pixmap(drawable);
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+       struct sna_damage **damage;
+       struct kgem_bo *bo;
+       BoxRec *box;
+       int16_t dx, dy;
+       int n;
+       uint8_t rop = copy_ROP[gc->alu];
+
+       bo = sna_drawable_use_bo(drawable, PREFER_GPU, &region->extents, &damage);
+       if (bo == NULL)
+               return false;
+
+       if (bo->tiling == I915_TILING_Y) {
+               DBG(("%s: converting bo from Y-tiling\n", __FUNCTION__));
+               assert(bo == sna_pixmap_get_bo(pixmap));
+               bo = sna_pixmap_change_tiling(pixmap, I915_TILING_X);
+               if (bo == NULL) {
+                       DBG(("%s: fallback -- unable to change tiling\n",
+                            __FUNCTION__));
+                       return false;
+               }
+       }
+
+       get_drawable_deltas(drawable, pixmap, &dx, &dy);
+       RegionTranslate(region, dx, dy);
+
+       assert_pixmap_contains_box(pixmap, RegionExtents(region));
+       if (damage)
+               sna_damage_add(damage, region);
+       assert_pixmap_damage(pixmap);
+
+       DBG(("%s: upload(%d, %d, %d, %d)\n", __FUNCTION__,
+            region->extents.x1, region->extents.y1,
+            region->extents.x2, region->extents.y2));
+
+       kgem_set_mode(&sna->kgem, KGEM_BLT);
+
+       /* Region is pre-clipped and translated into pixmap space */
+       box = REGION_RECTS(region);
+       n = REGION_NUM_RECTS(region);
+       do {
+               int bx1 = (box->x1 - region->extents.x1) & ~7;
+               int bx2 = (box->x2 - region->extents.x1 + 7) & ~7;
+               int bw = (bx2 - bx1)/8;
+               int bh = box->y2 - box->y1;
+               int bstride = ALIGN(bw, 2);
+               int src_stride;
+               uint8_t *dst, *src;
+               uint32_t *b;
+               struct kgem_bo *upload;
+               void *ptr;
+
+               if (!kgem_check_batch(&sna->kgem, 8) ||
+                   !kgem_check_bo_fenced(&sna->kgem, bo) ||
+                   !kgem_check_reloc_and_exec(&sna->kgem, 2)) {
+                       _kgem_submit(&sna->kgem);
+                       _kgem_set_mode(&sna->kgem, KGEM_BLT);
+               }
+
+               upload = kgem_create_buffer(&sna->kgem,
+                                           bstride*bh,
+                                           KGEM_BUFFER_WRITE_INPLACE,
+                                           &ptr);
+               if (!upload)
+                       break;
+
+               dst = ptr;
+
+               src_stride = bitmap->devKind;
+               src = (uint8_t*)bitmap->devPrivate.ptr;
+               src += (box->y1 - region->extents.y1) * src_stride + bx1/8;
+               src_stride -= bstride;
+               do {
+                       int i = bstride;
+                       do {
+                               *dst++ = byte_reverse(*src++);
+                               *dst++ = byte_reverse(*src++);
+                               i -= 2;
+                       } while (i);
+                       src += src_stride;
+               } while (--bh);
+
+               b = sna->kgem.batch + sna->kgem.nbatch;
+               b[0] = XY_MONO_SRC_COPY | 3 << 20;
+               b[0] |= ((box->x1 - region->extents.x1) & 7) << 17;
+               b[1] = bo->pitch;
+               if (sna->kgem.gen >= 40 && bo->tiling) {
+                       b[0] |= BLT_DST_TILED;
+                       b[1] >>= 2;
+               }
+               b[1] |= 1 << 29;
+               b[1] |= blt_depth(drawable->depth) << 24;
+               b[1] |= rop << 16;
+               b[2] = box->y1 << 16 | box->x1;
+               b[3] = box->y2 << 16 | box->x2;
+               b[4] = kgem_add_reloc(&sna->kgem, sna->kgem.nbatch + 4, bo,
+                                     I915_GEM_DOMAIN_RENDER << 16 |
+                                     I915_GEM_DOMAIN_RENDER |
+                                     KGEM_RELOC_FENCED,
+                                     0);
+               b[5] = kgem_add_reloc(&sna->kgem, sna->kgem.nbatch + 5,
+                                     upload,
+                                     I915_GEM_DOMAIN_RENDER << 16 |
+                                     KGEM_RELOC_FENCED,
+                                     0);
+               b[6] = gc->bgPixel;
+               b[7] = gc->fgPixel;
+
+               sna->kgem.nbatch += 8;
+               kgem_bo_destroy(&sna->kgem, upload);
+
+               box++;
+       } while (--n);
+
+       sna->blt_state.fill_bo = 0;
+       return true;
+}
+
+static void
+sna_push_pixels(GCPtr gc, PixmapPtr bitmap, DrawablePtr drawable,
+               int w, int h,
+               int x, int y)
+{
+       RegionRec region;
+
+       if (w == 0 || h == 0)
+               return;
+
+       DBG(("%s (%d, %d)x(%d, %d)\n", __FUNCTION__, x, y, w, h));
+
+       region.extents.x1 = x;
+       region.extents.y1 = y;
+       region.extents.x2 = region.extents.x1 + w;
+       region.extents.y2 = region.extents.y1 + h;
+
+       clip_box(&region.extents, gc);
+       if (box_empty(&region.extents))
+               return;
+
+       DBG(("%s: extents(%d, %d), (%d, %d)\n", __FUNCTION__,
+            region.extents.x1, region.extents.y1,
+            region.extents.x2, region.extents.y2));
+
+       region.data = NULL;
+       region_maybe_clip(&region, gc->pCompositeClip);
+       if (!RegionNotEmpty(&region))
+               return;
+
+       switch (gc->fillStyle) {
+       case FillSolid:
+               if (sna_push_pixels_solid_blt(gc, bitmap, drawable, &region))
+                       return;
+               break;
+       default:
+               break;
+       }
+
+       DBG(("%s: fallback\n", __FUNCTION__));
+       if (!sna_gc_move_to_cpu(gc, drawable, &region))
+               goto out;
+       if (!sna_pixmap_move_to_cpu(bitmap, MOVE_READ))
+               goto out_gc;
+       if (!sna_drawable_move_region_to_cpu(drawable, &region,
+                                            drawable_gc_flags(drawable, gc, false)))
+               goto out_gc;
+
+       DBG(("%s: fallback, fbPushPixels(%d, %d, %d %d)\n",
+            __FUNCTION__, w, h, x, y));
+       fbPushPixels(gc, bitmap, drawable, w, h, x, y);
+       FALLBACK_FLUSH(drawable);
+out_gc:
+       sna_gc_move_to_gpu(gc);
+out:
+       RegionUninit(&region);
+}
+
+static const GCOps sna_gc_ops = {
+       sna_fill_spans,
+       sna_set_spans,
+       sna_put_image,
+       sna_copy_area,
+       sna_copy_plane,
+       sna_poly_point,
+       sna_poly_line,
+       sna_poly_segment,
+       sna_poly_rectangle,
+       sna_poly_arc,
+       sna_poly_fill_polygon,
+       sna_poly_fill_rect,
+       sna_poly_fill_arc,
+       sna_poly_text8,
+       sna_poly_text16,
+       sna_image_text8,
+       sna_image_text16,
+       sna_image_glyph,
+       sna_poly_glyph,
+       sna_push_pixels,
+};
+
+static const GCOps sna_gc_ops__cpu = {
+       fbFillSpans,
+       fbSetSpans,
+       fbPutImage,
+       fbCopyArea,
+       fbCopyPlane,
+       sna_poly_point__cpu,
+       fbPolyLine,
+       fbPolySegment,
+       miPolyRectangle,
+       fbPolyArc,
+       miFillPolygon,
+       fbPolyFillRect,
+       miPolyFillArc,
+       miPolyText8,
+       miPolyText16,
+       miImageText8,
+       miImageText16,
+       fbImageGlyphBlt,
+       fbPolyGlyphBlt,
+       fbPushPixels
+};
+
+static GCOps sna_gc_ops__tmp = {
+       sna_fill_spans,
+       sna_set_spans,
+       sna_put_image,
+       sna_copy_area,
+       sna_copy_plane,
+       sna_poly_point,
+       sna_poly_line,
+       sna_poly_segment,
+       sna_poly_rectangle,
+       sna_poly_arc,
+       sna_poly_fill_polygon,
+       sna_poly_fill_rect,
+       sna_poly_fill_arc,
+       sna_poly_text8,
+       sna_poly_text16,
+       sna_image_text8,
+       sna_image_text16,
+       sna_image_glyph,
+       sna_poly_glyph,
+       sna_push_pixels,
+};
+
+static void
+sna_validate_gc(GCPtr gc, unsigned long changes, DrawablePtr drawable)
+{
+       DBG(("%s changes=%lx\n", __FUNCTION__, changes));
+
+       if (changes & (GCClipMask|GCSubwindowMode) ||
+           drawable->serialNumber != (gc->serialNumber & DRAWABLE_SERIAL_BITS) ||
+           (gc->clientClipType != CT_NONE && (changes & (GCClipXOrigin | GCClipYOrigin))))
+               miComputeCompositeClip(gc, drawable);
+
+       sna_gc(gc)->changes |= changes;
+}
+
+static const GCFuncs sna_gc_funcs = {
+       sna_validate_gc,
+       miChangeGC,
+       miCopyGC,
+       miDestroyGC,
+       miChangeClip,
+       miDestroyClip,
+       miCopyClip
+};
+
+static const GCFuncs sna_gc_funcs__cpu = {
+       fbValidateGC,
+       miChangeGC,
+       miCopyGC,
+       miDestroyGC,
+       miChangeClip,
+       miDestroyClip,
+       miCopyClip
+};
+
+static int sna_create_gc(GCPtr gc)
+{
+       gc->miTranslate = 1;
+       gc->fExpose = 1;
+
+       fb_gc(gc)->bpp = bits_per_pixel(gc->depth);
+
+       gc->funcs = (GCFuncs *)&sna_gc_funcs;
+       gc->ops = (GCOps *)&sna_gc_ops;
+       return true;
+}
+
+static void
+sna_get_image(DrawablePtr drawable,
+             int x, int y, int w, int h,
+             unsigned int format, unsigned long mask,
+             char *dst)
+{
+       RegionRec region;
+       unsigned int flags;
+
+       if (!fbDrawableEnabled(drawable))
+               return;
+
+       DBG(("%s (%d, %d)x(%d, %d)\n", __FUNCTION__, x, y, w, h));
+
+       region.extents.x1 = x + drawable->x;
+       region.extents.y1 = y + drawable->y;
+       region.extents.x2 = region.extents.x1 + w;
+       region.extents.y2 = region.extents.y1 + h;
+       region.data = NULL;
+
+       flags = MOVE_READ;
+       if ((w | h) == 1)
+               flags |= MOVE_INPLACE_HINT;
+       if (w == drawable->width)
+               flags |= MOVE_WHOLE_HINT;
+       if (!sna_drawable_move_region_to_cpu(drawable, &region, flags))
+               return;
+
+       if (format == ZPixmap &&
+           drawable->bitsPerPixel >= 8 &&
+           PM_IS_SOLID(drawable, mask)) {
+               PixmapPtr pixmap = get_drawable_pixmap(drawable);
+               int16_t dx, dy;
+
+               DBG(("%s: copy box (%d, %d), (%d, %d)\n",
+                    __FUNCTION__,
+                    region.extents.x1, region.extents.y1,
+                    region.extents.x2, region.extents.y2));
+               get_drawable_deltas(drawable, pixmap, &dx, &dy);
+               memcpy_blt(pixmap->devPrivate.ptr, dst, drawable->bitsPerPixel,
+                          pixmap->devKind, PixmapBytePad(w, drawable->depth),
+                          region.extents.x1 + dx,
+                          region.extents.y1 + dy,
+                          0, 0, w, h);
+       } else
+               fbGetImage(drawable, x, y, w, h, format, mask, dst);
+}
+
+static void
+sna_get_spans(DrawablePtr drawable, int wMax,
+             DDXPointPtr pt, int *width, int n, char *start)
+{
+       RegionRec region;
+
+       if (!fbDrawableEnabled(drawable))
+               return;
+
+       if (sna_spans_extents(drawable, NULL, n, pt, width, &region.extents) == 0)
+               return;
+
+       region.data = NULL;
+       if (!sna_drawable_move_region_to_cpu(drawable, &region, MOVE_READ))
+               return;
+
+       fbGetSpans(drawable, wMax, pt, width, n, start);
+}
+
+static void
+sna_copy_window(WindowPtr win, DDXPointRec origin, RegionPtr src)
+{
+       PixmapPtr pixmap = get_window_pixmap(win);
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+       RegionRec dst;
+       int dx, dy;
+
+       DBG(("%s origin=(%d, %d)\n", __FUNCTION__, origin.x, origin.y));
+       if (!fbWindowEnabled(win))
+               return;
+
+       dx = origin.x - win->drawable.x;
+       dy = origin.y - win->drawable.y;
+       RegionTranslate(src, -dx, -dy);
+
+       RegionNull(&dst);
+       RegionIntersect(&dst, &win->borderClip, src);
+       if (!RegionNotEmpty(&dst))
+               return;
+
+#ifdef COMPOSITE
+       if (pixmap->screen_x | pixmap->screen_y)
+               RegionTranslate(&dst, -pixmap->screen_x, -pixmap->screen_y);
+#endif
+
+       if (wedged(sna) || FORCE_FALLBACK || !ACCEL_COPY_WINDOW) {
+               DBG(("%s: fallback -- wedged\n", __FUNCTION__));
+               if (!sna_pixmap_move_to_cpu(pixmap, MOVE_READ | MOVE_WRITE))
+                       return;
+
+               miCopyRegion(&pixmap->drawable, &pixmap->drawable,
+                            0, &dst, dx, dy, fbCopyNtoN, 0, NULL);
+       } else {
+               sna_self_copy_boxes(&pixmap->drawable, &pixmap->drawable, NULL,
+                                   &dst, dx, dy, 0, NULL);
+       }
+
+       RegionUninit(&dst);
+}
+
+static Bool sna_change_window_attributes(WindowPtr win, unsigned long mask)
+{
+       bool ret = true;
+
+       DBG(("%s\n", __FUNCTION__));
+
+       /* Check if the fb layer wishes to modify the attached pixmaps,
+        * to fix up mismatches between the window and pixmap depths.
+        */
+       if (mask & CWBackPixmap && win->backgroundState == BackgroundPixmap) {
+               DBG(("%s: flushing background pixmap\n", __FUNCTION__));
+               ret &= sna_validate_pixmap(&win->drawable, win->background.pixmap);
+       }
+
+       if (mask & CWBorderPixmap && win->borderIsPixel == false) {
+               DBG(("%s: flushing border pixmap\n", __FUNCTION__));
+               ret &= sna_validate_pixmap(&win->drawable, win->border.pixmap);
+       }
+
+       return ret;
+}
+
+static void
+sna_accel_flush_callback(CallbackListPtr *list,
+                        pointer user_data, pointer call_data)
+{
+       struct sna *sna = user_data;
+       struct sna_pixmap *priv;
+
+       /* XXX we should be able to reduce the frequency of flushes further
+        * by checking for outgoing damage events or sync replies. Tricky,
+        * and doesn't appear to mitigate the performance loss.
+        */
+       DBG(("%s: flush?=%d, dirty?=%d\n", __FUNCTION__,
+            sna->kgem.flush, !list_is_empty(&sna->flush_pixmaps)));
+
+       /* flush any pending damage from shadow copies to tfp clients */
+       while (!list_is_empty(&sna->flush_pixmaps)) {
+               bool ret;
+
+               priv = list_first_entry(&sna->flush_pixmaps,
+                                       struct sna_pixmap, list);
+
+               list_del(&priv->list);
+               if (priv->shm) {
+                       DBG(("%s: syncing SHM pixmap=%ld\n", __FUNCTION__,
+                            priv->pixmap->drawable.serialNumber));
+                       ret = sna_pixmap_move_to_cpu(priv->pixmap,
+                                                    MOVE_READ | MOVE_WRITE);
+                       assert(!ret || priv->gpu_bo == NULL);
+                       if (priv->pixmap->refcnt == 0)
+                               __sna_free_pixmap(sna, priv->pixmap, priv);
+               } else {
+                       DBG(("%s: flushing DRI pixmap=%ld\n", __FUNCTION__,
+                            priv->pixmap->drawable.serialNumber));
+                       ret = sna_pixmap_move_to_gpu(priv->pixmap,
+                                                    MOVE_READ | __MOVE_FORCE);
+               }
+               (void)ret;
+       }
+
+       if (sna->kgem.flush)
+               kgem_submit(&sna->kgem);
+}
+
+static struct sna_pixmap *sna_accel_scanout(struct sna *sna)
+{
+       struct sna_pixmap *priv;
+
+       if (sna->vblank_interval == 0)
+               return NULL;
+
+       if (sna->front == NULL)
+               return NULL;
+
+       priv = sna_pixmap(sna->front);
+       return priv && priv->gpu_bo ? priv : NULL;
+}
+
+#define TIME currentTime.milliseconds
+static void sna_accel_disarm_timer(struct sna *sna, int id)
+{
+       DBG(("%s[%d] (time=%ld)\n", __FUNCTION__, id, (long)TIME));
+       sna->timer_active &= ~(1<<id);
+}
+
+static bool has_offload_slaves(struct sna *sna)
+{
+#if HAS_PIXMAP_SHARING
+       ScreenPtr screen = sna->scrn->pScreen;
+       PixmapDirtyUpdatePtr dirty;
+
+       xorg_list_for_each_entry(dirty, &screen->pixmap_dirty_list, ent) {
+               if (RegionNotEmpty(DamageRegion(dirty->damage)))
+                       return true;
+       }
+#endif
+       return false;
+}
+
+static bool has_shadow(struct sna *sna)
+{
+       DamagePtr damage = sna->mode.shadow_damage;
+
+       if (!(damage && RegionNotEmpty(DamageRegion(damage))))
+               return false;
+
+       DBG(("%s: has pending damage\n", __FUNCTION__));
+       if ((sna->flags & SNA_TEAR_FREE) == 0)
+               return true;
+
+       DBG(("%s: outstanding flips: %d\n",
+            __FUNCTION__, sna->mode.shadow_flip));
+       return !sna->mode.shadow_flip;
+}
+
+static bool start_flush(struct sna *sna, struct sna_pixmap *scanout)
+{
+       DBG(("%s: scanout=%d shadow?=%d, slaves?=%d, (cpu?=%d || gpu?=%d))\n",
+            __FUNCTION__,
+            scanout && scanout->gpu_bo ? scanout->gpu_bo->handle : 0,
+            has_shadow(sna), has_offload_slaves(sna),
+            scanout && scanout->cpu_damage != NULL,
+            scanout && scanout->gpu_bo && scanout->gpu_bo->exec != NULL));
+
+       if (has_offload_slaves(sna))
+               return true;
+
+       if (has_shadow(sna))
+               return true;
+
+       if (!scanout)
+               return false;
+
+       return scanout->cpu_damage || scanout->gpu_bo->exec;
+}
+
+static bool stop_flush(struct sna *sna, struct sna_pixmap *scanout)
+{
+       DBG(("%s: scanout=%d shadow?=%d, slaves?=%d, (cpu?=%d || gpu?=%d))\n",
+            __FUNCTION__,
+            scanout && scanout->gpu_bo ? scanout->gpu_bo->handle : 0,
+            has_shadow(sna), has_offload_slaves(sna),
+            scanout && scanout->cpu_damage != NULL,
+            scanout && scanout->gpu_bo && scanout->gpu_bo->rq != NULL));
+
+       if (has_offload_slaves(sna))
+               return true;
+
+       if (has_shadow(sna))
+               return true;
+
+       if (!scanout)
+               return false;
+
+       return scanout->cpu_damage || scanout->gpu_bo->needs_flush;
+}
+
+static bool sna_accel_do_flush(struct sna *sna)
+{
+       struct sna_pixmap *priv;
+       int interval;
+
+       priv = sna_accel_scanout(sna);
+       if (priv == NULL && !sna->mode.shadow_active && !has_offload_slaves(sna)) {
+               DBG(("%s -- no scanout attached\n", __FUNCTION__));
+               sna_accel_disarm_timer(sna, FLUSH_TIMER);
+               return false;
+       }
+
+       if (sna->flags & SNA_NO_DELAYED_FLUSH)
+               return true;
+
+       interval = sna->vblank_interval ?: 20;
+       if (sna->timer_active & (1<<(FLUSH_TIMER))) {
+               int32_t delta = sna->timer_expire[FLUSH_TIMER] - TIME;
+               DBG(("%s: flush timer active: delta=%d\n",
+                    __FUNCTION__, delta));
+               if (delta <= 3) {
+                       DBG(("%s (time=%ld), triggered\n", __FUNCTION__, (long)TIME));
+                       sna->timer_expire[FLUSH_TIMER] = TIME + interval;
+                       return true;
+               }
+       } else {
+               if (!start_flush(sna, priv)) {
+                       DBG(("%s -- no pending write to scanout\n", __FUNCTION__));
+                       if (priv)
+                               kgem_bo_flush(&sna->kgem, priv->gpu_bo);
+               } else {
+                       sna->timer_active |= 1 << FLUSH_TIMER;
+                       sna->timer_expire[FLUSH_TIMER] = TIME + interval / 2;
+                       DBG(("%s (time=%ld), starting\n", __FUNCTION__, (long)TIME));
+               }
+       }
+
+       return false;
+}
+
+static bool sna_accel_do_throttle(struct sna *sna)
+{
+       if (sna->flags & SNA_NO_THROTTLE)
+               return false;
+
+       if (sna->timer_active & (1<<(THROTTLE_TIMER))) {
+               int32_t delta = sna->timer_expire[THROTTLE_TIMER] - TIME;
+               if (delta <= 3) {
+                       DBG(("%s (time=%ld), triggered\n", __FUNCTION__, (long)TIME));
+                       sna->timer_expire[THROTTLE_TIMER] = TIME + 20;
+                       return true;
+               }
+       } else {
+               if (!sna->kgem.need_retire) {
+                       DBG(("%s -- no pending activity\n", __FUNCTION__));
+               } else {
+                       DBG(("%s (time=%ld), starting\n", __FUNCTION__, (long)TIME));
+                       sna->timer_active |= 1 << THROTTLE_TIMER;
+                       sna->timer_expire[THROTTLE_TIMER] = TIME + 20;
+               }
+       }
+
+       return false;
+}
+
+static bool sna_accel_do_expire(struct sna *sna)
+{
+       if (sna->timer_active & (1<<(EXPIRE_TIMER))) {
+               int32_t delta = sna->timer_expire[EXPIRE_TIMER] - TIME;
+               if (delta <= 3) {
+                       DBG(("%s (time=%ld), triggered\n", __FUNCTION__, (long)TIME));
+                       sna->timer_expire[EXPIRE_TIMER] =
+                               TIME + MAX_INACTIVE_TIME * 1000;
+                       return true;
+               }
+       } else {
+               if (sna->kgem.need_expire) {
+                       sna->timer_active |= 1 << EXPIRE_TIMER;
+                       sna->timer_expire[EXPIRE_TIMER] =
+                               TIME + MAX_INACTIVE_TIME * 1000;
+                       DBG(("%s (time=%ld), starting\n", __FUNCTION__, (long)TIME));
+               }
+       }
+
+       return false;
+}
+
+static bool sna_accel_do_inactive(struct sna *sna)
+{
+       if (!USE_INACTIVE)
+               return false;
+
+       if (sna->timer_active & (1<<(INACTIVE_TIMER))) {
+               int32_t delta = sna->timer_expire[INACTIVE_TIMER] - TIME;
+               if (delta <= 3) {
+                       sna->timer_expire[INACTIVE_TIMER] =
+                               TIME + 120 * 1000;
+                       DBG(("%s (time=%ld), triggered\n", __FUNCTION__, (long)TIME));
+                       return true;
+               }
+       } else {
+               if (!list_is_empty(&sna->active_pixmaps)) {
+                       sna->timer_active |= 1 << INACTIVE_TIMER;
+                       sna->timer_expire[INACTIVE_TIMER] =
+                               TIME + 120 * 1000;
+                       DBG(("%s (time=%ld), starting\n", __FUNCTION__, (long)TIME));
+               }
+       }
+
+       return false;
+}
+
+static int32_t sna_timeout(struct sna *sna)
+{
+       int32_t now = TIME, next = 0;
+       int i;
+
+       DBG(("%s: now=%d, active=%08x\n",
+            __FUNCTION__, (int)now, sna->timer_active));
+       for (i = 0; i < NUM_TIMERS; i++) {
+               if (sna->timer_active & (1 << i)) {
+                       int32_t delta = sna->timer_expire[i] - now;
+                       DBG(("%s: timer[%d] expires in %d [%d]\n",
+                            __FUNCTION__, i, delta, sna->timer_expire[i]));
+                       if (next == 0 || delta < next)
+                               next = delta;
+               }
+       }
+
+       DBG(("%s: active=%08x, next=+%d\n",
+            __FUNCTION__, sna->timer_active, next));
+       return next;
+}
+
+static void sna_accel_post_damage(struct sna *sna)
+{
+#if HAS_PIXMAP_SHARING
+       ScreenPtr screen = sna->scrn->pScreen;
+       PixmapDirtyUpdatePtr dirty;
+       bool flush = false;
+
+       xorg_list_for_each_entry(dirty, &screen->pixmap_dirty_list, ent) {
+               RegionRec region, *damage;
+               PixmapPtr src, dst;
+               BoxPtr box;
+               int n;
+
+               damage = DamageRegion(dirty->damage);
+               if (!RegionNotEmpty(damage))
+                       continue;
+
+               src = dirty->src;
+               dst = dirty->slave_dst->master_pixmap;
+
+               region.extents.x1 = dirty->x;
+               region.extents.x2 = dirty->x + dst->drawable.width;
+               region.extents.y1 = dirty->y;
+               region.extents.y2 = dirty->y + dst->drawable.height;
+               region.data = NULL;
+
+               DBG(("%s: pushing damage ((%d, %d), (%d, %d))x%d to slave pixmap=%ld, ((%d, %d), (%d, %d))\n", __FUNCTION__,
+                    damage->extents.x1, damage->extents.y1,
+                    damage->extents.x2, damage->extents.y2,
+                    RegionNumRects(damage),
+                    dst->drawable.serialNumber,
+                    region.extents.x1, region.extents.y1,
+                    region.extents.x2, region.extents.y2));
+
+               RegionIntersect(&region, &region, damage);
+
+               box = REGION_RECTS(&region);
+               n = REGION_NUM_RECTS(&region);
+               if (wedged(sna)) {
+fallback:
+                       if (!sna_pixmap_move_to_cpu(src, MOVE_READ))
+                               goto skip;
+
+                       if (!sna_pixmap_move_to_cpu(dst, MOVE_READ | MOVE_WRITE | MOVE_INPLACE_HINT))
+                               goto skip;
+
+                       assert(src->drawable.bitsPerPixel == dst->drawable.bitsPerPixel);
+                       do {
+                               DBG(("%s: copy box (%d, %d)->(%d, %d)x(%d, %d)\n",
+                                    __FUNCTION__,
+                                    box->x1, box->y1,
+                                    box->x1 - dirty->x, box->y1 - dirty->y,
+                                    box->x2 - box->x1, box->y2 - box->y1));
+
+                               assert(box->x2 > box->x1);
+                               assert(box->y2 > box->y1);
+
+                               assert(box->x1 >= 0);
+                               assert(box->y1 >= 0);
+                               assert(box->x2 <= src->drawable.width);
+                               assert(box->y2 <= src->drawable.height);
+
+                               assert(box->x1 - dirty->x >= 0);
+                               assert(box->y1 - dirty->y >= 0);
+                               assert(box->x2 - dirty->x <= src->drawable.width);
+                               assert(box->y2 - dirty->y <= src->drawable.height);
+
+                               memcpy_blt(src->devPrivate.ptr,
+                                          dst->devPrivate.ptr,
+                                          src->drawable.bitsPerPixel,
+                                          src->devKind, dst->devKind,
+                                          box->x1, box->y1,
+                                          box->x1 - dirty->x,
+                                          box->y1 - dirty->y,
+                                          box->x2 - box->x1,
+                                          box->y2 - box->y1);
+                               box++;
+                       } while (--n);
+               } else {
+                       if (!sna_pixmap_move_to_gpu(src, MOVE_READ | __MOVE_FORCE))
+                               goto fallback;
+
+                       if (!sna_pixmap_move_to_gpu(dst, MOVE_READ | MOVE_WRITE | __MOVE_FORCE))
+                               goto fallback;
+
+                       if (!sna->render.copy_boxes(sna, GXcopy,
+                                                   src, sna_pixmap_get_bo(src), 0, 0,
+                                                   dst, sna_pixmap_get_bo(dst), -dirty->x, -dirty->y,
+                                                   box, n, COPY_LAST))
+                               goto fallback;
+
+                       flush = true;
+               }
+
+               RegionTranslate(&region, -dirty->x, -dirty->y);
+               DamageRegionAppend(&dirty->slave_dst->drawable, &region);
+
+skip:
+               RegionUninit(&region);
+               DamageEmpty(dirty->damage);
+       }
+       if (flush)
+               kgem_submit(&sna->kgem);
+#endif
+}
+
+static void sna_accel_flush(struct sna *sna)
+{
+       struct sna_pixmap *priv = sna_accel_scanout(sna);
+       bool busy;
+
+       DBG(("%s (time=%ld), cpu damage? %d, exec? %d nbatch=%d, busy? %d\n",
+            __FUNCTION__, (long)TIME,
+            priv && priv->cpu_damage,
+            priv && priv->gpu_bo->exec != NULL,
+            sna->kgem.nbatch,
+            sna->kgem.busy));
+
+       busy = stop_flush(sna, priv);
+       if (!sna->kgem.busy && !busy)
+               sna_accel_disarm_timer(sna, FLUSH_TIMER);
+       sna->kgem.busy = busy;
+
+       if (priv) {
+               sna_pixmap_force_to_gpu(priv->pixmap, MOVE_READ);
+               kgem_bo_flush(&sna->kgem, priv->gpu_bo);
+               assert(!priv->cpu);
+       }
+
+       sna_mode_redisplay(sna);
+       sna_accel_post_damage(sna);
+}
+
+static void sna_accel_throttle(struct sna *sna)
+{
+       DBG(("%s (time=%ld)\n", __FUNCTION__, (long)TIME));
+
+       if (sna->kgem.need_throttle) {
+               kgem_submit(&sna->kgem);
+               kgem_throttle(&sna->kgem);
+       }
+
+       if (!sna->kgem.need_retire)
+               sna_accel_disarm_timer(sna, THROTTLE_TIMER);
+}
+
+static void sna_accel_expire(struct sna *sna)
+{
+       DBG(("%s (time=%ld)\n", __FUNCTION__, (long)TIME));
+
+       if (!kgem_expire_cache(&sna->kgem))
+               sna_accel_disarm_timer(sna, EXPIRE_TIMER);
+}
+
+static void sna_accel_inactive(struct sna *sna)
+{
+       struct sna_pixmap *priv;
+       struct list preserve;
+
+       DBG(("%s (time=%ld)\n", __FUNCTION__, (long)TIME));
+
+#if HAS_FULL_DEBUG
+       {
+               unsigned count, bytes;
+
+               count = bytes = 0;
+               list_for_each_entry(priv, &sna->inactive_clock[1], inactive)
+                       if (!priv->pinned)
+                               count++, bytes += kgem_bo_size(priv->gpu_bo);
+
+               DBG(("%s: trimming %d inactive GPU buffers, %d bytes\n",
+                   __FUNCTION__, count, bytes));
+
+               count = bytes = 0;
+               list_for_each_entry(priv, &sna->active_pixmaps, inactive) {
+                       if (priv->ptr &&
+                           sna_damage_is_all(&priv->gpu_damage,
+                                             priv->pixmap->drawable.width,
+                                             priv->pixmap->drawable.height)) {
+                               count++, bytes += priv->pixmap->devKind * priv->pixmap->drawable.height;
+                       }
+               }
+
+               DBG(("%s: trimming %d inactive CPU buffers, %d bytes\n",
+                   __FUNCTION__, count, bytes));
+       }
+#endif
+
+       /* clear out the oldest inactive pixmaps */
+       list_init(&preserve);
+       while (!list_is_empty(&sna->inactive_clock[1])) {
+               priv = list_first_entry(&sna->inactive_clock[1],
+                                       struct sna_pixmap,
+                                       inactive);
+               assert((priv->create & KGEM_CAN_CREATE_LARGE) == 0);
+               assert(priv->gpu_bo);
+               assert(!priv->gpu_bo->proxy);
+
+               /* XXX Rather than discarding the GPU buffer here, we
+                * could mark it purgeable and allow the shrinker to
+                * reap its storage only under memory pressure.
+                */
+               list_del(&priv->inactive);
+               if (priv->pinned)
+                       continue;
+
+               if (priv->ptr &&
+                   sna_damage_is_all(&priv->gpu_damage,
+                                     priv->pixmap->drawable.width,
+                                     priv->pixmap->drawable.height)) {
+                       DBG(("%s: discarding inactive CPU shadow\n",
+                            __FUNCTION__));
+                       sna_damage_destroy(&priv->cpu_damage);
+                       list_del(&priv->list);
+
+                       assert(priv->cpu_bo == NULL || !priv->cpu_bo->flush);
+                       assert(!priv->shm);
+                       sna_pixmap_free_cpu(sna, priv);
+                       priv->undamaged = false;
+                       priv->cpu = false;
+
+                       list_add(&priv->inactive, &preserve);
+               } else {
+                       DBG(("%s: discarding inactive GPU bo handle=%d\n",
+                            __FUNCTION__, priv->gpu_bo->handle));
+                       if (!sna_pixmap_move_to_cpu(priv->pixmap,
+                                                   MOVE_READ | MOVE_WRITE | MOVE_ASYNC_HINT))
+                               list_add(&priv->inactive, &preserve);
+               }
+       }
+
+       /* Age the current inactive pixmaps */
+       sna->inactive_clock[1].next = sna->inactive_clock[0].next;
+       sna->inactive_clock[0].next->prev = &sna->inactive_clock[1];
+       sna->inactive_clock[0].prev->next = &sna->inactive_clock[1];
+       sna->inactive_clock[1].prev = sna->inactive_clock[0].prev;
+
+       sna->inactive_clock[0].next = sna->active_pixmaps.next;
+       sna->active_pixmaps.next->prev = &sna->inactive_clock[0];
+       sna->active_pixmaps.prev->next = &sna->inactive_clock[0];
+       sna->inactive_clock[0].prev = sna->active_pixmaps.prev;
+
+       sna->active_pixmaps.next = preserve.next;
+       preserve.next->prev = &sna->active_pixmaps;
+       preserve.prev->next = &sna->active_pixmaps;
+       sna->active_pixmaps.prev = preserve.prev;
+
+       if (list_is_empty(&sna->inactive_clock[1]) &&
+           list_is_empty(&sna->inactive_clock[0]) &&
+           list_is_empty(&sna->active_pixmaps))
+               sna_accel_disarm_timer(sna, INACTIVE_TIMER);
+}
+
+#ifdef DEBUG_MEMORY
+static bool sna_accel_do_debug_memory(struct sna *sna)
+{
+       int32_t delta = sna->timer_expire[DEBUG_MEMORY_TIMER] - TIME;
+
+       if (delta <= 3) {
+               sna->timer_expire[DEBUG_MEMORY_TIMER] = TIME + 10 * 1000;
+               return true;
+       } else
+               return false;
+}
+
+static void sna_accel_debug_memory(struct sna *sna)
+{
+       ErrorF("Allocated bo: %d, %ld bytes\n",
+              sna->kgem.debug_memory.bo_allocs,
+              (long)sna->kgem.debug_memory.bo_bytes);
+       ErrorF("Allocated CPU bo: %d, %ld bytes\n",
+              sna->debug_memory.cpu_bo_allocs,
+              (long)sna->debug_memory.cpu_bo_bytes);
+}
+
+#else
+#define sna_accel_do_debug_memory(x) 0
+static void sna_accel_debug_memory(struct sna *sna) { }
+#endif
+
+static ShmFuncs shm_funcs = { sna_pixmap_create_shm, NULL };
+
+static PixmapPtr
+sna_get_window_pixmap(WindowPtr window)
+{
+       return get_window_pixmap(window);
+}
+
+static void
+sna_set_window_pixmap(WindowPtr window, PixmapPtr pixmap)
+{
+       *(PixmapPtr *)dixGetPrivateAddr(&window->devPrivates, &sna_window_key) = pixmap;
+}
+
+static Bool
+sna_create_window(WindowPtr win)
+{
+       sna_set_window_pixmap(win, win->drawable.pScreen->devPrivate);
+       return TRUE;
+}
+
+static Bool
+sna_map_window(WindowPtr win)
+{
+       return TRUE;
+}
+
+static Bool
+sna_position_window(WindowPtr win, int x, int y)
+{
+       return TRUE;
+}
+
+static Bool
+sna_unmap_window(WindowPtr win)
+{
+       return TRUE;
+}
+
+static Bool
+sna_destroy_window(WindowPtr win)
+{
+       sna_dri_destroy_window(win);
+       return TRUE;
+}
+
+static void
+sna_query_best_size(int class,
+                   unsigned short *width, unsigned short *height,
+                   ScreenPtr screen)
+{
+       unsigned short w;
+
+       switch (class) {
+       case CursorShape:
+               if (*width > screen->width)
+                       *width = screen->width;
+               if (*height > screen->height)
+                       *height = screen->height;
+               break;
+
+       case TileShape:
+       case StippleShape:
+               w = *width;
+               if ((w & (w - 1)) && w < FB_UNIT) {
+                       for (w = 1; w < *width; w <<= 1)
+                               ;
+                       *width = w;
+               }
+               break;
+       }
+}
+
+static void sna_store_colors(ColormapPtr cmap, int n, xColorItem *def)
+{
+}
+
+static bool sna_picture_init(ScreenPtr screen)
+{
+       PictureScreenPtr ps;
+
+       if (!miPictureInit(screen, NULL, 0))
+               return false;
+
+       ps = GetPictureScreen(screen);
+       assert(ps != NULL);
+
+       ps->Composite = sna_composite;
+       ps->CompositeRects = sna_composite_rectangles;
+       ps->Glyphs = sna_glyphs;
+       if (xf86IsEntityShared(xf86ScreenToScrn(screen)->entityList[0]))
+               ps->Glyphs = sna_glyphs__shared;
+       ps->UnrealizeGlyph = sna_glyph_unrealize;
+       ps->AddTraps = sna_add_traps;
+       ps->Trapezoids = sna_composite_trapezoids;
+       ps->Triangles = sna_composite_triangles;
+#if PICTURE_SCREEN_VERSION >= 2
+       ps->TriStrip = sna_composite_tristrip;
+       ps->TriFan = sna_composite_trifan;
+#endif
+
+       return true;
+}
+
+bool sna_accel_init(ScreenPtr screen, struct sna *sna)
+{
+       const char *backend;
+
+       sna_font_key = AllocateFontPrivateIndex();
+
+       list_init(&sna->flush_pixmaps);
+       list_init(&sna->active_pixmaps);
+       list_init(&sna->inactive_clock[0]);
+       list_init(&sna->inactive_clock[1]);
+
+       AddGeneralSocket(sna->kgem.fd);
+
+#ifdef DEBUG_MEMORY
+       sna->timer_expire[DEBUG_MEMORY_TIMER] = GetTimeInMillis()+ 10 * 1000;
+#endif
+
+       screen->defColormap = FakeClientID(0);
+       /* let CreateDefColormap do whatever it wants for pixels */
+       screen->blackPixel = screen->whitePixel = (Pixel) 0;
+       screen->QueryBestSize = sna_query_best_size;
+       assert(screen->GetImage == NULL);
+       screen->GetImage = sna_get_image;
+       assert(screen->GetSpans == NULL);
+       screen->GetSpans = sna_get_spans;
+       assert(screen->CreateWindow == NULL);
+       screen->CreateWindow = sna_create_window;
+       assert(screen->DestroyWindow == NULL);
+       screen->DestroyWindow = sna_destroy_window;
+       screen->PositionWindow = sna_position_window;
+       screen->ChangeWindowAttributes = sna_change_window_attributes;
+       screen->RealizeWindow = sna_map_window;
+       screen->UnrealizeWindow = sna_unmap_window;
+       screen->CopyWindow = sna_copy_window;
+       assert(screen->CreatePixmap == NULL);
+       screen->CreatePixmap = sna_create_pixmap;
+       assert(screen->DestroyPixmap == NULL);
+       screen->DestroyPixmap = sna_destroy_pixmap;
+#ifdef CREATE_PIXMAP_USAGE_SHARED
+       screen->SharePixmapBacking = sna_share_pixmap_backing;
+       screen->SetSharedPixmapBacking = sna_set_shared_pixmap_backing;
+#endif
+       screen->RealizeFont = sna_realize_font;
+       screen->UnrealizeFont = sna_unrealize_font;
+       assert(screen->CreateGC == NULL);
+       screen->CreateGC = sna_create_gc;
+       screen->CreateColormap = miInitializeColormap;
+       screen->DestroyColormap = (void (*)(ColormapPtr)) NoopDDA;
+       screen->InstallColormap = miInstallColormap;
+       screen->UninstallColormap = miUninstallColormap;
+       screen->ListInstalledColormaps = miListInstalledColormaps;
+       screen->ResolveColor = miResolveColor;
+       assert(screen->StoreColors == NULL);
+       screen->StoreColors = sna_store_colors;
+       screen->BitmapToRegion = fbBitmapToRegion;
+
+#if HAS_PIXMAP_SHARING
+       screen->StartPixmapTracking = PixmapStartDirtyTracking;
+       screen->StopPixmapTracking = PixmapStopDirtyTracking;
+#endif
+
+       assert(screen->GetWindowPixmap == NULL);
+       screen->GetWindowPixmap = sna_get_window_pixmap;
+       assert(screen->SetWindowPixmap == NULL);
+       screen->SetWindowPixmap = sna_set_window_pixmap;
+
+       if (sna->kgem.has_userptr)
+               ShmRegisterFuncs(screen, &shm_funcs);
+       else
+               ShmRegisterFbFuncs(screen);
+
+       if (!sna_picture_init(screen))
+               return false;
+
+       backend = "no";
+       sna->have_render = false;
+       no_render_init(sna);
+
+#if !DEBUG_NO_RENDER
+       if (sna->info->gen >= 80) {
+       } else if (sna->info->gen >= 70) {
+               if ((sna->have_render = gen7_render_init(sna)))
+                       backend = "IvyBridge";
+       } else if (sna->info->gen >= 60) {
+               if ((sna->have_render = gen6_render_init(sna)))
+                       backend = "SandyBridge";
+       } else if (sna->info->gen >= 50) {
+               if ((sna->have_render = gen5_render_init(sna)))
+                       backend = "Ironlake";
+       } else if (sna->info->gen >= 40) {
+               if ((sna->have_render = gen4_render_init(sna)))
+                       backend = "Broadwater";
+       } else if (sna->info->gen >= 30) {
+               if ((sna->have_render = gen3_render_init(sna)))
+                       backend = "gen3";
+       } else if (sna->info->gen >= 20) {
+               if ((sna->have_render = gen2_render_init(sna)))
+                       backend = "gen2";
+       }
+#endif
+       DBG(("%s(backend=%s, have_render=%d)\n",
+            __FUNCTION__, backend, sna->have_render));
+
+       kgem_reset(&sna->kgem);
+
+       xf86DrvMsg(sna->scrn->scrnIndex, X_INFO,
+                  "SNA initialized with %s backend\n",
+                  backend);
+
+       return true;
+}
+
+void sna_accel_create(struct sna *sna)
+{
+       if (!sna_glyphs_create(sna))
+               goto fail;
+
+       if (!sna_gradients_create(sna))
+               goto fail;
+
+       if (!sna_composite_create(sna))
+               goto fail;
+
+       return;
+
+fail:
+       xf86DrvMsg(sna->scrn->scrnIndex, X_ERROR,
+                  "Failed to allocate caches, disabling RENDER acceleration\n");
+       sna->have_render = false;
+       no_render_init(sna);
+}
+
+void sna_accel_watch_flush(struct sna *sna, int enable)
+{
+       DBG(("%s: enable=%d\n", __FUNCTION__, enable));
+       assert(enable);
+
+       if (sna->watch_flush == 0) {
+               DBG(("%s: installing watchers\n", __FUNCTION__));
+               assert(enable > 0);
+               if (!AddCallback(&FlushCallback, sna_accel_flush_callback, sna)) {
+                       xf86DrvMsg(sna->scrn->scrnIndex, X_Error,
+                                  "Failed to attach ourselves to the flush callbacks, expect missing synchronisation with DRI clients (e.g a compositor)\n");
+               }
+               sna->watch_flush++;
+       }
+
+       sna->watch_flush += enable;
+}
+
+void sna_accel_close(struct sna *sna)
+{
+       sna_composite_close(sna);
+       sna_gradients_close(sna);
+       sna_glyphs_close(sna);
+
+       while (sna->freed_pixmap) {
+               PixmapPtr pixmap = sna->freed_pixmap;
+               sna->freed_pixmap = pixmap->devPrivate.ptr;
+               assert(pixmap->refcnt == 0);
+               free(sna_pixmap(pixmap));
+               FreePixmap(pixmap);
+       }
+
+       DeleteCallback(&FlushCallback, sna_accel_flush_callback, sna);
+
+       kgem_cleanup_cache(&sna->kgem);
+}
+
+void sna_accel_block_handler(struct sna *sna, struct timeval **tv)
+{
+       UpdateCurrentTimeIf();
+
+       if (sna->kgem.nbatch && kgem_is_idle(&sna->kgem)) {
+               DBG(("%s: GPU idle, flushing\n", __FUNCTION__));
+               _kgem_submit(&sna->kgem);
+       }
+
+       if (sna_accel_do_flush(sna))
+               sna_accel_flush(sna);
+       assert(sna->flags & SNA_NO_DELAYED_FLUSH ||
+              sna_accel_scanout(sna) == NULL ||
+              sna_accel_scanout(sna)->gpu_bo->exec == NULL ||
+              sna->timer_active & (1<<(FLUSH_TIMER)));
+
+       if (sna_accel_do_throttle(sna))
+               sna_accel_throttle(sna);
+       assert(sna->flags & SNA_NO_THROTTLE ||
+              !sna->kgem.need_retire ||
+              sna->timer_active & (1<<(THROTTLE_TIMER)));
+
+       if (sna_accel_do_expire(sna))
+               sna_accel_expire(sna);
+       assert(!sna->kgem.need_expire ||
+              sna->timer_active & (1<<(EXPIRE_TIMER)));
+
+       if (sna_accel_do_inactive(sna))
+               sna_accel_inactive(sna);
+
+       if (sna_accel_do_debug_memory(sna))
+               sna_accel_debug_memory(sna);
+
+       if (sna->watch_flush == 1) {
+               DBG(("%s: removing watchers\n", __FUNCTION__));
+               DeleteCallback(&FlushCallback, sna_accel_flush_callback, sna);
+               sna->watch_flush = 0;
+       }
+
+       if (sna->timer_active) {
+               int32_t timeout;
+
+               DBG(("%s: evaluating timers, active=%x\n",
+                    __FUNCTION__, sna->timer_active));
+               timeout = sna_timeout(sna);
+               if (timeout) {
+                       if (*tv == NULL) {
+                               *tv = &sna->timer_tv;
+                               goto set_tv;
+                       }
+                       if ((*tv)->tv_sec * 1000 + (*tv)->tv_usec / 1000 > timeout) {
+set_tv:
+                               (*tv)->tv_sec = timeout / 1000;
+                               (*tv)->tv_usec = timeout % 1000 * 1000;
+                       }
+               }
+       }
+}
+
+void sna_accel_wakeup_handler(struct sna *sna)
+{
+       DBG(("%s\n", __FUNCTION__));
+
+       if (sna->kgem.need_retire)
+               kgem_retire(&sna->kgem);
+       if (!sna->mode.shadow_active && !sna->kgem.need_retire) {
+               DBG(("%s: GPU idle, flushing\n", __FUNCTION__));
+               kgem_submit(&sna->kgem);
+       }
+       if (sna->kgem.need_purge)
+               kgem_purge_cache(&sna->kgem);
+}
+
+void sna_accel_free(struct sna *sna)
+{
+}
diff --git a/src/sna/sna_blt.c b/src/sna/sna_blt.c
new file mode 100644 (file)
index 0000000..94b5f4a
--- /dev/null
@@ -0,0 +1,2701 @@
+/*
+ * Based on code from intel_uxa.c and i830_xaa.c
+ * Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright (c) 2005 Jesse Barnes <jbarnes@virtuousgeek.org>
+ * Copyright (c) 2009-2011 Intel 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.
+ *
+ * Authors:
+ *    Chris Wilson <chris@chris-wilson.co.uk>
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "sna.h"
+#include "sna_render.h"
+#include "sna_render_inline.h"
+#include "sna_reg.h"
+#include "rop.h"
+
+#define NO_BLT_COMPOSITE 0
+#define NO_BLT_COPY 0
+#define NO_BLT_COPY_BOXES 0
+#define NO_BLT_FILL 0
+#define NO_BLT_FILL_BOXES 0
+
+static const uint8_t copy_ROP[] = {
+       ROP_0,                  /* GXclear */
+       ROP_DSa,                /* GXand */
+       ROP_SDna,               /* GXandReverse */
+       ROP_S,                  /* GXcopy */
+       ROP_DSna,               /* GXandInverted */
+       ROP_D,                  /* GXnoop */
+       ROP_DSx,                /* GXxor */
+       ROP_DSo,                /* GXor */
+       ROP_DSon,               /* GXnor */
+       ROP_DSxn,               /* GXequiv */
+       ROP_Dn,                 /* GXinvert */
+       ROP_SDno,               /* GXorReverse */
+       ROP_Sn,                 /* GXcopyInverted */
+       ROP_DSno,               /* GXorInverted */
+       ROP_DSan,               /* GXnand */
+       ROP_1                   /* GXset */
+};
+
+static const uint8_t fill_ROP[] = {
+       ROP_0,
+       ROP_DPa,
+       ROP_PDna,
+       ROP_P,
+       ROP_DPna,
+       ROP_D,
+       ROP_DPx,
+       ROP_DPo,
+       ROP_DPon,
+       ROP_PDxn,
+       ROP_Dn,
+       ROP_PDno,
+       ROP_Pn,
+       ROP_DPno,
+       ROP_DPan,
+       ROP_1
+};
+
+static void nop_done(struct sna *sna, const struct sna_composite_op *op)
+{
+       (void)sna;
+       (void)op;
+}
+
+static void gen6_blt_copy_done(struct sna *sna, const struct sna_composite_op *op)
+{
+       struct kgem *kgem = &sna->kgem;
+
+       if (kgem_check_batch(kgem, 3)) {
+               uint32_t *b = kgem->batch + kgem->nbatch;
+               b[0] = XY_SETUP_CLIP;
+               b[1] = b[2] = 0;
+               kgem->nbatch += 3;
+       }
+       (void)op;
+}
+
+static bool sna_blt_fill_init(struct sna *sna,
+                             struct sna_blt_state *blt,
+                             struct kgem_bo *bo,
+                             int bpp,
+                             uint8_t alu,
+                             uint32_t pixel)
+{
+       struct kgem *kgem = &sna->kgem;
+
+       assert(kgem_bo_can_blt (kgem, bo));
+       assert(bo->tiling != I915_TILING_Y);
+       blt->bo[0] = bo;
+
+       blt->br13 = bo->pitch;
+       blt->cmd = XY_SCANLINE_BLT;
+       if (kgem->gen >= 40 && bo->tiling) {
+               blt->cmd |= BLT_DST_TILED;
+               blt->br13 >>= 2;
+       }
+       assert(blt->br13 <= MAXSHORT);
+
+       if (alu == GXclear)
+               pixel = 0;
+       else if (alu == GXcopy) {
+               if (pixel == 0)
+                       alu = GXclear;
+               else if (pixel == -1)
+                       alu = GXset;
+       }
+
+       blt->br13 |= 1<<31 | (fill_ROP[alu] << 16);
+       switch (bpp) {
+       default: assert(0);
+       case 32: blt->br13 |= 1 << 25; /* RGB8888 */
+       case 16: blt->br13 |= 1 << 24; /* RGB565 */
+       case 8: break;
+       }
+
+       blt->pixel = pixel;
+       blt->bpp = bpp;
+
+       kgem_set_mode(kgem, KGEM_BLT);
+       if (!kgem_check_bo_fenced(kgem, bo) ||
+           !kgem_check_batch(kgem, 12)) {
+               _kgem_submit(kgem);
+               assert(kgem_check_bo_fenced(kgem, bo));
+               _kgem_set_mode(kgem, KGEM_BLT);
+       }
+
+       if (sna->blt_state.fill_bo != bo->unique_id ||
+           sna->blt_state.fill_pixel != pixel ||
+           sna->blt_state.fill_alu != alu)
+       {
+               uint32_t *b;
+
+               if (!kgem_check_reloc(kgem, 1)) {
+                       _kgem_submit(kgem);
+                       _kgem_set_mode(kgem, KGEM_BLT);
+               }
+
+               b = kgem->batch + kgem->nbatch;
+               b[0] = XY_SETUP_MONO_PATTERN_SL_BLT;
+               if (bpp == 32)
+                       b[0] |= BLT_WRITE_ALPHA | BLT_WRITE_RGB;
+               b[1] = blt->br13;
+               b[2] = 0;
+               b[3] = 0;
+               b[4] = kgem_add_reloc(kgem, kgem->nbatch + 4, bo,
+                                     I915_GEM_DOMAIN_RENDER << 16 |
+                                     I915_GEM_DOMAIN_RENDER |
+                                     KGEM_RELOC_FENCED,
+                                     0);
+               b[5] = pixel;
+               b[6] = pixel;
+               b[7] = 0;
+               b[8] = 0;
+               kgem->nbatch += 9;
+
+               sna->blt_state.fill_bo = bo->unique_id;
+               sna->blt_state.fill_pixel = pixel;
+               sna->blt_state.fill_alu = alu;
+       }
+
+       return true;
+}
+
+noinline static void sna_blt_fill_begin(struct sna *sna,
+                                       const struct sna_blt_state *blt)
+{
+       struct kgem *kgem = &sna->kgem;
+       uint32_t *b;
+
+       _kgem_submit(kgem);
+       _kgem_set_mode(kgem, KGEM_BLT);
+
+       assert(kgem->nbatch == 0);
+       b = kgem->batch;
+       b[0] = XY_SETUP_MONO_PATTERN_SL_BLT;
+       if (blt->bpp == 32)
+               b[0] |= BLT_WRITE_ALPHA | BLT_WRITE_RGB;
+       b[1] = blt->br13;
+       b[2] = 0;
+       b[3] = 0;
+       b[4] = kgem_add_reloc(kgem, kgem->nbatch + 4, blt->bo[0],
+                             I915_GEM_DOMAIN_RENDER << 16 |
+                             I915_GEM_DOMAIN_RENDER |
+                             KGEM_RELOC_FENCED,
+                             0);
+       b[5] = blt->pixel;
+       b[6] = blt->pixel;
+       b[7] = 0;
+       b[8] = 0;
+       kgem->nbatch = 9;
+}
+
+inline static void sna_blt_fill_one(struct sna *sna,
+                                   const struct sna_blt_state *blt,
+                                   int16_t x, int16_t y,
+                                   int16_t width, int16_t height)
+{
+       struct kgem *kgem = &sna->kgem;
+       uint32_t *b;
+
+       DBG(("%s: (%d, %d) x (%d, %d): %08x\n",
+            __FUNCTION__, x, y, width, height, blt->pixel));
+
+       assert(x >= 0);
+       assert(y >= 0);
+       assert((y+height) * blt->bo[0]->pitch <= kgem_bo_size(blt->bo[0]));
+
+       if (!kgem_check_batch(kgem, 3))
+               sna_blt_fill_begin(sna, blt);
+
+       b = kgem->batch + kgem->nbatch;
+       kgem->nbatch += 3;
+
+       b[0] = blt->cmd;
+       b[1] = y << 16 | x;
+       b[2] = b[1] + (height << 16 | width);
+}
+
+static bool sna_blt_copy_init(struct sna *sna,
+                             struct sna_blt_state *blt,
+                             struct kgem_bo *src,
+                             struct kgem_bo *dst,
+                             int bpp,
+                             uint8_t alu)
+{
+       struct kgem *kgem = &sna->kgem;
+
+       assert(kgem_bo_can_blt (kgem, src));
+       assert(kgem_bo_can_blt (kgem, dst));
+
+       blt->bo[0] = src;
+       blt->bo[1] = dst;
+
+       blt->cmd = XY_SRC_COPY_BLT_CMD;
+       if (bpp == 32)
+               blt->cmd |= BLT_WRITE_ALPHA | BLT_WRITE_RGB;
+
+       blt->pitch[0] = src->pitch;
+       if (kgem->gen >= 40 && src->tiling) {
+               blt->cmd |= BLT_SRC_TILED;
+               blt->pitch[0] >>= 2;
+       }
+       assert(blt->pitch[0] <= MAXSHORT);
+
+       blt->pitch[1] = dst->pitch;
+       if (kgem->gen >= 40 && dst->tiling) {
+               blt->cmd |= BLT_DST_TILED;
+               blt->pitch[1] >>= 2;
+       }
+       assert(blt->pitch[1] <= MAXSHORT);
+
+       blt->overwrites = alu == GXcopy || alu == GXclear || alu == GXset;
+       blt->br13 = (copy_ROP[alu] << 16) | blt->pitch[1];
+       switch (bpp) {
+       default: assert(0);
+       case 32: blt->br13 |= 1 << 25; /* RGB8888 */
+       case 16: blt->br13 |= 1 << 24; /* RGB565 */
+       case 8: break;
+       }
+
+       kgem_set_mode(kgem, KGEM_BLT);
+       if (!kgem_check_many_bo_fenced(kgem, src, dst, NULL)) {
+               _kgem_submit(kgem);
+               if (!kgem_check_many_bo_fenced(kgem, src, dst, NULL))
+                       return false;
+               _kgem_set_mode(kgem, KGEM_BLT);
+       }
+
+       sna->blt_state.fill_bo = 0;
+       return true;
+}
+
+static bool sna_blt_alpha_fixup_init(struct sna *sna,
+                                    struct sna_blt_state *blt,
+                                    struct kgem_bo *src,
+                                    struct kgem_bo *dst,
+                                    int bpp, uint32_t alpha)
+{
+       struct kgem *kgem = &sna->kgem;
+
+       assert(kgem_bo_can_blt (kgem, src));
+       assert(kgem_bo_can_blt (kgem, dst));
+
+       blt->bo[0] = src;
+       blt->bo[1] = dst;
+
+       blt->cmd = XY_FULL_MONO_PATTERN_BLT;
+       blt->pitch[0] = src->pitch;
+       if (kgem->gen >= 40 && src->tiling) {
+               blt->cmd |= BLT_SRC_TILED;
+               blt->pitch[0] >>= 2;
+       }
+       assert(blt->pitch[0] <= MAXSHORT);
+
+       blt->pitch[1] = dst->pitch;
+       if (kgem->gen >= 40 && dst->tiling) {
+               blt->cmd |= BLT_DST_TILED;
+               blt->pitch[1] >>= 2;
+       }
+       assert(blt->pitch[1] <= MAXSHORT);
+
+       blt->overwrites = 1;
+       blt->br13 = (0xfc << 16) | blt->pitch[1];
+       switch (bpp) {
+       default: assert(0);
+       case 32: blt->cmd |= BLT_WRITE_ALPHA | BLT_WRITE_RGB;
+                blt->br13 |= 1 << 25; /* RGB8888 */
+       case 16: blt->br13 |= 1 << 24; /* RGB565 */
+       case 8: break;
+       }
+       blt->pixel = alpha;
+
+       kgem_set_mode(kgem, KGEM_BLT);
+       if (!kgem_check_many_bo_fenced(kgem, src, dst, NULL)) {
+               _kgem_submit(kgem);
+               if (!kgem_check_many_bo_fenced(kgem, src, dst, NULL))
+                       return false;
+               _kgem_set_mode(kgem, KGEM_BLT);
+       }
+
+       sna->blt_state.fill_bo = 0;
+       return true;
+}
+
+static void sna_blt_alpha_fixup_one(struct sna *sna,
+                                   const struct sna_blt_state *blt,
+                                   int src_x, int src_y,
+                                   int width, int height,
+                                   int dst_x, int dst_y)
+{
+       struct kgem *kgem = &sna->kgem;
+       uint32_t *b;
+
+       DBG(("%s: (%d, %d) -> (%d, %d) x (%d, %d)\n",
+            __FUNCTION__, src_x, src_y, dst_x, dst_y, width, height));
+
+       assert(src_x >= 0);
+       assert(src_y >= 0);
+       assert((src_y + height) * blt->bo[0]->pitch <= kgem_bo_size(blt->bo[0]));
+       assert(dst_x >= 0);
+       assert(dst_y >= 0);
+       assert((dst_y + height) * blt->bo[1]->pitch <= kgem_bo_size(blt->bo[1]));
+       assert(width > 0);
+       assert(height > 0);
+
+       if (!kgem_check_batch(kgem, 12) || !kgem_check_reloc(kgem, 2)) {
+               _kgem_submit(kgem);
+               _kgem_set_mode(kgem, KGEM_BLT);
+       }
+
+       b = kgem->batch + kgem->nbatch;
+       b[0] = blt->cmd;
+       b[1] = blt->br13;
+       b[2] = (dst_y << 16) | dst_x;
+       b[3] = ((dst_y + height) << 16) | (dst_x + width);
+       b[4] = kgem_add_reloc(kgem, kgem->nbatch + 4,
+                             blt->bo[1],
+                             I915_GEM_DOMAIN_RENDER << 16 |
+                             I915_GEM_DOMAIN_RENDER |
+                             KGEM_RELOC_FENCED,
+                             0);
+       b[5] = blt->pitch[0];
+       b[6] = (src_y << 16) | src_x;
+       b[7] = kgem_add_reloc(kgem, kgem->nbatch + 7,
+                             blt->bo[0],
+                             I915_GEM_DOMAIN_RENDER << 16 |
+                             KGEM_RELOC_FENCED,
+                             0);
+       b[8] = blt->pixel;
+       b[9] = blt->pixel;
+       b[10] = 0;
+       b[11] = 0;
+       kgem->nbatch += 12;
+}
+
+static void sna_blt_copy_one(struct sna *sna,
+                            const struct sna_blt_state *blt,
+                            int src_x, int src_y,
+                            int width, int height,
+                            int dst_x, int dst_y)
+{
+       struct kgem *kgem = &sna->kgem;
+       uint32_t *b;
+
+       DBG(("%s: (%d, %d) -> (%d, %d) x (%d, %d)\n",
+            __FUNCTION__, src_x, src_y, dst_x, dst_y, width, height));
+
+       assert(src_x >= 0);
+       assert(src_y >= 0);
+       assert((src_y + height) * blt->bo[0]->pitch <= kgem_bo_size(blt->bo[0]));
+       assert(dst_x >= 0);
+       assert(dst_y >= 0);
+       assert((dst_y + height) * blt->bo[1]->pitch <= kgem_bo_size(blt->bo[1]));
+       assert(width > 0);
+       assert(height > 0);
+
+       /* Compare against a previous fill */
+       if (kgem->nbatch >= 6 &&
+           blt->overwrites &&
+           kgem->batch[kgem->nbatch-6] == (XY_COLOR_BLT | (blt->cmd & (BLT_WRITE_ALPHA | BLT_WRITE_RGB))) &&
+           kgem->batch[kgem->nbatch-4] == ((uint32_t)dst_y << 16 | (uint16_t)dst_x) &&
+           kgem->batch[kgem->nbatch-3] == ((uint32_t)(dst_y+height) << 16 | (uint16_t)(dst_x+width)) &&
+           kgem->reloc[kgem->nreloc-1].target_handle == blt->bo[1]->handle) {
+               DBG(("%s: replacing last fill\n", __FUNCTION__));
+               b = kgem->batch + kgem->nbatch - 6;
+               b[0] = blt->cmd;
+               b[1] = blt->br13;
+               b[5] = (src_y << 16) | src_x;
+               b[6] = blt->pitch[0];
+               b[7] = kgem_add_reloc(kgem, kgem->nbatch + 7 - 6,
+                                     blt->bo[0],
+                                     I915_GEM_DOMAIN_RENDER << 16 |
+                                     KGEM_RELOC_FENCED,
+                                     0);
+               kgem->nbatch += 8 - 6;
+               return;
+       }
+
+       if (!kgem_check_batch(kgem, 8) || !kgem_check_reloc(kgem, 2)) {
+               _kgem_submit(kgem);
+               _kgem_set_mode(kgem, KGEM_BLT);
+       }
+
+       b = kgem->batch + kgem->nbatch;
+       b[0] = blt->cmd;
+       b[1] = blt->br13;
+       b[2] = (dst_y << 16) | dst_x;
+       b[3] = ((dst_y + height) << 16) | (dst_x + width);
+       b[4] = kgem_add_reloc(kgem, kgem->nbatch + 4,
+                             blt->bo[1],
+                             I915_GEM_DOMAIN_RENDER << 16 |
+                             I915_GEM_DOMAIN_RENDER |
+                             KGEM_RELOC_FENCED,
+                             0);
+       b[5] = (src_y << 16) | src_x;
+       b[6] = blt->pitch[0];
+       b[7] = kgem_add_reloc(kgem, kgem->nbatch + 7,
+                             blt->bo[0],
+                             I915_GEM_DOMAIN_RENDER << 16 |
+                             KGEM_RELOC_FENCED,
+                             0);
+       kgem->nbatch += 8;
+}
+
+bool
+sna_get_rgba_from_pixel(uint32_t pixel,
+                       uint16_t *red,
+                       uint16_t *green,
+                       uint16_t *blue,
+                       uint16_t *alpha,
+                       uint32_t format)
+{
+       int rbits, bbits, gbits, abits;
+       int rshift, bshift, gshift, ashift;
+
+       rbits = PICT_FORMAT_R(format);
+       gbits = PICT_FORMAT_G(format);
+       bbits = PICT_FORMAT_B(format);
+       abits = PICT_FORMAT_A(format);
+
+       if (PICT_FORMAT_TYPE(format) == PICT_TYPE_A) {
+               rshift = gshift = bshift = ashift = 0;
+       } else if (PICT_FORMAT_TYPE(format) == PICT_TYPE_ARGB) {
+               bshift = 0;
+               gshift = bbits;
+               rshift = gshift + gbits;
+               ashift = rshift + rbits;
+       } else if (PICT_FORMAT_TYPE(format) == PICT_TYPE_ABGR) {
+               rshift = 0;
+               gshift = rbits;
+               bshift = gshift + gbits;
+               ashift = bshift + bbits;
+       } else if (PICT_FORMAT_TYPE(format) == PICT_TYPE_BGRA) {
+               ashift = 0;
+               rshift = abits;
+               if (abits == 0)
+                       rshift = PICT_FORMAT_BPP(format) - (rbits+gbits+bbits);
+               gshift = rshift + rbits;
+               bshift = gshift + gbits;
+       } else {
+               return false;
+       }
+
+       if (rbits) {
+               *red = ((pixel >> rshift) & ((1 << rbits) - 1)) << (16 - rbits);
+               while (rbits < 16) {
+                       *red |= *red >> rbits;
+                       rbits <<= 1;
+               }
+       } else
+               *red = 0;
+
+       if (gbits) {
+               *green = ((pixel >> gshift) & ((1 << gbits) - 1)) << (16 - gbits);
+               while (gbits < 16) {
+                       *green |= *green >> gbits;
+                       gbits <<= 1;
+               }
+       } else
+               *green = 0;
+
+       if (bbits) {
+               *blue = ((pixel >> bshift) & ((1 << bbits) - 1)) << (16 - bbits);
+               while (bbits < 16) {
+                       *blue |= *blue >> bbits;
+                       bbits <<= 1;
+               }
+       } else
+               *blue = 0;
+
+       if (abits) {
+               *alpha = ((pixel >> ashift) & ((1 << abits) - 1)) << (16 - abits);
+               while (abits < 16) {
+                       *alpha |= *alpha >> abits;
+                       abits <<= 1;
+               }
+       } else
+               *alpha = 0xffff;
+
+       return true;
+}
+
+bool
+_sna_get_pixel_from_rgba(uint32_t * pixel,
+                       uint16_t red,
+                       uint16_t green,
+                       uint16_t blue,
+                       uint16_t alpha,
+                       uint32_t format)
+{
+       int rbits, bbits, gbits, abits;
+       int rshift, bshift, gshift, ashift;
+
+       rbits = PICT_FORMAT_R(format);
+       gbits = PICT_FORMAT_G(format);
+       bbits = PICT_FORMAT_B(format);
+       abits = PICT_FORMAT_A(format);
+       if (abits == 0)
+           abits = PICT_FORMAT_BPP(format) - (rbits+gbits+bbits);
+
+       if (PICT_FORMAT_TYPE(format) == PICT_TYPE_A) {
+               *pixel = alpha >> (16 - abits);
+               return true;
+       }
+
+       if (!PICT_FORMAT_COLOR(format))
+               return false;
+
+       if (PICT_FORMAT_TYPE(format) == PICT_TYPE_ARGB) {
+               bshift = 0;
+               gshift = bbits;
+               rshift = gshift + gbits;
+               ashift = rshift + rbits;
+       } else if (PICT_FORMAT_TYPE(format) == PICT_TYPE_ABGR) {
+               rshift = 0;
+               gshift = rbits;
+               bshift = gshift + gbits;
+               ashift = bshift + bbits;
+       } else if (PICT_FORMAT_TYPE(format) == PICT_TYPE_BGRA) {
+               ashift = 0;
+               rshift = abits;
+               gshift = rshift + rbits;
+               bshift = gshift + gbits;
+       } else
+               return false;
+
+       *pixel = 0;
+       *pixel |= (blue  >> (16 - bbits)) << bshift;
+       *pixel |= (green >> (16 - gbits)) << gshift;
+       *pixel |= (red   >> (16 - rbits)) << rshift;
+       *pixel |= (alpha >> (16 - abits)) << ashift;
+
+       return true;
+}
+
+uint32_t
+sna_rgba_for_color(uint32_t color, int depth)
+{
+       return color_convert(color, sna_format_for_depth(depth), PICT_a8r8g8b8);
+}
+
+uint32_t
+sna_rgba_to_color(uint32_t rgba, uint32_t format)
+{
+       return color_convert(rgba, PICT_a8r8g8b8, format);
+}
+
+static uint32_t
+get_pixel(PicturePtr picture)
+{
+       PixmapPtr pixmap = get_drawable_pixmap(picture->pDrawable);
+
+       DBG(("%s: %p\n", __FUNCTION__, pixmap));
+
+       if (!sna_pixmap_move_to_cpu(pixmap, MOVE_READ))
+               return 0;
+
+       switch (pixmap->drawable.bitsPerPixel) {
+       case 32: return *(uint32_t *)pixmap->devPrivate.ptr;
+       case 16: return *(uint16_t *)pixmap->devPrivate.ptr;
+       default: return *(uint8_t *)pixmap->devPrivate.ptr;
+       }
+}
+
+static uint32_t
+get_solid_color(PicturePtr picture, uint32_t format)
+{
+       if (picture->pSourcePict) {
+               PictSolidFill *fill = (PictSolidFill *)picture->pSourcePict;
+               return color_convert(fill->color, PICT_a8r8g8b8, format);
+       } else
+               return color_convert(get_pixel(picture), picture->format, format);
+}
+
+static bool
+is_solid(PicturePtr picture)
+{
+       if (picture->pSourcePict) {
+               if (picture->pSourcePict->type == SourcePictTypeSolidFill)
+                       return true;
+       }
+
+       if (picture->pDrawable) {
+               if (picture->pDrawable->width  == 1 &&
+                   picture->pDrawable->height == 1 &&
+                   picture->repeat)
+                       return true;
+       }
+
+       return false;
+}
+
+bool
+sna_picture_is_solid(PicturePtr picture, uint32_t *color)
+{
+       if (!is_solid(picture))
+               return false;
+
+       if (color)
+               *color = get_solid_color(picture, PICT_a8r8g8b8);
+       return true;
+}
+
+static bool
+pixel_is_opaque(uint32_t pixel, uint32_t format)
+{
+       unsigned int abits;
+
+       abits = PICT_FORMAT_A(format);
+       if (!abits)
+               return true;
+
+       if (PICT_FORMAT_TYPE(format) == PICT_TYPE_A ||
+           PICT_FORMAT_TYPE(format) == PICT_TYPE_BGRA) {
+               return (pixel & ((1 << abits) - 1)) == (unsigned)((1 << abits) - 1);
+       } else if (PICT_FORMAT_TYPE(format) == PICT_TYPE_ARGB ||
+                  PICT_FORMAT_TYPE(format) == PICT_TYPE_ABGR) {
+               unsigned int ashift = PICT_FORMAT_BPP(format) - abits;
+               return (pixel >> ashift) == (unsigned)((1 << abits) - 1);
+       } else
+               return false;
+}
+
+static bool
+pixel_is_white(uint32_t pixel, uint32_t format)
+{
+       switch (PICT_FORMAT_TYPE(format)) {
+       case PICT_TYPE_A:
+       case PICT_TYPE_ARGB:
+       case PICT_TYPE_ABGR:
+       case PICT_TYPE_BGRA:
+               return pixel == ((1U << PICT_FORMAT_BPP(format)) - 1);
+       default:
+               return false;
+       }
+}
+
+static bool
+is_opaque_solid(PicturePtr picture)
+{
+       if (picture->pSourcePict) {
+               PictSolidFill *fill = (PictSolidFill *) picture->pSourcePict;
+               return (fill->color >> 24) == 0xff;
+       } else
+               return pixel_is_opaque(get_pixel(picture), picture->format);
+}
+
+static bool
+is_white(PicturePtr picture)
+{
+       if (picture->pSourcePict) {
+               PictSolidFill *fill = (PictSolidFill *) picture->pSourcePict;
+               return fill->color == 0xffffffff;
+       } else
+               return pixel_is_white(get_pixel(picture), picture->format);
+}
+
+bool
+sna_composite_mask_is_opaque(PicturePtr mask)
+{
+       if (mask->componentAlpha && PICT_FORMAT_RGB(mask->format))
+               return is_solid(mask) && is_white(mask);
+       else if (!PICT_FORMAT_A(mask->format))
+               return true;
+       else
+               return is_solid(mask) && is_opaque_solid(mask);
+}
+
+fastcall
+static void blt_composite_fill(struct sna *sna,
+                              const struct sna_composite_op *op,
+                              const struct sna_composite_rectangles *r)
+{
+       int x1, x2, y1, y2;
+
+       x1 = r->dst.x + op->dst.x;
+       y1 = r->dst.y + op->dst.y;
+       x2 = x1 + r->width;
+       y2 = y1 + r->height;
+
+       if (x1 < 0)
+               x1 = 0;
+       if (y1 < 0)
+               y1 = 0;
+
+       if (x2 > op->dst.width)
+               x2 = op->dst.width;
+       if (y2 > op->dst.height)
+               y2 = op->dst.height;
+
+       if (x2 <= x1 || y2 <= y1)
+               return;
+
+       sna_blt_fill_one(sna, &op->u.blt, x1, y1, x2-x1, y2-y1);
+}
+
+fastcall
+static void blt_composite_fill__cpu(struct sna *sna,
+                                   const struct sna_composite_op *op,
+                                   const struct sna_composite_rectangles *r)
+{
+       int x1, x2, y1, y2;
+
+       x1 = r->dst.x + op->dst.x;
+       y1 = r->dst.y + op->dst.y;
+       x2 = x1 + r->width;
+       y2 = y1 + r->height;
+
+       if (x1 < 0)
+               x1 = 0;
+       if (y1 < 0)
+               y1 = 0;
+
+       if (x2 > op->dst.width)
+               x2 = op->dst.width;
+       if (y2 > op->dst.height)
+               y2 = op->dst.height;
+
+       if (x2 <= x1 || y2 <= y1)
+               return;
+
+       pixman_fill(op->dst.pixmap->devPrivate.ptr,
+                   op->dst.pixmap->devKind / sizeof(uint32_t),
+                   op->dst.pixmap->drawable.bitsPerPixel,
+                   x1, y1, x2-x1, y2-y1,
+                   op->u.blt.pixel);
+}
+
+fastcall static void
+blt_composite_fill_box__cpu(struct sna *sna,
+                           const struct sna_composite_op *op,
+                           const BoxRec *box)
+{
+       pixman_fill(op->dst.pixmap->devPrivate.ptr,
+                   op->dst.pixmap->devKind / sizeof(uint32_t),
+                   op->dst.pixmap->drawable.bitsPerPixel,
+                   box->x1, box->y1, box->x2-box->x1, box->y2-box->y1,
+                   op->u.blt.pixel);
+}
+
+static void
+blt_composite_fill_boxes__cpu(struct sna *sna,
+                             const struct sna_composite_op *op,
+                             const BoxRec *box, int n)
+{
+       do {
+               pixman_fill(op->dst.pixmap->devPrivate.ptr,
+                           op->dst.pixmap->devKind / sizeof(uint32_t),
+                           op->dst.pixmap->drawable.bitsPerPixel,
+                           box->x1, box->y1, box->x2-box->x1, box->y2-box->y1,
+                           op->u.blt.pixel);
+               box++;
+       } while (--n);
+}
+
+inline static void _sna_blt_fill_box(struct sna *sna,
+                                    const struct sna_blt_state *blt,
+                                    const BoxRec *box)
+{
+       struct kgem *kgem = &sna->kgem;
+       uint32_t *b;
+
+       DBG(("%s: (%d, %d), (%d, %d): %08x\n", __FUNCTION__,
+            box->x1, box->y1, box->x2, box->y2,
+            blt->pixel));
+
+       assert(box->x1 >= 0);
+       assert(box->y1 >= 0);
+       assert(box->y2 * blt->bo[0]->pitch <= kgem_bo_size(blt->bo[0]));
+
+       if (!kgem_check_batch(kgem, 3))
+               sna_blt_fill_begin(sna, blt);
+
+       b = kgem->batch + kgem->nbatch;
+       kgem->nbatch += 3;
+
+       b[0] = blt->cmd;
+       *(uint64_t *)(b+1) = *(const uint64_t *)box;
+}
+
+inline static void _sna_blt_fill_boxes(struct sna *sna,
+                                      const struct sna_blt_state *blt,
+                                      const BoxRec *box,
+                                      int nbox)
+{
+       struct kgem *kgem = &sna->kgem;
+       uint32_t cmd = blt->cmd;
+
+       DBG(("%s: %08x x %d\n", __FUNCTION__, blt->pixel, nbox));
+
+       if (!kgem_check_batch(kgem, 3))
+               sna_blt_fill_begin(sna, blt);
+
+       do {
+               uint32_t *b = kgem->batch + kgem->nbatch;
+               int nbox_this_time;
+
+               nbox_this_time = nbox;
+               if (3*nbox_this_time > kgem->surface - kgem->nbatch - KGEM_BATCH_RESERVED)
+                       nbox_this_time = (kgem->surface - kgem->nbatch - KGEM_BATCH_RESERVED) / 3;
+               assert(nbox_this_time);
+               nbox -= nbox_this_time;
+
+               kgem->nbatch += 3 * nbox_this_time;
+               while (nbox_this_time >= 8) {
+                       b[0] = cmd; *(uint64_t *)(b+1) = *(const uint64_t *)box++;
+                       b[3] = cmd; *(uint64_t *)(b+4) = *(const uint64_t *)box++;
+                       b[6] = cmd; *(uint64_t *)(b+7) = *(const uint64_t *)box++;
+                       b[9] = cmd; *(uint64_t *)(b+10) = *(const uint64_t *)box++;
+                       b[12] = cmd; *(uint64_t *)(b+13) = *(const uint64_t *)box++;
+                       b[15] = cmd; *(uint64_t *)(b+16) = *(const uint64_t *)box++;
+                       b[18] = cmd; *(uint64_t *)(b+19) = *(const uint64_t *)box++;
+                       b[21] = cmd; *(uint64_t *)(b+22) = *(const uint64_t *)box++;
+                       b += 24;
+                       nbox_this_time -= 8;
+               }
+               if (nbox_this_time & 4) {
+                       b[0] = cmd; *(uint64_t *)(b+1) = *(const uint64_t *)box++;
+                       b[3] = cmd; *(uint64_t *)(b+4) = *(const uint64_t *)box++;
+                       b[6] = cmd; *(uint64_t *)(b+7) = *(const uint64_t *)box++;
+                       b[9] = cmd; *(uint64_t *)(b+10) = *(const uint64_t *)box++;
+                       b += 12;
+               }
+               if (nbox_this_time & 2) {
+                       b[0] = cmd; *(uint64_t *)(b+1) = *(const uint64_t *)box++;
+                       b[3] = cmd; *(uint64_t *)(b+4) = *(const uint64_t *)box++;
+                       b += 6;
+               }
+               if (nbox_this_time & 1) {
+                       b[0] = cmd; *(uint64_t *)(b+1) = *(const uint64_t *)box++;
+               }
+
+               if (!nbox)
+                       return;
+
+               sna_blt_fill_begin(sna, blt);
+       } while (1);
+}
+
+fastcall static void blt_composite_fill_box_no_offset(struct sna *sna,
+                                                     const struct sna_composite_op *op,
+                                                     const BoxRec *box)
+{
+       _sna_blt_fill_box(sna, &op->u.blt, box);
+}
+
+static void blt_composite_fill_boxes_no_offset(struct sna *sna,
+                                              const struct sna_composite_op *op,
+                                              const BoxRec *box, int n)
+{
+       _sna_blt_fill_boxes(sna, &op->u.blt, box, n);
+}
+
+fastcall static void blt_composite_fill_box(struct sna *sna,
+                                           const struct sna_composite_op *op,
+                                           const BoxRec *box)
+{
+       sna_blt_fill_one(sna, &op->u.blt,
+                        box->x1 + op->dst.x,
+                        box->y1 + op->dst.y,
+                        box->x2 - box->x1,
+                        box->y2 - box->y1);
+}
+
+static void blt_composite_fill_boxes(struct sna *sna,
+                                    const struct sna_composite_op *op,
+                                    const BoxRec *box, int n)
+{
+       do {
+               sna_blt_fill_one(sna, &op->u.blt,
+                                box->x1 + op->dst.x, box->y1 + op->dst.y,
+                                box->x2 - box->x1, box->y2 - box->y1);
+               box++;
+       } while (--n);
+}
+
+fastcall
+static void blt_composite_nop(struct sna *sna,
+                              const struct sna_composite_op *op,
+                              const struct sna_composite_rectangles *r)
+{
+}
+
+fastcall static void blt_composite_nop_box(struct sna *sna,
+                                          const struct sna_composite_op *op,
+                                          const BoxRec *box)
+{
+}
+
+static void blt_composite_nop_boxes(struct sna *sna,
+                                   const struct sna_composite_op *op,
+                                   const BoxRec *box, int n)
+{
+}
+
+static bool
+begin_blt(struct sna *sna,
+         struct sna_composite_op *op)
+{
+       if (!kgem_check_bo_fenced(&sna->kgem, op->dst.bo)) {
+               _kgem_submit(&sna->kgem);
+               assert(kgem_check_bo_fenced(&sna->kgem, op->dst.bo));
+               _kgem_set_mode(&sna->kgem, KGEM_BLT);
+       }
+
+       return true;
+}
+
+static bool
+prepare_blt_nop(struct sna *sna,
+               struct sna_composite_op *op)
+{
+       DBG(("%s\n", __FUNCTION__));
+
+       op->blt   = blt_composite_nop;
+       op->box   = blt_composite_nop_box;
+       op->boxes = blt_composite_nop_boxes;
+       op->done  = nop_done;
+       return true;
+}
+
+static bool
+prepare_blt_clear(struct sna *sna,
+                 struct sna_composite_op *op)
+{
+       DBG(("%s\n", __FUNCTION__));
+
+       if (op->dst.bo == NULL) {
+               op->blt   = blt_composite_fill__cpu;
+               op->box   = blt_composite_fill_box__cpu;
+               op->boxes = blt_composite_fill_boxes__cpu;
+               op->done  = nop_done;
+               op->u.blt.pixel = 0;
+               return true;
+       }
+
+       op->blt = blt_composite_fill;
+       if (op->dst.x|op->dst.y) {
+               op->box   = blt_composite_fill_box;
+               op->boxes = blt_composite_fill_boxes;
+       } else {
+               op->box   = blt_composite_fill_box_no_offset;
+               op->boxes = blt_composite_fill_boxes_no_offset;
+       }
+       op->done = nop_done;
+
+       if (!sna_blt_fill_init(sna, &op->u.blt,
+                                op->dst.bo,
+                                op->dst.pixmap->drawable.bitsPerPixel,
+                                GXclear, 0))
+               return false;
+
+       return begin_blt(sna, op);
+}
+
+static bool
+prepare_blt_fill(struct sna *sna,
+                struct sna_composite_op *op,
+                PicturePtr source)
+{
+       DBG(("%s\n", __FUNCTION__));
+
+       if (op->dst.bo == NULL) {
+               op->u.blt.pixel = get_solid_color(source, op->dst.format);
+               op->blt = blt_composite_fill__cpu;
+               op->box   = blt_composite_fill_box__cpu;
+               op->boxes = blt_composite_fill_boxes__cpu;
+               op->done = nop_done;
+               return true;
+       }
+
+       op->blt = blt_composite_fill;
+       if (op->dst.x|op->dst.y) {
+               op->box   = blt_composite_fill_box;
+               op->boxes = blt_composite_fill_boxes;
+       } else {
+               op->box   = blt_composite_fill_box_no_offset;
+               op->boxes = blt_composite_fill_boxes_no_offset;
+       }
+       op->done = nop_done;
+
+       if (!sna_blt_fill_init(sna, &op->u.blt, op->dst.bo,
+                              op->dst.pixmap->drawable.bitsPerPixel,
+                              GXcopy,
+                              get_solid_color(source, op->dst.format)))
+               return false;
+
+       return begin_blt(sna, op);
+}
+
+fastcall static void
+blt_composite_copy(struct sna *sna,
+                  const struct sna_composite_op *op,
+                  const struct sna_composite_rectangles *r)
+{
+       int x1, x2, y1, y2;
+       int src_x, src_y;
+
+       DBG(("%s: src=(%d, %d), dst=(%d, %d), size=(%d, %d)\n",
+            __FUNCTION__,
+            r->src.x, r->src.y,
+            r->dst.x, r->dst.y,
+            r->width, r->height));
+
+       /* XXX higher layer should have clipped? */
+
+       x1 = r->dst.x + op->dst.x;
+       y1 = r->dst.y + op->dst.y;
+       x2 = x1 + r->width;
+       y2 = y1 + r->height;
+
+       src_x = r->src.x - x1;
+       src_y = r->src.y - y1;
+
+       /* clip against dst */
+       if (x1 < 0)
+               x1 = 0;
+       if (y1 < 0)
+               y1 = 0;
+
+       if (x2 > op->dst.width)
+               x2 = op->dst.width;
+
+       if (y2 > op->dst.height)
+               y2 = op->dst.height;
+
+       DBG(("%s: box=(%d, %d), (%d, %d)\n", __FUNCTION__, x1, y1, x2, y2));
+
+       if (x2 <= x1 || y2 <= y1)
+               return;
+
+       sna_blt_copy_one(sna, &op->u.blt,
+                        x1 + src_x, y1 + src_y,
+                        x2 - x1, y2 - y1,
+                        x1, y1);
+}
+
+fastcall static void blt_composite_copy_box(struct sna *sna,
+                                           const struct sna_composite_op *op,
+                                           const BoxRec *box)
+{
+       DBG(("%s: box (%d, %d), (%d, %d)\n",
+            __FUNCTION__, box->x1, box->y1, box->x2, box->y2));
+       sna_blt_copy_one(sna, &op->u.blt,
+                        box->x1 + op->u.blt.sx,
+                        box->y1 + op->u.blt.sy,
+                        box->x2 - box->x1,
+                        box->y2 - box->y1,
+                        box->x1 + op->dst.x,
+                        box->y1 + op->dst.y);
+}
+
+static void blt_composite_copy_boxes(struct sna *sna,
+                                    const struct sna_composite_op *op,
+                                    const BoxRec *box, int nbox)
+{
+       DBG(("%s: nbox=%d\n", __FUNCTION__, nbox));
+       do {
+               DBG(("%s: box (%d, %d), (%d, %d)\n",
+                    __FUNCTION__, box->x1, box->y1, box->x2, box->y2));
+               sna_blt_copy_one(sna, &op->u.blt,
+                                box->x1 + op->u.blt.sx, box->y1 + op->u.blt.sy,
+                                box->x2 - box->x1, box->y2 - box->y1,
+                                box->x1 + op->dst.x, box->y1 + op->dst.y);
+               box++;
+       } while(--nbox);
+}
+
+fastcall static void
+blt_composite_copy_with_alpha(struct sna *sna,
+                             const struct sna_composite_op *op,
+                             const struct sna_composite_rectangles *r)
+{
+       int x1, x2, y1, y2;
+       int src_x, src_y;
+
+       DBG(("%s: src=(%d, %d), dst=(%d, %d), size=(%d, %d)\n",
+            __FUNCTION__,
+            r->src.x, r->src.y,
+            r->dst.x, r->dst.y,
+            r->width, r->height));
+
+       /* XXX higher layer should have clipped? */
+
+       x1 = r->dst.x + op->dst.x;
+       y1 = r->dst.y + op->dst.y;
+       x2 = x1 + r->width;
+       y2 = y1 + r->height;
+
+       src_x = r->src.x - x1;
+       src_y = r->src.y - y1;
+
+       /* clip against dst */
+       if (x1 < 0)
+               x1 = 0;
+       if (y1 < 0)
+               y1 = 0;
+
+       if (x2 > op->dst.width)
+               x2 = op->dst.width;
+
+       if (y2 > op->dst.height)
+               y2 = op->dst.height;
+
+       DBG(("%s: box=(%d, %d), (%d, %d)\n", __FUNCTION__, x1, y1, x2, y2));
+
+       if (x2 <= x1 || y2 <= y1)
+               return;
+
+       sna_blt_alpha_fixup_one(sna, &op->u.blt,
+                               x1 + src_x, y1 + src_y,
+                               x2 - x1, y2 - y1,
+                               x1, y1);
+}
+
+fastcall static void
+blt_composite_copy_box_with_alpha(struct sna *sna,
+                                 const struct sna_composite_op *op,
+                                 const BoxRec *box)
+{
+       DBG(("%s: box (%d, %d), (%d, %d)\n",
+            __FUNCTION__, box->x1, box->y1, box->x2, box->y2));
+       sna_blt_alpha_fixup_one(sna, &op->u.blt,
+                               box->x1 + op->u.blt.sx,
+                               box->y1 + op->u.blt.sy,
+                               box->x2 - box->x1,
+                               box->y2 - box->y1,
+                               box->x1 + op->dst.x,
+                               box->y1 + op->dst.y);
+}
+
+static void
+blt_composite_copy_boxes_with_alpha(struct sna *sna,
+                                   const struct sna_composite_op *op,
+                                   const BoxRec *box, int nbox)
+{
+       DBG(("%s: nbox=%d\n", __FUNCTION__, nbox));
+       do {
+               DBG(("%s: box (%d, %d), (%d, %d)\n",
+                    __FUNCTION__, box->x1, box->y1, box->x2, box->y2));
+               sna_blt_alpha_fixup_one(sna, &op->u.blt,
+                                       box->x1 + op->u.blt.sx, box->y1 + op->u.blt.sy,
+                                       box->x2 - box->x1, box->y2 - box->y1,
+                                       box->x1 + op->dst.x, box->y1 + op->dst.y);
+               box++;
+       } while(--nbox);
+}
+
+static bool
+prepare_blt_copy(struct sna *sna,
+                struct sna_composite_op *op,
+                struct kgem_bo *bo,
+                uint32_t alpha_fixup)
+{
+       PixmapPtr src = op->u.blt.src_pixmap;
+
+       assert(op->dst.bo);
+       assert(kgem_bo_can_blt(&sna->kgem, op->dst.bo));
+
+       if (!kgem_bo_can_blt(&sna->kgem, bo)) {
+               DBG(("%s: fallback -- can't blt from source\n", __FUNCTION__));
+               return false;
+       }
+
+       if (!kgem_check_many_bo_fenced(&sna->kgem, op->dst.bo, bo, NULL)) {
+               _kgem_submit(&sna->kgem);
+               if (!kgem_check_many_bo_fenced(&sna->kgem,
+                                              op->dst.bo, bo, NULL)) {
+                       DBG(("%s: fallback -- no room in aperture\n", __FUNCTION__));
+                       return false;
+               }
+               _kgem_set_mode(&sna->kgem, KGEM_BLT);
+       }
+
+       DBG(("%s\n", __FUNCTION__));
+
+       if (sna->kgem.gen >= 60)
+               op->done = gen6_blt_copy_done;
+       else
+               op->done = nop_done;
+
+       if (alpha_fixup) {
+               op->blt   = blt_composite_copy_with_alpha;
+               op->box   = blt_composite_copy_box_with_alpha;
+               op->boxes = blt_composite_copy_boxes_with_alpha;
+
+               if (!sna_blt_alpha_fixup_init(sna, &op->u.blt, bo, op->dst.bo,
+                                             src->drawable.bitsPerPixel,
+                                             alpha_fixup))
+                       return false;
+       } else {
+               op->blt   = blt_composite_copy;
+               op->box   = blt_composite_copy_box;
+               op->boxes = blt_composite_copy_boxes;
+
+               if (!sna_blt_copy_init(sna, &op->u.blt, bo, op->dst.bo,
+                                      src->drawable.bitsPerPixel,
+                                      GXcopy))
+                       return false;
+       }
+
+       return true;
+}
+
+fastcall static void
+blt_put_composite__cpu(struct sna *sna,
+                      const struct sna_composite_op *op,
+                      const struct sna_composite_rectangles *r)
+{
+       PixmapPtr dst = op->dst.pixmap;
+       PixmapPtr src = op->u.blt.src_pixmap;
+       memcpy_blt(src->devPrivate.ptr, dst->devPrivate.ptr,
+                  src->drawable.bitsPerPixel, src->devKind, dst->devKind,
+                  r->src.x + op->u.blt.sx, r->src.y + op->u.blt.sy,
+                  r->dst.x + op->dst.x, r->dst.y + op->dst.y,
+                  r->width, r->height);
+}
+
+fastcall static void
+blt_put_composite_box__cpu(struct sna *sna,
+                          const struct sna_composite_op *op,
+                          const BoxRec *box)
+{
+       PixmapPtr dst = op->dst.pixmap;
+       PixmapPtr src = op->u.blt.src_pixmap;
+       memcpy_blt(src->devPrivate.ptr, dst->devPrivate.ptr,
+                  src->drawable.bitsPerPixel, src->devKind, dst->devKind,
+                  box->x1 + op->u.blt.sx, box->y1 + op->u.blt.sy,
+                  box->x1 + op->dst.x, box->y1 + op->dst.y,
+                  box->x2-box->x1, box->y2-box->y1);
+}
+
+static void
+blt_put_composite_boxes__cpu(struct sna *sna,
+                            const struct sna_composite_op *op,
+                            const BoxRec *box, int n)
+{
+       PixmapPtr dst = op->dst.pixmap;
+       PixmapPtr src = op->u.blt.src_pixmap;
+       do {
+               memcpy_blt(src->devPrivate.ptr, dst->devPrivate.ptr,
+                          src->drawable.bitsPerPixel, src->devKind, dst->devKind,
+                          box->x1 + op->u.blt.sx, box->y1 + op->u.blt.sy,
+                          box->x1 + op->dst.x, box->y1 + op->dst.y,
+                          box->x2-box->x1, box->y2-box->y1);
+               box++;
+       } while (--n);
+}
+
+fastcall static void
+blt_put_composite_with_alpha__cpu(struct sna *sna,
+                                 const struct sna_composite_op *op,
+                                 const struct sna_composite_rectangles *r)
+{
+       PixmapPtr dst = op->dst.pixmap;
+       PixmapPtr src = op->u.blt.src_pixmap;
+       memcpy_xor(src->devPrivate.ptr, dst->devPrivate.ptr,
+                  src->drawable.bitsPerPixel, src->devKind, dst->devKind,
+                  r->src.x + op->u.blt.sx, r->src.y + op->u.blt.sy,
+                  r->dst.x + op->dst.x, r->dst.y + op->dst.y,
+                  r->width, r->height,
+                  0xffffffff, op->u.blt.pixel);
+
+}
+
+fastcall static void
+blt_put_composite_box_with_alpha__cpu(struct sna *sna,
+                                     const struct sna_composite_op *op,
+                                     const BoxRec *box)
+{
+       PixmapPtr dst = op->dst.pixmap;
+       PixmapPtr src = op->u.blt.src_pixmap;
+       memcpy_xor(src->devPrivate.ptr, dst->devPrivate.ptr,
+                  src->drawable.bitsPerPixel, src->devKind, dst->devKind,
+                  box->x1 + op->u.blt.sx, box->y1 + op->u.blt.sy,
+                  box->x1 + op->dst.x, box->y1 + op->dst.y,
+                  box->x2-box->x1, box->y2-box->y1,
+                  0xffffffff, op->u.blt.pixel);
+}
+
+static void
+blt_put_composite_boxes_with_alpha__cpu(struct sna *sna,
+                                       const struct sna_composite_op *op,
+                                       const BoxRec *box, int n)
+{
+       PixmapPtr dst = op->dst.pixmap;
+       PixmapPtr src = op->u.blt.src_pixmap;
+       do {
+               memcpy_xor(src->devPrivate.ptr, dst->devPrivate.ptr,
+                          src->drawable.bitsPerPixel, src->devKind, dst->devKind,
+                          box->x1 + op->u.blt.sx, box->y1 + op->u.blt.sy,
+                          box->x1 + op->dst.x, box->y1 + op->dst.y,
+                          box->x2-box->x1, box->y2-box->y1,
+                          0xffffffff, op->u.blt.pixel);
+               box++;
+       } while (--n);
+}
+
+fastcall static void
+blt_put_composite(struct sna *sna,
+                 const struct sna_composite_op *op,
+                 const struct sna_composite_rectangles *r)
+{
+       PixmapPtr dst = op->dst.pixmap;
+       PixmapPtr src = op->u.blt.src_pixmap;
+       struct sna_pixmap *dst_priv = sna_pixmap(dst);
+       int pitch = src->devKind;
+       char *data = src->devPrivate.ptr;
+       int bpp = src->drawable.bitsPerPixel;
+
+       int16_t dst_x = r->dst.x + op->dst.x;
+       int16_t dst_y = r->dst.y + op->dst.y;
+       int16_t src_x = r->src.x + op->u.blt.sx;
+       int16_t src_y = r->src.y + op->u.blt.sy;
+
+       if (!dst_priv->pinned &&
+           dst_x <= 0 && dst_y <= 0 &&
+           dst_x + r->width >= op->dst.width &&
+           dst_y + r->height >= op->dst.height) {
+               data += (src_x - dst_x) * bpp / 8;
+               data += (src_y - dst_y) * pitch;
+
+               sna_replace(sna, op->dst.pixmap, &dst_priv->gpu_bo,
+                           data, pitch);
+       } else {
+               BoxRec box;
+               bool ok;
+
+               box.x1 = dst_x;
+               box.y1 = dst_y;
+               box.x2 = dst_x + r->width;
+               box.y2 = dst_y + r->height;
+
+               ok = sna_write_boxes(sna, dst,
+                                    dst_priv->gpu_bo, 0, 0,
+                                    data, pitch, src_x, src_y,
+                                    &box, 1);
+               assert(ok);
+       }
+}
+
+fastcall static void blt_put_composite_box(struct sna *sna,
+                                          const struct sna_composite_op *op,
+                                          const BoxRec *box)
+{
+       PixmapPtr src = op->u.blt.src_pixmap;
+       struct sna_pixmap *dst_priv = sna_pixmap(op->dst.pixmap);
+
+       DBG(("%s: src=(%d, %d), dst=(%d, %d)\n", __FUNCTION__,
+            op->u.blt.sx, op->u.blt.sy,
+            op->dst.x, op->dst.y));
+
+       if (!dst_priv->pinned &&
+           box->x2 - box->x1 == op->dst.width &&
+           box->y2 - box->y1 == op->dst.height) {
+               int pitch = src->devKind;
+               int bpp = src->drawable.bitsPerPixel / 8;
+               char *data = src->devPrivate.ptr;
+
+               data += (box->y1 + op->u.blt.sy) * pitch;
+               data += (box->x1 + op->u.blt.sx) * bpp;
+
+               sna_replace(sna, op->dst.pixmap, &dst_priv->gpu_bo,
+                           data, pitch);
+       } else {
+               bool ok;
+
+               ok = sna_write_boxes(sna, op->dst.pixmap,
+                                    op->dst.bo, op->dst.x, op->dst.y,
+                                    src->devPrivate.ptr,
+                                    src->devKind,
+                                    op->u.blt.sx, op->u.blt.sy,
+                                    box, 1);
+               assert(ok);
+       }
+}
+
+static void blt_put_composite_boxes(struct sna *sna,
+                                   const struct sna_composite_op *op,
+                                   const BoxRec *box, int n)
+{
+       PixmapPtr src = op->u.blt.src_pixmap;
+       struct sna_pixmap *dst_priv = sna_pixmap(op->dst.pixmap);
+
+       DBG(("%s: src=(%d, %d), dst=(%d, %d), [(%d, %d), (%d, %d) x %d]\n", __FUNCTION__,
+            op->u.blt.sx, op->u.blt.sy,
+            op->dst.x, op->dst.y,
+            box->x1, box->y1, box->x2, box->y2, n));
+
+       if (n == 1 && !dst_priv->pinned &&
+           box->x2 - box->x1 == op->dst.width &&
+           box->y2 - box->y1 == op->dst.height) {
+               int pitch = src->devKind;
+               int bpp = src->drawable.bitsPerPixel / 8;
+               char *data = src->devPrivate.ptr;
+
+               data += (box->y1 + op->u.blt.sy) * pitch;
+               data += (box->x1 + op->u.blt.sx) * bpp;
+
+               sna_replace(sna, op->dst.pixmap, &dst_priv->gpu_bo,
+                           data, pitch);
+       } else {
+               bool ok;
+
+               ok = sna_write_boxes(sna, op->dst.pixmap,
+                                    op->dst.bo, op->dst.x, op->dst.y,
+                                    src->devPrivate.ptr,
+                                    src->devKind,
+                                    op->u.blt.sx, op->u.blt.sy,
+                                    box, n);
+               assert(ok);
+       }
+}
+
+fastcall static void
+blt_put_composite_with_alpha(struct sna *sna,
+                            const struct sna_composite_op *op,
+                            const struct sna_composite_rectangles *r)
+{
+       PixmapPtr dst = op->dst.pixmap;
+       PixmapPtr src = op->u.blt.src_pixmap;
+       struct sna_pixmap *dst_priv = sna_pixmap(dst);
+       int pitch = src->devKind;
+       char *data = src->devPrivate.ptr;
+
+       int16_t dst_x = r->dst.x + op->dst.x;
+       int16_t dst_y = r->dst.y + op->dst.y;
+       int16_t src_x = r->src.x + op->u.blt.sx;
+       int16_t src_y = r->src.y + op->u.blt.sy;
+
+       if (!dst_priv->pinned &&
+           dst_x <= 0 && dst_y <= 0 &&
+           dst_x + r->width >= op->dst.width &&
+           dst_y + r->height >= op->dst.height) {
+               int bpp = dst->drawable.bitsPerPixel / 8;
+
+               data += (src_x - dst_x) * bpp;
+               data += (src_y - dst_y) * pitch;
+
+               dst_priv->gpu_bo =
+                       sna_replace__xor(sna, op->dst.pixmap, dst_priv->gpu_bo,
+                                        data, pitch,
+                                        0xffffffff, op->u.blt.pixel);
+       } else {
+               BoxRec box;
+
+               box.x1 = dst_x;
+               box.y1 = dst_y;
+               box.x2 = dst_x + r->width;
+               box.y2 = dst_y + r->height;
+
+               sna_write_boxes__xor(sna, dst,
+                                    dst_priv->gpu_bo, 0, 0,
+                                    data, pitch, src_x, src_y,
+                                    &box, 1,
+                                    0xffffffff, op->u.blt.pixel);
+       }
+}
+
+fastcall static void
+blt_put_composite_box_with_alpha(struct sna *sna,
+                                const struct sna_composite_op *op,
+                                const BoxRec *box)
+{
+       PixmapPtr src = op->u.blt.src_pixmap;
+       struct sna_pixmap *dst_priv = sna_pixmap(op->dst.pixmap);
+
+       DBG(("%s: src=(%d, %d), dst=(%d, %d)\n", __FUNCTION__,
+            op->u.blt.sx, op->u.blt.sy,
+            op->dst.x, op->dst.y));
+
+       if (!dst_priv->pinned &&
+           box->x2 - box->x1 == op->dst.width &&
+           box->y2 - box->y1 == op->dst.height) {
+               int pitch = src->devKind;
+               int bpp = src->drawable.bitsPerPixel / 8;
+               char *data = src->devPrivate.ptr;
+
+               data += (box->y1 + op->u.blt.sy) * pitch;
+               data += (box->x1 + op->u.blt.sx) * bpp;
+
+               dst_priv->gpu_bo =
+                       sna_replace__xor(sna, op->dst.pixmap, op->dst.bo,
+                                        data, pitch,
+                                        0xffffffff, op->u.blt.pixel);
+       } else {
+               sna_write_boxes__xor(sna, op->dst.pixmap,
+                                    op->dst.bo, op->dst.x, op->dst.y,
+                                    src->devPrivate.ptr,
+                                    src->devKind,
+                                    op->u.blt.sx, op->u.blt.sy,
+                                    box, 1,
+                                    0xffffffff, op->u.blt.pixel);
+       }
+}
+
+static void
+blt_put_composite_boxes_with_alpha(struct sna *sna,
+                                  const struct sna_composite_op *op,
+                                  const BoxRec *box, int n)
+{
+       PixmapPtr src = op->u.blt.src_pixmap;
+       struct sna_pixmap *dst_priv = sna_pixmap(op->dst.pixmap);
+
+       DBG(("%s: src=(%d, %d), dst=(%d, %d), [(%d, %d), (%d, %d) x %d]\n", __FUNCTION__,
+            op->u.blt.sx, op->u.blt.sy,
+            op->dst.x, op->dst.y,
+            box->x1, box->y1, box->x2, box->y2, n));
+
+       if (n == 1 && !dst_priv->pinned &&
+           box->x2 - box->x1 == op->dst.width &&
+           box->y2 - box->y1 == op->dst.height) {
+               int pitch = src->devKind;
+               int bpp = src->drawable.bitsPerPixel / 8;
+               char *data = src->devPrivate.ptr;
+
+               data += (box->y1 + op->u.blt.sy) * pitch;
+               data += (box->x1 + op->u.blt.sx) * bpp;
+
+               dst_priv->gpu_bo =
+                       sna_replace__xor(sna, op->dst.pixmap, op->dst.bo,
+                                        data, pitch,
+                                        0xffffffff, op->u.blt.pixel);
+       } else {
+               sna_write_boxes__xor(sna, op->dst.pixmap,
+                                    op->dst.bo, op->dst.x, op->dst.y,
+                                    src->devPrivate.ptr,
+                                    src->devKind,
+                                    op->u.blt.sx, op->u.blt.sy,
+                                    box, n,
+                                    0xffffffff, op->u.blt.pixel);
+       }
+}
+
+static bool
+prepare_blt_put(struct sna *sna,
+               struct sna_composite_op *op,
+               uint32_t alpha_fixup)
+{
+       PixmapPtr src = op->u.blt.src_pixmap;
+
+       DBG(("%s\n", __FUNCTION__));
+
+       if (!sna_pixmap_move_to_cpu(src, MOVE_READ))
+               return false;
+
+       assert(src->devKind);
+       assert(src->devPrivate.ptr);
+
+       if (op->dst.bo) {
+               assert(op->dst.bo == sna_pixmap(op->dst.pixmap)->gpu_bo);
+               if (alpha_fixup) {
+                       op->u.blt.pixel = alpha_fixup;
+                       op->blt   = blt_put_composite_with_alpha;
+                       op->box   = blt_put_composite_box_with_alpha;
+                       op->boxes = blt_put_composite_boxes_with_alpha;
+               } else {
+                       op->blt   = blt_put_composite;
+                       op->box   = blt_put_composite_box;
+                       op->boxes = blt_put_composite_boxes;
+               }
+       } else {
+               if (alpha_fixup) {
+                       op->u.blt.pixel = alpha_fixup;
+                       op->blt   = blt_put_composite_with_alpha__cpu;
+                       op->box   = blt_put_composite_box_with_alpha__cpu;
+                       op->boxes = blt_put_composite_boxes_with_alpha__cpu;
+               } else {
+                       op->blt   = blt_put_composite__cpu;
+                       op->box   = blt_put_composite_box__cpu;
+                       op->boxes = blt_put_composite_boxes__cpu;
+               }
+       }
+       op->done = nop_done;
+
+       return true;
+}
+
+static bool source_is_gpu(PixmapPtr pixmap, const BoxRec *box)
+{
+       struct sna_pixmap *priv = sna_pixmap(pixmap);
+       if (priv == NULL)
+               return false;
+       return sna_damage_contains_box(priv->gpu_damage,
+                                      box) != PIXMAN_REGION_OUT;
+}
+
+#define alphaless(format) PICT_FORMAT(PICT_FORMAT_BPP(format),         \
+                                     PICT_FORMAT_TYPE(format),         \
+                                     0,                                \
+                                     PICT_FORMAT_R(format),            \
+                                     PICT_FORMAT_G(format),            \
+                                     PICT_FORMAT_B(format))
+
+bool
+sna_blt_composite(struct sna *sna,
+                 uint32_t op,
+                 PicturePtr src,
+                 PicturePtr dst,
+                 int16_t x, int16_t y,
+                 int16_t dst_x, int16_t dst_y,
+                 int16_t width, int16_t height,
+                 struct sna_composite_op *tmp,
+                 bool fallback)
+{
+       PictFormat src_format = src->format;
+       PixmapPtr src_pixmap;
+       struct kgem_bo *bo;
+       int16_t tx, ty;
+       BoxRec dst_box, src_box;
+       uint32_t alpha_fixup;
+       bool was_clear;
+       bool ret;
+
+#if DEBUG_NO_BLT || NO_BLT_COMPOSITE
+       return false;
+#endif
+
+       DBG(("%s (%d, %d), (%d, %d), %dx%d\n",
+            __FUNCTION__, x, y, dst_x, dst_y, width, height));
+
+       switch (dst->pDrawable->bitsPerPixel) {
+       case 8:
+       case 16:
+       case 32:
+               break;
+       default:
+               DBG(("%s: unhandled bpp: %d\n", __FUNCTION__,
+                    dst->pDrawable->bitsPerPixel));
+               return false;
+       }
+
+       was_clear = sna_drawable_is_clear(dst->pDrawable);
+       tmp->dst.pixmap = get_drawable_pixmap(dst->pDrawable);
+
+       dst_box.x1 = dst_x; dst_box.x2 = dst_x + width;
+       dst_box.y1 = dst_y; dst_box.y2 = dst_y + height;
+       bo = sna_drawable_use_bo(dst->pDrawable, PREFER_GPU, &dst_box, &tmp->damage);
+       if (bo && !kgem_bo_can_blt(&sna->kgem, bo)) {
+               DBG(("%s: can not blit to dst, tiling? %d, pitch? %d\n",
+                    __FUNCTION__, bo->tiling, bo->pitch));
+               return false;
+       }
+
+       tmp->dst.format = dst->format;
+       tmp->dst.width = tmp->dst.pixmap->drawable.width;
+       tmp->dst.height = tmp->dst.pixmap->drawable.height;
+       get_drawable_deltas(dst->pDrawable, tmp->dst.pixmap,
+                           &tmp->dst.x, &tmp->dst.y);
+       tmp->dst.bo = bo;
+
+       if (op == PictOpClear) {
+clear:
+               if (was_clear)
+                       return prepare_blt_nop(sna, tmp);
+
+               if (!tmp->dst.bo) {
+                       RegionRec region;
+
+                       region.extents = dst_box;
+                       region.data = NULL;
+
+                       if (!sna_drawable_move_region_to_cpu(dst->pDrawable, &region,
+                                                            MOVE_INPLACE_HINT | MOVE_WRITE))
+                               return false;
+               }
+               return prepare_blt_clear(sna, tmp);
+       }
+
+       if (is_solid(src)) {
+               if (op == PictOpOver && is_opaque_solid(src))
+                       op = PictOpSrc;
+               if (op == PictOpAdd && is_white(src))
+                       op = PictOpSrc;
+               if (was_clear && (op == PictOpAdd || op == PictOpOver))
+                       op = PictOpSrc;
+               if (op == PictOpOutReverse && is_opaque_solid(src))
+                       goto clear;
+
+               if (op != PictOpSrc) {
+                       DBG(("%s: unsuported op [%d] for blitting\n",
+                            __FUNCTION__, op));
+                       return false;
+               }
+
+               if (!tmp->dst.bo) {
+                       RegionRec region;
+
+                       region.extents = dst_box;
+                       region.data = NULL;
+
+                       if (!sna_drawable_move_region_to_cpu(dst->pDrawable, &region,
+                                                       MOVE_INPLACE_HINT | MOVE_WRITE))
+                               return false;
+               }
+
+               return prepare_blt_fill(sna, tmp, src);
+       }
+
+       if (!src->pDrawable) {
+               DBG(("%s: unsuported procedural source\n",
+                    __FUNCTION__));
+               return false;
+       }
+
+       if (src->filter == PictFilterConvolution) {
+               DBG(("%s: convolutions filters not handled\n",
+                    __FUNCTION__));
+               return false;
+       }
+
+       if (op == PictOpOver && PICT_FORMAT_A(src_format) == 0)
+               op = PictOpSrc;
+
+       if (op != PictOpSrc) {
+               DBG(("%s: unsuported op [%d] for blitting\n",
+                    __FUNCTION__, op));
+               return false;
+       }
+
+       if (!sna_transform_is_integer_translation(src->transform, &tx, &ty)) {
+               DBG(("%s: source transform is not an integer translation\n",
+                    __FUNCTION__));
+               return false;
+       }
+       x += tx;
+       y += ty;
+
+       if ((x >= src->pDrawable->width ||
+            y >= src->pDrawable->height ||
+            x + width <= 0 ||
+            y + height <= 0) &&
+           (!src->repeat || src->repeatType == RepeatNone)) {
+               DBG(("%s: source is outside of valid area, converting to clear\n",
+                    __FUNCTION__));
+               goto clear;
+       }
+
+       alpha_fixup = 0;
+       if (!(dst->format == src_format ||
+             dst->format == alphaless(src_format) ||
+             (alphaless(dst->format) == alphaless(src_format) &&
+              sna_get_pixel_from_rgba(&alpha_fixup,
+                                      0, 0, 0, 0xffff,
+                                      dst->format)))) {
+               DBG(("%s: incompatible src/dst formats src=%08x, dst=%08x\n",
+                    __FUNCTION__, (unsigned)src_format, dst->format));
+               return false;
+       }
+
+       /* XXX tiling? fixup extend none? */
+       if (x < 0 || y < 0 ||
+           x + width > src->pDrawable->width ||
+           y + height > src->pDrawable->height) {
+               DBG(("%s: source extends outside (%d, %d), (%d, %d) of valid drawable %dx%d\n",
+                    __FUNCTION__,
+                    x, y, x+width, y+width, src->pDrawable->width, src->pDrawable->height));
+               return false;
+       }
+
+       src_pixmap = get_drawable_pixmap(src->pDrawable);
+       get_drawable_deltas(src->pDrawable, src_pixmap, &tx, &ty);
+       x += tx + src->pDrawable->x;
+       y += ty + src->pDrawable->y;
+       if (x < 0 || y < 0 ||
+           x + width  > src_pixmap->drawable.width ||
+           y + height > src_pixmap->drawable.height) {
+               DBG(("%s: source extends outside (%d, %d), (%d, %d) of valid pixmap %dx%d\n",
+                    __FUNCTION__,
+                    x, y, x+width, y+width, src_pixmap->drawable.width, src_pixmap->drawable.height));
+               return false;
+       }
+
+       tmp->u.blt.src_pixmap = src_pixmap;
+       tmp->u.blt.sx = x - dst_x;
+       tmp->u.blt.sy = y - dst_y;
+       DBG(("%s: blt dst offset (%d, %d), source offset (%d, %d), with alpha fixup? %x\n",
+            __FUNCTION__,
+            tmp->dst.x, tmp->dst.y, tmp->u.blt.sx, tmp->u.blt.sy, alpha_fixup));
+
+       ret = false;
+       src_box.x1 = x;
+       src_box.y1 = y;
+       src_box.x2 = x + width;
+       src_box.y2 = y + height;
+       bo = NULL;
+       if (tmp->dst.bo || source_is_gpu(src_pixmap, &src_box))
+               bo = __sna_render_pixmap_bo(sna, src_pixmap, &src_box, true);
+       if (bo) {
+               if (!tmp->dst.bo)
+                       tmp->dst.bo = sna_drawable_use_bo(dst->pDrawable,
+                                                         FORCE_GPU | PREFER_GPU,
+                                                         &dst_box,
+                                                         &tmp->damage);
+
+               if (!tmp->dst.bo) {
+                       DBG(("%s: fallback -- unaccelerated read back\n",
+                            __FUNCTION__));
+               } else if (bo->snoop && tmp->dst.bo->snoop) {
+                       DBG(("%s: fallback -- can not copy between snooped bo\n",
+                            __FUNCTION__));
+               } else {
+                       ret = prepare_blt_copy(sna, tmp, bo, alpha_fixup);
+                       if (fallback && !ret)
+                               goto put;
+               }
+       } else {
+put:
+               if (tmp->dst.bo) {
+                       struct sna_pixmap *priv = sna_pixmap(tmp->dst.pixmap);
+                       if (tmp->dst.bo == priv->cpu_bo) {
+                               assert(kgem_bo_is_busy(tmp->dst.bo));
+                               tmp->dst.bo = sna_drawable_use_bo(dst->pDrawable,
+                                                                 FORCE_GPU | PREFER_GPU,
+                                                                 &dst_box,
+                                                                 &tmp->damage);
+                               if (tmp->dst.bo == priv->cpu_bo) {
+                                       DBG(("%s: forcing the stall to overwrite a busy CPU bo\n", __FUNCTION__));
+                                       tmp->dst.bo = NULL;
+                               }
+                       }
+               }
+
+               if (tmp->dst.bo == NULL) {
+                       RegionRec region;
+
+                       region.extents = dst_box;
+                       region.data = NULL;
+
+                       if (!sna_drawable_move_region_to_cpu(dst->pDrawable, &region,
+                                                       MOVE_INPLACE_HINT | MOVE_READ | MOVE_WRITE))
+                               return false;
+               }
+
+               ret = prepare_blt_put(sna, tmp, alpha_fixup);
+       }
+
+       return ret;
+}
+
+static void convert_done(struct sna *sna, const struct sna_composite_op *op)
+{
+       struct kgem *kgem = &sna->kgem;
+
+       if (kgem->gen >= 60 && kgem_check_batch(kgem, 3)) {
+               uint32_t *b = kgem->batch + kgem->nbatch;
+               b[0] = XY_SETUP_CLIP;
+               b[1] = b[2] = 0;
+               kgem->nbatch += 3;
+       }
+
+       kgem_bo_destroy(kgem, op->src.bo);
+       sna_render_composite_redirect_done(sna, op);
+}
+
+bool
+sna_blt_composite__convert(struct sna *sna,
+                          int x, int y,
+                          int width, int height,
+                          struct sna_composite_op *tmp)
+{
+       uint32_t alpha_fixup;
+       uint8_t op;
+
+#if DEBUG_NO_BLT || NO_BLT_COMPOSITE
+       return false;
+#endif
+
+       DBG(("%s src=%d, dst=%d (redirect? %d)\n", __FUNCTION__,
+            tmp->src.bo->handle, tmp->dst.bo->handle,
+            tmp->redirect.real_bo ? tmp->redirect.real_bo->handle : 0));
+
+       if (!kgem_bo_can_blt(&sna->kgem, tmp->dst.bo) ||
+           !kgem_bo_can_blt(&sna->kgem, tmp->src.bo)) {
+               DBG(("%s: cannot blt from src or to dst\n", __FUNCTION__));
+               return false;
+       }
+
+       if (tmp->src.transform) {
+               DBG(("%s: transforms not handled by the BLT\n", __FUNCTION__));
+               return false;
+       }
+
+       if (tmp->src.filter == PictFilterConvolution) {
+               DBG(("%s: convolutions filters not handled\n",
+                    __FUNCTION__));
+               return false;
+       }
+
+       op = tmp->op;
+       if (op == PictOpOver && PICT_FORMAT_A(tmp->src.pict_format) == 0)
+               op = PictOpSrc;
+       if (op != PictOpSrc) {
+               DBG(("%s: unsuported op [%d] for blitting\n",
+                    __FUNCTION__, op));
+               return false;
+       }
+
+       alpha_fixup = 0;
+       if (!(tmp->dst.format == tmp->src.pict_format ||
+             tmp->dst.format == alphaless(tmp->src.pict_format) ||
+             (alphaless(tmp->dst.format) == alphaless(tmp->src.pict_format) &&
+              sna_get_pixel_from_rgba(&alpha_fixup,
+                                      0, 0, 0, 0xffff,
+                                      tmp->dst.format)))) {
+               DBG(("%s: incompatible src/dst formats src=%08x, dst=%08x\n",
+                    __FUNCTION__,
+                    (unsigned)tmp->src.pict_format,
+                    (unsigned)tmp->dst.format));
+               return false;
+       }
+
+       x += tmp->src.offset[0];
+       y += tmp->src.offset[1];
+       if (x < 0 || y < 0 ||
+           x + width  > tmp->src.width ||
+           y + height > tmp->src.height) {
+               DBG(("%s: source extends outside (%d, %d), (%d, %d) of valid drawable %dx%d\n",
+                    __FUNCTION__,
+                    x, y, x+width, y+width, tmp->src.width, tmp->src.height));
+               return false;
+       }
+
+       if (!kgem_check_many_bo_fenced(&sna->kgem, tmp->dst.bo, tmp->src.bo, NULL)) {
+               _kgem_submit(&sna->kgem);
+               if (!kgem_check_many_bo_fenced(&sna->kgem,
+                                              tmp->dst.bo, tmp->src.bo, NULL)) {
+                       DBG(("%s: fallback -- no room in aperture\n", __FUNCTION__));
+                       return false;
+               }
+               _kgem_set_mode(&sna->kgem, KGEM_BLT);
+       }
+
+       tmp->u.blt.src_pixmap = NULL;
+       tmp->u.blt.sx = tmp->src.offset[0];
+       tmp->u.blt.sy = tmp->src.offset[1];
+       DBG(("%s: blt dst offset (%d, %d), source offset (%d, %d), with alpha fixup? %x\n",
+            __FUNCTION__,
+            tmp->dst.x, tmp->dst.y, tmp->u.blt.sx, tmp->u.blt.sy, alpha_fixup));
+
+       if (alpha_fixup) {
+               tmp->blt   = blt_composite_copy_with_alpha;
+               tmp->box   = blt_composite_copy_box_with_alpha;
+               tmp->boxes = blt_composite_copy_boxes_with_alpha;
+
+               if (!sna_blt_alpha_fixup_init(sna, &tmp->u.blt,
+                                             tmp->src.bo, tmp->dst.bo,
+                                             PICT_FORMAT_BPP(tmp->src.pict_format),
+                                             alpha_fixup))
+                       return false;
+       } else {
+               tmp->blt   = blt_composite_copy;
+               tmp->box   = blt_composite_copy_box;
+               tmp->boxes = blt_composite_copy_boxes;
+
+               if (!sna_blt_copy_init(sna, &tmp->u.blt,
+                                      tmp->src.bo, tmp->dst.bo,
+                                      PICT_FORMAT_BPP(tmp->src.pict_format),
+                                      GXcopy))
+                       return false;
+       }
+
+       tmp->done = convert_done;
+       return true;
+}
+
+static void sna_blt_fill_op_blt(struct sna *sna,
+                               const struct sna_fill_op *op,
+                               int16_t x, int16_t y,
+                               int16_t width, int16_t height)
+{
+       sna_blt_fill_one(sna, &op->base.u.blt, x, y, width, height);
+}
+
+fastcall static void sna_blt_fill_op_box(struct sna *sna,
+                                        const struct sna_fill_op *op,
+                                        const BoxRec *box)
+{
+       _sna_blt_fill_box(sna, &op->base.u.blt, box);
+}
+
+fastcall static void sna_blt_fill_op_boxes(struct sna *sna,
+                                          const struct sna_fill_op *op,
+                                          const BoxRec *box,
+                                          int nbox)
+{
+       _sna_blt_fill_boxes(sna, &op->base.u.blt, box, nbox);
+}
+
+static void sna_blt_fill_op_done(struct sna *sna,
+                                const struct sna_fill_op *fill)
+{
+}
+
+bool sna_blt_fill(struct sna *sna, uint8_t alu,
+                 struct kgem_bo *bo, int bpp,
+                 uint32_t pixel,
+                 struct sna_fill_op *fill)
+{
+#if DEBUG_NO_BLT || NO_BLT_FILL
+       return false;
+#endif
+
+       DBG(("%s(alu=%d, pixel=%x, bpp=%d)\n", __FUNCTION__, alu, pixel, bpp));
+
+       if (!kgem_bo_can_blt(&sna->kgem, bo)) {
+               DBG(("%s: rejected due to incompatible Y-tiling\n",
+                    __FUNCTION__));
+               return false;
+       }
+
+       if (!sna_blt_fill_init(sna, &fill->base.u.blt,
+                              bo, bpp, alu, pixel))
+               return false;
+
+       fill->blt   = sna_blt_fill_op_blt;
+       fill->box   = sna_blt_fill_op_box;
+       fill->boxes = sna_blt_fill_op_boxes;
+       fill->done  = sna_blt_fill_op_done;
+       return true;
+}
+
+static void sna_blt_copy_op_blt(struct sna *sna,
+                               const struct sna_copy_op *op,
+                               int16_t src_x, int16_t src_y,
+                               int16_t width, int16_t height,
+                               int16_t dst_x, int16_t dst_y)
+{
+       sna_blt_copy_one(sna, &op->base.u.blt,
+                        src_x, src_y,
+                        width, height,
+                        dst_x, dst_y);
+}
+
+static void sna_blt_copy_op_done(struct sna *sna,
+                                const struct sna_copy_op *op)
+{
+}
+
+static void gen6_blt_copy_op_done(struct sna *sna,
+                                 const struct sna_copy_op *op)
+{
+       gen6_blt_copy_done(sna, &op->base);
+}
+
+bool sna_blt_copy(struct sna *sna, uint8_t alu,
+                 struct kgem_bo *src,
+                 struct kgem_bo *dst,
+                 int bpp,
+                 struct sna_copy_op *op)
+{
+#if DEBUG_NO_BLT || NO_BLT_COPY
+       return false;
+#endif
+
+       if (!kgem_bo_can_blt(&sna->kgem, src))
+               return false;
+
+       if (!kgem_bo_can_blt(&sna->kgem, dst))
+               return false;
+
+       if (!sna_blt_copy_init(sna, &op->base.u.blt,
+                              src, dst,
+                              bpp, alu))
+               return false;
+
+       op->blt  = sna_blt_copy_op_blt;
+       if (sna->kgem.gen >= 60)
+               op->done = gen6_blt_copy_op_done;
+       else
+               op->done = sna_blt_copy_op_done;
+       return true;
+}
+
+static bool sna_blt_fill_box(struct sna *sna, uint8_t alu,
+                            struct kgem_bo *bo, int bpp,
+                            uint32_t color,
+                            const BoxRec *box)
+{
+       struct kgem *kgem = &sna->kgem;
+       uint32_t br13, cmd, *b;
+       bool overwrites;
+
+       assert(kgem_bo_can_blt (kgem, bo));
+
+       DBG(("%s: box=((%d, %d), (%d, %d))\n", __FUNCTION__,
+            box->x1, box->y1, box->x2, box->y2));
+
+       assert(box->x1 >= 0);
+       assert(box->y1 >= 0);
+
+       cmd = XY_COLOR_BLT;
+       br13 = bo->pitch;
+       if (kgem->gen >= 40 && bo->tiling) {
+               cmd |= BLT_DST_TILED;
+               br13 >>= 2;
+       }
+       assert(br13 <= MAXSHORT);
+
+       br13 |= fill_ROP[alu] << 16;
+       switch (bpp) {
+       default: assert(0);
+       case 32: cmd |= BLT_WRITE_ALPHA | BLT_WRITE_RGB;
+                br13 |= 1 << 25; /* RGB8888 */
+       case 16: br13 |= 1 << 24; /* RGB565 */
+       case 8: break;
+       }
+
+       /* All too frequently one blt completely overwrites the previous */
+       overwrites = alu == GXcopy || alu == GXclear || alu == GXset;
+       if (overwrites && kgem->nbatch >= 6 &&
+           kgem->batch[kgem->nbatch-6] == cmd &&
+           *(uint64_t *)&kgem->batch[kgem->nbatch-4] == *(const uint64_t *)box &&
+           kgem->reloc[kgem->nreloc-1].target_handle == bo->handle) {
+               DBG(("%s: replacing last fill\n", __FUNCTION__));
+               kgem->batch[kgem->nbatch-5] = br13;
+               kgem->batch[kgem->nbatch-1] = color;
+               return true;
+       }
+       if (overwrites && kgem->nbatch >= 8 &&
+           (kgem->batch[kgem->nbatch-8] & 0xffc0000f) == XY_SRC_COPY_BLT_CMD &&
+           *(uint64_t *)&kgem->batch[kgem->nbatch-6] == *(const uint64_t *)box &&
+           kgem->reloc[kgem->nreloc-2].target_handle == bo->handle) {
+               DBG(("%s: replacing last copy\n", __FUNCTION__));
+               kgem->batch[kgem->nbatch-8] = cmd;
+               kgem->batch[kgem->nbatch-7] = br13;
+               kgem->batch[kgem->nbatch-3] = color;
+               /* Keep the src bo as part of the execlist, just remove
+                * its relocation entry.
+                */
+               kgem->nreloc--;
+               kgem->nbatch -= 2;
+               return true;
+       }
+
+       /* If we are currently emitting SCANLINES, keep doing so */
+       if (sna->blt_state.fill_bo == bo->unique_id &&
+           sna->blt_state.fill_pixel == color &&
+           (sna->blt_state.fill_alu == alu ||
+            sna->blt_state.fill_alu == ~alu)) {
+               DBG(("%s: matching last fill, converting to scanlines\n",
+                    __FUNCTION__));
+               return false;
+       }
+
+       kgem_set_mode(kgem, KGEM_BLT);
+       if (!kgem_check_batch(kgem, 6) ||
+           !kgem_check_reloc(kgem, 1) ||
+           !kgem_check_bo_fenced(kgem, bo)) {
+               _kgem_submit(kgem);
+               assert(kgem_check_bo_fenced(&sna->kgem, bo));
+               _kgem_set_mode(kgem, KGEM_BLT);
+       }
+
+       b = kgem->batch + kgem->nbatch;
+       b[0] = cmd;
+       b[1] = br13;
+       *(uint64_t *)(b+2) = *(const uint64_t *)box;
+       b[4] = kgem_add_reloc(kgem, kgem->nbatch + 4, bo,
+                             I915_GEM_DOMAIN_RENDER << 16 |
+                             I915_GEM_DOMAIN_RENDER |
+                             KGEM_RELOC_FENCED,
+                             0);
+       b[5] = color;
+       kgem->nbatch += 6;
+
+       sna->blt_state.fill_bo = bo->unique_id;
+       sna->blt_state.fill_pixel = color;
+       sna->blt_state.fill_alu = ~alu;
+       return true;
+}
+
+bool sna_blt_fill_boxes(struct sna *sna, uint8_t alu,
+                       struct kgem_bo *bo, int bpp,
+                       uint32_t pixel,
+                       const BoxRec *box, int nbox)
+{
+       struct kgem *kgem = &sna->kgem;
+       uint32_t br13, cmd;
+
+#if DEBUG_NO_BLT || NO_BLT_FILL_BOXES
+       return false;
+#endif
+
+       DBG(("%s (%d, %08x, %d) x %d\n",
+            __FUNCTION__, bpp, pixel, alu, nbox));
+
+       if (!kgem_bo_can_blt(kgem, bo)) {
+               DBG(("%s: fallback -- dst uses Y-tiling\n", __FUNCTION__));
+               return false;
+       }
+
+       if (alu == GXclear)
+               pixel = 0;
+       else if (alu == GXcopy) {
+               if (pixel == 0)
+                       alu = GXclear;
+               else if (pixel == -1)
+                       alu = GXset;
+       }
+
+       if (nbox == 1 && sna_blt_fill_box(sna, alu, bo, bpp, pixel, box))
+               return true;
+
+       br13 = bo->pitch;
+       cmd = XY_SCANLINE_BLT;
+       if (kgem->gen >= 40 && bo->tiling) {
+               cmd |= 1 << 11;
+               br13 >>= 2;
+       }
+       assert(br13 <= MAXSHORT);
+
+       br13 |= 1<<31 | fill_ROP[alu] << 16;
+       switch (bpp) {
+       default: assert(0);
+       case 32: br13 |= 1 << 25; /* RGB8888 */
+       case 16: br13 |= 1 << 24; /* RGB565 */
+       case 8: break;
+       }
+
+       kgem_set_mode(kgem, KGEM_BLT);
+       if (!kgem_check_bo_fenced(kgem, bo) ||
+           !kgem_check_batch(kgem, 12)) {
+               _kgem_submit(kgem);
+               assert(kgem_check_bo_fenced(&sna->kgem, bo));
+               _kgem_set_mode(kgem, KGEM_BLT);
+       }
+
+       if (sna->blt_state.fill_bo != bo->unique_id ||
+           sna->blt_state.fill_pixel != pixel ||
+           sna->blt_state.fill_alu != alu)
+       {
+               uint32_t *b;
+
+               if (!kgem_check_reloc(kgem, 1)) {
+                       _kgem_submit(kgem);
+                       _kgem_set_mode(kgem, KGEM_BLT);
+               }
+
+               b = kgem->batch + kgem->nbatch;
+               b[0] = XY_SETUP_MONO_PATTERN_SL_BLT;
+               if (bpp == 32)
+                       b[0] |= BLT_WRITE_ALPHA | BLT_WRITE_RGB;
+               b[1] = br13;
+               b[2] = 0;
+               b[3] = 0;
+               b[4] = kgem_add_reloc(kgem, kgem->nbatch + 4, bo,
+                                     I915_GEM_DOMAIN_RENDER << 16 |
+                                     I915_GEM_DOMAIN_RENDER |
+                                     KGEM_RELOC_FENCED,
+                                     0);
+               b[5] = pixel;
+               b[6] = pixel;
+               b[7] = 0;
+               b[8] = 0;
+               kgem->nbatch += 9;
+
+               sna->blt_state.fill_bo = bo->unique_id;
+               sna->blt_state.fill_pixel = pixel;
+               sna->blt_state.fill_alu = alu;
+       }
+
+       do {
+               int nbox_this_time;
+
+               nbox_this_time = nbox;
+               if (3*nbox_this_time > kgem->surface - kgem->nbatch - KGEM_BATCH_RESERVED)
+                       nbox_this_time = (kgem->surface - kgem->nbatch - KGEM_BATCH_RESERVED) / 3;
+               assert(nbox_this_time);
+               nbox -= nbox_this_time;
+
+               do {
+                       uint32_t *b;
+
+                       DBG(("%s: (%d, %d), (%d, %d): %08x\n",
+                            __FUNCTION__,
+                            box->x1, box->y1,
+                            box->x2, box->y2,
+                            pixel));
+
+                       assert(box->x1 >= 0);
+                       assert(box->y1 >= 0);
+                       assert(box->y2 * bo->pitch <= kgem_bo_size(bo));
+
+                       b = kgem->batch + kgem->nbatch;
+                       kgem->nbatch += 3;
+                       b[0] = cmd;
+                       *(uint64_t *)(b+1) = *(const uint64_t *)box;
+                       box++;
+               } while (--nbox_this_time);
+
+               if (nbox) {
+                       uint32_t *b;
+
+                       _kgem_submit(kgem);
+                       _kgem_set_mode(kgem, KGEM_BLT);
+
+                       b = kgem->batch + kgem->nbatch;
+                       b[0] = XY_SETUP_MONO_PATTERN_SL_BLT;
+                       if (bpp == 32)
+                               b[0] |= BLT_WRITE_ALPHA | BLT_WRITE_RGB;
+                       b[1] = br13;
+                       b[2] = 0;
+                       b[3] = 0;
+                       b[4] = kgem_add_reloc(kgem, kgem->nbatch + 4, bo,
+                                             I915_GEM_DOMAIN_RENDER << 16 |
+                                             I915_GEM_DOMAIN_RENDER |
+                                             KGEM_RELOC_FENCED,
+                                             0);
+                       b[5] = pixel;
+                       b[6] = pixel;
+                       b[7] = 0;
+                       b[8] = 0;
+                       kgem->nbatch += 9;
+               }
+       } while (nbox);
+
+       return true;
+}
+
+static inline uint32_t add2(uint32_t v, int16_t x, int16_t y)
+{
+       x += v & 0xffff;
+       y += v >> 16;
+       return (uint16_t)y << 16 | x;
+}
+
+bool sna_blt_copy_boxes(struct sna *sna, uint8_t alu,
+                       struct kgem_bo *src_bo, int16_t src_dx, int16_t src_dy,
+                       struct kgem_bo *dst_bo, int16_t dst_dx, int16_t dst_dy,
+                       int bpp, const BoxRec *box, int nbox)
+{
+       struct kgem *kgem = &sna->kgem;
+       unsigned src_pitch, br13, cmd;
+
+#if DEBUG_NO_BLT || NO_BLT_COPY_BOXES
+       return false;
+#endif
+
+       DBG(("%s src=(%d, %d) -> (%d, %d) x %d, tiling=(%d, %d), pitch=(%d, %d)\n",
+            __FUNCTION__, src_dx, src_dy, dst_dx, dst_dy, nbox,
+           src_bo->tiling, dst_bo->tiling,
+           src_bo->pitch, dst_bo->pitch));
+
+       if (!kgem_bo_can_blt(kgem, src_bo) || !kgem_bo_can_blt(kgem, dst_bo)) {
+               DBG(("%s: cannot blt to src? %d or dst? %d\n",
+                    __FUNCTION__,
+                    kgem_bo_can_blt(kgem, src_bo),
+                    kgem_bo_can_blt(kgem, dst_bo)));
+               return false;
+       }
+
+       cmd = XY_SRC_COPY_BLT_CMD;
+       if (bpp == 32)
+               cmd |= BLT_WRITE_ALPHA | BLT_WRITE_RGB;
+
+       src_pitch = src_bo->pitch;
+       if (kgem->gen >= 40 && src_bo->tiling) {
+               cmd |= BLT_SRC_TILED;
+               src_pitch >>= 2;
+       }
+       assert(src_pitch <= MAXSHORT);
+
+       br13 = dst_bo->pitch;
+       if (kgem->gen >= 40 && dst_bo->tiling) {
+               cmd |= BLT_DST_TILED;
+               br13 >>= 2;
+       }
+       assert(br13 <= MAXSHORT);
+
+       br13 |= copy_ROP[alu] << 16;
+       switch (bpp) {
+       default: assert(0);
+       case 32: br13 |= 1 << 25; /* RGB8888 */
+       case 16: br13 |= 1 << 24; /* RGB565 */
+       case 8: break;
+       }
+
+       /* Compare first box against a previous fill */
+       if (kgem->nbatch >= 6 &&
+           (alu == GXcopy || alu == GXclear || alu == GXset) &&
+           kgem->reloc[kgem->nreloc-1].target_handle == dst_bo->handle &&
+           kgem->batch[kgem->nbatch-6] == ((cmd & ~XY_SRC_COPY_BLT_CMD) | XY_COLOR_BLT) &&
+           kgem->batch[kgem->nbatch-4] == ((uint32_t)(box->y1 + dst_dy) << 16 | (uint16_t)(box->x1 + dst_dx)) &&
+           kgem->batch[kgem->nbatch-3] == ((uint32_t)(box->y2 + dst_dy) << 16 | (uint16_t)(box->x2 + dst_dx))) {
+               DBG(("%s: deleting last fill\n", __FUNCTION__));
+               kgem->nbatch -= 6;
+               kgem->nreloc--;
+       }
+
+       kgem_set_mode(kgem, KGEM_BLT);
+       if (!kgem_check_batch(kgem, 8) ||
+           !kgem_check_reloc(kgem, 2) ||
+           !kgem_check_many_bo_fenced(kgem, dst_bo, src_bo, NULL)) {
+               _kgem_submit(kgem);
+               if (!kgem_check_many_bo_fenced(kgem, dst_bo, src_bo, NULL))
+                       return sna_tiling_blt_copy_boxes(sna, alu,
+                                                        src_bo, src_dx, src_dy,
+                                                        dst_bo, dst_dx, dst_dy,
+                                                        bpp, box, nbox);
+               _kgem_set_mode(kgem, KGEM_BLT);
+       }
+
+       if ((dst_dx | dst_dy) == 0) {
+               uint64_t hdr = (uint64_t)br13 << 32 | cmd;
+               do {
+                       int nbox_this_time;
+
+                       nbox_this_time = nbox;
+                       if (8*nbox_this_time > kgem->surface - kgem->nbatch - KGEM_BATCH_RESERVED)
+                               nbox_this_time = (kgem->surface - kgem->nbatch - KGEM_BATCH_RESERVED) / 8;
+                       if (2*nbox_this_time > KGEM_RELOC_SIZE(kgem) - kgem->nreloc)
+                               nbox_this_time = (KGEM_RELOC_SIZE(kgem) - kgem->nreloc)/2;
+                       assert(nbox_this_time);
+                       nbox -= nbox_this_time;
+
+                       do {
+                               uint32_t *b = kgem->batch + kgem->nbatch;
+
+                               DBG(("  %s: box=(%d, %d)x(%d, %d)\n",
+                                    __FUNCTION__,
+                                    box->x1, box->y1,
+                                    box->x2 - box->x1, box->y2 - box->y1));
+
+                               assert(box->x1 + src_dx >= 0);
+                               assert(box->y1 + src_dy >= 0);
+                               assert(box->x1 + src_dx <= INT16_MAX);
+                               assert(box->y1 + src_dy <= INT16_MAX);
+
+                               assert(box->x1 >= 0);
+                               assert(box->y1 >= 0);
+
+                               *(uint64_t *)&b[0] = hdr;
+                               *(uint64_t *)&b[2] = *(const uint64_t *)box;
+                               b[4] = kgem_add_reloc(kgem, kgem->nbatch + 4, dst_bo,
+                                                     I915_GEM_DOMAIN_RENDER << 16 |
+                                                     I915_GEM_DOMAIN_RENDER |
+                                                     KGEM_RELOC_FENCED,
+                                                     0);
+                               b[5] = add2(b[2], src_dx, src_dy);
+                               b[6] = src_pitch;
+                               b[7] = kgem_add_reloc(kgem, kgem->nbatch + 7, src_bo,
+                                                     I915_GEM_DOMAIN_RENDER << 16 |
+                                                     KGEM_RELOC_FENCED,
+                                                     0);
+                               kgem->nbatch += 8;
+                               box++;
+                       } while (--nbox_this_time);
+
+                       if (!nbox)
+                               break;
+
+                       _kgem_submit(kgem);
+                       _kgem_set_mode(kgem, KGEM_BLT);
+               } while (1);
+       } else {
+               do {
+                       int nbox_this_time;
+
+                       nbox_this_time = nbox;
+                       if (8*nbox_this_time > kgem->surface - kgem->nbatch - KGEM_BATCH_RESERVED)
+                               nbox_this_time = (kgem->surface - kgem->nbatch - KGEM_BATCH_RESERVED) / 8;
+                       if (2*nbox_this_time > KGEM_RELOC_SIZE(kgem) - kgem->nreloc)
+                               nbox_this_time = (KGEM_RELOC_SIZE(kgem) - kgem->nreloc)/2;
+                       assert(nbox_this_time);
+                       nbox -= nbox_this_time;
+
+                       do {
+                               uint32_t *b = kgem->batch + kgem->nbatch;
+
+                               DBG(("  %s: box=(%d, %d)x(%d, %d)\n",
+                                    __FUNCTION__,
+                                    box->x1, box->y1,
+                                    box->x2 - box->x1, box->y2 - box->y1));
+
+                               assert(box->x1 + src_dx >= 0);
+                               assert(box->y1 + src_dy >= 0);
+
+                               assert(box->x1 + dst_dx >= 0);
+                               assert(box->y1 + dst_dy >= 0);
+
+                               b[0] = cmd;
+                               b[1] = br13;
+                               b[2] = ((box->y1 + dst_dy) << 16) | (box->x1 + dst_dx);
+                               b[3] = ((box->y2 + dst_dy) << 16) | (box->x2 + dst_dx);
+                               b[4] = kgem_add_reloc(kgem, kgem->nbatch + 4, dst_bo,
+                                                     I915_GEM_DOMAIN_RENDER << 16 |
+                                                     I915_GEM_DOMAIN_RENDER |
+                                                     KGEM_RELOC_FENCED,
+                                                     0);
+                               b[5] = ((box->y1 + src_dy) << 16) | (box->x1 + src_dx);
+                               b[6] = src_pitch;
+                               b[7] = kgem_add_reloc(kgem, kgem->nbatch + 7, src_bo,
+                                                     I915_GEM_DOMAIN_RENDER << 16 |
+                                                     KGEM_RELOC_FENCED,
+                                                     0);
+                               kgem->nbatch += 8;
+                               box++;
+                       } while (--nbox_this_time);
+
+                       if (!nbox)
+                               break;
+
+                       _kgem_submit(kgem);
+                       _kgem_set_mode(kgem, KGEM_BLT);
+               } while (1);
+       }
+
+       if (kgem->gen >= 60 && kgem_check_batch(kgem, 3)) {
+               uint32_t *b = kgem->batch + kgem->nbatch;
+               b[0] = XY_SETUP_CLIP;
+               b[1] = b[2] = 0;
+               kgem->nbatch += 3;
+       }
+
+       sna->blt_state.fill_bo = 0;
+       return true;
+}
+
+static void box_extents(const BoxRec *box, int n, BoxRec *extents)
+{
+       *extents = *box;
+       while (--n) {
+               box++;
+               if (box->x1 < extents->x1)
+                       extents->x1 = box->x1;
+               if (box->y1 < extents->y1)
+                       extents->y1 = box->y1;
+
+               if (box->x2 > extents->x2)
+                       extents->x2 = box->x2;
+               if (box->y2 > extents->y2)
+                       extents->y2 = box->y2;
+       }
+}
+
+bool sna_blt_copy_boxes_fallback(struct sna *sna, uint8_t alu,
+                                PixmapPtr src, struct kgem_bo *src_bo, int16_t src_dx, int16_t src_dy,
+                                PixmapPtr dst, struct kgem_bo *dst_bo, int16_t dst_dx, int16_t dst_dy,
+                                const BoxRec *box, int nbox)
+{
+       struct kgem_bo *free_bo = NULL;
+       bool ret;
+
+       DBG(("%s: alu=%d, n=%d\n", __FUNCTION__, alu, nbox));
+
+       if (!sna_blt_compare_depth(&src->drawable, &dst->drawable)) {
+               DBG(("%s: mismatching depths %d -> %d\n",
+                    __FUNCTION__, src->drawable.depth, dst->drawable.depth));
+               return false;
+       }
+
+       if (src_bo == dst_bo) {
+               DBG(("%s: dst == src\n", __FUNCTION__));
+
+               if (src_bo->tiling == I915_TILING_Y &&
+                   kgem_bo_blt_pitch_is_ok(&sna->kgem, src_bo)) {
+                       struct kgem_bo *bo;
+
+                       DBG(("%s: src is Y-tiled\n", __FUNCTION__));
+
+                       assert(src_bo == sna_pixmap(src)->gpu_bo);
+                       bo = sna_pixmap_change_tiling(src, I915_TILING_X);
+                       if (bo == NULL) {
+                               BoxRec extents;
+
+                               DBG(("%s: y-tiling conversion failed\n",
+                                    __FUNCTION__));
+
+                               box_extents(box, nbox, &extents);
+                               free_bo = kgem_create_2d(&sna->kgem,
+                                                        extents.x2 - extents.x1,
+                                                        extents.y2 - extents.y1,
+                                                        src->drawable.bitsPerPixel,
+                                                        I915_TILING_X, 0);
+                               if (free_bo == NULL) {
+                                       DBG(("%s: fallback -- temp allocation failed\n",
+                                            __FUNCTION__));
+                                       return false;
+                               }
+
+                               if (!sna_blt_copy_boxes(sna, GXcopy,
+                                                       src_bo, src_dx, src_dy,
+                                                       free_bo, -extents.x1, -extents.y1,
+                                                       src->drawable.bitsPerPixel,
+                                                       box, nbox)) {
+                                       DBG(("%s: fallback -- temp copy failed\n",
+                                            __FUNCTION__));
+                                       kgem_bo_destroy(&sna->kgem, free_bo);
+                                       return false;
+                               }
+
+                               src_dx = -extents.x1;
+                               src_dy = -extents.y1;
+                               src_bo = free_bo;
+                       } else
+                               dst_bo = src_bo = bo;
+               }
+       } else {
+               if (src_bo->tiling == I915_TILING_Y &&
+                   kgem_bo_blt_pitch_is_ok(&sna->kgem, src_bo)) {
+                       DBG(("%s: src is y-tiled\n", __FUNCTION__));
+                       assert(src_bo == sna_pixmap(src)->gpu_bo);
+                       src_bo = sna_pixmap_change_tiling(src, I915_TILING_X);
+                       if (src_bo == NULL) {
+                               DBG(("%s: fallback -- src y-tiling conversion failed\n",
+                                    __FUNCTION__));
+                               return false;
+                       }
+               }
+
+               if (dst_bo->tiling == I915_TILING_Y &&
+                   kgem_bo_blt_pitch_is_ok(&sna->kgem, dst_bo)) {
+                       DBG(("%s: dst is y-tiled\n", __FUNCTION__));
+                       assert(dst_bo == sna_pixmap(dst)->gpu_bo);
+                       dst_bo = sna_pixmap_change_tiling(dst, I915_TILING_X);
+                       if (dst_bo == NULL) {
+                               DBG(("%s: fallback -- dst y-tiling conversion failed\n",
+                                    __FUNCTION__));
+                               return false;
+                       }
+               }
+       }
+
+       ret =  sna_blt_copy_boxes(sna, alu,
+                                 src_bo, src_dx, src_dy,
+                                 dst_bo, dst_dx, dst_dy,
+                                 dst->drawable.bitsPerPixel,
+                                 box, nbox);
+
+       if (free_bo)
+               kgem_bo_destroy(&sna->kgem, free_bo);
+
+       return ret;
+}
diff --git a/src/sna/sna_composite.c b/src/sna/sna_composite.c
new file mode 100644 (file)
index 0000000..60d39cd
--- /dev/null
@@ -0,0 +1,995 @@
+/*
+ * Copyright (c) 2011 Intel 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.
+ *
+ * Authors:
+ *    Chris Wilson <chris@chris-wilson.co.uk>
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "sna.h"
+#include "sna_render.h"
+#include "sna_render_inline.h"
+#include "fb/fbpict.h"
+
+#include <mipict.h>
+
+#define NO_COMPOSITE 0
+#define NO_COMPOSITE_RECTANGLES 0
+
+#define BOUND(v)       (INT16) ((v) < MINSHORT ? MINSHORT : (v) > MAXSHORT ? MAXSHORT : (v))
+
+bool sna_composite_create(struct sna *sna)
+{
+       xRenderColor color ={ 0 };
+       int error;
+
+       if (!can_render(sna))
+               return true;
+
+       sna->clear = CreateSolidPicture(0, &color, &error);
+       return sna->clear != NULL;
+}
+
+void sna_composite_close(struct sna *sna)
+{
+       FreePicture(sna->clear, 0);
+}
+
+static inline bool
+region_is_singular(pixman_region16_t *region)
+{
+       return region->data == NULL;
+}
+
+static inline bool
+region_is_empty(pixman_region16_t *region)
+{
+       return region->data && region->data->numRects == 0;
+}
+
+static inline pixman_bool_t
+clip_to_dst(pixman_region16_t *region,
+           pixman_region16_t *clip,
+           int         dx,
+           int         dy)
+{
+       DBG(("%s: region: %dx[(%d, %d), (%d, %d)], clip: %dx[(%d, %d), (%d, %d)]\n",
+            __FUNCTION__,
+            pixman_region_n_rects(region),
+            region->extents.x1, region->extents.y1,
+            region->extents.x2, region->extents.y2,
+            pixman_region_n_rects(clip),
+            clip->extents.x1, clip->extents.y1,
+            clip->extents.x2, clip->extents.y2));
+
+       if (region_is_singular(region) && region_is_singular(clip)) {
+               pixman_box16_t *r = &region->extents;
+               pixman_box16_t *c = &clip->extents;
+               int v;
+
+               if (r->x1 < (v = c->x1 + dx))
+                       r->x1 = BOUND(v);
+               if (r->x2 > (v = c->x2 + dx))
+                       r->x2 = BOUND(v);
+               if (r->y1 < (v = c->y1 + dy))
+                       r->y1 = BOUND(v);
+               if (r->y2 > (v = c->y2 + dy))
+                       r->y2 = BOUND(v);
+
+               if (r->x1 >= r->x2 || r->y1 >= r->y2) {
+                       pixman_region_init(region);
+                       return FALSE;
+               }
+
+               return true;
+       } else if (region_is_empty(clip)) {
+               return FALSE;
+       } else {
+               if (dx | dy)
+                       pixman_region_translate(region, -dx, -dy);
+               if (!pixman_region_intersect(region, region, clip))
+                       return FALSE;
+               if (dx | dy)
+                       pixman_region_translate(region, dx, dy);
+
+               return !region_is_empty(region);
+       }
+}
+
+static inline bool
+clip_to_src(RegionPtr region, PicturePtr p, int dx, int         dy)
+{
+       bool result;
+
+       if (p->clientClipType == CT_NONE)
+               return true;
+
+       pixman_region_translate(p->clientClip,
+                               p->clipOrigin.x + dx,
+                               p->clipOrigin.y + dy);
+
+       result = RegionIntersect(region, region, p->clientClip);
+
+       pixman_region_translate(p->clientClip,
+                               -(p->clipOrigin.x + dx),
+                               -(p->clipOrigin.y + dy));
+
+       return result && !region_is_empty(region);
+}
+
+bool
+sna_compute_composite_region(RegionPtr region,
+                            PicturePtr src, PicturePtr mask, PicturePtr dst,
+                            INT16 src_x,  INT16 src_y,
+                            INT16 mask_x, INT16 mask_y,
+                            INT16 dst_x,  INT16 dst_y,
+                            CARD16 width, CARD16 height)
+{
+       int v;
+
+       DBG(("%s: dst=(%d, %d)x(%d, %d)\n",
+            __FUNCTION__,
+            dst_x, dst_y,
+            width, height));
+
+       region->extents.x1 = dst_x < 0 ? 0 : dst_x;
+       v = dst_x + width;
+       if (v > dst->pDrawable->width)
+               v = dst->pDrawable->width;
+       region->extents.x2 = v;
+
+       region->extents.y1 = dst_y < 0 ? 0 : dst_y;
+       v = dst_y + height;
+       if (v > dst->pDrawable->height)
+               v = dst->pDrawable->height;
+       region->extents.y2 = v;
+
+       region->data = 0;
+
+       DBG(("%s: initial clip against dst->pDrawable: (%d, %d), (%d, %d)\n",
+            __FUNCTION__,
+            region->extents.x1, region->extents.y1,
+            region->extents.x2, region->extents.y2));
+
+       if (region->extents.x1 >= region->extents.x2 ||
+           region->extents.y1 >= region->extents.y2)
+               return FALSE;
+
+       region->extents.x1 += dst->pDrawable->x;
+       region->extents.x2 += dst->pDrawable->x;
+       region->extents.y1 += dst->pDrawable->y;
+       region->extents.y2 += dst->pDrawable->y;
+
+       dst_x += dst->pDrawable->x;
+       dst_y += dst->pDrawable->y;
+
+       /* clip against dst */
+       if (!clip_to_dst(region, dst->pCompositeClip, 0, 0))
+               return FALSE;
+
+       DBG(("%s: clip against dst->pCompositeClip: (%d, %d), (%d, %d)\n",
+            __FUNCTION__,
+            region->extents.x1, region->extents.y1,
+            region->extents.x2, region->extents.y2));
+
+       if (dst->alphaMap) {
+               if (!clip_to_dst(region, dst->alphaMap->pCompositeClip,
+                                -dst->alphaOrigin.x,
+                                -dst->alphaOrigin.y)) {
+                       pixman_region_fini (region);
+                       return FALSE;
+               }
+       }
+
+       /* clip against src */
+       if (src) {
+               if (src->pDrawable) {
+                       src_x += src->pDrawable->x;
+                       src_y += src->pDrawable->y;
+               }
+               if (!clip_to_src(region, src, dst_x - src_x, dst_y - src_y)) {
+                       pixman_region_fini (region);
+                       return FALSE;
+               }
+               DBG(("%s: clip against src: (%d, %d), (%d, %d)\n",
+                    __FUNCTION__,
+                    region->extents.x1, region->extents.y1,
+                    region->extents.x2, region->extents.y2));
+
+               if (src->alphaMap) {
+                       if (!clip_to_src(region, src->alphaMap,
+                                        dst_x - (src_x - src->alphaOrigin.x),
+                                        dst_y - (src_y - src->alphaOrigin.y))) {
+                               pixman_region_fini(region);
+                               return FALSE;
+                       }
+               }
+       }
+
+       /* clip against mask */
+       if (mask) {
+               if (mask->pDrawable) {
+                       mask_x += mask->pDrawable->x;
+                       mask_y += mask->pDrawable->y;
+               }
+               if (!clip_to_src(region, mask, dst_x - mask_x, dst_y - mask_y)) {
+                       pixman_region_fini(region);
+                       return FALSE;
+               }
+               if (mask->alphaMap) {
+                       if (!clip_to_src(region, mask->alphaMap,
+                                        dst_x - (mask_x - mask->alphaOrigin.x),
+                                        dst_y - (mask_y - mask->alphaOrigin.y))) {
+                               pixman_region_fini(region);
+                               return FALSE;
+                       }
+               }
+
+               DBG(("%s: clip against mask: (%d, %d), (%d, %d)\n",
+                    __FUNCTION__,
+                    region->extents.x1, region->extents.y1,
+                    region->extents.x2, region->extents.y2));
+       }
+
+       return !region_is_empty(region);
+}
+
+static void
+trim_extents(BoxPtr extents, const PicturePtr p, int dx, int dy)
+{
+       const BoxPtr box = REGION_EXTENTS(NULL, p->pCompositeClip);
+
+       DBG(("%s: trim((%d, %d), (%d, %d)) against ((%d, %d), (%d, %d)) + (%d, %d)\n",
+            __FUNCTION__,
+            extents->x1, extents->y1, extents->x2, extents->y2,
+            box->x1, box->y1, box->x2, box->y2,
+            dx, dy));
+
+       if (extents->x1 < box->x1 + dx)
+               extents->x1 = box->x1 + dx;
+       if (extents->x2 > box->x2 + dx)
+               extents->x2 = box->x2 + dx;
+
+       if (extents->y1 < box->y1 + dy)
+               extents->y1 = box->y1 + dy;
+       if (extents->y2 > box->y2 + dy)
+               extents->y2 = box->y2 + dy;
+}
+
+static void
+_trim_source_extents(BoxPtr extents, const PicturePtr p, int dx, int dy)
+{
+       if (p->clientClipType != CT_NONE)
+               trim_extents(extents, p, dx, dy);
+}
+
+static void
+trim_source_extents(BoxPtr extents, const PicturePtr p, int dx, int dy)
+{
+       if (p->pDrawable) {
+               dx += p->pDrawable->x;
+               dy += p->pDrawable->y;
+       }
+       _trim_source_extents(extents, p, dx, dy);
+       if (p->alphaMap)
+               _trim_source_extents(extents, p->alphaMap,
+                                    dx - p->alphaOrigin.x,
+                                    dy - p->alphaOrigin.y);
+
+       DBG(("%s: -> (%d, %d), (%d, %d)\n",
+            __FUNCTION__,
+            extents->x1, extents->y1,
+            extents->x2, extents->y2));
+}
+
+bool
+sna_compute_composite_extents(BoxPtr extents,
+                             PicturePtr src, PicturePtr mask, PicturePtr dst,
+                             INT16 src_x,  INT16 src_y,
+                             INT16 mask_x, INT16 mask_y,
+                             INT16 dst_x,  INT16 dst_y,
+                             CARD16 width, CARD16 height)
+{
+       int v;
+
+       DBG(("%s: dst=(%d, %d)x(%d, %d)\n",
+            __FUNCTION__,
+            dst_x, dst_y,
+            width, height));
+
+       extents->x1 = dst_x < 0 ? 0 : dst_x;
+       v = dst_x + width;
+       if (v > dst->pDrawable->width)
+               v = dst->pDrawable->width;
+       extents->x2 = v;
+
+       extents->y1 = dst_y < 0 ? 0 : dst_y;
+       v = dst_y + height;
+       if (v > dst->pDrawable->height)
+               v = dst->pDrawable->height;
+       extents->y2 = v;
+
+       DBG(("%s: initial clip against dst->pDrawable: (%d, %d), (%d, %d)\n",
+            __FUNCTION__,
+            extents->x1, extents->y1,
+            extents->x2, extents->y2));
+
+       if (extents->x1 >= extents->x2 ||
+           extents->y1 >= extents->y2)
+               return FALSE;
+
+       extents->x1 += dst->pDrawable->x;
+       extents->x2 += dst->pDrawable->x;
+       extents->y1 += dst->pDrawable->y;
+       extents->y2 += dst->pDrawable->y;
+
+       dst_x += dst->pDrawable->x;
+       dst_y += dst->pDrawable->y;
+
+       /* clip against dst */
+       trim_extents(extents, dst, 0, 0);
+       if (dst->alphaMap)
+               trim_extents(extents, dst->alphaMap,
+                            -dst->alphaOrigin.x,
+                            -dst->alphaOrigin.y);
+
+       DBG(("%s: clip against dst: (%d, %d), (%d, %d)\n",
+            __FUNCTION__,
+            extents->x1, extents->y1,
+            extents->x2, extents->y2));
+
+       if (src)
+               trim_source_extents(extents, src, dst_x - src_x, dst_y - src_y);
+       if (mask)
+               trim_source_extents(extents, mask,
+                                   dst_x - mask_x, dst_y - mask_y);
+
+       if (extents->x1 >= extents->x2 || extents->y1 >= extents->y2)
+               return false;
+
+       if (region_is_singular(dst->pCompositeClip))
+               return true;
+
+       return pixman_region_contains_rectangle(dst->pCompositeClip,
+                                               extents) != PIXMAN_REGION_OUT;
+}
+
+#if HAS_DEBUG_FULL
+static void _assert_pixmap_contains_box(PixmapPtr pixmap, BoxPtr box, const char *function)
+{
+       if (box->x1 < 0 || box->y1 < 0 ||
+           box->x2 > pixmap->drawable.width ||
+           box->y2 > pixmap->drawable.height)
+       {
+               ErrorF("%s: damage box is beyond the pixmap: box=(%d, %d), (%d, %d), pixmap=(%d, %d)\n",
+                      __FUNCTION__,
+                      box->x1, box->y1, box->x2, box->y2,
+                      pixmap->drawable.width,
+                      pixmap->drawable.height);
+               assert(0);
+       }
+}
+#define assert_pixmap_contains_box(p, b) _assert_pixmap_contains_box(p, b, __FUNCTION__)
+#else
+#define assert_pixmap_contains_box(p, b)
+#endif
+
+static void apply_damage(struct sna_composite_op *op, RegionPtr region)
+{
+       DBG(("%s: damage=%p, region=%d [(%d, %d), (%d, %d) + (%d, %d)]\n",
+            __FUNCTION__, op->damage, REGION_NUM_RECTS(region),
+            region->extents.x1, region->extents.y1,
+            region->extents.x2, region->extents.y2,
+            op->dst.x, op->dst.y));
+
+       if (op->damage == NULL)
+               return;
+
+       if (op->dst.x | op->dst.y)
+               RegionTranslate(region, op->dst.x, op->dst.y);
+
+       assert_pixmap_contains_box(op->dst.pixmap, RegionExtents(region));
+       if (region->data == NULL &&
+           region->extents.x2 - region->extents.x1 == op->dst.width &&
+           region->extents.y2 - region->extents.y1 == op->dst.height)
+               sna_damage_all(op->damage, op->dst.width, op->dst.height);
+       else
+               sna_damage_add(op->damage, region);
+}
+
+static inline bool use_cpu(PixmapPtr pixmap, struct sna_pixmap *priv,
+                          CARD8 op, INT16 width, INT16 height)
+{
+       if (priv->cpu_bo && kgem_bo_is_busy(priv->cpu_bo))
+               return false;
+
+       if (DAMAGE_IS_ALL(priv->cpu_damage) &&
+           (op > PictOpSrc ||
+            width  < pixmap->drawable.width ||
+            height < pixmap->drawable.height))
+               return true;
+
+       if (priv->gpu_bo)
+               return false;
+
+       return (priv->create & KGEM_CAN_CREATE_GPU) == 0;
+}
+
+void
+sna_composite(CARD8 op,
+             PicturePtr src,
+             PicturePtr mask,
+             PicturePtr dst,
+             INT16 src_x,  INT16 src_y,
+             INT16 mask_x, INT16 mask_y,
+             INT16 dst_x,  INT16 dst_y,
+             CARD16 width, CARD16 height)
+{
+       PixmapPtr pixmap = get_drawable_pixmap(dst->pDrawable);
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+       struct sna_pixmap *priv;
+       struct sna_composite_op tmp;
+       unsigned flags;
+       RegionRec region;
+       int dx, dy;
+
+       DBG(("%s(%d src=(%d, %d), mask=(%d, %d), dst=(%d, %d)+(%d, %d), size=(%d, %d)\n",
+            __FUNCTION__, op,
+            src_x, src_y,
+            mask_x, mask_y,
+            dst_x, dst_y, dst->pDrawable->x, dst->pDrawable->y,
+            width, height));
+
+       if (region_is_empty(dst->pCompositeClip)) {
+               DBG(("%s: empty clip, skipping\n", __FUNCTION__));
+               return;
+       }
+
+       if (op == PictOpClear) {
+               DBG(("%s: discarding source and mask for clear\n", __FUNCTION__));
+               mask = NULL;
+               src = sna->clear;
+       }
+
+       if (mask && sna_composite_mask_is_opaque(mask)) {
+               DBG(("%s: removing opaque %smask\n",
+                    __FUNCTION__,
+                    mask->componentAlpha && PICT_FORMAT_RGB(mask->format) ? "CA " : ""));
+               mask = NULL;
+       }
+
+       if (!sna_compute_composite_region(&region,
+                                         src, mask, dst,
+                                         src_x,  src_y,
+                                         mask_x, mask_y,
+                                         dst_x,  dst_y,
+                                         width,  height))
+               return;
+
+       if (NO_COMPOSITE)
+               goto fallback;
+
+       if (wedged(sna)) {
+               DBG(("%s: fallback -- wedged\n", __FUNCTION__));
+               goto fallback;
+       }
+
+       if (dst->alphaMap) {
+               DBG(("%s: fallback due to unhandled alpha-map\n", __FUNCTION__));
+               goto fallback;
+       }
+
+       priv = sna_pixmap(pixmap);
+       if (priv == NULL) {
+               DBG(("%s: fallback as destination pixmap=%ld is unattached\n",
+                    __FUNCTION__, pixmap->drawable.serialNumber));
+               goto fallback;
+       }
+
+       if (use_cpu(pixmap, priv, op, width, height) &&
+           !picture_is_gpu(src) && !picture_is_gpu(mask)) {
+               DBG(("%s: fallback, dst pixmap=%ld is too small (or completely damaged)\n",
+                    __FUNCTION__, pixmap->drawable.serialNumber));
+               goto fallback;
+       }
+
+       dx = region.extents.x1 - (dst_x + dst->pDrawable->x);
+       dy = region.extents.y1 - (dst_y + dst->pDrawable->y);
+
+       DBG(("%s: composite region extents:+(%d, %d) -> (%d, %d), (%d, %d) + (%d, %d)\n",
+            __FUNCTION__,
+            dx, dy,
+            region.extents.x1, region.extents.y1,
+            region.extents.x2, region.extents.y2,
+            get_drawable_dx(dst->pDrawable),
+            get_drawable_dy(dst->pDrawable)));
+
+       if (op <= PictOpSrc && priv->cpu_damage) {
+               int16_t x, y;
+
+               get_drawable_deltas(dst->pDrawable, pixmap, &x, &y);
+               if (x|y)
+                       pixman_region_translate(&region, x, y);
+
+               sna_damage_subtract(&priv->cpu_damage, &region);
+               if (priv->cpu_damage == NULL) {
+                       list_del(&priv->list);
+                       priv->cpu = false;
+               }
+
+               if (x|y)
+                       pixman_region_translate(&region, -x, -y);
+       }
+
+       if (!sna->render.composite(sna,
+                                  op, src, mask, dst,
+                                  src_x + dx,  src_y + dy,
+                                  mask_x + dx, mask_y + dy,
+                                  region.extents.x1,
+                                  region.extents.y1,
+                                  region.extents.x2 - region.extents.x1,
+                                  region.extents.y2 - region.extents.y1,
+                                  memset(&tmp, 0, sizeof(tmp)))) {
+               DBG(("%s: fallback due unhandled composite op\n", __FUNCTION__));
+               goto fallback;
+       }
+
+       if (region.data == NULL)
+               tmp.box(sna, &tmp, &region.extents);
+       else
+               tmp.boxes(sna, &tmp,
+                         REGION_BOXPTR(&region),
+                         REGION_NUM_RECTS(&region));
+       apply_damage(&tmp, &region);
+       tmp.done(sna, &tmp);
+
+       goto out;
+
+fallback:
+       DBG(("%s -- fallback dst=(%d, %d)+(%d, %d), size=(%d, %d): region=((%d,%d), (%d, %d))\n",
+            __FUNCTION__,
+            dst_x, dst_y,
+            dst->pDrawable->x, dst->pDrawable->y,
+            width, height,
+            region.extents.x1, region.extents.y1,
+            region.extents.x2, region.extents.y2));
+       if (op <= PictOpSrc && !dst->alphaMap)
+               flags = MOVE_WRITE | MOVE_INPLACE_HINT;
+       else
+               flags = MOVE_WRITE | MOVE_READ;
+       DBG(("%s: fallback -- move dst to cpu\n", __FUNCTION__));
+       if (!sna_drawable_move_region_to_cpu(dst->pDrawable, &region, flags))
+               goto out;
+       if (dst->alphaMap &&
+           !sna_drawable_move_to_cpu(dst->alphaMap->pDrawable, flags))
+               goto out;
+       if (src->pDrawable) {
+               DBG(("%s: fallback -- move src to cpu\n", __FUNCTION__));
+               if (!sna_drawable_move_to_cpu(src->pDrawable,
+                                             MOVE_READ))
+                       goto out;
+
+               if (src->alphaMap &&
+                   !sna_drawable_move_to_cpu(src->alphaMap->pDrawable,
+                                             MOVE_READ))
+                       goto out;
+       }
+       if (mask && mask->pDrawable) {
+               DBG(("%s: fallback -- move mask to cpu\n", __FUNCTION__));
+               if (!sna_drawable_move_to_cpu(mask->pDrawable,
+                                             MOVE_READ))
+                       goto out;
+
+               if (mask->alphaMap &&
+                   !sna_drawable_move_to_cpu(mask->alphaMap->pDrawable,
+                                             MOVE_READ))
+                       goto out;
+       }
+
+       DBG(("%s: fallback -- fbComposite\n", __FUNCTION__));
+       fbComposite(op, src, mask, dst,
+                   src_x,  src_y,
+                   mask_x, mask_y,
+                   dst_x,  dst_y,
+                   width,  height);
+out:
+       REGION_UNINIT(NULL, &region);
+}
+
+static int16_t bound(int16_t a, uint16_t b)
+{
+       int v = (int)a + (int)b;
+       if (v > MAXSHORT)
+               return MAXSHORT;
+       return v;
+}
+
+static bool
+_pixman_region_init_clipped_rectangles(pixman_region16_t *region,
+                                      unsigned int num_rects,
+                                      xRectangle *rects,
+                                      int tx, int ty,
+                                      BoxPtr extents)
+{
+       pixman_box16_t stack_boxes[64], *boxes = stack_boxes;
+       pixman_bool_t ret;
+       unsigned int i, j;
+
+       if (num_rects > ARRAY_SIZE(stack_boxes)) {
+               boxes = malloc(sizeof(pixman_box16_t) * num_rects);
+               if (boxes == NULL)
+                       return FALSE;
+       }
+
+       for (i = j = 0; i < num_rects; i++) {
+               boxes[j].x1 = rects[i].x + tx;
+               if (boxes[j].x1 < extents->x1)
+                       boxes[j].x1 = extents->x1;
+
+               boxes[j].y1 = rects[i].y + ty;
+               if (boxes[j].y1 < extents->y1)
+                       boxes[j].y1 = extents->y1;
+
+               boxes[j].x2 = bound(rects[i].x + tx, rects[i].width);
+               if (boxes[j].x2 > extents->x2)
+                       boxes[j].x2 = extents->x2;
+
+               boxes[j].y2 = bound(rects[i].y + ty, rects[i].height);
+               if (boxes[j].y2 > extents->y2)
+                       boxes[j].y2 = extents->y2;
+
+               if (boxes[j].x2 > boxes[j].x1 && boxes[j].y2 > boxes[j].y1)
+                       j++;
+       }
+
+       ret = FALSE;
+       if (j)
+           ret = pixman_region_init_rects(region, boxes, j);
+
+       if (boxes != stack_boxes)
+               free(boxes);
+
+       DBG(("%s: nrects=%d, region=(%d, %d), (%d, %d) x %d\n",
+            __FUNCTION__, num_rects,
+            region->extents.x1, region->extents.y1,
+            region->extents.x2, region->extents.y2,
+            j));
+       return ret;
+}
+
+void
+sna_composite_rectangles(CARD8          op,
+                        PicturePtr      dst,
+                        xRenderColor   *color,
+                        int             num_rects,
+                        xRectangle     *rects)
+{
+       struct sna *sna = to_sna_from_drawable(dst->pDrawable);
+       PixmapPtr pixmap;
+       struct sna_pixmap *priv;
+       struct kgem_bo *bo;
+       struct sna_damage **damage;
+       pixman_region16_t region;
+       pixman_box16_t *boxes;
+       int16_t dst_x, dst_y;
+       int num_boxes, error;
+       unsigned hint;
+
+       DBG(("%s(op=%d, %08x x %d [(%d, %d)x(%d, %d) ...])\n",
+            __FUNCTION__, op,
+            (color->alpha >> 8 << 24) |
+            (color->red   >> 8 << 16) |
+            (color->green >> 8 << 8) |
+            (color->blue  >> 8 << 0),
+            num_rects,
+            rects[0].x, rects[0].y, rects[0].width, rects[0].height));
+
+       if (!num_rects)
+               return;
+
+       if (region_is_empty(dst->pCompositeClip)) {
+               DBG(("%s: empty clip, skipping\n", __FUNCTION__));
+               return;
+       }
+
+       if ((color->red|color->green|color->blue|color->alpha) <= 0x00ff) {
+               switch (op) {
+               case PictOpOver:
+               case PictOpOutReverse:
+               case PictOpAdd:
+                       return;
+               case  PictOpInReverse:
+               case  PictOpSrc:
+                       op = PictOpClear;
+                       break;
+               case  PictOpAtopReverse:
+                       op = PictOpOut;
+                       break;
+               case  PictOpXor:
+                       op = PictOpOverReverse;
+                       break;
+               }
+       }
+       if (color->alpha <= 0x00ff) {
+               switch (op) {
+               case PictOpOver:
+               case PictOpOutReverse:
+                       return;
+               case  PictOpInReverse:
+                       op = PictOpClear;
+                       break;
+               case  PictOpAtopReverse:
+                       op = PictOpOut;
+                       break;
+               case  PictOpXor:
+                       op = PictOpOverReverse;
+                       break;
+               }
+       } else if (color->alpha >= 0xff00) {
+               switch (op) {
+               case PictOpOver:
+                       op = PictOpSrc;
+                       break;
+               case PictOpInReverse:
+                       return;
+               case PictOpOutReverse:
+                       op = PictOpClear;
+                       break;
+               case  PictOpAtopReverse:
+                       op = PictOpOverReverse;
+                       break;
+               case  PictOpXor:
+                       op = PictOpOut;
+                       break;
+               }
+       }
+       DBG(("%s: converted to op %d\n", __FUNCTION__, op));
+
+       if (!_pixman_region_init_clipped_rectangles(&region,
+                                                   num_rects, rects,
+                                                   dst->pDrawable->x,
+                                                   dst->pDrawable->y,
+                                                   &dst->pCompositeClip->extents))
+       {
+               DBG(("%s: allocation failed for region\n", __FUNCTION__));
+               return;
+       }
+
+       DBG(("%s: drawable extents (%d, %d),(%d, %d) x %d\n",
+            __FUNCTION__,
+            RegionExtents(&region)->x1, RegionExtents(&region)->y1,
+            RegionExtents(&region)->x2, RegionExtents(&region)->y2,
+            RegionNumRects(&region)));
+
+       if (dst->pCompositeClip->data &&
+           (!pixman_region_intersect(&region, &region, dst->pCompositeClip) ||
+            region_is_empty(&region))) {
+               DBG(("%s: zero-intersection between rectangles and clip\n",
+                    __FUNCTION__));
+               pixman_region_fini(&region);
+               return;
+       }
+
+       DBG(("%s: clipped extents (%d, %d),(%d, %d) x %d\n",
+            __FUNCTION__,
+            RegionExtents(&region)->x1, RegionExtents(&region)->y1,
+            RegionExtents(&region)->x2, RegionExtents(&region)->y2,
+            RegionNumRects(&region)));
+
+       pixmap = get_drawable_pixmap(dst->pDrawable);
+       get_drawable_deltas(dst->pDrawable, pixmap, &dst_x, &dst_y);
+       pixman_region_translate(&region, dst_x, dst_y);
+
+       DBG(("%s: pixmap +(%d, %d) extents (%d, %d),(%d, %d)\n",
+            __FUNCTION__, dst_x, dst_y,
+            RegionExtents(&region)->x1, RegionExtents(&region)->y1,
+            RegionExtents(&region)->x2, RegionExtents(&region)->y2));
+       assert_pixmap_contains_box(pixmap, RegionExtents(&region));
+
+       if (NO_COMPOSITE_RECTANGLES)
+               goto fallback;
+
+       if (wedged(sna))
+               goto fallback;
+
+       if (dst->alphaMap) {
+               DBG(("%s: fallback, dst has an alpha-map\n", __FUNCTION__));
+               goto fallback;
+       }
+
+       priv = sna_pixmap(pixmap);
+       if (priv == NULL || too_small(priv)) {
+               DBG(("%s: fallback, dst pixmap=%ld too small or not attached\n",
+                    __FUNCTION__, pixmap->drawable.serialNumber));
+               goto fallback;
+       }
+
+       boxes = pixman_region_rectangles(&region, &num_boxes);
+
+       /* If we going to be overwriting any CPU damage with a subsequent
+        * operation, then we may as well delete it without moving it
+        * first to the GPU.
+        */
+       hint = PREFER_GPU;
+       if (op <= PictOpSrc) {
+               if (priv->cpu_damage &&
+                   region_subsumes_damage(&region, priv->cpu_damage)) {
+                       DBG(("%s: discarding existing CPU damage\n", __FUNCTION__));
+                       if (priv->gpu_bo && priv->gpu_bo->proxy) {
+                               kgem_bo_destroy(&sna->kgem, priv->gpu_bo);
+                               priv->gpu_bo = NULL;
+                       }
+                       sna_damage_destroy(&priv->cpu_damage);
+                       list_del(&priv->list);
+               }
+               if (region_subsumes_drawable(&region, &pixmap->drawable) ||
+                   box_inplace(pixmap, &region.extents)) {
+                       DBG(("%s: promoting to full GPU\n", __FUNCTION__));
+                       if (priv->gpu_bo && priv->cpu_damage == NULL) {
+                               sna_damage_all(&priv->gpu_damage,
+                                              pixmap->drawable.width,
+                                              pixmap->drawable.height);
+                               priv->undamaged = false;
+                       }
+               }
+               if (priv->cpu_damage == NULL) {
+                       DBG(("%s: dropping last-cpu hint\n", __FUNCTION__));
+                       priv->cpu = false;
+               }
+
+               if (region.data == NULL)
+                       hint |= IGNORE_CPU;
+       }
+
+       bo = sna_drawable_use_bo(&pixmap->drawable, hint,
+                                &region.extents, &damage);
+       if (bo == NULL) {
+               DBG(("%s: fallback due to no GPU bo\n", __FUNCTION__));
+               goto fallback;
+       }
+
+       if (!sna->render.fill_boxes(sna, op, dst->format, color,
+                                   pixmap, bo, boxes, num_boxes)) {
+               DBG(("%s: fallback - acceleration failed\n", __FUNCTION__));
+               goto fallback;
+       }
+
+       if (damage)
+               sna_damage_add(damage, &region);
+
+       /* Clearing a pixmap after creation is a common operation, so take
+        * advantage and reduce further damage operations.
+        */
+       if (region_subsumes_drawable(&region, &pixmap->drawable)) {
+               if (damage) {
+                       sna_damage_all(damage,
+                                      pixmap->drawable.width,
+                                      pixmap->drawable.height);
+                       sna_damage_destroy(damage == &priv->gpu_damage ?
+                                          &priv->cpu_damage : &priv->gpu_damage);
+                       priv->undamaged = false;
+               }
+
+               if (op <= PictOpSrc && bo == priv->gpu_bo) {
+                       bool ok;
+
+                       assert(DAMAGE_IS_ALL(priv->gpu_damage));
+
+                       priv->clear_color = 0;
+                       ok = true;
+                       if (op == PictOpSrc)
+                               ok = sna_get_pixel_from_rgba(&priv->clear_color,
+                                                            color->red,
+                                                            color->green,
+                                                            color->blue,
+                                                            color->alpha,
+                                                            dst->format);
+                       priv->clear = ok;
+                       DBG(("%s: marking clear [%08x]? %d\n",
+                            __FUNCTION__, priv->clear_color, ok));
+               }
+       }
+       goto done;
+
+fallback:
+       DBG(("%s: fallback\n", __FUNCTION__));
+       if (op <= PictOpSrc)
+               error = MOVE_WRITE;
+       else
+               error = MOVE_WRITE | MOVE_READ;
+       if (!sna_drawable_move_region_to_cpu(&pixmap->drawable, &region, error))
+               goto done;
+
+       if (dst->alphaMap &&
+           !sna_drawable_move_to_cpu(dst->alphaMap->pDrawable, error))
+               goto done;
+
+       if (op <= PictOpSrc) {
+               int nbox = REGION_NUM_RECTS(&region);
+               BoxPtr box = REGION_RECTS(&region);
+               uint32_t pixel;
+
+               if (op == PictOpClear)
+                       pixel = 0;
+               else if (!sna_get_pixel_from_rgba(&pixel,
+                                                 color->red,
+                                                 color->green,
+                                                 color->blue,
+                                                 color->alpha,
+                                                 dst->format))
+                       goto fallback_composite;
+
+               if (pixel == 0 &&
+                   box->x2 - box->x1 == pixmap->drawable.width &&
+                   box->y2 - box->y1 == pixmap->drawable.height) {
+                       memset(pixmap->devPrivate.ptr, 0,
+                              pixmap->devKind*pixmap->drawable.height);
+               } else do {
+                       DBG(("%s: fallback fill: (%d, %d)x(%d, %d) %08x\n",
+                            __FUNCTION__,
+                            box->x1, box->y1,
+                            box->x2 - box->x1,
+                            box->y2 - box->y1,
+                            pixel));
+
+                       pixman_fill(pixmap->devPrivate.ptr,
+                                   pixmap->devKind/sizeof(uint32_t),
+                                   pixmap->drawable.bitsPerPixel,
+                                   box->x1, box->y1,
+                                   box->x2 - box->x1,
+                                   box->y2 - box->y1,
+                                   pixel);
+                       box++;
+               } while (--nbox);
+       } else {
+               PicturePtr src;
+
+fallback_composite:
+               DBG(("%s: fallback -- fbComposite()\n", __FUNCTION__));
+               src = CreateSolidPicture(0, color, &error);
+               if (src) {
+                       do {
+                               fbComposite(op, src, NULL, dst,
+                                           0, 0,
+                                           0, 0,
+                                           rects->x, rects->y,
+                                           rects->width, rects->height);
+                               rects++;
+                       } while (--num_rects);
+                       FreePicture(src, 0);
+               }
+       }
+
+done:
+       /* XXX xserver-1.8: CompositeRects is not tracked by Damage, so we must
+        * manually append the damaged regions ourselves.
+        */
+       DamageRegionAppend(&pixmap->drawable, &region);
+       DamageRegionProcessPending(&pixmap->drawable);
+
+       pixman_region_fini(&region);
+       return;
+}
diff --git a/src/sna/sna_damage.c b/src/sna/sna_damage.c
new file mode 100644 (file)
index 0000000..d726b61
--- /dev/null
@@ -0,0 +1,1763 @@
+/**************************************************************************
+
+Copyright (c) 2011 Intel 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, sub license, 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 NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS 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_CONFIG_H
+#include "config.h"
+#endif
+
+#include "sna.h"
+#include "sna_damage.h"
+
+/*
+ * sna_damage is a batching layer on top of the regular pixman_region_t.
+ * It is required as the ever-growing accumulation of invidual small
+ * damage regions is an O(n^2) operation. Instead the accumulation of a
+ * batch can be done in closer to O(n.lgn), and so prevents abysmal
+ * performance in x11perf -copywinwin10.
+ *
+ * As with the core of SNA, damage is handled modally. That is, it
+ * accumulates whilst rendering and then subtracts during migration of the
+ * pixmap from GPU to CPU or vice versa. As such we can track the current
+ * mode globally and when that mode switches perform the update of the region
+ * in a single operation.
+ *
+ * Furthermore, we can track whether the whole pixmap is damaged and so
+ * cheapy discard no-ops.
+ */
+
+struct sna_damage_box {
+       struct list list;
+       int size;
+} __attribute__((packed));
+
+static struct sna_damage *__freed_damage;
+
+static inline bool region_is_singular(RegionRec *r)
+{
+       return r->data == NULL;
+}
+
+#if HAS_DEBUG_FULL
+static const char *_debug_describe_region(char *buf, int max,
+                                         RegionPtr region)
+{
+       BoxPtr extents;
+       BoxPtr box;
+       int n;
+       int len;
+
+       if (region == NULL)
+               return "nil";
+
+       n = REGION_NUM_RECTS(region);
+       if (n == 0)
+               return "[0]";
+
+       extents = REGION_EXTENTS(NULL, region);
+       if (n == 1) {
+               sprintf(buf,
+                       "[(%d, %d), (%d, %d)]",
+                       extents->x1, extents->y1,
+                       extents->x2, extents->y2);
+               return buf;
+       }
+
+       len = sprintf(buf,
+                     "[(%d, %d), (%d, %d) x %d: ",
+                     extents->x1, extents->y1,
+                     extents->x2, extents->y2,
+                     n) + 3;
+       max -= 2;
+       box = REGION_RECTS(region);
+       while (n--) {
+               char tmp[80];
+               int this;
+
+               this = snprintf(tmp, sizeof(tmp),
+                               "((%d, %d), (%d, %d))%s",
+                               box->x1, box->y1,
+                               box->x2, box->y2,
+                               n ? ", ..." : "");
+               box++;
+
+               if (this > max - len)
+                       break;
+
+               len -= 3;
+               memcpy(buf + len, tmp, this);
+               len += this;
+       }
+       buf[len++] = ']';
+       buf[len] = '\0';
+       return buf;
+}
+
+static const char *_debug_describe_damage(char *buf, int max,
+                                         struct sna_damage *damage)
+{
+       char damage_str[500], region_str[500];
+       int str_max;
+
+       if (damage == NULL)
+               return "None";
+
+       str_max = max/2 - 6;
+       if (str_max > sizeof(damage_str))
+               str_max = sizeof(damage_str);
+
+       if (damage->mode == DAMAGE_ALL) {
+               snprintf(buf, max, "[[(%d, %d), (%d, %d)]: all]",
+                        damage->extents.x1, damage->extents.y1,
+                        damage->extents.x2, damage->extents.y2);
+       } else {
+               if (damage->dirty) {
+                       sprintf(damage_str, "%c[ ...]",
+                               damage->mode == DAMAGE_SUBTRACT ? '-' : '+');
+               } else
+                       damage_str[0] = '\0';
+               snprintf(buf, max, "[[(%d, %d), (%d, %d)]: %s %s]%c",
+                        damage->extents.x1, damage->extents.y1,
+                        damage->extents.x2, damage->extents.y2,
+                        _debug_describe_region(region_str, str_max,
+                                               &damage->region),
+                        damage_str, damage->dirty ? '*' : ' ');
+       }
+
+       return buf;
+}
+#endif
+
+static void
+reset_embedded_box(struct sna_damage *damage)
+{
+       damage->dirty = false;
+       damage->box = damage->embedded_box.box;
+       damage->embedded_box.size =
+               damage->remain = ARRAY_SIZE(damage->embedded_box.box);
+       list_init(&damage->embedded_box.list);
+}
+
+static void reset_extents(struct sna_damage *damage)
+{
+       damage->extents.x1 = damage->extents.y1 = MAXSHORT;
+       damage->extents.x2 = damage->extents.y2 = MINSHORT;
+}
+
+static struct sna_damage *_sna_damage_create(void)
+{
+       struct sna_damage *damage;
+
+       if (__freed_damage) {
+               damage = __freed_damage;
+               __freed_damage = *(void **)__freed_damage;
+       } else {
+               damage = malloc(sizeof(*damage));
+               if (damage == NULL)
+                       return NULL;
+       }
+       reset_embedded_box(damage);
+       damage->mode = DAMAGE_ADD;
+       pixman_region_init(&damage->region);
+       reset_extents(damage);
+
+       return damage;
+}
+
+struct sna_damage *sna_damage_create(void)
+{
+       return _sna_damage_create();
+}
+
+static bool _sna_damage_create_boxes(struct sna_damage *damage,
+                                    int count)
+{
+       struct sna_damage_box *box;
+       int n;
+
+       box = list_entry(damage->embedded_box.list.prev,
+                        struct sna_damage_box,
+                        list);
+       n = 4*box->size;
+       if (n < count)
+               n = ALIGN(count, 64);
+
+       DBG(("    %s(%d->%d): new\n", __FUNCTION__, count, n));
+
+       box = malloc(sizeof(*box) + sizeof(BoxRec)*n);
+       if (box == NULL)
+               return false;
+
+       list_add_tail(&box->list, &damage->embedded_box.list);
+
+       box->size = damage->remain = n;
+       damage->box = (BoxRec *)(box + 1);
+       return true;
+}
+
+static struct sna_damage *
+_sna_damage_create_elt(struct sna_damage *damage,
+                      const BoxRec *boxes, int count)
+{
+       int n;
+
+       DBG(("    %s: prev=(remain %d), count=%d\n",
+            __FUNCTION__, damage->remain, count));
+
+       damage->dirty = true;
+       n = count;
+       if (n > damage->remain)
+               n = damage->remain;
+       if (n) {
+               memcpy(damage->box, boxes, n * sizeof(BoxRec));
+               damage->box += n;
+               damage->remain -= n;
+
+               count -= n;
+               boxes += n;
+               if (count == 0)
+                       return damage;
+       }
+
+       DBG(("    %s(): new elt\n", __FUNCTION__));
+
+       if (_sna_damage_create_boxes(damage, count)) {
+               memcpy(damage->box, boxes, count * sizeof(BoxRec));
+               damage->box += count;
+               damage->remain -= count;
+       }
+       assert(damage->remain >= 0);
+
+       return damage;
+}
+
+static struct sna_damage *
+_sna_damage_create_elt_from_boxes(struct sna_damage *damage,
+                                 const BoxRec *boxes, int count,
+                                 int16_t dx, int16_t dy)
+{
+       int i, n;
+
+       DBG(("    %s: prev=(remain %d)\n", __FUNCTION__, damage->remain));
+
+       damage->dirty = true;
+       n = count;
+       if (n > damage->remain)
+               n = damage->remain;
+       if (n) {
+               for (i = 0; i < n; i++) {
+                       damage->box[i].x1 = boxes[i].x1 + dx;
+                       damage->box[i].x2 = boxes[i].x2 + dx;
+                       damage->box[i].y1 = boxes[i].y1 + dy;
+                       damage->box[i].y2 = boxes[i].y2 + dy;
+               }
+               damage->box += n;
+               damage->remain -= n;
+
+               count -= n;
+               boxes += n;
+               if (count == 0)
+                       return damage;
+       }
+
+       DBG(("    %s(): new elt\n", __FUNCTION__));
+
+       if (!_sna_damage_create_boxes(damage, count))
+               return damage;
+
+       for (i = 0; i < count; i++) {
+               damage->box[i].x1 = boxes[i].x1 + dx;
+               damage->box[i].x2 = boxes[i].x2 + dx;
+               damage->box[i].y1 = boxes[i].y1 + dy;
+               damage->box[i].y2 = boxes[i].y2 + dy;
+       }
+       damage->box += count;
+       damage->remain -= count;
+       assert(damage->remain >= 0);
+
+       return damage;
+}
+
+static struct sna_damage *
+_sna_damage_create_elt_from_rectangles(struct sna_damage *damage,
+                                      const xRectangle *r, int count,
+                                      int16_t dx, int16_t dy)
+{
+       int i, n;
+
+       DBG(("    %s: prev=(remain %d), count=%d\n",
+            __FUNCTION__, damage->remain, count));
+
+       damage->dirty = true;
+       n = count;
+       if (n > damage->remain)
+               n = damage->remain;
+       if (n) {
+               for (i = 0; i < n; i++) {
+                       damage->box[i].x1 = r[i].x + dx;
+                       damage->box[i].x2 = damage->box[i].x1 + r[i].width;
+                       damage->box[i].y1 = r[i].y + dy;
+                       damage->box[i].y2 = damage->box[i].y1 + r[i].height;
+               }
+               damage->box += n;
+               damage->remain -= n;
+
+               count -= n;
+               r += n;
+               if (count == 0)
+                       return damage;
+       }
+
+       DBG(("    %s(): new elt\n", __FUNCTION__));
+
+       if (!_sna_damage_create_boxes(damage, count))
+               return damage;
+
+       for (i = 0; i < count; i++) {
+               damage->box[i].x1 = r[i].x + dx;
+               damage->box[i].x2 = damage->box[i].x1 + r[i].width;
+               damage->box[i].y1 = r[i].y + dy;
+               damage->box[i].y2 = damage->box[i].y1 + r[i].height;
+       }
+       damage->box += count;
+       damage->remain -= count;
+       assert(damage->remain >= 0);
+
+       return damage;
+}
+
+static struct sna_damage *
+_sna_damage_create_elt_from_points(struct sna_damage *damage,
+                                  const DDXPointRec *p, int count,
+                                  int16_t dx, int16_t dy)
+{
+       int i, n;
+
+       DBG(("    %s: prev=(remain %d), count=%d\n",
+            __FUNCTION__, damage->remain, count));
+
+       damage->dirty = true;
+       n = count;
+       if (n > damage->remain)
+               n = damage->remain;
+       if (n) {
+               for (i = 0; i < n; i++) {
+                       damage->box[i].x1 = p[i].x + dx;
+                       damage->box[i].x2 = damage->box[i].x1 + 1;
+                       damage->box[i].y1 = p[i].y + dy;
+                       damage->box[i].y2 = damage->box[i].y1 + 1;
+               }
+               damage->box += n;
+               damage->remain -= n;
+
+               count -= n;
+               p += n;
+               if (count == 0)
+                       return damage;
+       }
+
+       DBG(("    %s(): new elt\n", __FUNCTION__));
+
+       if (! _sna_damage_create_boxes(damage, count))
+               return damage;
+
+       for (i = 0; i < count; i++) {
+               damage->box[i].x1 = p[i].x + dx;
+               damage->box[i].x2 = damage->box[i].x1 + 1;
+               damage->box[i].y1 = p[i].y + dy;
+               damage->box[i].y2 = damage->box[i].y1 + 1;
+       }
+       damage->box += count;
+       damage->remain -= count;
+       assert(damage->remain >= 0);
+
+       return damage;
+}
+
+static void free_list(struct list *head)
+{
+       while (!list_is_empty(head)) {
+               struct list *l = head->next;
+               list_del(l);
+               free(l);
+       }
+}
+
+static void __sna_damage_reduce(struct sna_damage *damage)
+{
+       int n, nboxes;
+       BoxPtr boxes, free_boxes = NULL;
+       pixman_region16_t *region = &damage->region;
+       struct sna_damage_box *iter;
+
+       assert(damage->mode != DAMAGE_ALL);
+       assert(damage->dirty);
+
+       DBG(("    reduce: before region.n=%d\n", REGION_NUM_RECTS(region)));
+
+       nboxes = damage->embedded_box.size;
+       list_for_each_entry(iter, &damage->embedded_box.list, list)
+               nboxes += iter->size;
+       DBG(("   nboxes=%d, residual=%d\n", nboxes, damage->remain));
+       nboxes -= damage->remain;
+       if (nboxes == 0)
+               goto done;
+       if (nboxes == 1) {
+               pixman_region16_t tmp;
+
+               tmp.extents = damage->embedded_box.box[0];
+               tmp.data = NULL;
+
+               if (damage->mode == DAMAGE_ADD)
+                       pixman_region_union(region, region, &tmp);
+               else
+                       pixman_region_subtract(region, region, &tmp);
+               damage->extents = region->extents;
+
+               goto done;
+       }
+
+       if (damage->mode == DAMAGE_ADD)
+               nboxes += REGION_NUM_RECTS(region);
+
+       iter = list_entry(damage->embedded_box.list.prev,
+                         struct sna_damage_box,
+                         list);
+       n = iter->size - damage->remain;
+       boxes = (BoxRec *)(iter+1);
+       DBG(("   last box count=%d/%d, need=%d\n", n, iter->size, nboxes));
+       if (nboxes > iter->size) {
+               boxes = malloc(sizeof(BoxRec)*nboxes);
+               if (boxes == NULL)
+                       goto done;
+
+               free_boxes = boxes;
+       }
+
+       if (boxes != damage->embedded_box.box) {
+               if (list_is_empty(&damage->embedded_box.list)) {
+                       DBG(("   copying embedded boxes\n"));
+                       memcpy(boxes,
+                              damage->embedded_box.box,
+                              n*sizeof(BoxRec));
+               } else {
+                       if (boxes != (BoxPtr)(iter+1)) {
+                               DBG(("   copying %d boxes from last\n", n));
+                               memcpy(boxes, iter+1, n*sizeof(BoxRec));
+                       }
+
+                       iter = list_entry(iter->list.prev,
+                                         struct sna_damage_box,
+                                         list);
+                       while (&iter->list != &damage->embedded_box.list) {
+                               DBG(("   copy %d boxes from %d\n",
+                                    iter->size, n));
+                               memcpy(boxes + n, iter+1,
+                                      iter->size * sizeof(BoxRec));
+                               n += iter->size;
+
+                               iter = list_entry(iter->list.prev,
+                                                 struct sna_damage_box,
+                                                 list);
+                       }
+
+                       DBG(("   copying embedded boxes to %d\n", n));
+                       memcpy(boxes + n,
+                              damage->embedded_box.box,
+                              sizeof(damage->embedded_box.box));
+                       n += damage->embedded_box.size;
+               }
+       }
+
+       if (damage->mode == DAMAGE_ADD) {
+               memcpy(boxes + n,
+                      REGION_RECTS(region),
+                      REGION_NUM_RECTS(region)*sizeof(BoxRec));
+               assert(n + REGION_NUM_RECTS(region) == nboxes);
+               pixman_region_fini(region);
+               pixman_region_init_rects(region, boxes, nboxes);
+
+               assert(pixman_region_not_empty(region));
+               assert(damage->extents.x1 == region->extents.x1 &&
+                      damage->extents.y1 == region->extents.y1 &&
+                      damage->extents.x2 == region->extents.x2 &&
+                      damage->extents.y2 == region->extents.y2);
+       } else {
+               pixman_region16_t tmp;
+
+               pixman_region_init_rects(&tmp, boxes, nboxes);
+               pixman_region_subtract(region, region, &tmp);
+               pixman_region_fini(&tmp);
+
+               assert(damage->extents.x1 <= region->extents.x1 &&
+                      damage->extents.y1 <= region->extents.y1 &&
+                      damage->extents.x2 >= region->extents.x2 &&
+                      damage->extents.y2 >= region->extents.y2);
+               if (pixman_region_not_empty(region))
+                       damage->extents = region->extents;
+               else
+                       reset_extents(damage);
+       }
+
+       free(free_boxes);
+
+done:
+       damage->mode = DAMAGE_ADD;
+       free_list(&damage->embedded_box.list);
+       reset_embedded_box(damage);
+
+       DBG(("    reduce: after region.n=%d\n", REGION_NUM_RECTS(region)));
+}
+
+static void damage_union(struct sna_damage *damage, const BoxRec *box)
+{
+       DBG(("%s: extending damage (%d, %d), (%d, %d) by (%d, %d), (%d, %d)\n",
+            __FUNCTION__,
+            damage->extents.x1, damage->extents.y1,
+            damage->extents.x2, damage->extents.y2,
+            box->x1, box->y1, box->x2, box->y2));
+       assert(box->x2 > box->x1 && box->y2 > box->y1);
+       if (damage->extents.x2 < damage->extents.x1) {
+               damage->extents = *box;
+       } else {
+               if (damage->extents.x1 > box->x1)
+                       damage->extents.x1 = box->x1;
+               if (damage->extents.x2 < box->x2)
+                       damage->extents.x2 = box->x2;
+
+               if (damage->extents.y1 > box->y1)
+                       damage->extents.y1 = box->y1;
+               if (damage->extents.y2 < box->y2)
+                       damage->extents.y2 = box->y2;
+       }
+       assert(damage->extents.x2 > damage->extents.x1);
+       assert(damage->extents.y2 > damage->extents.y1);
+}
+
+static void _pixman_region_union_box(RegionRec *region, const BoxRec *box)
+{
+       RegionRec u = { *box, NULL };
+       pixman_region_union(region, region, &u);
+}
+
+static bool box_contains_region(const BoxRec *b, const RegionRec *r)
+{
+       return (b->x1 <= r->extents.x1 && b->x2 >= r->extents.x2 &&
+               b->y1 <= r->extents.y1 && b->y2 >= r->extents.y2);
+}
+
+static struct sna_damage *__sna_damage_add_box(struct sna_damage *damage,
+                                              const BoxRec *box)
+{
+       if (box->y2 <= box->y1 || box->x2 <= box->x1)
+               return damage;
+
+       if (!damage) {
+               damage = _sna_damage_create();
+               if (damage == NULL)
+                       return NULL;
+       } else switch (damage->mode) {
+       case DAMAGE_ALL:
+               return damage;
+       case DAMAGE_SUBTRACT:
+               __sna_damage_reduce(damage);
+       case DAMAGE_ADD:
+               break;
+       }
+
+       if (REGION_NUM_RECTS(&damage->region) <= 1 ||
+           box_contains_region(box, &damage->region)) {
+               _pixman_region_union_box(&damage->region, box);
+               assert(damage->region.extents.x2 > damage->region.extents.x1);
+               assert(damage->region.extents.y2 > damage->region.extents.y1);
+               damage_union(damage, box);
+               return damage;
+       }
+
+       if (pixman_region_contains_rectangle(&damage->region,
+                                            (BoxPtr)box) == PIXMAN_REGION_IN)
+               return damage;
+
+       damage_union(damage, box);
+       return _sna_damage_create_elt(damage, box, 1);
+}
+
+inline static struct sna_damage *__sna_damage_add(struct sna_damage *damage,
+                                                 RegionPtr region)
+{
+       assert(RegionNotEmpty(region));
+
+       if (!damage) {
+               damage = _sna_damage_create();
+               if (damage == NULL)
+                       return NULL;
+       } else switch (damage->mode) {
+       case DAMAGE_ALL:
+               return damage;
+       case DAMAGE_SUBTRACT:
+               __sna_damage_reduce(damage);
+       case DAMAGE_ADD:
+               break;
+       }
+
+       if (region->data == NULL)
+               return __sna_damage_add_box(damage, &region->extents);
+
+       if (REGION_NUM_RECTS(&damage->region) <= 1) {
+               pixman_region_union(&damage->region, &damage->region, region);
+               assert(damage->region.extents.x2 > damage->region.extents.x1);
+               assert(damage->region.extents.y2 > damage->region.extents.y1);
+               damage_union(damage, &region->extents);
+               return damage;
+       }
+
+       if (pixman_region_contains_rectangle(&damage->region,
+                                            &region->extents) == PIXMAN_REGION_IN)
+               return damage;
+
+       damage_union(damage, &region->extents);
+       return _sna_damage_create_elt(damage,
+                                     REGION_RECTS(region),
+                                     REGION_NUM_RECTS(region));
+}
+
+#if HAS_DEBUG_FULL
+fastcall struct sna_damage *_sna_damage_add(struct sna_damage *damage,
+                                           RegionPtr region)
+{
+       char region_buf[120];
+       char damage_buf[1000];
+
+       DBG(("%s(%s + %s)\n", __FUNCTION__,
+            _debug_describe_damage(damage_buf, sizeof(damage_buf), damage),
+            _debug_describe_region(region_buf, sizeof(region_buf), region)));
+
+       damage = __sna_damage_add(damage, region);
+
+       ErrorF("  = %s\n",
+              _debug_describe_damage(damage_buf, sizeof(damage_buf), damage));
+       assert(RegionNumRects(&damage->region));
+       assert(damage->region.extents.x2 > damage->region.extents.x1);
+       assert(damage->region.extents.y2 > damage->region.extents.y1);
+
+       return damage;
+}
+#else
+fastcall struct sna_damage *_sna_damage_add(struct sna_damage *damage,
+                                           RegionPtr region)
+{
+       return __sna_damage_add(damage, region);
+}
+#endif
+
+inline static struct sna_damage *
+__sna_damage_add_boxes(struct sna_damage *damage,
+                      const BoxRec *box, int n,
+                      int16_t dx, int16_t dy)
+{
+       BoxRec extents;
+       int i;
+
+       assert(n);
+
+       if (!damage) {
+               damage = _sna_damage_create();
+               if (damage == NULL)
+                       return NULL;
+       } else switch (damage->mode) {
+       case DAMAGE_ALL:
+               return damage;
+       case DAMAGE_SUBTRACT:
+               __sna_damage_reduce(damage);
+       case DAMAGE_ADD:
+               break;
+       }
+
+       assert(box[0].x2 > box[0].x1 && box[0].y2 > box[0].y1);
+       extents = box[0];
+       for (i = 1; i < n; i++) {
+               assert(box[i].x2 > box[i].x1 && box[i].y2 > box[i].y1);
+               if (extents.x1 > box[i].x1)
+                       extents.x1 = box[i].x1;
+               if (extents.x2 < box[i].x2)
+                       extents.x2 = box[i].x2;
+               if (extents.y1 > box[i].y1)
+                       extents.y1 = box[i].y1;
+               if (extents.y2 < box[i].y2)
+                       extents.y2 = box[i].y2;
+       }
+
+       assert(extents.y2 > extents.y1 && extents.x2 > extents.x1);
+
+       extents.x1 += dx;
+       extents.x2 += dx;
+       extents.y1 += dy;
+       extents.y2 += dy;
+
+       if (n == 1)
+               return __sna_damage_add_box(damage, &extents);
+
+       if (pixman_region_contains_rectangle(&damage->region,
+                                            &extents) == PIXMAN_REGION_IN)
+               return damage;
+
+       damage_union(damage, &extents);
+       return _sna_damage_create_elt_from_boxes(damage, box, n, dx, dy);
+}
+
+#if HAS_DEBUG_FULL
+struct sna_damage *_sna_damage_add_boxes(struct sna_damage *damage,
+                                        const BoxRec *b, int n,
+                                        int16_t dx, int16_t dy)
+{
+       char damage_buf[1000];
+
+       DBG(("%s(%s + [(%d, %d), (%d, %d) ... x %d])\n", __FUNCTION__,
+            _debug_describe_damage(damage_buf, sizeof(damage_buf), damage),
+            b->x1, b->y1, b->x2, b->y2, n));
+
+       damage = __sna_damage_add_boxes(damage, b, n, dx, dy);
+
+       ErrorF("  = %s\n",
+              _debug_describe_damage(damage_buf, sizeof(damage_buf), damage));
+       if (RegionNumRects(&damage->region)) {
+               assert(damage->region.extents.x2 > damage->region.extents.x1);
+               assert(damage->region.extents.y2 > damage->region.extents.y1);
+       }
+
+       return damage;
+}
+#else
+struct sna_damage *_sna_damage_add_boxes(struct sna_damage *damage,
+                                        const BoxRec *b, int n,
+                                        int16_t dx, int16_t dy)
+{
+       return __sna_damage_add_boxes(damage, b, n, dx, dy);
+}
+#endif
+
+inline static struct sna_damage *
+__sna_damage_add_rectangles(struct sna_damage *damage,
+                           const xRectangle *r, int n,
+                           int16_t dx, int16_t dy)
+{
+       BoxRec extents;
+       int i;
+
+       assert(n);
+
+       assert(r[0].width && r[0].height);
+       extents.x1 = r[0].x;
+       extents.x2 = r[0].x + r[0].width;
+       extents.y1 = r[0].y;
+       extents.y2 = r[0].y + r[0].height;
+       for (i = 1; i < n; i++) {
+               assert(r[i].width && r[i].height);
+               if (extents.x1 > r[i].x)
+                       extents.x1 = r[i].x;
+               if (extents.x2 < r[i].x + r[i].width)
+                       extents.x2 = r[i].x + r[i].width;
+               if (extents.y1 > r[i].y)
+                       extents.y1 = r[i].y;
+               if (extents.y2 < r[i].y + r[i].height)
+                       extents.y2 = r[i].y + r[i].height;
+       }
+
+       assert(extents.y2 > extents.y1 && extents.x2 > extents.x1);
+
+       extents.x1 += dx;
+       extents.x2 += dx;
+       extents.y1 += dy;
+       extents.y2 += dy;
+
+       if (n == 1)
+               return __sna_damage_add_box(damage, &extents);
+
+       if (!damage) {
+               damage = _sna_damage_create();
+               if (damage == NULL)
+                       return NULL;
+       } else switch (damage->mode) {
+       case DAMAGE_ALL:
+               return damage;
+       case DAMAGE_SUBTRACT:
+               __sna_damage_reduce(damage);
+       case DAMAGE_ADD:
+               break;
+       }
+
+       if (pixman_region_contains_rectangle(&damage->region,
+                                            &extents) == PIXMAN_REGION_IN)
+               return damage;
+
+       damage_union(damage, &extents);
+       return _sna_damage_create_elt_from_rectangles(damage, r, n, dx, dy);
+}
+
+#if HAS_DEBUG_FULL
+struct sna_damage *_sna_damage_add_rectangles(struct sna_damage *damage,
+                                             const xRectangle *r, int n,
+                                             int16_t dx, int16_t dy)
+{
+       char damage_buf[1000];
+
+       DBG(("%s(%s + [(%d, %d)x(%d, %d) ... x %d])\n", __FUNCTION__,
+            _debug_describe_damage(damage_buf, sizeof(damage_buf), damage),
+            r->x, r->y, r->width, r->height, n));
+
+       damage = __sna_damage_add_rectangles(damage, r, n, dx, dy);
+
+       ErrorF("  = %s\n",
+              _debug_describe_damage(damage_buf, sizeof(damage_buf), damage));
+       if (RegionNumRects(&damage->region)) {
+               assert(damage->region.extents.x2 > damage->region.extents.x1);
+               assert(damage->region.extents.y2 > damage->region.extents.y1);
+       }
+
+       return damage;
+}
+#else
+struct sna_damage *_sna_damage_add_rectangles(struct sna_damage *damage,
+                                             const xRectangle *r, int n,
+                                             int16_t dx, int16_t dy)
+{
+       return __sna_damage_add_rectangles(damage, r, n, dx, dy);
+}
+#endif
+
+/* XXX pass in extents? */
+inline static struct sna_damage *
+__sna_damage_add_points(struct sna_damage *damage,
+                       const DDXPointRec *p, int n,
+                       int16_t dx, int16_t dy)
+{
+       BoxRec extents;
+       int i;
+
+       assert(n);
+
+       extents.x2 = extents.x1 = p[0].x;
+       extents.y2 = extents.y1 = p[0].y;
+       for (i = 1; i < n; i++) {
+               if (extents.x1 > p[i].x)
+                       extents.x1 = p[i].x;
+               else if (extents.x2 < p[i].x)
+                       extents.x2 = p[i].x;
+               if (extents.y1 > p[i].y)
+                       extents.y1 = p[i].y;
+               else if (extents.y2 < p[i].y)
+                       extents.y2 = p[i].y;
+       }
+
+       extents.x1 += dx;
+       extents.x2 += dx + 1;
+       extents.y1 += dy;
+       extents.y2 += dy + 1;
+
+       if (n == 1)
+               return __sna_damage_add_box(damage, &extents);
+
+       if (!damage) {
+               damage = _sna_damage_create();
+               if (damage == NULL)
+                       return NULL;
+       } else switch (damage->mode) {
+       case DAMAGE_ALL:
+               return damage;
+       case DAMAGE_SUBTRACT:
+               __sna_damage_reduce(damage);
+       case DAMAGE_ADD:
+               break;
+       }
+
+       if (pixman_region_contains_rectangle(&damage->region,
+                                            &extents) == PIXMAN_REGION_IN)
+               return damage;
+
+       damage_union(damage, &extents);
+       _sna_damage_create_elt_from_points(damage, p, n, dx, dy);
+
+       return damage;
+}
+
+#if HAS_DEBUG_FULL
+struct sna_damage *_sna_damage_add_points(struct sna_damage *damage,
+                                         const DDXPointRec *p, int n,
+                                         int16_t dx, int16_t dy)
+{
+       char damage_buf[1000];
+
+       DBG(("%s(%s + [(%d, %d) ... x %d])\n", __FUNCTION__,
+            _debug_describe_damage(damage_buf, sizeof(damage_buf), damage),
+            p->x, p->y, n));
+
+       damage = __sna_damage_add_points(damage, p, n, dx, dy);
+
+       ErrorF("  = %s\n",
+              _debug_describe_damage(damage_buf, sizeof(damage_buf), damage));
+       if (RegionNumRects(&damage->region)) {
+               assert(damage->region.extents.x2 > damage->region.extents.x1);
+               assert(damage->region.extents.y2 > damage->region.extents.y1);
+       }
+
+       return damage;
+}
+#else
+struct sna_damage *_sna_damage_add_points(struct sna_damage *damage,
+                                         const DDXPointRec *p, int n,
+                                         int16_t dx, int16_t dy)
+{
+       return __sna_damage_add_points(damage, p, n, dx, dy);
+}
+#endif
+
+#if HAS_DEBUG_FULL
+fastcall struct sna_damage *_sna_damage_add_box(struct sna_damage *damage,
+                                               const BoxRec *box)
+{
+       char damage_buf[1000];
+
+       DBG(("%s(%s + [(%d, %d), (%d, %d)])\n", __FUNCTION__,
+            _debug_describe_damage(damage_buf, sizeof(damage_buf), damage),
+            box->x1, box->y1, box->x2, box->y2));
+
+       damage = __sna_damage_add_box(damage, box);
+
+       ErrorF("  = %s\n",
+              _debug_describe_damage(damage_buf, sizeof(damage_buf), damage));
+       assert(RegionNumRects(&damage->region));
+       assert(damage->region.extents.x2 > damage->region.extents.x1);
+       assert(damage->region.extents.y2 > damage->region.extents.y1);
+
+       return damage;
+}
+#else
+fastcall struct sna_damage *_sna_damage_add_box(struct sna_damage *damage,
+                                               const BoxRec *box)
+{
+       return __sna_damage_add_box(damage, box);
+}
+#endif
+
+struct sna_damage *__sna_damage_all(struct sna_damage *damage,
+                                   int width, int height)
+{
+       DBG(("%s(%d, %d)\n", __FUNCTION__, width, height));
+
+       if (damage) {
+               pixman_region_fini(&damage->region);
+               free_list(&damage->embedded_box.list);
+               reset_embedded_box(damage);
+       } else {
+               damage = _sna_damage_create();
+               if (damage == NULL)
+                       return NULL;
+       }
+
+       pixman_region_init_rect(&damage->region, 0, 0, width, height);
+       damage->extents = damage->region.extents;
+       damage->mode = DAMAGE_ALL;
+
+       return damage;
+}
+
+struct sna_damage *_sna_damage_is_all(struct sna_damage *damage,
+                                     int width, int height)
+{
+       DBG(("%s(%d, %d)%s?\n", __FUNCTION__, width, height,
+            damage->dirty ? "*" : ""));
+       DBG(("%s: (%d, %d), (%d, %d)\n", __FUNCTION__,
+            damage->extents.x1, damage->extents.y1,
+            damage->extents.x2, damage->extents.y2));
+
+       assert(damage->mode == DAMAGE_ADD);
+       assert(damage->extents.x1 == 0 &&
+              damage->extents.y1 == 0 &&
+              damage->extents.x2 == width &&
+              damage->extents.y2 == height);
+
+       if (damage->dirty) {
+               __sna_damage_reduce(damage);
+               assert(RegionNotEmpty(&damage->region));
+       }
+
+       if (damage->region.data) {
+               DBG(("%s: no, not singular\n", __FUNCTION__));
+               return damage;
+       }
+
+       assert(damage->extents.x1 == 0 &&
+              damage->extents.y1 == 0 &&
+              damage->extents.x2 == width &&
+              damage->extents.y2 == height);
+
+       return __sna_damage_all(damage, width, height);
+}
+
+static bool box_contains(const BoxRec *a, const BoxRec *b)
+{
+       if (b->x1 < a->x1 || b->x2 > a->x2)
+               return false;
+
+       if (b->y1 < a->y1 || b->y2 > a->y2)
+               return false;
+
+       return true;
+}
+
+static struct sna_damage *__sna_damage_subtract(struct sna_damage *damage,
+                                               RegionPtr region)
+{
+       if (damage == NULL)
+               return NULL;
+
+       if (!RegionNotEmpty(&damage->region)) {
+no_damage:
+               __sna_damage_destroy(damage);
+               return NULL;
+       }
+
+       assert(RegionNotEmpty(region));
+
+       if (!sna_damage_overlaps_box(damage, &region->extents))
+               return damage;
+
+       if (region_is_singular(region) &&
+           box_contains(&region->extents, &damage->extents))
+               goto no_damage;
+
+       if (damage->mode == DAMAGE_ALL) {
+               pixman_region_subtract(&damage->region,
+                                      &damage->region,
+                                      region);
+               if (damage->region.extents.x2 <= damage->region.extents.x1 ||
+                   damage->region.extents.y2 <= damage->region.extents.y1)
+                       goto no_damage;
+
+               damage->extents = damage->region.extents;
+               damage->mode = DAMAGE_ADD;
+               return damage;
+       }
+
+       if (damage->mode != DAMAGE_SUBTRACT) {
+               if (damage->dirty) {
+                       __sna_damage_reduce(damage);
+                       assert(RegionNotEmpty(&damage->region));
+               }
+
+               if (pixman_region_equal(region, &damage->region))
+                       goto no_damage;
+
+               if (region_is_singular(&damage->region) &&
+                   region_is_singular(region)) {
+                       pixman_region_subtract(&damage->region,
+                                              &damage->region,
+                                              region);
+                       if (damage->region.extents.x2 <= damage->region.extents.x1 ||
+                           damage->region.extents.y2 <= damage->region.extents.y1)
+                               goto no_damage;
+
+                       damage->extents = damage->region.extents;
+                       assert(pixman_region_not_empty(&damage->region));
+                       return damage;
+               }
+
+               damage->mode = DAMAGE_SUBTRACT;
+       }
+
+       return _sna_damage_create_elt(damage,
+                                     REGION_RECTS(region),
+                                     REGION_NUM_RECTS(region));
+}
+
+#if HAS_DEBUG_FULL
+fastcall struct sna_damage *_sna_damage_subtract(struct sna_damage *damage,
+                                                RegionPtr region)
+{
+       char damage_buf[1000];
+       char region_buf[120];
+
+       ErrorF("%s(%s - %s)...\n", __FUNCTION__,
+              _debug_describe_damage(damage_buf, sizeof(damage_buf), damage),
+              _debug_describe_region(region_buf, sizeof(region_buf), region));
+
+       damage = __sna_damage_subtract(damage, region);
+
+       ErrorF("  = %s\n",
+              _debug_describe_damage(damage_buf, sizeof(damage_buf), damage));
+
+       return damage;
+}
+#else
+fastcall struct sna_damage *_sna_damage_subtract(struct sna_damage *damage,
+                                                RegionPtr region)
+{
+       return __sna_damage_subtract(damage, region);
+}
+#endif
+
+inline static struct sna_damage *__sna_damage_subtract_box(struct sna_damage *damage,
+                                                          const BoxRec *box)
+{
+       assert(box->x2 > box->x1 && box->y2 > box->y1);
+
+       if (damage == NULL)
+               return NULL;
+
+       if (!RegionNotEmpty(&damage->region)) {
+               __sna_damage_destroy(damage);
+               return NULL;
+       }
+
+       if (!sna_damage_overlaps_box(damage, box))
+               return damage;
+
+       if (box_contains(box, &damage->extents)) {
+               __sna_damage_destroy(damage);
+               return NULL;
+       }
+
+       if (damage->mode != DAMAGE_SUBTRACT) {
+               if (damage->dirty) {
+                       __sna_damage_reduce(damage);
+                       assert(RegionNotEmpty(&damage->region));
+               }
+
+               if (region_is_singular(&damage->region)) {
+                       pixman_region16_t region;
+
+                       pixman_region_init_rects(&region, box, 1);
+                       pixman_region_subtract(&damage->region,
+                                              &damage->region,
+                                              &region);
+                       damage->extents = damage->region.extents;
+                       damage->mode = DAMAGE_ADD;
+                       return damage;
+               }
+
+               damage->mode = DAMAGE_SUBTRACT;
+       }
+
+       return _sna_damage_create_elt(damage, box, 1);
+}
+
+#if HAS_DEBUG_FULL
+fastcall struct sna_damage *_sna_damage_subtract_box(struct sna_damage *damage,
+                                                    const BoxRec *box)
+{
+       char damage_buf[1000];
+
+       ErrorF("%s(%s - (%d, %d), (%d, %d))...\n", __FUNCTION__,
+              _debug_describe_damage(damage_buf, sizeof(damage_buf), damage),
+              box->x1, box->y1, box->x2, box->y2);
+
+       damage = __sna_damage_subtract_box(damage, box);
+
+       ErrorF("  = %s\n",
+              _debug_describe_damage(damage_buf, sizeof(damage_buf), damage));
+
+       return damage;
+}
+#else
+fastcall struct sna_damage *_sna_damage_subtract_box(struct sna_damage *damage,
+                                                    const BoxRec *box)
+{
+       return __sna_damage_subtract_box(damage, box);
+}
+#endif
+
+static struct sna_damage *__sna_damage_subtract_boxes(struct sna_damage *damage,
+                                                     const BoxRec *box, int n,
+                                                     int dx, int dy)
+{
+       BoxRec extents;
+       int i;
+
+       if (damage == NULL)
+               return NULL;
+
+       if (!RegionNotEmpty(&damage->region)) {
+               __sna_damage_destroy(damage);
+               return NULL;
+       }
+
+       assert(n);
+
+       assert(box[0].x2 > box[0].x1 && box[0].y2 > box[0].y1);
+       extents = box[0];
+       for (i = 1; i < n; i++) {
+               assert(box[i].x2 > box[i].x1 && box[i].y2 > box[i].y1);
+               if (extents.x1 > box[i].x1)
+                       extents.x1 = box[i].x1;
+               if (extents.x2 < box[i].x2)
+                       extents.x2 = box[i].x2;
+               if (extents.y1 > box[i].y1)
+                       extents.y1 = box[i].y1;
+               if (extents.y2 < box[i].y2)
+                       extents.y2 = box[i].y2;
+       }
+
+       assert(extents.y2 > extents.y1 && extents.x2 > extents.x1);
+
+       extents.x1 += dx;
+       extents.x2 += dx;
+       extents.y1 += dy;
+       extents.y2 += dy;
+
+       if (!sna_damage_overlaps_box(damage, &extents))
+               return damage;
+
+       if (n == 1)
+               return __sna_damage_subtract_box(damage, &extents);
+
+       if (damage->mode != DAMAGE_SUBTRACT) {
+               if (damage->dirty) {
+                       __sna_damage_reduce(damage);
+                       assert(RegionNotEmpty(&damage->region));
+               }
+
+               damage->mode = DAMAGE_SUBTRACT;
+       }
+
+       return _sna_damage_create_elt_from_boxes(damage, box, n, dx, dy);
+}
+
+#if HAS_DEBUG_FULL
+fastcall struct sna_damage *_sna_damage_subtract_boxes(struct sna_damage *damage,
+                                                      const BoxRec *box, int n,
+                                                      int dx, int dy)
+{
+       char damage_buf[1000];
+       char region_buf[120];
+
+       ErrorF("%s(%s - [(%d,%d), (%d,%d)...x%d])...\n", __FUNCTION__,
+              _debug_describe_damage(damage_buf, sizeof(damage_buf), damage),
+              box->x1 + dx, box->y1 + dy,
+              box->x2 + dx, box->y2 + dy,
+              n);
+
+       damage = __sna_damage_subtract_boxes(damage, box, n, dx, dy);
+
+       ErrorF("  = %s\n",
+              _debug_describe_damage(damage_buf, sizeof(damage_buf), damage));
+
+       return damage;
+}
+#else
+fastcall struct sna_damage *_sna_damage_subtract_boxes(struct sna_damage *damage,
+                                                      const BoxRec *box, int n,
+                                                      int dx, int dy)
+{
+       return __sna_damage_subtract_boxes(damage, box, n, dx, dy);
+}
+#endif
+
+static int __sna_damage_contains_box(struct sna_damage *damage,
+                                    const BoxRec *box)
+{
+       int ret;
+
+       if (!damage)
+               return PIXMAN_REGION_OUT;
+
+       if (damage->mode == DAMAGE_ALL)
+               return PIXMAN_REGION_IN;
+
+       if (!sna_damage_overlaps_box(damage, box))
+               return PIXMAN_REGION_OUT;
+
+       ret = pixman_region_contains_rectangle(&damage->region, (BoxPtr)box);
+       if (!damage->dirty)
+               return ret;
+
+       if (damage->mode == DAMAGE_ADD) {
+               if (ret == PIXMAN_REGION_IN)
+                       return ret;
+       } else {
+               if (ret == PIXMAN_REGION_OUT)
+                       return ret;
+       }
+
+       __sna_damage_reduce(damage);
+       return pixman_region_contains_rectangle(&damage->region, (BoxPtr)box);
+}
+
+#if HAS_DEBUG_FULL
+int _sna_damage_contains_box(struct sna_damage *damage,
+                            const BoxRec *box)
+{
+       char damage_buf[1000];
+       int ret;
+
+       DBG(("%s(%s, [(%d, %d), (%d, %d)])\n", __FUNCTION__,
+            _debug_describe_damage(damage_buf, sizeof(damage_buf), damage),
+            box->x1, box->y1, box->x2, box->y2));
+
+       ret = __sna_damage_contains_box(damage, box);
+       ErrorF("  = %d", ret);
+       if (ret)
+               ErrorF(" [(%d, %d), (%d, %d)...]",
+                      box->x1, box->y1, box->x2, box->y2);
+       ErrorF("\n");
+
+       return ret;
+}
+#else
+int _sna_damage_contains_box(struct sna_damage *damage,
+                            const BoxRec *box)
+{
+       return __sna_damage_contains_box(damage, box);
+}
+#endif
+
+bool _sna_damage_contains_box__no_reduce(const struct sna_damage *damage,
+                                        const BoxRec *box)
+{
+       assert(damage && damage->mode != DAMAGE_ALL);
+       if (damage->mode == DAMAGE_SUBTRACT)
+               return false;
+
+       if (!sna_damage_overlaps_box(damage, box))
+               return false;
+
+       return pixman_region_contains_rectangle((RegionPtr)&damage->region,
+                                               (BoxPtr)box) == PIXMAN_REGION_IN;
+}
+
+static bool __sna_damage_intersect(struct sna_damage *damage,
+                                  RegionPtr region, RegionPtr result)
+{
+       assert(damage && damage->mode != DAMAGE_ALL);
+       if (region->extents.x2 <= damage->extents.x1 ||
+           region->extents.x1 >= damage->extents.x2)
+               return false;
+
+       if (region->extents.y2 <= damage->extents.y1 ||
+           region->extents.y1 >= damage->extents.y2)
+               return false;
+
+       if (damage->dirty)
+               __sna_damage_reduce(damage);
+
+       if (!pixman_region_not_empty(&damage->region))
+               return false;
+
+       RegionNull(result);
+       RegionIntersect(result, &damage->region, region);
+
+       return RegionNotEmpty(result);
+}
+
+#if HAS_DEBUG_FULL
+bool _sna_damage_intersect(struct sna_damage *damage,
+                          RegionPtr region, RegionPtr result)
+{
+       char damage_buf[1000];
+       char region_buf[120];
+       bool ret;
+
+       ErrorF("%s(%s, %s)...\n", __FUNCTION__,
+              _debug_describe_damage(damage_buf, sizeof(damage_buf), damage),
+              _debug_describe_region(region_buf, sizeof(region_buf), region));
+
+       ret = __sna_damage_intersect(damage, region, result);
+       if (ret)
+               ErrorF("  = %s\n",
+                      _debug_describe_region(region_buf, sizeof(region_buf), result));
+       else
+               ErrorF("  = none\n");
+
+       return ret;
+}
+#else
+bool _sna_damage_intersect(struct sna_damage *damage,
+                         RegionPtr region, RegionPtr result)
+{
+       return __sna_damage_intersect(damage, region, result);
+}
+#endif
+
+static int __sna_damage_get_boxes(struct sna_damage *damage, BoxPtr *boxes)
+{
+       assert(damage && damage->mode != DAMAGE_ALL);
+
+       if (damage->dirty)
+               __sna_damage_reduce(damage);
+
+       *boxes = REGION_RECTS(&damage->region);
+       return REGION_NUM_RECTS(&damage->region);
+}
+
+struct sna_damage *_sna_damage_reduce(struct sna_damage *damage)
+{
+       DBG(("%s\n", __FUNCTION__));
+
+       __sna_damage_reduce(damage);
+       if (!pixman_region_not_empty(&damage->region)) {
+               __sna_damage_destroy(damage);
+               damage = NULL;
+       }
+
+       return damage;
+}
+
+#if HAS_DEBUG_FULL
+int _sna_damage_get_boxes(struct sna_damage *damage, BoxPtr *boxes)
+{
+       char damage_buf[1000];
+       int count;
+
+       ErrorF("%s(%s)...\n", __FUNCTION__,
+              _debug_describe_damage(damage_buf, sizeof(damage_buf), damage));
+
+       count = __sna_damage_get_boxes(damage, boxes);
+       ErrorF("  = %d\n", count);
+
+       return count;
+}
+#else
+int _sna_damage_get_boxes(struct sna_damage *damage, BoxPtr *boxes)
+{
+       return __sna_damage_get_boxes(damage, boxes);
+}
+#endif
+
+struct sna_damage *_sna_damage_combine(struct sna_damage *l,
+                                      struct sna_damage *r,
+                                      int dx, int dy)
+{
+       if (r->dirty)
+               __sna_damage_reduce(r);
+
+       if (pixman_region_not_empty(&r->region)) {
+               pixman_region_translate(&r->region, dx, dy);
+               l = __sna_damage_add(l, &r->region);
+       }
+
+       return l;
+}
+
+void __sna_damage_destroy(struct sna_damage *damage)
+{
+       free_list(&damage->embedded_box.list);
+
+       pixman_region_fini(&damage->region);
+       *(void **)damage = __freed_damage;
+       __freed_damage = damage;
+}
+
+#if TEST_DAMAGE && HAS_DEBUG_FULL
+struct sna_damage_selftest{
+       int width, height;
+};
+
+static void st_damage_init_random_box(struct sna_damage_selftest *test,
+                                     BoxPtr box)
+{
+       int x, y, w, h;
+
+       if (test->width == 1) {
+               x = 0, w = 1;
+       } else {
+               x = rand() % (test->width - 1);
+               w = 1 + rand() % (test->width - x - 1);
+       }
+
+       if (test->height == 1) {
+               y = 0, h = 1;
+       } else {
+               y = rand() % (test->height - 1);
+               h = 1 + rand() % (test->height - y - 1);
+       }
+
+       box->x1 = x;
+       box->x2 = x+w;
+
+       box->y1 = y;
+       box->y2 = y+h;
+}
+
+static void st_damage_init_random_region1(struct sna_damage_selftest *test,
+                                         pixman_region16_t *region)
+{
+       int x, y, w, h;
+
+       if (test->width == 1) {
+               x = 0, w = 1;
+       } else {
+               x = rand() % (test->width - 1);
+               w = 1 + rand() % (test->width - x - 1);
+       }
+
+       if (test->height == 1) {
+               y = 0, h = 1;
+       } else {
+               y = rand() % (test->height - 1);
+               h = 1 + rand() % (test->height - y - 1);
+       }
+
+       pixman_region_init_rect(region, x, y, w, h);
+}
+
+static void st_damage_add(struct sna_damage_selftest *test,
+                         struct sna_damage **damage,
+                         pixman_region16_t *region)
+{
+       pixman_region16_t tmp;
+
+       st_damage_init_random_region1(test, &tmp);
+
+       if (!DAMAGE_IS_ALL(*damage))
+               sna_damage_add(damage, &tmp);
+       pixman_region_union(region, region, &tmp);
+}
+
+static void st_damage_add_box(struct sna_damage_selftest *test,
+                             struct sna_damage **damage,
+                             pixman_region16_t *region)
+{
+       RegionRec r;
+
+       st_damage_init_random_box(test, &r.extents);
+       r.data = NULL;
+
+       if (!DAMAGE_IS_ALL(*damage))
+               sna_damage_add_box(damage, &r.extents);
+       pixman_region_union(region, region, &r);
+}
+
+static void st_damage_subtract(struct sna_damage_selftest *test,
+                              struct sna_damage **damage,
+                              pixman_region16_t *region)
+{
+       pixman_region16_t tmp;
+
+       st_damage_init_random_region1(test, &tmp);
+
+       sna_damage_subtract(damage, &tmp);
+       pixman_region_subtract(region, region, &tmp);
+}
+
+static void st_damage_subtract_box(struct sna_damage_selftest *test,
+                                  struct sna_damage **damage,
+                                  pixman_region16_t *region)
+{
+       RegionRec r;
+
+       st_damage_init_random_box(test, &r.extents);
+       r.data = NULL;
+
+       sna_damage_subtract_box(damage, &r.extents);
+       pixman_region_subtract(region, region, &r);
+}
+
+static void st_damage_all(struct sna_damage_selftest *test,
+                         struct sna_damage **damage,
+                         pixman_region16_t *region)
+{
+       pixman_region16_t tmp;
+
+       pixman_region_init_rect(&tmp, 0, 0, test->width, test->height);
+
+       if (!DAMAGE_IS_ALL(*damage))
+               sna_damage_all(damage, test->width, test->height);
+       pixman_region_union(region, region, &tmp);
+}
+
+static bool st_check_equal(struct sna_damage_selftest *test,
+                          struct sna_damage **damage,
+                          pixman_region16_t *region)
+{
+       int d_num, r_num;
+       BoxPtr d_boxes, r_boxes;
+
+       d_num = *damage ? sna_damage_get_boxes(*damage, &d_boxes) : 0;
+       r_boxes = pixman_region_rectangles(region, &r_num);
+
+       if (d_num != r_num) {
+               ErrorF("%s: damage and ref contain different number of rectangles\n",
+                      __FUNCTION__);
+               return false;
+       }
+
+       if (memcmp(d_boxes, r_boxes, d_num*sizeof(BoxRec))) {
+               ErrorF("%s: damage and ref contain different rectangles\n",
+                      __FUNCTION__);
+               return false;
+       }
+
+       return true;
+}
+
+void sna_damage_selftest(void)
+{
+       void (*const op[])(struct sna_damage_selftest *test,
+                          struct sna_damage **damage,
+                          pixman_region16_t *region) = {
+               st_damage_add,
+               st_damage_add_box,
+               st_damage_subtract,
+               st_damage_subtract_box,
+               st_damage_all
+       };
+       bool (*const check[])(struct sna_damage_selftest *test,
+                             struct sna_damage **damage,
+                             pixman_region16_t *region) = {
+               st_check_equal,
+               //st_check_contains,
+       };
+       char region_buf[120];
+       char damage_buf[1000];
+       int pass;
+
+       for (pass = 0; pass < 16384; pass++) {
+               struct sna_damage_selftest test;
+               struct sna_damage *damage;
+               pixman_region16_t ref;
+               int iter, i;
+
+               iter = 1 + rand() % (1 + (pass / 64));
+               ErrorF("%s: pass %d, iters=%d\n", __FUNCTION__, pass, iter);
+
+               test.width = 1 + rand() % 2048;
+               test.height = 1 + rand() % 2048;
+
+               damage = _sna_damage_create();
+               pixman_region_init(&ref);
+
+               for (i = 0; i < iter; i++) {
+                       op[rand() % ARRAY_SIZE(op)](&test, &damage, &ref);
+               }
+
+               if (!check[rand() % ARRAY_SIZE(check)](&test, &damage, &ref)) {
+                       ErrorF("%s: failed - region = %s, damage = %s\n", __FUNCTION__,
+                              _debug_describe_region(region_buf, sizeof(region_buf), &ref),
+                              _debug_describe_damage(damage_buf, sizeof(damage_buf), damage));
+                       assert(0);
+               }
+
+               pixman_region_fini(&ref);
+               sna_damage_destroy(&damage);
+       }
+}
+#endif
+
+void _sna_damage_debug_get_region(struct sna_damage *damage, RegionRec *r)
+{
+       int n, nboxes;
+       BoxPtr boxes;
+       struct sna_damage_box *iter;
+
+       RegionCopy(r, &damage->region);
+       if (!damage->dirty)
+               return;
+
+       nboxes = damage->embedded_box.size;
+       list_for_each_entry(iter, &damage->embedded_box.list, list)
+               nboxes += iter->size;
+       nboxes -= damage->remain;
+       if (nboxes == 0)
+               return;
+
+       if (nboxes == 1) {
+               pixman_region16_t tmp;
+
+               tmp.extents = damage->embedded_box.box[0];
+               tmp.data = NULL;
+
+               if (damage->mode == DAMAGE_ADD)
+                       pixman_region_union(r, r, &tmp);
+               else
+                       pixman_region_subtract(r, r, &tmp);
+
+               return;
+       }
+
+       if (damage->mode == DAMAGE_ADD)
+               nboxes += REGION_NUM_RECTS(r);
+
+       iter = list_entry(damage->embedded_box.list.prev,
+                         struct sna_damage_box,
+                         list);
+       n = iter->size - damage->remain;
+       boxes = malloc(sizeof(BoxRec)*nboxes);
+       if (boxes == NULL)
+               return;
+
+       if (list_is_empty(&damage->embedded_box.list)) {
+               memcpy(boxes,
+                      damage->embedded_box.box,
+                      n*sizeof(BoxRec));
+       } else {
+               if (boxes != (BoxPtr)(iter+1))
+                       memcpy(boxes, iter+1, n*sizeof(BoxRec));
+
+               iter = list_entry(iter->list.prev,
+                                 struct sna_damage_box,
+                                 list);
+               while (&iter->list != &damage->embedded_box.list) {
+                       memcpy(boxes + n, iter+1,
+                              iter->size * sizeof(BoxRec));
+                       n += iter->size;
+
+                       iter = list_entry(iter->list.prev,
+                                         struct sna_damage_box,
+                                         list);
+               }
+
+               memcpy(boxes + n,
+                      damage->embedded_box.box,
+                      sizeof(damage->embedded_box.box));
+               n += damage->embedded_box.size;
+       }
+
+       if (damage->mode == DAMAGE_ADD) {
+               memcpy(boxes + n,
+                      REGION_RECTS(r),
+                      REGION_NUM_RECTS(r)*sizeof(BoxRec));
+               assert(n + REGION_NUM_RECTS(r) == nboxes);
+               pixman_region_fini(r);
+               pixman_region_init_rects(r, boxes, nboxes);
+
+               assert(pixman_region_not_empty(r));
+               assert(damage->extents.x1 == r->extents.x1 &&
+                      damage->extents.y1 == r->extents.y1 &&
+                      damage->extents.x2 == r->extents.x2 &&
+                      damage->extents.y2 == r->extents.y2);
+       } else {
+               pixman_region16_t tmp;
+
+               pixman_region_init_rects(&tmp, boxes, nboxes);
+               pixman_region_subtract(r, r, &tmp);
+               pixman_region_fini(&tmp);
+
+               assert(damage->extents.x1 <= r->extents.x1 &&
+                      damage->extents.y1 <= r->extents.y1 &&
+                      damage->extents.x2 >= r->extents.x2 &&
+                      damage->extents.y2 >= r->extents.y2);
+       }
+
+       free(boxes);
+}
diff --git a/src/sna/sna_damage.h b/src/sna/sna_damage.h
new file mode 100644 (file)
index 0000000..5e800b7
--- /dev/null
@@ -0,0 +1,296 @@
+#ifndef SNA_DAMAGE_H
+#define SNA_DAMAGE_H
+
+#include <regionstr.h>
+#include <list.h>
+
+#include "compiler.h"
+
+struct sna_damage {
+       BoxRec extents;
+       pixman_region16_t region;
+       enum sna_damage_mode {
+               DAMAGE_ADD = 0,
+               DAMAGE_SUBTRACT,
+               DAMAGE_ALL,
+       } mode;
+       int remain, dirty;
+       BoxPtr box;
+       struct {
+               struct list list;
+               int size;
+               BoxRec box[8];
+       } embedded_box;
+};
+
+#define DAMAGE_IS_ALL(ptr) (((uintptr_t)(ptr))&1)
+#define DAMAGE_MARK_ALL(ptr) ((struct sna_damage *)(((uintptr_t)(ptr))|1))
+#define DAMAGE_PTR(ptr) ((struct sna_damage *)(((uintptr_t)(ptr))&~1))
+
+struct sna_damage *sna_damage_create(void);
+
+struct sna_damage *_sna_damage_combine(struct sna_damage *l,
+                                      struct sna_damage *r,
+                                      int dx, int dy);
+static inline void sna_damage_combine(struct sna_damage **l,
+                                     struct sna_damage *r,
+                                     int dx, int dy)
+{
+       assert(!DAMAGE_IS_ALL(*l));
+       *l = _sna_damage_combine(*l, DAMAGE_PTR(r), dx, dy);
+}
+
+fastcall struct sna_damage *_sna_damage_add(struct sna_damage *damage,
+                                           RegionPtr region);
+static inline void sna_damage_add(struct sna_damage **damage,
+                                 RegionPtr region)
+{
+       assert(!DAMAGE_IS_ALL(*damage));
+       *damage = _sna_damage_add(*damage, region);
+}
+
+fastcall struct sna_damage *_sna_damage_add_box(struct sna_damage *damage,
+                                               const BoxRec *box);
+static inline void sna_damage_add_box(struct sna_damage **damage,
+                                     const BoxRec *box)
+{
+       assert(!DAMAGE_IS_ALL(*damage));
+       *damage = _sna_damage_add_box(*damage, box);
+}
+
+struct sna_damage *_sna_damage_add_boxes(struct sna_damage *damage,
+                                        const BoxRec *box, int n,
+                                        int16_t dx, int16_t dy);
+static inline void sna_damage_add_boxes(struct sna_damage **damage,
+                                       const BoxRec *box, int n,
+                                       int16_t dx, int16_t dy)
+{
+       assert(!DAMAGE_IS_ALL(*damage));
+       *damage = _sna_damage_add_boxes(*damage, box, n, dx, dy);
+}
+
+struct sna_damage *_sna_damage_add_rectangles(struct sna_damage *damage,
+                                             const xRectangle *r, int n,
+                                             int16_t dx, int16_t dy);
+static inline void sna_damage_add_rectangles(struct sna_damage **damage,
+                                            const xRectangle *r, int n,
+                                            int16_t dx, int16_t dy)
+{
+       if (damage) {
+               assert(!DAMAGE_IS_ALL(*damage));
+               *damage = _sna_damage_add_rectangles(*damage, r, n, dx, dy);
+       }
+}
+
+struct sna_damage *_sna_damage_add_points(struct sna_damage *damage,
+                                         const DDXPointRec *p, int n,
+                                         int16_t dx, int16_t dy);
+static inline void sna_damage_add_points(struct sna_damage **damage,
+                                        const DDXPointRec *p, int n,
+                                        int16_t dx, int16_t dy)
+{
+       if (damage) {
+               assert(!DAMAGE_IS_ALL(*damage));
+               *damage = _sna_damage_add_points(*damage, p, n, dx, dy);
+       }
+}
+
+struct sna_damage *_sna_damage_is_all(struct sna_damage *damage,
+                                      int width, int height);
+static inline bool sna_damage_is_all(struct sna_damage **_damage,
+                                    int width, int height)
+{
+       struct sna_damage *damage = *_damage;
+
+       if (damage == NULL)
+               return false;
+       if (DAMAGE_IS_ALL(damage))
+               return true;
+
+       switch (damage->mode) {
+       case DAMAGE_ALL:
+               assert(0);
+               return true;
+       case DAMAGE_SUBTRACT:
+               return false;
+       default:
+               assert(0);
+       case DAMAGE_ADD:
+               if (damage->extents.x2 < width  || damage->extents.x1 > 0)
+                       return false;
+               if (damage->extents.y2 < height || damage->extents.y1 > 0)
+                       return false;
+               damage = _sna_damage_is_all(damage, width, height);
+               if (damage->mode == DAMAGE_ALL) {
+                       *_damage = DAMAGE_MARK_ALL(damage);
+                       return true;
+               } else {
+                       *_damage = damage;
+                       return false;
+               }
+       }
+}
+
+struct sna_damage *__sna_damage_all(struct sna_damage *damage,
+                                   int width, int height);
+static inline struct sna_damage *
+_sna_damage_all(struct sna_damage *damage,
+               int width, int height)
+{
+       damage = __sna_damage_all(damage, width, height);
+       return DAMAGE_MARK_ALL(damage);
+}
+
+static inline void sna_damage_all(struct sna_damage **damage,
+                                 int width, int height)
+{
+       if (!DAMAGE_IS_ALL(*damage))
+               *damage = _sna_damage_all(*damage, width, height);
+}
+
+fastcall struct sna_damage *_sna_damage_subtract(struct sna_damage *damage,
+                                                RegionPtr region);
+static inline void sna_damage_subtract(struct sna_damage **damage,
+                                      RegionPtr region)
+{
+       *damage = _sna_damage_subtract(DAMAGE_PTR(*damage), region);
+       assert(*damage == NULL || (*damage)->mode != DAMAGE_ALL);
+}
+
+fastcall struct sna_damage *_sna_damage_subtract_box(struct sna_damage *damage,
+                                                    const BoxRec *box);
+static inline void sna_damage_subtract_box(struct sna_damage **damage,
+                                          const BoxRec *box)
+{
+       *damage = _sna_damage_subtract_box(DAMAGE_PTR(*damage), box);
+       assert(*damage == NULL || (*damage)->mode != DAMAGE_ALL);
+}
+
+fastcall struct sna_damage *_sna_damage_subtract_boxes(struct sna_damage *damage,
+                                                      const BoxRec *box, int n,
+                                                      int dx, int dy);
+static inline void sna_damage_subtract_boxes(struct sna_damage **damage,
+                                            const BoxRec *box, int n,
+                                            int dx, int dy)
+{
+       *damage = _sna_damage_subtract_boxes(DAMAGE_PTR(*damage),
+                                            box, n, dx, dy);
+       assert(*damage == NULL || (*damage)->mode != DAMAGE_ALL);
+}
+
+bool _sna_damage_intersect(struct sna_damage *damage,
+                         RegionPtr region, RegionPtr result);
+
+static inline bool sna_damage_intersect(struct sna_damage *damage,
+                                       RegionPtr region, RegionPtr result)
+{
+       assert(damage);
+       assert(RegionNotEmpty(region));
+       assert(!DAMAGE_IS_ALL(damage));
+
+       return _sna_damage_intersect(damage, region, result);
+}
+
+static inline bool
+sna_damage_overlaps_box(const struct sna_damage *damage,
+                       const BoxRec *box)
+{
+       if (box->x2 <= damage->extents.x1 ||
+           box->x1 >= damage->extents.x2)
+               return false;
+
+       if (box->y2 <= damage->extents.y1 ||
+           box->y1 >= damage->extents.y2)
+               return false;
+
+       return true;
+}
+
+int _sna_damage_contains_box(struct sna_damage *damage,
+                            const BoxRec *box);
+static inline int sna_damage_contains_box(struct sna_damage *damage,
+                                         const BoxRec *box)
+{
+       if (DAMAGE_IS_ALL(damage))
+               return PIXMAN_REGION_IN;
+
+       return _sna_damage_contains_box(damage, box);
+}
+bool _sna_damage_contains_box__no_reduce(const struct sna_damage *damage,
+                                       const BoxRec *box);
+static inline bool
+sna_damage_contains_box__no_reduce(const struct sna_damage *damage,
+                                  const BoxRec *box)
+{
+       assert(!DAMAGE_IS_ALL(damage));
+       return _sna_damage_contains_box__no_reduce(damage, box);
+}
+
+int _sna_damage_get_boxes(struct sna_damage *damage, BoxPtr *boxes);
+static inline int
+sna_damage_get_boxes(struct sna_damage *damage, BoxPtr *boxes)
+{
+       assert(damage);
+
+       if (DAMAGE_IS_ALL(damage)) {
+               *boxes = &DAMAGE_PTR(damage)->extents;
+               return 1;
+       } else
+               return _sna_damage_get_boxes(damage, boxes);
+}
+
+struct sna_damage *_sna_damage_reduce(struct sna_damage *damage);
+static inline void sna_damage_reduce(struct sna_damage **damage)
+{
+       if (*damage == NULL)
+               return;
+
+       if (!DAMAGE_IS_ALL(*damage) && (*damage)->dirty)
+               *damage = _sna_damage_reduce(*damage);
+}
+
+static inline void sna_damage_reduce_all(struct sna_damage **_damage,
+                                        int width, int height)
+{
+       struct sna_damage *damage = *_damage;
+
+       DBG(("%s(width=%d, height=%d)\n", __FUNCTION__, width, height));
+
+       if (damage == NULL || DAMAGE_IS_ALL(damage))
+               return;
+
+       if (damage->mode == DAMAGE_ADD &&
+           damage->extents.x1 <= 0 &&
+           damage->extents.y1 <= 0 &&
+           damage->extents.x2 >= width &&
+           damage->extents.y2 >= height) {
+               if (damage->dirty) {
+                       damage = *_damage = _sna_damage_reduce(damage);
+                       if (damage == NULL)
+                               return;
+               }
+
+               if (damage->region.data == NULL)
+                       *_damage = _sna_damage_all(damage, width, height);
+       }
+}
+
+void __sna_damage_destroy(struct sna_damage *damage);
+static inline void sna_damage_destroy(struct sna_damage **damage)
+{
+       if (*damage == NULL)
+               return;
+
+       __sna_damage_destroy(DAMAGE_PTR(*damage));
+       *damage = NULL;
+}
+
+void _sna_damage_debug_get_region(struct sna_damage *damage, RegionRec *r);
+
+#if HAS_DEBUG_FULL && TEST_DAMAGE
+void sna_damage_selftest(void);
+#else
+static inline void sna_damage_selftest(void) {}
+#endif
+
+#endif /* SNA_DAMAGE_H */
diff --git a/src/sna/sna_display.c b/src/sna/sna_display.c
new file mode 100644 (file)
index 0000000..61d1a9f
--- /dev/null
@@ -0,0 +1,3246 @@
+/*
+ * Copyright © 2007 Red Hat, Inc.
+ *
+ * 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.
+ *
+ * Authors:
+ *    Dave Airlie <airlied@redhat.com>
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdint.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <errno.h>
+#include <poll.h>
+#include <ctype.h>
+
+#include <xorgVersion.h>
+#include <X11/Xatom.h>
+#include <X11/extensions/dpmsconst.h>
+#include <xf86drm.h>
+#include <xf86DDC.h> /* for xf86InterpretEDID */
+
+#include "sna.h"
+#include "sna_reg.h"
+#include "fb/fbpict.h"
+
+#include "intel_options.h"
+
+#define KNOWN_MODE_FLAGS ((1<<14)-1)
+
+#if 0
+#define __DBG DBG
+#else
+#define __DBG(x)
+#endif
+
+struct sna_crtc {
+       struct drm_mode_modeinfo kmode;
+       int dpms_mode;
+       PixmapPtr scanout_pixmap;
+       struct kgem_bo *bo;
+       uint32_t cursor;
+       bool shadow;
+       bool fallback_shadow;
+       bool transform;
+       uint8_t id;
+       uint8_t pipe;
+       uint8_t plane;
+       struct list link;
+};
+
+struct sna_property {
+       drmModePropertyPtr mode_prop;
+       uint64_t value;
+       int num_atoms; /* if range prop, num_atoms == 1; if enum prop, num_atoms == num_enums + 1 */
+       Atom *atoms;
+};
+
+struct sna_output {
+       int id;
+       drmModeConnectorPtr mode_output;
+       int num_props;
+       struct sna_property *props;
+
+       bool has_panel_limits;
+       int panel_hdisplay;
+       int panel_vdisplay;
+
+       int dpms_mode;
+       char *backlight_iface;
+       int backlight_active_level;
+       int backlight_max;
+       struct list link;
+};
+
+static inline struct sna_crtc *to_sna_crtc(xf86CrtcPtr crtc)
+{
+       return crtc->driver_private;
+}
+
+#define BACKLIGHT_CLASS "/sys/class/backlight"
+
+/* Enough for 10 digits of backlight + '\n' + '\0' */
+#define BACKLIGHT_VALUE_LEN 12
+
+static inline uint32_t fb_id(struct kgem_bo *bo)
+{
+       return bo->delta;
+}
+
+int sna_crtc_id(xf86CrtcPtr crtc)
+{
+       return to_sna_crtc(crtc)->id;
+}
+
+int sna_crtc_to_pipe(xf86CrtcPtr crtc)
+{
+       return to_sna_crtc(crtc)->pipe;
+}
+
+int sna_crtc_to_plane(xf86CrtcPtr crtc)
+{
+       return to_sna_crtc(crtc)->plane;
+}
+
+static unsigned get_fb(struct sna *sna, struct kgem_bo *bo,
+                      int width, int height)
+{
+       ScrnInfoPtr scrn = sna->scrn;
+       struct drm_mode_fb_cmd arg;
+
+       assert(bo->refcnt);
+       assert(bo->proxy == NULL);
+       if (bo->delta) {
+               DBG(("%s: reusing fb=%d for handle=%d\n",
+                    __FUNCTION__, bo->delta, bo->handle));
+               return bo->delta;
+       }
+
+       DBG(("%s: create fb %dx%d@%d/%d\n",
+            __FUNCTION__, width, height, scrn->depth, scrn->bitsPerPixel));
+
+       assert(bo->tiling != I915_TILING_Y);
+       assert((bo->pitch & 63) == 0);
+
+       VG_CLEAR(arg);
+       arg.width = width;
+       arg.height = height;
+       arg.pitch = bo->pitch;
+       arg.bpp = scrn->bitsPerPixel;
+       arg.depth = scrn->depth;
+       arg.handle = bo->handle;
+
+       assert(sna->scrn->vtSema); /* must be master */
+       if (drmIoctl(sna->kgem.fd, DRM_IOCTL_MODE_ADDFB, &arg)) {
+               xf86DrvMsg(scrn->scrnIndex, X_ERROR,
+                          "%s: failed to add fb: %dx%d depth=%d, bpp=%d, pitch=%d: %d\n",
+                          __FUNCTION__, width, height,
+                          scrn->depth, scrn->bitsPerPixel, bo->pitch, errno);
+               return 0;
+       }
+
+       bo->scanout = true;
+       return bo->delta = arg.fb_id;
+}
+
+static uint32_t gem_create(int fd, int size)
+{
+       struct drm_i915_gem_create create;
+
+       VG_CLEAR(create);
+       create.handle = 0;
+       create.size = ALIGN(size, 4096);
+       (void)drmIoctl(fd, DRM_IOCTL_I915_GEM_CREATE, &create);
+
+       return create.handle;
+}
+
+static void gem_close(int fd, uint32_t handle)
+{
+       struct drm_gem_close close;
+
+       VG_CLEAR(close);
+       close.handle = handle;
+       (void)drmIoctl(fd, DRM_IOCTL_GEM_CLOSE, &close);
+}
+
+static void
+sna_output_backlight_set(xf86OutputPtr output, int level)
+{
+       struct sna_output *sna_output = output->driver_private;
+       char path[1024], val[BACKLIGHT_VALUE_LEN];
+       int fd, len, ret;
+
+       DBG(("%s: level=%d\n", __FUNCTION__, level));
+
+       if (level > sna_output->backlight_max)
+               level = sna_output->backlight_max;
+       if (!sna_output->backlight_iface || level < 0)
+               return;
+
+       len = snprintf(val, BACKLIGHT_VALUE_LEN, "%d\n", level);
+       sprintf(path, "%s/%s/brightness",
+               BACKLIGHT_CLASS, sna_output->backlight_iface);
+       fd = open(path, O_RDWR);
+       if (fd == -1) {
+               xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, "failed to open %s for backlight "
+                          "control: %s\n", path, strerror(errno));
+               return;
+       }
+
+       ret = write(fd, val, len);
+       if (ret == -1) {
+               xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, "write to %s for backlight "
+                          "control failed: %s\n", path, strerror(errno));
+       }
+
+       close(fd);
+}
+
+static int
+sna_output_backlight_get(xf86OutputPtr output)
+{
+       struct sna_output *sna_output = output->driver_private;
+       char path[1024], val[BACKLIGHT_VALUE_LEN];
+       int fd, level;
+
+       sprintf(path, "%s/%s/actual_brightness",
+               BACKLIGHT_CLASS, sna_output->backlight_iface);
+       fd = open(path, O_RDONLY);
+       if (fd == -1) {
+               xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, "failed to open %s "
+                          "for backlight control: %s\n", path, strerror(errno));
+               return -1;
+       }
+
+       memset(val, 0, sizeof(val));
+       if (read(fd, val, BACKLIGHT_VALUE_LEN) == -1) {
+               close(fd);
+               return -1;
+       }
+
+       close(fd);
+
+       level = atoi(val);
+       DBG(("%s: level=%d (max=%d)\n",
+            __FUNCTION__, level, sna_output->backlight_max));
+
+       if (level > sna_output->backlight_max)
+               level = sna_output->backlight_max;
+       else if (level < 0)
+               level = -1;
+       return level;
+}
+
+static int
+sna_output_backlight_get_max(xf86OutputPtr output)
+{
+       struct sna_output *sna_output = output->driver_private;
+       char path[1024], val[BACKLIGHT_VALUE_LEN];
+       int fd, max = 0;
+
+       sprintf(path, "%s/%s/max_brightness",
+               BACKLIGHT_CLASS, sna_output->backlight_iface);
+       fd = open(path, O_RDONLY);
+       if (fd == -1) {
+               xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, "failed to open %s "
+                          "for backlight control: %s\n", path, strerror(errno));
+               return -1;
+       }
+
+       memset(val, 0, sizeof(val));
+       if (read(fd, val, BACKLIGHT_VALUE_LEN) == -1) {
+               close(fd);
+               return -1;
+       }
+
+       close(fd);
+
+       max = atoi(val);
+       if (max <= 0)
+               max = -1;
+       return max;
+}
+
+enum {
+       PLATFORM,
+       FIRMWARE,
+       RAW,
+       NAMED,
+};
+
+static char *
+has_user_backlight_override(xf86OutputPtr output)
+{
+       struct sna_output *sna_output = output->driver_private;
+       struct sna *sna = to_sna(output->scrn);
+       char *str;
+       int max;
+
+       str = xf86GetOptValString(sna->Options, OPTION_BACKLIGHT);
+       if (str == NULL)
+               return NULL;
+
+       sna_output->backlight_iface = str;
+       max = sna_output_backlight_get_max(output);
+       sna_output->backlight_iface = NULL;
+       if (max <= 0) {
+               xf86DrvMsg(output->scrn->scrnIndex, X_ERROR,
+                          "unrecognised backlight control interface '%s'\n",
+                          str);
+               return NULL;
+       }
+
+       return str;
+}
+
+static char *
+has_device_backlight(xf86OutputPtr output, int *best_type)
+{
+       struct sna_output *sna_output = output->driver_private;
+       struct sna *sna = to_sna(output->scrn);
+       struct pci_device *pci = sna->PciInfo;
+       char path[1024];
+       char *best_iface = NULL;
+       DIR *dir;
+       struct dirent *de;
+
+       snprintf(path, sizeof(path),
+                "/sys/bus/pci/devices/%04x:%02x:%02x.%d/backlight",
+                pci->domain, pci->bus, pci->dev, pci->func);
+
+       DBG(("%s: scanning %s\n", __FUNCTION__, path));
+       dir = opendir(path);
+       if (dir == NULL)
+               return NULL;
+
+       while ((de = readdir(dir))) {
+               char buf[100];
+               int fd, v;
+
+               if (*de->d_name == '.')
+                       continue;
+
+               DBG(("%s: %s\n", __FUNCTION__, de->d_name));
+               snprintf(path, sizeof(path), "%s/%s/type",
+                        BACKLIGHT_CLASS, de->d_name);
+
+               v = -1;
+               fd = open(path, O_RDONLY);
+               if (fd >= 0) {
+                       v = read(fd, buf, sizeof(buf)-1);
+                       close(fd);
+               }
+               if (v > 0) {
+                       while (v > 0 && isspace(buf[v-1]))
+                               v--;
+                       buf[v] = '\0';
+
+                       if (strcmp(buf, "raw") == 0)
+                               v = RAW;
+                       else if (strcmp(buf, "platform") == 0)
+                               v = PLATFORM;
+                       else if (strcmp(buf, "firmware") == 0)
+                               v = FIRMWARE;
+                       else
+                               v = INT_MAX;
+               } else
+                       v = INT_MAX;
+
+               if (v < *best_type) {
+                       char *copy;
+                       int max;
+
+                       sna_output->backlight_iface = de->d_name;
+                       max = sna_output_backlight_get_max(output);
+                       sna_output->backlight_iface = NULL;
+                       if (max <= 0)
+                               continue;
+
+                       copy = strdup(de->d_name);
+                       if (copy) {
+                               free(best_iface);
+                               best_iface = copy;
+                               *best_type = v;
+                       }
+               }
+       }
+       closedir(dir);
+
+       return best_iface;
+}
+
+static char *
+has_backlight(xf86OutputPtr output, int *best_type)
+{
+       static const char *known_interfaces[] = {
+               "gmux_backlight",
+               "asus-laptop",
+               "asus-nb-wmi",
+               "eeepc",
+               "thinkpad_screen",
+               "mbp_backlight",
+               "fujitsu-laptop",
+               "sony",
+               "samsung",
+               "acpi_video1",
+               "acpi_video0",
+               "intel_backlight",
+       };
+       struct sna_output *sna_output = output->driver_private;
+       char *best_iface = NULL;
+       DIR *dir;
+       struct dirent *de;
+
+       dir = opendir(BACKLIGHT_CLASS);
+       if (dir == NULL)
+               return NULL;
+
+       while ((de = readdir(dir))) {
+               char path[1024];
+               char buf[100];
+               int fd, v;
+
+               if (*de->d_name == '.')
+                       continue;
+
+               snprintf(path, sizeof(path), "%s/%s/type",
+                        BACKLIGHT_CLASS, de->d_name);
+
+               v = -1;
+               fd = open(path, O_RDONLY);
+               if (fd >= 0) {
+                       v = read(fd, buf, sizeof(buf)-1);
+                       close(fd);
+               }
+               if (v > 0) {
+                       while (v > 0 && isspace(buf[v-1]))
+                               v--;
+                       buf[v] = '\0';
+
+                       if (strcmp(buf, "raw") == 0)
+                               v = RAW;
+                       else if (strcmp(buf, "platform") == 0)
+                               v = PLATFORM;
+                       else if (strcmp(buf, "firmware") == 0)
+                               v = FIRMWARE;
+                       else
+                               v = NAMED;
+               } else
+                       v = NAMED;
+
+               /* Fallback to priority list of known iface for old kernels */
+               if (v == NAMED) {
+                       int i;
+                       for (i = 0; i < ARRAY_SIZE(known_interfaces); i++) {
+                               if (strcmp(de->d_name, known_interfaces[i]) == 0)
+                                       break;
+                       }
+                       v += i;
+               }
+
+               if (v < *best_type) {
+                       char *copy;
+                       int max;
+
+                       /* XXX detect right backlight for multi-GPU/panels */
+
+                       sna_output->backlight_iface = de->d_name;
+                       max = sna_output_backlight_get_max(output);
+                       sna_output->backlight_iface = NULL;
+                       if (max <= 0)
+                               continue;
+
+                       copy = strdup(de->d_name);
+                       if (copy) {
+                               free(best_iface);
+                               best_iface = copy;
+                               *best_type = v;
+                       }
+               }
+       }
+       closedir(dir);
+
+       return best_iface;
+}
+
+static void
+sna_output_backlight_init(xf86OutputPtr output)
+{
+       struct sna_output *sna_output = output->driver_private;
+       MessageType from = X_PROBED;
+       char *best_iface;
+       int best_type;
+
+       best_type = INT_MAX;
+       best_iface = has_user_backlight_override(output);
+       if (best_iface)
+               goto done;
+
+       best_iface = has_device_backlight(output, &best_type);
+       if (best_iface)
+               goto done;
+
+       best_iface = has_backlight(output, &best_type);
+       if (best_iface)
+               goto done;
+
+       return;
+
+done:
+       sna_output->backlight_iface = best_iface;
+       sna_output->backlight_max = sna_output_backlight_get_max(output);
+       sna_output->backlight_active_level = sna_output_backlight_get(output);
+       switch (best_type) {
+       case INT_MAX: best_iface = "user"; from = X_CONFIG; break;
+       case FIRMWARE: best_iface = "firmware"; break;
+       case PLATFORM: best_iface = "platform"; break;
+       case RAW: best_iface = "raw"; break;
+       default: best_iface = "unknown"; break;
+       }
+       xf86DrvMsg(output->scrn->scrnIndex, from,
+                  "found backlight control interface %s (type '%s')\n",
+                  sna_output->backlight_iface, best_iface);
+}
+
+static void
+mode_from_kmode(ScrnInfoPtr scrn,
+               drmModeModeInfoPtr kmode,
+               DisplayModePtr  mode)
+{
+       memset(mode, 0, sizeof(DisplayModeRec));
+       mode->status = MODE_OK;
+
+       mode->Clock = kmode->clock;
+
+       mode->HDisplay = kmode->hdisplay;
+       mode->HSyncStart = kmode->hsync_start;
+       mode->HSyncEnd = kmode->hsync_end;
+       mode->HTotal = kmode->htotal;
+       mode->HSkew = kmode->hskew;
+
+       mode->VDisplay = kmode->vdisplay;
+       mode->VSyncStart = kmode->vsync_start;
+       mode->VSyncEnd = kmode->vsync_end;
+       mode->VTotal = kmode->vtotal;
+       mode->VScan = kmode->vscan;
+
+       mode->Flags = kmode->flags;
+       mode->name = strdup(kmode->name);
+
+       if (kmode->type & DRM_MODE_TYPE_DRIVER)
+               mode->type = M_T_DRIVER;
+       if (kmode->type & DRM_MODE_TYPE_PREFERRED)
+               mode->type |= M_T_PREFERRED;
+
+       if (mode->status == MODE_OK && kmode->flags & ~KNOWN_MODE_FLAGS)
+               mode->status = MODE_BAD; /* unknown flags => unhandled */
+
+       xf86SetModeCrtc (mode, scrn->adjustFlags);
+}
+
+static void
+mode_to_kmode(struct drm_mode_modeinfo *kmode, DisplayModePtr mode)
+{
+       memset(kmode, 0, sizeof(*kmode));
+
+       kmode->clock = mode->Clock;
+       kmode->hdisplay = mode->HDisplay;
+       kmode->hsync_start = mode->HSyncStart;
+       kmode->hsync_end = mode->HSyncEnd;
+       kmode->htotal = mode->HTotal;
+       kmode->hskew = mode->HSkew;
+
+       kmode->vdisplay = mode->VDisplay;
+       kmode->vsync_start = mode->VSyncStart;
+       kmode->vsync_end = mode->VSyncEnd;
+       kmode->vtotal = mode->VTotal;
+       kmode->vscan = mode->VScan;
+
+       kmode->flags = mode->Flags;
+       if (mode->name)
+               strncpy(kmode->name, mode->name, DRM_DISPLAY_MODE_LEN);
+       kmode->name[DRM_DISPLAY_MODE_LEN-1] = 0;
+}
+
+static bool sna_crtc_is_bound(struct sna *sna, xf86CrtcPtr crtc)
+{
+       struct sna_crtc *sna_crtc = to_sna_crtc(crtc);
+       struct drm_mode_crtc mode;
+
+       if (!sna_crtc->bo)
+               return false;
+
+       VG_CLEAR(mode);
+       mode.crtc_id = sna_crtc->id;
+       if (drmIoctl(sna->kgem.fd, DRM_IOCTL_MODE_GETCRTC, &mode))
+               return false;
+
+       DBG(("%s: crtc=%d, mode valid?=%d, fb attached?=%d\n", __FUNCTION__,
+            mode.crtc_id, mode.mode_valid, fb_id(sna_crtc->bo) == mode.fb_id));
+       return mode.mode_valid && fb_id(sna_crtc->bo) == mode.fb_id;
+}
+
+static void
+sna_crtc_force_outputs_on(xf86CrtcPtr crtc)
+{
+       xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
+       int i;
+
+       /* DPMS handling by the kernel is inconsistent, so after setting a
+        * mode on an output presume that we intend for it to be on, or that
+        * the kernel will force it on.
+        *
+        * So force DPMS to be on for all connected outputs, and restore
+        * the backlight.
+        */
+       for (i = 0; i < xf86_config->num_output; i++) {
+               xf86OutputPtr output = xf86_config->output[i];
+
+               if (output->crtc != crtc)
+                       continue;
+
+               output->funcs->dpms(output, DPMSModeOn);
+       }
+
+       to_sna_crtc(crtc)->dpms_mode = DPMSModeOn;
+}
+
+static bool
+sna_crtc_apply(xf86CrtcPtr crtc)
+{
+       struct sna *sna = to_sna(crtc->scrn);
+       struct sna_crtc *sna_crtc = to_sna_crtc(crtc);
+       xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
+       struct drm_mode_crtc arg;
+       uint32_t output_ids[16];
+       int output_count = 0;
+       int i;
+
+       DBG(("%s\n", __FUNCTION__));
+       kgem_bo_submit(&sna->kgem, sna_crtc->bo);
+
+       assert(xf86_config->num_output < ARRAY_SIZE(output_ids));
+
+       for (i = 0; i < xf86_config->num_output; i++) {
+               xf86OutputPtr output = xf86_config->output[i];
+               struct sna_output *sna_output;
+
+               if (output->crtc != crtc)
+                       continue;
+
+               sna_output = output->driver_private;
+               output_ids[output_count] =
+                       sna_output->mode_output->connector_id;
+               output_count++;
+       }
+
+       VG_CLEAR(arg);
+       arg.crtc_id = sna_crtc->id;
+       arg.fb_id = fb_id(sna_crtc->bo);
+       if (sna_crtc->transform) {
+               arg.x = 0;
+               arg.y = 0;
+       } else {
+               arg.x = crtc->x;
+               arg.y = crtc->y;
+       }
+       arg.set_connectors_ptr = (uintptr_t)output_ids;
+       arg.count_connectors = output_count;
+       arg.mode = sna_crtc->kmode;
+       arg.mode_valid = 1;
+
+       DBG(("%s: applying crtc [%d] mode=%dx%d+%d+%d@%d, fb=%d%s%s update to %d outputs\n",
+            __FUNCTION__, sna_crtc->id,
+            arg.mode.hdisplay,
+            arg.mode.vdisplay,
+            arg.x, arg.y,
+            arg.mode.clock,
+            arg.fb_id,
+            sna_crtc->shadow ? " [shadow]" : "",
+            sna_crtc->transform ? " [transformed]" : "",
+            output_count));
+
+       if (drmIoctl(sna->kgem.fd, DRM_IOCTL_MODE_SETCRTC, &arg))
+               return false;
+
+       sna_crtc_force_outputs_on(crtc);
+       return true;
+}
+
+static bool sna_mode_enable_shadow(struct sna *sna)
+{
+       ScreenPtr screen = sna->scrn->pScreen;
+
+       DBG(("%s\n", __FUNCTION__));
+       assert(sna->mode.shadow == NULL);
+       assert(sna->mode.shadow_damage == NULL);
+       assert(sna->mode.shadow_active == 0);
+
+       sna->mode.shadow_damage = DamageCreate(NULL, NULL,
+                                              DamageReportNone, TRUE,
+                                              screen, screen);
+       if (!sna->mode.shadow_damage)
+               return false;
+
+       DamageRegister(&sna->front->drawable, sna->mode.shadow_damage);
+       return true;
+}
+
+static void sna_mode_disable_shadow(struct sna *sna)
+{
+       if (!sna->mode.shadow_damage)
+               return;
+
+       DBG(("%s\n", __FUNCTION__));
+
+       DamageUnregister(&sna->front->drawable, sna->mode.shadow_damage);
+       DamageDestroy(sna->mode.shadow_damage);
+       sna->mode.shadow_damage = NULL;
+
+       if (sna->mode.shadow) {
+               kgem_bo_destroy(&sna->kgem, sna->mode.shadow);
+               sna->mode.shadow = NULL;
+       }
+
+       sna->mode.shadow_active = 0;
+}
+
+static bool sna_crtc_enable_shadow(struct sna *sna, struct sna_crtc *crtc)
+{
+       if (crtc->shadow) {
+               assert(sna->mode.shadow_damage && sna->mode.shadow_active);
+               return true;
+       }
+
+       DBG(("%s: enabling for crtc %d\n", __FUNCTION__, crtc->id));
+
+       if (!sna->mode.shadow_active) {
+               if (!sna_mode_enable_shadow(sna))
+                       return false;
+               assert(sna->mode.shadow_damage);
+               assert(sna->mode.shadow == NULL);
+       }
+
+       crtc->shadow = true;
+       sna->mode.shadow_active++;
+       return true;
+}
+
+static void sna_crtc_disable_shadow(struct sna *sna, struct sna_crtc *crtc)
+{
+       crtc->fallback_shadow = false;
+       if (!crtc->shadow)
+               return;
+
+       DBG(("%s: disabling for crtc %d\n", __FUNCTION__, crtc->id));
+       assert(sna->mode.shadow_active > 0);
+
+       if (!--sna->mode.shadow_active)
+               sna_mode_disable_shadow(sna);
+
+       crtc->shadow = false;
+}
+
+static void
+sna_crtc_disable(xf86CrtcPtr crtc)
+{
+       struct sna *sna = to_sna(crtc->scrn);
+       struct sna_crtc *sna_crtc = to_sna_crtc(crtc);
+       struct drm_mode_crtc arg;
+
+       DBG(("%s: disabling crtc [%d]\n", __FUNCTION__, sna_crtc->id));
+
+       memset(&arg, 0, sizeof(arg));
+       arg.crtc_id = sna_crtc->id;
+       (void)drmIoctl(sna->kgem.fd, DRM_IOCTL_MODE_SETCRTC, &arg);
+
+       sna_crtc_disable_shadow(sna, sna_crtc);
+
+       if (sna_crtc->bo) {
+               kgem_bo_destroy(&sna->kgem, sna_crtc->bo);
+               sna_crtc->bo = NULL;
+       }
+
+       sna_crtc->dpms_mode = DPMSModeOff;
+}
+
+static void update_flush_interval(struct sna *sna)
+{
+       xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(sna->scrn);
+       int i, max_vrefresh = 0;
+
+       for (i = 0; i < xf86_config->num_crtc; i++) {
+               xf86CrtcPtr crtc = xf86_config->crtc[i];
+
+               if (!crtc->enabled) {
+                       DBG(("%s: CRTC:%d (pipe %d) disabled\n",
+                            __FUNCTION__,i, to_sna_crtc(crtc)->pipe));
+                       continue;
+               }
+
+               if (to_sna_crtc(crtc)->dpms_mode != DPMSModeOn) {
+                       DBG(("%s: CRTC:%d (pipe %d) turned off\n",
+                            __FUNCTION__,i, to_sna_crtc(crtc)->pipe));
+                       continue;
+               }
+
+               DBG(("%s: CRTC:%d (pipe %d) vrefresh=%f\n",
+                    __FUNCTION__, i, to_sna_crtc(crtc)->pipe,
+                    xf86ModeVRefresh(&crtc->mode)));
+               max_vrefresh = max(max_vrefresh, xf86ModeVRefresh(&crtc->mode));
+       }
+
+       if (max_vrefresh == 0)
+               sna->vblank_interval = 0;
+       else
+               sna->vblank_interval = 1000 / max_vrefresh; /* Hz -> ms */
+
+       DBG(("max_vrefresh=%d, vblank_interval=%d ms\n",
+              max_vrefresh, sna->vblank_interval));
+}
+
+void sna_mode_disable_unused(struct sna *sna)
+{
+       xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(sna->scrn);
+       int i;
+
+       DBG(("%s\n", __FUNCTION__));
+
+       /* Force consistency between kernel and ourselves */
+       for (i = 0; i < xf86_config->num_crtc; i++) {
+               if (!xf86_config->crtc[i]->enabled)
+                       sna_crtc_disable(xf86_config->crtc[i]);
+       }
+}
+
+static struct kgem_bo *sna_create_bo_for_fbcon(struct sna *sna,
+                                              const struct drm_mode_fb_cmd *fbcon)
+{
+       struct drm_gem_flink flink;
+       struct kgem_bo *bo;
+       int ret;
+
+       /* Create a new reference for the fbcon so that we can track it
+        * using a normal bo and so that when we call gem_close on it we
+        * delete our reference and not fbcon's!
+        */
+       VG_CLEAR(flink);
+       flink.handle = fbcon->handle;
+       ret = drmIoctl(sna->kgem.fd, DRM_IOCTL_GEM_FLINK, &flink);
+       if (ret)
+               return NULL;
+
+       bo = kgem_create_for_name(&sna->kgem, flink.name);
+       if (bo == NULL)
+               return NULL;
+
+       bo->pitch = fbcon->pitch;
+       return bo;
+}
+
+/* Copy the current framebuffer contents into the front-buffer for a seamless
+ * transition from e.g. plymouth.
+ */
+void sna_copy_fbcon(struct sna *sna)
+{
+       xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(sna->scrn);
+       struct drm_mode_fb_cmd fbcon;
+       PixmapPtr scratch;
+       struct sna_pixmap *priv;
+       struct kgem_bo *bo;
+       BoxRec box;
+       bool ok;
+       int sx, sy;
+       int dx, dy;
+       int i;
+
+       if (wedged(sna))
+               return;
+
+       DBG(("%s\n", __FUNCTION__));
+
+       /* Scan the connectors for a framebuffer and assume that is the fbcon */
+       VG_CLEAR(fbcon);
+       fbcon.fb_id = 0;
+       for (i = 0; i < xf86_config->num_crtc; i++) {
+               struct sna_crtc *crtc = to_sna_crtc(xf86_config->crtc[i]);
+               struct drm_mode_crtc mode;
+
+               VG_CLEAR(mode);
+               mode.crtc_id = crtc->id;
+               if (drmIoctl(sna->kgem.fd, DRM_IOCTL_MODE_GETCRTC, &mode))
+                       continue;
+               if (!mode.fb_id)
+                       continue;
+
+               fbcon.fb_id = mode.fb_id;
+               if (drmIoctl(sna->kgem.fd, DRM_IOCTL_MODE_GETFB, &fbcon)) {
+                       fbcon.fb_id = 0;
+                       continue;
+               }
+               break;
+       }
+       if (fbcon.fb_id == 0) {
+               DBG(("%s: no fbcon found\n", __FUNCTION__));
+               return;
+       }
+
+       /* Wrap the fbcon in a pixmap so that we select the right formats
+        * in the render copy in case we need to preserve the fbcon
+        * across a depth change upon starting X.
+        */
+       scratch = GetScratchPixmapHeader(sna->scrn->pScreen,
+                                       fbcon.width, fbcon.height,
+                                       fbcon.depth, fbcon.bpp,
+                                       0, NULL);
+       if (scratch == NullPixmap)
+               return;
+
+       box.x1 = box.y1 = 0;
+       box.x2 = min(fbcon.width, sna->front->drawable.width);
+       box.y2 = min(fbcon.height, sna->front->drawable.height);
+
+       bo = sna_create_bo_for_fbcon(sna, &fbcon);
+       if (bo == NULL)
+               goto cleanup_scratch;
+
+       DBG(("%s: fbcon handle=%d\n", __FUNCTION__, bo->handle));
+
+       priv = sna_pixmap(sna->front);
+       assert(priv && priv->gpu_bo);
+
+       sx = dx = 0;
+       if (box.x2 < (uint16_t)fbcon.width)
+               sx = (fbcon.width - box.x2) / 2;
+       if (box.x2 < sna->front->drawable.width)
+               dx = (sna->front->drawable.width - box.x2) / 2;
+
+       sy = dy = 0;
+       if (box.y2 < (uint16_t)fbcon.height)
+               sy = (fbcon.height - box.y2) / 2;
+       if (box.y2 < sna->front->drawable.height)
+               dy = (sna->front->drawable.height - box.y2) / 2;
+
+       ok = sna->render.copy_boxes(sna, GXcopy,
+                                   scratch, bo, sx, sy,
+                                   sna->front, priv->gpu_bo, dx, dy,
+                                   &box, 1, 0);
+       if (!DAMAGE_IS_ALL(priv->gpu_damage))
+               sna_damage_add_box(&priv->gpu_damage, &box);
+
+       kgem_bo_destroy(&sna->kgem, bo);
+
+       sna->scrn->pScreen->canDoBGNoneRoot = ok;
+
+cleanup_scratch:
+       FreeScratchPixmapHeader(scratch);
+}
+
+static bool use_shadow(struct sna *sna, xf86CrtcPtr crtc)
+{
+       RRTransformPtr transform;
+       PictTransform crtc_to_fb;
+       struct pict_f_transform f_crtc_to_fb, f_fb_to_crtc;
+       BoxRec b;
+
+       assert(sna->scrn->virtualX && sna->scrn->virtualY);
+
+       if (sna->flags & SNA_FORCE_SHADOW) {
+               DBG(("%s: forcing shadow\n", __FUNCTION__));
+               return true;
+       }
+
+       if (to_sna_crtc(crtc)->fallback_shadow) {
+               DBG(("%s: fallback shadow\n", __FUNCTION__));
+               return true;
+       }
+
+       if (sna->scrn->virtualX > sna->mode.kmode->max_width ||
+           sna->scrn->virtualY > sna->mode.kmode->max_height) {
+               DBG(("%s: framebuffer too large (%dx%d) > (%dx%d)\n",
+                   __FUNCTION__,
+                   sna->scrn->virtualX, sna->scrn->virtualY,
+                   sna->mode.kmode->max_width,
+                   sna->mode.kmode->max_height));
+               return true;
+       }
+
+       transform = NULL;
+       if (crtc->transformPresent)
+               transform = &crtc->transform;
+       if (RRTransformCompute(crtc->x, crtc->y,
+                              crtc->mode.HDisplay, crtc->mode.VDisplay,
+                              crtc->rotation, transform,
+                              &crtc_to_fb,
+                              &f_crtc_to_fb,
+                              &f_fb_to_crtc)) {
+               DBG(("%s: RandR transform present\n", __FUNCTION__));
+               return true;
+       }
+
+       /* And finally check that it is entirely visible */
+       b.x1 = b.y1 = 0;
+       b.x2 = crtc->mode.HDisplay;
+       b.y2 = crtc->mode.VDisplay;
+       pixman_f_transform_bounds(&f_crtc_to_fb, &b);
+       DBG(("%s? bounds (%d, %d), (%d, %d), framebufer %dx%d\n",
+            __FUNCTION__, b.x1, b.y1, b.x2, b.y2,
+                sna->scrn->virtualX, sna->scrn->virtualY));
+
+       if  (b.x1 < 0 || b.y1 < 0 ||
+            b.x2 > sna->scrn->virtualX ||
+            b.y2 > sna->scrn->virtualY) {
+               DBG(("%s: scanout is partly outside the framebuffer\n",
+                    __FUNCTION__));
+               return true;
+       }
+
+       return false;
+}
+
+static struct kgem_bo *sna_crtc_attach(xf86CrtcPtr crtc)
+{
+       struct sna_crtc *sna_crtc = to_sna_crtc(crtc);
+       ScrnInfoPtr scrn = crtc->scrn;
+       struct sna *sna = to_sna(scrn);
+       struct kgem_bo *bo;
+
+       sna_crtc->transform = false;
+       if (sna_crtc->scanout_pixmap) {
+               DBG(("%s: attaching to scanout pixmap\n", __FUNCTION__));
+
+               bo = sna_pixmap_pin(sna_crtc->scanout_pixmap, PIN_SCANOUT);
+               if (bo == NULL)
+                       return NULL;
+
+               if (!get_fb(sna, bo,
+                           sna_crtc->scanout_pixmap->drawable.width,
+                           sna_crtc->scanout_pixmap->drawable.height))
+                       return NULL;
+
+               sna_crtc->transform = true;
+               return kgem_bo_reference(bo);
+       } else if (use_shadow(sna, crtc)) {
+               if (!sna_crtc_enable_shadow(sna, sna_crtc))
+                       return NULL;
+
+               DBG(("%s: attaching to per-crtc pixmap %dx%d\n",
+                    __FUNCTION__, crtc->mode.HDisplay, crtc->mode.VDisplay));
+
+               bo = kgem_create_2d(&sna->kgem,
+                                   crtc->mode.HDisplay, crtc->mode.VDisplay,
+                                   scrn->bitsPerPixel,
+                                   I915_TILING_X, CREATE_SCANOUT);
+               if (bo == NULL)
+                       return NULL;
+
+               if (!get_fb(sna, bo, crtc->mode.HDisplay, crtc->mode.VDisplay)) {
+                       kgem_bo_destroy(&sna->kgem, bo);
+                       return NULL;
+               }
+
+               sna_crtc->transform = true;
+               return bo;
+       } else if (sna->flags & SNA_TEAR_FREE) {
+               DBG(("%s: tear-free updates requested\n", __FUNCTION__));
+
+               if (!sna_crtc_enable_shadow(sna, sna_crtc))
+                       return NULL;
+
+               DBG(("%s: attaching to single shadow pixmap\n", __FUNCTION__));
+               if (sna->mode.shadow == NULL) {
+                       bo = kgem_create_2d(&sna->kgem,
+                                           sna->scrn->virtualX,
+                                           sna->scrn->virtualY,
+                                           scrn->bitsPerPixel,
+                                           I915_TILING_X,
+                                           CREATE_SCANOUT);
+                       if (bo == NULL)
+                               return NULL;
+
+                       if (!get_fb(sna, bo,
+                                   sna->scrn->virtualX,
+                                   sna->scrn->virtualY)) {
+                               kgem_bo_destroy(&sna->kgem, bo);
+                               return NULL;
+                       }
+
+                       sna->mode.shadow = bo;
+               }
+
+               return kgem_bo_reference(sna->mode.shadow);
+       } else {
+               DBG(("%s: attaching to framebuffer\n", __FUNCTION__));
+               sna_crtc_disable_shadow(sna, sna_crtc);
+               bo = sna_pixmap_pin(sna->front, PIN_SCANOUT);
+               if (bo == NULL)
+                       return NULL;
+
+               if (!get_fb(sna, bo, scrn->virtualX, scrn->virtualY))
+                       return NULL;
+
+               assert(!sna_crtc->shadow);
+               return kgem_bo_reference(bo);
+       }
+}
+
+static void sna_crtc_randr(xf86CrtcPtr crtc)
+{
+       struct sna_crtc *sna_crtc = to_sna_crtc(crtc);
+       struct pict_f_transform f_crtc_to_fb, f_fb_to_crtc;
+       PictTransform crtc_to_fb;
+       PictFilterPtr filter;
+       xFixed *params;
+       int nparams;
+       RRTransformPtr transform;
+
+       transform = NULL;
+       if (crtc->transformPresent)
+               transform = &crtc->transform;
+
+       RRTransformCompute(crtc->x, crtc->y,
+                          crtc->mode.HDisplay, crtc->mode.VDisplay,
+                          crtc->rotation, transform,
+                          &crtc_to_fb,
+                          &f_crtc_to_fb,
+                          &f_fb_to_crtc);
+
+       filter = NULL;
+       params = NULL;
+       nparams = 0;
+       if (sna_crtc->transform) {
+#ifdef RANDR_12_INTERFACE
+               if (transform) {
+                       if (transform->nparams) {
+                               params = malloc(transform->nparams * sizeof(xFixed));
+                               if (params) {
+                                       memcpy(params, transform->params,
+                                              transform->nparams * sizeof(xFixed));
+                                       nparams = transform->nparams;
+                                       filter = transform->filter;
+                               }
+                       } else
+                               filter = transform->filter;
+               }
+#endif
+               crtc->transform_in_use = TRUE;
+       } else
+               crtc->transform_in_use = FALSE;
+
+       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;
+
+       free(crtc->params);
+       crtc->params  = params;
+       crtc->nparams = nparams;
+
+       crtc->filter = filter;
+       if (filter) {
+               crtc->filter_width  = filter->width;
+               crtc->filter_height = filter->height;
+       } else {
+               crtc->filter_width  = 0;
+               crtc->filter_height = 0;
+       }
+
+       crtc->bounds.x1 = 0;
+       crtc->bounds.x2 = crtc->mode.HDisplay;
+       crtc->bounds.y1 = 0;
+       crtc->bounds.y2 = crtc->mode.VDisplay;
+       pixman_f_transform_bounds(&f_crtc_to_fb, &crtc->bounds);
+
+       DBG(("%s: transform? %d, bounds (%d, %d), (%d, %d)\n",
+            __FUNCTION__, crtc->transform_in_use,
+            crtc->bounds.x1, crtc->bounds.y1,
+            crtc->bounds.x2, crtc->bounds.y2));
+}
+
+static void
+sna_crtc_damage(xf86CrtcPtr crtc)
+{
+       ScreenPtr screen = crtc->scrn->pScreen;
+       struct sna *sna = to_sna(crtc->scrn);
+       RegionRec region, *damage;
+
+       region.extents = crtc->bounds;
+       region.data = NULL;
+
+       if (region.extents.x1 < 0)
+               region.extents.x1 = 0;
+       if (region.extents.y1 < 0)
+               region.extents.y1 = 0;
+       if (region.extents.x2 > screen->width)
+               region.extents.x2 = screen->width;
+       if (region.extents.y2 > screen->height)
+               region.extents.y2 = screen->height;
+
+       DBG(("%s: marking crtc %d as completely damaged (%d, %d), (%d, %d)\n",
+            __FUNCTION__, to_sna_crtc(crtc)->id,
+            region.extents.x1, region.extents.y1,
+            region.extents.x2, region.extents.y2));
+
+       assert(sna->mode.shadow_damage && sna->mode.shadow_active);
+       damage = DamageRegion(sna->mode.shadow_damage);
+       RegionUnion(damage, damage, &region);
+}
+
+static Bool
+sna_crtc_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
+                       Rotation rotation, int x, int y)
+{
+       ScrnInfoPtr scrn = crtc->scrn;
+       struct sna *sna = to_sna(scrn);
+       struct sna_crtc *sna_crtc = to_sna_crtc(crtc);
+       struct kgem_bo *saved_bo, *bo;
+       struct drm_mode_modeinfo saved_kmode;
+       bool saved_transform;
+
+       xf86DrvMsg(crtc->scrn->scrnIndex, X_INFO,
+                  "switch to mode %dx%d on crtc %d (pipe %d)\n",
+                  mode->HDisplay, mode->VDisplay,
+                  sna_crtc->id, sna_crtc->pipe);
+
+       DBG(("%s(crtc=%d [pipe=%d] rotation=%d, x=%d, y=%d, mode=%dx%d@%d)\n",
+            __FUNCTION__, sna_crtc->id, sna_crtc->pipe, rotation, x, y,
+            mode->HDisplay, mode->VDisplay, mode->Clock));
+
+       assert(mode->HDisplay <= sna->mode.kmode->max_width &&
+              mode->VDisplay <= sna->mode.kmode->max_height);
+
+       crtc->funcs->gamma_set(crtc,
+                              crtc->gamma_red,
+                              crtc->gamma_green,
+                              crtc->gamma_blue,
+                              crtc->gamma_size);
+
+       saved_kmode = sna_crtc->kmode;
+       saved_bo = sna_crtc->bo;
+       saved_transform = sna_crtc->transform;
+
+       sna_crtc->fallback_shadow = false;
+retry: /* Attach per-crtc pixmap or direct */
+       bo = sna_crtc_attach(crtc);
+       if (bo == NULL)
+               return FALSE;
+
+       sna_crtc->bo = bo;
+       mode_to_kmode(&sna_crtc->kmode, mode);
+       if (!sna_crtc_apply(crtc)) {
+               kgem_bo_destroy(&sna->kgem, bo);
+
+               if (!sna_crtc->shadow) {
+                       sna_crtc->fallback_shadow = true;
+                       goto retry;
+               }
+
+               xf86DrvMsg(crtc->scrn->scrnIndex, X_ERROR,
+                          "failed to set mode: %s\n", strerror(errno));
+
+               sna_crtc->transform = saved_transform;
+               sna_crtc->bo = saved_bo;
+               sna_crtc->kmode = saved_kmode;
+               return FALSE;
+       }
+       if (saved_bo)
+               kgem_bo_destroy(&sna->kgem, saved_bo);
+
+       sna_crtc_randr(crtc);
+       if (sna_crtc->shadow)
+               sna_crtc_damage(crtc);
+
+       if (scrn->pScreen)
+               xf86_reload_cursors(scrn->pScreen);
+
+       return TRUE;
+}
+
+static void
+sna_crtc_dpms(xf86CrtcPtr crtc, int mode)
+{
+       struct sna_crtc *priv = to_sna_crtc(crtc);
+
+       DBG(("%s(pipe %d, dpms mode -> %d):= active=%d\n",
+            __FUNCTION__, priv->pipe, mode, mode == DPMSModeOn));
+       if (mode == DPMSModeOn) {
+               if (priv->bo == NULL &&
+                   !sna_crtc_set_mode_major(crtc,
+                                            &crtc->mode, crtc->rotation,
+                                            crtc->x, crtc->y))
+                       sna_crtc_disable(crtc);
+       } else
+               sna_crtc_disable(crtc);
+
+       if (priv->bo != NULL) {
+               priv->dpms_mode = mode;
+               update_flush_interval(to_sna(crtc->scrn));
+       }
+}
+
+void sna_mode_adjust_frame(struct sna *sna, int x, int y)
+{
+       xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(sna->scrn);
+       xf86OutputPtr output = config->output[config->compat_output];
+       xf86CrtcPtr crtc = output->crtc;
+
+       if (crtc && crtc->enabled) {
+               int saved_x = crtc->x;
+               int saved_y = crtc->y;
+
+               crtc->x = x;
+               crtc->y = y;
+               if (!sna_crtc_set_mode_major(crtc, &crtc->mode,
+                                            crtc->rotation, x, y)) {
+                       crtc->x = saved_x;
+                       crtc->y = saved_y;
+               }
+       }
+}
+
+static void
+sna_crtc_hide_cursor(xf86CrtcPtr crtc)
+{
+       struct sna *sna = to_sna(crtc->scrn);
+       struct sna_crtc *sna_crtc = to_sna_crtc(crtc);
+       struct drm_mode_cursor arg;
+
+       __DBG(("%s: CRTC:%d\n", __FUNCTION__, sna_crtc->id));
+
+       VG_CLEAR(arg);
+       arg.flags = DRM_MODE_CURSOR_BO;
+       arg.crtc_id = sna_crtc->id;
+       arg.width = arg.height = 64;
+       arg.handle = 0;
+
+       (void)drmIoctl(sna->kgem.fd, DRM_IOCTL_MODE_CURSOR, &arg);
+}
+
+static void
+sna_crtc_show_cursor(xf86CrtcPtr crtc)
+{
+       struct sna *sna = to_sna(crtc->scrn);
+       struct sna_crtc *sna_crtc = to_sna_crtc(crtc);
+       struct drm_mode_cursor arg;
+
+       __DBG(("%s: CRTC:%d\n", __FUNCTION__, sna_crtc->id));
+
+       VG_CLEAR(arg);
+       arg.flags = DRM_MODE_CURSOR_BO;
+       arg.crtc_id = sna_crtc->id;
+       arg.width = arg.height = 64;
+       arg.handle = sna_crtc->cursor;
+
+       (void)drmIoctl(sna->kgem.fd, DRM_IOCTL_MODE_CURSOR, &arg);
+}
+
+static void
+sna_crtc_set_cursor_colors(xf86CrtcPtr crtc, int bg, int fg)
+{
+       __DBG(("%s: CRTC:%d (bg=%x, fg=%x)\n", __FUNCTION__,
+              to_sna_crtc(crtc)->id, bg, fg));
+}
+
+static void
+sna_crtc_set_cursor_position(xf86CrtcPtr crtc, int x, int y)
+{
+       struct sna *sna = to_sna(crtc->scrn);
+       struct sna_crtc *sna_crtc = to_sna_crtc(crtc);
+       struct drm_mode_cursor arg;
+
+       __DBG(("%s: CRTC:%d (%d, %d)\n", __FUNCTION__, sna_crtc->id, x, y));
+
+       VG_CLEAR(arg);
+       arg.flags = DRM_MODE_CURSOR_MOVE;
+       arg.crtc_id = sna_crtc->id;
+       arg.x = x;
+       arg.y = y;
+       arg.handle = sna_crtc->cursor;
+
+       (void)drmIoctl(sna->kgem.fd, DRM_IOCTL_MODE_CURSOR, &arg);
+}
+
+static void
+sna_crtc_load_cursor_argb(xf86CrtcPtr crtc, CARD32 *image)
+{
+       struct sna *sna = to_sna(crtc->scrn);
+       struct sna_crtc *sna_crtc = to_sna_crtc(crtc);
+       struct drm_i915_gem_pwrite pwrite;
+
+       __DBG(("%s: CRTC:%d\n", __FUNCTION__, sna_crtc->id));
+
+       VG_CLEAR(pwrite);
+       pwrite.handle = sna_crtc->cursor;
+       pwrite.offset = 0;
+       pwrite.size = 64*64*4;
+       pwrite.data_ptr = (uintptr_t)image;
+       (void)drmIoctl(sna->kgem.fd, DRM_IOCTL_I915_GEM_PWRITE, &pwrite);
+}
+
+static void
+sna_crtc_gamma_set(xf86CrtcPtr crtc,
+                      CARD16 *red, CARD16 *green, CARD16 *blue, int size)
+{
+       struct sna *sna = to_sna(crtc->scrn);
+       struct sna_crtc *sna_crtc = to_sna_crtc(crtc);
+
+       drmModeCrtcSetGamma(sna->kgem.fd, sna_crtc->id,
+                           size, red, green, blue);
+}
+
+static void
+sna_crtc_destroy(xf86CrtcPtr crtc)
+{
+       struct sna *sna = to_sna(crtc->scrn);
+       struct sna_crtc *sna_crtc = to_sna_crtc(crtc);
+
+       sna_crtc_hide_cursor(crtc);
+       gem_close(sna->kgem.fd, sna_crtc->cursor);
+
+       list_del(&sna_crtc->link);
+       free(sna_crtc);
+
+       crtc->driver_private = NULL;
+}
+
+#if HAS_PIXMAP_SHARING
+static Bool
+sna_set_scanout_pixmap(xf86CrtcPtr crtc, PixmapPtr pixmap)
+{
+       DBG(("%s: CRTC:%d, pipe=%d setting scanout pixmap=%ld\n",
+            __FUNCTION__,to_sna_crtc(crtc)->id, to_sna_crtc(crtc)->pipe,
+            pixmap ? pixmap->drawable.serialNumber : 0));
+       to_sna_crtc(crtc)->scanout_pixmap = pixmap;
+       return TRUE;
+}
+#endif
+
+static const xf86CrtcFuncsRec sna_crtc_funcs = {
+       .dpms = sna_crtc_dpms,
+       .set_mode_major = sna_crtc_set_mode_major,
+       .set_cursor_colors = sna_crtc_set_cursor_colors,
+       .set_cursor_position = sna_crtc_set_cursor_position,
+       .show_cursor = sna_crtc_show_cursor,
+       .hide_cursor = sna_crtc_hide_cursor,
+       .load_cursor_argb = sna_crtc_load_cursor_argb,
+       .gamma_set = sna_crtc_gamma_set,
+       .destroy = sna_crtc_destroy,
+#if HAS_PIXMAP_SHARING
+       .set_scanout_pixmap = sna_set_scanout_pixmap,
+#endif
+};
+
+static uint32_t
+sna_crtc_find_plane(struct sna *sna, int pipe)
+{
+       struct drm_mode_get_plane_res r;
+       uint32_t *planes, id = 0;
+       int i;
+
+       VG_CLEAR(r);
+       r.count_planes = 0;
+       if (drmIoctl(sna->kgem.fd, DRM_IOCTL_MODE_GETPLANERESOURCES, &r))
+               return 0;
+
+       if (!r.count_planes)
+               return 0;
+
+       planes = malloc(sizeof(uint32_t)*r.count_planes);
+       if (planes == NULL)
+               return 0;
+
+       r.plane_id_ptr = (uintptr_t)planes;
+       if (drmIoctl(sna->kgem.fd, DRM_IOCTL_MODE_GETPLANERESOURCES, &r))
+               r.count_planes = 0;
+
+       for (i = 0; i < r.count_planes; i++) {
+               struct drm_mode_get_plane p;
+
+               VG_CLEAR(p);
+               p.plane_id = planes[i];
+               p.count_format_types = 0;
+               if (drmIoctl(sna->kgem.fd, DRM_IOCTL_MODE_GETPLANE, &p) == 0) {
+                       if (p.possible_crtcs & (1 << pipe)) {
+                               id = p.plane_id;
+                               break;
+                       }
+               }
+       }
+       free(planes);
+
+       return id;
+}
+
+static void
+sna_crtc_init(ScrnInfoPtr scrn, struct sna_mode *mode, int num)
+{
+       struct sna *sna = to_sna(scrn);
+       xf86CrtcPtr crtc;
+       struct sna_crtc *sna_crtc;
+       struct drm_i915_get_pipe_from_crtc_id get_pipe;
+
+       DBG(("%s\n", __FUNCTION__));
+
+       sna_crtc = calloc(sizeof(struct sna_crtc), 1);
+       if (sna_crtc == NULL)
+               return;
+
+       sna_crtc->id = mode->kmode->crtcs[num];
+       sna_crtc->dpms_mode = DPMSModeOff;
+
+       VG_CLEAR(get_pipe);
+       get_pipe.pipe = 0;
+       get_pipe.crtc_id = sna_crtc->id;
+       if (drmIoctl(sna->kgem.fd,
+                    DRM_IOCTL_I915_GET_PIPE_FROM_CRTC_ID,
+                    &get_pipe)) {
+               free(sna_crtc);
+               return;
+       }
+       sna_crtc->pipe = get_pipe.pipe;
+       sna_crtc->plane = sna_crtc_find_plane(sna, sna_crtc->pipe);
+
+       if (xf86IsEntityShared(scrn->entityList[0]) &&
+           scrn->confScreen->device->screen != sna_crtc->pipe) {
+               free(sna_crtc);
+               return;
+       }
+
+       crtc = xf86CrtcCreate(scrn, &sna_crtc_funcs);
+       if (crtc == NULL) {
+               free(sna_crtc);
+               return;
+       }
+
+       crtc->driver_private = sna_crtc;
+
+       sna_crtc->cursor = gem_create(sna->kgem.fd, 64*64*4);
+       DBG(("%s: created handle=%d for cursor on CRTC:%d\n",
+            __FUNCTION__, sna_crtc->cursor, sna_crtc->id));
+
+       list_add(&sna_crtc->link, &mode->crtcs);
+
+       DBG(("%s: attached crtc[%d] id=%d, pipe=%d\n",
+            __FUNCTION__, num, sna_crtc->id, sna_crtc->pipe));
+}
+
+static bool
+is_panel(int type)
+{
+       return (type == DRM_MODE_CONNECTOR_LVDS ||
+               type == DRM_MODE_CONNECTOR_eDP);
+}
+
+static xf86OutputStatus
+sna_output_detect(xf86OutputPtr output)
+{
+       /* go to the hw and retrieve a new output struct */
+       struct sna *sna = to_sna(output->scrn);
+       struct sna_output *sna_output = output->driver_private;
+       xf86OutputStatus status;
+
+       DBG(("%s\n", __FUNCTION__));
+
+       drmModeFreeConnector(sna_output->mode_output);
+       sna_output->mode_output =
+               drmModeGetConnector(sna->kgem.fd, sna_output->id);
+
+       switch (sna_output->mode_output->connection) {
+       case DRM_MODE_CONNECTED:
+               status = XF86OutputStatusConnected;
+               break;
+       case DRM_MODE_DISCONNECTED:
+               status = XF86OutputStatusDisconnected;
+               break;
+       default:
+       case DRM_MODE_UNKNOWNCONNECTION:
+               status = XF86OutputStatusUnknown;
+               break;
+       }
+       return status;
+}
+
+static Bool
+sna_output_mode_valid(xf86OutputPtr output, DisplayModePtr mode)
+{
+       struct sna_output *sna_output = output->driver_private;
+       struct sna *sna = to_sna(output->scrn);
+
+       if (mode->HDisplay > sna->mode.kmode->max_width)
+               return MODE_VIRTUAL_X;
+       if (mode->VDisplay > sna->mode.kmode->max_height)
+               return MODE_VIRTUAL_Y;
+
+       /* Check that we can successfully pin this into the global GTT */
+       if ((kgem_can_create_2d(&sna->kgem,
+                               mode->HDisplay, mode->VDisplay,
+                               sna->scrn->bitsPerPixel) & KGEM_CAN_CREATE_GTT) == 0)
+               return MODE_MEM_VIRT;
+
+       /*
+        * If the connector type is a panel, we will use the panel limit to
+        * verfiy whether the mode is valid.
+        */
+       if (sna_output->has_panel_limits) {
+               if (mode->HDisplay > sna_output->panel_hdisplay ||
+                   mode->VDisplay > sna_output->panel_vdisplay)
+                       return MODE_PANEL;
+       }
+
+       return MODE_OK;
+}
+
+static void
+sna_output_attach_edid(xf86OutputPtr output)
+{
+       struct sna *sna = to_sna(output->scrn);
+       struct sna_output *sna_output = output->driver_private;
+       drmModeConnectorPtr koutput = sna_output->mode_output;
+       void *raw = NULL;
+       int raw_length = 0;
+       xf86MonPtr mon = NULL;
+       int i;
+
+       /* look for an EDID property */
+       for (i = 0; i < koutput->count_props; i++) {
+               struct drm_mode_get_property prop;
+               struct drm_mode_get_blob blob;
+               void *tmp;
+
+               VG_CLEAR(prop);
+               prop.prop_id = koutput->props[i];
+               prop.count_values = 0;
+               prop.count_enum_blobs = 0;
+               if (drmIoctl(sna->kgem.fd, DRM_IOCTL_MODE_GETPROPERTY, &prop))
+                       continue;
+
+               if (!(prop.flags & DRM_MODE_PROP_BLOB))
+                       continue;
+
+               if (strcmp(prop.name, "EDID"))
+                       continue;
+
+               if (koutput->prop_values[i] == 0)
+                       continue;
+
+               VG_CLEAR(blob);
+               blob.length = 0;
+               blob.data = 0;
+               blob.blob_id = koutput->prop_values[i];
+
+               if (drmIoctl(sna->kgem.fd, DRM_IOCTL_MODE_GETPROPBLOB, &blob))
+                       continue;
+
+               DBG(("%s: retreiving blob (property %d, id=%d, value=%ld), length=%d\n",
+                    __FUNCTION__, i, koutput->props[i], (long)koutput->prop_values[i],
+                    blob.length));
+
+               tmp = malloc(blob.length);
+               if (tmp == NULL)
+                       continue;
+
+               VG(memset(tmp, 0, blob.length));
+               blob.data = (uintptr_t)tmp;
+               if (drmIoctl(sna->kgem.fd, DRM_IOCTL_MODE_GETPROPBLOB, &blob)) {
+                       free(tmp);
+                       continue;
+               }
+
+               free(raw);
+               raw = tmp;
+               raw_length = blob.length;
+       }
+
+       if (raw) {
+               mon = xf86InterpretEDID(output->scrn->scrnIndex, raw);
+               if (mon && raw_length > 128)
+                       mon->flags |= MONITOR_EDID_COMPLETE_RAWDATA;
+       }
+
+       xf86OutputSetEDID(output, mon);
+       free(raw);
+}
+
+static DisplayModePtr
+sna_output_panel_edid(xf86OutputPtr output, DisplayModePtr modes)
+{
+       xf86MonPtr mon = output->MonInfo;
+
+       if (!mon || !GTF_SUPPORTED(mon->features.msc)) {
+               DisplayModePtr i, m, p = NULL;
+               int max_x = 0, max_y = 0;
+               float max_vrefresh = 0.0;
+
+               for (m = modes; m; m = m->next) {
+                       if (m->type & M_T_PREFERRED)
+                               p = m;
+                       max_x = max(max_x, m->HDisplay);
+                       max_y = max(max_y, m->VDisplay);
+                       max_vrefresh = max(max_vrefresh, xf86ModeVRefresh(m));
+               }
+
+               max_vrefresh = max(max_vrefresh, 60.0);
+               max_vrefresh *= (1 + SYNC_TOLERANCE);
+
+               m = xf86GetDefaultModes();
+               xf86ValidateModesSize(output->scrn, m, max_x, max_y, 0);
+
+               for (i = m; i; i = i->next) {
+                       if (xf86ModeVRefresh(i) > max_vrefresh)
+                               i->status = MODE_VSYNC;
+                       if (p && i->HDisplay >= p->HDisplay &&
+                           i->VDisplay >= p->VDisplay &&
+                           xf86ModeVRefresh(i) >= xf86ModeVRefresh(p))
+                               i->status = MODE_VSYNC;
+               }
+
+               xf86PruneInvalidModes(output->scrn, &m, FALSE);
+
+               modes = xf86ModesAdd(modes, m);
+       }
+
+       return modes;
+}
+
+static DisplayModePtr
+sna_output_get_modes(xf86OutputPtr output)
+{
+       struct sna_output *sna_output = output->driver_private;
+       drmModeConnectorPtr koutput = sna_output->mode_output;
+       DisplayModePtr Modes = NULL;
+       int i;
+
+       DBG(("%s\n", __FUNCTION__));
+
+       sna_output_attach_edid(output);
+
+       /* modes should already be available */
+       for (i = 0; i < koutput->count_modes; i++) {
+               DisplayModePtr Mode;
+
+               Mode = calloc(1, sizeof(DisplayModeRec));
+               if (Mode) {
+                       mode_from_kmode(output->scrn, &koutput->modes[i], Mode);
+                       Modes = xf86ModesAdd(Modes, Mode);
+               }
+       }
+
+       /*
+        * If the connector type is a panel, we will traverse the kernel mode to
+        * get the panel limit. And then add all the standard modes to fake
+        * the fullscreen experience.
+        * If it is incorrect, please fix me.
+        */
+       sna_output->has_panel_limits = false;
+       if (is_panel(koutput->connector_type)) {
+               for (i = 0; i < koutput->count_modes; i++) {
+                       drmModeModeInfo *mode_ptr;
+
+                       mode_ptr = &koutput->modes[i];
+                       if (mode_ptr->hdisplay > sna_output->panel_hdisplay)
+                               sna_output->panel_hdisplay = mode_ptr->hdisplay;
+                       if (mode_ptr->vdisplay > sna_output->panel_vdisplay)
+                               sna_output->panel_vdisplay = mode_ptr->vdisplay;
+               }
+
+               sna_output->has_panel_limits =
+                       sna_output->panel_hdisplay &&
+                       sna_output->panel_vdisplay;
+
+               Modes = sna_output_panel_edid(output, Modes);
+       }
+
+       return Modes;
+}
+
+static void
+sna_output_destroy(xf86OutputPtr output)
+{
+       struct sna_output *sna_output = output->driver_private;
+       int i;
+
+       for (i = 0; i < sna_output->num_props; i++) {
+               drmModeFreeProperty(sna_output->props[i].mode_prop);
+               free(sna_output->props[i].atoms);
+       }
+       free(sna_output->props);
+
+       drmModeFreeConnector(sna_output->mode_output);
+       sna_output->mode_output = NULL;
+
+       free(sna_output->backlight_iface);
+
+       list_del(&sna_output->link);
+       free(sna_output);
+
+       output->driver_private = NULL;
+}
+
+static void
+sna_output_dpms_backlight(xf86OutputPtr output, int oldmode, int mode)
+{
+       struct sna_output *sna_output = output->driver_private;
+
+       if (!sna_output->backlight_iface)
+               return;
+
+       if (mode == DPMSModeOn) {
+               /* If we're going from off->on we may need to turn on the backlight. */
+               if (oldmode != DPMSModeOn)
+                       sna_output_backlight_set(output,
+                                                  sna_output->backlight_active_level);
+       } else {
+               /* Only save the current backlight value if we're going from on to off. */
+               if (oldmode == DPMSModeOn)
+                       sna_output->backlight_active_level = sna_output_backlight_get(output);
+               sna_output_backlight_set(output, 0);
+       }
+}
+
+static void
+sna_output_dpms(xf86OutputPtr output, int dpms)
+{
+       struct sna *sna = to_sna(output->scrn);
+       struct sna_output *sna_output = output->driver_private;
+       drmModeConnectorPtr koutput = sna_output->mode_output;
+       int i;
+
+       DBG(("%s: dpms=%d\n", __FUNCTION__, dpms));
+
+       if (dpms != DPMSModeOn)
+               kgem_submit(&sna->kgem);
+
+       for (i = 0; i < koutput->count_props; i++) {
+               struct drm_mode_get_property prop;
+
+               VG_CLEAR(prop);
+               prop.prop_id = koutput->props[i];
+               prop.count_values = 0;
+               prop.count_enum_blobs = 0;
+               if (drmIoctl(sna->kgem.fd, DRM_IOCTL_MODE_GETPROPERTY, &prop))
+                       continue;
+
+               if (strcmp(prop.name, "DPMS"))
+                       continue;
+
+               /* Record thevalue of the backlight before turning
+                * off the display, and reset if after turnging it on.
+                * Order is important as the kernel may record and also
+                * reset the backlight across DPMS. Hence we need to
+                * record the value before the kernel modifies it
+                * and reapply it afterwards.
+                */
+               if (dpms == DPMSModeOff)
+                       sna_output_dpms_backlight(output,
+                                                 sna_output->dpms_mode,
+                                                 dpms);
+
+               drmModeConnectorSetProperty(sna->kgem.fd,
+                                           sna_output->id,
+                                           prop.prop_id,
+                                           dpms);
+
+               if (dpms != DPMSModeOff)
+                       sna_output_dpms_backlight(output,
+                                                 sna_output->dpms_mode,
+                                                 dpms);
+
+               sna_output->dpms_mode = dpms;
+               break;
+       }
+}
+
+static bool
+sna_property_ignore(drmModePropertyPtr prop)
+{
+       if (!prop)
+               return true;
+
+       /* ignore blob prop */
+       if (prop->flags & DRM_MODE_PROP_BLOB)
+               return true;
+
+       /* ignore standard property */
+       if (!strcmp(prop->name, "EDID") ||
+           !strcmp(prop->name, "DPMS"))
+               return true;
+
+       return false;
+}
+
+static void
+sna_output_create_ranged_atom(xf86OutputPtr output, Atom *atom,
+                             const char *name, INT32 min, INT32 max,
+                             uint64_t value, Bool immutable)
+{
+       int err;
+       INT32 atom_range[2];
+
+       atom_range[0] = min;
+       atom_range[1] = max;
+
+       *atom = MakeAtom(name, strlen(name), TRUE);
+
+       err = RRConfigureOutputProperty(output->randr_output, *atom, FALSE,
+                                       TRUE, immutable, 2, atom_range);
+       if (err != 0)
+               xf86DrvMsg(output->scrn->scrnIndex, X_ERROR,
+                          "RRConfigureOutputProperty error, %d\n", err);
+
+       err = RRChangeOutputProperty(output->randr_output, *atom, XA_INTEGER,
+                                    32, PropModeReplace, 1, &value, FALSE,
+                                    TRUE);
+       if (err != 0)
+               xf86DrvMsg(output->scrn->scrnIndex, X_ERROR,
+                          "RRChangeOutputProperty error, %d\n", err);
+}
+
+#define BACKLIGHT_NAME             "Backlight"
+#define BACKLIGHT_DEPRECATED_NAME  "BACKLIGHT"
+static Atom backlight_atom, backlight_deprecated_atom;
+
+static void
+sna_output_create_resources(xf86OutputPtr output)
+{
+       struct sna *sna = to_sna(output->scrn);
+       struct sna_output *sna_output = output->driver_private;
+       drmModeConnectorPtr mode_output = sna_output->mode_output;
+       int i, j, err;
+
+       sna_output->props = calloc(mode_output->count_props,
+                                    sizeof(struct sna_property));
+       if (!sna_output->props)
+               return;
+
+       sna_output->num_props = 0;
+       for (i = j = 0; i < mode_output->count_props; i++) {
+               drmModePropertyPtr drmmode_prop;
+
+               drmmode_prop = drmModeGetProperty(sna->kgem.fd,
+                                                 mode_output->props[i]);
+               if (sna_property_ignore(drmmode_prop)) {
+                       drmModeFreeProperty(drmmode_prop);
+                       continue;
+               }
+
+               sna_output->props[j].mode_prop = drmmode_prop;
+               sna_output->props[j].value = mode_output->prop_values[i];
+               j++;
+       }
+       sna_output->num_props = j;
+
+       for (i = 0; i < sna_output->num_props; i++) {
+               struct sna_property *p = &sna_output->props[i];
+               drmModePropertyPtr drmmode_prop = p->mode_prop;
+
+               if (drmmode_prop->flags & DRM_MODE_PROP_RANGE) {
+                       p->num_atoms = 1;
+                       p->atoms = calloc(p->num_atoms, sizeof(Atom));
+                       if (!p->atoms)
+                               continue;
+
+                       sna_output_create_ranged_atom(output, &p->atoms[0],
+                                                     drmmode_prop->name,
+                                                     drmmode_prop->values[0],
+                                                     drmmode_prop->values[1],
+                                                     p->value,
+                                                     drmmode_prop->flags & DRM_MODE_PROP_IMMUTABLE ? TRUE : FALSE);
+
+               } else if (drmmode_prop->flags & DRM_MODE_PROP_ENUM) {
+                       p->num_atoms = drmmode_prop->count_enums + 1;
+                       p->atoms = calloc(p->num_atoms, sizeof(Atom));
+                       if (!p->atoms)
+                               continue;
+
+                       p->atoms[0] = MakeAtom(drmmode_prop->name, strlen(drmmode_prop->name), TRUE);
+                       for (j = 1; j <= drmmode_prop->count_enums; j++) {
+                               struct drm_mode_property_enum *e = &drmmode_prop->enums[j-1];
+                               p->atoms[j] = MakeAtom(e->name, strlen(e->name), TRUE);
+                       }
+
+                       err = RRConfigureOutputProperty(output->randr_output, p->atoms[0],
+                                                       FALSE, FALSE,
+                                                       drmmode_prop->flags & DRM_MODE_PROP_IMMUTABLE ? TRUE : FALSE,
+                                                       p->num_atoms - 1, (INT32 *)&p->atoms[1]);
+                       if (err != 0) {
+                               xf86DrvMsg(output->scrn->scrnIndex, X_ERROR,
+                                          "RRConfigureOutputProperty error, %d\n", err);
+                       }
+
+                       for (j = 0; j < drmmode_prop->count_enums; j++)
+                               if (drmmode_prop->enums[j].value == p->value)
+                                       break;
+                       /* there's always a matching value */
+                       err = RRChangeOutputProperty(output->randr_output, p->atoms[0],
+                                                    XA_ATOM, 32, PropModeReplace, 1, &p->atoms[j+1], FALSE, TRUE);
+                       if (err != 0) {
+                               xf86DrvMsg(output->scrn->scrnIndex, X_ERROR,
+                                          "RRChangeOutputProperty error, %d\n", err);
+                       }
+               }
+       }
+
+       if (sna_output->backlight_iface) {
+               /* Set up the backlight property, which takes effect
+                * immediately and accepts values only within the
+                * backlight_range.
+                */
+               sna_output_create_ranged_atom(output, &backlight_atom,
+                                       BACKLIGHT_NAME, 0,
+                                       sna_output->backlight_max,
+                                       sna_output->backlight_active_level,
+                                       FALSE);
+               sna_output_create_ranged_atom(output,
+                                       &backlight_deprecated_atom,
+                                       BACKLIGHT_DEPRECATED_NAME, 0,
+                                       sna_output->backlight_max,
+                                       sna_output->backlight_active_level,
+                                       FALSE);
+       }
+}
+
+static Bool
+sna_output_set_property(xf86OutputPtr output, Atom property,
+                           RRPropertyValuePtr value)
+{
+       struct sna *sna = to_sna(output->scrn);
+       struct sna_output *sna_output = output->driver_private;
+       int i;
+
+       if (property == backlight_atom || property == backlight_deprecated_atom) {
+               INT32 val;
+
+               if (value->type != XA_INTEGER || value->format != 32 ||
+                   value->size != 1)
+               {
+                       return FALSE;
+               }
+
+               val = *(INT32 *)value->data;
+               if (val < 0 || val > sna_output->backlight_max)
+                       return FALSE;
+
+               if (sna_output->dpms_mode == DPMSModeOn)
+                       sna_output_backlight_set(output, val);
+               sna_output->backlight_active_level = val;
+               return TRUE;
+       }
+
+       for (i = 0; i < sna_output->num_props; i++) {
+               struct sna_property *p = &sna_output->props[i];
+
+               if (p->atoms[0] != property)
+                       continue;
+
+               if (p->mode_prop->flags & DRM_MODE_PROP_RANGE) {
+                       uint32_t val;
+
+                       if (value->type != XA_INTEGER || value->format != 32 ||
+                           value->size != 1)
+                               return FALSE;
+                       val = *(uint32_t *)value->data;
+
+                       drmModeConnectorSetProperty(sna->kgem.fd, sna_output->id,
+                                                   p->mode_prop->prop_id, (uint64_t)val);
+                       return TRUE;
+               } else if (p->mode_prop->flags & DRM_MODE_PROP_ENUM) {
+                       Atom    atom;
+                       const char      *name;
+                       int             j;
+
+                       if (value->type != XA_ATOM || value->format != 32 || value->size != 1)
+                               return FALSE;
+                       memcpy(&atom, value->data, 4);
+                       name = NameForAtom(atom);
+                       if (name == NULL)
+                               return FALSE;
+
+                       /* search for matching name string, then set its value down */
+                       for (j = 0; j < p->mode_prop->count_enums; j++) {
+                               if (!strcmp(p->mode_prop->enums[j].name, name)) {
+                                       drmModeConnectorSetProperty(sna->kgem.fd, sna_output->id,
+                                                                   p->mode_prop->prop_id, p->mode_prop->enums[j].value);
+                                       return TRUE;
+                               }
+                       }
+                       return FALSE;
+               }
+       }
+
+       /* We didn't recognise this property, just report success in order
+        * to allow the set to continue, otherwise we break setting of
+        * common properties like EDID.
+        */
+       return TRUE;
+}
+
+static Bool
+sna_output_get_property(xf86OutputPtr output, Atom property)
+{
+       struct sna_output *sna_output = output->driver_private;
+       int err;
+
+       if (property == backlight_atom || property == backlight_deprecated_atom) {
+               INT32 val;
+
+               if (! sna_output->backlight_iface)
+                       return FALSE;
+
+               val = sna_output_backlight_get(output);
+               if (val < 0)
+                       return FALSE;
+
+               err = RRChangeOutputProperty(output->randr_output, property,
+                                            XA_INTEGER, 32, PropModeReplace, 1, &val,
+                                            FALSE, TRUE);
+               if (err != 0) {
+                       xf86DrvMsg(output->scrn->scrnIndex, X_ERROR,
+                                  "RRChangeOutputProperty error, %d\n", err);
+                       return FALSE;
+               }
+
+               return TRUE;
+       }
+
+       return FALSE;
+}
+
+static const xf86OutputFuncsRec sna_output_funcs = {
+       .create_resources = sna_output_create_resources,
+#ifdef RANDR_12_INTERFACE
+       .set_property = sna_output_set_property,
+       .get_property = sna_output_get_property,
+#endif
+       .dpms = sna_output_dpms,
+       .detect = sna_output_detect,
+       .mode_valid = sna_output_mode_valid,
+
+       .get_modes = sna_output_get_modes,
+       .destroy = sna_output_destroy
+};
+
+static const int subpixel_conv_table[7] = {
+       0,
+       SubPixelUnknown,
+       SubPixelHorizontalRGB,
+       SubPixelHorizontalBGR,
+       SubPixelVerticalRGB,
+       SubPixelVerticalBGR,
+       SubPixelNone
+};
+
+static const char *output_names[] = {
+       "None",
+       "VGA",
+       "DVI",
+       "DVI",
+       "DVI",
+       "Composite",
+       "TV",
+       "LVDS",
+       "CTV",
+       "DIN",
+       "DP",
+       "HDMI",
+       "HDMI",
+       "TV",
+       "eDP",
+};
+
+static bool
+sna_zaphod_match(const char *s, const char *output)
+{
+       char t[20];
+       unsigned int i = 0;
+
+       do {
+               /* match any outputs in a comma list, stopping at whitespace */
+               switch (*s) {
+               case '\0':
+                       t[i] = '\0';
+                       return strcmp(t, output) == 0;
+
+               case ',':
+                       t[i] ='\0';
+                       if (strcmp(t, output) == 0)
+                               return TRUE;
+                       i = 0;
+                       break;
+
+               case ' ':
+               case '\t':
+               case '\n':
+               case '\r':
+                       break;
+
+               default:
+                       t[i++] = *s;
+                       break;
+               }
+
+               s++;
+       } while (i < sizeof(t));
+
+       return false;
+}
+
+static void
+sna_output_init(ScrnInfoPtr scrn, struct sna_mode *mode, int num)
+{
+       struct sna *sna = to_sna(scrn);
+       xf86OutputPtr output;
+       drmModeConnectorPtr koutput;
+       struct drm_mode_get_encoder enc;
+       struct sna_output *sna_output;
+       const char *output_name;
+       char name[32];
+
+       koutput = drmModeGetConnector(sna->kgem.fd,
+                                     mode->kmode->connectors[num]);
+       if (!koutput)
+               return;
+
+       VG_CLEAR(enc);
+       enc.encoder_id = koutput->encoders[0];
+       if (drmIoctl(sna->kgem.fd, DRM_IOCTL_MODE_GETENCODER, &enc))
+               goto cleanup_connector;
+
+       if (koutput->connector_type < ARRAY_SIZE(output_names))
+               output_name = output_names[koutput->connector_type];
+       else
+               output_name = "UNKNOWN";
+       snprintf(name, 32, "%s%d", output_name, koutput->connector_type_id);
+
+       if (xf86IsEntityShared(scrn->entityList[0])) {
+               const char *str;
+
+               str = xf86GetOptValString(sna->Options, OPTION_ZAPHOD);
+               if (str && !sna_zaphod_match(str, name))
+                       goto cleanup_connector;
+
+               if ((enc.possible_crtcs & (1 << scrn->confScreen->device->screen)) == 0) {
+                       if (str) {
+                               xf86DrvMsg(scrn->scrnIndex, X_ERROR,
+                                          "%s is an invalid output for screen (pipe) %d\n",
+                                          name, scrn->confScreen->device->screen);
+                       }
+                       goto cleanup_connector;
+               }
+
+               enc.possible_crtcs = 1;
+               enc.possible_clones = 0;
+       }
+
+       output = xf86OutputCreate(scrn, &sna_output_funcs, name);
+       if (!output)
+               goto cleanup_connector;
+
+       sna_output = calloc(sizeof(struct sna_output), 1);
+       if (!sna_output)
+               goto cleanup_output;
+
+       sna_output->id = mode->kmode->connectors[num];
+       sna_output->mode_output = koutput;
+
+       output->mm_width = koutput->mmWidth;
+       output->mm_height = koutput->mmHeight;
+
+       output->subpixel_order = subpixel_conv_table[koutput->subpixel];
+       output->driver_private = sna_output;
+
+       if (is_panel(koutput->connector_type))
+               sna_output_backlight_init(output);
+
+       output->possible_crtcs = enc.possible_crtcs;
+       output->possible_clones = enc.possible_clones;
+       output->interlaceAllowed = TRUE;
+
+       list_add(&sna_output->link, &mode->outputs);
+
+       return;
+
+cleanup_output:
+       xf86OutputDestroy(output);
+cleanup_connector:
+       drmModeFreeConnector(koutput);
+}
+
+struct sna_visit_set_pixmap_window {
+       PixmapPtr old, new;
+};
+
+static int
+sna_visit_set_window_pixmap(WindowPtr window, pointer data)
+{
+    struct sna_visit_set_pixmap_window *visit = data;
+    ScreenPtr screen = window->drawable.pScreen;
+
+    if (screen->GetWindowPixmap(window) == visit->old) {
+           screen->SetWindowPixmap(window, visit->new);
+           return WT_WALKCHILDREN;
+    }
+
+    return WT_DONTWALKCHILDREN;
+}
+
+static void copy_front(struct sna *sna, PixmapPtr old, PixmapPtr new)
+{
+       struct sna_pixmap *old_priv, *new_priv;
+       int16_t sx, sy, dx, dy;
+       BoxRec box;
+
+       DBG(("%s\n", __FUNCTION__));
+
+       if (wedged(sna))
+               return;
+
+       old_priv = sna_pixmap_force_to_gpu(old, MOVE_READ);
+       if (!old_priv)
+               return;
+
+       new_priv = sna_pixmap_force_to_gpu(new, MOVE_WRITE);
+       if (!new_priv)
+               return;
+
+       box.x1 = box.y1 = 0;
+       box.x2 = min(old->drawable.width, new->drawable.width);
+       box.y2 = min(old->drawable.height, new->drawable.height);
+
+       sx = dx = 0;
+       if (box.x2 < old->drawable.width)
+               sx = (old->drawable.width - box.x2) / 2;
+       if (box.x2 < new->drawable.width)
+               dx = (new->drawable.width - box.x2) / 2;
+
+       sy = dy = 0;
+       if (box.y2 < old->drawable.height)
+               sy = (old->drawable.height - box.y2) / 2;
+       if (box.y2 < new->drawable.height)
+               dy = (new->drawable.height - box.y2) / 2;
+
+       DBG(("%s: copying box (%dx%d) from (%d, %d) to (%d, %d)\n",
+            __FUNCTION__, box.x2, box.y2, sx, sy, dx, dy));
+
+       if (old_priv->clear) {
+               (void)sna->render.fill_one(sna, new, new_priv->gpu_bo,
+                                          old_priv->clear_color,
+                                          0, 0,
+                                          new->drawable.width,
+                                          new->drawable.height,
+                                          GXcopy);
+               new_priv->clear = true;
+               new_priv->clear_color = old_priv->clear_color;
+       } else {
+               if (box.x2 != new->drawable.width || box.y2 != new->drawable.height) {
+                       (void)sna->render.fill_one(sna, new, new_priv->gpu_bo, 0,
+                                                  0, 0,
+                                                  new->drawable.width,
+                                                  new->drawable.height,
+                                                  GXclear);
+               }
+               (void)sna->render.copy_boxes(sna, GXcopy,
+                                            old, old_priv->gpu_bo, sx, sy,
+                                            new, new_priv->gpu_bo, dx, dy,
+                                            &box, 1, 0);
+       }
+
+       if (!DAMAGE_IS_ALL(new_priv->gpu_damage))
+               sna_damage_all(&new_priv->gpu_damage,
+                              new->drawable.width,
+                              new->drawable.height);
+}
+
+static Bool
+sna_crtc_resize(ScrnInfoPtr scrn, int width, int height)
+{
+       xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+       struct sna *sna = to_sna(scrn);
+       ScreenPtr screen = scrn->pScreen;
+       PixmapPtr old_front, new_front;
+       int i;
+
+       DBG(("%s (%d, %d) -> (%d, %d)\n", __FUNCTION__,
+            scrn->virtualX, scrn->virtualY,
+            width, height));
+
+       if (scrn->virtualX == width && scrn->virtualY == height)
+               return TRUE;
+
+       assert(sna->front);
+       assert(screen->GetScreenPixmap(screen) == sna->front);
+
+       DBG(("%s: creating new framebuffer %dx%d\n",
+            __FUNCTION__, width, height));
+
+       old_front = sna->front;
+       new_front = screen->CreatePixmap(screen,
+                                        width, height, scrn->depth,
+                                        SNA_CREATE_FB);
+       if (!new_front)
+               return FALSE;
+
+       for (i = 0; i < xf86_config->num_crtc; i++)
+               sna_crtc_disable_shadow(sna, to_sna_crtc(xf86_config->crtc[i]));
+       assert(sna->mode.shadow_active == 0);
+       assert(sna->mode.shadow_damage == NULL);
+       assert(sna->mode.shadow == NULL);
+
+       copy_front(sna, sna->front, new_front);
+
+       sna->front = new_front;
+       scrn->virtualX = width;
+       scrn->virtualY = height;
+       scrn->displayWidth = width;
+
+       for (i = 0; i < xf86_config->num_crtc; i++) {
+               xf86CrtcPtr crtc = xf86_config->crtc[i];
+
+               if (!crtc->enabled)
+                       continue;
+
+               if (!sna_crtc_set_mode_major(crtc,
+                                            &crtc->mode, crtc->rotation,
+                                            crtc->x, crtc->y))
+                       sna_crtc_disable(crtc);
+       }
+
+       if (screen->root) {
+               struct sna_visit_set_pixmap_window visit;
+
+               visit.old = old_front;
+               visit.new = sna->front;
+               TraverseTree(screen->root, sna_visit_set_window_pixmap, &visit);
+               assert(screen->GetWindowPixmap(screen->root) == sna->front);
+       }
+       screen->SetScreenPixmap(sna->front);
+       assert(screen->GetScreenPixmap(screen) == sna->front);
+
+       screen->DestroyPixmap(old_front);
+
+       return TRUE;
+}
+
+static int do_page_flip(struct sna *sna, struct kgem_bo *bo,
+                       void *data, int ref_crtc_hw_id)
+{
+       xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(sna->scrn);
+       int width = sna->scrn->virtualX;
+       int height = sna->scrn->virtualY;
+       int count = 0;
+       int i;
+
+       /*
+        * Queue flips on all enabled CRTCs
+        * Note that if/when we get per-CRTC buffers, we'll have to update this.
+        * Right now it assumes a single shared fb across all CRTCs, with the
+        * kernel fixing up the offset of each CRTC as necessary.
+        *
+        * Also, flips queued on disabled or incorrectly configured displays
+        * may never complete; this is a configuration error.
+        */
+       for (i = 0; i < config->num_crtc; i++) {
+               struct sna_crtc *crtc = config->crtc[i]->driver_private;
+               struct drm_mode_crtc_page_flip arg;
+
+               DBG(("%s: crtc %d active? %d\n",
+                    __FUNCTION__, i, crtc->bo != NULL));
+               if (crtc->bo == NULL)
+                       continue;
+
+               arg.crtc_id = crtc->id;
+               arg.fb_id = get_fb(sna, bo, width, height);
+               if (arg.fb_id == 0)
+                       goto disable;
+
+               /* Only the reference crtc will finally deliver its page flip
+                * completion event. All other crtc's events will be discarded.
+                */
+               arg.user_data = (uintptr_t)data;
+               arg.user_data |= crtc->pipe == ref_crtc_hw_id;
+               arg.flags = DRM_MODE_PAGE_FLIP_EVENT;
+               arg.reserved = 0;
+
+               DBG(("%s: crtc %d [ref? %d] --> fb %d\n",
+                    __FUNCTION__, crtc->id,
+                    crtc->pipe == ref_crtc_hw_id, arg.fb_id));
+               if (drmIoctl(sna->kgem.fd, DRM_IOCTL_MODE_PAGE_FLIP, &arg)) {
+                       DBG(("%s: flip [fb=%d] on crtc %d [%d] failed - %d\n",
+                            __FUNCTION__, arg.fb_id, i, crtc->id, errno));
+disable:
+                       sna_crtc_disable(config->crtc[i]);
+                       continue;
+               }
+
+               if (crtc->bo != bo) {
+                       kgem_bo_destroy(&sna->kgem, crtc->bo);
+                       crtc->bo = kgem_bo_reference(bo);
+               }
+
+               count++;
+       }
+
+       return count;
+}
+
+int
+sna_page_flip(struct sna *sna,
+             struct kgem_bo *bo,
+             void *data,
+             int ref_crtc_hw_id)
+{
+       int count;
+
+       DBG(("%s: handle %d attached\n", __FUNCTION__, bo->handle));
+       assert(bo->refcnt);
+
+       kgem_submit(&sna->kgem);
+
+       /*
+        * Queue flips on all enabled CRTCs
+        * Note that if/when we get per-CRTC buffers, we'll have to update this.
+        * Right now it assumes a single shared fb across all CRTCs, with the
+        * kernel fixing up the offset of each CRTC as necessary.
+        *
+        * Also, flips queued on disabled or incorrectly configured displays
+        * may never complete; this is a configuration error.
+        */
+       count = do_page_flip(sna, bo, data, ref_crtc_hw_id);
+       DBG(("%s: page flipped %d crtcs\n", __FUNCTION__, count));
+
+       return count;
+}
+
+static const xf86CrtcConfigFuncsRec sna_crtc_config_funcs = {
+       sna_crtc_resize
+};
+
+static void set_size_range(struct sna *sna)
+{
+       /* We lie slightly as we expect no single monitor to exceed the
+        * crtc limits, so if the mode exceeds the scanout restrictions,
+        * we will quietly convert that to per-crtc pixmaps.
+        */
+       xf86CrtcSetSizeRange(sna->scrn, 320, 200, INT16_MAX, INT16_MAX);
+}
+
+bool sna_mode_pre_init(ScrnInfoPtr scrn, struct sna *sna)
+{
+       struct sna_mode *mode = &sna->mode;
+       int i;
+
+       list_init(&mode->crtcs);
+       list_init(&mode->outputs);
+
+       xf86CrtcConfigInit(scrn, &sna_crtc_config_funcs);
+
+       mode->kmode = drmModeGetResources(sna->kgem.fd);
+       if (!mode->kmode) {
+               xf86DrvMsg(scrn->scrnIndex, X_ERROR,
+                          "failed to get resources: %s\n", strerror(errno));
+               return false;
+       }
+
+       set_size_range(sna);
+
+       for (i = 0; i < mode->kmode->count_crtcs; i++)
+               sna_crtc_init(scrn, mode, i);
+
+       for (i = 0; i < mode->kmode->count_connectors; i++)
+               sna_output_init(scrn, mode, i);
+
+#if HAS_PIXMAP_SHARING
+       xf86ProviderSetup(scrn, NULL, "Intel");
+#endif
+       xf86InitialConfiguration(scrn, TRUE);
+
+       return true;
+}
+
+void
+sna_mode_fini(struct sna *sna)
+{
+#if 0
+       while (!list_is_empty(&mode->crtcs)) {
+               xf86CrtcDestroy(list_first_entry(&mode->crtcs,
+                                                struct sna_crtc,
+                                                link)->crtc);
+       }
+
+       while (!list_is_empty(&mode->outputs)) {
+               xf86OutputDestroy(list_first_entry(&mode->outputs,
+                                                  struct sna_output,
+                                                  link)->output);
+       }
+#endif
+}
+
+static bool sna_box_intersect(BoxPtr r, const BoxRec *a, const BoxRec *b)
+{
+       r->x1 = a->x1 > b->x1 ? a->x1 : b->x1;
+       r->x2 = a->x2 < b->x2 ? a->x2 : b->x2;
+       r->y1 = a->y1 > b->y1 ? a->y1 : b->y1;
+       r->y2 = a->y2 < b->y2 ? a->y2 : b->y2;
+       DBG(("%s: (%d, %d), (%d, %d) intersect (%d, %d), (%d, %d) = (%d, %d), (%d, %d)\n",
+            __FUNCTION__,
+            a->x1, a->y1, a->x2, a->y2,
+            b->x1, b->y1, b->x2, b->y2,
+            r->x1, r->y1, r->x2, r->y2));
+       return r->x2 > r->x1 && r->y2 > r->y1;
+}
+
+static int sna_box_area(const BoxRec *box)
+{
+       return (int)(box->x2 - box->x1) * (int)(box->y2 - box->y1);
+}
+
+/*
+ * Return the crtc covering 'box'. If two crtcs cover a portion of
+ * 'box', then prefer 'desired'. If 'desired' is NULL, then prefer the crtc
+ * with greater coverage
+ */
+xf86CrtcPtr
+sna_covering_crtc(ScrnInfoPtr scrn,
+                 const BoxRec *box,
+                 xf86CrtcPtr desired)
+{
+       xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+       xf86CrtcPtr best_crtc;
+       int best_coverage, c;
+
+       /* If we do not own the VT, we do not own the CRTC either */
+       if (!scrn->vtSema)
+               return NULL;
+
+       DBG(("%s for box=(%d, %d), (%d, %d)\n",
+            __FUNCTION__, box->x1, box->y1, box->x2, box->y2));
+
+       best_crtc = NULL;
+       best_coverage = 0;
+       for (c = 0; c < xf86_config->num_crtc; c++) {
+               xf86CrtcPtr crtc = xf86_config->crtc[c];
+               BoxRec cover_box;
+               int coverage;
+
+               /* If the CRTC is off, treat it as not covering */
+               if (to_sna_crtc(crtc)->bo == NULL) {
+                       DBG(("%s: crtc %d off, skipping\n", __FUNCTION__, c));
+                       continue;
+               }
+
+               DBG(("%s: crtc %d: (%d, %d), (%d, %d)\n",
+                    __FUNCTION__, c,
+                    crtc->bounds.x1, crtc->bounds.y1,
+                    crtc->bounds.x2, crtc->bounds.y2));
+
+               if (!sna_box_intersect(&cover_box, &crtc->bounds, box))
+                       continue;
+
+               DBG(("%s: box instersects (%d, %d), (%d, %d) of crtc %d\n",
+                    __FUNCTION__,
+                    cover_box.x1, cover_box.y1,
+                    cover_box.x2, cover_box.y2,
+                    c));
+               if (crtc == desired) {
+                       DBG(("%s: box is on desired crtc [%p]\n",
+                            __FUNCTION__, crtc));
+                       return crtc;
+               }
+
+               coverage = sna_box_area(&cover_box);
+               DBG(("%s: box covers %d of crtc %d\n",
+                    __FUNCTION__, coverage, c));
+               if (coverage > best_coverage) {
+                       best_crtc = crtc;
+                       best_coverage = coverage;
+               }
+       }
+       DBG(("%s: best crtc = %p, coverage = %d\n",
+            __FUNCTION__, best_crtc, best_coverage));
+       return best_crtc;
+}
+
+/* Gen6 wait for scan line support */
+#define MI_LOAD_REGISTER_IMM                   (0x22<<23)
+
+/* gen6: Scan lines register */
+#define GEN6_PIPEA_SLC                 (0x70004)
+#define GEN6_PIPEB_SLC                 (0x71004)
+
+static void sna_emit_wait_for_scanline_gen6(struct sna *sna,
+                                           int pipe, int y1, int y2,
+                                           bool full_height)
+{
+       uint32_t event;
+       uint32_t *b;
+
+       assert (y2 > 0);
+
+       /* We just wait until the trace passes the roi */
+       if (pipe == 0) {
+               pipe = GEN6_PIPEA_SLC;
+               event = MI_WAIT_FOR_PIPEA_SCAN_LINE_WINDOW;
+       } else {
+               pipe = GEN6_PIPEB_SLC;
+               event = MI_WAIT_FOR_PIPEB_SCAN_LINE_WINDOW;
+       }
+
+       kgem_set_mode(&sna->kgem, KGEM_RENDER);
+       b = kgem_get_batch(&sna->kgem, 4);
+       b[0] = MI_LOAD_REGISTER_IMM | 1;
+       b[1] = pipe;
+       b[2] = y2 - 1;
+       b[3] = MI_WAIT_FOR_EVENT | event;
+       kgem_advance_batch(&sna->kgem, 4);
+}
+
+static void sna_emit_wait_for_scanline_gen4(struct sna *sna,
+                                           int pipe, int y1, int y2,
+                                           bool full_height)
+{
+       uint32_t event;
+       uint32_t *b;
+
+       if (pipe == 0) {
+               if (full_height)
+                       event = MI_WAIT_FOR_PIPEA_SVBLANK;
+               else
+                       event = MI_WAIT_FOR_PIPEA_SCAN_LINE_WINDOW;
+       } else {
+               if (full_height)
+                       event = MI_WAIT_FOR_PIPEB_SVBLANK;
+               else
+                       event = MI_WAIT_FOR_PIPEB_SCAN_LINE_WINDOW;
+       }
+
+       kgem_set_mode(&sna->kgem, KGEM_BLT);
+       b = kgem_get_batch(&sna->kgem, 5);
+       /* The documentation says that the LOAD_SCAN_LINES command
+        * always comes in pairs. Don't ask me why. */
+       b[2] = b[0] = MI_LOAD_SCAN_LINES_INCL | pipe << 20;
+       b[3] = b[1] = (y1 << 16) | (y2-1);
+       b[4] = MI_WAIT_FOR_EVENT | event;
+       kgem_advance_batch(&sna->kgem, 5);
+}
+
+static void sna_emit_wait_for_scanline_gen2(struct sna *sna,
+                                           int pipe, int y1, int y2,
+                                           bool full_height)
+{
+       uint32_t *b;
+
+       /*
+        * Pre-965 doesn't have SVBLANK, so we need a bit
+        * of extra time for the blitter to start up and
+        * do its job for a full height blit
+        */
+       if (full_height)
+               y2 -= 2;
+
+       kgem_set_mode(&sna->kgem, KGEM_BLT);
+       b = kgem_get_batch(&sna->kgem, 5);
+       /* The documentation says that the LOAD_SCAN_LINES command
+        * always comes in pairs. Don't ask me why. */
+       b[2] = b[0] = MI_LOAD_SCAN_LINES_INCL | pipe << 20;
+       b[3] = b[1] = (y1 << 16) | (y2-1);
+       if (pipe == 0)
+               b[4] = MI_WAIT_FOR_EVENT | MI_WAIT_FOR_PIPEA_SCAN_LINE_WINDOW;
+       else
+               b[4] = MI_WAIT_FOR_EVENT | MI_WAIT_FOR_PIPEB_SCAN_LINE_WINDOW;
+       kgem_advance_batch(&sna->kgem, 5);
+}
+
+bool
+sna_wait_for_scanline(struct sna *sna,
+                     PixmapPtr pixmap,
+                     xf86CrtcPtr crtc,
+                     const BoxRec *clip)
+{
+       bool full_height;
+       int y1, y2, pipe;
+
+       assert(crtc);
+       assert(to_sna_crtc(crtc)->bo != NULL);
+       assert(pixmap == sna->front);
+
+       /* XXX WAIT_EVENT is still causing hangs on SNB */
+       if (sna->kgem.gen >= 60)
+               return false;
+
+       /*
+        * Make sure we don't wait for a scanline that will
+        * never occur
+        */
+       y1 = clip->y1 - crtc->bounds.y1;
+       if (y1 < 0)
+               y1 = 0;
+       y2 = clip->y2 - crtc->bounds.y1;
+       if (y2 > crtc->bounds.y2 - crtc->bounds.y1)
+               y2 = crtc->bounds.y2 - crtc->bounds.y1;
+       DBG(("%s: clipped range = %d, %d\n", __FUNCTION__, y1, y2));
+       if (y2 <= y1)
+               return false;
+
+       full_height = y1 == 0 && y2 == crtc->bounds.y2 - crtc->bounds.y1;
+
+       if (crtc->mode.Flags & V_INTERLACE) {
+               /* DSL count field lines */
+               y1 /= 2;
+               y2 /= 2;
+       }
+
+       pipe = sna_crtc_to_pipe(crtc);
+       DBG(("%s: pipe=%d, y1=%d, y2=%d, full_height?=%d\n",
+            __FUNCTION__, pipe, y1, y2, full_height));
+
+       if (sna->kgem.gen >= 60)
+               sna_emit_wait_for_scanline_gen6(sna, pipe, y1, y2, full_height);
+       else if (sna->kgem.gen >= 40)
+               sna_emit_wait_for_scanline_gen4(sna, pipe, y1, y2, full_height);
+       else
+               sna_emit_wait_for_scanline_gen2(sna, pipe, y1, y2, full_height);
+
+       return true;
+}
+
+void sna_mode_update(struct sna *sna)
+{
+       xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(sna->scrn);
+       int i;
+
+       /* Validate CRTC attachments */
+       for (i = 0; i < xf86_config->num_crtc; i++) {
+               xf86CrtcPtr crtc = xf86_config->crtc[i];
+               if (!crtc->active || !sna_crtc_is_bound(sna, crtc))
+                       sna_crtc_disable(crtc);
+       }
+
+       update_flush_interval(sna);
+}
+
+static void
+sna_crtc_redisplay__fallback(xf86CrtcPtr crtc, RegionPtr region)
+{
+       struct sna *sna = to_sna(crtc->scrn);
+       struct sna_crtc *sna_crtc = to_sna_crtc(crtc);
+       ScreenPtr screen = sna->scrn->pScreen;
+       PictFormatPtr format;
+       PicturePtr src, dst;
+       PixmapPtr pixmap;
+       BoxPtr b;
+       int n, error;
+       void *ptr;
+
+       DBG(("%s: compositing transformed damage boxes\n", __FUNCTION__));
+
+       ptr = kgem_bo_map__gtt(&sna->kgem, sna_crtc->bo);
+       if (ptr == NULL)
+               return;
+
+       pixmap = sna_pixmap_create_unattached(screen,
+                                             0, 0, sna->front->drawable.depth);
+       if (pixmap == NullPixmap)
+               return;
+
+       if (!screen->ModifyPixmapHeader(pixmap,
+                                       crtc->mode.HDisplay,
+                                       crtc->mode.VDisplay,
+                                       sna->front->drawable.depth,
+                                       sna->front->drawable.bitsPerPixel,
+                                       sna_crtc->bo->pitch, ptr))
+               goto free_pixmap;
+
+       error = sna_render_format_for_depth(sna->front->drawable.depth);
+       format = PictureMatchFormat(screen,
+                                   PIXMAN_FORMAT_DEPTH(error), error);
+       if (format == NULL) {
+               DBG(("%s: can't find format for depth=%d [%08x]\n",
+                    __FUNCTION__, sna->front->drawable.depth,
+                    (int)sna_render_format_for_depth(sna->front->drawable.depth)));
+               goto free_pixmap;
+       }
+
+       src = CreatePicture(None, &sna->front->drawable, format,
+                           0, NULL, serverClient, &error);
+       if (!src)
+               goto free_pixmap;
+
+       error = SetPictureTransform(src, &crtc->crtc_to_framebuffer);
+       if (error)
+               goto free_src;
+
+       if (crtc->filter)
+               SetPicturePictFilter(src, crtc->filter,
+                                    crtc->params, crtc->nparams);
+
+       dst = CreatePicture(None, &pixmap->drawable, format,
+                           0, NULL, serverClient, &error);
+       if (!dst)
+               goto free_src;
+
+       kgem_bo_sync__gtt(&sna->kgem, sna_crtc->bo);
+       n = REGION_NUM_RECTS(region);
+       b = REGION_RECTS(region);
+       do {
+               BoxRec box;
+
+               box = *b++;
+               box.x1 -= crtc->filter_width >> 1;
+               box.x2 += crtc->filter_width >> 1;
+               box.y1 -= crtc->filter_height >> 1;
+               box.y2 += crtc->filter_height >> 1;
+               pixman_f_transform_bounds(&crtc->f_framebuffer_to_crtc, & box);
+
+               DBG(("%s: (%d, %d)x(%d, %d) -> (%d, %d), (%d, %d)\n",
+                    __FUNCTION__,
+                    b[-1].x1, b[-1].y1, b[-1].x2-b[-1].x1, b[-1].y2-b[-1].y1,
+                    box.x1, box.y1, box.x2, box.y2));
+
+               fbComposite(PictOpSrc, src, NULL, dst,
+                           box.x1, box.y1,
+                           0, 0,
+                           box.x1, box.y1,
+                           box.x2 - box.x1, box.y2 - box.y1);
+       } while (--n);
+
+       FreePicture(dst, None);
+free_src:
+       FreePicture(src, None);
+free_pixmap:
+       screen->DestroyPixmap(pixmap);
+}
+
+static void
+sna_crtc_redisplay__composite(xf86CrtcPtr crtc, RegionPtr region)
+{
+       struct sna *sna = to_sna(crtc->scrn);
+       struct sna_crtc *sna_crtc = to_sna_crtc(crtc);
+       ScreenPtr screen = sna->scrn->pScreen;
+       struct sna_composite_op tmp;
+       PictFormatPtr format;
+       PicturePtr src, dst;
+       PixmapPtr pixmap;
+       BoxPtr b;
+       int n, error;
+
+       DBG(("%s: compositing transformed damage boxes\n", __FUNCTION__));
+
+       pixmap = sna_pixmap_create_unattached(screen,
+                                             crtc->mode.HDisplay,
+                                             crtc->mode.VDisplay,
+                                             sna->front->drawable.depth);
+       if (pixmap == NullPixmap)
+               return;
+
+       if (!sna_pixmap_attach_to_bo(pixmap, sna_crtc->bo))
+               goto free_pixmap;
+
+       error = sna_render_format_for_depth(sna->front->drawable.depth);
+       format = PictureMatchFormat(screen,
+                                   PIXMAN_FORMAT_DEPTH(error), error);
+       if (format == NULL) {
+               DBG(("%s: can't find format for depth=%d [%08x]\n",
+                    __FUNCTION__, sna->front->drawable.depth,
+                    (int)sna_render_format_for_depth(sna->front->drawable.depth)));
+               goto free_pixmap;
+       }
+
+       src = CreatePicture(None, &sna->front->drawable, format,
+                           0, NULL, serverClient, &error);
+       if (!src)
+               goto free_pixmap;
+
+       error = SetPictureTransform(src, &crtc->crtc_to_framebuffer);
+       if (error)
+               goto free_src;
+
+       if (crtc->filter)
+               SetPicturePictFilter(src, crtc->filter,
+                                    crtc->params, crtc->nparams);
+
+       dst = CreatePicture(None, &pixmap->drawable, format,
+                           0, NULL, serverClient, &error);
+       if (!dst)
+               goto free_src;
+
+       if (!sna->render.composite(sna,
+                                  PictOpSrc, src, NULL, dst,
+                                  0, 0,
+                                  0, 0,
+                                  0, 0,
+                                  0, 0,
+                                  memset(&tmp, 0, sizeof(tmp)))) {
+               DBG(("%s: unsupported operation!\n", __FUNCTION__));
+               sna_crtc_redisplay__fallback(crtc, region);
+               goto free_dst;
+       }
+
+       n = REGION_NUM_RECTS(region);
+       b = REGION_RECTS(region);
+       do {
+               BoxRec box;
+
+               box = *b++;
+               box.x1 -= crtc->filter_width >> 1;
+               box.x2 += crtc->filter_width >> 1;
+               box.y1 -= crtc->filter_height >> 1;
+               box.y2 += crtc->filter_height >> 1;
+               pixman_f_transform_bounds(&crtc->f_framebuffer_to_crtc, & box);
+
+               DBG(("%s: (%d, %d)x(%d, %d) -> (%d, %d), (%d, %d)\n",
+                    __FUNCTION__,
+                    b[-1].x1, b[-1].y1, b[-1].x2-b[-1].x1, b[-1].y2-b[-1].y1,
+                    box.x1, box.y1, box.x2, box.y2));
+
+               tmp.box(sna, &tmp, &box);
+       } while (--n);
+       tmp.done(sna, &tmp);
+
+free_dst:
+       FreePicture(dst, None);
+free_src:
+       FreePicture(src, None);
+free_pixmap:
+       screen->DestroyPixmap(pixmap);
+}
+
+static void
+sna_crtc_redisplay(xf86CrtcPtr crtc, RegionPtr region)
+{
+       struct sna *sna = to_sna(crtc->scrn);
+       struct sna_crtc *sna_crtc = to_sna_crtc(crtc);
+       int16_t tx, ty;
+
+       DBG(("%s: crtc %d [pipe=%d], damage (%d, %d), (%d, %d) x %d\n",
+            __FUNCTION__, sna_crtc->id, sna_crtc->pipe,
+            region->extents.x1, region->extents.y1,
+            region->extents.x2, region->extents.y2,
+            REGION_NUM_RECTS(region)));
+
+       assert(!wedged(sna));
+
+       if (crtc->filter == NULL &&
+           sna_transform_is_integer_translation(&crtc->crtc_to_framebuffer,
+                                                &tx, &ty)) {
+               PixmapRec tmp;
+
+               DBG(("%s: copy damage boxes\n", __FUNCTION__));
+
+               tmp.drawable.width = crtc->mode.HDisplay;
+               tmp.drawable.height = crtc->mode.VDisplay;
+               tmp.drawable.depth = sna->front->drawable.depth;
+               tmp.drawable.bitsPerPixel = sna->front->drawable.bitsPerPixel;
+
+               /* XXX for tear-free we may want to try copying to a back
+                * and flipping.
+                */
+
+               if (sna->render.copy_boxes(sna, GXcopy,
+                                          sna->front, sna_pixmap_get_bo(sna->front), 0, 0,
+                                          &tmp, sna_crtc->bo, -tx, -ty,
+                                          REGION_RECTS(region), REGION_NUM_RECTS(region), 0))
+                       return;
+       }
+
+       sna_crtc_redisplay__composite(crtc, region);
+}
+
+void sna_mode_redisplay(struct sna *sna)
+{
+       xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(sna->scrn);
+       RegionPtr region;
+       int i;
+
+       if (!sna->mode.shadow_damage)
+               return;
+
+       DBG(("%s: posting shadow damage\n", __FUNCTION__));
+       assert(sna->mode.shadow_active);
+
+       region = DamageRegion(sna->mode.shadow_damage);
+       if (!RegionNotEmpty(region))
+               return;
+
+       if (!sna_pixmap_move_to_gpu(sna->front, MOVE_READ)) {
+               if (!sna_pixmap_move_to_cpu(sna->front, MOVE_READ))
+                       return;
+
+               for (i = 0; i < config->num_crtc; i++) {
+                       xf86CrtcPtr crtc = config->crtc[i];
+                       struct sna_crtc *sna_crtc = to_sna_crtc(crtc);
+                       RegionRec damage;
+
+                       if (!sna_crtc->shadow)
+                               continue;
+
+                       assert(crtc->enabled);
+                       assert(crtc->transform_in_use);
+
+                       damage.extents = crtc->bounds;
+                       damage.data = NULL;
+                       RegionIntersect(&damage, &damage, region);
+                       if (RegionNotEmpty(&damage))
+                               sna_crtc_redisplay__fallback(crtc, &damage);
+                       RegionUninit(&damage);
+               }
+
+               RegionEmpty(region);
+               return;
+       }
+
+       for (i = 0; i < config->num_crtc; i++) {
+               xf86CrtcPtr crtc = config->crtc[i];
+               struct sna_crtc *sna_crtc = to_sna_crtc(crtc);
+               RegionRec damage;
+
+               if (!sna_crtc->shadow || sna_crtc->bo == sna->mode.shadow)
+                       continue;
+
+               assert(crtc->enabled);
+               assert(crtc->transform_in_use);
+
+               damage.extents = crtc->bounds;
+               damage.data = NULL;
+               RegionIntersect(&damage, &damage, region);
+               if (RegionNotEmpty(&damage)) {
+                       sna_crtc_redisplay(crtc, &damage);
+                       __kgem_flush(&sna->kgem, sna_crtc->bo);
+               }
+               RegionUninit(&damage);
+       }
+
+       if (!sna->mode.shadow) {
+               kgem_submit(&sna->kgem);
+               RegionEmpty(region);
+               return;
+       }
+
+       if (sna->mode.shadow_flip == 0) {
+               struct kgem_bo *new = sna_pixmap_get_bo(sna->front);
+               struct kgem_bo *old = sna->mode.shadow;
+
+               DBG(("%s: flipping tear-free outputs\n", __FUNCTION__));
+               kgem_bo_submit(&sna->kgem, new);
+
+               for (i = 0; i < config->num_crtc; i++) {
+                       struct sna_crtc *crtc = config->crtc[i]->driver_private;
+
+                       DBG(("%s: crtc %d [%d, pipe=%d] active? %d\n",
+                            __FUNCTION__, i, crtc->id, crtc->pipe, crtc->bo != NULL));
+                       if (crtc->bo != old)
+                               continue;
+
+                       assert(config->crtc[i]->enabled);
+
+                       if (crtc->dpms_mode == DPMSModeOn) {
+                               struct drm_mode_crtc_page_flip arg;
+                               arg.crtc_id = crtc->id;
+                               arg.fb_id = get_fb(sna, new,
+                                                  sna->scrn->virtualX,
+                                                  sna->scrn->virtualY);
+                               if (arg.fb_id == 0)
+                                       goto disable;
+
+                               /* Only the reference crtc will finally deliver its page flip
+                                * completion event. All other crtc's events will be discarded.
+                                */
+                               arg.user_data = 0;
+                               arg.flags = DRM_MODE_PAGE_FLIP_EVENT;
+                               arg.reserved = 0;
+
+                               if (drmIoctl(sna->kgem.fd, DRM_IOCTL_MODE_PAGE_FLIP, &arg)) {
+                                       DBG(("%s: flip [fb=%d] on crtc %d [%d, pipe=%d] failed - %d\n",
+                                            __FUNCTION__, arg.fb_id, i, crtc->id, crtc->pipe, errno));
+disable:
+                                       sna_crtc_disable(config->crtc[i]);
+                                       continue;
+                               }
+                               sna->mode.shadow_flip++;
+                       }
+
+                       kgem_bo_destroy(&sna->kgem, old);
+                       crtc->bo = kgem_bo_reference(new);
+               }
+
+               if (sna->mode.shadow) {
+                       /* XXX only works if the kernel stalls fwrites to the current
+                        * scanout whilst the flip is pending
+                        */
+                       while (sna->mode.shadow_flip)
+                               sna_mode_wakeup(sna);
+                       (void)sna->render.copy_boxes(sna, GXcopy,
+                                                    sna->front, new, 0, 0,
+                                                    sna->front, old, 0, 0,
+                                                    REGION_RECTS(region),
+                                                    REGION_NUM_RECTS(region),
+                                                    COPY_LAST);
+                       kgem_submit(&sna->kgem);
+
+                       sna_pixmap(sna->front)->gpu_bo = old;
+                       sna->mode.shadow = new;
+
+                       new->flush = old->flush;
+               }
+
+               RegionEmpty(region);
+       }
+}
+
+void sna_mode_wakeup(struct sna *sna)
+{
+       char buffer[1024];
+       int len, i;
+
+       /* The DRM read semantics guarantees that we always get only
+        * complete events.
+        */
+       len = read(sna->kgem.fd, buffer, sizeof (buffer));
+       if (len < (int)sizeof(struct drm_event))
+               return;
+
+       DBG(("%s: len=%d\n", __FUNCTION__, len));
+
+       i = 0;
+       while (i < len) {
+               struct drm_event *e = (struct drm_event *)&buffer[i];
+               switch (e->type) {
+               case DRM_EVENT_VBLANK:
+                       sna_dri_vblank_handler(sna, (struct drm_event_vblank *)e);
+                       break;
+               case DRM_EVENT_FLIP_COMPLETE:
+                       if (((struct drm_event_vblank *)e)->user_data)
+                               sna_dri_page_flip_handler(sna, (struct drm_event_vblank *)e);
+                       else
+                               sna->mode.shadow_flip--;
+                       break;
+               default:
+                       break;
+               }
+               i += e->length;
+       }
+}
diff --git a/src/sna/sna_dri.c b/src/sna/sna_dri.c
new file mode 100644 (file)
index 0000000..676636a
--- /dev/null
@@ -0,0 +1,2278 @@
+/**************************************************************************
+
+Copyright 2001 VA Linux Systems Inc., Fremont, California.
+Copyright © 2002 by David Dawes
+
+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
+on the rights to use, copy, modify, merge, publish, distribute, sub
+license, 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 NON-INFRINGEMENT. IN NO EVENT SHALL
+ATI, VA LINUX SYSTEMS AND/OR THEIR SUPPLIERS 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.
+
+**************************************************************************/
+
+/*
+ * Authors: Jeff Hartmann <jhartmann@valinux.com>
+ *          David Dawes <dawes@xfree86.org>
+ *          Keith Whitwell <keith@tungstengraphics.com>
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <string.h>
+
+#include "sna.h"
+#include "sna_reg.h"
+
+#include <xf86drm.h>
+#include <i915_drm.h>
+#include <dri2.h>
+
+#if DRI2INFOREC_VERSION <= 2
+#error DRI2 version supported by the Xserver is too old
+#endif
+
+#if DRI2INFOREC_VERSION < 10
+#define USE_ASYNC_SWAP 0
+#endif
+
+#define COLOR_PREFER_TILING_Y 0
+
+enum frame_event_type {
+       DRI2_SWAP,
+       DRI2_SWAP_WAIT,
+       DRI2_SWAP_THROTTLE,
+       DRI2_XCHG_THROTTLE,
+       DRI2_ASYNC_FLIP,
+       DRI2_FLIP,
+       DRI2_FLIP_THROTTLE,
+       DRI2_WAITMSC,
+};
+
+struct sna_dri_frame_event {
+       DrawablePtr draw;
+       ClientPtr client;
+       enum frame_event_type type;
+       int pipe;
+       int count;
+
+       /* for swaps & flips only */
+       DRI2SwapEventPtr event_complete;
+       void *event_data;
+       DRI2BufferPtr front;
+       DRI2BufferPtr back;
+       struct kgem_bo *bo;
+
+       struct sna_dri_frame_event *chain;
+
+       unsigned int fe_frame;
+       unsigned int fe_tv_sec;
+       unsigned int fe_tv_usec;
+
+       struct dri_bo {
+               struct kgem_bo *bo;
+               uint32_t name;
+       } old_front, next_front, cache;
+
+       int off_delay;
+};
+
+struct sna_dri_private {
+       int refcnt;
+       PixmapPtr pixmap;
+       struct kgem_bo *bo;
+};
+
+static inline struct sna_dri_frame_event *
+to_frame_event(uintptr_t  data)
+{
+        return (struct sna_dri_frame_event *)(data & ~1);
+}
+
+static inline struct sna_dri_private *
+get_private(DRI2Buffer2Ptr buffer)
+{
+       return (struct sna_dri_private *)(buffer+1);
+}
+
+static inline struct kgem_bo *ref(struct kgem_bo *bo)
+{
+       assert(bo->refcnt);
+       bo->refcnt++;
+       return bo;
+}
+
+/* Prefer to enable TILING_Y if this buffer will never be a
+ * candidate for pageflipping
+ */
+static uint32_t color_tiling(struct sna *sna, DrawablePtr draw)
+{
+       uint32_t tiling;
+
+       if (COLOR_PREFER_TILING_Y &&
+           (draw->width  != sna->front->drawable.width ||
+            draw->height != sna->front->drawable.height))
+               tiling = I915_TILING_Y;
+       else
+               tiling = I915_TILING_X;
+
+       return kgem_choose_tiling(&sna->kgem, -tiling,
+                                 draw->width,
+                                 draw->height,
+                                 draw->bitsPerPixel);
+}
+
+static uint32_t other_tiling(struct sna *sna, DrawablePtr draw)
+{
+       /* XXX Can mix color X / depth Y? */
+       return kgem_choose_tiling(&sna->kgem, -I915_TILING_Y,
+                                 draw->width,
+                                 draw->height,
+                                 draw->bitsPerPixel);
+}
+
+static struct kgem_bo *sna_pixmap_set_dri(struct sna *sna,
+                                         PixmapPtr pixmap)
+{
+       struct sna_pixmap *priv;
+       int tiling;
+
+       DBG(("%s: attaching DRI client to pixmap=%ld\n",
+            __FUNCTION__, pixmap->drawable.serialNumber));
+
+       priv = sna_pixmap(pixmap);
+       if (priv != NULL && priv->shm) {
+               DBG(("%s: SHM Pixmap, BadAlloc\n", __FUNCTION__));
+               return NULL;
+       }
+
+       priv = sna_pixmap_move_to_gpu(pixmap,
+                                     MOVE_READ | MOVE_WRITE | __MOVE_FORCE | __MOVE_DRI);
+       if (priv == NULL) {
+               DBG(("%s: failed to move to GPU, BadAlloc\n", __FUNCTION__));
+               return NULL;
+       }
+
+       assert(priv->cpu_damage == NULL);
+       if (priv->flush++)
+               return priv->gpu_bo;
+
+       tiling = color_tiling(sna, &pixmap->drawable);
+       if (tiling < 0)
+               tiling = -tiling;
+       if (priv->gpu_bo->tiling != tiling)
+               sna_pixmap_change_tiling(pixmap, tiling);
+
+       /* We need to submit any modifications to and reads from this
+        * buffer before we send any reply to the Client.
+        *
+        * As we don't track which Client, we flush for all.
+        */
+       sna_accel_watch_flush(sna, 1);
+
+       /* Don't allow this named buffer to be replaced */
+       priv->pinned |= PIN_DRI;
+
+       return priv->gpu_bo;
+}
+
+constant static inline void *sna_pixmap_get_buffer(PixmapPtr pixmap)
+{
+       assert(pixmap->refcnt);
+       return ((void **)dixGetPrivateAddr(&pixmap->devPrivates, &sna_pixmap_key))[2];
+}
+
+static inline void sna_pixmap_set_buffer(PixmapPtr pixmap, void *ptr)
+{
+       assert(pixmap->refcnt);
+       ((void **)dixGetPrivateAddr(&pixmap->devPrivates, &sna_pixmap_key))[2] = ptr;
+}
+
+static DRI2Buffer2Ptr
+sna_dri_create_buffer(DrawablePtr draw,
+                     unsigned int attachment,
+                     unsigned int format)
+{
+       struct sna *sna = to_sna_from_drawable(draw);
+       DRI2Buffer2Ptr buffer;
+       struct sna_dri_private *private;
+       PixmapPtr pixmap;
+       struct kgem_bo *bo;
+       int bpp;
+
+       DBG(("%s(attachment=%d, format=%d, drawable=%dx%d)\n",
+            __FUNCTION__, attachment, format, draw->width, draw->height));
+
+       pixmap = NULL;
+       switch (attachment) {
+       case DRI2BufferFrontLeft:
+               pixmap = get_drawable_pixmap(draw);
+               buffer = sna_pixmap_get_buffer(pixmap);
+               if (buffer) {
+                       private = get_private(buffer);
+
+                       DBG(("%s: reusing front buffer attachment, pixmap=%ld, handle=%d, name=%d\n",
+                            __FUNCTION__, pixmap->drawable.serialNumber,
+                            private->bo->handle, buffer->name));
+
+                       assert(private->pixmap == pixmap);
+                       assert(sna_pixmap(pixmap)->gpu_bo == private->bo);
+                       assert(kgem_bo_flink(&sna->kgem, private->bo) == buffer->name);
+
+                       private->refcnt++;
+                       return buffer;
+               }
+
+               bo = sna_pixmap_set_dri(sna, pixmap);
+               if (bo == NULL)
+                       return NULL;
+
+               bo = ref(bo);
+               bpp = pixmap->drawable.bitsPerPixel;
+               DBG(("%s: attaching to front buffer %dx%d [%p:%d]\n",
+                    __FUNCTION__,
+                    pixmap->drawable.width, pixmap->drawable.height,
+                    pixmap, pixmap->refcnt));
+               break;
+
+       case DRI2BufferBackLeft:
+       case DRI2BufferBackRight:
+       case DRI2BufferFrontRight:
+       case DRI2BufferFakeFrontLeft:
+       case DRI2BufferFakeFrontRight:
+               bpp = draw->bitsPerPixel;
+               bo = kgem_create_2d(&sna->kgem,
+                                   draw->width,
+                                   draw->height,
+                                   draw->bitsPerPixel,
+                                   color_tiling(sna, draw),
+                                   CREATE_SCANOUT | CREATE_EXACT);
+               break;
+
+       case DRI2BufferStencil:
+               /*
+                * The stencil buffer has quirky pitch requirements.  From Vol
+                * 2a, 11.5.6.2.1 3DSTATE_STENCIL_BUFFER, field "Surface
+                * Pitch":
+                *    The pitch must be set to 2x the value computed based on
+                *    width, as the stencil buffer is stored with two rows
+                *    interleaved.
+                * To accomplish this, we resort to the nasty hack of doubling
+                * the drm region's cpp and halving its height.
+                *
+                * If we neglect to double the pitch, then
+                * drm_intel_gem_bo_map_gtt() maps the memory incorrectly.
+                *
+                * The alignment for W-tiling is quite different to the
+                * nominal no-tiling case, so we have to account for
+                * the tiled access pattern explicitly.
+                *
+                * The stencil buffer is W tiled. However, we request from
+                * the kernel a non-tiled buffer because the kernel does
+                * not understand W tiling and the GTT is incapable of
+                * W fencing.
+                */
+               bpp = format ? format : draw->bitsPerPixel;
+               bpp *= 2;
+               bo = kgem_create_2d(&sna->kgem,
+                                   ALIGN(draw->width, 64),
+                                   ALIGN((draw->height + 1) / 2, 64),
+                                   bpp, I915_TILING_NONE, CREATE_EXACT);
+               break;
+
+       case DRI2BufferDepth:
+       case DRI2BufferDepthStencil:
+       case DRI2BufferHiz:
+       case DRI2BufferAccum:
+               bpp = format ? format : draw->bitsPerPixel,
+               bo = kgem_create_2d(&sna->kgem,
+                                   draw->width, draw->height, bpp,
+                                   other_tiling(sna, draw),
+                                   CREATE_EXACT);
+               break;
+
+       default:
+               return NULL;
+       }
+       if (bo == NULL)
+               return NULL;
+
+       buffer = calloc(1, sizeof *buffer + sizeof *private);
+       if (buffer == NULL)
+               goto err;
+
+       private = get_private(buffer);
+       buffer->attachment = attachment;
+       buffer->pitch = bo->pitch;
+       buffer->cpp = bpp / 8;
+       buffer->driverPrivate = private;
+       buffer->format = format;
+       buffer->flags = 0;
+       buffer->name = kgem_bo_flink(&sna->kgem, bo);
+       private->refcnt = 1;
+       private->bo = bo;
+       private->pixmap = pixmap;
+
+       if (buffer->name == 0)
+               goto err;
+
+       if (pixmap) {
+               assert(attachment == DRI2BufferFrontLeft);
+               sna_pixmap_set_buffer(pixmap, buffer);
+               assert(sna_pixmap_get_buffer(pixmap) == buffer);
+               pixmap->refcnt++;
+       }
+
+       assert(bo->flush == true);
+
+       return buffer;
+
+err:
+       kgem_bo_destroy(&sna->kgem, bo);
+       free(buffer);
+       return NULL;
+}
+
+static void _sna_dri_destroy_buffer(struct sna *sna, DRI2Buffer2Ptr buffer)
+{
+       struct sna_dri_private *private = get_private(buffer);
+
+       if (buffer == NULL)
+               return;
+
+       DBG(("%s: %p [handle=%d] -- refcnt=%d, pixmap=%ld\n",
+            __FUNCTION__, buffer, private->bo->handle, private->refcnt,
+            private->pixmap ? private->pixmap->drawable.serialNumber : 0));
+
+       if (--private->refcnt == 0) {
+               if (private->pixmap) {
+                       PixmapPtr pixmap = private->pixmap;
+                       struct sna_pixmap *priv = sna_pixmap(pixmap);
+
+                       /* Undo the DRI markings on this pixmap */
+                       if (priv->flush && --priv->flush == 0) {
+                               DBG(("%s: releasing last DRI pixmap=%ld, scanout?=%d\n",
+                                    __FUNCTION__,
+                                    pixmap->drawable.serialNumber,
+                                    pixmap == sna->front));
+                               list_del(&priv->list);
+                               sna_accel_watch_flush(sna, -1);
+                               priv->pinned &= ~PIN_DRI;
+                       }
+
+                       sna_pixmap_set_buffer(pixmap, NULL);
+                       pixmap->drawable.pScreen->DestroyPixmap(pixmap);
+               }
+
+               private->bo->flush = 0;
+               kgem_bo_destroy(&sna->kgem, private->bo);
+
+               free(buffer);
+       }
+}
+
+static void sna_dri_destroy_buffer(DrawablePtr draw, DRI2Buffer2Ptr buffer)
+{
+       _sna_dri_destroy_buffer(to_sna_from_drawable(draw), buffer);
+}
+
+static void sna_dri_reference_buffer(DRI2Buffer2Ptr buffer)
+{
+       get_private(buffer)->refcnt++;
+}
+
+static void damage(PixmapPtr pixmap, RegionPtr region)
+{
+       struct sna_pixmap *priv;
+
+       priv = sna_pixmap(pixmap);
+       assert(priv != NULL);
+       if (DAMAGE_IS_ALL(priv->gpu_damage))
+               return;
+
+       if (region == NULL) {
+damage_all:
+               priv->gpu_damage = _sna_damage_all(priv->gpu_damage,
+                                                  pixmap->drawable.width,
+                                                  pixmap->drawable.height);
+               sna_damage_destroy(&priv->cpu_damage);
+               priv->undamaged = false;
+       } else {
+               sna_damage_subtract(&priv->cpu_damage, region);
+               if (priv->cpu_damage == NULL)
+                       goto damage_all;
+               sna_damage_add(&priv->gpu_damage, region);
+       }
+}
+
+static void set_bo(PixmapPtr pixmap, struct kgem_bo *bo)
+{
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+       struct sna_pixmap *priv = sna_pixmap(pixmap);
+       RegionRec region;
+
+       sna_damage_all(&priv->gpu_damage,
+                      pixmap->drawable.width,
+                      pixmap->drawable.height);
+       sna_damage_destroy(&priv->cpu_damage);
+       list_del(&priv->list);
+       priv->cpu = false;
+       priv->undamaged = false;
+
+       assert(bo->refcnt);
+       if (priv->gpu_bo != bo) {
+               kgem_bo_destroy(&sna->kgem, priv->gpu_bo);
+               priv->gpu_bo = ref(bo);
+       }
+       if (bo->domain != DOMAIN_GPU)
+               bo->domain = DOMAIN_NONE;
+
+       /* Post damage on the new front buffer so that listeners, such
+        * as DisplayLink know take a copy and shove it over the USB.
+        */
+       region.extents.x1 = region.extents.y1 = 0;
+       region.extents.x2 = pixmap->drawable.width;
+       region.extents.y2 = pixmap->drawable.height;
+       region.data = NULL;
+       DamageRegionAppend(&pixmap->drawable, &region);
+       DamageRegionProcessPending(&pixmap->drawable);
+}
+
+static void sna_dri_select_mode(struct sna *sna, struct kgem_bo *src, bool sync)
+{
+       struct drm_i915_gem_busy busy;
+       int mode;
+
+       if (sna->kgem.gen < 60)
+               return;
+
+       if (sync) {
+               DBG(("%s: sync, force RENDER ring\n", __FUNCTION__));
+               kgem_set_mode(&sna->kgem, KGEM_RENDER);
+               return;
+       }
+
+       if (sna->kgem.mode != KGEM_NONE) {
+               DBG(("%s: busy, not switching\n", __FUNCTION__));
+               return;
+       }
+
+       if (sna->kgem.has_semaphores) {
+               DBG(("%s: have sempahores, prefering RENDER\n", __FUNCTION__));
+               kgem_set_mode(&sna->kgem, KGEM_RENDER);
+               return;
+       }
+
+       VG_CLEAR(busy);
+       busy.handle = src->handle;
+       if (drmIoctl(sna->kgem.fd, DRM_IOCTL_I915_GEM_BUSY, &busy))
+               return;
+
+       DBG(("%s: src busy?=%x\n", __FUNCTION__, busy.busy));
+       if (busy.busy == 0) {
+               DBG(("%s: src is idle, using defaults\n", __FUNCTION__));
+               return;
+       }
+
+       /* Sandybridge introduced a separate ring which it uses to
+        * perform blits. Switching rendering between rings incurs
+        * a stall as we wait upon the old ring to finish and
+        * flush its render cache before we can proceed on with
+        * the operation on the new ring.
+        *
+        * As this buffer, we presume, has just been written to by
+        * the DRI client using the RENDER ring, we want to perform
+        * our operation on the same ring, and ideally on the same
+        * ring as we will flip from (which should be the RENDER ring
+        * as well).
+        *
+        * The ultimate question is whether preserving the ring outweighs
+        * the cost of the query.
+        */
+       mode = KGEM_RENDER;
+       if (busy.busy & (1 << 17))
+               mode = KGEM_BLT;
+       _kgem_set_mode(&sna->kgem, mode);
+}
+
+static void
+sna_dri_copy_fallback(struct sna *sna, int bpp,
+                     struct kgem_bo *src_bo, int sx, int sy,
+                     struct kgem_bo *dst_bo, int dx, int dy,
+                     const BoxRec *box, int n)
+{
+       void *dst = kgem_bo_map__gtt(&sna->kgem, dst_bo);
+       void *src = kgem_bo_map__gtt(&sna->kgem, src_bo);
+
+       DBG(("%s: src(%d, %d), dst(%d, %d) x %d\n",
+            __FUNCTION__, sx, sy, dx, dy, n));
+
+       do {
+               memcpy_blt(src, dst, bpp,
+                          src_bo->pitch, dst_bo->pitch,
+                          box->x1 + sx, box->y1 + sy,
+                          box->x1 + dx, box->y1 + dy,
+                          box->x2 - box->x1, box->y2 - box->y1);
+               box++;
+       } while (--n);
+}
+
+static struct kgem_bo *
+sna_dri_copy_to_front(struct sna *sna, DrawablePtr draw, RegionPtr region,
+                     struct kgem_bo *dst_bo, struct kgem_bo *src_bo,
+                     bool sync)
+{
+       PixmapPtr pixmap = get_drawable_pixmap(draw);
+       pixman_region16_t clip;
+       struct kgem_bo *bo = NULL;
+       bool flush = false;
+       xf86CrtcPtr crtc;
+       BoxRec *boxes;
+       int16_t dx, dy;
+       int n;
+
+       clip.extents.x1 = draw->x;
+       clip.extents.y1 = draw->y;
+       clip.extents.x2 = draw->x + draw->width;
+       clip.extents.y2 = draw->y + draw->height;
+       clip.data = NULL;
+
+       if (region) {
+               pixman_region_translate(region, draw->x, draw->y);
+               pixman_region_intersect(&clip, &clip, region);
+               region = &clip;
+
+               if (!pixman_region_not_empty(region)) {
+                       DBG(("%s: all clipped\n", __FUNCTION__));
+                       return NULL;
+               }
+       }
+
+       if (!wedged(sna)) {
+               if (sync)
+                       sync = sna_pixmap_is_scanout(sna, pixmap);
+
+               sna_dri_select_mode(sna, src_bo, sync);
+       } else
+               sync = false;
+
+       dx = dy = 0;
+       if (draw->type != DRAWABLE_PIXMAP) {
+               WindowPtr win = (WindowPtr)draw;
+
+               if (is_clipped(&win->clipList, draw)) {
+                       DBG(("%s: draw=(%d, %d), delta=(%d, %d), clip.extents=(%d, %d), (%d, %d)\n",
+                            __FUNCTION__, draw->x, draw->y,
+                            get_drawable_dx(draw), get_drawable_dy(draw),
+                            win->clipList.extents.x1, win->clipList.extents.y1,
+                            win->clipList.extents.x2, win->clipList.extents.y2));
+
+                       if (region == NULL)
+                               region = &clip;
+
+                       pixman_region_intersect(&clip, &win->clipList, region);
+                       if (!pixman_region_not_empty(&clip)) {
+                               DBG(("%s: all clipped\n", __FUNCTION__));
+                               return NULL;
+                       }
+
+                       region = &clip;
+               }
+
+               if (sync) {
+                       crtc = sna_covering_crtc(sna->scrn, &clip.extents, NULL);
+                       if (crtc)
+                               flush = sna_wait_for_scanline(sna, pixmap, crtc,
+                                                             &clip.extents);
+               }
+
+               get_drawable_deltas(draw, pixmap, &dx, &dy);
+       }
+
+       damage(pixmap, region);
+       if (region) {
+               boxes = REGION_RECTS(region);
+               n = REGION_NUM_RECTS(region);
+               assert(n);
+       } else {
+               region = &clip;
+               boxes = &clip.extents;
+               n = 1;
+       }
+       if (wedged(sna)) {
+               sna_dri_copy_fallback(sna, draw->bitsPerPixel,
+                                     src_bo, -draw->x, -draw->y,
+                                     dst_bo, dx, dy,
+                                     boxes, n);
+       } else {
+               sna->render.copy_boxes(sna, GXcopy,
+                                      (PixmapPtr)draw, src_bo, -draw->x, -draw->y,
+                                      pixmap, dst_bo, dx, dy,
+                                      boxes, n, COPY_LAST);
+
+               DBG(("%s: flushing? %d\n", __FUNCTION__, flush));
+               if (flush) { /* STAT! */
+                       struct kgem_request *rq = sna->kgem.next_request;
+                       kgem_submit(&sna->kgem);
+                       bo = kgem_bo_reference(rq->bo);
+               }
+       }
+
+       pixman_region_translate(region, dx, dy);
+       DamageRegionAppend(&pixmap->drawable, region);
+       DamageRegionProcessPending(&pixmap->drawable);
+
+       if (clip.data)
+               pixman_region_fini(&clip);
+
+       return bo;
+}
+
+static void
+sna_dri_copy_from_front(struct sna *sna, DrawablePtr draw, RegionPtr region,
+                       struct kgem_bo *dst_bo, struct kgem_bo *src_bo,
+                       bool sync)
+{
+       PixmapPtr pixmap = get_drawable_pixmap(draw);
+       pixman_region16_t clip;
+       BoxRec box, *boxes;
+       int16_t dx, dy;
+       int n;
+
+       box.x1 = draw->x;
+       box.y1 = draw->y;
+       box.x2 = draw->x + draw->width;
+       box.y2 = draw->y + draw->height;
+
+       if (region) {
+               pixman_region_translate(region, draw->x, draw->y);
+               pixman_region_init_rects(&clip, &box, 1);
+               pixman_region_intersect(&clip, &clip, region);
+               region = &clip;
+
+               if (!pixman_region_not_empty(region)) {
+                       DBG(("%s: all clipped\n", __FUNCTION__));
+                       return;
+               }
+       }
+
+       dx = dy = 0;
+       if (draw->type != DRAWABLE_PIXMAP) {
+               WindowPtr win = (WindowPtr)draw;
+
+               DBG(("%s: draw=(%d, %d), delta=(%d, %d), clip.extents=(%d, %d), (%d, %d)\n",
+                    __FUNCTION__, draw->x, draw->y,
+                    get_drawable_dx(draw), get_drawable_dy(draw),
+                    win->clipList.extents.x1, win->clipList.extents.y1,
+                    win->clipList.extents.x2, win->clipList.extents.y2));
+
+               if (region == NULL) {
+                       pixman_region_init_rects(&clip, &box, 1);
+                       region = &clip;
+               }
+
+               pixman_region_intersect(region, &win->clipList, region);
+               if (!pixman_region_not_empty(region)) {
+                       DBG(("%s: all clipped\n", __FUNCTION__));
+                       return;
+               }
+
+               get_drawable_deltas(draw, pixmap, &dx, &dy);
+       }
+
+       if (region) {
+               boxes = REGION_RECTS(region);
+               n = REGION_NUM_RECTS(region);
+               assert(n);
+       } else {
+               pixman_region_init_rects(&clip, &box, 1);
+               region = &clip;
+               boxes = &box;
+               n = 1;
+       }
+       if (wedged(sna)) {
+               sna_dri_copy_fallback(sna, draw->bitsPerPixel,
+                                     src_bo, dx, dy,
+                                     dst_bo, -draw->x, -draw->y,
+                                     boxes, n);
+       } else {
+               sna_dri_select_mode(sna, src_bo, false);
+               sna->render.copy_boxes(sna, GXcopy,
+                                      pixmap, src_bo, dx, dy,
+                                      (PixmapPtr)draw, dst_bo, -draw->x, -draw->y,
+                                      boxes, n, COPY_LAST);
+       }
+
+       if (region == &clip)
+               pixman_region_fini(&clip);
+}
+
+static void
+sna_dri_copy(struct sna *sna, DrawablePtr draw, RegionPtr region,
+            struct kgem_bo *dst_bo, struct kgem_bo *src_bo,
+            bool sync)
+{
+       pixman_region16_t clip;
+       BoxRec box, *boxes;
+       int n;
+
+       box.x1 = 0;
+       box.y1 = 0;
+       box.x2 = draw->width;
+       box.y2 = draw->height;
+
+       if (region) {
+               pixman_region_init_rects(&clip, &box, 1);
+               pixman_region_intersect(&clip, &clip, region);
+               region = &clip;
+
+               if (!pixman_region_not_empty(region)) {
+                       DBG(("%s: all clipped\n", __FUNCTION__));
+                       return;
+               }
+
+               boxes = REGION_RECTS(region);
+               n = REGION_NUM_RECTS(region);
+               assert(n);
+       } else {
+               boxes = &box;
+               n = 1;
+       }
+
+       if (wedged(sna)) {
+               sna_dri_copy_fallback(sna, draw->bitsPerPixel,
+                                     src_bo, 0, 0,
+                                     dst_bo, 0, 0,
+                                     boxes, n);
+       } else {
+               sna_dri_select_mode(sna, src_bo, false);
+               sna->render.copy_boxes(sna, GXcopy,
+                                      (PixmapPtr)draw, src_bo, 0, 0,
+                                      (PixmapPtr)draw, dst_bo, 0, 0,
+                                      boxes, n, COPY_LAST);
+       }
+
+       if (region == &clip)
+               pixman_region_fini(&clip);
+}
+
+static void
+sna_dri_copy_region(DrawablePtr draw,
+                   RegionPtr region,
+                   DRI2BufferPtr dst_buffer,
+                   DRI2BufferPtr src_buffer)
+{
+       PixmapPtr pixmap = get_drawable_pixmap(draw);
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+       struct kgem_bo *src, *dst;
+       void (*copy)(struct sna *, DrawablePtr, RegionPtr,
+                    struct kgem_bo *, struct kgem_bo *, bool) = sna_dri_copy;
+
+       if (dst_buffer->attachment == DRI2BufferFrontLeft) {
+               dst = sna_pixmap_get_bo(pixmap);
+               copy = (void *)sna_dri_copy_to_front;
+       } else
+               dst = get_private(dst_buffer)->bo;
+
+       if (src_buffer->attachment == DRI2BufferFrontLeft) {
+               src = sna_pixmap_get_bo(pixmap);
+               assert(copy == sna_dri_copy);
+               copy = sna_dri_copy_from_front;
+       } else
+               src = get_private(src_buffer)->bo;
+
+       assert(dst != NULL);
+       assert(src != NULL);
+
+       DBG(("%s: dst -- attachment=%d, name=%d, handle=%d [screen=%d]\n",
+            __FUNCTION__,
+            dst_buffer->attachment, dst_buffer->name, dst->handle,
+            sna_pixmap_get_bo(sna->front)->handle));
+       DBG(("%s: src -- attachment=%d, name=%d, handle=%d\n",
+            __FUNCTION__,
+            src_buffer->attachment, src_buffer->name, src->handle));
+       DBG(("%s: region (%d, %d), (%d, %d) x %d\n",
+            __FUNCTION__,
+            region->extents.x1, region->extents.y1,
+            region->extents.x2, region->extents.y2,
+            REGION_NUM_RECTS(region)));
+
+       copy(sna, draw, region, dst, src, false);
+}
+
+static inline int sna_wait_vblank(struct sna *sna, drmVBlank *vbl)
+{
+       return drmIoctl(sna->kgem.fd, DRM_IOCTL_WAIT_VBLANK, vbl);
+}
+
+#if DRI2INFOREC_VERSION >= 4
+
+static int
+sna_dri_get_pipe(DrawablePtr pDraw)
+{
+       ScrnInfoPtr pScrn = xf86ScreenToScrn(pDraw->pScreen);
+       xf86CrtcPtr crtc;
+       BoxRec box;
+       int pipe;
+
+       if (pDraw->type == DRAWABLE_PIXMAP)
+               return -1;
+
+       box.x1 = pDraw->x;
+       box.y1 = pDraw->y;
+       box.x2 = box.x1 + pDraw->width;
+       box.y2 = box.y1 + pDraw->height;
+
+       crtc = sna_covering_crtc(pScrn, &box, NULL);
+
+       /* Make sure the CRTC is valid and this is the real front buffer */
+       pipe = -1;
+       if (crtc != NULL)
+               pipe = sna_crtc_to_pipe(crtc);
+
+       DBG(("%s(box=((%d, %d), (%d, %d)), pipe=%d)\n",
+            __FUNCTION__, box.x1, box.y1, box.x2, box.y2, pipe));
+
+       return pipe;
+}
+
+static struct sna_dri_frame_event *
+sna_dri_window_get_chain(WindowPtr win)
+{
+       return ((void **)dixGetPrivateAddr(&win->devPrivates, &sna_window_key))[1];
+}
+
+static void
+sna_dri_window_set_chain(WindowPtr win,
+                        struct sna_dri_frame_event *chain)
+{
+       DBG(("%s: head now %p\n", __FUNCTION__, chain));
+       assert(win->drawable.type == DRAWABLE_WINDOW);
+       ((void **)dixGetPrivateAddr(&win->devPrivates, &sna_window_key))[1] = chain;
+}
+
+static void
+sna_dri_remove_frame_event(WindowPtr win,
+                           struct sna_dri_frame_event *info)
+{
+       struct sna_dri_frame_event *chain;
+
+       DBG(("%s: remove[%p] from window %ld)\n",
+            __FUNCTION__, info, (long)win->drawable.id));
+
+       chain = sna_dri_window_get_chain(win);
+       if (chain == NULL)
+               return;
+
+       if (chain == info) {
+               sna_dri_window_set_chain(win, info->chain);
+               return;
+       }
+
+       while (chain->chain != info)
+               chain = chain->chain;
+       assert(chain != info);
+       assert(info->chain != chain);
+       chain->chain = info->chain;
+}
+
+void sna_dri_destroy_window(WindowPtr win)
+{
+       struct sna_dri_frame_event *chain;
+
+       chain = sna_dri_window_get_chain(win);
+       if (chain == NULL)
+               return;
+
+       DBG(("%s: window=%ld\n", __FUNCTION__, win->drawable.serialNumber));
+       while (chain) {
+               chain->draw = NULL;
+               chain = chain->chain;
+       }
+}
+
+static void
+sna_dri_add_frame_event(DrawablePtr draw, struct sna_dri_frame_event *info)
+{
+       struct sna_dri_frame_event *chain;
+
+       if (draw->type != DRAWABLE_WINDOW)
+               return;
+
+       DBG(("%s: add[%p] to window %ld)\n",
+            __FUNCTION__, info, (long)draw->id));
+
+       chain = sna_dri_window_get_chain((WindowPtr)draw);
+       if (chain == NULL) {
+               sna_dri_window_set_chain((WindowPtr)draw, info);
+               return;
+       }
+
+       assert(chain != info);
+       while (chain->chain != NULL)
+               chain = chain->chain;
+
+       assert(chain != info);
+       chain->chain = info;
+}
+
+static void
+sna_dri_frame_event_info_free(struct sna *sna,
+                             DrawablePtr draw,
+                             struct sna_dri_frame_event *info)
+{
+       if (draw && draw->type == DRAWABLE_WINDOW)
+               sna_dri_remove_frame_event((WindowPtr)draw, info);
+       _sna_dri_destroy_buffer(sna, info->front);
+       _sna_dri_destroy_buffer(sna, info->back);
+
+       if (info->old_front.bo)
+               kgem_bo_destroy(&sna->kgem, info->old_front.bo);
+
+       if (info->cache.bo)
+               kgem_bo_destroy(&sna->kgem, info->cache.bo);
+
+       if (info->bo)
+               kgem_bo_destroy(&sna->kgem, info->bo);
+
+       free(info);
+}
+
+static void
+sna_dri_page_flip(struct sna *sna, struct sna_dri_frame_event *info)
+{
+       struct kgem_bo *bo = get_private(info->back)->bo;
+
+       DBG(("%s()\n", __FUNCTION__));
+
+       assert(sna_pixmap_get_buffer(sna->front) == info->front);
+       assert(get_drawable_pixmap(info->draw)->drawable.height * bo->pitch <= kgem_bo_size(bo));
+
+       info->count = sna_page_flip(sna, bo, info, info->pipe);
+
+       info->old_front.name = info->front->name;
+       info->old_front.bo = get_private(info->front)->bo;
+
+       set_bo(sna->front, bo);
+
+       info->front->name = info->back->name;
+       get_private(info->front)->bo = bo;
+}
+
+static bool
+can_flip(struct sna * sna,
+        DrawablePtr draw,
+        DRI2BufferPtr front,
+        DRI2BufferPtr back)
+{
+       WindowPtr win = (WindowPtr)draw;
+       PixmapPtr pixmap;
+
+       if (draw->type == DRAWABLE_PIXMAP)
+               return false;
+
+       if (!sna->scrn->vtSema) {
+               DBG(("%s: no, not attached to VT\n", __FUNCTION__));
+               return false;
+       }
+
+       if (sna->flags & SNA_NO_FLIP) {
+               DBG(("%s: no, pageflips disabled\n", __FUNCTION__));
+               return false;
+       }
+
+       if (front->format != back->format) {
+               DBG(("%s: no, format mismatch, front = %d, back = %d\n",
+                    __FUNCTION__, front->format, back->format));
+               return false;
+       }
+
+       if (front->attachment != DRI2BufferFrontLeft) {
+               DBG(("%s: no, front attachment [%d] is not FrontLeft [%d]\n",
+                    __FUNCTION__,
+                    front->attachment,
+                    DRI2BufferFrontLeft));
+               return false;
+       }
+
+       if (sna->mode.shadow_active) {
+               DBG(("%s: no, shadow enabled\n", __FUNCTION__));
+               return false;
+       }
+
+       pixmap = get_drawable_pixmap(draw);
+       if (pixmap != sna->front) {
+               DBG(("%s: no, window is not on the front buffer\n",
+                    __FUNCTION__));
+               return false;
+       }
+
+       DBG(("%s: window size: %dx%d, clip=(%d, %d), (%d, %d)\n",
+            __FUNCTION__,
+            win->drawable.width, win->drawable.height,
+            win->clipList.extents.x1, win->clipList.extents.y1,
+            win->clipList.extents.x2, win->clipList.extents.y2));
+       if (!RegionEqual(&win->clipList, &draw->pScreen->root->winSize)) {
+               DBG(("%s: no, window is clipped: clip region=(%d, %d), (%d, %d), root size=(%d, %d), (%d, %d)\n",
+                    __FUNCTION__,
+                    win->clipList.extents.x1,
+                    win->clipList.extents.y1,
+                    win->clipList.extents.x2,
+                    win->clipList.extents.y2,
+                    draw->pScreen->root->winSize.extents.x1,
+                    draw->pScreen->root->winSize.extents.y1,
+                    draw->pScreen->root->winSize.extents.x2,
+                    draw->pScreen->root->winSize.extents.y2));
+               return false;
+       }
+
+       if (draw->x != 0 || draw->y != 0 ||
+#ifdef COMPOSITE
+           draw->x != pixmap->screen_x ||
+           draw->y != pixmap->screen_y ||
+#endif
+           draw->width != pixmap->drawable.width ||
+           draw->height != pixmap->drawable.height) {
+               DBG(("%s: no, window is not full size (%dx%d)!=(%dx%d)\n",
+                    __FUNCTION__,
+                    draw->width, draw->height,
+                    pixmap->drawable.width,
+                    pixmap->drawable.height));
+               return false;
+       }
+
+       /* prevent an implicit tiling mode change */
+       if (get_private(front)->bo->tiling != get_private(back)->bo->tiling) {
+               DBG(("%s -- no, tiling mismatch: front %d, back=%d\n",
+                    __FUNCTION__,
+                    get_private(front)->bo->tiling,
+                    get_private(back)->bo->tiling));
+               return false;
+       }
+
+       return true;
+}
+
+static bool
+can_exchange(struct sna * sna,
+            DrawablePtr draw,
+            DRI2BufferPtr front,
+            DRI2BufferPtr back)
+{
+       WindowPtr win = (WindowPtr)draw;
+       PixmapPtr pixmap;
+
+       if (draw->type == DRAWABLE_PIXMAP)
+               return true;
+
+       if (front->format != back->format) {
+               DBG(("%s: no, format mismatch, front = %d, back = %d\n",
+                    __FUNCTION__, front->format, back->format));
+               return false;
+       }
+
+       pixmap = get_window_pixmap(win);
+       if (pixmap == sna->front) {
+               DBG(("%s: no, window is attached to the front buffer\n",
+                    __FUNCTION__));
+               return false;
+       }
+
+       if (pixmap->drawable.width != win->drawable.width ||
+           pixmap->drawable.height != win->drawable.height) {
+               DBG(("%s: no, window has been reparented, window size %dx%d, parent %dx%d\n",
+                    __FUNCTION__,
+                    win->drawable.width,
+                    win->drawable.height,
+                    pixmap->drawable.width,
+                    pixmap->drawable.height));
+               return false;
+       }
+
+       if (sna_pixmap_get_buffer(pixmap) != front) {
+               DBG(("%s: no, DRI2 drawable is no longer attached\n",
+                    __FUNCTION__));
+               return false;
+       }
+
+       return true;
+}
+
+inline static uint32_t pipe_select(int pipe)
+{
+       /* The third pipe was introduced with IvyBridge long after
+        * multiple pipe support was added to the kernel, hence
+        * we can safely ignore the capability check - if we have more
+        * than two pipes, we can assume that they are fully supported.
+        */
+       if (pipe > 1)
+               return pipe << DRM_VBLANK_HIGH_CRTC_SHIFT;
+       else if (pipe > 0)
+               return DRM_VBLANK_SECONDARY;
+       else
+               return 0;
+}
+
+static void
+sna_dri_exchange_buffers(DrawablePtr draw,
+                        DRI2BufferPtr front,
+                        DRI2BufferPtr back)
+{
+       struct kgem_bo *back_bo, *front_bo;
+       PixmapPtr pixmap;
+       int tmp;
+
+       pixmap = get_drawable_pixmap(draw);
+
+       back_bo = get_private(back)->bo;
+       front_bo = get_private(front)->bo;
+
+       DBG(("%s: exchange front=%d/%d and back=%d/%d, pixmap=%ld %dx%d\n",
+            __FUNCTION__,
+            front_bo->handle, front->name,
+            back_bo->handle, back->name,
+            pixmap->drawable.serialNumber,
+            pixmap->drawable.width,
+            pixmap->drawable.height));
+
+       DBG(("%s: back_bo pitch=%d, size=%d\n",
+            __FUNCTION__, back_bo->pitch, kgem_bo_size(back_bo)));
+       DBG(("%s: front_bo pitch=%d, size=%d\n",
+            __FUNCTION__, front_bo->pitch, kgem_bo_size(front_bo)));
+
+       assert(sna_pixmap_get_buffer(pixmap) == front);
+       assert(pixmap->drawable.height * back_bo->pitch <= kgem_bo_size(back_bo));
+       assert(pixmap->drawable.height * front_bo->pitch <= kgem_bo_size(front_bo));
+
+       set_bo(pixmap, back_bo);
+
+       get_private(front)->bo = back_bo;
+       get_private(back)->bo = front_bo;
+
+       tmp = front->name;
+       front->name = back->name;
+       back->name = tmp;
+}
+
+static void chain_swap(struct sna *sna,
+                      DrawablePtr draw,
+                      struct drm_event_vblank *event,
+                      struct sna_dri_frame_event *chain)
+{
+       drmVBlank vbl;
+       int type;
+
+       assert(chain == sna_dri_window_get_chain((WindowPtr)draw));
+       DBG(("%s: chaining type=%d\n", __FUNCTION__, chain->type));
+       switch (chain->type) {
+       case DRI2_XCHG_THROTTLE:
+       case DRI2_SWAP_THROTTLE:
+               break;
+       default:
+               return;
+       }
+
+       if (chain->type == DRI2_XCHG_THROTTLE &&
+           can_exchange(sna, draw, chain->front, chain->back)) {
+               DBG(("%s: performing chained exchange\n", __FUNCTION__));
+               sna_dri_exchange_buffers(draw, chain->front, chain->back);
+               type = DRI2_EXCHANGE_COMPLETE;
+       } else {
+               DBG(("%s: emitting chained vsync'ed blit\n", __FUNCTION__));
+
+               chain->bo = sna_dri_copy_to_front(sna, draw, NULL,
+                                                 get_private(chain->front)->bo,
+                                                 get_private(chain->back)->bo,
+                                                 true);
+
+               type = DRI2_BLIT_COMPLETE;
+       }
+
+       DRI2SwapComplete(chain->client, draw,
+                        event->sequence, event->tv_sec, event->tv_usec,
+                        type, chain->client ? chain->event_complete : NULL, chain->event_data);
+
+       VG_CLEAR(vbl);
+       vbl.request.type =
+               DRM_VBLANK_RELATIVE |
+               DRM_VBLANK_NEXTONMISS |
+               DRM_VBLANK_EVENT |
+               pipe_select(chain->pipe);
+       vbl.request.sequence = 0;
+       vbl.request.signal = (unsigned long)chain;
+       if (sna_wait_vblank(sna, &vbl))
+               sna_dri_frame_event_info_free(sna, draw, chain);
+}
+
+static bool sna_dri_blit_complete(struct sna *sna,
+                                 struct sna_dri_frame_event *info)
+{
+       if (info->bo && __kgem_bo_is_busy(&sna->kgem, info->bo)) {
+               drmVBlank vbl;
+
+               DBG(("%s: vsync'ed blit is still busy, postponing\n",
+                    __FUNCTION__));
+
+               VG_CLEAR(vbl);
+               vbl.request.type =
+                       DRM_VBLANK_RELATIVE |
+                       DRM_VBLANK_EVENT |
+                       pipe_select(info->pipe);
+               vbl.request.sequence = 1;
+               vbl.request.signal = (unsigned long)info;
+               if (!sna_wait_vblank(sna, &vbl))
+                       return false;
+       }
+
+       return true;
+}
+
+void sna_dri_vblank_handler(struct sna *sna, struct drm_event_vblank *event)
+{
+       struct sna_dri_frame_event *info = (void *)(uintptr_t)event->user_data;
+       DrawablePtr draw;
+
+       DBG(("%s(type=%d)\n", __FUNCTION__, info->type));
+
+       draw = info->draw;
+       if (draw == NULL)
+               goto done;
+
+       switch (info->type) {
+       case DRI2_FLIP:
+               /* If we can still flip... */
+               if (can_flip(sna, draw, info->front, info->back)) {
+                       sna_dri_page_flip(sna, info);
+                       info->back->name = info->old_front.name;
+                       get_private(info->back)->bo = info->old_front.bo;
+                       info->old_front.bo = NULL;
+                       return;
+               }
+               /* else fall through to blit */
+       case DRI2_SWAP:
+               info->bo = sna_dri_copy_to_front(sna, draw, NULL,
+                                                get_private(info->front)->bo,
+                                                get_private(info->back)->bo,
+                                                true);
+               info->type = DRI2_SWAP_WAIT;
+               /* fall through to SwapComplete */
+       case DRI2_SWAP_WAIT:
+               if (!sna_dri_blit_complete(sna, info))
+                       return;
+
+               DRI2SwapComplete(info->client,
+                                draw, event->sequence,
+                                event->tv_sec, event->tv_usec,
+                                DRI2_BLIT_COMPLETE,
+                                info->client ? info->event_complete : NULL,
+                                info->event_data);
+               break;
+
+       case DRI2_SWAP_THROTTLE:
+               DBG(("%s: %d complete, frame=%d tv=%d.%06d\n",
+                    __FUNCTION__, info->type,
+                    event->sequence, event->tv_sec, event->tv_usec));
+               break;
+
+       case DRI2_XCHG_THROTTLE:
+               DBG(("%s: xchg throttle\n", __FUNCTION__));
+               break;
+
+       case DRI2_WAITMSC:
+               DRI2WaitMSCComplete(info->client, draw,
+                                   event->sequence,
+                                   event->tv_sec,
+                                   event->tv_usec);
+               break;
+       default:
+               xf86DrvMsg(sna->scrn->scrnIndex, X_WARNING,
+                          "%s: unknown vblank event received\n", __func__);
+               /* Unknown type */
+               break;
+       }
+
+       if (info->chain) {
+               sna_dri_remove_frame_event((WindowPtr)draw, info);
+               chain_swap(sna, draw, event, info->chain);
+               draw = NULL;
+       }
+
+done:
+       sna_dri_frame_event_info_free(sna, draw, info);
+}
+
+static void
+sna_dri_flip_continue(struct sna *sna, struct sna_dri_frame_event *info)
+{
+       struct dri_bo tmp;
+
+       DBG(("%s()\n", __FUNCTION__));
+
+       assert(sna_pixmap_get_buffer(get_drawable_pixmap(info->draw)) == info->front);
+
+       tmp = info->old_front;
+
+       sna_dri_page_flip(sna, info);
+
+       get_private(info->back)->bo = tmp.bo;
+       info->back->name = tmp.name;
+
+       info->next_front.name = 0;
+}
+
+static void sna_dri_flip_event(struct sna *sna,
+                              struct sna_dri_frame_event *flip)
+{
+       DBG(("%s(frame=%d, tv=%d.%06d, type=%d)\n",
+            __FUNCTION__,
+            flip->fe_frame,
+            flip->fe_tv_sec,
+            flip->fe_tv_usec,
+            flip->type));
+
+       if (sna->dri.flip_pending == flip)
+               sna->dri.flip_pending = NULL;
+
+       /* We assume our flips arrive in order, so we don't check the frame */
+       switch (flip->type) {
+       case DRI2_FLIP:
+               DBG(("%s: flip complete (drawable gone? %d)\n",
+                    __FUNCTION__, flip->draw == NULL));
+               if (flip->draw)
+                       DRI2SwapComplete(flip->client, flip->draw,
+                                        flip->fe_frame,
+                                        flip->fe_tv_sec,
+                                        flip->fe_tv_usec,
+                                        DRI2_FLIP_COMPLETE,
+                                        flip->client ? flip->event_complete : NULL,
+                                        flip->event_data);
+
+               sna_dri_frame_event_info_free(sna, flip->draw, flip);
+               break;
+
+       case DRI2_FLIP_THROTTLE:
+               if (!flip->next_front.name) {
+                       DBG(("%s: flip chain complete\n", __FUNCTION__));
+                       sna_dri_frame_event_info_free(sna, flip->draw, flip);
+               } else if (flip->draw &&
+                          can_flip(sna, flip->draw, flip->front, flip->back)) {
+                       sna_dri_flip_continue(sna, flip);
+                       DRI2SwapComplete(flip->client, flip->draw,
+                                        0, 0, 0,
+                                        DRI2_FLIP_COMPLETE,
+                                        flip->client ? flip->event_complete : NULL,
+                                        flip->event_data);
+                       if (flip->count)
+                               sna->dri.flip_pending = flip;
+                       else
+                               sna_dri_frame_event_info_free(sna, flip->draw, flip);
+               } else {
+                       DBG(("%s: no longer able to flip\n", __FUNCTION__));
+
+                       if (flip->draw) {
+                               flip->bo = sna_dri_copy_to_front(sna, flip->draw, NULL,
+                                                                get_private(flip->front)->bo,
+                                                                get_private(flip->back)->bo,
+                                                                false);
+                               DRI2SwapComplete(flip->client, flip->draw,
+                                                0, 0, 0,
+                                                DRI2_BLIT_COMPLETE,
+                                                flip->client ? flip->event_complete : NULL,
+                                                flip->event_data);
+                       }
+
+                       sna_dri_frame_event_info_free(sna, flip->draw, flip);
+               }
+               break;
+
+#if USE_ASYNC_SWAP
+       case DRI2_ASYNC_FLIP:
+               DBG(("%s: async swap flip completed on pipe %d, pending? %d, new? %d\n",
+                    __FUNCTION__, flip->pipe,
+                    sna->dri.flip_pending != NULL,
+                    flip->front->name != flip->old_front.name));
+
+               if (sna->dri.flip_pending)
+                       goto finish_async_flip;
+
+               if (flip->front->name != flip->next_front.name) {
+                       DBG(("%s: async flip continuing\n", __FUNCTION__));
+
+                       flip->cache = flip->old_front;
+                       flip->old_front = flip->next_front;
+
+                       flip->count = sna_page_flip(sna,
+                                                   get_private(flip->front)->bo,
+                                                   flip, flip->pipe);
+                       if (flip->count == 0)
+                               goto finish_async_flip;
+
+                       flip->next_front.bo = get_private(flip->front)->bo;
+                       flip->next_front.name = flip->front->name;
+                       flip->off_delay = 5;
+
+                       sna->dri.flip_pending = flip;
+               } else if (flip->draw && --flip->off_delay) {
+                       DBG(("%s: queuing no-flip [delay=%d]\n",
+                            __FUNCTION__, flip->off_delay));
+                       /* Just queue a no-op flip to trigger another event */
+                       flip->count = sna_page_flip(sna,
+                                                   get_private(flip->front)->bo,
+                                                   flip, flip->pipe);
+                       if (flip->count == 0)
+                               goto finish_async_flip;
+
+                       sna->dri.flip_pending = flip;
+               } else {
+finish_async_flip:
+                       DBG(("%s: async flip completed\n", __FUNCTION__));
+                       sna_dri_frame_event_info_free(sna, flip->draw, flip);
+               }
+               break;
+#endif
+
+       default:
+               xf86DrvMsg(sna->scrn->scrnIndex, X_WARNING,
+                          "%s: unknown vblank event received\n", __func__);
+               /* Unknown type */
+               break;
+       }
+}
+
+void
+sna_dri_page_flip_handler(struct sna *sna,
+                         struct drm_event_vblank *event)
+{
+       struct sna_dri_frame_event *info = to_frame_event(event->user_data);
+
+       DBG(("%s: pending flip_count=%d\n", __FUNCTION__, info->count));
+
+       /* Is this the event whose info shall be delivered to higher level? */
+       if (event->user_data & 1) {
+               info->fe_frame = event->sequence;
+               info->fe_tv_sec = event->tv_sec;
+               info->fe_tv_usec = event->tv_usec;
+       }
+
+       if (--info->count)
+               return;
+
+       sna_dri_flip_event(sna, info);
+}
+
+static bool
+sna_dri_schedule_flip(ClientPtr client, DrawablePtr draw, DRI2BufferPtr front,
+                     DRI2BufferPtr back, CARD64 *target_msc, CARD64 divisor,
+                     CARD64 remainder, DRI2SwapEventPtr func, void *data)
+{
+       struct sna *sna = to_sna_from_drawable(draw);
+       struct sna_dri_frame_event *info;
+       drmVBlank vbl;
+       int pipe;
+       CARD64 current_msc;
+
+       DBG(("%s(target_msc=%llu, divisor=%llu, remainder=%llu)\n",
+            __FUNCTION__,
+            (long long)*target_msc,
+            (long long)divisor,
+            (long long)remainder));
+
+       VG_CLEAR(vbl);
+
+       pipe = sna_dri_get_pipe(draw);
+       if (pipe == -1) {
+               /* XXX WARN_ON(sna->dri.flip_pending) ? */
+               if (sna->dri.flip_pending == NULL) {
+                       sna_dri_exchange_buffers(draw, front, back);
+                       DRI2SwapComplete(client, draw, 0, 0, 0,
+                                       DRI2_EXCHANGE_COMPLETE, func, data);
+                       return true;
+               } else
+                       return false;
+       }
+
+       /* Truncate to match kernel interfaces; means occasional overflow
+        * misses, but that's generally not a big deal */
+       divisor &= 0xffffffff;
+       if (divisor == 0) {
+               int type = DRI2_FLIP_THROTTLE;
+
+               DBG(("%s: performing immediate swap on pipe %d, pending? %d\n",
+                    __FUNCTION__, pipe, sna->dri.flip_pending != NULL));
+
+               info = sna->dri.flip_pending;
+               if (info) {
+                       if (info->draw == draw) {
+                               DBG(("%s: chaining flip\n", __FUNCTION__));
+                               info->next_front.name = 1;
+                               return true;
+                       } else {
+                               /* We need to first wait (one vblank) for the
+                                * async flips to complete before this client
+                                * can take over.
+                                */
+                               DBG(("%s: queueing flip after pending completion\n",
+                                    __FUNCTION__));
+                               type = DRI2_FLIP;
+                       }
+               }
+
+               info = calloc(1, sizeof(struct sna_dri_frame_event));
+               if (info == NULL)
+                       return false;
+
+               info->type = type;
+
+               info->draw = draw;
+               info->client = client;
+               info->event_complete = func;
+               info->event_data = data;
+               info->front = front;
+               info->back = back;
+               info->pipe = pipe;
+
+               sna_dri_add_frame_event(draw, info);
+               sna_dri_reference_buffer(front);
+               sna_dri_reference_buffer(back);
+
+               sna_dri_page_flip(sna, info);
+
+               if (info->count == 0) {
+                       info->back->name = info->old_front.name;
+                       get_private(info->back)->bo = info->old_front.bo;
+                       info->old_front.bo = NULL;
+
+                       DRI2SwapComplete(info->client, draw, 0, 0, 0,
+                                        DRI2_EXCHANGE_COMPLETE,
+                                        info->event_complete,
+                                        info->event_data);
+                       sna_dri_frame_event_info_free(sna, draw, info);
+               } else if (type != DRI2_FLIP) {
+                       get_private(info->back)->bo =
+                               kgem_create_2d(&sna->kgem,
+                                              draw->width,
+                                              draw->height,
+                                              draw->bitsPerPixel,
+                                              get_private(info->front)->bo->tiling,
+                                              CREATE_SCANOUT | CREATE_EXACT);
+                       info->back->name = kgem_bo_flink(&sna->kgem,
+                                                        get_private(info->back)->bo);
+                       sna->dri.flip_pending = info;
+
+                       DRI2SwapComplete(info->client, draw, 0, 0, 0,
+                                        DRI2_EXCHANGE_COMPLETE,
+                                        info->event_complete,
+                                        info->event_data);
+               } else {
+                       info->back->name = info->old_front.name;
+                       get_private(info->back)->bo = info->old_front.bo;
+                       info->old_front.bo = NULL;
+               }
+       } else {
+               info = calloc(1, sizeof(struct sna_dri_frame_event));
+               if (info == NULL)
+                       return false;
+
+               info->draw = draw;
+               info->client = client;
+               info->event_complete = func;
+               info->event_data = data;
+               info->front = front;
+               info->back = back;
+               info->pipe = pipe;
+               info->type = DRI2_FLIP;
+
+               sna_dri_add_frame_event(draw, info);
+               sna_dri_reference_buffer(front);
+               sna_dri_reference_buffer(back);
+
+               /* Get current count */
+               vbl.request.type = DRM_VBLANK_RELATIVE | pipe_select(pipe);
+               vbl.request.sequence = 0;
+               if (sna_wait_vblank(sna, &vbl)) {
+                       sna_dri_frame_event_info_free(sna, draw, info);
+                       return false;
+               }
+
+               current_msc = vbl.reply.sequence;
+               *target_msc &= 0xffffffff;
+               remainder &= 0xffffffff;
+
+               vbl.request.type =
+                       DRM_VBLANK_ABSOLUTE |
+                       DRM_VBLANK_EVENT |
+                       pipe_select(pipe);
+
+               /*
+                * If divisor is zero, or current_msc is smaller than target_msc
+                * we just need to make sure target_msc passes before initiating
+                * the swap.
+                */
+               if (current_msc < *target_msc) {
+                       DBG(("%s: waiting for swap: current=%d, target=%d, divisor=%d\n",
+                            __FUNCTION__,
+                            (int)current_msc,
+                            (int)*target_msc,
+                            (int)divisor));
+                       vbl.request.sequence = *target_msc;
+               } else {
+                       DBG(("%s: missed target, queueing event for next: current=%d, target=%d, divisor=%d\n",
+                            __FUNCTION__,
+                            (int)current_msc,
+                            (int)*target_msc,
+                            (int)divisor));
+
+                       vbl.request.sequence = current_msc - current_msc % divisor + remainder;
+
+                       /*
+                        * If the calculated deadline vbl.request.sequence is
+                        * smaller than or equal to current_msc, it means
+                        * we've passed the last point when effective onset
+                        * frame seq could satisfy *seq % divisor == remainder,
+                        * so we need to wait for the next time this will
+                        * happen.
+                        *
+                        * This comparison takes the 1 frame swap delay
+                        * in pageflipping mode into account.
+                        */
+                       if (vbl.request.sequence <= current_msc)
+                               vbl.request.sequence += divisor;
+
+                       /* Adjust returned value for 1 frame pageflip offset */
+                       *target_msc = vbl.reply.sequence + 1;
+               }
+
+               /* Account for 1 frame extra pageflip delay */
+               vbl.request.sequence -= 1;
+               vbl.request.signal = (unsigned long)info;
+               if (sna_wait_vblank(sna, &vbl)) {
+                       sna_dri_frame_event_info_free(sna, draw, info);
+                       return false;
+               }
+       }
+
+       return true;
+}
+
+static void
+sna_dri_immediate_xchg(struct sna *sna,
+                      DrawablePtr draw,
+                      struct sna_dri_frame_event *info)
+{
+       drmVBlank vbl;
+
+       DBG(("%s: emitting immediate exchange, throttling client\n",
+            __FUNCTION__));
+       VG_CLEAR(vbl);
+
+       if ((sna->flags & SNA_NO_WAIT) == 0) {
+               info->type = DRI2_XCHG_THROTTLE;
+               if (sna_dri_window_get_chain((WindowPtr)draw) == info) {
+                       DBG(("%s: no pending xchg, starting chain\n",
+                            __FUNCTION__));
+
+                       sna_dri_exchange_buffers(draw, info->front, info->back);
+                       DRI2SwapComplete(info->client, draw, 0, 0, 0,
+                                        DRI2_EXCHANGE_COMPLETE,
+                                        info->event_complete,
+                                        info->event_data);
+                       vbl.request.type =
+                               DRM_VBLANK_RELATIVE |
+                               DRM_VBLANK_NEXTONMISS |
+                               DRM_VBLANK_EVENT |
+                               pipe_select(info->pipe);
+                       vbl.request.sequence = 0;
+                       vbl.request.signal = (unsigned long)info;
+                       if (sna_wait_vblank(sna, &vbl))
+                               sna_dri_frame_event_info_free(sna, draw, info);
+               }
+       } else {
+               sna_dri_exchange_buffers(draw, info->front, info->back);
+               DRI2SwapComplete(info->client, draw, 0, 0, 0,
+                                DRI2_EXCHANGE_COMPLETE,
+                                info->event_complete,
+                                info->event_data);
+               sna_dri_frame_event_info_free(sna, draw, info);
+       }
+}
+
+static void
+sna_dri_immediate_blit(struct sna *sna,
+                      DrawablePtr draw,
+                      struct sna_dri_frame_event *info)
+{
+       drmVBlank vbl;
+
+       DBG(("%s: emitting immediate blit, throttling client\n", __FUNCTION__));
+       VG_CLEAR(vbl);
+
+       if ((sna->flags & SNA_NO_WAIT) == 0) {
+               info->type = DRI2_SWAP_THROTTLE;
+               if (sna_dri_window_get_chain((WindowPtr)draw) == info) {
+                       DBG(("%s: no pending blit, starting chain\n",
+                            __FUNCTION__));
+
+                       info->bo = sna_dri_copy_to_front(sna, draw, NULL,
+                                                        get_private(info->front)->bo,
+                                                        get_private(info->back)->bo,
+                                                        true);
+                       DRI2SwapComplete(info->client, draw, 0, 0, 0,
+                                        DRI2_BLIT_COMPLETE,
+                                        info->event_complete,
+                                        info->event_data);
+
+                       vbl.request.type =
+                               DRM_VBLANK_RELATIVE |
+                               DRM_VBLANK_NEXTONMISS |
+                               DRM_VBLANK_EVENT |
+                               pipe_select(info->pipe);
+                       vbl.request.sequence = 0;
+                       vbl.request.signal = (unsigned long)info;
+                       if (sna_wait_vblank(sna, &vbl))
+                               sna_dri_frame_event_info_free(sna, draw, info);
+               }
+       } else {
+               info->bo = sna_dri_copy_to_front(sna, draw, NULL,
+                                                get_private(info->front)->bo,
+                                                get_private(info->back)->bo,
+                                                false);
+               DRI2SwapComplete(info->client, draw, 0, 0, 0,
+                                DRI2_BLIT_COMPLETE,
+                                info->event_complete,
+                                info->event_data);
+               sna_dri_frame_event_info_free(sna, draw, info);
+       }
+}
+
+/*
+ * ScheduleSwap is responsible for requesting a DRM vblank event for the
+ * appropriate frame.
+ *
+ * In the case of a blit (e.g. for a windowed swap) or buffer exchange,
+ * the vblank requested can simply be the last queued swap frame + the swap
+ * interval for the drawable.
+ *
+ * In the case of a page flip, we request an event for the last queued swap
+ * frame + swap interval - 1, since we'll need to queue the flip for the frame
+ * immediately following the received event.
+ *
+ * The client will be blocked if it tries to perform further GL commands
+ * after queueing a swap, though in the Intel case after queueing a flip, the
+ * client is free to queue more commands; they'll block in the kernel if
+ * they access buffers busy with the flip.
+ *
+ * When the swap is complete, the driver should call into the server so it
+ * can send any swap complete events that have been requested.
+ */
+static int
+sna_dri_schedule_swap(ClientPtr client, DrawablePtr draw, DRI2BufferPtr front,
+                     DRI2BufferPtr back, CARD64 *target_msc, CARD64 divisor,
+                     CARD64 remainder, DRI2SwapEventPtr func, void *data)
+{
+       ScreenPtr screen = draw->pScreen;
+       ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+       struct sna *sna = to_sna(scrn);
+       drmVBlank vbl;
+       int pipe;
+       struct sna_dri_frame_event *info = NULL;
+       enum frame_event_type swap_type = DRI2_SWAP;
+       CARD64 current_msc;
+
+       DBG(("%s(target_msc=%llu, divisor=%llu, remainder=%llu)\n",
+            __FUNCTION__,
+            (long long)*target_msc,
+            (long long)divisor,
+            (long long)remainder));
+
+       if (can_flip(sna, draw, front, back)) {
+               DBG(("%s: try flip\n", __FUNCTION__));
+               if (!sna_dri_schedule_flip(client, draw, front, back,
+                                          target_msc, divisor, remainder,
+                                          func, data))
+                       goto blit_fallback;
+
+               return TRUE;
+       }
+
+       /* Drawable not displayed... just complete the swap */
+       pipe = sna_dri_get_pipe(draw);
+       if (pipe == -1) {
+               if (can_exchange(sna, draw, front, back)) {
+                       DBG(("%s: unattached, exchange pixmaps\n", __FUNCTION__));
+                       sna_dri_exchange_buffers(draw, front, back);
+
+                       DRI2SwapComplete(client, draw, 0, 0, 0,
+                                        DRI2_EXCHANGE_COMPLETE, func, data);
+                       return TRUE;
+               }
+
+               DBG(("%s: off-screen, immediate update\n", __FUNCTION__));
+               goto blit_fallback;
+       }
+
+       VG_CLEAR(vbl);
+
+       /* Truncate to match kernel interfaces; means occasional overflow
+        * misses, but that's generally not a big deal */
+       *target_msc &= 0xffffffff;
+       divisor &= 0xffffffff;
+       remainder &= 0xffffffff;
+
+       info = calloc(1, sizeof(struct sna_dri_frame_event));
+       if (!info)
+               goto blit_fallback;
+
+       info->draw = draw;
+       info->client = client;
+       info->event_complete = func;
+       info->event_data = data;
+       info->front = front;
+       info->back = back;
+       info->pipe = pipe;
+
+       sna_dri_add_frame_event(draw, info);
+       sna_dri_reference_buffer(front);
+       sna_dri_reference_buffer(back);
+
+       info->type = swap_type;
+       if (divisor == 0) {
+               if (can_exchange(sna, draw, front, back))
+                       sna_dri_immediate_xchg(sna, draw, info);
+               else
+                       sna_dri_immediate_blit(sna, draw, info);
+               return TRUE;
+       }
+
+       /* Get current count */
+       vbl.request.type = DRM_VBLANK_RELATIVE | pipe_select(pipe);
+       vbl.request.sequence = 0;
+       if (sna_wait_vblank(sna, &vbl))
+               goto blit_fallback;
+
+       current_msc = vbl.reply.sequence;
+
+       /*
+        * If divisor is zero, or current_msc is smaller than target_msc
+        * we just need to make sure target_msc passes before initiating
+        * the swap.
+        */
+       if (current_msc < *target_msc) {
+               DBG(("%s: waiting for swap: current=%d, target=%d, divisor=%d\n",
+                    __FUNCTION__,
+                    (int)current_msc,
+                    (int)*target_msc,
+                    (int)divisor));
+
+               info->type = DRI2_SWAP;
+
+               vbl.request.type =
+                       DRM_VBLANK_ABSOLUTE |
+                       DRM_VBLANK_EVENT |
+                       pipe_select(pipe);
+               vbl.request.sequence = *target_msc;
+               vbl.request.signal = (unsigned long)info;
+               if (sna_wait_vblank(sna, &vbl))
+                       goto blit_fallback;
+
+               return TRUE;
+       }
+
+       /*
+        * If we get here, target_msc has already passed or we don't have one,
+        * and we need to queue an event that will satisfy the divisor/remainder
+        * equation.
+        */
+       DBG(("%s: missed target, queueing event for next: current=%d, target=%d,  divisor=%d\n",
+            __FUNCTION__,
+            (int)current_msc,
+            (int)*target_msc,
+            (int)divisor));
+
+       vbl.request.type =
+               DRM_VBLANK_ABSOLUTE |
+               DRM_VBLANK_EVENT |
+               DRM_VBLANK_NEXTONMISS |
+               pipe_select(pipe);
+
+       vbl.request.sequence = current_msc - current_msc % divisor + remainder;
+       /*
+        * If the calculated deadline vbl.request.sequence is smaller than
+        * or equal to current_msc, it means we've passed the last point
+        * when effective onset frame seq could satisfy
+        * seq % divisor == remainder, so we need to wait for the next time
+        * this will happen.
+        */
+       if (vbl.request.sequence < current_msc)
+               vbl.request.sequence += divisor;
+       vbl.request.sequence -= 1;
+
+       vbl.request.signal = (unsigned long)info;
+       if (sna_wait_vblank(sna, &vbl))
+               goto blit_fallback;
+
+       *target_msc = vbl.reply.sequence;
+       return TRUE;
+
+blit_fallback:
+       if (can_exchange(sna, draw, front, back)) {
+               DBG(("%s -- xchg\n", __FUNCTION__));
+               sna_dri_exchange_buffers(draw, front, back);
+               pipe = DRI2_EXCHANGE_COMPLETE;
+       } else {
+               DBG(("%s -- blit\n", __FUNCTION__));
+               sna_dri_copy_to_front(sna, draw, NULL,
+                                     get_private(front)->bo,
+                                     get_private(back)->bo,
+                                     false);
+               pipe = DRI2_BLIT_COMPLETE;
+       }
+       if (info)
+               sna_dri_frame_event_info_free(sna, draw, info);
+       DRI2SwapComplete(client, draw, 0, 0, 0, pipe, func, data);
+       *target_msc = 0; /* offscreen, so zero out target vblank count */
+       return TRUE;
+}
+
+#if USE_ASYNC_SWAP
+static Bool
+sna_dri_async_swap(ClientPtr client, DrawablePtr draw,
+                  DRI2BufferPtr front, DRI2BufferPtr back,
+                  DRI2SwapEventPtr func, void *data)
+{
+       struct sna *sna = to_sna_from_drawable(draw);
+       struct sna_dri_frame_event *info;
+       struct kgem_bo *bo;
+       int name;
+
+       DBG(("%s()\n", __FUNCTION__));
+
+       if (!can_flip(sna, draw, front, back)) {
+blit:
+               if (can_exchange(sna, draw, front, back)) {
+                       DBG(("%s: unable to flip, so xchg\n", __FUNCTION__));
+                       sna_dri_exchange_buffers(draw, front, back);
+                       name = DRI2_EXCHANGE_COMPLETE;
+               } else {
+                       DBG(("%s: unable to flip, so blit\n", __FUNCTION__));
+                       sna_dri_copy_to_front(sna, draw, NULL,
+                                             get_private(front)->bo,
+                                             get_private(back)->bo,
+                                             false);
+                       name = DRI2_BLIT_COMPLETE;
+               }
+
+               DRI2SwapComplete(client, draw, 0, 0, 0, name, func, data);
+               return name == DRI2_EXCHANGE_COMPLETE;
+       }
+
+       bo = NULL;
+       name = 0;
+
+       info = sna->dri.flip_pending;
+       if (info == NULL) {
+               int pipe = sna_dri_get_pipe(draw);
+               if (pipe == -1)
+                       goto blit;
+
+               DBG(("%s: no pending flip, so updating scanout\n",
+                    __FUNCTION__));
+
+               info = calloc(1, sizeof(struct sna_dri_frame_event));
+               if (!info)
+                       goto blit;
+
+               info->client = client;
+               info->draw = draw;
+               info->type = DRI2_ASYNC_FLIP;
+               info->pipe = pipe;
+               info->front = front;
+               info->back = back;
+
+               sna_dri_add_frame_event(draw, info);
+               sna_dri_reference_buffer(front);
+               sna_dri_reference_buffer(back);
+
+               sna_dri_page_flip(sna, info);
+
+               info->next_front.name = info->front->name;
+               info->next_front.bo = get_private(info->front)->bo;
+               info->off_delay = 5;
+       } else if (info->type != DRI2_ASYNC_FLIP) {
+               /* A normal vsync'ed client is finishing, wait for it
+                * to unpin the old framebuffer before taking over.
+                */
+               goto blit;
+       } else {
+               DBG(("%s: pending flip, chaining next\n", __FUNCTION__));
+               if (info->next_front.name == info->front->name) {
+                       name = info->cache.name;
+                       bo = info->cache.bo;
+               } else {
+                       name = info->front->name;
+                       bo = get_private(info->front)->bo;
+               }
+               info->front->name = info->back->name;
+               get_private(info->front)->bo = get_private(info->back)->bo;
+       }
+
+       if (bo == NULL) {
+               DBG(("%s: creating new back buffer\n", __FUNCTION__));
+               bo = kgem_create_2d(&sna->kgem,
+                                   draw->width,
+                                   draw->height,
+                                   draw->bitsPerPixel,
+                                   get_private(info->front)->bo->tiling,
+                                   CREATE_SCANOUT | CREATE_EXACT);
+               name = kgem_bo_flink(&sna->kgem, bo);
+       }
+       assert(bo->refcnt);
+       get_private(info->back)->bo = bo;
+       info->back->name = name;
+
+       set_bo(sna->front, get_private(info->front)->bo);
+       sna->dri.flip_pending = info;
+
+       DRI2SwapComplete(client, draw, 0, 0, 0,
+                        DRI2_EXCHANGE_COMPLETE, func, data);
+       return TRUE;
+}
+#endif
+
+/*
+ * Get current frame count and frame count timestamp, based on drawable's
+ * crtc.
+ */
+static int
+sna_dri_get_msc(DrawablePtr draw, CARD64 *ust, CARD64 *msc)
+{
+       struct sna *sna = to_sna_from_drawable(draw);
+       drmVBlank vbl;
+       int pipe = sna_dri_get_pipe(draw);
+
+       DBG(("%s(pipe=%d)\n", __FUNCTION__, pipe));
+
+       /* Drawable not displayed, make up a value */
+       if (pipe == -1) {
+               *ust = 0;
+               *msc = 0;
+               return TRUE;
+       }
+
+       VG_CLEAR(vbl);
+       vbl.request.type = DRM_VBLANK_RELATIVE | pipe_select(pipe);
+       vbl.request.sequence = 0;
+       if (sna_wait_vblank(sna, &vbl)) {
+               DBG(("%s: query failed on pipe %d, ret=%d\n",
+                    __FUNCTION__, pipe, errno));
+               return FALSE;
+       }
+
+       *ust = ((CARD64)vbl.reply.tval_sec * 1000000) + vbl.reply.tval_usec;
+       *msc = vbl.reply.sequence;
+       DBG(("%s: msc=%llu, ust=%llu\n", __FUNCTION__,
+            (long long)*msc, (long long)*ust));
+       return TRUE;
+}
+
+/*
+ * Request a DRM event when the requested conditions will be satisfied.
+ *
+ * We need to handle the event and ask the server to wake up the client when
+ * we receive it.
+ */
+static int
+sna_dri_schedule_wait_msc(ClientPtr client, DrawablePtr draw, CARD64 target_msc,
+                         CARD64 divisor, CARD64 remainder)
+{
+       struct sna *sna = to_sna_from_drawable(draw);
+       struct sna_dri_frame_event *info = NULL;
+       int pipe = sna_dri_get_pipe(draw);
+       CARD64 current_msc;
+       drmVBlank vbl;
+
+       DBG(("%s(pipe=%d, target_msc=%llu, divisor=%llu, rem=%llu)\n",
+            __FUNCTION__, pipe,
+            (long long)target_msc,
+            (long long)divisor,
+            (long long)remainder));
+
+       /* Truncate to match kernel interfaces; means occasional overflow
+        * misses, but that's generally not a big deal */
+       target_msc &= 0xffffffff;
+       divisor &= 0xffffffff;
+       remainder &= 0xffffffff;
+
+       /* Drawable not visible, return immediately */
+       if (pipe == -1)
+               goto out_complete;
+
+       VG_CLEAR(vbl);
+
+       /* Get current count */
+       vbl.request.type = DRM_VBLANK_RELATIVE | pipe_select(pipe);
+       vbl.request.sequence = 0;
+       if (sna_wait_vblank(sna, &vbl))
+               goto out_complete;
+
+       current_msc = vbl.reply.sequence;
+
+       /* If target_msc already reached or passed, set it to
+        * current_msc to ensure we return a reasonable value back
+        * to the caller. This keeps the client from continually
+        * sending us MSC targets from the past by forcibly updating
+        * their count on this call.
+        */
+       if (divisor == 0 && current_msc >= target_msc) {
+               target_msc = current_msc;
+               goto out_complete;
+       }
+
+       info = calloc(1, sizeof(struct sna_dri_frame_event));
+       if (!info)
+               goto out_complete;
+
+       info->draw = draw;
+       info->client = client;
+       info->type = DRI2_WAITMSC;
+       sna_dri_add_frame_event(draw, info);
+
+       /*
+        * If divisor is zero, or current_msc is smaller than target_msc,
+        * we just need to make sure target_msc passes before waking up the
+        * client.
+        */
+       if (divisor == 0 || current_msc < target_msc) {
+               vbl.request.type =
+                       DRM_VBLANK_ABSOLUTE |
+                       DRM_VBLANK_EVENT |
+                       pipe_select(pipe);
+               vbl.request.sequence = target_msc;
+               vbl.request.signal = (unsigned long)info;
+               if (sna_wait_vblank(sna, &vbl))
+                       goto out_free_info;
+
+               DRI2BlockClient(client, draw);
+               return TRUE;
+       }
+
+       /*
+        * If we get here, target_msc has already passed or we don't have one,
+        * so we queue an event that will satisfy the divisor/remainder
+        * equation.
+        */
+       vbl.request.type =
+               DRM_VBLANK_ABSOLUTE | DRM_VBLANK_EVENT | pipe_select(pipe);
+
+       vbl.request.sequence = current_msc - current_msc % divisor + remainder;
+
+       /*
+        * If calculated remainder is larger than requested remainder,
+        * it means we've passed the last point where
+        * seq % divisor == remainder, so we need to wait for the next time
+        * that will happen.
+        */
+       if ((current_msc % divisor) >= remainder)
+               vbl.request.sequence += divisor;
+
+       vbl.request.signal = (unsigned long)info;
+       if (sna_wait_vblank(sna, &vbl))
+               goto out_free_info;
+
+       DRI2BlockClient(client, draw);
+       return TRUE;
+
+out_free_info:
+       sna_dri_frame_event_info_free(sna, draw, info);
+out_complete:
+       DRI2WaitMSCComplete(client, draw, target_msc, 0, 0);
+       return TRUE;
+}
+#endif
+
+bool sna_dri_open(struct sna *sna, ScreenPtr screen)
+{
+       DRI2InfoRec info;
+       int major = 1, minor = 0;
+#if DRI2INFOREC_VERSION >= 4
+       const char *driverNames[1];
+#endif
+
+       DBG(("%s()\n", __FUNCTION__));
+
+       if (wedged(sna)) {
+               xf86DrvMsg(sna->scrn->scrnIndex, X_WARNING,
+                          "loading DRI2 whilst the GPU is wedged.\n");
+       }
+
+       if (xf86LoaderCheckSymbol("DRI2Version"))
+               DRI2Version(&major, &minor);
+
+       if (minor < 1) {
+               xf86DrvMsg(sna->scrn->scrnIndex, X_WARNING,
+                          "DRI2 requires DRI2 module version 1.1.0 or later\n");
+               return false;
+       }
+
+       sna->deviceName = drmGetDeviceNameFromFd(sna->kgem.fd);
+       memset(&info, '\0', sizeof(info));
+       info.fd = sna->kgem.fd;
+       info.driverName =
+               (sna->kgem.gen && sna->kgem.gen < 40) ? "i915" : "i965";
+       info.deviceName = sna->deviceName;
+
+       DBG(("%s: loading dri driver '%s' [gen=%d] for device '%s'\n",
+            __FUNCTION__, info.driverName, sna->kgem.gen, info.deviceName));
+
+       info.version = 3;
+       info.CreateBuffer = sna_dri_create_buffer;
+       info.DestroyBuffer = sna_dri_destroy_buffer;
+
+       info.CopyRegion = sna_dri_copy_region;
+#if DRI2INFOREC_VERSION >= 4
+       info.version = 4;
+       info.ScheduleSwap = sna_dri_schedule_swap;
+       info.GetMSC = sna_dri_get_msc;
+       info.ScheduleWaitMSC = sna_dri_schedule_wait_msc;
+       info.numDrivers = 1;
+       info.driverNames = driverNames;
+       driverNames[0] = info.driverName;
+#endif
+
+#if DRI2INFOREC_VERSION >= 6
+       info.version = 6;
+       info.SwapLimitValidate = NULL;
+       info.ReuseBufferNotify = NULL;
+#endif
+
+#if USE_ASYNC_SWAP
+       info.version = 10;
+       info.AsyncSwap = sna_dri_async_swap;
+#endif
+
+       return DRI2ScreenInit(screen, &info);
+}
+
+void sna_dri_close(struct sna *sna, ScreenPtr screen)
+{
+       DBG(("%s()\n", __FUNCTION__));
+       DRI2CloseScreen(screen);
+       drmFree(sna->deviceName);
+}
diff --git a/src/sna/sna_driver.c b/src/sna/sna_driver.c
new file mode 100644 (file)
index 0000000..462d9ac
--- /dev/null
@@ -0,0 +1,1127 @@
+/**************************************************************************
+
+Copyright 2001 VA Linux Systems Inc., Fremont, California.
+Copyright © 2002 by David Dawes
+
+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
+on the rights to use, copy, modify, merge, publish, distribute, sub
+license, 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 NON-INFRINGEMENT. IN NO EVENT SHALL
+THE COPYRIGHT HOLDERS AND/OR THEIR SUPPLIERS 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.
+
+**************************************************************************/
+
+/*
+ * Authors: Jeff Hartmann <jhartmann@valinux.com>
+ *          Abraham van der Merwe <abraham@2d3d.co.za>
+ *          David Dawes <dawes@xfree86.org>
+ *          Alan Hourihane <alanh@tungstengraphics.com>
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <assert.h>
+#include <string.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+
+#include <xf86cmap.h>
+#include <xf86drm.h>
+#include <xf86RandR12.h>
+#include <mi.h>
+#include <micmap.h>
+#include <mipict.h>
+
+#include "compiler.h"
+#include "sna.h"
+#include "sna_module.h"
+#include "sna_video.h"
+
+#include "intel_driver.h"
+#include "intel_options.h"
+
+#include <sys/ioctl.h>
+#include <sys/fcntl.h>
+#include <sys/poll.h>
+#include "i915_drm.h"
+
+#ifdef HAVE_VALGRIND
+#include <valgrind.h>
+#include <memcheck.h>
+#endif
+
+#if HAVE_DOT_GIT
+#include "git_version.h"
+#endif
+
+DevPrivateKeyRec sna_pixmap_key;
+DevPrivateKeyRec sna_gc_key;
+DevPrivateKeyRec sna_window_key;
+DevPrivateKeyRec sna_glyph_key;
+
+static Bool sna_enter_vt(VT_FUNC_ARGS_DECL);
+
+/* temporary */
+extern void xf86SetCursor(ScreenPtr screen, CursorPtr pCurs, int x, int y);
+
+static void
+sna_load_palette(ScrnInfoPtr scrn, int numColors, int *indices,
+                LOCO * colors, VisualPtr pVisual)
+{
+       xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+       int i, j, index;
+       int p;
+       uint16_t lut_r[256], lut_g[256], lut_b[256];
+
+       DBG(("%s\n", __FUNCTION__));
+
+       for (p = 0; p < xf86_config->num_crtc; p++) {
+               xf86CrtcPtr crtc = xf86_config->crtc[p];
+
+               switch (scrn->depth) {
+               case 15:
+                       for (i = 0; i < numColors; i++) {
+                               index = indices[i];
+                               for (j = 0; j < 8; j++) {
+                                       lut_r[index * 8 + j] =
+                                           colors[index].red << 8;
+                                       lut_g[index * 8 + j] =
+                                           colors[index].green << 8;
+                                       lut_b[index * 8 + j] =
+                                           colors[index].blue << 8;
+                               }
+                       }
+                       break;
+               case 16:
+                       for (i = 0; i < numColors; i++) {
+                               index = indices[i];
+
+                               if (index <= 31) {
+                                       for (j = 0; j < 8; j++) {
+                                               lut_r[index * 8 + j] =
+                                                   colors[index].red << 8;
+                                               lut_b[index * 8 + j] =
+                                                   colors[index].blue << 8;
+                                       }
+                               }
+
+                               for (j = 0; j < 4; j++) {
+                                       lut_g[index * 4 + j] =
+                                           colors[index].green << 8;
+                               }
+                       }
+                       break;
+               default:
+                       for (i = 0; i < numColors; i++) {
+                               index = indices[i];
+                               lut_r[index] = colors[index].red << 8;
+                               lut_g[index] = colors[index].green << 8;
+                               lut_b[index] = colors[index].blue << 8;
+                       }
+                       break;
+               }
+
+               /* Make the change through RandR */
+#ifdef RANDR_12_INTERFACE
+               RRCrtcGammaSet(crtc->randr_crtc, lut_r, lut_g, lut_b);
+#else
+               crtc->funcs->gamma_set(crtc, lut_r, lut_g, lut_b, 256);
+#endif
+       }
+}
+
+/**
+ * Adjust the screen pixmap for the current location of the front buffer.
+ * This is done at EnterVT when buffers are bound as long as the resources
+ * have already been created, but the first EnterVT happens before
+ * CreateScreenResources.
+ */
+static Bool sna_create_screen_resources(ScreenPtr screen)
+{
+       ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+       struct sna *sna = to_sna_from_screen(screen);
+
+       DBG(("%s(%dx%d@%d)\n", __FUNCTION__,
+            screen->width, screen->height, screen->rootDepth));
+
+       free(screen->devPrivate);
+       screen->devPrivate = NULL;
+
+       sna_accel_create(sna);
+
+       sna->front = screen->CreatePixmap(screen,
+                                         screen->width,
+                                         screen->height,
+                                         screen->rootDepth,
+                                         SNA_CREATE_FB);
+       if (!sna->front) {
+               xf86DrvMsg(screen->myNum, X_ERROR,
+                          "[intel] Unable to create front buffer %dx%d at depth %d\n",
+                          screen->width,
+                          screen->height,
+                          screen->rootDepth);
+
+               return FALSE;
+       }
+
+       if (!sna_pixmap_force_to_gpu(sna->front, MOVE_WRITE)) {
+               xf86DrvMsg(screen->myNum, X_ERROR,
+                          "[intel] Failed to allocate video resources for front buffer %dx%d at depth %d\n",
+                          screen->width,
+                          screen->height,
+                          screen->rootDepth);
+               goto cleanup_front;
+       }
+
+       screen->SetScreenPixmap(sna->front);
+
+       sna_copy_fbcon(sna);
+
+       if (!sna_enter_vt(VT_FUNC_ARGS(0))) {
+               xf86DrvMsg(screen->myNum, X_ERROR,
+                          "[intel] Failed to become DRM master\n");
+               goto cleanup_front;
+       }
+
+       return TRUE;
+
+cleanup_front:
+       screen->SetScreenPixmap(NULL);
+       screen->DestroyPixmap(sna->front);
+       sna->front = NULL;
+       return FALSE;
+}
+
+static void PreInitCleanup(ScrnInfoPtr scrn)
+{
+       if (!scrn || !scrn->driverPrivate)
+               return;
+
+       free(scrn->driverPrivate);
+       scrn->driverPrivate = NULL;
+}
+
+struct sna_device {
+       int fd;
+       int open_count;
+};
+static int sna_device_key = -1;
+
+static inline struct sna_device *sna_device(ScrnInfoPtr scrn)
+{
+       if (scrn->entityList == NULL)
+               return NULL;
+
+       return xf86GetEntityPrivate(scrn->entityList[0], sna_device_key)->ptr;
+}
+
+static inline void sna_set_device(ScrnInfoPtr scrn, struct sna_device *dev)
+{
+       xf86GetEntityPrivate(scrn->entityList[0], sna_device_key)->ptr = dev;
+}
+
+static int sna_open_drm_master(ScrnInfoPtr scrn)
+{
+       struct sna_device *dev;
+       struct sna *sna = to_sna(scrn);
+       struct pci_device *pci = sna->PciInfo;
+       drmSetVersion sv;
+       int err;
+       char busid[20];
+       int fd;
+
+       DBG(("%s\n", __FUNCTION__));
+
+       dev = sna_device(scrn);
+       if (dev) {
+               dev->open_count++;
+               DBG(("%s: reusing device, count=%d\n",
+                    __FUNCTION__, dev->open_count));
+               return dev->fd;
+       }
+
+       snprintf(busid, sizeof(busid), "pci:%04x:%02x:%02x.%d",
+                pci->domain, pci->bus, pci->dev, pci->func);
+
+       DBG(("%s: opening device '%s'\n",  __FUNCTION__, busid));
+       fd = drmOpen(NULL, busid);
+       if (fd == -1) {
+               xf86DrvMsg(scrn->scrnIndex, X_ERROR,
+                          "[drm] Failed to open DRM device for %s: %s\n",
+                          busid, strerror(errno));
+               return -1;
+       }
+
+       /* Check that what we opened was a master or a master-capable FD,
+        * by setting the version of the interface we'll use to talk to it.
+        * (see DRIOpenDRMMaster() in DRI1)
+        */
+       sv.drm_di_major = 1;
+       sv.drm_di_minor = 1;
+       sv.drm_dd_major = -1;
+       sv.drm_dd_minor = -1;
+       err = drmSetInterfaceVersion(fd, &sv);
+       if (err != 0) {
+               xf86DrvMsg(scrn->scrnIndex, X_ERROR,
+                          "[drm] failed to set drm interface version: %s [%d].\n",
+                          strerror(-err), -err);
+               drmClose(fd);
+               return -1;
+       }
+
+       dev = malloc(sizeof(*dev));
+       if (dev) {
+               int flags;
+
+               /* make the fd nonblocking to handle event loops */
+               flags = fcntl(fd, F_GETFL, 0);
+               if (flags != -1)
+                       (void)fcntl(fd, F_SETFL, flags | O_NONBLOCK);
+
+               dev->fd = fd;
+               dev->open_count = 1;
+               sna_set_device(scrn, dev);
+       }
+
+       return fd;
+}
+
+static void sna_close_drm_master(ScrnInfoPtr scrn)
+{
+       struct sna_device *dev = sna_device(scrn);
+
+       if (dev == NULL)
+               return;
+
+       DBG(("%s(open_count=%d)\n", __FUNCTION__, dev->open_count));
+       if (--dev->open_count)
+               return;
+
+       drmClose(dev->fd);
+       sna_set_device(scrn, NULL);
+       free(dev);
+}
+
+static void sna_selftest(void)
+{
+       sna_damage_selftest();
+}
+
+static bool has_pageflipping(struct sna *sna)
+{
+       drm_i915_getparam_t gp;
+       int v;
+
+       if (sna->flags & SNA_NO_WAIT)
+               return false;
+
+       v = 0;
+
+       VG_CLEAR(gp);
+       gp.param = I915_PARAM_HAS_PAGEFLIPPING;
+       gp.value = &v;
+
+       if (drmIoctl(sna->kgem.fd, DRM_IOCTL_I915_GETPARAM, &gp))
+               return false;
+
+       VG(VALGRIND_MAKE_MEM_DEFINED(&v, sizeof(v)));
+       return v > 0;
+}
+
+static void sna_setup_capabilities(ScrnInfoPtr scrn, int fd)
+{
+#if HAS_PIXMAP_SHARING && defined(DRM_CAP_PRIME)
+       uint64_t value;
+
+       scrn->capabilities = 0;
+       if (drmGetCap(fd, DRM_CAP_PRIME, &value) == 0) {
+               if (value & DRM_PRIME_CAP_EXPORT)
+                       scrn->capabilities |= RR_Capability_SourceOutput | RR_Capability_SinkOffload;
+               if (value & DRM_PRIME_CAP_IMPORT)
+                       scrn->capabilities |= RR_Capability_SinkOutput;
+       }
+#endif
+}
+
+/**
+ * This is called before ScreenInit to do any require probing of screen
+ * configuration.
+ *
+ * This code generally covers probing, module loading, option handling
+ * card mapping, and RandR setup.
+ *
+ * Since xf86InitialConfiguration ends up requiring that we set video modes
+ * in order to detect configuration, we end up having to do a lot of driver
+ * setup (talking to the DRM, mapping the device, etc.) in this function.
+ * As a result, we want to set up that server initialization once rather
+ * that doing it per generation.
+ */
+static Bool sna_pre_init(ScrnInfoPtr scrn, int flags)
+{
+       struct sna *sna;
+       rgb defaultWeight = { 0, 0, 0 };
+       EntityInfoPtr pEnt;
+       int flags24;
+       Gamma zeros = { 0.0, 0.0, 0.0 };
+       int fd;
+
+       DBG(("%s flags=%x, numEntities=%d\n",
+            __FUNCTION__, flags, scrn->numEntities));
+
+       if (scrn->numEntities != 1)
+               return FALSE;
+
+       pEnt = xf86GetEntityInfo(scrn->entityList[0]);
+       if (pEnt == NULL)
+               return FALSE;
+
+       if (pEnt->location.type != BUS_PCI
+#ifdef XSERVER_PLATFORM_BUS
+           && pEnt->location.type != BUS_PLATFORM
+#endif
+               )
+               return FALSE;
+
+       if (flags & PROBE_DETECT)
+               return TRUE;
+
+       sna_selftest();
+
+       if (((uintptr_t)scrn->driverPrivate) & 1) {
+               sna = xnfcalloc(sizeof(struct sna), 1);
+               if (sna == NULL)
+                       return FALSE;
+
+               sna->info = (void *)((uintptr_t)scrn->driverPrivate & ~1);
+               scrn->driverPrivate = sna;
+       }
+       sna = to_sna(scrn);
+       sna->scrn = scrn;
+       sna->pEnt = pEnt;
+
+       scrn->displayWidth = 640;       /* default it */
+
+       sna->PciInfo = xf86GetPciInfoForEntity(sna->pEnt->index);
+
+       fd = sna_open_drm_master(scrn);
+       if (fd == -1) {
+               xf86DrvMsg(scrn->scrnIndex, X_ERROR,
+                          "Failed to become DRM master.\n");
+               return FALSE;
+       }
+
+       scrn->monitor = scrn->confScreen->monitor;
+       scrn->progClock = TRUE;
+       scrn->rgbBits = 8;
+
+       flags24 = Support32bppFb | PreferConvert24to32 | SupportConvert24to32;
+
+       if (!xf86SetDepthBpp(scrn, 0, 0, 0, flags24))
+               return FALSE;
+
+       switch (scrn->depth) {
+       case 8:
+       case 15:
+       case 16:
+       case 24:
+       case 30:
+               break;
+       default:
+               xf86DrvMsg(scrn->scrnIndex, X_ERROR,
+                          "Given depth (%d) is not supported by Intel driver\n",
+                          scrn->depth);
+               return FALSE;
+       }
+       xf86PrintDepthBpp(scrn);
+
+       if (!xf86SetWeight(scrn, defaultWeight, defaultWeight))
+               return FALSE;
+       if (!xf86SetDefaultVisual(scrn, -1))
+               return FALSE;
+
+       sna->Options = intel_options_get(scrn);
+       if (sna->Options == NULL)
+               return FALSE;
+
+       sna_setup_capabilities(scrn, fd);
+
+       intel_detect_chipset(scrn, sna->pEnt, sna->PciInfo);
+
+       kgem_init(&sna->kgem, fd, sna->PciInfo, sna->info->gen);
+       if (xf86ReturnOptValBool(sna->Options, OPTION_ACCEL_DISABLE, FALSE)) {
+               xf86DrvMsg(sna->scrn->scrnIndex, X_CONFIG,
+                          "Disabling hardware acceleration.\n");
+               sna->kgem.wedged = true;
+       }
+
+       if (!xf86ReturnOptValBool(sna->Options,
+                                 OPTION_RELAXED_FENCING,
+                                 sna->kgem.has_relaxed_fencing)) {
+               xf86DrvMsg(scrn->scrnIndex,
+                          sna->kgem.has_relaxed_fencing ? X_CONFIG : X_PROBED,
+                          "Disabling use of relaxed fencing\n");
+               sna->kgem.has_relaxed_fencing = 0;
+       }
+
+       /* Enable tiling by default */
+       sna->tiling = SNA_TILING_ALL;
+
+       /* Allow user override if they set a value */
+       if (!xf86ReturnOptValBool(sna->Options, OPTION_TILING_2D, TRUE))
+               sna->tiling &= ~SNA_TILING_2D;
+       if (xf86ReturnOptValBool(sna->Options, OPTION_TILING_FB, FALSE))
+               sna->tiling &= ~SNA_TILING_FB;
+
+       sna->flags = 0;
+       if (!xf86ReturnOptValBool(sna->Options, OPTION_THROTTLE, TRUE))
+               sna->flags |= SNA_NO_THROTTLE;
+       if (!xf86ReturnOptValBool(sna->Options, OPTION_DELAYED_FLUSH, TRUE))
+               sna->flags |= SNA_NO_DELAYED_FLUSH;
+       if (!xf86ReturnOptValBool(sna->Options, OPTION_SWAPBUFFERS_WAIT, TRUE))
+               sna->flags |= SNA_NO_WAIT;
+       if (has_pageflipping(sna)) {
+               if (xf86ReturnOptValBool(sna->Options, OPTION_TEAR_FREE, FALSE))
+                       sna->flags |= SNA_TEAR_FREE;
+       } else
+               sna->flags |= SNA_NO_FLIP;
+       if (xf86ReturnOptValBool(sna->Options, OPTION_CRTC_PIXMAPS, FALSE))
+               sna->flags |= SNA_FORCE_SHADOW;
+
+       xf86DrvMsg(scrn->scrnIndex, X_CONFIG, "Framebuffer %s\n",
+                  sna->tiling & SNA_TILING_FB ? "tiled" : "linear");
+       xf86DrvMsg(scrn->scrnIndex, X_CONFIG, "Pixmaps %s\n",
+                  sna->tiling & SNA_TILING_2D ? "tiled" : "linear");
+       xf86DrvMsg(scrn->scrnIndex, X_CONFIG, "3D buffers %s\n",
+                  sna->tiling & SNA_TILING_3D ? "tiled" : "linear");
+       xf86DrvMsg(scrn->scrnIndex, X_CONFIG, "Throttling %sabled\n",
+                  sna->flags & SNA_NO_THROTTLE ? "dis" : "en");
+       xf86DrvMsg(scrn->scrnIndex, X_CONFIG, "Delayed flush %sabled\n",
+                  sna->flags & SNA_NO_DELAYED_FLUSH ? "dis" : "en");
+       xf86DrvMsg(scrn->scrnIndex, X_CONFIG, "\"Tear free\" %sabled\n",
+                  sna->flags & SNA_TEAR_FREE ? "en" : "dis");
+       xf86DrvMsg(scrn->scrnIndex, X_CONFIG, "Forcing per-crtc-pixmaps? %s\n",
+                  sna->flags & SNA_FORCE_SHADOW ? "yes" : "no");
+
+       if (!sna_mode_pre_init(scrn, sna)) {
+               PreInitCleanup(scrn);
+               return FALSE;
+       }
+
+       if (!xf86SetGamma(scrn, zeros)) {
+               PreInitCleanup(scrn);
+               return FALSE;
+       }
+
+       if (scrn->modes == NULL) {
+               xf86DrvMsg(scrn->scrnIndex, X_ERROR, "No modes.\n");
+               PreInitCleanup(scrn);
+               return FALSE;
+       }
+       scrn->currentMode = scrn->modes;
+
+       /* Set display resolution */
+       xf86SetDpi(scrn, 0, 0);
+
+       sna->dri_available = false;
+       if (xf86ReturnOptValBool(sna->Options, OPTION_DRI, TRUE))
+               sna->dri_available = !!xf86LoadSubModule(scrn, "dri2");
+
+       return TRUE;
+}
+
+static void
+sna_block_handler(BLOCKHANDLER_ARGS_DECL)
+{
+       SCREEN_PTR(arg);
+       ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+       struct sna *sna = to_sna(scrn);
+       struct timeval **tv = timeout;
+
+       DBG(("%s (tv=%ld.%06ld)\n", __FUNCTION__,
+            *tv ? (*tv)->tv_sec : -1, *tv ? (*tv)->tv_usec : 0));
+
+       sna->BlockHandler(BLOCKHANDLER_ARGS);
+
+       if (*tv == NULL || ((*tv)->tv_usec | (*tv)->tv_sec))
+               sna_accel_block_handler(sna, tv);
+}
+
+static void
+sna_wakeup_handler(WAKEUPHANDLER_ARGS_DECL)
+{
+       SCREEN_PTR(arg);
+       ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+       struct sna *sna = to_sna(scrn);
+
+       DBG(("%s\n", __FUNCTION__));
+
+       /* despite all appearances, result is just a signed int */
+       if ((int)result < 0)
+               return;
+
+       sna->WakeupHandler(WAKEUPHANDLER_ARGS);
+
+       sna_accel_wakeup_handler(sna);
+
+       if (FD_ISSET(sna->kgem.fd, (fd_set*)read_mask))
+               sna_mode_wakeup(sna);
+}
+
+#if HAVE_UDEV
+static void
+sna_handle_uevents(int fd, void *closure)
+{
+       ScrnInfoPtr scrn = closure;
+       struct sna *sna = to_sna(scrn);
+       struct udev_device *dev;
+       const char *hotplug;
+       struct stat s;
+       dev_t udev_devnum;
+
+       DBG(("%s\n", __FUNCTION__));
+
+       dev = udev_monitor_receive_device(sna->uevent_monitor);
+       if (!dev)
+               return;
+
+       udev_devnum = udev_device_get_devnum(dev);
+       if (fstat(sna->kgem.fd, &s)) {
+               udev_device_unref(dev);
+               return;
+       }
+
+       /*
+        * Check to make sure this event is directed at our
+        * device (by comparing dev_t values), then make
+        * sure it's a hotplug event (HOTPLUG=1)
+        */
+
+       hotplug = udev_device_get_property_value(dev, "HOTPLUG");
+
+       if (memcmp(&s.st_rdev, &udev_devnum, sizeof (dev_t)) == 0 &&
+           hotplug && atoi(hotplug) == 1) {
+               DBG(("%s: hotplug event\n", __FUNCTION__));
+               sna_mode_update(sna);
+               RRGetInfo(xf86ScrnToScreen(scrn), TRUE);
+       }
+
+       udev_device_unref(dev);
+}
+
+static void
+sna_uevent_init(ScrnInfoPtr scrn)
+{
+       struct sna *sna = to_sna(scrn);
+       struct udev *u;
+       struct udev_monitor *mon;
+       Bool hotplug;
+       MessageType from = X_CONFIG;
+
+       DBG(("%s\n", __FUNCTION__));
+
+       if (!xf86GetOptValBool(sna->Options, OPTION_HOTPLUG, &hotplug)) {
+               from = X_DEFAULT;
+               hotplug = TRUE;
+       }
+
+       xf86DrvMsg(scrn->scrnIndex, from, "hotplug detection: \"%s\"\n",
+                       hotplug ? "enabled" : "disabled");
+       if (!hotplug)
+               return;
+
+       u = udev_new();
+       if (!u)
+               return;
+
+       mon = udev_monitor_new_from_netlink(u, "udev");
+
+       if (!mon) {
+               udev_unref(u);
+               return;
+       }
+
+       if (udev_monitor_filter_add_match_subsystem_devtype(mon,
+                               "drm",
+                               "drm_minor") < 0 ||
+                       udev_monitor_enable_receiving(mon) < 0)
+       {
+               udev_monitor_unref(mon);
+               udev_unref(u);
+               return;
+       }
+
+       sna->uevent_handler =
+               xf86AddGeneralHandler(udev_monitor_get_fd(mon),
+                                     sna_handle_uevents,
+                                     scrn);
+       if (!sna->uevent_handler) {
+               udev_monitor_unref(mon);
+               udev_unref(u);
+               return;
+       }
+
+       sna->uevent_monitor = mon;
+}
+
+static void
+sna_uevent_fini(ScrnInfoPtr scrn)
+{
+       struct sna *sna = to_sna(scrn);
+
+       if (sna->uevent_handler) {
+               struct udev *u = udev_monitor_get_udev(sna->uevent_monitor);
+
+               xf86RemoveGeneralHandler(sna->uevent_handler);
+
+               udev_monitor_unref(sna->uevent_monitor);
+               udev_unref(u);
+               sna->uevent_handler = NULL;
+               sna->uevent_monitor = NULL;
+       }
+}
+#else
+static void sna_uevent_fini(ScrnInfoPtr scrn) { }
+#endif /* HAVE_UDEV */
+
+static void sna_leave_vt(VT_FUNC_ARGS_DECL)
+{
+       SCRN_INFO_PTR(arg);
+       struct sna *sna = to_sna(scrn);
+
+       DBG(("%s\n", __FUNCTION__));
+
+       xf86_hide_cursors(scrn);
+
+       if (drmDropMaster(sna->kgem.fd))
+               xf86DrvMsg(scrn->scrnIndex, X_WARNING,
+                          "drmDropMaster failed: %s\n", strerror(errno));
+}
+
+/* In order to workaround a kernel bug in not honouring O_NONBLOCK,
+ * check that the fd is readable before attempting to read the next
+ * event from drm.
+ */
+static Bool sna_mode_has_pending_events(struct sna *sna)
+{
+       struct pollfd pfd;
+       pfd.fd = sna->kgem.fd;
+       pfd.events = POLLIN;
+       return poll(&pfd, 1, 0) == 1;
+}
+
+static Bool sna_early_close_screen(CLOSE_SCREEN_ARGS_DECL)
+{
+       ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+       struct sna *sna = to_sna(scrn);
+
+       DBG(("%s\n", __FUNCTION__));
+
+       sna_uevent_fini(scrn);
+
+       /* drain the event queues */
+       if (sna_mode_has_pending_events(sna))
+               sna_mode_wakeup(sna);
+
+       if (sna->dri_open) {
+               sna_dri_close(sna, screen);
+               sna->dri_open = false;
+       }
+
+       xf86_hide_cursors(scrn);
+       scrn->vtSema = FALSE;
+
+       xf86_cursors_fini(screen);
+
+       return TRUE;
+}
+
+static Bool sna_late_close_screen(CLOSE_SCREEN_ARGS_DECL)
+{
+       ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+       struct sna *sna = to_sna(scrn);
+       DepthPtr depths;
+       int d;
+
+       DBG(("%s\n", __FUNCTION__));
+
+       if (sna->front) {
+               screen->DestroyPixmap(sna->front);
+               sna->front = NULL;
+       }
+
+       sna_accel_close(sna);
+       drmDropMaster(sna->kgem.fd);
+
+       depths = screen->allowedDepths;
+       for (d = 0; d < screen->numDepths; d++)
+               free(depths[d].vids);
+       free(depths);
+
+       free(screen->visuals);
+
+       return TRUE;
+}
+
+static void sna_mode_set(ScrnInfoPtr scrn)
+{
+       struct sna *sna = to_sna(scrn);
+
+       DBG(("%s\n", __FUNCTION__));
+       sna_mode_update(sna);
+}
+
+static Bool
+sna_register_all_privates(void)
+{
+       if (!dixRegisterPrivateKey(&sna_pixmap_key, PRIVATE_PIXMAP,
+                                  3*sizeof(void *)))
+               return FALSE;
+
+       if (!dixRegisterPrivateKey(&sna_gc_key, PRIVATE_GC,
+                                  sizeof(FbGCPrivate)))
+               return FALSE;
+
+       if (!dixRegisterPrivateKey(&sna_glyph_key, PRIVATE_GLYPH,
+                                  sizeof(struct sna_glyph)))
+               return FALSE;
+
+       if (!dixRegisterPrivateKey(&sna_window_key, PRIVATE_WINDOW,
+                                  2*sizeof(void *)))
+               return FALSE;
+
+       return TRUE;
+}
+
+static size_t
+agp_aperture_size(struct pci_device *dev, int gen)
+{
+       return dev->regions[gen < 30 ? 0 : 2].size;
+}
+
+static Bool
+sna_screen_init(SCREEN_INIT_ARGS_DECL)
+{
+       ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+       struct sna *sna = to_sna(scrn);
+       VisualPtr visuals;
+       DepthPtr depths;
+       int nvisuals;
+       int ndepths;
+       int rootdepth;
+       VisualID defaultVisual;
+
+       DBG(("%s\n", __FUNCTION__));
+
+       if (!sna_register_all_privates())
+               return FALSE;
+
+       scrn->videoRam = agp_aperture_size(sna->PciInfo, sna->kgem.gen) / 1024;
+
+       miClearVisualTypes();
+       if (!miSetVisualTypes(scrn->depth,
+                             miGetDefaultVisualMask(scrn->depth),
+                             scrn->rgbBits, scrn->defaultVisual))
+               return FALSE;
+       if (!miSetPixmapDepths())
+               return FALSE;
+
+       rootdepth = 0;
+       if (!miInitVisuals(&visuals, &depths, &nvisuals, &ndepths, &rootdepth,
+                          &defaultVisual,
+                          ((unsigned long)1 << (scrn->bitsPerPixel - 1)),
+                          8, -1))
+               return FALSE;
+
+       if (!miScreenInit(screen, NULL,
+                         scrn->virtualX, scrn->virtualY,
+                         scrn->xDpi, scrn->yDpi, 0,
+                         rootdepth, ndepths, depths,
+                         defaultVisual, nvisuals, visuals))
+               return FALSE;
+
+       if (scrn->bitsPerPixel > 8) {
+               /* Fixup RGB ordering */
+               VisualPtr visual = screen->visuals + screen->numVisuals;
+               while (--visual >= screen->visuals) {
+                       if ((visual->class | DynamicClass) == DirectColor) {
+                               visual->offsetRed = scrn->offset.red;
+                               visual->offsetGreen = scrn->offset.green;
+                               visual->offsetBlue = scrn->offset.blue;
+                               visual->redMask = scrn->mask.red;
+                               visual->greenMask = scrn->mask.green;
+                               visual->blueMask = scrn->mask.blue;
+                       }
+               }
+       }
+
+       assert(screen->CloseScreen == NULL);
+       screen->CloseScreen = sna_late_close_screen;
+       if (!sna_accel_init(screen, sna)) {
+               xf86DrvMsg(scrn->scrnIndex, X_ERROR,
+                          "Hardware acceleration initialization failed\n");
+               return FALSE;
+       }
+
+       xf86SetBlackWhitePixels(screen);
+
+       xf86SetBackingStore(screen);
+       xf86SetSilkenMouse(screen);
+       if (!miDCInitialize(screen, xf86GetPointerScreenFuncs()))
+               return FALSE;
+
+       if (xf86_cursors_init(screen, SNA_CURSOR_X, SNA_CURSOR_Y,
+                              HARDWARE_CURSOR_TRUECOLOR_AT_8BPP |
+                              HARDWARE_CURSOR_BIT_ORDER_MSBFIRST |
+                              HARDWARE_CURSOR_INVERT_MASK |
+                              HARDWARE_CURSOR_SWAP_SOURCE_AND_MASK |
+                              HARDWARE_CURSOR_AND_SOURCE_WITH_MASK |
+                              HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_64 |
+                              HARDWARE_CURSOR_UPDATE_UNHIDDEN |
+                              HARDWARE_CURSOR_ARGB))
+               xf86DrvMsg(scrn->scrnIndex, X_INFO, "HW Cursor enabled\n");
+
+       /* Must force it before EnterVT, so we are in control of VT and
+        * later memory should be bound when allocating, e.g rotate_mem */
+       scrn->vtSema = TRUE;
+
+       sna->BlockHandler = screen->BlockHandler;
+       screen->BlockHandler = sna_block_handler;
+
+       sna->WakeupHandler = screen->WakeupHandler;
+       screen->WakeupHandler = sna_wakeup_handler;
+
+       screen->SaveScreen = xf86SaveScreen;
+       screen->CreateScreenResources = sna_create_screen_resources;
+
+       sna->CloseScreen = screen->CloseScreen;
+       screen->CloseScreen = sna_early_close_screen;
+
+       if (!xf86CrtcScreenInit(screen))
+               return FALSE;
+
+       xf86RandR12SetRotations(screen,
+                               RR_Rotate_0 | RR_Rotate_90 | RR_Rotate_180 | RR_Rotate_270 |
+                               RR_Reflect_X | RR_Reflect_Y);
+       xf86RandR12SetTransformSupport(screen, TRUE);
+
+       if (!miCreateDefColormap(screen))
+               return FALSE;
+
+       if (!xf86HandleColormaps(screen, 256, 8, sna_load_palette, NULL,
+                                CMAP_RELOAD_ON_MODE_SWITCH |
+                                CMAP_PALETTED_TRUECOLOR)) {
+               return FALSE;
+       }
+
+       xf86DPMSInit(screen, xf86DPMSSet, 0);
+
+       sna_video_init(sna, screen);
+       if (sna->dri_available)
+               sna->dri_open = sna_dri_open(sna, screen);
+       if (sna->dri_open)
+               xf86DrvMsg(scrn->scrnIndex, X_INFO,
+                          "direct rendering: DRI2 Enabled\n");
+
+       if (serverGeneration == 1)
+               xf86ShowUnusedOptions(scrn->scrnIndex, scrn->options);
+
+       sna->suspended = FALSE;
+
+#if HAVE_UDEV
+       sna_uevent_init(scrn);
+#endif
+
+       return TRUE;
+}
+
+static void sna_adjust_frame(ADJUST_FRAME_ARGS_DECL)
+{
+       SCRN_INFO_PTR(arg);
+       DBG(("%s(%d, %d)\n", __FUNCTION__, x, y));
+       sna_mode_adjust_frame(to_sna(scrn), x, y);
+}
+
+static void sna_free_screen(FREE_SCREEN_ARGS_DECL)
+{
+       SCRN_INFO_PTR(arg);
+       struct sna *sna = to_sna(scrn);
+
+       DBG(("%s\n", __FUNCTION__));
+
+       if (sna && ((intptr_t)sna & 1) == 0) {
+               sna_mode_fini(sna);
+               free(sna);
+       }
+       scrn->driverPrivate = NULL;
+
+       sna_close_drm_master(scrn);
+}
+
+/*
+ * This gets called when gaining control of the VT, and from ScreenInit().
+ */
+static Bool sna_enter_vt(VT_FUNC_ARGS_DECL)
+{
+       SCRN_INFO_PTR(arg);
+       struct sna *sna = to_sna(scrn);
+
+       DBG(("%s\n", __FUNCTION__));
+
+       if (drmSetMaster(sna->kgem.fd)) {
+               xf86DrvMsg(scrn->scrnIndex, X_ERROR,
+                          "drmSetMaster failed: %s\n",
+                          strerror(errno));
+               return FALSE;
+       }
+
+       if (!xf86SetDesiredModes(scrn))
+               xf86DrvMsg(scrn->scrnIndex, X_WARNING,
+                          "failed to restore desired modes on VT switch\n");
+
+       sna_mode_disable_unused(sna);
+
+       return TRUE;
+}
+
+static Bool sna_switch_mode(SWITCH_MODE_ARGS_DECL)
+{
+       SCRN_INFO_PTR(arg);
+       DBG(("%s\n", __FUNCTION__));
+       return xf86SetSingleMode(scrn, mode, RR_Rotate_0);
+}
+
+static ModeStatus
+sna_valid_mode(SCRN_ARG_TYPE arg, DisplayModePtr mode, Bool verbose, int flags)
+{
+       return MODE_OK;
+}
+
+#ifndef SUSPEND_SLEEP
+#define SUSPEND_SLEEP 0
+#endif
+#ifndef RESUME_SLEEP
+#define RESUME_SLEEP 0
+#endif
+
+/*
+ * This function is only required if we need to do anything differently from
+ * DoApmEvent() in common/xf86PM.c, including if we want to see events other
+ * than suspend/resume.
+ */
+static Bool sna_pm_event(SCRN_ARG_TYPE arg, pmEvent event, Bool undo)
+{
+       SCRN_INFO_PTR(arg);
+       struct sna *sna = to_sna(scrn);
+
+       DBG(("%s\n", __FUNCTION__));
+
+       switch (event) {
+       case XF86_APM_SYS_SUSPEND:
+       case XF86_APM_CRITICAL_SUSPEND: /*do we want to delay a critical suspend? */
+       case XF86_APM_USER_SUSPEND:
+       case XF86_APM_SYS_STANDBY:
+       case XF86_APM_USER_STANDBY:
+               if (!undo && !sna->suspended) {
+                       scrn->LeaveVT(VT_FUNC_ARGS(0));
+                       sna->suspended = TRUE;
+                       sleep(SUSPEND_SLEEP);
+               } else if (undo && sna->suspended) {
+                       sleep(RESUME_SLEEP);
+                       scrn->EnterVT(VT_FUNC_ARGS(0));
+                       sna->suspended = FALSE;
+               }
+               break;
+       case XF86_APM_STANDBY_RESUME:
+       case XF86_APM_NORMAL_RESUME:
+       case XF86_APM_CRITICAL_RESUME:
+               if (sna->suspended) {
+                       sleep(RESUME_SLEEP);
+                       scrn->EnterVT(VT_FUNC_ARGS(0));
+                       sna->suspended = FALSE;
+                       /*
+                        * Turn the screen saver off when resuming.  This seems to be
+                        * needed to stop xscreensaver kicking in (when used).
+                        *
+                        * XXX DoApmEvent() should probably call this just like
+                        * xf86VTSwitch() does.  Maybe do it here only in 4.2
+                        * compatibility mode.
+                        */
+                       SaveScreens(SCREEN_SAVER_FORCER, ScreenSaverReset);
+               }
+               break;
+               /* This is currently used for ACPI */
+       case XF86_APM_CAPABILITY_CHANGED:
+               SaveScreens(SCREEN_SAVER_FORCER, ScreenSaverReset);
+               break;
+
+       default:
+               ErrorF("sna_pm_event: received APM event %d\n", event);
+       }
+       return TRUE;
+}
+
+Bool sna_init_scrn(ScrnInfoPtr scrn, int entity_num)
+{
+       DBG(("%s: entity_num=%d\n", __FUNCTION__, entity_num));
+#if defined(USE_GIT_DESCRIBE)
+       xf86DrvMsg(scrn->scrnIndex, X_INFO,
+                  "SNA compiled from %s\n", git_version);
+#elif defined(BUILDER_DESCRIPTION)
+       xf86DrvMsg(scrn->scrnIndex, X_INFO,
+                  "SNA compiled: %s\n", BUILDER_DESCRIPTION);
+#endif
+#if !NDEBUG
+       xf86DrvMsg(scrn->scrnIndex, X_INFO,
+                  "SNA compiled with assertions enabled\n");
+#endif
+#if DEBUG_MEMORY
+       xf86DrvMsg(scrn->scrnIndex, X_INFO,
+                  "SNA compiled with memory allocation reporting enabled\n");
+#endif
+#if DEBUG_PIXMAP
+       xf86DrvMsg(scrn->scrnIndex, X_INFO,
+                  "SNA compiled with extra pixmap/damage validation\n");
+#endif
+       DBG(("pixman version: %s\n", pixman_version_string()));
+
+       if (sna_device_key == -1)
+               sna_device_key = xf86AllocateEntityPrivateIndex();
+
+       scrn->PreInit = sna_pre_init;
+       scrn->ScreenInit = sna_screen_init;
+       scrn->SwitchMode = sna_switch_mode;
+       scrn->AdjustFrame = sna_adjust_frame;
+       scrn->EnterVT = sna_enter_vt;
+       scrn->LeaveVT = sna_leave_vt;
+       scrn->FreeScreen = sna_free_screen;
+       scrn->ValidMode = sna_valid_mode;
+       scrn->PMEvent = sna_pm_event;
+
+       scrn->ModeSet = sna_mode_set;
+
+       xf86SetEntitySharable(entity_num);
+       xf86SetEntityInstanceForScreen(scrn, entity_num,
+                                      xf86GetNumEntityInstances(entity_num)-1);
+
+       return TRUE;
+}
diff --git a/src/sna/sna_glyphs.c b/src/sna/sna_glyphs.c
new file mode 100644 (file)
index 0000000..53494e3
--- /dev/null
@@ -0,0 +1,2025 @@
+/*
+ * Copyright © 2010 Intel Corporation
+ * Partly based on code Copyright © 2008 Red Hat, Inc.
+ * Partly based on code Copyright © 2000 SuSE, Inc.
+ *
+ * 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 Intel not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  Intel makes no representations about the
+ * suitability of this software for any purpose.  It is provided "as is"
+ * without express or implied warranty.
+ *
+ * INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL INTEL
+ * 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.
+ *
+ * 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 Red Hat not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  Red Hat makes no representations about the
+ * suitability of this software for any purpose.  It is provided "as is"
+ * without express or implied warranty.
+ *
+ * Red Hat DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL Red Hat
+ * 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.
+ *
+ * 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 SuSE not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  SuSE makes no representations about the
+ * suitability of this software for any purpose.  It is provided "as is"
+ * without express or implied warranty.
+ *
+ * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE
+ * 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.
+ *
+ * Author: Chris Wilson <chris@chris-wilson.co.uk>
+ * Based on code by: Keith Packard <keithp@keithp.com> and Owen Taylor <otaylor@fishsoup.net>
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "sna.h"
+#include "sna_render.h"
+#include "sna_render_inline.h"
+#include "fb/fbpict.h"
+
+#include <mipict.h>
+
+#define FALLBACK 0
+#define NO_GLYPH_CACHE 0
+#define NO_GLYPHS_TO_DST 0
+#define NO_GLYPHS_VIA_MASK 0
+#define NO_SMALL_MASK 0
+#define NO_GLYPHS_SLOW 0
+#define NO_DISCARD_MASK 0
+
+#define CACHE_PICTURE_SIZE 1024
+#define GLYPH_MIN_SIZE 8
+#define GLYPH_MAX_SIZE 64
+#define GLYPH_CACHE_SIZE (CACHE_PICTURE_SIZE * CACHE_PICTURE_SIZE / (GLYPH_MIN_SIZE * GLYPH_MIN_SIZE))
+
+#define N_STACK_GLYPHS 512
+
+#if HAS_DEBUG_FULL
+static void _assert_pixmap_contains_box(PixmapPtr pixmap, BoxPtr box, const char *function)
+{
+       if (box->x1 < 0 || box->y1 < 0 ||
+           box->x2 > pixmap->drawable.width ||
+           box->y2 > pixmap->drawable.height)
+       {
+               ErrorF("%s: damage box is beyond the pixmap: box=(%d, %d), (%d, %d), pixmap=(%d, %d)\n",
+                      __FUNCTION__,
+                      box->x1, box->y1, box->x2, box->y2,
+                      pixmap->drawable.width,
+                      pixmap->drawable.height);
+               assert(0);
+       }
+}
+#define assert_pixmap_contains_box(p, b) _assert_pixmap_contains_box(p, b, __FUNCTION__)
+#else
+#define assert_pixmap_contains_box(p, b)
+#endif
+
+extern DevPrivateKeyRec sna_glyph_key;
+
+static inline struct sna_glyph *sna_glyph(GlyphPtr glyph)
+{
+       return dixGetPrivateAddr(&glyph->devPrivates, &sna_glyph_key);
+}
+
+#define NeedsComponent(f) (PICT_FORMAT_A(f) != 0 && PICT_FORMAT_RGB(f) != 0)
+
+static bool op_is_bounded(uint8_t op)
+{
+       switch (op) {
+       case PictOpOver:
+       case PictOpOutReverse:
+       case PictOpAdd:
+       case PictOpXor:
+               return true;
+       default:
+               return false;
+       }
+}
+
+void sna_glyphs_close(struct sna *sna)
+{
+       struct sna_render *render = &sna->render;
+       unsigned int i;
+
+       DBG(("%s\n", __FUNCTION__));
+
+       for (i = 0; i < ARRAY_SIZE(render->glyph); i++) {
+               struct sna_glyph_cache *cache = &render->glyph[i];
+
+               if (cache->picture)
+                       FreePicture(cache->picture, 0);
+
+               free(cache->glyphs);
+       }
+       memset(render->glyph, 0, sizeof(render->glyph));
+
+       if (render->white_image) {
+               pixman_image_unref(render->white_image);
+               render->white_image = NULL;
+       }
+       if (render->white_picture) {
+               FreePicture(render->white_picture, 0);
+               render->white_picture = NULL;
+       }
+#if HAS_PIXMAN_GLYPHS
+       if (render->glyph_cache) {
+               pixman_glyph_cache_destroy(render->glyph_cache);
+               render->glyph_cache = NULL;
+       }
+#endif
+}
+
+/* All caches for a single format share a single pixmap for glyph storage,
+ * allowing mixing glyphs of different sizes without paying a penalty
+ * for switching between source pixmaps. (Note that for a size of font
+ * right at the border between two sizes, we might be switching for almost
+ * every glyph.)
+ *
+ * This function allocates the storage pixmap, and then fills in the
+ * rest of the allocated structures for all caches with the given format.
+ */
+bool sna_glyphs_create(struct sna *sna)
+{
+       ScreenPtr screen = sna->scrn->pScreen;
+       pixman_color_t white = { 0xffff, 0xffff, 0xffff, 0xffff };
+       unsigned int formats[] = {
+               PIXMAN_a8,
+               PIXMAN_a8r8g8b8,
+       };
+       unsigned int i;
+       int error;
+
+       DBG(("%s\n", __FUNCTION__));
+
+#if HAS_PIXMAN_GLYPHS
+       sna->render.glyph_cache = pixman_glyph_cache_create();
+       if (sna->render.glyph_cache == NULL)
+               goto bail;
+#endif
+
+       sna->render.white_image = pixman_image_create_solid_fill(&white);
+       if (sna->render.white_image == NULL)
+               goto bail;
+
+       if (!can_render(sna))
+               return true;
+
+       if (xf86IsEntityShared(sna->scrn->entityList[0]))
+               return true;
+
+       for (i = 0; i < ARRAY_SIZE(formats); i++) {
+               struct sna_glyph_cache *cache = &sna->render.glyph[i];
+               struct sna_pixmap *priv;
+               PixmapPtr pixmap;
+               PicturePtr picture = NULL;
+               PictFormatPtr pPictFormat;
+               CARD32 component_alpha;
+               int depth = PIXMAN_FORMAT_DEPTH(formats[i]);
+
+               pPictFormat = PictureMatchFormat(screen, depth, formats[i]);
+               if (!pPictFormat)
+                       goto bail;
+
+               /* Now allocate the pixmap and picture */
+               pixmap = screen->CreatePixmap(screen,
+                                             CACHE_PICTURE_SIZE,
+                                             CACHE_PICTURE_SIZE,
+                                             depth,
+                                             SNA_CREATE_SCRATCH);
+               if (!pixmap)
+                       goto bail;
+
+               priv = sna_pixmap(pixmap);
+               if (priv != NULL) {
+                       /* Prevent the cache from ever being paged out */
+                       priv->pinned = PIN_SCANOUT;
+
+                       component_alpha = NeedsComponent(pPictFormat->format);
+                       picture = CreatePicture(0, &pixmap->drawable, pPictFormat,
+                                               CPComponentAlpha, &component_alpha,
+                                               serverClient, &error);
+               }
+
+               screen->DestroyPixmap(pixmap);
+               if (!picture)
+                       goto bail;
+
+               ValidatePicture(picture);
+
+               cache->count = cache->evict = 0;
+               cache->picture = picture;
+               cache->glyphs = calloc(sizeof(struct sna_glyph *),
+                                      GLYPH_CACHE_SIZE);
+               if (!cache->glyphs)
+                       goto bail;
+
+               cache->evict = rand() % GLYPH_CACHE_SIZE;
+       }
+
+       sna->render.white_picture =
+               CreateSolidPicture(0, (xRenderColor *)&white, &error);
+       if (sna->render.white_picture == NULL)
+               goto bail;
+
+       return true;
+
+bail:
+       sna_glyphs_close(sna);
+       return false;
+}
+
+static void
+glyph_cache_upload(struct sna_glyph_cache *cache,
+                  GlyphPtr glyph, PicturePtr glyph_picture,
+                  int16_t x, int16_t y)
+{
+       DBG(("%s: upload glyph %p to cache (%d, %d)x(%d, %d)\n",
+            __FUNCTION__,
+            glyph, x, y,
+            glyph_picture->pDrawable->width,
+            glyph_picture->pDrawable->height));
+       sna_composite(PictOpSrc,
+                     glyph_picture, 0, cache->picture,
+                     0, 0,
+                     0, 0,
+                     x, y,
+                     glyph_picture->pDrawable->width,
+                     glyph_picture->pDrawable->height);
+}
+
+static void
+glyph_extents(int nlist,
+             GlyphListPtr list,
+             GlyphPtr *glyphs,
+             BoxPtr extents)
+{
+       int16_t x1, x2, y1, y2;
+       int16_t x, y;
+
+       x1 = y1 = MAXSHORT;
+       x2 = y2 = MINSHORT;
+       x = y = 0;
+       while (nlist--) {
+               int n = list->len;
+               x += list->xOff;
+               y += list->yOff;
+               list++;
+               while (n--) {
+                       GlyphPtr glyph = *glyphs++;
+
+                       if (glyph->info.width && glyph->info.height) {
+                               int v;
+
+                               v = x - glyph->info.x;
+                               if (v < x1)
+                                       x1 = v;
+                               v += glyph->info.width;
+                               if (v > x2)
+                                       x2 = v;
+
+                               v = y - glyph->info.y;
+                               if (v < y1)
+                                       y1 = v;
+                               v += glyph->info.height;
+                               if (v > y2)
+                                       y2 = v;
+                       }
+
+                       x += glyph->info.xOff;
+                       y += glyph->info.yOff;
+               }
+       }
+
+       extents->x1 = x1;
+       extents->x2 = x2;
+       extents->y1 = y1;
+       extents->y2 = y2;
+}
+
+static inline unsigned int
+glyph_size_to_count(int size)
+{
+       size /= GLYPH_MIN_SIZE;
+       return size * size;
+}
+
+static inline unsigned int
+glyph_count_to_mask(int count)
+{
+       return ~(count - 1);
+}
+
+static inline unsigned int
+glyph_size_to_mask(int size)
+{
+       return glyph_count_to_mask(glyph_size_to_count(size));
+}
+
+static int
+glyph_cache(ScreenPtr screen,
+           struct sna_render *render,
+           GlyphPtr glyph)
+{
+       PicturePtr glyph_picture = GetGlyphPicture(glyph, screen);
+       struct sna_glyph_cache *cache = &render->glyph[PICT_FORMAT_RGB(glyph_picture->format) != 0];
+       struct sna_glyph *priv;
+       int size, mask, pos, s;
+
+       if (NO_GLYPH_CACHE)
+               return false;
+
+       if (glyph->info.width > GLYPH_MAX_SIZE ||
+           glyph->info.height > GLYPH_MAX_SIZE) {
+               PixmapPtr pixmap = (PixmapPtr)glyph_picture->pDrawable;
+               assert(glyph_picture->pDrawable->type == DRAWABLE_PIXMAP);
+               if (pixmap->drawable.depth >= 8) {
+                       pixmap->usage_hint = 0;
+                       sna_pixmap_force_to_gpu(pixmap, MOVE_READ);
+               }
+               return false;
+       }
+
+       for (size = GLYPH_MIN_SIZE; size <= GLYPH_MAX_SIZE; size *= 2)
+               if (glyph->info.width <= size && glyph->info.height <= size)
+                       break;
+
+       s = glyph_size_to_count(size);
+       mask = glyph_count_to_mask(s);
+       pos = (cache->count + s - 1) & mask;
+       if (pos < GLYPH_CACHE_SIZE) {
+               cache->count = pos + s;
+       } else {
+               priv = NULL;
+               for (s = size; s <= GLYPH_MAX_SIZE; s *= 2) {
+                       int i = cache->evict & glyph_size_to_mask(s);
+                       priv = cache->glyphs[i];
+                       if (priv == NULL)
+                               continue;
+
+                       if (priv->size >= s) {
+                               cache->glyphs[i] = NULL;
+                               priv->atlas = NULL;
+                               pos = i;
+                       } else
+                               priv = NULL;
+                       break;
+               }
+               if (priv == NULL) {
+                       int count = glyph_size_to_count(size);
+                       pos = cache->evict & glyph_count_to_mask(count);
+                       for (s = 0; s < count; s++) {
+                               priv = cache->glyphs[pos + s];
+                               if (priv != NULL) {
+                                       priv->atlas =NULL;
+                                       cache->glyphs[pos + s] = NULL;
+                               }
+                       }
+               }
+
+               /* And pick a new eviction position */
+               cache->evict = rand() % GLYPH_CACHE_SIZE;
+       }
+       assert(cache->glyphs[pos] == NULL);
+
+       priv = sna_glyph(glyph);
+       DBG(("%s(%d): adding glyph to cache %d, pos %d\n",
+            __FUNCTION__, screen->myNum,
+            PICT_FORMAT_RGB(glyph_picture->format) != 0, pos));
+       cache->glyphs[pos] = priv;
+       priv->atlas = cache->picture;
+       priv->size = size;
+       priv->pos = pos << 1 | (PICT_FORMAT_RGB(glyph_picture->format) != 0);
+       s = pos / ((GLYPH_MAX_SIZE / GLYPH_MIN_SIZE) * (GLYPH_MAX_SIZE / GLYPH_MIN_SIZE));
+       priv->coordinate.x = s % (CACHE_PICTURE_SIZE / GLYPH_MAX_SIZE) * GLYPH_MAX_SIZE;
+       priv->coordinate.y = (s / (CACHE_PICTURE_SIZE / GLYPH_MAX_SIZE)) * GLYPH_MAX_SIZE;
+       for (s = GLYPH_MIN_SIZE; s < GLYPH_MAX_SIZE; s *= 2) {
+               if (pos & 1)
+                       priv->coordinate.x += s;
+               if (pos & 2)
+                       priv->coordinate.y += s;
+               pos >>= 2;
+       }
+
+       glyph_cache_upload(cache, glyph, glyph_picture,
+                          priv->coordinate.x, priv->coordinate.y);
+
+       return true;
+}
+
+static void apply_damage(struct sna_composite_op *op,
+                        const struct sna_composite_rectangles *r)
+{
+       BoxRec box;
+
+       if (op->damage == NULL)
+               return;
+
+       box.x1 = r->dst.x + op->dst.x;
+       box.y1 = r->dst.y + op->dst.y;
+       box.x2 = box.x1 + r->width;
+       box.y2 = box.y1 + r->height;
+
+       assert_pixmap_contains_box(op->dst.pixmap, &box);
+       sna_damage_add_box(op->damage, &box);
+}
+
+static void apply_damage_clipped_to_dst(struct sna_composite_op *op,
+                                       const struct sna_composite_rectangles *r,
+                                       DrawablePtr dst)
+{
+       BoxRec box;
+
+       if (op->damage == NULL)
+               return;
+
+       box.x1 = r->dst.x + op->dst.x;
+       box.y1 = r->dst.y + op->dst.y;
+       box.x2 = box.x1 + r->width;
+       box.y2 = box.y1 + r->height;
+
+       if (box.x1 < dst->x)
+               box.x1 = dst->x;
+
+       if (box.x2 > op->dst.width)
+               box.x2 = op->dst.width;
+
+       if (box.y1 < dst->y)
+               box.y1 = dst->y;
+
+       if (box.y2 > op->dst.height)
+               box.y2 = op->dst.height;
+
+       assert_pixmap_contains_box(op->dst.pixmap, &box);
+       sna_damage_add_box(op->damage, &box);
+}
+
+static bool
+glyphs_to_dst(struct sna *sna,
+             CARD8 op,
+             PicturePtr src,
+             PicturePtr dst,
+             INT16 src_x, INT16 src_y,
+             int nlist, GlyphListPtr list, GlyphPtr *glyphs)
+{
+       struct sna_composite_op tmp;
+       ScreenPtr screen = dst->pDrawable->pScreen;
+       PicturePtr glyph_atlas;
+       BoxPtr rects;
+       int nrect;
+       int16_t x, y;
+
+       if (NO_GLYPHS_TO_DST)
+               return false;
+
+       memset(&tmp, 0, sizeof(tmp));
+
+       DBG(("%s(op=%d, src=(%d, %d), nlist=%d,  dst=(%d, %d)+(%d, %d))\n",
+            __FUNCTION__, op, src_x, src_y, nlist,
+            list->xOff, list->yOff, dst->pDrawable->x, dst->pDrawable->y));
+
+       if (is_clipped(dst->pCompositeClip, dst->pDrawable)) {
+               rects = REGION_RECTS(dst->pCompositeClip);
+               nrect = REGION_NUM_RECTS(dst->pCompositeClip);
+       } else
+               nrect = 0;
+
+       x = dst->pDrawable->x;
+       y = dst->pDrawable->y;
+       src_x -= list->xOff + x;
+       src_y -= list->yOff + y;
+
+       glyph_atlas = NULL;
+       while (nlist--) {
+               int n = list->len;
+               x += list->xOff;
+               y += list->yOff;
+               while (n--) {
+                       GlyphPtr glyph = *glyphs++;
+                       struct sna_glyph priv;
+                       int i;
+
+                       if (glyph->info.width == 0 || glyph->info.height == 0)
+                               goto next_glyph;
+
+                       priv = *sna_glyph(glyph);
+                       if (priv.atlas == NULL) {
+                               if (glyph_atlas) {
+                                       tmp.done(sna, &tmp);
+                                       glyph_atlas = NULL;
+                               }
+                               if (!glyph_cache(screen, &sna->render, glyph)) {
+                                       /* no cache for this glyph */
+                                       priv.atlas = GetGlyphPicture(glyph, screen);
+                                       priv.coordinate.x = priv.coordinate.y = 0;
+                               } else
+                                       priv = *sna_glyph(glyph);
+                       }
+
+                       if (priv.atlas != glyph_atlas) {
+                               if (glyph_atlas)
+                                       tmp.done(sna, &tmp);
+
+                               if (!sna->render.composite(sna,
+                                                          op, src, priv.atlas, dst,
+                                                          0, 0, 0, 0, 0, 0,
+                                                          0, 0,
+                                                          &tmp))
+                                       return false;
+
+                               glyph_atlas = priv.atlas;
+                       }
+
+                       if (nrect) {
+                               for (i = 0; i < nrect; i++) {
+                                       struct sna_composite_rectangles r;
+                                       int16_t dx, dy;
+                                       int16_t x2, y2;
+
+                                       r.dst.x = x - glyph->info.x;
+                                       r.dst.y = y - glyph->info.y;
+                                       x2 = r.dst.x + glyph->info.width;
+                                       y2 = r.dst.y + glyph->info.height;
+                                       dx = dy = 0;
+
+                                       DBG(("%s: glyph=(%d, %d), (%d, %d), clip=(%d, %d), (%d, %d)\n",
+                                            __FUNCTION__,
+                                            r.dst.x, r.dst.y, x2, y2,
+                                            rects[i].x1, rects[i].y1,
+                                            rects[i].x2, rects[i].y2));
+                                       if (rects[i].y1 >= y2)
+                                               break;
+
+                                       if (r.dst.x < rects[i].x1)
+                                               dx = rects[i].x1 - r.dst.x, r.dst.x = rects[i].x1;
+                                       if (x2 > rects[i].x2)
+                                               x2 = rects[i].x2;
+                                       if (r.dst.y < rects[i].y1)
+                                               dy = rects[i].y1 - r.dst.y, r.dst.y = rects[i].y1;
+                                       if (y2 > rects[i].y2)
+                                               y2 = rects[i].y2;
+
+                                       if (r.dst.x < x2 && r.dst.y < y2) {
+                                               DBG(("%s: blt=(%d, %d), (%d, %d)\n",
+                                                    __FUNCTION__, r.dst.x, r.dst.y, x2, y2));
+
+                                               r.src.x = r.dst.x + src_x;
+                                               r.src.y = r.dst.y + src_y;
+                                               r.mask.x = dx + priv.coordinate.x;
+                                               r.mask.y = dy + priv.coordinate.y;
+                                               r.width  = x2 - r.dst.x;
+                                               r.height = y2 - r.dst.y;
+                                               tmp.blt(sna, &tmp, &r);
+                                               apply_damage(&tmp, &r);
+                                       }
+                               }
+                       } else {
+                               struct sna_composite_rectangles r;
+
+                               r.dst.x = x - glyph->info.x;
+                               r.dst.y = y - glyph->info.y;
+                               r.src.x = r.dst.x + src_x;
+                               r.src.y = r.dst.y + src_y;
+                               r.mask.x = priv.coordinate.x;
+                               r.mask.y = priv.coordinate.y;
+                               r.width  = glyph->info.width;
+                               r.height = glyph->info.height;
+
+                               DBG(("%s: glyph=(%d, %d)x(%d, %d), unclipped\n",
+                                    __FUNCTION__,
+                                    r.dst.x, r.dst.y,
+                                    r.width, r.height));
+
+                               tmp.blt(sna, &tmp, &r);
+                               apply_damage_clipped_to_dst(&tmp, &r, dst->pDrawable);
+                       }
+
+next_glyph:
+                       x += glyph->info.xOff;
+                       y += glyph->info.yOff;
+               }
+               list++;
+       }
+       if (glyph_atlas)
+               tmp.done(sna, &tmp);
+
+       return true;
+}
+
+static bool
+glyphs_slow(struct sna *sna,
+           CARD8 op,
+           PicturePtr src,
+           PicturePtr dst,
+           INT16 src_x, INT16 src_y,
+           int nlist, GlyphListPtr list, GlyphPtr *glyphs)
+{
+       struct sna_composite_op tmp;
+       ScreenPtr screen = dst->pDrawable->pScreen;
+       int16_t x, y;
+
+       if (NO_GLYPHS_SLOW)
+               return false;
+
+       memset(&tmp, 0, sizeof(tmp));
+
+       DBG(("%s(op=%d, src=(%d, %d), nlist=%d,  dst=(%d, %d)+(%d, %d))\n",
+            __FUNCTION__, op, src_x, src_y, nlist,
+            list->xOff, list->yOff, dst->pDrawable->x, dst->pDrawable->y));
+
+       x = dst->pDrawable->x;
+       y = dst->pDrawable->y;
+       src_x -= list->xOff + x;
+       src_y -= list->yOff + y;
+
+       while (nlist--) {
+               int n = list->len;
+               x += list->xOff;
+               y += list->yOff;
+               while (n--) {
+                       GlyphPtr glyph = *glyphs++;
+                       struct sna_glyph priv;
+                       BoxPtr rects;
+                       int nrect;
+
+                       if (glyph->info.width == 0 || glyph->info.height == 0)
+                               goto next_glyph;
+
+                       priv = *sna_glyph(glyph);
+                       if (priv.atlas == NULL) {
+                               if (!glyph_cache(screen, &sna->render, glyph)) {
+                                       /* no cache for this glyph */
+                                       priv.atlas = GetGlyphPicture(glyph, screen);
+                                       priv.coordinate.x = priv.coordinate.y = 0;
+                               } else
+                                       priv = *sna_glyph(glyph);
+                       }
+
+                       DBG(("%s: glyph=(%d, %d)x(%d, %d), src=(%d, %d), mask=(%d, %d)\n",
+                            __FUNCTION__,
+                            x - glyph->info.x,
+                            y - glyph->info.y,
+                            glyph->info.width,
+                            glyph->info.height,
+                            src_x + x - glyph->info.x,
+                            src_y + y - glyph->info.y,
+                            priv.coordinate.x, priv.coordinate.y));
+
+                       if (!sna->render.composite(sna,
+                                                  op, src, priv.atlas, dst,
+                                                  src_x + x - glyph->info.x,
+                                                  src_y + y - glyph->info.y,
+                                                  priv.coordinate.x, priv.coordinate.y,
+                                                  x - glyph->info.x,
+                                                  y - glyph->info.y,
+                                                  glyph->info.width,
+                                                  glyph->info.height,
+                                                  &tmp))
+                               return false;
+
+                       rects = REGION_RECTS(dst->pCompositeClip);
+                       nrect = REGION_NUM_RECTS(dst->pCompositeClip);
+                       do {
+                               struct sna_composite_rectangles r;
+                               int16_t x2, y2;
+
+                               r.dst.x = x - glyph->info.x;
+                               r.dst.y = y - glyph->info.y;
+                               x2 = r.dst.x + glyph->info.width;
+                               y2 = r.dst.y + glyph->info.height;
+
+                               DBG(("%s: glyph=(%d, %d), (%d, %d), clip=(%d, %d), (%d, %d)\n",
+                                    __FUNCTION__,
+                                    r.dst.x, r.dst.y, x2, y2,
+                                    rects->x1, rects->y1,
+                                    rects->x2, rects->y2));
+                               if (rects->y1 >= y2)
+                                       break;
+
+                               if (r.dst.x < rects->x1)
+                                       r.dst.x = rects->x1;
+                               if (x2 > rects->x2)
+                                       x2 = rects->x2;
+
+                               if (r.dst.y < rects->y1)
+                                       r.dst.y = rects->y1;
+                               if (y2 > rects->y2)
+                                       y2 = rects->y2;
+
+                               if (r.dst.x < x2 && r.dst.y < y2) {
+                                       DBG(("%s: blt=(%d, %d), (%d, %d)\n",
+                                            __FUNCTION__, r.dst.x, r.dst.y, x2, y2));
+                                       r.width  = x2 - r.dst.x;
+                                       r.height = y2 - r.dst.y;
+                                       r.src = r.mask = r .dst;
+                                       tmp.blt(sna, &tmp, &r);
+                                       apply_damage(&tmp, &r);
+                               }
+                               rects++;
+                       } while (--nrect);
+                       tmp.done(sna, &tmp);
+
+next_glyph:
+                       x += glyph->info.xOff;
+                       y += glyph->info.yOff;
+               }
+               list++;
+       }
+
+       return true;
+}
+
+static bool
+clear_pixmap(struct sna *sna, PixmapPtr pixmap)
+{
+       struct sna_pixmap *priv = sna_pixmap(pixmap);
+       return sna->render.clear(sna, pixmap, priv->gpu_bo);
+}
+
+static bool
+too_large(struct sna *sna, int width, int height)
+{
+       return (width > sna->render.max_3d_size ||
+               height > sna->render.max_3d_size);
+}
+
+static pixman_image_t *
+__sna_glyph_get_image(GlyphPtr g, ScreenPtr s)
+{
+       pixman_image_t *image;
+       PicturePtr p;
+       int dx, dy;
+
+       p = GetGlyphPicture(g, s);
+       if (p == NULL)
+               return NULL;
+
+       image = image_from_pict(p, FALSE, &dx, &dy);
+       if (!image)
+               return NULL;
+
+       assert(dx == 0 && dy == 0);
+       return sna_glyph(g)->image = image;
+}
+
+static inline pixman_image_t *
+sna_glyph_get_image(GlyphPtr g, ScreenPtr s)
+{
+       pixman_image_t *image;
+
+       image = sna_glyph(g)->image;
+       if (image == NULL)
+               image = __sna_glyph_get_image(g, s);
+
+       return image;
+}
+
+static bool
+glyphs_via_mask(struct sna *sna,
+               CARD8 op,
+               PicturePtr src,
+               PicturePtr dst,
+               PictFormatPtr format,
+               INT16 src_x, INT16 src_y,
+               int nlist, GlyphListPtr list, GlyphPtr *glyphs)
+{
+       ScreenPtr screen = dst->pDrawable->pScreen;
+       struct sna_composite_op tmp;
+       CARD32 component_alpha;
+       PixmapPtr pixmap;
+       PicturePtr glyph_atlas, mask;
+       int16_t x, y, width, height;
+       int error;
+       BoxRec box;
+
+       if (NO_GLYPHS_VIA_MASK)
+               return false;
+
+       DBG(("%s(op=%d, src=(%d, %d), nlist=%d,  dst=(%d, %d)+(%d, %d))\n",
+            __FUNCTION__, op, src_x, src_y, nlist,
+            list->xOff, list->yOff, dst->pDrawable->x, dst->pDrawable->y));
+
+       glyph_extents(nlist, list, glyphs, &box);
+       if (box.x2 <= box.x1 || box.y2 <= box.y1)
+               return true;
+
+       DBG(("%s: bounds=((%d, %d), (%d, %d))\n", __FUNCTION__,
+            box.x1, box.y1, box.x2, box.y2));
+
+       if (!sna_compute_composite_extents(&box,
+                                          src, NULL, dst,
+                                          src_x, src_y,
+                                          0, 0,
+                                          box.x1, box.y1,
+                                          box.x2 - box.x1,
+                                          box.y2 - box.y1))
+               return true;
+
+       DBG(("%s: extents=((%d, %d), (%d, %d))\n", __FUNCTION__,
+            box.x1, box.y1, box.x2, box.y2));
+
+       width  = box.x2 - box.x1;
+       height = box.y2 - box.y1;
+       box.x1 -= dst->pDrawable->x;
+       box.y1 -= dst->pDrawable->y;
+       x = -box.x1;
+       y = -box.y1;
+       src_x += box.x1 - list->xOff;
+       src_y += box.y1 - list->yOff;
+
+       if (format->depth < 8) {
+               format = PictureMatchFormat(screen, 8, PICT_a8);
+               if (!format)
+                       return false;
+       }
+
+       component_alpha = NeedsComponent(format->format);
+       if (!NO_SMALL_MASK &&
+           ((uint32_t)width * height * format->depth < 8 * 4096 ||
+            too_large(sna, width, height))) {
+               pixman_image_t *mask_image;
+
+               DBG(("%s: small mask [format=%lx, depth=%d, size=%d], rendering glyphs to upload buffer\n",
+                    __FUNCTION__, (unsigned long)format->format,
+                    format->depth, (uint32_t)width*height*format->depth));
+
+               pixmap = sna_pixmap_create_upload(screen,
+                                                 width, height,
+                                                 format->depth,
+                                                 KGEM_BUFFER_WRITE);
+               if (!pixmap)
+                       return false;
+
+               mask_image =
+                       pixman_image_create_bits(format->depth << 24 | format->format,
+                                                width, height,
+                                                pixmap->devPrivate.ptr,
+                                                pixmap->devKind);
+               if (mask_image == NULL)
+                       goto err_pixmap;
+
+               memset(pixmap->devPrivate.ptr, 0, pixmap->devKind*height);
+#if HAS_PIXMAN_GLYPHS
+               if (sna->render.glyph_cache) {
+                       pixman_glyph_t stack_glyphs[N_STACK_GLYPHS];
+                       pixman_glyph_t *pglyphs = stack_glyphs;
+                       pixman_glyph_cache_t *cache;
+                       int count, n;
+
+                       cache = sna->render.glyph_cache;
+                       pixman_glyph_cache_freeze(cache);
+
+                       count = 0;
+                       for (n = 0; n < nlist; ++n)
+                               count += list[n].len;
+                       if (count > N_STACK_GLYPHS) {
+                               pglyphs = malloc (count * sizeof(pixman_glyph_t));
+                               if (pglyphs == NULL)
+                                       goto err_pixmap;
+                       }
+
+                       count = 0;
+                       do {
+                               n = list->len;
+                               x += list->xOff;
+                               y += list->yOff;
+                               while (n--) {
+                                       GlyphPtr g = *glyphs++;
+                                       const void *ptr;
+
+                                       if (g->info.width == 0 || g->info.height == 0)
+                                               goto next_pglyph;
+
+                                       ptr = pixman_glyph_cache_lookup(cache, g, NULL);
+                                       if (ptr == NULL) {
+                                               pixman_image_t *glyph_image;
+
+                                               glyph_image = sna_glyph_get_image(g, screen);
+                                               if (glyph_image == NULL)
+                                                       goto next_pglyph;
+
+                                               ptr = pixman_glyph_cache_insert(cache, g, NULL,
+                                                                               g->info.x,
+                                                                               g->info.y,
+                                                                               glyph_image);
+                                               if (ptr == NULL)
+                                                       goto next_pglyph;
+                                       }
+
+                                       pglyphs[count].x = x;
+                                       pglyphs[count].y = y;
+                                       pglyphs[count].glyph = ptr;
+                                       count++;
+
+next_pglyph:
+                                       x += g->info.xOff;
+                                       y += g->info.yOff;
+                               }
+                               list++;
+                       } while (--nlist);
+
+                       pixman_composite_glyphs_no_mask(PIXMAN_OP_ADD,
+                                                       sna->render.white_image,
+                                                       mask_image,
+                                                       0, 0,
+                                                       0, 0,
+                                                       cache, count, pglyphs);
+                       pixman_glyph_cache_thaw(cache);
+                       if (pglyphs != stack_glyphs)
+                               free(pglyphs);
+               } else
+#endif
+               do {
+                       int n = list->len;
+                       x += list->xOff;
+                       y += list->yOff;
+                       while (n--) {
+                               GlyphPtr g = *glyphs++;
+                               pixman_image_t *glyph_image;
+                               int16_t xi, yi;
+
+                               if (g->info.width == 0 || g->info.height == 0)
+                                       goto next_image;
+
+                               /* If the mask has been cropped, it is likely
+                                * that some of the glyphs fall outside.
+                                */
+                               xi = x - g->info.x;
+                               yi = y - g->info.y;
+                               if (xi >= width || yi >= height)
+                                       goto next_image;
+                               if (xi + g->info.width  <= 0 ||
+                                   yi + g->info.height <= 0)
+                                       goto next_image;
+
+                               glyph_image =
+                                       sna_glyph_get_image(g, dst->pDrawable->pScreen);
+
+                               DBG(("%s: glyph to mask (%d, %d)x(%d, %d)\n",
+                                    __FUNCTION__,
+                                    xi, yi,
+                                    g->info.width,
+                                    g->info.height));
+
+                               if (list->format == format) {
+                                       assert(pixman_image_get_format(glyph_image) == pixman_image_get_format(mask_image));
+                                       pixman_image_composite(PictOpAdd,
+                                                              glyph_image,
+                                                              NULL,
+                                                              mask_image,
+                                                              0, 0,
+                                                              0, 0,
+                                                              xi, yi,
+                                                              g->info.width,
+                                                              g->info.height);
+                               } else {
+                                       pixman_image_composite(PictOpAdd,
+                                                              sna->render.white_image,
+                                                              glyph_image,
+                                                              mask_image,
+                                                              0, 0,
+                                                              0, 0,
+                                                              xi, yi,
+                                                              g->info.width,
+                                                              g->info.height);
+                               }
+
+next_image:
+                               x += g->info.xOff;
+                               y += g->info.yOff;
+                       }
+                       list++;
+               } while (--nlist);
+               pixman_image_unref(mask_image);
+
+               mask = CreatePicture(0, &pixmap->drawable,
+                                    format, CPComponentAlpha,
+                                    &component_alpha, serverClient, &error);
+               if (!mask)
+                       goto err_pixmap;
+
+               ValidatePicture(mask);
+       } else {
+               pixmap = screen->CreatePixmap(screen,
+                                             width, height, format->depth,
+                                             SNA_CREATE_SCRATCH);
+               if (!pixmap)
+                       return false;
+
+               mask = CreatePicture(0, &pixmap->drawable,
+                                    format, CPComponentAlpha,
+                                    &component_alpha, serverClient, &error);
+               if (!mask)
+                       goto err_pixmap;
+
+               ValidatePicture(mask);
+               if (!clear_pixmap(sna, pixmap))
+                       goto err_mask;
+
+               memset(&tmp, 0, sizeof(tmp));
+               glyph_atlas = NULL;
+               do {
+                       int n = list->len;
+                       x += list->xOff;
+                       y += list->yOff;
+                       while (n--) {
+                               GlyphPtr glyph = *glyphs++;
+                               struct sna_glyph *priv;
+                               PicturePtr this_atlas;
+                               struct sna_composite_rectangles r;
+
+                               if (glyph->info.width == 0 || glyph->info.height == 0)
+                                       goto next_glyph;
+
+                               priv = sna_glyph(glyph);
+                               if (priv->atlas != NULL) {
+                                       this_atlas = priv->atlas;
+                                       r.src = priv->coordinate;
+                               } else {
+                                       if (glyph_atlas) {
+                                               tmp.done(sna, &tmp);
+                                               glyph_atlas = NULL;
+                                       }
+                                       if (glyph_cache(screen, &sna->render, glyph)) {
+                                               this_atlas = priv->atlas;
+                                               r.src = priv->coordinate;
+                                       } else {
+                                               /* no cache for this glyph */
+                                               this_atlas = GetGlyphPicture(glyph, screen);
+                                               r.src.x = r.src.y = 0;
+                                       }
+                               }
+
+                               if (this_atlas != glyph_atlas) {
+                                       bool ok;
+
+                                       if (glyph_atlas)
+                                               tmp.done(sna, &tmp);
+
+                                       DBG(("%s: atlas format=%08x, mask format=%08x\n",
+                                            __FUNCTION__,
+                                            (int)this_atlas->format,
+                                            (int)(format->depth << 24 | format->format)));
+                                       if (this_atlas->format == (format->depth << 24 | format->format)) {
+                                               ok = sna->render.composite(sna, PictOpAdd,
+                                                                          this_atlas, NULL, mask,
+                                                                          0, 0, 0, 0, 0, 0,
+                                                                          0, 0,
+                                                                          &tmp);
+                                       } else {
+                                               ok = sna->render.composite(sna, PictOpAdd,
+                                                                          sna->render.white_picture, this_atlas, mask,
+                                                                          0, 0, 0, 0, 0, 0,
+                                                                          0, 0,
+                                                                          &tmp);
+                                       }
+                                       if (!ok) {
+                                               DBG(("%s: fallback -- can not handle PictOpAdd of glyph onto mask!\n",
+                                                    __FUNCTION__));
+                                               goto err_mask;
+                                       }
+
+                                       glyph_atlas = this_atlas;
+                               }
+
+                               DBG(("%s: blt glyph origin (%d, %d), offset (%d, %d), src (%d, %d), size (%d, %d)\n",
+                                    __FUNCTION__,
+                                    x, y,
+                                    glyph->info.x, glyph->info.y,
+                                    r.src.x, r.src.y,
+                                    glyph->info.width, glyph->info.height));
+
+                               r.mask = r.src;
+                               r.dst.x = x - glyph->info.x;
+                               r.dst.y = y - glyph->info.y;
+                               r.width  = glyph->info.width;
+                               r.height = glyph->info.height;
+                               tmp.blt(sna, &tmp, &r);
+
+next_glyph:
+                               x += glyph->info.xOff;
+                               y += glyph->info.yOff;
+                       }
+                       list++;
+               } while (--nlist);
+               if (glyph_atlas)
+                       tmp.done(sna, &tmp);
+       }
+
+       sna_composite(op,
+                     src, mask, dst,
+                     src_x, src_y,
+                     0, 0,
+                     box.x1, box.y1,
+                     width, height);
+err_mask:
+       FreePicture(mask, 0);
+err_pixmap:
+       sna_pixmap_destroy(pixmap);
+       return TRUE;
+}
+
+static PictFormatPtr
+glyphs_format(int nlist, GlyphListPtr list, GlyphPtr * glyphs)
+{
+       PictFormatPtr format = list[0].format;
+       int16_t x1, x2, y1, y2;
+       int16_t x, y;
+       BoxRec stack_extents[64], *list_extents = stack_extents;
+       int i, j;
+
+       if (nlist > ARRAY_SIZE(stack_extents)) {
+               list_extents = malloc(sizeof(BoxRec) * nlist);
+               if (list_extents == NULL)
+                       return NULL;
+       }
+
+       x = 0;
+       y = 0;
+       for (i = 0; i < nlist; i++) {
+               BoxRec extents;
+               bool first = true;
+               int n = list->len;
+
+               /* Check the intersection of each glyph within the list and
+                * then each list against the previous lists.
+                *
+                * If we overlap then we cannot substitute a mask as the
+                * rendering will be altered.
+                */
+               extents.x1 = 0;
+               extents.y1 = 0;
+               extents.x2 = 0;
+               extents.y2 = 0;
+
+               if (format->format != list->format->format) {
+                       format = NULL;
+                       goto out;
+               }
+
+               x += list->xOff;
+               y += list->yOff;
+               list++;
+               while (n--) {
+                       GlyphPtr glyph = *glyphs++;
+
+                       if (glyph->info.width == 0 || glyph->info.height == 0) {
+                               x += glyph->info.xOff;
+                               y += glyph->info.yOff;
+                               continue;
+                       }
+
+                       x1 = x - glyph->info.x;
+                       y1 = y - glyph->info.y;
+                       x2 = x1 + glyph->info.width;
+                       y2 = y1 + glyph->info.height;
+
+                       if (first) {
+                               extents.x1 = x1;
+                               extents.y1 = y1;
+                               extents.x2 = x2;
+                               extents.y2 = y2;
+                               first = false;
+                       } else {
+                               /* Potential overlap?
+                                * We cheat and ignore the boundary pixels, as
+                                * the likelihood of an actual overlap of
+                                * inkedk pixels being noticeable in the
+                                * boundary is small, yet glyphs frequently
+                                * overlap on the boundaries.
+                                */
+                               if (x1 < extents.x2-1 && x2 > extents.x1+1 &&
+                                   y1 < extents.y2-1 && y2 > extents.y1+1) {
+                                       format = NULL;
+                                       goto out;
+                               }
+
+                               if (x1 < extents.x1)
+                                       extents.x1 = x1;
+                               if (x2 > extents.x2)
+                                       extents.x2 = x2;
+                               if (y1 < extents.y1)
+                                       extents.y1 = y1;
+                               if (y2 > extents.y2)
+                                       extents.y2 = y2;
+                       }
+                       x += glyph->info.xOff;
+                       y += glyph->info.yOff;
+               }
+
+               /* Incrementally building a region is expensive. We expect
+                * the number of lists to be small, so just keep a list
+                * of the previous boxes and walk those.
+                */
+               for (j = 0; j < i; j++) {
+                       if (extents.x1 < list_extents[j].x2-1 &&
+                           extents.x2 > list_extents[j].x1+1 &&
+                           extents.y1 < list_extents[j].y2-1 &&
+                           extents.y2 > list_extents[j].y1+1) {
+                               format = NULL;
+                               goto out;
+                       }
+               }
+               list_extents[i] = extents;
+       }
+
+out:
+       if (list_extents != stack_extents)
+               free(list_extents);
+       return format;
+}
+
+static bool can_discard_mask(uint8_t op, PicturePtr src, PictFormatPtr mask,
+                            int nlist, GlyphListPtr list, GlyphPtr *glyphs)
+{
+       PictFormatPtr g;
+       uint32_t color;
+
+       if (NO_DISCARD_MASK)
+               return false;
+
+       if (nlist == 1 && list->len == 1)
+               return true;
+
+       if (!op_is_bounded(op))
+               return false;
+
+       /* No glyphs overlap and we are not performing a mask conversion. */
+       g = glyphs_format(nlist, list, glyphs);
+       if (mask == g)
+               return true;
+
+       /* Otherwise if the glyphs are all bitmaps and we have an
+        * opaque source we can also render directly to the dst.
+        */
+       if (g == NULL) {
+               while (nlist--) {
+                       if (list->format->depth != 1)
+                               return false;
+
+                       list++;
+               }
+       } else {
+               if (g->depth != 1)
+                       return false;
+       }
+
+       if (!sna_picture_is_solid(src, &color))
+               return false;
+
+       return color >> 24 == 0xff;
+}
+
+static void
+glyphs_fallback(CARD8 op,
+               PicturePtr src,
+               PicturePtr dst,
+               PictFormatPtr mask_format,
+               int src_x, int src_y,
+               int nlist, GlyphListPtr list, GlyphPtr *glyphs)
+{
+       struct sna *sna = to_sna_from_drawable(dst->pDrawable);
+       pixman_image_t *src_image, *dst_image;
+       int src_dx, src_dy;
+       ScreenPtr screen = dst->pDrawable->pScreen;
+       RegionRec region;
+       int x, y, n;
+
+       glyph_extents(nlist, list, glyphs, &region.extents);
+       if (region.extents.x2 <= region.extents.x1 ||
+           region.extents.y2 <= region.extents.y1)
+               return;
+
+       DBG(("%s: (%d, %d), (%d, %d)\n", __FUNCTION__,
+            region.extents.x1, region.extents.y1,
+            region.extents.x2, region.extents.y2));
+
+       region.data = NULL;
+       RegionTranslate(&region, dst->pDrawable->x, dst->pDrawable->y);
+       if (dst->pCompositeClip)
+               RegionIntersect(&region, &region, dst->pCompositeClip);
+       DBG(("%s: clipped extents (%d, %d), (%d, %d)\n",
+            __FUNCTION__,
+            RegionExtents(&region)->x1, RegionExtents(&region)->y1,
+            RegionExtents(&region)->x2, RegionExtents(&region)->y2));
+       if (!RegionNotEmpty(&region))
+               return;
+
+       if (!sna_drawable_move_region_to_cpu(dst->pDrawable, &region,
+                                            MOVE_READ | MOVE_WRITE))
+               return;
+       if (dst->alphaMap &&
+           !sna_drawable_move_to_cpu(dst->alphaMap->pDrawable,
+                                     MOVE_READ | MOVE_WRITE))
+               return;
+
+       if (src->pDrawable) {
+               if (!sna_drawable_move_to_cpu(src->pDrawable,
+                                             MOVE_READ))
+                       return;
+
+               if (src->alphaMap &&
+                   !sna_drawable_move_to_cpu(src->alphaMap->pDrawable,
+                                             MOVE_READ))
+                       return;
+       }
+       RegionTranslate(&region, -dst->pDrawable->x, -dst->pDrawable->y);
+
+       if (mask_format &&
+           can_discard_mask(op, src, mask_format, nlist, list, glyphs)) {
+               DBG(("%s: discarding mask\n", __FUNCTION__));
+               mask_format = NULL;
+       }
+
+#if HAS_PIXMAN_GLYPHS
+       if (sna->render.glyph_cache) {
+               pixman_glyph_t stack_glyphs[N_STACK_GLYPHS];
+               pixman_glyph_t *pglyphs = stack_glyphs;
+               pixman_glyph_cache_t *cache = sna->render.glyph_cache;
+               int dst_x = list->xOff, dst_y = list->yOff;
+               int dst_dx, dst_dy, count;
+
+               pixman_glyph_cache_freeze(cache);
+
+               count = 0;
+               for (n = 0; n < nlist; ++n)
+                       count += list[n].len;
+               if (count > N_STACK_GLYPHS) {
+                       pglyphs = malloc (count * sizeof(pixman_glyph_t));
+                       if (pglyphs == NULL)
+                               goto out;
+               }
+
+               count = 0;
+               x = y = 0;
+               while (nlist--) {
+                       n = list->len;
+                       x += list->xOff;
+                       y += list->yOff;
+                       while (n--) {
+                               GlyphPtr g = *glyphs++;
+                               const void *ptr;
+
+                               if (g->info.width == 0 || g->info.height == 0)
+                                       goto next;
+
+                               ptr = pixman_glyph_cache_lookup(cache, g, NULL);
+                               if (ptr == NULL) {
+                                       pixman_image_t *glyph_image;
+
+                                       glyph_image = sna_glyph_get_image(g, screen);
+                                       if (glyph_image == NULL)
+                                               goto next;
+
+                                       ptr = pixman_glyph_cache_insert(cache, g, NULL,
+                                                                       g->info.x,
+                                                                       g->info.y,
+                                                                       glyph_image);
+                                       if (ptr == NULL)
+                                               goto out;
+                               }
+
+                               pglyphs[count].x = x;
+                               pglyphs[count].y = y;
+                               pglyphs[count].glyph = ptr;
+                               count++;
+
+next:
+                               x += g->info.xOff;
+                               y += g->info.yOff;
+                       }
+                       list++;
+               }
+
+               src_image = image_from_pict(src, FALSE, &src_dx, &src_dy);
+               if (src_image == NULL)
+                       goto out;
+
+               dst_image = image_from_pict(dst, TRUE, &dst_dx, &dst_dy);
+               if (dst_image == NULL)
+                       goto out_free_src;
+
+               if (mask_format) {
+                       pixman_composite_glyphs(op, src_image, dst_image,
+                                               mask_format->format | (mask_format->depth << 24),
+                                               src_x + src_dx + region.extents.x1 - dst_x,
+                                               src_y + src_dy + region.extents.y1 - dst_y,
+                                               region.extents.x1, region.extents.y1,
+                                               region.extents.x1 + dst_dx, region.extents.y1 + dst_dy,
+                                               region.extents.x2 - region.extents.x1,
+                                               region.extents.y2 - region.extents.y1,
+                                               cache, count, pglyphs);
+               } else {
+                       pixman_composite_glyphs_no_mask(op, src_image, dst_image,
+                                                       src_x + src_dx - dst_x, src_y + src_dy - dst_y,
+                                                       dst_dx, dst_dy,
+                                                       cache, count, pglyphs);
+               }
+
+               free_pixman_pict(dst, dst_image);
+
+out_free_src:
+               free_pixman_pict(src, src_image);
+
+out:
+               pixman_glyph_cache_thaw(cache);
+               if (pglyphs != stack_glyphs)
+                       free(pglyphs);
+       } else
+#endif
+       {
+               pixman_image_t *mask_image;
+
+               dst_image = image_from_pict(dst, TRUE, &x, &y);
+               if (dst_image == NULL)
+                       goto cleanup_region;
+               DBG(("%s: dst offset (%d, %d)\n", __FUNCTION__, x, y));
+               if (x | y) {
+                       region.extents.x1 += x;
+                       region.extents.x2 += x;
+                       region.extents.y1 += y;
+                       region.extents.y2 += y;
+               }
+
+               src_image = image_from_pict(src, FALSE, &src_dx, &src_dy);
+               if (src_image == NULL)
+                       goto cleanup_dst;
+               DBG(("%s: src offset (%d, %d)\n", __FUNCTION__, src_dx, src_dy));
+               src_x += src_dx - list->xOff;
+               src_y += src_dy - list->yOff;
+
+               if (mask_format) {
+                       DBG(("%s: create mask (%d, %d)x(%d,%d) + (%d,%d) + (%d,%d), depth=%d, format=%lx [%lx], ca? %d\n",
+                            __FUNCTION__,
+                            region.extents.x1, region.extents.y1,
+                            region.extents.x2 - region.extents.x1,
+                            region.extents.y2 - region.extents.y1,
+                            dst->pDrawable->x, dst->pDrawable->y,
+                            x, y,
+                            mask_format->depth,
+                            (long)mask_format->format,
+                            (long)(mask_format->depth << 24 | mask_format->format),
+                            NeedsComponent(mask_format->format)));
+                       mask_image =
+                               pixman_image_create_bits(mask_format->depth << 24 | mask_format->format,
+                                                        region.extents.x2 - region.extents.x1,
+                                                        region.extents.y2 - region.extents.y1,
+                                                        NULL, 0);
+                       if (mask_image == NULL)
+                               goto cleanup_src;
+                       if (NeedsComponent(mask_format->format))
+                               pixman_image_set_component_alpha(mask_image, TRUE);
+
+                       x -= region.extents.x1;
+                       y -= region.extents.y1;
+               } else {
+                       mask_image = dst_image;
+                       src_x -= x - dst->pDrawable->x;
+                       src_y -= y - dst->pDrawable->y;
+               }
+
+               do {
+                       n = list->len;
+                       x += list->xOff;
+                       y += list->yOff;
+                       while (n--) {
+                               GlyphPtr g = *glyphs++;
+                               pixman_image_t *glyph_image;
+
+                               if (g->info.width == 0 || g->info.height == 0)
+                                       goto next_glyph;
+
+                               glyph_image = sna_glyph_get_image(g, screen);
+                               if (glyph_image == NULL)
+                                       goto next_glyph;
+
+                               if (mask_format) {
+                                       DBG(("%s: glyph to mask (%d, %d)x(%d, %d)\n",
+                                            __FUNCTION__,
+                                            x - g->info.x,
+                                            y - g->info.y,
+                                            g->info.width,
+                                            g->info.height));
+
+                                       if (list->format == mask_format) {
+                                               assert(pixman_image_get_format(glyph_image) == pixman_image_get_format(mask_image));
+                                               pixman_image_composite(PictOpAdd,
+                                                                      glyph_image,
+                                                                      NULL,
+                                                                      mask_image,
+                                                                      0, 0,
+                                                                      0, 0,
+                                                                      x - g->info.x,
+                                                                      y - g->info.y,
+                                                                      g->info.width,
+                                                                      g->info.height);
+                                       } else {
+                                               pixman_image_composite(PictOpAdd,
+                                                                      sna->render.white_image,
+                                                                      glyph_image,
+                                                                      mask_image,
+                                                                      0, 0,
+                                                                      0, 0,
+                                                                      x - g->info.x,
+                                                                      y - g->info.y,
+                                                                      g->info.width,
+                                                                      g->info.height);
+                                       }
+                               } else {
+                                       int xi = x - g->info.x;
+                                       int yi = y - g->info.y;
+
+                                       DBG(("%s: glyph to dst (%d, %d)x(%d, %d)/[(%d, %d)x(%d, %d)], src (%d, %d) [op=%d]\n",
+                                            __FUNCTION__,
+                                            xi, yi,
+                                            g->info.width, g->info.height,
+                                            dst->pDrawable->x,
+                                            dst->pDrawable->y,
+                                            dst->pDrawable->width,
+                                            dst->pDrawable->height,
+                                            src_x + xi,
+                                            src_y + yi,
+                                            op));
+
+                                       pixman_image_composite(op,
+                                                              src_image,
+                                                              glyph_image,
+                                                              dst_image,
+                                                              src_x + xi,
+                                                              src_y + yi,
+                                                              0, 0,
+                                                              xi, yi,
+                                                              g->info.width,
+                                                              g->info.height);
+                               }
+next_glyph:
+                               x += g->info.xOff;
+                               y += g->info.yOff;
+                       }
+                       list++;
+               } while (--nlist);
+
+               if (mask_format) {
+                       DBG(("%s: glyph mask composite src=(%d+%d,%d+%d) dst=(%d, %d)x(%d, %d)\n",
+                            __FUNCTION__,
+                            src_x, region.extents.x1, src_y, region.extents.y1,
+                            region.extents.x1, region.extents.y1,
+                            region.extents.x2 - region.extents.x1,
+                            region.extents.y2 - region.extents.y1));
+                       pixman_image_composite(op, src_image, mask_image, dst_image,
+                                              src_x, src_y,
+                                              0, 0,
+                                              region.extents.x1, region.extents.y1,
+                                              region.extents.x2 - region.extents.x1,
+                                              region.extents.y2 - region.extents.y1);
+                       pixman_image_unref(mask_image);
+               }
+
+cleanup_src:
+               free_pixman_pict(src, src_image);
+cleanup_dst:
+               free_pixman_pict(dst, dst_image);
+       }
+
+cleanup_region:
+       RegionUninit(&region);
+}
+
+void
+sna_glyphs(CARD8 op,
+          PicturePtr src,
+          PicturePtr dst,
+          PictFormatPtr mask,
+          INT16 src_x, INT16 src_y,
+          int nlist, GlyphListPtr list, GlyphPtr *glyphs)
+{
+       PixmapPtr pixmap = get_drawable_pixmap(dst->pDrawable);
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+       struct sna_pixmap *priv;
+
+       DBG(("%s(op=%d, nlist=%d, src=(%d, %d))\n",
+            __FUNCTION__, op, nlist, src_x, src_y));
+
+       if (REGION_NUM_RECTS(dst->pCompositeClip) == 0)
+               return;
+
+       if (FALLBACK)
+               goto fallback;
+
+       if (!can_render(sna)) {
+               DBG(("%s: wedged\n", __FUNCTION__));
+               goto fallback;
+       }
+
+       if (dst->alphaMap) {
+               DBG(("%s: fallback -- dst alpha map\n", __FUNCTION__));
+               goto fallback;
+       }
+
+       priv = sna_pixmap(pixmap);
+       if (priv == NULL) {
+               DBG(("%s: fallback -- destination unattached\n", __FUNCTION__));
+               goto fallback;
+       }
+
+       if ((too_small(priv) || DAMAGE_IS_ALL(priv->cpu_damage)) &&
+           !picture_is_gpu(src)) {
+               DBG(("%s: fallback -- too small (%dx%d)\n",
+                    __FUNCTION__, dst->pDrawable->width, dst->pDrawable->height));
+               goto fallback;
+       }
+
+       if (mask == NULL) {
+               if (glyphs_to_dst(sna, op,
+                                 src, dst,
+                                 src_x, src_y,
+                                 nlist, list, glyphs))
+                       return;
+       }
+
+       /* Try to discard the mask for non-overlapping glyphs */
+       if (mask && dst->pCompositeClip->data == NULL &&
+           can_discard_mask(op, src, mask, nlist, list, glyphs)) {
+               DBG(("%s: discarding mask\n", __FUNCTION__));
+               if (glyphs_to_dst(sna, op,
+                                 src, dst,
+                                 src_x, src_y,
+                                 nlist, list, glyphs))
+                       return;
+       }
+
+       /* Otherwise see if we can substitute a mask */
+       if (!mask) {
+               mask = glyphs_format(nlist, list, glyphs);
+               DBG(("%s: substituting mask? %d\n", __FUNCTION__, mask!=NULL));
+       }
+       if (mask) {
+               if (glyphs_via_mask(sna, op,
+                                   src, dst, mask,
+                                   src_x, src_y,
+                                   nlist, list, glyphs))
+                       return;
+       } else {
+               if (glyphs_slow(sna, op,
+                               src, dst,
+                               src_x, src_y,
+                               nlist, list, glyphs))
+                       return;
+       }
+
+fallback:
+       glyphs_fallback(op, src, dst, mask, src_x, src_y, nlist, list, glyphs);
+}
+
+static bool
+glyphs_via_image(struct sna *sna,
+                CARD8 op,
+                PicturePtr src,
+                PicturePtr dst,
+                PictFormatPtr format,
+                INT16 src_x, INT16 src_y,
+                int nlist, GlyphListPtr list, GlyphPtr *glyphs)
+{
+       ScreenPtr screen = dst->pDrawable->pScreen;
+       CARD32 component_alpha;
+       PixmapPtr pixmap;
+       PicturePtr mask;
+       int16_t x, y, width, height;
+       pixman_image_t *mask_image;
+       int error;
+       BoxRec box;
+
+       if (NO_GLYPHS_VIA_MASK)
+               return false;
+
+       DBG(("%s(op=%d, src=(%d, %d), nlist=%d,  dst=(%d, %d)+(%d, %d))\n",
+            __FUNCTION__, op, src_x, src_y, nlist,
+            list->xOff, list->yOff, dst->pDrawable->x, dst->pDrawable->y));
+
+       glyph_extents(nlist, list, glyphs, &box);
+       if (box.x2 <= box.x1 || box.y2 <= box.y1)
+               return true;
+
+       DBG(("%s: bounds=((%d, %d), (%d, %d))\n", __FUNCTION__,
+            box.x1, box.y1, box.x2, box.y2));
+
+       if (!sna_compute_composite_extents(&box,
+                                          src, NULL, dst,
+                                          src_x, src_y,
+                                          0, 0,
+                                          box.x1, box.y1,
+                                          box.x2 - box.x1,
+                                          box.y2 - box.y1))
+               return true;
+
+       DBG(("%s: extents=((%d, %d), (%d, %d))\n", __FUNCTION__,
+            box.x1, box.y1, box.x2, box.y2));
+
+       width  = box.x2 - box.x1;
+       height = box.y2 - box.y1;
+       box.x1 -= dst->pDrawable->x;
+       box.y1 -= dst->pDrawable->y;
+       x = -box.x1;
+       y = -box.y1;
+       src_x += box.x1 - list->xOff;
+       src_y += box.y1 - list->yOff;
+
+       if (format->depth < 8) {
+               format = PictureMatchFormat(screen, 8, PICT_a8);
+               if (!format)
+                       return false;
+       }
+
+       DBG(("%s: small mask [format=%lx, depth=%d, size=%d], rendering glyphs to upload buffer\n",
+            __FUNCTION__, (unsigned long)format->format,
+            format->depth, (uint32_t)width*height*format->depth));
+
+       pixmap = sna_pixmap_create_upload(screen,
+                                         width, height,
+                                         format->depth,
+                                         KGEM_BUFFER_WRITE);
+       if (!pixmap)
+               return false;
+
+       mask_image =
+               pixman_image_create_bits(format->depth << 24 | format->format,
+                                        width, height,
+                                        pixmap->devPrivate.ptr,
+                                        pixmap->devKind);
+       if (mask_image == NULL)
+               goto err_pixmap;
+
+       memset(pixmap->devPrivate.ptr, 0, pixmap->devKind*height);
+#if HAS_PIXMAN_GLYPHS
+       if (sna->render.glyph_cache) {
+               pixman_glyph_t stack_glyphs[N_STACK_GLYPHS];
+               pixman_glyph_t *pglyphs = stack_glyphs;
+               pixman_glyph_cache_t *cache;
+               int count, n;
+
+               cache = sna->render.glyph_cache;
+               pixman_glyph_cache_freeze(cache);
+
+               count = 0;
+               for (n = 0; n < nlist; ++n)
+                       count += list[n].len;
+               if (count > N_STACK_GLYPHS) {
+                       pglyphs = malloc (count * sizeof(pixman_glyph_t));
+                       if (pglyphs == NULL)
+                               goto err_pixmap;
+               }
+
+               count = 0;
+               do {
+                       n = list->len;
+                       x += list->xOff;
+                       y += list->yOff;
+                       while (n--) {
+                               GlyphPtr g = *glyphs++;
+                               const void *ptr;
+
+                               if (g->info.width == 0 || g->info.height == 0)
+                                       goto next_pglyph;
+
+                               ptr = pixman_glyph_cache_lookup(cache, g, NULL);
+                               if (ptr == NULL) {
+                                       pixman_image_t *glyph_image;
+
+                                       glyph_image = sna_glyph_get_image(g, screen);
+                                       if (glyph_image == NULL)
+                                               goto next_pglyph;
+
+                                       ptr = pixman_glyph_cache_insert(cache, g, NULL,
+                                                                       g->info.x,
+                                                                       g->info.y,
+                                                                       glyph_image);
+                                       if (ptr == NULL)
+                                               goto next_pglyph;
+                               }
+
+                               pglyphs[count].x = x;
+                               pglyphs[count].y = y;
+                               pglyphs[count].glyph = ptr;
+                               count++;
+
+next_pglyph:
+                               x += g->info.xOff;
+                               y += g->info.yOff;
+                       }
+                       list++;
+               } while (--nlist);
+
+               pixman_composite_glyphs_no_mask(PIXMAN_OP_ADD,
+                                               sna->render.white_image,
+                                               mask_image,
+                                               0, 0,
+                                               0, 0,
+                                               cache, count, pglyphs);
+               pixman_glyph_cache_thaw(cache);
+               if (pglyphs != stack_glyphs)
+                       free(pglyphs);
+       } else
+#endif
+               do {
+                       int n = list->len;
+                       x += list->xOff;
+                       y += list->yOff;
+                       while (n--) {
+                               GlyphPtr g = *glyphs++;
+                               pixman_image_t *glyph_image;
+                               int16_t xi, yi;
+
+                               if (g->info.width == 0 || g->info.height == 0)
+                                       goto next_image;
+
+                               /* If the mask has been cropped, it is likely
+                                * that some of the glyphs fall outside.
+                                */
+                               xi = x - g->info.x;
+                               yi = y - g->info.y;
+                               if (xi >= width || yi >= height)
+                                       goto next_image;
+                               if (xi + g->info.width  <= 0 ||
+                                   yi + g->info.height <= 0)
+                                       goto next_image;
+
+                               glyph_image =
+                                       sna_glyph_get_image(g, dst->pDrawable->pScreen);
+
+                               DBG(("%s: glyph to mask (%d, %d)x(%d, %d)\n",
+                                    __FUNCTION__,
+                                    xi, yi,
+                                    g->info.width,
+                                    g->info.height));
+
+                               if (list->format == format) {
+                                       assert(pixman_image_get_format(glyph_image) == pixman_image_get_format(mask_image));
+                                       pixman_image_composite(PictOpAdd,
+                                                              glyph_image,
+                                                              NULL,
+                                                              mask_image,
+                                                              0, 0,
+                                                              0, 0,
+                                                              xi, yi,
+                                                              g->info.width,
+                                                              g->info.height);
+                               } else {
+                                       pixman_image_composite(PictOpAdd,
+                                                              sna->render.white_image,
+                                                              glyph_image,
+                                                              mask_image,
+                                                              0, 0,
+                                                              0, 0,
+                                                              xi, yi,
+                                                              g->info.width,
+                                                              g->info.height);
+                               }
+
+next_image:
+                               x += g->info.xOff;
+                               y += g->info.yOff;
+                       }
+                       list++;
+               } while (--nlist);
+       pixman_image_unref(mask_image);
+
+       component_alpha = NeedsComponent(format->format);
+
+       mask = CreatePicture(0, &pixmap->drawable,
+                            format, CPComponentAlpha,
+                            &component_alpha, serverClient, &error);
+       if (!mask)
+               goto err_pixmap;
+
+       ValidatePicture(mask);
+
+       sna_composite(op,
+                     src, mask, dst,
+                     src_x, src_y,
+                     0, 0,
+                     box.x1, box.y1,
+                     width, height);
+       FreePicture(mask, 0);
+err_pixmap:
+       sna_pixmap_destroy(pixmap);
+       return TRUE;
+}
+
+void
+sna_glyphs__shared(CARD8 op,
+                  PicturePtr src,
+                  PicturePtr dst,
+                  PictFormatPtr mask,
+                  INT16 src_x, INT16 src_y,
+                  int nlist, GlyphListPtr list, GlyphPtr *glyphs)
+{
+       PixmapPtr pixmap = get_drawable_pixmap(dst->pDrawable);
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+       struct sna_pixmap *priv;
+
+       DBG(("%s(op=%d, nlist=%d, src=(%d, %d))\n",
+            __FUNCTION__, op, nlist, src_x, src_y));
+
+       if (REGION_NUM_RECTS(dst->pCompositeClip) == 0)
+               return;
+
+       if (FALLBACK)
+               goto fallback;
+
+       if (!can_render(sna)) {
+               DBG(("%s: wedged\n", __FUNCTION__));
+               goto fallback;
+       }
+
+       if (dst->alphaMap) {
+               DBG(("%s: fallback -- dst alpha map\n", __FUNCTION__));
+               goto fallback;
+       }
+
+       priv = sna_pixmap(pixmap);
+       if (priv == NULL) {
+               DBG(("%s: fallback -- destination unattached\n", __FUNCTION__));
+               goto fallback;
+       }
+
+       if ((too_small(priv) || DAMAGE_IS_ALL(priv->cpu_damage)) &&
+           !picture_is_gpu(src)) {
+               DBG(("%s: fallback -- too small (%dx%d)\n",
+                    __FUNCTION__, dst->pDrawable->width, dst->pDrawable->height));
+               goto fallback;
+       }
+
+       if (!mask) {
+               mask = glyphs_format(nlist, list, glyphs);
+               DBG(("%s: substituting mask? %d\n", __FUNCTION__, mask!=NULL));
+       }
+       if (mask) {
+               if (glyphs_via_image(sna, op,
+                                    src, dst, mask,
+                                    src_x, src_y,
+                                    nlist, list, glyphs))
+                       return;
+       }
+
+fallback:
+       glyphs_fallback(op, src, dst, mask, src_x, src_y, nlist, list, glyphs);
+}
+
+void
+sna_glyph_unrealize(ScreenPtr screen, GlyphPtr glyph)
+{
+       struct sna_glyph *priv = sna_glyph(glyph);
+
+       DBG(("%s: screen=%d, glyph(image?=%d, atlas?=%d)\n",
+            __FUNCTION__, screen->myNum, !!priv->image, !!priv->atlas));
+
+       if (priv->image) {
+#if HAS_PIXMAN_GLYPHS
+               struct sna *sna = to_sna_from_screen(screen);
+               if (sna->render.glyph_cache)
+                       pixman_glyph_cache_remove(sna->render.glyph_cache,
+                                                 glyph, NULL);
+#endif
+               pixman_image_unref(priv->image);
+               priv->image = NULL;
+       }
+
+       if (priv->atlas) {
+               struct sna *sna = to_sna_from_screen(screen);
+               struct sna_glyph_cache *cache = &sna->render.glyph[priv->pos&1];
+               DBG(("%s: releasing glyph pos %d from cache %d\n",
+                    __FUNCTION__, priv->pos >> 1, priv->pos & 1));
+               assert(cache->glyphs[priv->pos >> 1] == priv);
+               cache->glyphs[priv->pos >> 1] = NULL;
+               priv->atlas = NULL;
+       }
+}
diff --git a/src/sna/sna_gradient.c b/src/sna/sna_gradient.c
new file mode 100644 (file)
index 0000000..5f06fbc
--- /dev/null
@@ -0,0 +1,432 @@
+/*
+ * Copyright © 2010 Intel 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.
+ *
+ * Authors:
+ *    Chris Wilson <chris@chris-wilson.co.uk>
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "sna.h"
+#include "sna_render.h"
+
+#define xFixedToDouble(f) pixman_fixed_to_double(f)
+
+static int
+sna_gradient_sample_width(PictGradient *gradient)
+{
+       int n, width;
+
+       width = 0;
+       for (n = 1; n < gradient->nstops; n++) {
+               xFixed dx = gradient->stops[n].x - gradient->stops[n-1].x;
+               int delta, max, ramp;
+
+               if (dx == 0)
+                       return 1024;
+
+               max = gradient->stops[n].color.red -
+                       gradient->stops[n-1].color.red;
+               if (max < 0)
+                       max = -max;
+
+               delta = gradient->stops[n].color.green -
+                       gradient->stops[n-1].color.green;
+               if (delta < 0)
+                       delta = -delta;
+               if (delta > max)
+                       max = delta;
+
+               delta = gradient->stops[n].color.blue -
+                       gradient->stops[n-1].color.blue;
+               if (delta < 0)
+                       delta = -delta;
+               if (delta > max)
+                       max = delta;
+
+               delta = gradient->stops[n].color.alpha -
+                       gradient->stops[n-1].color.alpha;
+               if (delta < 0)
+                       delta = -delta;
+               if (delta > max)
+                       max = delta;
+
+               ramp = 256 * max / dx;
+               if (ramp > width)
+                       width = ramp;
+       }
+
+       if (width == 0)
+               return 1;
+
+       width = (width + 7) & -8;
+       return min(width, 1024);
+}
+
+static bool
+_gradient_color_stops_equal(PictGradient *pattern,
+                           struct sna_gradient_cache *cache)
+{
+    if (cache->nstops != pattern->nstops)
+           return false;
+
+    return memcmp(cache->stops,
+                 pattern->stops,
+                 sizeof(PictGradientStop)*cache->nstops) == 0;
+}
+
+struct kgem_bo *
+sna_render_get_gradient(struct sna *sna,
+                       PictGradient *pattern)
+{
+       struct sna_render *render = &sna->render;
+       struct sna_gradient_cache *cache;
+       pixman_image_t *gradient, *image;
+       pixman_point_fixed_t p1, p2;
+       int i, width;
+       struct kgem_bo *bo;
+
+       DBG(("%s: %dx[%f:%x ... %f:%x ... %f:%x]\n", __FUNCTION__,
+            pattern->nstops,
+            pattern->stops[0].x / 65536.,
+            pattern->stops[0].color.alpha >> 8 << 24 |
+            pattern->stops[0].color.red   >> 8 << 16 |
+            pattern->stops[0].color.green >> 8 << 8 |
+            pattern->stops[0].color.blue  >> 8 << 0,
+            pattern->stops[pattern->nstops/2].x / 65536.,
+            pattern->stops[pattern->nstops/2].color.alpha >> 8 << 24 |
+            pattern->stops[pattern->nstops/2].color.red   >> 8 << 16 |
+            pattern->stops[pattern->nstops/2].color.green >> 8 << 8 |
+            pattern->stops[pattern->nstops/2].color.blue  >> 8 << 0,
+            pattern->stops[pattern->nstops-1].x / 65536.,
+            pattern->stops[pattern->nstops-1].color.alpha >> 8 << 24 |
+            pattern->stops[pattern->nstops-1].color.red   >> 8 << 16 |
+            pattern->stops[pattern->nstops-1].color.green >> 8 << 8 |
+            pattern->stops[pattern->nstops-1].color.blue  >> 8 << 0));
+
+       for (i = 0; i < render->gradient_cache.size; i++) {
+               cache = &render->gradient_cache.cache[i];
+               if (_gradient_color_stops_equal(pattern, cache)) {
+                       DBG(("%s: old --> %d\n", __FUNCTION__, i));
+                       return kgem_bo_reference(cache->bo);
+               }
+       }
+
+       width = sna_gradient_sample_width(pattern);
+       DBG(("%s: sample width = %d\n", __FUNCTION__, width));
+       if (width == 0)
+               return NULL;
+
+       p1.x = 0;
+       p1.y = 0;
+       p2.x = width << 16;
+       p2.y = 0;
+
+       gradient = pixman_image_create_linear_gradient(&p1, &p2,
+                                                      (pixman_gradient_stop_t *)pattern->stops,
+                                                      pattern->nstops);
+       if (gradient == NULL)
+               return NULL;
+
+       pixman_image_set_filter(gradient, PIXMAN_FILTER_BILINEAR, NULL, 0);
+       pixman_image_set_repeat(gradient, PIXMAN_REPEAT_PAD);
+
+       image = pixman_image_create_bits(PIXMAN_a8r8g8b8, width, 1, NULL, 0);
+       if (image == NULL) {
+               pixman_image_unref(gradient);
+               return NULL;
+       }
+
+       pixman_image_composite(PIXMAN_OP_SRC,
+                              gradient, NULL, image,
+                              0, 0,
+                              0, 0,
+                              0, 0,
+                              width, 1);
+       pixman_image_unref(gradient);
+
+       DBG(("%s: [0]=%x, [%d]=%x [%d]=%x\n", __FUNCTION__,
+            pixman_image_get_data(image)[0],
+            width/2, pixman_image_get_data(image)[width/2],
+            width-1, pixman_image_get_data(image)[width-1]));
+
+       bo = kgem_create_linear(&sna->kgem, width*4, 0);
+       if (!bo) {
+               pixman_image_unref(image);
+               return NULL;
+       }
+
+       bo->pitch = 4*width;
+       kgem_bo_write(&sna->kgem, bo, pixman_image_get_data(image), 4*width);
+
+       pixman_image_unref(image);
+
+       if (render->gradient_cache.size < GRADIENT_CACHE_SIZE)
+               i = render->gradient_cache.size++;
+       else
+               i = rand () % GRADIENT_CACHE_SIZE;
+
+       cache = &render->gradient_cache.cache[i];
+       if (cache->nstops < pattern->nstops) {
+               PictGradientStop *newstops;
+
+               newstops = malloc(sizeof(PictGradientStop) * pattern->nstops);
+               if (newstops == NULL)
+                       return bo;
+
+               free(cache->stops);
+               cache->stops = newstops;
+       }
+
+       memcpy(cache->stops, pattern->stops,
+              sizeof(PictGradientStop) * pattern->nstops);
+       cache->nstops = pattern->nstops;
+
+       if (cache->bo)
+               kgem_bo_destroy(&sna->kgem, cache->bo);
+       cache->bo = kgem_bo_reference(bo);
+
+       return bo;
+}
+
+void
+sna_render_flush_solid(struct sna *sna)
+{
+       struct sna_solid_cache *cache = &sna->render.solid_cache;
+
+       DBG(("sna_render_flush_solid(size=%d)\n", cache->size));
+       assert(cache->dirty);
+       assert(cache->size);
+
+       kgem_bo_write(&sna->kgem, cache->cache_bo,
+                     cache->color, cache->size*sizeof(uint32_t));
+       cache->dirty = 0;
+       cache->last = 0;
+}
+
+static void
+sna_render_finish_solid(struct sna *sna, bool force)
+{
+       struct sna_solid_cache *cache = &sna->render.solid_cache;
+       struct kgem_bo *old;
+       int i;
+
+       DBG(("sna_render_finish_solid(force=%d, domain=%d, busy=%d, dirty=%d)\n",
+            force, cache->cache_bo->domain, cache->cache_bo->rq != NULL, cache->dirty));
+
+       if (!force && cache->cache_bo->domain != DOMAIN_GPU)
+               return;
+
+       if (cache->dirty)
+               sna_render_flush_solid(sna);
+
+       for (i = 0; i < cache->size; i++) {
+               if (cache->bo[i] == NULL)
+                       continue;
+
+               kgem_bo_destroy(&sna->kgem, cache->bo[i]);
+               cache->bo[i] = NULL;
+       }
+
+       old = cache->cache_bo;
+
+       DBG(("sna_render_finish_solid reset\n"));
+
+       cache->cache_bo = kgem_create_linear(&sna->kgem, sizeof(cache->color), 0);
+       if (cache->cache_bo == NULL) {
+               cache->cache_bo = old;
+               old = NULL;
+       }
+
+       cache->bo[0] = kgem_create_proxy(&sna->kgem, cache->cache_bo,
+                                        0, sizeof(uint32_t));
+       cache->bo[0]->pitch = 4;
+       if (force)
+               cache->size = 1;
+
+       if (old)
+               kgem_bo_destroy(&sna->kgem, old);
+}
+
+struct kgem_bo *
+sna_render_get_solid(struct sna *sna, uint32_t color)
+{
+       struct sna_solid_cache *cache = &sna->render.solid_cache;
+       int i;
+
+       DBG(("%s: %08x\n", __FUNCTION__, color));
+
+       if ((color & 0xffffff) == 0) /* alpha only */
+               return kgem_bo_reference(sna->render.alpha_cache.bo[color>>24]);
+
+       if (color == 0xffffffff) {
+               DBG(("%s(white)\n", __FUNCTION__));
+               return kgem_bo_reference(cache->bo[0]);
+       }
+
+       if (cache->color[cache->last] == color) {
+               DBG(("sna_render_get_solid(%d) = %x (last)\n",
+                    cache->last, color));
+               return kgem_bo_reference(cache->bo[cache->last]);
+       }
+
+       for (i = 1; i < cache->size; i++) {
+               if (cache->color[i] == color) {
+                       if (cache->bo[i] == NULL) {
+                               DBG(("sna_render_get_solid(%d) = %x (recreate)\n",
+                                    i, color));
+                               goto create;
+                       } else {
+                               DBG(("sna_render_get_solid(%d) = %x (old)\n",
+                                    i, color));
+                               goto done;
+                       }
+               }
+       }
+
+       sna_render_finish_solid(sna, i == ARRAY_SIZE(cache->color));
+
+       i = cache->size++;
+       cache->color[i] = color;
+       cache->dirty = 1;
+       DBG(("sna_render_get_solid(%d) = %x (new)\n", i, color));
+
+create:
+       cache->bo[i] = kgem_create_proxy(&sna->kgem, cache->cache_bo,
+                                        i*sizeof(uint32_t), sizeof(uint32_t));
+       cache->bo[i]->pitch = 4;
+
+done:
+       cache->last = i;
+       return kgem_bo_reference(cache->bo[i]);
+}
+
+static bool sna_alpha_cache_init(struct sna *sna)
+{
+       struct sna_alpha_cache *cache = &sna->render.alpha_cache;
+       uint32_t color[256];
+       int i;
+
+       DBG(("%s\n", __FUNCTION__));
+
+       cache->cache_bo = kgem_create_linear(&sna->kgem, sizeof(color), 0);
+       if (!cache->cache_bo)
+               return false;
+
+       for (i = 0; i < 256; i++) {
+               color[i] = i << 24;
+               cache->bo[i] = kgem_create_proxy(&sna->kgem,
+                                                cache->cache_bo,
+                                                sizeof(uint32_t)*i,
+                                                sizeof(uint32_t));
+               if (cache->bo[i] == NULL)
+                       return false;
+
+               cache->bo[i]->pitch = 4;
+       }
+       return kgem_bo_write(&sna->kgem, cache->cache_bo, color, sizeof(color));
+}
+
+static bool sna_solid_cache_init(struct sna *sna)
+{
+       struct sna_solid_cache *cache = &sna->render.solid_cache;
+
+       DBG(("%s\n", __FUNCTION__));
+
+       cache->cache_bo =
+               kgem_create_linear(&sna->kgem, sizeof(cache->color), 0);
+       if (!cache->cache_bo)
+               return false;
+
+       /*
+        * Initialise [0] with white since it is very common and filling the
+        * zeroth slot simplifies some of the checks.
+        */
+       cache->color[0] = 0xffffffff;
+       cache->bo[0] = kgem_create_proxy(&sna->kgem, cache->cache_bo,
+                                        0, sizeof(uint32_t));
+       if (cache->bo[0] == NULL)
+               return false;
+
+       cache->bo[0]->pitch = 4;
+       cache->dirty = 1;
+       cache->size = 1;
+       cache->last = 0;
+
+       return true;
+}
+
+bool sna_gradients_create(struct sna *sna)
+{
+       DBG(("%s\n", __FUNCTION__));
+
+       if (!can_render(sna))
+               return true;
+
+       if (!sna_alpha_cache_init(sna))
+               return false;
+
+       if (!sna_solid_cache_init(sna))
+               return false;
+
+       return true;
+}
+
+void sna_gradients_close(struct sna *sna)
+{
+       int i;
+
+       DBG(("%s\n", __FUNCTION__));
+
+       for (i = 0; i < 256; i++) {
+               if (sna->render.alpha_cache.bo[i])
+                       kgem_bo_destroy(&sna->kgem, sna->render.alpha_cache.bo[i]);
+       }
+       if (sna->render.alpha_cache.cache_bo)
+               kgem_bo_destroy(&sna->kgem, sna->render.alpha_cache.cache_bo);
+
+       if (sna->render.solid_cache.cache_bo)
+               kgem_bo_destroy(&sna->kgem, sna->render.solid_cache.cache_bo);
+       for (i = 0; i < sna->render.solid_cache.size; i++) {
+               if (sna->render.solid_cache.bo[i])
+                       kgem_bo_destroy(&sna->kgem, sna->render.solid_cache.bo[i]);
+       }
+       sna->render.solid_cache.cache_bo = 0;
+       sna->render.solid_cache.size = 0;
+       sna->render.solid_cache.dirty = 0;
+
+       for (i = 0; i < sna->render.gradient_cache.size; i++) {
+               struct sna_gradient_cache *cache =
+                       &sna->render.gradient_cache.cache[i];
+
+               if (cache->bo)
+                       kgem_bo_destroy(&sna->kgem, cache->bo);
+
+               free(cache->stops);
+               cache->stops = NULL;
+               cache->nstops = 0;
+       }
+       sna->render.gradient_cache.size = 0;
+}
diff --git a/src/sna/sna_io.c b/src/sna/sna_io.c
new file mode 100644 (file)
index 0000000..60ea517
--- /dev/null
@@ -0,0 +1,1489 @@
+/*
+ * Copyright (c) 2011 Intel 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.
+ *
+ * Authors:
+ *    Chris Wilson <chris@chris-wilson.co.uk>
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "sna.h"
+#include "sna_render.h"
+#include "sna_reg.h"
+
+#include <sys/mman.h>
+
+#define PITCH(x, y) ALIGN((x)*(y), 4)
+
+#define FORCE_INPLACE 0 /* 1 upload directly, -1 force indirect */
+
+/* XXX Need to avoid using GTT fenced access for I915_TILING_Y on 855GM */
+
+static bool
+box_intersect(BoxPtr a, const BoxRec *b)
+{
+       if (a->x1 < b->x1)
+               a->x1 = b->x1;
+       if (a->x2 > b->x2)
+               a->x2 = b->x2;
+       if (a->y1 < b->y1)
+               a->y1 = b->y1;
+       if (a->y2 > b->y2)
+               a->y2 = b->y2;
+
+       return a->x1 < a->x2 && a->y1 < a->y2;
+}
+
+static inline bool upload_too_large(struct sna *sna, int width, int height)
+{
+       return width * height * 4 > sna->kgem.max_upload_tile_size;
+}
+
+static inline bool must_tile(struct sna *sna, int width, int height)
+{
+       return (width  > sna->render.max_3d_size ||
+               height > sna->render.max_3d_size ||
+               upload_too_large(sna, width, height));
+}
+
+static void read_boxes_inplace(struct kgem *kgem,
+                              struct kgem_bo *bo, int16_t src_dx, int16_t src_dy,
+                              PixmapPtr pixmap, int16_t dst_dx, int16_t dst_dy,
+                              const BoxRec *box, int n)
+{
+       int bpp = pixmap->drawable.bitsPerPixel;
+       void *src, *dst = pixmap->devPrivate.ptr;
+       int src_pitch = bo->pitch;
+       int dst_pitch = pixmap->devKind;
+
+       DBG(("%s x %d, tiling=%d\n", __FUNCTION__, n, bo->tiling));
+
+       if (!kgem_bo_can_map(kgem, bo))
+               return;
+
+       kgem_bo_submit(kgem, bo);
+
+       src = kgem_bo_map(kgem, bo);
+       if (src == NULL)
+               return;
+
+       do {
+               DBG(("%s: copying box (%d, %d), (%d, %d)\n",
+                    __FUNCTION__, box->x1, box->y1, box->x2, box->y2));
+
+               assert(box->x2 > box->x1);
+               assert(box->y2 > box->y1);
+
+               assert(box->x1 + src_dx >= 0);
+               assert(box->y1 + src_dy >= 0);
+               assert(box->x2 + src_dx <= pixmap->drawable.width);
+               assert(box->y2 + src_dy <= pixmap->drawable.height);
+
+               assert(box->x1 + dst_dx >= 0);
+               assert(box->y1 + dst_dy >= 0);
+               assert(box->x2 + dst_dx <= pixmap->drawable.width);
+               assert(box->y2 + dst_dy <= pixmap->drawable.height);
+
+               memcpy_blt(src, dst, bpp,
+                          src_pitch, dst_pitch,
+                          box->x1 + src_dx, box->y1 + src_dy,
+                          box->x1 + dst_dx, box->y1 + dst_dy,
+                          box->x2 - box->x1, box->y2 - box->y1);
+               box++;
+       } while (--n);
+}
+
+static bool download_inplace(struct kgem *kgem, struct kgem_bo *bo)
+{
+       if (!kgem_bo_can_map(kgem, bo))
+               return false;
+
+       if (FORCE_INPLACE)
+               return FORCE_INPLACE > 0;
+
+       return !__kgem_bo_is_busy(kgem, bo) || bo->tiling == I915_TILING_NONE;
+}
+
+void sna_read_boxes(struct sna *sna,
+                   struct kgem_bo *src_bo, int16_t src_dx, int16_t src_dy,
+                   PixmapPtr dst, int16_t dst_dx, int16_t dst_dy,
+                   const BoxRec *box, int nbox)
+{
+       struct kgem *kgem = &sna->kgem;
+       struct kgem_bo *dst_bo;
+       BoxRec extents;
+       const BoxRec *tmp_box;
+       int tmp_nbox;
+       char *src;
+       void *ptr;
+       int src_pitch, cpp, offset;
+       int n, cmd, br13;
+       bool can_blt;
+
+       DBG(("%s x %d, src=(handle=%d, offset=(%d,%d)), dst=(size=(%d, %d), offset=(%d,%d))\n",
+            __FUNCTION__, nbox, src_bo->handle, src_dx, src_dy,
+            dst->drawable.width, dst->drawable.height, dst_dx, dst_dy));
+
+#ifndef NDEBUG
+       for (n = 0; n < nbox; n++) {
+               if (box[n].x1 + src_dx < 0 || box[n].y1 + src_dy < 0 ||
+                   (box[n].x2 + src_dx) * dst->drawable.bitsPerPixel/8 > src_bo->pitch ||
+                   (box[n].y2 + src_dy) * src_bo->pitch > kgem_bo_size(src_bo))
+               {
+                       FatalError("source out-of-bounds box[%d]=(%d, %d), (%d, %d) + (%d, %d), pitch=%d, size=%d\n", n,
+                                  box[n].x1, box[n].y1,
+                                  box[n].x2, box[n].y2,
+                                  src_dx, src_dy,
+                                  src_bo->pitch, kgem_bo_size(src_bo));
+               }
+       }
+#endif
+
+       /* XXX The gpu is faster to perform detiling in bulk, but takes
+        * longer to setup and retrieve the results, with an additional
+        * copy. The long term solution is to use snoopable bo and avoid
+        * this path.
+        */
+
+       if (download_inplace(kgem, src_bo)) {
+fallback:
+               read_boxes_inplace(kgem,
+                                  src_bo, src_dx, src_dy,
+                                  dst, dst_dx, dst_dy,
+                                  box, nbox);
+               return;
+       }
+
+       can_blt = kgem_bo_can_blt(kgem, src_bo) &&
+               (box[0].x2 - box[0].x1) * dst->drawable.bitsPerPixel < 8 * (MAXSHORT - 4);
+       extents = box[0];
+       for (n = 1; n < nbox; n++) {
+               if (box[n].x1 < extents.x1)
+                       extents.x1 = box[n].x1;
+               if (box[n].x2 > extents.x2)
+                       extents.x2 = box[n].x2;
+
+               if (can_blt)
+                       can_blt = (box[n].x2 - box[n].x1) * dst->drawable.bitsPerPixel < 8 * (MAXSHORT - 4);
+
+               if (box[n].y1 < extents.y1)
+                       extents.y1 = box[n].y1;
+               if (box[n].y2 > extents.y2)
+                       extents.y2 = box[n].y2;
+       }
+       if (kgem_bo_is_mappable(kgem, src_bo)) {
+               /* Is it worth detiling? */
+               if ((extents.y2 - extents.y1 - 1) * src_bo->pitch < 4096)
+                       goto fallback;
+       }
+
+       /* Try to avoid switching rings... */
+       if (!can_blt || kgem->ring == KGEM_RENDER ||
+           upload_too_large(sna, extents.x2 - extents.x1, extents.y2 - extents.y1)) {
+               PixmapRec tmp;
+
+               tmp.drawable.width  = extents.x2 - extents.x1;
+               tmp.drawable.height = extents.y2 - extents.y1;
+               tmp.drawable.depth  = dst->drawable.depth;
+               tmp.drawable.bitsPerPixel = dst->drawable.bitsPerPixel;
+               tmp.devPrivate.ptr = NULL;
+
+               assert(tmp.drawable.width);
+               assert(tmp.drawable.height);
+
+               if (must_tile(sna, tmp.drawable.width, tmp.drawable.height)) {
+                       BoxRec tile, stack[64], *clipped, *c;
+                       int step;
+
+                       if (n > ARRAY_SIZE(stack)) {
+                               clipped = malloc(sizeof(BoxRec) * n);
+                               if (clipped == NULL)
+                                       goto fallback;
+                       } else
+                               clipped = stack;
+
+                       step = MIN(sna->render.max_3d_size,
+                                  8*(MAXSHORT&~63) / dst->drawable.bitsPerPixel);
+                       while (step * step * 4 > sna->kgem.max_upload_tile_size)
+                               step /= 2;
+
+                       DBG(("%s: tiling download, using %dx%d tiles\n",
+                            __FUNCTION__, step, step));
+
+                       for (tile.y1 = extents.y1; tile.y1 < extents.y2; tile.y1 = tile.y2) {
+                               tile.y2 = tile.y1 + step;
+                               if (tile.y2 > extents.y2)
+                                       tile.y2 = extents.y2;
+
+                               for (tile.x1 = extents.x1; tile.x1 < extents.x2; tile.x1 = tile.x2) {
+                                       tile.x2 = tile.x1 + step;
+                                       if (tile.x2 > extents.x2)
+                                               tile.x2 = extents.x2;
+
+                                       tmp.drawable.width  = tile.x2 - tile.x1;
+                                       tmp.drawable.height = tile.y2 - tile.y1;
+
+                                       c = clipped;
+                                       for (n = 0; n < nbox; n++) {
+                                               *c = box[n];
+                                               if (!box_intersect(c, &tile))
+                                                       continue;
+
+                                               DBG(("%s: box(%d, %d), (%d, %d), src=(%d, %d), dst=(%d, %d)\n",
+                                                    __FUNCTION__,
+                                                    c->x1, c->y1,
+                                                    c->x2, c->y2,
+                                                    src_dx, src_dy,
+                                                    c->x1 - tile.x1,
+                                                    c->y1 - tile.y1));
+                                               c++;
+                                       }
+                                       if (c == clipped)
+                                               continue;
+
+                                       dst_bo = kgem_create_buffer_2d(kgem,
+                                                                      tmp.drawable.width,
+                                                                      tmp.drawable.height,
+                                                                      tmp.drawable.bitsPerPixel,
+                                                                      KGEM_BUFFER_LAST,
+                                                                      &ptr);
+                                       if (!dst_bo) {
+                                               if (clipped != stack)
+                                                       free(clipped);
+                                               goto fallback;
+                                       }
+
+                                       if (!sna->render.copy_boxes(sna, GXcopy,
+                                                                   dst, src_bo, src_dx, src_dy,
+                                                                   &tmp, dst_bo, -tile.x1, -tile.y1,
+                                                                   clipped, c-clipped, COPY_LAST)) {
+                                               kgem_bo_destroy(&sna->kgem, dst_bo);
+                                               if (clipped != stack)
+                                                       free(clipped);
+                                               goto fallback;
+                                       }
+
+                                       kgem_bo_submit(&sna->kgem, dst_bo);
+                                       kgem_buffer_read_sync(kgem, dst_bo);
+
+                                       while (c-- != clipped) {
+                                               memcpy_blt(ptr, dst->devPrivate.ptr, tmp.drawable.bitsPerPixel,
+                                                          dst_bo->pitch, dst->devKind,
+                                                          c->x1 - tile.x1,
+                                                          c->y1 - tile.y1,
+                                                          c->x1 + dst_dx,
+                                                          c->y1 + dst_dy,
+                                                          c->x2 - c->x1,
+                                                          c->y2 - c->y1);
+                                       }
+
+                                       kgem_bo_destroy(&sna->kgem, dst_bo);
+                               }
+                       }
+
+                       if (clipped != stack)
+                               free(clipped);
+               } else {
+                       dst_bo = kgem_create_buffer_2d(kgem,
+                                                      tmp.drawable.width,
+                                                      tmp.drawable.height,
+                                                      tmp.drawable.bitsPerPixel,
+                                                      KGEM_BUFFER_LAST,
+                                                      &ptr);
+                       if (!dst_bo)
+                               goto fallback;
+
+                       if (!sna->render.copy_boxes(sna, GXcopy,
+                                                   dst, src_bo, src_dx, src_dy,
+                                                   &tmp, dst_bo, -extents.x1, -extents.y1,
+                                                   box, nbox, COPY_LAST)) {
+                               kgem_bo_destroy(&sna->kgem, dst_bo);
+                               goto fallback;
+                       }
+
+                       kgem_bo_submit(&sna->kgem, dst_bo);
+                       kgem_buffer_read_sync(kgem, dst_bo);
+
+                       for (n = 0; n < nbox; n++) {
+                               memcpy_blt(ptr, dst->devPrivate.ptr, tmp.drawable.bitsPerPixel,
+                                          dst_bo->pitch, dst->devKind,
+                                          box[n].x1 - extents.x1,
+                                          box[n].y1 - extents.y1,
+                                          box[n].x1 + dst_dx,
+                                          box[n].y1 + dst_dy,
+                                          box[n].x2 - box[n].x1,
+                                          box[n].y2 - box[n].y1);
+                       }
+
+                       kgem_bo_destroy(&sna->kgem, dst_bo);
+               }
+               return;
+       }
+
+       /* count the total number of bytes to be read and allocate a bo */
+       cpp = dst->drawable.bitsPerPixel / 8;
+       offset = 0;
+       for (n = 0; n < nbox; n++) {
+               int height = box[n].y2 - box[n].y1;
+               int width = box[n].x2 - box[n].x1;
+               offset += PITCH(width, cpp) * height;
+       }
+
+       DBG(("    read buffer size=%d\n", offset));
+
+       dst_bo = kgem_create_buffer(kgem, offset, KGEM_BUFFER_LAST, &ptr);
+       if (!dst_bo) {
+               read_boxes_inplace(kgem,
+                                  src_bo, src_dx, src_dy,
+                                  dst, dst_dx, dst_dy,
+                                  box, nbox);
+               return;
+       }
+
+       cmd = XY_SRC_COPY_BLT_CMD;
+       src_pitch = src_bo->pitch;
+       if (kgem->gen >= 40 && src_bo->tiling) {
+               cmd |= BLT_SRC_TILED;
+               src_pitch >>= 2;
+       }
+
+       br13 = 0xcc << 16;
+       switch (cpp) {
+       default:
+       case 4: cmd |= BLT_WRITE_ALPHA | BLT_WRITE_RGB;
+               br13 |= 1 << 25; /* RGB8888 */
+       case 2: br13 |= 1 << 24; /* RGB565 */
+       case 1: break;
+       }
+
+       kgem_set_mode(kgem, KGEM_BLT);
+       if (kgem->nexec + 2 > KGEM_EXEC_SIZE(kgem) ||
+           kgem->nreloc + 2 > KGEM_RELOC_SIZE(kgem) ||
+           !kgem_check_batch(kgem, 8) ||
+           !kgem_check_many_bo_fenced(kgem, dst_bo, src_bo, NULL)) {
+               _kgem_submit(kgem);
+               _kgem_set_mode(kgem, KGEM_BLT);
+       }
+
+       tmp_nbox = nbox;
+       tmp_box = box;
+       offset = 0;
+       do {
+               int nbox_this_time;
+
+               nbox_this_time = tmp_nbox;
+               if (8*nbox_this_time > kgem->surface - kgem->nbatch - KGEM_BATCH_RESERVED)
+                       nbox_this_time = (kgem->surface - kgem->nbatch - KGEM_BATCH_RESERVED) / 8;
+               if (2*nbox_this_time > KGEM_RELOC_SIZE(kgem) - kgem->nreloc)
+                       nbox_this_time = (KGEM_RELOC_SIZE(kgem) - kgem->nreloc) / 2;
+               assert(nbox_this_time);
+               tmp_nbox -= nbox_this_time;
+
+               for (n = 0; n < nbox_this_time; n++) {
+                       int height = tmp_box[n].y2 - tmp_box[n].y1;
+                       int width = tmp_box[n].x2 - tmp_box[n].x1;
+                       int pitch = PITCH(width, cpp);
+                       uint32_t *b = kgem->batch + kgem->nbatch;
+
+                       DBG(("    blt offset %x: (%d, %d) x (%d, %d), pitch=%d\n",
+                            offset,
+                            tmp_box[n].x1 + src_dx,
+                            tmp_box[n].y1 + src_dy,
+                            width, height, pitch));
+
+                       assert(tmp_box[n].x1 + src_dx >= 0);
+                       assert((tmp_box[n].x2 + src_dx) * dst->drawable.bitsPerPixel/8 <= src_bo->pitch);
+                       assert(tmp_box[n].y1 + src_dy >= 0);
+                       assert((tmp_box[n].y2 + src_dy) * src_bo->pitch <= kgem_bo_size(src_bo));
+
+                       b[0] = cmd;
+                       b[1] = br13 | pitch;
+                       b[2] = 0;
+                       b[3] = height << 16 | width;
+                       b[4] = kgem_add_reloc(kgem, kgem->nbatch + 4, dst_bo,
+                                             I915_GEM_DOMAIN_RENDER << 16 |
+                                             I915_GEM_DOMAIN_RENDER |
+                                             KGEM_RELOC_FENCED,
+                                             offset);
+                       b[5] = (tmp_box[n].y1 + src_dy) << 16 | (tmp_box[n].x1 + src_dx);
+                       b[6] = src_pitch;
+                       b[7] = kgem_add_reloc(kgem, kgem->nbatch + 7, src_bo,
+                                             I915_GEM_DOMAIN_RENDER << 16 |
+                                             KGEM_RELOC_FENCED,
+                                             0);
+                       kgem->nbatch += 8;
+
+                       offset += pitch * height;
+               }
+
+               _kgem_submit(kgem);
+               if (!tmp_nbox)
+                       break;
+
+               _kgem_set_mode(kgem, KGEM_BLT);
+               tmp_box += nbox_this_time;
+       } while (1);
+       assert(offset == __kgem_buffer_size(dst_bo));
+
+       kgem_buffer_read_sync(kgem, dst_bo);
+
+       src = ptr;
+       do {
+               int height = box->y2 - box->y1;
+               int width  = box->x2 - box->x1;
+               int pitch = PITCH(width, cpp);
+
+               DBG(("    copy offset %lx [%08x...%08x...%08x]: (%d, %d) x (%d, %d), src pitch=%d, dst pitch=%d, bpp=%d\n",
+                    (long)((char *)src - (char *)ptr),
+                    *(uint32_t*)src, *(uint32_t*)(src+pitch*height/2 + pitch/2 - 4), *(uint32_t*)(src+pitch*height - 4),
+                    box->x1 + dst_dx,
+                    box->y1 + dst_dy,
+                    width, height,
+                    pitch, dst->devKind, cpp*8));
+
+               assert(box->x1 + dst_dx >= 0);
+               assert(box->x2 + dst_dx <= dst->drawable.width);
+               assert(box->y1 + dst_dy >= 0);
+               assert(box->y2 + dst_dy <= dst->drawable.height);
+
+               memcpy_blt(src, dst->devPrivate.ptr, cpp*8,
+                          pitch, dst->devKind,
+                          0, 0,
+                          box->x1 + dst_dx, box->y1 + dst_dy,
+                          width, height);
+               box++;
+
+               src += pitch * height;
+       } while (--nbox);
+       assert(src - (char *)ptr == __kgem_buffer_size(dst_bo));
+       kgem_bo_destroy(kgem, dst_bo);
+       sna->blt_state.fill_bo = 0;
+}
+
+static bool upload_inplace__tiled(struct kgem *kgem, struct kgem_bo *bo)
+{
+       if (kgem->gen < 50) /* bit17 swizzling :( */
+               return false;
+
+       if (bo->tiling != I915_TILING_X)
+               return false;
+
+       if (bo->scanout)
+               return false;
+
+       return bo->domain == DOMAIN_CPU || kgem->has_llc;
+}
+
+static bool
+write_boxes_inplace__tiled(struct kgem *kgem,
+                           const uint8_t *src, int stride, int bpp, int16_t src_dx, int16_t src_dy,
+                           struct kgem_bo *bo, int16_t dst_dx, int16_t dst_dy,
+                           const BoxRec *box, int n)
+{
+       uint8_t *dst;
+       int swizzle;
+
+       assert(bo->tiling == I915_TILING_X);
+
+       dst = __kgem_bo_map__cpu(kgem, bo);
+       if (dst == NULL)
+               return false;
+
+       kgem_bo_sync__cpu(kgem, bo);
+       swizzle = kgem_bo_get_swizzling(kgem, bo);
+       do {
+               memcpy_to_tiled_x(src, dst, bpp, swizzle, stride, bo->pitch,
+                                 box->x1 + src_dx, box->y1 + src_dy,
+                                 box->x1 + dst_dx, box->y1 + dst_dy,
+                                 box->x2 - box->x1, box->y2 - box->y1);
+               box++;
+       } while (--n);
+       __kgem_bo_unmap__cpu(kgem, bo, dst);
+
+       return true;
+}
+
+static bool write_boxes_inplace(struct kgem *kgem,
+                               const void *src, int stride, int bpp, int16_t src_dx, int16_t src_dy,
+                               struct kgem_bo *bo, int16_t dst_dx, int16_t dst_dy,
+                               const BoxRec *box, int n)
+{
+       void *dst;
+
+       DBG(("%s x %d, handle=%d, tiling=%d\n",
+            __FUNCTION__, n, bo->handle, bo->tiling));
+
+       if (upload_inplace__tiled(kgem, bo) &&
+           write_boxes_inplace__tiled(kgem, src, stride, bpp, src_dx, src_dy,
+                                      bo, dst_dx, dst_dy, box, n))
+               return true;
+
+       if (!kgem_bo_can_map(kgem, bo))
+               return false;
+
+       kgem_bo_submit(kgem, bo);
+
+       dst = kgem_bo_map(kgem, bo);
+       if (dst == NULL)
+               return false;
+
+       assert(dst != src);
+
+       do {
+               DBG(("%s: (%d, %d) -> (%d, %d) x (%d, %d) [bpp=%d, src_pitch=%d, dst_pitch=%d]\n", __FUNCTION__,
+                    box->x1 + src_dx, box->y1 + src_dy,
+                    box->x1 + dst_dx, box->y1 + dst_dy,
+                    box->x2 - box->x1, box->y2 - box->y1,
+                    bpp, stride, bo->pitch));
+
+               assert(box->x2 > box->x1);
+               assert(box->y2 > box->y1);
+
+               assert(box->x1 + dst_dx >= 0);
+               assert((box->x2 + dst_dx)*bpp <= 8*bo->pitch);
+               assert(box->y1 + dst_dy >= 0);
+               assert((box->y2 + dst_dy)*bo->pitch <= kgem_bo_size(bo));
+
+               assert(box->x1 + src_dx >= 0);
+               assert((box->x2 + src_dx)*bpp <= 8*stride);
+               assert(box->y1 + src_dy >= 0);
+
+               memcpy_blt(src, dst, bpp,
+                          stride, bo->pitch,
+                          box->x1 + src_dx, box->y1 + src_dy,
+                          box->x1 + dst_dx, box->y1 + dst_dy,
+                          box->x2 - box->x1, box->y2 - box->y1);
+               box++;
+       } while (--n);
+       return true;
+}
+
+static bool upload_inplace(struct kgem *kgem,
+                          struct kgem_bo *bo,
+                          const BoxRec *box,
+                          int n, int bpp)
+{
+       unsigned int bytes;
+
+       if (kgem->wedged)
+               return true;
+
+       if (!kgem_bo_can_map(kgem, bo) && !upload_inplace__tiled(kgem, bo))
+               return false;
+
+       if (FORCE_INPLACE)
+               return FORCE_INPLACE > 0;
+
+       /* If we are writing through the GTT, check first if we might be
+        * able to almagamate a series of small writes into a single
+        * operation.
+        */
+       bytes = 0;
+       while (n--) {
+               bytes += (box->x2 - box->x1) * (box->y2 - box->y1);
+               box++;
+       }
+       if (__kgem_bo_is_busy(kgem, bo))
+               return bytes * bpp >> 12 >= kgem->half_cpu_cache_pages;
+       else
+               return bytes * bpp >> 12;
+}
+
+bool sna_write_boxes(struct sna *sna, PixmapPtr dst,
+                    struct kgem_bo * const dst_bo, int16_t const dst_dx, int16_t const dst_dy,
+                    const void * const src, int const stride, int16_t const src_dx, int16_t const src_dy,
+                    const BoxRec *box, int nbox)
+{
+       struct kgem *kgem = &sna->kgem;
+       struct kgem_bo *src_bo;
+       BoxRec extents;
+       void *ptr;
+       int offset;
+       int n, cmd, br13;
+       bool can_blt;
+
+       DBG(("%s x %d, src stride=%d,  src dx=(%d, %d)\n", __FUNCTION__, nbox, stride, src_dx, src_dy));
+
+       if (upload_inplace(kgem, dst_bo, box, nbox, dst->drawable.bitsPerPixel)) {
+fallback:
+               return write_boxes_inplace(kgem,
+                                          src, stride, dst->drawable.bitsPerPixel, src_dx, src_dy,
+                                          dst_bo, dst_dx, dst_dy,
+                                          box, nbox);
+       }
+
+       can_blt = kgem_bo_can_blt(kgem, dst_bo) &&
+               (box[0].x2 - box[0].x1) * dst->drawable.bitsPerPixel < 8 * (MAXSHORT - 4);
+       extents = box[0];
+       for (n = 1; n < nbox; n++) {
+               if (box[n].x1 < extents.x1)
+                       extents.x1 = box[n].x1;
+               if (box[n].x2 > extents.x2)
+                       extents.x2 = box[n].x2;
+
+               if (can_blt)
+                       can_blt = (box[n].x2 - box[n].x1) * dst->drawable.bitsPerPixel < 8 * (MAXSHORT - 4);
+
+               if (box[n].y1 < extents.y1)
+                       extents.y1 = box[n].y1;
+               if (box[n].y2 > extents.y2)
+                       extents.y2 = box[n].y2;
+       }
+
+       /* Try to avoid switching rings... */
+       if (!can_blt || kgem->ring == KGEM_RENDER ||
+           upload_too_large(sna, extents.x2 - extents.x1, extents.y2 - extents.y1)) {
+               PixmapRec tmp;
+
+               tmp.drawable.width  = extents.x2 - extents.x1;
+               tmp.drawable.height = extents.y2 - extents.y1;
+               tmp.drawable.depth  = dst->drawable.depth;
+               tmp.drawable.bitsPerPixel = dst->drawable.bitsPerPixel;
+               tmp.devPrivate.ptr = NULL;
+
+               assert(tmp.drawable.width);
+               assert(tmp.drawable.height);
+
+               DBG(("%s: upload (%d, %d)x(%d, %d), max %dx%d\n",
+                    __FUNCTION__,
+                    extents.x1, extents.y1,
+                    tmp.drawable.width, tmp.drawable.height,
+                    sna->render.max_3d_size, sna->render.max_3d_size));
+               if (must_tile(sna, tmp.drawable.width, tmp.drawable.height)) {
+                       BoxRec tile, stack[64], *clipped, *c;
+                       int step;
+
+tile:
+                       step = MIN(sna->render.max_3d_size - 4096 / dst->drawable.bitsPerPixel,
+                                  8*(MAXSHORT&~63) / dst->drawable.bitsPerPixel);
+                       while (step * step * 4 > sna->kgem.max_upload_tile_size)
+                               step /= 2;
+
+                       DBG(("%s: tiling upload, using %dx%d tiles\n",
+                            __FUNCTION__, step, step));
+
+                       if (n > ARRAY_SIZE(stack)) {
+                               clipped = malloc(sizeof(BoxRec) * n);
+                               if (clipped == NULL)
+                                       goto fallback;
+                       } else
+                               clipped = stack;
+
+                       for (tile.y1 = extents.y1; tile.y1 < extents.y2; tile.y1 = tile.y2) {
+                               tile.y2 = tile.y1 + step;
+                               if (tile.y2 > extents.y2)
+                                       tile.y2 = extents.y2;
+
+                               for (tile.x1 = extents.x1; tile.x1 < extents.x2; tile.x1 = tile.x2) {
+                                       tile.x2 = tile.x1 + step;
+                                       if (tile.x2 > extents.x2)
+                                               tile.x2 = extents.x2;
+
+                                       tmp.drawable.width  = tile.x2 - tile.x1;
+                                       tmp.drawable.height = tile.y2 - tile.y1;
+
+                                       src_bo = kgem_create_buffer_2d(kgem,
+                                                                      tmp.drawable.width,
+                                                                      tmp.drawable.height,
+                                                                      tmp.drawable.bitsPerPixel,
+                                                                      KGEM_BUFFER_WRITE_INPLACE,
+                                                                      &ptr);
+                                       if (!src_bo) {
+                                               if (clipped != stack)
+                                                       free(clipped);
+                                               goto fallback;
+                                       }
+
+                                       c = clipped;
+                                       for (n = 0; n < nbox; n++) {
+                                               *c = box[n];
+                                               if (!box_intersect(c, &tile))
+                                                       continue;
+
+                                               DBG(("%s: box(%d, %d), (%d, %d), src=(%d, %d), dst=(%d, %d)\n",
+                                                    __FUNCTION__,
+                                                    c->x1, c->y1,
+                                                    c->x2, c->y2,
+                                                    src_dx, src_dy,
+                                                    c->x1 - tile.x1,
+                                                    c->y1 - tile.y1));
+                                               memcpy_blt(src, ptr, tmp.drawable.bitsPerPixel,
+                                                          stride, src_bo->pitch,
+                                                          c->x1 + src_dx,
+                                                          c->y1 + src_dy,
+                                                          c->x1 - tile.x1,
+                                                          c->y1 - tile.y1,
+                                                          c->x2 - c->x1,
+                                                          c->y2 - c->y1);
+                                               c++;
+                                       }
+
+                                       if (c != clipped)
+                                               n = sna->render.copy_boxes(sna, GXcopy,
+                                                                          &tmp, src_bo, -tile.x1, -tile.y1,
+                                                                          dst, dst_bo, dst_dx, dst_dy,
+                                                                          clipped, c - clipped, 0);
+                                       else
+                                               n = 1;
+
+                                       kgem_bo_destroy(&sna->kgem, src_bo);
+
+                                       if (!n) {
+                                               if (clipped != stack)
+                                                       free(clipped);
+                                               goto fallback;
+                                       }
+                               }
+                       }
+
+                       if (clipped != stack)
+                               free(clipped);
+               } else {
+                       src_bo = kgem_create_buffer_2d(kgem,
+                                                      tmp.drawable.width,
+                                                      tmp.drawable.height,
+                                                      tmp.drawable.bitsPerPixel,
+                                                      KGEM_BUFFER_WRITE_INPLACE,
+                                                      &ptr);
+                       if (!src_bo)
+                               goto fallback;
+
+                       for (n = 0; n < nbox; n++) {
+                               DBG(("%s: box(%d, %d), (%d, %d), src=(%d, %d), dst=(%d, %d)\n",
+                                    __FUNCTION__,
+                                    box[n].x1, box[n].y1,
+                                    box[n].x2, box[n].y2,
+                                    src_dx, src_dy,
+                                    box[n].x1 - extents.x1,
+                                    box[n].y1 - extents.y1));
+                               memcpy_blt(src, ptr, tmp.drawable.bitsPerPixel,
+                                          stride, src_bo->pitch,
+                                          box[n].x1 + src_dx,
+                                          box[n].y1 + src_dy,
+                                          box[n].x1 - extents.x1,
+                                          box[n].y1 - extents.y1,
+                                          box[n].x2 - box[n].x1,
+                                          box[n].y2 - box[n].y1);
+                       }
+
+                       n = sna->render.copy_boxes(sna, GXcopy,
+                                                  &tmp, src_bo, -extents.x1, -extents.y1,
+                                                  dst, dst_bo, dst_dx, dst_dy,
+                                                  box, nbox, 0);
+
+                       kgem_bo_destroy(&sna->kgem, src_bo);
+
+                       if (!n)
+                               goto tile;
+               }
+
+               return true;
+       }
+
+       cmd = XY_SRC_COPY_BLT_CMD;
+       br13 = dst_bo->pitch;
+       if (kgem->gen >= 40 && dst_bo->tiling) {
+               cmd |= BLT_DST_TILED;
+               br13 >>= 2;
+       }
+       br13 |= 0xcc << 16;
+       switch (dst->drawable.bitsPerPixel) {
+       default:
+       case 32: cmd |= BLT_WRITE_ALPHA | BLT_WRITE_RGB;
+                br13 |= 1 << 25; /* RGB8888 */
+       case 16: br13 |= 1 << 24; /* RGB565 */
+       case 8: break;
+       }
+
+       kgem_set_mode(kgem, KGEM_BLT);
+       if (!kgem_check_batch(kgem, 8) ||
+           !kgem_check_reloc_and_exec(kgem, 2) ||
+           !kgem_check_bo_fenced(kgem, dst_bo)) {
+               _kgem_submit(kgem);
+               _kgem_set_mode(kgem, KGEM_BLT);
+       }
+
+       do {
+               int nbox_this_time;
+
+               nbox_this_time = nbox;
+               if (8*nbox_this_time > kgem->surface - kgem->nbatch - KGEM_BATCH_RESERVED)
+                       nbox_this_time = (kgem->surface - kgem->nbatch - KGEM_BATCH_RESERVED) / 8;
+               if (2*nbox_this_time > KGEM_RELOC_SIZE(kgem) - kgem->nreloc)
+                       nbox_this_time = (KGEM_RELOC_SIZE(kgem) - kgem->nreloc) / 2;
+               assert(nbox_this_time);
+               nbox -= nbox_this_time;
+
+               /* Count the total number of bytes to be read and allocate a
+                * single buffer large enough. Or if it is very small, combine
+                * with other allocations. */
+               offset = 0;
+               for (n = 0; n < nbox_this_time; n++) {
+                       int height = box[n].y2 - box[n].y1;
+                       int width = box[n].x2 - box[n].x1;
+                       offset += PITCH(width, dst->drawable.bitsPerPixel >> 3) * height;
+               }
+
+               src_bo = kgem_create_buffer(kgem, offset,
+                                           KGEM_BUFFER_WRITE_INPLACE | (nbox ? KGEM_BUFFER_LAST : 0),
+                                           &ptr);
+               if (!src_bo)
+                       break;
+
+               offset = 0;
+               do {
+                       int height = box->y2 - box->y1;
+                       int width = box->x2 - box->x1;
+                       int pitch = PITCH(width, dst->drawable.bitsPerPixel >> 3);
+                       uint32_t *b;
+
+                       DBG(("  %s: box src=(%d, %d), dst=(%d, %d) size=(%d, %d), dst offset=%d, dst pitch=%d\n",
+                            __FUNCTION__,
+                            box->x1 + src_dx, box->y1 + src_dy,
+                            box->x1 + dst_dx, box->y1 + dst_dy,
+                            width, height,
+                            offset, pitch));
+
+                       assert(box->x1 + src_dx >= 0);
+                       assert((box->x2 + src_dx)*dst->drawable.bitsPerPixel <= 8*stride);
+                       assert(box->y1 + src_dy >= 0);
+
+                       assert(box->x1 + dst_dx >= 0);
+                       assert(box->y1 + dst_dy >= 0);
+
+                       memcpy_blt(src, (char *)ptr + offset,
+                                  dst->drawable.bitsPerPixel,
+                                  stride, pitch,
+                                  box->x1 + src_dx, box->y1 + src_dy,
+                                  0, 0,
+                                  width, height);
+
+                       b = kgem->batch + kgem->nbatch;
+                       b[0] = cmd;
+                       b[1] = br13;
+                       b[2] = (box->y1 + dst_dy) << 16 | (box->x1 + dst_dx);
+                       b[3] = (box->y2 + dst_dy) << 16 | (box->x2 + dst_dx);
+                       b[4] = kgem_add_reloc(kgem, kgem->nbatch + 4, dst_bo,
+                                             I915_GEM_DOMAIN_RENDER << 16 |
+                                             I915_GEM_DOMAIN_RENDER |
+                                             KGEM_RELOC_FENCED,
+                                             0);
+                       b[5] = 0;
+                       b[6] = pitch;
+                       b[7] = kgem_add_reloc(kgem, kgem->nbatch + 7, src_bo,
+                                             I915_GEM_DOMAIN_RENDER << 16 |
+                                             KGEM_RELOC_FENCED,
+                                             offset);
+                       kgem->nbatch += 8;
+
+                       box++;
+                       offset += pitch * height;
+               } while (--nbox_this_time);
+               assert(offset == __kgem_buffer_size(src_bo));
+
+               if (nbox) {
+                       _kgem_submit(kgem);
+                       _kgem_set_mode(kgem, KGEM_BLT);
+               }
+
+               kgem_bo_destroy(kgem, src_bo);
+       } while (nbox);
+
+       sna->blt_state.fill_bo = 0;
+       return true;
+}
+
+static void
+write_boxes_inplace__xor(struct kgem *kgem,
+                        const void *src, int stride, int bpp, int16_t src_dx, int16_t src_dy,
+                        struct kgem_bo *bo, int16_t dst_dx, int16_t dst_dy,
+                        const BoxRec *box, int n,
+                        uint32_t and, uint32_t or)
+{
+       void *dst;
+
+       DBG(("%s x %d, tiling=%d\n", __FUNCTION__, n, bo->tiling));
+
+       kgem_bo_submit(kgem, bo);
+
+       dst = kgem_bo_map(kgem, bo);
+       if (dst == NULL)
+               return;
+
+       do {
+               DBG(("%s: (%d, %d) -> (%d, %d) x (%d, %d) [bpp=%d, src_pitch=%d, dst_pitch=%d]\n", __FUNCTION__,
+                    box->x1 + src_dx, box->y1 + src_dy,
+                    box->x1 + dst_dx, box->y1 + dst_dy,
+                    box->x2 - box->x1, box->y2 - box->y1,
+                    bpp, stride, bo->pitch));
+
+               assert(box->x2 > box->x1);
+               assert(box->y2 > box->y1);
+
+               assert(box->x1 + dst_dx >= 0);
+               assert((box->x2 + dst_dx)*bpp <= 8*bo->pitch);
+               assert(box->y1 + dst_dy >= 0);
+               assert((box->y2 + dst_dy)*bo->pitch <= kgem_bo_size(bo));
+
+               assert(box->x1 + src_dx >= 0);
+               assert((box->x2 + src_dx)*bpp <= 8*stride);
+               assert(box->y1 + src_dy >= 0);
+
+               memcpy_xor(src, dst, bpp,
+                          stride, bo->pitch,
+                          box->x1 + src_dx, box->y1 + src_dy,
+                          box->x1 + dst_dx, box->y1 + dst_dy,
+                          box->x2 - box->x1, box->y2 - box->y1,
+                          and, or);
+               box++;
+       } while (--n);
+}
+
+void sna_write_boxes__xor(struct sna *sna, PixmapPtr dst,
+                         struct kgem_bo *dst_bo, int16_t dst_dx, int16_t dst_dy,
+                         const void *src, int stride, int16_t src_dx, int16_t src_dy,
+                         const BoxRec *box, int nbox,
+                         uint32_t and, uint32_t or)
+{
+       struct kgem *kgem = &sna->kgem;
+       struct kgem_bo *src_bo;
+       BoxRec extents;
+       bool can_blt;
+       void *ptr;
+       int offset;
+       int n, cmd, br13;
+
+       DBG(("%s x %d\n", __FUNCTION__, nbox));
+
+       if (upload_inplace(kgem, dst_bo, box, nbox, dst->drawable.bitsPerPixel)) {
+fallback:
+               write_boxes_inplace__xor(kgem,
+                                        src, stride, dst->drawable.bitsPerPixel, src_dx, src_dy,
+                                        dst_bo, dst_dx, dst_dy,
+                                        box, nbox,
+                                        and, or);
+               return;
+       }
+
+       can_blt = kgem_bo_can_blt(kgem, dst_bo) &&
+               (box[0].x2 - box[0].x1) * dst->drawable.bitsPerPixel < 8 * (MAXSHORT - 4);
+       extents = box[0];
+       for (n = 1; n < nbox; n++) {
+               if (box[n].x1 < extents.x1)
+                       extents.x1 = box[n].x1;
+               if (box[n].x2 > extents.x2)
+                       extents.x2 = box[n].x2;
+
+               if (can_blt)
+                       can_blt = (box[n].x2 - box[n].x1) * dst->drawable.bitsPerPixel < 8 * (MAXSHORT - 4);
+
+               if (box[n].y1 < extents.y1)
+                       extents.y1 = box[n].y1;
+               if (box[n].y2 > extents.y2)
+                       extents.y2 = box[n].y2;
+       }
+
+       /* Try to avoid switching rings... */
+       if (!can_blt || kgem->ring == KGEM_RENDER ||
+           upload_too_large(sna, extents.x2 - extents.x1, extents.y2 - extents.y1)) {
+               PixmapRec tmp;
+
+               tmp.drawable.width  = extents.x2 - extents.x1;
+               tmp.drawable.height = extents.y2 - extents.y1;
+               tmp.drawable.depth  = dst->drawable.depth;
+               tmp.drawable.bitsPerPixel = dst->drawable.bitsPerPixel;
+               tmp.devPrivate.ptr = NULL;
+
+               assert(tmp.drawable.width);
+               assert(tmp.drawable.height);
+
+               DBG(("%s: upload (%d, %d)x(%d, %d), max %dx%d\n",
+                    __FUNCTION__,
+                    extents.x1, extents.y1,
+                    tmp.drawable.width, tmp.drawable.height,
+                    sna->render.max_3d_size, sna->render.max_3d_size));
+               if (must_tile(sna, tmp.drawable.width, tmp.drawable.height)) {
+                       BoxRec tile, stack[64], *clipped, *c;
+                       int step;
+
+tile:
+                       step = MIN(sna->render.max_3d_size - 4096 / dst->drawable.bitsPerPixel,
+                                  8*(MAXSHORT&~63) / dst->drawable.bitsPerPixel);
+                       while (step * step * 4 > sna->kgem.max_upload_tile_size)
+                               step /= 2;
+
+                       DBG(("%s: tiling upload, using %dx%d tiles\n",
+                            __FUNCTION__, step, step));
+
+                       if (n > ARRAY_SIZE(stack)) {
+                               clipped = malloc(sizeof(BoxRec) * n);
+                               if (clipped == NULL)
+                                       goto fallback;
+                       } else
+                               clipped = stack;
+
+                       for (tile.y1 = extents.y1; tile.y1 < extents.y2; tile.y1 = tile.y2) {
+                               tile.y2 = tile.y1 + step;
+                               if (tile.y2 > extents.y2)
+                                       tile.y2 = extents.y2;
+
+                               for (tile.x1 = extents.x1; tile.x1 < extents.x2; tile.x1 = tile.x2) {
+                                       tile.x2 = tile.x1 + step;
+                                       if (tile.x2 > extents.x2)
+                                               tile.x2 = extents.x2;
+
+                                       tmp.drawable.width  = tile.x2 - tile.x1;
+                                       tmp.drawable.height = tile.y2 - tile.y1;
+
+                                       src_bo = kgem_create_buffer_2d(kgem,
+                                                                      tmp.drawable.width,
+                                                                      tmp.drawable.height,
+                                                                      tmp.drawable.bitsPerPixel,
+                                                                      KGEM_BUFFER_WRITE_INPLACE,
+                                                                      &ptr);
+                                       if (!src_bo) {
+                                               if (clipped != stack)
+                                                       free(clipped);
+                                               goto fallback;
+                                       }
+
+                                       c = clipped;
+                                       for (n = 0; n < nbox; n++) {
+                                               *c = box[n];
+                                               if (!box_intersect(c, &tile))
+                                                       continue;
+
+                                               DBG(("%s: box(%d, %d), (%d, %d), src=(%d, %d), dst=(%d, %d)\n",
+                                                    __FUNCTION__,
+                                                    c->x1, c->y1,
+                                                    c->x2, c->y2,
+                                                    src_dx, src_dy,
+                                                    c->x1 - tile.x1,
+                                                    c->y1 - tile.y1));
+                                               memcpy_xor(src, ptr, tmp.drawable.bitsPerPixel,
+                                                          stride, src_bo->pitch,
+                                                          c->x1 + src_dx,
+                                                          c->y1 + src_dy,
+                                                          c->x1 - tile.x1,
+                                                          c->y1 - tile.y1,
+                                                          c->x2 - c->x1,
+                                                          c->y2 - c->y1,
+                                                          and, or);
+                                               c++;
+                                       }
+
+                                       if (c != clipped)
+                                               n = sna->render.copy_boxes(sna, GXcopy,
+                                                                          &tmp, src_bo, -tile.x1, -tile.y1,
+                                                                          dst, dst_bo, dst_dx, dst_dy,
+                                                                          clipped, c - clipped, 0);
+                                       else
+                                               n = 1;
+
+                                       kgem_bo_destroy(&sna->kgem, src_bo);
+
+                                       if (!n) {
+                                               if (clipped != stack)
+                                                       free(clipped);
+                                               goto fallback;
+                                       }
+                               }
+                       }
+
+                       if (clipped != stack)
+                               free(clipped);
+               } else {
+                       src_bo = kgem_create_buffer_2d(kgem,
+                                                      tmp.drawable.width,
+                                                      tmp.drawable.height,
+                                                      tmp.drawable.bitsPerPixel,
+                                                      KGEM_BUFFER_WRITE_INPLACE,
+                                                      &ptr);
+                       if (!src_bo)
+                               goto fallback;
+
+                       for (n = 0; n < nbox; n++) {
+                               DBG(("%s: box(%d, %d), (%d, %d), src=(%d, %d), dst=(%d, %d)\n",
+                                    __FUNCTION__,
+                                    box[n].x1, box[n].y1,
+                                    box[n].x2, box[n].y2,
+                                    src_dx, src_dy,
+                                    box[n].x1 - extents.x1,
+                                    box[n].y1 - extents.y1));
+                               memcpy_xor(src, ptr, tmp.drawable.bitsPerPixel,
+                                          stride, src_bo->pitch,
+                                          box[n].x1 + src_dx,
+                                          box[n].y1 + src_dy,
+                                          box[n].x1 - extents.x1,
+                                          box[n].y1 - extents.y1,
+                                          box[n].x2 - box[n].x1,
+                                          box[n].y2 - box[n].y1,
+                                          and, or);
+                       }
+
+                       n = sna->render.copy_boxes(sna, GXcopy,
+                                                  &tmp, src_bo, -extents.x1, -extents.y1,
+                                                  dst, dst_bo, dst_dx, dst_dy,
+                                                  box, nbox, 0);
+
+                       kgem_bo_destroy(&sna->kgem, src_bo);
+
+                       if (!n)
+                               goto tile;
+               }
+
+               return;
+       }
+
+       cmd = XY_SRC_COPY_BLT_CMD;
+       br13 = dst_bo->pitch;
+       if (kgem->gen >= 40 && dst_bo->tiling) {
+               cmd |= BLT_DST_TILED;
+               br13 >>= 2;
+       }
+       br13 |= 0xcc << 16;
+       switch (dst->drawable.bitsPerPixel) {
+       default:
+       case 32: cmd |= BLT_WRITE_ALPHA | BLT_WRITE_RGB;
+                br13 |= 1 << 25; /* RGB8888 */
+       case 16: br13 |= 1 << 24; /* RGB565 */
+       case 8: break;
+       }
+
+       kgem_set_mode(kgem, KGEM_BLT);
+       if (kgem->nexec + 2 > KGEM_EXEC_SIZE(kgem) ||
+           kgem->nreloc + 2 > KGEM_RELOC_SIZE(kgem) ||
+           !kgem_check_batch(kgem, 8) ||
+           !kgem_check_bo_fenced(kgem, dst_bo)) {
+               _kgem_submit(kgem);
+               _kgem_set_mode(kgem, KGEM_BLT);
+       }
+
+       do {
+               int nbox_this_time;
+
+               nbox_this_time = nbox;
+               if (8*nbox_this_time > kgem->surface - kgem->nbatch - KGEM_BATCH_RESERVED)
+                       nbox_this_time = (kgem->surface - kgem->nbatch - KGEM_BATCH_RESERVED) / 8;
+               if (2*nbox_this_time > KGEM_RELOC_SIZE(kgem) - kgem->nreloc)
+                       nbox_this_time = (KGEM_RELOC_SIZE(kgem) - kgem->nreloc) / 2;
+               assert(nbox_this_time);
+               nbox -= nbox_this_time;
+
+               /* Count the total number of bytes to be read and allocate a
+                * single buffer large enough. Or if it is very small, combine
+                * with other allocations. */
+               offset = 0;
+               for (n = 0; n < nbox_this_time; n++) {
+                       int height = box[n].y2 - box[n].y1;
+                       int width = box[n].x2 - box[n].x1;
+                       offset += PITCH(width, dst->drawable.bitsPerPixel >> 3) * height;
+               }
+
+               src_bo = kgem_create_buffer(kgem, offset,
+                                           KGEM_BUFFER_WRITE_INPLACE | (nbox ? KGEM_BUFFER_LAST : 0),
+                                           &ptr);
+               if (!src_bo)
+                       break;
+
+               offset = 0;
+               do {
+                       int height = box->y2 - box->y1;
+                       int width = box->x2 - box->x1;
+                       int pitch = PITCH(width, dst->drawable.bitsPerPixel >> 3);
+                       uint32_t *b;
+
+                       DBG(("  %s: box src=(%d, %d), dst=(%d, %d) size=(%d, %d), dst offset=%d, dst pitch=%d\n",
+                            __FUNCTION__,
+                            box->x1 + src_dx, box->y1 + src_dy,
+                            box->x1 + dst_dx, box->y1 + dst_dy,
+                            width, height,
+                            offset, pitch));
+
+                       assert(box->x1 + src_dx >= 0);
+                       assert((box->x2 + src_dx)*dst->drawable.bitsPerPixel <= 8*stride);
+                       assert(box->y1 + src_dy >= 0);
+
+                       assert(box->x1 + dst_dx >= 0);
+                       assert(box->y1 + dst_dy >= 0);
+
+                       memcpy_xor(src, (char *)ptr + offset,
+                                  dst->drawable.bitsPerPixel,
+                                  stride, pitch,
+                                  box->x1 + src_dx, box->y1 + src_dy,
+                                  0, 0,
+                                  width, height,
+                                  and, or);
+
+                       b = kgem->batch + kgem->nbatch;
+                       b[0] = cmd;
+                       b[1] = br13;
+                       b[2] = (box->y1 + dst_dy) << 16 | (box->x1 + dst_dx);
+                       b[3] = (box->y2 + dst_dy) << 16 | (box->x2 + dst_dx);
+                       b[4] = kgem_add_reloc(kgem, kgem->nbatch + 4, dst_bo,
+                                             I915_GEM_DOMAIN_RENDER << 16 |
+                                             I915_GEM_DOMAIN_RENDER |
+                                             KGEM_RELOC_FENCED,
+                                             0);
+                       b[5] = 0;
+                       b[6] = pitch;
+                       b[7] = kgem_add_reloc(kgem, kgem->nbatch + 7, src_bo,
+                                             I915_GEM_DOMAIN_RENDER << 16 |
+                                             KGEM_RELOC_FENCED,
+                                             offset);
+                       kgem->nbatch += 8;
+
+                       box++;
+                       offset += pitch * height;
+               } while (--nbox_this_time);
+               assert(offset == __kgem_buffer_size(src_bo));
+
+               if (nbox) {
+                       _kgem_submit(kgem);
+                       _kgem_set_mode(kgem, KGEM_BLT);
+               }
+
+               kgem_bo_destroy(kgem, src_bo);
+       } while (nbox);
+
+       sna->blt_state.fill_bo = 0;
+}
+
+static bool
+indirect_replace(struct sna *sna,
+                PixmapPtr pixmap,
+                struct kgem_bo *bo,
+                const void *src, int stride)
+{
+       struct kgem *kgem = &sna->kgem;
+       struct kgem_bo *src_bo;
+       BoxRec box;
+       void *ptr;
+       bool ret;
+
+       DBG(("%s: size=%d vs %d\n",
+            __FUNCTION__,
+            (int)pixmap->devKind * pixmap->drawable.height >> 12,
+            kgem->half_cpu_cache_pages));
+
+       if ((int)pixmap->devKind * pixmap->drawable.height >> 12 > kgem->half_cpu_cache_pages)
+               return false;
+
+       if (!kgem_bo_can_blt(kgem, bo) &&
+           must_tile(sna, pixmap->drawable.width, pixmap->drawable.height))
+               return false;
+
+       src_bo = kgem_create_buffer_2d(kgem,
+                                      pixmap->drawable.width,
+                                      pixmap->drawable.height,
+                                      pixmap->drawable.bitsPerPixel,
+                                      KGEM_BUFFER_WRITE_INPLACE,
+                                      &ptr);
+       if (!src_bo)
+               return false;
+
+       memcpy_blt(src, ptr, pixmap->drawable.bitsPerPixel,
+                  stride, src_bo->pitch,
+                  0, 0,
+                  0, 0,
+                  pixmap->drawable.width,
+                  pixmap->drawable.height);
+
+       box.x1 = box.y1 = 0;
+       box.x2 = pixmap->drawable.width;
+       box.y2 = pixmap->drawable.height;
+
+       ret = sna->render.copy_boxes(sna, GXcopy,
+                                    pixmap, src_bo, 0, 0,
+                                    pixmap, bo, 0, 0,
+                                    &box, 1, 0);
+
+       kgem_bo_destroy(kgem, src_bo);
+
+       return ret;
+}
+
+bool sna_replace(struct sna *sna,
+                PixmapPtr pixmap,
+                struct kgem_bo **_bo,
+                const void *src, int stride)
+{
+       struct kgem_bo *bo = *_bo;
+       struct kgem *kgem = &sna->kgem;
+       bool busy;
+       void *dst;
+
+       busy = __kgem_bo_is_busy(kgem, bo);
+       DBG(("%s(handle=%d, %dx%d, bpp=%d, tiling=%d) busy?=%d\n",
+            __FUNCTION__, bo->handle,
+            pixmap->drawable.width,
+            pixmap->drawable.height,
+            pixmap->drawable.bitsPerPixel,
+            bo->tiling, busy));
+
+       if (!busy && upload_inplace__tiled(kgem, bo)) {
+               BoxRec box;
+
+               box.x1 = box.y1 = 0;
+               box.x2 = pixmap->drawable.width;
+               box.y2 = pixmap->drawable.height;
+
+               if (write_boxes_inplace__tiled(kgem, src,
+                                              stride, pixmap->drawable.bitsPerPixel, 0, 0,
+                                              bo, 0, 0, &box, 1))
+                       return true;
+       }
+
+       if ((busy || !kgem_bo_can_map(kgem, bo)) &&
+           indirect_replace(sna, pixmap, bo, src, stride))
+               return true;
+
+       if (busy) {
+               struct kgem_bo *new_bo;
+
+               new_bo = kgem_create_2d(kgem,
+                                       pixmap->drawable.width,
+                                       pixmap->drawable.height,
+                                       pixmap->drawable.bitsPerPixel,
+                                       bo->tiling,
+                                       CREATE_GTT_MAP | CREATE_INACTIVE);
+               if (new_bo)
+                       bo = new_bo;
+       }
+
+       if (bo->tiling == I915_TILING_NONE && bo->pitch == stride) {
+               if (!kgem_bo_write(kgem, bo, src,
+                                  (pixmap->drawable.height-1)*stride + pixmap->drawable.width*pixmap->drawable.bitsPerPixel/8))
+                       goto err;
+       } else {
+               if (upload_inplace__tiled(kgem, bo)) {
+                       BoxRec box;
+
+                       box.x1 = box.y1 = 0;
+                       box.x2 = pixmap->drawable.width;
+                       box.y2 = pixmap->drawable.height;
+
+                       if (write_boxes_inplace__tiled(kgem, src,
+                                                      stride, pixmap->drawable.bitsPerPixel, 0, 0,
+                                                      bo, 0, 0, &box, 1))
+                               goto done;
+               }
+
+               if (kgem_bo_is_mappable(kgem, bo)) {
+                       dst = kgem_bo_map(kgem, bo);
+                       if (!dst)
+                               goto err;
+
+                       memcpy_blt(src, dst, pixmap->drawable.bitsPerPixel,
+                                  stride, bo->pitch,
+                                  0, 0,
+                                  0, 0,
+                                  pixmap->drawable.width,
+                                  pixmap->drawable.height);
+               } else {
+                       BoxRec box;
+
+                       box.x1 = box.y1 = 0;
+                       box.x2 = pixmap->drawable.width;
+                       box.y2 = pixmap->drawable.height;
+
+                       if (!sna_write_boxes(sna, pixmap,
+                                            bo, 0, 0,
+                                            src, stride, 0, 0,
+                                            &box, 1))
+                               goto err;
+               }
+       }
+
+done:
+       if (bo != *_bo)
+               kgem_bo_destroy(kgem, *_bo);
+       *_bo = bo;
+       return true;
+
+err:
+       if (bo != *_bo)
+               kgem_bo_destroy(kgem, bo);
+       return false;
+}
+
+struct kgem_bo *sna_replace__xor(struct sna *sna,
+                                PixmapPtr pixmap,
+                                struct kgem_bo *bo,
+                                const void *src, int stride,
+                                uint32_t and, uint32_t or)
+{
+       struct kgem *kgem = &sna->kgem;
+       void *dst;
+
+       DBG(("%s(handle=%d, %dx%d, bpp=%d, tiling=%d)\n",
+            __FUNCTION__, bo->handle,
+            pixmap->drawable.width,
+            pixmap->drawable.height,
+            pixmap->drawable.bitsPerPixel,
+            bo->tiling));
+
+       if (kgem_bo_is_busy(bo)) {
+               struct kgem_bo *new_bo;
+
+               new_bo = kgem_create_2d(kgem,
+                                       pixmap->drawable.width,
+                                       pixmap->drawable.height,
+                                       pixmap->drawable.bitsPerPixel,
+                                       bo->tiling,
+                                       CREATE_GTT_MAP | CREATE_INACTIVE);
+               if (new_bo) {
+                       kgem_bo_destroy(kgem, bo);
+                       bo = new_bo;
+               }
+       }
+
+       if (kgem_bo_is_mappable(kgem, bo)) {
+               dst = kgem_bo_map(kgem, bo);
+               if (dst) {
+                       memcpy_xor(src, dst, pixmap->drawable.bitsPerPixel,
+                                  stride, bo->pitch,
+                                  0, 0,
+                                  0, 0,
+                                  pixmap->drawable.width,
+                                  pixmap->drawable.height,
+                                  and, or);
+               }
+       } else {
+               BoxRec box;
+
+               box.x1 = box.y1 = 0;
+               box.x2 = pixmap->drawable.width;
+               box.y2 = pixmap->drawable.height;
+
+               sna_write_boxes__xor(sna, pixmap,
+                                    bo, 0, 0,
+                                    src, stride, 0, 0,
+                                    &box, 1,
+                                    and, or);
+       }
+
+       return bo;
+}
diff --git a/src/sna/sna_module.h b/src/sna/sna_module.h
new file mode 100644 (file)
index 0000000..1b46cb7
--- /dev/null
@@ -0,0 +1 @@
+Bool sna_init_scrn(ScrnInfoPtr scrn, int entity_num);
diff --git a/src/sna/sna_reg.h b/src/sna/sna_reg.h
new file mode 100644 (file)
index 0000000..2628236
--- /dev/null
@@ -0,0 +1,82 @@
+#ifndef SNA_REG_H
+#define SNA_REG_H
+
+/* Flush */
+#define MI_FLUSH                       (0x04<<23)
+#define MI_FLUSH_DW                    (0x26<<23)
+
+#define MI_WRITE_DIRTY_STATE           (1<<4)
+#define MI_END_SCENE                   (1<<3)
+#define MI_GLOBAL_SNAPSHOT_COUNT_RESET (1<<3)
+#define MI_INHIBIT_RENDER_CACHE_FLUSH  (1<<2)
+#define MI_STATE_INSTRUCTION_CACHE_FLUSH (1<<1)
+#define MI_INVALIDATE_MAP_CACHE                (1<<0)
+/* broadwater flush bits */
+#define BRW_MI_GLOBAL_SNAPSHOT_RESET   (1 << 3)
+
+#define MI_BATCH_BUFFER_END    (0xA << 23)
+
+/* Noop */
+#define MI_NOOP                                0x00
+#define MI_NOOP_WRITE_ID               (1<<22)
+#define MI_NOOP_ID_MASK                        (1<<22 - 1)
+
+/* Wait for Events */
+#define MI_WAIT_FOR_EVENT                      (0x03<<23)
+#define MI_WAIT_FOR_PIPEB_SVBLANK              (1<<18)
+#define MI_WAIT_FOR_PIPEA_SVBLANK              (1<<17)
+#define MI_WAIT_FOR_OVERLAY_FLIP               (1<<16)
+#define MI_WAIT_FOR_PIPEB_VBLANK               (1<<7)
+#define MI_WAIT_FOR_PIPEB_SCAN_LINE_WINDOW     (1<<5)
+#define MI_WAIT_FOR_PIPEA_VBLANK               (1<<3)
+#define MI_WAIT_FOR_PIPEA_SCAN_LINE_WINDOW     (1<<1)
+
+/* Set the scan line for MI_WAIT_FOR_PIPE?_SCAN_LINE_WINDOW */
+#define MI_LOAD_SCAN_LINES_INCL                        (0x12<<23)
+#define MI_LOAD_SCAN_LINES_DISPLAY_PIPEA       (0)
+#define MI_LOAD_SCAN_LINES_DISPLAY_PIPEB       (0x1<<20)
+
+/* BLT commands */
+#define BLT_WRITE_ALPHA                (1<<21)
+#define BLT_WRITE_RGB          (1<<20)
+#define BLT_SRC_TILED          (1<<15)
+#define BLT_DST_TILED          (1<<11)
+
+#define COLOR_BLT_CMD                  ((2<<29)|(0x40<<22)|(0x3))
+#define XY_COLOR_BLT                   ((2<<29)|(0x50<<22)|(0x4))
+#define XY_SETUP_BLT                   ((2<<29)|(1<<22)|6)
+#define XY_SETUP_MONO_PATTERN_SL_BLT   ((2<<29)|(0x11<<22)|7)
+#define XY_SETUP_CLIP                  ((2<<29)|(3<<22)|1)
+#define XY_SCANLINE_BLT                        ((2<<29)|(0x25<<22)|1)
+#define XY_TEXT_IMMEDIATE_BLT          ((2<<29)|(0x31<<22)|(1<<16))
+#define XY_SRC_COPY_BLT_CMD            ((2<<29)|(0x53<<22)|6)
+#define SRC_COPY_BLT_CMD               ((2<<29)|(0x43<<22)|0x4)
+#define XY_PAT_BLT                     ((2<<29)|(0x51<<22)|0x4)
+#define XY_PAT_BLT_IMMEDIATE           ((2<<29)|(0x72<<22))
+#define XY_MONO_PAT                    ((0x2<<29)|(0x52<<22)|0x7)
+#define XY_MONO_SRC_COPY               ((0x2<<29)|(0x54<<22)|(0x6))
+#define XY_MONO_SRC_COPY_IMM           ((0x2<<29)|(0x71<<22))
+#define XY_FULL_MONO_PATTERN_BLT       ((0x2<<29)|(0x57<<22)|0xa)
+#define XY_FULL_MONO_PATTERN_MONO_SRC_BLT      ((0x2<<29)|(0x58<<22)|0xa)
+
+/* FLUSH commands */
+#define BRW_3D(Pipeline,Opcode,Subopcode) \
+       ((3 << 29) | \
+        ((Pipeline) << 27) | \
+        ((Opcode) << 24) | \
+        ((Subopcode) << 16))
+#define PIPE_CONTROL           BRW_3D(3, 2, 0)
+#define PIPE_CONTROL_NOWRITE       (0 << 14)
+#define PIPE_CONTROL_WRITE_QWORD   (1 << 14)
+#define PIPE_CONTROL_WRITE_DEPTH   (2 << 14)
+#define PIPE_CONTROL_WRITE_TIME    (3 << 14)
+#define PIPE_CONTROL_DEPTH_STALL   (1 << 13)
+#define PIPE_CONTROL_WC_FLUSH      (1 << 12)
+#define PIPE_CONTROL_IS_FLUSH      (1 << 11)
+#define PIPE_CONTROL_TC_FLUSH      (1 << 10)
+#define PIPE_CONTROL_NOTIFY_ENABLE (1 << 8)
+#define PIPE_CONTROL_GLOBAL_GTT    (1 << 2)
+#define PIPE_CONTROL_LOCAL_PGTT    (0 << 2)
+#define PIPE_CONTROL_DEPTH_CACHE_FLUSH (1 << 0)
+
+#endif
diff --git a/src/sna/sna_render.c b/src/sna/sna_render.c
new file mode 100644 (file)
index 0000000..5844922
--- /dev/null
@@ -0,0 +1,1960 @@
+/*
+ * Copyright © 2011 Intel 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.
+ *
+ * Authors:
+ *    Chris Wilson <chris@chris-wilson.co.uk>
+ *
+ */
+
+#include "sna.h"
+#include "sna_render.h"
+#include "sna_render_inline.h"
+#include "fb/fbpict.h"
+
+#define NO_REDIRECT 0
+#define NO_CONVERT 0
+#define NO_FIXUP 0
+#define NO_EXTRACT 0
+
+#define DBG_FORCE_UPLOAD 0
+#define DBG_NO_CPU_BO 0
+
+CARD32
+sna_format_for_depth(int depth)
+{
+       switch (depth) {
+       case 1: return PICT_a1;
+       case 4: return PICT_a4;
+       case 8: return PICT_a8;
+       case 15: return PICT_x1r5g5b5;
+       case 16: return PICT_r5g6b5;
+       default: assert(0);
+       case 24: return PICT_x8r8g8b8;
+       case 30: return PICT_x2r10g10b10;
+       case 32: return PICT_a8r8g8b8;
+       }
+}
+
+CARD32
+sna_render_format_for_depth(int depth)
+{
+       switch (depth) {
+       case 1: return PIXMAN_a1;
+       case 4: return PIXMAN_a4;
+       case 8: return PIXMAN_a8;
+       case 15: return PIXMAN_a1r5g5b5;
+       case 16: return PIXMAN_r5g6b5;
+       case 30: return PIXMAN_a2r10g10b10;
+       default: assert(0);
+       case 24:
+       case 32: return PIXMAN_a8r8g8b8;
+       }
+}
+
+static bool
+no_render_composite(struct sna *sna,
+                   uint8_t op,
+                   PicturePtr src,
+                   PicturePtr mask,
+                   PicturePtr dst,
+                   int16_t src_x, int16_t src_y,
+                   int16_t mask_x, int16_t mask_y,
+                   int16_t dst_x, int16_t dst_y,
+                   int16_t width, int16_t height,
+                   struct sna_composite_op *tmp)
+{
+       DBG(("%s (op=%d, mask? %d)\n", __FUNCTION__, op, mask != NULL));
+
+       if (mask)
+               return false;
+
+       if (!is_gpu(dst->pDrawable) &&
+           (src->pDrawable == NULL || !is_gpu(src->pDrawable)))
+               return false;
+
+       return sna_blt_composite(sna,
+                                op, src, dst,
+                                src_x, src_y,
+                                dst_x, dst_y,
+                                width, height,
+                                tmp, true);
+       (void)mask_x;
+       (void)mask_y;
+}
+
+static bool
+no_render_check_composite_spans(struct sna *sna,
+                               uint8_t op, PicturePtr src, PicturePtr dst,
+                               int16_t width,  int16_t height, unsigned flags)
+{
+       return false;
+}
+
+static bool
+no_render_copy_boxes(struct sna *sna, uint8_t alu,
+                    PixmapPtr src, struct kgem_bo *src_bo, int16_t src_dx, int16_t src_dy,
+                    PixmapPtr dst, struct kgem_bo *dst_bo, int16_t dst_dx, int16_t dst_dy,
+                    const BoxRec *box, int n, unsigned flags)
+{
+       DBG(("%s (n=%d)\n", __FUNCTION__, n));
+
+       if (!sna_blt_compare_depth(&src->drawable, &dst->drawable))
+               return false;
+
+       return sna_blt_copy_boxes(sna, alu,
+                                 src_bo, src_dx, src_dy,
+                                 dst_bo, dst_dx, dst_dy,
+                                 dst->drawable.bitsPerPixel,
+                                 box, n);
+}
+
+static bool
+no_render_copy(struct sna *sna, uint8_t alu,
+                PixmapPtr src, struct kgem_bo *src_bo,
+                PixmapPtr dst, struct kgem_bo *dst_bo,
+                struct sna_copy_op *tmp)
+{
+       DBG(("%s ()\n", __FUNCTION__));
+
+       if (sna_blt_compare_depth(&src->drawable, &dst->drawable) &&
+           sna_blt_copy(sna, alu,
+                        src_bo, dst_bo, dst->drawable.bitsPerPixel,
+                        tmp))
+               return true;
+
+       return false;
+}
+
+static bool
+no_render_fill_boxes(struct sna *sna,
+                    CARD8 op,
+                    PictFormat format,
+                    const xRenderColor *color,
+                    PixmapPtr dst, struct kgem_bo *dst_bo,
+                    const BoxRec *box, int n)
+{
+       uint8_t alu = GXcopy;
+       uint32_t pixel;
+
+       DBG(("%s (op=%d, color=(%04x,%04x,%04x, %04x))\n",
+            __FUNCTION__, op,
+            color->red, color->green, color->blue, color->alpha));
+
+       if (op == PictOpClear) {
+               pixel = 0;
+               alu = GXclear;
+               op = PictOpSrc;
+       }
+
+       if (op == PictOpOver) {
+               if ((color->alpha >= 0xff00))
+                       op = PictOpSrc;
+       }
+
+       if (op != PictOpSrc)
+               return false;
+
+       if (alu == GXcopy &&
+           !sna_get_pixel_from_rgba(&pixel,
+                                    color->red,
+                                    color->green,
+                                    color->blue,
+                                    color->alpha,
+                                    format))
+               return false;
+
+       return sna_blt_fill_boxes(sna, alu,
+                                 dst_bo, dst->drawable.bitsPerPixel,
+                                 pixel, box, n);
+}
+
+static bool
+no_render_fill(struct sna *sna, uint8_t alu,
+              PixmapPtr dst, struct kgem_bo *dst_bo,
+              uint32_t color,
+              struct sna_fill_op *tmp)
+{
+       DBG(("%s (alu=%d, color=%08x)\n", __FUNCTION__, alu, color));
+       return sna_blt_fill(sna, alu,
+                           dst_bo, dst->drawable.bitsPerPixel,
+                           color,
+                           tmp);
+}
+
+static bool
+no_render_fill_one(struct sna *sna, PixmapPtr dst, struct kgem_bo *bo,
+                  uint32_t color,
+                  int16_t x1, int16_t y1, int16_t x2, int16_t y2,
+                  uint8_t alu)
+{
+       BoxRec box;
+
+       box.x1 = x1;
+       box.y1 = y1;
+       box.x2 = x2;
+       box.y2 = y2;
+
+       DBG(("%s (alu=%d, color=%08x) (%d,%d), (%d, %d)\n",
+            __FUNCTION__, alu, color, x1, y1, x2, y2));
+       return sna_blt_fill_boxes(sna, alu,
+                                 bo, dst->drawable.bitsPerPixel,
+                                 color, &box, 1);
+}
+
+static bool
+no_render_clear(struct sna *sna, PixmapPtr dst, struct kgem_bo *bo)
+{
+       DBG(("%s: pixmap=%ld %dx%d\n", __FUNCTION__,
+            dst->drawable.serialNumber,
+            dst->drawable.width,
+            dst->drawable.height));
+       return sna->render.fill_one(sna, dst, bo, 0,
+                                   0, 0, dst->drawable.width, dst->drawable.height,
+                                   GXclear);
+}
+
+static void no_render_reset(struct sna *sna)
+{
+       (void)sna;
+}
+
+static void no_render_flush(struct sna *sna)
+{
+       (void)sna;
+}
+
+static void
+no_render_context_switch(struct kgem *kgem,
+                        int new_mode)
+{
+       if (!kgem->mode)
+               return;
+
+       if (kgem_is_idle(kgem)) {
+               DBG(("%s: GPU idle, flushing\n", __FUNCTION__));
+               _kgem_submit(kgem);
+       }
+
+       (void)kgem;
+       (void)new_mode;
+}
+
+static void
+no_render_retire(struct kgem *kgem)
+{
+       (void)kgem;
+}
+
+static void
+no_render_expire(struct kgem *kgem)
+{
+       (void)kgem;
+}
+
+static void
+no_render_fini(struct sna *sna)
+{
+       (void)sna;
+}
+
+void no_render_init(struct sna *sna)
+{
+       struct sna_render *render = &sna->render;
+
+       memset (render,0, sizeof (*render));
+
+       render->vertices = render->vertex_data;
+       render->vertex_size = ARRAY_SIZE(render->vertex_data);
+
+       render->composite = no_render_composite;
+       render->check_composite_spans = no_render_check_composite_spans;
+
+       render->copy_boxes = no_render_copy_boxes;
+       render->copy = no_render_copy;
+
+       render->fill_boxes = no_render_fill_boxes;
+       render->fill = no_render_fill;
+       render->fill_one = no_render_fill_one;
+       render->clear = no_render_clear;
+
+       render->reset = no_render_reset;
+       render->flush = no_render_flush;
+       render->fini = no_render_fini;
+
+       sna->kgem.context_switch = no_render_context_switch;
+       sna->kgem.retire = no_render_retire;
+       sna->kgem.expire = no_render_expire;
+       if (sna->kgem.has_blt)
+               sna->kgem.ring = KGEM_BLT;
+}
+
+static struct kgem_bo *
+use_cpu_bo(struct sna *sna, PixmapPtr pixmap, const BoxRec *box, bool blt)
+{
+       struct sna_pixmap *priv;
+
+       if (DBG_NO_CPU_BO)
+               return NULL;
+
+       priv = sna_pixmap(pixmap);
+       if (priv == NULL || priv->cpu_bo == NULL) {
+               DBG(("%s: no cpu bo\n", __FUNCTION__));
+               return NULL;
+       }
+
+       if (priv->cpu_bo->snoop && priv->source_count > SOURCE_BIAS) {
+               DBG(("%s: promoting snooped CPU bo due to reuse\n",
+                    __FUNCTION__));
+               return NULL;
+       }
+
+       if (priv->gpu_bo) {
+               switch (sna_damage_contains_box(priv->cpu_damage, box)) {
+               case PIXMAN_REGION_OUT:
+                       DBG(("%s: has GPU bo and no damage to upload\n",
+                            __FUNCTION__));
+                       return NULL;
+
+               case PIXMAN_REGION_IN:
+                       DBG(("%s: has GPU bo but box is completely on CPU\n",
+                            __FUNCTION__));
+                       break;
+               default:
+                       if (sna_damage_contains_box(priv->gpu_damage,
+                                                   box) != PIXMAN_REGION_OUT) {
+                               DBG(("%s: box is damaged on the GPU\n",
+                                    __FUNCTION__));
+                               return NULL;
+                       }
+                       break;
+               }
+       }
+
+       if (!blt) {
+               int w = box->x2 - box->x1;
+               int h = box->y2 - box->y1;
+
+               if (w < pixmap->drawable.width ||
+                   h < pixmap->drawable.height ||
+                   priv->source_count != SOURCE_BIAS) {
+                       bool want_tiling;
+
+                       if (priv->cpu_bo->pitch >= 4096) {
+                               DBG(("%s: size=%dx%d, promoting reused (%d) CPU bo due to TLB miss (%dx%d, pitch=%d)\n",
+                                    __FUNCTION__, w, h, priv->source_count,
+                                    pixmap->drawable.width,
+                                    pixmap->drawable.height,
+                                    priv->cpu_bo->pitch));
+                               return NULL;
+                       }
+
+                       if (priv->gpu_bo)
+                               want_tiling = priv->gpu_bo->tiling != I915_TILING_NONE;
+                       else
+                               want_tiling = kgem_choose_tiling(&sna->kgem,
+                                                                I915_TILING_Y,
+                                                                pixmap->drawable.width,
+                                                                pixmap->drawable.height,
+                                                                pixmap->drawable.bitsPerPixel) != I915_TILING_NONE;
+                       if (want_tiling &&
+                           priv->source_count*w*h >= (int)pixmap->drawable.width * pixmap->drawable.height) {
+                               DBG(("%s: pitch (%d) requires tiling\n",
+                                    __FUNCTION__, priv->cpu_bo->pitch));
+                               return NULL;
+                       }
+               }
+       }
+
+       if (priv->shm) {
+               assert(!priv->flush);
+               sna_add_flush_pixmap(sna, priv, priv->cpu_bo);
+       }
+
+       DBG(("%s for box=(%d, %d), (%d, %d)\n",
+            __FUNCTION__, box->x1, box->y1, box->x2, box->y2));
+       ++priv->source_count;
+       return priv->cpu_bo;
+}
+
+static struct kgem_bo *
+move_to_gpu(PixmapPtr pixmap, const BoxRec *box, bool blt)
+{
+       struct sna_pixmap *priv;
+       int count, w, h;
+       bool migrate = false;
+
+       if (DBG_FORCE_UPLOAD > 0)
+               return NULL;
+
+       priv = sna_pixmap(pixmap);
+       if (priv == NULL) {
+               DBG(("%s: not migrating unattached pixmap\n",
+                    __FUNCTION__));
+               return NULL;
+       }
+
+       if (priv->gpu_bo) {
+               if (priv->cpu_damage &&
+                   sna_damage_contains_box(priv->cpu_damage,
+                                           box) != PIXMAN_REGION_OUT) {
+                       if (!sna_pixmap_move_to_gpu(pixmap, MOVE_READ))
+                               return NULL;
+               }
+
+               return priv->gpu_bo;
+       }
+
+       if (pixmap->usage_hint) {
+               DBG(("%s: not migrating pixmap due to usage_hint=%d\n",
+                    __FUNCTION__, pixmap->usage_hint));
+               return NULL;
+       }
+
+       if (DBG_FORCE_UPLOAD < 0) {
+               if (!sna_pixmap_force_to_gpu(pixmap,
+                                            blt ? MOVE_READ : MOVE_SOURCE_HINT | MOVE_READ))
+                       return NULL;
+
+               return priv->gpu_bo;
+       }
+
+       w = box->x2 - box->x1;
+       h = box->y2 - box->y1;
+       if (w == pixmap->drawable.width && h == pixmap->drawable.height) {
+               migrate = priv->source_count++ > SOURCE_BIAS;
+
+               DBG(("%s: migrating whole pixmap (%dx%d) for source (%d,%d),(%d,%d), count %d? %d\n",
+                    __FUNCTION__,
+                    pixmap->drawable.width, pixmap->drawable.height,
+                    box->x1, box->y1, box->x2, box->y2, priv->source_count,
+                    migrate));
+       } else if (kgem_choose_tiling(&to_sna_from_pixmap(pixmap)->kgem,
+                                     blt ? I915_TILING_X : I915_TILING_Y, w, h,
+                                     pixmap->drawable.bitsPerPixel) != I915_TILING_NONE) {
+               count = priv->source_count++;
+               if ((priv->create & KGEM_CAN_CREATE_GPU) == 0)
+                       count -= SOURCE_BIAS;
+
+               DBG(("%s: migrate box (%d, %d), (%d, %d)? source count=%d, fraction=%d/%d [%d]\n",
+                    __FUNCTION__,
+                    box->x1, box->y1, box->x2, box->y2,
+                    count, w*h,
+                    pixmap->drawable.width * pixmap->drawable.height,
+                    pixmap->drawable.width * pixmap->drawable.height / (w*h)));
+
+               migrate = count*w*h > pixmap->drawable.width * pixmap->drawable.height;
+       }
+
+       if (migrate && !sna_pixmap_force_to_gpu(pixmap,
+                                               blt ? MOVE_READ : MOVE_SOURCE_HINT | MOVE_READ))
+               return NULL;
+
+       return priv->gpu_bo;
+}
+
+static struct kgem_bo *upload(struct sna *sna,
+                             struct sna_composite_channel *channel,
+                             PixmapPtr pixmap,
+                             BoxPtr box)
+{
+       struct sna_pixmap *priv;
+       struct kgem_bo *bo;
+
+       DBG(("%s: box=(%d, %d), (%d, %d), pixmap=%dx%d\n",
+            __FUNCTION__, box->x1, box->y1, box->x2, box->y2, pixmap->drawable.width, pixmap->drawable.height));
+       assert(box->x1 >= 0);
+       assert(box->y1 >= 0);
+       assert(box->x2 <= pixmap->drawable.width);
+       assert(box->y2 <= pixmap->drawable.height);
+
+       priv = sna_pixmap(pixmap);
+       if (priv) {
+               /* As we know this box is on the CPU just fixup the shadow */
+               if (priv->mapped) {
+                       pixmap->devPrivate.ptr = NULL;
+                       priv->mapped = false;
+               }
+               if (pixmap->devPrivate.ptr == NULL) {
+                       if (priv->ptr == NULL) /* uninitialised */
+                               return NULL;
+                       assert(priv->stride);
+                       pixmap->devPrivate.ptr = priv->ptr;
+                       pixmap->devKind = priv->stride;
+               }
+       }
+
+       bo = kgem_upload_source_image(&sna->kgem,
+                                     pixmap->devPrivate.ptr, box,
+                                     pixmap->devKind,
+                                     pixmap->drawable.bitsPerPixel);
+       if (channel && bo) {
+               channel->width  = box->x2 - box->x1;
+               channel->height = box->y2 - box->y1;
+               channel->offset[0] -= box->x1;
+               channel->offset[1] -= box->y1;
+
+               if (priv &&
+                   pixmap->usage_hint == 0 &&
+                   channel->width  == pixmap->drawable.width &&
+                   channel->height == pixmap->drawable.height)
+                       kgem_proxy_bo_attach(bo, &priv->gpu_bo);
+       }
+
+       return bo;
+}
+
+struct kgem_bo *
+__sna_render_pixmap_bo(struct sna *sna,
+                      PixmapPtr pixmap,
+                      const BoxRec *box,
+                      bool blt)
+{
+       struct kgem_bo *bo;
+
+       bo = use_cpu_bo(sna, pixmap, box, blt);
+       if (bo == NULL) {
+               bo = move_to_gpu(pixmap, box, blt);
+               if (bo == NULL)
+                       return NULL;
+       }
+
+       return bo;
+}
+
+int
+sna_render_pixmap_bo(struct sna *sna,
+                    struct sna_composite_channel *channel,
+                    PixmapPtr pixmap,
+                    int16_t x, int16_t y,
+                    int16_t w, int16_t h,
+                    int16_t dst_x, int16_t dst_y)
+{
+       struct sna_pixmap *priv;
+       BoxRec box;
+
+       DBG(("%s pixmap=%ld, (%d, %d)x(%d, %d)/(%d, %d)\n",
+            __FUNCTION__, pixmap->drawable.serialNumber,
+            x, y, w,h, pixmap->drawable.width, pixmap->drawable.height));
+
+       channel->width  = pixmap->drawable.width;
+       channel->height = pixmap->drawable.height;
+       channel->offset[0] = x - dst_x;
+       channel->offset[1] = y - dst_y;
+
+       priv = sna_pixmap(pixmap);
+       if (priv) {
+               if (priv->gpu_bo &&
+                   (DAMAGE_IS_ALL(priv->gpu_damage) || !priv->cpu_damage ||
+                    priv->gpu_bo->proxy)) {
+                       DBG(("%s: GPU all damaged\n", __FUNCTION__));
+                       channel->bo = priv->gpu_bo;
+                       goto done;
+               }
+
+               if (priv->cpu_bo &&
+                   (DAMAGE_IS_ALL(priv->cpu_damage) || !priv->gpu_damage) &&
+                   !priv->cpu_bo->snoop && priv->cpu_bo->pitch < 4096) {
+                       DBG(("%s: CPU all damaged\n", __FUNCTION__));
+                       channel->bo = priv->cpu_bo;
+                       goto done;
+               }
+       }
+
+       /* XXX handle transformed repeat */
+       if (w == 0 || h == 0 || channel->transform) {
+               box.x1 = box.y1 = 0;
+               box.x2 = pixmap->drawable.width;
+               box.y2 = pixmap->drawable.height;
+       } else {
+               box.x1 = x;
+               box.y1 = y;
+               box.x2 = x + w;
+               box.y2 = y + h;
+
+               if (channel->repeat == RepeatNone || channel->repeat == RepeatPad) {
+                       if (box.x1 < 0)
+                               box.x1 = 0;
+                       if (box.y1 < 0)
+                               box.y1 = 0;
+                       if (box.x2 > pixmap->drawable.width)
+                               box.x2 = pixmap->drawable.width;
+                       if (box.y2 > pixmap->drawable.height)
+                               box.y2 = pixmap->drawable.height;
+               } else {
+                       if (box.x1 < 0 || box.x2 > pixmap->drawable.width)
+                               box.x1 = 0, box.x2 = pixmap->drawable.width;
+                       if (box.y1 < 0 || box.y2 > pixmap->drawable.height)
+                               box.y1 = 0, box.y2 = pixmap->drawable.height;
+               }
+       }
+
+       w = box.x2 - box.x1;
+       h = box.y2 - box.y1;
+       DBG(("%s box=(%d, %d), (%d, %d): (%d, %d)/(%d, %d)\n", __FUNCTION__,
+            box.x1, box.y1, box.x2, box.y2, w, h,
+            pixmap->drawable.width, pixmap->drawable.height));
+       if (w <= 0 || h <= 0) {
+               DBG(("%s: sample extents outside of texture -> clear\n",
+                    __FUNCTION__));
+               return 0;
+       }
+
+       DBG(("%s: offset=(%d, %d), size=(%d, %d)\n",
+            __FUNCTION__,
+            channel->offset[0], channel->offset[1],
+            pixmap->drawable.width, pixmap->drawable.height));
+
+       channel->bo = __sna_render_pixmap_bo(sna, pixmap, &box, false);
+       if (channel->bo == NULL) {
+               DBG(("%s: uploading CPU box (%d, %d), (%d, %d)\n",
+                    __FUNCTION__, box.x1, box.y1, box.x2, box.y2));
+               channel->bo = upload(sna, channel, pixmap, &box);
+               if (channel->bo == NULL)
+                       return 0;
+       } else {
+done:
+               kgem_bo_reference(channel->bo);
+       }
+
+       channel->scale[0] = 1.f / channel->width;
+       channel->scale[1] = 1.f / channel->height;
+       return 1;
+}
+
+static int sna_render_picture_downsample(struct sna *sna,
+                                        PicturePtr picture,
+                                        struct sna_composite_channel *channel,
+                                        const int16_t x, const int16_t y,
+                                        const int16_t w, const int16_t h,
+                                        const int16_t dst_x, const int16_t dst_y)
+{
+       PixmapPtr pixmap = get_drawable_pixmap(picture->pDrawable);
+       ScreenPtr screen = pixmap->drawable.pScreen;
+       PicturePtr tmp_src, tmp_dst;
+       PictFormatPtr format;
+       struct sna_pixmap *priv;
+       pixman_transform_t t;
+       PixmapPtr tmp;
+       int width, height, size;
+       int sx, sy, sw, sh;
+       int error, ret = 0;
+       BoxRec box, b;
+
+       box.x1 = x;
+       box.y1 = y;
+       box.x2 = x + w;
+       box.y2 = y + h;
+       if (channel->transform) {
+               pixman_vector_t v;
+
+               pixman_transform_bounds(channel->transform, &box);
+
+               v.vector[0] = x << 16;
+               v.vector[1] = y << 16;
+               v.vector[2] = 1 << 16;
+               pixman_transform_point(channel->transform, &v);
+       }
+
+       if (channel->repeat == RepeatNone || channel->repeat == RepeatPad) {
+               if (box.x1 < 0)
+                       box.x1 = 0;
+               if (box.y1 < 0)
+                       box.y1 = 0;
+               if (box.x2 > pixmap->drawable.width)
+                       box.x2 = pixmap->drawable.width;
+               if (box.y2 > pixmap->drawable.height)
+                       box.y2 = pixmap->drawable.height;
+       } else {
+               /* XXX tiled repeats? */
+               if (box.x1 < 0 || box.x2 > pixmap->drawable.width)
+                       box.x1 = 0, box.x2 = pixmap->drawable.width;
+               if (box.y1 < 0 || box.y2 > pixmap->drawable.height)
+                       box.y1 = 0, box.y2 = pixmap->drawable.height;
+
+       }
+
+       sw = box.x2 - box.x1;
+       sh = box.y2 - box.y1;
+
+       DBG(("%s: sample (%d, %d), (%d, %d)\n",
+            __FUNCTION__, box.x1, box.y1, box.x2, box.y2));
+
+       sx = (sw + sna->render.max_3d_size - 1) / sna->render.max_3d_size;
+       sy = (sh + sna->render.max_3d_size - 1) / sna->render.max_3d_size;
+
+       DBG(("%s: scaling (%d, %d) down by %dx%d\n",
+            __FUNCTION__, sw, sh, sx, sy));
+
+       width  = sw / sx;
+       height = sh / sy;
+
+       DBG(("%s: creating temporary GPU bo %dx%d\n",
+            __FUNCTION__, width, height));
+
+       if (!sna_pixmap_force_to_gpu(pixmap, MOVE_SOURCE_HINT | MOVE_READ))
+               return sna_render_picture_fixup(sna, picture, channel,
+                                               x, y, w, h,
+                                               dst_x, dst_y);
+
+       tmp = screen->CreatePixmap(screen,
+                                  width, height,
+                                  pixmap->drawable.depth,
+                                  SNA_CREATE_SCRATCH);
+       if (!tmp)
+               return 0;
+
+       priv = sna_pixmap(tmp);
+       if (!priv)
+               goto cleanup_tmp;
+
+       format = PictureMatchFormat(screen,
+                                   pixmap->drawable.depth,
+                                   picture->format);
+
+       tmp_dst = CreatePicture(0, &tmp->drawable, format, 0, NULL,
+                               serverClient, &error);
+       if (!tmp_dst)
+               goto cleanup_tmp;
+
+       tmp_src = CreatePicture(0, &pixmap->drawable, format, 0, NULL,
+                               serverClient, &error);
+       if (!tmp_src)
+               goto cleanup_dst;
+
+       tmp_src->repeat = 1;
+       tmp_src->repeatType = RepeatPad;
+       /* Prefer to use nearest as it helps reduce artefacts from
+        * interpolating and filtering twice.
+        */
+       tmp_src->filter = PictFilterNearest;
+       memset(&t, 0, sizeof(t));
+       t.matrix[0][0] = (sw << 16) / width;
+       t.matrix[0][2] = box.x1 << 16;
+       t.matrix[1][1] = (sh << 16) / height;
+       t.matrix[1][2] = box.y1 << 16;
+       t.matrix[2][2] = 1 << 16;
+       tmp_src->transform = &t;
+
+       ValidatePicture(tmp_dst);
+       ValidatePicture(tmp_src);
+
+       /* Use a small size to accommodate enlargement through tile alignment */
+       size = sna->render.max_3d_size - 4096 / pixmap->drawable.bitsPerPixel;
+       while (size * size * 4 > sna->kgem.max_copy_tile_size)
+               size /= 2;
+
+       sw = size / sx - 2 * sx;
+       sh = size / sy - 2 * sy;
+       DBG(("%s %d:%d downsampling using %dx%d GPU tiles\n",
+            __FUNCTION__, (width + sw-1)/sw, (height + sh-1)/sh, sw, sh));
+
+       for (b.y1 = 0; b.y1 < height; b.y1 = b.y2) {
+               b.y2 = b.y1 + sh;
+               if (b.y2 > height)
+                       b.y2 = height;
+
+               for (b.x1 = 0; b.x1 < width; b.x1 = b.x2) {
+                       struct sna_composite_op op;
+
+                       b.x2 = b.x1 + sw;
+                       if (b.x2 > width)
+                               b.x2 = width;
+
+                       DBG(("%s: tile (%d, %d), (%d, %d)\n",
+                            __FUNCTION__, b.x1, b.y1, b.x2, b.y2));
+
+                       memset(&op, 0, sizeof(op));
+                       if (!sna->render.composite(sna,
+                                                  PictOpSrc,
+                                                  tmp_src, NULL, tmp_dst,
+                                                  b.x1, b.y1,
+                                                  0, 0,
+                                                  b.x1, b.y1,
+                                                  b.x2 - b.x1, b.y2 - b.y1,
+                                                  &op))
+                               goto cleanup_src;
+
+                       op.box(sna, &op, &b);
+                       op.done(sna, &op);
+               }
+       }
+
+       pixman_transform_invert(&channel->embedded_transform, &t);
+       if (channel->transform)
+               pixman_transform_multiply(&channel->embedded_transform,
+                                         &channel->embedded_transform,
+                                         channel->transform);
+       channel->transform = &channel->embedded_transform;
+
+       channel->offset[0] = x - dst_x;
+       channel->offset[1] = y - dst_y;
+       channel->scale[0] = 1.f/width;
+       channel->scale[1] = 1.f/height;
+       channel->width  = width;
+       channel->height = height;
+       channel->bo = kgem_bo_reference(priv->gpu_bo);
+
+       ret = 1;
+cleanup_src:
+       tmp_src->transform = NULL;
+       FreePicture(tmp_src, 0);
+cleanup_dst:
+       FreePicture(tmp_dst, 0);
+cleanup_tmp:
+       screen->DestroyPixmap(tmp);
+       return ret;
+}
+
+bool
+sna_render_pixmap_partial(struct sna *sna,
+                         PixmapPtr pixmap,
+                         struct kgem_bo *bo,
+                         struct sna_composite_channel *channel,
+                         int16_t x, int16_t y,
+                         int16_t w, int16_t h)
+{
+       BoxRec box;
+       int offset;
+
+       DBG(("%s (%d, %d)x(%d, %d), pitch %d, max %d\n",
+            __FUNCTION__, x, y, w, h, bo->pitch, sna->render.max_3d_pitch));
+
+       if (bo->pitch > sna->render.max_3d_pitch)
+               return false;
+
+       box.x1 = x;
+       box.y1 = y;
+       box.x2 = x + w;
+       box.y2 = y + h;
+       DBG(("%s: unaligned box (%d, %d), (%d, %d)\n",
+            __FUNCTION__, box.x1, box.y1, box.x2, box.y2));
+
+       if (box.x1 < 0)
+               box.x1 = 0;
+       if (box.y1 < 0)
+               box.y1 = 0;
+
+       if (bo->tiling) {
+               int tile_width, tile_height, tile_size;
+
+               kgem_get_tile_size(&sna->kgem, bo->tiling,
+                                  &tile_width, &tile_height, &tile_size);
+               DBG(("%s: tile size for tiling %d: %dx%d, size=%d\n",
+                    __FUNCTION__, bo->tiling, tile_width, tile_height, tile_size));
+
+               /* Ensure we align to an even tile row */
+               box.y1 = box.y1 & ~(2*tile_height - 1);
+               box.y2 = ALIGN(box.y2, 2*tile_height);
+
+               assert(tile_width * 8 >= pixmap->drawable.bitsPerPixel);
+               box.x1 = box.x1 & ~(tile_width * 8 / pixmap->drawable.bitsPerPixel - 1);
+               box.x2 = ALIGN(box.x2, tile_width * 8 / pixmap->drawable.bitsPerPixel);
+
+               offset = box.x1 * pixmap->drawable.bitsPerPixel / 8 / tile_width * tile_size;
+       } else {
+               box.y1 = box.y1 & ~1;
+               box.y2 = ALIGN(box.y2, 2);
+
+               box.x1 = box.x1 & ~1;
+               box.x2 = ALIGN(box.x2, 2);
+
+               offset = box.x1 * pixmap->drawable.bitsPerPixel / 8;
+       }
+
+       if (box.x2 > pixmap->drawable.width)
+               box.x2 = pixmap->drawable.width;
+       if (box.y2 > pixmap->drawable.height)
+               box.y2 = pixmap->drawable.height;
+
+       w = box.x2 - box.x1;
+       h = box.y2 - box.y1;
+       DBG(("%s box=(%d, %d), (%d, %d): (%d, %d)/(%d, %d)\n", __FUNCTION__,
+            box.x1, box.y1, box.x2, box.y2, w, h,
+            pixmap->drawable.width, pixmap->drawable.height));
+       if (w <= 0 || h <= 0 ||
+           w > sna->render.max_3d_size ||
+           h > sna->render.max_3d_size) {
+               DBG(("%s: box too large (%dx%d) for 3D pipeline (max %d)\n",
+                   __FUNCTION__, w, h, sna->render.max_3d_size));
+               return false;
+       }
+
+       /* How many tiles across are we? */
+       channel->bo = kgem_create_proxy(&sna->kgem, bo,
+                                       box.y1 * bo->pitch + offset,
+                                       h * bo->pitch);
+       if (channel->bo == NULL)
+               return false;
+
+       channel->bo->pitch = bo->pitch;
+
+       channel->offset[0] = -box.x1;
+       channel->offset[1] = -box.y1;
+       channel->scale[0] = 1.f/w;
+       channel->scale[1] = 1.f/h;
+       channel->width  = w;
+       channel->height = h;
+       return true;
+}
+
+static int
+sna_render_picture_partial(struct sna *sna,
+                          PicturePtr picture,
+                          struct sna_composite_channel *channel,
+                          int16_t x, int16_t y,
+                          int16_t w, int16_t h,
+                          int16_t dst_x, int16_t dst_y)
+{
+       struct kgem_bo *bo = NULL;
+       PixmapPtr pixmap = get_drawable_pixmap(picture->pDrawable);
+       BoxRec box;
+       int offset;
+
+       DBG(("%s (%d, %d)x(%d, %d) [dst=(%d, %d)]\n",
+            __FUNCTION__, x, y, w, h, dst_x, dst_y));
+
+       box.x1 = x;
+       box.y1 = y;
+       box.x2 = x + w;
+       box.y2 = y + h;
+       if (channel->transform)
+               pixman_transform_bounds(channel->transform, &box);
+
+       DBG(("%s sample=(%d, %d), (%d, %d): (%d, %d)/(%d, %d), repeat=%d\n", __FUNCTION__,
+            box.x1, box.y1, box.x2, box.y2, w, h,
+            pixmap->drawable.width, pixmap->drawable.height,
+            channel->repeat));
+
+       if (channel->repeat == RepeatNone || channel->repeat == RepeatPad) {
+               if (box.x1 < 0)
+                       box.x1 = 0;
+               if (box.y1 < 0)
+                       box.y1 = 0;
+               if (box.x2 > pixmap->drawable.width)
+                       box.x2 = pixmap->drawable.width;
+               if (box.y2 > pixmap->drawable.height)
+                       box.y2 = pixmap->drawable.height;
+       } else {
+               if (box.x1 < 0 || box.x2 > pixmap->drawable.width)
+                       box.x1 = 0, box.x2 = pixmap->drawable.width;
+               if (box.y1 < 0 || box.y2 > pixmap->drawable.height)
+                       box.y1 = 0, box.y2 = pixmap->drawable.height;
+       }
+
+       if (use_cpu_bo(sna, pixmap, &box, false)) {
+               bo = sna_pixmap(pixmap)->cpu_bo;
+       } else {
+               if (!sna_pixmap_force_to_gpu(pixmap,
+                                            MOVE_READ | MOVE_SOURCE_HINT))
+                       return 0;
+
+               bo = sna_pixmap(pixmap)->gpu_bo;
+       }
+
+       if (bo->pitch > sna->render.max_3d_pitch)
+               return 0;
+
+       if (bo->tiling) {
+               int tile_width, tile_height, tile_size;
+
+               kgem_get_tile_size(&sna->kgem, bo->tiling,
+                                  &tile_width, &tile_height, &tile_size);
+
+               DBG(("%s: tiling=%d, size=%dx%d, chunk=%d\n",
+                    __FUNCTION__, bo->tiling,
+                    tile_width, tile_height, tile_size));
+
+               /* Ensure we align to an even tile row */
+               box.y1 = box.y1 & ~(2*tile_height - 1);
+               box.y2 = ALIGN(box.y2, 2*tile_height);
+               if (box.y2 > pixmap->drawable.height)
+                       box.y2 = pixmap->drawable.height;
+
+               box.x1 = box.x1 & ~(tile_width * 8 / pixmap->drawable.bitsPerPixel - 1);
+               box.x2 = ALIGN(box.x2, tile_width * 8 / pixmap->drawable.bitsPerPixel);
+               if (box.x2 > pixmap->drawable.width)
+                       box.x2 = pixmap->drawable.width;
+
+               offset = box.x1 * pixmap->drawable.bitsPerPixel / 8 / tile_width * tile_size;
+       } else
+               offset = box.x1 * pixmap->drawable.bitsPerPixel / 8;
+
+       w = box.x2 - box.x1;
+       h = box.y2 - box.y1;
+       DBG(("%s box=(%d, %d), (%d, %d): (%d, %d)/(%d, %d)\n", __FUNCTION__,
+            box.x1, box.y1, box.x2, box.y2, w, h,
+            pixmap->drawable.width, pixmap->drawable.height));
+       if (w <= 0 || h <= 0 ||
+           w > sna->render.max_3d_size ||
+           h > sna->render.max_3d_size)
+               return 0;
+
+       /* How many tiles across are we? */
+       channel->bo = kgem_create_proxy(&sna->kgem, bo,
+                                       box.y1 * bo->pitch + offset,
+                                       h * bo->pitch);
+       if (channel->bo == NULL)
+               return 0;
+
+       if (channel->transform) {
+               memset(&channel->embedded_transform,
+                      0,
+                      sizeof(channel->embedded_transform));
+               channel->embedded_transform.matrix[0][0] = 1 << 16;
+               channel->embedded_transform.matrix[0][2] = -box.x1 << 16;
+               channel->embedded_transform.matrix[1][1] = 1 << 16;
+               channel->embedded_transform.matrix[1][2] = -box.y1 << 16;
+               channel->embedded_transform.matrix[2][2] = 1 << 16;
+               pixman_transform_multiply(&channel->embedded_transform,
+                                         &channel->embedded_transform,
+                                         channel->transform);
+               channel->transform = &channel->embedded_transform;
+       } else {
+               x -= box.x1;
+               y -= box.y1;
+       }
+
+       channel->offset[0] = x - dst_x;
+       channel->offset[1] = y - dst_y;
+       channel->scale[0] = 1.f/w;
+       channel->scale[1] = 1.f/h;
+       channel->width  = w;
+       channel->height = h;
+       return 1;
+}
+
+int
+sna_render_picture_extract(struct sna *sna,
+                          PicturePtr picture,
+                          struct sna_composite_channel *channel,
+                          int16_t x, int16_t y,
+                          int16_t w, int16_t h,
+                          int16_t dst_x, int16_t dst_y)
+{
+       struct kgem_bo *bo = NULL, *src_bo;
+       PixmapPtr pixmap = get_drawable_pixmap(picture->pDrawable);
+       int16_t ox, oy, ow, oh;
+       BoxRec box;
+
+#if NO_EXTRACT
+       return -1;
+#endif
+
+       DBG(("%s (%d, %d)x(%d, %d) [dst=(%d, %d)]\n",
+            __FUNCTION__, x, y, w, h, dst_x, dst_y));
+
+       if (w == 0 || h == 0) {
+               DBG(("%s: fallback -- unknown bounds\n", __FUNCTION__));
+               return -1;
+       }
+
+       if (sna_render_picture_partial(sna, picture, channel,
+                                      x, y, w, h,
+                                      dst_x, dst_y))
+               return 1;
+
+       ow = w;
+       oh = h;
+
+       ox = box.x1 = x;
+       oy = box.y1 = y;
+       box.x2 = x + w;
+       box.y2 = y + h;
+       if (channel->transform) {
+               pixman_vector_t v;
+
+               pixman_transform_bounds(channel->transform, &box);
+
+               v.vector[0] = ox << 16;
+               v.vector[1] = oy << 16;
+               v.vector[2] =  1 << 16;
+               pixman_transform_point(channel->transform, &v);
+               ox = v.vector[0] / v.vector[2];
+               oy = v.vector[1] / v.vector[2];
+       }
+
+       DBG(("%s sample=(%d, %d), (%d, %d): (%d, %d)/(%d, %d), repeat=%d\n", __FUNCTION__,
+            box.x1, box.y1, box.x2, box.y2, w, h,
+            pixmap->drawable.width, pixmap->drawable.height,
+            channel->repeat));
+
+       if (channel->repeat == RepeatNone || channel->repeat == RepeatPad) {
+               if (box.x1 < 0)
+                       box.x1 = 0;
+               if (box.y1 < 0)
+                       box.y1 = 0;
+               if (box.x2 > pixmap->drawable.width)
+                       box.x2 = pixmap->drawable.width;
+               if (box.y2 > pixmap->drawable.height)
+                       box.y2 = pixmap->drawable.height;
+       } else {
+               /* XXX tiled repeats? */
+               if (box.x1 < 0 || box.x2 > pixmap->drawable.width)
+                       box.x1 = 0, box.x2 = pixmap->drawable.width;
+               if (box.y1 < 0 || box.y2 > pixmap->drawable.height)
+                       box.y1 = 0, box.y2 = pixmap->drawable.height;
+       }
+
+       w = box.x2 - box.x1;
+       h = box.y2 - box.y1;
+       DBG(("%s box=(%d, %d), (%d, %d): (%d, %d)/(%d, %d)\n", __FUNCTION__,
+            box.x1, box.y1, box.x2, box.y2, w, h,
+            pixmap->drawable.width, pixmap->drawable.height));
+       if (w <= 0 || h <= 0) {
+               DBG(("%s: sample extents outside of texture -> clear\n",
+                    __FUNCTION__));
+               return 0;
+       }
+
+       if (w > sna->render.max_3d_size || h > sna->render.max_3d_size) {
+               DBG(("%s: fallback -- sample too large for texture (%d, %d)x(%d, %d)\n",
+                    __FUNCTION__, box.x1, box.y1, w, h));
+               return sna_render_picture_downsample(sna, picture, channel,
+                                                    x, y, ow, oh,
+                                                    dst_x, dst_y);
+       }
+
+       src_bo = use_cpu_bo(sna, pixmap, &box, true);
+       if (src_bo == NULL) {
+               src_bo = move_to_gpu(pixmap, &box, false);
+               if (src_bo == NULL) {
+                       bo = kgem_upload_source_image(&sna->kgem,
+                                                     pixmap->devPrivate.ptr,
+                                                     &box,
+                                                     pixmap->devKind,
+                                                     pixmap->drawable.bitsPerPixel);
+                       if (bo != NULL &&
+                           pixmap->usage_hint == 0 &&
+                           box.x2 - box.x1 == pixmap->drawable.width &&
+                           box.y2 - box.y1 == pixmap->drawable.height) {
+                               struct sna_pixmap *priv = sna_pixmap(pixmap);
+                               if (priv)
+                                       kgem_proxy_bo_attach(bo, &priv->gpu_bo);
+                       }
+               }
+       }
+       if (src_bo) {
+               bo = kgem_create_2d(&sna->kgem, w, h,
+                                   pixmap->drawable.bitsPerPixel,
+                                   kgem_choose_tiling(&sna->kgem,
+                                                      I915_TILING_X, w, h,
+                                                      pixmap->drawable.bitsPerPixel),
+                                   CREATE_TEMPORARY);
+               if (bo) {
+                       PixmapRec tmp;
+
+                       tmp.drawable.width  = w;
+                       tmp.drawable.height = h;
+                       tmp.drawable.depth  = pixmap->drawable.depth;
+                       tmp.drawable.bitsPerPixel = pixmap->drawable.bitsPerPixel;
+                       tmp.devPrivate.ptr = NULL;
+
+                       assert(tmp.drawable.width);
+                       assert(tmp.drawable.height);
+
+                       if (!sna->render.copy_boxes(sna, GXcopy,
+                                                   pixmap, src_bo, 0, 0,
+                                                   &tmp, bo, -box.x1, -box.y1,
+                                                   &box, 1, 0)) {
+                               kgem_bo_destroy(&sna->kgem, bo);
+                               bo = NULL;
+                       }
+               }
+       }
+
+       if (bo == NULL) {
+               DBG(("%s: falback -- pixmap is not on the GPU\n",
+                    __FUNCTION__));
+               return sna_render_picture_fixup(sna, picture, channel,
+                                               x, y, ow, oh, dst_x, dst_y);
+       }
+
+       if (ox == x && oy == y) {
+               x = y = 0;
+       } else if (channel->transform) {
+               pixman_vector_t v;
+               pixman_transform_t m;
+
+               v.vector[0] = (ox - box.x1) << 16;
+               v.vector[1] = (oy - box.y1) << 16;
+               v.vector[2] = 1 << 16;
+               pixman_transform_invert(&m, channel->transform);
+               pixman_transform_point(&m, &v);
+               x = v.vector[0] / v.vector[2];
+               y = v.vector[1] / v.vector[2];
+       } else {
+               x = ox - box.x1;
+               y = oy - box.y1;
+       }
+
+       channel->offset[0] = x - dst_x;
+       channel->offset[1] = y - dst_y;
+       channel->scale[0] = 1.f/w;
+       channel->scale[1] = 1.f/h;
+       channel->width  = w;
+       channel->height = h;
+       channel->bo = bo;
+       return 1;
+}
+
+static int
+sna_render_picture_convolve(struct sna *sna,
+                           PicturePtr picture,
+                           struct sna_composite_channel *channel,
+                           int16_t x, int16_t y,
+                           int16_t w, int16_t h,
+                           int16_t dst_x, int16_t dst_y)
+{
+       ScreenPtr screen = picture->pDrawable->pScreen;
+       PixmapPtr pixmap;
+       PicturePtr tmp;
+       pixman_fixed_t *params = picture->filter_params;
+       int x_off = -pixman_fixed_to_int((params[0] - pixman_fixed_1) >> 1);
+       int y_off = -pixman_fixed_to_int((params[1] - pixman_fixed_1) >> 1);
+       int cw = pixman_fixed_to_int(params[0]);
+       int ch = pixman_fixed_to_int(params[1]);
+       int i, j, error, depth;
+       struct kgem_bo *bo;
+
+       /* Lame multi-pass accumulation implementation of a general convolution
+        * that works everywhere.
+        */
+       DBG(("%s: origin=(%d,%d) kernel=%dx%d, size=%dx%d\n",
+            __FUNCTION__, x_off, y_off, cw, ch, w, h));
+
+       assert(picture->pDrawable);
+       assert(picture->filter == PictFilterConvolution);
+       assert(w <= sna->render.max_3d_size && h <= sna->render.max_3d_size);
+
+       if (PICT_FORMAT_RGB(picture->format) == 0) {
+               channel->pict_format = PIXMAN_a8;
+               depth = 8;
+       } else {
+               channel->pict_format = PIXMAN_a8r8g8b8;
+               depth = 32;
+       }
+
+       pixmap = screen->CreatePixmap(screen, w, h, depth, SNA_CREATE_SCRATCH);
+       if (pixmap == NullPixmap)
+               return 0;
+
+       tmp = CreatePicture(0, &pixmap->drawable,
+                           PictureMatchFormat(screen, depth, channel->pict_format),
+                           0, NULL, serverClient, &error);
+       screen->DestroyPixmap(pixmap);
+       if (tmp == NULL)
+               return 0;
+
+       ValidatePicture(tmp);
+
+       bo = sna_pixmap_get_bo(pixmap);
+       if (!sna->render.clear(sna, pixmap, bo)) {
+               FreePicture(tmp, 0);
+               return 0;
+       }
+
+       picture->filter = PictFilterBilinear;
+       params += 2;
+       for (j = 0; j < ch; j++) {
+               for (i = 0; i < cw; i++) {
+                       xRenderColor color;
+                       PicturePtr alpha;
+
+                       color.alpha = *params++;
+                       color.red = color.green = color.blue = 0;
+                       DBG(("%s: (%d, %d), alpha=%x\n",
+                            __FUNCTION__, i,j, color.alpha));
+
+                       if (color.alpha <= 0x00ff)
+                               continue;
+
+                       alpha = CreateSolidPicture(0, &color, &error);
+                       if (alpha) {
+                               sna_composite(PictOpAdd, picture, alpha, tmp,
+                                             x, y,
+                                             0, 0,
+                                             x_off+i, y_off+j,
+                                             w, h);
+                               FreePicture(alpha, 0);
+                       }
+               }
+       }
+       picture->filter = PictFilterConvolution;
+
+       channel->height = h;
+       channel->width  = w;
+       channel->filter = PictFilterNearest;
+       channel->repeat = RepeatNone;
+       channel->is_affine = true;
+       channel->transform = NULL;
+       channel->scale[0] = 1.f / w;
+       channel->scale[1] = 1.f / h;
+       channel->offset[0] = -dst_x;
+       channel->offset[1] = -dst_y;
+       channel->bo = kgem_bo_reference(bo); /* transfer ownership */
+       FreePicture(tmp, 0);
+
+       return 1;
+}
+
+static int
+sna_render_picture_flatten(struct sna *sna,
+                          PicturePtr picture,
+                          struct sna_composite_channel *channel,
+                          int16_t x, int16_t y,
+                          int16_t w, int16_t h,
+                          int16_t dst_x, int16_t dst_y)
+{
+       ScreenPtr screen = picture->pDrawable->pScreen;
+       PixmapPtr pixmap;
+       PicturePtr tmp, alpha;
+       int old_format, error;
+
+       assert(picture->pDrawable);
+       assert(picture->alphaMap);
+       assert(w <= sna->render.max_3d_size && h <= sna->render.max_3d_size);
+
+       /* XXX shortcut a8? */
+
+       pixmap = screen->CreatePixmap(screen, w, h, 32, SNA_CREATE_SCRATCH);
+       if (pixmap == NullPixmap)
+               return 0;
+
+       tmp = CreatePicture(0, &pixmap->drawable,
+                           PictureMatchFormat(screen, 32, PICT_a8r8g8b8),
+                           0, NULL, serverClient, &error);
+       screen->DestroyPixmap(pixmap);
+       if (tmp == NULL)
+               return 0;
+
+       old_format = picture->format;
+       picture->format = PICT_FORMAT(PICT_FORMAT_BPP(picture->format),
+                                     PICT_FORMAT_TYPE(picture->format),
+                                     0,
+                                     PICT_FORMAT_R(picture->format),
+                                     PICT_FORMAT_G(picture->format),
+                                     PICT_FORMAT_B(picture->format));
+
+       alpha = picture->alphaMap;
+       picture->alphaMap = NULL;
+
+       sna_composite(PictOpSrc, picture, alpha, tmp,
+                     x, y,
+                     x + picture->alphaOrigin.x, y + picture->alphaOrigin.y,
+                     0, 0,
+                     w, h);
+
+       picture->format = old_format;
+       picture->alphaMap = alpha;
+
+       channel->height = h;
+       channel->width  = w;
+       channel->filter = PictFilterNearest;
+       channel->repeat = RepeatNone;
+       channel->pict_format = PIXMAN_a8r8g8b8;
+       channel->is_affine = true;
+       channel->transform = NULL;
+       channel->scale[0] = 1.f / w;
+       channel->scale[1] = 1.f / h;
+       channel->offset[0] = -dst_x;
+       channel->offset[1] = -dst_y;
+       channel->bo = kgem_bo_reference(sna_pixmap_get_bo(pixmap));
+       FreePicture(tmp, 0);
+
+       return 1;
+}
+
+int
+sna_render_picture_approximate_gradient(struct sna *sna,
+                                       PicturePtr picture,
+                                       struct sna_composite_channel *channel,
+                                       int16_t x, int16_t y,
+                                       int16_t w, int16_t h,
+                                       int16_t dst_x, int16_t dst_y)
+{
+       pixman_image_t *dst, *src;
+       pixman_transform_t t;
+       int w2 = w/2, h2 = h/2;
+       int dx, dy;
+       void *ptr;
+
+#if NO_FIXUP
+       return -1;
+#endif
+
+       DBG(("%s: (%d, %d)x(%d, %d)\n", __FUNCTION__, x, y, w, h));
+
+       if (w2 == 0 || h2 == 0) {
+               DBG(("%s: fallback - unknown bounds\n", __FUNCTION__));
+               return -1;
+       }
+       if (w2 > sna->render.max_3d_size || h2 > sna->render.max_3d_size) {
+               DBG(("%s: fallback - too large (%dx%d)\n", __FUNCTION__, w, h));
+               return -1;
+       }
+
+       channel->pict_format = PIXMAN_a8r8g8b8;
+       channel->bo = kgem_create_buffer_2d(&sna->kgem,
+                                           w2, h2, 32,
+                                           KGEM_BUFFER_WRITE_INPLACE,
+                                           &ptr);
+       if (!channel->bo) {
+               DBG(("%s: failed to create upload buffer, using clear\n",
+                    __FUNCTION__));
+               return 0;
+       }
+
+       dst = pixman_image_create_bits(PIXMAN_a8r8g8b8,
+                                      w2, h2, ptr, channel->bo->pitch);
+       if (!dst) {
+               kgem_bo_destroy(&sna->kgem, channel->bo);
+               return 0;
+       }
+
+       src = image_from_pict(picture, false, &dx, &dy);
+       if (src == NULL) {
+               pixman_image_unref(dst);
+               kgem_bo_destroy(&sna->kgem, channel->bo);
+               return 0;
+       }
+
+       memset(&t, 0, sizeof(t));
+       t.matrix[0][0] = (w << 16) / w2;
+       t.matrix[1][1] = (h << 16) / h2;
+       t.matrix[2][2] = 1 << 16;
+       if (picture->transform)
+               pixman_transform_multiply(&t, picture->transform, &t);
+       pixman_image_set_transform(src, &t);
+
+       pixman_image_composite(PictOpSrc, src, NULL, dst,
+                              x + dx, y + dy,
+                              0, 0,
+                              0, 0,
+                              w2, h2);
+       free_pixman_pict(picture, src);
+       pixman_image_unref(dst);
+
+       channel->width  = w2;
+       channel->height = h2;
+
+       channel->filter = PictFilterNearest;
+       channel->repeat = RepeatNone;
+       channel->is_affine = true;
+
+       channel->scale[0] = 1.f/w;
+       channel->scale[1] = 1.f/h;
+       channel->offset[0] = -dst_x;
+       channel->offset[1] = -dst_y;
+       channel->transform = NULL;
+
+       return 1;
+}
+
+int
+sna_render_picture_fixup(struct sna *sna,
+                        PicturePtr picture,
+                        struct sna_composite_channel *channel,
+                        int16_t x, int16_t y,
+                        int16_t w, int16_t h,
+                        int16_t dst_x, int16_t dst_y)
+{
+       pixman_image_t *dst, *src;
+       int dx, dy;
+       void *ptr;
+
+#if NO_FIXUP
+       return -1;
+#endif
+
+       DBG(("%s: (%d, %d)x(%d, %d)\n", __FUNCTION__, x, y, w, h));
+
+       if (w == 0 || h == 0) {
+               DBG(("%s: fallback - unknown bounds\n", __FUNCTION__));
+               return -1;
+       }
+       if (w > sna->render.max_3d_size || h > sna->render.max_3d_size) {
+               DBG(("%s: fallback - too large (%dx%d)\n", __FUNCTION__, w, h));
+               return -1;
+       }
+
+       if (picture->alphaMap) {
+               DBG(("%s: alphamap\n", __FUNCTION__));
+               if (is_gpu(picture->pDrawable) || is_gpu(picture->alphaMap->pDrawable)) {
+                       return sna_render_picture_flatten(sna, picture, channel,
+                                                         x, y, w, h, dst_x, dst_y);
+               }
+
+               goto do_fixup;
+       }
+
+       if (picture->filter == PictFilterConvolution) {
+               DBG(("%s: convolution\n", __FUNCTION__));
+               if (is_gpu(picture->pDrawable)) {
+                       return sna_render_picture_convolve(sna, picture, channel,
+                                                          x, y, w, h, dst_x, dst_y);
+               }
+
+               goto do_fixup;
+       }
+
+do_fixup:
+       if (PICT_FORMAT_RGB(picture->format) == 0)
+               channel->pict_format = PIXMAN_a8;
+       else
+               channel->pict_format = PIXMAN_a8r8g8b8;
+       if (channel->pict_format != picture->format) {
+               DBG(("%s: converting to %08x from %08x\n",
+                    __FUNCTION__, channel->pict_format, picture->format));
+       }
+
+       if (picture->pDrawable &&
+           !sna_drawable_move_to_cpu(picture->pDrawable, MOVE_READ))
+               return 0;
+
+       channel->bo = kgem_create_buffer_2d(&sna->kgem,
+                                           w, h, PIXMAN_FORMAT_BPP(channel->pict_format),
+                                           KGEM_BUFFER_WRITE_INPLACE,
+                                           &ptr);
+       if (!channel->bo) {
+               DBG(("%s: failed to create upload buffer, using clear\n",
+                    __FUNCTION__));
+               return 0;
+       }
+
+       /* Composite in the original format to preserve idiosyncracies */
+       if (picture->format == channel->pict_format)
+               dst = pixman_image_create_bits(picture->format,
+                                              w, h, ptr, channel->bo->pitch);
+       else
+               dst = pixman_image_create_bits(picture->format, w, h, NULL, 0);
+       if (!dst) {
+               kgem_bo_destroy(&sna->kgem, channel->bo);
+               return 0;
+       }
+
+       src = image_from_pict(picture, false, &dx, &dy);
+       if (src == NULL) {
+               pixman_image_unref(dst);
+               kgem_bo_destroy(&sna->kgem, channel->bo);
+               return 0;
+       }
+
+       DBG(("%s: compositing tmp=(%d+%d, %d+%d)x(%d, %d)\n",
+            __FUNCTION__, x, dx, y, dy, w, h));
+       pixman_image_composite(PictOpSrc, src, NULL, dst,
+                              x + dx, y + dy,
+                              0, 0,
+                              0, 0,
+                              w, h);
+       free_pixman_pict(picture, src);
+
+       /* Then convert to card format */
+       if (picture->format != channel->pict_format) {
+               DBG(("%s: performing post-conversion %08x->%08x (%d, %d)\n",
+                    __FUNCTION__,
+                    picture->format, channel->pict_format,
+                    w, h));
+
+               src = dst;
+               dst = pixman_image_create_bits(channel->pict_format,
+                                              w, h, ptr, channel->bo->pitch);
+               if (dst) {
+                       pixman_image_composite(PictOpSrc, src, NULL, dst,
+                                              0, 0,
+                                              0, 0,
+                                              0, 0,
+                                              w, h);
+                       pixman_image_unref(src);
+               } else {
+                       memset(ptr, 0, __kgem_buffer_size(channel->bo));
+                       dst = src;
+               }
+       }
+       pixman_image_unref(dst);
+
+       channel->width  = w;
+       channel->height = h;
+
+       channel->filter = PictFilterNearest;
+       channel->repeat = RepeatNone;
+       channel->is_affine = true;
+
+       channel->scale[0] = 1.f/w;
+       channel->scale[1] = 1.f/h;
+       channel->offset[0] = -dst_x;
+       channel->offset[1] = -dst_y;
+       channel->transform = NULL;
+
+       return 1;
+}
+
+int
+sna_render_picture_convert(struct sna *sna,
+                          PicturePtr picture,
+                          struct sna_composite_channel *channel,
+                          PixmapPtr pixmap,
+                          int16_t x, int16_t y,
+                          int16_t w, int16_t h,
+                          int16_t dst_x, int16_t dst_y)
+{
+       pixman_image_t *src, *dst;
+       BoxRec box;
+       void *ptr;
+
+#if NO_CONVERT
+       return -1;
+#endif
+
+       if (w != 0 && h != 0) {
+               box.x1 = x;
+               box.y1 = y;
+               box.x2 = x + w;
+               box.y2 = y + h;
+
+               if (channel->transform) {
+                       DBG(("%s: has transform, converting whole surface\n",
+                            __FUNCTION__));
+                       box.x1 = box.y1 = 0;
+                       box.x2 = pixmap->drawable.width;
+                       box.y2 = pixmap->drawable.height;
+               }
+
+               if (box.x1 < 0)
+                       box.x1 = 0;
+               if (box.y1 < 0)
+                       box.y1 = 0;
+               if (box.x2 > pixmap->drawable.width)
+                       box.x2 = pixmap->drawable.width;
+               if (box.y2 > pixmap->drawable.height)
+                       box.y2 = pixmap->drawable.height;
+       } else {
+               DBG(("%s: op no bounds, converting whole surface\n",
+                    __FUNCTION__));
+               box.x1 = box.y1 = 0;
+               box.x2 = pixmap->drawable.width;
+               box.y2 = pixmap->drawable.height;
+       }
+
+       w = box.x2 - box.x1;
+       h = box.y2 - box.y1;
+
+       DBG(("%s: convert (%d, %d)x(%d, %d), source size %dx%d\n",
+            __FUNCTION__, box.x1, box.y1, w, h,
+            pixmap->drawable.width,
+            pixmap->drawable.height));
+
+       if (w == 0 || h == 0) {
+               DBG(("%s: sample extents lie outside of source, using clear\n",
+                    __FUNCTION__));
+               return 0;
+       }
+
+       if (!sna_pixmap_move_to_cpu(pixmap, MOVE_READ))
+               return 0;
+
+       src = pixman_image_create_bits(picture->format,
+                                      pixmap->drawable.width,
+                                      pixmap->drawable.height,
+                                      pixmap->devPrivate.ptr,
+                                      pixmap->devKind);
+       if (!src)
+               return 0;
+
+       if (PICT_FORMAT_RGB(picture->format) == 0) {
+               channel->pict_format = PIXMAN_a8;
+               DBG(("%s: converting to a8 from %08x\n",
+                    __FUNCTION__, picture->format));
+       } else {
+               channel->pict_format = PIXMAN_a8r8g8b8;
+               DBG(("%s: converting to a8r8g8b8 from %08x\n",
+                    __FUNCTION__, picture->format));
+       }
+
+       channel->bo = kgem_create_buffer_2d(&sna->kgem,
+                                           w, h, PIXMAN_FORMAT_BPP(channel->pict_format),
+                                           KGEM_BUFFER_WRITE_INPLACE,
+                                           &ptr);
+       if (!channel->bo) {
+               pixman_image_unref(src);
+               return 0;
+       }
+
+       dst = pixman_image_create_bits(channel->pict_format,
+                                      w, h, ptr, channel->bo->pitch);
+       if (!dst) {
+               kgem_bo_destroy(&sna->kgem, channel->bo);
+               pixman_image_unref(src);
+               return 0;
+       }
+
+       pixman_image_composite(PictOpSrc, src, NULL, dst,
+                              box.x1, box.y1,
+                              0, 0,
+                              0, 0,
+                              w, h);
+       pixman_image_unref(dst);
+       pixman_image_unref(src);
+
+       channel->width  = w;
+       channel->height = h;
+
+       channel->scale[0] = 1.f/w;
+       channel->scale[1] = 1.f/h;
+       channel->offset[0] = x - dst_x - box.x1;
+       channel->offset[1] = y - dst_y - box.y1;
+
+       DBG(("%s: offset=(%d, %d), size=(%d, %d) ptr[0]=%08x\n",
+            __FUNCTION__,
+            channel->offset[0], channel->offset[1],
+            channel->width, channel->height,
+            *(uint32_t*)ptr));
+       return 1;
+}
+
+bool
+sna_render_composite_redirect(struct sna *sna,
+                             struct sna_composite_op *op,
+                             int x, int y, int width, int height)
+{
+       struct sna_composite_redirect *t = &op->redirect;
+       int bpp = op->dst.pixmap->drawable.bitsPerPixel;
+       struct kgem_bo *bo;
+
+#if NO_REDIRECT
+       return false;
+#endif
+
+       DBG(("%s: target too large (%dx%d), copying to temporary %dx%d, max %d\n",
+            __FUNCTION__,
+            op->dst.width, op->dst.height,
+            width, height,
+            sna->render.max_3d_size));
+
+       if (!width || !height)
+               return false;
+
+       if (width  > sna->render.max_3d_size ||
+           height > sna->render.max_3d_size)
+               return false;
+
+       if (op->dst.bo->pitch <= sna->render.max_3d_pitch) {
+               BoxRec box;
+               int w, h, offset;
+
+               DBG(("%s: dst pitch (%d) fits within render pipeline (%d)\n",
+                    __FUNCTION__, op->dst.bo->pitch, sna->render.max_3d_pitch));
+
+               box.x1 = x;
+               box.x2 = x + width;
+               box.y1 = y;
+               box.y2 = y + height;
+
+               /* Ensure we align to an even tile row */
+               if (op->dst.bo->tiling) {
+                       int tile_width, tile_height, tile_size;
+
+                       kgem_get_tile_size(&sna->kgem, op->dst.bo->tiling,
+                                          &tile_width, &tile_height, &tile_size);
+
+                       box.y1 = box.y1 & ~(2*tile_height - 1);
+                       box.y2 = ALIGN(box.y2, 2*tile_height);
+
+                       box.x1 = box.x1 & ~(tile_width * 8 / op->dst.pixmap->drawable.bitsPerPixel - 1);
+                       box.x2 = ALIGN(box.x2, tile_width * 8 / op->dst.pixmap->drawable.bitsPerPixel);
+
+                       offset = box.x1 * op->dst.pixmap->drawable.bitsPerPixel / 8 / tile_width * tile_size;
+               } else {
+                       if (sna->kgem.gen < 40) {
+                               box.y1 = box.y1 & ~3;
+                               box.y2 = ALIGN(box.y2, 4);
+
+                               box.x1 = box.x1 & ~3;
+                               box.x2 = ALIGN(box.x2, 4);
+                       } else {
+                               box.y1 = box.y1 & ~1;
+                               box.y2 = ALIGN(box.y2, 2);
+
+                               box.x1 = box.x1 & ~1;
+                               box.x2 = ALIGN(box.x2, 2);
+                       }
+
+                       offset = box.x1 * op->dst.pixmap->drawable.bitsPerPixel / 8;
+               }
+
+               if (box.y2 > op->dst.pixmap->drawable.height)
+                       box.y2 = op->dst.pixmap->drawable.height;
+
+               if (box.x2 > op->dst.pixmap->drawable.width)
+                       box.x2 = op->dst.pixmap->drawable.width;
+
+               w = box.x2 - box.x1;
+               h = box.y2 - box.y1;
+               DBG(("%s box=(%d, %d), (%d, %d): (%d, %d)/(%d, %d), max %d\n", __FUNCTION__,
+                    box.x1, box.y1, box.x2, box.y2, w, h,
+                    op->dst.pixmap->drawable.width,
+                    op->dst.pixmap->drawable.height,
+                    sna->render.max_3d_size));
+               if (w <= sna->render.max_3d_size &&
+                   h <= sna->render.max_3d_size) {
+                       t->box.x2 = t->box.x1 = op->dst.x;
+                       t->box.y2 = t->box.y1 = op->dst.y;
+                       t->real_bo = op->dst.bo;
+                       t->real_damage = op->damage;
+                       if (op->damage) {
+                               t->damage = sna_damage_create();
+                               op->damage = &t->damage;
+                       }
+
+                       /* How many tiles across are we? */
+                       op->dst.bo = kgem_create_proxy(&sna->kgem, op->dst.bo,
+                                                      box.y1 * op->dst.bo->pitch + offset,
+                                                      h * op->dst.bo->pitch);
+                       if (!op->dst.bo) {
+                               t->real_bo = NULL;
+                               if (t->damage)
+                                       __sna_damage_destroy(t->damage);
+                               return false;
+                       }
+
+                       assert(op->dst.bo != t->real_bo);
+                       op->dst.bo->pitch = t->real_bo->pitch;
+
+                       op->dst.x -= box.x1;
+                       op->dst.y -= box.y1;
+                       op->dst.width  = w;
+                       op->dst.height = h;
+                       return true;
+               }
+       }
+
+       /* We can process the operation in a single pass,
+        * but the target is too large for the 3D pipeline.
+        * Copy into a smaller surface and replace afterwards.
+        */
+       bo = kgem_create_2d(&sna->kgem,
+                           width, height, bpp,
+                           kgem_choose_tiling(&sna->kgem, I915_TILING_X,
+                                              width, height, bpp),
+                           CREATE_TEMPORARY);
+       if (!bo)
+               return false;
+
+       t->box.x1 = x + op->dst.x;
+       t->box.y1 = y + op->dst.y;
+       t->box.x2 = t->box.x1 + width;
+       t->box.y2 = t->box.y1 + height;
+
+       DBG(("%s: original box (%d, %d), (%d, %d)\n",
+            __FUNCTION__, t->box.x1, t->box.y1, t->box.x2, t->box.y2));
+
+       if (!sna_blt_copy_boxes(sna, GXcopy,
+                               op->dst.bo, 0, 0,
+                               bo, -t->box.x1, -t->box.y1,
+                               bpp, &t->box, 1)) {
+               kgem_bo_destroy(&sna->kgem, bo);
+               return false;
+       }
+
+       t->real_bo = op->dst.bo;
+       t->real_damage = op->damage;
+       if (op->damage) {
+               assert(!DAMAGE_IS_ALL(op->damage));
+               t->damage = sna_damage_create();
+               op->damage = &t->damage;
+       }
+
+       op->dst.bo = bo;
+       op->dst.x = -x;
+       op->dst.y = -y;
+       op->dst.width  = width;
+       op->dst.height = height;
+       return true;
+}
+
+void
+sna_render_composite_redirect_done(struct sna *sna,
+                                  const struct sna_composite_op *op)
+{
+       const struct sna_composite_redirect *t = &op->redirect;
+
+       if (t->real_bo) {
+               assert(op->dst.bo != t->real_bo);
+
+               if (t->box.x2 > t->box.x1) {
+                       bool ok;
+
+                       DBG(("%s: copying temporary to dst\n", __FUNCTION__));
+                       ok = sna_blt_copy_boxes(sna, GXcopy,
+                                               op->dst.bo, -t->box.x1, -t->box.y1,
+                                               t->real_bo, 0, 0,
+                                               op->dst.pixmap->drawable.bitsPerPixel,
+                                               &t->box, 1);
+                       assert(ok);
+               }
+               if (t->damage) {
+                       DBG(("%s: combining damage, offset=(%d, %d)\n",
+                            __FUNCTION__, t->box.x1, t->box.y1));
+                       sna_damage_combine(t->real_damage, t->damage,
+                                          t->box.x1, t->box.y1);
+                       __sna_damage_destroy(t->damage);
+               }
+
+               kgem_bo_destroy(&sna->kgem, op->dst.bo);
+       }
+}
+
+bool
+sna_render_copy_boxes__overlap(struct sna *sna, uint8_t alu,
+                              PixmapPtr src, struct kgem_bo *src_bo, int16_t src_dx, int16_t src_dy,
+                              PixmapPtr dst, struct kgem_bo *dst_bo, int16_t dst_dx, int16_t dst_dy,
+                              const BoxRec *box, int n, const BoxRec *extents)
+{
+       ScreenPtr screen = dst->drawable.pScreen;
+       struct kgem_bo *bo;
+       PixmapPtr tmp;
+       bool ret = false;
+
+       tmp = screen->CreatePixmap(screen,
+                                  extents->x2 - extents->x1,
+                                  extents->y2 - extents->y1,
+                                  dst->drawable.depth,
+                                  SNA_CREATE_SCRATCH);
+       if (tmp == NULL)
+               return false;
+
+       bo = sna_pixmap_get_bo(tmp);
+       if (bo == NULL)
+               goto out;
+
+       ret = (sna->render.copy_boxes(sna, alu,
+                                     src, src_bo, src_dx, src_dy,
+                                     tmp, bo, -extents->x1, -extents->y1,
+                                     box, n , 0) &&
+              sna->render.copy_boxes(sna, alu,
+                                     tmp, bo, -extents->x1, -extents->y1,
+                                     dst, dst_bo, dst_dx, dst_dy,
+                                     box, n , 0));
+
+out:
+       screen->DestroyPixmap(tmp);
+       return ret;
+}
diff --git a/src/sna/sna_render.h b/src/sna/sna_render.h
new file mode 100644 (file)
index 0000000..03a7005
--- /dev/null
@@ -0,0 +1,720 @@
+#ifndef SNA_RENDER_H
+#define SNA_RENDER_H
+
+#include "compiler.h"
+
+#include <picturestr.h>
+
+#define GRADIENT_CACHE_SIZE 16
+
+#define GXinvalid 0xff
+
+struct sna;
+struct sna_glyph;
+struct sna_video;
+struct sna_video_frame;
+struct brw_compile;
+
+struct sna_composite_rectangles {
+       struct sna_coordinate {
+               int16_t x, y;
+       } src, mask, dst;
+       int16_t width, height;
+};
+
+struct sna_composite_op {
+       fastcall void (*blt)(struct sna *sna, const struct sna_composite_op *op,
+                            const struct sna_composite_rectangles *r);
+       fastcall void (*box)(struct sna *sna,
+                            const struct sna_composite_op *op,
+                            const BoxRec *box);
+       void (*boxes)(struct sna *sna, const struct sna_composite_op *op,
+                     const BoxRec *box, int nbox);
+       void (*done)(struct sna *sna, const struct sna_composite_op *op);
+
+       struct sna_damage **damage;
+
+       uint32_t op;
+
+       struct {
+               PixmapPtr pixmap;
+               CARD32 format;
+               struct kgem_bo *bo;
+               int16_t x, y;
+               uint16_t width, height;
+       } dst;
+
+       struct sna_composite_channel {
+               struct kgem_bo *bo;
+               PictTransform *transform;
+               uint16_t width;
+               uint16_t height;
+               uint32_t pict_format;
+               uint32_t card_format;
+               uint32_t filter;
+               uint32_t repeat;
+               uint32_t is_affine : 1;
+               uint32_t is_solid : 1;
+               uint32_t is_linear : 1;
+               uint32_t is_opaque : 1;
+               uint32_t alpha_fixup : 1;
+               uint32_t rb_reversed : 1;
+               int16_t offset[2];
+               float scale[2];
+
+               pixman_transform_t embedded_transform;
+
+               union {
+                       struct {
+                               uint32_t pixel;
+                               float linear_dx;
+                               float linear_dy;
+                               float linear_offset;
+                       } gen2;
+                       struct gen3_shader_channel {
+                               int type;
+                               uint32_t mode;
+                               uint32_t constants;
+                       } gen3;
+               } u;
+       } src, mask;
+       uint32_t is_affine : 1;
+       uint32_t has_component_alpha : 1;
+       uint32_t need_magic_ca_pass : 1;
+       uint32_t rb_reversed : 1;
+
+       int16_t floats_per_vertex;
+       int16_t floats_per_rect;
+       fastcall void (*prim_emit)(struct sna *sna,
+                                  const struct sna_composite_op *op,
+                                  const struct sna_composite_rectangles *r);
+
+       struct sna_composite_redirect {
+               struct kgem_bo *real_bo;
+               struct sna_damage **real_damage, *damage;
+               BoxRec box;
+       } redirect;
+
+       union {
+               struct sna_blt_state {
+                       PixmapPtr src_pixmap;
+                       int16_t sx, sy;
+
+                       uint32_t inplace :1;
+                       uint32_t overwrites:1;
+                       uint32_t bpp : 6;
+
+                       uint32_t cmd;
+                       uint32_t br13;
+                       uint32_t pitch[2];
+                       uint32_t pixel;
+                       struct kgem_bo *bo[2];
+               } blt;
+
+               struct {
+                       float constants[8];
+                       uint32_t num_constants;
+               } gen3;
+
+               struct {
+                       int wm_kernel;
+                       int ve_id;
+               } gen4;
+
+               struct {
+                       int wm_kernel;
+                       int ve_id;
+               } gen5;
+
+               struct {
+                       uint32_t flags;
+               } gen6;
+
+               struct {
+                       uint32_t flags;
+               } gen7;
+       } u;
+
+       void *priv;
+};
+
+struct sna_composite_spans_op {
+       struct sna_composite_op base;
+
+       fastcall void (*box)(struct sna *sna,
+                            const struct sna_composite_spans_op *op,
+                            const BoxRec *box,
+                            float opacity);
+       void (*boxes)(struct sna *sna,
+                     const struct sna_composite_spans_op *op,
+                     const BoxRec *box, int nbox,
+                     float opacity);
+       fastcall void (*done)(struct sna *sna,
+                             const struct sna_composite_spans_op *op);
+
+       fastcall void (*prim_emit)(struct sna *sna,
+                                  const struct sna_composite_spans_op *op,
+                                  const BoxRec *box,
+                                  float opacity);
+};
+
+struct sna_fill_op {
+       struct sna_composite_op base;
+
+       void (*blt)(struct sna *sna, const struct sna_fill_op *op,
+                   int16_t x, int16_t y, int16_t w, int16_t h);
+       fastcall void (*box)(struct sna *sna,
+                            const struct sna_fill_op *op,
+                            const BoxRec *box);
+       fastcall void (*boxes)(struct sna *sna,
+                              const struct sna_fill_op *op,
+                              const BoxRec *box,
+                              int count);
+       void (*done)(struct sna *sna, const struct sna_fill_op *op);
+};
+
+struct sna_copy_op {
+       struct sna_composite_op base;
+
+       void (*blt)(struct sna *sna, const struct sna_copy_op *op,
+                   int16_t sx, int16_t sy,
+                   int16_t w, int16_t h,
+                   int16_t dx, int16_t dy);
+       void (*done)(struct sna *sna, const struct sna_copy_op *op);
+};
+
+struct sna_render {
+       int max_3d_size;
+       int max_3d_pitch;
+
+       bool (*composite)(struct sna *sna, uint8_t op,
+                         PicturePtr dst, PicturePtr src, PicturePtr mask,
+                         int16_t src_x, int16_t src_y,
+                         int16_t msk_x, int16_t msk_y,
+                         int16_t dst_x, int16_t dst_y,
+                         int16_t w, int16_t h,
+                         struct sna_composite_op *tmp);
+
+       bool (*check_composite_spans)(struct sna *sna, uint8_t op,
+                                     PicturePtr dst, PicturePtr src,
+                                     int16_t w, int16_t h, unsigned flags);
+       bool (*composite_spans)(struct sna *sna, uint8_t op,
+                               PicturePtr dst, PicturePtr src,
+                               int16_t src_x, int16_t src_y,
+                               int16_t dst_x, int16_t dst_y,
+                               int16_t w, int16_t h,
+                               unsigned flags,
+                               struct sna_composite_spans_op *tmp);
+#define COMPOSITE_SPANS_RECTILINEAR 0x1
+#define COMPOSITE_SPANS_INPLACE_HINT 0x2
+
+       bool (*video)(struct sna *sna,
+                     struct sna_video *video,
+                     struct sna_video_frame *frame,
+                     RegionPtr dstRegion,
+                     short src_w, short src_h,
+                     short drw_w, short drw_h,
+                     PixmapPtr pixmap);
+
+       bool (*fill_boxes)(struct sna *sna,
+                          CARD8 op,
+                          PictFormat format,
+                          const xRenderColor *color,
+                          PixmapPtr dst, struct kgem_bo *dst_bo,
+                          const BoxRec *box, int n);
+       bool (*fill)(struct sna *sna, uint8_t alu,
+                    PixmapPtr dst, struct kgem_bo *dst_bo,
+                    uint32_t color,
+                    struct sna_fill_op *tmp);
+       bool (*fill_one)(struct sna *sna, PixmapPtr dst, struct kgem_bo *dst_bo,
+                        uint32_t color,
+                        int16_t x1, int16_t y1, int16_t x2, int16_t y2,
+                        uint8_t alu);
+       bool (*clear)(struct sna *sna, PixmapPtr dst, struct kgem_bo *dst_bo);
+
+       bool (*copy_boxes)(struct sna *sna, uint8_t alu,
+                          PixmapPtr src, struct kgem_bo *src_bo, int16_t src_dx, int16_t src_dy,
+                          PixmapPtr dst, struct kgem_bo *dst_bo, int16_t dst_dx, int16_t dst_dy,
+                          const BoxRec *box, int n, unsigned flags);
+#define COPY_LAST 0x1
+
+       bool (*copy)(struct sna *sna, uint8_t alu,
+                    PixmapPtr src, struct kgem_bo *src_bo,
+                    PixmapPtr dst, struct kgem_bo *dst_bo,
+                    struct sna_copy_op *op);
+
+       void (*flush)(struct sna *sna);
+       void (*reset)(struct sna *sna);
+       void (*fini)(struct sna *sna);
+
+       struct sna_alpha_cache {
+               struct kgem_bo *cache_bo;
+               struct kgem_bo *bo[256];
+       } alpha_cache;
+
+       struct sna_solid_cache {
+               struct kgem_bo *cache_bo;
+               uint32_t color[1024];
+               struct kgem_bo *bo[1024];
+               int last;
+               int size;
+               int dirty;
+       } solid_cache;
+
+       struct {
+               struct sna_gradient_cache {
+                       struct kgem_bo *bo;
+                       int nstops;
+                       PictGradientStop *stops;
+               } cache[GRADIENT_CACHE_SIZE];
+               int size;
+       } gradient_cache;
+
+       struct sna_glyph_cache{
+               PicturePtr picture;
+               struct sna_glyph **glyphs;
+               uint16_t count;
+               uint16_t evict;
+       } glyph[2];
+       pixman_image_t *white_image;
+       PicturePtr white_picture;
+#if HAS_PIXMAN_GLYPHS
+       pixman_glyph_cache_t *glyph_cache;
+#endif
+
+       uint16_t vertex_start;
+       uint16_t vertex_index;
+       uint16_t vertex_used;
+       uint16_t vertex_size;
+       uint16_t vertex_reloc[16];
+       int nvertex_reloc;
+
+       struct kgem_bo *vbo;
+       float *vertices;
+
+       float vertex_data[1024];
+};
+
+struct gen2_render_state {
+       uint32_t target;
+       bool need_invariant;
+       uint32_t logic_op_enabled;
+       uint32_t ls1, ls2, vft;
+       uint32_t diffuse;
+       uint32_t specular;
+       uint16_t vertex_offset;
+};
+
+struct gen3_render_state {
+       uint32_t current_dst;
+       bool need_invariant;
+       uint32_t tex_count;
+       uint32_t last_drawrect_limit;
+       uint32_t last_target;
+       uint32_t last_blend;
+       uint32_t last_constants;
+       uint32_t last_sampler;
+       uint32_t last_shader;
+       uint32_t last_diffuse;
+       uint32_t last_specular;
+
+       uint16_t vertex_offset;
+       uint16_t last_vertex_offset;
+       uint16_t floats_per_vertex;
+       uint16_t last_floats_per_vertex;
+
+       uint32_t tex_map[4];
+       uint32_t tex_handle[2];
+       uint32_t tex_delta[2];
+};
+
+struct gen4_render_state {
+       struct kgem_bo *general_bo;
+
+       uint32_t vs;
+       uint32_t sf[2];
+       uint32_t wm;
+       uint32_t cc;
+
+       int ve_id;
+       uint32_t drawrect_offset;
+       uint32_t drawrect_limit;
+       uint32_t vb_id;
+       uint32_t last_pipelined_pointers;
+       uint16_t vertex_offset;
+       uint16_t last_primitive;
+       int16_t floats_per_vertex;
+       uint16_t surface_table;
+
+       bool needs_invariant;
+       bool needs_urb;
+};
+
+struct gen5_render_state {
+       struct kgem_bo *general_bo;
+
+       uint32_t vs;
+       uint32_t sf[2];
+       uint32_t wm;
+       uint32_t cc;
+
+       int ve_id;
+       uint32_t drawrect_offset;
+       uint32_t drawrect_limit;
+       uint32_t vb_id;
+       uint16_t vertex_offset;
+       uint16_t last_primitive;
+       int16_t floats_per_vertex;
+       uint16_t surface_table;
+       uint16_t last_pipelined_pointers;
+
+       bool needs_invariant;
+};
+
+enum {
+       GEN6_WM_KERNEL_NOMASK = 0,
+       GEN6_WM_KERNEL_NOMASK_P,
+
+       GEN6_WM_KERNEL_MASK,
+       GEN6_WM_KERNEL_MASK_P,
+
+       GEN6_WM_KERNEL_MASKCA,
+       GEN6_WM_KERNEL_MASKCA_P,
+
+       GEN6_WM_KERNEL_MASKSA,
+       GEN6_WM_KERNEL_MASKSA_P,
+
+       GEN6_WM_KERNEL_OPACITY,
+       GEN6_WM_KERNEL_OPACITY_P,
+
+       GEN6_WM_KERNEL_VIDEO_PLANAR,
+       GEN6_WM_KERNEL_VIDEO_PACKED,
+       GEN6_KERNEL_COUNT
+};
+
+struct gen6_render_state {
+       const struct gt_info *info;
+       struct kgem_bo *general_bo;
+
+       uint32_t vs_state;
+       uint32_t sf_state;
+       uint32_t sf_mask_state;
+       uint32_t wm_state;
+       uint32_t wm_kernel[GEN6_KERNEL_COUNT][3];
+
+       uint32_t cc_vp;
+       uint32_t cc_blend;
+
+       uint32_t drawrect_offset;
+       uint32_t drawrect_limit;
+       uint32_t blend;
+       uint32_t samplers;
+       uint32_t kernel;
+
+       uint16_t num_sf_outputs;
+       uint16_t vb_id;
+       uint16_t ve_id;
+       uint16_t vertex_offset;
+       uint16_t last_primitive;
+       int16_t floats_per_vertex;
+       uint16_t surface_table;
+
+       bool needs_invariant;
+       bool first_state_packet;
+};
+
+enum {
+       GEN7_WM_KERNEL_NOMASK = 0,
+       GEN7_WM_KERNEL_NOMASK_P,
+
+       GEN7_WM_KERNEL_MASK,
+       GEN7_WM_KERNEL_MASK_P,
+
+       GEN7_WM_KERNEL_MASKCA,
+       GEN7_WM_KERNEL_MASKCA_P,
+
+       GEN7_WM_KERNEL_MASKSA,
+       GEN7_WM_KERNEL_MASKSA_P,
+
+       GEN7_WM_KERNEL_OPACITY,
+       GEN7_WM_KERNEL_OPACITY_P,
+
+       GEN7_WM_KERNEL_VIDEO_PLANAR,
+       GEN7_WM_KERNEL_VIDEO_PACKED,
+       GEN7_WM_KERNEL_COUNT
+};
+
+struct gen7_render_state {
+       const struct gt_info *info;
+       struct kgem_bo *general_bo;
+
+       uint32_t vs_state;
+       uint32_t sf_state;
+       uint32_t sf_mask_state;
+       uint32_t wm_state;
+       uint32_t wm_kernel[GEN7_WM_KERNEL_COUNT][3];
+
+       uint32_t cc_vp;
+       uint32_t cc_blend;
+
+       uint32_t drawrect_offset;
+       uint32_t drawrect_limit;
+       uint32_t blend;
+       uint32_t samplers;
+       uint32_t kernel;
+
+       uint16_t num_sf_outputs;
+       uint16_t vb_id;
+       uint16_t ve_id;
+       uint16_t vertex_offset;
+       uint16_t last_primitive;
+       int16_t floats_per_vertex;
+       uint16_t surface_table;
+
+       bool needs_invariant;
+       bool emit_flush;
+};
+
+struct sna_static_stream {
+       uint32_t size, used;
+       uint8_t *data;
+};
+
+int sna_static_stream_init(struct sna_static_stream *stream);
+uint32_t sna_static_stream_add(struct sna_static_stream *stream,
+                              const void *data, uint32_t len, uint32_t align);
+void *sna_static_stream_map(struct sna_static_stream *stream,
+                           uint32_t len, uint32_t align);
+uint32_t sna_static_stream_offsetof(struct sna_static_stream *stream,
+                                   void *ptr);
+unsigned sna_static_stream_compile_sf(struct sna *sna,
+                                     struct sna_static_stream *stream,
+                                     bool (*compile)(struct brw_compile *));
+
+unsigned sna_static_stream_compile_wm(struct sna *sna,
+                                     struct sna_static_stream *stream,
+                                     bool (*compile)(struct brw_compile *, int),
+                                     int width);
+struct kgem_bo *sna_static_stream_fini(struct sna *sna,
+                                      struct sna_static_stream *stream);
+
+struct kgem_bo *
+sna_render_get_solid(struct sna *sna,
+                    uint32_t color);
+
+void
+sna_render_flush_solid(struct sna *sna);
+
+struct kgem_bo *
+sna_render_get_gradient(struct sna *sna,
+                       PictGradient *pattern);
+
+uint32_t sna_rgba_for_color(uint32_t color, int depth);
+uint32_t sna_rgba_to_color(uint32_t rgba, uint32_t format);
+bool sna_get_rgba_from_pixel(uint32_t pixel,
+                            uint16_t *red,
+                            uint16_t *green,
+                            uint16_t *blue,
+                            uint16_t *alpha,
+                            uint32_t format);
+bool sna_picture_is_solid(PicturePtr picture, uint32_t *color);
+
+void no_render_init(struct sna *sna);
+
+bool gen2_render_init(struct sna *sna);
+bool gen3_render_init(struct sna *sna);
+bool gen4_render_init(struct sna *sna);
+bool gen5_render_init(struct sna *sna);
+bool gen6_render_init(struct sna *sna);
+bool gen7_render_init(struct sna *sna);
+
+bool sna_tiling_composite(uint32_t op,
+                         PicturePtr src,
+                         PicturePtr mask,
+                         PicturePtr dst,
+                         int16_t src_x, int16_t src_y,
+                         int16_t mask_x, int16_t mask_y,
+                         int16_t dst_x, int16_t dst_y,
+                         int16_t width, int16_t height,
+                         struct sna_composite_op *tmp);
+bool sna_tiling_composite_spans(uint32_t op,
+                               PicturePtr src,
+                               PicturePtr dst,
+                               int16_t src_x,  int16_t src_y,
+                               int16_t dst_x,  int16_t dst_y,
+                               int16_t width,  int16_t height,
+                               unsigned flags,
+                               struct sna_composite_spans_op *tmp);
+bool sna_tiling_fill_boxes(struct sna *sna,
+                          CARD8 op,
+                          PictFormat format,
+                          const xRenderColor *color,
+                          PixmapPtr dst, struct kgem_bo *dst_bo,
+                          const BoxRec *box, int n);
+
+bool sna_tiling_copy_boxes(struct sna *sna, uint8_t alu,
+                          PixmapPtr src, struct kgem_bo *src_bo, int16_t src_dx, int16_t src_dy,
+                          PixmapPtr dst, struct kgem_bo *dst_bo, int16_t dst_dx, int16_t dst_dy,
+                          const BoxRec *box, int n);
+
+bool sna_tiling_blt_copy_boxes(struct sna *sna, uint8_t alu,
+                              struct kgem_bo *src_bo, int16_t src_dx, int16_t src_dy,
+                              struct kgem_bo *dst_bo, int16_t dst_dx, int16_t dst_dy,
+                              int bpp, const BoxRec *box, int nbox);
+
+bool sna_blt_composite(struct sna *sna,
+                      uint32_t op,
+                      PicturePtr src,
+                      PicturePtr dst,
+                      int16_t src_x, int16_t src_y,
+                      int16_t dst_x, int16_t dst_y,
+                      int16_t width, int16_t height,
+                      struct sna_composite_op *tmp,
+                      bool fallback);
+bool sna_blt_composite__convert(struct sna *sna,
+                               int x, int y,
+                               int width, int height,
+                               struct sna_composite_op *tmp);
+
+bool sna_blt_fill(struct sna *sna, uint8_t alu,
+                 struct kgem_bo *bo,
+                 int bpp,
+                 uint32_t pixel,
+                 struct sna_fill_op *fill);
+
+bool sna_blt_copy(struct sna *sna, uint8_t alu,
+                 struct kgem_bo *src,
+                 struct kgem_bo *dst,
+                 int bpp,
+                 struct sna_copy_op *copy);
+
+bool sna_blt_fill_boxes(struct sna *sna, uint8_t alu,
+                       struct kgem_bo *bo,
+                       int bpp,
+                       uint32_t pixel,
+                       const BoxRec *box, int n);
+
+bool sna_blt_copy_boxes(struct sna *sna, uint8_t alu,
+                       struct kgem_bo *src_bo, int16_t src_dx, int16_t src_dy,
+                       struct kgem_bo *dst_bo, int16_t dst_dx, int16_t dst_dy,
+                       int bpp,
+                       const BoxRec *box, int n);
+bool sna_blt_copy_boxes_fallback(struct sna *sna, uint8_t alu,
+                                PixmapPtr src, struct kgem_bo *src_bo, int16_t src_dx, int16_t src_dy,
+                                PixmapPtr dst, struct kgem_bo *dst_bo, int16_t dst_dx, int16_t dst_dy,
+                                const BoxRec *box, int nbox);
+
+bool _sna_get_pixel_from_rgba(uint32_t *pixel,
+                            uint16_t red,
+                            uint16_t green,
+                            uint16_t blue,
+                            uint16_t alpha,
+                            uint32_t format);
+
+static inline bool
+sna_get_pixel_from_rgba(uint32_t * pixel,
+                       uint16_t red,
+                       uint16_t green,
+                       uint16_t blue,
+                       uint16_t alpha,
+                       uint32_t format)
+{
+       switch (format) {
+       case PICT_x8r8g8b8:
+               alpha = 0xffff;
+               /* fall through to re-use a8r8g8b8 expansion */
+       case PICT_a8r8g8b8:
+               *pixel = ((alpha >> 8 << 24) |
+                         (red >> 8 << 16) |
+                         (green & 0xff00) |
+                         (blue >> 8));
+               return TRUE;
+       case PICT_a8:
+               *pixel = alpha >> 8;
+               return TRUE;
+       }
+
+       return _sna_get_pixel_from_rgba(pixel, red, green, blue, alpha, format);
+}
+
+struct kgem_bo *
+__sna_render_pixmap_bo(struct sna *sna,
+                      PixmapPtr pixmap,
+                      const BoxRec *box,
+                      bool blt);
+
+int
+sna_render_pixmap_bo(struct sna *sna,
+                    struct sna_composite_channel *channel,
+                    PixmapPtr pixmap,
+                    int16_t x, int16_t y,
+                    int16_t w, int16_t h,
+                    int16_t dst_x, int16_t dst_y);
+
+bool
+sna_render_pixmap_partial(struct sna *sna,
+                         PixmapPtr pixmap,
+                         struct kgem_bo *bo,
+                         struct sna_composite_channel *channel,
+                         int16_t x, int16_t y,
+                         int16_t w, int16_t h);
+
+int
+sna_render_picture_extract(struct sna *sna,
+                          PicturePtr picture,
+                          struct sna_composite_channel *channel,
+                          int16_t x, int16_t y,
+                          int16_t w, int16_t h,
+                          int16_t dst_x, int16_t dst_y);
+
+int
+sna_render_picture_approximate_gradient(struct sna *sna,
+                                       PicturePtr picture,
+                                       struct sna_composite_channel *channel,
+                                       int16_t x, int16_t y,
+                                       int16_t w, int16_t h,
+                                       int16_t dst_x, int16_t dst_y);
+
+int
+sna_render_picture_fixup(struct sna *sna,
+                        PicturePtr picture,
+                        struct sna_composite_channel *channel,
+                        int16_t x, int16_t y,
+                        int16_t w, int16_t h,
+                        int16_t dst_x, int16_t dst_y);
+
+int
+sna_render_picture_convert(struct sna *sna,
+                          PicturePtr picture,
+                          struct sna_composite_channel *channel,
+                          PixmapPtr pixmap,
+                          int16_t x, int16_t y,
+                          int16_t w, int16_t h,
+                          int16_t dst_x, int16_t dst_y);
+
+inline static void sna_render_composite_redirect_init(struct sna_composite_op *op)
+{
+       struct sna_composite_redirect *t = &op->redirect;
+       t->real_bo = NULL;
+       t->damage = NULL;
+}
+
+bool
+sna_render_composite_redirect(struct sna *sna,
+                             struct sna_composite_op *op,
+                             int x, int y, int width, int height);
+
+void
+sna_render_composite_redirect_done(struct sna *sna,
+                                  const struct sna_composite_op *op);
+
+bool
+sna_render_copy_boxes__overlap(struct sna *sna, uint8_t alu,
+                              PixmapPtr src, struct kgem_bo *src_bo, int16_t src_dx, int16_t src_dy,
+                              PixmapPtr dst, struct kgem_bo *dst_bo, int16_t dst_dx, int16_t dst_dy,
+                              const BoxRec *box, int n, const BoxRec *extents);
+
+bool
+sna_composite_mask_is_opaque(PicturePtr mask);
+
+#endif /* SNA_RENDER_H */
diff --git a/src/sna/sna_render_inline.h b/src/sna/sna_render_inline.h
new file mode 100644 (file)
index 0000000..216937a
--- /dev/null
@@ -0,0 +1,219 @@
+#ifndef SNA_RENDER_INLINE_H
+#define SNA_RENDER_INLINE_H
+
+static inline bool need_tiling(struct sna *sna, int16_t width, int16_t height)
+{
+       /* Is the damage area too large to fit in 3D pipeline,
+        * and so do we need to split the operation up into tiles?
+        */
+       return (width > sna->render.max_3d_size ||
+               height > sna->render.max_3d_size);
+}
+
+static inline bool need_redirect(struct sna *sna, PixmapPtr dst)
+{
+       /* Is the pixmap too large to render to? */
+       return (dst->drawable.width > sna->render.max_3d_size ||
+               dst->drawable.height > sna->render.max_3d_size);
+}
+
+static inline int vertex_space(struct sna *sna)
+{
+       return sna->render.vertex_size - sna->render.vertex_used;
+}
+static inline void vertex_emit(struct sna *sna, float v)
+{
+       assert(sna->render.vertex_used < sna->render.vertex_size);
+       sna->render.vertices[sna->render.vertex_used++] = v;
+}
+static inline void vertex_emit_2s(struct sna *sna, int16_t x, int16_t y)
+{
+       int16_t *v = (int16_t *)&sna->render.vertices[sna->render.vertex_used++];
+       assert(sna->render.vertex_used <= sna->render.vertex_size);
+       v[0] = x;
+       v[1] = y;
+}
+
+static inline float pack_2s(int16_t x, int16_t y)
+{
+       union {
+               struct sna_coordinate p;
+               float f;
+       } u;
+       u.p.x = x;
+       u.p.y = y;
+       return u.f;
+}
+
+static inline int batch_space(struct sna *sna)
+{
+       return sna->kgem.surface - sna->kgem.nbatch - KGEM_BATCH_RESERVED;
+}
+
+static inline void batch_emit(struct sna *sna, uint32_t dword)
+{
+       assert(sna->kgem.mode != KGEM_NONE);
+       assert(sna->kgem.nbatch + KGEM_BATCH_RESERVED < sna->kgem.surface);
+       sna->kgem.batch[sna->kgem.nbatch++] = dword;
+}
+
+static inline void batch_emit_float(struct sna *sna, float f)
+{
+       union {
+               uint32_t dw;
+               float f;
+       } u;
+       u.f = f;
+       batch_emit(sna, u.dw);
+}
+
+static inline bool
+is_gpu(DrawablePtr drawable)
+{
+       struct sna_pixmap *priv = sna_pixmap_from_drawable(drawable);
+
+       if (priv == NULL || priv->clear)
+               return false;
+
+       if (priv->cpu_damage == NULL)
+               return true;
+
+       if (priv->gpu_damage && !priv->gpu_bo->proxy)
+               return true;
+
+       if (priv->cpu_bo && kgem_bo_is_busy(priv->cpu_bo))
+               return true;
+
+       return priv->gpu_bo && kgem_bo_is_busy(priv->gpu_bo);
+}
+
+static inline bool
+too_small(struct sna_pixmap *priv)
+{
+       assert(priv);
+
+       if (priv->gpu_bo)
+               return false;
+
+       if (priv->cpu_bo && kgem_bo_is_busy(priv->cpu_bo))
+               return false;
+
+       return (priv->create & KGEM_CAN_CREATE_GPU) == 0;
+}
+
+static inline bool
+unattached(DrawablePtr drawable)
+{
+       struct sna_pixmap *priv = sna_pixmap_from_drawable(drawable);
+       return priv == NULL || (priv->gpu_damage == NULL && priv->cpu_damage);
+}
+
+static inline bool
+picture_is_gpu(PicturePtr picture)
+{
+       if (!picture || !picture->pDrawable)
+               return false;
+       return is_gpu(picture->pDrawable);
+}
+
+static inline bool sna_blt_compare_depth(DrawablePtr src, DrawablePtr dst)
+{
+       if (src->depth == dst->depth)
+               return true;
+
+       /* Also allow for the alpha to be discarded on a copy */
+       if (src->bitsPerPixel != dst->bitsPerPixel)
+               return false;
+
+       if (dst->depth == 24 && src->depth == 32)
+               return true;
+
+       /* Note that a depth-16 pixmap is r5g6b5, not x1r5g5b5. */
+
+       return false;
+}
+
+static inline struct kgem_bo *
+sna_render_get_alpha_gradient(struct sna *sna)
+{
+       return kgem_bo_reference(sna->render.alpha_cache.cache_bo);
+}
+
+static inline void
+sna_render_picture_extents(PicturePtr p, BoxRec *box)
+{
+       box->x1 = p->pDrawable->x;
+       box->y1 = p->pDrawable->y;
+       box->x2 = p->pDrawable->x + p->pDrawable->width;
+       box->y2 = p->pDrawable->y + p->pDrawable->height;
+
+       if (box->x1 < p->pCompositeClip->extents.x1)
+               box->x1 = p->pCompositeClip->extents.x1;
+       if (box->y1 < p->pCompositeClip->extents.y1)
+               box->y1 = p->pCompositeClip->extents.y1;
+
+       if (box->x2 > p->pCompositeClip->extents.x2)
+               box->x2 = p->pCompositeClip->extents.x2;
+       if (box->y2 > p->pCompositeClip->extents.y2)
+               box->y2 = p->pCompositeClip->extents.y2;
+}
+
+static inline void
+sna_render_reduce_damage(struct sna_composite_op *op,
+                        int dst_x, int dst_y,
+                        int width, int height)
+{
+       BoxRec r;
+
+       if (op->damage == NULL || *op->damage == NULL)
+               return;
+
+       if (DAMAGE_IS_ALL(*op->damage)) {
+               DBG(("%s: damage-all, dicarding damage\n",
+                    __FUNCTION__));
+               op->damage = NULL;
+               return;
+       }
+
+       if (width == 0 || height == 0)
+               return;
+
+       r.x1 = dst_x + op->dst.x;
+       r.x2 = r.x1 + width;
+
+       r.y1 = dst_y + op->dst.y;
+       r.y2 = r.y1 + height;
+
+       if (sna_damage_contains_box__no_reduce(*op->damage, &r)) {
+               DBG(("%s: damage contains render extents, dicarding damage\n",
+                    __FUNCTION__));
+               op->damage = NULL;
+       }
+}
+
+inline static uint32_t
+color_convert(uint32_t pixel,
+             uint32_t src_format,
+             uint32_t dst_format)
+{
+       DBG(("%s: src=%08x [%08x]\n", __FUNCTION__, pixel, src_format));
+
+       if (src_format != dst_format) {
+               uint16_t red, green, blue, alpha;
+
+               if (!sna_get_rgba_from_pixel(pixel,
+                                            &red, &green, &blue, &alpha,
+                                            src_format))
+                       return 0;
+
+               if (!sna_get_pixel_from_rgba(&pixel,
+                                            red, green, blue, alpha,
+                                            dst_format))
+                       return 0;
+       }
+
+       DBG(("%s: dst=%08x [%08x]\n", __FUNCTION__, pixel, dst_format));
+       return pixel;
+}
+
+#endif /* SNA_RENDER_INLINE_H */
diff --git a/src/sna/sna_stream.c b/src/sna/sna_stream.c
new file mode 100644 (file)
index 0000000..1a0a86b
--- /dev/null
@@ -0,0 +1,140 @@
+/*
+ * Copyright © 2011 Intel 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.
+ *
+ * Authors:
+ *    Chris Wilson <chris@chris-wilson.co.uk>
+ *
+ */
+
+#include "sna.h"
+#include "sna_render.h"
+#include "brw/brw.h"
+
+int sna_static_stream_init(struct sna_static_stream *stream)
+{
+       stream->used = 0;
+       stream->size = 64*1024;
+
+       stream->data = malloc(stream->size);
+       return stream->data != NULL;
+}
+
+static uint32_t sna_static_stream_alloc(struct sna_static_stream *stream,
+                                       uint32_t len, uint32_t align)
+{
+       uint32_t offset = ALIGN(stream->used, align);
+       uint32_t size = offset + len;
+
+       if (size > stream->size) {
+               do
+                       stream->size *= 2;
+               while (stream->size < size);
+
+               stream->data = realloc(stream->data, stream->size);
+       }
+
+       stream->used = size;
+       return offset;
+}
+
+uint32_t sna_static_stream_add(struct sna_static_stream *stream,
+                              const void *data, uint32_t len, uint32_t align)
+{
+       uint32_t offset = sna_static_stream_alloc(stream, len, align);
+       memcpy(stream->data + offset, data, len);
+       return offset;
+}
+
+void *sna_static_stream_map(struct sna_static_stream *stream,
+                           uint32_t len, uint32_t align)
+{
+       uint32_t offset = sna_static_stream_alloc(stream, len, align);
+       return memset(stream->data + offset, 0, len);
+}
+
+uint32_t sna_static_stream_offsetof(struct sna_static_stream *stream, void *ptr)
+{
+       return (uint8_t *)ptr - stream->data;
+}
+
+struct kgem_bo *sna_static_stream_fini(struct sna *sna,
+                                      struct sna_static_stream *stream)
+{
+       struct kgem_bo *bo;
+
+       DBG(("uploaded %d bytes of static state\n", stream->used));
+
+       bo = kgem_create_linear(&sna->kgem, stream->used, 0);
+       if (bo && !kgem_bo_write(&sna->kgem, bo, stream->data, stream->used)) {
+               kgem_bo_destroy(&sna->kgem, bo);
+               return NULL;
+       }
+
+       free(stream->data);
+
+       return bo;
+}
+
+unsigned
+sna_static_stream_compile_sf(struct sna *sna,
+                            struct sna_static_stream *stream,
+                            bool (*compile)(struct brw_compile *))
+{
+       struct brw_compile p;
+
+       brw_compile_init(&p, sna->kgem.gen,
+                        sna_static_stream_map(stream,
+                                              64*sizeof(uint32_t), 64));
+
+       if (!compile(&p)) {
+               stream->used -= 64*sizeof(uint32_t);
+               return 0;
+       }
+
+       assert(p.nr_insn*sizeof(struct brw_instruction) <= 64*sizeof(uint32_t));
+
+       stream->used -= 64*sizeof(uint32_t) - p.nr_insn*sizeof(struct brw_instruction);
+       return sna_static_stream_offsetof(stream, p.store);
+}
+
+unsigned
+sna_static_stream_compile_wm(struct sna *sna,
+                            struct sna_static_stream *stream,
+                            bool (*compile)(struct brw_compile *, int),
+                            int dispatch_width)
+{
+       struct brw_compile p;
+
+       brw_compile_init(&p, sna->kgem.gen,
+                        sna_static_stream_map(stream,
+                                              256*sizeof(uint32_t), 64));
+
+       if (!compile(&p, dispatch_width)) {
+               stream->used -= 256*sizeof(uint32_t);
+               return 0;
+       }
+
+       assert(p.nr_insn*sizeof(struct brw_instruction) <= 256*sizeof(uint32_t));
+
+       stream->used -= 256*sizeof(uint32_t) - p.nr_insn*sizeof(struct brw_instruction);
+       return sna_static_stream_offsetof(stream, p.store);
+}
diff --git a/src/sna/sna_tiling.c b/src/sna/sna_tiling.c
new file mode 100644 (file)
index 0000000..9e70833
--- /dev/null
@@ -0,0 +1,913 @@
+/*
+ * Copyright © 2010 Intel 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.
+ *
+ * Authors:
+ *    Chris Wilson <chris@chris-wilson.co.uk>
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "sna.h"
+#include "sna_render.h"
+#include "fb/fbpict.h"
+
+struct sna_tile_span {
+       BoxRec box;
+       float opacity;
+};
+
+struct sna_tile_state {
+       int op;
+       PicturePtr src, mask, dst;
+       PixmapPtr dst_pixmap;
+       uint32_t dst_format;
+       int16_t src_x, src_y;
+       int16_t mask_x, mask_y;
+       int16_t dst_x, dst_y;
+       int16_t width, height;
+       unsigned flags;
+
+       int rect_count;
+       int rect_size;
+       struct sna_composite_rectangles rects_embedded[16], *rects;
+};
+
+static void
+sna_tiling_composite_add_rect(struct sna_tile_state *tile,
+                             const struct sna_composite_rectangles *r)
+{
+       if (tile->rect_count == tile->rect_size) {
+               struct sna_composite_rectangles *a;
+               int newsize = tile->rect_size * 2;
+
+               if (tile->rects == tile->rects_embedded) {
+                       a = malloc (sizeof(struct sna_composite_rectangles) * newsize);
+                       if (a == NULL)
+                               return;
+
+                       memcpy(a,
+                              tile->rects_embedded,
+                              sizeof(struct sna_composite_rectangles) * tile->rect_count);
+               } else {
+                       a = realloc(tile->rects,
+                                   sizeof(struct sna_composite_rectangles) * newsize);
+                       if (a == NULL)
+                               return;
+               }
+
+               tile->rects = a;
+               tile->rect_size = newsize;
+       }
+
+       tile->rects[tile->rect_count++] = *r;
+}
+
+fastcall static void
+sna_tiling_composite_blt(struct sna *sna,
+                        const struct sna_composite_op *op,
+                        const struct sna_composite_rectangles *r)
+{
+       sna_tiling_composite_add_rect(op->priv, r);
+       (void)sna;
+}
+
+fastcall static void
+sna_tiling_composite_box(struct sna *sna,
+                        const struct sna_composite_op *op,
+                        const BoxRec *box)
+{
+       struct sna_composite_rectangles r;
+
+       r.dst.x = box->x1;
+       r.dst.y = box->y1;
+       r.mask = r.src = r.dst;
+
+       r.width  = box->x2 - box->x1;
+       r.height = box->y2 - box->y1;
+
+       sna_tiling_composite_add_rect(op->priv, &r);
+       (void)sna;
+}
+
+static void
+sna_tiling_composite_boxes(struct sna *sna,
+                          const struct sna_composite_op *op,
+                          const BoxRec *box, int nbox)
+{
+       while (nbox--) {
+               struct sna_composite_rectangles r;
+
+               r.dst.x = box->x1;
+               r.dst.y = box->y1;
+               r.mask = r.src = r.dst;
+
+               r.width  = box->x2 - box->x1;
+               r.height = box->y2 - box->y1;
+
+               sna_tiling_composite_add_rect(op->priv, &r);
+               box++;
+       }
+       (void)sna;
+}
+
+static void
+sna_tiling_composite_done(struct sna *sna,
+                         const struct sna_composite_op *op)
+{
+       struct sna_tile_state *tile = op->priv;
+       struct sna_composite_op tmp;
+       int x, y, n, step;
+
+       /* Use a small step to accommodate enlargement through tile alignment */
+       step = sna->render.max_3d_size;
+       if (tile->dst_x & (8*512 / tile->dst->pDrawable->bitsPerPixel - 1) ||
+           tile->dst_y & 63)
+               step /= 2;
+       while (step * step * 4 > sna->kgem.max_copy_tile_size)
+               step /= 2;
+
+       DBG(("%s -- %dx%d, count=%d, step size=%d\n", __FUNCTION__,
+            tile->width, tile->height, tile->rect_count, step));
+
+       if (tile->rect_count == 0)
+               goto done;
+
+       for (y = 0; y < tile->height; y += step) {
+               int height = step;
+               if (y + height > tile->height)
+                       height = tile->height - y;
+               for (x = 0; x < tile->width; x += step) {
+                       int width = step;
+                       if (x + width > tile->width)
+                               width = tile->width - x;
+                       memset(&tmp, 0, sizeof(tmp));
+                       if (sna->render.composite(sna, tile->op,
+                                                 tile->src, tile->mask, tile->dst,
+                                                 tile->src_x + x,  tile->src_y + y,
+                                                 tile->mask_x + x, tile->mask_y + y,
+                                                 tile->dst_x + x,  tile->dst_y + y,
+                                                 width, height,
+                                                 &tmp)) {
+                               for (n = 0; n < tile->rect_count; n++) {
+                                       const struct sna_composite_rectangles *r = &tile->rects[n];
+                                       int x1, x2, dx, y1, y2, dy;
+
+                                       x1 = r->dst.x - tile->dst_x, dx = 0;
+                                       if (x1 < x)
+                                               dx = x - x1, x1 = x;
+                                       y1 = r->dst.y - tile->dst_y, dy = 0;
+                                       if (y1 < y)
+                                               dy = y - y1, y1 = y;
+
+                                       x2 = r->dst.x + r->width - tile->dst_x;
+                                       if (x2 > x + width)
+                                               x2 = x + width;
+                                       y2 = r->dst.y + r->height - tile->dst_y;
+                                       if (y2 > y + height)
+                                               y2 = y + height;
+
+                                       DBG(("%s: rect[%d] = (%d, %d)x(%d,%d), tile=(%d,%d)x(%d, %d), blt=(%d,%d),(%d,%d), delta=(%d,%d)\n",
+                                            __FUNCTION__, n,
+                                            r->dst.x, r->dst.y,
+                                            r->width, r->height,
+                                            x, y, width, height,
+                                            x1, y1, x2, y2,
+                                            dx, dy));
+
+                                       if (y2 > y1 && x2 > x1) {
+                                               struct sna_composite_rectangles rr;
+                                               rr.src.x = dx + r->src.x;
+                                               rr.src.y = dy + r->src.y;
+
+                                               rr.mask.x = dx + r->mask.x;
+                                               rr.mask.y = dy + r->mask.y;
+
+                                               rr.dst.x = dx + r->dst.x;
+                                               rr.dst.y = dy + r->dst.y;
+
+                                               rr.width  = x2 - x1;
+                                               rr.height = y2 - y1;
+
+                                               tmp.blt(sna, &tmp, &rr);
+                                       }
+                               }
+                               tmp.done(sna, &tmp);
+                       } else {
+                               unsigned int flags;
+                               DBG(("%s -- falback\n", __FUNCTION__));
+
+                               if (tile->op <= PictOpSrc)
+                                       flags = MOVE_WRITE;
+                               else
+                                       flags = MOVE_WRITE | MOVE_READ;
+                               if (!sna_drawable_move_to_cpu(tile->dst->pDrawable,
+                                                             flags))
+                                       goto done;
+                               if (tile->dst->alphaMap &&
+                                   !sna_drawable_move_to_cpu(tile->dst->alphaMap->pDrawable,
+                                                             flags))
+                                       goto done;
+
+                               if (tile->src->pDrawable &&
+                                   !sna_drawable_move_to_cpu(tile->src->pDrawable,
+                                                             MOVE_READ))
+                                       goto done;
+                               if (tile->src->alphaMap &&
+                                   !sna_drawable_move_to_cpu(tile->src->alphaMap->pDrawable,
+                                                             MOVE_READ))
+                                       goto done;
+
+                               if (tile->mask && tile->mask->pDrawable &&
+                                   !sna_drawable_move_to_cpu(tile->mask->pDrawable,
+                                                             MOVE_READ))
+                                       goto done;
+
+                               if (tile->mask && tile->mask->alphaMap &&
+                                   !sna_drawable_move_to_cpu(tile->mask->alphaMap->pDrawable,
+                                                             MOVE_READ))
+                                       goto done;
+
+                               fbComposite(tile->op,
+                                           tile->src, tile->mask, tile->dst,
+                                           tile->src_x + x,  tile->src_y + y,
+                                           tile->mask_x + x, tile->mask_y + y,
+                                           tile->dst_x + x,  tile->dst_y + y,
+                                           width, height);
+                       }
+               }
+       }
+
+done:
+       if (tile->rects != tile->rects_embedded)
+               free(tile->rects);
+       free(tile);
+}
+
+bool
+sna_tiling_composite(uint32_t op,
+                    PicturePtr src,
+                    PicturePtr mask,
+                    PicturePtr dst,
+                    int16_t src_x,  int16_t src_y,
+                    int16_t mask_x, int16_t mask_y,
+                    int16_t dst_x,  int16_t dst_y,
+                    int16_t width,  int16_t height,
+                    struct sna_composite_op *tmp)
+{
+       struct sna_tile_state *tile;
+       struct sna_pixmap *priv;
+
+       DBG(("%s size=(%d, %d), tile=%d\n",
+            __FUNCTION__, width, height,
+            to_sna_from_drawable(dst->pDrawable)->render.max_3d_size));
+
+       priv = sna_pixmap(get_drawable_pixmap(dst->pDrawable));
+       if (priv == NULL || priv->gpu_bo == NULL)
+               return false;
+
+       tile = malloc(sizeof(*tile));
+       if (!tile)
+               return false;
+
+       tile->op = op;
+
+       tile->src  = src;
+       tile->mask = mask;
+       tile->dst  = dst;
+
+       tile->src_x = src_x;
+       tile->src_y = src_y;
+       tile->mask_x = mask_x;
+       tile->mask_y = mask_y;
+       tile->dst_x = dst_x;
+       tile->dst_y = dst_y;
+       tile->width = width;
+       tile->height = height;
+       tile->rects = tile->rects_embedded;
+       tile->rect_count = 0;
+       tile->rect_size = ARRAY_SIZE(tile->rects_embedded);
+
+       tmp->blt   = sna_tiling_composite_blt;
+       tmp->box   = sna_tiling_composite_box;
+       tmp->boxes = sna_tiling_composite_boxes;
+       tmp->done  = sna_tiling_composite_done;
+
+       tmp->priv = tile;
+       return true;
+}
+
+fastcall static void
+sna_tiling_composite_spans_box(struct sna *sna,
+                              const struct sna_composite_spans_op *op,
+                              const BoxRec *box, float opacity)
+{
+       struct sna_tile_state *tile = op->base.priv;
+       struct sna_tile_span *a;
+
+       if (tile->rect_count == tile->rect_size) {
+               int newsize = tile->rect_size * 2;
+
+               if (tile->rects == tile->rects_embedded) {
+                       a = malloc (sizeof(struct sna_tile_span) * newsize);
+                       if (a == NULL)
+                               return;
+
+                       memcpy(a,
+                              tile->rects_embedded,
+                              sizeof(struct sna_tile_span) * tile->rect_count);
+               } else {
+                       a = realloc(tile->rects,
+                                   sizeof(struct sna_tile_span) * newsize);
+                       if (a == NULL)
+                               return;
+               }
+
+               tile->rects = (void *)a;
+               tile->rect_size = newsize;
+       } else
+               a = (void *)tile->rects;
+
+       a[tile->rect_count].box = *box;
+       a[tile->rect_count].opacity = opacity;
+       tile->rect_count++;
+       (void)sna;
+}
+
+static void
+sna_tiling_composite_spans_boxes(struct sna *sna,
+                                const struct sna_composite_spans_op *op,
+                                const BoxRec *box, int nbox, float opacity)
+{
+       while (nbox--)
+               sna_tiling_composite_spans_box(sna, op->base.priv, box++, opacity);
+       (void)sna;
+}
+
+fastcall static void
+sna_tiling_composite_spans_done(struct sna *sna,
+                               const struct sna_composite_spans_op *op)
+{
+       struct sna_tile_state *tile = op->base.priv;
+       struct sna_composite_spans_op tmp;
+       int x, y, n, step;
+       bool force_fallback = false;
+
+       /* Use a small step to accommodate enlargement through tile alignment */
+       step = sna->render.max_3d_size;
+       if (tile->dst_x & (8*512 / tile->dst->pDrawable->bitsPerPixel - 1) ||
+           tile->dst_y & 63)
+               step /= 2;
+       while (step * step * 4 > sna->kgem.max_copy_tile_size)
+               step /= 2;
+
+       DBG(("%s -- %dx%d, count=%d, step size=%d\n", __FUNCTION__,
+            tile->width, tile->height, tile->rect_count, step));
+
+       if (tile->rect_count == 0)
+               goto done;
+
+       for (y = 0; y < tile->height; y += step) {
+               int height = step;
+               if (y + height > tile->height)
+                       height = tile->height - y;
+               for (x = 0; x < tile->width; x += step) {
+                       const struct sna_tile_span *r = (void *)tile->rects;
+                       int width = step;
+                       if (x + width > tile->width)
+                               width = tile->width - x;
+                       if (!force_fallback &&
+                           sna->render.composite_spans(sna, tile->op,
+                                                       tile->src, tile->dst,
+                                                       tile->src_x + x,  tile->src_y + y,
+                                                       tile->dst_x + x,  tile->dst_y + y,
+                                                       width, height, tile->flags,
+                                                       memset(&tmp, 0, sizeof(tmp)))) {
+                               for (n = 0; n < tile->rect_count; n++) {
+                                       BoxRec b;
+
+                                       b.x1 = r->box.x1 - tile->dst_x;
+                                       if (b.x1 < x)
+                                               b.x1 = x;
+
+                                       b.y1 = r->box.y1 - tile->dst_y;
+                                       if (b.y1 < y)
+                                               b.y1 = y;
+
+                                       b.x2 = r->box.x2 - tile->dst_x;
+                                       if (b.x2 > x + width)
+                                               b.x2 = x + width;
+
+                                       b.y2 = r->box.y2 - tile->dst_y;
+                                       if (b.y2 > y + height)
+                                               b.y2 = y + height;
+
+                                       DBG(("%s: rect[%d] = (%d, %d)x(%d,%d), tile=(%d,%d)x(%d, %d), blt=(%d,%d),(%d,%d)\n",
+                                            __FUNCTION__, n,
+                                            r->box.x1, r->box.y1,
+                                            r->box.x2-r->box.x1, r->box.y2-r->box.y1,
+                                            x, y, width, height,
+                                            b.x1, b.y1, b.x2, b.y2));
+
+                                       if (b.y2 > b.y1 && b.x2 > b.x1)
+                                               tmp.box(sna, &tmp, &b, r->opacity);
+                                       r++;
+                               }
+                               tmp.done(sna, &tmp);
+                       } else {
+                               unsigned int flags;
+
+                               DBG(("%s -- falback\n", __FUNCTION__));
+
+                               if (tile->op <= PictOpSrc)
+                                       flags = MOVE_WRITE;
+                               else
+                                       flags = MOVE_WRITE | MOVE_READ;
+                               if (!sna_drawable_move_to_cpu(tile->dst->pDrawable,
+                                                             flags))
+                                       goto done;
+                               if (tile->dst->alphaMap &&
+                                   !sna_drawable_move_to_cpu(tile->dst->alphaMap->pDrawable,
+                                                             flags))
+                                       goto done;
+
+                               if (tile->src->pDrawable &&
+                                   !sna_drawable_move_to_cpu(tile->src->pDrawable,
+                                                             MOVE_READ))
+                                       goto done;
+                               if (tile->src->alphaMap &&
+                                   !sna_drawable_move_to_cpu(tile->src->alphaMap->pDrawable,
+                                                             MOVE_READ))
+                                       goto done;
+
+                               for (n = 0; n < tile->rect_count; n++) {
+                                       BoxRec b;
+
+                                       b.x1 = r->box.x1 - tile->dst_x;
+                                       if (b.x1 < x)
+                                               b.x1 = x;
+
+                                       b.y1 = r->box.y1 - tile->dst_y;
+                                       if (b.y1 < y)
+                                               b.y1 = y;
+
+                                       b.x2 = r->box.x2 - tile->dst_x;
+                                       if (b.x2 > x + width)
+                                               b.x2 = x + width;
+
+                                       b.y2 = r->box.y2 - tile->dst_y;
+                                       if (b.y2 > y + height)
+                                               b.y2 = y + height;
+
+                                       DBG(("%s: rect[%d] = (%d, %d)x(%d,%d), tile=(%d,%d)x(%d, %d), blt=(%d,%d),(%d,%d)\n",
+                                            __FUNCTION__, n,
+                                            r->box.x1, r->box.y1,
+                                            r->box.x2-r->box.x1, r->box.y2-r->box.y1,
+                                            x, y, width, height,
+                                            b.x1, b.y1, b.x2, b.y2));
+
+                                       if (b.y2 > b.y1 && b.x2 > b.x1) {
+                                               xRenderColor alpha;
+                                               PicturePtr mask;
+                                               int error;
+
+                                               alpha.red = alpha.green = alpha.blue = 0;
+                                               alpha.alpha = r->opacity * 0xffff;
+
+                                               mask = CreateSolidPicture(0, &alpha, &error);
+                                               if (!mask)
+                                                       goto done;
+
+                                               fbComposite(tile->op,
+                                                           tile->src, mask, tile->dst,
+                                                           tile->src_x + x,  tile->src_y + y,
+                                                           0, 0,
+                                                           tile->dst_x + x,  tile->dst_y + y,
+                                                           width, height);
+
+                                               FreePicture(mask, 0);
+                                       }
+                                       r++;
+                               }
+
+                               force_fallback = true;
+                       }
+               }
+       }
+
+done:
+       if (tile->rects != tile->rects_embedded)
+               free(tile->rects);
+       free(tile);
+}
+
+bool
+sna_tiling_composite_spans(uint32_t op,
+                          PicturePtr src,
+                          PicturePtr dst,
+                          int16_t src_x,  int16_t src_y,
+                          int16_t dst_x,  int16_t dst_y,
+                          int16_t width,  int16_t height,
+                          unsigned flags,
+                          struct sna_composite_spans_op *tmp)
+{
+       struct sna_tile_state *tile;
+       struct sna_pixmap *priv;
+
+       DBG(("%s size=(%d, %d), tile=%d\n",
+            __FUNCTION__, width, height,
+            to_sna_from_drawable(dst->pDrawable)->render.max_3d_size));
+
+       priv = sna_pixmap(get_drawable_pixmap(dst->pDrawable));
+       if (priv == NULL || priv->gpu_bo == NULL)
+               return false;
+
+       tile = malloc(sizeof(*tile));
+       if (!tile)
+               return false;
+
+       tile->op = op;
+       tile->flags = flags;
+
+       tile->src  = src;
+       tile->mask = NULL;
+       tile->dst  = dst;
+
+       tile->src_x = src_x;
+       tile->src_y = src_y;
+       tile->mask_x = 0;
+       tile->mask_y = 0;
+       tile->dst_x = dst_x;
+       tile->dst_y = dst_y;
+       tile->width = width;
+       tile->height = height;
+       tile->rects = tile->rects_embedded;
+       tile->rect_count = 0;
+       tile->rect_size = ARRAY_SIZE(tile->rects_embedded);
+
+       tmp->box   = sna_tiling_composite_spans_box;
+       tmp->boxes = sna_tiling_composite_spans_boxes;
+       tmp->done  = sna_tiling_composite_spans_done;
+
+       tmp->base.priv = tile;
+       return true;
+}
+
+bool
+sna_tiling_fill_boxes(struct sna *sna,
+                     CARD8 op,
+                     PictFormat format,
+                     const xRenderColor *color,
+                     PixmapPtr dst, struct kgem_bo *dst_bo,
+                     const BoxRec *box, int n)
+{
+       RegionRec region, tile, this;
+       struct kgem_bo *bo;
+       int step;
+       bool ret = false;
+
+       pixman_region_init_rects(&region, box, n);
+
+       /* Use a small step to accommodate enlargement through tile alignment */
+       step = sna->render.max_3d_size;
+       if (region.extents.x1 & (8*512 / dst->drawable.bitsPerPixel - 1) ||
+           region.extents.y1 & 63)
+               step /= 2;
+       while (step * step * 4 > sna->kgem.max_copy_tile_size)
+               step /= 2;
+
+       DBG(("%s (op=%d, format=%x, color=(%04x,%04x,%04x, %04x), tile.size=%d, box=%dx[(%d, %d), (%d, %d)])\n",
+            __FUNCTION__, op, (int)format,
+            color->red, color->green, color->blue, color->alpha,
+            step, n,
+            region.extents.x1, region.extents.y1,
+            region.extents.x2, region.extents.y2));
+
+       for (tile.extents.y1 = tile.extents.y2 = region.extents.y1;
+            tile.extents.y2 < region.extents.y2;
+            tile.extents.y1 = tile.extents.y2) {
+               tile.extents.y2 = tile.extents.y1 + step;
+               if (tile.extents.y2 > region.extents.y2)
+                       tile.extents.y2 = region.extents.y2;
+
+               for (tile.extents.x1 = tile.extents.x2 = region.extents.x1;
+                    tile.extents.x2 < region.extents.x2;
+                    tile.extents.x1 = tile.extents.x2) {
+                       PixmapRec tmp;
+
+                       tile.extents.x2 = tile.extents.x1 + step;
+                       if (tile.extents.x2 > region.extents.x2)
+                               tile.extents.x2 = region.extents.x2;
+
+                       tile.data = NULL;
+
+                       RegionNull(&this);
+                       RegionIntersect(&this, &region, &tile);
+                       if (!RegionNotEmpty(&this))
+                               continue;
+
+                       tmp.drawable.width  = this.extents.x2 - this.extents.x1;
+                       tmp.drawable.height = this.extents.y2 - this.extents.y1;
+                       tmp.drawable.depth  = dst->drawable.depth;
+                       tmp.drawable.bitsPerPixel = dst->drawable.bitsPerPixel;
+                       tmp.devPrivate.ptr = NULL;
+
+                       bo = kgem_create_2d(&sna->kgem,
+                                           tmp.drawable.width,
+                                           tmp.drawable.height,
+                                           dst->drawable.bitsPerPixel,
+                                           kgem_choose_tiling(&sna->kgem,
+                                                              I915_TILING_X,
+                                                              tmp.drawable.width,
+                                                              tmp.drawable.height,
+                                                              dst->drawable.bitsPerPixel),
+                                           CREATE_TEMPORARY);
+                       if (bo) {
+                               int16_t dx = this.extents.x1;
+                               int16_t dy = this.extents.y1;
+
+                               assert(kgem_bo_can_blt(&sna->kgem, bo));
+
+                               if (!sna->render.copy_boxes(sna, GXcopy,
+                                                            dst, dst_bo, 0, 0,
+                                                            &tmp, bo, -dx, -dy,
+                                                            REGION_RECTS(&this), REGION_NUM_RECTS(&this), 0))
+                                       goto err;
+
+                               RegionTranslate(&this, -dx, -dy);
+                               if (!sna->render.fill_boxes(sna, op, format, color,
+                                                            &tmp, bo,
+                                                            REGION_RECTS(&this), REGION_NUM_RECTS(&this)))
+                                       goto err;
+
+                               if (!sna->render.copy_boxes(sna, GXcopy,
+                                                            &tmp, bo, 0, 0,
+                                                            dst, dst_bo, dx, dy,
+                                                            REGION_RECTS(&this), REGION_NUM_RECTS(&this), 0))
+                                       goto err;
+
+                               kgem_bo_destroy(&sna->kgem, bo);
+                       }
+                       RegionUninit(&this);
+               }
+       }
+
+       ret = true;
+       goto done;
+err:
+       kgem_bo_destroy(&sna->kgem, bo);
+       RegionUninit(&this);
+done:
+       pixman_region_fini(&region);
+       return ret;
+}
+
+bool sna_tiling_blt_copy_boxes(struct sna *sna, uint8_t alu,
+                              struct kgem_bo *src_bo, int16_t src_dx, int16_t src_dy,
+                              struct kgem_bo *dst_bo, int16_t dst_dx, int16_t dst_dy,
+                              int bpp, const BoxRec *box, int nbox)
+{
+       RegionRec region, tile, this;
+       struct kgem_bo *bo;
+       int step;
+       bool ret = false;
+
+       if (!kgem_bo_can_blt(&sna->kgem, src_bo) ||
+           !kgem_bo_can_blt(&sna->kgem, dst_bo)) {
+               /* XXX */
+               DBG(("%s: tiling blt fail: src?=%d, dst?=%d\n",
+                    __FUNCTION__,
+                    kgem_bo_can_blt(&sna->kgem, src_bo),
+                    kgem_bo_can_blt(&sna->kgem, dst_bo)));
+               return false;
+       }
+
+       pixman_region_init_rects(&region, box, nbox);
+
+       /* Use a small step to accommodate enlargement through tile alignment */
+       step = sna->render.max_3d_size;
+       if (region.extents.x1 & (8*512 / bpp - 1) || region.extents.y1 & 63)
+               step /= 2;
+       while (step * step * 4 > sna->kgem.max_copy_tile_size)
+               step /= 2;
+
+       DBG(("%s (alu=%d), tile.size=%d, box=%dx[(%d, %d), (%d, %d)])\n",
+            __FUNCTION__, alu, step, nbox,
+            region.extents.x1, region.extents.y1,
+            region.extents.x2, region.extents.y2));
+
+       for (tile.extents.y1 = tile.extents.y2 = region.extents.y1;
+            tile.extents.y2 < region.extents.y2;
+            tile.extents.y1 = tile.extents.y2) {
+               tile.extents.y2 = tile.extents.y1 + step;
+               if (tile.extents.y2 > region.extents.y2)
+                       tile.extents.y2 = region.extents.y2;
+
+               for (tile.extents.x1 = tile.extents.x2 = region.extents.x1;
+                    tile.extents.x2 < region.extents.x2;
+                    tile.extents.x1 = tile.extents.x2) {
+                       int w, h;
+
+                       tile.extents.x2 = tile.extents.x1 + step;
+                       if (tile.extents.x2 > region.extents.x2)
+                               tile.extents.x2 = region.extents.x2;
+
+                       tile.data = NULL;
+
+                       RegionNull(&this);
+                       RegionIntersect(&this, &region, &tile);
+                       if (!RegionNotEmpty(&this))
+                               continue;
+
+                       w = this.extents.x2 - this.extents.x1;
+                       h = this.extents.y2 - this.extents.y1;
+                       bo = kgem_create_2d(&sna->kgem, w, h, bpp,
+                                           kgem_choose_tiling(&sna->kgem,
+                                                              I915_TILING_X,
+                                                              w, h, bpp),
+                                           CREATE_TEMPORARY);
+                       if (bo) {
+                               int16_t dx = this.extents.x1;
+                               int16_t dy = this.extents.y1;
+
+                               assert(bo->pitch <= 8192);
+                               assert(bo->tiling != I915_TILING_Y);
+
+                               if (!sna_blt_copy_boxes(sna, alu,
+                                                       src_bo, src_dx, src_dy,
+                                                       bo, -dx, -dy,
+                                                       bpp, REGION_RECTS(&this), REGION_NUM_RECTS(&this)))
+                                       goto err;
+
+                               if (!sna_blt_copy_boxes(sna, alu,
+                                                       bo, -dx, -dy,
+                                                       dst_bo, dst_dx, dst_dy,
+                                                       bpp, REGION_RECTS(&this), REGION_NUM_RECTS(&this)))
+                                       goto err;
+
+                               kgem_bo_destroy(&sna->kgem, bo);
+                       }
+                       RegionUninit(&this);
+               }
+       }
+
+       ret = true;
+       goto done;
+err:
+       kgem_bo_destroy(&sna->kgem, bo);
+       RegionUninit(&this);
+done:
+       pixman_region_fini(&region);
+       return ret;
+}
+
+static bool
+box_intersect(BoxPtr a, const BoxRec *b)
+{
+       if (a->x1 < b->x1)
+               a->x1 = b->x1;
+       if (a->x2 > b->x2)
+               a->x2 = b->x2;
+       if (a->y1 < b->y1)
+               a->y1 = b->y1;
+       if (a->y2 > b->y2)
+               a->y2 = b->y2;
+
+       return a->x1 < a->x2 && a->y1 < a->y2;
+}
+
+bool
+sna_tiling_copy_boxes(struct sna *sna, uint8_t alu,
+                     PixmapPtr src, struct kgem_bo *src_bo, int16_t src_dx, int16_t src_dy,
+                     PixmapPtr dst, struct kgem_bo *dst_bo, int16_t dst_dx, int16_t dst_dy,
+                     const BoxRec *box, int n)
+{
+       BoxRec extents, tile, stack[64], *clipped, *c;
+       PixmapRec p;
+       int i, step, tiling;
+       bool ret = false;
+
+       extents = box[0];
+       for (i = 1; i < n; i++) {
+               if (extents.x1 < box[i].x1)
+                       extents.x1 = box[i].x1;
+               if (extents.y1 < box[i].y1)
+                       extents.y1 = box[i].y1;
+
+               if (extents.x2 > box[i].x2)
+                       extents.x2 = box[i].x2;
+               if (extents.y2 > box[i].y2)
+                       extents.y2 = box[i].y2;
+       }
+
+       step = sna->render.max_3d_size - 4096 / dst->drawable.bitsPerPixel;
+       while (step * step * 4 > sna->kgem.max_upload_tile_size)
+               step /= 2;
+
+       tiling = I915_TILING_X;
+       if (!kgem_bo_can_blt(&sna->kgem, src_bo) ||
+           !kgem_bo_can_blt(&sna->kgem, dst_bo))
+               tiling = I915_TILING_Y;
+
+       DBG(("%s: tiling copy, using %dx%d %c tiles\n",
+            __FUNCTION__, step, step, tiling == I915_TILING_X ? 'X' : 'Y'));
+
+       if (n > ARRAY_SIZE(stack)) {
+               clipped = malloc(sizeof(BoxRec) * n);
+               if (clipped == NULL)
+                       goto tiled_error;
+       } else
+               clipped = stack;
+
+       p.drawable.depth = src->drawable.depth;
+       p.drawable.bitsPerPixel = src->drawable.bitsPerPixel;
+       p.devPrivate.ptr = NULL;
+
+       for (tile.y1 = extents.y1; tile.y1 < extents.y2; tile.y1 = tile.y2) {
+               tile.y2 = tile.y1 + step;
+               if (tile.y2 > extents.y2)
+                       tile.y2 = extents.y2;
+
+               for (tile.x1 = extents.x1; tile.x1 < extents.x2; tile.x1 = tile.x2) {
+                       struct kgem_bo *tmp_bo;
+
+                       tile.x2 = tile.x1 + step;
+                       if (tile.x2 > extents.x2)
+                               tile.x2 = extents.x2;
+
+                       c = clipped;
+                       for (i = 0; i < n; i++) {
+                               *c = box[i];
+                               if (!box_intersect(c, &tile))
+                                       continue;
+
+                               DBG(("%s: box(%d, %d), (%d, %d), src=(%d, %d), dst=(%d, %d)\n",
+                                    __FUNCTION__,
+                                    c->x1, c->y1,
+                                    c->x2, c->y2,
+                                    src_dx, src_dy,
+                                    c->x1 - tile.x1,
+                                    c->y1 - tile.y1));
+                               c++;
+                       }
+                       if (c == clipped)
+                               continue;
+
+                       p.drawable.width  = tile.x2 - tile.x1;
+                       p.drawable.height = tile.y2 - tile.y1;
+
+                       DBG(("%s: tile (%d, %d), (%d, %d)\n",
+                            __FUNCTION__, tile.x1, tile.y1, tile.x2, tile.y2));
+
+                       tmp_bo = kgem_create_2d(&sna->kgem,
+                                               p.drawable.width,
+                                               p.drawable.height,
+                                               p.drawable.bitsPerPixel,
+                                               tiling, CREATE_TEMPORARY);
+                       if (!tmp_bo)
+                               goto tiled_error;
+
+                       i = (sna->render.copy_boxes(sna, GXcopy,
+                                                   src, src_bo, src_dx, src_dy,
+                                                   &p, tmp_bo, -tile.x1, -tile.y1,
+                                                   clipped, c - clipped, 0) &&
+                            sna->render.copy_boxes(sna, alu,
+                                                   &p, tmp_bo, -tile.x1, -tile.y1,
+                                                   dst, dst_bo, dst_dx, dst_dy,
+                                                   clipped, c - clipped, 0));
+
+                       kgem_bo_destroy(&sna->kgem, tmp_bo);
+
+                       if (!i)
+                               goto tiled_error;
+               }
+       }
+
+       ret = true;
+tiled_error:
+       if (clipped != stack)
+               free(clipped);
+
+       return ret;
+}
diff --git a/src/sna/sna_transform.c b/src/sna/sna_transform.c
new file mode 100644 (file)
index 0000000..55cc1ad
--- /dev/null
@@ -0,0 +1,138 @@
+/*
+ * Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.  All Rights Reserved.
+ * Copyright (c) 2005 Jesse Barnes <jbarnes@virtuousgeek.org>
+ * Copyright © 2010 Intel 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.
+ *
+ * Authors:
+ *    Jesse Barns <jbarnes@virtuousgeek.org>
+ *    Chris Wilson <chris@chris-wilson.co.uk>
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "sna.h"
+
+/**
+ * Returns whether the provided transform is affine.
+ *
+ * transform may be null.
+ */
+bool sna_transform_is_affine(const PictTransform *t)
+{
+       if (t == NULL)
+               return true;
+
+       return t->matrix[2][0] == 0 && t->matrix[2][1] == 0;
+}
+
+bool
+sna_transform_is_translation(const PictTransform *t,
+                            pixman_fixed_t *tx,
+                            pixman_fixed_t *ty)
+{
+       if (t == NULL) {
+               *tx = *ty = 0;
+               return true;
+       }
+
+       if (t->matrix[0][0] != IntToxFixed(1) ||
+           t->matrix[0][1] != 0 ||
+           t->matrix[1][0] != 0 ||
+           t->matrix[1][1] != IntToxFixed(1) ||
+           t->matrix[2][0] != 0 ||
+           t->matrix[2][1] != 0 ||
+           t->matrix[2][2] != IntToxFixed(1))
+               return false;
+
+       *tx = t->matrix[0][2];
+       *ty = t->matrix[1][2];
+       return true;
+}
+
+bool
+sna_transform_is_integer_translation(const PictTransform *t, int16_t *tx, int16_t *ty)
+{
+       if (t == NULL) {
+               *tx = *ty = 0;
+               return true;
+       }
+
+       if (t->matrix[0][0] != IntToxFixed(1) ||
+           t->matrix[0][1] != 0 ||
+           t->matrix[1][0] != 0 ||
+           t->matrix[1][1] != IntToxFixed(1) ||
+           t->matrix[2][0] != 0 ||
+           t->matrix[2][1] != 0 ||
+           t->matrix[2][2] != IntToxFixed(1))
+               return false;
+
+       if (pixman_fixed_fraction(t->matrix[0][2]) ||
+           pixman_fixed_fraction(t->matrix[1][2]))
+               return false;
+
+       *tx = pixman_fixed_to_int(t->matrix[0][2]);
+       *ty = pixman_fixed_to_int(t->matrix[1][2]);
+       return true;
+}
+
+/**
+ * Returns the floating-point coordinates transformed by the given transform.
+ */
+void
+sna_get_transformed_coordinates(int x, int y,
+                               const PictTransform *transform,
+                               float *x_out, float *y_out)
+{
+       if (transform == NULL) {
+               *x_out = x;
+               *y_out = y;
+       } else
+               _sna_get_transformed_coordinates(x, y, transform, x_out, y_out);
+}
+
+/**
+ * Returns the un-normalized floating-point coordinates transformed by the given transform.
+ */
+void
+sna_get_transformed_coordinates_3d(int x, int y,
+                                  const PictTransform *transform,
+                                  float *x_out, float *y_out, float *w_out)
+{
+       if (transform == NULL) {
+               *x_out = x;
+               *y_out = y;
+               *w_out = 1;
+       } else {
+               int64_t result[3];
+
+               if (_sna_transform_point(transform, x, y, result)) {
+                       *x_out = result[0] / 65536.;
+                       *y_out = result[1] / 65536.;
+                       *w_out = result[2] / 65536.;
+               } else {
+                       *x_out = *y_out = 0;
+                       *w_out = 1.;
+               }
+       }
+}
diff --git a/src/sna/sna_trapezoids.c b/src/sna/sna_trapezoids.c
new file mode 100644 (file)
index 0000000..482abd3
--- /dev/null
@@ -0,0 +1,7003 @@
+/*
+ * Copyright (c) 2007  David Turner
+ * Copyright (c) 2008  M Joonas Pihlaja
+ * Copyright (c) 2011 Intel 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.
+ *
+ * Authors:
+ *    Chris Wilson <chris@chris-wilson.co.uk>
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "sna.h"
+#include "sna_render.h"
+#include "sna_render_inline.h"
+#include "fb/fbpict.h"
+
+#include <mipict.h>
+
+#if 0
+#define __DBG(x) ErrorF x
+#else
+#define __DBG(x)
+#endif
+
+#define NO_ACCEL 0
+#define FORCE_FALLBACK 0
+#define NO_ALIGNED_BOXES 0
+#define NO_UNALIGNED_BOXES 0
+#define NO_SCAN_CONVERTER 0
+
+/* TODO: Emit unantialiased and MSAA triangles. */
+
+#ifndef MAX
+#define MAX(x,y) ((x) >= (y) ? (x) : (y))
+#endif
+
+#ifndef MIN
+#define MIN(x,y) ((x) <= (y) ? (x) : (y))
+#endif
+
+#define SAMPLES_X 17
+#define SAMPLES_Y 15
+
+#define FAST_SAMPLES_shift 2
+#define FAST_SAMPLES_X (1<<FAST_SAMPLES_shift)
+#define FAST_SAMPLES_Y (1<<FAST_SAMPLES_shift)
+#define FAST_SAMPLES_mask ((1<<FAST_SAMPLES_shift)-1)
+
+typedef void (*span_func_t)(struct sna *sna,
+                           struct sna_composite_spans_op *op,
+                           pixman_region16_t *clip,
+                           const BoxRec *box,
+                           int coverage);
+
+#if HAS_DEBUG_FULL
+static void _assert_pixmap_contains_box(PixmapPtr pixmap, BoxPtr box, const char *function)
+{
+       if (box->x1 < 0 || box->y1 < 0 ||
+           box->x2 > pixmap->drawable.width ||
+           box->y2 > pixmap->drawable.height)
+       {
+               ErrorF("%s: damage box is beyond the pixmap: box=(%d, %d), (%d, %d), pixmap=(%d, %d)\n",
+                      __FUNCTION__,
+                      box->x1, box->y1, box->x2, box->y2,
+                      pixmap->drawable.width,
+                      pixmap->drawable.height);
+               assert(0);
+       }
+}
+#define assert_pixmap_contains_box(p, b) _assert_pixmap_contains_box(p, b, __FUNCTION__)
+#else
+#define assert_pixmap_contains_box(p, b)
+#endif
+
+static void apply_damage(struct sna_composite_op *op, RegionPtr region)
+{
+       DBG(("%s: damage=%p, region=%d\n",
+            __FUNCTION__, op->damage, REGION_NUM_RECTS(region)));
+
+       if (op->damage == NULL)
+               return;
+
+       RegionTranslate(region, op->dst.x, op->dst.y);
+
+       assert_pixmap_contains_box(op->dst.pixmap, RegionExtents(region));
+       sna_damage_add(op->damage, region);
+}
+
+static void _apply_damage_box(struct sna_composite_op *op, const BoxRec *box)
+{
+       BoxRec r;
+
+       r.x1 = box->x1 + op->dst.x;
+       r.x2 = box->x2 + op->dst.x;
+       r.y1 = box->y1 + op->dst.y;
+       r.y2 = box->y2 + op->dst.y;
+
+       assert_pixmap_contains_box(op->dst.pixmap, &r);
+       sna_damage_add_box(op->damage, &r);
+}
+
+inline static void apply_damage_box(struct sna_composite_op *op, const BoxRec *box)
+{
+       if (op->damage)
+               _apply_damage_box(op, box);
+}
+
+typedef int grid_scaled_x_t;
+typedef int grid_scaled_y_t;
+
+#define FAST_SAMPLES_X_TO_INT_FRAC(x, i, f) \
+       _GRID_TO_INT_FRAC_shift(x, i, f, FAST_SAMPLES_shift)
+
+#define FAST_SAMPLES_INT(x) ((x) >> (FAST_SAMPLES_shift))
+#define FAST_SAMPLES_FRAC(x) ((x) & (FAST_SAMPLES_mask))
+
+#define _GRID_TO_INT_FRAC_shift(t, i, f, b) do {       \
+    (f) = FAST_SAMPLES_FRAC(t);                                \
+    (i) = FAST_SAMPLES_INT(t);                         \
+} while (0)
+
+/* A grid area is a real in [0,1] scaled by 2*SAMPLES_X*SAMPLES_Y.  We want
+ * to be able to represent exactly areas of subpixel trapezoids whose
+ * vertices are given in grid scaled coordinates.  The scale factor
+ * comes from needing to accurately represent the area 0.5*dx*dy of a
+ * triangle with base dx and height dy in grid scaled numbers. */
+typedef int grid_area_t;
+#define FAST_SAMPLES_XY (2*FAST_SAMPLES_X*FAST_SAMPLES_Y) /* Unit area on the grid. */
+
+#define AREA_TO_ALPHA(c)  ((c) / (float)FAST_SAMPLES_XY)
+
+struct quorem {
+       int32_t quo;
+       int32_t rem;
+};
+
+struct _pool_chunk {
+       size_t size;
+       struct _pool_chunk *prev_chunk;
+       /* Actual data starts here.      Well aligned for pointers. */
+};
+
+/* A memory pool.  This is supposed to be embedded on the stack or
+ * within some other structure.         It may optionally be followed by an
+ * embedded array from which requests are fulfilled until
+ * malloc needs to be called to allocate a first real chunk. */
+struct pool {
+       struct _pool_chunk *current;
+       struct _pool_chunk *first_free;
+
+       /* Header for the sentinel chunk.  Directly following the pool
+        * struct should be some space for embedded elements from which
+        * the sentinel chunk allocates from. */
+       struct _pool_chunk sentinel[1];
+};
+
+struct edge {
+       struct edge *next, *prev;
+
+       int dir;
+
+       grid_scaled_y_t height_left;
+
+       /* Current x coordinate while the edge is on the active
+        * list. Initialised to the x coordinate of the top of the
+        * edge. The quotient is in grid_scaled_x_t units and the
+        * remainder is mod dy in grid_scaled_y_t units.*/
+       struct quorem x;
+
+       /* Advance of the current x when moving down a subsample line. */
+       struct quorem dxdy;
+       grid_scaled_y_t dy;
+
+       /* The clipped y of the top of the edge. */
+       grid_scaled_y_t ytop;
+
+       /* y2-y1 after orienting the edge downwards.  */
+};
+
+/* Number of subsample rows per y-bucket. Must be SAMPLES_Y. */
+#define EDGE_Y_BUCKET_HEIGHT FAST_SAMPLES_Y
+#define EDGE_Y_BUCKET_INDEX(y, ymin) (((y) - (ymin))/EDGE_Y_BUCKET_HEIGHT)
+
+/* A collection of sorted and vertically clipped edges of the polygon.
+ * Edges are moved from the polygon to an active list while scan
+ * converting. */
+struct polygon {
+       /* The vertical clip extents. */
+       grid_scaled_y_t ymin, ymax;
+
+       /* Array of edges all starting in the same bucket.      An edge is put
+        * into bucket EDGE_BUCKET_INDEX(edge->ytop, polygon->ymin) when
+        * it is added to the polygon. */
+       struct edge **y_buckets;
+       struct edge *y_buckets_embedded[64];
+
+       struct edge edges_embedded[32];
+       struct edge *edges;
+       int num_edges;
+};
+
+/* A cell records the effect on pixel coverage of polygon edges
+ * passing through a pixel.  It contains two accumulators of pixel
+ * coverage.
+ *
+ * Consider the effects of a polygon edge on the coverage of a pixel
+ * it intersects and that of the following one.  The coverage of the
+ * following pixel is the height of the edge multiplied by the width
+ * of the pixel, and the coverage of the pixel itself is the area of
+ * the trapezoid formed by the edge and the right side of the pixel.
+ *
+ * +-----------------------+-----------------------+
+ * |                       |                       |
+ * |                       |                       |
+ * |_______________________|_______________________|
+ * |   \...................|.......................|\
+ * |    \..................|.......................| |
+ * |     \.................|.......................| |
+ * |      \....covered.....|.......................| |
+ * |       \....area.......|.......................| } covered height
+ * |        \..............|.......................| |
+ * |uncovered\.............|.......................| |
+ * |  area    \............|.......................| |
+ * |___________\...........|.......................|/
+ * |                       |                       |
+ * |                       |                       |
+ * |                       |                       |
+ * +-----------------------+-----------------------+
+ *
+ * Since the coverage of the following pixel will always be a multiple
+ * of the width of the pixel, we can store the height of the covered
+ * area instead.  The coverage of the pixel itself is the total
+ * coverage minus the area of the uncovered area to the left of the
+ * edge.  As it's faster to compute the uncovered area we only store
+ * that and subtract it from the total coverage later when forming
+ * spans to blit.
+ *
+ * The heights and areas are signed, with left edges of the polygon
+ * having positive sign and right edges having negative sign.  When
+ * two edges intersect they swap their left/rightness so their
+ * contribution above and below the intersection point must be
+ * computed separately. */
+struct cell {
+       struct cell *next;
+       int x;
+       grid_area_t uncovered_area;
+       grid_scaled_y_t covered_height;
+};
+
+/* A cell list represents the scan line sparsely as cells ordered by
+ * ascending x.  It is geared towards scanning the cells in order
+ * using an internal cursor. */
+struct cell_list {
+       /* Points to the left-most cell in the scan line. */
+       struct cell head, tail;
+
+       struct cell *cursor;
+
+       /* Cells in the cell list are owned by the cell list and are
+        * allocated from this pool.  */
+       struct {
+               struct pool base[1];
+               struct cell embedded[256];
+       } cell_pool;
+};
+
+/* The active list contains edges in the current scan line ordered by
+ * the x-coordinate of the intercept of the edge and the scan line. */
+struct active_list {
+       /* Leftmost edge on the current scan line. */
+       struct edge head, tail;
+
+       /* A lower bound on the height of the active edges is used to
+        * estimate how soon some active edge ends.      We can't advance the
+        * scan conversion by a full pixel row if an edge ends somewhere
+        * within it. */
+       grid_scaled_y_t min_height;
+       int is_vertical;
+};
+
+struct tor {
+    struct polygon     polygon[1];
+    struct active_list active[1];
+    struct cell_list   coverages[1];
+
+    /* Clip box. */
+    grid_scaled_x_t xmin, xmax;
+    grid_scaled_y_t ymin, ymax;
+};
+
+/* Compute the floored division a/b. Assumes / and % perform symmetric
+ * division. */
+inline static struct quorem
+floored_divrem(int a, int b)
+{
+       struct quorem qr;
+       qr.quo = a/b;
+       qr.rem = a%b;
+       if (qr.rem && (a^b)<0) {
+               qr.quo -= 1;
+               qr.rem += b;
+       }
+       return qr;
+}
+
+/* Compute the floored division (x*a)/b. Assumes / and % perform symmetric
+ * division. */
+static struct quorem
+floored_muldivrem(int x, int a, int b)
+{
+       struct quorem qr;
+       long long xa = (long long)x*a;
+       qr.quo = xa/b;
+       qr.rem = xa%b;
+       if (qr.rem && (xa>=0) != (b>=0)) {
+               qr.quo -= 1;
+               qr.rem += b;
+       }
+       return qr;
+}
+
+static inline void
+_pool_chunk_init(struct _pool_chunk *p,
+                struct _pool_chunk *prev_chunk)
+{
+       p->prev_chunk = prev_chunk;
+       p->size = sizeof(*p);
+}
+
+static struct _pool_chunk *
+_pool_chunk_create(struct _pool_chunk *prev_chunk)
+{
+       size_t size = 256*sizeof(struct cell);
+       struct _pool_chunk *p;
+
+       p = malloc(size + sizeof(struct _pool_chunk));
+       if (unlikely (p == NULL))
+               abort();
+
+       _pool_chunk_init(p, prev_chunk);
+       return p;
+}
+
+static void
+pool_init(struct pool *pool)
+{
+       pool->current = pool->sentinel;
+       pool->first_free = NULL;
+       _pool_chunk_init(pool->sentinel, NULL);
+}
+
+static void
+pool_fini(struct pool *pool)
+{
+       struct _pool_chunk *p = pool->current;
+       do {
+               while (NULL != p) {
+                       struct _pool_chunk *prev = p->prev_chunk;
+                       if (p != pool->sentinel)
+                               free(p);
+                       p = prev;
+               }
+               p = pool->first_free;
+               pool->first_free = NULL;
+       } while (NULL != p);
+}
+
+static void *
+_pool_alloc_from_new_chunk(struct pool *pool)
+{
+       struct _pool_chunk *chunk;
+       void *obj;
+
+       chunk = pool->first_free;
+       if (chunk) {
+               pool->first_free = chunk->prev_chunk;
+               _pool_chunk_init(chunk, pool->current);
+       } else {
+               chunk = _pool_chunk_create(pool->current);
+       }
+       pool->current = chunk;
+
+       obj = (unsigned char*)chunk + chunk->size;
+       chunk->size += sizeof(struct cell);
+       return obj;
+}
+
+inline static void *
+pool_alloc(struct pool *pool)
+{
+       struct _pool_chunk *chunk = pool->current;
+
+       if (chunk->size < 256*sizeof(struct cell)+sizeof(*chunk)) {
+               void *obj = (unsigned char*)chunk + chunk->size;
+               chunk->size += sizeof(struct cell);
+               return obj;
+       } else
+               return _pool_alloc_from_new_chunk(pool);
+}
+
+static void
+pool_reset(struct pool *pool)
+{
+       /* Transfer all used chunks to the chunk free list. */
+       struct _pool_chunk *chunk = pool->current;
+       if (chunk != pool->sentinel) {
+               while (chunk->prev_chunk != pool->sentinel)
+                       chunk = chunk->prev_chunk;
+
+               chunk->prev_chunk = pool->first_free;
+               pool->first_free = pool->current;
+       }
+
+       /* Reset the sentinel as the current chunk. */
+       pool->current = pool->sentinel;
+       pool->sentinel->size = sizeof(*chunk);
+}
+
+/* Rewinds the cell list's cursor to the beginning.  After rewinding
+ * we're good to cell_list_find() the cell any x coordinate. */
+inline static void
+cell_list_rewind(struct cell_list *cells)
+{
+       cells->cursor = &cells->head;
+}
+
+static void
+cell_list_init(struct cell_list *cells)
+{
+       pool_init(cells->cell_pool.base);
+       cells->tail.next = NULL;
+       cells->tail.x = INT_MAX;
+       cells->head.x = INT_MIN;
+       cells->head.next = &cells->tail;
+       cell_list_rewind(cells);
+}
+
+static void
+cell_list_fini(struct cell_list *cells)
+{
+       pool_fini(cells->cell_pool.base);
+}
+
+inline static void
+cell_list_reset(struct cell_list *cells)
+{
+       cell_list_rewind(cells);
+       cells->head.next = &cells->tail;
+       pool_reset(cells->cell_pool.base);
+}
+
+static struct cell *
+cell_list_alloc(struct cell_list *cells,
+               struct cell *tail,
+               int x)
+{
+       struct cell *cell;
+
+       cell = pool_alloc(cells->cell_pool.base);
+
+       cell->next = tail->next;
+       tail->next = cell;
+       cell->x = x;
+       cell->uncovered_area = 0;
+       cell->covered_height = 0;
+       return cell;
+}
+
+/* Find a cell at the given x-coordinate.  Returns %NULL if a new cell
+ * needed to be allocated but couldn't be.  Cells must be found with
+ * non-decreasing x-coordinate until the cell list is rewound using
+ * cell_list_rewind(). Ownership of the returned cell is retained by
+ * the cell list. */
+inline static struct cell *
+cell_list_find(struct cell_list *cells, int x)
+{
+       struct cell *tail = cells->cursor;
+
+       if (tail->x == x)
+               return tail;
+
+       do {
+               if (tail->next->x > x)
+                       break;
+
+               tail = tail->next;
+               if (tail->next->x > x)
+                       break;
+
+               tail = tail->next;
+               if (tail->next->x > x)
+                       break;
+
+               tail = tail->next;
+       } while (1);
+
+       if (tail->x != x)
+               tail = cell_list_alloc (cells, tail, x);
+
+       return cells->cursor = tail;
+}
+
+/* Add a subpixel span covering [x1, x2) to the coverage cells. */
+inline static void
+cell_list_add_subspan(struct cell_list *cells,
+                     grid_scaled_x_t x1,
+                     grid_scaled_x_t x2)
+{
+       struct cell *cell;
+       int ix1, fx1;
+       int ix2, fx2;
+
+       FAST_SAMPLES_X_TO_INT_FRAC(x1, ix1, fx1);
+       FAST_SAMPLES_X_TO_INT_FRAC(x2, ix2, fx2);
+
+       __DBG(("%s: x1=%d (%d+%d), x2=%d (%d+%d)\n", __FUNCTION__,
+              x1, ix1, fx1, x2, ix2, fx2));
+
+       cell = cell_list_find(cells, ix1);
+       if (ix1 != ix2) {
+               cell->uncovered_area += 2*fx1;
+               ++cell->covered_height;
+
+               cell = cell_list_find(cells, ix2);
+               cell->uncovered_area -= 2*fx2;
+               --cell->covered_height;
+       } else
+               cell->uncovered_area += 2*(fx1-fx2);
+}
+
+inline static void
+cell_list_add_span(struct cell_list *cells,
+                  grid_scaled_x_t x1,
+                  grid_scaled_x_t x2)
+{
+       struct cell *cell;
+       int ix1, fx1;
+       int ix2, fx2;
+
+       FAST_SAMPLES_X_TO_INT_FRAC(x1, ix1, fx1);
+       FAST_SAMPLES_X_TO_INT_FRAC(x2, ix2, fx2);
+
+       __DBG(("%s: x1=%d (%d+%d), x2=%d (%d+%d)\n", __FUNCTION__,
+              x1, ix1, fx1, x2, ix2, fx2));
+
+       cell = cell_list_find(cells, ix1);
+       if (ix1 != ix2) {
+               cell->uncovered_area += 2*fx1*FAST_SAMPLES_Y;
+               cell->covered_height += FAST_SAMPLES_Y;
+
+               cell = cell_list_find(cells, ix2);
+               cell->uncovered_area -= 2*fx2*FAST_SAMPLES_Y;
+               cell->covered_height -= FAST_SAMPLES_Y;
+       } else
+               cell->uncovered_area += 2*(fx1-fx2)*FAST_SAMPLES_Y;
+}
+
+static void
+polygon_fini(struct polygon *polygon)
+{
+       if (polygon->y_buckets != polygon->y_buckets_embedded)
+               free(polygon->y_buckets);
+
+       if (polygon->edges != polygon->edges_embedded)
+               free(polygon->edges);
+}
+
+static int
+polygon_init(struct polygon *polygon,
+            int num_edges,
+            grid_scaled_y_t ymin,
+            grid_scaled_y_t ymax)
+{
+       unsigned h = ymax - ymin;
+       unsigned num_buckets =
+               EDGE_Y_BUCKET_INDEX(ymax+EDGE_Y_BUCKET_HEIGHT-1, ymin);
+
+       if (unlikely(h > 0x7FFFFFFFU - EDGE_Y_BUCKET_HEIGHT))
+               goto bail_no_mem; /* even if you could, you wouldn't want to. */
+
+       polygon->edges = polygon->edges_embedded;
+       polygon->y_buckets = polygon->y_buckets_embedded;
+
+       polygon->num_edges = 0;
+       if (num_edges > (int)ARRAY_SIZE(polygon->edges_embedded)) {
+               polygon->edges = malloc(sizeof(struct edge)*num_edges);
+               if (unlikely(NULL == polygon->edges))
+                       goto bail_no_mem;
+       }
+
+       if (num_buckets >= ARRAY_SIZE(polygon->y_buckets_embedded)) {
+               polygon->y_buckets = malloc((1+num_buckets)*sizeof(struct edge *));
+               if (unlikely(NULL == polygon->y_buckets))
+                       goto bail_no_mem;
+       }
+       memset(polygon->y_buckets, 0, num_buckets * sizeof(struct edge *));
+       polygon->y_buckets[num_buckets] = (void *)-1;
+
+       polygon->ymin = ymin;
+       polygon->ymax = ymax;
+       return 0;
+
+bail_no_mem:
+       polygon_fini(polygon);
+       return -1;
+}
+
+static void
+_polygon_insert_edge_into_its_y_bucket(struct polygon *polygon, struct edge *e)
+{
+       unsigned ix = EDGE_Y_BUCKET_INDEX(e->ytop, polygon->ymin);
+       struct edge **ptail = &polygon->y_buckets[ix];
+       e->next = *ptail;
+       *ptail = e;
+}
+
+inline static void
+polygon_add_edge(struct polygon *polygon,
+                grid_scaled_x_t x1,
+                grid_scaled_x_t x2,
+                grid_scaled_y_t y1,
+                grid_scaled_y_t y2,
+                grid_scaled_y_t top,
+                grid_scaled_y_t bottom,
+                int dir)
+{
+       struct edge *e = &polygon->edges[polygon->num_edges++];
+       grid_scaled_x_t dx = x2 - x1;
+       grid_scaled_y_t dy = y2 - y1;
+       grid_scaled_y_t ytop, ybot;
+       grid_scaled_y_t ymin = polygon->ymin;
+       grid_scaled_y_t ymax = polygon->ymax;
+
+       __DBG(("%s: edge=(%d [%d.%d], %d [%d.%d]), (%d [%d.%d], %d [%d.%d]), top=%d [%d.%d], bottom=%d [%d.%d], dir=%d\n",
+              __FUNCTION__,
+              x1, FAST_SAMPLES_INT(x1), FAST_SAMPLES_FRAC(x1),
+              y1, FAST_SAMPLES_INT(y1), FAST_SAMPLES_FRAC(y1),
+              x2, FAST_SAMPLES_INT(x2), FAST_SAMPLES_FRAC(x2),
+              y2, FAST_SAMPLES_INT(y2), FAST_SAMPLES_FRAC(y2),
+              top, FAST_SAMPLES_INT(top), FAST_SAMPLES_FRAC(top),
+              bottom, FAST_SAMPLES_INT(bottom), FAST_SAMPLES_FRAC(bottom),
+              dir));
+       assert (dy > 0);
+
+       e->dy = dy;
+       e->dir = dir;
+
+       ytop = top >= ymin ? top : ymin;
+       ybot = bottom <= ymax ? bottom : ymax;
+       e->ytop = ytop;
+       e->height_left = ybot - ytop;
+
+       if (dx == 0) {
+               e->x.quo = x1;
+               e->x.rem = 0;
+               e->dy = 0;
+               e->dxdy.quo = 0;
+               e->dxdy.rem = 0;
+       } else {
+               e->dxdy = floored_divrem(dx, dy);
+               if (ytop == y1) {
+                       e->x.quo = x1;
+                       e->x.rem = 0;
+               } else {
+                       e->x = floored_muldivrem(ytop - y1, dx, dy);
+                       e->x.quo += x1;
+               }
+       }
+
+       _polygon_insert_edge_into_its_y_bucket(polygon, e);
+
+       e->x.rem -= dy; /* Bias the remainder for faster edge advancement. */
+}
+
+inline static void
+polygon_add_line(struct polygon *polygon,
+                const xPointFixed *p1,
+                const xPointFixed *p2)
+{
+       struct edge *e = &polygon->edges[polygon->num_edges];
+       grid_scaled_x_t dx = p2->x - p1->x;
+       grid_scaled_y_t dy = p2->y - p1->y;
+       grid_scaled_y_t top, bot;
+
+       if (dy == 0)
+               return;
+
+       __DBG(("%s: line=(%d, %d), (%d, %d)\n",
+              __FUNCTION__, (int)p1->x, (int)p1->y, (int)p2->x, (int)p2->y));
+
+       e->dir = 1;
+       if (dy < 0) {
+               const xPointFixed *t;
+
+               dx = -dx;
+               dy = -dy;
+
+               e->dir = -1;
+
+               t = p1;
+               p1 = p2;
+               p2 = t;
+       }
+       assert (dy > 0);
+       e->dy = dy;
+
+       top = MAX(p1->y, polygon->ymin);
+       bot = MIN(p2->y, polygon->ymax);
+       if (bot <= top)
+               return;
+
+       e->ytop = top;
+       e->height_left = bot - top;
+
+       if (dx == 0) {
+               e->x.quo = p1->x;
+               e->x.rem = -dy;
+               e->dxdy.quo = 0;
+               e->dxdy.rem = 0;
+               e->dy = 0;
+       } else {
+               e->dxdy = floored_divrem(dx, dy);
+               if (top == p1->y) {
+                       e->x.quo = p1->x;
+                       e->x.rem = -dy;
+               } else {
+                       e->x = floored_muldivrem(top - p1->y, dx, dy);
+                       e->x.quo += p1->x;
+                       e->x.rem -= dy;
+               }
+       }
+
+       if (polygon->num_edges > 0) {
+               struct edge *prev = &polygon->edges[polygon->num_edges-1];
+               /* detect degenerate triangles inserted into tristrips */
+               if (e->dir == -prev->dir &&
+                   e->ytop == prev->ytop &&
+                   e->height_left == prev->height_left &&
+                   e->x.quo == prev->x.quo &&
+                   e->x.rem == prev->x.rem &&
+                   e->dxdy.quo == prev->dxdy.quo &&
+                   e->dxdy.rem == prev->dxdy.rem) {
+                       unsigned ix = EDGE_Y_BUCKET_INDEX(e->ytop,
+                                                         polygon->ymin);
+                       polygon->y_buckets[ix] = prev->next;
+                       polygon->num_edges--;
+                       return;
+               }
+       }
+
+       _polygon_insert_edge_into_its_y_bucket(polygon, e);
+       polygon->num_edges++;
+}
+
+static void
+active_list_reset(struct active_list *active)
+{
+       active->head.height_left = INT_MAX;
+       active->head.x.quo = INT_MIN;
+       active->head.dy = 0;
+       active->head.prev = NULL;
+       active->head.next = &active->tail;
+       active->tail.prev = &active->head;
+       active->tail.next = NULL;
+       active->tail.x.quo = INT_MAX;
+       active->tail.height_left = INT_MAX;
+       active->tail.dy = 0;
+       active->min_height = INT_MAX;
+       active->is_vertical = 1;
+}
+
+static struct edge *
+merge_sorted_edges(struct edge *head_a, struct edge *head_b)
+{
+       struct edge *head, **next, *prev;
+       int32_t x;
+
+       prev = head_a->prev;
+       next = &head;
+       if (head_a->x.quo <= head_b->x.quo) {
+               head = head_a;
+       } else {
+               head = head_b;
+               head_b->prev = prev;
+               goto start_with_b;
+       }
+
+       do {
+               x = head_b->x.quo;
+               while (head_a != NULL && head_a->x.quo <= x) {
+                       prev = head_a;
+                       next = &head_a->next;
+                       head_a = head_a->next;
+               }
+
+               head_b->prev = prev;
+               *next = head_b;
+               if (head_a == NULL)
+                       return head;
+
+start_with_b:
+               x = head_a->x.quo;
+               while (head_b != NULL && head_b->x.quo <= x) {
+                       prev = head_b;
+                       next = &head_b->next;
+                       head_b = head_b->next;
+               }
+
+               head_a->prev = prev;
+               *next = head_a;
+               if (head_b == NULL)
+                       return head;
+       } while (1);
+}
+
+static struct edge *
+sort_edges(struct edge  *list,
+          unsigned int  level,
+          struct edge **head_out)
+{
+       struct edge *head_other, *remaining;
+       unsigned int i;
+
+       head_other = list->next;
+       if (head_other == NULL) {
+               *head_out = list;
+               return NULL;
+       }
+
+       remaining = head_other->next;
+       if (list->x.quo <= head_other->x.quo) {
+               *head_out = list;
+               head_other->next = NULL;
+       } else {
+               *head_out = head_other;
+               head_other->prev = list->prev;
+               head_other->next = list;
+               list->prev = head_other;
+               list->next = NULL;
+       }
+
+       for (i = 0; i < level && remaining; i++) {
+               remaining = sort_edges(remaining, i, &head_other);
+               *head_out = merge_sorted_edges(*head_out, head_other);
+       }
+
+       return remaining;
+}
+
+static struct edge *
+merge_unsorted_edges (struct edge *head, struct edge *unsorted)
+{
+       sort_edges (unsorted, UINT_MAX, &unsorted);
+       return merge_sorted_edges (head, unsorted);
+}
+
+/* Test if the edges on the active list can be safely advanced by a
+ * full row without intersections or any edges ending. */
+inline static bool
+can_full_step(struct active_list *active)
+{
+       const struct edge *e;
+
+       /* Recomputes the minimum height of all edges on the active
+        * list if we have been dropping edges. */
+       if (active->min_height <= 0) {
+               int min_height = INT_MAX;
+               int is_vertical = 1;
+
+               for (e = active->head.next; &active->tail != e; e = e->next) {
+                       if (e->height_left < min_height)
+                               min_height = e->height_left;
+                       is_vertical &= e->dy == 0;
+               }
+
+               active->is_vertical = is_vertical;
+               active->min_height = min_height;
+       }
+
+       if (active->min_height < FAST_SAMPLES_Y)
+               return false;
+
+       return active->is_vertical;
+}
+
+inline static void
+merge_edges(struct active_list *active, struct edge *edges)
+{
+       active->head.next = merge_unsorted_edges (active->head.next, edges);
+}
+
+inline static void
+fill_buckets(struct active_list *active,
+            struct edge *edge,
+            struct edge **buckets)
+{
+       int min_height = active->min_height;
+       int is_vertical = active->is_vertical;
+
+       while (edge) {
+               struct edge *next = edge->next;
+               struct edge **b = &buckets[edge->ytop & (FAST_SAMPLES_Y-1)];
+               if (*b)
+                       (*b)->prev = edge;
+               edge->next = *b;
+               edge->prev = NULL;
+               *b = edge;
+               if (edge->height_left < min_height)
+                       min_height = edge->height_left;
+               is_vertical &= edge->dy == 0;
+               edge = next;
+       }
+
+       active->is_vertical = is_vertical;
+       active->min_height = min_height;
+}
+
+inline static void
+nonzero_subrow(struct active_list *active, struct cell_list *coverages)
+{
+       struct edge *edge = active->head.next;
+       grid_scaled_x_t prev_x = INT_MIN;
+       int winding = 0, xstart = INT_MIN;
+
+       cell_list_rewind (coverages);
+
+       while (&active->tail != edge) {
+               struct edge *next = edge->next;
+
+               winding += edge->dir;
+               if (0 == winding) {
+                       if (edge->next->x.quo != edge->x.quo) {
+                               cell_list_add_subspan(coverages,
+                                                     xstart, edge->x.quo);
+                               xstart = INT_MIN;
+                       }
+               } else if (xstart < 0)
+                       xstart = edge->x.quo;
+
+               if (--edge->height_left) {
+                       if (edge->dy) {
+                               edge->x.quo += edge->dxdy.quo;
+                               edge->x.rem += edge->dxdy.rem;
+                               if (edge->x.rem >= 0) {
+                                       ++edge->x.quo;
+                                       edge->x.rem -= edge->dy;
+                               }
+                       }
+
+                       if (edge->x.quo < prev_x) {
+                               struct edge *pos = edge->prev;
+                               pos->next = next;
+                               next->prev = pos;
+                               do {
+                                       pos = pos->prev;
+                               } while (edge->x.quo < pos->x.quo);
+                               pos->next->prev = edge;
+                               edge->next = pos->next;
+                               edge->prev = pos;
+                               pos->next = edge;
+                       } else
+                               prev_x = edge->x.quo;
+               } else {
+                       edge->prev->next = next;
+                       next->prev = edge->prev;
+                       active->min_height = -1;
+               }
+
+               edge = next;
+       }
+}
+
+static void
+nonzero_row(struct active_list *active, struct cell_list *coverages)
+{
+       struct edge *left = active->head.next;
+
+       assert(active->is_vertical);
+
+       while (&active->tail != left) {
+               struct edge *right;
+               int winding = left->dir;
+
+               left->height_left -= FAST_SAMPLES_Y;
+               if (! left->height_left) {
+                       left->prev->next = left->next;
+                       left->next->prev = left->prev;
+               }
+
+               right = left->next;
+               do {
+                       right->height_left -= FAST_SAMPLES_Y;
+                       if (!right->height_left) {
+                               right->prev->next = right->next;
+                               right->next->prev = right->prev;
+                       }
+
+                       winding += right->dir;
+                       if (0 == winding)
+                               break;
+
+                       right = right->next;
+               } while (1);
+
+               cell_list_add_span(coverages, left->x.quo, right->x.quo);
+               left = right->next;
+       }
+}
+
+static void
+tor_fini(struct tor *converter)
+{
+       polygon_fini(converter->polygon);
+       cell_list_fini(converter->coverages);
+}
+
+static int
+tor_init(struct tor *converter, const BoxRec *box, int num_edges)
+{
+       __DBG(("%s: (%d, %d),(%d, %d) x (%d, %d), num_edges=%d\n",
+              __FUNCTION__,
+              box->x1, box->y1, box->x2, box->y2,
+              FAST_SAMPLES_X, FAST_SAMPLES_Y,
+              num_edges));
+
+       converter->xmin = box->x1;
+       converter->ymin = box->y1;
+       converter->xmax = box->x2;
+       converter->ymax = box->y2;
+
+       cell_list_init(converter->coverages);
+       active_list_reset(converter->active);
+       return polygon_init(converter->polygon,
+                           num_edges,
+                           box->y1 * FAST_SAMPLES_Y,
+                           box->y2 * FAST_SAMPLES_Y);
+}
+
+static void
+tor_add_edge(struct tor *converter,
+            const xTrapezoid *t,
+            const xLineFixed *edge,
+            int dir)
+{
+       polygon_add_edge(converter->polygon,
+                        edge->p1.x, edge->p2.x,
+                        edge->p1.y, edge->p2.y,
+                        t->top, t->bottom,
+                        dir);
+}
+
+static void
+step_edges(struct active_list *active, int count)
+{
+       struct edge *edge;
+
+       count *= FAST_SAMPLES_Y;
+       for (edge = active->head.next; edge != &active->tail; edge = edge->next) {
+               edge->height_left -= count;
+               if (! edge->height_left) {
+                       edge->prev->next = edge->next;
+                       edge->next->prev = edge->prev;
+               }
+       }
+}
+
+static void
+tor_blt_span(struct sna *sna,
+            struct sna_composite_spans_op *op,
+            pixman_region16_t *clip,
+            const BoxRec *box,
+            int coverage)
+{
+       __DBG(("%s: %d -> %d @ %d\n", __FUNCTION__, box->x1, box->x2, coverage));
+
+       op->box(sna, op, box, AREA_TO_ALPHA(coverage));
+       apply_damage_box(&op->base, box);
+}
+
+static void
+tor_blt_span__no_damage(struct sna *sna,
+                       struct sna_composite_spans_op *op,
+                       pixman_region16_t *clip,
+                       const BoxRec *box,
+                       int coverage)
+{
+       __DBG(("%s: %d -> %d @ %d\n", __FUNCTION__, box->x1, box->x2, coverage));
+
+       op->box(sna, op, box, AREA_TO_ALPHA(coverage));
+}
+
+static void
+tor_blt_span_clipped(struct sna *sna,
+                    struct sna_composite_spans_op *op,
+                    pixman_region16_t *clip,
+                    const BoxRec *box,
+                    int coverage)
+{
+       pixman_region16_t region;
+       float opacity;
+
+       opacity = AREA_TO_ALPHA(coverage);
+       __DBG(("%s: %d -> %d @ %f\n", __FUNCTION__, box->x1, box->x2, opacity));
+
+       pixman_region_init_rects(&region, box, 1);
+       RegionIntersect(&region, &region, clip);
+       if (REGION_NUM_RECTS(&region)) {
+               op->boxes(sna, op,
+                         REGION_RECTS(&region),
+                         REGION_NUM_RECTS(&region),
+                         opacity);
+               apply_damage(&op->base, &region);
+       }
+       pixman_region_fini(&region);
+}
+
+static void
+tor_blt_span_mono(struct sna *sna,
+                 struct sna_composite_spans_op *op,
+                 pixman_region16_t *clip,
+                 const BoxRec *box,
+                 int coverage)
+{
+       if (coverage < FAST_SAMPLES_XY/2)
+               return;
+
+       tor_blt_span(sna, op, clip, box, FAST_SAMPLES_XY);
+}
+
+static void
+tor_blt_span_mono_clipped(struct sna *sna,
+                         struct sna_composite_spans_op *op,
+                         pixman_region16_t *clip,
+                         const BoxRec *box,
+                         int coverage)
+{
+       if (coverage < FAST_SAMPLES_XY/2)
+               return;
+
+       tor_blt_span_clipped(sna, op, clip, box, FAST_SAMPLES_XY);
+}
+
+static void
+tor_blt_span_mono_unbounded(struct sna *sna,
+                           struct sna_composite_spans_op *op,
+                           pixman_region16_t *clip,
+                           const BoxRec *box,
+                           int coverage)
+{
+       tor_blt_span(sna, op, clip, box,
+                    coverage < FAST_SAMPLES_XY/2 ? 0 : FAST_SAMPLES_XY);
+}
+
+static void
+tor_blt_span_mono_unbounded_clipped(struct sna *sna,
+                                   struct sna_composite_spans_op *op,
+                                   pixman_region16_t *clip,
+                                   const BoxRec *box,
+                                   int coverage)
+{
+       tor_blt_span_clipped(sna, op, clip, box,
+                            coverage < FAST_SAMPLES_XY/2 ? 0 : FAST_SAMPLES_XY);
+}
+
+static void
+tor_blt(struct sna *sna,
+       struct sna_composite_spans_op *op,
+       pixman_region16_t *clip,
+       void (*span)(struct sna *sna,
+                    struct sna_composite_spans_op *op,
+                    pixman_region16_t *clip,
+                    const BoxRec *box,
+                    int coverage),
+       struct cell_list *cells,
+       int y, int height,
+       int xmin, int xmax,
+       int unbounded)
+{
+       struct cell *cell = cells->head.next;
+       BoxRec box;
+       int cover = 0;
+
+       /* Skip cells to the left of the clip region. */
+       while (cell->x < xmin) {
+               __DBG(("%s: skipping cell (%d, %d, %d)\n",
+                      __FUNCTION__,
+                      cell->x, cell->covered_height, cell->uncovered_area));
+
+               cover += cell->covered_height;
+               cell = cell->next;
+       }
+       cover *= FAST_SAMPLES_X*2;
+
+       box.y1 = y;
+       box.y2 = y + height;
+       box.x1 = xmin;
+
+       /* Form the spans from the coverages and areas. */
+       for (; cell != NULL; cell = cell->next) {
+               int x = cell->x;
+
+               if (x >= xmax)
+                       break;
+
+               __DBG(("%s: cell=(%d, %d, %d), cover=%d, max=%d\n", __FUNCTION__,
+                      cell->x, cell->covered_height, cell->uncovered_area,
+                      cover, xmax));
+
+               if (cell->covered_height || cell->uncovered_area) {
+                       box.x2 = x;
+                       if (box.x2 > box.x1 && (unbounded || cover)) {
+                               __DBG(("%s: span (%d, %d)x(%d, %d) @ %d\n", __FUNCTION__,
+                                      box.x1, box.y1,
+                                      box.x2 - box.x1,
+                                      box.y2 - box.y1,
+                                      cover));
+                               span(sna, op, clip, &box, cover);
+                       }
+                       box.x1 = box.x2;
+                       cover += cell->covered_height*FAST_SAMPLES_X*2;
+               }
+
+               if (cell->uncovered_area) {
+                       int area = cover - cell->uncovered_area;
+                       box.x2 = x + 1;
+                       if (unbounded || area) {
+                               __DBG(("%s: span (%d, %d)x(%d, %d) @ %d\n", __FUNCTION__,
+                                      box.x1, box.y1,
+                                      box.x2 - box.x1,
+                                      box.y2 - box.y1,
+                                      area));
+                               span(sna, op, clip, &box, area);
+                       }
+                       box.x1 = box.x2;
+               }
+       }
+
+       box.x2 = xmax;
+       if (box.x2 > box.x1 && (unbounded || cover)) {
+               __DBG(("%s: span (%d, %d)x(%d, %d) @ %d\n", __FUNCTION__,
+                      box.x1, box.y1,
+                      box.x2 - box.x1,
+                      box.y2 - box.y1,
+                      cover));
+               span(sna, op, clip, &box, cover);
+       }
+}
+
+static void
+tor_blt_empty(struct sna *sna,
+             struct sna_composite_spans_op *op,
+             pixman_region16_t *clip,
+             void (*span)(struct sna *sna,
+                          struct sna_composite_spans_op *op,
+                          pixman_region16_t *clip,
+                          const BoxRec *box,
+                          int coverage),
+             int y, int height,
+             int xmin, int xmax)
+{
+       BoxRec box;
+
+       box.x1 = xmin;
+       box.x2 = xmax;
+       box.y1 = y;
+       box.y2 = y + height;
+
+       span(sna, op, clip, &box, 0);
+}
+
+static void
+tor_render(struct sna *sna,
+          struct tor *converter,
+          struct sna_composite_spans_op *op,
+          pixman_region16_t *clip,
+          void (*span)(struct sna *sna,
+                       struct sna_composite_spans_op *op,
+                       pixman_region16_t *clip,
+                       const BoxRec *box,
+                       int coverage),
+          int unbounded)
+{
+       int ymin = converter->ymin;
+       int xmin = converter->xmin;
+       int xmax = converter->xmax;
+       int i, j, h = converter->ymax - ymin;
+       struct polygon *polygon = converter->polygon;
+       struct cell_list *coverages = converter->coverages;
+       struct active_list *active = converter->active;
+       struct edge *buckets[FAST_SAMPLES_Y] = { 0 };
+
+       __DBG(("%s: unbounded=%d\n", __FUNCTION__, unbounded));
+
+       /* Render each pixel row. */
+       for (i = 0; i < h; i = j) {
+               int do_full_step = 0;
+
+               j = i + 1;
+
+               /* Determine if we can ignore this row or use the full pixel
+                * stepper. */
+               if (!polygon->y_buckets[i]) {
+                       if (active->head.next == &active->tail) {
+                               active->min_height = INT_MAX;
+                               active->is_vertical = 1;
+                               for (; !polygon->y_buckets[j]; j++)
+                                       ;
+                               __DBG(("%s: no new edges and no exisiting edges, skipping, %d -> %d\n",
+                                      __FUNCTION__, i, j));
+
+                               if (unbounded)
+                                       tor_blt_empty(sna, op, clip, span, i+ymin, j-i, xmin, xmax);
+                               continue;
+                       }
+
+                       do_full_step = can_full_step(active);
+               }
+
+               __DBG(("%s: y=%d [%d], do_full_step=%d, new edges=%d, min_height=%d, vertical=%d\n",
+                      __FUNCTION__,
+                      i, i+ymin, do_full_step,
+                      polygon->y_buckets[i] != NULL,
+                      active->min_height,
+                      active->is_vertical));
+               if (do_full_step) {
+                       assert(active->is_vertical);
+                       nonzero_row(active, coverages);
+
+                       while (polygon->y_buckets[j] == NULL &&
+                              active->min_height >= 2*FAST_SAMPLES_Y)
+                       {
+                               active->min_height -= FAST_SAMPLES_Y;
+                               j++;
+                       }
+                       if (j != i + 1)
+                               step_edges(active, j - (i + 1));
+
+                       __DBG(("%s: vertical edges, full step (%d, %d)\n",
+                              __FUNCTION__,  i, j));
+               } else {
+                       grid_scaled_y_t suby;
+
+                       fill_buckets(active, polygon->y_buckets[i], buckets);
+
+                       /* Subsample this row. */
+                       for (suby = 0; suby < FAST_SAMPLES_Y; suby++) {
+                               if (buckets[suby]) {
+                                       merge_edges(active, buckets[suby]);
+                                       buckets[suby] = NULL;
+                               }
+
+                               nonzero_subrow(active, coverages);
+                       }
+               }
+
+               if (coverages->head.next != &coverages->tail) {
+                       tor_blt(sna, op, clip, span, coverages,
+                               i+ymin, j-i, xmin, xmax,
+                               unbounded);
+                       cell_list_reset(coverages);
+               } else if (unbounded)
+                       tor_blt_empty(sna, op, clip, span, i+ymin, j-i, xmin, xmax);
+
+               active->min_height -= FAST_SAMPLES_Y;
+       }
+}
+
+static void
+inplace_row(struct active_list *active, uint8_t *row, int width)
+{
+       struct edge *left = active->head.next;
+
+       assert(active->is_vertical);
+
+       while (&active->tail != left) {
+               struct edge *right;
+               int winding = left->dir;
+               grid_scaled_x_t lfx, rfx;
+               int lix, rix;
+
+               left->height_left -= FAST_SAMPLES_Y;
+               if (!left->height_left) {
+                       left->prev->next = left->next;
+                       left->next->prev = left->prev;
+               }
+
+               right = left->next;
+               do {
+                       right->height_left -= FAST_SAMPLES_Y;
+                       if (!right->height_left) {
+                               right->prev->next = right->next;
+                               right->next->prev = right->prev;
+                       }
+
+                       winding += right->dir;
+                       if (0 == winding && right->x.quo != right->next->x.quo)
+                               break;
+
+                       right = right->next;
+               } while (1);
+
+               if (left->x.quo < 0) {
+                       lix = lfx = 0;
+               } else if (left->x.quo >= width * FAST_SAMPLES_X) {
+                       lix = width;
+                       lfx = 0;
+               } else
+                       FAST_SAMPLES_X_TO_INT_FRAC(left->x.quo, lix, lfx);
+
+               if (right->x.quo < 0) {
+                       rix = rfx = 0;
+               } else if (right->x.quo >= width * FAST_SAMPLES_X) {
+                       rix = width;
+                       rfx = 0;
+               } else
+                       FAST_SAMPLES_X_TO_INT_FRAC(right->x.quo, rix, rfx);
+               if (lix == rix) {
+                       if (rfx != lfx) {
+                               assert(lix < width);
+                               row[lix] += (rfx-lfx) * 256 / FAST_SAMPLES_X;
+                       }
+               } else {
+                       assert(lix < width);
+                       if (lfx == 0)
+                               row[lix] = 0xff;
+                       else
+                               row[lix] += 256 - lfx * 256 / FAST_SAMPLES_X;
+
+                       assert(rix <= width);
+                       if (rfx) {
+                               assert(rix < width);
+                               row[rix] += rfx * 256 / FAST_SAMPLES_X;
+                       }
+
+                       if (rix > ++lix) {
+                               uint8_t *r = row + lix;
+                               rix -= lix;
+#if 0
+                               if (rix == 1)
+                                       *row = 0xff;
+                               else
+                                       memset(row, 0xff, rix);
+#else
+                               if ((uintptr_t)r & 1 && rix) {
+                                       *r++ = 0xff;
+                                       rix--;
+                               }
+                               if ((uintptr_t)r & 2 && rix >= 2) {
+                                       *(uint16_t *)r = 0xffff;
+                                       r += 2;
+                                       rix -= 2;
+                               }
+                               if ((uintptr_t)r & 4 && rix >= 4) {
+                                       *(uint32_t *)r = 0xffffffff;
+                                       r += 4;
+                                       rix -= 4;
+                               }
+                               while (rix >= 8) {
+                                       *(uint64_t *)r = 0xffffffffffffffff;
+                                       r += 8;
+                                       rix -= 8;
+                               }
+                               if (rix & 4) {
+                                       *(uint32_t *)r = 0xffffffff;
+                                       r += 4;
+                               }
+                               if (rix & 2) {
+                                       *(uint16_t *)r = 0xffff;
+                                       r += 2;
+                               }
+                               if (rix & 1)
+                                       *r = 0xff;
+#endif
+                       }
+               }
+
+               left = right->next;
+       }
+}
+
+inline static void
+inplace_subrow(struct active_list *active, int8_t *row,
+              int width, int *min, int *max)
+{
+       struct edge *edge = active->head.next;
+       grid_scaled_x_t prev_x = INT_MIN;
+       int winding = 0, xstart = INT_MIN;
+
+       while (&active->tail != edge) {
+               struct edge *next = edge->next;
+
+               winding += edge->dir;
+               if (0 == winding) {
+                       if (edge->next->x.quo != edge->x.quo) {
+                               if (edge->x.quo <= xstart) {
+                                       xstart = INT_MIN;
+                               } else  {
+                                       grid_scaled_x_t fx;
+                                       int ix;
+
+                                       if (xstart < FAST_SAMPLES_X * width) {
+                                               FAST_SAMPLES_X_TO_INT_FRAC(xstart, ix, fx);
+                                               if (ix < *min)
+                                                       *min = ix;
+
+                                               row[ix++] += FAST_SAMPLES_X - fx;
+                                               if (fx && ix < width)
+                                                       row[ix] += fx;
+                                       }
+
+                                       xstart = edge->x.quo;
+                                       if (xstart < FAST_SAMPLES_X * width) {
+                                               FAST_SAMPLES_X_TO_INT_FRAC(xstart, ix, fx);
+                                               row[ix] -= FAST_SAMPLES_X - fx;
+                                               if (fx && ix + 1 < width)
+                                                       row[++ix] -= fx;
+
+                                               if (ix >= *max)
+                                                       *max = ix + 1;
+
+                                               xstart = INT_MIN;
+                                       } else
+                                               *max = width;
+                               }
+                       }
+               } else if (xstart < 0) {
+                       xstart = MAX(edge->x.quo, 0);
+               }
+
+               if (--edge->height_left) {
+                       if (edge->dy) {
+                               edge->x.quo += edge->dxdy.quo;
+                               edge->x.rem += edge->dxdy.rem;
+                               if (edge->x.rem >= 0) {
+                                       ++edge->x.quo;
+                                       edge->x.rem -= edge->dy;
+                               }
+                       }
+
+                       if (edge->x.quo < prev_x) {
+                               struct edge *pos = edge->prev;
+                               pos->next = next;
+                               next->prev = pos;
+                               do {
+                                       pos = pos->prev;
+                               } while (edge->x.quo < pos->x.quo);
+                               pos->next->prev = edge;
+                               edge->next = pos->next;
+                               edge->prev = pos;
+                               pos->next = edge;
+                       } else
+                               prev_x = edge->x.quo;
+               } else {
+                       edge->prev->next = next;
+                       next->prev = edge->prev;
+                       active->min_height = -1;
+               }
+
+               edge = next;
+       }
+}
+
+inline static void
+inplace_end_subrows(struct active_list *active, uint8_t *row,
+                   int8_t *buf, int width)
+{
+       int cover = 0;
+
+       while (width >= 4) {
+               uint32_t dw;
+               int v;
+
+               dw = *(uint32_t *)buf;
+               buf += 4;
+
+               if (dw == 0) {
+                       v = cover * 256 / (FAST_SAMPLES_X * FAST_SAMPLES_Y);
+                       v -= v >> 8;
+                       v |= v << 8;
+                       dw = v | v << 16;
+               } else {
+                       cover += (int8_t)(dw & 0xff);
+                       if (cover) {
+                               assert(cover > 0);
+                               v = cover * 256 / (FAST_SAMPLES_X * FAST_SAMPLES_Y);
+                               v -= v >> 8;
+                               dw >>= 8;
+                               dw |= v << 24;
+                       } else
+                               dw >>= 8;
+
+                       cover += (int8_t)(dw & 0xff);
+                       if (cover) {
+                               assert(cover > 0);
+                               v = cover * 256 / (FAST_SAMPLES_X * FAST_SAMPLES_Y);
+                               v -= v >> 8;
+                               dw >>= 8;
+                               dw |= v << 24;
+                       } else
+                               dw >>= 8;
+
+                       cover += (int8_t)(dw & 0xff);
+                       if (cover) {
+                               assert(cover > 0);
+                               v = cover * 256 / (FAST_SAMPLES_X * FAST_SAMPLES_Y);
+                               v -= v >> 8;
+                               dw >>= 8;
+                               dw |= v << 24;
+                       } else
+                               dw >>= 8;
+
+                       cover += (int8_t)(dw & 0xff);
+                       if (cover) {
+                               assert(cover > 0);
+                               v = cover * 256 / (FAST_SAMPLES_X * FAST_SAMPLES_Y);
+                               v -= v >> 8;
+                               dw >>= 8;
+                               dw |= v << 24;
+                       } else
+                               dw >>= 8;
+               }
+
+               *(uint32_t *)row = dw;
+               row += 4;
+               width -= 4;
+       }
+
+       while (width--) {
+               int v;
+
+               cover += *buf++;
+               assert(cover >= 0);
+
+               v = cover * 256 / (FAST_SAMPLES_X * FAST_SAMPLES_Y);
+               v -= v >> 8;
+               *row++ = v;
+       }
+}
+
+#define TOR_INPLACE_SIZE 128
+static void
+tor_inplace(struct tor *converter, PixmapPtr scratch, int mono, uint8_t *buf)
+{
+       int i, j, h = converter->ymax;
+       struct polygon *polygon = converter->polygon;
+       struct active_list *active = converter->active;
+       struct edge *buckets[FAST_SAMPLES_Y] = { 0 };
+       uint8_t *row = scratch->devPrivate.ptr;
+       int stride = scratch->devKind;
+       int width = scratch->drawable.width;
+
+       __DBG(("%s: mono=%d, buf?=%d\n", __FUNCTION__, mono, buf != NULL));
+       assert(!mono);
+       assert(converter->ymin == 0);
+       assert(converter->xmin == 0);
+       assert(scratch->drawable.depth == 8);
+
+       /* Render each pixel row. */
+       for (i = 0; i < h; i = j) {
+               int do_full_step = 0;
+               void *ptr = buf ?: row;
+
+               j = i + 1;
+
+               /* Determine if we can ignore this row or use the full pixel
+                * stepper. */
+               if (!polygon->y_buckets[i]) {
+                       if (active->head.next == &active->tail) {
+                               active->min_height = INT_MAX;
+                               active->is_vertical = 1;
+                               for (; !polygon->y_buckets[j]; j++)
+                                       ;
+                               __DBG(("%s: no new edges and no exisiting edges, skipping, %d -> %d\n",
+                                      __FUNCTION__, i, j));
+
+                               memset(row, 0, stride*(j-i));
+                               row += stride*(j-i);
+                               continue;
+                       }
+
+                       do_full_step = can_full_step(active);
+               }
+
+               __DBG(("%s: y=%d, do_full_step=%d, new edges=%d, min_height=%d, vertical=%d\n",
+                      __FUNCTION__,
+                      i, do_full_step,
+                      polygon->y_buckets[i] != NULL,
+                      active->min_height,
+                      active->is_vertical));
+               if (do_full_step) {
+                       assert(active->is_vertical);
+
+                       memset(ptr, 0, width);
+                       inplace_row(active, ptr, width);
+                       if (row != ptr)
+                               memcpy(row, ptr, width);
+
+                       while (polygon->y_buckets[j] == NULL &&
+                              active->min_height >= 2*FAST_SAMPLES_Y)
+                       {
+                               active->min_height -= FAST_SAMPLES_Y;
+                               row += stride;
+                               memcpy(row, ptr, width);
+                               j++;
+                       }
+                       if (j != i + 1)
+                               step_edges(active, j - (i + 1));
+
+                       __DBG(("%s: vertical edges, full step (%d, %d)\n",
+                              __FUNCTION__,  i, j));
+               } else {
+                       grid_scaled_y_t suby;
+                       int min = width, max = 0;
+
+                       fill_buckets(active, polygon->y_buckets[i], buckets);
+
+                       /* Subsample this row. */
+                       memset(ptr, 0, width);
+                       for (suby = 0; suby < FAST_SAMPLES_Y; suby++) {
+                               if (buckets[suby]) {
+                                       merge_edges(active, buckets[suby]);
+                                       buckets[suby] = NULL;
+                               }
+
+                               inplace_subrow(active, ptr, width, &min, &max);
+                       }
+                       assert(min >= 0 && max <= width);
+                       memset(row, 0, min);
+                       if (max > min)
+                               inplace_end_subrows(active, row+min, (int8_t*)ptr+min, max-min);
+                       if (max < width)
+                               memset(row+max, 0, width-max);
+               }
+
+               active->min_height -= FAST_SAMPLES_Y;
+               row += stride;
+       }
+}
+
+struct mono_edge {
+       struct mono_edge *next, *prev;
+
+       int32_t height_left;
+       int32_t dir;
+
+       int32_t dy;
+       struct quorem x;
+       struct quorem dxdy;
+};
+
+struct mono_polygon {
+       int num_edges;
+       struct mono_edge *edges;
+       struct mono_edge **y_buckets;
+
+       struct mono_edge *y_buckets_embedded[64];
+       struct mono_edge edges_embedded[32];
+};
+
+struct mono {
+       /* Leftmost edge on the current scan line. */
+       struct mono_edge head, tail;
+       int is_vertical;
+
+       struct sna *sna;
+       struct sna_composite_op op;
+       pixman_region16_t clip;
+
+       fastcall void (*span)(struct mono *, int, int, BoxPtr);
+
+       struct mono_polygon polygon;
+};
+
+#define I(x) pixman_fixed_to_int ((x) + pixman_fixed_1_minus_e/2)
+
+static bool
+mono_polygon_init(struct mono_polygon *polygon, BoxPtr box, int num_edges)
+{
+       unsigned h = box->y2 - box->y1;
+
+       polygon->y_buckets = polygon->y_buckets_embedded;
+       if (h > ARRAY_SIZE (polygon->y_buckets_embedded)) {
+               polygon->y_buckets = malloc (h * sizeof (struct mono_edge *));
+               if (unlikely (NULL == polygon->y_buckets))
+                       return false;
+       }
+
+       polygon->num_edges = 0;
+       polygon->edges = polygon->edges_embedded;
+       if (num_edges > (int)ARRAY_SIZE (polygon->edges_embedded)) {
+               polygon->edges = malloc (num_edges * sizeof (struct mono_edge));
+               if (unlikely (polygon->edges == NULL)) {
+                       if (polygon->y_buckets != polygon->y_buckets_embedded)
+                               free(polygon->y_buckets);
+                       return false;
+               }
+       }
+
+       memset(polygon->y_buckets, 0, h * sizeof (struct edge *));
+       return true;
+}
+
+static void
+mono_polygon_fini(struct mono_polygon *polygon)
+{
+       if (polygon->y_buckets != polygon->y_buckets_embedded)
+               free(polygon->y_buckets);
+
+       if (polygon->edges != polygon->edges_embedded)
+               free(polygon->edges);
+}
+
+static void
+mono_add_line(struct mono *mono,
+             int dst_x, int dst_y,
+             xFixed top, xFixed bottom,
+             xPointFixed *p1, xPointFixed *p2,
+             int dir)
+{
+       struct mono_polygon *polygon = &mono->polygon;
+       struct mono_edge *e;
+       pixman_fixed_t dx;
+       pixman_fixed_t dy;
+       int y, ytop, ybot;
+
+       __DBG(("%s: top=%d, bottom=%d, line=(%d, %d), (%d, %d) delta=%dx%d, dir=%d\n",
+              __FUNCTION__,
+              (int)top, (int)bottom,
+              (int)p1->x, (int)p1->y, (int)p2->x, (int)p2->y,
+              dst_x, dst_y,
+              dir));
+
+       if (top > bottom) {
+               xPointFixed *t;
+
+               y = top;
+               top = bottom;
+               bottom = y;
+
+               t = p1;
+               p1 = p2;
+               p2 = t;
+
+               dir = -dir;
+       }
+
+       y = I(top) + dst_y;
+       ytop = MAX(y, mono->clip.extents.y1);
+
+       y = I(bottom) + dst_y;
+       ybot = MIN(y, mono->clip.extents.y2);
+
+       if (ybot <= ytop) {
+               __DBG(("discard clipped line\n"));
+               return;
+       }
+
+       e = polygon->edges + polygon->num_edges++;
+       e->height_left = ybot - ytop;
+       e->dir = dir;
+
+       dx = p2->x - p1->x;
+       dy = p2->y - p1->y;
+
+       if (dx == 0) {
+               e->x.quo = p1->x;
+               e->x.rem = 0;
+               e->dxdy.quo = 0;
+               e->dxdy.rem = 0;
+               e->dy = 0;
+       } else {
+               e->dxdy = floored_muldivrem (dx, pixman_fixed_1, dy);
+               e->dy = dy;
+
+               e->x = floored_muldivrem ((ytop-dst_y) * pixman_fixed_1 + pixman_fixed_1_minus_e/2 - p1->y,
+                                         dx, dy);
+               e->x.quo += p1->x;
+               e->x.rem -= dy;
+       }
+       e->x.quo += dst_x*pixman_fixed_1;
+
+       {
+               struct mono_edge **ptail = &polygon->y_buckets[ytop - mono->clip.extents.y1];
+               if (*ptail)
+                       (*ptail)->prev = e;
+               e->next = *ptail;
+               e->prev = NULL;
+               *ptail = e;
+       }
+}
+
+static struct mono_edge *
+mono_merge_sorted_edges(struct mono_edge *head_a, struct mono_edge *head_b)
+{
+       struct mono_edge *head, **next, *prev;
+       int32_t x;
+
+       prev = head_a->prev;
+       next = &head;
+       if (head_a->x.quo <= head_b->x.quo) {
+               head = head_a;
+       } else {
+               head = head_b;
+               head_b->prev = prev;
+               goto start_with_b;
+       }
+
+       do {
+               x = head_b->x.quo;
+               while (head_a != NULL && head_a->x.quo <= x) {
+                       prev = head_a;
+                       next = &head_a->next;
+                       head_a = head_a->next;
+               }
+
+               head_b->prev = prev;
+               *next = head_b;
+               if (head_a == NULL)
+                       return head;
+
+start_with_b:
+               x = head_a->x.quo;
+               while (head_b != NULL && head_b->x.quo <= x) {
+                       prev = head_b;
+                       next = &head_b->next;
+                       head_b = head_b->next;
+               }
+
+               head_a->prev = prev;
+               *next = head_a;
+               if (head_b == NULL)
+                       return head;
+       } while (1);
+}
+
+static struct mono_edge *
+mono_sort_edges(struct mono_edge *list,
+               unsigned int level,
+               struct mono_edge **head_out)
+{
+       struct mono_edge *head_other, *remaining;
+       unsigned int i;
+
+       head_other = list->next;
+
+       if (head_other == NULL) {
+               *head_out = list;
+               return NULL;
+       }
+
+       remaining = head_other->next;
+       if (list->x.quo <= head_other->x.quo) {
+               *head_out = list;
+               head_other->next = NULL;
+       } else {
+               *head_out = head_other;
+               head_other->prev = list->prev;
+               head_other->next = list;
+               list->prev = head_other;
+               list->next = NULL;
+       }
+
+       for (i = 0; i < level && remaining; i++) {
+               remaining = mono_sort_edges(remaining, i, &head_other);
+               *head_out = mono_merge_sorted_edges(*head_out, head_other);
+       }
+
+       return remaining;
+}
+
+static struct mono_edge *
+mono_merge_unsorted_edges(struct mono_edge *head, struct mono_edge *unsorted)
+{
+       mono_sort_edges(unsorted, UINT_MAX, &unsorted);
+       return mono_merge_sorted_edges(head, unsorted);
+}
+
+#if 0
+static inline void
+__dbg_mono_edges(const char *function, struct mono_edge *edges)
+{
+       ErrorF("%s: ", function);
+       while (edges) {
+               if (edges->x.quo < INT16_MAX << 16) {
+                       ErrorF("(%d.%06d)+(%d.%06d)x%d, ",
+                              edges->x.quo, edges->x.rem,
+                              edges->dxdy.quo, edges->dxdy.rem,
+                              edges->dy*edges->dir);
+               }
+               edges = edges->next;
+       }
+       ErrorF("\n");
+}
+#define DBG_MONO_EDGES(x) __dbg_mono_edges(__FUNCTION__, x)
+static inline void
+VALIDATE_MONO_EDGES(struct mono_edge *edges)
+{
+       int prev_x = edges->x.quo;
+       while ((edges = edges->next)) {
+               assert(edges->x.quo >= prev_x);
+               prev_x = edges->x.quo;
+       }
+}
+
+#else
+#define DBG_MONO_EDGES(x)
+#define VALIDATE_MONO_EDGES(x)
+#endif
+
+inline static void
+mono_merge_edges(struct mono *c, struct mono_edge *edges)
+{
+       struct mono_edge *e;
+
+       DBG_MONO_EDGES(edges);
+
+       for (e = edges; c->is_vertical && e; e = e->next)
+               c->is_vertical = e->dy == 0;
+
+       c->head.next = mono_merge_unsorted_edges(c->head.next, edges);
+}
+
+fastcall static void
+mono_span(struct mono *c, int x1, int x2, BoxPtr box)
+{
+       __DBG(("%s [%d, %d]\n", __FUNCTION__, x1, x2));
+
+       box->x1 = x1;
+       box->x2 = x2;
+
+       if (c->clip.data) {
+               pixman_region16_t region;
+
+               pixman_region_init_rects(&region, box, 1);
+               RegionIntersect(&region, &region, &c->clip);
+               if (REGION_NUM_RECTS(&region)) {
+                       c->op.boxes(c->sna, &c->op,
+                                   REGION_RECTS(&region),
+                                   REGION_NUM_RECTS(&region));
+                       apply_damage(&c->op, &region);
+               }
+               pixman_region_fini(&region);
+       } else {
+               c->op.box(c->sna, &c->op, box);
+               apply_damage_box(&c->op, box);
+       }
+}
+
+fastcall static void
+mono_span__fast(struct mono *c, int x1, int x2, BoxPtr box)
+{
+       __DBG(("%s [%d, %d]\n", __FUNCTION__, x1, x2));
+
+       box->x1 = x1;
+       box->x2 = x2;
+
+       c->op.box(c->sna, &c->op, box);
+}
+
+inline static void
+mono_row(struct mono *c, int16_t y, int16_t h)
+{
+       struct mono_edge *edge = c->head.next;
+       int prev_x = INT_MIN;
+       int16_t xstart = INT16_MIN;
+       int winding = 0;
+       BoxRec box;
+
+       DBG_MONO_EDGES(edge);
+       VALIDATE_MONO_EDGES(&c->head);
+
+       box.y1 = c->clip.extents.y1 + y;
+       box.y2 = box.y1 + h;
+
+       while (&c->tail != edge) {
+               struct mono_edge *next = edge->next;
+               int16_t xend = I(edge->x.quo);
+
+               if (--edge->height_left) {
+                       if (edge->dy) {
+                               edge->x.quo += edge->dxdy.quo;
+                               edge->x.rem += edge->dxdy.rem;
+                               if (edge->x.rem >= 0) {
+                                       ++edge->x.quo;
+                                       edge->x.rem -= edge->dy;
+                               }
+                       }
+
+                       if (edge->x.quo < prev_x) {
+                               struct mono_edge *pos = edge->prev;
+                               pos->next = next;
+                               next->prev = pos;
+                               do {
+                                       pos = pos->prev;
+                               } while (edge->x.quo < pos->x.quo);
+                               pos->next->prev = edge;
+                               edge->next = pos->next;
+                               edge->prev = pos;
+                               pos->next = edge;
+                       } else
+                               prev_x = edge->x.quo;
+               } else {
+                       edge->prev->next = next;
+                       next->prev = edge->prev;
+               }
+
+               winding += edge->dir;
+               if (winding == 0) {
+                       assert(I(next->x.quo) >= xend);
+                       if (I(next->x.quo) > xend + 1) {
+                               if (xstart < c->clip.extents.x1)
+                                       xstart = c->clip.extents.x1;
+                               if (xend > c->clip.extents.x2)
+                                       xend = c->clip.extents.x2;
+                               if (xend > xstart)
+                                       c->span(c, xstart, xend, &box);
+                               xstart = INT16_MIN;
+                       }
+               } else if (xstart == INT16_MIN)
+                       xstart = xend;
+
+               edge = next;
+       }
+
+       DBG_MONO_EDGES(c->head.next);
+       VALIDATE_MONO_EDGES(&c->head);
+}
+
+static bool
+mono_init(struct mono *c, int num_edges)
+{
+       if (!mono_polygon_init(&c->polygon, &c->clip.extents, num_edges))
+               return false;
+
+       c->head.dy = 0;
+       c->head.height_left = INT_MAX;
+       c->head.x.quo = INT16_MIN << 16;
+       c->head.prev = NULL;
+       c->head.next = &c->tail;
+       c->tail.prev = &c->head;
+       c->tail.next = NULL;
+       c->tail.x.quo = INT16_MAX << 16;
+       c->tail.height_left = INT_MAX;
+       c->tail.dy = 0;
+
+       c->is_vertical = 1;
+
+       return true;
+}
+
+static void
+mono_fini(struct mono *mono)
+{
+       mono_polygon_fini(&mono->polygon);
+}
+
+static void
+mono_step_edges(struct mono *c, int count)
+{
+       struct mono_edge *edge;
+
+       for (edge = c->head.next; edge != &c->tail; edge = edge->next) {
+               edge->height_left -= count;
+               if (! edge->height_left) {
+                       edge->prev->next = edge->next;
+                       edge->next->prev = edge->prev;
+               }
+       }
+}
+
+static void
+mono_render(struct mono *mono)
+{
+       struct mono_polygon *polygon = &mono->polygon;
+       int i, j, h = mono->clip.extents.y2 - mono->clip.extents.y1;
+
+       if (mono->clip.data == NULL && mono->op.damage == NULL)
+               mono->span = mono_span__fast;
+       else
+               mono->span = mono_span;
+
+       for (i = 0; i < h; i = j) {
+               j = i + 1;
+
+               if (polygon->y_buckets[i])
+                       mono_merge_edges(mono, polygon->y_buckets[i]);
+
+               if (mono->is_vertical) {
+                       struct mono_edge *e = mono->head.next;
+                       int min_height = h - i;
+
+                       while (e != &mono->tail) {
+                               if (e->height_left < min_height)
+                                       min_height = e->height_left;
+                               e = e->next;
+                       }
+
+                       while (--min_height >= 1 && polygon->y_buckets[j] == NULL)
+                               j++;
+                       if (j != i + 1)
+                               mono_step_edges(mono, j - (i + 1));
+               }
+
+               mono_row(mono, i, j-i);
+
+               /* XXX recompute after dropping edges? */
+               if (mono->head.next == &mono->tail)
+                       mono->is_vertical = 1;
+       }
+}
+
+static int operator_is_bounded(uint8_t op)
+{
+       switch (op) {
+       case PictOpOver:
+       case PictOpOutReverse:
+       case PictOpAdd:
+               return true;
+       default:
+               return false;
+       }
+}
+
+inline static xFixed
+line_x_for_y(const xLineFixed *l, xFixed y, bool ceil)
+{
+       xFixed_32_32 ex = (xFixed_32_32)(y - l->p1.y) * (l->p2.x - l->p1.x);
+       xFixed d = l->p2.y - l->p1.y;
+
+       if (ceil)
+               ex += (d - 1);
+
+       return l->p1.x + (xFixed) (ex / d);
+}
+
+#define pixman_fixed_integer_floor(V) pixman_fixed_to_int(V)
+#define pixman_fixed_integer_ceil(V) pixman_fixed_to_int(pixman_fixed_ceil(V))
+
+static void
+trapezoids_bounds(int n, const xTrapezoid *t, BoxPtr box)
+{
+       xFixed x1, y1, x2, y2;
+
+       /* XXX need 33 bits... */
+       x1 = y1 = INT_MAX / 2;
+       x2 = y2 = INT_MIN / 2;
+
+       do {
+               xFixed fx1, fx2, v;
+
+               if (!xTrapezoidValid(t))
+                       continue;
+
+               if (t->top < y1)
+                       y1 = t->top;
+               if (t->bottom > y2)
+                       y2 = t->bottom;
+
+               if (((t->left.p1.x - x1) | (t->left.p2.x - x1)) < 0) {
+                       if (pixman_fixed_floor(t->left.p1.x) == pixman_fixed_floor(t->left.p2.x)) {
+                               x1 = pixman_fixed_floor(t->left.p1.x);
+                       } else {
+                               if (t->left.p1.y == t->top)
+                                       fx1 = t->left.p1.x;
+                               else
+                                       fx1 = line_x_for_y(&t->left, t->top, false);
+
+                               if (t->left.p2.y == t->bottom)
+                                       fx2 = t->left.p2.x;
+                               else
+                                       fx2 = line_x_for_y(&t->left, t->bottom, false);
+
+                               v = min(fx1, fx2);
+                               if (v < x1)
+                                       x1 = pixman_fixed_floor(v);
+                       }
+               }
+
+               if (((x2 - t->right.p1.x) | (x2 - t->right.p2.x)) < 0) {
+                       if (pixman_fixed_floor(t->right.p1.x) == pixman_fixed_floor(t->right.p2.x)) {
+                               x2 = pixman_fixed_ceil(t->right.p1.x);
+                       } else {
+                               if (t->right.p1.y == t->top)
+                                       fx1 = t->right.p1.x;
+                               else
+                                       fx1 = line_x_for_y(&t->right, t->top, true);
+
+                               if (t->right.p2.y == t->bottom)
+                                       fx2 = t->right.p2.x;
+                               else
+                                       fx2 = line_x_for_y(&t->right, t->bottom, true);
+
+                               v = max(fx1, fx2);
+                               if (v > x2)
+                                       x2 = pixman_fixed_ceil(v);
+                       }
+               }
+       } while (t++, --n);
+
+       box->x1 = pixman_fixed_to_int(x1);
+       box->x2 = pixman_fixed_to_int(x2);
+       box->y1 = pixman_fixed_integer_floor(y1);
+       box->y2 = pixman_fixed_integer_ceil(y2);
+}
+
+static bool
+is_mono(PicturePtr dst, PictFormatPtr mask)
+{
+       return mask ? mask->depth < 8 : dst->polyEdge==PolyEdgeSharp;
+}
+
+static bool
+trapezoids_inplace_fallback(CARD8 op,
+                           PicturePtr src, PicturePtr dst, PictFormatPtr mask,
+                           int ntrap, xTrapezoid *traps)
+{
+       pixman_image_t *image;
+       BoxRec box;
+       uint32_t color;
+       int dx, dy;
+
+       if (op != PictOpAdd)
+               return false;
+
+       if (is_mono(dst, mask)) {
+               if (dst->format != PICT_a1)
+                       return false;
+       } else {
+               if (dst->format != PICT_a8)
+                       return false;
+       }
+
+       if (!sna_picture_is_solid(src, &color) || (color >> 24) != 0xff) {
+               DBG(("%s: not an opaque solid source\n", __FUNCTION__));
+               return false;
+       }
+
+       box.x1 = dst->pDrawable->x;
+       box.y1 = dst->pDrawable->y;
+       box.x2 = dst->pDrawable->width;
+       box.y2 = dst->pDrawable->height;
+       if (pixman_region_contains_rectangle(dst->pCompositeClip,
+                                            &box) != PIXMAN_REGION_IN) {
+               DBG(("%s: requires clipping, drawable (%d,%d), (%d, %d), clip (%d, %d), (%d, %d)\n", __FUNCTION__,
+                    box.x1, box.y1, box.x2, box.y2,
+                    dst->pCompositeClip->extents.x1,
+                    dst->pCompositeClip->extents.y1,
+                    dst->pCompositeClip->extents.x2,
+                    dst->pCompositeClip->extents.y2));
+               return false;
+       }
+
+       if (is_gpu(dst->pDrawable)) {
+               DBG(("%s: not performing inplace as dst is already on the GPU\n",
+                    __FUNCTION__));
+               return false;
+       }
+
+       DBG(("%s\n", __FUNCTION__));
+
+       image = NULL;
+       if (sna_drawable_move_to_cpu(dst->pDrawable, MOVE_READ | MOVE_WRITE))
+               image = image_from_pict(dst, false, &dx, &dy);
+       if (image) {
+               dx += dst->pDrawable->x;
+               dy += dst->pDrawable->y;
+
+               for (; ntrap; ntrap--, traps++)
+                       pixman_rasterize_trapezoid(image,
+                                                  (pixman_trapezoid_t *)traps,
+                                                  dx, dy);
+
+               pixman_image_unref(image);
+       }
+
+       return true;
+}
+
+static void
+trapezoids_fallback(CARD8 op, PicturePtr src, PicturePtr dst,
+                   PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc,
+                   int ntrap, xTrapezoid * traps)
+{
+       ScreenPtr screen = dst->pDrawable->pScreen;
+
+       if (maskFormat) {
+               PixmapPtr scratch;
+               PicturePtr mask;
+               INT16 dst_x, dst_y;
+               BoxRec bounds;
+               int width, height, depth;
+               pixman_image_t *image;
+               pixman_format_code_t format;
+               int error;
+
+               dst_x = pixman_fixed_to_int(traps[0].left.p1.x);
+               dst_y = pixman_fixed_to_int(traps[0].left.p1.y);
+
+               trapezoids_bounds(ntrap, traps, &bounds);
+               if (bounds.y1 >= bounds.y2 || bounds.x1 >= bounds.x2)
+                       return;
+
+               DBG(("%s: bounds (%d, %d), (%d, %d)\n", __FUNCTION__,
+                    bounds.x1, bounds.y1, bounds.x2, bounds.y2));
+
+               if (!sna_compute_composite_extents(&bounds,
+                                                  src, NULL, dst,
+                                                  xSrc, ySrc,
+                                                  0, 0,
+                                                  bounds.x1, bounds.y1,
+                                                  bounds.x2 - bounds.x1,
+                                                  bounds.y2 - bounds.y1))
+                       return;
+
+               DBG(("%s: extents (%d, %d), (%d, %d)\n", __FUNCTION__,
+                    bounds.x1, bounds.y1, bounds.x2, bounds.y2));
+
+               width  = bounds.x2 - bounds.x1;
+               height = bounds.y2 - bounds.y1;
+               bounds.x1 -= dst->pDrawable->x;
+               bounds.y1 -= dst->pDrawable->y;
+               depth = maskFormat->depth;
+               if (depth == 1) {
+                       format = PIXMAN_a1;
+               } else if (depth <= 4) {
+                       format = PIXMAN_a4;
+                       depth = 4;
+               } else
+                       format = PIXMAN_a8;
+
+               DBG(("%s: mask (%dx%d) depth=%d, format=%08x\n",
+                    __FUNCTION__, width, height, depth, format));
+               if (is_gpu(dst->pDrawable) || picture_is_gpu(src)) {
+                       scratch = sna_pixmap_create_upload(screen,
+                                                          width, height, 8,
+                                                          KGEM_BUFFER_WRITE);
+                       if (!scratch)
+                               return;
+
+                       if (depth < 8) {
+                               image = pixman_image_create_bits(format, width, height,
+                                                                NULL, 0);
+                       } else {
+                               memset(scratch->devPrivate.ptr, 0, scratch->devKind*height);
+                               image = pixman_image_create_bits(format, width, height,
+                                                                scratch->devPrivate.ptr,
+                                                                scratch->devKind);
+                       }
+                       if (image) {
+                               for (; ntrap; ntrap--, traps++)
+                                       pixman_rasterize_trapezoid(image,
+                                                                  (pixman_trapezoid_t *)traps,
+                                                                  -bounds.x1, -bounds.y1);
+                               if (depth < 8) {
+                                       pixman_image_t *a8;
+
+                                       a8 = pixman_image_create_bits(PIXMAN_a8, width, height,
+                                                                     scratch->devPrivate.ptr,
+                                                                     scratch->devKind);
+                                       if (a8) {
+                                               pixman_image_composite(PIXMAN_OP_SRC,
+                                                                      image, NULL, a8,
+                                                                      0, 0,
+                                                                      0, 0,
+                                                                      0, 0,
+                                                                      width, height);
+                                               format = PIXMAN_a8;
+                                               depth = 8;
+                                               pixman_image_unref (a8);
+                                       }
+                               }
+
+                               pixman_image_unref(image);
+                       }
+                       if (format != PIXMAN_a8) {
+                               sna_pixmap_destroy(scratch);
+                               return;
+                       }
+               } else {
+                       scratch = sna_pixmap_create_unattached(screen,
+                                                              width, height,
+                                                              depth);
+                       if (!scratch)
+                               return;
+
+                       memset(scratch->devPrivate.ptr, 0, scratch->devKind*height);
+                       image = pixman_image_create_bits(format, width, height,
+                                                        scratch->devPrivate.ptr,
+                                                        scratch->devKind);
+                       if (image) {
+                               for (; ntrap; ntrap--, traps++)
+                                       pixman_rasterize_trapezoid(image,
+                                                                  (pixman_trapezoid_t *)traps,
+                                                                  -bounds.x1, -bounds.y1);
+                               pixman_image_unref(image);
+                       }
+               }
+
+               mask = CreatePicture(0, &scratch->drawable,
+                                    PictureMatchFormat(screen, depth, format),
+                                    0, 0, serverClient, &error);
+               if (mask) {
+                       CompositePicture(op, src, mask, dst,
+                                        xSrc + bounds.x1 - dst_x,
+                                        ySrc + bounds.y1 - dst_y,
+                                        0, 0,
+                                        bounds.x1, bounds.y1,
+                                        width, height);
+                       FreePicture(mask, 0);
+               }
+               sna_pixmap_destroy(scratch);
+       } else {
+               if (dst->polyEdge == PolyEdgeSharp)
+                       maskFormat = PictureMatchFormat(screen, 1, PICT_a1);
+               else
+                       maskFormat = PictureMatchFormat(screen, 8, PICT_a8);
+
+               for (; ntrap; ntrap--, traps++)
+                       trapezoids_fallback(op,
+                                           src, dst, maskFormat,
+                                           xSrc, ySrc, 1, traps);
+       }
+}
+
+static bool
+composite_aligned_boxes(struct sna *sna,
+                       CARD8 op,
+                       PicturePtr src,
+                       PicturePtr dst,
+                       PictFormatPtr maskFormat,
+                       INT16 src_x, INT16 src_y,
+                       int ntrap, xTrapezoid *traps,
+                       bool force_fallback)
+{
+       BoxRec stack_boxes[64], *boxes;
+       pixman_region16_t region, clip;
+       struct sna_composite_op tmp;
+       bool ret = true;
+       int dx, dy, n, num_boxes;
+
+       if (NO_ALIGNED_BOXES)
+               return false;
+
+       DBG(("%s\n", __FUNCTION__));
+
+       boxes = stack_boxes;
+       if (ntrap > (int)ARRAY_SIZE(stack_boxes)) {
+               boxes = malloc(sizeof(BoxRec)*ntrap);
+               if (boxes == NULL)
+                       return false;
+       }
+
+       dx = dst->pDrawable->x;
+       dy = dst->pDrawable->y;
+
+       region.extents.x1 = region.extents.y1 = 32767;
+       region.extents.x2 = region.extents.y2 = -32767;
+       num_boxes = 0;
+       for (n = 0; n < ntrap; n++) {
+               boxes[num_boxes].x1 = dx + pixman_fixed_to_int(traps[n].left.p1.x + pixman_fixed_1_minus_e/2);
+               boxes[num_boxes].y1 = dy + pixman_fixed_to_int(traps[n].top + pixman_fixed_1_minus_e/2);
+               boxes[num_boxes].x2 = dx + pixman_fixed_to_int(traps[n].right.p2.x + pixman_fixed_1_minus_e/2);
+               boxes[num_boxes].y2 = dy + pixman_fixed_to_int(traps[n].bottom + pixman_fixed_1_minus_e/2);
+
+               if (boxes[num_boxes].x1 >= boxes[num_boxes].x2)
+                       continue;
+               if (boxes[num_boxes].y1 >= boxes[num_boxes].y2)
+                       continue;
+
+               if (boxes[num_boxes].x1 < region.extents.x1)
+                       region.extents.x1 = boxes[num_boxes].x1;
+               if (boxes[num_boxes].x2 > region.extents.x2)
+                       region.extents.x2 = boxes[num_boxes].x2;
+
+               if (boxes[num_boxes].y1 < region.extents.y1)
+                       region.extents.y1 = boxes[num_boxes].y1;
+               if (boxes[num_boxes].y2 > region.extents.y2)
+                       region.extents.y2 = boxes[num_boxes].y2;
+
+               num_boxes++;
+       }
+
+       if (num_boxes == 0)
+               goto free_boxes;
+
+       DBG(("%s: extents (%d, %d), (%d, %d) offset of (%d, %d)\n",
+            __FUNCTION__,
+            region.extents.x1, region.extents.y1,
+            region.extents.x2, region.extents.y2,
+            region.extents.x1 - boxes[0].x1,
+            region.extents.y1 - boxes[0].y1));
+
+       src_x += region.extents.x1 - boxes[0].x1;
+       src_y += region.extents.y1 - boxes[0].y1;
+
+       if (!sna_compute_composite_region(&clip,
+                                         src, NULL, dst,
+                                         src_x,  src_y,
+                                         0, 0,
+                                         region.extents.x1 - dx, region.extents.y1 - dy,
+                                         region.extents.x2 - region.extents.x1,
+                                         region.extents.y2 - region.extents.y1)) {
+               DBG(("%s: trapezoids do not intersect drawable clips\n",
+                    __FUNCTION__)) ;
+               goto done;
+       }
+
+       if (force_fallback ||
+           !sna->render.composite(sna, op, src, NULL, dst,
+                                  src_x,  src_y,
+                                  0, 0,
+                                  clip.extents.x1,  clip.extents.y1,
+                                  clip.extents.x2 - clip.extents.x1,
+                                  clip.extents.y2 - clip.extents.y1,
+                                  memset(&tmp, 0, sizeof(tmp)))) {
+               unsigned int flags;
+               pixman_box16_t *b;
+               int i, count;
+
+               DBG(("%s: composite render op not supported\n",
+                    __FUNCTION__));
+
+               flags = MOVE_READ | MOVE_WRITE;
+               if (n == 1 && op <= PictOpSrc)
+                       flags = MOVE_WRITE | MOVE_INPLACE_HINT;
+
+               if (!sna_drawable_move_region_to_cpu(dst->pDrawable, &clip, flags))
+                       goto done;
+               if (dst->alphaMap  &&
+                   !sna_drawable_move_to_cpu(dst->alphaMap->pDrawable,
+                                             MOVE_READ | MOVE_WRITE))
+                       goto done;
+               if (src->pDrawable) {
+                       if (!sna_drawable_move_to_cpu(src->pDrawable,
+                                                     MOVE_READ))
+                               goto done;
+                       if (src->alphaMap &&
+                           !sna_drawable_move_to_cpu(src->alphaMap->pDrawable,
+                                                     MOVE_READ))
+                               goto done;
+               }
+
+               DBG(("%s: fbComposite()\n", __FUNCTION__));
+               if (maskFormat) {
+                       pixman_region_init_rects(&region, boxes, num_boxes);
+                       RegionIntersect(&region, &region, &clip);
+
+                       b = REGION_RECTS(&region);
+                       count = REGION_NUM_RECTS(&region);
+                       for (i = 0; i < count; i++) {
+                               fbComposite(op, src, NULL, dst,
+                                           src_x + b[i].x1 - boxes[0].x1,
+                                           src_y + b[i].y1 - boxes[0].y1,
+                                           0, 0,
+                                           b[i].x1, b[i].y1,
+                                           b[i].x2 - b[i].x1, b[i].y2 - b[i].y1);
+                       }
+                       pixman_region_fini(&region);
+               } else {
+                       for (n = 0; n < num_boxes; n++) {
+                               pixman_region_init_rects(&region, &boxes[n], 1);
+                               RegionIntersect(&region, &region, &clip);
+                               b = REGION_RECTS(&region);
+                               count = REGION_NUM_RECTS(&region);
+                               for (i = 0; i < count; i++) {
+                                       fbComposite(op, src, NULL, dst,
+                                                   src_x + b[i].x1 - boxes[0].x1,
+                                                   src_y + b[i].y1 - boxes[0].y1,
+                                                   0, 0,
+                                                   b[i].x1, b[i].y1,
+                                                   b[i].x2 - b[i].x1, b[i].y2 - b[i].y1);
+                               }
+                               pixman_region_fini(&region);
+                               pixman_region_fini(&region);
+                       }
+               }
+               ret = true;
+               goto done;
+       }
+
+       if (maskFormat ||
+           (op == PictOpSrc || op == PictOpClear) ||
+           num_boxes == 1) {
+               pixman_region_init_rects(&region, boxes, num_boxes);
+               RegionIntersect(&region, &region, &clip);
+               if (REGION_NUM_RECTS(&region)) {
+                       tmp.boxes(sna, &tmp,
+                                 REGION_RECTS(&region),
+                                 REGION_NUM_RECTS(&region));
+                       apply_damage(&tmp, &region);
+               }
+               pixman_region_fini(&region);
+       } else {
+               for (n = 0; n < num_boxes; n++) {
+                       pixman_region_init_rects(&region, &boxes[n], 1);
+                       RegionIntersect(&region, &region, &clip);
+                       if (REGION_NUM_RECTS(&region)) {
+                               tmp.boxes(sna, &tmp,
+                                         REGION_RECTS(&region),
+                                         REGION_NUM_RECTS(&region));
+                               apply_damage(&tmp, &region);
+                       }
+                       pixman_region_fini(&region);
+               }
+       }
+       tmp.done(sna, &tmp);
+
+done:
+       REGION_UNINIT(NULL, &clip);
+free_boxes:
+       if (boxes != stack_boxes)
+               free(boxes);
+
+       return ret;
+}
+
+static inline int grid_coverage(int samples, pixman_fixed_t f)
+{
+       return (samples * pixman_fixed_frac(f) + pixman_fixed_1/2) / pixman_fixed_1;
+}
+
+static void
+composite_unaligned_box(struct sna *sna,
+                       struct sna_composite_spans_op *tmp,
+                       const BoxRec *box,
+                       float opacity,
+                       pixman_region16_t *clip)
+{
+       assert(opacity != 0.);
+
+       if (clip) {
+               pixman_region16_t region;
+
+               pixman_region_init_rects(&region, box, 1);
+               RegionIntersect(&region, &region, clip);
+               if (REGION_NUM_RECTS(&region))
+                       tmp->boxes(sna, tmp,
+                                  REGION_RECTS(&region),
+                                  REGION_NUM_RECTS(&region),
+                                  opacity);
+               pixman_region_fini(&region);
+       } else
+               tmp->box(sna, tmp, box, opacity);
+}
+
+static void
+composite_unaligned_trap_row(struct sna *sna,
+                            struct sna_composite_spans_op *tmp,
+                            xTrapezoid *trap, int dx,
+                            int y1, int y2, int covered,
+                            pixman_region16_t *clip)
+{
+       BoxRec box;
+       int opacity;
+       int x1, x2;
+#define u8_to_float(x) ((x) * (1.f/255))
+
+       if (covered == 0)
+               return;
+
+       x1 = dx + pixman_fixed_to_int(trap->left.p1.x);
+       x2 = dx + pixman_fixed_to_int(trap->right.p1.x);
+       if (clip) {
+               if (y2 > clip->extents.y2)
+                       y2 = clip->extents.y2;
+               if (y1 < clip->extents.y1)
+                       y1 = clip->extents.y1;
+               if (y1 >= y2)
+                       return;
+
+               if (x2 < clip->extents.x1 || x1 > clip->extents.x2)
+                       return;
+       }
+
+       box.y1 = y1;
+       box.y2 = y2;
+
+       if (x1 == x2) {
+               box.x1 = x1;
+               box.x2 = x2 + 1;
+
+               opacity = covered;
+               opacity *= grid_coverage(SAMPLES_X, trap->right.p1.x) - grid_coverage(SAMPLES_X, trap->left.p1.x);
+
+               if (opacity)
+                       composite_unaligned_box(sna, tmp, &box,
+                                               u8_to_float(opacity), clip);
+       } else {
+               if (pixman_fixed_frac(trap->left.p1.x)) {
+                       box.x1 = x1;
+                       box.x2 = ++x1;
+
+                       opacity = covered;
+                       opacity *= SAMPLES_X - grid_coverage(SAMPLES_X, trap->left.p1.x);
+
+                       if (opacity)
+                               composite_unaligned_box(sna, tmp, &box,
+                                                       u8_to_float(opacity), clip);
+               }
+
+               if (x2 > x1) {
+                       box.x1 = x1;
+                       box.x2 = x2;
+
+                       composite_unaligned_box(sna, tmp, &box,
+                                               covered == SAMPLES_Y ? 1. : u8_to_float(covered*SAMPLES_X),
+                                               clip);
+               }
+
+               if (pixman_fixed_frac(trap->right.p1.x)) {
+                       box.x1 = x2;
+                       box.x2 = x2 + 1;
+
+                       opacity = covered;
+                       opacity *= grid_coverage(SAMPLES_X, trap->right.p1.x);
+
+                       if (opacity)
+                               composite_unaligned_box(sna, tmp, &box,
+                                                       u8_to_float(opacity), clip);
+               }
+       }
+}
+
+static void
+composite_unaligned_trap(struct sna *sna,
+                       struct sna_composite_spans_op *tmp,
+                       xTrapezoid *trap,
+                       int dx, int dy,
+                       pixman_region16_t *clip)
+{
+       int y1, y2;
+
+       y1 = dy + pixman_fixed_to_int(trap->top);
+       y2 = dy + pixman_fixed_to_int(trap->bottom);
+
+       if (y1 == y2) {
+               composite_unaligned_trap_row(sna, tmp, trap, dx,
+                                            y1, y1 + 1,
+                                            grid_coverage(SAMPLES_Y, trap->bottom) - grid_coverage(SAMPLES_Y, trap->top),
+                                            clip);
+       } else {
+               if (pixman_fixed_frac(trap->top)) {
+                       composite_unaligned_trap_row(sna, tmp, trap, dx,
+                                                    y1, y1 + 1,
+                                                    SAMPLES_Y - grid_coverage(SAMPLES_Y, trap->top),
+                                                    clip);
+                       y1++;
+               }
+
+               if (y2 > y1)
+                       composite_unaligned_trap_row(sna, tmp, trap, dx,
+                                                    y1, y2,
+                                                    SAMPLES_Y,
+                                                    clip);
+
+               if (pixman_fixed_frac(trap->bottom))
+                       composite_unaligned_trap_row(sna, tmp, trap, dx,
+                                                    y2, y2 + 1,
+                                                    grid_coverage(SAMPLES_Y, trap->bottom),
+                                                    clip);
+       }
+
+       if (tmp->base.damage) {
+               BoxRec box;
+
+               box.x1 = dx + pixman_fixed_to_int(trap->left.p1.x);
+               box.x2 = dx + pixman_fixed_to_int(trap->right.p1.x);
+               box.y1 = y1;
+               box.y2 = y2 + (pixman_fixed_frac(trap->bottom) != 0);
+
+               if (clip) {
+                       pixman_region16_t region;
+
+                       pixman_region_init_rects(&region, &box, 1);
+                       RegionIntersect(&region, &region, clip);
+                       if (REGION_NUM_RECTS(&region))
+                               apply_damage(&tmp->base, &region);
+                       RegionUninit(&region);
+               } else
+                       apply_damage_box(&tmp->base, &box);
+       }
+}
+
+inline static void
+blt_opacity(PixmapPtr scratch,
+           int x1, int x2,
+           int y, int h,
+           uint8_t opacity)
+{
+       uint8_t *ptr;
+
+       if (opacity == 0xff)
+               return;
+
+       if (x1 < 0)
+               x1 = 0;
+       if (x2 > scratch->drawable.width)
+               x2 = scratch->drawable.width;
+       if (x1 >= x2)
+               return;
+
+       x2 -= x1;
+
+       ptr = scratch->devPrivate.ptr;
+       ptr += scratch->devKind * y;
+       ptr += x1;
+       do {
+               if (x2 == 1)
+                       *ptr = opacity;
+               else
+                       memset(ptr, opacity, x2);
+               ptr += scratch->devKind;
+       } while (--h);
+}
+
+static void
+blt_unaligned_box_row(PixmapPtr scratch,
+                     BoxPtr extents,
+                     xTrapezoid *trap,
+                     int y1, int y2,
+                     int covered)
+{
+       int x1, x2;
+
+       if (y2 > scratch->drawable.height)
+               y2 = scratch->drawable.height;
+       if (y1 < 0)
+               y1 = 0;
+       if (y1 >= y2)
+               return;
+
+       y2 -= y1;
+
+       x1 = pixman_fixed_to_int(trap->left.p1.x);
+       x2 = pixman_fixed_to_int(trap->right.p1.x);
+
+       x1 -= extents->x1;
+       x2 -= extents->x1;
+
+       if (x1 == x2) {
+               blt_opacity(scratch,
+                           x1, x1+1,
+                           y1, y2,
+                           covered * (grid_coverage(SAMPLES_X, trap->right.p1.x) - grid_coverage(SAMPLES_X, trap->left.p1.x)));
+       } else {
+               if (pixman_fixed_frac(trap->left.p1.x)) {
+                       blt_opacity(scratch,
+                                   x1, x1 + 1,
+                                   y1, y2,
+                                   covered * (SAMPLES_X - grid_coverage(SAMPLES_X, trap->left.p1.x)));
+                       x1++;
+               }
+
+               if (x2 > x1) {
+                       blt_opacity(scratch,
+                                   x1, x2,
+                                   y1, y2,
+                                   covered*SAMPLES_X);
+               }
+
+               if (pixman_fixed_frac(trap->right.p1.x))
+                       blt_opacity(scratch,
+                                   x2, x2 + 1,
+                                   y1, y2,
+                                   covered * grid_coverage(SAMPLES_X, trap->right.p1.x));
+       }
+}
+
+#define ONE_HALF 0x7f
+#define RB_MASK 0x00ff00ff
+#define RB_ONE_HALF 0x007f007f
+#define RB_MASK_PLUS_ONE 0x01000100
+#define G_SHIFT 8
+
+static force_inline uint32_t
+mul8x2_8 (uint32_t a, uint8_t b)
+{
+       uint32_t t = (a & RB_MASK) * b + RB_ONE_HALF;
+       return ((t + ((t >> G_SHIFT) & RB_MASK)) >> G_SHIFT) & RB_MASK;
+}
+
+static force_inline uint32_t
+add8x2_8x2(uint32_t a, uint32_t b)
+{
+       uint32_t t = a + b;
+       t |= RB_MASK_PLUS_ONE - ((t >> G_SHIFT) & RB_MASK);
+       return t & RB_MASK;
+}
+
+static force_inline uint32_t
+lerp8x4(uint32_t src, uint8_t a, uint32_t dst)
+{
+       return (add8x2_8x2(mul8x2_8(src, a),
+                          mul8x2_8(dst, ~a)) |
+               add8x2_8x2(mul8x2_8(src >> G_SHIFT, a),
+                          mul8x2_8(dst >> G_SHIFT, ~a)) << G_SHIFT);
+}
+
+inline static void
+lerp32_opacity(PixmapPtr scratch,
+              uint32_t color,
+              int16_t x, int16_t w,
+              int16_t y, int16_t h,
+              uint8_t opacity)
+{
+       uint32_t *ptr;
+       int stride, i;
+
+       ptr = (uint32_t*)((uint8_t *)scratch->devPrivate.ptr + scratch->devKind * y);
+       ptr += x;
+       stride = scratch->devKind / 4;
+
+       if (opacity == 0xff) {
+               if ((w | h) == 1) {
+                       *ptr = color;
+               } else {
+                       if (w < 16) {
+                               do {
+                                       for (i = 0; i < w; i++)
+                                               ptr[i] = color;
+                                       ptr += stride;
+                               } while (--h);
+                       } else {
+                               pixman_fill(ptr, stride, 32,
+                                           0, 0, w, h, color);
+                       }
+               }
+       } else {
+               if ((w | h) == 1) {
+                       *ptr = lerp8x4(color, opacity, *ptr);
+               } else if (w == 1) {
+                       do {
+                               *ptr = lerp8x4(color, opacity, *ptr);
+                               ptr += stride;
+                       } while (--h);
+               } else{
+                       do {
+                               for (i = 0; i < w; i++)
+                                       ptr[i] = lerp8x4(color, opacity, ptr[i]);
+                               ptr += stride;
+                       } while (--h);
+               }
+       }
+}
+
+static void
+lerp32_unaligned_box_row(PixmapPtr scratch, uint32_t color,
+                        const BoxRec *extents,
+                        xTrapezoid *trap, int16_t dx,
+                        int16_t y, int16_t h,
+                        uint8_t covered)
+{
+       int16_t x1 = pixman_fixed_to_int(trap->left.p1.x) + dx;
+       int16_t fx1 = grid_coverage(SAMPLES_X, trap->left.p1.x);
+       int16_t x2 = pixman_fixed_to_int(trap->right.p2.x) + dx;
+       int16_t fx2 = grid_coverage(SAMPLES_X, trap->right.p2.x);
+
+       if (x1 < extents->x1)
+               x1 = extents->x1, fx1 = 0;
+       if (x2 > extents->x2)
+               x2 = extents->x2, fx2 = 0;
+
+       DBG(("%s: x=(%d.%d, %d.%d), y=%dx%d, covered=%d\n", __FUNCTION__,
+            x1, fx1, x2, fx2, y, h, covered));
+
+       if (x1 < x2) {
+               if (fx1) {
+                       lerp32_opacity(scratch, color,
+                                      x1, 1,
+                                      y, h,
+                                      covered * (SAMPLES_X - fx1));
+                       x1++;
+               }
+
+               if (x2 > x1) {
+                       lerp32_opacity(scratch, color,
+                                      x1, x2-x1,
+                                      y, h,
+                                      covered*SAMPLES_X);
+               }
+
+               if (fx2) {
+                       lerp32_opacity(scratch, color,
+                                      x2, 1,
+                                      y, h,
+                                      covered * fx2);
+               }
+       } else if (x1 == x2 && fx2 > fx1) {
+               lerp32_opacity(scratch, color,
+                              x1, 1,
+                              y, h,
+                              covered * (fx2 - fx1));
+       }
+}
+
+struct pixman_inplace {
+       pixman_image_t *image, *source, *mask;
+       uint32_t color;
+       uint32_t *bits;
+       int dx, dy;
+       int sx, sy;
+       uint8_t op;
+};
+
+static force_inline uint8_t
+mul_8_8(uint8_t a, uint8_t b)
+{
+    uint16_t t = a * (uint16_t)b + 0x7f;
+    return ((t >> 8) + t) >> 8;
+}
+
+static inline uint32_t multa(uint32_t s, uint8_t a, int shift)
+{
+       return mul_8_8((s >> shift) & 0xff, a) << shift;
+}
+
+static inline uint32_t mul_4x8_8(uint32_t color, uint8_t alpha)
+{
+       uint32_t v;
+
+       v = 0;
+       v |= multa(color, alpha, 24);
+       v |= multa(color, alpha, 16);
+       v |= multa(color, alpha, 8);
+       v |= multa(color, alpha, 0);
+
+       return v;
+}
+
+inline static void
+pixsolid_opacity(struct pixman_inplace *pi,
+                int16_t x, int16_t w,
+                int16_t y, int16_t h,
+                uint8_t opacity)
+{
+       if (opacity == 0xff)
+               *pi->bits = pi->color;
+       else
+               *pi->bits = mul_4x8_8(pi->color, opacity);
+       pixman_image_composite(pi->op, pi->source, NULL, pi->image,
+                              0, 0, 0, 0, pi->dx + x, pi->dy + y, w, h);
+}
+
+static void
+pixsolid_unaligned_box_row(struct pixman_inplace *pi,
+                          const BoxRec *extents,
+                          xTrapezoid *trap,
+                          int16_t y, int16_t h,
+                          uint8_t covered)
+{
+       int16_t x1 = pixman_fixed_to_int(trap->left.p1.x);
+       int16_t fx1 = grid_coverage(SAMPLES_X, trap->left.p1.x);
+       int16_t x2 = pixman_fixed_to_int(trap->right.p1.x);
+       int16_t fx2 = grid_coverage(SAMPLES_X, trap->right.p1.x);
+
+       if (x1 < extents->x1)
+               x1 = extents->x1, fx1 = 0;
+       if (x2 > extents->x2)
+               x2 = extents->x2, fx2 = 0;
+
+       if (x1 < x2) {
+               if (fx1) {
+                       pixsolid_opacity(pi, x1, 1, y, h,
+                                        covered * (SAMPLES_X - fx1));
+                       x1++;
+               }
+
+               if (x2 > x1)
+                       pixsolid_opacity(pi, x1, x2-x1, y, h, covered*SAMPLES_X);
+
+               if (fx2)
+                       pixsolid_opacity(pi, x2, 1, y, h, covered * fx2);
+       } else if (x1 == x2 && fx2 > fx1) {
+               pixsolid_opacity(pi, x1, 1, y, h, covered * (fx2 - fx1));
+       }
+}
+
+static bool
+composite_unaligned_boxes_inplace__solid(CARD8 op, uint32_t color,
+                                        PicturePtr dst, int n, xTrapezoid *t,
+                                        bool force_fallback)
+{
+       PixmapPtr pixmap;
+       int16_t dx, dy;
+
+       DBG(("%s: force=%d, is_gpu=%d, op=%d, color=%x\n", __FUNCTION__,
+            force_fallback, is_gpu(dst->pDrawable), op, color));
+
+       if (!force_fallback && is_gpu(dst->pDrawable)) {
+               DBG(("%s: fallback -- can not perform operation in place, destination busy\n",
+                    __FUNCTION__));
+
+               return false;
+       }
+
+       /* XXX a8 boxes */
+       if (!(dst->format == PICT_a8r8g8b8 || dst->format == PICT_x8r8g8b8)) {
+               DBG(("%s: fallback -- can not perform operation in place, unhanbled format %08lx\n",
+                    __FUNCTION__, (long)dst->format));
+
+               goto pixman;
+       }
+
+       pixmap = get_drawable_pixmap(dst->pDrawable);
+       get_drawable_deltas(dst->pDrawable, pixmap, &dx, &dy);
+
+       if (op == PictOpOver && (color >> 24) == 0xff)
+               op = PictOpSrc;
+       if (op == PictOpOver || op == PictOpAdd) {
+               struct sna_pixmap *priv = sna_pixmap(pixmap);
+               if (priv && priv->clear && priv->clear_color == 0)
+                       op = PictOpSrc;
+       }
+
+       switch (op) {
+       case PictOpSrc:
+               break;
+       default:
+               DBG(("%s: fallback -- can not perform op [%d] in place\n",
+                    __FUNCTION__, op));
+               goto pixman;
+       }
+
+       DBG(("%s: inplace operation on argb32 destination x %d\n",
+            __FUNCTION__, n));
+       do {
+               RegionRec clip;
+               BoxPtr extents;
+               int count;
+
+               clip.extents.x1 = pixman_fixed_to_int(t->left.p1.x);
+               clip.extents.x2 = pixman_fixed_to_int(t->right.p1.x + pixman_fixed_1_minus_e);
+               clip.extents.y1 = pixman_fixed_to_int(t->top);
+               clip.extents.y2 = pixman_fixed_to_int(t->bottom + pixman_fixed_1_minus_e);
+               clip.data = NULL;
+
+               if (!sna_compute_composite_region(&clip,
+                                                  NULL, NULL, dst,
+                                                  0, 0,
+                                                  0, 0,
+                                                  clip.extents.x1, clip.extents.y1,
+                                                  clip.extents.x2 - clip.extents.x1,
+                                                  clip.extents.y2 - clip.extents.y1))
+                       continue;
+
+               if (!sna_drawable_move_region_to_cpu(dst->pDrawable, &clip,
+                                                    MOVE_WRITE | MOVE_READ)) {
+                       RegionUninit(&clip);
+                       continue;
+               }
+
+               RegionTranslate(&clip, dx, dy);
+               count = REGION_NUM_RECTS(&clip);
+               extents = REGION_RECTS(&clip);
+               while (count--) {
+                       int16_t y1 = dy + pixman_fixed_to_int(t->top);
+                       int16_t fy1 = pixman_fixed_frac(t->top);
+                       int16_t y2 = dy + pixman_fixed_to_int(t->bottom);
+                       int16_t fy2 = pixman_fixed_frac(t->bottom);
+
+                       DBG(("%s: t=(%d, %d), (%d, %d), extents (%d, %d), (%d, %d)\n",
+                            __FUNCTION__,
+                            pixman_fixed_to_int(t->left.p1.x),
+                            pixman_fixed_to_int(t->top),
+                            pixman_fixed_to_int(t->right.p2.x),
+                            pixman_fixed_to_int(t->bottom),
+                            extents->x1, extents->y1,
+                            extents->x2, extents->y2));
+
+                       if (y1 < extents->y1)
+                               y1 = extents->y1, fy1 = 0;
+                       if (y2 > extents->y2)
+                               y2 = extents->y2, fy2 = 0;
+
+                       if (y1 < y2) {
+                               if (fy1) {
+                                       lerp32_unaligned_box_row(pixmap, color, extents,
+                                                                t, dx, y1, 1,
+                                                                SAMPLES_Y - grid_coverage(SAMPLES_Y, fy1));
+                                       y1++;
+                               }
+
+                               if (y2 > y1)
+                                       lerp32_unaligned_box_row(pixmap, color, extents,
+                                                                t, dx, y1, y2 - y1,
+                                                                SAMPLES_Y);
+
+                               if (fy2)
+                                       lerp32_unaligned_box_row(pixmap, color,  extents,
+                                                                t, dx, y2, 1,
+                                                                grid_coverage(SAMPLES_Y, fy2));
+                       } else if (y1 == y2 && fy2 > fy1) {
+                               lerp32_unaligned_box_row(pixmap, color, extents,
+                                                        t, dx, y1, 1,
+                                                        grid_coverage(SAMPLES_Y, fy2) - grid_coverage(SAMPLES_Y, fy1));
+                       }
+                       extents++;
+               }
+
+               RegionUninit(&clip);
+       } while (--n && t++);
+
+       return true;
+
+pixman:
+       do {
+               struct pixman_inplace pi;
+               RegionRec clip;
+               BoxPtr extents;
+               int count;
+
+               clip.extents.x1 = pixman_fixed_to_int(t->left.p1.x);
+               clip.extents.x2 = pixman_fixed_to_int(t->right.p1.x + pixman_fixed_1_minus_e);
+               clip.extents.y1 = pixman_fixed_to_int(t->top);
+               clip.extents.y2 = pixman_fixed_to_int(t->bottom + pixman_fixed_1_minus_e);
+               clip.data = NULL;
+
+               if (!sna_compute_composite_region(&clip,
+                                                  NULL, NULL, dst,
+                                                  0, 0,
+                                                  0, 0,
+                                                  clip.extents.x1, clip.extents.y1,
+                                                  clip.extents.x2 - clip.extents.x1,
+                                                  clip.extents.y2 - clip.extents.y1))
+                       continue;
+
+               if (!sna_drawable_move_region_to_cpu(dst->pDrawable, &clip,
+                                                    MOVE_WRITE | MOVE_READ)) {
+                       RegionUninit(&clip);
+                       continue;
+               }
+
+               pi.image = image_from_pict(dst, false, &pi.dx, &pi.dy);
+               pi.source = pixman_image_create_bits(PIXMAN_a8r8g8b8, 1, 1, NULL, 0);
+               pixman_image_set_repeat(pi.source, PIXMAN_REPEAT_NORMAL);
+               pi.bits = pixman_image_get_data(pi.source);
+               pi.color = color;
+               pi.op = op;
+
+               count = REGION_NUM_RECTS(&clip);
+               extents = REGION_RECTS(&clip);
+               while (count--) {
+                       int16_t y1 = pixman_fixed_to_int(t->top);
+                       int16_t fy1 = pixman_fixed_frac(t->top);
+                       int16_t y2 = pixman_fixed_to_int(t->bottom);
+                       int16_t fy2 = pixman_fixed_frac(t->bottom);
+
+                       if (y1 < extents->y1)
+                               y1 = extents->y1, fy1 = 0;
+                       if (y2 > extents->y2)
+                               y2 = extents->y2, fy2 = 0;
+                       if (y1 < y2) {
+                               if (fy1) {
+                                       pixsolid_unaligned_box_row(&pi, extents, t, y1, 1,
+                                                                  SAMPLES_Y - grid_coverage(SAMPLES_Y, fy1));
+                                       y1++;
+                               }
+
+                               if (y2 > y1)
+                                       pixsolid_unaligned_box_row(&pi, extents, t, y1, y2 - y1,
+                                                                  SAMPLES_Y);
+
+                               if (fy2)
+                                       pixsolid_unaligned_box_row(&pi, extents, t, y2, 1,
+                                                                  grid_coverage(SAMPLES_Y, fy2));
+                       } else if (y1 == y2 && fy2 > fy1) {
+                               pixsolid_unaligned_box_row(&pi, extents, t, y1, 1,
+                                                          grid_coverage(SAMPLES_Y, fy2) - grid_coverage(SAMPLES_Y, fy1));
+                       }
+                       extents++;
+               }
+
+               RegionUninit(&clip);
+               pixman_image_unref(pi.image);
+               pixman_image_unref(pi.source);
+       } while (--n && t++);
+       return true;
+}
+
+inline static void
+pixmask_opacity(struct pixman_inplace *pi,
+               int16_t x, int16_t w,
+               int16_t y, int16_t h,
+               uint8_t opacity)
+{
+       if (opacity == 0xff) {
+               pixman_image_composite(pi->op, pi->source, NULL, pi->image,
+                                      pi->sx + x, pi->sy + y,
+                                      0, 0,
+                                      pi->dx + x, pi->dy + y,
+                                      w, h);
+       } else {
+               *pi->bits = opacity;
+               pixman_image_composite(pi->op, pi->source, pi->mask, pi->image,
+                                      pi->sx + x, pi->sy + y,
+                                      0, 0,
+                                      pi->dx + x, pi->dy + y,
+                                      w, h);
+       }
+}
+
+static void
+pixmask_unaligned_box_row(struct pixman_inplace *pi,
+                         const BoxRec *extents,
+                         xTrapezoid *trap,
+                         int16_t y, int16_t h,
+                         uint8_t covered)
+{
+       int16_t x1 = pixman_fixed_to_int(trap->left.p1.x);
+       int16_t fx1 = grid_coverage(SAMPLES_X, trap->left.p1.x);
+       int16_t x2 = pixman_fixed_to_int(trap->right.p1.x);
+       int16_t fx2 = grid_coverage(SAMPLES_X, trap->right.p1.x);
+
+       if (x1 < extents->x1)
+               x1 = extents->x1, fx1 = 0;
+       if (x2 > extents->x2)
+               x2 = extents->x2, fx2 = 0;
+
+       if (x1 < x2) {
+               if (fx1) {
+                       pixmask_opacity(pi, x1, 1, y, h,
+                                        covered * (SAMPLES_X - fx1));
+                       x1++;
+               }
+
+               if (x2 > x1)
+                       pixmask_opacity(pi, x1, x2-x1, y, h, covered*SAMPLES_X);
+
+               if (fx2)
+                       pixmask_opacity(pi, x2, 1, y, h, covered * fx2);
+       } else if (x1 == x2 && fx2 > fx1) {
+               pixmask_opacity(pi, x1, 1, y, h, covered * (fx2 - fx1));
+       }
+}
+
+static bool
+composite_unaligned_boxes_inplace(CARD8 op,
+                                 PicturePtr src, int16_t src_x, int16_t src_y,
+                                 PicturePtr dst, int n, xTrapezoid *t,
+                                 bool force_fallback)
+{
+       if (!force_fallback) {
+               DBG(("%s: fallback -- not forcing\n", __FUNCTION__));
+               return false;
+       }
+
+       DBG(("%s\n", __FUNCTION__));
+
+       src_x -= pixman_fixed_to_int(t[0].left.p1.x);
+       src_y -= pixman_fixed_to_int(t[0].left.p1.y);
+       do {
+               struct pixman_inplace pi;
+               RegionRec clip;
+               BoxPtr extents;
+               int count;
+
+               clip.extents.x1 = pixman_fixed_to_int(t->left.p1.x);
+               clip.extents.x2 = pixman_fixed_to_int(t->right.p1.x + pixman_fixed_1_minus_e);
+               clip.extents.y1 = pixman_fixed_to_int(t->top);
+               clip.extents.y2 = pixman_fixed_to_int(t->bottom + pixman_fixed_1_minus_e);
+               clip.data = NULL;
+
+               if (!sna_compute_composite_region(&clip,
+                                                  src, NULL, dst,
+                                                  clip.extents.x1 + src_x,
+                                                  clip.extents.y1 + src_y,
+                                                  0, 0,
+                                                  clip.extents.x1, clip.extents.y1,
+                                                  clip.extents.x2 - clip.extents.x1,
+                                                  clip.extents.y2 - clip.extents.y1))
+                       continue;
+
+               if (!sna_drawable_move_region_to_cpu(dst->pDrawable, &clip,
+                                                    MOVE_WRITE | MOVE_READ)) {
+                       RegionUninit(&clip);
+                       continue;
+               }
+
+               if (src->pDrawable) {
+                       if (!sna_drawable_move_to_cpu(src->pDrawable,
+                                                     MOVE_READ)) {
+                               RegionUninit(&clip);
+                               continue;
+                       }
+                       if (src->alphaMap) {
+                               if (!sna_drawable_move_to_cpu(src->alphaMap->pDrawable,
+                                                             MOVE_READ)) {
+                                       RegionUninit(&clip);
+                                       continue;
+                               }
+                       }
+               }
+
+               pi.image = image_from_pict(dst, false, &pi.dx, &pi.dy);
+               pi.source = image_from_pict(src, false, &pi.sx, &pi.sy);
+               pi.sx += src_x;
+               pi.sy += src_y;
+               pi.mask = pixman_image_create_bits(PIXMAN_a8, 1, 1, NULL, 0);
+               pixman_image_set_repeat(pi.mask, PIXMAN_REPEAT_NORMAL);
+               pi.bits = pixman_image_get_data(pi.mask);
+               pi.op = op;
+
+               count = REGION_NUM_RECTS(&clip);
+               extents = REGION_RECTS(&clip);
+               while (count--) {
+                       int16_t y1 = pixman_fixed_to_int(t->top);
+                       int16_t fy1 = pixman_fixed_frac(t->top);
+                       int16_t y2 = pixman_fixed_to_int(t->bottom);
+                       int16_t fy2 = pixman_fixed_frac(t->bottom);
+
+                       if (y1 < extents->y1)
+                               y1 = extents->y1, fy1 = 0;
+                       if (y2 > extents->y2)
+                               y2 = extents->y2, fy2 = 0;
+                       if (y1 < y2) {
+                               if (fy1) {
+                                       pixmask_unaligned_box_row(&pi, extents, t, y1, 1,
+                                                                  SAMPLES_Y - grid_coverage(SAMPLES_Y, fy1));
+                                       y1++;
+                               }
+
+                               if (y2 > y1)
+                                       pixmask_unaligned_box_row(&pi, extents, t, y1, y2 - y1,
+                                                                  SAMPLES_Y);
+
+                               if (fy2)
+                                       pixmask_unaligned_box_row(&pi, extents, t, y2, 1,
+                                                                  grid_coverage(SAMPLES_Y, fy2));
+                       } else if (y1 == y2 && fy2 > fy1) {
+                               pixmask_unaligned_box_row(&pi, extents, t, y1, 1,
+                                                         grid_coverage(SAMPLES_Y, fy2) - grid_coverage(SAMPLES_Y, fy1));
+                       }
+                       extents++;
+               }
+
+               RegionUninit(&clip);
+               pixman_image_unref(pi.image);
+               pixman_image_unref(pi.source);
+               pixman_image_unref(pi.mask);
+       } while (--n && t++);
+
+       return true;
+}
+
+static bool
+composite_unaligned_boxes_fallback(CARD8 op,
+                                  PicturePtr src,
+                                  PicturePtr dst,
+                                  INT16 src_x, INT16 src_y,
+                                  int ntrap, xTrapezoid *traps,
+                                  bool force_fallback)
+{
+       ScreenPtr screen = dst->pDrawable->pScreen;
+       uint32_t color;
+       int16_t dst_x, dst_y;
+       int16_t dx, dy;
+       int n;
+
+       if (sna_picture_is_solid(src, &color) &&
+           composite_unaligned_boxes_inplace__solid(op, color, dst,
+                                                    ntrap, traps,
+                                                    force_fallback))
+               return true;
+
+       if (composite_unaligned_boxes_inplace(op, src, src_x, src_y,
+                                             dst, ntrap, traps,
+                                             force_fallback))
+               return true;
+
+       dst_x = pixman_fixed_to_int(traps[0].left.p1.x);
+       dst_y = pixman_fixed_to_int(traps[0].left.p1.y);
+       dx = dst->pDrawable->x;
+       dy = dst->pDrawable->y;
+       for (n = 0; n < ntrap; n++) {
+               xTrapezoid *t = &traps[n];
+               PixmapPtr scratch;
+               PicturePtr mask;
+               BoxRec extents;
+               int error;
+               int y1, y2;
+
+               extents.x1 = pixman_fixed_to_int(t->left.p1.x);
+               extents.x2 = pixman_fixed_to_int(t->right.p1.x + pixman_fixed_1_minus_e);
+               extents.y1 = pixman_fixed_to_int(t->top);
+               extents.y2 = pixman_fixed_to_int(t->bottom + pixman_fixed_1_minus_e);
+
+               if (!sna_compute_composite_extents(&extents,
+                                                  src, NULL, dst,
+                                                  src_x, src_y,
+                                                  0, 0,
+                                                  extents.x1, extents.y1,
+                                                  extents.x2 - extents.x1,
+                                                  extents.y2 - extents.y1))
+                       continue;
+
+               if (force_fallback)
+                       scratch = sna_pixmap_create_unattached(screen,
+                                                              extents.x2 - extents.x1,
+                                                              extents.y2 - extents.y1,
+                                                              8);
+               else
+                       scratch = sna_pixmap_create_upload(screen,
+                                                          extents.x2 - extents.x1,
+                                                          extents.y2 - extents.y1,
+                                                          8, KGEM_BUFFER_WRITE_INPLACE);
+               if (!scratch)
+                       continue;
+
+               memset(scratch->devPrivate.ptr, 0xff,
+                      scratch->devKind * (extents.y2 - extents.y1));
+
+               extents.x1 -= dx;
+               extents.x2 -= dx;
+               extents.y1 -= dy;
+               extents.y2 -= dy;
+
+               y1 = pixman_fixed_to_int(t->top) - extents.y1;
+               y2 = pixman_fixed_to_int(t->bottom) - extents.y1;
+
+               if (y1 == y2) {
+                       blt_unaligned_box_row(scratch, &extents, t, y1, y1 + 1,
+                                             grid_coverage(SAMPLES_Y, t->bottom) - grid_coverage(SAMPLES_Y, t->top));
+               } else {
+                       if (pixman_fixed_frac(t->top)) {
+                               blt_unaligned_box_row(scratch, &extents, t, y1, y1 + 1,
+                                                     SAMPLES_Y - grid_coverage(SAMPLES_Y, t->top));
+                               y1++;
+                       }
+
+                       if (y2 > y1)
+                               blt_unaligned_box_row(scratch, &extents, t, y1, y2,
+                                                     SAMPLES_Y);
+
+                       if (pixman_fixed_frac(t->bottom))
+                               blt_unaligned_box_row(scratch, &extents, t, y2, y2+1,
+                                                     grid_coverage(SAMPLES_Y, t->bottom));
+               }
+
+               mask = CreatePicture(0, &scratch->drawable,
+                                    PictureMatchFormat(screen, 8, PICT_a8),
+                                    0, 0, serverClient, &error);
+               if (mask) {
+                       CompositePicture(op, src, mask, dst,
+                                        src_x + extents.x1 - dst_x,
+                                        src_y + extents.y1 - dst_y,
+                                        0, 0,
+                                        extents.x1, extents.y1,
+                                        extents.x2 - extents.x1,
+                                        extents.y2 - extents.y1);
+                       FreePicture(mask, 0);
+               }
+               sna_pixmap_destroy(scratch);
+       }
+
+       return true;
+}
+
+static bool
+composite_unaligned_boxes(struct sna *sna,
+                         CARD8 op,
+                         PicturePtr src,
+                         PicturePtr dst,
+                         PictFormatPtr maskFormat,
+                         INT16 src_x, INT16 src_y,
+                         int ntrap, xTrapezoid *traps,
+                         bool force_fallback)
+{
+       BoxRec extents;
+       struct sna_composite_spans_op tmp;
+       struct sna_pixmap *priv;
+       pixman_region16_t clip, *c;
+       int dst_x, dst_y;
+       int dx, dy, n;
+
+       if (NO_UNALIGNED_BOXES)
+               return false;
+
+       DBG(("%s: force_fallback=%d, mask=%x, n=%d\n",
+            __FUNCTION__, force_fallback, maskFormat ? (int)maskFormat->format : 0, ntrap));
+
+       /* need a span converter to handle overlapping traps */
+       if (ntrap > 1 && maskFormat)
+               return false;
+
+       if (force_fallback ||
+           !sna->render.check_composite_spans(sna, op, src, dst, 0, 0,
+                                              COMPOSITE_SPANS_RECTILINEAR)) {
+fallback:
+               return composite_unaligned_boxes_fallback(op, src, dst,
+                                                         src_x, src_y,
+                                                         ntrap, traps,
+                                                         force_fallback);
+       }
+
+       dst_x = extents.x1 = pixman_fixed_to_int(traps[0].left.p1.x);
+       extents.x2 = pixman_fixed_to_int(traps[0].right.p1.x + pixman_fixed_1_minus_e);
+       dst_y = extents.y1 = pixman_fixed_to_int(traps[0].top);
+       extents.y2 = pixman_fixed_to_int(traps[0].bottom + pixman_fixed_1_minus_e);
+
+       DBG(("%s: src=(%d, %d), dst=(%d, %d)\n",
+            __FUNCTION__, src_x, src_y, dst_x, dst_y));
+
+       for (n = 1; n < ntrap; n++) {
+               int x1 = pixman_fixed_to_int(traps[n].left.p1.x);
+               int x2 = pixman_fixed_to_int(traps[n].right.p1.x + pixman_fixed_1_minus_e);
+               int y1 = pixman_fixed_to_int(traps[n].top);
+               int y2 = pixman_fixed_to_int(traps[n].bottom + pixman_fixed_1_minus_e);
+
+               if (x1 < extents.x1)
+                       extents.x1 = x1;
+               if (x2 > extents.x2)
+                       extents.x2 = x2;
+               if (y1 < extents.y1)
+                       extents.y1 = y1;
+               if (y2 > extents.y2)
+                       extents.y2 = y2;
+       }
+
+       DBG(("%s: extents (%d, %d), (%d, %d)\n", __FUNCTION__,
+            extents.x1, extents.y1, extents.x2, extents.y2));
+
+       if (!sna_compute_composite_region(&clip,
+                                         src, NULL, dst,
+                                         src_x + extents.x1 - dst_x,
+                                         src_y + extents.y1 - dst_y,
+                                         0, 0,
+                                         extents.x1, extents.y1,
+                                         extents.x2 - extents.x1,
+                                         extents.y2 - extents.y1)) {
+               DBG(("%s: trapezoids do not intersect drawable clips\n",
+                    __FUNCTION__)) ;
+               return true;
+       }
+
+       if (!sna->render.check_composite_spans(sna, op, src, dst,
+                                              clip.extents.x2 - clip.extents.x1,
+                                              clip.extents.y2 - clip.extents.y1,
+                                              COMPOSITE_SPANS_RECTILINEAR)) {
+               DBG(("%s: fallback -- composite spans not supported\n",
+                    __FUNCTION__));
+               goto fallback;
+       }
+
+       c = NULL;
+       if (extents.x2 - extents.x1 > clip.extents.x2 - clip.extents.x1 ||
+           extents.y2 - extents.y1 > clip.extents.y2 - clip.extents.y1)
+               c = &clip;
+
+       extents = *RegionExtents(&clip);
+       dx = dst->pDrawable->x;
+       dy = dst->pDrawable->y;
+
+       DBG(("%s: after clip -- extents (%d, %d), (%d, %d), delta=(%d, %d) src -> (%d, %d)\n",
+            __FUNCTION__,
+            extents.x1, extents.y1,
+            extents.x2, extents.y2,
+            dx, dy,
+            src_x + extents.x1 - dst_x - dx,
+            src_y + extents.y1 - dst_y - dy));
+
+       switch (op) {
+       case PictOpAdd:
+       case PictOpOver:
+               priv = sna_pixmap(get_drawable_pixmap(dst->pDrawable));
+               assert(priv != NULL);
+               if (priv->clear && priv->clear_color == 0)
+                       op = PictOpSrc;
+               break;
+       case PictOpIn:
+               priv = sna_pixmap(get_drawable_pixmap(dst->pDrawable));
+               assert(priv != NULL);
+               if (priv->clear && priv->clear_color == 0)
+                       return true;
+               break;
+       }
+
+       memset(&tmp, 0, sizeof(tmp));
+       if (!sna->render.composite_spans(sna, op, src, dst,
+                                        src_x + extents.x1 - dst_x - dx,
+                                        src_y + extents.y1 - dst_y - dy,
+                                        extents.x1,  extents.y1,
+                                        extents.x2 - extents.x1,
+                                        extents.y2 - extents.y1,
+                                        COMPOSITE_SPANS_RECTILINEAR,
+                                        &tmp)) {
+               DBG(("%s: composite spans render op not supported\n",
+                    __FUNCTION__));
+               REGION_UNINIT(NULL, &clip);
+               goto fallback;
+       }
+
+       for (n = 0; n < ntrap; n++)
+               composite_unaligned_trap(sna, &tmp, &traps[n], dx, dy, c);
+       tmp.done(sna, &tmp);
+       REGION_UNINIT(NULL, &clip);
+       return true;
+}
+
+static inline int pixman_fixed_to_grid (pixman_fixed_t v)
+{
+       return (v + ((1<<(16-FAST_SAMPLES_shift))-1)/2) >> (16 - FAST_SAMPLES_shift);
+}
+
+static inline bool
+project_trapezoid_onto_grid(const xTrapezoid *in,
+                           int dx, int dy,
+                           xTrapezoid *out)
+{
+       __DBG(("%s: in: L:(%d, %d), (%d, %d); R:(%d, %d), (%d, %d), [%d, %d]\n",
+              __FUNCTION__,
+              in->left.p1.x, in->left.p1.y, in->left.p2.x, in->left.p2.y,
+              in->right.p1.x, in->right.p1.y, in->right.p2.x, in->right.p2.y,
+              in->top, in->bottom));
+
+       out->left.p1.x = dx + pixman_fixed_to_grid(in->left.p1.x);
+       out->left.p1.y = dy + pixman_fixed_to_grid(in->left.p1.y);
+       out->left.p2.x = dx + pixman_fixed_to_grid(in->left.p2.x);
+       out->left.p2.y = dy + pixman_fixed_to_grid(in->left.p2.y);
+
+       out->right.p1.x = dx + pixman_fixed_to_grid(in->right.p1.x);
+       out->right.p1.y = dy + pixman_fixed_to_grid(in->right.p1.y);
+       out->right.p2.x = dx + pixman_fixed_to_grid(in->right.p2.x);
+       out->right.p2.y = dy + pixman_fixed_to_grid(in->right.p2.y);
+
+       out->top = dy + pixman_fixed_to_grid(in->top);
+       out->bottom = dy + pixman_fixed_to_grid(in->bottom);
+
+       __DBG(("%s: out: L:(%d, %d), (%d, %d); R:(%d, %d), (%d, %d), [%d, %d]\n",
+              __FUNCTION__,
+              out->left.p1.x, out->left.p1.y, out->left.p2.x, out->left.p2.y,
+              out->right.p1.x, out->right.p1.y, out->right.p2.x, out->right.p2.y,
+              out->top, out->bottom));
+
+       return xTrapezoidValid(out);
+}
+
+static span_func_t
+choose_span(struct sna_composite_spans_op *tmp,
+           PicturePtr dst,
+           PictFormatPtr maskFormat,
+           uint8_t op,
+           RegionPtr clip)
+{
+       span_func_t span;
+
+       if (is_mono(dst, maskFormat)) {
+               /* XXX An imprecise approximation */
+               if (maskFormat && !operator_is_bounded(op)) {
+                       span = tor_blt_span_mono_unbounded;
+                       if (REGION_NUM_RECTS(clip) > 1)
+                               span = tor_blt_span_mono_unbounded_clipped;
+               } else {
+                       span = tor_blt_span_mono;
+                       if (REGION_NUM_RECTS(clip) > 1)
+                               span = tor_blt_span_mono_clipped;
+               }
+       } else {
+               if (REGION_NUM_RECTS(clip) > 1)
+                       span = tor_blt_span_clipped;
+               else if (tmp->base.damage == NULL)
+                       span = tor_blt_span__no_damage;
+               else
+                       span = tor_blt_span;
+       }
+
+       return span;
+}
+
+static bool
+mono_trapezoids_span_converter(CARD8 op, PicturePtr src, PicturePtr dst,
+                              INT16 src_x, INT16 src_y,
+                              int ntrap, xTrapezoid *traps)
+{
+       struct mono mono;
+       BoxRec extents;
+       int16_t dst_x, dst_y;
+       int16_t dx, dy;
+       bool was_clear;
+       int n;
+
+       if (NO_SCAN_CONVERTER)
+               return false;
+
+       dst_x = pixman_fixed_to_int(traps[0].left.p1.x);
+       dst_y = pixman_fixed_to_int(traps[0].left.p1.y);
+
+       trapezoids_bounds(ntrap, traps, &extents);
+       if (extents.y1 >= extents.y2 || extents.x1 >= extents.x2)
+               return true;
+
+       DBG(("%s: extents (%d, %d), (%d, %d)\n",
+            __FUNCTION__, extents.x1, extents.y1, extents.x2, extents.y2));
+
+       if (!sna_compute_composite_region(&mono.clip,
+                                         src, NULL, dst,
+                                         src_x + extents.x1 - dst_x,
+                                         src_y + extents.y1 - dst_y,
+                                         0, 0,
+                                         extents.x1, extents.y1,
+                                         extents.x2 - extents.x1,
+                                         extents.y2 - extents.y1)) {
+               DBG(("%s: trapezoids do not intersect drawable clips\n",
+                    __FUNCTION__)) ;
+               return true;
+       }
+
+       dx = dst->pDrawable->x;
+       dy = dst->pDrawable->y;
+
+       DBG(("%s: after clip -- extents (%d, %d), (%d, %d), delta=(%d, %d) src -> (%d, %d)\n",
+            __FUNCTION__,
+            mono.clip.extents.x1, mono.clip.extents.y1,
+            mono.clip.extents.x2, mono.clip.extents.y2,
+            dx, dy,
+            src_x + mono.clip.extents.x1 - dst_x - dx,
+            src_y + mono.clip.extents.y1 - dst_y - dy));
+
+       mono.sna = to_sna_from_drawable(dst->pDrawable);
+       if (!mono_init(&mono, 2*ntrap))
+               return false;
+
+       was_clear = sna_drawable_is_clear(dst->pDrawable);
+
+       for (n = 0; n < ntrap; n++) {
+               if (!xTrapezoidValid(&traps[n]))
+                       continue;
+
+               if (pixman_fixed_to_int(traps[n].top) + dy >= mono.clip.extents.y2 ||
+                   pixman_fixed_to_int(traps[n].bottom) + dy < mono.clip.extents.y1)
+                       continue;
+
+               mono_add_line(&mono, dx, dy,
+                             traps[n].top, traps[n].bottom,
+                             &traps[n].left.p1, &traps[n].left.p2, 1);
+               mono_add_line(&mono, dx, dy,
+                             traps[n].top, traps[n].bottom,
+                             &traps[n].right.p1, &traps[n].right.p2, -1);
+       }
+
+       memset(&mono.op, 0, sizeof(mono.op));
+       if (!mono.sna->render.composite(mono.sna, op, src, NULL, dst,
+                                      src_x + mono.clip.extents.x1 - dst_x - dx,
+                                      src_y + mono.clip.extents.y1 - dst_y - dy,
+                                      0, 0,
+                                      mono.clip.extents.x1,  mono.clip.extents.y1,
+                                      mono.clip.extents.x2 - mono.clip.extents.x1,
+                                      mono.clip.extents.y2 - mono.clip.extents.y1,
+                                      &mono.op)) {
+               mono_fini(&mono);
+               return false;
+       }
+       mono_render(&mono);
+       mono.op.done(mono.sna, &mono.op);
+       mono_fini(&mono);
+
+       if (!was_clear && !operator_is_bounded(op)) {
+               xPointFixed p1, p2;
+
+               if (!mono_init(&mono, 2+2*ntrap))
+                       return false;
+
+               p1.y = mono.clip.extents.y1 * pixman_fixed_1;
+               p2.y = mono.clip.extents.y2 * pixman_fixed_1;
+
+               p1.x = mono.clip.extents.x1 * pixman_fixed_1;
+               p2.x = mono.clip.extents.x1 * pixman_fixed_1;
+               mono_add_line(&mono, 0, 0, p1.y, p2.y, &p1, &p2, -1);
+
+               p1.x = mono.clip.extents.x2 * pixman_fixed_1;
+               p2.x = mono.clip.extents.x2 * pixman_fixed_1;
+               mono_add_line(&mono, 0, 0, p1.y, p2.y, &p1, &p2, 1);
+
+               for (n = 0; n < ntrap; n++) {
+                       if (!xTrapezoidValid(&traps[n]))
+                               continue;
+
+                       if (pixman_fixed_to_int(traps[n].top) + dy >= mono.clip.extents.y2 ||
+                           pixman_fixed_to_int(traps[n].bottom) + dy < mono.clip.extents.y1)
+                               continue;
+
+                       mono_add_line(&mono, dx, dy,
+                                     traps[n].top, traps[n].bottom,
+                                     &traps[n].left.p1, &traps[n].left.p2, 1);
+                       mono_add_line(&mono, dx, dy,
+                                     traps[n].top, traps[n].bottom,
+                                     &traps[n].right.p1, &traps[n].right.p2, -1);
+               }
+               memset(&mono.op, 0, sizeof(mono.op));
+               if (mono.sna->render.composite(mono.sna,
+                                              PictOpClear,
+                                              mono.sna->clear, NULL, dst,
+                                              0, 0,
+                                              0, 0,
+                                              mono.clip.extents.x1,  mono.clip.extents.y1,
+                                              mono.clip.extents.x2 - mono.clip.extents.x1,
+                                              mono.clip.extents.y2 - mono.clip.extents.y1,
+                                              &mono.op)) {
+                       mono_render(&mono);
+                       mono.op.done(mono.sna, &mono.op);
+               }
+               mono_fini(&mono);
+       }
+
+       REGION_UNINIT(NULL, &mono.clip);
+       return true;
+}
+
+static bool
+trapezoid_span_converter(CARD8 op, PicturePtr src, PicturePtr dst,
+                        PictFormatPtr maskFormat, unsigned int flags,
+                        INT16 src_x, INT16 src_y,
+                        int ntrap, xTrapezoid *traps)
+{
+       struct sna *sna;
+       struct sna_composite_spans_op tmp;
+       struct tor tor;
+       BoxRec extents;
+       pixman_region16_t clip;
+       int16_t dst_x, dst_y;
+       bool was_clear;
+       int dx, dy, n;
+
+       if (NO_SCAN_CONVERTER)
+               return false;
+
+       if (is_mono(dst, maskFormat))
+               return mono_trapezoids_span_converter(op, src, dst,
+                                                     src_x, src_y,
+                                                     ntrap, traps);
+
+       /* XXX strict adherence to the Render specification */
+       if (dst->polyMode == PolyModePrecise) {
+               DBG(("%s: fallback -- precise rasterisation requested\n",
+                    __FUNCTION__));
+               return false;
+       }
+
+       sna = to_sna_from_drawable(dst->pDrawable);
+       if (!sna->render.check_composite_spans(sna, op, src, dst, 0, 0, flags)) {
+               DBG(("%s: fallback -- composite spans not supported\n",
+                    __FUNCTION__));
+               return false;
+       }
+
+       dst_x = pixman_fixed_to_int(traps[0].left.p1.x);
+       dst_y = pixman_fixed_to_int(traps[0].left.p1.y);
+
+       trapezoids_bounds(ntrap, traps, &extents);
+       if (extents.y1 >= extents.y2 || extents.x1 >= extents.x2)
+               return true;
+
+#if 0
+       if (extents.y2 - extents.y1 < 64 && extents.x2 - extents.x1 < 64) {
+               DBG(("%s: fallback -- traps extents too small %dx%d\n",
+                    __FUNCTION__, extents.y2 - extents.y1, extents.x2 - extents.x1));
+               return false;
+       }
+#endif
+
+       DBG(("%s: extents (%d, %d), (%d, %d)\n",
+            __FUNCTION__, extents.x1, extents.y1, extents.x2, extents.y2));
+
+       if (!sna_compute_composite_region(&clip,
+                                         src, NULL, dst,
+                                         src_x + extents.x1 - dst_x,
+                                         src_y + extents.y1 - dst_y,
+                                         0, 0,
+                                         extents.x1, extents.y1,
+                                         extents.x2 - extents.x1,
+                                         extents.y2 - extents.y1)) {
+               DBG(("%s: trapezoids do not intersect drawable clips\n",
+                    __FUNCTION__)) ;
+               return true;
+       }
+
+       if (!sna->render.check_composite_spans(sna, op, src, dst,
+                                              clip.extents.x2 - clip.extents.x1,
+                                              clip.extents.y2 - clip.extents.y1,
+                                              flags)) {
+               DBG(("%s: fallback -- composite spans not supported\n",
+                    __FUNCTION__));
+               return false;
+       }
+
+       extents = *RegionExtents(&clip);
+       dx = dst->pDrawable->x;
+       dy = dst->pDrawable->y;
+
+       DBG(("%s: after clip -- extents (%d, %d), (%d, %d), delta=(%d, %d) src -> (%d, %d)\n",
+            __FUNCTION__,
+            extents.x1, extents.y1,
+            extents.x2, extents.y2,
+            dx, dy,
+            src_x + extents.x1 - dst_x - dx,
+            src_y + extents.y1 - dst_y - dy));
+
+       was_clear = sna_drawable_is_clear(dst->pDrawable);
+       switch (op) {
+       case PictOpAdd:
+       case PictOpOver:
+               if (was_clear)
+                       op = PictOpSrc;
+               break;
+       case PictOpIn:
+               if (was_clear)
+                       return true;
+               break;
+       }
+
+       memset(&tmp, 0, sizeof(tmp));
+       if (!sna->render.composite_spans(sna, op, src, dst,
+                                        src_x + extents.x1 - dst_x - dx,
+                                        src_y + extents.y1 - dst_y - dy,
+                                        extents.x1,  extents.y1,
+                                        extents.x2 - extents.x1,
+                                        extents.y2 - extents.y1,
+                                        flags, &tmp)) {
+               DBG(("%s: fallback -- composite spans render op not supported\n",
+                    __FUNCTION__));
+               return false;
+       }
+
+       dx *= FAST_SAMPLES_X;
+       dy *= FAST_SAMPLES_Y;
+       if (tor_init(&tor, &extents, 2*ntrap))
+               goto skip;
+
+       for (n = 0; n < ntrap; n++) {
+               xTrapezoid t;
+
+               if (!project_trapezoid_onto_grid(&traps[n], dx, dy, &t))
+                       continue;
+
+               if (pixman_fixed_to_int(traps[n].top) + dst->pDrawable->y >= extents.y2 ||
+                   pixman_fixed_to_int(traps[n].bottom) + dst->pDrawable->y < extents.y1)
+                       continue;
+
+               tor_add_edge(&tor, &t, &t.left, 1);
+               tor_add_edge(&tor, &t, &t.right, -1);
+       }
+
+       tor_render(sna, &tor, &tmp, &clip,
+                  choose_span(&tmp, dst, maskFormat, op, &clip),
+                  !was_clear && maskFormat && !operator_is_bounded(op));
+
+skip:
+       tor_fini(&tor);
+       tmp.done(sna, &tmp);
+
+       REGION_UNINIT(NULL, &clip);
+       return true;
+}
+
+static void
+tor_blt_mask(struct sna *sna,
+            struct sna_composite_spans_op *op,
+            pixman_region16_t *clip,
+            const BoxRec *box,
+            int coverage)
+{
+       uint8_t *ptr = (uint8_t *)op;
+       int stride = (intptr_t)clip;
+       int h, w;
+
+       coverage = 256 * coverage / FAST_SAMPLES_XY;
+       coverage -= coverage >> 8;
+
+       ptr += box->y1 * stride + box->x1;
+
+       h = box->y2 - box->y1;
+       w = box->x2 - box->x1;
+       if ((w | h) == 1) {
+               *ptr = coverage;
+       } else if (w == 1) {
+               do {
+                       *ptr = coverage;
+                       ptr += stride;
+               } while (--h);
+       } else do {
+               memset(ptr, coverage, w);
+               ptr += stride;
+       } while (--h);
+}
+
+static void
+tor_blt_mask_mono(struct sna *sna,
+                 struct sna_composite_spans_op *op,
+                 pixman_region16_t *clip,
+                 const BoxRec *box,
+                 int coverage)
+{
+       tor_blt_mask(sna, op, clip, box,
+                    coverage < FAST_SAMPLES_XY/2 ? 0 : FAST_SAMPLES_XY);
+}
+
+static bool
+trapezoid_mask_converter(CARD8 op, PicturePtr src, PicturePtr dst,
+                        PictFormatPtr maskFormat, INT16 src_x, INT16 src_y,
+                        int ntrap, xTrapezoid *traps)
+{
+       struct tor tor;
+       ScreenPtr screen = dst->pDrawable->pScreen;
+       PixmapPtr scratch;
+       PicturePtr mask;
+       BoxRec extents;
+       int16_t dst_x, dst_y;
+       int dx, dy;
+       int error, n;
+
+       if (NO_SCAN_CONVERTER)
+               return false;
+
+       if (dst->polyMode == PolyModePrecise && !is_mono(dst, maskFormat)) {
+               DBG(("%s: fallback -- precise rasterisation requested\n",
+                    __FUNCTION__));
+               return false;
+       }
+
+       if (maskFormat == NULL && ntrap > 1) {
+               DBG(("%s: individual rasterisation requested\n",
+                    __FUNCTION__));
+               do {
+                       /* XXX unwind errors? */
+                       if (!trapezoid_mask_converter(op, src, dst, NULL,
+                                                src_x, src_y, 1, traps++))
+                               return false;
+               } while (--ntrap);
+               return true;
+       }
+
+       trapezoids_bounds(ntrap, traps, &extents);
+       if (extents.y1 >= extents.y2 || extents.x1 >= extents.x2)
+               return true;
+
+       DBG(("%s: ntraps=%d, extents (%d, %d), (%d, %d)\n",
+            __FUNCTION__, ntrap, extents.x1, extents.y1, extents.x2, extents.y2));
+
+       if (!sna_compute_composite_extents(&extents,
+                                          src, NULL, dst,
+                                          src_x, src_y,
+                                          0, 0,
+                                          extents.x1, extents.y1,
+                                          extents.x2 - extents.x1,
+                                          extents.y2 - extents.y1))
+               return true;
+
+       DBG(("%s: extents (%d, %d), (%d, %d)\n",
+            __FUNCTION__, extents.x1, extents.y1, extents.x2, extents.y2));
+
+       extents.y2 -= extents.y1;
+       extents.x2 -= extents.x1;
+       extents.x1 -= dst->pDrawable->x;
+       extents.y1 -= dst->pDrawable->y;
+       dst_x = extents.x1;
+       dst_y = extents.y1;
+       dx = -extents.x1 * FAST_SAMPLES_X;
+       dy = -extents.y1 * FAST_SAMPLES_Y;
+       extents.x1 = extents.y1 = 0;
+
+       DBG(("%s: mask (%dx%d), dx=(%d, %d)\n",
+            __FUNCTION__, extents.x2, extents.y2, dx, dy));
+       scratch = sna_pixmap_create_upload(screen,
+                                          extents.x2, extents.y2, 8,
+                                          KGEM_BUFFER_WRITE_INPLACE);
+       if (!scratch)
+               return true;
+
+       DBG(("%s: created buffer %p, stride %d\n",
+            __FUNCTION__, scratch->devPrivate.ptr, scratch->devKind));
+
+       if (tor_init(&tor, &extents, 2*ntrap)) {
+               sna_pixmap_destroy(scratch);
+               return true;
+       }
+
+       for (n = 0; n < ntrap; n++) {
+               xTrapezoid t;
+
+               if (!project_trapezoid_onto_grid(&traps[n], dx, dy, &t))
+                       continue;
+
+               if (pixman_fixed_to_int(traps[n].top) - dst_y >= extents.y2 ||
+                   pixman_fixed_to_int(traps[n].bottom) - dst_y < 0)
+                       continue;
+
+               tor_add_edge(&tor, &t, &t.left, 1);
+               tor_add_edge(&tor, &t, &t.right, -1);
+       }
+
+       if (extents.x2 <= TOR_INPLACE_SIZE) {
+               uint8_t buf[TOR_INPLACE_SIZE];
+               tor_inplace(&tor, scratch, is_mono(dst, maskFormat),
+                           scratch->usage_hint ? NULL : buf);
+       } else {
+               tor_render(NULL, &tor,
+                          scratch->devPrivate.ptr,
+                          (void *)(intptr_t)scratch->devKind,
+                          is_mono(dst, maskFormat) ? tor_blt_mask_mono : tor_blt_mask,
+                          true);
+       }
+       tor_fini(&tor);
+
+       mask = CreatePicture(0, &scratch->drawable,
+                            PictureMatchFormat(screen, 8, PICT_a8),
+                            0, 0, serverClient, &error);
+       if (mask) {
+               CompositePicture(op, src, mask, dst,
+                                src_x + dst_x - pixman_fixed_to_int(traps[0].left.p1.x),
+                                src_y + dst_y - pixman_fixed_to_int(traps[0].left.p1.y),
+                                0, 0,
+                                dst_x, dst_y,
+                                extents.x2, extents.y2);
+               FreePicture(mask, 0);
+       }
+       sna_pixmap_destroy(scratch);
+
+       return true;
+}
+
+struct inplace {
+       uint32_t stride;
+       uint8_t *ptr;
+       union {
+               uint8_t opacity;
+               uint32_t color;
+       };
+};
+
+static force_inline uint8_t coverage_opacity(int coverage, uint8_t opacity)
+{
+       coverage = coverage * 256 / FAST_SAMPLES_XY;
+       return mul_8_8(coverage - (coverage >> 8), opacity);
+}
+
+static void
+tor_blt_src(struct sna *sna,
+           struct sna_composite_spans_op *op,
+           pixman_region16_t *clip,
+           const BoxRec *box,
+           int coverage)
+{
+       struct inplace *in = (struct inplace *)op;
+       uint8_t *ptr = in->ptr;
+       int h, w;
+
+       coverage = coverage_opacity(coverage, in->opacity);
+
+       ptr += box->y1 * in->stride + box->x1;
+
+       h = box->y2 - box->y1;
+       w = box->x2 - box->x1;
+       if ((w | h) == 1) {
+               *ptr = coverage;
+       } else if (w == 1) {
+               do {
+                       *ptr = coverage;
+                       ptr += in->stride;
+               } while (--h);
+       } else do {
+               memset(ptr, coverage, w);
+               ptr += in->stride;
+       } while (--h);
+}
+
+static void
+tor_blt_src_clipped(struct sna *sna,
+                   struct sna_composite_spans_op *op,
+                   pixman_region16_t *clip,
+                   const BoxRec *box,
+                   int coverage)
+{
+       pixman_region16_t region;
+       int n;
+
+       pixman_region_init_rects(&region, box, 1);
+       RegionIntersect(&region, &region, clip);
+       n = REGION_NUM_RECTS(&region);
+       box = REGION_RECTS(&region);
+       while (n--)
+               tor_blt_src(sna, op, NULL, box++, coverage);
+       pixman_region_fini(&region);
+}
+
+static void
+tor_blt_in(struct sna *sna,
+          struct sna_composite_spans_op *op,
+          pixman_region16_t *clip,
+          const BoxRec *box,
+          int coverage)
+{
+       struct inplace *in = (struct inplace *)op;
+       uint8_t *ptr = in->ptr;
+       int h, w, i;
+
+       if (coverage == 0) {
+               tor_blt_src(sna, op, clip, box, 0);
+               return;
+       }
+
+       coverage = coverage_opacity(coverage, in->opacity);
+       if (coverage == 0xff)
+               return;
+
+       ptr += box->y1 * in->stride + box->x1;
+
+       h = box->y2 - box->y1;
+       w = box->x2 - box->x1;
+       do {
+               for (i = 0; i < w; i++)
+                       ptr[i] = mul_8_8(ptr[i], coverage);
+               ptr += in->stride;
+       } while (--h);
+}
+
+static void
+tor_blt_in_clipped(struct sna *sna,
+                  struct sna_composite_spans_op *op,
+                  pixman_region16_t *clip,
+                  const BoxRec *box,
+                  int coverage)
+{
+       pixman_region16_t region;
+       int n;
+
+       pixman_region_init_rects(&region, box, 1);
+       RegionIntersect(&region, &region, clip);
+       n = REGION_NUM_RECTS(&region);
+       box = REGION_RECTS(&region);
+       while (n--)
+               tor_blt_in(sna, op, NULL, box++, coverage);
+       pixman_region_fini(&region);
+}
+
+static void
+tor_blt_add(struct sna *sna,
+           struct sna_composite_spans_op *op,
+           pixman_region16_t *clip,
+           const BoxRec *box,
+           int coverage)
+{
+       struct inplace *in = (struct inplace *)op;
+       uint8_t *ptr = in->ptr;
+       int h, w, v, i;
+
+       if (coverage == 0)
+               return;
+
+       coverage = coverage_opacity(coverage, in->opacity);
+       if (coverage == 0xff) {
+               tor_blt_src(sna, op, clip, box, 0xff);
+               return;
+       }
+
+       ptr += box->y1 * in->stride + box->x1;
+
+       h = box->y2 - box->y1;
+       w = box->x2 - box->x1;
+       if ((w | h) == 1) {
+               v = coverage + *ptr;
+               *ptr = v >= 255 ? 255 : v;
+       } else {
+               do {
+                       for (i = 0; i < w; i++) {
+                               v = coverage + ptr[i];
+                               ptr[i] = v >= 255 ? 255 : v;
+                       }
+                       ptr += in->stride;
+               } while (--h);
+       }
+}
+
+static void
+tor_blt_add_clipped(struct sna *sna,
+                   struct sna_composite_spans_op *op,
+                   pixman_region16_t *clip,
+                   const BoxRec *box,
+                   int coverage)
+{
+       pixman_region16_t region;
+       int n;
+
+       pixman_region_init_rects(&region, box, 1);
+       RegionIntersect(&region, &region, clip);
+       n = REGION_NUM_RECTS(&region);
+       box = REGION_RECTS(&region);
+       while (n--)
+               tor_blt_add(sna, op, NULL, box++, coverage);
+       pixman_region_fini(&region);
+}
+
+static void
+tor_blt_lerp32(struct sna *sna,
+              struct sna_composite_spans_op *op,
+              pixman_region16_t *clip,
+              const BoxRec *box,
+              int coverage)
+{
+       struct inplace *in = (struct inplace *)op;
+       uint32_t *ptr = (uint32_t *)in->ptr;
+       int stride = in->stride / sizeof(uint32_t);
+       int h, w, i;
+
+       if (coverage == 0)
+               return;
+
+       ptr += box->y1 * stride + box->x1;
+
+       h = box->y2 - box->y1;
+       w = box->x2 - box->x1;
+       if (coverage == FAST_SAMPLES_XY) {
+               if ((w | h) == 1) {
+                       *ptr = in->color;
+               } else {
+                       if (w < 16) {
+                               do {
+                                       for (i = 0; i < w; i++)
+                                               ptr[i] = in->color;
+                                       ptr += stride;
+                               } while (--h);
+                       } else {
+                               pixman_fill(ptr, stride, 32,
+                                           0, 0, w, h, in->color);
+                       }
+               }
+       } else {
+               coverage = coverage * 256 / FAST_SAMPLES_XY;
+               coverage -= coverage >> 8;
+
+               if ((w | h) == 1) {
+                       *ptr = lerp8x4(in->color, coverage, *ptr);
+               } else if (w == 1) {
+                       do {
+                               *ptr = lerp8x4(in->color, coverage, *ptr);
+                               ptr += stride;
+                       } while (--h);
+               } else{
+                       do {
+                               for (i = 0; i < w; i++)
+                                       ptr[i] = lerp8x4(in->color, coverage, ptr[i]);
+                               ptr += stride;
+                       } while (--h);
+               }
+       }
+}
+
+static void
+tor_blt_lerp32_clipped(struct sna *sna,
+                      struct sna_composite_spans_op *op,
+                      pixman_region16_t *clip,
+                      const BoxRec *box,
+                      int coverage)
+{
+       pixman_region16_t region;
+       int n;
+
+       pixman_region_init_rects(&region, box, 1);
+       RegionIntersect(&region, &region, clip);
+       n = REGION_NUM_RECTS(&region);
+       box = REGION_RECTS(&region);
+       while (n--)
+               tor_blt_lerp32(sna, op, NULL, box++, coverage);
+       pixman_region_fini(&region);
+}
+
+struct mono_inplace_composite {
+       pixman_image_t *src, *dst;
+       int dx, dy;
+       int sx, sy;
+       int op;
+};
+struct mono_inplace_fill {
+       uint32_t *data, stride;
+       uint32_t color;
+       int bpp;
+};
+
+fastcall static void
+mono_inplace_fill_box(struct sna *sna,
+                     const struct sna_composite_op *op,
+                     const BoxRec *box)
+{
+       struct mono_inplace_fill *fill = op->priv;
+
+       DBG(("(%s: (%d, %d)x(%d, %d):%08x\n",
+            __FUNCTION__,
+            box->x1, box->y1,
+            box->x2 - box->x1,
+            box->y2 - box->y1,
+            fill->color));
+       pixman_fill(fill->data, fill->stride, fill->bpp,
+                   box->x1, box->y1,
+                   box->x2 - box->x1,
+                   box->y2 - box->y1,
+                   fill->color);
+}
+
+static void
+mono_inplace_fill_boxes(struct sna *sna,
+                       const struct sna_composite_op *op,
+                       const BoxRec *box, int nbox)
+{
+       struct mono_inplace_fill *fill = op->priv;
+
+       do {
+               DBG(("(%s: (%d, %d)x(%d, %d):%08x\n",
+                    __FUNCTION__,
+                    box->x1, box->y1,
+                    box->x2 - box->x1,
+                    box->y2 - box->y1,
+                    fill->color));
+               pixman_fill(fill->data, fill->stride, fill->bpp,
+                           box->x1, box->y1,
+                           box->x2 - box->x1,
+                           box->y2 - box->y1,
+                           fill->color);
+               box++;
+       } while (--nbox);
+}
+
+fastcall static void
+mono_inplace_composite_box(struct sna *sna,
+                          const struct sna_composite_op *op,
+                          const BoxRec *box)
+{
+       struct mono_inplace_composite *c = op->priv;
+
+       pixman_image_composite(c->op, c->src, NULL, c->dst,
+                              box->x1 + c->sx, box->y1 + c->sy,
+                              0, 0,
+                              box->x1 + c->dx, box->y1 + c->dy,
+                              box->x2 - box->x1,
+                              box->y2 - box->y1);
+}
+
+static void
+mono_inplace_composite_boxes(struct sna *sna,
+                            const struct sna_composite_op *op,
+                            const BoxRec *box, int nbox)
+{
+       struct mono_inplace_composite *c = op->priv;
+
+       do {
+               pixman_image_composite(c->op, c->src, NULL, c->dst,
+                                      box->x1 + c->sx, box->y1 + c->sy,
+                                      0, 0,
+                                      box->x1 + c->dx, box->y1 + c->dy,
+                                      box->x2 - box->x1,
+                                      box->y2 - box->y1);
+               box++;
+       } while (--nbox);
+}
+
+static bool
+trapezoid_spans_maybe_inplace(CARD8 op, PicturePtr src, PicturePtr dst,
+                             PictFormatPtr maskFormat)
+{
+       struct sna_pixmap *priv;
+
+       if (NO_SCAN_CONVERTER)
+               return false;
+
+       if (dst->polyMode == PolyModePrecise && !is_mono(dst, maskFormat))
+               return false;
+       if (dst->alphaMap)
+               return false;
+
+       if (is_mono(dst, maskFormat))
+               goto out;
+
+       switch ((int)dst->format) {
+       case PICT_a8:
+               if (!sna_picture_is_solid(src, NULL))
+                       return false;
+
+               switch (op) {
+               case PictOpIn:
+               case PictOpAdd:
+               case PictOpSrc:
+                       break;
+               default:
+                       return false;
+               }
+               break;
+
+       case PICT_x8r8g8b8:
+       case PICT_a8r8g8b8:
+               if (picture_is_gpu(src))
+                       return false;
+
+               switch (op) {
+               case PictOpOver:
+               case PictOpAdd:
+               case PictOpOutReverse:
+                       break;
+               case PictOpSrc:
+                       if (sna_picture_is_solid(src, NULL))
+                               break;
+
+                       if (!sna_drawable_is_clear(dst->pDrawable))
+                               return false;
+                       break;
+               default:
+                       return false;
+               }
+               break;
+       default:
+               return false;
+       }
+
+out:
+       priv = sna_pixmap_from_drawable(dst->pDrawable);
+       if (priv == NULL)
+               return true;
+
+       if (priv->cpu_bo && kgem_bo_is_busy(priv->cpu_bo))
+               return false;
+
+       if (DAMAGE_IS_ALL(priv->cpu_damage) || priv->gpu_damage == NULL)
+               return true;
+
+       if (priv->clear)
+               return dst->pDrawable->width <= TOR_INPLACE_SIZE;
+
+       if (kgem_bo_is_busy(priv->gpu_bo))
+               return false;
+
+       if (priv->cpu_damage)
+               return true;
+
+       return dst->pDrawable->width <= TOR_INPLACE_SIZE;
+}
+
+static bool
+trapezoid_span_mono_inplace(CARD8 op,
+                           PicturePtr src,
+                           PicturePtr dst,
+                           INT16 src_x, INT16 src_y,
+                           int ntrap, xTrapezoid *traps)
+{
+       struct mono mono;
+       union {
+               struct mono_inplace_fill fill;
+               struct mono_inplace_composite composite;
+       } inplace;
+       int was_clear;
+       int x, y, n;
+
+       trapezoids_bounds(ntrap, traps, &mono.clip.extents);
+       if (mono.clip.extents.y1 >= mono.clip.extents.y2 ||
+           mono.clip.extents.x1 >= mono.clip.extents.x2)
+               return true;
+
+       DBG(("%s: extents (%d, %d), (%d, %d)\n",
+            __FUNCTION__,
+            mono.clip.extents.x1, mono.clip.extents.y1,
+            mono.clip.extents.x2, mono.clip.extents.y2));
+
+       if (!sna_compute_composite_region(&mono.clip,
+                                         src, NULL, dst,
+                                         src_x, src_y,
+                                         0, 0,
+                                         mono.clip.extents.x1, mono.clip.extents.y1,
+                                         mono.clip.extents.x2 - mono.clip.extents.x1,
+                                         mono.clip.extents.y2 - mono.clip.extents.y1)) {
+               DBG(("%s: trapezoids do not intersect drawable clips\n",
+                    __FUNCTION__)) ;
+               return true;
+       }
+
+       DBG(("%s: clipped extents (%d, %d), (%d, %d)\n",
+            __FUNCTION__,
+            mono.clip.extents.x1, mono.clip.extents.y1,
+            mono.clip.extents.x2, mono.clip.extents.y2));
+
+       was_clear = sna_drawable_is_clear(dst->pDrawable);
+       if (!sna_drawable_move_region_to_cpu(dst->pDrawable, &mono.clip,
+                                            MOVE_WRITE | MOVE_READ))
+               return true;
+
+       mono.sna = to_sna_from_drawable(dst->pDrawable);
+       if (!mono_init(&mono, 2*ntrap))
+               return false;
+
+       mono.op.damage = NULL;
+
+       x = dst->pDrawable->x;
+       y = dst->pDrawable->y;
+
+       for (n = 0; n < ntrap; n++) {
+               if (!xTrapezoidValid(&traps[n]))
+                       continue;
+
+               if (pixman_fixed_to_int(traps[n].top) + y >= mono.clip.extents.y2 ||
+                   pixman_fixed_to_int(traps[n].bottom) + y < mono.clip.extents.y1)
+                       continue;
+
+               mono_add_line(&mono, x, y,
+                             traps[n].top, traps[n].bottom,
+                             &traps[n].left.p1, &traps[n].left.p2, 1);
+               mono_add_line(&mono, x, y,
+                             traps[n].top, traps[n].bottom,
+                             &traps[n].right.p1, &traps[n].right.p2, -1);
+       }
+
+       if (sna_picture_is_solid(src, &inplace.fill.color) &&
+           (op == PictOpSrc || op == PictOpClear ||
+            (was_clear && (op == PictOpOver || op == PictOpAdd)) ||
+            (op == PictOpOver && inplace.fill.color >> 24 == 0xff))) {
+               PixmapPtr pixmap;
+               int16_t dx, dy;
+               uint8_t *ptr;
+
+unbounded_pass:
+               pixmap = get_drawable_pixmap(dst->pDrawable);
+               get_drawable_deltas(dst->pDrawable, pixmap, &dx, &dy);
+
+               ptr = pixmap->devPrivate.ptr;
+               ptr += dy * pixmap->devKind + dx * pixmap->drawable.bitsPerPixel / 8;
+               inplace.fill.data = (uint32_t *)ptr;
+               inplace.fill.stride = pixmap->devKind / sizeof(uint32_t);
+               inplace.fill.bpp = pixmap->drawable.bitsPerPixel;
+
+               if (op == PictOpClear)
+                       inplace.fill.color = 0;
+               else if (dst->format != PICT_a8r8g8b8)
+                       inplace.fill.color = sna_rgba_to_color(inplace.fill.color, dst->format);
+
+               DBG(("%s: fill %x\n", __FUNCTION__, inplace.fill.color));
+
+               mono.op.priv = &inplace.fill;
+               mono.op.box = mono_inplace_fill_box;
+               mono.op.boxes = mono_inplace_fill_boxes;
+
+               op = 0;
+       } else {
+               inplace.composite.dst = image_from_pict(dst, false,
+                                                       &inplace.composite.dx,
+                                                       &inplace.composite.dy);
+               inplace.composite.src = image_from_pict(src, false,
+                                                       &inplace.composite.sx,
+                                                       &inplace.composite.sy);
+               inplace.composite.sx +=
+                       src_x - pixman_fixed_to_int(traps[0].left.p1.x),
+               inplace.composite.sy +=
+                       src_y - pixman_fixed_to_int(traps[0].left.p1.y),
+               inplace.composite.op = op;
+
+               mono.op.priv = &inplace.composite;
+               mono.op.box = mono_inplace_composite_box;
+               mono.op.boxes = mono_inplace_composite_boxes;
+       }
+       mono_render(&mono);
+       mono_fini(&mono);
+
+       if (op) {
+               free_pixman_pict(src, inplace.composite.src);
+               free_pixman_pict(dst, inplace.composite.dst);
+
+               if (!was_clear && !operator_is_bounded(op)) {
+                       xPointFixed p1, p2;
+
+                       DBG(("%s: unbounded fixup\n", __FUNCTION__));
+
+                       if (!mono_init(&mono, 2+2*ntrap))
+                               return false;
+
+                       p1.y = mono.clip.extents.y1 * pixman_fixed_1;
+                       p2.y = mono.clip.extents.y2 * pixman_fixed_1;
+
+                       p1.x = mono.clip.extents.x1 * pixman_fixed_1;
+                       p2.x = mono.clip.extents.x1 * pixman_fixed_1;
+                       mono_add_line(&mono, 0, 0, p1.y, p2.y, &p1, &p2, -1);
+
+                       p1.x = mono.clip.extents.x2 * pixman_fixed_1;
+                       p2.x = mono.clip.extents.x2 * pixman_fixed_1;
+                       mono_add_line(&mono, 0, 0, p1.y, p2.y, &p1, &p2, 1);
+
+                       for (n = 0; n < ntrap; n++) {
+                               if (!xTrapezoidValid(&traps[n]))
+                                       continue;
+
+                               if (pixman_fixed_to_int(traps[n].top) + x >= mono.clip.extents.y2 ||
+                                   pixman_fixed_to_int(traps[n].bottom) + y < mono.clip.extents.y1)
+                                       continue;
+
+                               mono_add_line(&mono, x, y,
+                                             traps[n].top, traps[n].bottom,
+                                             &traps[n].left.p1, &traps[n].left.p2, 1);
+                               mono_add_line(&mono, x, y,
+                                             traps[n].top, traps[n].bottom,
+                                             &traps[n].right.p1, &traps[n].right.p2, -1);
+                       }
+
+                       op = PictOpClear;
+                       goto unbounded_pass;
+               }
+       }
+
+       return true;
+}
+
+static void
+pixmask_span(struct sna *sna,
+            struct sna_composite_spans_op *op,
+            pixman_region16_t *clip,
+            const BoxRec *box,
+            int coverage)
+{
+       struct pixman_inplace *pi = (struct pixman_inplace *)op;
+       pixman_image_t *mask = NULL;
+       if (coverage != FAST_SAMPLES_XY) {
+               coverage = coverage * 256 / FAST_SAMPLES_XY;
+               coverage -= coverage >> 8;
+               *pi->bits = coverage;
+               mask = pi->mask;
+       }
+       pixman_image_composite(pi->op, pi->source, mask, pi->image,
+                              pi->sx + box->x1, pi->sy + box->y1,
+                              0, 0,
+                              pi->dx + box->x1, pi->dy + box->y1,
+                              box->x2 - box->x1, box->y2 - box->y1);
+}
+static void
+pixmask_span__clipped(struct sna *sna,
+                     struct sna_composite_spans_op *op,
+                     pixman_region16_t *clip,
+                     const BoxRec *box,
+                     int coverage)
+{
+       pixman_region16_t region;
+       int n;
+
+       pixman_region_init_rects(&region, box, 1);
+       RegionIntersect(&region, &region, clip);
+       n = REGION_NUM_RECTS(&region);
+       box = REGION_RECTS(&region);
+       while (n--)
+               pixmask_span(sna, op, NULL, box++, coverage);
+       pixman_region_fini(&region);
+}
+
+static bool
+trapezoid_span_inplace__x8r8g8b8(CARD8 op,
+                                PicturePtr dst,
+                                PicturePtr src, int16_t src_x, int16_t src_y,
+                                PictFormatPtr maskFormat,
+                                int ntrap, xTrapezoid *traps)
+{
+       struct tor tor;
+       span_func_t span;
+       uint32_t color;
+       bool lerp;
+       RegionRec region;
+       int16_t dst_x, dst_y;
+       int dx, dy;
+       int n;
+
+       lerp = false;
+       if (sna_picture_is_solid(src, &color)) {
+               if (op == PictOpOver && (color >> 24) == 0xff)
+                       op = PictOpSrc;
+               if (op == PictOpOver && sna_drawable_is_clear(dst->pDrawable))
+                       op = PictOpSrc;
+               lerp = op == PictOpSrc;
+       }
+       if (!lerp) {
+               switch (op) {
+               case PictOpOver:
+               case PictOpAdd:
+               case PictOpOutReverse:
+                       break;
+               case PictOpSrc:
+                       if (!sna_drawable_is_clear(dst->pDrawable))
+                               return false;
+                       break;
+               default:
+                       return false;
+               }
+       }
+
+       if (maskFormat == NULL && ntrap > 1) {
+               DBG(("%s: individual rasterisation requested\n",
+                    __FUNCTION__));
+               do {
+                       /* XXX unwind errors? */
+                       if (!trapezoid_span_inplace__x8r8g8b8(op, dst,
+                                                             src, src_x, src_y,
+                                                             NULL, 1, traps++))
+                               return false;
+               } while (--ntrap);
+               return true;
+       }
+
+       trapezoids_bounds(ntrap, traps, &region.extents);
+       if (region.extents.y1 >= region.extents.y2 ||
+           region.extents.x1 >= region.extents.x2)
+               return true;
+
+       DBG(("%s: extents (%d, %d), (%d, %d)\n",
+            __FUNCTION__,
+            region.extents.x1, region.extents.y1,
+            region.extents.x2, region.extents.y2));
+
+       if (!sna_compute_composite_extents(&region.extents,
+                                          src, NULL, dst,
+                                          src_x, src_y,
+                                          0, 0,
+                                          region.extents.x1, region.extents.y1,
+                                          region.extents.x2 - region.extents.x1,
+                                          region.extents.y2 - region.extents.y1))
+               return true;
+
+       DBG(("%s: clipped extents (%d, %d), (%d, %d)\n",
+            __FUNCTION__,
+            region.extents.x1, region.extents.y1,
+            region.extents.x2, region.extents.y2));
+
+       if (tor_init(&tor, &region.extents, 2*ntrap))
+               return true;
+
+       dx = dst->pDrawable->x * FAST_SAMPLES_X;
+       dy = dst->pDrawable->y * FAST_SAMPLES_Y;
+
+       for (n = 0; n < ntrap; n++) {
+               xTrapezoid t;
+
+               if (!project_trapezoid_onto_grid(&traps[n], dx, dy, &t))
+                       continue;
+
+               if (pixman_fixed_to_int(traps[n].top) >= region.extents.y2 - dst->pDrawable->y ||
+                   pixman_fixed_to_int(traps[n].bottom) < region.extents.y1 - dst->pDrawable->y)
+                       continue;
+
+               tor_add_edge(&tor, &t, &t.left, 1);
+               tor_add_edge(&tor, &t, &t.right, -1);
+       }
+
+       DBG(("%s: move-to-cpu\n", __FUNCTION__));
+       region.data = NULL;
+       if (sna_drawable_move_region_to_cpu(dst->pDrawable, &region,
+                                           MOVE_WRITE | MOVE_READ)) {
+               PixmapPtr pixmap;
+
+               pixmap = get_drawable_pixmap(dst->pDrawable);
+               get_drawable_deltas(dst->pDrawable, pixmap, &dst_x, &dst_y);
+
+               DBG(("%s: format=%x, op=%d, color=%x\n",
+                    __FUNCTION__, dst->format, op, color));
+
+               if (lerp) {
+                       struct inplace inplace;
+
+                       inplace.ptr = pixmap->devPrivate.ptr;
+                       inplace.ptr += dst_y * pixmap->devKind + dst_x;
+                       inplace.stride = pixmap->devKind;
+                       inplace.color = color;
+
+                       if (dst->pCompositeClip->data)
+                               span = tor_blt_lerp32_clipped;
+                       else
+                               span = tor_blt_lerp32;
+
+                       DBG(("%s: render inplace op=%d, color=%08x\n",
+                            __FUNCTION__, op, color));
+
+                       tor_render(NULL, &tor, (void*)&inplace,
+                                  dst->pCompositeClip, span, false);
+                       tor_fini(&tor);
+               } else {
+                       struct pixman_inplace pi;
+
+                       pi.image = image_from_pict(dst, false, &pi.dx, &pi.dy);
+                       pi.source = image_from_pict(src, false, &pi.sx, &pi.sy);
+                       pi.sx += src_x - pixman_fixed_to_int(traps[0].left.p1.x);
+                       pi.sy += src_y - pixman_fixed_to_int(traps[0].left.p1.y);
+                       pi.mask = pixman_image_create_bits(PIXMAN_a8, 1, 1, NULL, 0);
+                       pixman_image_set_repeat(pi.mask, PIXMAN_REPEAT_NORMAL);
+                       pi.bits = pixman_image_get_data(pi.mask);
+                       pi.op = op;
+
+                       if (dst->pCompositeClip->data)
+                               span = pixmask_span__clipped;
+                       else
+                               span = pixmask_span;
+
+                       tor_render(NULL, &tor, (void*)&pi,
+                                  dst->pCompositeClip, span,
+                                  false);
+                       tor_fini(&tor);
+
+                       pixman_image_unref(pi.mask);
+                       pixman_image_unref(pi.source);
+                       pixman_image_unref(pi.image);
+               }
+       }
+
+       return true;
+}
+
+static bool
+trapezoid_span_inplace(CARD8 op, PicturePtr src, PicturePtr dst,
+                      PictFormatPtr maskFormat, INT16 src_x, INT16 src_y,
+                      int ntrap, xTrapezoid *traps,
+                      bool fallback)
+{
+       struct tor tor;
+       struct inplace inplace;
+       span_func_t span;
+       PixmapPtr pixmap;
+       struct sna_pixmap *priv;
+       RegionRec region;
+       uint32_t color;
+       bool unbounded;
+       int16_t dst_x, dst_y;
+       int dx, dy;
+       int n;
+
+       if (NO_SCAN_CONVERTER)
+               return false;
+
+       if (dst->polyMode == PolyModePrecise && !is_mono(dst, maskFormat)) {
+               DBG(("%s: fallback -- precise rasterisation requested\n",
+                    __FUNCTION__));
+               return false;
+       }
+       if (dst->alphaMap) {
+               DBG(("%s: fallback -- dst alphamap\n",
+                    __FUNCTION__));
+               return false;
+       }
+
+       if (!fallback && is_gpu(dst->pDrawable)) {
+               DBG(("%s: fallback -- can not perform operation in place, destination busy\n",
+                    __FUNCTION__));
+
+               return false;
+       }
+
+       if (is_mono(dst, maskFormat))
+               return trapezoid_span_mono_inplace(op, src, dst,
+                                                  src_x, src_y, ntrap, traps);
+
+       if (dst->format == PICT_a8r8g8b8 || dst->format == PICT_x8r8g8b8)
+               return trapezoid_span_inplace__x8r8g8b8(op, dst,
+                                                       src, src_x, src_y,
+                                                       maskFormat,
+                                                       ntrap, traps);
+
+       if (!sna_picture_is_solid(src, &color)) {
+               DBG(("%s: fallback -- can not perform operation in place, requires solid source\n",
+                    __FUNCTION__));
+               return false;
+       }
+
+       if (dst->format != PICT_a8) {
+               DBG(("%s: fallback -- can not perform operation in place, format=%x\n",
+                    __FUNCTION__, dst->format));
+               return false;
+       }
+
+       pixmap = get_drawable_pixmap(dst->pDrawable);
+
+       unbounded = false;
+       priv = sna_pixmap(pixmap);
+       if (priv) {
+               switch (op) {
+               case PictOpAdd:
+                       if (priv->clear && priv->clear_color == 0) {
+                               unbounded = true;
+                               op = PictOpSrc;
+                       }
+                       if ((color >> 24) == 0)
+                               return true;
+                       break;
+               case PictOpIn:
+                       if (priv->clear && priv->clear_color == 0)
+                               return true;
+                       if (priv->clear && priv->clear_color == 0xff)
+                               op = PictOpSrc;
+                       unbounded = true;
+                       break;
+               case PictOpSrc:
+                       unbounded = true;
+                       break;
+               default:
+                       DBG(("%s: fallback -- can not perform op [%d] in place\n",
+                            __FUNCTION__, op));
+                       return false;
+               }
+       } else {
+               switch (op) {
+               case PictOpAdd:
+                       if ((color >> 24) == 0)
+                               return true;
+                       break;
+               case PictOpIn:
+               case PictOpSrc:
+                       unbounded = true;
+                       break;
+               default:
+                       DBG(("%s: fallback -- can not perform op [%d] in place\n",
+                            __FUNCTION__, op));
+                       return false;
+               }
+       }
+
+       DBG(("%s: format=%x, op=%d, color=%x\n",
+            __FUNCTION__, dst->format, op, color));
+
+       if (maskFormat == NULL && ntrap > 1) {
+               DBG(("%s: individual rasterisation requested\n",
+                    __FUNCTION__));
+               do {
+                       /* XXX unwind errors? */
+                       if (!trapezoid_span_inplace(op, src, dst, NULL,
+                                                   src_x, src_y, 1, traps++,
+                                                   fallback))
+                               return false;
+               } while (--ntrap);
+               return true;
+       }
+
+       trapezoids_bounds(ntrap, traps, &region.extents);
+       if (region.extents.y1 >= region.extents.y2 ||
+           region.extents.x1 >= region.extents.x2)
+               return true;
+
+       DBG(("%s: extents (%d, %d), (%d, %d)\n",
+            __FUNCTION__,
+            region.extents.x1, region.extents.y1,
+            region.extents.x2, region.extents.y2));
+
+       if (!sna_compute_composite_extents(&region.extents,
+                                          NULL, NULL, dst,
+                                          0, 0,
+                                          0, 0,
+                                          region.extents.x1, region.extents.y1,
+                                          region.extents.x2 - region.extents.x1,
+                                          region.extents.y2 - region.extents.y1))
+               return true;
+
+       DBG(("%s: clipped extents (%d, %d), (%d, %d)\n",
+            __FUNCTION__,
+            region.extents.x1, region.extents.y1,
+            region.extents.x2, region.extents.y2));
+
+       if (tor_init(&tor, &region.extents, 2*ntrap))
+               return true;
+
+       dx = dst->pDrawable->x * FAST_SAMPLES_X;
+       dy = dst->pDrawable->y * FAST_SAMPLES_Y;
+
+       for (n = 0; n < ntrap; n++) {
+               xTrapezoid t;
+
+               if (!project_trapezoid_onto_grid(&traps[n], dx, dy, &t))
+                       continue;
+
+               if (pixman_fixed_to_int(traps[n].top) >= region.extents.y2 - dst->pDrawable->y ||
+                   pixman_fixed_to_int(traps[n].bottom) < region.extents.y1 - dst->pDrawable->y)
+                       continue;
+
+               tor_add_edge(&tor, &t, &t.left, 1);
+               tor_add_edge(&tor, &t, &t.right, -1);
+       }
+
+       if (op == PictOpSrc) {
+               if (dst->pCompositeClip->data)
+                       span = tor_blt_src_clipped;
+               else
+                       span = tor_blt_src;
+       } else if (op == PictOpIn) {
+               if (dst->pCompositeClip->data)
+                       span = tor_blt_in_clipped;
+               else
+                       span = tor_blt_in;
+       } else {
+               assert(op == PictOpAdd);
+               if (dst->pCompositeClip->data)
+                       span = tor_blt_add_clipped;
+               else
+                       span = tor_blt_add;
+       }
+
+       DBG(("%s: move-to-cpu\n", __FUNCTION__));
+       region.data = NULL;
+       if (!sna_drawable_move_region_to_cpu(dst->pDrawable, &region,
+                                            op == PictOpSrc ? MOVE_WRITE | MOVE_INPLACE_HINT : MOVE_WRITE | MOVE_READ))
+               return true;
+
+       get_drawable_deltas(dst->pDrawable, pixmap, &dst_x, &dst_y);
+
+       inplace.ptr = pixmap->devPrivate.ptr;
+       inplace.ptr += dst_y * pixmap->devKind + dst_x;
+       inplace.stride = pixmap->devKind;
+       inplace.opacity = color >> 24;
+
+       tor_render(NULL, &tor, (void*)&inplace,
+                  dst->pCompositeClip, span, unbounded);
+
+       tor_fini(&tor);
+
+       return true;
+}
+
+static bool
+trapezoid_span_fallback(CARD8 op, PicturePtr src, PicturePtr dst,
+                       PictFormatPtr maskFormat, INT16 src_x, INT16 src_y,
+                       int ntrap, xTrapezoid *traps)
+{
+       struct tor tor;
+       ScreenPtr screen = dst->pDrawable->pScreen;
+       PixmapPtr scratch;
+       PicturePtr mask;
+       BoxRec extents;
+       int16_t dst_x, dst_y;
+       int dx, dy;
+       int error, n;
+
+       if (NO_SCAN_CONVERTER)
+               return false;
+
+       if (dst->polyMode == PolyModePrecise && !is_mono(dst, maskFormat)) {
+               DBG(("%s: fallback -- precise rasterisation requested\n",
+                    __FUNCTION__));
+               return false;
+       }
+
+       if (maskFormat == NULL && ntrap > 1) {
+               DBG(("%s: individual rasterisation requested\n",
+                    __FUNCTION__));
+               do {
+                       /* XXX unwind errors? */
+                       if (!trapezoid_span_fallback(op, src, dst, NULL,
+                                                    src_x, src_y, 1, traps++))
+                               return false;
+               } while (--ntrap);
+               return true;
+       }
+
+       trapezoids_bounds(ntrap, traps, &extents);
+       if (extents.y1 >= extents.y2 || extents.x1 >= extents.x2)
+               return true;
+
+       DBG(("%s: ntraps=%d, extents (%d, %d), (%d, %d)\n",
+            __FUNCTION__, ntrap, extents.x1, extents.y1, extents.x2, extents.y2));
+
+       if (!sna_compute_composite_extents(&extents,
+                                          src, NULL, dst,
+                                          src_x, src_y,
+                                          0, 0,
+                                          extents.x1, extents.y1,
+                                          extents.x2 - extents.x1,
+                                          extents.y2 - extents.y1))
+               return true;
+
+       DBG(("%s: extents (%d, %d), (%d, %d)\n",
+            __FUNCTION__, extents.x1, extents.y1, extents.x2, extents.y2));
+
+       extents.y2 -= extents.y1;
+       extents.x2 -= extents.x1;
+       extents.x1 -= dst->pDrawable->x;
+       extents.y1 -= dst->pDrawable->y;
+       dst_x = extents.x1;
+       dst_y = extents.y1;
+       dx = -extents.x1 * FAST_SAMPLES_X;
+       dy = -extents.y1 * FAST_SAMPLES_Y;
+       extents.x1 = extents.y1 = 0;
+
+       DBG(("%s: mask (%dx%d), dx=(%d, %d)\n",
+            __FUNCTION__, extents.x2, extents.y2, dx, dy));
+       scratch = sna_pixmap_create_unattached(screen,
+                                              extents.x2, extents.y2, 8);
+       if (!scratch)
+               return true;
+
+       DBG(("%s: created buffer %p, stride %d\n",
+            __FUNCTION__, scratch->devPrivate.ptr, scratch->devKind));
+
+       if (tor_init(&tor, &extents, 2*ntrap)) {
+               sna_pixmap_destroy(scratch);
+               return true;
+       }
+
+       for (n = 0; n < ntrap; n++) {
+               xTrapezoid t;
+
+               if (!project_trapezoid_onto_grid(&traps[n], dx, dy, &t))
+                       continue;
+
+               if (pixman_fixed_to_int(traps[n].top) - dst_y >= extents.y2 ||
+                   pixman_fixed_to_int(traps[n].bottom) - dst_y < 0)
+                       continue;
+
+               tor_add_edge(&tor, &t, &t.left, 1);
+               tor_add_edge(&tor, &t, &t.right, -1);
+       }
+
+       if (extents.x2 <= TOR_INPLACE_SIZE) {
+               tor_inplace(&tor, scratch, is_mono(dst, maskFormat), NULL);
+       } else {
+               tor_render(NULL, &tor,
+                          scratch->devPrivate.ptr,
+                          (void *)(intptr_t)scratch->devKind,
+                          is_mono(dst, maskFormat) ? tor_blt_mask_mono : tor_blt_mask,
+                          true);
+       }
+       tor_fini(&tor);
+
+       mask = CreatePicture(0, &scratch->drawable,
+                            PictureMatchFormat(screen, 8, PICT_a8),
+                            0, 0, serverClient, &error);
+       if (mask) {
+               RegionRec region;
+
+               region.extents.x1 = dst_x + dst->pDrawable->x;
+               region.extents.y1 = dst_y + dst->pDrawable->y;
+               region.extents.x2 = region.extents.x1 + extents.x2;
+               region.extents.y2 = region.extents.y1 + extents.y2;
+               region.data = NULL;
+
+               DBG(("%s: move-to-cpu\n", __FUNCTION__));
+               if (!sna_drawable_move_region_to_cpu(dst->pDrawable, &region,
+                                                    MOVE_READ | MOVE_WRITE))
+                       goto done;
+               if (dst->alphaMap  &&
+                   !sna_drawable_move_to_cpu(dst->alphaMap->pDrawable,
+                                             MOVE_READ | MOVE_WRITE))
+                       goto done;
+               if (src->pDrawable) {
+                       if (!sna_drawable_move_to_cpu(src->pDrawable,
+                                                     MOVE_READ))
+                               goto done;
+                       if (src->alphaMap &&
+                           !sna_drawable_move_to_cpu(src->alphaMap->pDrawable,
+                                                     MOVE_READ))
+                               goto done;
+               }
+
+               DBG(("%s: fbComposite()\n", __FUNCTION__));
+               fbComposite(op, src, mask, dst,
+                           src_x + dst_x - pixman_fixed_to_int(traps[0].left.p1.x),
+                           src_y + dst_y - pixman_fixed_to_int(traps[0].left.p1.y),
+                           0, 0,
+                           dst_x, dst_y,
+                           extents.x2, extents.y2);
+done:
+               FreePicture(mask, 0);
+       }
+       sna_pixmap_destroy(scratch);
+
+       return true;
+}
+
+void
+sna_composite_trapezoids(CARD8 op,
+                        PicturePtr src,
+                        PicturePtr dst,
+                        PictFormatPtr maskFormat,
+                        INT16 xSrc, INT16 ySrc,
+                        int ntrap, xTrapezoid *traps)
+{
+       PixmapPtr pixmap = get_drawable_pixmap(dst->pDrawable);
+       struct sna *sna = to_sna_from_pixmap(pixmap);
+       struct sna_pixmap *priv;
+       bool rectilinear, pixel_aligned, force_fallback;
+       unsigned flags;
+       int n;
+
+       DBG(("%s(op=%d, src=(%d, %d), mask=%08x, ntrap=%d)\n", __FUNCTION__,
+            op, xSrc, ySrc,
+            maskFormat ? (int)maskFormat->format : 0,
+            ntrap));
+
+       if (ntrap == 0)
+               return;
+
+       if (NO_ACCEL)
+               goto fallback;
+
+       if (wedged(sna)) {
+               DBG(("%s: fallback -- wedged\n", __FUNCTION__));
+               goto fallback;
+       }
+
+       if (dst->alphaMap) {
+               DBG(("%s: fallback -- dst alpha map\n", __FUNCTION__));
+               goto fallback;
+       }
+
+       priv = sna_pixmap(pixmap);
+       if (priv == NULL) {
+               DBG(("%s: fallback -- dst is unattached\n", __FUNCTION__));
+               goto fallback;
+       }
+
+       force_fallback = FORCE_FALLBACK > 0;
+       if ((too_small(priv) || DAMAGE_IS_ALL(priv->cpu_damage)) &&
+           !picture_is_gpu(src)) {
+               DBG(("%s: force fallbacks -- dst is too small, %dx%d\n",
+                    __FUNCTION__,
+                    dst->pDrawable->width,
+                    dst->pDrawable->height));
+               force_fallback = true;
+       }
+       if (FORCE_FALLBACK < 0)
+               force_fallback = false;
+
+       /* scan through for fast rectangles */
+       rectilinear = pixel_aligned = true;
+       if (is_mono(dst, maskFormat)) {
+               for (n = 0; n < ntrap && rectilinear; n++) {
+                       int lx1 = pixman_fixed_to_int(traps[n].left.p1.x + pixman_fixed_1_minus_e/2);
+                       int lx2 = pixman_fixed_to_int(traps[n].left.p2.x + pixman_fixed_1_minus_e/2);
+                       int rx1 = pixman_fixed_to_int(traps[n].right.p1.x + pixman_fixed_1_minus_e/2);
+                       int rx2 = pixman_fixed_to_int(traps[n].right.p2.x + pixman_fixed_1_minus_e/2);
+                       rectilinear &= lx1 == lx2 && rx1 == rx2;
+               }
+       } else if (dst->polyMode != PolyModePrecise) {
+               for (n = 0; n < ntrap && rectilinear; n++) {
+                       int lx1 = pixman_fixed_to_grid(traps[n].left.p1.x);
+                       int lx2 = pixman_fixed_to_grid(traps[n].left.p2.x);
+                       int rx1 = pixman_fixed_to_grid(traps[n].right.p1.x);
+                       int rx2 = pixman_fixed_to_grid(traps[n].right.p2.x);
+                       int top = pixman_fixed_to_grid(traps[n].top);
+                       int bot = pixman_fixed_to_grid(traps[n].bottom);
+
+                       rectilinear &= lx1 == lx2 && rx1 == rx2;
+                       pixel_aligned &= ((top | bot | lx1 | lx2 | rx1 | rx2) & FAST_SAMPLES_mask) == 0;
+               }
+       } else {
+               for (n = 0; n < ntrap && rectilinear; n++) {
+                       rectilinear &=
+                               traps[n].left.p1.x == traps[n].left.p2.x &&
+                               traps[n].right.p1.x == traps[n].right.p2.x;
+                       pixel_aligned &=
+                               ((traps[n].top | traps[n].bottom |
+                                 traps[n].left.p1.x | traps[n].left.p2.x |
+                                 traps[n].right.p1.x | traps[n].right.p2.x)
+                                & pixman_fixed_1_minus_e) == 0;
+               }
+       }
+
+       DBG(("%s: rectilinear? %d, pixel-aligned? %d\n",
+            __FUNCTION__, rectilinear, pixel_aligned));
+       flags = 0;
+       if (rectilinear) {
+               if (pixel_aligned) {
+                       if (composite_aligned_boxes(sna, op, src, dst,
+                                                   maskFormat,
+                                                   xSrc, ySrc,
+                                                   ntrap, traps,
+                                                   force_fallback))
+                           return;
+               } else {
+                       if (composite_unaligned_boxes(sna, op, src, dst,
+                                                     maskFormat,
+                                                     xSrc, ySrc,
+                                                     ntrap, traps,
+                                                     force_fallback))
+                               return;
+               }
+               flags |= COMPOSITE_SPANS_RECTILINEAR;
+       }
+
+       if (force_fallback)
+               goto fallback;
+
+       if (is_mono(dst, maskFormat) &&
+           mono_trapezoids_span_converter(op, src, dst,
+                                          xSrc, ySrc,
+                                          ntrap, traps))
+               return;
+
+       if (trapezoid_spans_maybe_inplace(op, src, dst, maskFormat)) {
+               flags |= COMPOSITE_SPANS_INPLACE_HINT;
+               if (trapezoid_span_inplace(op, src, dst, maskFormat,
+                                          xSrc, ySrc, ntrap, traps,
+                                          false))
+                       return;
+       }
+
+       if (trapezoid_span_converter(op, src, dst, maskFormat, flags,
+                                    xSrc, ySrc, ntrap, traps))
+               return;
+
+       if (trapezoid_span_inplace(op, src, dst, maskFormat,
+                                  xSrc, ySrc, ntrap, traps,
+                                  false))
+               return;
+
+       if (trapezoid_mask_converter(op, src, dst, maskFormat,
+                                    xSrc, ySrc, ntrap, traps))
+               return;
+
+fallback:
+       if (trapezoid_span_inplace(op, src, dst, maskFormat,
+                                  xSrc, ySrc, ntrap, traps,
+                                  true))
+               return;
+
+       if (trapezoid_span_fallback(op, src, dst, maskFormat,
+                                   xSrc, ySrc, ntrap, traps))
+               return;
+
+       if (trapezoids_inplace_fallback(op, src, dst, maskFormat, ntrap, traps))
+               return;
+
+       DBG(("%s: fallback mask=%08x, ntrap=%d\n", __FUNCTION__,
+            maskFormat ? (unsigned)maskFormat->format : 0, ntrap));
+       trapezoids_fallback(op, src, dst, maskFormat,
+                           xSrc, ySrc,
+                           ntrap, traps);
+}
+
+static inline bool
+project_trap_onto_grid(const xTrap *in,
+                      int dx, int dy,
+                      xTrap *out)
+{
+       out->top.l = dx + pixman_fixed_to_grid(in->top.l);
+       out->top.r = dx + pixman_fixed_to_grid(in->top.r);
+       out->top.y = dy + pixman_fixed_to_grid(in->top.y);
+
+       out->bot.l = dx + pixman_fixed_to_grid(in->bot.l);
+       out->bot.r = dx + pixman_fixed_to_grid(in->bot.r);
+       out->bot.y = dy + pixman_fixed_to_grid(in->bot.y);
+
+       return out->bot.y > out->top.y;
+}
+
+static bool
+mono_trap_span_converter(PicturePtr dst,
+                        INT16 x, INT16 y,
+                        int ntrap, xTrap *traps)
+{
+       struct mono mono;
+       xRenderColor white;
+       PicturePtr src;
+       int error;
+       int n;
+
+       white.red = white.green = white.blue = white.alpha = 0xffff;
+       src = CreateSolidPicture(0, &white, &error);
+       if (src == NULL)
+               return true;
+
+       mono.clip = *dst->pCompositeClip;
+       x += dst->pDrawable->x;
+       y += dst->pDrawable->y;
+
+       DBG(("%s: after clip -- extents (%d, %d), (%d, %d), delta=(%d, %d)\n",
+            __FUNCTION__,
+            mono.clip.extents.x1, mono.clip.extents.y1,
+            mono.clip.extents.x2, mono.clip.extents.y2,
+            x, y));
+
+       mono.sna = to_sna_from_drawable(dst->pDrawable);
+       if (!mono_init(&mono, 2*ntrap))
+               return false;
+
+       for (n = 0; n < ntrap; n++) {
+               xPointFixed p1, p2;
+
+               if (pixman_fixed_to_int(traps[n].top.y) + y >= mono.clip.extents.y2 ||
+                   pixman_fixed_to_int(traps[n].bot.y) + y < mono.clip.extents.y1)
+                       continue;
+
+               p1.y = traps[n].top.y;
+               p2.y = traps[n].bot.y;
+
+               p1.x = traps[n].top.l;
+               p2.x = traps[n].bot.l;
+               mono_add_line(&mono, x, y,
+                             traps[n].top.y, traps[n].bot.y,
+                             &p1, &p2, 1);
+
+               p1.x = traps[n].top.r;
+               p2.x = traps[n].bot.r;
+               mono_add_line(&mono, x, y,
+                             traps[n].top.y, traps[n].bot.y,
+                             &p1, &p2, -1);
+       }
+
+       memset(&mono.op, 0, sizeof(mono.op));
+       if (mono.sna->render.composite(mono.sna, PictOpAdd, src, NULL, dst,
+                                       0, 0,
+                                       0, 0,
+                                       mono.clip.extents.x1,  mono.clip.extents.y1,
+                                       mono.clip.extents.x2 - mono.clip.extents.x1,
+                                       mono.clip.extents.y2 - mono.clip.extents.y1,
+                                       &mono.op)) {
+               mono_render(&mono);
+               mono.op.done(mono.sna, &mono.op);
+       }
+
+       mono_fini(&mono);
+       FreePicture(src, 0);
+       return true;
+}
+
+static bool
+trap_span_converter(PicturePtr dst,
+                   INT16 src_x, INT16 src_y,
+                   int ntrap, xTrap *trap)
+{
+       struct sna *sna;
+       struct sna_composite_spans_op tmp;
+       struct tor tor;
+       BoxRec extents;
+       pixman_region16_t *clip;
+       int dx, dy, n;
+
+       if (NO_SCAN_CONVERTER)
+               return false;
+
+       if (dst->pDrawable->depth < 8)
+               return false;
+
+       if (dst->polyEdge == PolyEdgeSharp)
+               return mono_trap_span_converter(dst, src_x, src_y, ntrap, trap);
+
+       sna = to_sna_from_drawable(dst->pDrawable);
+       if (!sna->render.check_composite_spans(sna, PictOpAdd, sna->render.white_picture, dst,
+                                              dst->pCompositeClip->extents.x2 - dst->pCompositeClip->extents.x1,
+                                              dst->pCompositeClip->extents.y2 - dst->pCompositeClip->extents.y1,
+                                              0)) {
+               DBG(("%s: fallback -- composite spans not supported\n",
+                    __FUNCTION__));
+               return false;
+       }
+
+       clip = dst->pCompositeClip;
+       extents = *RegionExtents(clip);
+       dx = dst->pDrawable->x;
+       dy = dst->pDrawable->y;
+
+       DBG(("%s: after clip -- extents (%d, %d), (%d, %d), delta=(%d, %d)\n",
+            __FUNCTION__,
+            extents.x1, extents.y1,
+            extents.x2, extents.y2,
+            dx, dy));
+
+       memset(&tmp, 0, sizeof(tmp));
+       if (!sna->render.composite_spans(sna, PictOpAdd, sna->render.white_picture, dst,
+                                        0, 0,
+                                        extents.x1,  extents.y1,
+                                        extents.x2 - extents.x1,
+                                        extents.y2 - extents.y1,
+                                        0,
+                                        &tmp)) {
+               DBG(("%s: fallback -- composite spans render op not supported\n",
+                    __FUNCTION__));
+               return false;
+       }
+
+       dx *= FAST_SAMPLES_X;
+       dy *= FAST_SAMPLES_Y;
+       if (tor_init(&tor, &extents, 2*ntrap))
+               goto skip;
+
+       for (n = 0; n < ntrap; n++) {
+               xTrap t;
+               xPointFixed p1, p2;
+
+               if (!project_trap_onto_grid(&trap[n], dx, dy, &t))
+                       continue;
+
+               if (pixman_fixed_to_int(trap[n].top.y) + dst->pDrawable->y >= extents.y2 ||
+                   pixman_fixed_to_int(trap[n].bot.y) + dst->pDrawable->y < extents.y1)
+                       continue;
+
+               p1.y = t.top.y;
+               p2.y = t.bot.y;
+               p1.x = t.top.l;
+               p2.x = t.bot.l;
+               polygon_add_line(tor.polygon, &p1, &p2);
+
+               p1.y = t.bot.y;
+               p2.y = t.top.y;
+               p1.x = t.top.r;
+               p2.x = t.bot.r;
+               polygon_add_line(tor.polygon, &p1, &p2);
+       }
+
+       tor_render(sna, &tor, &tmp, clip,
+                  choose_span(&tmp, dst, NULL, PictOpAdd, clip), false);
+
+skip:
+       tor_fini(&tor);
+       tmp.done(sna, &tmp);
+       return true;
+}
+
+static void mark_damaged(PixmapPtr pixmap, struct sna_pixmap *priv,
+                        BoxPtr box, int16_t x, int16_t y)
+{
+       box->x1 += x; box->x2 += x;
+       box->y1 += y; box->y2 += y;
+       if (box->x1 <= 0 && box->y1 <= 0 &&
+           box->x2 >= pixmap->drawable.width &&
+           box->y2 >= pixmap->drawable.height) {
+               sna_damage_destroy(&priv->cpu_damage);
+               sna_damage_all(&priv->gpu_damage,
+                              pixmap->drawable.width,
+                              pixmap->drawable.height);
+               list_del(&priv->list);
+               priv->undamaged = false;
+       } else {
+               sna_damage_add_box(&priv->gpu_damage, box);
+               sna_damage_subtract_box(&priv->cpu_damage, box);
+       }
+}
+
+static bool
+trap_mask_converter(PicturePtr picture,
+                   INT16 x, INT16 y,
+                   int ntrap, xTrap *trap)
+{
+       struct sna *sna;
+       struct tor tor;
+       ScreenPtr screen = picture->pDrawable->pScreen;
+       PixmapPtr scratch, pixmap;
+       struct sna_pixmap *priv;
+       BoxRec extents;
+       span_func_t span;
+       int dx, dy, n;
+
+       if (NO_SCAN_CONVERTER)
+               return false;
+
+       pixmap = get_drawable_pixmap(picture->pDrawable);
+       priv = sna_pixmap_move_to_gpu(pixmap, MOVE_READ | MOVE_WRITE);
+       if (priv == NULL)
+               return false;
+
+       /* XXX strict adherence to the Render specification */
+       if (picture->polyMode == PolyModePrecise &&
+           picture->polyEdge != PolyEdgeSharp) {
+               DBG(("%s: fallback -- precise rasterisation requested\n",
+                    __FUNCTION__));
+               return false;
+       }
+
+       extents = *RegionExtents(picture->pCompositeClip);
+       for (n = 0; n < ntrap; n++) {
+               int v;
+
+               v = x + pixman_fixed_integer_floor (MIN(trap[n].top.l, trap[n].bot.l));
+               if (v < extents.x1)
+                       extents.x1 = v;
+
+               v = x + pixman_fixed_integer_ceil (MAX(trap[n].top.r, trap[n].bot.r));
+               if (v > extents.x2)
+                       extents.x2 = v;
+
+               v = y + pixman_fixed_integer_floor (trap[n].top.y);
+               if (v < extents.y1)
+                       extents.y1 = v;
+
+               v = y + pixman_fixed_integer_ceil (trap[n].bot.y);
+               if (v > extents.y2)
+                       extents.y2 = v;
+       }
+
+       DBG(("%s: extents (%d, %d), (%d, %d)\n",
+            __FUNCTION__, extents.x1, extents.y1, extents.x2, extents.y2));
+
+       scratch = sna_pixmap_create_upload(screen,
+                                          extents.x2-extents.x1,
+                                          extents.y2-extents.y1,
+                                          8, KGEM_BUFFER_WRITE_INPLACE);
+       if (!scratch)
+               return true;
+
+       dx = picture->pDrawable->x;
+       dy = picture->pDrawable->y;
+       dx *= FAST_SAMPLES_X;
+       dy *= FAST_SAMPLES_Y;
+       if (tor_init(&tor, &extents, 2*ntrap)) {
+               sna_pixmap_destroy(scratch);
+               return true;
+       }
+
+       for (n = 0; n < ntrap; n++) {
+               xTrap t;
+               xPointFixed p1, p2;
+
+               if (!project_trap_onto_grid(&trap[n], dx, dy, &t))
+                       continue;
+
+               if (pixman_fixed_to_int(trap[n].top.y) + picture->pDrawable->y >= extents.y2 ||
+                   pixman_fixed_to_int(trap[n].bot.y) + picture->pDrawable->y < extents.y1)
+                       continue;
+
+               p1.y = t.top.y;
+               p2.y = t.bot.y;
+               p1.x = t.top.l;
+               p2.x = t.bot.l;
+               polygon_add_line(tor.polygon, &p1, &p2);
+
+               p1.y = t.bot.y;
+               p2.y = t.top.y;
+               p1.x = t.top.r;
+               p2.x = t.bot.r;
+               polygon_add_line(tor.polygon, &p1, &p2);
+       }
+
+       if (picture->polyEdge == PolyEdgeSharp)
+               span = tor_blt_mask_mono;
+       else
+               span = tor_blt_mask;
+
+       tor_render(NULL, &tor,
+                  scratch->devPrivate.ptr,
+                  (void *)(intptr_t)scratch->devKind,
+                  span, true);
+
+       tor_fini(&tor);
+
+       /* XXX clip boxes */
+       get_drawable_deltas(picture->pDrawable, pixmap, &x, &y);
+       sna = to_sna_from_screen(screen);
+       sna->render.copy_boxes(sna, GXcopy,
+                              scratch, sna_pixmap_get_bo(scratch), -extents.x1, -extents.x1,
+                              pixmap, priv->gpu_bo, x, y,
+                              &extents, 1, 0);
+       mark_damaged(pixmap, priv, &extents ,x, y);
+       sna_pixmap_destroy(scratch);
+       return true;
+}
+
+static bool
+trap_upload(PicturePtr picture,
+           INT16 x, INT16 y,
+           int ntrap, xTrap *trap)
+{
+       ScreenPtr screen = picture->pDrawable->pScreen;
+       struct sna *sna = to_sna_from_screen(screen);
+       PixmapPtr pixmap = get_drawable_pixmap(picture->pDrawable);
+       PixmapPtr scratch;
+       struct sna_pixmap *priv;
+       BoxRec extents;
+       pixman_image_t *image;
+       int width, height, depth;
+       int n;
+
+       priv = sna_pixmap_move_to_gpu(pixmap, MOVE_READ | MOVE_WRITE);
+       if (priv == NULL)
+               return false;
+
+       extents = *RegionExtents(picture->pCompositeClip);
+       for (n = 0; n < ntrap; n++) {
+               int v;
+
+               v = x + pixman_fixed_integer_floor (MIN(trap[n].top.l, trap[n].bot.l));
+               if (v < extents.x1)
+                       extents.x1 = v;
+
+               v = x + pixman_fixed_integer_ceil (MAX(trap[n].top.r, trap[n].bot.r));
+               if (v > extents.x2)
+                       extents.x2 = v;
+
+               v = y + pixman_fixed_integer_floor (trap[n].top.y);
+               if (v < extents.y1)
+                       extents.y1 = v;
+
+               v = y + pixman_fixed_integer_ceil (trap[n].bot.y);
+               if (v > extents.y2)
+                       extents.y2 = v;
+       }
+
+       DBG(("%s: extents (%d, %d), (%d, %d)\n",
+            __FUNCTION__, extents.x1, extents.y1, extents.x2, extents.y2));
+
+       width  = extents.x2 - extents.x1;
+       height = extents.y2 - extents.y1;
+       depth = picture->pDrawable->depth;
+
+       DBG(("%s: tmp (%dx%d) depth=%d\n",
+            __FUNCTION__, width, height, depth));
+       scratch = sna_pixmap_create_upload(screen,
+                                          width, height, depth,
+                                          KGEM_BUFFER_WRITE);
+       if (!scratch)
+               return true;
+
+       memset(scratch->devPrivate.ptr, 0, scratch->devKind*height);
+       image = pixman_image_create_bits(picture->format, width, height,
+                                        scratch->devPrivate.ptr,
+                                        scratch->devKind);
+       if (image) {
+               pixman_add_traps (image, -extents.x1, -extents.y1,
+                                 ntrap, (pixman_trap_t *)trap);
+
+               pixman_image_unref(image);
+       }
+
+       /* XXX clip boxes */
+       get_drawable_deltas(picture->pDrawable, pixmap, &x, &y);
+       sna->render.copy_boxes(sna, GXcopy,
+                              scratch, sna_pixmap_get_bo(scratch), -extents.x1, -extents.x1,
+                              pixmap, priv->gpu_bo, x, y,
+                              &extents, 1, 0);
+       mark_damaged(pixmap, priv, &extents, x, y);
+
+       sna_pixmap_destroy(scratch);
+       return true;
+}
+
+void
+sna_add_traps(PicturePtr picture, INT16 x, INT16 y, int n, xTrap *t)
+{
+       DBG(("%s (%d, %d) x %d\n", __FUNCTION__, x, y, n));
+
+       if (is_gpu(picture->pDrawable)) {
+               if (trap_span_converter(picture, x, y, n, t))
+                       return;
+
+               if (trap_mask_converter(picture, x, y, n, t))
+                       return;
+
+               if (trap_upload(picture, x, y, n, t))
+                       return;
+       }
+
+       DBG(("%s -- fallback\n", __FUNCTION__));
+       if (sna_drawable_move_to_cpu(picture->pDrawable,
+                                    MOVE_READ | MOVE_WRITE)) {
+               pixman_image_t *image;
+               int dx, dy;
+
+               if (!(image = image_from_pict(picture, false, &dx, &dy)))
+                       return;
+
+               pixman_add_traps(image, x + dx, y + dy, n, (pixman_trap_t *)t);
+
+               free_pixman_pict(picture, image);
+       }
+}
+
+static inline void
+project_point_onto_grid(const xPointFixed *in,
+                       int dx, int dy,
+                       xPointFixed *out)
+{
+       out->x = dx + pixman_fixed_to_grid(in->x);
+       out->y = dy + pixman_fixed_to_grid(in->y);
+}
+
+static inline bool
+xTriangleValid(const xTriangle *t)
+{
+       xPointFixed v1, v2;
+
+       v1.x = t->p2.x - t->p1.x;
+       v1.y = t->p2.y - t->p1.y;
+
+       v2.x = t->p3.x - t->p1.x;
+       v2.y = t->p3.y - t->p1.y;
+
+       /* if the length of any edge is zero, the area must be zero */
+       if (v1.x == 0 && v1.y == 0)
+               return false;
+       if (v2.x == 0 && v2.y == 0)
+               return false;
+
+       /* if the cross-product is zero, so it the size */
+       return v2.y * v1.x != v1.y * v2.x;
+}
+
+static inline bool
+project_triangle_onto_grid(const xTriangle *in,
+                          int dx, int dy,
+                          xTriangle *out)
+{
+       project_point_onto_grid(&in->p1, dx, dy, &out->p1);
+       project_point_onto_grid(&in->p2, dx, dy, &out->p2);
+       project_point_onto_grid(&in->p3, dx, dy, &out->p3);
+
+       return xTriangleValid(out);
+}
+
+static bool
+mono_triangles_span_converter(CARD8 op, PicturePtr src, PicturePtr dst,
+                             INT16 src_x, INT16 src_y,
+                             int count, xTriangle *tri)
+{
+       struct mono mono;
+       BoxRec extents;
+       int16_t dst_x, dst_y;
+       int16_t dx, dy;
+       bool was_clear;
+       int n;
+
+       mono.sna = to_sna_from_drawable(dst->pDrawable);
+
+       dst_x = pixman_fixed_to_int(tri[0].p1.x);
+       dst_y = pixman_fixed_to_int(tri[0].p1.y);
+
+       miTriangleBounds(count, tri, &extents);
+       DBG(("%s: extents (%d, %d), (%d, %d)\n",
+            __FUNCTION__, extents.x1, extents.y1, extents.x2, extents.y2));
+
+       if (extents.y1 >= extents.y2 || extents.x1 >= extents.x2)
+               return true;
+
+       if (!sna_compute_composite_region(&mono.clip,
+                                         src, NULL, dst,
+                                         src_x + extents.x1 - dst_x,
+                                         src_y + extents.y1 - dst_y,
+                                         0, 0,
+                                         extents.x1, extents.y1,
+                                         extents.x2 - extents.x1,
+                                         extents.y2 - extents.y1)) {
+               DBG(("%s: triangles do not intersect drawable clips\n",
+                    __FUNCTION__)) ;
+               return true;
+       }
+
+       dx = dst->pDrawable->x;
+       dy = dst->pDrawable->y;
+
+       DBG(("%s: after clip -- extents (%d, %d), (%d, %d), delta=(%d, %d) src -> (%d, %d)\n",
+            __FUNCTION__,
+            mono.clip.extents.x1, mono.clip.extents.y1,
+            mono.clip.extents.x2, mono.clip.extents.y2,
+            dx, dy,
+            src_x + mono.clip.extents.x1 - dst_x - dx,
+            src_y + mono.clip.extents.y1 - dst_y - dy));
+
+       was_clear = sna_drawable_is_clear(dst->pDrawable);
+
+       if (mono_init(&mono, 3*count))
+               return false;
+
+       for (n = 0; n < count; n++) {
+               mono_add_line(&mono, dx, dy,
+                             tri[n].p1.y, tri[n].p2.y,
+                             &tri[n].p1, &tri[n].p2, 1);
+               mono_add_line(&mono, dx, dy,
+                             tri[n].p2.y, tri[n].p3.y,
+                             &tri[n].p2, &tri[n].p3, 1);
+               mono_add_line(&mono, dx, dy,
+                             tri[n].p3.y, tri[n].p1.y,
+                             &tri[n].p3, &tri[n].p1, 1);
+       }
+
+       memset(&mono.op, 0, sizeof(mono.op));
+       if (mono.sna->render.composite(mono.sna, op, src, NULL, dst,
+                                      src_x + mono.clip.extents.x1 - dst_x - dx,
+                                      src_y + mono.clip.extents.y1 - dst_y - dy,
+                                      0, 0,
+                                      mono.clip.extents.x1,  mono.clip.extents.y1,
+                                      mono.clip.extents.x2 - mono.clip.extents.x1,
+                                      mono.clip.extents.y2 - mono.clip.extents.y1,
+                                      &mono.op)) {
+               mono_render(&mono);
+               mono.op.done(mono.sna, &mono.op);
+       }
+
+       if (!was_clear && !operator_is_bounded(op)) {
+               xPointFixed p1, p2;
+
+               if (!mono_init(&mono, 2+3*count))
+                       return false;
+
+               p1.y = mono.clip.extents.y1 * pixman_fixed_1;
+               p2.y = mono.clip.extents.y2 * pixman_fixed_1;
+
+               p1.x = mono.clip.extents.x1 * pixman_fixed_1;
+               p2.x = mono.clip.extents.x1 * pixman_fixed_1;
+               mono_add_line(&mono, 0, 0, p1.y, p2.y, &p1, &p2, -1);
+
+               p1.x = mono.clip.extents.x2 * pixman_fixed_1;
+               p2.x = mono.clip.extents.x2 * pixman_fixed_1;
+               mono_add_line(&mono, 0, 0, p1.y, p2.y, &p1, &p2, 1);
+
+               for (n = 0; n < count; n++) {
+                       mono_add_line(&mono, dx, dy,
+                                     tri[n].p1.y, tri[n].p2.y,
+                                     &tri[n].p1, &tri[n].p2, 1);
+                       mono_add_line(&mono, dx, dy,
+                                     tri[n].p2.y, tri[n].p3.y,
+                                     &tri[n].p2, &tri[n].p3, 1);
+                       mono_add_line(&mono, dx, dy,
+                                     tri[n].p3.y, tri[n].p1.y,
+                                     &tri[n].p3, &tri[n].p1, 1);
+               }
+
+               memset(&mono.op, 0, sizeof(mono.op));
+               if (mono.sna->render.composite(mono.sna,
+                                              PictOpClear,
+                                              mono.sna->clear, NULL, dst,
+                                              0, 0,
+                                              0, 0,
+                                              mono.clip.extents.x1,  mono.clip.extents.y1,
+                                              mono.clip.extents.x2 - mono.clip.extents.x1,
+                                              mono.clip.extents.y2 - mono.clip.extents.y1,
+                                              &mono.op)) {
+                       mono_render(&mono);
+                       mono.op.done(mono.sna, &mono.op);
+               }
+               mono_fini(&mono);
+       }
+
+       mono_fini(&mono);
+       REGION_UNINIT(NULL, &mono.clip);
+       return true;
+}
+
+static bool
+triangles_span_converter(CARD8 op, PicturePtr src, PicturePtr dst,
+                        PictFormatPtr maskFormat, INT16 src_x, INT16 src_y,
+                        int count, xTriangle *tri)
+{
+       struct sna *sna;
+       struct sna_composite_spans_op tmp;
+       struct tor tor;
+       BoxRec extents;
+       pixman_region16_t clip;
+       int16_t dst_x, dst_y;
+       int dx, dy, n;
+       bool was_clear;
+
+       if (NO_SCAN_CONVERTER)
+               return false;
+
+       if (is_mono(dst, maskFormat))
+               return mono_triangles_span_converter(op, src, dst,
+                                                    src_x, src_y,
+                                                    count, tri);
+
+       /* XXX strict adherence to the Render specification */
+       if (dst->polyMode == PolyModePrecise) {
+               DBG(("%s: fallback -- precise rasterisation requested\n",
+                    __FUNCTION__));
+               return false;
+       }
+
+       sna = to_sna_from_drawable(dst->pDrawable);
+       if (!sna->render.check_composite_spans(sna, op, src, dst, 0, 0, 0)) {
+               DBG(("%s: fallback -- composite spans not supported\n",
+                    __FUNCTION__));
+               return false;
+       }
+
+       dst_x = pixman_fixed_to_int(tri[0].p1.x);
+       dst_y = pixman_fixed_to_int(tri[0].p1.y);
+
+       miTriangleBounds(count, tri, &extents);
+       DBG(("%s: extents (%d, %d), (%d, %d)\n",
+            __FUNCTION__, extents.x1, extents.y1, extents.x2, extents.y2));
+
+       if (extents.y1 >= extents.y2 || extents.x1 >= extents.x2)
+               return true;
+
+#if 0
+       if (extents.y2 - extents.y1 < 64 && extents.x2 - extents.x1 < 64) {
+               DBG(("%s: fallback -- traps extents too small %dx%d\n",
+                    __FUNCTION__, extents.y2 - extents.y1, extents.x2 - extents.x1));
+               return false;
+       }
+#endif
+
+       if (!sna_compute_composite_region(&clip,
+                                         src, NULL, dst,
+                                         src_x + extents.x1 - dst_x,
+                                         src_y + extents.y1 - dst_y,
+                                         0, 0,
+                                         extents.x1, extents.y1,
+                                         extents.x2 - extents.x1,
+                                         extents.y2 - extents.y1)) {
+               DBG(("%s: triangles do not intersect drawable clips\n",
+                    __FUNCTION__)) ;
+               return true;
+       }
+
+       if (!sna->render.check_composite_spans(sna, op, src, dst,
+                                              clip.extents.x2 - clip.extents.x1,
+                                              clip.extents.y2 - clip.extents.y1,
+                                              0)) {
+               DBG(("%s: fallback -- composite spans not supported\n",
+                    __FUNCTION__));
+               return false;
+       }
+
+       extents = *RegionExtents(&clip);
+       dx = dst->pDrawable->x;
+       dy = dst->pDrawable->y;
+
+       DBG(("%s: after clip -- extents (%d, %d), (%d, %d), delta=(%d, %d) src -> (%d, %d)\n",
+            __FUNCTION__,
+            extents.x1, extents.y1,
+            extents.x2, extents.y2,
+            dx, dy,
+            src_x + extents.x1 - dst_x - dx,
+            src_y + extents.y1 - dst_y - dy));
+
+       was_clear = sna_drawable_is_clear(dst->pDrawable);
+
+       memset(&tmp, 0, sizeof(tmp));
+       if (!sna->render.composite_spans(sna, op, src, dst,
+                                        src_x + extents.x1 - dst_x - dx,
+                                        src_y + extents.y1 - dst_y - dy,
+                                        extents.x1,  extents.y1,
+                                        extents.x2 - extents.x1,
+                                        extents.y2 - extents.y1,
+                                        0,
+                                        &tmp)) {
+               DBG(("%s: fallback -- composite spans render op not supported\n",
+                    __FUNCTION__));
+               return false;
+       }
+
+       dx *= FAST_SAMPLES_X;
+       dy *= FAST_SAMPLES_Y;
+       if (tor_init(&tor, &extents, 3*count))
+               goto skip;
+
+       for (n = 0; n < count; n++) {
+               xTriangle t;
+
+               if (!project_triangle_onto_grid(&tri[n], dx, dy, &t))
+                       continue;
+
+               polygon_add_line(tor.polygon, &t.p1, &t.p2);
+               polygon_add_line(tor.polygon, &t.p2, &t.p3);
+               polygon_add_line(tor.polygon, &t.p3, &t.p1);
+       }
+
+       tor_render(sna, &tor, &tmp, &clip,
+                  choose_span(&tmp, dst, maskFormat, op, &clip),
+                  !was_clear && maskFormat && !operator_is_bounded(op));
+
+skip:
+       tor_fini(&tor);
+       tmp.done(sna, &tmp);
+
+       REGION_UNINIT(NULL, &clip);
+       return true;
+}
+
+static bool
+triangles_mask_converter(CARD8 op, PicturePtr src, PicturePtr dst,
+                        PictFormatPtr maskFormat, INT16 src_x, INT16 src_y,
+                        int count, xTriangle *tri)
+{
+       struct tor tor;
+       void (*span)(struct sna *sna,
+                    struct sna_composite_spans_op *op,
+                    pixman_region16_t *clip,
+                    const BoxRec *box,
+                    int coverage);
+       ScreenPtr screen = dst->pDrawable->pScreen;
+       PixmapPtr scratch;
+       PicturePtr mask;
+       BoxRec extents;
+       int16_t dst_x, dst_y;
+       int dx, dy;
+       int error, n;
+
+       if (NO_SCAN_CONVERTER)
+               return false;
+
+       if (dst->polyMode == PolyModePrecise && !is_mono(dst, maskFormat)) {
+               DBG(("%s: fallback -- precise rasterisation requested\n",
+                    __FUNCTION__));
+               return false;
+       }
+
+       if (maskFormat == NULL && count > 1) {
+               DBG(("%s: fallback -- individual rasterisation requested\n",
+                    __FUNCTION__));
+               return false;
+       }
+
+       miTriangleBounds(count, tri, &extents);
+       DBG(("%s: extents (%d, %d), (%d, %d)\n",
+            __FUNCTION__, extents.x1, extents.y1, extents.x2, extents.y2));
+
+       if (extents.y1 >= extents.y2 || extents.x1 >= extents.x2)
+               return true;
+
+       if (!sna_compute_composite_extents(&extents,
+                                          src, NULL, dst,
+                                          src_x, src_y,
+                                          0, 0,
+                                          extents.x1, extents.y1,
+                                          extents.x2 - extents.x1,
+                                          extents.y2 - extents.y1))
+               return true;
+
+       DBG(("%s: extents (%d, %d), (%d, %d)\n",
+            __FUNCTION__, extents.x1, extents.y1, extents.x2, extents.y2));
+
+       extents.y2 -= extents.y1;
+       extents.x2 -= extents.x1;
+       extents.x1 -= dst->pDrawable->x;
+       extents.y1 -= dst->pDrawable->y;
+       dst_x = extents.x1;
+       dst_y = extents.y1;
+       dx = -extents.x1 * FAST_SAMPLES_X;
+       dy = -extents.y1 * FAST_SAMPLES_Y;
+       extents.x1 = extents.y1 = 0;
+
+       DBG(("%s: mask (%dx%d)\n",
+            __FUNCTION__, extents.x2, extents.y2));
+       scratch = sna_pixmap_create_upload(screen,
+                                          extents.x2, extents.y2, 8,
+                                          KGEM_BUFFER_WRITE_INPLACE);
+       if (!scratch)
+               return true;
+
+       DBG(("%s: created buffer %p, stride %d\n",
+            __FUNCTION__, scratch->devPrivate.ptr, scratch->devKind));
+
+       if (tor_init(&tor, &extents, 3*count)) {
+               sna_pixmap_destroy(scratch);
+               return true;
+       }
+
+       for (n = 0; n < count; n++) {
+               xTriangle t;
+
+               if (!project_triangle_onto_grid(&tri[n], dx, dy, &t))
+                       continue;
+
+               polygon_add_line(tor.polygon, &t.p1, &t.p2);
+               polygon_add_line(tor.polygon, &t.p2, &t.p3);
+               polygon_add_line(tor.polygon, &t.p3, &t.p1);
+       }
+
+       if (maskFormat ? maskFormat->depth < 8 : dst->polyEdge == PolyEdgeSharp)
+               span = tor_blt_mask_mono;
+       else
+               span = tor_blt_mask;
+
+       tor_render(NULL, &tor,
+                  scratch->devPrivate.ptr,
+                  (void *)(intptr_t)scratch->devKind,
+                  span, true);
+
+       mask = CreatePicture(0, &scratch->drawable,
+                            PictureMatchFormat(screen, 8, PICT_a8),
+                            0, 0, serverClient, &error);
+       if (mask) {
+               CompositePicture(op, src, mask, dst,
+                                src_x + dst_x - pixman_fixed_to_int(tri[0].p1.x),
+                                src_y + dst_y - pixman_fixed_to_int(tri[0].p1.y),
+                                0, 0,
+                                dst_x, dst_y,
+                                extents.x2, extents.y2);
+               FreePicture(mask, 0);
+       }
+       tor_fini(&tor);
+       sna_pixmap_destroy(scratch);
+
+       return true;
+}
+
+static void
+triangles_fallback(CARD8 op,
+                  PicturePtr src,
+                  PicturePtr dst,
+                  PictFormatPtr maskFormat,
+                  INT16 xSrc, INT16 ySrc,
+                  int n, xTriangle *tri)
+{
+       ScreenPtr screen = dst->pDrawable->pScreen;
+
+       DBG(("%s op=%d, count=%d\n", __FUNCTION__, op, n));
+
+       if (maskFormat) {
+               PixmapPtr scratch;
+               PicturePtr mask;
+               INT16 dst_x, dst_y;
+               BoxRec bounds;
+               int width, height, depth;
+               pixman_image_t *image;
+               pixman_format_code_t format;
+               int error;
+
+               dst_x = pixman_fixed_to_int(tri[0].p1.x);
+               dst_y = pixman_fixed_to_int(tri[0].p1.y);
+
+               miTriangleBounds(n, tri, &bounds);
+               DBG(("%s: bounds (%d, %d), (%d, %d)\n",
+                    __FUNCTION__, bounds.x1, bounds.y1, bounds.x2, bounds.y2));
+
+               if (bounds.y1 >= bounds.y2 || bounds.x1 >= bounds.x2)
+                       return;
+
+               if (!sna_compute_composite_extents(&bounds,
+                                                  src, NULL, dst,
+                                                  xSrc, ySrc,
+                                                  0, 0,
+                                                  bounds.x1, bounds.y1,
+                                                  bounds.x2 - bounds.x1,
+                                                  bounds.y2 - bounds.y1))
+                       return;
+
+               DBG(("%s: extents (%d, %d), (%d, %d)\n",
+                    __FUNCTION__, bounds.x1, bounds.y1, bounds.x2, bounds.y2));
+
+               width  = bounds.x2 - bounds.x1;
+               height = bounds.y2 - bounds.y1;
+               bounds.x1 -= dst->pDrawable->x;
+               bounds.y1 -= dst->pDrawable->y;
+               depth = maskFormat->depth;
+               format = maskFormat->format | (BitsPerPixel(depth) << 24);
+
+               DBG(("%s: mask (%dx%d) depth=%d, format=%08x\n",
+                    __FUNCTION__, width, height, depth, format));
+               scratch = sna_pixmap_create_upload(screen,
+                                                  width, height, depth,
+                                                  KGEM_BUFFER_WRITE);
+               if (!scratch)
+                       return;
+
+               memset(scratch->devPrivate.ptr, 0, scratch->devKind*height);
+               image = pixman_image_create_bits(format, width, height,
+                                                scratch->devPrivate.ptr,
+                                                scratch->devKind);
+               if (image) {
+                       pixman_add_triangles(image,
+                                            -bounds.x1, -bounds.y1,
+                                            n, (pixman_triangle_t *)tri);
+                       pixman_image_unref(image);
+               }
+
+               mask = CreatePicture(0, &scratch->drawable,
+                                    PictureMatchFormat(screen, depth, format),
+                                    0, 0, serverClient, &error);
+               if (mask) {
+                       CompositePicture(op, src, mask, dst,
+                                        xSrc + bounds.x1 - dst_x,
+                                        ySrc + bounds.y1 - dst_y,
+                                        0, 0,
+                                        bounds.x1, bounds.y1,
+                                        width, height);
+                       FreePicture(mask, 0);
+               }
+               sna_pixmap_destroy(scratch);
+       } else {
+               if (dst->polyEdge == PolyEdgeSharp)
+                       maskFormat = PictureMatchFormat(screen, 1, PICT_a1);
+               else
+                       maskFormat = PictureMatchFormat(screen, 8, PICT_a8);
+
+               for (; n--; tri++)
+                       triangles_fallback(op,
+                                          src, dst, maskFormat,
+                                          xSrc, ySrc, 1, tri);
+       }
+}
+
+void
+sna_composite_triangles(CARD8 op,
+                        PicturePtr src,
+                        PicturePtr dst,
+                        PictFormatPtr maskFormat,
+                        INT16 xSrc, INT16 ySrc,
+                        int n, xTriangle *tri)
+{
+       if (triangles_span_converter(op, src, dst, maskFormat,
+                                    xSrc, ySrc,
+                                    n, tri))
+               return;
+
+       if (triangles_mask_converter(op, src, dst, maskFormat,
+                                    xSrc, ySrc,
+                                    n, tri))
+               return;
+
+       triangles_fallback(op, src, dst, maskFormat, xSrc, ySrc, n, tri);
+}
+
+static bool
+tristrip_span_converter(CARD8 op, PicturePtr src, PicturePtr dst,
+                       PictFormatPtr maskFormat, INT16 src_x, INT16 src_y,
+                       int count, xPointFixed *points)
+{
+       struct sna *sna;
+       struct sna_composite_spans_op tmp;
+       struct tor tor;
+       BoxRec extents;
+       pixman_region16_t clip;
+       xPointFixed p[4];
+       int16_t dst_x, dst_y;
+       int dx, dy;
+       int cw, ccw, n;
+       bool was_clear;
+
+       if (NO_SCAN_CONVERTER)
+               return false;
+
+       /* XXX strict adherence to the Render specification */
+       if (dst->polyMode == PolyModePrecise && !is_mono(dst, maskFormat)) {
+               DBG(("%s: fallback -- precise rasterisation requested\n",
+                    __FUNCTION__));
+               return false;
+       }
+
+       sna = to_sna_from_drawable(dst->pDrawable);
+       if (!sna->render.check_composite_spans(sna, op, src, dst, 0, 0, 0)) {
+               DBG(("%s: fallback -- composite spans not supported\n",
+                    __FUNCTION__));
+               return false;
+       }
+
+       dst_x = pixman_fixed_to_int(points[0].x);
+       dst_y = pixman_fixed_to_int(points[0].y);
+
+       miPointFixedBounds(count, points, &extents);
+       DBG(("%s: extents (%d, %d), (%d, %d)\n",
+            __FUNCTION__, extents.x1, extents.y1, extents.x2, extents.y2));
+
+       if (extents.y1 >= extents.y2 || extents.x1 >= extents.x2)
+               return true;
+
+#if 0
+       if (extents.y2 - extents.y1 < 64 && extents.x2 - extents.x1 < 64) {
+               DBG(("%s: fallback -- traps extents too small %dx%d\n",
+                    __FUNCTION__, extents.y2 - extents.y1, extents.x2 - extents.x1));
+               return false;
+       }
+#endif
+
+       if (!sna_compute_composite_region(&clip,
+                                         src, NULL, dst,
+                                         src_x + extents.x1 - dst_x,
+                                         src_y + extents.y1 - dst_y,
+                                         0, 0,
+                                         extents.x1, extents.y1,
+                                         extents.x2 - extents.x1,
+                                         extents.y2 - extents.y1)) {
+               DBG(("%s: triangles do not intersect drawable clips\n",
+                    __FUNCTION__)) ;
+               return true;
+       }
+
+       if (!sna->render.check_composite_spans(sna, op, src, dst,
+                                              clip.extents.x2 - clip.extents.x1,
+                                              clip.extents.y2 - clip.extents.y1,
+                                              0)) {
+               DBG(("%s: fallback -- composite spans not supported\n",
+                    __FUNCTION__));
+               return false;
+       }
+
+       extents = *RegionExtents(&clip);
+       dx = dst->pDrawable->x;
+       dy = dst->pDrawable->y;
+
+       DBG(("%s: after clip -- extents (%d, %d), (%d, %d), delta=(%d, %d) src -> (%d, %d)\n",
+            __FUNCTION__,
+            extents.x1, extents.y1,
+            extents.x2, extents.y2,
+            dx, dy,
+            src_x + extents.x1 - dst_x - dx,
+            src_y + extents.y1 - dst_y - dy));
+
+       was_clear = sna_drawable_is_clear(dst->pDrawable);
+
+       memset(&tmp, 0, sizeof(tmp));
+       if (!sna->render.composite_spans(sna, op, src, dst,
+                                        src_x + extents.x1 - dst_x - dx,
+                                        src_y + extents.y1 - dst_y - dy,
+                                        extents.x1,  extents.y1,
+                                        extents.x2 - extents.x1,
+                                        extents.y2 - extents.y1,
+                                        0,
+                                        &tmp)) {
+               DBG(("%s: fallback -- composite spans render op not supported\n",
+                    __FUNCTION__));
+               return false;
+       }
+
+       dx *= FAST_SAMPLES_X;
+       dy *= FAST_SAMPLES_Y;
+       if (tor_init(&tor, &extents, 2*count))
+               goto skip;
+
+       cw = ccw = 0;
+       project_point_onto_grid(&points[0], dx, dy, &p[cw]);
+       project_point_onto_grid(&points[1], dx, dy, &p[2+ccw]);
+       polygon_add_line(tor.polygon, &p[cw], &p[2+ccw]);
+       n = 2;
+       do {
+               cw = !cw;
+               project_point_onto_grid(&points[n], dx, dy, &p[cw]);
+               polygon_add_line(tor.polygon, &p[!cw], &p[cw]);
+               if (++n == count)
+                       break;
+
+               ccw = !ccw;
+               project_point_onto_grid(&points[n], dx, dy, &p[2+ccw]);
+               polygon_add_line(tor.polygon, &p[2+ccw], &p[2+!ccw]);
+               if (++n == count)
+                       break;
+       } while (1);
+       polygon_add_line(tor.polygon, &p[2+ccw], &p[cw]);
+       assert(tor.polygon->num_edges <= 2*count);
+
+       tor_render(sna, &tor, &tmp, &clip,
+                  choose_span(&tmp, dst, maskFormat, op, &clip),
+                  !was_clear && maskFormat && !operator_is_bounded(op));
+
+skip:
+       tor_fini(&tor);
+       tmp.done(sna, &tmp);
+
+       REGION_UNINIT(NULL, &clip);
+       return true;
+}
+
+static void
+tristrip_fallback(CARD8 op,
+                 PicturePtr src,
+                 PicturePtr dst,
+                 PictFormatPtr maskFormat,
+                 INT16 xSrc, INT16 ySrc,
+                 int n, xPointFixed *points)
+{
+       ScreenPtr screen = dst->pDrawable->pScreen;
+
+       if (maskFormat) {
+               PixmapPtr scratch;
+               PicturePtr mask;
+               INT16 dst_x, dst_y;
+               BoxRec bounds;
+               int width, height, depth;
+               pixman_image_t *image;
+               pixman_format_code_t format;
+               int error;
+
+               dst_x = pixman_fixed_to_int(points->x);
+               dst_y = pixman_fixed_to_int(points->y);
+
+               miPointFixedBounds(n, points, &bounds);
+               DBG(("%s: bounds (%d, %d), (%d, %d)\n",
+                    __FUNCTION__, bounds.x1, bounds.y1, bounds.x2, bounds.y2));
+
+               if (bounds.y1 >= bounds.y2 || bounds.x1 >= bounds.x2)
+                       return;
+
+               if (!sna_compute_composite_extents(&bounds,
+                                                  src, NULL, dst,
+                                                  xSrc, ySrc,
+                                                  0, 0,
+                                                  bounds.x1, bounds.y1,
+                                                  bounds.x2 - bounds.x1,
+                                                  bounds.y2 - bounds.y1))
+                       return;
+
+               DBG(("%s: extents (%d, %d), (%d, %d)\n",
+                    __FUNCTION__, bounds.x1, bounds.y1, bounds.x2, bounds.y2));
+
+               width  = bounds.x2 - bounds.x1;
+               height = bounds.y2 - bounds.y1;
+               bounds.x1 -= dst->pDrawable->x;
+               bounds.y1 -= dst->pDrawable->y;
+               depth = maskFormat->depth;
+               format = maskFormat->format | (BitsPerPixel(depth) << 24);
+
+               DBG(("%s: mask (%dx%d) depth=%d, format=%08x\n",
+                    __FUNCTION__, width, height, depth, format));
+               scratch = sna_pixmap_create_upload(screen,
+                                                  width, height, depth,
+                                                  KGEM_BUFFER_WRITE);
+               if (!scratch)
+                       return;
+
+               memset(scratch->devPrivate.ptr, 0, scratch->devKind*height);
+               image = pixman_image_create_bits(format, width, height,
+                                                scratch->devPrivate.ptr,
+                                                scratch->devKind);
+               if (image) {
+                       xTriangle tri;
+                       xPointFixed *p[3] = { &tri.p1, &tri.p2, &tri.p3 };
+                       int i;
+
+                       *p[0] = points[0];
+                       *p[1] = points[1];
+                       *p[2] = points[2];
+                       pixman_add_triangles(image,
+                                            -bounds.x1, -bounds.y1,
+                                            1, (pixman_triangle_t *)&tri);
+                       for (i = 3; i < n; i++) {
+                               *p[i%3] = points[i];
+                               pixman_add_triangles(image,
+                                                    -bounds.x1, -bounds.y1,
+                                                    1, (pixman_triangle_t *)&tri);
+                       }
+                       pixman_image_unref(image);
+               }
+
+               mask = CreatePicture(0, &scratch->drawable,
+                                    PictureMatchFormat(screen, depth, format),
+                                    0, 0, serverClient, &error);
+               if (mask) {
+                       CompositePicture(op, src, mask, dst,
+                                        xSrc + bounds.x1 - dst_x,
+                                        ySrc + bounds.y1 - dst_y,
+                                        0, 0,
+                                        bounds.x1, bounds.y1,
+                                        width, height);
+                       FreePicture(mask, 0);
+               }
+               sna_pixmap_destroy(scratch);
+       } else {
+               xTriangle tri;
+               xPointFixed *p[3] = { &tri.p1, &tri.p2, &tri.p3 };
+               int i;
+
+               if (dst->polyEdge == PolyEdgeSharp)
+                       maskFormat = PictureMatchFormat(screen, 1, PICT_a1);
+               else
+                       maskFormat = PictureMatchFormat(screen, 8, PICT_a8);
+
+               *p[0] = points[0];
+               *p[1] = points[1];
+               *p[2] = points[2];
+               triangles_fallback(op,
+                                  src, dst, maskFormat,
+                                  xSrc, ySrc, 1, &tri);
+               for (i = 3; i < n; i++) {
+                       *p[i%3] = points[i];
+                       /* Should xSrc,ySrc be updated? */
+                       triangles_fallback(op,
+                                          src, dst, maskFormat,
+                                          xSrc, ySrc, 1, &tri);
+               }
+       }
+}
+
+void
+sna_composite_tristrip(CARD8 op,
+                      PicturePtr src,
+                      PicturePtr dst,
+                      PictFormatPtr maskFormat,
+                      INT16 xSrc, INT16 ySrc,
+                      int n, xPointFixed *points)
+{
+       if (tristrip_span_converter(op, src, dst, maskFormat, xSrc, ySrc, n, points))
+               return;
+
+       tristrip_fallback(op, src, dst, maskFormat, xSrc, ySrc, n, points);
+}
+
+static void
+trifan_fallback(CARD8 op,
+               PicturePtr src,
+               PicturePtr dst,
+               PictFormatPtr maskFormat,
+               INT16 xSrc, INT16 ySrc,
+               int n, xPointFixed *points)
+{
+       ScreenPtr screen = dst->pDrawable->pScreen;
+
+       if (maskFormat) {
+               PixmapPtr scratch;
+               PicturePtr mask;
+               INT16 dst_x, dst_y;
+               BoxRec bounds;
+               int width, height, depth;
+               pixman_image_t *image;
+               pixman_format_code_t format;
+               int error;
+
+               dst_x = pixman_fixed_to_int(points->x);
+               dst_y = pixman_fixed_to_int(points->y);
+
+               miPointFixedBounds(n, points, &bounds);
+               DBG(("%s: bounds (%d, %d), (%d, %d)\n",
+                    __FUNCTION__, bounds.x1, bounds.y1, bounds.x2, bounds.y2));
+
+               if (bounds.y1 >= bounds.y2 || bounds.x1 >= bounds.x2)
+                       return;
+
+               if (!sna_compute_composite_extents(&bounds,
+                                                  src, NULL, dst,
+                                                  xSrc, ySrc,
+                                                  0, 0,
+                                                  bounds.x1, bounds.y1,
+                                                  bounds.x2 - bounds.x1,
+                                                  bounds.y2 - bounds.y1))
+                       return;
+
+               DBG(("%s: extents (%d, %d), (%d, %d)\n",
+                    __FUNCTION__, bounds.x1, bounds.y1, bounds.x2, bounds.y2));
+
+               width  = bounds.x2 - bounds.x1;
+               height = bounds.y2 - bounds.y1;
+               bounds.x1 -= dst->pDrawable->x;
+               bounds.y1 -= dst->pDrawable->y;
+               depth = maskFormat->depth;
+               format = maskFormat->format | (BitsPerPixel(depth) << 24);
+
+               DBG(("%s: mask (%dx%d) depth=%d, format=%08x\n",
+                    __FUNCTION__, width, height, depth, format));
+               scratch = sna_pixmap_create_upload(screen,
+                                                  width, height, depth,
+                                                  KGEM_BUFFER_WRITE);
+               if (!scratch)
+                       return;
+
+               memset(scratch->devPrivate.ptr, 0, scratch->devKind*height);
+               image = pixman_image_create_bits(format, width, height,
+                                                scratch->devPrivate.ptr,
+                                                scratch->devKind);
+               if (image) {
+                       xTriangle tri;
+                       xPointFixed *p[3] = { &tri.p1, &tri.p2, &tri.p3 };
+                       int i;
+
+                       *p[0] = points[0];
+                       *p[1] = points[1];
+                       *p[2] = points[2];
+                       pixman_add_triangles(image,
+                                            -bounds.x1, -bounds.y1,
+                                            1, (pixman_triangle_t *)&tri);
+                       for (i = 3; i < n; i++) {
+                               *p[1+ (i%2)] = points[i];
+                               pixman_add_triangles(image,
+                                                    -bounds.x1, -bounds.y1,
+                                                    1, (pixman_triangle_t *)&tri);
+                       }
+                       pixman_image_unref(image);
+               }
+
+               mask = CreatePicture(0, &scratch->drawable,
+                                    PictureMatchFormat(screen, depth, format),
+                                    0, 0, serverClient, &error);
+               if (mask) {
+                       CompositePicture(op, src, mask, dst,
+                                        xSrc + bounds.x1 - dst_x,
+                                        ySrc + bounds.y1 - dst_y,
+                                        0, 0,
+                                        bounds.x1, bounds.y1,
+                                        width, height);
+                       FreePicture(mask, 0);
+               }
+               sna_pixmap_destroy(scratch);
+       } else {
+               xTriangle tri;
+               xPointFixed *p[3] = { &tri.p1, &tri.p2, &tri.p3 };
+               int i;
+
+               if (dst->polyEdge == PolyEdgeSharp)
+                       maskFormat = PictureMatchFormat(screen, 1, PICT_a1);
+               else
+                       maskFormat = PictureMatchFormat(screen, 8, PICT_a8);
+
+               *p[0] = points[0];
+               *p[1] = points[1];
+               *p[2] = points[2];
+               triangles_fallback(op,
+                                  src, dst, maskFormat,
+                                  xSrc, ySrc, 1, &tri);
+               for (i = 3; i < n; i++) {
+                       *p[1 + (i%2)] = points[i];
+                       /* Should xSrc,ySrc be updated? */
+                       triangles_fallback(op,
+                                          src, dst, maskFormat,
+                                          xSrc, ySrc, 1, &tri);
+               }
+       }
+}
+
+void
+sna_composite_trifan(CARD8 op,
+                    PicturePtr src,
+                    PicturePtr dst,
+                    PictFormatPtr maskFormat,
+                    INT16 xSrc, INT16 ySrc,
+                    int n, xPointFixed *points)
+{
+       trifan_fallback(op, src, dst, maskFormat, xSrc, ySrc, n, points);
+}
diff --git a/src/sna/sna_video.c b/src/sna/sna_video.c
new file mode 100644 (file)
index 0000000..7bf20e9
--- /dev/null
@@ -0,0 +1,566 @@
+/***************************************************************************
+
+ Copyright 2000 Intel Corporation.  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, sub license, 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 NON-INFRINGEMENT.
+ IN NO EVENT SHALL INTEL, AND/OR ITS SUPPLIERS 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.
+
+ **************************************************************************/
+
+/*
+ * i830_video.c: i830/i845 Xv driver.
+ *
+ * Copyright © 2002 by Alan Hourihane and David Dawes
+ *
+ * Authors:
+ *     Alan Hourihane <alanh@tungstengraphics.com>
+ *     David Dawes <dawes@xfree86.org>
+ *
+ * Derived from i810 Xv driver:
+ *
+ * Authors of i810 code:
+ *     Jonathan Bian <jonathan.bian@intel.com>
+ *      Offscreen Images:
+ *        Matt Sottek <matthew.j.sottek@intel.com>
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <inttypes.h>
+#include <math.h>
+#include <string.h>
+#include <assert.h>
+#include <errno.h>
+
+#include <sys/mman.h>
+
+#include "sna.h"
+#include "sna_reg.h"
+#include "sna_video.h"
+
+#include "intel_options.h"
+
+#include <xf86xv.h>
+#include <X11/extensions/Xv.h>
+
+#ifdef SNA_XVMC
+#define _SNA_XVMC_SERVER_
+#include "sna_video_hwmc.h"
+#else
+static inline bool sna_video_xvmc_setup(struct sna *sna,
+                                       ScreenPtr ptr,
+                                       XF86VideoAdaptorPtr target)
+{
+       return false;
+}
+#endif
+
+void sna_video_free_buffers(struct sna *sna, struct sna_video *video)
+{
+       unsigned int i;
+
+       for (i = 0; i < ARRAY_SIZE(video->old_buf); i++) {
+               if (video->old_buf[i]) {
+                       kgem_bo_destroy(&sna->kgem, video->old_buf[i]);
+                       video->old_buf[i] = NULL;
+               }
+       }
+
+       if (video->buf) {
+               kgem_bo_destroy(&sna->kgem, video->buf);
+               video->buf = NULL;
+       }
+}
+
+struct kgem_bo *
+sna_video_buffer(struct sna *sna,
+                struct sna_video *video,
+                struct sna_video_frame *frame)
+{
+       /* Free the current buffer if we're going to have to reallocate */
+       if (video->buf && __kgem_bo_size(video->buf) < frame->size)
+               sna_video_free_buffers(sna, video);
+
+       if (video->buf == NULL)
+               video->buf = kgem_create_linear(&sna->kgem, frame->size,
+                                               CREATE_GTT_MAP);
+
+       return video->buf;
+}
+
+void sna_video_buffer_fini(struct sna *sna,
+                          struct sna_video *video)
+{
+       struct kgem_bo *bo;
+
+       bo = video->old_buf[1];
+       video->old_buf[1] = video->old_buf[0];
+       video->old_buf[0] = video->buf;
+       video->buf = bo;
+}
+
+bool
+sna_video_clip_helper(ScrnInfoPtr scrn,
+                     struct sna_video *video,
+                     struct sna_video_frame *frame,
+                     xf86CrtcPtr * crtc_ret,
+                     BoxPtr dst,
+                     short src_x, short src_y,
+                     short drw_x, short drw_y,
+                     short src_w, short src_h,
+                     short drw_w, short drw_h,
+                     RegionPtr reg)
+{
+       bool ret;
+       RegionRec crtc_region_local;
+       RegionPtr crtc_region = reg;
+       INT32 x1, x2, y1, y2;
+       xf86CrtcPtr crtc;
+
+       x1 = src_x;
+       x2 = src_x + src_w;
+       y1 = src_y;
+       y2 = src_y + src_h;
+
+       dst->x1 = drw_x;
+       dst->x2 = drw_x + drw_w;
+       dst->y1 = drw_y;
+       dst->y2 = drw_y + drw_h;
+
+       /*
+        * For overlay video, compute the relevant CRTC and
+        * clip video to that
+        */
+       crtc = sna_covering_crtc(scrn, dst, video->desired_crtc);
+
+       /* For textured video, we don't actually want to clip at all. */
+       if (crtc && !video->textured) {
+               crtc_region_local.extents = crtc->bounds;
+               crtc_region_local.data = NULL;
+               crtc_region = &crtc_region_local;
+               RegionIntersect(crtc_region, crtc_region, reg);
+       }
+       *crtc_ret = crtc;
+
+       ret = xf86XVClipVideoHelper(dst, &x1, &x2, &y1, &y2,
+                                   crtc_region, frame->width, frame->height);
+       if (crtc_region != reg)
+               RegionUninit(crtc_region);
+
+       frame->top = y1 >> 16;
+       frame->left = (x1 >> 16) & ~1;
+       frame->npixels = ALIGN(((x2 + 0xffff) >> 16), 2) - frame->left;
+       if (is_planar_fourcc(frame->id)) {
+               frame->top &= ~1;
+               frame->nlines = ALIGN(((y2 + 0xffff) >> 16), 2) - frame->top;
+       } else
+               frame->nlines = ((y2 + 0xffff) >> 16) - frame->top;
+
+       return ret;
+}
+
+void
+sna_video_frame_init(struct sna *sna,
+                    struct sna_video *video,
+                    int id, short width, short height,
+                    struct sna_video_frame *frame)
+{
+       int align;
+
+       frame->bo = NULL;
+       frame->id = id;
+       frame->width = width;
+       frame->height = height;
+
+       /* Only needs to be DWORD-aligned for textured on i915, but overlay has
+        * stricter requirements.
+        */
+       if (video->textured) {
+               align = 4;
+       } else {
+               if (sna->kgem.gen >= 40)
+                       /* Actually the alignment is 64 bytes, too. But the
+                        * stride must be at least 512 bytes. Take the easy fix
+                        * and align on 512 bytes unconditionally. */
+                       align = 512;
+               else if (sna->kgem.gen < 21)
+                       /* Harsh, errata on these chipsets limit the stride
+                        * to be a multiple of 256 bytes.
+                        */
+                       align = 256;
+               else
+                       align = 64;
+       }
+
+#if SNA_XVMC
+       /* for i915 xvmc, hw requires 1kb aligned surfaces */
+       if (id == FOURCC_XVMC && sna->kgem.gen < 40)
+               align = 1024;
+#endif
+
+
+       /* Determine the desired destination pitch (representing the chroma's pitch,
+        * in the planar case.
+        */
+       if (is_planar_fourcc(id)) {
+               if (video->rotation & (RR_Rotate_90 | RR_Rotate_270)) {
+                       frame->pitch[0] = ALIGN((height / 2), align);
+                       frame->pitch[1] = ALIGN(height, align);
+                       frame->size = 3U * frame->pitch[0] * width;
+               } else {
+                       frame->pitch[0] = ALIGN((width / 2), align);
+                       frame->pitch[1] = ALIGN(width, align);
+                       frame->size = 3U * frame->pitch[0] * height;
+               }
+       } else {
+               if (video->rotation & (RR_Rotate_90 | RR_Rotate_270)) {
+                       frame->pitch[0] = ALIGN((height << 1), align);
+                       frame->size = (int)frame->pitch[0] * width;
+               } else {
+                       frame->pitch[0] = ALIGN((width << 1), align);
+                       frame->size = (int)frame->pitch[0] * height;
+               }
+               frame->pitch[1] = 0;
+       }
+
+       if (video->rotation & (RR_Rotate_90 | RR_Rotate_270)) {
+               frame->UBufOffset = (int)frame->pitch[1] * width;
+               frame->VBufOffset =
+                       frame->UBufOffset + (int)frame->pitch[0] * width / 2;
+       } else {
+               frame->UBufOffset = (int)frame->pitch[1] * height;
+               frame->VBufOffset =
+                       frame->UBufOffset + (int)frame->pitch[0] * height / 2;
+       }
+}
+
+static void sna_memcpy_plane(uint8_t *dst, const uint8_t *src,
+                            int height, int width,
+                            int dstPitch, int srcPitch,
+                            Rotation rotation)
+{
+       const uint8_t *s;
+       int i, j = 0;
+
+       switch (rotation) {
+       case RR_Rotate_0:
+               /* optimise for the case of no clipping */
+               if (srcPitch == dstPitch && srcPitch == width)
+                       memcpy(dst, src, srcPitch * height);
+               else while (height--) {
+                       memcpy(dst, src, width);
+                       src += srcPitch;
+                       dst += dstPitch;
+               }
+               break;
+       case RR_Rotate_90:
+               for (i = 0; i < height; i++) {
+                       s = src;
+                       for (j = 0; j < width; j++) {
+                               dst[(i) + ((width - j - 1) * dstPitch)] = *s++;
+                       }
+                       src += srcPitch;
+               }
+               break;
+       case RR_Rotate_180:
+               for (i = 0; i < height; i++) {
+                       s = src;
+                       for (j = 0; j < width; j++) {
+                               dst[(width - j - 1) +
+                                   ((height - i - 1) * dstPitch)] = *s++;
+                       }
+                       src += srcPitch;
+               }
+               break;
+       case RR_Rotate_270:
+               for (i = 0; i < height; i++) {
+                       s = src;
+                       for (j = 0; j < width; j++) {
+                               dst[(height - i - 1) + (j * dstPitch)] = *s++;
+                       }
+                       src += srcPitch;
+               }
+               break;
+       }
+}
+
+static void
+sna_copy_planar_data(struct sna_video *video,
+                    const struct sna_video_frame *frame,
+                    const uint8_t *src, uint8_t *dst)
+{
+       uint8_t *d;
+       int w = frame->npixels;
+       int h = frame->nlines;
+       int pitch;
+
+       pitch = ALIGN(frame->width, 4);
+       sna_memcpy_plane(dst, src + frame->top * pitch + frame->left,
+                        h, w, frame->pitch[1], pitch, video->rotation);
+
+       src += frame->height * pitch; /* move over Luma plane */
+
+       /* align to beginning of chroma planes */
+       pitch = ALIGN((frame->width >> 1), 0x4);
+       src += (frame->top >> 1) * pitch + (frame->left >> 1);
+       w >>= 1;
+       h >>= 1;
+
+       if (frame->id == FOURCC_I420)
+               d = dst + frame->UBufOffset;
+       else
+               d = dst + frame->VBufOffset;
+
+       sna_memcpy_plane(d, src, h, w, frame->pitch[0], pitch, video->rotation);
+       src += (frame->height >> 1) * pitch; /* move over Chroma plane */
+
+       if (frame->id == FOURCC_I420)
+               d = dst + frame->VBufOffset;
+       else
+               d = dst + frame->UBufOffset;
+
+       sna_memcpy_plane(d, src, h, w, frame->pitch[0], pitch, video->rotation);
+}
+
+static void
+sna_copy_packed_data(struct sna_video *video,
+                    const struct sna_video_frame *frame,
+                    const uint8_t *buf,
+                    uint8_t *dst)
+{
+       int pitch = frame->width << 1;
+       const uint8_t *src, *s;
+       int w = frame->npixels;
+       int h = frame->nlines;
+       int i, j;
+
+       src = buf + (frame->top * pitch) + (frame->left << 1);
+
+       switch (video->rotation) {
+       case RR_Rotate_0:
+               w <<= 1;
+               for (i = 0; i < h; i++) {
+                       memcpy(dst, src, w);
+                       src += pitch;
+                       dst += frame->pitch[0];
+               }
+               break;
+       case RR_Rotate_90:
+               h <<= 1;
+               for (i = 0; i < h; i += 2) {
+                       s = src;
+                       for (j = 0; j < w; j++) {
+                               /* Copy Y */
+                               dst[(i + 0) + ((w - j - 1) * frame->pitch[0])] = *s;
+                               s += 2;
+                       }
+                       src += pitch;
+               }
+               h >>= 1;
+               src = buf + (frame->top * pitch) + (frame->left << 1);
+               for (i = 0; i < h; i += 2) {
+                       for (j = 0; j < w; j += 2) {
+                               /* Copy U */
+                               dst[((i * 2) + 1) + ((w - j - 1) * frame->pitch[0])] = src[(j * 2) + 1 + (i * pitch)];
+                               dst[((i * 2) + 1) + ((w - j - 2) * frame->pitch[0])] = src[(j * 2) + 1 + ((i + 1) * pitch)];
+                               /* Copy V */ dst[((i * 2) + 3) + ((w - j - 1) * frame->pitch[0])] = src[(j * 2) + 3 + (i * pitch)];
+                               dst[((i * 2) + 3) + ((w - j - 2) * frame->pitch[0])] = src[(j * 2) + 3 + ((i + 1) * pitch)];
+                       }
+               }
+               break;
+       case RR_Rotate_180:
+               w <<= 1;
+               for (i = 0; i < h; i++) {
+                       s = src;
+                       for (j = 0; j < w; j += 4) {
+                               dst[(w - j - 4) + ((h - i - 1) * frame->pitch[0])] = *s++;
+                               dst[(w - j - 3) + ((h - i - 1) * frame->pitch[0])] = *s++;
+                               dst[(w - j - 2) + ((h - i - 1) * frame->pitch[0])] = *s++;
+                               dst[(w - j - 1) + ((h - i - 1) * frame->pitch[0])] = *s++;
+                       }
+                       src += pitch;
+               }
+               break;
+       case RR_Rotate_270:
+               h <<= 1;
+               for (i = 0; i < h; i += 2) {
+                       s = src;
+                       for (j = 0; j < w; j++) {
+                               /* Copy Y */
+                               dst[(h - i - 2) + (j * frame->pitch[0])] = *s;
+                               s += 2;
+                       }
+                       src += pitch;
+               }
+               h >>= 1;
+               src = buf + (frame->top * pitch) + (frame->left << 1);
+               for (i = 0; i < h; i += 2) {
+                       for (j = 0; j < w; j += 2) {
+                               /* Copy U */
+                               dst[(((h - i) * 2) - 3) + (j * frame->pitch[0])] = src[(j * 2) + 1 + (i * pitch)];
+                               dst[(((h - i) * 2) - 3) + ((j + 1) * frame->pitch[0])] = src[(j * 2) + 1 + ((i + 1) * pitch)];
+                               /* Copy V */
+                               dst[(((h - i) * 2) - 1) + (j * frame->pitch[0])] = src[(j * 2) + 3 + (i * pitch)];
+                               dst[(((h - i) * 2) - 1) + ((j + 1) * frame->pitch[0])] = src[(j * 2) + 3 + ((i + 1) * pitch)];
+                       }
+               }
+               break;
+       }
+}
+
+bool
+sna_video_copy_data(struct sna *sna,
+                   struct sna_video *video,
+                   struct sna_video_frame *frame,
+                   const uint8_t *buf)
+{
+       uint8_t *dst;
+
+       DBG(("%s: handle=%d, size=%dx%d, rotation=%d\n",
+            __FUNCTION__, frame->bo ? frame->bo->handle : 0,
+            frame->width, frame->height, video->rotation));
+       DBG(("%s: top=%d, left=%d\n", __FUNCTION__, frame->top, frame->left));
+
+       /* In the common case, we can simply the upload in a single pwrite */
+       if (video->rotation == RR_Rotate_0) {
+               if (is_planar_fourcc(frame->id)) {
+                       uint16_t pitch[2] = {
+                               ALIGN((frame->width >> 1), 0x4),
+                               ALIGN(frame->width, 0x4),
+                       };
+                       if (pitch[0] == frame->pitch[0] &&
+                           pitch[1] == frame->pitch[1] &&
+                           frame->top == 0 && frame->left == 0) {
+                               uint32_t len =
+                                       (uint32_t)pitch[1]*frame->height +
+                                       (uint32_t)pitch[0]*frame->height;
+                               if (frame->bo) {
+                                       kgem_bo_write(&sna->kgem, frame->bo,
+                                                     buf, len);
+                               } else {
+                                       frame->bo = kgem_create_buffer(&sna->kgem, frame->size,
+                                                                      KGEM_BUFFER_WRITE | KGEM_BUFFER_WRITE_INPLACE,
+                                                                      (void **)&dst);
+                                       if (frame->bo == NULL)
+                                               return false;
+
+                                       memcpy(dst, buf, len);
+                               }
+                               if (frame->id != FOURCC_I420) {
+                                       uint32_t tmp;
+                                       tmp = frame->VBufOffset;
+                                       frame->VBufOffset = frame->UBufOffset;
+                                       frame->UBufOffset = tmp;
+                               }
+                               return true;
+                       }
+               } else {
+                       if (frame->width*2 == frame->pitch[0]) {
+                               if (frame->bo) {
+                                       kgem_bo_write(&sna->kgem, frame->bo,
+                                                     buf + (2U*frame->top * frame->width) + (frame->left << 1),
+                                                     2U*frame->nlines*frame->width);
+                               } else {
+                                       frame->bo = kgem_create_buffer(&sna->kgem, frame->size,
+                                                                      KGEM_BUFFER_WRITE | KGEM_BUFFER_WRITE_INPLACE,
+                                                                      (void **)&dst);
+                                       if (frame->bo == NULL)
+                                               return false;
+
+                                       memcpy(dst,
+                                              buf + (frame->top * frame->width*2) + (frame->left << 1),
+                                              2U*frame->nlines*frame->width);
+                               }
+                               return true;
+                       }
+               }
+       }
+
+       /* copy data, must use GTT so that we keep the overlay uncached */
+       if (frame->bo) {
+               dst = kgem_bo_map__gtt(&sna->kgem, frame->bo);
+               if (dst == NULL)
+                       return false;
+       } else {
+               frame->bo = kgem_create_buffer(&sna->kgem, frame->size,
+                                              KGEM_BUFFER_WRITE | KGEM_BUFFER_WRITE_INPLACE,
+                                              (void **)&dst);
+               if (frame->bo == NULL)
+                       return false;
+       }
+
+       if (is_planar_fourcc(frame->id))
+               sna_copy_planar_data(video, frame, buf, dst);
+       else
+               sna_copy_packed_data(video, frame, buf, dst);
+
+       return true;
+}
+
+void sna_video_init(struct sna *sna, ScreenPtr screen)
+{
+       XF86VideoAdaptorPtr *adaptors, *newAdaptors;
+       XF86VideoAdaptorPtr textured, overlay;
+       int num_adaptors;
+       int prefer_overlay =
+           xf86ReturnOptValBool(sna->Options, OPTION_PREFER_OVERLAY, false);
+
+       if (!xf86LoaderCheckSymbol("xf86XVListGenericAdaptors"))
+               return;
+
+       adaptors = NULL;
+       num_adaptors = xf86XVListGenericAdaptors(sna->scrn, &adaptors);
+       newAdaptors = realloc(adaptors,
+                             (num_adaptors + 2) * sizeof(XF86VideoAdaptorPtr));
+       if (newAdaptors == NULL) {
+               free(adaptors);
+               return;
+       }
+       adaptors = newAdaptors;
+
+       /* Set up textured video if we can do it at this depth and we are on
+        * supported hardware.
+        */
+       textured = sna_video_textured_setup(sna, screen);
+       overlay = sna_video_sprite_setup(sna, screen);
+       if (overlay == NULL)
+               overlay = sna_video_overlay_setup(sna, screen);
+
+       if (overlay && prefer_overlay)
+               adaptors[num_adaptors++] = overlay;
+
+       if (textured)
+               adaptors[num_adaptors++] = textured;
+
+       if (overlay && !prefer_overlay)
+               adaptors[num_adaptors++] = overlay;
+
+       if (num_adaptors)
+               xf86XVScreenInit(screen, adaptors, num_adaptors);
+       else
+               xf86DrvMsg(sna->scrn->scrnIndex, X_WARNING,
+                          "Disabling Xv because no adaptors could be initialized.\n");
+       if (textured)
+               sna_video_xvmc_setup(sna, screen, textured);
+
+       free(adaptors);
+}
diff --git a/src/sna/sna_video.h b/src/sna/sna_video.h
new file mode 100644 (file)
index 0000000..3ce72c0
--- /dev/null
@@ -0,0 +1,137 @@
+/***************************************************************************
+
+Copyright 2000 Intel Corporation.  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, sub license, 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 NON-INFRINGEMENT.
+IN NO EVENT SHALL INTEL, AND/OR ITS SUPPLIERS 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 SNA_VIDEO_H
+#define SNA_VIDEO_H
+
+#include <xf86_OSproc.h>
+#include <xf86xv.h>
+#include <fourcc.h>
+
+#if defined(XvMCExtension) && defined(ENABLE_XVMC)
+#define SNA_XVMC 1
+#endif
+
+struct sna_video {
+       int brightness;
+       int contrast;
+       int saturation;
+       xf86CrtcPtr desired_crtc;
+
+       RegionRec clip;
+
+       uint32_t gamma0;
+       uint32_t gamma1;
+       uint32_t gamma2;
+       uint32_t gamma3;
+       uint32_t gamma4;
+       uint32_t gamma5;
+
+       int color_key;
+       int color_key_changed;
+
+       /** YUV data buffers */
+       struct kgem_bo *old_buf[2];
+       struct kgem_bo *buf;
+
+       bool textured;
+       Rotation rotation;
+       int plane;
+
+       int SyncToVblank;       /* -1: auto, 0: off, 1: on */
+};
+
+struct sna_video_frame {
+       struct kgem_bo *bo;
+       uint32_t id;
+       uint32_t size;
+       uint32_t UBufOffset;
+       uint32_t VBufOffset;
+
+       uint16_t width, height;
+       uint16_t pitch[2];
+
+       /* extents */
+       uint16_t top, left;
+       uint16_t npixels, nlines;
+};
+
+void sna_video_init(struct sna *sna, ScreenPtr screen);
+XF86VideoAdaptorPtr sna_video_overlay_setup(struct sna *sna, ScreenPtr screen);
+XF86VideoAdaptorPtr sna_video_sprite_setup(struct sna *sna, ScreenPtr screen);
+XF86VideoAdaptorPtr sna_video_textured_setup(struct sna *sna, ScreenPtr screen);
+
+#define FOURCC_XVMC     (('C' << 24) + ('M' << 16) + ('V' << 8) + 'X')
+
+static inline int is_planar_fourcc(int id)
+{
+       switch (id) {
+       case FOURCC_YV12:
+       case FOURCC_I420:
+       case FOURCC_XVMC:
+               return 1;
+       case FOURCC_UYVY:
+       case FOURCC_YUY2:
+       default:
+               return 0;
+       }
+}
+
+bool
+sna_video_clip_helper(ScrnInfoPtr scrn,
+                     struct sna_video *adaptor_priv,
+                     struct sna_video_frame *frame,
+                     xf86CrtcPtr * crtc_ret,
+                     BoxPtr dst,
+                     short src_x, short src_y,
+                     short drw_x, short drw_y,
+                     short src_w, short src_h,
+                     short drw_w, short drw_h,
+                     RegionPtr reg);
+
+void
+sna_video_frame_init(struct sna *sna,
+                    struct sna_video *video,
+                    int id, short width, short height,
+                    struct sna_video_frame *frame);
+
+struct kgem_bo *
+sna_video_buffer(struct sna *sna,
+                struct sna_video *video,
+                struct sna_video_frame *frame);
+
+bool
+sna_video_copy_data(struct sna *sna,
+                   struct sna_video *video,
+                   struct sna_video_frame *frame,
+                   const uint8_t *buf);
+
+void sna_video_buffer_fini(struct sna *sna,
+                          struct sna_video *video);
+
+void sna_video_free_buffers(struct sna *sna, struct sna_video *video);
+
+#endif /* SNA_VIDEO_H */
diff --git a/src/sna/sna_video_hwmc.c b/src/sna/sna_video_hwmc.c
new file mode 100644 (file)
index 0000000..b0e8d25
--- /dev/null
@@ -0,0 +1,253 @@
+/*
+ * Copyright © 2007 Intel 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.
+ *
+ * Authors:
+ *    Zhenyu Wang <zhenyu.z.wang@sna.com>
+ *
+ */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#define _SNA_XVMC_SERVER_
+#include "sna.h"
+#include "sna_video_hwmc.h"
+
+#include <X11/extensions/Xv.h>
+#include <X11/extensions/XvMC.h>
+#include <fourcc.h>
+
+static int create_subpicture(ScrnInfoPtr scrn, XvMCSubpicturePtr subpicture,
+                            int *num_priv, CARD32 ** priv)
+{
+       return Success;
+}
+
+static void destroy_subpicture(ScrnInfoPtr scrn, XvMCSubpicturePtr subpicture)
+{
+}
+
+static int create_surface(ScrnInfoPtr scrn, XvMCSurfacePtr surface,
+                         int *num_priv, CARD32 ** priv)
+{
+       return Success;
+}
+
+static void destroy_surface(ScrnInfoPtr scrn, XvMCSurfacePtr surface)
+{
+}
+
+static int create_context(ScrnInfoPtr scrn, XvMCContextPtr pContext,
+                                   int *num_priv, CARD32 **priv)
+{
+       struct sna *sna = to_sna(scrn);
+       struct sna_xvmc_hw_context *contextRec;
+
+       *priv = calloc(1, sizeof(struct sna_xvmc_hw_context));
+       contextRec = (struct sna_xvmc_hw_context *) *priv;
+       if (!contextRec) {
+               *num_priv = 0;
+               return BadAlloc;
+       }
+
+       *num_priv = sizeof(struct sna_xvmc_hw_context) >> 2;
+
+       if (sna->kgem.gen >= 40) {
+               if (sna->kgem.gen >= 45)
+                       contextRec->type = XVMC_I965_MPEG2_VLD;
+               else
+                       contextRec->type = XVMC_I965_MPEG2_MC;
+               contextRec->i965.is_g4x = sna->kgem.gen == 45;
+               contextRec->i965.is_965_q = IS_965_Q(sna);
+               contextRec->i965.is_igdng = sna->kgem.gen == 50;
+       } else {
+               contextRec->type = XVMC_I915_MPEG2_MC;
+               contextRec->i915.use_phys_addr = 0;
+       }
+
+       return Success;
+}
+
+static void destroy_context(ScrnInfoPtr scrn, XvMCContextPtr context)
+{
+}
+
+/* i915 hwmc support */
+static XF86MCSurfaceInfoRec i915_YV12_mpg2_surface = {
+       FOURCC_YV12,
+       XVMC_CHROMA_FORMAT_420,
+       0,
+       720,
+       576,
+       720,
+       576,
+       XVMC_MPEG_2,
+       /* XVMC_OVERLAID_SURFACE | XVMC_SUBPICTURE_INDEPENDENT_SCALING, */
+       0,
+       /* &yv12_subpicture_list */
+       NULL,
+};
+
+static XF86MCSurfaceInfoRec i915_YV12_mpg1_surface = {
+       FOURCC_YV12,
+       XVMC_CHROMA_FORMAT_420,
+       0,
+       720,
+       576,
+       720,
+       576,
+       XVMC_MPEG_1,
+       /* XVMC_OVERLAID_SURFACE | XVMC_SUBPICTURE_INDEPENDENT_SCALING, */
+       0,
+       NULL,
+};
+
+static XF86MCSurfaceInfoPtr surface_info_i915[2] = {
+       (XF86MCSurfaceInfoPtr) & i915_YV12_mpg2_surface,
+       (XF86MCSurfaceInfoPtr) & i915_YV12_mpg1_surface
+};
+
+/* i965 and later hwmc support */
+#ifndef XVMC_VLD
+#define XVMC_VLD  0x00020000
+#endif
+
+static XF86MCSurfaceInfoRec yv12_mpeg2_vld_surface = {
+       FOURCC_YV12,
+       XVMC_CHROMA_FORMAT_420,
+       0,
+       1936,
+       1096,
+       1920,
+       1080,
+       XVMC_MPEG_2 | XVMC_VLD,
+       XVMC_INTRA_UNSIGNED,
+       NULL
+};
+
+static XF86MCSurfaceInfoRec yv12_mpeg2_i965_surface = {
+       FOURCC_YV12,
+       XVMC_CHROMA_FORMAT_420,
+       0,
+       1936,
+       1096,
+       1920,
+       1080,
+       XVMC_MPEG_2 | XVMC_MOCOMP,
+       /* XVMC_OVERLAID_SURFACE | XVMC_SUBPICTURE_INDEPENDENT_SCALING, */
+       XVMC_INTRA_UNSIGNED,
+       /* &yv12_subpicture_list */
+       NULL
+};
+
+static XF86MCSurfaceInfoRec yv12_mpeg1_i965_surface = {
+       FOURCC_YV12,
+       XVMC_CHROMA_FORMAT_420,
+       0,
+       1920,
+       1080,
+       1920,
+       1080,
+       XVMC_MPEG_1 | XVMC_MOCOMP,
+       /*XVMC_OVERLAID_SURFACE | XVMC_SUBPICTURE_INDEPENDENT_SCALING |
+          XVMC_INTRA_UNSIGNED, */
+       XVMC_INTRA_UNSIGNED,
+
+       /*&yv12_subpicture_list */
+       NULL
+};
+
+static XF86MCSurfaceInfoPtr surface_info_i965[] = {
+       &yv12_mpeg2_i965_surface,
+       &yv12_mpeg1_i965_surface
+};
+
+static XF86MCSurfaceInfoPtr surface_info_vld[] = {
+       &yv12_mpeg2_vld_surface,
+       &yv12_mpeg2_i965_surface,
+};
+
+/* check chip type and load xvmc driver */
+Bool sna_video_xvmc_setup(struct sna *sna,
+                         ScreenPtr screen,
+                         XF86VideoAdaptorPtr target)
+{
+       XF86MCAdaptorRec *pAdapt;
+       const char *name;
+       char buf[64];
+
+       /* Needs KMS support. */
+       if (sna->kgem.gen < 31)
+               return FALSE;
+
+       /* Not implemented */
+       if (sna->kgem.gen >= 60)
+               return FALSE;
+
+       pAdapt = calloc(1, sizeof(XF86MCAdaptorRec));
+       if (!pAdapt)
+               return FALSE;
+
+       pAdapt->name = target->name;
+       pAdapt->num_subpictures = 0;
+       pAdapt->subpictures = NULL;
+       pAdapt->CreateContext = create_context;
+       pAdapt->DestroyContext = destroy_context;
+       pAdapt->CreateSurface = create_surface;
+       pAdapt->DestroySurface = destroy_surface;
+       pAdapt->CreateSubpicture =  create_subpicture;
+       pAdapt->DestroySubpicture = destroy_subpicture;
+
+       if (sna->kgem.gen >= 45) {
+               name = "xvmc_vld",
+               pAdapt->num_surfaces = ARRAY_SIZE(surface_info_vld);
+               pAdapt->surfaces = surface_info_vld;
+       } else if (sna->kgem.gen >= 40) {
+               name = "i965_xvmc",
+               pAdapt->num_surfaces = ARRAY_SIZE(surface_info_i965);
+               pAdapt->surfaces = surface_info_i965;
+       } else {
+               name = "i915_xvmc",
+               pAdapt->num_surfaces = ARRAY_SIZE(surface_info_i915);
+               pAdapt->surfaces = surface_info_i915;
+       }
+
+       if (xf86XvMCScreenInit(screen, 1, &pAdapt)) {
+               xf86DrvMsg(sna->scrn->scrnIndex, X_INFO,
+                          "[XvMC] %s driver initialized.\n",
+                          name);
+       } else {
+               xf86DrvMsg(sna->scrn->scrnIndex, X_INFO,
+                          "[XvMC] Failed to initialize XvMC.\n");
+               return FALSE;
+       }
+
+       sprintf(buf, "pci:%04x:%02x:%02x.%d",
+               sna->PciInfo->domain,
+               sna->PciInfo->bus, sna->PciInfo->dev, sna->PciInfo->func);
+
+       xf86XvMCRegisterDRInfo(screen, SNA_XVMC_LIBNAME,
+                              buf,
+                              SNA_XVMC_MAJOR, SNA_XVMC_MINOR,
+                              SNA_XVMC_PATCHLEVEL);
+       return TRUE;
+}
diff --git a/src/sna/sna_video_hwmc.h b/src/sna/sna_video_hwmc.h
new file mode 100644 (file)
index 0000000..2494d44
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * Copyright © 2007 Intel 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.
+ *
+ * Authors:
+ *    Zhenyu Wang <zhenyu.z.wang@sna.com>
+ *
+ */
+#ifndef SNA_VIDEO_HWMC_H
+#define SNA_VIDEO_HWMC_H
+
+#define SNA_XVMC_LIBNAME       "IntelXvMC"
+#define SNA_XVMC_MAJOR 0
+#define SNA_XVMC_MINOR 1
+#define SNA_XVMC_PATCHLEVEL    0
+
+/*
+ * Commands that client submits through XvPutImage:
+ */
+
+#define SNA_XVMC_COMMAND_DISPLAY      0x00
+#define SNA_XVMC_COMMAND_UNDISPLAY    0x01
+
+/* hw xvmc support type */
+#define XVMC_I915_MPEG2_MC     0x01
+#define XVMC_I965_MPEG2_MC     0x02
+#define XVMC_I945_MPEG2_VLD    0x04
+#define XVMC_I965_MPEG2_VLD    0x08
+
+struct sna_xvmc_hw_context {
+       unsigned int type;
+       union {
+               struct {
+                       unsigned int use_phys_addr : 1;
+               } i915;
+               struct {
+                       unsigned int is_g4x:1;
+                       unsigned int is_965_q:1;
+                       unsigned int is_igdng:1;
+               } i965;
+       };
+};
+
+/* Intel private XvMC command to DDX driver */
+struct sna_xvmc_command {
+       uint32_t handle;
+};
+
+#ifdef _SNA_XVMC_SERVER_
+#include <xf86xvmc.h>
+Bool sna_video_xvmc_setup(struct sna *sna,
+                         ScreenPtr screen,
+                         XF86VideoAdaptorPtr target);
+#endif
+
+#endif
diff --git a/src/sna/sna_video_overlay.c b/src/sna/sna_video_overlay.c
new file mode 100644 (file)
index 0000000..babdfc6
--- /dev/null
@@ -0,0 +1,725 @@
+/***************************************************************************
+
+ Copyright 2000-2011 Intel Corporation.  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, sub license, 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 NON-INFRINGEMENT.
+ IN NO EVENT SHALL INTEL, AND/OR ITS SUPPLIERS 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_CONFIG_H
+#include "config.h"
+#endif
+
+#include "sna.h"
+#include "sna_video.h"
+
+#include <xf86drm.h>
+#include <xf86xv.h>
+#include <X11/extensions/Xv.h>
+#include <fourcc.h>
+#include <i915_drm.h>
+
+#include "intel_options.h"
+
+#define MAKE_ATOM(a) MakeAtom(a, sizeof(a) - 1, TRUE)
+
+#define HAS_GAMMA(sna) ((sna)->kgem.gen >= 30)
+
+static Atom xvBrightness, xvContrast, xvSaturation, xvColorKey, xvPipe;
+static Atom xvGamma0, xvGamma1, xvGamma2, xvGamma3, xvGamma4, xvGamma5;
+static Atom xvSyncToVblank;
+
+/* Limits for the overlay/textured video source sizes.  The documented hardware
+ * limits are 2048x2048 or better for overlay and both of our textured video
+ * implementations.  Additionally, on the 830 and 845, larger sizes resulted in
+ * the card hanging, so we keep the limits lower there.
+ */
+#define IMAGE_MAX_WIDTH                2048
+#define IMAGE_MAX_HEIGHT       2048
+#define IMAGE_MAX_WIDTH_LEGACY 1024
+#define IMAGE_MAX_HEIGHT_LEGACY        1088
+
+/* client libraries expect an encoding */
+static const XF86VideoEncodingRec DummyEncoding[1] = {
+       {
+        0,
+        "XV_IMAGE",
+        IMAGE_MAX_WIDTH, IMAGE_MAX_HEIGHT,
+        {1, 1}
+        }
+};
+
+#define NUM_FORMATS 3
+static const XF86VideoFormatRec Formats[NUM_FORMATS] = {
+       {15, TrueColor}, {16, TrueColor}, {24, TrueColor}
+};
+
+#define NUM_ATTRIBUTES 5
+static const XF86AttributeRec Attributes[NUM_ATTRIBUTES] = {
+       {XvSettable | XvGettable, 0, (1 << 24) - 1, "XV_COLORKEY"},
+       {XvSettable | XvGettable, -128, 127, "XV_BRIGHTNESS"},
+       {XvSettable | XvGettable, 0, 255, "XV_CONTRAST"},
+       {XvSettable | XvGettable, 0, 1023, "XV_SATURATION"},
+       {XvSettable | XvGettable, -1, 1, "XV_PIPE"}
+};
+
+#define GAMMA_ATTRIBUTES 6
+static const XF86AttributeRec GammaAttributes[GAMMA_ATTRIBUTES] = {
+       {XvSettable | XvGettable, 0, 0xffffff, "XV_GAMMA0"},
+       {XvSettable | XvGettable, 0, 0xffffff, "XV_GAMMA1"},
+       {XvSettable | XvGettable, 0, 0xffffff, "XV_GAMMA2"},
+       {XvSettable | XvGettable, 0, 0xffffff, "XV_GAMMA3"},
+       {XvSettable | XvGettable, 0, 0xffffff, "XV_GAMMA4"},
+       {XvSettable | XvGettable, 0, 0xffffff, "XV_GAMMA5"}
+};
+
+#define NUM_IMAGES 4
+static const XF86ImageRec Images[NUM_IMAGES] = {
+       XVIMAGE_YUY2,
+       XVIMAGE_YV12,
+       XVIMAGE_I420,
+       XVIMAGE_UYVY,
+};
+
+/* kernel modesetting overlay functions */
+static bool sna_has_overlay(struct sna *sna)
+{
+       struct drm_i915_getparam gp;
+       int has_overlay = 0;
+       int ret;
+
+       VG_CLEAR(gp);
+       gp.param = I915_PARAM_HAS_OVERLAY;
+       gp.value = &has_overlay;
+       ret = drmIoctl(sna->kgem.fd, DRM_IOCTL_I915_GETPARAM, &gp);
+       return ret == 0 && has_overlay;
+}
+
+static bool sna_video_overlay_update_attrs(struct sna *sna,
+                                          struct sna_video *video)
+{
+       struct drm_intel_overlay_attrs attrs;
+
+       DBG(("%s()\n", __FUNCTION__));
+
+       attrs.flags = I915_OVERLAY_UPDATE_ATTRS;
+       attrs.brightness = video->brightness;
+       attrs.contrast = video->contrast;
+       attrs.saturation = video->saturation;
+       attrs.color_key = video->color_key;
+       attrs.gamma0 = video->gamma0;
+       attrs.gamma1 = video->gamma1;
+       attrs.gamma2 = video->gamma2;
+       attrs.gamma3 = video->gamma3;
+       attrs.gamma4 = video->gamma4;
+       attrs.gamma5 = video->gamma5;
+
+       return drmIoctl(sna->kgem.fd, DRM_IOCTL_I915_OVERLAY_ATTRS, &attrs) == 0;
+}
+
+static void sna_video_overlay_off(struct sna *sna)
+{
+       struct drm_intel_overlay_put_image request;
+
+       DBG(("%s()\n", __FUNCTION__));
+
+       request.flags = 0;
+
+       /* Not much we can do if the hardware dies before we turn it off! */
+       (void)drmIoctl(sna->kgem.fd,
+                      DRM_IOCTL_I915_OVERLAY_PUT_IMAGE,
+                      &request);
+}
+
+static void sna_video_overlay_stop(ScrnInfoPtr scrn,
+                                  pointer data,
+                                  Bool shutdown)
+{
+       struct sna *sna = to_sna(scrn);
+       struct sna_video *video = data;
+
+       DBG(("%s()\n", __FUNCTION__));
+
+       REGION_EMPTY(scrn->pScreen, &video->clip);
+
+       if (!shutdown)
+               return;
+
+       sna_video_overlay_off(sna);
+       sna_video_free_buffers(sna, video);
+}
+
+static int
+sna_video_overlay_set_port_attribute(ScrnInfoPtr scrn,
+                                    Atom attribute, INT32 value, pointer data)
+{
+       struct sna *sna = to_sna(scrn);
+       struct sna_video *video = data;
+
+       if (attribute == xvBrightness) {
+               if ((value < -128) || (value > 127))
+                       return BadValue;
+               DBG(("%s: BRIGHTNESS %d -> %d\n", __FUNCTION__,
+                    video->contrast, (int)value));
+               video->brightness = value;
+       } else if (attribute == xvContrast) {
+               if ((value < 0) || (value > 255))
+                       return BadValue;
+               DBG(("%s: CONTRAST %d -> %d\n", __FUNCTION__,
+                    video->contrast, (int)value));
+               video->contrast = value;
+       } else if (attribute == xvSaturation) {
+               if ((value < 0) || (value > 1023))
+                       return BadValue;
+               DBG(("%s: SATURATION %d -> %d\n", __FUNCTION__,
+                    video->saturation, (int)value));
+               video->saturation = value;
+       } else if (attribute == xvPipe) {
+               xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+               if ((value < -1) || (value >= xf86_config->num_crtc))
+                       return BadValue;
+               if (value < 0)
+                       video->desired_crtc = NULL;
+               else
+                       video->desired_crtc = xf86_config->crtc[value];
+       } else if (attribute == xvGamma0 && HAS_GAMMA(sna)) {
+               video->gamma0 = value;
+       } else if (attribute == xvGamma1 && HAS_GAMMA(sna)) {
+               video->gamma1 = value;
+       } else if (attribute == xvGamma2 && HAS_GAMMA(sna)) {
+               video->gamma2 = value;
+       } else if (attribute == xvGamma3 && HAS_GAMMA(sna)) {
+               video->gamma3 = value;
+       } else if (attribute == xvGamma4 && HAS_GAMMA(sna)) {
+               video->gamma4 = value;
+       } else if (attribute == xvGamma5 && HAS_GAMMA(sna)) {
+               video->gamma5 = value;
+       } else if (attribute == xvColorKey) {
+               video->color_key = value;
+               DBG(("COLORKEY\n"));
+       } else
+               return BadMatch;
+
+       if ((attribute == xvGamma0 ||
+            attribute == xvGamma1 ||
+            attribute == xvGamma2 ||
+            attribute == xvGamma3 ||
+            attribute == xvGamma4 ||
+            attribute == xvGamma5) && HAS_GAMMA(sna)) {
+               DBG(("%s: GAMMA\n", __FUNCTION__));
+       }
+
+       if (!sna_video_overlay_update_attrs(sna, data))
+               return BadValue;
+
+       if (attribute == xvColorKey)
+               REGION_EMPTY(scrn->pScreen, &video->clip);
+
+       return Success;
+}
+
+static int
+sna_video_overlay_get_port_attribute(ScrnInfoPtr scrn,
+                                    Atom attribute, INT32 * value, pointer data)
+{
+       struct sna *sna = to_sna(scrn);
+       struct sna_video *video = (struct sna_video *) data;
+
+       if (attribute == xvBrightness) {
+               *value = video->brightness;
+       } else if (attribute == xvContrast) {
+               *value = video->contrast;
+       } else if (attribute == xvSaturation) {
+               *value = video->saturation;
+       } else if (attribute == xvPipe) {
+               int c;
+               xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+               for (c = 0; c < xf86_config->num_crtc; c++)
+                       if (xf86_config->crtc[c] == video->desired_crtc)
+                               break;
+               if (c == xf86_config->num_crtc)
+                       c = -1;
+               *value = c;
+       } else if (attribute == xvGamma0 && HAS_GAMMA(sna)) {
+               *value = video->gamma0;
+       } else if (attribute == xvGamma1 && HAS_GAMMA(sna)) {
+               *value = video->gamma1;
+       } else if (attribute == xvGamma2 && HAS_GAMMA(sna)) {
+               *value = video->gamma2;
+       } else if (attribute == xvGamma3 && HAS_GAMMA(sna)) {
+               *value = video->gamma3;
+       } else if (attribute == xvGamma4 && HAS_GAMMA(sna)) {
+               *value = video->gamma4;
+       } else if (attribute == xvGamma5 && HAS_GAMMA(sna)) {
+               *value = video->gamma5;
+       } else if (attribute == xvColorKey) {
+               *value = video->color_key;
+       } else if (attribute == xvSyncToVblank) {
+               *value = video->SyncToVblank;
+       } else
+               return BadMatch;
+
+       return Success;
+}
+
+static void
+sna_video_overlay_query_best_size(ScrnInfoPtr scrn,
+                                 Bool motion,
+                                 short vid_w, short vid_h,
+                                 short drw_w, short drw_h,
+                                 unsigned int *p_w, unsigned int *p_h, pointer data)
+{
+       if (vid_w > (drw_w << 1))
+               drw_w = vid_w >> 1;
+       if (vid_h > (drw_h << 1))
+               drw_h = vid_h >> 1;
+
+       *p_w = drw_w;
+       *p_h = drw_h;
+}
+
+static void
+update_dst_box_to_crtc_coords(struct sna *sna, xf86CrtcPtr crtc, BoxPtr dstBox)
+{
+       ScrnInfoPtr scrn = sna->scrn;
+       int tmp;
+
+       /* for overlay, we should take it from crtc's screen
+        * coordinate to current crtc's display mode.
+        * yeah, a bit confusing.
+        */
+       switch (crtc->rotation & 0xf) {
+       case RR_Rotate_0:
+               dstBox->x1 -= crtc->x;
+               dstBox->x2 -= crtc->x;
+               dstBox->y1 -= crtc->y;
+               dstBox->y2 -= crtc->y;
+               break;
+       case RR_Rotate_90:
+               tmp = dstBox->x1;
+               dstBox->x1 = dstBox->y1 - crtc->x;
+               dstBox->y1 = scrn->virtualX - tmp - crtc->y;
+               tmp = dstBox->x2;
+               dstBox->x2 = dstBox->y2 - crtc->x;
+               dstBox->y2 = scrn->virtualX - tmp - crtc->y;
+               tmp = dstBox->y1;
+               dstBox->y1 = dstBox->y2;
+               dstBox->y2 = tmp;
+               break;
+       case RR_Rotate_180:
+               tmp = dstBox->x1;
+               dstBox->x1 = scrn->virtualX - dstBox->x2 - crtc->x;
+               dstBox->x2 = scrn->virtualX - tmp - crtc->x;
+               tmp = dstBox->y1;
+               dstBox->y1 = scrn->virtualY - dstBox->y2 - crtc->y;
+               dstBox->y2 = scrn->virtualY - tmp - crtc->y;
+               break;
+       case RR_Rotate_270:
+               tmp = dstBox->x1;
+               dstBox->x1 = scrn->virtualY - dstBox->y1 - crtc->x;
+               dstBox->y1 = tmp - crtc->y;
+               tmp = dstBox->x2;
+               dstBox->x2 = scrn->virtualY - dstBox->y2 - crtc->x;
+               dstBox->y2 = tmp - crtc->y;
+               tmp = dstBox->x1;
+               dstBox->x1 = dstBox->x2;
+               dstBox->x2 = tmp;
+               break;
+       }
+
+       return;
+}
+
+static bool
+sna_video_overlay_show(struct sna *sna,
+                      struct sna_video *video,
+                      struct sna_video_frame *frame,
+                      xf86CrtcPtr crtc,
+                      BoxPtr dstBox,
+                      short src_w, short src_h,
+                      short drw_w, short drw_h)
+{
+       struct drm_intel_overlay_put_image request;
+       bool planar = is_planar_fourcc(frame->id);
+       float scale;
+
+       DBG(("%s: src=(%dx%d), dst=(%dx%d)\n", __FUNCTION__,
+            src_w, src_h, drw_w, drw_h));
+
+       update_dst_box_to_crtc_coords(sna, crtc, dstBox);
+       if (crtc->rotation & (RR_Rotate_90 | RR_Rotate_270)) {
+               int tmp;
+
+               tmp = frame->width;
+               frame->width = frame->height;
+               frame->height = tmp;
+
+               tmp = drw_w;
+               drw_w = drw_h;
+               drw_h = tmp;
+
+               tmp = src_w;
+               src_w = src_h;
+               src_h = tmp;
+       }
+
+       memset(&request, 0, sizeof(request));
+       request.flags = I915_OVERLAY_ENABLE;
+
+       request.bo_handle = frame->bo->handle;
+       if (planar) {
+               request.stride_Y = frame->pitch[1];
+               request.stride_UV = frame->pitch[0];
+       } else {
+               request.stride_Y = frame->pitch[0];
+               request.stride_UV = 0;
+       }
+       request.offset_Y = 0;
+       request.offset_U = frame->UBufOffset;
+       request.offset_V = frame->VBufOffset;
+       DBG(("%s: handle=%d, stride_Y=%d, stride_UV=%d, off_Y: %i, off_U: %i, off_V: %i\n",
+            __FUNCTION__,
+            request.bo_handle, request.stride_Y, request.stride_UV,
+            request.offset_Y, request.offset_U, request.offset_V));
+
+       request.crtc_id = sna_crtc_id(crtc);
+       request.dst_x = dstBox->x1;
+       request.dst_y = dstBox->y1;
+       request.dst_width = dstBox->x2 - dstBox->x1;
+       request.dst_height = dstBox->y2 - dstBox->y1;
+
+       DBG(("%s: crtc=%d, dst=(%d, %d)x(%d, %d)\n",
+            __FUNCTION__, request.crtc_id,
+            request.dst_x, request.dst_y,
+            request.dst_width, request.dst_height));
+
+       request.src_width = frame->width;
+       request.src_height = frame->height;
+       /* adjust src dimensions */
+       if (request.dst_height > 1) {
+               scale = ((float)request.dst_height - 1) / ((float)drw_h - 1);
+               request.src_scan_height = src_h * scale;
+       } else
+               request.src_scan_height = 1;
+
+       if (request.dst_width > 1) {
+               scale = ((float)request.dst_width - 1) / ((float)drw_w - 1);
+               request.src_scan_width = src_w * scale;
+       } else
+               request.src_scan_width = 1;
+
+       DBG(("%s: src=(%d, %d) scan=(%d, %d)\n",
+            __FUNCTION__,
+            request.src_width, request.src_height,
+            request.src_scan_width, request.src_scan_height));
+
+       if (planar) {
+               request.flags |= I915_OVERLAY_YUV_PLANAR | I915_OVERLAY_YUV420;
+       } else {
+               request.flags |= I915_OVERLAY_YUV_PACKED | I915_OVERLAY_YUV422;
+               if (frame->id == FOURCC_UYVY)
+                       request.flags |= I915_OVERLAY_Y_SWAP;
+       }
+
+       DBG(("%s: flags=%x\n", __FUNCTION__, request.flags));
+
+       return drmIoctl(sna->kgem.fd, DRM_IOCTL_I915_OVERLAY_PUT_IMAGE, &request) == 0;
+}
+
+static int
+sna_video_overlay_put_image(ScrnInfoPtr scrn,
+                           short src_x, short src_y,
+                           short drw_x, short drw_y,
+                           short src_w, short src_h,
+                           short drw_w, short drw_h,
+                           int id, unsigned char *buf,
+                           short width, short height,
+                           Bool sync, RegionPtr clip, pointer data,
+                           DrawablePtr drawable)
+{
+       struct sna *sna = to_sna(scrn);
+       struct sna_video *video = data;
+       struct sna_video_frame frame;
+       BoxRec dstBox;
+       xf86CrtcPtr crtc;
+
+       DBG(("%s: src: (%d,%d)(%d,%d), dst: (%d,%d)(%d,%d), width %d, height %d\n",
+            __FUNCTION__,
+            src_x, src_y, src_w, src_h, drw_x,
+            drw_y, drw_w, drw_h, width, height));
+
+       /* If dst width and height are less than 1/8th the src size, the
+        * src/dst scale factor becomes larger than 8 and doesn't fit in
+        * the scale register. */
+       if (src_w >= (drw_w * 8))
+               drw_w = src_w / 7;
+
+       if (src_h >= (drw_h * 8))
+               drw_h = src_h / 7;
+
+       sna_video_frame_init(sna, video, id, width, height, &frame);
+
+       if (!sna_video_clip_helper(scrn,
+                                  video,
+                                  &frame,
+                                  &crtc,
+                                  &dstBox,
+                                  src_x, src_y, drw_x, drw_y,
+                                  src_w, src_h, drw_w, drw_h,
+                                  clip))
+               return Success;
+
+       if (!crtc) {
+               /*
+                * If the video isn't visible on any CRTC, turn it off
+                */
+               sna_video_overlay_off(sna);
+               return Success;
+       }
+
+       /* overlay can't handle rotation natively, store it for the copy func */
+       video->rotation = crtc->rotation;
+
+       frame.bo = sna_video_buffer(sna, video, &frame);
+       if (frame.bo == NULL) {
+               DBG(("%s: failed to allocate video bo\n", __FUNCTION__));
+               return BadAlloc;
+       }
+
+       if (!sna_video_copy_data(sna, video, &frame, buf)) {
+               DBG(("%s: failed to copy video data\n", __FUNCTION__));
+               return BadAlloc;
+       }
+
+       if (!sna_video_overlay_show
+           (sna, video, &frame, crtc, &dstBox, src_w, src_h, drw_w, drw_h)) {
+               DBG(("%s: failed to show video frame\n", __FUNCTION__));
+               return BadAlloc;
+       }
+
+       sna_video_buffer_fini(sna, video);
+
+       /* update cliplist */
+       if (!REGION_EQUAL(scrn->pScreen, &video->clip, clip)) {
+               REGION_COPY(scrn->pScreen, &video->clip, clip);
+               xf86XVFillKeyHelperDrawable(drawable, video->color_key, clip);
+       }
+
+       return Success;
+}
+
+static int
+sna_video_overlay_query_video_attributes(ScrnInfoPtr scrn,
+                                        int id,
+                                        unsigned short *w, unsigned short *h,
+                                        int *pitches, int *offsets)
+{
+       struct sna *sna = to_sna(scrn);
+       int size, tmp;
+
+       DBG(("%s: w is %d, h is %d\n", __FUNCTION__, *w, *h));
+
+       if (sna->kgem.gen < 21) {
+               if (*w > IMAGE_MAX_WIDTH_LEGACY)
+                       *w = IMAGE_MAX_WIDTH_LEGACY;
+               if (*h > IMAGE_MAX_HEIGHT_LEGACY)
+                       *h = IMAGE_MAX_HEIGHT_LEGACY;
+       } else {
+               if (*w > IMAGE_MAX_WIDTH)
+                       *w = IMAGE_MAX_WIDTH;
+               if (*h > IMAGE_MAX_HEIGHT)
+                       *h = IMAGE_MAX_HEIGHT;
+       }
+
+       *w = (*w + 1) & ~1;
+       if (offsets)
+               offsets[0] = 0;
+
+       switch (id) {
+               /* IA44 is for XvMC only */
+       case FOURCC_IA44:
+       case FOURCC_AI44:
+               if (pitches)
+                       pitches[0] = *w;
+               size = *w * *h;
+               break;
+       case FOURCC_YV12:
+       case FOURCC_I420:
+               *h = (*h + 1) & ~1;
+               size = (*w + 3) & ~3;
+               if (pitches)
+                       pitches[0] = size;
+               size *= *h;
+               if (offsets)
+                       offsets[1] = size;
+               tmp = ((*w >> 1) + 3) & ~3;
+               if (pitches)
+                       pitches[1] = pitches[2] = tmp;
+               tmp *= (*h >> 1);
+               size += tmp;
+               if (offsets)
+                       offsets[2] = size;
+               size += tmp;
+#if 0
+               if (pitches)
+                       ErrorF("pitch 0 is %d, pitch 1 is %d, pitch 2 is %d\n",
+                              pitches[0], pitches[1], pitches[2]);
+               if (offsets)
+                       ErrorF("offset 1 is %d, offset 2 is %d\n", offsets[1],
+                              offsets[2]);
+               if (offsets)
+                       ErrorF("size is %d\n", size);
+#endif
+               break;
+       case FOURCC_UYVY:
+       case FOURCC_YUY2:
+       default:
+               size = *w << 1;
+               if (pitches)
+                       pitches[0] = size;
+               size *= *h;
+               break;
+       }
+
+       return size;
+}
+
+static int sna_video_overlay_color_key(struct sna *sna)
+{
+       ScrnInfoPtr scrn = sna->scrn;
+       int color_key;
+
+       if (xf86GetOptValInteger(sna->Options, OPTION_VIDEO_KEY,
+                                &color_key)) {
+       } else if (xf86GetOptValInteger(sna->Options, OPTION_COLOR_KEY,
+                                       &color_key)) {
+       } else {
+               color_key =
+                   (1 << scrn->offset.red) |
+                   (1 << scrn->offset.green) |
+                   (((scrn->mask.blue >> scrn->offset.blue) - 1) << scrn->offset.blue);
+       }
+
+       return color_key & ((1 << scrn->depth) - 1);
+}
+
+XF86VideoAdaptorPtr sna_video_overlay_setup(struct sna *sna,
+                                           ScreenPtr screen)
+{
+       XF86VideoAdaptorPtr adaptor;
+       struct sna_video *video;
+
+       if (!sna_has_overlay(sna)) {
+               xf86DrvMsg(sna->scrn->scrnIndex, X_INFO,
+                          "Overlay video not supported on this hardware\n");
+               return NULL;
+       }
+
+       DBG(("%s()\n", __FUNCTION__));
+
+       if (!(adaptor = calloc(1,
+                            sizeof(XF86VideoAdaptorRec) +
+                            sizeof(struct sna_video) +
+                            sizeof(DevUnion))))
+               return NULL;
+
+       adaptor->type = XvWindowMask | XvInputMask | XvImageMask;
+       adaptor->flags = VIDEO_OVERLAID_IMAGES /*| VIDEO_CLIP_TO_VIEWPORT */ ;
+       adaptor->name = "Intel(R) Video Overlay";
+       adaptor->nEncodings = 1;
+       adaptor->pEncodings = xnfalloc(sizeof(DummyEncoding));
+       memcpy(adaptor->pEncodings, DummyEncoding, sizeof(DummyEncoding));
+       if (sna->kgem.gen < 21) {
+               adaptor->pEncodings->width = IMAGE_MAX_WIDTH_LEGACY;
+               adaptor->pEncodings->height = IMAGE_MAX_HEIGHT_LEGACY;
+       }
+       adaptor->nFormats = NUM_FORMATS;
+       adaptor->pFormats = (XF86VideoFormatPtr)Formats;
+       adaptor->nPorts = 1;
+       adaptor->pPortPrivates = (DevUnion *)&adaptor[1];
+
+       video = (struct sna_video *)&adaptor->pPortPrivates[1];
+
+       adaptor->pPortPrivates[0].ptr = video;
+       adaptor->nAttributes = NUM_ATTRIBUTES;
+       if (HAS_GAMMA(sna))
+               adaptor->nAttributes += GAMMA_ATTRIBUTES;
+
+        adaptor->pAttributes =
+           xnfalloc(sizeof(XF86AttributeRec) * adaptor->nAttributes);
+       /* Now copy the attributes */
+       memcpy(adaptor->pAttributes, Attributes, sizeof(XF86AttributeRec) * NUM_ATTRIBUTES);
+       if (HAS_GAMMA(sna))
+               memcpy(adaptor->pAttributes + NUM_ATTRIBUTES, GammaAttributes,
+                      sizeof(XF86AttributeRec) * GAMMA_ATTRIBUTES);
+
+       adaptor->nImages = NUM_IMAGES;
+       adaptor->pImages = (XF86ImagePtr)Images;
+       adaptor->PutVideo = NULL;
+       adaptor->PutStill = NULL;
+       adaptor->GetVideo = NULL;
+       adaptor->GetStill = NULL;
+       adaptor->StopVideo = sna_video_overlay_stop;
+       adaptor->SetPortAttribute = sna_video_overlay_set_port_attribute;
+       adaptor->GetPortAttribute = sna_video_overlay_get_port_attribute;
+       adaptor->QueryBestSize = sna_video_overlay_query_best_size;
+       adaptor->PutImage = sna_video_overlay_put_image;
+       adaptor->QueryImageAttributes = sna_video_overlay_query_video_attributes;
+
+       video->textured = false;
+       video->color_key = sna_video_overlay_color_key(sna);
+       video->brightness = -19;        /* (255/219) * -16 */
+       video->contrast = 75;   /* 255/219 * 64 */
+       video->saturation = 146;        /* 128/112 * 128 */
+       video->desired_crtc = NULL;
+       video->gamma5 = 0xc0c0c0;
+       video->gamma4 = 0x808080;
+       video->gamma3 = 0x404040;
+       video->gamma2 = 0x202020;
+       video->gamma1 = 0x101010;
+       video->gamma0 = 0x080808;
+
+       video->rotation = RR_Rotate_0;
+
+       /* gotta uninit this someplace */
+       REGION_NULL(screen, &video->clip);
+
+       xvColorKey = MAKE_ATOM("XV_COLORKEY");
+       xvBrightness = MAKE_ATOM("XV_BRIGHTNESS");
+       xvContrast = MAKE_ATOM("XV_CONTRAST");
+       xvSaturation = MAKE_ATOM("XV_SATURATION");
+
+       /* Allow the pipe to be switched from pipe A to B when in clone mode */
+       xvPipe = MAKE_ATOM("XV_PIPE");
+
+       if (HAS_GAMMA(sna)) {
+               xvGamma0 = MAKE_ATOM("XV_GAMMA0");
+               xvGamma1 = MAKE_ATOM("XV_GAMMA1");
+               xvGamma2 = MAKE_ATOM("XV_GAMMA2");
+               xvGamma3 = MAKE_ATOM("XV_GAMMA3");
+               xvGamma4 = MAKE_ATOM("XV_GAMMA4");
+               xvGamma5 = MAKE_ATOM("XV_GAMMA5");
+       }
+
+       sna_video_overlay_update_attrs(sna, video);
+
+       return adaptor;
+}
diff --git a/src/sna/sna_video_sprite.c b/src/sna/sna_video_sprite.c
new file mode 100644 (file)
index 0000000..a912590
--- /dev/null
@@ -0,0 +1,435 @@
+/***************************************************************************
+
+ Copyright 2000-2011 Intel Corporation.  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, sub license, 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 NON-INFRINGEMENT.
+ IN NO EVENT SHALL INTEL, AND/OR ITS SUPPLIERS 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_CONFIG_H
+#include "config.h"
+#endif
+
+#include "sna.h"
+#include "sna_video.h"
+
+#include "intel_options.h"
+
+#include <xf86drm.h>
+#include <xf86xv.h>
+#include <X11/extensions/Xv.h>
+#include <fourcc.h>
+#include <drm_fourcc.h>
+#include <i915_drm.h>
+
+#define IMAGE_MAX_WIDTH                2048
+#define IMAGE_MAX_HEIGHT       2048
+
+#define MAKE_ATOM(a) MakeAtom(a, sizeof(a) - 1, true)
+
+static Atom xvColorKey;
+
+static XF86VideoFormatRec xv_formats[] = {
+       {15, TrueColor}, {16, TrueColor}, {24, TrueColor}
+};
+static XF86ImageRec xv_images[] = { XVIMAGE_YUY2, XVIMAGE_UYVY, };
+static const XF86VideoEncodingRec xv_dummy_encoding[] = {
+       { 0, "XV_IMAGE", IMAGE_MAX_WIDTH, IMAGE_MAX_HEIGHT, {1, 1} }
+};
+static XF86AttributeRec attribs[] = {
+       {XvSettable | XvGettable, 0, 0xffffff, "XV_COLORKEY"},
+};
+
+static void sna_video_sprite_off(struct sna *sna, struct sna_video *video)
+{
+       if (video->plane == 0)
+               return;
+
+       if (drmModeSetPlane(sna->kgem.fd,
+                           video->plane, 0, 0, 0,
+                           0, 0, 0, 0,
+                           0, 0, 0, 0))
+               xf86DrvMsg(sna->scrn->scrnIndex, X_ERROR,
+                          "failed to disable plane\n");
+
+       video->plane = 0;
+}
+
+static void sna_video_sprite_stop(ScrnInfoPtr scrn, pointer data, Bool shutdown)
+{
+       return sna_video_sprite_off(to_sna(scrn), data);
+}
+
+static int sna_video_sprite_set_attr(ScrnInfoPtr scrn,
+                                    Atom attribute, INT32 value,
+                                    pointer data)
+{
+       struct sna_video *video = data;
+
+       if (attribute == xvColorKey) {
+               video->color_key_changed = true;
+               video->color_key = value;
+               DBG(("COLORKEY = %d\n", value));
+       } else
+               return BadMatch;
+
+       return Success;
+}
+
+static int sna_video_sprite_get_attr(ScrnInfoPtr scrn,
+                                    Atom attribute, INT32 *value,
+                                    pointer data)
+{
+       struct sna_video *video = data;
+
+       if (attribute == xvColorKey)
+               *value = video->color_key;
+       else
+               return BadMatch;
+
+       return Success;
+}
+
+static void sna_video_sprite_best_size(ScrnInfoPtr scrn, Bool motion,
+                                      short vid_w, short vid_h,
+                                      short drw_w, short drw_h,
+                                      unsigned int *p_w, unsigned int *p_h,
+                                      pointer data)
+{
+       *p_w = vid_w;
+       *p_h = vid_h;
+}
+
+static void
+update_dst_box_to_crtc_coords(struct sna *sna, xf86CrtcPtr crtc, BoxPtr dstBox)
+{
+       ScrnInfoPtr scrn = sna->scrn;
+       int tmp;
+
+       switch (crtc->rotation & 0xf) {
+       case RR_Rotate_0:
+               dstBox->x1 -= crtc->x;
+               dstBox->x2 -= crtc->x;
+               dstBox->y1 -= crtc->y;
+               dstBox->y2 -= crtc->y;
+               break;
+
+       case RR_Rotate_90:
+               tmp = dstBox->x1;
+               dstBox->x1 = dstBox->y1 - crtc->x;
+               dstBox->y1 = scrn->virtualX - tmp - crtc->y;
+               tmp = dstBox->x2;
+               dstBox->x2 = dstBox->y2 - crtc->x;
+               dstBox->y2 = scrn->virtualX - tmp - crtc->y;
+               tmp = dstBox->y1;
+               dstBox->y1 = dstBox->y2;
+               dstBox->y2 = tmp;
+               break;
+
+       case RR_Rotate_180:
+               tmp = dstBox->x1;
+               dstBox->x1 = scrn->virtualX - dstBox->x2 - crtc->x;
+               dstBox->x2 = scrn->virtualX - tmp - crtc->x;
+               tmp = dstBox->y1;
+               dstBox->y1 = scrn->virtualY - dstBox->y2 - crtc->y;
+               dstBox->y2 = scrn->virtualY - tmp - crtc->y;
+               break;
+
+       case RR_Rotate_270:
+               tmp = dstBox->x1;
+               dstBox->x1 = scrn->virtualY - dstBox->y1 - crtc->x;
+               dstBox->y1 = tmp - crtc->y;
+               tmp = dstBox->x2;
+               dstBox->x2 = scrn->virtualY - dstBox->y2 - crtc->x;
+               dstBox->y2 = tmp - crtc->y;
+               tmp = dstBox->x1;
+               dstBox->x1 = dstBox->x2;
+               dstBox->x2 = tmp;
+               break;
+       }
+}
+
+static bool
+sna_video_sprite_show(struct sna *sna,
+                     struct sna_video *video,
+                     struct sna_video_frame *frame,
+                     xf86CrtcPtr crtc,
+                     BoxPtr dstBox)
+{
+       int plane = sna_crtc_to_plane(crtc);
+
+       update_dst_box_to_crtc_coords(sna, crtc, dstBox);
+       if (crtc->rotation & (RR_Rotate_90 | RR_Rotate_270)) {
+               int tmp = frame->width;
+               frame->width = frame->height;
+               frame->height = tmp;
+       }
+
+#if defined(DRM_I915_SET_SPRITE_DESTKEY)
+       if (video->color_key_changed || video->plane != plane) {
+               struct drm_intel_set_sprite_destkey set;
+
+               DBG(("%s: updating color key: %x\n",
+                    __FUNCTION__, video->color_key));
+
+               set.plane_id = plane;
+               set.value = video->color_key;
+
+               if (drmIoctl(sna->kgem.fd,
+                            DRM_IOCTL_I915_SET_SPRITE_DESTKEY,
+                            &set))
+                       xf86DrvMsg(sna->scrn->scrnIndex, X_ERROR,
+                                  "failed to update color key\n");
+
+               video->color_key_changed = false;
+       }
+#endif
+
+       if (frame->bo->delta == 0) {
+               uint32_t offsets[4], pitches[4], handles[4];
+               uint32_t pixel_format;
+
+               switch (frame->id) {
+               case FOURCC_UYVY:
+                       pixel_format = DRM_FORMAT_UYVY;
+                       break;
+               case FOURCC_YUY2:
+               default:
+                       pixel_format = DRM_FORMAT_YUYV;
+                       break;
+               }
+
+               handles[0] = frame->bo->handle;
+               pitches[0] = frame->pitch[0];
+               offsets[0] = 0;
+
+               DBG(("%s: creating new fb for handle=%d\n",
+                    __FUNCTION__, frame->bo->handle));
+
+               if (drmModeAddFB2(sna->kgem.fd,
+                                 frame->width, frame->height, pixel_format,
+                                 handles, pitches, offsets,
+                                 &frame->bo->delta, 0)) {
+                       xf86DrvMsg(sna->scrn->scrnIndex,
+                                  X_ERROR, "failed to add fb\n");
+                       return false;
+               }
+
+               frame->bo->scanout = true;
+       }
+
+       DBG(("%s: updating plane=%d, handle=%d [fb %d], dst=(%d,%d)x(%d,%d)\n",
+            __FUNCTION__, plane, frame->bo->handle, frame->bo->delta,
+            dstBox->x1, dstBox->y1,
+            dstBox->x2 - dstBox->x1, dstBox->y2 - dstBox->y1));
+       assert(frame->bo->scanout);
+       assert(frame->bo->delta);
+
+       if (drmModeSetPlane(sna->kgem.fd,
+                           plane, sna_crtc_id(crtc), frame->bo->delta, 0,
+                           dstBox->x1, dstBox->y1,
+                           dstBox->x2 - dstBox->x1, dstBox->y2 - dstBox->y1,
+                           0, 0, frame->width << 16, frame->height << 16))
+               return false;
+
+       video->plane = plane;
+       return true;
+}
+
+static int sna_video_sprite_put_image(ScrnInfoPtr scrn,
+                                     short src_x, short src_y,
+                                     short drw_x, short drw_y,
+                                     short src_w, short src_h,
+                                     short drw_w, short drw_h,
+                                     int id, unsigned char *buf,
+                                     short width, short height,
+                                     Bool sync, RegionPtr clip, pointer data,
+                                     DrawablePtr drawable)
+{
+       struct sna *sna = to_sna(scrn);
+       struct sna_video *video = data;
+       struct sna_video_frame frame;
+       xf86CrtcPtr crtc;
+       BoxRec dst_box;
+
+       sna_video_frame_init(sna, video, id, width, height, &frame);
+
+       if (!sna_video_clip_helper(scrn, video, &frame, &crtc, &dst_box,
+                                  src_x, src_y, drw_x, drw_y,
+                                  src_w, src_h, drw_w, drw_h,
+                                  clip))
+               return Success;
+
+       if (!crtc || !sna_crtc_to_plane(crtc)) {
+               /* If the video isn't visible on any CRTC, turn it off */
+               sna_video_sprite_off(sna, video);
+               return Success;
+       }
+
+       /* sprites can't handle rotation natively, store it for the copy func */
+       video->rotation = crtc->rotation;
+
+       frame.bo = sna_video_buffer(sna, video, &frame);
+       if (frame.bo == NULL) {
+               DBG(("%s: failed to allocate video bo\n", __FUNCTION__));
+               return BadAlloc;
+       }
+
+       if (!sna_video_copy_data(sna, video, &frame, buf)) {
+               DBG(("%s: failed to copy video data\n", __FUNCTION__));
+               return BadAlloc;
+       }
+
+       if (!sna_video_sprite_show(sna, video, &frame, crtc, &dst_box)) {
+               DBG(("%s: failed to show video frame\n", __FUNCTION__));
+               return BadAlloc;
+       }
+
+       sna_video_buffer_fini(sna, video);
+
+       if (!REGION_EQUAL(scrn->pScreen, &video->clip, clip)) {
+               REGION_COPY(scrn->pScreen, &video->clip, clip);
+               xf86XVFillKeyHelperDrawable(drawable, video->color_key, clip);
+       }
+
+       return Success;
+}
+
+static int sna_video_sprite_query_attrs(ScrnInfoPtr scrn, int id,
+                                       unsigned short *w, unsigned short *h,
+                                       int *pitches, int *offsets)
+{
+       int size;
+
+       if (*w > IMAGE_MAX_WIDTH)
+               *w = IMAGE_MAX_WIDTH;
+       if (*h > IMAGE_MAX_HEIGHT)
+               *h = IMAGE_MAX_HEIGHT;
+
+       *w = (*w + 1) & ~1;
+       if (offsets)
+               offsets[0] = 0;
+
+       switch (id) {
+       case FOURCC_YUY2:
+       default:
+               size = *w << 1;
+               if (pitches)
+                       pitches[0] = size;
+               size *= *h;
+               break;
+       }
+
+       return size;
+}
+
+static int sna_video_sprite_color_key(struct sna *sna)
+{
+       ScrnInfoPtr scrn = sna->scrn;
+       int color_key;
+
+       if (xf86GetOptValInteger(sna->Options, OPTION_VIDEO_KEY,
+                                &color_key)) {
+       } else if (xf86GetOptValInteger(sna->Options, OPTION_COLOR_KEY,
+                                       &color_key)) {
+       } else {
+               color_key =
+                   (1 << scrn->offset.red) |
+                   (1 << scrn->offset.green) |
+                   (((scrn->mask.blue >> scrn->offset.blue) - 1) << scrn->offset.blue);
+       }
+
+       return color_key & ((1 << scrn->depth) - 1);
+}
+
+XF86VideoAdaptorPtr sna_video_sprite_setup(struct sna *sna,
+                                          ScreenPtr screen)
+{
+       XF86VideoAdaptorPtr adaptor;
+       struct drm_mode_get_plane_res r;
+       struct sna_video *video;
+
+       memset(&r, 0, sizeof(struct drm_mode_get_plane_res));
+       if (drmIoctl(sna->kgem.fd, DRM_IOCTL_MODE_GETPLANERESOURCES, &r))
+               return NULL;
+       if (r.count_planes == 0)
+               return NULL;
+
+       adaptor = calloc(1,
+                        sizeof(XF86VideoAdaptorRec) +
+                        sizeof(struct sna_video) +
+                        sizeof(DevUnion));
+       if (!adaptor)
+               return NULL;
+
+       adaptor->type = XvWindowMask | XvInputMask | XvImageMask;
+       adaptor->flags = VIDEO_OVERLAID_IMAGES /*| VIDEO_CLIP_TO_VIEWPORT */ ;
+       adaptor->name = "Intel(R) Video Sprite";
+       adaptor->nEncodings = ARRAY_SIZE(xv_dummy_encoding);
+       adaptor->pEncodings = xnfalloc(sizeof(xv_dummy_encoding));
+       memcpy(adaptor->pEncodings, xv_dummy_encoding, sizeof(xv_dummy_encoding));
+       adaptor->nFormats = ARRAY_SIZE(xv_formats);
+       adaptor->pFormats = xv_formats;
+       adaptor->nPorts = 1;
+       adaptor->pPortPrivates = (DevUnion *)&adaptor[1];
+
+       video = (struct sna_video *)&adaptor->pPortPrivates[1];
+       adaptor->pPortPrivates[0].ptr = video;
+
+       adaptor->nAttributes = ARRAY_SIZE(attribs);
+       adaptor->pAttributes = attribs;
+
+       adaptor->nImages = ARRAY_SIZE(xv_images);
+       adaptor->pImages = xv_images;
+
+       adaptor->PutVideo = NULL;
+       adaptor->PutStill = NULL;
+       adaptor->GetVideo = NULL;
+       adaptor->GetStill = NULL;
+       adaptor->StopVideo = sna_video_sprite_stop;
+       adaptor->SetPortAttribute = sna_video_sprite_set_attr;
+       adaptor->GetPortAttribute = sna_video_sprite_get_attr;
+       adaptor->QueryBestSize = sna_video_sprite_best_size;
+       adaptor->PutImage = sna_video_sprite_put_image;
+       adaptor->QueryImageAttributes = sna_video_sprite_query_attrs;
+
+       video->textured = false;
+       video->color_key = sna_video_sprite_color_key(sna);
+       video->color_key_changed = true;
+       video->brightness = -19;        /* (255/219) * -16 */
+       video->contrast = 75;   /* 255/219 * 64 */
+       video->saturation = 146;        /* 128/112 * 128 */
+       video->desired_crtc = NULL;
+       video->gamma5 = 0xc0c0c0;
+       video->gamma4 = 0x808080;
+       video->gamma3 = 0x404040;
+       video->gamma2 = 0x202020;
+       video->gamma1 = 0x101010;
+       video->gamma0 = 0x080808;
+
+       video->rotation = RR_Rotate_0;
+
+       REGION_NULL(screen, &video->clip);
+
+       xvColorKey = MAKE_ATOM("XV_COLORKEY");
+
+       return adaptor;
+}
diff --git a/src/sna/sna_video_textured.c b/src/sna/sna_video_textured.c
new file mode 100644 (file)
index 0000000..27fc09f
--- /dev/null
@@ -0,0 +1,464 @@
+/***************************************************************************
+
+ Copyright 2000-2011 Intel Corporation.  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, sub license, 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 NON-INFRINGEMENT.
+ IN NO EVENT SHALL INTEL, AND/OR ITS SUPPLIERS 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_CONFIG_H
+#include "config.h"
+#endif
+
+#include "sna.h"
+#include "sna_video.h"
+
+#include <xf86xv.h>
+#include <X11/extensions/Xv.h>
+
+#ifdef SNA_XVMC
+#define _SNA_XVMC_SERVER_
+#include "sna_video_hwmc.h"
+#endif
+
+#define MAKE_ATOM(a) MakeAtom(a, sizeof(a) - 1, true)
+
+static Atom xvBrightness, xvContrast, xvSyncToVblank;
+
+#define NUM_FORMATS 3
+static const XF86VideoFormatRec Formats[NUM_FORMATS] = {
+       {15, TrueColor}, {16, TrueColor}, {24, TrueColor}
+};
+
+//#define NUM_TEXTURED_ATTRIBUTES 3
+#define NUM_TEXTURED_ATTRIBUTES 1
+static const XF86AttributeRec TexturedAttributes[] = {
+       {XvSettable | XvGettable, -1, 1, "XV_SYNC_TO_VBLANK"},
+       {XvSettable | XvGettable, -128, 127, "XV_BRIGHTNESS"},
+       {XvSettable | XvGettable, 0, 255, "XV_CONTRAST"},
+};
+
+#ifdef SNA_XVMC
+#define NUM_IMAGES 5
+#define XVMC_IMAGE 1
+#else
+#define NUM_IMAGES 4
+#define XVMC_IMAGE 0
+#endif
+
+static const XF86ImageRec Images[NUM_IMAGES] = {
+       XVIMAGE_YUY2,
+       XVIMAGE_YV12,
+       XVIMAGE_I420,
+       XVIMAGE_UYVY,
+#ifdef SNA_XVMC
+       {
+               /*
+                * Below, a dummy picture type that is used in XvPutImage
+                * only to do an overlay update.
+                * Introduced for the XvMC client lib.
+                * Defined to have a zero data size.
+                */
+               FOURCC_XVMC,
+               XvYUV,
+               LSBFirst,
+               {'X', 'V', 'M', 'C',
+                       0x00, 0x00, 0x00, 0x10, 0x80, 0x00, 0x00, 0xAA, 0x00,
+                       0x38, 0x9B, 0x71},
+               12,
+               XvPlanar,
+               3,
+               0, 0, 0, 0,
+               8, 8, 8,
+               1, 2, 2,
+               1, 2, 2,
+               {'Y', 'V', 'U',
+                       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+                       0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+               XvTopToBottom},
+#endif
+};
+
+static int xvmc_passthrough(int id)
+{
+#ifdef SNA_XVMC
+       return id == FOURCC_XVMC;
+#else
+       return 0;
+       (void)id;
+#endif
+}
+
+static void sna_video_textured_stop(ScrnInfoPtr scrn,
+                                   pointer data,
+                                   Bool shutdown)
+{
+       struct sna *sna = to_sna(scrn);
+       struct sna_video *video = data;
+
+       DBG(("%s()\n", __FUNCTION__));
+
+       REGION_EMPTY(scrn->pScreen, &video->clip);
+
+       if (!shutdown)
+               return;
+
+       sna_video_free_buffers(sna, video);
+}
+
+static int
+sna_video_textured_set_attribute(ScrnInfoPtr scrn,
+                                Atom attribute,
+                                INT32 value,
+                                pointer data)
+{
+       struct sna_video *video = data;
+
+       if (attribute == xvBrightness) {
+               if (value < -128 || value > 127)
+                       return BadValue;
+
+               video->brightness = value;
+       } else if (attribute == xvContrast) {
+               if (value < 0 || value > 255)
+                       return BadValue;
+
+               video->contrast = value;
+       } else if (attribute == xvSyncToVblank) {
+               if (value < -1 || value > 1)
+                       return BadValue;
+
+               video->SyncToVblank = value;
+       } else
+               return BadMatch;
+
+       return Success;
+}
+
+static int
+sna_video_textured_get_attribute(ScrnInfoPtr scrn,
+                                Atom attribute,
+                                INT32 *value,
+                                pointer data)
+{
+       struct sna_video *video = data;
+
+       if (attribute == xvBrightness)
+               *value = video->brightness;
+       else if (attribute == xvContrast)
+               *value = video->contrast;
+       else if (attribute == xvSyncToVblank)
+               *value = video->SyncToVblank;
+       else
+               return BadMatch;
+
+       return Success;
+}
+
+static void
+sna_video_textured_best_size(ScrnInfoPtr scrn,
+                            Bool motion,
+                            short vid_w, short vid_h,
+                            short drw_w, short drw_h,
+                            unsigned int *p_w,
+                            unsigned int *p_h,
+                            pointer data)
+{
+       if (vid_w > (drw_w << 1))
+               drw_w = vid_w >> 1;
+       if (vid_h > (drw_h << 1))
+               drw_h = vid_h >> 1;
+
+       *p_w = drw_w;
+       *p_h = drw_h;
+}
+
+/*
+ * The source rectangle of the video is defined by (src_x, src_y, src_w, src_h).
+ * The dest rectangle of the video is defined by (drw_x, drw_y, drw_w, drw_h).
+ * id is a fourcc code for the format of the video.
+ * buf is the pointer to the source data in system memory.
+ * width and height are the w/h of the source data.
+ * If "sync" is true, then we must be finished with *buf at the point of return
+ * (which we always are).
+ * clip is the clipping region in screen space.
+ * data is a pointer to our port private.
+ * drawable is some Drawable, which might not be the screen in the case of
+ * compositing.  It's a new argument to the function in the 1.1 server.
+ */
+static int
+sna_video_textured_put_image(ScrnInfoPtr scrn,
+                            short src_x, short src_y,
+                            short drw_x, short drw_y,
+                            short src_w, short src_h,
+                            short drw_w, short drw_h,
+                            int id, unsigned char *buf,
+                            short width, short height,
+                            Bool sync, RegionPtr clip, pointer data,
+                            DrawablePtr drawable)
+{
+       struct sna *sna = to_sna(scrn);
+       struct sna_video *video = data;
+       struct sna_video_frame frame;
+       PixmapPtr pixmap = get_drawable_pixmap(drawable);
+       BoxRec dstBox;
+       xf86CrtcPtr crtc;
+       bool flush = false;
+       bool ret;
+
+       DBG(("%s: src=(%d, %d),(%d, %d), dst=(%d, %d),(%d, %d), id=%d, sizep=%dx%d, sync?=%d\n",
+            __FUNCTION__,
+            src_x, src_y, src_w, src_h,
+            drw_x, drw_y, drw_w, drw_h,
+            id, width, height, sync));
+
+       if (buf == 0) {
+               DBG(("%s: garbage video buffer\n", __FUNCTION__));
+               return BadAlloc;
+       }
+
+       if (!sna_pixmap_move_to_gpu(pixmap, MOVE_READ | MOVE_WRITE)) {
+               DBG(("%s: attempting to render to a non-GPU pixmap\n",
+                    __FUNCTION__));
+               return BadAlloc;
+       }
+
+       sna_video_frame_init(sna, video, id, width, height, &frame);
+
+       if (!sna_video_clip_helper(scrn, video, &frame,
+                                  &crtc, &dstBox,
+                                  src_x, src_y, drw_x, drw_y,
+                                  src_w, src_h, drw_w, drw_h,
+                                  clip))
+               return Success;
+
+       if (xvmc_passthrough(id)) {
+               DBG(("%s: using passthough, name=%d\n",
+                    __FUNCTION__, *(uint32_t *)buf));
+
+               if (sna->kgem.gen < 31) {
+                       /* XXX: i915 is not support and needs some
+                        * serious care.  grep for KMS in i915_hwmc.c */
+                       return BadAlloc;
+               }
+
+               frame.bo = kgem_create_for_name(&sna->kgem, *(uint32_t*)buf);
+               if (frame.bo == NULL) {
+                       DBG(("%s: failed to open bo\n", __FUNCTION__));
+                       return BadAlloc;
+               }
+
+               assert(kgem_bo_size(frame.bo) >= frame.size);
+       } else {
+               if (!sna_video_copy_data(sna, video, &frame, buf)) {
+                       DBG(("%s: failed to copy frame\n", __FUNCTION__));
+                       kgem_bo_destroy(&sna->kgem, frame.bo);
+                       return BadAlloc;
+               }
+       }
+
+       if (crtc && video->SyncToVblank != 0 &&
+           sna_pixmap_is_scanout(sna, pixmap))
+               flush = sna_wait_for_scanline(sna, pixmap, crtc,
+                                             &clip->extents);
+
+       ret = Success;
+       if (!sna->render.video(sna, video, &frame, clip,
+                             src_w, src_h,
+                             drw_w, drw_h,
+                             pixmap)) {
+               DBG(("%s: failed to render video\n", __FUNCTION__));
+               ret = BadAlloc;
+       } else
+               DamageDamageRegion(drawable, clip);
+
+       kgem_bo_destroy(&sna->kgem, frame.bo);
+
+       /* Push the frame to the GPU as soon as possible so
+        * we can hit the next vsync.
+        */
+       if (flush)
+               kgem_submit(&sna->kgem);
+
+       return ret;
+}
+
+static int
+sna_video_textured_query(ScrnInfoPtr scrn,
+                        int id,
+                        unsigned short *w, unsigned short *h,
+                        int *pitches, int *offsets)
+{
+       int size, tmp;
+
+       if (*w > 8192)
+               *w = 8192;
+       if (*h > 8192)
+               *h = 8192;
+
+       *w = (*w + 1) & ~1;
+       if (offsets)
+               offsets[0] = 0;
+
+       switch (id) {
+               /* IA44 is for XvMC only */
+       case FOURCC_IA44:
+       case FOURCC_AI44:
+               if (pitches)
+                       pitches[0] = *w;
+               size = *w * *h;
+               break;
+       case FOURCC_YV12:
+       case FOURCC_I420:
+               *h = (*h + 1) & ~1;
+               size = (*w + 3) & ~3;
+               if (pitches)
+                       pitches[0] = size;
+               size *= *h;
+               if (offsets)
+                       offsets[1] = size;
+               tmp = ((*w >> 1) + 3) & ~3;
+               if (pitches)
+                       pitches[1] = pitches[2] = tmp;
+               tmp *= (*h >> 1);
+               size += tmp;
+               if (offsets)
+                       offsets[2] = size;
+               size += tmp;
+               break;
+       case FOURCC_UYVY:
+       case FOURCC_YUY2:
+       default:
+               size = *w << 1;
+               if (pitches)
+                       pitches[0] = size;
+               size *= *h;
+               break;
+#ifdef SNA_XVMC
+       case FOURCC_XVMC:
+               *h = (*h + 1) & ~1;
+               size = sizeof(struct sna_xvmc_command);
+               if (pitches)
+                       pitches[0] = size;
+               break;
+#endif
+       }
+
+       return size;
+}
+
+XF86VideoAdaptorPtr sna_video_textured_setup(struct sna *sna,
+                                            ScreenPtr screen)
+{
+       XF86VideoAdaptorPtr adaptor;
+       XF86AttributePtr attrs;
+       struct sna_video *video;
+       DevUnion *devUnions;
+       int nports = 16, i;
+
+       if (!sna->render.video) {
+               xf86DrvMsg(sna->scrn->scrnIndex, X_WARNING,
+                          "Textured video not supported on this hardware\n");
+               return NULL;
+       }
+
+       if (wedged(sna)) {
+               xf86DrvMsg(sna->scrn->scrnIndex, X_WARNING,
+                          "cannot enable XVideo whilst the GPU is wedged\n");
+               return NULL;
+       }
+
+       adaptor = calloc(1, sizeof(XF86VideoAdaptorRec));
+       video = calloc(nports, sizeof(struct sna_video));
+       devUnions = calloc(nports, sizeof(DevUnion));
+#if NUM_TEXTURED_ATTRIBUTES
+       attrs = calloc(NUM_TEXTURED_ATTRIBUTES, sizeof(XF86AttributeRec));
+       if (adaptor == NULL ||
+           video == NULL ||
+           devUnions == NULL ||
+           attrs == NULL) {
+               free(adaptor);
+               free(video);
+               free(devUnions);
+               free(attrs);
+               return NULL;
+       }
+#else
+       if (adaptor == NULL || video == NULL || devUnions == NULL) {
+               free(adaptor);
+               free(video);
+               free(devUnions);
+               return NULL;
+       }
+       attrs = NULL;
+#endif
+
+       adaptor->type = XvWindowMask | XvInputMask | XvImageMask;
+       adaptor->flags = 0;
+       adaptor->name = "Intel(R) Textured Video";
+       adaptor->nEncodings = 1;
+       adaptor->pEncodings = xnfalloc(sizeof(XF86VideoEncodingRec));
+       adaptor->pEncodings[0].id = 0;
+       adaptor->pEncodings[0].name = "XV_IMAGE";
+       adaptor->pEncodings[0].width = sna->render.max_3d_size;
+       adaptor->pEncodings[0].height = sna->render.max_3d_size;
+       adaptor->pEncodings[0].rate.numerator = 1;
+       adaptor->pEncodings[0].rate.denominator = 1;
+       adaptor->nFormats = NUM_FORMATS;
+       adaptor->pFormats = (XF86VideoFormatPtr)Formats;
+       adaptor->nPorts = nports;
+       adaptor->pPortPrivates = devUnions;
+       adaptor->nAttributes = NUM_TEXTURED_ATTRIBUTES;
+       adaptor->pAttributes = attrs;
+       memcpy(attrs, TexturedAttributes,
+              NUM_TEXTURED_ATTRIBUTES * sizeof(XF86AttributeRec));
+       adaptor->nImages = NUM_IMAGES;
+       adaptor->pImages = (XF86ImagePtr)Images;
+       adaptor->PutVideo = NULL;
+       adaptor->PutStill = NULL;
+       adaptor->GetVideo = NULL;
+       adaptor->GetStill = NULL;
+       adaptor->StopVideo = sna_video_textured_stop;
+       adaptor->SetPortAttribute = sna_video_textured_set_attribute;
+       adaptor->GetPortAttribute = sna_video_textured_get_attribute;
+       adaptor->QueryBestSize = sna_video_textured_best_size;
+       adaptor->PutImage = sna_video_textured_put_image;
+       adaptor->QueryImageAttributes = sna_video_textured_query;
+
+       for (i = 0; i < nports; i++) {
+               struct sna_video *v = &video[i];
+
+               v->textured = true;
+               v->rotation = RR_Rotate_0;
+               v->SyncToVblank = 1;
+
+               /* gotta uninit this someplace, XXX: shouldn't be necessary for textured */
+               RegionNull(&v->clip);
+
+               adaptor->pPortPrivates[i].ptr = v;
+       }
+
+       xvBrightness = MAKE_ATOM("XV_BRIGHTNESS");
+       xvContrast = MAKE_ATOM("XV_CONTRAST");
+       xvSyncToVblank = MAKE_ATOM("XV_SYNC_TO_VBLANK");
+
+       return adaptor;
+}
index b9e0494..cdc1fe3 100644 (file)
@@ -1,9 +1,9 @@
-# Makefile.in generated by automake 1.11.1 from Makefile.am.
+# Makefile.in generated by automake 1.11.6 from Makefile.am.
 # @configure_input@
 
 # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-# 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
-# Inc.
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
+# Foundation, Inc.
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
 @SET_MAKE@
 
 VPATH = @srcdir@
+am__make_dryrun = \
+  { \
+    am__dry=no; \
+    case $$MAKEFLAGS in \
+      *\\[\ \  ]*) \
+        echo 'am--echo: ; @echo "AM"  OK' | $(MAKE) -f - 2>/dev/null \
+          | grep '^AM OK$$' >/dev/null || am__dry=yes;; \
+      *) \
+        for am__flg in $$MAKEFLAGS; do \
+          case $$am__flg in \
+            *=*|--*) ;; \
+            *n*) am__dry=yes; break;; \
+          esac; \
+        done;; \
+    esac; \
+    test $$am__dry = yes; \
+  }
 pkgdatadir = $(datadir)/@PACKAGE@
 pkgincludedir = $(includedir)/@PACKAGE@
 pkglibdir = $(libdir)/@PACKAGE@
@@ -37,10 +54,7 @@ host_triplet = @host@
 subdir = src/xvmc
 DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
-       $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
-       $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
-       $(top_srcdir)/configure.ac
+am__aclocal_m4_deps = $(top_srcdir)/configure.ac
 am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
        $(ACLOCAL_M4)
 mkinstalldirs = $(install_sh) -d
@@ -68,14 +82,20 @@ am__nobase_list = $(am__nobase_strip_setup); \
 am__base_list = \
   sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
   sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
+am__uninstall_files_from_dir = { \
+  test -z "$$files" \
+    || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \
+    || { echo " ( cd '$$dir' && rm -f" $$files ")"; \
+         $(am__cd) "$$dir" && rm -f $$files; }; \
+  }
 am__installdirs = "$(DESTDIR)$(libdir)"
 LTLIBRARIES = $(lib_LTLIBRARIES)
 libIntelXvMC_la_DEPENDENCIES =
 am_libIntelXvMC_la_OBJECTS = intel_xvmc.lo intel_xvmc_dump.lo \
        i915_xvmc.lo i965_xvmc.lo xvmc_vld.lo intel_batchbuffer.lo
 libIntelXvMC_la_OBJECTS = $(am_libIntelXvMC_la_OBJECTS)
-AM_V_lt = $(am__v_lt_$(V))
-am__v_lt_ = $(am__v_lt_$(AM_DEFAULT_VERBOSITY))
+AM_V_lt = $(am__v_lt_@AM_V@)
+am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
 am__v_lt_0 = --silent
 libIntelXvMC_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \
        $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \
@@ -83,7 +103,7 @@ libIntelXvMC_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \
        -o $@
 @XVMC_TRUE@am_libIntelXvMC_la_rpath = -rpath $(libdir)
 DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
-depcomp = $(SHELL) $(top_srcdir)/build-aux/depcomp
+depcomp = $(SHELL) $(top_srcdir)/depcomp
 am__depfiles_maybe = depfiles
 am__mv = mv -f
 COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
@@ -92,21 +112,21 @@ LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
        $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \
        $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
        $(AM_CFLAGS) $(CFLAGS)
-AM_V_CC = $(am__v_CC_$(V))
-am__v_CC_ = $(am__v_CC_$(AM_DEFAULT_VERBOSITY))
+AM_V_CC = $(am__v_CC_@AM_V@)
+am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@)
 am__v_CC_0 = @echo "  CC    " $@;
-AM_V_at = $(am__v_at_$(V))
-am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY))
+AM_V_at = $(am__v_at_@AM_V@)
+am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
 am__v_at_0 = @
 CCLD = $(CC)
 LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
        $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
        $(AM_LDFLAGS) $(LDFLAGS) -o $@
-AM_V_CCLD = $(am__v_CCLD_$(V))
-am__v_CCLD_ = $(am__v_CCLD_$(AM_DEFAULT_VERBOSITY))
+AM_V_CCLD = $(am__v_CCLD_@AM_V@)
+am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
 am__v_CCLD_0 = @echo "  CCLD  " $@;
-AM_V_GEN = $(am__v_GEN_$(V))
-am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY))
+AM_V_GEN = $(am__v_GEN_@AM_V@)
+am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
 am__v_GEN_0 = @echo "  GEN   " $@;
 SOURCES = $(libIntelXvMC_la_SOURCES)
 DIST_SOURCES = $(libIntelXvMC_la_SOURCES)
@@ -117,6 +137,11 @@ RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \
        install-pdf-recursive install-ps-recursive install-recursive \
        installcheck-recursive installdirs-recursive pdf-recursive \
        ps-recursive uninstall-recursive
+am__can_run_installinfo = \
+  case $$AM_UPDATE_INFO_DIR in \
+    n|no|NO) false;; \
+    *) (install-info --version) >/dev/null 2>&1;; \
+  esac
 RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive        \
   distclean-recursive maintainer-clean-recursive
 AM_RECURSIVE_TARGETS = $(RECURSIVE_TARGETS:-recursive=) \
@@ -163,6 +188,7 @@ AUTOCONF = @AUTOCONF@
 AUTOHEADER = @AUTOHEADER@
 AUTOMAKE = @AUTOMAKE@
 AWK = @AWK@
+BASE_CFLAGS = @BASE_CFLAGS@
 CC = @CC@
 CCDEPMODE = @CCDEPMODE@
 CFLAGS = @CFLAGS@
@@ -173,11 +199,16 @@ CWARNFLAGS = @CWARNFLAGS@
 CYGPATH_W = @CYGPATH_W@
 DEFS = @DEFS@
 DEPDIR = @DEPDIR@
+DLLTOOL = @DLLTOOL@
+DRI2_CFLAGS = @DRI2_CFLAGS@
+DRI2_LIBS = @DRI2_LIBS@
 DRIVER_MAN_DIR = @DRIVER_MAN_DIR@
 DRIVER_MAN_SUFFIX = @DRIVER_MAN_SUFFIX@
 DRIVER_NAME = @DRIVER_NAME@
 DRI_CFLAGS = @DRI_CFLAGS@
 DRI_LIBS = @DRI_LIBS@
+DRMINTEL_CFLAGS = @DRMINTEL_CFLAGS@
+DRMINTEL_LIBS = @DRMINTEL_LIBS@
 DRM_CFLAGS = @DRM_CFLAGS@
 DRM_LIBS = @DRM_LIBS@
 DSYMUTIL = @DSYMUTIL@
@@ -201,6 +232,10 @@ INSTALL_SCRIPT = @INSTALL_SCRIPT@
 INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
 LD = @LD@
 LDFLAGS = @LDFLAGS@
+LIBGLAMOR_CFLAGS = @LIBGLAMOR_CFLAGS@
+LIBGLAMOR_EGL_CFLAGS = @LIBGLAMOR_EGL_CFLAGS@
+LIBGLAMOR_EGL_LIBS = @LIBGLAMOR_EGL_LIBS@
+LIBGLAMOR_LIBS = @LIBGLAMOR_LIBS@
 LIBOBJS = @LIBOBJS@
 LIBS = @LIBS@
 LIBTOOL = @LIBTOOL@
@@ -211,6 +246,7 @@ LN_S = @LN_S@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MANIFEST_TOOL = @MANIFEST_TOOL@
 MAN_SUBSTS = @MAN_SUBSTS@
 MISC_MAN_DIR = @MISC_MAN_DIR@
 MISC_MAN_SUFFIX = @MISC_MAN_SUFFIX@
@@ -238,10 +274,15 @@ RANLIB = @RANLIB@
 SED = @SED@
 SET_MAKE = @SET_MAKE@
 SHELL = @SHELL@
+STRICT_CFLAGS = @STRICT_CFLAGS@
 STRIP = @STRIP@
 UDEV_CFLAGS = @UDEV_CFLAGS@
 UDEV_LIBS = @UDEV_LIBS@
+VALGRIND_CFLAGS = @VALGRIND_CFLAGS@
+VALGRIND_LIBS = @VALGRIND_LIBS@
 VERSION = @VERSION@
+X11_CFLAGS = @X11_CFLAGS@
+X11_LIBS = @X11_LIBS@
 XORG_CFLAGS = @XORG_CFLAGS@
 XORG_LIBS = @XORG_LIBS@
 XORG_MAN_PAGE = @XORG_MAN_PAGE@
@@ -251,6 +292,7 @@ abs_builddir = @abs_builddir@
 abs_srcdir = @abs_srcdir@
 abs_top_builddir = @abs_top_builddir@
 abs_top_srcdir = @abs_top_srcdir@
+ac_ct_AR = @ac_ct_AR@
 ac_ct_CC = @ac_ct_CC@
 ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
 am__include = @am__include@
@@ -283,7 +325,6 @@ libdir = @libdir@
 libexecdir = @libexecdir@
 localedir = @localedir@
 localstatedir = @localstatedir@
-lt_ECHO = @lt_ECHO@
 mandir = @mandir@
 mkdir_p = @mkdir_p@
 moduledir = @moduledir@
@@ -355,7 +396,6 @@ $(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
 $(am__aclocal_m4_deps):
 install-libLTLIBRARIES: $(lib_LTLIBRARIES)
        @$(NORMAL_INSTALL)
-       test -z "$(libdir)" || $(MKDIR_P) "$(DESTDIR)$(libdir)"
        @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \
        list2=; for p in $$list; do \
          if test -f $$p; then \
@@ -363,6 +403,8 @@ install-libLTLIBRARIES: $(lib_LTLIBRARIES)
          else :; fi; \
        done; \
        test -z "$$list2" || { \
+         echo " $(MKDIR_P) '$(DESTDIR)$(libdir)'"; \
+         $(MKDIR_P) "$(DESTDIR)$(libdir)" || exit 1; \
          echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(libdir)'"; \
          $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(libdir)"; \
        }
@@ -384,7 +426,7 @@ clean-libLTLIBRARIES:
          echo "rm -f \"$${dir}/so_locations\""; \
          rm -f "$${dir}/so_locations"; \
        done
-libIntelXvMC.la: $(libIntelXvMC_la_OBJECTS) $(libIntelXvMC_la_DEPENDENCIES) 
+libIntelXvMC.la: $(libIntelXvMC_la_OBJECTS) $(libIntelXvMC_la_DEPENDENCIES) $(EXTRA_libIntelXvMC_la_DEPENDENCIES) 
        $(AM_V_CCLD)$(libIntelXvMC_la_LINK) $(am_libIntelXvMC_la_rpath) $(libIntelXvMC_la_OBJECTS) $(libIntelXvMC_la_LIBADD) $(LIBS)
 
 mostlyclean-compile:
@@ -403,26 +445,23 @@ distclean-compile:
 .c.o:
 @am__fastdepCC_TRUE@   $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
 @am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
-@am__fastdepCC_FALSE@  $(AM_V_CC) @AM_BACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@  $(COMPILE) -c $<
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(COMPILE) -c $<
 
 .c.obj:
 @am__fastdepCC_TRUE@   $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
 @am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
-@am__fastdepCC_FALSE@  $(AM_V_CC) @AM_BACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@  $(COMPILE) -c `$(CYGPATH_W) '$<'`
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(COMPILE) -c `$(CYGPATH_W) '$<'`
 
 .c.lo:
 @am__fastdepCC_TRUE@   $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
 @am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
-@am__fastdepCC_FALSE@  $(AM_V_CC) @AM_BACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@  $(LTCOMPILE) -c -o $@ $<
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $<
 
 mostlyclean-libtool:
        -rm -f *.lo
@@ -597,13 +636,10 @@ distdir: $(DISTFILES)
        done
        @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
          if test "$$subdir" = .; then :; else \
-           test -d "$(distdir)/$$subdir" \
-           || $(MKDIR_P) "$(distdir)/$$subdir" \
-           || exit 1; \
-         fi; \
-       done
-       @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
-         if test "$$subdir" = .; then :; else \
+           $(am__make_dryrun) \
+             || test -d "$(distdir)/$$subdir" \
+             || $(MKDIR_P) "$(distdir)/$$subdir" \
+             || exit 1; \
            dir1=$$subdir; dir2="$(distdir)/$$subdir"; \
            $(am__relativize); \
            new_distdir=$$reldir; \
@@ -641,10 +677,15 @@ install-am: all-am
 
 installcheck: installcheck-recursive
 install-strip:
-       $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
-         install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
-         `test -z '$(STRIP)' || \
-           echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+       if test -z '$(STRIP)'; then \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+             install; \
+       else \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+           "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+       fi
 mostlyclean-generic:
 
 clean-generic:
index 210cf73..261cf35 100644 (file)
@@ -244,7 +244,7 @@ static Status destroy_context(Display * display, XvMCContext * context)
 {
        struct intel_xvmc_context *intel_ctx;
        intel_ctx = context->privData;
-       Xfree(intel_ctx->hw);
+       free(intel_ctx->hw);
        free(intel_ctx);
        return Success;
 }
index 888abeb..7fae6f7 100644 (file)
@@ -44,7 +44,6 @@ extern int VERBOSE;
     do {                                                                 \
         xvmc_driver->batch.space -= (batch_ptr - xvmc_driver->batch.ptr);\
         xvmc_driver->batch.ptr = batch_ptr;                              \
-        assert(xvmc_driver->batch.space >= 0);                           \
     } while(0)
 
 extern void intelFlushBatch(Bool);
index 1b96945..883dada 100644 (file)
@@ -972,7 +972,7 @@ _X_EXPORT Status XvMCGetSubpictureStatus(Display * display,
  * Function: XvMCQueryAttributes
  * Description: An array of XvAttributes of size "number" is returned by
  *   this function. If there are no attributes, NULL is returned and number
- *   is set to 0. The array may be freed with xfree().
+ *   is set to 0. The array may be freed with free().
  *
  * Arguments:
  *   display - Connection to the X server.
index baec344..68760d2 100644 (file)
@@ -1,9 +1,9 @@
-# Makefile.in generated by automake 1.11.1 from Makefile.am.
+# Makefile.in generated by automake 1.11.6 from Makefile.am.
 # @configure_input@
 
 # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-# 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
-# Inc.
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
+# Foundation, Inc.
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
 
 @SET_MAKE@
 VPATH = @srcdir@
+am__make_dryrun = \
+  { \
+    am__dry=no; \
+    case $$MAKEFLAGS in \
+      *\\[\ \  ]*) \
+        echo 'am--echo: ; @echo "AM"  OK' | $(MAKE) -f - 2>/dev/null \
+          | grep '^AM OK$$' >/dev/null || am__dry=yes;; \
+      *) \
+        for am__flg in $$MAKEFLAGS; do \
+          case $$am__flg in \
+            *=*|--*) ;; \
+            *n*) am__dry=yes; break;; \
+          esac; \
+        done;; \
+    esac; \
+    test $$am__dry = yes; \
+  }
 pkgdatadir = $(datadir)/@PACKAGE@
 pkgincludedir = $(includedir)/@PACKAGE@
 pkglibdir = $(libdir)/@PACKAGE@
@@ -36,21 +53,18 @@ host_triplet = @host@
 subdir = src/xvmc/shader
 DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
-       $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
-       $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
-       $(top_srcdir)/configure.ac
+am__aclocal_m4_deps = $(top_srcdir)/configure.ac
 am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
        $(ACLOCAL_M4)
 mkinstalldirs = $(install_sh) -d
 CONFIG_HEADER = $(top_builddir)/config.h
 CONFIG_CLEAN_FILES =
 CONFIG_CLEAN_VPATH_FILES =
-AM_V_GEN = $(am__v_GEN_$(V))
-am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY))
+AM_V_GEN = $(am__v_GEN_@AM_V@)
+am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
 am__v_GEN_0 = @echo "  GEN   " $@;
-AM_V_at = $(am__v_at_$(V))
-am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY))
+AM_V_at = $(am__v_at_@AM_V@)
+am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
 am__v_at_0 = @
 SOURCES =
 DIST_SOURCES =
@@ -61,6 +75,11 @@ RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \
        install-pdf-recursive install-ps-recursive install-recursive \
        installcheck-recursive installdirs-recursive pdf-recursive \
        ps-recursive uninstall-recursive
+am__can_run_installinfo = \
+  case $$AM_UPDATE_INFO_DIR in \
+    n|no|NO) false;; \
+    *) (install-info --version) >/dev/null 2>&1;; \
+  esac
 RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive        \
   distclean-recursive maintainer-clean-recursive
 AM_RECURSIVE_TARGETS = $(RECURSIVE_TARGETS:-recursive=) \
@@ -107,6 +126,7 @@ AUTOCONF = @AUTOCONF@
 AUTOHEADER = @AUTOHEADER@
 AUTOMAKE = @AUTOMAKE@
 AWK = @AWK@
+BASE_CFLAGS = @BASE_CFLAGS@
 CC = @CC@
 CCDEPMODE = @CCDEPMODE@
 CFLAGS = @CFLAGS@
@@ -117,11 +137,16 @@ CWARNFLAGS = @CWARNFLAGS@
 CYGPATH_W = @CYGPATH_W@
 DEFS = @DEFS@
 DEPDIR = @DEPDIR@
+DLLTOOL = @DLLTOOL@
+DRI2_CFLAGS = @DRI2_CFLAGS@
+DRI2_LIBS = @DRI2_LIBS@
 DRIVER_MAN_DIR = @DRIVER_MAN_DIR@
 DRIVER_MAN_SUFFIX = @DRIVER_MAN_SUFFIX@
 DRIVER_NAME = @DRIVER_NAME@
 DRI_CFLAGS = @DRI_CFLAGS@
 DRI_LIBS = @DRI_LIBS@
+DRMINTEL_CFLAGS = @DRMINTEL_CFLAGS@
+DRMINTEL_LIBS = @DRMINTEL_LIBS@
 DRM_CFLAGS = @DRM_CFLAGS@
 DRM_LIBS = @DRM_LIBS@
 DSYMUTIL = @DSYMUTIL@
@@ -145,6 +170,10 @@ INSTALL_SCRIPT = @INSTALL_SCRIPT@
 INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
 LD = @LD@
 LDFLAGS = @LDFLAGS@
+LIBGLAMOR_CFLAGS = @LIBGLAMOR_CFLAGS@
+LIBGLAMOR_EGL_CFLAGS = @LIBGLAMOR_EGL_CFLAGS@
+LIBGLAMOR_EGL_LIBS = @LIBGLAMOR_EGL_LIBS@
+LIBGLAMOR_LIBS = @LIBGLAMOR_LIBS@
 LIBOBJS = @LIBOBJS@
 LIBS = @LIBS@
 LIBTOOL = @LIBTOOL@
@@ -155,6 +184,7 @@ LN_S = @LN_S@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MANIFEST_TOOL = @MANIFEST_TOOL@
 MAN_SUBSTS = @MAN_SUBSTS@
 MISC_MAN_DIR = @MISC_MAN_DIR@
 MISC_MAN_SUFFIX = @MISC_MAN_SUFFIX@
@@ -182,10 +212,15 @@ RANLIB = @RANLIB@
 SED = @SED@
 SET_MAKE = @SET_MAKE@
 SHELL = @SHELL@
+STRICT_CFLAGS = @STRICT_CFLAGS@
 STRIP = @STRIP@
 UDEV_CFLAGS = @UDEV_CFLAGS@
 UDEV_LIBS = @UDEV_LIBS@
+VALGRIND_CFLAGS = @VALGRIND_CFLAGS@
+VALGRIND_LIBS = @VALGRIND_LIBS@
 VERSION = @VERSION@
+X11_CFLAGS = @X11_CFLAGS@
+X11_LIBS = @X11_LIBS@
 XORG_CFLAGS = @XORG_CFLAGS@
 XORG_LIBS = @XORG_LIBS@
 XORG_MAN_PAGE = @XORG_MAN_PAGE@
@@ -195,6 +230,7 @@ abs_builddir = @abs_builddir@
 abs_srcdir = @abs_srcdir@
 abs_top_builddir = @abs_top_builddir@
 abs_top_srcdir = @abs_top_srcdir@
+ac_ct_AR = @ac_ct_AR@
 ac_ct_CC = @ac_ct_CC@
 ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
 am__include = @am__include@
@@ -227,7 +263,6 @@ libdir = @libdir@
 libexecdir = @libexecdir@
 localedir = @localedir@
 localstatedir = @localstatedir@
-lt_ECHO = @lt_ECHO@
 mandir = @mandir@
 mkdir_p = @mkdir_p@
 moduledir = @moduledir@
@@ -452,13 +487,10 @@ distdir: $(DISTFILES)
        done
        @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
          if test "$$subdir" = .; then :; else \
-           test -d "$(distdir)/$$subdir" \
-           || $(MKDIR_P) "$(distdir)/$$subdir" \
-           || exit 1; \
-         fi; \
-       done
-       @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
-         if test "$$subdir" = .; then :; else \
+           $(am__make_dryrun) \
+             || test -d "$(distdir)/$$subdir" \
+             || $(MKDIR_P) "$(distdir)/$$subdir" \
+             || exit 1; \
            dir1=$$subdir; dir2="$(distdir)/$$subdir"; \
            $(am__relativize); \
            new_distdir=$$reldir; \
@@ -493,10 +525,15 @@ install-am: all-am
 
 installcheck: installcheck-recursive
 install-strip:
-       $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
-         install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
-         `test -z '$(STRIP)' || \
-           echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+       if test -z '$(STRIP)'; then \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+             install; \
+       else \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+           "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+       fi
 mostlyclean-generic:
 
 clean-generic:
index b63d4f6..fb2f314 100644 (file)
@@ -1,9 +1,9 @@
-# Makefile.in generated by automake 1.11.1 from Makefile.am.
+# Makefile.in generated by automake 1.11.6 from Makefile.am.
 # @configure_input@
 
 # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-# 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
-# Inc.
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
+# Foundation, Inc.
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
 
 @SET_MAKE@
 VPATH = @srcdir@
+am__make_dryrun = \
+  { \
+    am__dry=no; \
+    case $$MAKEFLAGS in \
+      *\\[\ \  ]*) \
+        echo 'am--echo: ; @echo "AM"  OK' | $(MAKE) -f - 2>/dev/null \
+          | grep '^AM OK$$' >/dev/null || am__dry=yes;; \
+      *) \
+        for am__flg in $$MAKEFLAGS; do \
+          case $$am__flg in \
+            *=*|--*) ;; \
+            *n*) am__dry=yes; break;; \
+          esac; \
+        done;; \
+    esac; \
+    test $$am__dry = yes; \
+  }
 pkgdatadir = $(datadir)/@PACKAGE@
 pkgincludedir = $(includedir)/@PACKAGE@
 pkglibdir = $(libdir)/@PACKAGE@
@@ -36,24 +53,26 @@ host_triplet = @host@
 subdir = src/xvmc/shader/mc
 DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
-       $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
-       $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
-       $(top_srcdir)/configure.ac
+am__aclocal_m4_deps = $(top_srcdir)/configure.ac
 am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
        $(ACLOCAL_M4)
 mkinstalldirs = $(install_sh) -d
 CONFIG_HEADER = $(top_builddir)/config.h
 CONFIG_CLEAN_FILES =
 CONFIG_CLEAN_VPATH_FILES =
-AM_V_GEN = $(am__v_GEN_$(V))
-am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY))
+AM_V_GEN = $(am__v_GEN_@AM_V@)
+am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
 am__v_GEN_0 = @echo "  GEN   " $@;
-AM_V_at = $(am__v_at_$(V))
-am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY))
+AM_V_at = $(am__v_at_@AM_V@)
+am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
 am__v_at_0 = @
 SOURCES =
 DIST_SOURCES =
+am__can_run_installinfo = \
+  case $$AM_UPDATE_INFO_DIR in \
+    n|no|NO) false;; \
+    *) (install-info --version) >/dev/null 2>&1;; \
+  esac
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
 ACLOCAL = @ACLOCAL@
 ADMIN_MAN_DIR = @ADMIN_MAN_DIR@
@@ -67,6 +86,7 @@ AUTOCONF = @AUTOCONF@
 AUTOHEADER = @AUTOHEADER@
 AUTOMAKE = @AUTOMAKE@
 AWK = @AWK@
+BASE_CFLAGS = @BASE_CFLAGS@
 CC = @CC@
 CCDEPMODE = @CCDEPMODE@
 CFLAGS = @CFLAGS@
@@ -77,11 +97,16 @@ CWARNFLAGS = @CWARNFLAGS@
 CYGPATH_W = @CYGPATH_W@
 DEFS = @DEFS@
 DEPDIR = @DEPDIR@
+DLLTOOL = @DLLTOOL@
+DRI2_CFLAGS = @DRI2_CFLAGS@
+DRI2_LIBS = @DRI2_LIBS@
 DRIVER_MAN_DIR = @DRIVER_MAN_DIR@
 DRIVER_MAN_SUFFIX = @DRIVER_MAN_SUFFIX@
 DRIVER_NAME = @DRIVER_NAME@
 DRI_CFLAGS = @DRI_CFLAGS@
 DRI_LIBS = @DRI_LIBS@
+DRMINTEL_CFLAGS = @DRMINTEL_CFLAGS@
+DRMINTEL_LIBS = @DRMINTEL_LIBS@
 DRM_CFLAGS = @DRM_CFLAGS@
 DRM_LIBS = @DRM_LIBS@
 DSYMUTIL = @DSYMUTIL@
@@ -105,6 +130,10 @@ INSTALL_SCRIPT = @INSTALL_SCRIPT@
 INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
 LD = @LD@
 LDFLAGS = @LDFLAGS@
+LIBGLAMOR_CFLAGS = @LIBGLAMOR_CFLAGS@
+LIBGLAMOR_EGL_CFLAGS = @LIBGLAMOR_EGL_CFLAGS@
+LIBGLAMOR_EGL_LIBS = @LIBGLAMOR_EGL_LIBS@
+LIBGLAMOR_LIBS = @LIBGLAMOR_LIBS@
 LIBOBJS = @LIBOBJS@
 LIBS = @LIBS@
 LIBTOOL = @LIBTOOL@
@@ -115,6 +144,7 @@ LN_S = @LN_S@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MANIFEST_TOOL = @MANIFEST_TOOL@
 MAN_SUBSTS = @MAN_SUBSTS@
 MISC_MAN_DIR = @MISC_MAN_DIR@
 MISC_MAN_SUFFIX = @MISC_MAN_SUFFIX@
@@ -142,10 +172,15 @@ RANLIB = @RANLIB@
 SED = @SED@
 SET_MAKE = @SET_MAKE@
 SHELL = @SHELL@
+STRICT_CFLAGS = @STRICT_CFLAGS@
 STRIP = @STRIP@
 UDEV_CFLAGS = @UDEV_CFLAGS@
 UDEV_LIBS = @UDEV_LIBS@
+VALGRIND_CFLAGS = @VALGRIND_CFLAGS@
+VALGRIND_LIBS = @VALGRIND_LIBS@
 VERSION = @VERSION@
+X11_CFLAGS = @X11_CFLAGS@
+X11_LIBS = @X11_LIBS@
 XORG_CFLAGS = @XORG_CFLAGS@
 XORG_LIBS = @XORG_LIBS@
 XORG_MAN_PAGE = @XORG_MAN_PAGE@
@@ -155,6 +190,7 @@ abs_builddir = @abs_builddir@
 abs_srcdir = @abs_srcdir@
 abs_top_builddir = @abs_top_builddir@
 abs_top_srcdir = @abs_top_srcdir@
+ac_ct_AR = @ac_ct_AR@
 ac_ct_CC = @ac_ct_CC@
 ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
 am__include = @am__include@
@@ -187,7 +223,6 @@ libdir = @libdir@
 libexecdir = @libexecdir@
 localedir = @localedir@
 localstatedir = @localstatedir@
-lt_ECHO = @lt_ECHO@
 mandir = @mandir@
 mkdir_p = @mkdir_p@
 moduledir = @moduledir@
@@ -406,10 +441,15 @@ install-am: all-am
 
 installcheck: installcheck-am
 install-strip:
-       $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
-         install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
-         `test -z '$(STRIP)' || \
-           echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+       if test -z '$(STRIP)'; then \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+             install; \
+       else \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+           "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+       fi
 mostlyclean-generic:
 
 clean-generic:
index 7b5f1f5..25f0123 100644 (file)
@@ -1,9 +1,9 @@
-# Makefile.in generated by automake 1.11.1 from Makefile.am.
+# Makefile.in generated by automake 1.11.6 from Makefile.am.
 # @configure_input@
 
 # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-# 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
-# Inc.
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
+# Foundation, Inc.
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
 
 @SET_MAKE@
 VPATH = @srcdir@
+am__make_dryrun = \
+  { \
+    am__dry=no; \
+    case $$MAKEFLAGS in \
+      *\\[\ \  ]*) \
+        echo 'am--echo: ; @echo "AM"  OK' | $(MAKE) -f - 2>/dev/null \
+          | grep '^AM OK$$' >/dev/null || am__dry=yes;; \
+      *) \
+        for am__flg in $$MAKEFLAGS; do \
+          case $$am__flg in \
+            *=*|--*) ;; \
+            *n*) am__dry=yes; break;; \
+          esac; \
+        done;; \
+    esac; \
+    test $$am__dry = yes; \
+  }
 pkgdatadir = $(datadir)/@PACKAGE@
 pkgincludedir = $(includedir)/@PACKAGE@
 pkglibdir = $(libdir)/@PACKAGE@
@@ -36,24 +53,26 @@ host_triplet = @host@
 subdir = src/xvmc/shader/vld
 DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
-       $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
-       $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
-       $(top_srcdir)/configure.ac
+am__aclocal_m4_deps = $(top_srcdir)/configure.ac
 am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
        $(ACLOCAL_M4)
 mkinstalldirs = $(install_sh) -d
 CONFIG_HEADER = $(top_builddir)/config.h
 CONFIG_CLEAN_FILES =
 CONFIG_CLEAN_VPATH_FILES =
-AM_V_GEN = $(am__v_GEN_$(V))
-am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY))
+AM_V_GEN = $(am__v_GEN_@AM_V@)
+am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
 am__v_GEN_0 = @echo "  GEN   " $@;
-AM_V_at = $(am__v_at_$(V))
-am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY))
+AM_V_at = $(am__v_at_@AM_V@)
+am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
 am__v_at_0 = @
 SOURCES =
 DIST_SOURCES =
+am__can_run_installinfo = \
+  case $$AM_UPDATE_INFO_DIR in \
+    n|no|NO) false;; \
+    *) (install-info --version) >/dev/null 2>&1;; \
+  esac
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
 ACLOCAL = @ACLOCAL@
 ADMIN_MAN_DIR = @ADMIN_MAN_DIR@
@@ -67,6 +86,7 @@ AUTOCONF = @AUTOCONF@
 AUTOHEADER = @AUTOHEADER@
 AUTOMAKE = @AUTOMAKE@
 AWK = @AWK@
+BASE_CFLAGS = @BASE_CFLAGS@
 CC = @CC@
 CCDEPMODE = @CCDEPMODE@
 CFLAGS = @CFLAGS@
@@ -77,11 +97,16 @@ CWARNFLAGS = @CWARNFLAGS@
 CYGPATH_W = @CYGPATH_W@
 DEFS = @DEFS@
 DEPDIR = @DEPDIR@
+DLLTOOL = @DLLTOOL@
+DRI2_CFLAGS = @DRI2_CFLAGS@
+DRI2_LIBS = @DRI2_LIBS@
 DRIVER_MAN_DIR = @DRIVER_MAN_DIR@
 DRIVER_MAN_SUFFIX = @DRIVER_MAN_SUFFIX@
 DRIVER_NAME = @DRIVER_NAME@
 DRI_CFLAGS = @DRI_CFLAGS@
 DRI_LIBS = @DRI_LIBS@
+DRMINTEL_CFLAGS = @DRMINTEL_CFLAGS@
+DRMINTEL_LIBS = @DRMINTEL_LIBS@
 DRM_CFLAGS = @DRM_CFLAGS@
 DRM_LIBS = @DRM_LIBS@
 DSYMUTIL = @DSYMUTIL@
@@ -105,6 +130,10 @@ INSTALL_SCRIPT = @INSTALL_SCRIPT@
 INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
 LD = @LD@
 LDFLAGS = @LDFLAGS@
+LIBGLAMOR_CFLAGS = @LIBGLAMOR_CFLAGS@
+LIBGLAMOR_EGL_CFLAGS = @LIBGLAMOR_EGL_CFLAGS@
+LIBGLAMOR_EGL_LIBS = @LIBGLAMOR_EGL_LIBS@
+LIBGLAMOR_LIBS = @LIBGLAMOR_LIBS@
 LIBOBJS = @LIBOBJS@
 LIBS = @LIBS@
 LIBTOOL = @LIBTOOL@
@@ -115,6 +144,7 @@ LN_S = @LN_S@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MANIFEST_TOOL = @MANIFEST_TOOL@
 MAN_SUBSTS = @MAN_SUBSTS@
 MISC_MAN_DIR = @MISC_MAN_DIR@
 MISC_MAN_SUFFIX = @MISC_MAN_SUFFIX@
@@ -142,10 +172,15 @@ RANLIB = @RANLIB@
 SED = @SED@
 SET_MAKE = @SET_MAKE@
 SHELL = @SHELL@
+STRICT_CFLAGS = @STRICT_CFLAGS@
 STRIP = @STRIP@
 UDEV_CFLAGS = @UDEV_CFLAGS@
 UDEV_LIBS = @UDEV_LIBS@
+VALGRIND_CFLAGS = @VALGRIND_CFLAGS@
+VALGRIND_LIBS = @VALGRIND_LIBS@
 VERSION = @VERSION@
+X11_CFLAGS = @X11_CFLAGS@
+X11_LIBS = @X11_LIBS@
 XORG_CFLAGS = @XORG_CFLAGS@
 XORG_LIBS = @XORG_LIBS@
 XORG_MAN_PAGE = @XORG_MAN_PAGE@
@@ -155,6 +190,7 @@ abs_builddir = @abs_builddir@
 abs_srcdir = @abs_srcdir@
 abs_top_builddir = @abs_top_builddir@
 abs_top_srcdir = @abs_top_srcdir@
+ac_ct_AR = @ac_ct_AR@
 ac_ct_CC = @ac_ct_CC@
 ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
 am__include = @am__include@
@@ -187,7 +223,6 @@ libdir = @libdir@
 libexecdir = @libexecdir@
 localedir = @localedir@
 localstatedir = @localstatedir@
-lt_ECHO = @lt_ECHO@
 mandir = @mandir@
 mkdir_p = @mkdir_p@
 moduledir = @moduledir@
@@ -359,10 +394,15 @@ install-am: all-am
 
 installcheck: installcheck-am
 install-strip:
-       $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
-         install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
-         `test -z '$(STRIP)' || \
-           echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+       if test -z '$(STRIP)'; then \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+             install; \
+       else \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+           "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+       fi
 mostlyclean-generic:
 
 clean-generic:
index 570e9b6..3f5fa5e 100644 (file)
@@ -622,7 +622,7 @@ static Status destroy_context(Display * display, XvMCContext * context)
 {
        struct intel_xvmc_context *intel_ctx;
        intel_ctx = context->privData;
-       Xfree(intel_ctx->hw);
+       free(intel_ctx->hw);
        free(intel_ctx);
        return Success;
 }
diff --git a/test/Makefile.am b/test/Makefile.am
new file mode 100644 (file)
index 0000000..96c87f8
--- /dev/null
@@ -0,0 +1,38 @@
+stress_TESTS = \
+       basic-fillrect \
+       basic-rectangle \
+       basic-string \
+       basic-copyarea \
+       basic-copyarea-size \
+       basic-putimage \
+       basic-lines \
+       basic-stress \
+       render-fill \
+       render-trapezoid \
+       render-trapezoid-image \
+       render-fill-copy \
+       render-composite-solid \
+       render-copyarea \
+       render-copyarea-size \
+       render-copy-alphaless \
+       mixed-stress \
+       dri2-swap \
+       $(NULL)
+
+check_PROGRAMS = $(stress_TESTS)
+
+AM_CFLAGS = @CWARNFLAGS@ @X11_CFLAGS@ @DRM_CFLAGS@
+LDADD = libtest.la @X11_LIBS@ -lXfixes @DRM_LIBS@ -lrt
+
+noinst_LTLIBRARIES = libtest.la
+libtest_la_SOURCES = \
+       test.h \
+       test_display.c \
+       test_image.c \
+       test_log.c \
+       test_render.c \
+       dri2.c \
+       dri2.h \
+       $(NULL)
+
+EXTRA_DIST = README
diff --git a/test/Makefile.in b/test/Makefile.in
new file mode 100644 (file)
index 0000000..47d68b3
--- /dev/null
@@ -0,0 +1,775 @@
+# Makefile.in generated by automake 1.11.6 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
+# Foundation, Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+
+VPATH = @srcdir@
+am__make_dryrun = \
+  { \
+    am__dry=no; \
+    case $$MAKEFLAGS in \
+      *\\[\ \  ]*) \
+        echo 'am--echo: ; @echo "AM"  OK' | $(MAKE) -f - 2>/dev/null \
+          | grep '^AM OK$$' >/dev/null || am__dry=yes;; \
+      *) \
+        for am__flg in $$MAKEFLAGS; do \
+          case $$am__flg in \
+            *=*|--*) ;; \
+            *n*) am__dry=yes; break;; \
+          esac; \
+        done;; \
+    esac; \
+    test $$am__dry = yes; \
+  }
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+check_PROGRAMS = $(am__EXEEXT_1)
+subdir = test
+DIST_COMMON = README $(srcdir)/Makefile.am $(srcdir)/Makefile.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+       $(ACLOCAL_M4)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+LTLIBRARIES = $(noinst_LTLIBRARIES)
+libtest_la_LIBADD =
+am_libtest_la_OBJECTS = test_display.lo test_image.lo test_log.lo \
+       test_render.lo dri2.lo
+libtest_la_OBJECTS = $(am_libtest_la_OBJECTS)
+AM_V_lt = $(am__v_lt_@AM_V@)
+am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
+am__v_lt_0 = --silent
+am__EXEEXT_1 = basic-fillrect$(EXEEXT) basic-rectangle$(EXEEXT) \
+       basic-string$(EXEEXT) basic-copyarea$(EXEEXT) \
+       basic-copyarea-size$(EXEEXT) basic-putimage$(EXEEXT) \
+       basic-lines$(EXEEXT) basic-stress$(EXEEXT) \
+       render-fill$(EXEEXT) render-trapezoid$(EXEEXT) \
+       render-trapezoid-image$(EXEEXT) render-fill-copy$(EXEEXT) \
+       render-composite-solid$(EXEEXT) render-copyarea$(EXEEXT) \
+       render-copyarea-size$(EXEEXT) render-copy-alphaless$(EXEEXT) \
+       mixed-stress$(EXEEXT) dri2-swap$(EXEEXT)
+basic_copyarea_SOURCES = basic-copyarea.c
+basic_copyarea_OBJECTS = basic-copyarea.$(OBJEXT)
+basic_copyarea_LDADD = $(LDADD)
+basic_copyarea_DEPENDENCIES = libtest.la
+basic_copyarea_size_SOURCES = basic-copyarea-size.c
+basic_copyarea_size_OBJECTS = basic-copyarea-size.$(OBJEXT)
+basic_copyarea_size_LDADD = $(LDADD)
+basic_copyarea_size_DEPENDENCIES = libtest.la
+basic_fillrect_SOURCES = basic-fillrect.c
+basic_fillrect_OBJECTS = basic-fillrect.$(OBJEXT)
+basic_fillrect_LDADD = $(LDADD)
+basic_fillrect_DEPENDENCIES = libtest.la
+basic_lines_SOURCES = basic-lines.c
+basic_lines_OBJECTS = basic-lines.$(OBJEXT)
+basic_lines_LDADD = $(LDADD)
+basic_lines_DEPENDENCIES = libtest.la
+basic_putimage_SOURCES = basic-putimage.c
+basic_putimage_OBJECTS = basic-putimage.$(OBJEXT)
+basic_putimage_LDADD = $(LDADD)
+basic_putimage_DEPENDENCIES = libtest.la
+basic_rectangle_SOURCES = basic-rectangle.c
+basic_rectangle_OBJECTS = basic-rectangle.$(OBJEXT)
+basic_rectangle_LDADD = $(LDADD)
+basic_rectangle_DEPENDENCIES = libtest.la
+basic_stress_SOURCES = basic-stress.c
+basic_stress_OBJECTS = basic-stress.$(OBJEXT)
+basic_stress_LDADD = $(LDADD)
+basic_stress_DEPENDENCIES = libtest.la
+basic_string_SOURCES = basic-string.c
+basic_string_OBJECTS = basic-string.$(OBJEXT)
+basic_string_LDADD = $(LDADD)
+basic_string_DEPENDENCIES = libtest.la
+dri2_swap_SOURCES = dri2-swap.c
+dri2_swap_OBJECTS = dri2-swap.$(OBJEXT)
+dri2_swap_LDADD = $(LDADD)
+dri2_swap_DEPENDENCIES = libtest.la
+mixed_stress_SOURCES = mixed-stress.c
+mixed_stress_OBJECTS = mixed-stress.$(OBJEXT)
+mixed_stress_LDADD = $(LDADD)
+mixed_stress_DEPENDENCIES = libtest.la
+render_composite_solid_SOURCES = render-composite-solid.c
+render_composite_solid_OBJECTS = render-composite-solid.$(OBJEXT)
+render_composite_solid_LDADD = $(LDADD)
+render_composite_solid_DEPENDENCIES = libtest.la
+render_copy_alphaless_SOURCES = render-copy-alphaless.c
+render_copy_alphaless_OBJECTS = render-copy-alphaless.$(OBJEXT)
+render_copy_alphaless_LDADD = $(LDADD)
+render_copy_alphaless_DEPENDENCIES = libtest.la
+render_copyarea_SOURCES = render-copyarea.c
+render_copyarea_OBJECTS = render-copyarea.$(OBJEXT)
+render_copyarea_LDADD = $(LDADD)
+render_copyarea_DEPENDENCIES = libtest.la
+render_copyarea_size_SOURCES = render-copyarea-size.c
+render_copyarea_size_OBJECTS = render-copyarea-size.$(OBJEXT)
+render_copyarea_size_LDADD = $(LDADD)
+render_copyarea_size_DEPENDENCIES = libtest.la
+render_fill_SOURCES = render-fill.c
+render_fill_OBJECTS = render-fill.$(OBJEXT)
+render_fill_LDADD = $(LDADD)
+render_fill_DEPENDENCIES = libtest.la
+render_fill_copy_SOURCES = render-fill-copy.c
+render_fill_copy_OBJECTS = render-fill-copy.$(OBJEXT)
+render_fill_copy_LDADD = $(LDADD)
+render_fill_copy_DEPENDENCIES = libtest.la
+render_trapezoid_SOURCES = render-trapezoid.c
+render_trapezoid_OBJECTS = render-trapezoid.$(OBJEXT)
+render_trapezoid_LDADD = $(LDADD)
+render_trapezoid_DEPENDENCIES = libtest.la
+render_trapezoid_image_SOURCES = render-trapezoid-image.c
+render_trapezoid_image_OBJECTS = render-trapezoid-image.$(OBJEXT)
+render_trapezoid_image_LDADD = $(LDADD)
+render_trapezoid_image_DEPENDENCIES = libtest.la
+DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
+depcomp = $(SHELL) $(top_srcdir)/depcomp
+am__depfiles_maybe = depfiles
+am__mv = mv -f
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+       $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+       $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \
+       $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
+       $(AM_CFLAGS) $(CFLAGS)
+AM_V_CC = $(am__v_CC_@AM_V@)
+am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@)
+am__v_CC_0 = @echo "  CC    " $@;
+AM_V_at = $(am__v_at_@AM_V@)
+am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
+am__v_at_0 = @
+CCLD = $(CC)
+LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+       $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+       $(AM_LDFLAGS) $(LDFLAGS) -o $@
+AM_V_CCLD = $(am__v_CCLD_@AM_V@)
+am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
+am__v_CCLD_0 = @echo "  CCLD  " $@;
+AM_V_GEN = $(am__v_GEN_@AM_V@)
+am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
+am__v_GEN_0 = @echo "  GEN   " $@;
+SOURCES = $(libtest_la_SOURCES) basic-copyarea.c basic-copyarea-size.c \
+       basic-fillrect.c basic-lines.c basic-putimage.c \
+       basic-rectangle.c basic-stress.c basic-string.c dri2-swap.c \
+       mixed-stress.c render-composite-solid.c \
+       render-copy-alphaless.c render-copyarea.c \
+       render-copyarea-size.c render-fill.c render-fill-copy.c \
+       render-trapezoid.c render-trapezoid-image.c
+DIST_SOURCES = $(libtest_la_SOURCES) basic-copyarea.c \
+       basic-copyarea-size.c basic-fillrect.c basic-lines.c \
+       basic-putimage.c basic-rectangle.c basic-stress.c \
+       basic-string.c dri2-swap.c mixed-stress.c \
+       render-composite-solid.c render-copy-alphaless.c \
+       render-copyarea.c render-copyarea-size.c render-fill.c \
+       render-fill-copy.c render-trapezoid.c render-trapezoid-image.c
+am__can_run_installinfo = \
+  case $$AM_UPDATE_INFO_DIR in \
+    n|no|NO) false;; \
+    *) (install-info --version) >/dev/null 2>&1;; \
+  esac
+ETAGS = etags
+CTAGS = ctags
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+ADMIN_MAN_DIR = @ADMIN_MAN_DIR@
+ADMIN_MAN_SUFFIX = @ADMIN_MAN_SUFFIX@
+AMTAR = @AMTAR@
+AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
+APP_MAN_DIR = @APP_MAN_DIR@
+APP_MAN_SUFFIX = @APP_MAN_SUFFIX@
+AR = @AR@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+BASE_CFLAGS = @BASE_CFLAGS@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CHANGELOG_CMD = @CHANGELOG_CMD@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CWARNFLAGS = @CWARNFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DLLTOOL = @DLLTOOL@
+DRI2_CFLAGS = @DRI2_CFLAGS@
+DRI2_LIBS = @DRI2_LIBS@
+DRIVER_MAN_DIR = @DRIVER_MAN_DIR@
+DRIVER_MAN_SUFFIX = @DRIVER_MAN_SUFFIX@
+DRIVER_NAME = @DRIVER_NAME@
+DRI_CFLAGS = @DRI_CFLAGS@
+DRI_LIBS = @DRI_LIBS@
+DRMINTEL_CFLAGS = @DRMINTEL_CFLAGS@
+DRMINTEL_LIBS = @DRMINTEL_LIBS@
+DRM_CFLAGS = @DRM_CFLAGS@
+DRM_LIBS = @DRM_LIBS@
+DSYMUTIL = @DSYMUTIL@
+DUMPBIN = @DUMPBIN@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+FGREP = @FGREP@
+FILE_MAN_DIR = @FILE_MAN_DIR@
+FILE_MAN_SUFFIX = @FILE_MAN_SUFFIX@
+GEN4ASM_CFLAGS = @GEN4ASM_CFLAGS@
+GEN4ASM_LIBS = @GEN4ASM_LIBS@
+GREP = @GREP@
+INSTALL = @INSTALL@
+INSTALL_CMD = @INSTALL_CMD@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+LD = @LD@
+LDFLAGS = @LDFLAGS@
+LIBGLAMOR_CFLAGS = @LIBGLAMOR_CFLAGS@
+LIBGLAMOR_EGL_CFLAGS = @LIBGLAMOR_EGL_CFLAGS@
+LIBGLAMOR_EGL_LIBS = @LIBGLAMOR_EGL_LIBS@
+LIBGLAMOR_LIBS = @LIBGLAMOR_LIBS@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBTOOL = @LIBTOOL@
+LIB_MAN_DIR = @LIB_MAN_DIR@
+LIB_MAN_SUFFIX = @LIB_MAN_SUFFIX@
+LIPO = @LIPO@
+LN_S = @LN_S@
+LTLIBOBJS = @LTLIBOBJS@
+MAINT = @MAINT@
+MAKEINFO = @MAKEINFO@
+MANIFEST_TOOL = @MANIFEST_TOOL@
+MAN_SUBSTS = @MAN_SUBSTS@
+MISC_MAN_DIR = @MISC_MAN_DIR@
+MISC_MAN_SUFFIX = @MISC_MAN_SUFFIX@
+MKDIR_P = @MKDIR_P@
+NM = @NM@
+NMEDIT = @NMEDIT@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+OTOOL = @OTOOL@
+OTOOL64 = @OTOOL64@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_URL = @PACKAGE_URL@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PCIACCESS_CFLAGS = @PCIACCESS_CFLAGS@
+PCIACCESS_LIBS = @PCIACCESS_LIBS@
+PKG_CONFIG = @PKG_CONFIG@
+PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
+PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
+RANLIB = @RANLIB@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STRICT_CFLAGS = @STRICT_CFLAGS@
+STRIP = @STRIP@
+UDEV_CFLAGS = @UDEV_CFLAGS@
+UDEV_LIBS = @UDEV_LIBS@
+VALGRIND_CFLAGS = @VALGRIND_CFLAGS@
+VALGRIND_LIBS = @VALGRIND_LIBS@
+VERSION = @VERSION@
+X11_CFLAGS = @X11_CFLAGS@
+X11_LIBS = @X11_LIBS@
+XORG_CFLAGS = @XORG_CFLAGS@
+XORG_LIBS = @XORG_LIBS@
+XORG_MAN_PAGE = @XORG_MAN_PAGE@
+XVMCLIB_CFLAGS = @XVMCLIB_CFLAGS@
+XVMCLIB_LIBS = @XVMCLIB_LIBS@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_AR = @ac_ct_AR@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+moduledir = @moduledir@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+stress_TESTS = \
+       basic-fillrect \
+       basic-rectangle \
+       basic-string \
+       basic-copyarea \
+       basic-copyarea-size \
+       basic-putimage \
+       basic-lines \
+       basic-stress \
+       render-fill \
+       render-trapezoid \
+       render-trapezoid-image \
+       render-fill-copy \
+       render-composite-solid \
+       render-copyarea \
+       render-copyarea-size \
+       render-copy-alphaless \
+       mixed-stress \
+       dri2-swap \
+       $(NULL)
+
+AM_CFLAGS = @CWARNFLAGS@ @X11_CFLAGS@ @DRM_CFLAGS@
+LDADD = libtest.la @X11_LIBS@ -lXfixes @DRM_LIBS@ -lrt
+noinst_LTLIBRARIES = libtest.la
+libtest_la_SOURCES = \
+       test.h \
+       test_display.c \
+       test_image.c \
+       test_log.c \
+       test_render.c \
+       dri2.c \
+       dri2.h \
+       $(NULL)
+
+EXTRA_DIST = README
+all: all-am
+
+.SUFFIXES:
+.SUFFIXES: .c .lo .o .obj
+$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am  $(am__configure_deps)
+       @for dep in $?; do \
+         case '$(am__configure_deps)' in \
+           *$$dep*) \
+             ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+               && { if test -f $@; then exit 0; else break; fi; }; \
+             exit 1;; \
+         esac; \
+       done; \
+       echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign test/Makefile'; \
+       $(am__cd) $(top_srcdir) && \
+         $(AUTOMAKE) --foreign test/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+       @case '$?' in \
+         *config.status*) \
+           cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+         *) \
+           echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+           cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+       esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+       cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
+       cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
+       cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+
+clean-noinstLTLIBRARIES:
+       -test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES)
+       @list='$(noinst_LTLIBRARIES)'; for p in $$list; do \
+         dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \
+         test "$$dir" != "$$p" || dir=.; \
+         echo "rm -f \"$${dir}/so_locations\""; \
+         rm -f "$${dir}/so_locations"; \
+       done
+libtest.la: $(libtest_la_OBJECTS) $(libtest_la_DEPENDENCIES) $(EXTRA_libtest_la_DEPENDENCIES) 
+       $(AM_V_CCLD)$(LINK)  $(libtest_la_OBJECTS) $(libtest_la_LIBADD) $(LIBS)
+
+clean-checkPROGRAMS:
+       @list='$(check_PROGRAMS)'; test -n "$$list" || exit 0; \
+       echo " rm -f" $$list; \
+       rm -f $$list || exit $$?; \
+       test -n "$(EXEEXT)" || exit 0; \
+       list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \
+       echo " rm -f" $$list; \
+       rm -f $$list
+basic-copyarea$(EXEEXT): $(basic_copyarea_OBJECTS) $(basic_copyarea_DEPENDENCIES) $(EXTRA_basic_copyarea_DEPENDENCIES) 
+       @rm -f basic-copyarea$(EXEEXT)
+       $(AM_V_CCLD)$(LINK) $(basic_copyarea_OBJECTS) $(basic_copyarea_LDADD) $(LIBS)
+basic-copyarea-size$(EXEEXT): $(basic_copyarea_size_OBJECTS) $(basic_copyarea_size_DEPENDENCIES) $(EXTRA_basic_copyarea_size_DEPENDENCIES) 
+       @rm -f basic-copyarea-size$(EXEEXT)
+       $(AM_V_CCLD)$(LINK) $(basic_copyarea_size_OBJECTS) $(basic_copyarea_size_LDADD) $(LIBS)
+basic-fillrect$(EXEEXT): $(basic_fillrect_OBJECTS) $(basic_fillrect_DEPENDENCIES) $(EXTRA_basic_fillrect_DEPENDENCIES) 
+       @rm -f basic-fillrect$(EXEEXT)
+       $(AM_V_CCLD)$(LINK) $(basic_fillrect_OBJECTS) $(basic_fillrect_LDADD) $(LIBS)
+basic-lines$(EXEEXT): $(basic_lines_OBJECTS) $(basic_lines_DEPENDENCIES) $(EXTRA_basic_lines_DEPENDENCIES) 
+       @rm -f basic-lines$(EXEEXT)
+       $(AM_V_CCLD)$(LINK) $(basic_lines_OBJECTS) $(basic_lines_LDADD) $(LIBS)
+basic-putimage$(EXEEXT): $(basic_putimage_OBJECTS) $(basic_putimage_DEPENDENCIES) $(EXTRA_basic_putimage_DEPENDENCIES) 
+       @rm -f basic-putimage$(EXEEXT)
+       $(AM_V_CCLD)$(LINK) $(basic_putimage_OBJECTS) $(basic_putimage_LDADD) $(LIBS)
+basic-rectangle$(EXEEXT): $(basic_rectangle_OBJECTS) $(basic_rectangle_DEPENDENCIES) $(EXTRA_basic_rectangle_DEPENDENCIES) 
+       @rm -f basic-rectangle$(EXEEXT)
+       $(AM_V_CCLD)$(LINK) $(basic_rectangle_OBJECTS) $(basic_rectangle_LDADD) $(LIBS)
+basic-stress$(EXEEXT): $(basic_stress_OBJECTS) $(basic_stress_DEPENDENCIES) $(EXTRA_basic_stress_DEPENDENCIES) 
+       @rm -f basic-stress$(EXEEXT)
+       $(AM_V_CCLD)$(LINK) $(basic_stress_OBJECTS) $(basic_stress_LDADD) $(LIBS)
+basic-string$(EXEEXT): $(basic_string_OBJECTS) $(basic_string_DEPENDENCIES) $(EXTRA_basic_string_DEPENDENCIES) 
+       @rm -f basic-string$(EXEEXT)
+       $(AM_V_CCLD)$(LINK) $(basic_string_OBJECTS) $(basic_string_LDADD) $(LIBS)
+dri2-swap$(EXEEXT): $(dri2_swap_OBJECTS) $(dri2_swap_DEPENDENCIES) $(EXTRA_dri2_swap_DEPENDENCIES) 
+       @rm -f dri2-swap$(EXEEXT)
+       $(AM_V_CCLD)$(LINK) $(dri2_swap_OBJECTS) $(dri2_swap_LDADD) $(LIBS)
+mixed-stress$(EXEEXT): $(mixed_stress_OBJECTS) $(mixed_stress_DEPENDENCIES) $(EXTRA_mixed_stress_DEPENDENCIES) 
+       @rm -f mixed-stress$(EXEEXT)
+       $(AM_V_CCLD)$(LINK) $(mixed_stress_OBJECTS) $(mixed_stress_LDADD) $(LIBS)
+render-composite-solid$(EXEEXT): $(render_composite_solid_OBJECTS) $(render_composite_solid_DEPENDENCIES) $(EXTRA_render_composite_solid_DEPENDENCIES) 
+       @rm -f render-composite-solid$(EXEEXT)
+       $(AM_V_CCLD)$(LINK) $(render_composite_solid_OBJECTS) $(render_composite_solid_LDADD) $(LIBS)
+render-copy-alphaless$(EXEEXT): $(render_copy_alphaless_OBJECTS) $(render_copy_alphaless_DEPENDENCIES) $(EXTRA_render_copy_alphaless_DEPENDENCIES) 
+       @rm -f render-copy-alphaless$(EXEEXT)
+       $(AM_V_CCLD)$(LINK) $(render_copy_alphaless_OBJECTS) $(render_copy_alphaless_LDADD) $(LIBS)
+render-copyarea$(EXEEXT): $(render_copyarea_OBJECTS) $(render_copyarea_DEPENDENCIES) $(EXTRA_render_copyarea_DEPENDENCIES) 
+       @rm -f render-copyarea$(EXEEXT)
+       $(AM_V_CCLD)$(LINK) $(render_copyarea_OBJECTS) $(render_copyarea_LDADD) $(LIBS)
+render-copyarea-size$(EXEEXT): $(render_copyarea_size_OBJECTS) $(render_copyarea_size_DEPENDENCIES) $(EXTRA_render_copyarea_size_DEPENDENCIES) 
+       @rm -f render-copyarea-size$(EXEEXT)
+       $(AM_V_CCLD)$(LINK) $(render_copyarea_size_OBJECTS) $(render_copyarea_size_LDADD) $(LIBS)
+render-fill$(EXEEXT): $(render_fill_OBJECTS) $(render_fill_DEPENDENCIES) $(EXTRA_render_fill_DEPENDENCIES) 
+       @rm -f render-fill$(EXEEXT)
+       $(AM_V_CCLD)$(LINK) $(render_fill_OBJECTS) $(render_fill_LDADD) $(LIBS)
+render-fill-copy$(EXEEXT): $(render_fill_copy_OBJECTS) $(render_fill_copy_DEPENDENCIES) $(EXTRA_render_fill_copy_DEPENDENCIES) 
+       @rm -f render-fill-copy$(EXEEXT)
+       $(AM_V_CCLD)$(LINK) $(render_fill_copy_OBJECTS) $(render_fill_copy_LDADD) $(LIBS)
+render-trapezoid$(EXEEXT): $(render_trapezoid_OBJECTS) $(render_trapezoid_DEPENDENCIES) $(EXTRA_render_trapezoid_DEPENDENCIES) 
+       @rm -f render-trapezoid$(EXEEXT)
+       $(AM_V_CCLD)$(LINK) $(render_trapezoid_OBJECTS) $(render_trapezoid_LDADD) $(LIBS)
+render-trapezoid-image$(EXEEXT): $(render_trapezoid_image_OBJECTS) $(render_trapezoid_image_DEPENDENCIES) $(EXTRA_render_trapezoid_image_DEPENDENCIES) 
+       @rm -f render-trapezoid-image$(EXEEXT)
+       $(AM_V_CCLD)$(LINK) $(render_trapezoid_image_OBJECTS) $(render_trapezoid_image_LDADD) $(LIBS)
+
+mostlyclean-compile:
+       -rm -f *.$(OBJEXT)
+
+distclean-compile:
+       -rm -f *.tab.c
+
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/basic-copyarea-size.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/basic-copyarea.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/basic-fillrect.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/basic-lines.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/basic-putimage.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/basic-rectangle.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/basic-stress.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/basic-string.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dri2-swap.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dri2.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mixed-stress.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/render-composite-solid.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/render-copy-alphaless.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/render-copyarea-size.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/render-copyarea.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/render-fill-copy.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/render-fill.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/render-trapezoid-image.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/render-trapezoid.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_display.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_image.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_log.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_render.Plo@am__quote@
+
+.c.o:
+@am__fastdepCC_TRUE@   $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(COMPILE) -c $<
+
+.c.obj:
+@am__fastdepCC_TRUE@   $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+@am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(COMPILE) -c `$(CYGPATH_W) '$<'`
+
+.c.lo:
+@am__fastdepCC_TRUE@   $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $<
+
+mostlyclean-libtool:
+       -rm -f *.lo
+
+clean-libtool:
+       -rm -rf .libs _libs
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+       list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+       unique=`for i in $$list; do \
+           if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+         done | \
+         $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+             END { if (nonempty) { for (i in files) print i; }; }'`; \
+       mkid -fID $$unique
+tags: TAGS
+
+TAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+               $(TAGS_FILES) $(LISP)
+       set x; \
+       here=`pwd`; \
+       list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+       unique=`for i in $$list; do \
+           if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+         done | \
+         $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+             END { if (nonempty) { for (i in files) print i; }; }'`; \
+       shift; \
+       if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
+         test -n "$$unique" || unique=$$empty_fix; \
+         if test $$# -gt 0; then \
+           $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+             "$$@" $$unique; \
+         else \
+           $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+             $$unique; \
+         fi; \
+       fi
+ctags: CTAGS
+CTAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+               $(TAGS_FILES) $(LISP)
+       list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+       unique=`for i in $$list; do \
+           if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+         done | \
+         $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+             END { if (nonempty) { for (i in files) print i; }; }'`; \
+       test -z "$(CTAGS_ARGS)$$unique" \
+         || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+            $$unique
+
+GTAGS:
+       here=`$(am__cd) $(top_builddir) && pwd` \
+         && $(am__cd) $(top_srcdir) \
+         && gtags -i $(GTAGS_ARGS) "$$here"
+
+distclean-tags:
+       -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+distdir: $(DISTFILES)
+       @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+       topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+       list='$(DISTFILES)'; \
+         dist_files=`for file in $$list; do echo $$file; done | \
+         sed -e "s|^$$srcdirstrip/||;t" \
+             -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+       case $$dist_files in \
+         */*) $(MKDIR_P) `echo "$$dist_files" | \
+                          sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+                          sort -u` ;; \
+       esac; \
+       for file in $$dist_files; do \
+         if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+         if test -d $$d/$$file; then \
+           dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+           if test -d "$(distdir)/$$file"; then \
+             find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+           fi; \
+           if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+             cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+             find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+           fi; \
+           cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+         else \
+           test -f "$(distdir)/$$file" \
+           || cp -p $$d/$$file "$(distdir)/$$file" \
+           || exit 1; \
+         fi; \
+       done
+check-am: all-am
+       $(MAKE) $(AM_MAKEFLAGS) $(check_PROGRAMS)
+check: check-am
+all-am: Makefile $(LTLIBRARIES)
+installdirs:
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+       @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+       if test -z '$(STRIP)'; then \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+             install; \
+       else \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+           "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+       fi
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+       -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+       -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+
+maintainer-clean-generic:
+       @echo "This command is intended for maintainers to use"
+       @echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-checkPROGRAMS clean-generic clean-libtool \
+       clean-noinstLTLIBRARIES mostlyclean-am
+
+distclean: distclean-am
+       -rm -rf ./$(DEPDIR)
+       -rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+       distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+html-am:
+
+info: info-am
+
+info-am:
+
+install-data-am:
+
+install-dvi: install-dvi-am
+
+install-dvi-am:
+
+install-exec-am:
+
+install-html: install-html-am
+
+install-html-am:
+
+install-info: install-info-am
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-am
+
+install-pdf-am:
+
+install-ps: install-ps-am
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+       -rm -rf ./$(DEPDIR)
+       -rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+       mostlyclean-libtool
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am:
+
+.MAKE: check-am install-am install-strip
+
+.PHONY: CTAGS GTAGS all all-am check check-am clean \
+       clean-checkPROGRAMS clean-generic clean-libtool \
+       clean-noinstLTLIBRARIES ctags distclean distclean-compile \
+       distclean-generic distclean-libtool distclean-tags distdir dvi \
+       dvi-am html html-am info info-am install install-am \
+       install-data install-data-am install-dvi install-dvi-am \
+       install-exec install-exec-am install-html install-html-am \
+       install-info install-info-am install-man install-pdf \
+       install-pdf-am install-ps install-ps-am install-strip \
+       installcheck installcheck-am installdirs maintainer-clean \
+       maintainer-clean-generic mostlyclean mostlyclean-compile \
+       mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
+       tags uninstall uninstall-am
+
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/test/README b/test/README
new file mode 100644 (file)
index 0000000..72b4450
--- /dev/null
@@ -0,0 +1,3 @@
+These are no substitute for xts, rendercheck and cairo-test-suite. They
+are intended to exercise corner cases in the batch management of long
+drawing commands and more explicit checking of the acceleration paths.
diff --git a/test/basic-copyarea-size.c b/test/basic-copyarea-size.c
new file mode 100644 (file)
index 0000000..732bb81
--- /dev/null
@@ -0,0 +1,104 @@
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <X11/Xutil.h> /* for XDestroyImage */
+
+#include "test.h"
+
+#define SIZE 20000
+struct draw {
+       Pixmap a, b;
+       GC gc;
+       XRenderPictFormat *format;
+};
+
+static void target_init(struct test_display *t, struct draw *tt, int size)
+{
+       XGCValues val;
+
+       tt->a = XCreatePixmap(t->dpy, DefaultRootWindow(t->dpy),
+                             size, size, 32);
+       tt->b = XCreatePixmap(t->dpy, DefaultRootWindow(t->dpy),
+                             size, size, 32);
+
+       val.graphics_exposures = 0;
+       tt->gc = XCreateGC(t->dpy, tt->a, GCGraphicsExposures, &val);
+
+       tt->format = XRenderFindStandardFormat(t->dpy, PictStandardARGB32);
+
+       val.foreground = 0xffff0000;
+       XChangeGC(t->dpy, tt->gc, GCForeground, &val);
+       XFillRectangle(t->dpy, tt->a, tt->gc, 0, 0, size, size);
+
+       val.foreground = 0xff0000ff;
+       XChangeGC(t->dpy, tt->gc, GCForeground, &val);
+       XFillRectangle(t->dpy, tt->b, tt->gc, 0, 0, size, size);
+}
+
+static void target_fini(struct test_display *t, struct draw *tt)
+{
+       XFreePixmap(t->dpy, tt->a);
+       XFreePixmap(t->dpy, tt->b);
+}
+
+int main(int argc, char **argv)
+{
+       struct test test;
+       struct draw real, ref;
+       int size, i;
+
+       test_init(&test, argc, argv);
+
+       /* Copy back and forth betwenn two pixmaps, gradually getting larger */
+       for (size = 1; size <= SIZE; size = (size * 3 + 1) / 2) {
+               target_init(&test.real, &real, size);
+               target_init(&test.ref, &ref, size);
+
+               printf("size=%d\n", size);
+               for (i = 0; i <= DEFAULT_ITERATIONS; i++) {
+                       int reps = 1 << i;
+                       do {
+                               int sx = rand() % (2*size) - size;
+                               int sy = rand() % (2*size) - size;
+
+                               int dx = rand() % (2*size) - size;
+                               int dy = rand() % (2*size) - size;
+
+                               int order = rand() & 1;
+
+                               XCopyArea(test.real.dpy,
+                                         order ? real.a : real.b,
+                                         (!order) ? real.a : real.b,
+                                         real.gc,
+                                         sx, sy,
+                                         size, size,
+                                         dx, dy);
+
+                               XCopyArea(test.ref.dpy,
+                                         order ? ref.a : ref.b,
+                                         (!order) ? ref.a : ref.b,
+                                         ref.gc,
+                                         sx, sy,
+                                         size, size,
+                                         dx, dy);
+                       } while (--reps);
+               }
+
+               test_compare(&test,
+                            real.a, real.format,
+                            ref.a, ref.format,
+                            0, 0, size, size,
+                            "");
+               test_compare(&test,
+                            real.b, real.format,
+                            ref.b, ref.format,
+                            0, 0, size, size,
+                            "");
+
+               target_fini(&test.real, &real);
+               target_fini(&test.ref, &ref);
+       }
+
+       return 0;
+}
diff --git a/test/basic-copyarea.c b/test/basic-copyarea.c
new file mode 100644 (file)
index 0000000..025b884
--- /dev/null
@@ -0,0 +1,302 @@
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <X11/Xutil.h> /* for XDestroyImage */
+#include <pixman.h> /* for pixman blt functions */
+
+#include "test.h"
+
+static void
+show_cells(char *buf,
+          const uint32_t *real, const uint32_t *ref,
+          int x, int y, int w, int h)
+{
+       int i, j, len = 0;
+
+       for (j = y - 2; j <= y + 2; j++) {
+               if (j < 0 || j >= h)
+                       continue;
+
+               for (i = x - 2; i <= x + 2; i++) {
+                       if (i < 0 || i >= w)
+                               continue;
+
+                       len += sprintf(buf+len, "%08x ", real[j*w+i]);
+               }
+
+               len += sprintf(buf+len, "\t");
+
+               for (i = x - 2; i <= x + 2; i++) {
+                       if (i < 0 || i >= w)
+                               continue;
+
+                       len += sprintf(buf+len, "%08x ", ref[j*w+i]);
+               }
+
+               len += sprintf(buf+len, "\n");
+       }
+}
+
+static void fill_rect(struct test_display *t,
+                     Drawable d,
+                     XRenderPictFormat *format,
+                     int use_window, int tx, int ty,
+                     uint8_t alu, int x, int y, int w, int h, uint32_t fg)
+{
+       XGCValues val;
+       Drawable tmp;
+       GC gc;
+
+       val.graphics_exposures = 0;
+       val.function = alu;
+       val.foreground = fg;
+
+       if (use_window) {
+               XSetWindowAttributes attr;
+
+               attr.override_redirect = 1;
+               tmp = XCreateWindow(t->dpy, DefaultRootWindow(t->dpy),
+                                   tx, ty,
+                                   w, h,
+                                   0, format->depth,
+                                   InputOutput,
+                                   DefaultVisual(t->dpy,
+                                                 DefaultScreen(t->dpy)),
+                                   CWOverrideRedirect, &attr);
+               XMapWindow(t->dpy, tmp);
+       } else
+               tmp = XCreatePixmap(t->dpy, d, w, h, format->depth);
+
+       gc = XCreateGC(t->dpy, d, GCGraphicsExposures | GCForeground, &val);
+       XFillRectangle(t->dpy, tmp, gc, 0, 0, w, h);
+
+       XChangeGC(t->dpy, gc, GCFunction, &val);
+       XCopyArea(t->dpy, tmp, d, gc, 0, 0, w, h, x, y);
+
+       XFreeGC(t->dpy, gc);
+       if (use_window)
+               XDestroyWindow(t->dpy, tmp);
+       else
+               XFreePixmap(t->dpy, tmp);
+}
+
+static void pixel_tests(struct test *t, int reps, int sets, enum target target)
+{
+       struct test_target tt;
+       XImage image;
+       uint32_t *cells = malloc(t->real.width*t->real.height*4);
+       struct {
+               uint16_t x, y;
+       } *pixels = malloc(reps*sizeof(*pixels));
+       int r, s;
+
+       test_target_create_render(&t->real, target, &tt);
+
+       printf("Testing setting of single pixels (%s): ",
+              test_target_name(target));
+       fflush(stdout);
+
+       for (s = 0; s < sets; s++) {
+               for (r = 0; r < reps; r++) {
+                       int x = rand() % (tt.width - 1);
+                       int y = rand() % (tt.height - 1);
+                       uint32_t fg = rand();
+
+                       fill_rect(&t->real, tt.draw, tt.format,
+                                 0, 0, 0,
+                                 GXcopy, x, y, 1, 1, fg);
+
+                       pixels[r].x = x;
+                       pixels[r].y = y;
+                       cells[y*tt.width+x] = fg;
+               }
+
+               test_init_image(&image, &t->real.shm, tt.format, 1, 1);
+
+               for (r = 0; r < reps; r++) {
+                       uint32_t x = pixels[r].x;
+                       uint32_t y = pixels[r].y;
+                       uint32_t result;
+
+                       XShmGetImage(t->real.dpy, tt.draw, &image,
+                                    x, y, AllPlanes);
+
+                       result = *(uint32_t *)image.data;
+                       if (!pixel_equal(image.depth, result,
+                                        cells[y*tt.width+x])) {
+                               uint32_t mask = depth_mask(image.depth);
+
+                               die("failed to set pixel (%d,%d) to %08x [%08x], found %08x [%08x] instead\n",
+                                   x, y,
+                                   cells[y*tt.width+x] & mask,
+                                   cells[y*tt.width+x],
+                                   result & mask,
+                                   result);
+                       }
+               }
+       }
+       printf("passed [%d iterations x %d]\n", reps, sets);
+
+       test_target_destroy_render(&t->real, &tt);
+       free(pixels);
+       free(cells);
+}
+
+static void clear(struct test_display *dpy, struct test_target *tt)
+{
+       XRenderColor render_color = {0};
+       XRenderFillRectangle(dpy->dpy, PictOpClear, tt->picture, &render_color,
+                            0, 0, tt->width, tt->height);
+}
+
+static void area_tests(struct test *t, int reps, int sets, enum target target)
+{
+       struct test_target tt;
+       XImage image;
+       uint32_t *cells = calloc(sizeof(uint32_t), t->real.width*t->real.height);
+       int r, s, x, y;
+
+       printf("Testing area sets (%s): ", test_target_name(target));
+       fflush(stdout);
+
+       test_target_create_render(&t->real, target, &tt);
+       clear(&t->real, &tt);
+
+       test_init_image(&image, &t->real.shm, tt.format, tt.width, tt.height);
+
+       for (s = 0; s < sets; s++) {
+               for (r = 0; r < reps; r++) {
+                       int w = 1 + rand() % (tt.width - 1);
+                       int h = 1 + rand() % (tt.height - 1);
+                       uint32_t fg = rand();
+
+                       x = rand() % (2*tt.width) - tt.width;
+                       y = rand() % (2*tt.height) - tt.height;
+
+                       fill_rect(&t->real, tt.draw, tt.format,
+                                 0, 0, 0,
+                                 GXcopy, x, y, w, h, fg);
+
+                       if (x < 0)
+                               w += x, x = 0;
+                       if (y < 0)
+                               h += y, y = 0;
+                       if (x >= tt.width || y >= tt.height)
+                               continue;
+
+                       if (x + w > tt.width)
+                               w = tt.width - x;
+                       if (y + h > tt.height)
+                               h = tt.height - y;
+                       if (w <= 0 || h <= 0)
+                               continue;
+
+                       pixman_fill(cells, tt.width, 32, x, y, w, h, fg);
+               }
+
+               XShmGetImage(t->real.dpy, tt.draw, &image, 0, 0, AllPlanes);
+
+               for (y = 0; y < tt.height; y++) {
+                       for (x = 0; x < tt.width; x++) {
+                               uint32_t result = *(uint32_t *)
+                                       (image.data +
+                                        y*image.bytes_per_line +
+                                        x*image.bits_per_pixel/8);
+                               if (!pixel_equal(image.depth, result, cells[y*tt.width+x])) {
+                                       char buf[600];
+                                       uint32_t mask = depth_mask(image.depth);
+                                       show_cells(buf,
+                                                  (uint32_t*)image.data, cells,
+                                                  x, y, tt.width, tt.height);
+
+                                       die("failed to set pixel (%d,%d) to %08x [%08x], found %08x [%08x] instead\n%s",
+                                           x, y,
+                                           cells[y*tt.width+x] & mask,
+                                           cells[y*tt.width+x],
+                                           result & mask,
+                                           result, buf);
+                               }
+                       }
+               }
+       }
+
+       printf("passed [%d iterations x %d]\n", reps, sets);
+
+       test_target_destroy_render(&t->real, &tt);
+       free(cells);
+}
+
+static void rect_tests(struct test *t, int reps, int sets, enum target target, int use_window)
+{
+       struct test_target real, ref;
+       int r, s;
+
+       printf("Testing area fills (%s, using %s source): ",
+              test_target_name(target), use_window ? "window" : "pixmap");
+       fflush(stdout);
+
+       test_target_create_render(&t->real, target, &real);
+       clear(&t->real, &real);
+
+       test_target_create_render(&t->ref, target, &ref);
+       clear(&t->ref, &ref);
+
+       for (s = 0; s < sets; s++) {
+               for (r = 0; r < reps; r++) {
+                       int x = rand() % (real.width - 1);
+                       int y = rand() % (real.height - 1);
+                       int w = 1 + rand() % (real.width - x - 1);
+                       int h = 1 + rand() % (real.height - y - 1);
+                       int tmpx = w == real.width ? 0 : rand() % (real.width - w);
+                       int tmpy = h == real.height ? 0 : rand() % (real.height - h);
+                       uint8_t alu = rand() % (GXset + 1);
+                       uint32_t fg = rand();
+
+                       fill_rect(&t->real, real.draw, real.format,
+                                 use_window, tmpx, tmpy,
+                                 alu, x, y, w, h, fg);
+                       fill_rect(&t->ref, ref.draw, ref.format,
+                                 use_window, tmpx, tmpy,
+                                 alu, x, y, w, h, fg);
+               }
+
+               test_compare(t,
+                            real.draw, real.format,
+                            ref.draw, ref.format,
+                            0, 0, real.width, real.height,
+                            "");
+       }
+
+       printf("passed [%d iterations x %d]\n", reps, sets);
+
+       test_target_destroy_render(&t->real, &real);
+       test_target_destroy_render(&t->ref, &ref);
+}
+
+int main(int argc, char **argv)
+{
+       struct test test;
+       int i;
+
+       test_init(&test, argc, argv);
+
+       for (i = 0; i <= DEFAULT_ITERATIONS; i++) {
+               int reps = 1 << i;
+               int sets = 1 << (12 - i);
+               enum target t;
+
+               if (sets < 2)
+                       sets = 2;
+
+               for (t = TARGET_FIRST; t <= TARGET_LAST; t++) {
+                       pixel_tests(&test, reps, sets, t);
+                       area_tests(&test, reps, sets, t);
+                       rect_tests(&test, reps, sets, t, 0);
+                       if (t != PIXMAP)
+                           rect_tests(&test, reps, sets, t, 1);
+               }
+       }
+
+       return 0;
+}
diff --git a/test/basic-fillrect.c b/test/basic-fillrect.c
new file mode 100644 (file)
index 0000000..67d7067
--- /dev/null
@@ -0,0 +1,264 @@
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <X11/Xutil.h> /* for XDestroyImage */
+#include <pixman.h> /* for pixman blt functions */
+
+#include "test.h"
+
+static void
+show_cells(char *buf,
+          const uint32_t *real, const uint32_t *ref,
+          int x, int y, int w, int h)
+{
+       int i, j, len = 0;
+
+       for (j = y - 2; j <= y + 2; j++) {
+               if (j < 0 || j >= h)
+                       continue;
+
+               for (i = x - 2; i <= x + 2; i++) {
+                       if (i < 0 || i >= w)
+                               continue;
+
+                       len += sprintf(buf+len, "%08x ", real[j*w+i]);
+               }
+
+               len += sprintf(buf+len, "\t");
+
+               for (i = x - 2; i <= x + 2; i++) {
+                       if (i < 0 || i >= w)
+                               continue;
+
+                       len += sprintf(buf+len, "%08x ", ref[j*w+i]);
+               }
+
+               len += sprintf(buf+len, "\n");
+       }
+}
+
+static void fill_rect(struct test_display *t, Drawable d, uint8_t alu,
+                     int x, int y, int w, int h, uint32_t fg)
+{
+       XGCValues val;
+       GC gc;
+
+       val.function = alu;
+       val.foreground = fg;
+
+       gc = XCreateGC(t->dpy, d, GCForeground | GCFunction, &val);
+       XFillRectangle(t->dpy, d, gc, x, y, w, h);
+       XFreeGC(t->dpy, gc);
+}
+
+static void pixel_tests(struct test *t, int reps, int sets, enum target target)
+{
+       struct test_target tt;
+       XImage image;
+       uint32_t *cells = malloc(t->real.width*t->real.height*4);
+       struct {
+               uint16_t x, y;
+       } *pixels = malloc(reps*sizeof(*pixels));
+       int r, s;
+
+       test_target_create_render(&t->real, target, &tt);
+
+       printf("Testing setting of single pixels (%s): ",
+              test_target_name(target));
+       fflush(stdout);
+
+       for (s = 0; s < sets; s++) {
+               for (r = 0; r < reps; r++) {
+                       int x = rand() % (tt.width - 1);
+                       int y = rand() % (tt.height - 1);
+                       uint32_t fg = rand();
+
+                       fill_rect(&t->real, tt.draw, GXcopy,
+                                 x, y, 1, 1, fg);
+
+                       pixels[r].x = x;
+                       pixels[r].y = y;
+                       cells[y*tt.width+x] = fg;
+               }
+
+               test_init_image(&image, &t->real.shm, tt.format, 1, 1);
+
+               for (r = 0; r < reps; r++) {
+                       uint32_t x = pixels[r].x;
+                       uint32_t y = pixels[r].y;
+                       uint32_t result;
+
+                       XShmGetImage(t->real.dpy, tt.draw, &image,
+                                    x, y, AllPlanes);
+
+                       result = *(uint32_t *)image.data;
+                       if (!pixel_equal(image.depth, result,
+                                        cells[y*tt.width+x])) {
+                               uint32_t mask = depth_mask(image.depth);
+
+                               die("failed to set pixel (%d,%d) to %08x [%08x], found %08x [%08x] instead\n",
+                                   x, y,
+                                   cells[y*tt.width+x] & mask,
+                                   cells[y*tt.width+x],
+                                   result & mask,
+                                   result);
+                       }
+               }
+       }
+       printf("passed [%d iterations x %d]\n", reps, sets);
+
+       test_target_destroy_render(&t->real, &tt);
+       free(pixels);
+       free(cells);
+}
+
+static void clear(struct test_display *dpy, struct test_target *tt)
+{
+       XRenderColor render_color = {0};
+       XRenderFillRectangle(dpy->dpy, PictOpClear, tt->picture, &render_color,
+                            0, 0, tt->width, tt->height);
+}
+
+static void area_tests(struct test *t, int reps, int sets, enum target target)
+{
+       struct test_target tt;
+       XImage image;
+       uint32_t *cells = calloc(sizeof(uint32_t), t->real.width*t->real.height);
+       int r, s, x, y;
+
+       printf("Testing area sets (%s): ", test_target_name(target));
+       fflush(stdout);
+
+       test_target_create_render(&t->real, target, &tt);
+       clear(&t->real, &tt);
+
+       test_init_image(&image, &t->real.shm, tt.format, tt.width, tt.height);
+
+       for (s = 0; s < sets; s++) {
+               for (r = 0; r < reps; r++) {
+                       int w = rand() % tt.width;
+                       int h = rand() % tt.height;
+                       uint32_t fg = rand();
+
+                       x = rand() % (2*tt.width) - tt.width;
+                       y = rand() % (2*tt.height) - tt.height;
+
+                       fill_rect(&t->real, tt.draw, GXcopy,
+                                 x, y, w, h, fg);
+
+                       if (x < 0)
+                               w += x, x = 0;
+                       if (y < 0)
+                               h += y, y = 0;
+                       if (x >= tt.width || y >= tt.height)
+                               continue;
+
+                       if (x + w > tt.width)
+                               w = tt.width - x;
+                       if (y + h > tt.height)
+                               h = tt.height - y;
+                       if (w <= 0 || h <= 0)
+                               continue;
+
+                       pixman_fill(cells, tt.width, 32, x, y, w, h, fg);
+               }
+
+               XShmGetImage(t->real.dpy, tt.draw, &image, 0, 0, AllPlanes);
+
+               for (y = 0; y < tt.height; y++) {
+                       for (x = 0; x < tt.width; x++) {
+                               uint32_t result = *(uint32_t *)
+                                       (image.data +
+                                        y*image.bytes_per_line +
+                                        x*image.bits_per_pixel/8);
+                               if (!pixel_equal(image.depth, result, cells[y*tt.width+x])) {
+                                       char buf[600];
+                                       uint32_t mask = depth_mask(image.depth);
+                                       show_cells(buf,
+                                                  (uint32_t*)image.data, cells,
+                                                  x, y, tt.width, tt.height);
+
+                                       die("failed to set pixel (%d,%d) to %08x [%08x], found %08x [%08x] instead\n%s",
+                                           x, y,
+                                           cells[y*tt.width+x] & mask,
+                                           cells[y*tt.width+x],
+                                           result & mask,
+                                           result, buf);
+                               }
+                       }
+               }
+       }
+
+       printf("passed [%d iterations x %d]\n", reps, sets);
+
+       test_target_destroy_render(&t->real, &tt);
+       free(cells);
+}
+
+static void rect_tests(struct test *t, int reps, int sets, enum target target)
+{
+       struct test_target real, ref;
+       int r, s;
+
+       printf("Testing area fills (%s): ", test_target_name(target));
+       fflush(stdout);
+
+       test_target_create_render(&t->real, target, &real);
+       clear(&t->real, &real);
+
+       test_target_create_render(&t->ref, target, &ref);
+       clear(&t->ref, &ref);
+
+       for (s = 0; s < sets; s++) {
+               for (r = 0; r < reps; r++) {
+                       int x = rand() % (2*real.width) - real.width;
+                       int y = rand() % (2*real.height) - real.height;
+                       int w = rand() % (2*real.width);
+                       int h = rand() % (2*real.height);
+                       uint8_t alu = rand() % (GXset + 1);
+                       uint32_t fg = rand();
+
+                       fill_rect(&t->real, real.draw, alu,
+                                 x, y, w, h, fg);
+                       fill_rect(&t->ref, ref.draw, alu,
+                                 x, y, w, h, fg);
+               }
+
+               test_compare(t,
+                            real.draw, real.format,
+                            ref.draw, ref.format,
+                            0, 0, real.width, real.height,
+                            "");
+       }
+
+       printf("passed [%d iterations x %d]\n", reps, sets);
+
+       test_target_destroy_render(&t->real, &real);
+       test_target_destroy_render(&t->ref, &ref);
+}
+
+int main(int argc, char **argv)
+{
+       struct test test;
+       int i;
+
+       test_init(&test, argc, argv);
+
+       for (i = 0; i <= DEFAULT_ITERATIONS; i++) {
+               int reps = 1 << i;
+               int sets = 1 << (12 - i);
+               enum target t;
+
+               if (sets < 2)
+                       sets = 2;
+
+               for (t = TARGET_FIRST; t <= TARGET_LAST; t++) {
+                       pixel_tests(&test, reps, sets, t);
+                       area_tests(&test, reps, sets, t);
+                       rect_tests(&test, reps, sets, t);
+               }
+       }
+
+       return 0;
+}
diff --git a/test/basic-lines.c b/test/basic-lines.c
new file mode 100644 (file)
index 0000000..b710b24
--- /dev/null
@@ -0,0 +1,147 @@
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <X11/Xutil.h> /* for XDestroyImage */
+#include <pixman.h> /* for pixman blt functions */
+
+#include "test.h"
+
+static const XPoint points[]= {
+       /* top */
+       { 0, 0},
+       { 1, 0},
+       { 2, 0},
+       { 3, 0},
+       { 4, 0},
+       { 5, 0},
+       { 6, 0},
+       { 7, 0},
+       { 8, 0},
+       /* right */
+       { 8, 1},
+       { 8, 2},
+       { 8, 3},
+       { 8, 4},
+       { 8, 5},
+       { 8, 6},
+       { 8, 7},
+       { 8, 8},
+       /* bottom */
+       { 7, 8},
+       { 6, 8},
+       { 5, 8},
+       { 4, 8},
+       { 3, 8},
+       { 2, 8},
+       { 1, 8},
+       { 0, 8},
+       /* left */
+       { 0, 7},
+       { 0, 6},
+       { 0, 5},
+       { 0, 4},
+       { 0, 3},
+       { 0, 2},
+       { 0, 1},
+       { 0, 0} /* and origin again for luck */
+};
+#define NUM_POINTS (sizeof(points)/sizeof(points[0]))
+
+static void clear(struct test_display *dpy, struct test_target *tt)
+{
+       XRenderColor render_color = {0};
+       XRenderFillRectangle(dpy->dpy, PictOpClear, tt->picture, &render_color,
+                            0, 0, tt->width, tt->height);
+}
+
+static void draw_line(struct test_display *dpy, struct test_target *tt,
+                     int alu, int width, int style, int cap,
+                     const XPoint *p1, const XPoint *p2,
+                     int dx, int dy)
+{
+       XGCValues val;
+       GC gc;
+
+       val.function = GXcopy;
+       val.foreground = WhitePixel(dpy->dpy, 0);
+       val.line_width = width;
+       val.line_style = style;
+       val.cap_style = cap;
+
+       gc = XCreateGC(dpy->dpy, tt->draw,
+                      GCForeground |
+                      GCFunction |
+                      GCLineWidth |
+                      GCLineStyle |
+                      GCCapStyle,
+                      &val);
+       XDrawLine(dpy->dpy, tt->draw, gc,
+                 p1->x + dx, p1->y + dy,
+                 p2->x + dx, p2->y + dy);
+       XFreeGC(dpy->dpy, gc);
+}
+
+static void line_tests(struct test *t, enum target target)
+{
+       char buf[1024];
+       struct test_target real, ref;
+       int a, b, alu, lw, style, cap;
+
+       printf("Testing drawing of single line segments (%s): ",
+              test_target_name(target));
+       fflush(stdout);
+
+       test_target_create_render(&t->real, target, &real);
+       test_target_create_render(&t->ref, target, &ref);
+
+       style = LineSolid;
+
+       for (alu = 0; alu < 16; alu++) {
+               for (cap = CapNotLast; cap <= CapProjecting; cap++) {
+                       for (lw = 0; lw <= 4; lw++) {
+                               for (a = 0; a < NUM_POINTS; a++) {
+                                       for (b = 0; b < NUM_POINTS; b++) {
+                                               sprintf(buf,
+                                                       "p1=(%d, %d), p2=(%d, %d), width=%d, cap=%d, alu=%d",
+                                                       points[a].x, points[a].y,
+                                                       points[b].x, points[b].y,
+                                                       lw, cap, alu);
+
+                                               clear(&t->real, &real);
+                                               clear(&t->ref, &ref);
+
+                                               draw_line(&t->real, &real, alu, lw, style, cap,
+                                                         &points[a], &points[b], 64, 64);
+                                               draw_line(&t->ref, &ref, alu, lw, style, cap,
+                                                         &points[a], &points[b], 64, 64);
+
+                                               test_compare(t,
+                                                            real.draw, real.format,
+                                                            ref.draw, ref.format,
+                                                            0, 0, real.width, real.height,
+                                                            buf);
+                                       }
+                               }
+                       }
+               }
+       }
+
+       test_target_destroy_render(&t->real, &real);
+       test_target_destroy_render(&t->ref, &ref);
+
+       printf("\n");
+}
+
+int main(int argc, char **argv)
+{
+       struct test test;
+       enum target t;
+
+       test_init(&test, argc, argv);
+
+       for (t = TARGET_FIRST; t <= TARGET_LAST; t++)
+               line_tests(&test, t);
+
+       return 0;
+}
diff --git a/test/basic-putimage.c b/test/basic-putimage.c
new file mode 100644 (file)
index 0000000..5d68908
--- /dev/null
@@ -0,0 +1,284 @@
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <X11/Xutil.h> /* for XDestroyImage */
+#include <pixman.h> /* for pixman blt functions */
+
+#include "test.h"
+
+static void
+show_cells(char *buf,
+          const uint32_t *real, const uint32_t *ref,
+          int x, int y, int w, int h)
+{
+       int i, j, len = 0;
+
+       for (j = y - 2; j <= y + 2; j++) {
+               if (j < 0 || j >= h)
+                       continue;
+
+               for (i = x - 2; i <= x + 2; i++) {
+                       if (i < 0 || i >= w)
+                               continue;
+
+                       len += sprintf(buf+len, "%08x ", real[j*w+i]);
+               }
+
+               len += sprintf(buf+len, "\t");
+
+               for (i = x - 2; i <= x + 2; i++) {
+                       if (i < 0 || i >= w)
+                               continue;
+
+                       len += sprintf(buf+len, "%08x ", ref[j*w+i]);
+               }
+
+               len += sprintf(buf+len, "\n");
+       }
+}
+
+static void fill_rect(struct test_display *dpy,
+                     Drawable d, XRenderPictFormat *format,
+                     int use_shm,
+                     uint8_t alu, int x, int y, int w, int h, uint32_t fg)
+{
+       XImage image;
+       XGCValues val;
+       GC gc;
+
+       test_init_image(&image, &dpy->shm, format, w, h);
+
+       pixman_fill((uint32_t*)image.data,
+                   image.bytes_per_line/sizeof(uint32_t),
+                   image.bits_per_pixel,
+                   0, 0, w, h, fg);
+
+       val.function = alu;
+       gc = XCreateGC(dpy->dpy, d, GCFunction, &val);
+       if (use_shm) {
+               XShmPutImage(dpy->dpy, d, gc, &image, 0, 0, x, y, w, h, 0);
+               XSync(dpy->dpy, 1);
+       } else {
+               XPutImage(dpy->dpy, d, gc, &image, 0, 0, x, y, w, h);
+       }
+       XFreeGC(dpy->dpy, gc);
+}
+
+static void pixel_tests(struct test *t, int reps, int sets, enum target target, int use_shm)
+{
+       struct test_target tt;
+       XImage image;
+       uint32_t *cells = malloc(t->real.width*t->real.height*4);
+       struct {
+               uint16_t x, y;
+       } *pixels = malloc(reps*sizeof(*pixels));
+       int r, s;
+
+       test_target_create_render(&t->real, target, &tt);
+
+       printf("Testing setting of single pixels (%s %s shm): ",
+              test_target_name(target), use_shm ? "with" : "without" );
+       fflush(stdout);
+
+       for (s = 0; s < sets; s++) {
+               for (r = 0; r < reps; r++) {
+                       int x = rand() % (tt.width - 1);
+                       int y = rand() % (tt.height - 1);
+                       int red = rand() % 0xff;
+                       int green = rand() % 0xff;
+                       int blue = rand() % 0xff;
+                       int alpha = rand() % 0xff;
+                       uint32_t fg = color(red, green, blue, alpha);
+
+                       fill_rect(&t->real, tt.draw, tt.format, use_shm,
+                                 GXcopy, x, y, 1, 1, fg);
+
+                       pixels[r].x = x;
+                       pixels[r].y = y;
+                       cells[y*tt.width+x] = fg;
+               }
+
+               test_init_image(&image, &t->real.shm, tt.format, 1, 1);
+
+               for (r = 0; r < reps; r++) {
+                       uint32_t result;
+                       uint32_t x = pixels[r].x;
+                       uint32_t y = pixels[r].y;
+
+                       XShmGetImage(t->real.dpy, tt.draw, &image,
+                                    x, y, AllPlanes);
+
+                       result = *(uint32_t *)image.data;
+                       if (!pixel_equal(image.depth, result,
+                                        cells[y*tt.width+x])) {
+                               uint32_t mask;
+
+                               if (image.depth == 32)
+                                       mask = 0xffffffff;
+                               else
+                                       mask = (1 << image.depth) - 1;
+                               die("failed to set pixel (%d,%d) to %08x[%08x], found %08x instead\n",
+                                   x, y,
+                                   cells[y*tt.width+x] & mask,
+                                   cells[y*tt.width+x],
+                                   result & mask);
+                       }
+               }
+       }
+       printf("passed [%d iterations x %d]\n", reps, sets);
+
+       test_target_destroy_render(&t->real, &tt);
+       free(pixels);
+       free(cells);
+}
+
+static void clear(struct test_display *dpy, struct test_target *tt)
+{
+       XRenderColor render_color = {0};
+       XRenderFillRectangle(dpy->dpy, PictOpClear, tt->picture, &render_color,
+                            0, 0, tt->width, tt->height);
+}
+
+static void area_tests(struct test *t, int reps, int sets, enum target target, int use_shm)
+{
+       struct test_target tt;
+       XImage image;
+       uint32_t *cells = calloc(sizeof(uint32_t), t->real.width*t->real.height);
+       int r, s, x, y;
+
+       printf("Testing area sets (%s %s shm): ",
+              test_target_name(target), use_shm ? "with" : "without" );
+       fflush(stdout);
+
+       test_target_create_render(&t->real, target, &tt);
+       clear(&t->real, &tt);
+
+       test_init_image(&image, &t->real.shm, tt.format, tt.width, tt.height);
+
+       for (s = 0; s < sets; s++) {
+               for (r = 0; r < reps; r++) {
+                       int red = rand() % 0xff;
+                       int green = rand() % 0xff;
+                       int blue = rand() % 0xff;
+                       int alpha = rand() % 0xff;
+                       uint32_t fg = color(red, green, blue, alpha);
+                       int w, h;
+
+                       x = rand() % tt.width;
+                       y = rand() % tt.height;
+                       w = rand() % (tt.width - x);
+                       h = rand() % (tt.height - y);
+
+                       fill_rect(&t->real, tt.draw, tt.format, use_shm,
+                                 GXcopy, x, y, w, h, fg);
+
+                       pixman_fill(cells, tt.width, 32, x, y, w, h, fg);
+               }
+
+               XShmGetImage(t->real.dpy, tt.draw, &image, 0, 0, AllPlanes);
+
+               for (y = 0; y < tt.height; y++) {
+                       for (x = 0; x < tt.width; x++) {
+                               uint32_t result =
+                                       *(uint32_t *)(image.data +
+                                                     y*image.bytes_per_line +
+                                                     image.bits_per_pixel*x/8);
+                               if (!pixel_equal(image.depth, result, cells[y*tt.width+x])) {
+                                       uint32_t mask = depth_mask(image.depth);
+                                       char buf[600];
+
+                                       show_cells(buf,
+                                                  (uint32_t*)image.data, cells,
+                                                  x, y, tt.width, tt.height);
+
+                                       die("failed to set pixel (%d,%d) to %08x[%08x], found %08x [%08x] instead\n%s",
+                                           x, y,
+                                           cells[y*tt.width+x] & mask,
+                                           cells[y*tt.width+x],
+                                           result & mask, result,
+                                           buf);
+                               }
+                       }
+               }
+       }
+
+       printf("passed [%d iterations x %d]\n", reps, sets);
+
+       test_target_destroy_render(&t->real, &tt);
+       free(cells);
+}
+
+static void rect_tests(struct test *t, int reps, int sets, enum target target, int use_shm)
+{
+       struct test_target real, ref;
+       int r, s;
+
+       printf("Testing area fills (%s): ", test_target_name(target));
+       fflush(stdout);
+
+       test_target_create_render(&t->real, target, &real);
+       clear(&t->real, &real);
+
+       test_target_create_render(&t->ref, target, &ref);
+       clear(&t->ref, &ref);
+
+       for (s = 0; s < sets; s++) {
+               for (r = 0; r < reps; r++) {
+                       int x = rand() % real.width;
+                       int y = rand() % real.height;
+                       int w = rand() % (real.width - x);
+                       int h = rand() % (real.height - y);
+                       uint8_t alu = rand() % (GXset + 1);
+                       int red = rand() % 0xff;
+                       int green = rand() % 0xff;
+                       int blue = rand() % 0xff;
+                       int alpha = rand() % 0xff;
+                       uint8_t fg = color(red, green, blue, alpha);
+
+                       fill_rect(&t->real, real.draw, real.format, use_shm,
+                                 alu, x, y, w, h, fg);
+                       fill_rect(&t->ref, ref.draw, ref.format, use_shm,
+                                 alu, x, y, w, h, fg);
+               }
+
+               test_compare(t,
+                            real.draw, real.format,
+                            ref.draw, ref.format,
+                            0, 0, real.width, real.height,
+                            "");
+       }
+
+       printf("passed [%d iterations x %d]\n", reps, sets);
+
+       test_target_destroy_render(&t->real, &real);
+       test_target_destroy_render(&t->ref, &ref);
+}
+int main(int argc, char **argv)
+{
+       struct test test;
+       int i;
+
+       test_init(&test, argc, argv);
+
+       for (i = 0; i <= DEFAULT_ITERATIONS; i++) {
+               int reps = 1 << i;
+               int sets = 1 << (12 - i);
+               enum target t;
+
+               if (sets < 2)
+                       sets = 2;
+
+               for (t = TARGET_FIRST; t <= TARGET_LAST; t++) {
+                       pixel_tests(&test, reps, sets, t, 0);
+                       area_tests(&test, reps, sets, t, 0);
+                       rect_tests(&test, reps, sets, t, 0);
+
+                       pixel_tests(&test, reps, sets, t, 1);
+                       area_tests(&test, reps, sets, t, 1);
+                       rect_tests(&test, reps, sets, t, 1);
+               }
+       }
+
+       return 0;
+}
diff --git a/test/basic-rectangle.c b/test/basic-rectangle.c
new file mode 100644 (file)
index 0000000..8f78bba
--- /dev/null
@@ -0,0 +1,223 @@
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <X11/Xutil.h> /* for XDestroyImage */
+
+#include "test.h"
+
+static void draw_rect(struct test_display *t, Drawable d, uint8_t alu,
+                     int x, int y, int w, int h, uint32_t fg, int lw)
+{
+       XGCValues val;
+       GC gc;
+
+       val.function = alu;
+       val.foreground = fg;
+       val.line_width = lw;
+
+       gc = XCreateGC(t->dpy, d, GCForeground | GCFunction | GCLineWidth, &val);
+       XDrawRectangle(t->dpy, d, gc, x, y, w, h);
+       XFreeGC(t->dpy, gc);
+}
+
+static void clear(struct test_display *dpy, struct test_target *tt)
+{
+       XRenderColor render_color = {0};
+       XRenderFillRectangle(dpy->dpy, PictOpClear, tt->picture, &render_color,
+                            0, 0, tt->width, tt->height);
+}
+
+static void zrect_tests(struct test *t, int reps, int sets, enum target target)
+{
+       struct test_target real, ref;
+       int r, s;
+
+       printf("Testing empty rects (%s): ", test_target_name(target));
+       fflush(stdout);
+
+       test_target_create_render(&t->real, target, &real);
+       clear(&t->real, &real);
+
+       test_target_create_render(&t->ref, target, &ref);
+       clear(&t->ref, &ref);
+
+       for (s = 0; s < sets; s++) {
+               for (r = 0; r < reps; r++) {
+                       int x = rand() % (2*real.width) - real.width;
+                       int y = rand() % (2*real.height) - real.height;
+                       uint8_t alu = rand() % (GXset + 1);
+                       uint32_t fg = rand();
+                       uint32_t lw = rand() % 4;
+
+                       draw_rect(&t->real, real.draw, alu,
+                                 x, y, 0, 0, fg, lw);
+                       draw_rect(&t->ref, ref.draw, alu,
+                                 x, y, 0, 0, fg, lw);
+               }
+
+               test_compare(t,
+                            real.draw, real.format,
+                            ref.draw, ref.format,
+                            0, 0, real.width, real.height,
+                            "");
+       }
+
+       printf("passed [%d iterations x %d]\n", reps, sets);
+
+       test_target_destroy_render(&t->real, &real);
+       test_target_destroy_render(&t->ref, &ref);
+}
+
+static void hrect_tests(struct test *t, int reps, int sets, enum target target)
+{
+       struct test_target real, ref;
+       int r, s;
+
+       printf("Testing horizontal rects (%s): ", test_target_name(target));
+       fflush(stdout);
+
+       test_target_create_render(&t->real, target, &real);
+       clear(&t->real, &real);
+
+       test_target_create_render(&t->ref, target, &ref);
+       clear(&t->ref, &ref);
+
+       for (s = 0; s < sets; s++) {
+               for (r = 0; r < reps; r++) {
+                       int x = rand() % (2*real.width) - real.width;
+                       int y = rand() % (2*real.height) - real.height;
+                       int w = rand() % (2*real.width);
+                       uint8_t alu = rand() % (GXset + 1);
+                       uint32_t fg = rand();
+                       uint32_t lw = rand() % 4;
+
+                       draw_rect(&t->real, real.draw, alu,
+                                 x, y, w, 0, fg, lw);
+                       draw_rect(&t->ref, ref.draw, alu,
+                                 x, y, w, 0, fg, lw);
+               }
+
+               test_compare(t,
+                            real.draw, real.format,
+                            ref.draw, ref.format,
+                            0, 0, real.width, real.height,
+                            "");
+       }
+
+       printf("passed [%d iterations x %d]\n", reps, sets);
+
+       test_target_destroy_render(&t->real, &real);
+       test_target_destroy_render(&t->ref, &ref);
+}
+
+static void vrect_tests(struct test *t, int reps, int sets, enum target target)
+{
+       struct test_target real, ref;
+       int r, s;
+
+       printf("Testing vertical rects (%s): ", test_target_name(target));
+       fflush(stdout);
+
+       test_target_create_render(&t->real, target, &real);
+       clear(&t->real, &real);
+
+       test_target_create_render(&t->ref, target, &ref);
+       clear(&t->ref, &ref);
+
+       for (s = 0; s < sets; s++) {
+               for (r = 0; r < reps; r++) {
+                       int x = rand() % (2*real.width) - real.width;
+                       int y = rand() % (2*real.height) - real.height;
+                       int h = rand() % (2*real.width);
+                       uint8_t alu = rand() % (GXset + 1);
+                       uint32_t fg = rand();
+                       uint32_t lw = rand() % 4;
+
+                       draw_rect(&t->real, real.draw, alu,
+                                 x, y, 0, h, fg, lw);
+                       draw_rect(&t->ref, ref.draw, alu,
+                                 x, y, 0, h, fg, lw);
+               }
+
+               test_compare(t,
+                            real.draw, real.format,
+                            ref.draw, ref.format,
+                            0, 0, real.width, real.height,
+                            "");
+       }
+
+       printf("passed [%d iterations x %d]\n", reps, sets);
+
+       test_target_destroy_render(&t->real, &real);
+       test_target_destroy_render(&t->ref, &ref);
+}
+
+static void rect_tests(struct test *t, int reps, int sets, enum target target)
+{
+       struct test_target real, ref;
+       int r, s;
+
+       printf("Testing general (%s): ", test_target_name(target));
+       fflush(stdout);
+
+       test_target_create_render(&t->real, target, &real);
+       clear(&t->real, &real);
+
+       test_target_create_render(&t->ref, target, &ref);
+       clear(&t->ref, &ref);
+
+       for (s = 0; s < sets; s++) {
+               for (r = 0; r < reps; r++) {
+                       int x = rand() % (2*real.width) - real.width;
+                       int y = rand() % (2*real.height) - real.height;
+                       int w = rand() % (2*real.width);
+                       int h = rand() % (2*real.height);
+                       uint8_t alu = rand() % (GXset + 1);
+                       uint32_t fg = rand();
+                       uint32_t lw = rand() % 4;
+
+                       draw_rect(&t->real, real.draw, alu,
+                                 x, y, w, h, fg, lw);
+                       draw_rect(&t->ref, ref.draw, alu,
+                                 x, y, w, h, fg, lw);
+               }
+
+               test_compare(t,
+                            real.draw, real.format,
+                            ref.draw, ref.format,
+                            0, 0, real.width, real.height,
+                            "");
+       }
+
+       printf("passed [%d iterations x %d]\n", reps, sets);
+
+       test_target_destroy_render(&t->real, &real);
+       test_target_destroy_render(&t->ref, &ref);
+}
+
+int main(int argc, char **argv)
+{
+       struct test test;
+       int i;
+
+       test_init(&test, argc, argv);
+
+       for (i = 0; i <= DEFAULT_ITERATIONS; i++) {
+               int reps = 1 << i;
+               int sets = 1 << (12 - i);
+               enum target t;
+
+               if (sets < 2)
+                       sets = 2;
+
+               for (t = TARGET_FIRST; t <= TARGET_LAST; t++) {
+                       zrect_tests(&test, reps, sets, t);
+                       hrect_tests(&test, reps, sets, t);
+                       vrect_tests(&test, reps, sets, t);
+                       rect_tests(&test, reps, sets, t);
+               }
+       }
+
+       return 0;
+}
diff --git a/test/basic-stress.c b/test/basic-stress.c
new file mode 100644 (file)
index 0000000..5657173
--- /dev/null
@@ -0,0 +1,156 @@
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <X11/Xutil.h> /* for XDestroyImage */
+#include <pixman.h>
+
+#include "test.h"
+
+static void fill_rect(struct test_target *tt,
+                     int alu, int color,
+                     int x, int y, int w, int h)
+{
+       XGCValues val;
+
+       val.function = alu;
+       val.foreground = color;
+       XChangeGC(tt->dpy->dpy, tt->gc, GCFunction | GCForeground, &val);
+
+       XFillRectangle(tt->dpy->dpy, tt->draw, tt->gc, x, y, w, h);
+}
+
+static void clear(struct test_target *tt)
+{
+       fill_rect(tt,
+                 GXcopy, 0,
+                 0, 0, tt->width, tt->height);
+}
+
+static void fill(struct test_target *real,
+                struct test_target *ref)
+{
+       int x = rand() % (2*real->width) - real->width;
+       int y = rand() % (2*real->height) - real->height;
+       int w = rand() % (2*real->width);
+       int h = rand() % (2*real->height);
+       int color = rand();
+       int alu = rand() % 16;
+
+       fill_rect(real, alu, color, x, y, w, h);
+       fill_rect(ref, alu, color, x, y, w, h);
+}
+
+static void copy(struct test_target *real,
+                struct test_target *ref)
+{
+       int sx = rand() % (2*real->width) - ref->width;
+       int sy = rand() % (2*real->height) - ref->height;
+       int dx = rand() % (2*real->width) - ref->width;
+       int dy = rand() % (2*real->height) - ref->height;
+       int w = rand() % (2*real->width);
+       int h = rand() % (2*real->height);
+       XGCValues val;
+
+       val.function = rand() % 16;
+
+       XChangeGC(real->dpy->dpy, real->gc, GCFunction, &val);
+       XCopyArea(real->dpy->dpy,
+                 real->draw, real->draw, real->gc,
+                 sx, sy, w, h, dx, dy);
+
+       XChangeGC(ref->dpy->dpy, ref->gc, GCFunction, &val);
+       XCopyArea(ref->dpy->dpy,
+                 ref->draw, ref->draw, ref->gc,
+                 sx, sy, w, h, dx, dy);
+}
+
+static void _put(struct test_target *tt,
+                int x, int y, int w,int h, int color, int alu)
+{
+       XImage image;
+       XGCValues val;
+
+       val.function = alu;
+
+       test_init_image(&image, &tt->dpy->shm, tt->format, w, h);
+       pixman_fill((uint32_t*)image.data,
+                   image.bytes_per_line/sizeof(uint32_t),
+                   image.bits_per_pixel,
+                   0, 0, w, h, color);
+
+       XChangeGC(tt->dpy->dpy, tt->gc, GCFunction, &val);
+       if (rand() & 1) {
+               XShmPutImage(tt->dpy->dpy, tt->draw, tt->gc, &image,
+                            0, 0, x, y, w, h, 0);
+               XSync(tt->dpy->dpy, 1);
+       } else {
+               XPutImage(tt->dpy->dpy, tt->draw, tt->gc, &image,
+                         0, 0, x, y, w, h);
+       }
+}
+
+static void put(struct test_target *real,
+               struct test_target *ref)
+{
+       int x = rand() % (2*real->width) - real->width;
+       int y = rand() % (2*real->height) - real->height;
+       int w = rand() % real->width;
+       int h = rand() % real->height;
+       int color = rand();
+       int alu = rand() % 16;
+
+       _put(real, x, y, w, h, color, alu);
+       _put(ref, x, y, w, h, color, alu);
+}
+
+static void rect_tests(struct test *test, int iterations, enum target target)
+{
+       struct test_target real, ref;
+       void (* const ops[])(struct test_target *, struct test_target *) = {
+               copy,
+               fill,
+               put,
+       };
+       int n;
+
+       printf("Running mixed ops stress against %s: ",
+              test_target_name(target));
+       fflush(stdout);
+
+       test_target_create_render(&test->real, target, &real);
+       test_target_create_render(&test->ref, target, &ref);
+
+       clear(&real);
+       clear(&ref);
+
+       for (n = 0; n < iterations; n++)
+               ops[rand() % ARRAY_SIZE(ops)](&real, &ref);
+
+       test_compare(test,
+                    real.draw, real.format,
+                    ref.draw, ref.format,
+                    0, 0, real.width, real.height,
+                    "");
+
+       printf("passed [%d iterations]\n", n);
+
+       test_target_destroy_render(&test->real, &real);
+       test_target_destroy_render(&test->ref, &ref);
+}
+
+int main(int argc, char **argv)
+{
+       struct test test;
+       int i;
+
+       test_init(&test, argc, argv);
+
+       for (i = 0; i <= DEFAULT_ITERATIONS; i++) {
+               int iterations = 1 << i;
+               rect_tests(&test, iterations, 0);
+               rect_tests(&test, iterations, 1);
+       }
+
+       return 0;
+}
diff --git a/test/basic-string.c b/test/basic-string.c
new file mode 100644 (file)
index 0000000..9f59c91
--- /dev/null
@@ -0,0 +1,102 @@
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <X11/Xutil.h> /* for XDestroyImage */
+
+#include "test.h"
+
+static void draw_string(struct test_display *t, Drawable d, uint8_t alu,
+                       int x, int y, uint32_t fg, uint32_t bg, int s, int fill)
+{
+       const char *strings[] = {
+               "Hello",
+               "World",
+               "Cairo's twin is Giza",
+       };
+       XGCValues val;
+       GC gc;
+
+       val.function = alu;
+       val.foreground = fg;
+       val.background = bg;
+
+       gc = XCreateGC(t->dpy, d, GCForeground | GCBackground | GCFunction, &val);
+       if (fill)
+               XDrawImageString(t->dpy, d, gc, x, y, strings[s%3], strlen(strings[s%3]));
+       else
+               XDrawString(t->dpy, d, gc, x, y, strings[s%3], strlen(strings[s%3]));
+       XFreeGC(t->dpy, gc);
+}
+
+static void clear(struct test_display *dpy, struct test_target *tt)
+{
+       XRenderColor render_color = {0};
+       XRenderFillRectangle(dpy->dpy, PictOpClear, tt->picture, &render_color,
+                            0, 0, tt->width, tt->height);
+}
+
+static void string_tests(struct test *t, int reps, int sets, enum target target)
+{
+       struct test_target real, ref;
+       int r, s;
+
+       printf("Testing general (%s): ", test_target_name(target));
+       fflush(stdout);
+
+       test_target_create_render(&t->real, target, &real);
+       clear(&t->real, &real);
+
+       test_target_create_render(&t->ref, target, &ref);
+       clear(&t->ref, &ref);
+
+       for (s = 0; s < sets; s++) {
+               for (r = 0; r < reps; r++) {
+                       int x = rand() % (2*real.width) - real.width;
+                       int y = rand() % (2*real.height) - real.height;
+                       uint8_t alu = rand() % (GXset + 1);
+                       uint32_t fg = rand();
+                       uint32_t bg = rand();
+                       int str = rand();
+                       int fill = rand() & 1;
+
+                       draw_string(&t->real, real.draw, alu, x, y, fg, bg, str, fill);
+                       draw_string(&t->ref, ref.draw, alu, x, y, fg, bg, str, fill);
+               }
+
+               test_compare(t,
+                            real.draw, real.format,
+                            ref.draw, ref.format,
+                            0, 0, real.width, real.height,
+                            "");
+       }
+
+       printf("passed [%d iterations x %d]\n", reps, sets);
+
+       test_target_destroy_render(&t->real, &real);
+       test_target_destroy_render(&t->ref, &ref);
+}
+
+int main(int argc, char **argv)
+{
+       struct test test;
+       int i;
+
+       test_init(&test, argc, argv);
+
+       for (i = 0; i <= DEFAULT_ITERATIONS; i++) {
+               int reps = 1 << i;
+               int sets = 1 << (12 - i);
+               enum target t;
+
+               if (sets < 2)
+                       sets = 2;
+
+               for (t = TARGET_FIRST; t <= TARGET_LAST; t++) {
+                       string_tests(&test, reps, sets, t);
+               }
+       }
+
+       return 0;
+}
diff --git a/test/dri2-swap.c b/test/dri2-swap.c
new file mode 100644 (file)
index 0000000..ba6b237
--- /dev/null
@@ -0,0 +1,172 @@
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/extensions/Xfixes.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <string.h>
+#include <time.h>
+
+#include <xf86drm.h>
+#include <drm.h>
+
+#include "dri2.h"
+
+#define COUNT 60
+
+static int dri2_open(Display *dpy)
+{
+       drm_auth_t auth;
+       char *driver, *device;
+       int fd;
+
+       if (!DRI2Connect(dpy, DefaultRootWindow(dpy), &driver, &device))
+               return -1;
+
+       printf ("Connecting to %s driver on %s\n", driver, device);
+
+       fd = open("/dev/dri/card0", O_RDWR);
+       if (fd < 0)
+               return -1;
+
+       if (drmIoctl(fd, DRM_IOCTL_GET_MAGIC, &auth))
+               return -1;
+
+       if (!DRI2Authenticate(dpy, DefaultRootWindow(dpy), auth.magic))
+               return -1;
+
+       return fd;
+}
+
+static void dri2_copy_swap(Display *dpy, Drawable d,
+                          int width, int height, int has_front)
+{
+       XRectangle rect;
+       XserverRegion region;
+
+       rect.x = 0;
+       rect.y = 0;
+       rect.width = width;
+       rect.height = height;
+
+       region = XFixesCreateRegion(dpy, &rect, 1);
+       DRI2CopyRegion(dpy, d, region, DRI2BufferFrontLeft, DRI2BufferBackLeft);
+       if (has_front)
+               DRI2CopyRegion(dpy, d, region, DRI2BufferFakeFrontLeft, DRI2BufferFrontLeft);
+       XFixesDestroyRegion(dpy, region);
+}
+
+static void xsync(Display *dpy, Window win)
+{
+       XImage *image;
+
+       image = XGetImage(dpy, win, 0, 0, 1, 1, ~0, ZPixmap);
+       if (image)
+               XDestroyImage(image);
+}
+
+static double elapsed(const struct timespec *start,
+                     const struct timespec *end)
+{
+       return (end->tv_sec - start->tv_sec) +
+               1e-9*(end->tv_nsec - start->tv_nsec);
+}
+
+static void run(Display *dpy, int width, int height,
+               unsigned int *attachments, int nattachments,
+               const char *name)
+{
+       Window win;
+       XSetWindowAttributes attr;
+       int count;
+       DRI2Buffer *buffers;
+       struct timespec start, end;
+
+       /* Be nasty and install a fullscreen window on top so that we
+        * can guarantee we do not get clipped by children.
+        */
+       attr.override_redirect = 1;
+       win = XCreateWindow(dpy, DefaultRootWindow(dpy),
+                        0, 0, width, height, 0,
+                        DefaultDepth(dpy, DefaultScreen(dpy)),
+                        InputOutput,
+                        DefaultVisual(dpy, DefaultScreen(dpy)),
+                        CWOverrideRedirect, &attr);
+       XMapWindow(dpy, win);
+       xsync(dpy, win);
+
+       DRI2CreateDrawable(dpy, win);
+
+       buffers = DRI2GetBuffers(dpy, win, &width, &height,
+                                attachments, nattachments, &count);
+       if (count != nattachments)
+               return;
+
+       xsync(dpy, win);
+       clock_gettime(CLOCK_MONOTONIC, &start);
+       for (count = 0; count < COUNT; count++)
+               DRI2SwapBuffers(dpy, win, 0, 0, 0);
+       xsync(dpy, win);
+       clock_gettime(CLOCK_MONOTONIC, &end);
+       printf("%d %s (%dx%d) swaps in %fs.\n",
+              count, name, width, height, elapsed(&start, &end));
+
+       xsync(dpy, win);
+       clock_gettime(CLOCK_MONOTONIC, &start);
+       for (count = 0; count < COUNT; count++)
+               dri2_copy_swap(dpy, win, width, height, nattachments == 2);
+       xsync(dpy, win);
+       clock_gettime(CLOCK_MONOTONIC, &end);
+
+       printf("%d %s (%dx%d) blits in %fs.\n",
+              count, name, width, height, elapsed(&start, &end));
+
+       DRI2SwapInterval(dpy, win, 0);
+
+       xsync(dpy, win);
+       clock_gettime(CLOCK_MONOTONIC, &start);
+       for (count = 0; count < COUNT; count++)
+               DRI2SwapBuffers(dpy, win, 0, 0, 0);
+       xsync(dpy, win);
+       clock_gettime(CLOCK_MONOTONIC, &end);
+       printf("%d %s (%dx%d) vblank=0 swaps in %fs.\n",
+              count, name, width, height, elapsed(&start, &end));
+
+       XDestroyWindow(dpy, win);
+       free(buffers);
+
+       XSync(dpy, 1);
+}
+
+int main(void)
+{
+       Display *dpy;
+       int width, height, fd;
+       unsigned int attachments[] = {
+               DRI2BufferBackLeft,
+               DRI2BufferFrontLeft,
+       };
+
+       dpy = XOpenDisplay (NULL);
+       if (dpy == NULL)
+               return 77;
+
+       fd = dri2_open(dpy);
+       if (fd < 0)
+               return 1;
+
+       width = WidthOfScreen(DefaultScreenOfDisplay(dpy));
+       height = HeightOfScreen(DefaultScreenOfDisplay(dpy));
+       run(dpy, width, height, attachments, 1, "fullscreen");
+       run(dpy, width, height, attachments, 2, "fullscreen (with front)");
+
+       width /= 2;
+       height /= 2;
+       run(dpy, width, height, attachments, 1, "windowed");
+       run(dpy, width, height, attachments, 2, "windowed (with front)");
+
+       return 0;
+}
diff --git a/test/dri2.c b/test/dri2.c
new file mode 100644 (file)
index 0000000..0e2003c
--- /dev/null
@@ -0,0 +1,668 @@
+/*
+ * Copyright © 2008 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Soft-
+ * ware"), to deal in the Software without restriction, including without
+ * limitation the rights to use, copy, modify, merge, publish, distribute,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, provided that the above copyright
+ * notice(s) and this permission notice appear in all copies of the Soft-
+ * ware and that both the above copyright notice(s) and this permission
+ * notice appear in supporting documentation.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
+ * ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY
+ * RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN
+ * THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSE-
+ * QUENTIAL 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 PERFOR-
+ * MANCE OF THIS SOFTWARE.
+ *
+ * Except as contained in this notice, the name of a copyright holder shall
+ * not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization of
+ * the copyright holder.
+ *
+ * Authors:
+ *   Kristian Høgsberg (krh@redhat.com)
+ */
+
+
+#include <stdio.h>
+#include <X11/Xlibint.h>
+#include <X11/extensions/Xext.h>
+#include <X11/extensions/extutil.h>
+#include <X11/extensions/dri2proto.h>
+
+#include <GL/glx.h>
+#include <GL/glxext.h>
+
+#include "dri2.h"
+
+/* Allow the build to work with an older versions of dri2proto.h and
+ * dri2tokens.h.
+ */
+#if DRI2_MINOR < 1
+#undef DRI2_MINOR
+#define DRI2_MINOR 1
+#define X_DRI2GetBuffersWithFormat 7
+#endif
+
+
+static char dri2ExtensionName[] = DRI2_NAME;
+static XExtensionInfo *dri2Info;
+static XEXT_GENERATE_CLOSE_DISPLAY (DRI2CloseDisplay, dri2Info)
+
+static Bool
+DRI2WireToEvent(Display *dpy, XEvent *event, xEvent *wire);
+static Status
+DRI2EventToWire(Display *dpy, XEvent *event, xEvent *wire);
+static int
+DRI2Error(Display *display, xError *err, XExtCodes *codes, int *ret_code);
+
+static /* const */ XExtensionHooks dri2ExtensionHooks = {
+  NULL,                   /* create_gc */
+  NULL,                   /* copy_gc */
+  NULL,                   /* flush_gc */
+  NULL,                   /* free_gc */
+  NULL,                   /* create_font */
+  NULL,                   /* free_font */
+  DRI2CloseDisplay,       /* close_display */
+  DRI2WireToEvent,        /* wire_to_event */
+  DRI2EventToWire,        /* event_to_wire */
+  DRI2Error,              /* error */
+  NULL,                   /* error_string */
+};
+
+static XEXT_GENERATE_FIND_DISPLAY (DRI2FindDisplay,
+                                   dri2Info,
+                                   dri2ExtensionName,
+                                   &dri2ExtensionHooks,
+                                   0, NULL)
+
+static Bool
+DRI2WireToEvent(Display *dpy, XEvent *event, xEvent *wire)
+{
+   XExtDisplayInfo *info = DRI2FindDisplay(dpy);
+
+   XextCheckExtension(dpy, info, dri2ExtensionName, False);
+
+   switch ((wire->u.u.type & 0x7f) - info->codes->first_event) {
+#ifdef X_DRI2SwapBuffers
+   case DRI2_BufferSwapComplete:
+      /* Ignore swap events if we're not looking for them */
+          printf("BufferSwapComplete\n");
+      return False;
+#endif
+#ifdef DRI2_InvalidateBuffers
+   case DRI2_InvalidateBuffers:
+          printf("InvalidateBuffers\n");
+      return False;
+#endif
+   default:
+      /* client doesn't support server event */
+      break;
+   }
+
+   return False;
+}
+
+/* We don't actually support this.  It doesn't make sense for clients to
+ * send each other DRI2 events.
+ */
+static Status
+DRI2EventToWire(Display *dpy, XEvent *event, xEvent *wire)
+{
+   XExtDisplayInfo *info = DRI2FindDisplay(dpy);
+
+   XextCheckExtension(dpy, info, dri2ExtensionName, False);
+
+   switch (event->type) {
+   default:
+      /* client doesn't support server event */
+      break;
+   }
+
+   return Success;
+}
+
+static int
+DRI2Error(Display *display, xError *err, XExtCodes *codes, int *ret_code)
+{
+    if (err->majorCode == codes->major_opcode &&
+       err->errorCode == BadDrawable &&
+       err->minorCode == X_DRI2CopyRegion)
+       return True;
+
+    /* If the X drawable was destroyed before the GLX drawable, the
+     * DRI2 drawble will be gone by the time we call
+     * DRI2DestroyDrawable.  So just ignore BadDrawable here. */
+    if (err->majorCode == codes->major_opcode &&
+       err->errorCode == BadDrawable &&
+       err->minorCode == X_DRI2DestroyDrawable)
+       return True;
+
+    /* If the server is non-local DRI2Connect will raise BadRequest.
+     * Swallow this so that DRI2Connect can signal this in its return code */
+    if (err->majorCode == codes->major_opcode &&
+        err->minorCode == X_DRI2Connect &&
+        err->errorCode == BadRequest) {
+       *ret_code = False;
+       return True;
+    }
+
+    return False;
+}
+
+Bool
+DRI2QueryExtension(Display * dpy, int *eventBase, int *errorBase)
+{
+   XExtDisplayInfo *info = DRI2FindDisplay(dpy);
+
+   if (XextHasExtension(info)) {
+      *eventBase = info->codes->first_event;
+      *errorBase = info->codes->first_error;
+      return True;
+   }
+
+   return False;
+}
+
+Bool
+DRI2QueryVersion(Display * dpy, int *major, int *minor)
+{
+   XExtDisplayInfo *info = DRI2FindDisplay(dpy);
+   xDRI2QueryVersionReply rep;
+   xDRI2QueryVersionReq *req;
+   int i, nevents;
+
+   XextCheckExtension(dpy, info, dri2ExtensionName, False);
+
+   LockDisplay(dpy);
+   GetReq(DRI2QueryVersion, req);
+   req->reqType = info->codes->major_opcode;
+   req->dri2ReqType = X_DRI2QueryVersion;
+   req->majorVersion = DRI2_MAJOR;
+   req->minorVersion = DRI2_MINOR;
+   if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
+      UnlockDisplay(dpy);
+      SyncHandle();
+      return False;
+   }
+   *major = rep.majorVersion;
+   *minor = rep.minorVersion;
+   UnlockDisplay(dpy);
+   SyncHandle();
+
+   switch (rep.minorVersion) {
+   case 1:
+          nevents = 0;
+          break;
+   case 2:
+          nevents = 1;
+          break;
+   case 3:
+   default:
+          nevents = 2;
+          break;
+   }
+       
+   for (i = 0; i < nevents; i++) {
+       XESetWireToEvent (dpy, info->codes->first_event + i, DRI2WireToEvent);
+       XESetEventToWire (dpy, info->codes->first_event + i, DRI2EventToWire);
+   }
+
+   return True;
+}
+
+Bool
+DRI2Connect(Display * dpy, XID window, char **driverName, char **deviceName)
+{
+   XExtDisplayInfo *info = DRI2FindDisplay(dpy);
+   xDRI2ConnectReply rep;
+   xDRI2ConnectReq *req;
+
+   XextCheckExtension(dpy, info, dri2ExtensionName, False);
+
+   LockDisplay(dpy);
+   GetReq(DRI2Connect, req);
+   req->reqType = info->codes->major_opcode;
+   req->dri2ReqType = X_DRI2Connect;
+   req->window = window;
+   req->driverType = DRI2DriverDRI;
+   if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
+      UnlockDisplay(dpy);
+      SyncHandle();
+      return False;
+   }
+
+   if (rep.driverNameLength == 0 && rep.deviceNameLength == 0) {
+      UnlockDisplay(dpy);
+      SyncHandle();
+      return False;
+   }
+
+   *driverName = Xmalloc(rep.driverNameLength + 1);
+   if (*driverName == NULL) {
+      _XEatData(dpy,
+                ((rep.driverNameLength + 3) & ~3) +
+                ((rep.deviceNameLength + 3) & ~3));
+      UnlockDisplay(dpy);
+      SyncHandle();
+      return False;
+   }
+   _XReadPad(dpy, *driverName, rep.driverNameLength);
+   (*driverName)[rep.driverNameLength] = '\0';
+
+   *deviceName = Xmalloc(rep.deviceNameLength + 1);
+   if (*deviceName == NULL) {
+      Xfree(*driverName);
+      _XEatData(dpy, ((rep.deviceNameLength + 3) & ~3));
+      UnlockDisplay(dpy);
+      SyncHandle();
+      return False;
+   }
+   _XReadPad(dpy, *deviceName, rep.deviceNameLength);
+   (*deviceName)[rep.deviceNameLength] = '\0';
+
+   UnlockDisplay(dpy);
+   SyncHandle();
+
+   return True;
+}
+
+Bool
+DRI2Authenticate(Display * dpy, XID window, unsigned int magic)
+{
+   XExtDisplayInfo *info = DRI2FindDisplay(dpy);
+   xDRI2AuthenticateReq *req;
+   xDRI2AuthenticateReply rep;
+
+   XextCheckExtension(dpy, info, dri2ExtensionName, False);
+
+   LockDisplay(dpy);
+   GetReq(DRI2Authenticate, req);
+   req->reqType = info->codes->major_opcode;
+   req->dri2ReqType = X_DRI2Authenticate;
+   req->window = window;
+   req->magic = magic;
+
+   if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
+      UnlockDisplay(dpy);
+      SyncHandle();
+      return False;
+   }
+
+   UnlockDisplay(dpy);
+   SyncHandle();
+
+   return rep.authenticated;
+}
+
+void
+DRI2CreateDrawable(Display * dpy, XID drawable)
+{
+   XExtDisplayInfo *info = DRI2FindDisplay(dpy);
+   xDRI2CreateDrawableReq *req;
+
+   XextSimpleCheckExtension(dpy, info, dri2ExtensionName);
+
+   LockDisplay(dpy);
+   GetReq(DRI2CreateDrawable, req);
+   req->reqType = info->codes->major_opcode;
+   req->dri2ReqType = X_DRI2CreateDrawable;
+   req->drawable = drawable;
+   UnlockDisplay(dpy);
+   SyncHandle();
+}
+
+void
+DRI2DestroyDrawable(Display * dpy, XID drawable)
+{
+   XExtDisplayInfo *info = DRI2FindDisplay(dpy);
+   xDRI2DestroyDrawableReq *req;
+
+   XextSimpleCheckExtension(dpy, info, dri2ExtensionName);
+
+   XSync(dpy, False);
+
+   LockDisplay(dpy);
+   GetReq(DRI2DestroyDrawable, req);
+   req->reqType = info->codes->major_opcode;
+   req->dri2ReqType = X_DRI2DestroyDrawable;
+   req->drawable = drawable;
+   UnlockDisplay(dpy);
+   SyncHandle();
+}
+
+DRI2Buffer *
+DRI2GetBuffers(Display * dpy, XID drawable,
+               int *width, int *height,
+               unsigned int *attachments, int count, int *outCount)
+{
+   XExtDisplayInfo *info = DRI2FindDisplay(dpy);
+   xDRI2GetBuffersReply rep;
+   xDRI2GetBuffersReq *req;
+   DRI2Buffer *buffers;
+   xDRI2Buffer repBuffer;
+   uint32_t *p;
+   int i;
+
+   XextCheckExtension(dpy, info, dri2ExtensionName, False);
+
+   LockDisplay(dpy);
+   GetReqExtra(DRI2GetBuffers, count * 4, req);
+   req->reqType = info->codes->major_opcode;
+   req->dri2ReqType = X_DRI2GetBuffers;
+   req->drawable = drawable;
+   req->count = count;
+   p = (uint32_t *) & req[1];
+   for (i = 0; i < count; i++)
+      p[i] = attachments[i];
+
+   if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
+      UnlockDisplay(dpy);
+      SyncHandle();
+      return NULL;
+   }
+
+   *width = rep.width;
+   *height = rep.height;
+   *outCount = rep.count;
+
+   buffers = Xmalloc(rep.count * sizeof buffers[0]);
+   if (buffers == NULL) {
+      _XEatData(dpy, rep.count * sizeof repBuffer);
+      UnlockDisplay(dpy);
+      SyncHandle();
+      return NULL;
+   }
+
+   for (i = 0; i < rep.count; i++) {
+      _XReadPad(dpy, (char *) &repBuffer, sizeof repBuffer);
+      buffers[i].attachment = repBuffer.attachment;
+      buffers[i].name = repBuffer.name;
+      buffers[i].pitch = repBuffer.pitch;
+      buffers[i].cpp = repBuffer.cpp;
+      buffers[i].flags = repBuffer.flags;
+   }
+
+   UnlockDisplay(dpy);
+   SyncHandle();
+
+   return buffers;
+}
+
+
+DRI2Buffer *
+DRI2GetBuffersWithFormat(Display * dpy, XID drawable,
+                         int *width, int *height,
+                         unsigned int *attachments, int count, int *outCount)
+{
+   XExtDisplayInfo *info = DRI2FindDisplay(dpy);
+   xDRI2GetBuffersReply rep;
+   xDRI2GetBuffersReq *req;
+   DRI2Buffer *buffers;
+   xDRI2Buffer repBuffer;
+   uint32_t *p;
+   int i;
+
+   XextCheckExtension(dpy, info, dri2ExtensionName, False);
+
+   LockDisplay(dpy);
+   GetReqExtra(DRI2GetBuffers, count * (4 * 2), req);
+   req->reqType = info->codes->major_opcode;
+   req->dri2ReqType = X_DRI2GetBuffersWithFormat;
+   req->drawable = drawable;
+   req->count = count;
+   p = (uint32_t *) & req[1];
+   for (i = 0; i < (count * 2); i++)
+      p[i] = attachments[i];
+
+   if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
+      UnlockDisplay(dpy);
+      SyncHandle();
+      return NULL;
+   }
+
+   *width = rep.width;
+   *height = rep.height;
+   *outCount = rep.count;
+
+   buffers = Xmalloc(rep.count * sizeof buffers[0]);
+   if (buffers == NULL) {
+      _XEatData(dpy, rep.count * sizeof repBuffer);
+      UnlockDisplay(dpy);
+      SyncHandle();
+      return NULL;
+   }
+
+   for (i = 0; i < rep.count; i++) {
+      _XReadPad(dpy, (char *) &repBuffer, sizeof repBuffer);
+      buffers[i].attachment = repBuffer.attachment;
+      buffers[i].name = repBuffer.name;
+      buffers[i].pitch = repBuffer.pitch;
+      buffers[i].cpp = repBuffer.cpp;
+      buffers[i].flags = repBuffer.flags;
+   }
+
+   UnlockDisplay(dpy);
+   SyncHandle();
+
+   return buffers;
+}
+
+
+void
+DRI2CopyRegion(Display * dpy, XID drawable, XserverRegion region,
+               uint32_t dest, uint32_t src)
+{
+   XExtDisplayInfo *info = DRI2FindDisplay(dpy);
+   xDRI2CopyRegionReq *req;
+   xDRI2CopyRegionReply rep;
+
+   XextSimpleCheckExtension(dpy, info, dri2ExtensionName);
+
+   LockDisplay(dpy);
+   GetReq(DRI2CopyRegion, req);
+   req->reqType = info->codes->major_opcode;
+   req->dri2ReqType = X_DRI2CopyRegion;
+   req->drawable = drawable;
+   req->region = region;
+   req->dest = dest;
+   req->src = src;
+
+   (void) _XReply(dpy, (xReply *) & rep, 0, xFalse);
+
+   UnlockDisplay(dpy);
+   SyncHandle();
+}
+
+#ifdef X_DRI2SwapBuffers
+static void
+load_swap_req(xDRI2SwapBuffersReq *req, uint64_t target, uint64_t divisor,
+            uint64_t remainder)
+{
+    req->target_msc_hi = target >> 32;
+    req->target_msc_lo = target & 0xffffffff;
+    req->divisor_hi = divisor >> 32;
+    req->divisor_lo = divisor & 0xffffffff;
+    req->remainder_hi = remainder >> 32;
+    req->remainder_lo = remainder & 0xffffffff;
+}
+
+static uint64_t
+vals_to_card64(uint32_t lo, uint32_t hi)
+{
+    return (uint64_t)hi << 32 | lo;
+}
+
+uint64_t DRI2SwapBuffers(Display *dpy, XID drawable,
+                        uint64_t target_msc, uint64_t divisor, uint64_t remainder)
+{
+    XExtDisplayInfo *info = DRI2FindDisplay(dpy);
+    xDRI2SwapBuffersReq *req;
+    xDRI2SwapBuffersReply rep;
+    uint64_t count;
+
+    XextCheckExtension (dpy, info, dri2ExtensionName, 0);
+
+    LockDisplay(dpy);
+    GetReq(DRI2SwapBuffers, req);
+    req->reqType = info->codes->major_opcode;
+    req->dri2ReqType = X_DRI2SwapBuffers;
+    req->drawable = drawable;
+    load_swap_req(req, target_msc, divisor, remainder);
+
+    (void) _XReply(dpy, (xReply *)&rep, 0, xFalse);
+
+    count = vals_to_card64(rep.swap_lo, rep.swap_hi);
+
+    UnlockDisplay(dpy);
+    SyncHandle();
+
+    return count;
+}
+#endif
+
+#ifdef X_DRI2GetMSC
+Bool DRI2GetMSC(Display *dpy, XID drawable, uint64_t *ust, uint64_t *msc,
+               uint64_t *sbc)
+{
+    XExtDisplayInfo *info = DRI2FindDisplay(dpy);
+    xDRI2GetMSCReq *req;
+    xDRI2MSCReply rep;
+
+    XextCheckExtension (dpy, info, dri2ExtensionName, False);
+
+    LockDisplay(dpy);
+    GetReq(DRI2GetMSC, req);
+    req->reqType = info->codes->major_opcode;
+    req->dri2ReqType = X_DRI2GetMSC;
+    req->drawable = drawable;
+
+    if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+       UnlockDisplay(dpy);
+       SyncHandle();
+       return False;
+    }
+
+    *ust = vals_to_card64(rep.ust_lo, rep.ust_hi);
+    *msc = vals_to_card64(rep.msc_lo, rep.msc_hi);
+    *sbc = vals_to_card64(rep.sbc_lo, rep.sbc_hi);
+
+    UnlockDisplay(dpy);
+    SyncHandle();
+
+    return True;
+}
+#endif
+
+#ifdef X_DRI2WaitMSC
+static void
+load_msc_req(xDRI2WaitMSCReq *req, uint64_t target, uint64_t divisor,
+            uint64_t remainder)
+{
+    req->target_msc_hi = target >> 32;
+    req->target_msc_lo = target & 0xffffffff;
+    req->divisor_hi = divisor >> 32;
+    req->divisor_lo = divisor & 0xffffffff;
+    req->remainder_hi = remainder >> 32;
+    req->remainder_lo = remainder & 0xffffffff;
+}
+
+Bool DRI2WaitMSC(Display *dpy, XID drawable, uint64_t target_msc, uint64_t divisor,
+                uint64_t remainder, uint64_t *ust, uint64_t *msc, uint64_t *sbc)
+{
+    XExtDisplayInfo *info = DRI2FindDisplay(dpy);
+    xDRI2WaitMSCReq *req;
+    xDRI2MSCReply rep;
+
+    XextCheckExtension (dpy, info, dri2ExtensionName, False);
+
+    LockDisplay(dpy);
+    GetReq(DRI2WaitMSC, req);
+    req->reqType = info->codes->major_opcode;
+    req->dri2ReqType = X_DRI2WaitMSC;
+    req->drawable = drawable;
+    load_msc_req(req, target_msc, divisor, remainder);
+
+    if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+       UnlockDisplay(dpy);
+       SyncHandle();
+       return False;
+    }
+
+    *ust = ((uint64_t)rep.ust_hi << 32) | (uint64_t)rep.ust_lo;
+    *msc = ((uint64_t)rep.msc_hi << 32) | (uint64_t)rep.msc_lo;
+    *sbc = ((uint64_t)rep.sbc_hi << 32) | (uint64_t)rep.sbc_lo;
+
+    UnlockDisplay(dpy);
+    SyncHandle();
+
+    return True;
+}
+#endif
+
+#ifdef X_DRI2WaitSBC
+static void
+load_sbc_req(xDRI2WaitSBCReq *req, uint64_t target)
+{
+    req->target_sbc_hi = target >> 32;
+    req->target_sbc_lo = target & 0xffffffff;
+}
+
+Bool DRI2WaitSBC(Display *dpy, XID drawable, uint64_t target_sbc, uint64_t *ust,
+                uint64_t *msc, uint64_t *sbc)
+{
+    XExtDisplayInfo *info = DRI2FindDisplay(dpy);
+    xDRI2WaitSBCReq *req;
+    xDRI2MSCReply rep;
+
+    XextCheckExtension (dpy, info, dri2ExtensionName, False);
+
+    LockDisplay(dpy);
+    GetReq(DRI2WaitSBC, req);
+    req->reqType = info->codes->major_opcode;
+    req->dri2ReqType = X_DRI2WaitSBC;
+    req->drawable = drawable;
+    load_sbc_req(req, target_sbc);
+
+    if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+       UnlockDisplay(dpy);
+       SyncHandle();
+       return False;
+    }
+
+    *ust = ((uint64_t)rep.ust_hi << 32) | rep.ust_lo;
+    *msc = ((uint64_t)rep.msc_hi << 32) | rep.msc_lo;
+    *sbc = ((uint64_t)rep.sbc_hi << 32) | rep.sbc_lo;
+
+    UnlockDisplay(dpy);
+    SyncHandle();
+
+    return True;
+}
+#endif
+
+#ifdef X_DRI2SwapInterval
+void DRI2SwapInterval(Display *dpy, XID drawable, int interval)
+{
+    XExtDisplayInfo *info = DRI2FindDisplay(dpy);
+    xDRI2SwapIntervalReq *req;
+
+    XextSimpleCheckExtension (dpy, info, dri2ExtensionName);
+
+    LockDisplay(dpy);
+    GetReq(DRI2SwapInterval, req);
+    req->reqType = info->codes->major_opcode;
+    req->dri2ReqType = X_DRI2SwapInterval;
+    req->drawable = drawable;
+    req->interval = interval;
+    UnlockDisplay(dpy);
+    SyncHandle();
+}
+#endif
diff --git a/test/dri2.h b/test/dri2.h
new file mode 100644 (file)
index 0000000..9034d3a
--- /dev/null
@@ -0,0 +1,108 @@
+/*
+ * Copyright © 2007,2008 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Soft-
+ * ware"), to deal in the Software without restriction, including without
+ * limitation the rights to use, copy, modify, merge, publish, distribute,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, provided that the above copyright
+ * notice(s) and this permission notice appear in all copies of the Soft-
+ * ware and that both the above copyright notice(s) and this permission
+ * notice appear in supporting documentation.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
+ * ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY
+ * RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN
+ * THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSE-
+ * QUENTIAL 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 PERFOR-
+ * MANCE OF THIS SOFTWARE.
+ *
+ * Except as contained in this notice, the name of a copyright holder shall
+ * not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization of
+ * the copyright holder.
+ *
+ * Authors:
+ *   Kristian Høgsberg (krh@redhat.com)
+ */
+
+#ifndef _DRI2_H_
+#define _DRI2_H_
+
+#include <stdint.h>
+
+#include <X11/extensions/Xfixes.h>
+#include <X11/extensions/dri2tokens.h>
+
+typedef struct
+{
+   unsigned int attachment;
+   unsigned int name;
+   unsigned int pitch;
+   unsigned int cpp;
+   unsigned int flags;
+} DRI2Buffer;
+
+extern Bool
+DRI2QueryExtension(Display * display, int *eventBase, int *errorBase);
+
+extern Bool
+DRI2QueryVersion(Display * display, int *major, int *minor);
+
+extern Bool
+DRI2Connect(Display * display, XID window,
+            char **driverName, char **deviceName);
+
+extern Bool
+DRI2Authenticate(Display * display, XID window, unsigned int magic);
+
+extern void
+DRI2CreateDrawable(Display * display, XID drawable);
+
+extern void
+DRI2DestroyDrawable(Display * display, XID handle);
+
+extern DRI2Buffer*
+DRI2GetBuffers(Display * dpy, XID drawable,
+               int *width, int *height,
+               unsigned int *attachments, int count,
+               int *outCount);
+
+/**
+ * \note
+ * This function is only supported with DRI2 version 1.1 or later.
+ */
+extern DRI2Buffer*
+DRI2GetBuffersWithFormat(Display * dpy, XID drawable,
+                         int *width, int *height,
+                         unsigned int *attachments,
+                         int count, int *outCount);
+
+extern void
+DRI2CopyRegion(Display * dpy, XID drawable,
+               XserverRegion region,
+               uint32_t dest, uint32_t src);
+
+extern uint64_t
+DRI2SwapBuffers(Display *dpy, XID drawable,
+               uint64_t target_msc, uint64_t divisor, uint64_t remainder);
+
+extern Bool
+DRI2GetMSC(Display *dpy, XID drawable, uint64_t *ust, uint64_t *msc, uint64_t *sbc);
+
+extern Bool
+DRI2WaitMSC(Display *dpy, XID drawable, uint64_t target_msc, uint64_t divisor,
+           uint64_t remainder, uint64_t *ust, uint64_t *msc, uint64_t *sbc);
+
+extern Bool
+DRI2WaitSBC(Display *dpy, XID drawable, uint64_t target_sbc, uint64_t *ust,
+           uint64_t *msc, uint64_t *sbc);
+
+extern void
+DRI2SwapInterval(Display *dpy, XID drawable, int interval);
+
+#endif
diff --git a/test/mixed-stress.c b/test/mixed-stress.c
new file mode 100644 (file)
index 0000000..42e2c08
--- /dev/null
@@ -0,0 +1,209 @@
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <X11/Xutil.h> /* for XDestroyImage */
+#include <pixman.h>
+
+#include "test.h"
+
+static void _render_copy(struct test_target *tt,
+                        int x, int y, int w, int h,
+                        uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha)
+{
+       XRenderColor color;
+       Picture src;
+       Pixmap tmp;
+
+       tmp = XCreatePixmap(tt->dpy->dpy, DefaultRootWindow(tt->dpy->dpy),
+                           10+w, 20+h, tt->format->depth);
+       src = XRenderCreatePicture(tt->dpy->dpy, tmp, tt->format, 0, NULL);
+
+       /* magenta border */
+       color.red = 0xffff;
+       color.green = 0;
+       color.blue = 0xffff;
+       color.alpha = 0xffff;
+       XRenderFillRectangle(tt->dpy->dpy, PictOpSrc, src, &color, 0, 0, w+10, h+20);
+
+       color.red = red * alpha;
+       color.green = green * alpha;
+       color.blue = blue * alpha;
+       color.alpha = alpha << 8 | alpha;
+       XRenderFillRectangle(tt->dpy->dpy, PictOpSrc, src, &color, 5, 10, w, h);
+
+       XRenderComposite(tt->dpy->dpy, PictOpSrc,
+                        src, 0, tt->picture,
+                        5, 10,
+                        0, 0,
+                        x, y,
+                        w, h);
+
+       XRenderFreePicture(tt->dpy->dpy, src);
+       XFreePixmap(tt->dpy->dpy, tmp);
+}
+
+static void render_copy(struct test_target *real,
+                       struct test_target *ref)
+{
+       int x = rand() % (2*real->width) - real->width;
+       int y = rand() % (2*real->height) - real->height;
+       int w = rand() % (2*real->width);
+       int h = rand() % (2*real->height);
+       int red = rand() & 0xff;
+       int green = rand() & 0xff;
+       int blue = rand() & 0xff;
+       int alpha = rand() & 0xff;
+
+       _render_copy(real, x, y, w, h, red, green, blue, alpha);
+       _render_copy(ref, x, y, w, h, red, green, blue, alpha);
+}
+
+static void fill_rect(struct test_target *tt,
+                     int alu, int color,
+                     int x, int y, int w, int h)
+{
+       XGCValues val;
+
+       val.function = alu;
+       val.foreground = color;
+       XChangeGC(tt->dpy->dpy, tt->gc, GCFunction | GCForeground, &val);
+
+       XFillRectangle(tt->dpy->dpy, tt->draw, tt->gc, x, y, w, h);
+}
+
+static void clear(struct test_target *tt)
+{
+       fill_rect(tt,
+                 GXcopy, 0,
+                 0, 0, tt->width, tt->height);
+}
+
+static void basic_fill(struct test_target *real,
+                      struct test_target *ref)
+{
+       int x = rand() % (2*real->width) - real->width;
+       int y = rand() % (2*real->height) - real->height;
+       int w = rand() % (2*real->width);
+       int h = rand() % (2*real->height);
+       int color = rand();
+       int alu = rand() % 16;
+
+       fill_rect(real, alu, color, x, y, w, h);
+       fill_rect(ref, alu, color, x, y, w, h);
+}
+
+static void basic_copy(struct test_target *real,
+                      struct test_target *ref)
+{
+       int sx = rand() % (2*real->width) - ref->width;
+       int sy = rand() % (2*real->height) - ref->height;
+       int dx = rand() % (2*real->width) - ref->width;
+       int dy = rand() % (2*real->height) - ref->height;
+       int w = rand() % (2*real->width);
+       int h = rand() % (2*real->height);
+       XGCValues val;
+
+       val.function = rand() % 16;
+
+       XChangeGC(real->dpy->dpy, real->gc, GCFunction, &val);
+       XCopyArea(real->dpy->dpy,
+                 real->draw, real->draw, real->gc,
+                 sx, sy, w, h, dx, dy);
+
+       XChangeGC(ref->dpy->dpy, ref->gc, GCFunction, &val);
+       XCopyArea(ref->dpy->dpy,
+                 ref->draw, ref->draw, ref->gc,
+                 sx, sy, w, h, dx, dy);
+}
+
+static void _put(struct test_target *tt,
+                int x, int y, int w,int h, int color, int alu)
+{
+       XImage image;
+       XGCValues val;
+
+       val.function = alu;
+
+       test_init_image(&image, &tt->dpy->shm, tt->format, w, h);
+       pixman_fill((uint32_t*)image.data,
+                   image.bytes_per_line/sizeof(uint32_t),
+                   image.bits_per_pixel,
+                   0, 0, w, h, color);
+
+       XChangeGC(tt->dpy->dpy, tt->gc, GCFunction, &val);
+       if (rand() & 1) {
+               XShmPutImage(tt->dpy->dpy, tt->draw, tt->gc, &image,
+                            0, 0, x, y, w, h, 0);
+               XSync(tt->dpy->dpy, 1);
+       } else {
+               XPutImage(tt->dpy->dpy, tt->draw, tt->gc, &image,
+                         0, 0, x, y, w, h);
+       }
+}
+
+static void basic_put(struct test_target *real,
+                     struct test_target *ref)
+{
+       int x = rand() % (2*real->width) - real->width;
+       int y = rand() % (2*real->height) - real->height;
+       int w = rand() % real->width;
+       int h = rand() % real->height;
+       int color = rand();
+       int alu = rand() % 16;
+
+       _put(real, x, y, w, h, color, alu);
+       _put(ref, x, y, w, h, color, alu);
+}
+
+static void rect_tests(struct test *test, int iterations, enum target target)
+{
+       struct test_target real, ref;
+       void (* const ops[])(struct test_target *, struct test_target *) = {
+               basic_copy,
+               basic_fill,
+               basic_put,
+               render_copy,
+       };
+       int n;
+
+       printf("Running mixed ops stress against %s: ",
+              test_target_name(target));
+       fflush(stdout);
+
+       test_target_create_render(&test->real, target, &real);
+       test_target_create_render(&test->ref, target, &ref);
+
+       clear(&real);
+       clear(&ref);
+
+       for (n = 0; n < iterations; n++)
+               ops[rand() % ARRAY_SIZE(ops)](&real, &ref);
+
+       test_compare(test,
+                    real.draw, real.format,
+                    ref.draw, ref.format,
+                    0, 0, real.width, real.height,
+                    "");
+
+       printf("passed [%d iterations]\n", n);
+
+       test_target_destroy_render(&test->real, &real);
+       test_target_destroy_render(&test->ref, &ref);
+}
+
+int main(int argc, char **argv)
+{
+       struct test test;
+       int i;
+
+       test_init(&test, argc, argv);
+
+       for (i = 0; i <= DEFAULT_ITERATIONS; i++) {
+               int iterations = 1 << i;
+               rect_tests(&test, iterations, 0);
+               rect_tests(&test, iterations, 1);
+       }
+
+       return 0;
+}
diff --git a/test/render-composite-solid.c b/test/render-composite-solid.c
new file mode 100644 (file)
index 0000000..6609c4b
--- /dev/null
@@ -0,0 +1,256 @@
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <X11/Xutil.h> /* for XDestroyImage */
+#include <pixman.h> /* for pixman blt functions */
+
+#include "test.h"
+
+static const uint8_t ops[] = {
+       PictOpClear,
+       PictOpSrc,
+       PictOpDst,
+};
+
+static void fill_rect(struct test_display *dpy, Picture p, uint8_t op,
+                     int x, int y, int w, int h,
+                     uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha)
+{
+       XRenderColor render_color;
+       Picture solid;
+
+       render_color.red   = red * alpha;
+       render_color.green = green * alpha;
+       render_color.blue  = blue * alpha;
+       render_color.alpha = alpha << 8 | alpha;
+
+       solid = XRenderCreateSolidFill(dpy->dpy, &render_color);
+       XRenderComposite(dpy->dpy, op, solid, 0, p, 0, 0, 0, 0, x, y, w,h);
+       XRenderFreePicture(dpy->dpy, solid);
+}
+
+static void pixel_tests(struct test *t, int reps, int sets, enum target target)
+{
+       struct test_target tt;
+       XImage image;
+       uint32_t *cells = malloc(t->real.width*t->real.height*4);
+       struct {
+               uint16_t x, y;
+       } *pixels = malloc(reps*sizeof(*pixels));
+       int r, s;
+
+       test_target_create_render(&t->real, target, &tt);
+
+       printf("Testing setting of single pixels (%s): ",
+              test_target_name(target));
+       fflush(stdout);
+
+       for (s = 0; s < sets; s++) {
+               for (r = 0; r < reps; r++) {
+                       int x = rand() % (tt.width - 1);
+                       int y = rand() % (tt.height - 1);
+                       int red = rand() % 0xff;
+                       int green = rand() % 0xff;
+                       int blue = rand() % 0xff;
+                       int alpha = rand() % 0xff;
+
+                       fill_rect(&t->real, tt.picture, PictOpSrc,
+                                 x, y, 1, 1,
+                                 red, green, blue, alpha);
+
+                       pixels[r].x = x;
+                       pixels[r].y = y;
+                       cells[y*tt.width+x] = color(red, green, blue, alpha);
+               }
+
+               test_init_image(&image, &t->real.shm, tt.format, 1, 1);
+
+               for (r = 0; r < reps; r++) {
+                       uint32_t result;
+                       uint32_t x = pixels[r].x;
+                       uint32_t y = pixels[r].y;
+
+                       XShmGetImage(t->real.dpy, tt.draw, &image,
+                                    x, y, AllPlanes);
+
+                       result = *(uint32_t *)image.data;
+                       if (!pixel_equal(image.depth, result,
+                                        cells[y*tt.width+x])) {
+                               uint32_t mask;
+
+                               if (image.depth == 32)
+                                       mask = 0xffffffff;
+                               else
+                                       mask = (1 << image.depth) - 1;
+                               die("failed to set pixel (%d,%d) to %08x[%08x], found %08x instead\n",
+                                   x, y,
+                                   cells[y*tt.width+x] & mask,
+                                   cells[y*tt.width+x],
+                                   result & mask);
+                       }
+               }
+       }
+       printf("passed [%d iterations x %d]\n", reps, sets);
+
+       test_target_destroy_render(&t->real, &tt);
+       free(pixels);
+       free(cells);
+}
+
+static void clear(struct test_display *dpy, struct test_target *tt)
+{
+       XRenderColor render_color = {0};
+       XRenderFillRectangle(dpy->dpy, PictOpClear, tt->picture, &render_color,
+                            0, 0, tt->width, tt->height);
+}
+
+static void area_tests(struct test *t, int reps, int sets, enum target target)
+{
+       struct test_target tt;
+       XImage image;
+       uint32_t *cells = calloc(sizeof(uint32_t), t->real.width*t->real.height);
+       int r, s, x, y;
+
+       printf("Testing area sets (%s): ", test_target_name(target));
+       fflush(stdout);
+
+       test_target_create_render(&t->real, target, &tt);
+       clear(&t->real, &tt);
+
+       test_init_image(&image, &t->real.shm, tt.format, tt.width, tt.height);
+
+       for (s = 0; s < sets; s++) {
+               for (r = 0; r < reps; r++) {
+                       int w = rand() % tt.width;
+                       int h = rand() % tt.height;
+                       int red = rand() % 0xff;
+                       int green = rand() % 0xff;
+                       int blue = rand() % 0xff;
+                       int alpha = rand() % 0xff;
+
+                       x = rand() % (2*tt.width) - tt.width;
+                       y = rand() % (2*tt.height) - tt.height;
+
+                       fill_rect(&t->real, tt.picture, PictOpSrc,
+                                 x, y, w, h, red, green, blue, alpha);
+
+                       if (x < 0)
+                               w += x, x = 0;
+                       if (y < 0)
+                               h += y, y = 0;
+                       if (x >= tt.width || y >= tt.height)
+                               continue;
+
+                       if (x + w > tt.width)
+                               w = tt.width - x;
+                       if (y + h > tt.height)
+                               h = tt.height - y;
+                       if (w <= 0 || h <= 0)
+                               continue;
+
+                       pixman_fill(cells, tt.width, 32, x, y, w, h,
+                                   color(red, green, blue, alpha));
+               }
+
+               XShmGetImage(t->real.dpy, tt.draw, &image, 0, 0, AllPlanes);
+
+               for (y = 0; y < tt.height; y++) {
+                       for (x = 0; x < tt.width; x++) {
+                               uint32_t result =
+                                       *(uint32_t *)(image.data +
+                                                     y*image.bytes_per_line +
+                                                     image.bits_per_pixel*x/8);
+                               if (!pixel_equal(image.depth, result, cells[y*tt.width+x])) {
+                                       uint32_t mask;
+                                       if (image.depth == 32)
+                                               mask = 0xffffffff;
+                                       else
+                                               mask = (1 << image.depth) - 1;
+                                       die("failed to set pixel (%d,%d) to %08x[%08x], found %08x instead\n",
+                                           x, y,
+                                           cells[y*tt.width+x] & mask,
+                                           cells[y*tt.width+x],
+                                           result & mask);
+                               }
+                       }
+               }
+       }
+
+       printf("passed [%d iterations x %d]\n", reps, sets);
+
+       test_target_destroy_render(&t->real, &tt);
+       free(cells);
+}
+
+static void rect_tests(struct test *t, int reps, int sets, enum target target)
+{
+       struct test_target real, ref;
+       int r, s;
+
+       printf("Testing area fills (%s): ", test_target_name(target));
+       fflush(stdout);
+
+       test_target_create_render(&t->real, target, &real);
+       clear(&t->real, &real);
+
+       test_target_create_render(&t->ref, target, &ref);
+       clear(&t->ref, &ref);
+
+       for (s = 0; s < sets; s++) {
+               for (r = 0; r < reps; r++) {
+                       int x = rand() % (2*real.width) - real.width;
+                       int y = rand() % (2*real.height) - real.height;
+                       int w = rand() % real.width;
+                       int h = rand() % real.height;
+                       int op = ops[rand() % sizeof(ops)];
+                       int red = rand() % 0xff;
+                       int green = rand() % 0xff;
+                       int blue = rand() % 0xff;
+                       int alpha = rand() % 0xff;
+
+                       fill_rect(&t->real, real.picture,
+                                 op, x, y, w, h,
+                                 red, green, blue, alpha);
+                       fill_rect(&t->ref, ref.picture,
+                                 op, x, y, w, h,
+                                 red, green, blue, alpha);
+               }
+
+               test_compare(t,
+                            real.draw, real.format,
+                            ref.draw, ref.format,
+                            0, 0, real.width, real.height,
+                            "");
+       }
+
+       printf("passed [%d iterations x %d]\n", reps, sets);
+
+       test_target_destroy_render(&t->real, &real);
+       test_target_destroy_render(&t->ref, &ref);
+}
+
+int main(int argc, char **argv)
+{
+       struct test test;
+       int i;
+
+       test_init(&test, argc, argv);
+
+       for (i = 0; i <= DEFAULT_ITERATIONS; i++) {
+               int reps = 1 << i;
+               int sets = 1 << (12 - i);
+               enum target t;
+
+               if (sets < 2)
+                       sets = 2;
+
+               for (t = TARGET_FIRST; t <= TARGET_LAST; t++) {
+                       pixel_tests(&test, reps, sets, t);
+                       area_tests(&test, reps, sets, t);
+                       rect_tests(&test, reps, sets, t);
+               }
+       }
+
+       return 0;
+}
diff --git a/test/render-copy-alphaless.c b/test/render-copy-alphaless.c
new file mode 100644 (file)
index 0000000..b968704
--- /dev/null
@@ -0,0 +1,285 @@
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <X11/Xutil.h> /* for XDestroyImage */
+#include <pixman.h> /* for pixman blt functions */
+
+#include "test.h"
+
+static void
+show_cells(char *buf,
+          const uint32_t *real, const uint32_t *ref,
+          int x, int y, int w, int h)
+{
+       int i, j, len = 0;
+
+       for (j = y - 2; j <= y + 2; j++) {
+               if (j < 0 || j >= h)
+                       continue;
+
+               for (i = x - 2; i <= x + 2; i++) {
+                       if (i < 0 || i >= w)
+                               continue;
+
+                       len += sprintf(buf+len, "%08x ", real[j*w+i]);
+               }
+
+               len += sprintf(buf+len, "\t");
+
+               for (i = x - 2; i <= x + 2; i++) {
+                       if (i < 0 || i >= w)
+                               continue;
+
+                       len += sprintf(buf+len, "%08x ", ref[j*w+i]);
+               }
+
+               len += sprintf(buf+len, "\n");
+       }
+}
+
+static void fill_rect(struct test_display *t, Picture p,
+                     int x, int y, int w, int h,
+                     uint8_t red, uint8_t green, uint8_t blue)
+{
+       Drawable tmp;
+       XRenderColor c;
+       Picture src;
+       XRenderPictFormat *format;
+
+       format = XRenderFindStandardFormat(t->dpy, PictStandardRGB24);
+
+       tmp = XCreatePixmap(t->dpy, DefaultRootWindow(t->dpy),
+                           w, h, format->depth);
+
+       src = XRenderCreatePicture(t->dpy, tmp, format, 0, NULL);
+       c.red = (int)red << 8 | red;
+       c.green = (int)green << 8 | green;
+       c.blue = (int)blue << 8 | blue;
+       c.alpha = 0xffff;
+       XRenderFillRectangle(t->dpy, PictOpSrc, src, &c, 0, 0, w, h);
+       XRenderComposite(t->dpy, PictOpOver, src, 0, p, 0, 0, 0, 0, x, y, w, h);
+
+       XRenderFreePicture(t->dpy, src);
+       XFreePixmap(t->dpy, tmp);
+}
+
+static void pixel_tests(struct test *t, int reps, int sets, enum target target)
+{
+       struct test_target tt;
+       XImage image;
+       uint32_t *cells = malloc(t->real.width*t->real.height*4);
+       struct {
+               uint16_t x, y;
+       } *pixels = malloc(reps*sizeof(*pixels));
+       int r, s;
+
+       test_target_create_render(&t->real, target, &tt);
+
+       printf("Testing setting of single pixels (%s): ",
+              test_target_name(target));
+       fflush(stdout);
+
+       for (s = 0; s < sets; s++) {
+               for (r = 0; r < reps; r++) {
+                       int x = rand() % (tt.width - 1);
+                       int y = rand() % (tt.height - 1);
+                       uint8_t red = rand();
+                       uint8_t green = rand();
+                       uint8_t blue = rand();
+
+                       fill_rect(&t->real, tt.picture,
+                                 x, y, 1, 1,
+                                 red, green, blue);
+
+                       pixels[r].x = x;
+                       pixels[r].y = y;
+                       cells[y*tt.width+x] = color(red, green, blue, 0xff);
+               }
+
+               test_init_image(&image, &t->real.shm, tt.format, 1, 1);
+
+               for (r = 0; r < reps; r++) {
+                       uint32_t x = pixels[r].x;
+                       uint32_t y = pixels[r].y;
+                       uint32_t result;
+
+                       XShmGetImage(t->real.dpy, tt.draw, &image,
+                                    x, y, AllPlanes);
+
+                       result = *(uint32_t *)image.data;
+                       if (!pixel_equal(image.depth, result,
+                                        cells[y*tt.width+x])) {
+                               uint32_t mask = depth_mask(image.depth);
+
+                               die("failed to set pixel (%d,%d) to %08x [%08x], found %08x [%08x] instead\n",
+                                   x, y,
+                                   cells[y*tt.width+x] & mask,
+                                   cells[y*tt.width+x],
+                                   result & mask,
+                                   result);
+                       }
+               }
+       }
+       printf("passed [%d iterations x %d]\n", reps, sets);
+
+       test_target_destroy_render(&t->real, &tt);
+       free(pixels);
+       free(cells);
+}
+
+static void clear(struct test_display *dpy, struct test_target *tt)
+{
+       XRenderColor render_color = {0};
+       XRenderFillRectangle(dpy->dpy, PictOpClear, tt->picture, &render_color,
+                            0, 0, tt->width, tt->height);
+}
+
+static void area_tests(struct test *t, int reps, int sets, enum target target)
+{
+       struct test_target tt;
+       XImage image;
+       uint32_t *cells = calloc(sizeof(uint32_t), t->real.width*t->real.height);
+       int r, s, x, y;
+
+       printf("Testing area sets (%s): ", test_target_name(target));
+       fflush(stdout);
+
+       test_target_create_render(&t->real, target, &tt);
+       clear(&t->real, &tt);
+
+       test_init_image(&image, &t->real.shm, tt.format, tt.width, tt.height);
+
+       for (s = 0; s < sets; s++) {
+               for (r = 0; r < reps; r++) {
+                       int w = 1 + rand() % (tt.width - 1);
+                       int h = 1 + rand() % (tt.height - 1);
+                       uint8_t red = rand();
+                       uint8_t green = rand();
+                       uint8_t blue = rand();
+
+                       x = rand() % (2*tt.width) - tt.width;
+                       y = rand() % (2*tt.height) - tt.height;
+
+                       fill_rect(&t->real, tt.picture,
+                                 x, y, w, h,
+                                 red, green, blue);
+
+                       if (x < 0)
+                               w += x, x = 0;
+                       if (y < 0)
+                               h += y, y = 0;
+                       if (x >= tt.width || y >= tt.height)
+                               continue;
+
+                       if (x + w > tt.width)
+                               w = tt.width - x;
+                       if (y + h > tt.height)
+                               h = tt.height - y;
+                       if (w <= 0 || h <= 0)
+                               continue;
+
+                       pixman_fill(cells, tt.width, 32, x, y, w, h,
+                                   color(red, green, blue, 0xff));
+               }
+
+               XShmGetImage(t->real.dpy, tt.draw, &image, 0, 0, AllPlanes);
+
+               for (y = 0; y < tt.height; y++) {
+                       for (x = 0; x < tt.width; x++) {
+                               uint32_t result = *(uint32_t *)
+                                       (image.data +
+                                        y*image.bytes_per_line +
+                                        x*image.bits_per_pixel/8);
+                               if (!pixel_equal(image.depth, result, cells[y*tt.width+x])) {
+                                       char buf[600];
+                                       uint32_t mask = depth_mask(image.depth);
+                                       show_cells(buf,
+                                                  (uint32_t*)image.data, cells,
+                                                  x, y, tt.width, tt.height);
+
+                                       die("failed to set pixel (%d,%d) to %08x [%08x], found %08x [%08x] instead (set %d, reps %d)\n%s",
+                                           x, y,
+                                           cells[y*tt.width+x] & mask,
+                                           cells[y*tt.width+x],
+                                           result & mask,
+                                           result, s, reps, buf);
+                               }
+                       }
+               }
+       }
+
+       printf("passed [%d iterations x %d]\n", reps, sets);
+
+       test_target_destroy_render(&t->real, &tt);
+       free(cells);
+}
+
+static void rect_tests(struct test *t, int reps, int sets, enum target target, int use_window)
+{
+       struct test_target real, ref;
+       int r, s;
+       printf("Testing area fills (%s, using %s source): ",
+              test_target_name(target), use_window ? "window" : "pixmap");
+       fflush(stdout);
+
+       test_target_create_render(&t->real, target, &real);
+       clear(&t->real, &real);
+
+       test_target_create_render(&t->ref, target, &ref);
+       clear(&t->ref, &ref);
+
+       for (s = 0; s < sets; s++) {
+               for (r = 0; r < reps; r++) {
+                       int x, y, w, h;
+                       uint8_t red = rand();
+                       uint8_t green = rand();
+                       uint8_t blue = rand();
+
+                       x = rand() % (real.width - 1);
+                       y = rand() % (real.height - 1);
+                       w = 1 + rand() % (real.width - x - 1);
+                       h = 1 + rand() % (real.height - y - 1);
+
+                       fill_rect(&t->real, real.picture,
+                                 x, y, w, h,
+                                 red, green, blue);
+                       fill_rect(&t->ref, ref.picture,
+                                 x, y, w, h,
+                                 red, green, blue);
+               }
+
+               test_compare(t,
+                            real.draw, real.format,
+                            ref.draw, ref.format,
+                            0, 0, real.width, real.height,
+                            "");
+       }
+
+       printf("passed [%d iterations x %d]\n", reps, sets);
+
+       test_target_destroy_render(&t->real, &real);
+       test_target_destroy_render(&t->ref, &ref);
+}
+
+int main(int argc, char **argv)
+{
+       struct test test;
+       int i;
+
+       test_init(&test, argc, argv);
+
+       for (i = 0; i <= DEFAULT_ITERATIONS; i++) {
+               int reps = 1 << i;
+               int sets = 1 << (12 - i);
+
+               if (sets < 2)
+                       sets = 2;
+
+               pixel_tests(&test, reps, sets, PIXMAP);
+               area_tests(&test, reps, sets, PIXMAP);
+               rect_tests(&test, reps, sets, PIXMAP, 0);
+       }
+
+       return 0;
+}
diff --git a/test/render-copyarea-size.c b/test/render-copyarea-size.c
new file mode 100644 (file)
index 0000000..65fb6ca
--- /dev/null
@@ -0,0 +1,117 @@
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <X11/Xutil.h> /* for XDestroyImage */
+
+#include "test.h"
+
+#define SIZE 20000
+struct draw {
+       Pixmap a, b;
+       Picture pa, pb;
+       GC gc;
+       XRenderPictFormat *format;
+};
+
+static void target_init(struct test_display *t, struct draw *tt, int size)
+{
+       XRenderColor color;
+
+       tt->format = XRenderFindStandardFormat(t->dpy, PictStandardARGB32);
+
+       tt->a = XCreatePixmap(t->dpy, DefaultRootWindow(t->dpy),
+                             size, size, tt->format->depth);
+       tt->pa = XRenderCreatePicture(t->dpy, tt->a, tt->format, 0, NULL);
+
+       color.alpha = 0xffff;
+       color.red = 0xffff;
+       color.green = 0;
+       color.blue = 0;
+       XRenderFillRectangle(t->dpy, PictOpSrc, tt->pa, &color, 0, 0, size, size);
+
+       tt->b = XCreatePixmap(t->dpy, DefaultRootWindow(t->dpy),
+                             size, size, tt->format->depth);
+       tt->pb = XRenderCreatePicture(t->dpy, tt->b, tt->format, 0, NULL);
+
+       color.alpha = 0xffff;
+       color.red = 0;
+       color.green = 0;
+       color.blue = 0xffff;
+       XRenderFillRectangle(t->dpy, PictOpSrc, tt->pb, &color, 0, 0, size, size);
+}
+
+static void target_fini(struct test_display *t, struct draw *tt)
+{
+       XRenderFreePicture(t->dpy, tt->pa);
+       XFreePixmap(t->dpy, tt->a);
+
+       XRenderFreePicture(t->dpy, tt->pb);
+       XFreePixmap(t->dpy, tt->b);
+}
+
+int main(int argc, char **argv)
+{
+       struct test test;
+       struct draw real, ref;
+       int size, i;
+
+       test_init(&test, argc, argv);
+
+       /* Copy back and forth betwenn two pixmaps, gradually getting larger */
+       for (size = 1; size <= SIZE; size = (size * 3 + 1) / 2) {
+               target_init(&test.real, &real, size);
+               target_init(&test.ref, &ref, size);
+
+               printf("size=%d\n", size);
+               for (i = 0; i <= DEFAULT_ITERATIONS; i++) {
+                       int reps = 1 << i;
+                       do {
+                               int sx = rand() % (2*size) - size;
+                               int sy = rand() % (2*size) - size;
+
+                               int dx = rand() % (2*size) - size;
+                               int dy = rand() % (2*size) - size;
+
+                               int w = rand() % size;
+                               int h = rand() % size;
+
+                               int order = rand() & 1;
+
+                               XRenderComposite(test.real.dpy, PictOpSrc,
+                                                order ? real.pa : real.pb,
+                                                0,
+                                                (!order) ? real.pa : real.pb,
+                                                sx, sy,
+                                                0, 0,
+                                                dx, dy,
+                                                w, h);
+
+                               XRenderComposite(test.ref.dpy, PictOpSrc,
+                                                order ? ref.pa : ref.pb,
+                                                0,
+                                                (!order) ? ref.pa : ref.pb,
+                                                sx, sy,
+                                                0, 0,
+                                                dx, dy,
+                                                w, h);
+                       } while (--reps);
+               }
+
+               test_compare(&test,
+                            real.a, real.format,
+                            ref.a, ref.format,
+                            0, 0, size, size,
+                            "");
+               test_compare(&test,
+                            real.b, real.format,
+                            ref.b, ref.format,
+                            0, 0, size, size,
+                            "");
+
+               target_fini(&test.real, &real);
+               target_fini(&test.ref, &ref);
+       }
+
+       return 0;
+}
diff --git a/test/render-copyarea.c b/test/render-copyarea.c
new file mode 100644 (file)
index 0000000..bcab553
--- /dev/null
@@ -0,0 +1,325 @@
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <X11/Xutil.h> /* for XDestroyImage */
+#include <pixman.h> /* for pixman blt functions */
+
+#include "test.h"
+
+static void
+show_cells(char *buf,
+          const uint32_t *real, const uint32_t *ref,
+          int x, int y, int w, int h)
+{
+       int i, j, len = 0;
+
+       for (j = y - 2; j <= y + 2; j++) {
+               if (j < 0 || j >= h)
+                       continue;
+
+               for (i = x - 2; i <= x + 2; i++) {
+                       if (i < 0 || i >= w)
+                               continue;
+
+                       len += sprintf(buf+len, "%08x ", real[j*w+i]);
+               }
+
+               len += sprintf(buf+len, "\t");
+
+               for (i = x - 2; i <= x + 2; i++) {
+                       if (i < 0 || i >= w)
+                               continue;
+
+                       len += sprintf(buf+len, "%08x ", ref[j*w+i]);
+               }
+
+               len += sprintf(buf+len, "\n");
+       }
+}
+
+static void fill_rect(struct test_display *t,
+                     Picture p,
+                     XRenderPictFormat *format,
+                     int use_window, int tx, int ty,
+                     uint8_t op, int x, int y, int w, int h,
+                     uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha)
+{
+       Drawable tmp;
+       XRenderColor color;
+       Picture src;
+
+       if (use_window) {
+               XSetWindowAttributes attr;
+
+               attr.override_redirect = 1;
+               tmp = XCreateWindow(t->dpy, DefaultRootWindow(t->dpy),
+                                   tx, ty,
+                                   w, h,
+                                   0, format->depth,
+                                   InputOutput,
+                                   DefaultVisual(t->dpy,
+                                                 DefaultScreen(t->dpy)),
+                                   CWOverrideRedirect, &attr);
+               XMapWindow(t->dpy, tmp);
+       } else
+               tmp = XCreatePixmap(t->dpy, DefaultRootWindow(t->dpy),
+                                   w, h, format->depth);
+
+       src = XRenderCreatePicture(t->dpy, tmp, format, 0, NULL);
+       color.red = red * alpha;
+       color.green = green * alpha;
+       color.blue = blue * alpha;
+       color.alpha = alpha << 8 | alpha;
+       XRenderFillRectangle(t->dpy, PictOpSrc, src, &color, 0, 0, w, h);
+       XRenderComposite(t->dpy, op, src, 0, p, 0, 0, 0, 0, x, y, w, h);
+
+       XRenderFreePicture(t->dpy, src);
+       if (use_window)
+               XDestroyWindow(t->dpy, tmp);
+       else
+               XFreePixmap(t->dpy, tmp);
+}
+
+static void pixel_tests(struct test *t, int reps, int sets, enum target target)
+{
+       struct test_target tt;
+       XImage image;
+       uint32_t *cells = malloc(t->real.width*t->real.height*4);
+       struct {
+               uint16_t x, y;
+       } *pixels = malloc(reps*sizeof(*pixels));
+       int r, s;
+
+       test_target_create_render(&t->real, target, &tt);
+
+       printf("Testing setting of single pixels (%s): ",
+              test_target_name(target));
+       fflush(stdout);
+
+       for (s = 0; s < sets; s++) {
+               for (r = 0; r < reps; r++) {
+                       int x = rand() % (tt.width - 1);
+                       int y = rand() % (tt.height - 1);
+                       uint8_t red = rand();
+                       uint8_t green = rand();
+                       uint8_t blue = rand();
+                       uint8_t alpha = rand();
+
+                       fill_rect(&t->real, tt.picture, tt.format,
+                                 0, 0, 0,
+                                 PictOpSrc, x, y, 1, 1,
+                                 red, green, blue, alpha);
+
+                       pixels[r].x = x;
+                       pixels[r].y = y;
+                       cells[y*tt.width+x] = color(red, green, blue, alpha);
+               }
+
+               test_init_image(&image, &t->real.shm, tt.format, 1, 1);
+
+               for (r = 0; r < reps; r++) {
+                       uint32_t x = pixels[r].x;
+                       uint32_t y = pixels[r].y;
+                       uint32_t result;
+
+                       XShmGetImage(t->real.dpy, tt.draw, &image,
+                                    x, y, AllPlanes);
+
+                       result = *(uint32_t *)image.data;
+                       if (!pixel_equal(image.depth, result,
+                                        cells[y*tt.width+x])) {
+                               uint32_t mask = depth_mask(image.depth);
+
+                               die("failed to set pixel (%d,%d) to %08x [%08x], found %08x [%08x] instead\n",
+                                   x, y,
+                                   cells[y*tt.width+x] & mask,
+                                   cells[y*tt.width+x],
+                                   result & mask,
+                                   result);
+                       }
+               }
+       }
+       printf("passed [%d iterations x %d]\n", reps, sets);
+
+       test_target_destroy_render(&t->real, &tt);
+       free(pixels);
+       free(cells);
+}
+
+static void clear(struct test_display *dpy, struct test_target *tt)
+{
+       XRenderColor render_color = {0};
+       XRenderFillRectangle(dpy->dpy, PictOpClear, tt->picture, &render_color,
+                            0, 0, tt->width, tt->height);
+}
+
+static void area_tests(struct test *t, int reps, int sets, enum target target)
+{
+       struct test_target tt;
+       XImage image;
+       uint32_t *cells = calloc(sizeof(uint32_t), t->real.width*t->real.height);
+       int r, s, x, y;
+
+       printf("Testing area sets (%s): ", test_target_name(target));
+       fflush(stdout);
+
+       test_target_create_render(&t->real, target, &tt);
+       clear(&t->real, &tt);
+
+       test_init_image(&image, &t->real.shm, tt.format, tt.width, tt.height);
+
+       for (s = 0; s < sets; s++) {
+               for (r = 0; r < reps; r++) {
+                       int w = 1 + rand() % (tt.width - 1);
+                       int h = 1 + rand() % (tt.height - 1);
+                       uint8_t red = rand();
+                       uint8_t green = rand();
+                       uint8_t blue = rand();
+                       uint8_t alpha = rand();
+
+                       x = rand() % (2*tt.width) - tt.width;
+                       y = rand() % (2*tt.height) - tt.height;
+
+                       fill_rect(&t->real, tt.picture, tt.format,
+                                 0, 0, 0,
+                                 PictOpSrc, x, y, w, h,
+                                 red, green, blue, alpha);
+
+                       if (x < 0)
+                               w += x, x = 0;
+                       if (y < 0)
+                               h += y, y = 0;
+                       if (x >= tt.width || y >= tt.height)
+                               continue;
+
+                       if (x + w > tt.width)
+                               w = tt.width - x;
+                       if (y + h > tt.height)
+                               h = tt.height - y;
+                       if (w <= 0 || h <= 0)
+                               continue;
+
+                       pixman_fill(cells, tt.width, 32, x, y, w, h,
+                                   color(red, green, blue, alpha));
+               }
+
+               XShmGetImage(t->real.dpy, tt.draw, &image, 0, 0, AllPlanes);
+
+               for (y = 0; y < tt.height; y++) {
+                       for (x = 0; x < tt.width; x++) {
+                               uint32_t result = *(uint32_t *)
+                                       (image.data +
+                                        y*image.bytes_per_line +
+                                        x*image.bits_per_pixel/8);
+                               if (!pixel_equal(image.depth, result, cells[y*tt.width+x])) {
+                                       char buf[600];
+                                       uint32_t mask = depth_mask(image.depth);
+                                       show_cells(buf,
+                                                  (uint32_t*)image.data, cells,
+                                                  x, y, tt.width, tt.height);
+
+                                       die("failed to set pixel (%d,%d) to %08x [%08x], found %08x [%08x] instead\n%s",
+                                           x, y,
+                                           cells[y*tt.width+x] & mask,
+                                           cells[y*tt.width+x],
+                                           result & mask,
+                                           result, buf);
+                               }
+                       }
+               }
+       }
+
+       printf("passed [%d iterations x %d]\n", reps, sets);
+
+       test_target_destroy_render(&t->real, &tt);
+       free(cells);
+}
+
+static void rect_tests(struct test *t, int reps, int sets, enum target target, int use_window)
+{
+       struct test_target real, ref;
+       int r, s;
+       printf("Testing area fills (%s, using %s source): ",
+              test_target_name(target), use_window ? "window" : "pixmap");
+       fflush(stdout);
+
+       test_target_create_render(&t->real, target, &real);
+       clear(&t->real, &real);
+
+       test_target_create_render(&t->ref, target, &ref);
+       clear(&t->ref, &ref);
+
+       for (s = 0; s < sets; s++) {
+               for (r = 0; r < reps; r++) {
+                       int x, y, w, h;
+                       int tmpx, tmpy;
+                       uint8_t red = rand();
+                       uint8_t green = rand();
+                       uint8_t blue = rand();
+                       uint8_t alpha = rand();
+                       int try = 50;
+
+                       do {
+                               x = rand() % (real.width - 1);
+                               y = rand() % (real.height - 1);
+                               w = 1 + rand() % (real.width - x - 1);
+                               h = 1 + rand() % (real.height - y - 1);
+                               tmpx = w == real.width ? 0 : rand() % (real.width - w);
+                               tmpy = h == real.height ? 0 : rand() % (real.height - h);
+                       } while (((tmpx+w > x && tmpx < x+w) ||
+                                 (tmpy+h > y && tmpy < y+h)) &&
+                                --try);
+
+
+                       if (try) {
+                               fill_rect(&t->real, real.picture, real.format,
+                                         use_window, tmpx, tmpy,
+                                         PictOpSrc, x, y, w, h,
+                                         red, green, blue, alpha);
+                               fill_rect(&t->ref, ref.picture, ref.format,
+                                         use_window, tmpx, tmpy,
+                                         PictOpSrc, x, y, w, h,
+                                         red, green, blue, alpha);
+                       }
+               }
+
+               test_compare(t,
+                            real.draw, real.format,
+                            ref.draw, ref.format,
+                            0, 0, real.width, real.height,
+                            "");
+       }
+
+       printf("passed [%d iterations x %d]\n", reps, sets);
+
+       test_target_destroy_render(&t->real, &real);
+       test_target_destroy_render(&t->ref, &ref);
+}
+
+int main(int argc, char **argv)
+{
+       struct test test;
+       int i;
+
+       test_init(&test, argc, argv);
+
+       for (i = 0; i <= DEFAULT_ITERATIONS; i++) {
+               int reps = 1 << i;
+               int sets = 1 << (12 - i);
+               enum target t;
+
+               if (sets < 2)
+                       sets = 2;
+
+               for (t = TARGET_FIRST; t <= TARGET_LAST; t++) {
+                       pixel_tests(&test, reps, sets, t);
+                       area_tests(&test, reps, sets, t);
+                       rect_tests(&test, reps, sets, t, 0);
+                       if (t != PIXMAP)
+                           rect_tests(&test, reps, sets, t, 1);
+               }
+       }
+
+       return 0;
+}
diff --git a/test/render-fill-copy.c b/test/render-fill-copy.c
new file mode 100644 (file)
index 0000000..bc4a734
--- /dev/null
@@ -0,0 +1,280 @@
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <X11/Xutil.h> /* for XDestroyImage */
+#include <pixman.h> /* for pixman blt functions */
+
+#include "test.h"
+
+static const uint8_t ops[] = {
+       PictOpClear,
+       PictOpSrc,
+       PictOpDst,
+};
+
+static void fill_rect(struct test_display *dpy,
+                     Picture p,
+                     XRenderPictFormat *format,
+                     uint8_t op, int x, int y, int w, int h,
+                     uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha)
+{
+       Display *d = dpy->dpy;
+       XRenderColor render_color;
+       Pixmap pixmap1, pixmap2;
+       Picture tmp1, tmp2;
+       XRenderPictureAttributes pa;
+       GC gc;
+
+       render_color.red   = red * alpha;
+       render_color.green = green * alpha;
+       render_color.blue  = blue * alpha;
+       render_color.alpha = alpha << 8;
+
+       pixmap1 = XCreatePixmap(d, dpy->root, 1, 1, format->depth);
+       tmp1 = XRenderCreatePicture(d, pixmap1, format, 0, NULL);
+
+       pixmap2 = XCreatePixmap(d, dpy->root, 1, 1, format->depth);
+       pa.repeat = 1;
+       tmp2 = XRenderCreatePicture(d, pixmap2, format, CPRepeat, &pa);
+
+       gc = XCreateGC(d, pixmap1, 0, NULL);
+
+       XRenderFillRectangle(d, PictOpSrc, tmp1, &render_color, 0, 0, 1,1);
+       XCopyArea(d, pixmap1, pixmap2, gc, 0, 0, 1, 1, 0, 0);
+       XRenderComposite(d, PictOpSrc, tmp2, 0, p, 0, 0, 0, 0, x, y, w,h);
+
+       XFreeGC(d, gc);
+
+       XRenderFreePicture(d, tmp2);
+       XFreePixmap(d, pixmap2);
+
+       XRenderFreePicture(d, tmp1);
+       XFreePixmap(d, pixmap1);
+}
+
+static void pixel_tests(struct test *t, int reps, int sets, enum target target)
+{
+       struct test_target tt;
+       XImage image;
+       uint32_t *cells = malloc(t->real.width*t->real.height*4);
+       struct {
+               uint16_t x, y;
+       } *pixels = malloc(reps*sizeof(*pixels));
+       int r, s;
+
+       test_target_create_render(&t->real, target, &tt);
+
+       printf("Testing setting of single pixels (%s): ",
+              test_target_name(target));
+       fflush(stdout);
+
+       for (s = 0; s < sets; s++) {
+               for (r = 0; r < reps; r++) {
+                       int x = rand() % (tt.width - 1);
+                       int y = rand() % (tt.height - 1);
+                       int red = rand() % 0xff;
+                       int green = rand() % 0xff;
+                       int blue = rand() % 0xff;
+                       int alpha = rand() % 0xff;
+
+                       fill_rect(&t->real, tt.picture, tt.format,
+                                 PictOpSrc, x, y, 1, 1,
+                                 red, green, blue, alpha);
+
+                       pixels[r].x = x;
+                       pixels[r].y = y;
+                       cells[y*tt.width+x] = color(red, green, blue, alpha);
+               }
+
+               test_init_image(&image, &t->real.shm, tt.format, 1, 1);
+
+               for (r = 0; r < reps; r++) {
+                       uint32_t result;
+                       uint32_t x = pixels[r].x;
+                       uint32_t y = pixels[r].y;
+
+                       XShmGetImage(t->real.dpy, tt.draw, &image,
+                                    x, y, AllPlanes);
+
+                       result = *(uint32_t *)image.data;
+                       if (!pixel_equal(image.depth, result,
+                                        cells[y*tt.width+x])) {
+                               uint32_t mask;
+
+                               if (image.depth == 32)
+                                       mask = 0xffffffff;
+                               else
+                                       mask = (1 << image.depth) - 1;
+                               die("failed to set pixel (%d,%d) to %08x, found %08x instead\n",
+                                   x, y,
+                                   cells[y*tt.width+x] & mask,
+                                   result & mask);
+                       }
+               }
+       }
+       printf("passed [%d iterations x %d]\n", reps, sets);
+
+       test_target_destroy_render(&t->real, &tt);
+       free(pixels);
+       free(cells);
+}
+
+static void clear(struct test_display *dpy, struct test_target *tt)
+{
+       XRenderColor render_color = {0};
+       XRenderFillRectangle(dpy->dpy, PictOpClear, tt->picture, &render_color,
+                            0, 0, tt->width, tt->height);
+}
+
+static void area_tests(struct test *t, int reps, int sets, enum target target)
+{
+       struct test_target tt;
+       XImage image;
+       uint32_t *cells = calloc(sizeof(uint32_t), t->real.width*t->real.height);
+       int r, s, x, y;
+
+       printf("Testing area sets (%s): ", test_target_name(target));
+       fflush(stdout);
+
+       test_target_create_render(&t->real, target, &tt);
+       clear(&t->real, &tt);
+
+       test_init_image(&image, &t->real.shm, tt.format, tt.width, tt.height);
+
+       for (s = 0; s < sets; s++) {
+               for (r = 0; r < reps; r++) {
+                       int w = rand() % tt.width;
+                       int h = rand() % tt.height;
+                       int red = rand() % 0xff;
+                       int green = rand() % 0xff;
+                       int blue = rand() % 0xff;
+                       int alpha = rand() % 0xff;
+
+                       x = rand() % (2*tt.width) - tt.width;
+                       y = rand() % (2*tt.height) - tt.height;
+
+                       fill_rect(&t->real, tt.picture, tt.format,
+                                 PictOpSrc, x, y, w, h,
+                                 red, green, blue, alpha);
+
+                       if (x < 0)
+                               w += x, x = 0;
+                       if (y < 0)
+                               h += y, y = 0;
+                       if (x >= tt.width || y >= tt.height)
+                               continue;
+
+                       if (x + w > tt.width)
+                               w = tt.width - x;
+                       if (y + h > tt.height)
+                               h = tt.height - y;
+                       if (w <= 0 || h <= 0)
+                               continue;
+
+                       pixman_fill(cells, tt.width, 32, x, y, w, h,
+                                   color(red, green, blue, alpha));
+               }
+
+               XShmGetImage(t->real.dpy, tt.draw, &image, 0, 0, AllPlanes);
+
+               for (y = 0; y < tt.height; y++) {
+                       for (x = 0; x < tt.width; x++) {
+                               uint32_t result =
+                                       *(uint32_t *)(image.data +
+                                                     y*image.bytes_per_line +
+                                                     image.bits_per_pixel*x/8);
+                               if (!pixel_equal(image.depth, result,
+                                                cells[y*tt.width+x])) {
+                                       uint32_t mask;
+
+                                       if (image.depth == 32)
+                                               mask = 0xffffffff;
+                                       else
+                                               mask = (1 << image.depth) - 1;
+                                       die("failed to set pixel (%d,%d) to %08x, found %08x instead\n",
+                                           x, y,
+                                           cells[y*tt.width+x] & mask,
+                                           result & mask);
+                               }
+                       }
+               }
+       }
+
+       printf("passed [%d iterations x %d]\n", reps, sets);
+
+       test_target_destroy_render(&t->real, &tt);
+       free(cells);
+}
+
+static void rect_tests(struct test *t, int reps, int sets, enum target target)
+{
+       struct test_target real, ref;
+       int r, s;
+
+       printf("Testing area fills (%s): ", test_target_name(target));
+       fflush(stdout);
+
+       test_target_create_render(&t->real, target, &real);
+       clear(&t->real, &real);
+
+       test_target_create_render(&t->ref, target, &ref);
+       clear(&t->ref, &ref);
+
+       for (s = 0; s < sets; s++) {
+               for (r = 0; r < reps; r++) {
+                       int x = rand() % (2*real.width) - real.width;
+                       int y = rand() % (2*real.height) - real.height;
+                       int w = rand() % real.width;
+                       int h = rand() % real.height;
+                       int op = ops[rand() % sizeof(ops)];
+                       int red = rand() % 0xff;
+                       int green = rand() % 0xff;
+                       int blue = rand() % 0xff;
+                       int alpha = rand() % 0xff;
+
+                       fill_rect(&t->real, real.picture, real.format,
+                                 op, x, y, w, h,
+                                 red, green, blue, alpha);
+                       fill_rect(&t->ref, ref.picture, ref.format,
+                                 op, x, y, w, h,
+                                 red, green, blue, alpha);
+               }
+
+               test_compare(t,
+                            real.draw, real.format,
+                            ref.draw, ref.format,
+                            0, 0, real.width, real.height,
+                            "");
+       }
+
+       printf("passed [%d iterations x %d]\n", reps, sets);
+
+       test_target_destroy_render(&t->real, &real);
+       test_target_destroy_render(&t->ref, &ref);
+}
+
+int main(int argc, char **argv)
+{
+       struct test test;
+       int i;
+
+       test_init(&test, argc, argv);
+
+       for (i = 0; i <= DEFAULT_ITERATIONS; i++) {
+               int reps = 1 << i;
+               int sets = 1 << (12 - i);
+               enum target t;
+
+               if (sets < 2)
+                       sets = 2;
+
+               for (t = TARGET_FIRST; t <= TARGET_LAST; t++) {
+                       pixel_tests(&test, reps, sets, t);
+                       area_tests(&test, reps, sets, t);
+                       rect_tests(&test, reps, sets, t);
+               }
+       }
+
+       return 0;
+}
diff --git a/test/render-fill.c b/test/render-fill.c
new file mode 100644 (file)
index 0000000..27d565b
--- /dev/null
@@ -0,0 +1,248 @@
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <X11/Xutil.h> /* for XDestroyImage */
+#include <pixman.h> /* for pixman blt functions */
+
+#include "test.h"
+
+static const uint8_t ops[] = {
+       PictOpClear,
+       PictOpSrc,
+       PictOpDst,
+};
+
+static void fill_rect(struct test_display *dpy, Picture p, uint8_t op,
+                     int x, int y, int w, int h,
+                     uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha)
+{
+       XRenderColor render_color;
+
+       render_color.red   = red * alpha;
+       render_color.green = green * alpha;
+       render_color.blue  = blue * alpha;
+       render_color.alpha = alpha << 8;
+
+       XRenderFillRectangle(dpy->dpy, op, p, &render_color, x, y, w,h);
+}
+
+static void pixel_tests(struct test *t, int reps, int sets, enum target target)
+{
+       struct test_target tt;
+       XImage image;
+       uint32_t *cells = malloc(t->real.width*t->real.height*4);
+       struct {
+               uint16_t x, y;
+       } *pixels = malloc(reps*sizeof(*pixels));
+       int r, s;
+
+       test_target_create_render(&t->real, target, &tt);
+
+       printf("Testing setting of single pixels (%s): ",
+              test_target_name(target));
+       fflush(stdout);
+
+       for (s = 0; s < sets; s++) {
+               for (r = 0; r < reps; r++) {
+                       int x = rand() % (tt.width - 1);
+                       int y = rand() % (tt.height - 1);
+                       int red = rand() % 0xff;
+                       int green = rand() % 0xff;
+                       int blue = rand() % 0xff;
+                       int alpha = rand() % 0xff;
+
+                       fill_rect(&t->real, tt.picture, PictOpSrc,
+                                 x, y, 1, 1,
+                                 red, green, blue, alpha);
+
+                       pixels[r].x = x;
+                       pixels[r].y = y;
+                       cells[y*tt.width+x] = color(red, green, blue, alpha);
+               }
+
+               test_init_image(&image, &t->real.shm, tt.format, 1, 1);
+
+               for (r = 0; r < reps; r++) {
+                       uint32_t result;
+                       uint32_t x = pixels[r].x;
+                       uint32_t y = pixels[r].y;
+
+                       XShmGetImage(t->real.dpy, tt.draw, &image,
+                                    x, y, AllPlanes);
+
+                       result = *(uint32_t *)image.data;
+                       if (!pixel_equal(image.depth, result,
+                                        cells[y*tt.width+x])) {
+                               uint32_t mask = depth_mask(image.depth);
+                               die("failed to set pixel (%d,%d) to %08x [%08x], found %08x [%08x] instead\n",
+                                   x, y,
+                                   cells[y*tt.width+x] & mask,
+                                   cells[y*tt.width+x],
+                                   result & mask);
+                       }
+               }
+       }
+       printf("passed [%d iterations x %d]\n", reps, sets);
+
+       test_target_destroy_render(&t->real, &tt);
+       free(pixels);
+       free(cells);
+}
+
+static void clear(struct test_display *dpy, struct test_target *tt)
+{
+       XRenderColor render_color = {0};
+       XRenderFillRectangle(dpy->dpy, PictOpClear, tt->picture, &render_color,
+                            0, 0, tt->width, tt->height);
+}
+
+static void area_tests(struct test *t, int reps, int sets, enum target target)
+{
+       struct test_target tt;
+       XImage image;
+       uint32_t *cells = calloc(sizeof(uint32_t), t->real.width*t->real.height);
+       int r, s, x, y;
+
+       printf("Testing area sets (%s): ", test_target_name(target));
+       fflush(stdout);
+
+       test_target_create_render(&t->real, target, &tt);
+       clear(&t->real, &tt);
+
+       test_init_image(&image, &t->real.shm, tt.format, tt.width, tt.height);
+
+       for (s = 0; s < sets; s++) {
+               for (r = 0; r < reps; r++) {
+                       int w = rand() % tt.width;
+                       int h = rand() % tt.height;
+                       int red = rand() % 0xff;
+                       int green = rand() % 0xff;
+                       int blue = rand() % 0xff;
+                       int alpha = rand() % 0xff;
+
+                       x = rand() % (2*tt.width) - tt.width;
+                       y = rand() % (2*tt.height) - tt.height;
+
+                       fill_rect(&t->real, tt.picture, PictOpSrc,
+                                 x, y, w, h, red, green, blue, alpha);
+
+                       if (x < 0)
+                               w += x, x = 0;
+                       if (y < 0)
+                               h += y, y = 0;
+                       if (x >= tt.width || y >= tt.height)
+                               continue;
+
+                       if (x + w > tt.width)
+                               w = tt.width - x;
+                       if (y + h > tt.height)
+                               h = tt.height - y;
+                       if (w <= 0 || h <= 0)
+                               continue;
+
+                       pixman_fill(cells, tt.width, 32, x, y, w, h,
+                                   color(red, green, blue, alpha));
+               }
+
+               XShmGetImage(t->real.dpy, tt.draw, &image, 0, 0, AllPlanes);
+
+               for (y = 0; y < tt.height; y++) {
+                       for (x = 0; x < tt.width; x++) {
+                               uint32_t result =
+                                       *(uint32_t *)(image.data +
+                                                     y*image.bytes_per_line +
+                                                     image.bits_per_pixel*x/8);
+                               if (!pixel_equal(image.depth, result, cells[y*tt.width+x])) {
+                                       uint32_t mask;
+                                       if (image.depth == 32)
+                                               mask = 0xffffffff;
+                                       else
+                                               mask = (1 << image.depth) - 1;
+                                       die("failed to set pixel (%d,%d) to %08x[%08x], found %08x instead\n",
+                                           x, y,
+                                           cells[y*tt.width+x] & mask,
+                                           cells[y*tt.width+x],
+                                           result & mask);
+                               }
+                       }
+               }
+       }
+
+       printf("passed [%d iterations x %d]\n", reps, sets);
+
+       test_target_destroy_render(&t->real, &tt);
+       free(cells);
+}
+
+static void rect_tests(struct test *t, int reps, int sets, enum target target)
+{
+       struct test_target real, ref;
+       int r, s;
+
+       printf("Testing area fills (%s): ", test_target_name(target));
+       fflush(stdout);
+
+       test_target_create_render(&t->real, target, &real);
+       clear(&t->real, &real);
+
+       test_target_create_render(&t->ref, target, &ref);
+       clear(&t->ref, &ref);
+
+       for (s = 0; s < sets; s++) {
+               for (r = 0; r < reps; r++) {
+                       int x = rand() % (2*real.width) - real.width;
+                       int y = rand() % (2*real.height) - real.height;
+                       int w = rand() % real.width;
+                       int h = rand() % real.height;
+                       int op = ops[rand() % sizeof(ops)];
+                       int red = rand() % 0xff;
+                       int green = rand() % 0xff;
+                       int blue = rand() % 0xff;
+                       int alpha = rand() % 0xff;
+
+                       fill_rect(&t->real, real.picture,
+                                 op, x, y, w, h,
+                                 red, green, blue, alpha);
+                       fill_rect(&t->ref, ref.picture,
+                                 op, x, y, w, h,
+                                 red, green, blue, alpha);
+               }
+
+               test_compare(t,
+                            real.draw, real.format,
+                            ref.draw, ref.format,
+                            0, 0, real.width, real.height,
+                            "");
+       }
+
+       printf("passed [%d iterations x %d]\n", reps, sets);
+
+       test_target_destroy_render(&t->real, &real);
+       test_target_destroy_render(&t->ref, &ref);
+}
+
+int main(int argc, char **argv)
+{
+       struct test test;
+       int i;
+
+       test_init(&test, argc, argv);
+
+       for (i = 0; i <= DEFAULT_ITERATIONS; i++) {
+               int reps = 1 << i;
+               int sets = 1 << (12 - i);
+               enum target t;
+
+               if (sets < 2)
+                       sets = 2;
+
+               for (t = TARGET_FIRST; t <= TARGET_LAST; t++) {
+                       pixel_tests(&test, reps, sets, t);
+                       area_tests(&test, reps, sets, t);
+                       rect_tests(&test, reps, sets, t);
+               }
+       }
+
+       return 0;
+}
diff --git a/test/render-trapezoid-image.c b/test/render-trapezoid-image.c
new file mode 100644 (file)
index 0000000..c794cbb
--- /dev/null
@@ -0,0 +1,617 @@
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <X11/Xutil.h> /* for XDestroyImage */
+#include <pixman.h> /* for pixman blt functions */
+
+#include "test.h"
+
+enum trapezoid {
+       RECT_ALIGN,
+       RECT_UNALIGN,
+       GENERAL
+};
+
+static const uint8_t ops[] = {
+       PictOpClear,
+       PictOpSrc,
+       PictOpDst,
+};
+
+static XRenderPictFormat *mask_format(Display *dpy, enum mask mask)
+{
+       switch (mask) {
+       default:
+       case MASK_NONE:
+       case MASK_NONE_AA:
+               return NULL;
+       case MASK_A1:
+               return  XRenderFindStandardFormat(dpy, PictStandardA1);
+       case MASK_A8:
+               return  XRenderFindStandardFormat(dpy, PictStandardA8);
+       }
+}
+
+static const char *mask_name(enum mask mask)
+{
+       switch (mask) {
+       default:
+       case MASK_NONE: return "none";
+       case MASK_NONE_AA: return "none/aa";
+       case MASK_A1: return "a1";
+       case MASK_A8: return "a8";
+       }
+}
+
+static const char *trapezoid_name(enum trapezoid trapezoid)
+{
+       switch (trapezoid) {
+       default:
+       case RECT_ALIGN: return "pixel-aligned";
+       case RECT_UNALIGN: return "rectilinear";
+       case GENERAL: return "general";
+       }
+}
+
+static void
+show_cells(char *buf,
+          const uint32_t *real, const uint32_t *ref,
+          int x, int y, int w, int h)
+{
+       int i, j, len = 0;
+
+       for (j = y - 2; j <= y + 2; j++) {
+               if (j < 0 || j >= h)
+                       continue;
+
+               for (i = x - 2; i <= x + 2; i++) {
+                       if (i < 0 || i >= w)
+                               continue;
+
+                       len += sprintf(buf+len, "%08x ", real[j*w+i]);
+               }
+
+               len += sprintf(buf+len, "\t");
+
+               for (i = x - 2; i <= x + 2; i++) {
+                       if (i < 0 || i >= w)
+                               continue;
+
+                       len += sprintf(buf+len, "%08x ", ref[j*w+i]);
+               }
+
+               len += sprintf(buf+len, "\n");
+       }
+}
+
+
+static void fill_rect(struct test_display *t, Picture p, XRenderPictFormat *format,
+                     uint8_t op, int x, int y, int w, int h,
+                     int dx, int dy, enum mask mask,
+                     int use_window, int tx, int ty,
+                     uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha)
+{
+       XRenderColor color;
+       XTrapezoid trap;
+       Drawable tmp;
+       Picture src;
+       int w1 = w + (dx!=0);
+       int h1 = h + (dy!=0);
+
+       if (use_window) {
+               XSetWindowAttributes attr;
+
+               attr.override_redirect = 1;
+               tmp = XCreateWindow(t->dpy, DefaultRootWindow(t->dpy),
+                                   tx, ty,
+                                   w1, h1,
+                                   0, format->depth,
+                                   InputOutput,
+                                   DefaultVisual(t->dpy,
+                                                 DefaultScreen(t->dpy)),
+                                   CWOverrideRedirect, &attr);
+               XMapWindow(t->dpy, tmp);
+       } else
+               tmp = XCreatePixmap(t->dpy, DefaultRootWindow(t->dpy),
+                                   w1, h1, format->depth);
+
+       src = XRenderCreatePicture(t->dpy, tmp, format, 0, NULL);
+       color.red = red * alpha;
+       color.green = green * alpha;
+       color.blue = blue * alpha;
+       color.alpha = alpha << 8 | alpha;
+       XRenderFillRectangle(t->dpy, PictOpSrc, src, &color, 0, 0, w1, h1);
+
+       trap.left.p1.x = trap.left.p2.x = (x << 16) + dx;
+       trap.top = trap.left.p1.y = trap.right.p1.y = (y << 16) + dy;
+       trap.right.p1.x = trap.right.p2.x = ((x + w) << 16) + dx;
+       trap.bottom = trap.left.p2.y = trap.right.p2.y = ((y + h) << 16) + dy;
+
+       XRenderCompositeTrapezoids(t->dpy,
+                                  op, src, p, mask_format(t->dpy, mask),
+                                  0, 0, &trap, 1);
+
+       XRenderFreePicture(t->dpy, src);
+       if (use_window)
+               XDestroyWindow(t->dpy, tmp);
+       else
+               XFreePixmap(t->dpy, tmp);
+}
+
+static void pixel_tests(struct test *t, int reps, int sets, enum target target, int use_window)
+{
+       struct test_target tt;
+       XImage image;
+       uint32_t *cells = malloc(t->real.width*t->real.height*4);
+       struct {
+               uint16_t x, y;
+       } *pixels = malloc(reps*sizeof(*pixels));
+       int r, s;
+
+       printf("Testing setting of single pixels (%s using %s): ",
+              test_target_name(target),
+              use_window ? "window" : "pixmap");
+       fflush(stdout);
+
+       test_target_create_render(&t->real, target, &tt);
+
+       for (s = 0; s < sets; s++) {
+               for (r = 0; r < reps; r++) {
+                       int x = rand() % (tt.width - 1);
+                       int y = rand() % (tt.height - 1);
+                       int red = rand() % 0xff;
+                       int green = rand() % 0xff;
+                       int blue = rand() % 0xff;
+                       int alpha = rand() % 0xff;
+
+                       int tx, ty;
+
+                       do {
+                               tx = rand() % (tt.width - 1);
+                               ty = rand() % (tt.height - 1);
+                       } while (tx == x && ty == y);
+
+                       fill_rect(&t->real, tt.picture,
+                                 use_window ? t->real.format : tt.format,
+                                 PictOpSrc, x, y, 1, 1,
+                                 0, 0, MASK_NONE,
+                                 use_window, tx, ty,
+                                 red, green, blue, alpha);
+
+                       pixels[r].x = x;
+                       pixels[r].y = y;
+                       cells[y*t->real.width+x] = color(red, green, blue, alpha);
+               }
+
+               test_init_image(&image, &t->real.shm, tt.format, 1, 1);
+
+               for (r = 0; r < reps; r++) {
+                       uint32_t result;
+                       uint32_t x = pixels[r].x;
+                       uint32_t y = pixels[r].y;
+
+                       XShmGetImage(t->real.dpy, tt.draw, &image,
+                                    x, y, AllPlanes);
+
+                       result = *(uint32_t *)image.data;
+                       if (!pixel_equal(image.depth, result,
+                                        cells[y*tt.width+x])) {
+                               uint32_t mask = depth_mask(image.depth);
+                               die("failed to set pixel (%d,%d) to %08x [%08x], found %08x [%08x] instead\n",
+                                   x, y,
+                                   cells[y*tt.width+x] & mask,
+                                   cells[y*tt.width+x],
+                                   result & mask,
+                                   result);
+                       }
+               }
+       }
+       printf("passed [%d iterations x %d]\n", reps, sets);
+
+       test_target_destroy_render(&t->real, &tt);
+
+       free(pixels);
+       free(cells);
+}
+
+static void clear(struct test_display *dpy, struct test_target *tt)
+{
+       XRenderColor render_color = {0};
+       XRenderFillRectangle(dpy->dpy, PictOpClear, tt->picture, &render_color,
+                            0, 0, tt->width, tt->height);
+}
+
+static void set_mask(struct test_display *t, struct test_target *tt, enum mask mask)
+{
+       XRenderPictureAttributes pa;
+
+       switch (mask) {
+       case MASK_NONE:
+               pa.poly_edge = PolyEdgeSharp;
+               break;
+       default:
+               pa.poly_edge = PolyEdgeSmooth;
+               break;
+       }
+
+       XRenderChangePicture(t->dpy, tt->picture, CPPolyEdge, &pa);
+}
+
+static void fill(uint32_t *cells,
+                int x, int y,
+                int w, int h,
+                int max_width, int max_height,
+                uint32_t pixel)
+{
+       if (x < 0)
+               w += x, x = 0;
+       if (y < 0)
+               h += y, y = 0;
+       if (x >= max_width || y >= max_height)
+               return;
+
+       if (x + w > max_width)
+               w = max_width - x;
+       if (y + h > max_height)
+               h = max_height - y;
+       if (w <= 0 || h <= 0)
+               return;
+
+       pixman_fill(cells, max_width, 32, x, y, w, h, pixel);
+}
+
+static void area_tests(struct test *t, int reps, int sets, enum target target, int use_window)
+{
+       struct test_target tt;
+       XImage image;
+       uint32_t *cells = calloc(sizeof(uint32_t), t->real.width*t->real.height);
+       int r, s, x, y;
+
+       printf("Testing area sets (%s using %s source): ",
+              test_target_name(target),
+              use_window ? "window" : "pixmap");
+       fflush(stdout);
+
+       test_target_create_render(&t->real, target, &tt);
+       clear(&t->real, &tt);
+
+       test_init_image(&image, &t->real.shm, tt.format, tt.width, tt.height);
+
+       for (s = 0; s < sets; s++) {
+               for (r = 0; r < reps; r++) {
+                       int red = rand() % 0xff;
+                       int green = rand() % 0xff;
+                       int blue = rand() % 0xff;
+                       int alpha = rand() % 0xff;
+                       int tx, ty, try = 50;
+                       int w, h;
+
+                       x = rand() % (2*tt.width) - tt.width;
+                       y = rand() % (2*tt.height) - tt.height;
+                       if (use_window) {
+                               do {
+                                       w = 1 + rand() % (tt.width - 1);
+                                       h = 1 + rand() % (tt.height - 1);
+
+                                       tx = w == tt.width ? 0 : rand() % (tt.width - w);
+                                       ty = h == tt.height ? 0 : rand() % (tt.height - h);
+                               } while (((tx+w > x && tx < x+w) &&
+                                         (ty+h > y && ty < y+h)) &&
+                                        --try);
+
+                               if (!try)
+                                       continue;
+                       } else {
+                               w = 1 + rand() % (2*tt.width);
+                               h = 1 + rand() % (2*tt.height);
+                               tx = ty = 0;
+                       }
+
+                       fill_rect(&t->real, tt.picture,
+                                 use_window ? t->real.format : tt.format,
+                                 PictOpSrc, x, y, w, h,
+                                 0, 0, MASK_NONE,
+                                 use_window, tx, ty,
+                                 red, green, blue, alpha);
+
+                       if (use_window)
+                               fill(cells, tx, ty, w, h, tt.width, tt.height,
+                                    color(red, green, blue, alpha));
+                       fill(cells, x, y, w, h, tt.width, tt.height,
+                            color(red, green, blue, alpha));
+
+               }
+
+               XShmGetImage(t->real.dpy, tt.draw, &image, 0, 0, AllPlanes);
+
+               for (y = 0; y < tt.height; y++) {
+                       for (x = 0; x < tt.width; x++) {
+                               uint32_t result =
+                                       *(uint32_t *)(image.data +
+                                                     y*image.bytes_per_line +
+                                                     image.bits_per_pixel*x/8);
+                               if (!pixel_equal(image.depth, result, cells[y*tt.width+x])) {
+                                       char buf[600];
+                                       uint32_t mask = depth_mask(image.depth);
+                                       show_cells(buf,
+                                                  (uint32_t*)image.data, cells,
+                                                  x, y, tt.width, tt.height);
+
+                                       die("failed to set pixel (%d,%d) to %08x [%08x], found %08x [%08x] instead\n%s",
+                                           x, y,
+                                           cells[y*tt.width+x] & mask,
+                                           cells[y*tt.width+x],
+                                           result & mask,
+                                           result, buf);
+                               }
+                       }
+               }
+       }
+
+       printf("passed [%d iterations x %d]\n", reps, sets);
+
+       test_target_destroy_render(&t->real, &tt);
+       free(cells);
+}
+
+static void rect_tests(struct test *t,
+                      int dx, int dy,
+                      enum mask mask,
+                      int reps, int sets,
+                      enum target target,
+                      int use_window)
+{
+       struct test_target real, ref;
+       int r, s;
+
+       printf("Testing area fills (offset %dx%d, mask %s) (%s using %s source): ",
+              dx, dy, mask_name(mask), test_target_name(target),
+              use_window ? "window" : "pixmap");
+       fflush(stdout);
+
+       test_target_create_render(&t->real, target, &real);
+       clear(&t->real, &real);
+       set_mask(&t->real, &real, mask);
+
+       test_target_create_render(&t->ref, target, &ref);
+       clear(&t->ref, &ref);
+       set_mask(&t->ref, &ref, mask);
+
+       for (s = 0; s < sets; s++) {
+               for (r = 0; r < reps; r++) {
+                       int x, y, w, h;
+                       int op = ops[rand() % sizeof(ops)];
+                       int red = rand() % 0xff;
+                       int green = rand() % 0xff;
+                       int blue = rand() % 0xff;
+                       int alpha = rand() % 0xff;
+                       int tx, ty, try = 50;
+
+                       do {
+                               x = rand() % (real.width - 1);
+                               y = rand() % (real.height - 1);
+                               w = 1 + rand() % (real.width - x - 1);
+                               h = 1 + rand() % (real.height - y - 1);
+                               tx = w == real.width ? 0 : rand() % (real.width - w);
+                               ty = h == real.height ? 0 : rand() % (real.height - h);
+                       } while (((tx+w > x && tx < x+w) &&
+                                 (ty+h > y && ty < y+h)) &&
+                                --try);
+
+                       if (try) {
+                               fill_rect(&t->real, real.picture,
+                                         use_window ? t->real.format : real.format,
+                                         op, x, y, w, h,
+                                         dx, dy, mask,
+                                         use_window, tx, ty,
+                                         red, green, blue, alpha);
+                               fill_rect(&t->ref, ref.picture,
+                                         use_window ? t->ref.format : ref.format,
+                                         op, x, y, w, h,
+                                         dx, dy, mask,
+                                         use_window, tx, ty,
+                                         red, green, blue, alpha);
+                       }
+               }
+
+               test_compare(t,
+                            real.draw, real.format,
+                            ref.draw, ref.format,
+                            0, 0, real.width, real.height,
+                            "");
+       }
+
+       printf("passed [%d iterations x %d]\n", reps, sets);
+
+       test_target_destroy_render(&t->real, &real);
+       test_target_destroy_render(&t->ref, &ref);
+}
+
+static void random_trapezoid(XTrapezoid *trap, enum trapezoid trapezoid,
+                            int x1, int y1, int x2, int y2)
+{
+       switch (trapezoid) {
+       case RECT_ALIGN:
+               x1 = x1 + rand() % (x2 - x1);
+               x2 = x1 + rand() % (x2 - x1);
+               y1 = y1 + rand() % (y2 - y1);
+               y2 = y1 + rand() % (y2 - y1);
+
+               trap->left.p1.x = trap->left.p2.x = x1 << 16;
+               trap->top = trap->left.p1.y = trap->right.p1.y = y1 << 16;
+               trap->right.p1.x = trap->right.p2.x = x2 << 16;
+               trap->bottom = trap->left.p2.y = trap->right.p2.y = y2 << 16;
+               break;
+
+       case RECT_UNALIGN:
+               x1 <<= 16; x2 <<= 16;
+               y1 <<= 16; y2 <<= 16;
+
+               x1 = x1 + rand() % (x2 - x1);
+               x2 = x1 + rand() % (x2 - x1);
+               y1 = y1 + rand() % (y2 - y1);
+               y2 = y1 + rand() % (y2 - y1);
+
+               trap->left.p1.x = trap->left.p2.x = x1;
+               trap->top = trap->left.p1.y = trap->right.p1.y = y1;
+               trap->right.p1.x = trap->right.p2.x = x2;
+               trap->bottom = trap->left.p2.y = trap->right.p2.y = y2;
+               break;
+
+       case GENERAL:
+               x1 <<= 16; x2 <<= 16;
+               y1 <<= 16; y2 <<= 16;
+
+               trap->top = y1 + rand() % (y2 - y1);
+               trap->bottom = y1 + rand() % (y2 - y1);
+
+               trap->left.p1.x = x1 + rand() % (x2 - x1);
+               trap->left.p2.x = x1 + rand() % (x2 - x1);
+
+               trap->right.p1.x = x1 + rand() % (x2 - x1);
+               trap->right.p2.x = x1 + rand() % (x2 - x1);
+               break;
+       }
+}
+
+static void fill_traps(struct test_display *t, Picture p, XRenderPictFormat *format,
+                      uint8_t op, XTrapezoid *traps, int ntraps, enum mask mask,
+                      int srcx, int srcy, int srcw, int srch,
+                      uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha)
+{
+       XRenderColor color;
+       Drawable tmp;
+       Picture src;
+
+       tmp = XCreatePixmap(t->dpy, DefaultRootWindow(t->dpy),
+                           srcw, srch, format->depth);
+
+       src = XRenderCreatePicture(t->dpy, tmp, format, 0, NULL);
+       color.red = red * alpha;
+       color.green = green * alpha;
+       color.blue = blue * alpha;
+       color.alpha = alpha << 8 | alpha;
+       XRenderFillRectangle(t->dpy, PictOpSrc, src, &color, 0, 0, srcw, srch);
+
+       XRenderCompositeTrapezoids(t->dpy,
+                                  op, src, p, mask_format(t->dpy, mask),
+                                  srcx, srcy, traps, ntraps);
+
+       XRenderFreePicture(t->dpy, src);
+       XFreePixmap(t->dpy, tmp);
+}
+
+static void trap_tests(struct test *t,
+                      enum mask mask,
+                      enum trapezoid trapezoid,
+                      int reps, int sets,
+                      enum target target)
+{
+       struct test_target real, ref;
+       XTrapezoid *traps;
+       int max_traps = 65536;
+       int r, s, n;
+
+       traps = malloc(sizeof(*traps) * max_traps);
+       if (traps == NULL)
+               return;
+
+       printf("Testing trapezoids (%s with mask %s) (%s): ",
+              trapezoid_name(trapezoid),
+              mask_name(mask),
+              test_target_name(target));
+       fflush(stdout);
+
+       test_target_create_render(&t->real, target, &real);
+       clear(&t->real, &real);
+       set_mask(&t->real, &real, mask);
+
+       test_target_create_render(&t->ref, target, &ref);
+       clear(&t->ref, &ref);
+       set_mask(&t->ref, &ref, mask);
+
+       for (s = 0; s < sets; s++) {
+               for (r = 0; r < reps; r++) {
+                       int op = ops[rand() % sizeof(ops)];
+                       int red = rand() % 0xff;
+                       int green = rand() % 0xff;
+                       int blue = rand() % 0xff;
+                       int alpha = rand() % 0xff;
+                       int num_traps = rand() % max_traps;
+                       int srcx = rand() % 2*real.width - real.width;
+                       int srcy = rand() % 2*real.height - real.height;
+                       int srcw = rand() % real.width;
+                       int srch = rand() % real.height;
+
+                       for (n = 0; n < num_traps; n++)
+                               random_trapezoid(&traps[n], 0,
+                                                0, 0, real.width, real.height);
+
+
+                       fill_traps(&t->real, real.picture, real.format,
+                                  op, traps, num_traps, mask,
+                                  srcx, srcy, srcw, srch,
+                                  red, green, blue, alpha);
+
+                       fill_traps(&t->ref, ref.picture, ref.format,
+                                  op, traps, num_traps, mask,
+                                  srcx, srcy, srcw, srch,
+                                  red, green, blue, alpha);
+               }
+
+               test_compare(t,
+                            real.draw, real.format,
+                            ref.draw, ref.format,
+                            0, 0, real.width, real.height,
+                            "");
+       }
+
+       printf("passed [%d iterations x %d]\n", reps, sets);
+
+       test_target_destroy_render(&t->real, &real);
+       test_target_destroy_render(&t->ref, &ref);
+       free(traps);
+}
+
+int main(int argc, char **argv)
+{
+       struct test test;
+       int i, dx, dy;
+       enum target target;
+       enum mask mask;
+       enum trapezoid trapezoid;
+
+       test_init(&test, argc, argv);
+
+       for (i = 0; i <= DEFAULT_ITERATIONS; i++) {
+               int reps = 1 << i;
+               int sets = 1 << (12 - i);
+
+               if (sets < 2)
+                       sets = 2;
+
+               for (target = TARGET_FIRST; target <= TARGET_LAST; target++) {
+                       pixel_tests(&test, reps, sets, target, 0);
+                       area_tests(&test, reps, sets, target, 0);
+                       for (dy = 0; dy < 1 << 16; dy += 1 << 14)
+                               for (dx = 0; dx < 1 << 16; dx += 1 << 14)
+                                       for (mask = MASK_NONE; mask <= MASK_A8; mask++)
+                                               rect_tests(&test, dx, dy, mask, reps, sets, target, 0);
+                       if (target != CHILD) {
+                               pixel_tests(&test, reps, sets, target, 1);
+                               area_tests(&test, reps, sets, target, 1);
+                               for (dy = 0; dy < 1 << 16; dy += 1 << 14)
+                                       for (dx = 0; dx < 1 << 16; dx += 1 << 14)
+                                               for (mask = MASK_NONE; mask <= MASK_A8; mask++)
+                                                       rect_tests(&test, dx, dy, mask, reps, sets, target, 1);
+                       }
+               }
+
+               for (target = TARGET_FIRST; target <= TARGET_LAST; target++)
+                       for (trapezoid = RECT_ALIGN; trapezoid <= GENERAL; trapezoid++)
+                               trap_tests(&test, mask, trapezoid, reps, sets, target);
+       }
+
+       return 0;
+}
diff --git a/test/render-trapezoid.c b/test/render-trapezoid.c
new file mode 100644 (file)
index 0000000..f7fd5bb
--- /dev/null
@@ -0,0 +1,436 @@
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <X11/Xutil.h> /* for XDestroyImage */
+#include <pixman.h> /* for pixman blt functions */
+
+#include "test.h"
+
+enum trapezoid {
+       RECT_ALIGN,
+       RECT_UNALIGN,
+       GENERAL
+};
+
+static const uint8_t ops[] = {
+       PictOpClear,
+       PictOpSrc,
+       PictOpDst,
+};
+
+static XRenderPictFormat *mask_format(Display *dpy, enum mask mask)
+{
+       switch (mask) {
+       default:
+       case MASK_NONE: return NULL;
+       case MASK_A1: return  XRenderFindStandardFormat(dpy, PictStandardA1);
+       case MASK_A8: return  XRenderFindStandardFormat(dpy, PictStandardA8);
+       }
+}
+
+static const char *mask_name(enum mask mask)
+{
+       switch (mask) {
+       default:
+       case MASK_NONE: return "none";
+       case MASK_A1: return "a1";
+       case MASK_A8: return "a8";
+       }
+}
+
+static const char *trapezoid_name(enum trapezoid trapezoid)
+{
+       switch (trapezoid) {
+       default:
+       case RECT_ALIGN: return "pixel-aligned";
+       case RECT_UNALIGN: return "rectilinear";
+       case GENERAL: return "general";
+       }
+}
+
+static void fill_rect(struct test_display *dpy, Picture p, uint8_t op,
+                     int x, int y, int w, int h,
+                     int dx, int dy, enum mask mask,
+                     uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha)
+{
+       XRenderColor render_color;
+       XTrapezoid trap;
+       Picture src;
+
+       render_color.red   = red * alpha;
+       render_color.green = green * alpha;
+       render_color.blue  = blue * alpha;
+       render_color.alpha = alpha << 8;
+
+       trap.left.p1.x = trap.left.p2.x = (x << 16) + dx;
+       trap.top = trap.left.p1.y = trap.right.p1.y = (y << 16) + dy;
+       trap.right.p1.x = trap.right.p2.x = ((x + w) << 16) + dx;
+       trap.bottom = trap.left.p2.y = trap.right.p2.y = ((y + h) << 16) + dy;
+
+       src = XRenderCreateSolidFill(dpy->dpy, &render_color);
+       XRenderCompositeTrapezoids(dpy->dpy,
+                                  op, src, p, mask_format(dpy->dpy, mask),
+                                  0, 0, &trap, 1);
+       XRenderFreePicture(dpy->dpy, src);
+}
+
+static void pixel_tests(struct test *t, int reps, int sets, enum target target)
+{
+       struct test_target tt;
+       XImage image;
+       uint32_t *cells = malloc(t->real.width*t->real.height*4);
+       struct {
+               uint16_t x, y;
+       } *pixels = malloc(reps*sizeof(*pixels));
+       int r, s;
+
+       printf("Testing setting of single pixels (%s): ", test_target_name(target));
+       fflush(stdout);
+
+       test_target_create_render(&t->real, target, &tt);
+
+       for (s = 0; s < sets; s++) {
+               for (r = 0; r < reps; r++) {
+                       int x = rand() % (tt.width - 1);
+                       int y = rand() % (tt.height - 1);
+                       int red = rand() % 0xff;
+                       int green = rand() % 0xff;
+                       int blue = rand() % 0xff;
+                       int alpha = rand() % 0xff;
+
+                       fill_rect(&t->real, tt.picture, PictOpSrc,
+                                 x, y, 1, 1,
+                                 0, 0, MASK_NONE,
+                                 red, green, blue, alpha);
+
+                       pixels[r].x = x;
+                       pixels[r].y = y;
+                       cells[y*t->real.width+x] = color(red, green, blue, alpha);
+               }
+
+               test_init_image(&image, &t->real.shm, tt.format, 1, 1);
+
+               for (r = 0; r < reps; r++) {
+                       uint32_t result;
+                       uint32_t x = pixels[r].x;
+                       uint32_t y = pixels[r].y;
+
+                       XShmGetImage(t->real.dpy, tt.draw, &image,
+                                    x, y, AllPlanes);
+
+                       result = *(uint32_t *)image.data;
+                       if (!pixel_equal(image.depth, result,
+                                        cells[y*tt.width+x])) {
+                               uint32_t mask = depth_mask(image.depth);
+                               die("failed to set pixel (%d,%d) to %08x [%08x], found %08x [%08x] instead\n",
+                                   x, y,
+                                   cells[y*tt.width+x] & mask,
+                                   cells[y*tt.width+x],
+                                   result & mask,
+                                   result);
+                       }
+               }
+       }
+       printf("passed [%d iterations x %d]\n", reps, sets);
+
+       test_target_destroy_render(&t->real, &tt);
+
+       free(pixels);
+       free(cells);
+}
+
+static void clear(struct test_display *dpy, struct test_target *tt)
+{
+       XRenderColor render_color = {0};
+       XRenderFillRectangle(dpy->dpy, PictOpClear, tt->picture, &render_color,
+                            0, 0, tt->width, tt->height);
+}
+
+static void area_tests(struct test *t, int reps, int sets, enum target target)
+{
+       struct test_target tt;
+       XImage image;
+       uint32_t *cells = calloc(sizeof(uint32_t), t->real.width*t->real.height);
+       int r, s, x, y;
+
+       printf("Testing area sets (%s): ", test_target_name(target));
+       fflush(stdout);
+
+       test_target_create_render(&t->real, target, &tt);
+       clear(&t->real, &tt);
+
+       test_init_image(&image, &t->real.shm, tt.format, tt.width, tt.height);
+
+       for (s = 0; s < sets; s++) {
+               for (r = 0; r < reps; r++) {
+                       int w = rand() % tt.width;
+                       int h = rand() % tt.height;
+                       int red = rand() % 0xff;
+                       int green = rand() % 0xff;
+                       int blue = rand() % 0xff;
+                       int alpha = rand() % 0xff;
+
+                       x = rand() % (2*tt.width) - tt.width;
+                       y = rand() % (2*tt.height) - tt.height;
+
+                       fill_rect(&t->real, tt.picture, PictOpSrc,
+                                 x, y, w, h,
+                                 0, 0, MASK_NONE,
+                                 red, green, blue, alpha);
+
+                       if (x < 0)
+                               w += x, x = 0;
+                       if (y < 0)
+                               h += y, y = 0;
+                       if (x >= tt.width || y >= tt.height)
+                               continue;
+
+                       if (x + w > tt.width)
+                               w = tt.width - x;
+                       if (y + h > tt.height)
+                               h = tt.height - y;
+                       if (w <= 0 || h <= 0)
+                               continue;
+
+                       pixman_fill(cells, tt.width, 32, x, y, w, h,
+                                   color(red, green, blue, alpha));
+               }
+
+               XShmGetImage(t->real.dpy, tt.draw, &image, 0, 0, AllPlanes);
+
+               for (y = 0; y < tt.height; y++) {
+                       for (x = 0; x < tt.width; x++) {
+                               uint32_t result =
+                                       *(uint32_t *)(image.data +
+                                                     y*image.bytes_per_line +
+                                                     image.bits_per_pixel*x/8);
+                               if (!pixel_equal(image.depth, result, cells[y*tt.width+x])) {
+                                       uint32_t mask = depth_mask(image.depth);
+
+                                       die("failed to set pixel (%d,%d) to %08x [%08x], found %08x [%08x] instead\n",
+                                           x, y,
+                                           cells[y*tt.width+x] & mask,
+                                           cells[y*tt.width+x],
+                                           result & mask,
+                                           result);
+                               }
+                       }
+               }
+       }
+
+       printf("passed [%d iterations x %d]\n", reps, sets);
+
+       test_target_destroy_render(&t->real, &tt);
+       free(cells);
+}
+
+static void rect_tests(struct test *t,
+                      int dx, int dy,
+                      enum mask mask,
+                      int reps, int sets,
+                      enum target target)
+{
+       struct test_target real, ref;
+       int r, s;
+
+       printf("Testing area fills (offset %dx%d, mask %s) (%s): ",
+              dx, dy, mask_name(mask), test_target_name(target));
+       fflush(stdout);
+
+       test_target_create_render(&t->real, target, &real);
+       clear(&t->real, &real);
+
+       test_target_create_render(&t->ref, target, &ref);
+       clear(&t->ref, &ref);
+
+       for (s = 0; s < sets; s++) {
+               for (r = 0; r < reps; r++) {
+                       int x = rand() % (2*real.width) - real.width;
+                       int y = rand() % (2*real.height) - real.height;
+                       int w = rand() % real.width;
+                       int h = rand() % real.height;
+                       int op = ops[rand() % sizeof(ops)];
+                       int red = rand() % 0xff;
+                       int green = rand() % 0xff;
+                       int blue = rand() % 0xff;
+                       int alpha = rand() % 0xff;
+
+                       fill_rect(&t->real, real.picture, op,
+                                 x, y, w, h, dx, dy, mask,
+                                 red, green, blue, alpha);
+                       fill_rect(&t->ref, ref.picture, op,
+                                 x, y, w, h, dx, dy, mask,
+                                 red, green, blue, alpha);
+               }
+
+               test_compare(t,
+                            real.draw, real.format,
+                            ref.draw, ref.format,
+                            0, 0, real.width, real.height,
+                            "");
+       }
+
+       printf("passed [%d iterations x %d]\n", reps, sets);
+
+       test_target_destroy_render(&t->real, &real);
+       test_target_destroy_render(&t->ref, &ref);
+}
+
+static void random_trapezoid(XTrapezoid *trap, enum trapezoid trapezoid,
+                            int x1, int y1, int x2, int y2)
+{
+       switch (trapezoid) {
+       case RECT_ALIGN:
+               x1 = x1 + rand() % (x2 - x1);
+               x2 = x1 + rand() % (x2 - x1);
+               y1 = y1 + rand() % (y2 - y1);
+               y2 = y1 + rand() % (y2 - y1);
+
+               trap->left.p1.x = trap->left.p2.x = x1 << 16;
+               trap->top = trap->left.p1.y = trap->right.p1.y = y1 << 16;
+               trap->right.p1.x = trap->right.p2.x = x2 << 16;
+               trap->bottom = trap->left.p2.y = trap->right.p2.y = y2 << 16;
+               break;
+
+       case RECT_UNALIGN:
+               x1 <<= 16; x2 <<= 16;
+               y1 <<= 16; y2 <<= 16;
+
+               x1 = x1 + rand() % (x2 - x1);
+               x2 = x1 + rand() % (x2 - x1);
+               y1 = y1 + rand() % (y2 - y1);
+               y2 = y1 + rand() % (y2 - y1);
+
+               trap->left.p1.x = trap->left.p2.x = x1;
+               trap->top = trap->left.p1.y = trap->right.p1.y = y1;
+               trap->right.p1.x = trap->right.p2.x = x2;
+               trap->bottom = trap->left.p2.y = trap->right.p2.y = y2;
+               break;
+
+       case GENERAL:
+               x1 <<= 16; x2 <<= 16;
+               y1 <<= 16; y2 <<= 16;
+
+               trap->top = y1 + rand() % (y2 - y1);
+               trap->bottom = y1 + rand() % (y2 - y1);
+
+               trap->left.p1.x = x1 + rand() % (x2 - x1);
+               trap->left.p2.x = x1 + rand() % (x2 - x1);
+
+               trap->right.p1.x = x1 + rand() % (x2 - x1);
+               trap->right.p2.x = x1 + rand() % (x2 - x1);
+               break;
+
+       }
+}
+
+static void trap_tests(struct test *t,
+                      enum mask mask,
+                      enum trapezoid trapezoid,
+                      int reps, int sets,
+                      enum target target)
+{
+       struct test_target real, ref;
+       XTrapezoid *traps;
+       int max_traps = 65536;
+       int r, s, n;
+
+       traps = malloc(sizeof(*traps) * max_traps);
+       if (traps == NULL)
+               return;
+
+       printf("Testing trapezoids (%s with mask %s) (%s): ",
+              trapezoid_name(trapezoid),
+              mask_name(mask),
+              test_target_name(target));
+       fflush(stdout);
+
+       test_target_create_render(&t->real, target, &real);
+       clear(&t->real, &real);
+
+       test_target_create_render(&t->ref, target, &ref);
+       clear(&t->ref, &ref);
+
+       for (s = 0; s < sets; s++) {
+               for (r = 0; r < reps; r++) {
+                       XRenderColor render_color;
+                       int op = ops[rand() % sizeof(ops)];
+                       int red = rand() % 0xff;
+                       int green = rand() % 0xff;
+                       int blue = rand() % 0xff;
+                       int alpha = rand() % 0xff;
+                       int num_traps = rand() % max_traps;
+                       Picture src;
+
+                       for (n = 0; n < num_traps; n++)
+                               random_trapezoid(&traps[n], 0,
+                                                0, 0, real.width, real.height);
+
+                       render_color.red   = red * alpha;
+                       render_color.green = green * alpha;
+                       render_color.blue  = blue * alpha;
+                       render_color.alpha = alpha << 8;
+
+                       src = XRenderCreateSolidFill(t->real.dpy,
+                                                    &render_color);
+                       XRenderCompositeTrapezoids(t->real.dpy,
+                                                  op, src, real.picture,
+                                                  mask_format(t->real.dpy, mask),
+                                                  0, 0, traps, num_traps);
+                       XRenderFreePicture(t->real.dpy, src);
+
+                       src = XRenderCreateSolidFill(t->ref.dpy,
+                                                    &render_color);
+                       XRenderCompositeTrapezoids(t->ref.dpy,
+                                                  op, src, ref.picture,
+                                                  mask_format(t->ref.dpy, mask),
+                                                  0, 0, traps, num_traps);
+                       XRenderFreePicture(t->ref.dpy, src);
+               }
+
+               test_compare(t,
+                            real.draw, real.format,
+                            ref.draw, ref.format,
+                            0, 0, real.width, real.height,
+                            "");
+       }
+
+       printf("passed [%d iterations x %d]\n", reps, sets);
+
+       test_target_destroy_render(&t->real, &real);
+       test_target_destroy_render(&t->ref, &ref);
+       free(traps);
+}
+
+int main(int argc, char **argv)
+{
+       struct test test;
+       int i, dx, dy;
+       enum target target;
+       enum mask mask;
+       enum trapezoid trapezoid;
+
+       test_init(&test, argc, argv);
+
+       for (i = 0; i <= DEFAULT_ITERATIONS; i++) {
+               int reps = 1 << i;
+               int sets = 1 << (12 - i);
+
+               if (sets < 2)
+                       sets = 2;
+
+               for (target = TARGET_FIRST; target <= TARGET_LAST; target++) {
+                       pixel_tests(&test, reps, sets, target);
+                       area_tests(&test, reps, sets, target);
+                       for (dy = 0; dy < 1 << 16; dy += 1 << 14)
+                               for (dx = 0; dx < 1 << 16; dx += 1 << 14)
+                                       for (mask = MASK_NONE; mask <= MASK_A8; mask++)
+                                               rect_tests(&test, dx, dy, mask, reps, sets, target);
+                       for (trapezoid = RECT_ALIGN; trapezoid <= GENERAL; trapezoid++)
+                               trap_tests(&test, mask, trapezoid, reps, sets, target);
+               }
+       }
+
+       return 0;
+}
diff --git a/test/test.h b/test/test.h
new file mode 100644 (file)
index 0000000..1e3995b
--- /dev/null
@@ -0,0 +1,118 @@
+#ifndef TEST_H
+#define TEST_H
+
+#include <stdint.h>
+#include <X11/Xlib.h>
+#include <X11/extensions/XShm.h>
+#include <X11/extensions/Xrender.h>
+
+#define DEFAULT_ITERATIONS 20
+
+enum target {
+       ROOT,
+       CHILD,
+       PIXMAP,
+};
+#define TARGET_FIRST ROOT
+#define TARGET_LAST PIXMAP
+
+enum mask {
+       MASK_NONE,
+       MASK_NONE_AA,
+       MASK_A1,
+       MASK_A8,
+};
+
+struct test {
+       struct test_display {
+               Display *dpy;
+               Window root;
+               XShmSegmentInfo shm;
+               int max_shm_size;
+               int width, height;
+               XRenderPictFormat *format;
+       } real, ref;
+};
+
+void die(const char *fmt, ...);
+
+#define die_unless(expr) do{ if (!(expr)) die("verification failed: %s\n", #expr); } while(0)
+
+void test_init(struct test *test, int argc, char **argv);
+
+void test_compare(struct test *real,
+                 Drawable real_draw, XRenderPictFormat *real_format,
+                 Drawable ref_draw, XRenderPictFormat *ref_format,
+                 int x, int y, int w, int h, const char *info);
+
+#define MAX_DELTA 3
+int pixel_difference(uint32_t a, uint32_t b);
+
+static inline int pixel_equal(int depth, uint32_t a, uint32_t b)
+{
+       uint32_t mask;
+
+       if (depth == 32)
+               mask = 0xffffffff;
+       else
+               mask = (1 << depth) - 1;
+
+       a &= mask;
+       b &= mask;
+
+       if (a == b)
+               return 1;
+
+       return pixel_difference(a, b) < MAX_DELTA;
+}
+
+void
+test_init_image(XImage *ximage,
+               XShmSegmentInfo *shm,
+               XRenderPictFormat *format,
+               int width, int height);
+
+const char *test_target_name(enum target target);
+
+struct test_target {
+       struct test_display *dpy;
+       Drawable draw;
+       GC gc;
+       XRenderPictFormat *format;
+       Picture picture;
+       int width, height;
+       enum target target;
+};
+
+void test_target_create_render(struct test_display *dpy,
+                              enum target target,
+                              struct test_target *tt);
+void test_target_destroy_render(struct test_display *dpy,
+                               struct test_target *tt);
+
+static inline uint32_t depth_mask(int depth)
+{
+       if (depth == 32)
+               return 0xffffffff;
+       else
+               return (1 << depth) - 1;
+}
+
+static inline uint32_t color(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha)
+{
+       uint16_t ra = red * alpha;
+       uint16_t ga = green * alpha;
+       uint16_t ba = blue * alpha;
+
+       return alpha << 24 | ra >> 8 << 16 | ga >> 8 << 8 | ba >> 8;
+}
+
+#ifndef MAX
+#define MAX(a,b) ((a) > (b) ? (a) : (b))
+#endif
+
+#ifndef ARRAY_SIZE
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
+#endif
+
+#endif
diff --git a/test/test_display.c b/test/test_display.c
new file mode 100644 (file)
index 0000000..ad3e40b
--- /dev/null
@@ -0,0 +1,150 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+
+#include "test.h"
+
+static Window get_root(struct test_display *t)
+{
+       XSetWindowAttributes attr;
+       Window w;
+
+       /* Be nasty and install a fullscreen window on top so that we
+        * can guarantee we do not get clipped by children.
+        */
+       attr.override_redirect = 1;
+       w= XCreateWindow(t->dpy, DefaultRootWindow(t->dpy),
+                        0, 0, t->width, t->height, 0,
+                        DefaultDepth(t->dpy, DefaultScreen(t->dpy)),
+                        InputOutput,
+                        DefaultVisual(t->dpy, DefaultScreen(t->dpy)),
+                        CWOverrideRedirect, &attr);
+       XMapWindow(t->dpy, w);
+
+       return w;
+}
+
+static Display *real_display(int argc, char **argv)
+{
+       Display *dpy;
+       const char *name = NULL;
+       int i;
+
+       for (i = 0; i < argc; i++) {
+               if (strncmp(argv[i], "-d", 2) == 0) {
+                       if (argv[i][2] == '\0') {
+                               if (i+1 < argc) {
+                                       name = argv[i+1];
+                                       i++;
+                               }
+                       } else
+                               name = argv[i] + 2;
+               }
+       }
+
+       if (name == NULL)
+               name = getenv("DISPLAY");
+       if (name == NULL)
+               name = ":0"; /* useful default */
+
+       dpy = XOpenDisplay(name);
+       if (dpy == NULL)
+               die("unable to open real display %s\n", name);
+
+       printf("Opened connection to %s for testing.\n", name);
+       return dpy;
+}
+
+static Display *ref_display(int width, int height, int depth)
+{
+       Display *dpy;
+       char buf[160];
+       const char *name;
+       int try;
+
+       name = getenv("REF_DISPLAY");
+       if (name) {
+               dpy = XOpenDisplay(name);
+               if (dpy == NULL)
+                       die("unable to open reference display %s\n", name);
+
+               printf("Opened connection to %s for reference.\n", name);
+               return dpy;
+       }
+
+       snprintf(buf, sizeof(buf),
+                "Xvfb -ac -terminate -screen 0 %dx%dx%d :99 >/dev/null 2>&1 &",
+                width, height, depth);
+       if (system(buf))
+               die("unable to spawn '%s' for reference display\n", buf);
+
+       try = 0;
+       while (try++ < 1000) {
+               dpy = XOpenDisplay(":99");
+               if (dpy)
+                       break;
+               usleep(1000);
+       }
+
+       if (dpy == NULL)
+               die("unable to open reference display\n");
+
+       return dpy;
+}
+
+static void shm_setup(struct test_display *d)
+{
+       int major, minor, has_pixmaps;
+       int size;
+
+       XShmQueryVersion(d->dpy, &major, &minor, &has_pixmaps);
+       if (major == 0 && minor == 0)
+               die("XSHM not supported\n");
+
+       size = d->width * d->height * 4;
+       d->max_shm_size = size;
+
+       d->shm.shmid = shmget(IPC_PRIVATE, size, IPC_CREAT | 0600);
+       if (d->shm.shmid == -1)
+               die("failed to allocated %d bytes for a shm segment\n", size);
+
+       d->shm.shmaddr = shmat(d->shm.shmid, NULL, 0);
+       d->shm.readOnly = 0;
+       XShmAttach(d->dpy, &d->shm);
+       XSync(d->dpy, 1);
+}
+
+static void default_setup(struct test_display *dpy)
+{
+       dpy->width = WidthOfScreen(DefaultScreenOfDisplay(dpy->dpy));
+       dpy->height = HeightOfScreen(DefaultScreenOfDisplay(dpy->dpy));
+       dpy->format =
+               XRenderFindVisualFormat(dpy->dpy,
+                                       DefaultVisual(dpy->dpy,
+                                                     DefaultScreen(dpy->dpy)));
+}
+
+static void test_get_displays(int argc, char **argv,
+                             struct test_display *real,
+                             struct test_display *ref)
+{
+       real->dpy = real_display(argc, argv);
+       default_setup(real);
+       shm_setup(real);
+       real->root = get_root(real);
+
+       ref->dpy = ref_display(real->width, real->height,
+                              DefaultDepth(real->dpy, DefaultScreen(real->dpy)));
+       default_setup(ref);
+       shm_setup(ref);
+       ref->root = get_root(ref);
+}
+
+void test_init(struct test *test, int argc, char **argv)
+{
+       memset(test, 0, sizeof(*test));
+       test_get_displays(argc, argv, &test->real, &test->ref);
+}
diff --git a/test/test_image.c b/test/test_image.c
new file mode 100644 (file)
index 0000000..f2cf906
--- /dev/null
@@ -0,0 +1,218 @@
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "test.h"
+
+#define MAX_DELTA 3
+
+int pixel_difference(uint32_t a, uint32_t b)
+{
+       int max = 0;
+       int i;
+
+       for (i = 0; i < 32; i += 8) {
+               uint8_t ac = (a >> i) & 0xff;
+               uint8_t bc = (b >> i) & 0xff;
+               int d;
+
+               if (ac > bc)
+                       d = ac - bc;
+               else
+                       d = bc - ac;
+               if (d > max)
+                       max = d;
+       }
+
+       return max;
+}
+
+static void
+show_pixels(char *buf,
+           const XImage *real, const XImage *ref,
+           int x, int y, int w, int h)
+{
+       int i, j, len = 0;
+
+       for (j = y - 2; j <= y + 2; j++) {
+               if (j < 0 || j >= h)
+                       continue;
+
+               for (i = x - 2; i <= x + 2; i++) {
+                       if (i < 0 || i >= w)
+                               continue;
+
+                       len += sprintf(buf+len,
+                                      "%08x ",
+                                      *(uint32_t*)(real->data +
+                                                   j*real->bytes_per_line +
+                                                   i*real->bits_per_pixel/8));
+               }
+
+               len += sprintf(buf+len, "\t");
+
+               for (i = x - 2; i <= x + 2; i++) {
+                       if (i < 0 || i >= w)
+                               continue;
+
+                       len += sprintf(buf+len,
+                                      "%08x ",
+                                      *(uint32_t*)(ref->data +
+                                                   j*real->bytes_per_line +
+                                                   i*real->bits_per_pixel/8));
+               }
+
+               len += sprintf(buf+len, "\n");
+       }
+}
+
+static void test_compare_fallback(struct test *t,
+                                 Drawable real_draw, XRenderPictFormat *real_format,
+                                 Drawable ref_draw, XRenderPictFormat *ref_format,
+                                 int x, int y, int w, int h)
+{
+       XImage *real_image, *ref_image;
+       char *real, *ref;
+       char buf[600];
+       uint32_t mask;
+       int i, j;
+
+       die_unless(real_format->depth == ref_format->depth);
+
+       real_image = XGetImage(t->real.dpy, real_draw,
+                              x, y, w, h,
+                              AllPlanes, ZPixmap);
+       real = real_image->data;
+
+       ref_image = XGetImage(t->ref.dpy, ref_draw,
+                             x, y, w, h,
+                             AllPlanes, ZPixmap);
+       ref = ref_image->data;
+
+       mask = depth_mask(real_image->depth);
+
+       /* Start with an exact comparison. However, one quicky desires
+        * a fuzzy comparator to hide hardware inaccuracies...
+        */
+       for (j = 0; j < h; j++) {
+               for (i = 0; i < w; i++) {
+                       uint32_t a = ((uint32_t *)real)[i] & mask;
+                       uint32_t b = ((uint32_t *)ref)[i] & mask;
+                       if (a != b && pixel_difference(a, b) > MAX_DELTA) {
+                               show_pixels(buf,
+                                           real_image, ref_image,
+                                           i, j, w, h);
+                               die("discrepancy found at (%d+%d, %d+%d): found %08x, expected %08x (delta: %d)\n%s",
+                                   x,i, y,j, a, b, pixel_difference(a, b), buf);
+                       }
+               }
+               real += real_image->bytes_per_line;
+               ref += ref_image->bytes_per_line;
+       }
+
+       XDestroyImage(real_image);
+       XDestroyImage(ref_image);
+}
+
+void test_compare(struct test *t,
+                 Drawable real_draw, XRenderPictFormat *real_format,
+                 Drawable ref_draw, XRenderPictFormat *ref_format,
+                 int x, int y, int w, int h,
+                 const char *info)
+{
+       XImage real_image, ref_image;
+       Pixmap tmp;
+       char *real, *ref;
+       char buf[600];
+       uint32_t mask;
+       int i, j;
+       XGCValues gcv;
+       GC gc;
+
+       if (w * h * 4 > t->real.max_shm_size)
+               return test_compare_fallback(t,
+                                            real_draw, real_format,
+                                            ref_draw, ref_format,
+                                            x, y, w, h);
+
+       test_init_image(&real_image, &t->real.shm, real_format, w, h);
+       test_init_image(&ref_image, &t->ref.shm, ref_format, w, h);
+
+       gcv.graphics_exposures = 0;
+
+       die_unless(real_image.depth == ref_image.depth);
+       die_unless(real_image.bits_per_pixel == ref_image.bits_per_pixel);
+       die_unless(real_image.bits_per_pixel == 32);
+
+       mask = depth_mask(real_image.depth);
+
+       tmp = XCreatePixmap(t->real.dpy, real_draw, w, h, real_image.depth);
+       gc = XCreateGC(t->real.dpy, tmp, GCGraphicsExposures, &gcv);
+       XCopyArea(t->real.dpy, real_draw, tmp, gc, x, y, w, h, 0, 0);
+       XShmGetImage(t->real.dpy, tmp, &real_image, 0, 0, AllPlanes);
+       XFreeGC(t->real.dpy, gc);
+       XFreePixmap(t->real.dpy, tmp);
+       real = real_image.data;
+
+       tmp = XCreatePixmap(t->ref.dpy, ref_draw, w, h, ref_image.depth);
+       gc = XCreateGC(t->ref.dpy, tmp, GCGraphicsExposures, &gcv);
+       XCopyArea(t->ref.dpy, ref_draw, tmp, gc, x, y, w, h, 0, 0);
+       XShmGetImage(t->ref.dpy, tmp, &ref_image, 0, 0, AllPlanes);
+       XFreeGC(t->ref.dpy, gc);
+       XFreePixmap(t->ref.dpy, tmp);
+       ref = ref_image.data;
+
+       /* Start with an exact comparison. However, one quicky desires
+        * a fuzzy comparator to hide hardware inaccuracies...
+        */
+       for (j = 0; j < h; j++) {
+               for (i = 0; i < w; i++) {
+                       uint32_t a = ((uint32_t *)real)[i] & mask;
+                       uint32_t b = ((uint32_t *)ref)[i] & mask;
+                       if (a != b && pixel_difference(a, b) > MAX_DELTA) {
+                               show_pixels(buf,
+                                           &real_image, &ref_image,
+                                           i, j, w, h);
+                               die("discrepancy found at (%d+%d, %d+%d): found %08x, expected %08x (delta: %d)\n%s%s\n",
+                                   x,i, y,j, a, b, pixel_difference(a, b), buf, info);
+                       }
+               }
+               real += real_image.bytes_per_line;
+               ref += ref_image.bytes_per_line;
+       }
+}
+
+static int
+_native_byte_order_lsb(void)
+{
+       int x = 1;
+       return *((char *) &x) == 1;
+}
+
+void
+test_init_image(XImage *ximage,
+               XShmSegmentInfo *shm,
+               XRenderPictFormat *format,
+               int width, int height)
+{
+       int native_byte_order = _native_byte_order_lsb() ? LSBFirst : MSBFirst;
+
+       ximage->width = width;
+       ximage->height = height;
+       ximage->format = ZPixmap;
+       ximage->data = shm->shmaddr;
+       ximage->obdata = (void *)shm;
+       ximage->byte_order = native_byte_order;
+       ximage->bitmap_unit = 32;
+       ximage->bitmap_bit_order = native_byte_order;
+       ximage->bitmap_pad = 32;
+       ximage->depth = format->depth;
+       ximage->bytes_per_line = 4*width;
+       ximage->bits_per_pixel = 32;
+       ximage->red_mask = 0xff << 16;
+       ximage->green_mask = 0xff << 8;
+       ximage->blue_mask = 0xff << 0;
+       ximage->xoffset = 0;
+
+       XInitImage(ximage);
+}
diff --git a/test/test_log.c b/test/test_log.c
new file mode 100644 (file)
index 0000000..55e07e5
--- /dev/null
@@ -0,0 +1,17 @@
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "test.h"
+
+void die(const char *fmt, ...)
+{
+       va_list va;
+
+       va_start(va, fmt);
+       vfprintf(stderr, fmt, va);
+       va_end(va);
+
+       exit(1);
+}
+
diff --git a/test/test_render.c b/test/test_render.c
new file mode 100644 (file)
index 0000000..67889ac
--- /dev/null
@@ -0,0 +1,149 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+
+#include "test.h"
+
+const char *test_target_name(enum target target)
+{
+       switch (target) {
+       default:
+       case ROOT: return "root";
+       case CHILD: return "child";
+       case PIXMAP: return "pixmap";
+       }
+}
+
+void test_target_create_render(struct test_display *dpy,
+                              enum target target,
+                              struct test_target *tt)
+{
+       XSetWindowAttributes attr;
+       XGCValues gcv;
+
+       tt->dpy = dpy;
+       tt->target = target;
+
+       tt->draw = dpy->root;
+       tt->format = dpy->format;
+       tt->width = dpy->width;
+       tt->height = dpy->height;
+
+       switch (target) {
+       case ROOT:
+               break;
+
+       case CHILD:
+               attr.override_redirect = 1;
+               tt->width /= 4;
+               tt->height /= 4;
+               tt->draw = XCreateWindow(dpy->dpy, tt->draw,
+                                        dpy->width/2, dpy->height/2,
+                                        tt->width, tt->height,
+                                        0, tt->format->depth,
+                                        InputOutput,
+                                        DefaultVisual(dpy->dpy,
+                                                      DefaultScreen(dpy->dpy)),
+                                        CWOverrideRedirect, &attr);
+               XMapWindow(dpy->dpy, tt->draw);
+               break;
+
+       case PIXMAP:
+               tt->format = XRenderFindStandardFormat(dpy->dpy, PictStandardARGB32);
+               tt->draw = XCreatePixmap(dpy->dpy, tt->draw,
+                                        dpy->width, dpy->height,
+                                        tt->format->depth);
+               break;
+       }
+
+       tt->picture =
+               XRenderCreatePicture(dpy->dpy, tt->draw, tt->format, 0, NULL);
+
+       gcv.graphics_exposures = 0;
+       tt->gc = XCreateGC(dpy->dpy, tt->draw, GCGraphicsExposures, &gcv);
+}
+
+void test_target_destroy_render(struct test_display *dpy,
+                               struct test_target *tt)
+{
+       XRenderFreePicture(dpy->dpy, tt->picture);
+       switch (tt->target) {
+       case ROOT:
+               break;
+       case CHILD:
+               XDestroyWindow(dpy->dpy, tt->draw);
+               break;
+       case PIXMAP:
+               XFreePixmap(dpy->dpy, tt->draw);
+               break;
+       }
+}
+
+#if 0
+static int random_bool(void)
+{
+       return rand() > RAND_MAX/2;
+}
+
+static Picture create_alpha_map(void)
+{
+       return 0;
+}
+
+static Pixmap create_clip_mask(void)
+{
+       return 0;
+}
+
+unsigned int test_render_randomize_picture_attributes(XRenderPictureAttributes *pa)
+{
+       unsigned int flags = 0;
+
+       memset(pa, 0, sizeof(*pa));
+
+       if (random_bool()) {
+               pa->repeat = repeat_modes[rand() % ARRAY_SIZE(repeat_modes)];
+               flags |= CPRepeat;
+
+       }
+
+       if (random_bool()) {
+               pa->alpha_map = create_alpha_map();
+               pa->alpha_x_origin = rand() % 1024;
+               pa->alpha_y_origin = rand() % 1024;
+               flags |= CPAlphaMap;
+       }
+
+       if (random_bool()) {
+               pa->clip_mask = create_clip_mask();
+               pa->clip_x_orgin = rand() % 1024;
+               pa->clip_y_orgin = rand() % 1024;
+               flags |= CPClipMask;
+       }
+
+       if (random_bool()) {
+               pa->subwindow_mode = random_bool();
+               flags |= CPSubwindowMode;
+       }
+
+       if (random_bool()) {
+               pa->poly_edge = random_bool();
+               flags |= CPPolyEdge;
+       }
+
+       if (random_bool()) {
+               pa->poly_mode = random_bool();
+               flags |= CPPolyMode;
+       }
+
+       if (random_bool()) {
+               pa->component_alpha = random_bool();
+               flags |= CPComponentAlpha;
+       }
+
+       return flags;
+}
+#endif
index c875b63..9763637 100644 (file)
@@ -6,10 +6,16 @@ SOLARIS_ASM_CFLAGS=""
 
 AM_CFLAGS = $(CWARNFLAGS) $(XORG_CFLAGS)
 
+if GLAMOR
+AM_CFLAGS += @LIBGLAMOR_CFLAGS@
+libuxa_la_LIBADD = @LIBGLAMOR_LIBS@
+endif
+
 libuxa_la_SOURCES = \
        uxa.c \
        uxa.h \
        uxa-accel.c \
+       uxa-glamor.h \
        uxa-glyphs.c \
        uxa-render.c \
        uxa-priv.h \
index 7c42c1d..084c703 100644 (file)
@@ -1,9 +1,9 @@
-# Makefile.in generated by automake 1.11.1 from Makefile.am.
+# Makefile.in generated by automake 1.11.6 from Makefile.am.
 # @configure_input@
 
 # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-# 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
-# Inc.
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
+# Foundation, Inc.
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
 @SET_MAKE@
 
 VPATH = @srcdir@
+am__make_dryrun = \
+  { \
+    am__dry=no; \
+    case $$MAKEFLAGS in \
+      *\\[\ \  ]*) \
+        echo 'am--echo: ; @echo "AM"  OK' | $(MAKE) -f - 2>/dev/null \
+          | grep '^AM OK$$' >/dev/null || am__dry=yes;; \
+      *) \
+        for am__flg in $$MAKEFLAGS; do \
+          case $$am__flg in \
+            *=*|--*) ;; \
+            *n*) am__dry=yes; break;; \
+          esac; \
+        done;; \
+    esac; \
+    test $$am__dry = yes; \
+  }
 pkgdatadir = $(datadir)/@PACKAGE@
 pkgincludedir = $(includedir)/@PACKAGE@
 pkglibdir = $(libdir)/@PACKAGE@
@@ -34,13 +51,11 @@ PRE_UNINSTALL = :
 POST_UNINSTALL = :
 build_triplet = @build@
 host_triplet = @host@
+@GLAMOR_TRUE@am__append_1 = @LIBGLAMOR_CFLAGS@
 subdir = uxa
 DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
-       $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
-       $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
-       $(top_srcdir)/configure.ac
+am__aclocal_m4_deps = $(top_srcdir)/configure.ac
 am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
        $(ACLOCAL_M4)
 mkinstalldirs = $(install_sh) -d
@@ -48,15 +63,15 @@ CONFIG_HEADER = $(top_builddir)/config.h
 CONFIG_CLEAN_FILES =
 CONFIG_CLEAN_VPATH_FILES =
 LTLIBRARIES = $(noinst_LTLIBRARIES)
-libuxa_la_LIBADD =
+libuxa_la_DEPENDENCIES =
 am_libuxa_la_OBJECTS = uxa.lo uxa-accel.lo uxa-glyphs.lo uxa-render.lo \
        uxa-unaccel.lo
 libuxa_la_OBJECTS = $(am_libuxa_la_OBJECTS)
-AM_V_lt = $(am__v_lt_$(V))
-am__v_lt_ = $(am__v_lt_$(AM_DEFAULT_VERBOSITY))
+AM_V_lt = $(am__v_lt_@AM_V@)
+am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
 am__v_lt_0 = --silent
 DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
-depcomp = $(SHELL) $(top_srcdir)/build-aux/depcomp
+depcomp = $(SHELL) $(top_srcdir)/depcomp
 am__depfiles_maybe = depfiles
 am__mv = mv -f
 COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
@@ -65,24 +80,29 @@ LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
        $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \
        $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
        $(AM_CFLAGS) $(CFLAGS)
-AM_V_CC = $(am__v_CC_$(V))
-am__v_CC_ = $(am__v_CC_$(AM_DEFAULT_VERBOSITY))
+AM_V_CC = $(am__v_CC_@AM_V@)
+am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@)
 am__v_CC_0 = @echo "  CC    " $@;
-AM_V_at = $(am__v_at_$(V))
-am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY))
+AM_V_at = $(am__v_at_@AM_V@)
+am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
 am__v_at_0 = @
 CCLD = $(CC)
 LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
        $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
        $(AM_LDFLAGS) $(LDFLAGS) -o $@
-AM_V_CCLD = $(am__v_CCLD_$(V))
-am__v_CCLD_ = $(am__v_CCLD_$(AM_DEFAULT_VERBOSITY))
+AM_V_CCLD = $(am__v_CCLD_@AM_V@)
+am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
 am__v_CCLD_0 = @echo "  CCLD  " $@;
-AM_V_GEN = $(am__v_GEN_$(V))
-am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY))
+AM_V_GEN = $(am__v_GEN_@AM_V@)
+am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
 am__v_GEN_0 = @echo "  GEN   " $@;
 SOURCES = $(libuxa_la_SOURCES)
 DIST_SOURCES = $(libuxa_la_SOURCES)
+am__can_run_installinfo = \
+  case $$AM_UPDATE_INFO_DIR in \
+    n|no|NO) false;; \
+    *) (install-info --version) >/dev/null 2>&1;; \
+  esac
 ETAGS = etags
 CTAGS = ctags
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
@@ -98,6 +118,7 @@ AUTOCONF = @AUTOCONF@
 AUTOHEADER = @AUTOHEADER@
 AUTOMAKE = @AUTOMAKE@
 AWK = @AWK@
+BASE_CFLAGS = @BASE_CFLAGS@
 CC = @CC@
 CCDEPMODE = @CCDEPMODE@
 CFLAGS = @CFLAGS@
@@ -108,11 +129,16 @@ CWARNFLAGS = @CWARNFLAGS@
 CYGPATH_W = @CYGPATH_W@
 DEFS = @DEFS@
 DEPDIR = @DEPDIR@
+DLLTOOL = @DLLTOOL@
+DRI2_CFLAGS = @DRI2_CFLAGS@
+DRI2_LIBS = @DRI2_LIBS@
 DRIVER_MAN_DIR = @DRIVER_MAN_DIR@
 DRIVER_MAN_SUFFIX = @DRIVER_MAN_SUFFIX@
 DRIVER_NAME = @DRIVER_NAME@
 DRI_CFLAGS = @DRI_CFLAGS@
 DRI_LIBS = @DRI_LIBS@
+DRMINTEL_CFLAGS = @DRMINTEL_CFLAGS@
+DRMINTEL_LIBS = @DRMINTEL_LIBS@
 DRM_CFLAGS = @DRM_CFLAGS@
 DRM_LIBS = @DRM_LIBS@
 DSYMUTIL = @DSYMUTIL@
@@ -136,6 +162,10 @@ INSTALL_SCRIPT = @INSTALL_SCRIPT@
 INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
 LD = @LD@
 LDFLAGS = @LDFLAGS@
+LIBGLAMOR_CFLAGS = @LIBGLAMOR_CFLAGS@
+LIBGLAMOR_EGL_CFLAGS = @LIBGLAMOR_EGL_CFLAGS@
+LIBGLAMOR_EGL_LIBS = @LIBGLAMOR_EGL_LIBS@
+LIBGLAMOR_LIBS = @LIBGLAMOR_LIBS@
 LIBOBJS = @LIBOBJS@
 LIBS = @LIBS@
 LIBTOOL = @LIBTOOL@
@@ -146,6 +176,7 @@ LN_S = @LN_S@
 LTLIBOBJS = @LTLIBOBJS@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
+MANIFEST_TOOL = @MANIFEST_TOOL@
 MAN_SUBSTS = @MAN_SUBSTS@
 MISC_MAN_DIR = @MISC_MAN_DIR@
 MISC_MAN_SUFFIX = @MISC_MAN_SUFFIX@
@@ -173,10 +204,15 @@ RANLIB = @RANLIB@
 SED = @SED@
 SET_MAKE = @SET_MAKE@
 SHELL = @SHELL@
+STRICT_CFLAGS = @STRICT_CFLAGS@
 STRIP = @STRIP@
 UDEV_CFLAGS = @UDEV_CFLAGS@
 UDEV_LIBS = @UDEV_LIBS@
+VALGRIND_CFLAGS = @VALGRIND_CFLAGS@
+VALGRIND_LIBS = @VALGRIND_LIBS@
 VERSION = @VERSION@
+X11_CFLAGS = @X11_CFLAGS@
+X11_LIBS = @X11_LIBS@
 XORG_CFLAGS = @XORG_CFLAGS@
 XORG_LIBS = @XORG_LIBS@
 XORG_MAN_PAGE = @XORG_MAN_PAGE@
@@ -186,6 +222,7 @@ abs_builddir = @abs_builddir@
 abs_srcdir = @abs_srcdir@
 abs_top_builddir = @abs_top_builddir@
 abs_top_srcdir = @abs_top_srcdir@
+ac_ct_AR = @ac_ct_AR@
 ac_ct_CC = @ac_ct_CC@
 ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
 am__include = @am__include@
@@ -218,7 +255,6 @@ libdir = @libdir@
 libexecdir = @libexecdir@
 localedir = @localedir@
 localstatedir = @localstatedir@
-lt_ECHO = @lt_ECHO@
 mandir = @mandir@
 mkdir_p = @mkdir_p@
 moduledir = @moduledir@
@@ -240,11 +276,13 @@ noinst_LTLIBRARIES = libuxa.la
 # Override these since UXA doesn't need them and the needed files aren't
 # built (in hw/xfree86/os-support/solaris) until after UXA is built
 SOLARIS_ASM_CFLAGS = ""
-AM_CFLAGS = $(CWARNFLAGS) $(XORG_CFLAGS)
+AM_CFLAGS = $(CWARNFLAGS) $(XORG_CFLAGS) $(am__append_1)
+@GLAMOR_TRUE@libuxa_la_LIBADD = @LIBGLAMOR_LIBS@
 libuxa_la_SOURCES = \
        uxa.c \
        uxa.h \
        uxa-accel.c \
+       uxa-glamor.h \
        uxa-glyphs.c \
        uxa-render.c \
        uxa-priv.h \
@@ -293,7 +331,7 @@ clean-noinstLTLIBRARIES:
          echo "rm -f \"$${dir}/so_locations\""; \
          rm -f "$${dir}/so_locations"; \
        done
-libuxa.la: $(libuxa_la_OBJECTS) $(libuxa_la_DEPENDENCIES) 
+libuxa.la: $(libuxa_la_OBJECTS) $(libuxa_la_DEPENDENCIES) $(EXTRA_libuxa_la_DEPENDENCIES) 
        $(AM_V_CCLD)$(LINK)  $(libuxa_la_OBJECTS) $(libuxa_la_LIBADD) $(LIBS)
 
 mostlyclean-compile:
@@ -311,26 +349,23 @@ distclean-compile:
 .c.o:
 @am__fastdepCC_TRUE@   $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
 @am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
-@am__fastdepCC_FALSE@  $(AM_V_CC) @AM_BACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@  $(COMPILE) -c $<
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(COMPILE) -c $<
 
 .c.obj:
 @am__fastdepCC_TRUE@   $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
 @am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
-@am__fastdepCC_FALSE@  $(AM_V_CC) @AM_BACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@  $(COMPILE) -c `$(CYGPATH_W) '$<'`
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(COMPILE) -c `$(CYGPATH_W) '$<'`
 
 .c.lo:
 @am__fastdepCC_TRUE@   $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
 @am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
-@am__fastdepCC_FALSE@  $(AM_V_CC) @AM_BACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@  $(LTCOMPILE) -c -o $@ $<
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $<
 
 mostlyclean-libtool:
        -rm -f *.lo
@@ -434,10 +469,15 @@ install-am: all-am
 
 installcheck: installcheck-am
 install-strip:
-       $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
-         install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
-         `test -z '$(STRIP)' || \
-           echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+       if test -z '$(STRIP)'; then \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+             install; \
+       else \
+         $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+           install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+           "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+       fi
 mostlyclean-generic:
 
 clean-generic:
index 0650ac2..76425fe 100644 (file)
@@ -1,3 +1,4 @@
+
 /*
  * Copyright ® 2001 Keith Packard
  *
 #include <dix-config.h>
 #endif
 #include "uxa-priv.h"
+#include "uxa-glamor.h"
 #include <X11/fonts/fontstruct.h>
 #include "dixfontstr.h"
 #include "uxa.h"
 #include "mipict.h"
 
-static CARD32
-format_for_depth(int depth)
-{
-       switch (depth) {
-       case 1: return PICT_a1;
-       case 4: return PICT_a4;
-       case 8: return PICT_a8;
-       case 15: return PICT_x1r5g5b5;
-       case 16: return PICT_r5g6b5;
-       default:
-       case 24: return PICT_x8r8g8b8;
-#if XORG_VERSION_CURRENT >= 10699900
-       case 30: return PICT_x2r10g10b10;
-#endif
-       case 32: return PICT_a8r8g8b8;
-       }
-}
-
 static void
 uxa_fill_spans(DrawablePtr pDrawable, GCPtr pGC, int n,
               DDXPointPtr ppt, int *pwidth, int fSorted)
@@ -61,151 +45,37 @@ uxa_fill_spans(DrawablePtr pDrawable, GCPtr pGC, int n,
        ScreenPtr screen = pDrawable->pScreen;
        uxa_screen_t *uxa_screen = uxa_get_screen(screen);
        RegionPtr pClip = fbGetCompositeClip(pGC);
-       PixmapPtr dst_pixmap, src_pixmap = NULL;
-       BoxPtr pextent, pbox;
+       PixmapPtr dst_pixmap;
+       BoxPtr pbox;
        int nbox;
-       int extentX1, extentX2, extentY1, extentY2;
-       int fullX1, fullX2, fullY1;
-       int partX1, partX2;
+       int x1, x2, y;
        int off_x, off_y;
-       xRenderColor color;
-       PictFormatPtr format;
-       PicturePtr dst, src;
-       int error;
-
-       if (uxa_screen->swappedOut || uxa_screen->force_fallback)
-               goto fallback;
-
-       if (pGC->fillStyle != FillSolid)
-               goto fallback;
-
-       dst_pixmap = uxa_get_offscreen_pixmap(pDrawable, &off_x, &off_y);
-       if (!dst_pixmap)
-               goto fallback;
-
-       if (pGC->alu != GXcopy || !UXA_PM_IS_SOLID(pDrawable, pGC->planemask))
-               goto solid;
-
-       format = PictureMatchFormat(screen,
-                                   dst_pixmap->drawable.depth,
-                                   format_for_depth(dst_pixmap->drawable.depth));
-       dst = CreatePicture(0, &dst_pixmap->drawable, format, 0, 0, serverClient, &error);
-       if (!dst)
-               goto solid;
-
-       ValidatePicture(dst);
-
-       uxa_get_rgba_from_pixel(pGC->fgPixel,
-                               &color.red,
-                               &color.green,
-                               &color.blue,
-                               &color.alpha,
-                               format_for_depth(dst_pixmap->drawable.depth));
-       src = CreateSolidPicture(0, &color, &error);
-       if (!src) {
-               FreePicture(dst, 0);
-               goto solid;
-       }
-
-       if (!uxa_screen->info->check_composite(PictOpSrc, src, NULL, dst, 0, 0)) {
-               FreePicture(src, 0);
-               FreePicture(dst, 0);
-               goto solid;
-       }
 
-       if (!uxa_screen->info->check_composite_texture ||
-           !uxa_screen->info->check_composite_texture(screen, src)) {
-               PicturePtr solid;
-               int src_off_x, src_off_y;
+       if (uxa_screen->info->flags & UXA_USE_GLAMOR) {
+               int ok = 0;
 
-               solid = uxa_acquire_solid(screen, src->pSourcePict);
-               FreePicture(src, 0);
-               if (!solid) {
-                       FreePicture(dst, 0);
-                       goto solid;
+               if (uxa_prepare_access(pDrawable, UXA_GLAMOR_ACCESS_RW)) {
+                       ok = glamor_fill_spans_nf(pDrawable,
+                                                 pGC, n, ppt, pwidth, fSorted);
+                       uxa_finish_access(pDrawable, UXA_GLAMOR_ACCESS_RW);
                }
 
-               src = solid;
-               src_pixmap = uxa_get_offscreen_pixmap(src->pDrawable,
-                                                     &src_off_x, &src_off_y);
-               if (!src_pixmap) {
-                       FreePicture(src, 0);
-                       FreePicture(dst, 0);
-                       goto solid;
-               }
-       }
+               if (!ok)
+                       goto fallback;
 
-       if (!uxa_screen->info->prepare_composite(PictOpSrc, src, NULL, dst, src_pixmap, NULL, dst_pixmap)) {
-               FreePicture(src, 0);
-               FreePicture(dst, 0);
-               goto solid;
+               return;
        }
 
-       pextent = REGION_EXTENTS(pGC->screen, pClip);
-       extentX1 = pextent->x1;
-       extentY1 = pextent->y1;
-       extentX2 = pextent->x2;
-       extentY2 = pextent->y2;
-       while (n--) {
-               fullX1 = ppt->x;
-               fullY1 = ppt->y;
-               fullX2 = fullX1 + (int)*pwidth;
-               ppt++;
-               pwidth++;
-
-               if (fullY1 < extentY1 || extentY2 <= fullY1)
-                       continue;
-
-               if (fullX1 < extentX1)
-                       fullX1 = extentX1;
-
-               if (fullX2 > extentX2)
-                       fullX2 = extentX2;
-
-               if (fullX1 >= fullX2)
-                       continue;
+       if (uxa_screen->force_fallback)
+               goto fallback;
 
-               nbox = REGION_NUM_RECTS(pClip);
-               if (nbox == 1) {
-                       uxa_screen->info->composite(dst_pixmap,
-                                                   0, 0, 0, 0,
-                                                   fullX1 + off_x,
-                                                   fullY1 + off_y,
-                                                   fullX2 - fullX1, 1);
-               } else {
-                       pbox = REGION_RECTS(pClip);
-                       while (nbox--) {
-                               if (pbox->y1 > fullY1)
-                                       break;
-
-                               if (pbox->y1 <= fullY1) {
-                                       partX1 = pbox->x1;
-                                       if (partX1 < fullX1)
-                                               partX1 = fullX1;
-
-                                       partX2 = pbox->x2;
-                                       if (partX2 > fullX2)
-                                               partX2 = fullX2;
-
-                                       if (partX2 > partX1) {
-                                               uxa_screen->info->composite(dst_pixmap,
-                                                                           0, 0, 0, 0,
-                                                                           partX1 + off_x,
-                                                                           fullY1 + off_y,
-                                                                           partX2 - partX1, 1);
-                                       }
-                               }
-                               pbox++;
-                       }
-               }
-       }
+       if (pGC->fillStyle != FillSolid)
+               goto fallback;
 
-       uxa_screen->info->done_composite(dst_pixmap);
-       FreePicture(src, 0);
-       FreePicture(dst, 0);
-       return;
+       dst_pixmap = uxa_get_offscreen_pixmap(pDrawable, &off_x, &off_y);
+       if (!dst_pixmap)
+               goto fallback;
 
-solid:
        if (uxa_screen->info->check_solid &&
            !uxa_screen->info->check_solid(pDrawable, pGC->alu, pGC->planemask))
                goto fallback;
@@ -216,58 +86,28 @@ solid:
                                                 pGC->fgPixel))
                goto fallback;
 
-       pextent = REGION_EXTENTS(pGC->screen, pClip);
-       extentX1 = pextent->x1;
-       extentY1 = pextent->y1;
-       extentX2 = pextent->x2;
-       extentY2 = pextent->y2;
        while (n--) {
-               fullX1 = ppt->x;
-               fullY1 = ppt->y;
-               fullX2 = fullX1 + (int)*pwidth;
+               x1 = ppt->x;
+               y = ppt->y;
+               x2 = x1 + (int)*pwidth;
                ppt++;
                pwidth++;
 
-               if (fullY1 < extentY1 || extentY2 <= fullY1)
-                       continue;
-
-               if (fullX1 < extentX1)
-                       fullX1 = extentX1;
-
-               if (fullX2 > extentX2)
-                       fullX2 = extentX2;
+               nbox = REGION_NUM_RECTS(pClip);
+               pbox = REGION_RECTS(pClip);
+               while (nbox--) {
+                       int X1 = x1, X2 = x2;
+                       if (X1 < pbox->x1)
+                               X1 = pbox->x1;
 
-               if (fullX1 >= fullX2)
-                       continue;
+                       if (X2 > pbox->x2)
+                               X2 = pbox->x2;
 
-               nbox = REGION_NUM_RECTS(pClip);
-               if (nbox == 1) {
-                       (*uxa_screen->info->solid) (dst_pixmap,
-                                                   fullX1 + off_x,
-                                                   fullY1 + off_y,
-                                                   fullX2 + off_x,
-                                                   fullY1 + 1 + off_y);
-               } else {
-                       pbox = REGION_RECTS(pClip);
-                       while (nbox--) {
-                               if (pbox->y1 <= fullY1 && fullY1 < pbox->y2) {
-                                       partX1 = pbox->x1;
-                                       if (partX1 < fullX1)
-                                               partX1 = fullX1;
-                                       partX2 = pbox->x2;
-                                       if (partX2 > fullX2)
-                                               partX2 = fullX2;
-                                       if (partX2 > partX1) {
-                                               (*uxa_screen->info->
-                                                solid) (dst_pixmap,
-                                                        partX1 + off_x,
-                                                        fullY1 + off_y,
-                                                        partX2 + off_x,
-                                                        fullY1 + 1 + off_y);
-                                       }
-                               }
-                               pbox++;
-                       }
+                       if (X2 > X1 && pbox->y1 <= y && pbox->y2 > y)
+                               (*uxa_screen->info->solid) (dst_pixmap,
+                                                           X1 + off_x, y + off_y,
+                                                           X2 + off_x, y + 1 + off_y);
+                       pbox++;
                }
        }
        (*uxa_screen->info->done_solid) (dst_pixmap);
@@ -294,7 +134,7 @@ uxa_do_put_image(DrawablePtr pDrawable, GCPtr pGC, int depth, int x, int y,
        if (format != ZPixmap || bpp < 8)
                return FALSE;
 
-       if (uxa_screen->swappedOut || uxa_screen->force_fallback)
+       if (uxa_screen->force_fallback)
                return FALSE;
 
        if (!uxa_screen->info->put_image)
@@ -359,7 +199,7 @@ uxa_do_put_image(DrawablePtr pDrawable, GCPtr pGC, int depth, int x, int y,
                                  (x1 + dstXoff) * dstBpp, (x2 - x1) * dstBpp,
                                  y2 - y1, GXcopy, FB_ALLONES, dstBpp);
 
-                       uxa_finish_access(pDrawable);
+                       uxa_finish_access(pDrawable, UXA_ACCESS_RW);
                }
        }
 
@@ -371,10 +211,29 @@ static void
 uxa_put_image(DrawablePtr pDrawable, GCPtr pGC, int depth, int x, int y,
              int w, int h, int leftPad, int format, char *bits)
 {
+       uxa_screen_t *uxa_screen = uxa_get_screen(pDrawable->pScreen);
+
+       if (uxa_screen->info->flags & UXA_USE_GLAMOR) {
+               int ok = 0;
+
+               if (uxa_prepare_access(pDrawable, UXA_GLAMOR_ACCESS_RW)) {
+                       ok = glamor_put_image_nf(pDrawable,
+                                                pGC, depth, x, y, w, h,
+                                                leftPad, format, bits);
+                       uxa_finish_access(pDrawable, UXA_GLAMOR_ACCESS_RW);
+               }
+               if (!ok)
+                       goto fallback;
+
+               return;
+       }
+
        if (!uxa_do_put_image(pDrawable, pGC, depth, x, y, w, h, format, bits,
-                             PixmapBytePad(w, pDrawable->depth)))
+                             PixmapBytePad(w, pDrawable->depth))) {
+fallback:
                uxa_check_put_image(pDrawable, pGC, depth, x, y, w, h, leftPad,
                                    format, bits);
+       }
 }
 
 static Bool inline
@@ -516,7 +375,27 @@ uxa_copy_n_to_n(DrawablePtr pSrcDrawable,
        int dst_off_x, dst_off_y;
        PixmapPtr pSrcPixmap, pDstPixmap;
 
-       if (uxa_screen->swappedOut || uxa_screen->force_fallback)
+       if (uxa_screen->info->flags & UXA_USE_GLAMOR) {
+               int ok = 0;
+
+               if (uxa_prepare_access(pSrcDrawable, UXA_GLAMOR_ACCESS_RO)) {
+                       if (uxa_prepare_access(pDstDrawable, UXA_GLAMOR_ACCESS_RW)) {
+                               ok = glamor_copy_n_to_n_nf(pSrcDrawable, pDstDrawable,
+                                                          pGC, pbox, nbox, dx, dy,
+                                                          reverse, upsidedown, bitplane,
+                                                          closure);
+                               uxa_finish_access(pDstDrawable, UXA_GLAMOR_ACCESS_RW);
+                       }
+                       uxa_finish_access(pSrcDrawable, UXA_GLAMOR_ACCESS_RO);
+               }
+
+               if (!ok)
+                       goto fallback;
+
+               return;
+       }
+
+       if (uxa_screen->force_fallback)
                goto fallback;
 
        pSrcPixmap = uxa_get_drawable_pixmap(pSrcDrawable);
@@ -653,9 +532,9 @@ fallback:
                                   dx, dy, reverse, upsidedown, bitplane,
                                   closure);
                        if (pSrcDrawable != pDstDrawable)
-                               uxa_finish_access(pSrcDrawable);
+                               uxa_finish_access(pSrcDrawable, UXA_ACCESS_RO);
                }
-               uxa_finish_access(pDstDrawable);
+               uxa_finish_access(pDstDrawable, UXA_ACCESS_RW);
        }
 }
 
@@ -665,7 +544,7 @@ uxa_copy_area(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable, GCPtr pGC,
 {
        uxa_screen_t *uxa_screen = uxa_get_screen(pDstDrawable->pScreen);
 
-       if (uxa_screen->swappedOut || uxa_screen->force_fallback) {
+       if (uxa_screen->force_fallback) {
                return uxa_check_copy_area(pSrcDrawable, pDstDrawable, pGC,
                                           srcx, srcy, width, height, dstx,
                                           dsty);
@@ -682,6 +561,19 @@ uxa_poly_point(DrawablePtr pDrawable, GCPtr pGC, int mode, int npt,
 {
        int i;
        xRectangle *prect;
+       uxa_screen_t *uxa_screen = uxa_get_screen(pDrawable->pScreen);
+
+       if (uxa_screen->info->flags & UXA_USE_GLAMOR) {
+               int ok = 0;
+
+               if (uxa_prepare_access(pDrawable, UXA_GLAMOR_ACCESS_RW)) {
+                       ok = glamor_poly_point_nf(pDrawable, pGC, mode, npt, ppt);
+                       uxa_finish_access(pDrawable, UXA_GLAMOR_ACCESS_RW);
+               }
+
+               if (ok)
+                       return;
+       }
 
        /* If we can't reuse the current GC as is, don't bother accelerating the
         * points.
@@ -720,6 +612,19 @@ uxa_poly_lines(DrawablePtr pDrawable, GCPtr pGC, int mode, int npt,
        xRectangle *prect;
        int x1, x2, y1, y2;
        int i;
+       uxa_screen_t *uxa_screen = uxa_get_screen(pDrawable->pScreen);
+
+       if (uxa_screen->info->flags & UXA_USE_GLAMOR) {
+               int ok = 0;
+
+               if (uxa_prepare_access(pDrawable, UXA_GLAMOR_ACCESS_RW)) {
+                       ok = glamor_poly_lines_nf(pDrawable, pGC, mode, npt, ppt);
+                       uxa_finish_access(pDrawable, UXA_GLAMOR_ACCESS_RW);
+               }
+
+               if (ok)
+                       return;
+       }
 
        /* Don't try to do wide lines or non-solid fill style. */
        if (pGC->lineWidth != 0 || pGC->lineStyle != LineSolid ||
@@ -781,6 +686,19 @@ uxa_poly_segment(DrawablePtr pDrawable, GCPtr pGC, int nseg, xSegment * pSeg)
 {
        xRectangle *prect;
        int i;
+       uxa_screen_t *uxa_screen = uxa_get_screen(pDrawable->pScreen);
+
+       if (uxa_screen->info->flags & UXA_USE_GLAMOR) {
+               int ok = 0;
+
+               if (uxa_prepare_access(pDrawable, UXA_GLAMOR_ACCESS_RW)) {
+                       ok = glamor_poly_segment_nf(pDrawable, pGC, nseg, pSeg);
+                       uxa_finish_access(pDrawable, UXA_GLAMOR_ACCESS_RW);
+               }
+
+               if (ok)
+                       return;
+       }
 
        /* Don't try to do wide lines or non-solid fill style. */
        if (pGC->lineWidth != 0 || pGC->lineStyle != LineSolid ||
@@ -838,24 +756,36 @@ uxa_poly_fill_rect(DrawablePtr pDrawable,
        uxa_screen_t *uxa_screen = uxa_get_screen(pDrawable->pScreen);
        RegionPtr pClip = fbGetCompositeClip(pGC);
        PixmapPtr pPixmap;
-       register BoxPtr pbox;
-       BoxPtr pextent;
-       int extentX1, extentX2, extentY1, extentY2;
+       RegionPtr pReg;
+       BoxPtr pbox;
        int fullX1, fullX2, fullY1, fullY2;
-       int partX1, partX2, partY1, partY2;
        int xoff, yoff;
        int xorg, yorg;
        int n;
-       RegionPtr pReg = RECTS_TO_REGION(pScreen, nrect, prect, CT_UNSORTED);
+
+       if (uxa_screen->info->flags & UXA_USE_GLAMOR) {
+               int ok = 0;
+
+               if (uxa_prepare_access(pDrawable, UXA_GLAMOR_ACCESS_RW)) {
+                       ok = glamor_poly_fill_rect_nf(pDrawable, pGC, nrect, prect);
+                       uxa_finish_access(pDrawable, UXA_GLAMOR_ACCESS_RW);
+               }
+
+               if (!ok)
+                       uxa_check_poly_fill_rect(pDrawable, pGC, nrect, prect);
+
+               return;
+       }
 
        /* Compute intersection of rects and clip region */
+       pReg = RECTS_TO_REGION(pScreen, nrect, prect, CT_UNSORTED);
        REGION_TRANSLATE(pScreen, pReg, pDrawable->x, pDrawable->y);
        REGION_INTERSECT(pScreen, pReg, pClip, pReg);
 
        if (!REGION_NUM_RECTS(pReg))
                goto out;
 
-       if (uxa_screen->swappedOut || uxa_screen->force_fallback)
+       if (uxa_screen->force_fallback)
                goto fallback;
 
        pPixmap = uxa_get_offscreen_pixmap (pDrawable, &xoff, &yoff);
@@ -904,11 +834,6 @@ fallback:
        xorg = pDrawable->x;
        yorg = pDrawable->y;
 
-       pextent = REGION_EXTENTS(pGC->pScreen, pClip);
-       extentX1 = pextent->x1;
-       extentY1 = pextent->y1;
-       extentX2 = pextent->x2;
-       extentY2 = pextent->y2;
        while (nrect--) {
                fullX1 = prect->x + xorg;
                fullY1 = prect->y + yorg;
@@ -916,62 +841,37 @@ fallback:
                fullY2 = fullY1 + (int)prect->height;
                prect++;
 
-               if (fullX1 < extentX1)
-                       fullX1 = extentX1;
-
-               if (fullY1 < extentY1)
-                       fullY1 = extentY1;
-
-               if (fullX2 > extentX2)
-                       fullX2 = extentX2;
+               n = REGION_NUM_RECTS(pClip);
+               pbox = REGION_RECTS(pClip);
+               /*
+                * clip the rectangle to each box in the clip region
+                * this is logically equivalent to calling Intersect(),
+                * but rectangles may overlap each other here.
+                */
+               while (n--) {
+                       int x1 = fullX1;
+                       int x2 = fullX2;
+                       int y1 = fullY1;
+                       int y2 = fullY2;
+
+                       if (pbox->x1 > x1)
+                               x1 = pbox->x1;
+                       if (pbox->x2 < x2)
+                               x2 = pbox->x2;
+                       if (pbox->y1 > y1)
+                               y1 = pbox->y1;
+                       if (pbox->y2 < y2)
+                               y2 = pbox->y2;
+                       pbox++;
 
-               if (fullY2 > extentY2)
-                       fullY2 = extentY2;
+                       if (x1 >= x2 || y1 >= y2)
+                               continue;
 
-               if ((fullX1 >= fullX2) || (fullY1 >= fullY2))
-                       continue;
-               n = REGION_NUM_RECTS(pClip);
-               if (n == 1) {
                        (*uxa_screen->info->solid) (pPixmap,
-                                                   fullX1 + xoff,
-                                                   fullY1 + yoff,
-                                                   fullX2 + xoff,
-                                                   fullY2 + yoff);
-               } else {
-                       pbox = REGION_RECTS(pClip);
-                       /*
-                        * clip the rectangle to each box in the clip region
-                        * this is logically equivalent to calling Intersect(),
-                        * but rectangles may overlap each other here.
-                        */
-                       while (n--) {
-                               partX1 = pbox->x1;
-                               if (partX1 < fullX1)
-                                       partX1 = fullX1;
-                               partY1 = pbox->y1;
-                               if (partY1 < fullY1)
-                                       partY1 = fullY1;
-                               partX2 = pbox->x2;
-                               if (partX2 > fullX2)
-                                       partX2 = fullX2;
-                               partY2 = pbox->y2;
-                               if (partY2 > fullY2)
-                                       partY2 = fullY2;
-
-                               pbox++;
-
-                               if (partX1 < partX2 && partY1 < partY2) {
-                                       (*uxa_screen->info->solid) (pPixmap,
-                                                                   partX1 +
-                                                                   xoff,
-                                                                   partY1 +
-                                                                   yoff,
-                                                                   partX2 +
-                                                                   xoff,
-                                                                   partY2 +
-                                                                   yoff);
-                               }
-                       }
+                                                   x1 + xoff,
+                                                   y1 + yoff,
+                                                   x2 + xoff,
+                                                   y2 + yoff);
                }
        }
        (*uxa_screen->info->done_solid) (pPixmap);
@@ -981,12 +881,169 @@ out:
        REGION_DESTROY(pScreen, pReg);
 }
 
+void
+uxa_get_spans(DrawablePtr pDrawable,
+             int wMax,
+             DDXPointPtr ppt, int *pwidth, int nspans, char *pdstStart)
+{
+       ScreenPtr screen = pDrawable->pScreen;
+       uxa_screen_t *uxa_screen = uxa_get_screen(screen);
+
+       if (uxa_screen->info->flags & UXA_USE_GLAMOR) {
+               int ok = 0;
+
+               if (uxa_prepare_access(pDrawable, UXA_GLAMOR_ACCESS_RW)) {
+                       ok = glamor_get_spans_nf(pDrawable, wMax, ppt,
+                                                pwidth, nspans, pdstStart);
+                       uxa_finish_access(pDrawable, UXA_GLAMOR_ACCESS_RW);
+               }
+
+               if (!ok)
+                       goto fallback;
+
+               return;
+       }
+
+fallback:
+       uxa_check_get_spans(pDrawable, wMax, ppt, pwidth, nspans, pdstStart);
+}
+
+static void
+uxa_set_spans(DrawablePtr pDrawable, GCPtr gc, char *src,
+                 DDXPointPtr points, int *widths, int n, int sorted)
+{
+       ScreenPtr screen = pDrawable->pScreen;
+       uxa_screen_t *uxa_screen = uxa_get_screen(screen);
+
+       if (uxa_screen->info->flags & UXA_USE_GLAMOR) {
+               int ok = 0;
+
+               if (uxa_prepare_access(pDrawable, UXA_GLAMOR_ACCESS_RW)) {
+                       ok = glamor_set_spans_nf(pDrawable, gc, src,
+                                                points, widths, n, sorted);
+                       uxa_finish_access(pDrawable, UXA_GLAMOR_ACCESS_RW);
+               }
+
+               if (!ok)
+                       goto fallback;
+
+               return;
+       }
+
+fallback:
+       uxa_check_set_spans(pDrawable, gc, src, points, widths, n, sorted);
+}
+
+static RegionPtr
+uxa_copy_plane(DrawablePtr pSrc, DrawablePtr pDst, GCPtr pGC,
+              int srcx, int srcy, int w, int h, int dstx, int dsty,
+              unsigned long bitPlane)
+{
+       ScreenPtr screen = pDst->pScreen;
+       uxa_screen_t *uxa_screen = uxa_get_screen(screen);
+
+       if (uxa_screen->info->flags & UXA_USE_GLAMOR) {
+               int ok = 0;
+               RegionPtr region;
+
+               if (uxa_prepare_access(pDst, UXA_GLAMOR_ACCESS_RW)) {
+                       if (uxa_prepare_access(pSrc, UXA_GLAMOR_ACCESS_RO)) {
+                               ok = glamor_copy_plane_nf(pSrc, pDst, pGC, srcx, srcy, w, h,
+                                                         dstx, dsty, bitPlane, &region);
+                               uxa_finish_access(pSrc, UXA_GLAMOR_ACCESS_RO);
+                       }
+                       uxa_finish_access(pDst, UXA_GLAMOR_ACCESS_RW);
+               }
+               if (!ok)
+                       goto fallback;
+               return region;
+       }
+
+fallback:
+       return uxa_check_copy_plane(pSrc, pDst, pGC, srcx, srcy, w, h,
+                                   dstx, dsty, bitPlane);
+}
+
+static void
+uxa_image_glyph_blt(DrawablePtr pDrawable, GCPtr pGC,
+                   int x, int y, unsigned int nglyph,
+                   CharInfoPtr * ppci, pointer pglyphBase)
+{
+       ScreenPtr screen = pDrawable->pScreen;
+       uxa_screen_t *uxa_screen = uxa_get_screen(screen);
+
+       if (uxa_screen->info->flags & UXA_USE_GLAMOR) {
+               int ok = 0;
+
+               if (uxa_prepare_access(pDrawable, UXA_GLAMOR_ACCESS_RW)) {
+                       ok = glamor_image_glyph_blt_nf(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase);
+                       uxa_finish_access(pDrawable, UXA_GLAMOR_ACCESS_RW);
+               }
+               if (!ok)
+                       goto fallback;
+               return;
+       }
+
+fallback:
+       uxa_check_image_glyph_blt(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase);
+}
+
+static void
+uxa_poly_glyph_blt(DrawablePtr pDrawable, GCPtr pGC,
+                  int x, int y, unsigned int nglyph,
+                  CharInfoPtr * ppci, pointer pglyphBase)
+{
+       ScreenPtr screen = pDrawable->pScreen;
+       uxa_screen_t *uxa_screen = uxa_get_screen(screen);
+
+       if (uxa_screen->info->flags & UXA_USE_GLAMOR) {
+               int ok = 0;
+
+               if (uxa_prepare_access(pDrawable, UXA_GLAMOR_ACCESS_RW)) {
+                       ok = glamor_poly_glyph_blt_nf(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase);
+                       uxa_finish_access(pDrawable, UXA_GLAMOR_ACCESS_RW);
+               }
+               if (!ok)
+                       goto fallback;
+               return;
+       }
+
+fallback:
+       uxa_check_poly_glyph_blt(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase);
+}
+
+static void
+uxa_push_pixels(GCPtr pGC, PixmapPtr pBitmap,
+               DrawablePtr pDrawable, int w, int h, int x, int y)
+{
+       ScreenPtr screen = pDrawable->pScreen;
+       uxa_screen_t *uxa_screen = uxa_get_screen(screen);
+
+       if (uxa_screen->info->flags & UXA_USE_GLAMOR) {
+               int ok = 0;
+
+               if (uxa_prepare_access(pDrawable, UXA_GLAMOR_ACCESS_RW)) {
+                       if (uxa_prepare_access(&pBitmap->drawable, UXA_GLAMOR_ACCESS_RO)) {
+                               ok = glamor_push_pixels_nf(pGC, pBitmap, pDrawable, w, h, x, y);
+                               uxa_finish_access(&pBitmap->drawable, UXA_GLAMOR_ACCESS_RO);
+                       }
+                       uxa_prepare_access(pDrawable, UXA_GLAMOR_ACCESS_RW);
+               }
+               if (!ok)
+                       goto fallback;
+               return;
+       }
+
+fallback:
+       uxa_check_push_pixels(pGC, pBitmap, pDrawable, w, h, x, y);
+}
+
 const GCOps uxa_ops = {
        uxa_fill_spans,
-       uxa_check_set_spans,
+       uxa_set_spans,
        uxa_put_image,
        uxa_copy_area,
-       uxa_check_copy_plane,
+       uxa_copy_plane,
        uxa_poly_point,
        uxa_poly_lines,
        uxa_poly_segment,
@@ -999,9 +1056,9 @@ const GCOps uxa_ops = {
        miPolyText16,
        miImageText8,
        miImageText16,
-       uxa_check_image_glyph_blt,
-       uxa_check_poly_glyph_blt,
-       uxa_check_push_pixels,
+       uxa_image_glyph_blt,
+       uxa_poly_glyph_blt,
+       uxa_push_pixels,
 };
 
 void uxa_copy_window(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
@@ -1040,7 +1097,7 @@ uxa_fill_region_solid(DrawablePtr pDrawable,
        PixmapPtr pixmap;
        int xoff, yoff;
        int nbox;
-       BoxPtr pBox, extents;
+       BoxPtr pBox;
        Bool ret = FALSE;
 
        pixmap = uxa_get_offscreen_pixmap(pDrawable, &xoff, &yoff);
@@ -1051,105 +1108,21 @@ uxa_fill_region_solid(DrawablePtr pDrawable,
 
        nbox = REGION_NUM_RECTS(pRegion);
        pBox = REGION_RECTS(pRegion);
-       extents = REGION_EXTENTS(screen, pRegion);
-
-       /* Using GEM, the relocation costs outweigh the advantages of the blitter */
-       if (nbox == 1 || (alu != GXcopy && alu != GXclear) || !UXA_PM_IS_SOLID(&pixmap->drawable, planemask)) {
-try_solid:
-               if (uxa_screen->info->check_solid &&
-                   !uxa_screen->info->check_solid(&pixmap->drawable, alu, planemask))
-                       goto err;
 
-               if (!uxa_screen->info->prepare_solid(pixmap, alu, planemask, pixel))
-                       goto err;
-
-               while (nbox--) {
-                       uxa_screen->info->solid(pixmap,
-                                               pBox->x1, pBox->y1,
-                                               pBox->x2, pBox->y2);
-                       pBox++;
-               }
-
-               uxa_screen->info->done_solid(pixmap);
-       } else {
-               PicturePtr dst, src;
-               PixmapPtr src_pixmap = NULL;
-               xRenderColor color;
-               int error;
-
-               dst = CreatePicture(0, &pixmap->drawable,
-                                   PictureMatchFormat(screen,
-                                                      pixmap->drawable.depth,
-                                                      format_for_depth(pixmap->drawable.depth)),
-                                   0, 0, serverClient, &error);
-               if (!dst)
-                       goto err;
-
-               ValidatePicture(dst);
-
-               uxa_get_rgba_from_pixel(pixel,
-                                       &color.red,
-                                       &color.green,
-                                       &color.blue,
-                                       &color.alpha,
-                                       format_for_depth(pixmap->drawable.depth));
-               src = CreateSolidPicture(0, &color, &error);
-               if (!src) {
-                       FreePicture(dst, 0);
-                       goto err;
-               }
-
-               if (!uxa_screen->info->check_composite(PictOpSrc, src, NULL, dst,
-                                                      extents->x2 - extents->x1,
-                                                      extents->y2 - extents->y1)) {
-                       FreePicture(src, 0);
-                       FreePicture(dst, 0);
-                       goto try_solid;
-               }
-
-               if (!uxa_screen->info->check_composite_texture ||
-                   !uxa_screen->info->check_composite_texture(screen, src)) {
-                       PicturePtr solid;
-                       int src_off_x, src_off_y;
-
-                       solid = uxa_acquire_solid(screen, src->pSourcePict);
-                       FreePicture(src, 0);
-                       if (!solid) {
-                               FreePicture(dst, 0);
-                               goto err;
-                       }
-
-                       src = solid;
-                       src_pixmap = uxa_get_offscreen_pixmap(src->pDrawable,
-                                                             &src_off_x, &src_off_y);
-                       if (!src_pixmap) {
-                               FreePicture(src, 0);
-                               FreePicture(dst, 0);
-                               goto err;
-                       }
-               }
+       if (uxa_screen->info->check_solid &&
+           !uxa_screen->info->check_solid(&pixmap->drawable, alu, planemask))
+               goto err;
 
-               if (!uxa_screen->info->prepare_composite(PictOpSrc, src, NULL, dst, src_pixmap, NULL, pixmap)) {
-                       FreePicture(src, 0);
-                       FreePicture(dst, 0);
-                       goto err;
-               }
+       if (!uxa_screen->info->prepare_solid(pixmap, alu, planemask, pixel))
+               goto err;
 
-               while (nbox--) {
-                       uxa_screen->info->composite(pixmap,
-                                                   0, 0, 0, 0,
-                                                   pBox->x1,
-                                                   pBox->y1,
-                                                   pBox->x2 - pBox->x1,
-                                                   pBox->y2 - pBox->y1);
-                       pBox++;
-               }
-
-               uxa_screen->info->done_composite(pixmap);
-               FreePicture(src, 0);
-               FreePicture(dst, 0);
+       while (nbox--) {
+               uxa_screen->info->solid(pixmap,
+                                       pBox->x1, pBox->y1,
+                                       pBox->x2, pBox->y2);
+               pBox++;
        }
-
+       uxa_screen->info->done_solid(pixmap);
        ret = TRUE;
 
 err:
@@ -1272,7 +1245,21 @@ uxa_get_image(DrawablePtr pDrawable, int x, int y, int w, int h,
        Box.x2 = Box.x1 + w;
        Box.y2 = Box.y1 + h;
 
-       if (uxa_screen->swappedOut || uxa_screen->force_fallback)
+       if (uxa_screen->info->flags & UXA_USE_GLAMOR) {
+               ok = 0;
+               if (uxa_prepare_access(pDrawable, UXA_GLAMOR_ACCESS_RW)) {
+                       ok = glamor_get_image_nf(pDrawable, x, y, w, h,
+                                                format, planeMask, d);
+                       uxa_finish_access(pDrawable, UXA_GLAMOR_ACCESS_RW);
+               }
+
+               if (!ok)
+                       goto fallback;
+
+               return;
+       }
+
+       if (uxa_screen->force_fallback)
                goto fallback;
 
        pPix = uxa_get_offscreen_pixmap(pDrawable, &xoff, &yoff);
@@ -1302,7 +1289,7 @@ fallback:
 
        if (uxa_prepare_access(pDrawable, UXA_ACCESS_RO)) {
                fbGetImage(pDrawable, x, y, w, h, format, planeMask, d);
-               uxa_finish_access(pDrawable);
+               uxa_finish_access(pDrawable, UXA_ACCESS_RO);
        }
 
        return;
diff --git a/uxa/uxa-glamor.h b/uxa/uxa-glamor.h
new file mode 100644 (file)
index 0000000..5ff19e0
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Copyright © 2011 Intel 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.
+ *
+ * Authors:
+ *    Zhigang Gong <zhigang.gong@linux.intel.com>
+ *
+ */
+
+#ifndef UXA_GLAMOR_H
+#define UXA_GLAMOR_H
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifdef USE_GLAMOR
+#include "glamor.h"
+#else
+#define glamor_fill_spans_nf(...)      FALSE
+#define glamor_poly_fill_rect_nf(...)  FALSE
+#define glamor_put_image_nf(...)       FALSE
+#define glamor_copy_n_to_n_nf(...)     FALSE
+#define glamor_get_spans_nf(...)       FALSE
+#define glamor_set_spans_nf(...)       FALSE
+#define glamor_get_image_nf(...)       FALSE
+#define glamor_glyphs_nf(...)          FALSE
+#define glamor_glyph_unrealize(...)    do { } while(0)
+#define glamor_composite_nf(...)       FALSE
+#define glamor_composite_rects_nf(...) FALSE
+#define glamor_trapezoids_nf(...)      FALSE
+#define glamor_triangles_nf(...)       FALSE
+#define glamor_add_traps_nf(...)       FALSE
+#define glamor_create_gc(...)          FALSE
+#define glamor_validate_gc(...)                do { } while(0)
+#define glamor_poly_point_nf(...)      FALSE
+#define glamor_poly_segment_nf(...)    FALSE
+#define glamor_poly_lines_nf(...)      FALSE
+#define glamor_push_pixels_nf(...)     FALSE
+#define glamor_copy_plane_nf(...)      FALSE
+#define glamor_image_glyph_blt_nf(...) FALSE
+#define glamor_poly_glyph_blt_nf(...)  FALSE
+#endif
+
+#endif /* UXA_GLAMOR_H */
index 0f5ddda..527942a 100644 (file)
@@ -65,6 +65,7 @@
 #include <stdlib.h>
 
 #include "uxa-priv.h"
+#include "uxa-glamor.h"
 #include "../src/common.h"
 
 #include "mipict.h"
@@ -111,6 +112,9 @@ static void uxa_unrealize_glyph_caches(ScreenPtr pScreen)
        uxa_screen_t *uxa_screen = uxa_get_screen(pScreen);
        int i;
 
+       if (uxa_screen->info->flags & UXA_USE_GLAMOR)
+               return;
+
        if (!uxa_screen->glyph_cache_initialized)
                return;
 
@@ -210,6 +214,11 @@ bail:
 
 Bool uxa_glyphs_init(ScreenPtr pScreen)
 {
+
+       uxa_screen_t *uxa_screen = uxa_get_screen(pScreen);
+
+       if (uxa_screen->info->flags & UXA_USE_GLAMOR)
+               return TRUE;
 #if HAS_DIXREGISTERPRIVATEKEY
        if (!dixRegisterPrivateKey(&uxa_glyph_key, PRIVATE_GLYPH, 0))
                return FALSE;
@@ -234,7 +243,7 @@ uxa_glyph_cache_upload_glyph(ScreenPtr screen,
                             GlyphPtr glyph,
                             int x, int y)
 {
-       PicturePtr pGlyphPicture = GlyphPicture(glyph)[screen->myNum];
+       PicturePtr pGlyphPicture = GetGlyphPicture(glyph, screen);
        PixmapPtr pGlyphPixmap = (PixmapPtr) pGlyphPicture->pDrawable;
        PixmapPtr pCachePixmap = (PixmapPtr) cache->picture->pDrawable;
        PixmapPtr scratch;
@@ -304,6 +313,12 @@ uxa_glyph_unrealize(ScreenPtr screen,
                    GlyphPtr glyph)
 {
        struct uxa_glyph *priv;
+       uxa_screen_t *uxa_screen = uxa_get_screen(screen);
+
+       if (uxa_screen->info->flags & UXA_USE_GLAMOR) {
+               glamor_glyph_unrealize(screen, glyph);
+               return;
+       }
 
        /* Use Lookup in case we have not attached to this glyph. */
        priv = dixLookupPrivate(&glyph->devPrivates, &uxa_glyph_key);
@@ -444,18 +459,19 @@ uxa_check_glyphs(CARD8 op,
                 INT16 xSrc,
                 INT16 ySrc, int nlist, GlyphListPtr list, GlyphPtr * glyphs)
 {
-       int screen = dst->pDrawable->pScreen->myNum;
        pixman_image_t *image;
        PixmapPtr scratch;
-       PicturePtr mask;
+       PicturePtr mask, mask_src = NULL, mask_dst = NULL, white = NULL;
        int width = 0, height = 0;
        int x, y, n;
        int xDst = list->xOff, yDst = list->yOff;
        BoxRec extents = { 0, 0, 0, 0 };
+       CARD8 mask_op = 0;
 
        if (maskFormat) {
                pixman_format_code_t format;
                CARD32 component_alpha;
+               xRenderColor color;
                int error;
 
                uxa_glyph_extents(nlist, list, glyphs, &extents);
@@ -496,6 +512,18 @@ uxa_check_glyphs(CARD8 op,
 
                x = -extents.x1;
                y = -extents.y1;
+
+               color.red = color.green = color.blue = color.alpha = 0xffff;
+               white = CreateSolidPicture(0, &color, &error);
+
+               mask_op = op;
+               op = PictOpAdd;
+
+               mask_src = src;
+               src = white;
+
+               mask_dst = dst;
+               dst = mask;
        } else {
                mask = dst;
                x = 0;
@@ -508,26 +536,16 @@ uxa_check_glyphs(CARD8 op,
                n = list->len;
                while (n--) {
                        GlyphPtr glyph = *glyphs++;
-                       PicturePtr g = GlyphPicture(glyph)[screen];
+                       PicturePtr g = GetGlyphPicture(glyph, dst->pDrawable->pScreen);
                        if (g) {
-                               if (maskFormat) {
-                                       CompositePicture(PictOpAdd, g, NULL, mask,
-                                                        0, 0,
-                                                        0, 0,
-                                                        x - glyph->info.x,
-                                                        y - glyph->info.y,
-                                                        glyph->info.width,
-                                                        glyph->info.height);
-                               } else {
-                                       CompositePicture(op, src, g, dst,
-                                                        xSrc + (x - glyph->info.x) - xDst,
-                                                        ySrc + (y - glyph->info.y) - yDst,
-                                                        0, 0,
-                                                        x - glyph->info.x,
-                                                        y - glyph->info.y,
-                                                        glyph->info.width,
-                                                        glyph->info.height);
-                               }
+                               CompositePicture(op, src, g, dst,
+                                                xSrc + (x - glyph->info.x) - xDst,
+                                                ySrc + (y - glyph->info.y) - yDst,
+                                                0, 0,
+                                                x - glyph->info.x,
+                                                y - glyph->info.y,
+                                                glyph->info.width,
+                                                glyph->info.height);
                        }
 
                        x += glyph->info.xOff;
@@ -536,10 +554,13 @@ uxa_check_glyphs(CARD8 op,
                list++;
        }
 
+       if (white)
+               FreePicture(white, 0);
+
        if (maskFormat) {
                x = extents.x1;
                y = extents.y1;
-               CompositePicture(op, src, mask, dst,
+               CompositePicture(mask_op, mask_src, mask, mask_dst,
                                 xSrc + x - xDst,
                                 ySrc + y - yDst,
                                 0, 0,
@@ -574,7 +595,7 @@ static PicturePtr
 uxa_glyph_cache(ScreenPtr screen, GlyphPtr glyph, int *out_x, int *out_y)
 {
        uxa_screen_t *uxa_screen = uxa_get_screen(screen);
-       PicturePtr glyph_picture = GlyphPicture(glyph)[screen->myNum];
+       PicturePtr glyph_picture = GetGlyphPicture(glyph, screen);
        uxa_glyph_cache_t *cache = &uxa_screen->glyphCaches[PICT_FORMAT_RGB(glyph_picture->format) != 0];
        struct uxa_glyph *priv = NULL;
        int size, mask, pos, s;
@@ -658,190 +679,6 @@ uxa_glyph_cache(ScreenPtr screen, GlyphPtr glyph, int *out_x, int *out_y)
        return cache->picture;
 }
 
-static int
-uxa_glyphs_to_dst(CARD8 op,
-                 PicturePtr pSrc,
-                 PicturePtr pDst,
-                 INT16 src_x, INT16 src_y,
-                 INT16 xDst, INT16 yDst,
-                 int nlist, GlyphListPtr list, GlyphPtr * glyphs,
-                 BoxPtr extents)
-{
-       ScreenPtr screen = pDst->pDrawable->pScreen;
-       uxa_screen_t *uxa_screen = uxa_get_screen(screen);
-       PixmapPtr src_pixmap, dst_pixmap;
-       PicturePtr localSrc, glyph_atlas;
-       int x, y, n;
-       BoxRec box;
-
-       if (uxa_screen->info->check_composite_texture &&
-           uxa_screen->info->check_composite_texture(screen, pSrc)) {
-               if (pSrc->pDrawable) {
-                       int src_off_x, src_off_y;
-
-                       src_pixmap = uxa_get_offscreen_pixmap(pSrc->pDrawable, &src_off_x, &src_off_y);
-                       if (src_pixmap == NULL)
-                               return -1;
-
-                       src_x += pSrc->pDrawable->x + src_off_x;
-                       src_y += pSrc->pDrawable->y + src_off_y;
-               } else {
-                       src_pixmap = NULL;
-               }
-               localSrc = pSrc;
-       } else {
-               int width, height;
-
-               if (extents == NULL) {
-                       uxa_glyph_extents(nlist, list, glyphs, &box);
-                       extents = &box;
-               }
-
-               width  = extents->x2 - extents->x1;
-               height = extents->y2 - extents->y1;
-               if (width == 0 || height == 0)
-                       return 0;
-
-               if (pSrc->pDrawable) {
-                       int src_off_x, src_off_y;
-
-                       src_off_x = extents->x1 - xDst;
-                       src_off_y = extents->y1 - yDst;
-                       localSrc = uxa_acquire_drawable(screen, pSrc,
-                                                       src_x + src_off_x, src_y + src_off_y,
-                                                       width, height,
-                                                       &src_x, &src_y);
-                       if (uxa_screen->info->check_composite_texture &&
-                           !uxa_screen->info->check_composite_texture(screen, localSrc)) {
-                               if (localSrc != pSrc)
-                                       FreePicture(localSrc, 0);
-                               return -1;
-                       }
-
-                       src_pixmap = uxa_get_offscreen_pixmap(localSrc->pDrawable, &src_off_x, &src_off_y);
-                       if (src_pixmap == NULL) {
-                               if (localSrc != pSrc)
-                                       FreePicture(localSrc, 0);
-                               return -1;
-                       }
-
-                       src_x += localSrc->pDrawable->x + src_off_x;
-                       src_y += localSrc->pDrawable->y + src_off_y;
-               } else {
-                       localSrc = uxa_acquire_pattern(screen, pSrc,
-                                                      PICT_a8r8g8b8, x, y, width, height);
-                       if (!localSrc)
-                               return 1;
-
-                       src_pixmap = uxa_get_drawable_pixmap(localSrc->pDrawable);
-                       if (src_pixmap == NULL) {
-                               FreePicture(localSrc, 0);
-                               return -1;
-                       }
-
-                       src_x = src_y = 0;
-               }
-       }
-
-       dst_pixmap = uxa_get_offscreen_pixmap(pDst->pDrawable, &x, &y);
-       x += xDst + pDst->pDrawable->x - list->xOff;
-       y += yDst + pDst->pDrawable->y - list->yOff;
-
-       glyph_atlas = NULL;
-       while (nlist--) {
-               x += list->xOff;
-               y += list->yOff;
-               n = list->len;
-               while (n--) {
-                       GlyphPtr glyph = *glyphs++;
-                       PicturePtr this_atlas;
-                       int mask_x, mask_y, nrect;
-                       struct uxa_glyph *priv;
-                       BoxPtr rects;
-
-                       if (glyph->info.width == 0 || glyph->info.height == 0)
-                               goto next_glyph;
-
-                       priv = uxa_glyph_get_private(glyph);
-                       if (priv != NULL) {
-                               mask_x = priv->x;
-                               mask_y = priv->y;
-                               this_atlas = priv->cache->picture;
-                       } else {
-                               if (glyph_atlas) {
-                                       uxa_screen->info->done_composite(dst_pixmap);
-                                       glyph_atlas = NULL;
-                               }
-                               this_atlas = uxa_glyph_cache(screen, glyph, &mask_x, &mask_y);
-                               if (this_atlas == NULL) {
-                                       /* no cache for this glyph */
-                                       this_atlas = GlyphPicture(glyph)[screen->myNum];
-                                       mask_x = mask_y = 0;
-                               }
-                       }
-
-                       if (this_atlas != glyph_atlas) {
-                               PixmapPtr mask_pixmap;
-
-                               if (glyph_atlas)
-                                       uxa_screen->info->done_composite(dst_pixmap);
-
-                               mask_pixmap =
-                                       uxa_get_drawable_pixmap(this_atlas->pDrawable);
-                               if (!uxa_pixmap_is_offscreen(mask_pixmap) ||
-                                   !uxa_screen->info->prepare_composite(op,
-                                                                        localSrc, this_atlas, pDst,
-                                                                        src_pixmap, mask_pixmap, dst_pixmap))
-                                       return -1;
-
-                               glyph_atlas = this_atlas;
-                       }
-
-                       rects = REGION_RECTS(pDst->pCompositeClip);
-                       nrect = REGION_NUM_RECTS(pDst->pCompositeClip);
-                       while (nrect--) {
-                               int x1 = x - glyph->info.x, dx = 0;
-                               int y1 = y - glyph->info.y, dy = 0;
-                               int x2 = x1 + glyph->info.width;
-                               int y2 = y1 + glyph->info.height;
-
-                               if (rects->y1 >= y2)
-                                       break;
-
-                               if (x1 < rects->x1)
-                                       dx = rects->x1 - x1, x1 = rects->x1;
-                               if (x2 > rects->x2)
-                                       x2 = rects->x2;
-                               if (y1 < rects->y1)
-                                       dy = rects->y1 - y1, y1 = rects->y1;
-                               if (y2 > rects->y2)
-                                       y2 = rects->y2;
-
-                               if (x1 < x2 && y1 < y2) {
-                                       uxa_screen->info->composite(dst_pixmap,
-                                                                   x1 + src_x,  y1 + src_y,
-                                                                   dx + mask_x, dy + mask_y,
-                                                                   x1, y1,
-                                                                   x2 - x1, y2 - y1);
-                               }
-                               rects++;
-                       }
-
-next_glyph:
-                       x += glyph->info.xOff;
-                       y += glyph->info.yOff;
-               }
-               list++;
-       }
-       if (glyph_atlas)
-               uxa_screen->info->done_composite(dst_pixmap);
-
-       if (localSrc != pSrc)
-               FreePicture(localSrc, 0);
-
-       return 0;
-}
-
 static void
 uxa_clear_pixmap(ScreenPtr screen,
                 uxa_screen_t *uxa_screen,
@@ -883,43 +720,53 @@ fallback:
        }
 }
 
+static PicturePtr
+create_white_solid(ScreenPtr screen)
+{
+       PicturePtr white, ret = NULL;
+       xRenderColor color;
+       int error;
+
+       color.red = color.green = color.blue = color.alpha = 0xffff;
+       white = CreateSolidPicture(0, &color, &error);
+       if (white) {
+               ret = uxa_acquire_solid(screen, white->pSourcePict);
+               FreePicture(white, 0);
+       }
+
+       return ret;
+}
+
 static int
 uxa_glyphs_via_mask(CARD8 op,
                    PicturePtr pSrc,
                    PicturePtr pDst,
                    PictFormatPtr maskFormat,
                    INT16 xSrc, INT16 ySrc,
-                   INT16 xDst, INT16 yDst,
-                   int nlist, GlyphListPtr list, GlyphPtr * glyphs,
-                   BoxPtr extents)
+                   int nlist, GlyphListPtr list, GlyphPtr * glyphs)
 {
        ScreenPtr screen = pDst->pDrawable->pScreen;
        uxa_screen_t *uxa_screen = uxa_get_screen(screen);
        CARD32 component_alpha;
-       PixmapPtr pixmap;
-       PicturePtr glyph_atlas, mask;
+       PixmapPtr pixmap, white_pixmap;
+       PicturePtr glyph_atlas, mask, white;
+       int xDst = list->xOff, yDst = list->yOff;
        int x, y, width, height;
        int dst_off_x, dst_off_y;
        int n, error;
        BoxRec box;
 
-       if (!extents) {
-               uxa_glyph_extents(nlist, list, glyphs, &box);
+       uxa_glyph_extents(nlist, list, glyphs, &box);
+       if (box.x2 <= box.x1 || box.y2 <= box.y1)
+               return 0;
 
-               if (box.x2 <= box.x1 || box.y2 <= box.y1)
-                       return 0;
+       dst_off_x = box.x1;
+       dst_off_y = box.y1;
 
-               extents = &box;
-               dst_off_x = box.x1;
-               dst_off_y = box.y1;
-       } else {
-               dst_off_x = dst_off_y = 0;
-       }
-
-       width  = extents->x2 - extents->x1;
-       height = extents->y2 - extents->y1;
-       x = -extents->x1;
-       y = -extents->y1;
+       width  = box.x2 - box.x1;
+       height = box.y2 - box.y1;
+       x = -box.x1;
+       y = -box.y1;
 
        if (maskFormat->depth == 1) {
                PictFormatPtr a8Format =
@@ -937,6 +784,22 @@ uxa_glyphs_via_mask(CARD8 op,
        if (!pixmap)
                return 1;
 
+       if (!uxa_pixmap_is_offscreen(pixmap)) {
+               screen->DestroyPixmap(pixmap);
+               return -1;
+       }
+
+       white_pixmap = NULL;
+       white = create_white_solid(screen);
+       if (white)
+               white_pixmap = uxa_get_drawable_pixmap(white->pDrawable);
+       if (!white_pixmap) {
+               if (white)
+                       FreePicture(white, 0);
+               screen->DestroyPixmap(pixmap);
+               return -1;
+       }
+
        uxa_clear_pixmap(screen, uxa_screen, pixmap);
 
        component_alpha = NeedsComponent(maskFormat->format);
@@ -945,8 +808,10 @@ uxa_glyphs_via_mask(CARD8 op,
                              &component_alpha, serverClient, &error);
        screen->DestroyPixmap(pixmap);
 
-       if (!mask)
+       if (!mask) {
+               FreePicture(white, 0);
                return 1;
+       }
 
        ValidatePicture(mask);
 
@@ -958,7 +823,7 @@ uxa_glyphs_via_mask(CARD8 op,
                while (n--) {
                        GlyphPtr glyph = *glyphs++;
                        PicturePtr this_atlas;
-                       int src_x, src_y;
+                       int glyph_x, glyph_y;
                        struct uxa_glyph *priv;
 
                        if (glyph->info.width == 0 || glyph->info.height == 0)
@@ -966,42 +831,45 @@ uxa_glyphs_via_mask(CARD8 op,
 
                        priv = uxa_glyph_get_private(glyph);
                        if (priv != NULL) {
-                               src_x = priv->x;
-                               src_y = priv->y;
+                               glyph_x = priv->x;
+                               glyph_y = priv->y;
                                this_atlas = priv->cache->picture;
                        } else {
                                if (glyph_atlas) {
                                        uxa_screen->info->done_composite(pixmap);
                                        glyph_atlas = NULL;
                                }
-                               this_atlas = uxa_glyph_cache(screen, glyph, &src_x, &src_y);
+                               this_atlas = uxa_glyph_cache(screen, glyph, &glyph_x, &glyph_y);
                                if (this_atlas == NULL) {
                                        /* no cache for this glyph */
-                                       this_atlas = GlyphPicture(glyph)[screen->myNum];
-                                       src_x = src_y = 0;
+                                       this_atlas = GetGlyphPicture(glyph, screen);
+                                       glyph_x = glyph_y = 0;
                                }
                        }
 
                        if (this_atlas != glyph_atlas) {
-                               PixmapPtr src_pixmap;
+                               PixmapPtr glyph_pixmap;
 
                                if (glyph_atlas)
                                        uxa_screen->info->done_composite(pixmap);
 
-                               src_pixmap =
+                               glyph_pixmap =
                                        uxa_get_drawable_pixmap(this_atlas->pDrawable);
-                               if (!uxa_pixmap_is_offscreen(src_pixmap) ||
+                               if (!uxa_pixmap_is_offscreen(glyph_pixmap) ||
                                    !uxa_screen->info->prepare_composite(PictOpAdd,
-                                                                        this_atlas, NULL, mask,
-                                                                        src_pixmap, NULL, pixmap))
+                                                                        white, this_atlas, mask,
+                                                                        white_pixmap, glyph_pixmap, pixmap)) {
+                                       FreePicture(white, 0);
+                                       FreePicture(mask, 0);
                                        return -1;
+                               }
 
                                glyph_atlas = this_atlas;
                        }
 
                        uxa_screen->info->composite(pixmap,
-                                                   src_x, src_y,
                                                    0, 0,
+                                                   glyph_x, glyph_y,
                                                    x - glyph->info.x,
                                                    y - glyph->info.y,
                                                    glyph->info.width,
@@ -1024,10 +892,83 @@ next_glyph:
                      dst_off_x, dst_off_y,
                      width, height);
 
+       FreePicture(white, 0);
        FreePicture(mask, 0);
        return 0;
 }
 
+static int
+uxa_glyphs_to_dst(CARD8 op,
+                 PicturePtr pSrc,
+                 PicturePtr pDst,
+                 INT16 xSrc, INT16 ySrc,
+                 int nlist, GlyphListPtr list, GlyphPtr * glyphs)
+{
+       ScreenPtr screen = pDst->pDrawable->pScreen;
+       int x, y, n;
+
+       xSrc -= list->xOff;
+       ySrc -= list->yOff;
+       x = y = 0;
+       while (nlist--) {
+               x += list->xOff;
+               y += list->yOff;
+               n = list->len;
+               while (n--) {
+                       GlyphPtr glyph = *glyphs++;
+                       PicturePtr glyph_atlas;
+                       int glyph_x, glyph_y;
+                       struct uxa_glyph *priv;
+
+                       if (glyph->info.width == 0 || glyph->info.height == 0)
+                               goto next_glyph;
+
+                       priv = uxa_glyph_get_private(glyph);
+                       if (priv != NULL) {
+                               glyph_x = priv->x;
+                               glyph_y = priv->y;
+                               glyph_atlas = priv->cache->picture;
+                       } else {
+                               glyph_atlas = uxa_glyph_cache(screen, glyph, &glyph_x, &glyph_y);
+                               if (glyph_atlas == NULL) {
+                                       /* no cache for this glyph */
+                                       glyph_atlas = GetGlyphPicture(glyph, screen);
+                                       glyph_x = glyph_y = 0;
+                               }
+                       }
+
+                       uxa_composite(op,
+                                     pSrc, glyph_atlas, pDst,
+                                     xSrc + x - glyph->info.x,
+                                     ySrc + y - glyph->info.y,
+                                     glyph_x, glyph_y,
+                                     x - glyph->info.x,
+                                     y - glyph->info.y,
+                                     glyph->info.width, glyph->info.height);
+
+next_glyph:
+                       x += glyph->info.xOff;
+                       y += glyph->info.yOff;
+               }
+               list++;
+       }
+
+       return 0;
+}
+
+static Bool
+is_solid(PicturePtr picture)
+{
+       if (picture->pSourcePict) {
+               SourcePict *source = picture->pSourcePict;
+               return source->type == SourcePictTypeSolidFill;
+       } else {
+               return (picture->repeat &&
+                       picture->pDrawable->width  == 1 &&
+                       picture->pDrawable->height == 1);
+       }
+}
+
 void
 uxa_glyphs(CARD8 op,
           PicturePtr pSrc,
@@ -1038,17 +979,30 @@ uxa_glyphs(CARD8 op,
 {
        ScreenPtr screen = pDst->pDrawable->pScreen;
        uxa_screen_t *uxa_screen = uxa_get_screen(screen);
-       int xDst = list->xOff, yDst = list->yOff;
-       BoxRec extents = { 0, 0, 0, 0 };
-       Bool have_extents = FALSE;
-       int width, height, ret;
-       PicturePtr localDst = pDst;
+
+       if (uxa_screen->info->flags & UXA_USE_GLAMOR) {
+               int ok;
+
+               uxa_picture_prepare_access(pDst, UXA_GLAMOR_ACCESS_RW);
+               uxa_picture_prepare_access(pSrc, UXA_GLAMOR_ACCESS_RO);
+               ok = glamor_glyphs_nf(op,
+                                    pSrc, pDst, maskFormat,
+                                    xSrc, ySrc, nlist, list, glyphs);
+               uxa_picture_finish_access(pSrc, UXA_GLAMOR_ACCESS_RO);
+               uxa_picture_finish_access(pDst, UXA_GLAMOR_ACCESS_RW);
+
+               if (!ok)
+                       goto fallback;
+
+               return;
+       }
 
        if (!uxa_screen->info->prepare_composite ||
-           uxa_screen->swappedOut ||
            uxa_screen->force_fallback ||
            !uxa_drawable_is_offscreen(pDst->pDrawable) ||
-           pDst->alphaMap || pSrc->alphaMap) {
+           pDst->alphaMap || pSrc->alphaMap ||
+           /* XXX we fail to handle (rare) non-solid sources correctly. */
+           !is_solid(pSrc)) {
 fallback:
            uxa_check_glyphs(op, pSrc, pDst, maskFormat, xSrc, ySrc, nlist, list, glyphs);
            return;
@@ -1087,107 +1041,16 @@ fallback:
                }
        }
 
-       if (!maskFormat &&
-           uxa_screen->info->check_composite_target &&
-           !uxa_screen->info->check_composite_target(uxa_get_drawable_pixmap(pDst->pDrawable))) {
-               int depth = pDst->pDrawable->depth;
-               PixmapPtr pixmap;
-               int x, y, error;
-               GCPtr gc;
-
-               pixmap = uxa_get_drawable_pixmap(pDst->pDrawable);
-               if (uxa_screen->info->check_copy &&
-                   !uxa_screen->info->check_copy(pixmap, pixmap, GXcopy, FB_ALLONES))
+       if (!maskFormat) {
+               if (uxa_glyphs_to_dst(op, pSrc, pDst,
+                                     xSrc, ySrc,
+                                     nlist, list, glyphs))
                        goto fallback;
-
-               uxa_glyph_extents(nlist, list, glyphs, &extents);
-
-               /* clip against dst bounds */
-               if (extents.x1 < 0)
-                       extents.x1 = 0;
-               if (extents.y1 < 0)
-                       extents.y1 = 0;
-               if (extents.x2 > pDst->pDrawable->width)
-                       extents.x2 = pDst->pDrawable->width;
-               if (extents.y2 > pDst->pDrawable->height)
-                       extents.y2 = pDst->pDrawable->height;
-
-               if (extents.x2 <= extents.x1 || extents.y2 <= extents.y1)
-                       return;
-               width  = extents.x2 - extents.x1;
-               height = extents.y2 - extents.y1;
-               x = -extents.x1;
-               y = -extents.y1;
-               have_extents = TRUE;
-
-               xDst += x;
-               yDst += y;
-
-               pixmap = screen->CreatePixmap(screen,
-                                             width, height, depth,
-                                             CREATE_PIXMAP_USAGE_SCRATCH);
-               if (!pixmap)
-                       return;
-
-               gc = GetScratchGC(depth, screen);
-               if (!gc) {
-                       screen->DestroyPixmap(pixmap);
-                       return;
-               }
-
-               ValidateGC(&pixmap->drawable, gc);
-               gc->ops->CopyArea(pDst->pDrawable, &pixmap->drawable, gc,
-                                 extents.x1, extents.y1,
-                                 width, height,
-                                 0, 0);
-               FreeScratchGC(gc);
-
-               localDst = CreatePicture(0, &pixmap->drawable,
-                                        PictureMatchFormat(screen, depth, pDst->format),
-                                        0, 0, serverClient, &error);
-               screen->DestroyPixmap(pixmap);
-
-               if (!localDst)
-                       return;
-
-               ValidatePicture(localDst);
-       }
-
-       if (maskFormat) {
-               ret = uxa_glyphs_via_mask(op,
-                                         pSrc, localDst, maskFormat,
-                                         xSrc, ySrc,
-                                         xDst, yDst,
-                                         nlist, list, glyphs,
-                                         have_extents ? &extents : NULL);
        } else {
-               ret = uxa_glyphs_to_dst(op,
-                                       pSrc, localDst,
+               if (uxa_glyphs_via_mask(op,
+                                       pSrc, pDst, maskFormat,
                                        xSrc, ySrc,
-                                       xDst, yDst,
-                                       nlist, list, glyphs,
-                                       have_extents ? &extents : NULL);
-       }
-       if (ret) {
-               if (localDst != pDst)
-                       FreePicture(localDst, 0);
-
-               goto fallback;
-       }
-
-       if (localDst != pDst) {
-               GCPtr gc;
-
-               gc = GetScratchGC(pDst->pDrawable->depth, screen);
-               if (gc) {
-                       ValidateGC(pDst->pDrawable, gc);
-                       gc->ops->CopyArea(localDst->pDrawable, pDst->pDrawable, gc,
-                                         0, 0,
-                                         width, height,
-                                         extents.x1, extents.y1);
-                       FreeScratchGC(gc);
-               }
-
-               FreePicture(localDst, 0);
+                                       nlist, list, glyphs))
+                       goto fallback;
        }
 }
index ac206af..3f639e7 100644 (file)
@@ -44,7 +44,6 @@
 #include "pixmapstr.h"
 #include "windowstr.h"
 #include "servermd.h"
-#include "mibstore.h"
 #include "colormapst.h"
 #include "gcstruct.h"
 #include "input.h"
@@ -59,6 +58,8 @@
 #endif
 #include "damage.h"
 
+#include "../src/compat-api.h"
+
 /* Provide substitutes for gcc's __FUNCTION__ on other compilers */
 #if !defined(__GNUC__) && !defined(__FUNCTION__)
 # if defined(__STDC__) && (__STDC_VERSION__>=199901L)  /* C99 */
@@ -123,20 +124,15 @@ typedef struct {
        BitmapToRegionProcPtr SavedBitmapToRegion;
 #ifdef RENDER
        CompositeProcPtr SavedComposite;
-       CompositeRectsProcPtr SavedCompositeRects;
        TrianglesProcPtr SavedTriangles;
        GlyphsProcPtr SavedGlyphs;
        TrapezoidsProcPtr SavedTrapezoids;
        AddTrapsProcPtr SavedAddTraps;
        UnrealizeGlyphProcPtr SavedUnrealizeGlyph;
 #endif
-       EnableDisableFBAccessProcPtr SavedEnableDisableFBAccess;
 
        Bool force_fallback;
        Bool fallback_debug;
-       Bool swappedOut;
-       unsigned disableFbCount;
-       unsigned offScreenCounter;
 
        uxa_glyph_cache_t glyphCaches[UXA_NUM_GLYPH_CACHE_FORMATS];
        Bool glyph_cache_initialized;
@@ -292,6 +288,14 @@ void
 uxa_get_image(DrawablePtr pDrawable, int x, int y, int w, int h,
              unsigned int format, unsigned long planeMask, char *d);
 
+void
+uxa_get_spans(DrawablePtr pDrawable, int wMax, DDXPointPtr ppt,
+             int *pwidth, int nspans, char *pdstStart);
+
+void
+uxa_add_traps(PicturePtr pPicture,
+             INT16 x_off, INT16 y_off, int ntrap, xTrap * traps);
+
 extern const GCOps uxa_ops;
 
 #ifdef RENDER
@@ -325,8 +329,10 @@ uxa_check_composite(CARD8 op,
 
 /* uxa.c */
 Bool uxa_prepare_access(DrawablePtr pDrawable, uxa_access_t access);
+void uxa_finish_access(DrawablePtr pDrawable, uxa_access_t access);
 
-void uxa_finish_access(DrawablePtr pDrawable);
+Bool uxa_picture_prepare_access(PicturePtr picture, int mode);
+void uxa_picture_finish_access(PicturePtr picture, int mode);
 
 void
 uxa_get_drawable_deltas(DrawablePtr pDrawable, PixmapPtr pPixmap,
index b26be80..4463dc2 100644 (file)
 #include <stdlib.h>
 
 #include "uxa-priv.h"
+#include "uxa-glamor.h"
 #include <xorgVersion.h>
 
 #ifdef RENDER
 #include "mipict.h"
 
+/* Note: when using glamor we can not fail through to the ordinary UXA
+ * code paths, as glamor keeps an internal texture which will become
+ * inconsistent with the original bo. (The texture is replaced whenever
+ * the format changes, e.g. switching between xRGB and ARGB, for which mesa
+ * will allocate its own bo.)
+ *
+ * Ergo it is unsafe to fall through to the original backend operations if
+ * glamor is enabled.
+ *
+ * XXX This has some serious implications for mixing Render, DRI, scanout...
+ */
+
 static void uxa_composite_fallback_pict_desc(PicturePtr pict, char *string,
                                             int n)
 {
@@ -183,10 +196,8 @@ uxa_print_composite_fallback(const char *func, CARD8 op,
               "  op   %s, \n"
               "  src  %s, \n"
               "  mask %s, \n"
-              "  dst  %s, \n"
-              "  screen %s\n",
-              func, op_to_string (op), srcdesc, maskdesc, dstdesc,
-              uxa_screen->swappedOut ? "swapped out" : "normal");
+              "  dst  %s, \n",
+              func, op_to_string (op), srcdesc, maskdesc, dstdesc);
 }
 
 Bool uxa_op_reads_destination(CARD8 op)
@@ -568,10 +579,10 @@ uxa_picture_from_pixman_image(ScreenPtr screen,
                }
                ValidatePicture(src);
 
-               if (uxa_prepare_access(picture->pDrawable, UXA_ACCESS_RW)) {
+               if (uxa_picture_prepare_access(picture, UXA_ACCESS_RW)) {
                        fbComposite(PictOpSrc, src, NULL, picture,
                                    0, 0, 0, 0, 0, 0, width, height);
-                       uxa_finish_access(picture->pDrawable);
+                       uxa_picture_finish_access(picture, UXA_ACCESS_RW);
                }
 
                FreePicture(src, 0);
@@ -599,7 +610,7 @@ uxa_create_solid(ScreenPtr screen, uint32_t color)
                return 0;
        }
        *((uint32_t *)pixmap->devPrivate.ptr) = color;
-       uxa_finish_access((DrawablePtr)pixmap);
+       uxa_finish_access((DrawablePtr)pixmap, UXA_ACCESS_RW);
 
        picture = CreatePicture(0, &pixmap->drawable,
                                PictureMatchFormat(screen, 32, PICT_a8r8g8b8),
@@ -699,10 +710,10 @@ uxa_acquire_pattern(ScreenPtr pScreen,
        if (!pDst)
                return 0;
 
-       if (uxa_prepare_access(pDst->pDrawable, UXA_ACCESS_RW)) {
+       if (uxa_picture_prepare_access(pDst, UXA_ACCESS_RW)) {
                fbComposite(PictOpSrc, pSrc, NULL, pDst,
                            x, y, 0, 0, 0, 0, width, height);
-               uxa_finish_access(pDst->pDrawable);
+               uxa_picture_finish_access(pDst, UXA_ACCESS_RW);
                return pDst;
        } else {
                FreePicture(pDst, 0);
@@ -756,14 +767,14 @@ uxa_render_picture(ScreenPtr screen,
        if (!picture)
                return 0;
 
-       if (uxa_prepare_access(picture->pDrawable, UXA_ACCESS_RW)) {
-               if (uxa_prepare_access(src->pDrawable, UXA_ACCESS_RO)) {
+       if (uxa_picture_prepare_access(picture, UXA_ACCESS_RW)) {
+               if (uxa_picture_prepare_access(src, UXA_ACCESS_RO)) {
                        ret = 1;
                        fbComposite(PictOpSrc, src, NULL, picture,
                                    x, y, 0, 0, 0, 0, width, height);
-                       uxa_finish_access(src->pDrawable);
+                       uxa_picture_finish_access(src, UXA_ACCESS_RO);
                }
-               uxa_finish_access(picture->pDrawable);
+               uxa_picture_finish_access(picture, UXA_ACCESS_RW);
        }
 
        if (!ret) {
@@ -936,181 +947,6 @@ uxa_acquire_mask(ScreenPtr screen,
                                    out_x, out_y);
 }
 
-static Bool
-_pixman_region_init_rectangles(pixman_region16_t *region,
-                              int num_rects,
-                              xRectangle *rects,
-                              int tx, int ty)
-{
-       pixman_box16_t stack_boxes[64], *boxes = stack_boxes;
-       pixman_bool_t ret;
-       int i;
-
-       if (num_rects > sizeof(stack_boxes) / sizeof(stack_boxes[0])) {
-               boxes = malloc(sizeof(pixman_box16_t) * num_rects);
-               if (boxes == NULL)
-                       return FALSE;
-       }
-
-       for (i = 0; i < num_rects; i++) {
-               boxes[i].x1 = rects[i].x + tx;
-               boxes[i].y1 = rects[i].y + ty;
-               boxes[i].x2 = rects[i].x + tx + rects[i].width;
-               boxes[i].y2 = rects[i].y + ty + rects[i].height;
-       }
-
-       ret = pixman_region_init_rects(region, boxes, num_rects);
-
-       if (boxes != stack_boxes)
-               free(boxes);
-
-       return ret;
-}
-
-void
-uxa_solid_rects (CARD8         op,
-                PicturePtr     dst,
-                xRenderColor  *color,
-                int            num_rects,
-                xRectangle    *rects)
-{
-       ScreenPtr screen = dst->pDrawable->pScreen;
-       uxa_screen_t *uxa_screen = uxa_get_screen(screen);
-       PixmapPtr dst_pixmap, src_pixmap = NULL;
-       pixman_region16_t region;
-       pixman_box16_t *boxes, *extents;
-       PicturePtr src;
-       int dst_x, dst_y;
-       int num_boxes;
-
-       if (!pixman_region_not_empty(dst->pCompositeClip))
-               return;
-
-       if (dst->alphaMap)
-               goto fallback;
-
-       dst_pixmap = uxa_get_offscreen_pixmap(dst->pDrawable, &dst_x, &dst_y);
-       if (!dst_pixmap)
-               goto fallback;
-
-       if (!_pixman_region_init_rectangles(&region,
-                                           num_rects, rects,
-                                           dst->pDrawable->x, dst->pDrawable->y))
-               goto fallback;
-
-       if (!pixman_region_intersect(&region, &region, dst->pCompositeClip)) {
-               pixman_region_fini(&region);
-               return;
-       }
-
-       pixman_region_translate(&region, dst_x, dst_y);
-       boxes = pixman_region_rectangles(&region, &num_boxes);
-       extents = pixman_region_extents (&region);
-
-       if (op == PictOpClear)
-               color->red = color->green = color->blue = color->alpha = 0;
-       if (color->alpha >= 0xff00 && op == PictOpOver) {
-               color->alpha = 0xffff;
-               op = PictOpSrc;
-       }
-
-       /* Using GEM, the relocation costs outweigh the advantages of the blitter */
-       if (num_boxes == 1 && (op == PictOpSrc || op == PictOpClear)) {
-               CARD32 pixel;
-
-try_solid:
-               if (uxa_screen->info->check_solid &&
-                   !uxa_screen->info->check_solid(&dst_pixmap->drawable, GXcopy, FB_ALLONES))
-                       goto err_region;
-
-               if (!uxa_get_pixel_from_rgba(&pixel,
-                                            color->red,
-                                            color->green,
-                                            color->blue,
-                                            color->alpha,
-                                            dst->format))
-                       goto err_region;
-
-               if (!uxa_screen->info->prepare_solid(dst_pixmap, GXcopy, FB_ALLONES, pixel))
-                       goto err_region;
-
-               while (num_boxes--) {
-                       uxa_screen->info->solid(dst_pixmap,
-                                               boxes->x1, boxes->y1,
-                                               boxes->x2, boxes->y2);
-                       boxes++;
-               }
-
-               uxa_screen->info->done_solid(dst_pixmap);
-       } else {
-               int error;
-
-               src = CreateSolidPicture(0, color, &error);
-               if (!src)
-                       goto err_region;
-
-               if (!uxa_screen->info->check_composite(op, src, NULL, dst,
-                                                      extents->x2 - extents->x1,
-                                                      extents->y2 - extents->y1)) {
-                       if (op == PictOpSrc || op == PictOpClear) {
-                               FreePicture(src, 0);
-                               goto try_solid;
-                       }
-
-                       goto err_src;
-               }
-
-               if (!uxa_screen->info->check_composite_texture ||
-                   !uxa_screen->info->check_composite_texture(screen, src)) {
-                       PicturePtr solid;
-                       int src_off_x, src_off_y;
-
-                       solid = uxa_acquire_solid(screen, src->pSourcePict);
-                       if (!solid)
-                               goto err_src;
-                       FreePicture(src, 0);
-
-                       src = solid;
-                       src_pixmap = uxa_get_offscreen_pixmap(src->pDrawable,
-                                                             &src_off_x, &src_off_y);
-                       if (!src_pixmap)
-                               goto err_src;
-               }
-
-               if (!uxa_screen->info->prepare_composite(op, src, NULL, dst, src_pixmap, NULL, dst_pixmap))
-                       goto err_src;
-
-               while (num_boxes--) {
-                       uxa_screen->info->composite(dst_pixmap,
-                                                   0, 0, 0, 0,
-                                                   boxes->x1,
-                                                   boxes->y1,
-                                                   boxes->x2 - boxes->x1,
-                                                   boxes->y2 - boxes->y1);
-                       boxes++;
-               }
-
-               uxa_screen->info->done_composite(dst_pixmap);
-               FreePicture(src, 0);
-       }
-
-       /* XXX xserver-1.8: CompositeRects is not tracked by Damage, so we must
-        * manually append the damaged regions ourselves.
-        */
-       pixman_region_translate(&region, -dst_x, -dst_y);
-       DamageRegionAppend(dst->pDrawable, &region);
-
-       pixman_region_fini(&region);
-       return;
-
-err_src:
-       FreePicture(src, 0);
-err_region:
-       pixman_region_fini(&region);
-fallback:
-       uxa_screen->SavedCompositeRects(op, dst, color, num_rects, rects);
-}
-
 static int
 uxa_try_driver_composite(CARD8 op,
                         PicturePtr pSrc,
@@ -1228,10 +1064,25 @@ uxa_try_driver_composite(CARD8 op,
                return 1;
        }
 
-       if (localSrc->pDrawable) {
-               pSrcPix = uxa_get_offscreen_pixmap(localSrc->pDrawable,
-                                                  &src_off_x, &src_off_y);
-               if (!pSrcPix) {
+       pSrcPix = uxa_get_offscreen_pixmap(localSrc->pDrawable,
+                                          &src_off_x, &src_off_y);
+       if (!pSrcPix) {
+               REGION_UNINIT(screen, &region);
+
+               if (localSrc != pSrc)
+                       FreePicture(localSrc, 0);
+               if (localMask && localMask != pMask)
+                       FreePicture(localMask, 0);
+               if (localDst != pDst)
+                       FreePicture(localDst, 0);
+
+               return 0;
+       }
+
+       if (localMask) {
+               pMaskPix = uxa_get_offscreen_pixmap(localMask->pDrawable,
+                                                   &mask_off_x, &mask_off_y);
+               if (!pMaskPix) {
                        REGION_UNINIT(screen, &region);
 
                        if (localSrc != pSrc)
@@ -1243,29 +1094,6 @@ uxa_try_driver_composite(CARD8 op,
 
                        return 0;
                }
-       } else {
-               pSrcPix = NULL;
-       }
-
-       if (localMask) {
-               if (localMask->pDrawable) {
-                       pMaskPix = uxa_get_offscreen_pixmap(localMask->pDrawable,
-                                                           &mask_off_x, &mask_off_y);
-                       if (!pMaskPix) {
-                               REGION_UNINIT(screen, &region);
-
-                               if (localSrc != pSrc)
-                                       FreePicture(localSrc, 0);
-                               if (localMask && localMask != pMask)
-                                       FreePicture(localMask, 0);
-                               if (localDst != pDst)
-                                       FreePicture(localDst, 0);
-
-                               return 0;
-                       }
-               } else {
-                       pMaskPix = NULL;
-               }
        }
 
        if (!(*uxa_screen->info->prepare_composite)
@@ -1530,7 +1358,31 @@ uxa_composite(CARD8 op,
        RegionRec region;
        int tx, ty;
 
-       if (uxa_screen->swappedOut || uxa_screen->force_fallback)
+       if (uxa_screen->info->flags & UXA_USE_GLAMOR) {
+               int ok;
+
+               uxa_picture_prepare_access(pDst, UXA_GLAMOR_ACCESS_RW);
+               uxa_picture_prepare_access(pSrc, UXA_GLAMOR_ACCESS_RO);
+               if (pMask)
+                       uxa_picture_prepare_access(pMask, UXA_GLAMOR_ACCESS_RO);
+
+               ok = glamor_composite_nf(op,
+                                        pSrc, pMask, pDst, xSrc, ySrc,
+                                        xMask, yMask, xDst, yDst,
+                                        width, height);
+
+               if (pMask)
+                       uxa_picture_finish_access(pMask, UXA_GLAMOR_ACCESS_RO);
+               uxa_picture_finish_access(pSrc, UXA_GLAMOR_ACCESS_RO);
+               uxa_picture_finish_access(pDst, UXA_GLAMOR_ACCESS_RW);
+
+               if (!ok)
+                       goto fallback;
+
+               return;
+       }
+
+       if (uxa_screen->force_fallback)
                goto fallback;
 
        if (!uxa_drawable_is_offscreen(pDst->pDrawable))
@@ -1766,8 +1618,8 @@ uxa_create_alpha_picture(ScreenPtr pScreen,
 
 static void
 uxa_check_trapezoids(CARD8 op, PicturePtr src, PicturePtr dst,
-              PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc,
-              int ntrap, xTrapezoid * traps)
+                    PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc,
+                    int ntrap, xTrapezoid * traps)
 {
        ScreenPtr screen = dst->pDrawable->pScreen;
 
@@ -1871,7 +1723,25 @@ uxa_trapezoids(CARD8 op, PicturePtr src, PicturePtr dst,
        BoxRec bounds;
        Bool direct;
 
-       if (uxa_screen->swappedOut || uxa_screen->force_fallback) {
+       if (uxa_screen->info->flags & UXA_USE_GLAMOR) {
+               int ok;
+
+               uxa_picture_prepare_access(dst, UXA_GLAMOR_ACCESS_RW);
+               uxa_picture_prepare_access(src, UXA_GLAMOR_ACCESS_RO);
+               ok = glamor_trapezoids_nf(op,
+                                         src, dst, maskFormat, xSrc,
+                                         ySrc, ntrap, traps);
+               uxa_picture_finish_access(src, UXA_GLAMOR_ACCESS_RO);
+               uxa_picture_finish_access(dst, UXA_GLAMOR_ACCESS_RW);
+
+               if (!ok)
+                       goto fallback;
+
+               return;
+       }
+
+       if (uxa_screen->force_fallback) {
+fallback:
                uxa_check_trapezoids(op, src, dst, maskFormat, xSrc, ySrc, ntrap, traps);
                return;
        }
@@ -1902,7 +1772,7 @@ uxa_trapezoids(CARD8 op, PicturePtr src, PicturePtr dst,
 
                        for (; ntrap; ntrap--, traps++)
                                (*ps->RasterizeTrapezoid) (dst, traps, 0, 0);
-                       uxa_finish_access(pDraw);
+                       uxa_finish_access(pDraw, UXA_ACCESS_RW);
                }
        } else if (maskFormat) {
                PixmapPtr scratch = NULL;
@@ -1976,6 +1846,88 @@ uxa_trapezoids(CARD8 op, PicturePtr src, PicturePtr dst,
        }
 }
 
+static void
+uxa_check_triangles(CARD8 op, PicturePtr src, PicturePtr dst,
+                   PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc,
+                   int ntri, xTriangle *tri)
+{
+       ScreenPtr screen = dst->pDrawable->pScreen;
+
+       if (maskFormat) {
+               PixmapPtr scratch = NULL;
+               PicturePtr mask;
+               INT16 xDst, yDst;
+               INT16 xRel, yRel;
+               BoxRec bounds;
+               int width, height;
+               pixman_image_t *image;
+               pixman_format_code_t format;
+               int error;
+
+               xDst = pixman_fixed_to_int(tri[0].p1.x);
+               yDst = pixman_fixed_to_int(tri[0].p1.y);
+
+               miTriangleBounds (ntri, tri, &bounds);
+               if (bounds.y1 >= bounds.y2 || bounds.x1 >= bounds.x2)
+                       return;
+
+               width  = bounds.x2 - bounds.x1;
+               height = bounds.y2 - bounds.y1;
+
+               format = maskFormat->format |
+                       (BitsPerPixel(maskFormat->depth) << 24);
+               image =
+                   pixman_image_create_bits(format, width, height, NULL, 0);
+               if (!image)
+                       return;
+
+               pixman_add_triangles(image,
+                                    -bounds.x1, -bounds.y1,
+                                    ntri, (pixman_triangle_t *)tri);
+
+               scratch = GetScratchPixmapHeader(screen, width, height,
+                                                PIXMAN_FORMAT_DEPTH(format),
+                                                PIXMAN_FORMAT_BPP(format),
+                                                pixman_image_get_stride(image),
+                                                pixman_image_get_data(image));
+               if (!scratch) {
+                       pixman_image_unref(image);
+                       return;
+               }
+
+               mask = CreatePicture(0, &scratch->drawable,
+                                    PictureMatchFormat(screen,
+                                                       PIXMAN_FORMAT_DEPTH(format),
+                                                       format),
+                                    0, 0, serverClient, &error);
+               if (!mask) {
+                       FreeScratchPixmapHeader(scratch);
+                       pixman_image_unref(image);
+                       return;
+               }
+
+               xRel = bounds.x1 + xSrc - xDst;
+               yRel = bounds.y1 + ySrc - yDst;
+               CompositePicture(op, src, mask, dst,
+                                xRel, yRel,
+                                0, 0,
+                                bounds.x1, bounds.y1,
+                                width, height);
+               FreePicture(mask, 0);
+
+               FreeScratchPixmapHeader(scratch);
+               pixman_image_unref(image);
+       } else {
+               if (dst->polyEdge == PolyEdgeSharp)
+                       maskFormat = PictureMatchFormat(screen, 1, PICT_a1);
+               else
+                       maskFormat = PictureMatchFormat(screen, 8, PICT_a8);
+
+               for (; ntri; ntri--, tri++)
+                       uxa_check_triangles(op, src, dst, maskFormat, xSrc, ySrc, 1, tri);
+       }
+}
+
 /**
  * uxa_triangles is essentially a copy of miTriangles that uses
  * uxa_create_alpha_picture instead of miCreateAlphaPicture.
@@ -1995,10 +1947,36 @@ uxa_triangles(CARD8 op, PicturePtr pSrc, PicturePtr pDst,
              int ntri, xTriangle * tris)
 {
        ScreenPtr pScreen = pDst->pDrawable->pScreen;
+       uxa_screen_t *uxa_screen = uxa_get_screen(pScreen);
        PictureScreenPtr ps = GetPictureScreen(pScreen);
        BoxRec bounds;
-       Bool direct = op == PictOpAdd && miIsSolidAlpha(pSrc);
+       Bool direct;
+
+       if (uxa_screen->info->flags & UXA_USE_GLAMOR) {
+               int ok;
+
+               uxa_picture_prepare_access(pDst, UXA_GLAMOR_ACCESS_RW);
+               uxa_picture_prepare_access(pSrc, UXA_GLAMOR_ACCESS_RO);
+               ok = glamor_triangles_nf(op,
+                                       pSrc, pDst, maskFormat, xSrc,
+                                       ySrc, ntri, tris);
+               uxa_picture_finish_access(pSrc, UXA_GLAMOR_ACCESS_RO);
+               uxa_picture_finish_access(pDst, UXA_GLAMOR_ACCESS_RW);
+
+               if (!ok)
+                       goto fallback;
+
+               return;
+       }
+
+       if (uxa_screen->force_fallback) {
+fallback:
+               uxa_check_triangles(op, pSrc, pDst, maskFormat,
+                                   xSrc, ySrc, ntri, tris);
+               return;
+       }
 
+       direct = op == PictOpAdd && miIsSolidAlpha(pSrc);
        if (maskFormat || direct) {
                miTriangleBounds(ntri, tris, &bounds);
 
@@ -2013,7 +1991,7 @@ uxa_triangles(CARD8 op, PicturePtr pSrc, PicturePtr pDst,
                DrawablePtr pDraw = pDst->pDrawable;
                if (uxa_prepare_access(pDraw, UXA_ACCESS_RW)) {
                        (*ps->AddTriangles) (pDst, 0, 0, ntri, tris);
-                       uxa_finish_access(pDraw);
+                       uxa_finish_access(pDraw, UXA_ACCESS_RW);
                }
        } else if (maskFormat) {
                PicturePtr pPicture;
@@ -2049,7 +2027,7 @@ uxa_triangles(CARD8 op, PicturePtr pSrc, PicturePtr pDst,
                if (uxa_prepare_access(pPicture->pDrawable, UXA_ACCESS_RW)) {
                        (*ps->AddTriangles) (pPicture, -bounds.x1, -bounds.y1,
                                             ntri, tris);
-                       uxa_finish_access(pPicture->pDrawable);
+                       uxa_finish_access(pPicture->pDrawable, UXA_ACCESS_RW);
                }
 
                xRel = bounds.x1 + xSrc - xDst;
@@ -2069,3 +2047,28 @@ uxa_triangles(CARD8 op, PicturePtr pSrc, PicturePtr pDst,
                                      tris);
        }
 }
+
+void
+uxa_add_traps(PicturePtr pPicture,
+             INT16 x_off, INT16 y_off, int ntrap, xTrap * traps)
+{
+       ScreenPtr pScreen = pPicture->pDrawable->pScreen;
+       uxa_screen_t *uxa_screen = uxa_get_screen(pScreen);
+
+       if (uxa_screen->info->flags & UXA_USE_GLAMOR) {
+               int ok;
+
+               uxa_picture_prepare_access(pPicture, UXA_GLAMOR_ACCESS_RW);
+               ok = glamor_add_traps_nf(pPicture,
+                                        x_off, y_off, ntrap, traps);
+               uxa_picture_finish_access(pPicture, UXA_GLAMOR_ACCESS_RW);
+
+               if (!ok)
+                       goto fallback;
+
+               return;
+       }
+
+fallback:
+       uxa_check_add_traps(pPicture, x_off, y_off, ntrap, traps);
+}
index 15be821..f431049 100644 (file)
@@ -50,7 +50,7 @@ Bool uxa_prepare_access_gc(GCPtr pGC)
                if (!uxa_prepare_access
                    (&pGC->tile.pixmap->drawable, UXA_ACCESS_RO)) {
                        if (pGC->stipple)
-                               uxa_finish_access(&pGC->stipple->drawable);
+                               uxa_finish_access(&pGC->stipple->drawable, UXA_ACCESS_RO);
                        return FALSE;
                }
        return TRUE;
@@ -62,11 +62,39 @@ Bool uxa_prepare_access_gc(GCPtr pGC)
 void uxa_finish_access_gc(GCPtr pGC)
 {
        if (pGC->fillStyle == FillTiled)
-               uxa_finish_access(&pGC->tile.pixmap->drawable);
+               uxa_finish_access(&pGC->tile.pixmap->drawable, UXA_ACCESS_RO);
        if (pGC->stipple)
-               uxa_finish_access(&pGC->stipple->drawable);
+               uxa_finish_access(&pGC->stipple->drawable, UXA_ACCESS_RO);
 }
 
+Bool uxa_picture_prepare_access(PicturePtr picture, int mode)
+{
+       if (picture->pDrawable == NULL)
+               return TRUE;
+
+       if (!uxa_prepare_access(picture->pDrawable, mode))
+               return FALSE;
+
+       if (picture->alphaMap &&
+           !uxa_prepare_access(picture->alphaMap->pDrawable, mode)) {
+               uxa_finish_access(picture->pDrawable, mode);
+               return FALSE;
+       }
+
+       return TRUE;
+}
+
+void uxa_picture_finish_access(PicturePtr picture, int mode)
+{
+       if (picture->pDrawable == NULL)
+               return;
+
+       uxa_finish_access(picture->pDrawable, mode);
+       if (picture->alphaMap)
+               uxa_finish_access(picture->alphaMap->pDrawable, mode);
+}
+
+
 char uxa_drawable_location(DrawablePtr pDrawable)
 {
        return uxa_drawable_is_offscreen(pDrawable) ? 's' : 'm';
@@ -86,7 +114,7 @@ uxa_check_fill_spans(DrawablePtr pDrawable, GCPtr pGC, int nspans,
                                    fSorted);
                        uxa_finish_access_gc(pGC);
                }
-               uxa_finish_access(pDrawable);
+               uxa_finish_access(pDrawable, UXA_ACCESS_RW);
        }
 }
 
@@ -100,7 +128,7 @@ uxa_check_set_spans(DrawablePtr pDrawable, GCPtr pGC, char *psrc,
                      uxa_drawable_location(pDrawable)));
        if (uxa_prepare_access(pDrawable, UXA_ACCESS_RW)) {
                fbSetSpans(pDrawable, pGC, psrc, ppt, pwidth, nspans, fSorted);
-               uxa_finish_access(pDrawable);
+               uxa_finish_access(pDrawable, UXA_ACCESS_RW);
        }
 }
 
@@ -116,7 +144,7 @@ uxa_check_put_image(DrawablePtr pDrawable, GCPtr pGC, int depth,
        if (uxa_prepare_access(pDrawable, UXA_ACCESS_RW)) {
                fbPutImage(pDrawable, pGC, depth, x, y, w, h, leftPad, format,
                           bits);
-               uxa_finish_access(pDrawable);
+               uxa_finish_access(pDrawable, UXA_ACCESS_RW);
        }
 }
 
@@ -135,9 +163,9 @@ uxa_check_copy_area(DrawablePtr pSrc, DrawablePtr pDst, GCPtr pGC,
                        ret =
                            fbCopyArea(pSrc, pDst, pGC, srcx, srcy, w, h, dstx,
                                       dsty);
-                       uxa_finish_access(pSrc);
+                       uxa_finish_access(pSrc, UXA_ACCESS_RO);
                }
-               uxa_finish_access(pDst);
+               uxa_finish_access(pDst, UXA_ACCESS_RW);
        }
        return ret;
 }
@@ -158,9 +186,9 @@ uxa_check_copy_plane(DrawablePtr pSrc, DrawablePtr pDst, GCPtr pGC,
                        ret =
                            fbCopyPlane(pSrc, pDst, pGC, srcx, srcy, w, h, dstx,
                                        dsty, bitPlane);
-                       uxa_finish_access(pSrc);
+                       uxa_finish_access(pSrc, UXA_ACCESS_RO);
                }
-               uxa_finish_access(pDst);
+               uxa_finish_access(pDst, UXA_ACCESS_RW);
        }
        return ret;
 }
@@ -175,7 +203,7 @@ uxa_check_poly_point(DrawablePtr pDrawable, GCPtr pGC, int mode, int npt,
                      uxa_drawable_location(pDrawable)));
        if (uxa_prepare_access(pDrawable, UXA_ACCESS_RW)) {
                fbPolyPoint(pDrawable, pGC, mode, npt, pptInit);
-               uxa_finish_access(pDrawable);
+               uxa_finish_access(pDrawable, UXA_ACCESS_RW);
        }
 }
 
@@ -195,7 +223,7 @@ uxa_check_poly_lines(DrawablePtr pDrawable, GCPtr pGC,
                                fbPolyLine(pDrawable, pGC, mode, npt, ppt);
                                uxa_finish_access_gc(pGC);
                        }
-                       uxa_finish_access(pDrawable);
+                       uxa_finish_access(pDrawable, UXA_ACCESS_RW);
                }
                return;
        }
@@ -219,7 +247,7 @@ uxa_check_poly_segment(DrawablePtr pDrawable, GCPtr pGC,
                                              pSegInit);
                                uxa_finish_access_gc(pGC);
                        }
-                       uxa_finish_access(pDrawable);
+                       uxa_finish_access(pDrawable, UXA_ACCESS_RW);
                }
                return;
        }
@@ -246,7 +274,7 @@ uxa_check_poly_arc(DrawablePtr pDrawable, GCPtr pGC, int narcs, xArc * pArcs)
                                fbPolyArc(pDrawable, pGC, narcs, pArcs);
                                uxa_finish_access_gc(pGC);
                        }
-                       uxa_finish_access(pDrawable);
+                       uxa_finish_access(pDrawable, UXA_ACCESS_RW);
                }
                return;
        }
@@ -268,7 +296,7 @@ uxa_check_poly_fill_rect(DrawablePtr pDrawable, GCPtr pGC,
                        fbPolyFillRect(pDrawable, pGC, nrect, prect);
                        uxa_finish_access_gc(pGC);
                }
-               uxa_finish_access(pDrawable);
+               uxa_finish_access(pDrawable, UXA_ACCESS_RW);
        }
 }
 
@@ -287,7 +315,7 @@ uxa_check_image_glyph_blt(DrawablePtr pDrawable, GCPtr pGC,
                                        pglyphBase);
                        uxa_finish_access_gc(pGC);
                }
-               uxa_finish_access(pDrawable);
+               uxa_finish_access(pDrawable, UXA_ACCESS_RW);
        }
 }
 
@@ -307,7 +335,7 @@ uxa_check_poly_glyph_blt(DrawablePtr pDrawable, GCPtr pGC,
                                       pglyphBase);
                        uxa_finish_access_gc(pGC);
                }
-               uxa_finish_access(pDrawable);
+               uxa_finish_access(pDrawable, UXA_ACCESS_RW);
        }
 }
 
@@ -327,9 +355,9 @@ uxa_check_push_pixels(GCPtr pGC, PixmapPtr pBitmap,
                                             y);
                                uxa_finish_access_gc(pGC);
                        }
-                       uxa_finish_access(&pBitmap->drawable);
+                       uxa_finish_access(&pBitmap->drawable, UXA_ACCESS_RO);
                }
-               uxa_finish_access(pDrawable);
+               uxa_finish_access(pDrawable, UXA_ACCESS_RW);
        }
 }
 
@@ -344,7 +372,7 @@ uxa_check_get_spans(DrawablePtr pDrawable,
                      uxa_drawable_location(pDrawable)));
        if (uxa_prepare_access(pDrawable, UXA_ACCESS_RO)) {
                fbGetSpans(pDrawable, wMax, ppt, pwidth, nspans, pdstStart);
-               uxa_finish_access(pDrawable);
+               uxa_finish_access(pDrawable, UXA_ACCESS_RO);
        }
 }
 
@@ -362,24 +390,20 @@ uxa_check_composite(CARD8 op,
 
        UXA_FALLBACK(("from picts %p/%p to pict %p\n", pSrc, pMask, pDst));
 
-       if (uxa_prepare_access(pDst->pDrawable, UXA_ACCESS_RW)) {
-               if (pSrc->pDrawable == NULL ||
-                   uxa_prepare_access(pSrc->pDrawable, UXA_ACCESS_RO)) {
-                       if (!pMask || pMask->pDrawable == NULL ||
-                           uxa_prepare_access(pMask->pDrawable, UXA_ACCESS_RO))
-                       {
+       if (uxa_picture_prepare_access(pDst, UXA_ACCESS_RW)) {
+               if (uxa_picture_prepare_access(pSrc, UXA_ACCESS_RO)) {
+                       if (!pMask || uxa_picture_prepare_access(pMask, UXA_ACCESS_RO)) {
                                fbComposite(op, pSrc, pMask, pDst,
                                            xSrc, ySrc,
                                            xMask, yMask,
                                            xDst, yDst,
                                            width, height);
-                               if (pMask && pMask->pDrawable != NULL)
-                                       uxa_finish_access(pMask->pDrawable);
+                               if (pMask)
+                                       uxa_picture_finish_access(pMask, UXA_ACCESS_RO);
                        }
-                       if (pSrc->pDrawable != NULL)
-                               uxa_finish_access(pSrc->pDrawable);
+                       uxa_picture_finish_access(pSrc, UXA_ACCESS_RO);
                }
-               uxa_finish_access(pDst->pDrawable);
+               uxa_picture_finish_access(pDst, UXA_ACCESS_RW);
        }
 }
 
@@ -391,9 +415,9 @@ uxa_check_add_traps(PicturePtr pPicture,
 
        UXA_FALLBACK(("to pict %p (%c)\n", pPicture,
                      uxa_drawable_location(pPicture->pDrawable)));
-       if (uxa_prepare_access(pPicture->pDrawable, UXA_ACCESS_RW)) {
+       if (uxa_picture_prepare_access(pPicture, UXA_ACCESS_RW)) {
                fbAddTraps(pPicture, x_off, y_off, ntrap, traps);
-               uxa_finish_access(pPicture->pDrawable);
+               uxa_picture_finish_access(pPicture, UXA_ACCESS_RW);
        }
 }
 
@@ -424,7 +448,7 @@ CARD32 uxa_get_pixmap_first_pixel(PixmapPtr pPixmap)
                pixel = *(CARD8 *) fb;
                break;
        }
-       uxa_finish_access(&pPixmap->drawable);
+       uxa_finish_access(&pPixmap->drawable, UXA_ACCESS_RO);
 
        return pixel;
 }
index 856a0ce..2635b50 100644 (file)
--- a/uxa/uxa.c
+++ b/uxa/uxa.c
@@ -38,6 +38,7 @@
 #include <X11/fonts/fontstruct.h>
 #include "dixfontstr.h"
 #include "uxa.h"
+#include "uxa-glamor.h"
 
 #if HAS_DEVPRIVATEKEYREC
 DevPrivateKeyRec uxa_screen_index;
@@ -160,7 +161,7 @@ Bool uxa_prepare_access(DrawablePtr pDrawable, uxa_access_t access)
  *
  * It deals with calling the driver's finish_access() only if necessary.
  */
-void uxa_finish_access(DrawablePtr pDrawable)
+void uxa_finish_access(DrawablePtr pDrawable, uxa_access_t access)
 {
        ScreenPtr pScreen = pDrawable->pScreen;
        uxa_screen_t *uxa_screen = uxa_get_screen(pScreen);
@@ -173,7 +174,7 @@ void uxa_finish_access(DrawablePtr pDrawable)
        if (!uxa_pixmap_is_offscreen(pPixmap))
                return;
 
-       (*uxa_screen->info->finish_access) (pPixmap);
+       (*uxa_screen->info->finish_access) (pPixmap, access);
 }
 
 /**
@@ -183,11 +184,21 @@ void uxa_finish_access(DrawablePtr pDrawable)
 static void
 uxa_validate_gc(GCPtr pGC, unsigned long changes, DrawablePtr pDrawable)
 {
+       uxa_screen_t *uxa_screen = uxa_get_screen(pGC->pScreen);
        /* fbValidateGC will do direct access to pixmaps if the tiling has
         * changed.
         * Preempt fbValidateGC by doing its work and masking the change out, so
         * that we can do the Prepare/finish_access.
         */
+
+       /* If we are using GLAMOR, then the tile or stipple pixmap
+        * may be pure GLAMOR pixmap, then we should let the glamor
+        * to do the validation.
+        */
+       if (uxa_screen->info->flags & UXA_USE_GLAMOR) {
+               glamor_validate_gc(pGC, changes, pDrawable);
+               goto set_ops;
+       }
 #ifdef FB_24_32BIT
        if ((changes & GCTile) && fbGetRotatedPixmap(pGC)) {
                (*pGC->pScreen->DestroyPixmap) (fbGetRotatedPixmap(pGC));
@@ -217,7 +228,7 @@ uxa_validate_gc(GCPtr pGC, unsigned long changes, DrawablePtr pDrawable)
                                            fb24_32ReformatTile(pOldTile,
                                                                pDrawable->
                                                                bitsPerPixel);
-                                       uxa_finish_access(&pOldTile->drawable);
+                                       uxa_finish_access(&pOldTile->drawable, UXA_ACCESS_RO);
                                }
                        }
                        if (pNewTile) {
@@ -235,7 +246,7 @@ uxa_validate_gc(GCPtr pGC, unsigned long changes, DrawablePtr pDrawable)
                        if (uxa_prepare_access
                            (&pGC->tile.pixmap->drawable, UXA_ACCESS_RW)) {
                                fbPadPixmap(pGC->tile.pixmap);
-                               uxa_finish_access(&pGC->tile.pixmap->drawable);
+                               uxa_finish_access(&pGC->tile.pixmap->drawable, UXA_ACCESS_RW);
                        }
                }
                /* Mask out the GCTile change notification, now that we've
@@ -250,12 +261,13 @@ uxa_validate_gc(GCPtr pGC, unsigned long changes, DrawablePtr pDrawable)
                 */
                if (uxa_prepare_access(&pGC->stipple->drawable, UXA_ACCESS_RW)) {
                        fbValidateGC(pGC, changes, pDrawable);
-                       uxa_finish_access(&pGC->stipple->drawable);
+                       uxa_finish_access(&pGC->stipple->drawable, UXA_ACCESS_RW);
                }
        } else {
                fbValidateGC(pGC, changes, pDrawable);
        }
 
+set_ops:
        pGC->ops = (GCOps *) & uxa_ops;
 }
 
@@ -296,7 +308,7 @@ Bool uxa_prepare_access_window(WindowPtr pWin)
                    (&pWin->border.pixmap->drawable, UXA_ACCESS_RO)) {
                        if (pWin->backgroundState == BackgroundPixmap)
                                uxa_finish_access(&pWin->background.pixmap->
-                                                 drawable);
+                                                 drawable, UXA_ACCESS_RO);
                        return FALSE;
                }
        }
@@ -306,10 +318,10 @@ Bool uxa_prepare_access_window(WindowPtr pWin)
 void uxa_finish_access_window(WindowPtr pWin)
 {
        if (pWin->backgroundState == BackgroundPixmap)
-               uxa_finish_access(&pWin->background.pixmap->drawable);
+               uxa_finish_access(&pWin->background.pixmap->drawable, UXA_ACCESS_RO);
 
        if (pWin->borderIsPixel == FALSE)
-               uxa_finish_access(&pWin->border.pixmap->drawable);
+               uxa_finish_access(&pWin->border.pixmap->drawable, UXA_ACCESS_RO);
 }
 
 static Bool uxa_change_window_attributes(WindowPtr pWin, unsigned long mask)
@@ -329,25 +341,10 @@ static RegionPtr uxa_bitmap_to_region(PixmapPtr pPix)
        if (!uxa_prepare_access(&pPix->drawable, UXA_ACCESS_RO))
                return NULL;
        ret = fbPixmapToRegion(pPix);
-       uxa_finish_access(&pPix->drawable);
+       uxa_finish_access(&pPix->drawable, UXA_ACCESS_RO);
        return ret;
 }
 
-static void uxa_xorg_enable_disable_fb_access(int index, Bool enable)
-{
-       ScreenPtr screen = screenInfo.screens[index];
-       uxa_screen_t *uxa_screen = uxa_get_screen(screen);
-
-       if (!enable && uxa_screen->disableFbCount++ == 0)
-               uxa_screen->swappedOut = TRUE;
-
-       if (enable && --uxa_screen->disableFbCount == 0)
-               uxa_screen->swappedOut = FALSE;
-
-       if (uxa_screen->SavedEnableDisableFBAccess)
-               uxa_screen->SavedEnableDisableFBAccess(index, enable);
-}
-
 void uxa_set_fallback_debug(ScreenPtr screen, Bool enable)
 {
        uxa_screen_t *uxa_screen = uxa_get_screen(screen);
@@ -366,12 +363,11 @@ void uxa_set_force_fallback(ScreenPtr screen, Bool value)
  * uxa_close_screen() unwraps its wrapped screen functions and tears down UXA's
  * screen private, before calling down to the next CloseSccreen.
  */
-static Bool uxa_close_screen(int i, ScreenPtr pScreen)
+static Bool uxa_close_screen(CLOSE_SCREEN_ARGS_DECL)
 {
-       uxa_screen_t *uxa_screen = uxa_get_screen(pScreen);
-       ScrnInfoPtr scrn = xf86Screens[pScreen->myNum];
+       uxa_screen_t *uxa_screen = uxa_get_screen(screen);
 #ifdef RENDER
-       PictureScreenPtr ps = GetPictureScreenIfSet(pScreen);
+       PictureScreenPtr ps = GetPictureScreenIfSet(screen);
 #endif
        int n;
 
@@ -384,33 +380,31 @@ static Bool uxa_close_screen(int i, ScreenPtr pScreen)
        for (n = 0; n < uxa_screen->solid_cache_size; n++)
                FreePicture(uxa_screen->solid_cache[n].picture, 0);
 
-       uxa_glyphs_fini(pScreen);
+       uxa_glyphs_fini(screen);
 
-       if (pScreen->devPrivate) {
+       if (screen->devPrivate) {
                /* Destroy the pixmap created by miScreenInit() *before*
                 * chaining up as we finalize ourselves here and so this
                 * is the last chance we have of releasing our resources
                 * associated with the Pixmap. So do it first.
                 */
-               (void) (*pScreen->DestroyPixmap) (pScreen->devPrivate);
-               pScreen->devPrivate = NULL;
+               (void) (*screen->DestroyPixmap) (screen->devPrivate);
+               screen->devPrivate = NULL;
        }
 
-       pScreen->CreateGC = uxa_screen->SavedCreateGC;
-       pScreen->CloseScreen = uxa_screen->SavedCloseScreen;
-       pScreen->GetImage = uxa_screen->SavedGetImage;
-       pScreen->GetSpans = uxa_screen->SavedGetSpans;
-       pScreen->CreatePixmap = uxa_screen->SavedCreatePixmap;
-       pScreen->DestroyPixmap = uxa_screen->SavedDestroyPixmap;
-       pScreen->CopyWindow = uxa_screen->SavedCopyWindow;
-       pScreen->ChangeWindowAttributes =
+       screen->CreateGC = uxa_screen->SavedCreateGC;
+       screen->CloseScreen = uxa_screen->SavedCloseScreen;
+       screen->GetImage = uxa_screen->SavedGetImage;
+       screen->GetSpans = uxa_screen->SavedGetSpans;
+       screen->CreatePixmap = uxa_screen->SavedCreatePixmap;
+       screen->DestroyPixmap = uxa_screen->SavedDestroyPixmap;
+       screen->CopyWindow = uxa_screen->SavedCopyWindow;
+       screen->ChangeWindowAttributes =
            uxa_screen->SavedChangeWindowAttributes;
-       pScreen->BitmapToRegion = uxa_screen->SavedBitmapToRegion;
-       scrn->EnableDisableFBAccess = uxa_screen->SavedEnableDisableFBAccess;
+       screen->BitmapToRegion = uxa_screen->SavedBitmapToRegion;
 #ifdef RENDER
        if (ps) {
                ps->Composite = uxa_screen->SavedComposite;
-               ps->CompositeRects = uxa_screen->SavedCompositeRects;
                ps->Glyphs = uxa_screen->SavedGlyphs;
                ps->Trapezoids = uxa_screen->SavedTrapezoids;
                ps->AddTraps = uxa_screen->SavedAddTraps;
@@ -422,7 +416,7 @@ static Bool uxa_close_screen(int i, ScreenPtr pScreen)
 
        free(uxa_screen);
 
-       return (*pScreen->CloseScreen) (i, pScreen);
+       return (*screen->CloseScreen) (CLOSE_SCREEN_ARGS);
 }
 
 /**
@@ -441,7 +435,7 @@ uxa_driver_t *uxa_driver_alloc(void)
 }
 
 /**
- * @param pScreen screen being initialized
+ * @param screen screen being initialized
  * @param pScreenInfo UXA driver record
  *
  * uxa_driver_init sets up UXA given a driver record filled in by the driver.
@@ -453,7 +447,6 @@ uxa_driver_t *uxa_driver_alloc(void)
 Bool uxa_driver_init(ScreenPtr screen, uxa_driver_t * uxa_driver)
 {
        uxa_screen_t *uxa_screen;
-       ScrnInfoPtr scrn = xf86Screens[screen->myNum];
 
        if (!uxa_driver)
                return FALSE;
@@ -521,7 +514,7 @@ Bool uxa_driver_init(ScreenPtr screen, uxa_driver_t * uxa_driver)
        screen->GetImage = uxa_get_image;
 
        uxa_screen->SavedGetSpans = screen->GetSpans;
-       screen->GetSpans = uxa_check_get_spans;
+       screen->GetSpans = uxa_get_spans;
 
        uxa_screen->SavedCopyWindow = screen->CopyWindow;
        screen->CopyWindow = uxa_copy_window;
@@ -533,9 +526,6 @@ Bool uxa_driver_init(ScreenPtr screen, uxa_driver_t * uxa_driver)
        uxa_screen->SavedBitmapToRegion = screen->BitmapToRegion;
        screen->BitmapToRegion = uxa_bitmap_to_region;
 
-       uxa_screen->SavedEnableDisableFBAccess = scrn->EnableDisableFBAccess;
-       scrn->EnableDisableFBAccess = uxa_xorg_enable_disable_fb_access;
-
 #ifdef RENDER
        {
                PictureScreenPtr ps = GetPictureScreenIfSet(screen);
@@ -543,9 +533,6 @@ Bool uxa_driver_init(ScreenPtr screen, uxa_driver_t * uxa_driver)
                        uxa_screen->SavedComposite = ps->Composite;
                        ps->Composite = uxa_composite;
 
-                       uxa_screen->SavedCompositeRects = ps->CompositeRects;
-                       ps->CompositeRects = uxa_solid_rects;
-
                        uxa_screen->SavedGlyphs = ps->Glyphs;
                        ps->Glyphs = uxa_glyphs;
 
@@ -559,7 +546,7 @@ Bool uxa_driver_init(ScreenPtr screen, uxa_driver_t * uxa_driver)
                        ps->Trapezoids = uxa_trapezoids;
 
                        uxa_screen->SavedAddTraps = ps->AddTraps;
-                       ps->AddTraps = uxa_check_add_traps;
+                       ps->AddTraps = uxa_add_traps;
                }
        }
 #endif
index e001c53..b8569f0 100644 (file)
--- a/uxa/uxa.h
+++ b/uxa/uxa.h
@@ -45,7 +45,9 @@
 
 typedef enum {
        UXA_ACCESS_RO,
-       UXA_ACCESS_RW
+       UXA_ACCESS_RW,
+       UXA_GLAMOR_ACCESS_RO,
+       UXA_GLAMOR_ACCESS_RW
 } uxa_access_t;
 
 /**
@@ -513,7 +515,7 @@ typedef struct _UxaDriver {
         * offscreen pixmap set up by prepare_access().  Note that the
         * finish_access() will not be called if prepare_access() failed.
         */
-       void (*finish_access) (PixmapPtr pPix);
+       void (*finish_access) (PixmapPtr pPix, uxa_access_t access);
 
        /**
         * PixmapIsOffscreen() is an optional driver replacement to
@@ -543,8 +545,21 @@ typedef struct _UxaDriver {
  */
 #define UXA_TWO_BITBLT_DIRECTIONS      (1 << 2)
 
-/** @} */
+/**
+ * UXA_USE_GLAMOR indicates to use glamor acceleration to perform rendering.
+ * And if glamor fail to accelerate the rendering, then goto fallback to
+ * use CPU to do the rendering. This flag will be set only when glamor get
+ * initialized successfully.
+ * Note, in ddx close screen, this bit need to be cleared.
+ */
+#define UXA_USE_GLAMOR                 (1 << 3)
 
+/* UXA_GLAMOR_EGL_INITIALIZED indicates glamor egl layer get initialized
+ * successfully. UXA layer does not use this flag, before call to
+ * glamor_init, ddx need to check this flag. */
+#define UXA_GLAMOR_EGL_INITIALIZED     (1 << 4)
+
+/** @} */
 /** @name UXA CreatePixmap hint flags
  * @{
  */